summaryrefslogtreecommitdiffstats
path: root/src/mesa/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/mesa/main')
-rw-r--r--src/mesa/main/attrib.c1
-rw-r--r--src/mesa/main/colortab.c306
-rw-r--r--src/mesa/main/context.c14
-rw-r--r--src/mesa/main/dd.h2
-rw-r--r--src/mesa/main/execmem.c12
-rw-r--r--src/mesa/main/fbobject.c21
-rw-r--r--src/mesa/main/framebuffer.c13
-rw-r--r--src/mesa/main/mtypes.h5
-rw-r--r--src/mesa/main/shaders.c6
-rw-r--r--src/mesa/main/teximage.c58
-rw-r--r--src/mesa/main/texobj.c253
-rw-r--r--src/mesa/main/texobj.h4
-rw-r--r--src/mesa/main/texstate.c179
13 files changed, 360 insertions, 514 deletions
diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
index 2e6bb76586e..b990369a9e8 100644
--- a/src/mesa/main/attrib.c
+++ b/src/mesa/main/attrib.c
@@ -361,6 +361,7 @@ _mesa_PushAttrib(GLbitfield mask)
ctx->Texture.Unit[u].Current1DArray->RefCount++;
ctx->Texture.Unit[u].Current2DArray->RefCount++;
}
+
attr = MALLOC_STRUCT( gl_texture_attrib );
MEMCPY( attr, &ctx->Texture, sizeof(struct gl_texture_attrib) );
/* copy state of the currently bound texture objects */
diff --git a/src/mesa/main/colortab.c b/src/mesa/main/colortab.c
index 610acba3068..97120398f9b 100644
--- a/src/mesa/main/colortab.c
+++ b/src/mesa/main/colortab.c
@@ -1,6 +1,6 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5.3
+ * Version: 7.1
*
* Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
@@ -30,6 +30,7 @@
#include "image.h"
#include "macros.h"
#include "state.h"
+#include "teximage.h"
/**
@@ -305,49 +306,6 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
switch (target) {
- case GL_TEXTURE_1D:
- texObj = texUnit->Current1D;
- table = &texObj->Palette;
- break;
- case GL_TEXTURE_2D:
- texObj = texUnit->Current2D;
- table = &texObj->Palette;
- break;
- case GL_TEXTURE_3D:
- texObj = texUnit->Current3D;
- table = &texObj->Palette;
- break;
- case GL_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
- return;
- }
- texObj = texUnit->CurrentCubeMap;
- table = &texObj->Palette;
- break;
- case GL_PROXY_TEXTURE_1D:
- texObj = ctx->Texture.Proxy1D;
- table = &texObj->Palette;
- proxy = GL_TRUE;
- break;
- case GL_PROXY_TEXTURE_2D:
- texObj = ctx->Texture.Proxy2D;
- table = &texObj->Palette;
- proxy = GL_TRUE;
- break;
- case GL_PROXY_TEXTURE_3D:
- texObj = ctx->Texture.Proxy3D;
- table = &texObj->Palette;
- proxy = GL_TRUE;
- break;
- case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
- return;
- }
- texObj = ctx->Texture.ProxyCubeMap;
- table = &texObj->Palette;
- break;
case GL_SHARED_TEXTURE_PALETTE_EXT:
table = &ctx->Texture.Palette;
break;
@@ -396,8 +354,19 @@ _mesa_ColorTable( GLenum target, GLenum internalFormat,
proxy = GL_TRUE;
break;
default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
- return;
+ /* try texture targets */
+ {
+ struct gl_texture_object *texobj
+ = _mesa_select_tex_object(ctx, texUnit, target);
+ if (texobj) {
+ table = &texobj->Palette;
+ proxy = _mesa_is_proxy_texture(target);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
+ return;
+ }
+ }
}
assert(table);
@@ -499,26 +468,6 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
switch (target) {
- case GL_TEXTURE_1D:
- texObj = texUnit->Current1D;
- table = &texObj->Palette;
- break;
- case GL_TEXTURE_2D:
- texObj = texUnit->Current2D;
- table = &texObj->Palette;
- break;
- case GL_TEXTURE_3D:
- texObj = texUnit->Current3D;
- table = &texObj->Palette;
- break;
- case GL_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
- return;
- }
- texObj = texUnit->CurrentCubeMap;
- table = &texObj->Palette;
- break;
case GL_SHARED_TEXTURE_PALETTE_EXT:
table = &ctx->Texture.Palette;
break;
@@ -547,8 +496,15 @@ _mesa_ColorSubTable( GLenum target, GLsizei start,
bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX];
break;
default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
- return;
+ /* try texture targets */
+ texObj = _mesa_select_tex_object(ctx, texUnit, target);
+ if (texObj && !_mesa_is_proxy_texture(target)) {
+ table = &texObj->Palette;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
+ return;
+ }
}
assert(table);
@@ -636,22 +592,6 @@ _mesa_GetColorTable( GLenum target, GLenum format,
}
switch (target) {
- case GL_TEXTURE_1D:
- table = &texUnit->Current1D->Palette;
- break;
- case GL_TEXTURE_2D:
- table = &texUnit->Current2D->Palette;
- break;
- case GL_TEXTURE_3D:
- table = &texUnit->Current3D->Palette;
- break;
- case GL_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
- return;
- }
- table = &texUnit->CurrentCubeMap->Palette;
- break;
case GL_SHARED_TEXTURE_PALETTE_EXT:
table = &ctx->Texture.Palette;
break;
@@ -672,8 +612,18 @@ _mesa_GetColorTable( GLenum target, GLenum format,
table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX];
break;
default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
- return;
+ /* try texture targets */
+ {
+ struct gl_texture_object *texobj
+ = _mesa_select_tex_object(ctx, texUnit, target);
+ if (texobj && !_mesa_is_proxy_texture(target)) {
+ table = &texobj->Palette;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
+ return;
+ }
+ }
}
ASSERT(table);
@@ -781,65 +731,41 @@ _mesa_GetColorTable( GLenum target, GLenum format,
void GLAPIENTRY
_mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
{
+ GLfloat *scale, *bias;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
switch (target) {
- case GL_COLOR_TABLE_SGI:
- if (pname == GL_COLOR_TABLE_SCALE_SGI) {
- COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION], params);
- }
- else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
- COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION], params);
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
- return;
- }
- break;
- case GL_TEXTURE_COLOR_TABLE_SGI:
- if (!ctx->Extensions.SGI_texture_color_table) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
- return;
- }
- if (pname == GL_COLOR_TABLE_SCALE_SGI) {
- COPY_4V(ctx->Pixel.TextureColorTableScale, params);
- }
- else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
- COPY_4V(ctx->Pixel.TextureColorTableBias, params);
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
- return;
- }
- break;
- case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
- if (pname == GL_COLOR_TABLE_SCALE_SGI) {
- COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION], params);
- }
- else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
- COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION], params);
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
- return;
- }
- break;
- case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
- if (pname == GL_COLOR_TABLE_SCALE_SGI) {
- COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX], params);
- }
- else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
- COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX], params);
- }
- else {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
- return;
- }
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
- return;
+ case GL_COLOR_TABLE_SGI:
+ scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION];
+ bias = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION];
+ break;
+ case GL_TEXTURE_COLOR_TABLE_SGI:
+ scale = ctx->Pixel.TextureColorTableScale;
+ bias = ctx->Pixel.TextureColorTableBias;
+ break;
+ case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
+ scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION];
+ bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION];
+ break;
+ case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
+ scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX];
+ bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX];
+ break;
+ default:
+ _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
+ return;
+ }
+
+ if (pname == GL_COLOR_TABLE_SCALE_SGI) {
+ COPY_4V(scale, params);
+ }
+ else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
+ COPY_4V(bias, params);
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
+ return;
}
ctx->NewState |= _NEW_PIXEL;
@@ -879,40 +805,6 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
ASSERT_OUTSIDE_BEGIN_END(ctx);
switch (target) {
- case GL_TEXTURE_1D:
- table = &texUnit->Current1D->Palette;
- break;
- case GL_TEXTURE_2D:
- table = &texUnit->Current2D->Palette;
- break;
- case GL_TEXTURE_3D:
- table = &texUnit->Current3D->Palette;
- break;
- case GL_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetColorTableParameterfv(target)");
- return;
- }
- table = &texUnit->CurrentCubeMap->Palette;
- break;
- case GL_PROXY_TEXTURE_1D:
- table = &ctx->Texture.Proxy1D->Palette;
- break;
- case GL_PROXY_TEXTURE_2D:
- table = &ctx->Texture.Proxy2D->Palette;
- break;
- case GL_PROXY_TEXTURE_3D:
- table = &ctx->Texture.Proxy3D->Palette;
- break;
- case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetColorTableParameterfv(target)");
- return;
- }
- table = &ctx->Texture.ProxyCubeMap->Palette;
- break;
case GL_SHARED_TEXTURE_PALETTE_EXT:
table = &ctx->Texture.Palette;
break;
@@ -981,8 +873,19 @@ _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX];
break;
default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)");
- return;
+ /* try texture targets */
+ {
+ struct gl_texture_object *texobj
+ = _mesa_select_tex_object(ctx, texUnit, target);
+ if (texobj) {
+ table = &texobj->Palette;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetColorTableParameterfv(target)");
+ return;
+ }
+ }
}
assert(table);
@@ -1029,40 +932,6 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
ASSERT_OUTSIDE_BEGIN_END(ctx);
switch (target) {
- case GL_TEXTURE_1D:
- table = &texUnit->Current1D->Palette;
- break;
- case GL_TEXTURE_2D:
- table = &texUnit->Current2D->Palette;
- break;
- case GL_TEXTURE_3D:
- table = &texUnit->Current3D->Palette;
- break;
- case GL_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetColorTableParameteriv(target)");
- return;
- }
- table = &texUnit->CurrentCubeMap->Palette;
- break;
- case GL_PROXY_TEXTURE_1D:
- table = &ctx->Texture.Proxy1D->Palette;
- break;
- case GL_PROXY_TEXTURE_2D:
- table = &ctx->Texture.Proxy2D->Palette;
- break;
- case GL_PROXY_TEXTURE_3D:
- table = &ctx->Texture.Proxy3D->Palette;
- break;
- case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error(ctx, GL_INVALID_ENUM,
- "glGetColorTableParameteriv(target)");
- return;
- }
- table = &ctx->Texture.ProxyCubeMap->Palette;
- break;
case GL_SHARED_TEXTURE_PALETTE_EXT:
table = &ctx->Texture.Palette;
break;
@@ -1161,8 +1030,19 @@ _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX];
break;
default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)");
- return;
+ /* Try texture targets */
+ {
+ struct gl_texture_object *texobj
+ = _mesa_select_tex_object(ctx, texUnit, target);
+ if (texobj) {
+ table = &texobj->Palette;
+ }
+ else {
+ _mesa_error(ctx, GL_INVALID_ENUM,
+ "glGetColorTableParameteriv(target)");
+ return;
+ }
+ }
}
assert(table);
diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c
index 33f6d2c0d0c..279880cf401 100644
--- a/src/mesa/main/context.c
+++ b/src/mesa/main/context.c
@@ -500,19 +500,12 @@ alloc_shared_state( GLcontext *ctx )
if (!ss->Default2DArray)
goto cleanup;
- /* Effectively bind the default textures to all texture units */
- ss->Default1D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
- ss->Default2D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
- ss->Default3D->RefCount += MAX_TEXTURE_IMAGE_UNITS;
- ss->DefaultCubeMap->RefCount += MAX_TEXTURE_IMAGE_UNITS;
- ss->DefaultRect->RefCount += MAX_TEXTURE_IMAGE_UNITS;
- ss->Default1DArray->RefCount += MAX_TEXTURE_IMAGE_UNITS;
- ss->Default2DArray->RefCount += MAX_TEXTURE_IMAGE_UNITS;
+ /* sanity check */
+ assert(ss->Default1D->RefCount == 1);
_glthread_INIT_MUTEX(ss->TexMutex);
ss->TextureStateStamp = 0;
-
#if FEATURE_EXT_framebuffer_object
ss->FrameBuffers = _mesa_NewHashTable();
if (!ss->FrameBuffers)
@@ -522,10 +515,9 @@ alloc_shared_state( GLcontext *ctx )
goto cleanup;
#endif
-
return GL_TRUE;
- cleanup:
+cleanup:
/* Ran out of memory at some point. Free everything and return NULL */
if (ss->DisplayList)
_mesa_DeleteHashTable(ss->DisplayList);
diff --git a/src/mesa/main/dd.h b/src/mesa/main/dd.h
index a24021c63fd..7fb0a211d7a 100644
--- a/src/mesa/main/dd.h
+++ b/src/mesa/main/dd.h
@@ -870,6 +870,8 @@ struct dd_function_table {
GLsizei *length, GLcharARB *sourceOut);
void (*GetUniformfv)(GLcontext *ctx, GLuint program, GLint location,
GLfloat *params);
+ void (*GetUniformiv)(GLcontext *ctx, GLuint program, GLint location,
+ GLint *params);
GLint (*GetUniformLocation)(GLcontext *ctx, GLuint program,
const GLcharARB *name);
GLboolean (*IsProgram)(GLcontext *ctx, GLuint name);
diff --git a/src/mesa/main/execmem.c b/src/mesa/main/execmem.c
index 40f66d7da2d..aa40b022051 100644
--- a/src/mesa/main/execmem.c
+++ b/src/mesa/main/execmem.c
@@ -36,7 +36,7 @@
-#if defined(__linux__)
+#if defined(__linux__) || defined(__OpenBSD__)
/*
* Allocate a large block of memory which can hold code then dole it out
@@ -47,6 +47,16 @@
#include <sys/mman.h>
#include "mm.h"
+#ifdef MESA_SELINUX
+#include <selinux/selinux.h>
+#endif
+
+
+#ifndef MAP_ANONYMOUS
+#define MAP_ANONYMOUS MAP_ANON
+#endif
+
+
#define EXEC_HEAP_SIZE (10*1024*1024)
_glthread_DECLARE_STATIC_MUTEX(exec_mutex);
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index e4ff575e18e..0ae69bdce7a 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -172,22 +172,17 @@ _mesa_remove_attachment(GLcontext *ctx, struct gl_renderbuffer_attachment *att)
{
if (att->Type == GL_TEXTURE) {
ASSERT(att->Texture);
- att->Texture->RefCount--;
- if (att->Texture->RefCount == 0) {
- ctx->Driver.DeleteTexture(ctx, att->Texture);
- }
- else {
+ if (ctx->Driver.FinishRenderTexture) {
/* tell driver that we're done rendering to this texture. */
- if (ctx->Driver.FinishRenderTexture) {
- ctx->Driver.FinishRenderTexture(ctx, att);
- }
+ ctx->Driver.FinishRenderTexture(ctx, att);
}
- att->Texture = NULL;
+ _mesa_reference_texobj(&att->Texture, NULL); /* unbind */
+ ASSERT(!att->Texture);
}
if (att->Type == GL_TEXTURE || att->Type == GL_RENDERBUFFER_EXT) {
- ASSERT(att->Renderbuffer);
ASSERT(!att->Texture);
- _mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
+ _mesa_reference_renderbuffer(&att->Renderbuffer, NULL); /* unbind */
+ ASSERT(!att->Renderbuffer);
}
att->Type = GL_NONE;
att->Complete = GL_TRUE;
@@ -213,8 +208,8 @@ _mesa_set_texture_attachment(GLcontext *ctx,
/* new attachment */
_mesa_remove_attachment(ctx, att);
att->Type = GL_TEXTURE;
- att->Texture = texObj;
- texObj->RefCount++;
+ assert(!att->Texture);
+ _mesa_reference_texobj(&att->Texture, texObj);
}
/* always update these fields */
diff --git a/src/mesa/main/framebuffer.c b/src/mesa/main/framebuffer.c
index 96f1b30c9b2..dab449fc09a 100644
--- a/src/mesa/main/framebuffer.c
+++ b/src/mesa/main/framebuffer.c
@@ -38,6 +38,7 @@
#include "fbobject.h"
#include "framebuffer.h"
#include "renderbuffer.h"
+#include "texobj.h"
@@ -192,17 +193,11 @@ _mesa_free_framebuffer_data(struct gl_framebuffer *fb)
_mesa_reference_renderbuffer(&att->Renderbuffer, NULL);
}
if (att->Texture) {
- /* render to texture */
- att->Texture->RefCount--;
- if (att->Texture->RefCount == 0) {
- GET_CURRENT_CONTEXT(ctx);
- if (ctx) {
- ctx->Driver.DeleteTexture(ctx, att->Texture);
- }
- }
+ _mesa_reference_texobj(&att->Texture, NULL);
}
+ ASSERT(!att->Renderbuffer);
+ ASSERT(!att->Texture);
att->Type = GL_NONE;
- att->Texture = NULL;
}
/* unbind _Depth/_StencilBuffer to decr ref counts */
diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
index 00e7d5d395d..2d6be1983c6 100644
--- a/src/mesa/main/mtypes.h
+++ b/src/mesa/main/mtypes.h
@@ -1404,6 +1404,7 @@ struct gl_texture_image
*/
struct gl_texture_object
{
+ _glthread_Mutex Mutex; /**< for thread safety */
GLint RefCount; /**< reference count */
GLuint Name; /**< the user-visible texture object ID */
GLenum Target; /**< GL_TEXTURE_1D, GL_TEXTURE_2D, etc. */
@@ -1578,6 +1579,7 @@ struct gl_texture_attrib
struct gl_texture_unit Unit[MAX_TEXTURE_UNITS];
+#if 0
struct gl_texture_object *Proxy1D;
struct gl_texture_object *Proxy2D;
struct gl_texture_object *Proxy3D;
@@ -1585,6 +1587,9 @@ struct gl_texture_attrib
struct gl_texture_object *ProxyRect;
struct gl_texture_object *Proxy1DArray;
struct gl_texture_object *Proxy2DArray;
+#else
+ struct gl_texture_object *ProxyTex[NUM_TEXTURE_TARGETS];
+#endif
/** GL_EXT_shared_texture_palette */
GLboolean SharedPalette;
diff --git a/src/mesa/main/shaders.c b/src/mesa/main/shaders.c
index b7b2f791a52..f0db0d2a818 100644
--- a/src/mesa/main/shaders.c
+++ b/src/mesa/main/shaders.c
@@ -309,11 +309,7 @@ void GLAPIENTRY
_mesa_GetUniformivARB(GLhandleARB program, GLint location, GLint * params)
{
GET_CURRENT_CONTEXT(ctx);
- GLfloat fparams[16]; /* XXX is 16 enough? */
- GLuint i;
- ctx->Driver.GetUniformfv(ctx, program, location, fparams);
- for (i = 0; i < 16; i++)
- params[i] = (GLint) fparams[i]; /* XXX correct? */
+ ctx->Driver.GetUniformiv(ctx, program, location, params);
}
diff --git a/src/mesa/main/teximage.c b/src/mesa/main/teximage.c
index eed19375176..36557f19fd4 100644
--- a/src/mesa/main/teximage.c
+++ b/src/mesa/main/teximage.c
@@ -767,15 +767,15 @@ _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit,
case GL_TEXTURE_1D:
return texUnit->Current1D;
case GL_PROXY_TEXTURE_1D:
- return ctx->Texture.Proxy1D;
+ return ctx->Texture.ProxyTex[TEXTURE_1D_INDEX];
case GL_TEXTURE_2D:
return texUnit->Current2D;
case GL_PROXY_TEXTURE_2D:
- return ctx->Texture.Proxy2D;
+ return ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
case GL_TEXTURE_3D:
return texUnit->Current3D;
case GL_PROXY_TEXTURE_3D:
- return ctx->Texture.Proxy3D;
+ return ctx->Texture.ProxyTex[TEXTURE_3D_INDEX];
case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
@@ -787,25 +787,25 @@ _mesa_select_tex_object(GLcontext *ctx, const struct gl_texture_unit *texUnit,
? texUnit->CurrentCubeMap : NULL;
case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
return ctx->Extensions.ARB_texture_cube_map
- ? ctx->Texture.ProxyCubeMap : NULL;
+ ? ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX] : NULL;
case GL_TEXTURE_RECTANGLE_NV:
return ctx->Extensions.NV_texture_rectangle
? texUnit->CurrentRect : NULL;
case GL_PROXY_TEXTURE_RECTANGLE_NV:
return ctx->Extensions.NV_texture_rectangle
- ? ctx->Texture.ProxyRect : NULL;
+ ? ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX] : NULL;
case GL_TEXTURE_1D_ARRAY_EXT:
return ctx->Extensions.MESA_texture_array
? texUnit->Current1DArray : NULL;
case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
return ctx->Extensions.MESA_texture_array
- ? ctx->Texture.Proxy1DArray : NULL;
+ ? ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX] : NULL;
case GL_TEXTURE_2D_ARRAY_EXT:
return ctx->Extensions.MESA_texture_array
? texUnit->Current2DArray : NULL;
case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
return ctx->Extensions.MESA_texture_array
- ? ctx->Texture.Proxy2DArray : NULL;
+ ? ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX] : NULL;
default:
_mesa_problem(NULL, "bad target in _mesa_select_tex_object()");
return NULL;
@@ -932,106 +932,106 @@ _mesa_get_proxy_tex_image(GLcontext *ctx, GLenum target, GLint level)
case GL_PROXY_TEXTURE_1D:
if (level >= ctx->Const.MaxTextureLevels)
return NULL;
- texImage = ctx->Texture.Proxy1D->Image[0][level];
+ texImage = ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]->Image[0][level];
if (!texImage) {
texImage = ctx->Driver.NewTextureImage(ctx);
if (!texImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
return NULL;
}
- ctx->Texture.Proxy1D->Image[0][level] = texImage;
+ ctx->Texture.ProxyTex[TEXTURE_1D_INDEX]->Image[0][level] = texImage;
/* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.Proxy1D;
+ texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_1D_INDEX];
}
return texImage;
case GL_PROXY_TEXTURE_2D:
if (level >= ctx->Const.MaxTextureLevels)
return NULL;
- texImage = ctx->Texture.Proxy2D->Image[0][level];
+ texImage = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level];
if (!texImage) {
texImage = ctx->Driver.NewTextureImage(ctx);
if (!texImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
return NULL;
}
- ctx->Texture.Proxy2D->Image[0][level] = texImage;
+ ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level] = texImage;
/* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.Proxy2D;
+ texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_2D_INDEX];
}
return texImage;
case GL_PROXY_TEXTURE_3D:
if (level >= ctx->Const.Max3DTextureLevels)
return NULL;
- texImage = ctx->Texture.Proxy3D->Image[0][level];
+ texImage = ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]->Image[0][level];
if (!texImage) {
texImage = ctx->Driver.NewTextureImage(ctx);
if (!texImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
return NULL;
}
- ctx->Texture.Proxy3D->Image[0][level] = texImage;
+ ctx->Texture.ProxyTex[TEXTURE_3D_INDEX]->Image[0][level] = texImage;
/* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.Proxy3D;
+ texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_3D_INDEX];
}
return texImage;
case GL_PROXY_TEXTURE_CUBE_MAP:
if (level >= ctx->Const.MaxCubeTextureLevels)
return NULL;
- texImage = ctx->Texture.ProxyCubeMap->Image[0][level];
+ texImage = ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX]->Image[0][level];
if (!texImage) {
texImage = ctx->Driver.NewTextureImage(ctx);
if (!texImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
return NULL;
}
- ctx->Texture.ProxyCubeMap->Image[0][level] = texImage;
+ ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX]->Image[0][level] = texImage;
/* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.ProxyCubeMap;
+ texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_CUBE_INDEX];
}
return texImage;
case GL_PROXY_TEXTURE_RECTANGLE_NV:
if (level > 0)
return NULL;
- texImage = ctx->Texture.ProxyRect->Image[0][level];
+ texImage = ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX]->Image[0][level];
if (!texImage) {
texImage = ctx->Driver.NewTextureImage(ctx);
if (!texImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
return NULL;
}
- ctx->Texture.ProxyRect->Image[0][level] = texImage;
+ ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX]->Image[0][level] = texImage;
/* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.ProxyRect;
+ texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_RECT_INDEX];
}
return texImage;
case GL_PROXY_TEXTURE_1D_ARRAY_EXT:
if (level >= ctx->Const.MaxTextureLevels)
return NULL;
- texImage = ctx->Texture.Proxy1DArray->Image[0][level];
+ texImage = ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX]->Image[0][level];
if (!texImage) {
texImage = ctx->Driver.NewTextureImage(ctx);
if (!texImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
return NULL;
}
- ctx->Texture.Proxy1DArray->Image[0][level] = texImage;
+ ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX]->Image[0][level] = texImage;
/* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.Proxy1DArray;
+ texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_1D_ARRAY_INDEX];
}
return texImage;
case GL_PROXY_TEXTURE_2D_ARRAY_EXT:
if (level >= ctx->Const.MaxTextureLevels)
return NULL;
- texImage = ctx->Texture.Proxy2DArray->Image[0][level];
+ texImage = ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX]->Image[0][level];
if (!texImage) {
texImage = ctx->Driver.NewTextureImage(ctx);
if (!texImage) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "proxy texture allocation");
return NULL;
}
- ctx->Texture.Proxy2DArray->Image[0][level] = texImage;
+ ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX]->Image[0][level] = texImage;
/* Set the 'back' pointer */
- texImage->TexObject = ctx->Texture.Proxy2DArray;
+ texImage->TexObject = ctx->Texture.ProxyTex[TEXTURE_2D_ARRAY_INDEX];
}
return texImage;
default:
@@ -2611,7 +2611,7 @@ _mesa_TexImage2D( GLenum target, GLint level, GLint internalFormat,
1, border)) {
/* when error, clear all proxy texture image parameters */
if (texImage)
- clear_teximage_fields(ctx->Texture.Proxy2D->Image[0][level]);
+ clear_teximage_fields(ctx->Texture.ProxyTex[TEXTURE_2D_INDEX]->Image[0][level]);
}
else {
/* no error, set the tex image parameters */
diff --git a/src/mesa/main/texobj.c b/src/mesa/main/texobj.c
index 606e62d7a08..b77a00dd15c 100644
--- a/src/mesa/main/texobj.c
+++ b/src/mesa/main/texobj.c
@@ -5,9 +5,9 @@
/*
* Mesa 3-D graphics library
- * Version: 6.5
+ * Version: 7.1
*
- * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
+ * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
@@ -108,6 +108,7 @@ _mesa_initialize_texture_object( struct gl_texture_object *obj,
_mesa_bzero(obj, sizeof(*obj));
/* init the non-zero fields */
+ _glthread_INIT_MUTEX(obj->Mutex);
obj->RefCount = 1;
obj->Name = name;
obj->Target = target;
@@ -155,6 +156,11 @@ _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
(void) ctx;
+ /* Set Target to an invalid value. With some assertions elsewhere
+ * we can try to detect possible use of deleted textures.
+ */
+ texObj->Target = 0x99;
+
#if FEATURE_colortable
_mesa_free_colortable_data(&texObj->Palette);
#endif
@@ -168,6 +174,9 @@ _mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
}
}
+ /* destroy the mutex -- it may have allocated memory (eg on bsd) */
+ _glthread_DESTROY_MUTEX(texObj->Mutex);
+
/* free this object */
_mesa_free(texObj);
}
@@ -186,6 +195,7 @@ void
_mesa_copy_texture_object( struct gl_texture_object *dest,
const struct gl_texture_object *src )
{
+ dest->Target = src->Target;
dest->Name = src->Name;
dest->Priority = src->Priority;
dest->BorderColor[0] = src->BorderColor[0];
@@ -218,6 +228,94 @@ _mesa_copy_texture_object( struct gl_texture_object *dest,
/**
+ * Check if the given texture object is valid by examining its Target field.
+ * For debugging only.
+ */
+static GLboolean
+valid_texture_object(const struct gl_texture_object *tex)
+{
+ switch (tex->Target) {
+ case 0:
+ case GL_TEXTURE_1D:
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_3D:
+ case GL_TEXTURE_CUBE_MAP_ARB:
+ case GL_TEXTURE_RECTANGLE_NV:
+ case GL_TEXTURE_1D_ARRAY_EXT:
+ case GL_TEXTURE_2D_ARRAY_EXT:
+ return GL_TRUE;
+ case 0x99:
+ _mesa_problem(NULL, "invalid reference to a deleted texture object");
+ return GL_FALSE;
+ default:
+ _mesa_problem(NULL, "invalid texture object Target value");
+ return GL_FALSE;
+ }
+}
+
+
+/**
+ * Reference (or unreference) a texture object.
+ * If '*ptr', decrement *ptr's refcount (and delete if it becomes zero).
+ * If 'tex' is non-null, increment its refcount.
+ */
+void
+_mesa_reference_texobj(struct gl_texture_object **ptr,
+ struct gl_texture_object *tex)
+{
+ assert(ptr);
+ if (*ptr == tex) {
+ /* no change */
+ return;
+ }
+
+ if (*ptr) {
+ /* Unreference the old texture */
+ GLboolean deleteFlag = GL_FALSE;
+ struct gl_texture_object *oldTex = *ptr;
+
+ assert(valid_texture_object(oldTex));
+
+ _glthread_LOCK_MUTEX(oldTex->Mutex);
+ ASSERT(oldTex->RefCount > 0);
+ oldTex->RefCount--;
+
+ deleteFlag = (oldTex->RefCount == 0);
+ _glthread_UNLOCK_MUTEX(oldTex->Mutex);
+
+ if (deleteFlag) {
+ GET_CURRENT_CONTEXT(ctx);
+ if (ctx)
+ ctx->Driver.DeleteTexture(ctx, oldTex);
+ else
+ _mesa_problem(NULL, "Unable to delete texture, no context");
+ }
+
+ *ptr = NULL;
+ }
+ assert(!*ptr);
+
+ if (tex) {
+ /* reference new texture */
+ assert(valid_texture_object(tex));
+ _glthread_LOCK_MUTEX(tex->Mutex);
+ if (tex->RefCount == 0) {
+ /* this texture's being deleted (look just above) */
+ /* Not sure this can every really happen. Warn if it does. */
+ _mesa_problem(NULL, "referencing deleted texture object");
+ *ptr = NULL;
+ }
+ else {
+ tex->RefCount++;
+ *ptr = tex;
+ }
+ _glthread_UNLOCK_MUTEX(tex->Mutex);
+ }
+}
+
+
+
+/**
* Report why a texture object is incomplete.
*
* \param t texture object.
@@ -613,8 +711,7 @@ unbind_texobj_from_fbo(GLcontext *ctx, struct gl_texture_object *texObj)
/**
* Check if the given texture object is bound to any texture image units and
- * unbind it if so.
- * XXX all RefCount accesses should be protected by a mutex.
+ * unbind it if so (revert to default textures).
*/
static void
unbind_texobj_from_texunits(GLcontext *ctx, struct gl_texture_object *texObj)
@@ -623,42 +720,26 @@ 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];
- struct gl_texture_object **curr = NULL;
-
if (texObj == unit->Current1D) {
- curr = &unit->Current1D;
- unit->Current1D = ctx->Shared->Default1D;
+ _mesa_reference_texobj(&unit->Current1D, ctx->Shared->Default1D);
}
else if (texObj == unit->Current2D) {
- curr = &unit->Current2D;
- unit->Current2D = ctx->Shared->Default2D;
+ _mesa_reference_texobj(&unit->Current2D, ctx->Shared->Default2D);
}
else if (texObj == unit->Current3D) {
- curr = &unit->Current3D;
- unit->Current3D = ctx->Shared->Default3D;
+ _mesa_reference_texobj(&unit->Current3D, ctx->Shared->Default3D);
}
else if (texObj == unit->CurrentCubeMap) {
- curr = &unit->CurrentCubeMap;
- unit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
+ _mesa_reference_texobj(&unit->CurrentCubeMap, ctx->Shared->DefaultCubeMap);
}
else if (texObj == unit->CurrentRect) {
- curr = &unit->CurrentRect;
- unit->CurrentRect = ctx->Shared->DefaultRect;
+ _mesa_reference_texobj(&unit->CurrentRect, ctx->Shared->DefaultRect);
}
else if (texObj == unit->Current1DArray) {
- curr = &unit->Current1DArray;
- unit->CurrentRect = ctx->Shared->Default1DArray;
+ _mesa_reference_texobj(&unit->Current1DArray, ctx->Shared->Default1DArray);
}
else if (texObj == unit->Current2DArray) {
- curr = &unit->Current1DArray;
- unit->CurrentRect = ctx->Shared->Default2DArray;
- }
-
- if (curr) {
- (*curr)->RefCount++;
- texObj->RefCount--;
- if (texObj == unit->_Current)
- unit->_Current = *curr;
+ _mesa_reference_texobj(&unit->Current2DArray, ctx->Shared->Default2DArray);
}
}
}
@@ -694,8 +775,6 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures)
= _mesa_lookup_texture(ctx, textures[i]);
if (delObj) {
- GLboolean deleted;
-
_mesa_lock_texture(ctx, delObj);
/* Check if texture is bound to any framebuffer objects.
@@ -705,10 +784,12 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures)
unbind_texobj_from_fbo(ctx, delObj);
/* Check if this texture is currently bound to any texture units.
- * If so, unbind it and decrement the reference count.
+ * If so, unbind it.
*/
unbind_texobj_from_texunits(ctx, delObj);
+ _mesa_unlock_texture(ctx, delObj);
+
ctx->NewState |= _NEW_TEXTURE;
/* The texture _name_ is now free for re-use.
@@ -718,23 +799,10 @@ _mesa_DeleteTextures( GLsizei n, const GLuint *textures)
_mesa_HashRemove(ctx->Shared->TexObjects, delObj->Name);
_glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
- /* The actual texture object will not be freed until it's no
- * longer bound in any context.
- * XXX all RefCount accesses should be protected by a mutex.
+ /* Unreference the texobj. If refcount hits zero, the texture
+ * will be deleted.
*/
- delObj->RefCount--;
- deleted = (delObj->RefCount == 0);
- _mesa_unlock_texture(ctx, delObj);
-
- /* We know that refcount went to zero above, so this is
- * the only pointer left to delObj, so we don't have to
- * worry about locking any more:
- */
- if (deleted) {
- ASSERT(delObj->Name != 0); /* Never delete default tex objs */
- ASSERT(ctx->Driver.DeleteTexture);
- (*ctx->Driver.DeleteTexture)(ctx, delObj);
- }
+ _mesa_reference_texobj(&delObj, NULL);
}
}
}
@@ -762,7 +830,6 @@ _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 *oldTexObj;
struct gl_texture_object *newTexObj = NULL;
ASSERT_OUTSIDE_BEGIN_END(ctx);
@@ -771,62 +838,6 @@ _mesa_BindTexture( GLenum target, GLuint texName )
_mesa_lookup_enum_by_nr(target), (GLint) texName);
/*
- * Get pointer to currently bound texture object (oldTexObj)
- */
- switch (target) {
- case GL_TEXTURE_1D:
- oldTexObj = texUnit->Current1D;
- break;
- case GL_TEXTURE_2D:
- oldTexObj = texUnit->Current2D;
- break;
- case GL_TEXTURE_3D:
- oldTexObj = texUnit->Current3D;
- break;
- case GL_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" );
- return;
- }
- oldTexObj = texUnit->CurrentCubeMap;
- break;
- case GL_TEXTURE_RECTANGLE_NV:
- if (!ctx->Extensions.NV_texture_rectangle) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" );
- return;
- }
- oldTexObj = texUnit->CurrentRect;
- break;
- case GL_TEXTURE_1D_ARRAY_EXT:
- if (!ctx->Extensions.MESA_texture_array) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" );
- return;
- }
- oldTexObj = texUnit->Current1DArray;
- break;
- case GL_TEXTURE_2D_ARRAY_EXT:
- if (!ctx->Extensions.MESA_texture_array) {
- _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" );
- return;
- }
- oldTexObj = texUnit->Current2DArray;
- break;
- default:
- _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" );
- return;
- }
-
- if (oldTexObj->Name == texName) {
- /* XXX this might be wrong. If the texobj is in use by another
- * context and a texobj parameter was changed, this might be our
- * only chance to update this context's hardware state.
- * Note that some applications re-bind the same texture a lot so we
- * want to handle that case quickly.
- */
- return; /* rebinding the same texture- no change */
- }
-
- /*
* Get pointer to new texture object (newTexObj)
*/
if (texName == 0) {
@@ -854,7 +865,8 @@ _mesa_BindTexture( GLenum target, GLuint texName )
newTexObj = ctx->Shared->Default2DArray;
break;
default:
- ; /* Bad targets are caught above */
+ _mesa_error(ctx, GL_INVALID_ENUM, "glBindTexture(target)");
+ return;
}
}
else {
@@ -900,28 +912,30 @@ _mesa_BindTexture( GLenum target, GLuint texName )
newTexObj->Target = target;
}
- /* XXX all RefCount accesses should be protected by a mutex. */
- newTexObj->RefCount++;
+ assert(valid_texture_object(newTexObj));
- /* do the actual binding, but first flush outstanding vertices:
- */
+ /* flush before changing binding */
FLUSH_VERTICES(ctx, _NEW_TEXTURE);
+ /* Do the actual binding. The refcount on the previously bound
+ * texture object will be decremented. It'll be deleted if the
+ * count hits zero.
+ */
switch (target) {
case GL_TEXTURE_1D:
- texUnit->Current1D = newTexObj;
+ _mesa_reference_texobj(&texUnit->Current1D, newTexObj);
break;
case GL_TEXTURE_2D:
- texUnit->Current2D = newTexObj;
+ _mesa_reference_texobj(&texUnit->Current2D, newTexObj);
break;
case GL_TEXTURE_3D:
- texUnit->Current3D = newTexObj;
+ _mesa_reference_texobj(&texUnit->Current3D, newTexObj);
break;
case GL_TEXTURE_CUBE_MAP_ARB:
- texUnit->CurrentCubeMap = newTexObj;
+ _mesa_reference_texobj(&texUnit->CurrentCubeMap, newTexObj);
break;
case GL_TEXTURE_RECTANGLE_NV:
- texUnit->CurrentRect = newTexObj;
+ _mesa_reference_texobj(&texUnit->CurrentRect, newTexObj);
break;
case GL_TEXTURE_1D_ARRAY_EXT:
texUnit->Current1DArray = newTexObj;
@@ -930,6 +944,7 @@ _mesa_BindTexture( GLenum target, GLuint texName )
texUnit->Current2DArray = newTexObj;
break;
default:
+ /* Bad target should be caught above */
_mesa_problem(ctx, "bad target in BindTexture");
return;
}
@@ -937,18 +952,6 @@ _mesa_BindTexture( GLenum target, GLuint texName )
/* Pass BindTexture call to device driver */
if (ctx->Driver.BindTexture)
(*ctx->Driver.BindTexture)( ctx, target, newTexObj );
-
- /* Decrement the reference count on the old texture and check if it's
- * time to delete it.
- */
- /* XXX all RefCount accesses should be protected by a mutex. */
- oldTexObj->RefCount--;
- ASSERT(oldTexObj->RefCount >= 0);
- if (oldTexObj->RefCount == 0) {
- ASSERT(oldTexObj->Name != 0);
- ASSERT(ctx->Driver.DeleteTexture);
- (*ctx->Driver.DeleteTexture)( ctx, oldTexObj );
- }
}
diff --git a/src/mesa/main/texobj.h b/src/mesa/main/texobj.h
index 2a2bde36017..d5374c5d6c4 100644
--- a/src/mesa/main/texobj.h
+++ b/src/mesa/main/texobj.h
@@ -58,6 +58,10 @@ _mesa_copy_texture_object( struct gl_texture_object *dest,
const struct gl_texture_object *src );
extern void
+_mesa_reference_texobj(struct gl_texture_object **ptr,
+ struct gl_texture_object *tex);
+
+extern void
_mesa_test_texobj_completeness( const GLcontext *ctx,
struct gl_texture_object *obj );
diff --git a/src/mesa/main/texstate.c b/src/mesa/main/texstate.c
index 421f9128493..20f9c4512c4 100644
--- a/src/mesa/main/texstate.c
+++ b/src/mesa/main/texstate.c
@@ -62,31 +62,6 @@ static const struct gl_tex_env_combine_state default_combine_state = {
};
-/**
- * Copy a texture binding. Helper used by _mesa_copy_texture_state().
- */
-static void
-copy_texture_binding(const GLcontext *ctx,
- struct gl_texture_object **dst,
- struct gl_texture_object *src)
-{
- /* only copy if names differ (per OpenGL SI) */
- if ((*dst)->Name != src->Name) {
- /* unbind/delete dest binding which we're changing */
- (*dst)->RefCount--;
- if ((*dst)->RefCount == 0) {
- /* time to delete this texture object */
- ASSERT((*dst)->Name != 0);
- ASSERT(ctx->Driver.DeleteTexture);
- /* XXX cast-away const, unfortunately */
- (*ctx->Driver.DeleteTexture)((GLcontext *) ctx, *dst);
- }
- /* make new binding, incrementing ref count */
- *dst = src;
- src->RefCount++;
- }
-}
-
/**
* Used by glXCopyContext to copy texture state from one context to another.
@@ -143,20 +118,20 @@ _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst )
/* copy texture object bindings, not contents of texture objects */
_mesa_lock_context_textures(dst);
- copy_texture_binding(src, &dst->Texture.Unit[i].Current1D,
- src->Texture.Unit[i].Current1D);
- copy_texture_binding(src, &dst->Texture.Unit[i].Current2D,
- src->Texture.Unit[i].Current2D);
- copy_texture_binding(src, &dst->Texture.Unit[i].Current3D,
- src->Texture.Unit[i].Current3D);
- copy_texture_binding(src, &dst->Texture.Unit[i].CurrentCubeMap,
- src->Texture.Unit[i].CurrentCubeMap);
- copy_texture_binding(src, &dst->Texture.Unit[i].CurrentRect,
- src->Texture.Unit[i].CurrentRect);
- copy_texture_binding(src, &dst->Texture.Unit[i].Current1DArray,
- src->Texture.Unit[i].Current1DArray);
- copy_texture_binding(src, &dst->Texture.Unit[i].Current2DArray,
- src->Texture.Unit[i].Current2DArray);
+ _mesa_reference_texobj(&dst->Texture.Unit[i].Current1D,
+ src->Texture.Unit[i].Current1D);
+ _mesa_reference_texobj(&dst->Texture.Unit[i].Current2D,
+ src->Texture.Unit[i].Current2D);
+ _mesa_reference_texobj(&dst->Texture.Unit[i].Current3D,
+ src->Texture.Unit[i].Current3D);
+ _mesa_reference_texobj(&dst->Texture.Unit[i].CurrentCubeMap,
+ src->Texture.Unit[i].CurrentCubeMap);
+ _mesa_reference_texobj(&dst->Texture.Unit[i].CurrentRect,
+ src->Texture.Unit[i].CurrentRect);
+ _mesa_reference_texobj(&dst->Texture.Unit[i].Current1DArray,
+ src->Texture.Unit[i].Current1DArray);
+ _mesa_reference_texobj(&dst->Texture.Unit[i].Current2DArray,
+ src->Texture.Unit[i].Current2DArray);
_mesa_unlock_context_textures(dst);
}
@@ -699,52 +674,32 @@ _mesa_update_texture( GLcontext *ctx, GLuint new_state )
static GLboolean
alloc_proxy_textures( GLcontext *ctx )
{
- ctx->Texture.Proxy1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
- if (!ctx->Texture.Proxy1D)
- goto cleanup;
-
- ctx->Texture.Proxy2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
- if (!ctx->Texture.Proxy2D)
- goto cleanup;
-
- ctx->Texture.Proxy3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
- if (!ctx->Texture.Proxy3D)
- goto cleanup;
-
- ctx->Texture.ProxyCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
- if (!ctx->Texture.ProxyCubeMap)
- goto cleanup;
-
- ctx->Texture.ProxyRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
- if (!ctx->Texture.ProxyRect)
- goto cleanup;
-
- ctx->Texture.Proxy1DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D_ARRAY_EXT);
- if (!ctx->Texture.Proxy1DArray)
- goto cleanup;
-
- ctx->Texture.Proxy2DArray = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D_ARRAY_EXT);
- if (!ctx->Texture.Proxy2DArray)
- goto cleanup;
+ static const GLenum targets[] = {
+ GL_TEXTURE_1D,
+ GL_TEXTURE_2D,
+ GL_TEXTURE_3D,
+ GL_TEXTURE_CUBE_MAP_ARB,
+ GL_TEXTURE_RECTANGLE_NV,
+ GL_TEXTURE_1D_ARRAY_EXT,
+ GL_TEXTURE_2D_ARRAY_EXT
+ };
+ GLint tgt;
+
+ ASSERT(Elements(targets) == NUM_TEXTURE_TARGETS);
+
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
+ if (!(ctx->Texture.ProxyTex[tgt]
+ = ctx->Driver.NewTextureObject(ctx, 0, targets[tgt]))) {
+ /* out of memory, free what we did allocate */
+ while (--tgt >= 0) {
+ ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
+ }
+ return GL_FALSE;
+ }
+ }
+ assert(ctx->Texture.ProxyTex[0]->RefCount == 1); /* sanity check */
return GL_TRUE;
-
- cleanup:
- if (ctx->Texture.Proxy1D)
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D);
- if (ctx->Texture.Proxy2D)
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2D);
- if (ctx->Texture.Proxy3D)
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy3D);
- if (ctx->Texture.ProxyCubeMap)
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyCubeMap);
- if (ctx->Texture.ProxyRect)
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyRect);
- if (ctx->Texture.Proxy1DArray)
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1DArray);
- if (ctx->Texture.Proxy2DArray)
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2DArray);
- return GL_FALSE;
}
@@ -786,13 +741,14 @@ init_texture_unit( GLcontext *ctx, GLuint unit )
ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
- texUnit->Current1D = ctx->Shared->Default1D;
- texUnit->Current2D = ctx->Shared->Default2D;
- texUnit->Current3D = ctx->Shared->Default3D;
- texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
- texUnit->CurrentRect = ctx->Shared->DefaultRect;
- texUnit->Current1DArray = ctx->Shared->Default1DArray;
- texUnit->Current2DArray = ctx->Shared->Default2DArray;
+ /* 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);
}
@@ -807,25 +763,22 @@ _mesa_init_texture(GLcontext *ctx)
assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
- /* Effectively bind the default textures to all texture units */
- ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
- ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
- ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
- ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
- ctx->Shared->DefaultRect->RefCount += MAX_TEXTURE_UNITS;
- ctx->Shared->Default1DArray->RefCount += MAX_TEXTURE_UNITS;
- ctx->Shared->Default2DArray->RefCount += MAX_TEXTURE_UNITS;
-
/* Texture group */
ctx->Texture.CurrentUnit = 0; /* multitexture */
ctx->Texture._EnabledUnits = 0;
- for (i=0; i<MAX_TEXTURE_UNITS; i++)
- init_texture_unit( ctx, i );
ctx->Texture.SharedPalette = GL_FALSE;
#if FEATURE_colortable
_mesa_init_colortable(&ctx->Texture.Palette);
#endif
+ for (i = 0; i < MAX_TEXTURE_UNITS; i++)
+ init_texture_unit( ctx, i );
+
+ /* 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);
+
/* Allocate proxy textures */
if (!alloc_proxy_textures( ctx ))
return GL_FALSE;
@@ -840,14 +793,24 @@ _mesa_init_texture(GLcontext *ctx)
void
_mesa_free_texture_data(GLcontext *ctx)
{
+ GLuint u, tgt;
+
+ /* unreference current textures */
+ for (u = 0; u < MAX_TEXTURE_IMAGE_UNITS; u++) {
+ struct gl_texture_unit *unit = ctx->Texture.Unit + u;
+ _mesa_reference_texobj(&unit->Current1D, NULL);
+ _mesa_reference_texobj(&unit->Current2D, NULL);
+ _mesa_reference_texobj(&unit->Current3D, NULL);
+ _mesa_reference_texobj(&unit->CurrentCubeMap, NULL);
+ _mesa_reference_texobj(&unit->CurrentRect, NULL);
+ _mesa_reference_texobj(&unit->Current1DArray, NULL);
+ _mesa_reference_texobj(&unit->Current2DArray, NULL);
+ }
+
/* Free proxy texture objects */
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D );
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2D );
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy3D );
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyCubeMap );
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyRect );
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1DArray );
- (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2DArray );
+ for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++)
+ ctx->Driver.DeleteTexture(ctx, ctx->Texture.ProxyTex[tgt]);
+
#if FEATURE_colortable
{