summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/texobj.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2009-02-21 14:53:25 -0700
committerBrian Paul <[email protected]>2009-02-21 14:53:25 -0700
commit9818734e0148510967ca9ee0d1aa8b196b509f02 (patch)
tree28f32aeadff161ca159674699151063c4728d1bc /src/mesa/main/texobj.c
parent4d24b639d160fe485a3e8f7395e7654538be29e0 (diff)
mesa: use an array for current texture objects
Use loops to consolidate lots of texture object code.
Diffstat (limited to 'src/mesa/main/texobj.c')
-rw-r--r--src/mesa/main/texobj.c136
1 files changed, 44 insertions, 92 deletions
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 52a651c4b69..2de2dcc95da 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -759,44 +759,17 @@ unbind_texobj_from_fbo(GLcontext *ctx, struct gl_texture_object *texObj)
static void
unbind_texobj_from_texunits(GLcontext *ctx, struct gl_texture_object *texObj)
{
- GLuint u;
+ GLuint u, tex;
for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) {
struct gl_texture_unit *unit = &ctx->Texture.Unit[u];
- if (texObj == unit->Current1D) {
- _mesa_reference_texobj(&unit->Current1D,
- ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]);
- ASSERT(unit->Current1D);
- }
- else if (texObj == unit->Current2D) {
- _mesa_reference_texobj(&unit->Current2D,
- ctx->Shared->DefaultTex[TEXTURE_2D_INDEX]);
- ASSERT(unit->Current2D);
- }
- else if (texObj == unit->Current3D) {
- _mesa_reference_texobj(&unit->Current3D,
- ctx->Shared->DefaultTex[TEXTURE_3D_INDEX]);
- ASSERT(unit->Current3D);
- }
- else if (texObj == unit->CurrentCubeMap) {
- _mesa_reference_texobj(&unit->CurrentCubeMap,
- ctx->Shared->DefaultTex[TEXTURE_CUBE_INDEX]);
- ASSERT(unit->CurrentCubeMap);
- }
- else if (texObj == unit->CurrentRect) {
- _mesa_reference_texobj(&unit->CurrentRect,
- ctx->Shared->DefaultTex[TEXTURE_RECT_INDEX]);
- ASSERT(unit->CurrentRect);
- }
- else if (texObj == unit->Current1DArray) {
- _mesa_reference_texobj(&unit->Current1DArray,
- ctx->Shared->DefaultTex[TEXTURE_1D_ARRAY_INDEX]);
- ASSERT(unit->Current1DArray);
- }
- else if (texObj == unit->Current2DArray) {
- _mesa_reference_texobj(&unit->Current2DArray,
- ctx->Shared->DefaultTex[TEXTURE_2D_ARRAY_INDEX]);
- ASSERT(unit->Current2DArray);
+ for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
+ if (texObj == unit->CurrentTex[tex]) {
+ _mesa_reference_texobj(&unit->CurrentTex[tex],
+ ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]);
+ ASSERT(unit->CurrentTex[tex]);
+ break;
+ }
}
}
}
@@ -867,6 +840,35 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures)
/**
+ * Convert a GL texture target enum such as GL_TEXTURE_2D or GL_TEXTURE_3D
+ * into the corresponding Mesa texture target index.
+ * Return -1 if target is invalid.
+ */
+static GLint
+target_enum_to_index(GLenum target)
+{
+ switch (target) {
+ case GL_TEXTURE_1D:
+ return TEXTURE_1D_INDEX;
+ case GL_TEXTURE_2D:
+ return TEXTURE_2D_INDEX;
+ case GL_TEXTURE_3D:
+ return TEXTURE_3D_INDEX;
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ return TEXTURE_CUBE_INDEX;
+ case GL_TEXTURE_RECTANGLE_NV:
+ return TEXTURE_RECT_INDEX;
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ return TEXTURE_1D_ARRAY_INDEX;
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ return TEXTURE_2D_ARRAY_INDEX;
+ default:
+ return -1;
+ }
+}
+
+
+/**
* Bind a named texture to a texturing target.
*
* \param target texture target.
@@ -888,38 +890,20 @@ _mesa_BindTexture( GLenum target, GLuint texName )
const GLuint unit = ctx->Texture.CurrentUnit;
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
struct gl_texture_object *newTexObj = NULL, *defaultTexObj = NULL;
+ GLint targetIndex;
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
_mesa_debug(ctx, "glBindTexture %s %d\n",
_mesa_lookup_enum_by_nr(target), (GLint) texName);
- switch (target) {
- case GL_TEXTURE_1D:
- defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_1D_INDEX];
- break;
- case GL_TEXTURE_2D:
- defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_2D_INDEX];
- break;
- case GL_TEXTURE_3D:
- defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_3D_INDEX];
- break;
- case GL_TEXTURE_CUBE_MAP_ARB:
- defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_CUBE_INDEX];
- break;
- case GL_TEXTURE_RECTANGLE_NV:
- defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_RECT_INDEX];
- break;
- case GL_TEXTURE_1D_ARRAY_EXT:
- defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_1D_ARRAY_INDEX];
- break;
- case GL_TEXTURE_2D_ARRAY_EXT:
- defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_2D_ARRAY_INDEX];
- break;
- default:
+ targetIndex = target_enum_to_index(target);
+ if (targetIndex < 0) {
_mesa_error(ctx, GL_INVALID_ENUM, "glBindTexture(target)");
return;
}
+ assert(targetIndex < NUM_TEXTURE_TARGETS);
+ defaultTexObj = ctx->Shared->DefaultTex[targetIndex];
/*
* Get pointer to new texture object (newTexObj)
@@ -967,40 +951,8 @@ _mesa_BindTexture( GLenum target, GLuint texName )
* texture object will be decremented. It'll be deleted if the
* count hits zero.
*/
- switch (target) {
- case GL_TEXTURE_1D:
- _mesa_reference_texobj(&texUnit->Current1D, newTexObj);
- ASSERT(texUnit->Current1D);
- break;
- case GL_TEXTURE_2D:
- _mesa_reference_texobj(&texUnit->Current2D, newTexObj);
- ASSERT(texUnit->Current2D);
- break;
- case GL_TEXTURE_3D:
- _mesa_reference_texobj(&texUnit->Current3D, newTexObj);
- ASSERT(texUnit->Current3D);
- break;
- case GL_TEXTURE_CUBE_MAP_ARB:
- _mesa_reference_texobj(&texUnit->CurrentCubeMap, newTexObj);
- ASSERT(texUnit->CurrentCubeMap);
- break;
- case GL_TEXTURE_RECTANGLE_NV:
- _mesa_reference_texobj(&texUnit->CurrentRect, newTexObj);
- ASSERT(texUnit->CurrentRect);
- break;
- case GL_TEXTURE_1D_ARRAY_EXT:
- _mesa_reference_texobj(&texUnit->Current1DArray, newTexObj);
- ASSERT(texUnit->Current1DArray);
- break;
- case GL_TEXTURE_2D_ARRAY_EXT:
- _mesa_reference_texobj(&texUnit->Current2DArray, newTexObj);
- ASSERT(texUnit->Current2DArray);
- break;
- default:
- /* Bad target should be caught above */
- _mesa_problem(ctx, "bad target in BindTexture");
- return;
- }
+ _mesa_reference_texobj(&texUnit->CurrentTex[targetIndex], newTexObj);
+ ASSERT(texUnit->CurrentTex[targetIndex]);
/* Pass BindTexture call to device driver */
if (ctx->Driver.BindTexture)