cogl: Cache the value for GL_MAX_TEXTURE_UNITS

The function _cogl_get_max_texture_units is called quite often while
rendering and it returns a constant value so we might as well cache
the result. Calling glGetInteger on Mesa can be expensive because it
flushes a lot of state.
This commit is contained in:
Neil Roberts 2010-02-12 14:26:33 +00:00
parent e48b817b0a
commit fbe9e80a07
3 changed files with 15 additions and 3 deletions

View File

@ -152,6 +152,8 @@ cogl_create_context (void)
_context->current_pbo = NULL; _context->current_pbo = NULL;
_context->max_texture_units = -1;
return TRUE; return TRUE;
} }

View File

@ -126,6 +126,10 @@ typedef struct
chances of getting the same colour during an animation */ chances of getting the same colour during an animation */
guint8 journal_rectangles_color; guint8 journal_rectangles_color;
/* Cached value for GL_MAX_TEXTURE_UNITS to avoid calling
glGetInteger too often */
GLint max_texture_units;
CoglContextDriver drv; CoglContextDriver drv;
} CoglContext; } CoglContext;

View File

@ -854,11 +854,17 @@ _cogl_destroy_texture_units (void)
unsigned int unsigned int
_cogl_get_max_texture_image_units (void) _cogl_get_max_texture_image_units (void)
{ {
GLint nb_texture_image_units; _COGL_GET_CONTEXT (ctx, 0);
GE( glGetIntegerv(GL_MAX_TEXTURE_UNITS, &nb_texture_image_units) ); /* This function is called quite often so we cache the value to
avoid too many GL calls */
if (ctx->max_texture_units == -1)
{
ctx->max_texture_units = 1;
GE( glGetIntegerv (GL_MAX_TEXTURE_UNITS, &ctx->max_texture_units) );
}
return nb_texture_image_units; return ctx->max_texture_units;
} }
void void