mesa: Remove unnecessary parameters from TexImage
[mesa.git] / src / mesa / main / texobj.c
1 /**
2 * \file texobj.c
3 * Texture object management.
4 */
5
6 /*
7 * Mesa 3-D graphics library
8 * Version: 7.1
9 *
10 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
11 *
12 * Permission is hereby granted, free of charge, to any person obtaining a
13 * copy of this software and associated documentation files (the "Software"),
14 * to deal in the Software without restriction, including without limitation
15 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 * and/or sell copies of the Software, and to permit persons to whom the
17 * Software is furnished to do so, subject to the following conditions:
18 *
19 * The above copyright notice and this permission notice shall be included
20 * in all copies or substantial portions of the Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
26 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 */
29
30
31 #include "mfeatures.h"
32 #include "bufferobj.h"
33 #include "colortab.h"
34 #include "context.h"
35 #include "enums.h"
36 #include "fbobject.h"
37 #include "formats.h"
38 #include "hash.h"
39 #include "imports.h"
40 #include "macros.h"
41 #include "teximage.h"
42 #include "texobj.h"
43 #include "texstate.h"
44 #include "mtypes.h"
45 #include "program/prog_instruction.h"
46
47
48
49 /**********************************************************************/
50 /** \name Internal functions */
51 /*@{*/
52
53
54 /**
55 * Return the gl_texture_object for a given ID.
56 */
57 struct gl_texture_object *
58 _mesa_lookup_texture(struct gl_context *ctx, GLuint id)
59 {
60 return (struct gl_texture_object *)
61 _mesa_HashLookup(ctx->Shared->TexObjects, id);
62 }
63
64
65
66 /**
67 * Allocate and initialize a new texture object. But don't put it into the
68 * texture object hash table.
69 *
70 * Called via ctx->Driver.NewTextureObject, unless overridden by a device
71 * driver.
72 *
73 * \param shared the shared GL state structure to contain the texture object
74 * \param name integer name for the texture object
75 * \param target either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
76 * GL_TEXTURE_CUBE_MAP_ARB or GL_TEXTURE_RECTANGLE_NV. zero is ok for the sake
77 * of GenTextures()
78 *
79 * \return pointer to new texture object.
80 */
81 struct gl_texture_object *
82 _mesa_new_texture_object( struct gl_context *ctx, GLuint name, GLenum target )
83 {
84 struct gl_texture_object *obj;
85 (void) ctx;
86 obj = MALLOC_STRUCT(gl_texture_object);
87 _mesa_initialize_texture_object(obj, name, target);
88 return obj;
89 }
90
91
92 /**
93 * Initialize a new texture object to default values.
94 * \param obj the texture object
95 * \param name the texture name
96 * \param target the texture target
97 */
98 void
99 _mesa_initialize_texture_object( struct gl_texture_object *obj,
100 GLuint name, GLenum target )
101 {
102 ASSERT(target == 0 ||
103 target == GL_TEXTURE_1D ||
104 target == GL_TEXTURE_2D ||
105 target == GL_TEXTURE_3D ||
106 target == GL_TEXTURE_CUBE_MAP_ARB ||
107 target == GL_TEXTURE_RECTANGLE_NV ||
108 target == GL_TEXTURE_1D_ARRAY_EXT ||
109 target == GL_TEXTURE_2D_ARRAY_EXT ||
110 target == GL_TEXTURE_EXTERNAL_OES ||
111 target == GL_TEXTURE_BUFFER);
112
113 memset(obj, 0, sizeof(*obj));
114 /* init the non-zero fields */
115 _glthread_INIT_MUTEX(obj->Mutex);
116 obj->RefCount = 1;
117 obj->Name = name;
118 obj->Target = target;
119 obj->Priority = 1.0F;
120 obj->BaseLevel = 0;
121 obj->MaxLevel = 1000;
122
123 /* must be one; no support for (YUV) planes in separate buffers */
124 obj->RequiredTextureImageUnits = 1;
125
126 /* sampler state */
127 if (target == GL_TEXTURE_RECTANGLE_NV ||
128 target == GL_TEXTURE_EXTERNAL_OES) {
129 obj->Sampler.WrapS = GL_CLAMP_TO_EDGE;
130 obj->Sampler.WrapT = GL_CLAMP_TO_EDGE;
131 obj->Sampler.WrapR = GL_CLAMP_TO_EDGE;
132 obj->Sampler.MinFilter = GL_LINEAR;
133 }
134 else {
135 obj->Sampler.WrapS = GL_REPEAT;
136 obj->Sampler.WrapT = GL_REPEAT;
137 obj->Sampler.WrapR = GL_REPEAT;
138 obj->Sampler.MinFilter = GL_NEAREST_MIPMAP_LINEAR;
139 }
140 obj->Sampler.MagFilter = GL_LINEAR;
141 obj->Sampler.MinLod = -1000.0;
142 obj->Sampler.MaxLod = 1000.0;
143 obj->Sampler.LodBias = 0.0;
144 obj->Sampler.MaxAnisotropy = 1.0;
145 obj->Sampler.CompareMode = GL_NONE; /* ARB_shadow */
146 obj->Sampler.CompareFunc = GL_LEQUAL; /* ARB_shadow */
147 obj->Sampler.CompareFailValue = 0.0F; /* ARB_shadow_ambient */
148 obj->DepthMode = GL_LUMINANCE;
149 obj->Sampler.CubeMapSeamless = GL_FALSE;
150 obj->Swizzle[0] = GL_RED;
151 obj->Swizzle[1] = GL_GREEN;
152 obj->Swizzle[2] = GL_BLUE;
153 obj->Swizzle[3] = GL_ALPHA;
154 obj->_Swizzle = SWIZZLE_NOOP;
155 obj->Sampler.sRGBDecode = GL_DECODE_EXT;
156 obj->BufferObjectFormat = GL_LUMINANCE8;
157 obj->_BufferObjectFormat = MESA_FORMAT_L8;
158 }
159
160
161 /**
162 * Some texture initialization can't be finished until we know which
163 * target it's getting bound to (GL_TEXTURE_1D/2D/etc).
164 */
165 static void
166 finish_texture_init(struct gl_context *ctx, GLenum target,
167 struct gl_texture_object *obj)
168 {
169 assert(obj->Target == 0);
170
171 if (target == GL_TEXTURE_RECTANGLE_NV ||
172 target == GL_TEXTURE_EXTERNAL_OES) {
173 /* have to init wrap and filter state here - kind of klunky */
174 obj->Sampler.WrapS = GL_CLAMP_TO_EDGE;
175 obj->Sampler.WrapT = GL_CLAMP_TO_EDGE;
176 obj->Sampler.WrapR = GL_CLAMP_TO_EDGE;
177 obj->Sampler.MinFilter = GL_LINEAR;
178 if (ctx->Driver.TexParameter) {
179 static const GLfloat fparam_wrap[1] = {(GLfloat) GL_CLAMP_TO_EDGE};
180 static const GLfloat fparam_filter[1] = {(GLfloat) GL_LINEAR};
181 ctx->Driver.TexParameter(ctx, target, obj, GL_TEXTURE_WRAP_S, fparam_wrap);
182 ctx->Driver.TexParameter(ctx, target, obj, GL_TEXTURE_WRAP_T, fparam_wrap);
183 ctx->Driver.TexParameter(ctx, target, obj, GL_TEXTURE_WRAP_R, fparam_wrap);
184 ctx->Driver.TexParameter(ctx, target, obj, GL_TEXTURE_MIN_FILTER, fparam_filter);
185 }
186 }
187 }
188
189
190 /**
191 * Deallocate a texture object struct. It should have already been
192 * removed from the texture object pool.
193 * Called via ctx->Driver.DeleteTexture() if not overriden by a driver.
194 *
195 * \param shared the shared GL state to which the object belongs.
196 * \param texObj the texture object to delete.
197 */
198 void
199 _mesa_delete_texture_object(struct gl_context *ctx,
200 struct gl_texture_object *texObj)
201 {
202 GLuint i, face;
203
204 /* Set Target to an invalid value. With some assertions elsewhere
205 * we can try to detect possible use of deleted textures.
206 */
207 texObj->Target = 0x99;
208
209 /* free the texture images */
210 for (face = 0; face < 6; face++) {
211 for (i = 0; i < MAX_TEXTURE_LEVELS; i++) {
212 if (texObj->Image[face][i]) {
213 ctx->Driver.DeleteTextureImage(ctx, texObj->Image[face][i]);
214 }
215 }
216 }
217
218 _mesa_reference_buffer_object(ctx, &texObj->BufferObject, NULL);
219
220 /* destroy the mutex -- it may have allocated memory (eg on bsd) */
221 _glthread_DESTROY_MUTEX(texObj->Mutex);
222
223 /* free this object */
224 free(texObj);
225 }
226
227
228
229 /**
230 * Copy texture object state from one texture object to another.
231 * Use for glPush/PopAttrib.
232 *
233 * \param dest destination texture object.
234 * \param src source texture object.
235 */
236 void
237 _mesa_copy_texture_object( struct gl_texture_object *dest,
238 const struct gl_texture_object *src )
239 {
240 dest->Target = src->Target;
241 dest->Name = src->Name;
242 dest->Priority = src->Priority;
243 dest->Sampler.BorderColor.f[0] = src->Sampler.BorderColor.f[0];
244 dest->Sampler.BorderColor.f[1] = src->Sampler.BorderColor.f[1];
245 dest->Sampler.BorderColor.f[2] = src->Sampler.BorderColor.f[2];
246 dest->Sampler.BorderColor.f[3] = src->Sampler.BorderColor.f[3];
247 dest->Sampler.WrapS = src->Sampler.WrapS;
248 dest->Sampler.WrapT = src->Sampler.WrapT;
249 dest->Sampler.WrapR = src->Sampler.WrapR;
250 dest->Sampler.MinFilter = src->Sampler.MinFilter;
251 dest->Sampler.MagFilter = src->Sampler.MagFilter;
252 dest->Sampler.MinLod = src->Sampler.MinLod;
253 dest->Sampler.MaxLod = src->Sampler.MaxLod;
254 dest->Sampler.LodBias = src->Sampler.LodBias;
255 dest->BaseLevel = src->BaseLevel;
256 dest->MaxLevel = src->MaxLevel;
257 dest->Sampler.MaxAnisotropy = src->Sampler.MaxAnisotropy;
258 dest->Sampler.CompareMode = src->Sampler.CompareMode;
259 dest->Sampler.CompareFunc = src->Sampler.CompareFunc;
260 dest->Sampler.CompareFailValue = src->Sampler.CompareFailValue;
261 dest->Sampler.CubeMapSeamless = src->Sampler.CubeMapSeamless;
262 dest->DepthMode = src->DepthMode;
263 dest->Sampler.sRGBDecode = src->Sampler.sRGBDecode;
264 dest->_MaxLevel = src->_MaxLevel;
265 dest->_MaxLambda = src->_MaxLambda;
266 dest->GenerateMipmap = src->GenerateMipmap;
267 dest->_BaseComplete = src->_BaseComplete;
268 dest->_MipmapComplete = src->_MipmapComplete;
269 COPY_4V(dest->Swizzle, src->Swizzle);
270 dest->_Swizzle = src->_Swizzle;
271
272 dest->RequiredTextureImageUnits = src->RequiredTextureImageUnits;
273 }
274
275
276 /**
277 * Free all texture images of the given texture object.
278 *
279 * \param ctx GL context.
280 * \param t texture object.
281 *
282 * \sa _mesa_clear_texture_image().
283 */
284 void
285 _mesa_clear_texture_object(struct gl_context *ctx,
286 struct gl_texture_object *texObj)
287 {
288 GLuint i, j;
289
290 if (texObj->Target == 0)
291 return;
292
293 for (i = 0; i < MAX_FACES; i++) {
294 for (j = 0; j < MAX_TEXTURE_LEVELS; j++) {
295 struct gl_texture_image *texImage = texObj->Image[i][j];
296 if (texImage)
297 _mesa_clear_texture_image(ctx, texImage);
298 }
299 }
300 }
301
302
303 /**
304 * Check if the given texture object is valid by examining its Target field.
305 * For debugging only.
306 */
307 static GLboolean
308 valid_texture_object(const struct gl_texture_object *tex)
309 {
310 switch (tex->Target) {
311 case 0:
312 case GL_TEXTURE_1D:
313 case GL_TEXTURE_2D:
314 case GL_TEXTURE_3D:
315 case GL_TEXTURE_CUBE_MAP_ARB:
316 case GL_TEXTURE_RECTANGLE_NV:
317 case GL_TEXTURE_1D_ARRAY_EXT:
318 case GL_TEXTURE_2D_ARRAY_EXT:
319 case GL_TEXTURE_BUFFER:
320 case GL_TEXTURE_EXTERNAL_OES:
321 return GL_TRUE;
322 case 0x99:
323 _mesa_problem(NULL, "invalid reference to a deleted texture object");
324 return GL_FALSE;
325 default:
326 _mesa_problem(NULL, "invalid texture object Target 0x%x, Id = %u",
327 tex->Target, tex->Name);
328 return GL_FALSE;
329 }
330 }
331
332
333 /**
334 * Reference (or unreference) a texture object.
335 * If '*ptr', decrement *ptr's refcount (and delete if it becomes zero).
336 * If 'tex' is non-null, increment its refcount.
337 * This is normally only called from the _mesa_reference_texobj() macro
338 * when there's a real pointer change.
339 */
340 void
341 _mesa_reference_texobj_(struct gl_texture_object **ptr,
342 struct gl_texture_object *tex)
343 {
344 assert(ptr);
345
346 if (*ptr) {
347 /* Unreference the old texture */
348 GLboolean deleteFlag = GL_FALSE;
349 struct gl_texture_object *oldTex = *ptr;
350
351 ASSERT(valid_texture_object(oldTex));
352 (void) valid_texture_object; /* silence warning in release builds */
353
354 _glthread_LOCK_MUTEX(oldTex->Mutex);
355 ASSERT(oldTex->RefCount > 0);
356 oldTex->RefCount--;
357
358 deleteFlag = (oldTex->RefCount == 0);
359 _glthread_UNLOCK_MUTEX(oldTex->Mutex);
360
361 if (deleteFlag) {
362 GET_CURRENT_CONTEXT(ctx);
363 if (ctx)
364 ctx->Driver.DeleteTexture(ctx, oldTex);
365 else
366 _mesa_problem(NULL, "Unable to delete texture, no context");
367 }
368
369 *ptr = NULL;
370 }
371 assert(!*ptr);
372
373 if (tex) {
374 /* reference new texture */
375 ASSERT(valid_texture_object(tex));
376 _glthread_LOCK_MUTEX(tex->Mutex);
377 if (tex->RefCount == 0) {
378 /* this texture's being deleted (look just above) */
379 /* Not sure this can every really happen. Warn if it does. */
380 _mesa_problem(NULL, "referencing deleted texture object");
381 *ptr = NULL;
382 }
383 else {
384 tex->RefCount++;
385 *ptr = tex;
386 }
387 _glthread_UNLOCK_MUTEX(tex->Mutex);
388 }
389 }
390
391
392 enum base_mipmap { BASE, MIPMAP };
393
394
395 /**
396 * Mark a texture object as incomplete. There are actually three kinds of
397 * (in)completeness:
398 * 1. "base incomplete": the base level of the texture is invalid so no
399 * texturing is possible.
400 * 2. "mipmap incomplete": a non-base level of the texture is invalid so
401 * mipmap filtering isn't possible, but non-mipmap filtering is.
402 * 3. "texture incompleteness": some combination of texture state and
403 * sampler state renders the texture incomplete.
404 *
405 * \param t texture object
406 * \param bm either BASE or MIPMAP to indicate what's incomplete
407 * \param fmt... string describing why it's incomplete (for debugging).
408 */
409 static void
410 incomplete(struct gl_texture_object *t, enum base_mipmap bm,
411 const char *fmt, ...)
412 {
413 if (MESA_DEBUG_FLAGS & DEBUG_INCOMPLETE_TEXTURE) {
414 va_list args;
415 char s[100];
416
417 va_start(args, fmt);
418 vsnprintf(s, sizeof(s), fmt, args);
419 va_end(args);
420
421 _mesa_debug(NULL, "Texture Obj %d incomplete because: %s\n", t->Name, s);
422 }
423
424 if (bm == BASE)
425 t->_BaseComplete = GL_FALSE;
426 t->_MipmapComplete = GL_FALSE;
427 }
428
429
430 /**
431 * Examine a texture object to determine if it is complete.
432 *
433 * The gl_texture_object::Complete flag will be set to GL_TRUE or GL_FALSE
434 * accordingly.
435 *
436 * \param ctx GL context.
437 * \param t texture object.
438 *
439 * According to the texture target, verifies that each of the mipmaps is
440 * present and has the expected size.
441 */
442 void
443 _mesa_test_texobj_completeness( const struct gl_context *ctx,
444 struct gl_texture_object *t )
445 {
446 const GLint baseLevel = t->BaseLevel;
447 const struct gl_texture_image *baseImage;
448 GLint maxLog2 = 0, maxLevels = 0;
449
450 /* We'll set these to FALSE if tests fail below */
451 t->_BaseComplete = GL_TRUE;
452 t->_MipmapComplete = GL_TRUE;
453
454 if (t->Target == GL_TEXTURE_BUFFER) {
455 /* Buffer textures are always considered complete. The obvious case where
456 * they would be incomplete (no BO attached) is actually specced to be
457 * undefined rendering results.
458 */
459 return;
460 }
461
462 /* Detect cases where the application set the base level to an invalid
463 * value.
464 */
465 if ((baseLevel < 0) || (baseLevel >= MAX_TEXTURE_LEVELS)) {
466 incomplete(t, BASE, "base level = %d is invalid", baseLevel);
467 return;
468 }
469
470 if (t->MaxLevel < baseLevel) {
471 incomplete(t, BASE, "MAX_LEVEL (%d) < BASE_LEVEL (%d)",
472 t->MaxLevel, baseLevel);
473 return;
474 }
475
476 baseImage = t->Image[0][baseLevel];
477
478 /* Always need the base level image */
479 if (!baseImage) {
480 incomplete(t, BASE, "Image[baseLevel=%d] == NULL", baseLevel);
481 return;
482 }
483
484 /* Check width/height/depth for zero */
485 if (baseImage->Width == 0 ||
486 baseImage->Height == 0 ||
487 baseImage->Depth == 0) {
488 incomplete(t, BASE, "texture width or height or depth = 0");
489 return;
490 }
491
492 /* Check if the texture values are integer */
493 {
494 GLenum datatype = _mesa_get_format_datatype(baseImage->TexFormat);
495 t->_IsIntegerFormat = datatype == GL_INT || datatype == GL_UNSIGNED_INT;
496 }
497
498 /* Compute _MaxLevel (the maximum mipmap level we'll sample from given the
499 * mipmap image sizes and GL_TEXTURE_MAX_LEVEL state).
500 */
501 switch (t->Target) {
502 case GL_TEXTURE_1D:
503 case GL_TEXTURE_1D_ARRAY_EXT:
504 maxLog2 = baseImage->WidthLog2;
505 maxLevels = ctx->Const.MaxTextureLevels;
506 break;
507 case GL_TEXTURE_2D:
508 case GL_TEXTURE_2D_ARRAY_EXT:
509 maxLog2 = MAX2(baseImage->WidthLog2,
510 baseImage->HeightLog2);
511 maxLevels = ctx->Const.MaxTextureLevels;
512 break;
513 case GL_TEXTURE_3D:
514 maxLog2 = MAX3(baseImage->WidthLog2,
515 baseImage->HeightLog2,
516 baseImage->DepthLog2);
517 maxLevels = ctx->Const.Max3DTextureLevels;
518 break;
519 case GL_TEXTURE_CUBE_MAP_ARB:
520 maxLog2 = MAX2(baseImage->WidthLog2,
521 baseImage->HeightLog2);
522 maxLevels = ctx->Const.MaxCubeTextureLevels;
523 break;
524 case GL_TEXTURE_RECTANGLE_NV:
525 case GL_TEXTURE_BUFFER:
526 case GL_TEXTURE_EXTERNAL_OES:
527 maxLog2 = 0; /* not applicable */
528 maxLevels = 1; /* no mipmapping */
529 break;
530 default:
531 _mesa_problem(ctx, "Bad t->Target in _mesa_test_texobj_completeness");
532 return;
533 }
534
535 ASSERT(maxLevels > 0);
536
537 t->_MaxLevel = baseLevel + maxLog2; /* 'p' in the GL spec */
538 t->_MaxLevel = MIN2(t->_MaxLevel, t->MaxLevel);
539 t->_MaxLevel = MIN2(t->_MaxLevel, maxLevels - 1); /* 'q' in the GL spec */
540
541 /* Compute _MaxLambda = q - b (see the 1.2 spec) used during mipmapping */
542 t->_MaxLambda = (GLfloat) (t->_MaxLevel - baseLevel);
543
544 if (t->Immutable) {
545 /* This texture object was created with glTexStorage1/2/3D() so we
546 * know that all the mipmap levels are the right size and all cube
547 * map faces are the same size.
548 * We don't need to do any of the additional checks below.
549 */
550 return;
551 }
552
553 if (t->Target == GL_TEXTURE_CUBE_MAP_ARB) {
554 /* Make sure that all six cube map level 0 images are the same size.
555 * Note: we know that the image's width==height (we enforce that
556 * at glTexImage time) so we only need to test the width here.
557 */
558 GLuint face;
559 assert(baseImage->Width2 == baseImage->Height);
560 for (face = 1; face < 6; face++) {
561 assert(t->Image[face][baseLevel] == NULL ||
562 t->Image[face][baseLevel]->Width2 ==
563 t->Image[face][baseLevel]->Height2);
564 if (t->Image[face][baseLevel] == NULL ||
565 t->Image[face][baseLevel]->Width2 != baseImage->Width2) {
566 incomplete(t, BASE, "Cube face missing or mismatched size");
567 return;
568 }
569 }
570 }
571
572 /*
573 * Do mipmap consistency checking.
574 * Note: we don't care about the current texture sampler state here.
575 * To determine texture completeness we'll either look at _BaseComplete
576 * or _MipmapComplete depending on the current minification filter mode.
577 */
578 {
579 GLint i;
580 const GLint minLevel = baseLevel;
581 const GLint maxLevel = t->_MaxLevel;
582 const GLuint numFaces = t->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
583 GLuint width, height, depth, face;
584
585 if (minLevel > maxLevel) {
586 incomplete(t, BASE, "minLevel > maxLevel");
587 return;
588 }
589
590 /* Get the base image's dimensions */
591 width = baseImage->Width2;
592 height = baseImage->Height2;
593 depth = baseImage->Depth2;
594
595 /* Note: this loop will be a no-op for RECT, BUFFER, EXTERNAL textures */
596 for (i = baseLevel + 1; i < maxLevels; i++) {
597 /* Compute the expected size of image at level[i] */
598 if (width > 1) {
599 width /= 2;
600 }
601 if (height > 1 && t->Target != GL_TEXTURE_1D_ARRAY) {
602 height /= 2;
603 }
604 if (depth > 1 && t->Target != GL_TEXTURE_2D_ARRAY) {
605 depth /= 2;
606 }
607
608 /* loop over cube faces (or single face otherwise) */
609 for (face = 0; face < numFaces; face++) {
610 if (i >= minLevel && i <= maxLevel) {
611 const struct gl_texture_image *img = t->Image[face][i];
612
613 if (!img) {
614 incomplete(t, MIPMAP, "TexImage[%d] is missing", i);
615 return;
616 }
617 if (img->TexFormat != baseImage->TexFormat) {
618 incomplete(t, MIPMAP, "Format[i] != Format[baseLevel]");
619 return;
620 }
621 if (img->Border != baseImage->Border) {
622 incomplete(t, MIPMAP, "Border[i] != Border[baseLevel]");
623 return;
624 }
625 if (img->Width2 != width) {
626 incomplete(t, MIPMAP, "TexImage[%d] bad width %u", i, img->Width2);
627 return;
628 }
629 if (img->Height2 != height) {
630 incomplete(t, MIPMAP, "TexImage[%d] bad height %u", i, img->Height2);
631 return;
632 }
633 if (img->Depth2 != depth) {
634 incomplete(t, MIPMAP, "TexImage[%d] bad depth %u", i, img->Depth2);
635 return;
636 }
637
638 /* Extra checks for cube textures */
639 if (face > 0) {
640 /* check that cube faces are the same size */
641 if (img->Width2 != t->Image[0][i]->Width2 ||
642 img->Height2 != t->Image[0][i]->Height2) {
643 incomplete(t, MIPMAP, "CubeMap Image[n][i] bad size");
644 return;
645 }
646 }
647 }
648 }
649
650 if (width == 1 && height == 1 && depth == 1) {
651 return; /* found smallest needed mipmap, all done! */
652 }
653 }
654 }
655 }
656
657
658 /**
659 * Check if the given cube map texture is "cube complete" as defined in
660 * the OpenGL specification.
661 */
662 GLboolean
663 _mesa_cube_complete(const struct gl_texture_object *texObj)
664 {
665 const GLint baseLevel = texObj->BaseLevel;
666 const struct gl_texture_image *img0, *img;
667 GLuint face;
668
669 if (texObj->Target != GL_TEXTURE_CUBE_MAP)
670 return GL_FALSE;
671
672 if ((baseLevel < 0) || (baseLevel >= MAX_TEXTURE_LEVELS))
673 return GL_FALSE;
674
675 /* check first face */
676 img0 = texObj->Image[0][baseLevel];
677 if (!img0 ||
678 img0->Width < 1 ||
679 img0->Width != img0->Height)
680 return GL_FALSE;
681
682 /* check remaining faces vs. first face */
683 for (face = 1; face < 6; face++) {
684 img = texObj->Image[face][baseLevel];
685 if (!img ||
686 img->Width != img0->Width ||
687 img->Height != img0->Height ||
688 img->TexFormat != img0->TexFormat)
689 return GL_FALSE;
690 }
691
692 return GL_TRUE;
693 }
694
695
696 /**
697 * Mark a texture object dirty. It forces the object to be incomplete
698 * and optionally forces the context to re-validate its state.
699 *
700 * \param ctx GL context.
701 * \param texObj texture object.
702 * \param invalidate_state also invalidate context state.
703 */
704 void
705 _mesa_dirty_texobj(struct gl_context *ctx, struct gl_texture_object *texObj,
706 GLboolean invalidate_state)
707 {
708 texObj->_BaseComplete = GL_FALSE;
709 texObj->_MipmapComplete = GL_FALSE;
710 if (invalidate_state)
711 ctx->NewState |= _NEW_TEXTURE;
712 }
713
714
715 /**
716 * Return pointer to a default/fallback texture of the given type/target.
717 * The texture is an RGBA texture with all texels = (0,0,0,1).
718 * That's the value a GLSL sampler should get when sampling from an
719 * incomplete texture.
720 */
721 struct gl_texture_object *
722 _mesa_get_fallback_texture(struct gl_context *ctx, gl_texture_index tex)
723 {
724 if (!ctx->Shared->FallbackTex[tex]) {
725 /* create fallback texture now */
726 const GLsizei width = 1, height = 1, depth = 1;
727 GLubyte texel[4];
728 struct gl_texture_object *texObj;
729 struct gl_texture_image *texImage;
730 gl_format texFormat;
731 GLuint dims, face, numFaces = 1;
732 GLenum target;
733
734 texel[0] =
735 texel[1] =
736 texel[2] = 0x0;
737 texel[3] = 0xff;
738
739 switch (tex) {
740 case TEXTURE_2D_ARRAY_INDEX:
741 dims = 3;
742 target = GL_TEXTURE_2D_ARRAY;
743 break;
744 case TEXTURE_1D_ARRAY_INDEX:
745 dims = 2;
746 target = GL_TEXTURE_1D_ARRAY;
747 break;
748 case TEXTURE_CUBE_INDEX:
749 dims = 2;
750 target = GL_TEXTURE_CUBE_MAP;
751 numFaces = 6;
752 break;
753 case TEXTURE_3D_INDEX:
754 dims = 3;
755 target = GL_TEXTURE_3D;
756 break;
757 case TEXTURE_RECT_INDEX:
758 dims = 2;
759 target = GL_TEXTURE_RECTANGLE;
760 break;
761 case TEXTURE_2D_INDEX:
762 dims = 2;
763 target = GL_TEXTURE_2D;
764 break;
765 case TEXTURE_1D_INDEX:
766 dims = 1;
767 target = GL_TEXTURE_1D;
768 break;
769 case TEXTURE_BUFFER_INDEX:
770 dims = 0;
771 target = GL_TEXTURE_BUFFER;
772 break;
773 case TEXTURE_EXTERNAL_INDEX:
774 default:
775 /* no-op */
776 return NULL;
777 }
778
779 /* create texture object */
780 texObj = ctx->Driver.NewTextureObject(ctx, 0, target);
781 if (!texObj)
782 return NULL;
783
784 assert(texObj->RefCount == 1);
785 texObj->Sampler.MinFilter = GL_NEAREST;
786 texObj->Sampler.MagFilter = GL_NEAREST;
787
788 texFormat = ctx->Driver.ChooseTextureFormat(ctx, GL_RGBA, GL_RGBA,
789 GL_UNSIGNED_BYTE);
790
791 /* need a loop here just for cube maps */
792 for (face = 0; face < numFaces; face++) {
793 GLenum faceTarget;
794
795 if (target == GL_TEXTURE_CUBE_MAP)
796 faceTarget = GL_TEXTURE_CUBE_MAP_POSITIVE_X + face;
797 else
798 faceTarget = target;
799
800 /* initialize level[0] texture image */
801 texImage = _mesa_get_tex_image(ctx, texObj, faceTarget, 0);
802
803 _mesa_init_teximage_fields(ctx, texImage,
804 width,
805 (dims > 1) ? height : 1,
806 (dims > 2) ? depth : 1,
807 0, /* border */
808 GL_RGBA, texFormat);
809
810 ctx->Driver.TexImage(ctx, dims, texImage,
811 GL_RGBA, GL_UNSIGNED_BYTE, texel,
812 &ctx->DefaultPacking);
813 }
814
815 _mesa_test_texobj_completeness(ctx, texObj);
816 assert(texObj->_BaseComplete);
817 assert(texObj->_MipmapComplete);
818
819 ctx->Shared->FallbackTex[tex] = texObj;
820 }
821 return ctx->Shared->FallbackTex[tex];
822 }
823
824
825 /**
826 * Compute the size of the given texture object, in bytes.
827 */
828 static GLuint
829 texture_size(const struct gl_texture_object *texObj)
830 {
831 const GLuint numFaces = texObj->Target == GL_TEXTURE_CUBE_MAP ? 6 : 1;
832 GLuint face, level, size = 0;
833
834 for (face = 0; face < numFaces; face++) {
835 for (level = 0; level < MAX_TEXTURE_LEVELS; level++) {
836 const struct gl_texture_image *img = texObj->Image[face][level];
837 if (img) {
838 GLuint sz = _mesa_format_image_size(img->TexFormat, img->Width,
839 img->Height, img->Depth);
840 size += sz;
841 }
842 }
843 }
844
845 return size;
846 }
847
848
849 /**
850 * Callback called from _mesa_HashWalk()
851 */
852 static void
853 count_tex_size(GLuint key, void *data, void *userData)
854 {
855 const struct gl_texture_object *texObj =
856 (const struct gl_texture_object *) data;
857 GLuint *total = (GLuint *) userData;
858
859 *total = *total + texture_size(texObj);
860 }
861
862
863 /**
864 * Compute total size (in bytes) of all textures for the given context.
865 * For debugging purposes.
866 */
867 GLuint
868 _mesa_total_texture_memory(struct gl_context *ctx)
869 {
870 GLuint tgt, total = 0;
871
872 _mesa_HashWalk(ctx->Shared->TexObjects, count_tex_size, &total);
873
874 /* plus, the default texture objects */
875 for (tgt = 0; tgt < NUM_TEXTURE_TARGETS; tgt++) {
876 total += texture_size(ctx->Shared->DefaultTex[tgt]);
877 }
878
879 return total;
880 }
881
882
883
884 /*@}*/
885
886
887 /***********************************************************************/
888 /** \name API functions */
889 /*@{*/
890
891
892 /**
893 * Generate texture names.
894 *
895 * \param n number of texture names to be generated.
896 * \param textures an array in which will hold the generated texture names.
897 *
898 * \sa glGenTextures().
899 *
900 * Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture
901 * IDs which are stored in \p textures. Corresponding empty texture
902 * objects are also generated.
903 */
904 void GLAPIENTRY
905 _mesa_GenTextures( GLsizei n, GLuint *textures )
906 {
907 GET_CURRENT_CONTEXT(ctx);
908 GLuint first;
909 GLint i;
910 ASSERT_OUTSIDE_BEGIN_END(ctx);
911
912 if (n < 0) {
913 _mesa_error( ctx, GL_INVALID_VALUE, "glGenTextures" );
914 return;
915 }
916
917 if (!textures)
918 return;
919
920 /*
921 * This must be atomic (generation and allocation of texture IDs)
922 */
923 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
924
925 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
926
927 /* Allocate new, empty texture objects */
928 for (i = 0; i < n; i++) {
929 struct gl_texture_object *texObj;
930 GLuint name = first + i;
931 GLenum target = 0;
932 texObj = ctx->Driver.NewTextureObject(ctx, name, target);
933 if (!texObj) {
934 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
935 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glGenTextures");
936 return;
937 }
938
939 /* insert into hash table */
940 _mesa_HashInsert(ctx->Shared->TexObjects, texObj->Name, texObj);
941
942 textures[i] = name;
943 }
944
945 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
946 }
947
948
949 /**
950 * Check if the given texture object is bound to the current draw or
951 * read framebuffer. If so, Unbind it.
952 */
953 static void
954 unbind_texobj_from_fbo(struct gl_context *ctx,
955 struct gl_texture_object *texObj)
956 {
957 const GLuint n = (ctx->DrawBuffer == ctx->ReadBuffer) ? 1 : 2;
958 GLuint i;
959
960 for (i = 0; i < n; i++) {
961 struct gl_framebuffer *fb = (i == 0) ? ctx->DrawBuffer : ctx->ReadBuffer;
962 if (_mesa_is_user_fbo(fb)) {
963 GLuint j;
964 for (j = 0; j < BUFFER_COUNT; j++) {
965 if (fb->Attachment[j].Type == GL_TEXTURE &&
966 fb->Attachment[j].Texture == texObj) {
967 /* Vertices are already flushed by _mesa_DeleteTextures */
968 ctx->NewState |= _NEW_BUFFERS;
969 _mesa_remove_attachment(ctx, fb->Attachment + j);
970 }
971 }
972 }
973 }
974 }
975
976
977 /**
978 * Check if the given texture object is bound to any texture image units and
979 * unbind it if so (revert to default textures).
980 */
981 static void
982 unbind_texobj_from_texunits(struct gl_context *ctx,
983 struct gl_texture_object *texObj)
984 {
985 GLuint u, tex;
986
987 for (u = 0; u < Elements(ctx->Texture.Unit); u++) {
988 struct gl_texture_unit *unit = &ctx->Texture.Unit[u];
989 for (tex = 0; tex < NUM_TEXTURE_TARGETS; tex++) {
990 if (texObj == unit->CurrentTex[tex]) {
991 _mesa_reference_texobj(&unit->CurrentTex[tex],
992 ctx->Shared->DefaultTex[tex]);
993 ASSERT(unit->CurrentTex[tex]);
994 break;
995 }
996 }
997 }
998 }
999
1000
1001 /**
1002 * Delete named textures.
1003 *
1004 * \param n number of textures to be deleted.
1005 * \param textures array of texture IDs to be deleted.
1006 *
1007 * \sa glDeleteTextures().
1008 *
1009 * If we're about to delete a texture that's currently bound to any
1010 * texture unit, unbind the texture first. Decrement the reference
1011 * count on the texture object and delete it if it's zero.
1012 * Recall that texture objects can be shared among several rendering
1013 * contexts.
1014 */
1015 void GLAPIENTRY
1016 _mesa_DeleteTextures( GLsizei n, const GLuint *textures)
1017 {
1018 GET_CURRENT_CONTEXT(ctx);
1019 GLint i;
1020 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
1021
1022 if (!textures)
1023 return;
1024
1025 for (i = 0; i < n; i++) {
1026 if (textures[i] > 0) {
1027 struct gl_texture_object *delObj
1028 = _mesa_lookup_texture(ctx, textures[i]);
1029
1030 if (delObj) {
1031 _mesa_lock_texture(ctx, delObj);
1032
1033 /* Check if texture is bound to any framebuffer objects.
1034 * If so, unbind.
1035 * See section 4.4.2.3 of GL_EXT_framebuffer_object.
1036 */
1037 unbind_texobj_from_fbo(ctx, delObj);
1038
1039 /* Check if this texture is currently bound to any texture units.
1040 * If so, unbind it.
1041 */
1042 unbind_texobj_from_texunits(ctx, delObj);
1043
1044 _mesa_unlock_texture(ctx, delObj);
1045
1046 ctx->NewState |= _NEW_TEXTURE;
1047
1048 /* The texture _name_ is now free for re-use.
1049 * Remove it from the hash table now.
1050 */
1051 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1052 _mesa_HashRemove(ctx->Shared->TexObjects, delObj->Name);
1053 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1054
1055 /* Unreference the texobj. If refcount hits zero, the texture
1056 * will be deleted.
1057 */
1058 _mesa_reference_texobj(&delObj, NULL);
1059 }
1060 }
1061 }
1062 }
1063
1064
1065 /**
1066 * Convert a GL texture target enum such as GL_TEXTURE_2D or GL_TEXTURE_3D
1067 * into the corresponding Mesa texture target index.
1068 * Note that proxy targets are not valid here.
1069 * \return TEXTURE_x_INDEX or -1 if target is invalid
1070 */
1071 static GLint
1072 target_enum_to_index(GLenum target)
1073 {
1074 switch (target) {
1075 case GL_TEXTURE_1D:
1076 return TEXTURE_1D_INDEX;
1077 case GL_TEXTURE_2D:
1078 return TEXTURE_2D_INDEX;
1079 case GL_TEXTURE_3D:
1080 return TEXTURE_3D_INDEX;
1081 case GL_TEXTURE_CUBE_MAP_ARB:
1082 return TEXTURE_CUBE_INDEX;
1083 case GL_TEXTURE_RECTANGLE_NV:
1084 return TEXTURE_RECT_INDEX;
1085 case GL_TEXTURE_1D_ARRAY_EXT:
1086 return TEXTURE_1D_ARRAY_INDEX;
1087 case GL_TEXTURE_2D_ARRAY_EXT:
1088 return TEXTURE_2D_ARRAY_INDEX;
1089 case GL_TEXTURE_BUFFER_ARB:
1090 return TEXTURE_BUFFER_INDEX;
1091 case GL_TEXTURE_EXTERNAL_OES:
1092 return TEXTURE_EXTERNAL_INDEX;
1093 default:
1094 return -1;
1095 }
1096 }
1097
1098
1099 /**
1100 * Bind a named texture to a texturing target.
1101 *
1102 * \param target texture target.
1103 * \param texName texture name.
1104 *
1105 * \sa glBindTexture().
1106 *
1107 * Determines the old texture object bound and returns immediately if rebinding
1108 * the same texture. Get the current texture which is either a default texture
1109 * if name is null, a named texture from the hash, or a new texture if the
1110 * given texture name is new. Increments its reference count, binds it, and
1111 * calls dd_function_table::BindTexture. Decrements the old texture reference
1112 * count and deletes it if it reaches zero.
1113 */
1114 void GLAPIENTRY
1115 _mesa_BindTexture( GLenum target, GLuint texName )
1116 {
1117 GET_CURRENT_CONTEXT(ctx);
1118 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
1119 struct gl_texture_object *newTexObj = NULL;
1120 GLint targetIndex;
1121 ASSERT_OUTSIDE_BEGIN_END(ctx);
1122
1123 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
1124 _mesa_debug(ctx, "glBindTexture %s %d\n",
1125 _mesa_lookup_enum_by_nr(target), (GLint) texName);
1126
1127 targetIndex = target_enum_to_index(target);
1128 if (targetIndex < 0) {
1129 _mesa_error(ctx, GL_INVALID_ENUM, "glBindTexture(target)");
1130 return;
1131 }
1132 assert(targetIndex < NUM_TEXTURE_TARGETS);
1133
1134 /*
1135 * Get pointer to new texture object (newTexObj)
1136 */
1137 if (texName == 0) {
1138 /* Use a default texture object */
1139 newTexObj = ctx->Shared->DefaultTex[targetIndex];
1140 }
1141 else {
1142 /* non-default texture object */
1143 newTexObj = _mesa_lookup_texture(ctx, texName);
1144 if (newTexObj) {
1145 /* error checking */
1146 if (newTexObj->Target != 0 && newTexObj->Target != target) {
1147 /* the named texture object's target doesn't match the given target */
1148 _mesa_error( ctx, GL_INVALID_OPERATION,
1149 "glBindTexture(target mismatch)" );
1150 return;
1151 }
1152 if (newTexObj->Target == 0) {
1153 finish_texture_init(ctx, target, newTexObj);
1154 }
1155 }
1156 else {
1157 /* if this is a new texture id, allocate a texture object now */
1158 newTexObj = ctx->Driver.NewTextureObject(ctx, texName, target);
1159 if (!newTexObj) {
1160 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindTexture");
1161 return;
1162 }
1163
1164 /* and insert it into hash table */
1165 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1166 _mesa_HashInsert(ctx->Shared->TexObjects, texName, newTexObj);
1167 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1168 }
1169 newTexObj->Target = target;
1170 }
1171
1172 assert(valid_texture_object(newTexObj));
1173
1174 /* Check if this texture is only used by this context and is already bound.
1175 * If so, just return.
1176 */
1177 {
1178 GLboolean early_out;
1179 _glthread_LOCK_MUTEX(ctx->Shared->Mutex);
1180 early_out = ((ctx->Shared->RefCount == 1)
1181 && (newTexObj == texUnit->CurrentTex[targetIndex]));
1182 _glthread_UNLOCK_MUTEX(ctx->Shared->Mutex);
1183 if (early_out) {
1184 return;
1185 }
1186 }
1187
1188 /* flush before changing binding */
1189 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1190
1191 /* Do the actual binding. The refcount on the previously bound
1192 * texture object will be decremented. It'll be deleted if the
1193 * count hits zero.
1194 */
1195 _mesa_reference_texobj(&texUnit->CurrentTex[targetIndex], newTexObj);
1196 ASSERT(texUnit->CurrentTex[targetIndex]);
1197
1198 /* Pass BindTexture call to device driver */
1199 if (ctx->Driver.BindTexture)
1200 ctx->Driver.BindTexture(ctx, target, newTexObj);
1201 }
1202
1203
1204 /**
1205 * Set texture priorities.
1206 *
1207 * \param n number of textures.
1208 * \param texName texture names.
1209 * \param priorities corresponding texture priorities.
1210 *
1211 * \sa glPrioritizeTextures().
1212 *
1213 * Looks up each texture in the hash, clamps the corresponding priority between
1214 * 0.0 and 1.0, and calls dd_function_table::PrioritizeTexture.
1215 */
1216 void GLAPIENTRY
1217 _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
1218 const GLclampf *priorities )
1219 {
1220 GET_CURRENT_CONTEXT(ctx);
1221 GLint i;
1222 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
1223
1224 if (n < 0) {
1225 _mesa_error( ctx, GL_INVALID_VALUE, "glPrioritizeTextures" );
1226 return;
1227 }
1228
1229 if (!priorities)
1230 return;
1231
1232 for (i = 0; i < n; i++) {
1233 if (texName[i] > 0) {
1234 struct gl_texture_object *t = _mesa_lookup_texture(ctx, texName[i]);
1235 if (t) {
1236 t->Priority = CLAMP( priorities[i], 0.0F, 1.0F );
1237 }
1238 }
1239 }
1240
1241 ctx->NewState |= _NEW_TEXTURE;
1242 }
1243
1244
1245
1246 /**
1247 * See if textures are loaded in texture memory.
1248 *
1249 * \param n number of textures to query.
1250 * \param texName array with the texture names.
1251 * \param residences array which will hold the residence status.
1252 *
1253 * \return GL_TRUE if all textures are resident and \p residences is left unchanged,
1254 *
1255 * Note: we assume all textures are always resident
1256 */
1257 GLboolean GLAPIENTRY
1258 _mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
1259 GLboolean *residences)
1260 {
1261 GET_CURRENT_CONTEXT(ctx);
1262 GLboolean allResident = GL_TRUE;
1263 GLint i;
1264 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
1265
1266 if (n < 0) {
1267 _mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)");
1268 return GL_FALSE;
1269 }
1270
1271 if (!texName || !residences)
1272 return GL_FALSE;
1273
1274 /* We only do error checking on the texture names */
1275 for (i = 0; i < n; i++) {
1276 struct gl_texture_object *t;
1277 if (texName[i] == 0) {
1278 _mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident");
1279 return GL_FALSE;
1280 }
1281 t = _mesa_lookup_texture(ctx, texName[i]);
1282 if (!t) {
1283 _mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident");
1284 return GL_FALSE;
1285 }
1286 }
1287
1288 return allResident;
1289 }
1290
1291
1292 /**
1293 * See if a name corresponds to a texture.
1294 *
1295 * \param texture texture name.
1296 *
1297 * \return GL_TRUE if texture name corresponds to a texture, or GL_FALSE
1298 * otherwise.
1299 *
1300 * \sa glIsTexture().
1301 *
1302 * Calls _mesa_HashLookup().
1303 */
1304 GLboolean GLAPIENTRY
1305 _mesa_IsTexture( GLuint texture )
1306 {
1307 struct gl_texture_object *t;
1308 GET_CURRENT_CONTEXT(ctx);
1309 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
1310
1311 if (!texture)
1312 return GL_FALSE;
1313
1314 t = _mesa_lookup_texture(ctx, texture);
1315
1316 /* IsTexture is true only after object has been bound once. */
1317 return t && t->Target;
1318 }
1319
1320
1321 /**
1322 * Simplest implementation of texture locking: grab the shared tex
1323 * mutex. Examine the shared context state timestamp and if there has
1324 * been a change, set the appropriate bits in ctx->NewState.
1325 *
1326 * This is used to deal with synchronizing things when a texture object
1327 * is used/modified by different contexts (or threads) which are sharing
1328 * the texture.
1329 *
1330 * See also _mesa_lock/unlock_texture() in teximage.h
1331 */
1332 void
1333 _mesa_lock_context_textures( struct gl_context *ctx )
1334 {
1335 _glthread_LOCK_MUTEX(ctx->Shared->TexMutex);
1336
1337 if (ctx->Shared->TextureStateStamp != ctx->TextureStateTimestamp) {
1338 ctx->NewState |= _NEW_TEXTURE;
1339 ctx->TextureStateTimestamp = ctx->Shared->TextureStateStamp;
1340 }
1341 }
1342
1343
1344 void
1345 _mesa_unlock_context_textures( struct gl_context *ctx )
1346 {
1347 assert(ctx->Shared->TextureStateStamp == ctx->TextureStateTimestamp);
1348 _glthread_UNLOCK_MUTEX(ctx->Shared->TexMutex);
1349 }
1350
1351 /*@}*/