1 /* $Id: texobj.c,v 1.57 2002/06/29 19:48:16 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
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
50 * Input: shared - the shared GL state structure to contain the texture object
51 * name - integer name for the texture object
52 * target - either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
53 * GL_TEXTURE_CUBE_MAP_ARB or GL_TEXTURE_RECTANGLE_NV
54 * zero is ok for the sake of GenTextures()
55 * Return: pointer to new texture object
57 struct gl_texture_object
*
58 _mesa_alloc_texture_object( struct gl_shared_state
*shared
,
59 GLuint name
, GLenum target
)
61 struct gl_texture_object
*obj
;
64 target
== GL_TEXTURE_1D
||
65 target
== GL_TEXTURE_2D
||
66 target
== GL_TEXTURE_3D
||
67 target
== GL_TEXTURE_CUBE_MAP_ARB
||
68 target
== GL_TEXTURE_RECTANGLE_NV
);
70 obj
= CALLOC_STRUCT(gl_texture_object
);
73 /* init the non-zero fields */
74 _glthread_INIT_MUTEX(obj
->Mutex
);
79 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
80 obj
->WrapS
= GL_CLAMP_TO_EDGE
;
81 obj
->WrapT
= GL_CLAMP_TO_EDGE
;
82 obj
->WrapR
= GL_CLAMP_TO_EDGE
;
83 obj
->MinFilter
= GL_LINEAR
;
86 obj
->WrapS
= GL_REPEAT
;
87 obj
->WrapT
= GL_REPEAT
;
88 obj
->WrapR
= GL_REPEAT
;
89 obj
->MinFilter
= GL_NEAREST_MIPMAP_LINEAR
;
91 obj
->MagFilter
= GL_LINEAR
;
92 obj
->MinLod
= -1000.0;
96 obj
->MaxAnisotropy
= 1.0;
97 obj
->CompareFlag
= GL_FALSE
; /* SGIX_shadow */
98 obj
->CompareOperator
= GL_TEXTURE_LEQUAL_R_SGIX
; /* SGIX_shadow */
99 obj
->CompareMode
= GL_LUMINANCE
; /* ARB_shadow */
100 obj
->CompareFunc
= GL_LEQUAL
; /* ARB_shadow */
101 obj
->DepthMode
= GL_LUMINANCE
; /* ARB_depth_texture */
102 obj
->ShadowAmbient
= 0; /* ARB/SGIX_shadow_ambient */
103 _mesa_init_colortable(&obj
->Palette
);
105 /* insert into linked list */
107 _glthread_LOCK_MUTEX(shared
->Mutex
);
108 obj
->Next
= shared
->TexObjectList
;
109 shared
->TexObjectList
= obj
;
110 _glthread_UNLOCK_MUTEX(shared
->Mutex
);
114 /* insert into hash table */
115 _mesa_HashInsert(shared
->TexObjects
, name
, obj
);
123 * Deallocate a texture object struct and remove it from the given
125 * Input: shared - the shared GL state to which the object belongs
126 * t - the texture object to delete
128 void _mesa_free_texture_object( struct gl_shared_state
*shared
,
129 struct gl_texture_object
*t
)
131 struct gl_texture_object
*tprev
, *tcurr
;
135 /* unlink t from the linked list */
137 _glthread_LOCK_MUTEX(shared
->Mutex
);
139 tcurr
= shared
->TexObjectList
;
143 tprev
->Next
= t
->Next
;
146 shared
->TexObjectList
= t
->Next
;
153 _glthread_UNLOCK_MUTEX(shared
->Mutex
);
157 /* remove from hash table */
158 _mesa_HashRemove(shared
->TexObjects
, t
->Name
);
161 _mesa_free_colortable_data(&t
->Palette
);
163 /* free the texture images */
166 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
168 _mesa_free_texture_image( t
->Image
[i
] );
173 /* free this object */
179 * Copy texture object state from one texture object to another.
182 _mesa_copy_texture_object( struct gl_texture_object
*dest
,
183 const struct gl_texture_object
*src
)
185 dest
->Name
= src
->Name
;
186 dest
->Priority
= src
->Priority
;
187 dest
->BorderColor
[0] = src
->BorderColor
[0];
188 dest
->BorderColor
[1] = src
->BorderColor
[1];
189 dest
->BorderColor
[2] = src
->BorderColor
[2];
190 dest
->BorderColor
[3] = src
->BorderColor
[3];
191 dest
->WrapS
= src
->WrapS
;
192 dest
->WrapT
= src
->WrapT
;
193 dest
->WrapR
= src
->WrapR
;
194 dest
->MinFilter
= src
->MinFilter
;
195 dest
->MagFilter
= src
->MagFilter
;
196 dest
->MinLod
= src
->MinLod
;
197 dest
->MaxLod
= src
->MaxLod
;
198 dest
->BaseLevel
= src
->BaseLevel
;
199 dest
->MaxLevel
= src
->MaxLevel
;
200 dest
->MaxAnisotropy
= src
->MaxAnisotropy
;
201 dest
->CompareFlag
= src
->CompareFlag
;
202 dest
->CompareOperator
= src
->CompareOperator
;
203 dest
->ShadowAmbient
= src
->ShadowAmbient
;
204 dest
->CompareMode
= src
->CompareMode
;
205 dest
->CompareFunc
= src
->CompareFunc
;
206 dest
->DepthMode
= src
->DepthMode
;
207 dest
->_MaxLevel
= src
->_MaxLevel
;
208 dest
->_MaxLambda
= src
->_MaxLambda
;
209 dest
->GenerateMipmap
= src
->GenerateMipmap
;
210 dest
->Palette
= src
->Palette
;
211 dest
->Complete
= src
->Complete
;
216 * Report why a texture object is incomplete. (for debug only)
220 incomplete(const struct gl_texture_object
*t
, const char *why
)
222 _mesa_printf("Texture Obj %d incomplete because: %s\n", t
->Name
, why
);
225 #define incomplete(a, b)
230 * Examine a texture object to determine if it is complete.
231 * The t->Complete flag will be set to GL_TRUE or GL_FALSE accordingly.
234 _mesa_test_texobj_completeness( const GLcontext
*ctx
,
235 struct gl_texture_object
*t
)
237 const GLint baseLevel
= t
->BaseLevel
;
238 GLint maxLog2
= 0, maxLevels
= 0;
240 t
->Complete
= GL_TRUE
; /* be optimistic */
242 /* Always need the base level image */
243 if (!t
->Image
[baseLevel
]) {
244 incomplete(t
, "Image[baseLevel] == NULL");
245 t
->Complete
= GL_FALSE
;
249 /* Compute _MaxLevel */
250 if (t
->Target
== GL_TEXTURE_1D
) {
251 maxLog2
= t
->Image
[baseLevel
]->WidthLog2
;
252 maxLevels
= ctx
->Const
.MaxTextureLevels
;
254 else if (t
->Target
== GL_TEXTURE_2D
) {
255 maxLog2
= MAX2(t
->Image
[baseLevel
]->WidthLog2
,
256 t
->Image
[baseLevel
]->HeightLog2
);
257 maxLevels
= ctx
->Const
.MaxTextureLevels
;
259 else if (t
->Target
== GL_TEXTURE_3D
) {
260 GLint max
= MAX2(t
->Image
[baseLevel
]->WidthLog2
,
261 t
->Image
[baseLevel
]->HeightLog2
);
262 maxLog2
= MAX2(max
, (GLint
)(t
->Image
[baseLevel
]->DepthLog2
));
263 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
265 else if (t
->Target
== GL_TEXTURE_CUBE_MAP_ARB
) {
266 maxLog2
= MAX2(t
->Image
[baseLevel
]->WidthLog2
,
267 t
->Image
[baseLevel
]->HeightLog2
);
268 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
270 else if (t
->Target
== GL_TEXTURE_RECTANGLE_NV
) {
271 maxLog2
= 0; /* not applicable */
272 maxLevels
= 1; /* no mipmapping */
275 _mesa_problem(ctx
, "Bad t->Target in _mesa_test_texobj_completeness");
279 ASSERT(maxLevels
> 0);
281 t
->_MaxLevel
= baseLevel
+ maxLog2
;
282 t
->_MaxLevel
= MIN2(t
->_MaxLevel
, t
->MaxLevel
);
283 t
->_MaxLevel
= MIN2(t
->_MaxLevel
, maxLevels
- 1);
285 /* Compute _MaxLambda = q - b (see the 1.2 spec) used during mipmapping */
286 t
->_MaxLambda
= (GLfloat
) (t
->_MaxLevel
- t
->BaseLevel
);
288 if (t
->Target
== GL_TEXTURE_CUBE_MAP_ARB
) {
289 /* make sure that all six cube map level 0 images are the same size */
290 const GLuint w
= t
->Image
[baseLevel
]->Width2
;
291 const GLuint h
= t
->Image
[baseLevel
]->Height2
;
292 if (!t
->NegX
[baseLevel
] ||
293 t
->NegX
[baseLevel
]->Width2
!= w
||
294 t
->NegX
[baseLevel
]->Height2
!= h
||
295 !t
->PosY
[baseLevel
] ||
296 t
->PosY
[baseLevel
]->Width2
!= w
||
297 t
->PosY
[baseLevel
]->Height2
!= h
||
298 !t
->NegY
[baseLevel
] ||
299 t
->NegY
[baseLevel
]->Width2
!= w
||
300 t
->NegY
[baseLevel
]->Height2
!= h
||
301 !t
->PosZ
[baseLevel
] ||
302 t
->PosZ
[baseLevel
]->Width2
!= w
||
303 t
->PosZ
[baseLevel
]->Height2
!= h
||
304 !t
->NegZ
[baseLevel
] ||
305 t
->NegZ
[baseLevel
]->Width2
!= w
||
306 t
->NegZ
[baseLevel
]->Height2
!= h
) {
307 t
->Complete
= GL_FALSE
;
308 incomplete(t
, "Non-quare cubemap image");
313 if (t
->MinFilter
!= GL_NEAREST
&& t
->MinFilter
!= GL_LINEAR
) {
315 * Mipmapping: determine if we have a complete set of mipmaps
318 GLint minLevel
= baseLevel
;
319 GLint maxLevel
= t
->_MaxLevel
;
321 if (minLevel
> maxLevel
) {
322 t
->Complete
= GL_FALSE
;
323 incomplete(t
, "minLevel > maxLevel");
327 /* Test dimension-independent attributes */
328 for (i
= minLevel
; i
<= maxLevel
; i
++) {
330 if (t
->Image
[i
]->TexFormat
!= t
->Image
[baseLevel
]->TexFormat
) {
331 t
->Complete
= GL_FALSE
;
332 incomplete(t
, "Format[i] != Format[baseLevel]");
335 if (t
->Image
[i
]->Border
!= t
->Image
[baseLevel
]->Border
) {
336 t
->Complete
= GL_FALSE
;
337 incomplete(t
, "Border[i] != Border[baseLevel]");
343 /* Test things which depend on number of texture image dimensions */
344 if (t
->Target
== GL_TEXTURE_1D
) {
345 /* Test 1-D mipmaps */
346 GLuint width
= t
->Image
[baseLevel
]->Width2
;
347 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
351 if (i
>= minLevel
&& i
<= maxLevel
) {
353 t
->Complete
= GL_FALSE
;
354 incomplete(t
, "1D Image[i] == NULL");
357 if (t
->Image
[i
]->Width2
!= width
) {
358 t
->Complete
= GL_FALSE
;
359 incomplete(t
, "1D Image[i] bad width");
364 return; /* found smallest needed mipmap, all done! */
368 else if (t
->Target
== GL_TEXTURE_2D
) {
369 /* Test 2-D mipmaps */
370 GLuint width
= t
->Image
[baseLevel
]->Width2
;
371 GLuint height
= t
->Image
[baseLevel
]->Height2
;
372 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
379 if (i
>= minLevel
&& i
<= maxLevel
) {
381 t
->Complete
= GL_FALSE
;
382 incomplete(t
, "2D Image[i] == NULL");
385 if (t
->Image
[i
]->Width2
!= width
) {
386 t
->Complete
= GL_FALSE
;
387 incomplete(t
, "2D Image[i] bad width");
390 if (t
->Image
[i
]->Height2
!= height
) {
391 t
->Complete
= GL_FALSE
;
392 incomplete(t
, "2D Image[i] bad height");
395 if (width
==1 && height
==1) {
396 return; /* found smallest needed mipmap, all done! */
401 else if (t
->Target
== GL_TEXTURE_3D
) {
402 /* Test 3-D mipmaps */
403 GLuint width
= t
->Image
[baseLevel
]->Width2
;
404 GLuint height
= t
->Image
[baseLevel
]->Height2
;
405 GLuint depth
= t
->Image
[baseLevel
]->Depth2
;
406 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
416 if (i
>= minLevel
&& i
<= maxLevel
) {
418 incomplete(t
, "3D Image[i] == NULL");
419 t
->Complete
= GL_FALSE
;
422 if (t
->Image
[i
]->Format
== GL_DEPTH_COMPONENT
) {
423 t
->Complete
= GL_FALSE
;
424 incomplete(t
, "GL_DEPTH_COMPONENT only works with 1/2D tex");
427 if (t
->Image
[i
]->Width2
!= width
) {
428 t
->Complete
= GL_FALSE
;
429 incomplete(t
, "3D Image[i] bad width");
432 if (t
->Image
[i
]->Height2
!= height
) {
433 t
->Complete
= GL_FALSE
;
434 incomplete(t
, "3D Image[i] bad height");
437 if (t
->Image
[i
]->Depth2
!= depth
) {
438 t
->Complete
= GL_FALSE
;
439 incomplete(t
, "3D Image[i] bad depth");
443 if (width
== 1 && height
== 1 && depth
== 1) {
444 return; /* found smallest needed mipmap, all done! */
448 else if (t
->Target
== GL_TEXTURE_CUBE_MAP_ARB
) {
449 /* make sure 6 cube faces are consistant */
450 GLuint width
= t
->Image
[baseLevel
]->Width2
;
451 GLuint height
= t
->Image
[baseLevel
]->Height2
;
452 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
459 if (i
>= minLevel
&& i
<= maxLevel
) {
460 /* Don't support GL_DEPTH_COMPONENT for cube maps */
461 if (t
->Image
[i
]->Format
== GL_DEPTH_COMPONENT
) {
462 t
->Complete
= GL_FALSE
;
463 incomplete(t
, "GL_DEPTH_COMPONENT only works with 1/2D tex");
466 /* check that we have images defined */
467 if (!t
->Image
[i
] || !t
->NegX
[i
] ||
468 !t
->PosY
[i
] || !t
->NegY
[i
] ||
469 !t
->PosZ
[i
] || !t
->NegZ
[i
]) {
470 t
->Complete
= GL_FALSE
;
471 incomplete(t
, "CubeMap Image[i] == NULL");
474 /* check that all six images have same size */
475 if (t
->NegX
[i
]->Width2
!=width
|| t
->NegX
[i
]->Height2
!=height
||
476 t
->PosY
[i
]->Width2
!=width
|| t
->PosY
[i
]->Height2
!=height
||
477 t
->NegY
[i
]->Width2
!=width
|| t
->NegY
[i
]->Height2
!=height
||
478 t
->PosZ
[i
]->Width2
!=width
|| t
->PosZ
[i
]->Height2
!=height
||
479 t
->NegZ
[i
]->Width2
!=width
|| t
->NegZ
[i
]->Height2
!=height
) {
480 t
->Complete
= GL_FALSE
;
481 incomplete(t
, "CubeMap Image[i] bad size");
485 if (width
== 1 && height
== 1) {
486 return; /* found smallest needed mipmap, all done! */
490 else if (t
->Target
== GL_TEXTURE_RECTANGLE_NV
) {
491 /* XXX special checking? */
496 _mesa_problem(ctx
, "Bug in gl_test_texture_object_completeness\n");
502 _glthread_DECLARE_STATIC_MUTEX(GenTexturesLock
);
506 * Execute glGenTextures
509 _mesa_GenTextures( GLsizei n
, GLuint
*texName
)
511 GET_CURRENT_CONTEXT(ctx
);
514 ASSERT_OUTSIDE_BEGIN_END(ctx
);
517 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGenTextures" );
525 * This must be atomic (generation and allocation of texture IDs)
527 _glthread_LOCK_MUTEX(GenTexturesLock
);
529 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->TexObjects
, n
);
531 /* Return the texture names */
533 texName
[i
] = first
+ i
;
536 /* Allocate new, empty texture objects */
538 GLuint name
= first
+ i
;
540 (void) _mesa_alloc_texture_object( ctx
->Shared
, name
, target
);
543 _glthread_UNLOCK_MUTEX(GenTexturesLock
);
549 * Execute glDeleteTextures
552 _mesa_DeleteTextures( GLsizei n
, const GLuint
*texName
)
554 GET_CURRENT_CONTEXT(ctx
);
556 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* too complex */
562 if (texName
[i
] > 0) {
563 struct gl_texture_object
*delObj
= (struct gl_texture_object
*)
564 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texName
[i
]);
566 /* First check if this texture is currently bound.
567 * If so, unbind it and decrement the reference count.
570 for (u
= 0; u
< MAX_TEXTURE_UNITS
; u
++) {
571 struct gl_texture_unit
*unit
= &ctx
->Texture
.Unit
[u
];
572 if (delObj
== unit
->Current1D
) {
573 unit
->Current1D
= ctx
->Shared
->Default1D
;
574 ctx
->Shared
->Default1D
->RefCount
++;
575 if (delObj
== unit
->_Current
)
576 unit
->_Current
= unit
->Current1D
;
578 else if (delObj
== unit
->Current2D
) {
579 unit
->Current2D
= ctx
->Shared
->Default2D
;
580 ctx
->Shared
->Default2D
->RefCount
++;
581 if (delObj
== unit
->_Current
)
582 unit
->_Current
= unit
->Current2D
;
584 else if (delObj
== unit
->Current3D
) {
585 unit
->Current3D
= ctx
->Shared
->Default3D
;
586 ctx
->Shared
->Default3D
->RefCount
++;
587 if (delObj
== unit
->_Current
)
588 unit
->_Current
= unit
->Current3D
;
590 else if (delObj
== unit
->CurrentCubeMap
) {
591 unit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
592 ctx
->Shared
->DefaultCubeMap
->RefCount
++;
593 if (delObj
== unit
->_Current
)
594 unit
->_Current
= unit
->CurrentCubeMap
;
597 ctx
->NewState
|= _NEW_TEXTURE
;
599 /* Decrement reference count and delete if zero */
601 ASSERT(delObj
->RefCount
>= 0);
603 if (delObj
->RefCount
== 0) {
604 ASSERT(delObj
->Name
!= 0);
605 if (ctx
->Driver
.DeleteTexture
)
606 (*ctx
->Driver
.DeleteTexture
)( ctx
, delObj
);
607 _mesa_free_texture_object(ctx
->Shared
, delObj
);
617 * Execute glBindTexture
620 _mesa_BindTexture( GLenum target
, GLuint texName
)
622 GET_CURRENT_CONTEXT(ctx
);
623 GLuint unit
= ctx
->Texture
.CurrentUnit
;
624 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
625 struct gl_texture_object
*oldTexObj
;
626 struct gl_texture_object
*newTexObj
= 0;
627 ASSERT_OUTSIDE_BEGIN_END(ctx
);
629 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
630 _mesa_debug(ctx
, "glBindTexture %s %d\n",
631 _mesa_lookup_enum_by_nr(target
), (GLint
) texName
);
635 oldTexObj
= texUnit
->Current1D
;
638 oldTexObj
= texUnit
->Current2D
;
641 oldTexObj
= texUnit
->Current3D
;
643 case GL_TEXTURE_CUBE_MAP_ARB
:
644 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
645 _mesa_error( ctx
, GL_INVALID_ENUM
, "glBindTexture(target)" );
648 oldTexObj
= texUnit
->CurrentCubeMap
;
650 case GL_TEXTURE_RECTANGLE_NV
:
651 if (!ctx
->Extensions
.NV_texture_rectangle
) {
652 _mesa_error( ctx
, GL_INVALID_ENUM
, "glBindTexture(target)" );
655 oldTexObj
= texUnit
->CurrentRect
;
658 _mesa_error( ctx
, GL_INVALID_ENUM
, "glBindTexture(target)" );
662 if (oldTexObj
->Name
== texName
)
663 return; /* rebinding the same texture- no change */
666 * Get pointer to new texture object (newTexObj)
669 /* newTexObj = a default texture object */
672 newTexObj
= ctx
->Shared
->Default1D
;
675 newTexObj
= ctx
->Shared
->Default2D
;
678 newTexObj
= ctx
->Shared
->Default3D
;
680 case GL_TEXTURE_CUBE_MAP_ARB
:
681 newTexObj
= ctx
->Shared
->DefaultCubeMap
;
683 case GL_TEXTURE_RECTANGLE_NV
:
684 newTexObj
= ctx
->Shared
->DefaultRect
;
687 ; /* Bad targets are caught above */
691 /* non-default texture object */
692 const struct _mesa_HashTable
*hash
= ctx
->Shared
->TexObjects
;
693 newTexObj
= (struct gl_texture_object
*) _mesa_HashLookup(hash
, texName
);
696 if (newTexObj
->Target
!= 0 && newTexObj
->Target
!= target
) {
697 /* the named texture object's dimensions don't match the target */
698 _mesa_error( ctx
, GL_INVALID_OPERATION
,
699 "glBindTexture(wrong dimensionality)" );
702 if (newTexObj
->Target
== 0 && target
== GL_TEXTURE_RECTANGLE_NV
) {
703 /* have to init wrap and filter state here - kind of klunky */
704 newTexObj
->WrapS
= GL_CLAMP_TO_EDGE
;
705 newTexObj
->WrapT
= GL_CLAMP_TO_EDGE
;
706 newTexObj
->WrapR
= GL_CLAMP_TO_EDGE
;
707 newTexObj
->MinFilter
= GL_LINEAR
;
711 /* if this is a new texture id, allocate a texture object now */
712 newTexObj
= _mesa_alloc_texture_object( ctx
->Shared
, texName
,
715 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindTexture");
719 newTexObj
->Target
= target
;
722 newTexObj
->RefCount
++;
724 /* do the actual binding, but first flush outstanding vertices:
726 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
730 texUnit
->Current1D
= newTexObj
;
733 texUnit
->Current2D
= newTexObj
;
736 texUnit
->Current3D
= newTexObj
;
738 case GL_TEXTURE_CUBE_MAP_ARB
:
739 texUnit
->CurrentCubeMap
= newTexObj
;
741 case GL_TEXTURE_RECTANGLE_NV
:
742 texUnit
->CurrentRect
= newTexObj
;
745 _mesa_problem(ctx
, "bad target in BindTexture");
749 /* Pass BindTexture call to device driver */
750 if (ctx
->Driver
.BindTexture
)
751 (*ctx
->Driver
.BindTexture
)( ctx
, target
, newTexObj
);
753 oldTexObj
->RefCount
--;
754 assert(oldTexObj
->RefCount
>= 0);
755 if (oldTexObj
->RefCount
== 0) {
756 assert(oldTexObj
->Name
!= 0);
757 if (ctx
->Driver
.DeleteTexture
) {
758 (*ctx
->Driver
.DeleteTexture
)( ctx
, oldTexObj
);
760 _mesa_free_texture_object(ctx
->Shared
, oldTexObj
);
767 * Execute glPrioritizeTextures
770 _mesa_PrioritizeTextures( GLsizei n
, const GLuint
*texName
,
771 const GLclampf
*priorities
)
773 GET_CURRENT_CONTEXT(ctx
);
775 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
778 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPrioritizeTextures" );
785 for (i
= 0; i
< n
; i
++) {
786 if (texName
[i
] > 0) {
787 struct gl_texture_object
*t
= (struct gl_texture_object
*)
788 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texName
[i
]);
790 t
->Priority
= CLAMP( priorities
[i
], 0.0F
, 1.0F
);
791 if (ctx
->Driver
.PrioritizeTexture
)
792 ctx
->Driver
.PrioritizeTexture( ctx
, t
, t
->Priority
);
797 ctx
->NewState
|= _NEW_TEXTURE
;
803 * Execute glAreTexturesResident
806 _mesa_AreTexturesResident(GLsizei n
, const GLuint
*texName
,
807 GLboolean
*residences
)
809 GET_CURRENT_CONTEXT(ctx
);
810 GLboolean allResident
= GL_TRUE
;
812 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
815 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident(n)");
819 if (!texName
|| !residences
)
822 for (i
= 0; i
< n
; i
++) {
823 struct gl_texture_object
*t
;
824 if (texName
[i
] == 0) {
825 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident(textures)");
828 t
= (struct gl_texture_object
*)
829 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texName
[i
]);
831 if (ctx
->Driver
.IsTextureResident
) {
832 residences
[i
] = ctx
->Driver
.IsTextureResident(ctx
, t
);
834 allResident
= GL_FALSE
;
837 residences
[i
] = GL_TRUE
;
841 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident(textures)");
851 * Execute glIsTexture
854 _mesa_IsTexture( GLuint texture
)
856 GET_CURRENT_CONTEXT(ctx
);
857 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
858 return texture
> 0 && _mesa_HashLookup(ctx
->Shared
->TexObjects
, texture
);