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 * Return the proxy target which corresponds to the given texture target
745 proxy_target(GLenum target
)
749 case GL_PROXY_TEXTURE_1D
:
750 return GL_PROXY_TEXTURE_1D
;
752 case GL_PROXY_TEXTURE_2D
:
753 return GL_PROXY_TEXTURE_2D
;
755 case GL_PROXY_TEXTURE_3D
:
756 return GL_PROXY_TEXTURE_3D
;
757 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
758 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
759 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
760 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
761 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
762 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
763 case GL_TEXTURE_CUBE_MAP_ARB
:
764 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
765 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
766 case GL_TEXTURE_RECTANGLE_NV
:
767 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
768 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
769 case GL_TEXTURE_1D_ARRAY_EXT
:
770 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
771 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
772 case GL_TEXTURE_2D_ARRAY_EXT
:
773 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
774 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
775 case GL_TEXTURE_CUBE_MAP_ARRAY
:
776 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
777 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
778 case GL_TEXTURE_2D_MULTISAMPLE
:
779 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
780 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
781 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
782 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
783 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
785 _mesa_problem(NULL
, "unexpected target in proxy_target()");
794 * Get a texture image pointer from a texture object, given a texture
795 * target and mipmap level. The target and level parameters should
796 * have already been error-checked.
798 * \param texObj texture unit.
799 * \param target texture target.
800 * \param level image level.
802 * \return pointer to the texture image structure, or NULL on failure.
804 struct gl_texture_image
*
805 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
806 GLenum target
, GLint level
)
808 const GLuint face
= _mesa_tex_target_to_face(target
);
812 assert(level
< MAX_TEXTURE_LEVELS
);
814 return texObj
->Image
[face
][level
];
819 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
820 * it and install it. Only return NULL if passed a bad parameter or run
823 struct gl_texture_image
*
824 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
825 GLenum target
, GLint level
)
827 struct gl_texture_image
*texImage
;
832 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
834 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
836 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
840 set_tex_image(texObj
, target
, level
, texImage
);
848 * Return pointer to the specified proxy texture image.
849 * Note that proxy textures are per-context, not per-texture unit.
850 * \return pointer to texture image or NULL if invalid target, invalid
851 * level, or out of memory.
853 static struct gl_texture_image
*
854 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
856 struct gl_texture_image
*texImage
;
863 case GL_PROXY_TEXTURE_1D
:
864 if (level
>= ctx
->Const
.MaxTextureLevels
)
866 texIndex
= TEXTURE_1D_INDEX
;
868 case GL_PROXY_TEXTURE_2D
:
869 if (level
>= ctx
->Const
.MaxTextureLevels
)
871 texIndex
= TEXTURE_2D_INDEX
;
873 case GL_PROXY_TEXTURE_3D
:
874 if (level
>= ctx
->Const
.Max3DTextureLevels
)
876 texIndex
= TEXTURE_3D_INDEX
;
878 case GL_PROXY_TEXTURE_CUBE_MAP
:
879 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
881 texIndex
= TEXTURE_CUBE_INDEX
;
883 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
886 texIndex
= TEXTURE_RECT_INDEX
;
888 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
889 if (level
>= ctx
->Const
.MaxTextureLevels
)
891 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
893 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
894 if (level
>= ctx
->Const
.MaxTextureLevels
)
896 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
898 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
899 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
901 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
903 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
906 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
908 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
911 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
917 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
919 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
921 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
924 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
925 /* Set the 'back' pointer */
926 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
933 * Get the maximum number of allowed mipmap levels.
935 * \param ctx GL context.
936 * \param target texture target.
938 * \return the maximum number of allowed mipmap levels for the given
939 * texture target, or zero if passed a bad target.
944 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
948 case GL_PROXY_TEXTURE_1D
:
950 case GL_PROXY_TEXTURE_2D
:
951 return ctx
->Const
.MaxTextureLevels
;
953 case GL_PROXY_TEXTURE_3D
:
954 return ctx
->Const
.Max3DTextureLevels
;
955 case GL_TEXTURE_CUBE_MAP
:
956 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
957 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
958 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
959 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
960 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
961 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
962 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
963 return ctx
->Extensions
.ARB_texture_cube_map
964 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
965 case GL_TEXTURE_RECTANGLE_NV
:
966 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
967 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
968 case GL_TEXTURE_1D_ARRAY_EXT
:
969 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
970 case GL_TEXTURE_2D_ARRAY_EXT
:
971 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
972 return ctx
->Extensions
.EXT_texture_array
973 ? ctx
->Const
.MaxTextureLevels
: 0;
974 case GL_TEXTURE_CUBE_MAP_ARRAY
:
975 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
976 return ctx
->Extensions
.ARB_texture_cube_map_array
977 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
978 case GL_TEXTURE_BUFFER
:
979 return ctx
->API
== API_OPENGL_CORE
&&
980 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
981 case GL_TEXTURE_2D_MULTISAMPLE
:
982 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
983 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
984 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
985 return _mesa_is_desktop_gl(ctx
)
986 && ctx
->Extensions
.ARB_texture_multisample
988 case GL_TEXTURE_EXTERNAL_OES
:
991 return 0; /* bad target */
997 * Return number of dimensions per mipmap level for the given texture target.
1000 _mesa_get_texture_dimensions(GLenum target
)
1004 case GL_PROXY_TEXTURE_1D
:
1007 case GL_TEXTURE_RECTANGLE
:
1008 case GL_TEXTURE_CUBE_MAP
:
1009 case GL_PROXY_TEXTURE_2D
:
1010 case GL_PROXY_TEXTURE_RECTANGLE
:
1011 case GL_PROXY_TEXTURE_CUBE_MAP
:
1012 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1013 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1014 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1015 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1016 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1017 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1018 case GL_TEXTURE_1D_ARRAY
:
1019 case GL_PROXY_TEXTURE_1D_ARRAY
:
1020 case GL_TEXTURE_EXTERNAL_OES
:
1021 case GL_TEXTURE_2D_MULTISAMPLE
:
1022 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1025 case GL_PROXY_TEXTURE_3D
:
1026 case GL_TEXTURE_2D_ARRAY
:
1027 case GL_PROXY_TEXTURE_2D_ARRAY
:
1028 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1029 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1030 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1031 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1033 case GL_TEXTURE_BUFFER
:
1036 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1044 * Check if a texture target can have more than one layer.
1047 _mesa_tex_target_is_layered(GLenum target
)
1051 case GL_PROXY_TEXTURE_1D
:
1053 case GL_PROXY_TEXTURE_2D
:
1054 case GL_TEXTURE_RECTANGLE
:
1055 case GL_PROXY_TEXTURE_RECTANGLE
:
1056 case GL_TEXTURE_2D_MULTISAMPLE
:
1057 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1058 case GL_TEXTURE_BUFFER
:
1059 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1060 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1061 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1062 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1063 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1064 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1065 case GL_TEXTURE_EXTERNAL_OES
:
1069 case GL_PROXY_TEXTURE_3D
:
1070 case GL_TEXTURE_CUBE_MAP
:
1071 case GL_PROXY_TEXTURE_CUBE_MAP
:
1072 case GL_TEXTURE_1D_ARRAY
:
1073 case GL_PROXY_TEXTURE_1D_ARRAY
:
1074 case GL_TEXTURE_2D_ARRAY
:
1075 case GL_PROXY_TEXTURE_2D_ARRAY
:
1076 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1077 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1078 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1079 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1083 assert(!"Invalid texture target.");
1090 * Return the number of layers present in the given level of an array,
1091 * cubemap or 3D texture. If the texture is not layered return zero.
1094 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1096 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1098 switch (texObj
->Target
) {
1101 case GL_TEXTURE_RECTANGLE
:
1102 case GL_TEXTURE_2D_MULTISAMPLE
:
1103 case GL_TEXTURE_BUFFER
:
1104 case GL_TEXTURE_EXTERNAL_OES
:
1107 case GL_TEXTURE_CUBE_MAP
:
1110 case GL_TEXTURE_1D_ARRAY
: {
1111 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1112 return img
? img
->Height
: 0;
1116 case GL_TEXTURE_2D_ARRAY
:
1117 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1118 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1119 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1120 return img
? img
->Depth
: 0;
1124 assert(!"Invalid texture target.");
1131 * Return the maximum number of mipmap levels for the given target
1132 * and the dimensions.
1133 * The dimensions are expected not to include the border.
1136 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1143 case GL_TEXTURE_1D_ARRAY
:
1144 case GL_PROXY_TEXTURE_1D
:
1145 case GL_PROXY_TEXTURE_1D_ARRAY
:
1148 case GL_TEXTURE_CUBE_MAP
:
1149 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1150 case GL_PROXY_TEXTURE_CUBE_MAP
:
1151 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1155 case GL_TEXTURE_2D_ARRAY
:
1156 case GL_PROXY_TEXTURE_2D
:
1157 case GL_PROXY_TEXTURE_2D_ARRAY
:
1158 size
= MAX2(width
, height
);
1161 case GL_PROXY_TEXTURE_3D
:
1162 size
= MAX3(width
, height
, depth
);
1164 case GL_TEXTURE_RECTANGLE
:
1165 case GL_TEXTURE_EXTERNAL_OES
:
1166 case GL_TEXTURE_2D_MULTISAMPLE
:
1167 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1168 case GL_PROXY_TEXTURE_RECTANGLE
:
1169 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1170 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1177 return _mesa_logbase2(size
) + 1;
1181 #if 000 /* not used anymore */
1183 * glTexImage[123]D can accept a NULL image pointer. In this case we
1184 * create a texture image with unspecified image contents per the OpenGL
1188 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1190 const GLint components
= _mesa_components_in_format(format
);
1191 const GLint numPixels
= width
* height
* depth
;
1192 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1196 * Let's see if anyone finds this. If glTexImage2D() is called with
1197 * a NULL image pointer then load the texture image with something
1198 * interesting instead of leaving it indeterminate.
1201 static const char message
[8][32] = {
1202 " X X XXXXX XXX X ",
1203 " XX XX X X X X X ",
1205 " X X XXXX XXX XXXXX ",
1208 " X X XXXXX XXX X X ",
1212 GLubyte
*imgPtr
= data
;
1214 for (h
= 0; h
< depth
; h
++) {
1215 for (i
= 0; i
< height
; i
++) {
1216 GLint srcRow
= 7 - (i
% 8);
1217 for (j
= 0; j
< width
; j
++) {
1218 GLint srcCol
= j
% 32;
1219 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1220 for (k
= 0; k
< components
; k
++) {
1236 * Set the size and format-related fields of a gl_texture_image struct
1237 * to zero. This is used when a proxy texture test fails.
1240 clear_teximage_fields(struct gl_texture_image
*img
)
1243 img
->_BaseFormat
= 0;
1244 img
->InternalFormat
= 0;
1253 img
->HeightLog2
= 0;
1255 img
->TexFormat
= MESA_FORMAT_NONE
;
1256 img
->NumSamples
= 0;
1257 img
->FixedSampleLocations
= GL_TRUE
;
1262 * Initialize basic fields of the gl_texture_image struct.
1264 * \param ctx GL context.
1265 * \param img texture image structure to be initialized.
1266 * \param width image width.
1267 * \param height image height.
1268 * \param depth image depth.
1269 * \param border image border.
1270 * \param internalFormat internal format.
1271 * \param format the actual hardware format (one of MESA_FORMAT_*)
1272 * \param numSamples number of samples per texel, or zero for non-MS.
1273 * \param fixedSampleLocations are sample locations fixed?
1275 * Fills in the fields of \p img with the given information.
1276 * Note: width, height and depth include the border.
1279 init_teximage_fields_ms(struct gl_context
*ctx
,
1280 struct gl_texture_image
*img
,
1281 GLsizei width
, GLsizei height
, GLsizei depth
,
1282 GLint border
, GLenum internalFormat
,
1284 GLuint numSamples
, GLboolean fixedSampleLocations
)
1289 assert(height
>= 0);
1292 target
= img
->TexObject
->Target
;
1293 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1294 assert(img
->_BaseFormat
!= -1);
1295 img
->InternalFormat
= internalFormat
;
1296 img
->Border
= border
;
1298 img
->Height
= height
;
1301 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1302 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1304 img
->NumSamples
= 0;
1305 img
->FixedSampleLocations
= GL_TRUE
;
1309 case GL_TEXTURE_BUFFER
:
1310 case GL_PROXY_TEXTURE_1D
:
1315 img
->HeightLog2
= 0;
1322 case GL_TEXTURE_1D_ARRAY
:
1323 case GL_PROXY_TEXTURE_1D_ARRAY
:
1324 img
->Height2
= height
; /* no border */
1325 img
->HeightLog2
= 0; /* not used */
1333 case GL_TEXTURE_RECTANGLE
:
1334 case GL_TEXTURE_CUBE_MAP
:
1335 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1336 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1337 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1338 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1339 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1340 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1341 case GL_TEXTURE_EXTERNAL_OES
:
1342 case GL_PROXY_TEXTURE_2D
:
1343 case GL_PROXY_TEXTURE_RECTANGLE
:
1344 case GL_PROXY_TEXTURE_CUBE_MAP
:
1345 case GL_TEXTURE_2D_MULTISAMPLE
:
1346 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1347 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1348 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1355 case GL_TEXTURE_2D_ARRAY
:
1356 case GL_PROXY_TEXTURE_2D_ARRAY
:
1357 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1358 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1359 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1360 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1361 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1362 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1363 img
->Depth2
= depth
; /* no border */
1364 img
->DepthLog2
= 0; /* not used */
1367 case GL_PROXY_TEXTURE_3D
:
1368 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1369 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1370 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1371 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1374 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1379 _mesa_get_tex_max_num_levels(target
,
1380 img
->Width2
, img
->Height2
, img
->Depth2
);
1381 img
->TexFormat
= format
;
1382 img
->NumSamples
= numSamples
;
1383 img
->FixedSampleLocations
= fixedSampleLocations
;
1388 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1389 struct gl_texture_image
*img
,
1390 GLsizei width
, GLsizei height
, GLsizei depth
,
1391 GLint border
, GLenum internalFormat
,
1394 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1395 internalFormat
, format
, 0, GL_TRUE
);
1400 * Free and clear fields of the gl_texture_image struct.
1402 * \param ctx GL context.
1403 * \param texImage texture image structure to be cleared.
1405 * After the call, \p texImage will have no data associated with it. Its
1406 * fields are cleared so that its parent object will test incomplete.
1409 _mesa_clear_texture_image(struct gl_context
*ctx
,
1410 struct gl_texture_image
*texImage
)
1412 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1413 clear_teximage_fields(texImage
);
1418 * Check the width, height, depth and border of a texture image are legal.
1419 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1421 * The target and level parameters will have already been validated.
1422 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1425 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1426 GLint level
, GLint width
, GLint height
,
1427 GLint depth
, GLint border
)
1433 case GL_PROXY_TEXTURE_1D
:
1434 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1435 maxSize
>>= level
; /* level size */
1436 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1438 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1439 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1445 case GL_PROXY_TEXTURE_2D
:
1446 case GL_TEXTURE_2D_MULTISAMPLE
:
1447 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1448 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1450 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1452 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1454 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1455 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1457 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1463 case GL_PROXY_TEXTURE_3D
:
1464 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1466 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1468 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1470 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1472 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1473 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1475 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1477 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1482 case GL_TEXTURE_RECTANGLE_NV
:
1483 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1486 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1487 if (width
< 0 || width
> maxSize
)
1489 if (height
< 0 || height
> maxSize
)
1493 case GL_TEXTURE_CUBE_MAP
:
1494 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1495 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1496 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1497 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1498 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1499 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1500 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1501 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1503 if (width
!= height
)
1505 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1507 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1509 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1510 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1512 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1517 case GL_TEXTURE_1D_ARRAY_EXT
:
1518 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1519 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1521 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1523 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1525 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1526 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1531 case GL_TEXTURE_2D_ARRAY_EXT
:
1532 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1533 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1534 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1535 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1537 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1539 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1541 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1543 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1544 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1546 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1551 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1552 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1553 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1554 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1556 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1558 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1560 if (width
!= height
)
1562 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1564 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1565 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1567 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1572 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1579 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1580 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1581 * \param destImage the destination texture image.
1582 * \return GL_TRUE if error found, GL_FALSE otherwise.
1585 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1586 const struct gl_texture_image
*destImage
,
1587 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1588 GLsizei subWidth
, GLsizei subHeight
,
1589 GLsizei subDepth
, const char *func
)
1591 const GLenum target
= destImage
->TexObject
->Target
;
1596 _mesa_error(ctx
, GL_INVALID_VALUE
,
1597 "%s%dD(width=%d)", func
, dims
, subWidth
);
1601 if (dims
> 1 && subHeight
< 0) {
1602 _mesa_error(ctx
, GL_INVALID_VALUE
,
1603 "%s%dD(height=%d)", func
, dims
, subHeight
);
1607 if (dims
> 2 && subDepth
< 0) {
1608 _mesa_error(ctx
, GL_INVALID_VALUE
,
1609 "%s%dD(depth=%d)", func
, dims
, subDepth
);
1613 /* check xoffset and width */
1614 if (xoffset
< - (GLint
) destImage
->Border
) {
1615 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1620 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1621 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1626 /* check yoffset and height */
1628 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1629 if (yoffset
< -yBorder
) {
1630 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1634 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1635 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1641 /* check zoffset and depth */
1644 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1645 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1646 0 : destImage
->Border
;
1648 if (zoffset
< -zBorder
) {
1649 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", func
);
1653 depth
= (GLint
) destImage
->Depth
;
1654 if (target
== GL_TEXTURE_CUBE_MAP
)
1656 if (zoffset
+ subDepth
> depth
) {
1657 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", func
);
1663 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1664 * compressed texture images can be updated. But, that restriction may be
1665 * relaxed for particular compressed formats. At this time, all the
1666 * compressed formats supported by Mesa allow sub-textures to be updated
1667 * along compressed block boundaries.
1669 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1671 if (bw
!= 1 || bh
!= 1) {
1672 /* offset must be multiple of block size */
1673 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1674 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1675 "%s%dD(xoffset = %d, yoffset = %d)",
1676 func
, dims
, xoffset
, yoffset
);
1680 /* The size must be a multiple of bw x bh, or we must be using a
1681 * offset+size that exactly hits the edge of the image. This
1682 * is important for small mipmap levels (1x1, 2x1, etc) and for
1685 if ((subWidth
% bw
!= 0) &&
1686 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1687 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1688 "%s%dD(width = %d)", func
, dims
, subWidth
);
1692 if ((subHeight
% bh
!= 0) &&
1693 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1694 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1695 "%s%dD(height = %d)", func
, dims
, subHeight
);
1707 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1708 * specific texture image size checks.
1710 * A hardware driver might override this function if, for example, the
1711 * max 3D texture size is 512x512x64 (i.e. not a cube).
1713 * Note that width, height, depth == 0 is not an error. However, a
1714 * texture with zero width/height/depth will be considered "incomplete"
1715 * and texturing will effectively be disabled.
1717 * \param target any texture target/type
1718 * \param level as passed to glTexImage
1719 * \param format the MESA_FORMAT_x for the tex image
1720 * \param width as passed to glTexImage
1721 * \param height as passed to glTexImage
1722 * \param depth as passed to glTexImage
1723 * \param border as passed to glTexImage
1724 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1727 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1729 GLint width
, GLint height
, GLint depth
, GLint border
)
1731 /* We just check if the image size is less than MaxTextureMbytes.
1732 * Some drivers may do more specific checks.
1734 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1735 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1736 mbytes
*= _mesa_num_tex_faces(target
);
1737 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1742 * Return true if the format is only valid for glCompressedTexImage.
1745 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1748 case GL_ETC1_RGB8_OES
:
1749 case GL_PALETTE4_RGB8_OES
:
1750 case GL_PALETTE4_RGBA8_OES
:
1751 case GL_PALETTE4_R5_G6_B5_OES
:
1752 case GL_PALETTE4_RGBA4_OES
:
1753 case GL_PALETTE4_RGB5_A1_OES
:
1754 case GL_PALETTE8_RGB8_OES
:
1755 case GL_PALETTE8_RGBA8_OES
:
1756 case GL_PALETTE8_R5_G6_B5_OES
:
1757 case GL_PALETTE8_RGBA4_OES
:
1758 case GL_PALETTE8_RGB5_A1_OES
:
1767 * Helper function to determine whether a target and specific compression
1768 * format are supported.
1771 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1774 (void) intFormat
; /* not used yet */
1778 case GL_PROXY_TEXTURE_2D
:
1779 return GL_TRUE
; /* true for any compressed format so far */
1780 case GL_PROXY_TEXTURE_CUBE_MAP
:
1781 case GL_TEXTURE_CUBE_MAP
:
1782 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1783 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1784 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1785 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1786 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1787 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1788 return ctx
->Extensions
.ARB_texture_cube_map
;
1789 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1790 case GL_TEXTURE_2D_ARRAY_EXT
:
1791 return ctx
->Extensions
.EXT_texture_array
;
1792 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1793 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1794 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1802 * Check if the given texture target value is legal for a
1803 * glTexImage1/2/3D call.
1806 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1812 case GL_PROXY_TEXTURE_1D
:
1813 return _mesa_is_desktop_gl(ctx
);
1821 case GL_PROXY_TEXTURE_2D
:
1822 return _mesa_is_desktop_gl(ctx
);
1823 case GL_PROXY_TEXTURE_CUBE_MAP
:
1824 return _mesa_is_desktop_gl(ctx
)
1825 && ctx
->Extensions
.ARB_texture_cube_map
;
1826 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1827 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1828 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1829 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1830 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1831 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1832 return ctx
->Extensions
.ARB_texture_cube_map
;
1833 case GL_TEXTURE_RECTANGLE_NV
:
1834 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1835 return _mesa_is_desktop_gl(ctx
)
1836 && ctx
->Extensions
.NV_texture_rectangle
;
1837 case GL_TEXTURE_1D_ARRAY_EXT
:
1838 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1839 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1847 case GL_PROXY_TEXTURE_3D
:
1848 return _mesa_is_desktop_gl(ctx
);
1849 case GL_TEXTURE_2D_ARRAY_EXT
:
1850 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1851 || _mesa_is_gles3(ctx
);
1852 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1853 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1854 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1855 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1856 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1861 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1868 * Check if the given texture target value is legal for a
1869 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1870 * The difference compared to legal_teximage_target() above is that
1871 * proxy targets are not supported.
1874 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1879 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1884 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1885 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1886 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1887 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1888 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1889 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1890 return ctx
->Extensions
.ARB_texture_cube_map
;
1891 case GL_TEXTURE_RECTANGLE_NV
:
1892 return _mesa_is_desktop_gl(ctx
)
1893 && ctx
->Extensions
.NV_texture_rectangle
;
1894 case GL_TEXTURE_1D_ARRAY_EXT
:
1895 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1903 case GL_TEXTURE_2D_ARRAY_EXT
:
1904 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1905 || _mesa_is_gles3(ctx
);
1906 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1907 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1908 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1910 /* Table 8.15 of the OpenGL 4.5 core profile spec
1911 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1912 * and CopyTextureSubImage3D.
1914 case GL_TEXTURE_CUBE_MAP
:
1920 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1928 * Helper function to determine if a texture object is mutable (in terms
1929 * of GL_ARB_texture_storage).
1932 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1934 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1938 return !texObj
->Immutable
;
1943 * Return expected size of a compressed texture.
1946 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1949 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1950 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1954 * Verify that a texture format is valid with a particular target
1956 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1957 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1960 * \param ctx GL context
1961 * \param target Texture target
1962 * \param internalFormat Internal format of the texture image
1963 * \param dimensions Dimensionality at the caller. This is \b not used
1964 * in the validation. It is only used when logging
1966 * \param caller Base name of the calling function (e.g.,
1967 * "glTexImage" or "glTexStorage").
1969 * \returns true if the combination is legal, false otherwise.
1972 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1973 GLenum target
, GLenum internalFormat
,
1974 unsigned dimensions
,
1977 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1978 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
1979 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1980 * Profile spec says:
1982 * "Textures with a base internal format of DEPTH_COMPONENT or
1983 * DEPTH_STENCIL are supported by texture image specification
1984 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1985 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1986 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1987 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1988 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1989 * formats in conjunction with any other target will result in an
1990 * INVALID_OPERATION error."
1992 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1993 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1995 if (target
!= GL_TEXTURE_1D
&&
1996 target
!= GL_PROXY_TEXTURE_1D
&&
1997 target
!= GL_TEXTURE_2D
&&
1998 target
!= GL_PROXY_TEXTURE_2D
&&
1999 target
!= GL_TEXTURE_1D_ARRAY
&&
2000 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2001 target
!= GL_TEXTURE_2D_ARRAY
&&
2002 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2003 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2004 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2005 !((_mesa_is_cube_face(target
) ||
2006 target
== GL_TEXTURE_CUBE_MAP
||
2007 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2008 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2009 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2010 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2011 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2012 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2013 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2014 "%s%dD(bad target for depth texture)",
2015 caller
, dimensions
);
2024 texture_formats_agree(GLenum internalFormat
,
2027 GLboolean colorFormat
;
2028 GLboolean is_format_depth_or_depthstencil
;
2029 GLboolean is_internalFormat_depth_or_depthstencil
;
2031 /* Even though there are no color-index textures, we still have to support
2032 * uploading color-index data and remapping it to RGB via the
2033 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2035 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2037 is_internalFormat_depth_or_depthstencil
=
2038 _mesa_is_depth_format(internalFormat
) ||
2039 _mesa_is_depthstencil_format(internalFormat
);
2041 is_format_depth_or_depthstencil
=
2042 _mesa_is_depth_format(format
) ||
2043 _mesa_is_depthstencil_format(format
);
2045 colorFormat
= _mesa_is_color_format(format
);
2047 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2050 if (is_internalFormat_depth_or_depthstencil
!=
2051 is_format_depth_or_depthstencil
)
2054 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2061 * Test the glTexImage[123]D() parameters for errors.
2063 * \param ctx GL context.
2064 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2065 * \param target texture target given by the user (already validated).
2066 * \param level image level given by the user.
2067 * \param internalFormat internal format given by the user.
2068 * \param format pixel data format given by the user.
2069 * \param type pixel data type given by the user.
2070 * \param width image width given by the user.
2071 * \param height image height given by the user.
2072 * \param depth image depth given by the user.
2073 * \param border image border given by the user.
2075 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2077 * Verifies each of the parameters against the constants specified in
2078 * __struct gl_contextRec::Const and the supported extensions, and according
2079 * to the OpenGL specification.
2080 * Note that we don't fully error-check the width, height, depth values
2081 * here. That's done in _mesa_legal_texture_dimensions() which is used
2082 * by several other GL entrypoints. Plus, texture dims have a special
2083 * interaction with proxy textures.
2086 texture_error_check( struct gl_context
*ctx
,
2087 GLuint dimensions
, GLenum target
,
2088 GLint level
, GLint internalFormat
,
2089 GLenum format
, GLenum type
,
2090 GLint width
, GLint height
,
2091 GLint depth
, GLint border
)
2095 /* Note: for proxy textures, some error conditions immediately generate
2096 * a GL error in the usual way. But others do not generate a GL error.
2097 * Instead, they cause the width, height, depth, format fields of the
2098 * texture image to be zeroed-out. The GL spec seems to indicate that the
2099 * zero-out behaviour is only used in cases related to memory allocation.
2103 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2104 _mesa_error(ctx
, GL_INVALID_VALUE
,
2105 "glTexImage%dD(level=%d)", dimensions
, level
);
2110 if (border
< 0 || border
> 1 ||
2111 ((ctx
->API
!= API_OPENGL_COMPAT
||
2112 target
== GL_TEXTURE_RECTANGLE_NV
||
2113 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2114 _mesa_error(ctx
, GL_INVALID_VALUE
,
2115 "glTexImage%dD(border=%d)", dimensions
, border
);
2119 if (width
< 0 || height
< 0 || depth
< 0) {
2120 _mesa_error(ctx
, GL_INVALID_VALUE
,
2121 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2125 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2126 * combinations of format, internalFormat, and type that can be used.
2127 * Formats and types that require additional extensions (e.g., GL_FLOAT
2128 * requires GL_OES_texture_float) are filtered elsewhere.
2131 if (_mesa_is_gles(ctx
)) {
2132 if (_mesa_is_gles3(ctx
)) {
2133 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
2136 if (format
!= internalFormat
) {
2137 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2138 "glTexImage%dD(format = %s, internalFormat = %s)",
2140 _mesa_lookup_enum_by_nr(format
),
2141 _mesa_lookup_enum_by_nr(internalFormat
));
2145 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2147 if (err
!= GL_NO_ERROR
) {
2148 _mesa_error(ctx
, err
,
2149 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2151 _mesa_lookup_enum_by_nr(format
),
2152 _mesa_lookup_enum_by_nr(type
),
2153 _mesa_lookup_enum_by_nr(internalFormat
));
2158 /* Check internalFormat */
2159 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2160 _mesa_error(ctx
, GL_INVALID_VALUE
,
2161 "glTexImage%dD(internalFormat=%s)",
2162 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2166 /* Check incoming image format and type */
2167 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2168 if (err
!= GL_NO_ERROR
) {
2169 _mesa_error(ctx
, err
,
2170 "glTexImage%dD(incompatible format = %s, type = %s)",
2171 dimensions
, _mesa_lookup_enum_by_nr(format
),
2172 _mesa_lookup_enum_by_nr(type
));
2176 /* make sure internal format and format basically agree */
2177 if (!texture_formats_agree(internalFormat
, format
)) {
2178 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2179 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2180 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2181 _mesa_lookup_enum_by_nr(format
));
2185 /* additional checks for ycbcr textures */
2186 if (internalFormat
== GL_YCBCR_MESA
) {
2187 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
2188 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2189 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2191 _mesa_snprintf(message
, sizeof(message
),
2192 "glTexImage%dD(format/type YCBCR mismatch)",
2194 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2195 return GL_TRUE
; /* error */
2197 if (target
!= GL_TEXTURE_2D
&&
2198 target
!= GL_PROXY_TEXTURE_2D
&&
2199 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2200 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2201 _mesa_error(ctx
, GL_INVALID_ENUM
,
2202 "glTexImage%dD(bad target for YCbCr texture)",
2208 _mesa_snprintf(message
, sizeof(message
),
2209 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2210 dimensions
, border
);
2211 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2216 /* additional checks for depth textures */
2217 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2218 dimensions
, "glTexImage"))
2221 /* additional checks for compressed textures */
2222 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2223 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2224 _mesa_error(ctx
, GL_INVALID_ENUM
,
2225 "glTexImage%dD(target can't be compressed)", dimensions
);
2228 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2229 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2230 "glTexImage%dD(no compression for format)", dimensions
);
2234 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2235 "glTexImage%dD(border!=0)", dimensions
);
2240 /* additional checks for integer textures */
2241 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2242 (_mesa_is_enum_format_integer(format
) !=
2243 _mesa_is_enum_format_integer(internalFormat
))) {
2244 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2245 "glTexImage%dD(integer/non-integer format mismatch)",
2250 if (!mutable_tex_object(ctx
, target
)) {
2251 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2252 "glTexImage%dD(immutable texture)", dimensions
);
2256 /* if we get here, the parameters are OK */
2262 * Error checking for glCompressedTexImage[123]D().
2263 * Note that the width, height and depth values are not fully error checked
2265 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2268 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2269 GLenum target
, GLint level
,
2270 GLenum internalFormat
, GLsizei width
,
2271 GLsizei height
, GLsizei depth
, GLint border
,
2274 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2276 GLenum error
= GL_NO_ERROR
;
2277 char *reason
= ""; /* no error */
2279 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2281 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
2283 * "The ETC2/EAC texture compression algorithm supports only
2284 * two-dimensional images. If internalformat is an ETC2/EAC format,
2285 * CompressedTexImage3D will generate an INVALID_OPERATION error if
2286 * target is not TEXTURE_2D_ARRAY."
2288 error
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
2292 /* This will detect any invalid internalFormat value */
2293 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2294 _mesa_error(ctx
, GL_INVALID_ENUM
,
2295 "glCompressedTexImage%dD(internalFormat=%s)",
2296 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2300 switch (internalFormat
) {
2301 case GL_PALETTE4_RGB8_OES
:
2302 case GL_PALETTE4_RGBA8_OES
:
2303 case GL_PALETTE4_R5_G6_B5_OES
:
2304 case GL_PALETTE4_RGBA4_OES
:
2305 case GL_PALETTE4_RGB5_A1_OES
:
2306 case GL_PALETTE8_RGB8_OES
:
2307 case GL_PALETTE8_RGBA8_OES
:
2308 case GL_PALETTE8_R5_G6_B5_OES
:
2309 case GL_PALETTE8_RGBA4_OES
:
2310 case GL_PALETTE8_RGB5_A1_OES
:
2311 /* check level (note that level should be zero or less!) */
2312 if (level
> 0 || level
< -maxLevels
) {
2314 error
= GL_INVALID_VALUE
;
2318 if (dimensions
!= 2) {
2319 reason
= "compressed paletted textures must be 2D";
2320 error
= GL_INVALID_OPERATION
;
2324 /* Figure out the expected texture size (in bytes). This will be
2325 * checked against the actual size later.
2327 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2330 /* This is for the benefit of the TestProxyTexImage below. It expects
2331 * level to be non-negative. OES_compressed_paletted_texture uses a
2332 * weird mechanism where the level specified to glCompressedTexImage2D
2333 * is -(n-1) number of levels in the texture, and the data specifies the
2334 * complete mipmap stack. This is done to ensure the palette is the
2335 * same for all levels.
2342 if (level
< 0 || level
>= maxLevels
) {
2344 error
= GL_INVALID_VALUE
;
2348 /* Figure out the expected texture size (in bytes). This will be
2349 * checked against the actual size later.
2351 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2355 /* This should really never fail */
2356 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2357 reason
= "internalFormat";
2358 error
= GL_INVALID_ENUM
;
2362 /* No compressed formats support borders at this time */
2364 reason
= "border != 0";
2365 error
= GL_INVALID_VALUE
;
2369 /* Check for invalid pixel storage modes */
2370 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2372 "glCompressedTexImage")) {
2376 /* check image size in bytes */
2377 if (expectedSize
!= imageSize
) {
2378 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2379 * if <imageSize> is not consistent with the format, dimensions, and
2380 * contents of the specified image.
2382 reason
= "imageSize inconsistant with width/height/format";
2383 error
= GL_INVALID_VALUE
;
2387 if (!mutable_tex_object(ctx
, target
)) {
2388 reason
= "immutable texture";
2389 error
= GL_INVALID_OPERATION
;
2396 /* Note: not all error paths exit through here. */
2397 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2398 dimensions
, reason
);
2405 * Test glTexSubImage[123]D() parameters for errors.
2407 * \param ctx GL context.
2408 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2409 * \param target texture target given by the user (already validated)
2410 * \param level image level given by the user.
2411 * \param xoffset sub-image x offset given by the user.
2412 * \param yoffset sub-image y offset given by the user.
2413 * \param zoffset sub-image z offset given by the user.
2414 * \param format pixel data format given by the user.
2415 * \param type pixel data type given by the user.
2416 * \param width image width given by the user.
2417 * \param height image height given by the user.
2418 * \param depth image depth given by the user.
2420 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2422 * Verifies each of the parameters against the constants specified in
2423 * __struct gl_contextRec::Const and the supported extensions, and according
2424 * to the OpenGL specification.
2427 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2428 struct gl_texture_object
*texObj
,
2429 GLenum target
, GLint level
,
2430 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2431 GLint width
, GLint height
, GLint depth
,
2432 GLenum format
, GLenum type
, bool dsa
)
2434 struct gl_texture_image
*texImage
;
2436 const char* suffix
= dsa
? "ture" : "";
2439 /* must be out of memory */
2440 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTex%sSubImage%dD()",
2441 suffix
, dimensions
);
2445 /* check target (proxies not allowed) */
2446 if (!legal_texsubimage_target(ctx
, dimensions
, target
, dsa
)) {
2447 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sSubImage%uD(target=%s)",
2448 suffix
, dimensions
, _mesa_lookup_enum_by_nr(target
));
2453 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2454 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sSubImage%uD(level=%d)",
2455 suffix
, dimensions
, level
);
2459 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2460 * combinations of format and type that can be used. Formats and types
2461 * that require additional extensions (e.g., GL_FLOAT requires
2462 * GL_OES_texture_float) are filtered elsewhere.
2464 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2465 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2466 if (err
!= GL_NO_ERROR
) {
2467 _mesa_error(ctx
, err
,
2468 "glTex%sSubImage%dD(format = %s, type = %s)",
2469 suffix
, dimensions
, _mesa_lookup_enum_by_nr(format
),
2470 _mesa_lookup_enum_by_nr(type
));
2475 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2476 if (err
!= GL_NO_ERROR
) {
2477 _mesa_error(ctx
, err
,
2478 "glTex%sSubImage%dD(incompatible format = %s, type = %s)",
2479 suffix
, dimensions
, _mesa_lookup_enum_by_nr(format
),
2480 _mesa_lookup_enum_by_nr(type
));
2484 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2486 /* non-existant texture level */
2487 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2488 "glTex%sSubImage%dD(invalid texture image)", suffix
,
2493 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2494 texImage
, xoffset
, yoffset
, 0,
2496 dsa
? "glTextureSubImage" :
2501 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2502 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2503 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2504 "glTex%sSubImage%dD(no compression for format)",
2505 suffix
, dimensions
);
2510 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2511 /* both source and dest must be integer-valued, or neither */
2512 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2513 _mesa_is_enum_format_integer(format
)) {
2514 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2515 "glTex%sSubImage%dD(integer/non-integer format mismatch)",
2516 suffix
, dimensions
);
2526 * Test glCopyTexImage[12]D() parameters for errors.
2528 * \param ctx GL context.
2529 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2530 * \param target texture target given by the user.
2531 * \param level image level given by the user.
2532 * \param internalFormat internal format given by the user.
2533 * \param width image width given by the user.
2534 * \param height image height given by the user.
2535 * \param border texture border.
2537 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2539 * Verifies each of the parameters against the constants specified in
2540 * __struct gl_contextRec::Const and the supported extensions, and according
2541 * to the OpenGL specification.
2544 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2545 GLenum target
, GLint level
, GLint internalFormat
,
2546 GLint width
, GLint height
, GLint border
)
2549 GLint rb_base_format
;
2550 struct gl_renderbuffer
*rb
;
2551 GLenum rb_internal_format
;
2554 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2555 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2556 dimensions
, _mesa_lookup_enum_by_nr(target
));
2561 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2562 _mesa_error(ctx
, GL_INVALID_VALUE
,
2563 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2567 /* Check that the source buffer is complete */
2568 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2569 if (ctx
->ReadBuffer
->_Status
== 0) {
2570 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2572 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2573 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2574 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2578 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2579 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2580 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2586 if (border
< 0 || border
> 1 ||
2587 ((ctx
->API
!= API_OPENGL_COMPAT
||
2588 target
== GL_TEXTURE_RECTANGLE_NV
||
2589 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2590 _mesa_error(ctx
, GL_INVALID_VALUE
,
2591 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2595 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2597 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2598 "glCopyTexImage%dD(read buffer)", dimensions
);
2602 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2605 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2606 switch (internalFormat
) {
2611 case GL_LUMINANCE_ALPHA
:
2614 _mesa_error(ctx
, GL_INVALID_VALUE
,
2615 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2616 _mesa_lookup_enum_by_nr(internalFormat
));
2621 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2622 if (baseFormat
< 0) {
2623 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2624 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2625 _mesa_lookup_enum_by_nr(internalFormat
));
2629 rb_internal_format
= rb
->InternalFormat
;
2630 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2631 if (_mesa_is_color_format(internalFormat
)) {
2632 if (rb_base_format
< 0) {
2633 _mesa_error(ctx
, GL_INVALID_VALUE
,
2634 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2635 _mesa_lookup_enum_by_nr(internalFormat
));
2640 if (_mesa_is_gles(ctx
)) {
2642 if (_mesa_base_format_component_count(baseFormat
) >
2643 _mesa_base_format_component_count(rb_base_format
)) {
2646 if (baseFormat
== GL_DEPTH_COMPONENT
||
2647 baseFormat
== GL_DEPTH_STENCIL
||
2648 rb_base_format
== GL_DEPTH_COMPONENT
||
2649 rb_base_format
== GL_DEPTH_STENCIL
||
2650 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2651 baseFormat
== GL_ALPHA
) &&
2652 rb_base_format
!= GL_RGBA
) ||
2653 internalFormat
== GL_RGB9_E5
) {
2656 if (internalFormat
== GL_RGB9_E5
) {
2660 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2661 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2662 _mesa_lookup_enum_by_nr(internalFormat
));
2667 if (_mesa_is_gles3(ctx
)) {
2668 bool rb_is_srgb
= false;
2669 bool dst_is_srgb
= false;
2671 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2672 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2676 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2680 if (rb_is_srgb
!= dst_is_srgb
) {
2681 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2682 * OpenGLES 3.0.0 spec says:
2684 * "The error INVALID_OPERATION is also generated if the
2685 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2686 * framebuffer attachment corresponding to the read buffer
2687 * is LINEAR (see section 6.1.13) and internalformat is
2688 * one of the sRGB formats described in section 3.8.16, or
2689 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2690 * SRGB and internalformat is not one of the sRGB formats."
2692 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2693 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2697 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2698 * types for SNORM formats. Also, conversion to SNORM formats is not
2699 * allowed by Table 3.2 on Page 110.
2701 if(_mesa_is_enum_format_snorm(internalFormat
)) {
2702 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2703 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2704 _mesa_lookup_enum_by_nr(internalFormat
));
2709 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2710 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2711 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2715 /* From the EXT_texture_integer spec:
2717 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2718 * if the texture internalformat is an integer format and the read color
2719 * buffer is not an integer format, or if the internalformat is not an
2720 * integer format and the read color buffer is an integer format."
2722 if (_mesa_is_color_format(internalFormat
)) {
2723 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2724 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2725 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2726 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2727 if (is_int
|| is_rbint
) {
2728 if (is_int
!= is_rbint
) {
2729 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2730 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2732 } else if (_mesa_is_gles(ctx
) &&
2733 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2734 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2735 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2736 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2741 /* From page 138 of OpenGL ES 3.0 spec:
2742 * "The error INVALID_OPERATION is generated if floating-point RGBA
2743 * data is required; if signed integer RGBA data is required and the
2744 * format of the current color buffer is not signed integer; if
2745 * unsigned integer RGBA data is required and the format of the
2746 * current color buffer is not unsigned integer; or if fixed-point
2747 * RGBA data is required and the format of the current color buffer
2748 * is not fixed-point.
2750 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2751 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2752 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2755 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2756 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2757 _mesa_error(ctx
, GL_INVALID_ENUM
,
2758 "glCopyTexImage%dD(target)", dimensions
);
2761 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2762 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2763 "glCopyTexImage%dD(no compression for format)", dimensions
);
2767 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2768 "glCopyTexImage%dD(border!=0)", dimensions
);
2773 if (!mutable_tex_object(ctx
, target
)) {
2774 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2775 "glCopyTexImage%dD(immutable texture)", dimensions
);
2779 /* if we get here, the parameters are OK */
2785 * Test glCopyTexSubImage[12]D() parameters for errors.
2786 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2789 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2790 const struct gl_texture_object
*texObj
,
2791 GLenum target
, GLint level
,
2792 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2793 GLint width
, GLint height
, bool dsa
)
2795 struct gl_texture_image
*texImage
;
2796 const char *suffix
= dsa
? "ture" : "";
2798 /* Check that the source buffer is complete */
2799 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2800 if (ctx
->ReadBuffer
->_Status
== 0) {
2801 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2803 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2804 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2805 "glCopyTex%sSubImage%dD(invalid readbuffer)",
2806 suffix
, dimensions
);
2810 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2811 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2812 "glCopyTex%sSubImage%dD(multisample FBO)", suffix
,
2818 /* check target (proxies not allowed) */
2819 if (!legal_texsubimage_target(ctx
, dimensions
, target
, dsa
)) {
2820 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTex%sSubImage%uD(target=%s)",
2822 _mesa_lookup_enum_by_nr(target
));
2827 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2828 _mesa_error(ctx
, GL_INVALID_VALUE
,
2829 "glCopyTex%sSubImage%dD(level=%d)", suffix
,
2834 /* Get dest image pointers */
2836 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTex%sSubImage%dD()",
2837 suffix
, dimensions
);
2841 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2843 /* destination image does not exist */
2844 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2845 "glCopyTex%sSubImage%dD(invalid texture image)",
2846 suffix
, dimensions
);
2850 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2851 xoffset
, yoffset
, zoffset
,
2852 width
, height
, 1, dsa
?
2853 "glCompressedTextureSubImage" :
2854 "glCompressedTexSubImage")) {
2858 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2859 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2860 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2861 "glCopyTex%sSubImage%dD(no compression for format)",
2862 suffix
, dimensions
);
2867 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2868 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTex%sSubImage2D", suffix
);
2872 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2873 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2874 "glCopyTex%sSubImage%dD(missing readbuffer, format=0x%x)",
2875 suffix
, dimensions
, texImage
->_BaseFormat
);
2879 /* From the EXT_texture_integer spec:
2881 * "INVALID_OPERATION is generated by CopyTexImage* and
2882 * CopyTexSubImage* if the texture internalformat is an integer format
2883 * and the read color buffer is not an integer format, or if the
2884 * internalformat is not an integer format and the read color buffer
2885 * is an integer format."
2887 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2888 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2890 if (_mesa_is_format_integer_color(rb
->Format
) !=
2891 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2892 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2893 "glCopyTex%sSubImage%dD(integer vs non-integer)",
2894 suffix
, dimensions
);
2899 /* if we get here, the parameters are OK */
2904 /** Callback info for walking over FBO hash table */
2907 struct gl_context
*ctx
;
2908 struct gl_texture_object
*texObj
;
2914 * Check render to texture callback. Called from _mesa_HashWalk().
2917 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2919 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2920 const struct cb_info
*info
= (struct cb_info
*) userData
;
2921 struct gl_context
*ctx
= info
->ctx
;
2922 const struct gl_texture_object
*texObj
= info
->texObj
;
2923 const GLuint level
= info
->level
, face
= info
->face
;
2925 /* If this is a user-created FBO */
2926 if (_mesa_is_user_fbo(fb
)) {
2928 /* check if any of the FBO's attachments point to 'texObj' */
2929 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2930 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2931 if (att
->Type
== GL_TEXTURE
&&
2932 att
->Texture
== texObj
&&
2933 att
->TextureLevel
== level
&&
2934 att
->CubeMapFace
== face
) {
2935 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2936 assert(att
->Renderbuffer
->TexImage
);
2937 /* Mark fb status as indeterminate to force re-validation */
2946 * When a texture image is specified we have to check if it's bound to
2947 * any framebuffer objects (render to texture) in order to detect changes
2948 * in size or format since that effects FBO completeness.
2949 * Any FBOs rendering into the texture must be re-validated.
2952 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2953 struct gl_texture_object
*texObj
,
2954 GLuint face
, GLuint level
)
2956 /* Only check this texture if it's been marked as RenderToTexture */
2957 if (texObj
->_RenderToTexture
) {
2958 struct cb_info info
;
2960 info
.texObj
= texObj
;
2963 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2969 * If the texture object's GenerateMipmap flag is set and we've
2970 * changed the texture base level image, regenerate the rest of the
2971 * mipmap levels now.
2974 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2975 struct gl_texture_object
*texObj
, GLint level
)
2977 if (texObj
->GenerateMipmap
&&
2978 level
== texObj
->BaseLevel
&&
2979 level
< texObj
->MaxLevel
) {
2980 assert(ctx
->Driver
.GenerateMipmap
);
2981 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2986 /** Debug helper: override the user-requested internal format */
2988 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2991 if (internalFormat
== GL_RGBA16F_ARB
||
2992 internalFormat
== GL_RGBA32F_ARB
) {
2993 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2996 else if (internalFormat
== GL_RGB16F_ARB
||
2997 internalFormat
== GL_RGB32F_ARB
) {
2998 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3001 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3002 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3003 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3004 return GL_LUMINANCE_ALPHA
;
3006 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3007 internalFormat
== GL_LUMINANCE32F_ARB
) {
3008 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3009 return GL_LUMINANCE
;
3011 else if (internalFormat
== GL_ALPHA16F_ARB
||
3012 internalFormat
== GL_ALPHA32F_ARB
) {
3013 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3017 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3018 internalFormat = GL_RGBA;
3022 return internalFormat
;
3025 return internalFormat
;
3031 * Choose the actual hardware format for a texture image.
3032 * Try to use the same format as the previous image level when possible.
3033 * Otherwise, ask the driver for the best format.
3034 * It's important to try to choose a consistant format for all levels
3035 * for efficient texture memory layout/allocation. In particular, this
3036 * comes up during automatic mipmap generation.
3039 _mesa_choose_texture_format(struct gl_context
*ctx
,
3040 struct gl_texture_object
*texObj
,
3041 GLenum target
, GLint level
,
3042 GLenum internalFormat
, GLenum format
, GLenum type
)
3046 /* see if we've already chosen a format for the previous level */
3048 struct gl_texture_image
*prevImage
=
3049 _mesa_select_tex_image(texObj
, target
, level
- 1);
3050 /* See if the prev level is defined and has an internal format which
3051 * matches the new internal format.
3054 prevImage
->Width
> 0 &&
3055 prevImage
->InternalFormat
== internalFormat
) {
3056 /* use the same format */
3057 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3058 return prevImage
->TexFormat
;
3062 /* If the application requested compression to an S3TC format but we don't
3063 * have the DXTn library, force a generic compressed format instead.
3065 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3066 const GLenum before
= internalFormat
;
3068 switch (internalFormat
) {
3069 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3070 if (!ctx
->Mesa_DXTn
)
3071 internalFormat
= GL_COMPRESSED_RGB
;
3073 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3074 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3075 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3076 if (!ctx
->Mesa_DXTn
)
3077 internalFormat
= GL_COMPRESSED_RGBA
;
3083 if (before
!= internalFormat
) {
3085 "DXT compression requested (%s), "
3086 "but libtxc_dxtn library not installed. Using %s "
3088 _mesa_lookup_enum_by_nr(before
),
3089 _mesa_lookup_enum_by_nr(internalFormat
));
3093 /* choose format from scratch */
3094 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3096 assert(f
!= MESA_FORMAT_NONE
);
3102 * Adjust pixel unpack params and image dimensions to strip off the
3103 * one-pixel texture border.
3105 * Gallium and intel don't support texture borders. They've seldem been used
3106 * and seldom been implemented correctly anyway.
3108 * \param unpackNew returns the new pixel unpack parameters
3111 strip_texture_border(GLenum target
,
3112 GLint
*width
, GLint
*height
, GLint
*depth
,
3113 const struct gl_pixelstore_attrib
*unpack
,
3114 struct gl_pixelstore_attrib
*unpackNew
)
3120 *unpackNew
= *unpack
;
3122 if (unpackNew
->RowLength
== 0)
3123 unpackNew
->RowLength
= *width
;
3125 if (unpackNew
->ImageHeight
== 0)
3126 unpackNew
->ImageHeight
= *height
;
3128 assert(*width
>= 3);
3129 unpackNew
->SkipPixels
++; /* skip the border */
3130 *width
= *width
- 2; /* reduce the width by two border pixels */
3132 /* The min height of a texture with a border is 3 */
3133 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3134 unpackNew
->SkipRows
++; /* skip the border */
3135 *height
= *height
- 2; /* reduce the height by two border pixels */
3139 target
!= GL_TEXTURE_2D_ARRAY
&&
3140 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3141 unpackNew
->SkipImages
++; /* skip the border */
3142 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3148 * Common code to implement all the glTexImage1D/2D/3D functions
3149 * as well as glCompressedTexImage1D/2D/3D.
3150 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3151 * \param format the user's image format (only used if !compressed)
3152 * \param type the user's image type (only used if !compressed)
3153 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3156 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3157 GLenum target
, GLint level
, GLint internalFormat
,
3158 GLsizei width
, GLsizei height
, GLsizei depth
,
3159 GLint border
, GLenum format
, GLenum type
,
3160 GLsizei imageSize
, const GLvoid
*pixels
)
3162 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3163 struct gl_pixelstore_attrib unpack_no_border
;
3164 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3165 struct gl_texture_object
*texObj
;
3166 mesa_format texFormat
;
3167 GLboolean dimensionsOK
, sizeOK
;
3169 FLUSH_VERTICES(ctx
, 0);
3171 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3174 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3176 _mesa_lookup_enum_by_nr(target
), level
,
3177 _mesa_lookup_enum_by_nr(internalFormat
),
3178 width
, height
, depth
, border
, pixels
);
3181 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3183 _mesa_lookup_enum_by_nr(target
), level
,
3184 _mesa_lookup_enum_by_nr(internalFormat
),
3185 width
, height
, depth
, border
,
3186 _mesa_lookup_enum_by_nr(format
),
3187 _mesa_lookup_enum_by_nr(type
), pixels
);
3190 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3192 /* target error checking */
3193 if (!legal_teximage_target(ctx
, dims
, target
)) {
3194 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3195 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3199 /* general error checking */
3201 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3203 width
, height
, depth
,
3208 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3209 format
, type
, width
, height
, depth
, border
))
3213 /* Here we convert a cpal compressed image into a regular glTexImage2D
3214 * call by decompressing the texture. If we really want to support cpal
3215 * textures in any driver this would have to be changed.
3217 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3218 switch (internalFormat
) {
3219 case GL_PALETTE4_RGB8_OES
:
3220 case GL_PALETTE4_RGBA8_OES
:
3221 case GL_PALETTE4_R5_G6_B5_OES
:
3222 case GL_PALETTE4_RGBA4_OES
:
3223 case GL_PALETTE4_RGB5_A1_OES
:
3224 case GL_PALETTE8_RGB8_OES
:
3225 case GL_PALETTE8_RGBA8_OES
:
3226 case GL_PALETTE8_R5_G6_B5_OES
:
3227 case GL_PALETTE8_RGBA4_OES
:
3228 case GL_PALETTE8_RGB5_A1_OES
:
3229 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3230 width
, height
, imageSize
, pixels
);
3235 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3239 /* For glCompressedTexImage() the driver has no choice about the
3240 * texture format since we'll never transcode the user's compressed
3241 * image data. The internalFormat was error checked earlier.
3243 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3246 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3247 * internal floating point format for the given base format.
3249 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3250 if (type
== GL_FLOAT
) {
3251 texObj
->_IsFloat
= GL_TRUE
;
3252 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3253 texObj
->_IsHalfFloat
= GL_TRUE
;
3256 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3259 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3260 internalFormat
, format
, type
);
3263 assert(texFormat
!= MESA_FORMAT_NONE
);
3265 /* check that width, height, depth are legal for the mipmap level */
3266 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3267 height
, depth
, border
);
3269 /* check that the texture won't take too much memory, etc */
3270 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3272 width
, height
, depth
, border
);
3274 if (_mesa_is_proxy_texture(target
)) {
3275 /* Proxy texture: just clear or set state depending on error checking */
3276 struct gl_texture_image
*texImage
=
3277 get_proxy_tex_image(ctx
, target
, level
);
3280 return; /* GL_OUT_OF_MEMORY already recorded */
3282 if (dimensionsOK
&& sizeOK
) {
3283 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3284 border
, internalFormat
, texFormat
);
3287 clear_teximage_fields(texImage
);
3291 /* non-proxy target */
3292 const GLuint face
= _mesa_tex_target_to_face(target
);
3293 struct gl_texture_image
*texImage
;
3295 if (!dimensionsOK
) {
3296 _mesa_error(ctx
, GL_INVALID_VALUE
,
3297 "glTexImage%uD(invalid width or height or depth)",
3303 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3304 "glTexImage%uD(image too large)", dims
);
3308 /* Allow a hardware driver to just strip out the border, to provide
3309 * reliable but slightly incorrect hardware rendering instead of
3310 * rarely-tested software fallback rendering.
3312 if (border
&& ctx
->Const
.StripTextureBorder
) {
3313 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3316 unpack
= &unpack_no_border
;
3319 if (ctx
->NewState
& _NEW_PIXEL
)
3320 _mesa_update_state(ctx
);
3322 _mesa_lock_texture(ctx
, texObj
);
3324 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3327 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3330 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3332 _mesa_init_teximage_fields(ctx
, texImage
,
3333 width
, height
, depth
,
3334 border
, internalFormat
, texFormat
);
3336 /* Give the texture to the driver. <pixels> may be null. */
3337 if (width
> 0 && height
> 0 && depth
> 0) {
3339 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3343 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3344 type
, pixels
, unpack
);
3348 check_gen_mipmap(ctx
, target
, texObj
, level
);
3350 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3352 _mesa_dirty_texobj(ctx
, texObj
);
3355 _mesa_unlock_texture(ctx
, texObj
);
3362 * Called from the API. Note that width includes the border.
3365 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3366 GLsizei width
, GLint border
, GLenum format
,
3367 GLenum type
, const GLvoid
*pixels
)
3369 GET_CURRENT_CONTEXT(ctx
);
3370 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3371 border
, format
, type
, 0, pixels
);
3376 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3377 GLsizei width
, GLsizei height
, GLint border
,
3378 GLenum format
, GLenum type
,
3379 const GLvoid
*pixels
)
3381 GET_CURRENT_CONTEXT(ctx
);
3382 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3383 border
, format
, type
, 0, pixels
);
3388 * Called by the API or display list executor.
3389 * Note that width and height include the border.
3392 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3393 GLsizei width
, GLsizei height
, GLsizei depth
,
3394 GLint border
, GLenum format
, GLenum type
,
3395 const GLvoid
*pixels
)
3397 GET_CURRENT_CONTEXT(ctx
);
3398 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3399 width
, height
, depth
,
3400 border
, format
, type
, 0, pixels
);
3405 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3406 GLsizei width
, GLsizei height
, GLsizei depth
,
3407 GLint border
, GLenum format
, GLenum type
,
3408 const GLvoid
*pixels
)
3410 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3411 depth
, border
, format
, type
, pixels
);
3416 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3418 struct gl_texture_object
*texObj
;
3419 struct gl_texture_image
*texImage
;
3421 GET_CURRENT_CONTEXT(ctx
);
3422 FLUSH_VERTICES(ctx
, 0);
3426 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3428 case GL_TEXTURE_EXTERNAL_OES
:
3430 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3433 valid_target
= false;
3437 if (!valid_target
) {
3438 _mesa_error(ctx
, GL_INVALID_ENUM
,
3439 "glEGLImageTargetTexture2D(target=%d)", target
);
3444 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3445 "glEGLImageTargetTexture2D(image=%p)", image
);
3449 if (ctx
->NewState
& _NEW_PIXEL
)
3450 _mesa_update_state(ctx
);
3452 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3456 _mesa_lock_texture(ctx
, texObj
);
3458 if (texObj
->Immutable
) {
3459 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3460 "glEGLImageTargetTexture2D(texture is immutable)");
3461 _mesa_unlock_texture(ctx
, texObj
);
3465 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3467 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3469 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3471 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3472 texObj
, texImage
, image
);
3474 _mesa_dirty_texobj(ctx
, texObj
);
3476 _mesa_unlock_texture(ctx
, texObj
);
3482 * Helper that implements the glTexSubImage1/2/3D()
3483 * and glTextureSubImage1/2/3D() functions.
3486 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3487 struct gl_texture_object
*texObj
,
3488 struct gl_texture_image
*texImage
,
3489 GLenum target
, GLint level
,
3490 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3491 GLsizei width
, GLsizei height
, GLsizei depth
,
3492 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3495 FLUSH_VERTICES(ctx
, 0);
3497 /* check target (proxies not allowed) */
3498 if (!legal_texsubimage_target(ctx
, dims
, target
, dsa
)) {
3499 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sSubImage%uD(target=%s)",
3501 dims
, _mesa_lookup_enum_by_nr(target
));
3505 if (ctx
->NewState
& _NEW_PIXEL
)
3506 _mesa_update_state(ctx
);
3508 _mesa_lock_texture(ctx
, texObj
);
3510 if (width
> 0 && height
> 0 && depth
> 0) {
3511 /* If we have a border, offset=-1 is legal. Bias by border width. */
3514 if (target
!= GL_TEXTURE_2D_ARRAY
)
3515 zoffset
+= texImage
->Border
;
3518 if (target
!= GL_TEXTURE_1D_ARRAY
)
3519 yoffset
+= texImage
->Border
;
3522 xoffset
+= texImage
->Border
;
3525 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3526 xoffset
, yoffset
, zoffset
,
3527 width
, height
, depth
,
3528 format
, type
, pixels
, &ctx
->Unpack
);
3530 check_gen_mipmap(ctx
, target
, texObj
, level
);
3532 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3533 * the texel data, not the texture format, size, etc.
3537 _mesa_unlock_texture(ctx
, texObj
);
3541 * Implement all the glTexSubImage1/2/3D() functions.
3542 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3545 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3546 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3547 GLsizei width
, GLsizei height
, GLsizei depth
,
3548 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3550 struct gl_texture_object
*texObj
;
3551 struct gl_texture_image
*texImage
;
3553 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3557 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3558 xoffset
, yoffset
, zoffset
,
3559 width
, height
, depth
, format
, type
, false)) {
3560 return; /* error was detected */
3563 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3564 /* texsubimage_error_check ensures that texImage is not NULL */
3566 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3567 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3569 _mesa_lookup_enum_by_nr(target
), level
,
3570 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3571 _mesa_lookup_enum_by_nr(format
),
3572 _mesa_lookup_enum_by_nr(type
), pixels
);
3574 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3575 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3576 format
, type
, pixels
, false);
3581 * Implement all the glTextureSubImage1/2/3D() functions.
3582 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3585 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3586 GLuint texture
, GLint level
,
3587 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3588 GLsizei width
, GLsizei height
, GLsizei depth
,
3589 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3591 struct gl_texture_object
*texObj
;
3592 struct gl_texture_image
*texImage
;
3595 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3597 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3598 dims
, texture
, level
,
3599 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3600 _mesa_lookup_enum_by_nr(format
),
3601 _mesa_lookup_enum_by_nr(type
), pixels
);
3603 /* Get the texture object by Name. */
3604 texObj
= _mesa_lookup_texture(ctx
, texture
);
3606 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3611 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3612 xoffset
, yoffset
, zoffset
,
3613 width
, height
, depth
, format
, type
, true)) {
3614 return; /* error was detected */
3618 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3619 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3622 /* Error checking */
3623 if (texObj
->NumLayers
< 6) {
3624 /* Not enough image planes for a cube map. The spec does not say
3625 * what should happen in this case because the user has always
3626 * specified each cube face separately (using
3627 * GL_TEXTURE_CUBE_MAP_POSITIVE_X+i) in previous GL versions.
3628 * This is addressed in Khronos Bug 13223.
3630 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3631 "glTextureSubImage%uD(insufficient cube map storage)",
3637 * What do we do if the user created a texture with the following code
3638 * and then called this function with its handle?
3641 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3642 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3643 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3644 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3645 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3646 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3647 * // wrong format, or given the wrong size, etc.
3648 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3649 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3651 * A bug has been filed against the spec for this case. In the
3652 * meantime, we will check for cube completeness.
3654 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3655 * Core Profile spec (30.10.2014):
3656 * "[A] cube map texture is cube complete if the
3657 * following conditions all hold true: The [base level] texture
3658 * images of each of the six cube map faces have identical, positive,
3659 * and square dimensions. The [base level] images were each specified
3660 * with the same internal format."
3662 * It seems reasonable to check for cube completeness of an arbitrary
3663 * level here so that the image data has a consistent format and size.
3665 if (!_mesa_cube_level_complete(texObj
, level
)) {
3666 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3667 "glTextureSubImage%uD(cube map incomplete)",
3672 rowStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3674 /* Copy in each face. */
3675 for (i
= 0; i
< 6; ++i
) {
3676 texImage
= texObj
->Image
[i
][level
];
3677 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3678 level
, xoffset
, yoffset
, zoffset
,
3679 width
, height
, 1, format
,
3680 type
, pixels
, true);
3681 pixels
= (GLubyte
*) pixels
+ rowStride
;
3685 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3689 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3690 level
, xoffset
, yoffset
, zoffset
,
3691 width
, height
, depth
, format
,
3692 type
, pixels
, true);
3698 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3699 GLint xoffset
, GLsizei width
,
3700 GLenum format
, GLenum type
,
3701 const GLvoid
*pixels
)
3703 GET_CURRENT_CONTEXT(ctx
);
3704 texsubimage(ctx
, 1, target
, level
,
3707 format
, type
, pixels
);
3712 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3713 GLint xoffset
, GLint yoffset
,
3714 GLsizei width
, GLsizei height
,
3715 GLenum format
, GLenum type
,
3716 const GLvoid
*pixels
)
3718 GET_CURRENT_CONTEXT(ctx
);
3719 texsubimage(ctx
, 2, target
, level
,
3720 xoffset
, yoffset
, 0,
3722 format
, type
, pixels
);
3728 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3729 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3730 GLsizei width
, GLsizei height
, GLsizei depth
,
3731 GLenum format
, GLenum type
,
3732 const GLvoid
*pixels
)
3734 GET_CURRENT_CONTEXT(ctx
);
3735 texsubimage(ctx
, 3, target
, level
,
3736 xoffset
, yoffset
, zoffset
,
3737 width
, height
, depth
,
3738 format
, type
, pixels
);
3742 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3743 GLint xoffset
, GLsizei width
,
3744 GLenum format
, GLenum type
,
3745 const GLvoid
*pixels
)
3747 GET_CURRENT_CONTEXT(ctx
);
3748 texturesubimage(ctx
, 1, texture
, level
,
3751 format
, type
, pixels
);
3756 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3757 GLint xoffset
, GLint yoffset
,
3758 GLsizei width
, GLsizei height
,
3759 GLenum format
, GLenum type
,
3760 const GLvoid
*pixels
)
3762 GET_CURRENT_CONTEXT(ctx
);
3763 texturesubimage(ctx
, 2, texture
, level
,
3764 xoffset
, yoffset
, 0,
3766 format
, type
, pixels
);
3771 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3772 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3773 GLsizei width
, GLsizei height
, GLsizei depth
,
3774 GLenum format
, GLenum type
,
3775 const GLvoid
*pixels
)
3777 GET_CURRENT_CONTEXT(ctx
);
3778 texturesubimage(ctx
, 3, texture
, level
,
3779 xoffset
, yoffset
, zoffset
,
3780 width
, height
, depth
,
3781 format
, type
, pixels
);
3786 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3787 * from. This depends on whether the texture contains color or depth values.
3789 static struct gl_renderbuffer
*
3790 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3792 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3793 /* reading from depth/stencil buffer */
3794 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3797 /* copying from color buffer */
3798 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3803 copytexsubimage_by_slice(struct gl_context
*ctx
,
3804 struct gl_texture_image
*texImage
,
3806 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3807 struct gl_renderbuffer
*rb
,
3809 GLsizei width
, GLsizei height
)
3811 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3814 /* For 1D arrays, we copy each scanline of the source rectangle into the
3817 assert(zoffset
== 0);
3819 for (slice
= 0; slice
< height
; slice
++) {
3820 assert(yoffset
+ slice
< texImage
->Height
);
3821 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3822 xoffset
, 0, yoffset
+ slice
,
3823 rb
, x
, y
+ slice
, width
, 1);
3826 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3827 xoffset
, yoffset
, zoffset
,
3828 rb
, x
, y
, width
, height
);
3833 formats_differ_in_component_sizes (mesa_format f1
,
3836 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3837 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3838 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3839 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3841 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3842 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3843 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3844 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3846 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3847 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3848 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3849 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3856 * Implement the glCopyTexImage1/2D() functions.
3859 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3860 GLenum target
, GLint level
, GLenum internalFormat
,
3861 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3863 struct gl_texture_object
*texObj
;
3864 struct gl_texture_image
*texImage
;
3865 const GLuint face
= _mesa_tex_target_to_face(target
);
3866 mesa_format texFormat
;
3867 struct gl_renderbuffer
*rb
;
3869 FLUSH_VERTICES(ctx
, 0);
3871 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3872 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3874 _mesa_lookup_enum_by_nr(target
), level
,
3875 _mesa_lookup_enum_by_nr(internalFormat
),
3876 x
, y
, width
, height
, border
);
3878 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3879 _mesa_update_state(ctx
);
3881 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3882 width
, height
, border
))
3885 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3887 _mesa_error(ctx
, GL_INVALID_VALUE
,
3888 "glCopyTexImage%uD(invalid width or height)", dims
);
3892 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3895 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3896 internalFormat
, GL_NONE
, GL_NONE
);
3898 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3900 if (_mesa_is_gles3(ctx
)) {
3901 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3902 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3903 * OpenGL ES 3.0. Khronos bug# 9807.
3905 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3906 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3907 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer and"
3908 " writing to unsized internal format)", dims
);
3912 /* From Page 139 of OpenGL ES 3.0 spec:
3913 * "If internalformat is sized, the internal format of the new texel
3914 * array is internalformat, and this is also the new texel array’s
3915 * effective internal format. If the component sizes of internalformat
3916 * do not exactly match the corresponding component sizes of the source
3917 * buffer’s effective internal format, described below, an
3918 * INVALID_OPERATION error is generated. If internalformat is unsized,
3919 * the internal format of the new texel array is the effective internal
3920 * format of the source buffer, and this is also the new texel array’s
3921 * effective internal format.
3923 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3924 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3925 "glCopyTexImage%uD(componenet size changed in"
3926 " internal format)", dims
);
3931 assert(texFormat
!= MESA_FORMAT_NONE
);
3933 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3935 width
, height
, 1, border
)) {
3936 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3937 "glCopyTexImage%uD(image too large)", dims
);
3941 if (border
&& ctx
->Const
.StripTextureBorder
) {
3943 width
-= border
* 2;
3946 height
-= border
* 2;
3951 _mesa_lock_texture(ctx
, texObj
);
3953 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3956 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3959 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3961 /* Free old texture image */
3962 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3964 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3965 border
, internalFormat
, texFormat
);
3967 if (width
&& height
) {
3968 /* Allocate texture memory (no pixel data yet) */
3969 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3971 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3973 struct gl_renderbuffer
*srcRb
=
3974 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3976 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3978 srcRb
, srcX
, srcY
, width
, height
);
3981 check_gen_mipmap(ctx
, target
, texObj
, level
);
3984 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3986 _mesa_dirty_texobj(ctx
, texObj
);
3989 _mesa_unlock_texture(ctx
, texObj
);
3995 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3996 GLenum internalFormat
,
3998 GLsizei width
, GLint border
)
4000 GET_CURRENT_CONTEXT(ctx
);
4001 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4007 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4008 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4011 GET_CURRENT_CONTEXT(ctx
);
4012 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4013 x
, y
, width
, height
, border
);
4017 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4020 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4021 struct gl_texture_object
*texObj
,
4022 GLenum target
, GLint level
,
4023 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4025 GLsizei width
, GLsizei height
,
4028 struct gl_texture_image
*texImage
;
4030 FLUSH_VERTICES(ctx
, 0);
4032 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4033 _mesa_debug(ctx
, "glCopyTex%sSubImage%uD %s %d %d %d %d %d %d %d %d\n",
4034 dsa
? "ture" : "", dims
,
4035 _mesa_lookup_enum_by_nr(target
),
4036 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4038 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4039 _mesa_update_state(ctx
);
4041 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4042 xoffset
, yoffset
, zoffset
,
4043 width
, height
, dsa
)) {
4047 _mesa_lock_texture(ctx
, texObj
);
4049 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4051 /* If we have a border, offset=-1 is legal. Bias by border width. */
4054 if (target
!= GL_TEXTURE_2D_ARRAY
)
4055 zoffset
+= texImage
->Border
;
4058 if (target
!= GL_TEXTURE_1D_ARRAY
)
4059 yoffset
+= texImage
->Border
;
4062 xoffset
+= texImage
->Border
;
4065 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4067 struct gl_renderbuffer
*srcRb
=
4068 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4070 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4071 xoffset
, yoffset
, zoffset
,
4072 srcRb
, x
, y
, width
, height
);
4074 check_gen_mipmap(ctx
, target
, texObj
, level
);
4076 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4077 * the texel data, not the texture format, size, etc.
4081 _mesa_unlock_texture(ctx
, texObj
);
4085 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4086 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4088 struct gl_texture_object
* texObj
;
4089 GET_CURRENT_CONTEXT(ctx
);
4091 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4095 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4096 x
, y
, width
, 1, false);
4102 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4103 GLint xoffset
, GLint yoffset
,
4104 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4106 struct gl_texture_object
* texObj
;
4107 GET_CURRENT_CONTEXT(ctx
);
4109 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4113 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4114 xoffset
, yoffset
, 0,
4115 x
, y
, width
, height
, false);
4121 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4122 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4123 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4125 struct gl_texture_object
* texObj
;
4126 GET_CURRENT_CONTEXT(ctx
);
4128 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4132 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4133 xoffset
, yoffset
, zoffset
,
4134 x
, y
, width
, height
, false);
4138 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4139 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4141 struct gl_texture_object
* texObj
;
4142 GET_CURRENT_CONTEXT(ctx
);
4144 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage1D");
4148 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4149 xoffset
, 0, 0, x
, y
, width
, 1, true);
4153 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4154 GLint xoffset
, GLint yoffset
,
4155 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4157 struct gl_texture_object
* texObj
;
4158 GET_CURRENT_CONTEXT(ctx
);
4160 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage2D");
4164 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4165 xoffset
, yoffset
, 0,
4166 x
, y
, width
, height
, true);
4172 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4173 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4174 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4176 struct gl_texture_object
* texObj
;
4177 GET_CURRENT_CONTEXT(ctx
);
4179 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage3D");
4183 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4184 xoffset
, yoffset
, zoffset
,
4185 x
, y
, width
, height
, true);
4189 check_clear_tex_image(struct gl_context
*ctx
,
4190 const char *function
,
4191 struct gl_texture_image
*texImage
,
4192 GLenum format
, GLenum type
,
4194 GLubyte
*clearValue
)
4196 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4197 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4198 GLenum internalFormat
= texImage
->InternalFormat
;
4201 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4202 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4203 "%s(buffer texture)", function
);
4207 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4208 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4209 "%s(compressed texture)", function
);
4213 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4214 if (err
!= GL_NO_ERROR
) {
4215 _mesa_error(ctx
, err
,
4216 "%s(incompatible format = %s, type = %s)",
4218 _mesa_lookup_enum_by_nr(format
),
4219 _mesa_lookup_enum_by_nr(type
));
4223 /* make sure internal format and format basically agree */
4224 if (!texture_formats_agree(internalFormat
, format
)) {
4225 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4226 "%s(incompatible internalFormat = %s, format = %s)",
4228 _mesa_lookup_enum_by_nr(internalFormat
),
4229 _mesa_lookup_enum_by_nr(format
));
4233 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4234 /* both source and dest must be integer-valued, or neither */
4235 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4236 _mesa_is_enum_format_integer(format
)) {
4237 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4238 "%s(integer/non-integer format mismatch)",
4244 if (!_mesa_texstore(ctx
,
4246 texImage
->_BaseFormat
,
4247 texImage
->TexFormat
,
4248 0, /* dstRowStride */
4250 1, 1, 1, /* srcWidth/Height/Depth */
4252 data
? data
: zeroData
,
4253 &ctx
->DefaultPacking
)) {
4254 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4261 static struct gl_texture_object
*
4262 get_tex_obj_for_clear(struct gl_context
*ctx
,
4263 const char *function
,
4266 struct gl_texture_object
*texObj
;
4269 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4273 texObj
= _mesa_lookup_texture(ctx
, texture
);
4275 if (texObj
== NULL
) {
4276 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4280 if (texObj
->Target
== 0) {
4281 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4289 get_tex_images_for_clear(struct gl_context
*ctx
,
4290 const char *function
,
4291 struct gl_texture_object
*texObj
,
4293 struct gl_texture_image
**texImages
)
4298 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4299 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4303 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4304 for (i
= 0; i
< MAX_FACES
; i
++) {
4305 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4307 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4308 if (texImages
[i
] == NULL
) {
4309 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4310 "%s(invalid level)", function
);
4318 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4320 if (texImages
[0] == NULL
) {
4321 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4329 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4330 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4331 GLsizei width
, GLsizei height
, GLsizei depth
,
4332 GLenum format
, GLenum type
, const void *data
)
4334 GET_CURRENT_CONTEXT(ctx
);
4335 struct gl_texture_object
*texObj
;
4336 struct gl_texture_image
*texImages
[MAX_FACES
];
4337 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4339 int minDepth
, maxDepth
;
4341 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4346 _mesa_lock_texture(ctx
, texObj
);
4348 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4349 texObj
, level
, texImages
);
4353 if (numImages
== 1) {
4354 minDepth
= -(int) texImages
[0]->Border
;
4355 maxDepth
= texImages
[0]->Depth
;
4358 maxDepth
= numImages
;
4361 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4362 yoffset
< -(GLint
) texImages
[0]->Border
||
4363 zoffset
< minDepth
||
4367 xoffset
+ width
> texImages
[0]->Width
||
4368 yoffset
+ height
> texImages
[0]->Height
||
4369 zoffset
+ depth
> maxDepth
) {
4370 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4371 "glClearSubTexImage(invalid dimensions)");
4375 if (numImages
== 1) {
4376 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4378 format
, type
, data
, clearValue
[0])) {
4379 ctx
->Driver
.ClearTexSubImage(ctx
,
4381 xoffset
, yoffset
, zoffset
,
4382 width
, height
, depth
,
4383 data
? clearValue
[0] : NULL
);
4386 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4387 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4389 format
, type
, data
, clearValue
[i
]))
4392 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4393 ctx
->Driver
.ClearTexSubImage(ctx
,
4395 xoffset
, yoffset
, 0,
4397 data
? clearValue
[i
] : NULL
);
4402 _mesa_unlock_texture(ctx
, texObj
);
4406 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4407 GLenum format
, GLenum type
, const void *data
)
4409 GET_CURRENT_CONTEXT(ctx
);
4410 struct gl_texture_object
*texObj
;
4411 struct gl_texture_image
*texImages
[MAX_FACES
];
4412 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4415 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4420 _mesa_lock_texture(ctx
, texObj
);
4422 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4423 texObj
, level
, texImages
);
4425 for (i
= 0; i
< numImages
; i
++) {
4426 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4433 for (i
= 0; i
< numImages
; i
++) {
4434 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4435 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4436 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4437 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4438 texImages
[i
]->Width
,
4439 texImages
[i
]->Height
,
4440 texImages
[i
]->Depth
,
4441 data
? clearValue
[i
] : NULL
);
4445 _mesa_unlock_texture(ctx
, texObj
);
4451 /**********************************************************************/
4452 /****** Compressed Textures ******/
4453 /**********************************************************************/
4457 * Error checking for glCompressedTexSubImage[123]D().
4458 * \return GL_TRUE if error, GL_FALSE if no error
4461 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4462 const struct gl_texture_object
*texObj
,
4463 GLenum target
, GLint level
,
4464 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4465 GLsizei width
, GLsizei height
, GLsizei depth
,
4466 GLenum format
, GLsizei imageSize
, bool dsa
)
4468 struct gl_texture_image
*texImage
;
4471 const char *suffix
= dsa
? "ture" : "";
4473 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4474 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4475 "glCompressedSubTexture%dD(target)", dims
);
4483 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4484 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4485 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4486 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4487 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4488 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4492 targetOK
= GL_FALSE
;
4497 targetOK
= (target
== GL_TEXTURE_3D
) ||
4498 (target
== GL_TEXTURE_2D_ARRAY
) ||
4499 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
4500 (target
== GL_TEXTURE_CUBE_MAP
&& dsa
);
4502 /* OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4504 * "An INVALID_OPERATION error is generated by
4505 * CompressedTex*SubImage3D if the internal format of the texture is
4506 * one of the EAC, ETC2, or RGTC formats and either border is
4507 * non-zero, or the effective target for the texture is not
4508 * TEXTURE_2D_ARRAY."
4510 if (target
!= GL_TEXTURE_2D_ARRAY
) {
4513 /* These came from _mesa_is_compressed_format in glformats.c. */
4515 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
4516 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
4517 case GL_COMPRESSED_R11_EAC
:
4518 case GL_COMPRESSED_RG11_EAC
:
4519 case GL_COMPRESSED_SIGNED_R11_EAC
:
4520 case GL_COMPRESSED_SIGNED_RG11_EAC
:
4522 case GL_COMPRESSED_RGB8_ETC2
:
4523 case GL_COMPRESSED_SRGB8_ETC2
:
4524 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
4525 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
4527 case GL_COMPRESSED_RED_RGTC1
:
4528 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
4529 case GL_COMPRESSED_RG_RGTC2
:
4530 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
4531 invalidformat
= true;
4534 invalidformat
= false;
4536 if (invalidformat
) {
4537 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4538 "glCompressedTex%sSubImage%uD(target)", suffix
, dims
);
4546 /* no 1D compressed textures at this time */
4547 targetOK
= GL_FALSE
;
4552 _mesa_error(ctx
, GL_INVALID_ENUM
,
4553 "glCompressedTex%sSubImage%uD(target)", suffix
, dims
);
4557 /* this will catch any invalid compressed format token */
4558 if (!_mesa_is_compressed_format(ctx
, format
)) {
4559 _mesa_error(ctx
, GL_INVALID_ENUM
,
4560 "glCompressedTex%sSubImage%uD(format)", suffix
, dims
);
4564 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4565 _mesa_error(ctx
, GL_INVALID_VALUE
,
4566 "glCompressedTex%sSubImage%uD(level=%d)",
4567 suffix
, dims
, level
);
4571 /* Check for invalid pixel storage modes */
4572 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4574 dsa
? "glCompressedTextureSubImage" :
4575 "glCompressedTexSubImage")) {
4579 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4580 if (expectedSize
!= imageSize
) {
4581 _mesa_error(ctx
, GL_INVALID_VALUE
,
4582 "glCompressedTex%sSubImage%uD(size=%d)",
4583 suffix
, dims
, imageSize
);
4587 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4589 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4590 "glCompressedTex%sSubImage%uD(invalid texture image)",
4595 if ((GLint
) format
!= texImage
->InternalFormat
) {
4596 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4597 "glCompressedTex%sSubImage%uD(format=0x%x)",
4598 suffix
, dims
, format
);
4602 if (compressedteximage_only_format(ctx
, format
)) {
4603 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4604 "glCompressedTex%sSubImage%uD(format=0x%x cannot be updated)",
4605 suffix
, dims
, format
);
4609 if (error_check_subtexture_dimensions(ctx
, dims
,
4610 texImage
, xoffset
, yoffset
, zoffset
,
4611 width
, height
, depth
,
4612 "glCompressedTexSubImage")) {
4621 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4622 GLenum internalFormat
, GLsizei width
,
4623 GLint border
, GLsizei imageSize
,
4626 GET_CURRENT_CONTEXT(ctx
);
4627 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4628 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4633 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4634 GLenum internalFormat
, GLsizei width
,
4635 GLsizei height
, GLint border
, GLsizei imageSize
,
4638 GET_CURRENT_CONTEXT(ctx
);
4639 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4640 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4645 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4646 GLenum internalFormat
, GLsizei width
,
4647 GLsizei height
, GLsizei depth
, GLint border
,
4648 GLsizei imageSize
, const GLvoid
*data
)
4650 GET_CURRENT_CONTEXT(ctx
);
4651 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4652 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4657 * Common helper for glCompressedTexSubImage1/2/3D() and
4658 * glCompressedTextureSubImage1/2/3D().
4661 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4662 struct gl_texture_object
*texObj
,
4663 GLenum target
, GLint level
,
4664 GLint xoffset
, GLint yoffset
,
4666 GLsizei width
, GLsizei height
,
4668 GLenum format
, GLsizei imageSize
,
4669 const GLvoid
*data
, bool dsa
)
4671 struct gl_texture_image
*texImage
;
4673 if (compressed_subtexture_error_check(ctx
, dims
, texObj
, target
,
4674 level
, xoffset
, yoffset
, zoffset
,
4675 width
, height
, depth
,
4676 format
, imageSize
, dsa
)) {
4680 FLUSH_VERTICES(ctx
, 0);
4682 _mesa_lock_texture(ctx
, texObj
);
4684 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4687 if (width
> 0 && height
> 0 && depth
> 0) {
4688 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4689 xoffset
, yoffset
, zoffset
,
4690 width
, height
, depth
,
4691 format
, imageSize
, data
);
4693 check_gen_mipmap(ctx
, target
, texObj
, level
);
4695 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4696 * the texel data, not the texture format, size, etc.
4700 _mesa_unlock_texture(ctx
, texObj
);
4705 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4706 GLsizei width
, GLenum format
,
4707 GLsizei imageSize
, const GLvoid
*data
)
4709 struct gl_texture_object
*texObj
;
4710 GET_CURRENT_CONTEXT(ctx
);
4712 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4716 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, target
, level
,
4717 xoffset
, 0, 0, width
, 1, 1,
4718 format
, imageSize
, data
, false);
4722 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4723 GLsizei width
, GLenum format
,
4724 GLsizei imageSize
, const GLvoid
*data
)
4726 struct gl_texture_object
*texObj
;
4727 GET_CURRENT_CONTEXT(ctx
);
4729 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4730 "glCompressedTextureSubImage1D");
4734 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4735 xoffset
, 0, 0, width
, 1, 1,
4736 format
, imageSize
, data
, true);
4741 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4742 GLint yoffset
, GLsizei width
, GLsizei height
,
4743 GLenum format
, GLsizei imageSize
,
4746 struct gl_texture_object
*texObj
;
4747 GET_CURRENT_CONTEXT(ctx
);
4749 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4753 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4754 xoffset
, yoffset
, 0, width
, height
, 1,
4755 format
, imageSize
, data
, false);
4759 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
4761 GLsizei width
, GLsizei height
,
4762 GLenum format
, GLsizei imageSize
,
4765 struct gl_texture_object
*texObj
;
4766 GET_CURRENT_CONTEXT(ctx
);
4768 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4769 "glCompressedTextureSubImage2D");
4773 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4774 xoffset
, yoffset
, 0, width
, height
, 1,
4775 format
, imageSize
, data
, true);
4779 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4780 GLint yoffset
, GLint zoffset
, GLsizei width
,
4781 GLsizei height
, GLsizei depth
, GLenum format
,
4782 GLsizei imageSize
, const GLvoid
*data
)
4784 struct gl_texture_object
*texObj
;
4785 GET_CURRENT_CONTEXT(ctx
);
4787 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4791 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4792 xoffset
, yoffset
, zoffset
,
4793 width
, height
, depth
,
4794 format
, imageSize
, data
, false);
4798 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
4799 GLint yoffset
, GLint zoffset
, GLsizei width
,
4800 GLsizei height
, GLsizei depth
,
4801 GLenum format
, GLsizei imageSize
,
4804 struct gl_texture_object
*texObj
;
4805 GET_CURRENT_CONTEXT(ctx
);
4807 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4808 "glCompressedTextureSubImage3D");
4812 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4813 xoffset
, yoffset
, zoffset
,
4814 width
, height
, depth
,
4815 format
, imageSize
, data
, true);
4819 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4821 if (ctx
->API
!= API_OPENGL_CORE
) {
4822 switch (internalFormat
) {
4824 return MESA_FORMAT_A_UNORM8
;
4826 return MESA_FORMAT_A_UNORM16
;
4827 case GL_ALPHA16F_ARB
:
4828 return MESA_FORMAT_A_FLOAT16
;
4829 case GL_ALPHA32F_ARB
:
4830 return MESA_FORMAT_A_FLOAT32
;
4831 case GL_ALPHA8I_EXT
:
4832 return MESA_FORMAT_A_SINT8
;
4833 case GL_ALPHA16I_EXT
:
4834 return MESA_FORMAT_A_SINT16
;
4835 case GL_ALPHA32I_EXT
:
4836 return MESA_FORMAT_A_SINT32
;
4837 case GL_ALPHA8UI_EXT
:
4838 return MESA_FORMAT_A_UINT8
;
4839 case GL_ALPHA16UI_EXT
:
4840 return MESA_FORMAT_A_UINT16
;
4841 case GL_ALPHA32UI_EXT
:
4842 return MESA_FORMAT_A_UINT32
;
4844 return MESA_FORMAT_L_UNORM8
;
4845 case GL_LUMINANCE16
:
4846 return MESA_FORMAT_L_UNORM16
;
4847 case GL_LUMINANCE16F_ARB
:
4848 return MESA_FORMAT_L_FLOAT16
;
4849 case GL_LUMINANCE32F_ARB
:
4850 return MESA_FORMAT_L_FLOAT32
;
4851 case GL_LUMINANCE8I_EXT
:
4852 return MESA_FORMAT_L_SINT8
;
4853 case GL_LUMINANCE16I_EXT
:
4854 return MESA_FORMAT_L_SINT16
;
4855 case GL_LUMINANCE32I_EXT
:
4856 return MESA_FORMAT_L_SINT32
;
4857 case GL_LUMINANCE8UI_EXT
:
4858 return MESA_FORMAT_L_UINT8
;
4859 case GL_LUMINANCE16UI_EXT
:
4860 return MESA_FORMAT_L_UINT16
;
4861 case GL_LUMINANCE32UI_EXT
:
4862 return MESA_FORMAT_L_UINT32
;
4863 case GL_LUMINANCE8_ALPHA8
:
4864 return MESA_FORMAT_L8A8_UNORM
;
4865 case GL_LUMINANCE16_ALPHA16
:
4866 return MESA_FORMAT_L16A16_UNORM
;
4867 case GL_LUMINANCE_ALPHA16F_ARB
:
4868 return MESA_FORMAT_LA_FLOAT16
;
4869 case GL_LUMINANCE_ALPHA32F_ARB
:
4870 return MESA_FORMAT_LA_FLOAT32
;
4871 case GL_LUMINANCE_ALPHA8I_EXT
:
4872 return MESA_FORMAT_LA_SINT8
;
4873 case GL_LUMINANCE_ALPHA16I_EXT
:
4874 return MESA_FORMAT_LA_SINT16
;
4875 case GL_LUMINANCE_ALPHA32I_EXT
:
4876 return MESA_FORMAT_LA_SINT32
;
4877 case GL_LUMINANCE_ALPHA8UI_EXT
:
4878 return MESA_FORMAT_LA_UINT8
;
4879 case GL_LUMINANCE_ALPHA16UI_EXT
:
4880 return MESA_FORMAT_LA_UINT16
;
4881 case GL_LUMINANCE_ALPHA32UI_EXT
:
4882 return MESA_FORMAT_LA_UINT32
;
4884 return MESA_FORMAT_I_UNORM8
;
4885 case GL_INTENSITY16
:
4886 return MESA_FORMAT_I_UNORM16
;
4887 case GL_INTENSITY16F_ARB
:
4888 return MESA_FORMAT_I_FLOAT16
;
4889 case GL_INTENSITY32F_ARB
:
4890 return MESA_FORMAT_I_FLOAT32
;
4891 case GL_INTENSITY8I_EXT
:
4892 return MESA_FORMAT_I_SINT8
;
4893 case GL_INTENSITY16I_EXT
:
4894 return MESA_FORMAT_I_SINT16
;
4895 case GL_INTENSITY32I_EXT
:
4896 return MESA_FORMAT_I_SINT32
;
4897 case GL_INTENSITY8UI_EXT
:
4898 return MESA_FORMAT_I_UINT8
;
4899 case GL_INTENSITY16UI_EXT
:
4900 return MESA_FORMAT_I_UINT16
;
4901 case GL_INTENSITY32UI_EXT
:
4902 return MESA_FORMAT_I_UINT32
;
4908 if (ctx
->API
== API_OPENGL_CORE
&&
4909 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4910 switch (internalFormat
) {
4912 return MESA_FORMAT_RGB_FLOAT32
;
4914 return MESA_FORMAT_RGB_UINT32
;
4916 return MESA_FORMAT_RGB_SINT32
;
4922 switch (internalFormat
) {
4924 return MESA_FORMAT_R8G8B8A8_UNORM
;
4926 return MESA_FORMAT_RGBA_UNORM16
;
4927 case GL_RGBA16F_ARB
:
4928 return MESA_FORMAT_RGBA_FLOAT16
;
4929 case GL_RGBA32F_ARB
:
4930 return MESA_FORMAT_RGBA_FLOAT32
;
4932 return MESA_FORMAT_RGBA_SINT8
;
4933 case GL_RGBA16I_EXT
:
4934 return MESA_FORMAT_RGBA_SINT16
;
4935 case GL_RGBA32I_EXT
:
4936 return MESA_FORMAT_RGBA_SINT32
;
4937 case GL_RGBA8UI_EXT
:
4938 return MESA_FORMAT_RGBA_UINT8
;
4939 case GL_RGBA16UI_EXT
:
4940 return MESA_FORMAT_RGBA_UINT16
;
4941 case GL_RGBA32UI_EXT
:
4942 return MESA_FORMAT_RGBA_UINT32
;
4945 return MESA_FORMAT_R8G8_UNORM
;
4947 return MESA_FORMAT_R16G16_UNORM
;
4949 return MESA_FORMAT_RG_FLOAT16
;
4951 return MESA_FORMAT_RG_FLOAT32
;
4953 return MESA_FORMAT_RG_SINT8
;
4955 return MESA_FORMAT_RG_SINT16
;
4957 return MESA_FORMAT_RG_SINT32
;
4959 return MESA_FORMAT_RG_UINT8
;
4961 return MESA_FORMAT_RG_UINT16
;
4963 return MESA_FORMAT_RG_UINT32
;
4966 return MESA_FORMAT_R_UNORM8
;
4968 return MESA_FORMAT_R_UNORM16
;
4970 return MESA_FORMAT_R_FLOAT16
;
4972 return MESA_FORMAT_R_FLOAT32
;
4974 return MESA_FORMAT_R_SINT8
;
4976 return MESA_FORMAT_R_SINT16
;
4978 return MESA_FORMAT_R_SINT32
;
4980 return MESA_FORMAT_R_UINT8
;
4982 return MESA_FORMAT_R_UINT16
;
4984 return MESA_FORMAT_R_UINT32
;
4987 return MESA_FORMAT_NONE
;
4993 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4994 GLenum internalFormat
)
4996 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
4999 if (format
== MESA_FORMAT_NONE
)
5000 return MESA_FORMAT_NONE
;
5002 datatype
= _mesa_get_format_datatype(format
);
5004 /* The GL_ARB_texture_buffer_object spec says:
5006 * "If ARB_texture_float is not supported, references to the
5007 * floating-point internal formats provided by that extension should be
5008 * removed, and such formats may not be passed to TexBufferARB."
5010 * As a result, GL_HALF_FLOAT internal format depends on both
5011 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5013 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5014 !ctx
->Extensions
.ARB_texture_float
)
5015 return MESA_FORMAT_NONE
;
5017 if (!ctx
->Extensions
.ARB_texture_rg
) {
5018 GLenum base_format
= _mesa_get_format_base_format(format
);
5019 if (base_format
== GL_R
|| base_format
== GL_RG
)
5020 return MESA_FORMAT_NONE
;
5023 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5024 GLenum base_format
= _mesa_get_format_base_format(format
);
5025 if (base_format
== GL_RGB
)
5026 return MESA_FORMAT_NONE
;
5033 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5034 struct gl_texture_object
*texObj
, GLenum target
,
5035 GLenum internalFormat
,
5036 struct gl_buffer_object
*bufObj
,
5037 GLintptr offset
, GLsizeiptr size
, bool range
,
5042 FLUSH_VERTICES(ctx
, 0);
5044 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5045 if (format
== MESA_FORMAT_NONE
) {
5046 _mesa_error(ctx
, GL_INVALID_ENUM
,
5047 "glTex%sBuffer%s(internalFormat 0x%x)", dsa
? "ture" : "",
5048 range
? "Range" : "", internalFormat
);
5052 _mesa_lock_texture(ctx
, texObj
);
5054 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5055 texObj
->BufferObjectFormat
= internalFormat
;
5056 texObj
->_BufferObjectFormat
= format
;
5057 texObj
->BufferOffset
= offset
;
5058 texObj
->BufferSize
= size
;
5060 _mesa_unlock_texture(ctx
, texObj
);
5062 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5065 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5070 /** GL_ARB_texture_buffer_object */
5072 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5074 struct gl_texture_object
*texObj
;
5075 struct gl_buffer_object
*bufObj
;
5077 GET_CURRENT_CONTEXT(ctx
);
5079 /* Need to catch this before it gets to _mesa_get_current_tex_object */
5080 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5081 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
5085 /* NOTE: ARB_texture_buffer_object has interactions with
5086 * the compatibility profile that are not implemented.
5088 if (!(ctx
->API
== API_OPENGL_CORE
&&
5089 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5090 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
5094 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
5095 if (!bufObj
&& buffer
) {
5096 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
5100 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5104 _mesa_texture_buffer_range(ctx
, texObj
, target
, internalFormat
, bufObj
, 0,
5105 buffer
? -1 : 0, false, false);
5109 /** GL_ARB_texture_buffer_range */
5111 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5112 GLintptr offset
, GLsizeiptr size
)
5114 struct gl_texture_object
*texObj
;
5115 struct gl_buffer_object
*bufObj
;
5117 GET_CURRENT_CONTEXT(ctx
);
5119 /* Need to catch this before it gets to _mesa_get_current_tex_object */
5120 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5121 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBufferRange(target)");
5125 if (!(ctx
->API
== API_OPENGL_CORE
&&
5126 ctx
->Extensions
.ARB_texture_buffer_range
)) {
5127 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
5131 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
5135 (offset
+ size
) > bufObj
->Size
) {
5136 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
5139 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5140 _mesa_error(ctx
, GL_INVALID_VALUE
,
5141 "glTexBufferRange(invalid offset alignment)");
5144 } else if (buffer
) {
5145 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
5153 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5157 _mesa_texture_buffer_range(ctx
, texObj
, target
, internalFormat
, bufObj
,
5158 offset
, size
, true, false);
5162 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5164 struct gl_texture_object
*texObj
;
5165 struct gl_buffer_object
*bufObj
;
5167 GET_CURRENT_CONTEXT(ctx
);
5169 /* NOTE: ARB_texture_buffer_object has interactions with
5170 * the compatibility profile that are not implemented.
5172 if (!(ctx
->API
== API_OPENGL_CORE
&&
5173 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5174 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureBuffer");
5178 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
5179 if (!bufObj
&& buffer
) {
5180 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureBuffer(buffer %u)",
5185 /* Get the texture object by Name. */
5186 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5187 "glTextureBuffer(texture)");
5191 if (texObj
->Target
!= GL_TEXTURE_BUFFER_ARB
) {
5192 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureBuffer(target)");
5196 _mesa_texture_buffer_range(ctx
, texObj
, texObj
->Target
, internalFormat
,
5197 bufObj
, 0, buffer
? -1 : 0, false, true);
5201 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5203 /* Everything that is allowed for renderbuffers,
5204 * except for a base format of GL_STENCIL_INDEX.
5206 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5207 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5211 /** GL_ARB_texture_multisample */
5213 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5216 case GL_TEXTURE_2D_MULTISAMPLE
:
5218 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5219 return dims
== 2 && !dsa
;
5221 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5223 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5224 return dims
== 3 && !dsa
;
5233 _mesa_texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5234 struct gl_texture_object
*texObj
,
5235 GLenum target
, GLsizei samples
,
5236 GLint internalformat
, GLsizei width
,
5237 GLsizei height
, GLsizei depth
,
5238 GLboolean fixedsamplelocations
,
5239 GLboolean immutable
, const char *func
)
5241 struct gl_texture_image
*texImage
;
5242 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5243 mesa_format texFormat
;
5244 GLenum sample_count_error
;
5245 bool dsa
= strstr(func
, "ture") ? true : false;
5247 if (!(ctx
->Extensions
.ARB_texture_multisample
5248 && _mesa_is_desktop_gl(ctx
))) {
5249 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5253 if (!check_multisample_target(dims
, target
, dsa
)) {
5255 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5259 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5264 /* check that the specified internalformat is color/depth/stencil-renderable;
5265 * refer GL3.1 spec 4.4.4
5268 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5269 _mesa_error(ctx
, GL_INVALID_ENUM
,
5270 "%s(internalformat=%s not legal for immutable-format)",
5271 func
, _mesa_lookup_enum_by_nr(internalformat
));
5275 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5276 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5277 "%s(internalformat=%s)",
5278 func
, _mesa_lookup_enum_by_nr(internalformat
));
5282 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5283 internalformat
, samples
);
5284 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5286 /* Page 254 of OpenGL 4.4 spec says:
5287 * "Proxy arrays for two-dimensional multisample and two-dimensional
5288 * multisample array textures are operated on in the same way when
5289 * TexImage2DMultisample is called with target specified as
5290 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5291 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5292 * However, if samples is not supported, then no error is generated.
5294 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5295 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5299 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5300 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5301 "%s(texture object 0)",
5306 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5308 if (texImage
== NULL
) {
5309 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5313 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5314 internalformat
, GL_NONE
, GL_NONE
);
5315 assert(texFormat
!= MESA_FORMAT_NONE
);
5317 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5318 width
, height
, depth
, 0);
5320 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5321 width
, height
, depth
, 0);
5323 if (_mesa_is_proxy_texture(target
)) {
5324 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5325 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5326 internalformat
, texFormat
,
5327 samples
, fixedsamplelocations
);
5330 /* clear all image fields */
5331 clear_teximage_fields(texImage
);
5335 if (!dimensionsOK
) {
5336 _mesa_error(ctx
, GL_INVALID_VALUE
,
5337 "%s(invalid width or height)", func
);
5342 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
5343 "%s(texture too large)", func
);
5347 /* Check if texObj->Immutable is set */
5348 if (texObj
->Immutable
) {
5349 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5353 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5355 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5356 internalformat
, texFormat
,
5357 samples
, fixedsamplelocations
);
5359 if (width
> 0 && height
> 0 && depth
> 0) {
5360 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5361 width
, height
, depth
)) {
5362 /* tidy up the texture image state. strictly speaking,
5363 * we're allowed to just leave this in whatever state we
5364 * like, but being tidy is good.
5366 _mesa_init_teximage_fields(ctx
, texImage
,
5367 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5371 texObj
->Immutable
|= immutable
;
5374 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5377 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5383 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5384 GLenum internalformat
, GLsizei width
,
5385 GLsizei height
, GLboolean fixedsamplelocations
)
5387 struct gl_texture_object
*texObj
;
5388 GET_CURRENT_CONTEXT(ctx
);
5390 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5394 _mesa_texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5395 internalformat
, width
, height
, 1,
5396 fixedsamplelocations
, GL_FALSE
,
5397 "glTexImage2DMultisample");
5402 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5403 GLenum internalformat
, GLsizei width
,
5404 GLsizei height
, GLsizei depth
,
5405 GLboolean fixedsamplelocations
)
5407 struct gl_texture_object
*texObj
;
5408 GET_CURRENT_CONTEXT(ctx
);
5410 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5414 _mesa_texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5415 internalformat
, width
, height
, depth
,
5416 fixedsamplelocations
, GL_FALSE
,
5417 "glTexImage3DMultisample");
5422 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5423 GLenum internalformat
, GLsizei width
,
5424 GLsizei height
, GLboolean fixedsamplelocations
)
5426 struct gl_texture_object
*texObj
;
5427 GET_CURRENT_CONTEXT(ctx
);
5429 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5433 _mesa_texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5434 internalformat
, width
, height
, 1,
5435 fixedsamplelocations
, GL_TRUE
,
5436 "glTexStorage2DMultisample");
5440 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5441 GLenum internalformat
, GLsizei width
,
5442 GLsizei height
, GLsizei depth
,
5443 GLboolean fixedsamplelocations
)
5445 struct gl_texture_object
*texObj
;
5446 GET_CURRENT_CONTEXT(ctx
);
5448 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5452 _mesa_texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5453 internalformat
, width
, height
, depth
,
5454 fixedsamplelocations
, GL_TRUE
,
5455 "glTexStorage3DMultisample");
5459 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5460 GLenum internalformat
, GLsizei width
,
5462 GLboolean fixedsamplelocations
)
5464 struct gl_texture_object
*texObj
;
5465 GET_CURRENT_CONTEXT(ctx
);
5467 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5468 "glTextureStorage2DMultisample");
5472 _mesa_texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5473 internalformat
, width
, height
, 1,
5474 fixedsamplelocations
, GL_TRUE
,
5475 "glTextureStorage2DMultisample");
5479 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5480 GLenum internalformat
, GLsizei width
,
5481 GLsizei height
, GLsizei depth
,
5482 GLboolean fixedsamplelocations
)
5484 struct gl_texture_object
*texObj
;
5485 GET_CURRENT_CONTEXT(ctx
);
5487 /* Get the texture object by Name. */
5488 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5489 "glTextureStorage3DMultisample");
5493 _mesa_texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5494 internalformat
, width
, height
, depth
,
5495 fixedsamplelocations
, GL_TRUE
,
5496 "glTextureStorage3DMultisample");