From 7a372bc0011b6301cc8b46767493a23218a67cff Mon Sep 17 00:00:00 2001 From: Neil Roberts Date: Fri, 12 Feb 2010 14:26:33 +0000 Subject: [PATCH] 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. --- clutter/cogl/cogl/cogl-context.c | 2 ++ clutter/cogl/cogl/cogl-context.h | 4 ++++ clutter/cogl/cogl/cogl.c | 12 +++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/clutter/cogl/cogl/cogl-context.c b/clutter/cogl/cogl/cogl-context.c index 20c307e..9f60087 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 3d59c0e..6872019 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 b4f9748..b5b501b 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 -- 2.7.4