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...
This commit is contained in:
parent
9705cff203
commit
4d24b639d1
|
@ -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);
|
||||
|
|
|
@ -2198,18 +2198,8 @@ struct gl_shared_state
|
|||
struct _mesa_HashTable *DisplayList; /**< Display lists hash table */
|
||||
struct _mesa_HashTable *TexObjects; /**< Texture objects hash table */
|
||||
|
||||
/**
|
||||
* \name Default texture objects (shared by all multi-texture units)
|
||||
*/
|
||||
/*@{*/
|
||||
struct gl_texture_object *Default1D;
|
||||
struct gl_texture_object *Default2D;
|
||||
struct gl_texture_object *Default3D;
|
||||
struct gl_texture_object *DefaultCubeMap;
|
||||
struct gl_texture_object *DefaultRect;
|
||||
struct gl_texture_object *Default1DArray;
|
||||
struct gl_texture_object *Default2DArray;
|
||||
/*@}*/
|
||||
/** Default texture objects (shared by all texture units) */
|
||||
struct gl_texture_object *DefaultTex[NUM_TEXTURE_TARGETS];
|
||||
|
||||
/**
|
||||
* \name Thread safety and statechange notification for texture
|
||||
|
|
|
@ -764,31 +764,38 @@ unbind_texobj_from_texunits(GLcontext *ctx, struct gl_texture_object *texObj)
|
|||
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->Default1D);
|
||||
_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->Default2D);
|
||||
_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->Default3D);
|
||||
_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->DefaultCubeMap);
|
||||
_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->DefaultRect);
|
||||
_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->Default1DArray);
|
||||
_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->Default2DArray);
|
||||
_mesa_reference_texobj(&unit->Current2DArray,
|
||||
ctx->Shared->DefaultTex[TEXTURE_2D_ARRAY_INDEX]);
|
||||
ASSERT(unit->Current2DArray);
|
||||
}
|
||||
}
|
||||
|
@ -889,25 +896,25 @@ _mesa_BindTexture( GLenum target, GLuint texName )
|
|||
|
||||
switch (target) {
|
||||
case GL_TEXTURE_1D:
|
||||
defaultTexObj = ctx->Shared->Default1D;
|
||||
defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_1D_INDEX];
|
||||
break;
|
||||
case GL_TEXTURE_2D:
|
||||
defaultTexObj = ctx->Shared->Default2D;
|
||||
defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_2D_INDEX];
|
||||
break;
|
||||
case GL_TEXTURE_3D:
|
||||
defaultTexObj = ctx->Shared->Default3D;
|
||||
defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_3D_INDEX];
|
||||
break;
|
||||
case GL_TEXTURE_CUBE_MAP_ARB:
|
||||
defaultTexObj = ctx->Shared->DefaultCubeMap;
|
||||
defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_CUBE_INDEX];
|
||||
break;
|
||||
case GL_TEXTURE_RECTANGLE_NV:
|
||||
defaultTexObj = ctx->Shared->DefaultRect;
|
||||
defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_RECT_INDEX];
|
||||
break;
|
||||
case GL_TEXTURE_1D_ARRAY_EXT:
|
||||
defaultTexObj = ctx->Shared->Default1DArray;
|
||||
defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_1D_ARRAY_INDEX];
|
||||
break;
|
||||
case GL_TEXTURE_2D_ARRAY_EXT:
|
||||
defaultTexObj = ctx->Shared->Default2DArray;
|
||||
defaultTexObj = ctx->Shared->DefaultTex[TEXTURE_2D_ARRAY_INDEX];
|
||||
break;
|
||||
default:
|
||||
_mesa_error(ctx, GL_INVALID_ENUM, "glBindTexture(target)");
|
||||
|
|
|
@ -763,13 +763,13 @@ init_texture_unit( GLcontext *ctx, GLuint unit )
|
|||
ASSIGN_4V( texUnit->GenQ.EyePlane, 0.0, 0.0, 0.0, 0.0 );
|
||||
|
||||
/* initialize current texture object ptrs to the shared default objects */
|
||||
_mesa_reference_texobj(&texUnit->Current1D, ctx->Shared->Default1D);
|
||||
_mesa_reference_texobj(&texUnit->Current2D, ctx->Shared->Default2D);
|
||||
_mesa_reference_texobj(&texUnit->Current3D, ctx->Shared->Default3D);
|
||||
_mesa_reference_texobj(&texUnit->CurrentCubeMap, ctx->Shared->DefaultCubeMap);
|
||||
_mesa_reference_texobj(&texUnit->CurrentRect, ctx->Shared->DefaultRect);
|
||||
_mesa_reference_texobj(&texUnit->Current1DArray, ctx->Shared->Default1DArray);
|
||||
_mesa_reference_texobj(&texUnit->Current2DArray, ctx->Shared->Default2DArray);
|
||||
_mesa_reference_texobj(&texUnit->Current1D, ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->Current2D, ctx->Shared->DefaultTex[TEXTURE_2D_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->Current3D, ctx->Shared->DefaultTex[TEXTURE_3D_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->CurrentCubeMap, ctx->Shared->DefaultTex[TEXTURE_CUBE_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->CurrentRect, ctx->Shared->DefaultTex[TEXTURE_RECT_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->Current1DArray, ctx->Shared->DefaultTex[TEXTURE_1D_ARRAY_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->Current2DArray, ctx->Shared->DefaultTex[TEXTURE_2D_ARRAY_INDEX]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -798,7 +798,8 @@ _mesa_init_texture(GLcontext *ctx)
|
|||
/* After we're done initializing the context's texture state the default
|
||||
* texture objects' refcounts should be at least MAX_TEXTURE_UNITS + 1.
|
||||
*/
|
||||
assert(ctx->Shared->Default1D->RefCount >= MAX_TEXTURE_UNITS + 1);
|
||||
assert(ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]->RefCount
|
||||
>= MAX_TEXTURE_UNITS + 1);
|
||||
|
||||
/* Allocate proxy textures */
|
||||
if (!alloc_proxy_textures( ctx ))
|
||||
|
@ -855,12 +856,19 @@ _mesa_update_default_objects_texture(GLcontext *ctx)
|
|||
for (i = 0; i < MAX_TEXTURE_UNITS; i++) {
|
||||
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[i];
|
||||
|
||||
_mesa_reference_texobj(&texUnit->Current1D, ctx->Shared->Default1D);
|
||||
_mesa_reference_texobj(&texUnit->Current2D, ctx->Shared->Default2D);
|
||||
_mesa_reference_texobj(&texUnit->Current3D, ctx->Shared->Default3D);
|
||||
_mesa_reference_texobj(&texUnit->CurrentCubeMap, ctx->Shared->DefaultCubeMap);
|
||||
_mesa_reference_texobj(&texUnit->CurrentRect, ctx->Shared->DefaultRect);
|
||||
_mesa_reference_texobj(&texUnit->Current1DArray, ctx->Shared->Default1DArray);
|
||||
_mesa_reference_texobj(&texUnit->Current2DArray, ctx->Shared->Default2DArray);
|
||||
_mesa_reference_texobj(&texUnit->Current1D,
|
||||
ctx->Shared->DefaultTex[TEXTURE_1D_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->Current2D,
|
||||
ctx->Shared->DefaultTex[TEXTURE_2D_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->Current3D,
|
||||
ctx->Shared->DefaultTex[TEXTURE_3D_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->CurrentCubeMap,
|
||||
ctx->Shared->DefaultTex[TEXTURE_CUBE_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->CurrentRect,
|
||||
ctx->Shared->DefaultTex[TEXTURE_RECT_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->Current1DArray,
|
||||
ctx->Shared->DefaultTex[TEXTURE_1D_ARRAY_INDEX]);
|
||||
_mesa_reference_texobj(&texUnit->Current2DArray,
|
||||
ctx->Shared->DefaultTex[TEXTURE_2D_ARRAY_INDEX]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue