#include "glheader.h"
#include "colortab.h"
#include "context.h"
#include "enums.h"
#include "fbobject.h"
#include "hash.h"
#include "imports.h"
#include "macros.h"
#include "teximage.h"
#include "texstate.h"
#include "texobj.h"
#include "mtypes.h"
#ifdef __VMS
#define _mesa_sprintf sprintf
#endif
struct gl_texture_object *
_mesa_lookup_texture(GLcontext *ctx, GLuint id)
{
return (struct gl_texture_object *)
_mesa_HashLookup(ctx->Shared->TexObjects, id);
}
struct gl_texture_object *
_mesa_new_texture_object( GLcontext *ctx, GLuint name, GLenum target )
{
struct gl_texture_object *obj;
(void) ctx;
obj = MALLOC_STRUCT(gl_texture_object);
_mesa_initialize_texture_object(obj, name, target);
return obj;
}
void
_mesa_initialize_texture_object( struct gl_texture_object *obj,
GLuint name, GLenum target )
{
ASSERT(target == 0 ||
target == GL_TEXTURE_1D ||
target == GL_TEXTURE_2D ||
target == GL_TEXTURE_3D ||
target == GL_TEXTURE_CUBE_MAP_ARB ||
target == GL_TEXTURE_RECTANGLE_NV);
_mesa_bzero(obj, sizeof(*obj));
_glthread_INIT_MUTEX(obj->Mutex);
obj->RefCount = 1;
obj->Name = name;
obj->Target = target;
obj->Priority = 1.0F;
if (target == GL_TEXTURE_RECTANGLE_NV) {
obj->WrapS = GL_CLAMP_TO_EDGE;
obj->WrapT = GL_CLAMP_TO_EDGE;
obj->WrapR = GL_CLAMP_TO_EDGE;
obj->MinFilter = GL_LINEAR;
}
else {
obj->WrapS = GL_REPEAT;
obj->WrapT = GL_REPEAT;
obj->WrapR = GL_REPEAT;
obj->MinFilter = GL_NEAREST_MIPMAP_LINEAR;
}
obj->MagFilter = GL_LINEAR;
obj->MinLod = -1000.0;
obj->MaxLod = 1000.0;
obj->LodBias = 0.0;
obj->BaseLevel = 0;
obj->MaxLevel = 1000;
obj->MaxAnisotropy = 1.0;
obj->CompareFlag = GL_FALSE;
obj->CompareOperator = GL_TEXTURE_LEQUAL_R_SGIX;
obj->CompareMode = GL_NONE;
obj->CompareFunc = GL_LEQUAL;
obj->DepthMode = GL_LUMINANCE;
obj->ShadowAmbient = 0.0F;
_mesa_init_colortable(&obj->Palette);
}
void
_mesa_delete_texture_object( GLcontext *ctx, struct gl_texture_object *texObj )
{
GLuint i, face;
(void) ctx;
texObj->Target = 0x99;
_mesa_free_colortable_data(&texObj->Palette);
for (face = 0; face < 6; face++) {
for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
if (texObj->Image[face][i]) {
_mesa_delete_texture_image( ctx, texObj->Image[face][i] );
}
}
}
_glthread_DESTROY_MUTEX(texObj->Mutex);
_mesa_free(texObj);
}
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];
dest->BorderColor[1] = src->BorderColor[1];
dest->BorderColor[2] = src->BorderColor[2];
dest->BorderColor[3] = src->BorderColor[3];
dest->WrapS = src->WrapS;
dest->WrapT = src->WrapT;
dest->WrapR = src->WrapR;
dest->MinFilter = src->MinFilter;
dest->MagFilter = src->MagFilter;
dest->MinLod = src->MinLod;
dest->MaxLod = src->MaxLod;
dest->LodBias = src->LodBias;
dest->BaseLevel = src->BaseLevel;
dest->MaxLevel = src->MaxLevel;
dest->MaxAnisotropy = src->MaxAnisotropy;
dest->CompareFlag = src->CompareFlag;
dest->CompareOperator = src->CompareOperator;
dest->ShadowAmbient = src->ShadowAmbient;
dest->CompareMode = src->CompareMode;
dest->CompareFunc = src->CompareFunc;
dest->DepthMode = src->DepthMode;
dest->_MaxLevel = src->_MaxLevel;
dest->_MaxLambda = src->_MaxLambda;
dest->GenerateMipmap = src->GenerateMipmap;
dest->Palette = src->Palette;
dest->Complete = src->Complete;
}
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:
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;
}
}
void
_mesa_reference_texobj(struct gl_texture_object **ptr,
struct gl_texture_object *tex)
{
assert(ptr);
if (*ptr == tex) {
return;
}
if (*ptr) {
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) {
assert(valid_texture_object(tex));
_glthread_LOCK_MUTEX(tex->Mutex);
if (tex->RefCount == 0) {
_mesa_problem(NULL, "referencing deleted texture object");
*ptr = NULL;
}
else {
tex->RefCount++;
*ptr = tex;
}
_glthread_UNLOCK_MUTEX(tex->Mutex);
}
}
#if 0
static void
incomplete(const struct gl_texture_object *t, const char *why)
{
_mesa_printf("Texture Obj %d incomplete because: %s\n", t->Name, why);
}
#else
#define incomplete(t, why)
#endif
void
_mesa_test_texobj_completeness( const GLcontext *ctx,
struct gl_texture_object *t )
{
const GLint baseLevel = t->BaseLevel;
GLint maxLog2 = 0, maxLevels = 0;
t->Complete = GL_TRUE;
if (!t->Image[0][baseLevel]) {
char s[100];
_mesa_sprintf(s, "obj %p (%d) Image[baseLevel=%d] == NULL",
(void *) t, t->Name, baseLevel);
incomplete(t, s);
t->Complete = GL_FALSE;
return;
}
if (t->Image[0][baseLevel]->Width == 0 ||
t->Image[0][baseLevel]->Height == 0 ||
t->Image[0][baseLevel]->Depth == 0) {
incomplete(t, "texture width = 0");
t->Complete = GL_FALSE;
return;
}
if (t->Target == GL_TEXTURE_1D) {
maxLog2 = t->Image[0][baseLevel]->WidthLog2;
maxLevels = ctx->Const.MaxTextureLevels;
}
else if (t->Target == GL_TEXTURE_2D) {
maxLog2 = MAX2(t->Image[0][baseLevel]->WidthLog2,
t->Image[0][baseLevel]->HeightLog2);
maxLevels = ctx->Const.MaxTextureLevels;
}
else if (t->Target == GL_TEXTURE_3D) {
GLint max = MAX2(t->Image[0][baseLevel]->WidthLog2,
t->Image[0][baseLevel]->HeightLog2);
maxLog2 = MAX2(max, (GLint)(t->Image[0][baseLevel]->DepthLog2));
maxLevels = ctx->Const.Max3DTextureLevels;
}
else if (t->Target == GL_TEXTURE_CUBE_MAP_ARB) {
maxLog2 = MAX2(t->Image[0][baseLevel]->WidthLog2,
t->Image[0][baseLevel]->HeightLog2);
maxLevels = ctx->Const.MaxCubeTextureLevels;
}
else if (t->Target == GL_TEXTURE_RECTANGLE_NV) {
maxLog2 = 0;
maxLevels = 1;
}
else {
_mesa_problem(ctx, "Bad t->Target in _mesa_test_texobj_completeness");
return;
}
ASSERT(maxLevels > 0);
t->_MaxLevel = baseLevel + maxLog2;
t->_MaxLevel = MIN2(t->_MaxLevel, t->MaxLevel);
t->_MaxLevel = MIN2(t->_MaxLevel, maxLevels - 1);
t->_MaxLambda = (GLfloat) (t->_MaxLevel - t->BaseLevel);
if (t->Target == GL_TEXTURE_CUBE_MAP_ARB) {
const GLuint w = t->Image[0][baseLevel]->Width2;
const GLuint h = t->Image[0][baseLevel]->Height2;
GLuint face;
for (face = 1; face < 6; face++) {
if (t->Image[face][baseLevel] == NULL ||
t->Image[face][baseLevel]->Width2 != w ||
t->Image[face][baseLevel]->Height2 != h) {
t->Complete = GL_FALSE;
incomplete(t, "Non-quare cubemap image");
return;
}
}
}
if (t->MinFilter != GL_NEAREST && t->MinFilter != GL_LINEAR) {
GLint i;
GLint minLevel = baseLevel;
GLint maxLevel = t->_MaxLevel;
if (minLevel > maxLevel) {
t->Complete = GL_FALSE;
incomplete(t, "minLevel > maxLevel");
return;
}
for (i = minLevel; i <= maxLevel; i++) {
if (t->Image[0][i]) {
if (t->Image[0][i]->TexFormat != t->Image[0][baseLevel]->TexFormat) {
t->Complete = GL_FALSE;
incomplete(t, "Format[i] != Format[baseLevel]");
return;
}
if (t->Image[0][i]->Border != t->Image[0][baseLevel]->Border) {
t->Complete = GL_FALSE;
incomplete(t, "Border[i] != Border[baseLevel]");
return;
}
}
}
if (t->Target == GL_TEXTURE_1D) {
GLuint width = t->Image[0][baseLevel]->Width2;
for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
if (i >= minLevel && i <= maxLevel) {
if (!t->Image[0][i]) {
t->Complete = GL_FALSE;
incomplete(t, "1D Image[0][i] == NULL");
return;
}
if (t->Image[0][i]->Width2 != width ) {
t->Complete = GL_FALSE;
incomplete(t, "1D Image[0][i] bad width");
return;
}
}
if (width == 1) {
return;
}
}
}
else if (t->Target == GL_TEXTURE_2D) {
GLuint width = t->Image[0][baseLevel]->Width2;
GLuint height = t->Image[0][baseLevel]->Height2;
for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
if (height > 1) {
height /= 2;
}
if (i >= minLevel && i <= maxLevel) {
if (!t->Image[0][i]) {
t->Complete = GL_FALSE;
incomplete(t, "2D Image[0][i] == NULL");
return;
}
if (t->Image[0][i]->Width2 != width) {
t->Complete = GL_FALSE;
incomplete(t, "2D Image[0][i] bad width");
return;
}
if (t->Image[0][i]->Height2 != height) {
t->Complete = GL_FALSE;
incomplete(t, "2D Image[0][i] bad height");
return;
}
if (width==1 && height==1) {
return;
}
}
}
}
else if (t->Target == GL_TEXTURE_3D) {
GLuint width = t->Image[0][baseLevel]->Width2;
GLuint height = t->Image[0][baseLevel]->Height2;
GLuint depth = t->Image[0][baseLevel]->Depth2;
for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
if (height > 1) {
height /= 2;
}
if (depth > 1) {
depth /= 2;
}
if (i >= minLevel && i <= maxLevel) {
if (!t->Image[0][i]) {
incomplete(t, "3D Image[0][i] == NULL");
t->Complete = GL_FALSE;
return;
}
if (t->Image[0][i]->_BaseFormat == GL_DEPTH_COMPONENT) {
t->Complete = GL_FALSE;
incomplete(t, "GL_DEPTH_COMPONENT only works with 1/2D tex");
return;
}
if (t->Image[0][i]->Width2 != width) {
t->Complete = GL_FALSE;
incomplete(t, "3D Image[0][i] bad width");
return;
}
if (t->Image[0][i]->Height2 != height) {
t->Complete = GL_FALSE;
incomplete(t, "3D Image[0][i] bad height");
return;
}
if (t->Image[0][i]->Depth2 != depth) {
t->Complete = GL_FALSE;
incomplete(t, "3D Image[0][i] bad depth");
return;
}
}
if (width == 1 && height == 1 && depth == 1) {
return;
}
}
}
else if (t->Target == GL_TEXTURE_CUBE_MAP_ARB) {
GLuint width = t->Image[0][baseLevel]->Width2;
GLuint height = t->Image[0][baseLevel]->Height2;
for (i = baseLevel + 1; i < maxLevels; i++) {
if (width > 1) {
width /= 2;
}
if (height > 1) {
height /= 2;
}
if (i >= minLevel && i <= maxLevel) {
GLuint face;
for (face = 0; face < 6; face++) {
if (!t->Image[face][i]) {
t->Complete = GL_FALSE;
incomplete(t, "CubeMap Image[n][i] == NULL");
return;
}
if (t->Image[face][i]->_BaseFormat == GL_DEPTH_COMPONENT) {
t->Complete = GL_FALSE;
incomplete(t, "GL_DEPTH_COMPONENT only works with 1/2D tex");
return;
}
if (t->Image[face][i]->Width2!=width ||
t->Image[face][i]->Height2!=height) {
t->Complete = GL_FALSE;
incomplete(t, "CubeMap Image[n][i] bad size");
return;
}
}
}
if (width == 1 && height == 1) {
return;
}
}
}
else if (t->Target == GL_TEXTURE_RECTANGLE_NV) {
}
else {
_mesa_problem(ctx, "Bug in gl_test_texture_object_completeness\n");
}
}
}
_glthread_DECLARE_STATIC_MUTEX(GenTexturesLock);
void GLAPIENTRY
_mesa_GenTextures( GLsizei n, GLuint *textures )
{
GET_CURRENT_CONTEXT(ctx);
GLuint first;
GLint i;
ASSERT_OUTSIDE_BEGIN_END(ctx);
if (n < 0) {
_mesa_error( ctx, GL_INVALID_VALUE, "glGenTextures" );
return;
}
if (!textures)
return;
_glthread_LOCK_MUTEX(GenTexturesLock);
first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
for (i = 0; i < n; i++) {
struct gl_texture_object *texObj;
GLuint name = first + i;
GLenum target = 0;
texObj = (*ctx->Driver.NewTextureObject)( ctx, name, target);
if (!texObj) {
_glthread_UNLOCK_MUTEX(GenTexturesLock);
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenTextures");
return;
}
_glthread_LOCK_MUTEX(ctx->Shared->Mutex);
_mesa_HashInsert(ctx->Shared->TexObjects, texObj->Name, texObj);
_glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
textures[i] = name;
}
_glthread_UNLOCK_MUTEX(GenTexturesLock);
}
static void
unbind_texobj_from_fbo(GLcontext *ctx, struct gl_texture_object *texObj)
{
const GLuint n = (ctx->DrawBuffer == ctx->ReadBuffer) ? 1 : 2;
GLuint i;
for (i = 0; i < n; i++) {
struct gl_framebuffer *fb = (i == 0) ? ctx->DrawBuffer : ctx->ReadBuffer;
if (fb->Name) {
GLuint j;
for (j = 0; j < BUFFER_COUNT; j++) {
if (fb->Attachment[j].Type == GL_TEXTURE &&
fb->Attachment[j].Texture == texObj) {
_mesa_remove_attachment(ctx, fb->Attachment + j);
}
}
}
}
}
static void
unbind_texobj_from_texunits(GLcontext *ctx, struct gl_texture_object *texObj)
{
GLuint u;
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);
}
else if (texObj == unit->Current2D) {
_mesa_reference_texobj(&unit->Current2D, ctx->Shared->Default2D);
}
else if (texObj == unit->Current3D) {
_mesa_reference_texobj(&unit->Current3D, ctx->Shared->Default3D);
}
else if (texObj == unit->CurrentCubeMap) {
_mesa_reference_texobj(&unit->CurrentCubeMap, ctx->Shared->DefaultCubeMap);
}
else if (texObj == unit->CurrentRect) {
_mesa_reference_texobj(&unit->CurrentRect, ctx->Shared->DefaultRect);
}
}
}
void GLAPIENTRY
_mesa_DeleteTextures( GLsizei n, const GLuint *textures)
{
GET_CURRENT_CONTEXT(ctx);
GLint i;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
if (!textures)
return;
for (i = 0; i < n; i++) {
if (textures[i] > 0) {
struct gl_texture_object *delObj
= _mesa_lookup_texture(ctx, textures[i]);
if (delObj) {
_mesa_lock_texture(ctx, delObj);
unbind_texobj_from_fbo(ctx, delObj);
unbind_texobj_from_texunits(ctx, delObj);
_mesa_unlock_texture(ctx, delObj);
ctx->NewState |= _NEW_TEXTURE;
_glthread_LOCK_MUTEX(ctx->Shared->Mutex);
_mesa_HashRemove(ctx->Shared->TexObjects, delObj->Name);
_glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
_mesa_reference_texobj(&delObj, NULL);
}
}
}
}
void GLAPIENTRY
_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;
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);
if (texName == 0) {
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;
default:
_mesa_error(ctx, GL_INVALID_ENUM, "glBindTexture(target)");
return;
}
}
else {
newTexObj = _mesa_lookup_texture(ctx, texName);
if (newTexObj) {
if (newTexObj->Target != 0 && newTexObj->Target != target) {
_mesa_error( ctx, GL_INVALID_OPERATION,
"glBindTexture(wrong dimensionality)" );
return;
}
if (newTexObj->Target == 0 && target == GL_TEXTURE_RECTANGLE_NV) {
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 );
}
}
}
else {
newTexObj = (*ctx->Driver.NewTextureObject)(ctx, texName, target);
if (!newTexObj) {
_mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindTexture");
return;
}
_glthread_LOCK_MUTEX(ctx->Shared->Mutex);
_mesa_HashInsert(ctx->Shared->TexObjects, texName, newTexObj);
_glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
}
newTexObj->Target = target;
}
assert(valid_texture_object(newTexObj));
FLUSH_VERTICES(ctx, _NEW_TEXTURE);
switch (target) {
case GL_TEXTURE_1D:
_mesa_reference_texobj(&texUnit->Current1D, newTexObj);
break;
case GL_TEXTURE_2D:
_mesa_reference_texobj(&texUnit->Current2D, newTexObj);
break;
case GL_TEXTURE_3D:
_mesa_reference_texobj(&texUnit->Current3D, newTexObj);
break;
case GL_TEXTURE_CUBE_MAP_ARB:
_mesa_reference_texobj(&texUnit->CurrentCubeMap, newTexObj);
break;
case GL_TEXTURE_RECTANGLE_NV:
_mesa_reference_texobj(&texUnit->CurrentRect, newTexObj);
break;
default:
_mesa_problem(ctx, "bad target in BindTexture");
return;
}
if (ctx->Driver.BindTexture)
(*ctx->Driver.BindTexture)( ctx, target, newTexObj );
}
void GLAPIENTRY
_mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
const GLclampf *priorities )
{
GET_CURRENT_CONTEXT(ctx);
GLint i;
ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
if (n < 0) {
_mesa_error( ctx, GL_INVALID_VALUE, "glPrioritizeTextures" );
return;
}
if (!priorities)
return;
for (i = 0; i < n; i++) {
if (texName[i] > 0) {
struct gl_texture_object *t = _mesa_lookup_texture(ctx, texName[i]);
if (t) {
t->Priority = CLAMP( priorities[i], 0.0F, 1.0F );
if (ctx->Driver.PrioritizeTexture)
ctx->Driver.PrioritizeTexture( ctx, t, t->Priority );
}
}
}
ctx->NewState |= _NEW_TEXTURE;
}
GLboolean GLAPIENTRY
_mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
GLboolean *residences)
{
GET_CURRENT_CONTEXT(ctx);
GLboolean allResident = GL_TRUE;
GLint i, j;
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
if (n < 0) {
_mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)");
return GL_FALSE;
}
if (!texName || !residences)
return GL_FALSE;
for (i = 0; i < n; i++) {
struct gl_texture_object *t;
if (texName[i] == 0) {
_mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident");
return GL_FALSE;
}
t = _mesa_lookup_texture(ctx, texName[i]);
if (!t) {
_mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident");
return GL_FALSE;
}
if (!ctx->Driver.IsTextureResident ||
ctx->Driver.IsTextureResident(ctx, t)) {
if (!allResident)
residences[i] = GL_TRUE;
}
else {
if (allResident) {
allResident = GL_FALSE;
for (j = 0; j < i; j++)
residences[j] = GL_TRUE;
}
residences[i] = GL_FALSE;
}
}
return allResident;
}
GLboolean GLAPIENTRY
_mesa_IsTexture( GLuint texture )
{
struct gl_texture_object *t;
GET_CURRENT_CONTEXT(ctx);
ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
if (!texture)
return GL_FALSE;
t = _mesa_lookup_texture(ctx, texture);
return t && t->Target;
}
void _mesa_lock_context_textures( GLcontext *ctx )
{
_glthread_LOCK_MUTEX(ctx->Shared->TexMutex);
if (ctx->Shared->TextureStateStamp != ctx->TextureStateTimestamp) {
ctx->NewState |= _NEW_TEXTURE;
ctx->TextureStateTimestamp = ctx->Shared->TextureStateStamp;
}
}
void _mesa_unlock_context_textures( GLcontext *ctx )
{
assert(ctx->Shared->TextureStateStamp == ctx->TextureStateTimestamp);
_glthread_UNLOCK_MUTEX(ctx->Shared->TexMutex);
}