From b2ab1fc98bf64fee535503fd255127840d54fdb3 Mon Sep 17 00:00:00 2001 From: josh Date: Wed, 18 Nov 2009 00:20:14 +0000 Subject: [PATCH] added DEBUG_GL_ERROR debug functionality git-svn-id: svn://anubis/misc/wfobj@215 bd8a9e45-a331-0410-811e-c64571078777 --- WFObj.cc | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/WFObj.cc b/WFObj.cc index e988fa1..b84e9f0 100644 --- a/WFObj.cc +++ b/WFObj.cc @@ -69,6 +69,23 @@ static string basePath(const string & str) return ""; } +//#define DEBUG_GL_ERROR +#ifdef DEBUG_GL_ERROR +#define checkGLError() checkGLErrorLine(__FUNCTION__, __LINE__) +#else +#define checkGLError() +#endif +static void checkGLErrorLine(const char * function, int line) +{ + GLenum err = glGetError(); + if (err != 0) + { + cerr << "gl error in " << function + << ": " << err << " (0x" << hex << err << ") at line " + << dec << line << endl; + } +} + /****** WFObj functions ******/ @@ -180,6 +197,7 @@ void WFObj::processInputLine(const std::string & input) GLuint WFObj::render(bool doTextureInfo) { + checkGLError(); GLuint list = glGenLists(1); glNewList(list, GL_COMPILE); int len = m_data.size(); @@ -348,6 +366,7 @@ GLuint WFObj::render(bool doTextureInfo) inMaterial = false; } glEndList(); + checkGLError(); return list; } @@ -483,6 +502,7 @@ void WFObj::WFMtl::renderBegin(const string & mtlname, bool doTextureInfo) int num_stmts = stmts.size(); bool foundTexture = false; bool didSomething = false; + checkGLError(); for (int i = 0; i < num_stmts; i++) { string & type = stmts[i][0]; @@ -584,6 +604,7 @@ void WFObj::WFMtl::renderBegin(const string & mtlname, bool doTextureInfo) } } + checkGLError(); if (didSomething) { pushAttributes(); @@ -605,6 +626,7 @@ void WFObj::WFMtl::renderBegin(const string & mtlname, bool doTextureInfo) } } } + checkGLError(); } void WFObj::WFMtl::pushAttributes() @@ -616,7 +638,9 @@ void WFObj::WFMtl::pushAttributes() cout << " glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT | GL_ENABLE_BIT)" << endl; #endif + checkGLError(); glPushAttrib(GL_LIGHTING_BIT | GL_TEXTURE_BIT | GL_ENABLE_BIT); + checkGLError(); } void WFObj::WFMtl::renderEnd(const string & mtlname, bool doTextureInfo) @@ -629,7 +653,9 @@ void WFObj::WFMtl::renderEnd(const string & mtlname, bool doTextureInfo) #ifdef DEBUGGL cout << " glPopAttrib()" << endl; #endif + checkGLError(); glPopAttrib(); + checkGLError(); m_attributesPushed = false; } }