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:
parent
22c33b2fea
commit
7a372bc001
@ -152,6 +152,8 @@ cogl_create_context (void)
|
||||
|
||||
_context->current_pbo = NULL;
|
||||
|
||||
_context->max_texture_units = -1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -126,6 +126,10 @@ typedef struct
|
||||
chances of getting the same colour during an animation */
|
||||
guint8 journal_rectangles_color;
|
||||
|
||||
/* Cached value for GL_MAX_TEXTURE_UNITS to avoid calling
|
||||
glGetInteger too often */
|
||||
GLint max_texture_units;
|
||||
|
||||
CoglContextDriver drv;
|
||||
} CoglContext;
|
||||
|
||||
|
@ -854,11 +854,17 @@ _cogl_destroy_texture_units (void)
|
||||
unsigned int
|
||||
_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
|
||||
|
Loading…
Reference in New Issue
Block a user