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