diff options
author | Brian Paul <[email protected]> | 2006-03-24 23:53:50 +0000 |
---|---|---|
committer | Brian Paul <[email protected]> | 2006-03-24 23:53:50 +0000 |
commit | 1bbc203c6e7fa200339204d4b686616ed030e6c1 (patch) | |
tree | 98c9a03756df56a42c7b3447dc64f2e1535dfc9c /src/mesa/main/texstate.c | |
parent | 6494541eaa375bdf4241ea7b8f8a881cbb0debda (diff) |
Clean up the recent code related to texture_override(). Pass params in a
more logical order.
Remove a mess of stray ^M chars.
Fix a bug when checking if the texture object's format is GL_COLOR_INDEX
or GL_DEPTH_COMPONENT. This fixes a segfault when GL_TEXTURE_BASE_LEVEL!=0.
Diffstat (limited to 'src/mesa/main/texstate.c')
-rw-r--r-- | src/mesa/main/texstate.c | 101 |
1 files changed, 56 insertions, 45 deletions
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c index 5de5f6815ab..daf579a7bfc 100644 --- a/src/mesa/main/texstate.c +++ b/src/mesa/main/texstate.c @@ -39,7 +39,7 @@ #include "texstate.h" #include "texenvprogram.h" #include "mtypes.h" -#include "math/m_xform.h"
+#include "math/m_xform.h" #include "shaderobjects.h" @@ -2766,23 +2766,29 @@ update_texture_matrices( GLcontext *ctx ) } } } -
-
-static void
-texture_override( struct gl_texture_object *texObj, GLuint textureBit, GLcontext *ctx,
- GLbitfield enableBits, struct gl_texture_unit *texUnit )
-{
- if (!texUnit->_ReallyEnabled && (enableBits & textureBit)) {
- if (!texObj->Complete) {
- _mesa_test_texobj_completeness(ctx, texObj);
- }
- if (texObj->Complete) {
- texUnit->_ReallyEnabled = textureBit;
- texUnit->_Current = texObj;
- }
- }
+ + +/** + * Helper function for determining which texture object (1D, 2D, cube, etc) + * should actually be used. + */ +static void +texture_override(GLcontext *ctx, + struct gl_texture_unit *texUnit, GLbitfield enableBits, + struct gl_texture_object *texObj, GLuint textureBit) +{ + if (!texUnit->_ReallyEnabled && (enableBits & textureBit)) { + if (!texObj->Complete) { + _mesa_test_texobj_completeness(ctx, texObj); + } + if (texObj->Complete) { + texUnit->_ReallyEnabled = textureBit; + texUnit->_Current = texObj; + } + } } + /** * \note This routine refers to derived texture matrix values to * compute the ENABLE_TEXMAT flags, but is only called on @@ -2794,9 +2800,9 @@ texture_override( struct gl_texture_object *texObj, GLuint textureBit, GLcontext static void update_texture_state( GLcontext *ctx ) { - GLuint unit;
- struct gl2_program_intf **prog = ctx->ShaderObjects.CurrentProgram;
- GLbitfield progteximageusage[MAX_TEXTURE_IMAGE_UNITS];
+ GLuint unit; + struct gl2_program_intf **prog = ctx->ShaderObjects.CurrentProgram; + GLbitfield progteximageusage[MAX_TEXTURE_IMAGE_UNITS]; ctx->NewState |= _NEW_TEXTURE; /* TODO: only set this if there are * actual changes. @@ -2805,20 +2811,19 @@ update_texture_state( GLcontext *ctx ) ctx->Texture._EnabledUnits = 0; ctx->Texture._GenFlags = 0; ctx->Texture._TexMatEnabled = 0; - ctx->Texture._TexGenEnabled = 0;
-
- /*
- * Grab texture image usage state from shader program. It must be grabbed every time
- * uniform sampler changes, so maybe there is a better place to perform these rather
- * expensive computations.
- */
- if (ctx->ShaderObjects._FragmentShaderPresent) {
- (**prog).GetTextureImageUsage (prog, progteximageusage);
+ ctx->Texture._TexGenEnabled = 0; + + /* + * Grab texture image usage state from shader program. It must be + * grabbed every time uniform sampler changes, so maybe there is a + * better place to perform these rather expensive computations. + */ + if (ctx->ShaderObjects._FragmentShaderPresent) { + (**prog).GetTextureImageUsage (prog, progteximageusage); } - /* Update texture unit state. - * XXX this loop should probably be broken into separate loops for - * texture coord units and texture image units. + /* + * Update texture unit state. */ for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) { struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; @@ -2828,10 +2833,10 @@ update_texture_state( GLcontext *ctx ) texUnit->_ReallyEnabled = 0; texUnit->_GenFlags = 0; - /* Get the bitmask of texture enables */
- if (ctx->ShaderObjects._FragmentShaderPresent) {
+ /* Get the bitmask of texture enables */ + if (ctx->ShaderObjects._FragmentShaderPresent) { enableBits = progteximageusage[unit]; - }
+ } else if (ctx->FragmentProgram._Enabled) { enableBits = ctx->FragmentProgram.Current->TexturesUsed[unit]; } @@ -2844,12 +2849,17 @@ update_texture_state( GLcontext *ctx ) /* Look for the highest-priority texture target that's enabled and * complete. That's the one we'll use for texturing. If we're using * a fragment program we're guaranteed that bitcount(enabledBits) <= 1. - */
- texture_override(texUnit->CurrentCubeMap, TEXTURE_CUBE_BIT, ctx, enableBits, texUnit);
- texture_override(texUnit->Current3D, TEXTURE_3D_BIT, ctx, enableBits, texUnit); - texture_override(texUnit->CurrentRect, TEXTURE_RECT_BIT, ctx, enableBits, texUnit);
- texture_override(texUnit->Current2D, TEXTURE_2D_BIT, ctx, enableBits, texUnit); - texture_override(texUnit->Current1D, TEXTURE_1D_BIT, ctx, enableBits, texUnit); + */ + texture_override(ctx, texUnit, enableBits, + texUnit->CurrentCubeMap, TEXTURE_CUBE_BIT); + texture_override(ctx, texUnit, enableBits, + texUnit->Current3D, TEXTURE_3D_BIT); + texture_override(ctx, texUnit, enableBits, + texUnit->CurrentRect, TEXTURE_RECT_BIT); + texture_override(ctx, texUnit, enableBits, + texUnit->Current2D, TEXTURE_2D_BIT); + texture_override(ctx, texUnit, enableBits, + texUnit->Current1D, TEXTURE_1D_BIT); if (!texUnit->_ReallyEnabled) { continue; @@ -2862,13 +2872,14 @@ update_texture_state( GLcontext *ctx ) texUnit->_CurrentCombine = & texUnit->Combine; } else { - GLenum format = texUnit->_Current->Image[0][0]->_BaseFormat; + const struct gl_texture_object *texObj = texUnit->_Current; + GLenum format = texObj->Image[0][texObj->BaseLevel]->_BaseFormat; if (format == GL_COLOR_INDEX) { format = GL_RGBA; /* a bit of a hack */ } else if (format == GL_DEPTH_COMPONENT || format == GL_DEPTH_STENCIL_EXT) { - format = texUnit->_Current->DepthMode; + format = texObj->DepthMode; } calculate_derived_texenv(&texUnit->_EnvMode, texUnit->EnvMode, format); texUnit->_CurrentCombine = & texUnit->_EnvMode; @@ -2947,9 +2958,9 @@ update_texture_state( GLcontext *ctx ) ctx->Texture._EnabledCoordUnits = ctx->Texture._EnabledUnits; /* Fragment programs may need texture coordinates but not the * corresponding texture images. - */
- if (ctx->ShaderObjects.CurrentProgram != NULL) {
- ctx->Texture._EnabledCoordUnits |= (1 << ctx->Const.MaxTextureCoordUnits) - 1;
+ */ + if (ctx->ShaderObjects.CurrentProgram != NULL) { + ctx->Texture._EnabledCoordUnits |= (1 << ctx->Const.MaxTextureCoordUnits) - 1; } else if (ctx->FragmentProgram._Enabled) { ctx->Texture._EnabledCoordUnits |= |