647
647
if (G_UNLIKELY (ctx->max_activateable_texture_units == -1))
649
#if defined (HAVE_COGL_GL)
650
GLint max_tex_coords;
651
GLint max_combined_tex_units;
652
GE (glGetIntegerv (GL_MAX_TEXTURE_COORDS, &max_tex_coords));
653
GE (glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
654
&max_combined_tex_units));
655
ctx->max_activateable_texture_units =
656
MAX (max_tex_coords - 1, max_combined_tex_units);
657
#elif defined (HAVE_COGL_GLES2)
658
GLint max_vertex_attribs;
659
GLint max_combined_tex_units;
660
GE (glGetIntegerv (GL_MAX_VERTEX_ATTRIBS, &max_vertex_attribs));
661
GE (glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
662
&max_combined_tex_units));
654
/* GL_MAX_TEXTURE_COORDS is provided for both GLSL and ARBfp. It
655
defines the number of texture coordinates that can be
656
uploaded (but doesn't necessarily relate to how many texture
657
images can be sampled) */
658
if (cogl_features_available (COGL_FEATURE_SHADERS_GLSL) ||
659
cogl_features_available (COGL_FEATURE_SHADERS_ARBFP))
660
/* Previously this code subtracted the value by one but there
661
was no explanation for why it did this and it doesn't seem
662
to make sense so it has been removed */
663
GE (glGetIntegerv (GL_MAX_TEXTURE_COORDS, values + n_values++));
665
/* GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS is defined for GLSL but
667
if (cogl_features_available (COGL_FEATURE_SHADERS_GLSL))
668
GE (glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
669
values + n_values++));
670
#endif /* HAVE_COGL_GL */
672
#ifdef HAVE_COGL_GLES2
674
GE (glGetIntegerv (GL_MAX_VERTEX_ATTRIBS, values + n_values));
663
675
/* Two of the vertex attribs need to be used for the position
665
ctx->max_activateable_texture_units =
666
MAX (max_vertex_attribs - 2, max_combined_tex_units);
677
values[n_values++] -= 2;
679
GE (glGetIntegerv (GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS,
680
values + n_values++));
682
#else /* HAVE_COGL_GLES2 */
684
/* GL_MAX_TEXTURE_UNITS defines the number of units that are
685
usable from the fixed function pipeline, therefore it isn't
686
available in GLES2. These are also tied to the number of
687
texture coordinates that can be uploaded so it should be less
688
than that available from the shader extensions */
668
689
GE (glGetIntegerv (GL_MAX_TEXTURE_UNITS,
669
&ctx->max_activateable_texture_units));
690
values + n_values++));
692
#endif /* HAVE_COGL_GLES2 */
694
g_assert (n_values <= G_N_ELEMENTS (values) &&
697
/* Use the maximum value */
698
ctx->max_activateable_texture_units = values[0];
699
for (i = 1; i < n_values; i++)
700
ctx->max_activateable_texture_units =
701
MAX (values[i], ctx->max_activateable_texture_units);
673
704
return ctx->max_activateable_texture_units;