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
;
121 texObj
= _mesa_lookup_texture(ctx
, id
); /* Returns NULL if not found. */
124 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(texture)", func
);
130 _mesa_begin_texture_lookups(struct gl_context
*ctx
)
132 _mesa_HashLockMutex(ctx
->Shared
->TexObjects
);
137 _mesa_end_texture_lookups(struct gl_context
*ctx
)
139 _mesa_HashUnlockMutex(ctx
->Shared
->TexObjects
);
143 struct gl_texture_object
*
144 _mesa_lookup_texture_locked(struct gl_context
*ctx
, GLuint id
)
146 return (struct gl_texture_object
*)
147 _mesa_HashLookupLocked(ctx
->Shared
->TexObjects
, id
);
151 * Return a pointer to the current texture object for the given target
152 * on the current texture unit.
153 * Note: all <target> error checking should have been done by this point.
155 struct gl_texture_object
*
156 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
158 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
159 const GLboolean arrayTex
= ctx
->Extensions
.EXT_texture_array
;
163 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
164 case GL_PROXY_TEXTURE_1D
:
165 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
167 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
168 case GL_PROXY_TEXTURE_2D
:
169 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
171 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
172 case GL_PROXY_TEXTURE_3D
:
173 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
174 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
175 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
176 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
177 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
178 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
179 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
180 case GL_TEXTURE_CUBE_MAP
:
181 return ctx
->Extensions
.ARB_texture_cube_map
182 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
183 case GL_PROXY_TEXTURE_CUBE_MAP
:
184 return ctx
->Extensions
.ARB_texture_cube_map
185 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
186 case GL_TEXTURE_CUBE_MAP_ARRAY
:
187 return _mesa_has_texture_cube_map_array(ctx
)
188 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
189 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
190 return _mesa_has_texture_cube_map_array(ctx
)
191 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
192 case GL_TEXTURE_RECTANGLE_NV
:
193 return ctx
->Extensions
.NV_texture_rectangle
194 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
195 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
196 return ctx
->Extensions
.NV_texture_rectangle
197 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
198 case GL_TEXTURE_1D_ARRAY_EXT
:
199 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
200 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
201 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
202 case GL_TEXTURE_2D_ARRAY_EXT
:
203 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
204 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
205 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
206 case GL_TEXTURE_BUFFER
:
207 return (_mesa_has_ARB_texture_buffer_object(ctx
) ||
208 _mesa_has_OES_texture_buffer(ctx
)) ?
209 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
210 case GL_TEXTURE_EXTERNAL_OES
:
211 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
212 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
213 case GL_TEXTURE_2D_MULTISAMPLE
:
214 return ctx
->Extensions
.ARB_texture_multisample
215 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
216 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
217 return ctx
->Extensions
.ARB_texture_multisample
218 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
219 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
220 return ctx
->Extensions
.ARB_texture_multisample
221 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
222 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
223 return ctx
->Extensions
.ARB_texture_multisample
224 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
226 _mesa_problem(NULL
, "bad target in _mesa_get_current_tex_object()");
233 * Allocate and initialize a new texture object. But don't put it into the
234 * texture object hash table.
236 * Called via ctx->Driver.NewTextureObject, unless overridden by a device
239 * \param shared the shared GL state structure to contain the texture object
240 * \param name integer name for the texture object
241 * \param target either GL_TEXTURE_1D, GL_TEXTURE_2D, GL_TEXTURE_3D,
242 * GL_TEXTURE_CUBE_MAP or GL_TEXTURE_RECTANGLE_NV. zero is ok for the sake
245 * \return pointer to new texture object.
247 struct gl_texture_object
*
248 _mesa_new_texture_object( struct gl_context
*ctx
, GLuint name
, GLenum target
)
250 struct gl_texture_object
*obj
;
252 obj
= MALLOC_STRUCT(gl_texture_object
);
253 _mesa_initialize_texture_object(ctx
, obj
, name
, target
);
259 * Initialize a new texture object to default values.
260 * \param obj the texture object
261 * \param name the texture name
262 * \param target the texture target
265 _mesa_initialize_texture_object( struct gl_context
*ctx
,
266 struct gl_texture_object
*obj
,
267 GLuint name
, GLenum target
)
269 assert(target
== 0 ||
270 target
== GL_TEXTURE_1D
||
271 target
== GL_TEXTURE_2D
||
272 target
== GL_TEXTURE_3D
||
273 target
== GL_TEXTURE_CUBE_MAP
||
274 target
== GL_TEXTURE_RECTANGLE_NV
||
275 target
== GL_TEXTURE_1D_ARRAY_EXT
||
276 target
== GL_TEXTURE_2D_ARRAY_EXT
||
277 target
== GL_TEXTURE_EXTERNAL_OES
||
278 target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
279 target
== GL_TEXTURE_BUFFER
||
280 target
== GL_TEXTURE_2D_MULTISAMPLE
||
281 target
== GL_TEXTURE_2D_MULTISAMPLE_ARRAY
);
283 memset(obj
, 0, sizeof(*obj
));
284 /* init the non-zero fields */
285 mtx_init(&obj
->Mutex
, mtx_plain
);
288 obj
->Target
= target
;
290 obj
->TargetIndex
= _mesa_tex_target_to_index(ctx
, target
);
293 obj
->TargetIndex
= NUM_TEXTURE_TARGETS
; /* invalid/error value */
295 obj
->Priority
= 1.0F
;
297 obj
->MaxLevel
= 1000;
299 /* must be one; no support for (YUV) planes in separate buffers */
300 obj
->RequiredTextureImageUnits
= 1;
303 if (target
== GL_TEXTURE_RECTANGLE_NV
||
304 target
== GL_TEXTURE_EXTERNAL_OES
) {
305 obj
->Sampler
.WrapS
= GL_CLAMP_TO_EDGE
;
306 obj
->Sampler
.WrapT
= GL_CLAMP_TO_EDGE
;
307 obj
->Sampler
.WrapR
= GL_CLAMP_TO_EDGE
;
308 obj
->Sampler
.MinFilter
= GL_LINEAR
;
311 obj
->Sampler
.WrapS
= GL_REPEAT
;
312 obj
->Sampler
.WrapT
= GL_REPEAT
;
313 obj
->Sampler
.WrapR
= GL_REPEAT
;
314 obj
->Sampler
.MinFilter
= GL_NEAREST_MIPMAP_LINEAR
;
316 obj
->Sampler
.MagFilter
= GL_LINEAR
;
317 obj
->Sampler
.MinLod
= -1000.0;
318 obj
->Sampler
.MaxLod
= 1000.0;
319 obj
->Sampler
.LodBias
= 0.0;
320 obj
->Sampler
.MaxAnisotropy
= 1.0;
321 obj
->Sampler
.CompareMode
= GL_NONE
; /* ARB_shadow */
322 obj
->Sampler
.CompareFunc
= GL_LEQUAL
; /* ARB_shadow */
323 obj
->DepthMode
= ctx
->API
== API_OPENGL_CORE
? GL_RED
: GL_LUMINANCE
;
324 obj
->StencilSampling
= false;
325 obj
->Sampler
.CubeMapSeamless
= GL_FALSE
;
326 obj
->Swizzle
[0] = GL_RED
;
327 obj
->Swizzle
[1] = GL_GREEN
;
328 obj
->Swizzle
[2] = GL_BLUE
;
329 obj
->Swizzle
[3] = GL_ALPHA
;
330 obj
->_Swizzle
= SWIZZLE_NOOP
;
331 obj
->Sampler
.sRGBDecode
= GL_DECODE_EXT
;
332 obj
->BufferObjectFormat
= GL_R8
;
333 obj
->_BufferObjectFormat
= MESA_FORMAT_R_UNORM8
;
334 obj
->ImageFormatCompatibilityType
= GL_IMAGE_FORMAT_COMPATIBILITY_BY_SIZE
;
339 * Some texture initialization can't be finished until we know which
340 * target it's getting bound to (GL_TEXTURE_1D/2D/etc).
343 finish_texture_init(struct gl_context
*ctx
, GLenum target
,
344 struct gl_texture_object
*obj
)
346 GLenum filter
= GL_LINEAR
;
347 assert(obj
->Target
== 0);
349 obj
->Target
= target
;
350 obj
->TargetIndex
= _mesa_tex_target_to_index(ctx
, target
);
351 assert(obj
->TargetIndex
< NUM_TEXTURE_TARGETS
);
354 case GL_TEXTURE_2D_MULTISAMPLE
:
355 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
359 case GL_TEXTURE_RECTANGLE_NV
:
360 case GL_TEXTURE_EXTERNAL_OES
:
361 /* have to init wrap and filter state here - kind of klunky */
362 obj
->Sampler
.WrapS
= GL_CLAMP_TO_EDGE
;
363 obj
->Sampler
.WrapT
= GL_CLAMP_TO_EDGE
;
364 obj
->Sampler
.WrapR
= GL_CLAMP_TO_EDGE
;
365 obj
->Sampler
.MinFilter
= filter
;
366 obj
->Sampler
.MagFilter
= filter
;
367 if (ctx
->Driver
.TexParameter
) {
368 static const GLfloat fparam_wrap
[1] = {(GLfloat
) GL_CLAMP_TO_EDGE
};
369 const GLfloat fparam_filter
[1] = {(GLfloat
) filter
};
370 ctx
->Driver
.TexParameter(ctx
, obj
, GL_TEXTURE_WRAP_S
, fparam_wrap
);
371 ctx
->Driver
.TexParameter(ctx
, obj
, GL_TEXTURE_WRAP_T
, fparam_wrap
);
372 ctx
->Driver
.TexParameter(ctx
, obj
, GL_TEXTURE_WRAP_R
, fparam_wrap
);
373 ctx
->Driver
.TexParameter(ctx
, obj
,
374 GL_TEXTURE_MIN_FILTER
, fparam_filter
);
375 ctx
->Driver
.TexParameter(ctx
, obj
,
376 GL_TEXTURE_MAG_FILTER
, fparam_filter
);
381 /* nothing needs done */
388 * Deallocate a texture object struct. It should have already been
389 * removed from the texture object pool.
390 * Called via ctx->Driver.DeleteTexture() if not overriden by a driver.
392 * \param shared the shared GL state to which the object belongs.
393 * \param texObj the texture object to delete.
396 _mesa_delete_texture_object(struct gl_context
*ctx
,
397 struct gl_texture_object
*texObj
)
401 /* Set Target to an invalid value. With some assertions elsewhere
402 * we can try to detect possible use of deleted textures.
404 texObj
->Target
= 0x99;
406 /* free the texture images */
407 for (face
= 0; face
< 6; face
++) {
408 for (i
= 0; i
< MAX_TEXTURE_LEVELS
; i
++) {
409 if (texObj
->Image
[face
][i
]) {
410 ctx
->Driver
.DeleteTextureImage(ctx
, texObj
->Image
[face
][i
]);
415 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, NULL
);
417 /* destroy the mutex -- it may have allocated memory (eg on bsd) */
418 mtx_destroy(&texObj
->Mutex
);
422 /* free this object */
428 * Copy texture object state from one texture object to another.
429 * Use for glPush/PopAttrib.
431 * \param dest destination texture object.
432 * \param src source texture object.
435 _mesa_copy_texture_object( struct gl_texture_object
*dest
,
436 const struct gl_texture_object
*src
)
438 dest
->Target
= src
->Target
;
439 dest
->TargetIndex
= src
->TargetIndex
;
440 dest
->Name
= src
->Name
;
441 dest
->Priority
= src
->Priority
;
442 dest
->Sampler
.BorderColor
.f
[0] = src
->Sampler
.BorderColor
.f
[0];
443 dest
->Sampler
.BorderColor
.f
[1] = src
->Sampler
.BorderColor
.f
[1];
444 dest
->Sampler
.BorderColor
.f
[2] = src
->Sampler
.BorderColor
.f
[2];
445 dest
->Sampler
.BorderColor
.f
[3] = src
->Sampler
.BorderColor
.f
[3];
446 dest
->Sampler
.WrapS
= src
->Sampler
.WrapS
;
447 dest
->Sampler
.WrapT
= src
->Sampler
.WrapT
;
448 dest
->Sampler
.WrapR
= src
->Sampler
.WrapR
;
449 dest
->Sampler
.MinFilter
= src
->Sampler
.MinFilter
;
450 dest
->Sampler
.MagFilter
= src
->Sampler
.MagFilter
;
451 dest
->Sampler
.MinLod
= src
->Sampler
.MinLod
;
452 dest
->Sampler
.MaxLod
= src
->Sampler
.MaxLod
;
453 dest
->Sampler
.LodBias
= src
->Sampler
.LodBias
;
454 dest
->BaseLevel
= src
->BaseLevel
;
455 dest
->MaxLevel
= src
->MaxLevel
;
456 dest
->Sampler
.MaxAnisotropy
= src
->Sampler
.MaxAnisotropy
;
457 dest
->Sampler
.CompareMode
= src
->Sampler
.CompareMode
;
458 dest
->Sampler
.CompareFunc
= src
->Sampler
.CompareFunc
;
459 dest
->Sampler
.CubeMapSeamless
= src
->Sampler
.CubeMapSeamless
;
460 dest
->DepthMode
= src
->DepthMode
;
461 dest
->StencilSampling
= src
->StencilSampling
;
462 dest
->Sampler
.sRGBDecode
= src
->Sampler
.sRGBDecode
;
463 dest
->_MaxLevel
= src
->_MaxLevel
;
464 dest
->_MaxLambda
= src
->_MaxLambda
;
465 dest
->GenerateMipmap
= src
->GenerateMipmap
;
466 dest
->_BaseComplete
= src
->_BaseComplete
;
467 dest
->_MipmapComplete
= src
->_MipmapComplete
;
468 COPY_4V(dest
->Swizzle
, src
->Swizzle
);
469 dest
->_Swizzle
= src
->_Swizzle
;
470 dest
->_IsHalfFloat
= src
->_IsHalfFloat
;
471 dest
->_IsFloat
= src
->_IsFloat
;
473 dest
->RequiredTextureImageUnits
= src
->RequiredTextureImageUnits
;
478 * Free all texture images of the given texture object.
480 * \param ctx GL context.
481 * \param t texture object.
483 * \sa _mesa_clear_texture_image().
486 _mesa_clear_texture_object(struct gl_context
*ctx
,
487 struct gl_texture_object
*texObj
)
491 if (texObj
->Target
== 0)
494 for (i
= 0; i
< MAX_FACES
; i
++) {
495 for (j
= 0; j
< MAX_TEXTURE_LEVELS
; j
++) {
496 struct gl_texture_image
*texImage
= texObj
->Image
[i
][j
];
498 _mesa_clear_texture_image(ctx
, texImage
);
505 * Check if the given texture object is valid by examining its Target field.
506 * For debugging only.
509 valid_texture_object(const struct gl_texture_object
*tex
)
511 switch (tex
->Target
) {
516 case GL_TEXTURE_CUBE_MAP
:
517 case GL_TEXTURE_RECTANGLE_NV
:
518 case GL_TEXTURE_1D_ARRAY_EXT
:
519 case GL_TEXTURE_2D_ARRAY_EXT
:
520 case GL_TEXTURE_BUFFER
:
521 case GL_TEXTURE_EXTERNAL_OES
:
522 case GL_TEXTURE_CUBE_MAP_ARRAY
:
523 case GL_TEXTURE_2D_MULTISAMPLE
:
524 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
527 _mesa_problem(NULL
, "invalid reference to a deleted texture object");
530 _mesa_problem(NULL
, "invalid texture object Target 0x%x, Id = %u",
531 tex
->Target
, tex
->Name
);
538 * Reference (or unreference) a texture object.
539 * If '*ptr', decrement *ptr's refcount (and delete if it becomes zero).
540 * If 'tex' is non-null, increment its refcount.
541 * This is normally only called from the _mesa_reference_texobj() macro
542 * when there's a real pointer change.
545 _mesa_reference_texobj_(struct gl_texture_object
**ptr
,
546 struct gl_texture_object
*tex
)
551 /* Unreference the old texture */
552 GLboolean deleteFlag
= GL_FALSE
;
553 struct gl_texture_object
*oldTex
= *ptr
;
555 assert(valid_texture_object(oldTex
));
556 (void) valid_texture_object
; /* silence warning in release builds */
558 mtx_lock(&oldTex
->Mutex
);
559 assert(oldTex
->RefCount
> 0);
562 deleteFlag
= (oldTex
->RefCount
== 0);
563 mtx_unlock(&oldTex
->Mutex
);
566 /* Passing in the context drastically changes the driver code for
567 * framebuffer deletion.
569 GET_CURRENT_CONTEXT(ctx
);
571 ctx
->Driver
.DeleteTexture(ctx
, oldTex
);
573 _mesa_problem(NULL
, "Unable to delete texture, no context");
581 /* reference new texture */
582 assert(valid_texture_object(tex
));
583 mtx_lock(&tex
->Mutex
);
584 if (tex
->RefCount
== 0) {
585 /* this texture's being deleted (look just above) */
586 /* Not sure this can every really happen. Warn if it does. */
587 _mesa_problem(NULL
, "referencing deleted texture object");
594 mtx_unlock(&tex
->Mutex
);
599 enum base_mipmap
{ BASE
, MIPMAP
};
603 * Mark a texture object as incomplete. There are actually three kinds of
605 * 1. "base incomplete": the base level of the texture is invalid so no
606 * texturing is possible.
607 * 2. "mipmap incomplete": a non-base level of the texture is invalid so
608 * mipmap filtering isn't possible, but non-mipmap filtering is.
609 * 3. "texture incompleteness": some combination of texture state and
610 * sampler state renders the texture incomplete.
612 * \param t texture object
613 * \param bm either BASE or MIPMAP to indicate what's incomplete
614 * \param fmt... string describing why it's incomplete (for debugging).
617 incomplete(struct gl_texture_object
*t
, enum base_mipmap bm
,
618 const char *fmt
, ...)
620 if (MESA_DEBUG_FLAGS
& DEBUG_INCOMPLETE_TEXTURE
) {
625 vsnprintf(s
, sizeof(s
), fmt
, args
);
628 _mesa_debug(NULL
, "Texture Obj %d incomplete because: %s\n", t
->Name
, s
);
632 t
->_BaseComplete
= GL_FALSE
;
633 t
->_MipmapComplete
= GL_FALSE
;
638 * Examine a texture object to determine if it is complete.
640 * The gl_texture_object::Complete flag will be set to GL_TRUE or GL_FALSE
643 * \param ctx GL context.
644 * \param t texture object.
646 * According to the texture target, verifies that each of the mipmaps is
647 * present and has the expected size.
650 _mesa_test_texobj_completeness( const struct gl_context
*ctx
,
651 struct gl_texture_object
*t
)
653 const GLint baseLevel
= t
->BaseLevel
;
654 const struct gl_texture_image
*baseImage
;
657 /* We'll set these to FALSE if tests fail below */
658 t
->_BaseComplete
= GL_TRUE
;
659 t
->_MipmapComplete
= GL_TRUE
;
661 if (t
->Target
== GL_TEXTURE_BUFFER
) {
662 /* Buffer textures are always considered complete. The obvious case where
663 * they would be incomplete (no BO attached) is actually specced to be
664 * undefined rendering results.
669 /* Detect cases where the application set the base level to an invalid
672 if ((baseLevel
< 0) || (baseLevel
>= MAX_TEXTURE_LEVELS
)) {
673 incomplete(t
, BASE
, "base level = %d is invalid", baseLevel
);
677 if (t
->MaxLevel
< baseLevel
) {
678 incomplete(t
, MIPMAP
, "MAX_LEVEL (%d) < BASE_LEVEL (%d)",
679 t
->MaxLevel
, baseLevel
);
683 baseImage
= t
->Image
[0][baseLevel
];
685 /* Always need the base level image */
687 incomplete(t
, BASE
, "Image[baseLevel=%d] == NULL", baseLevel
);
691 /* Check width/height/depth for zero */
692 if (baseImage
->Width
== 0 ||
693 baseImage
->Height
== 0 ||
694 baseImage
->Depth
== 0) {
695 incomplete(t
, BASE
, "texture width or height or depth = 0");
699 /* Check if the texture values are integer */
701 GLenum datatype
= _mesa_get_format_datatype(baseImage
->TexFormat
);
702 t
->_IsIntegerFormat
= datatype
== GL_INT
|| datatype
== GL_UNSIGNED_INT
;
705 /* Check if the texture type is Float or HalfFloatOES and ensure Min and Mag
706 * filters are supported in this case.
708 if (_mesa_is_gles(ctx
) && !valid_filter_for_float(ctx
, t
)) {
709 incomplete(t
, BASE
, "Filter is not supported with Float types.");
713 /* Compute _MaxLevel (the maximum mipmap level we'll sample from given the
714 * mipmap image sizes and GL_TEXTURE_MAX_LEVEL state).
718 case GL_TEXTURE_1D_ARRAY_EXT
:
719 maxLevels
= ctx
->Const
.MaxTextureLevels
;
722 case GL_TEXTURE_2D_ARRAY_EXT
:
723 maxLevels
= ctx
->Const
.MaxTextureLevels
;
726 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
728 case GL_TEXTURE_CUBE_MAP
:
729 case GL_TEXTURE_CUBE_MAP_ARRAY
:
730 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
732 case GL_TEXTURE_RECTANGLE_NV
:
733 case GL_TEXTURE_BUFFER
:
734 case GL_TEXTURE_EXTERNAL_OES
:
735 case GL_TEXTURE_2D_MULTISAMPLE
:
736 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
737 maxLevels
= 1; /* no mipmapping */
740 _mesa_problem(ctx
, "Bad t->Target in _mesa_test_texobj_completeness");
744 assert(maxLevels
> 0);
746 t
->_MaxLevel
= MIN3(t
->MaxLevel
,
747 /* 'p' in the GL spec */
748 (int) (baseLevel
+ baseImage
->MaxNumLevels
- 1),
749 /* 'q' in the GL spec */
753 /* Adjust max level for views: the data store may have more levels than
756 t
->_MaxLevel
= MIN2(t
->_MaxLevel
, t
->NumLevels
- 1);
759 /* Compute _MaxLambda = q - p in the spec used during mipmapping */
760 t
->_MaxLambda
= (GLfloat
) (t
->_MaxLevel
- baseLevel
);
763 /* This texture object was created with glTexStorage1/2/3D() so we
764 * know that all the mipmap levels are the right size and all cube
765 * map faces are the same size.
766 * We don't need to do any of the additional checks below.
771 if (t
->Target
== GL_TEXTURE_CUBE_MAP
) {
772 /* Make sure that all six cube map level 0 images are the same size and
774 * Note: we know that the image's width==height (we enforce that
775 * at glTexImage time) so we only need to test the width here.
778 assert(baseImage
->Width2
== baseImage
->Height
);
779 for (face
= 1; face
< 6; face
++) {
780 assert(t
->Image
[face
][baseLevel
] == NULL
||
781 t
->Image
[face
][baseLevel
]->Width2
==
782 t
->Image
[face
][baseLevel
]->Height2
);
783 if (t
->Image
[face
][baseLevel
] == NULL
||
784 t
->Image
[face
][baseLevel
]->Width2
!= baseImage
->Width2
) {
785 incomplete(t
, BASE
, "Cube face missing or mismatched size");
788 if (t
->Image
[face
][baseLevel
]->InternalFormat
!=
789 baseImage
->InternalFormat
) {
790 incomplete(t
, BASE
, "Cube face format mismatch");
793 if (t
->Image
[face
][baseLevel
]->Border
!= baseImage
->Border
) {
794 incomplete(t
, BASE
, "Cube face border size mismatch");
801 * Do mipmap consistency checking.
802 * Note: we don't care about the current texture sampler state here.
803 * To determine texture completeness we'll either look at _BaseComplete
804 * or _MipmapComplete depending on the current minification filter mode.
808 const GLint minLevel
= baseLevel
;
809 const GLint maxLevel
= t
->_MaxLevel
;
810 const GLuint numFaces
= _mesa_num_tex_faces(t
->Target
);
811 GLuint width
, height
, depth
, face
;
813 if (minLevel
> maxLevel
) {
814 incomplete(t
, MIPMAP
, "minLevel > maxLevel");
818 /* Get the base image's dimensions */
819 width
= baseImage
->Width2
;
820 height
= baseImage
->Height2
;
821 depth
= baseImage
->Depth2
;
823 /* Note: this loop will be a no-op for RECT, BUFFER, EXTERNAL,
824 * MULTISAMPLE and MULTISAMPLE_ARRAY textures
826 for (i
= baseLevel
+ 1; i
< maxLevels
; i
++) {
827 /* Compute the expected size of image at level[i] */
831 if (height
> 1 && t
->Target
!= GL_TEXTURE_1D_ARRAY
) {
834 if (depth
> 1 && t
->Target
!= GL_TEXTURE_2D_ARRAY
835 && t
->Target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
839 /* loop over cube faces (or single face otherwise) */
840 for (face
= 0; face
< numFaces
; face
++) {
841 if (i
>= minLevel
&& i
<= maxLevel
) {
842 const struct gl_texture_image
*img
= t
->Image
[face
][i
];
845 incomplete(t
, MIPMAP
, "TexImage[%d] is missing", i
);
848 if (img
->InternalFormat
!= baseImage
->InternalFormat
) {
849 incomplete(t
, MIPMAP
, "Format[i] != Format[baseLevel]");
852 if (img
->Border
!= baseImage
->Border
) {
853 incomplete(t
, MIPMAP
, "Border[i] != Border[baseLevel]");
856 if (img
->Width2
!= width
) {
857 incomplete(t
, MIPMAP
, "TexImage[%d] bad width %u", i
,
861 if (img
->Height2
!= height
) {
862 incomplete(t
, MIPMAP
, "TexImage[%d] bad height %u", i
,
866 if (img
->Depth2
!= depth
) {
867 incomplete(t
, MIPMAP
, "TexImage[%d] bad depth %u", i
,
874 if (width
== 1 && height
== 1 && depth
== 1) {
875 return; /* found smallest needed mipmap, all done! */
883 _mesa_cube_level_complete(const struct gl_texture_object
*texObj
,
886 const struct gl_texture_image
*img0
, *img
;
889 if (texObj
->Target
!= GL_TEXTURE_CUBE_MAP
)
892 if ((level
< 0) || (level
>= MAX_TEXTURE_LEVELS
))
895 /* check first face */
896 img0
= texObj
->Image
[0][level
];
899 img0
->Width
!= img0
->Height
)
902 /* check remaining faces vs. first face */
903 for (face
= 1; face
< 6; face
++) {
904 img
= texObj
->Image
[face
][level
];
906 img
->Width
!= img0
->Width
||
907 img
->Height
!= img0
->Height
||
908 img
->TexFormat
!= img0
->TexFormat
)
916 * Check if the given cube map texture is "cube complete" as defined in
917 * the OpenGL specification.
920 _mesa_cube_complete(const struct gl_texture_object
*texObj
)
922 return _mesa_cube_level_complete(texObj
, texObj
->BaseLevel
);
926 * Mark a texture object dirty. It forces the object to be incomplete
927 * and forces the context to re-validate its state.
929 * \param ctx GL context.
930 * \param texObj texture object.
933 _mesa_dirty_texobj(struct gl_context
*ctx
, struct gl_texture_object
*texObj
)
935 texObj
->_BaseComplete
= GL_FALSE
;
936 texObj
->_MipmapComplete
= GL_FALSE
;
937 ctx
->NewState
|= _NEW_TEXTURE
;
942 * Return pointer to a default/fallback texture of the given type/target.
943 * The texture is an RGBA texture with all texels = (0,0,0,1).
944 * That's the value a GLSL sampler should get when sampling from an
945 * incomplete texture.
947 struct gl_texture_object
*
948 _mesa_get_fallback_texture(struct gl_context
*ctx
, gl_texture_index tex
)
950 if (!ctx
->Shared
->FallbackTex
[tex
]) {
951 /* create fallback texture now */
952 const GLsizei width
= 1, height
= 1;
955 struct gl_texture_object
*texObj
;
956 struct gl_texture_image
*texImage
;
957 mesa_format texFormat
;
958 GLuint dims
, face
, numFaces
= 1;
961 for (face
= 0; face
< 6; face
++) {
964 texel
[4*face
+ 2] = 0x0;
965 texel
[4*face
+ 3] = 0xff;
969 case TEXTURE_2D_ARRAY_INDEX
:
971 target
= GL_TEXTURE_2D_ARRAY
;
973 case TEXTURE_1D_ARRAY_INDEX
:
975 target
= GL_TEXTURE_1D_ARRAY
;
977 case TEXTURE_CUBE_INDEX
:
979 target
= GL_TEXTURE_CUBE_MAP
;
982 case TEXTURE_3D_INDEX
:
984 target
= GL_TEXTURE_3D
;
986 case TEXTURE_RECT_INDEX
:
988 target
= GL_TEXTURE_RECTANGLE
;
990 case TEXTURE_2D_INDEX
:
992 target
= GL_TEXTURE_2D
;
994 case TEXTURE_1D_INDEX
:
996 target
= GL_TEXTURE_1D
;
998 case TEXTURE_BUFFER_INDEX
:
1000 target
= GL_TEXTURE_BUFFER
;
1002 case TEXTURE_CUBE_ARRAY_INDEX
:
1004 target
= GL_TEXTURE_CUBE_MAP_ARRAY
;
1007 case TEXTURE_EXTERNAL_INDEX
:
1009 target
= GL_TEXTURE_EXTERNAL_OES
;
1011 case TEXTURE_2D_MULTISAMPLE_INDEX
:
1013 target
= GL_TEXTURE_2D_MULTISAMPLE
;
1015 case TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
:
1017 target
= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
;
1024 /* create texture object */
1025 texObj
= ctx
->Driver
.NewTextureObject(ctx
, 0, target
);
1029 assert(texObj
->RefCount
== 1);
1030 texObj
->Sampler
.MinFilter
= GL_NEAREST
;
1031 texObj
->Sampler
.MagFilter
= GL_NEAREST
;
1033 texFormat
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
,
1037 /* need a loop here just for cube maps */
1038 for (face
= 0; face
< numFaces
; face
++) {
1039 const GLenum faceTarget
= _mesa_cube_face_target(target
, face
);
1041 /* initialize level[0] texture image */
1042 texImage
= _mesa_get_tex_image(ctx
, texObj
, faceTarget
, 0);
1044 _mesa_init_teximage_fields(ctx
, texImage
,
1046 (dims
> 1) ? height
: 1,
1047 (dims
> 2) ? depth
: 1,
1049 GL_RGBA
, texFormat
);
1051 ctx
->Driver
.TexImage(ctx
, dims
, texImage
,
1052 GL_RGBA
, GL_UNSIGNED_BYTE
, texel
,
1053 &ctx
->DefaultPacking
);
1056 _mesa_test_texobj_completeness(ctx
, texObj
);
1057 assert(texObj
->_BaseComplete
);
1058 assert(texObj
->_MipmapComplete
);
1060 ctx
->Shared
->FallbackTex
[tex
] = texObj
;
1062 return ctx
->Shared
->FallbackTex
[tex
];
1067 * Compute the size of the given texture object, in bytes.
1070 texture_size(const struct gl_texture_object
*texObj
)
1072 const GLuint numFaces
= _mesa_num_tex_faces(texObj
->Target
);
1073 GLuint face
, level
, size
= 0;
1075 for (face
= 0; face
< numFaces
; face
++) {
1076 for (level
= 0; level
< MAX_TEXTURE_LEVELS
; level
++) {
1077 const struct gl_texture_image
*img
= texObj
->Image
[face
][level
];
1079 GLuint sz
= _mesa_format_image_size(img
->TexFormat
, img
->Width
,
1080 img
->Height
, img
->Depth
);
1091 * Callback called from _mesa_HashWalk()
1094 count_tex_size(GLuint key
, void *data
, void *userData
)
1096 const struct gl_texture_object
*texObj
=
1097 (const struct gl_texture_object
*) data
;
1098 GLuint
*total
= (GLuint
*) userData
;
1102 *total
= *total
+ texture_size(texObj
);
1107 * Compute total size (in bytes) of all textures for the given context.
1108 * For debugging purposes.
1111 _mesa_total_texture_memory(struct gl_context
*ctx
)
1113 GLuint tgt
, total
= 0;
1115 _mesa_HashWalk(ctx
->Shared
->TexObjects
, count_tex_size
, &total
);
1117 /* plus, the default texture objects */
1118 for (tgt
= 0; tgt
< NUM_TEXTURE_TARGETS
; tgt
++) {
1119 total
+= texture_size(ctx
->Shared
->DefaultTex
[tgt
]);
1127 * Return the base format for the given texture object by looking
1128 * at the base texture image.
1129 * \return base format (such as GL_RGBA) or GL_NONE if it can't be determined
1132 _mesa_texture_base_format(const struct gl_texture_object
*texObj
)
1134 const struct gl_texture_image
*texImage
= _mesa_base_tex_image(texObj
);
1136 return texImage
? texImage
->_BaseFormat
: GL_NONE
;
1140 static struct gl_texture_object
*
1141 invalidate_tex_image_error_check(struct gl_context
*ctx
, GLuint texture
,
1142 GLint level
, const char *name
)
1144 /* The GL_ARB_invalidate_subdata spec says:
1146 * "If <texture> is zero or is not the name of a texture, the error
1147 * INVALID_VALUE is generated."
1149 * This performs the error check in a different order than listed in the
1150 * spec. We have to get the texture object before we can validate the
1151 * other parameters against values in the texture object.
1153 struct gl_texture_object
*const t
= _mesa_lookup_texture(ctx
, texture
);
1154 if (texture
== 0 || t
== NULL
) {
1155 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(texture)", name
);
1159 /* The GL_ARB_invalidate_subdata spec says:
1161 * "If <level> is less than zero or greater than the base 2 logarithm
1162 * of the maximum texture width, height, or depth, the error
1163 * INVALID_VALUE is generated."
1165 if (level
< 0 || level
> t
->MaxLevel
) {
1166 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level)", name
);
1170 /* The GL_ARB_invalidate_subdata spec says:
1172 * "If the target of <texture> is TEXTURE_RECTANGLE, TEXTURE_BUFFER,
1173 * TEXTURE_2D_MULTISAMPLE, or TEXTURE_2D_MULTISAMPLE_ARRAY, and <level>
1174 * is not zero, the error INVALID_VALUE is generated."
1177 switch (t
->Target
) {
1178 case GL_TEXTURE_RECTANGLE
:
1179 case GL_TEXTURE_BUFFER
:
1180 case GL_TEXTURE_2D_MULTISAMPLE
:
1181 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1182 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level)", name
);
1195 * Helper function for glCreateTextures and glGenTextures. Need this because
1196 * glCreateTextures should throw errors if target = 0. This is not exposed to
1197 * the rest of Mesa to encourage Mesa internals to use nameless textures,
1198 * which do not require expensive hash lookups.
1199 * \param target either 0 or a valid / error-checked texture target enum
1202 create_textures(struct gl_context
*ctx
, GLenum target
,
1203 GLsizei n
, GLuint
*textures
, const char *caller
)
1208 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1209 _mesa_debug(ctx
, "%s %d\n", caller
, n
);
1212 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(n < 0)", caller
);
1220 * This must be atomic (generation and allocation of texture IDs)
1222 _mesa_HashLockMutex(ctx
->Shared
->TexObjects
);
1224 first
= _mesa_HashFindFreeKeyBlock(ctx
->Shared
->TexObjects
, n
);
1226 /* Allocate new, empty texture objects */
1227 for (i
= 0; i
< n
; i
++) {
1228 struct gl_texture_object
*texObj
;
1229 GLuint name
= first
+ i
;
1230 texObj
= ctx
->Driver
.NewTextureObject(ctx
, name
, target
);
1232 _mesa_HashUnlockMutex(ctx
->Shared
->TexObjects
);
1233 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "gl%sTextures", caller
);
1237 /* insert into hash table */
1238 _mesa_HashInsertLocked(ctx
->Shared
->TexObjects
, texObj
->Name
, texObj
);
1243 _mesa_HashUnlockMutex(ctx
->Shared
->TexObjects
);
1249 /***********************************************************************/
1250 /** \name API functions */
1255 * Generate texture names.
1257 * \param n number of texture names to be generated.
1258 * \param textures an array in which will hold the generated texture names.
1260 * \sa glGenTextures(), glCreateTextures().
1262 * Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture
1263 * IDs which are stored in \p textures. Corresponding empty texture
1264 * objects are also generated.
1267 _mesa_GenTextures(GLsizei n
, GLuint
*textures
)
1269 GET_CURRENT_CONTEXT(ctx
);
1270 create_textures(ctx
, 0, n
, textures
, "glGenTextures");
1274 * Create texture objects.
1276 * \param target the texture target for each name to be generated.
1277 * \param n number of texture names to be generated.
1278 * \param textures an array in which will hold the generated texture names.
1280 * \sa glCreateTextures(), glGenTextures().
1282 * Calls _mesa_HashFindFreeKeyBlock() to find a block of free texture
1283 * IDs which are stored in \p textures. Corresponding empty texture
1284 * objects are also generated.
1287 _mesa_CreateTextures(GLenum target
, GLsizei n
, GLuint
*textures
)
1290 GET_CURRENT_CONTEXT(ctx
);
1293 * The 4.5 core profile spec (30.10.2014) doesn't specify what
1294 * glCreateTextures should do with invalid targets, which was probably an
1295 * oversight. This conforms to the spec for glBindTexture.
1297 targetIndex
= _mesa_tex_target_to_index(ctx
, target
);
1298 if (targetIndex
< 0) {
1299 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCreateTextures(target)");
1303 create_textures(ctx
, target
, n
, textures
, "glCreateTextures");
1307 * Check if the given texture object is bound to the current draw or
1308 * read framebuffer. If so, Unbind it.
1311 unbind_texobj_from_fbo(struct gl_context
*ctx
,
1312 struct gl_texture_object
*texObj
)
1314 bool progress
= false;
1316 /* Section 4.4.2 (Attaching Images to Framebuffer Objects), subsection
1317 * "Attaching Texture Images to a Framebuffer," of the OpenGL 3.1 spec
1320 * "If a texture object is deleted while its image is attached to one
1321 * or more attachment points in the currently bound framebuffer, then
1322 * it is as if FramebufferTexture* had been called, with a texture of
1323 * zero, for each attachment point to which this image was attached in
1324 * the currently bound framebuffer. In other words, this texture image
1325 * is first detached from all attachment points in the currently bound
1326 * framebuffer. Note that the texture image is specifically not
1327 * detached from any other framebuffer objects. Detaching the texture
1328 * image from any other framebuffer objects is the responsibility of
1331 if (_mesa_is_user_fbo(ctx
->DrawBuffer
)) {
1332 progress
= _mesa_detach_renderbuffer(ctx
, ctx
->DrawBuffer
, texObj
);
1334 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)
1335 && ctx
->ReadBuffer
!= ctx
->DrawBuffer
) {
1336 progress
= _mesa_detach_renderbuffer(ctx
, ctx
->ReadBuffer
, texObj
)
1341 /* Vertices are already flushed by _mesa_DeleteTextures */
1342 ctx
->NewState
|= _NEW_BUFFERS
;
1347 * Check if the given texture object is bound to any texture image units and
1348 * unbind it if so (revert to default textures).
1351 unbind_texobj_from_texunits(struct gl_context
*ctx
,
1352 struct gl_texture_object
*texObj
)
1354 const gl_texture_index index
= texObj
->TargetIndex
;
1357 if (texObj
->Target
== 0) {
1358 /* texture was never bound */
1362 assert(index
< NUM_TEXTURE_TARGETS
);
1364 for (u
= 0; u
< ctx
->Texture
.NumCurrentTexUsed
; u
++) {
1365 struct gl_texture_unit
*unit
= &ctx
->Texture
.Unit
[u
];
1367 if (texObj
== unit
->CurrentTex
[index
]) {
1368 /* Bind the default texture for this unit/target */
1369 _mesa_reference_texobj(&unit
->CurrentTex
[index
],
1370 ctx
->Shared
->DefaultTex
[index
]);
1371 unit
->_BoundTextures
&= ~(1 << index
);
1378 * Check if the given texture object is bound to any shader image unit
1379 * and unbind it if that's the case.
1382 unbind_texobj_from_image_units(struct gl_context
*ctx
,
1383 struct gl_texture_object
*texObj
)
1387 for (i
= 0; i
< ctx
->Const
.MaxImageUnits
; i
++) {
1388 struct gl_image_unit
*unit
= &ctx
->ImageUnits
[i
];
1390 if (texObj
== unit
->TexObj
) {
1391 _mesa_reference_texobj(&unit
->TexObj
, NULL
);
1392 *unit
= _mesa_default_image_unit(ctx
);
1399 * Unbinds all textures bound to the given texture image unit.
1402 unbind_textures_from_unit(struct gl_context
*ctx
, GLuint unit
)
1404 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[unit
];
1406 while (texUnit
->_BoundTextures
) {
1407 const GLuint index
= ffs(texUnit
->_BoundTextures
) - 1;
1408 struct gl_texture_object
*texObj
= ctx
->Shared
->DefaultTex
[index
];
1410 _mesa_reference_texobj(&texUnit
->CurrentTex
[index
], texObj
);
1412 /* Pass BindTexture call to device driver */
1413 if (ctx
->Driver
.BindTexture
)
1414 ctx
->Driver
.BindTexture(ctx
, unit
, 0, texObj
);
1416 texUnit
->_BoundTextures
&= ~(1 << index
);
1417 ctx
->NewState
|= _NEW_TEXTURE
;
1423 * Delete named textures.
1425 * \param n number of textures to be deleted.
1426 * \param textures array of texture IDs to be deleted.
1428 * \sa glDeleteTextures().
1430 * If we're about to delete a texture that's currently bound to any
1431 * texture unit, unbind the texture first. Decrement the reference
1432 * count on the texture object and delete it if it's zero.
1433 * Recall that texture objects can be shared among several rendering
1437 _mesa_DeleteTextures( GLsizei n
, const GLuint
*textures
)
1439 GET_CURRENT_CONTEXT(ctx
);
1442 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1443 _mesa_debug(ctx
, "glDeleteTextures %d\n", n
);
1446 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteTextures(n < 0)");
1450 FLUSH_VERTICES(ctx
, 0); /* too complex */
1453 _mesa_error(ctx
, GL_INVALID_VALUE
, "glDeleteTextures(n)");
1460 for (i
= 0; i
< n
; i
++) {
1461 if (textures
[i
] > 0) {
1462 struct gl_texture_object
*delObj
1463 = _mesa_lookup_texture(ctx
, textures
[i
]);
1466 _mesa_lock_texture(ctx
, delObj
);
1468 /* Check if texture is bound to any framebuffer objects.
1470 * See section 4.4.2.3 of GL_EXT_framebuffer_object.
1472 unbind_texobj_from_fbo(ctx
, delObj
);
1474 /* Check if this texture is currently bound to any texture units.
1477 unbind_texobj_from_texunits(ctx
, delObj
);
1479 /* Check if this texture is currently bound to any shader
1480 * image unit. If so, unbind it.
1481 * See section 3.9.X of GL_ARB_shader_image_load_store.
1483 unbind_texobj_from_image_units(ctx
, delObj
);
1485 _mesa_unlock_texture(ctx
, delObj
);
1487 ctx
->NewState
|= _NEW_TEXTURE
;
1489 /* The texture _name_ is now free for re-use.
1490 * Remove it from the hash table now.
1492 _mesa_HashRemove(ctx
->Shared
->TexObjects
, delObj
->Name
);
1494 /* Unreference the texobj. If refcount hits zero, the texture
1497 _mesa_reference_texobj(&delObj
, NULL
);
1504 * This deletes a texObj without altering the hash table.
1507 _mesa_delete_nameless_texture(struct gl_context
*ctx
,
1508 struct gl_texture_object
*texObj
)
1513 FLUSH_VERTICES(ctx
, 0);
1515 _mesa_lock_texture(ctx
, texObj
);
1517 /* Check if texture is bound to any framebuffer objects.
1519 * See section 4.4.2.3 of GL_EXT_framebuffer_object.
1521 unbind_texobj_from_fbo(ctx
, texObj
);
1523 /* Check if this texture is currently bound to any texture units.
1526 unbind_texobj_from_texunits(ctx
, texObj
);
1528 /* Check if this texture is currently bound to any shader
1529 * image unit. If so, unbind it.
1530 * See section 3.9.X of GL_ARB_shader_image_load_store.
1532 unbind_texobj_from_image_units(ctx
, texObj
);
1534 _mesa_unlock_texture(ctx
, texObj
);
1536 ctx
->NewState
|= _NEW_TEXTURE
;
1538 /* Unreference the texobj. If refcount hits zero, the texture
1541 _mesa_reference_texobj(&texObj
, NULL
);
1546 * Convert a GL texture target enum such as GL_TEXTURE_2D or GL_TEXTURE_3D
1547 * into the corresponding Mesa texture target index.
1548 * Note that proxy targets are not valid here.
1549 * \return TEXTURE_x_INDEX or -1 if target is invalid
1552 _mesa_tex_target_to_index(const struct gl_context
*ctx
, GLenum target
)
1556 return _mesa_is_desktop_gl(ctx
) ? TEXTURE_1D_INDEX
: -1;
1558 return TEXTURE_2D_INDEX
;
1560 return ctx
->API
!= API_OPENGLES
? TEXTURE_3D_INDEX
: -1;
1561 case GL_TEXTURE_CUBE_MAP
:
1562 return ctx
->Extensions
.ARB_texture_cube_map
1563 ? TEXTURE_CUBE_INDEX
: -1;
1564 case GL_TEXTURE_RECTANGLE
:
1565 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.NV_texture_rectangle
1566 ? TEXTURE_RECT_INDEX
: -1;
1567 case GL_TEXTURE_1D_ARRAY
:
1568 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
1569 ? TEXTURE_1D_ARRAY_INDEX
: -1;
1570 case GL_TEXTURE_2D_ARRAY
:
1571 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1572 || _mesa_is_gles3(ctx
)
1573 ? TEXTURE_2D_ARRAY_INDEX
: -1;
1574 case GL_TEXTURE_BUFFER
:
1575 return (_mesa_has_ARB_texture_buffer_object(ctx
) ||
1576 _mesa_has_OES_texture_buffer(ctx
)) ?
1577 TEXTURE_BUFFER_INDEX
: -1;
1578 case GL_TEXTURE_EXTERNAL_OES
:
1579 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
1580 ? TEXTURE_EXTERNAL_INDEX
: -1;
1581 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1582 return _mesa_has_ARB_texture_cube_map_array(ctx
)
1583 ? TEXTURE_CUBE_ARRAY_INDEX
: -1;
1584 case GL_TEXTURE_2D_MULTISAMPLE
:
1585 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
) ||
1586 _mesa_is_gles31(ctx
)) ? TEXTURE_2D_MULTISAMPLE_INDEX
: -1;
1587 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1588 return ((_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.ARB_texture_multisample
) ||
1589 _mesa_is_gles31(ctx
))
1590 ? TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
: -1;
1598 * Do actual texture binding. All error checking should have been done prior
1599 * to calling this function. Note that the texture target (1D, 2D, etc) is
1600 * always specified by the texObj->TargetIndex.
1602 * \param unit index of texture unit to update
1603 * \param texObj the new texture object (cannot be NULL)
1606 bind_texture(struct gl_context
*ctx
,
1608 struct gl_texture_object
*texObj
)
1610 struct gl_texture_unit
*texUnit
;
1613 assert(unit
< ARRAY_SIZE(ctx
->Texture
.Unit
));
1614 texUnit
= &ctx
->Texture
.Unit
[unit
];
1617 assert(valid_texture_object(texObj
));
1619 targetIndex
= texObj
->TargetIndex
;
1620 assert(targetIndex
>= 0);
1621 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
1623 /* Check if this texture is only used by this context and is already bound.
1624 * If so, just return.
1628 mtx_lock(&ctx
->Shared
->Mutex
);
1629 early_out
= ((ctx
->Shared
->RefCount
== 1)
1630 && (texObj
== texUnit
->CurrentTex
[targetIndex
]));
1631 mtx_unlock(&ctx
->Shared
->Mutex
);
1637 /* flush before changing binding */
1638 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
1640 /* If the refcount on the previously bound texture is decremented to
1641 * zero, it'll be deleted here.
1643 _mesa_reference_texobj(&texUnit
->CurrentTex
[targetIndex
], texObj
);
1645 ctx
->Texture
.NumCurrentTexUsed
= MAX2(ctx
->Texture
.NumCurrentTexUsed
,
1648 if (texObj
->Name
!= 0)
1649 texUnit
->_BoundTextures
|= (1 << targetIndex
);
1651 texUnit
->_BoundTextures
&= ~(1 << targetIndex
);
1653 /* Pass BindTexture call to device driver */
1654 if (ctx
->Driver
.BindTexture
) {
1655 ctx
->Driver
.BindTexture(ctx
, unit
, texObj
->Target
, texObj
);
1661 * Implement glBindTexture(). Do error checking, look-up or create a new
1662 * texture object, then bind it in the current texture unit.
1664 * \param target texture target.
1665 * \param texName texture name.
1668 _mesa_BindTexture( GLenum target
, GLuint texName
)
1670 GET_CURRENT_CONTEXT(ctx
);
1671 struct gl_texture_object
*newTexObj
= NULL
;
1674 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1675 _mesa_debug(ctx
, "glBindTexture %s %d\n",
1676 _mesa_enum_to_string(target
), (GLint
) texName
);
1678 targetIndex
= _mesa_tex_target_to_index(ctx
, target
);
1679 if (targetIndex
< 0) {
1680 _mesa_error(ctx
, GL_INVALID_ENUM
, "glBindTexture(target)");
1683 assert(targetIndex
< NUM_TEXTURE_TARGETS
);
1686 * Get pointer to new texture object (newTexObj)
1689 /* Use a default texture object */
1690 newTexObj
= ctx
->Shared
->DefaultTex
[targetIndex
];
1693 /* non-default texture object */
1694 newTexObj
= _mesa_lookup_texture(ctx
, texName
);
1696 /* error checking */
1697 if (newTexObj
->Target
!= 0 && newTexObj
->Target
!= target
) {
1698 /* The named texture object's target doesn't match the
1701 _mesa_error( ctx
, GL_INVALID_OPERATION
,
1702 "glBindTexture(target mismatch)" );
1705 if (newTexObj
->Target
== 0) {
1706 finish_texture_init(ctx
, target
, newTexObj
);
1710 if (ctx
->API
== API_OPENGL_CORE
) {
1711 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1712 "glBindTexture(non-gen name)");
1716 /* if this is a new texture id, allocate a texture object now */
1717 newTexObj
= ctx
->Driver
.NewTextureObject(ctx
, texName
, target
);
1719 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glBindTexture");
1723 /* and insert it into hash table */
1724 _mesa_HashInsert(ctx
->Shared
->TexObjects
, texName
, newTexObj
);
1728 assert(newTexObj
->Target
== target
);
1729 assert(newTexObj
->TargetIndex
== targetIndex
);
1731 bind_texture(ctx
, ctx
->Texture
.CurrentUnit
, newTexObj
);
1736 * OpenGL 4.5 / GL_ARB_direct_state_access glBindTextureUnit().
1738 * \param unit texture unit.
1739 * \param texture texture name.
1741 * \sa glBindTexture().
1743 * If the named texture is 0, this will reset each target for the specified
1744 * texture unit to its default texture.
1745 * If the named texture is not 0 or a recognized texture name, this throws
1746 * GL_INVALID_OPERATION.
1749 _mesa_BindTextureUnit(GLuint unit
, GLuint texture
)
1751 GET_CURRENT_CONTEXT(ctx
);
1752 struct gl_texture_object
*texObj
;
1754 if (unit
>= _mesa_max_tex_unit(ctx
)) {
1755 _mesa_error(ctx
, GL_INVALID_VALUE
, "glBindTextureUnit(unit=%u)", unit
);
1759 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1760 _mesa_debug(ctx
, "glBindTextureUnit %s %d\n",
1761 _mesa_enum_to_string(GL_TEXTURE0
+unit
), (GLint
) texture
);
1763 /* Section 8.1 (Texture Objects) of the OpenGL 4.5 core profile spec
1765 * "When texture is zero, each of the targets enumerated at the
1766 * beginning of this section is reset to its default texture for the
1767 * corresponding texture image unit."
1770 unbind_textures_from_unit(ctx
, unit
);
1774 /* Get the non-default texture object */
1775 texObj
= _mesa_lookup_texture(ctx
, texture
);
1777 /* Error checking */
1779 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1780 "glBindTextureUnit(non-gen name)");
1783 if (texObj
->Target
== 0) {
1784 /* Texture object was gen'd but never bound so the target is not set */
1785 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glBindTextureUnit(target)");
1788 assert(valid_texture_object(texObj
));
1790 bind_texture(ctx
, unit
, texObj
);
1795 * OpenGL 4.4 / GL_ARB_multi_bind glBindTextures().
1798 _mesa_BindTextures(GLuint first
, GLsizei count
, const GLuint
*textures
)
1800 GET_CURRENT_CONTEXT(ctx
);
1803 /* The ARB_multi_bind spec says:
1805 * "An INVALID_OPERATION error is generated if <first> + <count>
1806 * is greater than the number of texture image units supported
1807 * by the implementation."
1809 if (first
+ count
> ctx
->Const
.MaxCombinedTextureImageUnits
) {
1810 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1811 "glBindTextures(first=%u + count=%d > the value of "
1812 "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS=%u)",
1813 first
, count
, ctx
->Const
.MaxCombinedTextureImageUnits
);
1818 /* Note that the error semantics for multi-bind commands differ from
1819 * those of other GL commands.
1821 * The issues section in the ARB_multi_bind spec says:
1823 * "(11) Typically, OpenGL specifies that if an error is generated by
1824 * a command, that command has no effect. This is somewhat
1825 * unfortunate for multi-bind commands, because it would require
1826 * a first pass to scan the entire list of bound objects for
1827 * errors and then a second pass to actually perform the
1828 * bindings. Should we have different error semantics?
1830 * RESOLVED: Yes. In this specification, when the parameters for
1831 * one of the <count> binding points are invalid, that binding
1832 * point is not updated and an error will be generated. However,
1833 * other binding points in the same command will be updated if
1834 * their parameters are valid and no other error occurs."
1837 _mesa_begin_texture_lookups(ctx
);
1839 for (i
= 0; i
< count
; i
++) {
1840 if (textures
[i
] != 0) {
1841 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[first
+ i
];
1842 struct gl_texture_object
*current
= texUnit
->_Current
;
1843 struct gl_texture_object
*texObj
;
1845 if (current
&& current
->Name
== textures
[i
])
1848 texObj
= _mesa_lookup_texture_locked(ctx
, textures
[i
]);
1850 if (texObj
&& texObj
->Target
!= 0) {
1851 bind_texture(ctx
, first
+ i
, texObj
);
1853 /* The ARB_multi_bind spec says:
1855 * "An INVALID_OPERATION error is generated if any value
1856 * in <textures> is not zero or the name of an existing
1857 * texture object (per binding)."
1859 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1860 "glBindTextures(textures[%d]=%u is not zero "
1861 "or the name of an existing texture object)",
1865 unbind_textures_from_unit(ctx
, first
+ i
);
1869 _mesa_end_texture_lookups(ctx
);
1871 /* Unbind all textures in the range <first> through <first>+<count>-1 */
1872 for (i
= 0; i
< count
; i
++)
1873 unbind_textures_from_unit(ctx
, first
+ i
);
1879 * Set texture priorities.
1881 * \param n number of textures.
1882 * \param texName texture names.
1883 * \param priorities corresponding texture priorities.
1885 * \sa glPrioritizeTextures().
1887 * Looks up each texture in the hash, clamps the corresponding priority between
1888 * 0.0 and 1.0, and calls dd_function_table::PrioritizeTexture.
1891 _mesa_PrioritizeTextures( GLsizei n
, const GLuint
*texName
,
1892 const GLclampf
*priorities
)
1894 GET_CURRENT_CONTEXT(ctx
);
1897 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1898 _mesa_debug(ctx
, "glPrioritizeTextures %d\n", n
);
1900 FLUSH_VERTICES(ctx
, 0);
1903 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPrioritizeTextures" );
1910 for (i
= 0; i
< n
; i
++) {
1911 if (texName
[i
] > 0) {
1912 struct gl_texture_object
*t
= _mesa_lookup_texture(ctx
, texName
[i
]);
1914 t
->Priority
= CLAMP( priorities
[i
], 0.0F
, 1.0F
);
1919 ctx
->NewState
|= _NEW_TEXTURE
;
1925 * See if textures are loaded in texture memory.
1927 * \param n number of textures to query.
1928 * \param texName array with the texture names.
1929 * \param residences array which will hold the residence status.
1931 * \return GL_TRUE if all textures are resident and
1932 * residences is left unchanged,
1934 * Note: we assume all textures are always resident
1936 GLboolean GLAPIENTRY
1937 _mesa_AreTexturesResident(GLsizei n
, const GLuint
*texName
,
1938 GLboolean
*residences
)
1940 GET_CURRENT_CONTEXT(ctx
);
1941 GLboolean allResident
= GL_TRUE
;
1943 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1945 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1946 _mesa_debug(ctx
, "glAreTexturesResident %d\n", n
);
1949 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident(n)");
1953 if (!texName
|| !residences
)
1956 /* We only do error checking on the texture names */
1957 for (i
= 0; i
< n
; i
++) {
1958 struct gl_texture_object
*t
;
1959 if (texName
[i
] == 0) {
1960 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident");
1963 t
= _mesa_lookup_texture(ctx
, texName
[i
]);
1965 _mesa_error(ctx
, GL_INVALID_VALUE
, "glAreTexturesResident");
1975 * See if a name corresponds to a texture.
1977 * \param texture texture name.
1979 * \return GL_TRUE if texture name corresponds to a texture, or GL_FALSE
1982 * \sa glIsTexture().
1984 * Calls _mesa_HashLookup().
1986 GLboolean GLAPIENTRY
1987 _mesa_IsTexture( GLuint texture
)
1989 struct gl_texture_object
*t
;
1990 GET_CURRENT_CONTEXT(ctx
);
1991 ASSERT_OUTSIDE_BEGIN_END_WITH_RETVAL(ctx
, GL_FALSE
);
1993 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
1994 _mesa_debug(ctx
, "glIsTexture %d\n", texture
);
1999 t
= _mesa_lookup_texture(ctx
, texture
);
2001 /* IsTexture is true only after object has been bound once. */
2002 return t
&& t
->Target
;
2007 * Simplest implementation of texture locking: grab the shared tex
2008 * mutex. Examine the shared context state timestamp and if there has
2009 * been a change, set the appropriate bits in ctx->NewState.
2011 * This is used to deal with synchronizing things when a texture object
2012 * is used/modified by different contexts (or threads) which are sharing
2015 * See also _mesa_lock/unlock_texture() in teximage.h
2018 _mesa_lock_context_textures( struct gl_context
*ctx
)
2020 mtx_lock(&ctx
->Shared
->TexMutex
);
2022 if (ctx
->Shared
->TextureStateStamp
!= ctx
->TextureStateTimestamp
) {
2023 ctx
->NewState
|= _NEW_TEXTURE
;
2024 ctx
->TextureStateTimestamp
= ctx
->Shared
->TextureStateStamp
;
2030 _mesa_unlock_context_textures( struct gl_context
*ctx
)
2032 assert(ctx
->Shared
->TextureStateStamp
== ctx
->TextureStateTimestamp
);
2033 mtx_unlock(&ctx
->Shared
->TexMutex
);
2038 _mesa_InvalidateTexSubImage(GLuint texture
, GLint level
, GLint xoffset
,
2039 GLint yoffset
, GLint zoffset
, GLsizei width
,
2040 GLsizei height
, GLsizei depth
)
2042 struct gl_texture_object
*t
;
2043 struct gl_texture_image
*image
;
2044 GET_CURRENT_CONTEXT(ctx
);
2046 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2047 _mesa_debug(ctx
, "glInvalidateTexSubImage %d\n", texture
);
2049 t
= invalidate_tex_image_error_check(ctx
, texture
, level
,
2050 "glInvalidateTexSubImage");
2052 /* The GL_ARB_invalidate_subdata spec says:
2054 * "...the specified subregion must be between -<b> and <dim>+<b> where
2055 * <dim> is the size of the dimension of the texture image, and <b> is
2056 * the size of the border of that texture image, otherwise
2057 * INVALID_VALUE is generated (border is not applied to dimensions that
2058 * don't exist in a given texture target)."
2060 image
= t
->Image
[0][level
];
2069 /* The GL_ARB_invalidate_subdata spec says:
2071 * "For texture targets that don't have certain dimensions, this
2072 * command treats those dimensions as having a size of 1. For
2073 * example, to invalidate a portion of a two-dimensional texture,
2074 * the application would use <zoffset> equal to zero and <depth>
2077 switch (t
->Target
) {
2078 case GL_TEXTURE_BUFFER
:
2087 xBorder
= image
->Border
;
2090 imageWidth
= image
->Width
;
2094 case GL_TEXTURE_1D_ARRAY
:
2095 xBorder
= image
->Border
;
2098 imageWidth
= image
->Width
;
2099 imageHeight
= image
->Height
;
2103 case GL_TEXTURE_CUBE_MAP
:
2104 case GL_TEXTURE_RECTANGLE
:
2105 case GL_TEXTURE_2D_MULTISAMPLE
:
2106 xBorder
= image
->Border
;
2107 yBorder
= image
->Border
;
2109 imageWidth
= image
->Width
;
2110 imageHeight
= image
->Height
;
2113 case GL_TEXTURE_2D_ARRAY
:
2114 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2115 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
2116 xBorder
= image
->Border
;
2117 yBorder
= image
->Border
;
2119 imageWidth
= image
->Width
;
2120 imageHeight
= image
->Height
;
2121 imageDepth
= image
->Depth
;
2124 xBorder
= image
->Border
;
2125 yBorder
= image
->Border
;
2126 zBorder
= image
->Border
;
2127 imageWidth
= image
->Width
;
2128 imageHeight
= image
->Height
;
2129 imageDepth
= image
->Depth
;
2132 assert(!"Should not get here.");
2142 if (xoffset
< -xBorder
) {
2143 _mesa_error(ctx
, GL_INVALID_VALUE
, "glInvalidateSubTexImage(xoffset)");
2147 if (xoffset
+ width
> imageWidth
+ xBorder
) {
2148 _mesa_error(ctx
, GL_INVALID_VALUE
,
2149 "glInvalidateSubTexImage(xoffset+width)");
2153 if (yoffset
< -yBorder
) {
2154 _mesa_error(ctx
, GL_INVALID_VALUE
, "glInvalidateSubTexImage(yoffset)");
2158 if (yoffset
+ height
> imageHeight
+ yBorder
) {
2159 _mesa_error(ctx
, GL_INVALID_VALUE
,
2160 "glInvalidateSubTexImage(yoffset+height)");
2164 if (zoffset
< -zBorder
) {
2165 _mesa_error(ctx
, GL_INVALID_VALUE
,
2166 "glInvalidateSubTexImage(zoffset)");
2170 if (zoffset
+ depth
> imageDepth
+ zBorder
) {
2171 _mesa_error(ctx
, GL_INVALID_VALUE
,
2172 "glInvalidateSubTexImage(zoffset+depth)");
2177 /* We don't actually do anything for this yet. Just return after
2178 * validating the parameters and generating the required errors.
2185 _mesa_InvalidateTexImage(GLuint texture
, GLint level
)
2187 GET_CURRENT_CONTEXT(ctx
);
2189 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2190 _mesa_debug(ctx
, "glInvalidateTexImage(%d, %d)\n", texture
, level
);
2192 invalidate_tex_image_error_check(ctx
, texture
, level
,
2193 "glInvalidateTexImage");
2195 /* We don't actually do anything for this yet. Just return after
2196 * validating the parameters and generating the required errors.