summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorMarek Olšák <[email protected]>2017-11-15 22:10:43 +0100
committerMarek Olšák <[email protected]>2018-02-13 01:00:45 +0100
commit78043a75f6c05c470da97d1f18615821d69177c0 (patch)
tree041ebf7ab6e8faf5c406913f22fd51533018c8a5 /src/mesa
parent07c10cc59c164ddd0109e061dac8edf47437d8ca (diff)
mesa: decrease the array size of ctx->Texture.FixedFuncUnit to 8
GL allows doing glTexEnv on 192 texture units, while in reality, only MaxTextureCoordUnits units are used by fixed-func shaders. There is a piglit patch that adjusts piglits/texunits to check only MaxTextureCoordUnits units. Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/main/enable.c5
-rw-r--r--src/mesa/main/mtypes.h2
-rw-r--r--src/mesa/main/texenv.c27
-rw-r--r--src/mesa/main/texstate.c2
-rw-r--r--src/mesa/main/texstate.h3
5 files changed, 37 insertions, 2 deletions
diff --git a/src/mesa/main/enable.c b/src/mesa/main/enable.c
index 4c5f9dce5e4..f23673a6cdc 100644
--- a/src/mesa/main/enable.c
+++ b/src/mesa/main/enable.c
@@ -209,6 +209,8 @@ enable_texture(struct gl_context *ctx, GLboolean state, GLbitfield texBit)
{
struct gl_fixedfunc_texture_unit *texUnit =
_mesa_get_current_fixedfunc_tex_unit(ctx);
+ if (!texUnit)
+ return GL_FALSE;
const GLbitfield newenabled = state
? (texUnit->Enabled | texBit) : (texUnit->Enabled & ~texBit);
@@ -1293,6 +1295,9 @@ is_texture_enabled(struct gl_context *ctx, GLbitfield bit)
const struct gl_fixedfunc_texture_unit *const texUnit =
_mesa_get_current_fixedfunc_tex_unit(ctx);
+ if (!texUnit)
+ return GL_FALSE;
+
return (texUnit->Enabled & bit) ? GL_TRUE : GL_FALSE;
}
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 562fb17c10f..3a4fdb57c1c 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1370,7 +1370,7 @@ struct gl_texture_attrib
GLint NumCurrentTexUsed;
struct gl_texture_unit Unit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
- struct gl_fixedfunc_texture_unit FixedFuncUnit[MAX_COMBINED_TEXTURE_IMAGE_UNITS];
+ struct gl_fixedfunc_texture_unit FixedFuncUnit[MAX_TEXTURE_COORD_UNITS];
};
diff --git a/src/mesa/main/texenv.c b/src/mesa/main/texenv.c
index 9018ce9bc4c..22fc8da1cab 100644
--- a/src/mesa/main/texenv.c
+++ b/src/mesa/main/texenv.c
@@ -400,6 +400,15 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
struct gl_fixedfunc_texture_unit *texUnit =
_mesa_get_current_fixedfunc_tex_unit(ctx);
+ /* The GL spec says that we should report an error if the unit is greater
+ * than GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, but in practice, only
+ * fixed-function units are usable. This is probably a spec bug.
+ * Ignore glTexEnv(GL_TEXTURE_ENV) calls for non-fixed-func units,
+ * because we don't want to process calls that have no effect.
+ */
+ if (!texUnit)
+ return;
+
switch (pname) {
case GL_TEXTURE_ENV_MODE:
set_env_mode(ctx, texUnit, (GLenum) iparam0);
@@ -649,6 +658,15 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
struct gl_fixedfunc_texture_unit *texUnit =
_mesa_get_current_fixedfunc_tex_unit(ctx);
+ /* The GL spec says that we should report an error if the unit is greater
+ * than GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, but in practice, only
+ * fixed-function units are usable. This is probably a spec bug.
+ * Ignore calls for non-fixed-func units, because we don't process
+ * glTexEnv for them either.
+ */
+ if (!texUnit)
+ return;
+
if (pname == GL_TEXTURE_ENV_COLOR) {
if(ctx->NewState & (_NEW_BUFFERS | _NEW_FRAG_CLAMP))
_mesa_update_state(ctx);
@@ -717,6 +735,15 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
struct gl_fixedfunc_texture_unit *texUnit =
_mesa_get_current_fixedfunc_tex_unit(ctx);
+ /* The GL spec says that we should report an error if the unit is greater
+ * than GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, but in practice, only
+ * fixed-function units are usable. This is probably a spec bug.
+ * Ignore calls for non-fixed-func units, because we don't process
+ * glTexEnv for them either.
+ */
+ if (!texUnit)
+ return;
+
if (pname == GL_TEXTURE_ENV_COLOR) {
params[0] = FLOAT_TO_INT( texUnit->EnvColor[0] );
params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] );
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 2b05630e619..f9f50a30054 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -103,7 +103,7 @@ _mesa_copy_texture_state( const struct gl_context *src, struct gl_context *dst )
}
}
- for (u = 0; u < src->Const.MaxCombinedTextureImageUnits; u++) {
+ for (u = 0; u < src->Const.MaxTextureCoordUnits; u++) {
dst->Texture.FixedFuncUnit[u].Enabled = src->Texture.FixedFuncUnit[u].Enabled;
dst->Texture.FixedFuncUnit[u].EnvMode = src->Texture.FixedFuncUnit[u].EnvMode;
COPY_4V(dst->Texture.FixedFuncUnit[u].EnvColor, src->Texture.FixedFuncUnit[u].EnvColor);
diff --git a/src/mesa/main/texstate.h b/src/mesa/main/texstate.h
index cf3f7e5a216..c0b73b14e82 100644
--- a/src/mesa/main/texstate.h
+++ b/src/mesa/main/texstate.h
@@ -65,6 +65,9 @@ _mesa_get_current_fixedfunc_tex_unit(struct gl_context *ctx)
{
unsigned unit = ctx->Texture.CurrentUnit;
+ if (unit >= ARRAY_SIZE(ctx->Texture.FixedFuncUnit))
+ return NULL;
+
return &ctx->Texture.FixedFuncUnit[unit];
}