summaryrefslogtreecommitdiff
path: root/src/mesa
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2008-08-18 08:49:41 -0600
committerBrian Paul <brian.paul@tungstengraphics.com>2008-08-18 08:56:17 -0600
commit087ee474ed1dcf9b09c13227d442e6580f828f57 (patch)
tree437959427053c06d9ba8b25c7cd2cb80eb963e75 /src/mesa
parent6fdc057887bd5e1e5f5ae2781529df050b3a31c6 (diff)
mesa: rearrange some code in _mesa_BindTexture() to fix error detection bug 17173
Also, move GL_TEXTURE_RECTANGLE init code into separate function.
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/main/texobj.c101
1 files changed, 59 insertions, 42 deletions
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index c163a8158f..2a54ff7ff9 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -142,6 +142,34 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
/**
+ * Some texture initialization can't be finished until we know which
+ * target it's getting bound to (GL_TEXTURE_1D/2D/etc).
+ */
+static void
+finish_texture_init(GLcontext *ctx, GLenum target,
+ struct gl_texture_object *obj)
+{
+ assert(obj->Target == 0);
+
+ if (target == GL_TEXTURE_RECTANGLE_NV) {
+ /* have to init wrap and filter state here - kind of klunky */
+ obj->WrapS = GL_CLAMP_TO_EDGE;
+ obj->WrapT = GL_CLAMP_TO_EDGE;
+ obj->WrapR = GL_CLAMP_TO_EDGE;
+ obj->MinFilter = GL_LINEAR;
+ if (ctx->Driver.TexParameter) {
+ static const GLfloat fparam_wrap[1] = {(GLfloat) GL_CLAMP_TO_EDGE};
+ static const GLfloat fparam_filter[1] = {(GLfloat) GL_LINEAR};
+ ctx->Driver.TexParameter(ctx, target, obj, GL_TEXTURE_WRAP_S, fparam_wrap);
+ ctx->Driver.TexParameter(ctx, target, obj, GL_TEXTURE_WRAP_T, fparam_wrap);
+ ctx->Driver.TexParameter(ctx, target, obj, GL_TEXTURE_WRAP_R, fparam_wrap);
+ ctx->Driver.TexParameter(ctx, target, obj, GL_TEXTURE_MIN_FILTER, fparam_filter);
+ }
+ }
+}
+
+
+/**
* Deallocate a texture object struct. It should have already been
* removed from the texture object pool.
* Called via ctx->Driver.DeleteTexture() if not overriden by a driver.
@@ -830,44 +858,45 @@ _mesa_BindTexture( GLenum target, GLuint texName )
GET_CURRENT_CONTEXT(ctx);
const GLuint unit = ctx->Texture.CurrentUnit;
struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
- struct gl_texture_object *newTexObj = NULL;
+ struct gl_texture_object *newTexObj = NULL, *defaultTexObj = NULL;
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->Default1D;
+ break;
+ case GL_TEXTURE_2D:
+ defaultTexObj = ctx->Shared->Default2D;
+ break;
+ case GL_TEXTURE_3D:
+ defaultTexObj = ctx->Shared->Default3D;
+ break;
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ defaultTexObj = ctx->Shared->DefaultCubeMap;
+ break;
+ case GL_TEXTURE_RECTANGLE_NV:
+ defaultTexObj = ctx->Shared->DefaultRect;
+ break;
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ defaultTexObj = ctx->Shared->Default1DArray;
+ break;
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ defaultTexObj = ctx->Shared->Default2DArray;
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindTexture(target)");
+ return;
+ }
+
/*
* Get pointer to new texture object (newTexObj)
*/
if (texName == 0) {
- /* newTexObj = a default texture object */
- switch (target) {
- case GL_TEXTURE_1D:
- newTexObj = ctx->Shared->Default1D;
- break;
- case GL_TEXTURE_2D:
- newTexObj = ctx->Shared->Default2D;
- break;
- case GL_TEXTURE_3D:
- newTexObj = ctx->Shared->Default3D;
- break;
- case GL_TEXTURE_CUBE_MAP_ARB:
- newTexObj = ctx->Shared->DefaultCubeMap;
- break;
- case GL_TEXTURE_RECTANGLE_NV:
- newTexObj = ctx->Shared->DefaultRect;
- break;
- case GL_TEXTURE_1D_ARRAY_EXT:
- newTexObj = ctx->Shared->Default1DArray;
- break;
- case GL_TEXTURE_2D_ARRAY_EXT:
- newTexObj = ctx->Shared->Default2DArray;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glBindTexture(target)");
- return;
- }
+ newTexObj = defaultTexObj;
}
else {
/* non-default texture object */
@@ -880,20 +909,8 @@ _mesa_BindTexture( GLenum target, GLuint texName )
"glBindTexture(target mismatch)" );
return;
}
- if (newTexObj->Target == 0 && target == GL_TEXTURE_RECTANGLE_NV) {
- /* have to init wrap and filter state here - kind of klunky */
- newTexObj->WrapS = GL_CLAMP_TO_EDGE;
- newTexObj->WrapT = GL_CLAMP_TO_EDGE;
- newTexObj->WrapR = GL_CLAMP_TO_EDGE;
- newTexObj->MinFilter = GL_LINEAR;
- if (ctx->Driver.TexParameter) {
- static const GLfloat fparam_wrap[1] = {(GLfloat) GL_CLAMP_TO_EDGE};
- static const GLfloat fparam_filter[1] = {(GLfloat) GL_LINEAR};
- (*ctx->Driver.TexParameter)( ctx, target, newTexObj, GL_TEXTURE_WRAP_S, fparam_wrap );
- (*ctx->Driver.TexParameter)( ctx, target, newTexObj, GL_TEXTURE_WRAP_T, fparam_wrap );
- (*ctx->Driver.TexParameter)( ctx, target, newTexObj, GL_TEXTURE_WRAP_R, fparam_wrap );
- (*ctx->Driver.TexParameter)( ctx, target, newTexObj, GL_TEXTURE_MIN_FILTER, fparam_filter );
- }
+ if (newTexObj->Target == 0) {
+ finish_texture_init(ctx, target, newTexObj);
}
}
else {