Added some error-checking

This commit is contained in:
Josh Yelon 2008-02-26 23:02:27 +00:00
parent 21651167f1
commit 6fe75c8eed
6 changed files with 96 additions and 8 deletions

View File

@ -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<RTP_COUNT; i++) {
if (_rb[i] != 0) {
@ -601,13 +616,15 @@ close_buffer() {
}
_rb_size_x = 0;
_rb_size_y = 0;
report_my_gl_errors();
// Delete the FBO itself.
if (_fbo != 0) {
glgsg->_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();
}
}

View File

@ -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:

View File

@ -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, &gtc->_index);

View File

@ -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
}

View File

@ -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;

View File

@ -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";
}
////////////////////////////////////////////////////////////////////