diff options
author | Brian <[email protected]> | 2007-08-16 10:28:23 +0100 |
---|---|---|
committer | Brian <[email protected]> | 2007-08-16 10:28:23 +0100 |
commit | 0135ff512d25b221d1a4cf9a5d344420d4ad3341 (patch) | |
tree | cee2a69e68333c57920fba0b69887a9f587bb9f3 /src/mesa/main/attrib.c | |
parent | b3e3e72e25247a48c4f154e2971eff48ecb9d9ef (diff) |
replace separate 1D/2D/etc fields with an array indexed by texture target
Diffstat (limited to 'src/mesa/main/attrib.c')
-rw-r--r-- | src/mesa/main/attrib.c | 128 |
1 files changed, 46 insertions, 82 deletions
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c index 52e3f22adcf..3199c9b426b 100644 --- a/src/mesa/main/attrib.c +++ b/src/mesa/main/attrib.c @@ -59,25 +59,13 @@ struct texture_state struct gl_texture_attrib Texture; /**< The usual context state */ /** to save per texture object state (wrap modes, filters, etc): */ - struct gl_texture_object Saved1D[MAX_TEXTURE_UNITS]; - struct gl_texture_object Saved2D[MAX_TEXTURE_UNITS]; - struct gl_texture_object Saved3D[MAX_TEXTURE_UNITS]; - struct gl_texture_object SavedCube[MAX_TEXTURE_UNITS]; - struct gl_texture_object SavedRect[MAX_TEXTURE_UNITS]; - struct gl_texture_object Saved1DArray[MAX_TEXTURE_UNITS]; - struct gl_texture_object Saved2DArray[MAX_TEXTURE_UNITS]; + struct gl_texture_object SavedObj[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS]; /** * To save references to texture objects (so they don't get accidentally * deleted while saved in the attribute stack). */ - struct gl_texture_object *SavedRef1D[MAX_TEXTURE_UNITS]; - struct gl_texture_object *SavedRef2D[MAX_TEXTURE_UNITS]; - struct gl_texture_object *SavedRef3D[MAX_TEXTURE_UNITS]; - struct gl_texture_object *SavedRefCube[MAX_TEXTURE_UNITS]; - struct gl_texture_object *SavedRefRect[MAX_TEXTURE_UNITS]; - struct gl_texture_object *SavedRef1DArray[MAX_TEXTURE_UNITS]; - struct gl_texture_object *SavedRef2DArray[MAX_TEXTURE_UNITS]; + struct gl_texture_object *SavedTexRef[MAX_TEXTURE_UNITS][NUM_TEXTURE_TARGETS]; }; @@ -386,30 +374,37 @@ _mesa_PushAttrib(GLbitfield mask) * accidentally get deleted while referenced in the attribute stack. */ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { - _mesa_reference_texobj(&texstate->SavedRef1D[u], ctx->Texture.Unit[u].Current1D); - _mesa_reference_texobj(&texstate->SavedRef2D[u], ctx->Texture.Unit[u].Current2D); - _mesa_reference_texobj(&texstate->SavedRef3D[u], ctx->Texture.Unit[u].Current3D); - _mesa_reference_texobj(&texstate->SavedRefCube[u], ctx->Texture.Unit[u].CurrentCubeMap); - _mesa_reference_texobj(&texstate->SavedRefRect[u], ctx->Texture.Unit[u].CurrentRect); - _mesa_reference_texobj(&texstate->SavedRef1DArray[u], ctx->Texture.Unit[u].Current1DArray); - _mesa_reference_texobj(&texstate->SavedRef2DArray[u], ctx->Texture.Unit[u].Current2DArray); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_1D_INDEX], + ctx->Texture.Unit[u].Current1D); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_2D_INDEX], + ctx->Texture.Unit[u].Current2D); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_3D_INDEX], + ctx->Texture.Unit[u].Current3D); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_CUBE_INDEX], + ctx->Texture.Unit[u].CurrentCubeMap); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_RECT_INDEX], + ctx->Texture.Unit[u].CurrentRect); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_1D_ARRAY_INDEX], + ctx->Texture.Unit[u].Current1DArray); + _mesa_reference_texobj(&texstate->SavedTexRef[u][TEXTURE_2D_ARRAY_INDEX], + ctx->Texture.Unit[u].Current2DArray); } /* copy state/contents of the currently bound texture objects */ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { - _mesa_copy_texture_object(&texstate->Saved1D[u], + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_1D_INDEX], ctx->Texture.Unit[u].Current1D); - _mesa_copy_texture_object(&texstate->Saved2D[u], + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_2D_INDEX], ctx->Texture.Unit[u].Current2D); - _mesa_copy_texture_object(&texstate->Saved3D[u], + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_3D_INDEX], ctx->Texture.Unit[u].Current3D); - _mesa_copy_texture_object(&texstate->SavedCube[u], + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_CUBE_INDEX], ctx->Texture.Unit[u].CurrentCubeMap); - _mesa_copy_texture_object(&texstate->SavedRect[u], + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_RECT_INDEX], ctx->Texture.Unit[u].CurrentRect); - _mesa_copy_texture_object(&texstate->Saved1DArray[u], + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_1D_ARRAY_INDEX], ctx->Texture.Unit[u].Current1DArray); - _mesa_copy_texture_object(&texstate->Saved2DArray[u], + _mesa_copy_texture_object(&texstate->SavedObj[u][TEXTURE_2D_ARRAY_INDEX], ctx->Texture.Unit[u].Current2DArray); } @@ -773,45 +768,22 @@ pop_texture_group(GLcontext *ctx, struct texture_state *texstate) GLfloat bordColor[4]; GLenum target; - switch (tgt) { - case TEXTURE_1D_INDEX: - obj = &texstate->Saved1D[u]; - ASSERT(obj->Target == GL_TEXTURE_1D); - break; - case TEXTURE_2D_INDEX: - obj = &texstate->Saved2D[u]; - ASSERT(obj->Target == GL_TEXTURE_2D); - break; - case TEXTURE_3D_INDEX: - obj = &texstate->Saved3D[u]; - ASSERT(obj->Target == GL_TEXTURE_3D); - break; - case TEXTURE_CUBE_INDEX: - if (!ctx->Extensions.ARB_texture_cube_map) - continue; - obj = &texstate->SavedCube[u]; - ASSERT(obj->Target == GL_TEXTURE_CUBE_MAP_ARB); - break; - case TEXTURE_RECT_INDEX: - if (!ctx->Extensions.NV_texture_rectangle) - continue; - obj = &texstate->SavedRect[u]; - ASSERT(obj->Target == GL_TEXTURE_RECTANGLE_NV); - break; - case TEXTURE_1D_ARRAY_INDEX: - if (!ctx->Extensions.MESA_texture_array) - continue; - obj = &texstate->Saved1DArray[u]; - ASSERT(obj->Target == GL_TEXTURE_1D_ARRAY_EXT); - break; - case TEXTURE_2D_ARRAY_INDEX: - if (!ctx->Extensions.MESA_texture_array) - continue; - obj = &texstate->Saved2DArray[u]; - ASSERT(obj->Target == GL_TEXTURE_2D_ARRAY_EXT); - break; - default: - _mesa_problem(ctx, "bad texture index in pop_texture_group"); + obj = &texstate->SavedObj[u][tgt]; + + /* don't restore state for unsupported targets to prevent + * raising GL errors. + */ + if (obj->Target == GL_TEXTURE_CUBE_MAP_ARB && + !ctx->Extensions.ARB_texture_cube_map) { + continue; + } + else if (obj->Target == GL_TEXTURE_RECTANGLE_NV && + !ctx->Extensions.NV_texture_rectangle) { + continue; + } + else if ((obj->Target == GL_TEXTURE_1D_ARRAY_EXT || + obj->Target == GL_TEXTURE_2D_ARRAY_EXT) && + !ctx->Extensions.MESA_texture_array) { continue; } @@ -854,13 +826,9 @@ pop_texture_group(GLcontext *ctx, struct texture_state *texstate) } /* remove saved references to the texture objects */ - _mesa_reference_texobj(&texstate->SavedRef1D[u], NULL); - _mesa_reference_texobj(&texstate->SavedRef2D[u], NULL); - _mesa_reference_texobj(&texstate->SavedRef3D[u], NULL); - _mesa_reference_texobj(&texstate->SavedRefCube[u], NULL); - _mesa_reference_texobj(&texstate->SavedRefRect[u], NULL); - _mesa_reference_texobj(&texstate->SavedRef1DArray[u], NULL); - _mesa_reference_texobj(&texstate->SavedRef2DArray[u], NULL); + for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { + _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL); + } } _mesa_ActiveTextureARB(GL_TEXTURE0_ARB + texstate->Texture.CurrentUnit); @@ -1483,16 +1451,12 @@ _mesa_free_attrib_data(GLcontext *ctx) while (attr) { if (attr->kind == GL_TEXTURE_BIT) { struct texture_state *texstate = (struct texture_state*)attr->data; - GLuint u; + GLuint u, tgt; /* clear references to the saved texture objects */ for (u = 0; u < ctx->Const.MaxTextureUnits; u++) { - _mesa_reference_texobj(&texstate->SavedRef1D[u], NULL); - _mesa_reference_texobj(&texstate->SavedRef2D[u], NULL); - _mesa_reference_texobj(&texstate->SavedRef3D[u], NULL); - _mesa_reference_texobj(&texstate->SavedRefCube[u], NULL); - _mesa_reference_texobj(&texstate->SavedRefRect[u], NULL); - _mesa_reference_texobj(&texstate->SavedRef1DArray[u], NULL); - _mesa_reference_texobj(&texstate->SavedRef2DArray[u], NULL); + for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) { + _mesa_reference_texobj(&texstate->SavedTexRef[u][tgt], NULL); + } } } else { |