From 6fe75c8eed5c6b18284ef551fc4d4a76e1448d9e Mon Sep 17 00:00:00 2001 From: Josh Yelon Date: Tue, 26 Feb 2008 23:02:27 +0000 Subject: [PATCH] Added some error-checking --- panda/src/glstuff/glGraphicsBuffer_src.cxx | 67 +++++++++++++++++-- panda/src/glstuff/glGraphicsBuffer_src.h | 4 ++ .../glstuff/glGraphicsStateGuardian_src.cxx | 2 + panda/src/glstuff/glShaderContext_src.cxx | 27 ++++++++ panda/src/gobj/shader.cxx | 1 + panda/src/wgldisplay/wglGraphicsPipe.cxx | 3 +- 6 files changed, 96 insertions(+), 8 deletions(-) diff --git a/panda/src/glstuff/glGraphicsBuffer_src.cxx b/panda/src/glstuff/glGraphicsBuffer_src.cxx index 2f6982ee90..a7378f5426 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.cxx +++ b/panda/src/glstuff/glGraphicsBuffer_src.cxx @@ -74,7 +74,7 @@ CLP(GraphicsBuffer):: } graphics_buffer_iterator = _shared_depth_buffer_list.begin( ); } - } + } } //////////////////////////////////////////////////////////////////// @@ -90,6 +90,8 @@ bool CLP(GraphicsBuffer):: begin_frame(FrameMode mode, Thread *current_thread) { begin_frame_spam(mode); + check_host_valid(); + if (!_is_valid) { if (GLCAT.is_debug()) { GLCAT.debug() @@ -120,6 +122,7 @@ begin_frame(FrameMode mode, Thread *current_thread) { } _gsg->set_current_properties(&get_fb_properties()); + report_my_gl_errors(); return true; } @@ -158,8 +161,10 @@ check_fbo() { } glgsg->bind_fbo(0); + report_my_gl_errors(); return false; } + report_my_gl_errors(); return true; } @@ -173,6 +178,11 @@ check_fbo() { void CLP(GraphicsBuffer):: rebuild_bitplanes() { + check_host_valid(); + if (_gsg == 0) { + return; + } + CLP(GraphicsStateGuardian) *glgsg; DCAST_INTO_V(glgsg, _gsg); @@ -181,7 +191,7 @@ rebuild_bitplanes() { if (_fbo == 0) { glgsg->_glGenFramebuffers(1, &_fbo); if (_fbo == 0) { - glgsg->report_my_gl_errors(); + report_my_gl_errors(); return; } } @@ -274,7 +284,7 @@ rebuild_bitplanes() { } _cube_face_active = 0; - glgsg->report_my_gl_errors(); + report_my_gl_errors(); } //////////////////////////////////////////////////////////////////// @@ -441,7 +451,7 @@ generate_mipmaps() { 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(); } - 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, 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()); _is_valid = true; + report_my_gl_errors(); return true; } @@ -582,6 +594,8 @@ open_buffer() { void CLP(GraphicsBuffer):: close_buffer() { + check_host_valid(); + _active = false; if (_gsg == 0) { return; @@ -590,7 +604,8 @@ close_buffer() { // Get the glgsg. CLP(GraphicsStateGuardian) *glgsg; DCAST_INTO_V(glgsg, _gsg); - + + report_my_gl_errors(); // Delete the renderbuffers. for (int i=0; i_glDeleteFramebuffers(1, &_fbo); _fbo = 0; } - + report_my_gl_errors(); + // Release the Gsg _gsg.clear(); @@ -654,6 +671,7 @@ share_depth_buffer(GraphicsOutput *graphics_output) { } } + report_my_gl_errors(); return state; } @@ -703,3 +721,38 @@ unregister_shared_depth_buffer(GraphicsOutput *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(); + } +} diff --git a/panda/src/glstuff/glGraphicsBuffer_src.h b/panda/src/glstuff/glGraphicsBuffer_src.h index 2c4cecc99e..0721c42f86 100644 --- a/panda/src/glstuff/glGraphicsBuffer_src.h +++ b/panda/src/glstuff/glGraphicsBuffer_src.h @@ -79,6 +79,10 @@ public: protected: virtual void close_buffer(); virtual bool open_buffer(); + + void check_host_valid(); + + void report_my_errors(int line, const char *file); private: diff --git a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx index e81d0b7250..ec48b0533d 100644 --- a/panda/src/glstuff/glGraphicsStateGuardian_src.cxx +++ b/panda/src/glstuff/glGraphicsStateGuardian_src.cxx @@ -1507,6 +1507,7 @@ end_scene() { _current_shader = (Shader *)NULL; _current_shader_context = (CLP(ShaderContext) *)NULL; } + report_my_gl_errors(); } //////////////////////////////////////////////////////////////////// @@ -2530,6 +2531,7 @@ prepare_texture(Texture *tex) { //////////////////////////////////////////////////////////////////// void CLP(GraphicsStateGuardian):: release_texture(TextureContext *tc) { + report_my_gl_errors(); CLP(TextureContext) *gtc = DCAST(CLP(TextureContext), tc); GLP(DeleteTextures)(1, >c->_index); diff --git a/panda/src/glstuff/glShaderContext_src.cxx b/panda/src/glstuff/glShaderContext_src.cxx index e394ff80bd..d72d12c9b9 100755 --- a/panda/src/glstuff/glShaderContext_src.cxx +++ b/panda/src/glstuff/glShaderContext_src.cxx @@ -64,6 +64,9 @@ CLP(ShaderContext)(Shader *s, GSG *gsg) : ShaderContext(s) { cgGetProfileString(cgGetProgramProfile(_cg_fprogram)) << " " << str << ")\n"; release_resources(); } + if (glGetError() != GL_NO_ERROR) { + GLCAT.error() << "GL error in ShaderContext constructor\n"; + } } #endif } @@ -94,6 +97,9 @@ release_resources() { _cg_fprogram = 0; _cg_parameter_map.clear(); } + if (glGetError() != GL_NO_ERROR) { + GLCAT.error() << "GL error in ShaderContext destructor\n"; + } #endif } @@ -118,6 +124,9 @@ bind(GSG *gsg) { cgGLEnableProfile(cgGetProgramProfile(_cg_fprogram)); cgGLBindProgram(_cg_fprogram); cg_report_errors(); + if (glGetError() != GL_NO_ERROR) { + GLCAT.error() << "GL error in ShaderContext::bind\n"; + } } #endif } @@ -134,6 +143,9 @@ unbind() { cgGLDisableProfile(cgGetProgramProfile(_cg_vprogram)); cgGLDisableProfile(cgGetProgramProfile(_cg_fprogram)); cg_report_errors(); + if (glGetError() != GL_NO_ERROR) { + GLCAT.error() << "GL error in ShaderContext::unbind\n"; + } } #endif } @@ -182,6 +194,9 @@ issue_parameters(GSG *gsg, int altered) { } } cg_report_errors(); + if (glGetError() != GL_NO_ERROR) { + GLCAT.error() << "GL error in ShaderContext::issue_parameters\n"; + } #endif } @@ -203,6 +218,9 @@ disable_shader_vertex_arrays(GSG *gsg) { cgGLDisableClientState(p); } cg_report_errors(); + if (glGetError() != GL_NO_ERROR) { + GLCAT.error() << "GL error in ShaderContext::disable_shader_vertex_arrays\n"; + } #endif } @@ -272,6 +290,9 @@ update_shader_vertex_arrays(CLP(ShaderContext) *prev, GSG *gsg, } } cg_report_errors(); + if (glGetError() != GL_NO_ERROR) { + GLCAT.error() << "GL error in ShaderContext::update_shader_vertex_arrays\n"; + } #endif // HAVE_CG return true; } @@ -305,6 +326,9 @@ disable_shader_texture_bindings(GSG *gsg) { // cgGLDisableTextureParameter(p); } cg_report_errors(); + if (glGetError() != GL_NO_ERROR) { + GLCAT.error() << "GL error in ShaderContext::disable_shader_texture_bindings\n"; + } #endif } @@ -370,6 +394,9 @@ update_shader_texture_bindings(CLP(ShaderContext) *prev, GSG *gsg) { gsg->apply_texture(tc); } cg_report_errors(); + if (glGetError() != GL_NO_ERROR) { + GLCAT.error() << "GL error in ShaderContext::update_shader_texture_bindings\n"; + } #endif } diff --git a/panda/src/gobj/shader.cxx b/panda/src/gobj/shader.cxx index 46a0a476e9..e05758ad53 100755 --- a/panda/src/gobj/shader.cxx +++ b/panda/src/gobj/shader.cxx @@ -247,6 +247,7 @@ cp_parse_coord_sys(ShaderArgInfo &p, ShaderMatSpec &bind, bool fromflag) { string word1 = cp_parse_non_delimiter(pieces, next); + if (pieces[next] == "of") next++; string word2 = cp_parse_non_delimiter(pieces, next); ShaderMatInput from_single; diff --git a/panda/src/wgldisplay/wglGraphicsPipe.cxx b/panda/src/wgldisplay/wglGraphicsPipe.cxx index 96a0d3b316..36711ac34e 100644 --- a/panda/src/wgldisplay/wglGraphicsPipe.cxx +++ b/panda/src/wgldisplay/wglGraphicsPipe.cxx @@ -70,7 +70,8 @@ wgl_make_current(HDC hdc, HGLRC hglrc, PStatCollector *collector) { res = wglMakeCurrent(hdc, hglrc); } else { res = wglMakeCurrent(hdc, hglrc); - } + } + cerr << "MakeCurrent: " << hdc << " " << hglrc << "\n"; } ////////////////////////////////////////////////////////////////////