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 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
)
854 target
= img
->TexObject
->Target
;
855 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
856 assert(img
->_BaseFormat
!= -1);
857 img
->InternalFormat
= internalFormat
;
858 img
->Border
= border
;
860 img
->Height
= height
;
863 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
864 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
868 case GL_TEXTURE_BUFFER
:
869 case GL_PROXY_TEXTURE_1D
:
881 case GL_TEXTURE_1D_ARRAY
:
882 case GL_PROXY_TEXTURE_1D_ARRAY
:
883 img
->Height2
= height
; /* no border */
884 img
->HeightLog2
= 0; /* not used */
892 case GL_TEXTURE_RECTANGLE
:
893 case GL_TEXTURE_CUBE_MAP
:
894 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
895 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
896 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
897 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
898 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
899 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
900 case GL_TEXTURE_EXTERNAL_OES
:
901 case GL_PROXY_TEXTURE_2D
:
902 case GL_PROXY_TEXTURE_RECTANGLE
:
903 case GL_PROXY_TEXTURE_CUBE_MAP
:
904 case GL_TEXTURE_2D_MULTISAMPLE
:
905 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
906 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
907 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
914 case GL_TEXTURE_2D_ARRAY
:
915 case GL_PROXY_TEXTURE_2D_ARRAY
:
916 case GL_TEXTURE_CUBE_MAP_ARRAY
:
917 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
918 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
919 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
920 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
921 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
922 img
->Depth2
= depth
; /* no border */
923 img
->DepthLog2
= 0; /* not used */
926 case GL_PROXY_TEXTURE_3D
:
927 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
928 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
929 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
930 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
933 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
938 _mesa_get_tex_max_num_levels(target
,
939 img
->Width2
, img
->Height2
, img
->Depth2
);
940 img
->TexFormat
= format
;
941 img
->NumSamples
= numSamples
;
942 img
->FixedSampleLocations
= fixedSampleLocations
;
947 _mesa_init_teximage_fields(struct gl_context
*ctx
,
948 struct gl_texture_image
*img
,
949 GLsizei width
, GLsizei height
, GLsizei depth
,
950 GLint border
, GLenum internalFormat
,
953 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
954 internalFormat
, format
, 0, GL_TRUE
);
959 * Free and clear fields of the gl_texture_image struct.
961 * \param ctx GL context.
962 * \param texImage texture image structure to be cleared.
964 * After the call, \p texImage will have no data associated with it. Its
965 * fields are cleared so that its parent object will test incomplete.
968 _mesa_clear_texture_image(struct gl_context
*ctx
,
969 struct gl_texture_image
*texImage
)
971 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
972 clear_teximage_fields(texImage
);
977 * Check the width, height, depth and border of a texture image are legal.
978 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
980 * The target and level parameters will have already been validated.
981 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
984 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
985 GLint level
, GLint width
, GLint height
,
986 GLint depth
, GLint border
)
992 case GL_PROXY_TEXTURE_1D
:
993 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
994 maxSize
>>= level
; /* level size */
995 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
997 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
998 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1004 case GL_PROXY_TEXTURE_2D
:
1005 case GL_TEXTURE_2D_MULTISAMPLE
:
1006 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1007 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1009 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1011 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1013 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1014 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1016 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1022 case GL_PROXY_TEXTURE_3D
:
1023 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1025 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1027 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1029 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1031 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1032 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1034 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1036 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1041 case GL_TEXTURE_RECTANGLE_NV
:
1042 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1045 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1046 if (width
< 0 || width
> maxSize
)
1048 if (height
< 0 || height
> maxSize
)
1052 case GL_TEXTURE_CUBE_MAP
:
1053 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1054 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1055 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1056 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1057 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1058 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1059 case GL_PROXY_TEXTURE_CUBE_MAP
:
1060 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1062 if (width
!= height
)
1064 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1066 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1068 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1069 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1071 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1076 case GL_TEXTURE_1D_ARRAY_EXT
:
1077 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1078 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1080 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1082 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1084 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1085 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1090 case GL_TEXTURE_2D_ARRAY_EXT
:
1091 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1092 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1093 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1094 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1096 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1098 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1100 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1102 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1103 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1105 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1110 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1111 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1112 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1113 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1115 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1117 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1119 if (width
!= height
)
1121 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1123 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1124 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1126 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1131 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1137 error_check_subtexture_negative_dimensions(struct gl_context
*ctx
,
1146 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width=%d)", func
, subWidth
);
1150 if (dims
> 1 && subHeight
< 0) {
1151 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height=%d)", func
, subHeight
);
1155 if (dims
> 2 && subDepth
< 0) {
1156 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(depth=%d)", func
, subDepth
);
1164 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1165 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1166 * \param destImage the destination texture image.
1167 * \return GL_TRUE if error found, GL_FALSE otherwise.
1170 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1171 const struct gl_texture_image
*destImage
,
1172 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1173 GLsizei subWidth
, GLsizei subHeight
,
1174 GLsizei subDepth
, const char *func
)
1176 const GLenum target
= destImage
->TexObject
->Target
;
1179 /* check xoffset and width */
1180 if (xoffset
< - (GLint
) destImage
->Border
) {
1181 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset)", func
);
1185 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1186 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset %d + width %d > %u)", func
,
1187 xoffset
, subWidth
, destImage
->Width
);
1191 /* check yoffset and height */
1193 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1194 if (yoffset
< -yBorder
) {
1195 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset)", func
);
1198 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1199 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset %d + height %d > %u)",
1200 func
, yoffset
, subHeight
, destImage
->Height
);
1205 /* check zoffset and depth */
1208 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1209 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1210 0 : destImage
->Border
;
1212 if (zoffset
< -zBorder
) {
1213 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset)", func
);
1217 depth
= (GLint
) destImage
->Depth
;
1218 if (target
== GL_TEXTURE_CUBE_MAP
)
1220 if (zoffset
+ subDepth
> depth
) {
1221 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset %d + depth %d > %u)",
1222 func
, zoffset
, subDepth
, depth
);
1228 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1229 * compressed texture images can be updated. But, that restriction may be
1230 * relaxed for particular compressed formats. At this time, all the
1231 * compressed formats supported by Mesa allow sub-textures to be updated
1232 * along compressed block boundaries.
1234 _mesa_get_format_block_size_3d(destImage
->TexFormat
, &bw
, &bh
, &bd
);
1236 if (bw
!= 1 || bh
!= 1 || bd
!= 1) {
1237 /* offset must be multiple of block size */
1238 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0) || (zoffset
% bd
!= 0)) {
1239 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1240 "%s(xoffset = %d, yoffset = %d, zoffset = %d)",
1241 func
, xoffset
, yoffset
, zoffset
);
1245 /* The size must be a multiple of bw x bh, or we must be using a
1246 * offset+size that exactly hits the edge of the image. This
1247 * is important for small mipmap levels (1x1, 2x1, etc) and for
1250 if ((subWidth
% bw
!= 0) &&
1251 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1252 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1253 "%s(width = %d)", func
, subWidth
);
1257 if ((subHeight
% bh
!= 0) &&
1258 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1259 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1260 "%s(height = %d)", func
, subHeight
);
1264 if ((subDepth
% bd
!= 0) &&
1265 (zoffset
+ subDepth
!= (GLint
) destImage
->Depth
)) {
1266 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1267 "%s(depth = %d)", func
, subDepth
);
1279 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1280 * specific texture image size checks.
1282 * A hardware driver might override this function if, for example, the
1283 * max 3D texture size is 512x512x64 (i.e. not a cube).
1285 * Note that width, height, depth == 0 is not an error. However, a
1286 * texture with zero width/height/depth will be considered "incomplete"
1287 * and texturing will effectively be disabled.
1289 * \param target any texture target/type
1290 * \param numLevels number of mipmap levels in the texture or 0 if not known
1291 * \param level as passed to glTexImage
1292 * \param format the MESA_FORMAT_x for the tex image
1293 * \param numSamples number of samples per texel
1294 * \param width as passed to glTexImage
1295 * \param height as passed to glTexImage
1296 * \param depth as passed to glTexImage
1297 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1300 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
,
1301 GLuint numLevels
, GLint level
,
1302 mesa_format format
, GLuint numSamples
,
1303 GLint width
, GLint height
, GLint depth
)
1305 uint64_t bytes
, mbytes
;
1307 if (numLevels
> 0) {
1308 /* Compute total memory for a whole mipmap. This is the path
1309 * taken for glTexStorage(GL_PROXY_TEXTURE_x).
1317 for (l
= 0; l
< numLevels
; l
++) {
1318 GLint nextWidth
, nextHeight
, nextDepth
;
1320 bytes
+= _mesa_format_image_size64(format
, width
, height
, depth
);
1322 if (_mesa_next_mipmap_level_size(target
, 0, width
, height
, depth
,
1323 &nextWidth
, &nextHeight
,
1326 height
= nextHeight
;
1333 /* We just compute the size of one mipmap level. This is the path
1334 * taken for glTexImage(GL_PROXY_TEXTURE_x).
1336 bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1339 bytes
*= _mesa_num_tex_faces(target
);
1340 bytes
*= MAX2(1, numSamples
);
1342 mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1344 /* We just check if the image size is less than MaxTextureMbytes.
1345 * Some drivers may do more specific checks.
1347 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1352 * Return true if the format is only valid for glCompressedTexImage.
1355 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1358 case GL_PALETTE4_RGB8_OES
:
1359 case GL_PALETTE4_RGBA8_OES
:
1360 case GL_PALETTE4_R5_G6_B5_OES
:
1361 case GL_PALETTE4_RGBA4_OES
:
1362 case GL_PALETTE4_RGB5_A1_OES
:
1363 case GL_PALETTE8_RGB8_OES
:
1364 case GL_PALETTE8_RGBA8_OES
:
1365 case GL_PALETTE8_R5_G6_B5_OES
:
1366 case GL_PALETTE8_RGBA4_OES
:
1367 case GL_PALETTE8_RGB5_A1_OES
:
1375 * Return true if the format doesn't support online compression.
1378 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
)
1380 return _mesa_is_astc_format(format
) ||
1381 _mesa_is_etc2_format(format
) ||
1382 compressedteximage_only_format(ctx
, format
);
1385 /* Writes to an GL error pointer if non-null and returns whether or not the
1386 * error is GL_NO_ERROR */
1388 write_error(GLenum
*err_ptr
, GLenum error
)
1393 return error
== GL_NO_ERROR
;
1397 * Helper function to determine whether a target and specific compression
1398 * format are supported. The error parameter returns GL_NO_ERROR if the
1399 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1400 * or GL_INVALID_ENUM, whichever is more appropriate.
1403 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1404 GLenum intFormat
, GLenum
*error
)
1406 GLboolean target_can_be_compresed
= GL_FALSE
;
1407 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1408 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1412 case GL_PROXY_TEXTURE_2D
:
1413 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1415 case GL_PROXY_TEXTURE_CUBE_MAP
:
1416 case GL_TEXTURE_CUBE_MAP
:
1417 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1418 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1419 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1420 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1421 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1422 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1423 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1425 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1426 case GL_TEXTURE_2D_ARRAY_EXT
:
1427 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1429 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1430 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1431 /* From the KHR_texture_compression_astc_hdr spec:
1433 * Add a second new column "3D Tex." which is empty for all non-ASTC
1434 * formats. If only the LDR profile is supported by the
1435 * implementation, this column is also empty for all ASTC formats. If
1436 * both the LDR and HDR profiles are supported only, this column is
1437 * checked for all ASTC formats.
1439 * Add a third new column "Cube Map Array Tex." which is empty for all
1440 * non-ASTC formats, and checked for all ASTC formats.
1444 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1445 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1446 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1447 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1448 * 8.19 is *not* checked'
1450 * The instances of <internalformat> above should say <target>.
1452 * ETC2/EAC formats are the only alternative in GLES and thus such errors
1453 * have already been handled by normal ETC2/EAC behavior.
1456 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1458 * "The ETC2/EAC texture compression algorithm supports only
1459 * two-dimensional images. If internalformat is an ETC2/EAC format,
1460 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1461 * target is not TEXTURE_2D_ARRAY."
1463 * This should also be applicable for glTexStorage3D(). Other available
1464 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1466 * Section 8.7, page 179 of OpenGL ES 3.2 adds:
1468 * An INVALID_OPERATION error is generated by CompressedTexImage3D
1469 * if internalformat is one of the the formats in table 8.17 and target is
1470 * not TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY or TEXTURE_3D.
1472 * An INVALID_OPERATION error is generated by CompressedTexImage3D
1473 * if internalformat is TEXTURE_CUBE_MAP_ARRAY and the “Cube Map
1474 * Array” column of table 8.17 is not checked, or if internalformat
1475 * is TEXTURE_- 3D and the “3D Tex.” column of table 8.17 is not
1478 * The instances of <internalformat> above should say <target>.
1480 * Such table 8.17 has checked "Cube Map Array" column for all the
1481 * cases. So in practice, TEXTURE_CUBE_MAP_ARRAY is now valid for OpenGL ES 3.2
1483 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
) &&
1484 !_mesa_is_gles32(ctx
))
1485 return write_error(error
, GL_INVALID_OPERATION
);
1486 target_can_be_compresed
= _mesa_has_texture_cube_map_array(ctx
);
1490 case MESA_FORMAT_LAYOUT_ETC2
:
1491 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1492 if (_mesa_is_gles3(ctx
))
1493 return write_error(error
, GL_INVALID_OPERATION
);
1495 case MESA_FORMAT_LAYOUT_BPTC
:
1496 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1498 case MESA_FORMAT_LAYOUT_ASTC
:
1499 target_can_be_compresed
=
1500 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
1501 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
1503 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1504 * neither of the above extensions are supported. See comment in
1505 * switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1507 if (!target_can_be_compresed
)
1508 return write_error(error
, GL_INVALID_OPERATION
);
1516 return write_error(error
,
1517 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1522 * Check if the given texture target value is legal for a
1523 * glTexImage1/2/3D call.
1526 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1532 case GL_PROXY_TEXTURE_1D
:
1533 return _mesa_is_desktop_gl(ctx
);
1541 case GL_PROXY_TEXTURE_2D
:
1542 return _mesa_is_desktop_gl(ctx
);
1543 case GL_PROXY_TEXTURE_CUBE_MAP
:
1544 return _mesa_is_desktop_gl(ctx
)
1545 && ctx
->Extensions
.ARB_texture_cube_map
;
1546 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1547 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1548 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1549 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1550 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1551 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1552 return ctx
->Extensions
.ARB_texture_cube_map
;
1553 case GL_TEXTURE_RECTANGLE_NV
:
1554 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1555 return _mesa_is_desktop_gl(ctx
)
1556 && ctx
->Extensions
.NV_texture_rectangle
;
1557 case GL_TEXTURE_1D_ARRAY_EXT
:
1558 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1559 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1567 case GL_PROXY_TEXTURE_3D
:
1568 return _mesa_is_desktop_gl(ctx
);
1569 case GL_TEXTURE_2D_ARRAY_EXT
:
1570 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1571 || _mesa_is_gles3(ctx
);
1572 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1573 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1574 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1575 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1576 return _mesa_has_texture_cube_map_array(ctx
);
1581 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1588 * Check if the given texture target value is legal for a
1589 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1590 * The difference compared to legal_teximage_target() above is that
1591 * proxy targets are not supported.
1594 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1599 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1604 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1605 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1606 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1607 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1608 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1609 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1610 return ctx
->Extensions
.ARB_texture_cube_map
;
1611 case GL_TEXTURE_RECTANGLE_NV
:
1612 return _mesa_is_desktop_gl(ctx
)
1613 && ctx
->Extensions
.NV_texture_rectangle
;
1614 case GL_TEXTURE_1D_ARRAY_EXT
:
1615 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1623 case GL_TEXTURE_2D_ARRAY_EXT
:
1624 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1625 || _mesa_is_gles3(ctx
);
1626 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1627 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1628 return _mesa_has_texture_cube_map_array(ctx
);
1630 /* Table 8.15 of the OpenGL 4.5 core profile spec
1631 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1632 * and CopyTextureSubImage3D.
1634 case GL_TEXTURE_CUBE_MAP
:
1640 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1648 * Helper function to determine if a texture object is mutable (in terms
1649 * of GL_ARB_texture_storage/GL_ARB_bindless_texture).
1652 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1654 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1658 if (texObj
->HandleAllocated
) {
1659 /* The ARB_bindless_texture spec says:
1661 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
1662 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
1663 * functions defined in terms of these, if the texture object to be
1664 * modified is referenced by one or more texture or image handles."
1669 return !texObj
->Immutable
;
1674 * Return expected size of a compressed texture.
1677 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1680 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1681 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1685 * Verify that a texture format is valid with a particular target
1687 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1688 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1691 * \param ctx GL context
1692 * \param target Texture target
1693 * \param internalFormat Internal format of the texture image
1695 * \returns true if the combination is legal, false otherwise.
1698 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1699 GLenum target
, GLenum internalFormat
)
1701 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1702 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
1703 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
1704 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1705 * Profile spec says:
1707 * "Textures with a base internal format of DEPTH_COMPONENT or
1708 * DEPTH_STENCIL are supported by texture image specification
1709 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1710 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1711 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1712 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1713 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1714 * formats in conjunction with any other target will result in an
1715 * INVALID_OPERATION error."
1717 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1718 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1720 if (target
!= GL_TEXTURE_1D
&&
1721 target
!= GL_PROXY_TEXTURE_1D
&&
1722 target
!= GL_TEXTURE_2D
&&
1723 target
!= GL_PROXY_TEXTURE_2D
&&
1724 target
!= GL_TEXTURE_1D_ARRAY
&&
1725 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1726 target
!= GL_TEXTURE_2D_ARRAY
&&
1727 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1728 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1729 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1730 !((_mesa_is_cube_face(target
) ||
1731 target
== GL_TEXTURE_CUBE_MAP
||
1732 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1733 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
1734 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
1735 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
1736 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
1737 _mesa_has_texture_cube_map_array(ctx
))) {
1746 texture_formats_agree(GLenum internalFormat
,
1749 GLboolean colorFormat
;
1750 GLboolean is_format_depth_or_depthstencil
;
1751 GLboolean is_internalFormat_depth_or_depthstencil
;
1753 /* Even though there are no color-index textures, we still have to support
1754 * uploading color-index data and remapping it to RGB via the
1755 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1757 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1759 is_internalFormat_depth_or_depthstencil
=
1760 _mesa_is_depth_format(internalFormat
) ||
1761 _mesa_is_depthstencil_format(internalFormat
);
1763 is_format_depth_or_depthstencil
=
1764 _mesa_is_depth_format(format
) ||
1765 _mesa_is_depthstencil_format(format
);
1767 colorFormat
= _mesa_is_color_format(format
);
1769 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
1772 if (is_internalFormat_depth_or_depthstencil
!=
1773 is_format_depth_or_depthstencil
)
1776 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
1783 * Test the combination of format, type and internal format arguments of
1784 * different texture operations on GLES.
1786 * \param ctx GL context.
1787 * \param format pixel data format given by the user.
1788 * \param type pixel data type given by the user.
1789 * \param internalFormat internal format given by the user.
1790 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1791 * \param callerName name of the caller function to print in the error message
1793 * \return true if a error is found, false otherwise
1795 * Currently, it is used by texture_error_check() and texsubimage_error_check().
1798 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
1799 GLenum type
, GLenum internalFormat
,
1800 GLuint dimensions
, const char *callerName
)
1802 GLenum err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
1804 if (err
!= GL_NO_ERROR
) {
1805 _mesa_error(ctx
, err
,
1806 "%s(format = %s, type = %s, internalformat = %s)",
1807 callerName
, _mesa_enum_to_string(format
),
1808 _mesa_enum_to_string(type
),
1809 _mesa_enum_to_string(internalFormat
));
1817 * Test the glTexImage[123]D() parameters for errors.
1819 * \param ctx GL context.
1820 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1821 * \param target texture target given by the user (already validated).
1822 * \param level image level given by the user.
1823 * \param internalFormat internal format given by the user.
1824 * \param format pixel data format given by the user.
1825 * \param type pixel data type given by the user.
1826 * \param width image width given by the user.
1827 * \param height image height given by the user.
1828 * \param depth image depth given by the user.
1829 * \param border image border given by the user.
1831 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1833 * Verifies each of the parameters against the constants specified in
1834 * __struct gl_contextRec::Const and the supported extensions, and according
1835 * to the OpenGL specification.
1836 * Note that we don't fully error-check the width, height, depth values
1837 * here. That's done in _mesa_legal_texture_dimensions() which is used
1838 * by several other GL entrypoints. Plus, texture dims have a special
1839 * interaction with proxy textures.
1842 texture_error_check( struct gl_context
*ctx
,
1843 GLuint dimensions
, GLenum target
,
1844 GLint level
, GLint internalFormat
,
1845 GLenum format
, GLenum type
,
1846 GLint width
, GLint height
,
1847 GLint depth
, GLint border
,
1848 const GLvoid
*pixels
)
1852 /* Note: for proxy textures, some error conditions immediately generate
1853 * a GL error in the usual way. But others do not generate a GL error.
1854 * Instead, they cause the width, height, depth, format fields of the
1855 * texture image to be zeroed-out. The GL spec seems to indicate that the
1856 * zero-out behaviour is only used in cases related to memory allocation.
1860 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1861 _mesa_error(ctx
, GL_INVALID_VALUE
,
1862 "glTexImage%dD(level=%d)", dimensions
, level
);
1867 if (border
< 0 || border
> 1 ||
1868 ((ctx
->API
!= API_OPENGL_COMPAT
||
1869 target
== GL_TEXTURE_RECTANGLE_NV
||
1870 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1871 _mesa_error(ctx
, GL_INVALID_VALUE
,
1872 "glTexImage%dD(border=%d)", dimensions
, border
);
1876 if (width
< 0 || height
< 0 || depth
< 0) {
1877 _mesa_error(ctx
, GL_INVALID_VALUE
,
1878 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1882 /* Check incoming image format and type */
1883 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1884 if (err
!= GL_NO_ERROR
) {
1885 /* Prior to OpenGL-ES 2.0, an INVALID_VALUE is expected instead of
1886 * INVALID_ENUM. From page 73 OpenGL ES 1.1 spec:
1888 * "Specifying a value for internalformat that is not one of the
1889 * above (acceptable) values generates the error INVALID VALUE."
1891 if (err
== GL_INVALID_ENUM
&& _mesa_is_gles(ctx
) && ctx
->Version
< 20)
1892 err
= GL_INVALID_VALUE
;
1894 _mesa_error(ctx
, err
,
1895 "glTexImage%dD(incompatible format = %s, type = %s)",
1896 dimensions
, _mesa_enum_to_string(format
),
1897 _mesa_enum_to_string(type
));
1901 /* Check internalFormat */
1902 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1903 _mesa_error(ctx
, GL_INVALID_VALUE
,
1904 "glTexImage%dD(internalFormat=%s)",
1905 dimensions
, _mesa_enum_to_string(internalFormat
));
1909 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1910 * combinations of format, internalFormat, and type that can be used.
1911 * Formats and types that require additional extensions (e.g., GL_FLOAT
1912 * requires GL_OES_texture_float) are filtered elsewhere.
1914 if (_mesa_is_gles(ctx
) &&
1915 texture_format_error_check_gles(ctx
, format
, type
, internalFormat
,
1916 dimensions
, "glTexImage%dD")) {
1920 /* validate the bound PBO, if any */
1921 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
1922 width
, height
, depth
, format
, type
,
1923 INT_MAX
, pixels
, "glTexImage")) {
1927 /* make sure internal format and format basically agree */
1928 if (!texture_formats_agree(internalFormat
, format
)) {
1929 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1930 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
1931 dimensions
, _mesa_enum_to_string(internalFormat
),
1932 _mesa_enum_to_string(format
));
1936 /* additional checks for ycbcr textures */
1937 if (internalFormat
== GL_YCBCR_MESA
) {
1938 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
1939 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1940 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1942 _mesa_snprintf(message
, sizeof(message
),
1943 "glTexImage%dD(format/type YCBCR mismatch)",
1945 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1946 return GL_TRUE
; /* error */
1948 if (target
!= GL_TEXTURE_2D
&&
1949 target
!= GL_PROXY_TEXTURE_2D
&&
1950 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1951 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1952 _mesa_error(ctx
, GL_INVALID_ENUM
,
1953 "glTexImage%dD(bad target for YCbCr texture)",
1959 _mesa_snprintf(message
, sizeof(message
),
1960 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1961 dimensions
, border
);
1962 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1967 /* additional checks for depth textures */
1968 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
)) {
1969 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1970 "glTexImage%dD(bad target for texture)", dimensions
);
1974 /* additional checks for compressed textures */
1975 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1977 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
1978 _mesa_error(ctx
, err
,
1979 "glTexImage%dD(target can't be compressed)", dimensions
);
1982 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
1983 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1984 "glTexImage%dD(no compression for format)", dimensions
);
1988 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1989 "glTexImage%dD(border!=0)", dimensions
);
1994 /* additional checks for integer textures */
1995 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1996 (_mesa_is_enum_format_integer(format
) !=
1997 _mesa_is_enum_format_integer(internalFormat
))) {
1998 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1999 "glTexImage%dD(integer/non-integer format mismatch)",
2004 if (!mutable_tex_object(ctx
, target
)) {
2005 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2006 "glTexImage%dD(immutable texture)", dimensions
);
2010 /* if we get here, the parameters are OK */
2016 * Error checking for glCompressedTexImage[123]D().
2017 * Note that the width, height and depth values are not fully error checked
2019 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2022 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2023 GLenum target
, GLint level
,
2024 GLenum internalFormat
, GLsizei width
,
2025 GLsizei height
, GLsizei depth
, GLint border
,
2026 GLsizei imageSize
, const GLvoid
*data
)
2028 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2030 GLenum error
= GL_NO_ERROR
;
2031 char *reason
= ""; /* no error */
2033 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
2038 /* This will detect any invalid internalFormat value */
2039 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2040 _mesa_error(ctx
, GL_INVALID_ENUM
,
2041 "glCompressedTexImage%dD(internalFormat=%s)",
2042 dimensions
, _mesa_enum_to_string(internalFormat
));
2046 /* validate the bound PBO, if any */
2047 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2049 "glCompressedTexImage")) {
2053 switch (internalFormat
) {
2054 case GL_PALETTE4_RGB8_OES
:
2055 case GL_PALETTE4_RGBA8_OES
:
2056 case GL_PALETTE4_R5_G6_B5_OES
:
2057 case GL_PALETTE4_RGBA4_OES
:
2058 case GL_PALETTE4_RGB5_A1_OES
:
2059 case GL_PALETTE8_RGB8_OES
:
2060 case GL_PALETTE8_RGBA8_OES
:
2061 case GL_PALETTE8_R5_G6_B5_OES
:
2062 case GL_PALETTE8_RGBA4_OES
:
2063 case GL_PALETTE8_RGB5_A1_OES
:
2064 /* check level (note that level should be zero or less!) */
2065 if (level
> 0 || level
< -maxLevels
) {
2067 error
= GL_INVALID_VALUE
;
2071 if (dimensions
!= 2) {
2072 reason
= "compressed paletted textures must be 2D";
2073 error
= GL_INVALID_OPERATION
;
2077 /* Figure out the expected texture size (in bytes). This will be
2078 * checked against the actual size later.
2080 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2083 /* This is for the benefit of the TestProxyTexImage below. It expects
2084 * level to be non-negative. OES_compressed_paletted_texture uses a
2085 * weird mechanism where the level specified to glCompressedTexImage2D
2086 * is -(n-1) number of levels in the texture, and the data specifies the
2087 * complete mipmap stack. This is done to ensure the palette is the
2088 * same for all levels.
2095 if (level
< 0 || level
>= maxLevels
) {
2097 error
= GL_INVALID_VALUE
;
2101 /* Figure out the expected texture size (in bytes). This will be
2102 * checked against the actual size later.
2104 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2108 /* This should really never fail */
2109 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2110 reason
= "internalFormat";
2111 error
= GL_INVALID_ENUM
;
2115 /* No compressed formats support borders at this time */
2117 reason
= "border != 0";
2118 error
= GL_INVALID_VALUE
;
2122 /* Check for invalid pixel storage modes */
2123 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2125 "glCompressedTexImage")) {
2129 /* check image size in bytes */
2130 if (expectedSize
!= imageSize
) {
2131 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2132 * if <imageSize> is not consistent with the format, dimensions, and
2133 * contents of the specified image.
2135 reason
= "imageSize inconsistent with width/height/format";
2136 error
= GL_INVALID_VALUE
;
2140 if (!mutable_tex_object(ctx
, target
)) {
2141 reason
= "immutable texture";
2142 error
= GL_INVALID_OPERATION
;
2149 /* Note: not all error paths exit through here. */
2150 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2151 dimensions
, reason
);
2158 * Test glTexSubImage[123]D() parameters for errors.
2160 * \param ctx GL context.
2161 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2162 * \param target texture target given by the user (already validated)
2163 * \param level image level given by the user.
2164 * \param xoffset sub-image x offset given by the user.
2165 * \param yoffset sub-image y offset given by the user.
2166 * \param zoffset sub-image z offset given by the user.
2167 * \param format pixel data format given by the user.
2168 * \param type pixel data type given by the user.
2169 * \param width image width given by the user.
2170 * \param height image height given by the user.
2171 * \param depth image depth given by the user.
2173 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2175 * Verifies each of the parameters against the constants specified in
2176 * __struct gl_contextRec::Const and the supported extensions, and according
2177 * to the OpenGL specification.
2180 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2181 struct gl_texture_object
*texObj
,
2182 GLenum target
, GLint level
,
2183 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2184 GLint width
, GLint height
, GLint depth
,
2185 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2186 bool dsa
, const char *callerName
)
2188 struct gl_texture_image
*texImage
;
2192 /* must be out of memory */
2193 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2198 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2199 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2203 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2204 width
, height
, depth
,
2209 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2211 /* non-existant texture level */
2212 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture level %d)",
2217 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2218 if (err
!= GL_NO_ERROR
) {
2219 _mesa_error(ctx
, err
,
2220 "%s(incompatible format = %s, type = %s)",
2221 callerName
, _mesa_enum_to_string(format
),
2222 _mesa_enum_to_string(type
));
2226 GLenum internalFormat
= _mesa_is_gles(ctx
) ?
2227 oes_float_internal_format(ctx
, texImage
->InternalFormat
, type
) :
2228 texImage
->InternalFormat
;
2230 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2231 * combinations of format, internalFormat, and type that can be used.
2232 * Formats and types that require additional extensions (e.g., GL_FLOAT
2233 * requires GL_OES_texture_float) are filtered elsewhere.
2235 if (_mesa_is_gles(ctx
) &&
2236 texture_format_error_check_gles(ctx
, format
, type
,
2238 dimensions
, callerName
)) {
2242 /* validate the bound PBO, if any */
2243 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2244 width
, height
, depth
, format
, type
,
2245 INT_MAX
, pixels
, callerName
)) {
2249 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2250 texImage
, xoffset
, yoffset
, zoffset
,
2251 width
, height
, depth
, callerName
)) {
2255 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2256 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2257 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2258 "%s(no compression for format)", callerName
);
2263 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2264 /* both source and dest must be integer-valued, or neither */
2265 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2266 _mesa_is_enum_format_integer(format
)) {
2267 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2268 "%s(integer/non-integer format mismatch)", callerName
);
2278 * Test glCopyTexImage[12]D() parameters for errors.
2280 * \param ctx GL context.
2281 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2282 * \param target texture target given by the user.
2283 * \param level image level given by the user.
2284 * \param internalFormat internal format given by the user.
2285 * \param width image width given by the user.
2286 * \param height image height given by the user.
2287 * \param border texture border.
2289 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2291 * Verifies each of the parameters against the constants specified in
2292 * __struct gl_contextRec::Const and the supported extensions, and according
2293 * to the OpenGL specification.
2296 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2297 GLenum target
, GLint level
, GLint internalFormat
,
2298 GLint width
, GLint height
, GLint border
)
2301 GLint rb_base_format
;
2302 struct gl_renderbuffer
*rb
;
2303 GLenum rb_internal_format
;
2306 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2307 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2308 dimensions
, _mesa_enum_to_string(target
));
2313 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2314 _mesa_error(ctx
, GL_INVALID_VALUE
,
2315 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2319 /* Check that the source buffer is complete */
2320 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2321 if (ctx
->ReadBuffer
->_Status
== 0) {
2322 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2324 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2325 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2326 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2330 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2331 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2332 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2338 if (border
< 0 || border
> 1 ||
2339 ((ctx
->API
!= API_OPENGL_COMPAT
||
2340 target
== GL_TEXTURE_RECTANGLE_NV
||
2341 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2342 _mesa_error(ctx
, GL_INVALID_VALUE
,
2343 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2347 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2350 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2351 switch (internalFormat
) {
2356 case GL_LUMINANCE_ALPHA
:
2359 _mesa_error(ctx
, GL_INVALID_ENUM
,
2360 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2361 _mesa_enum_to_string(internalFormat
));
2366 * Section 8.6 (Alternate Texture Image Specification Commands) of the
2367 * OpenGL 4.5 (Compatibility Profile) spec says:
2369 * "Parameters level, internalformat, and border are specified using
2370 * the same values, with the same meanings, as the corresponding
2371 * arguments of TexImage2D, except that internalformat may not be
2372 * specified as 1, 2, 3, or 4."
2374 if (internalFormat
>= 1 && internalFormat
<= 4) {
2375 _mesa_error(ctx
, GL_INVALID_ENUM
,
2376 "glCopyTexImage%dD(internalFormat=%d)", dimensions
,
2382 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2383 if (baseFormat
< 0) {
2384 _mesa_error(ctx
, GL_INVALID_ENUM
,
2385 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2386 _mesa_enum_to_string(internalFormat
));
2390 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2392 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2393 "glCopyTexImage%dD(read buffer)", dimensions
);
2397 rb_internal_format
= rb
->InternalFormat
;
2398 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2399 if (_mesa_is_color_format(internalFormat
)) {
2400 if (rb_base_format
< 0) {
2401 _mesa_error(ctx
, GL_INVALID_VALUE
,
2402 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2403 _mesa_enum_to_string(internalFormat
));
2408 if (_mesa_is_gles(ctx
)) {
2410 if (_mesa_base_format_component_count(baseFormat
) >
2411 _mesa_base_format_component_count(rb_base_format
)) {
2414 if (baseFormat
== GL_DEPTH_COMPONENT
||
2415 baseFormat
== GL_DEPTH_STENCIL
||
2416 baseFormat
== GL_STENCIL_INDEX
||
2417 rb_base_format
== GL_DEPTH_COMPONENT
||
2418 rb_base_format
== GL_DEPTH_STENCIL
||
2419 rb_base_format
== GL_STENCIL_INDEX
||
2420 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2421 baseFormat
== GL_ALPHA
) &&
2422 rb_base_format
!= GL_RGBA
) ||
2423 internalFormat
== GL_RGB9_E5
) {
2426 if (internalFormat
== GL_RGB9_E5
) {
2430 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2431 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2432 _mesa_enum_to_string(internalFormat
));
2437 if (_mesa_is_gles3(ctx
)) {
2438 bool rb_is_srgb
= false;
2439 bool dst_is_srgb
= false;
2441 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2442 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2446 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2450 if (rb_is_srgb
!= dst_is_srgb
) {
2451 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2452 * OpenGLES 3.0.0 spec says:
2454 * "The error INVALID_OPERATION is also generated if the
2455 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2456 * framebuffer attachment corresponding to the read buffer
2457 * is LINEAR (see section 6.1.13) and internalformat is
2458 * one of the sRGB formats described in section 3.8.16, or
2459 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2460 * SRGB and internalformat is not one of the sRGB formats."
2462 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2463 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2467 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2468 * types for SNORM formats. Also, conversion to SNORM formats is not
2469 * allowed by Table 3.2 on Page 110.
2471 if (_mesa_is_enum_format_snorm(internalFormat
)) {
2472 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2473 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2474 _mesa_enum_to_string(internalFormat
));
2479 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2480 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2481 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2485 /* From the EXT_texture_integer spec:
2487 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2488 * if the texture internalformat is an integer format and the read color
2489 * buffer is not an integer format, or if the internalformat is not an
2490 * integer format and the read color buffer is an integer format."
2492 if (_mesa_is_color_format(internalFormat
)) {
2493 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2494 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2495 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2496 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2497 if (is_int
|| is_rbint
) {
2498 if (is_int
!= is_rbint
) {
2499 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2500 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2502 } else if (_mesa_is_gles(ctx
) &&
2503 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2504 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2505 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2506 "glCopyTexImage%dD(signed vs unsigned integer)",
2512 /* From page 138 of OpenGL ES 3.0 spec:
2513 * "The error INVALID_OPERATION is generated if floating-point RGBA
2514 * data is required; if signed integer RGBA data is required and the
2515 * format of the current color buffer is not signed integer; if
2516 * unsigned integer RGBA data is required and the format of the
2517 * current color buffer is not unsigned integer; or if fixed-point
2518 * RGBA data is required and the format of the current color buffer
2519 * is not fixed-point.
2521 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2522 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2523 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2526 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2528 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2529 _mesa_error(ctx
, err
,
2530 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2533 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2534 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2535 "glCopyTexImage%dD(no compression for format)", dimensions
);
2539 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2540 "glCopyTexImage%dD(border!=0)", dimensions
);
2545 if (!mutable_tex_object(ctx
, target
)) {
2546 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2547 "glCopyTexImage%dD(immutable texture)", dimensions
);
2551 /* if we get here, the parameters are OK */
2557 * Test glCopyTexSubImage[12]D() parameters for errors.
2558 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2561 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2562 const struct gl_texture_object
*texObj
,
2563 GLenum target
, GLint level
,
2564 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2565 GLint width
, GLint height
, const char *caller
)
2569 struct gl_texture_image
*texImage
;
2571 /* Check that the source buffer is complete */
2572 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2573 if (ctx
->ReadBuffer
->_Status
== 0) {
2574 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2576 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2577 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2578 "%s(invalid readbuffer)", caller
);
2582 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2583 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2584 "%s(multisample FBO)", caller
);
2590 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2591 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2595 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2597 /* destination image does not exist */
2598 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2599 "%s(invalid texture level %d)", caller
, level
);
2603 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2604 width
, height
, 1, caller
)) {
2608 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2609 xoffset
, yoffset
, zoffset
,
2610 width
, height
, 1, caller
)) {
2614 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2615 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2616 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2617 "%s(no compression for format)", caller
);
2622 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2623 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2627 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2628 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2629 "%s(missing readbuffer, format=%s)", caller
,
2630 _mesa_enum_to_string(texImage
->_BaseFormat
));
2634 /* From the EXT_texture_integer spec:
2636 * "INVALID_OPERATION is generated by CopyTexImage* and
2637 * CopyTexSubImage* if the texture internalformat is an integer format
2638 * and the read color buffer is not an integer format, or if the
2639 * internalformat is not an integer format and the read color buffer
2640 * is an integer format."
2642 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2643 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2645 if (_mesa_is_format_integer_color(rb
->Format
) !=
2646 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2647 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2648 "%s(integer vs non-integer)", caller
);
2653 /* In the ES 3.2 specification's Table 8.13 (Valid CopyTexImage source
2654 * framebuffer/destination texture base internal format combinations),
2655 * all the entries for stencil are left blank (unsupported).
2657 if (_mesa_is_gles(ctx
) && _mesa_is_stencil_format(texImage
->_BaseFormat
)) {
2658 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(stencil disallowed)", caller
);
2662 /* if we get here, the parameters are OK */
2667 /** Callback info for walking over FBO hash table */
2670 struct gl_context
*ctx
;
2671 struct gl_texture_object
*texObj
;
2677 * Check render to texture callback. Called from _mesa_HashWalk().
2680 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2682 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2683 const struct cb_info
*info
= (struct cb_info
*) userData
;
2684 struct gl_context
*ctx
= info
->ctx
;
2685 const struct gl_texture_object
*texObj
= info
->texObj
;
2686 const GLuint level
= info
->level
, face
= info
->face
;
2688 /* If this is a user-created FBO */
2689 if (_mesa_is_user_fbo(fb
)) {
2691 /* check if any of the FBO's attachments point to 'texObj' */
2692 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2693 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2694 if (att
->Type
== GL_TEXTURE
&&
2695 att
->Texture
== texObj
&&
2696 att
->TextureLevel
== level
&&
2697 att
->CubeMapFace
== face
) {
2698 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
2699 assert(att
->Renderbuffer
->TexImage
);
2700 /* Mark fb status as indeterminate to force re-validation */
2703 /* Make sure that the revalidation actually happens if this is
2704 * being done to currently-bound buffers.
2706 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
)
2707 ctx
->NewState
|= _NEW_BUFFERS
;
2715 * When a texture image is specified we have to check if it's bound to
2716 * any framebuffer objects (render to texture) in order to detect changes
2717 * in size or format since that effects FBO completeness.
2718 * Any FBOs rendering into the texture must be re-validated.
2721 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2722 struct gl_texture_object
*texObj
,
2723 GLuint face
, GLuint level
)
2725 /* Only check this texture if it's been marked as RenderToTexture */
2726 if (texObj
->_RenderToTexture
) {
2727 struct cb_info info
;
2729 info
.texObj
= texObj
;
2732 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2738 * If the texture object's GenerateMipmap flag is set and we've
2739 * changed the texture base level image, regenerate the rest of the
2740 * mipmap levels now.
2743 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2744 struct gl_texture_object
*texObj
, GLint level
)
2746 if (texObj
->GenerateMipmap
&&
2747 level
== texObj
->BaseLevel
&&
2748 level
< texObj
->MaxLevel
) {
2749 assert(ctx
->Driver
.GenerateMipmap
);
2750 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2755 /** Debug helper: override the user-requested internal format */
2757 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2760 if (internalFormat
== GL_RGBA16F_ARB
||
2761 internalFormat
== GL_RGBA32F_ARB
) {
2762 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2765 else if (internalFormat
== GL_RGB16F_ARB
||
2766 internalFormat
== GL_RGB32F_ARB
) {
2767 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2770 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2771 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2772 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2773 return GL_LUMINANCE_ALPHA
;
2775 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2776 internalFormat
== GL_LUMINANCE32F_ARB
) {
2777 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2778 return GL_LUMINANCE
;
2780 else if (internalFormat
== GL_ALPHA16F_ARB
||
2781 internalFormat
== GL_ALPHA32F_ARB
) {
2782 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2786 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2787 internalFormat = GL_RGBA;
2791 return internalFormat
;
2794 return internalFormat
;
2800 * Choose the actual hardware format for a texture image.
2801 * Try to use the same format as the previous image level when possible.
2802 * Otherwise, ask the driver for the best format.
2803 * It's important to try to choose a consistant format for all levels
2804 * for efficient texture memory layout/allocation. In particular, this
2805 * comes up during automatic mipmap generation.
2808 _mesa_choose_texture_format(struct gl_context
*ctx
,
2809 struct gl_texture_object
*texObj
,
2810 GLenum target
, GLint level
,
2811 GLenum internalFormat
, GLenum format
, GLenum type
)
2815 /* see if we've already chosen a format for the previous level */
2817 struct gl_texture_image
*prevImage
=
2818 _mesa_select_tex_image(texObj
, target
, level
- 1);
2819 /* See if the prev level is defined and has an internal format which
2820 * matches the new internal format.
2823 prevImage
->Width
> 0 &&
2824 prevImage
->InternalFormat
== internalFormat
) {
2825 /* use the same format */
2826 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2827 return prevImage
->TexFormat
;
2831 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
2833 assert(f
!= MESA_FORMAT_NONE
);
2839 * Adjust pixel unpack params and image dimensions to strip off the
2840 * one-pixel texture border.
2842 * Gallium and intel don't support texture borders. They've seldem been used
2843 * and seldom been implemented correctly anyway.
2845 * \param unpackNew returns the new pixel unpack parameters
2848 strip_texture_border(GLenum target
,
2849 GLint
*width
, GLint
*height
, GLint
*depth
,
2850 const struct gl_pixelstore_attrib
*unpack
,
2851 struct gl_pixelstore_attrib
*unpackNew
)
2857 *unpackNew
= *unpack
;
2859 if (unpackNew
->RowLength
== 0)
2860 unpackNew
->RowLength
= *width
;
2862 if (unpackNew
->ImageHeight
== 0)
2863 unpackNew
->ImageHeight
= *height
;
2865 assert(*width
>= 3);
2866 unpackNew
->SkipPixels
++; /* skip the border */
2867 *width
= *width
- 2; /* reduce the width by two border pixels */
2869 /* The min height of a texture with a border is 3 */
2870 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2871 unpackNew
->SkipRows
++; /* skip the border */
2872 *height
= *height
- 2; /* reduce the height by two border pixels */
2876 target
!= GL_TEXTURE_2D_ARRAY
&&
2877 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2878 unpackNew
->SkipImages
++; /* skip the border */
2879 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2885 * Common code to implement all the glTexImage1D/2D/3D functions
2886 * as well as glCompressedTexImage1D/2D/3D.
2887 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2888 * \param format the user's image format (only used if !compressed)
2889 * \param type the user's image type (only used if !compressed)
2890 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2892 static ALWAYS_INLINE
void
2893 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2894 GLenum target
, GLint level
, GLint internalFormat
,
2895 GLsizei width
, GLsizei height
, GLsizei depth
,
2896 GLint border
, GLenum format
, GLenum type
,
2897 GLsizei imageSize
, const GLvoid
*pixels
, bool no_error
)
2899 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2900 struct gl_pixelstore_attrib unpack_no_border
;
2901 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2902 struct gl_texture_object
*texObj
;
2903 mesa_format texFormat
;
2904 bool dimensionsOK
= true, sizeOK
= true;
2906 FLUSH_VERTICES(ctx
, 0);
2908 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2911 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2913 _mesa_enum_to_string(target
), level
,
2914 _mesa_enum_to_string(internalFormat
),
2915 width
, height
, depth
, border
, pixels
);
2918 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2920 _mesa_enum_to_string(target
), level
,
2921 _mesa_enum_to_string(internalFormat
),
2922 width
, height
, depth
, border
,
2923 _mesa_enum_to_string(format
),
2924 _mesa_enum_to_string(type
), pixels
);
2927 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2930 /* target error checking */
2931 if (!legal_teximage_target(ctx
, dims
, target
)) {
2932 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2933 func
, dims
, _mesa_enum_to_string(target
));
2937 /* general error checking */
2939 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2941 width
, height
, depth
,
2942 border
, imageSize
, pixels
))
2945 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2946 format
, type
, width
, height
, depth
, border
,
2952 /* Here we convert a cpal compressed image into a regular glTexImage2D
2953 * call by decompressing the texture. If we really want to support cpal
2954 * textures in any driver this would have to be changed.
2956 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
2957 switch (internalFormat
) {
2958 case GL_PALETTE4_RGB8_OES
:
2959 case GL_PALETTE4_RGBA8_OES
:
2960 case GL_PALETTE4_R5_G6_B5_OES
:
2961 case GL_PALETTE4_RGBA4_OES
:
2962 case GL_PALETTE4_RGB5_A1_OES
:
2963 case GL_PALETTE8_RGB8_OES
:
2964 case GL_PALETTE8_RGBA8_OES
:
2965 case GL_PALETTE8_R5_G6_B5_OES
:
2966 case GL_PALETTE8_RGBA4_OES
:
2967 case GL_PALETTE8_RGB5_A1_OES
:
2968 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
2969 width
, height
, imageSize
, pixels
);
2974 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2978 /* For glCompressedTexImage() the driver has no choice about the
2979 * texture format since we'll never transcode the user's compressed
2980 * image data. The internalFormat was error checked earlier.
2982 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
2985 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
2986 * internal floating point format for the given base format.
2988 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
2989 if (type
== GL_FLOAT
) {
2990 texObj
->_IsFloat
= GL_TRUE
;
2991 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
2992 texObj
->_IsHalfFloat
= GL_TRUE
;
2995 internalFormat
= adjust_for_oes_float_texture(ctx
, format
, type
);
2998 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2999 internalFormat
, format
, type
);
3002 assert(texFormat
!= MESA_FORMAT_NONE
);
3005 /* check that width, height, depth are legal for the mipmap level */
3006 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3007 height
, depth
, border
);
3009 /* check that the texture won't take too much memory, etc */
3010 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3011 0, level
, texFormat
, 1,
3012 width
, height
, depth
);
3015 if (_mesa_is_proxy_texture(target
)) {
3016 /* Proxy texture: just clear or set state depending on error checking */
3017 struct gl_texture_image
*texImage
=
3018 get_proxy_tex_image(ctx
, target
, level
);
3021 return; /* GL_OUT_OF_MEMORY already recorded */
3023 if (dimensionsOK
&& sizeOK
) {
3024 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3025 border
, internalFormat
, texFormat
);
3028 clear_teximage_fields(texImage
);
3032 /* non-proxy target */
3033 const GLuint face
= _mesa_tex_target_to_face(target
);
3034 struct gl_texture_image
*texImage
;
3036 if (!dimensionsOK
) {
3037 _mesa_error(ctx
, GL_INVALID_VALUE
,
3038 "%s%uD(invalid width=%d or height=%d or depth=%d)",
3039 func
, dims
, width
, height
, depth
);
3044 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3045 "%s%uD(image too large: %d x %d x %d, %s format)",
3046 func
, dims
, width
, height
, depth
,
3047 _mesa_enum_to_string(internalFormat
));
3051 /* Allow a hardware driver to just strip out the border, to provide
3052 * reliable but slightly incorrect hardware rendering instead of
3053 * rarely-tested software fallback rendering.
3055 if (border
&& ctx
->Const
.StripTextureBorder
) {
3056 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3059 unpack
= &unpack_no_border
;
3062 if (ctx
->NewState
& _NEW_PIXEL
)
3063 _mesa_update_state(ctx
);
3065 _mesa_lock_texture(ctx
, texObj
);
3067 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3070 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3073 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3075 _mesa_init_teximage_fields(ctx
, texImage
,
3076 width
, height
, depth
,
3077 border
, internalFormat
, texFormat
);
3079 /* Give the texture to the driver. <pixels> may be null. */
3080 if (width
> 0 && height
> 0 && depth
> 0) {
3082 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3086 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3087 type
, pixels
, unpack
);
3091 check_gen_mipmap(ctx
, target
, texObj
, level
);
3093 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3095 _mesa_dirty_texobj(ctx
, texObj
);
3098 _mesa_unlock_texture(ctx
, texObj
);
3103 /* This is a wrapper around teximage() so that we can force the KHR_no_error
3104 * logic to be inlined without inlining the function into all the callers.
3107 teximage_err(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3108 GLenum target
, GLint level
, GLint internalFormat
,
3109 GLsizei width
, GLsizei height
, GLsizei depth
,
3110 GLint border
, GLenum format
, GLenum type
,
3111 GLsizei imageSize
, const GLvoid
*pixels
)
3113 teximage(ctx
, compressed
, dims
, target
, level
, internalFormat
, width
, height
,
3114 depth
, border
, format
, type
, imageSize
, pixels
, false);
3119 teximage_no_error(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3120 GLenum target
, GLint level
, GLint internalFormat
,
3121 GLsizei width
, GLsizei height
, GLsizei depth
,
3122 GLint border
, GLenum format
, GLenum type
,
3123 GLsizei imageSize
, const GLvoid
*pixels
)
3125 teximage(ctx
, compressed
, dims
, target
, level
, internalFormat
, width
, height
,
3126 depth
, border
, format
, type
, imageSize
, pixels
, true);
3131 * Called from the API. Note that width includes the border.
3134 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3135 GLsizei width
, GLint border
, GLenum format
,
3136 GLenum type
, const GLvoid
*pixels
)
3138 GET_CURRENT_CONTEXT(ctx
);
3139 teximage_err(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3140 border
, format
, type
, 0, pixels
);
3145 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3146 GLsizei width
, GLsizei height
, GLint border
,
3147 GLenum format
, GLenum type
,
3148 const GLvoid
*pixels
)
3150 GET_CURRENT_CONTEXT(ctx
);
3151 teximage_err(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3152 border
, format
, type
, 0, pixels
);
3157 * Called by the API or display list executor.
3158 * Note that width and height include the border.
3161 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3162 GLsizei width
, GLsizei height
, GLsizei depth
,
3163 GLint border
, GLenum format
, GLenum type
,
3164 const GLvoid
*pixels
)
3166 GET_CURRENT_CONTEXT(ctx
);
3167 teximage_err(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3168 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3173 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3174 GLsizei width
, GLsizei height
, GLsizei depth
,
3175 GLint border
, GLenum format
, GLenum type
,
3176 const GLvoid
*pixels
)
3178 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3179 depth
, border
, format
, type
, pixels
);
3184 _mesa_TexImage1D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3185 GLsizei width
, GLint border
, GLenum format
,
3186 GLenum type
, const GLvoid
*pixels
)
3188 GET_CURRENT_CONTEXT(ctx
);
3189 teximage_no_error(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1,
3190 1, border
, format
, type
, 0, pixels
);
3195 _mesa_TexImage2D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3196 GLsizei width
, GLsizei height
, GLint border
,
3197 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3199 GET_CURRENT_CONTEXT(ctx
);
3200 teximage_no_error(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
,
3201 height
, 1, border
, format
, type
, 0, pixels
);
3206 _mesa_TexImage3D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3207 GLsizei width
, GLsizei height
, GLsizei depth
,
3208 GLint border
, GLenum format
, GLenum type
,
3209 const GLvoid
*pixels
)
3211 GET_CURRENT_CONTEXT(ctx
);
3212 teximage_no_error(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3213 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3218 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3220 struct gl_texture_object
*texObj
;
3221 struct gl_texture_image
*texImage
;
3223 GET_CURRENT_CONTEXT(ctx
);
3224 FLUSH_VERTICES(ctx
, 0);
3228 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3230 case GL_TEXTURE_EXTERNAL_OES
:
3232 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3235 valid_target
= false;
3239 if (!valid_target
) {
3240 _mesa_error(ctx
, GL_INVALID_ENUM
,
3241 "glEGLImageTargetTexture2D(target=%d)", target
);
3246 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3247 "glEGLImageTargetTexture2D(image=%p)", image
);
3251 if (ctx
->NewState
& _NEW_PIXEL
)
3252 _mesa_update_state(ctx
);
3254 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3258 _mesa_lock_texture(ctx
, texObj
);
3260 if (texObj
->Immutable
) {
3261 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3262 "glEGLImageTargetTexture2D(texture is immutable)");
3263 _mesa_unlock_texture(ctx
, texObj
);
3267 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3269 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3271 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3273 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3274 texObj
, texImage
, image
);
3276 _mesa_dirty_texobj(ctx
, texObj
);
3278 _mesa_unlock_texture(ctx
, texObj
);
3283 * Helper that implements the glTexSubImage1/2/3D()
3284 * and glTextureSubImage1/2/3D() functions.
3287 texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3288 struct gl_texture_object
*texObj
,
3289 struct gl_texture_image
*texImage
,
3290 GLenum target
, GLint level
,
3291 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3292 GLsizei width
, GLsizei height
, GLsizei depth
,
3293 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3296 FLUSH_VERTICES(ctx
, 0);
3298 if (ctx
->NewState
& _NEW_PIXEL
)
3299 _mesa_update_state(ctx
);
3301 _mesa_lock_texture(ctx
, texObj
);
3303 if (width
> 0 && height
> 0 && depth
> 0) {
3304 /* If we have a border, offset=-1 is legal. Bias by border width. */
3307 if (target
!= GL_TEXTURE_2D_ARRAY
)
3308 zoffset
+= texImage
->Border
;
3311 if (target
!= GL_TEXTURE_1D_ARRAY
)
3312 yoffset
+= texImage
->Border
;
3315 xoffset
+= texImage
->Border
;
3318 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3319 xoffset
, yoffset
, zoffset
,
3320 width
, height
, depth
,
3321 format
, type
, pixels
, &ctx
->Unpack
);
3323 check_gen_mipmap(ctx
, target
, texObj
, level
);
3325 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3326 * the texel data, not the texture format, size, etc.
3330 _mesa_unlock_texture(ctx
, texObj
);
3334 * Implement all the glTexSubImage1/2/3D() functions.
3335 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3338 texsubimage_err(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3339 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3340 GLsizei width
, GLsizei height
, GLsizei depth
,
3341 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3342 const char *callerName
)
3344 struct gl_texture_object
*texObj
;
3345 struct gl_texture_image
*texImage
;
3347 /* check target (proxies not allowed) */
3348 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3349 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3350 dims
, _mesa_enum_to_string(target
));
3354 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3358 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3359 xoffset
, yoffset
, zoffset
,
3360 width
, height
, depth
, format
, type
,
3361 pixels
, false, callerName
)) {
3362 return; /* error was detected */
3365 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3366 /* texsubimage_error_check ensures that texImage is not NULL */
3368 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3369 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3371 _mesa_enum_to_string(target
), level
,
3372 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3373 _mesa_enum_to_string(format
),
3374 _mesa_enum_to_string(type
), pixels
);
3376 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3377 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3378 format
, type
, pixels
, false);
3383 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3384 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3385 GLsizei width
, GLsizei height
, GLsizei depth
,
3386 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3388 struct gl_texture_object
*texObj
;
3389 struct gl_texture_image
*texImage
;
3391 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3392 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3394 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3395 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3396 format
, type
, pixels
, false);
3401 * Implement all the glTextureSubImage1/2/3D() functions.
3402 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3404 static ALWAYS_INLINE
void
3405 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3406 GLuint texture
, GLint level
,
3407 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3408 GLsizei width
, GLsizei height
, GLsizei depth
,
3409 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3410 const char *callerName
, bool no_error
)
3412 struct gl_texture_object
*texObj
;
3413 struct gl_texture_image
*texImage
;
3416 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3418 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3419 dims
, texture
, level
,
3420 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3421 _mesa_enum_to_string(format
),
3422 _mesa_enum_to_string(type
), pixels
);
3424 /* Get the texture object by Name. */
3426 texObj
= _mesa_lookup_texture_err(ctx
, texture
, callerName
);
3430 texObj
= _mesa_lookup_texture(ctx
, texture
);
3434 /* check target (proxies not allowed) */
3435 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3436 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3437 callerName
, _mesa_enum_to_string(texObj
->Target
));
3441 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3442 xoffset
, yoffset
, zoffset
,
3443 width
, height
, depth
, format
, type
,
3444 pixels
, true, callerName
)) {
3445 return; /* error was detected */
3449 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3450 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3454 * What do we do if the user created a texture with the following code
3455 * and then called this function with its handle?
3458 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3459 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3460 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3461 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3462 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3463 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3464 * // wrong format, or given the wrong size, etc.
3465 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3466 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3468 * A bug has been filed against the spec for this case. In the
3469 * meantime, we will check for cube completeness.
3471 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3472 * Core Profile spec (30.10.2014):
3473 * "[A] cube map texture is cube complete if the
3474 * following conditions all hold true: The [base level] texture
3475 * images of each of the six cube map faces have identical, positive,
3476 * and square dimensions. The [base level] images were each specified
3477 * with the same internal format."
3479 * It seems reasonable to check for cube completeness of an arbitrary
3480 * level here so that the image data has a consistent format and size.
3482 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
3483 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3484 "glTextureSubImage%uD(cube map incomplete)",
3489 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3491 /* Copy in each face. */
3492 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3493 texImage
= texObj
->Image
[i
][level
];
3496 texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3497 level
, xoffset
, yoffset
, 0,
3498 width
, height
, 1, format
,
3499 type
, pixels
, true);
3500 pixels
= (GLubyte
*) pixels
+ imageStride
;
3504 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3507 texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3508 level
, xoffset
, yoffset
, zoffset
,
3509 width
, height
, depth
, format
,
3510 type
, pixels
, true);
3516 texturesubimage_error(struct gl_context
*ctx
, GLuint dims
,
3517 GLuint texture
, GLint level
,
3518 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3519 GLsizei width
, GLsizei height
, GLsizei depth
,
3520 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3521 const char *callerName
)
3523 texturesubimage(ctx
, dims
, texture
, level
, xoffset
, yoffset
, zoffset
,
3524 width
, height
, depth
, format
, type
, pixels
, callerName
,
3530 texturesubimage_no_error(struct gl_context
*ctx
, GLuint dims
,
3531 GLuint texture
, GLint level
,
3532 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3533 GLsizei width
, GLsizei height
, GLsizei depth
,
3534 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3535 const char *callerName
)
3537 texturesubimage(ctx
, dims
, texture
, level
, xoffset
, yoffset
, zoffset
,
3538 width
, height
, depth
, format
, type
, pixels
, callerName
,
3544 _mesa_TexSubImage1D_no_error(GLenum target
, GLint level
,
3545 GLint xoffset
, GLsizei width
,
3546 GLenum format
, GLenum type
,
3547 const GLvoid
*pixels
)
3549 GET_CURRENT_CONTEXT(ctx
);
3550 texsubimage(ctx
, 1, target
, level
,
3553 format
, type
, pixels
);
3558 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3559 GLint xoffset
, GLsizei width
,
3560 GLenum format
, GLenum type
,
3561 const GLvoid
*pixels
)
3563 GET_CURRENT_CONTEXT(ctx
);
3564 texsubimage_err(ctx
, 1, target
, level
,
3567 format
, type
, pixels
, "glTexSubImage1D");
3572 _mesa_TexSubImage2D_no_error(GLenum target
, GLint level
,
3573 GLint xoffset
, GLint yoffset
,
3574 GLsizei width
, GLsizei height
,
3575 GLenum format
, GLenum type
,
3576 const GLvoid
*pixels
)
3578 GET_CURRENT_CONTEXT(ctx
);
3579 texsubimage(ctx
, 2, target
, level
,
3580 xoffset
, yoffset
, 0,
3582 format
, type
, pixels
);
3587 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3588 GLint xoffset
, GLint yoffset
,
3589 GLsizei width
, GLsizei height
,
3590 GLenum format
, GLenum type
,
3591 const GLvoid
*pixels
)
3593 GET_CURRENT_CONTEXT(ctx
);
3594 texsubimage_err(ctx
, 2, target
, level
,
3595 xoffset
, yoffset
, 0,
3597 format
, type
, pixels
, "glTexSubImage2D");
3602 _mesa_TexSubImage3D_no_error(GLenum target
, GLint level
,
3603 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3604 GLsizei width
, GLsizei height
, GLsizei depth
,
3605 GLenum format
, GLenum type
,
3606 const GLvoid
*pixels
)
3608 GET_CURRENT_CONTEXT(ctx
);
3609 texsubimage(ctx
, 3, target
, level
,
3610 xoffset
, yoffset
, zoffset
,
3611 width
, height
, depth
,
3612 format
, type
, pixels
);
3617 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3618 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3619 GLsizei width
, GLsizei height
, GLsizei depth
,
3620 GLenum format
, GLenum type
,
3621 const GLvoid
*pixels
)
3623 GET_CURRENT_CONTEXT(ctx
);
3624 texsubimage_err(ctx
, 3, target
, level
,
3625 xoffset
, yoffset
, zoffset
,
3626 width
, height
, depth
,
3627 format
, type
, pixels
, "glTexSubImage3D");
3632 _mesa_TextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3633 GLsizei width
, GLenum format
, GLenum type
,
3634 const GLvoid
*pixels
)
3636 GET_CURRENT_CONTEXT(ctx
);
3637 texturesubimage_no_error(ctx
, 1, texture
, level
, xoffset
, 0, 0, width
, 1, 1,
3638 format
, type
, pixels
, "glTextureSubImage1D");
3643 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3644 GLint xoffset
, GLsizei width
,
3645 GLenum format
, GLenum type
,
3646 const GLvoid
*pixels
)
3648 GET_CURRENT_CONTEXT(ctx
);
3649 texturesubimage_error(ctx
, 1, texture
, level
, xoffset
, 0, 0, width
, 1, 1,
3650 format
, type
, pixels
, "glTextureSubImage1D");
3655 _mesa_TextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3656 GLint yoffset
, GLsizei width
, GLsizei height
,
3657 GLenum format
, GLenum type
,
3658 const GLvoid
*pixels
)
3660 GET_CURRENT_CONTEXT(ctx
);
3661 texturesubimage_no_error(ctx
, 2, texture
, level
, xoffset
, yoffset
, 0, width
,
3662 height
, 1, format
, type
, pixels
,
3663 "glTextureSubImage2D");
3668 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3669 GLint xoffset
, GLint yoffset
,
3670 GLsizei width
, GLsizei height
,
3671 GLenum format
, GLenum type
,
3672 const GLvoid
*pixels
)
3674 GET_CURRENT_CONTEXT(ctx
);
3675 texturesubimage_error(ctx
, 2, texture
, level
, xoffset
, yoffset
, 0, width
,
3676 height
, 1, format
, type
, pixels
,
3677 "glTextureSubImage2D");
3682 _mesa_TextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3683 GLint yoffset
, GLint zoffset
, GLsizei width
,
3684 GLsizei height
, GLsizei depth
, GLenum format
,
3685 GLenum type
, const GLvoid
*pixels
)
3687 GET_CURRENT_CONTEXT(ctx
);
3688 texturesubimage_no_error(ctx
, 3, texture
, level
, xoffset
, yoffset
, zoffset
,
3689 width
, height
, depth
, format
, type
, pixels
,
3690 "glTextureSubImage3D");
3695 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3696 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3697 GLsizei width
, GLsizei height
, GLsizei depth
,
3698 GLenum format
, GLenum type
,
3699 const GLvoid
*pixels
)
3701 GET_CURRENT_CONTEXT(ctx
);
3702 texturesubimage_error(ctx
, 3, texture
, level
, xoffset
, yoffset
, zoffset
,
3703 width
, height
, depth
, format
, type
, pixels
,
3704 "glTextureSubImage3D");
3709 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3710 * from. This depends on whether the texture contains color or depth values.
3712 static struct gl_renderbuffer
*
3713 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3715 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3716 /* reading from depth/stencil buffer */
3717 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3718 } else if (_mesa_get_format_bits(texFormat
, GL_STENCIL_BITS
) > 0) {
3719 return ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3721 /* copying from color buffer */
3722 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3728 copytexsubimage_by_slice(struct gl_context
*ctx
,
3729 struct gl_texture_image
*texImage
,
3731 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3732 struct gl_renderbuffer
*rb
,
3734 GLsizei width
, GLsizei height
)
3736 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3739 /* For 1D arrays, we copy each scanline of the source rectangle into the
3742 assert(zoffset
== 0);
3744 for (slice
= 0; slice
< height
; slice
++) {
3745 assert(yoffset
+ slice
< texImage
->Height
);
3746 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3747 xoffset
, 0, yoffset
+ slice
,
3748 rb
, x
, y
+ slice
, width
, 1);
3751 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3752 xoffset
, yoffset
, zoffset
,
3753 rb
, x
, y
, width
, height
);
3759 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3761 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3762 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3763 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3764 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3766 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3767 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3768 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3769 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3771 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3772 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3773 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3774 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3782 * Check if the given texture format and size arguments match those
3783 * of the texture image.
3784 * \param return true if arguments match, false otherwise.
3787 can_avoid_reallocation(const struct gl_texture_image
*texImage
,
3788 GLenum internalFormat
,
3789 mesa_format texFormat
, GLint x
, GLint y
, GLsizei width
,
3790 GLsizei height
, GLint border
)
3792 if (texImage
->InternalFormat
!= internalFormat
)
3794 if (texImage
->TexFormat
!= texFormat
)
3796 if (texImage
->Border
!= border
)
3798 if (texImage
->Width2
!= width
)
3800 if (texImage
->Height2
!= height
)
3807 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
3810 copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3811 struct gl_texture_object
*texObj
,
3812 GLenum target
, GLint level
,
3813 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3814 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3816 struct gl_texture_image
*texImage
;
3818 _mesa_lock_texture(ctx
, texObj
);
3820 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3822 /* If we have a border, offset=-1 is legal. Bias by border width. */
3825 if (target
!= GL_TEXTURE_2D_ARRAY
)
3826 zoffset
+= texImage
->Border
;
3829 if (target
!= GL_TEXTURE_1D_ARRAY
)
3830 yoffset
+= texImage
->Border
;
3833 xoffset
+= texImage
->Border
;
3836 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3838 struct gl_renderbuffer
*srcRb
=
3839 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3841 copytexsubimage_by_slice(ctx
, texImage
, dims
, xoffset
, yoffset
, zoffset
,
3842 srcRb
, x
, y
, width
, height
);
3844 check_gen_mipmap(ctx
, target
, texObj
, level
);
3846 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3847 * the texel data, not the texture format, size, etc.
3851 _mesa_unlock_texture(ctx
, texObj
);
3856 copy_texture_sub_image_err(struct gl_context
*ctx
, GLuint dims
,
3857 struct gl_texture_object
*texObj
,
3858 GLenum target
, GLint level
,
3859 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3860 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3863 FLUSH_VERTICES(ctx
, 0);
3865 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3866 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
3867 _mesa_enum_to_string(target
),
3868 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3870 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3871 _mesa_update_state(ctx
);
3873 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3874 xoffset
, yoffset
, zoffset
,
3875 width
, height
, caller
)) {
3879 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
3880 zoffset
, x
, y
, width
, height
);
3885 copy_texture_sub_image_no_error(struct gl_context
*ctx
, GLuint dims
,
3886 struct gl_texture_object
*texObj
,
3887 GLenum target
, GLint level
,
3888 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3889 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3891 FLUSH_VERTICES(ctx
, 0);
3893 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3894 _mesa_update_state(ctx
);
3896 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
3897 zoffset
, x
, y
, width
, height
);
3902 * Implement the glCopyTexImage1/2D() functions.
3904 static ALWAYS_INLINE
void
3905 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3906 GLenum target
, GLint level
, GLenum internalFormat
,
3907 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
,
3910 struct gl_texture_image
*texImage
;
3911 struct gl_texture_object
*texObj
;
3912 mesa_format texFormat
;
3914 FLUSH_VERTICES(ctx
, 0);
3916 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3917 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3919 _mesa_enum_to_string(target
), level
,
3920 _mesa_enum_to_string(internalFormat
),
3921 x
, y
, width
, height
, border
);
3923 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3924 _mesa_update_state(ctx
);
3927 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3928 width
, height
, border
))
3931 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3933 _mesa_error(ctx
, GL_INVALID_VALUE
,
3934 "glCopyTexImage%uD(invalid width=%d or height=%d)",
3935 dims
, width
, height
);
3940 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3943 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3944 internalFormat
, GL_NONE
, GL_NONE
);
3946 /* First check if reallocating the texture buffer can be avoided.
3947 * Without the realloc the copy can be 20x faster.
3949 _mesa_lock_texture(ctx
, texObj
);
3951 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3952 if (texImage
&& can_avoid_reallocation(texImage
, internalFormat
, texFormat
,
3953 x
, y
, width
, height
, border
)) {
3954 _mesa_unlock_texture(ctx
, texObj
);
3956 copy_texture_sub_image_no_error(ctx
, dims
, texObj
, target
, level
, 0,
3957 0, 0, x
, y
, width
, height
);
3959 copy_texture_sub_image_err(ctx
, dims
, texObj
, target
, level
, 0, 0,
3960 0, x
, y
, width
, height
,"CopyTexImage");
3965 _mesa_unlock_texture(ctx
, texObj
);
3966 _mesa_perf_debug(ctx
, MESA_DEBUG_SEVERITY_LOW
, "glCopyTexImage "
3967 "can't avoid reallocating texture storage\n");
3969 if (!no_error
&& _mesa_is_gles3(ctx
)) {
3970 struct gl_renderbuffer
*rb
=
3971 _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3973 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3974 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3975 * OpenGL ES 3.0. Khronos bug# 9807.
3977 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3978 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3979 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
3980 " and writing to unsized internal format)", dims
);
3984 /* From Page 139 of OpenGL ES 3.0 spec:
3985 * "If internalformat is sized, the internal format of the new texel
3986 * array is internalformat, and this is also the new texel array’s
3987 * effective internal format. If the component sizes of internalformat
3988 * do not exactly match the corresponding component sizes of the source
3989 * buffer’s effective internal format, described below, an
3990 * INVALID_OPERATION error is generated. If internalformat is unsized,
3991 * the internal format of the new texel array is the effective internal
3992 * format of the source buffer, and this is also the new texel array’s
3993 * effective internal format.
3995 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3996 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3997 "glCopyTexImage%uD(componenet size changed in"
3998 " internal format)", dims
);
4003 assert(texFormat
!= MESA_FORMAT_NONE
);
4005 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
4006 0, level
, texFormat
, 1,
4007 width
, height
, 1)) {
4008 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4009 "glCopyTexImage%uD(image too large)", dims
);
4013 if (border
&& ctx
->Const
.StripTextureBorder
) {
4015 width
-= border
* 2;
4018 height
-= border
* 2;
4023 _mesa_lock_texture(ctx
, texObj
);
4025 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
4028 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
4031 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
4032 const GLuint face
= _mesa_tex_target_to_face(target
);
4034 /* Free old texture image */
4035 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4037 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
4038 border
, internalFormat
, texFormat
);
4040 if (width
&& height
) {
4041 /* Allocate texture memory (no pixel data yet) */
4042 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
4044 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
4046 struct gl_renderbuffer
*srcRb
=
4047 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4049 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4051 srcRb
, srcX
, srcY
, width
, height
);
4054 check_gen_mipmap(ctx
, target
, texObj
, level
);
4057 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4059 _mesa_dirty_texobj(ctx
, texObj
);
4062 _mesa_unlock_texture(ctx
, texObj
);
4067 copyteximage_err(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
4068 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4069 GLsizei width
, GLsizei height
, GLint border
)
4071 copyteximage(ctx
, dims
, target
, level
, internalFormat
, x
, y
, width
, height
,
4077 copyteximage_no_error(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
4078 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4079 GLsizei width
, GLsizei height
, GLint border
)
4081 copyteximage(ctx
, dims
, target
, level
, internalFormat
, x
, y
, width
, height
,
4087 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4088 GLenum internalFormat
,
4090 GLsizei width
, GLint border
)
4092 GET_CURRENT_CONTEXT(ctx
);
4093 copyteximage_err(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4099 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4100 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4103 GET_CURRENT_CONTEXT(ctx
);
4104 copyteximage_err(ctx
, 2, target
, level
, internalFormat
,
4105 x
, y
, width
, height
, border
);
4110 _mesa_CopyTexImage1D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4111 GLint x
, GLint y
, GLsizei width
, GLint border
)
4113 GET_CURRENT_CONTEXT(ctx
);
4114 copyteximage_no_error(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4120 _mesa_CopyTexImage2D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4121 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4124 GET_CURRENT_CONTEXT(ctx
);
4125 copyteximage_no_error(ctx
, 2, target
, level
, internalFormat
,
4126 x
, y
, width
, height
, border
);
4131 _mesa_CopyTexSubImage1D(GLenum target
, GLint level
,
4132 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4134 struct gl_texture_object
* texObj
;
4135 const char *self
= "glCopyTexSubImage1D";
4136 GET_CURRENT_CONTEXT(ctx
);
4138 /* Check target (proxies not allowed). Target must be checked prior to
4139 * calling _mesa_get_current_tex_object.
4141 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4142 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4143 _mesa_enum_to_string(target
));
4147 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4151 copy_texture_sub_image_err(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4152 x
, y
, width
, 1, self
);
4157 _mesa_CopyTexSubImage2D(GLenum target
, GLint level
,
4158 GLint xoffset
, GLint yoffset
,
4159 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4161 struct gl_texture_object
* texObj
;
4162 const char *self
= "glCopyTexSubImage2D";
4163 GET_CURRENT_CONTEXT(ctx
);
4165 /* Check target (proxies not allowed). Target must be checked prior to
4166 * calling _mesa_get_current_tex_object.
4168 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4169 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4170 _mesa_enum_to_string(target
));
4174 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4178 copy_texture_sub_image_err(ctx
, 2, texObj
, target
, level
, xoffset
, yoffset
,
4179 0, x
, y
, width
, height
, self
);
4184 _mesa_CopyTexSubImage3D(GLenum target
, GLint level
,
4185 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4186 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4188 struct gl_texture_object
* texObj
;
4189 const char *self
= "glCopyTexSubImage3D";
4190 GET_CURRENT_CONTEXT(ctx
);
4192 /* Check target (proxies not allowed). Target must be checked prior to
4193 * calling _mesa_get_current_tex_object.
4195 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4196 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4197 _mesa_enum_to_string(target
));
4201 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4205 copy_texture_sub_image_err(ctx
, 3, texObj
, target
, level
, xoffset
, yoffset
,
4206 zoffset
, x
, y
, width
, height
, self
);
4211 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4212 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4214 struct gl_texture_object
* texObj
;
4215 const char *self
= "glCopyTextureSubImage1D";
4216 GET_CURRENT_CONTEXT(ctx
);
4218 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4222 /* Check target (proxies not allowed). */
4223 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4224 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4225 _mesa_enum_to_string(texObj
->Target
));
4229 copy_texture_sub_image_err(ctx
, 1, texObj
, texObj
->Target
, level
, xoffset
, 0,
4230 0, x
, y
, width
, 1, self
);
4235 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4236 GLint xoffset
, GLint yoffset
,
4237 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4239 struct gl_texture_object
* texObj
;
4240 const char *self
= "glCopyTextureSubImage2D";
4241 GET_CURRENT_CONTEXT(ctx
);
4243 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4247 /* Check target (proxies not allowed). */
4248 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4249 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4250 _mesa_enum_to_string(texObj
->Target
));
4254 copy_texture_sub_image_err(ctx
, 2, texObj
, texObj
->Target
, level
, xoffset
,
4255 yoffset
, 0, x
, y
, width
, height
, self
);
4260 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4261 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4262 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4264 struct gl_texture_object
* texObj
;
4265 const char *self
= "glCopyTextureSubImage3D";
4266 GET_CURRENT_CONTEXT(ctx
);
4268 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4272 /* Check target (proxies not allowed). */
4273 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4274 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4275 _mesa_enum_to_string(texObj
->Target
));
4279 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4280 /* Act like CopyTexSubImage2D */
4281 copy_texture_sub_image_err(ctx
, 2, texObj
,
4282 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4283 level
, xoffset
, yoffset
, 0, x
, y
, width
, height
,
4287 copy_texture_sub_image_err(ctx
, 3, texObj
, texObj
->Target
, level
, xoffset
,
4288 yoffset
, zoffset
, x
, y
, width
, height
, self
);
4293 _mesa_CopyTexSubImage1D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4294 GLint x
, GLint y
, GLsizei width
)
4296 GET_CURRENT_CONTEXT(ctx
);
4298 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4299 copy_texture_sub_image_no_error(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4305 _mesa_CopyTexSubImage2D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4306 GLint yoffset
, GLint x
, GLint y
, GLsizei width
,
4309 GET_CURRENT_CONTEXT(ctx
);
4311 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4312 copy_texture_sub_image_no_error(ctx
, 2, texObj
, target
, level
, xoffset
,
4313 yoffset
, 0, x
, y
, width
, height
);
4318 _mesa_CopyTexSubImage3D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4319 GLint yoffset
, GLint zoffset
, GLint x
, GLint y
,
4320 GLsizei width
, GLsizei height
)
4322 GET_CURRENT_CONTEXT(ctx
);
4324 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4325 copy_texture_sub_image_no_error(ctx
, 3, texObj
, target
, level
, xoffset
,
4326 yoffset
, zoffset
, x
, y
, width
, height
);
4331 _mesa_CopyTextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4332 GLint x
, GLint y
, GLsizei width
)
4334 GET_CURRENT_CONTEXT(ctx
);
4336 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4337 copy_texture_sub_image_no_error(ctx
, 1, texObj
, texObj
->Target
, level
,
4338 xoffset
, 0, 0, x
, y
, width
, 1);
4343 _mesa_CopyTextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4344 GLint yoffset
, GLint x
, GLint y
,
4345 GLsizei width
, GLsizei height
)
4347 GET_CURRENT_CONTEXT(ctx
);
4349 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4350 copy_texture_sub_image_no_error(ctx
, 2, texObj
, texObj
->Target
, level
,
4351 xoffset
, yoffset
, 0, x
, y
, width
, height
);
4356 _mesa_CopyTextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4357 GLint yoffset
, GLint zoffset
, GLint x
,
4358 GLint y
, GLsizei width
, GLsizei height
)
4360 GET_CURRENT_CONTEXT(ctx
);
4362 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4363 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4364 /* Act like CopyTexSubImage2D */
4365 copy_texture_sub_image_no_error(ctx
, 2, texObj
,
4366 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4367 level
, xoffset
, yoffset
, 0, x
, y
, width
,
4371 copy_texture_sub_image_no_error(ctx
, 3, texObj
, texObj
->Target
, level
,
4372 xoffset
, yoffset
, zoffset
, x
, y
, width
,
4378 check_clear_tex_image(struct gl_context
*ctx
,
4379 const char *function
,
4380 struct gl_texture_image
*texImage
,
4381 GLenum format
, GLenum type
,
4383 GLubyte
*clearValue
)
4385 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4386 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4387 GLenum internalFormat
= texImage
->InternalFormat
;
4390 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4391 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4392 "%s(buffer texture)", function
);
4396 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4397 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4398 "%s(compressed texture)", function
);
4402 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4403 if (err
!= GL_NO_ERROR
) {
4404 _mesa_error(ctx
, err
,
4405 "%s(incompatible format = %s, type = %s)",
4407 _mesa_enum_to_string(format
),
4408 _mesa_enum_to_string(type
));
4412 /* make sure internal format and format basically agree */
4413 if (!texture_formats_agree(internalFormat
, format
)) {
4414 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4415 "%s(incompatible internalFormat = %s, format = %s)",
4417 _mesa_enum_to_string(internalFormat
),
4418 _mesa_enum_to_string(format
));
4422 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4423 /* both source and dest must be integer-valued, or neither */
4424 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4425 _mesa_is_enum_format_integer(format
)) {
4426 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4427 "%s(integer/non-integer format mismatch)",
4433 if (!_mesa_texstore(ctx
,
4435 texImage
->_BaseFormat
,
4436 texImage
->TexFormat
,
4437 0, /* dstRowStride */
4439 1, 1, 1, /* srcWidth/Height/Depth */
4441 data
? data
: zeroData
,
4442 &ctx
->DefaultPacking
)) {
4443 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4451 static struct gl_texture_object
*
4452 get_tex_obj_for_clear(struct gl_context
*ctx
,
4453 const char *function
,
4456 struct gl_texture_object
*texObj
;
4458 texObj
= _mesa_lookup_texture_err(ctx
, texture
, function
);
4462 if (texObj
->Target
== 0) {
4463 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4472 * For clearing cube textures, the zoffset and depth parameters indicate
4473 * which cube map faces are to be cleared. This is the one case where we
4474 * need to be concerned with multiple gl_texture_images. This function
4475 * returns the array of texture images to clear for cube maps, or one
4476 * texture image otherwise.
4477 * \return number of texture images, 0 for error, 6 for cube, 1 otherwise.
4480 get_tex_images_for_clear(struct gl_context
*ctx
,
4481 const char *function
,
4482 struct gl_texture_object
*texObj
,
4484 struct gl_texture_image
**texImages
)
4489 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4490 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4494 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4495 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
4496 numFaces
= MAX_FACES
;
4499 target
= texObj
->Target
;
4503 for (i
= 0; i
< numFaces
; i
++) {
4504 texImages
[i
] = _mesa_select_tex_image(texObj
, target
+ i
, level
);
4505 if (texImages
[i
] == NULL
) {
4506 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4516 _mesa_ClearTexSubImage(GLuint texture
, GLint level
,
4517 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4518 GLsizei width
, GLsizei height
, GLsizei depth
,
4519 GLenum format
, GLenum type
, const void *data
)
4521 GET_CURRENT_CONTEXT(ctx
);
4522 struct gl_texture_object
*texObj
;
4523 struct gl_texture_image
*texImages
[MAX_FACES
];
4524 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4526 int minDepth
, maxDepth
;
4528 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4533 _mesa_lock_texture(ctx
, texObj
);
4535 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4536 texObj
, level
, texImages
);
4540 if (numImages
== 1) {
4541 minDepth
= -(int) texImages
[0]->Border
;
4542 maxDepth
= texImages
[0]->Depth
;
4544 assert(numImages
== MAX_FACES
);
4546 maxDepth
= numImages
;
4549 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4550 yoffset
< -(GLint
) texImages
[0]->Border
||
4551 zoffset
< minDepth
||
4555 xoffset
+ width
> texImages
[0]->Width
||
4556 yoffset
+ height
> texImages
[0]->Height
||
4557 zoffset
+ depth
> maxDepth
) {
4558 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4559 "glClearSubTexImage(invalid dimensions)");
4563 if (numImages
== 1) {
4564 if (check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[0],
4565 format
, type
, data
, clearValue
[0])) {
4566 ctx
->Driver
.ClearTexSubImage(ctx
,
4568 xoffset
, yoffset
, zoffset
,
4569 width
, height
, depth
,
4570 data
? clearValue
[0] : NULL
);
4573 /* loop over cube face images */
4574 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4575 assert(i
< MAX_FACES
);
4576 if (!check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[i
],
4577 format
, type
, data
, clearValue
[i
]))
4580 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4581 ctx
->Driver
.ClearTexSubImage(ctx
,
4583 xoffset
, yoffset
, 0,
4585 data
? clearValue
[i
] : NULL
);
4590 _mesa_unlock_texture(ctx
, texObj
);
4595 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4596 GLenum format
, GLenum type
, const void *data
)
4598 GET_CURRENT_CONTEXT(ctx
);
4599 struct gl_texture_object
*texObj
;
4600 struct gl_texture_image
*texImages
[MAX_FACES
];
4601 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4604 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4609 _mesa_lock_texture(ctx
, texObj
);
4611 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4612 texObj
, level
, texImages
);
4614 for (i
= 0; i
< numImages
; i
++) {
4615 if (!check_clear_tex_image(ctx
, "glClearTexImage", texImages
[i
], format
,
4616 type
, data
, clearValue
[i
]))
4620 for (i
= 0; i
< numImages
; i
++) {
4621 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4622 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4623 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4624 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4625 texImages
[i
]->Width
,
4626 texImages
[i
]->Height
,
4627 texImages
[i
]->Depth
,
4628 data
? clearValue
[i
] : NULL
);
4632 _mesa_unlock_texture(ctx
, texObj
);
4638 /**********************************************************************/
4639 /****** Compressed Textures ******/
4640 /**********************************************************************/
4644 * Target checking for glCompressedTexSubImage[123]D().
4645 * \return GL_TRUE if error, GL_FALSE if no error
4646 * Must come before other error checking so that the texture object can
4647 * be correctly retrieved using _mesa_get_current_tex_object.
4650 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4651 GLint dims
, GLenum format
, bool dsa
,
4656 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4657 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4658 _mesa_enum_to_string(target
));
4668 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4669 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4670 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4671 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4672 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4673 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4674 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4677 targetOK
= GL_FALSE
;
4683 case GL_TEXTURE_CUBE_MAP
:
4684 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4686 case GL_TEXTURE_2D_ARRAY
:
4687 targetOK
= _mesa_is_gles3(ctx
) ||
4688 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4690 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4691 targetOK
= _mesa_has_texture_cube_map_array(ctx
);
4696 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4698 * "An INVALID_OPERATION error is generated by
4699 * CompressedTex*SubImage3D if the internal format of the texture
4700 * is one of the EAC, ETC2, or RGTC formats and either border is
4701 * non-zero, or the effective target for the texture is not
4702 * TEXTURE_2D_ARRAY."
4704 * NOTE: that's probably a spec error. It should probably say
4705 * "... or the effective target for the texture is not
4706 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4707 * GL_TEXTURE_CUBE_MAP_ARRAY."
4708 * since those targets are 2D images and they support all compression
4711 * Instead of listing all these, just list those which are allowed,
4712 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4713 * more) are valid here, which they are not, but of course not
4714 * mentioned by core spec.
4717 /* These are the only 3D compression formats supported at this time */
4718 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
4719 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
4720 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
4721 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
4725 /* invalid format */
4726 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4727 "%s(invalid target %s for format %s)", caller
,
4728 _mesa_enum_to_string(target
),
4729 _mesa_enum_to_string(format
));
4734 targetOK
= GL_FALSE
;
4740 /* no 1D compressed textures at this time */
4741 targetOK
= GL_FALSE
;
4746 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4747 _mesa_enum_to_string(target
));
4755 * Error checking for glCompressedTexSubImage[123]D().
4756 * \return GL_TRUE if error, GL_FALSE if no error
4759 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4760 const struct gl_texture_object
*texObj
,
4761 GLenum target
, GLint level
,
4762 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4763 GLsizei width
, GLsizei height
, GLsizei depth
,
4764 GLenum format
, GLsizei imageSize
,
4765 const GLvoid
*data
, const char *callerName
)
4767 struct gl_texture_image
*texImage
;
4770 /* this will catch any invalid compressed format token */
4771 if (!_mesa_is_compressed_format(ctx
, format
)) {
4772 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(format)", callerName
);
4776 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4777 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
4781 /* validate the bound PBO, if any */
4782 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4783 imageSize
, data
, callerName
)) {
4787 /* Check for invalid pixel storage modes */
4788 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4789 &ctx
->Unpack
, callerName
)) {
4793 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4794 if (expectedSize
!= imageSize
) {
4795 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", callerName
, imageSize
);
4799 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4801 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture level %d)",
4806 if ((GLint
) format
!= texImage
->InternalFormat
) {
4807 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s)",
4808 callerName
, _mesa_enum_to_string(format
));
4812 if (compressedteximage_only_format(ctx
, format
)) {
4813 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s cannot be updated)",
4814 callerName
, _mesa_enum_to_string(format
));
4818 if (error_check_subtexture_negative_dimensions(ctx
, dims
, width
, height
,
4819 depth
, callerName
)) {
4823 if (error_check_subtexture_dimensions(ctx
, dims
, texImage
, xoffset
, yoffset
,
4824 zoffset
, width
, height
, depth
,
4834 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4835 GLenum internalFormat
, GLsizei width
,
4836 GLint border
, GLsizei imageSize
,
4839 GET_CURRENT_CONTEXT(ctx
);
4840 teximage_err(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4841 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4846 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4847 GLenum internalFormat
, GLsizei width
,
4848 GLsizei height
, GLint border
, GLsizei imageSize
,
4851 GET_CURRENT_CONTEXT(ctx
);
4852 teximage_err(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4853 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4858 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4859 GLenum internalFormat
, GLsizei width
,
4860 GLsizei height
, GLsizei depth
, GLint border
,
4861 GLsizei imageSize
, const GLvoid
*data
)
4863 GET_CURRENT_CONTEXT(ctx
);
4864 teximage_err(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
, height
,
4865 depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4870 _mesa_CompressedTexImage1D_no_error(GLenum target
, GLint level
,
4871 GLenum internalFormat
, GLsizei width
,
4872 GLint border
, GLsizei imageSize
,
4875 GET_CURRENT_CONTEXT(ctx
);
4876 teximage_no_error(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
, width
, 1,
4877 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4882 _mesa_CompressedTexImage2D_no_error(GLenum target
, GLint level
,
4883 GLenum internalFormat
, GLsizei width
,
4884 GLsizei height
, GLint border
,
4885 GLsizei imageSize
, const GLvoid
*data
)
4887 GET_CURRENT_CONTEXT(ctx
);
4888 teximage_no_error(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
, width
,
4889 height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4894 _mesa_CompressedTexImage3D_no_error(GLenum target
, GLint level
,
4895 GLenum internalFormat
, GLsizei width
,
4896 GLsizei height
, GLsizei depth
, GLint border
,
4897 GLsizei imageSize
, const GLvoid
*data
)
4899 GET_CURRENT_CONTEXT(ctx
);
4900 teximage_no_error(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
,
4901 height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4906 * Common helper for glCompressedTexSubImage1/2/3D() and
4907 * glCompressedTextureSubImage1/2/3D().
4910 compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4911 struct gl_texture_object
*texObj
,
4912 struct gl_texture_image
*texImage
,
4913 GLenum target
, GLint level
, GLint xoffset
,
4914 GLint yoffset
, GLint zoffset
, GLsizei width
,
4915 GLsizei height
, GLsizei depth
, GLenum format
,
4916 GLsizei imageSize
, const GLvoid
*data
)
4918 FLUSH_VERTICES(ctx
, 0);
4920 _mesa_lock_texture(ctx
, texObj
);
4922 if (width
> 0 && height
> 0 && depth
> 0) {
4923 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4924 xoffset
, yoffset
, zoffset
,
4925 width
, height
, depth
,
4926 format
, imageSize
, data
);
4928 check_gen_mipmap(ctx
, target
, texObj
, level
);
4930 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
4931 * the texel data, not the texture format, size, etc.
4935 _mesa_unlock_texture(ctx
, texObj
);
4939 static ALWAYS_INLINE
void
4940 compressed_tex_sub_image(unsigned dim
, GLenum target
, GLuint texture
,
4941 GLint level
, GLint xoffset
, GLint yoffset
,
4942 GLint zoffset
, GLsizei width
, GLsizei height
,
4943 GLsizei depth
, GLenum format
, GLsizei imageSize
,
4944 const GLvoid
*data
, bool dsa
, bool no_error
,
4947 struct gl_texture_object
*texObj
= NULL
;
4948 struct gl_texture_image
*texImage
;
4950 GET_CURRENT_CONTEXT(ctx
);
4954 texObj
= _mesa_lookup_texture(ctx
, texture
);
4956 texObj
= _mesa_lookup_texture_err(ctx
, texture
, caller
);
4961 target
= texObj
->Target
;
4965 compressed_subtexture_target_check(ctx
, target
, dim
, format
, dsa
,
4971 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4972 if (!no_error
&& !texObj
)
4977 compressed_subtexture_error_check(ctx
, dim
, texObj
, target
, level
,
4978 xoffset
, yoffset
, zoffset
, width
,
4979 height
, depth
, format
,
4980 imageSize
, data
, caller
)) {
4984 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
4985 if (dim
== 3 && dsa
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4986 const char *pixels
= data
;
4989 /* Make sure the texture object is a proper cube.
4990 * (See texturesubimage in teximage.c for details on why this check is
4993 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
4994 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4995 "glCompressedTextureSubImage3D(cube map incomplete)");
4999 /* Copy in each face. */
5000 for (int i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
5001 texImage
= texObj
->Image
[i
][level
];
5004 compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5005 texObj
->Target
, level
, xoffset
, yoffset
,
5006 0, width
, height
, 1, format
,
5009 /* Compressed images don't have a client format */
5010 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5012 texImage
->Height
, 1);
5014 pixels
+= image_stride
;
5015 imageSize
-= image_stride
;
5018 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5021 compressed_texture_sub_image(ctx
, dim
, texObj
, texImage
, target
, level
,
5022 xoffset
, yoffset
, zoffset
, width
, height
,
5023 depth
, format
, imageSize
, data
);
5028 compressed_tex_sub_image_error(unsigned dim
, GLenum target
, GLuint texture
,
5029 GLint level
, GLint xoffset
, GLint yoffset
,
5030 GLint zoffset
, GLsizei width
, GLsizei height
,
5031 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5032 const GLvoid
*data
, bool dsa
,
5035 compressed_tex_sub_image(dim
, target
, texture
, level
, xoffset
, yoffset
,
5036 zoffset
, width
, height
, depth
, format
, imageSize
,
5037 data
, dsa
, false, caller
);
5041 compressed_tex_sub_image_no_error(unsigned dim
, GLenum target
, GLuint texture
,
5042 GLint level
, GLint xoffset
, GLint yoffset
,
5043 GLint zoffset
, GLsizei width
, GLsizei height
,
5044 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5045 const GLvoid
*data
, bool dsa
,
5048 compressed_tex_sub_image(dim
, target
, texture
, level
, xoffset
, yoffset
,
5049 zoffset
, width
, height
, depth
, format
, imageSize
,
5050 data
, dsa
, true, caller
);
5054 _mesa_CompressedTexSubImage1D_no_error(GLenum target
, GLint level
,
5055 GLint xoffset
, GLsizei width
,
5056 GLenum format
, GLsizei imageSize
,
5059 compressed_tex_sub_image_no_error(1, target
, 0, level
, xoffset
, 0, 0, width
,
5060 1, 1, format
, imageSize
, data
, false,
5061 "glCompressedTexSubImage1D");
5066 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
5067 GLsizei width
, GLenum format
,
5068 GLsizei imageSize
, const GLvoid
*data
)
5070 compressed_tex_sub_image_error(1, target
, 0, level
, xoffset
, 0, 0, width
, 1,
5071 1, format
, imageSize
, data
, false,
5072 "glCompressedTexSubImage1D");
5077 _mesa_CompressedTextureSubImage1D_no_error(GLuint texture
, GLint level
,
5078 GLint xoffset
, GLsizei width
,
5079 GLenum format
, GLsizei imageSize
,
5082 compressed_tex_sub_image_no_error(1, 0, texture
, level
, xoffset
, 0, 0, width
,
5083 1, 1, format
, imageSize
, data
, true,
5084 "glCompressedTextureSubImage1D");
5089 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
5090 GLsizei width
, GLenum format
,
5091 GLsizei imageSize
, const GLvoid
*data
)
5093 compressed_tex_sub_image_error(1, 0, texture
, level
, xoffset
, 0, 0, width
,
5094 1, 1, format
, imageSize
, data
, true,
5095 "glCompressedTextureSubImage1D");
5099 _mesa_CompressedTexSubImage2D_no_error(GLenum target
, GLint level
,
5100 GLint xoffset
, GLint yoffset
,
5101 GLsizei width
, GLsizei height
,
5102 GLenum format
, GLsizei imageSize
,
5105 compressed_tex_sub_image_no_error(2, target
, 0, level
, xoffset
, yoffset
, 0,
5106 width
, height
, 1, format
, imageSize
, data
,
5107 false, "glCompressedTexSubImage2D");
5112 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
5113 GLint yoffset
, GLsizei width
, GLsizei height
,
5114 GLenum format
, GLsizei imageSize
,
5117 compressed_tex_sub_image_error(2, target
, 0, level
, xoffset
, yoffset
, 0,
5118 width
, height
, 1, format
, imageSize
, data
,
5119 false, "glCompressedTexSubImage2D");
5124 _mesa_CompressedTextureSubImage2D_no_error(GLuint texture
, GLint level
,
5125 GLint xoffset
, GLint yoffset
,
5126 GLsizei width
, GLsizei height
,
5127 GLenum format
, GLsizei imageSize
,
5130 compressed_tex_sub_image_no_error(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5131 width
, height
, 1, format
, imageSize
, data
,
5132 true, "glCompressedTextureSubImage2D");
5137 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
5139 GLsizei width
, GLsizei height
,
5140 GLenum format
, GLsizei imageSize
,
5143 compressed_tex_sub_image_error(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5144 width
, height
, 1, format
, imageSize
, data
,
5145 true, "glCompressedTextureSubImage2D");
5149 _mesa_CompressedTexSubImage3D_no_error(GLenum target
, GLint level
,
5150 GLint xoffset
, GLint yoffset
,
5151 GLint zoffset
, GLsizei width
,
5152 GLsizei height
, GLsizei depth
,
5153 GLenum format
, GLsizei imageSize
,
5156 compressed_tex_sub_image_no_error(3, target
, 0, level
, xoffset
, yoffset
,
5157 zoffset
, width
, height
, depth
, format
,
5158 imageSize
, data
, false,
5159 "glCompressedTexSubImage3D");
5163 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
5164 GLint yoffset
, GLint zoffset
, GLsizei width
,
5165 GLsizei height
, GLsizei depth
, GLenum format
,
5166 GLsizei imageSize
, const GLvoid
*data
)
5168 compressed_tex_sub_image_error(3, target
, 0, level
, xoffset
, yoffset
,
5169 zoffset
, width
, height
, depth
, format
,
5170 imageSize
, data
, false,
5171 "glCompressedTexSubImage3D");
5175 _mesa_CompressedTextureSubImage3D_no_error(GLuint texture
, GLint level
,
5176 GLint xoffset
, GLint yoffset
,
5177 GLint zoffset
, GLsizei width
,
5178 GLsizei height
, GLsizei depth
,
5179 GLenum format
, GLsizei imageSize
,
5182 compressed_tex_sub_image_no_error(3, 0, texture
, level
, xoffset
, yoffset
,
5183 zoffset
, width
, height
, depth
, format
,
5184 imageSize
, data
, true,
5185 "glCompressedTextureSubImage3D");
5189 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
5190 GLint yoffset
, GLint zoffset
, GLsizei width
,
5191 GLsizei height
, GLsizei depth
,
5192 GLenum format
, GLsizei imageSize
,
5195 compressed_tex_sub_image_error(3, 0, texture
, level
, xoffset
, yoffset
,
5196 zoffset
, width
, height
, depth
, format
,
5197 imageSize
, data
, true,
5198 "glCompressedTextureSubImage3D");
5202 _mesa_get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5204 if (ctx
->API
== API_OPENGL_COMPAT
) {
5205 switch (internalFormat
) {
5207 return MESA_FORMAT_A_UNORM8
;
5209 return MESA_FORMAT_A_UNORM16
;
5210 case GL_ALPHA16F_ARB
:
5211 return MESA_FORMAT_A_FLOAT16
;
5212 case GL_ALPHA32F_ARB
:
5213 return MESA_FORMAT_A_FLOAT32
;
5214 case GL_ALPHA8I_EXT
:
5215 return MESA_FORMAT_A_SINT8
;
5216 case GL_ALPHA16I_EXT
:
5217 return MESA_FORMAT_A_SINT16
;
5218 case GL_ALPHA32I_EXT
:
5219 return MESA_FORMAT_A_SINT32
;
5220 case GL_ALPHA8UI_EXT
:
5221 return MESA_FORMAT_A_UINT8
;
5222 case GL_ALPHA16UI_EXT
:
5223 return MESA_FORMAT_A_UINT16
;
5224 case GL_ALPHA32UI_EXT
:
5225 return MESA_FORMAT_A_UINT32
;
5227 return MESA_FORMAT_L_UNORM8
;
5228 case GL_LUMINANCE16
:
5229 return MESA_FORMAT_L_UNORM16
;
5230 case GL_LUMINANCE16F_ARB
:
5231 return MESA_FORMAT_L_FLOAT16
;
5232 case GL_LUMINANCE32F_ARB
:
5233 return MESA_FORMAT_L_FLOAT32
;
5234 case GL_LUMINANCE8I_EXT
:
5235 return MESA_FORMAT_L_SINT8
;
5236 case GL_LUMINANCE16I_EXT
:
5237 return MESA_FORMAT_L_SINT16
;
5238 case GL_LUMINANCE32I_EXT
:
5239 return MESA_FORMAT_L_SINT32
;
5240 case GL_LUMINANCE8UI_EXT
:
5241 return MESA_FORMAT_L_UINT8
;
5242 case GL_LUMINANCE16UI_EXT
:
5243 return MESA_FORMAT_L_UINT16
;
5244 case GL_LUMINANCE32UI_EXT
:
5245 return MESA_FORMAT_L_UINT32
;
5246 case GL_LUMINANCE8_ALPHA8
:
5247 return MESA_FORMAT_L8A8_UNORM
;
5248 case GL_LUMINANCE16_ALPHA16
:
5249 return MESA_FORMAT_L16A16_UNORM
;
5250 case GL_LUMINANCE_ALPHA16F_ARB
:
5251 return MESA_FORMAT_LA_FLOAT16
;
5252 case GL_LUMINANCE_ALPHA32F_ARB
:
5253 return MESA_FORMAT_LA_FLOAT32
;
5254 case GL_LUMINANCE_ALPHA8I_EXT
:
5255 return MESA_FORMAT_LA_SINT8
;
5256 case GL_LUMINANCE_ALPHA16I_EXT
:
5257 return MESA_FORMAT_LA_SINT16
;
5258 case GL_LUMINANCE_ALPHA32I_EXT
:
5259 return MESA_FORMAT_LA_SINT32
;
5260 case GL_LUMINANCE_ALPHA8UI_EXT
:
5261 return MESA_FORMAT_LA_UINT8
;
5262 case GL_LUMINANCE_ALPHA16UI_EXT
:
5263 return MESA_FORMAT_LA_UINT16
;
5264 case GL_LUMINANCE_ALPHA32UI_EXT
:
5265 return MESA_FORMAT_LA_UINT32
;
5267 return MESA_FORMAT_I_UNORM8
;
5268 case GL_INTENSITY16
:
5269 return MESA_FORMAT_I_UNORM16
;
5270 case GL_INTENSITY16F_ARB
:
5271 return MESA_FORMAT_I_FLOAT16
;
5272 case GL_INTENSITY32F_ARB
:
5273 return MESA_FORMAT_I_FLOAT32
;
5274 case GL_INTENSITY8I_EXT
:
5275 return MESA_FORMAT_I_SINT8
;
5276 case GL_INTENSITY16I_EXT
:
5277 return MESA_FORMAT_I_SINT16
;
5278 case GL_INTENSITY32I_EXT
:
5279 return MESA_FORMAT_I_SINT32
;
5280 case GL_INTENSITY8UI_EXT
:
5281 return MESA_FORMAT_I_UINT8
;
5282 case GL_INTENSITY16UI_EXT
:
5283 return MESA_FORMAT_I_UINT16
;
5284 case GL_INTENSITY32UI_EXT
:
5285 return MESA_FORMAT_I_UINT32
;
5291 if (_mesa_has_ARB_texture_buffer_object_rgb32(ctx
) ||
5292 _mesa_has_OES_texture_buffer(ctx
)) {
5293 switch (internalFormat
) {
5295 return MESA_FORMAT_RGB_FLOAT32
;
5297 return MESA_FORMAT_RGB_UINT32
;
5299 return MESA_FORMAT_RGB_SINT32
;
5305 switch (internalFormat
) {
5307 return MESA_FORMAT_R8G8B8A8_UNORM
;
5309 if (_mesa_is_gles(ctx
))
5310 return MESA_FORMAT_NONE
;
5311 return MESA_FORMAT_RGBA_UNORM16
;
5312 case GL_RGBA16F_ARB
:
5313 return MESA_FORMAT_RGBA_FLOAT16
;
5314 case GL_RGBA32F_ARB
:
5315 return MESA_FORMAT_RGBA_FLOAT32
;
5317 return MESA_FORMAT_RGBA_SINT8
;
5318 case GL_RGBA16I_EXT
:
5319 return MESA_FORMAT_RGBA_SINT16
;
5320 case GL_RGBA32I_EXT
:
5321 return MESA_FORMAT_RGBA_SINT32
;
5322 case GL_RGBA8UI_EXT
:
5323 return MESA_FORMAT_RGBA_UINT8
;
5324 case GL_RGBA16UI_EXT
:
5325 return MESA_FORMAT_RGBA_UINT16
;
5326 case GL_RGBA32UI_EXT
:
5327 return MESA_FORMAT_RGBA_UINT32
;
5330 return MESA_FORMAT_R8G8_UNORM
;
5332 if (_mesa_is_gles(ctx
))
5333 return MESA_FORMAT_NONE
;
5334 return MESA_FORMAT_R16G16_UNORM
;
5336 return MESA_FORMAT_RG_FLOAT16
;
5338 return MESA_FORMAT_RG_FLOAT32
;
5340 return MESA_FORMAT_RG_SINT8
;
5342 return MESA_FORMAT_RG_SINT16
;
5344 return MESA_FORMAT_RG_SINT32
;
5346 return MESA_FORMAT_RG_UINT8
;
5348 return MESA_FORMAT_RG_UINT16
;
5350 return MESA_FORMAT_RG_UINT32
;
5353 return MESA_FORMAT_R_UNORM8
;
5355 if (_mesa_is_gles(ctx
))
5356 return MESA_FORMAT_NONE
;
5357 return MESA_FORMAT_R_UNORM16
;
5359 return MESA_FORMAT_R_FLOAT16
;
5361 return MESA_FORMAT_R_FLOAT32
;
5363 return MESA_FORMAT_R_SINT8
;
5365 return MESA_FORMAT_R_SINT16
;
5367 return MESA_FORMAT_R_SINT32
;
5369 return MESA_FORMAT_R_UINT8
;
5371 return MESA_FORMAT_R_UINT16
;
5373 return MESA_FORMAT_R_UINT32
;
5376 return MESA_FORMAT_NONE
;
5382 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5383 GLenum internalFormat
)
5385 mesa_format format
= _mesa_get_texbuffer_format(ctx
, internalFormat
);
5388 if (format
== MESA_FORMAT_NONE
)
5389 return MESA_FORMAT_NONE
;
5391 datatype
= _mesa_get_format_datatype(format
);
5393 /* The GL_ARB_texture_buffer_object spec says:
5395 * "If ARB_texture_float is not supported, references to the
5396 * floating-point internal formats provided by that extension should be
5397 * removed, and such formats may not be passed to TexBufferARB."
5399 * As a result, GL_HALF_FLOAT internal format depends on both
5400 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5402 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5403 !ctx
->Extensions
.ARB_texture_float
)
5404 return MESA_FORMAT_NONE
;
5406 if (!ctx
->Extensions
.ARB_texture_rg
) {
5407 GLenum base_format
= _mesa_get_format_base_format(format
);
5408 if (base_format
== GL_R
|| base_format
== GL_RG
)
5409 return MESA_FORMAT_NONE
;
5412 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5413 GLenum base_format
= _mesa_get_format_base_format(format
);
5414 if (base_format
== GL_RGB
)
5415 return MESA_FORMAT_NONE
;
5422 * Do work common to glTexBuffer, glTexBufferRange, glTextureBuffer
5423 * and glTextureBufferRange, including some error checking.
5426 texture_buffer_range(struct gl_context
*ctx
,
5427 struct gl_texture_object
*texObj
,
5428 GLenum internalFormat
,
5429 struct gl_buffer_object
*bufObj
,
5430 GLintptr offset
, GLsizeiptr size
,
5433 GLintptr oldOffset
= texObj
->BufferOffset
;
5434 GLsizeiptr oldSize
= texObj
->BufferSize
;
5437 /* NOTE: ARB_texture_buffer_object has interactions with
5438 * the compatibility profile that are not implemented.
5440 if (!_mesa_has_ARB_texture_buffer_object(ctx
) &&
5441 !_mesa_has_OES_texture_buffer(ctx
)) {
5442 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5443 "%s(ARB_texture_buffer_object is not"
5444 " implemented for the compatibility profile)", caller
);
5448 if (texObj
->HandleAllocated
) {
5449 /* The ARB_bindless_texture spec says:
5451 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
5452 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
5453 * functions defined in terms of these, if the texture object to be
5454 * modified is referenced by one or more texture or image handles."
5456 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable texture)", caller
);
5460 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5461 if (format
== MESA_FORMAT_NONE
) {
5462 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat %s)",
5463 caller
, _mesa_enum_to_string(internalFormat
));
5467 FLUSH_VERTICES(ctx
, 0);
5469 _mesa_lock_texture(ctx
, texObj
);
5471 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5472 texObj
->BufferObjectFormat
= internalFormat
;
5473 texObj
->_BufferObjectFormat
= format
;
5474 texObj
->BufferOffset
= offset
;
5475 texObj
->BufferSize
= size
;
5477 _mesa_unlock_texture(ctx
, texObj
);
5479 if (ctx
->Driver
.TexParameter
) {
5480 if (offset
!= oldOffset
) {
5481 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_OFFSET
);
5483 if (size
!= oldSize
) {
5484 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_SIZE
);
5488 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5491 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5497 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5498 * Return true if it is, and return false if it is not
5499 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5500 * core spec, 02.02.2015, PDF page 245).
5503 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5506 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5507 _mesa_error(ctx
, GL_INVALID_ENUM
,
5508 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5516 * Check for errors related to the texture buffer range.
5517 * Return false if errors are found, true if none are found.
5520 check_texture_buffer_range(struct gl_context
*ctx
,
5521 struct gl_buffer_object
*bufObj
,
5522 GLintptr offset
, GLsizeiptr size
,
5525 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5526 * Textures (PDF page 245):
5527 * "An INVALID_VALUE error is generated if offset is negative, if
5528 * size is less than or equal to zero, or if offset + size is greater
5529 * than the value of BUFFER_SIZE for the buffer bound to target."
5532 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5538 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5543 if (offset
+ size
> bufObj
->Size
) {
5544 _mesa_error(ctx
, GL_INVALID_VALUE
,
5545 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5546 (int) offset
, (int) size
, (int) bufObj
->Size
);
5550 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5551 * Textures (PDF page 245):
5552 * "An INVALID_VALUE error is generated if offset is not an integer
5553 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5555 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5556 _mesa_error(ctx
, GL_INVALID_VALUE
,
5557 "%s(invalid offset alignment)", caller
);
5565 /** GL_ARB_texture_buffer_object */
5567 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5569 struct gl_texture_object
*texObj
;
5570 struct gl_buffer_object
*bufObj
;
5572 GET_CURRENT_CONTEXT(ctx
);
5574 /* Need to catch a bad target before it gets to
5575 * _mesa_get_current_tex_object.
5577 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5581 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5587 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5591 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5592 buffer
? -1 : 0, "glTexBuffer");
5596 /** GL_ARB_texture_buffer_range */
5598 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5599 GLintptr offset
, GLsizeiptr size
)
5601 struct gl_texture_object
*texObj
;
5602 struct gl_buffer_object
*bufObj
;
5604 GET_CURRENT_CONTEXT(ctx
);
5606 /* Need to catch a bad target before it gets to
5607 * _mesa_get_current_tex_object.
5609 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5613 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5617 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5618 "glTexBufferRange"))
5622 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5623 * Textures (PDF page 254):
5624 * "If buffer is zero, then any buffer object attached to the buffer
5625 * texture is detached, the values offset and size are ignored and
5626 * the state for offset and size for the buffer texture are reset to
5634 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5638 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5639 offset
, size
, "glTexBufferRange");
5643 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5645 struct gl_texture_object
*texObj
;
5646 struct gl_buffer_object
*bufObj
;
5648 GET_CURRENT_CONTEXT(ctx
);
5651 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5657 /* Get the texture object by Name. */
5658 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5662 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5665 texture_buffer_range(ctx
, texObj
, internalFormat
,
5666 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5670 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5671 GLintptr offset
, GLsizeiptr size
)
5673 struct gl_texture_object
*texObj
;
5674 struct gl_buffer_object
*bufObj
;
5676 GET_CURRENT_CONTEXT(ctx
);
5679 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5680 "glTextureBufferRange");
5684 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5685 "glTextureBufferRange"))
5689 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5690 * Textures (PDF page 254):
5691 * "If buffer is zero, then any buffer object attached to the buffer
5692 * texture is detached, the values offset and size are ignored and
5693 * the state for offset and size for the buffer texture are reset to
5701 /* Get the texture object by Name. */
5702 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5706 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5707 "glTextureBufferRange"))
5710 texture_buffer_range(ctx
, texObj
, internalFormat
,
5711 bufObj
, offset
, size
, "glTextureBufferRange");
5715 _mesa_is_renderable_texture_format(const struct gl_context
*ctx
,
5716 GLenum internalformat
)
5718 /* Everything that is allowed for renderbuffers,
5719 * except for a base format of GL_STENCIL_INDEX, unless supported.
5721 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5722 if (ctx
->Extensions
.ARB_texture_stencil8
)
5723 return baseFormat
!= 0;
5725 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5729 /** GL_ARB_texture_multisample */
5731 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5734 case GL_TEXTURE_2D_MULTISAMPLE
:
5736 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5737 return dims
== 2 && !dsa
;
5738 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5740 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5741 return dims
== 3 && !dsa
;
5749 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5750 struct gl_texture_object
*texObj
,
5751 struct gl_memory_object
*memObj
,
5752 GLenum target
, GLsizei samples
,
5753 GLint internalformat
, GLsizei width
,
5754 GLsizei height
, GLsizei depth
,
5755 GLboolean fixedsamplelocations
,
5756 GLboolean immutable
, GLuint64 offset
,
5759 struct gl_texture_image
*texImage
;
5760 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5761 mesa_format texFormat
;
5762 GLenum sample_count_error
;
5763 bool dsa
= strstr(func
, "ture") ? true : false;
5765 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
5766 _mesa_debug(ctx
, "%s(target=%s, samples=%d)\n", func
,
5767 _mesa_enum_to_string(target
), samples
);
5770 if (!((ctx
->Extensions
.ARB_texture_multisample
5771 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5772 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5777 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5781 if (!check_multisample_target(dims
, target
, dsa
)) {
5782 GLenum err
= dsa
? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
5783 _mesa_error(ctx
, err
, "%s(target=%s)", func
,
5784 _mesa_enum_to_string(target
));
5788 /* check that the specified internalformat is color/depth/stencil-renderable;
5789 * refer GL3.1 spec 4.4.4
5792 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5793 _mesa_error(ctx
, GL_INVALID_ENUM
,
5794 "%s(internalformat=%s not legal for immutable-format)",
5795 func
, _mesa_enum_to_string(internalformat
));
5799 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
)) {
5800 /* Page 172 of OpenGL ES 3.1 spec says:
5801 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5802 * color-renderable, depth-renderable, or stencil-renderable (as
5803 * defined in section 9.4).
5805 * (Same error is also defined for desktop OpenGL for multisample
5806 * teximage/texstorage functions.)
5808 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5809 _mesa_enum_to_string(internalformat
));
5813 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5814 internalformat
, samples
);
5815 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5817 /* Page 254 of OpenGL 4.4 spec says:
5818 * "Proxy arrays for two-dimensional multisample and two-dimensional
5819 * multisample array textures are operated on in the same way when
5820 * TexImage2DMultisample is called with target specified as
5821 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5822 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5823 * However, if samples is not supported, then no error is generated.
5825 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5826 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
5830 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5831 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5832 "%s(texture object 0)",
5837 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5839 if (texImage
== NULL
) {
5840 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5844 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5845 internalformat
, GL_NONE
, GL_NONE
);
5846 assert(texFormat
!= MESA_FORMAT_NONE
);
5848 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5849 width
, height
, depth
, 0);
5851 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, 0, texFormat
,
5852 samples
, width
, height
, depth
);
5854 if (_mesa_is_proxy_texture(target
)) {
5855 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5856 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5857 internalformat
, texFormat
,
5858 samples
, fixedsamplelocations
);
5861 /* clear all image fields */
5862 clear_teximage_fields(texImage
);
5866 if (!dimensionsOK
) {
5867 _mesa_error(ctx
, GL_INVALID_VALUE
,
5868 "%s(invalid width=%d or height=%d)", func
, width
, height
);
5873 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5877 /* Check if texObj->Immutable is set */
5878 if (texObj
->Immutable
) {
5879 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5883 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5885 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5886 internalformat
, texFormat
,
5887 samples
, fixedsamplelocations
);
5889 if (width
> 0 && height
> 0 && depth
> 0) {
5891 if (!ctx
->Driver
.SetTextureStorageForMemoryObject(ctx
, texObj
,
5896 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
5897 internalformat
, texFormat
);
5900 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5901 width
, height
, depth
)) {
5902 /* tidy up the texture image state. strictly speaking,
5903 * we're allowed to just leave this in whatever state we
5904 * like, but being tidy is good.
5906 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
5907 internalformat
, texFormat
);
5912 texObj
->Immutable
|= immutable
;
5915 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5918 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5924 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5925 GLenum internalformat
, GLsizei width
,
5926 GLsizei height
, GLboolean fixedsamplelocations
)
5928 struct gl_texture_object
*texObj
;
5929 GET_CURRENT_CONTEXT(ctx
);
5931 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5935 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
5936 internalformat
, width
, height
, 1,
5937 fixedsamplelocations
, GL_FALSE
, 0,
5938 "glTexImage2DMultisample");
5943 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5944 GLenum internalformat
, GLsizei width
,
5945 GLsizei height
, GLsizei depth
,
5946 GLboolean fixedsamplelocations
)
5948 struct gl_texture_object
*texObj
;
5949 GET_CURRENT_CONTEXT(ctx
);
5951 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5955 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
5956 internalformat
, width
, height
, depth
,
5957 fixedsamplelocations
, GL_FALSE
, 0,
5958 "glTexImage3DMultisample");
5962 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
5963 GLsizei samples
, unsigned dims
)
5965 GET_CURRENT_CONTEXT(ctx
);
5967 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
5968 _mesa_error(ctx
, GL_INVALID_VALUE
,
5969 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
5970 dims
, width
, height
, depth
);
5977 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5978 GLenum internalformat
, GLsizei width
,
5979 GLsizei height
, GLboolean fixedsamplelocations
)
5981 struct gl_texture_object
*texObj
;
5982 GET_CURRENT_CONTEXT(ctx
);
5984 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5988 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5991 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
5992 internalformat
, width
, height
, 1,
5993 fixedsamplelocations
, GL_TRUE
, 0,
5994 "glTexStorage2DMultisample");
5998 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5999 GLenum internalformat
, GLsizei width
,
6000 GLsizei height
, GLsizei depth
,
6001 GLboolean fixedsamplelocations
)
6003 struct gl_texture_object
*texObj
;
6004 GET_CURRENT_CONTEXT(ctx
);
6006 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6010 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
6013 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
6014 internalformat
, width
, height
, depth
,
6015 fixedsamplelocations
, GL_TRUE
, 0,
6016 "glTexStorage3DMultisample");
6020 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
6021 GLenum internalformat
, GLsizei width
,
6023 GLboolean fixedsamplelocations
)
6025 struct gl_texture_object
*texObj
;
6026 GET_CURRENT_CONTEXT(ctx
);
6028 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6029 "glTextureStorage2DMultisample");
6033 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
6036 texture_image_multisample(ctx
, 2, texObj
, NULL
, texObj
->Target
,
6037 samples
, internalformat
, width
, height
, 1,
6038 fixedsamplelocations
, GL_TRUE
, 0,
6039 "glTextureStorage2DMultisample");
6043 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
6044 GLenum internalformat
, GLsizei width
,
6045 GLsizei height
, GLsizei depth
,
6046 GLboolean fixedsamplelocations
)
6048 struct gl_texture_object
*texObj
;
6049 GET_CURRENT_CONTEXT(ctx
);
6051 /* Get the texture object by Name. */
6052 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6053 "glTextureStorage3DMultisample");
6057 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
6060 texture_image_multisample(ctx
, 3, texObj
, NULL
, texObj
->Target
, samples
,
6061 internalformat
, width
, height
, depth
,
6062 fixedsamplelocations
, GL_TRUE
, 0,
6063 "glTextureStorage3DMultisample");
6067 _mesa_texture_storage_ms_memory(struct gl_context
*ctx
, GLuint dims
,
6068 struct gl_texture_object
*texObj
,
6069 struct gl_memory_object
*memObj
,
6070 GLenum target
, GLsizei samples
,
6071 GLenum internalFormat
, GLsizei width
,
6072 GLsizei height
, GLsizei depth
,
6073 GLboolean fixedSampleLocations
,
6074 GLuint64 offset
, const char* func
)
6078 texture_image_multisample(ctx
, dims
, texObj
, memObj
, target
, samples
,
6079 internalFormat
, width
, height
, depth
,
6080 fixedSampleLocations
, GL_TRUE
, offset
,