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"
43 #include "multisample.h"
44 #include "pixelstore.h"
46 #include "texcompress.h"
47 #include "texcompress_cpal.h"
51 #include "texstorage.h"
52 #include "textureview.h"
54 #include "glformats.h"
60 * State changes which we care about for glCopyTex[Sub]Image() calls.
61 * In particular, we care about pixel transfer state and buffer state
62 * (such as glReadBuffer to make sure we read from the right renderbuffer).
64 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
67 * Returns a corresponding internal floating point format for a given base
68 * format as specifed by OES_texture_float. In case of GL_FLOAT, the internal
69 * format needs to be a 32 bit component and in case of GL_HALF_FLOAT_OES it
70 * needs to be a 16 bit component.
72 * For example, given base format GL_RGBA, type GL_Float return GL_RGBA32F_ARB.
75 adjust_for_oes_float_texture(GLenum format
, GLenum type
)
85 return GL_ALPHA32F_ARB
;
87 return GL_LUMINANCE32F_ARB
;
88 case GL_LUMINANCE_ALPHA
:
89 return GL_LUMINANCE_ALPHA32F_ARB
;
95 case GL_HALF_FLOAT_OES
:
102 return GL_ALPHA16F_ARB
;
104 return GL_LUMINANCE16F_ARB
;
105 case GL_LUMINANCE_ALPHA
:
106 return GL_LUMINANCE_ALPHA16F_ARB
;
120 * Return the simple base format for a given internal texture format.
121 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
123 * \param ctx GL context.
124 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
126 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
127 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
129 * This is the format which is used during texture application (i.e. the
130 * texture format and env mode determine the arithmetic used.
133 _mesa_base_tex_format(const struct gl_context
*ctx
, GLint internalFormat
)
135 switch (internalFormat
) {
141 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
148 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
150 case GL_LUMINANCE_ALPHA
:
151 case GL_LUMINANCE4_ALPHA4
:
152 case GL_LUMINANCE6_ALPHA2
:
153 case GL_LUMINANCE8_ALPHA8
:
154 case GL_LUMINANCE12_ALPHA4
:
155 case GL_LUMINANCE12_ALPHA12
:
156 case GL_LUMINANCE16_ALPHA16
:
157 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
163 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
165 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
176 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
190 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
192 if (_mesa_is_gles(ctx
)) {
193 switch (internalFormat
) {
201 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
202 switch (internalFormat
) {
210 if (ctx
->Extensions
.ARB_depth_texture
) {
211 switch (internalFormat
) {
212 case GL_DEPTH_COMPONENT
:
213 case GL_DEPTH_COMPONENT16
:
214 case GL_DEPTH_COMPONENT24
:
215 case GL_DEPTH_COMPONENT32
:
216 return GL_DEPTH_COMPONENT
;
217 case GL_DEPTH_STENCIL
:
218 case GL_DEPTH24_STENCIL8
:
219 return GL_DEPTH_STENCIL
;
225 if (ctx
->Extensions
.ARB_texture_stencil8
) {
226 switch (internalFormat
) {
227 case GL_STENCIL_INDEX
:
228 case GL_STENCIL_INDEX1
:
229 case GL_STENCIL_INDEX4
:
230 case GL_STENCIL_INDEX8
:
231 case GL_STENCIL_INDEX16
:
232 return GL_STENCIL_INDEX
;
238 switch (internalFormat
) {
239 case GL_COMPRESSED_ALPHA
:
241 case GL_COMPRESSED_LUMINANCE
:
243 case GL_COMPRESSED_LUMINANCE_ALPHA
:
244 return GL_LUMINANCE_ALPHA
;
245 case GL_COMPRESSED_INTENSITY
:
247 case GL_COMPRESSED_RGB
:
249 case GL_COMPRESSED_RGBA
:
255 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
256 GLenum base_compressed
=
257 _mesa_gl_compressed_format_base_format(internalFormat
);
259 return base_compressed
;
262 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
263 if (internalFormat
== GL_YCBCR_MESA
)
264 return GL_YCBCR_MESA
;
267 if (ctx
->Extensions
.ARB_texture_float
) {
268 switch (internalFormat
) {
269 case GL_ALPHA16F_ARB
:
270 case GL_ALPHA32F_ARB
:
278 case GL_INTENSITY16F_ARB
:
279 case GL_INTENSITY32F_ARB
:
281 case GL_LUMINANCE16F_ARB
:
282 case GL_LUMINANCE32F_ARB
:
284 case GL_LUMINANCE_ALPHA16F_ARB
:
285 case GL_LUMINANCE_ALPHA32F_ARB
:
286 return GL_LUMINANCE_ALPHA
;
292 if (ctx
->Extensions
.EXT_texture_snorm
) {
293 switch (internalFormat
) {
308 case GL_RGBA16_SNORM
:
311 case GL_ALPHA8_SNORM
:
312 case GL_ALPHA16_SNORM
:
314 case GL_LUMINANCE_SNORM
:
315 case GL_LUMINANCE8_SNORM
:
316 case GL_LUMINANCE16_SNORM
:
318 case GL_LUMINANCE_ALPHA_SNORM
:
319 case GL_LUMINANCE8_ALPHA8_SNORM
:
320 case GL_LUMINANCE16_ALPHA16_SNORM
:
321 return GL_LUMINANCE_ALPHA
;
322 case GL_INTENSITY_SNORM
:
323 case GL_INTENSITY8_SNORM
:
324 case GL_INTENSITY16_SNORM
:
331 if (ctx
->Extensions
.EXT_texture_sRGB
) {
332 switch (internalFormat
) {
335 case GL_COMPRESSED_SRGB_EXT
:
337 case GL_SRGB_ALPHA_EXT
:
338 case GL_SRGB8_ALPHA8_EXT
:
339 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
341 case GL_SLUMINANCE_ALPHA_EXT
:
342 case GL_SLUMINANCE8_ALPHA8_EXT
:
343 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
344 return GL_LUMINANCE_ALPHA
;
345 case GL_SLUMINANCE_EXT
:
346 case GL_SLUMINANCE8_EXT
:
347 case GL_COMPRESSED_SLUMINANCE_EXT
:
354 if (ctx
->Version
>= 30 ||
355 ctx
->Extensions
.EXT_texture_integer
) {
356 switch (internalFormat
) {
358 case GL_RGBA16UI_EXT
:
359 case GL_RGBA32UI_EXT
:
375 if (ctx
->Extensions
.EXT_texture_integer
) {
376 switch (internalFormat
) {
377 case GL_ALPHA8UI_EXT
:
378 case GL_ALPHA16UI_EXT
:
379 case GL_ALPHA32UI_EXT
:
381 case GL_ALPHA16I_EXT
:
382 case GL_ALPHA32I_EXT
:
384 case GL_INTENSITY8UI_EXT
:
385 case GL_INTENSITY16UI_EXT
:
386 case GL_INTENSITY32UI_EXT
:
387 case GL_INTENSITY8I_EXT
:
388 case GL_INTENSITY16I_EXT
:
389 case GL_INTENSITY32I_EXT
:
391 case GL_LUMINANCE8UI_EXT
:
392 case GL_LUMINANCE16UI_EXT
:
393 case GL_LUMINANCE32UI_EXT
:
394 case GL_LUMINANCE8I_EXT
:
395 case GL_LUMINANCE16I_EXT
:
396 case GL_LUMINANCE32I_EXT
:
398 case GL_LUMINANCE_ALPHA8UI_EXT
:
399 case GL_LUMINANCE_ALPHA16UI_EXT
:
400 case GL_LUMINANCE_ALPHA32UI_EXT
:
401 case GL_LUMINANCE_ALPHA8I_EXT
:
402 case GL_LUMINANCE_ALPHA16I_EXT
:
403 case GL_LUMINANCE_ALPHA32I_EXT
:
404 return GL_LUMINANCE_ALPHA
;
410 if (ctx
->Extensions
.ARB_texture_rg
) {
411 switch (internalFormat
) {
414 if (!ctx
->Extensions
.ARB_texture_float
)
423 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
429 case GL_COMPRESSED_RED
:
434 if (!ctx
->Extensions
.ARB_texture_float
)
443 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
449 case GL_COMPRESSED_RG
:
456 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
457 switch (internalFormat
) {
465 if (ctx
->Extensions
.EXT_packed_float
) {
466 switch (internalFormat
) {
467 case GL_R11F_G11F_B10F_EXT
:
474 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
475 switch (internalFormat
) {
476 case GL_DEPTH_COMPONENT32F
:
477 return GL_DEPTH_COMPONENT
;
478 case GL_DEPTH32F_STENCIL8
:
479 return GL_DEPTH_STENCIL
;
485 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
486 _mesa_is_astc_format(internalFormat
))
489 return -1; /* error */
494 * For cube map faces, return a face index in [0,5].
495 * For other targets return 0;
498 _mesa_tex_target_to_face(GLenum target
)
500 if (_mesa_is_cube_face(target
))
501 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
509 * Install gl_texture_image in a gl_texture_object according to the target
510 * and level parameters.
512 * \param tObj texture object.
513 * \param target texture target.
514 * \param level image level.
515 * \param texImage texture image.
518 set_tex_image(struct gl_texture_object
*tObj
,
519 GLenum target
, GLint level
,
520 struct gl_texture_image
*texImage
)
522 const GLuint face
= _mesa_tex_target_to_face(target
);
526 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
529 tObj
->Image
[face
][level
] = texImage
;
531 /* Set the 'back' pointer */
532 texImage
->TexObject
= tObj
;
533 texImage
->Level
= level
;
534 texImage
->Face
= face
;
539 * Allocate a texture image structure.
541 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
544 * \return a pointer to gl_texture_image struct with all fields initialized to
547 struct gl_texture_image
*
548 _mesa_new_texture_image( struct gl_context
*ctx
)
551 return CALLOC_STRUCT(gl_texture_image
);
556 * Free a gl_texture_image and associated data.
557 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
559 * \param texImage texture image.
561 * Free the texture image structure and the associated image data.
564 _mesa_delete_texture_image(struct gl_context
*ctx
,
565 struct gl_texture_image
*texImage
)
567 /* Free texImage->Data and/or any other driver-specific texture
570 assert(ctx
->Driver
.FreeTextureImageBuffer
);
571 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
577 * Test if a target is a proxy target.
579 * \param target texture target.
581 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
584 _mesa_is_proxy_texture(GLenum target
)
587 static const GLenum targets
[] = {
591 GL_PROXY_TEXTURE_CUBE_MAP
,
592 GL_PROXY_TEXTURE_RECTANGLE
,
593 GL_PROXY_TEXTURE_1D_ARRAY
,
594 GL_PROXY_TEXTURE_2D_ARRAY
,
595 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
596 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
597 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
600 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
601 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
603 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
605 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
606 if (target
== targets
[i
])
613 * Test if a target is an array target.
615 * \param target texture target.
617 * \return true if the target is an array target, false otherwise.
620 _mesa_is_array_texture(GLenum target
)
623 case GL_TEXTURE_1D_ARRAY
:
624 case GL_TEXTURE_2D_ARRAY
:
625 case GL_TEXTURE_CUBE_MAP_ARRAY
:
626 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
635 * Return the proxy target which corresponds to the given texture target
638 proxy_target(GLenum target
)
642 case GL_PROXY_TEXTURE_1D
:
643 return GL_PROXY_TEXTURE_1D
;
645 case GL_PROXY_TEXTURE_2D
:
646 return GL_PROXY_TEXTURE_2D
;
648 case GL_PROXY_TEXTURE_3D
:
649 return GL_PROXY_TEXTURE_3D
;
650 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
651 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
652 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
653 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
654 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
655 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
656 case GL_TEXTURE_CUBE_MAP_ARB
:
657 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
658 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
659 case GL_TEXTURE_RECTANGLE_NV
:
660 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
661 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
662 case GL_TEXTURE_1D_ARRAY_EXT
:
663 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
664 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
665 case GL_TEXTURE_2D_ARRAY_EXT
:
666 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
667 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
668 case GL_TEXTURE_CUBE_MAP_ARRAY
:
669 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
670 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
671 case GL_TEXTURE_2D_MULTISAMPLE
:
672 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
673 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
674 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
675 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
676 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
678 _mesa_problem(NULL
, "unexpected target in proxy_target()");
687 * Get a texture image pointer from a texture object, given a texture
688 * target and mipmap level. The target and level parameters should
689 * have already been error-checked.
691 * \param texObj texture unit.
692 * \param target texture target.
693 * \param level image level.
695 * \return pointer to the texture image structure, or NULL on failure.
697 struct gl_texture_image
*
698 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
699 GLenum target
, GLint level
)
701 const GLuint face
= _mesa_tex_target_to_face(target
);
705 assert(level
< MAX_TEXTURE_LEVELS
);
707 return texObj
->Image
[face
][level
];
712 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
713 * it and install it. Only return NULL if passed a bad parameter or run
716 struct gl_texture_image
*
717 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
718 GLenum target
, GLint level
)
720 struct gl_texture_image
*texImage
;
725 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
727 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
729 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
733 set_tex_image(texObj
, target
, level
, texImage
);
741 * Return pointer to the specified proxy texture image.
742 * Note that proxy textures are per-context, not per-texture unit.
743 * \return pointer to texture image or NULL if invalid target, invalid
744 * level, or out of memory.
746 static struct gl_texture_image
*
747 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
749 struct gl_texture_image
*texImage
;
756 case GL_PROXY_TEXTURE_1D
:
757 if (level
>= ctx
->Const
.MaxTextureLevels
)
759 texIndex
= TEXTURE_1D_INDEX
;
761 case GL_PROXY_TEXTURE_2D
:
762 if (level
>= ctx
->Const
.MaxTextureLevels
)
764 texIndex
= TEXTURE_2D_INDEX
;
766 case GL_PROXY_TEXTURE_3D
:
767 if (level
>= ctx
->Const
.Max3DTextureLevels
)
769 texIndex
= TEXTURE_3D_INDEX
;
771 case GL_PROXY_TEXTURE_CUBE_MAP
:
772 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
774 texIndex
= TEXTURE_CUBE_INDEX
;
776 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
779 texIndex
= TEXTURE_RECT_INDEX
;
781 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
782 if (level
>= ctx
->Const
.MaxTextureLevels
)
784 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
786 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
787 if (level
>= ctx
->Const
.MaxTextureLevels
)
789 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
791 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
792 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
794 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
796 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
799 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
801 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
804 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
810 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
812 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
814 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
817 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
818 /* Set the 'back' pointer */
819 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
826 * Get the maximum number of allowed mipmap levels.
828 * \param ctx GL context.
829 * \param target texture target.
831 * \return the maximum number of allowed mipmap levels for the given
832 * texture target, or zero if passed a bad target.
837 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
841 case GL_PROXY_TEXTURE_1D
:
843 case GL_PROXY_TEXTURE_2D
:
844 return ctx
->Const
.MaxTextureLevels
;
846 case GL_PROXY_TEXTURE_3D
:
847 return ctx
->Const
.Max3DTextureLevels
;
848 case GL_TEXTURE_CUBE_MAP
:
849 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
850 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
851 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
852 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
853 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
854 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
855 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
856 return ctx
->Extensions
.ARB_texture_cube_map
857 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
858 case GL_TEXTURE_RECTANGLE_NV
:
859 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
860 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
861 case GL_TEXTURE_1D_ARRAY_EXT
:
862 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
863 case GL_TEXTURE_2D_ARRAY_EXT
:
864 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
865 return ctx
->Extensions
.EXT_texture_array
866 ? ctx
->Const
.MaxTextureLevels
: 0;
867 case GL_TEXTURE_CUBE_MAP_ARRAY
:
868 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
869 return ctx
->Extensions
.ARB_texture_cube_map_array
870 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
871 case GL_TEXTURE_BUFFER
:
872 return ctx
->API
== API_OPENGL_CORE
&&
873 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
874 case GL_TEXTURE_2D_MULTISAMPLE
:
875 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
876 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
877 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
878 return (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
))
879 && ctx
->Extensions
.ARB_texture_multisample
881 case GL_TEXTURE_EXTERNAL_OES
:
884 return 0; /* bad target */
890 * Return number of dimensions per mipmap level for the given texture target.
893 _mesa_get_texture_dimensions(GLenum target
)
897 case GL_PROXY_TEXTURE_1D
:
900 case GL_TEXTURE_RECTANGLE
:
901 case GL_TEXTURE_CUBE_MAP
:
902 case GL_PROXY_TEXTURE_2D
:
903 case GL_PROXY_TEXTURE_RECTANGLE
:
904 case GL_PROXY_TEXTURE_CUBE_MAP
:
905 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
906 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
907 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
908 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
909 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
910 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
911 case GL_TEXTURE_1D_ARRAY
:
912 case GL_PROXY_TEXTURE_1D_ARRAY
:
913 case GL_TEXTURE_EXTERNAL_OES
:
914 case GL_TEXTURE_2D_MULTISAMPLE
:
915 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
918 case GL_PROXY_TEXTURE_3D
:
919 case GL_TEXTURE_2D_ARRAY
:
920 case GL_PROXY_TEXTURE_2D_ARRAY
:
921 case GL_TEXTURE_CUBE_MAP_ARRAY
:
922 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
923 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
924 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
926 case GL_TEXTURE_BUFFER
:
929 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
937 * Check if a texture target can have more than one layer.
940 _mesa_tex_target_is_layered(GLenum target
)
944 case GL_PROXY_TEXTURE_1D
:
946 case GL_PROXY_TEXTURE_2D
:
947 case GL_TEXTURE_RECTANGLE
:
948 case GL_PROXY_TEXTURE_RECTANGLE
:
949 case GL_TEXTURE_2D_MULTISAMPLE
:
950 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
951 case GL_TEXTURE_BUFFER
:
952 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
953 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
954 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
955 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
956 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
957 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
958 case GL_TEXTURE_EXTERNAL_OES
:
962 case GL_PROXY_TEXTURE_3D
:
963 case GL_TEXTURE_CUBE_MAP
:
964 case GL_PROXY_TEXTURE_CUBE_MAP
:
965 case GL_TEXTURE_1D_ARRAY
:
966 case GL_PROXY_TEXTURE_1D_ARRAY
:
967 case GL_TEXTURE_2D_ARRAY
:
968 case GL_PROXY_TEXTURE_2D_ARRAY
:
969 case GL_TEXTURE_CUBE_MAP_ARRAY
:
970 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
971 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
972 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
976 assert(!"Invalid texture target.");
983 * Return the number of layers present in the given level of an array,
984 * cubemap or 3D texture. If the texture is not layered return zero.
987 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
989 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
991 switch (texObj
->Target
) {
994 case GL_TEXTURE_RECTANGLE
:
995 case GL_TEXTURE_2D_MULTISAMPLE
:
996 case GL_TEXTURE_BUFFER
:
997 case GL_TEXTURE_EXTERNAL_OES
:
1000 case GL_TEXTURE_CUBE_MAP
:
1003 case GL_TEXTURE_1D_ARRAY
: {
1004 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1005 return img
? img
->Height
: 0;
1009 case GL_TEXTURE_2D_ARRAY
:
1010 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1011 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1012 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1013 return img
? img
->Depth
: 0;
1017 assert(!"Invalid texture target.");
1024 * Return the maximum number of mipmap levels for the given target
1025 * and the dimensions.
1026 * The dimensions are expected not to include the border.
1029 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1036 case GL_TEXTURE_1D_ARRAY
:
1037 case GL_PROXY_TEXTURE_1D
:
1038 case GL_PROXY_TEXTURE_1D_ARRAY
:
1041 case GL_TEXTURE_CUBE_MAP
:
1042 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1043 case GL_PROXY_TEXTURE_CUBE_MAP
:
1044 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1048 case GL_TEXTURE_2D_ARRAY
:
1049 case GL_PROXY_TEXTURE_2D
:
1050 case GL_PROXY_TEXTURE_2D_ARRAY
:
1051 size
= MAX2(width
, height
);
1054 case GL_PROXY_TEXTURE_3D
:
1055 size
= MAX3(width
, height
, depth
);
1057 case GL_TEXTURE_RECTANGLE
:
1058 case GL_TEXTURE_EXTERNAL_OES
:
1059 case GL_TEXTURE_2D_MULTISAMPLE
:
1060 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1061 case GL_PROXY_TEXTURE_RECTANGLE
:
1062 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1063 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1070 return _mesa_logbase2(size
) + 1;
1074 #if 000 /* not used anymore */
1076 * glTexImage[123]D can accept a NULL image pointer. In this case we
1077 * create a texture image with unspecified image contents per the OpenGL
1081 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1083 const GLint components
= _mesa_components_in_format(format
);
1084 const GLint numPixels
= width
* height
* depth
;
1085 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1089 * Let's see if anyone finds this. If glTexImage2D() is called with
1090 * a NULL image pointer then load the texture image with something
1091 * interesting instead of leaving it indeterminate.
1094 static const char message
[8][32] = {
1095 " X X XXXXX XXX X ",
1096 " XX XX X X X X X ",
1098 " X X XXXX XXX XXXXX ",
1101 " X X XXXXX XXX X X ",
1105 GLubyte
*imgPtr
= data
;
1107 for (h
= 0; h
< depth
; h
++) {
1108 for (i
= 0; i
< height
; i
++) {
1109 GLint srcRow
= 7 - (i
% 8);
1110 for (j
= 0; j
< width
; j
++) {
1111 GLint srcCol
= j
% 32;
1112 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1113 for (k
= 0; k
< components
; k
++) {
1129 * Set the size and format-related fields of a gl_texture_image struct
1130 * to zero. This is used when a proxy texture test fails.
1133 clear_teximage_fields(struct gl_texture_image
*img
)
1136 img
->_BaseFormat
= 0;
1137 img
->InternalFormat
= 0;
1146 img
->HeightLog2
= 0;
1148 img
->TexFormat
= MESA_FORMAT_NONE
;
1149 img
->NumSamples
= 0;
1150 img
->FixedSampleLocations
= GL_TRUE
;
1155 * Initialize basic fields of the gl_texture_image struct.
1157 * \param ctx GL context.
1158 * \param img texture image structure to be initialized.
1159 * \param width image width.
1160 * \param height image height.
1161 * \param depth image depth.
1162 * \param border image border.
1163 * \param internalFormat internal format.
1164 * \param format the actual hardware format (one of MESA_FORMAT_*)
1165 * \param numSamples number of samples per texel, or zero for non-MS.
1166 * \param fixedSampleLocations are sample locations fixed?
1168 * Fills in the fields of \p img with the given information.
1169 * Note: width, height and depth include the border.
1172 init_teximage_fields_ms(struct gl_context
*ctx
,
1173 struct gl_texture_image
*img
,
1174 GLsizei width
, GLsizei height
, GLsizei depth
,
1175 GLint border
, GLenum internalFormat
,
1177 GLuint numSamples
, GLboolean fixedSampleLocations
)
1182 assert(height
>= 0);
1185 target
= img
->TexObject
->Target
;
1186 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1187 assert(img
->_BaseFormat
!= -1);
1188 img
->InternalFormat
= internalFormat
;
1189 img
->Border
= border
;
1191 img
->Height
= height
;
1194 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1195 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1197 img
->NumSamples
= 0;
1198 img
->FixedSampleLocations
= GL_TRUE
;
1202 case GL_TEXTURE_BUFFER
:
1203 case GL_PROXY_TEXTURE_1D
:
1208 img
->HeightLog2
= 0;
1215 case GL_TEXTURE_1D_ARRAY
:
1216 case GL_PROXY_TEXTURE_1D_ARRAY
:
1217 img
->Height2
= height
; /* no border */
1218 img
->HeightLog2
= 0; /* not used */
1226 case GL_TEXTURE_RECTANGLE
:
1227 case GL_TEXTURE_CUBE_MAP
:
1228 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1229 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1230 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1231 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1232 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1233 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1234 case GL_TEXTURE_EXTERNAL_OES
:
1235 case GL_PROXY_TEXTURE_2D
:
1236 case GL_PROXY_TEXTURE_RECTANGLE
:
1237 case GL_PROXY_TEXTURE_CUBE_MAP
:
1238 case GL_TEXTURE_2D_MULTISAMPLE
:
1239 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1240 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1241 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1248 case GL_TEXTURE_2D_ARRAY
:
1249 case GL_PROXY_TEXTURE_2D_ARRAY
:
1250 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1251 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1252 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1253 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1254 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1255 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1256 img
->Depth2
= depth
; /* no border */
1257 img
->DepthLog2
= 0; /* not used */
1260 case GL_PROXY_TEXTURE_3D
:
1261 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1262 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1263 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1264 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1267 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1272 _mesa_get_tex_max_num_levels(target
,
1273 img
->Width2
, img
->Height2
, img
->Depth2
);
1274 img
->TexFormat
= format
;
1275 img
->NumSamples
= numSamples
;
1276 img
->FixedSampleLocations
= fixedSampleLocations
;
1281 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1282 struct gl_texture_image
*img
,
1283 GLsizei width
, GLsizei height
, GLsizei depth
,
1284 GLint border
, GLenum internalFormat
,
1287 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1288 internalFormat
, format
, 0, GL_TRUE
);
1293 * Free and clear fields of the gl_texture_image struct.
1295 * \param ctx GL context.
1296 * \param texImage texture image structure to be cleared.
1298 * After the call, \p texImage will have no data associated with it. Its
1299 * fields are cleared so that its parent object will test incomplete.
1302 _mesa_clear_texture_image(struct gl_context
*ctx
,
1303 struct gl_texture_image
*texImage
)
1305 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1306 clear_teximage_fields(texImage
);
1311 * Check the width, height, depth and border of a texture image are legal.
1312 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1314 * The target and level parameters will have already been validated.
1315 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1318 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1319 GLint level
, GLint width
, GLint height
,
1320 GLint depth
, GLint border
)
1326 case GL_PROXY_TEXTURE_1D
:
1327 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1328 maxSize
>>= level
; /* level size */
1329 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1331 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1332 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1338 case GL_PROXY_TEXTURE_2D
:
1339 case GL_TEXTURE_2D_MULTISAMPLE
:
1340 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1341 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1343 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1345 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1347 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1348 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1350 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1356 case GL_PROXY_TEXTURE_3D
:
1357 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1359 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1361 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1363 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1365 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1366 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1368 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1370 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1375 case GL_TEXTURE_RECTANGLE_NV
:
1376 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1379 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1380 if (width
< 0 || width
> maxSize
)
1382 if (height
< 0 || height
> maxSize
)
1386 case GL_TEXTURE_CUBE_MAP
:
1387 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1388 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1389 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1390 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1391 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1392 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1393 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1394 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1396 if (width
!= height
)
1398 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1400 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1402 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1403 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1405 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1410 case GL_TEXTURE_1D_ARRAY_EXT
:
1411 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1412 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1414 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1416 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1418 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1419 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1424 case GL_TEXTURE_2D_ARRAY_EXT
:
1425 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1426 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1427 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1428 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1430 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1432 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1434 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1436 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1437 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1439 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1444 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1445 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1446 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1447 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1449 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1451 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1453 if (width
!= height
)
1455 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1457 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1458 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1460 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1465 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1472 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1473 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1474 * \param destImage the destination texture image.
1475 * \return GL_TRUE if error found, GL_FALSE otherwise.
1478 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1479 const struct gl_texture_image
*destImage
,
1480 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1481 GLsizei subWidth
, GLsizei subHeight
,
1482 GLsizei subDepth
, const char *func
)
1484 const GLenum target
= destImage
->TexObject
->Target
;
1489 _mesa_error(ctx
, GL_INVALID_VALUE
,
1490 "%s(width=%d)", func
, subWidth
);
1494 if (dims
> 1 && subHeight
< 0) {
1495 _mesa_error(ctx
, GL_INVALID_VALUE
,
1496 "%s(height=%d)", func
, subHeight
);
1500 if (dims
> 2 && subDepth
< 0) {
1501 _mesa_error(ctx
, GL_INVALID_VALUE
,
1502 "%s(depth=%d)", func
, subDepth
);
1506 /* check xoffset and width */
1507 if (xoffset
< - (GLint
) destImage
->Border
) {
1508 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset)", func
);
1512 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1513 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset+width)", func
);
1517 /* check yoffset and height */
1519 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1520 if (yoffset
< -yBorder
) {
1521 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset)", func
);
1524 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1525 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset+height)", func
);
1530 /* check zoffset and depth */
1533 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1534 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1535 0 : destImage
->Border
;
1537 if (zoffset
< -zBorder
) {
1538 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset)", func
);
1542 depth
= (GLint
) destImage
->Depth
;
1543 if (target
== GL_TEXTURE_CUBE_MAP
)
1545 if (zoffset
+ subDepth
> depth
) {
1546 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset+depth)", func
);
1552 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1553 * compressed texture images can be updated. But, that restriction may be
1554 * relaxed for particular compressed formats. At this time, all the
1555 * compressed formats supported by Mesa allow sub-textures to be updated
1556 * along compressed block boundaries.
1558 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1560 if (bw
!= 1 || bh
!= 1) {
1561 /* offset must be multiple of block size */
1562 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1563 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1564 "%s(xoffset = %d, yoffset = %d)",
1565 func
, xoffset
, yoffset
);
1569 /* The size must be a multiple of bw x bh, or we must be using a
1570 * offset+size that exactly hits the edge of the image. This
1571 * is important for small mipmap levels (1x1, 2x1, etc) and for
1574 if ((subWidth
% bw
!= 0) &&
1575 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1576 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1577 "%s(width = %d)", func
, subWidth
);
1581 if ((subHeight
% bh
!= 0) &&
1582 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1583 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1584 "%s(height = %d)", func
, subHeight
);
1596 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1597 * specific texture image size checks.
1599 * A hardware driver might override this function if, for example, the
1600 * max 3D texture size is 512x512x64 (i.e. not a cube).
1602 * Note that width, height, depth == 0 is not an error. However, a
1603 * texture with zero width/height/depth will be considered "incomplete"
1604 * and texturing will effectively be disabled.
1606 * \param target any texture target/type
1607 * \param level as passed to glTexImage
1608 * \param format the MESA_FORMAT_x for the tex image
1609 * \param width as passed to glTexImage
1610 * \param height as passed to glTexImage
1611 * \param depth as passed to glTexImage
1612 * \param border as passed to glTexImage
1613 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1616 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1618 GLint width
, GLint height
, GLint depth
, GLint border
)
1620 /* We just check if the image size is less than MaxTextureMbytes.
1621 * Some drivers may do more specific checks.
1623 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1624 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1625 mbytes
*= _mesa_num_tex_faces(target
);
1626 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1631 * Return true if the format is only valid for glCompressedTexImage.
1634 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1637 case GL_ETC1_RGB8_OES
:
1638 case GL_PALETTE4_RGB8_OES
:
1639 case GL_PALETTE4_RGBA8_OES
:
1640 case GL_PALETTE4_R5_G6_B5_OES
:
1641 case GL_PALETTE4_RGBA4_OES
:
1642 case GL_PALETTE4_RGB5_A1_OES
:
1643 case GL_PALETTE8_RGB8_OES
:
1644 case GL_PALETTE8_RGBA8_OES
:
1645 case GL_PALETTE8_R5_G6_B5_OES
:
1646 case GL_PALETTE8_RGBA4_OES
:
1647 case GL_PALETTE8_RGB5_A1_OES
:
1655 * Return true if the format doesn't support online compression.
1658 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
)
1660 return _mesa_is_astc_format(format
) ||
1661 compressedteximage_only_format(ctx
, format
);
1664 /* Writes to an GL error pointer if non-null and returns whether or not the
1665 * error is GL_NO_ERROR */
1667 write_error(GLenum
*err_ptr
, GLenum error
)
1672 return error
== GL_NO_ERROR
;
1676 * Helper function to determine whether a target and specific compression
1677 * format are supported. The error parameter returns GL_NO_ERROR if the
1678 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1679 * or GL_INVALID_ENUM, whichever is more appropriate.
1682 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1683 GLenum intFormat
, GLenum
*error
)
1685 GLboolean target_can_be_compresed
= GL_FALSE
;
1686 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1687 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1691 case GL_PROXY_TEXTURE_2D
:
1692 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1694 case GL_PROXY_TEXTURE_CUBE_MAP
:
1695 case GL_TEXTURE_CUBE_MAP
:
1696 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1697 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1698 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1699 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1700 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1701 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1702 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1704 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1705 case GL_TEXTURE_2D_ARRAY_EXT
:
1706 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1708 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1709 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1710 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1712 * "The ETC2/EAC texture compression algorithm supports only
1713 * two-dimensional images. If internalformat is an ETC2/EAC format,
1714 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1715 * target is not TEXTURE_2D_ARRAY."
1717 * This should also be applicable for glTexStorage3D(). Other available
1718 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1720 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
))
1721 return write_error(error
, GL_INVALID_OPERATION
);
1723 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map_array
;
1725 /* From the KHR_texture_compression_astc_hdr spec:
1727 * Add a second new column "3D Tex." which is empty for all non-ASTC
1728 * formats. If only the LDR profile is supported by the
1729 * implementation, this column is also empty for all ASTC formats. If
1730 * both the LDR and HDR profiles are supported only, this column is
1731 * checked for all ASTC formats.
1733 * Add a third new column "Cube Map Array Tex." which is empty for all
1734 * non-ASTC formats, and checked for all ASTC formats.
1738 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1739 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1740 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1741 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1742 * 8.19 is *not* checked'
1744 * The instances of <internalformat> above should say <target>.
1747 /* Throw an INVALID_OPERATION error if the target is
1748 * TEXTURE_CUBE_MAP_ARRAY and the format is not ASTC.
1750 if (target_can_be_compresed
&&
1751 ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
1752 layout
!= MESA_FORMAT_LAYOUT_ASTC
)
1753 return write_error(error
, GL_INVALID_OPERATION
);
1758 case MESA_FORMAT_LAYOUT_ETC2
:
1759 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1760 if (_mesa_is_gles3(ctx
))
1761 return write_error(error
, GL_INVALID_OPERATION
);
1763 case MESA_FORMAT_LAYOUT_BPTC
:
1764 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1766 case MESA_FORMAT_LAYOUT_ASTC
:
1767 target_can_be_compresed
=
1768 ctx
->Extensions
.KHR_texture_compression_astc_hdr
;
1770 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1771 * and the hdr extension is not supported.
1772 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1774 if (!target_can_be_compresed
)
1775 return write_error(error
, GL_INVALID_OPERATION
);
1778 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1779 * the format is not ASTC.
1780 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1782 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
)
1783 return write_error(error
, GL_INVALID_OPERATION
);
1789 return write_error(error
,
1790 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1795 * Check if the given texture target value is legal for a
1796 * glTexImage1/2/3D call.
1799 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1805 case GL_PROXY_TEXTURE_1D
:
1806 return _mesa_is_desktop_gl(ctx
);
1814 case GL_PROXY_TEXTURE_2D
:
1815 return _mesa_is_desktop_gl(ctx
);
1816 case GL_PROXY_TEXTURE_CUBE_MAP
:
1817 return _mesa_is_desktop_gl(ctx
)
1818 && ctx
->Extensions
.ARB_texture_cube_map
;
1819 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1820 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1821 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1822 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1823 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1824 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1825 return ctx
->Extensions
.ARB_texture_cube_map
;
1826 case GL_TEXTURE_RECTANGLE_NV
:
1827 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1828 return _mesa_is_desktop_gl(ctx
)
1829 && ctx
->Extensions
.NV_texture_rectangle
;
1830 case GL_TEXTURE_1D_ARRAY_EXT
:
1831 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1832 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1840 case GL_PROXY_TEXTURE_3D
:
1841 return _mesa_is_desktop_gl(ctx
);
1842 case GL_TEXTURE_2D_ARRAY_EXT
:
1843 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1844 || _mesa_is_gles3(ctx
);
1845 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1846 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1847 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1848 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1849 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1854 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1861 * Check if the given texture target value is legal for a
1862 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1863 * The difference compared to legal_teximage_target() above is that
1864 * proxy targets are not supported.
1867 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1872 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1877 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1878 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1879 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1880 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1881 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1882 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1883 return ctx
->Extensions
.ARB_texture_cube_map
;
1884 case GL_TEXTURE_RECTANGLE_NV
:
1885 return _mesa_is_desktop_gl(ctx
)
1886 && ctx
->Extensions
.NV_texture_rectangle
;
1887 case GL_TEXTURE_1D_ARRAY_EXT
:
1888 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1896 case GL_TEXTURE_2D_ARRAY_EXT
:
1897 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1898 || _mesa_is_gles3(ctx
);
1899 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1900 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1901 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1903 /* Table 8.15 of the OpenGL 4.5 core profile spec
1904 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1905 * and CopyTextureSubImage3D.
1907 case GL_TEXTURE_CUBE_MAP
:
1913 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1921 * Helper function to determine if a texture object is mutable (in terms
1922 * of GL_ARB_texture_storage).
1925 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1927 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1931 return !texObj
->Immutable
;
1936 * Return expected size of a compressed texture.
1939 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1942 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1943 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1947 * Verify that a texture format is valid with a particular target
1949 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1950 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1953 * \param ctx GL context
1954 * \param target Texture target
1955 * \param internalFormat Internal format of the texture image
1956 * \param dimensions Dimensionality at the caller. This is \b not used
1957 * in the validation. It is only used when logging
1959 * \param caller Base name of the calling function (e.g.,
1960 * "glTexImage" or "glTexStorage").
1962 * \returns true if the combination is legal, false otherwise.
1965 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1966 GLenum target
, GLenum internalFormat
,
1967 unsigned dimensions
,
1970 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1971 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
1972 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
1973 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1974 * Profile spec says:
1976 * "Textures with a base internal format of DEPTH_COMPONENT or
1977 * DEPTH_STENCIL are supported by texture image specification
1978 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1979 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1980 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1981 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1982 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1983 * formats in conjunction with any other target will result in an
1984 * INVALID_OPERATION error."
1986 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1987 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1989 if (target
!= GL_TEXTURE_1D
&&
1990 target
!= GL_PROXY_TEXTURE_1D
&&
1991 target
!= GL_TEXTURE_2D
&&
1992 target
!= GL_PROXY_TEXTURE_2D
&&
1993 target
!= GL_TEXTURE_1D_ARRAY
&&
1994 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1995 target
!= GL_TEXTURE_2D_ARRAY
&&
1996 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1997 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1998 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1999 !((_mesa_is_cube_face(target
) ||
2000 target
== GL_TEXTURE_CUBE_MAP
||
2001 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2002 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2003 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2004 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2005 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2006 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2007 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2008 "%s%dD(bad target for depth texture)",
2009 caller
, dimensions
);
2018 texture_formats_agree(GLenum internalFormat
,
2021 GLboolean colorFormat
;
2022 GLboolean is_format_depth_or_depthstencil
;
2023 GLboolean is_internalFormat_depth_or_depthstencil
;
2025 /* Even though there are no color-index textures, we still have to support
2026 * uploading color-index data and remapping it to RGB via the
2027 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2029 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2031 is_internalFormat_depth_or_depthstencil
=
2032 _mesa_is_depth_format(internalFormat
) ||
2033 _mesa_is_depthstencil_format(internalFormat
);
2035 is_format_depth_or_depthstencil
=
2036 _mesa_is_depth_format(format
) ||
2037 _mesa_is_depthstencil_format(format
);
2039 colorFormat
= _mesa_is_color_format(format
);
2041 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2044 if (is_internalFormat_depth_or_depthstencil
!=
2045 is_format_depth_or_depthstencil
)
2048 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2055 * Test the combination of format, type and internal format arguments of
2056 * different texture operations on GLES.
2058 * \param ctx GL context.
2059 * \param format pixel data format given by the user.
2060 * \param type pixel data type given by the user.
2061 * \param internalFormat internal format given by the user.
2062 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2063 * \param callerName name of the caller function to print in the error message
2065 * \return true if a error is found, false otherwise
2067 * Currently, it is used by texture_error_check() and texsubimage_error_check().
2070 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
2071 GLenum type
, GLenum internalFormat
,
2072 GLuint dimensions
, const char *callerName
)
2076 if (_mesa_is_gles3(ctx
)) {
2077 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
2079 if (err
!= GL_NO_ERROR
) {
2080 _mesa_error(ctx
, err
,
2081 "%s(format = %s, type = %s, internalformat = %s)",
2082 callerName
, _mesa_enum_to_string(format
),
2083 _mesa_enum_to_string(type
),
2084 _mesa_enum_to_string(internalFormat
));
2089 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2090 if (err
!= GL_NO_ERROR
) {
2091 _mesa_error(ctx
, err
, "%s(format = %s, type = %s)",
2092 callerName
, _mesa_enum_to_string(format
),
2093 _mesa_enum_to_string(type
));
2102 * Test the glTexImage[123]D() parameters for errors.
2104 * \param ctx GL context.
2105 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2106 * \param target texture target given by the user (already validated).
2107 * \param level image level given by the user.
2108 * \param internalFormat internal format given by the user.
2109 * \param format pixel data format given by the user.
2110 * \param type pixel data type given by the user.
2111 * \param width image width given by the user.
2112 * \param height image height given by the user.
2113 * \param depth image depth given by the user.
2114 * \param border image border given by the user.
2116 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2118 * Verifies each of the parameters against the constants specified in
2119 * __struct gl_contextRec::Const and the supported extensions, and according
2120 * to the OpenGL specification.
2121 * Note that we don't fully error-check the width, height, depth values
2122 * here. That's done in _mesa_legal_texture_dimensions() which is used
2123 * by several other GL entrypoints. Plus, texture dims have a special
2124 * interaction with proxy textures.
2127 texture_error_check( struct gl_context
*ctx
,
2128 GLuint dimensions
, GLenum target
,
2129 GLint level
, GLint internalFormat
,
2130 GLenum format
, GLenum type
,
2131 GLint width
, GLint height
,
2132 GLint depth
, GLint border
,
2133 const GLvoid
*pixels
)
2137 /* Note: for proxy textures, some error conditions immediately generate
2138 * a GL error in the usual way. But others do not generate a GL error.
2139 * Instead, they cause the width, height, depth, format fields of the
2140 * texture image to be zeroed-out. The GL spec seems to indicate that the
2141 * zero-out behaviour is only used in cases related to memory allocation.
2145 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2146 _mesa_error(ctx
, GL_INVALID_VALUE
,
2147 "glTexImage%dD(level=%d)", dimensions
, level
);
2152 if (border
< 0 || border
> 1 ||
2153 ((ctx
->API
!= API_OPENGL_COMPAT
||
2154 target
== GL_TEXTURE_RECTANGLE_NV
||
2155 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2156 _mesa_error(ctx
, GL_INVALID_VALUE
,
2157 "glTexImage%dD(border=%d)", dimensions
, border
);
2161 if (width
< 0 || height
< 0 || depth
< 0) {
2162 _mesa_error(ctx
, GL_INVALID_VALUE
,
2163 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2167 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2168 * combinations of format, internalFormat, and type that can be used.
2169 * Formats and types that require additional extensions (e.g., GL_FLOAT
2170 * requires GL_OES_texture_float) are filtered elsewhere.
2172 if (_mesa_is_gles(ctx
) &&
2173 texture_format_error_check_gles(ctx
, format
, type
, internalFormat
,
2174 dimensions
, "glTexImage%dD")) {
2178 /* Check internalFormat */
2179 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2180 _mesa_error(ctx
, GL_INVALID_VALUE
,
2181 "glTexImage%dD(internalFormat=%s)",
2182 dimensions
, _mesa_enum_to_string(internalFormat
));
2186 /* Check incoming image format and type */
2187 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2188 if (err
!= GL_NO_ERROR
) {
2189 _mesa_error(ctx
, err
,
2190 "glTexImage%dD(incompatible format = %s, type = %s)",
2191 dimensions
, _mesa_enum_to_string(format
),
2192 _mesa_enum_to_string(type
));
2196 /* validate the bound PBO, if any */
2197 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2198 width
, height
, depth
, format
, type
,
2199 INT_MAX
, pixels
, "glTexImage")) {
2203 /* make sure internal format and format basically agree */
2204 if (!texture_formats_agree(internalFormat
, format
)) {
2205 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2206 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2207 dimensions
, _mesa_enum_to_string(internalFormat
),
2208 _mesa_enum_to_string(format
));
2212 /* additional checks for ycbcr textures */
2213 if (internalFormat
== GL_YCBCR_MESA
) {
2214 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
2215 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2216 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2218 _mesa_snprintf(message
, sizeof(message
),
2219 "glTexImage%dD(format/type YCBCR mismatch)",
2221 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2222 return GL_TRUE
; /* error */
2224 if (target
!= GL_TEXTURE_2D
&&
2225 target
!= GL_PROXY_TEXTURE_2D
&&
2226 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2227 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2228 _mesa_error(ctx
, GL_INVALID_ENUM
,
2229 "glTexImage%dD(bad target for YCbCr texture)",
2235 _mesa_snprintf(message
, sizeof(message
),
2236 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2237 dimensions
, border
);
2238 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2243 /* additional checks for depth textures */
2244 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2245 dimensions
, "glTexImage"))
2248 /* additional checks for compressed textures */
2249 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2251 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2252 _mesa_error(ctx
, err
,
2253 "glTexImage%dD(target can't be compressed)", dimensions
);
2256 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2257 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2258 "glTexImage%dD(no compression for format)", dimensions
);
2262 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2263 "glTexImage%dD(border!=0)", dimensions
);
2268 /* additional checks for integer textures */
2269 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2270 (_mesa_is_enum_format_integer(format
) !=
2271 _mesa_is_enum_format_integer(internalFormat
))) {
2272 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2273 "glTexImage%dD(integer/non-integer format mismatch)",
2278 if (!mutable_tex_object(ctx
, target
)) {
2279 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2280 "glTexImage%dD(immutable texture)", dimensions
);
2284 /* if we get here, the parameters are OK */
2290 * Error checking for glCompressedTexImage[123]D().
2291 * Note that the width, height and depth values are not fully error checked
2293 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2296 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2297 GLenum target
, GLint level
,
2298 GLenum internalFormat
, GLsizei width
,
2299 GLsizei height
, GLsizei depth
, GLint border
,
2300 GLsizei imageSize
, const GLvoid
*data
)
2302 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2304 GLenum error
= GL_NO_ERROR
;
2305 char *reason
= ""; /* no error */
2307 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
2312 /* This will detect any invalid internalFormat value */
2313 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2314 _mesa_error(ctx
, GL_INVALID_ENUM
,
2315 "glCompressedTexImage%dD(internalFormat=%s)",
2316 dimensions
, _mesa_enum_to_string(internalFormat
));
2320 /* validate the bound PBO, if any */
2321 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2323 "glCompressedTexImage")) {
2327 switch (internalFormat
) {
2328 case GL_PALETTE4_RGB8_OES
:
2329 case GL_PALETTE4_RGBA8_OES
:
2330 case GL_PALETTE4_R5_G6_B5_OES
:
2331 case GL_PALETTE4_RGBA4_OES
:
2332 case GL_PALETTE4_RGB5_A1_OES
:
2333 case GL_PALETTE8_RGB8_OES
:
2334 case GL_PALETTE8_RGBA8_OES
:
2335 case GL_PALETTE8_R5_G6_B5_OES
:
2336 case GL_PALETTE8_RGBA4_OES
:
2337 case GL_PALETTE8_RGB5_A1_OES
:
2338 /* check level (note that level should be zero or less!) */
2339 if (level
> 0 || level
< -maxLevels
) {
2341 error
= GL_INVALID_VALUE
;
2345 if (dimensions
!= 2) {
2346 reason
= "compressed paletted textures must be 2D";
2347 error
= GL_INVALID_OPERATION
;
2351 /* Figure out the expected texture size (in bytes). This will be
2352 * checked against the actual size later.
2354 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2357 /* This is for the benefit of the TestProxyTexImage below. It expects
2358 * level to be non-negative. OES_compressed_paletted_texture uses a
2359 * weird mechanism where the level specified to glCompressedTexImage2D
2360 * is -(n-1) number of levels in the texture, and the data specifies the
2361 * complete mipmap stack. This is done to ensure the palette is the
2362 * same for all levels.
2369 if (level
< 0 || level
>= maxLevels
) {
2371 error
= GL_INVALID_VALUE
;
2375 /* Figure out the expected texture size (in bytes). This will be
2376 * checked against the actual size later.
2378 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2382 /* This should really never fail */
2383 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2384 reason
= "internalFormat";
2385 error
= GL_INVALID_ENUM
;
2389 /* No compressed formats support borders at this time */
2391 reason
= "border != 0";
2392 error
= GL_INVALID_VALUE
;
2396 /* Check for invalid pixel storage modes */
2397 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2399 "glCompressedTexImage")) {
2403 /* check image size in bytes */
2404 if (expectedSize
!= imageSize
) {
2405 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2406 * if <imageSize> is not consistent with the format, dimensions, and
2407 * contents of the specified image.
2409 reason
= "imageSize inconsistant with width/height/format";
2410 error
= GL_INVALID_VALUE
;
2414 if (!mutable_tex_object(ctx
, target
)) {
2415 reason
= "immutable texture";
2416 error
= GL_INVALID_OPERATION
;
2423 /* Note: not all error paths exit through here. */
2424 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2425 dimensions
, reason
);
2432 * Test glTexSubImage[123]D() parameters for errors.
2434 * \param ctx GL context.
2435 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2436 * \param target texture target given by the user (already validated)
2437 * \param level image level given by the user.
2438 * \param xoffset sub-image x offset given by the user.
2439 * \param yoffset sub-image y offset given by the user.
2440 * \param zoffset sub-image z offset given by the user.
2441 * \param format pixel data format given by the user.
2442 * \param type pixel data type given by the user.
2443 * \param width image width given by the user.
2444 * \param height image height given by the user.
2445 * \param depth image depth given by the user.
2447 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2449 * Verifies each of the parameters against the constants specified in
2450 * __struct gl_contextRec::Const and the supported extensions, and according
2451 * to the OpenGL specification.
2454 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2455 struct gl_texture_object
*texObj
,
2456 GLenum target
, GLint level
,
2457 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2458 GLint width
, GLint height
, GLint depth
,
2459 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2460 bool dsa
, const char *callerName
)
2462 struct gl_texture_image
*texImage
;
2466 /* must be out of memory */
2467 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2472 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2473 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2477 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2479 /* non-existant texture level */
2480 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture image)",
2485 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2486 if (err
!= GL_NO_ERROR
) {
2487 _mesa_error(ctx
, err
,
2488 "%s(incompatible format = %s, type = %s)",
2489 callerName
, _mesa_enum_to_string(format
),
2490 _mesa_enum_to_string(type
));
2494 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2495 * combinations of format, internalFormat, and type that can be used.
2496 * Formats and types that require additional extensions (e.g., GL_FLOAT
2497 * requires GL_OES_texture_float) are filtered elsewhere.
2499 if (_mesa_is_gles(ctx
) &&
2500 texture_format_error_check_gles(ctx
, format
, type
,
2501 texImage
->InternalFormat
,
2502 dimensions
, callerName
)) {
2506 /* validate the bound PBO, if any */
2507 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2508 width
, height
, depth
, format
, type
,
2509 INT_MAX
, pixels
, callerName
)) {
2513 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2514 texImage
, xoffset
, yoffset
, zoffset
,
2515 width
, height
, depth
, callerName
)) {
2519 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2520 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2521 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2522 "%s(no compression for format)", callerName
);
2527 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2528 /* both source and dest must be integer-valued, or neither */
2529 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2530 _mesa_is_enum_format_integer(format
)) {
2531 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2532 "%s(integer/non-integer format mismatch)", callerName
);
2542 * Test glCopyTexImage[12]D() parameters for errors.
2544 * \param ctx GL context.
2545 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2546 * \param target texture target given by the user.
2547 * \param level image level given by the user.
2548 * \param internalFormat internal format given by the user.
2549 * \param width image width given by the user.
2550 * \param height image height given by the user.
2551 * \param border texture border.
2553 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2555 * Verifies each of the parameters against the constants specified in
2556 * __struct gl_contextRec::Const and the supported extensions, and according
2557 * to the OpenGL specification.
2560 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2561 GLenum target
, GLint level
, GLint internalFormat
,
2562 GLint width
, GLint height
, GLint border
)
2565 GLint rb_base_format
;
2566 struct gl_renderbuffer
*rb
;
2567 GLenum rb_internal_format
;
2570 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2571 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2572 dimensions
, _mesa_enum_to_string(target
));
2577 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2578 _mesa_error(ctx
, GL_INVALID_VALUE
,
2579 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2583 /* Check that the source buffer is complete */
2584 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2585 if (ctx
->ReadBuffer
->_Status
== 0) {
2586 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2588 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2589 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2590 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2594 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2596 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2602 if (border
< 0 || border
> 1 ||
2603 ((ctx
->API
!= API_OPENGL_COMPAT
||
2604 target
== GL_TEXTURE_RECTANGLE_NV
||
2605 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2606 _mesa_error(ctx
, GL_INVALID_VALUE
,
2607 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2611 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2614 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2615 switch (internalFormat
) {
2620 case GL_LUMINANCE_ALPHA
:
2623 _mesa_error(ctx
, GL_INVALID_ENUM
,
2624 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2625 _mesa_enum_to_string(internalFormat
));
2630 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2631 if (baseFormat
< 0) {
2632 _mesa_error(ctx
, GL_INVALID_ENUM
,
2633 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2634 _mesa_enum_to_string(internalFormat
));
2638 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2640 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2641 "glCopyTexImage%dD(read buffer)", dimensions
);
2645 rb_internal_format
= rb
->InternalFormat
;
2646 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2647 if (_mesa_is_color_format(internalFormat
)) {
2648 if (rb_base_format
< 0) {
2649 _mesa_error(ctx
, GL_INVALID_VALUE
,
2650 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2651 _mesa_enum_to_string(internalFormat
));
2656 if (_mesa_is_gles(ctx
)) {
2658 if (_mesa_base_format_component_count(baseFormat
) >
2659 _mesa_base_format_component_count(rb_base_format
)) {
2662 if (baseFormat
== GL_DEPTH_COMPONENT
||
2663 baseFormat
== GL_DEPTH_STENCIL
||
2664 rb_base_format
== GL_DEPTH_COMPONENT
||
2665 rb_base_format
== GL_DEPTH_STENCIL
||
2666 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2667 baseFormat
== GL_ALPHA
) &&
2668 rb_base_format
!= GL_RGBA
) ||
2669 internalFormat
== GL_RGB9_E5
) {
2672 if (internalFormat
== GL_RGB9_E5
) {
2676 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2677 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2678 _mesa_enum_to_string(internalFormat
));
2683 if (_mesa_is_gles3(ctx
)) {
2684 bool rb_is_srgb
= false;
2685 bool dst_is_srgb
= false;
2687 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2688 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2692 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2696 if (rb_is_srgb
!= dst_is_srgb
) {
2697 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2698 * OpenGLES 3.0.0 spec says:
2700 * "The error INVALID_OPERATION is also generated if the
2701 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2702 * framebuffer attachment corresponding to the read buffer
2703 * is LINEAR (see section 6.1.13) and internalformat is
2704 * one of the sRGB formats described in section 3.8.16, or
2705 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2706 * SRGB and internalformat is not one of the sRGB formats."
2708 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2709 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2713 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2714 * types for SNORM formats. Also, conversion to SNORM formats is not
2715 * allowed by Table 3.2 on Page 110.
2717 if (_mesa_is_enum_format_snorm(internalFormat
)) {
2718 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2719 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2720 _mesa_enum_to_string(internalFormat
));
2725 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2726 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2727 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2731 /* From the EXT_texture_integer spec:
2733 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2734 * if the texture internalformat is an integer format and the read color
2735 * buffer is not an integer format, or if the internalformat is not an
2736 * integer format and the read color buffer is an integer format."
2738 if (_mesa_is_color_format(internalFormat
)) {
2739 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2740 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2741 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2742 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2743 if (is_int
|| is_rbint
) {
2744 if (is_int
!= is_rbint
) {
2745 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2746 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2748 } else if (_mesa_is_gles(ctx
) &&
2749 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2750 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2751 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2752 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2757 /* From page 138 of OpenGL ES 3.0 spec:
2758 * "The error INVALID_OPERATION is generated if floating-point RGBA
2759 * data is required; if signed integer RGBA data is required and the
2760 * format of the current color buffer is not signed integer; if
2761 * unsigned integer RGBA data is required and the format of the
2762 * current color buffer is not unsigned integer; or if fixed-point
2763 * RGBA data is required and the format of the current color buffer
2764 * is not fixed-point.
2766 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2767 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2768 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2771 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2773 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2774 _mesa_error(ctx
, err
,
2775 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2778 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2779 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2780 "glCopyTexImage%dD(no compression for format)", dimensions
);
2784 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2785 "glCopyTexImage%dD(border!=0)", dimensions
);
2790 if (!mutable_tex_object(ctx
, target
)) {
2791 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2792 "glCopyTexImage%dD(immutable texture)", dimensions
);
2796 /* if we get here, the parameters are OK */
2802 * Test glCopyTexSubImage[12]D() parameters for errors.
2803 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2806 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2807 const struct gl_texture_object
*texObj
,
2808 GLenum target
, GLint level
,
2809 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2810 GLint width
, GLint height
, const char *caller
)
2812 struct gl_texture_image
*texImage
;
2814 /* Check that the source buffer is complete */
2815 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2816 if (ctx
->ReadBuffer
->_Status
== 0) {
2817 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2819 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2820 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2821 "%s(invalid readbuffer)", caller
);
2825 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2826 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2827 "%s(multisample FBO)", caller
);
2833 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2834 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2838 /* Get dest image pointers */
2840 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", caller
);
2844 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2846 /* destination image does not exist */
2847 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2848 "%s(invalid texture image)", caller
);
2852 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2853 xoffset
, yoffset
, zoffset
,
2854 width
, height
, 1, caller
)) {
2858 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2859 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2860 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2861 "%s(no compression for format)", caller
);
2866 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2867 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2871 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2872 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2873 "%s(missing readbuffer, format=0x%x)", caller
,
2874 texImage
->_BaseFormat
);
2878 /* From the EXT_texture_integer spec:
2880 * "INVALID_OPERATION is generated by CopyTexImage* and
2881 * CopyTexSubImage* if the texture internalformat is an integer format
2882 * and the read color buffer is not an integer format, or if the
2883 * internalformat is not an integer format and the read color buffer
2884 * is an integer format."
2886 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2887 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2889 if (_mesa_is_format_integer_color(rb
->Format
) !=
2890 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2891 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2892 "%s(integer vs non-integer)", caller
);
2897 /* if we get here, the parameters are OK */
2902 /** Callback info for walking over FBO hash table */
2905 struct gl_context
*ctx
;
2906 struct gl_texture_object
*texObj
;
2912 * Check render to texture callback. Called from _mesa_HashWalk().
2915 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2917 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2918 const struct cb_info
*info
= (struct cb_info
*) userData
;
2919 struct gl_context
*ctx
= info
->ctx
;
2920 const struct gl_texture_object
*texObj
= info
->texObj
;
2921 const GLuint level
= info
->level
, face
= info
->face
;
2923 /* If this is a user-created FBO */
2924 if (_mesa_is_user_fbo(fb
)) {
2926 /* check if any of the FBO's attachments point to 'texObj' */
2927 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2928 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2929 if (att
->Type
== GL_TEXTURE
&&
2930 att
->Texture
== texObj
&&
2931 att
->TextureLevel
== level
&&
2932 att
->CubeMapFace
== face
) {
2933 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2934 assert(att
->Renderbuffer
->TexImage
);
2935 /* Mark fb status as indeterminate to force re-validation */
2944 * When a texture image is specified we have to check if it's bound to
2945 * any framebuffer objects (render to texture) in order to detect changes
2946 * in size or format since that effects FBO completeness.
2947 * Any FBOs rendering into the texture must be re-validated.
2950 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2951 struct gl_texture_object
*texObj
,
2952 GLuint face
, GLuint level
)
2954 /* Only check this texture if it's been marked as RenderToTexture */
2955 if (texObj
->_RenderToTexture
) {
2956 struct cb_info info
;
2958 info
.texObj
= texObj
;
2961 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2967 * If the texture object's GenerateMipmap flag is set and we've
2968 * changed the texture base level image, regenerate the rest of the
2969 * mipmap levels now.
2972 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2973 struct gl_texture_object
*texObj
, GLint level
)
2975 if (texObj
->GenerateMipmap
&&
2976 level
== texObj
->BaseLevel
&&
2977 level
< texObj
->MaxLevel
) {
2978 assert(ctx
->Driver
.GenerateMipmap
);
2979 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2984 /** Debug helper: override the user-requested internal format */
2986 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2989 if (internalFormat
== GL_RGBA16F_ARB
||
2990 internalFormat
== GL_RGBA32F_ARB
) {
2991 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2994 else if (internalFormat
== GL_RGB16F_ARB
||
2995 internalFormat
== GL_RGB32F_ARB
) {
2996 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2999 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3000 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3001 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3002 return GL_LUMINANCE_ALPHA
;
3004 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3005 internalFormat
== GL_LUMINANCE32F_ARB
) {
3006 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3007 return GL_LUMINANCE
;
3009 else if (internalFormat
== GL_ALPHA16F_ARB
||
3010 internalFormat
== GL_ALPHA32F_ARB
) {
3011 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3015 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3016 internalFormat = GL_RGBA;
3020 return internalFormat
;
3023 return internalFormat
;
3029 * Choose the actual hardware format for a texture image.
3030 * Try to use the same format as the previous image level when possible.
3031 * Otherwise, ask the driver for the best format.
3032 * It's important to try to choose a consistant format for all levels
3033 * for efficient texture memory layout/allocation. In particular, this
3034 * comes up during automatic mipmap generation.
3037 _mesa_choose_texture_format(struct gl_context
*ctx
,
3038 struct gl_texture_object
*texObj
,
3039 GLenum target
, GLint level
,
3040 GLenum internalFormat
, GLenum format
, GLenum type
)
3044 /* see if we've already chosen a format for the previous level */
3046 struct gl_texture_image
*prevImage
=
3047 _mesa_select_tex_image(texObj
, target
, level
- 1);
3048 /* See if the prev level is defined and has an internal format which
3049 * matches the new internal format.
3052 prevImage
->Width
> 0 &&
3053 prevImage
->InternalFormat
== internalFormat
) {
3054 /* use the same format */
3055 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3056 return prevImage
->TexFormat
;
3060 /* If the application requested compression to an S3TC format but we don't
3061 * have the DXTn library, force a generic compressed format instead.
3063 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3064 const GLenum before
= internalFormat
;
3066 switch (internalFormat
) {
3067 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3068 if (!ctx
->Mesa_DXTn
)
3069 internalFormat
= GL_COMPRESSED_RGB
;
3071 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3072 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3073 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3074 if (!ctx
->Mesa_DXTn
)
3075 internalFormat
= GL_COMPRESSED_RGBA
;
3081 if (before
!= internalFormat
) {
3083 "DXT compression requested (%s), "
3084 "but libtxc_dxtn library not installed. Using %s "
3086 _mesa_enum_to_string(before
),
3087 _mesa_enum_to_string(internalFormat
));
3091 /* choose format from scratch */
3092 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3094 assert(f
!= MESA_FORMAT_NONE
);
3100 * Adjust pixel unpack params and image dimensions to strip off the
3101 * one-pixel texture border.
3103 * Gallium and intel don't support texture borders. They've seldem been used
3104 * and seldom been implemented correctly anyway.
3106 * \param unpackNew returns the new pixel unpack parameters
3109 strip_texture_border(GLenum target
,
3110 GLint
*width
, GLint
*height
, GLint
*depth
,
3111 const struct gl_pixelstore_attrib
*unpack
,
3112 struct gl_pixelstore_attrib
*unpackNew
)
3118 *unpackNew
= *unpack
;
3120 if (unpackNew
->RowLength
== 0)
3121 unpackNew
->RowLength
= *width
;
3123 if (unpackNew
->ImageHeight
== 0)
3124 unpackNew
->ImageHeight
= *height
;
3126 assert(*width
>= 3);
3127 unpackNew
->SkipPixels
++; /* skip the border */
3128 *width
= *width
- 2; /* reduce the width by two border pixels */
3130 /* The min height of a texture with a border is 3 */
3131 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3132 unpackNew
->SkipRows
++; /* skip the border */
3133 *height
= *height
- 2; /* reduce the height by two border pixels */
3137 target
!= GL_TEXTURE_2D_ARRAY
&&
3138 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3139 unpackNew
->SkipImages
++; /* skip the border */
3140 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3146 * Common code to implement all the glTexImage1D/2D/3D functions
3147 * as well as glCompressedTexImage1D/2D/3D.
3148 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3149 * \param format the user's image format (only used if !compressed)
3150 * \param type the user's image type (only used if !compressed)
3151 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3154 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3155 GLenum target
, GLint level
, GLint internalFormat
,
3156 GLsizei width
, GLsizei height
, GLsizei depth
,
3157 GLint border
, GLenum format
, GLenum type
,
3158 GLsizei imageSize
, const GLvoid
*pixels
)
3160 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3161 struct gl_pixelstore_attrib unpack_no_border
;
3162 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3163 struct gl_texture_object
*texObj
;
3164 mesa_format texFormat
;
3165 GLboolean dimensionsOK
, sizeOK
;
3167 FLUSH_VERTICES(ctx
, 0);
3169 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3172 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3174 _mesa_enum_to_string(target
), level
,
3175 _mesa_enum_to_string(internalFormat
),
3176 width
, height
, depth
, border
, pixels
);
3179 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3181 _mesa_enum_to_string(target
), level
,
3182 _mesa_enum_to_string(internalFormat
),
3183 width
, height
, depth
, border
,
3184 _mesa_enum_to_string(format
),
3185 _mesa_enum_to_string(type
), pixels
);
3188 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3190 /* target error checking */
3191 if (!legal_teximage_target(ctx
, dims
, target
)) {
3192 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3193 func
, dims
, _mesa_enum_to_string(target
));
3197 /* general error checking */
3199 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3201 width
, height
, depth
,
3202 border
, imageSize
, pixels
))
3206 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3207 format
, type
, width
, height
, depth
, border
,
3212 /* Here we convert a cpal compressed image into a regular glTexImage2D
3213 * call by decompressing the texture. If we really want to support cpal
3214 * textures in any driver this would have to be changed.
3216 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3217 switch (internalFormat
) {
3218 case GL_PALETTE4_RGB8_OES
:
3219 case GL_PALETTE4_RGBA8_OES
:
3220 case GL_PALETTE4_R5_G6_B5_OES
:
3221 case GL_PALETTE4_RGBA4_OES
:
3222 case GL_PALETTE4_RGB5_A1_OES
:
3223 case GL_PALETTE8_RGB8_OES
:
3224 case GL_PALETTE8_RGBA8_OES
:
3225 case GL_PALETTE8_R5_G6_B5_OES
:
3226 case GL_PALETTE8_RGBA4_OES
:
3227 case GL_PALETTE8_RGB5_A1_OES
:
3228 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3229 width
, height
, imageSize
, pixels
);
3234 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3238 /* For glCompressedTexImage() the driver has no choice about the
3239 * texture format since we'll never transcode the user's compressed
3240 * image data. The internalFormat was error checked earlier.
3242 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3245 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3246 * internal floating point format for the given base format.
3248 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3249 if (type
== GL_FLOAT
) {
3250 texObj
->_IsFloat
= GL_TRUE
;
3251 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3252 texObj
->_IsHalfFloat
= GL_TRUE
;
3255 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3258 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3259 internalFormat
, format
, type
);
3262 assert(texFormat
!= MESA_FORMAT_NONE
);
3264 /* check that width, height, depth are legal for the mipmap level */
3265 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3266 height
, depth
, border
);
3268 /* check that the texture won't take too much memory, etc */
3269 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3271 width
, height
, depth
, border
);
3273 if (_mesa_is_proxy_texture(target
)) {
3274 /* Proxy texture: just clear or set state depending on error checking */
3275 struct gl_texture_image
*texImage
=
3276 get_proxy_tex_image(ctx
, target
, level
);
3279 return; /* GL_OUT_OF_MEMORY already recorded */
3281 if (dimensionsOK
&& sizeOK
) {
3282 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3283 border
, internalFormat
, texFormat
);
3286 clear_teximage_fields(texImage
);
3290 /* non-proxy target */
3291 const GLuint face
= _mesa_tex_target_to_face(target
);
3292 struct gl_texture_image
*texImage
;
3294 if (!dimensionsOK
) {
3295 _mesa_error(ctx
, GL_INVALID_VALUE
,
3296 "%s%uD(invalid width or height or depth)",
3302 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3303 "%s%uD(image too large: %d x %d x %d, %s format)",
3304 func
, dims
, width
, height
, depth
,
3305 _mesa_enum_to_string(internalFormat
));
3309 /* Allow a hardware driver to just strip out the border, to provide
3310 * reliable but slightly incorrect hardware rendering instead of
3311 * rarely-tested software fallback rendering.
3313 if (border
&& ctx
->Const
.StripTextureBorder
) {
3314 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3317 unpack
= &unpack_no_border
;
3320 if (ctx
->NewState
& _NEW_PIXEL
)
3321 _mesa_update_state(ctx
);
3323 _mesa_lock_texture(ctx
, texObj
);
3325 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3328 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3331 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3333 _mesa_init_teximage_fields(ctx
, texImage
,
3334 width
, height
, depth
,
3335 border
, internalFormat
, texFormat
);
3337 /* Give the texture to the driver. <pixels> may be null. */
3338 if (width
> 0 && height
> 0 && depth
> 0) {
3340 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3344 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3345 type
, pixels
, unpack
);
3349 check_gen_mipmap(ctx
, target
, texObj
, level
);
3351 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3353 _mesa_dirty_texobj(ctx
, texObj
);
3356 _mesa_unlock_texture(ctx
, texObj
);
3363 * Called from the API. Note that width includes the border.
3366 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3367 GLsizei width
, GLint border
, GLenum format
,
3368 GLenum type
, const GLvoid
*pixels
)
3370 GET_CURRENT_CONTEXT(ctx
);
3371 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3372 border
, format
, type
, 0, pixels
);
3377 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3378 GLsizei width
, GLsizei height
, GLint border
,
3379 GLenum format
, GLenum type
,
3380 const GLvoid
*pixels
)
3382 GET_CURRENT_CONTEXT(ctx
);
3383 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3384 border
, format
, type
, 0, pixels
);
3389 * Called by the API or display list executor.
3390 * Note that width and height include the border.
3393 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3394 GLsizei width
, GLsizei height
, GLsizei depth
,
3395 GLint border
, GLenum format
, GLenum type
,
3396 const GLvoid
*pixels
)
3398 GET_CURRENT_CONTEXT(ctx
);
3399 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3400 width
, height
, depth
,
3401 border
, format
, type
, 0, pixels
);
3406 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3407 GLsizei width
, GLsizei height
, GLsizei depth
,
3408 GLint border
, GLenum format
, GLenum type
,
3409 const GLvoid
*pixels
)
3411 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3412 depth
, border
, format
, type
, pixels
);
3417 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3419 struct gl_texture_object
*texObj
;
3420 struct gl_texture_image
*texImage
;
3422 GET_CURRENT_CONTEXT(ctx
);
3423 FLUSH_VERTICES(ctx
, 0);
3427 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3429 case GL_TEXTURE_EXTERNAL_OES
:
3431 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3434 valid_target
= false;
3438 if (!valid_target
) {
3439 _mesa_error(ctx
, GL_INVALID_ENUM
,
3440 "glEGLImageTargetTexture2D(target=%d)", target
);
3445 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3446 "glEGLImageTargetTexture2D(image=%p)", image
);
3450 if (ctx
->NewState
& _NEW_PIXEL
)
3451 _mesa_update_state(ctx
);
3453 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3457 _mesa_lock_texture(ctx
, texObj
);
3459 if (texObj
->Immutable
) {
3460 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3461 "glEGLImageTargetTexture2D(texture is immutable)");
3462 _mesa_unlock_texture(ctx
, texObj
);
3466 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3468 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3470 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3472 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3473 texObj
, texImage
, image
);
3475 _mesa_dirty_texobj(ctx
, texObj
);
3477 _mesa_unlock_texture(ctx
, texObj
);
3482 * Helper that implements the glTexSubImage1/2/3D()
3483 * and glTextureSubImage1/2/3D() functions.
3486 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3487 struct gl_texture_object
*texObj
,
3488 struct gl_texture_image
*texImage
,
3489 GLenum target
, GLint level
,
3490 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3491 GLsizei width
, GLsizei height
, GLsizei depth
,
3492 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3495 FLUSH_VERTICES(ctx
, 0);
3497 if (ctx
->NewState
& _NEW_PIXEL
)
3498 _mesa_update_state(ctx
);
3500 _mesa_lock_texture(ctx
, texObj
);
3502 if (width
> 0 && height
> 0 && depth
> 0) {
3503 /* If we have a border, offset=-1 is legal. Bias by border width. */
3506 if (target
!= GL_TEXTURE_2D_ARRAY
)
3507 zoffset
+= texImage
->Border
;
3510 if (target
!= GL_TEXTURE_1D_ARRAY
)
3511 yoffset
+= texImage
->Border
;
3514 xoffset
+= texImage
->Border
;
3517 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3518 xoffset
, yoffset
, zoffset
,
3519 width
, height
, depth
,
3520 format
, type
, pixels
, &ctx
->Unpack
);
3522 check_gen_mipmap(ctx
, target
, texObj
, level
);
3524 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3525 * the texel data, not the texture format, size, etc.
3529 _mesa_unlock_texture(ctx
, texObj
);
3533 * Implement all the glTexSubImage1/2/3D() functions.
3534 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3537 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3538 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3539 GLsizei width
, GLsizei height
, GLsizei depth
,
3540 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3541 const char *callerName
)
3543 struct gl_texture_object
*texObj
;
3544 struct gl_texture_image
*texImage
;
3546 /* check target (proxies not allowed) */
3547 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3548 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3549 dims
, _mesa_enum_to_string(target
));
3553 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3557 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3558 xoffset
, yoffset
, zoffset
,
3559 width
, height
, depth
, format
, type
,
3560 pixels
, false, callerName
)) {
3561 return; /* error was detected */
3564 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3565 /* texsubimage_error_check ensures that texImage is not NULL */
3567 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3568 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3570 _mesa_enum_to_string(target
), level
,
3571 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3572 _mesa_enum_to_string(format
),
3573 _mesa_enum_to_string(type
), pixels
);
3575 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3576 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3577 format
, type
, pixels
, false);
3582 * Implement all the glTextureSubImage1/2/3D() functions.
3583 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3586 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3587 GLuint texture
, GLint level
,
3588 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3589 GLsizei width
, GLsizei height
, GLsizei depth
,
3590 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3591 const char *callerName
)
3593 struct gl_texture_object
*texObj
;
3594 struct gl_texture_image
*texImage
;
3597 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3599 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3600 dims
, texture
, level
,
3601 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3602 _mesa_enum_to_string(format
),
3603 _mesa_enum_to_string(type
), pixels
);
3605 /* Get the texture object by Name. */
3606 texObj
= _mesa_lookup_texture(ctx
, texture
);
3608 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3613 /* check target (proxies not allowed) */
3614 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3615 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3616 callerName
, _mesa_enum_to_string(texObj
->Target
));
3620 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3621 xoffset
, yoffset
, zoffset
,
3622 width
, height
, depth
, format
, type
,
3623 pixels
, true, callerName
)) {
3624 return; /* error was detected */
3628 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3629 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3633 * What do we do if the user created a texture with the following code
3634 * and then called this function with its handle?
3637 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3638 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3639 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3640 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3641 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3642 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3643 * // wrong format, or given the wrong size, etc.
3644 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3645 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3647 * A bug has been filed against the spec for this case. In the
3648 * meantime, we will check for cube completeness.
3650 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3651 * Core Profile spec (30.10.2014):
3652 * "[A] cube map texture is cube complete if the
3653 * following conditions all hold true: The [base level] texture
3654 * images of each of the six cube map faces have identical, positive,
3655 * and square dimensions. The [base level] images were each specified
3656 * with the same internal format."
3658 * It seems reasonable to check for cube completeness of an arbitrary
3659 * level here so that the image data has a consistent format and size.
3661 if (!_mesa_cube_level_complete(texObj
, level
)) {
3662 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3663 "glTextureSubImage%uD(cube map incomplete)",
3668 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3670 /* Copy in each face. */
3671 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3672 texImage
= texObj
->Image
[i
][level
];
3675 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3676 level
, xoffset
, yoffset
, 0,
3677 width
, height
, 1, format
,
3678 type
, pixels
, true);
3679 pixels
= (GLubyte
*) pixels
+ imageStride
;
3683 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3686 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3687 level
, xoffset
, yoffset
, zoffset
,
3688 width
, height
, depth
, format
,
3689 type
, pixels
, true);
3695 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3696 GLint xoffset
, GLsizei width
,
3697 GLenum format
, GLenum type
,
3698 const GLvoid
*pixels
)
3700 GET_CURRENT_CONTEXT(ctx
);
3701 texsubimage(ctx
, 1, target
, level
,
3704 format
, type
, pixels
, "glTexSubImage1D");
3709 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3710 GLint xoffset
, GLint yoffset
,
3711 GLsizei width
, GLsizei height
,
3712 GLenum format
, GLenum type
,
3713 const GLvoid
*pixels
)
3715 GET_CURRENT_CONTEXT(ctx
);
3716 texsubimage(ctx
, 2, target
, level
,
3717 xoffset
, yoffset
, 0,
3719 format
, type
, pixels
, "glTexSubImage2D");
3725 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3726 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3727 GLsizei width
, GLsizei height
, GLsizei depth
,
3728 GLenum format
, GLenum type
,
3729 const GLvoid
*pixels
)
3731 GET_CURRENT_CONTEXT(ctx
);
3732 texsubimage(ctx
, 3, target
, level
,
3733 xoffset
, yoffset
, zoffset
,
3734 width
, height
, depth
,
3735 format
, type
, pixels
, "glTexSubImage3D");
3739 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3740 GLint xoffset
, GLsizei width
,
3741 GLenum format
, GLenum type
,
3742 const GLvoid
*pixels
)
3744 GET_CURRENT_CONTEXT(ctx
);
3745 texturesubimage(ctx
, 1, texture
, level
,
3748 format
, type
, pixels
, "glTextureSubImage1D");
3753 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3754 GLint xoffset
, GLint yoffset
,
3755 GLsizei width
, GLsizei height
,
3756 GLenum format
, GLenum type
,
3757 const GLvoid
*pixels
)
3759 GET_CURRENT_CONTEXT(ctx
);
3760 texturesubimage(ctx
, 2, texture
, level
,
3761 xoffset
, yoffset
, 0,
3763 format
, type
, pixels
, "glTextureSubImage2D");
3768 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3769 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3770 GLsizei width
, GLsizei height
, GLsizei depth
,
3771 GLenum format
, GLenum type
,
3772 const GLvoid
*pixels
)
3774 GET_CURRENT_CONTEXT(ctx
);
3775 texturesubimage(ctx
, 3, texture
, level
,
3776 xoffset
, yoffset
, zoffset
,
3777 width
, height
, depth
,
3778 format
, type
, pixels
, "glTextureSubImage3D");
3783 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3784 * from. This depends on whether the texture contains color or depth values.
3786 static struct gl_renderbuffer
*
3787 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3789 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3790 /* reading from depth/stencil buffer */
3791 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3794 /* copying from color buffer */
3795 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3800 copytexsubimage_by_slice(struct gl_context
*ctx
,
3801 struct gl_texture_image
*texImage
,
3803 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3804 struct gl_renderbuffer
*rb
,
3806 GLsizei width
, GLsizei height
)
3808 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3811 /* For 1D arrays, we copy each scanline of the source rectangle into the
3814 assert(zoffset
== 0);
3816 for (slice
= 0; slice
< height
; slice
++) {
3817 assert(yoffset
+ slice
< texImage
->Height
);
3818 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3819 xoffset
, 0, yoffset
+ slice
,
3820 rb
, x
, y
+ slice
, width
, 1);
3823 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3824 xoffset
, yoffset
, zoffset
,
3825 rb
, x
, y
, width
, height
);
3830 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3832 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3833 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3834 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3835 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3837 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3838 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3839 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3840 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3842 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3843 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3844 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3845 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3852 * Implement the glCopyTexImage1/2D() functions.
3855 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3856 GLenum target
, GLint level
, GLenum internalFormat
,
3857 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3859 struct gl_texture_object
*texObj
;
3860 struct gl_texture_image
*texImage
;
3861 const GLuint face
= _mesa_tex_target_to_face(target
);
3862 mesa_format texFormat
;
3863 struct gl_renderbuffer
*rb
;
3865 FLUSH_VERTICES(ctx
, 0);
3867 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3868 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3870 _mesa_enum_to_string(target
), level
,
3871 _mesa_enum_to_string(internalFormat
),
3872 x
, y
, width
, height
, border
);
3874 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3875 _mesa_update_state(ctx
);
3877 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3878 width
, height
, border
))
3881 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3883 _mesa_error(ctx
, GL_INVALID_VALUE
,
3884 "glCopyTexImage%uD(invalid width or height)", dims
);
3888 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3891 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3892 internalFormat
, GL_NONE
, GL_NONE
);
3894 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3896 if (_mesa_is_gles3(ctx
)) {
3897 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3898 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3899 * OpenGL ES 3.0. Khronos bug# 9807.
3901 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3902 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3903 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
3904 " and writing to unsized internal format)", dims
);
3908 /* From Page 139 of OpenGL ES 3.0 spec:
3909 * "If internalformat is sized, the internal format of the new texel
3910 * array is internalformat, and this is also the new texel array’s
3911 * effective internal format. If the component sizes of internalformat
3912 * do not exactly match the corresponding component sizes of the source
3913 * buffer’s effective internal format, described below, an
3914 * INVALID_OPERATION error is generated. If internalformat is unsized,
3915 * the internal format of the new texel array is the effective internal
3916 * format of the source buffer, and this is also the new texel array’s
3917 * effective internal format.
3919 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3920 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3921 "glCopyTexImage%uD(componenet size changed in"
3922 " internal format)", dims
);
3927 assert(texFormat
!= MESA_FORMAT_NONE
);
3929 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3931 width
, height
, 1, border
)) {
3932 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3933 "glCopyTexImage%uD(image too large)", dims
);
3937 if (border
&& ctx
->Const
.StripTextureBorder
) {
3939 width
-= border
* 2;
3942 height
-= border
* 2;
3947 _mesa_lock_texture(ctx
, texObj
);
3949 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3952 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3955 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3957 /* Free old texture image */
3958 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3960 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3961 border
, internalFormat
, texFormat
);
3963 if (width
&& height
) {
3964 /* Allocate texture memory (no pixel data yet) */
3965 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3967 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3969 struct gl_renderbuffer
*srcRb
=
3970 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3972 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3974 srcRb
, srcX
, srcY
, width
, height
);
3977 check_gen_mipmap(ctx
, target
, texObj
, level
);
3980 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3982 _mesa_dirty_texobj(ctx
, texObj
);
3985 _mesa_unlock_texture(ctx
, texObj
);
3991 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3992 GLenum internalFormat
,
3994 GLsizei width
, GLint border
)
3996 GET_CURRENT_CONTEXT(ctx
);
3997 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4003 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4004 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4007 GET_CURRENT_CONTEXT(ctx
);
4008 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4009 x
, y
, width
, height
, border
);
4013 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4016 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4017 struct gl_texture_object
*texObj
,
4018 GLenum target
, GLint level
,
4019 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4021 GLsizei width
, GLsizei height
,
4024 struct gl_texture_image
*texImage
;
4026 FLUSH_VERTICES(ctx
, 0);
4028 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4029 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
4030 _mesa_enum_to_string(target
),
4031 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4033 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4034 _mesa_update_state(ctx
);
4036 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4037 xoffset
, yoffset
, zoffset
,
4038 width
, height
, caller
)) {
4042 _mesa_lock_texture(ctx
, texObj
);
4044 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4046 /* If we have a border, offset=-1 is legal. Bias by border width. */
4049 if (target
!= GL_TEXTURE_2D_ARRAY
)
4050 zoffset
+= texImage
->Border
;
4053 if (target
!= GL_TEXTURE_1D_ARRAY
)
4054 yoffset
+= texImage
->Border
;
4057 xoffset
+= texImage
->Border
;
4060 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4062 struct gl_renderbuffer
*srcRb
=
4063 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4065 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4066 xoffset
, yoffset
, zoffset
,
4067 srcRb
, x
, y
, width
, height
);
4069 check_gen_mipmap(ctx
, target
, texObj
, level
);
4071 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4072 * the texel data, not the texture format, size, etc.
4076 _mesa_unlock_texture(ctx
, texObj
);
4080 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4081 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4083 struct gl_texture_object
* texObj
;
4084 const char *self
= "glCopyTexSubImage1D";
4085 GET_CURRENT_CONTEXT(ctx
);
4087 /* Check target (proxies not allowed). Target must be checked prior to
4088 * calling _mesa_get_current_tex_object.
4090 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4091 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4092 _mesa_enum_to_string(target
));
4096 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4100 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4101 x
, y
, width
, 1, self
);
4107 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4108 GLint xoffset
, GLint yoffset
,
4109 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4111 struct gl_texture_object
* texObj
;
4112 const char *self
= "glCopyTexSubImage2D";
4113 GET_CURRENT_CONTEXT(ctx
);
4115 /* Check target (proxies not allowed). Target must be checked prior to
4116 * calling _mesa_get_current_tex_object.
4118 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4119 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4120 _mesa_enum_to_string(target
));
4124 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4128 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4129 xoffset
, yoffset
, 0,
4130 x
, y
, width
, height
, self
);
4136 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4137 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4138 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4140 struct gl_texture_object
* texObj
;
4141 const char *self
= "glCopyTexSubImage3D";
4142 GET_CURRENT_CONTEXT(ctx
);
4144 /* Check target (proxies not allowed). Target must be checked prior to
4145 * calling _mesa_get_current_tex_object.
4147 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4148 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4149 _mesa_enum_to_string(target
));
4153 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4157 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4158 xoffset
, yoffset
, zoffset
,
4159 x
, y
, width
, height
, self
);
4163 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4164 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4166 struct gl_texture_object
* texObj
;
4167 const char *self
= "glCopyTextureSubImage1D";
4168 GET_CURRENT_CONTEXT(ctx
);
4170 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4174 /* Check target (proxies not allowed). */
4175 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4176 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4177 _mesa_enum_to_string(texObj
->Target
));
4181 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4182 xoffset
, 0, 0, x
, y
, width
, 1, self
);
4186 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4187 GLint xoffset
, GLint yoffset
,
4188 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4190 struct gl_texture_object
* texObj
;
4191 const char *self
= "glCopyTextureSubImage2D";
4192 GET_CURRENT_CONTEXT(ctx
);
4194 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4198 /* Check target (proxies not allowed). */
4199 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4200 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4201 _mesa_enum_to_string(texObj
->Target
));
4205 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4206 xoffset
, yoffset
, 0,
4207 x
, y
, width
, height
, self
);
4213 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4214 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4215 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4217 struct gl_texture_object
* texObj
;
4218 const char *self
= "glCopyTextureSubImage3D";
4219 GET_CURRENT_CONTEXT(ctx
);
4221 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4225 /* Check target (proxies not allowed). */
4226 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4227 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4228 _mesa_enum_to_string(texObj
->Target
));
4232 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4233 /* Act like CopyTexSubImage2D */
4234 _mesa_copy_texture_sub_image(ctx
, 2, texObj
,
4235 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4236 level
, xoffset
, yoffset
, 0,
4237 x
, y
, width
, height
, self
);
4240 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4241 xoffset
, yoffset
, zoffset
,
4242 x
, y
, width
, height
, self
);
4246 check_clear_tex_image(struct gl_context
*ctx
,
4247 const char *function
,
4248 struct gl_texture_image
*texImage
,
4249 GLenum format
, GLenum type
,
4251 GLubyte
*clearValue
)
4253 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4254 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4255 GLenum internalFormat
= texImage
->InternalFormat
;
4258 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4259 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4260 "%s(buffer texture)", function
);
4264 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4265 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4266 "%s(compressed texture)", function
);
4270 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4271 if (err
!= GL_NO_ERROR
) {
4272 _mesa_error(ctx
, err
,
4273 "%s(incompatible format = %s, type = %s)",
4275 _mesa_enum_to_string(format
),
4276 _mesa_enum_to_string(type
));
4280 /* make sure internal format and format basically agree */
4281 if (!texture_formats_agree(internalFormat
, format
)) {
4282 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4283 "%s(incompatible internalFormat = %s, format = %s)",
4285 _mesa_enum_to_string(internalFormat
),
4286 _mesa_enum_to_string(format
));
4290 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4291 /* both source and dest must be integer-valued, or neither */
4292 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4293 _mesa_is_enum_format_integer(format
)) {
4294 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4295 "%s(integer/non-integer format mismatch)",
4301 if (!_mesa_texstore(ctx
,
4303 texImage
->_BaseFormat
,
4304 texImage
->TexFormat
,
4305 0, /* dstRowStride */
4307 1, 1, 1, /* srcWidth/Height/Depth */
4309 data
? data
: zeroData
,
4310 &ctx
->DefaultPacking
)) {
4311 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4318 static struct gl_texture_object
*
4319 get_tex_obj_for_clear(struct gl_context
*ctx
,
4320 const char *function
,
4323 struct gl_texture_object
*texObj
;
4326 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4330 texObj
= _mesa_lookup_texture(ctx
, texture
);
4332 if (texObj
== NULL
) {
4333 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4337 if (texObj
->Target
== 0) {
4338 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4346 get_tex_images_for_clear(struct gl_context
*ctx
,
4347 const char *function
,
4348 struct gl_texture_object
*texObj
,
4350 struct gl_texture_image
**texImages
)
4355 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4356 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4360 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4361 for (i
= 0; i
< MAX_FACES
; i
++) {
4362 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4364 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4365 if (texImages
[i
] == NULL
) {
4366 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4367 "%s(invalid level)", function
);
4375 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4377 if (texImages
[0] == NULL
) {
4378 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4386 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4387 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4388 GLsizei width
, GLsizei height
, GLsizei depth
,
4389 GLenum format
, GLenum type
, const void *data
)
4391 GET_CURRENT_CONTEXT(ctx
);
4392 struct gl_texture_object
*texObj
;
4393 struct gl_texture_image
*texImages
[MAX_FACES
];
4394 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4396 int minDepth
, maxDepth
;
4398 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4403 _mesa_lock_texture(ctx
, texObj
);
4405 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4406 texObj
, level
, texImages
);
4410 if (numImages
== 1) {
4411 minDepth
= -(int) texImages
[0]->Border
;
4412 maxDepth
= texImages
[0]->Depth
;
4415 maxDepth
= numImages
;
4418 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4419 yoffset
< -(GLint
) texImages
[0]->Border
||
4420 zoffset
< minDepth
||
4424 xoffset
+ width
> texImages
[0]->Width
||
4425 yoffset
+ height
> texImages
[0]->Height
||
4426 zoffset
+ depth
> maxDepth
) {
4427 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4428 "glClearSubTexImage(invalid dimensions)");
4432 if (numImages
== 1) {
4433 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4435 format
, type
, data
, clearValue
[0])) {
4436 ctx
->Driver
.ClearTexSubImage(ctx
,
4438 xoffset
, yoffset
, zoffset
,
4439 width
, height
, depth
,
4440 data
? clearValue
[0] : NULL
);
4443 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4444 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4446 format
, type
, data
, clearValue
[i
]))
4449 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4450 ctx
->Driver
.ClearTexSubImage(ctx
,
4452 xoffset
, yoffset
, 0,
4454 data
? clearValue
[i
] : NULL
);
4459 _mesa_unlock_texture(ctx
, texObj
);
4463 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4464 GLenum format
, GLenum type
, const void *data
)
4466 GET_CURRENT_CONTEXT(ctx
);
4467 struct gl_texture_object
*texObj
;
4468 struct gl_texture_image
*texImages
[MAX_FACES
];
4469 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4472 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4477 _mesa_lock_texture(ctx
, texObj
);
4479 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4480 texObj
, level
, texImages
);
4482 for (i
= 0; i
< numImages
; i
++) {
4483 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4490 for (i
= 0; i
< numImages
; i
++) {
4491 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4492 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4493 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4494 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4495 texImages
[i
]->Width
,
4496 texImages
[i
]->Height
,
4497 texImages
[i
]->Depth
,
4498 data
? clearValue
[i
] : NULL
);
4502 _mesa_unlock_texture(ctx
, texObj
);
4508 /**********************************************************************/
4509 /****** Compressed Textures ******/
4510 /**********************************************************************/
4514 * Target checking for glCompressedTexSubImage[123]D().
4515 * \return GL_TRUE if error, GL_FALSE if no error
4516 * Must come before other error checking so that the texture object can
4517 * be correctly retrieved using _mesa_get_current_tex_object.
4520 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4521 GLint dims
, GLenum format
, bool dsa
,
4526 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4527 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4528 _mesa_enum_to_string(target
));
4538 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4539 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4540 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4541 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4542 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4543 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4544 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4547 targetOK
= GL_FALSE
;
4553 case GL_TEXTURE_CUBE_MAP
:
4554 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4556 case GL_TEXTURE_2D_ARRAY
:
4557 targetOK
= _mesa_is_gles3(ctx
) ||
4558 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4560 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4561 targetOK
= ctx
->Extensions
.ARB_texture_cube_map_array
;
4566 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4568 * "An INVALID_OPERATION error is generated by
4569 * CompressedTex*SubImage3D if the internal format of the texture
4570 * is one of the EAC, ETC2, or RGTC formats and either border is
4571 * non-zero, or the effective target for the texture is not
4572 * TEXTURE_2D_ARRAY."
4574 * NOTE: that's probably a spec error. It should probably say
4575 * "... or the effective target for the texture is not
4576 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4577 * GL_TEXTURE_CUBE_MAP_ARRAY."
4578 * since those targets are 2D images and they support all compression
4581 * Instead of listing all these, just list those which are allowed,
4582 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4583 * more) are valid here, which they are not, but of course not
4584 * mentioned by core spec.
4587 /* These are the only 3D compression formats supported at this time */
4588 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
4589 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
4590 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
4591 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
4595 /* invalid format */
4596 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4597 "%s(invalid target %s for format %s)", caller
,
4598 _mesa_enum_to_string(target
),
4599 _mesa_enum_to_string(format
));
4604 targetOK
= GL_FALSE
;
4610 /* no 1D compressed textures at this time */
4611 targetOK
= GL_FALSE
;
4616 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4617 _mesa_enum_to_string(target
));
4625 * Error checking for glCompressedTexSubImage[123]D().
4626 * \return GL_TRUE if error, GL_FALSE if no error
4629 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4630 const struct gl_texture_object
*texObj
,
4631 GLenum target
, GLint level
,
4632 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4633 GLsizei width
, GLsizei height
, GLsizei depth
,
4634 GLenum format
, GLsizei imageSize
,
4635 const GLvoid
*data
, const char *callerName
)
4637 struct gl_texture_image
*texImage
;
4640 /* this will catch any invalid compressed format token */
4641 if (!_mesa_is_compressed_format(ctx
, format
)) {
4642 _mesa_error(ctx
, GL_INVALID_ENUM
,
4643 "%s(format)", callerName
);
4647 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4648 _mesa_error(ctx
, GL_INVALID_VALUE
,
4654 /* validate the bound PBO, if any */
4655 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4656 imageSize
, data
, callerName
)) {
4660 /* Check for invalid pixel storage modes */
4661 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4662 &ctx
->Unpack
, callerName
)) {
4666 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4667 if (expectedSize
!= imageSize
) {
4668 _mesa_error(ctx
, GL_INVALID_VALUE
,
4670 callerName
, imageSize
);
4674 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4676 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4677 "%s(invalid texture image)",
4682 if ((GLint
) format
!= texImage
->InternalFormat
) {
4683 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4685 callerName
, format
);
4689 if (compressedteximage_only_format(ctx
, format
)) {
4690 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4691 "%s(format=0x%x cannot be updated)",
4692 callerName
, format
);
4696 if (error_check_subtexture_dimensions(ctx
, dims
,
4697 texImage
, xoffset
, yoffset
, zoffset
,
4698 width
, height
, depth
,
4708 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4709 GLenum internalFormat
, GLsizei width
,
4710 GLint border
, GLsizei imageSize
,
4713 GET_CURRENT_CONTEXT(ctx
);
4714 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4715 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4720 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4721 GLenum internalFormat
, GLsizei width
,
4722 GLsizei height
, GLint border
, GLsizei imageSize
,
4725 GET_CURRENT_CONTEXT(ctx
);
4726 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4727 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4732 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4733 GLenum internalFormat
, GLsizei width
,
4734 GLsizei height
, GLsizei depth
, GLint border
,
4735 GLsizei imageSize
, const GLvoid
*data
)
4737 GET_CURRENT_CONTEXT(ctx
);
4738 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4739 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4744 * Common helper for glCompressedTexSubImage1/2/3D() and
4745 * glCompressedTextureSubImage1/2/3D().
4748 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4749 struct gl_texture_object
*texObj
,
4750 struct gl_texture_image
*texImage
,
4751 GLenum target
, GLint level
,
4752 GLint xoffset
, GLint yoffset
,
4754 GLsizei width
, GLsizei height
,
4756 GLenum format
, GLsizei imageSize
,
4759 FLUSH_VERTICES(ctx
, 0);
4761 _mesa_lock_texture(ctx
, texObj
);
4763 if (width
> 0 && height
> 0 && depth
> 0) {
4764 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4765 xoffset
, yoffset
, zoffset
,
4766 width
, height
, depth
,
4767 format
, imageSize
, data
);
4769 check_gen_mipmap(ctx
, target
, texObj
, level
);
4771 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4772 * the texel data, not the texture format, size, etc.
4776 _mesa_unlock_texture(ctx
, texObj
);
4781 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4782 GLsizei width
, GLenum format
,
4783 GLsizei imageSize
, const GLvoid
*data
)
4785 struct gl_texture_object
*texObj
;
4786 struct gl_texture_image
*texImage
;
4788 GET_CURRENT_CONTEXT(ctx
);
4790 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4791 "glCompressedTexSubImage1D")) {
4795 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4799 if (compressed_subtexture_error_check(ctx
, 1, texObj
, target
,
4800 level
, xoffset
, 0, 0,
4802 format
, imageSize
, data
,
4803 "glCompressedTexSubImage1D")) {
4807 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4810 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
4811 xoffset
, 0, 0, width
, 1, 1,
4812 format
, imageSize
, data
);
4816 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4817 GLsizei width
, GLenum format
,
4818 GLsizei imageSize
, const GLvoid
*data
)
4820 struct gl_texture_object
*texObj
;
4821 struct gl_texture_image
*texImage
;
4823 GET_CURRENT_CONTEXT(ctx
);
4825 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4826 "glCompressedTextureSubImage1D");
4830 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
, true,
4831 "glCompressedTextureSubImage1D")) {
4835 if (compressed_subtexture_error_check(ctx
, 1, texObj
, texObj
->Target
,
4836 level
, xoffset
, 0, 0,
4838 format
, imageSize
, data
,
4839 "glCompressedTextureSubImage1D")) {
4843 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4846 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
,
4847 texObj
->Target
, level
,
4848 xoffset
, 0, 0, width
, 1, 1,
4849 format
, imageSize
, data
);
4854 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4855 GLint yoffset
, GLsizei width
, GLsizei height
,
4856 GLenum format
, GLsizei imageSize
,
4859 struct gl_texture_object
*texObj
;
4860 struct gl_texture_image
*texImage
;
4862 GET_CURRENT_CONTEXT(ctx
);
4864 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
4865 "glCompressedTexSubImage2D")) {
4869 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4873 if (compressed_subtexture_error_check(ctx
, 2, texObj
, target
,
4874 level
, xoffset
, yoffset
, 0,
4876 format
, imageSize
, data
,
4877 "glCompressedTexSubImage2D")) {
4882 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4885 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
4886 xoffset
, yoffset
, 0, width
, height
, 1,
4887 format
, imageSize
, data
);
4891 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
4893 GLsizei width
, GLsizei height
,
4894 GLenum format
, GLsizei imageSize
,
4897 struct gl_texture_object
*texObj
;
4898 struct gl_texture_image
*texImage
;
4900 GET_CURRENT_CONTEXT(ctx
);
4902 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4903 "glCompressedTextureSubImage2D");
4907 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
, true,
4908 "glCompressedTextureSubImage2D")) {
4912 if (compressed_subtexture_error_check(ctx
, 2, texObj
, texObj
->Target
,
4913 level
, xoffset
, yoffset
, 0,
4915 format
, imageSize
, data
,
4916 "glCompressedTextureSubImage2D")) {
4920 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4923 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
,
4924 texObj
->Target
, level
,
4925 xoffset
, yoffset
, 0, width
, height
, 1,
4926 format
, imageSize
, data
);
4930 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4931 GLint yoffset
, GLint zoffset
, GLsizei width
,
4932 GLsizei height
, GLsizei depth
, GLenum format
,
4933 GLsizei imageSize
, const GLvoid
*data
)
4935 struct gl_texture_object
*texObj
;
4936 struct gl_texture_image
*texImage
;
4938 GET_CURRENT_CONTEXT(ctx
);
4940 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
4941 "glCompressedTexSubImage3D")) {
4945 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4949 if (compressed_subtexture_error_check(ctx
, 3, texObj
, target
,
4950 level
, xoffset
, yoffset
, zoffset
,
4951 width
, height
, depth
,
4952 format
, imageSize
, data
,
4953 "glCompressedTexSubImage3D")) {
4958 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4961 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
4962 xoffset
, yoffset
, zoffset
,
4963 width
, height
, depth
,
4964 format
, imageSize
, data
);
4968 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
4969 GLint yoffset
, GLint zoffset
, GLsizei width
,
4970 GLsizei height
, GLsizei depth
,
4971 GLenum format
, GLsizei imageSize
,
4974 struct gl_texture_object
*texObj
;
4975 struct gl_texture_image
*texImage
;
4977 GET_CURRENT_CONTEXT(ctx
);
4979 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4980 "glCompressedTextureSubImage3D");
4984 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
, true,
4985 "glCompressedTextureSubImage3D")) {
4989 if (compressed_subtexture_error_check(ctx
, 3, texObj
, texObj
->Target
,
4990 level
, xoffset
, yoffset
, zoffset
,
4991 width
, height
, depth
,
4992 format
, imageSize
, data
,
4993 "glCompressedTextureSubImage3D")) {
4997 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
4998 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4999 const char *pixels
= data
;
5003 /* Make sure the texture object is a proper cube.
5004 * (See texturesubimage in teximage.c for details on why this check is
5007 if (!_mesa_cube_level_complete(texObj
, level
)) {
5008 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5009 "glCompressedTextureSubImage3D(cube map incomplete)");
5013 /* Copy in each face. */
5014 for (i
= 0; i
< 6; ++i
) {
5015 texImage
= texObj
->Image
[i
][level
];
5018 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5019 texObj
->Target
, level
,
5020 xoffset
, yoffset
, zoffset
,
5022 format
, imageSize
, pixels
);
5024 /* Compressed images don't have a client format */
5025 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5027 texImage
->Height
, 1);
5029 pixels
+= image_stride
;
5030 imageSize
-= image_stride
;
5034 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5037 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5038 texObj
->Target
, level
,
5039 xoffset
, yoffset
, zoffset
,
5040 width
, height
, depth
,
5041 format
, imageSize
, data
);
5046 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5048 if (ctx
->API
!= API_OPENGL_CORE
) {
5049 switch (internalFormat
) {
5051 return MESA_FORMAT_A_UNORM8
;
5053 return MESA_FORMAT_A_UNORM16
;
5054 case GL_ALPHA16F_ARB
:
5055 return MESA_FORMAT_A_FLOAT16
;
5056 case GL_ALPHA32F_ARB
:
5057 return MESA_FORMAT_A_FLOAT32
;
5058 case GL_ALPHA8I_EXT
:
5059 return MESA_FORMAT_A_SINT8
;
5060 case GL_ALPHA16I_EXT
:
5061 return MESA_FORMAT_A_SINT16
;
5062 case GL_ALPHA32I_EXT
:
5063 return MESA_FORMAT_A_SINT32
;
5064 case GL_ALPHA8UI_EXT
:
5065 return MESA_FORMAT_A_UINT8
;
5066 case GL_ALPHA16UI_EXT
:
5067 return MESA_FORMAT_A_UINT16
;
5068 case GL_ALPHA32UI_EXT
:
5069 return MESA_FORMAT_A_UINT32
;
5071 return MESA_FORMAT_L_UNORM8
;
5072 case GL_LUMINANCE16
:
5073 return MESA_FORMAT_L_UNORM16
;
5074 case GL_LUMINANCE16F_ARB
:
5075 return MESA_FORMAT_L_FLOAT16
;
5076 case GL_LUMINANCE32F_ARB
:
5077 return MESA_FORMAT_L_FLOAT32
;
5078 case GL_LUMINANCE8I_EXT
:
5079 return MESA_FORMAT_L_SINT8
;
5080 case GL_LUMINANCE16I_EXT
:
5081 return MESA_FORMAT_L_SINT16
;
5082 case GL_LUMINANCE32I_EXT
:
5083 return MESA_FORMAT_L_SINT32
;
5084 case GL_LUMINANCE8UI_EXT
:
5085 return MESA_FORMAT_L_UINT8
;
5086 case GL_LUMINANCE16UI_EXT
:
5087 return MESA_FORMAT_L_UINT16
;
5088 case GL_LUMINANCE32UI_EXT
:
5089 return MESA_FORMAT_L_UINT32
;
5090 case GL_LUMINANCE8_ALPHA8
:
5091 return MESA_FORMAT_L8A8_UNORM
;
5092 case GL_LUMINANCE16_ALPHA16
:
5093 return MESA_FORMAT_L16A16_UNORM
;
5094 case GL_LUMINANCE_ALPHA16F_ARB
:
5095 return MESA_FORMAT_LA_FLOAT16
;
5096 case GL_LUMINANCE_ALPHA32F_ARB
:
5097 return MESA_FORMAT_LA_FLOAT32
;
5098 case GL_LUMINANCE_ALPHA8I_EXT
:
5099 return MESA_FORMAT_LA_SINT8
;
5100 case GL_LUMINANCE_ALPHA16I_EXT
:
5101 return MESA_FORMAT_LA_SINT16
;
5102 case GL_LUMINANCE_ALPHA32I_EXT
:
5103 return MESA_FORMAT_LA_SINT32
;
5104 case GL_LUMINANCE_ALPHA8UI_EXT
:
5105 return MESA_FORMAT_LA_UINT8
;
5106 case GL_LUMINANCE_ALPHA16UI_EXT
:
5107 return MESA_FORMAT_LA_UINT16
;
5108 case GL_LUMINANCE_ALPHA32UI_EXT
:
5109 return MESA_FORMAT_LA_UINT32
;
5111 return MESA_FORMAT_I_UNORM8
;
5112 case GL_INTENSITY16
:
5113 return MESA_FORMAT_I_UNORM16
;
5114 case GL_INTENSITY16F_ARB
:
5115 return MESA_FORMAT_I_FLOAT16
;
5116 case GL_INTENSITY32F_ARB
:
5117 return MESA_FORMAT_I_FLOAT32
;
5118 case GL_INTENSITY8I_EXT
:
5119 return MESA_FORMAT_I_SINT8
;
5120 case GL_INTENSITY16I_EXT
:
5121 return MESA_FORMAT_I_SINT16
;
5122 case GL_INTENSITY32I_EXT
:
5123 return MESA_FORMAT_I_SINT32
;
5124 case GL_INTENSITY8UI_EXT
:
5125 return MESA_FORMAT_I_UINT8
;
5126 case GL_INTENSITY16UI_EXT
:
5127 return MESA_FORMAT_I_UINT16
;
5128 case GL_INTENSITY32UI_EXT
:
5129 return MESA_FORMAT_I_UINT32
;
5135 if (ctx
->API
== API_OPENGL_CORE
&&
5136 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5137 switch (internalFormat
) {
5139 return MESA_FORMAT_RGB_FLOAT32
;
5141 return MESA_FORMAT_RGB_UINT32
;
5143 return MESA_FORMAT_RGB_SINT32
;
5149 switch (internalFormat
) {
5151 return MESA_FORMAT_R8G8B8A8_UNORM
;
5153 return MESA_FORMAT_RGBA_UNORM16
;
5154 case GL_RGBA16F_ARB
:
5155 return MESA_FORMAT_RGBA_FLOAT16
;
5156 case GL_RGBA32F_ARB
:
5157 return MESA_FORMAT_RGBA_FLOAT32
;
5159 return MESA_FORMAT_RGBA_SINT8
;
5160 case GL_RGBA16I_EXT
:
5161 return MESA_FORMAT_RGBA_SINT16
;
5162 case GL_RGBA32I_EXT
:
5163 return MESA_FORMAT_RGBA_SINT32
;
5164 case GL_RGBA8UI_EXT
:
5165 return MESA_FORMAT_RGBA_UINT8
;
5166 case GL_RGBA16UI_EXT
:
5167 return MESA_FORMAT_RGBA_UINT16
;
5168 case GL_RGBA32UI_EXT
:
5169 return MESA_FORMAT_RGBA_UINT32
;
5172 return MESA_FORMAT_R8G8_UNORM
;
5174 return MESA_FORMAT_R16G16_UNORM
;
5176 return MESA_FORMAT_RG_FLOAT16
;
5178 return MESA_FORMAT_RG_FLOAT32
;
5180 return MESA_FORMAT_RG_SINT8
;
5182 return MESA_FORMAT_RG_SINT16
;
5184 return MESA_FORMAT_RG_SINT32
;
5186 return MESA_FORMAT_RG_UINT8
;
5188 return MESA_FORMAT_RG_UINT16
;
5190 return MESA_FORMAT_RG_UINT32
;
5193 return MESA_FORMAT_R_UNORM8
;
5195 return MESA_FORMAT_R_UNORM16
;
5197 return MESA_FORMAT_R_FLOAT16
;
5199 return MESA_FORMAT_R_FLOAT32
;
5201 return MESA_FORMAT_R_SINT8
;
5203 return MESA_FORMAT_R_SINT16
;
5205 return MESA_FORMAT_R_SINT32
;
5207 return MESA_FORMAT_R_UINT8
;
5209 return MESA_FORMAT_R_UINT16
;
5211 return MESA_FORMAT_R_UINT32
;
5214 return MESA_FORMAT_NONE
;
5220 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5221 GLenum internalFormat
)
5223 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5226 if (format
== MESA_FORMAT_NONE
)
5227 return MESA_FORMAT_NONE
;
5229 datatype
= _mesa_get_format_datatype(format
);
5231 /* The GL_ARB_texture_buffer_object spec says:
5233 * "If ARB_texture_float is not supported, references to the
5234 * floating-point internal formats provided by that extension should be
5235 * removed, and such formats may not be passed to TexBufferARB."
5237 * As a result, GL_HALF_FLOAT internal format depends on both
5238 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5240 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5241 !ctx
->Extensions
.ARB_texture_float
)
5242 return MESA_FORMAT_NONE
;
5244 if (!ctx
->Extensions
.ARB_texture_rg
) {
5245 GLenum base_format
= _mesa_get_format_base_format(format
);
5246 if (base_format
== GL_R
|| base_format
== GL_RG
)
5247 return MESA_FORMAT_NONE
;
5250 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5251 GLenum base_format
= _mesa_get_format_base_format(format
);
5252 if (base_format
== GL_RGB
)
5253 return MESA_FORMAT_NONE
;
5260 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5261 struct gl_texture_object
*texObj
,
5262 GLenum internalFormat
,
5263 struct gl_buffer_object
*bufObj
,
5264 GLintptr offset
, GLsizeiptr size
,
5269 /* NOTE: ARB_texture_buffer_object has interactions with
5270 * the compatibility profile that are not implemented.
5272 if (!(ctx
->API
== API_OPENGL_CORE
&&
5273 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5274 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5275 "%s(ARB_texture_buffer_object is not"
5276 " implemented for the compatibility profile)", caller
);
5280 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5281 if (format
== MESA_FORMAT_NONE
) {
5282 _mesa_error(ctx
, GL_INVALID_ENUM
,
5283 "%s(internalFormat 0x%x)", caller
, internalFormat
);
5287 FLUSH_VERTICES(ctx
, 0);
5289 _mesa_lock_texture(ctx
, texObj
);
5291 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5292 texObj
->BufferObjectFormat
= internalFormat
;
5293 texObj
->_BufferObjectFormat
= format
;
5294 texObj
->BufferOffset
= offset
;
5295 texObj
->BufferSize
= size
;
5297 _mesa_unlock_texture(ctx
, texObj
);
5299 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5302 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5308 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5309 * Return true if it is, and return false if it is not
5310 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5311 * core spec, 02.02.2015, PDF page 245).
5314 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5317 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5318 _mesa_error(ctx
, GL_INVALID_ENUM
,
5319 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5327 * Check for errors related to the texture buffer range.
5328 * Return false if errors are found, true if none are found.
5331 check_texture_buffer_range(struct gl_context
*ctx
,
5332 struct gl_buffer_object
*bufObj
,
5333 GLintptr offset
, GLsizeiptr size
,
5336 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5337 * Textures (PDF page 245):
5338 * "An INVALID_VALUE error is generated if offset is negative, if
5339 * size is less than or equal to zero, or if offset + size is greater
5340 * than the value of BUFFER_SIZE for the buffer bound to target."
5343 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5349 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5354 if (offset
+ size
> bufObj
->Size
) {
5355 _mesa_error(ctx
, GL_INVALID_VALUE
,
5356 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5357 (int) offset
, (int) size
, (int) bufObj
->Size
);
5361 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5362 * Textures (PDF page 245):
5363 * "An INVALID_VALUE error is generated if offset is not an integer
5364 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5366 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5367 _mesa_error(ctx
, GL_INVALID_VALUE
,
5368 "%s(invalid offset alignment)", caller
);
5376 /** GL_ARB_texture_buffer_object */
5378 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5380 struct gl_texture_object
*texObj
;
5381 struct gl_buffer_object
*bufObj
;
5383 GET_CURRENT_CONTEXT(ctx
);
5385 /* Need to catch a bad target before it gets to
5386 * _mesa_get_current_tex_object.
5388 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5392 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5398 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5402 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5403 buffer
? -1 : 0, "glTexBuffer");
5407 /** GL_ARB_texture_buffer_range */
5409 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5410 GLintptr offset
, GLsizeiptr size
)
5412 struct gl_texture_object
*texObj
;
5413 struct gl_buffer_object
*bufObj
;
5415 GET_CURRENT_CONTEXT(ctx
);
5417 /* Need to catch a bad target before it gets to
5418 * _mesa_get_current_tex_object.
5420 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5424 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5428 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5429 "glTexBufferRange"))
5433 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5434 * Textures (PDF page 254):
5435 * "If buffer is zero, then any buffer object attached to the buffer
5436 * texture is detached, the values offset and size are ignored and
5437 * the state for offset and size for the buffer texture are reset to
5445 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5449 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5450 offset
, size
, "glTexBufferRange");
5454 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5456 struct gl_texture_object
*texObj
;
5457 struct gl_buffer_object
*bufObj
;
5459 GET_CURRENT_CONTEXT(ctx
);
5462 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5468 /* Get the texture object by Name. */
5469 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5473 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5476 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5477 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5481 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5482 GLintptr offset
, GLsizeiptr size
)
5484 struct gl_texture_object
*texObj
;
5485 struct gl_buffer_object
*bufObj
;
5487 GET_CURRENT_CONTEXT(ctx
);
5490 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5491 "glTextureBufferRange");
5495 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5496 "glTextureBufferRange"))
5500 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5501 * Textures (PDF page 254):
5502 * "If buffer is zero, then any buffer object attached to the buffer
5503 * texture is detached, the values offset and size are ignored and
5504 * the state for offset and size for the buffer texture are reset to
5512 /* Get the texture object by Name. */
5513 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5517 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5518 "glTextureBufferRange"))
5521 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5522 bufObj
, offset
, size
, "glTextureBufferRange");
5526 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5528 /* Everything that is allowed for renderbuffers,
5529 * except for a base format of GL_STENCIL_INDEX, unless supported.
5531 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5532 if (ctx
->Extensions
.ARB_texture_stencil8
)
5533 return baseFormat
!= 0;
5535 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5539 /** GL_ARB_texture_multisample */
5541 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5544 case GL_TEXTURE_2D_MULTISAMPLE
:
5546 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5547 return dims
== 2 && !dsa
;
5548 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5550 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5551 return dims
== 3 && !dsa
;
5559 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5560 struct gl_texture_object
*texObj
,
5561 GLenum target
, GLsizei samples
,
5562 GLint internalformat
, GLsizei width
,
5563 GLsizei height
, GLsizei depth
,
5564 GLboolean fixedsamplelocations
,
5565 GLboolean immutable
, const char *func
)
5567 struct gl_texture_image
*texImage
;
5568 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5569 mesa_format texFormat
;
5570 GLenum sample_count_error
;
5571 bool dsa
= strstr(func
, "ture") ? true : false;
5573 if (!((ctx
->Extensions
.ARB_texture_multisample
5574 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5575 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5580 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5584 if (!check_multisample_target(dims
, target
, dsa
)) {
5586 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5590 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5595 /* check that the specified internalformat is color/depth/stencil-renderable;
5596 * refer GL3.1 spec 4.4.4
5599 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5600 _mesa_error(ctx
, GL_INVALID_ENUM
,
5601 "%s(internalformat=%s not legal for immutable-format)",
5602 func
, _mesa_enum_to_string(internalformat
));
5606 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5607 /* Page 172 of OpenGL ES 3.1 spec says:
5608 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5609 * color-renderable, depth-renderable, or stencil-renderable (as
5610 * defined in section 9.4).
5612 * (Same error is also defined for desktop OpenGL for multisample
5613 * teximage/texstorage functions.)
5615 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5616 _mesa_enum_to_string(internalformat
));
5620 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5621 internalformat
, samples
);
5622 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5624 /* Page 254 of OpenGL 4.4 spec says:
5625 * "Proxy arrays for two-dimensional multisample and two-dimensional
5626 * multisample array textures are operated on in the same way when
5627 * TexImage2DMultisample is called with target specified as
5628 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5629 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5630 * However, if samples is not supported, then no error is generated.
5632 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5633 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5637 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5638 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5639 "%s(texture object 0)",
5644 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5646 if (texImage
== NULL
) {
5647 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5651 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5652 internalformat
, GL_NONE
, GL_NONE
);
5653 assert(texFormat
!= MESA_FORMAT_NONE
);
5655 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5656 width
, height
, depth
, 0);
5658 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5659 width
, height
, depth
, 0);
5661 if (_mesa_is_proxy_texture(target
)) {
5662 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5663 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5664 internalformat
, texFormat
,
5665 samples
, fixedsamplelocations
);
5668 /* clear all image fields */
5669 clear_teximage_fields(texImage
);
5673 if (!dimensionsOK
) {
5674 _mesa_error(ctx
, GL_INVALID_VALUE
,
5675 "%s(invalid width or height)", func
);
5680 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5684 /* Check if texObj->Immutable is set */
5685 if (texObj
->Immutable
) {
5686 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5690 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5692 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5693 internalformat
, texFormat
,
5694 samples
, fixedsamplelocations
);
5696 if (width
> 0 && height
> 0 && depth
> 0) {
5697 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5698 width
, height
, depth
)) {
5699 /* tidy up the texture image state. strictly speaking,
5700 * we're allowed to just leave this in whatever state we
5701 * like, but being tidy is good.
5703 _mesa_init_teximage_fields(ctx
, texImage
,
5704 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5708 texObj
->Immutable
|= immutable
;
5711 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5714 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5720 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5721 GLenum internalformat
, GLsizei width
,
5722 GLsizei height
, GLboolean fixedsamplelocations
)
5724 struct gl_texture_object
*texObj
;
5725 GET_CURRENT_CONTEXT(ctx
);
5727 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5731 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5732 internalformat
, width
, height
, 1,
5733 fixedsamplelocations
, GL_FALSE
,
5734 "glTexImage2DMultisample");
5739 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5740 GLenum internalformat
, GLsizei width
,
5741 GLsizei height
, GLsizei depth
,
5742 GLboolean fixedsamplelocations
)
5744 struct gl_texture_object
*texObj
;
5745 GET_CURRENT_CONTEXT(ctx
);
5747 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5751 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5752 internalformat
, width
, height
, depth
,
5753 fixedsamplelocations
, GL_FALSE
,
5754 "glTexImage3DMultisample");
5758 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
5759 GLsizei samples
, unsigned dims
)
5761 GET_CURRENT_CONTEXT(ctx
);
5763 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
5764 _mesa_error(ctx
, GL_INVALID_VALUE
,
5765 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
5766 dims
, width
, height
, depth
);
5773 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5774 GLenum internalformat
, GLsizei width
,
5775 GLsizei height
, GLboolean fixedsamplelocations
)
5777 struct gl_texture_object
*texObj
;
5778 GET_CURRENT_CONTEXT(ctx
);
5780 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5784 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5787 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5788 internalformat
, width
, height
, 1,
5789 fixedsamplelocations
, GL_TRUE
,
5790 "glTexStorage2DMultisample");
5794 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5795 GLenum internalformat
, GLsizei width
,
5796 GLsizei height
, GLsizei depth
,
5797 GLboolean fixedsamplelocations
)
5799 struct gl_texture_object
*texObj
;
5800 GET_CURRENT_CONTEXT(ctx
);
5802 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5806 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5809 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5810 internalformat
, width
, height
, depth
,
5811 fixedsamplelocations
, GL_TRUE
,
5812 "glTexStorage3DMultisample");
5816 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5817 GLenum internalformat
, GLsizei width
,
5819 GLboolean fixedsamplelocations
)
5821 struct gl_texture_object
*texObj
;
5822 GET_CURRENT_CONTEXT(ctx
);
5824 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5825 "glTextureStorage2DMultisample");
5829 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5832 texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5833 internalformat
, width
, height
, 1,
5834 fixedsamplelocations
, GL_TRUE
,
5835 "glTextureStorage2DMultisample");
5839 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5840 GLenum internalformat
, GLsizei width
,
5841 GLsizei height
, GLsizei depth
,
5842 GLboolean fixedsamplelocations
)
5844 struct gl_texture_object
*texObj
;
5845 GET_CURRENT_CONTEXT(ctx
);
5847 /* Get the texture object by Name. */
5848 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5849 "glTextureStorage3DMultisample");
5853 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5856 texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5857 internalformat
, width
, height
, depth
,
5858 fixedsamplelocations
, GL_TRUE
,
5859 "glTextureStorage3DMultisample");