Unified OpenGL error handling
This adds a glErrors function that returns true in case of errors after outputting them with file and line number from where it was called. Closes #1011. git-svn-id: https://warzone2100.svn.sourceforge.net/svnroot/warzone2100/trunk@8337 4a71c877-e1ca-e34f-864e-861f7616d084master
parent
289a73d103
commit
65caade5c5
|
@ -32,6 +32,8 @@
|
|||
|
||||
/***************************************************************************/
|
||||
|
||||
#include <SDL/SDL_opengl.h>
|
||||
|
||||
#include "lib/framework/frame.h"
|
||||
#include "piedef.h"
|
||||
|
||||
|
@ -136,4 +138,10 @@ extern void pie_ShowMouse(bool visible);
|
|||
|
||||
extern void pie_SetTranslucencyMode(TRANSLUCENCY_MODE transMode);
|
||||
|
||||
#define glErrors(info) \
|
||||
_glerrors(__FUNCTION__, __FILE__, __LINE__)
|
||||
|
||||
extern bool _glerrors(const char *, const char *, int);
|
||||
|
||||
|
||||
#endif // _pieState_h
|
||||
|
|
|
@ -258,3 +258,15 @@ void pie_ShowMouse(bool visible)
|
|||
}
|
||||
}
|
||||
|
||||
bool _glerrors(const char *function, const char *file, int line)
|
||||
{
|
||||
bool ret = false;
|
||||
GLenum err = glGetError();
|
||||
while (err != GL_NO_ERROR)
|
||||
{
|
||||
ret = true;
|
||||
debug(LOG_ERROR, "OpenGL error in function %s at %s:%u: %s\n", function, file, line, gluErrorString(err));
|
||||
err = glGetError();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
|
@ -246,6 +246,7 @@ BOOL screenInitialise(
|
|||
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
glErrors();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -459,25 +460,12 @@ void screenDumpToDisk(const char* path)
|
|||
screendump_required = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an OpenGL error has occurred.
|
||||
* \param label Label to print when an OpenGL occurred.
|
||||
*/
|
||||
void checkGLErrors(const char *label)
|
||||
{
|
||||
const GLenum errCode = glGetError();
|
||||
|
||||
if (errCode == GL_NO_ERROR)
|
||||
return;
|
||||
|
||||
debug(LOG_ERROR, "OpenGL ERROR in %s: %s, (0x%0x)", label, gluErrorString(errCode), errCode);
|
||||
bFboProblem = true; // we have a issue with the FBO, fallback to normal routine
|
||||
}
|
||||
|
||||
BOOL Init_FBO(unsigned int width, unsigned int height)
|
||||
{
|
||||
GLenum status;
|
||||
|
||||
glErrors();
|
||||
// Bail out if FBOs aren't supported
|
||||
if (!GLEE_EXT_framebuffer_object)
|
||||
return false;
|
||||
|
@ -555,21 +543,20 @@ BOOL Init_FBO(unsigned int width, unsigned int height)
|
|||
}
|
||||
|
||||
glBindFramebufferEXT (GL_FRAMEBUFFER_EXT, 0); // unbind it for now.
|
||||
checkGLErrors("Init_FBO() Completed");
|
||||
return true;
|
||||
|
||||
bFboProblem |= glErrors(); // don't use FBOs if something here caused an error
|
||||
return true;
|
||||
}
|
||||
|
||||
void Delete_FBO(void)
|
||||
{
|
||||
if(FBOinit)
|
||||
{
|
||||
glErrors();
|
||||
glDeleteFramebuffersEXT(1, &fbo);
|
||||
checkGLErrors("Deleting FBO");
|
||||
glDeleteRenderbuffersEXT(1, &FBOdepthbuffer);
|
||||
checkGLErrors("deleting FBOdepthbuffer");
|
||||
glDeleteTextures(1,&FBOtexture);
|
||||
checkGLErrors("deleting FBOtexture");
|
||||
bFboProblem |= glErrors();
|
||||
fbo = FBOdepthbuffer = FBOtexture = FBOinit = 0; //reset everything.
|
||||
}
|
||||
}
|
||||
|
|
|
@ -62,5 +62,4 @@ extern void screenDoDumpToDiskIfRequired(void);
|
|||
|
||||
extern BOOL Init_FBO(unsigned int width, unsigned int height);
|
||||
extern void Delete_FBO(void);
|
||||
extern void checkGLErrors(const char *label); // reports what the openGL error was
|
||||
#endif
|
||||
|
|
|
@ -297,6 +297,7 @@ static void video_write(bool update)
|
|||
const int video_height = videodata.ti.frame_height;
|
||||
yuv_buffer yuv;
|
||||
|
||||
glErrors();
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glBindTexture(GL_TEXTURE_2D, video_texture);
|
||||
|
||||
|
@ -330,6 +331,7 @@ static void video_write(bool update)
|
|||
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, video_width,
|
||||
video_height, GL_RGBA, GL_UNSIGNED_BYTE, RGBAframe);
|
||||
glErrors();
|
||||
}
|
||||
|
||||
glDisable(GL_DEPTH_TEST);
|
||||
|
|
|
@ -418,7 +418,7 @@ void loadMapPreview(bool hideInterface)
|
|||
memset(playerpos,0x77,sizeof(playerpos));
|
||||
// color our texture with clancolors @ correct position
|
||||
plotStructurePreview16(imageData, scale, offX2, offY2,playerpos);
|
||||
glGetError(); // clear openGL errorcodes
|
||||
glErrors(); // clear openGL errorcodes
|
||||
// and now, for those that have FBO available on their card
|
||||
// added hack to work around bad drivers that report FBO available, when it is not.
|
||||
if(Init_FBO(BACKDROP_HACK_WIDTH,BACKDROP_HACK_HEIGHT) && !bFboProblem)
|
||||
|
@ -428,7 +428,7 @@ void loadMapPreview(bool hideInterface)
|
|||
|
||||
// First we bind the FBO so we can render to it
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fbo);
|
||||
checkGLErrors("write to fbo enabled");
|
||||
bFboProblem |= glErrors();
|
||||
|
||||
//set up projection & model matrix for the texture(!)
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
@ -440,7 +440,6 @@ void loadMapPreview(bool hideInterface)
|
|||
glPushMatrix();
|
||||
glLoadIdentity();
|
||||
glViewport( 0, 0, BACKDROP_HACK_WIDTH, BACKDROP_HACK_HEIGHT );
|
||||
checkGLErrors("viewport set");
|
||||
// Then render as normal
|
||||
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT ); //| GL_DEPTH_BUFFER_BIT);
|
||||
|
@ -450,11 +449,9 @@ void loadMapPreview(bool hideInterface)
|
|||
glBindTexture(GL_TEXTURE_2D, FBOtexture);
|
||||
//upload the texture to the FBO
|
||||
glTexSubImage2D(GL_TEXTURE_2D,0,0,0,BACKDROP_HACK_WIDTH,BACKDROP_HACK_HEIGHT,GL_RGB,GL_UNSIGNED_BYTE,imageData);
|
||||
checkGLErrors("After texture upload");
|
||||
|
||||
iV_SetFont(font_large);
|
||||
glDisable(GL_CULL_FACE);
|
||||
checkGLErrors("After setting font");
|
||||
for(i=0;i < MAX_PLAYERS;i++)//
|
||||
{
|
||||
float fx,fy;
|
||||
|
@ -477,12 +474,10 @@ void loadMapPreview(bool hideInterface)
|
|||
iV_DrawTextF(fx,fy,"%d",i);
|
||||
}
|
||||
glcRenderStyle(GLC_TEXTURE);
|
||||
checkGLErrors("after text draw");
|
||||
|
||||
// set rendering back to default frame buffer
|
||||
glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
|
||||
glReadPixels(0, 0, BACKDROP_HACK_WIDTH, BACKDROP_HACK_HEIGHT,GL_RGB,GL_UNSIGNED_BYTE,fboData);
|
||||
checkGLErrors("Reading pixels");
|
||||
|
||||
//done with the FBO, so unbind it.
|
||||
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
|
||||
|
@ -491,6 +486,7 @@ void loadMapPreview(bool hideInterface)
|
|||
glMatrixMode(GL_MODELVIEW);
|
||||
glPopMatrix();
|
||||
glPopAttrib();
|
||||
bFboProblem |= glErrors();
|
||||
// if we detected a error, then we must fallback to old texture, or user will not see anything.
|
||||
if(!bFboProblem)
|
||||
{
|
||||
|
@ -500,8 +496,7 @@ void loadMapPreview(bool hideInterface)
|
|||
{
|
||||
screen_Upload(imageData);
|
||||
}
|
||||
checkGLErrors("Done with FBO routine");
|
||||
|
||||
bFboProblem |= glErrors();
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue