2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
44 #include "multisample.h"
45 #include "pixelstore.h"
47 #include "texcompress.h"
48 #include "texcompress_cpal.h"
52 #include "texstorage.h"
53 #include "textureview.h"
55 #include "glformats.h"
61 * State changes which we care about for glCopyTex[Sub]Image() calls.
62 * In particular, we care about pixel transfer state and buffer state
63 * (such as glReadBuffer to make sure we read from the right renderbuffer).
65 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
68 * Returns a corresponding internal floating point format for a given base
69 * format as specifed by OES_texture_float. In case of GL_FLOAT, the internal
70 * format needs to be a 32 bit component and in case of GL_HALF_FLOAT_OES it
71 * needs to be a 16 bit component.
73 * For example, given base format GL_RGBA, type GL_FLOAT return GL_RGBA32F_ARB.
76 adjust_for_oes_float_texture(const struct gl_context
*ctx
,
77 GLenum format
, GLenum type
)
81 if (ctx
->Extensions
.OES_texture_float
) {
88 return GL_ALPHA32F_ARB
;
90 return GL_LUMINANCE32F_ARB
;
91 case GL_LUMINANCE_ALPHA
:
92 return GL_LUMINANCE_ALPHA32F_ARB
;
99 case GL_HALF_FLOAT_OES
:
100 if (ctx
->Extensions
.OES_texture_half_float
) {
107 return GL_ALPHA16F_ARB
;
109 return GL_LUMINANCE16F_ARB
;
110 case GL_LUMINANCE_ALPHA
:
111 return GL_LUMINANCE_ALPHA16F_ARB
;
126 * Returns a corresponding base format for a given internal floating point
127 * format as specifed by OES_texture_float.
130 oes_float_internal_format(const struct gl_context
*ctx
,
131 GLenum format
, GLenum type
)
135 if (ctx
->Extensions
.OES_texture_float
) {
141 case GL_ALPHA32F_ARB
:
143 case GL_LUMINANCE32F_ARB
:
145 case GL_LUMINANCE_ALPHA32F_ARB
:
146 return GL_LUMINANCE_ALPHA
;
153 case GL_HALF_FLOAT_OES
:
154 if (ctx
->Extensions
.OES_texture_half_float
) {
160 case GL_ALPHA16F_ARB
:
162 case GL_LUMINANCE16F_ARB
:
164 case GL_LUMINANCE_ALPHA16F_ARB
:
165 return GL_LUMINANCE_ALPHA
;
177 * Install gl_texture_image in a gl_texture_object according to the target
178 * and level parameters.
180 * \param tObj texture object.
181 * \param target texture target.
182 * \param level image level.
183 * \param texImage texture image.
186 set_tex_image(struct gl_texture_object
*tObj
,
187 GLenum target
, GLint level
,
188 struct gl_texture_image
*texImage
)
190 const GLuint face
= _mesa_tex_target_to_face(target
);
194 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
197 tObj
->Image
[face
][level
] = texImage
;
199 /* Set the 'back' pointer */
200 texImage
->TexObject
= tObj
;
201 texImage
->Level
= level
;
202 texImage
->Face
= face
;
207 * Free a gl_texture_image and associated data.
208 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
210 * \param texImage texture image.
212 * Free the texture image structure and the associated image data.
215 _mesa_delete_texture_image(struct gl_context
*ctx
,
216 struct gl_texture_image
*texImage
)
218 /* Free texImage->Data and/or any other driver-specific texture
221 assert(ctx
->Driver
.FreeTextureImageBuffer
);
222 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
228 * Test if a target is a proxy target.
230 * \param target texture target.
232 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
235 _mesa_is_proxy_texture(GLenum target
)
238 static const GLenum targets
[] = {
242 GL_PROXY_TEXTURE_CUBE_MAP
,
243 GL_PROXY_TEXTURE_RECTANGLE
,
244 GL_PROXY_TEXTURE_1D_ARRAY
,
245 GL_PROXY_TEXTURE_2D_ARRAY
,
246 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
247 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
248 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
251 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
252 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
254 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
256 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
257 if (target
== targets
[i
])
264 * Test if a target is an array target.
266 * \param target texture target.
268 * \return true if the target is an array target, false otherwise.
271 _mesa_is_array_texture(GLenum target
)
274 case GL_TEXTURE_1D_ARRAY
:
275 case GL_TEXTURE_2D_ARRAY
:
276 case GL_TEXTURE_CUBE_MAP_ARRAY
:
277 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
285 * Test if a target is a cube map.
287 * \param target texture target.
289 * \return true if the target is a cube map, false otherwise.
292 _mesa_is_cube_map_texture(GLenum target
)
295 case GL_TEXTURE_CUBE_MAP
:
296 case GL_TEXTURE_CUBE_MAP_ARRAY
:
304 * Return the proxy target which corresponds to the given texture target
307 proxy_target(GLenum target
)
311 case GL_PROXY_TEXTURE_1D
:
312 return GL_PROXY_TEXTURE_1D
;
314 case GL_PROXY_TEXTURE_2D
:
315 return GL_PROXY_TEXTURE_2D
;
317 case GL_PROXY_TEXTURE_3D
:
318 return GL_PROXY_TEXTURE_3D
;
319 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
320 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
321 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
322 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
323 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
324 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
325 case GL_TEXTURE_CUBE_MAP
:
326 case GL_PROXY_TEXTURE_CUBE_MAP
:
327 return GL_PROXY_TEXTURE_CUBE_MAP
;
328 case GL_TEXTURE_RECTANGLE_NV
:
329 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
330 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
331 case GL_TEXTURE_1D_ARRAY_EXT
:
332 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
333 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
334 case GL_TEXTURE_2D_ARRAY_EXT
:
335 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
336 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
337 case GL_TEXTURE_CUBE_MAP_ARRAY
:
338 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
339 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
340 case GL_TEXTURE_2D_MULTISAMPLE
:
341 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
342 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
343 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
344 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
345 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
347 _mesa_problem(NULL
, "unexpected target in proxy_target()");
356 * Get a texture image pointer from a texture object, given a texture
357 * target and mipmap level. The target and level parameters should
358 * have already been error-checked.
360 * \param texObj texture unit.
361 * \param target texture target.
362 * \param level image level.
364 * \return pointer to the texture image structure, or NULL on failure.
366 struct gl_texture_image
*
367 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
368 GLenum target
, GLint level
)
370 const GLuint face
= _mesa_tex_target_to_face(target
);
374 assert(level
< MAX_TEXTURE_LEVELS
);
376 return texObj
->Image
[face
][level
];
381 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
382 * it and install it. Only return NULL if passed a bad parameter or run
385 struct gl_texture_image
*
386 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
387 GLenum target
, GLint level
)
389 struct gl_texture_image
*texImage
;
394 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
396 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
398 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
402 set_tex_image(texObj
, target
, level
, texImage
);
410 * Return pointer to the specified proxy texture image.
411 * Note that proxy textures are per-context, not per-texture unit.
412 * \return pointer to texture image or NULL if invalid target, invalid
413 * level, or out of memory.
415 static struct gl_texture_image
*
416 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
418 struct gl_texture_image
*texImage
;
425 case GL_PROXY_TEXTURE_1D
:
426 if (level
>= ctx
->Const
.MaxTextureLevels
)
428 texIndex
= TEXTURE_1D_INDEX
;
430 case GL_PROXY_TEXTURE_2D
:
431 if (level
>= ctx
->Const
.MaxTextureLevels
)
433 texIndex
= TEXTURE_2D_INDEX
;
435 case GL_PROXY_TEXTURE_3D
:
436 if (level
>= ctx
->Const
.Max3DTextureLevels
)
438 texIndex
= TEXTURE_3D_INDEX
;
440 case GL_PROXY_TEXTURE_CUBE_MAP
:
441 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
443 texIndex
= TEXTURE_CUBE_INDEX
;
445 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
448 texIndex
= TEXTURE_RECT_INDEX
;
450 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
451 if (level
>= ctx
->Const
.MaxTextureLevels
)
453 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
455 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
456 if (level
>= ctx
->Const
.MaxTextureLevels
)
458 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
460 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
461 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
463 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
465 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
468 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
470 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
473 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
479 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
481 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
483 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
486 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
487 /* Set the 'back' pointer */
488 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
495 * Get the maximum number of allowed mipmap levels.
497 * \param ctx GL context.
498 * \param target texture target.
500 * \return the maximum number of allowed mipmap levels for the given
501 * texture target, or zero if passed a bad target.
506 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
510 case GL_PROXY_TEXTURE_1D
:
512 case GL_PROXY_TEXTURE_2D
:
513 return ctx
->Const
.MaxTextureLevels
;
515 case GL_PROXY_TEXTURE_3D
:
516 return ctx
->Const
.Max3DTextureLevels
;
517 case GL_TEXTURE_CUBE_MAP
:
518 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
519 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
520 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
521 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
522 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
523 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
524 case GL_PROXY_TEXTURE_CUBE_MAP
:
525 return ctx
->Extensions
.ARB_texture_cube_map
526 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
527 case GL_TEXTURE_RECTANGLE_NV
:
528 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
529 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
530 case GL_TEXTURE_1D_ARRAY_EXT
:
531 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
532 case GL_TEXTURE_2D_ARRAY_EXT
:
533 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
534 return ctx
->Extensions
.EXT_texture_array
535 ? ctx
->Const
.MaxTextureLevels
: 0;
536 case GL_TEXTURE_CUBE_MAP_ARRAY
:
537 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
538 return _mesa_has_texture_cube_map_array(ctx
)
539 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
540 case GL_TEXTURE_BUFFER
:
541 return (_mesa_has_ARB_texture_buffer_object(ctx
) ||
542 _mesa_has_OES_texture_buffer(ctx
)) ? 1 : 0;
543 case GL_TEXTURE_2D_MULTISAMPLE
:
544 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
545 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
546 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
547 return (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
))
548 && ctx
->Extensions
.ARB_texture_multisample
550 case GL_TEXTURE_EXTERNAL_OES
:
553 return 0; /* bad target */
559 * Return number of dimensions per mipmap level for the given texture target.
562 _mesa_get_texture_dimensions(GLenum target
)
566 case GL_PROXY_TEXTURE_1D
:
569 case GL_TEXTURE_RECTANGLE
:
570 case GL_TEXTURE_CUBE_MAP
:
571 case GL_PROXY_TEXTURE_2D
:
572 case GL_PROXY_TEXTURE_RECTANGLE
:
573 case GL_PROXY_TEXTURE_CUBE_MAP
:
574 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
575 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
576 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
577 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
578 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
579 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
580 case GL_TEXTURE_1D_ARRAY
:
581 case GL_PROXY_TEXTURE_1D_ARRAY
:
582 case GL_TEXTURE_EXTERNAL_OES
:
583 case GL_TEXTURE_2D_MULTISAMPLE
:
584 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
587 case GL_PROXY_TEXTURE_3D
:
588 case GL_TEXTURE_2D_ARRAY
:
589 case GL_PROXY_TEXTURE_2D_ARRAY
:
590 case GL_TEXTURE_CUBE_MAP_ARRAY
:
591 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
592 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
593 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
595 case GL_TEXTURE_BUFFER
:
598 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
606 * Check if a texture target can have more than one layer.
609 _mesa_tex_target_is_layered(GLenum target
)
613 case GL_PROXY_TEXTURE_1D
:
615 case GL_PROXY_TEXTURE_2D
:
616 case GL_TEXTURE_RECTANGLE
:
617 case GL_PROXY_TEXTURE_RECTANGLE
:
618 case GL_TEXTURE_2D_MULTISAMPLE
:
619 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
620 case GL_TEXTURE_BUFFER
:
621 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
623 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
624 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
625 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
626 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
627 case GL_TEXTURE_EXTERNAL_OES
:
631 case GL_PROXY_TEXTURE_3D
:
632 case GL_TEXTURE_CUBE_MAP
:
633 case GL_PROXY_TEXTURE_CUBE_MAP
:
634 case GL_TEXTURE_1D_ARRAY
:
635 case GL_PROXY_TEXTURE_1D_ARRAY
:
636 case GL_TEXTURE_2D_ARRAY
:
637 case GL_PROXY_TEXTURE_2D_ARRAY
:
638 case GL_TEXTURE_CUBE_MAP_ARRAY
:
639 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
640 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
641 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
645 assert(!"Invalid texture target.");
652 * Return the number of layers present in the given level of an array,
653 * cubemap or 3D texture. If the texture is not layered return zero.
656 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
658 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
660 switch (texObj
->Target
) {
663 case GL_TEXTURE_RECTANGLE
:
664 case GL_TEXTURE_2D_MULTISAMPLE
:
665 case GL_TEXTURE_BUFFER
:
666 case GL_TEXTURE_EXTERNAL_OES
:
669 case GL_TEXTURE_CUBE_MAP
:
672 case GL_TEXTURE_1D_ARRAY
: {
673 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
674 return img
? img
->Height
: 0;
678 case GL_TEXTURE_2D_ARRAY
:
679 case GL_TEXTURE_CUBE_MAP_ARRAY
:
680 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
681 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
682 return img
? img
->Depth
: 0;
686 assert(!"Invalid texture target.");
693 * Return the maximum number of mipmap levels for the given target
694 * and the dimensions.
695 * The dimensions are expected not to include the border.
698 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
705 case GL_TEXTURE_1D_ARRAY
:
706 case GL_PROXY_TEXTURE_1D
:
707 case GL_PROXY_TEXTURE_1D_ARRAY
:
710 case GL_TEXTURE_CUBE_MAP
:
711 case GL_TEXTURE_CUBE_MAP_ARRAY
:
712 case GL_PROXY_TEXTURE_CUBE_MAP
:
713 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
717 case GL_TEXTURE_2D_ARRAY
:
718 case GL_PROXY_TEXTURE_2D
:
719 case GL_PROXY_TEXTURE_2D_ARRAY
:
720 size
= MAX2(width
, height
);
723 case GL_PROXY_TEXTURE_3D
:
724 size
= MAX3(width
, height
, depth
);
726 case GL_TEXTURE_RECTANGLE
:
727 case GL_TEXTURE_EXTERNAL_OES
:
728 case GL_TEXTURE_2D_MULTISAMPLE
:
729 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
730 case GL_PROXY_TEXTURE_RECTANGLE
:
731 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
732 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
739 return _mesa_logbase2(size
) + 1;
743 #if 000 /* not used anymore */
745 * glTexImage[123]D can accept a NULL image pointer. In this case we
746 * create a texture image with unspecified image contents per the OpenGL
750 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
752 const GLint components
= _mesa_components_in_format(format
);
753 const GLint numPixels
= width
* height
* depth
;
754 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
758 * Let's see if anyone finds this. If glTexImage2D() is called with
759 * a NULL image pointer then load the texture image with something
760 * interesting instead of leaving it indeterminate.
763 static const char message
[8][32] = {
767 " X X XXXX XXX XXXXX ",
770 " X X XXXXX XXX X X ",
774 GLubyte
*imgPtr
= data
;
776 for (h
= 0; h
< depth
; h
++) {
777 for (i
= 0; i
< height
; i
++) {
778 GLint srcRow
= 7 - (i
% 8);
779 for (j
= 0; j
< width
; j
++) {
780 GLint srcCol
= j
% 32;
781 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
782 for (k
= 0; k
< components
; k
++) {
798 * Set the size and format-related fields of a gl_texture_image struct
799 * to zero. This is used when a proxy texture test fails.
802 clear_teximage_fields(struct gl_texture_image
*img
)
805 img
->_BaseFormat
= 0;
806 img
->InternalFormat
= 0;
817 img
->TexFormat
= MESA_FORMAT_NONE
;
819 img
->FixedSampleLocations
= GL_TRUE
;
824 * Initialize basic fields of the gl_texture_image struct.
826 * \param ctx GL context.
827 * \param img texture image structure to be initialized.
828 * \param width image width.
829 * \param height image height.
830 * \param depth image depth.
831 * \param border image border.
832 * \param internalFormat internal format.
833 * \param format the actual hardware format (one of MESA_FORMAT_*)
834 * \param numSamples number of samples per texel, or zero for non-MS.
835 * \param fixedSampleLocations are sample locations fixed?
837 * Fills in the fields of \p img with the given information.
838 * Note: width, height and depth include the border.
841 _mesa_init_teximage_fields_ms(struct gl_context
*ctx
,
842 struct gl_texture_image
*img
,
843 GLsizei width
, GLsizei height
, GLsizei depth
,
844 GLint border
, GLenum internalFormat
,
846 GLuint numSamples
, GLboolean fixedSampleLocations
)
848 const GLint base_format
=_mesa_base_tex_format(ctx
, internalFormat
);
855 target
= img
->TexObject
->Target
;
856 assert(base_format
!= -1);
857 img
->_BaseFormat
= (GLenum16
)base_format
;
858 img
->InternalFormat
= internalFormat
;
859 img
->Border
= border
;
861 img
->Height
= height
;
864 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
865 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
869 case GL_TEXTURE_BUFFER
:
870 case GL_PROXY_TEXTURE_1D
:
882 case GL_TEXTURE_1D_ARRAY
:
883 case GL_PROXY_TEXTURE_1D_ARRAY
:
884 img
->Height2
= height
; /* no border */
885 img
->HeightLog2
= 0; /* not used */
893 case GL_TEXTURE_RECTANGLE
:
894 case GL_TEXTURE_CUBE_MAP
:
895 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
896 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
897 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
898 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
899 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
900 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
901 case GL_TEXTURE_EXTERNAL_OES
:
902 case GL_PROXY_TEXTURE_2D
:
903 case GL_PROXY_TEXTURE_RECTANGLE
:
904 case GL_PROXY_TEXTURE_CUBE_MAP
:
905 case GL_TEXTURE_2D_MULTISAMPLE
:
906 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
907 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
908 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
915 case GL_TEXTURE_2D_ARRAY
:
916 case GL_PROXY_TEXTURE_2D_ARRAY
:
917 case GL_TEXTURE_CUBE_MAP_ARRAY
:
918 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
919 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
920 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
921 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
922 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
923 img
->Depth2
= depth
; /* no border */
924 img
->DepthLog2
= 0; /* not used */
927 case GL_PROXY_TEXTURE_3D
:
928 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
929 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
930 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
931 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
934 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
939 _mesa_get_tex_max_num_levels(target
,
940 img
->Width2
, img
->Height2
, img
->Depth2
);
941 img
->TexFormat
= format
;
942 img
->NumSamples
= numSamples
;
943 img
->FixedSampleLocations
= fixedSampleLocations
;
948 _mesa_init_teximage_fields(struct gl_context
*ctx
,
949 struct gl_texture_image
*img
,
950 GLsizei width
, GLsizei height
, GLsizei depth
,
951 GLint border
, GLenum internalFormat
,
954 _mesa_init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
955 internalFormat
, format
, 0, GL_TRUE
);
960 * Free and clear fields of the gl_texture_image struct.
962 * \param ctx GL context.
963 * \param texImage texture image structure to be cleared.
965 * After the call, \p texImage will have no data associated with it. Its
966 * fields are cleared so that its parent object will test incomplete.
969 _mesa_clear_texture_image(struct gl_context
*ctx
,
970 struct gl_texture_image
*texImage
)
972 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
973 clear_teximage_fields(texImage
);
978 * Check the width, height, depth and border of a texture image are legal.
979 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
981 * The target and level parameters will have already been validated.
982 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
985 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
986 GLint level
, GLint width
, GLint height
,
987 GLint depth
, GLint border
)
993 case GL_PROXY_TEXTURE_1D
:
994 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
995 maxSize
>>= level
; /* level size */
996 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
998 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
999 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1005 case GL_PROXY_TEXTURE_2D
:
1006 case GL_TEXTURE_2D_MULTISAMPLE
:
1007 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1008 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1010 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1012 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1014 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1015 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1017 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1023 case GL_PROXY_TEXTURE_3D
:
1024 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1026 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1028 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1030 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1032 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1033 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1035 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1037 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1042 case GL_TEXTURE_RECTANGLE_NV
:
1043 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1046 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1047 if (width
< 0 || width
> maxSize
)
1049 if (height
< 0 || height
> maxSize
)
1053 case GL_TEXTURE_CUBE_MAP
:
1054 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1055 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1056 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1057 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1058 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1059 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1060 case GL_PROXY_TEXTURE_CUBE_MAP
:
1061 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1063 if (width
!= height
)
1065 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1067 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1069 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1070 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1072 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1077 case GL_TEXTURE_1D_ARRAY_EXT
:
1078 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1079 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1081 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1083 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1085 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1086 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1091 case GL_TEXTURE_2D_ARRAY_EXT
:
1092 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1093 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1094 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1095 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1097 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1099 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1101 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1103 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1104 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1106 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1111 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1112 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1113 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1114 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1116 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1118 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1120 if (width
!= height
)
1122 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1124 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1125 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1127 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1132 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1138 error_check_subtexture_negative_dimensions(struct gl_context
*ctx
,
1147 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width=%d)", func
, subWidth
);
1151 if (dims
> 1 && subHeight
< 0) {
1152 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height=%d)", func
, subHeight
);
1156 if (dims
> 2 && subDepth
< 0) {
1157 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(depth=%d)", func
, subDepth
);
1165 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1166 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1167 * \param destImage the destination texture image.
1168 * \return GL_TRUE if error found, GL_FALSE otherwise.
1171 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1172 const struct gl_texture_image
*destImage
,
1173 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1174 GLsizei subWidth
, GLsizei subHeight
,
1175 GLsizei subDepth
, const char *func
)
1177 const GLenum target
= destImage
->TexObject
->Target
;
1180 /* check xoffset and width */
1181 if (xoffset
< - (GLint
) destImage
->Border
) {
1182 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset)", func
);
1186 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1187 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset %d + width %d > %u)", func
,
1188 xoffset
, subWidth
, destImage
->Width
);
1192 /* check yoffset and height */
1194 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1195 if (yoffset
< -yBorder
) {
1196 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset)", func
);
1199 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1200 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset %d + height %d > %u)",
1201 func
, yoffset
, subHeight
, destImage
->Height
);
1206 /* check zoffset and depth */
1209 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1210 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1211 0 : destImage
->Border
;
1213 if (zoffset
< -zBorder
) {
1214 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset)", func
);
1218 depth
= (GLint
) destImage
->Depth
;
1219 if (target
== GL_TEXTURE_CUBE_MAP
)
1221 if (zoffset
+ subDepth
> depth
) {
1222 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset %d + depth %d > %u)",
1223 func
, zoffset
, subDepth
, depth
);
1229 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1230 * compressed texture images can be updated. But, that restriction may be
1231 * relaxed for particular compressed formats. At this time, all the
1232 * compressed formats supported by Mesa allow sub-textures to be updated
1233 * along compressed block boundaries.
1235 _mesa_get_format_block_size_3d(destImage
->TexFormat
, &bw
, &bh
, &bd
);
1237 if (bw
!= 1 || bh
!= 1 || bd
!= 1) {
1238 /* offset must be multiple of block size */
1239 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0) || (zoffset
% bd
!= 0)) {
1240 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1241 "%s(xoffset = %d, yoffset = %d, zoffset = %d)",
1242 func
, xoffset
, yoffset
, zoffset
);
1246 /* The size must be a multiple of bw x bh, or we must be using a
1247 * offset+size that exactly hits the edge of the image. This
1248 * is important for small mipmap levels (1x1, 2x1, etc) and for
1251 if ((subWidth
% bw
!= 0) &&
1252 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1253 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1254 "%s(width = %d)", func
, subWidth
);
1258 if ((subHeight
% bh
!= 0) &&
1259 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1260 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1261 "%s(height = %d)", func
, subHeight
);
1265 if ((subDepth
% bd
!= 0) &&
1266 (zoffset
+ subDepth
!= (GLint
) destImage
->Depth
)) {
1267 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1268 "%s(depth = %d)", func
, subDepth
);
1280 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1281 * specific texture image size checks.
1283 * A hardware driver might override this function if, for example, the
1284 * max 3D texture size is 512x512x64 (i.e. not a cube).
1286 * Note that width, height, depth == 0 is not an error. However, a
1287 * texture with zero width/height/depth will be considered "incomplete"
1288 * and texturing will effectively be disabled.
1290 * \param target any texture target/type
1291 * \param numLevels number of mipmap levels in the texture or 0 if not known
1292 * \param level as passed to glTexImage
1293 * \param format the MESA_FORMAT_x for the tex image
1294 * \param numSamples number of samples per texel
1295 * \param width as passed to glTexImage
1296 * \param height as passed to glTexImage
1297 * \param depth as passed to glTexImage
1298 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1301 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
,
1302 GLuint numLevels
, MAYBE_UNUSED GLint level
,
1303 mesa_format format
, GLuint numSamples
,
1304 GLint width
, GLint height
, GLint depth
)
1306 uint64_t bytes
, mbytes
;
1308 if (numLevels
> 0) {
1309 /* Compute total memory for a whole mipmap. This is the path
1310 * taken for glTexStorage(GL_PROXY_TEXTURE_x).
1318 for (l
= 0; l
< numLevels
; l
++) {
1319 GLint nextWidth
, nextHeight
, nextDepth
;
1321 bytes
+= _mesa_format_image_size64(format
, width
, height
, depth
);
1323 if (_mesa_next_mipmap_level_size(target
, 0, width
, height
, depth
,
1324 &nextWidth
, &nextHeight
,
1327 height
= nextHeight
;
1334 /* We just compute the size of one mipmap level. This is the path
1335 * taken for glTexImage(GL_PROXY_TEXTURE_x).
1337 bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1340 bytes
*= _mesa_num_tex_faces(target
);
1341 bytes
*= MAX2(1, numSamples
);
1343 mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1345 /* We just check if the image size is less than MaxTextureMbytes.
1346 * Some drivers may do more specific checks.
1348 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1353 * Return true if the format is only valid for glCompressedTexImage.
1356 compressedteximage_only_format(GLenum format
)
1359 case GL_PALETTE4_RGB8_OES
:
1360 case GL_PALETTE4_RGBA8_OES
:
1361 case GL_PALETTE4_R5_G6_B5_OES
:
1362 case GL_PALETTE4_RGBA4_OES
:
1363 case GL_PALETTE4_RGB5_A1_OES
:
1364 case GL_PALETTE8_RGB8_OES
:
1365 case GL_PALETTE8_RGBA8_OES
:
1366 case GL_PALETTE8_R5_G6_B5_OES
:
1367 case GL_PALETTE8_RGBA4_OES
:
1368 case GL_PALETTE8_RGB5_A1_OES
:
1369 case GL_ATC_RGB_AMD
:
1370 case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
:
1371 case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
:
1379 * Return true if the format doesn't support online compression.
1382 _mesa_format_no_online_compression(GLenum format
)
1384 return _mesa_is_astc_format(format
) ||
1385 _mesa_is_etc2_format(format
) ||
1386 compressedteximage_only_format(format
);
1389 /* Writes to an GL error pointer if non-null and returns whether or not the
1390 * error is GL_NO_ERROR */
1392 write_error(GLenum
*err_ptr
, GLenum error
)
1397 return error
== GL_NO_ERROR
;
1401 * Helper function to determine whether a target and specific compression
1402 * format are supported. The error parameter returns GL_NO_ERROR if the
1403 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1404 * or GL_INVALID_ENUM, whichever is more appropriate.
1407 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1408 GLenum intFormat
, GLenum
*error
)
1410 GLboolean target_can_be_compresed
= GL_FALSE
;
1411 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1412 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1416 case GL_PROXY_TEXTURE_2D
:
1417 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1419 case GL_PROXY_TEXTURE_CUBE_MAP
:
1420 case GL_TEXTURE_CUBE_MAP
:
1421 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1422 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1423 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1424 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1425 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1426 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1427 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1429 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1430 case GL_TEXTURE_2D_ARRAY_EXT
:
1431 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1433 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1434 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1435 /* From the KHR_texture_compression_astc_hdr spec:
1437 * Add a second new column "3D Tex." which is empty for all non-ASTC
1438 * formats. If only the LDR profile is supported by the
1439 * implementation, this column is also empty for all ASTC formats. If
1440 * both the LDR and HDR profiles are supported only, this column is
1441 * checked for all ASTC formats.
1443 * Add a third new column "Cube Map Array Tex." which is empty for all
1444 * non-ASTC formats, and checked for all ASTC formats.
1448 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1449 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1450 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1451 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1452 * 8.19 is *not* checked'
1454 * The instances of <internalformat> above should say <target>.
1456 * ETC2/EAC formats are the only alternative in GLES and thus such errors
1457 * have already been handled by normal ETC2/EAC behavior.
1460 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1462 * "The ETC2/EAC texture compression algorithm supports only
1463 * two-dimensional images. If internalformat is an ETC2/EAC format,
1464 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1465 * target is not TEXTURE_2D_ARRAY."
1467 * This should also be applicable for glTexStorage3D(). Other available
1468 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1470 * Section 8.7, page 179 of OpenGL ES 3.2 adds:
1472 * An INVALID_OPERATION error is generated by CompressedTexImage3D
1473 * if internalformat is one of the the formats in table 8.17 and target is
1474 * not TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY or TEXTURE_3D.
1476 * An INVALID_OPERATION error is generated by CompressedTexImage3D
1477 * if internalformat is TEXTURE_CUBE_MAP_ARRAY and the “Cube Map
1478 * Array” column of table 8.17 is not checked, or if internalformat
1479 * is TEXTURE_- 3D and the “3D Tex.” column of table 8.17 is not
1482 * The instances of <internalformat> above should say <target>.
1484 * Such table 8.17 has checked "Cube Map Array" column for all the
1485 * cases. So in practice, TEXTURE_CUBE_MAP_ARRAY is now valid for OpenGL ES 3.2
1487 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
) &&
1488 !_mesa_is_gles32(ctx
))
1489 return write_error(error
, GL_INVALID_OPERATION
);
1490 target_can_be_compresed
= _mesa_has_texture_cube_map_array(ctx
);
1494 case MESA_FORMAT_LAYOUT_ETC2
:
1495 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1496 if (_mesa_is_gles3(ctx
))
1497 return write_error(error
, GL_INVALID_OPERATION
);
1499 case MESA_FORMAT_LAYOUT_BPTC
:
1500 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1502 case MESA_FORMAT_LAYOUT_ASTC
:
1503 target_can_be_compresed
=
1504 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
1505 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
1507 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1508 * neither of the above extensions are supported. See comment in
1509 * switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1511 if (!target_can_be_compresed
)
1512 return write_error(error
, GL_INVALID_OPERATION
);
1520 return write_error(error
,
1521 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1526 * Check if the given texture target value is legal for a
1527 * glTexImage1/2/3D call.
1530 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1536 case GL_PROXY_TEXTURE_1D
:
1537 return _mesa_is_desktop_gl(ctx
);
1545 case GL_PROXY_TEXTURE_2D
:
1546 return _mesa_is_desktop_gl(ctx
);
1547 case GL_PROXY_TEXTURE_CUBE_MAP
:
1548 return _mesa_is_desktop_gl(ctx
)
1549 && ctx
->Extensions
.ARB_texture_cube_map
;
1550 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1551 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1552 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1553 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1554 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1555 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1556 return ctx
->Extensions
.ARB_texture_cube_map
;
1557 case GL_TEXTURE_RECTANGLE_NV
:
1558 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1559 return _mesa_is_desktop_gl(ctx
)
1560 && ctx
->Extensions
.NV_texture_rectangle
;
1561 case GL_TEXTURE_1D_ARRAY_EXT
:
1562 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1563 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1571 case GL_PROXY_TEXTURE_3D
:
1572 return _mesa_is_desktop_gl(ctx
);
1573 case GL_TEXTURE_2D_ARRAY_EXT
:
1574 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1575 || _mesa_is_gles3(ctx
);
1576 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1577 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1578 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1579 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1580 return _mesa_has_texture_cube_map_array(ctx
);
1585 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1592 * Check if the given texture target value is legal for a
1593 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1594 * The difference compared to legal_teximage_target() above is that
1595 * proxy targets are not supported.
1598 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1603 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1608 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1609 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1610 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1611 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1612 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1613 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1614 return ctx
->Extensions
.ARB_texture_cube_map
;
1615 case GL_TEXTURE_RECTANGLE_NV
:
1616 return _mesa_is_desktop_gl(ctx
)
1617 && ctx
->Extensions
.NV_texture_rectangle
;
1618 case GL_TEXTURE_1D_ARRAY_EXT
:
1619 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1627 case GL_TEXTURE_2D_ARRAY_EXT
:
1628 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1629 || _mesa_is_gles3(ctx
);
1630 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1631 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1632 return _mesa_has_texture_cube_map_array(ctx
);
1634 /* Table 8.15 of the OpenGL 4.5 core profile spec
1635 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1636 * and CopyTextureSubImage3D.
1638 case GL_TEXTURE_CUBE_MAP
:
1644 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1652 * Helper function to determine if a texture object is mutable (in terms
1653 * of GL_ARB_texture_storage/GL_ARB_bindless_texture).
1656 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1658 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1662 if (texObj
->HandleAllocated
) {
1663 /* The ARB_bindless_texture spec says:
1665 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
1666 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
1667 * functions defined in terms of these, if the texture object to be
1668 * modified is referenced by one or more texture or image handles."
1673 return !texObj
->Immutable
;
1678 * Return expected size of a compressed texture.
1681 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1684 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1685 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1689 * Verify that a texture format is valid with a particular target
1691 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1692 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1695 * \param ctx GL context
1696 * \param target Texture target
1697 * \param internalFormat Internal format of the texture image
1699 * \returns true if the combination is legal, false otherwise.
1702 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1703 GLenum target
, GLenum internalFormat
)
1705 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1706 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
1707 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
1708 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1709 * Profile spec says:
1711 * "Textures with a base internal format of DEPTH_COMPONENT or
1712 * DEPTH_STENCIL are supported by texture image specification
1713 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1714 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1715 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1716 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1717 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1718 * formats in conjunction with any other target will result in an
1719 * INVALID_OPERATION error."
1721 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1722 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1724 if (target
!= GL_TEXTURE_1D
&&
1725 target
!= GL_PROXY_TEXTURE_1D
&&
1726 target
!= GL_TEXTURE_2D
&&
1727 target
!= GL_PROXY_TEXTURE_2D
&&
1728 target
!= GL_TEXTURE_1D_ARRAY
&&
1729 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1730 target
!= GL_TEXTURE_2D_ARRAY
&&
1731 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1732 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1733 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1734 !((_mesa_is_cube_face(target
) ||
1735 target
== GL_TEXTURE_CUBE_MAP
||
1736 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1737 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
1738 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
1739 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
1740 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
1741 _mesa_has_texture_cube_map_array(ctx
))) {
1750 texture_formats_agree(GLenum internalFormat
,
1753 GLboolean colorFormat
;
1754 GLboolean is_format_depth_or_depthstencil
;
1755 GLboolean is_internalFormat_depth_or_depthstencil
;
1757 /* Even though there are no color-index textures, we still have to support
1758 * uploading color-index data and remapping it to RGB via the
1759 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1761 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1763 is_internalFormat_depth_or_depthstencil
=
1764 _mesa_is_depth_format(internalFormat
) ||
1765 _mesa_is_depthstencil_format(internalFormat
);
1767 is_format_depth_or_depthstencil
=
1768 _mesa_is_depth_format(format
) ||
1769 _mesa_is_depthstencil_format(format
);
1771 colorFormat
= _mesa_is_color_format(format
);
1773 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
1776 if (is_internalFormat_depth_or_depthstencil
!=
1777 is_format_depth_or_depthstencil
)
1780 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
1787 * Test the combination of format, type and internal format arguments of
1788 * different texture operations on GLES.
1790 * \param ctx GL context.
1791 * \param format pixel data format given by the user.
1792 * \param type pixel data type given by the user.
1793 * \param internalFormat internal format given by the user.
1794 * \param callerName name of the caller function to print in the error message
1796 * \return true if a error is found, false otherwise
1798 * Currently, it is used by texture_error_check() and texsubimage_error_check().
1801 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
1802 GLenum type
, GLenum internalFormat
, const char *callerName
)
1804 GLenum err
= _mesa_gles_error_check_format_and_type(ctx
, format
, type
,
1806 if (err
!= GL_NO_ERROR
) {
1807 _mesa_error(ctx
, err
,
1808 "%s(format = %s, type = %s, internalformat = %s)",
1809 callerName
, _mesa_enum_to_string(format
),
1810 _mesa_enum_to_string(type
),
1811 _mesa_enum_to_string(internalFormat
));
1819 * Test the glTexImage[123]D() parameters for errors.
1821 * \param ctx GL context.
1822 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1823 * \param target texture target given by the user (already validated).
1824 * \param level image level given by the user.
1825 * \param internalFormat internal format given by the user.
1826 * \param format pixel data format given by the user.
1827 * \param type pixel data type given by the user.
1828 * \param width image width given by the user.
1829 * \param height image height given by the user.
1830 * \param depth image depth given by the user.
1831 * \param border image border given by the user.
1833 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1835 * Verifies each of the parameters against the constants specified in
1836 * __struct gl_contextRec::Const and the supported extensions, and according
1837 * to the OpenGL specification.
1838 * Note that we don't fully error-check the width, height, depth values
1839 * here. That's done in _mesa_legal_texture_dimensions() which is used
1840 * by several other GL entrypoints. Plus, texture dims have a special
1841 * interaction with proxy textures.
1844 texture_error_check( struct gl_context
*ctx
,
1845 GLuint dimensions
, GLenum target
,
1846 GLint level
, GLint internalFormat
,
1847 GLenum format
, GLenum type
,
1848 GLint width
, GLint height
,
1849 GLint depth
, GLint border
,
1850 const GLvoid
*pixels
)
1854 /* Note: for proxy textures, some error conditions immediately generate
1855 * a GL error in the usual way. But others do not generate a GL error.
1856 * Instead, they cause the width, height, depth, format fields of the
1857 * texture image to be zeroed-out. The GL spec seems to indicate that the
1858 * zero-out behaviour is only used in cases related to memory allocation.
1862 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1863 _mesa_error(ctx
, GL_INVALID_VALUE
,
1864 "glTexImage%dD(level=%d)", dimensions
, level
);
1869 if (border
< 0 || border
> 1 ||
1870 ((ctx
->API
!= API_OPENGL_COMPAT
||
1871 target
== GL_TEXTURE_RECTANGLE_NV
||
1872 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1873 _mesa_error(ctx
, GL_INVALID_VALUE
,
1874 "glTexImage%dD(border=%d)", dimensions
, border
);
1878 if (width
< 0 || height
< 0 || depth
< 0) {
1879 _mesa_error(ctx
, GL_INVALID_VALUE
,
1880 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1884 /* Check incoming image format and type */
1885 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1886 if (err
!= GL_NO_ERROR
) {
1887 /* Prior to OpenGL-ES 2.0, an INVALID_VALUE is expected instead of
1888 * INVALID_ENUM. From page 73 OpenGL ES 1.1 spec:
1890 * "Specifying a value for internalformat that is not one of the
1891 * above (acceptable) values generates the error INVALID VALUE."
1893 if (err
== GL_INVALID_ENUM
&& _mesa_is_gles(ctx
) && ctx
->Version
< 20)
1894 err
= GL_INVALID_VALUE
;
1896 _mesa_error(ctx
, err
,
1897 "glTexImage%dD(incompatible format = %s, type = %s)",
1898 dimensions
, _mesa_enum_to_string(format
),
1899 _mesa_enum_to_string(type
));
1903 /* Check internalFormat */
1904 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1905 _mesa_error(ctx
, GL_INVALID_VALUE
,
1906 "glTexImage%dD(internalFormat=%s)",
1907 dimensions
, _mesa_enum_to_string(internalFormat
));
1911 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1912 * combinations of format, internalFormat, and type that can be used.
1913 * Formats and types that require additional extensions (e.g., GL_FLOAT
1914 * requires GL_OES_texture_float) are filtered elsewhere.
1916 char bufCallerName
[20];
1917 _mesa_snprintf(bufCallerName
, 20, "glTexImage%dD", dimensions
);
1918 if (_mesa_is_gles(ctx
) &&
1919 texture_format_error_check_gles(ctx
, format
, type
,
1920 internalFormat
, bufCallerName
)) {
1924 /* validate the bound PBO, if any */
1925 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
1926 width
, height
, depth
, format
, type
,
1927 INT_MAX
, pixels
, "glTexImage")) {
1931 /* make sure internal format and format basically agree */
1932 if (!texture_formats_agree(internalFormat
, format
)) {
1933 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1934 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
1935 dimensions
, _mesa_enum_to_string(internalFormat
),
1936 _mesa_enum_to_string(format
));
1940 /* additional checks for ycbcr textures */
1941 if (internalFormat
== GL_YCBCR_MESA
) {
1942 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
1943 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1944 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1946 _mesa_snprintf(message
, sizeof(message
),
1947 "glTexImage%dD(format/type YCBCR mismatch)",
1949 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1950 return GL_TRUE
; /* error */
1952 if (target
!= GL_TEXTURE_2D
&&
1953 target
!= GL_PROXY_TEXTURE_2D
&&
1954 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1955 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1956 _mesa_error(ctx
, GL_INVALID_ENUM
,
1957 "glTexImage%dD(bad target for YCbCr texture)",
1963 _mesa_snprintf(message
, sizeof(message
),
1964 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1965 dimensions
, border
);
1966 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1971 /* additional checks for depth textures */
1972 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
)) {
1973 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1974 "glTexImage%dD(bad target for texture)", dimensions
);
1978 /* additional checks for compressed textures */
1979 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1981 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
1982 _mesa_error(ctx
, err
,
1983 "glTexImage%dD(target can't be compressed)", dimensions
);
1986 if (_mesa_format_no_online_compression(internalFormat
)) {
1987 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1988 "glTexImage%dD(no compression for format)", dimensions
);
1992 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1993 "glTexImage%dD(border!=0)", dimensions
);
1998 /* additional checks for integer textures */
1999 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2000 (_mesa_is_enum_format_integer(format
) !=
2001 _mesa_is_enum_format_integer(internalFormat
))) {
2002 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2003 "glTexImage%dD(integer/non-integer format mismatch)",
2008 if (!mutable_tex_object(ctx
, target
)) {
2009 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2010 "glTexImage%dD(immutable texture)", dimensions
);
2014 /* if we get here, the parameters are OK */
2020 * Error checking for glCompressedTexImage[123]D().
2021 * Note that the width, height and depth values are not fully error checked
2023 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2026 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2027 GLenum target
, GLint level
,
2028 GLenum internalFormat
, GLsizei width
,
2029 GLsizei height
, GLsizei depth
, GLint border
,
2030 GLsizei imageSize
, const GLvoid
*data
)
2032 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2034 GLenum error
= GL_NO_ERROR
;
2035 char *reason
= ""; /* no error */
2037 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
2042 /* This will detect any invalid internalFormat value */
2043 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2044 _mesa_error(ctx
, GL_INVALID_ENUM
,
2045 "glCompressedTexImage%dD(internalFormat=%s)",
2046 dimensions
, _mesa_enum_to_string(internalFormat
));
2050 /* validate the bound PBO, if any */
2051 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2053 "glCompressedTexImage")) {
2057 switch (internalFormat
) {
2058 case GL_PALETTE4_RGB8_OES
:
2059 case GL_PALETTE4_RGBA8_OES
:
2060 case GL_PALETTE4_R5_G6_B5_OES
:
2061 case GL_PALETTE4_RGBA4_OES
:
2062 case GL_PALETTE4_RGB5_A1_OES
:
2063 case GL_PALETTE8_RGB8_OES
:
2064 case GL_PALETTE8_RGBA8_OES
:
2065 case GL_PALETTE8_R5_G6_B5_OES
:
2066 case GL_PALETTE8_RGBA4_OES
:
2067 case GL_PALETTE8_RGB5_A1_OES
:
2068 /* check level (note that level should be zero or less!) */
2069 if (level
> 0 || level
< -maxLevels
) {
2071 error
= GL_INVALID_VALUE
;
2075 if (dimensions
!= 2) {
2076 reason
= "compressed paletted textures must be 2D";
2077 error
= GL_INVALID_OPERATION
;
2081 /* Figure out the expected texture size (in bytes). This will be
2082 * checked against the actual size later.
2084 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2087 /* This is for the benefit of the TestProxyTexImage below. It expects
2088 * level to be non-negative. OES_compressed_paletted_texture uses a
2089 * weird mechanism where the level specified to glCompressedTexImage2D
2090 * is -(n-1) number of levels in the texture, and the data specifies the
2091 * complete mipmap stack. This is done to ensure the palette is the
2092 * same for all levels.
2099 if (level
< 0 || level
>= maxLevels
) {
2101 error
= GL_INVALID_VALUE
;
2105 /* Figure out the expected texture size (in bytes). This will be
2106 * checked against the actual size later.
2108 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2112 /* This should really never fail */
2113 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2114 reason
= "internalFormat";
2115 error
= GL_INVALID_ENUM
;
2119 /* No compressed formats support borders at this time */
2121 reason
= "border != 0";
2122 error
= GL_INVALID_VALUE
;
2126 /* Check for invalid pixel storage modes */
2127 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2129 "glCompressedTexImage")) {
2133 /* check image size in bytes */
2134 if (expectedSize
!= imageSize
) {
2135 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2136 * if <imageSize> is not consistent with the format, dimensions, and
2137 * contents of the specified image.
2139 reason
= "imageSize inconsistent with width/height/format";
2140 error
= GL_INVALID_VALUE
;
2144 if (!mutable_tex_object(ctx
, target
)) {
2145 reason
= "immutable texture";
2146 error
= GL_INVALID_OPERATION
;
2153 /* Note: not all error paths exit through here. */
2154 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2155 dimensions
, reason
);
2162 * Test glTexSubImage[123]D() parameters for errors.
2164 * \param ctx GL context.
2165 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2166 * \param target texture target given by the user (already validated)
2167 * \param level image level given by the user.
2168 * \param xoffset sub-image x offset given by the user.
2169 * \param yoffset sub-image y offset given by the user.
2170 * \param zoffset sub-image z offset given by the user.
2171 * \param format pixel data format given by the user.
2172 * \param type pixel data type given by the user.
2173 * \param width image width given by the user.
2174 * \param height image height given by the user.
2175 * \param depth image depth given by the user.
2177 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2179 * Verifies each of the parameters against the constants specified in
2180 * __struct gl_contextRec::Const and the supported extensions, and according
2181 * to the OpenGL specification.
2184 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2185 struct gl_texture_object
*texObj
,
2186 GLenum target
, GLint level
,
2187 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2188 GLint width
, GLint height
, GLint depth
,
2189 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2190 const char *callerName
)
2192 struct gl_texture_image
*texImage
;
2196 /* must be out of memory */
2197 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2202 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2203 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2207 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2208 width
, height
, depth
,
2213 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2215 /* non-existant texture level */
2216 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture level %d)",
2221 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2222 if (err
!= GL_NO_ERROR
) {
2223 _mesa_error(ctx
, err
,
2224 "%s(incompatible format = %s, type = %s)",
2225 callerName
, _mesa_enum_to_string(format
),
2226 _mesa_enum_to_string(type
));
2230 GLenum internalFormat
= _mesa_is_gles(ctx
) ?
2231 oes_float_internal_format(ctx
, texImage
->InternalFormat
, type
) :
2232 texImage
->InternalFormat
;
2234 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2235 * combinations of format, internalFormat, and type that can be used.
2236 * Formats and types that require additional extensions (e.g., GL_FLOAT
2237 * requires GL_OES_texture_float) are filtered elsewhere.
2239 if (_mesa_is_gles(ctx
) &&
2240 texture_format_error_check_gles(ctx
, format
, type
,
2241 internalFormat
, callerName
)) {
2245 /* validate the bound PBO, if any */
2246 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2247 width
, height
, depth
, format
, type
,
2248 INT_MAX
, pixels
, callerName
)) {
2252 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2253 texImage
, xoffset
, yoffset
, zoffset
,
2254 width
, height
, depth
, callerName
)) {
2258 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2259 if (_mesa_format_no_online_compression(texImage
->InternalFormat
)) {
2260 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2261 "%s(no compression for format)", callerName
);
2266 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2267 /* both source and dest must be integer-valued, or neither */
2268 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2269 _mesa_is_enum_format_integer(format
)) {
2270 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2271 "%s(integer/non-integer format mismatch)", callerName
);
2281 * Test glCopyTexImage[12]D() parameters for errors.
2283 * \param ctx GL context.
2284 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2285 * \param target texture target given by the user.
2286 * \param level image level given by the user.
2287 * \param internalFormat internal format given by the user.
2288 * \param width image width given by the user.
2289 * \param height image height given by the user.
2290 * \param border texture border.
2292 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2294 * Verifies each of the parameters against the constants specified in
2295 * __struct gl_contextRec::Const and the supported extensions, and according
2296 * to the OpenGL specification.
2299 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2300 GLenum target
, GLint level
, GLint internalFormat
,
2304 GLint rb_base_format
;
2305 struct gl_renderbuffer
*rb
;
2306 GLenum rb_internal_format
;
2309 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2310 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2311 dimensions
, _mesa_enum_to_string(target
));
2316 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2317 _mesa_error(ctx
, GL_INVALID_VALUE
,
2318 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2322 /* Check that the source buffer is complete */
2323 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2324 if (ctx
->ReadBuffer
->_Status
== 0) {
2325 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2327 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2328 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2329 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2333 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2334 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2335 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2341 if (border
< 0 || border
> 1 ||
2342 ((ctx
->API
!= API_OPENGL_COMPAT
||
2343 target
== GL_TEXTURE_RECTANGLE_NV
||
2344 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2345 _mesa_error(ctx
, GL_INVALID_VALUE
,
2346 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2350 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2353 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2354 switch (internalFormat
) {
2359 case GL_LUMINANCE_ALPHA
:
2362 _mesa_error(ctx
, GL_INVALID_ENUM
,
2363 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2364 _mesa_enum_to_string(internalFormat
));
2369 * Section 8.6 (Alternate Texture Image Specification Commands) of the
2370 * OpenGL 4.5 (Compatibility Profile) spec says:
2372 * "Parameters level, internalformat, and border are specified using
2373 * the same values, with the same meanings, as the corresponding
2374 * arguments of TexImage2D, except that internalformat may not be
2375 * specified as 1, 2, 3, or 4."
2377 if (internalFormat
>= 1 && internalFormat
<= 4) {
2378 _mesa_error(ctx
, GL_INVALID_ENUM
,
2379 "glCopyTexImage%dD(internalFormat=%d)", dimensions
,
2385 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2386 if (baseFormat
< 0) {
2387 _mesa_error(ctx
, GL_INVALID_ENUM
,
2388 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2389 _mesa_enum_to_string(internalFormat
));
2393 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2395 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2396 "glCopyTexImage%dD(read buffer)", dimensions
);
2400 rb_internal_format
= rb
->InternalFormat
;
2401 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2402 if (_mesa_is_color_format(internalFormat
)) {
2403 if (rb_base_format
< 0) {
2404 _mesa_error(ctx
, GL_INVALID_VALUE
,
2405 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2406 _mesa_enum_to_string(internalFormat
));
2411 if (_mesa_is_gles(ctx
)) {
2413 if (_mesa_components_in_format(baseFormat
) >
2414 _mesa_components_in_format(rb_base_format
)) {
2417 if (baseFormat
== GL_DEPTH_COMPONENT
||
2418 baseFormat
== GL_DEPTH_STENCIL
||
2419 baseFormat
== GL_STENCIL_INDEX
||
2420 rb_base_format
== GL_DEPTH_COMPONENT
||
2421 rb_base_format
== GL_DEPTH_STENCIL
||
2422 rb_base_format
== GL_STENCIL_INDEX
||
2423 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2424 baseFormat
== GL_ALPHA
) &&
2425 rb_base_format
!= GL_RGBA
) ||
2426 internalFormat
== GL_RGB9_E5
) {
2429 if (internalFormat
== GL_RGB9_E5
) {
2433 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2434 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2435 _mesa_enum_to_string(internalFormat
));
2440 if (_mesa_is_gles3(ctx
)) {
2441 bool rb_is_srgb
= false;
2442 bool dst_is_srgb
= false;
2444 if (ctx
->Extensions
.EXT_sRGB
&&
2445 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2449 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2453 if (rb_is_srgb
!= dst_is_srgb
) {
2454 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2455 * OpenGLES 3.0.0 spec says:
2457 * "The error INVALID_OPERATION is also generated if the
2458 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2459 * framebuffer attachment corresponding to the read buffer
2460 * is LINEAR (see section 6.1.13) and internalformat is
2461 * one of the sRGB formats described in section 3.8.16, or
2462 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2463 * SRGB and internalformat is not one of the sRGB formats."
2465 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2466 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2470 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2471 * types for SNORM formats. Also, conversion to SNORM formats is not
2472 * allowed by Table 3.2 on Page 110.
2474 if (!_mesa_has_EXT_render_snorm(ctx
) &&
2475 _mesa_is_enum_format_snorm(internalFormat
)) {
2476 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2477 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2478 _mesa_enum_to_string(internalFormat
));
2483 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2484 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2485 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2489 /* From the EXT_texture_integer spec:
2491 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2492 * if the texture internalformat is an integer format and the read color
2493 * buffer is not an integer format, or if the internalformat is not an
2494 * integer format and the read color buffer is an integer format."
2496 if (_mesa_is_color_format(internalFormat
)) {
2497 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2498 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2499 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2500 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2501 if (is_int
|| is_rbint
) {
2502 if (is_int
!= is_rbint
) {
2503 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2504 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2506 } else if (_mesa_is_gles(ctx
) &&
2507 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2508 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2509 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2510 "glCopyTexImage%dD(signed vs unsigned integer)",
2516 /* From page 138 of OpenGL ES 3.0 spec:
2517 * "The error INVALID_OPERATION is generated if floating-point RGBA
2518 * data is required; if signed integer RGBA data is required and the
2519 * format of the current color buffer is not signed integer; if
2520 * unsigned integer RGBA data is required and the format of the
2521 * current color buffer is not unsigned integer; or if fixed-point
2522 * RGBA data is required and the format of the current color buffer
2523 * is not fixed-point.
2525 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2526 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2527 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2530 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2532 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2533 _mesa_error(ctx
, err
,
2534 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2537 if (_mesa_format_no_online_compression(internalFormat
)) {
2538 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2539 "glCopyTexImage%dD(no compression for format)", dimensions
);
2543 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2544 "glCopyTexImage%dD(border!=0)", dimensions
);
2549 if (!mutable_tex_object(ctx
, target
)) {
2550 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2551 "glCopyTexImage%dD(immutable texture)", dimensions
);
2555 /* if we get here, the parameters are OK */
2561 * Test glCopyTexSubImage[12]D() parameters for errors.
2562 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2565 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2566 const struct gl_texture_object
*texObj
,
2567 GLenum target
, GLint level
,
2568 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2569 GLint width
, GLint height
, const char *caller
)
2573 struct gl_texture_image
*texImage
;
2575 /* Check that the source buffer is complete */
2576 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2577 if (ctx
->ReadBuffer
->_Status
== 0) {
2578 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2580 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2581 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2582 "%s(invalid readbuffer)", caller
);
2586 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2587 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2588 "%s(multisample FBO)", caller
);
2594 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2595 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2599 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2601 /* destination image does not exist */
2602 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2603 "%s(invalid texture level %d)", caller
, level
);
2607 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2608 width
, height
, 1, caller
)) {
2612 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2613 xoffset
, yoffset
, zoffset
,
2614 width
, height
, 1, caller
)) {
2618 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2619 if (_mesa_format_no_online_compression(texImage
->InternalFormat
)) {
2620 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2621 "%s(no compression for format)", caller
);
2626 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2627 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2631 /* From OpenGL ES 3.2 spec, section 8.6:
2633 * "An INVALID_OPERATION error is generated by CopyTexSubImage3D,
2634 * CopyTexImage2D, or CopyTexSubImage2D if the internalformat of the
2635 * texture image being (re)specified is RGB9_E5"
2637 if (texImage
->InternalFormat
== GL_RGB9_E5
&&
2638 !_mesa_is_desktop_gl(ctx
)) {
2639 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2640 "%s(invalid internal format %s)", caller
,
2641 _mesa_enum_to_string(texImage
->InternalFormat
));
2645 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2646 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2647 "%s(missing readbuffer, format=%s)", caller
,
2648 _mesa_enum_to_string(texImage
->_BaseFormat
));
2652 /* From the EXT_texture_integer spec:
2654 * "INVALID_OPERATION is generated by CopyTexImage* and
2655 * CopyTexSubImage* if the texture internalformat is an integer format
2656 * and the read color buffer is not an integer format, or if the
2657 * internalformat is not an integer format and the read color buffer
2658 * is an integer format."
2660 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2661 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2663 if (_mesa_is_format_integer_color(rb
->Format
) !=
2664 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2665 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2666 "%s(integer vs non-integer)", caller
);
2671 /* In the ES 3.2 specification's Table 8.13 (Valid CopyTexImage source
2672 * framebuffer/destination texture base internal format combinations),
2673 * all the entries for stencil are left blank (unsupported).
2675 if (_mesa_is_gles(ctx
) && _mesa_is_stencil_format(texImage
->_BaseFormat
)) {
2676 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(stencil disallowed)", caller
);
2680 /* if we get here, the parameters are OK */
2685 /** Callback info for walking over FBO hash table */
2688 struct gl_context
*ctx
;
2689 struct gl_texture_object
*texObj
;
2695 * Check render to texture callback. Called from _mesa_HashWalk().
2698 check_rtt_cb(UNUSED GLuint key
, void *data
, void *userData
)
2700 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2701 const struct cb_info
*info
= (struct cb_info
*) userData
;
2702 struct gl_context
*ctx
= info
->ctx
;
2703 const struct gl_texture_object
*texObj
= info
->texObj
;
2704 const GLuint level
= info
->level
, face
= info
->face
;
2706 /* If this is a user-created FBO */
2707 if (_mesa_is_user_fbo(fb
)) {
2709 /* check if any of the FBO's attachments point to 'texObj' */
2710 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2711 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2712 if (att
->Type
== GL_TEXTURE
&&
2713 att
->Texture
== texObj
&&
2714 att
->TextureLevel
== level
&&
2715 att
->CubeMapFace
== face
) {
2716 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
2717 assert(att
->Renderbuffer
->TexImage
);
2718 /* Mark fb status as indeterminate to force re-validation */
2721 /* Make sure that the revalidation actually happens if this is
2722 * being done to currently-bound buffers.
2724 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
)
2725 ctx
->NewState
|= _NEW_BUFFERS
;
2733 * When a texture image is specified we have to check if it's bound to
2734 * any framebuffer objects (render to texture) in order to detect changes
2735 * in size or format since that effects FBO completeness.
2736 * Any FBOs rendering into the texture must be re-validated.
2739 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2740 struct gl_texture_object
*texObj
,
2741 GLuint face
, GLuint level
)
2743 /* Only check this texture if it's been marked as RenderToTexture */
2744 if (texObj
->_RenderToTexture
) {
2745 struct cb_info info
;
2747 info
.texObj
= texObj
;
2750 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2756 * If the texture object's GenerateMipmap flag is set and we've
2757 * changed the texture base level image, regenerate the rest of the
2758 * mipmap levels now.
2761 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2762 struct gl_texture_object
*texObj
, GLint level
)
2764 if (texObj
->GenerateMipmap
&&
2765 level
== texObj
->BaseLevel
&&
2766 level
< texObj
->MaxLevel
) {
2767 assert(ctx
->Driver
.GenerateMipmap
);
2768 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2773 /** Debug helper: override the user-requested internal format */
2775 override_internal_format(GLenum internalFormat
, UNUSED GLint width
,
2776 UNUSED GLint height
)
2779 if (internalFormat
== GL_RGBA16F_ARB
||
2780 internalFormat
== GL_RGBA32F_ARB
) {
2781 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2784 else if (internalFormat
== GL_RGB16F_ARB
||
2785 internalFormat
== GL_RGB32F_ARB
) {
2786 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2789 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2790 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2791 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2792 return GL_LUMINANCE_ALPHA
;
2794 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2795 internalFormat
== GL_LUMINANCE32F_ARB
) {
2796 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2797 return GL_LUMINANCE
;
2799 else if (internalFormat
== GL_ALPHA16F_ARB
||
2800 internalFormat
== GL_ALPHA32F_ARB
) {
2801 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2805 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2806 internalFormat = GL_RGBA;
2810 return internalFormat
;
2813 return internalFormat
;
2819 * Choose the actual hardware format for a texture image.
2820 * Try to use the same format as the previous image level when possible.
2821 * Otherwise, ask the driver for the best format.
2822 * It's important to try to choose a consistant format for all levels
2823 * for efficient texture memory layout/allocation. In particular, this
2824 * comes up during automatic mipmap generation.
2827 _mesa_choose_texture_format(struct gl_context
*ctx
,
2828 struct gl_texture_object
*texObj
,
2829 GLenum target
, GLint level
,
2830 GLenum internalFormat
, GLenum format
, GLenum type
)
2834 /* see if we've already chosen a format for the previous level */
2836 struct gl_texture_image
*prevImage
=
2837 _mesa_select_tex_image(texObj
, target
, level
- 1);
2838 /* See if the prev level is defined and has an internal format which
2839 * matches the new internal format.
2842 prevImage
->Width
> 0 &&
2843 prevImage
->InternalFormat
== internalFormat
) {
2844 /* use the same format */
2845 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2846 return prevImage
->TexFormat
;
2850 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
2852 assert(f
!= MESA_FORMAT_NONE
);
2858 * Adjust pixel unpack params and image dimensions to strip off the
2859 * one-pixel texture border.
2861 * Gallium and intel don't support texture borders. They've seldem been used
2862 * and seldom been implemented correctly anyway.
2864 * \param unpackNew returns the new pixel unpack parameters
2867 strip_texture_border(GLenum target
,
2868 GLint
*width
, GLint
*height
, GLint
*depth
,
2869 const struct gl_pixelstore_attrib
*unpack
,
2870 struct gl_pixelstore_attrib
*unpackNew
)
2876 *unpackNew
= *unpack
;
2878 if (unpackNew
->RowLength
== 0)
2879 unpackNew
->RowLength
= *width
;
2881 if (unpackNew
->ImageHeight
== 0)
2882 unpackNew
->ImageHeight
= *height
;
2884 assert(*width
>= 3);
2885 unpackNew
->SkipPixels
++; /* skip the border */
2886 *width
= *width
- 2; /* reduce the width by two border pixels */
2888 /* The min height of a texture with a border is 3 */
2889 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2890 unpackNew
->SkipRows
++; /* skip the border */
2891 *height
= *height
- 2; /* reduce the height by two border pixels */
2895 target
!= GL_TEXTURE_2D_ARRAY
&&
2896 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2897 unpackNew
->SkipImages
++; /* skip the border */
2898 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2904 * Common code to implement all the glTexImage1D/2D/3D functions
2905 * as well as glCompressedTexImage1D/2D/3D.
2906 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2907 * \param format the user's image format (only used if !compressed)
2908 * \param type the user's image type (only used if !compressed)
2909 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2911 static ALWAYS_INLINE
void
2912 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2913 GLenum target
, GLint level
, GLint internalFormat
,
2914 GLsizei width
, GLsizei height
, GLsizei depth
,
2915 GLint border
, GLenum format
, GLenum type
,
2916 GLsizei imageSize
, const GLvoid
*pixels
, bool no_error
)
2918 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2919 struct gl_pixelstore_attrib unpack_no_border
;
2920 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2921 struct gl_texture_object
*texObj
;
2922 mesa_format texFormat
;
2923 bool dimensionsOK
= true, sizeOK
= true;
2925 FLUSH_VERTICES(ctx
, 0);
2927 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2930 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2932 _mesa_enum_to_string(target
), level
,
2933 _mesa_enum_to_string(internalFormat
),
2934 width
, height
, depth
, border
, pixels
);
2937 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2939 _mesa_enum_to_string(target
), level
,
2940 _mesa_enum_to_string(internalFormat
),
2941 width
, height
, depth
, border
,
2942 _mesa_enum_to_string(format
),
2943 _mesa_enum_to_string(type
), pixels
);
2946 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2949 /* target error checking */
2950 if (!legal_teximage_target(ctx
, dims
, target
)) {
2951 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2952 func
, dims
, _mesa_enum_to_string(target
));
2956 /* general error checking */
2958 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2960 width
, height
, depth
,
2961 border
, imageSize
, pixels
))
2964 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2965 format
, type
, width
, height
, depth
, border
,
2971 /* Here we convert a cpal compressed image into a regular glTexImage2D
2972 * call by decompressing the texture. If we really want to support cpal
2973 * textures in any driver this would have to be changed.
2975 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
2976 switch (internalFormat
) {
2977 case GL_PALETTE4_RGB8_OES
:
2978 case GL_PALETTE4_RGBA8_OES
:
2979 case GL_PALETTE4_R5_G6_B5_OES
:
2980 case GL_PALETTE4_RGBA4_OES
:
2981 case GL_PALETTE4_RGB5_A1_OES
:
2982 case GL_PALETTE8_RGB8_OES
:
2983 case GL_PALETTE8_RGBA8_OES
:
2984 case GL_PALETTE8_R5_G6_B5_OES
:
2985 case GL_PALETTE8_RGBA4_OES
:
2986 case GL_PALETTE8_RGB5_A1_OES
:
2987 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
2988 width
, height
, imageSize
, pixels
);
2993 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2997 /* For glCompressedTexImage() the driver has no choice about the
2998 * texture format since we'll never transcode the user's compressed
2999 * image data. The internalFormat was error checked earlier.
3001 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3004 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3005 * internal floating point format for the given base format.
3007 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3008 if (type
== GL_FLOAT
) {
3009 texObj
->_IsFloat
= GL_TRUE
;
3010 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3011 texObj
->_IsHalfFloat
= GL_TRUE
;
3014 internalFormat
= adjust_for_oes_float_texture(ctx
, format
, type
);
3017 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3018 internalFormat
, format
, type
);
3021 assert(texFormat
!= MESA_FORMAT_NONE
);
3024 /* check that width, height, depth are legal for the mipmap level */
3025 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3026 height
, depth
, border
);
3028 /* check that the texture won't take too much memory, etc */
3029 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3030 0, level
, texFormat
, 1,
3031 width
, height
, depth
);
3034 if (_mesa_is_proxy_texture(target
)) {
3035 /* Proxy texture: just clear or set state depending on error checking */
3036 struct gl_texture_image
*texImage
=
3037 get_proxy_tex_image(ctx
, target
, level
);
3040 return; /* GL_OUT_OF_MEMORY already recorded */
3042 if (dimensionsOK
&& sizeOK
) {
3043 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3044 border
, internalFormat
, texFormat
);
3047 clear_teximage_fields(texImage
);
3051 /* non-proxy target */
3052 const GLuint face
= _mesa_tex_target_to_face(target
);
3053 struct gl_texture_image
*texImage
;
3055 if (!dimensionsOK
) {
3056 _mesa_error(ctx
, GL_INVALID_VALUE
,
3057 "%s%uD(invalid width=%d or height=%d or depth=%d)",
3058 func
, dims
, width
, height
, depth
);
3063 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3064 "%s%uD(image too large: %d x %d x %d, %s format)",
3065 func
, dims
, width
, height
, depth
,
3066 _mesa_enum_to_string(internalFormat
));
3070 /* Allow a hardware driver to just strip out the border, to provide
3071 * reliable but slightly incorrect hardware rendering instead of
3072 * rarely-tested software fallback rendering.
3074 if (border
&& ctx
->Const
.StripTextureBorder
) {
3075 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3078 unpack
= &unpack_no_border
;
3081 if (ctx
->NewState
& _NEW_PIXEL
)
3082 _mesa_update_state(ctx
);
3084 _mesa_lock_texture(ctx
, texObj
);
3086 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3089 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3092 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3094 _mesa_init_teximage_fields(ctx
, texImage
,
3095 width
, height
, depth
,
3096 border
, internalFormat
, texFormat
);
3098 /* Give the texture to the driver. <pixels> may be null. */
3099 if (width
> 0 && height
> 0 && depth
> 0) {
3101 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3105 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3106 type
, pixels
, unpack
);
3110 check_gen_mipmap(ctx
, target
, texObj
, level
);
3112 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3114 _mesa_dirty_texobj(ctx
, texObj
);
3117 _mesa_unlock_texture(ctx
, texObj
);
3122 /* This is a wrapper around teximage() so that we can force the KHR_no_error
3123 * logic to be inlined without inlining the function into all the callers.
3126 teximage_err(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3127 GLenum target
, GLint level
, GLint internalFormat
,
3128 GLsizei width
, GLsizei height
, GLsizei depth
,
3129 GLint border
, GLenum format
, GLenum type
,
3130 GLsizei imageSize
, const GLvoid
*pixels
)
3132 teximage(ctx
, compressed
, dims
, target
, level
, internalFormat
, width
, height
,
3133 depth
, border
, format
, type
, imageSize
, pixels
, false);
3138 teximage_no_error(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3139 GLenum target
, GLint level
, GLint internalFormat
,
3140 GLsizei width
, GLsizei height
, GLsizei depth
,
3141 GLint border
, GLenum format
, GLenum type
,
3142 GLsizei imageSize
, const GLvoid
*pixels
)
3144 teximage(ctx
, compressed
, dims
, target
, level
, internalFormat
, width
, height
,
3145 depth
, border
, format
, type
, imageSize
, pixels
, true);
3150 * Called from the API. Note that width includes the border.
3153 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3154 GLsizei width
, GLint border
, GLenum format
,
3155 GLenum type
, const GLvoid
*pixels
)
3157 GET_CURRENT_CONTEXT(ctx
);
3158 teximage_err(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3159 border
, format
, type
, 0, pixels
);
3164 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3165 GLsizei width
, GLsizei height
, GLint border
,
3166 GLenum format
, GLenum type
,
3167 const GLvoid
*pixels
)
3169 GET_CURRENT_CONTEXT(ctx
);
3170 teximage_err(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3171 border
, format
, type
, 0, pixels
);
3176 * Called by the API or display list executor.
3177 * Note that width and height include the border.
3180 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3181 GLsizei width
, GLsizei height
, GLsizei depth
,
3182 GLint border
, GLenum format
, GLenum type
,
3183 const GLvoid
*pixels
)
3185 GET_CURRENT_CONTEXT(ctx
);
3186 teximage_err(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3187 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3192 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3193 GLsizei width
, GLsizei height
, GLsizei depth
,
3194 GLint border
, GLenum format
, GLenum type
,
3195 const GLvoid
*pixels
)
3197 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3198 depth
, border
, format
, type
, pixels
);
3203 _mesa_TexImage1D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3204 GLsizei width
, GLint border
, GLenum format
,
3205 GLenum type
, const GLvoid
*pixels
)
3207 GET_CURRENT_CONTEXT(ctx
);
3208 teximage_no_error(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1,
3209 1, border
, format
, type
, 0, pixels
);
3214 _mesa_TexImage2D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3215 GLsizei width
, GLsizei height
, GLint border
,
3216 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3218 GET_CURRENT_CONTEXT(ctx
);
3219 teximage_no_error(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
,
3220 height
, 1, border
, format
, type
, 0, pixels
);
3225 _mesa_TexImage3D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3226 GLsizei width
, GLsizei height
, GLsizei depth
,
3227 GLint border
, GLenum format
, GLenum type
,
3228 const GLvoid
*pixels
)
3230 GET_CURRENT_CONTEXT(ctx
);
3231 teximage_no_error(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3232 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3237 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3239 struct gl_texture_object
*texObj
;
3240 struct gl_texture_image
*texImage
;
3242 GET_CURRENT_CONTEXT(ctx
);
3243 FLUSH_VERTICES(ctx
, 0);
3247 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3249 case GL_TEXTURE_EXTERNAL_OES
:
3251 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3254 valid_target
= false;
3258 if (!valid_target
) {
3259 _mesa_error(ctx
, GL_INVALID_ENUM
,
3260 "glEGLImageTargetTexture2D(target=%d)", target
);
3265 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3266 "glEGLImageTargetTexture2D(image=%p)", image
);
3270 if (ctx
->NewState
& _NEW_PIXEL
)
3271 _mesa_update_state(ctx
);
3273 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3277 _mesa_lock_texture(ctx
, texObj
);
3279 if (texObj
->Immutable
) {
3280 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3281 "glEGLImageTargetTexture2D(texture is immutable)");
3282 _mesa_unlock_texture(ctx
, texObj
);
3286 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3288 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3290 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3292 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3293 texObj
, texImage
, image
);
3295 _mesa_dirty_texobj(ctx
, texObj
);
3297 _mesa_unlock_texture(ctx
, texObj
);
3302 * Helper that implements the glTexSubImage1/2/3D()
3303 * and glTextureSubImage1/2/3D() functions.
3306 texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3307 struct gl_texture_object
*texObj
,
3308 struct gl_texture_image
*texImage
,
3309 GLenum target
, GLint level
,
3310 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3311 GLsizei width
, GLsizei height
, GLsizei depth
,
3312 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3314 FLUSH_VERTICES(ctx
, 0);
3316 if (ctx
->NewState
& _NEW_PIXEL
)
3317 _mesa_update_state(ctx
);
3319 _mesa_lock_texture(ctx
, texObj
);
3321 if (width
> 0 && height
> 0 && depth
> 0) {
3322 /* If we have a border, offset=-1 is legal. Bias by border width. */
3325 if (target
!= GL_TEXTURE_2D_ARRAY
)
3326 zoffset
+= texImage
->Border
;
3329 if (target
!= GL_TEXTURE_1D_ARRAY
)
3330 yoffset
+= texImage
->Border
;
3333 xoffset
+= texImage
->Border
;
3336 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3337 xoffset
, yoffset
, zoffset
,
3338 width
, height
, depth
,
3339 format
, type
, pixels
, &ctx
->Unpack
);
3341 check_gen_mipmap(ctx
, target
, texObj
, level
);
3343 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3344 * the texel data, not the texture format, size, etc.
3348 _mesa_unlock_texture(ctx
, texObj
);
3352 * Implement all the glTexSubImage1/2/3D() functions.
3353 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3356 texsubimage_err(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3357 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3358 GLsizei width
, GLsizei height
, GLsizei depth
,
3359 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3360 const char *callerName
)
3362 struct gl_texture_object
*texObj
;
3363 struct gl_texture_image
*texImage
;
3365 /* check target (proxies not allowed) */
3366 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3367 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3368 dims
, _mesa_enum_to_string(target
));
3372 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3376 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3377 xoffset
, yoffset
, zoffset
,
3378 width
, height
, depth
, format
, type
,
3379 pixels
, callerName
)) {
3380 return; /* error was detected */
3383 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3384 /* texsubimage_error_check ensures that texImage is not NULL */
3386 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3387 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3389 _mesa_enum_to_string(target
), level
,
3390 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3391 _mesa_enum_to_string(format
),
3392 _mesa_enum_to_string(type
), pixels
);
3394 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3395 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3396 format
, type
, pixels
);
3401 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3402 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3403 GLsizei width
, GLsizei height
, GLsizei depth
,
3404 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3406 struct gl_texture_object
*texObj
;
3407 struct gl_texture_image
*texImage
;
3409 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3410 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3412 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3413 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3414 format
, type
, pixels
);
3419 * Implement all the glTextureSubImage1/2/3D() functions.
3420 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3422 static ALWAYS_INLINE
void
3423 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3424 GLuint texture
, GLint level
,
3425 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3426 GLsizei width
, GLsizei height
, GLsizei depth
,
3427 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3428 const char *callerName
, bool no_error
)
3430 struct gl_texture_object
*texObj
;
3431 struct gl_texture_image
*texImage
;
3434 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3436 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3437 dims
, texture
, level
,
3438 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3439 _mesa_enum_to_string(format
),
3440 _mesa_enum_to_string(type
), pixels
);
3442 /* Get the texture object by Name. */
3444 texObj
= _mesa_lookup_texture_err(ctx
, texture
, callerName
);
3448 texObj
= _mesa_lookup_texture(ctx
, texture
);
3452 /* check target (proxies not allowed) */
3453 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3454 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3455 callerName
, _mesa_enum_to_string(texObj
->Target
));
3459 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3460 xoffset
, yoffset
, zoffset
,
3461 width
, height
, depth
, format
, type
,
3462 pixels
, callerName
)) {
3463 return; /* error was detected */
3467 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3468 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3472 * What do we do if the user created a texture with the following code
3473 * and then called this function with its handle?
3476 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3477 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3478 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3479 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3480 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3481 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3482 * // wrong format, or given the wrong size, etc.
3483 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3484 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3486 * A bug has been filed against the spec for this case. In the
3487 * meantime, we will check for cube completeness.
3489 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3490 * Core Profile spec (30.10.2014):
3491 * "[A] cube map texture is cube complete if the
3492 * following conditions all hold true: The [base level] texture
3493 * images of each of the six cube map faces have identical, positive,
3494 * and square dimensions. The [base level] images were each specified
3495 * with the same internal format."
3497 * It seems reasonable to check for cube completeness of an arbitrary
3498 * level here so that the image data has a consistent format and size.
3500 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
3501 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3502 "glTextureSubImage%uD(cube map incomplete)",
3507 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3509 /* Copy in each face. */
3510 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3511 texImage
= texObj
->Image
[i
][level
];
3514 texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3515 level
, xoffset
, yoffset
, 0,
3516 width
, height
, 1, format
,
3518 pixels
= (GLubyte
*) pixels
+ imageStride
;
3522 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3525 texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3526 level
, xoffset
, yoffset
, zoffset
,
3527 width
, height
, depth
, format
,
3534 texturesubimage_error(struct gl_context
*ctx
, GLuint dims
,
3535 GLuint texture
, GLint level
,
3536 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3537 GLsizei width
, GLsizei height
, GLsizei depth
,
3538 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3539 const char *callerName
)
3541 texturesubimage(ctx
, dims
, texture
, level
, xoffset
, yoffset
, zoffset
,
3542 width
, height
, depth
, format
, type
, pixels
, callerName
,
3548 texturesubimage_no_error(struct gl_context
*ctx
, GLuint dims
,
3549 GLuint texture
, GLint level
,
3550 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3551 GLsizei width
, GLsizei height
, GLsizei depth
,
3552 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3553 const char *callerName
)
3555 texturesubimage(ctx
, dims
, texture
, level
, xoffset
, yoffset
, zoffset
,
3556 width
, height
, depth
, format
, type
, pixels
, callerName
,
3562 _mesa_TexSubImage1D_no_error(GLenum target
, GLint level
,
3563 GLint xoffset
, GLsizei width
,
3564 GLenum format
, GLenum type
,
3565 const GLvoid
*pixels
)
3567 GET_CURRENT_CONTEXT(ctx
);
3568 texsubimage(ctx
, 1, target
, level
,
3571 format
, type
, pixels
);
3576 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3577 GLint xoffset
, GLsizei width
,
3578 GLenum format
, GLenum type
,
3579 const GLvoid
*pixels
)
3581 GET_CURRENT_CONTEXT(ctx
);
3582 texsubimage_err(ctx
, 1, target
, level
,
3585 format
, type
, pixels
, "glTexSubImage1D");
3590 _mesa_TexSubImage2D_no_error(GLenum target
, GLint level
,
3591 GLint xoffset
, GLint yoffset
,
3592 GLsizei width
, GLsizei height
,
3593 GLenum format
, GLenum type
,
3594 const GLvoid
*pixels
)
3596 GET_CURRENT_CONTEXT(ctx
);
3597 texsubimage(ctx
, 2, target
, level
,
3598 xoffset
, yoffset
, 0,
3600 format
, type
, pixels
);
3605 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3606 GLint xoffset
, GLint yoffset
,
3607 GLsizei width
, GLsizei height
,
3608 GLenum format
, GLenum type
,
3609 const GLvoid
*pixels
)
3611 GET_CURRENT_CONTEXT(ctx
);
3612 texsubimage_err(ctx
, 2, target
, level
,
3613 xoffset
, yoffset
, 0,
3615 format
, type
, pixels
, "glTexSubImage2D");
3620 _mesa_TexSubImage3D_no_error(GLenum target
, GLint level
,
3621 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3622 GLsizei width
, GLsizei height
, GLsizei depth
,
3623 GLenum format
, GLenum type
,
3624 const GLvoid
*pixels
)
3626 GET_CURRENT_CONTEXT(ctx
);
3627 texsubimage(ctx
, 3, target
, level
,
3628 xoffset
, yoffset
, zoffset
,
3629 width
, height
, depth
,
3630 format
, type
, pixels
);
3635 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3636 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3637 GLsizei width
, GLsizei height
, GLsizei depth
,
3638 GLenum format
, GLenum type
,
3639 const GLvoid
*pixels
)
3641 GET_CURRENT_CONTEXT(ctx
);
3642 texsubimage_err(ctx
, 3, target
, level
,
3643 xoffset
, yoffset
, zoffset
,
3644 width
, height
, depth
,
3645 format
, type
, pixels
, "glTexSubImage3D");
3650 _mesa_TextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3651 GLsizei width
, GLenum format
, GLenum type
,
3652 const GLvoid
*pixels
)
3654 GET_CURRENT_CONTEXT(ctx
);
3655 texturesubimage_no_error(ctx
, 1, texture
, level
, xoffset
, 0, 0, width
, 1, 1,
3656 format
, type
, pixels
, "glTextureSubImage1D");
3661 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3662 GLint xoffset
, GLsizei width
,
3663 GLenum format
, GLenum type
,
3664 const GLvoid
*pixels
)
3666 GET_CURRENT_CONTEXT(ctx
);
3667 texturesubimage_error(ctx
, 1, texture
, level
, xoffset
, 0, 0, width
, 1, 1,
3668 format
, type
, pixels
, "glTextureSubImage1D");
3673 _mesa_TextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3674 GLint yoffset
, GLsizei width
, GLsizei height
,
3675 GLenum format
, GLenum type
,
3676 const GLvoid
*pixels
)
3678 GET_CURRENT_CONTEXT(ctx
);
3679 texturesubimage_no_error(ctx
, 2, texture
, level
, xoffset
, yoffset
, 0, width
,
3680 height
, 1, format
, type
, pixels
,
3681 "glTextureSubImage2D");
3686 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3687 GLint xoffset
, GLint yoffset
,
3688 GLsizei width
, GLsizei height
,
3689 GLenum format
, GLenum type
,
3690 const GLvoid
*pixels
)
3692 GET_CURRENT_CONTEXT(ctx
);
3693 texturesubimage_error(ctx
, 2, texture
, level
, xoffset
, yoffset
, 0, width
,
3694 height
, 1, format
, type
, pixels
,
3695 "glTextureSubImage2D");
3700 _mesa_TextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3701 GLint yoffset
, GLint zoffset
, GLsizei width
,
3702 GLsizei height
, GLsizei depth
, GLenum format
,
3703 GLenum type
, const GLvoid
*pixels
)
3705 GET_CURRENT_CONTEXT(ctx
);
3706 texturesubimage_no_error(ctx
, 3, texture
, level
, xoffset
, yoffset
, zoffset
,
3707 width
, height
, depth
, format
, type
, pixels
,
3708 "glTextureSubImage3D");
3713 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3714 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3715 GLsizei width
, GLsizei height
, GLsizei depth
,
3716 GLenum format
, GLenum type
,
3717 const GLvoid
*pixels
)
3719 GET_CURRENT_CONTEXT(ctx
);
3720 texturesubimage_error(ctx
, 3, texture
, level
, xoffset
, yoffset
, zoffset
,
3721 width
, height
, depth
, format
, type
, pixels
,
3722 "glTextureSubImage3D");
3727 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3728 * from. This depends on whether the texture contains color or depth values.
3730 static struct gl_renderbuffer
*
3731 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3733 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3734 /* reading from depth/stencil buffer */
3735 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3736 } else if (_mesa_get_format_bits(texFormat
, GL_STENCIL_BITS
) > 0) {
3737 return ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3739 /* copying from color buffer */
3740 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3746 copytexsubimage_by_slice(struct gl_context
*ctx
,
3747 struct gl_texture_image
*texImage
,
3749 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3750 struct gl_renderbuffer
*rb
,
3752 GLsizei width
, GLsizei height
)
3754 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3757 /* For 1D arrays, we copy each scanline of the source rectangle into the
3760 assert(zoffset
== 0);
3762 for (slice
= 0; slice
< height
; slice
++) {
3763 assert(yoffset
+ slice
< texImage
->Height
);
3764 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3765 xoffset
, 0, yoffset
+ slice
,
3766 rb
, x
, y
+ slice
, width
, 1);
3769 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3770 xoffset
, yoffset
, zoffset
,
3771 rb
, x
, y
, width
, height
);
3777 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3779 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3780 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3781 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3782 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3784 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3785 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3786 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3787 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3789 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3790 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3791 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3792 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3800 * Check if the given texture format and size arguments match those
3801 * of the texture image.
3802 * \param return true if arguments match, false otherwise.
3805 can_avoid_reallocation(const struct gl_texture_image
*texImage
,
3806 GLenum internalFormat
,
3807 mesa_format texFormat
, GLsizei width
,
3808 GLsizei height
, GLint border
)
3810 if (texImage
->InternalFormat
!= internalFormat
)
3812 if (texImage
->TexFormat
!= texFormat
)
3814 if (texImage
->Border
!= border
)
3816 if (texImage
->Width2
!= width
)
3818 if (texImage
->Height2
!= height
)
3825 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
3828 copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3829 struct gl_texture_object
*texObj
,
3830 GLenum target
, GLint level
,
3831 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3832 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3834 struct gl_texture_image
*texImage
;
3836 _mesa_lock_texture(ctx
, texObj
);
3838 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3840 /* If we have a border, offset=-1 is legal. Bias by border width. */
3843 if (target
!= GL_TEXTURE_2D_ARRAY
)
3844 zoffset
+= texImage
->Border
;
3847 if (target
!= GL_TEXTURE_1D_ARRAY
)
3848 yoffset
+= texImage
->Border
;
3851 xoffset
+= texImage
->Border
;
3854 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3856 struct gl_renderbuffer
*srcRb
=
3857 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3859 copytexsubimage_by_slice(ctx
, texImage
, dims
, xoffset
, yoffset
, zoffset
,
3860 srcRb
, x
, y
, width
, height
);
3862 check_gen_mipmap(ctx
, target
, texObj
, level
);
3864 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3865 * the texel data, not the texture format, size, etc.
3869 _mesa_unlock_texture(ctx
, texObj
);
3874 copy_texture_sub_image_err(struct gl_context
*ctx
, GLuint dims
,
3875 struct gl_texture_object
*texObj
,
3876 GLenum target
, GLint level
,
3877 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3878 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3881 FLUSH_VERTICES(ctx
, 0);
3883 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3884 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
3885 _mesa_enum_to_string(target
),
3886 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3888 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3889 _mesa_update_state(ctx
);
3891 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3892 xoffset
, yoffset
, zoffset
,
3893 width
, height
, caller
)) {
3897 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
3898 zoffset
, x
, y
, width
, height
);
3903 copy_texture_sub_image_no_error(struct gl_context
*ctx
, GLuint dims
,
3904 struct gl_texture_object
*texObj
,
3905 GLenum target
, GLint level
,
3906 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3907 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3909 FLUSH_VERTICES(ctx
, 0);
3911 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3912 _mesa_update_state(ctx
);
3914 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
3915 zoffset
, x
, y
, width
, height
);
3920 * Implement the glCopyTexImage1/2D() functions.
3922 static ALWAYS_INLINE
void
3923 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3924 GLenum target
, GLint level
, GLenum internalFormat
,
3925 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
,
3928 struct gl_texture_image
*texImage
;
3929 struct gl_texture_object
*texObj
;
3930 mesa_format texFormat
;
3932 FLUSH_VERTICES(ctx
, 0);
3934 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3935 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3937 _mesa_enum_to_string(target
), level
,
3938 _mesa_enum_to_string(internalFormat
),
3939 x
, y
, width
, height
, border
);
3941 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3942 _mesa_update_state(ctx
);
3945 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3949 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3951 _mesa_error(ctx
, GL_INVALID_VALUE
,
3952 "glCopyTexImage%uD(invalid width=%d or height=%d)",
3953 dims
, width
, height
);
3958 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3961 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3962 internalFormat
, GL_NONE
, GL_NONE
);
3964 /* First check if reallocating the texture buffer can be avoided.
3965 * Without the realloc the copy can be 20x faster.
3967 _mesa_lock_texture(ctx
, texObj
);
3969 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3970 if (texImage
&& can_avoid_reallocation(texImage
, internalFormat
, texFormat
,
3971 width
, height
, border
)) {
3972 _mesa_unlock_texture(ctx
, texObj
);
3974 copy_texture_sub_image_no_error(ctx
, dims
, texObj
, target
, level
, 0,
3975 0, 0, x
, y
, width
, height
);
3977 copy_texture_sub_image_err(ctx
, dims
, texObj
, target
, level
, 0, 0,
3978 0, x
, y
, width
, height
,"CopyTexImage");
3983 _mesa_unlock_texture(ctx
, texObj
);
3984 _mesa_perf_debug(ctx
, MESA_DEBUG_SEVERITY_LOW
, "glCopyTexImage "
3985 "can't avoid reallocating texture storage\n");
3987 if (!no_error
&& _mesa_is_gles3(ctx
)) {
3988 struct gl_renderbuffer
*rb
=
3989 _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3991 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3992 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3993 * OpenGL ES 3.0. Khronos bug# 9807.
3995 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3996 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3997 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
3998 " and writing to unsized internal format)", dims
);
4002 /* From Page 139 of OpenGL ES 3.0 spec:
4003 * "If internalformat is sized, the internal format of the new texel
4004 * array is internalformat, and this is also the new texel array’s
4005 * effective internal format. If the component sizes of internalformat
4006 * do not exactly match the corresponding component sizes of the source
4007 * buffer’s effective internal format, described below, an
4008 * INVALID_OPERATION error is generated. If internalformat is unsized,
4009 * the internal format of the new texel array is the effective internal
4010 * format of the source buffer, and this is also the new texel array’s
4011 * effective internal format.
4013 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
4014 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4015 "glCopyTexImage%uD(component size changed in"
4016 " internal format)", dims
);
4021 assert(texFormat
!= MESA_FORMAT_NONE
);
4023 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
4024 0, level
, texFormat
, 1,
4025 width
, height
, 1)) {
4026 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4027 "glCopyTexImage%uD(image too large)", dims
);
4031 if (border
&& ctx
->Const
.StripTextureBorder
) {
4033 width
-= border
* 2;
4036 height
-= border
* 2;
4041 _mesa_lock_texture(ctx
, texObj
);
4043 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
4046 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
4049 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
4050 const GLuint face
= _mesa_tex_target_to_face(target
);
4052 /* Free old texture image */
4053 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4055 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
4056 border
, internalFormat
, texFormat
);
4058 if (width
&& height
) {
4059 /* Allocate texture memory (no pixel data yet) */
4060 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
4062 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
4064 struct gl_renderbuffer
*srcRb
=
4065 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4067 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4069 srcRb
, srcX
, srcY
, width
, height
);
4072 check_gen_mipmap(ctx
, target
, texObj
, level
);
4075 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4077 _mesa_dirty_texobj(ctx
, texObj
);
4080 _mesa_unlock_texture(ctx
, texObj
);
4085 copyteximage_err(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
4086 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4087 GLsizei width
, GLsizei height
, GLint border
)
4089 copyteximage(ctx
, dims
, target
, level
, internalFormat
, x
, y
, width
, height
,
4095 copyteximage_no_error(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
4096 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4097 GLsizei width
, GLsizei height
, GLint border
)
4099 copyteximage(ctx
, dims
, target
, level
, internalFormat
, x
, y
, width
, height
,
4105 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4106 GLenum internalFormat
,
4108 GLsizei width
, GLint border
)
4110 GET_CURRENT_CONTEXT(ctx
);
4111 copyteximage_err(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4117 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4118 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4121 GET_CURRENT_CONTEXT(ctx
);
4122 copyteximage_err(ctx
, 2, target
, level
, internalFormat
,
4123 x
, y
, width
, height
, border
);
4128 _mesa_CopyTexImage1D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4129 GLint x
, GLint y
, GLsizei width
, GLint border
)
4131 GET_CURRENT_CONTEXT(ctx
);
4132 copyteximage_no_error(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4138 _mesa_CopyTexImage2D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4139 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4142 GET_CURRENT_CONTEXT(ctx
);
4143 copyteximage_no_error(ctx
, 2, target
, level
, internalFormat
,
4144 x
, y
, width
, height
, border
);
4149 _mesa_CopyTexSubImage1D(GLenum target
, GLint level
,
4150 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4152 struct gl_texture_object
* texObj
;
4153 const char *self
= "glCopyTexSubImage1D";
4154 GET_CURRENT_CONTEXT(ctx
);
4156 /* Check target (proxies not allowed). Target must be checked prior to
4157 * calling _mesa_get_current_tex_object.
4159 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4160 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4161 _mesa_enum_to_string(target
));
4165 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4169 copy_texture_sub_image_err(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4170 x
, y
, width
, 1, self
);
4175 _mesa_CopyTexSubImage2D(GLenum target
, GLint level
,
4176 GLint xoffset
, GLint yoffset
,
4177 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4179 struct gl_texture_object
* texObj
;
4180 const char *self
= "glCopyTexSubImage2D";
4181 GET_CURRENT_CONTEXT(ctx
);
4183 /* Check target (proxies not allowed). Target must be checked prior to
4184 * calling _mesa_get_current_tex_object.
4186 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4187 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4188 _mesa_enum_to_string(target
));
4192 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4196 copy_texture_sub_image_err(ctx
, 2, texObj
, target
, level
, xoffset
, yoffset
,
4197 0, x
, y
, width
, height
, self
);
4202 _mesa_CopyTexSubImage3D(GLenum target
, GLint level
,
4203 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4204 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4206 struct gl_texture_object
* texObj
;
4207 const char *self
= "glCopyTexSubImage3D";
4208 GET_CURRENT_CONTEXT(ctx
);
4210 /* Check target (proxies not allowed). Target must be checked prior to
4211 * calling _mesa_get_current_tex_object.
4213 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4214 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4215 _mesa_enum_to_string(target
));
4219 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4223 copy_texture_sub_image_err(ctx
, 3, texObj
, target
, level
, xoffset
, yoffset
,
4224 zoffset
, x
, y
, width
, height
, self
);
4229 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4230 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4232 struct gl_texture_object
* texObj
;
4233 const char *self
= "glCopyTextureSubImage1D";
4234 GET_CURRENT_CONTEXT(ctx
);
4236 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4240 /* Check target (proxies not allowed). */
4241 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4242 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4243 _mesa_enum_to_string(texObj
->Target
));
4247 copy_texture_sub_image_err(ctx
, 1, texObj
, texObj
->Target
, level
, xoffset
, 0,
4248 0, x
, y
, width
, 1, self
);
4253 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4254 GLint xoffset
, GLint yoffset
,
4255 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4257 struct gl_texture_object
* texObj
;
4258 const char *self
= "glCopyTextureSubImage2D";
4259 GET_CURRENT_CONTEXT(ctx
);
4261 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4265 /* Check target (proxies not allowed). */
4266 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4267 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4268 _mesa_enum_to_string(texObj
->Target
));
4272 copy_texture_sub_image_err(ctx
, 2, texObj
, texObj
->Target
, level
, xoffset
,
4273 yoffset
, 0, x
, y
, width
, height
, self
);
4278 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4279 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4280 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4282 struct gl_texture_object
* texObj
;
4283 const char *self
= "glCopyTextureSubImage3D";
4284 GET_CURRENT_CONTEXT(ctx
);
4286 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4290 /* Check target (proxies not allowed). */
4291 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4292 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4293 _mesa_enum_to_string(texObj
->Target
));
4297 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4298 /* Act like CopyTexSubImage2D */
4299 copy_texture_sub_image_err(ctx
, 2, texObj
,
4300 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4301 level
, xoffset
, yoffset
, 0, x
, y
, width
, height
,
4305 copy_texture_sub_image_err(ctx
, 3, texObj
, texObj
->Target
, level
, xoffset
,
4306 yoffset
, zoffset
, x
, y
, width
, height
, self
);
4311 _mesa_CopyTexSubImage1D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4312 GLint x
, GLint y
, GLsizei width
)
4314 GET_CURRENT_CONTEXT(ctx
);
4316 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4317 copy_texture_sub_image_no_error(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4323 _mesa_CopyTexSubImage2D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4324 GLint yoffset
, GLint x
, GLint y
, GLsizei width
,
4327 GET_CURRENT_CONTEXT(ctx
);
4329 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4330 copy_texture_sub_image_no_error(ctx
, 2, texObj
, target
, level
, xoffset
,
4331 yoffset
, 0, x
, y
, width
, height
);
4336 _mesa_CopyTexSubImage3D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4337 GLint yoffset
, GLint zoffset
, GLint x
, GLint y
,
4338 GLsizei width
, GLsizei height
)
4340 GET_CURRENT_CONTEXT(ctx
);
4342 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4343 copy_texture_sub_image_no_error(ctx
, 3, texObj
, target
, level
, xoffset
,
4344 yoffset
, zoffset
, x
, y
, width
, height
);
4349 _mesa_CopyTextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4350 GLint x
, GLint y
, GLsizei width
)
4352 GET_CURRENT_CONTEXT(ctx
);
4354 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4355 copy_texture_sub_image_no_error(ctx
, 1, texObj
, texObj
->Target
, level
,
4356 xoffset
, 0, 0, x
, y
, width
, 1);
4361 _mesa_CopyTextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4362 GLint yoffset
, GLint x
, GLint y
,
4363 GLsizei width
, GLsizei height
)
4365 GET_CURRENT_CONTEXT(ctx
);
4367 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4368 copy_texture_sub_image_no_error(ctx
, 2, texObj
, texObj
->Target
, level
,
4369 xoffset
, yoffset
, 0, x
, y
, width
, height
);
4374 _mesa_CopyTextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4375 GLint yoffset
, GLint zoffset
, GLint x
,
4376 GLint y
, GLsizei width
, GLsizei height
)
4378 GET_CURRENT_CONTEXT(ctx
);
4380 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4381 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4382 /* Act like CopyTexSubImage2D */
4383 copy_texture_sub_image_no_error(ctx
, 2, texObj
,
4384 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4385 level
, xoffset
, yoffset
, 0, x
, y
, width
,
4389 copy_texture_sub_image_no_error(ctx
, 3, texObj
, texObj
->Target
, level
,
4390 xoffset
, yoffset
, zoffset
, x
, y
, width
,
4396 check_clear_tex_image(struct gl_context
*ctx
,
4397 const char *function
,
4398 struct gl_texture_image
*texImage
,
4399 GLenum format
, GLenum type
,
4401 GLubyte
*clearValue
)
4403 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4404 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4405 GLenum internalFormat
= texImage
->InternalFormat
;
4408 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4409 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4410 "%s(buffer texture)", function
);
4414 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4415 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4416 "%s(compressed texture)", function
);
4420 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4421 if (err
!= GL_NO_ERROR
) {
4422 _mesa_error(ctx
, err
,
4423 "%s(incompatible format = %s, type = %s)",
4425 _mesa_enum_to_string(format
),
4426 _mesa_enum_to_string(type
));
4430 /* make sure internal format and format basically agree */
4431 if (!texture_formats_agree(internalFormat
, format
)) {
4432 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4433 "%s(incompatible internalFormat = %s, format = %s)",
4435 _mesa_enum_to_string(internalFormat
),
4436 _mesa_enum_to_string(format
));
4440 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4441 /* both source and dest must be integer-valued, or neither */
4442 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4443 _mesa_is_enum_format_integer(format
)) {
4444 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4445 "%s(integer/non-integer format mismatch)",
4451 if (!_mesa_texstore(ctx
,
4453 texImage
->_BaseFormat
,
4454 texImage
->TexFormat
,
4455 0, /* dstRowStride */
4457 1, 1, 1, /* srcWidth/Height/Depth */
4459 data
? data
: zeroData
,
4460 &ctx
->DefaultPacking
)) {
4461 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4469 static struct gl_texture_object
*
4470 get_tex_obj_for_clear(struct gl_context
*ctx
,
4471 const char *function
,
4474 struct gl_texture_object
*texObj
;
4476 texObj
= _mesa_lookup_texture_err(ctx
, texture
, function
);
4480 if (texObj
->Target
== 0) {
4481 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4490 * For clearing cube textures, the zoffset and depth parameters indicate
4491 * which cube map faces are to be cleared. This is the one case where we
4492 * need to be concerned with multiple gl_texture_images. This function
4493 * returns the array of texture images to clear for cube maps, or one
4494 * texture image otherwise.
4495 * \return number of texture images, 0 for error, 6 for cube, 1 otherwise.
4498 get_tex_images_for_clear(struct gl_context
*ctx
,
4499 const char *function
,
4500 struct gl_texture_object
*texObj
,
4502 struct gl_texture_image
**texImages
)
4507 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4508 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4512 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4513 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
4514 numFaces
= MAX_FACES
;
4517 target
= texObj
->Target
;
4521 for (i
= 0; i
< numFaces
; i
++) {
4522 texImages
[i
] = _mesa_select_tex_image(texObj
, target
+ i
, level
);
4523 if (texImages
[i
] == NULL
) {
4524 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4534 _mesa_ClearTexSubImage(GLuint texture
, GLint level
,
4535 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4536 GLsizei width
, GLsizei height
, GLsizei depth
,
4537 GLenum format
, GLenum type
, const void *data
)
4539 GET_CURRENT_CONTEXT(ctx
);
4540 struct gl_texture_object
*texObj
;
4541 struct gl_texture_image
*texImages
[MAX_FACES
];
4542 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4544 int minDepth
, maxDepth
;
4546 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4551 _mesa_lock_texture(ctx
, texObj
);
4553 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4554 texObj
, level
, texImages
);
4558 if (numImages
== 1) {
4559 minDepth
= -(int) texImages
[0]->Border
;
4560 maxDepth
= texImages
[0]->Depth
;
4562 assert(numImages
== MAX_FACES
);
4564 maxDepth
= numImages
;
4567 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4568 yoffset
< -(GLint
) texImages
[0]->Border
||
4569 zoffset
< minDepth
||
4573 xoffset
+ width
> texImages
[0]->Width
||
4574 yoffset
+ height
> texImages
[0]->Height
||
4575 zoffset
+ depth
> maxDepth
) {
4576 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4577 "glClearSubTexImage(invalid dimensions)");
4581 if (numImages
== 1) {
4582 if (check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[0],
4583 format
, type
, data
, clearValue
[0])) {
4584 ctx
->Driver
.ClearTexSubImage(ctx
,
4586 xoffset
, yoffset
, zoffset
,
4587 width
, height
, depth
,
4588 data
? clearValue
[0] : NULL
);
4591 /* loop over cube face images */
4592 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4593 assert(i
< MAX_FACES
);
4594 if (!check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[i
],
4595 format
, type
, data
, clearValue
[i
]))
4598 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4599 ctx
->Driver
.ClearTexSubImage(ctx
,
4601 xoffset
, yoffset
, 0,
4603 data
? clearValue
[i
] : NULL
);
4608 _mesa_unlock_texture(ctx
, texObj
);
4613 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4614 GLenum format
, GLenum type
, const void *data
)
4616 GET_CURRENT_CONTEXT(ctx
);
4617 struct gl_texture_object
*texObj
;
4618 struct gl_texture_image
*texImages
[MAX_FACES
];
4619 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4622 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4627 _mesa_lock_texture(ctx
, texObj
);
4629 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4630 texObj
, level
, texImages
);
4632 for (i
= 0; i
< numImages
; i
++) {
4633 if (!check_clear_tex_image(ctx
, "glClearTexImage", texImages
[i
], format
,
4634 type
, data
, clearValue
[i
]))
4638 for (i
= 0; i
< numImages
; i
++) {
4639 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4640 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4641 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4642 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4643 texImages
[i
]->Width
,
4644 texImages
[i
]->Height
,
4645 texImages
[i
]->Depth
,
4646 data
? clearValue
[i
] : NULL
);
4650 _mesa_unlock_texture(ctx
, texObj
);
4656 /**********************************************************************/
4657 /****** Compressed Textures ******/
4658 /**********************************************************************/
4662 * Target checking for glCompressedTexSubImage[123]D().
4663 * \return GL_TRUE if error, GL_FALSE if no error
4664 * Must come before other error checking so that the texture object can
4665 * be correctly retrieved using _mesa_get_current_tex_object.
4668 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4669 GLint dims
, GLenum intFormat
, bool dsa
,
4674 enum mesa_format_layout layout
;
4676 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4677 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4678 _mesa_enum_to_string(target
));
4688 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4689 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4690 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4691 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4692 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4693 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4694 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4697 targetOK
= GL_FALSE
;
4703 case GL_TEXTURE_CUBE_MAP
:
4704 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4706 case GL_TEXTURE_2D_ARRAY
:
4707 targetOK
= _mesa_is_gles3(ctx
) ||
4708 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4710 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4711 targetOK
= _mesa_has_texture_cube_map_array(ctx
);
4716 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4718 * "An INVALID_OPERATION error is generated by
4719 * CompressedTex*SubImage3D if the internal format of the texture
4720 * is one of the EAC, ETC2, or RGTC formats and either border is
4721 * non-zero, or the effective target for the texture is not
4722 * TEXTURE_2D_ARRAY."
4724 * NOTE: that's probably a spec error. It should probably say
4725 * "... or the effective target for the texture is not
4726 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4727 * GL_TEXTURE_CUBE_MAP_ARRAY."
4728 * since those targets are 2D images and they support all compression
4731 * Instead of listing all these, just list those which are allowed,
4732 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4733 * more) are valid here, which they are not, but of course not
4734 * mentioned by core spec.
4736 * Also, from GL_KHR_texture_compression_astc_{hdr,ldr}:
4738 * "Add a second new column "3D Tex." which is empty for all non-ASTC
4739 * formats. If only the LDR profile is supported by the implementation,
4740 * this column is also empty for all ASTC formats. If both the LDR and HDR
4741 * profiles are supported, this column is checked for all ASTC formats."
4743 * "An INVALID_OPERATION error is generated by CompressedTexSubImage3D if
4744 * <format> is one of the formats in table 8.19 and <target> is not
4745 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, or TEXTURE_3D.
4747 * An INVALID_OPERATION error is generated by CompressedTexSubImage3D if
4748 * <format> is TEXTURE_CUBE_MAP_ARRAY and the "Cube Map Array" column of
4749 * table 8.19 is *not* checked, or if <format> is TEXTURE_3D and the "3D
4750 * Tex." column of table 8.19 is *not* checked"
4752 * And from GL_KHR_texture_compression_astc_sliced_3d:
4754 * "Modify the "3D Tex." column to be checked for all ASTC formats."
4756 format
= _mesa_glenum_to_compressed_format(intFormat
);
4757 layout
= _mesa_get_format_layout(format
);
4759 case MESA_FORMAT_LAYOUT_BPTC
:
4762 case MESA_FORMAT_LAYOUT_ASTC
:
4764 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
4765 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
4768 /* invalid format */
4769 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4770 "%s(invalid target %s for format %s)", caller
,
4771 _mesa_enum_to_string(target
),
4772 _mesa_enum_to_string(intFormat
));
4777 targetOK
= GL_FALSE
;
4783 /* no 1D compressed textures at this time */
4784 targetOK
= GL_FALSE
;
4789 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4790 _mesa_enum_to_string(target
));
4798 * Error checking for glCompressedTexSubImage[123]D().
4799 * \return GL_TRUE if error, GL_FALSE if no error
4802 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4803 const struct gl_texture_object
*texObj
,
4804 GLenum target
, GLint level
,
4805 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4806 GLsizei width
, GLsizei height
, GLsizei depth
,
4807 GLenum format
, GLsizei imageSize
,
4808 const GLvoid
*data
, const char *callerName
)
4810 struct gl_texture_image
*texImage
;
4813 /* this will catch any invalid compressed format token */
4814 if (!_mesa_is_compressed_format(ctx
, format
)) {
4815 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(format)", callerName
);
4819 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4820 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
4824 /* validate the bound PBO, if any */
4825 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4826 imageSize
, data
, callerName
)) {
4830 /* Check for invalid pixel storage modes */
4831 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4832 &ctx
->Unpack
, callerName
)) {
4836 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4837 if (expectedSize
!= imageSize
) {
4838 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", callerName
, imageSize
);
4842 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4844 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture level %d)",
4849 if ((GLint
) format
!= texImage
->InternalFormat
) {
4850 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s)",
4851 callerName
, _mesa_enum_to_string(format
));
4855 if (compressedteximage_only_format(format
)) {
4856 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s cannot be updated)",
4857 callerName
, _mesa_enum_to_string(format
));
4861 if (error_check_subtexture_negative_dimensions(ctx
, dims
, width
, height
,
4862 depth
, callerName
)) {
4866 if (error_check_subtexture_dimensions(ctx
, dims
, texImage
, xoffset
, yoffset
,
4867 zoffset
, width
, height
, depth
,
4877 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4878 GLenum internalFormat
, GLsizei width
,
4879 GLint border
, GLsizei imageSize
,
4882 GET_CURRENT_CONTEXT(ctx
);
4883 teximage_err(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4884 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4889 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4890 GLenum internalFormat
, GLsizei width
,
4891 GLsizei height
, GLint border
, GLsizei imageSize
,
4894 GET_CURRENT_CONTEXT(ctx
);
4895 teximage_err(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4896 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4901 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4902 GLenum internalFormat
, GLsizei width
,
4903 GLsizei height
, GLsizei depth
, GLint border
,
4904 GLsizei imageSize
, const GLvoid
*data
)
4906 GET_CURRENT_CONTEXT(ctx
);
4907 teximage_err(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
, height
,
4908 depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4913 _mesa_CompressedTexImage1D_no_error(GLenum target
, GLint level
,
4914 GLenum internalFormat
, GLsizei width
,
4915 GLint border
, GLsizei imageSize
,
4918 GET_CURRENT_CONTEXT(ctx
);
4919 teximage_no_error(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
, width
, 1,
4920 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4925 _mesa_CompressedTexImage2D_no_error(GLenum target
, GLint level
,
4926 GLenum internalFormat
, GLsizei width
,
4927 GLsizei height
, GLint border
,
4928 GLsizei imageSize
, const GLvoid
*data
)
4930 GET_CURRENT_CONTEXT(ctx
);
4931 teximage_no_error(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
, width
,
4932 height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4937 _mesa_CompressedTexImage3D_no_error(GLenum target
, GLint level
,
4938 GLenum internalFormat
, GLsizei width
,
4939 GLsizei height
, GLsizei depth
, GLint border
,
4940 GLsizei imageSize
, const GLvoid
*data
)
4942 GET_CURRENT_CONTEXT(ctx
);
4943 teximage_no_error(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
,
4944 height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4949 * Common helper for glCompressedTexSubImage1/2/3D() and
4950 * glCompressedTextureSubImage1/2/3D().
4953 compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4954 struct gl_texture_object
*texObj
,
4955 struct gl_texture_image
*texImage
,
4956 GLenum target
, GLint level
, GLint xoffset
,
4957 GLint yoffset
, GLint zoffset
, GLsizei width
,
4958 GLsizei height
, GLsizei depth
, GLenum format
,
4959 GLsizei imageSize
, const GLvoid
*data
)
4961 FLUSH_VERTICES(ctx
, 0);
4963 _mesa_lock_texture(ctx
, texObj
);
4965 if (width
> 0 && height
> 0 && depth
> 0) {
4966 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4967 xoffset
, yoffset
, zoffset
,
4968 width
, height
, depth
,
4969 format
, imageSize
, data
);
4971 check_gen_mipmap(ctx
, target
, texObj
, level
);
4973 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
4974 * the texel data, not the texture format, size, etc.
4978 _mesa_unlock_texture(ctx
, texObj
);
4982 static ALWAYS_INLINE
void
4983 compressed_tex_sub_image(unsigned dim
, GLenum target
, GLuint texture
,
4984 GLint level
, GLint xoffset
, GLint yoffset
,
4985 GLint zoffset
, GLsizei width
, GLsizei height
,
4986 GLsizei depth
, GLenum format
, GLsizei imageSize
,
4987 const GLvoid
*data
, bool dsa
, bool no_error
,
4990 struct gl_texture_object
*texObj
= NULL
;
4991 struct gl_texture_image
*texImage
;
4993 GET_CURRENT_CONTEXT(ctx
);
4997 texObj
= _mesa_lookup_texture(ctx
, texture
);
4999 texObj
= _mesa_lookup_texture_err(ctx
, texture
, caller
);
5004 target
= texObj
->Target
;
5008 compressed_subtexture_target_check(ctx
, target
, dim
, format
, dsa
,
5014 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5015 if (!no_error
&& !texObj
)
5020 compressed_subtexture_error_check(ctx
, dim
, texObj
, target
, level
,
5021 xoffset
, yoffset
, zoffset
, width
,
5022 height
, depth
, format
,
5023 imageSize
, data
, caller
)) {
5027 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
5028 if (dim
== 3 && dsa
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5029 const char *pixels
= data
;
5032 /* Make sure the texture object is a proper cube.
5033 * (See texturesubimage in teximage.c for details on why this check is
5036 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
5037 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5038 "glCompressedTextureSubImage3D(cube map incomplete)");
5042 /* Copy in each face. */
5043 for (int i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
5044 texImage
= texObj
->Image
[i
][level
];
5047 compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5048 texObj
->Target
, level
, xoffset
, yoffset
,
5049 0, width
, height
, 1, format
,
5052 /* Compressed images don't have a client format */
5053 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5055 texImage
->Height
, 1);
5057 pixels
+= image_stride
;
5058 imageSize
-= image_stride
;
5061 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5064 compressed_texture_sub_image(ctx
, dim
, texObj
, texImage
, target
, level
,
5065 xoffset
, yoffset
, zoffset
, width
, height
,
5066 depth
, format
, imageSize
, data
);
5071 compressed_tex_sub_image_error(unsigned dim
, GLenum target
, GLuint texture
,
5072 GLint level
, GLint xoffset
, GLint yoffset
,
5073 GLint zoffset
, GLsizei width
, GLsizei height
,
5074 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5075 const GLvoid
*data
, bool dsa
,
5078 compressed_tex_sub_image(dim
, target
, texture
, level
, xoffset
, yoffset
,
5079 zoffset
, width
, height
, depth
, format
, imageSize
,
5080 data
, dsa
, false, caller
);
5084 compressed_tex_sub_image_no_error(unsigned dim
, GLenum target
, GLuint texture
,
5085 GLint level
, GLint xoffset
, GLint yoffset
,
5086 GLint zoffset
, GLsizei width
, GLsizei height
,
5087 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5088 const GLvoid
*data
, bool dsa
,
5091 compressed_tex_sub_image(dim
, target
, texture
, level
, xoffset
, yoffset
,
5092 zoffset
, width
, height
, depth
, format
, imageSize
,
5093 data
, dsa
, true, caller
);
5097 _mesa_CompressedTexSubImage1D_no_error(GLenum target
, GLint level
,
5098 GLint xoffset
, GLsizei width
,
5099 GLenum format
, GLsizei imageSize
,
5102 compressed_tex_sub_image_no_error(1, target
, 0, level
, xoffset
, 0, 0, width
,
5103 1, 1, format
, imageSize
, data
, false,
5104 "glCompressedTexSubImage1D");
5109 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
5110 GLsizei width
, GLenum format
,
5111 GLsizei imageSize
, const GLvoid
*data
)
5113 compressed_tex_sub_image_error(1, target
, 0, level
, xoffset
, 0, 0, width
, 1,
5114 1, format
, imageSize
, data
, false,
5115 "glCompressedTexSubImage1D");
5120 _mesa_CompressedTextureSubImage1D_no_error(GLuint texture
, GLint level
,
5121 GLint xoffset
, GLsizei width
,
5122 GLenum format
, GLsizei imageSize
,
5125 compressed_tex_sub_image_no_error(1, 0, texture
, level
, xoffset
, 0, 0, width
,
5126 1, 1, format
, imageSize
, data
, true,
5127 "glCompressedTextureSubImage1D");
5132 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
5133 GLsizei width
, GLenum format
,
5134 GLsizei imageSize
, const GLvoid
*data
)
5136 compressed_tex_sub_image_error(1, 0, texture
, level
, xoffset
, 0, 0, width
,
5137 1, 1, format
, imageSize
, data
, true,
5138 "glCompressedTextureSubImage1D");
5142 _mesa_CompressedTexSubImage2D_no_error(GLenum target
, GLint level
,
5143 GLint xoffset
, GLint yoffset
,
5144 GLsizei width
, GLsizei height
,
5145 GLenum format
, GLsizei imageSize
,
5148 compressed_tex_sub_image_no_error(2, target
, 0, level
, xoffset
, yoffset
, 0,
5149 width
, height
, 1, format
, imageSize
, data
,
5150 false, "glCompressedTexSubImage2D");
5155 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
5156 GLint yoffset
, GLsizei width
, GLsizei height
,
5157 GLenum format
, GLsizei imageSize
,
5160 compressed_tex_sub_image_error(2, target
, 0, level
, xoffset
, yoffset
, 0,
5161 width
, height
, 1, format
, imageSize
, data
,
5162 false, "glCompressedTexSubImage2D");
5167 _mesa_CompressedTextureSubImage2D_no_error(GLuint texture
, GLint level
,
5168 GLint xoffset
, GLint yoffset
,
5169 GLsizei width
, GLsizei height
,
5170 GLenum format
, GLsizei imageSize
,
5173 compressed_tex_sub_image_no_error(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5174 width
, height
, 1, format
, imageSize
, data
,
5175 true, "glCompressedTextureSubImage2D");
5180 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
5182 GLsizei width
, GLsizei height
,
5183 GLenum format
, GLsizei imageSize
,
5186 compressed_tex_sub_image_error(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5187 width
, height
, 1, format
, imageSize
, data
,
5188 true, "glCompressedTextureSubImage2D");
5192 _mesa_CompressedTexSubImage3D_no_error(GLenum target
, GLint level
,
5193 GLint xoffset
, GLint yoffset
,
5194 GLint zoffset
, GLsizei width
,
5195 GLsizei height
, GLsizei depth
,
5196 GLenum format
, GLsizei imageSize
,
5199 compressed_tex_sub_image_no_error(3, target
, 0, level
, xoffset
, yoffset
,
5200 zoffset
, width
, height
, depth
, format
,
5201 imageSize
, data
, false,
5202 "glCompressedTexSubImage3D");
5206 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
5207 GLint yoffset
, GLint zoffset
, GLsizei width
,
5208 GLsizei height
, GLsizei depth
, GLenum format
,
5209 GLsizei imageSize
, const GLvoid
*data
)
5211 compressed_tex_sub_image_error(3, target
, 0, level
, xoffset
, yoffset
,
5212 zoffset
, width
, height
, depth
, format
,
5213 imageSize
, data
, false,
5214 "glCompressedTexSubImage3D");
5218 _mesa_CompressedTextureSubImage3D_no_error(GLuint texture
, GLint level
,
5219 GLint xoffset
, GLint yoffset
,
5220 GLint zoffset
, GLsizei width
,
5221 GLsizei height
, GLsizei depth
,
5222 GLenum format
, GLsizei imageSize
,
5225 compressed_tex_sub_image_no_error(3, 0, texture
, level
, xoffset
, yoffset
,
5226 zoffset
, width
, height
, depth
, format
,
5227 imageSize
, data
, true,
5228 "glCompressedTextureSubImage3D");
5232 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
5233 GLint yoffset
, GLint zoffset
, GLsizei width
,
5234 GLsizei height
, GLsizei depth
,
5235 GLenum format
, GLsizei imageSize
,
5238 compressed_tex_sub_image_error(3, 0, texture
, level
, xoffset
, yoffset
,
5239 zoffset
, width
, height
, depth
, format
,
5240 imageSize
, data
, true,
5241 "glCompressedTextureSubImage3D");
5245 _mesa_get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5247 if (ctx
->API
== API_OPENGL_COMPAT
) {
5248 switch (internalFormat
) {
5250 return MESA_FORMAT_A_UNORM8
;
5252 return MESA_FORMAT_A_UNORM16
;
5253 case GL_ALPHA16F_ARB
:
5254 return MESA_FORMAT_A_FLOAT16
;
5255 case GL_ALPHA32F_ARB
:
5256 return MESA_FORMAT_A_FLOAT32
;
5257 case GL_ALPHA8I_EXT
:
5258 return MESA_FORMAT_A_SINT8
;
5259 case GL_ALPHA16I_EXT
:
5260 return MESA_FORMAT_A_SINT16
;
5261 case GL_ALPHA32I_EXT
:
5262 return MESA_FORMAT_A_SINT32
;
5263 case GL_ALPHA8UI_EXT
:
5264 return MESA_FORMAT_A_UINT8
;
5265 case GL_ALPHA16UI_EXT
:
5266 return MESA_FORMAT_A_UINT16
;
5267 case GL_ALPHA32UI_EXT
:
5268 return MESA_FORMAT_A_UINT32
;
5270 return MESA_FORMAT_L_UNORM8
;
5271 case GL_LUMINANCE16
:
5272 return MESA_FORMAT_L_UNORM16
;
5273 case GL_LUMINANCE16F_ARB
:
5274 return MESA_FORMAT_L_FLOAT16
;
5275 case GL_LUMINANCE32F_ARB
:
5276 return MESA_FORMAT_L_FLOAT32
;
5277 case GL_LUMINANCE8I_EXT
:
5278 return MESA_FORMAT_L_SINT8
;
5279 case GL_LUMINANCE16I_EXT
:
5280 return MESA_FORMAT_L_SINT16
;
5281 case GL_LUMINANCE32I_EXT
:
5282 return MESA_FORMAT_L_SINT32
;
5283 case GL_LUMINANCE8UI_EXT
:
5284 return MESA_FORMAT_L_UINT8
;
5285 case GL_LUMINANCE16UI_EXT
:
5286 return MESA_FORMAT_L_UINT16
;
5287 case GL_LUMINANCE32UI_EXT
:
5288 return MESA_FORMAT_L_UINT32
;
5289 case GL_LUMINANCE8_ALPHA8
:
5290 return MESA_FORMAT_L8A8_UNORM
;
5291 case GL_LUMINANCE16_ALPHA16
:
5292 return MESA_FORMAT_L16A16_UNORM
;
5293 case GL_LUMINANCE_ALPHA16F_ARB
:
5294 return MESA_FORMAT_LA_FLOAT16
;
5295 case GL_LUMINANCE_ALPHA32F_ARB
:
5296 return MESA_FORMAT_LA_FLOAT32
;
5297 case GL_LUMINANCE_ALPHA8I_EXT
:
5298 return MESA_FORMAT_LA_SINT8
;
5299 case GL_LUMINANCE_ALPHA16I_EXT
:
5300 return MESA_FORMAT_LA_SINT16
;
5301 case GL_LUMINANCE_ALPHA32I_EXT
:
5302 return MESA_FORMAT_LA_SINT32
;
5303 case GL_LUMINANCE_ALPHA8UI_EXT
:
5304 return MESA_FORMAT_LA_UINT8
;
5305 case GL_LUMINANCE_ALPHA16UI_EXT
:
5306 return MESA_FORMAT_LA_UINT16
;
5307 case GL_LUMINANCE_ALPHA32UI_EXT
:
5308 return MESA_FORMAT_LA_UINT32
;
5310 return MESA_FORMAT_I_UNORM8
;
5311 case GL_INTENSITY16
:
5312 return MESA_FORMAT_I_UNORM16
;
5313 case GL_INTENSITY16F_ARB
:
5314 return MESA_FORMAT_I_FLOAT16
;
5315 case GL_INTENSITY32F_ARB
:
5316 return MESA_FORMAT_I_FLOAT32
;
5317 case GL_INTENSITY8I_EXT
:
5318 return MESA_FORMAT_I_SINT8
;
5319 case GL_INTENSITY16I_EXT
:
5320 return MESA_FORMAT_I_SINT16
;
5321 case GL_INTENSITY32I_EXT
:
5322 return MESA_FORMAT_I_SINT32
;
5323 case GL_INTENSITY8UI_EXT
:
5324 return MESA_FORMAT_I_UINT8
;
5325 case GL_INTENSITY16UI_EXT
:
5326 return MESA_FORMAT_I_UINT16
;
5327 case GL_INTENSITY32UI_EXT
:
5328 return MESA_FORMAT_I_UINT32
;
5334 if (_mesa_has_ARB_texture_buffer_object_rgb32(ctx
) ||
5335 _mesa_has_OES_texture_buffer(ctx
)) {
5336 switch (internalFormat
) {
5338 return MESA_FORMAT_RGB_FLOAT32
;
5340 return MESA_FORMAT_RGB_UINT32
;
5342 return MESA_FORMAT_RGB_SINT32
;
5348 switch (internalFormat
) {
5350 return MESA_FORMAT_R8G8B8A8_UNORM
;
5352 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5353 return MESA_FORMAT_NONE
;
5354 return MESA_FORMAT_RGBA_UNORM16
;
5355 case GL_RGBA16F_ARB
:
5356 return MESA_FORMAT_RGBA_FLOAT16
;
5357 case GL_RGBA32F_ARB
:
5358 return MESA_FORMAT_RGBA_FLOAT32
;
5360 return MESA_FORMAT_RGBA_SINT8
;
5361 case GL_RGBA16I_EXT
:
5362 return MESA_FORMAT_RGBA_SINT16
;
5363 case GL_RGBA32I_EXT
:
5364 return MESA_FORMAT_RGBA_SINT32
;
5365 case GL_RGBA8UI_EXT
:
5366 return MESA_FORMAT_RGBA_UINT8
;
5367 case GL_RGBA16UI_EXT
:
5368 return MESA_FORMAT_RGBA_UINT16
;
5369 case GL_RGBA32UI_EXT
:
5370 return MESA_FORMAT_RGBA_UINT32
;
5373 return MESA_FORMAT_R8G8_UNORM
;
5375 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5376 return MESA_FORMAT_NONE
;
5377 return MESA_FORMAT_R16G16_UNORM
;
5379 return MESA_FORMAT_RG_FLOAT16
;
5381 return MESA_FORMAT_RG_FLOAT32
;
5383 return MESA_FORMAT_RG_SINT8
;
5385 return MESA_FORMAT_RG_SINT16
;
5387 return MESA_FORMAT_RG_SINT32
;
5389 return MESA_FORMAT_RG_UINT8
;
5391 return MESA_FORMAT_RG_UINT16
;
5393 return MESA_FORMAT_RG_UINT32
;
5396 return MESA_FORMAT_R_UNORM8
;
5398 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5399 return MESA_FORMAT_NONE
;
5400 return MESA_FORMAT_R_UNORM16
;
5402 return MESA_FORMAT_R_FLOAT16
;
5404 return MESA_FORMAT_R_FLOAT32
;
5406 return MESA_FORMAT_R_SINT8
;
5408 return MESA_FORMAT_R_SINT16
;
5410 return MESA_FORMAT_R_SINT32
;
5412 return MESA_FORMAT_R_UINT8
;
5414 return MESA_FORMAT_R_UINT16
;
5416 return MESA_FORMAT_R_UINT32
;
5419 return MESA_FORMAT_NONE
;
5425 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5426 GLenum internalFormat
)
5428 mesa_format format
= _mesa_get_texbuffer_format(ctx
, internalFormat
);
5431 if (format
== MESA_FORMAT_NONE
)
5432 return MESA_FORMAT_NONE
;
5434 datatype
= _mesa_get_format_datatype(format
);
5436 /* The GL_ARB_texture_buffer_object spec says:
5438 * "If ARB_texture_float is not supported, references to the
5439 * floating-point internal formats provided by that extension should be
5440 * removed, and such formats may not be passed to TexBufferARB."
5442 * As a result, GL_HALF_FLOAT internal format depends on both
5443 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5445 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5446 !ctx
->Extensions
.ARB_texture_float
)
5447 return MESA_FORMAT_NONE
;
5449 if (!ctx
->Extensions
.ARB_texture_rg
) {
5450 GLenum base_format
= _mesa_get_format_base_format(format
);
5451 if (base_format
== GL_R
|| base_format
== GL_RG
)
5452 return MESA_FORMAT_NONE
;
5455 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5456 GLenum base_format
= _mesa_get_format_base_format(format
);
5457 if (base_format
== GL_RGB
)
5458 return MESA_FORMAT_NONE
;
5465 * Do work common to glTexBuffer, glTexBufferRange, glTextureBuffer
5466 * and glTextureBufferRange, including some error checking.
5469 texture_buffer_range(struct gl_context
*ctx
,
5470 struct gl_texture_object
*texObj
,
5471 GLenum internalFormat
,
5472 struct gl_buffer_object
*bufObj
,
5473 GLintptr offset
, GLsizeiptr size
,
5476 GLintptr oldOffset
= texObj
->BufferOffset
;
5477 GLsizeiptr oldSize
= texObj
->BufferSize
;
5480 /* NOTE: ARB_texture_buffer_object might not be supported in
5481 * the compatibility profile.
5483 if (!_mesa_has_ARB_texture_buffer_object(ctx
) &&
5484 !_mesa_has_OES_texture_buffer(ctx
)) {
5485 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5486 "%s(ARB_texture_buffer_object is not"
5487 " implemented for the compatibility profile)", caller
);
5491 if (texObj
->HandleAllocated
) {
5492 /* The ARB_bindless_texture spec says:
5494 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
5495 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
5496 * functions defined in terms of these, if the texture object to be
5497 * modified is referenced by one or more texture or image handles."
5499 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable texture)", caller
);
5503 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5504 if (format
== MESA_FORMAT_NONE
) {
5505 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat %s)",
5506 caller
, _mesa_enum_to_string(internalFormat
));
5510 FLUSH_VERTICES(ctx
, 0);
5512 _mesa_lock_texture(ctx
, texObj
);
5514 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5515 texObj
->BufferObjectFormat
= internalFormat
;
5516 texObj
->_BufferObjectFormat
= format
;
5517 texObj
->BufferOffset
= offset
;
5518 texObj
->BufferSize
= size
;
5520 _mesa_unlock_texture(ctx
, texObj
);
5522 if (ctx
->Driver
.TexParameter
) {
5523 if (offset
!= oldOffset
) {
5524 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_OFFSET
);
5526 if (size
!= oldSize
) {
5527 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_SIZE
);
5531 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5534 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5540 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5541 * Return true if it is, and return false if it is not
5542 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5543 * core spec, 02.02.2015, PDF page 245).
5546 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5549 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5550 _mesa_error(ctx
, GL_INVALID_ENUM
,
5551 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5559 * Check for errors related to the texture buffer range.
5560 * Return false if errors are found, true if none are found.
5563 check_texture_buffer_range(struct gl_context
*ctx
,
5564 struct gl_buffer_object
*bufObj
,
5565 GLintptr offset
, GLsizeiptr size
,
5568 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5569 * Textures (PDF page 245):
5570 * "An INVALID_VALUE error is generated if offset is negative, if
5571 * size is less than or equal to zero, or if offset + size is greater
5572 * than the value of BUFFER_SIZE for the buffer bound to target."
5575 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5581 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5586 if (offset
+ size
> bufObj
->Size
) {
5587 _mesa_error(ctx
, GL_INVALID_VALUE
,
5588 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5589 (int) offset
, (int) size
, (int) bufObj
->Size
);
5593 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5594 * Textures (PDF page 245):
5595 * "An INVALID_VALUE error is generated if offset is not an integer
5596 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5598 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5599 _mesa_error(ctx
, GL_INVALID_VALUE
,
5600 "%s(invalid offset alignment)", caller
);
5608 /** GL_ARB_texture_buffer_object */
5610 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5612 struct gl_texture_object
*texObj
;
5613 struct gl_buffer_object
*bufObj
;
5615 GET_CURRENT_CONTEXT(ctx
);
5617 /* Need to catch a bad target before it gets to
5618 * _mesa_get_current_tex_object.
5620 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5624 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5630 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5634 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5635 buffer
? -1 : 0, "glTexBuffer");
5639 /** GL_ARB_texture_buffer_range */
5641 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5642 GLintptr offset
, GLsizeiptr size
)
5644 struct gl_texture_object
*texObj
;
5645 struct gl_buffer_object
*bufObj
;
5647 GET_CURRENT_CONTEXT(ctx
);
5649 /* Need to catch a bad target before it gets to
5650 * _mesa_get_current_tex_object.
5652 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5656 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5660 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5661 "glTexBufferRange"))
5665 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5666 * Textures (PDF page 254):
5667 * "If buffer is zero, then any buffer object attached to the buffer
5668 * texture is detached, the values offset and size are ignored and
5669 * the state for offset and size for the buffer texture are reset to
5677 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5681 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5682 offset
, size
, "glTexBufferRange");
5686 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5688 struct gl_texture_object
*texObj
;
5689 struct gl_buffer_object
*bufObj
;
5691 GET_CURRENT_CONTEXT(ctx
);
5694 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5700 /* Get the texture object by Name. */
5701 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5705 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5708 texture_buffer_range(ctx
, texObj
, internalFormat
,
5709 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5713 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5714 GLintptr offset
, GLsizeiptr size
)
5716 struct gl_texture_object
*texObj
;
5717 struct gl_buffer_object
*bufObj
;
5719 GET_CURRENT_CONTEXT(ctx
);
5722 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5723 "glTextureBufferRange");
5727 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5728 "glTextureBufferRange"))
5732 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5733 * Textures (PDF page 254):
5734 * "If buffer is zero, then any buffer object attached to the buffer
5735 * texture is detached, the values offset and size are ignored and
5736 * the state for offset and size for the buffer texture are reset to
5744 /* Get the texture object by Name. */
5745 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5749 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5750 "glTextureBufferRange"))
5753 texture_buffer_range(ctx
, texObj
, internalFormat
,
5754 bufObj
, offset
, size
, "glTextureBufferRange");
5758 _mesa_is_renderable_texture_format(const struct gl_context
*ctx
,
5759 GLenum internalformat
)
5761 /* Everything that is allowed for renderbuffers,
5762 * except for a base format of GL_STENCIL_INDEX, unless supported.
5764 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5765 if (ctx
->Extensions
.ARB_texture_stencil8
)
5766 return baseFormat
!= 0;
5768 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5772 /** GL_ARB_texture_multisample */
5774 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5777 case GL_TEXTURE_2D_MULTISAMPLE
:
5779 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5780 return dims
== 2 && !dsa
;
5781 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5783 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5784 return dims
== 3 && !dsa
;
5792 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5793 struct gl_texture_object
*texObj
,
5794 struct gl_memory_object
*memObj
,
5795 GLenum target
, GLsizei samples
,
5796 GLint internalformat
, GLsizei width
,
5797 GLsizei height
, GLsizei depth
,
5798 GLboolean fixedsamplelocations
,
5799 GLboolean immutable
, GLuint64 offset
,
5802 struct gl_texture_image
*texImage
;
5803 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5804 mesa_format texFormat
;
5805 GLenum sample_count_error
;
5806 bool dsa
= strstr(func
, "ture") ? true : false;
5808 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
5809 _mesa_debug(ctx
, "%s(target=%s, samples=%d)\n", func
,
5810 _mesa_enum_to_string(target
), samples
);
5813 if (!((ctx
->Extensions
.ARB_texture_multisample
5814 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5815 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5820 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5824 if (!check_multisample_target(dims
, target
, dsa
)) {
5825 GLenum err
= dsa
? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
5826 _mesa_error(ctx
, err
, "%s(target=%s)", func
,
5827 _mesa_enum_to_string(target
));
5831 /* check that the specified internalformat is color/depth/stencil-renderable;
5832 * refer GL3.1 spec 4.4.4
5835 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5836 _mesa_error(ctx
, GL_INVALID_ENUM
,
5837 "%s(internalformat=%s not legal for immutable-format)",
5838 func
, _mesa_enum_to_string(internalformat
));
5842 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
)) {
5843 /* Page 172 of OpenGL ES 3.1 spec says:
5844 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5845 * color-renderable, depth-renderable, or stencil-renderable (as
5846 * defined in section 9.4).
5848 * (Same error is also defined for desktop OpenGL for multisample
5849 * teximage/texstorage functions.)
5851 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5852 _mesa_enum_to_string(internalformat
));
5856 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5857 internalformat
, samples
, samples
);
5858 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5860 /* Page 254 of OpenGL 4.4 spec says:
5861 * "Proxy arrays for two-dimensional multisample and two-dimensional
5862 * multisample array textures are operated on in the same way when
5863 * TexImage2DMultisample is called with target specified as
5864 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5865 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5866 * However, if samples is not supported, then no error is generated.
5868 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5869 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
5873 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5874 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5875 "%s(texture object 0)",
5880 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5882 if (texImage
== NULL
) {
5883 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5887 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5888 internalformat
, GL_NONE
, GL_NONE
);
5889 assert(texFormat
!= MESA_FORMAT_NONE
);
5891 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5892 width
, height
, depth
, 0);
5894 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, 0, texFormat
,
5895 samples
, width
, height
, depth
);
5897 if (_mesa_is_proxy_texture(target
)) {
5898 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5899 _mesa_init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5900 internalformat
, texFormat
,
5901 samples
, fixedsamplelocations
);
5904 /* clear all image fields */
5905 clear_teximage_fields(texImage
);
5909 if (!dimensionsOK
) {
5910 _mesa_error(ctx
, GL_INVALID_VALUE
,
5911 "%s(invalid width=%d or height=%d)", func
, width
, height
);
5916 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5920 /* Check if texObj->Immutable is set */
5921 if (texObj
->Immutable
) {
5922 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5926 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5928 _mesa_init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5929 internalformat
, texFormat
,
5930 samples
, fixedsamplelocations
);
5932 if (width
> 0 && height
> 0 && depth
> 0) {
5934 if (!ctx
->Driver
.SetTextureStorageForMemoryObject(ctx
, texObj
,
5939 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
5940 internalformat
, texFormat
);
5943 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5944 width
, height
, depth
)) {
5945 /* tidy up the texture image state. strictly speaking,
5946 * we're allowed to just leave this in whatever state we
5947 * like, but being tidy is good.
5949 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
5950 internalformat
, texFormat
);
5955 texObj
->Immutable
|= immutable
;
5958 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5961 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5967 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5968 GLenum internalformat
, GLsizei width
,
5969 GLsizei height
, GLboolean fixedsamplelocations
)
5971 struct gl_texture_object
*texObj
;
5972 GET_CURRENT_CONTEXT(ctx
);
5974 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5978 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
5979 internalformat
, width
, height
, 1,
5980 fixedsamplelocations
, GL_FALSE
, 0,
5981 "glTexImage2DMultisample");
5986 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5987 GLenum internalformat
, GLsizei width
,
5988 GLsizei height
, GLsizei depth
,
5989 GLboolean fixedsamplelocations
)
5991 struct gl_texture_object
*texObj
;
5992 GET_CURRENT_CONTEXT(ctx
);
5994 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5998 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
5999 internalformat
, width
, height
, depth
,
6000 fixedsamplelocations
, GL_FALSE
, 0,
6001 "glTexImage3DMultisample");
6005 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
6008 GET_CURRENT_CONTEXT(ctx
);
6010 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
6011 _mesa_error(ctx
, GL_INVALID_VALUE
,
6012 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
6013 dims
, width
, height
, depth
);
6020 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
6021 GLenum internalformat
, GLsizei width
,
6022 GLsizei height
, GLboolean fixedsamplelocations
)
6024 struct gl_texture_object
*texObj
;
6025 GET_CURRENT_CONTEXT(ctx
);
6027 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6031 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
6034 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
6035 internalformat
, width
, height
, 1,
6036 fixedsamplelocations
, GL_TRUE
, 0,
6037 "glTexStorage2DMultisample");
6041 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
6042 GLenum internalformat
, GLsizei width
,
6043 GLsizei height
, GLsizei depth
,
6044 GLboolean fixedsamplelocations
)
6046 struct gl_texture_object
*texObj
;
6047 GET_CURRENT_CONTEXT(ctx
);
6049 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6053 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
6056 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
6057 internalformat
, width
, height
, depth
,
6058 fixedsamplelocations
, GL_TRUE
, 0,
6059 "glTexStorage3DMultisample");
6063 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
6064 GLenum internalformat
, GLsizei width
,
6066 GLboolean fixedsamplelocations
)
6068 struct gl_texture_object
*texObj
;
6069 GET_CURRENT_CONTEXT(ctx
);
6071 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6072 "glTextureStorage2DMultisample");
6076 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
6079 texture_image_multisample(ctx
, 2, texObj
, NULL
, texObj
->Target
,
6080 samples
, internalformat
, width
, height
, 1,
6081 fixedsamplelocations
, GL_TRUE
, 0,
6082 "glTextureStorage2DMultisample");
6086 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
6087 GLenum internalformat
, GLsizei width
,
6088 GLsizei height
, GLsizei depth
,
6089 GLboolean fixedsamplelocations
)
6091 struct gl_texture_object
*texObj
;
6092 GET_CURRENT_CONTEXT(ctx
);
6094 /* Get the texture object by Name. */
6095 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6096 "glTextureStorage3DMultisample");
6100 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
6103 texture_image_multisample(ctx
, 3, texObj
, NULL
, texObj
->Target
, samples
,
6104 internalformat
, width
, height
, depth
,
6105 fixedsamplelocations
, GL_TRUE
, 0,
6106 "glTextureStorage3DMultisample");
6110 _mesa_texture_storage_ms_memory(struct gl_context
*ctx
, GLuint dims
,
6111 struct gl_texture_object
*texObj
,
6112 struct gl_memory_object
*memObj
,
6113 GLenum target
, GLsizei samples
,
6114 GLenum internalFormat
, GLsizei width
,
6115 GLsizei height
, GLsizei depth
,
6116 GLboolean fixedSampleLocations
,
6117 GLuint64 offset
, const char* func
)
6121 texture_image_multisample(ctx
, dims
, texObj
, memObj
, target
, samples
,
6122 internalFormat
, width
, height
, depth
,
6123 fixedSampleLocations
, GL_TRUE
, offset
,