Browse Source

Fix an issue with programs being destroyed and then reused by different copies of the same shader. Also, added better error reporting system for Cg errors.

rdb 16 years ago
parent
commit
30a2c57cb3
2 changed files with 16 additions and 19 deletions
  1. 16 18
      panda/src/glstuff/glShaderContext_src.cxx
  2. 0 1
      panda/src/glstuff/glShaderContext_src.h

+ 16 - 18
panda/src/glstuff/glShaderContext_src.cxx

@@ -27,6 +27,18 @@ TypeHandle CLP(ShaderContext)::_type_handle;
 #define GL_GEOMETRY_SHADER 0x8DD9
 #define GL_GEOMETRY_SHADER 0x8DD9
 #endif
 #endif
 
 
+#ifdef HAVE_CG
+#ifndef NDEBUG
+#define cg_report_errors() { \
+  CGerror err = cgGetError(); \
+  if (err != CG_NO_ERROR) { \
+    GLCAT.error() << __FILE__ ", line " << __LINE__ << ": " << cgGetErrorString(err) << "\n"; \
+  } }
+#else
+#define cg_report_errors()
+#endif
+#endif
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: GLShaderContext::Constructor
 //     Function: GLShaderContext::Constructor
 //       Access: Public
 //       Access: Public
@@ -354,9 +366,10 @@ release_resources(GSG *gsg) {
   if (_cg_context) {
   if (_cg_context) {
     cgDestroyContext(_cg_context);
     cgDestroyContext(_cg_context);
     _cg_context  = 0;
     _cg_context  = 0;
-    if (_cg_vprogram != 0) cgDestroyProgram(_cg_vprogram);
-    if (_cg_fprogram != 0) cgDestroyProgram(_cg_fprogram);
-    if (_cg_gprogram != 0) cgDestroyProgram(_cg_gprogram);
+    // Do *NOT* destroy the programs here! It causes problems.
+//  if (_cg_vprogram != 0) cgDestroyProgram(_cg_vprogram);
+//  if (_cg_fprogram != 0) cgDestroyProgram(_cg_fprogram);
+//  if (_cg_gprogram != 0) cgDestroyProgram(_cg_gprogram);
     _cg_vprogram = 0;
     _cg_vprogram = 0;
     _cg_fprogram = 0;
     _cg_fprogram = 0;
     _cg_gprogram = 0;
     _cg_gprogram = 0;
@@ -838,21 +851,6 @@ update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg) {
   gsg->report_my_gl_errors();
   gsg->report_my_gl_errors();
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     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() << cgGetErrorString(err) << "\n";
-  }
-}
-#endif
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Shader::glsl_report_shader_errors
 //     Function: Shader::glsl_report_shader_errors
 //       Access: Private
 //       Access: Private

+ 0 - 1
panda/src/glstuff/glShaderContext_src.h

@@ -58,7 +58,6 @@ private:
   CGprogram _cg_gprogram;
   CGprogram _cg_gprogram;
 
 
   pvector <CGparameter> _cg_parameter_map;
   pvector <CGparameter> _cg_parameter_map;
-  void cg_report_errors();
 #endif
 #endif
   
   
   GLuint _glsl_program;
   GLuint _glsl_program;