added DEBUG_GL_ERROR debug functionality

git-svn-id: svn://anubis/anaglym/trunk@188 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-11-18 00:20:04 +00:00
parent 72173f9fa0
commit 016ae7f1a2
3 changed files with 54 additions and 4 deletions

View File

@ -72,6 +72,24 @@ static void debug_hook(lua_State * L, lua_Debug * debug)
g_engine->debug_hook(debug); g_engine->debug_hook(debug);
} }
#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;
}
}
/******** Engine functions ********/ /******** Engine functions ********/
Engine::Engine(const string & path, Video & video) Engine::Engine(const string & path, Video & video)
@ -300,12 +318,14 @@ Engine::Object * Engine::getObject(int id)
void Engine::startFrame() void Engine::startFrame()
{ {
checkGLError();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glLoadIdentity(); glLoadIdentity();
gluLookAt(m_eye[0], m_eye[1], m_eye[2], gluLookAt(m_eye[0], m_eye[1], m_eye[2],
m_center[0], m_center[1], m_center[2], m_center[0], m_center[1], m_center[2],
m_up[0], m_up[1], m_up[2]); m_up[0], m_up[1], m_up[2]);
checkGLError();
} }
void Engine::endFrame() void Engine::endFrame()
@ -506,8 +526,9 @@ void Engine::getScreenSize(int * width, int * height)
void Engine::drawText(const char * text, GLfloat r, GLfloat g, GLfloat b, void Engine::drawText(const char * text, GLfloat r, GLfloat g, GLfloat b,
int ptsize, float x, float y) int ptsize, float x, float y)
{ {
checkGLError();
m_font->FaceSize(ptsize); m_font->FaceSize(ptsize);
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glPushMatrix(); glPushMatrix();
glTranslatef(x, y, 0); glTranslatef(x, y, 0);
@ -515,6 +536,7 @@ void Engine::drawText(const char * text, GLfloat r, GLfloat g, GLfloat b,
m_font->Render(text); m_font->Render(text);
glPopMatrix(); glPopMatrix();
glPopAttrib(); glPopAttrib();
checkGLError();
} }
void Engine::getTextSize(const char * text, int ptsize, void Engine::getTextSize(const char * text, int ptsize,
@ -529,6 +551,7 @@ void Engine::getTextSize(const char * text, int ptsize,
void Engine::drawLine(float r, float g, float b, void Engine::drawLine(float r, float g, float b,
float x1, float y1, float x2, float y2, float width) float x1, float y1, float x2, float y2, float width)
{ {
checkGLError();
glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT); glPushAttrib(GL_LINE_BIT | GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
@ -540,11 +563,13 @@ void Engine::drawLine(float r, float g, float b,
glVertex2f(x2, y2); glVertex2f(x2, y2);
glEnd(); glEnd();
glPopAttrib(); glPopAttrib();
checkGLError();
} }
void Engine::drawRect(float r, float g, float b, void Engine::drawRect(float r, float g, float b,
float width, float height, float x, float y, float rot) float width, float height, float x, float y, float rot)
{ {
checkGLError();
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
glPushMatrix(); glPushMatrix();
glTranslatef(x, y, 0); glTranslatef(x, y, 0);
@ -561,11 +586,13 @@ void Engine::drawRect(float r, float g, float b,
glEnd(); glEnd();
glPopMatrix(); glPopMatrix();
glPopAttrib(); glPopAttrib();
checkGLError();
} }
void Engine::fillRect(float r, float g, float b, void Engine::fillRect(float r, float g, float b,
float width, float height, float x, float y, float rot) float width, float height, float x, float y, float rot)
{ {
checkGLError();
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
glPushMatrix(); glPushMatrix();
glTranslatef(x, y, 0); glTranslatef(x, y, 0);
@ -582,11 +609,13 @@ void Engine::fillRect(float r, float g, float b,
glEnd(); glEnd();
glPopMatrix(); glPopMatrix();
glPopAttrib(); glPopAttrib();
checkGLError();
} }
void Engine::drawImage(float width, float height, float x, float y, void Engine::drawImage(float width, float height, float x, float y,
int tex, float rot) int tex, float rot)
{ {
checkGLError();
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
glPushMatrix(); glPushMatrix();
glTranslatef(x, y, 0); glTranslatef(x, y, 0);
@ -608,6 +637,7 @@ void Engine::drawImage(float width, float height, float x, float y,
glEnd(); glEnd();
glPopMatrix(); glPopMatrix();
glPopAttrib(); glPopAttrib();
checkGLError();
} }
/* called by SDL when the update timer expires */ /* called by SDL when the update timer expires */
@ -726,6 +756,7 @@ void Engine::update_overlay_event()
{ {
if (m_event_update_overlay_present) if (m_event_update_overlay_present)
{ {
checkGLError();
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
glDisable(GL_DEPTH_TEST); glDisable(GL_DEPTH_TEST);
int width = m_video.getWidth(); int width = m_video.getWidth();
@ -749,6 +780,7 @@ void Engine::update_overlay_event()
glPopMatrix(); glPopMatrix();
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPopAttrib(); glPopAttrib();
checkGLError();
} }
} }
@ -926,18 +958,23 @@ Engine::Object::Object(const Engine::Object & orig)
{ {
m_is_visible = orig.m_is_visible; m_is_visible = orig.m_is_visible;
m_ode_object = new OdeWorld::Object(*orig.m_ode_object); m_ode_object = new OdeWorld::Object(*orig.m_ode_object);
m_display_list = orig.m_display_list; m_is_managed = orig.m_is_managed;
if (m_is_managed)
m_display_list = 0;
else
m_display_list = orig.m_display_list;
m_display_list_refcnt = orig.m_display_list_refcnt; m_display_list_refcnt = orig.m_display_list_refcnt;
if (m_display_list_refcnt != NULL) if (m_display_list_refcnt != NULL)
(*m_display_list_refcnt)++; (*m_display_list_refcnt)++;
m_scale = orig.m_scale; m_scale = orig.m_scale;
m_is_scaled = orig.m_is_scaled; m_is_scaled = orig.m_is_scaled;
m_is_managed = orig.m_is_managed;
m_geom_type = orig.m_geom_type; m_geom_type = orig.m_geom_type;
m_args = orig.m_args; m_args = orig.m_args;
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
m_color[i] = orig.m_color[i]; m_color[i] = orig.m_color[i];
m_texture = orig.m_texture; m_texture = orig.m_texture;
if (m_is_managed)
render();
} }
Engine::Object::~Object() Engine::Object::~Object()
@ -953,6 +990,10 @@ Engine::Object::~Object()
glDeleteLists(m_display_list, 1); glDeleteLists(m_display_list, 1);
} }
} }
else
{
glDeleteLists(m_display_list, 1);
}
} }
void Engine::Object::createManagedObject() void Engine::Object::createManagedObject()
@ -997,7 +1038,10 @@ void Engine::Object::render()
return; return;
GLUquadric * quad = gluNewQuadric(); GLUquadric * quad = gluNewQuadric();
if (m_display_list <= 0) if (m_display_list <= 0)
{
m_display_list = glGenLists(1); m_display_list = glGenLists(1);
}
checkGLError();
glNewList(m_display_list, GL_COMPILE); glNewList(m_display_list, GL_COMPILE);
glPushAttrib(GL_ENABLE_BIT); glPushAttrib(GL_ENABLE_BIT);
if (m_texture != 0) if (m_texture != 0)
@ -1182,6 +1226,7 @@ void Engine::Object::render()
gluDeleteQuadric(quad); gluDeleteQuadric(quad);
glPopAttrib(); glPopAttrib();
glEndList(); glEndList();
checkGLError();
} }
void Engine::Object::loadPhy(const FileLoader::Path & path) void Engine::Object::loadPhy(const FileLoader::Path & path)
@ -1257,6 +1302,7 @@ void Engine::Object::draw()
{ {
if (m_is_visible) if (m_is_visible)
{ {
checkGLError();
const dReal * pos = m_ode_object->getPosition(); const dReal * pos = m_ode_object->getPosition();
const dReal * rot = m_ode_object->getRotation(); const dReal * rot = m_ode_object->getRotation();
bool transform = (pos != NULL && rot != NULL); bool transform = (pos != NULL && rot != NULL);
@ -1271,13 +1317,16 @@ void Engine::Object::draw()
glScalef(m_scale, m_scale, m_scale); glScalef(m_scale, m_scale, m_scale);
} }
checkGLError();
glCallList(m_display_list); glCallList(m_display_list);
checkGLError();
if (m_is_scaled) if (m_is_scaled)
glPopAttrib(); glPopAttrib();
if (transform) if (transform)
glPopMatrix(); glPopMatrix();
checkGLError();
} }
} }

View File

@ -82,7 +82,6 @@ class Engine
float m_scale; float m_scale;
bool m_is_scaled; bool m_is_scaled;
bool m_is_managed; bool m_is_managed;
GLuint m_texture;
/* for "pre-loaded" objects */ /* for "pre-loaded" objects */
int * m_display_list_refcnt; int * m_display_list_refcnt;
@ -91,6 +90,7 @@ class Engine
OdeWorld::GeomType m_geom_type; OdeWorld::GeomType m_geom_type;
refptr< std::vector<float> > m_args; refptr< std::vector<float> > m_args;
float m_color[4]; float m_color[4];
GLuint m_texture;
}; };
class EngineFileLoader : public FileLoader class EngineFileLoader : public FileLoader

View File

@ -57,6 +57,7 @@ end
function update_overlay_event(width, height) function update_overlay_event(width, height)
local tw, th = ag.getTextSize("Hi there", 18) local tw, th = ag.getTextSize("Hi there", 18)
ag.drawText("Hi there", 1, 1, 0, 18, width - tw - 40, height - th - 40) ag.drawText("Hi there", 1, 1, 0, 18, width - tw - 40, height - th - 40)
ag.drawText("Hello", 1, 0, 1, 20, 200, 200)
-- ag.drawLine(1, 0, 0.3, 10, 10, 40, 60) -- ag.drawLine(1, 0, 0.3, 10, 10, 40, 60)
-- ag.drawLine(1, 0.7, 1, 50, 10, 100, 60, 5) -- ag.drawLine(1, 0.7, 1, 50, 10, 100, 60, 5)
-- ag.drawRect(0, 1, 0, 40, 40, width / 2, height / 2) -- ag.drawRect(0, 1, 0, 40, 40, width / 2, height / 2)