aboutsummaryrefslogtreecommitdiffstats
path: root/src/mesa/main/texstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main/texstate.c')
-rw-r--r--src/mesa/main/texstate.c463
1 files changed, 414 insertions, 49 deletions
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 32ce6005630..64df9016dc9 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -1,4 +1,4 @@
-/* $Id: texstate.c,v 1.13 2000/05/23 20:10:50 brianp Exp $ */
+/* $Id: texstate.c,v 1.14 2000/06/27 21:42:13 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -71,64 +71,287 @@ _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexEnv");
if (target==GL_TEXTURE_ENV) {
-
- if (pname==GL_TEXTURE_ENV_MODE) {
- GLenum mode = (GLenum) (GLint) *param;
- switch (mode) {
- case GL_ADD:
- if (!ctx->Extensions.HaveTextureEnvAdd) {
- gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)");
- return;
- }
- /* FALL-THROUGH */
- case GL_MODULATE:
- case GL_BLEND:
- case GL_DECAL:
- case GL_REPLACE:
- /* A small optimization for drivers */
- if (texUnit->EnvMode == mode)
- return;
-
- if (MESA_VERBOSE & (VERBOSE_STATE|VERBOSE_TEXTURE))
- fprintf(stderr, "glTexEnv: old mode %s, new mode %s\n",
- gl_lookup_enum_by_nr(texUnit->EnvMode),
- gl_lookup_enum_by_nr(mode));
-
- texUnit->EnvMode = mode;
- ctx->NewState |= NEW_TEXTURE_ENV;
- break;
- default:
- gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
- return;
- }
- }
- else if (pname==GL_TEXTURE_ENV_COLOR) {
- texUnit->EnvColor[0] = CLAMP( param[0], 0.0F, 1.0F );
- texUnit->EnvColor[1] = CLAMP( param[1], 0.0F, 1.0F );
- texUnit->EnvColor[2] = CLAMP( param[2], 0.0F, 1.0F );
- texUnit->EnvColor[3] = CLAMP( param[3], 0.0F, 1.0F );
- }
- else {
- gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
- return;
+ switch (pname) {
+ case GL_TEXTURE_ENV_MODE:
+ {
+ GLenum mode = (GLenum) (GLint) *param;
+ switch (mode) {
+ case GL_MODULATE:
+ case GL_BLEND:
+ case GL_DECAL:
+ case GL_REPLACE:
+ case GL_ADD:
+ case GL_COMBINE_EXT:
+ if (mode == GL_ADD &&
+ !ctx->Extensions.HaveTextureEnvAdd) {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)");
+ return;
+ }
+ if (mode == GL_COMBINE_EXT &&
+ !ctx->Extensions.HaveTextureEnvCombine) {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)");
+ return;
+ }
+ if (texUnit->EnvMode == mode)
+ return; /* no change */
+ texUnit->EnvMode = mode;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ break;
+ default:
+ gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
+ return;
+ }
+ }
+ break;
+ case GL_TEXTURE_ENV_COLOR:
+ texUnit->EnvColor[0] = CLAMP( param[0], 0.0F, 1.0F );
+ texUnit->EnvColor[1] = CLAMP( param[1], 0.0F, 1.0F );
+ texUnit->EnvColor[2] = CLAMP( param[2], 0.0F, 1.0F );
+ texUnit->EnvColor[3] = CLAMP( param[3], 0.0F, 1.0F );
+ break;
+ case GL_COMBINE_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ GLenum mode = (GLenum) (GLint) *param;
+ switch (mode) {
+ case GL_REPLACE:
+ case GL_MODULATE:
+ case GL_ADD:
+ case GL_ADD_SIGNED_EXT:
+ case GL_INTERPOLATE_EXT:
+ if (texUnit->CombineModeRGB == mode)
+ return; /* no change */
+ texUnit->CombineModeRGB = mode;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ break;
+ default:
+ gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
+ return;
+ }
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
+ return;
+ }
+ break;
+ case GL_COMBINE_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ GLenum mode = (GLenum) (GLint) *param;
+ switch (mode) {
+ case GL_REPLACE:
+ case GL_MODULATE:
+ case GL_ADD:
+ case GL_ADD_SIGNED_EXT:
+ case GL_INTERPOLATE_EXT:
+ if (texUnit->CombineModeA == mode)
+ return; /* no change */
+ texUnit->CombineModeA = mode;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ break;
+ default:
+ gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
+ return;
+ }
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
+ return;
+ }
+ break;
+ case GL_SOURCE0_RGB_EXT:
+ case GL_SOURCE1_RGB_EXT:
+ case GL_SOURCE2_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ GLenum source = (GLenum) (GLint) *param;
+ GLuint s = pname - GL_SOURCE0_RGB_EXT;
+ switch (source) {
+ case GL_TEXTURE:
+ case GL_CONSTANT_EXT:
+ case GL_PRIMARY_COLOR_EXT:
+ case GL_PREVIOUS_EXT:
+ if (texUnit->CombineSourceRGB[s] == source)
+ return; /* no change */
+ texUnit->CombineSourceRGB[s] = source;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ break;
+ default:
+ gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
+ return;
+ }
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
+ return;
+ }
+ break;
+ case GL_SOURCE0_ALPHA_EXT:
+ case GL_SOURCE1_ALPHA_EXT:
+ case GL_SOURCE2_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ GLenum source = (GLenum) (GLint) *param;
+ GLuint s = pname - GL_SOURCE0_ALPHA_EXT;
+ switch (source) {
+ case GL_TEXTURE:
+ case GL_CONSTANT_EXT:
+ case GL_PRIMARY_COLOR_EXT:
+ case GL_PREVIOUS_EXT:
+ if (texUnit->CombineSourceA[s] == source) return;
+ texUnit->CombineSourceA[s] = source;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ break;
+ default:
+ gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
+ return;
+ }
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
+ return;
+ }
+ break;
+ case GL_OPERAND0_RGB_EXT:
+ case GL_OPERAND1_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ GLenum operand = (GLenum) (GLint) *param;
+ GLuint s = pname - GL_OPERAND0_RGB_EXT;
+ switch (operand) {
+ case GL_SRC_COLOR:
+ case GL_ONE_MINUS_SRC_COLOR:
+ texUnit->CombineOperandRGB[s] = operand;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ break;
+ case GL_SRC_ALPHA:
+ case GL_ONE_MINUS_SRC_ALPHA:
+ texUnit->CombineOperandA[s] = operand;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ break;
+ default:
+ gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
+ return;
+ }
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
+ return;
+ }
+ break;
+ case GL_OPERAND0_ALPHA_EXT:
+ case GL_OPERAND1_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ GLenum operand = (GLenum) (GLint) *param;
+ switch (operand) {
+ case GL_SRC_ALPHA:
+ case GL_ONE_MINUS_SRC_ALPHA:
+ texUnit->CombineOperandA[pname-GL_OPERAND0_ALPHA_EXT]
+ = operand;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ break;
+ default:
+ gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
+ return;
+ }
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
+ return;
+ }
+ break;
+ case GL_OPERAND2_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ if ((GLenum) (GLint) *param == GL_SRC_ALPHA) {
+ texUnit->CombineOperandRGB[2] = (GLenum) (GLint) *param;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ }
+ else {
+ gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
+ return;
+ }
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
+ return;
+ }
+ break;
+ case GL_OPERAND2_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ if ((GLenum) (GLint) *param == GL_SRC_ALPHA) {
+ texUnit->CombineOperandA[2] = (GLenum) (GLint) *param;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ }
+ else {
+ gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
+ return;
+ }
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
+ return;
+ }
+ break;
+ case GL_RGB_SCALE_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ if (*param == 1.0) {
+ texUnit->CombineScaleShiftRGB = 0;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ }
+ else if (*param == 2.0) {
+ texUnit->CombineScaleShiftRGB = 1;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ }
+ else if (*param == 4.0) {
+ texUnit->CombineScaleShiftRGB = 2;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ }
+ else {
+ gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
+ return;
+ }
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
+ return;
+ }
+ break;
+ case GL_ALPHA_SCALE:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ if (*param == 1.0) {
+ texUnit->CombineScaleShiftA = 0;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ }
+ else if (*param == 2.0) {
+ texUnit->CombineScaleShiftA = 1;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ }
+ else if (*param == 4.0) {
+ texUnit->CombineScaleShiftA = 2;
+ ctx->NewState |= NEW_TEXTURE_ENV;
+ }
+ else {
+ gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
+ return;
+ }
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
+ return;
+ }
+ break;
+ default:
+ gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
+ return;
}
-
}
else if (target==GL_TEXTURE_FILTER_CONTROL_EXT) {
-
if (!ctx->Extensions.HaveTextureLodBias) {
gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
return;
}
-
- if (pname==GL_TEXTURE_LOD_BIAS_EXT) {
+ if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
texUnit->LodBias = param[0];
}
else {
gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
return;
}
-
}
else {
gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" );
@@ -184,7 +407,7 @@ void
_mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
{
GET_CURRENT_CONTEXT(ctx);
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnvfv");
@@ -192,6 +415,7 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
return;
}
+
switch (pname) {
case GL_TEXTURE_ENV_MODE:
*params = ENUM_TO_FLOAT(texUnit->EnvMode);
@@ -199,6 +423,34 @@ _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
case GL_TEXTURE_ENV_COLOR:
COPY_4FV( params, texUnit->EnvColor );
break;
+ case GL_RGB_SCALE_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ if (texUnit->CombineScaleShiftRGB == 0)
+ *params = 1.0;
+ else if (texUnit->CombineScaleShiftRGB == 1)
+ *params = 2.0;
+ else
+ *params = 4.0;
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
+ return;
+ }
+ break;
+ case GL_ALPHA_SCALE:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ if (texUnit->CombineScaleShiftA == 0)
+ *params = 1.0;
+ else if (texUnit->CombineScaleShiftA == 1)
+ *params = 2.0;
+ else
+ *params = 4.0;
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
+ return;
+ }
+ break;
default:
gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
}
@@ -209,14 +461,15 @@ void
_mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
{
GET_CURRENT_CONTEXT(ctx);
- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
+ const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnviv");
- if (target!=GL_TEXTURE_ENV) {
+ if (target != GL_TEXTURE_ENV) {
gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
return;
}
+
switch (pname) {
case GL_TEXTURE_ENV_MODE:
*params = (GLint) texUnit->EnvMode;
@@ -226,6 +479,118 @@ _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] );
params[2] = FLOAT_TO_INT( texUnit->EnvColor[2] );
params[3] = FLOAT_TO_INT( texUnit->EnvColor[3] );
+ break;
+ case GL_COMBINE_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineModeRGB;
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_COMBINE_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineModeA;
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_SOURCE0_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineSourceRGB[0];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_SOURCE1_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineSourceRGB[1];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_SOURCE2_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineSourceRGB[2];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_SOURCE0_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineSourceA[0];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_SOURCE1_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineSourceA[1];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_SOURCE2_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineSourceA[2];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_OPERAND0_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineOperandRGB[0];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_OPERAND1_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineOperandRGB[1];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_OPERAND2_RGB_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineOperandRGB[2];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_OPERAND0_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineOperandA[0];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_OPERAND1_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineOperandA[1];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
+ break;
+ case GL_OPERAND2_ALPHA_EXT:
+ if (ctx->Extensions.HaveTextureEnvCombine) {
+ *params = (GLint) texUnit->CombineOperandA[2];
+ }
+ else {
+ gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
+ }
break;
default:
gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" );