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_has_EXT_render_snorm(ctx
) &&
2472 _mesa_is_enum_format_snorm(internalFormat
)) {
2473 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2474 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2475 _mesa_enum_to_string(internalFormat
));
2480 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2481 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2482 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2486 /* From the EXT_texture_integer spec:
2488 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2489 * if the texture internalformat is an integer format and the read color
2490 * buffer is not an integer format, or if the internalformat is not an
2491 * integer format and the read color buffer is an integer format."
2493 if (_mesa_is_color_format(internalFormat
)) {
2494 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2495 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2496 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2497 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2498 if (is_int
|| is_rbint
) {
2499 if (is_int
!= is_rbint
) {
2500 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2501 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2503 } else if (_mesa_is_gles(ctx
) &&
2504 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2505 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2506 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2507 "glCopyTexImage%dD(signed vs unsigned integer)",
2513 /* From page 138 of OpenGL ES 3.0 spec:
2514 * "The error INVALID_OPERATION is generated if floating-point RGBA
2515 * data is required; if signed integer RGBA data is required and the
2516 * format of the current color buffer is not signed integer; if
2517 * unsigned integer RGBA data is required and the format of the
2518 * current color buffer is not unsigned integer; or if fixed-point
2519 * RGBA data is required and the format of the current color buffer
2520 * is not fixed-point.
2522 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2523 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2524 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2527 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2529 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2530 _mesa_error(ctx
, err
,
2531 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2534 if (_mesa_format_no_online_compression(internalFormat
)) {
2535 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2536 "glCopyTexImage%dD(no compression for format)", dimensions
);
2540 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2541 "glCopyTexImage%dD(border!=0)", dimensions
);
2546 if (!mutable_tex_object(ctx
, target
)) {
2547 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2548 "glCopyTexImage%dD(immutable texture)", dimensions
);
2552 /* if we get here, the parameters are OK */
2558 * Test glCopyTexSubImage[12]D() parameters for errors.
2559 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2562 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2563 const struct gl_texture_object
*texObj
,
2564 GLenum target
, GLint level
,
2565 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2566 GLint width
, GLint height
, const char *caller
)
2570 struct gl_texture_image
*texImage
;
2572 /* Check that the source buffer is complete */
2573 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2574 if (ctx
->ReadBuffer
->_Status
== 0) {
2575 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2577 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2578 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2579 "%s(invalid readbuffer)", caller
);
2583 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2584 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2585 "%s(multisample FBO)", caller
);
2591 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2592 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2596 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2598 /* destination image does not exist */
2599 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2600 "%s(invalid texture level %d)", caller
, level
);
2604 if (error_check_subtexture_negative_dimensions(ctx
, dimensions
,
2605 width
, height
, 1, caller
)) {
2609 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2610 xoffset
, yoffset
, zoffset
,
2611 width
, height
, 1, caller
)) {
2615 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2616 if (_mesa_format_no_online_compression(texImage
->InternalFormat
)) {
2617 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2618 "%s(no compression for format)", caller
);
2623 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2624 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2628 /* From OpenGL ES 3.2 spec, section 8.6:
2630 * "An INVALID_OPERATION error is generated by CopyTexSubImage3D,
2631 * CopyTexImage2D, or CopyTexSubImage2D if the internalformat of the
2632 * texture image being (re)specified is RGB9_E5"
2634 if (texImage
->InternalFormat
== GL_RGB9_E5
&&
2635 !_mesa_is_desktop_gl(ctx
)) {
2636 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2637 "%s(invalid internal format %s)", caller
,
2638 _mesa_enum_to_string(texImage
->InternalFormat
));
2642 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2643 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2644 "%s(missing readbuffer, format=%s)", caller
,
2645 _mesa_enum_to_string(texImage
->_BaseFormat
));
2649 /* From the EXT_texture_integer spec:
2651 * "INVALID_OPERATION is generated by CopyTexImage* and
2652 * CopyTexSubImage* if the texture internalformat is an integer format
2653 * and the read color buffer is not an integer format, or if the
2654 * internalformat is not an integer format and the read color buffer
2655 * is an integer format."
2657 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2658 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2660 if (_mesa_is_format_integer_color(rb
->Format
) !=
2661 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2662 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2663 "%s(integer vs non-integer)", caller
);
2668 /* In the ES 3.2 specification's Table 8.13 (Valid CopyTexImage source
2669 * framebuffer/destination texture base internal format combinations),
2670 * all the entries for stencil are left blank (unsupported).
2672 if (_mesa_is_gles(ctx
) && _mesa_is_stencil_format(texImage
->_BaseFormat
)) {
2673 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(stencil disallowed)", caller
);
2677 /* if we get here, the parameters are OK */
2682 /** Callback info for walking over FBO hash table */
2685 struct gl_context
*ctx
;
2686 struct gl_texture_object
*texObj
;
2692 * Check render to texture callback. Called from _mesa_HashWalk().
2695 check_rtt_cb(UNUSED GLuint key
, void *data
, void *userData
)
2697 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2698 const struct cb_info
*info
= (struct cb_info
*) userData
;
2699 struct gl_context
*ctx
= info
->ctx
;
2700 const struct gl_texture_object
*texObj
= info
->texObj
;
2701 const GLuint level
= info
->level
, face
= info
->face
;
2703 /* If this is a user-created FBO */
2704 if (_mesa_is_user_fbo(fb
)) {
2706 /* check if any of the FBO's attachments point to 'texObj' */
2707 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2708 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2709 if (att
->Type
== GL_TEXTURE
&&
2710 att
->Texture
== texObj
&&
2711 att
->TextureLevel
== level
&&
2712 att
->CubeMapFace
== face
) {
2713 _mesa_update_texture_renderbuffer(ctx
, fb
, att
);
2714 assert(att
->Renderbuffer
->TexImage
);
2715 /* Mark fb status as indeterminate to force re-validation */
2718 /* Make sure that the revalidation actually happens if this is
2719 * being done to currently-bound buffers.
2721 if (fb
== ctx
->DrawBuffer
|| fb
== ctx
->ReadBuffer
)
2722 ctx
->NewState
|= _NEW_BUFFERS
;
2730 * When a texture image is specified we have to check if it's bound to
2731 * any framebuffer objects (render to texture) in order to detect changes
2732 * in size or format since that effects FBO completeness.
2733 * Any FBOs rendering into the texture must be re-validated.
2736 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2737 struct gl_texture_object
*texObj
,
2738 GLuint face
, GLuint level
)
2740 /* Only check this texture if it's been marked as RenderToTexture */
2741 if (texObj
->_RenderToTexture
) {
2742 struct cb_info info
;
2744 info
.texObj
= texObj
;
2747 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2753 * If the texture object's GenerateMipmap flag is set and we've
2754 * changed the texture base level image, regenerate the rest of the
2755 * mipmap levels now.
2758 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2759 struct gl_texture_object
*texObj
, GLint level
)
2761 if (texObj
->GenerateMipmap
&&
2762 level
== texObj
->BaseLevel
&&
2763 level
< texObj
->MaxLevel
) {
2764 assert(ctx
->Driver
.GenerateMipmap
);
2765 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2770 /** Debug helper: override the user-requested internal format */
2772 override_internal_format(GLenum internalFormat
, UNUSED GLint width
,
2773 UNUSED GLint height
)
2776 if (internalFormat
== GL_RGBA16F_ARB
||
2777 internalFormat
== GL_RGBA32F_ARB
) {
2778 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2781 else if (internalFormat
== GL_RGB16F_ARB
||
2782 internalFormat
== GL_RGB32F_ARB
) {
2783 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2786 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2787 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2788 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2789 return GL_LUMINANCE_ALPHA
;
2791 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2792 internalFormat
== GL_LUMINANCE32F_ARB
) {
2793 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2794 return GL_LUMINANCE
;
2796 else if (internalFormat
== GL_ALPHA16F_ARB
||
2797 internalFormat
== GL_ALPHA32F_ARB
) {
2798 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2802 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2803 internalFormat = GL_RGBA;
2807 return internalFormat
;
2810 return internalFormat
;
2816 * Choose the actual hardware format for a texture image.
2817 * Try to use the same format as the previous image level when possible.
2818 * Otherwise, ask the driver for the best format.
2819 * It's important to try to choose a consistant format for all levels
2820 * for efficient texture memory layout/allocation. In particular, this
2821 * comes up during automatic mipmap generation.
2824 _mesa_choose_texture_format(struct gl_context
*ctx
,
2825 struct gl_texture_object
*texObj
,
2826 GLenum target
, GLint level
,
2827 GLenum internalFormat
, GLenum format
, GLenum type
)
2831 /* see if we've already chosen a format for the previous level */
2833 struct gl_texture_image
*prevImage
=
2834 _mesa_select_tex_image(texObj
, target
, level
- 1);
2835 /* See if the prev level is defined and has an internal format which
2836 * matches the new internal format.
2839 prevImage
->Width
> 0 &&
2840 prevImage
->InternalFormat
== internalFormat
) {
2841 /* use the same format */
2842 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2843 return prevImage
->TexFormat
;
2847 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
2849 assert(f
!= MESA_FORMAT_NONE
);
2855 * Adjust pixel unpack params and image dimensions to strip off the
2856 * one-pixel texture border.
2858 * Gallium and intel don't support texture borders. They've seldem been used
2859 * and seldom been implemented correctly anyway.
2861 * \param unpackNew returns the new pixel unpack parameters
2864 strip_texture_border(GLenum target
,
2865 GLint
*width
, GLint
*height
, GLint
*depth
,
2866 const struct gl_pixelstore_attrib
*unpack
,
2867 struct gl_pixelstore_attrib
*unpackNew
)
2873 *unpackNew
= *unpack
;
2875 if (unpackNew
->RowLength
== 0)
2876 unpackNew
->RowLength
= *width
;
2878 if (unpackNew
->ImageHeight
== 0)
2879 unpackNew
->ImageHeight
= *height
;
2881 assert(*width
>= 3);
2882 unpackNew
->SkipPixels
++; /* skip the border */
2883 *width
= *width
- 2; /* reduce the width by two border pixels */
2885 /* The min height of a texture with a border is 3 */
2886 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2887 unpackNew
->SkipRows
++; /* skip the border */
2888 *height
= *height
- 2; /* reduce the height by two border pixels */
2892 target
!= GL_TEXTURE_2D_ARRAY
&&
2893 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2894 unpackNew
->SkipImages
++; /* skip the border */
2895 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2901 * Common code to implement all the glTexImage1D/2D/3D functions
2902 * as well as glCompressedTexImage1D/2D/3D.
2903 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2904 * \param format the user's image format (only used if !compressed)
2905 * \param type the user's image type (only used if !compressed)
2906 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2908 static ALWAYS_INLINE
void
2909 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2910 GLenum target
, GLint level
, GLint internalFormat
,
2911 GLsizei width
, GLsizei height
, GLsizei depth
,
2912 GLint border
, GLenum format
, GLenum type
,
2913 GLsizei imageSize
, const GLvoid
*pixels
, bool no_error
)
2915 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2916 struct gl_pixelstore_attrib unpack_no_border
;
2917 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2918 struct gl_texture_object
*texObj
;
2919 mesa_format texFormat
;
2920 bool dimensionsOK
= true, sizeOK
= true;
2922 FLUSH_VERTICES(ctx
, 0);
2924 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2927 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2929 _mesa_enum_to_string(target
), level
,
2930 _mesa_enum_to_string(internalFormat
),
2931 width
, height
, depth
, border
, pixels
);
2934 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2936 _mesa_enum_to_string(target
), level
,
2937 _mesa_enum_to_string(internalFormat
),
2938 width
, height
, depth
, border
,
2939 _mesa_enum_to_string(format
),
2940 _mesa_enum_to_string(type
), pixels
);
2943 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2946 /* target error checking */
2947 if (!legal_teximage_target(ctx
, dims
, target
)) {
2948 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2949 func
, dims
, _mesa_enum_to_string(target
));
2953 /* general error checking */
2955 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2957 width
, height
, depth
,
2958 border
, imageSize
, pixels
))
2961 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2962 format
, type
, width
, height
, depth
, border
,
2968 /* Here we convert a cpal compressed image into a regular glTexImage2D
2969 * call by decompressing the texture. If we really want to support cpal
2970 * textures in any driver this would have to be changed.
2972 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
2973 switch (internalFormat
) {
2974 case GL_PALETTE4_RGB8_OES
:
2975 case GL_PALETTE4_RGBA8_OES
:
2976 case GL_PALETTE4_R5_G6_B5_OES
:
2977 case GL_PALETTE4_RGBA4_OES
:
2978 case GL_PALETTE4_RGB5_A1_OES
:
2979 case GL_PALETTE8_RGB8_OES
:
2980 case GL_PALETTE8_RGBA8_OES
:
2981 case GL_PALETTE8_R5_G6_B5_OES
:
2982 case GL_PALETTE8_RGBA4_OES
:
2983 case GL_PALETTE8_RGB5_A1_OES
:
2984 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
2985 width
, height
, imageSize
, pixels
);
2990 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2994 /* For glCompressedTexImage() the driver has no choice about the
2995 * texture format since we'll never transcode the user's compressed
2996 * image data. The internalFormat was error checked earlier.
2998 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3001 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3002 * internal floating point format for the given base format.
3004 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3005 if (type
== GL_FLOAT
) {
3006 texObj
->_IsFloat
= GL_TRUE
;
3007 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3008 texObj
->_IsHalfFloat
= GL_TRUE
;
3011 internalFormat
= adjust_for_oes_float_texture(ctx
, format
, type
);
3014 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3015 internalFormat
, format
, type
);
3018 assert(texFormat
!= MESA_FORMAT_NONE
);
3021 /* check that width, height, depth are legal for the mipmap level */
3022 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3023 height
, depth
, border
);
3025 /* check that the texture won't take too much memory, etc */
3026 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3027 0, level
, texFormat
, 1,
3028 width
, height
, depth
);
3031 if (_mesa_is_proxy_texture(target
)) {
3032 /* Proxy texture: just clear or set state depending on error checking */
3033 struct gl_texture_image
*texImage
=
3034 get_proxy_tex_image(ctx
, target
, level
);
3037 return; /* GL_OUT_OF_MEMORY already recorded */
3039 if (dimensionsOK
&& sizeOK
) {
3040 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3041 border
, internalFormat
, texFormat
);
3044 clear_teximage_fields(texImage
);
3048 /* non-proxy target */
3049 const GLuint face
= _mesa_tex_target_to_face(target
);
3050 struct gl_texture_image
*texImage
;
3052 if (!dimensionsOK
) {
3053 _mesa_error(ctx
, GL_INVALID_VALUE
,
3054 "%s%uD(invalid width=%d or height=%d or depth=%d)",
3055 func
, dims
, width
, height
, depth
);
3060 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3061 "%s%uD(image too large: %d x %d x %d, %s format)",
3062 func
, dims
, width
, height
, depth
,
3063 _mesa_enum_to_string(internalFormat
));
3067 /* Allow a hardware driver to just strip out the border, to provide
3068 * reliable but slightly incorrect hardware rendering instead of
3069 * rarely-tested software fallback rendering.
3071 if (border
&& ctx
->Const
.StripTextureBorder
) {
3072 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3075 unpack
= &unpack_no_border
;
3078 if (ctx
->NewState
& _NEW_PIXEL
)
3079 _mesa_update_state(ctx
);
3081 _mesa_lock_texture(ctx
, texObj
);
3083 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3086 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3089 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3091 _mesa_init_teximage_fields(ctx
, texImage
,
3092 width
, height
, depth
,
3093 border
, internalFormat
, texFormat
);
3095 /* Give the texture to the driver. <pixels> may be null. */
3096 if (width
> 0 && height
> 0 && depth
> 0) {
3098 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3102 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3103 type
, pixels
, unpack
);
3107 check_gen_mipmap(ctx
, target
, texObj
, level
);
3109 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3111 _mesa_dirty_texobj(ctx
, texObj
);
3114 _mesa_unlock_texture(ctx
, texObj
);
3119 /* This is a wrapper around teximage() so that we can force the KHR_no_error
3120 * logic to be inlined without inlining the function into all the callers.
3123 teximage_err(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3124 GLenum target
, GLint level
, GLint internalFormat
,
3125 GLsizei width
, GLsizei height
, GLsizei depth
,
3126 GLint border
, GLenum format
, GLenum type
,
3127 GLsizei imageSize
, const GLvoid
*pixels
)
3129 teximage(ctx
, compressed
, dims
, target
, level
, internalFormat
, width
, height
,
3130 depth
, border
, format
, type
, imageSize
, pixels
, false);
3135 teximage_no_error(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3136 GLenum target
, GLint level
, GLint internalFormat
,
3137 GLsizei width
, GLsizei height
, GLsizei depth
,
3138 GLint border
, GLenum format
, GLenum type
,
3139 GLsizei imageSize
, const GLvoid
*pixels
)
3141 teximage(ctx
, compressed
, dims
, target
, level
, internalFormat
, width
, height
,
3142 depth
, border
, format
, type
, imageSize
, pixels
, true);
3147 * Called from the API. Note that width includes the border.
3150 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3151 GLsizei width
, GLint border
, GLenum format
,
3152 GLenum type
, const GLvoid
*pixels
)
3154 GET_CURRENT_CONTEXT(ctx
);
3155 teximage_err(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3156 border
, format
, type
, 0, pixels
);
3161 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3162 GLsizei width
, GLsizei height
, GLint border
,
3163 GLenum format
, GLenum type
,
3164 const GLvoid
*pixels
)
3166 GET_CURRENT_CONTEXT(ctx
);
3167 teximage_err(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3168 border
, format
, type
, 0, pixels
);
3173 * Called by the API or display list executor.
3174 * Note that width and height include the border.
3177 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3178 GLsizei width
, GLsizei height
, GLsizei depth
,
3179 GLint border
, GLenum format
, GLenum type
,
3180 const GLvoid
*pixels
)
3182 GET_CURRENT_CONTEXT(ctx
);
3183 teximage_err(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3184 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3189 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3190 GLsizei width
, GLsizei height
, GLsizei depth
,
3191 GLint border
, GLenum format
, GLenum type
,
3192 const GLvoid
*pixels
)
3194 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3195 depth
, border
, format
, type
, pixels
);
3200 _mesa_TexImage1D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3201 GLsizei width
, GLint border
, GLenum format
,
3202 GLenum type
, const GLvoid
*pixels
)
3204 GET_CURRENT_CONTEXT(ctx
);
3205 teximage_no_error(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1,
3206 1, border
, format
, type
, 0, pixels
);
3211 _mesa_TexImage2D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3212 GLsizei width
, GLsizei height
, GLint border
,
3213 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3215 GET_CURRENT_CONTEXT(ctx
);
3216 teximage_no_error(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
,
3217 height
, 1, border
, format
, type
, 0, pixels
);
3222 _mesa_TexImage3D_no_error(GLenum target
, GLint level
, GLint internalFormat
,
3223 GLsizei width
, GLsizei height
, GLsizei depth
,
3224 GLint border
, GLenum format
, GLenum type
,
3225 const GLvoid
*pixels
)
3227 GET_CURRENT_CONTEXT(ctx
);
3228 teximage_no_error(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3229 width
, height
, depth
, border
, format
, type
, 0, pixels
);
3234 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3236 struct gl_texture_object
*texObj
;
3237 struct gl_texture_image
*texImage
;
3239 GET_CURRENT_CONTEXT(ctx
);
3240 FLUSH_VERTICES(ctx
, 0);
3244 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3246 case GL_TEXTURE_EXTERNAL_OES
:
3248 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3251 valid_target
= false;
3255 if (!valid_target
) {
3256 _mesa_error(ctx
, GL_INVALID_ENUM
,
3257 "glEGLImageTargetTexture2D(target=%d)", target
);
3262 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3263 "glEGLImageTargetTexture2D(image=%p)", image
);
3267 if (ctx
->NewState
& _NEW_PIXEL
)
3268 _mesa_update_state(ctx
);
3270 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3274 _mesa_lock_texture(ctx
, texObj
);
3276 if (texObj
->Immutable
) {
3277 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3278 "glEGLImageTargetTexture2D(texture is immutable)");
3279 _mesa_unlock_texture(ctx
, texObj
);
3283 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3285 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3287 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3289 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3290 texObj
, texImage
, image
);
3292 _mesa_dirty_texobj(ctx
, texObj
);
3294 _mesa_unlock_texture(ctx
, texObj
);
3299 * Helper that implements the glTexSubImage1/2/3D()
3300 * and glTextureSubImage1/2/3D() functions.
3303 texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3304 struct gl_texture_object
*texObj
,
3305 struct gl_texture_image
*texImage
,
3306 GLenum target
, GLint level
,
3307 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3308 GLsizei width
, GLsizei height
, GLsizei depth
,
3309 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3311 FLUSH_VERTICES(ctx
, 0);
3313 if (ctx
->NewState
& _NEW_PIXEL
)
3314 _mesa_update_state(ctx
);
3316 _mesa_lock_texture(ctx
, texObj
);
3318 if (width
> 0 && height
> 0 && depth
> 0) {
3319 /* If we have a border, offset=-1 is legal. Bias by border width. */
3322 if (target
!= GL_TEXTURE_2D_ARRAY
)
3323 zoffset
+= texImage
->Border
;
3326 if (target
!= GL_TEXTURE_1D_ARRAY
)
3327 yoffset
+= texImage
->Border
;
3330 xoffset
+= texImage
->Border
;
3333 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3334 xoffset
, yoffset
, zoffset
,
3335 width
, height
, depth
,
3336 format
, type
, pixels
, &ctx
->Unpack
);
3338 check_gen_mipmap(ctx
, target
, texObj
, level
);
3340 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3341 * the texel data, not the texture format, size, etc.
3345 _mesa_unlock_texture(ctx
, texObj
);
3349 * Implement all the glTexSubImage1/2/3D() functions.
3350 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3353 texsubimage_err(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3354 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3355 GLsizei width
, GLsizei height
, GLsizei depth
,
3356 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3357 const char *callerName
)
3359 struct gl_texture_object
*texObj
;
3360 struct gl_texture_image
*texImage
;
3362 /* check target (proxies not allowed) */
3363 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3364 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3365 dims
, _mesa_enum_to_string(target
));
3369 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3373 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3374 xoffset
, yoffset
, zoffset
,
3375 width
, height
, depth
, format
, type
,
3376 pixels
, callerName
)) {
3377 return; /* error was detected */
3380 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3381 /* texsubimage_error_check ensures that texImage is not NULL */
3383 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3384 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3386 _mesa_enum_to_string(target
), level
,
3387 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3388 _mesa_enum_to_string(format
),
3389 _mesa_enum_to_string(type
), pixels
);
3391 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3392 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3393 format
, type
, pixels
);
3398 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3399 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3400 GLsizei width
, GLsizei height
, GLsizei depth
,
3401 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3403 struct gl_texture_object
*texObj
;
3404 struct gl_texture_image
*texImage
;
3406 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3407 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3409 texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3410 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3411 format
, type
, pixels
);
3416 * Implement all the glTextureSubImage1/2/3D() functions.
3417 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3419 static ALWAYS_INLINE
void
3420 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3421 GLuint texture
, GLint level
,
3422 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3423 GLsizei width
, GLsizei height
, GLsizei depth
,
3424 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3425 const char *callerName
, bool no_error
)
3427 struct gl_texture_object
*texObj
;
3428 struct gl_texture_image
*texImage
;
3431 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3433 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3434 dims
, texture
, level
,
3435 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3436 _mesa_enum_to_string(format
),
3437 _mesa_enum_to_string(type
), pixels
);
3439 /* Get the texture object by Name. */
3441 texObj
= _mesa_lookup_texture_err(ctx
, texture
, callerName
);
3445 texObj
= _mesa_lookup_texture(ctx
, texture
);
3449 /* check target (proxies not allowed) */
3450 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3451 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3452 callerName
, _mesa_enum_to_string(texObj
->Target
));
3456 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3457 xoffset
, yoffset
, zoffset
,
3458 width
, height
, depth
, format
, type
,
3459 pixels
, callerName
)) {
3460 return; /* error was detected */
3464 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3465 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3469 * What do we do if the user created a texture with the following code
3470 * and then called this function with its handle?
3473 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3474 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3475 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3476 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3477 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3478 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3479 * // wrong format, or given the wrong size, etc.
3480 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3481 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3483 * A bug has been filed against the spec for this case. In the
3484 * meantime, we will check for cube completeness.
3486 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3487 * Core Profile spec (30.10.2014):
3488 * "[A] cube map texture is cube complete if the
3489 * following conditions all hold true: The [base level] texture
3490 * images of each of the six cube map faces have identical, positive,
3491 * and square dimensions. The [base level] images were each specified
3492 * with the same internal format."
3494 * It seems reasonable to check for cube completeness of an arbitrary
3495 * level here so that the image data has a consistent format and size.
3497 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
3498 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3499 "glTextureSubImage%uD(cube map incomplete)",
3504 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3506 /* Copy in each face. */
3507 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3508 texImage
= texObj
->Image
[i
][level
];
3511 texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3512 level
, xoffset
, yoffset
, 0,
3513 width
, height
, 1, format
,
3515 pixels
= (GLubyte
*) pixels
+ imageStride
;
3519 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3522 texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3523 level
, xoffset
, yoffset
, zoffset
,
3524 width
, height
, depth
, format
,
3531 texturesubimage_error(struct gl_context
*ctx
, GLuint dims
,
3532 GLuint texture
, GLint level
,
3533 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3534 GLsizei width
, GLsizei height
, GLsizei depth
,
3535 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3536 const char *callerName
)
3538 texturesubimage(ctx
, dims
, texture
, level
, xoffset
, yoffset
, zoffset
,
3539 width
, height
, depth
, format
, type
, pixels
, callerName
,
3545 texturesubimage_no_error(struct gl_context
*ctx
, GLuint dims
,
3546 GLuint texture
, GLint level
,
3547 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3548 GLsizei width
, GLsizei height
, GLsizei depth
,
3549 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3550 const char *callerName
)
3552 texturesubimage(ctx
, dims
, texture
, level
, xoffset
, yoffset
, zoffset
,
3553 width
, height
, depth
, format
, type
, pixels
, callerName
,
3559 _mesa_TexSubImage1D_no_error(GLenum target
, GLint level
,
3560 GLint xoffset
, GLsizei width
,
3561 GLenum format
, GLenum type
,
3562 const GLvoid
*pixels
)
3564 GET_CURRENT_CONTEXT(ctx
);
3565 texsubimage(ctx
, 1, target
, level
,
3568 format
, type
, pixels
);
3573 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3574 GLint xoffset
, GLsizei width
,
3575 GLenum format
, GLenum type
,
3576 const GLvoid
*pixels
)
3578 GET_CURRENT_CONTEXT(ctx
);
3579 texsubimage_err(ctx
, 1, target
, level
,
3582 format
, type
, pixels
, "glTexSubImage1D");
3587 _mesa_TexSubImage2D_no_error(GLenum target
, GLint level
,
3588 GLint xoffset
, GLint yoffset
,
3589 GLsizei width
, GLsizei height
,
3590 GLenum format
, GLenum type
,
3591 const GLvoid
*pixels
)
3593 GET_CURRENT_CONTEXT(ctx
);
3594 texsubimage(ctx
, 2, target
, level
,
3595 xoffset
, yoffset
, 0,
3597 format
, type
, pixels
);
3602 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3603 GLint xoffset
, GLint yoffset
,
3604 GLsizei width
, GLsizei height
,
3605 GLenum format
, GLenum type
,
3606 const GLvoid
*pixels
)
3608 GET_CURRENT_CONTEXT(ctx
);
3609 texsubimage_err(ctx
, 2, target
, level
,
3610 xoffset
, yoffset
, 0,
3612 format
, type
, pixels
, "glTexSubImage2D");
3617 _mesa_TexSubImage3D_no_error(GLenum target
, GLint level
,
3618 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3619 GLsizei width
, GLsizei height
, GLsizei depth
,
3620 GLenum format
, GLenum type
,
3621 const GLvoid
*pixels
)
3623 GET_CURRENT_CONTEXT(ctx
);
3624 texsubimage(ctx
, 3, target
, level
,
3625 xoffset
, yoffset
, zoffset
,
3626 width
, height
, depth
,
3627 format
, type
, pixels
);
3632 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3633 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3634 GLsizei width
, GLsizei height
, GLsizei depth
,
3635 GLenum format
, GLenum type
,
3636 const GLvoid
*pixels
)
3638 GET_CURRENT_CONTEXT(ctx
);
3639 texsubimage_err(ctx
, 3, target
, level
,
3640 xoffset
, yoffset
, zoffset
,
3641 width
, height
, depth
,
3642 format
, type
, pixels
, "glTexSubImage3D");
3647 _mesa_TextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3648 GLsizei width
, GLenum format
, GLenum type
,
3649 const GLvoid
*pixels
)
3651 GET_CURRENT_CONTEXT(ctx
);
3652 texturesubimage_no_error(ctx
, 1, texture
, level
, xoffset
, 0, 0, width
, 1, 1,
3653 format
, type
, pixels
, "glTextureSubImage1D");
3658 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3659 GLint xoffset
, GLsizei width
,
3660 GLenum format
, GLenum type
,
3661 const GLvoid
*pixels
)
3663 GET_CURRENT_CONTEXT(ctx
);
3664 texturesubimage_error(ctx
, 1, texture
, level
, xoffset
, 0, 0, width
, 1, 1,
3665 format
, type
, pixels
, "glTextureSubImage1D");
3670 _mesa_TextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3671 GLint yoffset
, GLsizei width
, GLsizei height
,
3672 GLenum format
, GLenum type
,
3673 const GLvoid
*pixels
)
3675 GET_CURRENT_CONTEXT(ctx
);
3676 texturesubimage_no_error(ctx
, 2, texture
, level
, xoffset
, yoffset
, 0, width
,
3677 height
, 1, format
, type
, pixels
,
3678 "glTextureSubImage2D");
3683 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3684 GLint xoffset
, GLint yoffset
,
3685 GLsizei width
, GLsizei height
,
3686 GLenum format
, GLenum type
,
3687 const GLvoid
*pixels
)
3689 GET_CURRENT_CONTEXT(ctx
);
3690 texturesubimage_error(ctx
, 2, texture
, level
, xoffset
, yoffset
, 0, width
,
3691 height
, 1, format
, type
, pixels
,
3692 "glTextureSubImage2D");
3697 _mesa_TextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
3698 GLint yoffset
, GLint zoffset
, GLsizei width
,
3699 GLsizei height
, GLsizei depth
, GLenum format
,
3700 GLenum type
, const GLvoid
*pixels
)
3702 GET_CURRENT_CONTEXT(ctx
);
3703 texturesubimage_no_error(ctx
, 3, texture
, level
, xoffset
, yoffset
, zoffset
,
3704 width
, height
, depth
, format
, type
, pixels
,
3705 "glTextureSubImage3D");
3710 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3711 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3712 GLsizei width
, GLsizei height
, GLsizei depth
,
3713 GLenum format
, GLenum type
,
3714 const GLvoid
*pixels
)
3716 GET_CURRENT_CONTEXT(ctx
);
3717 texturesubimage_error(ctx
, 3, texture
, level
, xoffset
, yoffset
, zoffset
,
3718 width
, height
, depth
, format
, type
, pixels
,
3719 "glTextureSubImage3D");
3724 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3725 * from. This depends on whether the texture contains color or depth values.
3727 static struct gl_renderbuffer
*
3728 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3730 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3731 /* reading from depth/stencil buffer */
3732 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3733 } else if (_mesa_get_format_bits(texFormat
, GL_STENCIL_BITS
) > 0) {
3734 return ctx
->ReadBuffer
->Attachment
[BUFFER_STENCIL
].Renderbuffer
;
3736 /* copying from color buffer */
3737 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3743 copytexsubimage_by_slice(struct gl_context
*ctx
,
3744 struct gl_texture_image
*texImage
,
3746 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3747 struct gl_renderbuffer
*rb
,
3749 GLsizei width
, GLsizei height
)
3751 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3754 /* For 1D arrays, we copy each scanline of the source rectangle into the
3757 assert(zoffset
== 0);
3759 for (slice
= 0; slice
< height
; slice
++) {
3760 assert(yoffset
+ slice
< texImage
->Height
);
3761 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3762 xoffset
, 0, yoffset
+ slice
,
3763 rb
, x
, y
+ slice
, width
, 1);
3766 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3767 xoffset
, yoffset
, zoffset
,
3768 rb
, x
, y
, width
, height
);
3774 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3776 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3777 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3778 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3779 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3781 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3782 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3783 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3784 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3786 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3787 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3788 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3789 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3797 * Check if the given texture format and size arguments match those
3798 * of the texture image.
3799 * \param return true if arguments match, false otherwise.
3802 can_avoid_reallocation(const struct gl_texture_image
*texImage
,
3803 GLenum internalFormat
,
3804 mesa_format texFormat
, GLsizei width
,
3805 GLsizei height
, GLint border
)
3807 if (texImage
->InternalFormat
!= internalFormat
)
3809 if (texImage
->TexFormat
!= texFormat
)
3811 if (texImage
->Border
!= border
)
3813 if (texImage
->Width2
!= width
)
3815 if (texImage
->Height2
!= height
)
3822 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
3825 copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3826 struct gl_texture_object
*texObj
,
3827 GLenum target
, GLint level
,
3828 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3829 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3831 struct gl_texture_image
*texImage
;
3833 _mesa_lock_texture(ctx
, texObj
);
3835 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3837 /* If we have a border, offset=-1 is legal. Bias by border width. */
3840 if (target
!= GL_TEXTURE_2D_ARRAY
)
3841 zoffset
+= texImage
->Border
;
3844 if (target
!= GL_TEXTURE_1D_ARRAY
)
3845 yoffset
+= texImage
->Border
;
3848 xoffset
+= texImage
->Border
;
3851 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3853 struct gl_renderbuffer
*srcRb
=
3854 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3856 copytexsubimage_by_slice(ctx
, texImage
, dims
, xoffset
, yoffset
, zoffset
,
3857 srcRb
, x
, y
, width
, height
);
3859 check_gen_mipmap(ctx
, target
, texObj
, level
);
3861 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
3862 * the texel data, not the texture format, size, etc.
3866 _mesa_unlock_texture(ctx
, texObj
);
3871 copy_texture_sub_image_err(struct gl_context
*ctx
, GLuint dims
,
3872 struct gl_texture_object
*texObj
,
3873 GLenum target
, GLint level
,
3874 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3875 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3878 FLUSH_VERTICES(ctx
, 0);
3880 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3881 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
3882 _mesa_enum_to_string(target
),
3883 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3885 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3886 _mesa_update_state(ctx
);
3888 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3889 xoffset
, yoffset
, zoffset
,
3890 width
, height
, caller
)) {
3894 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
3895 zoffset
, x
, y
, width
, height
);
3900 copy_texture_sub_image_no_error(struct gl_context
*ctx
, GLuint dims
,
3901 struct gl_texture_object
*texObj
,
3902 GLenum target
, GLint level
,
3903 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3904 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3906 FLUSH_VERTICES(ctx
, 0);
3908 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3909 _mesa_update_state(ctx
);
3911 copy_texture_sub_image(ctx
, dims
, texObj
, target
, level
, xoffset
, yoffset
,
3912 zoffset
, x
, y
, width
, height
);
3917 * Implement the glCopyTexImage1/2D() functions.
3919 static ALWAYS_INLINE
void
3920 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3921 GLenum target
, GLint level
, GLenum internalFormat
,
3922 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
,
3925 struct gl_texture_image
*texImage
;
3926 struct gl_texture_object
*texObj
;
3927 mesa_format texFormat
;
3929 FLUSH_VERTICES(ctx
, 0);
3931 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3932 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3934 _mesa_enum_to_string(target
), level
,
3935 _mesa_enum_to_string(internalFormat
),
3936 x
, y
, width
, height
, border
);
3938 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3939 _mesa_update_state(ctx
);
3942 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3946 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3948 _mesa_error(ctx
, GL_INVALID_VALUE
,
3949 "glCopyTexImage%uD(invalid width=%d or height=%d)",
3950 dims
, width
, height
);
3955 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3958 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3959 internalFormat
, GL_NONE
, GL_NONE
);
3961 /* First check if reallocating the texture buffer can be avoided.
3962 * Without the realloc the copy can be 20x faster.
3964 _mesa_lock_texture(ctx
, texObj
);
3966 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3967 if (texImage
&& can_avoid_reallocation(texImage
, internalFormat
, texFormat
,
3968 width
, height
, border
)) {
3969 _mesa_unlock_texture(ctx
, texObj
);
3971 copy_texture_sub_image_no_error(ctx
, dims
, texObj
, target
, level
, 0,
3972 0, 0, x
, y
, width
, height
);
3974 copy_texture_sub_image_err(ctx
, dims
, texObj
, target
, level
, 0, 0,
3975 0, x
, y
, width
, height
,"CopyTexImage");
3980 _mesa_unlock_texture(ctx
, texObj
);
3981 _mesa_perf_debug(ctx
, MESA_DEBUG_SEVERITY_LOW
, "glCopyTexImage "
3982 "can't avoid reallocating texture storage\n");
3984 if (!no_error
&& _mesa_is_gles3(ctx
)) {
3985 struct gl_renderbuffer
*rb
=
3986 _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3988 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3989 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3990 * OpenGL ES 3.0. Khronos bug# 9807.
3992 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3993 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3994 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
3995 " and writing to unsized internal format)", dims
);
3999 /* From Page 139 of OpenGL ES 3.0 spec:
4000 * "If internalformat is sized, the internal format of the new texel
4001 * array is internalformat, and this is also the new texel array’s
4002 * effective internal format. If the component sizes of internalformat
4003 * do not exactly match the corresponding component sizes of the source
4004 * buffer’s effective internal format, described below, an
4005 * INVALID_OPERATION error is generated. If internalformat is unsized,
4006 * the internal format of the new texel array is the effective internal
4007 * format of the source buffer, and this is also the new texel array’s
4008 * effective internal format.
4010 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
4011 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4012 "glCopyTexImage%uD(component size changed in"
4013 " internal format)", dims
);
4018 assert(texFormat
!= MESA_FORMAT_NONE
);
4020 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
4021 0, level
, texFormat
, 1,
4022 width
, height
, 1)) {
4023 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4024 "glCopyTexImage%uD(image too large)", dims
);
4028 if (border
&& ctx
->Const
.StripTextureBorder
) {
4030 width
-= border
* 2;
4033 height
-= border
* 2;
4038 _mesa_lock_texture(ctx
, texObj
);
4040 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
4043 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
4046 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
4047 const GLuint face
= _mesa_tex_target_to_face(target
);
4049 /* Free old texture image */
4050 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4052 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
4053 border
, internalFormat
, texFormat
);
4055 if (width
&& height
) {
4056 /* Allocate texture memory (no pixel data yet) */
4057 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
4059 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
4061 struct gl_renderbuffer
*srcRb
=
4062 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4064 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4066 srcRb
, srcX
, srcY
, width
, height
);
4069 check_gen_mipmap(ctx
, target
, texObj
, level
);
4072 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4074 _mesa_dirty_texobj(ctx
, texObj
);
4077 _mesa_unlock_texture(ctx
, texObj
);
4082 copyteximage_err(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
4083 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4084 GLsizei width
, GLsizei height
, GLint border
)
4086 copyteximage(ctx
, dims
, target
, level
, internalFormat
, x
, y
, width
, height
,
4092 copyteximage_no_error(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
4093 GLint level
, GLenum internalFormat
, GLint x
, GLint y
,
4094 GLsizei width
, GLsizei height
, GLint border
)
4096 copyteximage(ctx
, dims
, target
, level
, internalFormat
, x
, y
, width
, height
,
4102 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4103 GLenum internalFormat
,
4105 GLsizei width
, GLint border
)
4107 GET_CURRENT_CONTEXT(ctx
);
4108 copyteximage_err(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4114 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4115 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4118 GET_CURRENT_CONTEXT(ctx
);
4119 copyteximage_err(ctx
, 2, target
, level
, internalFormat
,
4120 x
, y
, width
, height
, border
);
4125 _mesa_CopyTexImage1D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4126 GLint x
, GLint y
, GLsizei width
, GLint border
)
4128 GET_CURRENT_CONTEXT(ctx
);
4129 copyteximage_no_error(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1,
4135 _mesa_CopyTexImage2D_no_error(GLenum target
, GLint level
, GLenum internalFormat
,
4136 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4139 GET_CURRENT_CONTEXT(ctx
);
4140 copyteximage_no_error(ctx
, 2, target
, level
, internalFormat
,
4141 x
, y
, width
, height
, border
);
4146 _mesa_CopyTexSubImage1D(GLenum target
, GLint level
,
4147 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4149 struct gl_texture_object
* texObj
;
4150 const char *self
= "glCopyTexSubImage1D";
4151 GET_CURRENT_CONTEXT(ctx
);
4153 /* Check target (proxies not allowed). Target must be checked prior to
4154 * calling _mesa_get_current_tex_object.
4156 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4157 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4158 _mesa_enum_to_string(target
));
4162 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4166 copy_texture_sub_image_err(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4167 x
, y
, width
, 1, self
);
4172 _mesa_CopyTexSubImage2D(GLenum target
, GLint level
,
4173 GLint xoffset
, GLint yoffset
,
4174 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4176 struct gl_texture_object
* texObj
;
4177 const char *self
= "glCopyTexSubImage2D";
4178 GET_CURRENT_CONTEXT(ctx
);
4180 /* Check target (proxies not allowed). Target must be checked prior to
4181 * calling _mesa_get_current_tex_object.
4183 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4184 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4185 _mesa_enum_to_string(target
));
4189 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4193 copy_texture_sub_image_err(ctx
, 2, texObj
, target
, level
, xoffset
, yoffset
,
4194 0, x
, y
, width
, height
, self
);
4199 _mesa_CopyTexSubImage3D(GLenum target
, GLint level
,
4200 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4201 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4203 struct gl_texture_object
* texObj
;
4204 const char *self
= "glCopyTexSubImage3D";
4205 GET_CURRENT_CONTEXT(ctx
);
4207 /* Check target (proxies not allowed). Target must be checked prior to
4208 * calling _mesa_get_current_tex_object.
4210 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4211 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4212 _mesa_enum_to_string(target
));
4216 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4220 copy_texture_sub_image_err(ctx
, 3, texObj
, target
, level
, xoffset
, yoffset
,
4221 zoffset
, x
, y
, width
, height
, self
);
4226 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4227 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4229 struct gl_texture_object
* texObj
;
4230 const char *self
= "glCopyTextureSubImage1D";
4231 GET_CURRENT_CONTEXT(ctx
);
4233 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4237 /* Check target (proxies not allowed). */
4238 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4239 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4240 _mesa_enum_to_string(texObj
->Target
));
4244 copy_texture_sub_image_err(ctx
, 1, texObj
, texObj
->Target
, level
, xoffset
, 0,
4245 0, x
, y
, width
, 1, self
);
4250 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4251 GLint xoffset
, GLint yoffset
,
4252 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4254 struct gl_texture_object
* texObj
;
4255 const char *self
= "glCopyTextureSubImage2D";
4256 GET_CURRENT_CONTEXT(ctx
);
4258 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4262 /* Check target (proxies not allowed). */
4263 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4264 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4265 _mesa_enum_to_string(texObj
->Target
));
4269 copy_texture_sub_image_err(ctx
, 2, texObj
, texObj
->Target
, level
, xoffset
,
4270 yoffset
, 0, x
, y
, width
, height
, self
);
4275 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4276 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4277 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4279 struct gl_texture_object
* texObj
;
4280 const char *self
= "glCopyTextureSubImage3D";
4281 GET_CURRENT_CONTEXT(ctx
);
4283 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4287 /* Check target (proxies not allowed). */
4288 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4289 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", self
,
4290 _mesa_enum_to_string(texObj
->Target
));
4294 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4295 /* Act like CopyTexSubImage2D */
4296 copy_texture_sub_image_err(ctx
, 2, texObj
,
4297 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4298 level
, xoffset
, yoffset
, 0, x
, y
, width
, height
,
4302 copy_texture_sub_image_err(ctx
, 3, texObj
, texObj
->Target
, level
, xoffset
,
4303 yoffset
, zoffset
, x
, y
, width
, height
, self
);
4308 _mesa_CopyTexSubImage1D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4309 GLint x
, GLint y
, GLsizei width
)
4311 GET_CURRENT_CONTEXT(ctx
);
4313 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4314 copy_texture_sub_image_no_error(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4320 _mesa_CopyTexSubImage2D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4321 GLint yoffset
, GLint x
, GLint y
, GLsizei width
,
4324 GET_CURRENT_CONTEXT(ctx
);
4326 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4327 copy_texture_sub_image_no_error(ctx
, 2, texObj
, target
, level
, xoffset
,
4328 yoffset
, 0, x
, y
, width
, height
);
4333 _mesa_CopyTexSubImage3D_no_error(GLenum target
, GLint level
, GLint xoffset
,
4334 GLint yoffset
, GLint zoffset
, GLint x
, GLint y
,
4335 GLsizei width
, GLsizei height
)
4337 GET_CURRENT_CONTEXT(ctx
);
4339 struct gl_texture_object
* texObj
= _mesa_get_current_tex_object(ctx
, target
);
4340 copy_texture_sub_image_no_error(ctx
, 3, texObj
, target
, level
, xoffset
,
4341 yoffset
, zoffset
, x
, y
, width
, height
);
4346 _mesa_CopyTextureSubImage1D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4347 GLint x
, GLint y
, GLsizei width
)
4349 GET_CURRENT_CONTEXT(ctx
);
4351 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4352 copy_texture_sub_image_no_error(ctx
, 1, texObj
, texObj
->Target
, level
,
4353 xoffset
, 0, 0, x
, y
, width
, 1);
4358 _mesa_CopyTextureSubImage2D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4359 GLint yoffset
, GLint x
, GLint y
,
4360 GLsizei width
, GLsizei height
)
4362 GET_CURRENT_CONTEXT(ctx
);
4364 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4365 copy_texture_sub_image_no_error(ctx
, 2, texObj
, texObj
->Target
, level
,
4366 xoffset
, yoffset
, 0, x
, y
, width
, height
);
4371 _mesa_CopyTextureSubImage3D_no_error(GLuint texture
, GLint level
, GLint xoffset
,
4372 GLint yoffset
, GLint zoffset
, GLint x
,
4373 GLint y
, GLsizei width
, GLsizei height
)
4375 GET_CURRENT_CONTEXT(ctx
);
4377 struct gl_texture_object
* texObj
= _mesa_lookup_texture(ctx
, texture
);
4378 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4379 /* Act like CopyTexSubImage2D */
4380 copy_texture_sub_image_no_error(ctx
, 2, texObj
,
4381 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4382 level
, xoffset
, yoffset
, 0, x
, y
, width
,
4386 copy_texture_sub_image_no_error(ctx
, 3, texObj
, texObj
->Target
, level
,
4387 xoffset
, yoffset
, zoffset
, x
, y
, width
,
4393 check_clear_tex_image(struct gl_context
*ctx
,
4394 const char *function
,
4395 struct gl_texture_image
*texImage
,
4396 GLenum format
, GLenum type
,
4398 GLubyte
*clearValue
)
4400 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4401 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4402 GLenum internalFormat
= texImage
->InternalFormat
;
4405 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4406 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4407 "%s(buffer texture)", function
);
4411 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4412 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4413 "%s(compressed texture)", function
);
4417 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4418 if (err
!= GL_NO_ERROR
) {
4419 _mesa_error(ctx
, err
,
4420 "%s(incompatible format = %s, type = %s)",
4422 _mesa_enum_to_string(format
),
4423 _mesa_enum_to_string(type
));
4427 /* make sure internal format and format basically agree */
4428 if (!texture_formats_agree(internalFormat
, format
)) {
4429 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4430 "%s(incompatible internalFormat = %s, format = %s)",
4432 _mesa_enum_to_string(internalFormat
),
4433 _mesa_enum_to_string(format
));
4437 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4438 /* both source and dest must be integer-valued, or neither */
4439 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4440 _mesa_is_enum_format_integer(format
)) {
4441 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4442 "%s(integer/non-integer format mismatch)",
4448 if (!_mesa_texstore(ctx
,
4450 texImage
->_BaseFormat
,
4451 texImage
->TexFormat
,
4452 0, /* dstRowStride */
4454 1, 1, 1, /* srcWidth/Height/Depth */
4456 data
? data
: zeroData
,
4457 &ctx
->DefaultPacking
)) {
4458 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4466 static struct gl_texture_object
*
4467 get_tex_obj_for_clear(struct gl_context
*ctx
,
4468 const char *function
,
4471 struct gl_texture_object
*texObj
;
4473 texObj
= _mesa_lookup_texture_err(ctx
, texture
, function
);
4477 if (texObj
->Target
== 0) {
4478 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4487 * For clearing cube textures, the zoffset and depth parameters indicate
4488 * which cube map faces are to be cleared. This is the one case where we
4489 * need to be concerned with multiple gl_texture_images. This function
4490 * returns the array of texture images to clear for cube maps, or one
4491 * texture image otherwise.
4492 * \return number of texture images, 0 for error, 6 for cube, 1 otherwise.
4495 get_tex_images_for_clear(struct gl_context
*ctx
,
4496 const char *function
,
4497 struct gl_texture_object
*texObj
,
4499 struct gl_texture_image
**texImages
)
4504 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4505 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4509 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4510 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
4511 numFaces
= MAX_FACES
;
4514 target
= texObj
->Target
;
4518 for (i
= 0; i
< numFaces
; i
++) {
4519 texImages
[i
] = _mesa_select_tex_image(texObj
, target
+ i
, level
);
4520 if (texImages
[i
] == NULL
) {
4521 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4531 _mesa_ClearTexSubImage(GLuint texture
, GLint level
,
4532 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4533 GLsizei width
, GLsizei height
, GLsizei depth
,
4534 GLenum format
, GLenum type
, const void *data
)
4536 GET_CURRENT_CONTEXT(ctx
);
4537 struct gl_texture_object
*texObj
;
4538 struct gl_texture_image
*texImages
[MAX_FACES
];
4539 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4541 int minDepth
, maxDepth
;
4543 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4548 _mesa_lock_texture(ctx
, texObj
);
4550 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4551 texObj
, level
, texImages
);
4555 if (numImages
== 1) {
4556 minDepth
= -(int) texImages
[0]->Border
;
4557 maxDepth
= texImages
[0]->Depth
;
4559 assert(numImages
== MAX_FACES
);
4561 maxDepth
= numImages
;
4564 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4565 yoffset
< -(GLint
) texImages
[0]->Border
||
4566 zoffset
< minDepth
||
4570 xoffset
+ width
> texImages
[0]->Width
||
4571 yoffset
+ height
> texImages
[0]->Height
||
4572 zoffset
+ depth
> maxDepth
) {
4573 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4574 "glClearSubTexImage(invalid dimensions)");
4578 if (numImages
== 1) {
4579 if (check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[0],
4580 format
, type
, data
, clearValue
[0])) {
4581 ctx
->Driver
.ClearTexSubImage(ctx
,
4583 xoffset
, yoffset
, zoffset
,
4584 width
, height
, depth
,
4585 data
? clearValue
[0] : NULL
);
4588 /* loop over cube face images */
4589 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4590 assert(i
< MAX_FACES
);
4591 if (!check_clear_tex_image(ctx
, "glClearTexSubImage", texImages
[i
],
4592 format
, type
, data
, clearValue
[i
]))
4595 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4596 ctx
->Driver
.ClearTexSubImage(ctx
,
4598 xoffset
, yoffset
, 0,
4600 data
? clearValue
[i
] : NULL
);
4605 _mesa_unlock_texture(ctx
, texObj
);
4610 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4611 GLenum format
, GLenum type
, const void *data
)
4613 GET_CURRENT_CONTEXT(ctx
);
4614 struct gl_texture_object
*texObj
;
4615 struct gl_texture_image
*texImages
[MAX_FACES
];
4616 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4619 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4624 _mesa_lock_texture(ctx
, texObj
);
4626 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4627 texObj
, level
, texImages
);
4629 for (i
= 0; i
< numImages
; i
++) {
4630 if (!check_clear_tex_image(ctx
, "glClearTexImage", texImages
[i
], format
,
4631 type
, data
, clearValue
[i
]))
4635 for (i
= 0; i
< numImages
; i
++) {
4636 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4637 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4638 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4639 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4640 texImages
[i
]->Width
,
4641 texImages
[i
]->Height
,
4642 texImages
[i
]->Depth
,
4643 data
? clearValue
[i
] : NULL
);
4647 _mesa_unlock_texture(ctx
, texObj
);
4653 /**********************************************************************/
4654 /****** Compressed Textures ******/
4655 /**********************************************************************/
4659 * Target checking for glCompressedTexSubImage[123]D().
4660 * \return GL_TRUE if error, GL_FALSE if no error
4661 * Must come before other error checking so that the texture object can
4662 * be correctly retrieved using _mesa_get_current_tex_object.
4665 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4666 GLint dims
, GLenum intFormat
, bool dsa
,
4671 enum mesa_format_layout layout
;
4673 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4674 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4675 _mesa_enum_to_string(target
));
4685 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4686 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4687 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4688 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4689 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4690 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4691 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4694 targetOK
= GL_FALSE
;
4700 case GL_TEXTURE_CUBE_MAP
:
4701 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4703 case GL_TEXTURE_2D_ARRAY
:
4704 targetOK
= _mesa_is_gles3(ctx
) ||
4705 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4707 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4708 targetOK
= _mesa_has_texture_cube_map_array(ctx
);
4713 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4715 * "An INVALID_OPERATION error is generated by
4716 * CompressedTex*SubImage3D if the internal format of the texture
4717 * is one of the EAC, ETC2, or RGTC formats and either border is
4718 * non-zero, or the effective target for the texture is not
4719 * TEXTURE_2D_ARRAY."
4721 * NOTE: that's probably a spec error. It should probably say
4722 * "... or the effective target for the texture is not
4723 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4724 * GL_TEXTURE_CUBE_MAP_ARRAY."
4725 * since those targets are 2D images and they support all compression
4728 * Instead of listing all these, just list those which are allowed,
4729 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4730 * more) are valid here, which they are not, but of course not
4731 * mentioned by core spec.
4733 * Also, from GL_KHR_texture_compression_astc_{hdr,ldr}:
4735 * "Add a second new column "3D Tex." which is empty for all non-ASTC
4736 * formats. If only the LDR profile is supported by the implementation,
4737 * this column is also empty for all ASTC formats. If both the LDR and HDR
4738 * profiles are supported, this column is checked for all ASTC formats."
4740 * "An INVALID_OPERATION error is generated by CompressedTexSubImage3D if
4741 * <format> is one of the formats in table 8.19 and <target> is not
4742 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, or TEXTURE_3D.
4744 * An INVALID_OPERATION error is generated by CompressedTexSubImage3D if
4745 * <format> is TEXTURE_CUBE_MAP_ARRAY and the "Cube Map Array" column of
4746 * table 8.19 is *not* checked, or if <format> is TEXTURE_3D and the "3D
4747 * Tex." column of table 8.19 is *not* checked"
4749 * And from GL_KHR_texture_compression_astc_sliced_3d:
4751 * "Modify the "3D Tex." column to be checked for all ASTC formats."
4753 format
= _mesa_glenum_to_compressed_format(intFormat
);
4754 layout
= _mesa_get_format_layout(format
);
4756 case MESA_FORMAT_LAYOUT_BPTC
:
4759 case MESA_FORMAT_LAYOUT_ASTC
:
4761 ctx
->Extensions
.KHR_texture_compression_astc_hdr
||
4762 ctx
->Extensions
.KHR_texture_compression_astc_sliced_3d
;
4765 /* invalid format */
4766 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4767 "%s(invalid target %s for format %s)", caller
,
4768 _mesa_enum_to_string(target
),
4769 _mesa_enum_to_string(intFormat
));
4774 targetOK
= GL_FALSE
;
4780 /* no 1D compressed textures at this time */
4781 targetOK
= GL_FALSE
;
4786 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4787 _mesa_enum_to_string(target
));
4795 * Error checking for glCompressedTexSubImage[123]D().
4796 * \return GL_TRUE if error, GL_FALSE if no error
4799 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4800 const struct gl_texture_object
*texObj
,
4801 GLenum target
, GLint level
,
4802 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4803 GLsizei width
, GLsizei height
, GLsizei depth
,
4804 GLenum format
, GLsizei imageSize
,
4805 const GLvoid
*data
, const char *callerName
)
4807 struct gl_texture_image
*texImage
;
4810 /* this will catch any invalid compressed format token */
4811 if (!_mesa_is_compressed_format(ctx
, format
)) {
4812 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(format)", callerName
);
4816 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4817 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
4821 /* validate the bound PBO, if any */
4822 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4823 imageSize
, data
, callerName
)) {
4827 /* Check for invalid pixel storage modes */
4828 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4829 &ctx
->Unpack
, callerName
)) {
4833 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4834 if (expectedSize
!= imageSize
) {
4835 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d)", callerName
, imageSize
);
4839 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4841 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture level %d)",
4846 if ((GLint
) format
!= texImage
->InternalFormat
) {
4847 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s)",
4848 callerName
, _mesa_enum_to_string(format
));
4852 if (compressedteximage_only_format(format
)) {
4853 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(format=%s cannot be updated)",
4854 callerName
, _mesa_enum_to_string(format
));
4858 if (error_check_subtexture_negative_dimensions(ctx
, dims
, width
, height
,
4859 depth
, callerName
)) {
4863 if (error_check_subtexture_dimensions(ctx
, dims
, texImage
, xoffset
, yoffset
,
4864 zoffset
, width
, height
, depth
,
4874 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4875 GLenum internalFormat
, GLsizei width
,
4876 GLint border
, GLsizei imageSize
,
4879 GET_CURRENT_CONTEXT(ctx
);
4880 teximage_err(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4881 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4886 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4887 GLenum internalFormat
, GLsizei width
,
4888 GLsizei height
, GLint border
, GLsizei imageSize
,
4891 GET_CURRENT_CONTEXT(ctx
);
4892 teximage_err(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4893 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4898 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4899 GLenum internalFormat
, GLsizei width
,
4900 GLsizei height
, GLsizei depth
, GLint border
,
4901 GLsizei imageSize
, const GLvoid
*data
)
4903 GET_CURRENT_CONTEXT(ctx
);
4904 teximage_err(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
, height
,
4905 depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4910 _mesa_CompressedTexImage1D_no_error(GLenum target
, GLint level
,
4911 GLenum internalFormat
, GLsizei width
,
4912 GLint border
, GLsizei imageSize
,
4915 GET_CURRENT_CONTEXT(ctx
);
4916 teximage_no_error(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
, width
, 1,
4917 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4922 _mesa_CompressedTexImage2D_no_error(GLenum target
, GLint level
,
4923 GLenum internalFormat
, GLsizei width
,
4924 GLsizei height
, GLint border
,
4925 GLsizei imageSize
, const GLvoid
*data
)
4927 GET_CURRENT_CONTEXT(ctx
);
4928 teximage_no_error(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
, width
,
4929 height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4934 _mesa_CompressedTexImage3D_no_error(GLenum target
, GLint level
,
4935 GLenum internalFormat
, GLsizei width
,
4936 GLsizei height
, GLsizei depth
, GLint border
,
4937 GLsizei imageSize
, const GLvoid
*data
)
4939 GET_CURRENT_CONTEXT(ctx
);
4940 teximage_no_error(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
, width
,
4941 height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4946 * Common helper for glCompressedTexSubImage1/2/3D() and
4947 * glCompressedTextureSubImage1/2/3D().
4950 compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4951 struct gl_texture_object
*texObj
,
4952 struct gl_texture_image
*texImage
,
4953 GLenum target
, GLint level
, GLint xoffset
,
4954 GLint yoffset
, GLint zoffset
, GLsizei width
,
4955 GLsizei height
, GLsizei depth
, GLenum format
,
4956 GLsizei imageSize
, const GLvoid
*data
)
4958 FLUSH_VERTICES(ctx
, 0);
4960 _mesa_lock_texture(ctx
, texObj
);
4962 if (width
> 0 && height
> 0 && depth
> 0) {
4963 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4964 xoffset
, yoffset
, zoffset
,
4965 width
, height
, depth
,
4966 format
, imageSize
, data
);
4968 check_gen_mipmap(ctx
, target
, texObj
, level
);
4970 /* NOTE: Don't signal _NEW_TEXTURE_OBJECT since we've only changed
4971 * the texel data, not the texture format, size, etc.
4975 _mesa_unlock_texture(ctx
, texObj
);
4979 static ALWAYS_INLINE
void
4980 compressed_tex_sub_image(unsigned dim
, GLenum target
, GLuint texture
,
4981 GLint level
, GLint xoffset
, GLint yoffset
,
4982 GLint zoffset
, GLsizei width
, GLsizei height
,
4983 GLsizei depth
, GLenum format
, GLsizei imageSize
,
4984 const GLvoid
*data
, bool dsa
, bool no_error
,
4987 struct gl_texture_object
*texObj
= NULL
;
4988 struct gl_texture_image
*texImage
;
4990 GET_CURRENT_CONTEXT(ctx
);
4994 texObj
= _mesa_lookup_texture(ctx
, texture
);
4996 texObj
= _mesa_lookup_texture_err(ctx
, texture
, caller
);
5001 target
= texObj
->Target
;
5005 compressed_subtexture_target_check(ctx
, target
, dim
, format
, dsa
,
5011 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5012 if (!no_error
&& !texObj
)
5017 compressed_subtexture_error_check(ctx
, dim
, texObj
, target
, level
,
5018 xoffset
, yoffset
, zoffset
, width
,
5019 height
, depth
, format
,
5020 imageSize
, data
, caller
)) {
5024 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
5025 if (dim
== 3 && dsa
&& texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5026 const char *pixels
= data
;
5029 /* Make sure the texture object is a proper cube.
5030 * (See texturesubimage in teximage.c for details on why this check is
5033 if (!no_error
&& !_mesa_cube_level_complete(texObj
, level
)) {
5034 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5035 "glCompressedTextureSubImage3D(cube map incomplete)");
5039 /* Copy in each face. */
5040 for (int i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
5041 texImage
= texObj
->Image
[i
][level
];
5044 compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5045 texObj
->Target
, level
, xoffset
, yoffset
,
5046 0, width
, height
, 1, format
,
5049 /* Compressed images don't have a client format */
5050 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5052 texImage
->Height
, 1);
5054 pixels
+= image_stride
;
5055 imageSize
-= image_stride
;
5058 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5061 compressed_texture_sub_image(ctx
, dim
, texObj
, texImage
, target
, level
,
5062 xoffset
, yoffset
, zoffset
, width
, height
,
5063 depth
, format
, imageSize
, data
);
5068 compressed_tex_sub_image_error(unsigned dim
, GLenum target
, GLuint texture
,
5069 GLint level
, GLint xoffset
, GLint yoffset
,
5070 GLint zoffset
, GLsizei width
, GLsizei height
,
5071 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5072 const GLvoid
*data
, bool dsa
,
5075 compressed_tex_sub_image(dim
, target
, texture
, level
, xoffset
, yoffset
,
5076 zoffset
, width
, height
, depth
, format
, imageSize
,
5077 data
, dsa
, false, caller
);
5081 compressed_tex_sub_image_no_error(unsigned dim
, GLenum target
, GLuint texture
,
5082 GLint level
, GLint xoffset
, GLint yoffset
,
5083 GLint zoffset
, GLsizei width
, GLsizei height
,
5084 GLsizei depth
, GLenum format
, GLsizei imageSize
,
5085 const GLvoid
*data
, bool dsa
,
5088 compressed_tex_sub_image(dim
, target
, texture
, level
, xoffset
, yoffset
,
5089 zoffset
, width
, height
, depth
, format
, imageSize
,
5090 data
, dsa
, true, caller
);
5094 _mesa_CompressedTexSubImage1D_no_error(GLenum target
, GLint level
,
5095 GLint xoffset
, GLsizei width
,
5096 GLenum format
, GLsizei imageSize
,
5099 compressed_tex_sub_image_no_error(1, target
, 0, level
, xoffset
, 0, 0, width
,
5100 1, 1, format
, imageSize
, data
, false,
5101 "glCompressedTexSubImage1D");
5106 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
5107 GLsizei width
, GLenum format
,
5108 GLsizei imageSize
, const GLvoid
*data
)
5110 compressed_tex_sub_image_error(1, target
, 0, level
, xoffset
, 0, 0, width
, 1,
5111 1, format
, imageSize
, data
, false,
5112 "glCompressedTexSubImage1D");
5117 _mesa_CompressedTextureSubImage1D_no_error(GLuint texture
, GLint level
,
5118 GLint xoffset
, GLsizei width
,
5119 GLenum format
, GLsizei imageSize
,
5122 compressed_tex_sub_image_no_error(1, 0, texture
, level
, xoffset
, 0, 0, width
,
5123 1, 1, format
, imageSize
, data
, true,
5124 "glCompressedTextureSubImage1D");
5129 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
5130 GLsizei width
, GLenum format
,
5131 GLsizei imageSize
, const GLvoid
*data
)
5133 compressed_tex_sub_image_error(1, 0, texture
, level
, xoffset
, 0, 0, width
,
5134 1, 1, format
, imageSize
, data
, true,
5135 "glCompressedTextureSubImage1D");
5139 _mesa_CompressedTexSubImage2D_no_error(GLenum target
, GLint level
,
5140 GLint xoffset
, GLint yoffset
,
5141 GLsizei width
, GLsizei height
,
5142 GLenum format
, GLsizei imageSize
,
5145 compressed_tex_sub_image_no_error(2, target
, 0, level
, xoffset
, yoffset
, 0,
5146 width
, height
, 1, format
, imageSize
, data
,
5147 false, "glCompressedTexSubImage2D");
5152 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
5153 GLint yoffset
, GLsizei width
, GLsizei height
,
5154 GLenum format
, GLsizei imageSize
,
5157 compressed_tex_sub_image_error(2, target
, 0, level
, xoffset
, yoffset
, 0,
5158 width
, height
, 1, format
, imageSize
, data
,
5159 false, "glCompressedTexSubImage2D");
5164 _mesa_CompressedTextureSubImage2D_no_error(GLuint texture
, GLint level
,
5165 GLint xoffset
, GLint yoffset
,
5166 GLsizei width
, GLsizei height
,
5167 GLenum format
, GLsizei imageSize
,
5170 compressed_tex_sub_image_no_error(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5171 width
, height
, 1, format
, imageSize
, data
,
5172 true, "glCompressedTextureSubImage2D");
5177 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
5179 GLsizei width
, GLsizei height
,
5180 GLenum format
, GLsizei imageSize
,
5183 compressed_tex_sub_image_error(2, 0, texture
, level
, xoffset
, yoffset
, 0,
5184 width
, height
, 1, format
, imageSize
, data
,
5185 true, "glCompressedTextureSubImage2D");
5189 _mesa_CompressedTexSubImage3D_no_error(GLenum target
, GLint level
,
5190 GLint xoffset
, GLint yoffset
,
5191 GLint zoffset
, GLsizei width
,
5192 GLsizei height
, GLsizei depth
,
5193 GLenum format
, GLsizei imageSize
,
5196 compressed_tex_sub_image_no_error(3, target
, 0, level
, xoffset
, yoffset
,
5197 zoffset
, width
, height
, depth
, format
,
5198 imageSize
, data
, false,
5199 "glCompressedTexSubImage3D");
5203 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
5204 GLint yoffset
, GLint zoffset
, GLsizei width
,
5205 GLsizei height
, GLsizei depth
, GLenum format
,
5206 GLsizei imageSize
, const GLvoid
*data
)
5208 compressed_tex_sub_image_error(3, target
, 0, level
, xoffset
, yoffset
,
5209 zoffset
, width
, height
, depth
, format
,
5210 imageSize
, data
, false,
5211 "glCompressedTexSubImage3D");
5215 _mesa_CompressedTextureSubImage3D_no_error(GLuint texture
, GLint level
,
5216 GLint xoffset
, GLint yoffset
,
5217 GLint zoffset
, GLsizei width
,
5218 GLsizei height
, GLsizei depth
,
5219 GLenum format
, GLsizei imageSize
,
5222 compressed_tex_sub_image_no_error(3, 0, texture
, level
, xoffset
, yoffset
,
5223 zoffset
, width
, height
, depth
, format
,
5224 imageSize
, data
, true,
5225 "glCompressedTextureSubImage3D");
5229 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
5230 GLint yoffset
, GLint zoffset
, GLsizei width
,
5231 GLsizei height
, GLsizei depth
,
5232 GLenum format
, GLsizei imageSize
,
5235 compressed_tex_sub_image_error(3, 0, texture
, level
, xoffset
, yoffset
,
5236 zoffset
, width
, height
, depth
, format
,
5237 imageSize
, data
, true,
5238 "glCompressedTextureSubImage3D");
5242 _mesa_get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5244 if (ctx
->API
== API_OPENGL_COMPAT
) {
5245 switch (internalFormat
) {
5247 return MESA_FORMAT_A_UNORM8
;
5249 return MESA_FORMAT_A_UNORM16
;
5250 case GL_ALPHA16F_ARB
:
5251 return MESA_FORMAT_A_FLOAT16
;
5252 case GL_ALPHA32F_ARB
:
5253 return MESA_FORMAT_A_FLOAT32
;
5254 case GL_ALPHA8I_EXT
:
5255 return MESA_FORMAT_A_SINT8
;
5256 case GL_ALPHA16I_EXT
:
5257 return MESA_FORMAT_A_SINT16
;
5258 case GL_ALPHA32I_EXT
:
5259 return MESA_FORMAT_A_SINT32
;
5260 case GL_ALPHA8UI_EXT
:
5261 return MESA_FORMAT_A_UINT8
;
5262 case GL_ALPHA16UI_EXT
:
5263 return MESA_FORMAT_A_UINT16
;
5264 case GL_ALPHA32UI_EXT
:
5265 return MESA_FORMAT_A_UINT32
;
5267 return MESA_FORMAT_L_UNORM8
;
5268 case GL_LUMINANCE16
:
5269 return MESA_FORMAT_L_UNORM16
;
5270 case GL_LUMINANCE16F_ARB
:
5271 return MESA_FORMAT_L_FLOAT16
;
5272 case GL_LUMINANCE32F_ARB
:
5273 return MESA_FORMAT_L_FLOAT32
;
5274 case GL_LUMINANCE8I_EXT
:
5275 return MESA_FORMAT_L_SINT8
;
5276 case GL_LUMINANCE16I_EXT
:
5277 return MESA_FORMAT_L_SINT16
;
5278 case GL_LUMINANCE32I_EXT
:
5279 return MESA_FORMAT_L_SINT32
;
5280 case GL_LUMINANCE8UI_EXT
:
5281 return MESA_FORMAT_L_UINT8
;
5282 case GL_LUMINANCE16UI_EXT
:
5283 return MESA_FORMAT_L_UINT16
;
5284 case GL_LUMINANCE32UI_EXT
:
5285 return MESA_FORMAT_L_UINT32
;
5286 case GL_LUMINANCE8_ALPHA8
:
5287 return MESA_FORMAT_L8A8_UNORM
;
5288 case GL_LUMINANCE16_ALPHA16
:
5289 return MESA_FORMAT_L16A16_UNORM
;
5290 case GL_LUMINANCE_ALPHA16F_ARB
:
5291 return MESA_FORMAT_LA_FLOAT16
;
5292 case GL_LUMINANCE_ALPHA32F_ARB
:
5293 return MESA_FORMAT_LA_FLOAT32
;
5294 case GL_LUMINANCE_ALPHA8I_EXT
:
5295 return MESA_FORMAT_LA_SINT8
;
5296 case GL_LUMINANCE_ALPHA16I_EXT
:
5297 return MESA_FORMAT_LA_SINT16
;
5298 case GL_LUMINANCE_ALPHA32I_EXT
:
5299 return MESA_FORMAT_LA_SINT32
;
5300 case GL_LUMINANCE_ALPHA8UI_EXT
:
5301 return MESA_FORMAT_LA_UINT8
;
5302 case GL_LUMINANCE_ALPHA16UI_EXT
:
5303 return MESA_FORMAT_LA_UINT16
;
5304 case GL_LUMINANCE_ALPHA32UI_EXT
:
5305 return MESA_FORMAT_LA_UINT32
;
5307 return MESA_FORMAT_I_UNORM8
;
5308 case GL_INTENSITY16
:
5309 return MESA_FORMAT_I_UNORM16
;
5310 case GL_INTENSITY16F_ARB
:
5311 return MESA_FORMAT_I_FLOAT16
;
5312 case GL_INTENSITY32F_ARB
:
5313 return MESA_FORMAT_I_FLOAT32
;
5314 case GL_INTENSITY8I_EXT
:
5315 return MESA_FORMAT_I_SINT8
;
5316 case GL_INTENSITY16I_EXT
:
5317 return MESA_FORMAT_I_SINT16
;
5318 case GL_INTENSITY32I_EXT
:
5319 return MESA_FORMAT_I_SINT32
;
5320 case GL_INTENSITY8UI_EXT
:
5321 return MESA_FORMAT_I_UINT8
;
5322 case GL_INTENSITY16UI_EXT
:
5323 return MESA_FORMAT_I_UINT16
;
5324 case GL_INTENSITY32UI_EXT
:
5325 return MESA_FORMAT_I_UINT32
;
5331 if (_mesa_has_ARB_texture_buffer_object_rgb32(ctx
) ||
5332 _mesa_has_OES_texture_buffer(ctx
)) {
5333 switch (internalFormat
) {
5335 return MESA_FORMAT_RGB_FLOAT32
;
5337 return MESA_FORMAT_RGB_UINT32
;
5339 return MESA_FORMAT_RGB_SINT32
;
5345 switch (internalFormat
) {
5347 return MESA_FORMAT_R8G8B8A8_UNORM
;
5349 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5350 return MESA_FORMAT_NONE
;
5351 return MESA_FORMAT_RGBA_UNORM16
;
5352 case GL_RGBA16F_ARB
:
5353 return MESA_FORMAT_RGBA_FLOAT16
;
5354 case GL_RGBA32F_ARB
:
5355 return MESA_FORMAT_RGBA_FLOAT32
;
5357 return MESA_FORMAT_RGBA_SINT8
;
5358 case GL_RGBA16I_EXT
:
5359 return MESA_FORMAT_RGBA_SINT16
;
5360 case GL_RGBA32I_EXT
:
5361 return MESA_FORMAT_RGBA_SINT32
;
5362 case GL_RGBA8UI_EXT
:
5363 return MESA_FORMAT_RGBA_UINT8
;
5364 case GL_RGBA16UI_EXT
:
5365 return MESA_FORMAT_RGBA_UINT16
;
5366 case GL_RGBA32UI_EXT
:
5367 return MESA_FORMAT_RGBA_UINT32
;
5370 return MESA_FORMAT_R8G8_UNORM
;
5372 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5373 return MESA_FORMAT_NONE
;
5374 return MESA_FORMAT_R16G16_UNORM
;
5376 return MESA_FORMAT_RG_FLOAT16
;
5378 return MESA_FORMAT_RG_FLOAT32
;
5380 return MESA_FORMAT_RG_SINT8
;
5382 return MESA_FORMAT_RG_SINT16
;
5384 return MESA_FORMAT_RG_SINT32
;
5386 return MESA_FORMAT_RG_UINT8
;
5388 return MESA_FORMAT_RG_UINT16
;
5390 return MESA_FORMAT_RG_UINT32
;
5393 return MESA_FORMAT_R_UNORM8
;
5395 if (_mesa_is_gles(ctx
) && !_mesa_has_EXT_texture_norm16(ctx
))
5396 return MESA_FORMAT_NONE
;
5397 return MESA_FORMAT_R_UNORM16
;
5399 return MESA_FORMAT_R_FLOAT16
;
5401 return MESA_FORMAT_R_FLOAT32
;
5403 return MESA_FORMAT_R_SINT8
;
5405 return MESA_FORMAT_R_SINT16
;
5407 return MESA_FORMAT_R_SINT32
;
5409 return MESA_FORMAT_R_UINT8
;
5411 return MESA_FORMAT_R_UINT16
;
5413 return MESA_FORMAT_R_UINT32
;
5416 return MESA_FORMAT_NONE
;
5422 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5423 GLenum internalFormat
)
5425 mesa_format format
= _mesa_get_texbuffer_format(ctx
, internalFormat
);
5428 if (format
== MESA_FORMAT_NONE
)
5429 return MESA_FORMAT_NONE
;
5431 datatype
= _mesa_get_format_datatype(format
);
5433 /* The GL_ARB_texture_buffer_object spec says:
5435 * "If ARB_texture_float is not supported, references to the
5436 * floating-point internal formats provided by that extension should be
5437 * removed, and such formats may not be passed to TexBufferARB."
5439 * As a result, GL_HALF_FLOAT internal format depends on both
5440 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5442 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5443 !ctx
->Extensions
.ARB_texture_float
)
5444 return MESA_FORMAT_NONE
;
5446 if (!ctx
->Extensions
.ARB_texture_rg
) {
5447 GLenum base_format
= _mesa_get_format_base_format(format
);
5448 if (base_format
== GL_R
|| base_format
== GL_RG
)
5449 return MESA_FORMAT_NONE
;
5452 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5453 GLenum base_format
= _mesa_get_format_base_format(format
);
5454 if (base_format
== GL_RGB
)
5455 return MESA_FORMAT_NONE
;
5462 * Do work common to glTexBuffer, glTexBufferRange, glTextureBuffer
5463 * and glTextureBufferRange, including some error checking.
5466 texture_buffer_range(struct gl_context
*ctx
,
5467 struct gl_texture_object
*texObj
,
5468 GLenum internalFormat
,
5469 struct gl_buffer_object
*bufObj
,
5470 GLintptr offset
, GLsizeiptr size
,
5473 GLintptr oldOffset
= texObj
->BufferOffset
;
5474 GLsizeiptr oldSize
= texObj
->BufferSize
;
5477 /* NOTE: ARB_texture_buffer_object might not be supported in
5478 * the compatibility profile.
5480 if (!_mesa_has_ARB_texture_buffer_object(ctx
) &&
5481 !_mesa_has_OES_texture_buffer(ctx
)) {
5482 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5483 "%s(ARB_texture_buffer_object is not"
5484 " implemented for the compatibility profile)", caller
);
5488 if (texObj
->HandleAllocated
) {
5489 /* The ARB_bindless_texture spec says:
5491 * "The error INVALID_OPERATION is generated by TexImage*, CopyTexImage*,
5492 * CompressedTexImage*, TexBuffer*, TexParameter*, as well as other
5493 * functions defined in terms of these, if the texture object to be
5494 * modified is referenced by one or more texture or image handles."
5496 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable texture)", caller
);
5500 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5501 if (format
== MESA_FORMAT_NONE
) {
5502 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalFormat %s)",
5503 caller
, _mesa_enum_to_string(internalFormat
));
5507 FLUSH_VERTICES(ctx
, 0);
5509 _mesa_lock_texture(ctx
, texObj
);
5511 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5512 texObj
->BufferObjectFormat
= internalFormat
;
5513 texObj
->_BufferObjectFormat
= format
;
5514 texObj
->BufferOffset
= offset
;
5515 texObj
->BufferSize
= size
;
5517 _mesa_unlock_texture(ctx
, texObj
);
5519 if (ctx
->Driver
.TexParameter
) {
5520 if (offset
!= oldOffset
) {
5521 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_OFFSET
);
5523 if (size
!= oldSize
) {
5524 ctx
->Driver
.TexParameter(ctx
, texObj
, GL_TEXTURE_BUFFER_SIZE
);
5528 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5531 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5537 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5538 * Return true if it is, and return false if it is not
5539 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5540 * core spec, 02.02.2015, PDF page 245).
5543 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5546 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5547 _mesa_error(ctx
, GL_INVALID_ENUM
,
5548 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5556 * Check for errors related to the texture buffer range.
5557 * Return false if errors are found, true if none are found.
5560 check_texture_buffer_range(struct gl_context
*ctx
,
5561 struct gl_buffer_object
*bufObj
,
5562 GLintptr offset
, GLsizeiptr size
,
5565 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5566 * Textures (PDF page 245):
5567 * "An INVALID_VALUE error is generated if offset is negative, if
5568 * size is less than or equal to zero, or if offset + size is greater
5569 * than the value of BUFFER_SIZE for the buffer bound to target."
5572 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5578 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5583 if (offset
+ size
> bufObj
->Size
) {
5584 _mesa_error(ctx
, GL_INVALID_VALUE
,
5585 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5586 (int) offset
, (int) size
, (int) bufObj
->Size
);
5590 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5591 * Textures (PDF page 245):
5592 * "An INVALID_VALUE error is generated if offset is not an integer
5593 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5595 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5596 _mesa_error(ctx
, GL_INVALID_VALUE
,
5597 "%s(invalid offset alignment)", caller
);
5605 /** GL_ARB_texture_buffer_object */
5607 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5609 struct gl_texture_object
*texObj
;
5610 struct gl_buffer_object
*bufObj
;
5612 GET_CURRENT_CONTEXT(ctx
);
5614 /* Need to catch a bad target before it gets to
5615 * _mesa_get_current_tex_object.
5617 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5621 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5627 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5631 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5632 buffer
? -1 : 0, "glTexBuffer");
5636 /** GL_ARB_texture_buffer_range */
5638 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5639 GLintptr offset
, GLsizeiptr size
)
5641 struct gl_texture_object
*texObj
;
5642 struct gl_buffer_object
*bufObj
;
5644 GET_CURRENT_CONTEXT(ctx
);
5646 /* Need to catch a bad target before it gets to
5647 * _mesa_get_current_tex_object.
5649 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5653 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5657 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5658 "glTexBufferRange"))
5662 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5663 * Textures (PDF page 254):
5664 * "If buffer is zero, then any buffer object attached to the buffer
5665 * texture is detached, the values offset and size are ignored and
5666 * the state for offset and size for the buffer texture are reset to
5674 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5678 texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5679 offset
, size
, "glTexBufferRange");
5683 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5685 struct gl_texture_object
*texObj
;
5686 struct gl_buffer_object
*bufObj
;
5688 GET_CURRENT_CONTEXT(ctx
);
5691 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5697 /* Get the texture object by Name. */
5698 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5702 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5705 texture_buffer_range(ctx
, texObj
, internalFormat
,
5706 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5710 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5711 GLintptr offset
, GLsizeiptr size
)
5713 struct gl_texture_object
*texObj
;
5714 struct gl_buffer_object
*bufObj
;
5716 GET_CURRENT_CONTEXT(ctx
);
5719 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5720 "glTextureBufferRange");
5724 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5725 "glTextureBufferRange"))
5729 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5730 * Textures (PDF page 254):
5731 * "If buffer is zero, then any buffer object attached to the buffer
5732 * texture is detached, the values offset and size are ignored and
5733 * the state for offset and size for the buffer texture are reset to
5741 /* Get the texture object by Name. */
5742 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5746 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5747 "glTextureBufferRange"))
5750 texture_buffer_range(ctx
, texObj
, internalFormat
,
5751 bufObj
, offset
, size
, "glTextureBufferRange");
5755 _mesa_is_renderable_texture_format(const struct gl_context
*ctx
,
5756 GLenum internalformat
)
5758 /* Everything that is allowed for renderbuffers,
5759 * except for a base format of GL_STENCIL_INDEX, unless supported.
5761 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5762 if (ctx
->Extensions
.ARB_texture_stencil8
)
5763 return baseFormat
!= 0;
5765 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5769 /** GL_ARB_texture_multisample */
5771 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5774 case GL_TEXTURE_2D_MULTISAMPLE
:
5776 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5777 return dims
== 2 && !dsa
;
5778 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5780 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5781 return dims
== 3 && !dsa
;
5789 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5790 struct gl_texture_object
*texObj
,
5791 struct gl_memory_object
*memObj
,
5792 GLenum target
, GLsizei samples
,
5793 GLint internalformat
, GLsizei width
,
5794 GLsizei height
, GLsizei depth
,
5795 GLboolean fixedsamplelocations
,
5796 GLboolean immutable
, GLuint64 offset
,
5799 struct gl_texture_image
*texImage
;
5800 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5801 mesa_format texFormat
;
5802 GLenum sample_count_error
;
5803 bool dsa
= strstr(func
, "ture") ? true : false;
5805 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
5806 _mesa_debug(ctx
, "%s(target=%s, samples=%d)\n", func
,
5807 _mesa_enum_to_string(target
), samples
);
5810 if (!((ctx
->Extensions
.ARB_texture_multisample
5811 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5812 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5817 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5821 if (!check_multisample_target(dims
, target
, dsa
)) {
5822 GLenum err
= dsa
? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
5823 _mesa_error(ctx
, err
, "%s(target=%s)", func
,
5824 _mesa_enum_to_string(target
));
5828 /* check that the specified internalformat is color/depth/stencil-renderable;
5829 * refer GL3.1 spec 4.4.4
5832 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5833 _mesa_error(ctx
, GL_INVALID_ENUM
,
5834 "%s(internalformat=%s not legal for immutable-format)",
5835 func
, _mesa_enum_to_string(internalformat
));
5839 if (!_mesa_is_renderable_texture_format(ctx
, internalformat
)) {
5840 /* Page 172 of OpenGL ES 3.1 spec says:
5841 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5842 * color-renderable, depth-renderable, or stencil-renderable (as
5843 * defined in section 9.4).
5845 * (Same error is also defined for desktop OpenGL for multisample
5846 * teximage/texstorage functions.)
5848 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5849 _mesa_enum_to_string(internalformat
));
5853 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5854 internalformat
, samples
, samples
);
5855 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5857 /* Page 254 of OpenGL 4.4 spec says:
5858 * "Proxy arrays for two-dimensional multisample and two-dimensional
5859 * multisample array textures are operated on in the same way when
5860 * TexImage2DMultisample is called with target specified as
5861 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5862 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5863 * However, if samples is not supported, then no error is generated.
5865 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5866 _mesa_error(ctx
, sample_count_error
, "%s(samples=%d)", func
, samples
);
5870 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5871 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5872 "%s(texture object 0)",
5877 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5879 if (texImage
== NULL
) {
5880 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5884 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5885 internalformat
, GL_NONE
, GL_NONE
);
5886 assert(texFormat
!= MESA_FORMAT_NONE
);
5888 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5889 width
, height
, depth
, 0);
5891 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, 0, texFormat
,
5892 samples
, width
, height
, depth
);
5894 if (_mesa_is_proxy_texture(target
)) {
5895 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5896 _mesa_init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5897 internalformat
, texFormat
,
5898 samples
, fixedsamplelocations
);
5901 /* clear all image fields */
5902 clear_teximage_fields(texImage
);
5906 if (!dimensionsOK
) {
5907 _mesa_error(ctx
, GL_INVALID_VALUE
,
5908 "%s(invalid width=%d or height=%d)", func
, width
, height
);
5913 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5917 /* Check if texObj->Immutable is set */
5918 if (texObj
->Immutable
) {
5919 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5923 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5925 _mesa_init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5926 internalformat
, texFormat
,
5927 samples
, fixedsamplelocations
);
5929 if (width
> 0 && height
> 0 && depth
> 0) {
5931 if (!ctx
->Driver
.SetTextureStorageForMemoryObject(ctx
, texObj
,
5936 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
5937 internalformat
, texFormat
);
5940 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5941 width
, height
, depth
)) {
5942 /* tidy up the texture image state. strictly speaking,
5943 * we're allowed to just leave this in whatever state we
5944 * like, but being tidy is good.
5946 _mesa_init_teximage_fields(ctx
, texImage
, 0, 0, 0, 0,
5947 internalformat
, texFormat
);
5952 texObj
->Immutable
|= immutable
;
5955 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5958 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5964 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5965 GLenum internalformat
, GLsizei width
,
5966 GLsizei height
, GLboolean fixedsamplelocations
)
5968 struct gl_texture_object
*texObj
;
5969 GET_CURRENT_CONTEXT(ctx
);
5971 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5975 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
5976 internalformat
, width
, height
, 1,
5977 fixedsamplelocations
, GL_FALSE
, 0,
5978 "glTexImage2DMultisample");
5983 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5984 GLenum internalformat
, GLsizei width
,
5985 GLsizei height
, GLsizei depth
,
5986 GLboolean fixedsamplelocations
)
5988 struct gl_texture_object
*texObj
;
5989 GET_CURRENT_CONTEXT(ctx
);
5991 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5995 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
5996 internalformat
, width
, height
, depth
,
5997 fixedsamplelocations
, GL_FALSE
, 0,
5998 "glTexImage3DMultisample");
6002 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
6005 GET_CURRENT_CONTEXT(ctx
);
6007 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
6008 _mesa_error(ctx
, GL_INVALID_VALUE
,
6009 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
6010 dims
, width
, height
, depth
);
6017 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
6018 GLenum internalformat
, GLsizei width
,
6019 GLsizei height
, GLboolean fixedsamplelocations
)
6021 struct gl_texture_object
*texObj
;
6022 GET_CURRENT_CONTEXT(ctx
);
6024 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6028 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
6031 texture_image_multisample(ctx
, 2, texObj
, NULL
, target
, samples
,
6032 internalformat
, width
, height
, 1,
6033 fixedsamplelocations
, GL_TRUE
, 0,
6034 "glTexStorage2DMultisample");
6038 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
6039 GLenum internalformat
, GLsizei width
,
6040 GLsizei height
, GLsizei depth
,
6041 GLboolean fixedsamplelocations
)
6043 struct gl_texture_object
*texObj
;
6044 GET_CURRENT_CONTEXT(ctx
);
6046 texObj
= _mesa_get_current_tex_object(ctx
, target
);
6050 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
6053 texture_image_multisample(ctx
, 3, texObj
, NULL
, target
, samples
,
6054 internalformat
, width
, height
, depth
,
6055 fixedsamplelocations
, GL_TRUE
, 0,
6056 "glTexStorage3DMultisample");
6060 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
6061 GLenum internalformat
, GLsizei width
,
6063 GLboolean fixedsamplelocations
)
6065 struct gl_texture_object
*texObj
;
6066 GET_CURRENT_CONTEXT(ctx
);
6068 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6069 "glTextureStorage2DMultisample");
6073 if (!valid_texstorage_ms_parameters(width
, height
, 1, 2))
6076 texture_image_multisample(ctx
, 2, texObj
, NULL
, texObj
->Target
,
6077 samples
, internalformat
, width
, height
, 1,
6078 fixedsamplelocations
, GL_TRUE
, 0,
6079 "glTextureStorage2DMultisample");
6083 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
6084 GLenum internalformat
, GLsizei width
,
6085 GLsizei height
, GLsizei depth
,
6086 GLboolean fixedsamplelocations
)
6088 struct gl_texture_object
*texObj
;
6089 GET_CURRENT_CONTEXT(ctx
);
6091 /* Get the texture object by Name. */
6092 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
6093 "glTextureStorage3DMultisample");
6097 if (!valid_texstorage_ms_parameters(width
, height
, depth
, 3))
6100 texture_image_multisample(ctx
, 3, texObj
, NULL
, texObj
->Target
, samples
,
6101 internalformat
, width
, height
, depth
,
6102 fixedsamplelocations
, GL_TRUE
, 0,
6103 "glTextureStorage3DMultisample");
6107 _mesa_texture_storage_ms_memory(struct gl_context
*ctx
, GLuint dims
,
6108 struct gl_texture_object
*texObj
,
6109 struct gl_memory_object
*memObj
,
6110 GLenum target
, GLsizei samples
,
6111 GLenum internalFormat
, GLsizei width
,
6112 GLsizei height
, GLsizei depth
,
6113 GLboolean fixedSampleLocations
,
6114 GLuint64 offset
, const char* func
)
6118 texture_image_multisample(ctx
, dims
, texObj
, memObj
, target
, samples
,
6119 internalFormat
, width
, height
, depth
,
6120 fixedSampleLocations
, GL_TRUE
, offset
,