From 475aa1f1fa43713af21aae1ad99c9a95c3947981 Mon Sep 17 00:00:00 2001 From: Allanis Date: Sat, 20 Jul 2013 19:06:36 +0100 Subject: [PATCH] [Add] Check for multitexture abilities and texture leaks. --- src/opengl.c | 22 ++++++++++++++++++++-- src/opengl.h | 1 + 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/opengl.c b/src/opengl.c index b39df7f..15f90bd 100644 --- a/src/opengl.c +++ b/src/opengl.c @@ -14,6 +14,9 @@ #include "pack.h" #include "opengl.h" +/* Requirements. */ +#define OPENGL_REQ_MULTITEX 3 + /* The screen info, gives data of current opengl settings. */ glInfo gl_screen; @@ -896,8 +899,9 @@ int gl_init(void) { if(gl_hasExt("GL_ARB_fragment_shader")==GL_TRUE) gl_screen.flags |= OPENGL_FRAG_SHADER; - /* Max texture size. */ + /* Texture information. */ glGetIntegerv(GL_MAX_TEXTURE_SIZE, &gl_screen.tex_max); + glGetIntegerv(GL_MAX_TEXTURE_UNITS, &gl_screen.multitex_max); /* Debug heaven. */ DEBUG("OpenGL Window Created: %dx%d@%dbpp %s", SCREEN_W, SCREEN_H, @@ -910,8 +914,12 @@ int gl_init(void) { DEBUG("Renderer: %s", glGetString(GL_RENDERER)); DEBUG("Version: %s", glGetString(GL_VERSION)); + /* Now check for things that can be bad. */ + if(gl_screen.multitex_max < OPENGL_REQ_MULTITEX) + WARN("Missing texture units (%d required, %d found)", + OPENGL_REQ_MULTITEX, gl_screen.multitex_max); if(!gl_has(OPENGL_FRAG_SHADER)) - DEBUG("No fragment shader extension detected"); + DEBUG("No fragment shader extension detected"); /* Not a warning yet. */ DEBUG(""); /* Some openGL options. */ @@ -947,6 +955,16 @@ int gl_init(void) { /* Clean up our mess. */ void gl_exit(void) { + glTexList* tex; + + /* Make sure there's no texture leak. */ + if(texture_list != NULL) { + DEBUG("Texture leak detected!"); + for(tex = texture_list; tex != NULL; tex = tex->next) + DEBUG(" '%s' opened %d times", tex->tex->name, tex->used); + } + + /* Shut down the subsystem. */ SDL_QuitSubSystem(SDL_INIT_VIDEO); } diff --git a/src/opengl.h b/src/opengl.h index 2314080..895c852 100644 --- a/src/opengl.h +++ b/src/opengl.h @@ -34,6 +34,7 @@ typedef struct glInfo_ { int r, g, b, a; /* Framebuffer values in bits. */ int flags; /* Store different properties. */ int tex_max; /* Max texture size. */ + int multitex_max; /* Max multitexture levels. */ } glInfo; extern glInfo gl_screen; /* Local structure set with gl_init etc. */