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 /* Check incoming image format and type */
2168 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2169 if (err
!= GL_NO_ERROR
) {
2170 /* Prior to OpenGL-ES 2.0, an INVALID_VALUE is expected instead of
2171 * INVALID_ENUM. From page 73 OpenGL ES 1.1 spec:
2173 * "Specifying a value for internalformat that is not one of the
2174 * above (acceptable) values generates the error INVALID VALUE."
2176 if (err
== GL_INVALID_ENUM
&& _mesa_is_gles(ctx
) && ctx
->Version
< 20)
2177 err
= GL_INVALID_VALUE
;
2179 _mesa_error(ctx
, err
,
2180 "glTexImage%dD(incompatible format = %s, type = %s)",
2181 dimensions
, _mesa_enum_to_string(format
),
2182 _mesa_enum_to_string(type
));
2186 /* Check internalFormat */
2187 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2188 _mesa_error(ctx
, GL_INVALID_VALUE
,
2189 "glTexImage%dD(internalFormat=%s)",
2190 dimensions
, _mesa_enum_to_string(internalFormat
));
2194 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2195 * combinations of format, internalFormat, and type that can be used.
2196 * Formats and types that require additional extensions (e.g., GL_FLOAT
2197 * requires GL_OES_texture_float) are filtered elsewhere.
2199 if (_mesa_is_gles(ctx
) &&
2200 texture_format_error_check_gles(ctx
, format
, type
, internalFormat
,
2201 dimensions
, "glTexImage%dD")) {
2205 /* validate the bound PBO, if any */
2206 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2207 width
, height
, depth
, format
, type
,
2208 INT_MAX
, pixels
, "glTexImage")) {
2212 /* make sure internal format and format basically agree */
2213 if (!texture_formats_agree(internalFormat
, format
)) {
2214 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2215 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2216 dimensions
, _mesa_enum_to_string(internalFormat
),
2217 _mesa_enum_to_string(format
));
2221 /* additional checks for ycbcr textures */
2222 if (internalFormat
== GL_YCBCR_MESA
) {
2223 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
2224 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2225 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2227 _mesa_snprintf(message
, sizeof(message
),
2228 "glTexImage%dD(format/type YCBCR mismatch)",
2230 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2231 return GL_TRUE
; /* error */
2233 if (target
!= GL_TEXTURE_2D
&&
2234 target
!= GL_PROXY_TEXTURE_2D
&&
2235 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2236 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2237 _mesa_error(ctx
, GL_INVALID_ENUM
,
2238 "glTexImage%dD(bad target for YCbCr texture)",
2244 _mesa_snprintf(message
, sizeof(message
),
2245 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2246 dimensions
, border
);
2247 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2252 /* additional checks for depth textures */
2253 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2254 dimensions
, "glTexImage"))
2257 /* additional checks for compressed textures */
2258 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2260 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2261 _mesa_error(ctx
, err
,
2262 "glTexImage%dD(target can't be compressed)", dimensions
);
2265 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2266 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2267 "glTexImage%dD(no compression for format)", dimensions
);
2271 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2272 "glTexImage%dD(border!=0)", dimensions
);
2277 /* additional checks for integer textures */
2278 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2279 (_mesa_is_enum_format_integer(format
) !=
2280 _mesa_is_enum_format_integer(internalFormat
))) {
2281 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2282 "glTexImage%dD(integer/non-integer format mismatch)",
2287 if (!mutable_tex_object(ctx
, target
)) {
2288 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2289 "glTexImage%dD(immutable texture)", dimensions
);
2293 /* if we get here, the parameters are OK */
2299 * Error checking for glCompressedTexImage[123]D().
2300 * Note that the width, height and depth values are not fully error checked
2302 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2305 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2306 GLenum target
, GLint level
,
2307 GLenum internalFormat
, GLsizei width
,
2308 GLsizei height
, GLsizei depth
, GLint border
,
2309 GLsizei imageSize
, const GLvoid
*data
)
2311 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2313 GLenum error
= GL_NO_ERROR
;
2314 char *reason
= ""; /* no error */
2316 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
2321 /* This will detect any invalid internalFormat value */
2322 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2323 _mesa_error(ctx
, GL_INVALID_ENUM
,
2324 "glCompressedTexImage%dD(internalFormat=%s)",
2325 dimensions
, _mesa_enum_to_string(internalFormat
));
2329 /* validate the bound PBO, if any */
2330 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2332 "glCompressedTexImage")) {
2336 switch (internalFormat
) {
2337 case GL_PALETTE4_RGB8_OES
:
2338 case GL_PALETTE4_RGBA8_OES
:
2339 case GL_PALETTE4_R5_G6_B5_OES
:
2340 case GL_PALETTE4_RGBA4_OES
:
2341 case GL_PALETTE4_RGB5_A1_OES
:
2342 case GL_PALETTE8_RGB8_OES
:
2343 case GL_PALETTE8_RGBA8_OES
:
2344 case GL_PALETTE8_R5_G6_B5_OES
:
2345 case GL_PALETTE8_RGBA4_OES
:
2346 case GL_PALETTE8_RGB5_A1_OES
:
2347 /* check level (note that level should be zero or less!) */
2348 if (level
> 0 || level
< -maxLevels
) {
2350 error
= GL_INVALID_VALUE
;
2354 if (dimensions
!= 2) {
2355 reason
= "compressed paletted textures must be 2D";
2356 error
= GL_INVALID_OPERATION
;
2360 /* Figure out the expected texture size (in bytes). This will be
2361 * checked against the actual size later.
2363 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2366 /* This is for the benefit of the TestProxyTexImage below. It expects
2367 * level to be non-negative. OES_compressed_paletted_texture uses a
2368 * weird mechanism where the level specified to glCompressedTexImage2D
2369 * is -(n-1) number of levels in the texture, and the data specifies the
2370 * complete mipmap stack. This is done to ensure the palette is the
2371 * same for all levels.
2378 if (level
< 0 || level
>= maxLevels
) {
2380 error
= GL_INVALID_VALUE
;
2384 /* Figure out the expected texture size (in bytes). This will be
2385 * checked against the actual size later.
2387 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2391 /* This should really never fail */
2392 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2393 reason
= "internalFormat";
2394 error
= GL_INVALID_ENUM
;
2398 /* No compressed formats support borders at this time */
2400 reason
= "border != 0";
2401 error
= GL_INVALID_VALUE
;
2405 /* Check for invalid pixel storage modes */
2406 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2408 "glCompressedTexImage")) {
2412 /* check image size in bytes */
2413 if (expectedSize
!= imageSize
) {
2414 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2415 * if <imageSize> is not consistent with the format, dimensions, and
2416 * contents of the specified image.
2418 reason
= "imageSize inconsistant with width/height/format";
2419 error
= GL_INVALID_VALUE
;
2423 if (!mutable_tex_object(ctx
, target
)) {
2424 reason
= "immutable texture";
2425 error
= GL_INVALID_OPERATION
;
2432 /* Note: not all error paths exit through here. */
2433 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2434 dimensions
, reason
);
2441 * Test glTexSubImage[123]D() parameters for errors.
2443 * \param ctx GL context.
2444 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2445 * \param target texture target given by the user (already validated)
2446 * \param level image level given by the user.
2447 * \param xoffset sub-image x offset given by the user.
2448 * \param yoffset sub-image y offset given by the user.
2449 * \param zoffset sub-image z offset given by the user.
2450 * \param format pixel data format given by the user.
2451 * \param type pixel data type given by the user.
2452 * \param width image width given by the user.
2453 * \param height image height given by the user.
2454 * \param depth image depth given by the user.
2456 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2458 * Verifies each of the parameters against the constants specified in
2459 * __struct gl_contextRec::Const and the supported extensions, and according
2460 * to the OpenGL specification.
2463 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2464 struct gl_texture_object
*texObj
,
2465 GLenum target
, GLint level
,
2466 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2467 GLint width
, GLint height
, GLint depth
,
2468 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2469 bool dsa
, const char *callerName
)
2471 struct gl_texture_image
*texImage
;
2475 /* must be out of memory */
2476 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2481 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2482 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2486 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2488 /* non-existant texture level */
2489 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture image)",
2494 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2495 if (err
!= GL_NO_ERROR
) {
2496 _mesa_error(ctx
, err
,
2497 "%s(incompatible format = %s, type = %s)",
2498 callerName
, _mesa_enum_to_string(format
),
2499 _mesa_enum_to_string(type
));
2503 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2504 * combinations of format, internalFormat, and type that can be used.
2505 * Formats and types that require additional extensions (e.g., GL_FLOAT
2506 * requires GL_OES_texture_float) are filtered elsewhere.
2508 if (_mesa_is_gles(ctx
) &&
2509 texture_format_error_check_gles(ctx
, format
, type
,
2510 texImage
->InternalFormat
,
2511 dimensions
, callerName
)) {
2515 /* validate the bound PBO, if any */
2516 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2517 width
, height
, depth
, format
, type
,
2518 INT_MAX
, pixels
, callerName
)) {
2522 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2523 texImage
, xoffset
, yoffset
, zoffset
,
2524 width
, height
, depth
, callerName
)) {
2528 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2529 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2530 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2531 "%s(no compression for format)", callerName
);
2536 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2537 /* both source and dest must be integer-valued, or neither */
2538 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2539 _mesa_is_enum_format_integer(format
)) {
2540 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2541 "%s(integer/non-integer format mismatch)", callerName
);
2551 * Test glCopyTexImage[12]D() parameters for errors.
2553 * \param ctx GL context.
2554 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2555 * \param target texture target given by the user.
2556 * \param level image level given by the user.
2557 * \param internalFormat internal format given by the user.
2558 * \param width image width given by the user.
2559 * \param height image height given by the user.
2560 * \param border texture border.
2562 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2564 * Verifies each of the parameters against the constants specified in
2565 * __struct gl_contextRec::Const and the supported extensions, and according
2566 * to the OpenGL specification.
2569 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2570 GLenum target
, GLint level
, GLint internalFormat
,
2571 GLint width
, GLint height
, GLint border
)
2574 GLint rb_base_format
;
2575 struct gl_renderbuffer
*rb
;
2576 GLenum rb_internal_format
;
2579 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2580 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2581 dimensions
, _mesa_enum_to_string(target
));
2586 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2587 _mesa_error(ctx
, GL_INVALID_VALUE
,
2588 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2592 /* Check that the source buffer is complete */
2593 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2594 if (ctx
->ReadBuffer
->_Status
== 0) {
2595 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2597 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2598 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2599 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2603 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2604 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2605 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2611 if (border
< 0 || border
> 1 ||
2612 ((ctx
->API
!= API_OPENGL_COMPAT
||
2613 target
== GL_TEXTURE_RECTANGLE_NV
||
2614 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2615 _mesa_error(ctx
, GL_INVALID_VALUE
,
2616 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2620 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2623 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2624 switch (internalFormat
) {
2629 case GL_LUMINANCE_ALPHA
:
2632 _mesa_error(ctx
, GL_INVALID_ENUM
,
2633 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2634 _mesa_enum_to_string(internalFormat
));
2639 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2640 if (baseFormat
< 0) {
2641 _mesa_error(ctx
, GL_INVALID_ENUM
,
2642 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2643 _mesa_enum_to_string(internalFormat
));
2647 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2649 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2650 "glCopyTexImage%dD(read buffer)", dimensions
);
2654 rb_internal_format
= rb
->InternalFormat
;
2655 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2656 if (_mesa_is_color_format(internalFormat
)) {
2657 if (rb_base_format
< 0) {
2658 _mesa_error(ctx
, GL_INVALID_VALUE
,
2659 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2660 _mesa_enum_to_string(internalFormat
));
2665 if (_mesa_is_gles(ctx
)) {
2667 if (_mesa_base_format_component_count(baseFormat
) >
2668 _mesa_base_format_component_count(rb_base_format
)) {
2671 if (baseFormat
== GL_DEPTH_COMPONENT
||
2672 baseFormat
== GL_DEPTH_STENCIL
||
2673 rb_base_format
== GL_DEPTH_COMPONENT
||
2674 rb_base_format
== GL_DEPTH_STENCIL
||
2675 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2676 baseFormat
== GL_ALPHA
) &&
2677 rb_base_format
!= GL_RGBA
) ||
2678 internalFormat
== GL_RGB9_E5
) {
2681 if (internalFormat
== GL_RGB9_E5
) {
2685 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2686 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2687 _mesa_enum_to_string(internalFormat
));
2692 if (_mesa_is_gles3(ctx
)) {
2693 bool rb_is_srgb
= false;
2694 bool dst_is_srgb
= false;
2696 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2697 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2701 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2705 if (rb_is_srgb
!= dst_is_srgb
) {
2706 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2707 * OpenGLES 3.0.0 spec says:
2709 * "The error INVALID_OPERATION is also generated if the
2710 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2711 * framebuffer attachment corresponding to the read buffer
2712 * is LINEAR (see section 6.1.13) and internalformat is
2713 * one of the sRGB formats described in section 3.8.16, or
2714 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2715 * SRGB and internalformat is not one of the sRGB formats."
2717 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2718 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2722 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2723 * types for SNORM formats. Also, conversion to SNORM formats is not
2724 * allowed by Table 3.2 on Page 110.
2726 if (_mesa_is_enum_format_snorm(internalFormat
)) {
2727 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2728 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2729 _mesa_enum_to_string(internalFormat
));
2734 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2735 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2736 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2740 /* From the EXT_texture_integer spec:
2742 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2743 * if the texture internalformat is an integer format and the read color
2744 * buffer is not an integer format, or if the internalformat is not an
2745 * integer format and the read color buffer is an integer format."
2747 if (_mesa_is_color_format(internalFormat
)) {
2748 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2749 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2750 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2751 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2752 if (is_int
|| is_rbint
) {
2753 if (is_int
!= is_rbint
) {
2754 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2755 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2757 } else if (_mesa_is_gles(ctx
) &&
2758 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2759 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2760 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2761 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2766 /* From page 138 of OpenGL ES 3.0 spec:
2767 * "The error INVALID_OPERATION is generated if floating-point RGBA
2768 * data is required; if signed integer RGBA data is required and the
2769 * format of the current color buffer is not signed integer; if
2770 * unsigned integer RGBA data is required and the format of the
2771 * current color buffer is not unsigned integer; or if fixed-point
2772 * RGBA data is required and the format of the current color buffer
2773 * is not fixed-point.
2775 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2776 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2777 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2780 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2782 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2783 _mesa_error(ctx
, err
,
2784 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2787 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2788 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2789 "glCopyTexImage%dD(no compression for format)", dimensions
);
2793 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2794 "glCopyTexImage%dD(border!=0)", dimensions
);
2799 if (!mutable_tex_object(ctx
, target
)) {
2800 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2801 "glCopyTexImage%dD(immutable texture)", dimensions
);
2805 /* if we get here, the parameters are OK */
2811 * Test glCopyTexSubImage[12]D() parameters for errors.
2812 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2815 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2816 const struct gl_texture_object
*texObj
,
2817 GLenum target
, GLint level
,
2818 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2819 GLint width
, GLint height
, const char *caller
)
2821 struct gl_texture_image
*texImage
;
2823 /* Check that the source buffer is complete */
2824 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2825 if (ctx
->ReadBuffer
->_Status
== 0) {
2826 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2828 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2829 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2830 "%s(invalid readbuffer)", caller
);
2834 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2835 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2836 "%s(multisample FBO)", caller
);
2842 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2843 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2847 /* Get dest image pointers */
2849 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", caller
);
2853 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2855 /* destination image does not exist */
2856 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2857 "%s(invalid texture image)", caller
);
2861 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2862 xoffset
, yoffset
, zoffset
,
2863 width
, height
, 1, caller
)) {
2867 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2868 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2869 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2870 "%s(no compression for format)", caller
);
2875 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2876 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2880 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2881 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2882 "%s(missing readbuffer, format=0x%x)", caller
,
2883 texImage
->_BaseFormat
);
2887 /* From the EXT_texture_integer spec:
2889 * "INVALID_OPERATION is generated by CopyTexImage* and
2890 * CopyTexSubImage* if the texture internalformat is an integer format
2891 * and the read color buffer is not an integer format, or if the
2892 * internalformat is not an integer format and the read color buffer
2893 * is an integer format."
2895 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2896 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2898 if (_mesa_is_format_integer_color(rb
->Format
) !=
2899 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2900 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2901 "%s(integer vs non-integer)", caller
);
2906 /* if we get here, the parameters are OK */
2911 /** Callback info for walking over FBO hash table */
2914 struct gl_context
*ctx
;
2915 struct gl_texture_object
*texObj
;
2921 * Check render to texture callback. Called from _mesa_HashWalk().
2924 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2926 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2927 const struct cb_info
*info
= (struct cb_info
*) userData
;
2928 struct gl_context
*ctx
= info
->ctx
;
2929 const struct gl_texture_object
*texObj
= info
->texObj
;
2930 const GLuint level
= info
->level
, face
= info
->face
;
2932 /* If this is a user-created FBO */
2933 if (_mesa_is_user_fbo(fb
)) {
2935 /* check if any of the FBO's attachments point to 'texObj' */
2936 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2937 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2938 if (att
->Type
== GL_TEXTURE
&&
2939 att
->Texture
== texObj
&&
2940 att
->TextureLevel
== level
&&
2941 att
->CubeMapFace
== face
) {
2942 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2943 assert(att
->Renderbuffer
->TexImage
);
2944 /* Mark fb status as indeterminate to force re-validation */
2953 * When a texture image is specified we have to check if it's bound to
2954 * any framebuffer objects (render to texture) in order to detect changes
2955 * in size or format since that effects FBO completeness.
2956 * Any FBOs rendering into the texture must be re-validated.
2959 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2960 struct gl_texture_object
*texObj
,
2961 GLuint face
, GLuint level
)
2963 /* Only check this texture if it's been marked as RenderToTexture */
2964 if (texObj
->_RenderToTexture
) {
2965 struct cb_info info
;
2967 info
.texObj
= texObj
;
2970 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2976 * If the texture object's GenerateMipmap flag is set and we've
2977 * changed the texture base level image, regenerate the rest of the
2978 * mipmap levels now.
2981 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2982 struct gl_texture_object
*texObj
, GLint level
)
2984 if (texObj
->GenerateMipmap
&&
2985 level
== texObj
->BaseLevel
&&
2986 level
< texObj
->MaxLevel
) {
2987 assert(ctx
->Driver
.GenerateMipmap
);
2988 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2993 /** Debug helper: override the user-requested internal format */
2995 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2998 if (internalFormat
== GL_RGBA16F_ARB
||
2999 internalFormat
== GL_RGBA32F_ARB
) {
3000 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3003 else if (internalFormat
== GL_RGB16F_ARB
||
3004 internalFormat
== GL_RGB32F_ARB
) {
3005 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3008 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3009 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3010 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3011 return GL_LUMINANCE_ALPHA
;
3013 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3014 internalFormat
== GL_LUMINANCE32F_ARB
) {
3015 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3016 return GL_LUMINANCE
;
3018 else if (internalFormat
== GL_ALPHA16F_ARB
||
3019 internalFormat
== GL_ALPHA32F_ARB
) {
3020 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3024 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3025 internalFormat = GL_RGBA;
3029 return internalFormat
;
3032 return internalFormat
;
3038 * Choose the actual hardware format for a texture image.
3039 * Try to use the same format as the previous image level when possible.
3040 * Otherwise, ask the driver for the best format.
3041 * It's important to try to choose a consistant format for all levels
3042 * for efficient texture memory layout/allocation. In particular, this
3043 * comes up during automatic mipmap generation.
3046 _mesa_choose_texture_format(struct gl_context
*ctx
,
3047 struct gl_texture_object
*texObj
,
3048 GLenum target
, GLint level
,
3049 GLenum internalFormat
, GLenum format
, GLenum type
)
3053 /* see if we've already chosen a format for the previous level */
3055 struct gl_texture_image
*prevImage
=
3056 _mesa_select_tex_image(texObj
, target
, level
- 1);
3057 /* See if the prev level is defined and has an internal format which
3058 * matches the new internal format.
3061 prevImage
->Width
> 0 &&
3062 prevImage
->InternalFormat
== internalFormat
) {
3063 /* use the same format */
3064 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3065 return prevImage
->TexFormat
;
3069 /* If the application requested compression to an S3TC format but we don't
3070 * have the DXTn library, force a generic compressed format instead.
3072 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3073 const GLenum before
= internalFormat
;
3075 switch (internalFormat
) {
3076 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3077 if (!ctx
->Mesa_DXTn
)
3078 internalFormat
= GL_COMPRESSED_RGB
;
3080 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3081 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3082 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3083 if (!ctx
->Mesa_DXTn
)
3084 internalFormat
= GL_COMPRESSED_RGBA
;
3090 if (before
!= internalFormat
) {
3092 "DXT compression requested (%s), "
3093 "but libtxc_dxtn library not installed. Using %s "
3095 _mesa_enum_to_string(before
),
3096 _mesa_enum_to_string(internalFormat
));
3100 /* choose format from scratch */
3101 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3103 assert(f
!= MESA_FORMAT_NONE
);
3109 * Adjust pixel unpack params and image dimensions to strip off the
3110 * one-pixel texture border.
3112 * Gallium and intel don't support texture borders. They've seldem been used
3113 * and seldom been implemented correctly anyway.
3115 * \param unpackNew returns the new pixel unpack parameters
3118 strip_texture_border(GLenum target
,
3119 GLint
*width
, GLint
*height
, GLint
*depth
,
3120 const struct gl_pixelstore_attrib
*unpack
,
3121 struct gl_pixelstore_attrib
*unpackNew
)
3127 *unpackNew
= *unpack
;
3129 if (unpackNew
->RowLength
== 0)
3130 unpackNew
->RowLength
= *width
;
3132 if (unpackNew
->ImageHeight
== 0)
3133 unpackNew
->ImageHeight
= *height
;
3135 assert(*width
>= 3);
3136 unpackNew
->SkipPixels
++; /* skip the border */
3137 *width
= *width
- 2; /* reduce the width by two border pixels */
3139 /* The min height of a texture with a border is 3 */
3140 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3141 unpackNew
->SkipRows
++; /* skip the border */
3142 *height
= *height
- 2; /* reduce the height by two border pixels */
3146 target
!= GL_TEXTURE_2D_ARRAY
&&
3147 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3148 unpackNew
->SkipImages
++; /* skip the border */
3149 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3155 * Common code to implement all the glTexImage1D/2D/3D functions
3156 * as well as glCompressedTexImage1D/2D/3D.
3157 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3158 * \param format the user's image format (only used if !compressed)
3159 * \param type the user's image type (only used if !compressed)
3160 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3163 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3164 GLenum target
, GLint level
, GLint internalFormat
,
3165 GLsizei width
, GLsizei height
, GLsizei depth
,
3166 GLint border
, GLenum format
, GLenum type
,
3167 GLsizei imageSize
, const GLvoid
*pixels
)
3169 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3170 struct gl_pixelstore_attrib unpack_no_border
;
3171 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3172 struct gl_texture_object
*texObj
;
3173 mesa_format texFormat
;
3174 GLboolean dimensionsOK
, sizeOK
;
3176 FLUSH_VERTICES(ctx
, 0);
3178 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3181 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3183 _mesa_enum_to_string(target
), level
,
3184 _mesa_enum_to_string(internalFormat
),
3185 width
, height
, depth
, border
, pixels
);
3188 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3190 _mesa_enum_to_string(target
), level
,
3191 _mesa_enum_to_string(internalFormat
),
3192 width
, height
, depth
, border
,
3193 _mesa_enum_to_string(format
),
3194 _mesa_enum_to_string(type
), pixels
);
3197 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3199 /* target error checking */
3200 if (!legal_teximage_target(ctx
, dims
, target
)) {
3201 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3202 func
, dims
, _mesa_enum_to_string(target
));
3206 /* general error checking */
3208 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3210 width
, height
, depth
,
3211 border
, imageSize
, pixels
))
3215 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3216 format
, type
, width
, height
, depth
, border
,
3221 /* Here we convert a cpal compressed image into a regular glTexImage2D
3222 * call by decompressing the texture. If we really want to support cpal
3223 * textures in any driver this would have to be changed.
3225 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3226 switch (internalFormat
) {
3227 case GL_PALETTE4_RGB8_OES
:
3228 case GL_PALETTE4_RGBA8_OES
:
3229 case GL_PALETTE4_R5_G6_B5_OES
:
3230 case GL_PALETTE4_RGBA4_OES
:
3231 case GL_PALETTE4_RGB5_A1_OES
:
3232 case GL_PALETTE8_RGB8_OES
:
3233 case GL_PALETTE8_RGBA8_OES
:
3234 case GL_PALETTE8_R5_G6_B5_OES
:
3235 case GL_PALETTE8_RGBA4_OES
:
3236 case GL_PALETTE8_RGB5_A1_OES
:
3237 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3238 width
, height
, imageSize
, pixels
);
3243 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3247 /* For glCompressedTexImage() the driver has no choice about the
3248 * texture format since we'll never transcode the user's compressed
3249 * image data. The internalFormat was error checked earlier.
3251 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3254 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3255 * internal floating point format for the given base format.
3257 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3258 if (type
== GL_FLOAT
) {
3259 texObj
->_IsFloat
= GL_TRUE
;
3260 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3261 texObj
->_IsHalfFloat
= GL_TRUE
;
3264 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3267 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3268 internalFormat
, format
, type
);
3271 assert(texFormat
!= MESA_FORMAT_NONE
);
3273 /* check that width, height, depth are legal for the mipmap level */
3274 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3275 height
, depth
, border
);
3277 /* check that the texture won't take too much memory, etc */
3278 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3280 width
, height
, depth
, border
);
3282 if (_mesa_is_proxy_texture(target
)) {
3283 /* Proxy texture: just clear or set state depending on error checking */
3284 struct gl_texture_image
*texImage
=
3285 get_proxy_tex_image(ctx
, target
, level
);
3288 return; /* GL_OUT_OF_MEMORY already recorded */
3290 if (dimensionsOK
&& sizeOK
) {
3291 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3292 border
, internalFormat
, texFormat
);
3295 clear_teximage_fields(texImage
);
3299 /* non-proxy target */
3300 const GLuint face
= _mesa_tex_target_to_face(target
);
3301 struct gl_texture_image
*texImage
;
3303 if (!dimensionsOK
) {
3304 _mesa_error(ctx
, GL_INVALID_VALUE
,
3305 "%s%uD(invalid width or height or depth)",
3311 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3312 "%s%uD(image too large: %d x %d x %d, %s format)",
3313 func
, dims
, width
, height
, depth
,
3314 _mesa_enum_to_string(internalFormat
));
3318 /* Allow a hardware driver to just strip out the border, to provide
3319 * reliable but slightly incorrect hardware rendering instead of
3320 * rarely-tested software fallback rendering.
3322 if (border
&& ctx
->Const
.StripTextureBorder
) {
3323 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3326 unpack
= &unpack_no_border
;
3329 if (ctx
->NewState
& _NEW_PIXEL
)
3330 _mesa_update_state(ctx
);
3332 _mesa_lock_texture(ctx
, texObj
);
3334 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3337 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3340 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3342 _mesa_init_teximage_fields(ctx
, texImage
,
3343 width
, height
, depth
,
3344 border
, internalFormat
, texFormat
);
3346 /* Give the texture to the driver. <pixels> may be null. */
3347 if (width
> 0 && height
> 0 && depth
> 0) {
3349 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3353 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3354 type
, pixels
, unpack
);
3358 check_gen_mipmap(ctx
, target
, texObj
, level
);
3360 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3362 _mesa_dirty_texobj(ctx
, texObj
);
3365 _mesa_unlock_texture(ctx
, texObj
);
3372 * Called from the API. Note that width includes the border.
3375 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3376 GLsizei width
, GLint border
, GLenum format
,
3377 GLenum type
, const GLvoid
*pixels
)
3379 GET_CURRENT_CONTEXT(ctx
);
3380 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3381 border
, format
, type
, 0, pixels
);
3386 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3387 GLsizei width
, GLsizei height
, GLint border
,
3388 GLenum format
, GLenum type
,
3389 const GLvoid
*pixels
)
3391 GET_CURRENT_CONTEXT(ctx
);
3392 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3393 border
, format
, type
, 0, pixels
);
3398 * Called by the API or display list executor.
3399 * Note that width and height include the border.
3402 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3403 GLsizei width
, GLsizei height
, GLsizei depth
,
3404 GLint border
, GLenum format
, GLenum type
,
3405 const GLvoid
*pixels
)
3407 GET_CURRENT_CONTEXT(ctx
);
3408 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3409 width
, height
, depth
,
3410 border
, format
, type
, 0, pixels
);
3415 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3416 GLsizei width
, GLsizei height
, GLsizei depth
,
3417 GLint border
, GLenum format
, GLenum type
,
3418 const GLvoid
*pixels
)
3420 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3421 depth
, border
, format
, type
, pixels
);
3426 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3428 struct gl_texture_object
*texObj
;
3429 struct gl_texture_image
*texImage
;
3431 GET_CURRENT_CONTEXT(ctx
);
3432 FLUSH_VERTICES(ctx
, 0);
3436 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3438 case GL_TEXTURE_EXTERNAL_OES
:
3440 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3443 valid_target
= false;
3447 if (!valid_target
) {
3448 _mesa_error(ctx
, GL_INVALID_ENUM
,
3449 "glEGLImageTargetTexture2D(target=%d)", target
);
3454 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3455 "glEGLImageTargetTexture2D(image=%p)", image
);
3459 if (ctx
->NewState
& _NEW_PIXEL
)
3460 _mesa_update_state(ctx
);
3462 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3466 _mesa_lock_texture(ctx
, texObj
);
3468 if (texObj
->Immutable
) {
3469 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3470 "glEGLImageTargetTexture2D(texture is immutable)");
3471 _mesa_unlock_texture(ctx
, texObj
);
3475 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3477 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3479 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3481 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3482 texObj
, texImage
, image
);
3484 _mesa_dirty_texobj(ctx
, texObj
);
3486 _mesa_unlock_texture(ctx
, texObj
);
3491 * Helper that implements the glTexSubImage1/2/3D()
3492 * and glTextureSubImage1/2/3D() functions.
3495 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3496 struct gl_texture_object
*texObj
,
3497 struct gl_texture_image
*texImage
,
3498 GLenum target
, GLint level
,
3499 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3500 GLsizei width
, GLsizei height
, GLsizei depth
,
3501 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3504 FLUSH_VERTICES(ctx
, 0);
3506 if (ctx
->NewState
& _NEW_PIXEL
)
3507 _mesa_update_state(ctx
);
3509 _mesa_lock_texture(ctx
, texObj
);
3511 if (width
> 0 && height
> 0 && depth
> 0) {
3512 /* If we have a border, offset=-1 is legal. Bias by border width. */
3515 if (target
!= GL_TEXTURE_2D_ARRAY
)
3516 zoffset
+= texImage
->Border
;
3519 if (target
!= GL_TEXTURE_1D_ARRAY
)
3520 yoffset
+= texImage
->Border
;
3523 xoffset
+= texImage
->Border
;
3526 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3527 xoffset
, yoffset
, zoffset
,
3528 width
, height
, depth
,
3529 format
, type
, pixels
, &ctx
->Unpack
);
3531 check_gen_mipmap(ctx
, target
, texObj
, level
);
3533 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3534 * the texel data, not the texture format, size, etc.
3538 _mesa_unlock_texture(ctx
, texObj
);
3542 * Implement all the glTexSubImage1/2/3D() functions.
3543 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3546 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3547 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3548 GLsizei width
, GLsizei height
, GLsizei depth
,
3549 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3550 const char *callerName
)
3552 struct gl_texture_object
*texObj
;
3553 struct gl_texture_image
*texImage
;
3555 /* check target (proxies not allowed) */
3556 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3557 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3558 dims
, _mesa_enum_to_string(target
));
3562 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3566 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3567 xoffset
, yoffset
, zoffset
,
3568 width
, height
, depth
, format
, type
,
3569 pixels
, false, callerName
)) {
3570 return; /* error was detected */
3573 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3574 /* texsubimage_error_check ensures that texImage is not NULL */
3576 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3577 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3579 _mesa_enum_to_string(target
), level
,
3580 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3581 _mesa_enum_to_string(format
),
3582 _mesa_enum_to_string(type
), pixels
);
3584 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3585 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3586 format
, type
, pixels
, false);
3591 * Implement all the glTextureSubImage1/2/3D() functions.
3592 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3595 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3596 GLuint texture
, GLint level
,
3597 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3598 GLsizei width
, GLsizei height
, GLsizei depth
,
3599 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3600 const char *callerName
)
3602 struct gl_texture_object
*texObj
;
3603 struct gl_texture_image
*texImage
;
3606 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3608 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3609 dims
, texture
, level
,
3610 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3611 _mesa_enum_to_string(format
),
3612 _mesa_enum_to_string(type
), pixels
);
3614 /* Get the texture object by Name. */
3615 texObj
= _mesa_lookup_texture(ctx
, texture
);
3617 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3622 /* check target (proxies not allowed) */
3623 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3624 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3625 callerName
, _mesa_enum_to_string(texObj
->Target
));
3629 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3630 xoffset
, yoffset
, zoffset
,
3631 width
, height
, depth
, format
, type
,
3632 pixels
, true, callerName
)) {
3633 return; /* error was detected */
3637 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3638 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3642 * What do we do if the user created a texture with the following code
3643 * and then called this function with its handle?
3646 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3647 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3648 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3649 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3650 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3651 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3652 * // wrong format, or given the wrong size, etc.
3653 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3654 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3656 * A bug has been filed against the spec for this case. In the
3657 * meantime, we will check for cube completeness.
3659 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3660 * Core Profile spec (30.10.2014):
3661 * "[A] cube map texture is cube complete if the
3662 * following conditions all hold true: The [base level] texture
3663 * images of each of the six cube map faces have identical, positive,
3664 * and square dimensions. The [base level] images were each specified
3665 * with the same internal format."
3667 * It seems reasonable to check for cube completeness of an arbitrary
3668 * level here so that the image data has a consistent format and size.
3670 if (!_mesa_cube_level_complete(texObj
, level
)) {
3671 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3672 "glTextureSubImage%uD(cube map incomplete)",
3677 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3679 /* Copy in each face. */
3680 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3681 texImage
= texObj
->Image
[i
][level
];
3684 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3685 level
, xoffset
, yoffset
, 0,
3686 width
, height
, 1, format
,
3687 type
, pixels
, true);
3688 pixels
= (GLubyte
*) pixels
+ imageStride
;
3692 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3695 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3696 level
, xoffset
, yoffset
, zoffset
,
3697 width
, height
, depth
, format
,
3698 type
, pixels
, true);
3704 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3705 GLint xoffset
, GLsizei width
,
3706 GLenum format
, GLenum type
,
3707 const GLvoid
*pixels
)
3709 GET_CURRENT_CONTEXT(ctx
);
3710 texsubimage(ctx
, 1, target
, level
,
3713 format
, type
, pixels
, "glTexSubImage1D");
3718 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3719 GLint xoffset
, GLint yoffset
,
3720 GLsizei width
, GLsizei height
,
3721 GLenum format
, GLenum type
,
3722 const GLvoid
*pixels
)
3724 GET_CURRENT_CONTEXT(ctx
);
3725 texsubimage(ctx
, 2, target
, level
,
3726 xoffset
, yoffset
, 0,
3728 format
, type
, pixels
, "glTexSubImage2D");
3734 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3735 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3736 GLsizei width
, GLsizei height
, GLsizei depth
,
3737 GLenum format
, GLenum type
,
3738 const GLvoid
*pixels
)
3740 GET_CURRENT_CONTEXT(ctx
);
3741 texsubimage(ctx
, 3, target
, level
,
3742 xoffset
, yoffset
, zoffset
,
3743 width
, height
, depth
,
3744 format
, type
, pixels
, "glTexSubImage3D");
3748 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3749 GLint xoffset
, GLsizei width
,
3750 GLenum format
, GLenum type
,
3751 const GLvoid
*pixels
)
3753 GET_CURRENT_CONTEXT(ctx
);
3754 texturesubimage(ctx
, 1, texture
, level
,
3757 format
, type
, pixels
, "glTextureSubImage1D");
3762 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3763 GLint xoffset
, GLint yoffset
,
3764 GLsizei width
, GLsizei height
,
3765 GLenum format
, GLenum type
,
3766 const GLvoid
*pixels
)
3768 GET_CURRENT_CONTEXT(ctx
);
3769 texturesubimage(ctx
, 2, texture
, level
,
3770 xoffset
, yoffset
, 0,
3772 format
, type
, pixels
, "glTextureSubImage2D");
3777 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3778 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3779 GLsizei width
, GLsizei height
, GLsizei depth
,
3780 GLenum format
, GLenum type
,
3781 const GLvoid
*pixels
)
3783 GET_CURRENT_CONTEXT(ctx
);
3784 texturesubimage(ctx
, 3, texture
, level
,
3785 xoffset
, yoffset
, zoffset
,
3786 width
, height
, depth
,
3787 format
, type
, pixels
, "glTextureSubImage3D");
3792 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3793 * from. This depends on whether the texture contains color or depth values.
3795 static struct gl_renderbuffer
*
3796 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3798 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3799 /* reading from depth/stencil buffer */
3800 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3803 /* copying from color buffer */
3804 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3809 copytexsubimage_by_slice(struct gl_context
*ctx
,
3810 struct gl_texture_image
*texImage
,
3812 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3813 struct gl_renderbuffer
*rb
,
3815 GLsizei width
, GLsizei height
)
3817 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3820 /* For 1D arrays, we copy each scanline of the source rectangle into the
3823 assert(zoffset
== 0);
3825 for (slice
= 0; slice
< height
; slice
++) {
3826 assert(yoffset
+ slice
< texImage
->Height
);
3827 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3828 xoffset
, 0, yoffset
+ slice
,
3829 rb
, x
, y
+ slice
, width
, 1);
3832 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3833 xoffset
, yoffset
, zoffset
,
3834 rb
, x
, y
, width
, height
);
3839 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3841 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3842 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3843 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3844 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3846 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3847 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3848 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3849 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3851 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3852 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3853 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3854 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3861 * Implement the glCopyTexImage1/2D() functions.
3864 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3865 GLenum target
, GLint level
, GLenum internalFormat
,
3866 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3868 struct gl_texture_object
*texObj
;
3869 struct gl_texture_image
*texImage
;
3870 const GLuint face
= _mesa_tex_target_to_face(target
);
3871 mesa_format texFormat
;
3872 struct gl_renderbuffer
*rb
;
3874 FLUSH_VERTICES(ctx
, 0);
3876 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3877 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3879 _mesa_enum_to_string(target
), level
,
3880 _mesa_enum_to_string(internalFormat
),
3881 x
, y
, width
, height
, border
);
3883 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3884 _mesa_update_state(ctx
);
3886 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3887 width
, height
, border
))
3890 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3892 _mesa_error(ctx
, GL_INVALID_VALUE
,
3893 "glCopyTexImage%uD(invalid width or height)", dims
);
3897 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3900 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3901 internalFormat
, GL_NONE
, GL_NONE
);
3903 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3905 if (_mesa_is_gles3(ctx
)) {
3906 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3907 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3908 * OpenGL ES 3.0. Khronos bug# 9807.
3910 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3911 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3912 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
3913 " and writing to unsized internal format)", dims
);
3917 /* From Page 139 of OpenGL ES 3.0 spec:
3918 * "If internalformat is sized, the internal format of the new texel
3919 * array is internalformat, and this is also the new texel array’s
3920 * effective internal format. If the component sizes of internalformat
3921 * do not exactly match the corresponding component sizes of the source
3922 * buffer’s effective internal format, described below, an
3923 * INVALID_OPERATION error is generated. If internalformat is unsized,
3924 * the internal format of the new texel array is the effective internal
3925 * format of the source buffer, and this is also the new texel array’s
3926 * effective internal format.
3928 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3929 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3930 "glCopyTexImage%uD(componenet size changed in"
3931 " internal format)", dims
);
3936 assert(texFormat
!= MESA_FORMAT_NONE
);
3938 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3940 width
, height
, 1, border
)) {
3941 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3942 "glCopyTexImage%uD(image too large)", dims
);
3946 if (border
&& ctx
->Const
.StripTextureBorder
) {
3948 width
-= border
* 2;
3951 height
-= border
* 2;
3956 _mesa_lock_texture(ctx
, texObj
);
3958 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3961 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3964 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3966 /* Free old texture image */
3967 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3969 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3970 border
, internalFormat
, texFormat
);
3972 if (width
&& height
) {
3973 /* Allocate texture memory (no pixel data yet) */
3974 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3976 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3978 struct gl_renderbuffer
*srcRb
=
3979 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3981 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3983 srcRb
, srcX
, srcY
, width
, height
);
3986 check_gen_mipmap(ctx
, target
, texObj
, level
);
3989 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3991 _mesa_dirty_texobj(ctx
, texObj
);
3994 _mesa_unlock_texture(ctx
, texObj
);
4000 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4001 GLenum internalFormat
,
4003 GLsizei width
, GLint border
)
4005 GET_CURRENT_CONTEXT(ctx
);
4006 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4012 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4013 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4016 GET_CURRENT_CONTEXT(ctx
);
4017 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4018 x
, y
, width
, height
, border
);
4022 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4025 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4026 struct gl_texture_object
*texObj
,
4027 GLenum target
, GLint level
,
4028 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4030 GLsizei width
, GLsizei height
,
4033 struct gl_texture_image
*texImage
;
4035 FLUSH_VERTICES(ctx
, 0);
4037 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4038 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
4039 _mesa_enum_to_string(target
),
4040 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4042 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4043 _mesa_update_state(ctx
);
4045 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4046 xoffset
, yoffset
, zoffset
,
4047 width
, height
, caller
)) {
4051 _mesa_lock_texture(ctx
, texObj
);
4053 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4055 /* If we have a border, offset=-1 is legal. Bias by border width. */
4058 if (target
!= GL_TEXTURE_2D_ARRAY
)
4059 zoffset
+= texImage
->Border
;
4062 if (target
!= GL_TEXTURE_1D_ARRAY
)
4063 yoffset
+= texImage
->Border
;
4066 xoffset
+= texImage
->Border
;
4069 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4071 struct gl_renderbuffer
*srcRb
=
4072 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4074 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4075 xoffset
, yoffset
, zoffset
,
4076 srcRb
, x
, y
, width
, height
);
4078 check_gen_mipmap(ctx
, target
, texObj
, level
);
4080 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4081 * the texel data, not the texture format, size, etc.
4085 _mesa_unlock_texture(ctx
, texObj
);
4089 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4090 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4092 struct gl_texture_object
* texObj
;
4093 const char *self
= "glCopyTexSubImage1D";
4094 GET_CURRENT_CONTEXT(ctx
);
4096 /* Check target (proxies not allowed). Target must be checked prior to
4097 * calling _mesa_get_current_tex_object.
4099 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4100 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4101 _mesa_enum_to_string(target
));
4105 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4109 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4110 x
, y
, width
, 1, self
);
4116 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4117 GLint xoffset
, GLint yoffset
,
4118 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4120 struct gl_texture_object
* texObj
;
4121 const char *self
= "glCopyTexSubImage2D";
4122 GET_CURRENT_CONTEXT(ctx
);
4124 /* Check target (proxies not allowed). Target must be checked prior to
4125 * calling _mesa_get_current_tex_object.
4127 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4128 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4129 _mesa_enum_to_string(target
));
4133 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4137 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4138 xoffset
, yoffset
, 0,
4139 x
, y
, width
, height
, self
);
4145 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4146 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4147 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4149 struct gl_texture_object
* texObj
;
4150 const char *self
= "glCopyTexSubImage3D";
4151 GET_CURRENT_CONTEXT(ctx
);
4153 /* Check target (proxies not allowed). Target must be checked prior to
4154 * calling _mesa_get_current_tex_object.
4156 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4157 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4158 _mesa_enum_to_string(target
));
4162 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4166 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4167 xoffset
, yoffset
, zoffset
,
4168 x
, y
, width
, height
, self
);
4172 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4173 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4175 struct gl_texture_object
* texObj
;
4176 const char *self
= "glCopyTextureSubImage1D";
4177 GET_CURRENT_CONTEXT(ctx
);
4179 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4183 /* Check target (proxies not allowed). */
4184 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4185 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4186 _mesa_enum_to_string(texObj
->Target
));
4190 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4191 xoffset
, 0, 0, x
, y
, width
, 1, self
);
4195 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4196 GLint xoffset
, GLint yoffset
,
4197 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4199 struct gl_texture_object
* texObj
;
4200 const char *self
= "glCopyTextureSubImage2D";
4201 GET_CURRENT_CONTEXT(ctx
);
4203 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4207 /* Check target (proxies not allowed). */
4208 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4209 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4210 _mesa_enum_to_string(texObj
->Target
));
4214 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4215 xoffset
, yoffset
, 0,
4216 x
, y
, width
, height
, self
);
4222 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4223 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4224 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4226 struct gl_texture_object
* texObj
;
4227 const char *self
= "glCopyTextureSubImage3D";
4228 GET_CURRENT_CONTEXT(ctx
);
4230 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4234 /* Check target (proxies not allowed). */
4235 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4236 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4237 _mesa_enum_to_string(texObj
->Target
));
4241 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4242 /* Act like CopyTexSubImage2D */
4243 _mesa_copy_texture_sub_image(ctx
, 2, texObj
,
4244 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4245 level
, xoffset
, yoffset
, 0,
4246 x
, y
, width
, height
, self
);
4249 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4250 xoffset
, yoffset
, zoffset
,
4251 x
, y
, width
, height
, self
);
4255 check_clear_tex_image(struct gl_context
*ctx
,
4256 const char *function
,
4257 struct gl_texture_image
*texImage
,
4258 GLenum format
, GLenum type
,
4260 GLubyte
*clearValue
)
4262 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4263 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4264 GLenum internalFormat
= texImage
->InternalFormat
;
4267 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4268 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4269 "%s(buffer texture)", function
);
4273 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4274 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4275 "%s(compressed texture)", function
);
4279 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4280 if (err
!= GL_NO_ERROR
) {
4281 _mesa_error(ctx
, err
,
4282 "%s(incompatible format = %s, type = %s)",
4284 _mesa_enum_to_string(format
),
4285 _mesa_enum_to_string(type
));
4289 /* make sure internal format and format basically agree */
4290 if (!texture_formats_agree(internalFormat
, format
)) {
4291 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4292 "%s(incompatible internalFormat = %s, format = %s)",
4294 _mesa_enum_to_string(internalFormat
),
4295 _mesa_enum_to_string(format
));
4299 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4300 /* both source and dest must be integer-valued, or neither */
4301 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4302 _mesa_is_enum_format_integer(format
)) {
4303 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4304 "%s(integer/non-integer format mismatch)",
4310 if (!_mesa_texstore(ctx
,
4312 texImage
->_BaseFormat
,
4313 texImage
->TexFormat
,
4314 0, /* dstRowStride */
4316 1, 1, 1, /* srcWidth/Height/Depth */
4318 data
? data
: zeroData
,
4319 &ctx
->DefaultPacking
)) {
4320 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4327 static struct gl_texture_object
*
4328 get_tex_obj_for_clear(struct gl_context
*ctx
,
4329 const char *function
,
4332 struct gl_texture_object
*texObj
;
4335 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4339 texObj
= _mesa_lookup_texture(ctx
, texture
);
4341 if (texObj
== NULL
) {
4342 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4346 if (texObj
->Target
== 0) {
4347 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4355 get_tex_images_for_clear(struct gl_context
*ctx
,
4356 const char *function
,
4357 struct gl_texture_object
*texObj
,
4359 struct gl_texture_image
**texImages
)
4364 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4365 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4369 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4370 for (i
= 0; i
< MAX_FACES
; i
++) {
4371 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4373 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4374 if (texImages
[i
] == NULL
) {
4375 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4376 "%s(invalid level)", function
);
4384 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4386 if (texImages
[0] == NULL
) {
4387 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4395 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4396 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4397 GLsizei width
, GLsizei height
, GLsizei depth
,
4398 GLenum format
, GLenum type
, const void *data
)
4400 GET_CURRENT_CONTEXT(ctx
);
4401 struct gl_texture_object
*texObj
;
4402 struct gl_texture_image
*texImages
[MAX_FACES
];
4403 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4405 int minDepth
, maxDepth
;
4407 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4412 _mesa_lock_texture(ctx
, texObj
);
4414 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4415 texObj
, level
, texImages
);
4419 if (numImages
== 1) {
4420 minDepth
= -(int) texImages
[0]->Border
;
4421 maxDepth
= texImages
[0]->Depth
;
4424 maxDepth
= numImages
;
4427 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4428 yoffset
< -(GLint
) texImages
[0]->Border
||
4429 zoffset
< minDepth
||
4433 xoffset
+ width
> texImages
[0]->Width
||
4434 yoffset
+ height
> texImages
[0]->Height
||
4435 zoffset
+ depth
> maxDepth
) {
4436 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4437 "glClearSubTexImage(invalid dimensions)");
4441 if (numImages
== 1) {
4442 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4444 format
, type
, data
, clearValue
[0])) {
4445 ctx
->Driver
.ClearTexSubImage(ctx
,
4447 xoffset
, yoffset
, zoffset
,
4448 width
, height
, depth
,
4449 data
? clearValue
[0] : NULL
);
4452 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4453 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4455 format
, type
, data
, clearValue
[i
]))
4458 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4459 ctx
->Driver
.ClearTexSubImage(ctx
,
4461 xoffset
, yoffset
, 0,
4463 data
? clearValue
[i
] : NULL
);
4468 _mesa_unlock_texture(ctx
, texObj
);
4472 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4473 GLenum format
, GLenum type
, const void *data
)
4475 GET_CURRENT_CONTEXT(ctx
);
4476 struct gl_texture_object
*texObj
;
4477 struct gl_texture_image
*texImages
[MAX_FACES
];
4478 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4481 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4486 _mesa_lock_texture(ctx
, texObj
);
4488 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4489 texObj
, level
, texImages
);
4491 for (i
= 0; i
< numImages
; i
++) {
4492 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4499 for (i
= 0; i
< numImages
; i
++) {
4500 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4501 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4502 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4503 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4504 texImages
[i
]->Width
,
4505 texImages
[i
]->Height
,
4506 texImages
[i
]->Depth
,
4507 data
? clearValue
[i
] : NULL
);
4511 _mesa_unlock_texture(ctx
, texObj
);
4517 /**********************************************************************/
4518 /****** Compressed Textures ******/
4519 /**********************************************************************/
4523 * Target checking for glCompressedTexSubImage[123]D().
4524 * \return GL_TRUE if error, GL_FALSE if no error
4525 * Must come before other error checking so that the texture object can
4526 * be correctly retrieved using _mesa_get_current_tex_object.
4529 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4530 GLint dims
, GLenum format
, bool dsa
,
4535 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4536 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4537 _mesa_enum_to_string(target
));
4547 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4548 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4549 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4550 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4551 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4552 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4553 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4556 targetOK
= GL_FALSE
;
4562 case GL_TEXTURE_CUBE_MAP
:
4563 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4565 case GL_TEXTURE_2D_ARRAY
:
4566 targetOK
= _mesa_is_gles3(ctx
) ||
4567 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4569 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4570 targetOK
= ctx
->Extensions
.ARB_texture_cube_map_array
;
4575 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4577 * "An INVALID_OPERATION error is generated by
4578 * CompressedTex*SubImage3D if the internal format of the texture
4579 * is one of the EAC, ETC2, or RGTC formats and either border is
4580 * non-zero, or the effective target for the texture is not
4581 * TEXTURE_2D_ARRAY."
4583 * NOTE: that's probably a spec error. It should probably say
4584 * "... or the effective target for the texture is not
4585 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4586 * GL_TEXTURE_CUBE_MAP_ARRAY."
4587 * since those targets are 2D images and they support all compression
4590 * Instead of listing all these, just list those which are allowed,
4591 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4592 * more) are valid here, which they are not, but of course not
4593 * mentioned by core spec.
4596 /* These are the only 3D compression formats supported at this time */
4597 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
4598 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
4599 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
4600 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
4604 /* invalid format */
4605 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4606 "%s(invalid target %s for format %s)", caller
,
4607 _mesa_enum_to_string(target
),
4608 _mesa_enum_to_string(format
));
4613 targetOK
= GL_FALSE
;
4619 /* no 1D compressed textures at this time */
4620 targetOK
= GL_FALSE
;
4625 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4626 _mesa_enum_to_string(target
));
4634 * Error checking for glCompressedTexSubImage[123]D().
4635 * \return GL_TRUE if error, GL_FALSE if no error
4638 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4639 const struct gl_texture_object
*texObj
,
4640 GLenum target
, GLint level
,
4641 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4642 GLsizei width
, GLsizei height
, GLsizei depth
,
4643 GLenum format
, GLsizei imageSize
,
4644 const GLvoid
*data
, const char *callerName
)
4646 struct gl_texture_image
*texImage
;
4649 /* this will catch any invalid compressed format token */
4650 if (!_mesa_is_compressed_format(ctx
, format
)) {
4651 _mesa_error(ctx
, GL_INVALID_ENUM
,
4652 "%s(format)", callerName
);
4656 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4657 _mesa_error(ctx
, GL_INVALID_VALUE
,
4663 /* validate the bound PBO, if any */
4664 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4665 imageSize
, data
, callerName
)) {
4669 /* Check for invalid pixel storage modes */
4670 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4671 &ctx
->Unpack
, callerName
)) {
4675 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4676 if (expectedSize
!= imageSize
) {
4677 _mesa_error(ctx
, GL_INVALID_VALUE
,
4679 callerName
, imageSize
);
4683 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4685 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4686 "%s(invalid texture image)",
4691 if ((GLint
) format
!= texImage
->InternalFormat
) {
4692 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4694 callerName
, format
);
4698 if (compressedteximage_only_format(ctx
, format
)) {
4699 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4700 "%s(format=0x%x cannot be updated)",
4701 callerName
, format
);
4705 if (error_check_subtexture_dimensions(ctx
, dims
,
4706 texImage
, xoffset
, yoffset
, zoffset
,
4707 width
, height
, depth
,
4717 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4718 GLenum internalFormat
, GLsizei width
,
4719 GLint border
, GLsizei imageSize
,
4722 GET_CURRENT_CONTEXT(ctx
);
4723 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4724 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4729 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4730 GLenum internalFormat
, GLsizei width
,
4731 GLsizei height
, GLint border
, GLsizei imageSize
,
4734 GET_CURRENT_CONTEXT(ctx
);
4735 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4736 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4741 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4742 GLenum internalFormat
, GLsizei width
,
4743 GLsizei height
, GLsizei depth
, GLint border
,
4744 GLsizei imageSize
, const GLvoid
*data
)
4746 GET_CURRENT_CONTEXT(ctx
);
4747 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4748 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4753 * Common helper for glCompressedTexSubImage1/2/3D() and
4754 * glCompressedTextureSubImage1/2/3D().
4757 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4758 struct gl_texture_object
*texObj
,
4759 struct gl_texture_image
*texImage
,
4760 GLenum target
, GLint level
,
4761 GLint xoffset
, GLint yoffset
,
4763 GLsizei width
, GLsizei height
,
4765 GLenum format
, GLsizei imageSize
,
4768 FLUSH_VERTICES(ctx
, 0);
4770 _mesa_lock_texture(ctx
, texObj
);
4772 if (width
> 0 && height
> 0 && depth
> 0) {
4773 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4774 xoffset
, yoffset
, zoffset
,
4775 width
, height
, depth
,
4776 format
, imageSize
, data
);
4778 check_gen_mipmap(ctx
, target
, texObj
, level
);
4780 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4781 * the texel data, not the texture format, size, etc.
4785 _mesa_unlock_texture(ctx
, texObj
);
4790 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4791 GLsizei width
, GLenum format
,
4792 GLsizei imageSize
, const GLvoid
*data
)
4794 struct gl_texture_object
*texObj
;
4795 struct gl_texture_image
*texImage
;
4797 GET_CURRENT_CONTEXT(ctx
);
4799 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4800 "glCompressedTexSubImage1D")) {
4804 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4808 if (compressed_subtexture_error_check(ctx
, 1, texObj
, target
,
4809 level
, xoffset
, 0, 0,
4811 format
, imageSize
, data
,
4812 "glCompressedTexSubImage1D")) {
4816 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4819 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
4820 xoffset
, 0, 0, width
, 1, 1,
4821 format
, imageSize
, data
);
4825 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4826 GLsizei width
, GLenum format
,
4827 GLsizei imageSize
, const GLvoid
*data
)
4829 struct gl_texture_object
*texObj
;
4830 struct gl_texture_image
*texImage
;
4832 GET_CURRENT_CONTEXT(ctx
);
4834 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4835 "glCompressedTextureSubImage1D");
4839 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
, true,
4840 "glCompressedTextureSubImage1D")) {
4844 if (compressed_subtexture_error_check(ctx
, 1, texObj
, texObj
->Target
,
4845 level
, xoffset
, 0, 0,
4847 format
, imageSize
, data
,
4848 "glCompressedTextureSubImage1D")) {
4852 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4855 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
,
4856 texObj
->Target
, level
,
4857 xoffset
, 0, 0, width
, 1, 1,
4858 format
, imageSize
, data
);
4863 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4864 GLint yoffset
, GLsizei width
, GLsizei height
,
4865 GLenum format
, GLsizei imageSize
,
4868 struct gl_texture_object
*texObj
;
4869 struct gl_texture_image
*texImage
;
4871 GET_CURRENT_CONTEXT(ctx
);
4873 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
4874 "glCompressedTexSubImage2D")) {
4878 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4882 if (compressed_subtexture_error_check(ctx
, 2, texObj
, target
,
4883 level
, xoffset
, yoffset
, 0,
4885 format
, imageSize
, data
,
4886 "glCompressedTexSubImage2D")) {
4891 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4894 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
4895 xoffset
, yoffset
, 0, width
, height
, 1,
4896 format
, imageSize
, data
);
4900 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
4902 GLsizei width
, GLsizei height
,
4903 GLenum format
, GLsizei imageSize
,
4906 struct gl_texture_object
*texObj
;
4907 struct gl_texture_image
*texImage
;
4909 GET_CURRENT_CONTEXT(ctx
);
4911 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4912 "glCompressedTextureSubImage2D");
4916 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
, true,
4917 "glCompressedTextureSubImage2D")) {
4921 if (compressed_subtexture_error_check(ctx
, 2, texObj
, texObj
->Target
,
4922 level
, xoffset
, yoffset
, 0,
4924 format
, imageSize
, data
,
4925 "glCompressedTextureSubImage2D")) {
4929 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4932 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
,
4933 texObj
->Target
, level
,
4934 xoffset
, yoffset
, 0, width
, height
, 1,
4935 format
, imageSize
, data
);
4939 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4940 GLint yoffset
, GLint zoffset
, GLsizei width
,
4941 GLsizei height
, GLsizei depth
, GLenum format
,
4942 GLsizei imageSize
, const GLvoid
*data
)
4944 struct gl_texture_object
*texObj
;
4945 struct gl_texture_image
*texImage
;
4947 GET_CURRENT_CONTEXT(ctx
);
4949 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
4950 "glCompressedTexSubImage3D")) {
4954 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4958 if (compressed_subtexture_error_check(ctx
, 3, texObj
, target
,
4959 level
, xoffset
, yoffset
, zoffset
,
4960 width
, height
, depth
,
4961 format
, imageSize
, data
,
4962 "glCompressedTexSubImage3D")) {
4967 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4970 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
4971 xoffset
, yoffset
, zoffset
,
4972 width
, height
, depth
,
4973 format
, imageSize
, data
);
4977 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
4978 GLint yoffset
, GLint zoffset
, GLsizei width
,
4979 GLsizei height
, GLsizei depth
,
4980 GLenum format
, GLsizei imageSize
,
4983 struct gl_texture_object
*texObj
;
4984 struct gl_texture_image
*texImage
;
4986 GET_CURRENT_CONTEXT(ctx
);
4988 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4989 "glCompressedTextureSubImage3D");
4993 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
, true,
4994 "glCompressedTextureSubImage3D")) {
4998 if (compressed_subtexture_error_check(ctx
, 3, texObj
, texObj
->Target
,
4999 level
, xoffset
, yoffset
, zoffset
,
5000 width
, height
, depth
,
5001 format
, imageSize
, data
,
5002 "glCompressedTextureSubImage3D")) {
5006 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
5007 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5008 const char *pixels
= data
;
5012 /* Make sure the texture object is a proper cube.
5013 * (See texturesubimage in teximage.c for details on why this check is
5016 if (!_mesa_cube_level_complete(texObj
, level
)) {
5017 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5018 "glCompressedTextureSubImage3D(cube map incomplete)");
5022 /* Copy in each face. */
5023 for (i
= 0; i
< 6; ++i
) {
5024 texImage
= texObj
->Image
[i
][level
];
5027 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5028 texObj
->Target
, level
,
5029 xoffset
, yoffset
, zoffset
,
5031 format
, imageSize
, pixels
);
5033 /* Compressed images don't have a client format */
5034 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5036 texImage
->Height
, 1);
5038 pixels
+= image_stride
;
5039 imageSize
-= image_stride
;
5043 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5046 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5047 texObj
->Target
, level
,
5048 xoffset
, yoffset
, zoffset
,
5049 width
, height
, depth
,
5050 format
, imageSize
, data
);
5055 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5057 if (ctx
->API
!= API_OPENGL_CORE
) {
5058 switch (internalFormat
) {
5060 return MESA_FORMAT_A_UNORM8
;
5062 return MESA_FORMAT_A_UNORM16
;
5063 case GL_ALPHA16F_ARB
:
5064 return MESA_FORMAT_A_FLOAT16
;
5065 case GL_ALPHA32F_ARB
:
5066 return MESA_FORMAT_A_FLOAT32
;
5067 case GL_ALPHA8I_EXT
:
5068 return MESA_FORMAT_A_SINT8
;
5069 case GL_ALPHA16I_EXT
:
5070 return MESA_FORMAT_A_SINT16
;
5071 case GL_ALPHA32I_EXT
:
5072 return MESA_FORMAT_A_SINT32
;
5073 case GL_ALPHA8UI_EXT
:
5074 return MESA_FORMAT_A_UINT8
;
5075 case GL_ALPHA16UI_EXT
:
5076 return MESA_FORMAT_A_UINT16
;
5077 case GL_ALPHA32UI_EXT
:
5078 return MESA_FORMAT_A_UINT32
;
5080 return MESA_FORMAT_L_UNORM8
;
5081 case GL_LUMINANCE16
:
5082 return MESA_FORMAT_L_UNORM16
;
5083 case GL_LUMINANCE16F_ARB
:
5084 return MESA_FORMAT_L_FLOAT16
;
5085 case GL_LUMINANCE32F_ARB
:
5086 return MESA_FORMAT_L_FLOAT32
;
5087 case GL_LUMINANCE8I_EXT
:
5088 return MESA_FORMAT_L_SINT8
;
5089 case GL_LUMINANCE16I_EXT
:
5090 return MESA_FORMAT_L_SINT16
;
5091 case GL_LUMINANCE32I_EXT
:
5092 return MESA_FORMAT_L_SINT32
;
5093 case GL_LUMINANCE8UI_EXT
:
5094 return MESA_FORMAT_L_UINT8
;
5095 case GL_LUMINANCE16UI_EXT
:
5096 return MESA_FORMAT_L_UINT16
;
5097 case GL_LUMINANCE32UI_EXT
:
5098 return MESA_FORMAT_L_UINT32
;
5099 case GL_LUMINANCE8_ALPHA8
:
5100 return MESA_FORMAT_L8A8_UNORM
;
5101 case GL_LUMINANCE16_ALPHA16
:
5102 return MESA_FORMAT_L16A16_UNORM
;
5103 case GL_LUMINANCE_ALPHA16F_ARB
:
5104 return MESA_FORMAT_LA_FLOAT16
;
5105 case GL_LUMINANCE_ALPHA32F_ARB
:
5106 return MESA_FORMAT_LA_FLOAT32
;
5107 case GL_LUMINANCE_ALPHA8I_EXT
:
5108 return MESA_FORMAT_LA_SINT8
;
5109 case GL_LUMINANCE_ALPHA16I_EXT
:
5110 return MESA_FORMAT_LA_SINT16
;
5111 case GL_LUMINANCE_ALPHA32I_EXT
:
5112 return MESA_FORMAT_LA_SINT32
;
5113 case GL_LUMINANCE_ALPHA8UI_EXT
:
5114 return MESA_FORMAT_LA_UINT8
;
5115 case GL_LUMINANCE_ALPHA16UI_EXT
:
5116 return MESA_FORMAT_LA_UINT16
;
5117 case GL_LUMINANCE_ALPHA32UI_EXT
:
5118 return MESA_FORMAT_LA_UINT32
;
5120 return MESA_FORMAT_I_UNORM8
;
5121 case GL_INTENSITY16
:
5122 return MESA_FORMAT_I_UNORM16
;
5123 case GL_INTENSITY16F_ARB
:
5124 return MESA_FORMAT_I_FLOAT16
;
5125 case GL_INTENSITY32F_ARB
:
5126 return MESA_FORMAT_I_FLOAT32
;
5127 case GL_INTENSITY8I_EXT
:
5128 return MESA_FORMAT_I_SINT8
;
5129 case GL_INTENSITY16I_EXT
:
5130 return MESA_FORMAT_I_SINT16
;
5131 case GL_INTENSITY32I_EXT
:
5132 return MESA_FORMAT_I_SINT32
;
5133 case GL_INTENSITY8UI_EXT
:
5134 return MESA_FORMAT_I_UINT8
;
5135 case GL_INTENSITY16UI_EXT
:
5136 return MESA_FORMAT_I_UINT16
;
5137 case GL_INTENSITY32UI_EXT
:
5138 return MESA_FORMAT_I_UINT32
;
5144 if (ctx
->API
== API_OPENGL_CORE
&&
5145 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5146 switch (internalFormat
) {
5148 return MESA_FORMAT_RGB_FLOAT32
;
5150 return MESA_FORMAT_RGB_UINT32
;
5152 return MESA_FORMAT_RGB_SINT32
;
5158 switch (internalFormat
) {
5160 return MESA_FORMAT_R8G8B8A8_UNORM
;
5162 return MESA_FORMAT_RGBA_UNORM16
;
5163 case GL_RGBA16F_ARB
:
5164 return MESA_FORMAT_RGBA_FLOAT16
;
5165 case GL_RGBA32F_ARB
:
5166 return MESA_FORMAT_RGBA_FLOAT32
;
5168 return MESA_FORMAT_RGBA_SINT8
;
5169 case GL_RGBA16I_EXT
:
5170 return MESA_FORMAT_RGBA_SINT16
;
5171 case GL_RGBA32I_EXT
:
5172 return MESA_FORMAT_RGBA_SINT32
;
5173 case GL_RGBA8UI_EXT
:
5174 return MESA_FORMAT_RGBA_UINT8
;
5175 case GL_RGBA16UI_EXT
:
5176 return MESA_FORMAT_RGBA_UINT16
;
5177 case GL_RGBA32UI_EXT
:
5178 return MESA_FORMAT_RGBA_UINT32
;
5181 return MESA_FORMAT_R8G8_UNORM
;
5183 return MESA_FORMAT_R16G16_UNORM
;
5185 return MESA_FORMAT_RG_FLOAT16
;
5187 return MESA_FORMAT_RG_FLOAT32
;
5189 return MESA_FORMAT_RG_SINT8
;
5191 return MESA_FORMAT_RG_SINT16
;
5193 return MESA_FORMAT_RG_SINT32
;
5195 return MESA_FORMAT_RG_UINT8
;
5197 return MESA_FORMAT_RG_UINT16
;
5199 return MESA_FORMAT_RG_UINT32
;
5202 return MESA_FORMAT_R_UNORM8
;
5204 return MESA_FORMAT_R_UNORM16
;
5206 return MESA_FORMAT_R_FLOAT16
;
5208 return MESA_FORMAT_R_FLOAT32
;
5210 return MESA_FORMAT_R_SINT8
;
5212 return MESA_FORMAT_R_SINT16
;
5214 return MESA_FORMAT_R_SINT32
;
5216 return MESA_FORMAT_R_UINT8
;
5218 return MESA_FORMAT_R_UINT16
;
5220 return MESA_FORMAT_R_UINT32
;
5223 return MESA_FORMAT_NONE
;
5229 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5230 GLenum internalFormat
)
5232 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5235 if (format
== MESA_FORMAT_NONE
)
5236 return MESA_FORMAT_NONE
;
5238 datatype
= _mesa_get_format_datatype(format
);
5240 /* The GL_ARB_texture_buffer_object spec says:
5242 * "If ARB_texture_float is not supported, references to the
5243 * floating-point internal formats provided by that extension should be
5244 * removed, and such formats may not be passed to TexBufferARB."
5246 * As a result, GL_HALF_FLOAT internal format depends on both
5247 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5249 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5250 !ctx
->Extensions
.ARB_texture_float
)
5251 return MESA_FORMAT_NONE
;
5253 if (!ctx
->Extensions
.ARB_texture_rg
) {
5254 GLenum base_format
= _mesa_get_format_base_format(format
);
5255 if (base_format
== GL_R
|| base_format
== GL_RG
)
5256 return MESA_FORMAT_NONE
;
5259 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5260 GLenum base_format
= _mesa_get_format_base_format(format
);
5261 if (base_format
== GL_RGB
)
5262 return MESA_FORMAT_NONE
;
5269 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5270 struct gl_texture_object
*texObj
,
5271 GLenum internalFormat
,
5272 struct gl_buffer_object
*bufObj
,
5273 GLintptr offset
, GLsizeiptr size
,
5278 /* NOTE: ARB_texture_buffer_object has interactions with
5279 * the compatibility profile that are not implemented.
5281 if (!(ctx
->API
== API_OPENGL_CORE
&&
5282 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5283 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5284 "%s(ARB_texture_buffer_object is not"
5285 " implemented for the compatibility profile)", caller
);
5289 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5290 if (format
== MESA_FORMAT_NONE
) {
5291 _mesa_error(ctx
, GL_INVALID_ENUM
,
5292 "%s(internalFormat 0x%x)", caller
, internalFormat
);
5296 FLUSH_VERTICES(ctx
, 0);
5298 _mesa_lock_texture(ctx
, texObj
);
5300 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5301 texObj
->BufferObjectFormat
= internalFormat
;
5302 texObj
->_BufferObjectFormat
= format
;
5303 texObj
->BufferOffset
= offset
;
5304 texObj
->BufferSize
= size
;
5306 _mesa_unlock_texture(ctx
, texObj
);
5308 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5311 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5317 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5318 * Return true if it is, and return false if it is not
5319 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5320 * core spec, 02.02.2015, PDF page 245).
5323 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5326 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5327 _mesa_error(ctx
, GL_INVALID_ENUM
,
5328 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5336 * Check for errors related to the texture buffer range.
5337 * Return false if errors are found, true if none are found.
5340 check_texture_buffer_range(struct gl_context
*ctx
,
5341 struct gl_buffer_object
*bufObj
,
5342 GLintptr offset
, GLsizeiptr size
,
5345 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5346 * Textures (PDF page 245):
5347 * "An INVALID_VALUE error is generated if offset is negative, if
5348 * size is less than or equal to zero, or if offset + size is greater
5349 * than the value of BUFFER_SIZE for the buffer bound to target."
5352 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5358 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5363 if (offset
+ size
> bufObj
->Size
) {
5364 _mesa_error(ctx
, GL_INVALID_VALUE
,
5365 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5366 (int) offset
, (int) size
, (int) bufObj
->Size
);
5370 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5371 * Textures (PDF page 245):
5372 * "An INVALID_VALUE error is generated if offset is not an integer
5373 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5375 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5376 _mesa_error(ctx
, GL_INVALID_VALUE
,
5377 "%s(invalid offset alignment)", caller
);
5385 /** GL_ARB_texture_buffer_object */
5387 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5389 struct gl_texture_object
*texObj
;
5390 struct gl_buffer_object
*bufObj
;
5392 GET_CURRENT_CONTEXT(ctx
);
5394 /* Need to catch a bad target before it gets to
5395 * _mesa_get_current_tex_object.
5397 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5401 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5407 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5411 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5412 buffer
? -1 : 0, "glTexBuffer");
5416 /** GL_ARB_texture_buffer_range */
5418 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5419 GLintptr offset
, GLsizeiptr size
)
5421 struct gl_texture_object
*texObj
;
5422 struct gl_buffer_object
*bufObj
;
5424 GET_CURRENT_CONTEXT(ctx
);
5426 /* Need to catch a bad target before it gets to
5427 * _mesa_get_current_tex_object.
5429 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5433 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5437 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5438 "glTexBufferRange"))
5442 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5443 * Textures (PDF page 254):
5444 * "If buffer is zero, then any buffer object attached to the buffer
5445 * texture is detached, the values offset and size are ignored and
5446 * the state for offset and size for the buffer texture are reset to
5454 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5458 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5459 offset
, size
, "glTexBufferRange");
5463 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5465 struct gl_texture_object
*texObj
;
5466 struct gl_buffer_object
*bufObj
;
5468 GET_CURRENT_CONTEXT(ctx
);
5471 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5477 /* Get the texture object by Name. */
5478 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5482 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5485 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5486 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5490 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5491 GLintptr offset
, GLsizeiptr size
)
5493 struct gl_texture_object
*texObj
;
5494 struct gl_buffer_object
*bufObj
;
5496 GET_CURRENT_CONTEXT(ctx
);
5499 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5500 "glTextureBufferRange");
5504 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5505 "glTextureBufferRange"))
5509 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5510 * Textures (PDF page 254):
5511 * "If buffer is zero, then any buffer object attached to the buffer
5512 * texture is detached, the values offset and size are ignored and
5513 * the state for offset and size for the buffer texture are reset to
5521 /* Get the texture object by Name. */
5522 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5526 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5527 "glTextureBufferRange"))
5530 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5531 bufObj
, offset
, size
, "glTextureBufferRange");
5535 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5537 /* Everything that is allowed for renderbuffers,
5538 * except for a base format of GL_STENCIL_INDEX, unless supported.
5540 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5541 if (ctx
->Extensions
.ARB_texture_stencil8
)
5542 return baseFormat
!= 0;
5544 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5548 /** GL_ARB_texture_multisample */
5550 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5553 case GL_TEXTURE_2D_MULTISAMPLE
:
5555 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5556 return dims
== 2 && !dsa
;
5557 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5559 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5560 return dims
== 3 && !dsa
;
5568 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5569 struct gl_texture_object
*texObj
,
5570 GLenum target
, GLsizei samples
,
5571 GLint internalformat
, GLsizei width
,
5572 GLsizei height
, GLsizei depth
,
5573 GLboolean fixedsamplelocations
,
5574 GLboolean immutable
, const char *func
)
5576 struct gl_texture_image
*texImage
;
5577 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5578 mesa_format texFormat
;
5579 GLenum sample_count_error
;
5580 bool dsa
= strstr(func
, "ture") ? true : false;
5582 if (!((ctx
->Extensions
.ARB_texture_multisample
5583 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5584 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5589 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5593 if (!check_multisample_target(dims
, target
, dsa
)) {
5595 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5599 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5604 /* check that the specified internalformat is color/depth/stencil-renderable;
5605 * refer GL3.1 spec 4.4.4
5608 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5609 _mesa_error(ctx
, GL_INVALID_ENUM
,
5610 "%s(internalformat=%s not legal for immutable-format)",
5611 func
, _mesa_enum_to_string(internalformat
));
5615 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5616 /* Page 172 of OpenGL ES 3.1 spec says:
5617 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5618 * color-renderable, depth-renderable, or stencil-renderable (as
5619 * defined in section 9.4).
5621 * (Same error is also defined for desktop OpenGL for multisample
5622 * teximage/texstorage functions.)
5624 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5625 _mesa_enum_to_string(internalformat
));
5629 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5630 internalformat
, samples
);
5631 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5633 /* Page 254 of OpenGL 4.4 spec says:
5634 * "Proxy arrays for two-dimensional multisample and two-dimensional
5635 * multisample array textures are operated on in the same way when
5636 * TexImage2DMultisample is called with target specified as
5637 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5638 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5639 * However, if samples is not supported, then no error is generated.
5641 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5642 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5646 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5647 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5648 "%s(texture object 0)",
5653 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5655 if (texImage
== NULL
) {
5656 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5660 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5661 internalformat
, GL_NONE
, GL_NONE
);
5662 assert(texFormat
!= MESA_FORMAT_NONE
);
5664 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5665 width
, height
, depth
, 0);
5667 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5668 width
, height
, depth
, 0);
5670 if (_mesa_is_proxy_texture(target
)) {
5671 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5672 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5673 internalformat
, texFormat
,
5674 samples
, fixedsamplelocations
);
5677 /* clear all image fields */
5678 clear_teximage_fields(texImage
);
5682 if (!dimensionsOK
) {
5683 _mesa_error(ctx
, GL_INVALID_VALUE
,
5684 "%s(invalid width or height)", func
);
5689 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5693 /* Check if texObj->Immutable is set */
5694 if (texObj
->Immutable
) {
5695 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5699 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5701 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5702 internalformat
, texFormat
,
5703 samples
, fixedsamplelocations
);
5705 if (width
> 0 && height
> 0 && depth
> 0) {
5706 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5707 width
, height
, depth
)) {
5708 /* tidy up the texture image state. strictly speaking,
5709 * we're allowed to just leave this in whatever state we
5710 * like, but being tidy is good.
5712 _mesa_init_teximage_fields(ctx
, texImage
,
5713 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5717 texObj
->Immutable
|= immutable
;
5720 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5723 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5729 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5730 GLenum internalformat
, GLsizei width
,
5731 GLsizei height
, GLboolean fixedsamplelocations
)
5733 struct gl_texture_object
*texObj
;
5734 GET_CURRENT_CONTEXT(ctx
);
5736 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5740 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5741 internalformat
, width
, height
, 1,
5742 fixedsamplelocations
, GL_FALSE
,
5743 "glTexImage2DMultisample");
5748 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5749 GLenum internalformat
, GLsizei width
,
5750 GLsizei height
, GLsizei depth
,
5751 GLboolean fixedsamplelocations
)
5753 struct gl_texture_object
*texObj
;
5754 GET_CURRENT_CONTEXT(ctx
);
5756 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5760 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5761 internalformat
, width
, height
, depth
,
5762 fixedsamplelocations
, GL_FALSE
,
5763 "glTexImage3DMultisample");
5767 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
5768 GLsizei samples
, unsigned dims
)
5770 GET_CURRENT_CONTEXT(ctx
);
5772 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
5773 _mesa_error(ctx
, GL_INVALID_VALUE
,
5774 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
5775 dims
, width
, height
, depth
);
5782 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5783 GLenum internalformat
, GLsizei width
,
5784 GLsizei height
, GLboolean fixedsamplelocations
)
5786 struct gl_texture_object
*texObj
;
5787 GET_CURRENT_CONTEXT(ctx
);
5789 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5793 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5796 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5797 internalformat
, width
, height
, 1,
5798 fixedsamplelocations
, GL_TRUE
,
5799 "glTexStorage2DMultisample");
5803 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5804 GLenum internalformat
, GLsizei width
,
5805 GLsizei height
, GLsizei depth
,
5806 GLboolean fixedsamplelocations
)
5808 struct gl_texture_object
*texObj
;
5809 GET_CURRENT_CONTEXT(ctx
);
5811 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5815 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5818 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5819 internalformat
, width
, height
, depth
,
5820 fixedsamplelocations
, GL_TRUE
,
5821 "glTexStorage3DMultisample");
5825 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5826 GLenum internalformat
, GLsizei width
,
5828 GLboolean fixedsamplelocations
)
5830 struct gl_texture_object
*texObj
;
5831 GET_CURRENT_CONTEXT(ctx
);
5833 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5834 "glTextureStorage2DMultisample");
5838 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5841 texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5842 internalformat
, width
, height
, 1,
5843 fixedsamplelocations
, GL_TRUE
,
5844 "glTextureStorage2DMultisample");
5848 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5849 GLenum internalformat
, GLsizei width
,
5850 GLsizei height
, GLsizei depth
,
5851 GLboolean fixedsamplelocations
)
5853 struct gl_texture_object
*texObj
;
5854 GET_CURRENT_CONTEXT(ctx
);
5856 /* Get the texture object by Name. */
5857 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5858 "glTextureStorage3DMultisample");
5862 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5865 texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5866 internalformat
, width
, height
, depth
,
5867 fixedsamplelocations
, GL_TRUE
,
5868 "glTextureStorage3DMultisample");