2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
43 #include "multisample.h"
44 #include "pixelstore.h"
46 #include "texcompress.h"
47 #include "texcompress_cpal.h"
51 #include "texstorage.h"
52 #include "textureview.h"
54 #include "glformats.h"
60 * State changes which we care about for glCopyTex[Sub]Image() calls.
61 * In particular, we care about pixel transfer state and buffer state
62 * (such as glReadBuffer to make sure we read from the right renderbuffer).
64 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
67 * Returns a corresponding internal floating point format for a given base
68 * format as specifed by OES_texture_float. In case of GL_FLOAT, the internal
69 * format needs to be a 32 bit component and in case of GL_HALF_FLOAT_OES it
70 * needs to be a 16 bit component.
72 * For example, given base format GL_RGBA, type GL_Float return GL_RGBA32F_ARB.
75 adjust_for_oes_float_texture(GLenum format
, GLenum type
)
85 return GL_ALPHA32F_ARB
;
87 return GL_LUMINANCE32F_ARB
;
88 case GL_LUMINANCE_ALPHA
:
89 return GL_LUMINANCE_ALPHA32F_ARB
;
95 case GL_HALF_FLOAT_OES
:
102 return GL_ALPHA16F_ARB
;
104 return GL_LUMINANCE16F_ARB
;
105 case GL_LUMINANCE_ALPHA
:
106 return GL_LUMINANCE_ALPHA16F_ARB
;
120 * Return the simple base format for a given internal texture format.
121 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
123 * \param ctx GL context.
124 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
126 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
127 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
129 * This is the format which is used during texture application (i.e. the
130 * texture format and env mode determine the arithmetic used.
133 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
135 switch (internalFormat
) {
141 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
148 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
150 case GL_LUMINANCE_ALPHA
:
151 case GL_LUMINANCE4_ALPHA4
:
152 case GL_LUMINANCE6_ALPHA2
:
153 case GL_LUMINANCE8_ALPHA8
:
154 case GL_LUMINANCE12_ALPHA4
:
155 case GL_LUMINANCE12_ALPHA12
:
156 case GL_LUMINANCE16_ALPHA16
:
157 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
163 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
165 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
176 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
190 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
192 if (_mesa_is_gles(ctx
)) {
193 switch (internalFormat
) {
201 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
202 switch (internalFormat
) {
210 if (ctx
->Extensions
.ARB_depth_texture
) {
211 switch (internalFormat
) {
212 case GL_DEPTH_COMPONENT
:
213 case GL_DEPTH_COMPONENT16
:
214 case GL_DEPTH_COMPONENT24
:
215 case GL_DEPTH_COMPONENT32
:
216 return GL_DEPTH_COMPONENT
;
217 case GL_DEPTH_STENCIL
:
218 case GL_DEPTH24_STENCIL8
:
219 return GL_DEPTH_STENCIL
;
225 if (ctx
->Extensions
.ARB_texture_stencil8
) {
226 switch (internalFormat
) {
227 case GL_STENCIL_INDEX
:
228 case GL_STENCIL_INDEX1
:
229 case GL_STENCIL_INDEX4
:
230 case GL_STENCIL_INDEX8
:
231 case GL_STENCIL_INDEX16
:
232 return GL_STENCIL_INDEX
;
238 switch (internalFormat
) {
239 case GL_COMPRESSED_ALPHA
:
241 case GL_COMPRESSED_LUMINANCE
:
243 case GL_COMPRESSED_LUMINANCE_ALPHA
:
244 return GL_LUMINANCE_ALPHA
;
245 case GL_COMPRESSED_INTENSITY
:
247 case GL_COMPRESSED_RGB
:
249 case GL_COMPRESSED_RGBA
:
255 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
256 switch (internalFormat
) {
257 case GL_COMPRESSED_RGB_FXT1_3DFX
:
259 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
266 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
268 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
269 switch (internalFormat
) {
270 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
272 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
273 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
274 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
281 if (_mesa_is_desktop_gl(ctx
)
282 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
283 switch (internalFormat
) {
295 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
296 if (internalFormat
== GL_YCBCR_MESA
)
297 return GL_YCBCR_MESA
;
300 if (ctx
->Extensions
.ARB_texture_float
) {
301 switch (internalFormat
) {
302 case GL_ALPHA16F_ARB
:
303 case GL_ALPHA32F_ARB
:
311 case GL_INTENSITY16F_ARB
:
312 case GL_INTENSITY32F_ARB
:
314 case GL_LUMINANCE16F_ARB
:
315 case GL_LUMINANCE32F_ARB
:
317 case GL_LUMINANCE_ALPHA16F_ARB
:
318 case GL_LUMINANCE_ALPHA32F_ARB
:
319 return GL_LUMINANCE_ALPHA
;
325 if (ctx
->Extensions
.EXT_texture_snorm
) {
326 switch (internalFormat
) {
341 case GL_RGBA16_SNORM
:
344 case GL_ALPHA8_SNORM
:
345 case GL_ALPHA16_SNORM
:
347 case GL_LUMINANCE_SNORM
:
348 case GL_LUMINANCE8_SNORM
:
349 case GL_LUMINANCE16_SNORM
:
351 case GL_LUMINANCE_ALPHA_SNORM
:
352 case GL_LUMINANCE8_ALPHA8_SNORM
:
353 case GL_LUMINANCE16_ALPHA16_SNORM
:
354 return GL_LUMINANCE_ALPHA
;
355 case GL_INTENSITY_SNORM
:
356 case GL_INTENSITY8_SNORM
:
357 case GL_INTENSITY16_SNORM
:
364 if (ctx
->Extensions
.EXT_texture_sRGB
) {
365 switch (internalFormat
) {
368 case GL_COMPRESSED_SRGB_EXT
:
370 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
371 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
372 case GL_SRGB_ALPHA_EXT
:
373 case GL_SRGB8_ALPHA8_EXT
:
374 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
376 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
377 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
378 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
379 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
380 case GL_SLUMINANCE_ALPHA_EXT
:
381 case GL_SLUMINANCE8_ALPHA8_EXT
:
382 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
383 return GL_LUMINANCE_ALPHA
;
384 case GL_SLUMINANCE_EXT
:
385 case GL_SLUMINANCE8_EXT
:
386 case GL_COMPRESSED_SLUMINANCE_EXT
:
393 if (ctx
->Version
>= 30 ||
394 ctx
->Extensions
.EXT_texture_integer
) {
395 switch (internalFormat
) {
397 case GL_RGBA16UI_EXT
:
398 case GL_RGBA32UI_EXT
:
414 if (ctx
->Extensions
.EXT_texture_integer
) {
415 switch (internalFormat
) {
416 case GL_ALPHA8UI_EXT
:
417 case GL_ALPHA16UI_EXT
:
418 case GL_ALPHA32UI_EXT
:
420 case GL_ALPHA16I_EXT
:
421 case GL_ALPHA32I_EXT
:
423 case GL_INTENSITY8UI_EXT
:
424 case GL_INTENSITY16UI_EXT
:
425 case GL_INTENSITY32UI_EXT
:
426 case GL_INTENSITY8I_EXT
:
427 case GL_INTENSITY16I_EXT
:
428 case GL_INTENSITY32I_EXT
:
430 case GL_LUMINANCE8UI_EXT
:
431 case GL_LUMINANCE16UI_EXT
:
432 case GL_LUMINANCE32UI_EXT
:
433 case GL_LUMINANCE8I_EXT
:
434 case GL_LUMINANCE16I_EXT
:
435 case GL_LUMINANCE32I_EXT
:
437 case GL_LUMINANCE_ALPHA8UI_EXT
:
438 case GL_LUMINANCE_ALPHA16UI_EXT
:
439 case GL_LUMINANCE_ALPHA32UI_EXT
:
440 case GL_LUMINANCE_ALPHA8I_EXT
:
441 case GL_LUMINANCE_ALPHA16I_EXT
:
442 case GL_LUMINANCE_ALPHA32I_EXT
:
443 return GL_LUMINANCE_ALPHA
;
449 if (ctx
->Extensions
.ARB_texture_rg
) {
450 switch (internalFormat
) {
453 if (!ctx
->Extensions
.ARB_texture_float
)
462 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
468 case GL_COMPRESSED_RED
:
473 if (!ctx
->Extensions
.ARB_texture_float
)
482 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
488 case GL_COMPRESSED_RG
:
495 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
496 switch (internalFormat
) {
504 if (ctx
->Extensions
.EXT_packed_float
) {
505 switch (internalFormat
) {
506 case GL_R11F_G11F_B10F_EXT
:
513 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
514 switch (internalFormat
) {
515 case GL_DEPTH_COMPONENT32F
:
516 return GL_DEPTH_COMPONENT
;
517 case GL_DEPTH32F_STENCIL8
:
518 return GL_DEPTH_STENCIL
;
524 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
525 switch (internalFormat
) {
526 case GL_COMPRESSED_RED_RGTC1
:
527 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
529 case GL_COMPRESSED_RG_RGTC2
:
530 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
537 if (ctx
->API
== API_OPENGL_COMPAT
&&
538 ctx
->Extensions
.EXT_texture_compression_latc
) {
539 switch (internalFormat
) {
540 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
541 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
543 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
544 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
545 return GL_LUMINANCE_ALPHA
;
551 if (ctx
->API
== API_OPENGL_COMPAT
&&
552 ctx
->Extensions
.ATI_texture_compression_3dc
) {
553 switch (internalFormat
) {
554 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
555 return GL_LUMINANCE_ALPHA
;
561 if (_mesa_is_gles(ctx
) &&
562 ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
563 switch (internalFormat
) {
564 case GL_ETC1_RGB8_OES
:
571 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
572 _mesa_is_astc_format(internalFormat
))
575 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
576 switch (internalFormat
) {
577 case GL_COMPRESSED_RGB8_ETC2
:
578 case GL_COMPRESSED_SRGB8_ETC2
:
580 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
581 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
582 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
583 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
585 case GL_COMPRESSED_R11_EAC
:
586 case GL_COMPRESSED_SIGNED_R11_EAC
:
588 case GL_COMPRESSED_RG11_EAC
:
589 case GL_COMPRESSED_SIGNED_RG11_EAC
:
596 if (_mesa_is_desktop_gl(ctx
) &&
597 ctx
->Extensions
.ARB_texture_compression_bptc
) {
598 switch (internalFormat
) {
599 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
600 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
602 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
603 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
610 if (ctx
->API
== API_OPENGLES
) {
611 switch (internalFormat
) {
612 case GL_PALETTE4_RGB8_OES
:
613 case GL_PALETTE4_R5_G6_B5_OES
:
614 case GL_PALETTE8_RGB8_OES
:
615 case GL_PALETTE8_R5_G6_B5_OES
:
617 case GL_PALETTE4_RGBA8_OES
:
618 case GL_PALETTE8_RGB5_A1_OES
:
619 case GL_PALETTE4_RGBA4_OES
:
620 case GL_PALETTE4_RGB5_A1_OES
:
621 case GL_PALETTE8_RGBA8_OES
:
622 case GL_PALETTE8_RGBA4_OES
:
629 return -1; /* error */
634 * For cube map faces, return a face index in [0,5].
635 * For other targets return 0;
638 _mesa_tex_target_to_face(GLenum target
)
640 if (_mesa_is_cube_face(target
))
641 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
649 * Install gl_texture_image in a gl_texture_object according to the target
650 * and level parameters.
652 * \param tObj texture object.
653 * \param target texture target.
654 * \param level image level.
655 * \param texImage texture image.
658 set_tex_image(struct gl_texture_object
*tObj
,
659 GLenum target
, GLint level
,
660 struct gl_texture_image
*texImage
)
662 const GLuint face
= _mesa_tex_target_to_face(target
);
666 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
669 tObj
->Image
[face
][level
] = texImage
;
671 /* Set the 'back' pointer */
672 texImage
->TexObject
= tObj
;
673 texImage
->Level
= level
;
674 texImage
->Face
= face
;
679 * Allocate a texture image structure.
681 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
684 * \return a pointer to gl_texture_image struct with all fields initialized to
687 struct gl_texture_image
*
688 _mesa_new_texture_image( struct gl_context
*ctx
)
691 return CALLOC_STRUCT(gl_texture_image
);
696 * Free a gl_texture_image and associated data.
697 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
699 * \param texImage texture image.
701 * Free the texture image structure and the associated image data.
704 _mesa_delete_texture_image(struct gl_context
*ctx
,
705 struct gl_texture_image
*texImage
)
707 /* Free texImage->Data and/or any other driver-specific texture
710 assert(ctx
->Driver
.FreeTextureImageBuffer
);
711 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
717 * Test if a target is a proxy target.
719 * \param target texture target.
721 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
724 _mesa_is_proxy_texture(GLenum target
)
727 static const GLenum targets
[] = {
731 GL_PROXY_TEXTURE_CUBE_MAP
,
732 GL_PROXY_TEXTURE_RECTANGLE
,
733 GL_PROXY_TEXTURE_1D_ARRAY
,
734 GL_PROXY_TEXTURE_2D_ARRAY
,
735 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
736 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
737 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
740 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
741 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
743 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
745 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
746 if (target
== targets
[i
])
753 * Test if a target is an array target.
755 * \param target texture target.
757 * \return true if the target is an array target, false otherwise.
760 _mesa_is_array_texture(GLenum target
)
763 case GL_TEXTURE_1D_ARRAY
:
764 case GL_TEXTURE_2D_ARRAY
:
765 case GL_TEXTURE_CUBE_MAP_ARRAY
:
766 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
775 * Return the proxy target which corresponds to the given texture target
778 proxy_target(GLenum target
)
782 case GL_PROXY_TEXTURE_1D
:
783 return GL_PROXY_TEXTURE_1D
;
785 case GL_PROXY_TEXTURE_2D
:
786 return GL_PROXY_TEXTURE_2D
;
788 case GL_PROXY_TEXTURE_3D
:
789 return GL_PROXY_TEXTURE_3D
;
790 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
791 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
792 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
793 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
794 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
795 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
796 case GL_TEXTURE_CUBE_MAP_ARB
:
797 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
798 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
799 case GL_TEXTURE_RECTANGLE_NV
:
800 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
801 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
802 case GL_TEXTURE_1D_ARRAY_EXT
:
803 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
804 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
805 case GL_TEXTURE_2D_ARRAY_EXT
:
806 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
807 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
808 case GL_TEXTURE_CUBE_MAP_ARRAY
:
809 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
810 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
811 case GL_TEXTURE_2D_MULTISAMPLE
:
812 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
813 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
814 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
815 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
816 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
818 _mesa_problem(NULL
, "unexpected target in proxy_target()");
827 * Get a texture image pointer from a texture object, given a texture
828 * target and mipmap level. The target and level parameters should
829 * have already been error-checked.
831 * \param texObj texture unit.
832 * \param target texture target.
833 * \param level image level.
835 * \return pointer to the texture image structure, or NULL on failure.
837 struct gl_texture_image
*
838 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
839 GLenum target
, GLint level
)
841 const GLuint face
= _mesa_tex_target_to_face(target
);
845 assert(level
< MAX_TEXTURE_LEVELS
);
847 return texObj
->Image
[face
][level
];
852 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
853 * it and install it. Only return NULL if passed a bad parameter or run
856 struct gl_texture_image
*
857 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
858 GLenum target
, GLint level
)
860 struct gl_texture_image
*texImage
;
865 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
867 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
869 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
873 set_tex_image(texObj
, target
, level
, texImage
);
881 * Return pointer to the specified proxy texture image.
882 * Note that proxy textures are per-context, not per-texture unit.
883 * \return pointer to texture image or NULL if invalid target, invalid
884 * level, or out of memory.
886 static struct gl_texture_image
*
887 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
889 struct gl_texture_image
*texImage
;
896 case GL_PROXY_TEXTURE_1D
:
897 if (level
>= ctx
->Const
.MaxTextureLevels
)
899 texIndex
= TEXTURE_1D_INDEX
;
901 case GL_PROXY_TEXTURE_2D
:
902 if (level
>= ctx
->Const
.MaxTextureLevels
)
904 texIndex
= TEXTURE_2D_INDEX
;
906 case GL_PROXY_TEXTURE_3D
:
907 if (level
>= ctx
->Const
.Max3DTextureLevels
)
909 texIndex
= TEXTURE_3D_INDEX
;
911 case GL_PROXY_TEXTURE_CUBE_MAP
:
912 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
914 texIndex
= TEXTURE_CUBE_INDEX
;
916 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
919 texIndex
= TEXTURE_RECT_INDEX
;
921 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
922 if (level
>= ctx
->Const
.MaxTextureLevels
)
924 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
926 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
927 if (level
>= ctx
->Const
.MaxTextureLevels
)
929 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
931 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
932 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
934 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
936 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
939 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
941 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
944 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
950 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
952 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
954 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
957 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
958 /* Set the 'back' pointer */
959 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
966 * Get the maximum number of allowed mipmap levels.
968 * \param ctx GL context.
969 * \param target texture target.
971 * \return the maximum number of allowed mipmap levels for the given
972 * texture target, or zero if passed a bad target.
977 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
981 case GL_PROXY_TEXTURE_1D
:
983 case GL_PROXY_TEXTURE_2D
:
984 return ctx
->Const
.MaxTextureLevels
;
986 case GL_PROXY_TEXTURE_3D
:
987 return ctx
->Const
.Max3DTextureLevels
;
988 case GL_TEXTURE_CUBE_MAP
:
989 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
990 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
991 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
992 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
993 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
994 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
995 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
996 return ctx
->Extensions
.ARB_texture_cube_map
997 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
998 case GL_TEXTURE_RECTANGLE_NV
:
999 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1000 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
1001 case GL_TEXTURE_1D_ARRAY_EXT
:
1002 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1003 case GL_TEXTURE_2D_ARRAY_EXT
:
1004 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1005 return ctx
->Extensions
.EXT_texture_array
1006 ? ctx
->Const
.MaxTextureLevels
: 0;
1007 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1008 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1009 return ctx
->Extensions
.ARB_texture_cube_map_array
1010 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1011 case GL_TEXTURE_BUFFER
:
1012 return ctx
->API
== API_OPENGL_CORE
&&
1013 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1014 case GL_TEXTURE_2D_MULTISAMPLE
:
1015 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1016 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1017 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1018 return (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
))
1019 && ctx
->Extensions
.ARB_texture_multisample
1021 case GL_TEXTURE_EXTERNAL_OES
:
1024 return 0; /* bad target */
1030 * Return number of dimensions per mipmap level for the given texture target.
1033 _mesa_get_texture_dimensions(GLenum target
)
1037 case GL_PROXY_TEXTURE_1D
:
1040 case GL_TEXTURE_RECTANGLE
:
1041 case GL_TEXTURE_CUBE_MAP
:
1042 case GL_PROXY_TEXTURE_2D
:
1043 case GL_PROXY_TEXTURE_RECTANGLE
:
1044 case GL_PROXY_TEXTURE_CUBE_MAP
:
1045 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1046 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1047 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1048 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1049 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1050 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1051 case GL_TEXTURE_1D_ARRAY
:
1052 case GL_PROXY_TEXTURE_1D_ARRAY
:
1053 case GL_TEXTURE_EXTERNAL_OES
:
1054 case GL_TEXTURE_2D_MULTISAMPLE
:
1055 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1058 case GL_PROXY_TEXTURE_3D
:
1059 case GL_TEXTURE_2D_ARRAY
:
1060 case GL_PROXY_TEXTURE_2D_ARRAY
:
1061 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1062 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1063 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1064 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1066 case GL_TEXTURE_BUFFER
:
1069 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1077 * Check if a texture target can have more than one layer.
1080 _mesa_tex_target_is_layered(GLenum target
)
1084 case GL_PROXY_TEXTURE_1D
:
1086 case GL_PROXY_TEXTURE_2D
:
1087 case GL_TEXTURE_RECTANGLE
:
1088 case GL_PROXY_TEXTURE_RECTANGLE
:
1089 case GL_TEXTURE_2D_MULTISAMPLE
:
1090 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1091 case GL_TEXTURE_BUFFER
:
1092 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1093 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1094 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1095 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1096 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1097 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1098 case GL_TEXTURE_EXTERNAL_OES
:
1102 case GL_PROXY_TEXTURE_3D
:
1103 case GL_TEXTURE_CUBE_MAP
:
1104 case GL_PROXY_TEXTURE_CUBE_MAP
:
1105 case GL_TEXTURE_1D_ARRAY
:
1106 case GL_PROXY_TEXTURE_1D_ARRAY
:
1107 case GL_TEXTURE_2D_ARRAY
:
1108 case GL_PROXY_TEXTURE_2D_ARRAY
:
1109 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1110 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1111 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1112 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1116 assert(!"Invalid texture target.");
1123 * Return the number of layers present in the given level of an array,
1124 * cubemap or 3D texture. If the texture is not layered return zero.
1127 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1129 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1131 switch (texObj
->Target
) {
1134 case GL_TEXTURE_RECTANGLE
:
1135 case GL_TEXTURE_2D_MULTISAMPLE
:
1136 case GL_TEXTURE_BUFFER
:
1137 case GL_TEXTURE_EXTERNAL_OES
:
1140 case GL_TEXTURE_CUBE_MAP
:
1143 case GL_TEXTURE_1D_ARRAY
: {
1144 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1145 return img
? img
->Height
: 0;
1149 case GL_TEXTURE_2D_ARRAY
:
1150 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1151 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1152 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1153 return img
? img
->Depth
: 0;
1157 assert(!"Invalid texture target.");
1164 * Return the maximum number of mipmap levels for the given target
1165 * and the dimensions.
1166 * The dimensions are expected not to include the border.
1169 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1176 case GL_TEXTURE_1D_ARRAY
:
1177 case GL_PROXY_TEXTURE_1D
:
1178 case GL_PROXY_TEXTURE_1D_ARRAY
:
1181 case GL_TEXTURE_CUBE_MAP
:
1182 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1183 case GL_PROXY_TEXTURE_CUBE_MAP
:
1184 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1188 case GL_TEXTURE_2D_ARRAY
:
1189 case GL_PROXY_TEXTURE_2D
:
1190 case GL_PROXY_TEXTURE_2D_ARRAY
:
1191 size
= MAX2(width
, height
);
1194 case GL_PROXY_TEXTURE_3D
:
1195 size
= MAX3(width
, height
, depth
);
1197 case GL_TEXTURE_RECTANGLE
:
1198 case GL_TEXTURE_EXTERNAL_OES
:
1199 case GL_TEXTURE_2D_MULTISAMPLE
:
1200 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1201 case GL_PROXY_TEXTURE_RECTANGLE
:
1202 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1203 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1210 return _mesa_logbase2(size
) + 1;
1214 #if 000 /* not used anymore */
1216 * glTexImage[123]D can accept a NULL image pointer. In this case we
1217 * create a texture image with unspecified image contents per the OpenGL
1221 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1223 const GLint components
= _mesa_components_in_format(format
);
1224 const GLint numPixels
= width
* height
* depth
;
1225 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1229 * Let's see if anyone finds this. If glTexImage2D() is called with
1230 * a NULL image pointer then load the texture image with something
1231 * interesting instead of leaving it indeterminate.
1234 static const char message
[8][32] = {
1235 " X X XXXXX XXX X ",
1236 " XX XX X X X X X ",
1238 " X X XXXX XXX XXXXX ",
1241 " X X XXXXX XXX X X ",
1245 GLubyte
*imgPtr
= data
;
1247 for (h
= 0; h
< depth
; h
++) {
1248 for (i
= 0; i
< height
; i
++) {
1249 GLint srcRow
= 7 - (i
% 8);
1250 for (j
= 0; j
< width
; j
++) {
1251 GLint srcCol
= j
% 32;
1252 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1253 for (k
= 0; k
< components
; k
++) {
1269 * Set the size and format-related fields of a gl_texture_image struct
1270 * to zero. This is used when a proxy texture test fails.
1273 clear_teximage_fields(struct gl_texture_image
*img
)
1276 img
->_BaseFormat
= 0;
1277 img
->InternalFormat
= 0;
1286 img
->HeightLog2
= 0;
1288 img
->TexFormat
= MESA_FORMAT_NONE
;
1289 img
->NumSamples
= 0;
1290 img
->FixedSampleLocations
= GL_TRUE
;
1295 * Initialize basic fields of the gl_texture_image struct.
1297 * \param ctx GL context.
1298 * \param img texture image structure to be initialized.
1299 * \param width image width.
1300 * \param height image height.
1301 * \param depth image depth.
1302 * \param border image border.
1303 * \param internalFormat internal format.
1304 * \param format the actual hardware format (one of MESA_FORMAT_*)
1305 * \param numSamples number of samples per texel, or zero for non-MS.
1306 * \param fixedSampleLocations are sample locations fixed?
1308 * Fills in the fields of \p img with the given information.
1309 * Note: width, height and depth include the border.
1312 init_teximage_fields_ms(struct gl_context
*ctx
,
1313 struct gl_texture_image
*img
,
1314 GLsizei width
, GLsizei height
, GLsizei depth
,
1315 GLint border
, GLenum internalFormat
,
1317 GLuint numSamples
, GLboolean fixedSampleLocations
)
1322 assert(height
>= 0);
1325 target
= img
->TexObject
->Target
;
1326 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1327 assert(img
->_BaseFormat
!= -1);
1328 img
->InternalFormat
= internalFormat
;
1329 img
->Border
= border
;
1331 img
->Height
= height
;
1334 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1335 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1337 img
->NumSamples
= 0;
1338 img
->FixedSampleLocations
= GL_TRUE
;
1342 case GL_TEXTURE_BUFFER
:
1343 case GL_PROXY_TEXTURE_1D
:
1348 img
->HeightLog2
= 0;
1355 case GL_TEXTURE_1D_ARRAY
:
1356 case GL_PROXY_TEXTURE_1D_ARRAY
:
1357 img
->Height2
= height
; /* no border */
1358 img
->HeightLog2
= 0; /* not used */
1366 case GL_TEXTURE_RECTANGLE
:
1367 case GL_TEXTURE_CUBE_MAP
:
1368 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1369 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1370 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1371 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1372 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1373 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1374 case GL_TEXTURE_EXTERNAL_OES
:
1375 case GL_PROXY_TEXTURE_2D
:
1376 case GL_PROXY_TEXTURE_RECTANGLE
:
1377 case GL_PROXY_TEXTURE_CUBE_MAP
:
1378 case GL_TEXTURE_2D_MULTISAMPLE
:
1379 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1380 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1381 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1388 case GL_TEXTURE_2D_ARRAY
:
1389 case GL_PROXY_TEXTURE_2D_ARRAY
:
1390 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1391 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1392 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1393 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1394 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1395 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1396 img
->Depth2
= depth
; /* no border */
1397 img
->DepthLog2
= 0; /* not used */
1400 case GL_PROXY_TEXTURE_3D
:
1401 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1402 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1403 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1404 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1407 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1412 _mesa_get_tex_max_num_levels(target
,
1413 img
->Width2
, img
->Height2
, img
->Depth2
);
1414 img
->TexFormat
= format
;
1415 img
->NumSamples
= numSamples
;
1416 img
->FixedSampleLocations
= fixedSampleLocations
;
1421 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1422 struct gl_texture_image
*img
,
1423 GLsizei width
, GLsizei height
, GLsizei depth
,
1424 GLint border
, GLenum internalFormat
,
1427 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1428 internalFormat
, format
, 0, GL_TRUE
);
1433 * Free and clear fields of the gl_texture_image struct.
1435 * \param ctx GL context.
1436 * \param texImage texture image structure to be cleared.
1438 * After the call, \p texImage will have no data associated with it. Its
1439 * fields are cleared so that its parent object will test incomplete.
1442 _mesa_clear_texture_image(struct gl_context
*ctx
,
1443 struct gl_texture_image
*texImage
)
1445 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1446 clear_teximage_fields(texImage
);
1451 * Check the width, height, depth and border of a texture image are legal.
1452 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1454 * The target and level parameters will have already been validated.
1455 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1458 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1459 GLint level
, GLint width
, GLint height
,
1460 GLint depth
, GLint border
)
1466 case GL_PROXY_TEXTURE_1D
:
1467 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1468 maxSize
>>= level
; /* level size */
1469 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1471 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1472 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1478 case GL_PROXY_TEXTURE_2D
:
1479 case GL_TEXTURE_2D_MULTISAMPLE
:
1480 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1481 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1483 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1485 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1487 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1488 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1490 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1496 case GL_PROXY_TEXTURE_3D
:
1497 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1499 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1501 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1503 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1505 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1506 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1508 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1510 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1515 case GL_TEXTURE_RECTANGLE_NV
:
1516 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1519 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1520 if (width
< 0 || width
> maxSize
)
1522 if (height
< 0 || height
> maxSize
)
1526 case GL_TEXTURE_CUBE_MAP
:
1527 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1528 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1529 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1530 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1531 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1532 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1533 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1534 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1536 if (width
!= height
)
1538 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1540 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1542 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1543 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1545 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1550 case GL_TEXTURE_1D_ARRAY_EXT
:
1551 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1552 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1554 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1556 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1558 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1559 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1564 case GL_TEXTURE_2D_ARRAY_EXT
:
1565 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1566 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1567 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1568 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1570 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1572 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1574 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1576 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1577 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1579 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1584 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1585 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1586 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1587 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1589 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1591 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1593 if (width
!= height
)
1595 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1597 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1598 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1600 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1605 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1612 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1613 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1614 * \param destImage the destination texture image.
1615 * \return GL_TRUE if error found, GL_FALSE otherwise.
1618 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1619 const struct gl_texture_image
*destImage
,
1620 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1621 GLsizei subWidth
, GLsizei subHeight
,
1622 GLsizei subDepth
, const char *func
)
1624 const GLenum target
= destImage
->TexObject
->Target
;
1629 _mesa_error(ctx
, GL_INVALID_VALUE
,
1630 "%s(width=%d)", func
, subWidth
);
1634 if (dims
> 1 && subHeight
< 0) {
1635 _mesa_error(ctx
, GL_INVALID_VALUE
,
1636 "%s(height=%d)", func
, subHeight
);
1640 if (dims
> 2 && subDepth
< 0) {
1641 _mesa_error(ctx
, GL_INVALID_VALUE
,
1642 "%s(depth=%d)", func
, subDepth
);
1646 /* check xoffset and width */
1647 if (xoffset
< - (GLint
) destImage
->Border
) {
1648 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset)", func
);
1652 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1653 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset+width)", func
);
1657 /* check yoffset and height */
1659 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1660 if (yoffset
< -yBorder
) {
1661 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset)", func
);
1664 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1665 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset+height)", func
);
1670 /* check zoffset and depth */
1673 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1674 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1675 0 : destImage
->Border
;
1677 if (zoffset
< -zBorder
) {
1678 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset)", func
);
1682 depth
= (GLint
) destImage
->Depth
;
1683 if (target
== GL_TEXTURE_CUBE_MAP
)
1685 if (zoffset
+ subDepth
> depth
) {
1686 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset+depth)", func
);
1692 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1693 * compressed texture images can be updated. But, that restriction may be
1694 * relaxed for particular compressed formats. At this time, all the
1695 * compressed formats supported by Mesa allow sub-textures to be updated
1696 * along compressed block boundaries.
1698 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1700 if (bw
!= 1 || bh
!= 1) {
1701 /* offset must be multiple of block size */
1702 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1703 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1704 "%s(xoffset = %d, yoffset = %d)",
1705 func
, xoffset
, yoffset
);
1709 /* The size must be a multiple of bw x bh, or we must be using a
1710 * offset+size that exactly hits the edge of the image. This
1711 * is important for small mipmap levels (1x1, 2x1, etc) and for
1714 if ((subWidth
% bw
!= 0) &&
1715 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1716 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1717 "%s(width = %d)", func
, subWidth
);
1721 if ((subHeight
% bh
!= 0) &&
1722 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1723 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1724 "%s(height = %d)", func
, subHeight
);
1736 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1737 * specific texture image size checks.
1739 * A hardware driver might override this function if, for example, the
1740 * max 3D texture size is 512x512x64 (i.e. not a cube).
1742 * Note that width, height, depth == 0 is not an error. However, a
1743 * texture with zero width/height/depth will be considered "incomplete"
1744 * and texturing will effectively be disabled.
1746 * \param target any texture target/type
1747 * \param level as passed to glTexImage
1748 * \param format the MESA_FORMAT_x for the tex image
1749 * \param width as passed to glTexImage
1750 * \param height as passed to glTexImage
1751 * \param depth as passed to glTexImage
1752 * \param border as passed to glTexImage
1753 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1756 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1758 GLint width
, GLint height
, GLint depth
, GLint border
)
1760 /* We just check if the image size is less than MaxTextureMbytes.
1761 * Some drivers may do more specific checks.
1763 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1764 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1765 mbytes
*= _mesa_num_tex_faces(target
);
1766 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1771 * Return true if the format is only valid for glCompressedTexImage.
1774 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1777 case GL_ETC1_RGB8_OES
:
1778 case GL_PALETTE4_RGB8_OES
:
1779 case GL_PALETTE4_RGBA8_OES
:
1780 case GL_PALETTE4_R5_G6_B5_OES
:
1781 case GL_PALETTE4_RGBA4_OES
:
1782 case GL_PALETTE4_RGB5_A1_OES
:
1783 case GL_PALETTE8_RGB8_OES
:
1784 case GL_PALETTE8_RGBA8_OES
:
1785 case GL_PALETTE8_R5_G6_B5_OES
:
1786 case GL_PALETTE8_RGBA4_OES
:
1787 case GL_PALETTE8_RGB5_A1_OES
:
1795 * Return true if the format doesn't support online compression.
1798 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
)
1800 return _mesa_is_astc_format(format
) ||
1801 compressedteximage_only_format(ctx
, format
);
1804 /* Writes to an GL error pointer if non-null and returns whether or not the
1805 * error is GL_NO_ERROR */
1807 write_error(GLenum
*err_ptr
, GLenum error
)
1812 return error
== GL_NO_ERROR
;
1816 * Helper function to determine whether a target and specific compression
1817 * format are supported. The error parameter returns GL_NO_ERROR if the
1818 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1819 * or GL_INVALID_ENUM, whichever is more appropriate.
1822 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1823 GLenum intFormat
, GLenum
*error
)
1825 GLboolean target_can_be_compresed
= GL_FALSE
;
1826 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1827 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1831 case GL_PROXY_TEXTURE_2D
:
1832 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1834 case GL_PROXY_TEXTURE_CUBE_MAP
:
1835 case GL_TEXTURE_CUBE_MAP
:
1836 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1837 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1838 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1839 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1840 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1841 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1842 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1844 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1845 case GL_TEXTURE_2D_ARRAY_EXT
:
1846 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1848 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1849 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1850 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1852 * "The ETC2/EAC texture compression algorithm supports only
1853 * two-dimensional images. If internalformat is an ETC2/EAC format,
1854 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1855 * target is not TEXTURE_2D_ARRAY."
1857 * This should also be applicable for glTexStorage3D(). Other available
1858 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1860 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
))
1861 return write_error(error
, GL_INVALID_OPERATION
);
1863 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map_array
;
1865 /* From the KHR_texture_compression_astc_hdr spec:
1867 * Add a second new column "3D Tex." which is empty for all non-ASTC
1868 * formats. If only the LDR profile is supported by the
1869 * implementation, this column is also empty for all ASTC formats. If
1870 * both the LDR and HDR profiles are supported only, this column is
1871 * checked for all ASTC formats.
1873 * Add a third new column "Cube Map Array Tex." which is empty for all
1874 * non-ASTC formats, and checked for all ASTC formats.
1878 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1879 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1880 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1881 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1882 * 8.19 is *not* checked'
1884 * The instances of <internalformat> above should say <target>.
1887 /* Throw an INVALID_OPERATION error if the target is
1888 * TEXTURE_CUBE_MAP_ARRAY and the format is not ASTC.
1890 if (target_can_be_compresed
&&
1891 ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
1892 layout
!= MESA_FORMAT_LAYOUT_ASTC
)
1893 return write_error(error
, GL_INVALID_OPERATION
);
1898 case MESA_FORMAT_LAYOUT_ETC2
:
1899 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1900 if (_mesa_is_gles3(ctx
))
1901 return write_error(error
, GL_INVALID_OPERATION
);
1903 case MESA_FORMAT_LAYOUT_BPTC
:
1904 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1906 case MESA_FORMAT_LAYOUT_ASTC
:
1907 target_can_be_compresed
=
1908 ctx
->Extensions
.KHR_texture_compression_astc_hdr
;
1910 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1911 * and the hdr extension is not supported.
1912 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1914 if (!target_can_be_compresed
)
1915 return write_error(error
, GL_INVALID_OPERATION
);
1918 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1919 * the format is not ASTC.
1920 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1922 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
)
1923 return write_error(error
, GL_INVALID_OPERATION
);
1929 return write_error(error
,
1930 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1935 * Check if the given texture target value is legal for a
1936 * glTexImage1/2/3D call.
1939 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1945 case GL_PROXY_TEXTURE_1D
:
1946 return _mesa_is_desktop_gl(ctx
);
1954 case GL_PROXY_TEXTURE_2D
:
1955 return _mesa_is_desktop_gl(ctx
);
1956 case GL_PROXY_TEXTURE_CUBE_MAP
:
1957 return _mesa_is_desktop_gl(ctx
)
1958 && ctx
->Extensions
.ARB_texture_cube_map
;
1959 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1960 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1961 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1962 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1963 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1964 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1965 return ctx
->Extensions
.ARB_texture_cube_map
;
1966 case GL_TEXTURE_RECTANGLE_NV
:
1967 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1968 return _mesa_is_desktop_gl(ctx
)
1969 && ctx
->Extensions
.NV_texture_rectangle
;
1970 case GL_TEXTURE_1D_ARRAY_EXT
:
1971 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1972 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1980 case GL_PROXY_TEXTURE_3D
:
1981 return _mesa_is_desktop_gl(ctx
);
1982 case GL_TEXTURE_2D_ARRAY_EXT
:
1983 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1984 || _mesa_is_gles3(ctx
);
1985 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1986 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1987 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1988 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1989 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1994 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
2001 * Check if the given texture target value is legal for a
2002 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
2003 * The difference compared to legal_teximage_target() above is that
2004 * proxy targets are not supported.
2007 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
2012 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
2017 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2018 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2019 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2020 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2021 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2022 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2023 return ctx
->Extensions
.ARB_texture_cube_map
;
2024 case GL_TEXTURE_RECTANGLE_NV
:
2025 return _mesa_is_desktop_gl(ctx
)
2026 && ctx
->Extensions
.NV_texture_rectangle
;
2027 case GL_TEXTURE_1D_ARRAY_EXT
:
2028 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
2036 case GL_TEXTURE_2D_ARRAY_EXT
:
2037 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
2038 || _mesa_is_gles3(ctx
);
2039 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2040 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
2041 return ctx
->Extensions
.ARB_texture_cube_map_array
;
2043 /* Table 8.15 of the OpenGL 4.5 core profile spec
2044 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
2045 * and CopyTextureSubImage3D.
2047 case GL_TEXTURE_CUBE_MAP
:
2053 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
2061 * Helper function to determine if a texture object is mutable (in terms
2062 * of GL_ARB_texture_storage).
2065 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
2067 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
2071 return !texObj
->Immutable
;
2076 * Return expected size of a compressed texture.
2079 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2082 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2083 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2087 * Verify that a texture format is valid with a particular target
2089 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
2090 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
2093 * \param ctx GL context
2094 * \param target Texture target
2095 * \param internalFormat Internal format of the texture image
2096 * \param dimensions Dimensionality at the caller. This is \b not used
2097 * in the validation. It is only used when logging
2099 * \param caller Base name of the calling function (e.g.,
2100 * "glTexImage" or "glTexStorage").
2102 * \returns true if the combination is legal, false otherwise.
2105 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
2106 GLenum target
, GLenum internalFormat
,
2107 unsigned dimensions
,
2110 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2111 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
2112 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
2113 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
2114 * Profile spec says:
2116 * "Textures with a base internal format of DEPTH_COMPONENT or
2117 * DEPTH_STENCIL are supported by texture image specification
2118 * commands only if target is TEXTURE_1D, TEXTURE_2D,
2119 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
2120 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
2121 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
2122 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
2123 * formats in conjunction with any other target will result in an
2124 * INVALID_OPERATION error."
2126 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
2127 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
2129 if (target
!= GL_TEXTURE_1D
&&
2130 target
!= GL_PROXY_TEXTURE_1D
&&
2131 target
!= GL_TEXTURE_2D
&&
2132 target
!= GL_PROXY_TEXTURE_2D
&&
2133 target
!= GL_TEXTURE_1D_ARRAY
&&
2134 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2135 target
!= GL_TEXTURE_2D_ARRAY
&&
2136 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2137 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2138 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2139 !((_mesa_is_cube_face(target
) ||
2140 target
== GL_TEXTURE_CUBE_MAP
||
2141 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2142 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2143 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2144 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2145 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2146 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2147 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2148 "%s%dD(bad target for depth texture)",
2149 caller
, dimensions
);
2158 texture_formats_agree(GLenum internalFormat
,
2161 GLboolean colorFormat
;
2162 GLboolean is_format_depth_or_depthstencil
;
2163 GLboolean is_internalFormat_depth_or_depthstencil
;
2165 /* Even though there are no color-index textures, we still have to support
2166 * uploading color-index data and remapping it to RGB via the
2167 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2169 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2171 is_internalFormat_depth_or_depthstencil
=
2172 _mesa_is_depth_format(internalFormat
) ||
2173 _mesa_is_depthstencil_format(internalFormat
);
2175 is_format_depth_or_depthstencil
=
2176 _mesa_is_depth_format(format
) ||
2177 _mesa_is_depthstencil_format(format
);
2179 colorFormat
= _mesa_is_color_format(format
);
2181 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2184 if (is_internalFormat_depth_or_depthstencil
!=
2185 is_format_depth_or_depthstencil
)
2188 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2195 * Test the combination of format, type and internal format arguments of
2196 * different texture operations on GLES.
2198 * \param ctx GL context.
2199 * \param format pixel data format given by the user.
2200 * \param type pixel data type given by the user.
2201 * \param internalFormat internal format given by the user.
2202 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2203 * \param callerName name of the caller function to print in the error message
2205 * \return true if a error is found, false otherwise
2207 * Currently, it is used by texture_error_check() and texsubimage_error_check().
2210 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
2211 GLenum type
, GLenum internalFormat
,
2212 GLuint dimensions
, const char *callerName
)
2216 if (_mesa_is_gles3(ctx
)) {
2217 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
2219 if (err
!= GL_NO_ERROR
) {
2220 _mesa_error(ctx
, err
,
2221 "%s(format = %s, type = %s, internalformat = %s)",
2222 callerName
, _mesa_enum_to_string(format
),
2223 _mesa_enum_to_string(type
),
2224 _mesa_enum_to_string(internalFormat
));
2229 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2230 if (err
!= GL_NO_ERROR
) {
2231 _mesa_error(ctx
, err
, "%s(format = %s, type = %s)",
2232 callerName
, _mesa_enum_to_string(format
),
2233 _mesa_enum_to_string(type
));
2242 * Test the glTexImage[123]D() parameters for errors.
2244 * \param ctx GL context.
2245 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2246 * \param target texture target given by the user (already validated).
2247 * \param level image level given by the user.
2248 * \param internalFormat internal format given by the user.
2249 * \param format pixel data format given by the user.
2250 * \param type pixel data type given by the user.
2251 * \param width image width given by the user.
2252 * \param height image height given by the user.
2253 * \param depth image depth given by the user.
2254 * \param border image border given by the user.
2256 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2258 * Verifies each of the parameters against the constants specified in
2259 * __struct gl_contextRec::Const and the supported extensions, and according
2260 * to the OpenGL specification.
2261 * Note that we don't fully error-check the width, height, depth values
2262 * here. That's done in _mesa_legal_texture_dimensions() which is used
2263 * by several other GL entrypoints. Plus, texture dims have a special
2264 * interaction with proxy textures.
2267 texture_error_check( struct gl_context
*ctx
,
2268 GLuint dimensions
, GLenum target
,
2269 GLint level
, GLint internalFormat
,
2270 GLenum format
, GLenum type
,
2271 GLint width
, GLint height
,
2272 GLint depth
, GLint border
,
2273 const GLvoid
*pixels
)
2277 /* Note: for proxy textures, some error conditions immediately generate
2278 * a GL error in the usual way. But others do not generate a GL error.
2279 * Instead, they cause the width, height, depth, format fields of the
2280 * texture image to be zeroed-out. The GL spec seems to indicate that the
2281 * zero-out behaviour is only used in cases related to memory allocation.
2285 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2286 _mesa_error(ctx
, GL_INVALID_VALUE
,
2287 "glTexImage%dD(level=%d)", dimensions
, level
);
2292 if (border
< 0 || border
> 1 ||
2293 ((ctx
->API
!= API_OPENGL_COMPAT
||
2294 target
== GL_TEXTURE_RECTANGLE_NV
||
2295 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2296 _mesa_error(ctx
, GL_INVALID_VALUE
,
2297 "glTexImage%dD(border=%d)", dimensions
, border
);
2301 if (width
< 0 || height
< 0 || depth
< 0) {
2302 _mesa_error(ctx
, GL_INVALID_VALUE
,
2303 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2307 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2308 * combinations of format, internalFormat, and type that can be used.
2309 * Formats and types that require additional extensions (e.g., GL_FLOAT
2310 * requires GL_OES_texture_float) are filtered elsewhere.
2312 if (_mesa_is_gles(ctx
) &&
2313 texture_format_error_check_gles(ctx
, format
, type
, internalFormat
,
2314 dimensions
, "glTexImage%dD")) {
2318 /* Check internalFormat */
2319 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2320 _mesa_error(ctx
, GL_INVALID_VALUE
,
2321 "glTexImage%dD(internalFormat=%s)",
2322 dimensions
, _mesa_enum_to_string(internalFormat
));
2326 /* Check incoming image format and type */
2327 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2328 if (err
!= GL_NO_ERROR
) {
2329 _mesa_error(ctx
, err
,
2330 "glTexImage%dD(incompatible format = %s, type = %s)",
2331 dimensions
, _mesa_enum_to_string(format
),
2332 _mesa_enum_to_string(type
));
2336 /* validate the bound PBO, if any */
2337 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2338 width
, height
, depth
, format
, type
,
2339 INT_MAX
, pixels
, "glTexImage")) {
2343 /* make sure internal format and format basically agree */
2344 if (!texture_formats_agree(internalFormat
, format
)) {
2345 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2346 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2347 dimensions
, _mesa_enum_to_string(internalFormat
),
2348 _mesa_enum_to_string(format
));
2352 /* additional checks for ycbcr textures */
2353 if (internalFormat
== GL_YCBCR_MESA
) {
2354 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
2355 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2356 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2358 _mesa_snprintf(message
, sizeof(message
),
2359 "glTexImage%dD(format/type YCBCR mismatch)",
2361 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2362 return GL_TRUE
; /* error */
2364 if (target
!= GL_TEXTURE_2D
&&
2365 target
!= GL_PROXY_TEXTURE_2D
&&
2366 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2367 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2368 _mesa_error(ctx
, GL_INVALID_ENUM
,
2369 "glTexImage%dD(bad target for YCbCr texture)",
2375 _mesa_snprintf(message
, sizeof(message
),
2376 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2377 dimensions
, border
);
2378 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2383 /* additional checks for depth textures */
2384 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2385 dimensions
, "glTexImage"))
2388 /* additional checks for compressed textures */
2389 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2391 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2392 _mesa_error(ctx
, err
,
2393 "glTexImage%dD(target can't be compressed)", dimensions
);
2396 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2397 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2398 "glTexImage%dD(no compression for format)", dimensions
);
2402 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2403 "glTexImage%dD(border!=0)", dimensions
);
2408 /* additional checks for integer textures */
2409 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2410 (_mesa_is_enum_format_integer(format
) !=
2411 _mesa_is_enum_format_integer(internalFormat
))) {
2412 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2413 "glTexImage%dD(integer/non-integer format mismatch)",
2418 if (!mutable_tex_object(ctx
, target
)) {
2419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2420 "glTexImage%dD(immutable texture)", dimensions
);
2424 /* if we get here, the parameters are OK */
2430 * Error checking for glCompressedTexImage[123]D().
2431 * Note that the width, height and depth values are not fully error checked
2433 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2436 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2437 GLenum target
, GLint level
,
2438 GLenum internalFormat
, GLsizei width
,
2439 GLsizei height
, GLsizei depth
, GLint border
,
2440 GLsizei imageSize
, const GLvoid
*data
)
2442 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2444 GLenum error
= GL_NO_ERROR
;
2445 char *reason
= ""; /* no error */
2447 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
2452 /* This will detect any invalid internalFormat value */
2453 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2454 _mesa_error(ctx
, GL_INVALID_ENUM
,
2455 "glCompressedTexImage%dD(internalFormat=%s)",
2456 dimensions
, _mesa_enum_to_string(internalFormat
));
2460 /* validate the bound PBO, if any */
2461 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2463 "glCompressedTexImage")) {
2467 switch (internalFormat
) {
2468 case GL_PALETTE4_RGB8_OES
:
2469 case GL_PALETTE4_RGBA8_OES
:
2470 case GL_PALETTE4_R5_G6_B5_OES
:
2471 case GL_PALETTE4_RGBA4_OES
:
2472 case GL_PALETTE4_RGB5_A1_OES
:
2473 case GL_PALETTE8_RGB8_OES
:
2474 case GL_PALETTE8_RGBA8_OES
:
2475 case GL_PALETTE8_R5_G6_B5_OES
:
2476 case GL_PALETTE8_RGBA4_OES
:
2477 case GL_PALETTE8_RGB5_A1_OES
:
2478 /* check level (note that level should be zero or less!) */
2479 if (level
> 0 || level
< -maxLevels
) {
2481 error
= GL_INVALID_VALUE
;
2485 if (dimensions
!= 2) {
2486 reason
= "compressed paletted textures must be 2D";
2487 error
= GL_INVALID_OPERATION
;
2491 /* Figure out the expected texture size (in bytes). This will be
2492 * checked against the actual size later.
2494 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2497 /* This is for the benefit of the TestProxyTexImage below. It expects
2498 * level to be non-negative. OES_compressed_paletted_texture uses a
2499 * weird mechanism where the level specified to glCompressedTexImage2D
2500 * is -(n-1) number of levels in the texture, and the data specifies the
2501 * complete mipmap stack. This is done to ensure the palette is the
2502 * same for all levels.
2509 if (level
< 0 || level
>= maxLevels
) {
2511 error
= GL_INVALID_VALUE
;
2515 /* Figure out the expected texture size (in bytes). This will be
2516 * checked against the actual size later.
2518 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2522 /* This should really never fail */
2523 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2524 reason
= "internalFormat";
2525 error
= GL_INVALID_ENUM
;
2529 /* No compressed formats support borders at this time */
2531 reason
= "border != 0";
2532 error
= GL_INVALID_VALUE
;
2536 /* Check for invalid pixel storage modes */
2537 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2539 "glCompressedTexImage")) {
2543 /* check image size in bytes */
2544 if (expectedSize
!= imageSize
) {
2545 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2546 * if <imageSize> is not consistent with the format, dimensions, and
2547 * contents of the specified image.
2549 reason
= "imageSize inconsistant with width/height/format";
2550 error
= GL_INVALID_VALUE
;
2554 if (!mutable_tex_object(ctx
, target
)) {
2555 reason
= "immutable texture";
2556 error
= GL_INVALID_OPERATION
;
2563 /* Note: not all error paths exit through here. */
2564 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2565 dimensions
, reason
);
2572 * Test glTexSubImage[123]D() parameters for errors.
2574 * \param ctx GL context.
2575 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2576 * \param target texture target given by the user (already validated)
2577 * \param level image level given by the user.
2578 * \param xoffset sub-image x offset given by the user.
2579 * \param yoffset sub-image y offset given by the user.
2580 * \param zoffset sub-image z offset given by the user.
2581 * \param format pixel data format given by the user.
2582 * \param type pixel data type given by the user.
2583 * \param width image width given by the user.
2584 * \param height image height given by the user.
2585 * \param depth image depth given by the user.
2587 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2589 * Verifies each of the parameters against the constants specified in
2590 * __struct gl_contextRec::Const and the supported extensions, and according
2591 * to the OpenGL specification.
2594 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2595 struct gl_texture_object
*texObj
,
2596 GLenum target
, GLint level
,
2597 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2598 GLint width
, GLint height
, GLint depth
,
2599 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2600 bool dsa
, const char *callerName
)
2602 struct gl_texture_image
*texImage
;
2606 /* must be out of memory */
2607 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2612 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2613 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2617 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2619 /* non-existant texture level */
2620 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture image)",
2625 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2626 if (err
!= GL_NO_ERROR
) {
2627 _mesa_error(ctx
, err
,
2628 "%s(incompatible format = %s, type = %s)",
2629 callerName
, _mesa_enum_to_string(format
),
2630 _mesa_enum_to_string(type
));
2634 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2635 * combinations of format, internalFormat, and type that can be used.
2636 * Formats and types that require additional extensions (e.g., GL_FLOAT
2637 * requires GL_OES_texture_float) are filtered elsewhere.
2639 if (_mesa_is_gles(ctx
) &&
2640 texture_format_error_check_gles(ctx
, format
, type
,
2641 texImage
->InternalFormat
,
2642 dimensions
, callerName
)) {
2646 /* validate the bound PBO, if any */
2647 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2648 width
, height
, depth
, format
, type
,
2649 INT_MAX
, pixels
, callerName
)) {
2653 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2654 texImage
, xoffset
, yoffset
, zoffset
,
2655 width
, height
, depth
, callerName
)) {
2659 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2660 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2661 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2662 "%s(no compression for format)", callerName
);
2667 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2668 /* both source and dest must be integer-valued, or neither */
2669 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2670 _mesa_is_enum_format_integer(format
)) {
2671 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2672 "%s(integer/non-integer format mismatch)", callerName
);
2682 * Test glCopyTexImage[12]D() parameters for errors.
2684 * \param ctx GL context.
2685 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2686 * \param target texture target given by the user.
2687 * \param level image level given by the user.
2688 * \param internalFormat internal format given by the user.
2689 * \param width image width given by the user.
2690 * \param height image height given by the user.
2691 * \param border texture border.
2693 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2695 * Verifies each of the parameters against the constants specified in
2696 * __struct gl_contextRec::Const and the supported extensions, and according
2697 * to the OpenGL specification.
2700 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2701 GLenum target
, GLint level
, GLint internalFormat
,
2702 GLint width
, GLint height
, GLint border
)
2705 GLint rb_base_format
;
2706 struct gl_renderbuffer
*rb
;
2707 GLenum rb_internal_format
;
2710 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2711 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2712 dimensions
, _mesa_enum_to_string(target
));
2717 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2718 _mesa_error(ctx
, GL_INVALID_VALUE
,
2719 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2723 /* Check that the source buffer is complete */
2724 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2725 if (ctx
->ReadBuffer
->_Status
== 0) {
2726 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2728 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2729 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2730 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2734 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2735 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2736 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2742 if (border
< 0 || border
> 1 ||
2743 ((ctx
->API
!= API_OPENGL_COMPAT
||
2744 target
== GL_TEXTURE_RECTANGLE_NV
||
2745 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2746 _mesa_error(ctx
, GL_INVALID_VALUE
,
2747 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2751 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2754 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2755 switch (internalFormat
) {
2760 case GL_LUMINANCE_ALPHA
:
2763 _mesa_error(ctx
, GL_INVALID_ENUM
,
2764 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2765 _mesa_enum_to_string(internalFormat
));
2770 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2771 if (baseFormat
< 0) {
2772 _mesa_error(ctx
, GL_INVALID_ENUM
,
2773 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2774 _mesa_enum_to_string(internalFormat
));
2778 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2780 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2781 "glCopyTexImage%dD(read buffer)", dimensions
);
2785 rb_internal_format
= rb
->InternalFormat
;
2786 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2787 if (_mesa_is_color_format(internalFormat
)) {
2788 if (rb_base_format
< 0) {
2789 _mesa_error(ctx
, GL_INVALID_VALUE
,
2790 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2791 _mesa_enum_to_string(internalFormat
));
2796 if (_mesa_is_gles(ctx
)) {
2798 if (_mesa_base_format_component_count(baseFormat
) >
2799 _mesa_base_format_component_count(rb_base_format
)) {
2802 if (baseFormat
== GL_DEPTH_COMPONENT
||
2803 baseFormat
== GL_DEPTH_STENCIL
||
2804 rb_base_format
== GL_DEPTH_COMPONENT
||
2805 rb_base_format
== GL_DEPTH_STENCIL
||
2806 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2807 baseFormat
== GL_ALPHA
) &&
2808 rb_base_format
!= GL_RGBA
) ||
2809 internalFormat
== GL_RGB9_E5
) {
2812 if (internalFormat
== GL_RGB9_E5
) {
2816 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2817 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2818 _mesa_enum_to_string(internalFormat
));
2823 if (_mesa_is_gles3(ctx
)) {
2824 bool rb_is_srgb
= false;
2825 bool dst_is_srgb
= false;
2827 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2828 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2832 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2836 if (rb_is_srgb
!= dst_is_srgb
) {
2837 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2838 * OpenGLES 3.0.0 spec says:
2840 * "The error INVALID_OPERATION is also generated if the
2841 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2842 * framebuffer attachment corresponding to the read buffer
2843 * is LINEAR (see section 6.1.13) and internalformat is
2844 * one of the sRGB formats described in section 3.8.16, or
2845 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2846 * SRGB and internalformat is not one of the sRGB formats."
2848 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2849 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2853 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2854 * types for SNORM formats. Also, conversion to SNORM formats is not
2855 * allowed by Table 3.2 on Page 110.
2857 if (_mesa_is_enum_format_snorm(internalFormat
)) {
2858 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2859 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2860 _mesa_enum_to_string(internalFormat
));
2865 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2866 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2867 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2871 /* From the EXT_texture_integer spec:
2873 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2874 * if the texture internalformat is an integer format and the read color
2875 * buffer is not an integer format, or if the internalformat is not an
2876 * integer format and the read color buffer is an integer format."
2878 if (_mesa_is_color_format(internalFormat
)) {
2879 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2880 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2881 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2882 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2883 if (is_int
|| is_rbint
) {
2884 if (is_int
!= is_rbint
) {
2885 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2886 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2888 } else if (_mesa_is_gles(ctx
) &&
2889 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2890 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2891 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2892 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2897 /* From page 138 of OpenGL ES 3.0 spec:
2898 * "The error INVALID_OPERATION is generated if floating-point RGBA
2899 * data is required; if signed integer RGBA data is required and the
2900 * format of the current color buffer is not signed integer; if
2901 * unsigned integer RGBA data is required and the format of the
2902 * current color buffer is not unsigned integer; or if fixed-point
2903 * RGBA data is required and the format of the current color buffer
2904 * is not fixed-point.
2906 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2907 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2908 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2911 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2913 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2914 _mesa_error(ctx
, err
,
2915 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2918 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2919 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2920 "glCopyTexImage%dD(no compression for format)", dimensions
);
2924 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2925 "glCopyTexImage%dD(border!=0)", dimensions
);
2930 if (!mutable_tex_object(ctx
, target
)) {
2931 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2932 "glCopyTexImage%dD(immutable texture)", dimensions
);
2936 /* if we get here, the parameters are OK */
2942 * Test glCopyTexSubImage[12]D() parameters for errors.
2943 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2946 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2947 const struct gl_texture_object
*texObj
,
2948 GLenum target
, GLint level
,
2949 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2950 GLint width
, GLint height
, const char *caller
)
2952 struct gl_texture_image
*texImage
;
2954 /* Check that the source buffer is complete */
2955 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2956 if (ctx
->ReadBuffer
->_Status
== 0) {
2957 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2959 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2960 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2961 "%s(invalid readbuffer)", caller
);
2965 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2966 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2967 "%s(multisample FBO)", caller
);
2973 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2974 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2978 /* Get dest image pointers */
2980 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", caller
);
2984 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2986 /* destination image does not exist */
2987 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2988 "%s(invalid texture image)", caller
);
2992 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2993 xoffset
, yoffset
, zoffset
,
2994 width
, height
, 1, caller
)) {
2998 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2999 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
3000 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3001 "%s(no compression for format)", caller
);
3006 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
3007 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
3011 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
3012 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3013 "%s(missing readbuffer, format=0x%x)", caller
,
3014 texImage
->_BaseFormat
);
3018 /* From the EXT_texture_integer spec:
3020 * "INVALID_OPERATION is generated by CopyTexImage* and
3021 * CopyTexSubImage* if the texture internalformat is an integer format
3022 * and the read color buffer is not an integer format, or if the
3023 * internalformat is not an integer format and the read color buffer
3024 * is an integer format."
3026 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
3027 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
3029 if (_mesa_is_format_integer_color(rb
->Format
) !=
3030 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
3031 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3032 "%s(integer vs non-integer)", caller
);
3037 /* if we get here, the parameters are OK */
3042 /** Callback info for walking over FBO hash table */
3045 struct gl_context
*ctx
;
3046 struct gl_texture_object
*texObj
;
3052 * Check render to texture callback. Called from _mesa_HashWalk().
3055 check_rtt_cb(GLuint key
, void *data
, void *userData
)
3057 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
3058 const struct cb_info
*info
= (struct cb_info
*) userData
;
3059 struct gl_context
*ctx
= info
->ctx
;
3060 const struct gl_texture_object
*texObj
= info
->texObj
;
3061 const GLuint level
= info
->level
, face
= info
->face
;
3063 /* If this is a user-created FBO */
3064 if (_mesa_is_user_fbo(fb
)) {
3066 /* check if any of the FBO's attachments point to 'texObj' */
3067 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
3068 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
3069 if (att
->Type
== GL_TEXTURE
&&
3070 att
->Texture
== texObj
&&
3071 att
->TextureLevel
== level
&&
3072 att
->CubeMapFace
== face
) {
3073 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
3074 assert(att
->Renderbuffer
->TexImage
);
3075 /* Mark fb status as indeterminate to force re-validation */
3084 * When a texture image is specified we have to check if it's bound to
3085 * any framebuffer objects (render to texture) in order to detect changes
3086 * in size or format since that effects FBO completeness.
3087 * Any FBOs rendering into the texture must be re-validated.
3090 _mesa_update_fbo_texture(struct gl_context
*ctx
,
3091 struct gl_texture_object
*texObj
,
3092 GLuint face
, GLuint level
)
3094 /* Only check this texture if it's been marked as RenderToTexture */
3095 if (texObj
->_RenderToTexture
) {
3096 struct cb_info info
;
3098 info
.texObj
= texObj
;
3101 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
3107 * If the texture object's GenerateMipmap flag is set and we've
3108 * changed the texture base level image, regenerate the rest of the
3109 * mipmap levels now.
3112 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
3113 struct gl_texture_object
*texObj
, GLint level
)
3115 if (texObj
->GenerateMipmap
&&
3116 level
== texObj
->BaseLevel
&&
3117 level
< texObj
->MaxLevel
) {
3118 assert(ctx
->Driver
.GenerateMipmap
);
3119 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3124 /** Debug helper: override the user-requested internal format */
3126 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
3129 if (internalFormat
== GL_RGBA16F_ARB
||
3130 internalFormat
== GL_RGBA32F_ARB
) {
3131 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3134 else if (internalFormat
== GL_RGB16F_ARB
||
3135 internalFormat
== GL_RGB32F_ARB
) {
3136 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3139 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3140 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3141 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3142 return GL_LUMINANCE_ALPHA
;
3144 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3145 internalFormat
== GL_LUMINANCE32F_ARB
) {
3146 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3147 return GL_LUMINANCE
;
3149 else if (internalFormat
== GL_ALPHA16F_ARB
||
3150 internalFormat
== GL_ALPHA32F_ARB
) {
3151 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3155 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3156 internalFormat = GL_RGBA;
3160 return internalFormat
;
3163 return internalFormat
;
3169 * Choose the actual hardware format for a texture image.
3170 * Try to use the same format as the previous image level when possible.
3171 * Otherwise, ask the driver for the best format.
3172 * It's important to try to choose a consistant format for all levels
3173 * for efficient texture memory layout/allocation. In particular, this
3174 * comes up during automatic mipmap generation.
3177 _mesa_choose_texture_format(struct gl_context
*ctx
,
3178 struct gl_texture_object
*texObj
,
3179 GLenum target
, GLint level
,
3180 GLenum internalFormat
, GLenum format
, GLenum type
)
3184 /* see if we've already chosen a format for the previous level */
3186 struct gl_texture_image
*prevImage
=
3187 _mesa_select_tex_image(texObj
, target
, level
- 1);
3188 /* See if the prev level is defined and has an internal format which
3189 * matches the new internal format.
3192 prevImage
->Width
> 0 &&
3193 prevImage
->InternalFormat
== internalFormat
) {
3194 /* use the same format */
3195 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3196 return prevImage
->TexFormat
;
3200 /* If the application requested compression to an S3TC format but we don't
3201 * have the DXTn library, force a generic compressed format instead.
3203 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3204 const GLenum before
= internalFormat
;
3206 switch (internalFormat
) {
3207 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3208 if (!ctx
->Mesa_DXTn
)
3209 internalFormat
= GL_COMPRESSED_RGB
;
3211 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3212 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3213 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3214 if (!ctx
->Mesa_DXTn
)
3215 internalFormat
= GL_COMPRESSED_RGBA
;
3221 if (before
!= internalFormat
) {
3223 "DXT compression requested (%s), "
3224 "but libtxc_dxtn library not installed. Using %s "
3226 _mesa_enum_to_string(before
),
3227 _mesa_enum_to_string(internalFormat
));
3231 /* choose format from scratch */
3232 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3234 assert(f
!= MESA_FORMAT_NONE
);
3240 * Adjust pixel unpack params and image dimensions to strip off the
3241 * one-pixel texture border.
3243 * Gallium and intel don't support texture borders. They've seldem been used
3244 * and seldom been implemented correctly anyway.
3246 * \param unpackNew returns the new pixel unpack parameters
3249 strip_texture_border(GLenum target
,
3250 GLint
*width
, GLint
*height
, GLint
*depth
,
3251 const struct gl_pixelstore_attrib
*unpack
,
3252 struct gl_pixelstore_attrib
*unpackNew
)
3258 *unpackNew
= *unpack
;
3260 if (unpackNew
->RowLength
== 0)
3261 unpackNew
->RowLength
= *width
;
3263 if (unpackNew
->ImageHeight
== 0)
3264 unpackNew
->ImageHeight
= *height
;
3266 assert(*width
>= 3);
3267 unpackNew
->SkipPixels
++; /* skip the border */
3268 *width
= *width
- 2; /* reduce the width by two border pixels */
3270 /* The min height of a texture with a border is 3 */
3271 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3272 unpackNew
->SkipRows
++; /* skip the border */
3273 *height
= *height
- 2; /* reduce the height by two border pixels */
3277 target
!= GL_TEXTURE_2D_ARRAY
&&
3278 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3279 unpackNew
->SkipImages
++; /* skip the border */
3280 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3286 * Common code to implement all the glTexImage1D/2D/3D functions
3287 * as well as glCompressedTexImage1D/2D/3D.
3288 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3289 * \param format the user's image format (only used if !compressed)
3290 * \param type the user's image type (only used if !compressed)
3291 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3294 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3295 GLenum target
, GLint level
, GLint internalFormat
,
3296 GLsizei width
, GLsizei height
, GLsizei depth
,
3297 GLint border
, GLenum format
, GLenum type
,
3298 GLsizei imageSize
, const GLvoid
*pixels
)
3300 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3301 struct gl_pixelstore_attrib unpack_no_border
;
3302 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3303 struct gl_texture_object
*texObj
;
3304 mesa_format texFormat
;
3305 GLboolean dimensionsOK
, sizeOK
;
3307 FLUSH_VERTICES(ctx
, 0);
3309 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3312 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3314 _mesa_enum_to_string(target
), level
,
3315 _mesa_enum_to_string(internalFormat
),
3316 width
, height
, depth
, border
, pixels
);
3319 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3321 _mesa_enum_to_string(target
), level
,
3322 _mesa_enum_to_string(internalFormat
),
3323 width
, height
, depth
, border
,
3324 _mesa_enum_to_string(format
),
3325 _mesa_enum_to_string(type
), pixels
);
3328 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3330 /* target error checking */
3331 if (!legal_teximage_target(ctx
, dims
, target
)) {
3332 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3333 func
, dims
, _mesa_enum_to_string(target
));
3337 /* general error checking */
3339 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3341 width
, height
, depth
,
3342 border
, imageSize
, pixels
))
3346 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3347 format
, type
, width
, height
, depth
, border
,
3352 /* Here we convert a cpal compressed image into a regular glTexImage2D
3353 * call by decompressing the texture. If we really want to support cpal
3354 * textures in any driver this would have to be changed.
3356 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3357 switch (internalFormat
) {
3358 case GL_PALETTE4_RGB8_OES
:
3359 case GL_PALETTE4_RGBA8_OES
:
3360 case GL_PALETTE4_R5_G6_B5_OES
:
3361 case GL_PALETTE4_RGBA4_OES
:
3362 case GL_PALETTE4_RGB5_A1_OES
:
3363 case GL_PALETTE8_RGB8_OES
:
3364 case GL_PALETTE8_RGBA8_OES
:
3365 case GL_PALETTE8_R5_G6_B5_OES
:
3366 case GL_PALETTE8_RGBA4_OES
:
3367 case GL_PALETTE8_RGB5_A1_OES
:
3368 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3369 width
, height
, imageSize
, pixels
);
3374 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3378 /* For glCompressedTexImage() the driver has no choice about the
3379 * texture format since we'll never transcode the user's compressed
3380 * image data. The internalFormat was error checked earlier.
3382 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3385 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3386 * internal floating point format for the given base format.
3388 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3389 if (type
== GL_FLOAT
) {
3390 texObj
->_IsFloat
= GL_TRUE
;
3391 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3392 texObj
->_IsHalfFloat
= GL_TRUE
;
3395 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3398 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3399 internalFormat
, format
, type
);
3402 assert(texFormat
!= MESA_FORMAT_NONE
);
3404 /* check that width, height, depth are legal for the mipmap level */
3405 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3406 height
, depth
, border
);
3408 /* check that the texture won't take too much memory, etc */
3409 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3411 width
, height
, depth
, border
);
3413 if (_mesa_is_proxy_texture(target
)) {
3414 /* Proxy texture: just clear or set state depending on error checking */
3415 struct gl_texture_image
*texImage
=
3416 get_proxy_tex_image(ctx
, target
, level
);
3419 return; /* GL_OUT_OF_MEMORY already recorded */
3421 if (dimensionsOK
&& sizeOK
) {
3422 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3423 border
, internalFormat
, texFormat
);
3426 clear_teximage_fields(texImage
);
3430 /* non-proxy target */
3431 const GLuint face
= _mesa_tex_target_to_face(target
);
3432 struct gl_texture_image
*texImage
;
3434 if (!dimensionsOK
) {
3435 _mesa_error(ctx
, GL_INVALID_VALUE
,
3436 "%s%uD(invalid width or height or depth)",
3442 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3443 "%s%uD(image too large: %d x %d x %d, %s format)",
3444 func
, dims
, width
, height
, depth
,
3445 _mesa_enum_to_string(internalFormat
));
3449 /* Allow a hardware driver to just strip out the border, to provide
3450 * reliable but slightly incorrect hardware rendering instead of
3451 * rarely-tested software fallback rendering.
3453 if (border
&& ctx
->Const
.StripTextureBorder
) {
3454 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3457 unpack
= &unpack_no_border
;
3460 if (ctx
->NewState
& _NEW_PIXEL
)
3461 _mesa_update_state(ctx
);
3463 _mesa_lock_texture(ctx
, texObj
);
3465 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3468 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3471 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3473 _mesa_init_teximage_fields(ctx
, texImage
,
3474 width
, height
, depth
,
3475 border
, internalFormat
, texFormat
);
3477 /* Give the texture to the driver. <pixels> may be null. */
3478 if (width
> 0 && height
> 0 && depth
> 0) {
3480 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3484 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3485 type
, pixels
, unpack
);
3489 check_gen_mipmap(ctx
, target
, texObj
, level
);
3491 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3493 _mesa_dirty_texobj(ctx
, texObj
);
3496 _mesa_unlock_texture(ctx
, texObj
);
3503 * Called from the API. Note that width includes the border.
3506 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3507 GLsizei width
, GLint border
, GLenum format
,
3508 GLenum type
, const GLvoid
*pixels
)
3510 GET_CURRENT_CONTEXT(ctx
);
3511 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3512 border
, format
, type
, 0, pixels
);
3517 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3518 GLsizei width
, GLsizei height
, GLint border
,
3519 GLenum format
, GLenum type
,
3520 const GLvoid
*pixels
)
3522 GET_CURRENT_CONTEXT(ctx
);
3523 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3524 border
, format
, type
, 0, pixels
);
3529 * Called by the API or display list executor.
3530 * Note that width and height include the border.
3533 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3534 GLsizei width
, GLsizei height
, GLsizei depth
,
3535 GLint border
, GLenum format
, GLenum type
,
3536 const GLvoid
*pixels
)
3538 GET_CURRENT_CONTEXT(ctx
);
3539 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3540 width
, height
, depth
,
3541 border
, format
, type
, 0, pixels
);
3546 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3547 GLsizei width
, GLsizei height
, GLsizei depth
,
3548 GLint border
, GLenum format
, GLenum type
,
3549 const GLvoid
*pixels
)
3551 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3552 depth
, border
, format
, type
, pixels
);
3557 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3559 struct gl_texture_object
*texObj
;
3560 struct gl_texture_image
*texImage
;
3562 GET_CURRENT_CONTEXT(ctx
);
3563 FLUSH_VERTICES(ctx
, 0);
3567 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3569 case GL_TEXTURE_EXTERNAL_OES
:
3571 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3574 valid_target
= false;
3578 if (!valid_target
) {
3579 _mesa_error(ctx
, GL_INVALID_ENUM
,
3580 "glEGLImageTargetTexture2D(target=%d)", target
);
3585 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3586 "glEGLImageTargetTexture2D(image=%p)", image
);
3590 if (ctx
->NewState
& _NEW_PIXEL
)
3591 _mesa_update_state(ctx
);
3593 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3597 _mesa_lock_texture(ctx
, texObj
);
3599 if (texObj
->Immutable
) {
3600 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3601 "glEGLImageTargetTexture2D(texture is immutable)");
3602 _mesa_unlock_texture(ctx
, texObj
);
3606 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3608 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3610 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3612 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3613 texObj
, texImage
, image
);
3615 _mesa_dirty_texobj(ctx
, texObj
);
3617 _mesa_unlock_texture(ctx
, texObj
);
3622 * Helper that implements the glTexSubImage1/2/3D()
3623 * and glTextureSubImage1/2/3D() functions.
3626 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3627 struct gl_texture_object
*texObj
,
3628 struct gl_texture_image
*texImage
,
3629 GLenum target
, GLint level
,
3630 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3631 GLsizei width
, GLsizei height
, GLsizei depth
,
3632 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3635 FLUSH_VERTICES(ctx
, 0);
3637 if (ctx
->NewState
& _NEW_PIXEL
)
3638 _mesa_update_state(ctx
);
3640 _mesa_lock_texture(ctx
, texObj
);
3642 if (width
> 0 && height
> 0 && depth
> 0) {
3643 /* If we have a border, offset=-1 is legal. Bias by border width. */
3646 if (target
!= GL_TEXTURE_2D_ARRAY
)
3647 zoffset
+= texImage
->Border
;
3650 if (target
!= GL_TEXTURE_1D_ARRAY
)
3651 yoffset
+= texImage
->Border
;
3654 xoffset
+= texImage
->Border
;
3657 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3658 xoffset
, yoffset
, zoffset
,
3659 width
, height
, depth
,
3660 format
, type
, pixels
, &ctx
->Unpack
);
3662 check_gen_mipmap(ctx
, target
, texObj
, level
);
3664 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3665 * the texel data, not the texture format, size, etc.
3669 _mesa_unlock_texture(ctx
, texObj
);
3673 * Implement all the glTexSubImage1/2/3D() functions.
3674 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3677 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3678 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3679 GLsizei width
, GLsizei height
, GLsizei depth
,
3680 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3681 const char *callerName
)
3683 struct gl_texture_object
*texObj
;
3684 struct gl_texture_image
*texImage
;
3686 /* check target (proxies not allowed) */
3687 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3688 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3689 dims
, _mesa_enum_to_string(target
));
3693 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3697 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3698 xoffset
, yoffset
, zoffset
,
3699 width
, height
, depth
, format
, type
,
3700 pixels
, false, callerName
)) {
3701 return; /* error was detected */
3704 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3705 /* texsubimage_error_check ensures that texImage is not NULL */
3707 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3708 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3710 _mesa_enum_to_string(target
), level
,
3711 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3712 _mesa_enum_to_string(format
),
3713 _mesa_enum_to_string(type
), pixels
);
3715 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3716 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3717 format
, type
, pixels
, false);
3722 * Implement all the glTextureSubImage1/2/3D() functions.
3723 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3726 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3727 GLuint texture
, GLint level
,
3728 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3729 GLsizei width
, GLsizei height
, GLsizei depth
,
3730 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3731 const char *callerName
)
3733 struct gl_texture_object
*texObj
;
3734 struct gl_texture_image
*texImage
;
3737 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3739 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3740 dims
, texture
, level
,
3741 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3742 _mesa_enum_to_string(format
),
3743 _mesa_enum_to_string(type
), pixels
);
3745 /* Get the texture object by Name. */
3746 texObj
= _mesa_lookup_texture(ctx
, texture
);
3748 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3753 /* check target (proxies not allowed) */
3754 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3755 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3756 callerName
, _mesa_enum_to_string(texObj
->Target
));
3760 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3761 xoffset
, yoffset
, zoffset
,
3762 width
, height
, depth
, format
, type
,
3763 pixels
, true, callerName
)) {
3764 return; /* error was detected */
3768 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3769 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3773 * What do we do if the user created a texture with the following code
3774 * and then called this function with its handle?
3777 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3778 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3779 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3780 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3781 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3782 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3783 * // wrong format, or given the wrong size, etc.
3784 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3785 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3787 * A bug has been filed against the spec for this case. In the
3788 * meantime, we will check for cube completeness.
3790 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3791 * Core Profile spec (30.10.2014):
3792 * "[A] cube map texture is cube complete if the
3793 * following conditions all hold true: The [base level] texture
3794 * images of each of the six cube map faces have identical, positive,
3795 * and square dimensions. The [base level] images were each specified
3796 * with the same internal format."
3798 * It seems reasonable to check for cube completeness of an arbitrary
3799 * level here so that the image data has a consistent format and size.
3801 if (!_mesa_cube_level_complete(texObj
, level
)) {
3802 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3803 "glTextureSubImage%uD(cube map incomplete)",
3808 imageStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3810 /* Copy in each face. */
3811 for (i
= zoffset
; i
< zoffset
+ depth
; ++i
) {
3812 texImage
= texObj
->Image
[i
][level
];
3815 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3816 level
, xoffset
, yoffset
, 0,
3817 width
, height
, 1, format
,
3818 type
, pixels
, true);
3819 pixels
= (GLubyte
*) pixels
+ imageStride
;
3823 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3826 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3827 level
, xoffset
, yoffset
, zoffset
,
3828 width
, height
, depth
, format
,
3829 type
, pixels
, true);
3835 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3836 GLint xoffset
, GLsizei width
,
3837 GLenum format
, GLenum type
,
3838 const GLvoid
*pixels
)
3840 GET_CURRENT_CONTEXT(ctx
);
3841 texsubimage(ctx
, 1, target
, level
,
3844 format
, type
, pixels
, "glTexSubImage1D");
3849 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3850 GLint xoffset
, GLint yoffset
,
3851 GLsizei width
, GLsizei height
,
3852 GLenum format
, GLenum type
,
3853 const GLvoid
*pixels
)
3855 GET_CURRENT_CONTEXT(ctx
);
3856 texsubimage(ctx
, 2, target
, level
,
3857 xoffset
, yoffset
, 0,
3859 format
, type
, pixels
, "glTexSubImage2D");
3865 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3866 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3867 GLsizei width
, GLsizei height
, GLsizei depth
,
3868 GLenum format
, GLenum type
,
3869 const GLvoid
*pixels
)
3871 GET_CURRENT_CONTEXT(ctx
);
3872 texsubimage(ctx
, 3, target
, level
,
3873 xoffset
, yoffset
, zoffset
,
3874 width
, height
, depth
,
3875 format
, type
, pixels
, "glTexSubImage3D");
3879 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3880 GLint xoffset
, GLsizei width
,
3881 GLenum format
, GLenum type
,
3882 const GLvoid
*pixels
)
3884 GET_CURRENT_CONTEXT(ctx
);
3885 texturesubimage(ctx
, 1, texture
, level
,
3888 format
, type
, pixels
, "glTextureSubImage1D");
3893 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3894 GLint xoffset
, GLint yoffset
,
3895 GLsizei width
, GLsizei height
,
3896 GLenum format
, GLenum type
,
3897 const GLvoid
*pixels
)
3899 GET_CURRENT_CONTEXT(ctx
);
3900 texturesubimage(ctx
, 2, texture
, level
,
3901 xoffset
, yoffset
, 0,
3903 format
, type
, pixels
, "glTextureSubImage2D");
3908 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3909 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3910 GLsizei width
, GLsizei height
, GLsizei depth
,
3911 GLenum format
, GLenum type
,
3912 const GLvoid
*pixels
)
3914 GET_CURRENT_CONTEXT(ctx
);
3915 texturesubimage(ctx
, 3, texture
, level
,
3916 xoffset
, yoffset
, zoffset
,
3917 width
, height
, depth
,
3918 format
, type
, pixels
, "glTextureSubImage3D");
3923 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3924 * from. This depends on whether the texture contains color or depth values.
3926 static struct gl_renderbuffer
*
3927 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3929 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3930 /* reading from depth/stencil buffer */
3931 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3934 /* copying from color buffer */
3935 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3940 copytexsubimage_by_slice(struct gl_context
*ctx
,
3941 struct gl_texture_image
*texImage
,
3943 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3944 struct gl_renderbuffer
*rb
,
3946 GLsizei width
, GLsizei height
)
3948 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3951 /* For 1D arrays, we copy each scanline of the source rectangle into the
3954 assert(zoffset
== 0);
3956 for (slice
= 0; slice
< height
; slice
++) {
3957 assert(yoffset
+ slice
< texImage
->Height
);
3958 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3959 xoffset
, 0, yoffset
+ slice
,
3960 rb
, x
, y
+ slice
, width
, 1);
3963 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3964 xoffset
, yoffset
, zoffset
,
3965 rb
, x
, y
, width
, height
);
3970 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3972 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3973 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3974 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3975 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3977 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3978 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3979 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3980 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3982 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3983 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3984 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3985 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3992 * Implement the glCopyTexImage1/2D() functions.
3995 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3996 GLenum target
, GLint level
, GLenum internalFormat
,
3997 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3999 struct gl_texture_object
*texObj
;
4000 struct gl_texture_image
*texImage
;
4001 const GLuint face
= _mesa_tex_target_to_face(target
);
4002 mesa_format texFormat
;
4003 struct gl_renderbuffer
*rb
;
4005 FLUSH_VERTICES(ctx
, 0);
4007 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4008 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
4010 _mesa_enum_to_string(target
), level
,
4011 _mesa_enum_to_string(internalFormat
),
4012 x
, y
, width
, height
, border
);
4014 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4015 _mesa_update_state(ctx
);
4017 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
4018 width
, height
, border
))
4021 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
4023 _mesa_error(ctx
, GL_INVALID_VALUE
,
4024 "glCopyTexImage%uD(invalid width or height)", dims
);
4028 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4031 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
4032 internalFormat
, GL_NONE
, GL_NONE
);
4034 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
4036 if (_mesa_is_gles3(ctx
)) {
4037 if (_mesa_is_enum_format_unsized(internalFormat
)) {
4038 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
4039 * OpenGL ES 3.0. Khronos bug# 9807.
4041 if (rb
->InternalFormat
== GL_RGB10_A2
) {
4042 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4043 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
4044 " and writing to unsized internal format)", dims
);
4048 /* From Page 139 of OpenGL ES 3.0 spec:
4049 * "If internalformat is sized, the internal format of the new texel
4050 * array is internalformat, and this is also the new texel array’s
4051 * effective internal format. If the component sizes of internalformat
4052 * do not exactly match the corresponding component sizes of the source
4053 * buffer’s effective internal format, described below, an
4054 * INVALID_OPERATION error is generated. If internalformat is unsized,
4055 * the internal format of the new texel array is the effective internal
4056 * format of the source buffer, and this is also the new texel array’s
4057 * effective internal format.
4059 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
4060 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4061 "glCopyTexImage%uD(componenet size changed in"
4062 " internal format)", dims
);
4067 assert(texFormat
!= MESA_FORMAT_NONE
);
4069 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
4071 width
, height
, 1, border
)) {
4072 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4073 "glCopyTexImage%uD(image too large)", dims
);
4077 if (border
&& ctx
->Const
.StripTextureBorder
) {
4079 width
-= border
* 2;
4082 height
-= border
* 2;
4087 _mesa_lock_texture(ctx
, texObj
);
4089 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
4092 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
4095 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
4097 /* Free old texture image */
4098 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4100 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
4101 border
, internalFormat
, texFormat
);
4103 if (width
&& height
) {
4104 /* Allocate texture memory (no pixel data yet) */
4105 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
4107 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
4109 struct gl_renderbuffer
*srcRb
=
4110 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4112 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4114 srcRb
, srcX
, srcY
, width
, height
);
4117 check_gen_mipmap(ctx
, target
, texObj
, level
);
4120 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4122 _mesa_dirty_texobj(ctx
, texObj
);
4125 _mesa_unlock_texture(ctx
, texObj
);
4131 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4132 GLenum internalFormat
,
4134 GLsizei width
, GLint border
)
4136 GET_CURRENT_CONTEXT(ctx
);
4137 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4143 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4144 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4147 GET_CURRENT_CONTEXT(ctx
);
4148 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4149 x
, y
, width
, height
, border
);
4153 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4156 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4157 struct gl_texture_object
*texObj
,
4158 GLenum target
, GLint level
,
4159 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4161 GLsizei width
, GLsizei height
,
4164 struct gl_texture_image
*texImage
;
4166 FLUSH_VERTICES(ctx
, 0);
4168 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4169 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
4170 _mesa_enum_to_string(target
),
4171 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4173 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4174 _mesa_update_state(ctx
);
4176 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4177 xoffset
, yoffset
, zoffset
,
4178 width
, height
, caller
)) {
4182 _mesa_lock_texture(ctx
, texObj
);
4184 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4186 /* If we have a border, offset=-1 is legal. Bias by border width. */
4189 if (target
!= GL_TEXTURE_2D_ARRAY
)
4190 zoffset
+= texImage
->Border
;
4193 if (target
!= GL_TEXTURE_1D_ARRAY
)
4194 yoffset
+= texImage
->Border
;
4197 xoffset
+= texImage
->Border
;
4200 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4202 struct gl_renderbuffer
*srcRb
=
4203 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4205 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4206 xoffset
, yoffset
, zoffset
,
4207 srcRb
, x
, y
, width
, height
);
4209 check_gen_mipmap(ctx
, target
, texObj
, level
);
4211 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4212 * the texel data, not the texture format, size, etc.
4216 _mesa_unlock_texture(ctx
, texObj
);
4220 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4221 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4223 struct gl_texture_object
* texObj
;
4224 const char *self
= "glCopyTexSubImage1D";
4225 GET_CURRENT_CONTEXT(ctx
);
4227 /* Check target (proxies not allowed). Target must be checked prior to
4228 * calling _mesa_get_current_tex_object.
4230 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4231 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4232 _mesa_enum_to_string(target
));
4236 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4240 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4241 x
, y
, width
, 1, self
);
4247 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4248 GLint xoffset
, GLint yoffset
,
4249 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4251 struct gl_texture_object
* texObj
;
4252 const char *self
= "glCopyTexSubImage2D";
4253 GET_CURRENT_CONTEXT(ctx
);
4255 /* Check target (proxies not allowed). Target must be checked prior to
4256 * calling _mesa_get_current_tex_object.
4258 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4259 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4260 _mesa_enum_to_string(target
));
4264 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4268 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4269 xoffset
, yoffset
, 0,
4270 x
, y
, width
, height
, self
);
4276 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4277 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4278 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4280 struct gl_texture_object
* texObj
;
4281 const char *self
= "glCopyTexSubImage3D";
4282 GET_CURRENT_CONTEXT(ctx
);
4284 /* Check target (proxies not allowed). Target must be checked prior to
4285 * calling _mesa_get_current_tex_object.
4287 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4288 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4289 _mesa_enum_to_string(target
));
4293 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4297 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4298 xoffset
, yoffset
, zoffset
,
4299 x
, y
, width
, height
, self
);
4303 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4304 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4306 struct gl_texture_object
* texObj
;
4307 const char *self
= "glCopyTextureSubImage1D";
4308 GET_CURRENT_CONTEXT(ctx
);
4310 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4314 /* Check target (proxies not allowed). */
4315 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4316 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4317 _mesa_enum_to_string(texObj
->Target
));
4321 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4322 xoffset
, 0, 0, x
, y
, width
, 1, self
);
4326 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4327 GLint xoffset
, GLint yoffset
,
4328 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4330 struct gl_texture_object
* texObj
;
4331 const char *self
= "glCopyTextureSubImage2D";
4332 GET_CURRENT_CONTEXT(ctx
);
4334 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4338 /* Check target (proxies not allowed). */
4339 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4340 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4341 _mesa_enum_to_string(texObj
->Target
));
4345 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4346 xoffset
, yoffset
, 0,
4347 x
, y
, width
, height
, self
);
4353 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4354 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4355 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4357 struct gl_texture_object
* texObj
;
4358 const char *self
= "glCopyTextureSubImage3D";
4359 GET_CURRENT_CONTEXT(ctx
);
4361 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4365 /* Check target (proxies not allowed). */
4366 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4367 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4368 _mesa_enum_to_string(texObj
->Target
));
4372 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4373 /* Act like CopyTexSubImage2D */
4374 _mesa_copy_texture_sub_image(ctx
, 2, texObj
,
4375 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4376 level
, xoffset
, yoffset
, 0,
4377 x
, y
, width
, height
, self
);
4380 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4381 xoffset
, yoffset
, zoffset
,
4382 x
, y
, width
, height
, self
);
4386 check_clear_tex_image(struct gl_context
*ctx
,
4387 const char *function
,
4388 struct gl_texture_image
*texImage
,
4389 GLenum format
, GLenum type
,
4391 GLubyte
*clearValue
)
4393 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4394 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4395 GLenum internalFormat
= texImage
->InternalFormat
;
4398 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4399 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4400 "%s(buffer texture)", function
);
4404 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4405 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4406 "%s(compressed texture)", function
);
4410 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4411 if (err
!= GL_NO_ERROR
) {
4412 _mesa_error(ctx
, err
,
4413 "%s(incompatible format = %s, type = %s)",
4415 _mesa_enum_to_string(format
),
4416 _mesa_enum_to_string(type
));
4420 /* make sure internal format and format basically agree */
4421 if (!texture_formats_agree(internalFormat
, format
)) {
4422 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4423 "%s(incompatible internalFormat = %s, format = %s)",
4425 _mesa_enum_to_string(internalFormat
),
4426 _mesa_enum_to_string(format
));
4430 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4431 /* both source and dest must be integer-valued, or neither */
4432 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4433 _mesa_is_enum_format_integer(format
)) {
4434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4435 "%s(integer/non-integer format mismatch)",
4441 if (!_mesa_texstore(ctx
,
4443 texImage
->_BaseFormat
,
4444 texImage
->TexFormat
,
4445 0, /* dstRowStride */
4447 1, 1, 1, /* srcWidth/Height/Depth */
4449 data
? data
: zeroData
,
4450 &ctx
->DefaultPacking
)) {
4451 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4458 static struct gl_texture_object
*
4459 get_tex_obj_for_clear(struct gl_context
*ctx
,
4460 const char *function
,
4463 struct gl_texture_object
*texObj
;
4466 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4470 texObj
= _mesa_lookup_texture(ctx
, texture
);
4472 if (texObj
== NULL
) {
4473 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4477 if (texObj
->Target
== 0) {
4478 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4486 get_tex_images_for_clear(struct gl_context
*ctx
,
4487 const char *function
,
4488 struct gl_texture_object
*texObj
,
4490 struct gl_texture_image
**texImages
)
4495 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4496 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4500 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4501 for (i
= 0; i
< MAX_FACES
; i
++) {
4502 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4504 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4505 if (texImages
[i
] == NULL
) {
4506 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4507 "%s(invalid level)", function
);
4515 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4517 if (texImages
[0] == NULL
) {
4518 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4526 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4527 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4528 GLsizei width
, GLsizei height
, GLsizei depth
,
4529 GLenum format
, GLenum type
, const void *data
)
4531 GET_CURRENT_CONTEXT(ctx
);
4532 struct gl_texture_object
*texObj
;
4533 struct gl_texture_image
*texImages
[MAX_FACES
];
4534 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4536 int minDepth
, maxDepth
;
4538 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4543 _mesa_lock_texture(ctx
, texObj
);
4545 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4546 texObj
, level
, texImages
);
4550 if (numImages
== 1) {
4551 minDepth
= -(int) texImages
[0]->Border
;
4552 maxDepth
= texImages
[0]->Depth
;
4555 maxDepth
= numImages
;
4558 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4559 yoffset
< -(GLint
) texImages
[0]->Border
||
4560 zoffset
< minDepth
||
4564 xoffset
+ width
> texImages
[0]->Width
||
4565 yoffset
+ height
> texImages
[0]->Height
||
4566 zoffset
+ depth
> maxDepth
) {
4567 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4568 "glClearSubTexImage(invalid dimensions)");
4572 if (numImages
== 1) {
4573 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4575 format
, type
, data
, clearValue
[0])) {
4576 ctx
->Driver
.ClearTexSubImage(ctx
,
4578 xoffset
, yoffset
, zoffset
,
4579 width
, height
, depth
,
4580 data
? clearValue
[0] : NULL
);
4583 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4584 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4586 format
, type
, data
, clearValue
[i
]))
4589 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4590 ctx
->Driver
.ClearTexSubImage(ctx
,
4592 xoffset
, yoffset
, 0,
4594 data
? clearValue
[i
] : NULL
);
4599 _mesa_unlock_texture(ctx
, texObj
);
4603 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4604 GLenum format
, GLenum type
, const void *data
)
4606 GET_CURRENT_CONTEXT(ctx
);
4607 struct gl_texture_object
*texObj
;
4608 struct gl_texture_image
*texImages
[MAX_FACES
];
4609 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4612 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4617 _mesa_lock_texture(ctx
, texObj
);
4619 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4620 texObj
, level
, texImages
);
4622 for (i
= 0; i
< numImages
; i
++) {
4623 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4630 for (i
= 0; i
< numImages
; i
++) {
4631 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4632 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4633 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4634 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4635 texImages
[i
]->Width
,
4636 texImages
[i
]->Height
,
4637 texImages
[i
]->Depth
,
4638 data
? clearValue
[i
] : NULL
);
4642 _mesa_unlock_texture(ctx
, texObj
);
4648 /**********************************************************************/
4649 /****** Compressed Textures ******/
4650 /**********************************************************************/
4654 * Target checking for glCompressedTexSubImage[123]D().
4655 * \return GL_TRUE if error, GL_FALSE if no error
4656 * Must come before other error checking so that the texture object can
4657 * be correctly retrieved using _mesa_get_current_tex_object.
4660 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4661 GLint dims
, GLenum format
, bool dsa
,
4666 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4667 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4668 _mesa_enum_to_string(target
));
4678 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4679 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4680 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4681 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4682 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4683 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4684 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4687 targetOK
= GL_FALSE
;
4693 case GL_TEXTURE_CUBE_MAP
:
4694 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4696 case GL_TEXTURE_2D_ARRAY
:
4697 targetOK
= _mesa_is_gles3(ctx
) ||
4698 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4700 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4701 targetOK
= ctx
->Extensions
.ARB_texture_cube_map_array
;
4706 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4708 * "An INVALID_OPERATION error is generated by
4709 * CompressedTex*SubImage3D if the internal format of the texture
4710 * is one of the EAC, ETC2, or RGTC formats and either border is
4711 * non-zero, or the effective target for the texture is not
4712 * TEXTURE_2D_ARRAY."
4714 * NOTE: that's probably a spec error. It should probably say
4715 * "... or the effective target for the texture is not
4716 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4717 * GL_TEXTURE_CUBE_MAP_ARRAY."
4718 * since those targets are 2D images and they support all compression
4721 * Instead of listing all these, just list those which are allowed,
4722 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4723 * more) are valid here, which they are not, but of course not
4724 * mentioned by core spec.
4727 /* These are the only 3D compression formats supported at this time */
4728 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
4729 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
4730 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
4731 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
4735 /* invalid format */
4736 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4737 "%s(invalid target %s for format %s)", caller
,
4738 _mesa_enum_to_string(target
),
4739 _mesa_enum_to_string(format
));
4744 targetOK
= GL_FALSE
;
4750 /* no 1D compressed textures at this time */
4751 targetOK
= GL_FALSE
;
4756 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4757 _mesa_enum_to_string(target
));
4765 * Error checking for glCompressedTexSubImage[123]D().
4766 * \return GL_TRUE if error, GL_FALSE if no error
4769 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4770 const struct gl_texture_object
*texObj
,
4771 GLenum target
, GLint level
,
4772 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4773 GLsizei width
, GLsizei height
, GLsizei depth
,
4774 GLenum format
, GLsizei imageSize
,
4775 const GLvoid
*data
, const char *callerName
)
4777 struct gl_texture_image
*texImage
;
4780 /* this will catch any invalid compressed format token */
4781 if (!_mesa_is_compressed_format(ctx
, format
)) {
4782 _mesa_error(ctx
, GL_INVALID_ENUM
,
4783 "%s(format)", callerName
);
4787 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4788 _mesa_error(ctx
, GL_INVALID_VALUE
,
4794 /* validate the bound PBO, if any */
4795 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4796 imageSize
, data
, callerName
)) {
4800 /* Check for invalid pixel storage modes */
4801 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4802 &ctx
->Unpack
, callerName
)) {
4806 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4807 if (expectedSize
!= imageSize
) {
4808 _mesa_error(ctx
, GL_INVALID_VALUE
,
4810 callerName
, imageSize
);
4814 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4816 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4817 "%s(invalid texture image)",
4822 if ((GLint
) format
!= texImage
->InternalFormat
) {
4823 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4825 callerName
, format
);
4829 if (compressedteximage_only_format(ctx
, format
)) {
4830 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4831 "%s(format=0x%x cannot be updated)",
4832 callerName
, format
);
4836 if (error_check_subtexture_dimensions(ctx
, dims
,
4837 texImage
, xoffset
, yoffset
, zoffset
,
4838 width
, height
, depth
,
4848 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4849 GLenum internalFormat
, GLsizei width
,
4850 GLint border
, GLsizei imageSize
,
4853 GET_CURRENT_CONTEXT(ctx
);
4854 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4855 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4860 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4861 GLenum internalFormat
, GLsizei width
,
4862 GLsizei height
, GLint border
, GLsizei imageSize
,
4865 GET_CURRENT_CONTEXT(ctx
);
4866 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4867 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4872 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4873 GLenum internalFormat
, GLsizei width
,
4874 GLsizei height
, GLsizei depth
, GLint border
,
4875 GLsizei imageSize
, const GLvoid
*data
)
4877 GET_CURRENT_CONTEXT(ctx
);
4878 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4879 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4884 * Common helper for glCompressedTexSubImage1/2/3D() and
4885 * glCompressedTextureSubImage1/2/3D().
4888 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4889 struct gl_texture_object
*texObj
,
4890 struct gl_texture_image
*texImage
,
4891 GLenum target
, GLint level
,
4892 GLint xoffset
, GLint yoffset
,
4894 GLsizei width
, GLsizei height
,
4896 GLenum format
, GLsizei imageSize
,
4899 FLUSH_VERTICES(ctx
, 0);
4901 _mesa_lock_texture(ctx
, texObj
);
4903 if (width
> 0 && height
> 0 && depth
> 0) {
4904 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4905 xoffset
, yoffset
, zoffset
,
4906 width
, height
, depth
,
4907 format
, imageSize
, data
);
4909 check_gen_mipmap(ctx
, target
, texObj
, level
);
4911 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4912 * the texel data, not the texture format, size, etc.
4916 _mesa_unlock_texture(ctx
, texObj
);
4921 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4922 GLsizei width
, GLenum format
,
4923 GLsizei imageSize
, const GLvoid
*data
)
4925 struct gl_texture_object
*texObj
;
4926 struct gl_texture_image
*texImage
;
4928 GET_CURRENT_CONTEXT(ctx
);
4930 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4931 "glCompressedTexSubImage1D")) {
4935 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4939 if (compressed_subtexture_error_check(ctx
, 1, texObj
, target
,
4940 level
, xoffset
, 0, 0,
4942 format
, imageSize
, data
,
4943 "glCompressedTexSubImage1D")) {
4947 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4950 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
4951 xoffset
, 0, 0, width
, 1, 1,
4952 format
, imageSize
, data
);
4956 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4957 GLsizei width
, GLenum format
,
4958 GLsizei imageSize
, const GLvoid
*data
)
4960 struct gl_texture_object
*texObj
;
4961 struct gl_texture_image
*texImage
;
4963 GET_CURRENT_CONTEXT(ctx
);
4965 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4966 "glCompressedTextureSubImage1D");
4970 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
, true,
4971 "glCompressedTextureSubImage1D")) {
4975 if (compressed_subtexture_error_check(ctx
, 1, texObj
, texObj
->Target
,
4976 level
, xoffset
, 0, 0,
4978 format
, imageSize
, data
,
4979 "glCompressedTextureSubImage1D")) {
4983 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4986 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
,
4987 texObj
->Target
, level
,
4988 xoffset
, 0, 0, width
, 1, 1,
4989 format
, imageSize
, data
);
4994 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4995 GLint yoffset
, GLsizei width
, GLsizei height
,
4996 GLenum format
, GLsizei imageSize
,
4999 struct gl_texture_object
*texObj
;
5000 struct gl_texture_image
*texImage
;
5002 GET_CURRENT_CONTEXT(ctx
);
5004 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
5005 "glCompressedTexSubImage2D")) {
5009 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5013 if (compressed_subtexture_error_check(ctx
, 2, texObj
, target
,
5014 level
, xoffset
, yoffset
, 0,
5016 format
, imageSize
, data
,
5017 "glCompressedTexSubImage2D")) {
5022 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5025 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
5026 xoffset
, yoffset
, 0, width
, height
, 1,
5027 format
, imageSize
, data
);
5031 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
5033 GLsizei width
, GLsizei height
,
5034 GLenum format
, GLsizei imageSize
,
5037 struct gl_texture_object
*texObj
;
5038 struct gl_texture_image
*texImage
;
5040 GET_CURRENT_CONTEXT(ctx
);
5042 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5043 "glCompressedTextureSubImage2D");
5047 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
, true,
5048 "glCompressedTextureSubImage2D")) {
5052 if (compressed_subtexture_error_check(ctx
, 2, texObj
, texObj
->Target
,
5053 level
, xoffset
, yoffset
, 0,
5055 format
, imageSize
, data
,
5056 "glCompressedTextureSubImage2D")) {
5060 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5063 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
,
5064 texObj
->Target
, level
,
5065 xoffset
, yoffset
, 0, width
, height
, 1,
5066 format
, imageSize
, data
);
5070 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
5071 GLint yoffset
, GLint zoffset
, GLsizei width
,
5072 GLsizei height
, GLsizei depth
, GLenum format
,
5073 GLsizei imageSize
, const GLvoid
*data
)
5075 struct gl_texture_object
*texObj
;
5076 struct gl_texture_image
*texImage
;
5078 GET_CURRENT_CONTEXT(ctx
);
5080 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
5081 "glCompressedTexSubImage3D")) {
5085 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5089 if (compressed_subtexture_error_check(ctx
, 3, texObj
, target
,
5090 level
, xoffset
, yoffset
, zoffset
,
5091 width
, height
, depth
,
5092 format
, imageSize
, data
,
5093 "glCompressedTexSubImage3D")) {
5098 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5101 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
5102 xoffset
, yoffset
, zoffset
,
5103 width
, height
, depth
,
5104 format
, imageSize
, data
);
5108 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
5109 GLint yoffset
, GLint zoffset
, GLsizei width
,
5110 GLsizei height
, GLsizei depth
,
5111 GLenum format
, GLsizei imageSize
,
5114 struct gl_texture_object
*texObj
;
5115 struct gl_texture_image
*texImage
;
5117 GET_CURRENT_CONTEXT(ctx
);
5119 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5120 "glCompressedTextureSubImage3D");
5124 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
, true,
5125 "glCompressedTextureSubImage3D")) {
5129 if (compressed_subtexture_error_check(ctx
, 3, texObj
, texObj
->Target
,
5130 level
, xoffset
, yoffset
, zoffset
,
5131 width
, height
, depth
,
5132 format
, imageSize
, data
,
5133 "glCompressedTextureSubImage3D")) {
5137 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
5138 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5139 const char *pixels
= data
;
5143 /* Make sure the texture object is a proper cube.
5144 * (See texturesubimage in teximage.c for details on why this check is
5147 if (!_mesa_cube_level_complete(texObj
, level
)) {
5148 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5149 "glCompressedTextureSubImage3D(cube map incomplete)");
5153 /* Copy in each face. */
5154 for (i
= 0; i
< 6; ++i
) {
5155 texImage
= texObj
->Image
[i
][level
];
5158 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5159 texObj
->Target
, level
,
5160 xoffset
, yoffset
, zoffset
,
5162 format
, imageSize
, pixels
);
5164 /* Compressed images don't have a client format */
5165 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5167 texImage
->Height
, 1);
5169 pixels
+= image_stride
;
5170 imageSize
-= image_stride
;
5174 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5177 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5178 texObj
->Target
, level
,
5179 xoffset
, yoffset
, zoffset
,
5180 width
, height
, depth
,
5181 format
, imageSize
, data
);
5186 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5188 if (ctx
->API
!= API_OPENGL_CORE
) {
5189 switch (internalFormat
) {
5191 return MESA_FORMAT_A_UNORM8
;
5193 return MESA_FORMAT_A_UNORM16
;
5194 case GL_ALPHA16F_ARB
:
5195 return MESA_FORMAT_A_FLOAT16
;
5196 case GL_ALPHA32F_ARB
:
5197 return MESA_FORMAT_A_FLOAT32
;
5198 case GL_ALPHA8I_EXT
:
5199 return MESA_FORMAT_A_SINT8
;
5200 case GL_ALPHA16I_EXT
:
5201 return MESA_FORMAT_A_SINT16
;
5202 case GL_ALPHA32I_EXT
:
5203 return MESA_FORMAT_A_SINT32
;
5204 case GL_ALPHA8UI_EXT
:
5205 return MESA_FORMAT_A_UINT8
;
5206 case GL_ALPHA16UI_EXT
:
5207 return MESA_FORMAT_A_UINT16
;
5208 case GL_ALPHA32UI_EXT
:
5209 return MESA_FORMAT_A_UINT32
;
5211 return MESA_FORMAT_L_UNORM8
;
5212 case GL_LUMINANCE16
:
5213 return MESA_FORMAT_L_UNORM16
;
5214 case GL_LUMINANCE16F_ARB
:
5215 return MESA_FORMAT_L_FLOAT16
;
5216 case GL_LUMINANCE32F_ARB
:
5217 return MESA_FORMAT_L_FLOAT32
;
5218 case GL_LUMINANCE8I_EXT
:
5219 return MESA_FORMAT_L_SINT8
;
5220 case GL_LUMINANCE16I_EXT
:
5221 return MESA_FORMAT_L_SINT16
;
5222 case GL_LUMINANCE32I_EXT
:
5223 return MESA_FORMAT_L_SINT32
;
5224 case GL_LUMINANCE8UI_EXT
:
5225 return MESA_FORMAT_L_UINT8
;
5226 case GL_LUMINANCE16UI_EXT
:
5227 return MESA_FORMAT_L_UINT16
;
5228 case GL_LUMINANCE32UI_EXT
:
5229 return MESA_FORMAT_L_UINT32
;
5230 case GL_LUMINANCE8_ALPHA8
:
5231 return MESA_FORMAT_L8A8_UNORM
;
5232 case GL_LUMINANCE16_ALPHA16
:
5233 return MESA_FORMAT_L16A16_UNORM
;
5234 case GL_LUMINANCE_ALPHA16F_ARB
:
5235 return MESA_FORMAT_LA_FLOAT16
;
5236 case GL_LUMINANCE_ALPHA32F_ARB
:
5237 return MESA_FORMAT_LA_FLOAT32
;
5238 case GL_LUMINANCE_ALPHA8I_EXT
:
5239 return MESA_FORMAT_LA_SINT8
;
5240 case GL_LUMINANCE_ALPHA16I_EXT
:
5241 return MESA_FORMAT_LA_SINT16
;
5242 case GL_LUMINANCE_ALPHA32I_EXT
:
5243 return MESA_FORMAT_LA_SINT32
;
5244 case GL_LUMINANCE_ALPHA8UI_EXT
:
5245 return MESA_FORMAT_LA_UINT8
;
5246 case GL_LUMINANCE_ALPHA16UI_EXT
:
5247 return MESA_FORMAT_LA_UINT16
;
5248 case GL_LUMINANCE_ALPHA32UI_EXT
:
5249 return MESA_FORMAT_LA_UINT32
;
5251 return MESA_FORMAT_I_UNORM8
;
5252 case GL_INTENSITY16
:
5253 return MESA_FORMAT_I_UNORM16
;
5254 case GL_INTENSITY16F_ARB
:
5255 return MESA_FORMAT_I_FLOAT16
;
5256 case GL_INTENSITY32F_ARB
:
5257 return MESA_FORMAT_I_FLOAT32
;
5258 case GL_INTENSITY8I_EXT
:
5259 return MESA_FORMAT_I_SINT8
;
5260 case GL_INTENSITY16I_EXT
:
5261 return MESA_FORMAT_I_SINT16
;
5262 case GL_INTENSITY32I_EXT
:
5263 return MESA_FORMAT_I_SINT32
;
5264 case GL_INTENSITY8UI_EXT
:
5265 return MESA_FORMAT_I_UINT8
;
5266 case GL_INTENSITY16UI_EXT
:
5267 return MESA_FORMAT_I_UINT16
;
5268 case GL_INTENSITY32UI_EXT
:
5269 return MESA_FORMAT_I_UINT32
;
5275 if (ctx
->API
== API_OPENGL_CORE
&&
5276 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5277 switch (internalFormat
) {
5279 return MESA_FORMAT_RGB_FLOAT32
;
5281 return MESA_FORMAT_RGB_UINT32
;
5283 return MESA_FORMAT_RGB_SINT32
;
5289 switch (internalFormat
) {
5291 return MESA_FORMAT_R8G8B8A8_UNORM
;
5293 return MESA_FORMAT_RGBA_UNORM16
;
5294 case GL_RGBA16F_ARB
:
5295 return MESA_FORMAT_RGBA_FLOAT16
;
5296 case GL_RGBA32F_ARB
:
5297 return MESA_FORMAT_RGBA_FLOAT32
;
5299 return MESA_FORMAT_RGBA_SINT8
;
5300 case GL_RGBA16I_EXT
:
5301 return MESA_FORMAT_RGBA_SINT16
;
5302 case GL_RGBA32I_EXT
:
5303 return MESA_FORMAT_RGBA_SINT32
;
5304 case GL_RGBA8UI_EXT
:
5305 return MESA_FORMAT_RGBA_UINT8
;
5306 case GL_RGBA16UI_EXT
:
5307 return MESA_FORMAT_RGBA_UINT16
;
5308 case GL_RGBA32UI_EXT
:
5309 return MESA_FORMAT_RGBA_UINT32
;
5312 return MESA_FORMAT_R8G8_UNORM
;
5314 return MESA_FORMAT_R16G16_UNORM
;
5316 return MESA_FORMAT_RG_FLOAT16
;
5318 return MESA_FORMAT_RG_FLOAT32
;
5320 return MESA_FORMAT_RG_SINT8
;
5322 return MESA_FORMAT_RG_SINT16
;
5324 return MESA_FORMAT_RG_SINT32
;
5326 return MESA_FORMAT_RG_UINT8
;
5328 return MESA_FORMAT_RG_UINT16
;
5330 return MESA_FORMAT_RG_UINT32
;
5333 return MESA_FORMAT_R_UNORM8
;
5335 return MESA_FORMAT_R_UNORM16
;
5337 return MESA_FORMAT_R_FLOAT16
;
5339 return MESA_FORMAT_R_FLOAT32
;
5341 return MESA_FORMAT_R_SINT8
;
5343 return MESA_FORMAT_R_SINT16
;
5345 return MESA_FORMAT_R_SINT32
;
5347 return MESA_FORMAT_R_UINT8
;
5349 return MESA_FORMAT_R_UINT16
;
5351 return MESA_FORMAT_R_UINT32
;
5354 return MESA_FORMAT_NONE
;
5360 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5361 GLenum internalFormat
)
5363 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5366 if (format
== MESA_FORMAT_NONE
)
5367 return MESA_FORMAT_NONE
;
5369 datatype
= _mesa_get_format_datatype(format
);
5371 /* The GL_ARB_texture_buffer_object spec says:
5373 * "If ARB_texture_float is not supported, references to the
5374 * floating-point internal formats provided by that extension should be
5375 * removed, and such formats may not be passed to TexBufferARB."
5377 * As a result, GL_HALF_FLOAT internal format depends on both
5378 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5380 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5381 !ctx
->Extensions
.ARB_texture_float
)
5382 return MESA_FORMAT_NONE
;
5384 if (!ctx
->Extensions
.ARB_texture_rg
) {
5385 GLenum base_format
= _mesa_get_format_base_format(format
);
5386 if (base_format
== GL_R
|| base_format
== GL_RG
)
5387 return MESA_FORMAT_NONE
;
5390 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5391 GLenum base_format
= _mesa_get_format_base_format(format
);
5392 if (base_format
== GL_RGB
)
5393 return MESA_FORMAT_NONE
;
5400 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5401 struct gl_texture_object
*texObj
,
5402 GLenum internalFormat
,
5403 struct gl_buffer_object
*bufObj
,
5404 GLintptr offset
, GLsizeiptr size
,
5409 /* NOTE: ARB_texture_buffer_object has interactions with
5410 * the compatibility profile that are not implemented.
5412 if (!(ctx
->API
== API_OPENGL_CORE
&&
5413 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5414 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5415 "%s(ARB_texture_buffer_object is not"
5416 " implemented for the compatibility profile)", caller
);
5420 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5421 if (format
== MESA_FORMAT_NONE
) {
5422 _mesa_error(ctx
, GL_INVALID_ENUM
,
5423 "%s(internalFormat 0x%x)", caller
, internalFormat
);
5427 FLUSH_VERTICES(ctx
, 0);
5429 _mesa_lock_texture(ctx
, texObj
);
5431 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5432 texObj
->BufferObjectFormat
= internalFormat
;
5433 texObj
->_BufferObjectFormat
= format
;
5434 texObj
->BufferOffset
= offset
;
5435 texObj
->BufferSize
= size
;
5437 _mesa_unlock_texture(ctx
, texObj
);
5439 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5442 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5448 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5449 * Return true if it is, and return false if it is not
5450 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5451 * core spec, 02.02.2015, PDF page 245).
5454 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5457 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5458 _mesa_error(ctx
, GL_INVALID_ENUM
,
5459 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5467 * Check for errors related to the texture buffer range.
5468 * Return false if errors are found, true if none are found.
5471 check_texture_buffer_range(struct gl_context
*ctx
,
5472 struct gl_buffer_object
*bufObj
,
5473 GLintptr offset
, GLsizeiptr size
,
5476 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5477 * Textures (PDF page 245):
5478 * "An INVALID_VALUE error is generated if offset is negative, if
5479 * size is less than or equal to zero, or if offset + size is greater
5480 * than the value of BUFFER_SIZE for the buffer bound to target."
5483 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5489 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5494 if (offset
+ size
> bufObj
->Size
) {
5495 _mesa_error(ctx
, GL_INVALID_VALUE
,
5496 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5497 (int) offset
, (int) size
, (int) bufObj
->Size
);
5501 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5502 * Textures (PDF page 245):
5503 * "An INVALID_VALUE error is generated if offset is not an integer
5504 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5506 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5507 _mesa_error(ctx
, GL_INVALID_VALUE
,
5508 "%s(invalid offset alignment)", caller
);
5516 /** GL_ARB_texture_buffer_object */
5518 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5520 struct gl_texture_object
*texObj
;
5521 struct gl_buffer_object
*bufObj
;
5523 GET_CURRENT_CONTEXT(ctx
);
5525 /* Need to catch a bad target before it gets to
5526 * _mesa_get_current_tex_object.
5528 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5532 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5538 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5542 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5543 buffer
? -1 : 0, "glTexBuffer");
5547 /** GL_ARB_texture_buffer_range */
5549 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5550 GLintptr offset
, GLsizeiptr size
)
5552 struct gl_texture_object
*texObj
;
5553 struct gl_buffer_object
*bufObj
;
5555 GET_CURRENT_CONTEXT(ctx
);
5557 /* Need to catch a bad target before it gets to
5558 * _mesa_get_current_tex_object.
5560 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5564 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5568 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5569 "glTexBufferRange"))
5573 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5574 * Textures (PDF page 254):
5575 * "If buffer is zero, then any buffer object attached to the buffer
5576 * texture is detached, the values offset and size are ignored and
5577 * the state for offset and size for the buffer texture are reset to
5585 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5589 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5590 offset
, size
, "glTexBufferRange");
5594 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5596 struct gl_texture_object
*texObj
;
5597 struct gl_buffer_object
*bufObj
;
5599 GET_CURRENT_CONTEXT(ctx
);
5602 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5608 /* Get the texture object by Name. */
5609 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5613 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5616 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5617 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5621 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5622 GLintptr offset
, GLsizeiptr size
)
5624 struct gl_texture_object
*texObj
;
5625 struct gl_buffer_object
*bufObj
;
5627 GET_CURRENT_CONTEXT(ctx
);
5630 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5631 "glTextureBufferRange");
5635 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5636 "glTextureBufferRange"))
5640 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5641 * Textures (PDF page 254):
5642 * "If buffer is zero, then any buffer object attached to the buffer
5643 * texture is detached, the values offset and size are ignored and
5644 * the state for offset and size for the buffer texture are reset to
5652 /* Get the texture object by Name. */
5653 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5657 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5658 "glTextureBufferRange"))
5661 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5662 bufObj
, offset
, size
, "glTextureBufferRange");
5666 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5668 /* Everything that is allowed for renderbuffers,
5669 * except for a base format of GL_STENCIL_INDEX, unless supported.
5671 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5672 if (ctx
->Extensions
.ARB_texture_stencil8
)
5673 return baseFormat
!= 0;
5675 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5679 /** GL_ARB_texture_multisample */
5681 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5684 case GL_TEXTURE_2D_MULTISAMPLE
:
5686 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5687 return dims
== 2 && !dsa
;
5688 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5690 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5691 return dims
== 3 && !dsa
;
5699 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5700 struct gl_texture_object
*texObj
,
5701 GLenum target
, GLsizei samples
,
5702 GLint internalformat
, GLsizei width
,
5703 GLsizei height
, GLsizei depth
,
5704 GLboolean fixedsamplelocations
,
5705 GLboolean immutable
, const char *func
)
5707 struct gl_texture_image
*texImage
;
5708 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5709 mesa_format texFormat
;
5710 GLenum sample_count_error
;
5711 bool dsa
= strstr(func
, "ture") ? true : false;
5713 if (!((ctx
->Extensions
.ARB_texture_multisample
5714 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5715 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5720 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5724 if (!check_multisample_target(dims
, target
, dsa
)) {
5726 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5730 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5735 /* check that the specified internalformat is color/depth/stencil-renderable;
5736 * refer GL3.1 spec 4.4.4
5739 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5740 _mesa_error(ctx
, GL_INVALID_ENUM
,
5741 "%s(internalformat=%s not legal for immutable-format)",
5742 func
, _mesa_enum_to_string(internalformat
));
5746 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5747 /* Page 172 of OpenGL ES 3.1 spec says:
5748 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5749 * color-renderable, depth-renderable, or stencil-renderable (as
5750 * defined in section 9.4).
5752 * (Same error is also defined for desktop OpenGL for multisample
5753 * teximage/texstorage functions.)
5755 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5756 _mesa_enum_to_string(internalformat
));
5760 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5761 internalformat
, samples
);
5762 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5764 /* Page 254 of OpenGL 4.4 spec says:
5765 * "Proxy arrays for two-dimensional multisample and two-dimensional
5766 * multisample array textures are operated on in the same way when
5767 * TexImage2DMultisample is called with target specified as
5768 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5769 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5770 * However, if samples is not supported, then no error is generated.
5772 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5773 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5777 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5778 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5779 "%s(texture object 0)",
5784 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5786 if (texImage
== NULL
) {
5787 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5791 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5792 internalformat
, GL_NONE
, GL_NONE
);
5793 assert(texFormat
!= MESA_FORMAT_NONE
);
5795 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5796 width
, height
, depth
, 0);
5798 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5799 width
, height
, depth
, 0);
5801 if (_mesa_is_proxy_texture(target
)) {
5802 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5803 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5804 internalformat
, texFormat
,
5805 samples
, fixedsamplelocations
);
5808 /* clear all image fields */
5809 clear_teximage_fields(texImage
);
5813 if (!dimensionsOK
) {
5814 _mesa_error(ctx
, GL_INVALID_VALUE
,
5815 "%s(invalid width or height)", func
);
5820 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5824 /* Check if texObj->Immutable is set */
5825 if (texObj
->Immutable
) {
5826 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5830 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5832 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5833 internalformat
, texFormat
,
5834 samples
, fixedsamplelocations
);
5836 if (width
> 0 && height
> 0 && depth
> 0) {
5837 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5838 width
, height
, depth
)) {
5839 /* tidy up the texture image state. strictly speaking,
5840 * we're allowed to just leave this in whatever state we
5841 * like, but being tidy is good.
5843 _mesa_init_teximage_fields(ctx
, texImage
,
5844 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5848 texObj
->Immutable
|= immutable
;
5851 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5854 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5860 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5861 GLenum internalformat
, GLsizei width
,
5862 GLsizei height
, GLboolean fixedsamplelocations
)
5864 struct gl_texture_object
*texObj
;
5865 GET_CURRENT_CONTEXT(ctx
);
5867 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5871 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5872 internalformat
, width
, height
, 1,
5873 fixedsamplelocations
, GL_FALSE
,
5874 "glTexImage2DMultisample");
5879 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5880 GLenum internalformat
, GLsizei width
,
5881 GLsizei height
, GLsizei depth
,
5882 GLboolean fixedsamplelocations
)
5884 struct gl_texture_object
*texObj
;
5885 GET_CURRENT_CONTEXT(ctx
);
5887 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5891 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5892 internalformat
, width
, height
, depth
,
5893 fixedsamplelocations
, GL_FALSE
,
5894 "glTexImage3DMultisample");
5898 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
5899 GLsizei samples
, unsigned dims
)
5901 GET_CURRENT_CONTEXT(ctx
);
5903 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
5904 _mesa_error(ctx
, GL_INVALID_VALUE
,
5905 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
5906 dims
, width
, height
, depth
);
5913 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5914 GLenum internalformat
, GLsizei width
,
5915 GLsizei height
, GLboolean fixedsamplelocations
)
5917 struct gl_texture_object
*texObj
;
5918 GET_CURRENT_CONTEXT(ctx
);
5920 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5924 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5927 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5928 internalformat
, width
, height
, 1,
5929 fixedsamplelocations
, GL_TRUE
,
5930 "glTexStorage2DMultisample");
5934 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5935 GLenum internalformat
, GLsizei width
,
5936 GLsizei height
, GLsizei depth
,
5937 GLboolean fixedsamplelocations
)
5939 struct gl_texture_object
*texObj
;
5940 GET_CURRENT_CONTEXT(ctx
);
5942 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5946 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5949 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5950 internalformat
, width
, height
, depth
,
5951 fixedsamplelocations
, GL_TRUE
,
5952 "glTexStorage3DMultisample");
5956 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5957 GLenum internalformat
, GLsizei width
,
5959 GLboolean fixedsamplelocations
)
5961 struct gl_texture_object
*texObj
;
5962 GET_CURRENT_CONTEXT(ctx
);
5964 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5965 "glTextureStorage2DMultisample");
5969 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5972 texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5973 internalformat
, width
, height
, 1,
5974 fixedsamplelocations
, GL_TRUE
,
5975 "glTextureStorage2DMultisample");
5979 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5980 GLenum internalformat
, GLsizei width
,
5981 GLsizei height
, GLsizei depth
,
5982 GLboolean fixedsamplelocations
)
5984 struct gl_texture_object
*texObj
;
5985 GET_CURRENT_CONTEXT(ctx
);
5987 /* Get the texture object by Name. */
5988 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5989 "glTextureStorage3DMultisample");
5993 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5996 texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5997 internalformat
, width
, height
, depth
,
5998 fixedsamplelocations
, GL_TRUE
,
5999 "glTextureStorage3DMultisample");