diff --git a/clutter/cogl/cogl/cogl-context.c b/clutter/cogl/cogl/cogl-context.c index 20c307e13..9f600873d 100644 --- a/clutter/cogl/cogl/cogl-context.c +++ b/clutter/cogl/cogl/cogl-context.c @@ -152,6 +152,8 @@ cogl_create_context (void) _context->current_pbo = NULL; + _context->max_texture_units = -1; + return TRUE; } diff --git a/clutter/cogl/cogl/cogl-context.h b/clutter/cogl/cogl/cogl-context.h index 3d59c0ecf..6872019aa 100644 --- a/clutter/cogl/cogl/cogl-context.h +++ b/clutter/cogl/cogl/cogl-context.h @@ -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; diff --git a/clutter/cogl/cogl/cogl.c b/clutter/cogl/cogl/cogl.c index b4f97485a..b5b501bd2 100644 --- a/clutter/cogl/cogl/cogl.c +++ b/clutter/cogl/cogl/cogl.c @@ -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