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.
32 #include "bufferobj.h"
40 #include "shaderimage.h"
45 #include "program/prog_instruction.h"
49 /**********************************************************************/
50 /** \name Internal functions */
54 * This function checks for all valid combinations of Min and Mag filters for
55 * Float types, when extensions like OES_texture_float and
56 * OES_texture_float_linear are supported. OES_texture_float mentions support
57 * for NEAREST, NEAREST_MIPMAP_NEAREST magnification and minification filters.
58 * Mag filters like LINEAR and min filters like NEAREST_MIPMAP_LINEAR,
59 * LINEAR_MIPMAP_NEAREST and LINEAR_MIPMAP_LINEAR are only valid in case
60 * OES_texture_float_linear is supported.
62 * Returns true in case the filter is valid for given Float type else false.
65 valid_filter_for_float(const struct gl_context
*ctx
,
66 const struct gl_texture_object
*obj
)
68 switch (obj
->Sampler
.MagFilter
) {
70 if (obj
->_IsHalfFloat
&& !ctx
->Extensions
.OES_texture_half_float_linear
) {
72 } else if (obj
->_IsFloat
&& !ctx
->Extensions
.OES_texture_float_linear
) {
76 case GL_NEAREST_MIPMAP_NEAREST
:
79 unreachable("Invalid mag filter");
82 switch (obj
->Sampler
.MinFilter
) {
84 case GL_NEAREST_MIPMAP_LINEAR
:
85 case GL_LINEAR_MIPMAP_NEAREST
:
86 case GL_LINEAR_MIPMAP_LINEAR
:
87 if (obj
->_IsHalfFloat
&& !ctx
->Extensions
.OES_texture_half_float_linear
) {
89 } else if (obj
->_IsFloat
&& !ctx
->Extensions
.OES_texture_float_linear
) {
93 case GL_NEAREST_MIPMAP_NEAREST
:
96 unreachable("Invalid min filter");
103 * Return the gl_texture_object for a given ID.
105 struct gl_texture_object
*
106 _mesa_lookup_texture(struct gl_context
*ctx
, GLuint id
)
108 return (struct gl_texture_object
*)
109 _mesa_HashLookup(ctx
->Shared
->TexObjects
, id
);
113 * Wrapper around _mesa_lookup_texture that throws GL_INVALID_OPERATION if id
114 * is not in the hash table. After calling _mesa_error, it returns NULL.
116 struct gl_texture_object
*
117 _mesa_lookup_texture_err(struct gl_context
*ctx
, GLuint id
, const char* func
)
119 struct gl_texture_object
*texObj
= NULL
;
122 texObj
= _mesa_lookup_texture(ctx
, id
); /* Returns NULL if not found. */
125 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture)", func
);
131 struct gl_texture_object
*
132 _mesa_lookup_texture_locked(struct gl_context
*ctx
, GLuint id
)
134 return (struct gl_texture_object
*)
135 _mesa_HashLookupLocked(ctx
->Shared
->TexObjects
, id
);
139 * Return a pointer to the current texture object for the given target
140 * on the current texture unit.
141 * Note: all <target> error checking should have been done by this point.
143 struct gl_texture_object
*
144 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
146 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
147 const GLboolean arrayTex
= ctx
->Extensions
.EXT_texture_array
;
151 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
152 case GL_PROXY_TEXTURE_1D
:
153 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
155 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
156 case GL_PROXY_TEXTURE_2D
:
157 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
159 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
160 case GL_PROXY_TEXTURE_3D
:
161 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
162 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
163 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
164 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
165 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
166 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
167 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
168 case GL_TEXTURE_CUBE_MAP
:
169 return ctx
->Extensions
.ARB_texture_cube_map
170 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
171 case GL_PROXY_TEXTURE_CUBE_MAP
:
172 return ctx
->Extensions
.ARB_texture_cube_map
173 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
174 case GL_TEXTURE_CUBE_MAP_ARRAY
:
175 return _mesa_has_texture_cube_map_array(ctx
)
176 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
177 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
178 return _mesa_has_texture_cube_map_array(ctx
)
179 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
180 case GL_TEXTURE_RECTANGLE_NV
:
181 return ctx
->Extensions
.NV_texture_rectangle
182 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
183 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
184 return ctx
->Extensions
.NV_texture_rectangle
185 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
186 case GL_TEXTURE_1D_ARRAY_EXT
:
187 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
188 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
189 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
190 case GL_TEXTURE_2D_ARRAY_EXT
:
191 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
192 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
193 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
194 case GL_TEXTURE_BUFFER
:
195 return (_mesa_has_ARB_texture_buffer_object(ctx
) ||
196 _mesa_has_OES_texture_buffer(ctx
)) ?
197 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
198 case GL_TEXTURE_EXTERNAL_OES
:
199 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
200 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
201 case GL_TEXTURE_2D_MULTISAMPLE
:
202 return ctx
->Extensions
.ARB_texture_multisample
203 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
204 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
205 return ctx
->Extensions
.ARB_texture_multisample
206 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
207 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
208 return ctx
->Extensions
.ARB_texture_multisample
209 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
210 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
211 return ctx
->Extensions
.ARB_texture_multisample
212 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
214 _mesa_problem(NULL
, "bad target in _mesa_get_current_tex_object()");
221 * Allocate and initialize a new texture object. But don't put it into the
222 * texture object hash table.
224 * Called via ctx->Driver.NewTextureObject, unless overridden by a device
227 * \param shared the shared GL state structure to contain the texture object
228 * \param name integer name for the texture object
229 * \param target either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
230 * GL_TEXTURE_CUBE_MAP or GL_TEXTURE_RECTANGLE_NV. zero is ok for the sake
233 * \return pointer to new texture object.
235 struct gl_texture_object
*
236 _mesa_new_texture_object( struct gl_context
*ctx
, GLuint name
, GLenum target
)
238 struct gl_texture_object
*obj
;
240 obj
= MALLOC_STRUCT(gl_texture_object
);
241 _mesa_initialize_texture_object(ctx
, obj
, name
, target
);
247 * Initialize a new texture object to default values.
248 * \param obj the texture object
249 * \param name the texture name
250 * \param target the texture target
253 _mesa_initialize_texture_object( struct gl_context
*ctx
,
254 struct gl_texture_object
*obj
,
255 GLuint name
, GLenum target
)
257 assert(target
== 0 ||
258 target
== GL_TEXTURE_1D
||
259 target
== GL_TEXTURE_2D
||
260 target
== GL_TEXTURE_3D
||
261 target
== GL_TEXTURE_CUBE_MAP
||
262 target
== GL_TEXTURE_RECTANGLE_NV
||
263 target
== GL_TEXTURE_1D_ARRAY_EXT
||
264 target
== GL_TEXTURE_2D_ARRAY_EXT
||
265 target
== GL_TEXTURE_EXTERNAL_OES
||
266 target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
267 target
== GL_TEXTURE_BUFFER
||
268 target
== GL_TEXTURE_2D_MULTISAMPLE
||
269 target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
);
271 memset(obj
, 0, sizeof(*obj
));
272 /* init the non-zero fields */
273 mtx_init(&obj
->Mutex
, mtx_plain
);
276 obj
->Target
= target
;
278 obj
->TargetIndex
= _mesa_tex_target_to_index(ctx
, target
);
281 obj
->TargetIndex
= NUM_TEXTURE_TARGETS
; /* invalid/error value */
283 obj
->Priority
= 1.0F
;
285 obj
->MaxLevel
= 1000;
287 /* must be one; no support for (YUV) planes in separate buffers */
288 obj
->RequiredTextureImageUnits
= 1;
291 if (target
== GL_TEXTURE_RECTANGLE_NV
||
292 target
== GL_TEXTURE_EXTERNAL_OES
) {
293 obj
->Sampler
.WrapS
= GL_CLAMP_TO_EDGE
;
294 obj
->Sampler
.WrapT
= GL_CLAMP_TO_EDGE
;
295 obj
->Sampler
.WrapR
= GL_CLAMP_TO_EDGE
;
296 obj
->Sampler
.MinFilter
= GL_LINEAR
;
299 obj
->Sampler
.WrapS
= GL_REPEAT
;
300 obj
->Sampler
.WrapT
= GL_REPEAT
;
301 obj
->Sampler
.WrapR
= GL_REPEAT
;
302 obj
->Sampler
.MinFilter
= GL_NEAREST_MIPMAP_LINEAR
;
304 obj
->Sampler
.MagFilter
= GL_LINEAR
;
305 obj
->Sampler
.MinLod
= -1000.0;
306 obj
->Sampler
.MaxLod
= 1000.0;
307 obj
->Sampler
.LodBias
= 0.0;
308 obj
->Sampler
.MaxAnisotropy
= 1.0;
309 obj
->Sampler
.CompareMode
= GL_NONE
; /* ARB_shadow */
310 obj
->Sampler
.CompareFunc
= GL_LEQUAL
; /* ARB_shadow */
311 obj
->DepthMode
= ctx
->API
== API_OPENGL_CORE
? GL_RED
: GL_LUMINANCE
;
312 obj
->StencilSampling
= false;
313 obj
->Sampler
.CubeMapSeamless
= GL_FALSE
;
314 obj
->Swizzle
[0] = GL_RED
;
315 obj
->Swizzle
[1] = GL_GREEN
;
316 obj
->Swizzle
[2] = GL_BLUE
;
317 obj
->Swizzle
[3] = GL_ALPHA
;
318 obj
->_Swizzle
= SWIZZLE_NOOP
;
319 obj
->Sampler
.sRGBDecode
= GL_DECODE_EXT
;
320 obj
->BufferObjectFormat
= GL_R8
;
321 obj
->_BufferObjectFormat
= MESA_FORMAT_R_UNORM8
;
322 obj
->ImageFormatCompatibilityType
= GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE
;
327 * Some texture initialization can't be finished until we know which
328 * target it's getting bound to (GL_TEXTURE_1D/2D/etc).
331 finish_texture_init(struct gl_context
*ctx
, GLenum target
,
332 struct gl_texture_object
*obj
, int targetIndex
)
334 GLenum filter
= GL_LINEAR
;
335 assert(obj
->Target
== 0);
337 obj
->Target
= target
;
338 obj
->TargetIndex
= targetIndex
;
339 assert(obj
->TargetIndex
< NUM_TEXTURE_TARGETS
);
342 case GL_TEXTURE_2D_MULTISAMPLE
:
343 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
347 case GL_TEXTURE_RECTANGLE_NV
:
348 case GL_TEXTURE_EXTERNAL_OES
:
349 /* have to init wrap and filter state here - kind of klunky */
350 obj
->Sampler
.WrapS
= GL_CLAMP_TO_EDGE
;
351 obj
->Sampler
.WrapT
= GL_CLAMP_TO_EDGE
;
352 obj
->Sampler
.WrapR
= GL_CLAMP_TO_EDGE
;
353 obj
->Sampler
.MinFilter
= filter
;
354 obj
->Sampler
.MagFilter
= filter
;
355 if (ctx
->Driver
.TexParameter
) {
356 /* XXX we probably don't need to make all these calls */
357 ctx
->Driver
.TexParameter(ctx
, obj
, GL_TEXTURE_WRAP_S
);
358 ctx
->Driver
.TexParameter(ctx
, obj
, GL_TEXTURE_WRAP_T
);
359 ctx
->Driver
.TexParameter(ctx
, obj
, GL_TEXTURE_WRAP_R
);
360 ctx
->Driver
.TexParameter(ctx
, obj
, GL_TEXTURE_MIN_FILTER
);
361 ctx
->Driver
.TexParameter(ctx
, obj
, GL_TEXTURE_MAG_FILTER
);
366 /* nothing needs done */
373 * Deallocate a texture object struct. It should have already been
374 * removed from the texture object pool.
375 * Called via ctx->Driver.DeleteTexture() if not overriden by a driver.
377 * \param shared the shared GL state to which the object belongs.
378 * \param texObj the texture object to delete.
381 _mesa_delete_texture_object(struct gl_context
*ctx
,
382 struct gl_texture_object
*texObj
)
386 /* Set Target to an invalid value. With some assertions elsewhere
387 * we can try to detect possible use of deleted textures.
389 texObj
->Target
= 0x99;
391 /* free the texture images */
392 for (face
= 0; face
< 6; face
++) {
393 for (i
= 0; i
< MAX_TEXTURE_LEVELS
; i
++) {
394 if (texObj
->Image
[face
][i
]) {
395 ctx
->Driver
.DeleteTextureImage(ctx
, texObj
->Image
[face
][i
]);
400 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, NULL
);
402 /* destroy the mutex -- it may have allocated memory (eg on bsd) */
403 mtx_destroy(&texObj
->Mutex
);
407 /* free this object */
413 * Copy texture object state from one texture object to another.
414 * Use for glPush/PopAttrib.
416 * \param dest destination texture object.
417 * \param src source texture object.
420 _mesa_copy_texture_object( struct gl_texture_object
*dest
,
421 const struct gl_texture_object
*src
)
423 dest
->Target
= src
->Target
;
424 dest
->TargetIndex
= src
->TargetIndex
;
425 dest
->Name
= src
->Name
;
426 dest
->Priority
= src
->Priority
;
427 dest
->Sampler
.BorderColor
.f
[0] = src
->Sampler
.BorderColor
.f
[0];
428 dest
->Sampler
.BorderColor
.f
[1] = src
->Sampler
.BorderColor
.f
[1];
429 dest
->Sampler
.BorderColor
.f
[2] = src
->Sampler
.BorderColor
.f
[2];
430 dest
->Sampler
.BorderColor
.f
[3] = src
->Sampler
.BorderColor
.f
[3];
431 dest
->Sampler
.WrapS
= src
->Sampler
.WrapS
;
432 dest
->Sampler
.WrapT
= src
->Sampler
.WrapT
;
433 dest
->Sampler
.WrapR
= src
->Sampler
.WrapR
;
434 dest
->Sampler
.MinFilter
= src
->Sampler
.MinFilter
;
435 dest
->Sampler
.MagFilter
= src
->Sampler
.MagFilter
;
436 dest
->Sampler
.MinLod
= src
->Sampler
.MinLod
;
437 dest
->Sampler
.MaxLod
= src
->Sampler
.MaxLod
;
438 dest
->Sampler
.LodBias
= src
->Sampler
.LodBias
;
439 dest
->BaseLevel
= src
->BaseLevel
;
440 dest
->MaxLevel
= src
->MaxLevel
;
441 dest
->Sampler
.MaxAnisotropy
= src
->Sampler
.MaxAnisotropy
;
442 dest
->Sampler
.CompareMode
= src
->Sampler
.CompareMode
;
443 dest
->Sampler
.CompareFunc
= src
->Sampler
.CompareFunc
;
444 dest
->Sampler
.CubeMapSeamless
= src
->Sampler
.CubeMapSeamless
;
445 dest
->DepthMode
= src
->DepthMode
;
446 dest
->StencilSampling
= src
->StencilSampling
;
447 dest
->Sampler
.sRGBDecode
= src
->Sampler
.sRGBDecode
;
448 dest
->_MaxLevel
= src
->_MaxLevel
;
449 dest
->_MaxLambda
= src
->_MaxLambda
;
450 dest
->GenerateMipmap
= src
->GenerateMipmap
;
451 dest
->_BaseComplete
= src
->_BaseComplete
;
452 dest
->_MipmapComplete
= src
->_MipmapComplete
;
453 COPY_4V(dest
->Swizzle
, src
->Swizzle
);
454 dest
->_Swizzle
= src
->_Swizzle
;
455 dest
->_IsHalfFloat
= src
->_IsHalfFloat
;
456 dest
->_IsFloat
= src
->_IsFloat
;
458 dest
->RequiredTextureImageUnits
= src
->RequiredTextureImageUnits
;
463 * Free all texture images of the given texture object.
465 * \param ctx GL context.
466 * \param t texture object.
468 * \sa _mesa_clear_texture_image().
471 _mesa_clear_texture_object(struct gl_context
*ctx
,
472 struct gl_texture_object
*texObj
)
476 if (texObj
->Target
== 0)
479 for (i
= 0; i
< MAX_FACES
; i
++) {
480 for (j
= 0; j
< MAX_TEXTURE_LEVELS
; j
++) {
481 struct gl_texture_image
*texImage
= texObj
->Image
[i
][j
];
483 _mesa_clear_texture_image(ctx
, texImage
);
490 * Check if the given texture object is valid by examining its Target field.
491 * For debugging only.
494 valid_texture_object(const struct gl_texture_object
*tex
)
496 switch (tex
->Target
) {
501 case GL_TEXTURE_CUBE_MAP
:
502 case GL_TEXTURE_RECTANGLE_NV
:
503 case GL_TEXTURE_1D_ARRAY_EXT
:
504 case GL_TEXTURE_2D_ARRAY_EXT
:
505 case GL_TEXTURE_BUFFER
:
506 case GL_TEXTURE_EXTERNAL_OES
:
507 case GL_TEXTURE_CUBE_MAP_ARRAY
:
508 case GL_TEXTURE_2D_MULTISAMPLE
:
509 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
512 _mesa_problem(NULL
, "invalid reference to a deleted texture object");
515 _mesa_problem(NULL
, "invalid texture object Target 0x%x, Id = %u",
516 tex
->Target
, tex
->Name
);
523 * Reference (or unreference) a texture object.
524 * If '*ptr', decrement *ptr's refcount (and delete if it becomes zero).
525 * If 'tex' is non-null, increment its refcount.
526 * This is normally only called from the _mesa_reference_texobj() macro
527 * when there's a real pointer change.
530 _mesa_reference_texobj_(struct gl_texture_object
**ptr
,
531 struct gl_texture_object
*tex
)
536 /* Unreference the old texture */
537 GLboolean deleteFlag
= GL_FALSE
;
538 struct gl_texture_object
*oldTex
= *ptr
;
540 assert(valid_texture_object(oldTex
));
541 (void) valid_texture_object
; /* silence warning in release builds */
543 mtx_lock(&oldTex
->Mutex
);
544 assert(oldTex
->RefCount
> 0);
547 deleteFlag
= (oldTex
->RefCount
== 0);
548 mtx_unlock(&oldTex
->Mutex
);
551 /* Passing in the context drastically changes the driver code for
552 * framebuffer deletion.
554 GET_CURRENT_CONTEXT(ctx
);
556 ctx
->Driver
.DeleteTexture(ctx
, oldTex
);
558 _mesa_problem(NULL
, "Unable to delete texture, no context");
566 /* reference new texture */
567 assert(valid_texture_object(tex
));
568 mtx_lock(&tex
->Mutex
);
569 assert(tex
->RefCount
> 0);
573 mtx_unlock(&tex
->Mutex
);
578 enum base_mipmap
{ BASE
, MIPMAP
};
582 * Mark a texture object as incomplete. There are actually three kinds of
584 * 1. "base incomplete": the base level of the texture is invalid so no
585 * texturing is possible.
586 * 2. "mipmap incomplete": a non-base level of the texture is invalid so
587 * mipmap filtering isn't possible, but non-mipmap filtering is.
588 * 3. "texture incompleteness": some combination of texture state and
589 * sampler state renders the texture incomplete.
591 * \param t texture object
592 * \param bm either BASE or MIPMAP to indicate what's incomplete
593 * \param fmt... string describing why it's incomplete (for debugging).
596 incomplete(struct gl_texture_object
*t
, enum base_mipmap bm
,
597 const char *fmt
, ...)
599 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_TEXTURE
) {
604 vsnprintf(s
, sizeof(s
), fmt
, args
);
607 _mesa_debug(NULL
, "Texture Obj %d incomplete because: %s\n", t
->Name
, s
);
611 t
->_BaseComplete
= GL_FALSE
;
612 t
->_MipmapComplete
= GL_FALSE
;
617 * Examine a texture object to determine if it is complete.
619 * The gl_texture_object::Complete flag will be set to GL_TRUE or GL_FALSE
622 * \param ctx GL context.
623 * \param t texture object.
625 * According to the texture target, verifies that each of the mipmaps is
626 * present and has the expected size.
629 _mesa_test_texobj_completeness( const struct gl_context
*ctx
,
630 struct gl_texture_object
*t
)
632 const GLint baseLevel
= t
->BaseLevel
;
633 const struct gl_texture_image
*baseImage
;
636 /* We'll set these to FALSE if tests fail below */
637 t
->_BaseComplete
= GL_TRUE
;
638 t
->_MipmapComplete
= GL_TRUE
;
640 if (t
->Target
== GL_TEXTURE_BUFFER
) {
641 /* Buffer textures are always considered complete. The obvious case where
642 * they would be incomplete (no BO attached) is actually specced to be
643 * undefined rendering results.
648 /* Detect cases where the application set the base level to an invalid
651 if ((baseLevel
< 0) || (baseLevel
>= MAX_TEXTURE_LEVELS
)) {
652 incomplete(t
, BASE
, "base level = %d is invalid", baseLevel
);
656 if (t
->MaxLevel
< baseLevel
) {
657 incomplete(t
, MIPMAP
, "MAX_LEVEL (%d) < BASE_LEVEL (%d)",
658 t
->MaxLevel
, baseLevel
);
662 baseImage
= t
->Image
[0][baseLevel
];
664 /* Always need the base level image */
666 incomplete(t
, BASE
, "Image[baseLevel=%d] == NULL", baseLevel
);
670 /* Check width/height/depth for zero */
671 if (baseImage
->Width
== 0 ||
672 baseImage
->Height
== 0 ||
673 baseImage
->Depth
== 0) {
674 incomplete(t
, BASE
, "texture width or height or depth = 0");
678 /* Check if the texture values are integer */
680 GLenum datatype
= _mesa_get_format_datatype(baseImage
->TexFormat
);
681 t
->_IsIntegerFormat
= datatype
== GL_INT
|| datatype
== GL_UNSIGNED_INT
;
684 /* Check if the texture type is Float or HalfFloatOES and ensure Min and Mag
685 * filters are supported in this case.
687 if (_mesa_is_gles(ctx
) && !valid_filter_for_float(ctx
, t
)) {
688 incomplete(t
, BASE
, "Filter is not supported with Float types.");
692 /* Compute _MaxLevel (the maximum mipmap level we'll sample from given the
693 * mipmap image sizes and GL_TEXTURE_MAX_LEVEL state).
697 case GL_TEXTURE_1D_ARRAY_EXT
:
698 maxLevels
= ctx
->Const
.MaxTextureLevels
;
701 case GL_TEXTURE_2D_ARRAY_EXT
:
702 maxLevels
= ctx
->Const
.MaxTextureLevels
;
705 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
707 case GL_TEXTURE_CUBE_MAP
:
708 case GL_TEXTURE_CUBE_MAP_ARRAY
:
709 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
711 case GL_TEXTURE_RECTANGLE_NV
:
712 case GL_TEXTURE_BUFFER
:
713 case GL_TEXTURE_EXTERNAL_OES
:
714 case GL_TEXTURE_2D_MULTISAMPLE
:
715 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
716 maxLevels
= 1; /* no mipmapping */
719 _mesa_problem(ctx
, "Bad t->Target in _mesa_test_texobj_completeness");
723 assert(maxLevels
> 0);
725 t
->_MaxLevel
= MIN3(t
->MaxLevel
,
726 /* 'p' in the GL spec */
727 (int) (baseLevel
+ baseImage
->MaxNumLevels
- 1),
728 /* 'q' in the GL spec */
732 /* Adjust max level for views: the data store may have more levels than
735 t
->_MaxLevel
= MIN2(t
->_MaxLevel
, t
->NumLevels
- 1);
738 /* Compute _MaxLambda = q - p in the spec used during mipmapping */
739 t
->_MaxLambda
= (GLfloat
) (t
->_MaxLevel
- baseLevel
);
742 /* This texture object was created with glTexStorage1/2/3D() so we
743 * know that all the mipmap levels are the right size and all cube
744 * map faces are the same size.
745 * We don't need to do any of the additional checks below.
750 if (t
->Target
== GL_TEXTURE_CUBE_MAP
) {
751 /* Make sure that all six cube map level 0 images are the same size and
753 * Note: we know that the image's width==height (we enforce that
754 * at glTexImage time) so we only need to test the width here.
757 assert(baseImage
->Width2
== baseImage
->Height
);
758 for (face
= 1; face
< 6; face
++) {
759 assert(t
->Image
[face
][baseLevel
] == NULL
||
760 t
->Image
[face
][baseLevel
]->Width2
==
761 t
->Image
[face
][baseLevel
]->Height2
);
762 if (t
->Image
[face
][baseLevel
] == NULL
||
763 t
->Image
[face
][baseLevel
]->Width2
!= baseImage
->Width2
) {
764 incomplete(t
, BASE
, "Cube face missing or mismatched size");
767 if (t
->Image
[face
][baseLevel
]->InternalFormat
!=
768 baseImage
->InternalFormat
) {
769 incomplete(t
, BASE
, "Cube face format mismatch");
772 if (t
->Image
[face
][baseLevel
]->Border
!= baseImage
->Border
) {
773 incomplete(t
, BASE
, "Cube face border size mismatch");
780 * Do mipmap consistency checking.
781 * Note: we don't care about the current texture sampler state here.
782 * To determine texture completeness we'll either look at _BaseComplete
783 * or _MipmapComplete depending on the current minification filter mode.
787 const GLint minLevel
= baseLevel
;
788 const GLint maxLevel
= t
->_MaxLevel
;
789 const GLuint numFaces
= _mesa_num_tex_faces(t
->Target
);
790 GLuint width
, height
, depth
, face
;
792 if (minLevel
> maxLevel
) {
793 incomplete(t
, MIPMAP
, "minLevel > maxLevel");
797 /* Get the base image's dimensions */
798 width
= baseImage
->Width2
;
799 height
= baseImage
->Height2
;
800 depth
= baseImage
->Depth2
;
802 /* Note: this loop will be a no-op for RECT, BUFFER, EXTERNAL,
803 * MULTISAMPLE and MULTISAMPLE_ARRAY textures
805 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
806 /* Compute the expected size of image at level[i] */
810 if (height
> 1 && t
->Target
!= GL_TEXTURE_1D_ARRAY
) {
813 if (depth
> 1 && t
->Target
!= GL_TEXTURE_2D_ARRAY
814 && t
->Target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
818 /* loop over cube faces (or single face otherwise) */
819 for (face
= 0; face
< numFaces
; face
++) {
820 if (i
>= minLevel
&& i
<= maxLevel
) {
821 const struct gl_texture_image
*img
= t
->Image
[face
][i
];
824 incomplete(t
, MIPMAP
, "TexImage[%d] is missing", i
);
827 if (img
->InternalFormat
!= baseImage
->InternalFormat
) {
828 incomplete(t
, MIPMAP
, "Format[i] != Format[baseLevel]");
831 if (img
->Border
!= baseImage
->Border
) {
832 incomplete(t
, MIPMAP
, "Border[i] != Border[baseLevel]");
835 if (img
->Width2
!= width
) {
836 incomplete(t
, MIPMAP
, "TexImage[%d] bad width %u", i
,
840 if (img
->Height2
!= height
) {
841 incomplete(t
, MIPMAP
, "TexImage[%d] bad height %u", i
,
845 if (img
->Depth2
!= depth
) {
846 incomplete(t
, MIPMAP
, "TexImage[%d] bad depth %u", i
,
853 if (width
== 1 && height
== 1 && depth
== 1) {
854 return; /* found smallest needed mipmap, all done! */
862 _mesa_cube_level_complete(const struct gl_texture_object
*texObj
,
865 const struct gl_texture_image
*img0
, *img
;
868 if (texObj
->Target
!= GL_TEXTURE_CUBE_MAP
)
871 if ((level
< 0) || (level
>= MAX_TEXTURE_LEVELS
))
874 /* check first face */
875 img0
= texObj
->Image
[0][level
];
878 img0
->Width
!= img0
->Height
)
881 /* check remaining faces vs. first face */
882 for (face
= 1; face
< 6; face
++) {
883 img
= texObj
->Image
[face
][level
];
885 img
->Width
!= img0
->Width
||
886 img
->Height
!= img0
->Height
||
887 img
->TexFormat
!= img0
->TexFormat
)
895 * Check if the given cube map texture is "cube complete" as defined in
896 * the OpenGL specification.
899 _mesa_cube_complete(const struct gl_texture_object
*texObj
)
901 return _mesa_cube_level_complete(texObj
, texObj
->BaseLevel
);
905 * Mark a texture object dirty. It forces the object to be incomplete
906 * and forces the context to re-validate its state.
908 * \param ctx GL context.
909 * \param texObj texture object.
912 _mesa_dirty_texobj(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
914 texObj
->_BaseComplete
= GL_FALSE
;
915 texObj
->_MipmapComplete
= GL_FALSE
;
916 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
;
921 * Return pointer to a default/fallback texture of the given type/target.
922 * The texture is an RGBA texture with all texels = (0,0,0,1).
923 * That's the value a GLSL sampler should get when sampling from an
924 * incomplete texture.
926 struct gl_texture_object
*
927 _mesa_get_fallback_texture(struct gl_context
*ctx
, gl_texture_index tex
)
929 if (!ctx
->Shared
->FallbackTex
[tex
]) {
930 /* create fallback texture now */
931 const GLsizei width
= 1, height
= 1;
934 struct gl_texture_object
*texObj
;
935 struct gl_texture_image
*texImage
;
936 mesa_format texFormat
;
937 GLuint dims
, face
, numFaces
= 1;
940 for (face
= 0; face
< 6; face
++) {
943 texel
[4*face
+ 2] = 0x0;
944 texel
[4*face
+ 3] = 0xff;
948 case TEXTURE_2D_ARRAY_INDEX
:
950 target
= GL_TEXTURE_2D_ARRAY
;
952 case TEXTURE_1D_ARRAY_INDEX
:
954 target
= GL_TEXTURE_1D_ARRAY
;
956 case TEXTURE_CUBE_INDEX
:
958 target
= GL_TEXTURE_CUBE_MAP
;
961 case TEXTURE_3D_INDEX
:
963 target
= GL_TEXTURE_3D
;
965 case TEXTURE_RECT_INDEX
:
967 target
= GL_TEXTURE_RECTANGLE
;
969 case TEXTURE_2D_INDEX
:
971 target
= GL_TEXTURE_2D
;
973 case TEXTURE_1D_INDEX
:
975 target
= GL_TEXTURE_1D
;
977 case TEXTURE_BUFFER_INDEX
:
979 target
= GL_TEXTURE_BUFFER
;
981 case TEXTURE_CUBE_ARRAY_INDEX
:
983 target
= GL_TEXTURE_CUBE_MAP_ARRAY
;
986 case TEXTURE_EXTERNAL_INDEX
:
988 target
= GL_TEXTURE_EXTERNAL_OES
;
990 case TEXTURE_2D_MULTISAMPLE_INDEX
:
992 target
= GL_TEXTURE_2D_MULTISAMPLE
;
994 case TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
:
996 target
= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
;
1003 /* create texture object */
1004 texObj
= ctx
->Driver
.NewTextureObject(ctx
, 0, target
);
1008 assert(texObj
->RefCount
== 1);
1009 texObj
->Sampler
.MinFilter
= GL_NEAREST
;
1010 texObj
->Sampler
.MagFilter
= GL_NEAREST
;
1012 texFormat
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
,
1016 /* need a loop here just for cube maps */
1017 for (face
= 0; face
< numFaces
; face
++) {
1018 const GLenum faceTarget
= _mesa_cube_face_target(target
, face
);
1020 /* initialize level[0] texture image */
1021 texImage
= _mesa_get_tex_image(ctx
, texObj
, faceTarget
, 0);
1023 _mesa_init_teximage_fields(ctx
, texImage
,
1025 (dims
> 1) ? height
: 1,
1026 (dims
> 2) ? depth
: 1,
1028 GL_RGBA
, texFormat
);
1030 ctx
->Driver
.TexImage(ctx
, dims
, texImage
,
1031 GL_RGBA
, GL_UNSIGNED_BYTE
, texel
,
1032 &ctx
->DefaultPacking
);
1035 _mesa_test_texobj_completeness(ctx
, texObj
);
1036 assert(texObj
->_BaseComplete
);
1037 assert(texObj
->_MipmapComplete
);
1039 ctx
->Shared
->FallbackTex
[tex
] = texObj
;
1041 return ctx
->Shared
->FallbackTex
[tex
];
1046 * Compute the size of the given texture object, in bytes.
1049 texture_size(const struct gl_texture_object
*texObj
)
1051 const GLuint numFaces
= _mesa_num_tex_faces(texObj
->Target
);
1052 GLuint face
, level
, size
= 0;
1054 for (face
= 0; face
< numFaces
; face
++) {
1055 for (level
= 0; level
< MAX_TEXTURE_LEVELS
; level
++) {
1056 const struct gl_texture_image
*img
= texObj
->Image
[face
][level
];
1058 GLuint sz
= _mesa_format_image_size(img
->TexFormat
, img
->Width
,
1059 img
->Height
, img
->Depth
);
1070 * Callback called from _mesa_HashWalk()
1073 count_tex_size(GLuint key
, void *data
, void *userData
)
1075 const struct gl_texture_object
*texObj
=
1076 (const struct gl_texture_object
*) data
;
1077 GLuint
*total
= (GLuint
*) userData
;
1081 *total
= *total
+ texture_size(texObj
);
1086 * Compute total size (in bytes) of all textures for the given context.
1087 * For debugging purposes.
1090 _mesa_total_texture_memory(struct gl_context
*ctx
)
1092 GLuint tgt
, total
= 0;
1094 _mesa_HashWalk(ctx
->Shared
->TexObjects
, count_tex_size
, &total
);
1096 /* plus, the default texture objects */
1097 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1098 total
+= texture_size(ctx
->Shared
->DefaultTex
[tgt
]);
1106 * Return the base format for the given texture object by looking
1107 * at the base texture image.
1108 * \return base format (such as GL_RGBA) or GL_NONE if it can't be determined
1111 _mesa_texture_base_format(const struct gl_texture_object
*texObj
)
1113 const struct gl_texture_image
*texImage
= _mesa_base_tex_image(texObj
);
1115 return texImage
? texImage
->_BaseFormat
: GL_NONE
;
1119 static struct gl_texture_object
*
1120 invalidate_tex_image_error_check(struct gl_context
*ctx
, GLuint texture
,
1121 GLint level
, const char *name
)
1123 /* The GL_ARB_invalidate_subdata spec says:
1125 * "If <texture> is zero or is not the name of a texture, the error
1126 * INVALID_VALUE is generated."
1128 * This performs the error check in a different order than listed in the
1129 * spec. We have to get the texture object before we can validate the
1130 * other parameters against values in the texture object.
1132 struct gl_texture_object
*const t
= _mesa_lookup_texture(ctx
, texture
);
1133 if (texture
== 0 || t
== NULL
) {
1134 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(texture)", name
);
1138 /* The GL_ARB_invalidate_subdata spec says:
1140 * "If <level> is less than zero or greater than the base 2 logarithm
1141 * of the maximum texture width, height, or depth, the error
1142 * INVALID_VALUE is generated."
1144 if (level
< 0 || level
> t
->MaxLevel
) {
1145 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level)", name
);
1149 /* The GL_ARB_invalidate_subdata spec says:
1151 * "If the target of <texture> is TEXTURE_RECTANGLE, TEXTURE_BUFFER,
1152 * TEXTURE_2D_MULTISAMPLE, or TEXTURE_2D_MULTISAMPLE_ARRAY, and <level>
1153 * is not zero, the error INVALID_VALUE is generated."
1156 switch (t
->Target
) {
1157 case GL_TEXTURE_RECTANGLE
:
1158 case GL_TEXTURE_BUFFER
:
1159 case GL_TEXTURE_2D_MULTISAMPLE
:
1160 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1161 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level)", name
);
1174 * Helper function for glCreateTextures and glGenTextures. Need this because
1175 * glCreateTextures should throw errors if target = 0. This is not exposed to
1176 * the rest of Mesa to encourage Mesa internals to use nameless textures,
1177 * which do not require expensive hash lookups.
1178 * \param target either 0 or a valid / error-checked texture target enum
1181 create_textures(struct gl_context
*ctx
, GLenum target
,
1182 GLsizei n
, GLuint
*textures
, const char *caller
)
1187 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1188 _mesa_debug(ctx
, "%s %d\n", caller
, n
);
1191 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", caller
);
1199 * This must be atomic (generation and allocation of texture IDs)
1201 _mesa_HashLockMutex(ctx
->Shared
->TexObjects
);
1203 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->TexObjects
, n
);
1205 /* Allocate new, empty texture objects */
1206 for (i
= 0; i
< n
; i
++) {
1207 struct gl_texture_object
*texObj
;
1208 GLuint name
= first
+ i
;
1209 texObj
= ctx
->Driver
.NewTextureObject(ctx
, name
, target
);
1211 _mesa_HashUnlockMutex(ctx
->Shared
->TexObjects
);
1212 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "gl%sTextures", caller
);
1216 /* insert into hash table */
1217 _mesa_HashInsertLocked(ctx
->Shared
->TexObjects
, texObj
->Name
, texObj
);
1222 _mesa_HashUnlockMutex(ctx
->Shared
->TexObjects
);
1228 /***********************************************************************/
1229 /** \name API functions */
1234 * Generate texture names.
1236 * \param n number of texture names to be generated.
1237 * \param textures an array in which will hold the generated texture names.
1239 * \sa glGenTextures(), glCreateTextures().
1241 * Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture
1242 * IDs which are stored in \p textures. Corresponding empty texture
1243 * objects are also generated.
1246 _mesa_GenTextures(GLsizei n
, GLuint
*textures
)
1248 GET_CURRENT_CONTEXT(ctx
);
1249 create_textures(ctx
, 0, n
, textures
, "glGenTextures");
1253 * Create texture objects.
1255 * \param target the texture target for each name to be generated.
1256 * \param n number of texture names to be generated.
1257 * \param textures an array in which will hold the generated texture names.
1259 * \sa glCreateTextures(), glGenTextures().
1261 * Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture
1262 * IDs which are stored in \p textures. Corresponding empty texture
1263 * objects are also generated.
1266 _mesa_CreateTextures(GLenum target
, GLsizei n
, GLuint
*textures
)
1269 GET_CURRENT_CONTEXT(ctx
);
1272 * The 4.5 core profile spec (30.10.2014) doesn't specify what
1273 * glCreateTextures should do with invalid targets, which was probably an
1274 * oversight. This conforms to the spec for glBindTexture.
1276 targetIndex
= _mesa_tex_target_to_index(ctx
, target
);
1277 if (targetIndex
< 0) {
1278 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCreateTextures(target)");
1282 create_textures(ctx
, target
, n
, textures
, "glCreateTextures");
1286 * Check if the given texture object is bound to the current draw or
1287 * read framebuffer. If so, Unbind it.
1290 unbind_texobj_from_fbo(struct gl_context
*ctx
,
1291 struct gl_texture_object
*texObj
)
1293 bool progress
= false;
1295 /* Section 4.4.2 (Attaching Images to Framebuffer Objects), subsection
1296 * "Attaching Texture Images to a Framebuffer," of the OpenGL 3.1 spec
1299 * "If a texture object is deleted while its image is attached to one
1300 * or more attachment points in the currently bound framebuffer, then
1301 * it is as if FramebufferTexture* had been called, with a texture of
1302 * zero, for each attachment point to which this image was attached in
1303 * the currently bound framebuffer. In other words, this texture image
1304 * is first detached from all attachment points in the currently bound
1305 * framebuffer. Note that the texture image is specifically not
1306 * detached from any other framebuffer objects. Detaching the texture
1307 * image from any other framebuffer objects is the responsibility of
1310 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1311 progress
= _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, texObj
);
1313 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1314 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1315 progress
= _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, texObj
)
1320 /* Vertices are already flushed by _mesa_DeleteTextures */
1321 ctx
->NewState
|= _NEW_BUFFERS
;
1326 * Check if the given texture object is bound to any texture image units and
1327 * unbind it if so (revert to default textures).
1330 unbind_texobj_from_texunits(struct gl_context
*ctx
,
1331 struct gl_texture_object
*texObj
)
1333 const gl_texture_index index
= texObj
->TargetIndex
;
1336 if (texObj
->Target
== 0) {
1337 /* texture was never bound */
1341 assert(index
< NUM_TEXTURE_TARGETS
);
1343 for (u
= 0; u
< ctx
->Texture
.NumCurrentTexUsed
; u
++) {
1344 struct gl_texture_unit
*unit
= &ctx
->Texture
.Unit
[u
];
1346 if (texObj
== unit
->CurrentTex
[index
]) {
1347 /* Bind the default texture for this unit/target */
1348 _mesa_reference_texobj(&unit
->CurrentTex
[index
],
1349 ctx
->Shared
->DefaultTex
[index
]);
1350 unit
->_BoundTextures
&= ~(1 << index
);
1357 * Check if the given texture object is bound to any shader image unit
1358 * and unbind it if that's the case.
1361 unbind_texobj_from_image_units(struct gl_context
*ctx
,
1362 struct gl_texture_object
*texObj
)
1366 for (i
= 0; i
< ctx
->Const
.MaxImageUnits
; i
++) {
1367 struct gl_image_unit
*unit
= &ctx
->ImageUnits
[i
];
1369 if (texObj
== unit
->TexObj
) {
1370 _mesa_reference_texobj(&unit
->TexObj
, NULL
);
1371 *unit
= _mesa_default_image_unit(ctx
);
1378 * Unbinds all textures bound to the given texture image unit.
1381 unbind_textures_from_unit(struct gl_context
*ctx
, GLuint unit
)
1383 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
1385 while (texUnit
->_BoundTextures
) {
1386 const GLuint index
= ffs(texUnit
->_BoundTextures
) - 1;
1387 struct gl_texture_object
*texObj
= ctx
->Shared
->DefaultTex
[index
];
1389 _mesa_reference_texobj(&texUnit
->CurrentTex
[index
], texObj
);
1391 /* Pass BindTexture call to device driver */
1392 if (ctx
->Driver
.BindTexture
)
1393 ctx
->Driver
.BindTexture(ctx
, unit
, 0, texObj
);
1395 texUnit
->_BoundTextures
&= ~(1 << index
);
1396 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
;
1402 * Delete named textures.
1404 * \param n number of textures to be deleted.
1405 * \param textures array of texture IDs to be deleted.
1407 * \sa glDeleteTextures().
1409 * If we're about to delete a texture that's currently bound to any
1410 * texture unit, unbind the texture first. Decrement the reference
1411 * count on the texture object and delete it if it's zero.
1412 * Recall that texture objects can be shared among several rendering
1416 _mesa_DeleteTextures( GLsizei n
, const GLuint
*textures
)
1418 GET_CURRENT_CONTEXT(ctx
);
1421 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1422 _mesa_debug(ctx
, "glDeleteTextures %d\n", n
);
1425 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteTextures(n < 0)");
1429 FLUSH_VERTICES(ctx
, 0); /* too complex */
1432 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteTextures(n)");
1439 for (i
= 0; i
< n
; i
++) {
1440 if (textures
[i
] > 0) {
1441 struct gl_texture_object
*delObj
1442 = _mesa_lookup_texture(ctx
, textures
[i
]);
1445 _mesa_lock_texture(ctx
, delObj
);
1447 /* Check if texture is bound to any framebuffer objects.
1449 * See section 4.4.2.3 of GL_EXT_framebuffer_object.
1451 unbind_texobj_from_fbo(ctx
, delObj
);
1453 /* Check if this texture is currently bound to any texture units.
1456 unbind_texobj_from_texunits(ctx
, delObj
);
1458 /* Check if this texture is currently bound to any shader
1459 * image unit. If so, unbind it.
1460 * See section 3.9.X of GL_ARB_shader_image_load_store.
1462 unbind_texobj_from_image_units(ctx
, delObj
);
1464 _mesa_unlock_texture(ctx
, delObj
);
1466 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
;
1468 /* The texture _name_ is now free for re-use.
1469 * Remove it from the hash table now.
1471 _mesa_HashRemove(ctx
->Shared
->TexObjects
, delObj
->Name
);
1473 /* Unreference the texobj. If refcount hits zero, the texture
1476 _mesa_reference_texobj(&delObj
, NULL
);
1483 * This deletes a texObj without altering the hash table.
1486 _mesa_delete_nameless_texture(struct gl_context
*ctx
,
1487 struct gl_texture_object
*texObj
)
1492 FLUSH_VERTICES(ctx
, 0);
1494 _mesa_lock_texture(ctx
, texObj
);
1496 /* Check if texture is bound to any framebuffer objects.
1498 * See section 4.4.2.3 of GL_EXT_framebuffer_object.
1500 unbind_texobj_from_fbo(ctx
, texObj
);
1502 /* Check if this texture is currently bound to any texture units.
1505 unbind_texobj_from_texunits(ctx
, texObj
);
1507 /* Check if this texture is currently bound to any shader
1508 * image unit. If so, unbind it.
1509 * See section 3.9.X of GL_ARB_shader_image_load_store.
1511 unbind_texobj_from_image_units(ctx
, texObj
);
1513 _mesa_unlock_texture(ctx
, texObj
);
1515 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
;
1517 /* Unreference the texobj. If refcount hits zero, the texture
1520 _mesa_reference_texobj(&texObj
, NULL
);
1525 * Convert a GL texture target enum such as GL_TEXTURE_2D or GL_TEXTURE_3D
1526 * into the corresponding Mesa texture target index.
1527 * Note that proxy targets are not valid here.
1528 * \return TEXTURE_x_INDEX or -1 if target is invalid
1531 _mesa_tex_target_to_index(const struct gl_context
*ctx
, GLenum target
)
1535 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1537 return TEXTURE_2D_INDEX
;
1539 return ctx
->API
!= API_OPENGLES
? TEXTURE_3D_INDEX
: -1;
1540 case GL_TEXTURE_CUBE_MAP
:
1541 return ctx
->Extensions
.ARB_texture_cube_map
1542 ? TEXTURE_CUBE_INDEX
: -1;
1543 case GL_TEXTURE_RECTANGLE
:
1544 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1545 ? TEXTURE_RECT_INDEX
: -1;
1546 case GL_TEXTURE_1D_ARRAY
:
1547 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
1548 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1549 case GL_TEXTURE_2D_ARRAY
:
1550 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1551 || _mesa_is_gles3(ctx
)
1552 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1553 case GL_TEXTURE_BUFFER
:
1554 return (_mesa_has_ARB_texture_buffer_object(ctx
) ||
1555 _mesa_has_OES_texture_buffer(ctx
)) ?
1556 TEXTURE_BUFFER_INDEX
: -1;
1557 case GL_TEXTURE_EXTERNAL_OES
:
1558 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
1559 ? TEXTURE_EXTERNAL_INDEX
: -1;
1560 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1561 return _mesa_has_texture_cube_map_array(ctx
)
1562 ? TEXTURE_CUBE_ARRAY_INDEX
: -1;
1563 case GL_TEXTURE_2D_MULTISAMPLE
:
1564 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
) ||
1565 _mesa_is_gles31(ctx
)) ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1566 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1567 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
) ||
1568 _mesa_is_gles31(ctx
))
1569 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1577 * Do actual texture binding. All error checking should have been done prior
1578 * to calling this function. Note that the texture target (1D, 2D, etc) is
1579 * always specified by the texObj->TargetIndex.
1581 * \param unit index of texture unit to update
1582 * \param texObj the new texture object (cannot be NULL)
1585 bind_texture(struct gl_context
*ctx
,
1587 struct gl_texture_object
*texObj
)
1589 struct gl_texture_unit
*texUnit
;
1592 assert(unit
< ARRAY_SIZE(ctx
->Texture
.Unit
));
1593 texUnit
= &ctx
->Texture
.Unit
[unit
];
1596 assert(valid_texture_object(texObj
));
1598 targetIndex
= texObj
->TargetIndex
;
1599 assert(targetIndex
>= 0);
1600 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
1602 /* Check if this texture is only used by this context and is already bound.
1603 * If so, just return. For GL_OES_image_external, rebinding the texture
1604 * always must invalidate cached resources.
1606 if (targetIndex
!= TEXTURE_EXTERNAL_INDEX
) {
1608 mtx_lock(&ctx
->Shared
->Mutex
);
1609 early_out
= ((ctx
->Shared
->RefCount
== 1)
1610 && (texObj
== texUnit
->CurrentTex
[targetIndex
]));
1611 mtx_unlock(&ctx
->Shared
->Mutex
);
1617 /* flush before changing binding */
1618 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_OBJECT
);
1620 /* If the refcount on the previously bound texture is decremented to
1621 * zero, it'll be deleted here.
1623 _mesa_reference_texobj(&texUnit
->CurrentTex
[targetIndex
], texObj
);
1625 ctx
->Texture
.NumCurrentTexUsed
= MAX2(ctx
->Texture
.NumCurrentTexUsed
,
1628 if (texObj
->Name
!= 0)
1629 texUnit
->_BoundTextures
|= (1 << targetIndex
);
1631 texUnit
->_BoundTextures
&= ~(1 << targetIndex
);
1633 /* Pass BindTexture call to device driver */
1634 if (ctx
->Driver
.BindTexture
) {
1635 ctx
->Driver
.BindTexture(ctx
, unit
, texObj
->Target
, texObj
);
1641 * Implement glBindTexture(). Do error checking, look-up or create a new
1642 * texture object, then bind it in the current texture unit.
1644 * \param target texture target.
1645 * \param texName texture name.
1648 _mesa_BindTexture( GLenum target
, GLuint texName
)
1650 GET_CURRENT_CONTEXT(ctx
);
1651 struct gl_texture_object
*newTexObj
= NULL
;
1653 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1654 _mesa_debug(ctx
, "glBindTexture %s %d\n",
1655 _mesa_enum_to_string(target
), (GLint
) texName
);
1657 int targetIndex
= _mesa_tex_target_to_index(ctx
, target
);
1658 if (targetIndex
< 0) {
1659 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindTexture(target = %s)",
1660 _mesa_enum_to_string(target
));
1663 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
1666 * Get pointer to new texture object (newTexObj)
1669 /* Use a default texture object */
1670 newTexObj
= ctx
->Shared
->DefaultTex
[targetIndex
];
1673 /* non-default texture object */
1674 newTexObj
= _mesa_lookup_texture(ctx
, texName
);
1676 /* error checking */
1677 if (newTexObj
->Target
!= 0 && newTexObj
->Target
!= target
) {
1678 /* The named texture object's target doesn't match the
1681 _mesa_error( ctx
, GL_INVALID_OPERATION
,
1682 "glBindTexture(target mismatch)" );
1685 if (newTexObj
->Target
== 0) {
1686 finish_texture_init(ctx
, target
, newTexObj
, targetIndex
);
1690 if (ctx
->API
== API_OPENGL_CORE
) {
1691 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1692 "glBindTexture(non-gen name)");
1696 /* if this is a new texture id, allocate a texture object now */
1697 newTexObj
= ctx
->Driver
.NewTextureObject(ctx
, texName
, target
);
1699 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindTexture");
1703 /* and insert it into hash table */
1704 _mesa_HashInsert(ctx
->Shared
->TexObjects
, texName
, newTexObj
);
1708 assert(newTexObj
->Target
== target
);
1709 assert(newTexObj
->TargetIndex
== targetIndex
);
1711 bind_texture(ctx
, ctx
->Texture
.CurrentUnit
, newTexObj
);
1716 * OpenGL 4.5 / GL_ARB_direct_state_access glBindTextureUnit().
1718 * \param unit texture unit.
1719 * \param texture texture name.
1721 * \sa glBindTexture().
1723 * If the named texture is 0, this will reset each target for the specified
1724 * texture unit to its default texture.
1725 * If the named texture is not 0 or a recognized texture name, this throws
1726 * GL_INVALID_OPERATION.
1729 _mesa_BindTextureUnit(GLuint unit
, GLuint texture
)
1731 GET_CURRENT_CONTEXT(ctx
);
1732 struct gl_texture_object
*texObj
;
1734 if (unit
>= _mesa_max_tex_unit(ctx
)) {
1735 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindTextureUnit(unit=%u)", unit
);
1739 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1740 _mesa_debug(ctx
, "glBindTextureUnit %s %d\n",
1741 _mesa_enum_to_string(GL_TEXTURE0
+unit
), (GLint
) texture
);
1743 /* Section 8.1 (Texture Objects) of the OpenGL 4.5 core profile spec
1745 * "When texture is zero, each of the targets enumerated at the
1746 * beginning of this section is reset to its default texture for the
1747 * corresponding texture image unit."
1750 unbind_textures_from_unit(ctx
, unit
);
1754 /* Get the non-default texture object */
1755 texObj
= _mesa_lookup_texture(ctx
, texture
);
1757 /* Error checking */
1759 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1760 "glBindTextureUnit(non-gen name)");
1763 if (texObj
->Target
== 0) {
1764 /* Texture object was gen'd but never bound so the target is not set */
1765 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindTextureUnit(target)");
1768 assert(valid_texture_object(texObj
));
1770 bind_texture(ctx
, unit
, texObj
);
1775 * OpenGL 4.4 / GL_ARB_multi_bind glBindTextures().
1778 _mesa_BindTextures(GLuint first
, GLsizei count
, const GLuint
*textures
)
1780 GET_CURRENT_CONTEXT(ctx
);
1783 /* The ARB_multi_bind spec says:
1785 * "An INVALID_OPERATION error is generated if <first> + <count>
1786 * is greater than the number of texture image units supported
1787 * by the implementation."
1789 if (first
+ count
> ctx
->Const
.MaxCombinedTextureImageUnits
) {
1790 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1791 "glBindTextures(first=%u + count=%d > the value of "
1792 "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS=%u)",
1793 first
, count
, ctx
->Const
.MaxCombinedTextureImageUnits
);
1798 /* Note that the error semantics for multi-bind commands differ from
1799 * those of other GL commands.
1801 * The issues section in the ARB_multi_bind spec says:
1803 * "(11) Typically, OpenGL specifies that if an error is generated by
1804 * a command, that command has no effect. This is somewhat
1805 * unfortunate for multi-bind commands, because it would require
1806 * a first pass to scan the entire list of bound objects for
1807 * errors and then a second pass to actually perform the
1808 * bindings. Should we have different error semantics?
1810 * RESOLVED: Yes. In this specification, when the parameters for
1811 * one of the <count> binding points are invalid, that binding
1812 * point is not updated and an error will be generated. However,
1813 * other binding points in the same command will be updated if
1814 * their parameters are valid and no other error occurs."
1817 _mesa_HashLockMutex(ctx
->Shared
->TexObjects
);
1819 for (i
= 0; i
< count
; i
++) {
1820 if (textures
[i
] != 0) {
1821 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[first
+ i
];
1822 struct gl_texture_object
*current
= texUnit
->_Current
;
1823 struct gl_texture_object
*texObj
;
1825 if (current
&& current
->Name
== textures
[i
])
1828 texObj
= _mesa_lookup_texture_locked(ctx
, textures
[i
]);
1830 if (texObj
&& texObj
->Target
!= 0) {
1831 bind_texture(ctx
, first
+ i
, texObj
);
1833 /* The ARB_multi_bind spec says:
1835 * "An INVALID_OPERATION error is generated if any value
1836 * in <textures> is not zero or the name of an existing
1837 * texture object (per binding)."
1839 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1840 "glBindTextures(textures[%d]=%u is not zero "
1841 "or the name of an existing texture object)",
1845 unbind_textures_from_unit(ctx
, first
+ i
);
1849 _mesa_HashUnlockMutex(ctx
->Shared
->TexObjects
);
1851 /* Unbind all textures in the range <first> through <first>+<count>-1 */
1852 for (i
= 0; i
< count
; i
++)
1853 unbind_textures_from_unit(ctx
, first
+ i
);
1859 * Set texture priorities.
1861 * \param n number of textures.
1862 * \param texName texture names.
1863 * \param priorities corresponding texture priorities.
1865 * \sa glPrioritizeTextures().
1867 * Looks up each texture in the hash, clamps the corresponding priority between
1868 * 0.0 and 1.0, and calls dd_function_table::PrioritizeTexture.
1871 _mesa_PrioritizeTextures( GLsizei n
, const GLuint
*texName
,
1872 const GLclampf
*priorities
)
1874 GET_CURRENT_CONTEXT(ctx
);
1877 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1878 _mesa_debug(ctx
, "glPrioritizeTextures %d\n", n
);
1880 FLUSH_VERTICES(ctx
, 0);
1883 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPrioritizeTextures" );
1890 for (i
= 0; i
< n
; i
++) {
1891 if (texName
[i
] > 0) {
1892 struct gl_texture_object
*t
= _mesa_lookup_texture(ctx
, texName
[i
]);
1894 t
->Priority
= CLAMP( priorities
[i
], 0.0F
, 1.0F
);
1899 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
;
1905 * See if textures are loaded in texture memory.
1907 * \param n number of textures to query.
1908 * \param texName array with the texture names.
1909 * \param residences array which will hold the residence status.
1911 * \return GL_TRUE if all textures are resident and
1912 * residences is left unchanged,
1914 * Note: we assume all textures are always resident
1916 GLboolean GLAPIENTRY
1917 _mesa_AreTexturesResident(GLsizei n
, const GLuint
*texName
,
1918 GLboolean
*residences
)
1920 GET_CURRENT_CONTEXT(ctx
);
1921 GLboolean allResident
= GL_TRUE
;
1923 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1925 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1926 _mesa_debug(ctx
, "glAreTexturesResident %d\n", n
);
1929 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident(n)");
1933 if (!texName
|| !residences
)
1936 /* We only do error checking on the texture names */
1937 for (i
= 0; i
< n
; i
++) {
1938 struct gl_texture_object
*t
;
1939 if (texName
[i
] == 0) {
1940 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident");
1943 t
= _mesa_lookup_texture(ctx
, texName
[i
]);
1945 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident");
1955 * See if a name corresponds to a texture.
1957 * \param texture texture name.
1959 * \return GL_TRUE if texture name corresponds to a texture, or GL_FALSE
1962 * \sa glIsTexture().
1964 * Calls _mesa_HashLookup().
1966 GLboolean GLAPIENTRY
1967 _mesa_IsTexture( GLuint texture
)
1969 struct gl_texture_object
*t
;
1970 GET_CURRENT_CONTEXT(ctx
);
1971 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1973 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1974 _mesa_debug(ctx
, "glIsTexture %d\n", texture
);
1979 t
= _mesa_lookup_texture(ctx
, texture
);
1981 /* IsTexture is true only after object has been bound once. */
1982 return t
&& t
->Target
;
1987 * Simplest implementation of texture locking: grab the shared tex
1988 * mutex. Examine the shared context state timestamp and if there has
1989 * been a change, set the appropriate bits in ctx->NewState.
1991 * This is used to deal with synchronizing things when a texture object
1992 * is used/modified by different contexts (or threads) which are sharing
1995 * See also _mesa_lock/unlock_texture() in teximage.h
1998 _mesa_lock_context_textures( struct gl_context
*ctx
)
2000 mtx_lock(&ctx
->Shared
->TexMutex
);
2002 if (ctx
->Shared
->TextureStateStamp
!= ctx
->TextureStateTimestamp
) {
2003 ctx
->NewState
|= _NEW_TEXTURE_OBJECT
;
2004 ctx
->TextureStateTimestamp
= ctx
->Shared
->TextureStateStamp
;
2010 _mesa_unlock_context_textures( struct gl_context
*ctx
)
2012 assert(ctx
->Shared
->TextureStateStamp
== ctx
->TextureStateTimestamp
);
2013 mtx_unlock(&ctx
->Shared
->TexMutex
);
2018 _mesa_InvalidateTexSubImage(GLuint texture
, GLint level
, GLint xoffset
,
2019 GLint yoffset
, GLint zoffset
, GLsizei width
,
2020 GLsizei height
, GLsizei depth
)
2022 struct gl_texture_object
*t
;
2023 struct gl_texture_image
*image
;
2024 GET_CURRENT_CONTEXT(ctx
);
2026 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2027 _mesa_debug(ctx
, "glInvalidateTexSubImage %d\n", texture
);
2029 t
= invalidate_tex_image_error_check(ctx
, texture
, level
,
2030 "glInvalidateTexSubImage");
2032 /* The GL_ARB_invalidate_subdata spec says:
2034 * "...the specified subregion must be between -<b> and <dim>+<b> where
2035 * <dim> is the size of the dimension of the texture image, and <b> is
2036 * the size of the border of that texture image, otherwise
2037 * INVALID_VALUE is generated (border is not applied to dimensions that
2038 * don't exist in a given texture target)."
2040 image
= t
->Image
[0][level
];
2049 /* The GL_ARB_invalidate_subdata spec says:
2051 * "For texture targets that don't have certain dimensions, this
2052 * command treats those dimensions as having a size of 1. For
2053 * example, to invalidate a portion of a two-dimensional texture,
2054 * the application would use <zoffset> equal to zero and <depth>
2057 switch (t
->Target
) {
2058 case GL_TEXTURE_BUFFER
:
2067 xBorder
= image
->Border
;
2070 imageWidth
= image
->Width
;
2074 case GL_TEXTURE_1D_ARRAY
:
2075 xBorder
= image
->Border
;
2078 imageWidth
= image
->Width
;
2079 imageHeight
= image
->Height
;
2083 case GL_TEXTURE_CUBE_MAP
:
2084 case GL_TEXTURE_RECTANGLE
:
2085 case GL_TEXTURE_2D_MULTISAMPLE
:
2086 xBorder
= image
->Border
;
2087 yBorder
= image
->Border
;
2089 imageWidth
= image
->Width
;
2090 imageHeight
= image
->Height
;
2093 case GL_TEXTURE_2D_ARRAY
:
2094 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2095 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2096 xBorder
= image
->Border
;
2097 yBorder
= image
->Border
;
2099 imageWidth
= image
->Width
;
2100 imageHeight
= image
->Height
;
2101 imageDepth
= image
->Depth
;
2104 xBorder
= image
->Border
;
2105 yBorder
= image
->Border
;
2106 zBorder
= image
->Border
;
2107 imageWidth
= image
->Width
;
2108 imageHeight
= image
->Height
;
2109 imageDepth
= image
->Depth
;
2112 assert(!"Should not get here.");
2122 if (xoffset
< -xBorder
) {
2123 _mesa_error(ctx
, GL_INVALID_VALUE
, "glInvalidateSubTexImage(xoffset)");
2127 if (xoffset
+ width
> imageWidth
+ xBorder
) {
2128 _mesa_error(ctx
, GL_INVALID_VALUE
,
2129 "glInvalidateSubTexImage(xoffset+width)");
2133 if (yoffset
< -yBorder
) {
2134 _mesa_error(ctx
, GL_INVALID_VALUE
, "glInvalidateSubTexImage(yoffset)");
2138 if (yoffset
+ height
> imageHeight
+ yBorder
) {
2139 _mesa_error(ctx
, GL_INVALID_VALUE
,
2140 "glInvalidateSubTexImage(yoffset+height)");
2144 if (zoffset
< -zBorder
) {
2145 _mesa_error(ctx
, GL_INVALID_VALUE
,
2146 "glInvalidateSubTexImage(zoffset)");
2150 if (zoffset
+ depth
> imageDepth
+ zBorder
) {
2151 _mesa_error(ctx
, GL_INVALID_VALUE
,
2152 "glInvalidateSubTexImage(zoffset+depth)");
2157 /* We don't actually do anything for this yet. Just return after
2158 * validating the parameters and generating the required errors.
2165 _mesa_InvalidateTexImage(GLuint texture
, GLint level
)
2167 GET_CURRENT_CONTEXT(ctx
);
2169 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2170 _mesa_debug(ctx
, "glInvalidateTexImage(%d, %d)\n", texture
, level
);
2172 invalidate_tex_image_error_check(ctx
, texture
, level
,
2173 "glInvalidateTexImage");
2175 /* We don't actually do anything for this yet. Just return after
2176 * validating the parameters and generating the required errors.