fix for gl_ztrick bug (Ove Kaaven)
[mesa.git] / src / mesa / main / texobj.c
1 /* $Id: texobj.c,v 1.45 2001/03/18 08:53:49 gareth Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.5
6 *
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "colortab.h"
33 #include "context.h"
34 #include "enums.h"
35 #include "hash.h"
36 #include "macros.h"
37 #include "mem.h"
38 #include "teximage.h"
39 #include "texstate.h"
40 #include "texobj.h"
41 #include "mtypes.h"
42 #endif
43
44
45
46 /*
47 * Allocate a new texture object and add it to the linked list of texture
48 * objects. If name>0 then also insert the new texture object into the hash
49 * table.
50 * Input: shared - the shared GL state structure to contain the texture object
51 * name - integer name for the texture object
52 * dimensions - either 1, 2, 3 or 6 (cube map)
53 * zero is ok for the sake of GenTextures()
54 * Return: pointer to new texture object
55 */
56 struct gl_texture_object *
57 _mesa_alloc_texture_object( struct gl_shared_state *shared,
58 GLuint name, GLuint dimensions )
59 {
60 struct gl_texture_object *obj;
61
62 ASSERT(dimensions <= 3 || dimensions == 6);
63
64 obj = CALLOC_STRUCT(gl_texture_object);
65
66 if (obj) {
67 /* init the non-zero fields */
68 _glthread_INIT_MUTEX(obj->Mutex);
69 obj->RefCount = 1;
70 obj->Name = name;
71 obj->Dimensions = dimensions;
72 obj->Priority = 1.0F;
73 obj->WrapS = GL_REPEAT;
74 obj->WrapT = GL_REPEAT;
75 obj->WrapR = GL_REPEAT;
76 obj->MinFilter = GL_NEAREST_MIPMAP_LINEAR;
77 obj->MagFilter = GL_LINEAR;
78 obj->MinLod = -1000.0;
79 obj->MaxLod = 1000.0;
80 obj->BaseLevel = 0;
81 obj->MaxLevel = 1000;
82 obj->MaxAnisotropy = 1.0;
83 obj->CompareFlag = GL_FALSE;
84 obj->CompareOperator = GL_TEXTURE_LEQUAL_R_SGIX;
85 obj->ShadowAmbient = 0;
86 _mesa_init_colortable(&obj->Palette);
87
88 /* insert into linked list */
89 if (shared) {
90 _glthread_LOCK_MUTEX(shared->Mutex);
91 obj->Next = shared->TexObjectList;
92 shared->TexObjectList = obj;
93 _glthread_UNLOCK_MUTEX(shared->Mutex);
94 }
95
96 if (name > 0) {
97 /* insert into hash table */
98 _mesa_HashInsert(shared->TexObjects, name, obj);
99 }
100 }
101 return obj;
102 }
103
104
105 /*
106 * Deallocate a texture object struct and remove it from the given
107 * shared GL state.
108 * Input: shared - the shared GL state to which the object belongs
109 * t - the texture object to delete
110 */
111 void _mesa_free_texture_object( struct gl_shared_state *shared,
112 struct gl_texture_object *t )
113 {
114 struct gl_texture_object *tprev, *tcurr;
115
116 assert(t);
117
118 /* unlink t from the linked list */
119 if (shared) {
120 _glthread_LOCK_MUTEX(shared->Mutex);
121 tprev = NULL;
122 tcurr = shared->TexObjectList;
123 while (tcurr) {
124 if (tcurr==t) {
125 if (tprev) {
126 tprev->Next = t->Next;
127 }
128 else {
129 shared->TexObjectList = t->Next;
130 }
131 break;
132 }
133 tprev = tcurr;
134 tcurr = tcurr->Next;
135 }
136 _glthread_UNLOCK_MUTEX(shared->Mutex);
137 }
138
139 if (t->Name) {
140 /* remove from hash table */
141 _mesa_HashRemove(shared->TexObjects, t->Name);
142 }
143
144 _mesa_free_colortable_data(&t->Palette);
145
146 /* free the texture images */
147 {
148 GLuint i;
149 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
150 if (t->Image[i]) {
151 _mesa_free_texture_image( t->Image[i] );
152 }
153 }
154 }
155
156 /* free this object */
157 FREE( t );
158 }
159
160
161 /*
162 * Report why a texture object is incomplete. (for debug only)
163 */
164 #if 0
165 static void
166 incomplete(const struct gl_texture_object *t, const char *why)
167 {
168 printf("Texture Obj %d incomplete because: %s\n", t->Name, why);
169 }
170 #else
171 #define incomplete(a, b)
172 #endif
173
174
175 /*
176 * Examine a texture object to determine if it is complete.
177 * The t->Complete flag will be set to GL_TRUE or GL_FALSE accordingly.
178 */
179 void
180 _mesa_test_texobj_completeness( const GLcontext *ctx,
181 struct gl_texture_object *t )
182 {
183 const GLint baseLevel = t->BaseLevel;
184 GLint maxLog2 = 0;
185
186 t->Complete = GL_TRUE; /* be optimistic */
187
188 /* Always need the base level image */
189 if (!t->Image[baseLevel]) {
190 incomplete(t, "Image[baseLevel] == NULL");
191 t->Complete = GL_FALSE;
192 return;
193 }
194
195 /* Compute _MaxLevel */
196 if (t->Dimensions == 1) {
197 maxLog2 = t->Image[baseLevel]->WidthLog2;
198 }
199 else if (t->Dimensions == 2 || t->Dimensions == 6) {
200 maxLog2 = MAX2(t->Image[baseLevel]->WidthLog2,
201 t->Image[baseLevel]->HeightLog2);
202 }
203 else if (t->Dimensions == 3) {
204 GLint max = MAX2(t->Image[baseLevel]->WidthLog2,
205 t->Image[baseLevel]->HeightLog2);
206 maxLog2 = MAX2(max, (GLint)(t->Image[baseLevel]->DepthLog2));
207 }
208
209 t->_MaxLevel = baseLevel + maxLog2;
210 t->_MaxLevel = MIN2(t->_MaxLevel, t->MaxLevel);
211 t->_MaxLevel = MIN2(t->_MaxLevel, ctx->Const.MaxTextureLevels - 1);
212
213 /* Compute _MaxLambda = q - b (see the 1.2 spec) used during mipmapping */
214 t->_MaxLambda = (GLfloat) (t->_MaxLevel - t->BaseLevel);
215
216 if (t->Dimensions == 6) {
217 /* make sure that all six cube map level 0 images are the same size */
218 const GLuint w = t->Image[baseLevel]->Width2;
219 const GLuint h = t->Image[baseLevel]->Height2;
220 if (!t->NegX[baseLevel] ||
221 t->NegX[baseLevel]->Width2 != w ||
222 t->NegX[baseLevel]->Height2 != h ||
223 !t->PosY[baseLevel] ||
224 t->PosY[baseLevel]->Width2 != w ||
225 t->PosY[baseLevel]->Height2 != h ||
226 !t->NegY[baseLevel] ||
227 t->NegY[baseLevel]->Width2 != w ||
228 t->NegY[baseLevel]->Height2 != h ||
229 !t->PosZ[baseLevel] ||
230 t->PosZ[baseLevel]->Width2 != w ||
231 t->PosZ[baseLevel]->Height2 != h ||
232 !t->NegZ[baseLevel] ||
233 t->NegZ[baseLevel]->Width2 != w ||
234 t->NegZ[baseLevel]->Height2 != h) {
235 t->Complete = GL_FALSE;
236 incomplete(t, "Non-quare cubemap image");
237 return;
238 }
239 }
240
241 if (t->MinFilter != GL_NEAREST && t->MinFilter != GL_LINEAR) {
242 /*
243 * Mipmapping: determine if we have a complete set of mipmaps
244 */
245 GLint i;
246 GLint minLevel = baseLevel;
247 GLint maxLevel = t->_MaxLevel;
248
249 if (minLevel > maxLevel) {
250 t->Complete = GL_FALSE;
251 incomplete(t, "minLevel > maxLevel");
252 return;
253 }
254
255 /* Test dimension-independent attributes */
256 for (i = minLevel; i <= maxLevel; i++) {
257 if (t->Image[i]) {
258 if (t->Image[i]->Format != t->Image[baseLevel]->Format) {
259 t->Complete = GL_FALSE;
260 incomplete(t, "Format[i] != Format[baseLevel]");
261 return;
262 }
263 if (t->Image[i]->Border != t->Image[baseLevel]->Border) {
264 t->Complete = GL_FALSE;
265 incomplete(t, "Border[i] != Border[baseLevel]");
266 return;
267 }
268 }
269 }
270
271 /* Test things which depend on number of texture image dimensions */
272 if (t->Dimensions == 1) {
273 /* Test 1-D mipmaps */
274 GLuint width = t->Image[baseLevel]->Width2;
275 for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) {
276 if (width > 1) {
277 width /= 2;
278 }
279 if (i >= minLevel && i <= maxLevel) {
280 if (!t->Image[i]) {
281 t->Complete = GL_FALSE;
282 incomplete(t, "1D Image[i] == NULL");
283 return;
284 }
285 if (t->Image[i]->Width2 != width ) {
286 t->Complete = GL_FALSE;
287 incomplete(t, "1D Image[i] bad width");
288 return;
289 }
290 }
291 if (width == 1) {
292 return; /* found smallest needed mipmap, all done! */
293 }
294 }
295 }
296 else if (t->Dimensions == 2) {
297 /* Test 2-D mipmaps */
298 GLuint width = t->Image[baseLevel]->Width2;
299 GLuint height = t->Image[baseLevel]->Height2;
300 for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) {
301 if (width > 1) {
302 width /= 2;
303 }
304 if (height > 1) {
305 height /= 2;
306 }
307 if (i >= minLevel && i <= maxLevel) {
308 if (!t->Image[i]) {
309 t->Complete = GL_FALSE;
310 incomplete(t, "2D Image[i] == NULL");
311 return;
312 }
313 if (t->Image[i]->Width2 != width) {
314 t->Complete = GL_FALSE;
315 incomplete(t, "2D Image[i] bad width");
316 return;
317 }
318 if (t->Image[i]->Height2 != height) {
319 t->Complete = GL_FALSE;
320 incomplete(t, "2D Image[i] bad height");
321 return;
322 }
323 if (width==1 && height==1) {
324 return; /* found smallest needed mipmap, all done! */
325 }
326 }
327 }
328 }
329 else if (t->Dimensions == 3) {
330 /* Test 3-D mipmaps */
331 GLuint width = t->Image[baseLevel]->Width2;
332 GLuint height = t->Image[baseLevel]->Height2;
333 GLuint depth = t->Image[baseLevel]->Depth2;
334 for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) {
335 if (width > 1) {
336 width /= 2;
337 }
338 if (height > 1) {
339 height /= 2;
340 }
341 if (depth > 1) {
342 depth /= 2;
343 }
344 if (i >= minLevel && i <= maxLevel) {
345 if (!t->Image[i]) {
346 incomplete(t, "3D Image[i] == NULL");
347 t->Complete = GL_FALSE;
348 return;
349 }
350 if (t->Image[i]->Width2 != width) {
351 t->Complete = GL_FALSE;
352 incomplete(t, "3D Image[i] bad width");
353 return;
354 }
355 if (t->Image[i]->Height2 != height) {
356 t->Complete = GL_FALSE;
357 incomplete(t, "3D Image[i] bad height");
358 return;
359 }
360 if (t->Image[i]->Depth2 != depth) {
361 t->Complete = GL_FALSE;
362 incomplete(t, "3D Image[i] bad depth");
363 return;
364 }
365 }
366 if (width == 1 && height == 1 && depth == 1) {
367 return; /* found smallest needed mipmap, all done! */
368 }
369 }
370 }
371 else if (t->Dimensions == 6) {
372 /* make sure 6 cube faces are consistant */
373 GLuint width = t->Image[baseLevel]->Width2;
374 GLuint height = t->Image[baseLevel]->Height2;
375 for (i = baseLevel + 1; i < ctx->Const.MaxTextureLevels; i++) {
376 if (width > 1) {
377 width /= 2;
378 }
379 if (height > 1) {
380 height /= 2;
381 }
382 if (i >= minLevel && i <= maxLevel) {
383 /* check that we have images defined */
384 if (!t->Image[i] || !t->NegX[i] ||
385 !t->PosY[i] || !t->NegY[i] ||
386 !t->PosZ[i] || !t->NegZ[i]) {
387 t->Complete = GL_FALSE;
388 incomplete(t, "CubeMap Image[i] == NULL");
389 return;
390 }
391 /* check that all six images have same size */
392 if (t->NegX[i]->Width2!=width || t->NegX[i]->Height2!=height ||
393 t->PosY[i]->Width2!=width || t->PosY[i]->Height2!=height ||
394 t->NegY[i]->Width2!=width || t->NegY[i]->Height2!=height ||
395 t->PosZ[i]->Width2!=width || t->PosZ[i]->Height2!=height ||
396 t->NegZ[i]->Width2!=width || t->NegZ[i]->Height2!=height) {
397 t->Complete = GL_FALSE;
398 incomplete(t, "CubeMap Image[i] bad size");
399 return;
400 }
401 }
402 if (width == 1 && height == 1) {
403 return; /* found smallest needed mipmap, all done! */
404 }
405 }
406 }
407 else {
408 /* Dimensions = ??? */
409 _mesa_problem(ctx, "Bug in gl_test_texture_object_completeness\n");
410 }
411 }
412 }
413
414
415 _glthread_DECLARE_STATIC_MUTEX(GenTexturesLock);
416
417
418 /*
419 * Execute glGenTextures
420 */
421 void
422 _mesa_GenTextures( GLsizei n, GLuint *texName )
423 {
424 GET_CURRENT_CONTEXT(ctx);
425 GLuint first;
426 GLint i;
427 ASSERT_OUTSIDE_BEGIN_END(ctx);
428
429 if (n < 0) {
430 _mesa_error( ctx, GL_INVALID_VALUE, "glGenTextures" );
431 return;
432 }
433
434 if (!texName)
435 return;
436
437 /*
438 * This must be atomic (generation and allocation of texture IDs)
439 */
440 _glthread_LOCK_MUTEX(GenTexturesLock);
441
442 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
443
444 /* Return the texture names */
445 for (i=0;i<n;i++) {
446 texName[i] = first + i;
447 }
448
449 /* Allocate new, empty texture objects */
450 for (i=0;i<n;i++) {
451 GLuint name = first + i;
452 GLuint dims = 0;
453 (void) _mesa_alloc_texture_object( ctx->Shared, name, dims);
454 }
455
456 _glthread_UNLOCK_MUTEX(GenTexturesLock);
457 }
458
459
460
461 /*
462 * Execute glDeleteTextures
463 */
464 void
465 _mesa_DeleteTextures( GLsizei n, const GLuint *texName)
466 {
467 GET_CURRENT_CONTEXT(ctx);
468 GLint i;
469 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
470
471 if (!texName)
472 return;
473
474 for (i=0;i<n;i++) {
475 if (texName[i] > 0) {
476 struct gl_texture_object *delObj = (struct gl_texture_object *)
477 _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]);
478 if (delObj) {
479 /* First check if this texture is currently bound.
480 * If so, unbind it and decrement the reference count.
481 */
482 GLuint u;
483 for (u = 0; u < MAX_TEXTURE_UNITS; u++) {
484 struct gl_texture_unit *unit = &ctx->Texture.Unit[u];
485 if (delObj == unit->Current1D) {
486 unit->Current1D = ctx->Shared->Default1D;
487 ctx->Shared->Default1D->RefCount++;
488 }
489 else if (delObj == unit->Current2D) {
490 unit->Current2D = ctx->Shared->Default2D;
491 ctx->Shared->Default2D->RefCount++;
492 }
493 else if (delObj == unit->Current3D) {
494 unit->Current3D = ctx->Shared->Default3D;
495 ctx->Shared->Default3D->RefCount++;
496 }
497 else if (delObj == unit->CurrentCubeMap) {
498 unit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
499 ctx->Shared->DefaultCubeMap->RefCount++;
500 }
501 }
502 ctx->NewState |= _NEW_TEXTURE;
503
504 /* Decrement reference count and delete if zero */
505 delObj->RefCount--;
506 ASSERT( delObj->RefCount >= 0 );
507 if (delObj->RefCount == 0) {
508 if (ctx->Driver.DeleteTexture)
509 (*ctx->Driver.DeleteTexture)( ctx, delObj );
510 _mesa_free_texture_object(ctx->Shared, delObj);
511 }
512 }
513 }
514 }
515 }
516
517
518
519 /*
520 * Execute glBindTexture
521 */
522 void
523 _mesa_BindTexture( GLenum target, GLuint texName )
524 {
525 GET_CURRENT_CONTEXT(ctx);
526 GLuint unit = ctx->Texture.CurrentUnit;
527 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
528 struct gl_texture_object *oldTexObj;
529 struct gl_texture_object *newTexObj = 0;
530 GLuint targetDim;
531 ASSERT_OUTSIDE_BEGIN_END(ctx);
532
533 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
534 fprintf(stderr, "glBindTexture %s %d\n",
535 _mesa_lookup_enum_by_nr(target), (GLint) texName);
536
537 switch (target) {
538 case GL_TEXTURE_1D:
539 targetDim = 1;
540 oldTexObj = texUnit->Current1D;
541 break;
542 case GL_TEXTURE_2D:
543 targetDim = 2;
544 oldTexObj = texUnit->Current2D;
545 break;
546 case GL_TEXTURE_3D:
547 targetDim = 3;
548 oldTexObj = texUnit->Current3D;
549 break;
550 case GL_TEXTURE_CUBE_MAP_ARB:
551 if (ctx->Extensions.ARB_texture_cube_map) {
552 targetDim = 6;
553 oldTexObj = texUnit->CurrentCubeMap;
554 break;
555 }
556 /* fallthrough */
557 default:
558 _mesa_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" );
559 return;
560 }
561
562 if (oldTexObj->Name == texName)
563 return; /* rebinding the same texture- no change */
564
565 /*
566 * Get pointer to new texture object (newTexObj)
567 */
568 if (texName == 0) {
569 /* newTexObj = a default texture object */
570 switch (target) {
571 case GL_TEXTURE_1D:
572 newTexObj = ctx->Shared->Default1D;
573 break;
574 case GL_TEXTURE_2D:
575 newTexObj = ctx->Shared->Default2D;
576 break;
577 case GL_TEXTURE_3D:
578 newTexObj = ctx->Shared->Default3D;
579 break;
580 case GL_TEXTURE_CUBE_MAP_ARB:
581 newTexObj = ctx->Shared->DefaultCubeMap;
582 break;
583 default:
584 ; /* Bad targets are caught above */
585 }
586 }
587 else {
588 /* non-default texture object */
589 const struct _mesa_HashTable *hash = ctx->Shared->TexObjects;
590 newTexObj = (struct gl_texture_object *) _mesa_HashLookup(hash, texName);
591 if (newTexObj) {
592 /* error checking */
593 if (newTexObj->Dimensions > 0 && newTexObj->Dimensions != targetDim) {
594 /* the named texture object's dimensions don't match the target */
595 _mesa_error( ctx, GL_INVALID_OPERATION, "glBindTexture" );
596 return;
597 }
598 }
599 else {
600 /* if this is a new texture id, allocate a texture object now */
601 newTexObj = _mesa_alloc_texture_object( ctx->Shared, texName,
602 targetDim);
603 if (!newTexObj) {
604 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glBindTexture");
605 return;
606 }
607 }
608 newTexObj->Dimensions = targetDim;
609 }
610
611 newTexObj->RefCount++;
612
613
614 /* do the actual binding, but first flush outstanding vertices:
615 */
616 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
617
618 switch (target) {
619 case GL_TEXTURE_1D:
620 texUnit->Current1D = newTexObj;
621 break;
622 case GL_TEXTURE_2D:
623 texUnit->Current2D = newTexObj;
624 break;
625 case GL_TEXTURE_3D:
626 texUnit->Current3D = newTexObj;
627 break;
628 case GL_TEXTURE_CUBE_MAP_ARB:
629 texUnit->CurrentCubeMap = newTexObj;
630 break;
631 default:
632 _mesa_problem(ctx, "bad target in BindTexture");
633 }
634
635 /* Pass BindTexture call to device driver */
636 if (ctx->Driver.BindTexture)
637 (*ctx->Driver.BindTexture)( ctx, target, newTexObj );
638
639 if (oldTexObj->Name > 0) {
640 /* never delete default (id=0) texture objects */
641 oldTexObj->RefCount--;
642 if (oldTexObj->RefCount <= 0) {
643 if (ctx->Driver.DeleteTexture) {
644 (*ctx->Driver.DeleteTexture)( ctx, oldTexObj );
645 }
646 _mesa_free_texture_object(ctx->Shared, oldTexObj);
647 }
648 }
649 }
650
651
652
653 /*
654 * Execute glPrioritizeTextures
655 */
656 void
657 _mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
658 const GLclampf *priorities )
659 {
660 GET_CURRENT_CONTEXT(ctx);
661 GLint i;
662 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
663
664 if (n < 0) {
665 _mesa_error( ctx, GL_INVALID_VALUE, "glPrioritizeTextures" );
666 return;
667 }
668
669 if (!priorities)
670 return;
671
672 for (i = 0; i < n; i++) {
673 if (texName[i] > 0) {
674 struct gl_texture_object *t = (struct gl_texture_object *)
675 _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]);
676 if (t) {
677 t->Priority = CLAMP( priorities[i], 0.0F, 1.0F );
678 if (ctx->Driver.PrioritizeTexture)
679 ctx->Driver.PrioritizeTexture( ctx, t, t->Priority );
680 }
681 }
682 }
683
684 ctx->NewState |= _NEW_TEXTURE;
685 }
686
687
688
689 /*
690 * Execute glAreTexturesResident
691 */
692 GLboolean
693 _mesa_AreTexturesResident(GLsizei n, const GLuint *texName,
694 GLboolean *residences)
695 {
696 GET_CURRENT_CONTEXT(ctx);
697 GLboolean allResident = GL_TRUE;
698 GLint i;
699 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
700
701 if (n < 0) {
702 _mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)");
703 return GL_FALSE;
704 }
705
706 if (!texName || !residences)
707 return GL_FALSE;
708
709 for (i = 0; i < n; i++) {
710 struct gl_texture_object *t;
711 if (texName[i] == 0) {
712 _mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)");
713 return GL_FALSE;
714 }
715 t = (struct gl_texture_object *)
716 _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]);
717 if (t) {
718 if (ctx->Driver.IsTextureResident) {
719 residences[i] = ctx->Driver.IsTextureResident(ctx, t);
720 if (!residences[i])
721 allResident = GL_FALSE;
722 }
723 else {
724 residences[i] = GL_TRUE;
725 }
726 }
727 else {
728 _mesa_error(ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)");
729 return GL_FALSE;
730 }
731 }
732 return allResident;
733 }
734
735
736
737 /*
738 * Execute glIsTexture
739 */
740 GLboolean
741 _mesa_IsTexture( GLuint texture )
742 {
743 GET_CURRENT_CONTEXT(ctx);
744 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx, GL_FALSE);
745 return texture > 0 && _mesa_HashLookup(ctx->Shared->TexObjects, texture);
746 }