[Add] Finally added opengl error checking in DEBUG builds.
This commit is contained in:
parent
bd6281692b
commit
8f7ec2fa09
15
src/font.c
15
src/font.c
@ -72,6 +72,8 @@ void gl_print(const glFont* ft_font, const double x, const double y,
|
||||
|
||||
glPopMatrix(); // Translation matrix.
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
gl_checkErr();
|
||||
}
|
||||
|
||||
// Acts just like gl_print, but prints to a max length of max.
|
||||
@ -120,6 +122,8 @@ int gl_printMax(const glFont* ft_font, const int max,
|
||||
glPopMatrix(); // Translation matrix.
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
gl_checkErr();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -173,6 +177,8 @@ int gl_printMid(const glFont* ft_font, const int width, double x, const double y
|
||||
glPopMatrix(); // Translation matrix.
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
gl_checkErr();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -256,6 +262,8 @@ int gl_printText(const glFont* ft_font, const int width, const int height,
|
||||
}
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
gl_checkErr();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -407,12 +415,16 @@ static void glFontMakeDList(FT_Face face, char ch, GLuint list_base,
|
||||
glEndList();
|
||||
|
||||
FT_Done_Glyph(glyph);
|
||||
|
||||
gl_checkErr();
|
||||
}
|
||||
|
||||
void gl_fontInit(glFont* font, const char* fname, const unsigned int h) {
|
||||
uint32_t bufsize;
|
||||
int i;
|
||||
|
||||
if(font == NULL) font = &gl_defFont;
|
||||
|
||||
uint32_t bufsize;
|
||||
FT_Byte* buf = pack_readfile(DATA, (fname) ? fname : FONT_DEF, &bufsize);
|
||||
|
||||
// Allocatagery.
|
||||
@ -443,7 +455,6 @@ void gl_fontInit(glFont* font, const char* fname, const unsigned int h) {
|
||||
glGenTextures(128, font->textures);
|
||||
|
||||
// Create each of the font display lists.
|
||||
unsigned char i;
|
||||
for(i = 0; i < 128; i++)
|
||||
glFontMakeDList(face, i, font->list_base, font->textures, font->w);
|
||||
|
||||
|
@ -246,6 +246,8 @@ void main_loop(void) {
|
||||
}
|
||||
if(toolkit) toolkit_render();
|
||||
|
||||
gl_checkErr(); // Check error every loop.
|
||||
|
||||
SDL_GL_SwapBuffers();
|
||||
}
|
||||
|
||||
|
55
src/opengl.c
55
src/opengl.c
@ -141,6 +141,8 @@ void gl_screenshot(const char* filename) {
|
||||
|
||||
for(i = 0; i < screen->h; i++) rows[i] = screenbuf[screen->h - i - 1];
|
||||
write_png(filename, rows, screen->w, screen->h, PNG_COLOR_TYPE_RGB, 8);
|
||||
|
||||
gl_checkErr();
|
||||
}
|
||||
|
||||
// ================
|
||||
@ -235,6 +237,8 @@ static GLuint gl_loadSurface(SDL_Surface* surface, int* rw, int* rh) {
|
||||
SDL_UnlockSurface(surface);
|
||||
SDL_FreeSurface(surface);
|
||||
|
||||
gl_checkErr();
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
@ -387,6 +391,8 @@ void gl_blitSprite(const glTexture* sprite, const double bx, const double by,
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
gl_checkErr();
|
||||
}
|
||||
|
||||
// Just straight out blit the thing at position.
|
||||
@ -419,6 +425,8 @@ void gl_blitStatic(const glTexture* texture, const double bx, const double by,
|
||||
glEnd();
|
||||
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
||||
gl_checkErr();
|
||||
}
|
||||
|
||||
// Bind our precious camera to a vector.
|
||||
@ -469,6 +477,8 @@ void gl_drawCircle(const double cx, const double cy, const double r) {
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
|
||||
gl_checkErr();
|
||||
}
|
||||
|
||||
// Draw a cirlce in a rect.
|
||||
@ -532,7 +542,10 @@ void gl_drawCircleInRect(const double cx, const double cy, const double r,
|
||||
}
|
||||
}
|
||||
glEnd();
|
||||
|
||||
gl_checkErr();
|
||||
}
|
||||
#undef PIXEL
|
||||
|
||||
// ================
|
||||
// GLOBAL.
|
||||
@ -564,6 +577,46 @@ static GLboolean gl_hasExt(char* name) {
|
||||
return GL_FALSE;
|
||||
}
|
||||
|
||||
// Check and report if there's been an error.
|
||||
void gl_checkErr(void) {
|
||||
#ifdef DEBUG
|
||||
GLenum err;
|
||||
char* errstr;
|
||||
|
||||
err = glGetError();
|
||||
|
||||
if(err == GL_NO_ERROR) return; // No error.
|
||||
|
||||
switch(err) {
|
||||
case GL_INVALID_ENUM:
|
||||
errstr = "GL invalid enum";
|
||||
break;
|
||||
case GL_INVALID_VALUE:
|
||||
errstr = "GL invalid operation";
|
||||
break;
|
||||
case GL_INVALID_OPERATION:
|
||||
errstr = "GL invalid operation";
|
||||
break;
|
||||
case GL_STACK_OVERFLOW:
|
||||
errstr = "GL stack overflow";
|
||||
break;
|
||||
case GL_STACK_UNDERFLOW:
|
||||
errstr = "GL stack underflow";
|
||||
break;
|
||||
case GL_OUT_OF_MEMORY:
|
||||
errstr = "GL out of memory";
|
||||
break;
|
||||
case GL_TABLE_TOO_LARGE:
|
||||
errstr = "GL table too large";
|
||||
break;
|
||||
default:
|
||||
errstr = "GL unkown error";
|
||||
break;
|
||||
}
|
||||
WARN("OpenGL error: %s", errstr);
|
||||
#endif
|
||||
}
|
||||
|
||||
// Initialize SDL/OpenGL etc.
|
||||
int gl_init(void) {
|
||||
int doublebuf, depth, i, j, off, toff, supported;
|
||||
@ -683,6 +736,8 @@ int gl_init(void) {
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
|
||||
gl_checkErr();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -79,4 +79,5 @@ void gl_exit(void);
|
||||
int gl_isTrans(const glTexture* t, const int x, const int y);
|
||||
void gl_getSpriteFromDir(int* x, int* y, const glTexture* t, const double dir);
|
||||
void gl_screenshot(const char* filename);
|
||||
void gl_checkErr(void);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user