summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/context.c
diff options
context:
space:
mode:
authorBrian Paul <[email protected]>2009-02-21 13:59:29 -0700
committerBrian Paul <[email protected]>2009-02-21 13:59:29 -0700
commit4d24b639d160fe485a3e8f7395e7654538be29e0 (patch)
tree189413bbaf62937bdcf8ca65c80bb0fb559d43ed /src/mesa/main/context.c
parent9705cff2033f1771a39ac3bb78eb5fcea522218a (diff)
mesa: use an array for default texture objects
Replace Default1D/2D/3D/Cube/etc with DefaultTex[TEXTURE_x_INDEX]. The same should be done with the Current1D/2D/3D/etc pointers...
Diffstat (limited to 'src/mesa/main/context.c')
-rw-r--r--src/mesa/main/context.c75
1 files changed, 26 insertions, 49 deletions
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 9705fd8a988..04848794aa2 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -423,6 +423,7 @@ one_time_init( GLcontext *ctx )
static GLboolean
alloc_shared_state( GLcontext *ctx )
{
+ GLuint i;
struct gl_shared_state *ss = CALLOC_STRUCT(gl_shared_state);
if (!ss)
return GL_FALSE;
@@ -464,36 +465,24 @@ alloc_shared_state( GLcontext *ctx )
ss->ShaderObjects = _mesa_NewHashTable();
#endif
- ss->Default1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
- if (!ss->Default1D)
- goto cleanup;
-
- ss->Default2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
- if (!ss->Default2D)
- goto cleanup;
-
- ss->Default3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
- if (!ss->Default3D)
- goto cleanup;
-
- ss->DefaultCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
- if (!ss->DefaultCubeMap)
- goto cleanup;
-
- ss->DefaultRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
- if (!ss->DefaultRect)
- goto cleanup;
-
- ss->Default1DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D_ARRAY_EXT);
- if (!ss->Default1DArray)
- goto cleanup;
-
- ss->Default2DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D_ARRAY_EXT);
- if (!ss->Default2DArray)
- goto cleanup;
+ /* Create default texture objects */
+ for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
+ static const GLenum targets[NUM_TEXTURE_TARGETS] = {
+ GL_TEXTURE_1D,
+ GL_TEXTURE_2D,
+ GL_TEXTURE_3D,
+ GL_TEXTURE_CUBE_MAP,
+ GL_TEXTURE_RECTANGLE_NV,
+ GL_TEXTURE_1D_ARRAY_EXT,
+ GL_TEXTURE_2D_ARRAY_EXT
+ };
+ ss->DefaultTex[i] = ctx->Driver.NewTextureObject(ctx, 0, targets[i]);
+ if (!ss->DefaultTex[i])
+ goto cleanup;
+ }
/* sanity check */
- assert(ss->Default1D->RefCount == 1);
+ assert(ss->DefaultTex[TEXTURE_1D_INDEX]->RefCount == 1);
_glthread_INIT_MUTEX(ss->TexMutex);
ss->TextureStateStamp = 0;
@@ -547,20 +536,10 @@ cleanup:
_mesa_DeleteHashTable(ss->RenderBuffers);
#endif
- if (ss->Default1D)
- (*ctx->Driver.DeleteTexture)(ctx, ss->Default1D);
- if (ss->Default2D)
- (*ctx->Driver.DeleteTexture)(ctx, ss->Default2D);
- if (ss->Default3D)
- (*ctx->Driver.DeleteTexture)(ctx, ss->Default3D);
- if (ss->DefaultCubeMap)
- (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultCubeMap);
- if (ss->DefaultRect)
- (*ctx->Driver.DeleteTexture)(ctx, ss->DefaultRect);
- if (ss->Default1DArray)
- (*ctx->Driver.DeleteTexture)(ctx, ss->Default1DArray);
- if (ss->Default2DArray)
- (*ctx->Driver.DeleteTexture)(ctx, ss->Default2DArray);
+ for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
+ if (ss->DefaultTex[i])
+ ctx->Driver.DeleteTexture(ctx, ss->DefaultTex[i]);
+ }
_mesa_free(ss);
@@ -723,6 +702,8 @@ delete_renderbuffer_cb(GLuint id, void *data, void *userData)
static void
free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
{
+ GLuint i;
+
/*
* Free display lists
*/
@@ -772,13 +753,9 @@ free_shared_state( GLcontext *ctx, struct gl_shared_state *ss )
*/
ASSERT(ctx->Driver.DeleteTexture);
/* the default textures */
- ctx->Driver.DeleteTexture(ctx, ss->Default1D);
- ctx->Driver.DeleteTexture(ctx, ss->Default2D);
- ctx->Driver.DeleteTexture(ctx, ss->Default3D);
- ctx->Driver.DeleteTexture(ctx, ss->DefaultCubeMap);
- ctx->Driver.DeleteTexture(ctx, ss->DefaultRect);
- ctx->Driver.DeleteTexture(ctx, ss->Default1DArray);
- ctx->Driver.DeleteTexture(ctx, ss->Default2DArray);
+ for (i = 0; i < NUM_TEXTURE_TARGETS; i++) {
+ ctx->Driver.DeleteTexture(ctx, ss->DefaultTex[i]);
+ }
/* all other textures */
_mesa_HashDeleteAll(ss->TexObjects, delete_texture_cb, ctx);
_mesa_DeleteHashTable(ss->TexObjects);