From 52cb54f5fa665fdf06270fc58121617b44877639 Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Tue, 26 Jan 2010 18:47:25 +0000 Subject: [PATCH] cogl: Fix checks of the number of available texture units We were checking the number of texture units against the GL enum that is used in glGetInteger() to query that number. Let's abstract this in a little function. Took the opportunity to dig a bit on the usage of GL limits for the number of texture (image) units and document our use of them. We'll need something finer grained if we want to fully exploit texture image units with a programmable pipeline. --- clutter/cogl/cogl/cogl-internal.h | 2 ++ clutter/cogl/cogl/cogl-material.c | 10 ++-------- clutter/cogl/cogl/cogl.c | 30 ++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/clutter/cogl/cogl/cogl-internal.h b/clutter/cogl/cogl/cogl-internal.h index 585220a1d..f38107ead 100644 --- a/clutter/cogl/cogl/cogl-internal.h +++ b/clutter/cogl/cogl/cogl-internal.h @@ -101,6 +101,8 @@ CoglTextureUnit * _cogl_get_texture_unit (int index_); void _cogl_destroy_texture_units (void); +guint +_cogl_get_max_texture_image_units (void); void _cogl_flush_face_winding (void); diff --git a/clutter/cogl/cogl/cogl-material.c b/clutter/cogl/cogl/cogl-material.c index 00c376fb5..65b7258d0 100644 --- a/clutter/cogl/cogl/cogl-material.c +++ b/clutter/cogl/cogl/cogl-material.c @@ -48,12 +48,6 @@ #include "../gles/cogl-gles2-wrapper.h" #endif -#ifdef HAVE_COGL_GLES -#define COGL_MATERIAL_MAX_TEXTURE_UNITS GL_MAX_TEXTURE_UNITS -#else -#define COGL_MATERIAL_MAX_TEXTURE_UNITS GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS -#endif - #ifdef HAVE_COGL_GL #define glActiveTexture ctx->drv.pf_glActiveTexture #define glClientActiveTexture ctx->drv.pf_glClientActiveTexture @@ -828,7 +822,7 @@ cogl_material_set_layer (CoglHandle material_handle, _cogl_material_pre_change_notify (material, FALSE, NULL); material->n_layers = g_list_length (material->layers); - if (material->n_layers >= COGL_MATERIAL_MAX_TEXTURE_UNITS) + if (material->n_layers >= _cogl_get_max_texture_image_units ()) { if (!(material->flags & COGL_MATERIAL_FLAG_SHOWN_SAMPLER_WARNING)) { @@ -1537,7 +1531,7 @@ _cogl_material_flush_layers_gl_state (CoglMaterial *material, layer->flags &= ~COGL_MATERIAL_LAYER_FLAG_DIRTY; - if ((i+1) >= COGL_MATERIAL_MAX_TEXTURE_UNITS) + if ((i+1) >= _cogl_get_max_texture_image_units ()) break; } diff --git a/clutter/cogl/cogl/cogl.c b/clutter/cogl/cogl/cogl.c index ca76641f5..387eac417 100644 --- a/clutter/cogl/cogl/cogl.c +++ b/clutter/cogl/cogl/cogl.c @@ -788,6 +788,36 @@ _cogl_destroy_texture_units (void) g_list_free (ctx->texture_units); } +/* + * This is more complicated than that, another pass needs to be done when + * cogl have a neat way of saying if we are using the fixed function pipeline + * or not (for the GL case): + * MAX_TEXTURE_UNITS: fixed function pipeline, a texture unit has both a + * sampler and a set of texture coordinates + * MAX_TEXTURE_IMAGE_UNITS: number of samplers one can use from a fragment + * program/shader (ARBfp1.0 asm/GLSL) + * MAX_VERTEX_TEXTURE_UNITS: number of samplers one can use from a vertex + * program/shader (can be 0) + * MAX_COMBINED_TEXTURE_IMAGE_UNITS: Maximum samplers one can use, counting both + * the vertex and fragment shaders + * + * If both the vertex shader and the fragment processing stage access the same + * texture image unit, then that counts as using two texture image units + * against the latter limit: http://www.opengl.org/sdk/docs/man/xhtml/glGet.xml + * + * Note that, for now, we use GL_MAX_TEXTURE_UNITS as we are exposing the + * fixed function pipeline. + */ +guint +_cogl_get_max_texture_image_units (void) +{ + GLint nb_texture_image_units; + + GE( glGetIntegerv(GL_MAX_TEXTURE_UNITS, &nb_texture_image_units) ); + + return nb_texture_image_units; +} + void cogl_push_matrix (void) {