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
== Elements(targets
) + 2);
734 for (i
= 0; i
< Elements(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
,
2840 /* check target (proxies not allowed) */
2841 if (!legal_texsubimage_target(ctx
, dimensions
, target
, dsa
)) {
2842 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTex%sSubImage%uD(target=%s)",
2844 _mesa_lookup_enum_by_nr(target
));
2849 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2850 _mesa_error(ctx
, GL_INVALID_VALUE
,
2851 "glCopyTex%sSubImage%dD(level=%d)", suffix
,
2856 /* Get dest image pointers */
2858 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTex%sSubImage%dD()",
2859 suffix
, dimensions
);
2863 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2865 /* destination image does not exist */
2866 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2867 "glCopyTex%sSubImage%dD(invalid texture image)",
2868 suffix
, dimensions
);
2872 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2873 xoffset
, yoffset
, zoffset
,
2874 width
, height
, 1, dsa
?
2875 "glCompressedTextureSubImage" :
2876 "glCompressedTexSubImage")) {
2880 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2881 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2882 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2883 "glCopyTex%sSubImage%dD(no compression for format)",
2884 suffix
, dimensions
);
2889 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2890 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTex%sSubImage2D", suffix
);
2894 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2895 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2896 "glCopyTex%sSubImage%dD(missing readbuffer, format=0x%x)",
2897 suffix
, dimensions
, texImage
->_BaseFormat
);
2901 /* From the EXT_texture_integer spec:
2903 * "INVALID_OPERATION is generated by CopyTexImage* and
2904 * CopyTexSubImage* if the texture internalformat is an integer format
2905 * and the read color buffer is not an integer format, or if the
2906 * internalformat is not an integer format and the read color buffer
2907 * is an integer format."
2909 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2910 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2912 if (_mesa_is_format_integer_color(rb
->Format
) !=
2913 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2914 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2915 "glCopyTex%sSubImage%dD(integer vs non-integer)",
2916 suffix
, dimensions
);
2921 /* if we get here, the parameters are OK */
2926 /** Callback info for walking over FBO hash table */
2929 struct gl_context
*ctx
;
2930 struct gl_texture_object
*texObj
;
2936 * Check render to texture callback. Called from _mesa_HashWalk().
2939 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2941 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2942 const struct cb_info
*info
= (struct cb_info
*) userData
;
2943 struct gl_context
*ctx
= info
->ctx
;
2944 const struct gl_texture_object
*texObj
= info
->texObj
;
2945 const GLuint level
= info
->level
, face
= info
->face
;
2947 /* If this is a user-created FBO */
2948 if (_mesa_is_user_fbo(fb
)) {
2950 /* check if any of the FBO's attachments point to 'texObj' */
2951 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2952 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2953 if (att
->Type
== GL_TEXTURE
&&
2954 att
->Texture
== texObj
&&
2955 att
->TextureLevel
== level
&&
2956 att
->CubeMapFace
== face
) {
2957 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2958 assert(att
->Renderbuffer
->TexImage
);
2959 /* Mark fb status as indeterminate to force re-validation */
2968 * When a texture image is specified we have to check if it's bound to
2969 * any framebuffer objects (render to texture) in order to detect changes
2970 * in size or format since that effects FBO completeness.
2971 * Any FBOs rendering into the texture must be re-validated.
2974 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2975 struct gl_texture_object
*texObj
,
2976 GLuint face
, GLuint level
)
2978 /* Only check this texture if it's been marked as RenderToTexture */
2979 if (texObj
->_RenderToTexture
) {
2980 struct cb_info info
;
2982 info
.texObj
= texObj
;
2985 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2991 * If the texture object's GenerateMipmap flag is set and we've
2992 * changed the texture base level image, regenerate the rest of the
2993 * mipmap levels now.
2996 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2997 struct gl_texture_object
*texObj
, GLint level
)
2999 if (texObj
->GenerateMipmap
&&
3000 level
== texObj
->BaseLevel
&&
3001 level
< texObj
->MaxLevel
) {
3002 assert(ctx
->Driver
.GenerateMipmap
);
3003 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3008 /** Debug helper: override the user-requested internal format */
3010 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
3013 if (internalFormat
== GL_RGBA16F_ARB
||
3014 internalFormat
== GL_RGBA32F_ARB
) {
3015 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3018 else if (internalFormat
== GL_RGB16F_ARB
||
3019 internalFormat
== GL_RGB32F_ARB
) {
3020 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3023 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3024 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3025 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3026 return GL_LUMINANCE_ALPHA
;
3028 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3029 internalFormat
== GL_LUMINANCE32F_ARB
) {
3030 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3031 return GL_LUMINANCE
;
3033 else if (internalFormat
== GL_ALPHA16F_ARB
||
3034 internalFormat
== GL_ALPHA32F_ARB
) {
3035 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3039 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3040 internalFormat = GL_RGBA;
3044 return internalFormat
;
3047 return internalFormat
;
3053 * Choose the actual hardware format for a texture image.
3054 * Try to use the same format as the previous image level when possible.
3055 * Otherwise, ask the driver for the best format.
3056 * It's important to try to choose a consistant format for all levels
3057 * for efficient texture memory layout/allocation. In particular, this
3058 * comes up during automatic mipmap generation.
3061 _mesa_choose_texture_format(struct gl_context
*ctx
,
3062 struct gl_texture_object
*texObj
,
3063 GLenum target
, GLint level
,
3064 GLenum internalFormat
, GLenum format
, GLenum type
)
3068 /* see if we've already chosen a format for the previous level */
3070 struct gl_texture_image
*prevImage
=
3071 _mesa_select_tex_image(texObj
, target
, level
- 1);
3072 /* See if the prev level is defined and has an internal format which
3073 * matches the new internal format.
3076 prevImage
->Width
> 0 &&
3077 prevImage
->InternalFormat
== internalFormat
) {
3078 /* use the same format */
3079 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3080 return prevImage
->TexFormat
;
3084 /* If the application requested compression to an S3TC format but we don't
3085 * have the DXTn library, force a generic compressed format instead.
3087 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3088 const GLenum before
= internalFormat
;
3090 switch (internalFormat
) {
3091 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3092 if (!ctx
->Mesa_DXTn
)
3093 internalFormat
= GL_COMPRESSED_RGB
;
3095 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3096 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3097 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3098 if (!ctx
->Mesa_DXTn
)
3099 internalFormat
= GL_COMPRESSED_RGBA
;
3105 if (before
!= internalFormat
) {
3107 "DXT compression requested (%s), "
3108 "but libtxc_dxtn library not installed. Using %s "
3110 _mesa_lookup_enum_by_nr(before
),
3111 _mesa_lookup_enum_by_nr(internalFormat
));
3115 /* choose format from scratch */
3116 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3118 assert(f
!= MESA_FORMAT_NONE
);
3124 * Adjust pixel unpack params and image dimensions to strip off the
3125 * one-pixel texture border.
3127 * Gallium and intel don't support texture borders. They've seldem been used
3128 * and seldom been implemented correctly anyway.
3130 * \param unpackNew returns the new pixel unpack parameters
3133 strip_texture_border(GLenum target
,
3134 GLint
*width
, GLint
*height
, GLint
*depth
,
3135 const struct gl_pixelstore_attrib
*unpack
,
3136 struct gl_pixelstore_attrib
*unpackNew
)
3142 *unpackNew
= *unpack
;
3144 if (unpackNew
->RowLength
== 0)
3145 unpackNew
->RowLength
= *width
;
3147 if (unpackNew
->ImageHeight
== 0)
3148 unpackNew
->ImageHeight
= *height
;
3150 assert(*width
>= 3);
3151 unpackNew
->SkipPixels
++; /* skip the border */
3152 *width
= *width
- 2; /* reduce the width by two border pixels */
3154 /* The min height of a texture with a border is 3 */
3155 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3156 unpackNew
->SkipRows
++; /* skip the border */
3157 *height
= *height
- 2; /* reduce the height by two border pixels */
3161 target
!= GL_TEXTURE_2D_ARRAY
&&
3162 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3163 unpackNew
->SkipImages
++; /* skip the border */
3164 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3170 * Common code to implement all the glTexImage1D/2D/3D functions
3171 * as well as glCompressedTexImage1D/2D/3D.
3172 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3173 * \param format the user's image format (only used if !compressed)
3174 * \param type the user's image type (only used if !compressed)
3175 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3178 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3179 GLenum target
, GLint level
, GLint internalFormat
,
3180 GLsizei width
, GLsizei height
, GLsizei depth
,
3181 GLint border
, GLenum format
, GLenum type
,
3182 GLsizei imageSize
, const GLvoid
*pixels
)
3184 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3185 struct gl_pixelstore_attrib unpack_no_border
;
3186 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3187 struct gl_texture_object
*texObj
;
3188 mesa_format texFormat
;
3189 GLboolean dimensionsOK
, sizeOK
;
3191 FLUSH_VERTICES(ctx
, 0);
3193 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3196 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3198 _mesa_lookup_enum_by_nr(target
), level
,
3199 _mesa_lookup_enum_by_nr(internalFormat
),
3200 width
, height
, depth
, border
, pixels
);
3203 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3205 _mesa_lookup_enum_by_nr(target
), level
,
3206 _mesa_lookup_enum_by_nr(internalFormat
),
3207 width
, height
, depth
, border
,
3208 _mesa_lookup_enum_by_nr(format
),
3209 _mesa_lookup_enum_by_nr(type
), pixels
);
3212 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3214 /* target error checking */
3215 if (!legal_teximage_target(ctx
, dims
, target
)) {
3216 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3217 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3221 /* general error checking */
3223 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3225 width
, height
, depth
,
3230 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3231 format
, type
, width
, height
, depth
, border
))
3235 /* Here we convert a cpal compressed image into a regular glTexImage2D
3236 * call by decompressing the texture. If we really want to support cpal
3237 * textures in any driver this would have to be changed.
3239 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3240 switch (internalFormat
) {
3241 case GL_PALETTE4_RGB8_OES
:
3242 case GL_PALETTE4_RGBA8_OES
:
3243 case GL_PALETTE4_R5_G6_B5_OES
:
3244 case GL_PALETTE4_RGBA4_OES
:
3245 case GL_PALETTE4_RGB5_A1_OES
:
3246 case GL_PALETTE8_RGB8_OES
:
3247 case GL_PALETTE8_RGBA8_OES
:
3248 case GL_PALETTE8_R5_G6_B5_OES
:
3249 case GL_PALETTE8_RGBA4_OES
:
3250 case GL_PALETTE8_RGB5_A1_OES
:
3251 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3252 width
, height
, imageSize
, pixels
);
3257 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3261 /* For glCompressedTexImage() the driver has no choice about the
3262 * texture format since we'll never transcode the user's compressed
3263 * image data. The internalFormat was error checked earlier.
3265 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3268 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3269 * internal floating point format for the given base format.
3271 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3272 if (type
== GL_FLOAT
) {
3273 texObj
->_IsFloat
= GL_TRUE
;
3274 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3275 texObj
->_IsHalfFloat
= GL_TRUE
;
3278 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3281 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3282 internalFormat
, format
, type
);
3285 assert(texFormat
!= MESA_FORMAT_NONE
);
3287 /* check that width, height, depth are legal for the mipmap level */
3288 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3289 height
, depth
, border
);
3291 /* check that the texture won't take too much memory, etc */
3292 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3294 width
, height
, depth
, border
);
3296 if (_mesa_is_proxy_texture(target
)) {
3297 /* Proxy texture: just clear or set state depending on error checking */
3298 struct gl_texture_image
*texImage
=
3299 get_proxy_tex_image(ctx
, target
, level
);
3302 return; /* GL_OUT_OF_MEMORY already recorded */
3304 if (dimensionsOK
&& sizeOK
) {
3305 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3306 border
, internalFormat
, texFormat
);
3309 clear_teximage_fields(texImage
);
3313 /* non-proxy target */
3314 const GLuint face
= _mesa_tex_target_to_face(target
);
3315 struct gl_texture_image
*texImage
;
3317 if (!dimensionsOK
) {
3318 _mesa_error(ctx
, GL_INVALID_VALUE
,
3319 "glTexImage%uD(invalid width or height or depth)",
3325 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3326 "glTexImage%uD(image too large)", dims
);
3330 /* Allow a hardware driver to just strip out the border, to provide
3331 * reliable but slightly incorrect hardware rendering instead of
3332 * rarely-tested software fallback rendering.
3334 if (border
&& ctx
->Const
.StripTextureBorder
) {
3335 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3338 unpack
= &unpack_no_border
;
3341 if (ctx
->NewState
& _NEW_PIXEL
)
3342 _mesa_update_state(ctx
);
3344 _mesa_lock_texture(ctx
, texObj
);
3346 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3349 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3352 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3354 _mesa_init_teximage_fields(ctx
, texImage
,
3355 width
, height
, depth
,
3356 border
, internalFormat
, texFormat
);
3358 /* Give the texture to the driver. <pixels> may be null. */
3359 if (width
> 0 && height
> 0 && depth
> 0) {
3361 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3365 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3366 type
, pixels
, unpack
);
3370 check_gen_mipmap(ctx
, target
, texObj
, level
);
3372 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3374 _mesa_dirty_texobj(ctx
, texObj
);
3377 _mesa_unlock_texture(ctx
, texObj
);
3384 * Called from the API. Note that width includes the border.
3387 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3388 GLsizei width
, GLint border
, GLenum format
,
3389 GLenum type
, const GLvoid
*pixels
)
3391 GET_CURRENT_CONTEXT(ctx
);
3392 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3393 border
, format
, type
, 0, pixels
);
3398 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3399 GLsizei width
, GLsizei height
, GLint border
,
3400 GLenum format
, GLenum type
,
3401 const GLvoid
*pixels
)
3403 GET_CURRENT_CONTEXT(ctx
);
3404 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3405 border
, format
, type
, 0, pixels
);
3410 * Called by the API or display list executor.
3411 * Note that width and height include the border.
3414 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3415 GLsizei width
, GLsizei height
, GLsizei depth
,
3416 GLint border
, GLenum format
, GLenum type
,
3417 const GLvoid
*pixels
)
3419 GET_CURRENT_CONTEXT(ctx
);
3420 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3421 width
, height
, depth
,
3422 border
, format
, type
, 0, pixels
);
3427 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3428 GLsizei width
, GLsizei height
, GLsizei depth
,
3429 GLint border
, GLenum format
, GLenum type
,
3430 const GLvoid
*pixels
)
3432 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3433 depth
, border
, format
, type
, pixels
);
3438 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3440 struct gl_texture_object
*texObj
;
3441 struct gl_texture_image
*texImage
;
3443 GET_CURRENT_CONTEXT(ctx
);
3444 FLUSH_VERTICES(ctx
, 0);
3448 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3450 case GL_TEXTURE_EXTERNAL_OES
:
3452 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3455 valid_target
= false;
3459 if (!valid_target
) {
3460 _mesa_error(ctx
, GL_INVALID_ENUM
,
3461 "glEGLImageTargetTexture2D(target=%d)", target
);
3466 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3467 "glEGLImageTargetTexture2D(image=%p)", image
);
3471 if (ctx
->NewState
& _NEW_PIXEL
)
3472 _mesa_update_state(ctx
);
3474 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3478 _mesa_lock_texture(ctx
, texObj
);
3480 if (texObj
->Immutable
) {
3481 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3482 "glEGLImageTargetTexture2D(texture is immutable)");
3483 _mesa_unlock_texture(ctx
, texObj
);
3487 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3489 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3491 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3493 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3494 texObj
, texImage
, image
);
3496 _mesa_dirty_texobj(ctx
, texObj
);
3498 _mesa_unlock_texture(ctx
, texObj
);
3504 * Helper that implements the glTexSubImage1/2/3D()
3505 * and glTextureSubImage1/2/3D() functions.
3508 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3509 struct gl_texture_object
*texObj
,
3510 struct gl_texture_image
*texImage
,
3511 GLenum target
, GLint level
,
3512 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3513 GLsizei width
, GLsizei height
, GLsizei depth
,
3514 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3517 FLUSH_VERTICES(ctx
, 0);
3519 /* check target (proxies not allowed) */
3520 if (!legal_texsubimage_target(ctx
, dims
, target
, dsa
)) {
3521 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sSubImage%uD(target=%s)",
3523 dims
, _mesa_lookup_enum_by_nr(target
));
3527 if (ctx
->NewState
& _NEW_PIXEL
)
3528 _mesa_update_state(ctx
);
3530 _mesa_lock_texture(ctx
, texObj
);
3532 if (width
> 0 && height
> 0 && depth
> 0) {
3533 /* If we have a border, offset=-1 is legal. Bias by border width. */
3536 if (target
!= GL_TEXTURE_2D_ARRAY
)
3537 zoffset
+= texImage
->Border
;
3540 if (target
!= GL_TEXTURE_1D_ARRAY
)
3541 yoffset
+= texImage
->Border
;
3544 xoffset
+= texImage
->Border
;
3547 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3548 xoffset
, yoffset
, zoffset
,
3549 width
, height
, depth
,
3550 format
, type
, pixels
, &ctx
->Unpack
);
3552 check_gen_mipmap(ctx
, target
, texObj
, level
);
3554 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3555 * the texel data, not the texture format, size, etc.
3559 _mesa_unlock_texture(ctx
, texObj
);
3563 * Implement all the glTexSubImage1/2/3D() functions.
3564 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3567 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3568 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3569 GLsizei width
, GLsizei height
, GLsizei depth
,
3570 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3572 struct gl_texture_object
*texObj
;
3573 struct gl_texture_image
*texImage
;
3575 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3579 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3580 xoffset
, yoffset
, zoffset
,
3581 width
, height
, depth
, format
, type
, false)) {
3582 return; /* error was detected */
3585 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3586 /* texsubimage_error_check ensures that texImage is not NULL */
3588 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3589 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3591 _mesa_lookup_enum_by_nr(target
), level
,
3592 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3593 _mesa_lookup_enum_by_nr(format
),
3594 _mesa_lookup_enum_by_nr(type
), pixels
);
3596 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3597 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3598 format
, type
, pixels
, false);
3603 * Implement all the glTextureSubImage1/2/3D() functions.
3604 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3607 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3608 GLuint texture
, GLint level
,
3609 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3610 GLsizei width
, GLsizei height
, GLsizei depth
,
3611 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3613 struct gl_texture_object
*texObj
;
3614 struct gl_texture_image
*texImage
;
3617 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3619 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3620 dims
, texture
, level
,
3621 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3622 _mesa_lookup_enum_by_nr(format
),
3623 _mesa_lookup_enum_by_nr(type
), pixels
);
3625 /* Get the texture object by Name. */
3626 texObj
= _mesa_lookup_texture(ctx
, texture
);
3628 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3633 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3634 xoffset
, yoffset
, zoffset
,
3635 width
, height
, depth
, format
, type
, true)) {
3636 return; /* error was detected */
3640 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3641 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3644 /* Error checking */
3645 if (texObj
->NumLayers
< 6) {
3646 /* Not enough image planes for a cube map. The spec does not say
3647 * what should happen in this case because the user has always
3648 * specified each cube face separately (using
3649 * GL_TEXTURE_CUBE_MAP_POSITIVE_X+i) in previous GL versions.
3650 * This is addressed in Khronos Bug 13223.
3652 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3653 "glTextureSubImage%uD(insufficient cube map storage)",
3659 * What do we do if the user created a texture with the following code
3660 * and then called this function with its handle?
3663 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3664 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3665 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3666 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3667 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3668 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3669 * // wrong format, or given the wrong size, etc.
3670 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3671 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3673 * A bug has been filed against the spec for this case. In the
3674 * meantime, we will check for cube completeness.
3676 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3677 * Core Profile spec (30.10.2014):
3678 * "[A] cube map texture is cube complete if the
3679 * following conditions all hold true: The [base level] texture
3680 * images of each of the six cube map faces have identical, positive,
3681 * and square dimensions. The [base level] images were each specified
3682 * with the same internal format."
3684 * It seems reasonable to check for cube completeness of an arbitrary
3685 * level here so that the image data has a consistent format and size.
3687 if (!_mesa_cube_level_complete(texObj
, level
)) {
3688 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3689 "glTextureSubImage%uD(cube map incomplete)",
3694 rowStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3696 /* Copy in each face. */
3697 for (i
= 0; i
< 6; ++i
) {
3698 texImage
= texObj
->Image
[i
][level
];
3699 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3700 level
, xoffset
, yoffset
, zoffset
,
3701 width
, height
, 1, format
,
3702 type
, pixels
, true);
3703 pixels
= (GLubyte
*) pixels
+ rowStride
;
3707 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3711 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3712 level
, xoffset
, yoffset
, zoffset
,
3713 width
, height
, depth
, format
,
3714 type
, pixels
, true);
3720 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3721 GLint xoffset
, GLsizei width
,
3722 GLenum format
, GLenum type
,
3723 const GLvoid
*pixels
)
3725 GET_CURRENT_CONTEXT(ctx
);
3726 texsubimage(ctx
, 1, target
, level
,
3729 format
, type
, pixels
);
3734 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3735 GLint xoffset
, GLint yoffset
,
3736 GLsizei width
, GLsizei height
,
3737 GLenum format
, GLenum type
,
3738 const GLvoid
*pixels
)
3740 GET_CURRENT_CONTEXT(ctx
);
3741 texsubimage(ctx
, 2, target
, level
,
3742 xoffset
, yoffset
, 0,
3744 format
, type
, pixels
);
3750 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3751 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3752 GLsizei width
, GLsizei height
, GLsizei depth
,
3753 GLenum format
, GLenum type
,
3754 const GLvoid
*pixels
)
3756 GET_CURRENT_CONTEXT(ctx
);
3757 texsubimage(ctx
, 3, target
, level
,
3758 xoffset
, yoffset
, zoffset
,
3759 width
, height
, depth
,
3760 format
, type
, pixels
);
3764 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3765 GLint xoffset
, GLsizei width
,
3766 GLenum format
, GLenum type
,
3767 const GLvoid
*pixels
)
3769 GET_CURRENT_CONTEXT(ctx
);
3770 texturesubimage(ctx
, 1, texture
, level
,
3773 format
, type
, pixels
);
3778 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3779 GLint xoffset
, GLint yoffset
,
3780 GLsizei width
, GLsizei height
,
3781 GLenum format
, GLenum type
,
3782 const GLvoid
*pixels
)
3784 GET_CURRENT_CONTEXT(ctx
);
3785 texturesubimage(ctx
, 2, texture
, level
,
3786 xoffset
, yoffset
, 0,
3788 format
, type
, pixels
);
3793 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3794 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3795 GLsizei width
, GLsizei height
, GLsizei depth
,
3796 GLenum format
, GLenum type
,
3797 const GLvoid
*pixels
)
3799 GET_CURRENT_CONTEXT(ctx
);
3800 texturesubimage(ctx
, 3, texture
, level
,
3801 xoffset
, yoffset
, zoffset
,
3802 width
, height
, depth
,
3803 format
, type
, pixels
);
3808 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3809 * from. This depends on whether the texture contains color or depth values.
3811 static struct gl_renderbuffer
*
3812 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3814 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3815 /* reading from depth/stencil buffer */
3816 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3819 /* copying from color buffer */
3820 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3825 copytexsubimage_by_slice(struct gl_context
*ctx
,
3826 struct gl_texture_image
*texImage
,
3828 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3829 struct gl_renderbuffer
*rb
,
3831 GLsizei width
, GLsizei height
)
3833 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3836 /* For 1D arrays, we copy each scanline of the source rectangle into the
3839 assert(zoffset
== 0);
3841 for (slice
= 0; slice
< height
; slice
++) {
3842 assert(yoffset
+ slice
< texImage
->Height
);
3843 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3844 xoffset
, 0, yoffset
+ slice
,
3845 rb
, x
, y
+ slice
, width
, 1);
3848 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3849 xoffset
, yoffset
, zoffset
,
3850 rb
, x
, y
, width
, height
);
3855 formats_differ_in_component_sizes (mesa_format f1
,
3858 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3859 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3860 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3861 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3863 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3864 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3865 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3866 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3868 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3869 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3870 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3871 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3878 * Implement the glCopyTexImage1/2D() functions.
3881 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3882 GLenum target
, GLint level
, GLenum internalFormat
,
3883 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3885 struct gl_texture_object
*texObj
;
3886 struct gl_texture_image
*texImage
;
3887 const GLuint face
= _mesa_tex_target_to_face(target
);
3888 mesa_format texFormat
;
3889 struct gl_renderbuffer
*rb
;
3891 FLUSH_VERTICES(ctx
, 0);
3893 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3894 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3896 _mesa_lookup_enum_by_nr(target
), level
,
3897 _mesa_lookup_enum_by_nr(internalFormat
),
3898 x
, y
, width
, height
, border
);
3900 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3901 _mesa_update_state(ctx
);
3903 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3904 width
, height
, border
))
3907 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3909 _mesa_error(ctx
, GL_INVALID_VALUE
,
3910 "glCopyTexImage%uD(invalid width or height)", dims
);
3914 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3917 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3918 internalFormat
, GL_NONE
, GL_NONE
);
3920 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3922 if (_mesa_is_gles3(ctx
)) {
3923 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3924 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3925 * OpenGL ES 3.0. Khronos bug# 9807.
3927 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3928 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3929 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer and"
3930 " writing to unsized internal format)", dims
);
3934 /* From Page 139 of OpenGL ES 3.0 spec:
3935 * "If internalformat is sized, the internal format of the new texel
3936 * array is internalformat, and this is also the new texel array’s
3937 * effective internal format. If the component sizes of internalformat
3938 * do not exactly match the corresponding component sizes of the source
3939 * buffer’s effective internal format, described below, an
3940 * INVALID_OPERATION error is generated. If internalformat is unsized,
3941 * the internal format of the new texel array is the effective internal
3942 * format of the source buffer, and this is also the new texel array’s
3943 * effective internal format.
3945 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3946 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3947 "glCopyTexImage%uD(componenet size changed in"
3948 " internal format)", dims
);
3953 assert(texFormat
!= MESA_FORMAT_NONE
);
3955 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3957 width
, height
, 1, border
)) {
3958 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3959 "glCopyTexImage%uD(image too large)", dims
);
3963 if (border
&& ctx
->Const
.StripTextureBorder
) {
3965 width
-= border
* 2;
3968 height
-= border
* 2;
3973 _mesa_lock_texture(ctx
, texObj
);
3975 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3978 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3981 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3983 /* Free old texture image */
3984 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3986 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3987 border
, internalFormat
, texFormat
);
3989 if (width
&& height
) {
3990 /* Allocate texture memory (no pixel data yet) */
3991 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3993 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3995 struct gl_renderbuffer
*srcRb
=
3996 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3998 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4000 srcRb
, srcX
, srcY
, width
, height
);
4003 check_gen_mipmap(ctx
, target
, texObj
, level
);
4006 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4008 _mesa_dirty_texobj(ctx
, texObj
);
4011 _mesa_unlock_texture(ctx
, texObj
);
4017 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4018 GLenum internalFormat
,
4020 GLsizei width
, GLint border
)
4022 GET_CURRENT_CONTEXT(ctx
);
4023 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4029 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4030 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4033 GET_CURRENT_CONTEXT(ctx
);
4034 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4035 x
, y
, width
, height
, border
);
4039 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4042 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4043 struct gl_texture_object
*texObj
,
4044 GLenum target
, GLint level
,
4045 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4047 GLsizei width
, GLsizei height
,
4050 struct gl_texture_image
*texImage
;
4052 FLUSH_VERTICES(ctx
, 0);
4054 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4055 _mesa_debug(ctx
, "glCopyTex%sSubImage%uD %s %d %d %d %d %d %d %d %d\n",
4056 dsa
? "ture" : "", dims
,
4057 _mesa_lookup_enum_by_nr(target
),
4058 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4060 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4061 _mesa_update_state(ctx
);
4063 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4064 xoffset
, yoffset
, zoffset
,
4065 width
, height
, dsa
)) {
4069 _mesa_lock_texture(ctx
, texObj
);
4071 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4073 /* If we have a border, offset=-1 is legal. Bias by border width. */
4076 if (target
!= GL_TEXTURE_2D_ARRAY
)
4077 zoffset
+= texImage
->Border
;
4080 if (target
!= GL_TEXTURE_1D_ARRAY
)
4081 yoffset
+= texImage
->Border
;
4084 xoffset
+= texImage
->Border
;
4087 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4089 struct gl_renderbuffer
*srcRb
=
4090 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4092 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4093 xoffset
, yoffset
, zoffset
,
4094 srcRb
, x
, y
, width
, height
);
4096 check_gen_mipmap(ctx
, target
, texObj
, level
);
4098 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4099 * the texel data, not the texture format, size, etc.
4103 _mesa_unlock_texture(ctx
, texObj
);
4107 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4108 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4110 struct gl_texture_object
* texObj
;
4111 GET_CURRENT_CONTEXT(ctx
);
4113 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4117 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4118 x
, y
, width
, 1, false);
4124 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4125 GLint xoffset
, GLint yoffset
,
4126 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4128 struct gl_texture_object
* texObj
;
4129 GET_CURRENT_CONTEXT(ctx
);
4131 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4135 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4136 xoffset
, yoffset
, 0,
4137 x
, y
, width
, height
, false);
4143 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4144 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4145 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4147 struct gl_texture_object
* texObj
;
4148 GET_CURRENT_CONTEXT(ctx
);
4150 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4154 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4155 xoffset
, yoffset
, zoffset
,
4156 x
, y
, width
, height
, false);
4160 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4161 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4163 struct gl_texture_object
* texObj
;
4164 GET_CURRENT_CONTEXT(ctx
);
4166 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage1D");
4170 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4171 xoffset
, 0, 0, x
, y
, width
, 1, true);
4175 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4176 GLint xoffset
, GLint yoffset
,
4177 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4179 struct gl_texture_object
* texObj
;
4180 GET_CURRENT_CONTEXT(ctx
);
4182 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage2D");
4186 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4187 xoffset
, yoffset
, 0,
4188 x
, y
, width
, height
, true);
4194 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4195 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4196 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4198 struct gl_texture_object
* texObj
;
4199 GET_CURRENT_CONTEXT(ctx
);
4201 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage3D");
4205 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4206 xoffset
, yoffset
, zoffset
,
4207 x
, y
, width
, height
, true);
4211 check_clear_tex_image(struct gl_context
*ctx
,
4212 const char *function
,
4213 struct gl_texture_image
*texImage
,
4214 GLenum format
, GLenum type
,
4216 GLubyte
*clearValue
)
4218 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4219 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4220 GLenum internalFormat
= texImage
->InternalFormat
;
4223 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4224 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4225 "%s(buffer texture)", function
);
4229 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4230 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4231 "%s(compressed texture)", function
);
4235 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4236 if (err
!= GL_NO_ERROR
) {
4237 _mesa_error(ctx
, err
,
4238 "%s(incompatible format = %s, type = %s)",
4240 _mesa_lookup_enum_by_nr(format
),
4241 _mesa_lookup_enum_by_nr(type
));
4245 /* make sure internal format and format basically agree */
4246 if (!texture_formats_agree(internalFormat
, format
)) {
4247 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4248 "%s(incompatible internalFormat = %s, format = %s)",
4250 _mesa_lookup_enum_by_nr(internalFormat
),
4251 _mesa_lookup_enum_by_nr(format
));
4255 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4256 /* both source and dest must be integer-valued, or neither */
4257 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4258 _mesa_is_enum_format_integer(format
)) {
4259 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4260 "%s(integer/non-integer format mismatch)",
4266 if (!_mesa_texstore(ctx
,
4268 texImage
->_BaseFormat
,
4269 texImage
->TexFormat
,
4270 0, /* dstRowStride */
4272 1, 1, 1, /* srcWidth/Height/Depth */
4274 data
? data
: zeroData
,
4275 &ctx
->DefaultPacking
)) {
4276 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4283 static struct gl_texture_object
*
4284 get_tex_obj_for_clear(struct gl_context
*ctx
,
4285 const char *function
,
4288 struct gl_texture_object
*texObj
;
4291 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4295 texObj
= _mesa_lookup_texture(ctx
, texture
);
4297 if (texObj
== NULL
) {
4298 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4302 if (texObj
->Target
== 0) {
4303 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4311 get_tex_images_for_clear(struct gl_context
*ctx
,
4312 const char *function
,
4313 struct gl_texture_object
*texObj
,
4315 struct gl_texture_image
**texImages
)
4320 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4321 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4325 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4326 for (i
= 0; i
< MAX_FACES
; i
++) {
4327 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4329 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4330 if (texImages
[i
] == NULL
) {
4331 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4332 "%s(invalid level)", function
);
4340 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4342 if (texImages
[0] == NULL
) {
4343 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4351 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4352 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4353 GLsizei width
, GLsizei height
, GLsizei depth
,
4354 GLenum format
, GLenum type
, const void *data
)
4356 GET_CURRENT_CONTEXT(ctx
);
4357 struct gl_texture_object
*texObj
;
4358 struct gl_texture_image
*texImages
[MAX_FACES
];
4359 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4361 int minDepth
, maxDepth
;
4363 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4368 _mesa_lock_texture(ctx
, texObj
);
4370 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4371 texObj
, level
, texImages
);
4375 if (numImages
== 1) {
4376 minDepth
= -(int) texImages
[0]->Border
;
4377 maxDepth
= texImages
[0]->Depth
;
4380 maxDepth
= numImages
;
4383 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4384 yoffset
< -(GLint
) texImages
[0]->Border
||
4385 zoffset
< minDepth
||
4389 xoffset
+ width
> texImages
[0]->Width
||
4390 yoffset
+ height
> texImages
[0]->Height
||
4391 zoffset
+ depth
> maxDepth
) {
4392 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4393 "glClearSubTexImage(invalid dimensions)");
4397 if (numImages
== 1) {
4398 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4400 format
, type
, data
, clearValue
[0])) {
4401 ctx
->Driver
.ClearTexSubImage(ctx
,
4403 xoffset
, yoffset
, zoffset
,
4404 width
, height
, depth
,
4405 data
? clearValue
[0] : NULL
);
4408 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4409 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4411 format
, type
, data
, clearValue
[i
]))
4414 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4415 ctx
->Driver
.ClearTexSubImage(ctx
,
4417 xoffset
, yoffset
, 0,
4419 data
? clearValue
[i
] : NULL
);
4424 _mesa_unlock_texture(ctx
, texObj
);
4428 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4429 GLenum format
, GLenum type
, const void *data
)
4431 GET_CURRENT_CONTEXT(ctx
);
4432 struct gl_texture_object
*texObj
;
4433 struct gl_texture_image
*texImages
[MAX_FACES
];
4434 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4437 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4442 _mesa_lock_texture(ctx
, texObj
);
4444 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4445 texObj
, level
, texImages
);
4447 for (i
= 0; i
< numImages
; i
++) {
4448 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4455 for (i
= 0; i
< numImages
; i
++) {
4456 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4457 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4458 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4459 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4460 texImages
[i
]->Width
,
4461 texImages
[i
]->Height
,
4462 texImages
[i
]->Depth
,
4463 data
? clearValue
[i
] : NULL
);
4467 _mesa_unlock_texture(ctx
, texObj
);
4473 /**********************************************************************/
4474 /****** Compressed Textures ******/
4475 /**********************************************************************/
4479 * Error checking for glCompressedTexSubImage[123]D().
4480 * \return GL_TRUE if error, GL_FALSE if no error
4483 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4484 const struct gl_texture_object
*texObj
,
4485 GLenum target
, GLint level
,
4486 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4487 GLsizei width
, GLsizei height
, GLsizei depth
,
4488 GLenum format
, GLsizei imageSize
, bool dsa
)
4490 struct gl_texture_image
*texImage
;
4493 const char *suffix
= dsa
? "ture" : "";
4495 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4496 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4497 "glCompressedSubTexture%dD(target)", dims
);
4505 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4506 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4507 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4508 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4509 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4510 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4514 targetOK
= GL_FALSE
;
4519 targetOK
= (target
== GL_TEXTURE_3D
) ||
4520 (target
== GL_TEXTURE_2D_ARRAY
) ||
4521 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
4522 (target
== GL_TEXTURE_CUBE_MAP
&& dsa
);
4524 /* OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4526 * "An INVALID_OPERATION error is generated by
4527 * CompressedTex*SubImage3D if the internal format of the texture is
4528 * one of the EAC, ETC2, or RGTC formats and either border is
4529 * non-zero, or the effective target for the texture is not
4530 * TEXTURE_2D_ARRAY."
4532 if (target
!= GL_TEXTURE_2D_ARRAY
) {
4535 /* These came from _mesa_is_compressed_format in glformats.c. */
4537 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
4538 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
4539 case GL_COMPRESSED_R11_EAC
:
4540 case GL_COMPRESSED_RG11_EAC
:
4541 case GL_COMPRESSED_SIGNED_R11_EAC
:
4542 case GL_COMPRESSED_SIGNED_RG11_EAC
:
4544 case GL_COMPRESSED_RGB8_ETC2
:
4545 case GL_COMPRESSED_SRGB8_ETC2
:
4546 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
4547 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
4549 case GL_COMPRESSED_RED_RGTC1
:
4550 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
4551 case GL_COMPRESSED_RG_RGTC2
:
4552 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
4553 invalidformat
= true;
4556 invalidformat
= false;
4558 if (invalidformat
) {
4559 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4560 "glCompressedTex%sSubImage%uD(target)", suffix
, dims
);
4568 /* no 1D compressed textures at this time */
4569 targetOK
= GL_FALSE
;
4574 _mesa_error(ctx
, GL_INVALID_ENUM
,
4575 "glCompressedTex%sSubImage%uD(target)", suffix
, dims
);
4579 /* this will catch any invalid compressed format token */
4580 if (!_mesa_is_compressed_format(ctx
, format
)) {
4581 _mesa_error(ctx
, GL_INVALID_ENUM
,
4582 "glCompressedTex%sSubImage%uD(format)", suffix
, dims
);
4586 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4587 _mesa_error(ctx
, GL_INVALID_VALUE
,
4588 "glCompressedTex%sSubImage%uD(level=%d)",
4589 suffix
, dims
, level
);
4593 /* Check for invalid pixel storage modes */
4594 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4596 dsa
? "glCompressedTextureSubImage" :
4597 "glCompressedTexSubImage")) {
4601 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4602 if (expectedSize
!= imageSize
) {
4603 _mesa_error(ctx
, GL_INVALID_VALUE
,
4604 "glCompressedTex%sSubImage%uD(size=%d)",
4605 suffix
, dims
, imageSize
);
4609 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4611 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4612 "glCompressedTex%sSubImage%uD(invalid texture image)",
4617 if ((GLint
) format
!= texImage
->InternalFormat
) {
4618 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4619 "glCompressedTex%sSubImage%uD(format=0x%x)",
4620 suffix
, dims
, format
);
4624 if (compressedteximage_only_format(ctx
, format
)) {
4625 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4626 "glCompressedTex%sSubImage%uD(format=0x%x cannot be updated)",
4627 suffix
, dims
, format
);
4631 if (error_check_subtexture_dimensions(ctx
, dims
,
4632 texImage
, xoffset
, yoffset
, zoffset
,
4633 width
, height
, depth
,
4634 "glCompressedTexSubImage")) {
4643 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4644 GLenum internalFormat
, GLsizei width
,
4645 GLint border
, GLsizei imageSize
,
4648 GET_CURRENT_CONTEXT(ctx
);
4649 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4650 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4655 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4656 GLenum internalFormat
, GLsizei width
,
4657 GLsizei height
, GLint border
, GLsizei imageSize
,
4660 GET_CURRENT_CONTEXT(ctx
);
4661 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4662 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4667 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4668 GLenum internalFormat
, GLsizei width
,
4669 GLsizei height
, GLsizei depth
, GLint border
,
4670 GLsizei imageSize
, const GLvoid
*data
)
4672 GET_CURRENT_CONTEXT(ctx
);
4673 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4674 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4679 * Common helper for glCompressedTexSubImage1/2/3D() and
4680 * glCompressedTextureSubImage1/2/3D().
4683 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4684 struct gl_texture_object
*texObj
,
4685 GLenum target
, GLint level
,
4686 GLint xoffset
, GLint yoffset
,
4688 GLsizei width
, GLsizei height
,
4690 GLenum format
, GLsizei imageSize
,
4691 const GLvoid
*data
, bool dsa
)
4693 struct gl_texture_image
*texImage
;
4695 if (compressed_subtexture_error_check(ctx
, dims
, texObj
, target
,
4696 level
, xoffset
, yoffset
, zoffset
,
4697 width
, height
, depth
,
4698 format
, imageSize
, dsa
)) {
4702 FLUSH_VERTICES(ctx
, 0);
4704 _mesa_lock_texture(ctx
, texObj
);
4706 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4709 if (width
> 0 && height
> 0 && depth
> 0) {
4710 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4711 xoffset
, yoffset
, zoffset
,
4712 width
, height
, depth
,
4713 format
, imageSize
, data
);
4715 check_gen_mipmap(ctx
, target
, texObj
, level
);
4717 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4718 * the texel data, not the texture format, size, etc.
4722 _mesa_unlock_texture(ctx
, texObj
);
4727 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4728 GLsizei width
, GLenum format
,
4729 GLsizei imageSize
, const GLvoid
*data
)
4731 struct gl_texture_object
*texObj
;
4732 GET_CURRENT_CONTEXT(ctx
);
4734 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4738 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, target
, level
,
4739 xoffset
, 0, 0, width
, 1, 1,
4740 format
, imageSize
, data
, false);
4744 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4745 GLsizei width
, GLenum format
,
4746 GLsizei imageSize
, const GLvoid
*data
)
4748 struct gl_texture_object
*texObj
;
4749 GET_CURRENT_CONTEXT(ctx
);
4751 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4752 "glCompressedTextureSubImage1D");
4756 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4757 xoffset
, 0, 0, width
, 1, 1,
4758 format
, imageSize
, data
, true);
4763 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4764 GLint yoffset
, GLsizei width
, GLsizei height
,
4765 GLenum format
, GLsizei imageSize
,
4768 struct gl_texture_object
*texObj
;
4769 GET_CURRENT_CONTEXT(ctx
);
4771 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4775 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4776 xoffset
, yoffset
, 0, width
, height
, 1,
4777 format
, imageSize
, data
, false);
4781 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
4783 GLsizei width
, GLsizei height
,
4784 GLenum format
, GLsizei imageSize
,
4787 struct gl_texture_object
*texObj
;
4788 GET_CURRENT_CONTEXT(ctx
);
4790 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4791 "glCompressedTextureSubImage2D");
4795 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4796 xoffset
, yoffset
, 0, width
, height
, 1,
4797 format
, imageSize
, data
, true);
4801 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4802 GLint yoffset
, GLint zoffset
, GLsizei width
,
4803 GLsizei height
, GLsizei depth
, GLenum format
,
4804 GLsizei imageSize
, const GLvoid
*data
)
4806 struct gl_texture_object
*texObj
;
4807 GET_CURRENT_CONTEXT(ctx
);
4809 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4813 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4814 xoffset
, yoffset
, zoffset
,
4815 width
, height
, depth
,
4816 format
, imageSize
, data
, false);
4820 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
4821 GLint yoffset
, GLint zoffset
, GLsizei width
,
4822 GLsizei height
, GLsizei depth
,
4823 GLenum format
, GLsizei imageSize
,
4826 struct gl_texture_object
*texObj
;
4827 GET_CURRENT_CONTEXT(ctx
);
4829 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4830 "glCompressedTextureSubImage3D");
4834 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4835 xoffset
, yoffset
, zoffset
,
4836 width
, height
, depth
,
4837 format
, imageSize
, data
, true);
4841 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4843 if (ctx
->API
!= API_OPENGL_CORE
) {
4844 switch (internalFormat
) {
4846 return MESA_FORMAT_A_UNORM8
;
4848 return MESA_FORMAT_A_UNORM16
;
4849 case GL_ALPHA16F_ARB
:
4850 return MESA_FORMAT_A_FLOAT16
;
4851 case GL_ALPHA32F_ARB
:
4852 return MESA_FORMAT_A_FLOAT32
;
4853 case GL_ALPHA8I_EXT
:
4854 return MESA_FORMAT_A_SINT8
;
4855 case GL_ALPHA16I_EXT
:
4856 return MESA_FORMAT_A_SINT16
;
4857 case GL_ALPHA32I_EXT
:
4858 return MESA_FORMAT_A_SINT32
;
4859 case GL_ALPHA8UI_EXT
:
4860 return MESA_FORMAT_A_UINT8
;
4861 case GL_ALPHA16UI_EXT
:
4862 return MESA_FORMAT_A_UINT16
;
4863 case GL_ALPHA32UI_EXT
:
4864 return MESA_FORMAT_A_UINT32
;
4866 return MESA_FORMAT_L_UNORM8
;
4867 case GL_LUMINANCE16
:
4868 return MESA_FORMAT_L_UNORM16
;
4869 case GL_LUMINANCE16F_ARB
:
4870 return MESA_FORMAT_L_FLOAT16
;
4871 case GL_LUMINANCE32F_ARB
:
4872 return MESA_FORMAT_L_FLOAT32
;
4873 case GL_LUMINANCE8I_EXT
:
4874 return MESA_FORMAT_L_SINT8
;
4875 case GL_LUMINANCE16I_EXT
:
4876 return MESA_FORMAT_L_SINT16
;
4877 case GL_LUMINANCE32I_EXT
:
4878 return MESA_FORMAT_L_SINT32
;
4879 case GL_LUMINANCE8UI_EXT
:
4880 return MESA_FORMAT_L_UINT8
;
4881 case GL_LUMINANCE16UI_EXT
:
4882 return MESA_FORMAT_L_UINT16
;
4883 case GL_LUMINANCE32UI_EXT
:
4884 return MESA_FORMAT_L_UINT32
;
4885 case GL_LUMINANCE8_ALPHA8
:
4886 return MESA_FORMAT_L8A8_UNORM
;
4887 case GL_LUMINANCE16_ALPHA16
:
4888 return MESA_FORMAT_L16A16_UNORM
;
4889 case GL_LUMINANCE_ALPHA16F_ARB
:
4890 return MESA_FORMAT_LA_FLOAT16
;
4891 case GL_LUMINANCE_ALPHA32F_ARB
:
4892 return MESA_FORMAT_LA_FLOAT32
;
4893 case GL_LUMINANCE_ALPHA8I_EXT
:
4894 return MESA_FORMAT_LA_SINT8
;
4895 case GL_LUMINANCE_ALPHA16I_EXT
:
4896 return MESA_FORMAT_LA_SINT16
;
4897 case GL_LUMINANCE_ALPHA32I_EXT
:
4898 return MESA_FORMAT_LA_SINT32
;
4899 case GL_LUMINANCE_ALPHA8UI_EXT
:
4900 return MESA_FORMAT_LA_UINT8
;
4901 case GL_LUMINANCE_ALPHA16UI_EXT
:
4902 return MESA_FORMAT_LA_UINT16
;
4903 case GL_LUMINANCE_ALPHA32UI_EXT
:
4904 return MESA_FORMAT_LA_UINT32
;
4906 return MESA_FORMAT_I_UNORM8
;
4907 case GL_INTENSITY16
:
4908 return MESA_FORMAT_I_UNORM16
;
4909 case GL_INTENSITY16F_ARB
:
4910 return MESA_FORMAT_I_FLOAT16
;
4911 case GL_INTENSITY32F_ARB
:
4912 return MESA_FORMAT_I_FLOAT32
;
4913 case GL_INTENSITY8I_EXT
:
4914 return MESA_FORMAT_I_SINT8
;
4915 case GL_INTENSITY16I_EXT
:
4916 return MESA_FORMAT_I_SINT16
;
4917 case GL_INTENSITY32I_EXT
:
4918 return MESA_FORMAT_I_SINT32
;
4919 case GL_INTENSITY8UI_EXT
:
4920 return MESA_FORMAT_I_UINT8
;
4921 case GL_INTENSITY16UI_EXT
:
4922 return MESA_FORMAT_I_UINT16
;
4923 case GL_INTENSITY32UI_EXT
:
4924 return MESA_FORMAT_I_UINT32
;
4930 if (ctx
->API
== API_OPENGL_CORE
&&
4931 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4932 switch (internalFormat
) {
4934 return MESA_FORMAT_RGB_FLOAT32
;
4936 return MESA_FORMAT_RGB_UINT32
;
4938 return MESA_FORMAT_RGB_SINT32
;
4944 switch (internalFormat
) {
4946 return MESA_FORMAT_R8G8B8A8_UNORM
;
4948 return MESA_FORMAT_RGBA_UNORM16
;
4949 case GL_RGBA16F_ARB
:
4950 return MESA_FORMAT_RGBA_FLOAT16
;
4951 case GL_RGBA32F_ARB
:
4952 return MESA_FORMAT_RGBA_FLOAT32
;
4954 return MESA_FORMAT_RGBA_SINT8
;
4955 case GL_RGBA16I_EXT
:
4956 return MESA_FORMAT_RGBA_SINT16
;
4957 case GL_RGBA32I_EXT
:
4958 return MESA_FORMAT_RGBA_SINT32
;
4959 case GL_RGBA8UI_EXT
:
4960 return MESA_FORMAT_RGBA_UINT8
;
4961 case GL_RGBA16UI_EXT
:
4962 return MESA_FORMAT_RGBA_UINT16
;
4963 case GL_RGBA32UI_EXT
:
4964 return MESA_FORMAT_RGBA_UINT32
;
4967 return MESA_FORMAT_R8G8_UNORM
;
4969 return MESA_FORMAT_R16G16_UNORM
;
4971 return MESA_FORMAT_RG_FLOAT16
;
4973 return MESA_FORMAT_RG_FLOAT32
;
4975 return MESA_FORMAT_RG_SINT8
;
4977 return MESA_FORMAT_RG_SINT16
;
4979 return MESA_FORMAT_RG_SINT32
;
4981 return MESA_FORMAT_RG_UINT8
;
4983 return MESA_FORMAT_RG_UINT16
;
4985 return MESA_FORMAT_RG_UINT32
;
4988 return MESA_FORMAT_R_UNORM8
;
4990 return MESA_FORMAT_R_UNORM16
;
4992 return MESA_FORMAT_R_FLOAT16
;
4994 return MESA_FORMAT_R_FLOAT32
;
4996 return MESA_FORMAT_R_SINT8
;
4998 return MESA_FORMAT_R_SINT16
;
5000 return MESA_FORMAT_R_SINT32
;
5002 return MESA_FORMAT_R_UINT8
;
5004 return MESA_FORMAT_R_UINT16
;
5006 return MESA_FORMAT_R_UINT32
;
5009 return MESA_FORMAT_NONE
;
5015 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5016 GLenum internalFormat
)
5018 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5021 if (format
== MESA_FORMAT_NONE
)
5022 return MESA_FORMAT_NONE
;
5024 datatype
= _mesa_get_format_datatype(format
);
5026 /* The GL_ARB_texture_buffer_object spec says:
5028 * "If ARB_texture_float is not supported, references to the
5029 * floating-point internal formats provided by that extension should be
5030 * removed, and such formats may not be passed to TexBufferARB."
5032 * As a result, GL_HALF_FLOAT internal format depends on both
5033 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5035 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5036 !ctx
->Extensions
.ARB_texture_float
)
5037 return MESA_FORMAT_NONE
;
5039 if (!ctx
->Extensions
.ARB_texture_rg
) {
5040 GLenum base_format
= _mesa_get_format_base_format(format
);
5041 if (base_format
== GL_R
|| base_format
== GL_RG
)
5042 return MESA_FORMAT_NONE
;
5045 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5046 GLenum base_format
= _mesa_get_format_base_format(format
);
5047 if (base_format
== GL_RGB
)
5048 return MESA_FORMAT_NONE
;
5055 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5056 struct gl_texture_object
*texObj
, GLenum target
,
5057 GLenum internalFormat
,
5058 struct gl_buffer_object
*bufObj
,
5059 GLintptr offset
, GLsizeiptr size
, bool range
,
5064 FLUSH_VERTICES(ctx
, 0);
5066 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5067 if (format
== MESA_FORMAT_NONE
) {
5068 _mesa_error(ctx
, GL_INVALID_ENUM
,
5069 "glTex%sBuffer%s(internalFormat 0x%x)", dsa
? "ture" : "",
5070 range
? "Range" : "", internalFormat
);
5074 _mesa_lock_texture(ctx
, texObj
);
5076 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5077 texObj
->BufferObjectFormat
= internalFormat
;
5078 texObj
->_BufferObjectFormat
= format
;
5079 texObj
->BufferOffset
= offset
;
5080 texObj
->BufferSize
= size
;
5082 _mesa_unlock_texture(ctx
, texObj
);
5084 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5087 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5092 /** GL_ARB_texture_buffer_object */
5094 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5096 struct gl_texture_object
*texObj
;
5097 struct gl_buffer_object
*bufObj
;
5099 GET_CURRENT_CONTEXT(ctx
);
5101 /* Need to catch this before it gets to _mesa_get_current_tex_object */
5102 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5103 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
5107 /* NOTE: ARB_texture_buffer_object has interactions with
5108 * the compatibility profile that are not implemented.
5110 if (!(ctx
->API
== API_OPENGL_CORE
&&
5111 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5112 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
5116 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
5117 if (!bufObj
&& buffer
) {
5118 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
5122 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5126 _mesa_texture_buffer_range(ctx
, texObj
, target
, internalFormat
, bufObj
, 0,
5127 buffer
? -1 : 0, false, false);
5131 /** GL_ARB_texture_buffer_range */
5133 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5134 GLintptr offset
, GLsizeiptr size
)
5136 struct gl_texture_object
*texObj
;
5137 struct gl_buffer_object
*bufObj
;
5139 GET_CURRENT_CONTEXT(ctx
);
5141 /* Need to catch this before it gets to _mesa_get_current_tex_object */
5142 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5143 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBufferRange(target)");
5147 if (!(ctx
->API
== API_OPENGL_CORE
&&
5148 ctx
->Extensions
.ARB_texture_buffer_range
)) {
5149 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
5153 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
5157 (offset
+ size
) > bufObj
->Size
) {
5158 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
5161 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5162 _mesa_error(ctx
, GL_INVALID_VALUE
,
5163 "glTexBufferRange(invalid offset alignment)");
5166 } else if (buffer
) {
5167 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
5175 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5179 _mesa_texture_buffer_range(ctx
, texObj
, target
, internalFormat
, bufObj
,
5180 offset
, size
, true, false);
5184 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5186 struct gl_texture_object
*texObj
;
5187 struct gl_buffer_object
*bufObj
;
5189 GET_CURRENT_CONTEXT(ctx
);
5191 /* NOTE: ARB_texture_buffer_object has interactions with
5192 * the compatibility profile that are not implemented.
5194 if (!(ctx
->API
== API_OPENGL_CORE
&&
5195 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5196 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureBuffer");
5200 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
5201 if (!bufObj
&& buffer
) {
5202 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureBuffer(buffer %u)",
5207 /* Get the texture object by Name. */
5208 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5209 "glTextureBuffer(texture)");
5213 if (texObj
->Target
!= GL_TEXTURE_BUFFER_ARB
) {
5214 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureBuffer(target)");
5218 _mesa_texture_buffer_range(ctx
, texObj
, texObj
->Target
, internalFormat
,
5219 bufObj
, 0, buffer
? -1 : 0, false, true);
5223 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5225 /* Everything that is allowed for renderbuffers,
5226 * except for a base format of GL_STENCIL_INDEX.
5228 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5229 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5233 /** GL_ARB_texture_multisample */
5235 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5238 case GL_TEXTURE_2D_MULTISAMPLE
:
5240 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5241 return dims
== 2 && !dsa
;
5243 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5245 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5246 return dims
== 3 && !dsa
;
5255 _mesa_texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5256 struct gl_texture_object
*texObj
,
5257 GLenum target
, GLsizei samples
,
5258 GLint internalformat
, GLsizei width
,
5259 GLsizei height
, GLsizei depth
,
5260 GLboolean fixedsamplelocations
,
5261 GLboolean immutable
, const char *func
)
5263 struct gl_texture_image
*texImage
;
5264 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5265 mesa_format texFormat
;
5266 GLenum sample_count_error
;
5267 bool dsa
= strstr(func
, "ture") ? true : false;
5269 if (!(ctx
->Extensions
.ARB_texture_multisample
5270 && _mesa_is_desktop_gl(ctx
))) {
5271 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5275 if (!check_multisample_target(dims
, target
, dsa
)) {
5277 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5281 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5286 /* check that the specified internalformat is color/depth/stencil-renderable;
5287 * refer GL3.1 spec 4.4.4
5290 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5291 _mesa_error(ctx
, GL_INVALID_ENUM
,
5292 "%s(internalformat=%s not legal for immutable-format)",
5293 func
, _mesa_lookup_enum_by_nr(internalformat
));
5297 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5298 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5299 "%s(internalformat=%s)",
5300 func
, _mesa_lookup_enum_by_nr(internalformat
));
5304 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5305 internalformat
, samples
);
5306 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5308 /* Page 254 of OpenGL 4.4 spec says:
5309 * "Proxy arrays for two-dimensional multisample and two-dimensional
5310 * multisample array textures are operated on in the same way when
5311 * TexImage2DMultisample is called with target specified as
5312 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5313 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5314 * However, if samples is not supported, then no error is generated.
5316 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5317 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5321 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5322 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5323 "%s(texture object 0)",
5328 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5330 if (texImage
== NULL
) {
5331 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5335 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5336 internalformat
, GL_NONE
, GL_NONE
);
5337 assert(texFormat
!= MESA_FORMAT_NONE
);
5339 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5340 width
, height
, depth
, 0);
5342 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5343 width
, height
, depth
, 0);
5345 if (_mesa_is_proxy_texture(target
)) {
5346 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5347 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5348 internalformat
, texFormat
,
5349 samples
, fixedsamplelocations
);
5352 /* clear all image fields */
5353 clear_teximage_fields(texImage
);
5357 if (!dimensionsOK
) {
5358 _mesa_error(ctx
, GL_INVALID_VALUE
,
5359 "%s(invalid width or height)", func
);
5364 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
5365 "%s(texture too large)", func
);
5369 /* Check if texObj->Immutable is set */
5370 if (texObj
->Immutable
) {
5371 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5375 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5377 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5378 internalformat
, texFormat
,
5379 samples
, fixedsamplelocations
);
5381 if (width
> 0 && height
> 0 && depth
> 0) {
5382 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5383 width
, height
, depth
)) {
5384 /* tidy up the texture image state. strictly speaking,
5385 * we're allowed to just leave this in whatever state we
5386 * like, but being tidy is good.
5388 _mesa_init_teximage_fields(ctx
, texImage
,
5389 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5393 texObj
->Immutable
|= immutable
;
5396 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5399 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5405 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5406 GLenum internalformat
, GLsizei width
,
5407 GLsizei height
, GLboolean fixedsamplelocations
)
5409 struct gl_texture_object
*texObj
;
5410 GET_CURRENT_CONTEXT(ctx
);
5412 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5416 _mesa_texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5417 internalformat
, width
, height
, 1,
5418 fixedsamplelocations
, GL_FALSE
,
5419 "glTexImage2DMultisample");
5424 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5425 GLenum internalformat
, GLsizei width
,
5426 GLsizei height
, GLsizei depth
,
5427 GLboolean fixedsamplelocations
)
5429 struct gl_texture_object
*texObj
;
5430 GET_CURRENT_CONTEXT(ctx
);
5432 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5436 _mesa_texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5437 internalformat
, width
, height
, depth
,
5438 fixedsamplelocations
, GL_FALSE
,
5439 "glTexImage3DMultisample");
5444 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5445 GLenum internalformat
, GLsizei width
,
5446 GLsizei height
, GLboolean fixedsamplelocations
)
5448 struct gl_texture_object
*texObj
;
5449 GET_CURRENT_CONTEXT(ctx
);
5451 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5455 _mesa_texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5456 internalformat
, width
, height
, 1,
5457 fixedsamplelocations
, GL_TRUE
,
5458 "glTexStorage2DMultisample");
5462 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5463 GLenum internalformat
, GLsizei width
,
5464 GLsizei height
, GLsizei depth
,
5465 GLboolean fixedsamplelocations
)
5467 struct gl_texture_object
*texObj
;
5468 GET_CURRENT_CONTEXT(ctx
);
5470 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5474 _mesa_texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5475 internalformat
, width
, height
, depth
,
5476 fixedsamplelocations
, GL_TRUE
,
5477 "glTexStorage3DMultisample");
5481 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5482 GLenum internalformat
, GLsizei width
,
5484 GLboolean fixedsamplelocations
)
5486 struct gl_texture_object
*texObj
;
5487 GET_CURRENT_CONTEXT(ctx
);
5489 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5490 "glTextureStorage2DMultisample");
5494 _mesa_texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5495 internalformat
, width
, height
, 1,
5496 fixedsamplelocations
, GL_TRUE
,
5497 "glTextureStorage2DMultisample");
5501 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5502 GLenum internalformat
, GLsizei width
,
5503 GLsizei height
, GLsizei depth
,
5504 GLboolean fixedsamplelocations
)
5506 struct gl_texture_object
*texObj
;
5507 GET_CURRENT_CONTEXT(ctx
);
5509 /* Get the texture object by Name. */
5510 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5511 "glTextureStorage3DMultisample");
5515 _mesa_texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5516 internalformat
, width
, height
, depth
,
5517 fixedsamplelocations
, GL_TRUE
,
5518 "glTextureStorage3DMultisample");