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