From 32a6c8fd95ed4db83b6f998d33ff773d66eed389 Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Thu, 2 Aug 2007 22:02:10 +0000 Subject: [PATCH] Fixes some bugs in cg parameter handling --- panda/src/glstuff/glShaderContext_src.cxx | 26 +++++++++++++++++++++++ panda/src/glstuff/glShaderContext_src.h | 1 + panda/src/gobj/shaderExpansion.cxx | 23 ++++++++++++++++++++ panda/src/gobj/shaderExpansion.h | 1 + 4 files changed, 51 insertions(+) diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index 5282e2e40d..50f62d881c 100755 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -117,6 +117,7 @@ bind(GSG *gsg) { cgGLBindProgram(_cg_vprogram); cgGLEnableProfile(cgGetProgramProfile(_cg_fprogram)); cgGLBindProgram(_cg_fprogram); + cg_report_errors(); } #endif } @@ -132,6 +133,7 @@ unbind() { if (_cg_context != 0) { cgGLDisableProfile(cgGetProgramProfile(_cg_vprogram)); cgGLDisableProfile(cgGetProgramProfile(_cg_fprogram)); + cg_report_errors(); } #endif } @@ -179,6 +181,7 @@ issue_parameters(GSG *gsg, bool altered) { } } } + cg_report_errors(); #endif } @@ -196,8 +199,10 @@ disable_shader_vertex_arrays(GSG *gsg) { for (int i=0; i<(int)_expansion->_var_spec.size(); i++) { CGparameter p = _cg_parameter_map[_expansion->_var_spec[i]._id._seqno]; + if (p == 0) continue; cgGLDisableClientState(p); } + cg_report_errors(); #endif } @@ -220,6 +225,7 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg, if (_cg_context == 0) { return true; } + cg_report_errors(); #ifdef SUPPORT_IMMEDIATE_MODE if (gsg->_use_sender) { @@ -233,6 +239,7 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg, int nvarying = _expansion->_var_spec.size(); for (int i=0; i_var_spec[i]._id._seqno]; + if (p == 0) continue; InternalName *name = _expansion->_var_spec[i]._name; int texslot = _expansion->_var_spec[i]._append_uv; if (texslot >= 0) { @@ -264,6 +271,7 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg, } } } + cg_report_errors(); #endif // HAVE_CG return true; } @@ -282,6 +290,7 @@ disable_shader_texture_bindings(GSG *gsg) { for (int i=0; i<(int)_expansion->_tex_spec.size(); i++) { CGparameter p = _cg_parameter_map[_expansion->_tex_spec[i]._id._seqno]; + if (p == 0) continue; int texunit = cgGetParameterResourceIndex(p); gsg->_glActiveTexture(GL_TEXTURE0 + texunit); GLP(Disable)(GL_TEXTURE_1D); @@ -295,6 +304,7 @@ disable_shader_texture_bindings(GSG *gsg) { // This is probably faster - but maybe not as safe? // cgGLDisableTextureParameter(p); } + cg_report_errors(); #endif } @@ -319,6 +329,7 @@ update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg) { for (int i=0; i<(int)_expansion->_tex_spec.size(); i++) { CGparameter p = _cg_parameter_map[_expansion->_tex_spec[i]._id._seqno]; + if (p == 0) continue; Texture *tex = 0; InternalName *id = _expansion->_tex_spec[i]._name; if (id != 0) { @@ -358,6 +369,21 @@ update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg) { gsg->apply_texture(tc); } + cg_report_errors(); #endif } +//////////////////////////////////////////////////////////////////// +// Function: GLShaderContext::cg_report_errors +// Access: Public +// Description: Report any Cg errors that were not previously caught. +//////////////////////////////////////////////////////////////////// +#ifdef HAVE_CG +void CLP(ShaderContext):: +cg_report_errors() { + CGerror err = cgGetError(); + if (err != CG_NO_ERROR) { + GLCAT.error() << _expansion->get_name() << " " << cgGetErrorString(err) << "\n"; + } +} +#endif diff --git a/panda/src/glstuff/glShaderContext_src.h b/panda/src/glstuff/glShaderContext_src.h index 81f70f6d50..64aeb39edc 100755 --- a/panda/src/glstuff/glShaderContext_src.h +++ b/panda/src/glstuff/glShaderContext_src.h @@ -55,6 +55,7 @@ private: CGprogram _cg_vprogram; CGprogram _cg_fprogram; pvector _cg_parameter_map; + void cg_report_errors(); #endif void release_resources(void); diff --git a/panda/src/gobj/shaderExpansion.cxx b/panda/src/gobj/shaderExpansion.cxx index 2f303a64e1..f8ff18767c 100644 --- a/panda/src/gobj/shaderExpansion.cxx +++ b/panda/src/gobj/shaderExpansion.cxx @@ -770,6 +770,20 @@ cg_release_resources() { _cg_context = 0; } } + +//////////////////////////////////////////////////////////////////// +// Function: ShaderExpansion::cg_report_errors +// Access: Private +// Description: xyz +//////////////////////////////////////////////////////////////////// +void ShaderExpansion:: +cg_report_errors() { + CGerror err = cgGetError(); + if (err != CG_NO_ERROR) { + gobj_cat.error() << _name << " " << cgGetErrorString(err) << "\n"; + } +} + //////////////////////////////////////////////////////////////////// // Function: ShaderExpansion::cg_compile_entry_point // Access: Private @@ -785,6 +799,8 @@ cg_compile_entry_point(char *entry, const ShaderCaps &caps, bool fshader) int active = fshader ? caps._active_fprofile : caps._active_vprofile; int ultimate = fshader ? caps._ultimate_fprofile : caps._ultimate_vprofile; + cg_report_errors(); + if (fshader && caps._bug_list.count(SBUG_ati_draw_buffers)) { compiler_args[nargs++] = "-po"; compiler_args[nargs++] = "ATI_draw_buffers"; @@ -824,6 +840,7 @@ cg_compile_entry_point(char *entry, const ShaderCaps &caps, bool fshader) if (prog != 0) { cgDestroyProgram(prog); } + return 0; } @@ -1110,11 +1127,17 @@ cg_compile_for(const ShaderCaps &caps, const ShaderArgId &id = _tex_spec[i]._id; CGprogram prog = (id._fshader) ? _cg_fprogram : _cg_vprogram; map[id._seqno] = cgGetNamedParameter(prog, id._name.c_str()); + if (cgGetParameterBaseResource(map[id._seqno]) == CG_UNDEFINED) { + map[id._seqno] = 0; + } } for (int i=0; i