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( 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 (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
256 switch (internalFormat
) {
257 case GL_COMPRESSED_RGB_FXT1_3DFX
:
259 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
266 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
268 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
269 switch (internalFormat
) {
270 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
272 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
273 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
274 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
281 if (_mesa_is_desktop_gl(ctx
)
282 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
283 switch (internalFormat
) {
295 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
296 if (internalFormat
== GL_YCBCR_MESA
)
297 return GL_YCBCR_MESA
;
300 if (ctx
->Extensions
.ARB_texture_float
) {
301 switch (internalFormat
) {
302 case GL_ALPHA16F_ARB
:
303 case GL_ALPHA32F_ARB
:
311 case GL_INTENSITY16F_ARB
:
312 case GL_INTENSITY32F_ARB
:
314 case GL_LUMINANCE16F_ARB
:
315 case GL_LUMINANCE32F_ARB
:
317 case GL_LUMINANCE_ALPHA16F_ARB
:
318 case GL_LUMINANCE_ALPHA32F_ARB
:
319 return GL_LUMINANCE_ALPHA
;
325 if (ctx
->Extensions
.EXT_texture_snorm
) {
326 switch (internalFormat
) {
341 case GL_RGBA16_SNORM
:
344 case GL_ALPHA8_SNORM
:
345 case GL_ALPHA16_SNORM
:
347 case GL_LUMINANCE_SNORM
:
348 case GL_LUMINANCE8_SNORM
:
349 case GL_LUMINANCE16_SNORM
:
351 case GL_LUMINANCE_ALPHA_SNORM
:
352 case GL_LUMINANCE8_ALPHA8_SNORM
:
353 case GL_LUMINANCE16_ALPHA16_SNORM
:
354 return GL_LUMINANCE_ALPHA
;
355 case GL_INTENSITY_SNORM
:
356 case GL_INTENSITY8_SNORM
:
357 case GL_INTENSITY16_SNORM
:
364 if (ctx
->Extensions
.EXT_texture_sRGB
) {
365 switch (internalFormat
) {
368 case GL_COMPRESSED_SRGB_EXT
:
370 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
371 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
372 case GL_SRGB_ALPHA_EXT
:
373 case GL_SRGB8_ALPHA8_EXT
:
374 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
376 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
377 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
378 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
379 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
380 case GL_SLUMINANCE_ALPHA_EXT
:
381 case GL_SLUMINANCE8_ALPHA8_EXT
:
382 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
383 return GL_LUMINANCE_ALPHA
;
384 case GL_SLUMINANCE_EXT
:
385 case GL_SLUMINANCE8_EXT
:
386 case GL_COMPRESSED_SLUMINANCE_EXT
:
393 if (ctx
->Version
>= 30 ||
394 ctx
->Extensions
.EXT_texture_integer
) {
395 switch (internalFormat
) {
397 case GL_RGBA16UI_EXT
:
398 case GL_RGBA32UI_EXT
:
414 if (ctx
->Extensions
.EXT_texture_integer
) {
415 switch (internalFormat
) {
416 case GL_ALPHA8UI_EXT
:
417 case GL_ALPHA16UI_EXT
:
418 case GL_ALPHA32UI_EXT
:
420 case GL_ALPHA16I_EXT
:
421 case GL_ALPHA32I_EXT
:
423 case GL_INTENSITY8UI_EXT
:
424 case GL_INTENSITY16UI_EXT
:
425 case GL_INTENSITY32UI_EXT
:
426 case GL_INTENSITY8I_EXT
:
427 case GL_INTENSITY16I_EXT
:
428 case GL_INTENSITY32I_EXT
:
430 case GL_LUMINANCE8UI_EXT
:
431 case GL_LUMINANCE16UI_EXT
:
432 case GL_LUMINANCE32UI_EXT
:
433 case GL_LUMINANCE8I_EXT
:
434 case GL_LUMINANCE16I_EXT
:
435 case GL_LUMINANCE32I_EXT
:
437 case GL_LUMINANCE_ALPHA8UI_EXT
:
438 case GL_LUMINANCE_ALPHA16UI_EXT
:
439 case GL_LUMINANCE_ALPHA32UI_EXT
:
440 case GL_LUMINANCE_ALPHA8I_EXT
:
441 case GL_LUMINANCE_ALPHA16I_EXT
:
442 case GL_LUMINANCE_ALPHA32I_EXT
:
443 return GL_LUMINANCE_ALPHA
;
449 if (ctx
->Extensions
.ARB_texture_rg
) {
450 switch (internalFormat
) {
453 if (!ctx
->Extensions
.ARB_texture_float
)
462 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
468 case GL_COMPRESSED_RED
:
473 if (!ctx
->Extensions
.ARB_texture_float
)
482 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
488 case GL_COMPRESSED_RG
:
495 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
496 switch (internalFormat
) {
504 if (ctx
->Extensions
.EXT_packed_float
) {
505 switch (internalFormat
) {
506 case GL_R11F_G11F_B10F_EXT
:
513 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
514 switch (internalFormat
) {
515 case GL_DEPTH_COMPONENT32F
:
516 return GL_DEPTH_COMPONENT
;
517 case GL_DEPTH32F_STENCIL8
:
518 return GL_DEPTH_STENCIL
;
524 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
525 switch (internalFormat
) {
526 case GL_COMPRESSED_RED_RGTC1
:
527 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
529 case GL_COMPRESSED_RG_RGTC2
:
530 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
537 if (ctx
->API
== API_OPENGL_COMPAT
&&
538 ctx
->Extensions
.EXT_texture_compression_latc
) {
539 switch (internalFormat
) {
540 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
541 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
543 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
544 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
545 return GL_LUMINANCE_ALPHA
;
551 if (ctx
->API
== API_OPENGL_COMPAT
&&
552 ctx
->Extensions
.ATI_texture_compression_3dc
) {
553 switch (internalFormat
) {
554 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
555 return GL_LUMINANCE_ALPHA
;
561 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
562 switch (internalFormat
) {
563 case GL_ETC1_RGB8_OES
:
570 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
571 _mesa_is_astc_format(internalFormat
))
574 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
575 switch (internalFormat
) {
576 case GL_COMPRESSED_RGB8_ETC2
:
577 case GL_COMPRESSED_SRGB8_ETC2
:
579 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
580 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
581 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
582 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
584 case GL_COMPRESSED_R11_EAC
:
585 case GL_COMPRESSED_SIGNED_R11_EAC
:
587 case GL_COMPRESSED_RG11_EAC
:
588 case GL_COMPRESSED_SIGNED_RG11_EAC
:
595 if (_mesa_is_desktop_gl(ctx
) &&
596 ctx
->Extensions
.ARB_texture_compression_bptc
) {
597 switch (internalFormat
) {
598 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
599 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
601 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
602 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
609 if (ctx
->API
== API_OPENGLES
) {
610 switch (internalFormat
) {
611 case GL_PALETTE4_RGB8_OES
:
612 case GL_PALETTE4_R5_G6_B5_OES
:
613 case GL_PALETTE8_RGB8_OES
:
614 case GL_PALETTE8_R5_G6_B5_OES
:
616 case GL_PALETTE4_RGBA8_OES
:
617 case GL_PALETTE8_RGB5_A1_OES
:
618 case GL_PALETTE4_RGBA4_OES
:
619 case GL_PALETTE4_RGB5_A1_OES
:
620 case GL_PALETTE8_RGBA8_OES
:
621 case GL_PALETTE8_RGBA4_OES
:
628 return -1; /* error */
633 * For cube map faces, return a face index in [0,5].
634 * For other targets return 0;
637 _mesa_tex_target_to_face(GLenum target
)
639 if (_mesa_is_cube_face(target
))
640 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
648 * Install gl_texture_image in a gl_texture_object according to the target
649 * and level parameters.
651 * \param tObj texture object.
652 * \param target texture target.
653 * \param level image level.
654 * \param texImage texture image.
657 set_tex_image(struct gl_texture_object
*tObj
,
658 GLenum target
, GLint level
,
659 struct gl_texture_image
*texImage
)
661 const GLuint face
= _mesa_tex_target_to_face(target
);
665 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
668 tObj
->Image
[face
][level
] = texImage
;
670 /* Set the 'back' pointer */
671 texImage
->TexObject
= tObj
;
672 texImage
->Level
= level
;
673 texImage
->Face
= face
;
678 * Allocate a texture image structure.
680 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
683 * \return a pointer to gl_texture_image struct with all fields initialized to
686 struct gl_texture_image
*
687 _mesa_new_texture_image( struct gl_context
*ctx
)
690 return CALLOC_STRUCT(gl_texture_image
);
695 * Free a gl_texture_image and associated data.
696 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
698 * \param texImage texture image.
700 * Free the texture image structure and the associated image data.
703 _mesa_delete_texture_image(struct gl_context
*ctx
,
704 struct gl_texture_image
*texImage
)
706 /* Free texImage->Data and/or any other driver-specific texture
709 assert(ctx
->Driver
.FreeTextureImageBuffer
);
710 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
716 * Test if a target is a proxy target.
718 * \param target texture target.
720 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
723 _mesa_is_proxy_texture(GLenum target
)
726 static const GLenum targets
[] = {
730 GL_PROXY_TEXTURE_CUBE_MAP
,
731 GL_PROXY_TEXTURE_RECTANGLE
,
732 GL_PROXY_TEXTURE_1D_ARRAY
,
733 GL_PROXY_TEXTURE_2D_ARRAY
,
734 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
735 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
736 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
739 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
740 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
742 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
744 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
745 if (target
== targets
[i
])
752 * Test if a target is an array target.
754 * \param target texture target.
756 * \return true if the target is an array target, false otherwise.
759 _mesa_is_array_texture(GLenum target
)
762 case GL_TEXTURE_1D_ARRAY
:
763 case GL_TEXTURE_2D_ARRAY
:
764 case GL_TEXTURE_CUBE_MAP_ARRAY
:
765 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
774 * Return the proxy target which corresponds to the given texture target
777 proxy_target(GLenum target
)
781 case GL_PROXY_TEXTURE_1D
:
782 return GL_PROXY_TEXTURE_1D
;
784 case GL_PROXY_TEXTURE_2D
:
785 return GL_PROXY_TEXTURE_2D
;
787 case GL_PROXY_TEXTURE_3D
:
788 return GL_PROXY_TEXTURE_3D
;
789 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
790 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
791 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
792 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
793 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
794 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
795 case GL_TEXTURE_CUBE_MAP_ARB
:
796 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
797 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
798 case GL_TEXTURE_RECTANGLE_NV
:
799 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
800 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
801 case GL_TEXTURE_1D_ARRAY_EXT
:
802 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
803 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
804 case GL_TEXTURE_2D_ARRAY_EXT
:
805 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
806 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
807 case GL_TEXTURE_CUBE_MAP_ARRAY
:
808 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
809 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
810 case GL_TEXTURE_2D_MULTISAMPLE
:
811 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
812 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
813 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
814 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
815 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
817 _mesa_problem(NULL
, "unexpected target in proxy_target()");
826 * Get a texture image pointer from a texture object, given a texture
827 * target and mipmap level. The target and level parameters should
828 * have already been error-checked.
830 * \param texObj texture unit.
831 * \param target texture target.
832 * \param level image level.
834 * \return pointer to the texture image structure, or NULL on failure.
836 struct gl_texture_image
*
837 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
838 GLenum target
, GLint level
)
840 const GLuint face
= _mesa_tex_target_to_face(target
);
844 assert(level
< MAX_TEXTURE_LEVELS
);
846 return texObj
->Image
[face
][level
];
851 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
852 * it and install it. Only return NULL if passed a bad parameter or run
855 struct gl_texture_image
*
856 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
857 GLenum target
, GLint level
)
859 struct gl_texture_image
*texImage
;
864 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
866 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
868 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
872 set_tex_image(texObj
, target
, level
, texImage
);
880 * Return pointer to the specified proxy texture image.
881 * Note that proxy textures are per-context, not per-texture unit.
882 * \return pointer to texture image or NULL if invalid target, invalid
883 * level, or out of memory.
885 static struct gl_texture_image
*
886 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
888 struct gl_texture_image
*texImage
;
895 case GL_PROXY_TEXTURE_1D
:
896 if (level
>= ctx
->Const
.MaxTextureLevels
)
898 texIndex
= TEXTURE_1D_INDEX
;
900 case GL_PROXY_TEXTURE_2D
:
901 if (level
>= ctx
->Const
.MaxTextureLevels
)
903 texIndex
= TEXTURE_2D_INDEX
;
905 case GL_PROXY_TEXTURE_3D
:
906 if (level
>= ctx
->Const
.Max3DTextureLevels
)
908 texIndex
= TEXTURE_3D_INDEX
;
910 case GL_PROXY_TEXTURE_CUBE_MAP
:
911 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
913 texIndex
= TEXTURE_CUBE_INDEX
;
915 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
918 texIndex
= TEXTURE_RECT_INDEX
;
920 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
921 if (level
>= ctx
->Const
.MaxTextureLevels
)
923 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
925 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
926 if (level
>= ctx
->Const
.MaxTextureLevels
)
928 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
930 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
931 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
933 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
935 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
938 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
940 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
943 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
949 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
951 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
953 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
956 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
957 /* Set the 'back' pointer */
958 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
965 * Get the maximum number of allowed mipmap levels.
967 * \param ctx GL context.
968 * \param target texture target.
970 * \return the maximum number of allowed mipmap levels for the given
971 * texture target, or zero if passed a bad target.
976 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
980 case GL_PROXY_TEXTURE_1D
:
982 case GL_PROXY_TEXTURE_2D
:
983 return ctx
->Const
.MaxTextureLevels
;
985 case GL_PROXY_TEXTURE_3D
:
986 return ctx
->Const
.Max3DTextureLevels
;
987 case GL_TEXTURE_CUBE_MAP
:
988 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
989 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
990 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
991 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
992 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
993 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
994 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
995 return ctx
->Extensions
.ARB_texture_cube_map
996 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
997 case GL_TEXTURE_RECTANGLE_NV
:
998 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
999 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
1000 case GL_TEXTURE_1D_ARRAY_EXT
:
1001 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1002 case GL_TEXTURE_2D_ARRAY_EXT
:
1003 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1004 return ctx
->Extensions
.EXT_texture_array
1005 ? ctx
->Const
.MaxTextureLevels
: 0;
1006 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1007 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1008 return ctx
->Extensions
.ARB_texture_cube_map_array
1009 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1010 case GL_TEXTURE_BUFFER
:
1011 return ctx
->API
== API_OPENGL_CORE
&&
1012 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1013 case GL_TEXTURE_2D_MULTISAMPLE
:
1014 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1015 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1016 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1017 return (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
))
1018 && ctx
->Extensions
.ARB_texture_multisample
1020 case GL_TEXTURE_EXTERNAL_OES
:
1023 return 0; /* bad target */
1029 * Return number of dimensions per mipmap level for the given texture target.
1032 _mesa_get_texture_dimensions(GLenum target
)
1036 case GL_PROXY_TEXTURE_1D
:
1039 case GL_TEXTURE_RECTANGLE
:
1040 case GL_TEXTURE_CUBE_MAP
:
1041 case GL_PROXY_TEXTURE_2D
:
1042 case GL_PROXY_TEXTURE_RECTANGLE
:
1043 case GL_PROXY_TEXTURE_CUBE_MAP
:
1044 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1045 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1046 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1047 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1048 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1049 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1050 case GL_TEXTURE_1D_ARRAY
:
1051 case GL_PROXY_TEXTURE_1D_ARRAY
:
1052 case GL_TEXTURE_EXTERNAL_OES
:
1053 case GL_TEXTURE_2D_MULTISAMPLE
:
1054 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1057 case GL_PROXY_TEXTURE_3D
:
1058 case GL_TEXTURE_2D_ARRAY
:
1059 case GL_PROXY_TEXTURE_2D_ARRAY
:
1060 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1061 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1062 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1063 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1065 case GL_TEXTURE_BUFFER
:
1068 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1076 * Check if a texture target can have more than one layer.
1079 _mesa_tex_target_is_layered(GLenum target
)
1083 case GL_PROXY_TEXTURE_1D
:
1085 case GL_PROXY_TEXTURE_2D
:
1086 case GL_TEXTURE_RECTANGLE
:
1087 case GL_PROXY_TEXTURE_RECTANGLE
:
1088 case GL_TEXTURE_2D_MULTISAMPLE
:
1089 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1090 case GL_TEXTURE_BUFFER
:
1091 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1092 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1093 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1094 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1095 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1096 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1097 case GL_TEXTURE_EXTERNAL_OES
:
1101 case GL_PROXY_TEXTURE_3D
:
1102 case GL_TEXTURE_CUBE_MAP
:
1103 case GL_PROXY_TEXTURE_CUBE_MAP
:
1104 case GL_TEXTURE_1D_ARRAY
:
1105 case GL_PROXY_TEXTURE_1D_ARRAY
:
1106 case GL_TEXTURE_2D_ARRAY
:
1107 case GL_PROXY_TEXTURE_2D_ARRAY
:
1108 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1109 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1110 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1111 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1115 assert(!"Invalid texture target.");
1122 * Return the number of layers present in the given level of an array,
1123 * cubemap or 3D texture. If the texture is not layered return zero.
1126 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1128 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1130 switch (texObj
->Target
) {
1133 case GL_TEXTURE_RECTANGLE
:
1134 case GL_TEXTURE_2D_MULTISAMPLE
:
1135 case GL_TEXTURE_BUFFER
:
1136 case GL_TEXTURE_EXTERNAL_OES
:
1139 case GL_TEXTURE_CUBE_MAP
:
1142 case GL_TEXTURE_1D_ARRAY
: {
1143 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1144 return img
? img
->Height
: 0;
1148 case GL_TEXTURE_2D_ARRAY
:
1149 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1150 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1151 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1152 return img
? img
->Depth
: 0;
1156 assert(!"Invalid texture target.");
1163 * Return the maximum number of mipmap levels for the given target
1164 * and the dimensions.
1165 * The dimensions are expected not to include the border.
1168 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1175 case GL_TEXTURE_1D_ARRAY
:
1176 case GL_PROXY_TEXTURE_1D
:
1177 case GL_PROXY_TEXTURE_1D_ARRAY
:
1180 case GL_TEXTURE_CUBE_MAP
:
1181 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1182 case GL_PROXY_TEXTURE_CUBE_MAP
:
1183 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1187 case GL_TEXTURE_2D_ARRAY
:
1188 case GL_PROXY_TEXTURE_2D
:
1189 case GL_PROXY_TEXTURE_2D_ARRAY
:
1190 size
= MAX2(width
, height
);
1193 case GL_PROXY_TEXTURE_3D
:
1194 size
= MAX3(width
, height
, depth
);
1196 case GL_TEXTURE_RECTANGLE
:
1197 case GL_TEXTURE_EXTERNAL_OES
:
1198 case GL_TEXTURE_2D_MULTISAMPLE
:
1199 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1200 case GL_PROXY_TEXTURE_RECTANGLE
:
1201 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1202 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1209 return _mesa_logbase2(size
) + 1;
1213 #if 000 /* not used anymore */
1215 * glTexImage[123]D can accept a NULL image pointer. In this case we
1216 * create a texture image with unspecified image contents per the OpenGL
1220 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1222 const GLint components
= _mesa_components_in_format(format
);
1223 const GLint numPixels
= width
* height
* depth
;
1224 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1228 * Let's see if anyone finds this. If glTexImage2D() is called with
1229 * a NULL image pointer then load the texture image with something
1230 * interesting instead of leaving it indeterminate.
1233 static const char message
[8][32] = {
1234 " X X XXXXX XXX X ",
1235 " XX XX X X X X X ",
1237 " X X XXXX XXX XXXXX ",
1240 " X X XXXXX XXX X X ",
1244 GLubyte
*imgPtr
= data
;
1246 for (h
= 0; h
< depth
; h
++) {
1247 for (i
= 0; i
< height
; i
++) {
1248 GLint srcRow
= 7 - (i
% 8);
1249 for (j
= 0; j
< width
; j
++) {
1250 GLint srcCol
= j
% 32;
1251 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1252 for (k
= 0; k
< components
; k
++) {
1268 * Set the size and format-related fields of a gl_texture_image struct
1269 * to zero. This is used when a proxy texture test fails.
1272 clear_teximage_fields(struct gl_texture_image
*img
)
1275 img
->_BaseFormat
= 0;
1276 img
->InternalFormat
= 0;
1285 img
->HeightLog2
= 0;
1287 img
->TexFormat
= MESA_FORMAT_NONE
;
1288 img
->NumSamples
= 0;
1289 img
->FixedSampleLocations
= GL_TRUE
;
1294 * Initialize basic fields of the gl_texture_image struct.
1296 * \param ctx GL context.
1297 * \param img texture image structure to be initialized.
1298 * \param width image width.
1299 * \param height image height.
1300 * \param depth image depth.
1301 * \param border image border.
1302 * \param internalFormat internal format.
1303 * \param format the actual hardware format (one of MESA_FORMAT_*)
1304 * \param numSamples number of samples per texel, or zero for non-MS.
1305 * \param fixedSampleLocations are sample locations fixed?
1307 * Fills in the fields of \p img with the given information.
1308 * Note: width, height and depth include the border.
1311 init_teximage_fields_ms(struct gl_context
*ctx
,
1312 struct gl_texture_image
*img
,
1313 GLsizei width
, GLsizei height
, GLsizei depth
,
1314 GLint border
, GLenum internalFormat
,
1316 GLuint numSamples
, GLboolean fixedSampleLocations
)
1321 assert(height
>= 0);
1324 target
= img
->TexObject
->Target
;
1325 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1326 assert(img
->_BaseFormat
!= -1);
1327 img
->InternalFormat
= internalFormat
;
1328 img
->Border
= border
;
1330 img
->Height
= height
;
1333 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1334 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1336 img
->NumSamples
= 0;
1337 img
->FixedSampleLocations
= GL_TRUE
;
1341 case GL_TEXTURE_BUFFER
:
1342 case GL_PROXY_TEXTURE_1D
:
1347 img
->HeightLog2
= 0;
1354 case GL_TEXTURE_1D_ARRAY
:
1355 case GL_PROXY_TEXTURE_1D_ARRAY
:
1356 img
->Height2
= height
; /* no border */
1357 img
->HeightLog2
= 0; /* not used */
1365 case GL_TEXTURE_RECTANGLE
:
1366 case GL_TEXTURE_CUBE_MAP
:
1367 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1368 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1369 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1370 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1371 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1372 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1373 case GL_TEXTURE_EXTERNAL_OES
:
1374 case GL_PROXY_TEXTURE_2D
:
1375 case GL_PROXY_TEXTURE_RECTANGLE
:
1376 case GL_PROXY_TEXTURE_CUBE_MAP
:
1377 case GL_TEXTURE_2D_MULTISAMPLE
:
1378 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1379 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1380 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1387 case GL_TEXTURE_2D_ARRAY
:
1388 case GL_PROXY_TEXTURE_2D_ARRAY
:
1389 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1390 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1391 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1392 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1393 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1394 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1395 img
->Depth2
= depth
; /* no border */
1396 img
->DepthLog2
= 0; /* not used */
1399 case GL_PROXY_TEXTURE_3D
:
1400 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1401 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1402 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1403 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1406 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1411 _mesa_get_tex_max_num_levels(target
,
1412 img
->Width2
, img
->Height2
, img
->Depth2
);
1413 img
->TexFormat
= format
;
1414 img
->NumSamples
= numSamples
;
1415 img
->FixedSampleLocations
= fixedSampleLocations
;
1420 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1421 struct gl_texture_image
*img
,
1422 GLsizei width
, GLsizei height
, GLsizei depth
,
1423 GLint border
, GLenum internalFormat
,
1426 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1427 internalFormat
, format
, 0, GL_TRUE
);
1432 * Free and clear fields of the gl_texture_image struct.
1434 * \param ctx GL context.
1435 * \param texImage texture image structure to be cleared.
1437 * After the call, \p texImage will have no data associated with it. Its
1438 * fields are cleared so that its parent object will test incomplete.
1441 _mesa_clear_texture_image(struct gl_context
*ctx
,
1442 struct gl_texture_image
*texImage
)
1444 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1445 clear_teximage_fields(texImage
);
1450 * Check the width, height, depth and border of a texture image are legal.
1451 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1453 * The target and level parameters will have already been validated.
1454 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1457 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1458 GLint level
, GLint width
, GLint height
,
1459 GLint depth
, GLint border
)
1465 case GL_PROXY_TEXTURE_1D
:
1466 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1467 maxSize
>>= level
; /* level size */
1468 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1470 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1471 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1477 case GL_PROXY_TEXTURE_2D
:
1478 case GL_TEXTURE_2D_MULTISAMPLE
:
1479 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1480 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1482 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1484 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1486 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1487 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1489 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1495 case GL_PROXY_TEXTURE_3D
:
1496 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1498 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1500 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1502 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1504 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1505 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1507 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1509 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1514 case GL_TEXTURE_RECTANGLE_NV
:
1515 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1518 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1519 if (width
< 0 || width
> maxSize
)
1521 if (height
< 0 || height
> maxSize
)
1525 case GL_TEXTURE_CUBE_MAP
:
1526 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1527 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1528 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1529 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1530 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1531 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1532 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1533 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1535 if (width
!= height
)
1537 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1539 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1541 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1542 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1544 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1549 case GL_TEXTURE_1D_ARRAY_EXT
:
1550 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1551 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1553 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1555 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1557 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1558 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1563 case GL_TEXTURE_2D_ARRAY_EXT
:
1564 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1565 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1566 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1567 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1569 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1571 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1573 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1575 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1576 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1578 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1583 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1584 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1585 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1586 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1588 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1590 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1592 if (width
!= height
)
1594 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1596 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1597 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1599 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1604 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1611 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1612 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1613 * \param destImage the destination texture image.
1614 * \return GL_TRUE if error found, GL_FALSE otherwise.
1617 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1618 const struct gl_texture_image
*destImage
,
1619 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1620 GLsizei subWidth
, GLsizei subHeight
,
1621 GLsizei subDepth
, const char *func
)
1623 const GLenum target
= destImage
->TexObject
->Target
;
1628 _mesa_error(ctx
, GL_INVALID_VALUE
,
1629 "%s(width=%d)", func
, subWidth
);
1633 if (dims
> 1 && subHeight
< 0) {
1634 _mesa_error(ctx
, GL_INVALID_VALUE
,
1635 "%s(height=%d)", func
, subHeight
);
1639 if (dims
> 2 && subDepth
< 0) {
1640 _mesa_error(ctx
, GL_INVALID_VALUE
,
1641 "%s(depth=%d)", func
, subDepth
);
1645 /* check xoffset and width */
1646 if (xoffset
< - (GLint
) destImage
->Border
) {
1647 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset)", func
);
1651 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1652 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset+width)", func
);
1656 /* check yoffset and height */
1658 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1659 if (yoffset
< -yBorder
) {
1660 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset)", func
);
1663 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1664 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset+height)", func
);
1669 /* check zoffset and depth */
1672 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1673 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1674 0 : destImage
->Border
;
1676 if (zoffset
< -zBorder
) {
1677 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset)", func
);
1681 depth
= (GLint
) destImage
->Depth
;
1682 if (target
== GL_TEXTURE_CUBE_MAP
)
1684 if (zoffset
+ subDepth
> depth
) {
1685 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset+depth)", func
);
1691 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1692 * compressed texture images can be updated. But, that restriction may be
1693 * relaxed for particular compressed formats. At this time, all the
1694 * compressed formats supported by Mesa allow sub-textures to be updated
1695 * along compressed block boundaries.
1697 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1699 if (bw
!= 1 || bh
!= 1) {
1700 /* offset must be multiple of block size */
1701 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1702 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1703 "%s(xoffset = %d, yoffset = %d)",
1704 func
, xoffset
, yoffset
);
1708 /* The size must be a multiple of bw x bh, or we must be using a
1709 * offset+size that exactly hits the edge of the image. This
1710 * is important for small mipmap levels (1x1, 2x1, etc) and for
1713 if ((subWidth
% bw
!= 0) &&
1714 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1715 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1716 "%s(width = %d)", func
, subWidth
);
1720 if ((subHeight
% bh
!= 0) &&
1721 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1722 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1723 "%s(height = %d)", func
, subHeight
);
1735 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1736 * specific texture image size checks.
1738 * A hardware driver might override this function if, for example, the
1739 * max 3D texture size is 512x512x64 (i.e. not a cube).
1741 * Note that width, height, depth == 0 is not an error. However, a
1742 * texture with zero width/height/depth will be considered "incomplete"
1743 * and texturing will effectively be disabled.
1745 * \param target any texture target/type
1746 * \param level as passed to glTexImage
1747 * \param format the MESA_FORMAT_x for the tex image
1748 * \param width as passed to glTexImage
1749 * \param height as passed to glTexImage
1750 * \param depth as passed to glTexImage
1751 * \param border as passed to glTexImage
1752 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1755 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1757 GLint width
, GLint height
, GLint depth
, GLint border
)
1759 /* We just check if the image size is less than MaxTextureMbytes.
1760 * Some drivers may do more specific checks.
1762 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1763 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1764 mbytes
*= _mesa_num_tex_faces(target
);
1765 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1770 * Return true if the format is only valid for glCompressedTexImage.
1773 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1776 case GL_ETC1_RGB8_OES
:
1777 case GL_PALETTE4_RGB8_OES
:
1778 case GL_PALETTE4_RGBA8_OES
:
1779 case GL_PALETTE4_R5_G6_B5_OES
:
1780 case GL_PALETTE4_RGBA4_OES
:
1781 case GL_PALETTE4_RGB5_A1_OES
:
1782 case GL_PALETTE8_RGB8_OES
:
1783 case GL_PALETTE8_RGBA8_OES
:
1784 case GL_PALETTE8_R5_G6_B5_OES
:
1785 case GL_PALETTE8_RGBA4_OES
:
1786 case GL_PALETTE8_RGB5_A1_OES
:
1794 * Return true if the format doesn't support online compression.
1797 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
)
1799 return _mesa_is_astc_format(format
) ||
1800 compressedteximage_only_format(ctx
, format
);
1803 /* Writes to an GL error pointer if non-null and returns whether or not the
1804 * error is GL_NO_ERROR */
1806 write_error(GLenum
*err_ptr
, GLenum error
)
1811 return error
== GL_NO_ERROR
;
1815 * Helper function to determine whether a target and specific compression
1816 * format are supported. The error parameter returns GL_NO_ERROR if the
1817 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1818 * or GL_INVALID_ENUM, whichever is more appropriate.
1821 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1822 GLenum intFormat
, GLenum
*error
)
1824 GLboolean target_can_be_compresed
= GL_FALSE
;
1825 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1826 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1830 case GL_PROXY_TEXTURE_2D
:
1831 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1833 case GL_PROXY_TEXTURE_CUBE_MAP
:
1834 case GL_TEXTURE_CUBE_MAP
:
1835 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1836 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1837 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1838 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1839 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1840 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1841 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1843 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1844 case GL_TEXTURE_2D_ARRAY_EXT
:
1845 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1847 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1848 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1849 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1851 * "The ETC2/EAC texture compression algorithm supports only
1852 * two-dimensional images. If internalformat is an ETC2/EAC format,
1853 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1854 * target is not TEXTURE_2D_ARRAY."
1856 * This should also be applicable for glTexStorage3D(). Other available
1857 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1859 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
))
1860 return write_error(error
, GL_INVALID_OPERATION
);
1862 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map_array
;
1864 /* From the KHR_texture_compression_astc_hdr spec:
1866 * Add a second new column "3D Tex." which is empty for all non-ASTC
1867 * formats. If only the LDR profile is supported by the
1868 * implementation, this column is also empty for all ASTC formats. If
1869 * both the LDR and HDR profiles are supported only, this column is
1870 * checked for all ASTC formats.
1872 * Add a third new column "Cube Map Array Tex." which is empty for all
1873 * non-ASTC formats, and checked for all ASTC formats.
1877 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1878 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1879 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1880 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1881 * 8.19 is *not* checked'
1883 * The instances of <internalformat> above should say <target>.
1886 /* Throw an INVALID_OPERATION error if the target is
1887 * TEXTURE_CUBE_MAP_ARRAY and the format is not ASTC.
1889 if (target_can_be_compresed
&&
1890 ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
1891 layout
!= MESA_FORMAT_LAYOUT_ASTC
)
1892 return write_error(error
, GL_INVALID_OPERATION
);
1897 case MESA_FORMAT_LAYOUT_ETC2
:
1898 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1899 if (_mesa_is_gles3(ctx
))
1900 return write_error(error
, GL_INVALID_OPERATION
);
1902 case MESA_FORMAT_LAYOUT_BPTC
:
1903 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1905 case MESA_FORMAT_LAYOUT_ASTC
:
1906 target_can_be_compresed
=
1907 ctx
->Extensions
.KHR_texture_compression_astc_hdr
;
1909 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1910 * and the hdr extension is not supported.
1911 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1913 if (!target_can_be_compresed
)
1914 return write_error(error
, GL_INVALID_OPERATION
);
1917 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1918 * the format is not ASTC.
1919 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1921 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
)
1922 return write_error(error
, GL_INVALID_OPERATION
);
1928 return write_error(error
,
1929 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1934 * Check if the given texture target value is legal for a
1935 * glTexImage1/2/3D call.
1938 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1944 case GL_PROXY_TEXTURE_1D
:
1945 return _mesa_is_desktop_gl(ctx
);
1953 case GL_PROXY_TEXTURE_2D
:
1954 return _mesa_is_desktop_gl(ctx
);
1955 case GL_PROXY_TEXTURE_CUBE_MAP
:
1956 return _mesa_is_desktop_gl(ctx
)
1957 && ctx
->Extensions
.ARB_texture_cube_map
;
1958 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1959 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1960 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1961 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1962 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1963 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1964 return ctx
->Extensions
.ARB_texture_cube_map
;
1965 case GL_TEXTURE_RECTANGLE_NV
:
1966 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1967 return _mesa_is_desktop_gl(ctx
)
1968 && ctx
->Extensions
.NV_texture_rectangle
;
1969 case GL_TEXTURE_1D_ARRAY_EXT
:
1970 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1971 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1979 case GL_PROXY_TEXTURE_3D
:
1980 return _mesa_is_desktop_gl(ctx
);
1981 case GL_TEXTURE_2D_ARRAY_EXT
:
1982 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1983 || _mesa_is_gles3(ctx
);
1984 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1985 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1986 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1987 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1988 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1993 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
2000 * Check if the given texture target value is legal for a
2001 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
2002 * The difference compared to legal_teximage_target() above is that
2003 * proxy targets are not supported.
2006 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
2011 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
2016 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2017 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2018 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2019 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2020 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2021 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2022 return ctx
->Extensions
.ARB_texture_cube_map
;
2023 case GL_TEXTURE_RECTANGLE_NV
:
2024 return _mesa_is_desktop_gl(ctx
)
2025 && ctx
->Extensions
.NV_texture_rectangle
;
2026 case GL_TEXTURE_1D_ARRAY_EXT
:
2027 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
2035 case GL_TEXTURE_2D_ARRAY_EXT
:
2036 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
2037 || _mesa_is_gles3(ctx
);
2038 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2039 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
2040 return ctx
->Extensions
.ARB_texture_cube_map_array
;
2042 /* Table 8.15 of the OpenGL 4.5 core profile spec
2043 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
2044 * and CopyTextureSubImage3D.
2046 case GL_TEXTURE_CUBE_MAP
:
2052 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
2060 * Helper function to determine if a texture object is mutable (in terms
2061 * of GL_ARB_texture_storage).
2064 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
2066 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
2070 return !texObj
->Immutable
;
2075 * Return expected size of a compressed texture.
2078 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2081 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2082 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2086 * Verify that a texture format is valid with a particular target
2088 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
2089 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
2092 * \param ctx GL context
2093 * \param target Texture target
2094 * \param internalFormat Internal format of the texture image
2095 * \param dimensions Dimensionality at the caller. This is \b not used
2096 * in the validation. It is only used when logging
2098 * \param caller Base name of the calling function (e.g.,
2099 * "glTexImage" or "glTexStorage").
2101 * \returns true if the combination is legal, false otherwise.
2104 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
2105 GLenum target
, GLenum internalFormat
,
2106 unsigned dimensions
,
2109 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2110 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
2111 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
2112 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
2113 * Profile spec says:
2115 * "Textures with a base internal format of DEPTH_COMPONENT or
2116 * DEPTH_STENCIL are supported by texture image specification
2117 * commands only if target is TEXTURE_1D, TEXTURE_2D,
2118 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
2119 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
2120 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
2121 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
2122 * formats in conjunction with any other target will result in an
2123 * INVALID_OPERATION error."
2125 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
2126 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
2128 if (target
!= GL_TEXTURE_1D
&&
2129 target
!= GL_PROXY_TEXTURE_1D
&&
2130 target
!= GL_TEXTURE_2D
&&
2131 target
!= GL_PROXY_TEXTURE_2D
&&
2132 target
!= GL_TEXTURE_1D_ARRAY
&&
2133 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2134 target
!= GL_TEXTURE_2D_ARRAY
&&
2135 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2136 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2137 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2138 !((_mesa_is_cube_face(target
) ||
2139 target
== GL_TEXTURE_CUBE_MAP
||
2140 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2141 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2142 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2143 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2144 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2145 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2146 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2147 "%s%dD(bad target for depth texture)",
2148 caller
, dimensions
);
2157 texture_formats_agree(GLenum internalFormat
,
2160 GLboolean colorFormat
;
2161 GLboolean is_format_depth_or_depthstencil
;
2162 GLboolean is_internalFormat_depth_or_depthstencil
;
2164 /* Even though there are no color-index textures, we still have to support
2165 * uploading color-index data and remapping it to RGB via the
2166 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2168 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2170 is_internalFormat_depth_or_depthstencil
=
2171 _mesa_is_depth_format(internalFormat
) ||
2172 _mesa_is_depthstencil_format(internalFormat
);
2174 is_format_depth_or_depthstencil
=
2175 _mesa_is_depth_format(format
) ||
2176 _mesa_is_depthstencil_format(format
);
2178 colorFormat
= _mesa_is_color_format(format
);
2180 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2183 if (is_internalFormat_depth_or_depthstencil
!=
2184 is_format_depth_or_depthstencil
)
2187 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2194 * Test the combination of format, type and internal format arguments of
2195 * different texture operations on GLES.
2197 * \param ctx GL context.
2198 * \param format pixel data format given by the user.
2199 * \param type pixel data type given by the user.
2200 * \param internalFormat internal format given by the user.
2201 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2202 * \param callerName name of the caller function to print in the error message
2204 * \return true if a error is found, false otherwise
2206 * Currently, it is used by texture_error_check() and texsubimage_error_check().
2209 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
2210 GLenum type
, GLenum internalFormat
,
2211 GLuint dimensions
, const char *callerName
)
2215 if (_mesa_is_gles3(ctx
)) {
2216 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
2218 if (err
!= GL_NO_ERROR
) {
2219 _mesa_error(ctx
, err
,
2220 "%s(format = %s, type = %s, internalformat = %s)",
2221 callerName
, _mesa_enum_to_string(format
),
2222 _mesa_enum_to_string(type
),
2223 _mesa_enum_to_string(internalFormat
));
2228 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2229 if (err
!= GL_NO_ERROR
) {
2230 _mesa_error(ctx
, err
, "%s(format = %s, type = %s)",
2231 callerName
, _mesa_enum_to_string(format
),
2232 _mesa_enum_to_string(type
));
2241 * Test the glTexImage[123]D() parameters for errors.
2243 * \param ctx GL context.
2244 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2245 * \param target texture target given by the user (already validated).
2246 * \param level image level given by the user.
2247 * \param internalFormat internal format given by the user.
2248 * \param format pixel data format given by the user.
2249 * \param type pixel data type given by the user.
2250 * \param width image width given by the user.
2251 * \param height image height given by the user.
2252 * \param depth image depth given by the user.
2253 * \param border image border given by the user.
2255 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2257 * Verifies each of the parameters against the constants specified in
2258 * __struct gl_contextRec::Const and the supported extensions, and according
2259 * to the OpenGL specification.
2260 * Note that we don't fully error-check the width, height, depth values
2261 * here. That's done in _mesa_legal_texture_dimensions() which is used
2262 * by several other GL entrypoints. Plus, texture dims have a special
2263 * interaction with proxy textures.
2266 texture_error_check( struct gl_context
*ctx
,
2267 GLuint dimensions
, GLenum target
,
2268 GLint level
, GLint internalFormat
,
2269 GLenum format
, GLenum type
,
2270 GLint width
, GLint height
,
2271 GLint depth
, GLint border
,
2272 const GLvoid
*pixels
)
2276 /* Note: for proxy textures, some error conditions immediately generate
2277 * a GL error in the usual way. But others do not generate a GL error.
2278 * Instead, they cause the width, height, depth, format fields of the
2279 * texture image to be zeroed-out. The GL spec seems to indicate that the
2280 * zero-out behaviour is only used in cases related to memory allocation.
2284 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2285 _mesa_error(ctx
, GL_INVALID_VALUE
,
2286 "glTexImage%dD(level=%d)", dimensions
, level
);
2291 if (border
< 0 || border
> 1 ||
2292 ((ctx
->API
!= API_OPENGL_COMPAT
||
2293 target
== GL_TEXTURE_RECTANGLE_NV
||
2294 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2295 _mesa_error(ctx
, GL_INVALID_VALUE
,
2296 "glTexImage%dD(border=%d)", dimensions
, border
);
2300 if (width
< 0 || height
< 0 || depth
< 0) {
2301 _mesa_error(ctx
, GL_INVALID_VALUE
,
2302 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2306 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2307 * combinations of format, internalFormat, and type that can be used.
2308 * Formats and types that require additional extensions (e.g., GL_FLOAT
2309 * requires GL_OES_texture_float) are filtered elsewhere.
2311 if (_mesa_is_gles(ctx
) &&
2312 texture_format_error_check_gles(ctx
, format
, type
, internalFormat
,
2313 dimensions
, "glTexImage%dD")) {
2317 /* Check internalFormat */
2318 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2319 _mesa_error(ctx
, GL_INVALID_VALUE
,
2320 "glTexImage%dD(internalFormat=%s)",
2321 dimensions
, _mesa_enum_to_string(internalFormat
));
2325 /* Check incoming image format and type */
2326 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2327 if (err
!= GL_NO_ERROR
) {
2328 _mesa_error(ctx
, err
,
2329 "glTexImage%dD(incompatible format = %s, type = %s)",
2330 dimensions
, _mesa_enum_to_string(format
),
2331 _mesa_enum_to_string(type
));
2335 /* validate the bound PBO, if any */
2336 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2337 width
, height
, depth
, format
, type
,
2338 INT_MAX
, pixels
, "glTexImage")) {
2342 /* make sure internal format and format basically agree */
2343 if (!texture_formats_agree(internalFormat
, format
)) {
2344 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2345 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2346 dimensions
, _mesa_enum_to_string(internalFormat
),
2347 _mesa_enum_to_string(format
));
2351 /* additional checks for ycbcr textures */
2352 if (internalFormat
== GL_YCBCR_MESA
) {
2353 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
2354 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2355 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2357 _mesa_snprintf(message
, sizeof(message
),
2358 "glTexImage%dD(format/type YCBCR mismatch)",
2360 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2361 return GL_TRUE
; /* error */
2363 if (target
!= GL_TEXTURE_2D
&&
2364 target
!= GL_PROXY_TEXTURE_2D
&&
2365 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2366 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2367 _mesa_error(ctx
, GL_INVALID_ENUM
,
2368 "glTexImage%dD(bad target for YCbCr texture)",
2374 _mesa_snprintf(message
, sizeof(message
),
2375 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2376 dimensions
, border
);
2377 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2382 /* additional checks for depth textures */
2383 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2384 dimensions
, "glTexImage"))
2387 /* additional checks for compressed textures */
2388 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2390 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2391 _mesa_error(ctx
, err
,
2392 "glTexImage%dD(target can't be compressed)", dimensions
);
2395 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2396 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2397 "glTexImage%dD(no compression for format)", dimensions
);
2401 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2402 "glTexImage%dD(border!=0)", dimensions
);
2407 /* additional checks for integer textures */
2408 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2409 (_mesa_is_enum_format_integer(format
) !=
2410 _mesa_is_enum_format_integer(internalFormat
))) {
2411 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2412 "glTexImage%dD(integer/non-integer format mismatch)",
2417 if (!mutable_tex_object(ctx
, target
)) {
2418 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2419 "glTexImage%dD(immutable texture)", dimensions
);
2423 /* if we get here, the parameters are OK */
2429 * Error checking for glCompressedTexImage[123]D().
2430 * Note that the width, height and depth values are not fully error checked
2432 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2435 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2436 GLenum target
, GLint level
,
2437 GLenum internalFormat
, GLsizei width
,
2438 GLsizei height
, GLsizei depth
, GLint border
,
2439 GLsizei imageSize
, const GLvoid
*data
)
2441 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2443 GLenum error
= GL_NO_ERROR
;
2444 char *reason
= ""; /* no error */
2446 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
2451 /* This will detect any invalid internalFormat value */
2452 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2453 _mesa_error(ctx
, GL_INVALID_ENUM
,
2454 "glCompressedTexImage%dD(internalFormat=%s)",
2455 dimensions
, _mesa_enum_to_string(internalFormat
));
2459 /* validate the bound PBO, if any */
2460 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2462 "glCompressedTexImage")) {
2466 switch (internalFormat
) {
2467 case GL_PALETTE4_RGB8_OES
:
2468 case GL_PALETTE4_RGBA8_OES
:
2469 case GL_PALETTE4_R5_G6_B5_OES
:
2470 case GL_PALETTE4_RGBA4_OES
:
2471 case GL_PALETTE4_RGB5_A1_OES
:
2472 case GL_PALETTE8_RGB8_OES
:
2473 case GL_PALETTE8_RGBA8_OES
:
2474 case GL_PALETTE8_R5_G6_B5_OES
:
2475 case GL_PALETTE8_RGBA4_OES
:
2476 case GL_PALETTE8_RGB5_A1_OES
:
2477 /* check level (note that level should be zero or less!) */
2478 if (level
> 0 || level
< -maxLevels
) {
2480 error
= GL_INVALID_VALUE
;
2484 if (dimensions
!= 2) {
2485 reason
= "compressed paletted textures must be 2D";
2486 error
= GL_INVALID_OPERATION
;
2490 /* Figure out the expected texture size (in bytes). This will be
2491 * checked against the actual size later.
2493 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2496 /* This is for the benefit of the TestProxyTexImage below. It expects
2497 * level to be non-negative. OES_compressed_paletted_texture uses a
2498 * weird mechanism where the level specified to glCompressedTexImage2D
2499 * is -(n-1) number of levels in the texture, and the data specifies the
2500 * complete mipmap stack. This is done to ensure the palette is the
2501 * same for all levels.
2508 if (level
< 0 || level
>= maxLevels
) {
2510 error
= GL_INVALID_VALUE
;
2514 /* Figure out the expected texture size (in bytes). This will be
2515 * checked against the actual size later.
2517 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2521 /* This should really never fail */
2522 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2523 reason
= "internalFormat";
2524 error
= GL_INVALID_ENUM
;
2528 /* No compressed formats support borders at this time */
2530 reason
= "border != 0";
2531 error
= GL_INVALID_VALUE
;
2535 /* Check for invalid pixel storage modes */
2536 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2538 "glCompressedTexImage")) {
2542 /* check image size in bytes */
2543 if (expectedSize
!= imageSize
) {
2544 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2545 * if <imageSize> is not consistent with the format, dimensions, and
2546 * contents of the specified image.
2548 reason
= "imageSize inconsistant with width/height/format";
2549 error
= GL_INVALID_VALUE
;
2553 if (!mutable_tex_object(ctx
, target
)) {
2554 reason
= "immutable texture";
2555 error
= GL_INVALID_OPERATION
;
2562 /* Note: not all error paths exit through here. */
2563 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2564 dimensions
, reason
);
2571 * Test glTexSubImage[123]D() parameters for errors.
2573 * \param ctx GL context.
2574 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2575 * \param target texture target given by the user (already validated)
2576 * \param level image level given by the user.
2577 * \param xoffset sub-image x offset given by the user.
2578 * \param yoffset sub-image y offset given by the user.
2579 * \param zoffset sub-image z offset given by the user.
2580 * \param format pixel data format given by the user.
2581 * \param type pixel data type given by the user.
2582 * \param width image width given by the user.
2583 * \param height image height given by the user.
2584 * \param depth image depth given by the user.
2586 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2588 * Verifies each of the parameters against the constants specified in
2589 * __struct gl_contextRec::Const and the supported extensions, and according
2590 * to the OpenGL specification.
2593 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2594 struct gl_texture_object
*texObj
,
2595 GLenum target
, GLint level
,
2596 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2597 GLint width
, GLint height
, GLint depth
,
2598 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2599 bool dsa
, const char *callerName
)
2601 struct gl_texture_image
*texImage
;
2605 /* must be out of memory */
2606 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2611 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2612 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2616 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2618 /* non-existant texture level */
2619 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture image)",
2624 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2625 if (err
!= GL_NO_ERROR
) {
2626 _mesa_error(ctx
, err
,
2627 "%s(incompatible format = %s, type = %s)",
2628 callerName
, _mesa_enum_to_string(format
),
2629 _mesa_enum_to_string(type
));
2633 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2634 * combinations of format, internalFormat, and type that can be used.
2635 * Formats and types that require additional extensions (e.g., GL_FLOAT
2636 * requires GL_OES_texture_float) are filtered elsewhere.
2638 if (_mesa_is_gles(ctx
) &&
2639 texture_format_error_check_gles(ctx
, format
, type
,
2640 texImage
->InternalFormat
,
2641 dimensions
, callerName
)) {
2645 /* validate the bound PBO, if any */
2646 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2647 width
, height
, depth
, format
, type
,
2648 INT_MAX
, pixels
, callerName
)) {
2652 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2653 texImage
, xoffset
, yoffset
, zoffset
,
2654 width
, height
, depth
, callerName
)) {
2658 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2659 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2660 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2661 "%s(no compression for format)", callerName
);
2666 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2667 /* both source and dest must be integer-valued, or neither */
2668 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2669 _mesa_is_enum_format_integer(format
)) {
2670 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2671 "%s(integer/non-integer format mismatch)", callerName
);
2681 * Test glCopyTexImage[12]D() parameters for errors.
2683 * \param ctx GL context.
2684 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2685 * \param target texture target given by the user.
2686 * \param level image level given by the user.
2687 * \param internalFormat internal format given by the user.
2688 * \param width image width given by the user.
2689 * \param height image height given by the user.
2690 * \param border texture border.
2692 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2694 * Verifies each of the parameters against the constants specified in
2695 * __struct gl_contextRec::Const and the supported extensions, and according
2696 * to the OpenGL specification.
2699 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2700 GLenum target
, GLint level
, GLint internalFormat
,
2701 GLint width
, GLint height
, GLint border
)
2704 GLint rb_base_format
;
2705 struct gl_renderbuffer
*rb
;
2706 GLenum rb_internal_format
;
2709 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2710 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2711 dimensions
, _mesa_enum_to_string(target
));
2716 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2717 _mesa_error(ctx
, GL_INVALID_VALUE
,
2718 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2722 /* Check that the source buffer is complete */
2723 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2724 if (ctx
->ReadBuffer
->_Status
== 0) {
2725 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2727 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2728 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2729 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2733 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2734 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2735 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2741 if (border
< 0 || border
> 1 ||
2742 ((ctx
->API
!= API_OPENGL_COMPAT
||
2743 target
== GL_TEXTURE_RECTANGLE_NV
||
2744 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2745 _mesa_error(ctx
, GL_INVALID_VALUE
,
2746 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2750 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2753 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2754 switch (internalFormat
) {
2759 case GL_LUMINANCE_ALPHA
:
2762 _mesa_error(ctx
, GL_INVALID_ENUM
,
2763 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2764 _mesa_enum_to_string(internalFormat
));
2769 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2770 if (baseFormat
< 0) {
2771 _mesa_error(ctx
, GL_INVALID_ENUM
,
2772 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2773 _mesa_enum_to_string(internalFormat
));
2777 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2779 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2780 "glCopyTexImage%dD(read buffer)", dimensions
);
2784 rb_internal_format
= rb
->InternalFormat
;
2785 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2786 if (_mesa_is_color_format(internalFormat
)) {
2787 if (rb_base_format
< 0) {
2788 _mesa_error(ctx
, GL_INVALID_VALUE
,
2789 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2790 _mesa_enum_to_string(internalFormat
));
2795 if (_mesa_is_gles(ctx
)) {
2797 if (_mesa_base_format_component_count(baseFormat
) >
2798 _mesa_base_format_component_count(rb_base_format
)) {
2801 if (baseFormat
== GL_DEPTH_COMPONENT
||
2802 baseFormat
== GL_DEPTH_STENCIL
||
2803 rb_base_format
== GL_DEPTH_COMPONENT
||
2804 rb_base_format
== GL_DEPTH_STENCIL
||
2805 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2806 baseFormat
== GL_ALPHA
) &&
2807 rb_base_format
!= GL_RGBA
) ||
2808 internalFormat
== GL_RGB9_E5
) {
2811 if (internalFormat
== GL_RGB9_E5
) {
2815 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2816 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2817 _mesa_enum_to_string(internalFormat
));
2822 if (_mesa_is_gles3(ctx
)) {
2823 bool rb_is_srgb
= false;
2824 bool dst_is_srgb
= false;
2826 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2827 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2831 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2835 if (rb_is_srgb
!= dst_is_srgb
) {
2836 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2837 * OpenGLES 3.0.0 spec says:
2839 * "The error INVALID_OPERATION is also generated if the
2840 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2841 * framebuffer attachment corresponding to the read buffer
2842 * is LINEAR (see section 6.1.13) and internalformat is
2843 * one of the sRGB formats described in section 3.8.16, or
2844 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2845 * SRGB and internalformat is not one of the sRGB formats."
2847 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2848 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2852 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2853 * types for SNORM formats. Also, conversion to SNORM formats is not
2854 * allowed by Table 3.2 on Page 110.
2856 if (_mesa_is_enum_format_snorm(internalFormat
)) {
2857 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2858 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2859 _mesa_enum_to_string(internalFormat
));
2864 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2865 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2866 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2870 /* From the EXT_texture_integer spec:
2872 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2873 * if the texture internalformat is an integer format and the read color
2874 * buffer is not an integer format, or if the internalformat is not an
2875 * integer format and the read color buffer is an integer format."
2877 if (_mesa_is_color_format(internalFormat
)) {
2878 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2879 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2880 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2881 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2882 if (is_int
|| is_rbint
) {
2883 if (is_int
!= is_rbint
) {
2884 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2885 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2887 } else if (_mesa_is_gles(ctx
) &&
2888 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2889 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2890 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2891 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2896 /* From page 138 of OpenGL ES 3.0 spec:
2897 * "The error INVALID_OPERATION is generated if floating-point RGBA
2898 * data is required; if signed integer RGBA data is required and the
2899 * format of the current color buffer is not signed integer; if
2900 * unsigned integer RGBA data is required and the format of the
2901 * current color buffer is not unsigned integer; or if fixed-point
2902 * RGBA data is required and the format of the current color buffer
2903 * is not fixed-point.
2905 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2906 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2907 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2910 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2912 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2913 _mesa_error(ctx
, err
,
2914 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2917 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2918 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2919 "glCopyTexImage%dD(no compression for format)", dimensions
);
2923 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2924 "glCopyTexImage%dD(border!=0)", dimensions
);
2929 if (!mutable_tex_object(ctx
, target
)) {
2930 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2931 "glCopyTexImage%dD(immutable texture)", dimensions
);
2935 /* if we get here, the parameters are OK */
2941 * Test glCopyTexSubImage[12]D() parameters for errors.
2942 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2945 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2946 const struct gl_texture_object
*texObj
,
2947 GLenum target
, GLint level
,
2948 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2949 GLint width
, GLint height
, const char *caller
)
2951 struct gl_texture_image
*texImage
;
2953 /* Check that the source buffer is complete */
2954 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2955 if (ctx
->ReadBuffer
->_Status
== 0) {
2956 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2958 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2959 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2960 "%s(invalid readbuffer)", caller
);
2964 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2965 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2966 "%s(multisample FBO)", caller
);
2972 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2973 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2977 /* Get dest image pointers */
2979 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", caller
);
2983 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2985 /* destination image does not exist */
2986 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2987 "%s(invalid texture image)", caller
);
2991 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2992 xoffset
, yoffset
, zoffset
,
2993 width
, height
, 1, caller
)) {
2997 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2998 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2999 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3000 "%s(no compression for format)", caller
);
3005 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
3006 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
3010 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
3011 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3012 "%s(missing readbuffer, format=0x%x)", caller
,
3013 texImage
->_BaseFormat
);
3017 /* From the EXT_texture_integer spec:
3019 * "INVALID_OPERATION is generated by CopyTexImage* and
3020 * CopyTexSubImage* if the texture internalformat is an integer format
3021 * and the read color buffer is not an integer format, or if the
3022 * internalformat is not an integer format and the read color buffer
3023 * is an integer format."
3025 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
3026 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
3028 if (_mesa_is_format_integer_color(rb
->Format
) !=
3029 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
3030 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3031 "%s(integer vs non-integer)", caller
);
3036 /* if we get here, the parameters are OK */
3041 /** Callback info for walking over FBO hash table */
3044 struct gl_context
*ctx
;
3045 struct gl_texture_object
*texObj
;
3051 * Check render to texture callback. Called from _mesa_HashWalk().
3054 check_rtt_cb(GLuint key
, void *data
, void *userData
)
3056 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
3057 const struct cb_info
*info
= (struct cb_info
*) userData
;
3058 struct gl_context
*ctx
= info
->ctx
;
3059 const struct gl_texture_object
*texObj
= info
->texObj
;
3060 const GLuint level
= info
->level
, face
= info
->face
;
3062 /* If this is a user-created FBO */
3063 if (_mesa_is_user_fbo(fb
)) {
3065 /* check if any of the FBO's attachments point to 'texObj' */
3066 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
3067 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
3068 if (att
->Type
== GL_TEXTURE
&&
3069 att
->Texture
== texObj
&&
3070 att
->TextureLevel
== level
&&
3071 att
->CubeMapFace
== face
) {
3072 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
3073 assert(att
->Renderbuffer
->TexImage
);
3074 /* Mark fb status as indeterminate to force re-validation */
3083 * When a texture image is specified we have to check if it's bound to
3084 * any framebuffer objects (render to texture) in order to detect changes
3085 * in size or format since that effects FBO completeness.
3086 * Any FBOs rendering into the texture must be re-validated.
3089 _mesa_update_fbo_texture(struct gl_context
*ctx
,
3090 struct gl_texture_object
*texObj
,
3091 GLuint face
, GLuint level
)
3093 /* Only check this texture if it's been marked as RenderToTexture */
3094 if (texObj
->_RenderToTexture
) {
3095 struct cb_info info
;
3097 info
.texObj
= texObj
;
3100 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
3106 * If the texture object's GenerateMipmap flag is set and we've
3107 * changed the texture base level image, regenerate the rest of the
3108 * mipmap levels now.
3111 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
3112 struct gl_texture_object
*texObj
, GLint level
)
3114 if (texObj
->GenerateMipmap
&&
3115 level
== texObj
->BaseLevel
&&
3116 level
< texObj
->MaxLevel
) {
3117 assert(ctx
->Driver
.GenerateMipmap
);
3118 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3123 /** Debug helper: override the user-requested internal format */
3125 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
3128 if (internalFormat
== GL_RGBA16F_ARB
||
3129 internalFormat
== GL_RGBA32F_ARB
) {
3130 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3133 else if (internalFormat
== GL_RGB16F_ARB
||
3134 internalFormat
== GL_RGB32F_ARB
) {
3135 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3138 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3139 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3140 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3141 return GL_LUMINANCE_ALPHA
;
3143 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3144 internalFormat
== GL_LUMINANCE32F_ARB
) {
3145 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3146 return GL_LUMINANCE
;
3148 else if (internalFormat
== GL_ALPHA16F_ARB
||
3149 internalFormat
== GL_ALPHA32F_ARB
) {
3150 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3154 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3155 internalFormat = GL_RGBA;
3159 return internalFormat
;
3162 return internalFormat
;
3168 * Choose the actual hardware format for a texture image.
3169 * Try to use the same format as the previous image level when possible.
3170 * Otherwise, ask the driver for the best format.
3171 * It's important to try to choose a consistant format for all levels
3172 * for efficient texture memory layout/allocation. In particular, this
3173 * comes up during automatic mipmap generation.
3176 _mesa_choose_texture_format(struct gl_context
*ctx
,
3177 struct gl_texture_object
*texObj
,
3178 GLenum target
, GLint level
,
3179 GLenum internalFormat
, GLenum format
, GLenum type
)
3183 /* see if we've already chosen a format for the previous level */
3185 struct gl_texture_image
*prevImage
=
3186 _mesa_select_tex_image(texObj
, target
, level
- 1);
3187 /* See if the prev level is defined and has an internal format which
3188 * matches the new internal format.
3191 prevImage
->Width
> 0 &&
3192 prevImage
->InternalFormat
== internalFormat
) {
3193 /* use the same format */
3194 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3195 return prevImage
->TexFormat
;
3199 /* If the application requested compression to an S3TC format but we don't
3200 * have the DXTn library, force a generic compressed format instead.
3202 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3203 const GLenum before
= internalFormat
;
3205 switch (internalFormat
) {
3206 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3207 if (!ctx
->Mesa_DXTn
)
3208 internalFormat
= GL_COMPRESSED_RGB
;
3210 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3211 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3212 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3213 if (!ctx
->Mesa_DXTn
)
3214 internalFormat
= GL_COMPRESSED_RGBA
;
3220 if (before
!= internalFormat
) {
3222 "DXT compression requested (%s), "
3223 "but libtxc_dxtn library not installed. Using %s "
3225 _mesa_enum_to_string(before
),
3226 _mesa_enum_to_string(internalFormat
));
3230 /* choose format from scratch */
3231 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3233 assert(f
!= MESA_FORMAT_NONE
);
3239 * Adjust pixel unpack params and image dimensions to strip off the
3240 * one-pixel texture border.
3242 * Gallium and intel don't support texture borders. They've seldem been used
3243 * and seldom been implemented correctly anyway.
3245 * \param unpackNew returns the new pixel unpack parameters
3248 strip_texture_border(GLenum target
,
3249 GLint
*width
, GLint
*height
, GLint
*depth
,
3250 const struct gl_pixelstore_attrib
*unpack
,
3251 struct gl_pixelstore_attrib
*unpackNew
)
3257 *unpackNew
= *unpack
;
3259 if (unpackNew
->RowLength
== 0)
3260 unpackNew
->RowLength
= *width
;
3262 if (unpackNew
->ImageHeight
== 0)
3263 unpackNew
->ImageHeight
= *height
;
3265 assert(*width
>= 3);
3266 unpackNew
->SkipPixels
++; /* skip the border */
3267 *width
= *width
- 2; /* reduce the width by two border pixels */
3269 /* The min height of a texture with a border is 3 */
3270 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3271 unpackNew
->SkipRows
++; /* skip the border */
3272 *height
= *height
- 2; /* reduce the height by two border pixels */
3276 target
!= GL_TEXTURE_2D_ARRAY
&&
3277 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3278 unpackNew
->SkipImages
++; /* skip the border */
3279 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3285 * Common code to implement all the glTexImage1D/2D/3D functions
3286 * as well as glCompressedTexImage1D/2D/3D.
3287 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3288 * \param format the user's image format (only used if !compressed)
3289 * \param type the user's image type (only used if !compressed)
3290 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3293 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3294 GLenum target
, GLint level
, GLint internalFormat
,
3295 GLsizei width
, GLsizei height
, GLsizei depth
,
3296 GLint border
, GLenum format
, GLenum type
,
3297 GLsizei imageSize
, const GLvoid
*pixels
)
3299 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3300 struct gl_pixelstore_attrib unpack_no_border
;
3301 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3302 struct gl_texture_object
*texObj
;
3303 mesa_format texFormat
;
3304 GLboolean dimensionsOK
, sizeOK
;
3306 FLUSH_VERTICES(ctx
, 0);
3308 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3311 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3313 _mesa_enum_to_string(target
), level
,
3314 _mesa_enum_to_string(internalFormat
),
3315 width
, height
, depth
, border
, pixels
);
3318 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3320 _mesa_enum_to_string(target
), level
,
3321 _mesa_enum_to_string(internalFormat
),
3322 width
, height
, depth
, border
,
3323 _mesa_enum_to_string(format
),
3324 _mesa_enum_to_string(type
), pixels
);
3327 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3329 /* target error checking */
3330 if (!legal_teximage_target(ctx
, dims
, target
)) {
3331 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3332 func
, dims
, _mesa_enum_to_string(target
));
3336 /* general error checking */
3338 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3340 width
, height
, depth
,
3341 border
, imageSize
, pixels
))
3345 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3346 format
, type
, width
, height
, depth
, border
,
3351 /* Here we convert a cpal compressed image into a regular glTexImage2D
3352 * call by decompressing the texture. If we really want to support cpal
3353 * textures in any driver this would have to be changed.
3355 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3356 switch (internalFormat
) {
3357 case GL_PALETTE4_RGB8_OES
:
3358 case GL_PALETTE4_RGBA8_OES
:
3359 case GL_PALETTE4_R5_G6_B5_OES
:
3360 case GL_PALETTE4_RGBA4_OES
:
3361 case GL_PALETTE4_RGB5_A1_OES
:
3362 case GL_PALETTE8_RGB8_OES
:
3363 case GL_PALETTE8_RGBA8_OES
:
3364 case GL_PALETTE8_R5_G6_B5_OES
:
3365 case GL_PALETTE8_RGBA4_OES
:
3366 case GL_PALETTE8_RGB5_A1_OES
:
3367 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3368 width
, height
, imageSize
, pixels
);
3373 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3377 /* For glCompressedTexImage() the driver has no choice about the
3378 * texture format since we'll never transcode the user's compressed
3379 * image data. The internalFormat was error checked earlier.
3381 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3384 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3385 * internal floating point format for the given base format.
3387 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3388 if (type
== GL_FLOAT
) {
3389 texObj
->_IsFloat
= GL_TRUE
;
3390 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3391 texObj
->_IsHalfFloat
= GL_TRUE
;
3394 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3397 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3398 internalFormat
, format
, type
);
3401 assert(texFormat
!= MESA_FORMAT_NONE
);
3403 /* check that width, height, depth are legal for the mipmap level */
3404 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3405 height
, depth
, border
);
3407 /* check that the texture won't take too much memory, etc */
3408 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3410 width
, height
, depth
, border
);
3412 if (_mesa_is_proxy_texture(target
)) {
3413 /* Proxy texture: just clear or set state depending on error checking */
3414 struct gl_texture_image
*texImage
=
3415 get_proxy_tex_image(ctx
, target
, level
);
3418 return; /* GL_OUT_OF_MEMORY already recorded */
3420 if (dimensionsOK
&& sizeOK
) {
3421 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3422 border
, internalFormat
, texFormat
);
3425 clear_teximage_fields(texImage
);
3429 /* non-proxy target */
3430 const GLuint face
= _mesa_tex_target_to_face(target
);
3431 struct gl_texture_image
*texImage
;
3433 if (!dimensionsOK
) {
3434 _mesa_error(ctx
, GL_INVALID_VALUE
,
3435 "%s%uD(invalid width or height or depth)",
3441 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3442 "%s%uD(image too large: %d x %d x %d, %s format)",
3443 func
, dims
, width
, height
, depth
,
3444 _mesa_enum_to_string(internalFormat
));
3448 /* Allow a hardware driver to just strip out the border, to provide
3449 * reliable but slightly incorrect hardware rendering instead of
3450 * rarely-tested software fallback rendering.
3452 if (border
&& ctx
->Const
.StripTextureBorder
) {
3453 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3456 unpack
= &unpack_no_border
;
3459 if (ctx
->NewState
& _NEW_PIXEL
)
3460 _mesa_update_state(ctx
);
3462 _mesa_lock_texture(ctx
, texObj
);
3464 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3467 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3470 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3472 _mesa_init_teximage_fields(ctx
, texImage
,
3473 width
, height
, depth
,
3474 border
, internalFormat
, texFormat
);
3476 /* Give the texture to the driver. <pixels> may be null. */
3477 if (width
> 0 && height
> 0 && depth
> 0) {
3479 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3483 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3484 type
, pixels
, unpack
);
3488 check_gen_mipmap(ctx
, target
, texObj
, level
);
3490 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3492 _mesa_dirty_texobj(ctx
, texObj
);
3495 _mesa_unlock_texture(ctx
, texObj
);
3502 * Called from the API. Note that width includes the border.
3505 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3506 GLsizei width
, GLint border
, GLenum format
,
3507 GLenum type
, const GLvoid
*pixels
)
3509 GET_CURRENT_CONTEXT(ctx
);
3510 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3511 border
, format
, type
, 0, pixels
);
3516 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3517 GLsizei width
, GLsizei height
, GLint border
,
3518 GLenum format
, GLenum type
,
3519 const GLvoid
*pixels
)
3521 GET_CURRENT_CONTEXT(ctx
);
3522 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3523 border
, format
, type
, 0, pixels
);
3528 * Called by the API or display list executor.
3529 * Note that width and height include the border.
3532 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3533 GLsizei width
, GLsizei height
, GLsizei depth
,
3534 GLint border
, GLenum format
, GLenum type
,
3535 const GLvoid
*pixels
)
3537 GET_CURRENT_CONTEXT(ctx
);
3538 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3539 width
, height
, depth
,
3540 border
, format
, type
, 0, pixels
);
3545 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3546 GLsizei width
, GLsizei height
, GLsizei depth
,
3547 GLint border
, GLenum format
, GLenum type
,
3548 const GLvoid
*pixels
)
3550 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3551 depth
, border
, format
, type
, pixels
);
3556 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3558 struct gl_texture_object
*texObj
;
3559 struct gl_texture_image
*texImage
;
3561 GET_CURRENT_CONTEXT(ctx
);
3562 FLUSH_VERTICES(ctx
, 0);
3566 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3568 case GL_TEXTURE_EXTERNAL_OES
:
3570 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3573 valid_target
= false;
3577 if (!valid_target
) {
3578 _mesa_error(ctx
, GL_INVALID_ENUM
,
3579 "glEGLImageTargetTexture2D(target=%d)", target
);
3584 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3585 "glEGLImageTargetTexture2D(image=%p)", image
);
3589 if (ctx
->NewState
& _NEW_PIXEL
)
3590 _mesa_update_state(ctx
);
3592 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3596 _mesa_lock_texture(ctx
, texObj
);
3598 if (texObj
->Immutable
) {
3599 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3600 "glEGLImageTargetTexture2D(texture is immutable)");
3601 _mesa_unlock_texture(ctx
, texObj
);
3605 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3607 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3609 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3611 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3612 texObj
, texImage
, image
);
3614 _mesa_dirty_texobj(ctx
, texObj
);
3616 _mesa_unlock_texture(ctx
, texObj
);
3621 * Helper that implements the glTexSubImage1/2/3D()
3622 * and glTextureSubImage1/2/3D() functions.
3625 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3626 struct gl_texture_object
*texObj
,
3627 struct gl_texture_image
*texImage
,
3628 GLenum target
, GLint level
,
3629 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3630 GLsizei width
, GLsizei height
, GLsizei depth
,
3631 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3634 FLUSH_VERTICES(ctx
, 0);
3636 if (ctx
->NewState
& _NEW_PIXEL
)
3637 _mesa_update_state(ctx
);
3639 _mesa_lock_texture(ctx
, texObj
);
3641 if (width
> 0 && height
> 0 && depth
> 0) {
3642 /* If we have a border, offset=-1 is legal. Bias by border width. */
3645 if (target
!= GL_TEXTURE_2D_ARRAY
)
3646 zoffset
+= texImage
->Border
;
3649 if (target
!= GL_TEXTURE_1D_ARRAY
)
3650 yoffset
+= texImage
->Border
;
3653 xoffset
+= texImage
->Border
;
3656 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3657 xoffset
, yoffset
, zoffset
,
3658 width
, height
, depth
,
3659 format
, type
, pixels
, &ctx
->Unpack
);
3661 check_gen_mipmap(ctx
, target
, texObj
, level
);
3663 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3664 * the texel data, not the texture format, size, etc.
3668 _mesa_unlock_texture(ctx
, texObj
);
3672 * Implement all the glTexSubImage1/2/3D() functions.
3673 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3676 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3677 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3678 GLsizei width
, GLsizei height
, GLsizei depth
,
3679 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3680 const char *callerName
)
3682 struct gl_texture_object
*texObj
;
3683 struct gl_texture_image
*texImage
;
3685 /* check target (proxies not allowed) */
3686 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3687 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3688 dims
, _mesa_enum_to_string(target
));
3692 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3696 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3697 xoffset
, yoffset
, zoffset
,
3698 width
, height
, depth
, format
, type
,
3699 pixels
, false, callerName
)) {
3700 return; /* error was detected */
3703 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3704 /* texsubimage_error_check ensures that texImage is not NULL */
3706 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3707 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3709 _mesa_enum_to_string(target
), level
,
3710 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3711 _mesa_enum_to_string(format
),
3712 _mesa_enum_to_string(type
), pixels
);
3714 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3715 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3716 format
, type
, pixels
, false);
3721 * Implement all the glTextureSubImage1/2/3D() functions.
3722 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3725 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3726 GLuint texture
, GLint level
,
3727 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3728 GLsizei width
, GLsizei height
, GLsizei depth
,
3729 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3730 const char *callerName
)
3732 struct gl_texture_object
*texObj
;
3733 struct gl_texture_image
*texImage
;
3736 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3738 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3739 dims
, texture
, level
,
3740 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3741 _mesa_enum_to_string(format
),
3742 _mesa_enum_to_string(type
), pixels
);
3744 /* Get the texture object by Name. */
3745 texObj
= _mesa_lookup_texture(ctx
, texture
);
3747 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3752 /* check target (proxies not allowed) */
3753 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3754 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3755 callerName
, _mesa_enum_to_string(texObj
->Target
));
3759 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3760 xoffset
, yoffset
, zoffset
,
3761 width
, height
, depth
, format
, type
,
3762 pixels
, true, callerName
)) {
3763 return; /* error was detected */
3767 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3768 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3772 * What do we do if the user created a texture with the following code
3773 * and then called this function with its handle?
3776 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3777 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3778 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3779 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3780 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3781 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3782 * // wrong format, or given the wrong size, etc.
3783 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3784 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3786 * A bug has been filed against the spec for this case. In the
3787 * meantime, we will check for cube completeness.
3789 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3790 * Core Profile spec (30.10.2014):
3791 * "[A] cube map texture is cube complete if the
3792 * following conditions all hold true: The [base level] texture
3793 * images of each of the six cube map faces have identical, positive,
3794 * and square dimensions. The [base level] images were each specified
3795 * with the same internal format."
3797 * It seems reasonable to check for cube completeness of an arbitrary
3798 * level here so that the image data has a consistent format and size.
3800 if (!_mesa_cube_level_complete(texObj
, level
)) {
3801 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3802 "glTextureSubImage%uD(cube map incomplete)",
3807 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3809 /* Copy in each face. */
3810 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3811 texImage
= texObj
->Image
[i
][level
];
3814 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3815 level
, xoffset
, yoffset
, 0,
3816 width
, height
, 1, format
,
3817 type
, pixels
, true);
3818 pixels
= (GLubyte
*) pixels
+ imageStride
;
3822 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3825 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3826 level
, xoffset
, yoffset
, zoffset
,
3827 width
, height
, depth
, format
,
3828 type
, pixels
, true);
3834 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3835 GLint xoffset
, GLsizei width
,
3836 GLenum format
, GLenum type
,
3837 const GLvoid
*pixels
)
3839 GET_CURRENT_CONTEXT(ctx
);
3840 texsubimage(ctx
, 1, target
, level
,
3843 format
, type
, pixels
, "glTexSubImage1D");
3848 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3849 GLint xoffset
, GLint yoffset
,
3850 GLsizei width
, GLsizei height
,
3851 GLenum format
, GLenum type
,
3852 const GLvoid
*pixels
)
3854 GET_CURRENT_CONTEXT(ctx
);
3855 texsubimage(ctx
, 2, target
, level
,
3856 xoffset
, yoffset
, 0,
3858 format
, type
, pixels
, "glTexSubImage2D");
3864 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3865 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3866 GLsizei width
, GLsizei height
, GLsizei depth
,
3867 GLenum format
, GLenum type
,
3868 const GLvoid
*pixels
)
3870 GET_CURRENT_CONTEXT(ctx
);
3871 texsubimage(ctx
, 3, target
, level
,
3872 xoffset
, yoffset
, zoffset
,
3873 width
, height
, depth
,
3874 format
, type
, pixels
, "glTexSubImage3D");
3878 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3879 GLint xoffset
, GLsizei width
,
3880 GLenum format
, GLenum type
,
3881 const GLvoid
*pixels
)
3883 GET_CURRENT_CONTEXT(ctx
);
3884 texturesubimage(ctx
, 1, texture
, level
,
3887 format
, type
, pixels
, "glTextureSubImage1D");
3892 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3893 GLint xoffset
, GLint yoffset
,
3894 GLsizei width
, GLsizei height
,
3895 GLenum format
, GLenum type
,
3896 const GLvoid
*pixels
)
3898 GET_CURRENT_CONTEXT(ctx
);
3899 texturesubimage(ctx
, 2, texture
, level
,
3900 xoffset
, yoffset
, 0,
3902 format
, type
, pixels
, "glTextureSubImage2D");
3907 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3908 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3909 GLsizei width
, GLsizei height
, GLsizei depth
,
3910 GLenum format
, GLenum type
,
3911 const GLvoid
*pixels
)
3913 GET_CURRENT_CONTEXT(ctx
);
3914 texturesubimage(ctx
, 3, texture
, level
,
3915 xoffset
, yoffset
, zoffset
,
3916 width
, height
, depth
,
3917 format
, type
, pixels
, "glTextureSubImage3D");
3922 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3923 * from. This depends on whether the texture contains color or depth values.
3925 static struct gl_renderbuffer
*
3926 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3928 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3929 /* reading from depth/stencil buffer */
3930 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3933 /* copying from color buffer */
3934 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3939 copytexsubimage_by_slice(struct gl_context
*ctx
,
3940 struct gl_texture_image
*texImage
,
3942 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3943 struct gl_renderbuffer
*rb
,
3945 GLsizei width
, GLsizei height
)
3947 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3950 /* For 1D arrays, we copy each scanline of the source rectangle into the
3953 assert(zoffset
== 0);
3955 for (slice
= 0; slice
< height
; slice
++) {
3956 assert(yoffset
+ slice
< texImage
->Height
);
3957 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3958 xoffset
, 0, yoffset
+ slice
,
3959 rb
, x
, y
+ slice
, width
, 1);
3962 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3963 xoffset
, yoffset
, zoffset
,
3964 rb
, x
, y
, width
, height
);
3969 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3971 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3972 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3973 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3974 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3976 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3977 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3978 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3979 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3981 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3982 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3983 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3984 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3991 * Implement the glCopyTexImage1/2D() functions.
3994 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3995 GLenum target
, GLint level
, GLenum internalFormat
,
3996 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3998 struct gl_texture_object
*texObj
;
3999 struct gl_texture_image
*texImage
;
4000 const GLuint face
= _mesa_tex_target_to_face(target
);
4001 mesa_format texFormat
;
4002 struct gl_renderbuffer
*rb
;
4004 FLUSH_VERTICES(ctx
, 0);
4006 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4007 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
4009 _mesa_enum_to_string(target
), level
,
4010 _mesa_enum_to_string(internalFormat
),
4011 x
, y
, width
, height
, border
);
4013 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4014 _mesa_update_state(ctx
);
4016 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
4017 width
, height
, border
))
4020 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
4022 _mesa_error(ctx
, GL_INVALID_VALUE
,
4023 "glCopyTexImage%uD(invalid width or height)", dims
);
4027 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4030 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
4031 internalFormat
, GL_NONE
, GL_NONE
);
4033 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
4035 if (_mesa_is_gles3(ctx
)) {
4036 if (_mesa_is_enum_format_unsized(internalFormat
)) {
4037 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
4038 * OpenGL ES 3.0. Khronos bug# 9807.
4040 if (rb
->InternalFormat
== GL_RGB10_A2
) {
4041 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4042 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
4043 " and writing to unsized internal format)", dims
);
4047 /* From Page 139 of OpenGL ES 3.0 spec:
4048 * "If internalformat is sized, the internal format of the new texel
4049 * array is internalformat, and this is also the new texel array’s
4050 * effective internal format. If the component sizes of internalformat
4051 * do not exactly match the corresponding component sizes of the source
4052 * buffer’s effective internal format, described below, an
4053 * INVALID_OPERATION error is generated. If internalformat is unsized,
4054 * the internal format of the new texel array is the effective internal
4055 * format of the source buffer, and this is also the new texel array’s
4056 * effective internal format.
4058 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
4059 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4060 "glCopyTexImage%uD(componenet size changed in"
4061 " internal format)", dims
);
4066 assert(texFormat
!= MESA_FORMAT_NONE
);
4068 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
4070 width
, height
, 1, border
)) {
4071 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4072 "glCopyTexImage%uD(image too large)", dims
);
4076 if (border
&& ctx
->Const
.StripTextureBorder
) {
4078 width
-= border
* 2;
4081 height
-= border
* 2;
4086 _mesa_lock_texture(ctx
, texObj
);
4088 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
4091 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
4094 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
4096 /* Free old texture image */
4097 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4099 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
4100 border
, internalFormat
, texFormat
);
4102 if (width
&& height
) {
4103 /* Allocate texture memory (no pixel data yet) */
4104 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
4106 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
4108 struct gl_renderbuffer
*srcRb
=
4109 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4111 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4113 srcRb
, srcX
, srcY
, width
, height
);
4116 check_gen_mipmap(ctx
, target
, texObj
, level
);
4119 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4121 _mesa_dirty_texobj(ctx
, texObj
);
4124 _mesa_unlock_texture(ctx
, texObj
);
4130 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4131 GLenum internalFormat
,
4133 GLsizei width
, GLint border
)
4135 GET_CURRENT_CONTEXT(ctx
);
4136 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4142 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4143 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4146 GET_CURRENT_CONTEXT(ctx
);
4147 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4148 x
, y
, width
, height
, border
);
4152 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4155 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4156 struct gl_texture_object
*texObj
,
4157 GLenum target
, GLint level
,
4158 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4160 GLsizei width
, GLsizei height
,
4163 struct gl_texture_image
*texImage
;
4165 FLUSH_VERTICES(ctx
, 0);
4167 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4168 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
4169 _mesa_enum_to_string(target
),
4170 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4172 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4173 _mesa_update_state(ctx
);
4175 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4176 xoffset
, yoffset
, zoffset
,
4177 width
, height
, caller
)) {
4181 _mesa_lock_texture(ctx
, texObj
);
4183 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4185 /* If we have a border, offset=-1 is legal. Bias by border width. */
4188 if (target
!= GL_TEXTURE_2D_ARRAY
)
4189 zoffset
+= texImage
->Border
;
4192 if (target
!= GL_TEXTURE_1D_ARRAY
)
4193 yoffset
+= texImage
->Border
;
4196 xoffset
+= texImage
->Border
;
4199 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4201 struct gl_renderbuffer
*srcRb
=
4202 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4204 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4205 xoffset
, yoffset
, zoffset
,
4206 srcRb
, x
, y
, width
, height
);
4208 check_gen_mipmap(ctx
, target
, texObj
, level
);
4210 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4211 * the texel data, not the texture format, size, etc.
4215 _mesa_unlock_texture(ctx
, texObj
);
4219 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4220 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4222 struct gl_texture_object
* texObj
;
4223 const char *self
= "glCopyTexSubImage1D";
4224 GET_CURRENT_CONTEXT(ctx
);
4226 /* Check target (proxies not allowed). Target must be checked prior to
4227 * calling _mesa_get_current_tex_object.
4229 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4230 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4231 _mesa_enum_to_string(target
));
4235 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4239 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4240 x
, y
, width
, 1, self
);
4246 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4247 GLint xoffset
, GLint yoffset
,
4248 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4250 struct gl_texture_object
* texObj
;
4251 const char *self
= "glCopyTexSubImage2D";
4252 GET_CURRENT_CONTEXT(ctx
);
4254 /* Check target (proxies not allowed). Target must be checked prior to
4255 * calling _mesa_get_current_tex_object.
4257 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4258 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4259 _mesa_enum_to_string(target
));
4263 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4267 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4268 xoffset
, yoffset
, 0,
4269 x
, y
, width
, height
, self
);
4275 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4276 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4277 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4279 struct gl_texture_object
* texObj
;
4280 const char *self
= "glCopyTexSubImage3D";
4281 GET_CURRENT_CONTEXT(ctx
);
4283 /* Check target (proxies not allowed). Target must be checked prior to
4284 * calling _mesa_get_current_tex_object.
4286 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4287 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4288 _mesa_enum_to_string(target
));
4292 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4296 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4297 xoffset
, yoffset
, zoffset
,
4298 x
, y
, width
, height
, self
);
4302 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4303 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4305 struct gl_texture_object
* texObj
;
4306 const char *self
= "glCopyTextureSubImage1D";
4307 GET_CURRENT_CONTEXT(ctx
);
4309 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4313 /* Check target (proxies not allowed). */
4314 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4315 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4316 _mesa_enum_to_string(texObj
->Target
));
4320 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4321 xoffset
, 0, 0, x
, y
, width
, 1, self
);
4325 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4326 GLint xoffset
, GLint yoffset
,
4327 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4329 struct gl_texture_object
* texObj
;
4330 const char *self
= "glCopyTextureSubImage2D";
4331 GET_CURRENT_CONTEXT(ctx
);
4333 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4337 /* Check target (proxies not allowed). */
4338 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4339 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4340 _mesa_enum_to_string(texObj
->Target
));
4344 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4345 xoffset
, yoffset
, 0,
4346 x
, y
, width
, height
, self
);
4352 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4353 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4354 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4356 struct gl_texture_object
* texObj
;
4357 const char *self
= "glCopyTextureSubImage3D";
4358 GET_CURRENT_CONTEXT(ctx
);
4360 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4364 /* Check target (proxies not allowed). */
4365 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4366 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4367 _mesa_enum_to_string(texObj
->Target
));
4371 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4372 /* Act like CopyTexSubImage2D */
4373 _mesa_copy_texture_sub_image(ctx
, 2, texObj
,
4374 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4375 level
, xoffset
, yoffset
, 0,
4376 x
, y
, width
, height
, self
);
4379 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4380 xoffset
, yoffset
, zoffset
,
4381 x
, y
, width
, height
, self
);
4385 check_clear_tex_image(struct gl_context
*ctx
,
4386 const char *function
,
4387 struct gl_texture_image
*texImage
,
4388 GLenum format
, GLenum type
,
4390 GLubyte
*clearValue
)
4392 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4393 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4394 GLenum internalFormat
= texImage
->InternalFormat
;
4397 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4398 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4399 "%s(buffer texture)", function
);
4403 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4404 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4405 "%s(compressed texture)", function
);
4409 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4410 if (err
!= GL_NO_ERROR
) {
4411 _mesa_error(ctx
, err
,
4412 "%s(incompatible format = %s, type = %s)",
4414 _mesa_enum_to_string(format
),
4415 _mesa_enum_to_string(type
));
4419 /* make sure internal format and format basically agree */
4420 if (!texture_formats_agree(internalFormat
, format
)) {
4421 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4422 "%s(incompatible internalFormat = %s, format = %s)",
4424 _mesa_enum_to_string(internalFormat
),
4425 _mesa_enum_to_string(format
));
4429 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4430 /* both source and dest must be integer-valued, or neither */
4431 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4432 _mesa_is_enum_format_integer(format
)) {
4433 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4434 "%s(integer/non-integer format mismatch)",
4440 if (!_mesa_texstore(ctx
,
4442 texImage
->_BaseFormat
,
4443 texImage
->TexFormat
,
4444 0, /* dstRowStride */
4446 1, 1, 1, /* srcWidth/Height/Depth */
4448 data
? data
: zeroData
,
4449 &ctx
->DefaultPacking
)) {
4450 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4457 static struct gl_texture_object
*
4458 get_tex_obj_for_clear(struct gl_context
*ctx
,
4459 const char *function
,
4462 struct gl_texture_object
*texObj
;
4465 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4469 texObj
= _mesa_lookup_texture(ctx
, texture
);
4471 if (texObj
== NULL
) {
4472 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4476 if (texObj
->Target
== 0) {
4477 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4485 get_tex_images_for_clear(struct gl_context
*ctx
,
4486 const char *function
,
4487 struct gl_texture_object
*texObj
,
4489 struct gl_texture_image
**texImages
)
4494 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4495 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4499 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4500 for (i
= 0; i
< MAX_FACES
; i
++) {
4501 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4503 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4504 if (texImages
[i
] == NULL
) {
4505 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4506 "%s(invalid level)", function
);
4514 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4516 if (texImages
[0] == NULL
) {
4517 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4525 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4526 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4527 GLsizei width
, GLsizei height
, GLsizei depth
,
4528 GLenum format
, GLenum type
, const void *data
)
4530 GET_CURRENT_CONTEXT(ctx
);
4531 struct gl_texture_object
*texObj
;
4532 struct gl_texture_image
*texImages
[MAX_FACES
];
4533 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4535 int minDepth
, maxDepth
;
4537 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4542 _mesa_lock_texture(ctx
, texObj
);
4544 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4545 texObj
, level
, texImages
);
4549 if (numImages
== 1) {
4550 minDepth
= -(int) texImages
[0]->Border
;
4551 maxDepth
= texImages
[0]->Depth
;
4554 maxDepth
= numImages
;
4557 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4558 yoffset
< -(GLint
) texImages
[0]->Border
||
4559 zoffset
< minDepth
||
4563 xoffset
+ width
> texImages
[0]->Width
||
4564 yoffset
+ height
> texImages
[0]->Height
||
4565 zoffset
+ depth
> maxDepth
) {
4566 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4567 "glClearSubTexImage(invalid dimensions)");
4571 if (numImages
== 1) {
4572 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4574 format
, type
, data
, clearValue
[0])) {
4575 ctx
->Driver
.ClearTexSubImage(ctx
,
4577 xoffset
, yoffset
, zoffset
,
4578 width
, height
, depth
,
4579 data
? clearValue
[0] : NULL
);
4582 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4583 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4585 format
, type
, data
, clearValue
[i
]))
4588 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4589 ctx
->Driver
.ClearTexSubImage(ctx
,
4591 xoffset
, yoffset
, 0,
4593 data
? clearValue
[i
] : NULL
);
4598 _mesa_unlock_texture(ctx
, texObj
);
4602 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4603 GLenum format
, GLenum type
, const void *data
)
4605 GET_CURRENT_CONTEXT(ctx
);
4606 struct gl_texture_object
*texObj
;
4607 struct gl_texture_image
*texImages
[MAX_FACES
];
4608 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4611 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4616 _mesa_lock_texture(ctx
, texObj
);
4618 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4619 texObj
, level
, texImages
);
4621 for (i
= 0; i
< numImages
; i
++) {
4622 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4629 for (i
= 0; i
< numImages
; i
++) {
4630 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4631 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4632 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4633 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4634 texImages
[i
]->Width
,
4635 texImages
[i
]->Height
,
4636 texImages
[i
]->Depth
,
4637 data
? clearValue
[i
] : NULL
);
4641 _mesa_unlock_texture(ctx
, texObj
);
4647 /**********************************************************************/
4648 /****** Compressed Textures ******/
4649 /**********************************************************************/
4653 * Target checking for glCompressedTexSubImage[123]D().
4654 * \return GL_TRUE if error, GL_FALSE if no error
4655 * Must come before other error checking so that the texture object can
4656 * be correctly retrieved using _mesa_get_current_tex_object.
4659 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4660 GLint dims
, GLenum format
, bool dsa
,
4665 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4666 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4667 _mesa_enum_to_string(target
));
4677 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4678 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4679 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4680 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4681 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4682 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4683 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4686 targetOK
= GL_FALSE
;
4692 case GL_TEXTURE_CUBE_MAP
:
4693 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4695 case GL_TEXTURE_2D_ARRAY
:
4696 targetOK
= _mesa_is_gles3(ctx
) ||
4697 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4699 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4700 targetOK
= ctx
->Extensions
.ARB_texture_cube_map_array
;
4705 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4707 * "An INVALID_OPERATION error is generated by
4708 * CompressedTex*SubImage3D if the internal format of the texture
4709 * is one of the EAC, ETC2, or RGTC formats and either border is
4710 * non-zero, or the effective target for the texture is not
4711 * TEXTURE_2D_ARRAY."
4713 * NOTE: that's probably a spec error. It should probably say
4714 * "... or the effective target for the texture is not
4715 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4716 * GL_TEXTURE_CUBE_MAP_ARRAY."
4717 * since those targets are 2D images and they support all compression
4720 * Instead of listing all these, just list those which are allowed,
4721 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4722 * more) are valid here, which they are not, but of course not
4723 * mentioned by core spec.
4726 /* These are the only 3D compression formats supported at this time */
4727 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
4728 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
4729 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
4730 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
4734 /* invalid format */
4735 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4736 "%s(invalid target %s for format %s)", caller
,
4737 _mesa_enum_to_string(target
),
4738 _mesa_enum_to_string(format
));
4743 targetOK
= GL_FALSE
;
4749 /* no 1D compressed textures at this time */
4750 targetOK
= GL_FALSE
;
4755 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4756 _mesa_enum_to_string(target
));
4764 * Error checking for glCompressedTexSubImage[123]D().
4765 * \return GL_TRUE if error, GL_FALSE if no error
4768 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4769 const struct gl_texture_object
*texObj
,
4770 GLenum target
, GLint level
,
4771 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4772 GLsizei width
, GLsizei height
, GLsizei depth
,
4773 GLenum format
, GLsizei imageSize
,
4774 const GLvoid
*data
, const char *callerName
)
4776 struct gl_texture_image
*texImage
;
4779 /* this will catch any invalid compressed format token */
4780 if (!_mesa_is_compressed_format(ctx
, format
)) {
4781 _mesa_error(ctx
, GL_INVALID_ENUM
,
4782 "%s(format)", callerName
);
4786 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4787 _mesa_error(ctx
, GL_INVALID_VALUE
,
4793 /* validate the bound PBO, if any */
4794 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4795 imageSize
, data
, callerName
)) {
4799 /* Check for invalid pixel storage modes */
4800 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4801 &ctx
->Unpack
, callerName
)) {
4805 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4806 if (expectedSize
!= imageSize
) {
4807 _mesa_error(ctx
, GL_INVALID_VALUE
,
4809 callerName
, imageSize
);
4813 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4815 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4816 "%s(invalid texture image)",
4821 if ((GLint
) format
!= texImage
->InternalFormat
) {
4822 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4824 callerName
, format
);
4828 if (compressedteximage_only_format(ctx
, format
)) {
4829 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4830 "%s(format=0x%x cannot be updated)",
4831 callerName
, format
);
4835 if (error_check_subtexture_dimensions(ctx
, dims
,
4836 texImage
, xoffset
, yoffset
, zoffset
,
4837 width
, height
, depth
,
4847 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4848 GLenum internalFormat
, GLsizei width
,
4849 GLint border
, GLsizei imageSize
,
4852 GET_CURRENT_CONTEXT(ctx
);
4853 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4854 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4859 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4860 GLenum internalFormat
, GLsizei width
,
4861 GLsizei height
, GLint border
, GLsizei imageSize
,
4864 GET_CURRENT_CONTEXT(ctx
);
4865 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4866 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4871 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4872 GLenum internalFormat
, GLsizei width
,
4873 GLsizei height
, GLsizei depth
, GLint border
,
4874 GLsizei imageSize
, const GLvoid
*data
)
4876 GET_CURRENT_CONTEXT(ctx
);
4877 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4878 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4883 * Common helper for glCompressedTexSubImage1/2/3D() and
4884 * glCompressedTextureSubImage1/2/3D().
4887 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4888 struct gl_texture_object
*texObj
,
4889 struct gl_texture_image
*texImage
,
4890 GLenum target
, GLint level
,
4891 GLint xoffset
, GLint yoffset
,
4893 GLsizei width
, GLsizei height
,
4895 GLenum format
, GLsizei imageSize
,
4898 FLUSH_VERTICES(ctx
, 0);
4900 _mesa_lock_texture(ctx
, texObj
);
4902 if (width
> 0 && height
> 0 && depth
> 0) {
4903 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4904 xoffset
, yoffset
, zoffset
,
4905 width
, height
, depth
,
4906 format
, imageSize
, data
);
4908 check_gen_mipmap(ctx
, target
, texObj
, level
);
4910 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4911 * the texel data, not the texture format, size, etc.
4915 _mesa_unlock_texture(ctx
, texObj
);
4920 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4921 GLsizei width
, GLenum format
,
4922 GLsizei imageSize
, const GLvoid
*data
)
4924 struct gl_texture_object
*texObj
;
4925 struct gl_texture_image
*texImage
;
4927 GET_CURRENT_CONTEXT(ctx
);
4929 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4930 "glCompressedTexSubImage1D")) {
4934 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4938 if (compressed_subtexture_error_check(ctx
, 1, texObj
, target
,
4939 level
, xoffset
, 0, 0,
4941 format
, imageSize
, data
,
4942 "glCompressedTexSubImage1D")) {
4946 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4949 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
4950 xoffset
, 0, 0, width
, 1, 1,
4951 format
, imageSize
, data
);
4955 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4956 GLsizei width
, GLenum format
,
4957 GLsizei imageSize
, const GLvoid
*data
)
4959 struct gl_texture_object
*texObj
;
4960 struct gl_texture_image
*texImage
;
4962 GET_CURRENT_CONTEXT(ctx
);
4964 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4965 "glCompressedTextureSubImage1D");
4969 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
, true,
4970 "glCompressedTextureSubImage1D")) {
4974 if (compressed_subtexture_error_check(ctx
, 1, texObj
, texObj
->Target
,
4975 level
, xoffset
, 0, 0,
4977 format
, imageSize
, data
,
4978 "glCompressedTextureSubImage1D")) {
4982 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4985 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
,
4986 texObj
->Target
, level
,
4987 xoffset
, 0, 0, width
, 1, 1,
4988 format
, imageSize
, data
);
4993 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4994 GLint yoffset
, GLsizei width
, GLsizei height
,
4995 GLenum format
, GLsizei imageSize
,
4998 struct gl_texture_object
*texObj
;
4999 struct gl_texture_image
*texImage
;
5001 GET_CURRENT_CONTEXT(ctx
);
5003 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
5004 "glCompressedTexSubImage2D")) {
5008 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5012 if (compressed_subtexture_error_check(ctx
, 2, texObj
, target
,
5013 level
, xoffset
, yoffset
, 0,
5015 format
, imageSize
, data
,
5016 "glCompressedTexSubImage2D")) {
5021 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5024 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
5025 xoffset
, yoffset
, 0, width
, height
, 1,
5026 format
, imageSize
, data
);
5030 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
5032 GLsizei width
, GLsizei height
,
5033 GLenum format
, GLsizei imageSize
,
5036 struct gl_texture_object
*texObj
;
5037 struct gl_texture_image
*texImage
;
5039 GET_CURRENT_CONTEXT(ctx
);
5041 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5042 "glCompressedTextureSubImage2D");
5046 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
, true,
5047 "glCompressedTextureSubImage2D")) {
5051 if (compressed_subtexture_error_check(ctx
, 2, texObj
, texObj
->Target
,
5052 level
, xoffset
, yoffset
, 0,
5054 format
, imageSize
, data
,
5055 "glCompressedTextureSubImage2D")) {
5059 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5062 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
,
5063 texObj
->Target
, level
,
5064 xoffset
, yoffset
, 0, width
, height
, 1,
5065 format
, imageSize
, data
);
5069 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
5070 GLint yoffset
, GLint zoffset
, GLsizei width
,
5071 GLsizei height
, GLsizei depth
, GLenum format
,
5072 GLsizei imageSize
, const GLvoid
*data
)
5074 struct gl_texture_object
*texObj
;
5075 struct gl_texture_image
*texImage
;
5077 GET_CURRENT_CONTEXT(ctx
);
5079 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
5080 "glCompressedTexSubImage3D")) {
5084 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5088 if (compressed_subtexture_error_check(ctx
, 3, texObj
, target
,
5089 level
, xoffset
, yoffset
, zoffset
,
5090 width
, height
, depth
,
5091 format
, imageSize
, data
,
5092 "glCompressedTexSubImage3D")) {
5097 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5100 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
5101 xoffset
, yoffset
, zoffset
,
5102 width
, height
, depth
,
5103 format
, imageSize
, data
);
5107 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
5108 GLint yoffset
, GLint zoffset
, GLsizei width
,
5109 GLsizei height
, GLsizei depth
,
5110 GLenum format
, GLsizei imageSize
,
5113 struct gl_texture_object
*texObj
;
5114 struct gl_texture_image
*texImage
;
5116 GET_CURRENT_CONTEXT(ctx
);
5118 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5119 "glCompressedTextureSubImage3D");
5123 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
, true,
5124 "glCompressedTextureSubImage3D")) {
5128 if (compressed_subtexture_error_check(ctx
, 3, texObj
, texObj
->Target
,
5129 level
, xoffset
, yoffset
, zoffset
,
5130 width
, height
, depth
,
5131 format
, imageSize
, data
,
5132 "glCompressedTextureSubImage3D")) {
5136 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
5137 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5138 const char *pixels
= data
;
5142 /* Make sure the texture object is a proper cube.
5143 * (See texturesubimage in teximage.c for details on why this check is
5146 if (!_mesa_cube_level_complete(texObj
, level
)) {
5147 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5148 "glCompressedTextureSubImage3D(cube map incomplete)");
5152 /* Copy in each face. */
5153 for (i
= 0; i
< 6; ++i
) {
5154 texImage
= texObj
->Image
[i
][level
];
5157 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5158 texObj
->Target
, level
,
5159 xoffset
, yoffset
, zoffset
,
5161 format
, imageSize
, pixels
);
5163 /* Compressed images don't have a client format */
5164 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5166 texImage
->Height
, 1);
5168 pixels
+= image_stride
;
5169 imageSize
-= image_stride
;
5173 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5176 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5177 texObj
->Target
, level
,
5178 xoffset
, yoffset
, zoffset
,
5179 width
, height
, depth
,
5180 format
, imageSize
, data
);
5185 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5187 if (ctx
->API
!= API_OPENGL_CORE
) {
5188 switch (internalFormat
) {
5190 return MESA_FORMAT_A_UNORM8
;
5192 return MESA_FORMAT_A_UNORM16
;
5193 case GL_ALPHA16F_ARB
:
5194 return MESA_FORMAT_A_FLOAT16
;
5195 case GL_ALPHA32F_ARB
:
5196 return MESA_FORMAT_A_FLOAT32
;
5197 case GL_ALPHA8I_EXT
:
5198 return MESA_FORMAT_A_SINT8
;
5199 case GL_ALPHA16I_EXT
:
5200 return MESA_FORMAT_A_SINT16
;
5201 case GL_ALPHA32I_EXT
:
5202 return MESA_FORMAT_A_SINT32
;
5203 case GL_ALPHA8UI_EXT
:
5204 return MESA_FORMAT_A_UINT8
;
5205 case GL_ALPHA16UI_EXT
:
5206 return MESA_FORMAT_A_UINT16
;
5207 case GL_ALPHA32UI_EXT
:
5208 return MESA_FORMAT_A_UINT32
;
5210 return MESA_FORMAT_L_UNORM8
;
5211 case GL_LUMINANCE16
:
5212 return MESA_FORMAT_L_UNORM16
;
5213 case GL_LUMINANCE16F_ARB
:
5214 return MESA_FORMAT_L_FLOAT16
;
5215 case GL_LUMINANCE32F_ARB
:
5216 return MESA_FORMAT_L_FLOAT32
;
5217 case GL_LUMINANCE8I_EXT
:
5218 return MESA_FORMAT_L_SINT8
;
5219 case GL_LUMINANCE16I_EXT
:
5220 return MESA_FORMAT_L_SINT16
;
5221 case GL_LUMINANCE32I_EXT
:
5222 return MESA_FORMAT_L_SINT32
;
5223 case GL_LUMINANCE8UI_EXT
:
5224 return MESA_FORMAT_L_UINT8
;
5225 case GL_LUMINANCE16UI_EXT
:
5226 return MESA_FORMAT_L_UINT16
;
5227 case GL_LUMINANCE32UI_EXT
:
5228 return MESA_FORMAT_L_UINT32
;
5229 case GL_LUMINANCE8_ALPHA8
:
5230 return MESA_FORMAT_L8A8_UNORM
;
5231 case GL_LUMINANCE16_ALPHA16
:
5232 return MESA_FORMAT_L16A16_UNORM
;
5233 case GL_LUMINANCE_ALPHA16F_ARB
:
5234 return MESA_FORMAT_LA_FLOAT16
;
5235 case GL_LUMINANCE_ALPHA32F_ARB
:
5236 return MESA_FORMAT_LA_FLOAT32
;
5237 case GL_LUMINANCE_ALPHA8I_EXT
:
5238 return MESA_FORMAT_LA_SINT8
;
5239 case GL_LUMINANCE_ALPHA16I_EXT
:
5240 return MESA_FORMAT_LA_SINT16
;
5241 case GL_LUMINANCE_ALPHA32I_EXT
:
5242 return MESA_FORMAT_LA_SINT32
;
5243 case GL_LUMINANCE_ALPHA8UI_EXT
:
5244 return MESA_FORMAT_LA_UINT8
;
5245 case GL_LUMINANCE_ALPHA16UI_EXT
:
5246 return MESA_FORMAT_LA_UINT16
;
5247 case GL_LUMINANCE_ALPHA32UI_EXT
:
5248 return MESA_FORMAT_LA_UINT32
;
5250 return MESA_FORMAT_I_UNORM8
;
5251 case GL_INTENSITY16
:
5252 return MESA_FORMAT_I_UNORM16
;
5253 case GL_INTENSITY16F_ARB
:
5254 return MESA_FORMAT_I_FLOAT16
;
5255 case GL_INTENSITY32F_ARB
:
5256 return MESA_FORMAT_I_FLOAT32
;
5257 case GL_INTENSITY8I_EXT
:
5258 return MESA_FORMAT_I_SINT8
;
5259 case GL_INTENSITY16I_EXT
:
5260 return MESA_FORMAT_I_SINT16
;
5261 case GL_INTENSITY32I_EXT
:
5262 return MESA_FORMAT_I_SINT32
;
5263 case GL_INTENSITY8UI_EXT
:
5264 return MESA_FORMAT_I_UINT8
;
5265 case GL_INTENSITY16UI_EXT
:
5266 return MESA_FORMAT_I_UINT16
;
5267 case GL_INTENSITY32UI_EXT
:
5268 return MESA_FORMAT_I_UINT32
;
5274 if (ctx
->API
== API_OPENGL_CORE
&&
5275 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5276 switch (internalFormat
) {
5278 return MESA_FORMAT_RGB_FLOAT32
;
5280 return MESA_FORMAT_RGB_UINT32
;
5282 return MESA_FORMAT_RGB_SINT32
;
5288 switch (internalFormat
) {
5290 return MESA_FORMAT_R8G8B8A8_UNORM
;
5292 return MESA_FORMAT_RGBA_UNORM16
;
5293 case GL_RGBA16F_ARB
:
5294 return MESA_FORMAT_RGBA_FLOAT16
;
5295 case GL_RGBA32F_ARB
:
5296 return MESA_FORMAT_RGBA_FLOAT32
;
5298 return MESA_FORMAT_RGBA_SINT8
;
5299 case GL_RGBA16I_EXT
:
5300 return MESA_FORMAT_RGBA_SINT16
;
5301 case GL_RGBA32I_EXT
:
5302 return MESA_FORMAT_RGBA_SINT32
;
5303 case GL_RGBA8UI_EXT
:
5304 return MESA_FORMAT_RGBA_UINT8
;
5305 case GL_RGBA16UI_EXT
:
5306 return MESA_FORMAT_RGBA_UINT16
;
5307 case GL_RGBA32UI_EXT
:
5308 return MESA_FORMAT_RGBA_UINT32
;
5311 return MESA_FORMAT_R8G8_UNORM
;
5313 return MESA_FORMAT_R16G16_UNORM
;
5315 return MESA_FORMAT_RG_FLOAT16
;
5317 return MESA_FORMAT_RG_FLOAT32
;
5319 return MESA_FORMAT_RG_SINT8
;
5321 return MESA_FORMAT_RG_SINT16
;
5323 return MESA_FORMAT_RG_SINT32
;
5325 return MESA_FORMAT_RG_UINT8
;
5327 return MESA_FORMAT_RG_UINT16
;
5329 return MESA_FORMAT_RG_UINT32
;
5332 return MESA_FORMAT_R_UNORM8
;
5334 return MESA_FORMAT_R_UNORM16
;
5336 return MESA_FORMAT_R_FLOAT16
;
5338 return MESA_FORMAT_R_FLOAT32
;
5340 return MESA_FORMAT_R_SINT8
;
5342 return MESA_FORMAT_R_SINT16
;
5344 return MESA_FORMAT_R_SINT32
;
5346 return MESA_FORMAT_R_UINT8
;
5348 return MESA_FORMAT_R_UINT16
;
5350 return MESA_FORMAT_R_UINT32
;
5353 return MESA_FORMAT_NONE
;
5359 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5360 GLenum internalFormat
)
5362 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5365 if (format
== MESA_FORMAT_NONE
)
5366 return MESA_FORMAT_NONE
;
5368 datatype
= _mesa_get_format_datatype(format
);
5370 /* The GL_ARB_texture_buffer_object spec says:
5372 * "If ARB_texture_float is not supported, references to the
5373 * floating-point internal formats provided by that extension should be
5374 * removed, and such formats may not be passed to TexBufferARB."
5376 * As a result, GL_HALF_FLOAT internal format depends on both
5377 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5379 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5380 !ctx
->Extensions
.ARB_texture_float
)
5381 return MESA_FORMAT_NONE
;
5383 if (!ctx
->Extensions
.ARB_texture_rg
) {
5384 GLenum base_format
= _mesa_get_format_base_format(format
);
5385 if (base_format
== GL_R
|| base_format
== GL_RG
)
5386 return MESA_FORMAT_NONE
;
5389 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5390 GLenum base_format
= _mesa_get_format_base_format(format
);
5391 if (base_format
== GL_RGB
)
5392 return MESA_FORMAT_NONE
;
5399 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5400 struct gl_texture_object
*texObj
,
5401 GLenum internalFormat
,
5402 struct gl_buffer_object
*bufObj
,
5403 GLintptr offset
, GLsizeiptr size
,
5408 /* NOTE: ARB_texture_buffer_object has interactions with
5409 * the compatibility profile that are not implemented.
5411 if (!(ctx
->API
== API_OPENGL_CORE
&&
5412 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5413 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5414 "%s(ARB_texture_buffer_object is not"
5415 " implemented for the compatibility profile)", caller
);
5419 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5420 if (format
== MESA_FORMAT_NONE
) {
5421 _mesa_error(ctx
, GL_INVALID_ENUM
,
5422 "%s(internalFormat 0x%x)", caller
, internalFormat
);
5426 FLUSH_VERTICES(ctx
, 0);
5428 _mesa_lock_texture(ctx
, texObj
);
5430 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5431 texObj
->BufferObjectFormat
= internalFormat
;
5432 texObj
->_BufferObjectFormat
= format
;
5433 texObj
->BufferOffset
= offset
;
5434 texObj
->BufferSize
= size
;
5436 _mesa_unlock_texture(ctx
, texObj
);
5438 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5441 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5447 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5448 * Return true if it is, and return false if it is not
5449 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5450 * core spec, 02.02.2015, PDF page 245).
5453 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5456 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5457 _mesa_error(ctx
, GL_INVALID_ENUM
,
5458 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5466 * Check for errors related to the texture buffer range.
5467 * Return false if errors are found, true if none are found.
5470 check_texture_buffer_range(struct gl_context
*ctx
,
5471 struct gl_buffer_object
*bufObj
,
5472 GLintptr offset
, GLsizeiptr size
,
5475 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5476 * Textures (PDF page 245):
5477 * "An INVALID_VALUE error is generated if offset is negative, if
5478 * size is less than or equal to zero, or if offset + size is greater
5479 * than the value of BUFFER_SIZE for the buffer bound to target."
5482 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5488 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5493 if (offset
+ size
> bufObj
->Size
) {
5494 _mesa_error(ctx
, GL_INVALID_VALUE
,
5495 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5496 (int) offset
, (int) size
, (int) bufObj
->Size
);
5500 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5501 * Textures (PDF page 245):
5502 * "An INVALID_VALUE error is generated if offset is not an integer
5503 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5505 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5506 _mesa_error(ctx
, GL_INVALID_VALUE
,
5507 "%s(invalid offset alignment)", caller
);
5515 /** GL_ARB_texture_buffer_object */
5517 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5519 struct gl_texture_object
*texObj
;
5520 struct gl_buffer_object
*bufObj
;
5522 GET_CURRENT_CONTEXT(ctx
);
5524 /* Need to catch a bad target before it gets to
5525 * _mesa_get_current_tex_object.
5527 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5531 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5537 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5541 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5542 buffer
? -1 : 0, "glTexBuffer");
5546 /** GL_ARB_texture_buffer_range */
5548 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5549 GLintptr offset
, GLsizeiptr size
)
5551 struct gl_texture_object
*texObj
;
5552 struct gl_buffer_object
*bufObj
;
5554 GET_CURRENT_CONTEXT(ctx
);
5556 /* Need to catch a bad target before it gets to
5557 * _mesa_get_current_tex_object.
5559 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5563 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5567 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5568 "glTexBufferRange"))
5572 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5573 * Textures (PDF page 254):
5574 * "If buffer is zero, then any buffer object attached to the buffer
5575 * texture is detached, the values offset and size are ignored and
5576 * the state for offset and size for the buffer texture are reset to
5584 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5588 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5589 offset
, size
, "glTexBufferRange");
5593 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5595 struct gl_texture_object
*texObj
;
5596 struct gl_buffer_object
*bufObj
;
5598 GET_CURRENT_CONTEXT(ctx
);
5601 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5607 /* Get the texture object by Name. */
5608 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5612 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5615 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5616 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5620 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5621 GLintptr offset
, GLsizeiptr size
)
5623 struct gl_texture_object
*texObj
;
5624 struct gl_buffer_object
*bufObj
;
5626 GET_CURRENT_CONTEXT(ctx
);
5629 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5630 "glTextureBufferRange");
5634 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5635 "glTextureBufferRange"))
5639 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5640 * Textures (PDF page 254):
5641 * "If buffer is zero, then any buffer object attached to the buffer
5642 * texture is detached, the values offset and size are ignored and
5643 * the state for offset and size for the buffer texture are reset to
5651 /* Get the texture object by Name. */
5652 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5656 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5657 "glTextureBufferRange"))
5660 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5661 bufObj
, offset
, size
, "glTextureBufferRange");
5665 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5667 /* Everything that is allowed for renderbuffers,
5668 * except for a base format of GL_STENCIL_INDEX, unless supported.
5670 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5671 if (ctx
->Extensions
.ARB_texture_stencil8
)
5672 return baseFormat
!= 0;
5674 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5678 /** GL_ARB_texture_multisample */
5680 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5683 case GL_TEXTURE_2D_MULTISAMPLE
:
5685 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5686 return dims
== 2 && !dsa
;
5687 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5689 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5690 return dims
== 3 && !dsa
;
5698 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5699 struct gl_texture_object
*texObj
,
5700 GLenum target
, GLsizei samples
,
5701 GLint internalformat
, GLsizei width
,
5702 GLsizei height
, GLsizei depth
,
5703 GLboolean fixedsamplelocations
,
5704 GLboolean immutable
, const char *func
)
5706 struct gl_texture_image
*texImage
;
5707 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5708 mesa_format texFormat
;
5709 GLenum sample_count_error
;
5710 bool dsa
= strstr(func
, "ture") ? true : false;
5712 if (!((ctx
->Extensions
.ARB_texture_multisample
5713 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5714 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5719 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5723 if (!check_multisample_target(dims
, target
, dsa
)) {
5725 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5729 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5734 /* check that the specified internalformat is color/depth/stencil-renderable;
5735 * refer GL3.1 spec 4.4.4
5738 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5739 _mesa_error(ctx
, GL_INVALID_ENUM
,
5740 "%s(internalformat=%s not legal for immutable-format)",
5741 func
, _mesa_enum_to_string(internalformat
));
5745 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5746 /* Page 172 of OpenGL ES 3.1 spec says:
5747 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5748 * color-renderable, depth-renderable, or stencil-renderable (as
5749 * defined in section 9.4).
5751 * (Same error is also defined for desktop OpenGL for multisample
5752 * teximage/texstorage functions.)
5754 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5755 _mesa_enum_to_string(internalformat
));
5759 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5760 internalformat
, samples
);
5761 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5763 /* Page 254 of OpenGL 4.4 spec says:
5764 * "Proxy arrays for two-dimensional multisample and two-dimensional
5765 * multisample array textures are operated on in the same way when
5766 * TexImage2DMultisample is called with target specified as
5767 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5768 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5769 * However, if samples is not supported, then no error is generated.
5771 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5772 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5776 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5777 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5778 "%s(texture object 0)",
5783 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5785 if (texImage
== NULL
) {
5786 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5790 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5791 internalformat
, GL_NONE
, GL_NONE
);
5792 assert(texFormat
!= MESA_FORMAT_NONE
);
5794 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5795 width
, height
, depth
, 0);
5797 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5798 width
, height
, depth
, 0);
5800 if (_mesa_is_proxy_texture(target
)) {
5801 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5802 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5803 internalformat
, texFormat
,
5804 samples
, fixedsamplelocations
);
5807 /* clear all image fields */
5808 clear_teximage_fields(texImage
);
5812 if (!dimensionsOK
) {
5813 _mesa_error(ctx
, GL_INVALID_VALUE
,
5814 "%s(invalid width or height)", func
);
5819 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5823 /* Check if texObj->Immutable is set */
5824 if (texObj
->Immutable
) {
5825 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5829 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5831 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5832 internalformat
, texFormat
,
5833 samples
, fixedsamplelocations
);
5835 if (width
> 0 && height
> 0 && depth
> 0) {
5836 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5837 width
, height
, depth
)) {
5838 /* tidy up the texture image state. strictly speaking,
5839 * we're allowed to just leave this in whatever state we
5840 * like, but being tidy is good.
5842 _mesa_init_teximage_fields(ctx
, texImage
,
5843 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5847 texObj
->Immutable
|= immutable
;
5850 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5853 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5859 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5860 GLenum internalformat
, GLsizei width
,
5861 GLsizei height
, GLboolean fixedsamplelocations
)
5863 struct gl_texture_object
*texObj
;
5864 GET_CURRENT_CONTEXT(ctx
);
5866 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5870 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5871 internalformat
, width
, height
, 1,
5872 fixedsamplelocations
, GL_FALSE
,
5873 "glTexImage2DMultisample");
5878 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5879 GLenum internalformat
, GLsizei width
,
5880 GLsizei height
, GLsizei depth
,
5881 GLboolean fixedsamplelocations
)
5883 struct gl_texture_object
*texObj
;
5884 GET_CURRENT_CONTEXT(ctx
);
5886 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5890 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5891 internalformat
, width
, height
, depth
,
5892 fixedsamplelocations
, GL_FALSE
,
5893 "glTexImage3DMultisample");
5897 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
5898 GLsizei samples
, unsigned dims
)
5900 GET_CURRENT_CONTEXT(ctx
);
5902 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
5903 _mesa_error(ctx
, GL_INVALID_VALUE
,
5904 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
5905 dims
, width
, height
, depth
);
5912 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5913 GLenum internalformat
, GLsizei width
,
5914 GLsizei height
, GLboolean fixedsamplelocations
)
5916 struct gl_texture_object
*texObj
;
5917 GET_CURRENT_CONTEXT(ctx
);
5919 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5923 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5926 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5927 internalformat
, width
, height
, 1,
5928 fixedsamplelocations
, GL_TRUE
,
5929 "glTexStorage2DMultisample");
5933 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5934 GLenum internalformat
, GLsizei width
,
5935 GLsizei height
, GLsizei depth
,
5936 GLboolean fixedsamplelocations
)
5938 struct gl_texture_object
*texObj
;
5939 GET_CURRENT_CONTEXT(ctx
);
5941 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5945 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5948 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5949 internalformat
, width
, height
, depth
,
5950 fixedsamplelocations
, GL_TRUE
,
5951 "glTexStorage3DMultisample");
5955 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5956 GLenum internalformat
, GLsizei width
,
5958 GLboolean fixedsamplelocations
)
5960 struct gl_texture_object
*texObj
;
5961 GET_CURRENT_CONTEXT(ctx
);
5963 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5964 "glTextureStorage2DMultisample");
5968 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5971 texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5972 internalformat
, width
, height
, 1,
5973 fixedsamplelocations
, GL_TRUE
,
5974 "glTextureStorage2DMultisample");
5978 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5979 GLenum internalformat
, GLsizei width
,
5980 GLsizei height
, GLsizei depth
,
5981 GLboolean fixedsamplelocations
)
5983 struct gl_texture_object
*texObj
;
5984 GET_CURRENT_CONTEXT(ctx
);
5986 /* Get the texture object by Name. */
5987 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5988 "glTextureStorage3DMultisample");
5992 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5995 texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5996 internalformat
, width
, height
, depth
,
5997 fixedsamplelocations
, GL_TRUE
,
5998 "glTextureStorage3DMultisample");