blob: 81833a3fa62020a1308fb2d290c3bded55a9d707 [file] [log] [blame]
jtgafb833d1999-08-19 00:55:39 +00001
2/*
3 * Mesa 3-D graphics library
Brian Paulfbd8f211999-11-11 01:22:25 +00004 * Version: 3.3
jtgafb833d1999-08-19 00:55:39 +00005 *
Brian Paulbb797902000-01-24 16:19:54 +00006 * Copyright (C) 1999-2000 Brian Paul All Rights Reserved.
jtgafb833d1999-08-19 00:55:39 +00007 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
jtgafb833d1999-08-19 00:55:39 +000025
26
27#ifdef PC_HEADER
28#include "all.h"
29#else
Brian Paulfbd8f211999-11-11 01:22:25 +000030#include "glheader.h"
Brian Paul4bdcfe52000-04-17 17:57:04 +000031#include "colortab.h"
jtgafb833d1999-08-19 00:55:39 +000032#include "context.h"
33#include "enums.h"
34#include "hash.h"
Brian Paulfbd8f211999-11-11 01:22:25 +000035#include "mem.h"
jtgafb833d1999-08-19 00:55:39 +000036#include "teximage.h"
37#include "texstate.h"
38#include "texobj.h"
39#include "types.h"
jtgafb833d1999-08-19 00:55:39 +000040#endif
41
42
43
44/*
45 * Allocate a new texture object and add it to the linked list of texture
46 * objects. If name>0 then also insert the new texture object into the hash
47 * table.
48 * Input: shared - the shared GL state structure to contain the texture object
49 * name - integer name for the texture object
Brian Paulfc4b4432000-05-23 15:17:12 +000050 * dimensions - either 1, 2, 3 or 6 (cube map)
jtgafb833d1999-08-19 00:55:39 +000051 * Return: pointer to new texture object
52 */
53struct gl_texture_object *
54gl_alloc_texture_object( struct gl_shared_state *shared, GLuint name,
55 GLuint dimensions)
56{
57 struct gl_texture_object *obj;
58
Brian Paulfc4b4432000-05-23 15:17:12 +000059 ASSERT(dimensions <= 3 || dimensions == 6);
jtgafb833d1999-08-19 00:55:39 +000060
Brian Paul420ef641999-12-01 21:10:08 +000061 obj = CALLOC_STRUCT(gl_texture_object);
62
jtgafb833d1999-08-19 00:55:39 +000063 if (obj) {
64 /* init the non-zero fields */
Brian Paul6e6d4c61999-10-09 20:17:07 +000065 obj->RefCount = 1;
jtgafb833d1999-08-19 00:55:39 +000066 obj->Name = name;
67 obj->Dimensions = dimensions;
68 obj->WrapS = GL_REPEAT;
69 obj->WrapT = GL_REPEAT;
70 obj->MinFilter = GL_NEAREST_MIPMAP_LINEAR;
71 obj->MagFilter = GL_LINEAR;
72 obj->MinLod = -1000.0;
73 obj->MaxLod = 1000.0;
74 obj->BaseLevel = 0;
75 obj->MaxLevel = 1000;
76 obj->MinMagThresh = 0.0F;
Brian Paul4bdcfe52000-04-17 17:57:04 +000077 _mesa_init_colortable(&obj->Palette);
jtgafb833d1999-08-19 00:55:39 +000078
79 /* insert into linked list */
80 if (shared) {
Brian Paul9560f052000-01-31 23:11:39 +000081 _glthread_LOCK_MUTEX(shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +000082 obj->Next = shared->TexObjectList;
83 shared->TexObjectList = obj;
Brian Paul9560f052000-01-31 23:11:39 +000084 _glthread_UNLOCK_MUTEX(shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +000085 }
86
87 if (name > 0) {
88 /* insert into hash table */
Brian Paulbb797902000-01-24 16:19:54 +000089 _mesa_HashInsert(shared->TexObjects, name, obj);
jtgafb833d1999-08-19 00:55:39 +000090 }
91 }
92 return obj;
93}
94
95
96/*
97 * Deallocate a texture object struct and remove it from the given
98 * shared GL state.
99 * Input: shared - the shared GL state to which the object belongs
100 * t - the texture object to delete
101 */
102void gl_free_texture_object( struct gl_shared_state *shared,
103 struct gl_texture_object *t )
104{
105 struct gl_texture_object *tprev, *tcurr;
106
107 assert(t);
108
109 /* Remove t from dirty list so we don't touch free'd memory later.
110 * Test for shared since Proxy texture aren't in global linked list.
111 */
112 if (shared)
113 gl_remove_texobj_from_dirty_list( shared, t );
114
115 /* unlink t from the linked list */
116 if (shared) {
Brian Paul9560f052000-01-31 23:11:39 +0000117 _glthread_LOCK_MUTEX(shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000118 tprev = NULL;
119 tcurr = shared->TexObjectList;
120 while (tcurr) {
121 if (tcurr==t) {
122 if (tprev) {
123 tprev->Next = t->Next;
124 }
125 else {
126 shared->TexObjectList = t->Next;
127 }
128 break;
129 }
130 tprev = tcurr;
131 tcurr = tcurr->Next;
132 }
Brian Paul9560f052000-01-31 23:11:39 +0000133 _glthread_UNLOCK_MUTEX(shared->Mutex);
jtgafb833d1999-08-19 00:55:39 +0000134 }
135
136 if (t->Name) {
137 /* remove from hash table */
Brian Paulbb797902000-01-24 16:19:54 +0000138 _mesa_HashRemove(shared->TexObjects, t->Name);
jtgafb833d1999-08-19 00:55:39 +0000139 }
140
Brian Paul4bdcfe52000-04-17 17:57:04 +0000141 _mesa_free_colortable_data(&t->Palette);
142
143 /* free texture images */
jtgafb833d1999-08-19 00:55:39 +0000144 {
145 GLuint i;
146 for (i=0;i<MAX_TEXTURE_LEVELS;i++) {
147 if (t->Image[i]) {
Brian Paul021a5252000-03-27 17:54:17 +0000148 _mesa_free_texture_image( t->Image[i] );
jtgafb833d1999-08-19 00:55:39 +0000149 }
150 }
151 }
152 /* free this object */
Brian Paulbd5cdaf1999-10-13 18:42:49 +0000153 FREE( t );
jtgafb833d1999-08-19 00:55:39 +0000154}
155
156
157
158/*
159 * Examine a texture object to determine if it is complete or not.
160 * The t->Complete flag will be set to GL_TRUE or GL_FALSE accordingly.
161 */
Brian Paul35d53012000-05-23 17:14:49 +0000162void
163_mesa_test_texobj_completeness( const GLcontext *ctx,
164 struct gl_texture_object *t )
jtgafb833d1999-08-19 00:55:39 +0000165{
166 t->Complete = GL_TRUE; /* be optimistic */
167
168 /* Always need level zero image */
Brian Paul48271792000-03-29 18:13:59 +0000169 if (!t->Image[0]) {
jtgafb833d1999-08-19 00:55:39 +0000170 t->Complete = GL_FALSE;
171 return;
172 }
173
174 /* Compute number of mipmap levels */
175 if (t->Dimensions==1) {
176 t->P = t->Image[0]->WidthLog2;
177 }
Brian Paulfc4b4432000-05-23 15:17:12 +0000178 else if (t->Dimensions == 2 || t->Dimensions == 6) {
jtgafb833d1999-08-19 00:55:39 +0000179 t->P = MAX2(t->Image[0]->WidthLog2, t->Image[0]->HeightLog2);
180 }
181 else if (t->Dimensions==3) {
182 GLint max = MAX2(t->Image[0]->WidthLog2, t->Image[0]->HeightLog2);
183 max = MAX2(max, (GLint)(t->Image[0]->DepthLog2));
184 t->P = max;
185 }
186
187 /* Compute M (see the 1.2 spec) used during mipmapping */
188 t->M = (GLfloat) (MIN2(t->MaxLevel, t->P) - t->BaseLevel);
189
190
191 if (t->MinFilter!=GL_NEAREST && t->MinFilter!=GL_LINEAR) {
192 /*
193 * Mipmapping: determine if we have a complete set of mipmaps
194 */
195 GLint i;
196 GLint minLevel = t->BaseLevel;
197 GLint maxLevel = MIN2(t->P, ctx->Const.MaxTextureLevels-1);
198 maxLevel = MIN2(maxLevel, t->MaxLevel);
199
200 if (minLevel > maxLevel) {
201 t->Complete = GL_FALSE;
202 return;
203 }
204
205 /* Test dimension-independent attributes */
206 for (i = minLevel; i <= maxLevel; i++) {
207 if (t->Image[i]) {
jtgafb833d1999-08-19 00:55:39 +0000208 if (t->Image[i]->Format != t->Image[0]->Format) {
209 t->Complete = GL_FALSE;
210 return;
211 }
212 if (t->Image[i]->Border != t->Image[0]->Border) {
213 t->Complete = GL_FALSE;
214 return;
215 }
216 }
217 }
218
219 /* Test things which depend on number of texture image dimensions */
220 if (t->Dimensions==1) {
221 /* Test 1-D mipmaps */
222 GLuint width = t->Image[0]->Width2;
223 for (i=1; i<ctx->Const.MaxTextureLevels; i++) {
224 if (width>1) {
225 width /= 2;
226 }
227 if (i >= minLevel && i <= maxLevel) {
228 if (!t->Image[i]) {
229 t->Complete = GL_FALSE;
230 return;
231 }
jtgafb833d1999-08-19 00:55:39 +0000232 if (t->Image[i]->Width2 != width ) {
233 t->Complete = GL_FALSE;
234 return;
235 }
236 }
237 if (width==1) {
238 return; /* found smallest needed mipmap, all done! */
239 }
240 }
241 }
242 else if (t->Dimensions==2) {
243 /* Test 2-D mipmaps */
244 GLuint width = t->Image[0]->Width2;
245 GLuint height = t->Image[0]->Height2;
246 for (i=1; i<ctx->Const.MaxTextureLevels; i++) {
247 if (width>1) {
248 width /= 2;
249 }
250 if (height>1) {
251 height /= 2;
252 }
253 if (i >= minLevel && i <= maxLevel) {
254 if (!t->Image[i]) {
255 t->Complete = GL_FALSE;
256 return;
257 }
258 if (t->Image[i]->Width2 != width) {
259 t->Complete = GL_FALSE;
260 return;
261 }
262 if (t->Image[i]->Height2 != height) {
263 t->Complete = GL_FALSE;
264 return;
265 }
266 if (width==1 && height==1) {
267 return; /* found smallest needed mipmap, all done! */
268 }
269 }
270 }
271 }
272 else if (t->Dimensions==3) {
273 /* Test 3-D mipmaps */
274 GLuint width = t->Image[0]->Width2;
275 GLuint height = t->Image[0]->Height2;
276 GLuint depth = t->Image[0]->Depth2;
277 for (i=1; i<ctx->Const.MaxTextureLevels; i++) {
278 if (width>1) {
279 width /= 2;
280 }
281 if (height>1) {
282 height /= 2;
283 }
284 if (depth>1) {
285 depth /= 2;
286 }
287 if (i >= minLevel && i <= maxLevel) {
288 if (!t->Image[i]) {
289 t->Complete = GL_FALSE;
290 return;
291 }
292 if (t->Image[i]->Width2 != width) {
293 t->Complete = GL_FALSE;
294 return;
295 }
296 if (t->Image[i]->Height2 != height) {
297 t->Complete = GL_FALSE;
298 return;
299 }
300 if (t->Image[i]->Depth2 != depth) {
301 t->Complete = GL_FALSE;
302 return;
303 }
304 }
305 if (width==1 && height==1 && depth==1) {
306 return; /* found smallest needed mipmap, all done! */
307 }
308 }
309 }
310 else {
311 /* Dimensions = ??? */
312 gl_problem(NULL, "Bug in gl_test_texture_object_completeness\n");
313 }
314 }
315}
316
317
Brian Paul832179c2000-03-21 17:42:27 +0000318_glthread_DECLARE_STATIC_MUTEX(GenTexturesLock);
319
jtgafb833d1999-08-19 00:55:39 +0000320
321/*
322 * Execute glGenTextures
323 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000324void
325_mesa_GenTextures( GLsizei n, GLuint *texName )
jtgafb833d1999-08-19 00:55:39 +0000326{
Brian Paulfbd8f211999-11-11 01:22:25 +0000327 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000328 GLuint first;
329 GLint i;
330
331 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGenTextures");
332 if (n<0) {
333 gl_error( ctx, GL_INVALID_VALUE, "glGenTextures" );
334 return;
335 }
336
Brian Paul832179c2000-03-21 17:42:27 +0000337
338 /*
339 * This must be atomic (generation and allocation of texture IDs)
340 */
341 _glthread_LOCK_MUTEX(GenTexturesLock);
342
Brian Paulbb797902000-01-24 16:19:54 +0000343 first = _mesa_HashFindFreeKeyBlock(ctx->Shared->TexObjects, n);
jtgafb833d1999-08-19 00:55:39 +0000344
345 /* Return the texture names */
346 for (i=0;i<n;i++) {
347 texName[i] = first + i;
348 }
349
350 /* Allocate new, empty texture objects */
351 for (i=0;i<n;i++) {
352 GLuint name = first + i;
353 GLuint dims = 0;
354 (void) gl_alloc_texture_object(ctx->Shared, name, dims);
355 }
Brian Paul832179c2000-03-21 17:42:27 +0000356
357 _glthread_UNLOCK_MUTEX(GenTexturesLock);
jtgafb833d1999-08-19 00:55:39 +0000358}
359
360
361
362/*
363 * Execute glDeleteTextures
364 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000365void
366_mesa_DeleteTextures( GLsizei n, const GLuint *texName)
jtgafb833d1999-08-19 00:55:39 +0000367{
Brian Paulfbd8f211999-11-11 01:22:25 +0000368 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000369 GLint i;
370
371 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glDeleteTextures");
372
373 for (i=0;i<n;i++) {
374 struct gl_texture_object *t;
375 if (texName[i]>0) {
376 t = (struct gl_texture_object *)
Brian Paulbb797902000-01-24 16:19:54 +0000377 _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]);
jtgafb833d1999-08-19 00:55:39 +0000378 if (t) {
Brian Paul59d6da52000-02-12 01:59:19 +0000379 /* First check if this texture is currently bound.
380 * If so, unbind it and decrement the reference count.
381 */
jtgafb833d1999-08-19 00:55:39 +0000382 GLuint u;
Brian Paul59d6da52000-02-12 01:59:19 +0000383 for (u = 0; u < MAX_TEXTURE_UNITS; u++) {
jtgafb833d1999-08-19 00:55:39 +0000384 struct gl_texture_unit *unit = &ctx->Texture.Unit[u];
385 GLuint d;
386 for (d = 1 ; d <= 3 ; d++) {
Brian Paul59d6da52000-02-12 01:59:19 +0000387 if (unit->CurrentD[d] == t) {
Brian Paul6e6d4c61999-10-09 20:17:07 +0000388 unit->CurrentD[d] = ctx->Shared->DefaultD[d];
389 ctx->Shared->DefaultD[d]->RefCount++;
jtgafb833d1999-08-19 00:55:39 +0000390 t->RefCount--;
Brian Paul59d6da52000-02-12 01:59:19 +0000391 ASSERT( t->RefCount >= 0 );
jtgafb833d1999-08-19 00:55:39 +0000392 }
393 }
394 }
395
Brian Paul59d6da52000-02-12 01:59:19 +0000396 /* Decrement reference count and delete if zero */
397 t->RefCount--;
398 ASSERT( t->RefCount >= 0 );
399 if (t->RefCount == 0) {
400 if (ctx->Driver.DeleteTexture)
401 (*ctx->Driver.DeleteTexture)( ctx, t );
jtgafb833d1999-08-19 00:55:39 +0000402 gl_free_texture_object(ctx->Shared, t);
403 }
404 }
405 }
406 }
407}
408
409
410
411/*
412 * Execute glBindTexture
413 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000414void
415_mesa_BindTexture( GLenum target, GLuint texName )
jtgafb833d1999-08-19 00:55:39 +0000416{
Brian Paulfbd8f211999-11-11 01:22:25 +0000417 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000418 GLuint unit = ctx->Texture.CurrentUnit;
419 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
420 struct gl_texture_object *oldTexObj;
421 struct gl_texture_object *newTexObj;
Brian Paul5b37c321999-11-05 06:43:10 +0000422 GLuint dim;
jtgafb833d1999-08-19 00:55:39 +0000423
424 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
425 fprintf(stderr, "glBindTexture %s %d\n",
426 gl_lookup_enum_by_nr(target), (GLint) texName);
427
428 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glBindTexture");
429
Brian Paul420ef641999-12-01 21:10:08 +0000430 switch (target) {
431 case GL_TEXTURE_1D:
432 dim = 1;
Brian Paulfc4b4432000-05-23 15:17:12 +0000433 oldTexObj = texUnit->CurrentD[1];
Brian Paul420ef641999-12-01 21:10:08 +0000434 break;
435 case GL_TEXTURE_2D:
436 dim = 2;
Brian Paulfc4b4432000-05-23 15:17:12 +0000437 oldTexObj = texUnit->CurrentD[2];
Brian Paul420ef641999-12-01 21:10:08 +0000438 break;
439 case GL_TEXTURE_3D:
440 dim = 3;
Brian Paulfc4b4432000-05-23 15:17:12 +0000441 oldTexObj = texUnit->CurrentD[3];
Brian Paul420ef641999-12-01 21:10:08 +0000442 break;
Brian Paulfc4b4432000-05-23 15:17:12 +0000443 case GL_TEXTURE_CUBE_MAP_ARB:
444 if (ctx->Extensions.HaveTextureCubeMap) {
445 dim = 6;
446 oldTexObj = texUnit->CurrentCubeMap;
447 break;
448 }
449 /* fallthrough */
Brian Paul420ef641999-12-01 21:10:08 +0000450 default:
451 gl_error( ctx, GL_INVALID_ENUM, "glBindTexture(target)" );
452 return;
jtgafb833d1999-08-19 00:55:39 +0000453 }
454
jtgafb833d1999-08-19 00:55:39 +0000455 if (oldTexObj->Name == texName)
456 return;
457
Brian Paulfc4b4432000-05-23 15:17:12 +0000458 if (texName == 0) {
459 if (target == GL_TEXTURE_CUBE_MAP_ARB)
460 newTexObj = ctx->Shared->DefaultCubeMap;
461 else
462 newTexObj = ctx->Shared->DefaultD[dim];
463 }
jtgafb833d1999-08-19 00:55:39 +0000464 else {
Brian Paulbb797902000-01-24 16:19:54 +0000465 struct _mesa_HashTable *hash = ctx->Shared->TexObjects;
Brian Paulc79fab42000-01-24 20:53:32 +0000466 newTexObj = (struct gl_texture_object *) _mesa_HashLookup(hash, texName);
jtgafb833d1999-08-19 00:55:39 +0000467
468 if (!newTexObj)
469 newTexObj = gl_alloc_texture_object(ctx->Shared, texName, dim);
470
471 if (newTexObj->Dimensions != dim) {
472 if (newTexObj->Dimensions) {
Brian Paul420ef641999-12-01 21:10:08 +0000473 /* the named texture object's dimensions don't match the target */
jtgafb833d1999-08-19 00:55:39 +0000474 gl_error( ctx, GL_INVALID_OPERATION, "glBindTexture" );
475 return;
476 }
477 newTexObj->Dimensions = dim;
478 }
479 }
480
jtgafb833d1999-08-19 00:55:39 +0000481 newTexObj->RefCount++;
Brian Paul6e6d4c61999-10-09 20:17:07 +0000482
Brian Paulfc4b4432000-05-23 15:17:12 +0000483 switch (target) {
484 case GL_TEXTURE_1D:
485 texUnit->CurrentD[1] = newTexObj;
486 break;
487 case GL_TEXTURE_2D:
488 texUnit->CurrentD[2] = newTexObj;
489 break;
490 case GL_TEXTURE_3D:
491 texUnit->CurrentD[3] = newTexObj;
492 break;
493 case GL_TEXTURE_CUBE_MAP_ARB:
494 texUnit->CurrentCubeMap = newTexObj;
495 break;
496 default:
497 gl_problem(ctx, "bad target in BindTexture");
498 }
jtgafb833d1999-08-19 00:55:39 +0000499
500 /* If we've changed the CurrentD[123] texture object then update the
501 * ctx->Texture.Current pointer to point to the new texture object.
502 */
503 texUnit->Current = texUnit->CurrentD[texUnit->CurrentDimension];
504
505 /* Check if we may have to use a new triangle rasterizer */
506 if ((ctx->IndirectTriangles & DD_SW_RASTERIZE) &&
507 ( oldTexObj->WrapS != newTexObj->WrapS
508 || oldTexObj->WrapT != newTexObj->WrapT
509 || oldTexObj->WrapR != newTexObj->WrapR
510 || oldTexObj->MinFilter != newTexObj->MinFilter
511 || oldTexObj->MagFilter != newTexObj->MagFilter
512 || (oldTexObj->Image[0] && newTexObj->Image[0] &&
513 (oldTexObj->Image[0]->Format!=newTexObj->Image[0]->Format))))
514 {
515 ctx->NewState |= (NEW_RASTER_OPS | NEW_TEXTURING);
516 }
517
518 if (oldTexObj->Complete != newTexObj->Complete)
519 ctx->NewState |= NEW_TEXTURING;
520
521 /* Pass BindTexture call to device driver */
522 if (ctx->Driver.BindTexture) {
523 (*ctx->Driver.BindTexture)( ctx, target, newTexObj );
524 }
Brian Paul6e6d4c61999-10-09 20:17:07 +0000525
526 if (oldTexObj->Name > 0) {
527 /* never delete default (id=0) texture objects */
528 oldTexObj->RefCount--;
529 if (oldTexObj->RefCount <= 0) {
530 if (ctx->Driver.DeleteTexture) {
531 (*ctx->Driver.DeleteTexture)( ctx, oldTexObj );
532 }
533 gl_free_texture_object(ctx->Shared, oldTexObj);
534 }
535 }
jtgafb833d1999-08-19 00:55:39 +0000536}
537
538
539
540/*
541 * Execute glPrioritizeTextures
542 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000543void
544_mesa_PrioritizeTextures( GLsizei n, const GLuint *texName,
545 const GLclampf *priorities )
jtgafb833d1999-08-19 00:55:39 +0000546{
Brian Paulfbd8f211999-11-11 01:22:25 +0000547 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000548 GLint i;
549
550 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glPrioritizeTextures");
551 if (n<0) {
552 gl_error( ctx, GL_INVALID_VALUE, "glPrioritizeTextures" );
553 return;
554 }
555
556 for (i=0;i<n;i++) {
557 struct gl_texture_object *t;
558 if (texName[i]>0) {
559 t = (struct gl_texture_object *)
Brian Paulbb797902000-01-24 16:19:54 +0000560 _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]);
jtgafb833d1999-08-19 00:55:39 +0000561 if (t) {
562 t->Priority = CLAMP( priorities[i], 0.0F, 1.0F );
Keith Whitwell69cfdb21999-09-30 11:18:21 +0000563
564 if (ctx->Driver.PrioritizeTexture)
565 ctx->Driver.PrioritizeTexture( ctx, t, t->Priority );
jtgafb833d1999-08-19 00:55:39 +0000566 }
567 }
568 }
569}
570
571
572
573/*
Keith Whitwell69cfdb21999-09-30 11:18:21 +0000574 * Execute glAreTexturesResident
jtgafb833d1999-08-19 00:55:39 +0000575 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000576GLboolean
577_mesa_AreTexturesResident( GLsizei n, const GLuint *texName,
578 GLboolean *residences )
jtgafb833d1999-08-19 00:55:39 +0000579{
Brian Paulfbd8f211999-11-11 01:22:25 +0000580 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000581 GLboolean resident = GL_TRUE;
582 GLint i;
583
584 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx,
585 "glAreTexturesResident",
586 GL_FALSE);
587 if (n<0) {
588 gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(n)" );
589 return GL_FALSE;
590 }
591
592 for (i=0;i<n;i++) {
593 struct gl_texture_object *t;
594 if (texName[i]==0) {
595 gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)" );
596 return GL_FALSE;
597 }
598 t = (struct gl_texture_object *)
Brian Paulbb797902000-01-24 16:19:54 +0000599 _mesa_HashLookup(ctx->Shared->TexObjects, texName[i]);
jtgafb833d1999-08-19 00:55:39 +0000600 if (t) {
Keith Whitwell69cfdb21999-09-30 11:18:21 +0000601 if (ctx->Driver.IsTextureResident)
602 residences[i] = ctx->Driver.IsTextureResident( ctx, t );
603 else
604 residences[i] = GL_TRUE;
jtgafb833d1999-08-19 00:55:39 +0000605 }
606 else {
607 gl_error( ctx, GL_INVALID_VALUE, "glAreTexturesResident(textures)" );
608 return GL_FALSE;
609 }
610 }
611 return resident;
612}
613
614
615
616/*
617 * Execute glIsTexture
618 */
Brian Paulfbd8f211999-11-11 01:22:25 +0000619GLboolean
620_mesa_IsTexture( GLuint texture )
jtgafb833d1999-08-19 00:55:39 +0000621{
Brian Paulfbd8f211999-11-11 01:22:25 +0000622 GET_CURRENT_CONTEXT(ctx);
jtgafb833d1999-08-19 00:55:39 +0000623 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH_WITH_RETVAL(ctx, "glIsTextures",
624 GL_FALSE);
Brian Paulbb797902000-01-24 16:19:54 +0000625 if (texture>0 && _mesa_HashLookup(ctx->Shared->TexObjects, texture)) {
jtgafb833d1999-08-19 00:55:39 +0000626 return GL_TRUE;
627 }
628 else {
629 return GL_FALSE;
630 }
631}
632