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
->Extensions
.EXT_texture_compression_latc
) {
538 switch (internalFormat
) {
539 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
540 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
542 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
543 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
544 return GL_LUMINANCE_ALPHA
;
550 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
551 switch (internalFormat
) {
552 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
553 return GL_LUMINANCE_ALPHA
;
559 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
560 switch (internalFormat
) {
561 case GL_ETC1_RGB8_OES
:
568 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
569 _mesa_is_astc_format(internalFormat
))
572 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
573 switch (internalFormat
) {
574 case GL_COMPRESSED_RGB8_ETC2
:
575 case GL_COMPRESSED_SRGB8_ETC2
:
577 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
578 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
579 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
580 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
582 case GL_COMPRESSED_R11_EAC
:
583 case GL_COMPRESSED_SIGNED_R11_EAC
:
585 case GL_COMPRESSED_RG11_EAC
:
586 case GL_COMPRESSED_SIGNED_RG11_EAC
:
593 if (_mesa_is_desktop_gl(ctx
) &&
594 ctx
->Extensions
.ARB_texture_compression_bptc
) {
595 switch (internalFormat
) {
596 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
597 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
599 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
600 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
607 if (ctx
->API
== API_OPENGLES
) {
608 switch (internalFormat
) {
609 case GL_PALETTE4_RGB8_OES
:
610 case GL_PALETTE4_R5_G6_B5_OES
:
611 case GL_PALETTE8_RGB8_OES
:
612 case GL_PALETTE8_R5_G6_B5_OES
:
614 case GL_PALETTE4_RGBA8_OES
:
615 case GL_PALETTE8_RGB5_A1_OES
:
616 case GL_PALETTE4_RGBA4_OES
:
617 case GL_PALETTE4_RGB5_A1_OES
:
618 case GL_PALETTE8_RGBA8_OES
:
619 case GL_PALETTE8_RGBA4_OES
:
626 return -1; /* error */
631 * For cube map faces, return a face index in [0,5].
632 * For other targets return 0;
635 _mesa_tex_target_to_face(GLenum target
)
637 if (_mesa_is_cube_face(target
))
638 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
646 * Install gl_texture_image in a gl_texture_object according to the target
647 * and level parameters.
649 * \param tObj texture object.
650 * \param target texture target.
651 * \param level image level.
652 * \param texImage texture image.
655 set_tex_image(struct gl_texture_object
*tObj
,
656 GLenum target
, GLint level
,
657 struct gl_texture_image
*texImage
)
659 const GLuint face
= _mesa_tex_target_to_face(target
);
663 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
666 tObj
->Image
[face
][level
] = texImage
;
668 /* Set the 'back' pointer */
669 texImage
->TexObject
= tObj
;
670 texImage
->Level
= level
;
671 texImage
->Face
= face
;
676 * Allocate a texture image structure.
678 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
681 * \return a pointer to gl_texture_image struct with all fields initialized to
684 struct gl_texture_image
*
685 _mesa_new_texture_image( struct gl_context
*ctx
)
688 return CALLOC_STRUCT(gl_texture_image
);
693 * Free a gl_texture_image and associated data.
694 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
696 * \param texImage texture image.
698 * Free the texture image structure and the associated image data.
701 _mesa_delete_texture_image(struct gl_context
*ctx
,
702 struct gl_texture_image
*texImage
)
704 /* Free texImage->Data and/or any other driver-specific texture
707 assert(ctx
->Driver
.FreeTextureImageBuffer
);
708 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
714 * Test if a target is a proxy target.
716 * \param target texture target.
718 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
721 _mesa_is_proxy_texture(GLenum target
)
724 static const GLenum targets
[] = {
728 GL_PROXY_TEXTURE_CUBE_MAP
,
729 GL_PROXY_TEXTURE_RECTANGLE
,
730 GL_PROXY_TEXTURE_1D_ARRAY
,
731 GL_PROXY_TEXTURE_2D_ARRAY
,
732 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
733 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
734 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
737 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
738 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
740 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
742 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
743 if (target
== targets
[i
])
750 * Test if a target is an array target.
752 * \param target texture target.
754 * \return true if the target is an array target, false otherwise.
757 _mesa_is_array_texture(GLenum target
)
760 case GL_TEXTURE_1D_ARRAY
:
761 case GL_TEXTURE_2D_ARRAY
:
762 case GL_TEXTURE_CUBE_MAP_ARRAY
:
763 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
772 * Return the proxy target which corresponds to the given texture target
775 proxy_target(GLenum target
)
779 case GL_PROXY_TEXTURE_1D
:
780 return GL_PROXY_TEXTURE_1D
;
782 case GL_PROXY_TEXTURE_2D
:
783 return GL_PROXY_TEXTURE_2D
;
785 case GL_PROXY_TEXTURE_3D
:
786 return GL_PROXY_TEXTURE_3D
;
787 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
788 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
789 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
790 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
791 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
792 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
793 case GL_TEXTURE_CUBE_MAP_ARB
:
794 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
795 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
796 case GL_TEXTURE_RECTANGLE_NV
:
797 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
798 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
799 case GL_TEXTURE_1D_ARRAY_EXT
:
800 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
801 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
802 case GL_TEXTURE_2D_ARRAY_EXT
:
803 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
804 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
805 case GL_TEXTURE_CUBE_MAP_ARRAY
:
806 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
807 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
808 case GL_TEXTURE_2D_MULTISAMPLE
:
809 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
810 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
811 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
812 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
813 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
815 _mesa_problem(NULL
, "unexpected target in proxy_target()");
824 * Get a texture image pointer from a texture object, given a texture
825 * target and mipmap level. The target and level parameters should
826 * have already been error-checked.
828 * \param texObj texture unit.
829 * \param target texture target.
830 * \param level image level.
832 * \return pointer to the texture image structure, or NULL on failure.
834 struct gl_texture_image
*
835 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
836 GLenum target
, GLint level
)
838 const GLuint face
= _mesa_tex_target_to_face(target
);
842 assert(level
< MAX_TEXTURE_LEVELS
);
844 return texObj
->Image
[face
][level
];
849 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
850 * it and install it. Only return NULL if passed a bad parameter or run
853 struct gl_texture_image
*
854 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
855 GLenum target
, GLint level
)
857 struct gl_texture_image
*texImage
;
862 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
864 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
866 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
870 set_tex_image(texObj
, target
, level
, texImage
);
878 * Return pointer to the specified proxy texture image.
879 * Note that proxy textures are per-context, not per-texture unit.
880 * \return pointer to texture image or NULL if invalid target, invalid
881 * level, or out of memory.
883 static struct gl_texture_image
*
884 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
886 struct gl_texture_image
*texImage
;
893 case GL_PROXY_TEXTURE_1D
:
894 if (level
>= ctx
->Const
.MaxTextureLevels
)
896 texIndex
= TEXTURE_1D_INDEX
;
898 case GL_PROXY_TEXTURE_2D
:
899 if (level
>= ctx
->Const
.MaxTextureLevels
)
901 texIndex
= TEXTURE_2D_INDEX
;
903 case GL_PROXY_TEXTURE_3D
:
904 if (level
>= ctx
->Const
.Max3DTextureLevels
)
906 texIndex
= TEXTURE_3D_INDEX
;
908 case GL_PROXY_TEXTURE_CUBE_MAP
:
909 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
911 texIndex
= TEXTURE_CUBE_INDEX
;
913 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
916 texIndex
= TEXTURE_RECT_INDEX
;
918 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
919 if (level
>= ctx
->Const
.MaxTextureLevels
)
921 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
923 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
924 if (level
>= ctx
->Const
.MaxTextureLevels
)
926 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
928 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
929 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
931 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
933 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
936 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
938 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
941 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
947 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
949 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
951 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
954 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
955 /* Set the 'back' pointer */
956 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
963 * Get the maximum number of allowed mipmap levels.
965 * \param ctx GL context.
966 * \param target texture target.
968 * \return the maximum number of allowed mipmap levels for the given
969 * texture target, or zero if passed a bad target.
974 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
978 case GL_PROXY_TEXTURE_1D
:
980 case GL_PROXY_TEXTURE_2D
:
981 return ctx
->Const
.MaxTextureLevels
;
983 case GL_PROXY_TEXTURE_3D
:
984 return ctx
->Const
.Max3DTextureLevels
;
985 case GL_TEXTURE_CUBE_MAP
:
986 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
987 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
988 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
989 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
990 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
991 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
992 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
993 return ctx
->Extensions
.ARB_texture_cube_map
994 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
995 case GL_TEXTURE_RECTANGLE_NV
:
996 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
997 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
998 case GL_TEXTURE_1D_ARRAY_EXT
:
999 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1000 case GL_TEXTURE_2D_ARRAY_EXT
:
1001 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1002 return ctx
->Extensions
.EXT_texture_array
1003 ? ctx
->Const
.MaxTextureLevels
: 0;
1004 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1005 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1006 return ctx
->Extensions
.ARB_texture_cube_map_array
1007 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1008 case GL_TEXTURE_BUFFER
:
1009 return ctx
->API
== API_OPENGL_CORE
&&
1010 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1011 case GL_TEXTURE_2D_MULTISAMPLE
:
1012 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1013 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1014 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1015 return (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
))
1016 && ctx
->Extensions
.ARB_texture_multisample
1018 case GL_TEXTURE_EXTERNAL_OES
:
1021 return 0; /* bad target */
1027 * Return number of dimensions per mipmap level for the given texture target.
1030 _mesa_get_texture_dimensions(GLenum target
)
1034 case GL_PROXY_TEXTURE_1D
:
1037 case GL_TEXTURE_RECTANGLE
:
1038 case GL_TEXTURE_CUBE_MAP
:
1039 case GL_PROXY_TEXTURE_2D
:
1040 case GL_PROXY_TEXTURE_RECTANGLE
:
1041 case GL_PROXY_TEXTURE_CUBE_MAP
:
1042 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1043 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1044 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1045 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1046 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1047 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1048 case GL_TEXTURE_1D_ARRAY
:
1049 case GL_PROXY_TEXTURE_1D_ARRAY
:
1050 case GL_TEXTURE_EXTERNAL_OES
:
1051 case GL_TEXTURE_2D_MULTISAMPLE
:
1052 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1055 case GL_PROXY_TEXTURE_3D
:
1056 case GL_TEXTURE_2D_ARRAY
:
1057 case GL_PROXY_TEXTURE_2D_ARRAY
:
1058 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1059 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1060 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1061 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1063 case GL_TEXTURE_BUFFER
:
1066 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1074 * Check if a texture target can have more than one layer.
1077 _mesa_tex_target_is_layered(GLenum target
)
1081 case GL_PROXY_TEXTURE_1D
:
1083 case GL_PROXY_TEXTURE_2D
:
1084 case GL_TEXTURE_RECTANGLE
:
1085 case GL_PROXY_TEXTURE_RECTANGLE
:
1086 case GL_TEXTURE_2D_MULTISAMPLE
:
1087 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1088 case GL_TEXTURE_BUFFER
:
1089 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1090 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1091 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1092 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1093 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1094 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1095 case GL_TEXTURE_EXTERNAL_OES
:
1099 case GL_PROXY_TEXTURE_3D
:
1100 case GL_TEXTURE_CUBE_MAP
:
1101 case GL_PROXY_TEXTURE_CUBE_MAP
:
1102 case GL_TEXTURE_1D_ARRAY
:
1103 case GL_PROXY_TEXTURE_1D_ARRAY
:
1104 case GL_TEXTURE_2D_ARRAY
:
1105 case GL_PROXY_TEXTURE_2D_ARRAY
:
1106 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1107 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1108 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1109 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1113 assert(!"Invalid texture target.");
1120 * Return the number of layers present in the given level of an array,
1121 * cubemap or 3D texture. If the texture is not layered return zero.
1124 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1126 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1128 switch (texObj
->Target
) {
1131 case GL_TEXTURE_RECTANGLE
:
1132 case GL_TEXTURE_2D_MULTISAMPLE
:
1133 case GL_TEXTURE_BUFFER
:
1134 case GL_TEXTURE_EXTERNAL_OES
:
1137 case GL_TEXTURE_CUBE_MAP
:
1140 case GL_TEXTURE_1D_ARRAY
: {
1141 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1142 return img
? img
->Height
: 0;
1146 case GL_TEXTURE_2D_ARRAY
:
1147 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1148 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1149 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1150 return img
? img
->Depth
: 0;
1154 assert(!"Invalid texture target.");
1161 * Return the maximum number of mipmap levels for the given target
1162 * and the dimensions.
1163 * The dimensions are expected not to include the border.
1166 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1173 case GL_TEXTURE_1D_ARRAY
:
1174 case GL_PROXY_TEXTURE_1D
:
1175 case GL_PROXY_TEXTURE_1D_ARRAY
:
1178 case GL_TEXTURE_CUBE_MAP
:
1179 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1180 case GL_PROXY_TEXTURE_CUBE_MAP
:
1181 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1185 case GL_TEXTURE_2D_ARRAY
:
1186 case GL_PROXY_TEXTURE_2D
:
1187 case GL_PROXY_TEXTURE_2D_ARRAY
:
1188 size
= MAX2(width
, height
);
1191 case GL_PROXY_TEXTURE_3D
:
1192 size
= MAX3(width
, height
, depth
);
1194 case GL_TEXTURE_RECTANGLE
:
1195 case GL_TEXTURE_EXTERNAL_OES
:
1196 case GL_TEXTURE_2D_MULTISAMPLE
:
1197 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1198 case GL_PROXY_TEXTURE_RECTANGLE
:
1199 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1200 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1207 return _mesa_logbase2(size
) + 1;
1211 #if 000 /* not used anymore */
1213 * glTexImage[123]D can accept a NULL image pointer. In this case we
1214 * create a texture image with unspecified image contents per the OpenGL
1218 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1220 const GLint components
= _mesa_components_in_format(format
);
1221 const GLint numPixels
= width
* height
* depth
;
1222 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1226 * Let's see if anyone finds this. If glTexImage2D() is called with
1227 * a NULL image pointer then load the texture image with something
1228 * interesting instead of leaving it indeterminate.
1231 static const char message
[8][32] = {
1232 " X X XXXXX XXX X ",
1233 " XX XX X X X X X ",
1235 " X X XXXX XXX XXXXX ",
1238 " X X XXXXX XXX X X ",
1242 GLubyte
*imgPtr
= data
;
1244 for (h
= 0; h
< depth
; h
++) {
1245 for (i
= 0; i
< height
; i
++) {
1246 GLint srcRow
= 7 - (i
% 8);
1247 for (j
= 0; j
< width
; j
++) {
1248 GLint srcCol
= j
% 32;
1249 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1250 for (k
= 0; k
< components
; k
++) {
1266 * Set the size and format-related fields of a gl_texture_image struct
1267 * to zero. This is used when a proxy texture test fails.
1270 clear_teximage_fields(struct gl_texture_image
*img
)
1273 img
->_BaseFormat
= 0;
1274 img
->InternalFormat
= 0;
1283 img
->HeightLog2
= 0;
1285 img
->TexFormat
= MESA_FORMAT_NONE
;
1286 img
->NumSamples
= 0;
1287 img
->FixedSampleLocations
= GL_TRUE
;
1292 * Initialize basic fields of the gl_texture_image struct.
1294 * \param ctx GL context.
1295 * \param img texture image structure to be initialized.
1296 * \param width image width.
1297 * \param height image height.
1298 * \param depth image depth.
1299 * \param border image border.
1300 * \param internalFormat internal format.
1301 * \param format the actual hardware format (one of MESA_FORMAT_*)
1302 * \param numSamples number of samples per texel, or zero for non-MS.
1303 * \param fixedSampleLocations are sample locations fixed?
1305 * Fills in the fields of \p img with the given information.
1306 * Note: width, height and depth include the border.
1309 init_teximage_fields_ms(struct gl_context
*ctx
,
1310 struct gl_texture_image
*img
,
1311 GLsizei width
, GLsizei height
, GLsizei depth
,
1312 GLint border
, GLenum internalFormat
,
1314 GLuint numSamples
, GLboolean fixedSampleLocations
)
1319 assert(height
>= 0);
1322 target
= img
->TexObject
->Target
;
1323 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1324 assert(img
->_BaseFormat
!= -1);
1325 img
->InternalFormat
= internalFormat
;
1326 img
->Border
= border
;
1328 img
->Height
= height
;
1331 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1332 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1334 img
->NumSamples
= 0;
1335 img
->FixedSampleLocations
= GL_TRUE
;
1339 case GL_TEXTURE_BUFFER
:
1340 case GL_PROXY_TEXTURE_1D
:
1345 img
->HeightLog2
= 0;
1352 case GL_TEXTURE_1D_ARRAY
:
1353 case GL_PROXY_TEXTURE_1D_ARRAY
:
1354 img
->Height2
= height
; /* no border */
1355 img
->HeightLog2
= 0; /* not used */
1363 case GL_TEXTURE_RECTANGLE
:
1364 case GL_TEXTURE_CUBE_MAP
:
1365 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1366 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1367 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1368 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1369 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1370 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1371 case GL_TEXTURE_EXTERNAL_OES
:
1372 case GL_PROXY_TEXTURE_2D
:
1373 case GL_PROXY_TEXTURE_RECTANGLE
:
1374 case GL_PROXY_TEXTURE_CUBE_MAP
:
1375 case GL_TEXTURE_2D_MULTISAMPLE
:
1376 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1377 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1378 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1385 case GL_TEXTURE_2D_ARRAY
:
1386 case GL_PROXY_TEXTURE_2D_ARRAY
:
1387 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1388 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1389 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1390 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1391 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1392 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1393 img
->Depth2
= depth
; /* no border */
1394 img
->DepthLog2
= 0; /* not used */
1397 case GL_PROXY_TEXTURE_3D
:
1398 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1399 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1400 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1401 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1404 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1409 _mesa_get_tex_max_num_levels(target
,
1410 img
->Width2
, img
->Height2
, img
->Depth2
);
1411 img
->TexFormat
= format
;
1412 img
->NumSamples
= numSamples
;
1413 img
->FixedSampleLocations
= fixedSampleLocations
;
1418 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1419 struct gl_texture_image
*img
,
1420 GLsizei width
, GLsizei height
, GLsizei depth
,
1421 GLint border
, GLenum internalFormat
,
1424 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1425 internalFormat
, format
, 0, GL_TRUE
);
1430 * Free and clear fields of the gl_texture_image struct.
1432 * \param ctx GL context.
1433 * \param texImage texture image structure to be cleared.
1435 * After the call, \p texImage will have no data associated with it. Its
1436 * fields are cleared so that its parent object will test incomplete.
1439 _mesa_clear_texture_image(struct gl_context
*ctx
,
1440 struct gl_texture_image
*texImage
)
1442 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1443 clear_teximage_fields(texImage
);
1448 * Check the width, height, depth and border of a texture image are legal.
1449 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1451 * The target and level parameters will have already been validated.
1452 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1455 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1456 GLint level
, GLint width
, GLint height
,
1457 GLint depth
, GLint border
)
1463 case GL_PROXY_TEXTURE_1D
:
1464 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1465 maxSize
>>= level
; /* level size */
1466 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1468 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1469 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1475 case GL_PROXY_TEXTURE_2D
:
1476 case GL_TEXTURE_2D_MULTISAMPLE
:
1477 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1478 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1480 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1482 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1484 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1485 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1487 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1493 case GL_PROXY_TEXTURE_3D
:
1494 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1496 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1498 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1500 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1502 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1503 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1505 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1507 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1512 case GL_TEXTURE_RECTANGLE_NV
:
1513 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1516 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1517 if (width
< 0 || width
> maxSize
)
1519 if (height
< 0 || height
> maxSize
)
1523 case GL_TEXTURE_CUBE_MAP
:
1524 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1525 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1526 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1527 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1528 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1529 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1530 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1531 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1533 if (width
!= height
)
1535 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1537 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1539 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1540 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1542 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1547 case GL_TEXTURE_1D_ARRAY_EXT
:
1548 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1549 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1551 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1553 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1555 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1556 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1561 case GL_TEXTURE_2D_ARRAY_EXT
:
1562 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1563 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1564 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1565 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1567 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1569 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1571 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1573 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1574 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1576 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1581 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1582 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1583 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1584 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1586 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1588 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1590 if (width
!= height
)
1592 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1594 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1595 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1597 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1602 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1609 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1610 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1611 * \param destImage the destination texture image.
1612 * \return GL_TRUE if error found, GL_FALSE otherwise.
1615 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1616 const struct gl_texture_image
*destImage
,
1617 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1618 GLsizei subWidth
, GLsizei subHeight
,
1619 GLsizei subDepth
, const char *func
)
1621 const GLenum target
= destImage
->TexObject
->Target
;
1626 _mesa_error(ctx
, GL_INVALID_VALUE
,
1627 "%s(width=%d)", func
, subWidth
);
1631 if (dims
> 1 && subHeight
< 0) {
1632 _mesa_error(ctx
, GL_INVALID_VALUE
,
1633 "%s(height=%d)", func
, subHeight
);
1637 if (dims
> 2 && subDepth
< 0) {
1638 _mesa_error(ctx
, GL_INVALID_VALUE
,
1639 "%s(depth=%d)", func
, subDepth
);
1643 /* check xoffset and width */
1644 if (xoffset
< - (GLint
) destImage
->Border
) {
1645 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset)", func
);
1649 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1650 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset+width)", func
);
1654 /* check yoffset and height */
1656 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1657 if (yoffset
< -yBorder
) {
1658 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset)", func
);
1661 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1662 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset+height)", func
);
1667 /* check zoffset and depth */
1670 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1671 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1672 0 : destImage
->Border
;
1674 if (zoffset
< -zBorder
) {
1675 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset)", func
);
1679 depth
= (GLint
) destImage
->Depth
;
1680 if (target
== GL_TEXTURE_CUBE_MAP
)
1682 if (zoffset
+ subDepth
> depth
) {
1683 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset+depth)", func
);
1689 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1690 * compressed texture images can be updated. But, that restriction may be
1691 * relaxed for particular compressed formats. At this time, all the
1692 * compressed formats supported by Mesa allow sub-textures to be updated
1693 * along compressed block boundaries.
1695 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1697 if (bw
!= 1 || bh
!= 1) {
1698 /* offset must be multiple of block size */
1699 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1700 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1701 "%s(xoffset = %d, yoffset = %d)",
1702 func
, xoffset
, yoffset
);
1706 /* The size must be a multiple of bw x bh, or we must be using a
1707 * offset+size that exactly hits the edge of the image. This
1708 * is important for small mipmap levels (1x1, 2x1, etc) and for
1711 if ((subWidth
% bw
!= 0) &&
1712 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1713 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1714 "%s(width = %d)", func
, subWidth
);
1718 if ((subHeight
% bh
!= 0) &&
1719 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1720 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1721 "%s(height = %d)", func
, subHeight
);
1733 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1734 * specific texture image size checks.
1736 * A hardware driver might override this function if, for example, the
1737 * max 3D texture size is 512x512x64 (i.e. not a cube).
1739 * Note that width, height, depth == 0 is not an error. However, a
1740 * texture with zero width/height/depth will be considered "incomplete"
1741 * and texturing will effectively be disabled.
1743 * \param target any texture target/type
1744 * \param level as passed to glTexImage
1745 * \param format the MESA_FORMAT_x for the tex image
1746 * \param width as passed to glTexImage
1747 * \param height as passed to glTexImage
1748 * \param depth as passed to glTexImage
1749 * \param border as passed to glTexImage
1750 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1753 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1755 GLint width
, GLint height
, GLint depth
, GLint border
)
1757 /* We just check if the image size is less than MaxTextureMbytes.
1758 * Some drivers may do more specific checks.
1760 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1761 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1762 mbytes
*= _mesa_num_tex_faces(target
);
1763 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1768 * Return true if the format is only valid for glCompressedTexImage.
1771 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1774 case GL_ETC1_RGB8_OES
:
1775 case GL_PALETTE4_RGB8_OES
:
1776 case GL_PALETTE4_RGBA8_OES
:
1777 case GL_PALETTE4_R5_G6_B5_OES
:
1778 case GL_PALETTE4_RGBA4_OES
:
1779 case GL_PALETTE4_RGB5_A1_OES
:
1780 case GL_PALETTE8_RGB8_OES
:
1781 case GL_PALETTE8_RGBA8_OES
:
1782 case GL_PALETTE8_R5_G6_B5_OES
:
1783 case GL_PALETTE8_RGBA4_OES
:
1784 case GL_PALETTE8_RGB5_A1_OES
:
1792 * Return true if the format doesn't support online compression.
1795 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
)
1797 return _mesa_is_astc_format(format
) ||
1798 compressedteximage_only_format(ctx
, format
);
1801 /* Writes to an GL error pointer if non-null and returns whether or not the
1802 * error is GL_NO_ERROR */
1804 write_error(GLenum
*err_ptr
, GLenum error
)
1809 return error
== GL_NO_ERROR
;
1813 * Helper function to determine whether a target and specific compression
1814 * format are supported. The error parameter returns GL_NO_ERROR if the
1815 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1816 * or GL_INVALID_ENUM, whichever is more appropriate.
1819 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1820 GLenum intFormat
, GLenum
*error
)
1822 GLboolean target_can_be_compresed
= GL_FALSE
;
1823 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1824 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1828 case GL_PROXY_TEXTURE_2D
:
1829 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1831 case GL_PROXY_TEXTURE_CUBE_MAP
:
1832 case GL_TEXTURE_CUBE_MAP
:
1833 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1834 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1835 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1836 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1837 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1838 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1839 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1841 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1842 case GL_TEXTURE_2D_ARRAY_EXT
:
1843 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1845 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1846 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1847 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1849 * "The ETC2/EAC texture compression algorithm supports only
1850 * two-dimensional images. If internalformat is an ETC2/EAC format,
1851 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1852 * target is not TEXTURE_2D_ARRAY."
1854 * This should also be applicable for glTexStorage3D(). Other available
1855 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1857 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
))
1858 return write_error(error
, GL_INVALID_OPERATION
);
1860 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map_array
;
1862 /* From the KHR_texture_compression_astc_hdr spec:
1864 * Add a second new column "3D Tex." which is empty for all non-ASTC
1865 * formats. If only the LDR profile is supported by the
1866 * implementation, this column is also empty for all ASTC formats. If
1867 * both the LDR and HDR profiles are supported only, this column is
1868 * checked for all ASTC formats.
1870 * Add a third new column "Cube Map Array Tex." which is empty for all
1871 * non-ASTC formats, and checked for all ASTC formats.
1875 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1876 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1877 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1878 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1879 * 8.19 is *not* checked'
1881 * The instances of <internalformat> above should say <target>.
1884 /* Throw an INVALID_OPERATION error if the target is
1885 * TEXTURE_CUBE_MAP_ARRAY and the format is not ASTC.
1887 if (target_can_be_compresed
&&
1888 ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
1889 layout
!= MESA_FORMAT_LAYOUT_ASTC
)
1890 return write_error(error
, GL_INVALID_OPERATION
);
1895 case MESA_FORMAT_LAYOUT_ETC2
:
1896 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1897 if (_mesa_is_gles3(ctx
))
1898 return write_error(error
, GL_INVALID_OPERATION
);
1900 case MESA_FORMAT_LAYOUT_BPTC
:
1901 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1903 case MESA_FORMAT_LAYOUT_ASTC
:
1904 target_can_be_compresed
=
1905 ctx
->Extensions
.KHR_texture_compression_astc_hdr
;
1907 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1908 * and the hdr extension is not supported.
1909 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1911 if (!target_can_be_compresed
)
1912 return write_error(error
, GL_INVALID_OPERATION
);
1915 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1916 * the format is not ASTC.
1917 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1919 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
)
1920 return write_error(error
, GL_INVALID_OPERATION
);
1926 return write_error(error
,
1927 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1932 * Check if the given texture target value is legal for a
1933 * glTexImage1/2/3D call.
1936 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1942 case GL_PROXY_TEXTURE_1D
:
1943 return _mesa_is_desktop_gl(ctx
);
1951 case GL_PROXY_TEXTURE_2D
:
1952 return _mesa_is_desktop_gl(ctx
);
1953 case GL_PROXY_TEXTURE_CUBE_MAP
:
1954 return _mesa_is_desktop_gl(ctx
)
1955 && ctx
->Extensions
.ARB_texture_cube_map
;
1956 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1957 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1958 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1959 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1960 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1961 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1962 return ctx
->Extensions
.ARB_texture_cube_map
;
1963 case GL_TEXTURE_RECTANGLE_NV
:
1964 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1965 return _mesa_is_desktop_gl(ctx
)
1966 && ctx
->Extensions
.NV_texture_rectangle
;
1967 case GL_TEXTURE_1D_ARRAY_EXT
:
1968 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1969 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1977 case GL_PROXY_TEXTURE_3D
:
1978 return _mesa_is_desktop_gl(ctx
);
1979 case GL_TEXTURE_2D_ARRAY_EXT
:
1980 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1981 || _mesa_is_gles3(ctx
);
1982 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1983 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1984 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1985 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1986 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1991 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1998 * Check if the given texture target value is legal for a
1999 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
2000 * The difference compared to legal_teximage_target() above is that
2001 * proxy targets are not supported.
2004 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
2009 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
2014 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2015 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2016 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2017 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2018 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2019 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2020 return ctx
->Extensions
.ARB_texture_cube_map
;
2021 case GL_TEXTURE_RECTANGLE_NV
:
2022 return _mesa_is_desktop_gl(ctx
)
2023 && ctx
->Extensions
.NV_texture_rectangle
;
2024 case GL_TEXTURE_1D_ARRAY_EXT
:
2025 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
2033 case GL_TEXTURE_2D_ARRAY_EXT
:
2034 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
2035 || _mesa_is_gles3(ctx
);
2036 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2037 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
2038 return ctx
->Extensions
.ARB_texture_cube_map_array
;
2040 /* Table 8.15 of the OpenGL 4.5 core profile spec
2041 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
2042 * and CopyTextureSubImage3D.
2044 case GL_TEXTURE_CUBE_MAP
:
2050 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
2058 * Helper function to determine if a texture object is mutable (in terms
2059 * of GL_ARB_texture_storage).
2062 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
2064 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
2068 return !texObj
->Immutable
;
2073 * Return expected size of a compressed texture.
2076 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2079 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2080 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2084 * Verify that a texture format is valid with a particular target
2086 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
2087 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
2090 * \param ctx GL context
2091 * \param target Texture target
2092 * \param internalFormat Internal format of the texture image
2093 * \param dimensions Dimensionality at the caller. This is \b not used
2094 * in the validation. It is only used when logging
2096 * \param caller Base name of the calling function (e.g.,
2097 * "glTexImage" or "glTexStorage").
2099 * \returns true if the combination is legal, false otherwise.
2102 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
2103 GLenum target
, GLenum internalFormat
,
2104 unsigned dimensions
,
2107 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2108 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
2109 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
2110 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
2111 * Profile spec says:
2113 * "Textures with a base internal format of DEPTH_COMPONENT or
2114 * DEPTH_STENCIL are supported by texture image specification
2115 * commands only if target is TEXTURE_1D, TEXTURE_2D,
2116 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
2117 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
2118 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
2119 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
2120 * formats in conjunction with any other target will result in an
2121 * INVALID_OPERATION error."
2123 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
2124 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
2126 if (target
!= GL_TEXTURE_1D
&&
2127 target
!= GL_PROXY_TEXTURE_1D
&&
2128 target
!= GL_TEXTURE_2D
&&
2129 target
!= GL_PROXY_TEXTURE_2D
&&
2130 target
!= GL_TEXTURE_1D_ARRAY
&&
2131 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2132 target
!= GL_TEXTURE_2D_ARRAY
&&
2133 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2134 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2135 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2136 !((_mesa_is_cube_face(target
) ||
2137 target
== GL_TEXTURE_CUBE_MAP
||
2138 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2139 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2140 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2141 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2142 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2143 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2144 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2145 "%s%dD(bad target for depth texture)",
2146 caller
, dimensions
);
2155 texture_formats_agree(GLenum internalFormat
,
2158 GLboolean colorFormat
;
2159 GLboolean is_format_depth_or_depthstencil
;
2160 GLboolean is_internalFormat_depth_or_depthstencil
;
2162 /* Even though there are no color-index textures, we still have to support
2163 * uploading color-index data and remapping it to RGB via the
2164 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2166 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2168 is_internalFormat_depth_or_depthstencil
=
2169 _mesa_is_depth_format(internalFormat
) ||
2170 _mesa_is_depthstencil_format(internalFormat
);
2172 is_format_depth_or_depthstencil
=
2173 _mesa_is_depth_format(format
) ||
2174 _mesa_is_depthstencil_format(format
);
2176 colorFormat
= _mesa_is_color_format(format
);
2178 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2181 if (is_internalFormat_depth_or_depthstencil
!=
2182 is_format_depth_or_depthstencil
)
2185 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2192 * Test the combination of format, type and internal format arguments of
2193 * different texture operations on GLES.
2195 * \param ctx GL context.
2196 * \param format pixel data format given by the user.
2197 * \param type pixel data type given by the user.
2198 * \param internalFormat internal format given by the user.
2199 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2200 * \param callerName name of the caller function to print in the error message
2202 * \return true if a error is found, false otherwise
2204 * Currently, it is used by texture_error_check() and texsubimage_error_check().
2207 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
2208 GLenum type
, GLenum internalFormat
,
2209 GLuint dimensions
, const char *callerName
)
2213 if (_mesa_is_gles3(ctx
)) {
2214 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
2216 if (err
!= GL_NO_ERROR
) {
2217 _mesa_error(ctx
, err
,
2218 "%s(format = %s, type = %s, internalformat = %s)",
2219 callerName
, _mesa_enum_to_string(format
),
2220 _mesa_enum_to_string(type
),
2221 _mesa_enum_to_string(internalFormat
));
2226 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2227 if (err
!= GL_NO_ERROR
) {
2228 _mesa_error(ctx
, err
, "%s(format = %s, type = %s)",
2229 callerName
, _mesa_enum_to_string(format
),
2230 _mesa_enum_to_string(type
));
2239 * Test the glTexImage[123]D() parameters for errors.
2241 * \param ctx GL context.
2242 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2243 * \param target texture target given by the user (already validated).
2244 * \param level image level given by the user.
2245 * \param internalFormat internal format given by the user.
2246 * \param format pixel data format given by the user.
2247 * \param type pixel data type given by the user.
2248 * \param width image width given by the user.
2249 * \param height image height given by the user.
2250 * \param depth image depth given by the user.
2251 * \param border image border given by the user.
2253 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2255 * Verifies each of the parameters against the constants specified in
2256 * __struct gl_contextRec::Const and the supported extensions, and according
2257 * to the OpenGL specification.
2258 * Note that we don't fully error-check the width, height, depth values
2259 * here. That's done in _mesa_legal_texture_dimensions() which is used
2260 * by several other GL entrypoints. Plus, texture dims have a special
2261 * interaction with proxy textures.
2264 texture_error_check( struct gl_context
*ctx
,
2265 GLuint dimensions
, GLenum target
,
2266 GLint level
, GLint internalFormat
,
2267 GLenum format
, GLenum type
,
2268 GLint width
, GLint height
,
2269 GLint depth
, GLint border
,
2270 const GLvoid
*pixels
)
2274 /* Note: for proxy textures, some error conditions immediately generate
2275 * a GL error in the usual way. But others do not generate a GL error.
2276 * Instead, they cause the width, height, depth, format fields of the
2277 * texture image to be zeroed-out. The GL spec seems to indicate that the
2278 * zero-out behaviour is only used in cases related to memory allocation.
2282 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2283 _mesa_error(ctx
, GL_INVALID_VALUE
,
2284 "glTexImage%dD(level=%d)", dimensions
, level
);
2289 if (border
< 0 || border
> 1 ||
2290 ((ctx
->API
!= API_OPENGL_COMPAT
||
2291 target
== GL_TEXTURE_RECTANGLE_NV
||
2292 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2293 _mesa_error(ctx
, GL_INVALID_VALUE
,
2294 "glTexImage%dD(border=%d)", dimensions
, border
);
2298 if (width
< 0 || height
< 0 || depth
< 0) {
2299 _mesa_error(ctx
, GL_INVALID_VALUE
,
2300 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2304 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2305 * combinations of format, internalFormat, and type that can be used.
2306 * Formats and types that require additional extensions (e.g., GL_FLOAT
2307 * requires GL_OES_texture_float) are filtered elsewhere.
2309 if (_mesa_is_gles(ctx
) &&
2310 texture_format_error_check_gles(ctx
, format
, type
, internalFormat
,
2311 dimensions
, "glTexImage%dD")) {
2315 /* Check internalFormat */
2316 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2317 _mesa_error(ctx
, GL_INVALID_VALUE
,
2318 "glTexImage%dD(internalFormat=%s)",
2319 dimensions
, _mesa_enum_to_string(internalFormat
));
2323 /* Check incoming image format and type */
2324 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2325 if (err
!= GL_NO_ERROR
) {
2326 _mesa_error(ctx
, err
,
2327 "glTexImage%dD(incompatible format = %s, type = %s)",
2328 dimensions
, _mesa_enum_to_string(format
),
2329 _mesa_enum_to_string(type
));
2333 /* validate the bound PBO, if any */
2334 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2335 width
, height
, depth
, format
, type
,
2336 INT_MAX
, pixels
, "glTexImage")) {
2340 /* make sure internal format and format basically agree */
2341 if (!texture_formats_agree(internalFormat
, format
)) {
2342 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2343 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2344 dimensions
, _mesa_enum_to_string(internalFormat
),
2345 _mesa_enum_to_string(format
));
2349 /* additional checks for ycbcr textures */
2350 if (internalFormat
== GL_YCBCR_MESA
) {
2351 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
2352 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2353 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2355 _mesa_snprintf(message
, sizeof(message
),
2356 "glTexImage%dD(format/type YCBCR mismatch)",
2358 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2359 return GL_TRUE
; /* error */
2361 if (target
!= GL_TEXTURE_2D
&&
2362 target
!= GL_PROXY_TEXTURE_2D
&&
2363 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2364 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2365 _mesa_error(ctx
, GL_INVALID_ENUM
,
2366 "glTexImage%dD(bad target for YCbCr texture)",
2372 _mesa_snprintf(message
, sizeof(message
),
2373 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2374 dimensions
, border
);
2375 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2380 /* additional checks for depth textures */
2381 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2382 dimensions
, "glTexImage"))
2385 /* additional checks for compressed textures */
2386 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2388 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2389 _mesa_error(ctx
, err
,
2390 "glTexImage%dD(target can't be compressed)", dimensions
);
2393 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2394 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2395 "glTexImage%dD(no compression for format)", dimensions
);
2399 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2400 "glTexImage%dD(border!=0)", dimensions
);
2405 /* additional checks for integer textures */
2406 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2407 (_mesa_is_enum_format_integer(format
) !=
2408 _mesa_is_enum_format_integer(internalFormat
))) {
2409 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2410 "glTexImage%dD(integer/non-integer format mismatch)",
2415 if (!mutable_tex_object(ctx
, target
)) {
2416 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2417 "glTexImage%dD(immutable texture)", dimensions
);
2421 /* if we get here, the parameters are OK */
2427 * Error checking for glCompressedTexImage[123]D().
2428 * Note that the width, height and depth values are not fully error checked
2430 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2433 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2434 GLenum target
, GLint level
,
2435 GLenum internalFormat
, GLsizei width
,
2436 GLsizei height
, GLsizei depth
, GLint border
,
2437 GLsizei imageSize
, const GLvoid
*data
)
2439 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2441 GLenum error
= GL_NO_ERROR
;
2442 char *reason
= ""; /* no error */
2444 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
2449 /* This will detect any invalid internalFormat value */
2450 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2451 _mesa_error(ctx
, GL_INVALID_ENUM
,
2452 "glCompressedTexImage%dD(internalFormat=%s)",
2453 dimensions
, _mesa_enum_to_string(internalFormat
));
2457 /* validate the bound PBO, if any */
2458 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2460 "glCompressedTexImage")) {
2464 switch (internalFormat
) {
2465 case GL_PALETTE4_RGB8_OES
:
2466 case GL_PALETTE4_RGBA8_OES
:
2467 case GL_PALETTE4_R5_G6_B5_OES
:
2468 case GL_PALETTE4_RGBA4_OES
:
2469 case GL_PALETTE4_RGB5_A1_OES
:
2470 case GL_PALETTE8_RGB8_OES
:
2471 case GL_PALETTE8_RGBA8_OES
:
2472 case GL_PALETTE8_R5_G6_B5_OES
:
2473 case GL_PALETTE8_RGBA4_OES
:
2474 case GL_PALETTE8_RGB5_A1_OES
:
2475 /* check level (note that level should be zero or less!) */
2476 if (level
> 0 || level
< -maxLevels
) {
2478 error
= GL_INVALID_VALUE
;
2482 if (dimensions
!= 2) {
2483 reason
= "compressed paletted textures must be 2D";
2484 error
= GL_INVALID_OPERATION
;
2488 /* Figure out the expected texture size (in bytes). This will be
2489 * checked against the actual size later.
2491 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2494 /* This is for the benefit of the TestProxyTexImage below. It expects
2495 * level to be non-negative. OES_compressed_paletted_texture uses a
2496 * weird mechanism where the level specified to glCompressedTexImage2D
2497 * is -(n-1) number of levels in the texture, and the data specifies the
2498 * complete mipmap stack. This is done to ensure the palette is the
2499 * same for all levels.
2506 if (level
< 0 || level
>= maxLevels
) {
2508 error
= GL_INVALID_VALUE
;
2512 /* Figure out the expected texture size (in bytes). This will be
2513 * checked against the actual size later.
2515 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2519 /* This should really never fail */
2520 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2521 reason
= "internalFormat";
2522 error
= GL_INVALID_ENUM
;
2526 /* No compressed formats support borders at this time */
2528 reason
= "border != 0";
2529 error
= GL_INVALID_VALUE
;
2533 /* Check for invalid pixel storage modes */
2534 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2536 "glCompressedTexImage")) {
2540 /* check image size in bytes */
2541 if (expectedSize
!= imageSize
) {
2542 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2543 * if <imageSize> is not consistent with the format, dimensions, and
2544 * contents of the specified image.
2546 reason
= "imageSize inconsistant with width/height/format";
2547 error
= GL_INVALID_VALUE
;
2551 if (!mutable_tex_object(ctx
, target
)) {
2552 reason
= "immutable texture";
2553 error
= GL_INVALID_OPERATION
;
2560 /* Note: not all error paths exit through here. */
2561 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2562 dimensions
, reason
);
2569 * Test glTexSubImage[123]D() parameters for errors.
2571 * \param ctx GL context.
2572 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2573 * \param target texture target given by the user (already validated)
2574 * \param level image level given by the user.
2575 * \param xoffset sub-image x offset given by the user.
2576 * \param yoffset sub-image y offset given by the user.
2577 * \param zoffset sub-image z offset given by the user.
2578 * \param format pixel data format given by the user.
2579 * \param type pixel data type given by the user.
2580 * \param width image width given by the user.
2581 * \param height image height given by the user.
2582 * \param depth image depth given by the user.
2584 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2586 * Verifies each of the parameters against the constants specified in
2587 * __struct gl_contextRec::Const and the supported extensions, and according
2588 * to the OpenGL specification.
2591 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2592 struct gl_texture_object
*texObj
,
2593 GLenum target
, GLint level
,
2594 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2595 GLint width
, GLint height
, GLint depth
,
2596 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2597 bool dsa
, const char *callerName
)
2599 struct gl_texture_image
*texImage
;
2603 /* must be out of memory */
2604 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2609 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2610 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2614 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2616 /* non-existant texture level */
2617 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture image)",
2622 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2623 if (err
!= GL_NO_ERROR
) {
2624 _mesa_error(ctx
, err
,
2625 "%s(incompatible format = %s, type = %s)",
2626 callerName
, _mesa_enum_to_string(format
),
2627 _mesa_enum_to_string(type
));
2631 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2632 * combinations of format, internalFormat, and type that can be used.
2633 * Formats and types that require additional extensions (e.g., GL_FLOAT
2634 * requires GL_OES_texture_float) are filtered elsewhere.
2636 if (_mesa_is_gles(ctx
) &&
2637 texture_format_error_check_gles(ctx
, format
, type
,
2638 texImage
->InternalFormat
,
2639 dimensions
, callerName
)) {
2643 /* validate the bound PBO, if any */
2644 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2645 width
, height
, depth
, format
, type
,
2646 INT_MAX
, pixels
, callerName
)) {
2650 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2651 texImage
, xoffset
, yoffset
, zoffset
,
2652 width
, height
, depth
, callerName
)) {
2656 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2657 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2658 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2659 "%s(no compression for format)", callerName
);
2664 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2665 /* both source and dest must be integer-valued, or neither */
2666 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2667 _mesa_is_enum_format_integer(format
)) {
2668 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2669 "%s(integer/non-integer format mismatch)", callerName
);
2679 * Test glCopyTexImage[12]D() parameters for errors.
2681 * \param ctx GL context.
2682 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2683 * \param target texture target given by the user.
2684 * \param level image level given by the user.
2685 * \param internalFormat internal format given by the user.
2686 * \param width image width given by the user.
2687 * \param height image height given by the user.
2688 * \param border texture border.
2690 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2692 * Verifies each of the parameters against the constants specified in
2693 * __struct gl_contextRec::Const and the supported extensions, and according
2694 * to the OpenGL specification.
2697 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2698 GLenum target
, GLint level
, GLint internalFormat
,
2699 GLint width
, GLint height
, GLint border
)
2702 GLint rb_base_format
;
2703 struct gl_renderbuffer
*rb
;
2704 GLenum rb_internal_format
;
2707 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2708 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2709 dimensions
, _mesa_enum_to_string(target
));
2714 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2715 _mesa_error(ctx
, GL_INVALID_VALUE
,
2716 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2720 /* Check that the source buffer is complete */
2721 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2722 if (ctx
->ReadBuffer
->_Status
== 0) {
2723 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2725 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2726 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2727 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2731 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2732 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2733 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2739 if (border
< 0 || border
> 1 ||
2740 ((ctx
->API
!= API_OPENGL_COMPAT
||
2741 target
== GL_TEXTURE_RECTANGLE_NV
||
2742 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2743 _mesa_error(ctx
, GL_INVALID_VALUE
,
2744 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2748 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2751 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2752 switch (internalFormat
) {
2757 case GL_LUMINANCE_ALPHA
:
2760 _mesa_error(ctx
, GL_INVALID_ENUM
,
2761 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2762 _mesa_enum_to_string(internalFormat
));
2767 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2768 if (baseFormat
< 0) {
2769 _mesa_error(ctx
, GL_INVALID_ENUM
,
2770 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2771 _mesa_enum_to_string(internalFormat
));
2775 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2777 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2778 "glCopyTexImage%dD(read buffer)", dimensions
);
2782 rb_internal_format
= rb
->InternalFormat
;
2783 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2784 if (_mesa_is_color_format(internalFormat
)) {
2785 if (rb_base_format
< 0) {
2786 _mesa_error(ctx
, GL_INVALID_VALUE
,
2787 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2788 _mesa_enum_to_string(internalFormat
));
2793 if (_mesa_is_gles(ctx
)) {
2795 if (_mesa_base_format_component_count(baseFormat
) >
2796 _mesa_base_format_component_count(rb_base_format
)) {
2799 if (baseFormat
== GL_DEPTH_COMPONENT
||
2800 baseFormat
== GL_DEPTH_STENCIL
||
2801 rb_base_format
== GL_DEPTH_COMPONENT
||
2802 rb_base_format
== GL_DEPTH_STENCIL
||
2803 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2804 baseFormat
== GL_ALPHA
) &&
2805 rb_base_format
!= GL_RGBA
) ||
2806 internalFormat
== GL_RGB9_E5
) {
2809 if (internalFormat
== GL_RGB9_E5
) {
2813 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2814 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2815 _mesa_enum_to_string(internalFormat
));
2820 if (_mesa_is_gles3(ctx
)) {
2821 bool rb_is_srgb
= false;
2822 bool dst_is_srgb
= false;
2824 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2825 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2829 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2833 if (rb_is_srgb
!= dst_is_srgb
) {
2834 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2835 * OpenGLES 3.0.0 spec says:
2837 * "The error INVALID_OPERATION is also generated if the
2838 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2839 * framebuffer attachment corresponding to the read buffer
2840 * is LINEAR (see section 6.1.13) and internalformat is
2841 * one of the sRGB formats described in section 3.8.16, or
2842 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2843 * SRGB and internalformat is not one of the sRGB formats."
2845 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2846 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2850 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2851 * types for SNORM formats. Also, conversion to SNORM formats is not
2852 * allowed by Table 3.2 on Page 110.
2854 if (_mesa_is_enum_format_snorm(internalFormat
)) {
2855 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2856 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2857 _mesa_enum_to_string(internalFormat
));
2862 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2863 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2864 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2868 /* From the EXT_texture_integer spec:
2870 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2871 * if the texture internalformat is an integer format and the read color
2872 * buffer is not an integer format, or if the internalformat is not an
2873 * integer format and the read color buffer is an integer format."
2875 if (_mesa_is_color_format(internalFormat
)) {
2876 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2877 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2878 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2879 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2880 if (is_int
|| is_rbint
) {
2881 if (is_int
!= is_rbint
) {
2882 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2883 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2885 } else if (_mesa_is_gles(ctx
) &&
2886 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2887 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2888 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2889 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2894 /* From page 138 of OpenGL ES 3.0 spec:
2895 * "The error INVALID_OPERATION is generated if floating-point RGBA
2896 * data is required; if signed integer RGBA data is required and the
2897 * format of the current color buffer is not signed integer; if
2898 * unsigned integer RGBA data is required and the format of the
2899 * current color buffer is not unsigned integer; or if fixed-point
2900 * RGBA data is required and the format of the current color buffer
2901 * is not fixed-point.
2903 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2904 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2905 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2908 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2910 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2911 _mesa_error(ctx
, err
,
2912 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2915 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2916 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2917 "glCopyTexImage%dD(no compression for format)", dimensions
);
2921 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2922 "glCopyTexImage%dD(border!=0)", dimensions
);
2927 if (!mutable_tex_object(ctx
, target
)) {
2928 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2929 "glCopyTexImage%dD(immutable texture)", dimensions
);
2933 /* if we get here, the parameters are OK */
2939 * Test glCopyTexSubImage[12]D() parameters for errors.
2940 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2943 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2944 const struct gl_texture_object
*texObj
,
2945 GLenum target
, GLint level
,
2946 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2947 GLint width
, GLint height
, const char *caller
)
2949 struct gl_texture_image
*texImage
;
2951 /* Check that the source buffer is complete */
2952 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2953 if (ctx
->ReadBuffer
->_Status
== 0) {
2954 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2956 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2957 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2958 "%s(invalid readbuffer)", caller
);
2962 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2963 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2964 "%s(multisample FBO)", caller
);
2970 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2971 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2975 /* Get dest image pointers */
2977 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", caller
);
2981 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2983 /* destination image does not exist */
2984 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2985 "%s(invalid texture image)", caller
);
2989 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2990 xoffset
, yoffset
, zoffset
,
2991 width
, height
, 1, caller
)) {
2995 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2996 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2997 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2998 "%s(no compression for format)", caller
);
3003 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
3004 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
3008 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
3009 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3010 "%s(missing readbuffer, format=0x%x)", caller
,
3011 texImage
->_BaseFormat
);
3015 /* From the EXT_texture_integer spec:
3017 * "INVALID_OPERATION is generated by CopyTexImage* and
3018 * CopyTexSubImage* if the texture internalformat is an integer format
3019 * and the read color buffer is not an integer format, or if the
3020 * internalformat is not an integer format and the read color buffer
3021 * is an integer format."
3023 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
3024 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
3026 if (_mesa_is_format_integer_color(rb
->Format
) !=
3027 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
3028 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3029 "%s(integer vs non-integer)", caller
);
3034 /* if we get here, the parameters are OK */
3039 /** Callback info for walking over FBO hash table */
3042 struct gl_context
*ctx
;
3043 struct gl_texture_object
*texObj
;
3049 * Check render to texture callback. Called from _mesa_HashWalk().
3052 check_rtt_cb(GLuint key
, void *data
, void *userData
)
3054 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
3055 const struct cb_info
*info
= (struct cb_info
*) userData
;
3056 struct gl_context
*ctx
= info
->ctx
;
3057 const struct gl_texture_object
*texObj
= info
->texObj
;
3058 const GLuint level
= info
->level
, face
= info
->face
;
3060 /* If this is a user-created FBO */
3061 if (_mesa_is_user_fbo(fb
)) {
3063 /* check if any of the FBO's attachments point to 'texObj' */
3064 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
3065 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
3066 if (att
->Type
== GL_TEXTURE
&&
3067 att
->Texture
== texObj
&&
3068 att
->TextureLevel
== level
&&
3069 att
->CubeMapFace
== face
) {
3070 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
3071 assert(att
->Renderbuffer
->TexImage
);
3072 /* Mark fb status as indeterminate to force re-validation */
3081 * When a texture image is specified we have to check if it's bound to
3082 * any framebuffer objects (render to texture) in order to detect changes
3083 * in size or format since that effects FBO completeness.
3084 * Any FBOs rendering into the texture must be re-validated.
3087 _mesa_update_fbo_texture(struct gl_context
*ctx
,
3088 struct gl_texture_object
*texObj
,
3089 GLuint face
, GLuint level
)
3091 /* Only check this texture if it's been marked as RenderToTexture */
3092 if (texObj
->_RenderToTexture
) {
3093 struct cb_info info
;
3095 info
.texObj
= texObj
;
3098 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
3104 * If the texture object's GenerateMipmap flag is set and we've
3105 * changed the texture base level image, regenerate the rest of the
3106 * mipmap levels now.
3109 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
3110 struct gl_texture_object
*texObj
, GLint level
)
3112 if (texObj
->GenerateMipmap
&&
3113 level
== texObj
->BaseLevel
&&
3114 level
< texObj
->MaxLevel
) {
3115 assert(ctx
->Driver
.GenerateMipmap
);
3116 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3121 /** Debug helper: override the user-requested internal format */
3123 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
3126 if (internalFormat
== GL_RGBA16F_ARB
||
3127 internalFormat
== GL_RGBA32F_ARB
) {
3128 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3131 else if (internalFormat
== GL_RGB16F_ARB
||
3132 internalFormat
== GL_RGB32F_ARB
) {
3133 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3136 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3137 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3138 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3139 return GL_LUMINANCE_ALPHA
;
3141 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3142 internalFormat
== GL_LUMINANCE32F_ARB
) {
3143 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3144 return GL_LUMINANCE
;
3146 else if (internalFormat
== GL_ALPHA16F_ARB
||
3147 internalFormat
== GL_ALPHA32F_ARB
) {
3148 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3152 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3153 internalFormat = GL_RGBA;
3157 return internalFormat
;
3160 return internalFormat
;
3166 * Choose the actual hardware format for a texture image.
3167 * Try to use the same format as the previous image level when possible.
3168 * Otherwise, ask the driver for the best format.
3169 * It's important to try to choose a consistant format for all levels
3170 * for efficient texture memory layout/allocation. In particular, this
3171 * comes up during automatic mipmap generation.
3174 _mesa_choose_texture_format(struct gl_context
*ctx
,
3175 struct gl_texture_object
*texObj
,
3176 GLenum target
, GLint level
,
3177 GLenum internalFormat
, GLenum format
, GLenum type
)
3181 /* see if we've already chosen a format for the previous level */
3183 struct gl_texture_image
*prevImage
=
3184 _mesa_select_tex_image(texObj
, target
, level
- 1);
3185 /* See if the prev level is defined and has an internal format which
3186 * matches the new internal format.
3189 prevImage
->Width
> 0 &&
3190 prevImage
->InternalFormat
== internalFormat
) {
3191 /* use the same format */
3192 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3193 return prevImage
->TexFormat
;
3197 /* If the application requested compression to an S3TC format but we don't
3198 * have the DXTn library, force a generic compressed format instead.
3200 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3201 const GLenum before
= internalFormat
;
3203 switch (internalFormat
) {
3204 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3205 if (!ctx
->Mesa_DXTn
)
3206 internalFormat
= GL_COMPRESSED_RGB
;
3208 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3209 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3210 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3211 if (!ctx
->Mesa_DXTn
)
3212 internalFormat
= GL_COMPRESSED_RGBA
;
3218 if (before
!= internalFormat
) {
3220 "DXT compression requested (%s), "
3221 "but libtxc_dxtn library not installed. Using %s "
3223 _mesa_enum_to_string(before
),
3224 _mesa_enum_to_string(internalFormat
));
3228 /* choose format from scratch */
3229 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3231 assert(f
!= MESA_FORMAT_NONE
);
3237 * Adjust pixel unpack params and image dimensions to strip off the
3238 * one-pixel texture border.
3240 * Gallium and intel don't support texture borders. They've seldem been used
3241 * and seldom been implemented correctly anyway.
3243 * \param unpackNew returns the new pixel unpack parameters
3246 strip_texture_border(GLenum target
,
3247 GLint
*width
, GLint
*height
, GLint
*depth
,
3248 const struct gl_pixelstore_attrib
*unpack
,
3249 struct gl_pixelstore_attrib
*unpackNew
)
3255 *unpackNew
= *unpack
;
3257 if (unpackNew
->RowLength
== 0)
3258 unpackNew
->RowLength
= *width
;
3260 if (unpackNew
->ImageHeight
== 0)
3261 unpackNew
->ImageHeight
= *height
;
3263 assert(*width
>= 3);
3264 unpackNew
->SkipPixels
++; /* skip the border */
3265 *width
= *width
- 2; /* reduce the width by two border pixels */
3267 /* The min height of a texture with a border is 3 */
3268 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3269 unpackNew
->SkipRows
++; /* skip the border */
3270 *height
= *height
- 2; /* reduce the height by two border pixels */
3274 target
!= GL_TEXTURE_2D_ARRAY
&&
3275 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3276 unpackNew
->SkipImages
++; /* skip the border */
3277 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3283 * Common code to implement all the glTexImage1D/2D/3D functions
3284 * as well as glCompressedTexImage1D/2D/3D.
3285 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3286 * \param format the user's image format (only used if !compressed)
3287 * \param type the user's image type (only used if !compressed)
3288 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3291 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3292 GLenum target
, GLint level
, GLint internalFormat
,
3293 GLsizei width
, GLsizei height
, GLsizei depth
,
3294 GLint border
, GLenum format
, GLenum type
,
3295 GLsizei imageSize
, const GLvoid
*pixels
)
3297 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3298 struct gl_pixelstore_attrib unpack_no_border
;
3299 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3300 struct gl_texture_object
*texObj
;
3301 mesa_format texFormat
;
3302 GLboolean dimensionsOK
, sizeOK
;
3304 FLUSH_VERTICES(ctx
, 0);
3306 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3309 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3311 _mesa_enum_to_string(target
), level
,
3312 _mesa_enum_to_string(internalFormat
),
3313 width
, height
, depth
, border
, pixels
);
3316 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3318 _mesa_enum_to_string(target
), level
,
3319 _mesa_enum_to_string(internalFormat
),
3320 width
, height
, depth
, border
,
3321 _mesa_enum_to_string(format
),
3322 _mesa_enum_to_string(type
), pixels
);
3325 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3327 /* target error checking */
3328 if (!legal_teximage_target(ctx
, dims
, target
)) {
3329 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3330 func
, dims
, _mesa_enum_to_string(target
));
3334 /* general error checking */
3336 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3338 width
, height
, depth
,
3339 border
, imageSize
, pixels
))
3343 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3344 format
, type
, width
, height
, depth
, border
,
3349 /* Here we convert a cpal compressed image into a regular glTexImage2D
3350 * call by decompressing the texture. If we really want to support cpal
3351 * textures in any driver this would have to be changed.
3353 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3354 switch (internalFormat
) {
3355 case GL_PALETTE4_RGB8_OES
:
3356 case GL_PALETTE4_RGBA8_OES
:
3357 case GL_PALETTE4_R5_G6_B5_OES
:
3358 case GL_PALETTE4_RGBA4_OES
:
3359 case GL_PALETTE4_RGB5_A1_OES
:
3360 case GL_PALETTE8_RGB8_OES
:
3361 case GL_PALETTE8_RGBA8_OES
:
3362 case GL_PALETTE8_R5_G6_B5_OES
:
3363 case GL_PALETTE8_RGBA4_OES
:
3364 case GL_PALETTE8_RGB5_A1_OES
:
3365 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3366 width
, height
, imageSize
, pixels
);
3371 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3375 /* For glCompressedTexImage() the driver has no choice about the
3376 * texture format since we'll never transcode the user's compressed
3377 * image data. The internalFormat was error checked earlier.
3379 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3382 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3383 * internal floating point format for the given base format.
3385 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3386 if (type
== GL_FLOAT
) {
3387 texObj
->_IsFloat
= GL_TRUE
;
3388 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3389 texObj
->_IsHalfFloat
= GL_TRUE
;
3392 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3395 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3396 internalFormat
, format
, type
);
3399 assert(texFormat
!= MESA_FORMAT_NONE
);
3401 /* check that width, height, depth are legal for the mipmap level */
3402 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3403 height
, depth
, border
);
3405 /* check that the texture won't take too much memory, etc */
3406 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3408 width
, height
, depth
, border
);
3410 if (_mesa_is_proxy_texture(target
)) {
3411 /* Proxy texture: just clear or set state depending on error checking */
3412 struct gl_texture_image
*texImage
=
3413 get_proxy_tex_image(ctx
, target
, level
);
3416 return; /* GL_OUT_OF_MEMORY already recorded */
3418 if (dimensionsOK
&& sizeOK
) {
3419 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3420 border
, internalFormat
, texFormat
);
3423 clear_teximage_fields(texImage
);
3427 /* non-proxy target */
3428 const GLuint face
= _mesa_tex_target_to_face(target
);
3429 struct gl_texture_image
*texImage
;
3431 if (!dimensionsOK
) {
3432 _mesa_error(ctx
, GL_INVALID_VALUE
,
3433 "%s%uD(invalid width or height or depth)",
3439 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3440 "%s%uD(image too large: %d x %d x %d, %s format)",
3441 func
, dims
, width
, height
, depth
,
3442 _mesa_enum_to_string(internalFormat
));
3446 /* Allow a hardware driver to just strip out the border, to provide
3447 * reliable but slightly incorrect hardware rendering instead of
3448 * rarely-tested software fallback rendering.
3450 if (border
&& ctx
->Const
.StripTextureBorder
) {
3451 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3454 unpack
= &unpack_no_border
;
3457 if (ctx
->NewState
& _NEW_PIXEL
)
3458 _mesa_update_state(ctx
);
3460 _mesa_lock_texture(ctx
, texObj
);
3462 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3465 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3468 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3470 _mesa_init_teximage_fields(ctx
, texImage
,
3471 width
, height
, depth
,
3472 border
, internalFormat
, texFormat
);
3474 /* Give the texture to the driver. <pixels> may be null. */
3475 if (width
> 0 && height
> 0 && depth
> 0) {
3477 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3481 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3482 type
, pixels
, unpack
);
3486 check_gen_mipmap(ctx
, target
, texObj
, level
);
3488 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3490 _mesa_dirty_texobj(ctx
, texObj
);
3493 _mesa_unlock_texture(ctx
, texObj
);
3500 * Called from the API. Note that width includes the border.
3503 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3504 GLsizei width
, GLint border
, GLenum format
,
3505 GLenum type
, const GLvoid
*pixels
)
3507 GET_CURRENT_CONTEXT(ctx
);
3508 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3509 border
, format
, type
, 0, pixels
);
3514 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3515 GLsizei width
, GLsizei height
, GLint border
,
3516 GLenum format
, GLenum type
,
3517 const GLvoid
*pixels
)
3519 GET_CURRENT_CONTEXT(ctx
);
3520 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3521 border
, format
, type
, 0, pixels
);
3526 * Called by the API or display list executor.
3527 * Note that width and height include the border.
3530 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3531 GLsizei width
, GLsizei height
, GLsizei depth
,
3532 GLint border
, GLenum format
, GLenum type
,
3533 const GLvoid
*pixels
)
3535 GET_CURRENT_CONTEXT(ctx
);
3536 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3537 width
, height
, depth
,
3538 border
, format
, type
, 0, pixels
);
3543 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3544 GLsizei width
, GLsizei height
, GLsizei depth
,
3545 GLint border
, GLenum format
, GLenum type
,
3546 const GLvoid
*pixels
)
3548 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3549 depth
, border
, format
, type
, pixels
);
3554 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3556 struct gl_texture_object
*texObj
;
3557 struct gl_texture_image
*texImage
;
3559 GET_CURRENT_CONTEXT(ctx
);
3560 FLUSH_VERTICES(ctx
, 0);
3564 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3566 case GL_TEXTURE_EXTERNAL_OES
:
3568 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3571 valid_target
= false;
3575 if (!valid_target
) {
3576 _mesa_error(ctx
, GL_INVALID_ENUM
,
3577 "glEGLImageTargetTexture2D(target=%d)", target
);
3582 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3583 "glEGLImageTargetTexture2D(image=%p)", image
);
3587 if (ctx
->NewState
& _NEW_PIXEL
)
3588 _mesa_update_state(ctx
);
3590 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3594 _mesa_lock_texture(ctx
, texObj
);
3596 if (texObj
->Immutable
) {
3597 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3598 "glEGLImageTargetTexture2D(texture is immutable)");
3599 _mesa_unlock_texture(ctx
, texObj
);
3603 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3605 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3607 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3609 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3610 texObj
, texImage
, image
);
3612 _mesa_dirty_texobj(ctx
, texObj
);
3614 _mesa_unlock_texture(ctx
, texObj
);
3619 * Helper that implements the glTexSubImage1/2/3D()
3620 * and glTextureSubImage1/2/3D() functions.
3623 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3624 struct gl_texture_object
*texObj
,
3625 struct gl_texture_image
*texImage
,
3626 GLenum target
, GLint level
,
3627 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3628 GLsizei width
, GLsizei height
, GLsizei depth
,
3629 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3632 FLUSH_VERTICES(ctx
, 0);
3634 if (ctx
->NewState
& _NEW_PIXEL
)
3635 _mesa_update_state(ctx
);
3637 _mesa_lock_texture(ctx
, texObj
);
3639 if (width
> 0 && height
> 0 && depth
> 0) {
3640 /* If we have a border, offset=-1 is legal. Bias by border width. */
3643 if (target
!= GL_TEXTURE_2D_ARRAY
)
3644 zoffset
+= texImage
->Border
;
3647 if (target
!= GL_TEXTURE_1D_ARRAY
)
3648 yoffset
+= texImage
->Border
;
3651 xoffset
+= texImage
->Border
;
3654 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3655 xoffset
, yoffset
, zoffset
,
3656 width
, height
, depth
,
3657 format
, type
, pixels
, &ctx
->Unpack
);
3659 check_gen_mipmap(ctx
, target
, texObj
, level
);
3661 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3662 * the texel data, not the texture format, size, etc.
3666 _mesa_unlock_texture(ctx
, texObj
);
3670 * Implement all the glTexSubImage1/2/3D() functions.
3671 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3674 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3675 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3676 GLsizei width
, GLsizei height
, GLsizei depth
,
3677 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3678 const char *callerName
)
3680 struct gl_texture_object
*texObj
;
3681 struct gl_texture_image
*texImage
;
3683 /* check target (proxies not allowed) */
3684 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3685 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3686 dims
, _mesa_enum_to_string(target
));
3690 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3694 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3695 xoffset
, yoffset
, zoffset
,
3696 width
, height
, depth
, format
, type
,
3697 pixels
, false, callerName
)) {
3698 return; /* error was detected */
3701 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3702 /* texsubimage_error_check ensures that texImage is not NULL */
3704 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3705 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3707 _mesa_enum_to_string(target
), level
,
3708 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3709 _mesa_enum_to_string(format
),
3710 _mesa_enum_to_string(type
), pixels
);
3712 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3713 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3714 format
, type
, pixels
, false);
3719 * Implement all the glTextureSubImage1/2/3D() functions.
3720 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3723 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3724 GLuint texture
, GLint level
,
3725 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3726 GLsizei width
, GLsizei height
, GLsizei depth
,
3727 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3728 const char *callerName
)
3730 struct gl_texture_object
*texObj
;
3731 struct gl_texture_image
*texImage
;
3734 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3736 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3737 dims
, texture
, level
,
3738 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3739 _mesa_enum_to_string(format
),
3740 _mesa_enum_to_string(type
), pixels
);
3742 /* Get the texture object by Name. */
3743 texObj
= _mesa_lookup_texture(ctx
, texture
);
3745 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3750 /* check target (proxies not allowed) */
3751 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3752 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3753 callerName
, _mesa_enum_to_string(texObj
->Target
));
3757 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3758 xoffset
, yoffset
, zoffset
,
3759 width
, height
, depth
, format
, type
,
3760 pixels
, true, callerName
)) {
3761 return; /* error was detected */
3765 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3766 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3770 * What do we do if the user created a texture with the following code
3771 * and then called this function with its handle?
3774 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3775 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3776 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3777 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3778 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3779 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3780 * // wrong format, or given the wrong size, etc.
3781 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3782 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3784 * A bug has been filed against the spec for this case. In the
3785 * meantime, we will check for cube completeness.
3787 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3788 * Core Profile spec (30.10.2014):
3789 * "[A] cube map texture is cube complete if the
3790 * following conditions all hold true: The [base level] texture
3791 * images of each of the six cube map faces have identical, positive,
3792 * and square dimensions. The [base level] images were each specified
3793 * with the same internal format."
3795 * It seems reasonable to check for cube completeness of an arbitrary
3796 * level here so that the image data has a consistent format and size.
3798 if (!_mesa_cube_level_complete(texObj
, level
)) {
3799 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3800 "glTextureSubImage%uD(cube map incomplete)",
3805 rowStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3807 /* Copy in each face. */
3808 for (i
= 0; i
< 6; ++i
) {
3809 texImage
= texObj
->Image
[i
][level
];
3812 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3813 level
, xoffset
, yoffset
, zoffset
,
3814 width
, height
, 1, format
,
3815 type
, pixels
, true);
3816 pixels
= (GLubyte
*) pixels
+ rowStride
;
3820 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3823 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3824 level
, xoffset
, yoffset
, zoffset
,
3825 width
, height
, depth
, format
,
3826 type
, pixels
, true);
3832 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3833 GLint xoffset
, GLsizei width
,
3834 GLenum format
, GLenum type
,
3835 const GLvoid
*pixels
)
3837 GET_CURRENT_CONTEXT(ctx
);
3838 texsubimage(ctx
, 1, target
, level
,
3841 format
, type
, pixels
, "glTexSubImage1D");
3846 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3847 GLint xoffset
, GLint yoffset
,
3848 GLsizei width
, GLsizei height
,
3849 GLenum format
, GLenum type
,
3850 const GLvoid
*pixels
)
3852 GET_CURRENT_CONTEXT(ctx
);
3853 texsubimage(ctx
, 2, target
, level
,
3854 xoffset
, yoffset
, 0,
3856 format
, type
, pixels
, "glTexSubImage2D");
3862 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3863 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3864 GLsizei width
, GLsizei height
, GLsizei depth
,
3865 GLenum format
, GLenum type
,
3866 const GLvoid
*pixels
)
3868 GET_CURRENT_CONTEXT(ctx
);
3869 texsubimage(ctx
, 3, target
, level
,
3870 xoffset
, yoffset
, zoffset
,
3871 width
, height
, depth
,
3872 format
, type
, pixels
, "glTexSubImage3D");
3876 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3877 GLint xoffset
, GLsizei width
,
3878 GLenum format
, GLenum type
,
3879 const GLvoid
*pixels
)
3881 GET_CURRENT_CONTEXT(ctx
);
3882 texturesubimage(ctx
, 1, texture
, level
,
3885 format
, type
, pixels
, "glTextureSubImage1D");
3890 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3891 GLint xoffset
, GLint yoffset
,
3892 GLsizei width
, GLsizei height
,
3893 GLenum format
, GLenum type
,
3894 const GLvoid
*pixels
)
3896 GET_CURRENT_CONTEXT(ctx
);
3897 texturesubimage(ctx
, 2, texture
, level
,
3898 xoffset
, yoffset
, 0,
3900 format
, type
, pixels
, "glTextureSubImage2D");
3905 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3906 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3907 GLsizei width
, GLsizei height
, GLsizei depth
,
3908 GLenum format
, GLenum type
,
3909 const GLvoid
*pixels
)
3911 GET_CURRENT_CONTEXT(ctx
);
3912 texturesubimage(ctx
, 3, texture
, level
,
3913 xoffset
, yoffset
, zoffset
,
3914 width
, height
, depth
,
3915 format
, type
, pixels
, "glTextureSubImage3D");
3920 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3921 * from. This depends on whether the texture contains color or depth values.
3923 static struct gl_renderbuffer
*
3924 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3926 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3927 /* reading from depth/stencil buffer */
3928 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3931 /* copying from color buffer */
3932 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3937 copytexsubimage_by_slice(struct gl_context
*ctx
,
3938 struct gl_texture_image
*texImage
,
3940 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3941 struct gl_renderbuffer
*rb
,
3943 GLsizei width
, GLsizei height
)
3945 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3948 /* For 1D arrays, we copy each scanline of the source rectangle into the
3951 assert(zoffset
== 0);
3953 for (slice
= 0; slice
< height
; slice
++) {
3954 assert(yoffset
+ slice
< texImage
->Height
);
3955 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3956 xoffset
, 0, yoffset
+ slice
,
3957 rb
, x
, y
+ slice
, width
, 1);
3960 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3961 xoffset
, yoffset
, zoffset
,
3962 rb
, x
, y
, width
, height
);
3967 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3969 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3970 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3971 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3972 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3974 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3975 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3976 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3977 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3979 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3980 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3981 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3982 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3989 * Implement the glCopyTexImage1/2D() functions.
3992 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3993 GLenum target
, GLint level
, GLenum internalFormat
,
3994 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3996 struct gl_texture_object
*texObj
;
3997 struct gl_texture_image
*texImage
;
3998 const GLuint face
= _mesa_tex_target_to_face(target
);
3999 mesa_format texFormat
;
4000 struct gl_renderbuffer
*rb
;
4002 FLUSH_VERTICES(ctx
, 0);
4004 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4005 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
4007 _mesa_enum_to_string(target
), level
,
4008 _mesa_enum_to_string(internalFormat
),
4009 x
, y
, width
, height
, border
);
4011 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4012 _mesa_update_state(ctx
);
4014 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
4015 width
, height
, border
))
4018 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
4020 _mesa_error(ctx
, GL_INVALID_VALUE
,
4021 "glCopyTexImage%uD(invalid width or height)", dims
);
4025 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4028 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
4029 internalFormat
, GL_NONE
, GL_NONE
);
4031 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
4033 if (_mesa_is_gles3(ctx
)) {
4034 if (_mesa_is_enum_format_unsized(internalFormat
)) {
4035 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
4036 * OpenGL ES 3.0. Khronos bug# 9807.
4038 if (rb
->InternalFormat
== GL_RGB10_A2
) {
4039 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4040 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
4041 " and writing to unsized internal format)", dims
);
4045 /* From Page 139 of OpenGL ES 3.0 spec:
4046 * "If internalformat is sized, the internal format of the new texel
4047 * array is internalformat, and this is also the new texel array’s
4048 * effective internal format. If the component sizes of internalformat
4049 * do not exactly match the corresponding component sizes of the source
4050 * buffer’s effective internal format, described below, an
4051 * INVALID_OPERATION error is generated. If internalformat is unsized,
4052 * the internal format of the new texel array is the effective internal
4053 * format of the source buffer, and this is also the new texel array’s
4054 * effective internal format.
4056 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
4057 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4058 "glCopyTexImage%uD(componenet size changed in"
4059 " internal format)", dims
);
4064 assert(texFormat
!= MESA_FORMAT_NONE
);
4066 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
4068 width
, height
, 1, border
)) {
4069 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4070 "glCopyTexImage%uD(image too large)", dims
);
4074 if (border
&& ctx
->Const
.StripTextureBorder
) {
4076 width
-= border
* 2;
4079 height
-= border
* 2;
4084 _mesa_lock_texture(ctx
, texObj
);
4086 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
4089 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
4092 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
4094 /* Free old texture image */
4095 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4097 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
4098 border
, internalFormat
, texFormat
);
4100 if (width
&& height
) {
4101 /* Allocate texture memory (no pixel data yet) */
4102 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
4104 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
4106 struct gl_renderbuffer
*srcRb
=
4107 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4109 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4111 srcRb
, srcX
, srcY
, width
, height
);
4114 check_gen_mipmap(ctx
, target
, texObj
, level
);
4117 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4119 _mesa_dirty_texobj(ctx
, texObj
);
4122 _mesa_unlock_texture(ctx
, texObj
);
4128 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4129 GLenum internalFormat
,
4131 GLsizei width
, GLint border
)
4133 GET_CURRENT_CONTEXT(ctx
);
4134 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4140 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4141 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4144 GET_CURRENT_CONTEXT(ctx
);
4145 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4146 x
, y
, width
, height
, border
);
4150 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4153 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4154 struct gl_texture_object
*texObj
,
4155 GLenum target
, GLint level
,
4156 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4158 GLsizei width
, GLsizei height
,
4161 struct gl_texture_image
*texImage
;
4163 FLUSH_VERTICES(ctx
, 0);
4165 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4166 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
4167 _mesa_enum_to_string(target
),
4168 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4170 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4171 _mesa_update_state(ctx
);
4173 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4174 xoffset
, yoffset
, zoffset
,
4175 width
, height
, caller
)) {
4179 _mesa_lock_texture(ctx
, texObj
);
4181 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4183 /* If we have a border, offset=-1 is legal. Bias by border width. */
4186 if (target
!= GL_TEXTURE_2D_ARRAY
)
4187 zoffset
+= texImage
->Border
;
4190 if (target
!= GL_TEXTURE_1D_ARRAY
)
4191 yoffset
+= texImage
->Border
;
4194 xoffset
+= texImage
->Border
;
4197 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4199 struct gl_renderbuffer
*srcRb
=
4200 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4202 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4203 xoffset
, yoffset
, zoffset
,
4204 srcRb
, x
, y
, width
, height
);
4206 check_gen_mipmap(ctx
, target
, texObj
, level
);
4208 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4209 * the texel data, not the texture format, size, etc.
4213 _mesa_unlock_texture(ctx
, texObj
);
4217 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4218 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4220 struct gl_texture_object
* texObj
;
4221 const char *self
= "glCopyTexSubImage1D";
4222 GET_CURRENT_CONTEXT(ctx
);
4224 /* Check target (proxies not allowed). Target must be checked prior to
4225 * calling _mesa_get_current_tex_object.
4227 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4228 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4229 _mesa_enum_to_string(target
));
4233 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4237 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4238 x
, y
, width
, 1, self
);
4244 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4245 GLint xoffset
, GLint yoffset
,
4246 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4248 struct gl_texture_object
* texObj
;
4249 const char *self
= "glCopyTexSubImage2D";
4250 GET_CURRENT_CONTEXT(ctx
);
4252 /* Check target (proxies not allowed). Target must be checked prior to
4253 * calling _mesa_get_current_tex_object.
4255 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4256 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4257 _mesa_enum_to_string(target
));
4261 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4265 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4266 xoffset
, yoffset
, 0,
4267 x
, y
, width
, height
, self
);
4273 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4274 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4275 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4277 struct gl_texture_object
* texObj
;
4278 const char *self
= "glCopyTexSubImage3D";
4279 GET_CURRENT_CONTEXT(ctx
);
4281 /* Check target (proxies not allowed). Target must be checked prior to
4282 * calling _mesa_get_current_tex_object.
4284 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4285 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4286 _mesa_enum_to_string(target
));
4290 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4294 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4295 xoffset
, yoffset
, zoffset
,
4296 x
, y
, width
, height
, self
);
4300 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4301 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4303 struct gl_texture_object
* texObj
;
4304 const char *self
= "glCopyTextureSubImage1D";
4305 GET_CURRENT_CONTEXT(ctx
);
4307 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4311 /* Check target (proxies not allowed). */
4312 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4313 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4314 _mesa_enum_to_string(texObj
->Target
));
4318 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4319 xoffset
, 0, 0, x
, y
, width
, 1, self
);
4323 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4324 GLint xoffset
, GLint yoffset
,
4325 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4327 struct gl_texture_object
* texObj
;
4328 const char *self
= "glCopyTextureSubImage2D";
4329 GET_CURRENT_CONTEXT(ctx
);
4331 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4335 /* Check target (proxies not allowed). */
4336 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4337 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4338 _mesa_enum_to_string(texObj
->Target
));
4342 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4343 xoffset
, yoffset
, 0,
4344 x
, y
, width
, height
, self
);
4350 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4351 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4352 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4354 struct gl_texture_object
* texObj
;
4355 const char *self
= "glCopyTextureSubImage3D";
4356 GET_CURRENT_CONTEXT(ctx
);
4358 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4362 /* Check target (proxies not allowed). */
4363 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4364 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4365 _mesa_enum_to_string(texObj
->Target
));
4369 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4370 /* Act like CopyTexSubImage2D */
4371 _mesa_copy_texture_sub_image(ctx
, 2, texObj
,
4372 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4373 level
, xoffset
, yoffset
, 0,
4374 x
, y
, width
, height
, self
);
4377 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4378 xoffset
, yoffset
, zoffset
,
4379 x
, y
, width
, height
, self
);
4383 check_clear_tex_image(struct gl_context
*ctx
,
4384 const char *function
,
4385 struct gl_texture_image
*texImage
,
4386 GLenum format
, GLenum type
,
4388 GLubyte
*clearValue
)
4390 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4391 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4392 GLenum internalFormat
= texImage
->InternalFormat
;
4395 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4396 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4397 "%s(buffer texture)", function
);
4401 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4402 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4403 "%s(compressed texture)", function
);
4407 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4408 if (err
!= GL_NO_ERROR
) {
4409 _mesa_error(ctx
, err
,
4410 "%s(incompatible format = %s, type = %s)",
4412 _mesa_enum_to_string(format
),
4413 _mesa_enum_to_string(type
));
4417 /* make sure internal format and format basically agree */
4418 if (!texture_formats_agree(internalFormat
, format
)) {
4419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4420 "%s(incompatible internalFormat = %s, format = %s)",
4422 _mesa_enum_to_string(internalFormat
),
4423 _mesa_enum_to_string(format
));
4427 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4428 /* both source and dest must be integer-valued, or neither */
4429 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4430 _mesa_is_enum_format_integer(format
)) {
4431 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4432 "%s(integer/non-integer format mismatch)",
4438 if (!_mesa_texstore(ctx
,
4440 texImage
->_BaseFormat
,
4441 texImage
->TexFormat
,
4442 0, /* dstRowStride */
4444 1, 1, 1, /* srcWidth/Height/Depth */
4446 data
? data
: zeroData
,
4447 &ctx
->DefaultPacking
)) {
4448 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4455 static struct gl_texture_object
*
4456 get_tex_obj_for_clear(struct gl_context
*ctx
,
4457 const char *function
,
4460 struct gl_texture_object
*texObj
;
4463 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4467 texObj
= _mesa_lookup_texture(ctx
, texture
);
4469 if (texObj
== NULL
) {
4470 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4474 if (texObj
->Target
== 0) {
4475 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4483 get_tex_images_for_clear(struct gl_context
*ctx
,
4484 const char *function
,
4485 struct gl_texture_object
*texObj
,
4487 struct gl_texture_image
**texImages
)
4492 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4493 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4497 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4498 for (i
= 0; i
< MAX_FACES
; i
++) {
4499 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4501 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4502 if (texImages
[i
] == NULL
) {
4503 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4504 "%s(invalid level)", function
);
4512 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4514 if (texImages
[0] == NULL
) {
4515 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4523 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4524 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4525 GLsizei width
, GLsizei height
, GLsizei depth
,
4526 GLenum format
, GLenum type
, const void *data
)
4528 GET_CURRENT_CONTEXT(ctx
);
4529 struct gl_texture_object
*texObj
;
4530 struct gl_texture_image
*texImages
[MAX_FACES
];
4531 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4533 int minDepth
, maxDepth
;
4535 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4540 _mesa_lock_texture(ctx
, texObj
);
4542 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4543 texObj
, level
, texImages
);
4547 if (numImages
== 1) {
4548 minDepth
= -(int) texImages
[0]->Border
;
4549 maxDepth
= texImages
[0]->Depth
;
4552 maxDepth
= numImages
;
4555 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4556 yoffset
< -(GLint
) texImages
[0]->Border
||
4557 zoffset
< minDepth
||
4561 xoffset
+ width
> texImages
[0]->Width
||
4562 yoffset
+ height
> texImages
[0]->Height
||
4563 zoffset
+ depth
> maxDepth
) {
4564 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4565 "glClearSubTexImage(invalid dimensions)");
4569 if (numImages
== 1) {
4570 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4572 format
, type
, data
, clearValue
[0])) {
4573 ctx
->Driver
.ClearTexSubImage(ctx
,
4575 xoffset
, yoffset
, zoffset
,
4576 width
, height
, depth
,
4577 data
? clearValue
[0] : NULL
);
4580 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4581 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4583 format
, type
, data
, clearValue
[i
]))
4586 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4587 ctx
->Driver
.ClearTexSubImage(ctx
,
4589 xoffset
, yoffset
, 0,
4591 data
? clearValue
[i
] : NULL
);
4596 _mesa_unlock_texture(ctx
, texObj
);
4600 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4601 GLenum format
, GLenum type
, const void *data
)
4603 GET_CURRENT_CONTEXT(ctx
);
4604 struct gl_texture_object
*texObj
;
4605 struct gl_texture_image
*texImages
[MAX_FACES
];
4606 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4609 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4614 _mesa_lock_texture(ctx
, texObj
);
4616 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4617 texObj
, level
, texImages
);
4619 for (i
= 0; i
< numImages
; i
++) {
4620 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4627 for (i
= 0; i
< numImages
; i
++) {
4628 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4629 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4630 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4631 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4632 texImages
[i
]->Width
,
4633 texImages
[i
]->Height
,
4634 texImages
[i
]->Depth
,
4635 data
? clearValue
[i
] : NULL
);
4639 _mesa_unlock_texture(ctx
, texObj
);
4645 /**********************************************************************/
4646 /****** Compressed Textures ******/
4647 /**********************************************************************/
4651 * Target checking for glCompressedTexSubImage[123]D().
4652 * \return GL_TRUE if error, GL_FALSE if no error
4653 * Must come before other error checking so that the texture object can
4654 * be correctly retrieved using _mesa_get_current_tex_object.
4657 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4658 GLint dims
, GLenum format
, bool dsa
,
4663 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4664 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4665 _mesa_enum_to_string(target
));
4675 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4676 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4677 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4678 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4679 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4680 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4681 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4684 targetOK
= GL_FALSE
;
4690 case GL_TEXTURE_CUBE_MAP
:
4691 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4693 case GL_TEXTURE_2D_ARRAY
:
4694 targetOK
= _mesa_is_gles3(ctx
) ||
4695 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4697 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4698 targetOK
= ctx
->Extensions
.ARB_texture_cube_map_array
;
4703 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4705 * "An INVALID_OPERATION error is generated by
4706 * CompressedTex*SubImage3D if the internal format of the texture
4707 * is one of the EAC, ETC2, or RGTC formats and either border is
4708 * non-zero, or the effective target for the texture is not
4709 * TEXTURE_2D_ARRAY."
4711 * NOTE: that's probably a spec error. It should probably say
4712 * "... or the effective target for the texture is not
4713 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4714 * GL_TEXTURE_CUBE_MAP_ARRAY."
4715 * since those targets are 2D images and they support all compression
4718 * Instead of listing all these, just list those which are allowed,
4719 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4720 * more) are valid here, which they are not, but of course not
4721 * mentioned by core spec.
4724 /* These are the only 3D compression formats supported at this time */
4725 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
4726 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
4727 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
4728 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
4732 /* invalid format */
4733 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4734 "%s(invalid target %s for format %s)", caller
,
4735 _mesa_enum_to_string(target
),
4736 _mesa_enum_to_string(format
));
4741 targetOK
= GL_FALSE
;
4747 /* no 1D compressed textures at this time */
4748 targetOK
= GL_FALSE
;
4753 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4754 _mesa_enum_to_string(target
));
4762 * Error checking for glCompressedTexSubImage[123]D().
4763 * \return GL_TRUE if error, GL_FALSE if no error
4766 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4767 const struct gl_texture_object
*texObj
,
4768 GLenum target
, GLint level
,
4769 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4770 GLsizei width
, GLsizei height
, GLsizei depth
,
4771 GLenum format
, GLsizei imageSize
,
4772 const GLvoid
*data
, const char *callerName
)
4774 struct gl_texture_image
*texImage
;
4777 /* this will catch any invalid compressed format token */
4778 if (!_mesa_is_compressed_format(ctx
, format
)) {
4779 _mesa_error(ctx
, GL_INVALID_ENUM
,
4780 "%s(format)", callerName
);
4784 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4785 _mesa_error(ctx
, GL_INVALID_VALUE
,
4791 /* validate the bound PBO, if any */
4792 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4793 imageSize
, data
, callerName
)) {
4797 /* Check for invalid pixel storage modes */
4798 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4799 &ctx
->Unpack
, callerName
)) {
4803 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4804 if (expectedSize
!= imageSize
) {
4805 _mesa_error(ctx
, GL_INVALID_VALUE
,
4807 callerName
, imageSize
);
4811 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4813 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4814 "%s(invalid texture image)",
4819 if ((GLint
) format
!= texImage
->InternalFormat
) {
4820 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4822 callerName
, format
);
4826 if (compressedteximage_only_format(ctx
, format
)) {
4827 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4828 "%s(format=0x%x cannot be updated)",
4829 callerName
, format
);
4833 if (error_check_subtexture_dimensions(ctx
, dims
,
4834 texImage
, xoffset
, yoffset
, zoffset
,
4835 width
, height
, depth
,
4845 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4846 GLenum internalFormat
, GLsizei width
,
4847 GLint border
, GLsizei imageSize
,
4850 GET_CURRENT_CONTEXT(ctx
);
4851 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4852 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4857 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4858 GLenum internalFormat
, GLsizei width
,
4859 GLsizei height
, GLint border
, GLsizei imageSize
,
4862 GET_CURRENT_CONTEXT(ctx
);
4863 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4864 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4869 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4870 GLenum internalFormat
, GLsizei width
,
4871 GLsizei height
, GLsizei depth
, GLint border
,
4872 GLsizei imageSize
, const GLvoid
*data
)
4874 GET_CURRENT_CONTEXT(ctx
);
4875 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4876 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4881 * Common helper for glCompressedTexSubImage1/2/3D() and
4882 * glCompressedTextureSubImage1/2/3D().
4885 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4886 struct gl_texture_object
*texObj
,
4887 struct gl_texture_image
*texImage
,
4888 GLenum target
, GLint level
,
4889 GLint xoffset
, GLint yoffset
,
4891 GLsizei width
, GLsizei height
,
4893 GLenum format
, GLsizei imageSize
,
4896 FLUSH_VERTICES(ctx
, 0);
4898 _mesa_lock_texture(ctx
, texObj
);
4900 if (width
> 0 && height
> 0 && depth
> 0) {
4901 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4902 xoffset
, yoffset
, zoffset
,
4903 width
, height
, depth
,
4904 format
, imageSize
, data
);
4906 check_gen_mipmap(ctx
, target
, texObj
, level
);
4908 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4909 * the texel data, not the texture format, size, etc.
4913 _mesa_unlock_texture(ctx
, texObj
);
4918 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4919 GLsizei width
, GLenum format
,
4920 GLsizei imageSize
, const GLvoid
*data
)
4922 struct gl_texture_object
*texObj
;
4923 struct gl_texture_image
*texImage
;
4925 GET_CURRENT_CONTEXT(ctx
);
4927 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4928 "glCompressedTexSubImage1D")) {
4932 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4936 if (compressed_subtexture_error_check(ctx
, 1, texObj
, target
,
4937 level
, xoffset
, 0, 0,
4939 format
, imageSize
, data
,
4940 "glCompressedTexSubImage1D")) {
4944 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4947 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
4948 xoffset
, 0, 0, width
, 1, 1,
4949 format
, imageSize
, data
);
4953 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4954 GLsizei width
, GLenum format
,
4955 GLsizei imageSize
, const GLvoid
*data
)
4957 struct gl_texture_object
*texObj
;
4958 struct gl_texture_image
*texImage
;
4960 GET_CURRENT_CONTEXT(ctx
);
4962 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4963 "glCompressedTextureSubImage1D");
4967 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
, true,
4968 "glCompressedTextureSubImage1D")) {
4972 if (compressed_subtexture_error_check(ctx
, 1, texObj
, texObj
->Target
,
4973 level
, xoffset
, 0, 0,
4975 format
, imageSize
, data
,
4976 "glCompressedTextureSubImage1D")) {
4980 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4983 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
,
4984 texObj
->Target
, level
,
4985 xoffset
, 0, 0, width
, 1, 1,
4986 format
, imageSize
, data
);
4991 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4992 GLint yoffset
, GLsizei width
, GLsizei height
,
4993 GLenum format
, GLsizei imageSize
,
4996 struct gl_texture_object
*texObj
;
4997 struct gl_texture_image
*texImage
;
4999 GET_CURRENT_CONTEXT(ctx
);
5001 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
5002 "glCompressedTexSubImage2D")) {
5006 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5010 if (compressed_subtexture_error_check(ctx
, 2, texObj
, target
,
5011 level
, xoffset
, yoffset
, 0,
5013 format
, imageSize
, data
,
5014 "glCompressedTexSubImage2D")) {
5019 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5022 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
5023 xoffset
, yoffset
, 0, width
, height
, 1,
5024 format
, imageSize
, data
);
5028 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
5030 GLsizei width
, GLsizei height
,
5031 GLenum format
, GLsizei imageSize
,
5034 struct gl_texture_object
*texObj
;
5035 struct gl_texture_image
*texImage
;
5037 GET_CURRENT_CONTEXT(ctx
);
5039 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5040 "glCompressedTextureSubImage2D");
5044 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
, true,
5045 "glCompressedTextureSubImage2D")) {
5049 if (compressed_subtexture_error_check(ctx
, 2, texObj
, texObj
->Target
,
5050 level
, xoffset
, yoffset
, 0,
5052 format
, imageSize
, data
,
5053 "glCompressedTextureSubImage2D")) {
5057 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5060 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
,
5061 texObj
->Target
, level
,
5062 xoffset
, yoffset
, 0, width
, height
, 1,
5063 format
, imageSize
, data
);
5067 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
5068 GLint yoffset
, GLint zoffset
, GLsizei width
,
5069 GLsizei height
, GLsizei depth
, GLenum format
,
5070 GLsizei imageSize
, const GLvoid
*data
)
5072 struct gl_texture_object
*texObj
;
5073 struct gl_texture_image
*texImage
;
5075 GET_CURRENT_CONTEXT(ctx
);
5077 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
5078 "glCompressedTexSubImage3D")) {
5082 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5086 if (compressed_subtexture_error_check(ctx
, 3, texObj
, target
,
5087 level
, xoffset
, yoffset
, zoffset
,
5088 width
, height
, depth
,
5089 format
, imageSize
, data
,
5090 "glCompressedTexSubImage3D")) {
5095 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5098 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
5099 xoffset
, yoffset
, zoffset
,
5100 width
, height
, depth
,
5101 format
, imageSize
, data
);
5105 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
5106 GLint yoffset
, GLint zoffset
, GLsizei width
,
5107 GLsizei height
, GLsizei depth
,
5108 GLenum format
, GLsizei imageSize
,
5111 struct gl_texture_object
*texObj
;
5112 struct gl_texture_image
*texImage
;
5114 GET_CURRENT_CONTEXT(ctx
);
5116 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5117 "glCompressedTextureSubImage3D");
5121 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
, true,
5122 "glCompressedTextureSubImage3D")) {
5126 if (compressed_subtexture_error_check(ctx
, 3, texObj
, texObj
->Target
,
5127 level
, xoffset
, yoffset
, zoffset
,
5128 width
, height
, depth
,
5129 format
, imageSize
, data
,
5130 "glCompressedTextureSubImage3D")) {
5134 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
5135 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5136 const char *pixels
= data
;
5140 /* Make sure the texture object is a proper cube.
5141 * (See texturesubimage in teximage.c for details on why this check is
5144 if (!_mesa_cube_level_complete(texObj
, level
)) {
5145 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5146 "glCompressedTextureSubImage3D(cube map incomplete)");
5150 /* Copy in each face. */
5151 for (i
= 0; i
< 6; ++i
) {
5152 texImage
= texObj
->Image
[i
][level
];
5155 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5156 texObj
->Target
, level
,
5157 xoffset
, yoffset
, zoffset
,
5159 format
, imageSize
, pixels
);
5161 /* Compressed images don't have a client format */
5162 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5164 texImage
->Height
, 1);
5166 pixels
+= image_stride
;
5167 imageSize
-= image_stride
;
5171 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5174 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5175 texObj
->Target
, level
,
5176 xoffset
, yoffset
, zoffset
,
5177 width
, height
, depth
,
5178 format
, imageSize
, data
);
5183 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5185 if (ctx
->API
!= API_OPENGL_CORE
) {
5186 switch (internalFormat
) {
5188 return MESA_FORMAT_A_UNORM8
;
5190 return MESA_FORMAT_A_UNORM16
;
5191 case GL_ALPHA16F_ARB
:
5192 return MESA_FORMAT_A_FLOAT16
;
5193 case GL_ALPHA32F_ARB
:
5194 return MESA_FORMAT_A_FLOAT32
;
5195 case GL_ALPHA8I_EXT
:
5196 return MESA_FORMAT_A_SINT8
;
5197 case GL_ALPHA16I_EXT
:
5198 return MESA_FORMAT_A_SINT16
;
5199 case GL_ALPHA32I_EXT
:
5200 return MESA_FORMAT_A_SINT32
;
5201 case GL_ALPHA8UI_EXT
:
5202 return MESA_FORMAT_A_UINT8
;
5203 case GL_ALPHA16UI_EXT
:
5204 return MESA_FORMAT_A_UINT16
;
5205 case GL_ALPHA32UI_EXT
:
5206 return MESA_FORMAT_A_UINT32
;
5208 return MESA_FORMAT_L_UNORM8
;
5209 case GL_LUMINANCE16
:
5210 return MESA_FORMAT_L_UNORM16
;
5211 case GL_LUMINANCE16F_ARB
:
5212 return MESA_FORMAT_L_FLOAT16
;
5213 case GL_LUMINANCE32F_ARB
:
5214 return MESA_FORMAT_L_FLOAT32
;
5215 case GL_LUMINANCE8I_EXT
:
5216 return MESA_FORMAT_L_SINT8
;
5217 case GL_LUMINANCE16I_EXT
:
5218 return MESA_FORMAT_L_SINT16
;
5219 case GL_LUMINANCE32I_EXT
:
5220 return MESA_FORMAT_L_SINT32
;
5221 case GL_LUMINANCE8UI_EXT
:
5222 return MESA_FORMAT_L_UINT8
;
5223 case GL_LUMINANCE16UI_EXT
:
5224 return MESA_FORMAT_L_UINT16
;
5225 case GL_LUMINANCE32UI_EXT
:
5226 return MESA_FORMAT_L_UINT32
;
5227 case GL_LUMINANCE8_ALPHA8
:
5228 return MESA_FORMAT_L8A8_UNORM
;
5229 case GL_LUMINANCE16_ALPHA16
:
5230 return MESA_FORMAT_L16A16_UNORM
;
5231 case GL_LUMINANCE_ALPHA16F_ARB
:
5232 return MESA_FORMAT_LA_FLOAT16
;
5233 case GL_LUMINANCE_ALPHA32F_ARB
:
5234 return MESA_FORMAT_LA_FLOAT32
;
5235 case GL_LUMINANCE_ALPHA8I_EXT
:
5236 return MESA_FORMAT_LA_SINT8
;
5237 case GL_LUMINANCE_ALPHA16I_EXT
:
5238 return MESA_FORMAT_LA_SINT16
;
5239 case GL_LUMINANCE_ALPHA32I_EXT
:
5240 return MESA_FORMAT_LA_SINT32
;
5241 case GL_LUMINANCE_ALPHA8UI_EXT
:
5242 return MESA_FORMAT_LA_UINT8
;
5243 case GL_LUMINANCE_ALPHA16UI_EXT
:
5244 return MESA_FORMAT_LA_UINT16
;
5245 case GL_LUMINANCE_ALPHA32UI_EXT
:
5246 return MESA_FORMAT_LA_UINT32
;
5248 return MESA_FORMAT_I_UNORM8
;
5249 case GL_INTENSITY16
:
5250 return MESA_FORMAT_I_UNORM16
;
5251 case GL_INTENSITY16F_ARB
:
5252 return MESA_FORMAT_I_FLOAT16
;
5253 case GL_INTENSITY32F_ARB
:
5254 return MESA_FORMAT_I_FLOAT32
;
5255 case GL_INTENSITY8I_EXT
:
5256 return MESA_FORMAT_I_SINT8
;
5257 case GL_INTENSITY16I_EXT
:
5258 return MESA_FORMAT_I_SINT16
;
5259 case GL_INTENSITY32I_EXT
:
5260 return MESA_FORMAT_I_SINT32
;
5261 case GL_INTENSITY8UI_EXT
:
5262 return MESA_FORMAT_I_UINT8
;
5263 case GL_INTENSITY16UI_EXT
:
5264 return MESA_FORMAT_I_UINT16
;
5265 case GL_INTENSITY32UI_EXT
:
5266 return MESA_FORMAT_I_UINT32
;
5272 if (ctx
->API
== API_OPENGL_CORE
&&
5273 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5274 switch (internalFormat
) {
5276 return MESA_FORMAT_RGB_FLOAT32
;
5278 return MESA_FORMAT_RGB_UINT32
;
5280 return MESA_FORMAT_RGB_SINT32
;
5286 switch (internalFormat
) {
5288 return MESA_FORMAT_R8G8B8A8_UNORM
;
5290 return MESA_FORMAT_RGBA_UNORM16
;
5291 case GL_RGBA16F_ARB
:
5292 return MESA_FORMAT_RGBA_FLOAT16
;
5293 case GL_RGBA32F_ARB
:
5294 return MESA_FORMAT_RGBA_FLOAT32
;
5296 return MESA_FORMAT_RGBA_SINT8
;
5297 case GL_RGBA16I_EXT
:
5298 return MESA_FORMAT_RGBA_SINT16
;
5299 case GL_RGBA32I_EXT
:
5300 return MESA_FORMAT_RGBA_SINT32
;
5301 case GL_RGBA8UI_EXT
:
5302 return MESA_FORMAT_RGBA_UINT8
;
5303 case GL_RGBA16UI_EXT
:
5304 return MESA_FORMAT_RGBA_UINT16
;
5305 case GL_RGBA32UI_EXT
:
5306 return MESA_FORMAT_RGBA_UINT32
;
5309 return MESA_FORMAT_R8G8_UNORM
;
5311 return MESA_FORMAT_R16G16_UNORM
;
5313 return MESA_FORMAT_RG_FLOAT16
;
5315 return MESA_FORMAT_RG_FLOAT32
;
5317 return MESA_FORMAT_RG_SINT8
;
5319 return MESA_FORMAT_RG_SINT16
;
5321 return MESA_FORMAT_RG_SINT32
;
5323 return MESA_FORMAT_RG_UINT8
;
5325 return MESA_FORMAT_RG_UINT16
;
5327 return MESA_FORMAT_RG_UINT32
;
5330 return MESA_FORMAT_R_UNORM8
;
5332 return MESA_FORMAT_R_UNORM16
;
5334 return MESA_FORMAT_R_FLOAT16
;
5336 return MESA_FORMAT_R_FLOAT32
;
5338 return MESA_FORMAT_R_SINT8
;
5340 return MESA_FORMAT_R_SINT16
;
5342 return MESA_FORMAT_R_SINT32
;
5344 return MESA_FORMAT_R_UINT8
;
5346 return MESA_FORMAT_R_UINT16
;
5348 return MESA_FORMAT_R_UINT32
;
5351 return MESA_FORMAT_NONE
;
5357 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5358 GLenum internalFormat
)
5360 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5363 if (format
== MESA_FORMAT_NONE
)
5364 return MESA_FORMAT_NONE
;
5366 datatype
= _mesa_get_format_datatype(format
);
5368 /* The GL_ARB_texture_buffer_object spec says:
5370 * "If ARB_texture_float is not supported, references to the
5371 * floating-point internal formats provided by that extension should be
5372 * removed, and such formats may not be passed to TexBufferARB."
5374 * As a result, GL_HALF_FLOAT internal format depends on both
5375 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5377 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5378 !ctx
->Extensions
.ARB_texture_float
)
5379 return MESA_FORMAT_NONE
;
5381 if (!ctx
->Extensions
.ARB_texture_rg
) {
5382 GLenum base_format
= _mesa_get_format_base_format(format
);
5383 if (base_format
== GL_R
|| base_format
== GL_RG
)
5384 return MESA_FORMAT_NONE
;
5387 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5388 GLenum base_format
= _mesa_get_format_base_format(format
);
5389 if (base_format
== GL_RGB
)
5390 return MESA_FORMAT_NONE
;
5397 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5398 struct gl_texture_object
*texObj
,
5399 GLenum internalFormat
,
5400 struct gl_buffer_object
*bufObj
,
5401 GLintptr offset
, GLsizeiptr size
,
5406 /* NOTE: ARB_texture_buffer_object has interactions with
5407 * the compatibility profile that are not implemented.
5409 if (!(ctx
->API
== API_OPENGL_CORE
&&
5410 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5411 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5412 "%s(ARB_texture_buffer_object is not"
5413 " implemented for the compatibility profile)", caller
);
5417 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5418 if (format
== MESA_FORMAT_NONE
) {
5419 _mesa_error(ctx
, GL_INVALID_ENUM
,
5420 "%s(internalFormat 0x%x)", caller
, internalFormat
);
5424 FLUSH_VERTICES(ctx
, 0);
5426 _mesa_lock_texture(ctx
, texObj
);
5428 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5429 texObj
->BufferObjectFormat
= internalFormat
;
5430 texObj
->_BufferObjectFormat
= format
;
5431 texObj
->BufferOffset
= offset
;
5432 texObj
->BufferSize
= size
;
5434 _mesa_unlock_texture(ctx
, texObj
);
5436 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5439 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5445 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5446 * Return true if it is, and return false if it is not
5447 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5448 * core spec, 02.02.2015, PDF page 245).
5451 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5454 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5455 _mesa_error(ctx
, GL_INVALID_ENUM
,
5456 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5464 * Check for errors related to the texture buffer range.
5465 * Return false if errors are found, true if none are found.
5468 check_texture_buffer_range(struct gl_context
*ctx
,
5469 struct gl_buffer_object
*bufObj
,
5470 GLintptr offset
, GLsizeiptr size
,
5473 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5474 * Textures (PDF page 245):
5475 * "An INVALID_VALUE error is generated if offset is negative, if
5476 * size is less than or equal to zero, or if offset + size is greater
5477 * than the value of BUFFER_SIZE for the buffer bound to target."
5480 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5486 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5491 if (offset
+ size
> bufObj
->Size
) {
5492 _mesa_error(ctx
, GL_INVALID_VALUE
,
5493 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5494 (int) offset
, (int) size
, (int) bufObj
->Size
);
5498 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5499 * Textures (PDF page 245):
5500 * "An INVALID_VALUE error is generated if offset is not an integer
5501 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5503 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5504 _mesa_error(ctx
, GL_INVALID_VALUE
,
5505 "%s(invalid offset alignment)", caller
);
5513 /** GL_ARB_texture_buffer_object */
5515 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5517 struct gl_texture_object
*texObj
;
5518 struct gl_buffer_object
*bufObj
;
5520 GET_CURRENT_CONTEXT(ctx
);
5522 /* Need to catch a bad target before it gets to
5523 * _mesa_get_current_tex_object.
5525 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5529 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5535 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5539 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5540 buffer
? -1 : 0, "glTexBuffer");
5544 /** GL_ARB_texture_buffer_range */
5546 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5547 GLintptr offset
, GLsizeiptr size
)
5549 struct gl_texture_object
*texObj
;
5550 struct gl_buffer_object
*bufObj
;
5552 GET_CURRENT_CONTEXT(ctx
);
5554 /* Need to catch a bad target before it gets to
5555 * _mesa_get_current_tex_object.
5557 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5561 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5565 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5566 "glTexBufferRange"))
5570 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5571 * Textures (PDF page 254):
5572 * "If buffer is zero, then any buffer object attached to the buffer
5573 * texture is detached, the values offset and size are ignored and
5574 * the state for offset and size for the buffer texture are reset to
5582 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5586 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5587 offset
, size
, "glTexBufferRange");
5591 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5593 struct gl_texture_object
*texObj
;
5594 struct gl_buffer_object
*bufObj
;
5596 GET_CURRENT_CONTEXT(ctx
);
5599 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5605 /* Get the texture object by Name. */
5606 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5610 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5613 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5614 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5618 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5619 GLintptr offset
, GLsizeiptr size
)
5621 struct gl_texture_object
*texObj
;
5622 struct gl_buffer_object
*bufObj
;
5624 GET_CURRENT_CONTEXT(ctx
);
5627 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5628 "glTextureBufferRange");
5632 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5633 "glTextureBufferRange"))
5637 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5638 * Textures (PDF page 254):
5639 * "If buffer is zero, then any buffer object attached to the buffer
5640 * texture is detached, the values offset and size are ignored and
5641 * the state for offset and size for the buffer texture are reset to
5649 /* Get the texture object by Name. */
5650 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5654 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5655 "glTextureBufferRange"))
5658 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5659 bufObj
, offset
, size
, "glTextureBufferRange");
5663 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5665 /* Everything that is allowed for renderbuffers,
5666 * except for a base format of GL_STENCIL_INDEX, unless supported.
5668 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5669 if (ctx
->Extensions
.ARB_texture_stencil8
)
5670 return baseFormat
!= 0;
5672 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5676 /** GL_ARB_texture_multisample */
5678 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5681 case GL_TEXTURE_2D_MULTISAMPLE
:
5683 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5684 return dims
== 2 && !dsa
;
5685 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5687 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5688 return dims
== 3 && !dsa
;
5696 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5697 struct gl_texture_object
*texObj
,
5698 GLenum target
, GLsizei samples
,
5699 GLint internalformat
, GLsizei width
,
5700 GLsizei height
, GLsizei depth
,
5701 GLboolean fixedsamplelocations
,
5702 GLboolean immutable
, const char *func
)
5704 struct gl_texture_image
*texImage
;
5705 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5706 mesa_format texFormat
;
5707 GLenum sample_count_error
;
5708 bool dsa
= strstr(func
, "ture") ? true : false;
5710 if (!((ctx
->Extensions
.ARB_texture_multisample
5711 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5712 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5717 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5721 if (!check_multisample_target(dims
, target
, dsa
)) {
5723 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5727 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5732 /* check that the specified internalformat is color/depth/stencil-renderable;
5733 * refer GL3.1 spec 4.4.4
5736 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5737 _mesa_error(ctx
, GL_INVALID_ENUM
,
5738 "%s(internalformat=%s not legal for immutable-format)",
5739 func
, _mesa_enum_to_string(internalformat
));
5743 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5744 /* Page 172 of OpenGL ES 3.1 spec says:
5745 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5746 * color-renderable, depth-renderable, or stencil-renderable (as
5747 * defined in section 9.4).
5749 * (Same error is also defined for desktop OpenGL for multisample
5750 * teximage/texstorage functions.)
5752 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5753 _mesa_enum_to_string(internalformat
));
5757 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5758 internalformat
, samples
);
5759 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5761 /* Page 254 of OpenGL 4.4 spec says:
5762 * "Proxy arrays for two-dimensional multisample and two-dimensional
5763 * multisample array textures are operated on in the same way when
5764 * TexImage2DMultisample is called with target specified as
5765 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5766 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5767 * However, if samples is not supported, then no error is generated.
5769 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5770 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5774 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5775 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5776 "%s(texture object 0)",
5781 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5783 if (texImage
== NULL
) {
5784 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5788 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5789 internalformat
, GL_NONE
, GL_NONE
);
5790 assert(texFormat
!= MESA_FORMAT_NONE
);
5792 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5793 width
, height
, depth
, 0);
5795 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5796 width
, height
, depth
, 0);
5798 if (_mesa_is_proxy_texture(target
)) {
5799 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5800 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5801 internalformat
, texFormat
,
5802 samples
, fixedsamplelocations
);
5805 /* clear all image fields */
5806 clear_teximage_fields(texImage
);
5810 if (!dimensionsOK
) {
5811 _mesa_error(ctx
, GL_INVALID_VALUE
,
5812 "%s(invalid width or height)", func
);
5817 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5821 /* Check if texObj->Immutable is set */
5822 if (texObj
->Immutable
) {
5823 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5827 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5829 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5830 internalformat
, texFormat
,
5831 samples
, fixedsamplelocations
);
5833 if (width
> 0 && height
> 0 && depth
> 0) {
5834 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5835 width
, height
, depth
)) {
5836 /* tidy up the texture image state. strictly speaking,
5837 * we're allowed to just leave this in whatever state we
5838 * like, but being tidy is good.
5840 _mesa_init_teximage_fields(ctx
, texImage
,
5841 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5845 texObj
->Immutable
|= immutable
;
5848 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5851 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5857 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5858 GLenum internalformat
, GLsizei width
,
5859 GLsizei height
, GLboolean fixedsamplelocations
)
5861 struct gl_texture_object
*texObj
;
5862 GET_CURRENT_CONTEXT(ctx
);
5864 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5868 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5869 internalformat
, width
, height
, 1,
5870 fixedsamplelocations
, GL_FALSE
,
5871 "glTexImage2DMultisample");
5876 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5877 GLenum internalformat
, GLsizei width
,
5878 GLsizei height
, GLsizei depth
,
5879 GLboolean fixedsamplelocations
)
5881 struct gl_texture_object
*texObj
;
5882 GET_CURRENT_CONTEXT(ctx
);
5884 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5888 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5889 internalformat
, width
, height
, depth
,
5890 fixedsamplelocations
, GL_FALSE
,
5891 "glTexImage3DMultisample");
5895 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
5896 GLsizei samples
, unsigned dims
)
5898 GET_CURRENT_CONTEXT(ctx
);
5900 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
5901 _mesa_error(ctx
, GL_INVALID_VALUE
,
5902 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
5903 dims
, width
, height
, depth
);
5910 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5911 GLenum internalformat
, GLsizei width
,
5912 GLsizei height
, GLboolean fixedsamplelocations
)
5914 struct gl_texture_object
*texObj
;
5915 GET_CURRENT_CONTEXT(ctx
);
5917 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5921 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5924 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5925 internalformat
, width
, height
, 1,
5926 fixedsamplelocations
, GL_TRUE
,
5927 "glTexStorage2DMultisample");
5931 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5932 GLenum internalformat
, GLsizei width
,
5933 GLsizei height
, GLsizei depth
,
5934 GLboolean fixedsamplelocations
)
5936 struct gl_texture_object
*texObj
;
5937 GET_CURRENT_CONTEXT(ctx
);
5939 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5943 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5946 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5947 internalformat
, width
, height
, depth
,
5948 fixedsamplelocations
, GL_TRUE
,
5949 "glTexStorage3DMultisample");
5953 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5954 GLenum internalformat
, GLsizei width
,
5956 GLboolean fixedsamplelocations
)
5958 struct gl_texture_object
*texObj
;
5959 GET_CURRENT_CONTEXT(ctx
);
5961 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5962 "glTextureStorage2DMultisample");
5966 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5969 texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5970 internalformat
, width
, height
, 1,
5971 fixedsamplelocations
, GL_TRUE
,
5972 "glTextureStorage2DMultisample");
5976 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5977 GLenum internalformat
, GLsizei width
,
5978 GLsizei height
, GLsizei depth
,
5979 GLboolean fixedsamplelocations
)
5981 struct gl_texture_object
*texObj
;
5982 GET_CURRENT_CONTEXT(ctx
);
5984 /* Get the texture object by Name. */
5985 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5986 "glTextureStorage3DMultisample");
5990 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5993 texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5994 internalformat
, width
, height
, depth
,
5995 fixedsamplelocations
, GL_TRUE
,
5996 "glTextureStorage3DMultisample");