mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-18 12:43:44 -04:00
glCgShader files added updates to glStateGuardian...
This commit is contained in:
parent
2a6d6944b6
commit
216f78cb19
@ -1,6 +1,6 @@
|
|||||||
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
|
#define OTHER_LIBS interrogatedb:c dconfig:c dtoolconfig:m \
|
||||||
dtoolutil:c dtoolbase:c dtool:m
|
dtoolutil:c dtoolbase:c dtool:m
|
||||||
|
#define USE_PACKAGES gl cggl
|
||||||
// Most of the files here are not actually compiled into anything;
|
// Most of the files here are not actually compiled into anything;
|
||||||
// they're just included by various other directories.
|
// they're just included by various other directories.
|
||||||
|
|
||||||
@ -8,7 +8,8 @@
|
|||||||
#define TARGET glstuff
|
#define TARGET glstuff
|
||||||
#define LOCAL_LIBS \
|
#define LOCAL_LIBS \
|
||||||
gsgmisc gsgbase gobj display \
|
gsgmisc gsgbase gobj display \
|
||||||
putil linmath mathutil pnmimage
|
putil linmath mathutil pnmimage \
|
||||||
|
effects
|
||||||
|
|
||||||
#define INSTALL_HEADERS \
|
#define INSTALL_HEADERS \
|
||||||
glext.h \
|
glext.h \
|
||||||
@ -26,7 +27,10 @@
|
|||||||
glSavedFrameBuffer_src.h \
|
glSavedFrameBuffer_src.h \
|
||||||
glTextureContext_src.cxx \
|
glTextureContext_src.cxx \
|
||||||
glTextureContext_src.I \
|
glTextureContext_src.I \
|
||||||
glTextureContext_src.h
|
glTextureContext_src.h \
|
||||||
|
glCgShaderContext_src.cxx \
|
||||||
|
glCgShaderContext_src.h \
|
||||||
|
glCgShaderContext_src.I \
|
||||||
|
|
||||||
#define SOURCES \
|
#define SOURCES \
|
||||||
$[INSTALL_HEADERS] glpure.cxx
|
$[INSTALL_HEADERS] glpure.cxx
|
||||||
|
219
panda/src/glstuff/glCgShaderContext_src.I
Executable file
219
panda/src/glstuff/glCgShaderContext_src.I
Executable file
@ -0,0 +1,219 @@
|
|||||||
|
// 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) {
|
||||||
|
bool res = 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
|
425
panda/src/glstuff/glCgShaderContext_src.cxx
Executable file
425
panda/src/glstuff/glCgShaderContext_src.cxx
Executable file
@ -0,0 +1,425 @@
|
|||||||
|
// 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:
|
||||||
|
// M_MODELVIEW,M_PROJECTION,M_TEXTURE,M_MODELVIEW_PROJECTION,
|
||||||
|
// and they can have th transforms:
|
||||||
|
// T_IDENTITY,T_TRANSPOSE,T_INVERSE,T_INVERSE_TRANSPOSE,
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void CLP(CgShaderContext)::
|
||||||
|
set_param(const string &pname, CgShader::Matrix_Type m, CgShader::Transform_Type t,
|
||||||
|
bool vert_or_frag) {
|
||||||
|
// MODELVIEW BEGINS
|
||||||
|
if (m == M_MODELVIEW) {
|
||||||
|
if (t == T_IDENTITY) {
|
||||||
|
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 == T_TRANSPOSE) {
|
||||||
|
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 == T_INVERSE) {
|
||||||
|
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 == T_INVERSE_TRANSPOSE) {
|
||||||
|
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 == M_PROJECTION) {
|
||||||
|
if (t == T_IDENTITY) {
|
||||||
|
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 == T_TRANSPOSE) {
|
||||||
|
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 == T_INVERSE) {
|
||||||
|
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 == T_INVERSE_TRANSPOSE) {
|
||||||
|
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 == M_TEXTURE) {
|
||||||
|
if (t == T_IDENTITY) {
|
||||||
|
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 == T_TRANSPOSE) {
|
||||||
|
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 == T_INVERSE) {
|
||||||
|
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 == T_INVERSE_TRANSPOSE) {
|
||||||
|
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 == M_MODELVIEW_PROJECTION) {
|
||||||
|
if (t == T_IDENTITY) {
|
||||||
|
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 == T_TRANSPOSE) {
|
||||||
|
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 == T_INVERSE) {
|
||||||
|
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 == T_INVERSE_TRANSPOSE) {
|
||||||
|
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
|
109
panda/src/glstuff/glCgShaderContext_src.h
Executable file
109
panda/src/glstuff/glCgShaderContext_src.h
Executable file
@ -0,0 +1,109 @@
|
|||||||
|
// 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
|
||||||
|
|
@ -39,6 +39,7 @@
|
|||||||
#include "colorWriteAttrib.h"
|
#include "colorWriteAttrib.h"
|
||||||
#include "texMatrixAttrib.h"
|
#include "texMatrixAttrib.h"
|
||||||
#include "texGenAttrib.h"
|
#include "texGenAttrib.h"
|
||||||
|
#include "cgShaderAttrib.h"
|
||||||
#include "materialAttrib.h"
|
#include "materialAttrib.h"
|
||||||
#include "renderModeAttrib.h"
|
#include "renderModeAttrib.h"
|
||||||
#include "fogAttrib.h"
|
#include "fogAttrib.h"
|
||||||
@ -51,7 +52,6 @@
|
|||||||
#include "pvector.h"
|
#include "pvector.h"
|
||||||
#include "vector_string.h"
|
#include "vector_string.h"
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
|
|
||||||
#ifdef DO_PSTATS
|
#ifdef DO_PSTATS
|
||||||
#include "pStatTimer.h"
|
#include "pStatTimer.h"
|
||||||
#endif
|
#endif
|
||||||
@ -241,6 +241,9 @@ CLP(GraphicsStateGuardian)(const FrameBufferProperties &properties) :
|
|||||||
GraphicsStateGuardian(properties)
|
GraphicsStateGuardian(properties)
|
||||||
{
|
{
|
||||||
_error_count = 0;
|
_error_count = 0;
|
||||||
|
#ifdef HAVE_CGGL
|
||||||
|
_cg_shader = (CgShader *)NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -384,6 +387,10 @@ reset() {
|
|||||||
enable_line_smooth(false);
|
enable_line_smooth(false);
|
||||||
enable_multisample(true);
|
enable_multisample(true);
|
||||||
|
|
||||||
|
#ifdef HAVE_CGGL
|
||||||
|
_cg_shader = (CgShader *)NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
// Should we normalize lighting normals?
|
// Should we normalize lighting normals?
|
||||||
if (CLP(auto_normalize_lighting)) {
|
if (CLP(auto_normalize_lighting)) {
|
||||||
GLP(Enable)(GL_NORMALIZE);
|
GLP(Enable)(GL_NORMALIZE);
|
||||||
@ -1411,6 +1418,7 @@ draw_quad(GeomQuad *geom, GeomContext *gc) {
|
|||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
void CLP(GraphicsStateGuardian)::
|
void CLP(GraphicsStateGuardian)::
|
||||||
draw_tristrip(GeomTristrip *geom, GeomContext *gc) {
|
draw_tristrip(GeomTristrip *geom, GeomContext *gc) {
|
||||||
|
|
||||||
#ifdef GSG_VERBOSE
|
#ifdef GSG_VERBOSE
|
||||||
GLCAT.spam() << "draw_tristrip()" << endl;
|
GLCAT.spam() << "draw_tristrip()" << endl;
|
||||||
#endif
|
#endif
|
||||||
@ -1503,6 +1511,7 @@ draw_tristrip(GeomTristrip *geom, GeomContext *gc) {
|
|||||||
|
|
||||||
report_my_gl_errors();
|
report_my_gl_errors();
|
||||||
DO_PSTATS_STUFF(_draw_primitive_pcollector.stop());
|
DO_PSTATS_STUFF(_draw_primitive_pcollector.stop());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
@ -1713,6 +1722,8 @@ TextureContext *CLP(GraphicsStateGuardian)::
|
|||||||
prepare_texture(Texture *tex) {
|
prepare_texture(Texture *tex) {
|
||||||
CLP(TextureContext) *gtc = new CLP(TextureContext)(tex);
|
CLP(TextureContext) *gtc = new CLP(TextureContext)(tex);
|
||||||
GLP(GenTextures)(1, >c->_index);
|
GLP(GenTextures)(1, >c->_index);
|
||||||
|
//cerr << "preparing texture " << tex->get_name() << ", assigning "
|
||||||
|
// << gtc->_index << "\n";
|
||||||
|
|
||||||
bind_texture(gtc);
|
bind_texture(gtc);
|
||||||
GLP(PrioritizeTextures)(1, >c->_index, >c->_priority);
|
GLP(PrioritizeTextures)(1, >c->_index, >c->_priority);
|
||||||
@ -2192,6 +2203,49 @@ issue_tex_matrix(const TexMatrixAttrib *attrib) {
|
|||||||
report_my_gl_errors();
|
report_my_gl_errors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
// Function: CLP(GraphicsStateGuardian)::issue_cg_shader_bind
|
||||||
|
// 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
|
||||||
|
////////////////////////////////////////////////////////////////////
|
||||||
|
void CLP(GraphicsStateGuardian)::
|
||||||
|
issue_cg_shader_bind(const CgShaderAttrib *attrib) {
|
||||||
|
#ifdef HAVE_CGGL
|
||||||
|
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
|
||||||
|
}
|
||||||
|
_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);
|
||||||
|
bool result = _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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////
|
||||||
// Function: CLP(GraphicsStateGuardian)::issue_tex_gen
|
// Function: CLP(GraphicsStateGuardian)::issue_tex_gen
|
||||||
// Access: Public, Virtual
|
// Access: Public, Virtual
|
||||||
|
@ -30,7 +30,8 @@
|
|||||||
#include "fog.h"
|
#include "fog.h"
|
||||||
#include "graphicsWindow.h"
|
#include "graphicsWindow.h"
|
||||||
#include "pset.h"
|
#include "pset.h"
|
||||||
|
#include "pmap.h"
|
||||||
|
#include "cgShader.h"
|
||||||
class PlaneNode;
|
class PlaneNode;
|
||||||
class Light;
|
class Light;
|
||||||
|
|
||||||
@ -104,6 +105,7 @@ public:
|
|||||||
virtual void issue_fog(const FogAttrib *attrib);
|
virtual void issue_fog(const FogAttrib *attrib);
|
||||||
virtual void issue_depth_offset(const DepthOffsetAttrib *attrib);
|
virtual void issue_depth_offset(const DepthOffsetAttrib *attrib);
|
||||||
virtual void issue_tex_gen(const TexGenAttrib *attrib);
|
virtual void issue_tex_gen(const TexGenAttrib *attrib);
|
||||||
|
virtual void issue_cg_shader_bind(const CgShaderAttrib *attrib);
|
||||||
// virtual void issue_stencil(const StencilAttrib *attrib);
|
// virtual void issue_stencil(const StencilAttrib *attrib);
|
||||||
|
|
||||||
virtual void bind_light(PointLight *light, int light_id);
|
virtual void bind_light(PointLight *light, int light_id);
|
||||||
@ -297,6 +299,11 @@ protected:
|
|||||||
int _projection_mat_stack_count;
|
int _projection_mat_stack_count;
|
||||||
|
|
||||||
CPT(DisplayRegion) _actual_display_region;
|
CPT(DisplayRegion) _actual_display_region;
|
||||||
|
#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;
|
int _pass_number;
|
||||||
|
|
||||||
|
@ -25,5 +25,7 @@
|
|||||||
#include "glTextureContext_src.cxx"
|
#include "glTextureContext_src.cxx"
|
||||||
#include "glGeomContext_src.cxx"
|
#include "glGeomContext_src.cxx"
|
||||||
#include "glSavedFrameBuffer_src.cxx"
|
#include "glSavedFrameBuffer_src.cxx"
|
||||||
|
#include "glCgShaderContext_src.cxx"
|
||||||
#include "glGraphicsStateGuardian_src.cxx"
|
#include "glGraphicsStateGuardian_src.cxx"
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,5 +43,7 @@
|
|||||||
#include "glTextureContext_src.h"
|
#include "glTextureContext_src.h"
|
||||||
#include "glGeomContext_src.h"
|
#include "glGeomContext_src.h"
|
||||||
#include "glSavedFrameBuffer_src.h"
|
#include "glSavedFrameBuffer_src.h"
|
||||||
|
#include "glCgShaderContext_src.h"
|
||||||
#include "glGraphicsStateGuardian_src.h"
|
#include "glGraphicsStateGuardian_src.h"
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user