2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
44 #include "multisample.h"
45 #include "pixelstore.h"
47 #include "texcompress.h"
48 #include "texcompress_cpal.h"
52 #include "texstorage.h"
53 #include "textureview.h"
55 #include "glformats.h"
61 * State changes which we care about for glCopyTex[Sub]Image() calls.
62 * In particular, we care about pixel transfer state and buffer state
63 * (such as glReadBuffer to make sure we read from the right renderbuffer).
65 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
68 * Returns a corresponding internal floating point format for a given base
69 * format as specifed by OES_texture_float. In case of GL_FLOAT, the internal
70 * format needs to be a 32 bit component and in case of GL_HALF_FLOAT_OES it
71 * needs to be a 16 bit component.
73 * For example, given base format GL_RGBA, type GL_FLOAT return GL_RGBA32F_ARB.
76 adjust_for_oes_float_texture(const struct gl_context
*ctx
,
77 GLenum format
, GLenum type
)
81 if (ctx
->Extensions
.OES_texture_float
) {
88 return GL_ALPHA32F_ARB
;
90 return GL_LUMINANCE32F_ARB
;
91 case GL_LUMINANCE_ALPHA
:
92 return GL_LUMINANCE_ALPHA32F_ARB
;
99 case GL_HALF_FLOAT_OES
:
100 if (ctx
->Extensions
.OES_texture_half_float
) {
107 return GL_ALPHA16F_ARB
;
109 return GL_LUMINANCE16F_ARB
;
110 case GL_LUMINANCE_ALPHA
:
111 return GL_LUMINANCE_ALPHA16F_ARB
;
126 * Returns a corresponding base format for a given internal floating point
127 * format as specifed by OES_texture_float.
130 oes_float_internal_format(const struct gl_context
*ctx
,
131 GLenum format
, GLenum type
)
135 if (ctx
->Extensions
.OES_texture_float
) {
141 case GL_ALPHA32F_ARB
:
143 case GL_LUMINANCE32F_ARB
:
145 case GL_LUMINANCE_ALPHA32F_ARB
:
146 return GL_LUMINANCE_ALPHA
;
153 case GL_HALF_FLOAT_OES
:
154 if (ctx
->Extensions
.OES_texture_half_float
) {
160 case GL_ALPHA16F_ARB
:
162 case GL_LUMINANCE16F_ARB
:
164 case GL_LUMINANCE_ALPHA16F_ARB
:
165 return GL_LUMINANCE_ALPHA
;
177 * Install gl_texture_image in a gl_texture_object according to the target
178 * and level parameters.
180 * \param tObj texture object.
181 * \param target texture target.
182 * \param level image level.
183 * \param texImage texture image.
186 set_tex_image(struct gl_texture_object
*tObj
,
187 GLenum target
, GLint level
,
188 struct gl_texture_image
*texImage
)
190 const GLuint face
= _mesa_tex_target_to_face(target
);
194 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
197 tObj
->Image
[face
][level
] = texImage
;
199 /* Set the 'back' pointer */
200 texImage
->TexObject
= tObj
;
201 texImage
->Level
= level
;
202 texImage
->Face
= face
;
207 * Free a gl_texture_image and associated data.
208 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
210 * \param texImage texture image.
212 * Free the texture image structure and the associated image data.
215 _mesa_delete_texture_image(struct gl_context
*ctx
,
216 struct gl_texture_image
*texImage
)
218 /* Free texImage->Data and/or any other driver-specific texture
221 assert(ctx
->Driver
.FreeTextureImageBuffer
);
222 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
228 * Test if a target is a proxy target.
230 * \param target texture target.
232 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
235 _mesa_is_proxy_texture(GLenum target
)
238 static const GLenum targets
[] = {
242 GL_PROXY_TEXTURE_CUBE_MAP
,
243 GL_PROXY_TEXTURE_RECTANGLE
,
244 GL_PROXY_TEXTURE_1D_ARRAY
,
245 GL_PROXY_TEXTURE_2D_ARRAY
,
246 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
247 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
248 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
251 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
252 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
254 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
256 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
257 if (target
== targets
[i
])
264 * Test if a target is an array target.
266 * \param target texture target.
268 * \return true if the target is an array target, false otherwise.
271 _mesa_is_array_texture(GLenum target
)
274 case GL_TEXTURE_1D_ARRAY
:
275 case GL_TEXTURE_2D_ARRAY
:
276 case GL_TEXTURE_CUBE_MAP_ARRAY
:
277 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
285 * Test if a target is a cube map.
287 * \param target texture target.
289 * \return true if the target is a cube map, false otherwise.
292 _mesa_is_cube_map_texture(GLenum target
)
295 case GL_TEXTURE_CUBE_MAP
:
296 case GL_TEXTURE_CUBE_MAP_ARRAY
:
304 * Return the proxy target which corresponds to the given texture target
307 proxy_target(GLenum target
)
311 case GL_PROXY_TEXTURE_1D
:
312 return GL_PROXY_TEXTURE_1D
;
314 case GL_PROXY_TEXTURE_2D
:
315 return GL_PROXY_TEXTURE_2D
;
317 case GL_PROXY_TEXTURE_3D
:
318 return GL_PROXY_TEXTURE_3D
;
319 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
320 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
321 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
322 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
323 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
324 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
325 case GL_TEXTURE_CUBE_MAP
:
326 case GL_PROXY_TEXTURE_CUBE_MAP
:
327 return GL_PROXY_TEXTURE_CUBE_MAP
;
328 case GL_TEXTURE_RECTANGLE_NV
:
329 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
330 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
331 case GL_TEXTURE_1D_ARRAY_EXT
:
332 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
333 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
334 case GL_TEXTURE_2D_ARRAY_EXT
:
335 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
336 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
337 case GL_TEXTURE_CUBE_MAP_ARRAY
:
338 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
339 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
340 case GL_TEXTURE_2D_MULTISAMPLE
:
341 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
342 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
343 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
344 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
345 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
347 _mesa_problem(NULL
, "unexpected target in proxy_target()");
356 * Get a texture image pointer from a texture object, given a texture
357 * target and mipmap level. The target and level parameters should
358 * have already been error-checked.
360 * \param texObj texture unit.
361 * \param target texture target.
362 * \param level image level.
364 * \return pointer to the texture image structure, or NULL on failure.
366 struct gl_texture_image
*
367 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
368 GLenum target
, GLint level
)
370 const GLuint face
= _mesa_tex_target_to_face(target
);
374 assert(level
< MAX_TEXTURE_LEVELS
);
376 return texObj
->Image
[face
][level
];
381 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
382 * it and install it. Only return NULL if passed a bad parameter or run
385 struct gl_texture_image
*
386 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
387 GLenum target
, GLint level
)
389 struct gl_texture_image
*texImage
;
394 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
396 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
398 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
402 set_tex_image(texObj
, target
, level
, texImage
);
410 * Return pointer to the specified proxy texture image.
411 * Note that proxy textures are per-context, not per-texture unit.
412 * \return pointer to texture image or NULL if invalid target, invalid
413 * level, or out of memory.
415 static struct gl_texture_image
*
416 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
418 struct gl_texture_image
*texImage
;
425 case GL_PROXY_TEXTURE_1D
:
426 if (level
>= ctx
->Const
.MaxTextureLevels
)
428 texIndex
= TEXTURE_1D_INDEX
;
430 case GL_PROXY_TEXTURE_2D
:
431 if (level
>= ctx
->Const
.MaxTextureLevels
)
433 texIndex
= TEXTURE_2D_INDEX
;
435 case GL_PROXY_TEXTURE_3D
:
436 if (level
>= ctx
->Const
.Max3DTextureLevels
)
438 texIndex
= TEXTURE_3D_INDEX
;
440 case GL_PROXY_TEXTURE_CUBE_MAP
:
441 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
443 texIndex
= TEXTURE_CUBE_INDEX
;
445 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
448 texIndex
= TEXTURE_RECT_INDEX
;
450 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
451 if (level
>= ctx
->Const
.MaxTextureLevels
)
453 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
455 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
456 if (level
>= ctx
->Const
.MaxTextureLevels
)
458 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
460 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
461 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
463 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
465 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
468 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
470 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
473 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
479 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
481 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
483 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
486 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
487 /* Set the 'back' pointer */
488 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
495 * Get the maximum number of allowed mipmap levels.
497 * \param ctx GL context.
498 * \param target texture target.
500 * \return the maximum number of allowed mipmap levels for the given
501 * texture target, or zero if passed a bad target.
506 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
510 case GL_PROXY_TEXTURE_1D
:
512 case GL_PROXY_TEXTURE_2D
:
513 return ctx
->Const
.MaxTextureLevels
;
515 case GL_PROXY_TEXTURE_3D
:
516 return ctx
->Const
.Max3DTextureLevels
;
517 case GL_TEXTURE_CUBE_MAP
:
518 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
519 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
520 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
521 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
522 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
523 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
524 case GL_PROXY_TEXTURE_CUBE_MAP
:
525 return ctx
->Extensions
.ARB_texture_cube_map
526 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
527 case GL_TEXTURE_RECTANGLE_NV
:
528 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
529 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
530 case GL_TEXTURE_1D_ARRAY_EXT
:
531 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
532 case GL_TEXTURE_2D_ARRAY_EXT
:
533 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
534 return ctx
->Extensions
.EXT_texture_array
535 ? ctx
->Const
.MaxTextureLevels
: 0;
536 case GL_TEXTURE_CUBE_MAP_ARRAY
:
537 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
538 return _mesa_has_texture_cube_map_array(ctx
)
539 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
540 case GL_TEXTURE_BUFFER
:
541 return (_mesa_has_ARB_texture_buffer_object(ctx
) ||
542 _mesa_has_OES_texture_buffer(ctx
)) ? 1 : 0;
543 case GL_TEXTURE_2D_MULTISAMPLE
:
544 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
545 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
546 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
547 return (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
))
548 && ctx
->Extensions
.ARB_texture_multisample
550 case GL_TEXTURE_EXTERNAL_OES
:
553 return 0; /* bad target */
559 * Return number of dimensions per mipmap level for the given texture target.
562 _mesa_get_texture_dimensions(GLenum target
)
566 case GL_PROXY_TEXTURE_1D
:
569 case GL_TEXTURE_RECTANGLE
:
570 case GL_TEXTURE_CUBE_MAP
:
571 case GL_PROXY_TEXTURE_2D
:
572 case GL_PROXY_TEXTURE_RECTANGLE
:
573 case GL_PROXY_TEXTURE_CUBE_MAP
:
574 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
575 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
576 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
577 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
578 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
579 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
580 case GL_TEXTURE_1D_ARRAY
:
581 case GL_PROXY_TEXTURE_1D_ARRAY
:
582 case GL_TEXTURE_EXTERNAL_OES
:
583 case GL_TEXTURE_2D_MULTISAMPLE
:
584 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
587 case GL_PROXY_TEXTURE_3D
:
588 case GL_TEXTURE_2D_ARRAY
:
589 case GL_PROXY_TEXTURE_2D_ARRAY
:
590 case GL_TEXTURE_CUBE_MAP_ARRAY
:
591 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
592 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
593 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
595 case GL_TEXTURE_BUFFER
:
598 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
606 * Check if a texture target can have more than one layer.
609 _mesa_tex_target_is_layered(GLenum target
)
613 case GL_PROXY_TEXTURE_1D
:
615 case GL_PROXY_TEXTURE_2D
:
616 case GL_TEXTURE_RECTANGLE
:
617 case GL_PROXY_TEXTURE_RECTANGLE
:
618 case GL_TEXTURE_2D_MULTISAMPLE
:
619 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
620 case GL_TEXTURE_BUFFER
:
621 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
622 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
623 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
624 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
625 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
626 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
627 case GL_TEXTURE_EXTERNAL_OES
:
631 case GL_PROXY_TEXTURE_3D
:
632 case GL_TEXTURE_CUBE_MAP
:
633 case GL_PROXY_TEXTURE_CUBE_MAP
:
634 case GL_TEXTURE_1D_ARRAY
:
635 case GL_PROXY_TEXTURE_1D_ARRAY
:
636 case GL_TEXTURE_2D_ARRAY
:
637 case GL_PROXY_TEXTURE_2D_ARRAY
:
638 case GL_TEXTURE_CUBE_MAP_ARRAY
:
639 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
640 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
641 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
645 assert(!"Invalid texture target.");
652 * Return the number of layers present in the given level of an array,
653 * cubemap or 3D texture. If the texture is not layered return zero.
656 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
658 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
660 switch (texObj
->Target
) {
663 case GL_TEXTURE_RECTANGLE
:
664 case GL_TEXTURE_2D_MULTISAMPLE
:
665 case GL_TEXTURE_BUFFER
:
666 case GL_TEXTURE_EXTERNAL_OES
:
669 case GL_TEXTURE_CUBE_MAP
:
672 case GL_TEXTURE_1D_ARRAY
: {
673 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
674 return img
? img
->Height
: 0;
678 case GL_TEXTURE_2D_ARRAY
:
679 case GL_TEXTURE_CUBE_MAP_ARRAY
:
680 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
681 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
682 return img
? img
->Depth
: 0;
686 assert(!"Invalid texture target.");
693 * Return the maximum number of mipmap levels for the given target
694 * and the dimensions.
695 * The dimensions are expected not to include the border.
698 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
705 case GL_TEXTURE_1D_ARRAY
:
706 case GL_PROXY_TEXTURE_1D
:
707 case GL_PROXY_TEXTURE_1D_ARRAY
:
710 case GL_TEXTURE_CUBE_MAP
:
711 case GL_TEXTURE_CUBE_MAP_ARRAY
:
712 case GL_PROXY_TEXTURE_CUBE_MAP
:
713 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
717 case GL_TEXTURE_2D_ARRAY
:
718 case GL_PROXY_TEXTURE_2D
:
719 case GL_PROXY_TEXTURE_2D_ARRAY
:
720 size
= MAX2(width
, height
);
723 case GL_PROXY_TEXTURE_3D
:
724 size
= MAX3(width
, height
, depth
);
726 case GL_TEXTURE_RECTANGLE
:
727 case GL_TEXTURE_EXTERNAL_OES
:
728 case GL_TEXTURE_2D_MULTISAMPLE
:
729 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
730 case GL_PROXY_TEXTURE_RECTANGLE
:
731 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
732 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
739 return _mesa_logbase2(size
) + 1;
743 #if 000 /* not used anymore */
745 * glTexImage[123]D can accept a NULL image pointer. In this case we
746 * create a texture image with unspecified image contents per the OpenGL
750 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
752 const GLint components
= _mesa_components_in_format(format
);
753 const GLint numPixels
= width
* height
* depth
;
754 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
758 * Let's see if anyone finds this. If glTexImage2D() is called with
759 * a NULL image pointer then load the texture image with something
760 * interesting instead of leaving it indeterminate.
763 static const char message
[8][32] = {
767 " X X XXXX XXX XXXXX ",
770 " X X XXXXX XXX X X ",
774 GLubyte
*imgPtr
= data
;
776 for (h
= 0; h
< depth
; h
++) {
777 for (i
= 0; i
< height
; i
++) {
778 GLint srcRow
= 7 - (i
% 8);
779 for (j
= 0; j
< width
; j
++) {
780 GLint srcCol
= j
% 32;
781 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
782 for (k
= 0; k
< components
; k
++) {
798 * Set the size and format-related fields of a gl_texture_image struct
799 * to zero. This is used when a proxy texture test fails.
802 clear_teximage_fields(struct gl_texture_image
*img
)
805 img
->_BaseFormat
= 0;
806 img
->InternalFormat
= 0;
817 img
->TexFormat
= MESA_FORMAT_NONE
;
819 img
->FixedSampleLocations
= GL_TRUE
;
824 * Initialize basic fields of the gl_texture_image struct.
826 * \param ctx GL context.
827 * \param img texture image structure to be initialized.
828 * \param width image width.
829 * \param height image height.
830 * \param depth image depth.
831 * \param border image border.
832 * \param internalFormat internal format.
833 * \param format the actual hardware format (one of MESA_FORMAT_*)
834 * \param numSamples number of samples per texel, or zero for non-MS.
835 * \param fixedSampleLocations are sample locations fixed?
837 * Fills in the fields of \p img with the given information.
838 * Note: width, height and depth include the border.
841 _mesa_init_teximage_fields_ms(struct gl_context
*ctx
,
842 struct gl_texture_image
*img
,
843 GLsizei width
, GLsizei height
, GLsizei depth
,
844 GLint border
, GLenum internalFormat
,
846 GLuint numSamples
, GLboolean fixedSampleLocations
)
848 const GLint base_format
=_mesa_base_tex_format(ctx
, internalFormat
);
855 target
= img
->TexObject
->Target
;
856 assert(base_format
!= -1);
857 img
->_BaseFormat
= (GLenum16
)base_format
;
858 img
->InternalFormat
= internalFormat
;
859 img
->Border
= border
;
861 img
->Height
= height
;
864 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
865 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
869 case GL_TEXTURE_BUFFER
:
870 case GL_PROXY_TEXTURE_1D
:
882 case GL_TEXTURE_1D_ARRAY
:
883 case GL_PROXY_TEXTURE_1D_ARRAY
:
884 img
->Height2
= height
; /* no border */
885 img
->HeightLog2
= 0; /* not used */
893 case GL_TEXTURE_RECTANGLE
:
894 case GL_TEXTURE_CUBE_MAP
:
895 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
896 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
897 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
898 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
899 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
900 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
901 case GL_TEXTURE_EXTERNAL_OES
:
902 case GL_PROXY_TEXTURE_2D
:
903 case GL_PROXY_TEXTURE_RECTANGLE
:
904 case GL_PROXY_TEXTURE_CUBE_MAP
:
905 case GL_TEXTURE_2D_MULTISAMPLE
:
906 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
907 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
908 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
915 case GL_TEXTURE_2D_ARRAY
:
916 case GL_PROXY_TEXTURE_2D_ARRAY
:
917 case GL_TEXTURE_CUBE_MAP_ARRAY
:
918 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
919 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
920 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
921 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
922 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
923 img
->Depth2
= depth
; /* no border */
924 img
->DepthLog2
= 0; /* not used */
927 case GL_PROXY_TEXTURE_3D
:
928 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
929 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
930 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
931 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
934 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
939 _mesa_get_tex_max_num_levels(target
,
940 img
->Width2
, img
->Height2
, img
->Depth2
);
941 img
->TexFormat
= format
;
942 img
->NumSamples
= numSamples
;
943 img
->FixedSampleLocations
= fixedSampleLocations
;
948 _mesa_init_teximage_fields(struct gl_context
*ctx
,
949 struct gl_texture_image
*img
,
950 GLsizei width
, GLsizei height
, GLsizei depth
,
951 GLint border
, GLenum internalFormat
,
954 _mesa_init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
955 internalFormat
, format
, 0, GL_TRUE
);
960 * Free and clear fields of the gl_texture_image struct.
962 * \param ctx GL context.
963 * \param texImage texture image structure to be cleared.
965 * After the call, \p texImage will have no data associated with it. Its
966 * fields are cleared so that its parent object will test incomplete.
969 _mesa_clear_texture_image(struct gl_context
*ctx
,
970 struct gl_texture_image
*texImage
)
972 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
973 clear_teximage_fields(texImage
);
978 * Check the width, height, depth and border of a texture image are legal.
979 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
981 * The target and level parameters will have already been validated.
982 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
985 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
986 GLint level
, GLint width
, GLint height
,
987 GLint depth
, GLint border
)
993 case GL_PROXY_TEXTURE_1D
:
994 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
995 maxSize
>>= level
; /* level size */
996 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
998 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
999 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1005 case GL_PROXY_TEXTURE_2D
:
1006 case GL_TEXTURE_2D_MULTISAMPLE
:
1007 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1008 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1010 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1012 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1014 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1015 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1017 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1023 case GL_PROXY_TEXTURE_3D
:
1024 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1026 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1028 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1030 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1032 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1033 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1035 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1037 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1042 case GL_TEXTURE_RECTANGLE_NV
:
1043 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1046 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1047 if (width
< 0 || width
> maxSize
)
1049 if (height
< 0 || height
> maxSize
)
1053 case GL_TEXTURE_CUBE_MAP
:
1054 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1055 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1056 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1057 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1058 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1059 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1060 case GL_PROXY_TEXTURE_CUBE_MAP
:
1061 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1063 if (width
!= height
)
1065 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1067 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1069 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1070 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1072 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1077 case GL_TEXTURE_1D_ARRAY_EXT
:
1078 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1079 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1081 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1083 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1085 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1086 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1091 case GL_TEXTURE_2D_ARRAY_EXT
:
1092 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1093 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1094 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1095 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1097 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1099 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1101 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1103 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1104 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1106 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1111 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1112 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1113 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1114 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1116 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1118 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1120 if (width
!= height
)
1122 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1124 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1125 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1127 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1132 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1138 error_check_subtexture_negative_dimensions(struct gl_context
*ctx
,
1147 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(width=%d)", func
, subWidth
);
1151 if (dims
> 1 && subHeight
< 0) {
1152 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(height=%d)", func
, subHeight
);
1156 if (dims
> 2 && subDepth
< 0) {
1157 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(depth=%d)", func
, subDepth
);
1165 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1166 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1167 * \param destImage the destination texture image.
1168 * \return GL_TRUE if error found, GL_FALSE otherwise.
1171 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1172 const struct gl_texture_image
*destImage
,
1173 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1174 GLsizei subWidth
, GLsizei subHeight
,
1175 GLsizei subDepth
, const char *func
)
1177 const GLenum target
= destImage
->TexObject
->Target
;
1180 /* check xoffset and width */
1181 if (xoffset
< - (GLint
) destImage
->Border
) {
1182 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset)", func
);
1186 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1187 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset %d + width %d > %u)", func
,
1188 xoffset
, subWidth
, destImage
->Width
);
1192 /* check yoffset and height */
1194 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1195 if (yoffset
< -yBorder
) {
1196 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset)", func
);
1199 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1200 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset %d + height %d > %u)",
1201 func
, yoffset
, subHeight
, destImage
->Height
);
1206 /* check zoffset and depth */
1209 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1210 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1211 0 : destImage
->Border
;
1213 if (zoffset
< -zBorder
) {
1214 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset)", func
);
1218 depth
= (GLint
) destImage
->Depth
;
1219 if (target
== GL_TEXTURE_CUBE_MAP
)
1221 if (zoffset
+ subDepth
> depth
) {
1222 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset %d + depth %d > %u)",
1223 func
, zoffset
, subDepth
, depth
);
1229 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1230 * compressed texture images can be updated. But, that restriction may be
1231 * relaxed for particular compressed formats. At this time, all the
1232 * compressed formats supported by Mesa allow sub-textures to be updated
1233 * along compressed block boundaries.
1235 _mesa_get_format_block_size_3d(destImage
->TexFormat
, &bw
, &bh
, &bd
);
1237 if (bw
!= 1 || bh
!= 1 || bd
!= 1) {
1238 /* offset must be multiple of block size */
1239 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0) || (zoffset
% bd
!= 0)) {
1240 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1241 "%s(xoffset = %d, yoffset = %d, zoffset = %d)",
1242 func
, xoffset
, yoffset
, zoffset
);
1246 /* The size must be a multiple of bw x bh, or we must be using a
1247 * offset+size that exactly hits the edge of the image. This
1248 * is important for small mipmap levels (1x1, 2x1, etc) and for
1251 if ((subWidth
% bw
!= 0) &&
1252 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1253 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1254 "%s(width = %d)", func
, subWidth
);
1258 if ((subHeight
% bh
!= 0) &&
1259 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1260 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1261 "%s(height = %d)", func
, subHeight
);
1265 if ((subDepth
% bd
!= 0) &&
1266 (zoffset
+ subDepth
!= (GLint
) destImage
->Depth
)) {
1267 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1268 "%s(depth = %d)", func
, subDepth
);
1280 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1281 * specific texture image size checks.
1283 * A hardware driver might override this function if, for example, the
1284 * max 3D texture size is 512x512x64 (i.e. not a cube).
1286 * Note that width, height, depth == 0 is not an error. However, a
1287 * texture with zero width/height/depth will be considered "incomplete"
1288 * and texturing will effectively be disabled.
1290 * \param target any texture target/type
1291 * \param numLevels number of mipmap levels in the texture or 0 if not known
1292 * \param level as passed to glTexImage
1293 * \param format the MESA_FORMAT_x for the tex image
1294 * \param numSamples number of samples per texel
1295 * \param width as passed to glTexImage
1296 * \param height as passed to glTexImage
1297 * \param depth as passed to glTexImage
1298 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1301 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
,
1302 GLuint numLevels
, MAYBE_UNUSED GLint level
,
1303 mesa_format format
, GLuint numSamples
,
1304 GLint width
, GLint height
, GLint depth
)
1306 uint64_t bytes
, mbytes
;
1308 if (numLevels
> 0) {
1309 /* Compute total memory for a whole mipmap. This is the path
1310 * taken for glTexStorage(GL_PROXY_TEXTURE_x).
1318 for (l
= 0; l
< numLevels
; l
++) {
1319 GLint nextWidth
, nextHeight
, nextDepth
;
1321 bytes
+= _mesa_format_image_size64(format
, width
, height
, depth
);
1323 if (_mesa_next_mipmap_level_size(target
, 0, width
, height
, depth
,
1324 &nextWidth
, &nextHeight
,
1327 height
= nextHeight
;
1334 /* We just compute the size of one mipmap level. This is the path
1335 * taken for glTexImage(GL_PROXY_TEXTURE_x).
1337 bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1340 bytes
*= _mesa_num_tex_faces(target
);
1341 bytes
*= MAX2(1, numSamples
);
1343 mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1345 /* We just check if the image size is less than MaxTextureMbytes.
1346 * Some drivers may do more specific checks.
1348 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1353 * Return true if the format is only valid for glCompressedTexImage.
1356 compressedteximage_only_format(GLenum format
)
1359 case GL_PALETTE4_RGB8_OES
:
1360 case GL_PALETTE4_RGBA8_OES
:
1361 case GL_PALETTE4_R5_G6_B5_OES
:
1362 case GL_PALETTE4_RGBA4_OES
:
1363 case GL_PALETTE4_RGB5_A1_OES
:
1364 case GL_PALETTE8_RGB8_OES
:
1365 case GL_PALETTE8_RGBA8_OES
:
1366 case GL_PALETTE8_R5_G6_B5_OES
:
1367 case GL_PALETTE8_RGBA4_OES
:
1368 case GL_PALETTE8_RGB5_A1_OES
:
1376 * Return true if the format doesn't support online compression.
1379 _mesa_format_no_online_compression(GLenum format
)
1381 return _mesa_is_astc_format(format
) ||
1382 _mesa_is_etc2_format(format
) ||
1383 compressedteximage_only_format(format
);
1386 /* Writes to an GL error pointer if non-null and returns whether or not the
1387 * error is GL_NO_ERROR */
1389 write_error(GLenum
*err_ptr
, GLenum error
)
1394 return error
== GL_NO_ERROR
;
1398 * Helper function to determine whether a target and specific compression
1399 * format are supported. The error parameter returns GL_NO_ERROR if the
1400 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1401 * or GL_INVALID_ENUM, whichever is more appropriate.
1404 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1405 GLenum intFormat
, GLenum
*error
)
1407 GLboolean target_can_be_compresed
= GL_FALSE
;
1408 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1409 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1413 case GL_PROXY_TEXTURE_2D
:
1414 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1416 case GL_PROXY_TEXTURE_CUBE_MAP
:
1417 case GL_TEXTURE_CUBE_MAP
:
1418 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1419 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1420 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1421 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1422 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1423 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1424 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1426 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1427 case GL_TEXTURE_2D_ARRAY_EXT
:
1428 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1430 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1431 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1432 /* From the KHR_texture_compression_astc_hdr spec:
1434 * Add a second new column "3D Tex." which is empty for all non-ASTC
1435 * formats. If only the LDR profile is supported by the
1436 * implementation, this column is also empty for all ASTC formats. If
1437 * both the LDR and HDR profiles are supported only, this column is
1438 * checked for all ASTC formats.
1440 * Add a third new column "Cube Map Array Tex." which is empty for all
1441 * non-ASTC formats, and checked for all ASTC formats.
1445 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1446 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1447 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1448 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1449 * 8.19 is *not* checked'
1451 * The instances of <internalformat> above should say <target>.
1453 * ETC2/EAC formats are the only alternative in GLES and thus such errors
1454 * have already been handled by normal ETC2/EAC behavior.
1457 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1459 * "The ETC2/EAC texture compression algorithm supports only
1460 * two-dimensional images. If internalformat is an ETC2/EAC format,
1461 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1462 * target is not TEXTURE_2D_ARRAY."
1464 * This should also be applicable for glTexStorage3D(). Other available
1465 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1467 * Section 8.7, page 179 of OpenGL ES 3.2 adds:
1469 * An INVALID_OPERATION error is generated by CompressedTexImage3D
1470 * if internalformat is one of the the formats in table 8.17 and target is
1471 * not TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY or TEXTURE_3D.
1473 * An INVALID_OPERATION error is generated by CompressedTexImage3D
1474 * if internalformat is TEXTURE_CUBE_MAP_ARRAY and the “Cube Map
1475 * Array” column of table 8.17 is not checked, or if internalformat
1476 * is TEXTURE_- 3D and the “3D Tex.” column of table 8.17 is not
1479 * The instances of <internalformat> above should say <target>.
1481 * Such table 8.17 has checked "Cube Map Array" column for all the
1482 * cases. So in practice, TEXTURE_CUBE_MAP_ARRAY is now valid for OpenGL ES 3.2
1484 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
) &&
1485 !_mesa_is_gles32(ctx
))
1486 return write_error(error
, GL_INVALID_OPERATION
);
1487 target_can_be_compresed
= _mesa_has_texture_cube_map_array(ctx
);
1491 case MESA_FORMAT_LAYOUT_ETC2
:
1492 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1493 if (_mesa_is_gles3(ctx
))
1494 return write_error(error
, GL_INVALID_OPERATION
);
1496 case MESA_FORMAT_LAYOUT_BPTC
:
1497 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1499 case MESA_FORMAT_LAYOUT_ASTC
:
1500 target_can_be_compresed
=
1501 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
1502 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
1504 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1505 * neither of the above extensions are supported. See comment in
1506 * switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1508 if (!target_can_be_compresed
)
1509 return write_error(error
, GL_INVALID_OPERATION
);
1517 return write_error(error
,
1518 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1523 * Check if the given texture target value is legal for a
1524 * glTexImage1/2/3D call.
1527 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1533 case GL_PROXY_TEXTURE_1D
:
1534 return _mesa_is_desktop_gl(ctx
);
1542 case GL_PROXY_TEXTURE_2D
:
1543 return _mesa_is_desktop_gl(ctx
);
1544 case GL_PROXY_TEXTURE_CUBE_MAP
:
1545 return _mesa_is_desktop_gl(ctx
)
1546 && ctx
->Extensions
.ARB_texture_cube_map
;
1547 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1548 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1549 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1550 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1551 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1552 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1553 return ctx
->Extensions
.ARB_texture_cube_map
;
1554 case GL_TEXTURE_RECTANGLE_NV
:
1555 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1556 return _mesa_is_desktop_gl(ctx
)
1557 && ctx
->Extensions
.NV_texture_rectangle
;
1558 case GL_TEXTURE_1D_ARRAY_EXT
:
1559 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1560 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1568 case GL_PROXY_TEXTURE_3D
:
1569 return _mesa_is_desktop_gl(ctx
);
1570 case GL_TEXTURE_2D_ARRAY_EXT
:
1571 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1572 || _mesa_is_gles3(ctx
);
1573 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1574 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1575 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1576 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1577 return _mesa_has_texture_cube_map_array(ctx
);
1582 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1589 * Check if the given texture target value is legal for a
1590 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1591 * The difference compared to legal_teximage_target() above is that
1592 * proxy targets are not supported.
1595 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1600 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1605 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1606 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1607 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1608 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1609 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1610 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1611 return ctx
->Extensions
.ARB_texture_cube_map
;
1612 case GL_TEXTURE_RECTANGLE_NV
:
1613 return _mesa_is_desktop_gl(ctx
)
1614 && ctx
->Extensions
.NV_texture_rectangle
;
1615 case GL_TEXTURE_1D_ARRAY_EXT
:
1616 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1624 case GL_TEXTURE_2D_ARRAY_EXT
:
1625 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1626 || _mesa_is_gles3(ctx
);
1627 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1628 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1629 return _mesa_has_texture_cube_map_array(ctx
);
1631 /* Table 8.15 of the OpenGL 4.5 core profile spec
1632 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1633 * and CopyTextureSubImage3D.
1635 case GL_TEXTURE_CUBE_MAP
:
1641 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1649 * Helper function to determine if a texture object is mutable (in terms
1650 * of GL_ARB_texture_storage/GL_ARB_bindless_texture).
1653 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1655 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1659 if (texObj
->HandleAllocated
) {
1660 /* The ARB_bindless_texture spec says:
1662 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
1663 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
1664 * functions defined in terms of these, if the texture object to be
1665 * modified is referenced by one or more texture or image handles."
1670 return !texObj
->Immutable
;
1675 * Return expected size of a compressed texture.
1678 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1681 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1682 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1686 * Verify that a texture format is valid with a particular target
1688 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1689 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1692 * \param ctx GL context
1693 * \param target Texture target
1694 * \param internalFormat Internal format of the texture image
1696 * \returns true if the combination is legal, false otherwise.
1699 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1700 GLenum target
, GLenum internalFormat
)
1702 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1703 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
1704 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
1705 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1706 * Profile spec says:
1708 * "Textures with a base internal format of DEPTH_COMPONENT or
1709 * DEPTH_STENCIL are supported by texture image specification
1710 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1711 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1712 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1713 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1714 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1715 * formats in conjunction with any other target will result in an
1716 * INVALID_OPERATION error."
1718 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1719 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1721 if (target
!= GL_TEXTURE_1D
&&
1722 target
!= GL_PROXY_TEXTURE_1D
&&
1723 target
!= GL_TEXTURE_2D
&&
1724 target
!= GL_PROXY_TEXTURE_2D
&&
1725 target
!= GL_TEXTURE_1D_ARRAY
&&
1726 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1727 target
!= GL_TEXTURE_2D_ARRAY
&&
1728 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1729 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1730 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1731 !((_mesa_is_cube_face(target
) ||
1732 target
== GL_TEXTURE_CUBE_MAP
||
1733 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1734 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
1735 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
1736 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
1737 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
1738 _mesa_has_texture_cube_map_array(ctx
))) {
1747 texture_formats_agree(GLenum internalFormat
,
1750 GLboolean colorFormat
;
1751 GLboolean is_format_depth_or_depthstencil
;
1752 GLboolean is_internalFormat_depth_or_depthstencil
;
1754 /* Even though there are no color-index textures, we still have to support
1755 * uploading color-index data and remapping it to RGB via the
1756 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1758 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1760 is_internalFormat_depth_or_depthstencil
=
1761 _mesa_is_depth_format(internalFormat
) ||
1762 _mesa_is_depthstencil_format(internalFormat
);
1764 is_format_depth_or_depthstencil
=
1765 _mesa_is_depth_format(format
) ||
1766 _mesa_is_depthstencil_format(format
);
1768 colorFormat
= _mesa_is_color_format(format
);
1770 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
1773 if (is_internalFormat_depth_or_depthstencil
!=
1774 is_format_depth_or_depthstencil
)
1777 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
1784 * Test the combination of format, type and internal format arguments of
1785 * different texture operations on GLES.
1787 * \param ctx GL context.
1788 * \param format pixel data format given by the user.
1789 * \param type pixel data type given by the user.
1790 * \param internalFormat internal format given by the user.
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
, const char *callerName
)
1801 GLenum err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
1803 if (err
!= GL_NO_ERROR
) {
1804 _mesa_error(ctx
, err
,
1805 "%s(format = %s, type = %s, internalformat = %s)",
1806 callerName
, _mesa_enum_to_string(format
),
1807 _mesa_enum_to_string(type
),
1808 _mesa_enum_to_string(internalFormat
));
1816 * Test the glTexImage[123]D() parameters for errors.
1818 * \param ctx GL context.
1819 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1820 * \param target texture target given by the user (already validated).
1821 * \param level image level given by the user.
1822 * \param internalFormat internal format given by the user.
1823 * \param format pixel data format given by the user.
1824 * \param type pixel data type given by the user.
1825 * \param width image width given by the user.
1826 * \param height image height given by the user.
1827 * \param depth image depth given by the user.
1828 * \param border image border given by the user.
1830 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1832 * Verifies each of the parameters against the constants specified in
1833 * __struct gl_contextRec::Const and the supported extensions, and according
1834 * to the OpenGL specification.
1835 * Note that we don't fully error-check the width, height, depth values
1836 * here. That's done in _mesa_legal_texture_dimensions() which is used
1837 * by several other GL entrypoints. Plus, texture dims have a special
1838 * interaction with proxy textures.
1841 texture_error_check( struct gl_context
*ctx
,
1842 GLuint dimensions
, GLenum target
,
1843 GLint level
, GLint internalFormat
,
1844 GLenum format
, GLenum type
,
1845 GLint width
, GLint height
,
1846 GLint depth
, GLint border
,
1847 const GLvoid
*pixels
)
1851 /* Note: for proxy textures, some error conditions immediately generate
1852 * a GL error in the usual way. But others do not generate a GL error.
1853 * Instead, they cause the width, height, depth, format fields of the
1854 * texture image to be zeroed-out. The GL spec seems to indicate that the
1855 * zero-out behaviour is only used in cases related to memory allocation.
1859 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1860 _mesa_error(ctx
, GL_INVALID_VALUE
,
1861 "glTexImage%dD(level=%d)", dimensions
, level
);
1866 if (border
< 0 || border
> 1 ||
1867 ((ctx
->API
!= API_OPENGL_COMPAT
||
1868 target
== GL_TEXTURE_RECTANGLE_NV
||
1869 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1870 _mesa_error(ctx
, GL_INVALID_VALUE
,
1871 "glTexImage%dD(border=%d)", dimensions
, border
);
1875 if (width
< 0 || height
< 0 || depth
< 0) {
1876 _mesa_error(ctx
, GL_INVALID_VALUE
,
1877 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1881 /* Check incoming image format and type */
1882 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1883 if (err
!= GL_NO_ERROR
) {
1884 /* Prior to OpenGL-ES 2.0, an INVALID_VALUE is expected instead of
1885 * INVALID_ENUM. From page 73 OpenGL ES 1.1 spec:
1887 * "Specifying a value for internalformat that is not one of the
1888 * above (acceptable) values generates the error INVALID VALUE."
1890 if (err
== GL_INVALID_ENUM
&& _mesa_is_gles(ctx
) && ctx
->Version
< 20)
1891 err
= GL_INVALID_VALUE
;
1893 _mesa_error(ctx
, err
,
1894 "glTexImage%dD(incompatible format = %s, type = %s)",
1895 dimensions
, _mesa_enum_to_string(format
),
1896 _mesa_enum_to_string(type
));
1900 /* Check internalFormat */
1901 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1902 _mesa_error(ctx
, GL_INVALID_VALUE
,
1903 "glTexImage%dD(internalFormat=%s)",
1904 dimensions
, _mesa_enum_to_string(internalFormat
));
1908 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1909 * combinations of format, internalFormat, and type that can be used.
1910 * Formats and types that require additional extensions (e.g., GL_FLOAT
1911 * requires GL_OES_texture_float) are filtered elsewhere.
1913 char bufCallerName
[20];
1914 _mesa_snprintf(bufCallerName
, 20, "glTexImage%dD", dimensions
);
1915 if (_mesa_is_gles(ctx
) &&
1916 texture_format_error_check_gles(ctx
, format
, type
,
1917 internalFormat
, bufCallerName
)) {
1921 /* validate the bound PBO, if any */
1922 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
1923 width
, height
, depth
, format
, type
,
1924 INT_MAX
, pixels
, "glTexImage")) {
1928 /* make sure internal format and format basically agree */
1929 if (!texture_formats_agree(internalFormat
, format
)) {
1930 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1931 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
1932 dimensions
, _mesa_enum_to_string(internalFormat
),
1933 _mesa_enum_to_string(format
));
1937 /* additional checks for ycbcr textures */
1938 if (internalFormat
== GL_YCBCR_MESA
) {
1939 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
1940 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1941 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1943 _mesa_snprintf(message
, sizeof(message
),
1944 "glTexImage%dD(format/type YCBCR mismatch)",
1946 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1947 return GL_TRUE
; /* error */
1949 if (target
!= GL_TEXTURE_2D
&&
1950 target
!= GL_PROXY_TEXTURE_2D
&&
1951 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1952 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1953 _mesa_error(ctx
, GL_INVALID_ENUM
,
1954 "glTexImage%dD(bad target for YCbCr texture)",
1960 _mesa_snprintf(message
, sizeof(message
),
1961 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1962 dimensions
, border
);
1963 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1968 /* additional checks for depth textures */
1969 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
)) {
1970 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1971 "glTexImage%dD(bad target for texture)", dimensions
);
1975 /* additional checks for compressed textures */
1976 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1978 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
1979 _mesa_error(ctx
, err
,
1980 "glTexImage%dD(target can't be compressed)", dimensions
);
1983 if (_mesa_format_no_online_compression(internalFormat
)) {
1984 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1985 "glTexImage%dD(no compression for format)", dimensions
);
1989 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1990 "glTexImage%dD(border!=0)", dimensions
);
1995 /* additional checks for integer textures */
1996 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1997 (_mesa_is_enum_format_integer(format
) !=
1998 _mesa_is_enum_format_integer(internalFormat
))) {
1999 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2000 "glTexImage%dD(integer/non-integer format mismatch)",
2005 if (!mutable_tex_object(ctx
, target
)) {
2006 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2007 "glTexImage%dD(immutable texture)", dimensions
);
2011 /* if we get here, the parameters are OK */
2017 * Error checking for glCompressedTexImage[123]D().
2018 * Note that the width, height and depth values are not fully error checked
2020 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2023 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2024 GLenum target
, GLint level
,
2025 GLenum internalFormat
, GLsizei width
,
2026 GLsizei height
, GLsizei depth
, GLint border
,
2027 GLsizei imageSize
, const GLvoid
*data
)
2029 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2031 GLenum error
= GL_NO_ERROR
;
2032 char *reason
= ""; /* no error */
2034 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
2039 /* This will detect any invalid internalFormat value */
2040 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2041 _mesa_error(ctx
, GL_INVALID_ENUM
,
2042 "glCompressedTexImage%dD(internalFormat=%s)",
2043 dimensions
, _mesa_enum_to_string(internalFormat
));
2047 /* validate the bound PBO, if any */
2048 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2050 "glCompressedTexImage")) {
2054 switch (internalFormat
) {
2055 case GL_PALETTE4_RGB8_OES
:
2056 case GL_PALETTE4_RGBA8_OES
:
2057 case GL_PALETTE4_R5_G6_B5_OES
:
2058 case GL_PALETTE4_RGBA4_OES
:
2059 case GL_PALETTE4_RGB5_A1_OES
:
2060 case GL_PALETTE8_RGB8_OES
:
2061 case GL_PALETTE8_RGBA8_OES
:
2062 case GL_PALETTE8_R5_G6_B5_OES
:
2063 case GL_PALETTE8_RGBA4_OES
:
2064 case GL_PALETTE8_RGB5_A1_OES
:
2065 /* check level (note that level should be zero or less!) */
2066 if (level
> 0 || level
< -maxLevels
) {
2068 error
= GL_INVALID_VALUE
;
2072 if (dimensions
!= 2) {
2073 reason
= "compressed paletted textures must be 2D";
2074 error
= GL_INVALID_OPERATION
;
2078 /* Figure out the expected texture size (in bytes). This will be
2079 * checked against the actual size later.
2081 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2084 /* This is for the benefit of the TestProxyTexImage below. It expects
2085 * level to be non-negative. OES_compressed_paletted_texture uses a
2086 * weird mechanism where the level specified to glCompressedTexImage2D
2087 * is -(n-1) number of levels in the texture, and the data specifies the
2088 * complete mipmap stack. This is done to ensure the palette is the
2089 * same for all levels.
2096 if (level
< 0 || level
>= maxLevels
) {
2098 error
= GL_INVALID_VALUE
;
2102 /* Figure out the expected texture size (in bytes). This will be
2103 * checked against the actual size later.
2105 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2109 /* This should really never fail */
2110 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2111 reason
= "internalFormat";
2112 error
= GL_INVALID_ENUM
;
2116 /* No compressed formats support borders at this time */
2118 reason
= "border != 0";
2119 error
= GL_INVALID_VALUE
;
2123 /* Check for invalid pixel storage modes */
2124 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2126 "glCompressedTexImage")) {
2130 /* check image size in bytes */
2131 if (expectedSize
!= imageSize
) {
2132 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2133 * if <imageSize> is not consistent with the format, dimensions, and
2134 * contents of the specified image.
2136 reason
= "imageSize inconsistent with width/height/format";
2137 error
= GL_INVALID_VALUE
;
2141 if (!mutable_tex_object(ctx
, target
)) {
2142 reason
= "immutable texture";
2143 error
= GL_INVALID_OPERATION
;
2150 /* Note: not all error paths exit through here. */
2151 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2152 dimensions
, reason
);
2159 * Test glTexSubImage[123]D() parameters for errors.
2161 * \param ctx GL context.
2162 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2163 * \param target texture target given by the user (already validated)
2164 * \param level image level given by the user.
2165 * \param xoffset sub-image x offset given by the user.
2166 * \param yoffset sub-image y offset given by the user.
2167 * \param zoffset sub-image z offset given by the user.
2168 * \param format pixel data format given by the user.
2169 * \param type pixel data type given by the user.
2170 * \param width image width given by the user.
2171 * \param height image height given by the user.
2172 * \param depth image depth given by the user.
2174 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2176 * Verifies each of the parameters against the constants specified in
2177 * __struct gl_contextRec::Const and the supported extensions, and according
2178 * to the OpenGL specification.
2181 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2182 struct gl_texture_object
*texObj
,
2183 GLenum target
, GLint level
,
2184 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2185 GLint width
, GLint height
, GLint depth
,
2186 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2187 const char *callerName
)
2189 struct gl_texture_image
*texImage
;
2193 /* must be out of memory */
2194 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2199 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2200 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2204 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2205 width
, height
, depth
,
2210 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2212 /* non-existant texture level */
2213 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture level %d)",
2218 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2219 if (err
!= GL_NO_ERROR
) {
2220 _mesa_error(ctx
, err
,
2221 "%s(incompatible format = %s, type = %s)",
2222 callerName
, _mesa_enum_to_string(format
),
2223 _mesa_enum_to_string(type
));
2227 GLenum internalFormat
= _mesa_is_gles(ctx
) ?
2228 oes_float_internal_format(ctx
, texImage
->InternalFormat
, type
) :
2229 texImage
->InternalFormat
;
2231 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2232 * combinations of format, internalFormat, and type that can be used.
2233 * Formats and types that require additional extensions (e.g., GL_FLOAT
2234 * requires GL_OES_texture_float) are filtered elsewhere.
2236 if (_mesa_is_gles(ctx
) &&
2237 texture_format_error_check_gles(ctx
, format
, type
,
2238 internalFormat
, 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(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
,
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(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(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 /* From OpenGL ES 3.2 spec, section 8.6:
2629 * "An INVALID_OPERATION error is generated by CopyTexSubImage3D,
2630 * CopyTexImage2D, or CopyTexSubImage2D if the internalformat of the
2631 * texture image being (re)specified is RGB9_E5"
2633 if (texImage
->InternalFormat
== GL_RGB9_E5
&&
2634 !_mesa_is_desktop_gl(ctx
)) {
2635 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2636 "%s(invalid internal format %s)", caller
,
2637 _mesa_enum_to_string(texImage
->InternalFormat
));
2641 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2642 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2643 "%s(missing readbuffer, format=%s)", caller
,
2644 _mesa_enum_to_string(texImage
->_BaseFormat
));
2648 /* From the EXT_texture_integer spec:
2650 * "INVALID_OPERATION is generated by CopyTexImage* and
2651 * CopyTexSubImage* if the texture internalformat is an integer format
2652 * and the read color buffer is not an integer format, or if the
2653 * internalformat is not an integer format and the read color buffer
2654 * is an integer format."
2656 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2657 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2659 if (_mesa_is_format_integer_color(rb
->Format
) !=
2660 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2661 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2662 "%s(integer vs non-integer)", caller
);
2667 /* In the ES 3.2 specification's Table 8.13 (Valid CopyTexImage source
2668 * framebuffer/destination texture base internal format combinations),
2669 * all the entries for stencil are left blank (unsupported).
2671 if (_mesa_is_gles(ctx
) && _mesa_is_stencil_format(texImage
->_BaseFormat
)) {
2672 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(stencil disallowed)", caller
);
2676 /* if we get here, the parameters are OK */
2681 /** Callback info for walking over FBO hash table */
2684 struct gl_context
*ctx
;
2685 struct gl_texture_object
*texObj
;
2691 * Check render to texture callback. Called from _mesa_HashWalk().
2694 check_rtt_cb(UNUSED GLuint key
, void *data
, void *userData
)
2696 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2697 const struct cb_info
*info
= (struct cb_info
*) userData
;
2698 struct gl_context
*ctx
= info
->ctx
;
2699 const struct gl_texture_object
*texObj
= info
->texObj
;
2700 const GLuint level
= info
->level
, face
= info
->face
;
2702 /* If this is a user-created FBO */
2703 if (_mesa_is_user_fbo(fb
)) {
2705 /* check if any of the FBO's attachments point to 'texObj' */
2706 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2707 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2708 if (att
->Type
== GL_TEXTURE
&&
2709 att
->Texture
== texObj
&&
2710 att
->TextureLevel
== level
&&
2711 att
->CubeMapFace
== face
) {
2712 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
2713 assert(att
->Renderbuffer
->TexImage
);
2714 /* Mark fb status as indeterminate to force re-validation */
2717 /* Make sure that the revalidation actually happens if this is
2718 * being done to currently-bound buffers.
2720 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
)
2721 ctx
->NewState
|= _NEW_BUFFERS
;
2729 * When a texture image is specified we have to check if it's bound to
2730 * any framebuffer objects (render to texture) in order to detect changes
2731 * in size or format since that effects FBO completeness.
2732 * Any FBOs rendering into the texture must be re-validated.
2735 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2736 struct gl_texture_object
*texObj
,
2737 GLuint face
, GLuint level
)
2739 /* Only check this texture if it's been marked as RenderToTexture */
2740 if (texObj
->_RenderToTexture
) {
2741 struct cb_info info
;
2743 info
.texObj
= texObj
;
2746 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2752 * If the texture object's GenerateMipmap flag is set and we've
2753 * changed the texture base level image, regenerate the rest of the
2754 * mipmap levels now.
2757 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2758 struct gl_texture_object
*texObj
, GLint level
)
2760 if (texObj
->GenerateMipmap
&&
2761 level
== texObj
->BaseLevel
&&
2762 level
< texObj
->MaxLevel
) {
2763 assert(ctx
->Driver
.GenerateMipmap
);
2764 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2769 /** Debug helper: override the user-requested internal format */
2771 override_internal_format(GLenum internalFormat
, UNUSED GLint width
,
2772 UNUSED GLint height
)
2775 if (internalFormat
== GL_RGBA16F_ARB
||
2776 internalFormat
== GL_RGBA32F_ARB
) {
2777 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2780 else if (internalFormat
== GL_RGB16F_ARB
||
2781 internalFormat
== GL_RGB32F_ARB
) {
2782 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2785 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2786 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2787 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2788 return GL_LUMINANCE_ALPHA
;
2790 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2791 internalFormat
== GL_LUMINANCE32F_ARB
) {
2792 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2793 return GL_LUMINANCE
;
2795 else if (internalFormat
== GL_ALPHA16F_ARB
||
2796 internalFormat
== GL_ALPHA32F_ARB
) {
2797 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2801 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2802 internalFormat = GL_RGBA;
2806 return internalFormat
;
2809 return internalFormat
;
2815 * Choose the actual hardware format for a texture image.
2816 * Try to use the same format as the previous image level when possible.
2817 * Otherwise, ask the driver for the best format.
2818 * It's important to try to choose a consistant format for all levels
2819 * for efficient texture memory layout/allocation. In particular, this
2820 * comes up during automatic mipmap generation.
2823 _mesa_choose_texture_format(struct gl_context
*ctx
,
2824 struct gl_texture_object
*texObj
,
2825 GLenum target
, GLint level
,
2826 GLenum internalFormat
, GLenum format
, GLenum type
)
2830 /* see if we've already chosen a format for the previous level */
2832 struct gl_texture_image
*prevImage
=
2833 _mesa_select_tex_image(texObj
, target
, level
- 1);
2834 /* See if the prev level is defined and has an internal format which
2835 * matches the new internal format.
2838 prevImage
->Width
> 0 &&
2839 prevImage
->InternalFormat
== internalFormat
) {
2840 /* use the same format */
2841 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2842 return prevImage
->TexFormat
;
2846 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
2848 assert(f
!= MESA_FORMAT_NONE
);
2854 * Adjust pixel unpack params and image dimensions to strip off the
2855 * one-pixel texture border.
2857 * Gallium and intel don't support texture borders. They've seldem been used
2858 * and seldom been implemented correctly anyway.
2860 * \param unpackNew returns the new pixel unpack parameters
2863 strip_texture_border(GLenum target
,
2864 GLint
*width
, GLint
*height
, GLint
*depth
,
2865 const struct gl_pixelstore_attrib
*unpack
,
2866 struct gl_pixelstore_attrib
*unpackNew
)
2872 *unpackNew
= *unpack
;
2874 if (unpackNew
->RowLength
== 0)
2875 unpackNew
->RowLength
= *width
;
2877 if (unpackNew
->ImageHeight
== 0)
2878 unpackNew
->ImageHeight
= *height
;
2880 assert(*width
>= 3);
2881 unpackNew
->SkipPixels
++; /* skip the border */
2882 *width
= *width
- 2; /* reduce the width by two border pixels */
2884 /* The min height of a texture with a border is 3 */
2885 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2886 unpackNew
->SkipRows
++; /* skip the border */
2887 *height
= *height
- 2; /* reduce the height by two border pixels */
2891 target
!= GL_TEXTURE_2D_ARRAY
&&
2892 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2893 unpackNew
->SkipImages
++; /* skip the border */
2894 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2900 * Common code to implement all the glTexImage1D/2D/3D functions
2901 * as well as glCompressedTexImage1D/2D/3D.
2902 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2903 * \param format the user's image format (only used if !compressed)
2904 * \param type the user's image type (only used if !compressed)
2905 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2907 static ALWAYS_INLINE
void
2908 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2909 GLenum target
, GLint level
, GLint internalFormat
,
2910 GLsizei width
, GLsizei height
, GLsizei depth
,
2911 GLint border
, GLenum format
, GLenum type
,
2912 GLsizei imageSize
, const GLvoid
*pixels
, bool no_error
)
2914 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2915 struct gl_pixelstore_attrib unpack_no_border
;
2916 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2917 struct gl_texture_object
*texObj
;
2918 mesa_format texFormat
;
2919 bool dimensionsOK
= true, sizeOK
= true;
2921 FLUSH_VERTICES(ctx
, 0);
2923 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2926 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2928 _mesa_enum_to_string(target
), level
,
2929 _mesa_enum_to_string(internalFormat
),
2930 width
, height
, depth
, border
, pixels
);
2933 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2935 _mesa_enum_to_string(target
), level
,
2936 _mesa_enum_to_string(internalFormat
),
2937 width
, height
, depth
, border
,
2938 _mesa_enum_to_string(format
),
2939 _mesa_enum_to_string(type
), pixels
);
2942 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2945 /* target error checking */
2946 if (!legal_teximage_target(ctx
, dims
, target
)) {
2947 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2948 func
, dims
, _mesa_enum_to_string(target
));
2952 /* general error checking */
2954 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2956 width
, height
, depth
,
2957 border
, imageSize
, pixels
))
2960 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2961 format
, type
, width
, height
, depth
, border
,
2967 /* Here we convert a cpal compressed image into a regular glTexImage2D
2968 * call by decompressing the texture. If we really want to support cpal
2969 * textures in any driver this would have to be changed.
2971 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
2972 switch (internalFormat
) {
2973 case GL_PALETTE4_RGB8_OES
:
2974 case GL_PALETTE4_RGBA8_OES
:
2975 case GL_PALETTE4_R5_G6_B5_OES
:
2976 case GL_PALETTE4_RGBA4_OES
:
2977 case GL_PALETTE4_RGB5_A1_OES
:
2978 case GL_PALETTE8_RGB8_OES
:
2979 case GL_PALETTE8_RGBA8_OES
:
2980 case GL_PALETTE8_R5_G6_B5_OES
:
2981 case GL_PALETTE8_RGBA4_OES
:
2982 case GL_PALETTE8_RGB5_A1_OES
:
2983 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
2984 width
, height
, imageSize
, pixels
);
2989 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2993 /* For glCompressedTexImage() the driver has no choice about the
2994 * texture format since we'll never transcode the user's compressed
2995 * image data. The internalFormat was error checked earlier.
2997 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3000 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3001 * internal floating point format for the given base format.
3003 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3004 if (type
== GL_FLOAT
) {
3005 texObj
->_IsFloat
= GL_TRUE
;
3006 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3007 texObj
->_IsHalfFloat
= GL_TRUE
;
3010 internalFormat
= adjust_for_oes_float_texture(ctx
, format
, type
);
3013 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3014 internalFormat
, format
, type
);
3017 assert(texFormat
!= MESA_FORMAT_NONE
);
3020 /* check that width, height, depth are legal for the mipmap level */
3021 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3022 height
, depth
, border
);
3024 /* check that the texture won't take too much memory, etc */
3025 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3026 0, level
, texFormat
, 1,
3027 width
, height
, depth
);
3030 if (_mesa_is_proxy_texture(target
)) {
3031 /* Proxy texture: just clear or set state depending on error checking */
3032 struct gl_texture_image
*texImage
=
3033 get_proxy_tex_image(ctx
, target
, level
);
3036 return; /* GL_OUT_OF_MEMORY already recorded */
3038 if (dimensionsOK
&& sizeOK
) {
3039 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3040 border
, internalFormat
, texFormat
);
3043 clear_teximage_fields(texImage
);
3047 /* non-proxy target */
3048 const GLuint face
= _mesa_tex_target_to_face(target
);
3049 struct gl_texture_image
*texImage
;
3051 if (!dimensionsOK
) {
3052 _mesa_error(ctx
, GL_INVALID_VALUE
,
3053 "%s%uD(invalid width=%d or height=%d or depth=%d)",
3054 func
, dims
, width
, height
, depth
);
3059 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3060 "%s%uD(image too large: %d x %d x %d, %s format)",
3061 func
, dims
, width
, height
, depth
,
3062 _mesa_enum_to_string(internalFormat
));
3066 /* Allow a hardware driver to just strip out the border, to provide
3067 * reliable but slightly incorrect hardware rendering instead of
3068 * rarely-tested software fallback rendering.
3070 if (border
&& ctx
->Const
.StripTextureBorder
) {
3071 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3074 unpack
= &unpack_no_border
;
3077 if (ctx
->NewState
& _NEW_PIXEL
)
3078 _mesa_update_state(ctx
);
3080 _mesa_lock_texture(ctx
, texObj
);
3082 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3085 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3088 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3090 _mesa_init_teximage_fields(ctx
, texImage
,
3091 width
, height
, depth
,
3092 border
, internalFormat
, texFormat
);
3094 /* Give the texture to the driver. <pixels> may be null. */
3095 if (width
> 0 && height
> 0 && depth
> 0) {
3097 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3101 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3102 type
, pixels
, unpack
);
3106 check_gen_mipmap(ctx
, target
, texObj
, level
);
3108 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3110 _mesa_dirty_texobj(ctx
, texObj
);
3113 _mesa_unlock_texture(ctx
, texObj
);
3118 /* This is a wrapper around teximage() so that we can force the KHR_no_error
3119 * logic to be inlined without inlining the function into all the callers.
3122 teximage_err(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3123 GLenum target
, GLint level
, GLint internalFormat
,
3124 GLsizei width
, GLsizei height
, GLsizei depth
,
3125 GLint border
, GLenum format
, GLenum type
,
3126 GLsizei imageSize
, const GLvoid
*pixels
)
3128 teximage(ctx
, compressed
, dims
, target
, level
, internalFormat
, width
, height
,
3129 depth
, border
, format
, type
, imageSize
, pixels
, false);
3134 teximage_no_error(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3135 GLenum target
, GLint level
, GLint internalFormat
,
3136 GLsizei width
, GLsizei height
, GLsizei depth
,
3137 GLint border
, GLenum format
, GLenum type
,
3138 GLsizei imageSize
, const GLvoid
*pixels
)
3140 teximage(ctx
, compressed
, dims
, target
, level
, internalFormat
, width
, height
,
3141 depth
, border
, format
, type
, imageSize
, pixels
, true);
3146 * Called from the API. Note that width includes the border.
3149 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3150 GLsizei width
, GLint border
, GLenum format
,
3151 GLenum type
, const GLvoid
*pixels
)
3153 GET_CURRENT_CONTEXT(ctx
);
3154 teximage_err(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3155 border
, format
, type
, 0, pixels
);
3160 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3161 GLsizei width
, GLsizei height
, GLint border
,
3162 GLenum format
, GLenum type
,
3163 const GLvoid
*pixels
)
3165 GET_CURRENT_CONTEXT(ctx
);
3166 teximage_err(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3167 border
, format
, type
, 0, pixels
);
3172 * Called by the API or display list executor.
3173 * Note that width and height include the border.
3176 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3177 GLsizei width
, GLsizei height
, GLsizei depth
,
3178 GLint border
, GLenum format
, GLenum type
,
3179 const GLvoid
*pixels
)
3181 GET_CURRENT_CONTEXT(ctx
);
3182 teximage_err(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3183 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3188 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3189 GLsizei width
, GLsizei height
, GLsizei depth
,
3190 GLint border
, GLenum format
, GLenum type
,
3191 const GLvoid
*pixels
)
3193 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3194 depth
, border
, format
, type
, pixels
);
3199 _mesa_TexImage1D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3200 GLsizei width
, GLint border
, GLenum format
,
3201 GLenum type
, const GLvoid
*pixels
)
3203 GET_CURRENT_CONTEXT(ctx
);
3204 teximage_no_error(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1,
3205 1, border
, format
, type
, 0, pixels
);
3210 _mesa_TexImage2D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3211 GLsizei width
, GLsizei height
, GLint border
,
3212 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3214 GET_CURRENT_CONTEXT(ctx
);
3215 teximage_no_error(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
,
3216 height
, 1, border
, format
, type
, 0, pixels
);
3221 _mesa_TexImage3D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3222 GLsizei width
, GLsizei height
, GLsizei depth
,
3223 GLint border
, GLenum format
, GLenum type
,
3224 const GLvoid
*pixels
)
3226 GET_CURRENT_CONTEXT(ctx
);
3227 teximage_no_error(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3228 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3233 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3235 struct gl_texture_object
*texObj
;
3236 struct gl_texture_image
*texImage
;
3238 GET_CURRENT_CONTEXT(ctx
);
3239 FLUSH_VERTICES(ctx
, 0);
3243 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3245 case GL_TEXTURE_EXTERNAL_OES
:
3247 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3250 valid_target
= false;
3254 if (!valid_target
) {
3255 _mesa_error(ctx
, GL_INVALID_ENUM
,
3256 "glEGLImageTargetTexture2D(target=%d)", target
);
3261 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3262 "glEGLImageTargetTexture2D(image=%p)", image
);
3266 if (ctx
->NewState
& _NEW_PIXEL
)
3267 _mesa_update_state(ctx
);
3269 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3273 _mesa_lock_texture(ctx
, texObj
);
3275 if (texObj
->Immutable
) {
3276 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3277 "glEGLImageTargetTexture2D(texture is immutable)");
3278 _mesa_unlock_texture(ctx
, texObj
);
3282 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3284 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3286 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3288 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3289 texObj
, texImage
, image
);
3291 _mesa_dirty_texobj(ctx
, texObj
);
3293 _mesa_unlock_texture(ctx
, texObj
);
3298 * Helper that implements the glTexSubImage1/2/3D()
3299 * and glTextureSubImage1/2/3D() functions.
3302 texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3303 struct gl_texture_object
*texObj
,
3304 struct gl_texture_image
*texImage
,
3305 GLenum target
, GLint level
,
3306 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3307 GLsizei width
, GLsizei height
, GLsizei depth
,
3308 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3310 FLUSH_VERTICES(ctx
, 0);
3312 if (ctx
->NewState
& _NEW_PIXEL
)
3313 _mesa_update_state(ctx
);
3315 _mesa_lock_texture(ctx
, texObj
);
3317 if (width
> 0 && height
> 0 && depth
> 0) {
3318 /* If we have a border, offset=-1 is legal. Bias by border width. */
3321 if (target
!= GL_TEXTURE_2D_ARRAY
)
3322 zoffset
+= texImage
->Border
;
3325 if (target
!= GL_TEXTURE_1D_ARRAY
)
3326 yoffset
+= texImage
->Border
;
3329 xoffset
+= texImage
->Border
;
3332 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3333 xoffset
, yoffset
, zoffset
,
3334 width
, height
, depth
,
3335 format
, type
, pixels
, &ctx
->Unpack
);
3337 check_gen_mipmap(ctx
, target
, texObj
, level
);
3339 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3340 * the texel data, not the texture format, size, etc.
3344 _mesa_unlock_texture(ctx
, texObj
);
3348 * Implement all the glTexSubImage1/2/3D() functions.
3349 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3352 texsubimage_err(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3353 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3354 GLsizei width
, GLsizei height
, GLsizei depth
,
3355 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3356 const char *callerName
)
3358 struct gl_texture_object
*texObj
;
3359 struct gl_texture_image
*texImage
;
3361 /* check target (proxies not allowed) */
3362 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3363 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3364 dims
, _mesa_enum_to_string(target
));
3368 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3372 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3373 xoffset
, yoffset
, zoffset
,
3374 width
, height
, depth
, format
, type
,
3375 pixels
, callerName
)) {
3376 return; /* error was detected */
3379 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3380 /* texsubimage_error_check ensures that texImage is not NULL */
3382 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3383 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3385 _mesa_enum_to_string(target
), level
,
3386 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3387 _mesa_enum_to_string(format
),
3388 _mesa_enum_to_string(type
), pixels
);
3390 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3391 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3392 format
, type
, pixels
);
3397 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3398 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3399 GLsizei width
, GLsizei height
, GLsizei depth
,
3400 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3402 struct gl_texture_object
*texObj
;
3403 struct gl_texture_image
*texImage
;
3405 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3406 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3408 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3409 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3410 format
, type
, pixels
);
3415 * Implement all the glTextureSubImage1/2/3D() functions.
3416 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3418 static ALWAYS_INLINE
void
3419 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3420 GLuint texture
, GLint level
,
3421 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3422 GLsizei width
, GLsizei height
, GLsizei depth
,
3423 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3424 const char *callerName
, bool no_error
)
3426 struct gl_texture_object
*texObj
;
3427 struct gl_texture_image
*texImage
;
3430 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3432 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3433 dims
, texture
, level
,
3434 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3435 _mesa_enum_to_string(format
),
3436 _mesa_enum_to_string(type
), pixels
);
3438 /* Get the texture object by Name. */
3440 texObj
= _mesa_lookup_texture_err(ctx
, texture
, callerName
);
3444 texObj
= _mesa_lookup_texture(ctx
, texture
);
3448 /* check target (proxies not allowed) */
3449 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3450 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3451 callerName
, _mesa_enum_to_string(texObj
->Target
));
3455 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3456 xoffset
, yoffset
, zoffset
,
3457 width
, height
, depth
, format
, type
,
3458 pixels
, callerName
)) {
3459 return; /* error was detected */
3463 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3464 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3468 * What do we do if the user created a texture with the following code
3469 * and then called this function with its handle?
3472 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3473 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3474 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3475 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3476 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3477 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3478 * // wrong format, or given the wrong size, etc.
3479 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3480 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3482 * A bug has been filed against the spec for this case. In the
3483 * meantime, we will check for cube completeness.
3485 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3486 * Core Profile spec (30.10.2014):
3487 * "[A] cube map texture is cube complete if the
3488 * following conditions all hold true: The [base level] texture
3489 * images of each of the six cube map faces have identical, positive,
3490 * and square dimensions. The [base level] images were each specified
3491 * with the same internal format."
3493 * It seems reasonable to check for cube completeness of an arbitrary
3494 * level here so that the image data has a consistent format and size.
3496 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
3497 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3498 "glTextureSubImage%uD(cube map incomplete)",
3503 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3505 /* Copy in each face. */
3506 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3507 texImage
= texObj
->Image
[i
][level
];
3510 texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3511 level
, xoffset
, yoffset
, 0,
3512 width
, height
, 1, format
,
3514 pixels
= (GLubyte
*) pixels
+ imageStride
;
3518 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3521 texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3522 level
, xoffset
, yoffset
, zoffset
,
3523 width
, height
, depth
, format
,
3530 texturesubimage_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 texturesubimage_no_error(struct gl_context
*ctx
, GLuint dims
,
3545 GLuint texture
, GLint level
,
3546 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3547 GLsizei width
, GLsizei height
, GLsizei depth
,
3548 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3549 const char *callerName
)
3551 texturesubimage(ctx
, dims
, texture
, level
, xoffset
, yoffset
, zoffset
,
3552 width
, height
, depth
, format
, type
, pixels
, callerName
,
3558 _mesa_TexSubImage1D_no_error(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(ctx
, 1, target
, level
,
3567 format
, type
, pixels
);
3572 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3573 GLint xoffset
, GLsizei width
,
3574 GLenum format
, GLenum type
,
3575 const GLvoid
*pixels
)
3577 GET_CURRENT_CONTEXT(ctx
);
3578 texsubimage_err(ctx
, 1, target
, level
,
3581 format
, type
, pixels
, "glTexSubImage1D");
3586 _mesa_TexSubImage2D_no_error(GLenum target
, GLint level
,
3587 GLint xoffset
, GLint yoffset
,
3588 GLsizei width
, GLsizei height
,
3589 GLenum format
, GLenum type
,
3590 const GLvoid
*pixels
)
3592 GET_CURRENT_CONTEXT(ctx
);
3593 texsubimage(ctx
, 2, target
, level
,
3594 xoffset
, yoffset
, 0,
3596 format
, type
, pixels
);
3601 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3602 GLint xoffset
, GLint yoffset
,
3603 GLsizei width
, GLsizei height
,
3604 GLenum format
, GLenum type
,
3605 const GLvoid
*pixels
)
3607 GET_CURRENT_CONTEXT(ctx
);
3608 texsubimage_err(ctx
, 2, target
, level
,
3609 xoffset
, yoffset
, 0,
3611 format
, type
, pixels
, "glTexSubImage2D");
3616 _mesa_TexSubImage3D_no_error(GLenum target
, GLint level
,
3617 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3618 GLsizei width
, GLsizei height
, GLsizei depth
,
3619 GLenum format
, GLenum type
,
3620 const GLvoid
*pixels
)
3622 GET_CURRENT_CONTEXT(ctx
);
3623 texsubimage(ctx
, 3, target
, level
,
3624 xoffset
, yoffset
, zoffset
,
3625 width
, height
, depth
,
3626 format
, type
, pixels
);
3631 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3632 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3633 GLsizei width
, GLsizei height
, GLsizei depth
,
3634 GLenum format
, GLenum type
,
3635 const GLvoid
*pixels
)
3637 GET_CURRENT_CONTEXT(ctx
);
3638 texsubimage_err(ctx
, 3, target
, level
,
3639 xoffset
, yoffset
, zoffset
,
3640 width
, height
, depth
,
3641 format
, type
, pixels
, "glTexSubImage3D");
3646 _mesa_TextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3647 GLsizei width
, GLenum format
, GLenum type
,
3648 const GLvoid
*pixels
)
3650 GET_CURRENT_CONTEXT(ctx
);
3651 texturesubimage_no_error(ctx
, 1, texture
, level
, xoffset
, 0, 0, width
, 1, 1,
3652 format
, type
, pixels
, "glTextureSubImage1D");
3657 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3658 GLint xoffset
, GLsizei width
,
3659 GLenum format
, GLenum type
,
3660 const GLvoid
*pixels
)
3662 GET_CURRENT_CONTEXT(ctx
);
3663 texturesubimage_error(ctx
, 1, texture
, level
, xoffset
, 0, 0, width
, 1, 1,
3664 format
, type
, pixels
, "glTextureSubImage1D");
3669 _mesa_TextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3670 GLint yoffset
, GLsizei width
, GLsizei height
,
3671 GLenum format
, GLenum type
,
3672 const GLvoid
*pixels
)
3674 GET_CURRENT_CONTEXT(ctx
);
3675 texturesubimage_no_error(ctx
, 2, texture
, level
, xoffset
, yoffset
, 0, width
,
3676 height
, 1, format
, type
, pixels
,
3677 "glTextureSubImage2D");
3682 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3683 GLint xoffset
, GLint yoffset
,
3684 GLsizei width
, GLsizei height
,
3685 GLenum format
, GLenum type
,
3686 const GLvoid
*pixels
)
3688 GET_CURRENT_CONTEXT(ctx
);
3689 texturesubimage_error(ctx
, 2, texture
, level
, xoffset
, yoffset
, 0, width
,
3690 height
, 1, format
, type
, pixels
,
3691 "glTextureSubImage2D");
3696 _mesa_TextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3697 GLint yoffset
, GLint zoffset
, GLsizei width
,
3698 GLsizei height
, GLsizei depth
, GLenum format
,
3699 GLenum type
, const GLvoid
*pixels
)
3701 GET_CURRENT_CONTEXT(ctx
);
3702 texturesubimage_no_error(ctx
, 3, texture
, level
, xoffset
, yoffset
, zoffset
,
3703 width
, height
, depth
, format
, type
, pixels
,
3704 "glTextureSubImage3D");
3709 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3710 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3711 GLsizei width
, GLsizei height
, GLsizei depth
,
3712 GLenum format
, GLenum type
,
3713 const GLvoid
*pixels
)
3715 GET_CURRENT_CONTEXT(ctx
);
3716 texturesubimage_error(ctx
, 3, texture
, level
, xoffset
, yoffset
, zoffset
,
3717 width
, height
, depth
, format
, type
, pixels
,
3718 "glTextureSubImage3D");
3723 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3724 * from. This depends on whether the texture contains color or depth values.
3726 static struct gl_renderbuffer
*
3727 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3729 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3730 /* reading from depth/stencil buffer */
3731 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3732 } else if (_mesa_get_format_bits(texFormat
, GL_STENCIL_BITS
) > 0) {
3733 return ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3735 /* copying from color buffer */
3736 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3742 copytexsubimage_by_slice(struct gl_context
*ctx
,
3743 struct gl_texture_image
*texImage
,
3745 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3746 struct gl_renderbuffer
*rb
,
3748 GLsizei width
, GLsizei height
)
3750 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3753 /* For 1D arrays, we copy each scanline of the source rectangle into the
3756 assert(zoffset
== 0);
3758 for (slice
= 0; slice
< height
; slice
++) {
3759 assert(yoffset
+ slice
< texImage
->Height
);
3760 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3761 xoffset
, 0, yoffset
+ slice
,
3762 rb
, x
, y
+ slice
, width
, 1);
3765 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3766 xoffset
, yoffset
, zoffset
,
3767 rb
, x
, y
, width
, height
);
3773 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3775 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3776 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3777 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3778 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3780 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3781 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3782 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3783 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3785 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3786 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3787 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3788 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3796 * Check if the given texture format and size arguments match those
3797 * of the texture image.
3798 * \param return true if arguments match, false otherwise.
3801 can_avoid_reallocation(const struct gl_texture_image
*texImage
,
3802 GLenum internalFormat
,
3803 mesa_format texFormat
, GLsizei width
,
3804 GLsizei height
, GLint border
)
3806 if (texImage
->InternalFormat
!= internalFormat
)
3808 if (texImage
->TexFormat
!= texFormat
)
3810 if (texImage
->Border
!= border
)
3812 if (texImage
->Width2
!= width
)
3814 if (texImage
->Height2
!= height
)
3821 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
3824 copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3825 struct gl_texture_object
*texObj
,
3826 GLenum target
, GLint level
,
3827 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3828 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3830 struct gl_texture_image
*texImage
;
3832 _mesa_lock_texture(ctx
, texObj
);
3834 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3836 /* If we have a border, offset=-1 is legal. Bias by border width. */
3839 if (target
!= GL_TEXTURE_2D_ARRAY
)
3840 zoffset
+= texImage
->Border
;
3843 if (target
!= GL_TEXTURE_1D_ARRAY
)
3844 yoffset
+= texImage
->Border
;
3847 xoffset
+= texImage
->Border
;
3850 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3852 struct gl_renderbuffer
*srcRb
=
3853 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3855 copytexsubimage_by_slice(ctx
, texImage
, dims
, xoffset
, yoffset
, zoffset
,
3856 srcRb
, x
, y
, width
, height
);
3858 check_gen_mipmap(ctx
, target
, texObj
, level
);
3860 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3861 * the texel data, not the texture format, size, etc.
3865 _mesa_unlock_texture(ctx
, texObj
);
3870 copy_texture_sub_image_err(struct gl_context
*ctx
, GLuint dims
,
3871 struct gl_texture_object
*texObj
,
3872 GLenum target
, GLint level
,
3873 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3874 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3877 FLUSH_VERTICES(ctx
, 0);
3879 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3880 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
3881 _mesa_enum_to_string(target
),
3882 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3884 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3885 _mesa_update_state(ctx
);
3887 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3888 xoffset
, yoffset
, zoffset
,
3889 width
, height
, caller
)) {
3893 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
3894 zoffset
, x
, y
, width
, height
);
3899 copy_texture_sub_image_no_error(struct gl_context
*ctx
, GLuint dims
,
3900 struct gl_texture_object
*texObj
,
3901 GLenum target
, GLint level
,
3902 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3903 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3905 FLUSH_VERTICES(ctx
, 0);
3907 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3908 _mesa_update_state(ctx
);
3910 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
3911 zoffset
, x
, y
, width
, height
);
3916 * Implement the glCopyTexImage1/2D() functions.
3918 static ALWAYS_INLINE
void
3919 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3920 GLenum target
, GLint level
, GLenum internalFormat
,
3921 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
,
3924 struct gl_texture_image
*texImage
;
3925 struct gl_texture_object
*texObj
;
3926 mesa_format texFormat
;
3928 FLUSH_VERTICES(ctx
, 0);
3930 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3931 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3933 _mesa_enum_to_string(target
), level
,
3934 _mesa_enum_to_string(internalFormat
),
3935 x
, y
, width
, height
, border
);
3937 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3938 _mesa_update_state(ctx
);
3941 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3945 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3947 _mesa_error(ctx
, GL_INVALID_VALUE
,
3948 "glCopyTexImage%uD(invalid width=%d or height=%d)",
3949 dims
, width
, height
);
3954 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3957 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3958 internalFormat
, GL_NONE
, GL_NONE
);
3960 /* First check if reallocating the texture buffer can be avoided.
3961 * Without the realloc the copy can be 20x faster.
3963 _mesa_lock_texture(ctx
, texObj
);
3965 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3966 if (texImage
&& can_avoid_reallocation(texImage
, internalFormat
, texFormat
,
3967 width
, height
, border
)) {
3968 _mesa_unlock_texture(ctx
, texObj
);
3970 copy_texture_sub_image_no_error(ctx
, dims
, texObj
, target
, level
, 0,
3971 0, 0, x
, y
, width
, height
);
3973 copy_texture_sub_image_err(ctx
, dims
, texObj
, target
, level
, 0, 0,
3974 0, x
, y
, width
, height
,"CopyTexImage");
3979 _mesa_unlock_texture(ctx
, texObj
);
3980 _mesa_perf_debug(ctx
, MESA_DEBUG_SEVERITY_LOW
, "glCopyTexImage "
3981 "can't avoid reallocating texture storage\n");
3983 if (!no_error
&& _mesa_is_gles3(ctx
)) {
3984 struct gl_renderbuffer
*rb
=
3985 _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3987 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3988 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3989 * OpenGL ES 3.0. Khronos bug# 9807.
3991 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3992 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3993 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
3994 " and writing to unsized internal format)", dims
);
3998 /* From Page 139 of OpenGL ES 3.0 spec:
3999 * "If internalformat is sized, the internal format of the new texel
4000 * array is internalformat, and this is also the new texel array’s
4001 * effective internal format. If the component sizes of internalformat
4002 * do not exactly match the corresponding component sizes of the source
4003 * buffer’s effective internal format, described below, an
4004 * INVALID_OPERATION error is generated. If internalformat is unsized,
4005 * the internal format of the new texel array is the effective internal
4006 * format of the source buffer, and this is also the new texel array’s
4007 * effective internal format.
4009 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
4010 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4011 "glCopyTexImage%uD(component size changed in"
4012 " internal format)", dims
);
4017 assert(texFormat
!= MESA_FORMAT_NONE
);
4019 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
4020 0, level
, texFormat
, 1,
4021 width
, height
, 1)) {
4022 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4023 "glCopyTexImage%uD(image too large)", dims
);
4027 if (border
&& ctx
->Const
.StripTextureBorder
) {
4029 width
-= border
* 2;
4032 height
-= border
* 2;
4037 _mesa_lock_texture(ctx
, texObj
);
4039 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
4042 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
4045 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
4046 const GLuint face
= _mesa_tex_target_to_face(target
);
4048 /* Free old texture image */
4049 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4051 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
4052 border
, internalFormat
, texFormat
);
4054 if (width
&& height
) {
4055 /* Allocate texture memory (no pixel data yet) */
4056 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
4058 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
4060 struct gl_renderbuffer
*srcRb
=
4061 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4063 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4065 srcRb
, srcX
, srcY
, width
, height
);
4068 check_gen_mipmap(ctx
, target
, texObj
, level
);
4071 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4073 _mesa_dirty_texobj(ctx
, texObj
);
4076 _mesa_unlock_texture(ctx
, texObj
);
4081 copyteximage_err(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
4082 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4083 GLsizei width
, GLsizei height
, GLint border
)
4085 copyteximage(ctx
, dims
, target
, level
, internalFormat
, x
, y
, width
, height
,
4091 copyteximage_no_error(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
4092 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4093 GLsizei width
, GLsizei height
, GLint border
)
4095 copyteximage(ctx
, dims
, target
, level
, internalFormat
, x
, y
, width
, height
,
4101 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4102 GLenum internalFormat
,
4104 GLsizei width
, GLint border
)
4106 GET_CURRENT_CONTEXT(ctx
);
4107 copyteximage_err(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4113 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4114 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4117 GET_CURRENT_CONTEXT(ctx
);
4118 copyteximage_err(ctx
, 2, target
, level
, internalFormat
,
4119 x
, y
, width
, height
, border
);
4124 _mesa_CopyTexImage1D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4125 GLint x
, GLint y
, GLsizei width
, GLint border
)
4127 GET_CURRENT_CONTEXT(ctx
);
4128 copyteximage_no_error(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4134 _mesa_CopyTexImage2D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4135 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4138 GET_CURRENT_CONTEXT(ctx
);
4139 copyteximage_no_error(ctx
, 2, target
, level
, internalFormat
,
4140 x
, y
, width
, height
, border
);
4145 _mesa_CopyTexSubImage1D(GLenum target
, GLint level
,
4146 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4148 struct gl_texture_object
* texObj
;
4149 const char *self
= "glCopyTexSubImage1D";
4150 GET_CURRENT_CONTEXT(ctx
);
4152 /* Check target (proxies not allowed). Target must be checked prior to
4153 * calling _mesa_get_current_tex_object.
4155 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4156 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4157 _mesa_enum_to_string(target
));
4161 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4165 copy_texture_sub_image_err(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4166 x
, y
, width
, 1, self
);
4171 _mesa_CopyTexSubImage2D(GLenum target
, GLint level
,
4172 GLint xoffset
, GLint yoffset
,
4173 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4175 struct gl_texture_object
* texObj
;
4176 const char *self
= "glCopyTexSubImage2D";
4177 GET_CURRENT_CONTEXT(ctx
);
4179 /* Check target (proxies not allowed). Target must be checked prior to
4180 * calling _mesa_get_current_tex_object.
4182 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4183 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4184 _mesa_enum_to_string(target
));
4188 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4192 copy_texture_sub_image_err(ctx
, 2, texObj
, target
, level
, xoffset
, yoffset
,
4193 0, x
, y
, width
, height
, self
);
4198 _mesa_CopyTexSubImage3D(GLenum target
, GLint level
,
4199 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4200 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4202 struct gl_texture_object
* texObj
;
4203 const char *self
= "glCopyTexSubImage3D";
4204 GET_CURRENT_CONTEXT(ctx
);
4206 /* Check target (proxies not allowed). Target must be checked prior to
4207 * calling _mesa_get_current_tex_object.
4209 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4210 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4211 _mesa_enum_to_string(target
));
4215 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4219 copy_texture_sub_image_err(ctx
, 3, texObj
, target
, level
, xoffset
, yoffset
,
4220 zoffset
, x
, y
, width
, height
, self
);
4225 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4226 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4228 struct gl_texture_object
* texObj
;
4229 const char *self
= "glCopyTextureSubImage1D";
4230 GET_CURRENT_CONTEXT(ctx
);
4232 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4236 /* Check target (proxies not allowed). */
4237 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4238 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4239 _mesa_enum_to_string(texObj
->Target
));
4243 copy_texture_sub_image_err(ctx
, 1, texObj
, texObj
->Target
, level
, xoffset
, 0,
4244 0, x
, y
, width
, 1, self
);
4249 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4250 GLint xoffset
, GLint yoffset
,
4251 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4253 struct gl_texture_object
* texObj
;
4254 const char *self
= "glCopyTextureSubImage2D";
4255 GET_CURRENT_CONTEXT(ctx
);
4257 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4261 /* Check target (proxies not allowed). */
4262 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4263 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4264 _mesa_enum_to_string(texObj
->Target
));
4268 copy_texture_sub_image_err(ctx
, 2, texObj
, texObj
->Target
, level
, xoffset
,
4269 yoffset
, 0, x
, y
, width
, height
, self
);
4274 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4275 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4276 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4278 struct gl_texture_object
* texObj
;
4279 const char *self
= "glCopyTextureSubImage3D";
4280 GET_CURRENT_CONTEXT(ctx
);
4282 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4286 /* Check target (proxies not allowed). */
4287 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4288 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4289 _mesa_enum_to_string(texObj
->Target
));
4293 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4294 /* Act like CopyTexSubImage2D */
4295 copy_texture_sub_image_err(ctx
, 2, texObj
,
4296 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4297 level
, xoffset
, yoffset
, 0, x
, y
, width
, height
,
4301 copy_texture_sub_image_err(ctx
, 3, texObj
, texObj
->Target
, level
, xoffset
,
4302 yoffset
, zoffset
, x
, y
, width
, height
, self
);
4307 _mesa_CopyTexSubImage1D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4308 GLint x
, GLint y
, GLsizei width
)
4310 GET_CURRENT_CONTEXT(ctx
);
4312 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4313 copy_texture_sub_image_no_error(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4319 _mesa_CopyTexSubImage2D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4320 GLint yoffset
, GLint x
, GLint y
, GLsizei width
,
4323 GET_CURRENT_CONTEXT(ctx
);
4325 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4326 copy_texture_sub_image_no_error(ctx
, 2, texObj
, target
, level
, xoffset
,
4327 yoffset
, 0, x
, y
, width
, height
);
4332 _mesa_CopyTexSubImage3D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4333 GLint yoffset
, GLint zoffset
, GLint x
, GLint y
,
4334 GLsizei width
, GLsizei height
)
4336 GET_CURRENT_CONTEXT(ctx
);
4338 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4339 copy_texture_sub_image_no_error(ctx
, 3, texObj
, target
, level
, xoffset
,
4340 yoffset
, zoffset
, x
, y
, width
, height
);
4345 _mesa_CopyTextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4346 GLint x
, GLint y
, GLsizei width
)
4348 GET_CURRENT_CONTEXT(ctx
);
4350 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4351 copy_texture_sub_image_no_error(ctx
, 1, texObj
, texObj
->Target
, level
,
4352 xoffset
, 0, 0, x
, y
, width
, 1);
4357 _mesa_CopyTextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4358 GLint yoffset
, GLint x
, GLint y
,
4359 GLsizei width
, GLsizei height
)
4361 GET_CURRENT_CONTEXT(ctx
);
4363 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4364 copy_texture_sub_image_no_error(ctx
, 2, texObj
, texObj
->Target
, level
,
4365 xoffset
, yoffset
, 0, x
, y
, width
, height
);
4370 _mesa_CopyTextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4371 GLint yoffset
, GLint zoffset
, GLint x
,
4372 GLint y
, GLsizei width
, GLsizei height
)
4374 GET_CURRENT_CONTEXT(ctx
);
4376 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4377 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4378 /* Act like CopyTexSubImage2D */
4379 copy_texture_sub_image_no_error(ctx
, 2, texObj
,
4380 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4381 level
, xoffset
, yoffset
, 0, x
, y
, width
,
4385 copy_texture_sub_image_no_error(ctx
, 3, texObj
, texObj
->Target
, level
,
4386 xoffset
, yoffset
, zoffset
, x
, y
, width
,
4392 check_clear_tex_image(struct gl_context
*ctx
,
4393 const char *function
,
4394 struct gl_texture_image
*texImage
,
4395 GLenum format
, GLenum type
,
4397 GLubyte
*clearValue
)
4399 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4400 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4401 GLenum internalFormat
= texImage
->InternalFormat
;
4404 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4405 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4406 "%s(buffer texture)", function
);
4410 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4411 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4412 "%s(compressed texture)", function
);
4416 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4417 if (err
!= GL_NO_ERROR
) {
4418 _mesa_error(ctx
, err
,
4419 "%s(incompatible format = %s, type = %s)",
4421 _mesa_enum_to_string(format
),
4422 _mesa_enum_to_string(type
));
4426 /* make sure internal format and format basically agree */
4427 if (!texture_formats_agree(internalFormat
, format
)) {
4428 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4429 "%s(incompatible internalFormat = %s, format = %s)",
4431 _mesa_enum_to_string(internalFormat
),
4432 _mesa_enum_to_string(format
));
4436 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4437 /* both source and dest must be integer-valued, or neither */
4438 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4439 _mesa_is_enum_format_integer(format
)) {
4440 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4441 "%s(integer/non-integer format mismatch)",
4447 if (!_mesa_texstore(ctx
,
4449 texImage
->_BaseFormat
,
4450 texImage
->TexFormat
,
4451 0, /* dstRowStride */
4453 1, 1, 1, /* srcWidth/Height/Depth */
4455 data
? data
: zeroData
,
4456 &ctx
->DefaultPacking
)) {
4457 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4465 static struct gl_texture_object
*
4466 get_tex_obj_for_clear(struct gl_context
*ctx
,
4467 const char *function
,
4470 struct gl_texture_object
*texObj
;
4472 texObj
= _mesa_lookup_texture_err(ctx
, texture
, function
);
4476 if (texObj
->Target
== 0) {
4477 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4486 * For clearing cube textures, the zoffset and depth parameters indicate
4487 * which cube map faces are to be cleared. This is the one case where we
4488 * need to be concerned with multiple gl_texture_images. This function
4489 * returns the array of texture images to clear for cube maps, or one
4490 * texture image otherwise.
4491 * \return number of texture images, 0 for error, 6 for cube, 1 otherwise.
4494 get_tex_images_for_clear(struct gl_context
*ctx
,
4495 const char *function
,
4496 struct gl_texture_object
*texObj
,
4498 struct gl_texture_image
**texImages
)
4503 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4504 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4508 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4509 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
4510 numFaces
= MAX_FACES
;
4513 target
= texObj
->Target
;
4517 for (i
= 0; i
< numFaces
; i
++) {
4518 texImages
[i
] = _mesa_select_tex_image(texObj
, target
+ i
, level
);
4519 if (texImages
[i
] == NULL
) {
4520 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4530 _mesa_ClearTexSubImage(GLuint texture
, GLint level
,
4531 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4532 GLsizei width
, GLsizei height
, GLsizei depth
,
4533 GLenum format
, GLenum type
, const void *data
)
4535 GET_CURRENT_CONTEXT(ctx
);
4536 struct gl_texture_object
*texObj
;
4537 struct gl_texture_image
*texImages
[MAX_FACES
];
4538 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4540 int minDepth
, maxDepth
;
4542 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4547 _mesa_lock_texture(ctx
, texObj
);
4549 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4550 texObj
, level
, texImages
);
4554 if (numImages
== 1) {
4555 minDepth
= -(int) texImages
[0]->Border
;
4556 maxDepth
= texImages
[0]->Depth
;
4558 assert(numImages
== MAX_FACES
);
4560 maxDepth
= numImages
;
4563 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4564 yoffset
< -(GLint
) texImages
[0]->Border
||
4565 zoffset
< minDepth
||
4569 xoffset
+ width
> texImages
[0]->Width
||
4570 yoffset
+ height
> texImages
[0]->Height
||
4571 zoffset
+ depth
> maxDepth
) {
4572 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4573 "glClearSubTexImage(invalid dimensions)");
4577 if (numImages
== 1) {
4578 if (check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[0],
4579 format
, type
, data
, clearValue
[0])) {
4580 ctx
->Driver
.ClearTexSubImage(ctx
,
4582 xoffset
, yoffset
, zoffset
,
4583 width
, height
, depth
,
4584 data
? clearValue
[0] : NULL
);
4587 /* loop over cube face images */
4588 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4589 assert(i
< MAX_FACES
);
4590 if (!check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[i
],
4591 format
, type
, data
, clearValue
[i
]))
4594 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4595 ctx
->Driver
.ClearTexSubImage(ctx
,
4597 xoffset
, yoffset
, 0,
4599 data
? clearValue
[i
] : NULL
);
4604 _mesa_unlock_texture(ctx
, texObj
);
4609 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4610 GLenum format
, GLenum type
, const void *data
)
4612 GET_CURRENT_CONTEXT(ctx
);
4613 struct gl_texture_object
*texObj
;
4614 struct gl_texture_image
*texImages
[MAX_FACES
];
4615 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4618 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4623 _mesa_lock_texture(ctx
, texObj
);
4625 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4626 texObj
, level
, texImages
);
4628 for (i
= 0; i
< numImages
; i
++) {
4629 if (!check_clear_tex_image(ctx
, "glClearTexImage", texImages
[i
], format
,
4630 type
, data
, clearValue
[i
]))
4634 for (i
= 0; i
< numImages
; i
++) {
4635 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4636 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4637 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4638 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4639 texImages
[i
]->Width
,
4640 texImages
[i
]->Height
,
4641 texImages
[i
]->Depth
,
4642 data
? clearValue
[i
] : NULL
);
4646 _mesa_unlock_texture(ctx
, texObj
);
4652 /**********************************************************************/
4653 /****** Compressed Textures ******/
4654 /**********************************************************************/
4658 * Target checking for glCompressedTexSubImage[123]D().
4659 * \return GL_TRUE if error, GL_FALSE if no error
4660 * Must come before other error checking so that the texture object can
4661 * be correctly retrieved using _mesa_get_current_tex_object.
4664 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4665 GLint dims
, GLenum intFormat
, bool dsa
,
4670 enum mesa_format_layout layout
;
4672 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4673 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4674 _mesa_enum_to_string(target
));
4684 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4685 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4686 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4687 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4688 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4689 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4690 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4693 targetOK
= GL_FALSE
;
4699 case GL_TEXTURE_CUBE_MAP
:
4700 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4702 case GL_TEXTURE_2D_ARRAY
:
4703 targetOK
= _mesa_is_gles3(ctx
) ||
4704 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4706 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4707 targetOK
= _mesa_has_texture_cube_map_array(ctx
);
4712 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4714 * "An INVALID_OPERATION error is generated by
4715 * CompressedTex*SubImage3D if the internal format of the texture
4716 * is one of the EAC, ETC2, or RGTC formats and either border is
4717 * non-zero, or the effective target for the texture is not
4718 * TEXTURE_2D_ARRAY."
4720 * NOTE: that's probably a spec error. It should probably say
4721 * "... or the effective target for the texture is not
4722 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4723 * GL_TEXTURE_CUBE_MAP_ARRAY."
4724 * since those targets are 2D images and they support all compression
4727 * Instead of listing all these, just list those which are allowed,
4728 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4729 * more) are valid here, which they are not, but of course not
4730 * mentioned by core spec.
4732 * Also, from GL_KHR_texture_compression_astc_{hdr,ldr}:
4734 * "Add a second new column "3D Tex." which is empty for all non-ASTC
4735 * formats. If only the LDR profile is supported by the implementation,
4736 * this column is also empty for all ASTC formats. If both the LDR and HDR
4737 * profiles are supported, this column is checked for all ASTC formats."
4739 * "An INVALID_OPERATION error is generated by CompressedTexSubImage3D if
4740 * <format> is one of the formats in table 8.19 and <target> is not
4741 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, or TEXTURE_3D.
4743 * An INVALID_OPERATION error is generated by CompressedTexSubImage3D if
4744 * <format> is TEXTURE_CUBE_MAP_ARRAY and the "Cube Map Array" column of
4745 * table 8.19 is *not* checked, or if <format> is TEXTURE_3D and the "3D
4746 * Tex." column of table 8.19 is *not* checked"
4748 * And from GL_KHR_texture_compression_astc_sliced_3d:
4750 * "Modify the "3D Tex." column to be checked for all ASTC formats."
4752 format
= _mesa_glenum_to_compressed_format(intFormat
);
4753 layout
= _mesa_get_format_layout(format
);
4755 case MESA_FORMAT_LAYOUT_BPTC
:
4758 case MESA_FORMAT_LAYOUT_ASTC
:
4760 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
4761 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
4764 /* invalid format */
4765 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4766 "%s(invalid target %s for format %s)", caller
,
4767 _mesa_enum_to_string(target
),
4768 _mesa_enum_to_string(intFormat
));
4773 targetOK
= GL_FALSE
;
4779 /* no 1D compressed textures at this time */
4780 targetOK
= GL_FALSE
;
4785 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4786 _mesa_enum_to_string(target
));
4794 * Error checking for glCompressedTexSubImage[123]D().
4795 * \return GL_TRUE if error, GL_FALSE if no error
4798 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4799 const struct gl_texture_object
*texObj
,
4800 GLenum target
, GLint level
,
4801 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4802 GLsizei width
, GLsizei height
, GLsizei depth
,
4803 GLenum format
, GLsizei imageSize
,
4804 const GLvoid
*data
, const char *callerName
)
4806 struct gl_texture_image
*texImage
;
4809 /* this will catch any invalid compressed format token */
4810 if (!_mesa_is_compressed_format(ctx
, format
)) {
4811 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(format)", callerName
);
4815 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4816 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
4820 /* validate the bound PBO, if any */
4821 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4822 imageSize
, data
, callerName
)) {
4826 /* Check for invalid pixel storage modes */
4827 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4828 &ctx
->Unpack
, callerName
)) {
4832 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4833 if (expectedSize
!= imageSize
) {
4834 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", callerName
, imageSize
);
4838 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4840 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture level %d)",
4845 if ((GLint
) format
!= texImage
->InternalFormat
) {
4846 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s)",
4847 callerName
, _mesa_enum_to_string(format
));
4851 if (compressedteximage_only_format(format
)) {
4852 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s cannot be updated)",
4853 callerName
, _mesa_enum_to_string(format
));
4857 if (error_check_subtexture_negative_dimensions(ctx
, dims
, width
, height
,
4858 depth
, callerName
)) {
4862 if (error_check_subtexture_dimensions(ctx
, dims
, texImage
, xoffset
, yoffset
,
4863 zoffset
, width
, height
, depth
,
4873 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4874 GLenum internalFormat
, GLsizei width
,
4875 GLint border
, GLsizei imageSize
,
4878 GET_CURRENT_CONTEXT(ctx
);
4879 teximage_err(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4880 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4885 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4886 GLenum internalFormat
, GLsizei width
,
4887 GLsizei height
, GLint border
, GLsizei imageSize
,
4890 GET_CURRENT_CONTEXT(ctx
);
4891 teximage_err(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4892 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4897 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4898 GLenum internalFormat
, GLsizei width
,
4899 GLsizei height
, GLsizei depth
, GLint border
,
4900 GLsizei imageSize
, const GLvoid
*data
)
4902 GET_CURRENT_CONTEXT(ctx
);
4903 teximage_err(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
, height
,
4904 depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4909 _mesa_CompressedTexImage1D_no_error(GLenum target
, GLint level
,
4910 GLenum internalFormat
, GLsizei width
,
4911 GLint border
, GLsizei imageSize
,
4914 GET_CURRENT_CONTEXT(ctx
);
4915 teximage_no_error(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
, width
, 1,
4916 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4921 _mesa_CompressedTexImage2D_no_error(GLenum target
, GLint level
,
4922 GLenum internalFormat
, GLsizei width
,
4923 GLsizei height
, GLint border
,
4924 GLsizei imageSize
, const GLvoid
*data
)
4926 GET_CURRENT_CONTEXT(ctx
);
4927 teximage_no_error(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
, width
,
4928 height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4933 _mesa_CompressedTexImage3D_no_error(GLenum target
, GLint level
,
4934 GLenum internalFormat
, GLsizei width
,
4935 GLsizei height
, GLsizei depth
, GLint border
,
4936 GLsizei imageSize
, const GLvoid
*data
)
4938 GET_CURRENT_CONTEXT(ctx
);
4939 teximage_no_error(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
,
4940 height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4945 * Common helper for glCompressedTexSubImage1/2/3D() and
4946 * glCompressedTextureSubImage1/2/3D().
4949 compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4950 struct gl_texture_object
*texObj
,
4951 struct gl_texture_image
*texImage
,
4952 GLenum target
, GLint level
, GLint xoffset
,
4953 GLint yoffset
, GLint zoffset
, GLsizei width
,
4954 GLsizei height
, GLsizei depth
, GLenum format
,
4955 GLsizei imageSize
, const GLvoid
*data
)
4957 FLUSH_VERTICES(ctx
, 0);
4959 _mesa_lock_texture(ctx
, texObj
);
4961 if (width
> 0 && height
> 0 && depth
> 0) {
4962 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4963 xoffset
, yoffset
, zoffset
,
4964 width
, height
, depth
,
4965 format
, imageSize
, data
);
4967 check_gen_mipmap(ctx
, target
, texObj
, level
);
4969 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
4970 * the texel data, not the texture format, size, etc.
4974 _mesa_unlock_texture(ctx
, texObj
);
4978 static ALWAYS_INLINE
void
4979 compressed_tex_sub_image(unsigned dim
, GLenum target
, GLuint texture
,
4980 GLint level
, GLint xoffset
, GLint yoffset
,
4981 GLint zoffset
, GLsizei width
, GLsizei height
,
4982 GLsizei depth
, GLenum format
, GLsizei imageSize
,
4983 const GLvoid
*data
, bool dsa
, bool no_error
,
4986 struct gl_texture_object
*texObj
= NULL
;
4987 struct gl_texture_image
*texImage
;
4989 GET_CURRENT_CONTEXT(ctx
);
4993 texObj
= _mesa_lookup_texture(ctx
, texture
);
4995 texObj
= _mesa_lookup_texture_err(ctx
, texture
, caller
);
5000 target
= texObj
->Target
;
5004 compressed_subtexture_target_check(ctx
, target
, dim
, format
, dsa
,
5010 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5011 if (!no_error
&& !texObj
)
5016 compressed_subtexture_error_check(ctx
, dim
, texObj
, target
, level
,
5017 xoffset
, yoffset
, zoffset
, width
,
5018 height
, depth
, format
,
5019 imageSize
, data
, caller
)) {
5023 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
5024 if (dim
== 3 && dsa
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5025 const char *pixels
= data
;
5028 /* Make sure the texture object is a proper cube.
5029 * (See texturesubimage in teximage.c for details on why this check is
5032 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
5033 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5034 "glCompressedTextureSubImage3D(cube map incomplete)");
5038 /* Copy in each face. */
5039 for (int i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
5040 texImage
= texObj
->Image
[i
][level
];
5043 compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5044 texObj
->Target
, level
, xoffset
, yoffset
,
5045 0, width
, height
, 1, format
,
5048 /* Compressed images don't have a client format */
5049 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5051 texImage
->Height
, 1);
5053 pixels
+= image_stride
;
5054 imageSize
-= image_stride
;
5057 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5060 compressed_texture_sub_image(ctx
, dim
, texObj
, texImage
, target
, level
,
5061 xoffset
, yoffset
, zoffset
, width
, height
,
5062 depth
, format
, imageSize
, data
);
5067 compressed_tex_sub_image_error(unsigned dim
, GLenum target
, GLuint texture
,
5068 GLint level
, GLint xoffset
, GLint yoffset
,
5069 GLint zoffset
, GLsizei width
, GLsizei height
,
5070 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5071 const GLvoid
*data
, bool dsa
,
5074 compressed_tex_sub_image(dim
, target
, texture
, level
, xoffset
, yoffset
,
5075 zoffset
, width
, height
, depth
, format
, imageSize
,
5076 data
, dsa
, false, caller
);
5080 compressed_tex_sub_image_no_error(unsigned dim
, GLenum target
, GLuint texture
,
5081 GLint level
, GLint xoffset
, GLint yoffset
,
5082 GLint zoffset
, GLsizei width
, GLsizei height
,
5083 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5084 const GLvoid
*data
, bool dsa
,
5087 compressed_tex_sub_image(dim
, target
, texture
, level
, xoffset
, yoffset
,
5088 zoffset
, width
, height
, depth
, format
, imageSize
,
5089 data
, dsa
, true, caller
);
5093 _mesa_CompressedTexSubImage1D_no_error(GLenum target
, GLint level
,
5094 GLint xoffset
, GLsizei width
,
5095 GLenum format
, GLsizei imageSize
,
5098 compressed_tex_sub_image_no_error(1, target
, 0, level
, xoffset
, 0, 0, width
,
5099 1, 1, format
, imageSize
, data
, false,
5100 "glCompressedTexSubImage1D");
5105 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
5106 GLsizei width
, GLenum format
,
5107 GLsizei imageSize
, const GLvoid
*data
)
5109 compressed_tex_sub_image_error(1, target
, 0, level
, xoffset
, 0, 0, width
, 1,
5110 1, format
, imageSize
, data
, false,
5111 "glCompressedTexSubImage1D");
5116 _mesa_CompressedTextureSubImage1D_no_error(GLuint texture
, GLint level
,
5117 GLint xoffset
, GLsizei width
,
5118 GLenum format
, GLsizei imageSize
,
5121 compressed_tex_sub_image_no_error(1, 0, texture
, level
, xoffset
, 0, 0, width
,
5122 1, 1, format
, imageSize
, data
, true,
5123 "glCompressedTextureSubImage1D");
5128 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
5129 GLsizei width
, GLenum format
,
5130 GLsizei imageSize
, const GLvoid
*data
)
5132 compressed_tex_sub_image_error(1, 0, texture
, level
, xoffset
, 0, 0, width
,
5133 1, 1, format
, imageSize
, data
, true,
5134 "glCompressedTextureSubImage1D");
5138 _mesa_CompressedTexSubImage2D_no_error(GLenum target
, GLint level
,
5139 GLint xoffset
, GLint yoffset
,
5140 GLsizei width
, GLsizei height
,
5141 GLenum format
, GLsizei imageSize
,
5144 compressed_tex_sub_image_no_error(2, target
, 0, level
, xoffset
, yoffset
, 0,
5145 width
, height
, 1, format
, imageSize
, data
,
5146 false, "glCompressedTexSubImage2D");
5151 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
5152 GLint yoffset
, GLsizei width
, GLsizei height
,
5153 GLenum format
, GLsizei imageSize
,
5156 compressed_tex_sub_image_error(2, target
, 0, level
, xoffset
, yoffset
, 0,
5157 width
, height
, 1, format
, imageSize
, data
,
5158 false, "glCompressedTexSubImage2D");
5163 _mesa_CompressedTextureSubImage2D_no_error(GLuint texture
, GLint level
,
5164 GLint xoffset
, GLint yoffset
,
5165 GLsizei width
, GLsizei height
,
5166 GLenum format
, GLsizei imageSize
,
5169 compressed_tex_sub_image_no_error(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5170 width
, height
, 1, format
, imageSize
, data
,
5171 true, "glCompressedTextureSubImage2D");
5176 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
5178 GLsizei width
, GLsizei height
,
5179 GLenum format
, GLsizei imageSize
,
5182 compressed_tex_sub_image_error(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5183 width
, height
, 1, format
, imageSize
, data
,
5184 true, "glCompressedTextureSubImage2D");
5188 _mesa_CompressedTexSubImage3D_no_error(GLenum target
, GLint level
,
5189 GLint xoffset
, GLint yoffset
,
5190 GLint zoffset
, GLsizei width
,
5191 GLsizei height
, GLsizei depth
,
5192 GLenum format
, GLsizei imageSize
,
5195 compressed_tex_sub_image_no_error(3, target
, 0, level
, xoffset
, yoffset
,
5196 zoffset
, width
, height
, depth
, format
,
5197 imageSize
, data
, false,
5198 "glCompressedTexSubImage3D");
5202 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
5203 GLint yoffset
, GLint zoffset
, GLsizei width
,
5204 GLsizei height
, GLsizei depth
, GLenum format
,
5205 GLsizei imageSize
, const GLvoid
*data
)
5207 compressed_tex_sub_image_error(3, target
, 0, level
, xoffset
, yoffset
,
5208 zoffset
, width
, height
, depth
, format
,
5209 imageSize
, data
, false,
5210 "glCompressedTexSubImage3D");
5214 _mesa_CompressedTextureSubImage3D_no_error(GLuint texture
, GLint level
,
5215 GLint xoffset
, GLint yoffset
,
5216 GLint zoffset
, GLsizei width
,
5217 GLsizei height
, GLsizei depth
,
5218 GLenum format
, GLsizei imageSize
,
5221 compressed_tex_sub_image_no_error(3, 0, texture
, level
, xoffset
, yoffset
,
5222 zoffset
, width
, height
, depth
, format
,
5223 imageSize
, data
, true,
5224 "glCompressedTextureSubImage3D");
5228 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
5229 GLint yoffset
, GLint zoffset
, GLsizei width
,
5230 GLsizei height
, GLsizei depth
,
5231 GLenum format
, GLsizei imageSize
,
5234 compressed_tex_sub_image_error(3, 0, texture
, level
, xoffset
, yoffset
,
5235 zoffset
, width
, height
, depth
, format
,
5236 imageSize
, data
, true,
5237 "glCompressedTextureSubImage3D");
5241 _mesa_get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5243 if (ctx
->API
== API_OPENGL_COMPAT
) {
5244 switch (internalFormat
) {
5246 return MESA_FORMAT_A_UNORM8
;
5248 return MESA_FORMAT_A_UNORM16
;
5249 case GL_ALPHA16F_ARB
:
5250 return MESA_FORMAT_A_FLOAT16
;
5251 case GL_ALPHA32F_ARB
:
5252 return MESA_FORMAT_A_FLOAT32
;
5253 case GL_ALPHA8I_EXT
:
5254 return MESA_FORMAT_A_SINT8
;
5255 case GL_ALPHA16I_EXT
:
5256 return MESA_FORMAT_A_SINT16
;
5257 case GL_ALPHA32I_EXT
:
5258 return MESA_FORMAT_A_SINT32
;
5259 case GL_ALPHA8UI_EXT
:
5260 return MESA_FORMAT_A_UINT8
;
5261 case GL_ALPHA16UI_EXT
:
5262 return MESA_FORMAT_A_UINT16
;
5263 case GL_ALPHA32UI_EXT
:
5264 return MESA_FORMAT_A_UINT32
;
5266 return MESA_FORMAT_L_UNORM8
;
5267 case GL_LUMINANCE16
:
5268 return MESA_FORMAT_L_UNORM16
;
5269 case GL_LUMINANCE16F_ARB
:
5270 return MESA_FORMAT_L_FLOAT16
;
5271 case GL_LUMINANCE32F_ARB
:
5272 return MESA_FORMAT_L_FLOAT32
;
5273 case GL_LUMINANCE8I_EXT
:
5274 return MESA_FORMAT_L_SINT8
;
5275 case GL_LUMINANCE16I_EXT
:
5276 return MESA_FORMAT_L_SINT16
;
5277 case GL_LUMINANCE32I_EXT
:
5278 return MESA_FORMAT_L_SINT32
;
5279 case GL_LUMINANCE8UI_EXT
:
5280 return MESA_FORMAT_L_UINT8
;
5281 case GL_LUMINANCE16UI_EXT
:
5282 return MESA_FORMAT_L_UINT16
;
5283 case GL_LUMINANCE32UI_EXT
:
5284 return MESA_FORMAT_L_UINT32
;
5285 case GL_LUMINANCE8_ALPHA8
:
5286 return MESA_FORMAT_L8A8_UNORM
;
5287 case GL_LUMINANCE16_ALPHA16
:
5288 return MESA_FORMAT_L16A16_UNORM
;
5289 case GL_LUMINANCE_ALPHA16F_ARB
:
5290 return MESA_FORMAT_LA_FLOAT16
;
5291 case GL_LUMINANCE_ALPHA32F_ARB
:
5292 return MESA_FORMAT_LA_FLOAT32
;
5293 case GL_LUMINANCE_ALPHA8I_EXT
:
5294 return MESA_FORMAT_LA_SINT8
;
5295 case GL_LUMINANCE_ALPHA16I_EXT
:
5296 return MESA_FORMAT_LA_SINT16
;
5297 case GL_LUMINANCE_ALPHA32I_EXT
:
5298 return MESA_FORMAT_LA_SINT32
;
5299 case GL_LUMINANCE_ALPHA8UI_EXT
:
5300 return MESA_FORMAT_LA_UINT8
;
5301 case GL_LUMINANCE_ALPHA16UI_EXT
:
5302 return MESA_FORMAT_LA_UINT16
;
5303 case GL_LUMINANCE_ALPHA32UI_EXT
:
5304 return MESA_FORMAT_LA_UINT32
;
5306 return MESA_FORMAT_I_UNORM8
;
5307 case GL_INTENSITY16
:
5308 return MESA_FORMAT_I_UNORM16
;
5309 case GL_INTENSITY16F_ARB
:
5310 return MESA_FORMAT_I_FLOAT16
;
5311 case GL_INTENSITY32F_ARB
:
5312 return MESA_FORMAT_I_FLOAT32
;
5313 case GL_INTENSITY8I_EXT
:
5314 return MESA_FORMAT_I_SINT8
;
5315 case GL_INTENSITY16I_EXT
:
5316 return MESA_FORMAT_I_SINT16
;
5317 case GL_INTENSITY32I_EXT
:
5318 return MESA_FORMAT_I_SINT32
;
5319 case GL_INTENSITY8UI_EXT
:
5320 return MESA_FORMAT_I_UINT8
;
5321 case GL_INTENSITY16UI_EXT
:
5322 return MESA_FORMAT_I_UINT16
;
5323 case GL_INTENSITY32UI_EXT
:
5324 return MESA_FORMAT_I_UINT32
;
5330 if (_mesa_has_ARB_texture_buffer_object_rgb32(ctx
) ||
5331 _mesa_has_OES_texture_buffer(ctx
)) {
5332 switch (internalFormat
) {
5334 return MESA_FORMAT_RGB_FLOAT32
;
5336 return MESA_FORMAT_RGB_UINT32
;
5338 return MESA_FORMAT_RGB_SINT32
;
5344 switch (internalFormat
) {
5346 return MESA_FORMAT_R8G8B8A8_UNORM
;
5348 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5349 return MESA_FORMAT_NONE
;
5350 return MESA_FORMAT_RGBA_UNORM16
;
5351 case GL_RGBA16F_ARB
:
5352 return MESA_FORMAT_RGBA_FLOAT16
;
5353 case GL_RGBA32F_ARB
:
5354 return MESA_FORMAT_RGBA_FLOAT32
;
5356 return MESA_FORMAT_RGBA_SINT8
;
5357 case GL_RGBA16I_EXT
:
5358 return MESA_FORMAT_RGBA_SINT16
;
5359 case GL_RGBA32I_EXT
:
5360 return MESA_FORMAT_RGBA_SINT32
;
5361 case GL_RGBA8UI_EXT
:
5362 return MESA_FORMAT_RGBA_UINT8
;
5363 case GL_RGBA16UI_EXT
:
5364 return MESA_FORMAT_RGBA_UINT16
;
5365 case GL_RGBA32UI_EXT
:
5366 return MESA_FORMAT_RGBA_UINT32
;
5369 return MESA_FORMAT_R8G8_UNORM
;
5371 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5372 return MESA_FORMAT_NONE
;
5373 return MESA_FORMAT_R16G16_UNORM
;
5375 return MESA_FORMAT_RG_FLOAT16
;
5377 return MESA_FORMAT_RG_FLOAT32
;
5379 return MESA_FORMAT_RG_SINT8
;
5381 return MESA_FORMAT_RG_SINT16
;
5383 return MESA_FORMAT_RG_SINT32
;
5385 return MESA_FORMAT_RG_UINT8
;
5387 return MESA_FORMAT_RG_UINT16
;
5389 return MESA_FORMAT_RG_UINT32
;
5392 return MESA_FORMAT_R_UNORM8
;
5394 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5395 return MESA_FORMAT_NONE
;
5396 return MESA_FORMAT_R_UNORM16
;
5398 return MESA_FORMAT_R_FLOAT16
;
5400 return MESA_FORMAT_R_FLOAT32
;
5402 return MESA_FORMAT_R_SINT8
;
5404 return MESA_FORMAT_R_SINT16
;
5406 return MESA_FORMAT_R_SINT32
;
5408 return MESA_FORMAT_R_UINT8
;
5410 return MESA_FORMAT_R_UINT16
;
5412 return MESA_FORMAT_R_UINT32
;
5415 return MESA_FORMAT_NONE
;
5421 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5422 GLenum internalFormat
)
5424 mesa_format format
= _mesa_get_texbuffer_format(ctx
, internalFormat
);
5427 if (format
== MESA_FORMAT_NONE
)
5428 return MESA_FORMAT_NONE
;
5430 datatype
= _mesa_get_format_datatype(format
);
5432 /* The GL_ARB_texture_buffer_object spec says:
5434 * "If ARB_texture_float is not supported, references to the
5435 * floating-point internal formats provided by that extension should be
5436 * removed, and such formats may not be passed to TexBufferARB."
5438 * As a result, GL_HALF_FLOAT internal format depends on both
5439 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5441 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5442 !ctx
->Extensions
.ARB_texture_float
)
5443 return MESA_FORMAT_NONE
;
5445 if (!ctx
->Extensions
.ARB_texture_rg
) {
5446 GLenum base_format
= _mesa_get_format_base_format(format
);
5447 if (base_format
== GL_R
|| base_format
== GL_RG
)
5448 return MESA_FORMAT_NONE
;
5451 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5452 GLenum base_format
= _mesa_get_format_base_format(format
);
5453 if (base_format
== GL_RGB
)
5454 return MESA_FORMAT_NONE
;
5461 * Do work common to glTexBuffer, glTexBufferRange, glTextureBuffer
5462 * and glTextureBufferRange, including some error checking.
5465 texture_buffer_range(struct gl_context
*ctx
,
5466 struct gl_texture_object
*texObj
,
5467 GLenum internalFormat
,
5468 struct gl_buffer_object
*bufObj
,
5469 GLintptr offset
, GLsizeiptr size
,
5472 GLintptr oldOffset
= texObj
->BufferOffset
;
5473 GLsizeiptr oldSize
= texObj
->BufferSize
;
5476 /* NOTE: ARB_texture_buffer_object might not be supported in
5477 * the compatibility profile.
5479 if (!_mesa_has_ARB_texture_buffer_object(ctx
) &&
5480 !_mesa_has_OES_texture_buffer(ctx
)) {
5481 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5482 "%s(ARB_texture_buffer_object is not"
5483 " implemented for the compatibility profile)", caller
);
5487 if (texObj
->HandleAllocated
) {
5488 /* The ARB_bindless_texture spec says:
5490 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
5491 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
5492 * functions defined in terms of these, if the texture object to be
5493 * modified is referenced by one or more texture or image handles."
5495 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable texture)", caller
);
5499 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5500 if (format
== MESA_FORMAT_NONE
) {
5501 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat %s)",
5502 caller
, _mesa_enum_to_string(internalFormat
));
5506 FLUSH_VERTICES(ctx
, 0);
5508 _mesa_lock_texture(ctx
, texObj
);
5510 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5511 texObj
->BufferObjectFormat
= internalFormat
;
5512 texObj
->_BufferObjectFormat
= format
;
5513 texObj
->BufferOffset
= offset
;
5514 texObj
->BufferSize
= size
;
5516 _mesa_unlock_texture(ctx
, texObj
);
5518 if (ctx
->Driver
.TexParameter
) {
5519 if (offset
!= oldOffset
) {
5520 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_OFFSET
);
5522 if (size
!= oldSize
) {
5523 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_SIZE
);
5527 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5530 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5536 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5537 * Return true if it is, and return false if it is not
5538 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5539 * core spec, 02.02.2015, PDF page 245).
5542 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5545 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5546 _mesa_error(ctx
, GL_INVALID_ENUM
,
5547 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5555 * Check for errors related to the texture buffer range.
5556 * Return false if errors are found, true if none are found.
5559 check_texture_buffer_range(struct gl_context
*ctx
,
5560 struct gl_buffer_object
*bufObj
,
5561 GLintptr offset
, GLsizeiptr size
,
5564 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5565 * Textures (PDF page 245):
5566 * "An INVALID_VALUE error is generated if offset is negative, if
5567 * size is less than or equal to zero, or if offset + size is greater
5568 * than the value of BUFFER_SIZE for the buffer bound to target."
5571 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5577 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5582 if (offset
+ size
> bufObj
->Size
) {
5583 _mesa_error(ctx
, GL_INVALID_VALUE
,
5584 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5585 (int) offset
, (int) size
, (int) bufObj
->Size
);
5589 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5590 * Textures (PDF page 245):
5591 * "An INVALID_VALUE error is generated if offset is not an integer
5592 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5594 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5595 _mesa_error(ctx
, GL_INVALID_VALUE
,
5596 "%s(invalid offset alignment)", caller
);
5604 /** GL_ARB_texture_buffer_object */
5606 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5608 struct gl_texture_object
*texObj
;
5609 struct gl_buffer_object
*bufObj
;
5611 GET_CURRENT_CONTEXT(ctx
);
5613 /* Need to catch a bad target before it gets to
5614 * _mesa_get_current_tex_object.
5616 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5620 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5626 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5630 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5631 buffer
? -1 : 0, "glTexBuffer");
5635 /** GL_ARB_texture_buffer_range */
5637 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5638 GLintptr offset
, GLsizeiptr size
)
5640 struct gl_texture_object
*texObj
;
5641 struct gl_buffer_object
*bufObj
;
5643 GET_CURRENT_CONTEXT(ctx
);
5645 /* Need to catch a bad target before it gets to
5646 * _mesa_get_current_tex_object.
5648 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5652 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5656 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5657 "glTexBufferRange"))
5661 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5662 * Textures (PDF page 254):
5663 * "If buffer is zero, then any buffer object attached to the buffer
5664 * texture is detached, the values offset and size are ignored and
5665 * the state for offset and size for the buffer texture are reset to
5673 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5677 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5678 offset
, size
, "glTexBufferRange");
5682 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5684 struct gl_texture_object
*texObj
;
5685 struct gl_buffer_object
*bufObj
;
5687 GET_CURRENT_CONTEXT(ctx
);
5690 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5696 /* Get the texture object by Name. */
5697 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5701 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5704 texture_buffer_range(ctx
, texObj
, internalFormat
,
5705 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5709 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5710 GLintptr offset
, GLsizeiptr size
)
5712 struct gl_texture_object
*texObj
;
5713 struct gl_buffer_object
*bufObj
;
5715 GET_CURRENT_CONTEXT(ctx
);
5718 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5719 "glTextureBufferRange");
5723 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5724 "glTextureBufferRange"))
5728 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5729 * Textures (PDF page 254):
5730 * "If buffer is zero, then any buffer object attached to the buffer
5731 * texture is detached, the values offset and size are ignored and
5732 * the state for offset and size for the buffer texture are reset to
5740 /* Get the texture object by Name. */
5741 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5745 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5746 "glTextureBufferRange"))
5749 texture_buffer_range(ctx
, texObj
, internalFormat
,
5750 bufObj
, offset
, size
, "glTextureBufferRange");
5754 _mesa_is_renderable_texture_format(const struct gl_context
*ctx
,
5755 GLenum internalformat
)
5757 /* Everything that is allowed for renderbuffers,
5758 * except for a base format of GL_STENCIL_INDEX, unless supported.
5760 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5761 if (ctx
->Extensions
.ARB_texture_stencil8
)
5762 return baseFormat
!= 0;
5764 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5768 /** GL_ARB_texture_multisample */
5770 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5773 case GL_TEXTURE_2D_MULTISAMPLE
:
5775 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5776 return dims
== 2 && !dsa
;
5777 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5779 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5780 return dims
== 3 && !dsa
;
5788 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5789 struct gl_texture_object
*texObj
,
5790 struct gl_memory_object
*memObj
,
5791 GLenum target
, GLsizei samples
,
5792 GLint internalformat
, GLsizei width
,
5793 GLsizei height
, GLsizei depth
,
5794 GLboolean fixedsamplelocations
,
5795 GLboolean immutable
, GLuint64 offset
,
5798 struct gl_texture_image
*texImage
;
5799 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5800 mesa_format texFormat
;
5801 GLenum sample_count_error
;
5802 bool dsa
= strstr(func
, "ture") ? true : false;
5804 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
5805 _mesa_debug(ctx
, "%s(target=%s, samples=%d)\n", func
,
5806 _mesa_enum_to_string(target
), samples
);
5809 if (!((ctx
->Extensions
.ARB_texture_multisample
5810 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5811 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5816 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5820 if (!check_multisample_target(dims
, target
, dsa
)) {
5821 GLenum err
= dsa
? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
5822 _mesa_error(ctx
, err
, "%s(target=%s)", func
,
5823 _mesa_enum_to_string(target
));
5827 /* check that the specified internalformat is color/depth/stencil-renderable;
5828 * refer GL3.1 spec 4.4.4
5831 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5832 _mesa_error(ctx
, GL_INVALID_ENUM
,
5833 "%s(internalformat=%s not legal for immutable-format)",
5834 func
, _mesa_enum_to_string(internalformat
));
5838 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
)) {
5839 /* Page 172 of OpenGL ES 3.1 spec says:
5840 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5841 * color-renderable, depth-renderable, or stencil-renderable (as
5842 * defined in section 9.4).
5844 * (Same error is also defined for desktop OpenGL for multisample
5845 * teximage/texstorage functions.)
5847 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5848 _mesa_enum_to_string(internalformat
));
5852 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5853 internalformat
, samples
, samples
);
5854 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5856 /* Page 254 of OpenGL 4.4 spec says:
5857 * "Proxy arrays for two-dimensional multisample and two-dimensional
5858 * multisample array textures are operated on in the same way when
5859 * TexImage2DMultisample is called with target specified as
5860 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5861 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5862 * However, if samples is not supported, then no error is generated.
5864 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5865 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
5869 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5870 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5871 "%s(texture object 0)",
5876 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5878 if (texImage
== NULL
) {
5879 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5883 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5884 internalformat
, GL_NONE
, GL_NONE
);
5885 assert(texFormat
!= MESA_FORMAT_NONE
);
5887 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5888 width
, height
, depth
, 0);
5890 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, 0, texFormat
,
5891 samples
, width
, height
, depth
);
5893 if (_mesa_is_proxy_texture(target
)) {
5894 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5895 _mesa_init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5896 internalformat
, texFormat
,
5897 samples
, fixedsamplelocations
);
5900 /* clear all image fields */
5901 clear_teximage_fields(texImage
);
5905 if (!dimensionsOK
) {
5906 _mesa_error(ctx
, GL_INVALID_VALUE
,
5907 "%s(invalid width=%d or height=%d)", func
, width
, height
);
5912 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5916 /* Check if texObj->Immutable is set */
5917 if (texObj
->Immutable
) {
5918 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5922 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5924 _mesa_init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5925 internalformat
, texFormat
,
5926 samples
, fixedsamplelocations
);
5928 if (width
> 0 && height
> 0 && depth
> 0) {
5930 if (!ctx
->Driver
.SetTextureStorageForMemoryObject(ctx
, texObj
,
5935 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
5936 internalformat
, texFormat
);
5939 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5940 width
, height
, depth
)) {
5941 /* tidy up the texture image state. strictly speaking,
5942 * we're allowed to just leave this in whatever state we
5943 * like, but being tidy is good.
5945 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
5946 internalformat
, texFormat
);
5951 texObj
->Immutable
|= immutable
;
5954 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5957 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5963 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5964 GLenum internalformat
, GLsizei width
,
5965 GLsizei height
, GLboolean fixedsamplelocations
)
5967 struct gl_texture_object
*texObj
;
5968 GET_CURRENT_CONTEXT(ctx
);
5970 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5974 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
5975 internalformat
, width
, height
, 1,
5976 fixedsamplelocations
, GL_FALSE
, 0,
5977 "glTexImage2DMultisample");
5982 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5983 GLenum internalformat
, GLsizei width
,
5984 GLsizei height
, GLsizei depth
,
5985 GLboolean fixedsamplelocations
)
5987 struct gl_texture_object
*texObj
;
5988 GET_CURRENT_CONTEXT(ctx
);
5990 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5994 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
5995 internalformat
, width
, height
, depth
,
5996 fixedsamplelocations
, GL_FALSE
, 0,
5997 "glTexImage3DMultisample");
6001 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
6004 GET_CURRENT_CONTEXT(ctx
);
6006 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
6007 _mesa_error(ctx
, GL_INVALID_VALUE
,
6008 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
6009 dims
, width
, height
, depth
);
6016 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
6017 GLenum internalformat
, GLsizei width
,
6018 GLsizei height
, GLboolean fixedsamplelocations
)
6020 struct gl_texture_object
*texObj
;
6021 GET_CURRENT_CONTEXT(ctx
);
6023 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6027 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
6030 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
6031 internalformat
, width
, height
, 1,
6032 fixedsamplelocations
, GL_TRUE
, 0,
6033 "glTexStorage2DMultisample");
6037 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
6038 GLenum internalformat
, GLsizei width
,
6039 GLsizei height
, GLsizei depth
,
6040 GLboolean fixedsamplelocations
)
6042 struct gl_texture_object
*texObj
;
6043 GET_CURRENT_CONTEXT(ctx
);
6045 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6049 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
6052 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
6053 internalformat
, width
, height
, depth
,
6054 fixedsamplelocations
, GL_TRUE
, 0,
6055 "glTexStorage3DMultisample");
6059 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
6060 GLenum internalformat
, GLsizei width
,
6062 GLboolean fixedsamplelocations
)
6064 struct gl_texture_object
*texObj
;
6065 GET_CURRENT_CONTEXT(ctx
);
6067 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6068 "glTextureStorage2DMultisample");
6072 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
6075 texture_image_multisample(ctx
, 2, texObj
, NULL
, texObj
->Target
,
6076 samples
, internalformat
, width
, height
, 1,
6077 fixedsamplelocations
, GL_TRUE
, 0,
6078 "glTextureStorage2DMultisample");
6082 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
6083 GLenum internalformat
, GLsizei width
,
6084 GLsizei height
, GLsizei depth
,
6085 GLboolean fixedsamplelocations
)
6087 struct gl_texture_object
*texObj
;
6088 GET_CURRENT_CONTEXT(ctx
);
6090 /* Get the texture object by Name. */
6091 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6092 "glTextureStorage3DMultisample");
6096 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
6099 texture_image_multisample(ctx
, 3, texObj
, NULL
, texObj
->Target
, samples
,
6100 internalformat
, width
, height
, depth
,
6101 fixedsamplelocations
, GL_TRUE
, 0,
6102 "glTextureStorage3DMultisample");
6106 _mesa_texture_storage_ms_memory(struct gl_context
*ctx
, GLuint dims
,
6107 struct gl_texture_object
*texObj
,
6108 struct gl_memory_object
*memObj
,
6109 GLenum target
, GLsizei samples
,
6110 GLenum internalFormat
, GLsizei width
,
6111 GLsizei height
, GLsizei depth
,
6112 GLboolean fixedSampleLocations
,
6113 GLuint64 offset
, const char* func
)
6117 texture_image_multisample(ctx
, dims
, texObj
, memObj
, target
, samples
,
6118 internalFormat
, width
, height
, depth
,
6119 fixedSampleLocations
, GL_TRUE
, offset
,