1 /* $Id: texobj.c,v 1.62 2002/10/24 23:57:21 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.
41 * Allocate a new texture object and add it to the linked list of texture
42 * objects. If name>0 then also insert the new texture object into the hash
44 * Input: shared - the shared GL state structure to contain the texture object
45 * name - integer name for the texture object
46 * target - either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
47 * GL_TEXTURE_CUBE_MAP_ARB or GL_TEXTURE_RECTANGLE_NV
48 * zero is ok for the sake of GenTextures()
49 * Return: pointer to new texture object
51 struct gl_texture_object
*
52 _mesa_alloc_texture_object( struct gl_shared_state
*shared
,
53 GLuint name
, GLenum target
)
55 struct gl_texture_object
*obj
;
58 target
== GL_TEXTURE_1D
||
59 target
== GL_TEXTURE_2D
||
60 target
== GL_TEXTURE_3D
||
61 target
== GL_TEXTURE_CUBE_MAP_ARB
||
62 target
== GL_TEXTURE_RECTANGLE_NV
);
64 obj
= CALLOC_STRUCT(gl_texture_object
);
67 /* init the non-zero fields */
68 _glthread_INIT_MUTEX(obj
->Mutex
);
73 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
74 obj
->WrapS
= GL_CLAMP_TO_EDGE
;
75 obj
->WrapT
= GL_CLAMP_TO_EDGE
;
76 obj
->WrapR
= GL_CLAMP_TO_EDGE
;
77 obj
->MinFilter
= GL_LINEAR
;
80 obj
->WrapS
= GL_REPEAT
;
81 obj
->WrapT
= GL_REPEAT
;
82 obj
->WrapR
= GL_REPEAT
;
83 obj
->MinFilter
= GL_NEAREST_MIPMAP_LINEAR
;
85 obj
->MagFilter
= GL_LINEAR
;
86 obj
->MinLod
= -1000.0;
90 obj
->MaxAnisotropy
= 1.0;
91 obj
->CompareFlag
= GL_FALSE
; /* SGIX_shadow */
92 obj
->CompareOperator
= GL_TEXTURE_LEQUAL_R_SGIX
; /* SGIX_shadow */
93 obj
->CompareMode
= GL_LUMINANCE
; /* ARB_shadow */
94 obj
->CompareFunc
= GL_LEQUAL
; /* ARB_shadow */
95 obj
->DepthMode
= GL_LUMINANCE
; /* ARB_depth_texture */
96 obj
->ShadowAmbient
= 0.0F
; /* ARB/SGIX_shadow_ambient */
97 _mesa_init_colortable(&obj
->Palette
);
99 /* insert into linked list */
101 _glthread_LOCK_MUTEX(shared
->Mutex
);
102 obj
->Next
= shared
->TexObjectList
;
103 shared
->TexObjectList
= obj
;
104 _glthread_UNLOCK_MUTEX(shared
->Mutex
);
108 /* insert into hash table */
109 _mesa_HashInsert(shared
->TexObjects
, name
, obj
);
117 * Deallocate a texture object struct and remove it from the given
119 * Input: shared - the shared GL state to which the object belongs
120 * t - the texture object to delete
122 void _mesa_free_texture_object( struct gl_shared_state
*shared
,
123 struct gl_texture_object
*t
)
125 struct gl_texture_object
*tprev
, *tcurr
;
129 /* unlink t from the linked list */
131 _glthread_LOCK_MUTEX(shared
->Mutex
);
133 tcurr
= shared
->TexObjectList
;
137 tprev
->Next
= t
->Next
;
140 shared
->TexObjectList
= t
->Next
;
147 _glthread_UNLOCK_MUTEX(shared
->Mutex
);
151 /* remove from hash table */
152 _mesa_HashRemove(shared
->TexObjects
, t
->Name
);
155 _mesa_free_colortable_data(&t
->Palette
);
157 /* free the texture images */
160 for (i
=0;i
<MAX_TEXTURE_LEVELS
;i
++) {
162 _mesa_free_texture_image( t
->Image
[i
] );
167 /* free this object */
173 * Copy texture object state from one texture object to another.
176 _mesa_copy_texture_object( struct gl_texture_object
*dest
,
177 const struct gl_texture_object
*src
)
179 dest
->Name
= src
->Name
;
180 dest
->Priority
= src
->Priority
;
181 dest
->BorderColor
[0] = src
->BorderColor
[0];
182 dest
->BorderColor
[1] = src
->BorderColor
[1];
183 dest
->BorderColor
[2] = src
->BorderColor
[2];
184 dest
->BorderColor
[3] = src
->BorderColor
[3];
185 dest
->WrapS
= src
->WrapS
;
186 dest
->WrapT
= src
->WrapT
;
187 dest
->WrapR
= src
->WrapR
;
188 dest
->MinFilter
= src
->MinFilter
;
189 dest
->MagFilter
= src
->MagFilter
;
190 dest
->MinLod
= src
->MinLod
;
191 dest
->MaxLod
= src
->MaxLod
;
192 dest
->BaseLevel
= src
->BaseLevel
;
193 dest
->MaxLevel
= src
->MaxLevel
;
194 dest
->MaxAnisotropy
= src
->MaxAnisotropy
;
195 dest
->CompareFlag
= src
->CompareFlag
;
196 dest
->CompareOperator
= src
->CompareOperator
;
197 dest
->ShadowAmbient
= src
->ShadowAmbient
;
198 dest
->CompareMode
= src
->CompareMode
;
199 dest
->CompareFunc
= src
->CompareFunc
;
200 dest
->DepthMode
= src
->DepthMode
;
201 dest
->_MaxLevel
= src
->_MaxLevel
;
202 dest
->_MaxLambda
= src
->_MaxLambda
;
203 dest
->GenerateMipmap
= src
->GenerateMipmap
;
204 dest
->Palette
= src
->Palette
;
205 dest
->Complete
= src
->Complete
;
210 * Report why a texture object is incomplete. (for debug only)
214 incomplete(const struct gl_texture_object
*t
, const char *why
)
216 _mesa_printf("Texture Obj %d incomplete because: %s\n", t
->Name
, why
);
219 #define incomplete(a, b)
224 * Examine a texture object to determine if it is complete.
225 * The t->Complete flag will be set to GL_TRUE or GL_FALSE accordingly.
228 _mesa_test_texobj_completeness( const GLcontext
*ctx
,
229 struct gl_texture_object
*t
)
231 const GLint baseLevel
= t
->BaseLevel
;
232 GLint maxLog2
= 0, maxLevels
= 0;
234 t
->Complete
= GL_TRUE
; /* be optimistic */
236 /* Always need the base level image */
237 if (!t
->Image
[baseLevel
]) {
238 incomplete(t
, "Image[baseLevel] == NULL");
239 t
->Complete
= GL_FALSE
;
243 /* Compute _MaxLevel */
244 if (t
->Target
== GL_TEXTURE_1D
) {
245 maxLog2
= t
->Image
[baseLevel
]->WidthLog2
;
246 maxLevels
= ctx
->Const
.MaxTextureLevels
;
248 else if (t
->Target
== GL_TEXTURE_2D
) {
249 maxLog2
= MAX2(t
->Image
[baseLevel
]->WidthLog2
,
250 t
->Image
[baseLevel
]->HeightLog2
);
251 maxLevels
= ctx
->Const
.MaxTextureLevels
;
253 else if (t
->Target
== GL_TEXTURE_3D
) {
254 GLint max
= MAX2(t
->Image
[baseLevel
]->WidthLog2
,
255 t
->Image
[baseLevel
]->HeightLog2
);
256 maxLog2
= MAX2(max
, (GLint
)(t
->Image
[baseLevel
]->DepthLog2
));
257 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
259 else if (t
->Target
== GL_TEXTURE_CUBE_MAP_ARB
) {
260 maxLog2
= MAX2(t
->Image
[baseLevel
]->WidthLog2
,
261 t
->Image
[baseLevel
]->HeightLog2
);
262 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
264 else if (t
->Target
== GL_TEXTURE_RECTANGLE_NV
) {
265 maxLog2
= 0; /* not applicable */
266 maxLevels
= 1; /* no mipmapping */
269 _mesa_problem(ctx
, "Bad t->Target in _mesa_test_texobj_completeness");
273 ASSERT(maxLevels
> 0);
275 t
->_MaxLevel
= baseLevel
+ maxLog2
;
276 t
->_MaxLevel
= MIN2(t
->_MaxLevel
, t
->MaxLevel
);
277 t
->_MaxLevel
= MIN2(t
->_MaxLevel
, maxLevels
- 1);
279 /* Compute _MaxLambda = q - b (see the 1.2 spec) used during mipmapping */
280 t
->_MaxLambda
= (GLfloat
) (t
->_MaxLevel
- t
->BaseLevel
);
282 if (t
->Target
== GL_TEXTURE_CUBE_MAP_ARB
) {
283 /* make sure that all six cube map level 0 images are the same size */
284 const GLuint w
= t
->Image
[baseLevel
]->Width2
;
285 const GLuint h
= t
->Image
[baseLevel
]->Height2
;
286 if (!t
->NegX
[baseLevel
] ||
287 t
->NegX
[baseLevel
]->Width2
!= w
||
288 t
->NegX
[baseLevel
]->Height2
!= h
||
289 !t
->PosY
[baseLevel
] ||
290 t
->PosY
[baseLevel
]->Width2
!= w
||
291 t
->PosY
[baseLevel
]->Height2
!= h
||
292 !t
->NegY
[baseLevel
] ||
293 t
->NegY
[baseLevel
]->Width2
!= w
||
294 t
->NegY
[baseLevel
]->Height2
!= h
||
295 !t
->PosZ
[baseLevel
] ||
296 t
->PosZ
[baseLevel
]->Width2
!= w
||
297 t
->PosZ
[baseLevel
]->Height2
!= h
||
298 !t
->NegZ
[baseLevel
] ||
299 t
->NegZ
[baseLevel
]->Width2
!= w
||
300 t
->NegZ
[baseLevel
]->Height2
!= h
) {
301 t
->Complete
= GL_FALSE
;
302 incomplete(t
, "Non-quare cubemap image");
307 if (t
->MinFilter
!= GL_NEAREST
&& t
->MinFilter
!= GL_LINEAR
) {
309 * Mipmapping: determine if we have a complete set of mipmaps
312 GLint minLevel
= baseLevel
;
313 GLint maxLevel
= t
->_MaxLevel
;
315 if (minLevel
> maxLevel
) {
316 t
->Complete
= GL_FALSE
;
317 incomplete(t
, "minLevel > maxLevel");
321 /* Test dimension-independent attributes */
322 for (i
= minLevel
; i
<= maxLevel
; i
++) {
324 if (t
->Image
[i
]->TexFormat
!= t
->Image
[baseLevel
]->TexFormat
) {
325 t
->Complete
= GL_FALSE
;
326 incomplete(t
, "Format[i] != Format[baseLevel]");
329 if (t
->Image
[i
]->Border
!= t
->Image
[baseLevel
]->Border
) {
330 t
->Complete
= GL_FALSE
;
331 incomplete(t
, "Border[i] != Border[baseLevel]");
337 /* Test things which depend on number of texture image dimensions */
338 if (t
->Target
== GL_TEXTURE_1D
) {
339 /* Test 1-D mipmaps */
340 GLuint width
= t
->Image
[baseLevel
]->Width2
;
341 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
345 if (i
>= minLevel
&& i
<= maxLevel
) {
347 t
->Complete
= GL_FALSE
;
348 incomplete(t
, "1D Image[i] == NULL");
351 if (t
->Image
[i
]->Width2
!= width
) {
352 t
->Complete
= GL_FALSE
;
353 incomplete(t
, "1D Image[i] bad width");
358 return; /* found smallest needed mipmap, all done! */
362 else if (t
->Target
== GL_TEXTURE_2D
) {
363 /* Test 2-D mipmaps */
364 GLuint width
= t
->Image
[baseLevel
]->Width2
;
365 GLuint height
= t
->Image
[baseLevel
]->Height2
;
366 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
373 if (i
>= minLevel
&& i
<= maxLevel
) {
375 t
->Complete
= GL_FALSE
;
376 incomplete(t
, "2D Image[i] == NULL");
379 if (t
->Image
[i
]->Width2
!= width
) {
380 t
->Complete
= GL_FALSE
;
381 incomplete(t
, "2D Image[i] bad width");
384 if (t
->Image
[i
]->Height2
!= height
) {
385 t
->Complete
= GL_FALSE
;
386 incomplete(t
, "2D Image[i] bad height");
389 if (width
==1 && height
==1) {
390 return; /* found smallest needed mipmap, all done! */
395 else if (t
->Target
== GL_TEXTURE_3D
) {
396 /* Test 3-D mipmaps */
397 GLuint width
= t
->Image
[baseLevel
]->Width2
;
398 GLuint height
= t
->Image
[baseLevel
]->Height2
;
399 GLuint depth
= t
->Image
[baseLevel
]->Depth2
;
400 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
410 if (i
>= minLevel
&& i
<= maxLevel
) {
412 incomplete(t
, "3D Image[i] == NULL");
413 t
->Complete
= GL_FALSE
;
416 if (t
->Image
[i
]->Format
== GL_DEPTH_COMPONENT
) {
417 t
->Complete
= GL_FALSE
;
418 incomplete(t
, "GL_DEPTH_COMPONENT only works with 1/2D tex");
421 if (t
->Image
[i
]->Width2
!= width
) {
422 t
->Complete
= GL_FALSE
;
423 incomplete(t
, "3D Image[i] bad width");
426 if (t
->Image
[i
]->Height2
!= height
) {
427 t
->Complete
= GL_FALSE
;
428 incomplete(t
, "3D Image[i] bad height");
431 if (t
->Image
[i
]->Depth2
!= depth
) {
432 t
->Complete
= GL_FALSE
;
433 incomplete(t
, "3D Image[i] bad depth");
437 if (width
== 1 && height
== 1 && depth
== 1) {
438 return; /* found smallest needed mipmap, all done! */
442 else if (t
->Target
== GL_TEXTURE_CUBE_MAP_ARB
) {
443 /* make sure 6 cube faces are consistant */
444 GLuint width
= t
->Image
[baseLevel
]->Width2
;
445 GLuint height
= t
->Image
[baseLevel
]->Height2
;
446 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
453 if (i
>= minLevel
&& i
<= maxLevel
) {
454 /* Don't support GL_DEPTH_COMPONENT for cube maps */
455 if (t
->Image
[i
]->Format
== GL_DEPTH_COMPONENT
) {
456 t
->Complete
= GL_FALSE
;
457 incomplete(t
, "GL_DEPTH_COMPONENT only works with 1/2D tex");
460 /* check that we have images defined */
461 if (!t
->Image
[i
] || !t
->NegX
[i
] ||
462 !t
->PosY
[i
] || !t
->NegY
[i
] ||
463 !t
->PosZ
[i
] || !t
->NegZ
[i
]) {
464 t
->Complete
= GL_FALSE
;
465 incomplete(t
, "CubeMap Image[i] == NULL");
468 /* check that all six images have same size */
469 if (t
->NegX
[i
]->Width2
!=width
|| t
->NegX
[i
]->Height2
!=height
||
470 t
->PosY
[i
]->Width2
!=width
|| t
->PosY
[i
]->Height2
!=height
||
471 t
->NegY
[i
]->Width2
!=width
|| t
->NegY
[i
]->Height2
!=height
||
472 t
->PosZ
[i
]->Width2
!=width
|| t
->PosZ
[i
]->Height2
!=height
||
473 t
->NegZ
[i
]->Width2
!=width
|| t
->NegZ
[i
]->Height2
!=height
) {
474 t
->Complete
= GL_FALSE
;
475 incomplete(t
, "CubeMap Image[i] bad size");
479 if (width
== 1 && height
== 1) {
480 return; /* found smallest needed mipmap, all done! */
484 else if (t
->Target
== GL_TEXTURE_RECTANGLE_NV
) {
485 /* XXX special checking? */
490 _mesa_problem(ctx
, "Bug in gl_test_texture_object_completeness\n");
496 _glthread_DECLARE_STATIC_MUTEX(GenTexturesLock
);
500 * Execute glGenTextures
503 _mesa_GenTextures( GLsizei n
, GLuint
*texName
)
505 GET_CURRENT_CONTEXT(ctx
);
508 ASSERT_OUTSIDE_BEGIN_END(ctx
);
511 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGenTextures" );
519 * This must be atomic (generation and allocation of texture IDs)
521 _glthread_LOCK_MUTEX(GenTexturesLock
);
523 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->TexObjects
, n
);
525 /* Return the texture names */
527 texName
[i
] = first
+ i
;
530 /* Allocate new, empty texture objects */
532 GLuint name
= first
+ i
;
534 (void) _mesa_alloc_texture_object( ctx
->Shared
, name
, target
);
537 _glthread_UNLOCK_MUTEX(GenTexturesLock
);
543 * Execute glDeleteTextures
546 _mesa_DeleteTextures( GLsizei n
, const GLuint
*texName
)
548 GET_CURRENT_CONTEXT(ctx
);
550 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* too complex */
556 if (texName
[i
] > 0) {
557 struct gl_texture_object
*delObj
= (struct gl_texture_object
*)
558 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texName
[i
]);
560 /* First check if this texture is currently bound.
561 * If so, unbind it and decrement the reference count.
564 for (u
= 0; u
< MAX_TEXTURE_UNITS
; u
++) {
565 struct gl_texture_unit
*unit
= &ctx
->Texture
.Unit
[u
];
566 if (delObj
== unit
->Current1D
) {
567 unit
->Current1D
= ctx
->Shared
->Default1D
;
568 ctx
->Shared
->Default1D
->RefCount
++;
570 if (delObj
== unit
->_Current
)
571 unit
->_Current
= unit
->Current1D
;
573 else if (delObj
== unit
->Current2D
) {
574 unit
->Current2D
= ctx
->Shared
->Default2D
;
575 ctx
->Shared
->Default2D
->RefCount
++;
577 if (delObj
== unit
->_Current
)
578 unit
->_Current
= unit
->Current2D
;
580 else if (delObj
== unit
->Current3D
) {
581 unit
->Current3D
= ctx
->Shared
->Default3D
;
582 ctx
->Shared
->Default3D
->RefCount
++;
584 if (delObj
== unit
->_Current
)
585 unit
->_Current
= unit
->Current3D
;
587 else if (delObj
== unit
->CurrentCubeMap
) {
588 unit
->CurrentCubeMap
= ctx
->Shared
->DefaultCubeMap
;
589 ctx
->Shared
->DefaultCubeMap
->RefCount
++;
591 if (delObj
== unit
->_Current
)
592 unit
->_Current
= unit
->CurrentCubeMap
;
594 else if (delObj
== unit
->CurrentRect
) {
595 unit
->CurrentRect
= ctx
->Shared
->DefaultRect
;
596 ctx
->Shared
->DefaultRect
->RefCount
++;
598 if (delObj
== unit
->_Current
)
599 unit
->_Current
= unit
->CurrentRect
;
602 ctx
->NewState
|= _NEW_TEXTURE
;
604 /* Decrement reference count and delete if zero */
606 ASSERT(delObj
->RefCount
>= 0);
608 if (delObj
->RefCount
== 0) {
609 ASSERT(delObj
->Name
!= 0);
610 if (ctx
->Driver
.DeleteTexture
)
611 (*ctx
->Driver
.DeleteTexture
)( ctx
, delObj
);
612 _mesa_free_texture_object(ctx
->Shared
, delObj
);
622 * Execute glBindTexture
625 _mesa_BindTexture( GLenum target
, GLuint texName
)
627 GET_CURRENT_CONTEXT(ctx
);
628 GLuint unit
= ctx
->Texture
.CurrentUnit
;
629 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
630 struct gl_texture_object
*oldTexObj
;
631 struct gl_texture_object
*newTexObj
= 0;
632 ASSERT_OUTSIDE_BEGIN_END(ctx
);
634 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
635 _mesa_debug(ctx
, "glBindTexture %s %d\n",
636 _mesa_lookup_enum_by_nr(target
), (GLint
) texName
);
640 oldTexObj
= texUnit
->Current1D
;
643 oldTexObj
= texUnit
->Current2D
;
646 oldTexObj
= texUnit
->Current3D
;
648 case GL_TEXTURE_CUBE_MAP_ARB
:
649 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
650 _mesa_error( ctx
, GL_INVALID_ENUM
, "glBindTexture(target)" );
653 oldTexObj
= texUnit
->CurrentCubeMap
;
655 case GL_TEXTURE_RECTANGLE_NV
:
656 if (!ctx
->Extensions
.NV_texture_rectangle
) {
657 _mesa_error( ctx
, GL_INVALID_ENUM
, "glBindTexture(target)" );
660 oldTexObj
= texUnit
->CurrentRect
;
663 _mesa_error( ctx
, GL_INVALID_ENUM
, "glBindTexture(target)" );
667 if (oldTexObj
->Name
== texName
)
668 return; /* rebinding the same texture- no change */
671 * Get pointer to new texture object (newTexObj)
674 /* newTexObj = a default texture object */
677 newTexObj
= ctx
->Shared
->Default1D
;
680 newTexObj
= ctx
->Shared
->Default2D
;
683 newTexObj
= ctx
->Shared
->Default3D
;
685 case GL_TEXTURE_CUBE_MAP_ARB
:
686 newTexObj
= ctx
->Shared
->DefaultCubeMap
;
688 case GL_TEXTURE_RECTANGLE_NV
:
689 newTexObj
= ctx
->Shared
->DefaultRect
;
692 ; /* Bad targets are caught above */
696 /* non-default texture object */
697 const struct _mesa_HashTable
*hash
= ctx
->Shared
->TexObjects
;
698 newTexObj
= (struct gl_texture_object
*) _mesa_HashLookup(hash
, texName
);
701 if (newTexObj
->Target
!= 0 && newTexObj
->Target
!= target
) {
702 /* the named texture object's dimensions don't match the target */
703 _mesa_error( ctx
, GL_INVALID_OPERATION
,
704 "glBindTexture(wrong dimensionality)" );
707 if (newTexObj
->Target
== 0 && target
== GL_TEXTURE_RECTANGLE_NV
) {
708 /* have to init wrap and filter state here - kind of klunky */
709 newTexObj
->WrapS
= GL_CLAMP_TO_EDGE
;
710 newTexObj
->WrapT
= GL_CLAMP_TO_EDGE
;
711 newTexObj
->WrapR
= GL_CLAMP_TO_EDGE
;
712 newTexObj
->MinFilter
= GL_LINEAR
;
716 /* if this is a new texture id, allocate a texture object now */
717 newTexObj
= _mesa_alloc_texture_object( ctx
->Shared
, texName
,
720 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindTexture");
724 newTexObj
->Target
= target
;
727 newTexObj
->RefCount
++;
729 /* do the actual binding, but first flush outstanding vertices:
731 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
735 texUnit
->Current1D
= newTexObj
;
738 texUnit
->Current2D
= newTexObj
;
741 texUnit
->Current3D
= newTexObj
;
743 case GL_TEXTURE_CUBE_MAP_ARB
:
744 texUnit
->CurrentCubeMap
= newTexObj
;
746 case GL_TEXTURE_RECTANGLE_NV
:
747 texUnit
->CurrentRect
= newTexObj
;
750 _mesa_problem(ctx
, "bad target in BindTexture");
754 /* Pass BindTexture call to device driver */
755 if (ctx
->Driver
.BindTexture
)
756 (*ctx
->Driver
.BindTexture
)( ctx
, target
, newTexObj
);
758 oldTexObj
->RefCount
--;
759 assert(oldTexObj
->RefCount
>= 0);
760 if (oldTexObj
->RefCount
== 0) {
761 assert(oldTexObj
->Name
!= 0);
762 if (ctx
->Driver
.DeleteTexture
) {
763 (*ctx
->Driver
.DeleteTexture
)( ctx
, oldTexObj
);
765 _mesa_free_texture_object(ctx
->Shared
, oldTexObj
);
772 * Execute glPrioritizeTextures
775 _mesa_PrioritizeTextures( GLsizei n
, const GLuint
*texName
,
776 const GLclampf
*priorities
)
778 GET_CURRENT_CONTEXT(ctx
);
780 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
783 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPrioritizeTextures" );
790 for (i
= 0; i
< n
; i
++) {
791 if (texName
[i
] > 0) {
792 struct gl_texture_object
*t
= (struct gl_texture_object
*)
793 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texName
[i
]);
795 t
->Priority
= CLAMP( priorities
[i
], 0.0F
, 1.0F
);
796 if (ctx
->Driver
.PrioritizeTexture
)
797 ctx
->Driver
.PrioritizeTexture( ctx
, t
, t
->Priority
);
802 ctx
->NewState
|= _NEW_TEXTURE
;
808 * Execute glAreTexturesResident
811 _mesa_AreTexturesResident(GLsizei n
, const GLuint
*texName
,
812 GLboolean
*residences
)
814 GET_CURRENT_CONTEXT(ctx
);
815 GLboolean allResident
= GL_TRUE
;
817 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
820 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident(n)");
824 if (!texName
|| !residences
)
827 for (i
= 0; i
< n
; i
++) {
828 struct gl_texture_object
*t
;
829 if (texName
[i
] == 0) {
830 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident(textures)");
833 t
= (struct gl_texture_object
*)
834 _mesa_HashLookup(ctx
->Shared
->TexObjects
, texName
[i
]);
836 if (ctx
->Driver
.IsTextureResident
) {
837 residences
[i
] = ctx
->Driver
.IsTextureResident(ctx
, t
);
839 allResident
= GL_FALSE
;
842 residences
[i
] = GL_TRUE
;
846 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident(textures)");
856 * Execute glIsTexture
859 _mesa_IsTexture( GLuint texture
)
861 GET_CURRENT_CONTEXT(ctx
);
862 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
863 return texture
> 0 && _mesa_HashLookup(ctx
->Shared
->TexObjects
, texture
);