mirror of
https://github.com/panda3d/panda3d.git
synced 2025-09-30 16:58:40 -04:00
New shader code
This commit is contained in:
parent
f7ee3b5729
commit
e012688824
@ -40,9 +40,9 @@
|
||||
glTextureContext_src.cxx \
|
||||
glTextureContext_src.I \
|
||||
glTextureContext_src.h \
|
||||
glCgShaderContext_src.cxx \
|
||||
glCgShaderContext_src.h \
|
||||
glCgShaderContext_src.I \
|
||||
glShaderContext_src.cxx \
|
||||
glShaderContext_src.h \
|
||||
glShaderContext_src.I \
|
||||
|
||||
#define SOURCES \
|
||||
$[INSTALL_HEADERS] glpure.cxx
|
||||
|
@ -1,219 +0,0 @@
|
||||
// Filename: glCgShaderContext_src.I
|
||||
// Created by: sshodhan (19Jul04)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#ifdef HAVE_CGGL
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::Constructor
|
||||
// Access: Published
|
||||
// Description: Use CLP(CgShaderContext)() to construct a new
|
||||
// CLP(CgShaderContext object.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE CLP(CgShaderContext)::
|
||||
CLP(CgShaderContext)(PT(CgShader) cg_shader) :
|
||||
CgShaderContext(cg_shader) {
|
||||
init_cg_shader_context();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::set_param 1f
|
||||
// Access: Published
|
||||
// Description: Send 1f values to vertex or fragment shaders
|
||||
// Your shaders must declare these as uniform params
|
||||
// and can make use of them
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
set_param(const string &pname, const float value, bool vert_or_frag) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetParameter1f(_cg_shader->_vertex_1f_params[pname], value);
|
||||
} else {
|
||||
cgGLSetParameter1f(_cg_shader->_fragment_1f_params[pname], value);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::set_param 1d
|
||||
// Access: Published
|
||||
// Description: Send 1d values to vertex or fragment shaders
|
||||
// Your shaders must declare these as uniform params
|
||||
// and can make use of them
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
set_param(const string &pname, const double value, bool vert_or_frag) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetParameter1f(_cg_shader->_vertex_1d_params[pname], value);
|
||||
} else {
|
||||
cgGLSetParameter1f(_cg_shader->_fragment_1d_params[pname], value);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::set_param 2f
|
||||
// Access: Published
|
||||
// Description: Send 2f values to vertex or fragment shaders
|
||||
// Your shaders must declare these as uniform params
|
||||
// and can make use of them
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
set_param(const string &pname, const float value1, const float value2,
|
||||
bool vert_or_frag) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetParameter2f(_cg_shader->_vertex_2f_params[pname], value1, value2);
|
||||
} else {
|
||||
cgGLSetParameter2f(_cg_shader->_fragment_2f_params[pname], value1, value2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::set_param 2d
|
||||
// Access: Published
|
||||
// Description: Send 2d values to vertex or fragment shaders
|
||||
// Your shaders must declare these as uniform params
|
||||
// and can make use of them
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
set_param(const string &pname, const double value1, const double value2,
|
||||
bool vert_or_frag) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetParameter2d(_cg_shader->_vertex_2d_params[pname], value1, value2);
|
||||
} else {
|
||||
cgGLSetParameter2d(_cg_shader->_fragment_2d_params[pname], value1, value2);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::set_param 3f
|
||||
// Access: Published
|
||||
// Description: Send 3f values to vertex or fragment shaders
|
||||
// Your shaders must declare these as uniform params
|
||||
// and can make use of them
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
set_param(const string &pname, const float value1, const float value2,
|
||||
const float value3, bool vert_or_frag) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetParameter3f(_cg_shader->_vertex_3f_params[pname], value1, value2, value3);
|
||||
} else {
|
||||
cgGLSetParameter3f(_cg_shader->_fragment_3f_params[pname], value1, value2, value3);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::set_param 3d
|
||||
// Access: Published
|
||||
// Description: Send 3d values to vertex or fragment shaders
|
||||
// Your shaders must declare these as uniform params
|
||||
// and can make use of them
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
set_param(const string &pname, const double value1, const double value2,
|
||||
const double value3, bool vert_or_frag) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetParameter3d(_cg_shader->_vertex_3d_params[pname], value1, value2, value3);
|
||||
} else {
|
||||
cgGLSetParameter3d(_cg_shader->_fragment_3d_params[pname], value1, value2, value3);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::set_param 4f
|
||||
// Access: Published
|
||||
// Description: Send 4f values to vertex or fragment shaders
|
||||
// Your shaders must declare these as uniform params
|
||||
// and can make use of them
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
set_param(const string &pname, const float value1, const float value2,
|
||||
const float value3, const float value4, bool vert_or_frag) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetParameter4f(_cg_shader->_vertex_4f_params[pname], value1, value2, value3, value4);
|
||||
} else {
|
||||
cgGLSetParameter4f(_cg_shader->_fragment_4f_params[pname], value1, value2, value3, value4);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::set_param 4d
|
||||
// Access: Published
|
||||
// Description: Send 4d values to vertex or fragment shaders
|
||||
// Your shaders must declare these as uniform params
|
||||
// and can make use of them
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
set_param(const string &pname, const double value1, const double value2,
|
||||
const double value3, const double value4, bool vert_or_frag) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetParameter4d(_cg_shader->_vertex_4d_params[pname], value1, value2, value3, value4);
|
||||
} else {
|
||||
cgGLSetParameter4d(_cg_shader->_fragment_4d_params[pname], value1, value2, value3, value4);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::set_param texture
|
||||
// Access: Published
|
||||
// Description: Send texture to vertex or fragment shaders
|
||||
// Your shaders must declare these as uniform params
|
||||
// and can make use of them
|
||||
// What we actually send is the OpenGL texture index
|
||||
// for a texture
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
set_param(const string &pname, Texture *t , bool vert_or_frag, GraphicsStateGuardianBase *gsg) {
|
||||
TextureContext *tc = t->prepare_now(gsg->get_prepared_objects(),gsg);
|
||||
CLP(TextureContext) *gtc = DCAST(CLP(TextureContext), tc);
|
||||
if (vert_or_frag) {
|
||||
cgGLSetTextureParameter(_cg_shader->_vertex_texture_params[pname], gtc->_index);
|
||||
} else {
|
||||
cgGLSetTextureParameter(_cg_shader->_fragment_texture_params[pname], gtc->_index);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::enable_texture_param
|
||||
// Access: Published
|
||||
// Description: Enable a texture that has already been set
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
enable_texture_param(const string &pname, bool vert_or_frag) {
|
||||
if (vert_or_frag) {
|
||||
cgGLEnableTextureParameter(_cg_shader->_vertex_texture_params[pname]);
|
||||
} else {
|
||||
cgGLEnableTextureParameter(_cg_shader->_fragment_texture_params[pname]);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::enable_texture_param
|
||||
// Access: Published
|
||||
// Description: Disable a texture
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE void CLP(CgShaderContext)::
|
||||
disable_texture_param(const string &pname, bool vert_or_frag) {
|
||||
if (vert_or_frag) {
|
||||
cgGLDisableTextureParameter(_cg_shader->_vertex_texture_params[pname]);
|
||||
} else {
|
||||
cgGLDisableTextureParameter(_cg_shader->_fragment_texture_params[pname]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
@ -1,425 +0,0 @@
|
||||
// Filename: glCgShaderContext_src.cxx
|
||||
// Created by: sshodhan (19Jul04)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#include "pandabase.h"
|
||||
|
||||
#ifdef HAVE_CGGL
|
||||
|
||||
#include <Cg/cgGL.h>
|
||||
|
||||
TypeHandle CLP(CgShaderContext)::_type_handle;
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CgShaderContext::init_cg
|
||||
// Access: Published
|
||||
// Description: Create the profiles : just go for the best available
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
bool CLP(CgShaderContext)::
|
||||
init_cg_shader_context() {
|
||||
|
||||
// Get The Latest GL Vertex Profile
|
||||
_cg_shader->cgVertexProfile = cgGLGetLatestProfile(CG_GL_VERTEX);
|
||||
// Get The Latest GL Fragment Profile
|
||||
_cg_shader->cgFragmentProfile = cgGLGetLatestProfile(CG_GL_FRAGMENT);
|
||||
|
||||
// Validate Our Profile Determination
|
||||
if (_cg_shader->cgVertexProfile == CG_PROFILE_UNKNOWN) {
|
||||
cerr << "VERTEX PROFILE UNKNOWN" << endl;
|
||||
return false;
|
||||
}
|
||||
if (_cg_shader->cgFragmentProfile == CG_PROFILE_UNKNOWN) {
|
||||
cerr << "FRAGMENT PROFILE UNKNOWN" << endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
cgGLSetOptimalOptions(_cg_shader->cgVertexProfile);// Set The Current Profile
|
||||
cgGLSetOptimalOptions(_cg_shader->cgFragmentProfile);// Set The Current Profile
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CgShaderContext::load_shaders
|
||||
// Access: Published
|
||||
// Description: Download the programs to the GPU
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CLP(CgShaderContext)::
|
||||
load_shaders() {
|
||||
// Load The Programs
|
||||
cgGLLoadProgram(_cg_shader->cgVertexProgram);
|
||||
cgGLLoadProgram(_cg_shader->cgFragmentProgram);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CgShaderContext::bind
|
||||
// Access: Published
|
||||
// Description: We support Textures, Matrices and Numbers as
|
||||
// parameters to the shaders. We iterate through
|
||||
// maps which have <name, CgParameter> tuples
|
||||
// There are two maps..one for vertex shader params
|
||||
// and one for fragment shader params.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CLP(CgShaderContext)::
|
||||
bind(GraphicsStateGuardianBase *gsg) {
|
||||
CgShader::CGPARAMETER::const_iterator param_iter; // Use this to go through all params
|
||||
|
||||
// Matrix params
|
||||
// Vertex
|
||||
for (param_iter = _cg_shader->_vertex_matrix_params.begin();
|
||||
param_iter != _cg_shader->_vertex_matrix_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_matrices[param_iter->first].matrix,
|
||||
_cg_shader->_cg_matrices[param_iter->first].transform, 1);
|
||||
}
|
||||
// Fragment
|
||||
for (param_iter = _cg_shader->_fragment_matrix_params.begin();
|
||||
param_iter != _cg_shader->_fragment_matrix_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_matrices[param_iter->first].matrix,
|
||||
_cg_shader->_cg_matrices[param_iter->first].transform, 0);
|
||||
}
|
||||
|
||||
// BIND THE FRAGMENT AND SHADER PROGRAMS (after Matrices are loaded)
|
||||
cgGLEnableProfile(_cg_shader->cgVertexProfile);
|
||||
cgGLBindProgram(_cg_shader->cgVertexProgram);
|
||||
cgGLEnableProfile(_cg_shader->cgFragmentProfile);
|
||||
cgGLBindProgram(_cg_shader->cgFragmentProgram);
|
||||
|
||||
// Texture params
|
||||
// Vertex
|
||||
for (param_iter = _cg_shader->_vertex_texture_params.begin();
|
||||
param_iter != _cg_shader->_vertex_texture_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_textures[param_iter->first] , 1, gsg);
|
||||
enable_texture_param(param_iter->first, 1);
|
||||
}
|
||||
//Fragment
|
||||
for (param_iter = _cg_shader->_fragment_texture_params.begin();
|
||||
param_iter != _cg_shader->_fragment_texture_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_textures[param_iter->first] , 0, gsg);
|
||||
enable_texture_param(param_iter->first, 0);
|
||||
}
|
||||
|
||||
// 1F params
|
||||
// Vertex
|
||||
for (param_iter = _cg_shader->_vertex_1f_params.begin();
|
||||
param_iter != _cg_shader->_vertex_1f_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params1f[param_iter->first] , 1);
|
||||
}
|
||||
//Fragment
|
||||
for (param_iter = _cg_shader->_fragment_1f_params.begin();
|
||||
param_iter != _cg_shader->_fragment_1f_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params1f[param_iter->first] , 0);
|
||||
}
|
||||
|
||||
|
||||
// 2F params
|
||||
// Vertex
|
||||
for (param_iter = _cg_shader->_vertex_2f_params.begin();
|
||||
param_iter != _cg_shader->_vertex_2f_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params2f[param_iter->first][0],
|
||||
_cg_shader->_cg_params2f[param_iter->first][1], 1);
|
||||
}
|
||||
//Fragment
|
||||
for (param_iter = _cg_shader->_fragment_2f_params.begin();
|
||||
param_iter != _cg_shader->_fragment_2f_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params2f[param_iter->first][0],
|
||||
_cg_shader->_cg_params2f[param_iter->first][1], 0);
|
||||
}
|
||||
|
||||
// 3F params
|
||||
// Vertex
|
||||
for (param_iter = _cg_shader->_vertex_3f_params.begin();
|
||||
param_iter != _cg_shader->_vertex_3f_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params3f[param_iter->first][0],
|
||||
_cg_shader->_cg_params3f[param_iter->first][1],
|
||||
_cg_shader->_cg_params3f[param_iter->first][2], 1);
|
||||
}
|
||||
//Fragment
|
||||
for (param_iter = _cg_shader->_fragment_3f_params.begin();
|
||||
param_iter != _cg_shader->_fragment_3f_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params3f[param_iter->first][0],
|
||||
_cg_shader->_cg_params3f[param_iter->first][1],
|
||||
_cg_shader->_cg_params3f[param_iter->first][2], 0);
|
||||
}
|
||||
|
||||
// 4F params
|
||||
// Vertex
|
||||
for (param_iter = _cg_shader->_vertex_4f_params.begin();
|
||||
param_iter != _cg_shader->_vertex_4f_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params4f[param_iter->first][0],
|
||||
_cg_shader->_cg_params4f[param_iter->first][1],
|
||||
_cg_shader->_cg_params4f[param_iter->first][2],
|
||||
_cg_shader->_cg_params4f[param_iter->first][3], 1);
|
||||
}
|
||||
//Fragment
|
||||
for (param_iter = _cg_shader->_fragment_4f_params.begin();
|
||||
param_iter != _cg_shader->_fragment_4f_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params4f[param_iter->first][0],
|
||||
_cg_shader->_cg_params4f[param_iter->first][1],
|
||||
_cg_shader->_cg_params4f[param_iter->first][2],
|
||||
_cg_shader->_cg_params4f[param_iter->first][3],0);
|
||||
}
|
||||
|
||||
// 1D params
|
||||
// Vertex
|
||||
for (param_iter = _cg_shader->_vertex_1d_params.begin();
|
||||
param_iter != _cg_shader->_vertex_1d_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params1d[param_iter->first] , 1);
|
||||
}
|
||||
//Fragment
|
||||
for (param_iter = _cg_shader->_fragment_1d_params.begin();
|
||||
param_iter != _cg_shader->_fragment_1d_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params1d[param_iter->first] , 0);
|
||||
}
|
||||
|
||||
|
||||
// 2D params
|
||||
// Vertex
|
||||
for (param_iter = _cg_shader->_vertex_2d_params.begin();
|
||||
param_iter != _cg_shader->_vertex_2d_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params2d[param_iter->first][0],
|
||||
_cg_shader->_cg_params2d[param_iter->first][1], 1);
|
||||
}
|
||||
//Fragment
|
||||
for (param_iter = _cg_shader->_fragment_2d_params.begin();
|
||||
param_iter != _cg_shader->_fragment_2d_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params2d[param_iter->first][0],
|
||||
_cg_shader->_cg_params2d[param_iter->first][1], 0);
|
||||
}
|
||||
|
||||
// 3D params
|
||||
// Vertex
|
||||
for (param_iter = _cg_shader->_vertex_3d_params.begin();
|
||||
param_iter != _cg_shader->_vertex_3d_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params3d[param_iter->first][0],
|
||||
_cg_shader->_cg_params3d[param_iter->first][1],
|
||||
_cg_shader->_cg_params3d[param_iter->first][2], 1);
|
||||
}
|
||||
//Fragment
|
||||
for (param_iter = _cg_shader->_fragment_3d_params.begin();
|
||||
param_iter != _cg_shader->_fragment_3d_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params3d[param_iter->first][0],
|
||||
_cg_shader->_cg_params3d[param_iter->first][1],
|
||||
_cg_shader->_cg_params3d[param_iter->first][2], 0);
|
||||
}
|
||||
|
||||
// 4D params
|
||||
// Vertex
|
||||
for (param_iter = _cg_shader->_vertex_4d_params.begin();
|
||||
param_iter != _cg_shader->_vertex_4d_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params4d[param_iter->first][0],
|
||||
_cg_shader->_cg_params4d[param_iter->first][1],
|
||||
_cg_shader->_cg_params4d[param_iter->first][2],
|
||||
_cg_shader->_cg_params4d[param_iter->first][3], 1);
|
||||
}
|
||||
//Fragment
|
||||
for (param_iter = _cg_shader->_fragment_4d_params.begin();
|
||||
param_iter != _cg_shader->_fragment_4d_params.end(); param_iter++) {
|
||||
set_param(param_iter->first, _cg_shader->_cg_params4d[param_iter->first][0],
|
||||
_cg_shader->_cg_params4d[param_iter->first][1],
|
||||
_cg_shader->_cg_params4d[param_iter->first][2],
|
||||
_cg_shader->_cg_params4d[param_iter->first][3],0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CgShaderContext::unbind
|
||||
// Access: Published
|
||||
// Description: Disable textures and shaders
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CLP(CgShaderContext)::
|
||||
un_bind(){
|
||||
|
||||
CgShader::CGPARAMETER::const_iterator param_iter;
|
||||
for (param_iter = _cg_shader->_vertex_texture_params.begin();
|
||||
param_iter != _cg_shader->_vertex_texture_params.end(); param_iter++) {
|
||||
disable_texture_param(param_iter->first, 1);
|
||||
}
|
||||
|
||||
for (param_iter = _cg_shader->_fragment_texture_params.begin();
|
||||
param_iter != _cg_shader->_fragment_texture_params.end(); param_iter++) {
|
||||
disable_texture_param(param_iter->first, 0);
|
||||
}
|
||||
|
||||
|
||||
cgGLDisableProfile(_cg_shader->cgVertexProfile);// Disable Our Vertex Profile
|
||||
cgGLDisableProfile(_cg_shader->cgFragmentProfile);// Disable Our Fragment Profile
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: CLP(CgShaderContext)::set_param Matrix
|
||||
// Access: Published
|
||||
// Description: Select a matrix type and a transform type
|
||||
// Matrices you can send to your shaders are:
|
||||
// MTXMODELVIEW,MTXPROJECTION,MTXTEXTURE,MTXMODELVIEWPROJECTION,
|
||||
// and they can have th transforms:
|
||||
// TRFIDENTITY,TRFTRANSPOSE,TRFINVERSE,TRFINVERSETRANSPOSE,
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CLP(CgShaderContext)::
|
||||
set_param(const string &pname, CgShader::Matrix_Type m, CgShader::Transform_Type t,
|
||||
bool vert_or_frag) {
|
||||
// MODELVIEW BEGINS
|
||||
if (m == CgShader::MTXMODELVIEW) {
|
||||
if (t == CgShader::TRFIDENTITY) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
}
|
||||
} else if (t == CgShader::TRFTRANSPOSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_TRANSPOSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_TRANSPOSE);
|
||||
}
|
||||
} else if (t == CgShader::TRFINVERSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE);
|
||||
}
|
||||
} else if (t == CgShader::TRFINVERSETRANSPOSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE);
|
||||
}
|
||||
}
|
||||
// MODELVIEW ENDS
|
||||
// PROJECTION BEGINS
|
||||
} else if (m == CgShader::MTXPROJECTION) {
|
||||
if (t == CgShader::TRFIDENTITY) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
}
|
||||
} else if (t == CgShader::TRFTRANSPOSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_TRANSPOSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_TRANSPOSE);
|
||||
}
|
||||
} else if (t == CgShader::TRFINVERSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_INVERSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_INVERSE);
|
||||
}
|
||||
} else if (t == CgShader::TRFINVERSETRANSPOSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_PROJECTION_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE);
|
||||
}
|
||||
}
|
||||
// PROJECTION ENDS
|
||||
// TEXTURE BEGINS
|
||||
} else if (m == CgShader::MTXTEXTURE) {
|
||||
if (t == CgShader::TRFIDENTITY) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
}
|
||||
} else if (t == CgShader::TRFTRANSPOSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_TRANSPOSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_TRANSPOSE);
|
||||
}
|
||||
} else if (t == CgShader::TRFINVERSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_INVERSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_INVERSE);
|
||||
}
|
||||
} else if (t == CgShader::TRFINVERSETRANSPOSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_TEXTURE_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE);
|
||||
}
|
||||
}
|
||||
// TEXTURE ENDS
|
||||
// MODELVIEWPROJECTION BEGINS
|
||||
} else if (m == CgShader::MTXMODELVIEWPROJECTION) {
|
||||
if (t == CgShader::TRFIDENTITY) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_IDENTITY);
|
||||
}
|
||||
} else if (t == CgShader::TRFTRANSPOSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_TRANSPOSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_TRANSPOSE);
|
||||
}
|
||||
} else if (t == CgShader::TRFINVERSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_INVERSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_INVERSE);
|
||||
}
|
||||
} else if (t == CgShader::TRFINVERSETRANSPOSE) {
|
||||
if (vert_or_frag) {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_vertex_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE);
|
||||
} else {
|
||||
cgGLSetStateMatrixParameter(_cg_shader->_fragment_matrix_params[pname],
|
||||
CG_GL_MODELVIEW_PROJECTION_MATRIX, CG_GL_MATRIX_INVERSE_TRANSPOSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
// MODELVIEWPROJECTION ENDS
|
||||
}
|
||||
|
||||
#endif
|
@ -1,109 +0,0 @@
|
||||
// Filename: glCgShaderContext_src.h
|
||||
// Created by: sshodhan (19Jul04)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pandabase.h"
|
||||
|
||||
#ifdef HAVE_CGGL
|
||||
#include "cgShader.h"
|
||||
#include "cgShaderContext.h"
|
||||
#include "luse.h"
|
||||
#include "pmap.h"
|
||||
#include "texture.h"
|
||||
#include "dcast.h"
|
||||
#include <Cg/cgGL.h>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : GLCgShaderContext
|
||||
// Description : The GL version of CgShaderContext.
|
||||
// This class binds and unbinds shaders, does the
|
||||
// actual API specific parameter passing based on
|
||||
// the CgShader object pointed to in CgShaderContext
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EXPCL_GL CLP(CgShaderContext) : public CgShaderContext {
|
||||
|
||||
public:
|
||||
CLP(CgShaderContext)(PT(CgShader) cg_shader);
|
||||
|
||||
INLINE void set_param(const string &pname, const float value,
|
||||
bool vert_or_frag);
|
||||
|
||||
INLINE void set_param(const string &pname, const double value,
|
||||
bool vert_or_frag);
|
||||
|
||||
INLINE void set_param(const string &pname, const float value1,
|
||||
const float value2, bool vert_or_frag);
|
||||
|
||||
INLINE void set_param(const string &pname, const double value1,
|
||||
const double value2, bool vert_or_frag);
|
||||
|
||||
INLINE void set_param(const string &pname, const float value1,
|
||||
const float value2, const float value3, bool vert_or_frag);
|
||||
|
||||
INLINE void set_param(const string &pname, const double value1,
|
||||
const double value2, const double value3, bool vert_or_frag);
|
||||
|
||||
INLINE void set_param(const string &pname, const float value1,
|
||||
const float value2, const float value3, const float value4,
|
||||
bool vert_or_frag);
|
||||
|
||||
INLINE void set_param(const string &pname, const double value1,
|
||||
const double value2, const double value3, const double value4,
|
||||
bool vert_or_frag);
|
||||
|
||||
INLINE void set_param(const string &pname, Texture *t, bool vert_or_frag, GraphicsStateGuardianBase *gsg);
|
||||
|
||||
void set_param(const string &pname, CgShader::Matrix_Type m,
|
||||
CgShader::Transform_Type t, bool vert_or_frag);
|
||||
|
||||
INLINE void enable_texture_param(const string &pname, bool vert_or_frag);
|
||||
|
||||
INLINE void disable_texture_param(const string &pname, bool vert_or_frag);
|
||||
|
||||
void load_shaders();
|
||||
|
||||
public:
|
||||
|
||||
|
||||
INLINE void bind(GraphicsStateGuardianBase *gsg);
|
||||
INLINE void un_bind();
|
||||
bool init_cg_shader_context();
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
CgShaderContext::init_type();
|
||||
register_type(_type_handle, CLASSPREFIX_QUOTED "CgShaderContext",
|
||||
CgShaderContext::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
#include "glCgShaderContext_src.I"
|
||||
|
||||
#endif
|
||||
|
@ -51,6 +51,7 @@
|
||||
#include "fogAttrib.h"
|
||||
#include "depthOffsetAttrib.h"
|
||||
#include "shadeModelAttrib.h"
|
||||
#include "shaderAttrib.h"
|
||||
#include "fog.h"
|
||||
#include "clockObject.h"
|
||||
#include "string_utils.h"
|
||||
@ -64,9 +65,8 @@
|
||||
#include "mutexHolder.h"
|
||||
#include "indirectLess.h"
|
||||
#include "pStatTimer.h"
|
||||
#ifdef HAVE_CGGL
|
||||
#include "cgShaderAttrib.h"
|
||||
#endif
|
||||
#include "shader.h"
|
||||
#include "shaderMode.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
@ -279,9 +279,8 @@ CLP(GraphicsStateGuardian)(const FrameBufferProperties &properties) :
|
||||
GraphicsStateGuardian(properties, CS_yup_right)
|
||||
{
|
||||
_error_count = 0;
|
||||
#ifdef HAVE_CGGL
|
||||
_cg_shader = (CgShader *)NULL;
|
||||
#endif
|
||||
_shader_mode = (ShaderMode *)NULL;
|
||||
_shader_context = (CLP(ShaderContext) *)NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
@ -774,10 +773,9 @@ reset() {
|
||||
|
||||
_texgen_forced_normal = false;
|
||||
|
||||
#ifdef HAVE_CGGL
|
||||
_cg_shader = (CgShader *)NULL;
|
||||
#endif
|
||||
|
||||
_shader_mode = (ShaderMode *)NULL;
|
||||
_shader_context = (CLP(ShaderContext) *)NULL;
|
||||
|
||||
// Count the max number of lights
|
||||
GLint max_lights;
|
||||
GLP(GetIntegerv)(GL_MAX_LIGHTS, &max_lights);
|
||||
@ -1927,6 +1925,27 @@ release_geom(GeomContext *gc) {
|
||||
delete ggc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GLGraphicsStateGuardian::prepare_shader
|
||||
// Access: Public, Virtual
|
||||
// Description: yadda.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
ShaderContext *CLP(GraphicsStateGuardian)::
|
||||
prepare_shader(Shader *shader) {
|
||||
return new CLP(ShaderContext)(shader);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GLGraphicsStateGuardian::release_shader
|
||||
// Access: Public, Virtual
|
||||
// Description: yadda.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void CLP(GraphicsStateGuardian)::
|
||||
release_shader(ShaderContext *sc) {
|
||||
CLP(ShaderContext) *gsc = DCAST(CLP(ShaderContext), sc);
|
||||
delete gsc;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GLGraphicsStateGuardian::record_deleted_display_list
|
||||
// Access: Public
|
||||
@ -2561,49 +2580,33 @@ issue_shade_model(const ShadeModelAttrib *attrib) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GLGraphicsStateGuardian::issue_cg_shader_bind
|
||||
// Function: GLGraphicsStateGuardian::issue_shader
|
||||
// Access: Public, Virtual
|
||||
// Description: Bind shader of current node
|
||||
// and unbind the shader of the previous node
|
||||
// Create a new GLCgShaderContext if this shader
|
||||
// object is coming in for the first time
|
||||
// Also maintain the map of CgShader objects to
|
||||
// respective GLCgShaderContexts
|
||||
// Description: Bind a shader.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
#ifdef HAVE_CGGL
|
||||
void CLP(GraphicsStateGuardian)::
|
||||
issue_cg_shader_bind(const CgShaderAttrib *attrib) {
|
||||
issue_shader(const ShaderAttrib *attrib) {
|
||||
ShaderMode *mode = attrib->get_shader_mode();
|
||||
Shader *shader = mode->get_shader();
|
||||
CLP(ShaderContext) *context = (CLP(ShaderContext) *)(shader->prepare_now(get_prepared_objects(), this));
|
||||
|
||||
if (attrib->is_off()) { //Current node has no shaders
|
||||
if (_cg_shader != (CgShader *) NULL) {
|
||||
_gl_cg_shader_contexts[_cg_shader]->un_bind();// Prev node had shaders
|
||||
}
|
||||
_cg_shader = attrib->get_cg_shader();//Store current node.. here NULL
|
||||
} else {// Current node has shaders
|
||||
if (_cg_shader != (CgShader *) NULL) {
|
||||
_gl_cg_shader_contexts[_cg_shader]->un_bind();// Prev node had shaders
|
||||
if (context != _shader_context) {
|
||||
// Use a completely different shader than before.
|
||||
// Unbind old shader, bind the new one.
|
||||
if (_shader_context != 0) {
|
||||
_shader_context->unbind();
|
||||
_shader_context = 0;
|
||||
}
|
||||
_cg_shader = attrib->get_cg_shader();//Store current node
|
||||
CGSHADERCONTEXTS::const_iterator csci;
|
||||
csci = _gl_cg_shader_contexts.find(_cg_shader);
|
||||
if (csci != _gl_cg_shader_contexts.end()) { // Already have context?
|
||||
(*csci).second->bind(this); // Bind the current shader
|
||||
} else {// First time CgShader object...need to make a new GLCgShaderContext
|
||||
PT(CLP(CgShaderContext)) csc = new CLP(CgShaderContext)(_cg_shader);
|
||||
_cg_shader->load_shaders(); // Profiles created lets load from HD
|
||||
csc->load_shaders(); // Programs loaded, compile and download to GPU
|
||||
CGSHADERCONTEXTS::value_type shader_and_context(_cg_shader, csc);
|
||||
_gl_cg_shader_contexts.insert(shader_and_context);
|
||||
csc->bind(this);// Bind the new shader
|
||||
if (context != 0) {
|
||||
context->bind(mode);
|
||||
_shader_context = context;
|
||||
}
|
||||
} else {
|
||||
// Use the same shader as before, but with new input arguments.
|
||||
context->rebind(_shader_mode, mode);
|
||||
}
|
||||
report_my_gl_errors();
|
||||
}
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: GLGraphicsStateGuardian::issue_render_mode
|
||||
|
@ -27,6 +27,7 @@
|
||||
#include "textureAttrib.h"
|
||||
#include "texMatrixAttrib.h"
|
||||
#include "texGenAttrib.h"
|
||||
#include "shaderAttrib.h"
|
||||
#include "textureStage.h"
|
||||
#include "antialiasAttrib.h"
|
||||
#include "renderModeAttrib.h"
|
||||
@ -37,9 +38,8 @@
|
||||
#include "pmap.h"
|
||||
#include "geomVertexArrayData.h"
|
||||
#include "pmutex.h"
|
||||
#ifdef HAVE_CGGL
|
||||
#include "cgShader.h"
|
||||
#endif
|
||||
#include "shader.h"
|
||||
#include "shaderMode.h"
|
||||
|
||||
class PlaneNode;
|
||||
class Light;
|
||||
@ -102,6 +102,10 @@ public:
|
||||
|
||||
virtual GeomContext *prepare_geom(Geom *geom);
|
||||
virtual void release_geom(GeomContext *gc);
|
||||
|
||||
virtual ShaderContext *prepare_shader(Shader *shader);
|
||||
virtual void release_shader(ShaderContext *sc);
|
||||
|
||||
void record_deleted_display_list(GLuint index);
|
||||
|
||||
virtual VertexBufferContext *prepare_vertex_buffer(GeomVertexArrayData *data);
|
||||
@ -135,9 +139,7 @@ public:
|
||||
virtual void issue_fog(const FogAttrib *attrib);
|
||||
virtual void issue_depth_offset(const DepthOffsetAttrib *attrib);
|
||||
virtual void issue_shade_model(const ShadeModelAttrib *attrib);
|
||||
#ifdef HAVE_CGGL
|
||||
virtual void issue_cg_shader_bind(const CgShaderAttrib *attrib);
|
||||
#endif
|
||||
virtual void issue_shader(const ShaderAttrib *attrib);
|
||||
|
||||
virtual void do_issue_material();
|
||||
|
||||
@ -294,7 +296,9 @@ protected:
|
||||
bool _polygon_offset_enabled;
|
||||
bool _flat_shade_model;
|
||||
int _decal_level;
|
||||
|
||||
PT(ShaderMode) _shader_mode;
|
||||
CLP(ShaderContext) *_shader_context;
|
||||
|
||||
bool _dithering_enabled;
|
||||
bool _texgen_forced_normal;
|
||||
|
||||
@ -305,7 +309,6 @@ protected:
|
||||
RenderModeAttrib::Mode _render_mode;
|
||||
float _point_size;
|
||||
bool _point_perspective;
|
||||
|
||||
bool _vertex_blending_enabled;
|
||||
|
||||
CPT(DisplayRegion) _actual_display_region;
|
||||
@ -315,12 +318,6 @@ protected:
|
||||
bool _use_sender;
|
||||
#endif // SUPPORT_IMMEDIATE_MODE
|
||||
|
||||
#ifdef HAVE_CGGL
|
||||
PT(CgShader) _cg_shader; // The current CgShader object
|
||||
typedef pmap< PT(CgShader), PT(CLP(CgShaderContext)) > CGSHADERCONTEXTS;
|
||||
CGSHADERCONTEXTS _gl_cg_shader_contexts;// Associate CgShader with GLCgShaderContext
|
||||
#endif
|
||||
|
||||
int _pass_number;
|
||||
bool _auto_rescale_normal;
|
||||
GLuint _geom_display_list;
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "glIndexBufferContext_src.cxx"
|
||||
#include "glGeomContext_src.cxx"
|
||||
#include "glGeomMunger_src.cxx"
|
||||
#include "glCgShaderContext_src.cxx"
|
||||
#include "glShaderContext_src.cxx"
|
||||
#include "glImmediateModeSender_src.cxx"
|
||||
#include "glGraphicsStateGuardian_src.cxx"
|
||||
|
||||
|
@ -45,7 +45,7 @@
|
||||
#include "glIndexBufferContext_src.h"
|
||||
#include "glGeomContext_src.h"
|
||||
#include "glGeomMunger_src.h"
|
||||
#include "glCgShaderContext_src.h"
|
||||
#include "glShaderContext_src.h"
|
||||
#include "glImmediateModeSender_src.h"
|
||||
#include "glGraphicsStateGuardian_src.h"
|
||||
|
||||
|
@ -90,6 +90,8 @@
|
||||
selectiveChildNode.I selectiveChildNode.h \
|
||||
sequenceNode.I sequenceNode.h \
|
||||
shadeModelAttrib.I shadeModelAttrib.h \
|
||||
shaderMode.I shaderMode.h \
|
||||
shaderAttrib.I shaderAttrib.h \
|
||||
showBoundsEffect.I showBoundsEffect.h \
|
||||
spotlight.I spotlight.h \
|
||||
stateMunger.I stateMunger.h \
|
||||
@ -189,6 +191,8 @@
|
||||
selectiveChildNode.cxx \
|
||||
sequenceNode.cxx \
|
||||
shadeModelAttrib.cxx \
|
||||
shaderMode.cxx \
|
||||
shaderAttrib.cxx \
|
||||
showBoundsEffect.cxx \
|
||||
spotlight.cxx \
|
||||
stateMunger.cxx \
|
||||
@ -284,6 +288,8 @@
|
||||
selectiveChildNode.I selectiveChildNode.h \
|
||||
sequenceNode.I sequenceNode.h \
|
||||
shadeModelAttrib.I shadeModelAttrib.h \
|
||||
shaderMode.I shaderMode.h \
|
||||
shaderAttrib.I shaderAttrib.h \
|
||||
showBoundsEffect.I showBoundsEffect.h \
|
||||
spotlight.I spotlight.h \
|
||||
stateMunger.I stateMunger.h \
|
||||
|
@ -80,6 +80,8 @@
|
||||
#include "selectiveChildNode.h"
|
||||
#include "sequenceNode.h"
|
||||
#include "shadeModelAttrib.h"
|
||||
#include "shaderMode.h"
|
||||
#include "shaderAttrib.h"
|
||||
#include "showBoundsEffect.h"
|
||||
#include "spotlight.h"
|
||||
#include "stateMunger.h"
|
||||
@ -318,6 +320,8 @@ init_libpgraph() {
|
||||
SelectiveChildNode::init_type();
|
||||
SequenceNode::init_type();
|
||||
ShadeModelAttrib::init_type();
|
||||
ShaderMode::init_type();
|
||||
ShaderAttrib::init_type();
|
||||
ShowBoundsEffect::init_type();
|
||||
Spotlight::init_type();
|
||||
StateMunger::init_type();
|
||||
@ -374,6 +378,8 @@ init_libpgraph() {
|
||||
RenderState::register_with_read_factory();
|
||||
SequenceNode::register_with_read_factory();
|
||||
ShadeModelAttrib::register_with_read_factory();
|
||||
ShaderMode::register_with_read_factory();
|
||||
ShaderAttrib::register_with_read_factory();
|
||||
ShowBoundsEffect::register_with_read_factory();
|
||||
Spotlight::register_with_read_factory();
|
||||
SwitchNode::register_with_read_factory();
|
||||
|
@ -9,6 +9,8 @@
|
||||
#include "selectiveChildNode.cxx"
|
||||
#include "sequenceNode.cxx"
|
||||
#include "shadeModelAttrib.cxx"
|
||||
#include "shaderMode.cxx"
|
||||
#include "shaderAttrib.cxx"
|
||||
#include "showBoundsEffect.cxx"
|
||||
#include "spotlight.cxx"
|
||||
#include "stateMunger.cxx"
|
||||
|
53
panda/src/pgraph/shaderAttrib.I
Executable file
53
panda/src/pgraph/shaderAttrib.I
Executable file
@ -0,0 +1,53 @@
|
||||
// Filename: shaderAttrib.I
|
||||
// Created by: sshodhan (10Jul04)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderAttrib::Constructor
|
||||
// Access: Private
|
||||
// Description: Use ShaderAttrib::make() to construct a new
|
||||
// ShaderAttrib object.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE ShaderAttrib::
|
||||
ShaderAttrib() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderAttrib::is_off
|
||||
// Access: Published
|
||||
// Description: Returns true if the ShaderAttrib is an 'off'
|
||||
// ShaderAttrib, indicating that it should disable
|
||||
// the previous shader profiles
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE bool ShaderAttrib::
|
||||
is_off() const {
|
||||
return _shader_mode == (ShaderMode *)NULL;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderAttrib::get_shader_mode
|
||||
// Access: Published
|
||||
// Description: If the ShaderAttrib is not an 'off' ShaderAttrib,
|
||||
// returns the ShaderMode that is associated. Otherwise,
|
||||
// return NULL.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE ShaderMode *ShaderAttrib::
|
||||
get_shader_mode() const {
|
||||
return _shader_mode;
|
||||
}
|
||||
|
124
panda/src/pgraph/shaderAttrib.cxx
Executable file
124
panda/src/pgraph/shaderAttrib.cxx
Executable file
@ -0,0 +1,124 @@
|
||||
// Filename: shaderAttrib.cxx
|
||||
// Created by: sshodhan (10Jul04)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pandabase.h"
|
||||
#include "shaderAttrib.h"
|
||||
#include "config_effects.h"
|
||||
|
||||
#include "graphicsStateGuardianBase.h"
|
||||
#include "bamReader.h"
|
||||
#include "bamWriter.h"
|
||||
#include "datagram.h"
|
||||
#include "datagramIterator.h"
|
||||
|
||||
TypeHandle ShaderAttrib::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderAttrib::make
|
||||
// Access: Published, Static
|
||||
// Description: Constructs a new ShaderAttrib object suitable for
|
||||
// process the indicated geometry with shaders
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CPT(RenderAttrib) ShaderAttrib::
|
||||
make(ShaderMode *shader_mode) {
|
||||
ShaderAttrib *attrib = new ShaderAttrib;
|
||||
attrib->_shader_mode = shader_mode;
|
||||
return return_new(attrib);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderAttrib::make_off
|
||||
// Access: Published, Static
|
||||
// Description: Constructs a new ShaderAttrib object suitable for
|
||||
// rendering geometry with no shader interference
|
||||
////////////////////////////////////////////////////////////////////
|
||||
CPT(RenderAttrib) ShaderAttrib::
|
||||
make_off() {
|
||||
ShaderAttrib *attrib = new ShaderAttrib;
|
||||
return return_new(attrib);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderAttrib::issue
|
||||
// Access: Public, Virtual
|
||||
// Description: Calls the appropriate method on the indicated GSG
|
||||
// to issue the graphics commands appropriate to the
|
||||
// given attribute. This is normally called
|
||||
// (indirectly) only from
|
||||
// GraphicsStateGuardian::set_state() or modify_state().
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderAttrib::
|
||||
issue(GraphicsStateGuardianBase *gsg) const {
|
||||
gsg->issue_shader(this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderAttrib::make_default_impl
|
||||
// Access: Protected, Virtual
|
||||
// Description: Intended to be overridden by derived ShaderAttrib
|
||||
// types to specify what the default property for a
|
||||
// TexGenAttrib of this type should be.
|
||||
//
|
||||
// This should return a newly-allocated ShaderAttrib of
|
||||
// the same type that corresponds to whatever the
|
||||
// standard default for this kind of ShaderAttrib is.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
RenderAttrib *ShaderAttrib::
|
||||
make_default_impl() const {
|
||||
return new ShaderAttrib;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderAttrib::compare_to_impl
|
||||
// Access: Protected, Virtual
|
||||
// Description: Intended to be overridden by derived ShaderAttrib
|
||||
// types to return a unique number indicating whether
|
||||
// this ShaderAttrib is equivalent to the other one.
|
||||
//
|
||||
// This should return 0 if the two ShaderAttrib objects
|
||||
// are equivalent, a number less than zero if this one
|
||||
// should be sorted before the other one, and a number
|
||||
// greater than zero otherwise.
|
||||
//
|
||||
// This will only be called with two ShaderAttrib
|
||||
// objects whose get_type() functions return the same.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
int ShaderAttrib::
|
||||
compare_to_impl(const RenderAttrib *other) const {
|
||||
const ShaderAttrib *cgsa;
|
||||
DCAST_INTO_R(cgsa, other, 0);
|
||||
|
||||
// Comparing pointers by subtraction is problematic. Instead of
|
||||
// doing this, we'll just depend on the built-in != and < operators
|
||||
// for comparing pointers.
|
||||
if (_shader_mode != cgsa->_shader_mode) {
|
||||
return _shader_mode < cgsa->_shader_mode ? -1 : 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderAttrib::register_with_read_factory
|
||||
// Access: Public, Static
|
||||
// Description: Factory method to generate a Shader object
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderAttrib::
|
||||
register_with_read_factory() {
|
||||
// IMPLEMENT ME
|
||||
}
|
||||
|
86
panda/src/pgraph/shaderAttrib.h
Executable file
86
panda/src/pgraph/shaderAttrib.h
Executable file
@ -0,0 +1,86 @@
|
||||
// Filename: shaderAttrib.h
|
||||
// Created by: sshodhan (10Jul04)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SHADERATTRIB_H
|
||||
#define SHADERATTRIB_H
|
||||
|
||||
#include "pandabase.h"
|
||||
#include "luse.h"
|
||||
#include "pmap.h"
|
||||
#include "shader.h"
|
||||
#include "renderAttrib.h"
|
||||
#include "typedObject.h"
|
||||
#include "typedReferenceCount.h"
|
||||
#include "pointerTo.h"
|
||||
#include "factoryParam.h"
|
||||
#include "dcast.h"
|
||||
#include "shaderMode.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : ShaderAttrib
|
||||
// Description : fill me in
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EXPCL_PANDA ShaderAttrib: public RenderAttrib {
|
||||
|
||||
private:
|
||||
INLINE ShaderAttrib();
|
||||
|
||||
PUBLISHED:
|
||||
static CPT(RenderAttrib) make(ShaderMode *sm);
|
||||
static CPT(RenderAttrib) make_off();
|
||||
|
||||
INLINE bool is_off() const;
|
||||
INLINE ShaderMode *get_shader_mode() const;
|
||||
|
||||
static void register_with_read_factory();
|
||||
|
||||
virtual void issue(GraphicsStateGuardianBase *gsg) const;
|
||||
|
||||
protected:
|
||||
virtual RenderAttrib *make_default_impl() const;
|
||||
virtual int compare_to_impl(const RenderAttrib *other) const;
|
||||
|
||||
private:
|
||||
PT(ShaderMode) _shader_mode;
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
RenderAttrib::init_type();
|
||||
register_type(_type_handle, "ShaderAttrib",
|
||||
RenderAttrib::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
|
||||
#include "shaderAttrib.I"
|
||||
|
||||
#endif // SHADERATTRIB_H
|
||||
|
||||
|
||||
|
47
panda/src/pgraph/shaderMode.I
Executable file
47
panda/src/pgraph/shaderMode.I
Executable file
@ -0,0 +1,47 @@
|
||||
// Filename: shaderMode.I
|
||||
// Heavily Modified: jyelon (01Sep05)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderModeArg::Constructor
|
||||
// Access: Public
|
||||
// Description: initialize a shader arg storage structure.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE ShaderModeArg::
|
||||
ShaderModeArg(void) {
|
||||
_type = SAT_INVALID;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderModeArg::Destructor
|
||||
// Access: Public
|
||||
// Description: delete a shader arg storage structure.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE ShaderModeArg::
|
||||
~ShaderModeArg(void) {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::get_shader
|
||||
// Access: Public
|
||||
// Description: Return the Shader associated with this shader mode.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE Shader *ShaderMode::
|
||||
get_shader(void) {
|
||||
return _shader;
|
||||
}
|
||||
|
237
panda/src/pgraph/shaderMode.cxx
Executable file
237
panda/src/pgraph/shaderMode.cxx
Executable file
@ -0,0 +1,237 @@
|
||||
// Filename: shaderMode.cxx
|
||||
// Created by: jyelon (01Sep05)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "pandabase.h"
|
||||
#include "shader.h"
|
||||
#include "shaderMode.h"
|
||||
#include "virtualFileSystem.h"
|
||||
|
||||
TypeHandle ShaderMode::_type_handle;
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::load
|
||||
// Access: Published
|
||||
// Description: Obtain the shader associated with the specified
|
||||
// file and construct a ShaderMode for that shader.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(ShaderMode) ShaderMode::
|
||||
load(const Filename &file)
|
||||
{
|
||||
string text;
|
||||
VirtualFileSystem *vfs = VirtualFileSystem::get_global_ptr();
|
||||
if (!vfs->read_file(file, text)) {
|
||||
cerr << "Could not read " << file << "\n";
|
||||
return new ShaderMode(new Shader("", file));
|
||||
}
|
||||
return new ShaderMode(new Shader(text, file));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::load
|
||||
// Access: Published
|
||||
// Description: Obtain the shader associated with the specified
|
||||
// file and construct a ShaderMode for that shader.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(ShaderMode) ShaderMode::
|
||||
load(const string &file)
|
||||
{
|
||||
Filename fn(file);
|
||||
return load(fn);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::make
|
||||
// Access: Published
|
||||
// Description: Obtain the shader associated with the specified
|
||||
// text and construct a ShaderMode for that shader.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
PT(ShaderMode) ShaderMode::
|
||||
make(const string &text)
|
||||
{
|
||||
return new ShaderMode(new Shader(text, ""));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::Constructor
|
||||
// Access: Published
|
||||
// Description: Use to construct a new shader instance.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
ShaderMode::
|
||||
ShaderMode(Shader *shader) {
|
||||
_shader = shader;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::Destructor
|
||||
// Access: Public
|
||||
// Description: delete a shader
|
||||
////////////////////////////////////////////////////////////////////
|
||||
ShaderMode::
|
||||
~ShaderMode() {
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::mod_param
|
||||
// Access: Private
|
||||
// Description: To set a parameter, you must first access it and
|
||||
// then clear it. This function accesses then clears
|
||||
// the storage for a parameter, prior to setting it.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
INLINE ShaderModeArg *ShaderMode::
|
||||
mod_param(const string &pname, int t) {
|
||||
int index = _shader->arg_index(pname);
|
||||
if (index >= (int)(_args.size()))
|
||||
_args.resize(index+1);
|
||||
ShaderModeArg *arg = &(_args[index]);
|
||||
arg->_type = t;
|
||||
arg->_nvalue = NodePath();
|
||||
arg->_tvalue = (Texture*)NULL;
|
||||
arg->_fvalue = LVector4d(0,0,0,0);
|
||||
return arg;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::set_param texture
|
||||
// Access: Public
|
||||
// Description: Store texture in the map to associate with
|
||||
// param name
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
set_param(const string &pname, Texture *x) {
|
||||
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_TEXTURE);
|
||||
arg->_tvalue = x;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::set_param nodepath
|
||||
// Access: Public
|
||||
// Description: Store nodepath in the map to associate with
|
||||
// param name
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
set_param(const string &pname, const NodePath &x) {
|
||||
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_NODEPATH);
|
||||
arg->_nvalue = x;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::set_param 1f
|
||||
// Access: Public
|
||||
// Description: Store 1f in the map to associate with
|
||||
// param name
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
set_param(const string &pname, float x) {
|
||||
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
|
||||
arg->_fvalue = LVector4d(x,0,0,0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::set_param 2f
|
||||
// Access: Public
|
||||
// Description: Store 2f in the map to associate with
|
||||
// param name
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
set_param(const string &pname, LVector2f x) {
|
||||
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
|
||||
arg->_fvalue = LVector4d(x[0],x[1],0,0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::set_param 3f
|
||||
// Access: Public
|
||||
// Description: Store 3f in the map to associate with
|
||||
// param name
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
set_param(const string &pname, LVector3f x) {
|
||||
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
|
||||
arg->_fvalue = LVector4d(x[0],x[1],x[2],0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::set_param 4f
|
||||
// Access: Public
|
||||
// Description: Store 4f in the map to associate with
|
||||
// param name
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
set_param(const string &pname, LVector4f x) {
|
||||
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
|
||||
arg->_fvalue = LVector4d(x[0],x[1],x[2],x[3]);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::set_param 1d
|
||||
// Access: Public
|
||||
// Description: Store 1d in the map to associate with
|
||||
// param name
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
set_param(const string &pname, double x) {
|
||||
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
|
||||
arg->_fvalue = LVector4d(x,0,0,0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::set_param 2d
|
||||
// Access: Public
|
||||
// Description: Store 2d in the map to associate with
|
||||
// param name
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
set_param(const string &pname, LVector2d x) {
|
||||
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
|
||||
arg->_fvalue = LVector4d(x[0],x[1],0,0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::set_param 3d
|
||||
// Access: Public
|
||||
// Description: Store 3d in the map to associate with
|
||||
// param name
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
set_param(const string &pname, LVector3d x) {
|
||||
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
|
||||
arg->_fvalue = LVector4d(x[0],x[1],x[2],0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::set_param 4d
|
||||
// Access: Public
|
||||
// Description: Store 4d in the map to associate with
|
||||
// param name
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
set_param(const string &pname, LVector4d x) {
|
||||
ShaderModeArg *arg = mod_param(pname, ShaderModeArg::SAT_FLOAT);
|
||||
arg->_fvalue = x;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Function: ShaderMode::register_with_read_factory
|
||||
// Access: Public, Static
|
||||
// Description: Factory method to generate a ShaderMode object
|
||||
////////////////////////////////////////////////////////////////////
|
||||
void ShaderMode::
|
||||
register_with_read_factory() {
|
||||
// IMPLEMENT ME
|
||||
}
|
||||
|
117
panda/src/pgraph/shaderMode.h
Executable file
117
panda/src/pgraph/shaderMode.h
Executable file
@ -0,0 +1,117 @@
|
||||
// Filename: shaderMode.h
|
||||
// Created by: jyelon (01Sep05)
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PANDA 3D SOFTWARE
|
||||
// Copyright (c) 2001 - 2004, Disney Enterprises, Inc. All rights reserved
|
||||
//
|
||||
// All use of this software is subject to the terms of the Panda 3d
|
||||
// Software license. You should have received a copy of this license
|
||||
// along with this source code; you will also find a current copy of
|
||||
// the license at http://etc.cmu.edu/panda3d/docs/license/ .
|
||||
//
|
||||
// To contact the maintainers of this program write to
|
||||
// panda3d-general@lists.sourceforge.net .
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SHADERMODE_H
|
||||
#define SHADERMODE_H
|
||||
|
||||
#include "pandabase.h"
|
||||
#include "nodePath.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : ShaderModeArg
|
||||
// Description : The ShaderModeArg is a small structure designed to hold
|
||||
// any of the various kinds of values that can be
|
||||
// passed to a shader. Basically, it is a temporary
|
||||
// storage repository for shader input parameters.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class ShaderModeArg
|
||||
{
|
||||
public:
|
||||
enum ShaderModeArgType
|
||||
{
|
||||
SAT_INVALID,
|
||||
SAT_FLOAT,
|
||||
SAT_TEXTURE,
|
||||
SAT_NODEPATH,
|
||||
};
|
||||
|
||||
INLINE ShaderModeArg(void);
|
||||
INLINE ~ShaderModeArg(void);
|
||||
|
||||
int _type;
|
||||
NodePath _nvalue;
|
||||
PT(Texture) _tvalue;
|
||||
LVector4d _fvalue;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////
|
||||
// Class : ShaderMode
|
||||
// Summary: The ShaderMode object contains a Shader and a
|
||||
// list of input data to pass into the shader when
|
||||
// it is executing.
|
||||
////////////////////////////////////////////////////////////////////
|
||||
|
||||
class EXPCL_PANDA ShaderMode: public TypedWritableReferenceCount {
|
||||
|
||||
public:
|
||||
PT(Shader) _shader;
|
||||
vector<ShaderModeArg> _args;
|
||||
|
||||
PUBLISHED:
|
||||
ShaderMode(Shader *body);
|
||||
|
||||
static PT(ShaderMode) load(const string &file);
|
||||
static PT(ShaderMode) load(const Filename &file);
|
||||
static PT(ShaderMode) make(const string &text);
|
||||
|
||||
~ShaderMode();
|
||||
|
||||
INLINE Shader *get_shader(void);
|
||||
|
||||
// Overloaded set_param to be used based on your param type
|
||||
void set_param(const string &pname, Texture *t);
|
||||
void set_param(const string &pname, const NodePath &np);
|
||||
void set_param(const string &pname, float p1f);
|
||||
void set_param(const string &pname, LVector2f p2f);
|
||||
void set_param(const string &pname, LVector3f p3f);
|
||||
void set_param(const string &pname, LVector4f p4f);
|
||||
void set_param(const string &pname, double p1d);
|
||||
void set_param(const string &pname, LVector2d p2d);
|
||||
void set_param(const string &pname, LVector3d p3d);
|
||||
void set_param(const string &pname, LVector4d p4d);
|
||||
|
||||
static void register_with_read_factory(void);
|
||||
|
||||
private:
|
||||
ShaderModeArg *mod_param(const string &pname, int kind);
|
||||
|
||||
public:
|
||||
static TypeHandle get_class_type() {
|
||||
return _type_handle;
|
||||
}
|
||||
static void init_type() {
|
||||
TypedWritableReferenceCount::init_type();
|
||||
register_type(_type_handle, "ShaderMode",
|
||||
TypedWritableReferenceCount::get_class_type());
|
||||
}
|
||||
virtual TypeHandle get_type() const {
|
||||
return get_class_type();
|
||||
}
|
||||
virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
|
||||
|
||||
private:
|
||||
static TypeHandle _type_handle;
|
||||
};
|
||||
|
||||
|
||||
#include "shaderMode.I"
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user