3 * Texture object management.
7 * Mesa 3-D graphics library
9 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
11 * Permission is hereby granted, free of charge, to any person obtaining a
12 * copy of this software and associated documentation files (the "Software"),
13 * to deal in the Software without restriction, including without limitation
14 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
15 * and/or sell copies of the Software, and to permit persons to whom the
16 * Software is furnished to do so, subject to the following conditions:
18 * The above copyright notice and this permission notice shall be included
19 * in all copies or substantial portions of the Software.
21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
22 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
24 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
25 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
26 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
27 * OTHER DEALINGS IN THE SOFTWARE.
31 #include "bufferobj.h"
44 #include "program/prog_instruction.h"
48 /**********************************************************************/
49 /** \name Internal functions */
54 * Return the gl_texture_object for a given ID.
56 struct gl_texture_object
*
57 _mesa_lookup_texture(struct gl_context
*ctx
, GLuint id
)
59 return (struct gl_texture_object
*)
60 _mesa_HashLookup(ctx
->Shared
->TexObjects
, id
);
66 * Allocate and initialize a new texture object. But don't put it into the
67 * texture object hash table.
69 * Called via ctx->Driver.NewTextureObject, unless overridden by a device
72 * \param shared the shared GL state structure to contain the texture object
73 * \param name integer name for the texture object
74 * \param target either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
75 * GL_TEXTURE_CUBE_MAP_ARB or GL_TEXTURE_RECTANGLE_NV. zero is ok for the sake
78 * \return pointer to new texture object.
80 struct gl_texture_object
*
81 _mesa_new_texture_object( struct gl_context
*ctx
, GLuint name
, GLenum target
)
83 struct gl_texture_object
*obj
;
85 obj
= MALLOC_STRUCT(gl_texture_object
);
86 _mesa_initialize_texture_object(ctx
, obj
, name
, target
);
92 * Initialize a new texture object to default values.
93 * \param obj the texture object
94 * \param name the texture name
95 * \param target the texture target
98 _mesa_initialize_texture_object( struct gl_context
*ctx
,
99 struct gl_texture_object
*obj
,
100 GLuint name
, GLenum target
)
102 ASSERT(target
== 0 ||
103 target
== GL_TEXTURE_1D
||
104 target
== GL_TEXTURE_2D
||
105 target
== GL_TEXTURE_3D
||
106 target
== GL_TEXTURE_CUBE_MAP_ARB
||
107 target
== GL_TEXTURE_RECTANGLE_NV
||
108 target
== GL_TEXTURE_1D_ARRAY_EXT
||
109 target
== GL_TEXTURE_2D_ARRAY_EXT
||
110 target
== GL_TEXTURE_EXTERNAL_OES
||
111 target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
112 target
== GL_TEXTURE_BUFFER
||
113 target
== GL_TEXTURE_2D_MULTISAMPLE
||
114 target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
);
116 memset(obj
, 0, sizeof(*obj
));
117 /* init the non-zero fields */
118 _glthread_INIT_MUTEX(obj
->Mutex
);
121 obj
->Target
= target
;
122 obj
->Priority
= 1.0F
;
124 obj
->MaxLevel
= 1000;
126 /* must be one; no support for (YUV) planes in separate buffers */
127 obj
->RequiredTextureImageUnits
= 1;
130 if (target
== GL_TEXTURE_RECTANGLE_NV
||
131 target
== GL_TEXTURE_EXTERNAL_OES
) {
132 obj
->Sampler
.WrapS
= GL_CLAMP_TO_EDGE
;
133 obj
->Sampler
.WrapT
= GL_CLAMP_TO_EDGE
;
134 obj
->Sampler
.WrapR
= GL_CLAMP_TO_EDGE
;
135 obj
->Sampler
.MinFilter
= GL_LINEAR
;
138 obj
->Sampler
.WrapS
= GL_REPEAT
;
139 obj
->Sampler
.WrapT
= GL_REPEAT
;
140 obj
->Sampler
.WrapR
= GL_REPEAT
;
141 obj
->Sampler
.MinFilter
= GL_NEAREST_MIPMAP_LINEAR
;
143 obj
->Sampler
.MagFilter
= GL_LINEAR
;
144 obj
->Sampler
.MinLod
= -1000.0;
145 obj
->Sampler
.MaxLod
= 1000.0;
146 obj
->Sampler
.LodBias
= 0.0;
147 obj
->Sampler
.MaxAnisotropy
= 1.0;
148 obj
->Sampler
.CompareMode
= GL_NONE
; /* ARB_shadow */
149 obj
->Sampler
.CompareFunc
= GL_LEQUAL
; /* ARB_shadow */
150 obj
->DepthMode
= ctx
->API
== API_OPENGL_CORE
? GL_RED
: GL_LUMINANCE
;
151 obj
->Sampler
.CubeMapSeamless
= GL_FALSE
;
152 obj
->Swizzle
[0] = GL_RED
;
153 obj
->Swizzle
[1] = GL_GREEN
;
154 obj
->Swizzle
[2] = GL_BLUE
;
155 obj
->Swizzle
[3] = GL_ALPHA
;
156 obj
->_Swizzle
= SWIZZLE_NOOP
;
157 obj
->Sampler
.sRGBDecode
= GL_DECODE_EXT
;
158 obj
->BufferObjectFormat
= GL_R8
;
159 obj
->_BufferObjectFormat
= MESA_FORMAT_R8
;
164 * Some texture initialization can't be finished until we know which
165 * target it's getting bound to (GL_TEXTURE_1D/2D/etc).
168 finish_texture_init(struct gl_context
*ctx
, GLenum target
,
169 struct gl_texture_object
*obj
)
171 GLenum filter
= GL_LINEAR
;
172 assert(obj
->Target
== 0);
175 case GL_TEXTURE_2D_MULTISAMPLE
:
176 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
180 case GL_TEXTURE_RECTANGLE_NV
:
181 case GL_TEXTURE_EXTERNAL_OES
:
182 /* have to init wrap and filter state here - kind of klunky */
183 obj
->Sampler
.WrapS
= GL_CLAMP_TO_EDGE
;
184 obj
->Sampler
.WrapT
= GL_CLAMP_TO_EDGE
;
185 obj
->Sampler
.WrapR
= GL_CLAMP_TO_EDGE
;
186 obj
->Sampler
.MinFilter
= filter
;
187 obj
->Sampler
.MagFilter
= filter
;
188 if (ctx
->Driver
.TexParameter
) {
189 static const GLfloat fparam_wrap
[1] = {(GLfloat
) GL_CLAMP_TO_EDGE
};
190 const GLfloat fparam_filter
[1] = {(GLfloat
) filter
};
191 ctx
->Driver
.TexParameter(ctx
, target
, obj
, GL_TEXTURE_WRAP_S
, fparam_wrap
);
192 ctx
->Driver
.TexParameter(ctx
, target
, obj
, GL_TEXTURE_WRAP_T
, fparam_wrap
);
193 ctx
->Driver
.TexParameter(ctx
, target
, obj
, GL_TEXTURE_WRAP_R
, fparam_wrap
);
194 ctx
->Driver
.TexParameter(ctx
, target
, obj
,
195 GL_TEXTURE_MIN_FILTER
, fparam_filter
);
196 ctx
->Driver
.TexParameter(ctx
, target
, obj
,
197 GL_TEXTURE_MAG_FILTER
, fparam_filter
);
202 /* nothing needs done */
209 * Deallocate a texture object struct. It should have already been
210 * removed from the texture object pool.
211 * Called via ctx->Driver.DeleteTexture() if not overriden by a driver.
213 * \param shared the shared GL state to which the object belongs.
214 * \param texObj the texture object to delete.
217 _mesa_delete_texture_object(struct gl_context
*ctx
,
218 struct gl_texture_object
*texObj
)
222 /* Set Target to an invalid value. With some assertions elsewhere
223 * we can try to detect possible use of deleted textures.
225 texObj
->Target
= 0x99;
227 /* free the texture images */
228 for (face
= 0; face
< 6; face
++) {
229 for (i
= 0; i
< MAX_TEXTURE_LEVELS
; i
++) {
230 if (texObj
->Image
[face
][i
]) {
231 ctx
->Driver
.DeleteTextureImage(ctx
, texObj
->Image
[face
][i
]);
236 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, NULL
);
238 /* destroy the mutex -- it may have allocated memory (eg on bsd) */
239 _glthread_DESTROY_MUTEX(texObj
->Mutex
);
241 /* free this object */
248 * Copy texture object state from one texture object to another.
249 * Use for glPush/PopAttrib.
251 * \param dest destination texture object.
252 * \param src source texture object.
255 _mesa_copy_texture_object( struct gl_texture_object
*dest
,
256 const struct gl_texture_object
*src
)
258 dest
->Target
= src
->Target
;
259 dest
->Name
= src
->Name
;
260 dest
->Priority
= src
->Priority
;
261 dest
->Sampler
.BorderColor
.f
[0] = src
->Sampler
.BorderColor
.f
[0];
262 dest
->Sampler
.BorderColor
.f
[1] = src
->Sampler
.BorderColor
.f
[1];
263 dest
->Sampler
.BorderColor
.f
[2] = src
->Sampler
.BorderColor
.f
[2];
264 dest
->Sampler
.BorderColor
.f
[3] = src
->Sampler
.BorderColor
.f
[3];
265 dest
->Sampler
.WrapS
= src
->Sampler
.WrapS
;
266 dest
->Sampler
.WrapT
= src
->Sampler
.WrapT
;
267 dest
->Sampler
.WrapR
= src
->Sampler
.WrapR
;
268 dest
->Sampler
.MinFilter
= src
->Sampler
.MinFilter
;
269 dest
->Sampler
.MagFilter
= src
->Sampler
.MagFilter
;
270 dest
->Sampler
.MinLod
= src
->Sampler
.MinLod
;
271 dest
->Sampler
.MaxLod
= src
->Sampler
.MaxLod
;
272 dest
->Sampler
.LodBias
= src
->Sampler
.LodBias
;
273 dest
->BaseLevel
= src
->BaseLevel
;
274 dest
->MaxLevel
= src
->MaxLevel
;
275 dest
->Sampler
.MaxAnisotropy
= src
->Sampler
.MaxAnisotropy
;
276 dest
->Sampler
.CompareMode
= src
->Sampler
.CompareMode
;
277 dest
->Sampler
.CompareFunc
= src
->Sampler
.CompareFunc
;
278 dest
->Sampler
.CubeMapSeamless
= src
->Sampler
.CubeMapSeamless
;
279 dest
->DepthMode
= src
->DepthMode
;
280 dest
->Sampler
.sRGBDecode
= src
->Sampler
.sRGBDecode
;
281 dest
->_MaxLevel
= src
->_MaxLevel
;
282 dest
->_MaxLambda
= src
->_MaxLambda
;
283 dest
->GenerateMipmap
= src
->GenerateMipmap
;
284 dest
->_BaseComplete
= src
->_BaseComplete
;
285 dest
->_MipmapComplete
= src
->_MipmapComplete
;
286 COPY_4V(dest
->Swizzle
, src
->Swizzle
);
287 dest
->_Swizzle
= src
->_Swizzle
;
289 dest
->RequiredTextureImageUnits
= src
->RequiredTextureImageUnits
;
294 * Free all texture images of the given texture object.
296 * \param ctx GL context.
297 * \param t texture object.
299 * \sa _mesa_clear_texture_image().
302 _mesa_clear_texture_object(struct gl_context
*ctx
,
303 struct gl_texture_object
*texObj
)
307 if (texObj
->Target
== 0)
310 for (i
= 0; i
< MAX_FACES
; i
++) {
311 for (j
= 0; j
< MAX_TEXTURE_LEVELS
; j
++) {
312 struct gl_texture_image
*texImage
= texObj
->Image
[i
][j
];
314 _mesa_clear_texture_image(ctx
, texImage
);
321 * Check if the given texture object is valid by examining its Target field.
322 * For debugging only.
325 valid_texture_object(const struct gl_texture_object
*tex
)
327 switch (tex
->Target
) {
332 case GL_TEXTURE_CUBE_MAP_ARB
:
333 case GL_TEXTURE_RECTANGLE_NV
:
334 case GL_TEXTURE_1D_ARRAY_EXT
:
335 case GL_TEXTURE_2D_ARRAY_EXT
:
336 case GL_TEXTURE_BUFFER
:
337 case GL_TEXTURE_EXTERNAL_OES
:
338 case GL_TEXTURE_CUBE_MAP_ARRAY
:
339 case GL_TEXTURE_2D_MULTISAMPLE
:
340 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
343 _mesa_problem(NULL
, "invalid reference to a deleted texture object");
346 _mesa_problem(NULL
, "invalid texture object Target 0x%x, Id = %u",
347 tex
->Target
, tex
->Name
);
354 * Reference (or unreference) a texture object.
355 * If '*ptr', decrement *ptr's refcount (and delete if it becomes zero).
356 * If 'tex' is non-null, increment its refcount.
357 * This is normally only called from the _mesa_reference_texobj() macro
358 * when there's a real pointer change.
361 _mesa_reference_texobj_(struct gl_texture_object
**ptr
,
362 struct gl_texture_object
*tex
)
367 /* Unreference the old texture */
368 GLboolean deleteFlag
= GL_FALSE
;
369 struct gl_texture_object
*oldTex
= *ptr
;
371 ASSERT(valid_texture_object(oldTex
));
372 (void) valid_texture_object
; /* silence warning in release builds */
374 _glthread_LOCK_MUTEX(oldTex
->Mutex
);
375 ASSERT(oldTex
->RefCount
> 0);
378 deleteFlag
= (oldTex
->RefCount
== 0);
379 _glthread_UNLOCK_MUTEX(oldTex
->Mutex
);
382 GET_CURRENT_CONTEXT(ctx
);
384 ctx
->Driver
.DeleteTexture(ctx
, oldTex
);
386 _mesa_problem(NULL
, "Unable to delete texture, no context");
394 /* reference new texture */
395 ASSERT(valid_texture_object(tex
));
396 _glthread_LOCK_MUTEX(tex
->Mutex
);
397 if (tex
->RefCount
== 0) {
398 /* this texture's being deleted (look just above) */
399 /* Not sure this can every really happen. Warn if it does. */
400 _mesa_problem(NULL
, "referencing deleted texture object");
407 _glthread_UNLOCK_MUTEX(tex
->Mutex
);
412 enum base_mipmap
{ BASE
, MIPMAP
};
416 * Mark a texture object as incomplete. There are actually three kinds of
418 * 1. "base incomplete": the base level of the texture is invalid so no
419 * texturing is possible.
420 * 2. "mipmap incomplete": a non-base level of the texture is invalid so
421 * mipmap filtering isn't possible, but non-mipmap filtering is.
422 * 3. "texture incompleteness": some combination of texture state and
423 * sampler state renders the texture incomplete.
425 * \param t texture object
426 * \param bm either BASE or MIPMAP to indicate what's incomplete
427 * \param fmt... string describing why it's incomplete (for debugging).
430 incomplete(struct gl_texture_object
*t
, enum base_mipmap bm
,
431 const char *fmt
, ...)
433 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_TEXTURE
) {
438 vsnprintf(s
, sizeof(s
), fmt
, args
);
441 _mesa_debug(NULL
, "Texture Obj %d incomplete because: %s\n", t
->Name
, s
);
445 t
->_BaseComplete
= GL_FALSE
;
446 t
->_MipmapComplete
= GL_FALSE
;
451 * Examine a texture object to determine if it is complete.
453 * The gl_texture_object::Complete flag will be set to GL_TRUE or GL_FALSE
456 * \param ctx GL context.
457 * \param t texture object.
459 * According to the texture target, verifies that each of the mipmaps is
460 * present and has the expected size.
463 _mesa_test_texobj_completeness( const struct gl_context
*ctx
,
464 struct gl_texture_object
*t
)
466 const GLint baseLevel
= t
->BaseLevel
;
467 const struct gl_texture_image
*baseImage
;
470 /* We'll set these to FALSE if tests fail below */
471 t
->_BaseComplete
= GL_TRUE
;
472 t
->_MipmapComplete
= GL_TRUE
;
474 if (t
->Target
== GL_TEXTURE_BUFFER
) {
475 /* Buffer textures are always considered complete. The obvious case where
476 * they would be incomplete (no BO attached) is actually specced to be
477 * undefined rendering results.
482 /* Detect cases where the application set the base level to an invalid
485 if ((baseLevel
< 0) || (baseLevel
>= MAX_TEXTURE_LEVELS
)) {
486 incomplete(t
, BASE
, "base level = %d is invalid", baseLevel
);
490 if (t
->MaxLevel
< baseLevel
) {
491 incomplete(t
, MIPMAP
, "MAX_LEVEL (%d) < BASE_LEVEL (%d)",
492 t
->MaxLevel
, baseLevel
);
496 baseImage
= t
->Image
[0][baseLevel
];
498 /* Always need the base level image */
500 incomplete(t
, BASE
, "Image[baseLevel=%d] == NULL", baseLevel
);
504 /* Check width/height/depth for zero */
505 if (baseImage
->Width
== 0 ||
506 baseImage
->Height
== 0 ||
507 baseImage
->Depth
== 0) {
508 incomplete(t
, BASE
, "texture width or height or depth = 0");
512 /* Check if the texture values are integer */
514 GLenum datatype
= _mesa_get_format_datatype(baseImage
->TexFormat
);
515 t
->_IsIntegerFormat
= datatype
== GL_INT
|| datatype
== GL_UNSIGNED_INT
;
518 /* Compute _MaxLevel (the maximum mipmap level we'll sample from given the
519 * mipmap image sizes and GL_TEXTURE_MAX_LEVEL state).
523 case GL_TEXTURE_1D_ARRAY_EXT
:
524 maxLevels
= ctx
->Const
.MaxTextureLevels
;
527 case GL_TEXTURE_2D_ARRAY_EXT
:
528 maxLevels
= ctx
->Const
.MaxTextureLevels
;
531 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
533 case GL_TEXTURE_CUBE_MAP_ARB
:
534 case GL_TEXTURE_CUBE_MAP_ARRAY
:
535 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
537 case GL_TEXTURE_RECTANGLE_NV
:
538 case GL_TEXTURE_BUFFER
:
539 case GL_TEXTURE_EXTERNAL_OES
:
540 case GL_TEXTURE_2D_MULTISAMPLE
:
541 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
542 maxLevels
= 1; /* no mipmapping */
545 _mesa_problem(ctx
, "Bad t->Target in _mesa_test_texobj_completeness");
549 ASSERT(maxLevels
> 0);
551 t
->_MaxLevel
= MIN3(t
->MaxLevel
,
552 /* 'p' in the GL spec */
553 baseLevel
+ baseImage
->MaxNumLevels
- 1,
554 /* 'q' in the GL spec */
557 /* Compute _MaxLambda = q - p in the spec used during mipmapping */
558 t
->_MaxLambda
= (GLfloat
) (t
->_MaxLevel
- baseLevel
);
561 /* This texture object was created with glTexStorage1/2/3D() so we
562 * know that all the mipmap levels are the right size and all cube
563 * map faces are the same size.
564 * We don't need to do any of the additional checks below.
569 if (t
->Target
== GL_TEXTURE_CUBE_MAP_ARB
) {
570 /* Make sure that all six cube map level 0 images are the same size.
571 * Note: we know that the image's width==height (we enforce that
572 * at glTexImage time) so we only need to test the width here.
575 assert(baseImage
->Width2
== baseImage
->Height
);
576 for (face
= 1; face
< 6; face
++) {
577 assert(t
->Image
[face
][baseLevel
] == NULL
||
578 t
->Image
[face
][baseLevel
]->Width2
==
579 t
->Image
[face
][baseLevel
]->Height2
);
580 if (t
->Image
[face
][baseLevel
] == NULL
||
581 t
->Image
[face
][baseLevel
]->Width2
!= baseImage
->Width2
) {
582 incomplete(t
, BASE
, "Cube face missing or mismatched size");
589 * Do mipmap consistency checking.
590 * Note: we don't care about the current texture sampler state here.
591 * To determine texture completeness we'll either look at _BaseComplete
592 * or _MipmapComplete depending on the current minification filter mode.
596 const GLint minLevel
= baseLevel
;
597 const GLint maxLevel
= t
->_MaxLevel
;
598 const GLuint numFaces
= _mesa_num_tex_faces(t
->Target
);
599 GLuint width
, height
, depth
, face
;
601 if (minLevel
> maxLevel
) {
602 incomplete(t
, MIPMAP
, "minLevel > maxLevel");
606 /* Get the base image's dimensions */
607 width
= baseImage
->Width2
;
608 height
= baseImage
->Height2
;
609 depth
= baseImage
->Depth2
;
611 /* Note: this loop will be a no-op for RECT, BUFFER, EXTERNAL,
612 * MULTISAMPLE and MULTISAMPLE_ARRAY textures
614 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
615 /* Compute the expected size of image at level[i] */
619 if (height
> 1 && t
->Target
!= GL_TEXTURE_1D_ARRAY
) {
622 if (depth
> 1 && t
->Target
!= GL_TEXTURE_2D_ARRAY
&& t
->Target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
626 /* loop over cube faces (or single face otherwise) */
627 for (face
= 0; face
< numFaces
; face
++) {
628 if (i
>= minLevel
&& i
<= maxLevel
) {
629 const struct gl_texture_image
*img
= t
->Image
[face
][i
];
632 incomplete(t
, MIPMAP
, "TexImage[%d] is missing", i
);
635 if (img
->TexFormat
!= baseImage
->TexFormat
) {
636 incomplete(t
, MIPMAP
, "Format[i] != Format[baseLevel]");
639 if (img
->Border
!= baseImage
->Border
) {
640 incomplete(t
, MIPMAP
, "Border[i] != Border[baseLevel]");
643 if (img
->Width2
!= width
) {
644 incomplete(t
, MIPMAP
, "TexImage[%d] bad width %u", i
, img
->Width2
);
647 if (img
->Height2
!= height
) {
648 incomplete(t
, MIPMAP
, "TexImage[%d] bad height %u", i
, img
->Height2
);
651 if (img
->Depth2
!= depth
) {
652 incomplete(t
, MIPMAP
, "TexImage[%d] bad depth %u", i
, img
->Depth2
);
656 /* Extra checks for cube textures */
658 /* check that cube faces are the same size */
659 if (img
->Width2
!= t
->Image
[0][i
]->Width2
||
660 img
->Height2
!= t
->Image
[0][i
]->Height2
) {
661 incomplete(t
, MIPMAP
, "CubeMap Image[n][i] bad size");
668 if (width
== 1 && height
== 1 && depth
== 1) {
669 return; /* found smallest needed mipmap, all done! */
677 * Check if the given cube map texture is "cube complete" as defined in
678 * the OpenGL specification.
681 _mesa_cube_complete(const struct gl_texture_object
*texObj
)
683 const GLint baseLevel
= texObj
->BaseLevel
;
684 const struct gl_texture_image
*img0
, *img
;
687 if (texObj
->Target
!= GL_TEXTURE_CUBE_MAP
)
690 if ((baseLevel
< 0) || (baseLevel
>= MAX_TEXTURE_LEVELS
))
693 /* check first face */
694 img0
= texObj
->Image
[0][baseLevel
];
697 img0
->Width
!= img0
->Height
)
700 /* check remaining faces vs. first face */
701 for (face
= 1; face
< 6; face
++) {
702 img
= texObj
->Image
[face
][baseLevel
];
704 img
->Width
!= img0
->Width
||
705 img
->Height
!= img0
->Height
||
706 img
->TexFormat
!= img0
->TexFormat
)
715 * Mark a texture object dirty. It forces the object to be incomplete
716 * and optionally forces the context to re-validate its state.
718 * \param ctx GL context.
719 * \param texObj texture object.
720 * \param invalidate_state also invalidate context state.
723 _mesa_dirty_texobj(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
724 GLboolean invalidate_state
)
726 texObj
->_BaseComplete
= GL_FALSE
;
727 texObj
->_MipmapComplete
= GL_FALSE
;
728 if (invalidate_state
)
729 ctx
->NewState
|= _NEW_TEXTURE
;
734 * Return pointer to a default/fallback texture of the given type/target.
735 * The texture is an RGBA texture with all texels = (0,0,0,1).
736 * That's the value a GLSL sampler should get when sampling from an
737 * incomplete texture.
739 struct gl_texture_object
*
740 _mesa_get_fallback_texture(struct gl_context
*ctx
, gl_texture_index tex
)
742 if (!ctx
->Shared
->FallbackTex
[tex
]) {
743 /* create fallback texture now */
744 const GLsizei width
= 1, height
= 1, depth
= 1;
746 struct gl_texture_object
*texObj
;
747 struct gl_texture_image
*texImage
;
749 GLuint dims
, face
, numFaces
= 1;
758 case TEXTURE_2D_ARRAY_INDEX
:
760 target
= GL_TEXTURE_2D_ARRAY
;
762 case TEXTURE_1D_ARRAY_INDEX
:
764 target
= GL_TEXTURE_1D_ARRAY
;
766 case TEXTURE_CUBE_INDEX
:
768 target
= GL_TEXTURE_CUBE_MAP
;
771 case TEXTURE_3D_INDEX
:
773 target
= GL_TEXTURE_3D
;
775 case TEXTURE_RECT_INDEX
:
777 target
= GL_TEXTURE_RECTANGLE
;
779 case TEXTURE_2D_INDEX
:
781 target
= GL_TEXTURE_2D
;
783 case TEXTURE_1D_INDEX
:
785 target
= GL_TEXTURE_1D
;
787 case TEXTURE_BUFFER_INDEX
:
789 target
= GL_TEXTURE_BUFFER
;
791 case TEXTURE_CUBE_ARRAY_INDEX
:
793 target
= GL_TEXTURE_CUBE_MAP_ARRAY
;
795 case TEXTURE_EXTERNAL_INDEX
:
797 target
= GL_TEXTURE_EXTERNAL_OES
;
799 case TEXTURE_2D_MULTISAMPLE_INDEX
:
801 target
= GL_TEXTURE_2D_MULTISAMPLE
;
803 case TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
:
805 target
= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
;
812 /* create texture object */
813 texObj
= ctx
->Driver
.NewTextureObject(ctx
, 0, target
);
817 assert(texObj
->RefCount
== 1);
818 texObj
->Sampler
.MinFilter
= GL_NEAREST
;
819 texObj
->Sampler
.MagFilter
= GL_NEAREST
;
821 texFormat
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
,
825 /* need a loop here just for cube maps */
826 for (face
= 0; face
< numFaces
; face
++) {
829 if (target
== GL_TEXTURE_CUBE_MAP
)
830 faceTarget
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ face
;
834 /* initialize level[0] texture image */
835 texImage
= _mesa_get_tex_image(ctx
, texObj
, faceTarget
, 0);
837 _mesa_init_teximage_fields(ctx
, texImage
,
839 (dims
> 1) ? height
: 1,
840 (dims
> 2) ? depth
: 1,
844 ctx
->Driver
.TexImage(ctx
, dims
, texImage
,
845 GL_RGBA
, GL_UNSIGNED_BYTE
, texel
,
846 &ctx
->DefaultPacking
);
849 _mesa_test_texobj_completeness(ctx
, texObj
);
850 assert(texObj
->_BaseComplete
);
851 assert(texObj
->_MipmapComplete
);
853 ctx
->Shared
->FallbackTex
[tex
] = texObj
;
855 return ctx
->Shared
->FallbackTex
[tex
];
860 * Compute the size of the given texture object, in bytes.
863 texture_size(const struct gl_texture_object
*texObj
)
865 const GLuint numFaces
= _mesa_num_tex_faces(texObj
->Target
);
866 GLuint face
, level
, size
= 0;
868 for (face
= 0; face
< numFaces
; face
++) {
869 for (level
= 0; level
< MAX_TEXTURE_LEVELS
; level
++) {
870 const struct gl_texture_image
*img
= texObj
->Image
[face
][level
];
872 GLuint sz
= _mesa_format_image_size(img
->TexFormat
, img
->Width
,
873 img
->Height
, img
->Depth
);
884 * Callback called from _mesa_HashWalk()
887 count_tex_size(GLuint key
, void *data
, void *userData
)
889 const struct gl_texture_object
*texObj
=
890 (const struct gl_texture_object
*) data
;
891 GLuint
*total
= (GLuint
*) userData
;
893 *total
= *total
+ texture_size(texObj
);
898 * Compute total size (in bytes) of all textures for the given context.
899 * For debugging purposes.
902 _mesa_total_texture_memory(struct gl_context
*ctx
)
904 GLuint tgt
, total
= 0;
906 _mesa_HashWalk(ctx
->Shared
->TexObjects
, count_tex_size
, &total
);
908 /* plus, the default texture objects */
909 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
910 total
+= texture_size(ctx
->Shared
->DefaultTex
[tgt
]);
916 static struct gl_texture_object
*
917 invalidate_tex_image_error_check(struct gl_context
*ctx
, GLuint texture
,
918 GLint level
, const char *name
)
920 /* The GL_ARB_invalidate_subdata spec says:
922 * "If <texture> is zero or is not the name of a texture, the error
923 * INVALID_VALUE is generated."
925 * This performs the error check in a different order than listed in the
926 * spec. We have to get the texture object before we can validate the
927 * other parameters against values in the texture object.
929 struct gl_texture_object
*const t
= _mesa_lookup_texture(ctx
, texture
);
930 if (texture
== 0 || t
== NULL
) {
931 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(texture)", name
);
935 /* The GL_ARB_invalidate_subdata spec says:
937 * "If <level> is less than zero or greater than the base 2 logarithm
938 * of the maximum texture width, height, or depth, the error
939 * INVALID_VALUE is generated."
941 if (level
< 0 || level
> t
->MaxLevel
) {
942 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level)", name
);
946 /* The GL_ARB_invalidate_subdata spec says:
948 * "If the target of <texture> is TEXTURE_RECTANGLE, TEXTURE_BUFFER,
949 * TEXTURE_2D_MULTISAMPLE, or TEXTURE_2D_MULTISAMPLE_ARRAY, and <level>
950 * is not zero, the error INVALID_VALUE is generated."
954 case GL_TEXTURE_RECTANGLE
:
955 case GL_TEXTURE_BUFFER
:
956 case GL_TEXTURE_2D_MULTISAMPLE
:
957 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
958 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level)", name
);
972 /***********************************************************************/
973 /** \name API functions */
978 * Generate texture names.
980 * \param n number of texture names to be generated.
981 * \param textures an array in which will hold the generated texture names.
983 * \sa glGenTextures().
985 * Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture
986 * IDs which are stored in \p textures. Corresponding empty texture
987 * objects are also generated.
990 _mesa_GenTextures( GLsizei n
, GLuint
*textures
)
992 GET_CURRENT_CONTEXT(ctx
);
996 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
997 _mesa_debug(ctx
, "glGenTextures %d\n", n
);
1000 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGenTextures" );
1008 * This must be atomic (generation and allocation of texture IDs)
1010 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1012 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->TexObjects
, n
);
1014 /* Allocate new, empty texture objects */
1015 for (i
= 0; i
< n
; i
++) {
1016 struct gl_texture_object
*texObj
;
1017 GLuint name
= first
+ i
;
1019 texObj
= ctx
->Driver
.NewTextureObject(ctx
, name
, target
);
1021 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1022 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glGenTextures");
1026 /* insert into hash table */
1027 _mesa_HashInsert(ctx
->Shared
->TexObjects
, texObj
->Name
, texObj
);
1032 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1037 * Check if the given texture object is bound to the current draw or
1038 * read framebuffer. If so, Unbind it.
1041 unbind_texobj_from_fbo(struct gl_context
*ctx
,
1042 struct gl_texture_object
*texObj
)
1044 const GLuint n
= (ctx
->DrawBuffer
== ctx
->ReadBuffer
) ? 1 : 2;
1047 for (i
= 0; i
< n
; i
++) {
1048 struct gl_framebuffer
*fb
= (i
== 0) ? ctx
->DrawBuffer
: ctx
->ReadBuffer
;
1049 if (_mesa_is_user_fbo(fb
)) {
1051 for (j
= 0; j
< BUFFER_COUNT
; j
++) {
1052 if (fb
->Attachment
[j
].Type
== GL_TEXTURE
&&
1053 fb
->Attachment
[j
].Texture
== texObj
) {
1054 /* Vertices are already flushed by _mesa_DeleteTextures */
1055 ctx
->NewState
|= _NEW_BUFFERS
;
1056 _mesa_remove_attachment(ctx
, fb
->Attachment
+ j
);
1065 * Check if the given texture object is bound to any texture image units and
1066 * unbind it if so (revert to default textures).
1069 unbind_texobj_from_texunits(struct gl_context
*ctx
,
1070 struct gl_texture_object
*texObj
)
1074 for (u
= 0; u
< Elements(ctx
->Texture
.Unit
); u
++) {
1075 struct gl_texture_unit
*unit
= &ctx
->Texture
.Unit
[u
];
1076 for (tex
= 0; tex
< NUM_TEXTURE_TARGETS
; tex
++) {
1077 if (texObj
== unit
->CurrentTex
[tex
]) {
1078 _mesa_reference_texobj(&unit
->CurrentTex
[tex
],
1079 ctx
->Shared
->DefaultTex
[tex
]);
1080 ASSERT(unit
->CurrentTex
[tex
]);
1089 * Delete named textures.
1091 * \param n number of textures to be deleted.
1092 * \param textures array of texture IDs to be deleted.
1094 * \sa glDeleteTextures().
1096 * If we're about to delete a texture that's currently bound to any
1097 * texture unit, unbind the texture first. Decrement the reference
1098 * count on the texture object and delete it if it's zero.
1099 * Recall that texture objects can be shared among several rendering
1103 _mesa_DeleteTextures( GLsizei n
, const GLuint
*textures
)
1105 GET_CURRENT_CONTEXT(ctx
);
1108 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1109 _mesa_debug(ctx
, "glDeleteTextures %d\n", n
);
1111 FLUSH_VERTICES(ctx
, 0); /* too complex */
1116 for (i
= 0; i
< n
; i
++) {
1117 if (textures
[i
] > 0) {
1118 struct gl_texture_object
*delObj
1119 = _mesa_lookup_texture(ctx
, textures
[i
]);
1122 _mesa_lock_texture(ctx
, delObj
);
1124 /* Check if texture is bound to any framebuffer objects.
1126 * See section 4.4.2.3 of GL_EXT_framebuffer_object.
1128 unbind_texobj_from_fbo(ctx
, delObj
);
1130 /* Check if this texture is currently bound to any texture units.
1133 unbind_texobj_from_texunits(ctx
, delObj
);
1135 _mesa_unlock_texture(ctx
, delObj
);
1137 ctx
->NewState
|= _NEW_TEXTURE
;
1139 /* The texture _name_ is now free for re-use.
1140 * Remove it from the hash table now.
1142 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1143 _mesa_HashRemove(ctx
->Shared
->TexObjects
, delObj
->Name
);
1144 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1146 /* Unreference the texobj. If refcount hits zero, the texture
1149 _mesa_reference_texobj(&delObj
, NULL
);
1157 * Convert a GL texture target enum such as GL_TEXTURE_2D or GL_TEXTURE_3D
1158 * into the corresponding Mesa texture target index.
1159 * Note that proxy targets are not valid here.
1160 * \return TEXTURE_x_INDEX or -1 if target is invalid
1163 target_enum_to_index(struct gl_context
*ctx
, GLenum target
)
1167 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1169 return TEXTURE_2D_INDEX
;
1171 return TEXTURE_3D_INDEX
;
1172 case GL_TEXTURE_CUBE_MAP_ARB
:
1173 return ctx
->Extensions
.ARB_texture_cube_map
1174 ? TEXTURE_CUBE_INDEX
: -1;
1175 case GL_TEXTURE_RECTANGLE_NV
:
1176 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1177 ? TEXTURE_RECT_INDEX
: -1;
1178 case GL_TEXTURE_1D_ARRAY_EXT
:
1179 return _mesa_is_desktop_gl(ctx
)
1180 && (ctx
->Extensions
.EXT_texture_array
1181 || ctx
->Extensions
.MESA_texture_array
)
1182 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1183 case GL_TEXTURE_2D_ARRAY_EXT
:
1184 return (_mesa_is_desktop_gl(ctx
)
1185 && (ctx
->Extensions
.EXT_texture_array
1186 || ctx
->Extensions
.MESA_texture_array
))
1187 || _mesa_is_gles3(ctx
)
1188 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1189 case GL_TEXTURE_BUFFER_ARB
:
1190 return ctx
->API
== API_OPENGL_CORE
&&
1191 ctx
->Extensions
.ARB_texture_buffer_object
?
1192 TEXTURE_BUFFER_INDEX
: -1;
1193 case GL_TEXTURE_EXTERNAL_OES
:
1194 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
1195 ? TEXTURE_EXTERNAL_INDEX
: -1;
1196 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1197 return TEXTURE_CUBE_ARRAY_INDEX
;
1198 case GL_TEXTURE_2D_MULTISAMPLE
:
1199 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1200 ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1201 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1202 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
1203 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1211 * Bind a named texture to a texturing target.
1213 * \param target texture target.
1214 * \param texName texture name.
1216 * \sa glBindTexture().
1218 * Determines the old texture object bound and returns immediately if rebinding
1219 * the same texture. Get the current texture which is either a default texture
1220 * if name is null, a named texture from the hash, or a new texture if the
1221 * given texture name is new. Increments its reference count, binds it, and
1222 * calls dd_function_table::BindTexture. Decrements the old texture reference
1223 * count and deletes it if it reaches zero.
1226 _mesa_BindTexture( GLenum target
, GLuint texName
)
1228 GET_CURRENT_CONTEXT(ctx
);
1229 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
1230 struct gl_texture_object
*newTexObj
= NULL
;
1233 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1234 _mesa_debug(ctx
, "glBindTexture %s %d\n",
1235 _mesa_lookup_enum_by_nr(target
), (GLint
) texName
);
1237 targetIndex
= target_enum_to_index(ctx
, target
);
1238 if (targetIndex
< 0) {
1239 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindTexture(target)");
1242 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
1245 * Get pointer to new texture object (newTexObj)
1248 /* Use a default texture object */
1249 newTexObj
= ctx
->Shared
->DefaultTex
[targetIndex
];
1252 /* non-default texture object */
1253 newTexObj
= _mesa_lookup_texture(ctx
, texName
);
1255 /* error checking */
1256 if (newTexObj
->Target
!= 0 && newTexObj
->Target
!= target
) {
1257 /* the named texture object's target doesn't match the given target */
1258 _mesa_error( ctx
, GL_INVALID_OPERATION
,
1259 "glBindTexture(target mismatch)" );
1262 if (newTexObj
->Target
== 0) {
1263 finish_texture_init(ctx
, target
, newTexObj
);
1267 if (ctx
->API
== API_OPENGL_CORE
) {
1268 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindTexture(non-gen name)");
1272 /* if this is a new texture id, allocate a texture object now */
1273 newTexObj
= ctx
->Driver
.NewTextureObject(ctx
, texName
, target
);
1275 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindTexture");
1279 /* and insert it into hash table */
1280 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1281 _mesa_HashInsert(ctx
->Shared
->TexObjects
, texName
, newTexObj
);
1282 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1284 newTexObj
->Target
= target
;
1287 assert(valid_texture_object(newTexObj
));
1289 /* Check if this texture is only used by this context and is already bound.
1290 * If so, just return.
1293 GLboolean early_out
;
1294 _glthread_LOCK_MUTEX(ctx
->Shared
->Mutex
);
1295 early_out
= ((ctx
->Shared
->RefCount
== 1)
1296 && (newTexObj
== texUnit
->CurrentTex
[targetIndex
]));
1297 _glthread_UNLOCK_MUTEX(ctx
->Shared
->Mutex
);
1303 /* flush before changing binding */
1304 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1306 /* Do the actual binding. The refcount on the previously bound
1307 * texture object will be decremented. It'll be deleted if the
1310 _mesa_reference_texobj(&texUnit
->CurrentTex
[targetIndex
], newTexObj
);
1311 ASSERT(texUnit
->CurrentTex
[targetIndex
]);
1313 /* Pass BindTexture call to device driver */
1314 if (ctx
->Driver
.BindTexture
)
1315 ctx
->Driver
.BindTexture(ctx
, target
, newTexObj
);
1320 * Set texture priorities.
1322 * \param n number of textures.
1323 * \param texName texture names.
1324 * \param priorities corresponding texture priorities.
1326 * \sa glPrioritizeTextures().
1328 * Looks up each texture in the hash, clamps the corresponding priority between
1329 * 0.0 and 1.0, and calls dd_function_table::PrioritizeTexture.
1332 _mesa_PrioritizeTextures( GLsizei n
, const GLuint
*texName
,
1333 const GLclampf
*priorities
)
1335 GET_CURRENT_CONTEXT(ctx
);
1338 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1339 _mesa_debug(ctx
, "glPrioritizeTextures %d\n", n
);
1341 FLUSH_VERTICES(ctx
, 0);
1344 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPrioritizeTextures" );
1351 for (i
= 0; i
< n
; i
++) {
1352 if (texName
[i
] > 0) {
1353 struct gl_texture_object
*t
= _mesa_lookup_texture(ctx
, texName
[i
]);
1355 t
->Priority
= CLAMP( priorities
[i
], 0.0F
, 1.0F
);
1360 ctx
->NewState
|= _NEW_TEXTURE
;
1366 * See if textures are loaded in texture memory.
1368 * \param n number of textures to query.
1369 * \param texName array with the texture names.
1370 * \param residences array which will hold the residence status.
1372 * \return GL_TRUE if all textures are resident and \p residences is left unchanged,
1374 * Note: we assume all textures are always resident
1376 GLboolean GLAPIENTRY
1377 _mesa_AreTexturesResident(GLsizei n
, const GLuint
*texName
,
1378 GLboolean
*residences
)
1380 GET_CURRENT_CONTEXT(ctx
);
1381 GLboolean allResident
= GL_TRUE
;
1383 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1385 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1386 _mesa_debug(ctx
, "glAreTexturesResident %d\n", n
);
1389 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident(n)");
1393 if (!texName
|| !residences
)
1396 /* We only do error checking on the texture names */
1397 for (i
= 0; i
< n
; i
++) {
1398 struct gl_texture_object
*t
;
1399 if (texName
[i
] == 0) {
1400 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident");
1403 t
= _mesa_lookup_texture(ctx
, texName
[i
]);
1405 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident");
1415 * See if a name corresponds to a texture.
1417 * \param texture texture name.
1419 * \return GL_TRUE if texture name corresponds to a texture, or GL_FALSE
1422 * \sa glIsTexture().
1424 * Calls _mesa_HashLookup().
1426 GLboolean GLAPIENTRY
1427 _mesa_IsTexture( GLuint texture
)
1429 struct gl_texture_object
*t
;
1430 GET_CURRENT_CONTEXT(ctx
);
1431 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1433 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1434 _mesa_debug(ctx
, "glIsTexture %d\n", texture
);
1439 t
= _mesa_lookup_texture(ctx
, texture
);
1441 /* IsTexture is true only after object has been bound once. */
1442 return t
&& t
->Target
;
1447 * Simplest implementation of texture locking: grab the shared tex
1448 * mutex. Examine the shared context state timestamp and if there has
1449 * been a change, set the appropriate bits in ctx->NewState.
1451 * This is used to deal with synchronizing things when a texture object
1452 * is used/modified by different contexts (or threads) which are sharing
1455 * See also _mesa_lock/unlock_texture() in teximage.h
1458 _mesa_lock_context_textures( struct gl_context
*ctx
)
1460 _glthread_LOCK_MUTEX(ctx
->Shared
->TexMutex
);
1462 if (ctx
->Shared
->TextureStateStamp
!= ctx
->TextureStateTimestamp
) {
1463 ctx
->NewState
|= _NEW_TEXTURE
;
1464 ctx
->TextureStateTimestamp
= ctx
->Shared
->TextureStateStamp
;
1470 _mesa_unlock_context_textures( struct gl_context
*ctx
)
1472 assert(ctx
->Shared
->TextureStateStamp
== ctx
->TextureStateTimestamp
);
1473 _glthread_UNLOCK_MUTEX(ctx
->Shared
->TexMutex
);
1477 _mesa_InvalidateTexSubImage(GLuint texture
, GLint level
, GLint xoffset
,
1478 GLint yoffset
, GLint zoffset
, GLsizei width
,
1479 GLsizei height
, GLsizei depth
)
1481 struct gl_texture_object
*t
;
1482 struct gl_texture_image
*image
;
1483 GET_CURRENT_CONTEXT(ctx
);
1485 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1486 _mesa_debug(ctx
, "glInvalidateTexSubImage %d\n", texture
);
1488 t
= invalidate_tex_image_error_check(ctx
, texture
, level
,
1489 "glInvalidateTexSubImage");
1491 /* The GL_ARB_invalidate_subdata spec says:
1493 * "...the specified subregion must be between -<b> and <dim>+<b> where
1494 * <dim> is the size of the dimension of the texture image, and <b> is
1495 * the size of the border of that texture image, otherwise
1496 * INVALID_VALUE is generated (border is not applied to dimensions that
1497 * don't exist in a given texture target)."
1499 image
= t
->Image
[0][level
];
1508 /* The GL_ARB_invalidate_subdata spec says:
1510 * "For texture targets that don't have certain dimensions, this
1511 * command treats those dimensions as having a size of 1. For
1512 * example, to invalidate a portion of a two-dimensional texture,
1513 * the application would use <zoffset> equal to zero and <depth>
1516 switch (t
->Target
) {
1517 case GL_TEXTURE_BUFFER
:
1526 xBorder
= image
->Border
;
1529 imageWidth
= image
->Width
;
1533 case GL_TEXTURE_1D_ARRAY
:
1534 xBorder
= image
->Border
;
1537 imageWidth
= image
->Width
;
1538 imageHeight
= image
->Height
;
1542 case GL_TEXTURE_CUBE_MAP
:
1543 case GL_TEXTURE_RECTANGLE
:
1544 case GL_TEXTURE_2D_MULTISAMPLE
:
1545 xBorder
= image
->Border
;
1546 yBorder
= image
->Border
;
1548 imageWidth
= image
->Width
;
1549 imageHeight
= image
->Height
;
1552 case GL_TEXTURE_2D_ARRAY
:
1553 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1554 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1555 xBorder
= image
->Border
;
1556 yBorder
= image
->Border
;
1558 imageWidth
= image
->Width
;
1559 imageHeight
= image
->Height
;
1560 imageDepth
= image
->Depth
;
1563 xBorder
= image
->Border
;
1564 yBorder
= image
->Border
;
1565 zBorder
= image
->Border
;
1566 imageWidth
= image
->Width
;
1567 imageHeight
= image
->Height
;
1568 imageDepth
= image
->Depth
;
1571 assert(!"Should not get here.");
1581 if (xoffset
< -xBorder
) {
1582 _mesa_error(ctx
, GL_INVALID_VALUE
, "glInvalidateSubTexImage(xoffset)");
1586 if (xoffset
+ width
> imageWidth
+ xBorder
) {
1587 _mesa_error(ctx
, GL_INVALID_VALUE
,
1588 "glInvalidateSubTexImage(xoffset+width)");
1592 if (yoffset
< -yBorder
) {
1593 _mesa_error(ctx
, GL_INVALID_VALUE
, "glInvalidateSubTexImage(yoffset)");
1597 if (yoffset
+ height
> imageHeight
+ yBorder
) {
1598 _mesa_error(ctx
, GL_INVALID_VALUE
,
1599 "glInvalidateSubTexImage(yoffset+height)");
1603 if (zoffset
< -zBorder
) {
1604 _mesa_error(ctx
, GL_INVALID_VALUE
,
1605 "glInvalidateSubTexImage(zoffset)");
1609 if (zoffset
+ depth
> imageDepth
+ zBorder
) {
1610 _mesa_error(ctx
, GL_INVALID_VALUE
,
1611 "glInvalidateSubTexImage(zoffset+depth)");
1616 /* We don't actually do anything for this yet. Just return after
1617 * validating the parameters and generating the required errors.
1623 _mesa_InvalidateTexImage(GLuint texture
, GLint level
)
1625 GET_CURRENT_CONTEXT(ctx
);
1627 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1628 _mesa_debug(ctx
, "glInvalidateTexImage(%d, %d)\n", texture
, level
);
1630 invalidate_tex_image_error_check(ctx
, texture
, level
,
1631 "glInvalidateTexImage");
1633 /* We don't actually do anything for this yet. Just return after
1634 * validating the parameters and generating the required errors.