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"
59 * State changes which we care about for glCopyTex[Sub]Image() calls.
60 * In particular, we care about pixel transfer state and buffer state
61 * (such as glReadBuffer to make sure we read from the right renderbuffer).
63 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
66 * Returns a corresponding internal floating point format for a given base
67 * format as specifed by OES_texture_float. In case of GL_FLOAT, the internal
68 * format needs to be a 32 bit component and in case of GL_HALF_FLOAT_OES it
69 * needs to be a 16 bit component.
71 * For example, given base format GL_RGBA, type GL_Float return GL_RGBA32F_ARB.
74 adjust_for_oes_float_texture(GLenum format
, GLenum type
)
84 return GL_ALPHA32F_ARB
;
86 return GL_LUMINANCE32F_ARB
;
87 case GL_LUMINANCE_ALPHA
:
88 return GL_LUMINANCE_ALPHA32F_ARB
;
94 case GL_HALF_FLOAT_OES
:
101 return GL_ALPHA16F_ARB
;
103 return GL_LUMINANCE16F_ARB
;
104 case GL_LUMINANCE_ALPHA
:
105 return GL_LUMINANCE_ALPHA16F_ARB
;
119 * Return the simple base format for a given internal texture format.
120 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
122 * \param ctx GL context.
123 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
125 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
126 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
128 * This is the format which is used during texture application (i.e. the
129 * texture format and env mode determine the arithmetic used.
132 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
134 switch (internalFormat
) {
140 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
147 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
149 case GL_LUMINANCE_ALPHA
:
150 case GL_LUMINANCE4_ALPHA4
:
151 case GL_LUMINANCE6_ALPHA2
:
152 case GL_LUMINANCE8_ALPHA8
:
153 case GL_LUMINANCE12_ALPHA4
:
154 case GL_LUMINANCE12_ALPHA12
:
155 case GL_LUMINANCE16_ALPHA16
:
156 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
162 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
164 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
175 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
189 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
191 if (_mesa_is_gles(ctx
)) {
192 switch (internalFormat
) {
200 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
201 switch (internalFormat
) {
209 if (ctx
->Extensions
.ARB_depth_texture
) {
210 switch (internalFormat
) {
211 case GL_DEPTH_COMPONENT
:
212 case GL_DEPTH_COMPONENT16
:
213 case GL_DEPTH_COMPONENT24
:
214 case GL_DEPTH_COMPONENT32
:
215 return GL_DEPTH_COMPONENT
;
216 case GL_DEPTH_STENCIL
:
217 case GL_DEPTH24_STENCIL8
:
218 return GL_DEPTH_STENCIL
;
224 if (ctx
->Extensions
.ARB_stencil_texturing
) {
225 switch (internalFormat
) {
226 case GL_STENCIL_INDEX
:
227 case GL_STENCIL_INDEX8
:
228 return GL_STENCIL_INDEX
;
234 switch (internalFormat
) {
235 case GL_COMPRESSED_ALPHA
:
237 case GL_COMPRESSED_LUMINANCE
:
239 case GL_COMPRESSED_LUMINANCE_ALPHA
:
240 return GL_LUMINANCE_ALPHA
;
241 case GL_COMPRESSED_INTENSITY
:
243 case GL_COMPRESSED_RGB
:
245 case GL_COMPRESSED_RGBA
:
251 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
252 switch (internalFormat
) {
253 case GL_COMPRESSED_RGB_FXT1_3DFX
:
255 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
262 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
264 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
265 switch (internalFormat
) {
266 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
268 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
269 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
270 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
277 if (_mesa_is_desktop_gl(ctx
)
278 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
279 switch (internalFormat
) {
291 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
292 if (internalFormat
== GL_YCBCR_MESA
)
293 return GL_YCBCR_MESA
;
296 if (ctx
->Extensions
.ARB_texture_float
) {
297 switch (internalFormat
) {
298 case GL_ALPHA16F_ARB
:
299 case GL_ALPHA32F_ARB
:
307 case GL_INTENSITY16F_ARB
:
308 case GL_INTENSITY32F_ARB
:
310 case GL_LUMINANCE16F_ARB
:
311 case GL_LUMINANCE32F_ARB
:
313 case GL_LUMINANCE_ALPHA16F_ARB
:
314 case GL_LUMINANCE_ALPHA32F_ARB
:
315 return GL_LUMINANCE_ALPHA
;
321 if (ctx
->Extensions
.EXT_texture_snorm
) {
322 switch (internalFormat
) {
337 case GL_RGBA16_SNORM
:
340 case GL_ALPHA8_SNORM
:
341 case GL_ALPHA16_SNORM
:
343 case GL_LUMINANCE_SNORM
:
344 case GL_LUMINANCE8_SNORM
:
345 case GL_LUMINANCE16_SNORM
:
347 case GL_LUMINANCE_ALPHA_SNORM
:
348 case GL_LUMINANCE8_ALPHA8_SNORM
:
349 case GL_LUMINANCE16_ALPHA16_SNORM
:
350 return GL_LUMINANCE_ALPHA
;
351 case GL_INTENSITY_SNORM
:
352 case GL_INTENSITY8_SNORM
:
353 case GL_INTENSITY16_SNORM
:
360 if (ctx
->Extensions
.EXT_texture_sRGB
) {
361 switch (internalFormat
) {
364 case GL_COMPRESSED_SRGB_EXT
:
366 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
367 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
368 case GL_SRGB_ALPHA_EXT
:
369 case GL_SRGB8_ALPHA8_EXT
:
370 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
372 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
373 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
374 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
375 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
376 case GL_SLUMINANCE_ALPHA_EXT
:
377 case GL_SLUMINANCE8_ALPHA8_EXT
:
378 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
379 return GL_LUMINANCE_ALPHA
;
380 case GL_SLUMINANCE_EXT
:
381 case GL_SLUMINANCE8_EXT
:
382 case GL_COMPRESSED_SLUMINANCE_EXT
:
389 if (ctx
->Version
>= 30 ||
390 ctx
->Extensions
.EXT_texture_integer
) {
391 switch (internalFormat
) {
393 case GL_RGBA16UI_EXT
:
394 case GL_RGBA32UI_EXT
:
410 if (ctx
->Extensions
.EXT_texture_integer
) {
411 switch (internalFormat
) {
412 case GL_ALPHA8UI_EXT
:
413 case GL_ALPHA16UI_EXT
:
414 case GL_ALPHA32UI_EXT
:
416 case GL_ALPHA16I_EXT
:
417 case GL_ALPHA32I_EXT
:
419 case GL_INTENSITY8UI_EXT
:
420 case GL_INTENSITY16UI_EXT
:
421 case GL_INTENSITY32UI_EXT
:
422 case GL_INTENSITY8I_EXT
:
423 case GL_INTENSITY16I_EXT
:
424 case GL_INTENSITY32I_EXT
:
426 case GL_LUMINANCE8UI_EXT
:
427 case GL_LUMINANCE16UI_EXT
:
428 case GL_LUMINANCE32UI_EXT
:
429 case GL_LUMINANCE8I_EXT
:
430 case GL_LUMINANCE16I_EXT
:
431 case GL_LUMINANCE32I_EXT
:
433 case GL_LUMINANCE_ALPHA8UI_EXT
:
434 case GL_LUMINANCE_ALPHA16UI_EXT
:
435 case GL_LUMINANCE_ALPHA32UI_EXT
:
436 case GL_LUMINANCE_ALPHA8I_EXT
:
437 case GL_LUMINANCE_ALPHA16I_EXT
:
438 case GL_LUMINANCE_ALPHA32I_EXT
:
439 return GL_LUMINANCE_ALPHA
;
445 if (ctx
->Extensions
.ARB_texture_rg
) {
446 switch (internalFormat
) {
449 if (!ctx
->Extensions
.ARB_texture_float
)
458 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
464 case GL_COMPRESSED_RED
:
469 if (!ctx
->Extensions
.ARB_texture_float
)
478 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
484 case GL_COMPRESSED_RG
:
491 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
492 switch (internalFormat
) {
500 if (ctx
->Extensions
.EXT_packed_float
) {
501 switch (internalFormat
) {
502 case GL_R11F_G11F_B10F_EXT
:
509 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
510 switch (internalFormat
) {
511 case GL_DEPTH_COMPONENT32F
:
512 return GL_DEPTH_COMPONENT
;
513 case GL_DEPTH32F_STENCIL8
:
514 return GL_DEPTH_STENCIL
;
520 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
521 switch (internalFormat
) {
522 case GL_COMPRESSED_RED_RGTC1
:
523 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
525 case GL_COMPRESSED_RG_RGTC2
:
526 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
533 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
534 switch (internalFormat
) {
535 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
536 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
538 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
539 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
540 return GL_LUMINANCE_ALPHA
;
546 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
547 switch (internalFormat
) {
548 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
549 return GL_LUMINANCE_ALPHA
;
555 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
556 switch (internalFormat
) {
557 case GL_ETC1_RGB8_OES
:
564 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
565 switch (internalFormat
) {
566 case GL_COMPRESSED_RGB8_ETC2
:
567 case GL_COMPRESSED_SRGB8_ETC2
:
569 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
570 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
571 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
572 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
574 case GL_COMPRESSED_R11_EAC
:
575 case GL_COMPRESSED_SIGNED_R11_EAC
:
577 case GL_COMPRESSED_RG11_EAC
:
578 case GL_COMPRESSED_SIGNED_RG11_EAC
:
585 if (_mesa_is_desktop_gl(ctx
) &&
586 ctx
->Extensions
.ARB_texture_compression_bptc
) {
587 switch (internalFormat
) {
588 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
589 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
591 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
592 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
599 if (ctx
->API
== API_OPENGLES
) {
600 switch (internalFormat
) {
601 case GL_PALETTE4_RGB8_OES
:
602 case GL_PALETTE4_R5_G6_B5_OES
:
603 case GL_PALETTE8_RGB8_OES
:
604 case GL_PALETTE8_R5_G6_B5_OES
:
606 case GL_PALETTE4_RGBA8_OES
:
607 case GL_PALETTE8_RGB5_A1_OES
:
608 case GL_PALETTE4_RGBA4_OES
:
609 case GL_PALETTE4_RGB5_A1_OES
:
610 case GL_PALETTE8_RGBA8_OES
:
611 case GL_PALETTE8_RGBA4_OES
:
618 return -1; /* error */
623 * For cube map faces, return a face index in [0,5].
624 * For other targets return 0;
627 _mesa_tex_target_to_face(GLenum target
)
629 if (_mesa_is_cube_face(target
))
630 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
638 * Install gl_texture_image in a gl_texture_object according to the target
639 * and level parameters.
641 * \param tObj texture object.
642 * \param target texture target.
643 * \param level image level.
644 * \param texImage texture image.
647 set_tex_image(struct gl_texture_object
*tObj
,
648 GLenum target
, GLint level
,
649 struct gl_texture_image
*texImage
)
651 const GLuint face
= _mesa_tex_target_to_face(target
);
655 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
658 tObj
->Image
[face
][level
] = texImage
;
660 /* Set the 'back' pointer */
661 texImage
->TexObject
= tObj
;
662 texImage
->Level
= level
;
663 texImage
->Face
= face
;
668 * Allocate a texture image structure.
670 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
673 * \return a pointer to gl_texture_image struct with all fields initialized to
676 struct gl_texture_image
*
677 _mesa_new_texture_image( struct gl_context
*ctx
)
680 return CALLOC_STRUCT(gl_texture_image
);
685 * Free a gl_texture_image and associated data.
686 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
688 * \param texImage texture image.
690 * Free the texture image structure and the associated image data.
693 _mesa_delete_texture_image(struct gl_context
*ctx
,
694 struct gl_texture_image
*texImage
)
696 /* Free texImage->Data and/or any other driver-specific texture
699 assert(ctx
->Driver
.FreeTextureImageBuffer
);
700 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
706 * Test if a target is a proxy target.
708 * \param target texture target.
710 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
713 _mesa_is_proxy_texture(GLenum target
)
716 static const GLenum targets
[] = {
720 GL_PROXY_TEXTURE_CUBE_MAP
,
721 GL_PROXY_TEXTURE_RECTANGLE
,
722 GL_PROXY_TEXTURE_1D_ARRAY
,
723 GL_PROXY_TEXTURE_2D_ARRAY
,
724 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
725 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
726 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
729 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
730 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
732 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
734 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
735 if (target
== targets
[i
])
742 * Test if a target is an array target.
744 * \param target texture target.
746 * \return true if the target is an array target, false otherwise.
749 _mesa_is_array_texture(GLenum target
)
752 case GL_TEXTURE_1D_ARRAY
:
753 case GL_TEXTURE_2D_ARRAY
:
754 case GL_TEXTURE_CUBE_MAP_ARRAY
:
755 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
764 * Return the proxy target which corresponds to the given texture target
767 proxy_target(GLenum target
)
771 case GL_PROXY_TEXTURE_1D
:
772 return GL_PROXY_TEXTURE_1D
;
774 case GL_PROXY_TEXTURE_2D
:
775 return GL_PROXY_TEXTURE_2D
;
777 case GL_PROXY_TEXTURE_3D
:
778 return GL_PROXY_TEXTURE_3D
;
779 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
780 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
781 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
782 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
783 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
784 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
785 case GL_TEXTURE_CUBE_MAP_ARB
:
786 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
787 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
788 case GL_TEXTURE_RECTANGLE_NV
:
789 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
790 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
791 case GL_TEXTURE_1D_ARRAY_EXT
:
792 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
793 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
794 case GL_TEXTURE_2D_ARRAY_EXT
:
795 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
796 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
797 case GL_TEXTURE_CUBE_MAP_ARRAY
:
798 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
799 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
800 case GL_TEXTURE_2D_MULTISAMPLE
:
801 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
802 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
803 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
804 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
805 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
807 _mesa_problem(NULL
, "unexpected target in proxy_target()");
816 * Get a texture image pointer from a texture object, given a texture
817 * target and mipmap level. The target and level parameters should
818 * have already been error-checked.
820 * \param texObj texture unit.
821 * \param target texture target.
822 * \param level image level.
824 * \return pointer to the texture image structure, or NULL on failure.
826 struct gl_texture_image
*
827 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
828 GLenum target
, GLint level
)
830 const GLuint face
= _mesa_tex_target_to_face(target
);
834 assert(level
< MAX_TEXTURE_LEVELS
);
836 return texObj
->Image
[face
][level
];
841 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
842 * it and install it. Only return NULL if passed a bad parameter or run
845 struct gl_texture_image
*
846 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
847 GLenum target
, GLint level
)
849 struct gl_texture_image
*texImage
;
854 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
856 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
858 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
862 set_tex_image(texObj
, target
, level
, texImage
);
870 * Return pointer to the specified proxy texture image.
871 * Note that proxy textures are per-context, not per-texture unit.
872 * \return pointer to texture image or NULL if invalid target, invalid
873 * level, or out of memory.
875 static struct gl_texture_image
*
876 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
878 struct gl_texture_image
*texImage
;
885 case GL_PROXY_TEXTURE_1D
:
886 if (level
>= ctx
->Const
.MaxTextureLevels
)
888 texIndex
= TEXTURE_1D_INDEX
;
890 case GL_PROXY_TEXTURE_2D
:
891 if (level
>= ctx
->Const
.MaxTextureLevels
)
893 texIndex
= TEXTURE_2D_INDEX
;
895 case GL_PROXY_TEXTURE_3D
:
896 if (level
>= ctx
->Const
.Max3DTextureLevels
)
898 texIndex
= TEXTURE_3D_INDEX
;
900 case GL_PROXY_TEXTURE_CUBE_MAP
:
901 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
903 texIndex
= TEXTURE_CUBE_INDEX
;
905 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
908 texIndex
= TEXTURE_RECT_INDEX
;
910 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
911 if (level
>= ctx
->Const
.MaxTextureLevels
)
913 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
915 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
916 if (level
>= ctx
->Const
.MaxTextureLevels
)
918 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
920 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
921 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
923 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
925 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
928 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
930 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
933 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
939 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
941 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
943 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
946 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
947 /* Set the 'back' pointer */
948 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
955 * Get the maximum number of allowed mipmap levels.
957 * \param ctx GL context.
958 * \param target texture target.
960 * \return the maximum number of allowed mipmap levels for the given
961 * texture target, or zero if passed a bad target.
966 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
970 case GL_PROXY_TEXTURE_1D
:
972 case GL_PROXY_TEXTURE_2D
:
973 return ctx
->Const
.MaxTextureLevels
;
975 case GL_PROXY_TEXTURE_3D
:
976 return ctx
->Const
.Max3DTextureLevels
;
977 case GL_TEXTURE_CUBE_MAP
:
978 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
979 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
980 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
981 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
982 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
983 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
984 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
985 return ctx
->Extensions
.ARB_texture_cube_map
986 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
987 case GL_TEXTURE_RECTANGLE_NV
:
988 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
989 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
990 case GL_TEXTURE_1D_ARRAY_EXT
:
991 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
992 case GL_TEXTURE_2D_ARRAY_EXT
:
993 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
994 return ctx
->Extensions
.EXT_texture_array
995 ? ctx
->Const
.MaxTextureLevels
: 0;
996 case GL_TEXTURE_CUBE_MAP_ARRAY
:
997 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
998 return ctx
->Extensions
.ARB_texture_cube_map_array
999 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1000 case GL_TEXTURE_BUFFER
:
1001 return ctx
->API
== API_OPENGL_CORE
&&
1002 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1003 case GL_TEXTURE_2D_MULTISAMPLE
:
1004 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1005 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1006 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1007 return _mesa_is_desktop_gl(ctx
)
1008 && ctx
->Extensions
.ARB_texture_multisample
1010 case GL_TEXTURE_EXTERNAL_OES
:
1013 return 0; /* bad target */
1019 * Return number of dimensions per mipmap level for the given texture target.
1022 _mesa_get_texture_dimensions(GLenum target
)
1026 case GL_PROXY_TEXTURE_1D
:
1029 case GL_TEXTURE_RECTANGLE
:
1030 case GL_TEXTURE_CUBE_MAP
:
1031 case GL_PROXY_TEXTURE_2D
:
1032 case GL_PROXY_TEXTURE_RECTANGLE
:
1033 case GL_PROXY_TEXTURE_CUBE_MAP
:
1034 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1035 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1036 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1037 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1038 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1039 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1040 case GL_TEXTURE_1D_ARRAY
:
1041 case GL_PROXY_TEXTURE_1D_ARRAY
:
1042 case GL_TEXTURE_EXTERNAL_OES
:
1043 case GL_TEXTURE_2D_MULTISAMPLE
:
1044 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1047 case GL_PROXY_TEXTURE_3D
:
1048 case GL_TEXTURE_2D_ARRAY
:
1049 case GL_PROXY_TEXTURE_2D_ARRAY
:
1050 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1051 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1052 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1053 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1055 case GL_TEXTURE_BUFFER
:
1058 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1066 * Check if a texture target can have more than one layer.
1069 _mesa_tex_target_is_layered(GLenum target
)
1073 case GL_PROXY_TEXTURE_1D
:
1075 case GL_PROXY_TEXTURE_2D
:
1076 case GL_TEXTURE_RECTANGLE
:
1077 case GL_PROXY_TEXTURE_RECTANGLE
:
1078 case GL_TEXTURE_2D_MULTISAMPLE
:
1079 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1080 case GL_TEXTURE_BUFFER
:
1081 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1082 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1083 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1084 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1085 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1086 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1087 case GL_TEXTURE_EXTERNAL_OES
:
1091 case GL_PROXY_TEXTURE_3D
:
1092 case GL_TEXTURE_CUBE_MAP
:
1093 case GL_PROXY_TEXTURE_CUBE_MAP
:
1094 case GL_TEXTURE_1D_ARRAY
:
1095 case GL_PROXY_TEXTURE_1D_ARRAY
:
1096 case GL_TEXTURE_2D_ARRAY
:
1097 case GL_PROXY_TEXTURE_2D_ARRAY
:
1098 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1099 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1100 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1101 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1105 assert(!"Invalid texture target.");
1112 * Return the number of layers present in the given level of an array,
1113 * cubemap or 3D texture. If the texture is not layered return zero.
1116 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1118 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1120 switch (texObj
->Target
) {
1123 case GL_TEXTURE_RECTANGLE
:
1124 case GL_TEXTURE_2D_MULTISAMPLE
:
1125 case GL_TEXTURE_BUFFER
:
1126 case GL_TEXTURE_EXTERNAL_OES
:
1129 case GL_TEXTURE_CUBE_MAP
:
1132 case GL_TEXTURE_1D_ARRAY
: {
1133 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1134 return img
? img
->Height
: 0;
1138 case GL_TEXTURE_2D_ARRAY
:
1139 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1140 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1141 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1142 return img
? img
->Depth
: 0;
1146 assert(!"Invalid texture target.");
1153 * Return the maximum number of mipmap levels for the given target
1154 * and the dimensions.
1155 * The dimensions are expected not to include the border.
1158 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1165 case GL_TEXTURE_1D_ARRAY
:
1166 case GL_PROXY_TEXTURE_1D
:
1167 case GL_PROXY_TEXTURE_1D_ARRAY
:
1170 case GL_TEXTURE_CUBE_MAP
:
1171 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1172 case GL_PROXY_TEXTURE_CUBE_MAP
:
1173 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1177 case GL_TEXTURE_2D_ARRAY
:
1178 case GL_PROXY_TEXTURE_2D
:
1179 case GL_PROXY_TEXTURE_2D_ARRAY
:
1180 size
= MAX2(width
, height
);
1183 case GL_PROXY_TEXTURE_3D
:
1184 size
= MAX3(width
, height
, depth
);
1186 case GL_TEXTURE_RECTANGLE
:
1187 case GL_TEXTURE_EXTERNAL_OES
:
1188 case GL_TEXTURE_2D_MULTISAMPLE
:
1189 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1190 case GL_PROXY_TEXTURE_RECTANGLE
:
1191 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1192 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1199 return _mesa_logbase2(size
) + 1;
1203 #if 000 /* not used anymore */
1205 * glTexImage[123]D can accept a NULL image pointer. In this case we
1206 * create a texture image with unspecified image contents per the OpenGL
1210 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1212 const GLint components
= _mesa_components_in_format(format
);
1213 const GLint numPixels
= width
* height
* depth
;
1214 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1218 * Let's see if anyone finds this. If glTexImage2D() is called with
1219 * a NULL image pointer then load the texture image with something
1220 * interesting instead of leaving it indeterminate.
1223 static const char message
[8][32] = {
1224 " X X XXXXX XXX X ",
1225 " XX XX X X X X X ",
1227 " X X XXXX XXX XXXXX ",
1230 " X X XXXXX XXX X X ",
1234 GLubyte
*imgPtr
= data
;
1236 for (h
= 0; h
< depth
; h
++) {
1237 for (i
= 0; i
< height
; i
++) {
1238 GLint srcRow
= 7 - (i
% 8);
1239 for (j
= 0; j
< width
; j
++) {
1240 GLint srcCol
= j
% 32;
1241 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1242 for (k
= 0; k
< components
; k
++) {
1258 * Set the size and format-related fields of a gl_texture_image struct
1259 * to zero. This is used when a proxy texture test fails.
1262 clear_teximage_fields(struct gl_texture_image
*img
)
1265 img
->_BaseFormat
= 0;
1266 img
->InternalFormat
= 0;
1275 img
->HeightLog2
= 0;
1277 img
->TexFormat
= MESA_FORMAT_NONE
;
1278 img
->NumSamples
= 0;
1279 img
->FixedSampleLocations
= GL_TRUE
;
1284 * Initialize basic fields of the gl_texture_image struct.
1286 * \param ctx GL context.
1287 * \param img texture image structure to be initialized.
1288 * \param width image width.
1289 * \param height image height.
1290 * \param depth image depth.
1291 * \param border image border.
1292 * \param internalFormat internal format.
1293 * \param format the actual hardware format (one of MESA_FORMAT_*)
1294 * \param numSamples number of samples per texel, or zero for non-MS.
1295 * \param fixedSampleLocations are sample locations fixed?
1297 * Fills in the fields of \p img with the given information.
1298 * Note: width, height and depth include the border.
1301 init_teximage_fields_ms(struct gl_context
*ctx
,
1302 struct gl_texture_image
*img
,
1303 GLsizei width
, GLsizei height
, GLsizei depth
,
1304 GLint border
, GLenum internalFormat
,
1306 GLuint numSamples
, GLboolean fixedSampleLocations
)
1311 assert(height
>= 0);
1314 target
= img
->TexObject
->Target
;
1315 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1316 assert(img
->_BaseFormat
!= -1);
1317 img
->InternalFormat
= internalFormat
;
1318 img
->Border
= border
;
1320 img
->Height
= height
;
1323 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1324 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1326 img
->NumSamples
= 0;
1327 img
->FixedSampleLocations
= GL_TRUE
;
1331 case GL_TEXTURE_BUFFER
:
1332 case GL_PROXY_TEXTURE_1D
:
1337 img
->HeightLog2
= 0;
1344 case GL_TEXTURE_1D_ARRAY
:
1345 case GL_PROXY_TEXTURE_1D_ARRAY
:
1346 img
->Height2
= height
; /* no border */
1347 img
->HeightLog2
= 0; /* not used */
1355 case GL_TEXTURE_RECTANGLE
:
1356 case GL_TEXTURE_CUBE_MAP
:
1357 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1358 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1359 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1360 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1361 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1362 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1363 case GL_TEXTURE_EXTERNAL_OES
:
1364 case GL_PROXY_TEXTURE_2D
:
1365 case GL_PROXY_TEXTURE_RECTANGLE
:
1366 case GL_PROXY_TEXTURE_CUBE_MAP
:
1367 case GL_TEXTURE_2D_MULTISAMPLE
:
1368 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1369 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1370 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1377 case GL_TEXTURE_2D_ARRAY
:
1378 case GL_PROXY_TEXTURE_2D_ARRAY
:
1379 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1380 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1381 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1382 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1383 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1384 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1385 img
->Depth2
= depth
; /* no border */
1386 img
->DepthLog2
= 0; /* not used */
1389 case GL_PROXY_TEXTURE_3D
:
1390 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1391 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1392 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1393 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1396 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1401 _mesa_get_tex_max_num_levels(target
,
1402 img
->Width2
, img
->Height2
, img
->Depth2
);
1403 img
->TexFormat
= format
;
1404 img
->NumSamples
= numSamples
;
1405 img
->FixedSampleLocations
= fixedSampleLocations
;
1410 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1411 struct gl_texture_image
*img
,
1412 GLsizei width
, GLsizei height
, GLsizei depth
,
1413 GLint border
, GLenum internalFormat
,
1416 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1417 internalFormat
, format
, 0, GL_TRUE
);
1422 * Free and clear fields of the gl_texture_image struct.
1424 * \param ctx GL context.
1425 * \param texImage texture image structure to be cleared.
1427 * After the call, \p texImage will have no data associated with it. Its
1428 * fields are cleared so that its parent object will test incomplete.
1431 _mesa_clear_texture_image(struct gl_context
*ctx
,
1432 struct gl_texture_image
*texImage
)
1434 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1435 clear_teximage_fields(texImage
);
1440 * Check the width, height, depth and border of a texture image are legal.
1441 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1443 * The target and level parameters will have already been validated.
1444 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1447 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1448 GLint level
, GLint width
, GLint height
,
1449 GLint depth
, GLint border
)
1455 case GL_PROXY_TEXTURE_1D
:
1456 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1457 maxSize
>>= level
; /* level size */
1458 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1460 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1461 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1467 case GL_PROXY_TEXTURE_2D
:
1468 case GL_TEXTURE_2D_MULTISAMPLE
:
1469 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1470 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1472 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1474 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1476 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1477 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1479 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1485 case GL_PROXY_TEXTURE_3D
:
1486 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1488 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1490 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1492 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1494 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1495 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1497 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1499 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1504 case GL_TEXTURE_RECTANGLE_NV
:
1505 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1508 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1509 if (width
< 0 || width
> maxSize
)
1511 if (height
< 0 || height
> maxSize
)
1515 case GL_TEXTURE_CUBE_MAP
:
1516 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1517 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1518 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1519 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1520 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1521 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1522 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1523 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1525 if (width
!= height
)
1527 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1529 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1531 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1532 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1534 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1539 case GL_TEXTURE_1D_ARRAY_EXT
:
1540 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1541 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1543 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1545 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1547 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1548 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1553 case GL_TEXTURE_2D_ARRAY_EXT
:
1554 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1555 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1556 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1557 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1559 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1561 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1563 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1565 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1566 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1568 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1573 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1574 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1575 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1576 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1578 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1580 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1582 if (width
!= height
)
1584 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1586 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1587 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1589 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1594 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1601 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1602 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1603 * \param destImage the destination texture image.
1604 * \return GL_TRUE if error found, GL_FALSE otherwise.
1607 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1608 const struct gl_texture_image
*destImage
,
1609 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1610 GLsizei subWidth
, GLsizei subHeight
,
1611 GLsizei subDepth
, const char *func
)
1613 const GLenum target
= destImage
->TexObject
->Target
;
1618 _mesa_error(ctx
, GL_INVALID_VALUE
,
1619 "%s%dD(width=%d)", func
, dims
, subWidth
);
1623 if (dims
> 1 && subHeight
< 0) {
1624 _mesa_error(ctx
, GL_INVALID_VALUE
,
1625 "%s%dD(height=%d)", func
, dims
, subHeight
);
1629 if (dims
> 2 && subDepth
< 0) {
1630 _mesa_error(ctx
, GL_INVALID_VALUE
,
1631 "%s%dD(depth=%d)", func
, dims
, subDepth
);
1635 /* check xoffset and width */
1636 if (xoffset
< - (GLint
) destImage
->Border
) {
1637 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1642 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1643 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1648 /* check yoffset and height */
1650 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1651 if (yoffset
< -yBorder
) {
1652 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1656 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1657 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1663 /* check zoffset and depth */
1666 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1667 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1668 0 : destImage
->Border
;
1670 if (zoffset
< -zBorder
) {
1671 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", func
);
1675 depth
= (GLint
) destImage
->Depth
;
1676 if (target
== GL_TEXTURE_CUBE_MAP
)
1678 if (zoffset
+ subDepth
> depth
) {
1679 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", func
);
1685 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1686 * compressed texture images can be updated. But, that restriction may be
1687 * relaxed for particular compressed formats. At this time, all the
1688 * compressed formats supported by Mesa allow sub-textures to be updated
1689 * along compressed block boundaries.
1691 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1693 if (bw
!= 1 || bh
!= 1) {
1694 /* offset must be multiple of block size */
1695 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1696 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1697 "%s%dD(xoffset = %d, yoffset = %d)",
1698 func
, dims
, xoffset
, yoffset
);
1702 /* The size must be a multiple of bw x bh, or we must be using a
1703 * offset+size that exactly hits the edge of the image. This
1704 * is important for small mipmap levels (1x1, 2x1, etc) and for
1707 if ((subWidth
% bw
!= 0) &&
1708 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1709 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1710 "%s%dD(width = %d)", func
, dims
, subWidth
);
1714 if ((subHeight
% bh
!= 0) &&
1715 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1716 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1717 "%s%dD(height = %d)", func
, dims
, subHeight
);
1729 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1730 * specific texture image size checks.
1732 * A hardware driver might override this function if, for example, the
1733 * max 3D texture size is 512x512x64 (i.e. not a cube).
1735 * Note that width, height, depth == 0 is not an error. However, a
1736 * texture with zero width/height/depth will be considered "incomplete"
1737 * and texturing will effectively be disabled.
1739 * \param target any texture target/type
1740 * \param level as passed to glTexImage
1741 * \param format the MESA_FORMAT_x for the tex image
1742 * \param width as passed to glTexImage
1743 * \param height as passed to glTexImage
1744 * \param depth as passed to glTexImage
1745 * \param border as passed to glTexImage
1746 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1749 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1751 GLint width
, GLint height
, GLint depth
, GLint border
)
1753 /* We just check if the image size is less than MaxTextureMbytes.
1754 * Some drivers may do more specific checks.
1756 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1757 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1758 mbytes
*= _mesa_num_tex_faces(target
);
1759 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1764 * Return true if the format is only valid for glCompressedTexImage.
1767 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1770 case GL_ETC1_RGB8_OES
:
1771 case GL_PALETTE4_RGB8_OES
:
1772 case GL_PALETTE4_RGBA8_OES
:
1773 case GL_PALETTE4_R5_G6_B5_OES
:
1774 case GL_PALETTE4_RGBA4_OES
:
1775 case GL_PALETTE4_RGB5_A1_OES
:
1776 case GL_PALETTE8_RGB8_OES
:
1777 case GL_PALETTE8_RGBA8_OES
:
1778 case GL_PALETTE8_R5_G6_B5_OES
:
1779 case GL_PALETTE8_RGBA4_OES
:
1780 case GL_PALETTE8_RGB5_A1_OES
:
1789 * Helper function to determine whether a target and specific compression
1790 * format are supported.
1793 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1796 (void) intFormat
; /* not used yet */
1800 case GL_PROXY_TEXTURE_2D
:
1801 return GL_TRUE
; /* true for any compressed format so far */
1802 case GL_PROXY_TEXTURE_CUBE_MAP
:
1803 case GL_TEXTURE_CUBE_MAP
:
1804 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1805 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1806 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1807 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1808 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1809 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1810 return ctx
->Extensions
.ARB_texture_cube_map
;
1811 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1812 case GL_TEXTURE_2D_ARRAY_EXT
:
1813 return ctx
->Extensions
.EXT_texture_array
;
1814 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1815 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1816 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1824 * Check if the given texture target value is legal for a
1825 * glTexImage1/2/3D call.
1828 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1834 case GL_PROXY_TEXTURE_1D
:
1835 return _mesa_is_desktop_gl(ctx
);
1843 case GL_PROXY_TEXTURE_2D
:
1844 return _mesa_is_desktop_gl(ctx
);
1845 case GL_PROXY_TEXTURE_CUBE_MAP
:
1846 return _mesa_is_desktop_gl(ctx
)
1847 && ctx
->Extensions
.ARB_texture_cube_map
;
1848 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1850 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1851 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1852 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1853 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1854 return ctx
->Extensions
.ARB_texture_cube_map
;
1855 case GL_TEXTURE_RECTANGLE_NV
:
1856 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1857 return _mesa_is_desktop_gl(ctx
)
1858 && ctx
->Extensions
.NV_texture_rectangle
;
1859 case GL_TEXTURE_1D_ARRAY_EXT
:
1860 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1861 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1869 case GL_PROXY_TEXTURE_3D
:
1870 return _mesa_is_desktop_gl(ctx
);
1871 case GL_TEXTURE_2D_ARRAY_EXT
:
1872 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1873 || _mesa_is_gles3(ctx
);
1874 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1875 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1876 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1877 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1878 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1883 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1890 * Check if the given texture target value is legal for a
1891 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1892 * The difference compared to legal_teximage_target() above is that
1893 * proxy targets are not supported.
1896 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1901 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1906 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1907 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1908 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1909 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1910 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1911 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1912 return ctx
->Extensions
.ARB_texture_cube_map
;
1913 case GL_TEXTURE_RECTANGLE_NV
:
1914 return _mesa_is_desktop_gl(ctx
)
1915 && ctx
->Extensions
.NV_texture_rectangle
;
1916 case GL_TEXTURE_1D_ARRAY_EXT
:
1917 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1925 case GL_TEXTURE_2D_ARRAY_EXT
:
1926 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1927 || _mesa_is_gles3(ctx
);
1928 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1929 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1930 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1932 /* Table 8.15 of the OpenGL 4.5 core profile spec
1933 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1934 * and CopyTextureSubImage3D.
1936 case GL_TEXTURE_CUBE_MAP
:
1942 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1950 * Helper function to determine if a texture object is mutable (in terms
1951 * of GL_ARB_texture_storage).
1954 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1956 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1960 return !texObj
->Immutable
;
1965 * Return expected size of a compressed texture.
1968 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1971 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1972 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1976 * Verify that a texture format is valid with a particular target
1978 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1979 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1982 * \param ctx GL context
1983 * \param target Texture target
1984 * \param internalFormat Internal format of the texture image
1985 * \param dimensions Dimensionality at the caller. This is \b not used
1986 * in the validation. It is only used when logging
1988 * \param caller Base name of the calling function (e.g.,
1989 * "glTexImage" or "glTexStorage").
1991 * \returns true if the combination is legal, false otherwise.
1994 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1995 GLenum target
, GLenum internalFormat
,
1996 unsigned dimensions
,
1999 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2000 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2001 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
2002 * Profile spec says:
2004 * "Textures with a base internal format of DEPTH_COMPONENT or
2005 * DEPTH_STENCIL are supported by texture image specification
2006 * commands only if target is TEXTURE_1D, TEXTURE_2D,
2007 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
2008 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
2009 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
2010 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
2011 * formats in conjunction with any other target will result in an
2012 * INVALID_OPERATION error."
2014 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
2015 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
2017 if (target
!= GL_TEXTURE_1D
&&
2018 target
!= GL_PROXY_TEXTURE_1D
&&
2019 target
!= GL_TEXTURE_2D
&&
2020 target
!= GL_PROXY_TEXTURE_2D
&&
2021 target
!= GL_TEXTURE_1D_ARRAY
&&
2022 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2023 target
!= GL_TEXTURE_2D_ARRAY
&&
2024 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2025 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2026 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2027 !((_mesa_is_cube_face(target
) ||
2028 target
== GL_TEXTURE_CUBE_MAP
||
2029 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2030 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2031 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2032 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2033 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2034 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2035 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2036 "%s%dD(bad target for depth texture)",
2037 caller
, dimensions
);
2046 texture_formats_agree(GLenum internalFormat
,
2049 GLboolean colorFormat
;
2050 GLboolean is_format_depth_or_depthstencil
;
2051 GLboolean is_internalFormat_depth_or_depthstencil
;
2053 /* Even though there are no color-index textures, we still have to support
2054 * uploading color-index data and remapping it to RGB via the
2055 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2057 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2059 is_internalFormat_depth_or_depthstencil
=
2060 _mesa_is_depth_format(internalFormat
) ||
2061 _mesa_is_depthstencil_format(internalFormat
);
2063 is_format_depth_or_depthstencil
=
2064 _mesa_is_depth_format(format
) ||
2065 _mesa_is_depthstencil_format(format
);
2067 colorFormat
= _mesa_is_color_format(format
);
2069 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2072 if (is_internalFormat_depth_or_depthstencil
!=
2073 is_format_depth_or_depthstencil
)
2076 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2083 * Test the glTexImage[123]D() parameters for errors.
2085 * \param ctx GL context.
2086 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2087 * \param target texture target given by the user (already validated).
2088 * \param level image level given by the user.
2089 * \param internalFormat internal format given by the user.
2090 * \param format pixel data format given by the user.
2091 * \param type pixel data type given by the user.
2092 * \param width image width given by the user.
2093 * \param height image height given by the user.
2094 * \param depth image depth given by the user.
2095 * \param border image border given by the user.
2097 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2099 * Verifies each of the parameters against the constants specified in
2100 * __struct gl_contextRec::Const and the supported extensions, and according
2101 * to the OpenGL specification.
2102 * Note that we don't fully error-check the width, height, depth values
2103 * here. That's done in _mesa_legal_texture_dimensions() which is used
2104 * by several other GL entrypoints. Plus, texture dims have a special
2105 * interaction with proxy textures.
2108 texture_error_check( struct gl_context
*ctx
,
2109 GLuint dimensions
, GLenum target
,
2110 GLint level
, GLint internalFormat
,
2111 GLenum format
, GLenum type
,
2112 GLint width
, GLint height
,
2113 GLint depth
, GLint border
)
2117 /* Note: for proxy textures, some error conditions immediately generate
2118 * a GL error in the usual way. But others do not generate a GL error.
2119 * Instead, they cause the width, height, depth, format fields of the
2120 * texture image to be zeroed-out. The GL spec seems to indicate that the
2121 * zero-out behaviour is only used in cases related to memory allocation.
2125 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2126 _mesa_error(ctx
, GL_INVALID_VALUE
,
2127 "glTexImage%dD(level=%d)", dimensions
, level
);
2132 if (border
< 0 || border
> 1 ||
2133 ((ctx
->API
!= API_OPENGL_COMPAT
||
2134 target
== GL_TEXTURE_RECTANGLE_NV
||
2135 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2136 _mesa_error(ctx
, GL_INVALID_VALUE
,
2137 "glTexImage%dD(border=%d)", dimensions
, border
);
2141 if (width
< 0 || height
< 0 || depth
< 0) {
2142 _mesa_error(ctx
, GL_INVALID_VALUE
,
2143 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2147 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2148 * combinations of format, internalFormat, and type that can be used.
2149 * Formats and types that require additional extensions (e.g., GL_FLOAT
2150 * requires GL_OES_texture_float) are filtered elsewhere.
2153 if (_mesa_is_gles(ctx
)) {
2154 if (_mesa_is_gles3(ctx
)) {
2155 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
2158 if (format
!= internalFormat
) {
2159 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2160 "glTexImage%dD(format = %s, internalFormat = %s)",
2162 _mesa_lookup_enum_by_nr(format
),
2163 _mesa_lookup_enum_by_nr(internalFormat
));
2167 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2169 if (err
!= GL_NO_ERROR
) {
2170 _mesa_error(ctx
, err
,
2171 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2173 _mesa_lookup_enum_by_nr(format
),
2174 _mesa_lookup_enum_by_nr(type
),
2175 _mesa_lookup_enum_by_nr(internalFormat
));
2180 /* Check internalFormat */
2181 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2182 _mesa_error(ctx
, GL_INVALID_VALUE
,
2183 "glTexImage%dD(internalFormat=%s)",
2184 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2188 /* Check incoming image format and type */
2189 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2190 if (err
!= GL_NO_ERROR
) {
2191 _mesa_error(ctx
, err
,
2192 "glTexImage%dD(incompatible format = %s, type = %s)",
2193 dimensions
, _mesa_lookup_enum_by_nr(format
),
2194 _mesa_lookup_enum_by_nr(type
));
2198 /* make sure internal format and format basically agree */
2199 if (!texture_formats_agree(internalFormat
, format
)) {
2200 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2201 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2202 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2203 _mesa_lookup_enum_by_nr(format
));
2207 /* additional checks for ycbcr textures */
2208 if (internalFormat
== GL_YCBCR_MESA
) {
2209 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
2210 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2211 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2213 _mesa_snprintf(message
, sizeof(message
),
2214 "glTexImage%dD(format/type YCBCR mismatch)",
2216 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2217 return GL_TRUE
; /* error */
2219 if (target
!= GL_TEXTURE_2D
&&
2220 target
!= GL_PROXY_TEXTURE_2D
&&
2221 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2222 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2223 _mesa_error(ctx
, GL_INVALID_ENUM
,
2224 "glTexImage%dD(bad target for YCbCr texture)",
2230 _mesa_snprintf(message
, sizeof(message
),
2231 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2232 dimensions
, border
);
2233 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2238 /* additional checks for depth textures */
2239 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2240 dimensions
, "glTexImage"))
2243 /* additional checks for compressed textures */
2244 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2245 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2246 _mesa_error(ctx
, GL_INVALID_ENUM
,
2247 "glTexImage%dD(target can't be compressed)", dimensions
);
2250 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2251 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2252 "glTexImage%dD(no compression for format)", dimensions
);
2256 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2257 "glTexImage%dD(border!=0)", dimensions
);
2262 /* additional checks for integer textures */
2263 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2264 (_mesa_is_enum_format_integer(format
) !=
2265 _mesa_is_enum_format_integer(internalFormat
))) {
2266 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2267 "glTexImage%dD(integer/non-integer format mismatch)",
2272 if (!mutable_tex_object(ctx
, target
)) {
2273 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2274 "glTexImage%dD(immutable texture)", dimensions
);
2278 /* if we get here, the parameters are OK */
2284 * Error checking for glCompressedTexImage[123]D().
2285 * Note that the width, height and depth values are not fully error checked
2287 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2290 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2291 GLenum target
, GLint level
,
2292 GLenum internalFormat
, GLsizei width
,
2293 GLsizei height
, GLsizei depth
, GLint border
,
2296 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2298 GLenum error
= GL_NO_ERROR
;
2299 char *reason
= ""; /* no error */
2301 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2303 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
2305 * "The ETC2/EAC texture compression algorithm supports only
2306 * two-dimensional images. If internalformat is an ETC2/EAC format,
2307 * CompressedTexImage3D will generate an INVALID_OPERATION error if
2308 * target is not TEXTURE_2D_ARRAY."
2310 error
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
2314 /* This will detect any invalid internalFormat value */
2315 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2316 _mesa_error(ctx
, GL_INVALID_ENUM
,
2317 "glCompressedTexImage%dD(internalFormat=%s)",
2318 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2322 switch (internalFormat
) {
2323 case GL_PALETTE4_RGB8_OES
:
2324 case GL_PALETTE4_RGBA8_OES
:
2325 case GL_PALETTE4_R5_G6_B5_OES
:
2326 case GL_PALETTE4_RGBA4_OES
:
2327 case GL_PALETTE4_RGB5_A1_OES
:
2328 case GL_PALETTE8_RGB8_OES
:
2329 case GL_PALETTE8_RGBA8_OES
:
2330 case GL_PALETTE8_R5_G6_B5_OES
:
2331 case GL_PALETTE8_RGBA4_OES
:
2332 case GL_PALETTE8_RGB5_A1_OES
:
2333 /* check level (note that level should be zero or less!) */
2334 if (level
> 0 || level
< -maxLevels
) {
2336 error
= GL_INVALID_VALUE
;
2340 if (dimensions
!= 2) {
2341 reason
= "compressed paletted textures must be 2D";
2342 error
= GL_INVALID_OPERATION
;
2346 /* Figure out the expected texture size (in bytes). This will be
2347 * checked against the actual size later.
2349 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2352 /* This is for the benefit of the TestProxyTexImage below. It expects
2353 * level to be non-negative. OES_compressed_paletted_texture uses a
2354 * weird mechanism where the level specified to glCompressedTexImage2D
2355 * is -(n-1) number of levels in the texture, and the data specifies the
2356 * complete mipmap stack. This is done to ensure the palette is the
2357 * same for all levels.
2364 if (level
< 0 || level
>= maxLevels
) {
2366 error
= GL_INVALID_VALUE
;
2370 /* Figure out the expected texture size (in bytes). This will be
2371 * checked against the actual size later.
2373 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2377 /* This should really never fail */
2378 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2379 reason
= "internalFormat";
2380 error
= GL_INVALID_ENUM
;
2384 /* No compressed formats support borders at this time */
2386 reason
= "border != 0";
2387 error
= GL_INVALID_VALUE
;
2391 /* Check for invalid pixel storage modes */
2392 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2394 "glCompressedTexImage")) {
2398 /* check image size in bytes */
2399 if (expectedSize
!= imageSize
) {
2400 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2401 * if <imageSize> is not consistent with the format, dimensions, and
2402 * contents of the specified image.
2404 reason
= "imageSize inconsistant with width/height/format";
2405 error
= GL_INVALID_VALUE
;
2409 if (!mutable_tex_object(ctx
, target
)) {
2410 reason
= "immutable texture";
2411 error
= GL_INVALID_OPERATION
;
2418 /* Note: not all error paths exit through here. */
2419 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2420 dimensions
, reason
);
2427 * Test glTexSubImage[123]D() parameters for errors.
2429 * \param ctx GL context.
2430 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2431 * \param target texture target given by the user (already validated)
2432 * \param level image level given by the user.
2433 * \param xoffset sub-image x offset given by the user.
2434 * \param yoffset sub-image y offset given by the user.
2435 * \param zoffset sub-image z offset given by the user.
2436 * \param format pixel data format given by the user.
2437 * \param type pixel data type given by the user.
2438 * \param width image width given by the user.
2439 * \param height image height given by the user.
2440 * \param depth image depth given by the user.
2442 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2444 * Verifies each of the parameters against the constants specified in
2445 * __struct gl_contextRec::Const and the supported extensions, and according
2446 * to the OpenGL specification.
2449 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2450 struct gl_texture_object
*texObj
,
2451 GLenum target
, GLint level
,
2452 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2453 GLint width
, GLint height
, GLint depth
,
2454 GLenum format
, GLenum type
, bool dsa
)
2456 struct gl_texture_image
*texImage
;
2458 const char* suffix
= dsa
? "ture" : "";
2461 /* must be out of memory */
2462 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTex%sSubImage%dD()",
2463 suffix
, dimensions
);
2467 /* check target (proxies not allowed) */
2468 if (!legal_texsubimage_target(ctx
, dimensions
, target
, dsa
)) {
2469 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sSubImage%uD(target=%s)",
2470 suffix
, dimensions
, _mesa_lookup_enum_by_nr(target
));
2475 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2476 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sSubImage%uD(level=%d)",
2477 suffix
, dimensions
, level
);
2481 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2482 * combinations of format and type that can be used. Formats and types
2483 * that require additional extensions (e.g., GL_FLOAT requires
2484 * GL_OES_texture_float) are filtered elsewhere.
2486 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2487 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2488 if (err
!= GL_NO_ERROR
) {
2489 _mesa_error(ctx
, err
,
2490 "glTex%sSubImage%dD(format = %s, type = %s)",
2491 suffix
, dimensions
, _mesa_lookup_enum_by_nr(format
),
2492 _mesa_lookup_enum_by_nr(type
));
2497 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2498 if (err
!= GL_NO_ERROR
) {
2499 _mesa_error(ctx
, err
,
2500 "glTex%sSubImage%dD(incompatible format = %s, type = %s)",
2501 suffix
, dimensions
, _mesa_lookup_enum_by_nr(format
),
2502 _mesa_lookup_enum_by_nr(type
));
2506 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2508 /* non-existant texture level */
2509 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2510 "glTex%sSubImage%dD(invalid texture image)", suffix
,
2515 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2516 texImage
, xoffset
, yoffset
, zoffset
,
2517 width
, height
, depth
,
2518 dsa
? "glTextureSubImage" :
2523 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2524 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2525 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2526 "glTex%sSubImage%dD(no compression for format)",
2527 suffix
, dimensions
);
2532 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2533 /* both source and dest must be integer-valued, or neither */
2534 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2535 _mesa_is_enum_format_integer(format
)) {
2536 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2537 "glTex%sSubImage%dD(integer/non-integer format mismatch)",
2538 suffix
, dimensions
);
2548 * Test glCopyTexImage[12]D() parameters for errors.
2550 * \param ctx GL context.
2551 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2552 * \param target texture target given by the user.
2553 * \param level image level given by the user.
2554 * \param internalFormat internal format given by the user.
2555 * \param width image width given by the user.
2556 * \param height image height given by the user.
2557 * \param border texture border.
2559 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2561 * Verifies each of the parameters against the constants specified in
2562 * __struct gl_contextRec::Const and the supported extensions, and according
2563 * to the OpenGL specification.
2566 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2567 GLenum target
, GLint level
, GLint internalFormat
,
2568 GLint width
, GLint height
, GLint border
)
2571 GLint rb_base_format
;
2572 struct gl_renderbuffer
*rb
;
2573 GLenum rb_internal_format
;
2576 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2577 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2578 dimensions
, _mesa_lookup_enum_by_nr(target
));
2583 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2584 _mesa_error(ctx
, GL_INVALID_VALUE
,
2585 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2589 /* Check that the source buffer is complete */
2590 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2591 if (ctx
->ReadBuffer
->_Status
== 0) {
2592 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2594 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2595 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2596 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2600 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2602 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2608 if (border
< 0 || border
> 1 ||
2609 ((ctx
->API
!= API_OPENGL_COMPAT
||
2610 target
== GL_TEXTURE_RECTANGLE_NV
||
2611 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2612 _mesa_error(ctx
, GL_INVALID_VALUE
,
2613 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2617 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2619 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2620 "glCopyTexImage%dD(read buffer)", dimensions
);
2624 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2627 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2628 switch (internalFormat
) {
2633 case GL_LUMINANCE_ALPHA
:
2636 _mesa_error(ctx
, GL_INVALID_VALUE
,
2637 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2638 _mesa_lookup_enum_by_nr(internalFormat
));
2643 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2644 if (baseFormat
< 0) {
2645 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2646 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2647 _mesa_lookup_enum_by_nr(internalFormat
));
2651 rb_internal_format
= rb
->InternalFormat
;
2652 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2653 if (_mesa_is_color_format(internalFormat
)) {
2654 if (rb_base_format
< 0) {
2655 _mesa_error(ctx
, GL_INVALID_VALUE
,
2656 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2657 _mesa_lookup_enum_by_nr(internalFormat
));
2662 if (_mesa_is_gles(ctx
)) {
2664 if (_mesa_base_format_component_count(baseFormat
) >
2665 _mesa_base_format_component_count(rb_base_format
)) {
2668 if (baseFormat
== GL_DEPTH_COMPONENT
||
2669 baseFormat
== GL_DEPTH_STENCIL
||
2670 rb_base_format
== GL_DEPTH_COMPONENT
||
2671 rb_base_format
== GL_DEPTH_STENCIL
||
2672 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2673 baseFormat
== GL_ALPHA
) &&
2674 rb_base_format
!= GL_RGBA
) ||
2675 internalFormat
== GL_RGB9_E5
) {
2678 if (internalFormat
== GL_RGB9_E5
) {
2682 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2683 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2684 _mesa_lookup_enum_by_nr(internalFormat
));
2689 if (_mesa_is_gles3(ctx
)) {
2690 bool rb_is_srgb
= false;
2691 bool dst_is_srgb
= false;
2693 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2694 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2698 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2702 if (rb_is_srgb
!= dst_is_srgb
) {
2703 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2704 * OpenGLES 3.0.0 spec says:
2706 * "The error INVALID_OPERATION is also generated if the
2707 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2708 * framebuffer attachment corresponding to the read buffer
2709 * is LINEAR (see section 6.1.13) and internalformat is
2710 * one of the sRGB formats described in section 3.8.16, or
2711 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2712 * SRGB and internalformat is not one of the sRGB formats."
2714 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2715 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2719 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2720 * types for SNORM formats. Also, conversion to SNORM formats is not
2721 * allowed by Table 3.2 on Page 110.
2723 if(_mesa_is_enum_format_snorm(internalFormat
)) {
2724 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2725 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2726 _mesa_lookup_enum_by_nr(internalFormat
));
2731 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2732 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2733 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2737 /* From the EXT_texture_integer spec:
2739 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2740 * if the texture internalformat is an integer format and the read color
2741 * buffer is not an integer format, or if the internalformat is not an
2742 * integer format and the read color buffer is an integer format."
2744 if (_mesa_is_color_format(internalFormat
)) {
2745 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2746 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2747 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2748 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2749 if (is_int
|| is_rbint
) {
2750 if (is_int
!= is_rbint
) {
2751 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2752 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2754 } else if (_mesa_is_gles(ctx
) &&
2755 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2756 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2757 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2758 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2763 /* From page 138 of OpenGL ES 3.0 spec:
2764 * "The error INVALID_OPERATION is generated if floating-point RGBA
2765 * data is required; if signed integer RGBA data is required and the
2766 * format of the current color buffer is not signed integer; if
2767 * unsigned integer RGBA data is required and the format of the
2768 * current color buffer is not unsigned integer; or if fixed-point
2769 * RGBA data is required and the format of the current color buffer
2770 * is not fixed-point.
2772 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2773 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2774 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2777 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2778 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2779 _mesa_error(ctx
, GL_INVALID_ENUM
,
2780 "glCopyTexImage%dD(target)", dimensions
);
2783 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2784 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2785 "glCopyTexImage%dD(no compression for format)", dimensions
);
2789 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2790 "glCopyTexImage%dD(border!=0)", dimensions
);
2795 if (!mutable_tex_object(ctx
, target
)) {
2796 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2797 "glCopyTexImage%dD(immutable texture)", dimensions
);
2801 /* if we get here, the parameters are OK */
2807 * Test glCopyTexSubImage[12]D() parameters for errors.
2808 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2811 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2812 const struct gl_texture_object
*texObj
,
2813 GLenum target
, GLint level
,
2814 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2815 GLint width
, GLint height
, bool dsa
)
2817 struct gl_texture_image
*texImage
;
2818 const char *suffix
= dsa
? "ture" : "";
2820 /* Check that the source buffer is complete */
2821 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2822 if (ctx
->ReadBuffer
->_Status
== 0) {
2823 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2825 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2826 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2827 "glCopyTex%sSubImage%dD(invalid readbuffer)",
2828 suffix
, dimensions
);
2832 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2833 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2834 "glCopyTex%sSubImage%dD(multisample FBO)", suffix
,
2841 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2842 _mesa_error(ctx
, GL_INVALID_VALUE
,
2843 "glCopyTex%sSubImage%dD(level=%d)", suffix
,
2848 /* Get dest image pointers */
2850 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTex%sSubImage%dD()",
2851 suffix
, dimensions
);
2855 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2857 /* destination image does not exist */
2858 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2859 "glCopyTex%sSubImage%dD(invalid texture image)",
2860 suffix
, dimensions
);
2864 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2865 xoffset
, yoffset
, zoffset
,
2866 width
, height
, 1, dsa
?
2867 "glCompressedTextureSubImage" :
2868 "glCompressedTexSubImage")) {
2872 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2873 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2874 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2875 "glCopyTex%sSubImage%dD(no compression for format)",
2876 suffix
, dimensions
);
2881 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2882 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTex%sSubImage2D", suffix
);
2886 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2887 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2888 "glCopyTex%sSubImage%dD(missing readbuffer, format=0x%x)",
2889 suffix
, dimensions
, texImage
->_BaseFormat
);
2893 /* From the EXT_texture_integer spec:
2895 * "INVALID_OPERATION is generated by CopyTexImage* and
2896 * CopyTexSubImage* if the texture internalformat is an integer format
2897 * and the read color buffer is not an integer format, or if the
2898 * internalformat is not an integer format and the read color buffer
2899 * is an integer format."
2901 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2902 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2904 if (_mesa_is_format_integer_color(rb
->Format
) !=
2905 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2906 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2907 "glCopyTex%sSubImage%dD(integer vs non-integer)",
2908 suffix
, dimensions
);
2913 /* if we get here, the parameters are OK */
2918 /** Callback info for walking over FBO hash table */
2921 struct gl_context
*ctx
;
2922 struct gl_texture_object
*texObj
;
2928 * Check render to texture callback. Called from _mesa_HashWalk().
2931 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2933 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2934 const struct cb_info
*info
= (struct cb_info
*) userData
;
2935 struct gl_context
*ctx
= info
->ctx
;
2936 const struct gl_texture_object
*texObj
= info
->texObj
;
2937 const GLuint level
= info
->level
, face
= info
->face
;
2939 /* If this is a user-created FBO */
2940 if (_mesa_is_user_fbo(fb
)) {
2942 /* check if any of the FBO's attachments point to 'texObj' */
2943 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2944 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2945 if (att
->Type
== GL_TEXTURE
&&
2946 att
->Texture
== texObj
&&
2947 att
->TextureLevel
== level
&&
2948 att
->CubeMapFace
== face
) {
2949 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2950 assert(att
->Renderbuffer
->TexImage
);
2951 /* Mark fb status as indeterminate to force re-validation */
2960 * When a texture image is specified we have to check if it's bound to
2961 * any framebuffer objects (render to texture) in order to detect changes
2962 * in size or format since that effects FBO completeness.
2963 * Any FBOs rendering into the texture must be re-validated.
2966 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2967 struct gl_texture_object
*texObj
,
2968 GLuint face
, GLuint level
)
2970 /* Only check this texture if it's been marked as RenderToTexture */
2971 if (texObj
->_RenderToTexture
) {
2972 struct cb_info info
;
2974 info
.texObj
= texObj
;
2977 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2983 * If the texture object's GenerateMipmap flag is set and we've
2984 * changed the texture base level image, regenerate the rest of the
2985 * mipmap levels now.
2988 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2989 struct gl_texture_object
*texObj
, GLint level
)
2991 if (texObj
->GenerateMipmap
&&
2992 level
== texObj
->BaseLevel
&&
2993 level
< texObj
->MaxLevel
) {
2994 assert(ctx
->Driver
.GenerateMipmap
);
2995 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3000 /** Debug helper: override the user-requested internal format */
3002 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
3005 if (internalFormat
== GL_RGBA16F_ARB
||
3006 internalFormat
== GL_RGBA32F_ARB
) {
3007 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3010 else if (internalFormat
== GL_RGB16F_ARB
||
3011 internalFormat
== GL_RGB32F_ARB
) {
3012 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3015 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3016 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3017 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3018 return GL_LUMINANCE_ALPHA
;
3020 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3021 internalFormat
== GL_LUMINANCE32F_ARB
) {
3022 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3023 return GL_LUMINANCE
;
3025 else if (internalFormat
== GL_ALPHA16F_ARB
||
3026 internalFormat
== GL_ALPHA32F_ARB
) {
3027 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3031 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3032 internalFormat = GL_RGBA;
3036 return internalFormat
;
3039 return internalFormat
;
3045 * Choose the actual hardware format for a texture image.
3046 * Try to use the same format as the previous image level when possible.
3047 * Otherwise, ask the driver for the best format.
3048 * It's important to try to choose a consistant format for all levels
3049 * for efficient texture memory layout/allocation. In particular, this
3050 * comes up during automatic mipmap generation.
3053 _mesa_choose_texture_format(struct gl_context
*ctx
,
3054 struct gl_texture_object
*texObj
,
3055 GLenum target
, GLint level
,
3056 GLenum internalFormat
, GLenum format
, GLenum type
)
3060 /* see if we've already chosen a format for the previous level */
3062 struct gl_texture_image
*prevImage
=
3063 _mesa_select_tex_image(texObj
, target
, level
- 1);
3064 /* See if the prev level is defined and has an internal format which
3065 * matches the new internal format.
3068 prevImage
->Width
> 0 &&
3069 prevImage
->InternalFormat
== internalFormat
) {
3070 /* use the same format */
3071 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3072 return prevImage
->TexFormat
;
3076 /* If the application requested compression to an S3TC format but we don't
3077 * have the DXTn library, force a generic compressed format instead.
3079 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3080 const GLenum before
= internalFormat
;
3082 switch (internalFormat
) {
3083 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3084 if (!ctx
->Mesa_DXTn
)
3085 internalFormat
= GL_COMPRESSED_RGB
;
3087 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3088 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3089 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3090 if (!ctx
->Mesa_DXTn
)
3091 internalFormat
= GL_COMPRESSED_RGBA
;
3097 if (before
!= internalFormat
) {
3099 "DXT compression requested (%s), "
3100 "but libtxc_dxtn library not installed. Using %s "
3102 _mesa_lookup_enum_by_nr(before
),
3103 _mesa_lookup_enum_by_nr(internalFormat
));
3107 /* choose format from scratch */
3108 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3110 assert(f
!= MESA_FORMAT_NONE
);
3116 * Adjust pixel unpack params and image dimensions to strip off the
3117 * one-pixel texture border.
3119 * Gallium and intel don't support texture borders. They've seldem been used
3120 * and seldom been implemented correctly anyway.
3122 * \param unpackNew returns the new pixel unpack parameters
3125 strip_texture_border(GLenum target
,
3126 GLint
*width
, GLint
*height
, GLint
*depth
,
3127 const struct gl_pixelstore_attrib
*unpack
,
3128 struct gl_pixelstore_attrib
*unpackNew
)
3134 *unpackNew
= *unpack
;
3136 if (unpackNew
->RowLength
== 0)
3137 unpackNew
->RowLength
= *width
;
3139 if (unpackNew
->ImageHeight
== 0)
3140 unpackNew
->ImageHeight
= *height
;
3142 assert(*width
>= 3);
3143 unpackNew
->SkipPixels
++; /* skip the border */
3144 *width
= *width
- 2; /* reduce the width by two border pixels */
3146 /* The min height of a texture with a border is 3 */
3147 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3148 unpackNew
->SkipRows
++; /* skip the border */
3149 *height
= *height
- 2; /* reduce the height by two border pixels */
3153 target
!= GL_TEXTURE_2D_ARRAY
&&
3154 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3155 unpackNew
->SkipImages
++; /* skip the border */
3156 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3162 * Common code to implement all the glTexImage1D/2D/3D functions
3163 * as well as glCompressedTexImage1D/2D/3D.
3164 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3165 * \param format the user's image format (only used if !compressed)
3166 * \param type the user's image type (only used if !compressed)
3167 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3170 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3171 GLenum target
, GLint level
, GLint internalFormat
,
3172 GLsizei width
, GLsizei height
, GLsizei depth
,
3173 GLint border
, GLenum format
, GLenum type
,
3174 GLsizei imageSize
, const GLvoid
*pixels
)
3176 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3177 struct gl_pixelstore_attrib unpack_no_border
;
3178 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3179 struct gl_texture_object
*texObj
;
3180 mesa_format texFormat
;
3181 GLboolean dimensionsOK
, sizeOK
;
3183 FLUSH_VERTICES(ctx
, 0);
3185 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3188 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3190 _mesa_lookup_enum_by_nr(target
), level
,
3191 _mesa_lookup_enum_by_nr(internalFormat
),
3192 width
, height
, depth
, border
, pixels
);
3195 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3197 _mesa_lookup_enum_by_nr(target
), level
,
3198 _mesa_lookup_enum_by_nr(internalFormat
),
3199 width
, height
, depth
, border
,
3200 _mesa_lookup_enum_by_nr(format
),
3201 _mesa_lookup_enum_by_nr(type
), pixels
);
3204 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3206 /* target error checking */
3207 if (!legal_teximage_target(ctx
, dims
, target
)) {
3208 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3209 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3213 /* general error checking */
3215 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3217 width
, height
, depth
,
3222 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3223 format
, type
, width
, height
, depth
, border
))
3227 /* Here we convert a cpal compressed image into a regular glTexImage2D
3228 * call by decompressing the texture. If we really want to support cpal
3229 * textures in any driver this would have to be changed.
3231 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3232 switch (internalFormat
) {
3233 case GL_PALETTE4_RGB8_OES
:
3234 case GL_PALETTE4_RGBA8_OES
:
3235 case GL_PALETTE4_R5_G6_B5_OES
:
3236 case GL_PALETTE4_RGBA4_OES
:
3237 case GL_PALETTE4_RGB5_A1_OES
:
3238 case GL_PALETTE8_RGB8_OES
:
3239 case GL_PALETTE8_RGBA8_OES
:
3240 case GL_PALETTE8_R5_G6_B5_OES
:
3241 case GL_PALETTE8_RGBA4_OES
:
3242 case GL_PALETTE8_RGB5_A1_OES
:
3243 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3244 width
, height
, imageSize
, pixels
);
3249 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3253 /* For glCompressedTexImage() the driver has no choice about the
3254 * texture format since we'll never transcode the user's compressed
3255 * image data. The internalFormat was error checked earlier.
3257 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3260 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3261 * internal floating point format for the given base format.
3263 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3264 if (type
== GL_FLOAT
) {
3265 texObj
->_IsFloat
= GL_TRUE
;
3266 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3267 texObj
->_IsHalfFloat
= GL_TRUE
;
3270 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3273 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3274 internalFormat
, format
, type
);
3277 assert(texFormat
!= MESA_FORMAT_NONE
);
3279 /* check that width, height, depth are legal for the mipmap level */
3280 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3281 height
, depth
, border
);
3283 /* check that the texture won't take too much memory, etc */
3284 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3286 width
, height
, depth
, border
);
3288 if (_mesa_is_proxy_texture(target
)) {
3289 /* Proxy texture: just clear or set state depending on error checking */
3290 struct gl_texture_image
*texImage
=
3291 get_proxy_tex_image(ctx
, target
, level
);
3294 return; /* GL_OUT_OF_MEMORY already recorded */
3296 if (dimensionsOK
&& sizeOK
) {
3297 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3298 border
, internalFormat
, texFormat
);
3301 clear_teximage_fields(texImage
);
3305 /* non-proxy target */
3306 const GLuint face
= _mesa_tex_target_to_face(target
);
3307 struct gl_texture_image
*texImage
;
3309 if (!dimensionsOK
) {
3310 _mesa_error(ctx
, GL_INVALID_VALUE
,
3311 "glTexImage%uD(invalid width or height or depth)",
3317 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3318 "glTexImage%uD(image too large)", dims
);
3322 /* Allow a hardware driver to just strip out the border, to provide
3323 * reliable but slightly incorrect hardware rendering instead of
3324 * rarely-tested software fallback rendering.
3326 if (border
&& ctx
->Const
.StripTextureBorder
) {
3327 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3330 unpack
= &unpack_no_border
;
3333 if (ctx
->NewState
& _NEW_PIXEL
)
3334 _mesa_update_state(ctx
);
3336 _mesa_lock_texture(ctx
, texObj
);
3338 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3341 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3344 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3346 _mesa_init_teximage_fields(ctx
, texImage
,
3347 width
, height
, depth
,
3348 border
, internalFormat
, texFormat
);
3350 /* Give the texture to the driver. <pixels> may be null. */
3351 if (width
> 0 && height
> 0 && depth
> 0) {
3353 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3357 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3358 type
, pixels
, unpack
);
3362 check_gen_mipmap(ctx
, target
, texObj
, level
);
3364 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3366 _mesa_dirty_texobj(ctx
, texObj
);
3369 _mesa_unlock_texture(ctx
, texObj
);
3376 * Called from the API. Note that width includes the border.
3379 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3380 GLsizei width
, GLint border
, GLenum format
,
3381 GLenum type
, const GLvoid
*pixels
)
3383 GET_CURRENT_CONTEXT(ctx
);
3384 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3385 border
, format
, type
, 0, pixels
);
3390 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3391 GLsizei width
, GLsizei height
, GLint border
,
3392 GLenum format
, GLenum type
,
3393 const GLvoid
*pixels
)
3395 GET_CURRENT_CONTEXT(ctx
);
3396 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3397 border
, format
, type
, 0, pixels
);
3402 * Called by the API or display list executor.
3403 * Note that width and height include the border.
3406 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3407 GLsizei width
, GLsizei height
, GLsizei depth
,
3408 GLint border
, GLenum format
, GLenum type
,
3409 const GLvoid
*pixels
)
3411 GET_CURRENT_CONTEXT(ctx
);
3412 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3413 width
, height
, depth
,
3414 border
, format
, type
, 0, pixels
);
3419 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3420 GLsizei width
, GLsizei height
, GLsizei depth
,
3421 GLint border
, GLenum format
, GLenum type
,
3422 const GLvoid
*pixels
)
3424 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3425 depth
, border
, format
, type
, pixels
);
3430 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3432 struct gl_texture_object
*texObj
;
3433 struct gl_texture_image
*texImage
;
3435 GET_CURRENT_CONTEXT(ctx
);
3436 FLUSH_VERTICES(ctx
, 0);
3440 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3442 case GL_TEXTURE_EXTERNAL_OES
:
3444 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3447 valid_target
= false;
3451 if (!valid_target
) {
3452 _mesa_error(ctx
, GL_INVALID_ENUM
,
3453 "glEGLImageTargetTexture2D(target=%d)", target
);
3458 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3459 "glEGLImageTargetTexture2D(image=%p)", image
);
3463 if (ctx
->NewState
& _NEW_PIXEL
)
3464 _mesa_update_state(ctx
);
3466 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3470 _mesa_lock_texture(ctx
, texObj
);
3472 if (texObj
->Immutable
) {
3473 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3474 "glEGLImageTargetTexture2D(texture is immutable)");
3475 _mesa_unlock_texture(ctx
, texObj
);
3479 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3481 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3483 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3485 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3486 texObj
, texImage
, image
);
3488 _mesa_dirty_texobj(ctx
, texObj
);
3490 _mesa_unlock_texture(ctx
, texObj
);
3496 * Helper that implements the glTexSubImage1/2/3D()
3497 * and glTextureSubImage1/2/3D() functions.
3500 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3501 struct gl_texture_object
*texObj
,
3502 struct gl_texture_image
*texImage
,
3503 GLenum target
, GLint level
,
3504 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3505 GLsizei width
, GLsizei height
, GLsizei depth
,
3506 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3509 FLUSH_VERTICES(ctx
, 0);
3511 /* check target (proxies not allowed) */
3512 if (!legal_texsubimage_target(ctx
, dims
, target
, dsa
)) {
3513 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sSubImage%uD(target=%s)",
3515 dims
, _mesa_lookup_enum_by_nr(target
));
3519 if (ctx
->NewState
& _NEW_PIXEL
)
3520 _mesa_update_state(ctx
);
3522 _mesa_lock_texture(ctx
, texObj
);
3524 if (width
> 0 && height
> 0 && depth
> 0) {
3525 /* If we have a border, offset=-1 is legal. Bias by border width. */
3528 if (target
!= GL_TEXTURE_2D_ARRAY
)
3529 zoffset
+= texImage
->Border
;
3532 if (target
!= GL_TEXTURE_1D_ARRAY
)
3533 yoffset
+= texImage
->Border
;
3536 xoffset
+= texImage
->Border
;
3539 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3540 xoffset
, yoffset
, zoffset
,
3541 width
, height
, depth
,
3542 format
, type
, pixels
, &ctx
->Unpack
);
3544 check_gen_mipmap(ctx
, target
, texObj
, level
);
3546 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3547 * the texel data, not the texture format, size, etc.
3551 _mesa_unlock_texture(ctx
, texObj
);
3555 * Implement all the glTexSubImage1/2/3D() functions.
3556 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3559 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3560 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3561 GLsizei width
, GLsizei height
, GLsizei depth
,
3562 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3564 struct gl_texture_object
*texObj
;
3565 struct gl_texture_image
*texImage
;
3567 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3571 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3572 xoffset
, yoffset
, zoffset
,
3573 width
, height
, depth
, format
, type
, false)) {
3574 return; /* error was detected */
3577 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3578 /* texsubimage_error_check ensures that texImage is not NULL */
3580 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3581 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3583 _mesa_lookup_enum_by_nr(target
), level
,
3584 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3585 _mesa_lookup_enum_by_nr(format
),
3586 _mesa_lookup_enum_by_nr(type
), pixels
);
3588 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3589 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3590 format
, type
, pixels
, false);
3595 * Implement all the glTextureSubImage1/2/3D() functions.
3596 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3599 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3600 GLuint texture
, GLint level
,
3601 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3602 GLsizei width
, GLsizei height
, GLsizei depth
,
3603 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3605 struct gl_texture_object
*texObj
;
3606 struct gl_texture_image
*texImage
;
3609 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3611 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3612 dims
, texture
, level
,
3613 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3614 _mesa_lookup_enum_by_nr(format
),
3615 _mesa_lookup_enum_by_nr(type
), pixels
);
3617 /* Get the texture object by Name. */
3618 texObj
= _mesa_lookup_texture(ctx
, texture
);
3620 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3625 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3626 xoffset
, yoffset
, zoffset
,
3627 width
, height
, depth
, format
, type
, true)) {
3628 return; /* error was detected */
3632 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3633 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3636 /* Error checking */
3637 if (texObj
->NumLayers
< 6) {
3638 /* Not enough image planes for a cube map. The spec does not say
3639 * what should happen in this case because the user has always
3640 * specified each cube face separately (using
3641 * GL_TEXTURE_CUBE_MAP_POSITIVE_X+i) in previous GL versions.
3642 * This is addressed in Khronos Bug 13223.
3644 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3645 "glTextureSubImage%uD(insufficient cube map storage)",
3651 * What do we do if the user created a texture with the following code
3652 * and then called this function with its handle?
3655 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3656 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3657 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3658 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3659 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3660 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3661 * // wrong format, or given the wrong size, etc.
3662 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3663 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3665 * A bug has been filed against the spec for this case. In the
3666 * meantime, we will check for cube completeness.
3668 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3669 * Core Profile spec (30.10.2014):
3670 * "[A] cube map texture is cube complete if the
3671 * following conditions all hold true: The [base level] texture
3672 * images of each of the six cube map faces have identical, positive,
3673 * and square dimensions. The [base level] images were each specified
3674 * with the same internal format."
3676 * It seems reasonable to check for cube completeness of an arbitrary
3677 * level here so that the image data has a consistent format and size.
3679 if (!_mesa_cube_level_complete(texObj
, level
)) {
3680 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3681 "glTextureSubImage%uD(cube map incomplete)",
3686 rowStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3688 /* Copy in each face. */
3689 for (i
= 0; i
< 6; ++i
) {
3690 texImage
= texObj
->Image
[i
][level
];
3691 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3692 level
, xoffset
, yoffset
, zoffset
,
3693 width
, height
, 1, format
,
3694 type
, pixels
, true);
3695 pixels
= (GLubyte
*) pixels
+ rowStride
;
3699 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3703 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3704 level
, xoffset
, yoffset
, zoffset
,
3705 width
, height
, depth
, format
,
3706 type
, pixels
, true);
3712 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3713 GLint xoffset
, GLsizei width
,
3714 GLenum format
, GLenum type
,
3715 const GLvoid
*pixels
)
3717 GET_CURRENT_CONTEXT(ctx
);
3718 texsubimage(ctx
, 1, target
, level
,
3721 format
, type
, pixels
);
3726 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3727 GLint xoffset
, GLint yoffset
,
3728 GLsizei width
, GLsizei height
,
3729 GLenum format
, GLenum type
,
3730 const GLvoid
*pixels
)
3732 GET_CURRENT_CONTEXT(ctx
);
3733 texsubimage(ctx
, 2, target
, level
,
3734 xoffset
, yoffset
, 0,
3736 format
, type
, pixels
);
3742 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3743 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3744 GLsizei width
, GLsizei height
, GLsizei depth
,
3745 GLenum format
, GLenum type
,
3746 const GLvoid
*pixels
)
3748 GET_CURRENT_CONTEXT(ctx
);
3749 texsubimage(ctx
, 3, target
, level
,
3750 xoffset
, yoffset
, zoffset
,
3751 width
, height
, depth
,
3752 format
, type
, pixels
);
3756 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3757 GLint xoffset
, GLsizei width
,
3758 GLenum format
, GLenum type
,
3759 const GLvoid
*pixels
)
3761 GET_CURRENT_CONTEXT(ctx
);
3762 texturesubimage(ctx
, 1, texture
, level
,
3765 format
, type
, pixels
);
3770 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3771 GLint xoffset
, GLint yoffset
,
3772 GLsizei width
, GLsizei height
,
3773 GLenum format
, GLenum type
,
3774 const GLvoid
*pixels
)
3776 GET_CURRENT_CONTEXT(ctx
);
3777 texturesubimage(ctx
, 2, texture
, level
,
3778 xoffset
, yoffset
, 0,
3780 format
, type
, pixels
);
3785 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3786 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3787 GLsizei width
, GLsizei height
, GLsizei depth
,
3788 GLenum format
, GLenum type
,
3789 const GLvoid
*pixels
)
3791 GET_CURRENT_CONTEXT(ctx
);
3792 texturesubimage(ctx
, 3, texture
, level
,
3793 xoffset
, yoffset
, zoffset
,
3794 width
, height
, depth
,
3795 format
, type
, pixels
);
3800 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3801 * from. This depends on whether the texture contains color or depth values.
3803 static struct gl_renderbuffer
*
3804 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3806 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3807 /* reading from depth/stencil buffer */
3808 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3811 /* copying from color buffer */
3812 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3817 copytexsubimage_by_slice(struct gl_context
*ctx
,
3818 struct gl_texture_image
*texImage
,
3820 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3821 struct gl_renderbuffer
*rb
,
3823 GLsizei width
, GLsizei height
)
3825 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3828 /* For 1D arrays, we copy each scanline of the source rectangle into the
3831 assert(zoffset
== 0);
3833 for (slice
= 0; slice
< height
; slice
++) {
3834 assert(yoffset
+ slice
< texImage
->Height
);
3835 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3836 xoffset
, 0, yoffset
+ slice
,
3837 rb
, x
, y
+ slice
, width
, 1);
3840 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3841 xoffset
, yoffset
, zoffset
,
3842 rb
, x
, y
, width
, height
);
3847 formats_differ_in_component_sizes (mesa_format f1
,
3850 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3851 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3852 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3853 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3855 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3856 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3857 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3858 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3860 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3861 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3862 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3863 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3870 * Implement the glCopyTexImage1/2D() functions.
3873 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3874 GLenum target
, GLint level
, GLenum internalFormat
,
3875 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3877 struct gl_texture_object
*texObj
;
3878 struct gl_texture_image
*texImage
;
3879 const GLuint face
= _mesa_tex_target_to_face(target
);
3880 mesa_format texFormat
;
3881 struct gl_renderbuffer
*rb
;
3883 FLUSH_VERTICES(ctx
, 0);
3885 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3886 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3888 _mesa_lookup_enum_by_nr(target
), level
,
3889 _mesa_lookup_enum_by_nr(internalFormat
),
3890 x
, y
, width
, height
, border
);
3892 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3893 _mesa_update_state(ctx
);
3895 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3896 width
, height
, border
))
3899 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3901 _mesa_error(ctx
, GL_INVALID_VALUE
,
3902 "glCopyTexImage%uD(invalid width or height)", dims
);
3906 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3909 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3910 internalFormat
, GL_NONE
, GL_NONE
);
3912 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3914 if (_mesa_is_gles3(ctx
)) {
3915 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3916 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3917 * OpenGL ES 3.0. Khronos bug# 9807.
3919 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3920 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3921 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer and"
3922 " writing to unsized internal format)", dims
);
3926 /* From Page 139 of OpenGL ES 3.0 spec:
3927 * "If internalformat is sized, the internal format of the new texel
3928 * array is internalformat, and this is also the new texel array’s
3929 * effective internal format. If the component sizes of internalformat
3930 * do not exactly match the corresponding component sizes of the source
3931 * buffer’s effective internal format, described below, an
3932 * INVALID_OPERATION error is generated. If internalformat is unsized,
3933 * the internal format of the new texel array is the effective internal
3934 * format of the source buffer, and this is also the new texel array’s
3935 * effective internal format.
3937 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3938 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3939 "glCopyTexImage%uD(componenet size changed in"
3940 " internal format)", dims
);
3945 assert(texFormat
!= MESA_FORMAT_NONE
);
3947 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3949 width
, height
, 1, border
)) {
3950 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3951 "glCopyTexImage%uD(image too large)", dims
);
3955 if (border
&& ctx
->Const
.StripTextureBorder
) {
3957 width
-= border
* 2;
3960 height
-= border
* 2;
3965 _mesa_lock_texture(ctx
, texObj
);
3967 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3970 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3973 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3975 /* Free old texture image */
3976 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3978 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3979 border
, internalFormat
, texFormat
);
3981 if (width
&& height
) {
3982 /* Allocate texture memory (no pixel data yet) */
3983 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3985 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3987 struct gl_renderbuffer
*srcRb
=
3988 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3990 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3992 srcRb
, srcX
, srcY
, width
, height
);
3995 check_gen_mipmap(ctx
, target
, texObj
, level
);
3998 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4000 _mesa_dirty_texobj(ctx
, texObj
);
4003 _mesa_unlock_texture(ctx
, texObj
);
4009 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4010 GLenum internalFormat
,
4012 GLsizei width
, GLint border
)
4014 GET_CURRENT_CONTEXT(ctx
);
4015 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4021 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4022 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4025 GET_CURRENT_CONTEXT(ctx
);
4026 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4027 x
, y
, width
, height
, border
);
4031 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4034 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4035 struct gl_texture_object
*texObj
,
4036 GLenum target
, GLint level
,
4037 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4039 GLsizei width
, GLsizei height
,
4042 struct gl_texture_image
*texImage
;
4044 FLUSH_VERTICES(ctx
, 0);
4046 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4047 _mesa_debug(ctx
, "glCopyTex%sSubImage%uD %s %d %d %d %d %d %d %d %d\n",
4048 dsa
? "ture" : "", dims
,
4049 _mesa_lookup_enum_by_nr(target
),
4050 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4052 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4053 _mesa_update_state(ctx
);
4055 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4056 xoffset
, yoffset
, zoffset
,
4057 width
, height
, dsa
)) {
4061 _mesa_lock_texture(ctx
, texObj
);
4063 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4065 /* If we have a border, offset=-1 is legal. Bias by border width. */
4068 if (target
!= GL_TEXTURE_2D_ARRAY
)
4069 zoffset
+= texImage
->Border
;
4072 if (target
!= GL_TEXTURE_1D_ARRAY
)
4073 yoffset
+= texImage
->Border
;
4076 xoffset
+= texImage
->Border
;
4079 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4081 struct gl_renderbuffer
*srcRb
=
4082 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4084 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4085 xoffset
, yoffset
, zoffset
,
4086 srcRb
, x
, y
, width
, height
);
4088 check_gen_mipmap(ctx
, target
, texObj
, level
);
4090 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4091 * the texel data, not the texture format, size, etc.
4095 _mesa_unlock_texture(ctx
, texObj
);
4099 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4100 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4102 struct gl_texture_object
* texObj
;
4103 GET_CURRENT_CONTEXT(ctx
);
4105 /* Check target (proxies not allowed). Target must be checked prior to
4106 * calling _mesa_get_current_tex_object.
4108 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4109 _mesa_error(ctx
, GL_INVALID_ENUM
,
4110 "glCopyTexSubImage1D(invalid target %s)",
4111 _mesa_lookup_enum_by_nr(target
));
4115 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4119 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4120 x
, y
, width
, 1, false);
4126 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4127 GLint xoffset
, GLint yoffset
,
4128 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4130 struct gl_texture_object
* texObj
;
4131 GET_CURRENT_CONTEXT(ctx
);
4133 /* Check target (proxies not allowed). Target must be checked prior to
4134 * calling _mesa_get_current_tex_object.
4136 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4137 _mesa_error(ctx
, GL_INVALID_ENUM
,
4138 "glCopyTexSubImage2D(invalid target %s)",
4139 _mesa_lookup_enum_by_nr(target
));
4143 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4147 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4148 xoffset
, yoffset
, 0,
4149 x
, y
, width
, height
, false);
4155 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4156 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4157 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4159 struct gl_texture_object
* texObj
;
4160 GET_CURRENT_CONTEXT(ctx
);
4162 /* Check target (proxies not allowed). Target must be checked prior to
4163 * calling _mesa_get_current_tex_object.
4165 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4166 _mesa_error(ctx
, GL_INVALID_ENUM
,
4167 "glCopyTexSubImage3D(invalid target %s)",
4168 _mesa_lookup_enum_by_nr(target
));
4172 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4176 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4177 xoffset
, yoffset
, zoffset
,
4178 x
, y
, width
, height
, false);
4182 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4183 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4185 struct gl_texture_object
* texObj
;
4186 GET_CURRENT_CONTEXT(ctx
);
4188 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage1D");
4192 /* Check target (proxies not allowed). */
4193 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4194 _mesa_error(ctx
, GL_INVALID_ENUM
,
4195 "glCopyTextureSubImage1D(invalid target %s)",
4196 _mesa_lookup_enum_by_nr(texObj
->Target
));
4200 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4201 xoffset
, 0, 0, x
, y
, width
, 1, true);
4205 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4206 GLint xoffset
, GLint yoffset
,
4207 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4209 struct gl_texture_object
* texObj
;
4210 GET_CURRENT_CONTEXT(ctx
);
4212 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage2D");
4216 /* Check target (proxies not allowed). */
4217 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4218 _mesa_error(ctx
, GL_INVALID_ENUM
,
4219 "glCopyTextureSubImage2D(invalid target %s)",
4220 _mesa_lookup_enum_by_nr(texObj
->Target
));
4224 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4225 xoffset
, yoffset
, 0,
4226 x
, y
, width
, height
, true);
4232 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4233 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4234 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4236 struct gl_texture_object
* texObj
;
4237 GET_CURRENT_CONTEXT(ctx
);
4239 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage3D");
4243 /* Check target (proxies not allowed). */
4244 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4245 _mesa_error(ctx
, GL_INVALID_ENUM
,
4246 "glCopyTextureSubImage3D(invalid target %s)",
4247 _mesa_lookup_enum_by_nr(texObj
->Target
));
4251 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4252 xoffset
, yoffset
, zoffset
,
4253 x
, y
, width
, height
, true);
4257 check_clear_tex_image(struct gl_context
*ctx
,
4258 const char *function
,
4259 struct gl_texture_image
*texImage
,
4260 GLenum format
, GLenum type
,
4262 GLubyte
*clearValue
)
4264 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4265 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4266 GLenum internalFormat
= texImage
->InternalFormat
;
4269 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4270 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4271 "%s(buffer texture)", function
);
4275 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4276 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4277 "%s(compressed texture)", function
);
4281 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4282 if (err
!= GL_NO_ERROR
) {
4283 _mesa_error(ctx
, err
,
4284 "%s(incompatible format = %s, type = %s)",
4286 _mesa_lookup_enum_by_nr(format
),
4287 _mesa_lookup_enum_by_nr(type
));
4291 /* make sure internal format and format basically agree */
4292 if (!texture_formats_agree(internalFormat
, format
)) {
4293 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4294 "%s(incompatible internalFormat = %s, format = %s)",
4296 _mesa_lookup_enum_by_nr(internalFormat
),
4297 _mesa_lookup_enum_by_nr(format
));
4301 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4302 /* both source and dest must be integer-valued, or neither */
4303 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4304 _mesa_is_enum_format_integer(format
)) {
4305 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4306 "%s(integer/non-integer format mismatch)",
4312 if (!_mesa_texstore(ctx
,
4314 texImage
->_BaseFormat
,
4315 texImage
->TexFormat
,
4316 0, /* dstRowStride */
4318 1, 1, 1, /* srcWidth/Height/Depth */
4320 data
? data
: zeroData
,
4321 &ctx
->DefaultPacking
)) {
4322 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4329 static struct gl_texture_object
*
4330 get_tex_obj_for_clear(struct gl_context
*ctx
,
4331 const char *function
,
4334 struct gl_texture_object
*texObj
;
4337 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4341 texObj
= _mesa_lookup_texture(ctx
, texture
);
4343 if (texObj
== NULL
) {
4344 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4348 if (texObj
->Target
== 0) {
4349 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4357 get_tex_images_for_clear(struct gl_context
*ctx
,
4358 const char *function
,
4359 struct gl_texture_object
*texObj
,
4361 struct gl_texture_image
**texImages
)
4366 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4367 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4371 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4372 for (i
= 0; i
< MAX_FACES
; i
++) {
4373 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4375 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4376 if (texImages
[i
] == NULL
) {
4377 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4378 "%s(invalid level)", function
);
4386 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4388 if (texImages
[0] == NULL
) {
4389 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4397 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4398 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4399 GLsizei width
, GLsizei height
, GLsizei depth
,
4400 GLenum format
, GLenum type
, const void *data
)
4402 GET_CURRENT_CONTEXT(ctx
);
4403 struct gl_texture_object
*texObj
;
4404 struct gl_texture_image
*texImages
[MAX_FACES
];
4405 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4407 int minDepth
, maxDepth
;
4409 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4414 _mesa_lock_texture(ctx
, texObj
);
4416 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4417 texObj
, level
, texImages
);
4421 if (numImages
== 1) {
4422 minDepth
= -(int) texImages
[0]->Border
;
4423 maxDepth
= texImages
[0]->Depth
;
4426 maxDepth
= numImages
;
4429 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4430 yoffset
< -(GLint
) texImages
[0]->Border
||
4431 zoffset
< minDepth
||
4435 xoffset
+ width
> texImages
[0]->Width
||
4436 yoffset
+ height
> texImages
[0]->Height
||
4437 zoffset
+ depth
> maxDepth
) {
4438 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4439 "glClearSubTexImage(invalid dimensions)");
4443 if (numImages
== 1) {
4444 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4446 format
, type
, data
, clearValue
[0])) {
4447 ctx
->Driver
.ClearTexSubImage(ctx
,
4449 xoffset
, yoffset
, zoffset
,
4450 width
, height
, depth
,
4451 data
? clearValue
[0] : NULL
);
4454 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4455 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4457 format
, type
, data
, clearValue
[i
]))
4460 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4461 ctx
->Driver
.ClearTexSubImage(ctx
,
4463 xoffset
, yoffset
, 0,
4465 data
? clearValue
[i
] : NULL
);
4470 _mesa_unlock_texture(ctx
, texObj
);
4474 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4475 GLenum format
, GLenum type
, const void *data
)
4477 GET_CURRENT_CONTEXT(ctx
);
4478 struct gl_texture_object
*texObj
;
4479 struct gl_texture_image
*texImages
[MAX_FACES
];
4480 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4483 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4488 _mesa_lock_texture(ctx
, texObj
);
4490 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4491 texObj
, level
, texImages
);
4493 for (i
= 0; i
< numImages
; i
++) {
4494 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4501 for (i
= 0; i
< numImages
; i
++) {
4502 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4503 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4504 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4505 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4506 texImages
[i
]->Width
,
4507 texImages
[i
]->Height
,
4508 texImages
[i
]->Depth
,
4509 data
? clearValue
[i
] : NULL
);
4513 _mesa_unlock_texture(ctx
, texObj
);
4519 /**********************************************************************/
4520 /****** Compressed Textures ******/
4521 /**********************************************************************/
4525 * Target checking for glCompressedTexSubImage[123]D().
4526 * \return GL_TRUE if error, GL_FALSE if no error
4527 * Must come before other error checking so that the texture object can
4528 * be correctly retrieved using _mesa_get_current_tex_object.
4531 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4532 GLint dims
, GLenum format
, bool dsa
,
4537 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4538 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4539 _mesa_lookup_enum_by_nr(target
));
4547 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4548 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4549 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4550 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4551 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4552 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4556 targetOK
= GL_FALSE
;
4561 targetOK
= (target
== GL_TEXTURE_3D
) ||
4562 (target
== GL_TEXTURE_2D_ARRAY
) ||
4563 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
4564 (target
== GL_TEXTURE_CUBE_MAP
&& dsa
);
4566 /* OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4568 * "An INVALID_OPERATION error is generated by
4569 * CompressedTex*SubImage3D if the internal format of the texture is
4570 * one of the EAC, ETC2, or RGTC formats and either border is
4571 * non-zero, or the effective target for the texture is not
4572 * TEXTURE_2D_ARRAY."
4574 if (target
!= GL_TEXTURE_2D_ARRAY
) {
4577 /* These came from _mesa_is_compressed_format in glformats.c. */
4579 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
4580 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
4581 case GL_COMPRESSED_R11_EAC
:
4582 case GL_COMPRESSED_RG11_EAC
:
4583 case GL_COMPRESSED_SIGNED_R11_EAC
:
4584 case GL_COMPRESSED_SIGNED_RG11_EAC
:
4586 case GL_COMPRESSED_RGB8_ETC2
:
4587 case GL_COMPRESSED_SRGB8_ETC2
:
4588 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
4589 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
4591 case GL_COMPRESSED_RED_RGTC1
:
4592 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
4593 case GL_COMPRESSED_RG_RGTC2
:
4594 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
4595 invalidformat
= true;
4598 invalidformat
= false;
4600 if (invalidformat
) {
4601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4602 "%s(invalid target %s for format %s)", caller
,
4603 _mesa_lookup_enum_by_nr(target
),
4604 _mesa_lookup_enum_by_nr(format
));
4612 /* no 1D compressed textures at this time */
4613 targetOK
= GL_FALSE
;
4618 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4619 _mesa_lookup_enum_by_nr(target
));
4627 * Error checking for glCompressedTexSubImage[123]D().
4628 * \return GL_TRUE if error, GL_FALSE if no error
4631 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4632 const struct gl_texture_object
*texObj
,
4633 GLenum target
, GLint level
,
4634 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4635 GLsizei width
, GLsizei height
, GLsizei depth
,
4636 GLenum format
, GLsizei imageSize
, bool dsa
)
4638 struct gl_texture_image
*texImage
;
4640 const char *suffix
= dsa
? "ture" : "";
4642 /* this will catch any invalid compressed format token */
4643 if (!_mesa_is_compressed_format(ctx
, format
)) {
4644 _mesa_error(ctx
, GL_INVALID_ENUM
,
4645 "glCompressedTex%sSubImage%uD(format)", suffix
, dims
);
4649 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4650 _mesa_error(ctx
, GL_INVALID_VALUE
,
4651 "glCompressedTex%sSubImage%uD(level=%d)",
4652 suffix
, dims
, level
);
4656 /* Check for invalid pixel storage modes */
4657 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4659 dsa
? "glCompressedTextureSubImage" :
4660 "glCompressedTexSubImage")) {
4664 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4665 if (expectedSize
!= imageSize
) {
4666 _mesa_error(ctx
, GL_INVALID_VALUE
,
4667 "glCompressedTex%sSubImage%uD(size=%d)",
4668 suffix
, dims
, imageSize
);
4672 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4674 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4675 "glCompressedTex%sSubImage%uD(invalid texture image)",
4680 if ((GLint
) format
!= texImage
->InternalFormat
) {
4681 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4682 "glCompressedTex%sSubImage%uD(format=0x%x)",
4683 suffix
, dims
, format
);
4687 if (compressedteximage_only_format(ctx
, format
)) {
4688 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4689 "glCompressedTex%sSubImage%uD(format=0x%x cannot be updated)",
4690 suffix
, dims
, format
);
4694 if (error_check_subtexture_dimensions(ctx
, dims
,
4695 texImage
, xoffset
, yoffset
, zoffset
,
4696 width
, height
, depth
,
4697 "glCompressedTexSubImage")) {
4706 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4707 GLenum internalFormat
, GLsizei width
,
4708 GLint border
, GLsizei imageSize
,
4711 GET_CURRENT_CONTEXT(ctx
);
4712 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4713 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4718 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4719 GLenum internalFormat
, GLsizei width
,
4720 GLsizei height
, GLint border
, GLsizei imageSize
,
4723 GET_CURRENT_CONTEXT(ctx
);
4724 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4725 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4730 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4731 GLenum internalFormat
, GLsizei width
,
4732 GLsizei height
, GLsizei depth
, GLint border
,
4733 GLsizei imageSize
, const GLvoid
*data
)
4735 GET_CURRENT_CONTEXT(ctx
);
4736 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4737 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4742 * Common helper for glCompressedTexSubImage1/2/3D() and
4743 * glCompressedTextureSubImage1/2/3D().
4746 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4747 struct gl_texture_object
*texObj
,
4748 GLenum target
, GLint level
,
4749 GLint xoffset
, GLint yoffset
,
4751 GLsizei width
, GLsizei height
,
4753 GLenum format
, GLsizei imageSize
,
4754 const GLvoid
*data
, bool dsa
)
4756 struct gl_texture_image
*texImage
;
4758 if (compressed_subtexture_error_check(ctx
, dims
, texObj
, target
,
4759 level
, xoffset
, yoffset
, zoffset
,
4760 width
, height
, depth
,
4761 format
, imageSize
, dsa
)) {
4765 FLUSH_VERTICES(ctx
, 0);
4767 _mesa_lock_texture(ctx
, texObj
);
4769 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4772 if (width
> 0 && height
> 0 && depth
> 0) {
4773 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4774 xoffset
, yoffset
, zoffset
,
4775 width
, height
, depth
,
4776 format
, imageSize
, data
);
4778 check_gen_mipmap(ctx
, target
, texObj
, level
);
4780 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4781 * the texel data, not the texture format, size, etc.
4785 _mesa_unlock_texture(ctx
, texObj
);
4790 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4791 GLsizei width
, GLenum format
,
4792 GLsizei imageSize
, const GLvoid
*data
)
4794 struct gl_texture_object
*texObj
;
4795 GET_CURRENT_CONTEXT(ctx
);
4797 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4798 "glCompressedTexSubImage1D")) {
4802 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4806 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, target
, level
,
4807 xoffset
, 0, 0, width
, 1, 1,
4808 format
, imageSize
, data
, false);
4812 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4813 GLsizei width
, GLenum format
,
4814 GLsizei imageSize
, const GLvoid
*data
)
4816 struct gl_texture_object
*texObj
;
4817 GET_CURRENT_CONTEXT(ctx
);
4819 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4820 "glCompressedTextureSubImage1D");
4824 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
,
4826 "glCompressedTextureSubImage1D")) {
4830 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4831 xoffset
, 0, 0, width
, 1, 1,
4832 format
, imageSize
, data
, true);
4837 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4838 GLint yoffset
, GLsizei width
, GLsizei height
,
4839 GLenum format
, GLsizei imageSize
,
4842 struct gl_texture_object
*texObj
;
4843 GET_CURRENT_CONTEXT(ctx
);
4845 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
4846 "glCompressedTexSubImage2D")) {
4850 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4854 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4855 xoffset
, yoffset
, 0, width
, height
, 1,
4856 format
, imageSize
, data
, false);
4860 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
4862 GLsizei width
, GLsizei height
,
4863 GLenum format
, GLsizei imageSize
,
4866 struct gl_texture_object
*texObj
;
4867 GET_CURRENT_CONTEXT(ctx
);
4869 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4870 "glCompressedTextureSubImage2D");
4874 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
,
4876 "glCompressedTextureSubImage2D")) {
4880 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4881 xoffset
, yoffset
, 0, width
, height
, 1,
4882 format
, imageSize
, data
, true);
4886 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4887 GLint yoffset
, GLint zoffset
, GLsizei width
,
4888 GLsizei height
, GLsizei depth
, GLenum format
,
4889 GLsizei imageSize
, const GLvoid
*data
)
4891 struct gl_texture_object
*texObj
;
4892 GET_CURRENT_CONTEXT(ctx
);
4894 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
4895 "glCompressedTexSubImage3D")) {
4899 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4903 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4904 xoffset
, yoffset
, zoffset
,
4905 width
, height
, depth
,
4906 format
, imageSize
, data
, false);
4910 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
4911 GLint yoffset
, GLint zoffset
, GLsizei width
,
4912 GLsizei height
, GLsizei depth
,
4913 GLenum format
, GLsizei imageSize
,
4916 struct gl_texture_object
*texObj
;
4917 GET_CURRENT_CONTEXT(ctx
);
4919 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4920 "glCompressedTextureSubImage3D");
4924 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
,
4926 "glCompressedTextureSubImage3D")) {
4930 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4931 xoffset
, yoffset
, zoffset
,
4932 width
, height
, depth
,
4933 format
, imageSize
, data
, true);
4937 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4939 if (ctx
->API
!= API_OPENGL_CORE
) {
4940 switch (internalFormat
) {
4942 return MESA_FORMAT_A_UNORM8
;
4944 return MESA_FORMAT_A_UNORM16
;
4945 case GL_ALPHA16F_ARB
:
4946 return MESA_FORMAT_A_FLOAT16
;
4947 case GL_ALPHA32F_ARB
:
4948 return MESA_FORMAT_A_FLOAT32
;
4949 case GL_ALPHA8I_EXT
:
4950 return MESA_FORMAT_A_SINT8
;
4951 case GL_ALPHA16I_EXT
:
4952 return MESA_FORMAT_A_SINT16
;
4953 case GL_ALPHA32I_EXT
:
4954 return MESA_FORMAT_A_SINT32
;
4955 case GL_ALPHA8UI_EXT
:
4956 return MESA_FORMAT_A_UINT8
;
4957 case GL_ALPHA16UI_EXT
:
4958 return MESA_FORMAT_A_UINT16
;
4959 case GL_ALPHA32UI_EXT
:
4960 return MESA_FORMAT_A_UINT32
;
4962 return MESA_FORMAT_L_UNORM8
;
4963 case GL_LUMINANCE16
:
4964 return MESA_FORMAT_L_UNORM16
;
4965 case GL_LUMINANCE16F_ARB
:
4966 return MESA_FORMAT_L_FLOAT16
;
4967 case GL_LUMINANCE32F_ARB
:
4968 return MESA_FORMAT_L_FLOAT32
;
4969 case GL_LUMINANCE8I_EXT
:
4970 return MESA_FORMAT_L_SINT8
;
4971 case GL_LUMINANCE16I_EXT
:
4972 return MESA_FORMAT_L_SINT16
;
4973 case GL_LUMINANCE32I_EXT
:
4974 return MESA_FORMAT_L_SINT32
;
4975 case GL_LUMINANCE8UI_EXT
:
4976 return MESA_FORMAT_L_UINT8
;
4977 case GL_LUMINANCE16UI_EXT
:
4978 return MESA_FORMAT_L_UINT16
;
4979 case GL_LUMINANCE32UI_EXT
:
4980 return MESA_FORMAT_L_UINT32
;
4981 case GL_LUMINANCE8_ALPHA8
:
4982 return MESA_FORMAT_L8A8_UNORM
;
4983 case GL_LUMINANCE16_ALPHA16
:
4984 return MESA_FORMAT_L16A16_UNORM
;
4985 case GL_LUMINANCE_ALPHA16F_ARB
:
4986 return MESA_FORMAT_LA_FLOAT16
;
4987 case GL_LUMINANCE_ALPHA32F_ARB
:
4988 return MESA_FORMAT_LA_FLOAT32
;
4989 case GL_LUMINANCE_ALPHA8I_EXT
:
4990 return MESA_FORMAT_LA_SINT8
;
4991 case GL_LUMINANCE_ALPHA16I_EXT
:
4992 return MESA_FORMAT_LA_SINT16
;
4993 case GL_LUMINANCE_ALPHA32I_EXT
:
4994 return MESA_FORMAT_LA_SINT32
;
4995 case GL_LUMINANCE_ALPHA8UI_EXT
:
4996 return MESA_FORMAT_LA_UINT8
;
4997 case GL_LUMINANCE_ALPHA16UI_EXT
:
4998 return MESA_FORMAT_LA_UINT16
;
4999 case GL_LUMINANCE_ALPHA32UI_EXT
:
5000 return MESA_FORMAT_LA_UINT32
;
5002 return MESA_FORMAT_I_UNORM8
;
5003 case GL_INTENSITY16
:
5004 return MESA_FORMAT_I_UNORM16
;
5005 case GL_INTENSITY16F_ARB
:
5006 return MESA_FORMAT_I_FLOAT16
;
5007 case GL_INTENSITY32F_ARB
:
5008 return MESA_FORMAT_I_FLOAT32
;
5009 case GL_INTENSITY8I_EXT
:
5010 return MESA_FORMAT_I_SINT8
;
5011 case GL_INTENSITY16I_EXT
:
5012 return MESA_FORMAT_I_SINT16
;
5013 case GL_INTENSITY32I_EXT
:
5014 return MESA_FORMAT_I_SINT32
;
5015 case GL_INTENSITY8UI_EXT
:
5016 return MESA_FORMAT_I_UINT8
;
5017 case GL_INTENSITY16UI_EXT
:
5018 return MESA_FORMAT_I_UINT16
;
5019 case GL_INTENSITY32UI_EXT
:
5020 return MESA_FORMAT_I_UINT32
;
5026 if (ctx
->API
== API_OPENGL_CORE
&&
5027 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5028 switch (internalFormat
) {
5030 return MESA_FORMAT_RGB_FLOAT32
;
5032 return MESA_FORMAT_RGB_UINT32
;
5034 return MESA_FORMAT_RGB_SINT32
;
5040 switch (internalFormat
) {
5042 return MESA_FORMAT_R8G8B8A8_UNORM
;
5044 return MESA_FORMAT_RGBA_UNORM16
;
5045 case GL_RGBA16F_ARB
:
5046 return MESA_FORMAT_RGBA_FLOAT16
;
5047 case GL_RGBA32F_ARB
:
5048 return MESA_FORMAT_RGBA_FLOAT32
;
5050 return MESA_FORMAT_RGBA_SINT8
;
5051 case GL_RGBA16I_EXT
:
5052 return MESA_FORMAT_RGBA_SINT16
;
5053 case GL_RGBA32I_EXT
:
5054 return MESA_FORMAT_RGBA_SINT32
;
5055 case GL_RGBA8UI_EXT
:
5056 return MESA_FORMAT_RGBA_UINT8
;
5057 case GL_RGBA16UI_EXT
:
5058 return MESA_FORMAT_RGBA_UINT16
;
5059 case GL_RGBA32UI_EXT
:
5060 return MESA_FORMAT_RGBA_UINT32
;
5063 return MESA_FORMAT_R8G8_UNORM
;
5065 return MESA_FORMAT_R16G16_UNORM
;
5067 return MESA_FORMAT_RG_FLOAT16
;
5069 return MESA_FORMAT_RG_FLOAT32
;
5071 return MESA_FORMAT_RG_SINT8
;
5073 return MESA_FORMAT_RG_SINT16
;
5075 return MESA_FORMAT_RG_SINT32
;
5077 return MESA_FORMAT_RG_UINT8
;
5079 return MESA_FORMAT_RG_UINT16
;
5081 return MESA_FORMAT_RG_UINT32
;
5084 return MESA_FORMAT_R_UNORM8
;
5086 return MESA_FORMAT_R_UNORM16
;
5088 return MESA_FORMAT_R_FLOAT16
;
5090 return MESA_FORMAT_R_FLOAT32
;
5092 return MESA_FORMAT_R_SINT8
;
5094 return MESA_FORMAT_R_SINT16
;
5096 return MESA_FORMAT_R_SINT32
;
5098 return MESA_FORMAT_R_UINT8
;
5100 return MESA_FORMAT_R_UINT16
;
5102 return MESA_FORMAT_R_UINT32
;
5105 return MESA_FORMAT_NONE
;
5111 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5112 GLenum internalFormat
)
5114 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5117 if (format
== MESA_FORMAT_NONE
)
5118 return MESA_FORMAT_NONE
;
5120 datatype
= _mesa_get_format_datatype(format
);
5122 /* The GL_ARB_texture_buffer_object spec says:
5124 * "If ARB_texture_float is not supported, references to the
5125 * floating-point internal formats provided by that extension should be
5126 * removed, and such formats may not be passed to TexBufferARB."
5128 * As a result, GL_HALF_FLOAT internal format depends on both
5129 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5131 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5132 !ctx
->Extensions
.ARB_texture_float
)
5133 return MESA_FORMAT_NONE
;
5135 if (!ctx
->Extensions
.ARB_texture_rg
) {
5136 GLenum base_format
= _mesa_get_format_base_format(format
);
5137 if (base_format
== GL_R
|| base_format
== GL_RG
)
5138 return MESA_FORMAT_NONE
;
5141 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5142 GLenum base_format
= _mesa_get_format_base_format(format
);
5143 if (base_format
== GL_RGB
)
5144 return MESA_FORMAT_NONE
;
5151 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5152 struct gl_texture_object
*texObj
, GLenum target
,
5153 GLenum internalFormat
,
5154 struct gl_buffer_object
*bufObj
,
5155 GLintptr offset
, GLsizeiptr size
, bool range
,
5160 FLUSH_VERTICES(ctx
, 0);
5162 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5163 if (format
== MESA_FORMAT_NONE
) {
5164 _mesa_error(ctx
, GL_INVALID_ENUM
,
5165 "glTex%sBuffer%s(internalFormat 0x%x)", dsa
? "ture" : "",
5166 range
? "Range" : "", internalFormat
);
5170 _mesa_lock_texture(ctx
, texObj
);
5172 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5173 texObj
->BufferObjectFormat
= internalFormat
;
5174 texObj
->_BufferObjectFormat
= format
;
5175 texObj
->BufferOffset
= offset
;
5176 texObj
->BufferSize
= size
;
5178 _mesa_unlock_texture(ctx
, texObj
);
5180 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5183 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5188 /** GL_ARB_texture_buffer_object */
5190 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5192 struct gl_texture_object
*texObj
;
5193 struct gl_buffer_object
*bufObj
;
5195 GET_CURRENT_CONTEXT(ctx
);
5197 /* Need to catch this before it gets to _mesa_get_current_tex_object */
5198 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5199 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
5203 /* NOTE: ARB_texture_buffer_object has interactions with
5204 * the compatibility profile that are not implemented.
5206 if (!(ctx
->API
== API_OPENGL_CORE
&&
5207 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5208 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
5212 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
5213 if (!bufObj
&& buffer
) {
5214 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
5218 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5222 _mesa_texture_buffer_range(ctx
, texObj
, target
, internalFormat
, bufObj
, 0,
5223 buffer
? -1 : 0, false, false);
5227 /** GL_ARB_texture_buffer_range */
5229 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5230 GLintptr offset
, GLsizeiptr size
)
5232 struct gl_texture_object
*texObj
;
5233 struct gl_buffer_object
*bufObj
;
5235 GET_CURRENT_CONTEXT(ctx
);
5237 /* Need to catch this before it gets to _mesa_get_current_tex_object */
5238 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5239 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBufferRange(target)");
5243 if (!(ctx
->API
== API_OPENGL_CORE
&&
5244 ctx
->Extensions
.ARB_texture_buffer_range
)) {
5245 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
5249 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
5253 (offset
+ size
) > bufObj
->Size
) {
5254 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
5257 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5258 _mesa_error(ctx
, GL_INVALID_VALUE
,
5259 "glTexBufferRange(invalid offset alignment)");
5262 } else if (buffer
) {
5263 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
5271 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5275 _mesa_texture_buffer_range(ctx
, texObj
, target
, internalFormat
, bufObj
,
5276 offset
, size
, true, false);
5280 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5282 struct gl_texture_object
*texObj
;
5283 struct gl_buffer_object
*bufObj
;
5285 GET_CURRENT_CONTEXT(ctx
);
5287 /* NOTE: ARB_texture_buffer_object has interactions with
5288 * the compatibility profile that are not implemented.
5290 if (!(ctx
->API
== API_OPENGL_CORE
&&
5291 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5292 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureBuffer");
5296 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
5297 if (!bufObj
&& buffer
) {
5298 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureBuffer(buffer %u)",
5303 /* Get the texture object by Name. */
5304 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5305 "glTextureBuffer(texture)");
5309 if (texObj
->Target
!= GL_TEXTURE_BUFFER_ARB
) {
5310 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureBuffer(target)");
5314 _mesa_texture_buffer_range(ctx
, texObj
, texObj
->Target
, internalFormat
,
5315 bufObj
, 0, buffer
? -1 : 0, false, true);
5319 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5321 /* Everything that is allowed for renderbuffers,
5322 * except for a base format of GL_STENCIL_INDEX.
5324 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5325 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5329 /** GL_ARB_texture_multisample */
5331 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5334 case GL_TEXTURE_2D_MULTISAMPLE
:
5336 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5337 return dims
== 2 && !dsa
;
5339 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5341 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5342 return dims
== 3 && !dsa
;
5351 _mesa_texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5352 struct gl_texture_object
*texObj
,
5353 GLenum target
, GLsizei samples
,
5354 GLint internalformat
, GLsizei width
,
5355 GLsizei height
, GLsizei depth
,
5356 GLboolean fixedsamplelocations
,
5357 GLboolean immutable
, const char *func
)
5359 struct gl_texture_image
*texImage
;
5360 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5361 mesa_format texFormat
;
5362 GLenum sample_count_error
;
5363 bool dsa
= strstr(func
, "ture") ? true : false;
5365 if (!(ctx
->Extensions
.ARB_texture_multisample
5366 && _mesa_is_desktop_gl(ctx
))) {
5367 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5371 if (!check_multisample_target(dims
, target
, dsa
)) {
5373 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5377 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5382 /* check that the specified internalformat is color/depth/stencil-renderable;
5383 * refer GL3.1 spec 4.4.4
5386 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5387 _mesa_error(ctx
, GL_INVALID_ENUM
,
5388 "%s(internalformat=%s not legal for immutable-format)",
5389 func
, _mesa_lookup_enum_by_nr(internalformat
));
5393 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5394 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5395 "%s(internalformat=%s)",
5396 func
, _mesa_lookup_enum_by_nr(internalformat
));
5400 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5401 internalformat
, samples
);
5402 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5404 /* Page 254 of OpenGL 4.4 spec says:
5405 * "Proxy arrays for two-dimensional multisample and two-dimensional
5406 * multisample array textures are operated on in the same way when
5407 * TexImage2DMultisample is called with target specified as
5408 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5409 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5410 * However, if samples is not supported, then no error is generated.
5412 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5413 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5417 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5418 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5419 "%s(texture object 0)",
5424 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5426 if (texImage
== NULL
) {
5427 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5431 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5432 internalformat
, GL_NONE
, GL_NONE
);
5433 assert(texFormat
!= MESA_FORMAT_NONE
);
5435 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5436 width
, height
, depth
, 0);
5438 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5439 width
, height
, depth
, 0);
5441 if (_mesa_is_proxy_texture(target
)) {
5442 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5443 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5444 internalformat
, texFormat
,
5445 samples
, fixedsamplelocations
);
5448 /* clear all image fields */
5449 clear_teximage_fields(texImage
);
5453 if (!dimensionsOK
) {
5454 _mesa_error(ctx
, GL_INVALID_VALUE
,
5455 "%s(invalid width or height)", func
);
5460 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
5461 "%s(texture too large)", func
);
5465 /* Check if texObj->Immutable is set */
5466 if (texObj
->Immutable
) {
5467 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5471 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5473 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5474 internalformat
, texFormat
,
5475 samples
, fixedsamplelocations
);
5477 if (width
> 0 && height
> 0 && depth
> 0) {
5478 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5479 width
, height
, depth
)) {
5480 /* tidy up the texture image state. strictly speaking,
5481 * we're allowed to just leave this in whatever state we
5482 * like, but being tidy is good.
5484 _mesa_init_teximage_fields(ctx
, texImage
,
5485 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5489 texObj
->Immutable
|= immutable
;
5492 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5495 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5501 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5502 GLenum internalformat
, GLsizei width
,
5503 GLsizei height
, GLboolean fixedsamplelocations
)
5505 struct gl_texture_object
*texObj
;
5506 GET_CURRENT_CONTEXT(ctx
);
5508 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5512 _mesa_texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5513 internalformat
, width
, height
, 1,
5514 fixedsamplelocations
, GL_FALSE
,
5515 "glTexImage2DMultisample");
5520 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5521 GLenum internalformat
, GLsizei width
,
5522 GLsizei height
, GLsizei depth
,
5523 GLboolean fixedsamplelocations
)
5525 struct gl_texture_object
*texObj
;
5526 GET_CURRENT_CONTEXT(ctx
);
5528 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5532 _mesa_texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5533 internalformat
, width
, height
, depth
,
5534 fixedsamplelocations
, GL_FALSE
,
5535 "glTexImage3DMultisample");
5540 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5541 GLenum internalformat
, GLsizei width
,
5542 GLsizei height
, GLboolean fixedsamplelocations
)
5544 struct gl_texture_object
*texObj
;
5545 GET_CURRENT_CONTEXT(ctx
);
5547 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5551 _mesa_texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5552 internalformat
, width
, height
, 1,
5553 fixedsamplelocations
, GL_TRUE
,
5554 "glTexStorage2DMultisample");
5558 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5559 GLenum internalformat
, GLsizei width
,
5560 GLsizei height
, GLsizei depth
,
5561 GLboolean fixedsamplelocations
)
5563 struct gl_texture_object
*texObj
;
5564 GET_CURRENT_CONTEXT(ctx
);
5566 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5570 _mesa_texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5571 internalformat
, width
, height
, depth
,
5572 fixedsamplelocations
, GL_TRUE
,
5573 "glTexStorage3DMultisample");
5577 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5578 GLenum internalformat
, GLsizei width
,
5580 GLboolean fixedsamplelocations
)
5582 struct gl_texture_object
*texObj
;
5583 GET_CURRENT_CONTEXT(ctx
);
5585 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5586 "glTextureStorage2DMultisample");
5590 _mesa_texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5591 internalformat
, width
, height
, 1,
5592 fixedsamplelocations
, GL_TRUE
,
5593 "glTextureStorage2DMultisample");
5597 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5598 GLenum internalformat
, GLsizei width
,
5599 GLsizei height
, GLsizei depth
,
5600 GLboolean fixedsamplelocations
)
5602 struct gl_texture_object
*texObj
;
5603 GET_CURRENT_CONTEXT(ctx
);
5605 /* Get the texture object by Name. */
5606 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5607 "glTextureStorage3DMultisample");
5611 _mesa_texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5612 internalformat
, width
, height
, depth
,
5613 fixedsamplelocations
, GL_TRUE
,
5614 "glTextureStorage3DMultisample");