Переглянути джерело

Added some error-checking

Josh Yelon 18 роки тому
батько
коміт
6fe75c8eed

+ 60 - 7
panda/src/glstuff/glGraphicsBuffer_src.cxx

@@ -74,7 +74,7 @@ CLP(GraphicsBuffer)::
       }      
       }      
       graphics_buffer_iterator = _shared_depth_buffer_list.begin( );
       graphics_buffer_iterator = _shared_depth_buffer_list.begin( );
     }
     }
-  }  
+  }
 }
 }
  
  
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -90,6 +90,8 @@ bool CLP(GraphicsBuffer)::
 begin_frame(FrameMode mode, Thread *current_thread) {
 begin_frame(FrameMode mode, Thread *current_thread) {
   begin_frame_spam(mode);
   begin_frame_spam(mode);
 
 
+  check_host_valid();
+  
   if (!_is_valid) {
   if (!_is_valid) {
     if (GLCAT.is_debug()) {
     if (GLCAT.is_debug()) {
       GLCAT.debug()
       GLCAT.debug()
@@ -120,6 +122,7 @@ begin_frame(FrameMode mode, Thread *current_thread) {
   }
   }
 
 
   _gsg->set_current_properties(&get_fb_properties());
   _gsg->set_current_properties(&get_fb_properties());
+  report_my_gl_errors();
   return true;
   return true;
 }
 }
 
 
@@ -158,8 +161,10 @@ check_fbo() {
     }
     }
     
     
     glgsg->bind_fbo(0);
     glgsg->bind_fbo(0);
+    report_my_gl_errors();
     return false;
     return false;
   }
   }
+  report_my_gl_errors();
   return true;
   return true;
 }
 }
 
 
@@ -173,6 +178,11 @@ check_fbo() {
 void CLP(GraphicsBuffer)::
 void CLP(GraphicsBuffer)::
 rebuild_bitplanes() {
 rebuild_bitplanes() {
 
 
+  check_host_valid();
+  if (_gsg == 0) {
+    return;
+  }
+  
   CLP(GraphicsStateGuardian) *glgsg;
   CLP(GraphicsStateGuardian) *glgsg;
   DCAST_INTO_V(glgsg, _gsg);
   DCAST_INTO_V(glgsg, _gsg);
 
 
@@ -181,7 +191,7 @@ rebuild_bitplanes() {
   if (_fbo == 0) {
   if (_fbo == 0) {
     glgsg->_glGenFramebuffers(1, &_fbo);
     glgsg->_glGenFramebuffers(1, &_fbo);
     if (_fbo == 0) {
     if (_fbo == 0) {
-      glgsg->report_my_gl_errors();
+      report_my_gl_errors();
       return;
       return;
     }
     }
   }
   }
@@ -274,7 +284,7 @@ rebuild_bitplanes() {
   }
   }
   _cube_face_active = 0;
   _cube_face_active = 0;
   
   
-  glgsg->report_my_gl_errors();
+  report_my_gl_errors();
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -441,7 +451,7 @@ generate_mipmaps() {
       GLP(BindTexture)(target, 0);
       GLP(BindTexture)(target, 0);
     }
     }
   }
   }
-  glgsg->report_my_gl_errors();
+  report_my_gl_errors();
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -478,7 +488,7 @@ end_frame(FrameMode mode, Thread *current_thread) {
     }
     }
     clear_cube_map_selection();
     clear_cube_map_selection();
   }
   }
-  glgsg->report_my_gl_errors();
+  report_my_gl_errors();
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -513,6 +523,7 @@ select_cube_map(int cube_map_index) {
                                    GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + cube_map_index,
                                    GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB + cube_map_index,
                                    gtc->_index, 0);
                                    gtc->_index, 0);
   }
   }
+  report_my_gl_errors();
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -570,6 +581,7 @@ open_buffer() {
   _fb_properties.set_force_software(_host->get_fb_properties().get_force_software());
   _fb_properties.set_force_software(_host->get_fb_properties().get_force_software());
   
   
   _is_valid = true;
   _is_valid = true;
+  report_my_gl_errors();
   return true;
   return true;
 }
 }
 
 
@@ -582,6 +594,8 @@ open_buffer() {
 void CLP(GraphicsBuffer)::
 void CLP(GraphicsBuffer)::
 close_buffer() {
 close_buffer() {
 
 
+  check_host_valid();
+  
   _active = false;
   _active = false;
   if (_gsg == 0) {
   if (_gsg == 0) {
     return;
     return;
@@ -590,7 +604,8 @@ close_buffer() {
   // Get the glgsg.
   // Get the glgsg.
   CLP(GraphicsStateGuardian) *glgsg;
   CLP(GraphicsStateGuardian) *glgsg;
   DCAST_INTO_V(glgsg, _gsg);
   DCAST_INTO_V(glgsg, _gsg);
-  
+
+  report_my_gl_errors();
   // Delete the renderbuffers.
   // Delete the renderbuffers.
   for (int i=0; i<RTP_COUNT; i++) {
   for (int i=0; i<RTP_COUNT; i++) {
     if (_rb[i] != 0) {
     if (_rb[i] != 0) {
@@ -601,13 +616,15 @@ close_buffer() {
   }
   }
   _rb_size_x = 0;
   _rb_size_x = 0;
   _rb_size_y = 0;
   _rb_size_y = 0;
+  report_my_gl_errors();
   
   
   // Delete the FBO itself.
   // Delete the FBO itself.
   if (_fbo != 0) {
   if (_fbo != 0) {
     glgsg->_glDeleteFramebuffers(1, &_fbo);
     glgsg->_glDeleteFramebuffers(1, &_fbo);
     _fbo = 0;
     _fbo = 0;
   }
   }
-  
+  report_my_gl_errors();
+
   // Release the Gsg
   // Release the Gsg
   _gsg.clear();
   _gsg.clear();
 
 
@@ -654,6 +671,7 @@ share_depth_buffer(GraphicsOutput *graphics_output) {
     }
     }
   }
   }
   
   
+  report_my_gl_errors();
   return state;
   return state;
 }
 }
 
 
@@ -703,3 +721,38 @@ unregister_shared_depth_buffer(GraphicsOutput *graphics_output) {
     _shared_depth_buffer_list.remove(input_graphics_output);
     _shared_depth_buffer_list.remove(input_graphics_output);
   }
   }
 }
 }
+
+////////////////////////////////////////////////////////////////////
+//     Function: glGraphicsBuffer::unregister_shared_depth_buffer
+//       Access: Public
+//  Description: Unregister who is sharing the depth buffer.
+////////////////////////////////////////////////////////////////////
+void CLP(GraphicsBuffer)::
+report_my_errors(int line, const char *file) {
+  if (_gsg == 0) {
+    GLenum error_code = glGetError();
+    if (error_code != GL_NO_ERROR) {
+      GLCAT.error() << file << ", line " << line << ": GL error " << error_code << "\n";
+    }
+  } else {
+    CLP(GraphicsStateGuardian) *glgsg;
+    DCAST_INTO_V(glgsg, _gsg);
+    glgsg->report_my_errors(line, file);
+  }
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: glGraphicsBuffer::check_host_valid
+//       Access: Public
+//  Description: If the host window has been closed, then
+//               this buffer is dead too.
+////////////////////////////////////////////////////////////////////
+void CLP(GraphicsBuffer)::
+check_host_valid() {
+  if ((_host == 0)||(!_host->is_valid())) {
+    _is_valid = false;
+    _active = false;
+    _gsg.clear();
+    _host.clear();
+  }
+}

+ 4 - 0
panda/src/glstuff/glGraphicsBuffer_src.h

@@ -79,6 +79,10 @@ public:
 protected:
 protected:
   virtual void close_buffer();
   virtual void close_buffer();
   virtual bool open_buffer();
   virtual bool open_buffer();
+  
+  void check_host_valid();
+  
+  void report_my_errors(int line, const char *file);
 
 
 private:
 private:
   
   

+ 2 - 0
panda/src/glstuff/glGraphicsStateGuardian_src.cxx

@@ -1507,6 +1507,7 @@ end_scene() {
     _current_shader = (Shader *)NULL;
     _current_shader = (Shader *)NULL;
     _current_shader_context = (CLP(ShaderContext) *)NULL;
     _current_shader_context = (CLP(ShaderContext) *)NULL;
   }
   }
+  report_my_gl_errors();
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -2530,6 +2531,7 @@ prepare_texture(Texture *tex) {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 void CLP(GraphicsStateGuardian)::
 void CLP(GraphicsStateGuardian)::
 release_texture(TextureContext *tc) {
 release_texture(TextureContext *tc) {
+  report_my_gl_errors();
   CLP(TextureContext) *gtc = DCAST(CLP(TextureContext), tc);
   CLP(TextureContext) *gtc = DCAST(CLP(TextureContext), tc);
 
 
   GLP(DeleteTextures)(1, &gtc->_index);
   GLP(DeleteTextures)(1, &gtc->_index);

+ 27 - 0
panda/src/glstuff/glShaderContext_src.cxx

@@ -64,6 +64,9 @@ CLP(ShaderContext)(Shader *s, GSG *gsg) : ShaderContext(s) {
         cgGetProfileString(cgGetProgramProfile(_cg_fprogram)) << " " << str << ")\n";
         cgGetProfileString(cgGetProgramProfile(_cg_fprogram)) << " " << str << ")\n";
       release_resources();
       release_resources();
     }
     }
+    if (glGetError() != GL_NO_ERROR) {
+      GLCAT.error() << "GL error in ShaderContext constructor\n";
+    }
   }
   }
 #endif
 #endif
 }
 }
@@ -94,6 +97,9 @@ release_resources() {
     _cg_fprogram = 0;
     _cg_fprogram = 0;
     _cg_parameter_map.clear();
     _cg_parameter_map.clear();
   }
   }
+  if (glGetError() != GL_NO_ERROR) {
+    GLCAT.error() << "GL error in ShaderContext destructor\n";
+  }
 #endif
 #endif
 }
 }
 
 
@@ -118,6 +124,9 @@ bind(GSG *gsg) {
     cgGLEnableProfile(cgGetProgramProfile(_cg_fprogram));
     cgGLEnableProfile(cgGetProgramProfile(_cg_fprogram));
     cgGLBindProgram(_cg_fprogram);
     cgGLBindProgram(_cg_fprogram);
     cg_report_errors();
     cg_report_errors();
+    if (glGetError() != GL_NO_ERROR) {
+      GLCAT.error() << "GL error in ShaderContext::bind\n";
+    }
   }
   }
 #endif
 #endif
 }
 }
@@ -134,6 +143,9 @@ unbind() {
     cgGLDisableProfile(cgGetProgramProfile(_cg_vprogram));
     cgGLDisableProfile(cgGetProgramProfile(_cg_vprogram));
     cgGLDisableProfile(cgGetProgramProfile(_cg_fprogram));
     cgGLDisableProfile(cgGetProgramProfile(_cg_fprogram));
     cg_report_errors();
     cg_report_errors();
+    if (glGetError() != GL_NO_ERROR) {
+      GLCAT.error() << "GL error in ShaderContext::unbind\n";
+    }
   }
   }
 #endif
 #endif
 }
 }
@@ -182,6 +194,9 @@ issue_parameters(GSG *gsg, int altered) {
     }
     }
   }
   }
   cg_report_errors();
   cg_report_errors();
+  if (glGetError() != GL_NO_ERROR) {
+    GLCAT.error() << "GL error in ShaderContext::issue_parameters\n";
+  }
 #endif
 #endif
 }
 }
 
 
@@ -203,6 +218,9 @@ disable_shader_vertex_arrays(GSG *gsg) {
     cgGLDisableClientState(p);
     cgGLDisableClientState(p);
   }
   }
   cg_report_errors();
   cg_report_errors();
+  if (glGetError() != GL_NO_ERROR) {
+    GLCAT.error() << "GL error in ShaderContext::disable_shader_vertex_arrays\n";
+  }
 #endif
 #endif
 }
 }
 
 
@@ -272,6 +290,9 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg,
     }
     }
   }
   }
   cg_report_errors();
   cg_report_errors();
+  if (glGetError() != GL_NO_ERROR) {
+    GLCAT.error() << "GL error in ShaderContext::update_shader_vertex_arrays\n";
+  }
 #endif // HAVE_CG
 #endif // HAVE_CG
   return true;
   return true;
 }
 }
@@ -305,6 +326,9 @@ disable_shader_texture_bindings(GSG *gsg) {
     // cgGLDisableTextureParameter(p);
     // cgGLDisableTextureParameter(p);
   }
   }
   cg_report_errors();
   cg_report_errors();
+  if (glGetError() != GL_NO_ERROR) {
+    GLCAT.error() << "GL error in ShaderContext::disable_shader_texture_bindings\n";
+  }
 #endif
 #endif
 }
 }
 
 
@@ -370,6 +394,9 @@ update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg) {
     gsg->apply_texture(tc);
     gsg->apply_texture(tc);
   }
   }
   cg_report_errors();
   cg_report_errors();
+  if (glGetError() != GL_NO_ERROR) {
+    GLCAT.error() << "GL error in ShaderContext::update_shader_texture_bindings\n";
+  }
 #endif
 #endif
 }
 }
 
 

+ 1 - 0
panda/src/gobj/shader.cxx

@@ -247,6 +247,7 @@ cp_parse_coord_sys(ShaderArgInfo &p,
                    ShaderMatSpec &bind, bool fromflag) {
                    ShaderMatSpec &bind, bool fromflag) {
 
 
   string word1 = cp_parse_non_delimiter(pieces, next);
   string word1 = cp_parse_non_delimiter(pieces, next);
+  if (pieces[next] == "of") next++;
   string word2 = cp_parse_non_delimiter(pieces, next);
   string word2 = cp_parse_non_delimiter(pieces, next);
 
 
   ShaderMatInput from_single;
   ShaderMatInput from_single;

+ 2 - 1
panda/src/wgldisplay/wglGraphicsPipe.cxx

@@ -70,7 +70,8 @@ wgl_make_current(HDC hdc, HGLRC hglrc, PStatCollector *collector) {
     res = wglMakeCurrent(hdc, hglrc);
     res = wglMakeCurrent(hdc, hglrc);
   } else {
   } else {
     res = wglMakeCurrent(hdc, hglrc);
     res = wglMakeCurrent(hdc, hglrc);
-  }    
+  }
+  cerr << "MakeCurrent: " << hdc << " " << hglrc << "\n";
 }
 }
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////