summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mesa/main/context.c3
-rw-r--r--src/mesa/main/mtypes.h2
-rw-r--r--src/mesa/main/texparam.c4
-rw-r--r--src/mesa/main/texstate.c29
4 files changed, 25 insertions, 13 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 017ad502959..74c6ac4990c 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -577,6 +577,9 @@ _mesa_init_constants(GLcontext *ctx)
ctx->Const.MaxTextureCoordUnits));
ASSERT(ctx->Const.FragmentProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
ASSERT(ctx->Const.VertexProgram.MaxLocalParams <= MAX_PROGRAM_LOCAL_PARAMS);
+ ASSERT(ctx->Const.MaxCombinedTextureImageUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
+ ASSERT(ctx->Const.MaxTextureCoordUnits <= MAX_COMBINED_TEXTURE_IMAGE_UNITS);
+ ASSERT(MAX_COMBINED_TEXTURE_IMAGE_UNITS <= 32); /* GLbitfield size limit */
ASSERT(MAX_NV_FRAGMENT_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
ASSERT(MAX_NV_VERTEX_PROGRAM_TEMPS <= MAX_PROGRAM_TEMPS);
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index aeb9b3adea8..2640ba5ac42 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1361,7 +1361,7 @@ struct gl_texture_unit
struct gl_texture_attrib
{
GLuint CurrentUnit; /**< GL_ACTIVE_TEXTURE */
- struct gl_texture_unit Unit[MAX_TEXTURE_UNITS];
+ struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
diff --git a/src/mesa/main/texparam.c b/src/mesa/main/texparam.c
index c4f24950187..0fde89b5079 100644
--- a/src/mesa/main/texparam.c
+++ b/src/mesa/main/texparam.c
@@ -87,7 +87,7 @@ get_texobj(GLcontext *ctx, GLenum target, GLboolean get)
{
struct gl_texture_unit *texUnit;
- if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureImageUnits) {
+ if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"gl%sTexParameter(current unit)", get ? "Get" : "");
return NULL;
@@ -815,7 +815,7 @@ _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END(ctx);
- if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureImageUnits) {
+ if (ctx->Texture.CurrentUnit >= ctx->Const.MaxCombinedTextureImageUnits) {
_mesa_error(ctx, GL_INVALID_OPERATION,
"glGetTexLevelParameteriv(current unit)");
return;
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 6f8831dfe03..8c4399a430a 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -77,7 +77,7 @@ _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst )
dst->Texture.SharedPalette = src->Texture.SharedPalette;
/* per-unit state */
- for (u = 0; u < src->Const.MaxTextureImageUnits; u++) {
+ for (u = 0; u < src->Const.MaxCombinedTextureImageUnits; u++) {
dst->Texture.Unit[u].Enabled = src->Texture.Unit[u].Enabled;
dst->Texture.Unit[u].EnvMode = src->Texture.Unit[u].EnvMode;
COPY_4V(dst->Texture.Unit[u].EnvColor, src->Texture.Unit[u].EnvColor);
@@ -282,15 +282,23 @@ calculate_derived_texenv( struct gl_tex_env_combine_state *state,
void GLAPIENTRY
_mesa_ActiveTextureARB(GLenum texture)
{
- GET_CURRENT_CONTEXT(ctx);
const GLuint texUnit = texture - GL_TEXTURE0;
+ GLuint k;
+ GET_CURRENT_CONTEXT(ctx);
+
+ /* See OpenGL spec for glActiveTexture: */
+ k = MAX2(ctx->Const.MaxCombinedTextureImageUnits,
+ ctx->Const.MaxTextureCoordUnits);
+
+ ASSERT(k <= Elements(ctx->Texture.Unit));
+
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
_mesa_debug(ctx, "glActiveTexture %s\n",
_mesa_lookup_enum_by_nr(texture));
- if (texUnit >= ctx->Const.MaxTextureImageUnits) {
+ if (texUnit >= k) {
_mesa_error(ctx, GL_INVALID_ENUM, "glActiveTexture(texture=%s)",
_mesa_lookup_enum_by_nr(texture));
return;
@@ -510,7 +518,7 @@ update_texture_state( GLcontext *ctx )
/*
* Update texture unit state.
*/
- for (unit = 0; unit < ctx->Const.MaxTextureImageUnits; unit++) {
+ for (unit = 0; unit < ctx->Const.MaxCombinedTextureImageUnits; unit++) {
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
GLbitfield enabledVertTargets = 0x0;
GLbitfield enabledFragTargets = 0x0;
@@ -760,14 +768,15 @@ _mesa_init_texture(GLcontext *ctx)
ctx->Texture.SharedPalette = GL_FALSE;
_mesa_init_colortable(&ctx->Texture.Palette);
- for (u = 0; u < MAX_TEXTURE_UNITS; u++)
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++)
init_texture_unit(ctx, u);
/* After we're done initializing the context's texture state the default
- * texture objects' refcounts should be at least MAX_TEXTURE_UNITS + 1.
+ * texture objects' refcounts should be at least
+ * MAX_COMBINED_TEXTURE_IMAGE_UNITS + 1.
*/
assert(ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]->RefCount
- >= MAX_TEXTURE_UNITS + 1);
+ >= MAX_COMBINED_TEXTURE_IMAGE_UNITS + 1);
/* Allocate proxy textures */
if (!alloc_proxy_textures( ctx ))
@@ -786,7 +795,7 @@ _mesa_free_texture_data(GLcontext *ctx)
GLuint u, tgt;
/* unreference current textures */
- for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) {
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
/* The _Current texture could account for another reference */
_mesa_reference_texobj(&ctx->Texture.Unit[u]._Current, NULL);
@@ -799,7 +808,7 @@ _mesa_free_texture_data(GLcontext *ctx)
for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++)
ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
- for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++)
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++)
_mesa_free_colortable_data(&ctx->Texture.Unit[u].ColorTable);
}
@@ -814,7 +823,7 @@ _mesa_update_default_objects_texture(GLcontext *ctx)
{
GLuint u, tex;
- for (u = 0; u < MAX_TEXTURE_UNITS; u++) {
+ for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[u];
for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
_mesa_reference_texobj(&texUnit->CurrentTex[tex],