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_INDEX1
:
228 case GL_STENCIL_INDEX4
:
229 case GL_STENCIL_INDEX8
:
230 case GL_STENCIL_INDEX16
:
231 return GL_STENCIL_INDEX
;
237 switch (internalFormat
) {
238 case GL_COMPRESSED_ALPHA
:
240 case GL_COMPRESSED_LUMINANCE
:
242 case GL_COMPRESSED_LUMINANCE_ALPHA
:
243 return GL_LUMINANCE_ALPHA
;
244 case GL_COMPRESSED_INTENSITY
:
246 case GL_COMPRESSED_RGB
:
248 case GL_COMPRESSED_RGBA
:
254 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
255 switch (internalFormat
) {
256 case GL_COMPRESSED_RGB_FXT1_3DFX
:
258 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
265 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
267 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
268 switch (internalFormat
) {
269 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
271 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
272 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
273 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
280 if (_mesa_is_desktop_gl(ctx
)
281 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
282 switch (internalFormat
) {
294 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
295 if (internalFormat
== GL_YCBCR_MESA
)
296 return GL_YCBCR_MESA
;
299 if (ctx
->Extensions
.ARB_texture_float
) {
300 switch (internalFormat
) {
301 case GL_ALPHA16F_ARB
:
302 case GL_ALPHA32F_ARB
:
310 case GL_INTENSITY16F_ARB
:
311 case GL_INTENSITY32F_ARB
:
313 case GL_LUMINANCE16F_ARB
:
314 case GL_LUMINANCE32F_ARB
:
316 case GL_LUMINANCE_ALPHA16F_ARB
:
317 case GL_LUMINANCE_ALPHA32F_ARB
:
318 return GL_LUMINANCE_ALPHA
;
324 if (ctx
->Extensions
.EXT_texture_snorm
) {
325 switch (internalFormat
) {
340 case GL_RGBA16_SNORM
:
343 case GL_ALPHA8_SNORM
:
344 case GL_ALPHA16_SNORM
:
346 case GL_LUMINANCE_SNORM
:
347 case GL_LUMINANCE8_SNORM
:
348 case GL_LUMINANCE16_SNORM
:
350 case GL_LUMINANCE_ALPHA_SNORM
:
351 case GL_LUMINANCE8_ALPHA8_SNORM
:
352 case GL_LUMINANCE16_ALPHA16_SNORM
:
353 return GL_LUMINANCE_ALPHA
;
354 case GL_INTENSITY_SNORM
:
355 case GL_INTENSITY8_SNORM
:
356 case GL_INTENSITY16_SNORM
:
363 if (ctx
->Extensions
.EXT_texture_sRGB
) {
364 switch (internalFormat
) {
367 case GL_COMPRESSED_SRGB_EXT
:
369 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
370 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
371 case GL_SRGB_ALPHA_EXT
:
372 case GL_SRGB8_ALPHA8_EXT
:
373 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
375 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
376 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
377 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
378 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
379 case GL_SLUMINANCE_ALPHA_EXT
:
380 case GL_SLUMINANCE8_ALPHA8_EXT
:
381 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
382 return GL_LUMINANCE_ALPHA
;
383 case GL_SLUMINANCE_EXT
:
384 case GL_SLUMINANCE8_EXT
:
385 case GL_COMPRESSED_SLUMINANCE_EXT
:
392 if (ctx
->Version
>= 30 ||
393 ctx
->Extensions
.EXT_texture_integer
) {
394 switch (internalFormat
) {
396 case GL_RGBA16UI_EXT
:
397 case GL_RGBA32UI_EXT
:
413 if (ctx
->Extensions
.EXT_texture_integer
) {
414 switch (internalFormat
) {
415 case GL_ALPHA8UI_EXT
:
416 case GL_ALPHA16UI_EXT
:
417 case GL_ALPHA32UI_EXT
:
419 case GL_ALPHA16I_EXT
:
420 case GL_ALPHA32I_EXT
:
422 case GL_INTENSITY8UI_EXT
:
423 case GL_INTENSITY16UI_EXT
:
424 case GL_INTENSITY32UI_EXT
:
425 case GL_INTENSITY8I_EXT
:
426 case GL_INTENSITY16I_EXT
:
427 case GL_INTENSITY32I_EXT
:
429 case GL_LUMINANCE8UI_EXT
:
430 case GL_LUMINANCE16UI_EXT
:
431 case GL_LUMINANCE32UI_EXT
:
432 case GL_LUMINANCE8I_EXT
:
433 case GL_LUMINANCE16I_EXT
:
434 case GL_LUMINANCE32I_EXT
:
436 case GL_LUMINANCE_ALPHA8UI_EXT
:
437 case GL_LUMINANCE_ALPHA16UI_EXT
:
438 case GL_LUMINANCE_ALPHA32UI_EXT
:
439 case GL_LUMINANCE_ALPHA8I_EXT
:
440 case GL_LUMINANCE_ALPHA16I_EXT
:
441 case GL_LUMINANCE_ALPHA32I_EXT
:
442 return GL_LUMINANCE_ALPHA
;
448 if (ctx
->Extensions
.ARB_texture_rg
) {
449 switch (internalFormat
) {
452 if (!ctx
->Extensions
.ARB_texture_float
)
461 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
467 case GL_COMPRESSED_RED
:
472 if (!ctx
->Extensions
.ARB_texture_float
)
481 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
487 case GL_COMPRESSED_RG
:
494 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
495 switch (internalFormat
) {
503 if (ctx
->Extensions
.EXT_packed_float
) {
504 switch (internalFormat
) {
505 case GL_R11F_G11F_B10F_EXT
:
512 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
513 switch (internalFormat
) {
514 case GL_DEPTH_COMPONENT32F
:
515 return GL_DEPTH_COMPONENT
;
516 case GL_DEPTH32F_STENCIL8
:
517 return GL_DEPTH_STENCIL
;
523 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
524 switch (internalFormat
) {
525 case GL_COMPRESSED_RED_RGTC1
:
526 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
528 case GL_COMPRESSED_RG_RGTC2
:
529 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
536 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
537 switch (internalFormat
) {
538 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
539 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
541 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
542 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
543 return GL_LUMINANCE_ALPHA
;
549 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
550 switch (internalFormat
) {
551 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
552 return GL_LUMINANCE_ALPHA
;
558 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
559 switch (internalFormat
) {
560 case GL_ETC1_RGB8_OES
:
567 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
568 switch (internalFormat
) {
569 case GL_COMPRESSED_RGB8_ETC2
:
570 case GL_COMPRESSED_SRGB8_ETC2
:
572 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
573 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
574 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
575 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
577 case GL_COMPRESSED_R11_EAC
:
578 case GL_COMPRESSED_SIGNED_R11_EAC
:
580 case GL_COMPRESSED_RG11_EAC
:
581 case GL_COMPRESSED_SIGNED_RG11_EAC
:
588 if (_mesa_is_desktop_gl(ctx
) &&
589 ctx
->Extensions
.ARB_texture_compression_bptc
) {
590 switch (internalFormat
) {
591 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
592 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
594 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
595 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
602 if (ctx
->API
== API_OPENGLES
) {
603 switch (internalFormat
) {
604 case GL_PALETTE4_RGB8_OES
:
605 case GL_PALETTE4_R5_G6_B5_OES
:
606 case GL_PALETTE8_RGB8_OES
:
607 case GL_PALETTE8_R5_G6_B5_OES
:
609 case GL_PALETTE4_RGBA8_OES
:
610 case GL_PALETTE8_RGB5_A1_OES
:
611 case GL_PALETTE4_RGBA4_OES
:
612 case GL_PALETTE4_RGB5_A1_OES
:
613 case GL_PALETTE8_RGBA8_OES
:
614 case GL_PALETTE8_RGBA4_OES
:
621 return -1; /* error */
626 * For cube map faces, return a face index in [0,5].
627 * For other targets return 0;
630 _mesa_tex_target_to_face(GLenum target
)
632 if (_mesa_is_cube_face(target
))
633 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
641 * Install gl_texture_image in a gl_texture_object according to the target
642 * and level parameters.
644 * \param tObj texture object.
645 * \param target texture target.
646 * \param level image level.
647 * \param texImage texture image.
650 set_tex_image(struct gl_texture_object
*tObj
,
651 GLenum target
, GLint level
,
652 struct gl_texture_image
*texImage
)
654 const GLuint face
= _mesa_tex_target_to_face(target
);
658 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
661 tObj
->Image
[face
][level
] = texImage
;
663 /* Set the 'back' pointer */
664 texImage
->TexObject
= tObj
;
665 texImage
->Level
= level
;
666 texImage
->Face
= face
;
671 * Allocate a texture image structure.
673 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
676 * \return a pointer to gl_texture_image struct with all fields initialized to
679 struct gl_texture_image
*
680 _mesa_new_texture_image( struct gl_context
*ctx
)
683 return CALLOC_STRUCT(gl_texture_image
);
688 * Free a gl_texture_image and associated data.
689 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
691 * \param texImage texture image.
693 * Free the texture image structure and the associated image data.
696 _mesa_delete_texture_image(struct gl_context
*ctx
,
697 struct gl_texture_image
*texImage
)
699 /* Free texImage->Data and/or any other driver-specific texture
702 assert(ctx
->Driver
.FreeTextureImageBuffer
);
703 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
709 * Test if a target is a proxy target.
711 * \param target texture target.
713 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
716 _mesa_is_proxy_texture(GLenum target
)
719 static const GLenum targets
[] = {
723 GL_PROXY_TEXTURE_CUBE_MAP
,
724 GL_PROXY_TEXTURE_RECTANGLE
,
725 GL_PROXY_TEXTURE_1D_ARRAY
,
726 GL_PROXY_TEXTURE_2D_ARRAY
,
727 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
728 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
729 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
732 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
733 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
735 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
737 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
738 if (target
== targets
[i
])
745 * Test if a target is an array target.
747 * \param target texture target.
749 * \return true if the target is an array target, false otherwise.
752 _mesa_is_array_texture(GLenum target
)
755 case GL_TEXTURE_1D_ARRAY
:
756 case GL_TEXTURE_2D_ARRAY
:
757 case GL_TEXTURE_CUBE_MAP_ARRAY
:
758 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
767 * Return the proxy target which corresponds to the given texture target
770 proxy_target(GLenum target
)
774 case GL_PROXY_TEXTURE_1D
:
775 return GL_PROXY_TEXTURE_1D
;
777 case GL_PROXY_TEXTURE_2D
:
778 return GL_PROXY_TEXTURE_2D
;
780 case GL_PROXY_TEXTURE_3D
:
781 return GL_PROXY_TEXTURE_3D
;
782 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
783 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
784 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
785 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
786 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
787 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
788 case GL_TEXTURE_CUBE_MAP_ARB
:
789 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
790 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
791 case GL_TEXTURE_RECTANGLE_NV
:
792 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
793 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
794 case GL_TEXTURE_1D_ARRAY_EXT
:
795 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
796 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
797 case GL_TEXTURE_2D_ARRAY_EXT
:
798 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
799 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
800 case GL_TEXTURE_CUBE_MAP_ARRAY
:
801 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
802 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
803 case GL_TEXTURE_2D_MULTISAMPLE
:
804 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
805 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
806 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
807 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
808 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
810 _mesa_problem(NULL
, "unexpected target in proxy_target()");
819 * Get a texture image pointer from a texture object, given a texture
820 * target and mipmap level. The target and level parameters should
821 * have already been error-checked.
823 * \param texObj texture unit.
824 * \param target texture target.
825 * \param level image level.
827 * \return pointer to the texture image structure, or NULL on failure.
829 struct gl_texture_image
*
830 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
831 GLenum target
, GLint level
)
833 const GLuint face
= _mesa_tex_target_to_face(target
);
837 assert(level
< MAX_TEXTURE_LEVELS
);
839 return texObj
->Image
[face
][level
];
844 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
845 * it and install it. Only return NULL if passed a bad parameter or run
848 struct gl_texture_image
*
849 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
850 GLenum target
, GLint level
)
852 struct gl_texture_image
*texImage
;
857 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
859 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
861 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
865 set_tex_image(texObj
, target
, level
, texImage
);
873 * Return pointer to the specified proxy texture image.
874 * Note that proxy textures are per-context, not per-texture unit.
875 * \return pointer to texture image or NULL if invalid target, invalid
876 * level, or out of memory.
878 static struct gl_texture_image
*
879 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
881 struct gl_texture_image
*texImage
;
888 case GL_PROXY_TEXTURE_1D
:
889 if (level
>= ctx
->Const
.MaxTextureLevels
)
891 texIndex
= TEXTURE_1D_INDEX
;
893 case GL_PROXY_TEXTURE_2D
:
894 if (level
>= ctx
->Const
.MaxTextureLevels
)
896 texIndex
= TEXTURE_2D_INDEX
;
898 case GL_PROXY_TEXTURE_3D
:
899 if (level
>= ctx
->Const
.Max3DTextureLevels
)
901 texIndex
= TEXTURE_3D_INDEX
;
903 case GL_PROXY_TEXTURE_CUBE_MAP
:
904 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
906 texIndex
= TEXTURE_CUBE_INDEX
;
908 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
911 texIndex
= TEXTURE_RECT_INDEX
;
913 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
914 if (level
>= ctx
->Const
.MaxTextureLevels
)
916 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
918 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
919 if (level
>= ctx
->Const
.MaxTextureLevels
)
921 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
923 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
924 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
926 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
928 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
931 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
933 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
936 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
942 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
944 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
946 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
949 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
950 /* Set the 'back' pointer */
951 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
958 * Get the maximum number of allowed mipmap levels.
960 * \param ctx GL context.
961 * \param target texture target.
963 * \return the maximum number of allowed mipmap levels for the given
964 * texture target, or zero if passed a bad target.
969 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
973 case GL_PROXY_TEXTURE_1D
:
975 case GL_PROXY_TEXTURE_2D
:
976 return ctx
->Const
.MaxTextureLevels
;
978 case GL_PROXY_TEXTURE_3D
:
979 return ctx
->Const
.Max3DTextureLevels
;
980 case GL_TEXTURE_CUBE_MAP
:
981 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
982 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
983 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
984 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
985 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
986 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
987 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
988 return ctx
->Extensions
.ARB_texture_cube_map
989 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
990 case GL_TEXTURE_RECTANGLE_NV
:
991 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
992 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
993 case GL_TEXTURE_1D_ARRAY_EXT
:
994 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
995 case GL_TEXTURE_2D_ARRAY_EXT
:
996 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
997 return ctx
->Extensions
.EXT_texture_array
998 ? ctx
->Const
.MaxTextureLevels
: 0;
999 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1000 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1001 return ctx
->Extensions
.ARB_texture_cube_map_array
1002 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1003 case GL_TEXTURE_BUFFER
:
1004 return ctx
->API
== API_OPENGL_CORE
&&
1005 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1006 case GL_TEXTURE_2D_MULTISAMPLE
:
1007 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1008 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1009 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1010 return _mesa_is_desktop_gl(ctx
)
1011 && ctx
->Extensions
.ARB_texture_multisample
1013 case GL_TEXTURE_EXTERNAL_OES
:
1016 return 0; /* bad target */
1022 * Return number of dimensions per mipmap level for the given texture target.
1025 _mesa_get_texture_dimensions(GLenum target
)
1029 case GL_PROXY_TEXTURE_1D
:
1032 case GL_TEXTURE_RECTANGLE
:
1033 case GL_TEXTURE_CUBE_MAP
:
1034 case GL_PROXY_TEXTURE_2D
:
1035 case GL_PROXY_TEXTURE_RECTANGLE
:
1036 case GL_PROXY_TEXTURE_CUBE_MAP
:
1037 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1038 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1039 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1040 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1041 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1042 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1043 case GL_TEXTURE_1D_ARRAY
:
1044 case GL_PROXY_TEXTURE_1D_ARRAY
:
1045 case GL_TEXTURE_EXTERNAL_OES
:
1046 case GL_TEXTURE_2D_MULTISAMPLE
:
1047 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1050 case GL_PROXY_TEXTURE_3D
:
1051 case GL_TEXTURE_2D_ARRAY
:
1052 case GL_PROXY_TEXTURE_2D_ARRAY
:
1053 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1054 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1055 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1056 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1058 case GL_TEXTURE_BUFFER
:
1061 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1069 * Check if a texture target can have more than one layer.
1072 _mesa_tex_target_is_layered(GLenum target
)
1076 case GL_PROXY_TEXTURE_1D
:
1078 case GL_PROXY_TEXTURE_2D
:
1079 case GL_TEXTURE_RECTANGLE
:
1080 case GL_PROXY_TEXTURE_RECTANGLE
:
1081 case GL_TEXTURE_2D_MULTISAMPLE
:
1082 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1083 case GL_TEXTURE_BUFFER
:
1084 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1085 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1086 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1087 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1088 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1089 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1090 case GL_TEXTURE_EXTERNAL_OES
:
1094 case GL_PROXY_TEXTURE_3D
:
1095 case GL_TEXTURE_CUBE_MAP
:
1096 case GL_PROXY_TEXTURE_CUBE_MAP
:
1097 case GL_TEXTURE_1D_ARRAY
:
1098 case GL_PROXY_TEXTURE_1D_ARRAY
:
1099 case GL_TEXTURE_2D_ARRAY
:
1100 case GL_PROXY_TEXTURE_2D_ARRAY
:
1101 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1102 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1103 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1104 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1108 assert(!"Invalid texture target.");
1115 * Return the number of layers present in the given level of an array,
1116 * cubemap or 3D texture. If the texture is not layered return zero.
1119 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1121 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1123 switch (texObj
->Target
) {
1126 case GL_TEXTURE_RECTANGLE
:
1127 case GL_TEXTURE_2D_MULTISAMPLE
:
1128 case GL_TEXTURE_BUFFER
:
1129 case GL_TEXTURE_EXTERNAL_OES
:
1132 case GL_TEXTURE_CUBE_MAP
:
1135 case GL_TEXTURE_1D_ARRAY
: {
1136 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1137 return img
? img
->Height
: 0;
1141 case GL_TEXTURE_2D_ARRAY
:
1142 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1143 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1144 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1145 return img
? img
->Depth
: 0;
1149 assert(!"Invalid texture target.");
1156 * Return the maximum number of mipmap levels for the given target
1157 * and the dimensions.
1158 * The dimensions are expected not to include the border.
1161 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1168 case GL_TEXTURE_1D_ARRAY
:
1169 case GL_PROXY_TEXTURE_1D
:
1170 case GL_PROXY_TEXTURE_1D_ARRAY
:
1173 case GL_TEXTURE_CUBE_MAP
:
1174 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1175 case GL_PROXY_TEXTURE_CUBE_MAP
:
1176 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1180 case GL_TEXTURE_2D_ARRAY
:
1181 case GL_PROXY_TEXTURE_2D
:
1182 case GL_PROXY_TEXTURE_2D_ARRAY
:
1183 size
= MAX2(width
, height
);
1186 case GL_PROXY_TEXTURE_3D
:
1187 size
= MAX3(width
, height
, depth
);
1189 case GL_TEXTURE_RECTANGLE
:
1190 case GL_TEXTURE_EXTERNAL_OES
:
1191 case GL_TEXTURE_2D_MULTISAMPLE
:
1192 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1193 case GL_PROXY_TEXTURE_RECTANGLE
:
1194 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1195 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1202 return _mesa_logbase2(size
) + 1;
1206 #if 000 /* not used anymore */
1208 * glTexImage[123]D can accept a NULL image pointer. In this case we
1209 * create a texture image with unspecified image contents per the OpenGL
1213 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1215 const GLint components
= _mesa_components_in_format(format
);
1216 const GLint numPixels
= width
* height
* depth
;
1217 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1221 * Let's see if anyone finds this. If glTexImage2D() is called with
1222 * a NULL image pointer then load the texture image with something
1223 * interesting instead of leaving it indeterminate.
1226 static const char message
[8][32] = {
1227 " X X XXXXX XXX X ",
1228 " XX XX X X X X X ",
1230 " X X XXXX XXX XXXXX ",
1233 " X X XXXXX XXX X X ",
1237 GLubyte
*imgPtr
= data
;
1239 for (h
= 0; h
< depth
; h
++) {
1240 for (i
= 0; i
< height
; i
++) {
1241 GLint srcRow
= 7 - (i
% 8);
1242 for (j
= 0; j
< width
; j
++) {
1243 GLint srcCol
= j
% 32;
1244 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1245 for (k
= 0; k
< components
; k
++) {
1261 * Set the size and format-related fields of a gl_texture_image struct
1262 * to zero. This is used when a proxy texture test fails.
1265 clear_teximage_fields(struct gl_texture_image
*img
)
1268 img
->_BaseFormat
= 0;
1269 img
->InternalFormat
= 0;
1278 img
->HeightLog2
= 0;
1280 img
->TexFormat
= MESA_FORMAT_NONE
;
1281 img
->NumSamples
= 0;
1282 img
->FixedSampleLocations
= GL_TRUE
;
1287 * Initialize basic fields of the gl_texture_image struct.
1289 * \param ctx GL context.
1290 * \param img texture image structure to be initialized.
1291 * \param width image width.
1292 * \param height image height.
1293 * \param depth image depth.
1294 * \param border image border.
1295 * \param internalFormat internal format.
1296 * \param format the actual hardware format (one of MESA_FORMAT_*)
1297 * \param numSamples number of samples per texel, or zero for non-MS.
1298 * \param fixedSampleLocations are sample locations fixed?
1300 * Fills in the fields of \p img with the given information.
1301 * Note: width, height and depth include the border.
1304 init_teximage_fields_ms(struct gl_context
*ctx
,
1305 struct gl_texture_image
*img
,
1306 GLsizei width
, GLsizei height
, GLsizei depth
,
1307 GLint border
, GLenum internalFormat
,
1309 GLuint numSamples
, GLboolean fixedSampleLocations
)
1314 assert(height
>= 0);
1317 target
= img
->TexObject
->Target
;
1318 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1319 assert(img
->_BaseFormat
!= -1);
1320 img
->InternalFormat
= internalFormat
;
1321 img
->Border
= border
;
1323 img
->Height
= height
;
1326 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1327 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1329 img
->NumSamples
= 0;
1330 img
->FixedSampleLocations
= GL_TRUE
;
1334 case GL_TEXTURE_BUFFER
:
1335 case GL_PROXY_TEXTURE_1D
:
1340 img
->HeightLog2
= 0;
1347 case GL_TEXTURE_1D_ARRAY
:
1348 case GL_PROXY_TEXTURE_1D_ARRAY
:
1349 img
->Height2
= height
; /* no border */
1350 img
->HeightLog2
= 0; /* not used */
1358 case GL_TEXTURE_RECTANGLE
:
1359 case GL_TEXTURE_CUBE_MAP
:
1360 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1361 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1362 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1363 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1364 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1365 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1366 case GL_TEXTURE_EXTERNAL_OES
:
1367 case GL_PROXY_TEXTURE_2D
:
1368 case GL_PROXY_TEXTURE_RECTANGLE
:
1369 case GL_PROXY_TEXTURE_CUBE_MAP
:
1370 case GL_TEXTURE_2D_MULTISAMPLE
:
1371 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1372 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1373 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1380 case GL_TEXTURE_2D_ARRAY
:
1381 case GL_PROXY_TEXTURE_2D_ARRAY
:
1382 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1383 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1384 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1385 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1386 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1387 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1388 img
->Depth2
= depth
; /* no border */
1389 img
->DepthLog2
= 0; /* not used */
1392 case GL_PROXY_TEXTURE_3D
:
1393 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1394 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1395 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1396 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1399 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1404 _mesa_get_tex_max_num_levels(target
,
1405 img
->Width2
, img
->Height2
, img
->Depth2
);
1406 img
->TexFormat
= format
;
1407 img
->NumSamples
= numSamples
;
1408 img
->FixedSampleLocations
= fixedSampleLocations
;
1413 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1414 struct gl_texture_image
*img
,
1415 GLsizei width
, GLsizei height
, GLsizei depth
,
1416 GLint border
, GLenum internalFormat
,
1419 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1420 internalFormat
, format
, 0, GL_TRUE
);
1425 * Free and clear fields of the gl_texture_image struct.
1427 * \param ctx GL context.
1428 * \param texImage texture image structure to be cleared.
1430 * After the call, \p texImage will have no data associated with it. Its
1431 * fields are cleared so that its parent object will test incomplete.
1434 _mesa_clear_texture_image(struct gl_context
*ctx
,
1435 struct gl_texture_image
*texImage
)
1437 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1438 clear_teximage_fields(texImage
);
1443 * Check the width, height, depth and border of a texture image are legal.
1444 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1446 * The target and level parameters will have already been validated.
1447 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1450 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1451 GLint level
, GLint width
, GLint height
,
1452 GLint depth
, GLint border
)
1458 case GL_PROXY_TEXTURE_1D
:
1459 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1460 maxSize
>>= level
; /* level size */
1461 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1463 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1464 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1470 case GL_PROXY_TEXTURE_2D
:
1471 case GL_TEXTURE_2D_MULTISAMPLE
:
1472 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1473 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1475 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1477 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1479 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1480 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1482 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1488 case GL_PROXY_TEXTURE_3D
:
1489 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1491 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1493 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1495 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1497 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1498 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1500 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1502 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1507 case GL_TEXTURE_RECTANGLE_NV
:
1508 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1511 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1512 if (width
< 0 || width
> maxSize
)
1514 if (height
< 0 || height
> maxSize
)
1518 case GL_TEXTURE_CUBE_MAP
:
1519 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1520 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1521 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1522 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1523 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1524 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1525 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1526 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1528 if (width
!= height
)
1530 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1532 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1534 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1535 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1537 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1542 case GL_TEXTURE_1D_ARRAY_EXT
:
1543 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1544 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1546 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1548 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1550 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1551 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1556 case GL_TEXTURE_2D_ARRAY_EXT
:
1557 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1558 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1559 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1560 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1562 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1564 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1566 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1568 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1569 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1571 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1576 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1577 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1578 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1579 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1581 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1583 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1585 if (width
!= height
)
1587 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1589 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1590 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1592 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1597 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1604 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1605 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1606 * \param destImage the destination texture image.
1607 * \return GL_TRUE if error found, GL_FALSE otherwise.
1610 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1611 const struct gl_texture_image
*destImage
,
1612 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1613 GLsizei subWidth
, GLsizei subHeight
,
1614 GLsizei subDepth
, const char *func
)
1616 const GLenum target
= destImage
->TexObject
->Target
;
1621 _mesa_error(ctx
, GL_INVALID_VALUE
,
1622 "%s%dD(width=%d)", func
, dims
, subWidth
);
1626 if (dims
> 1 && subHeight
< 0) {
1627 _mesa_error(ctx
, GL_INVALID_VALUE
,
1628 "%s%dD(height=%d)", func
, dims
, subHeight
);
1632 if (dims
> 2 && subDepth
< 0) {
1633 _mesa_error(ctx
, GL_INVALID_VALUE
,
1634 "%s%dD(depth=%d)", func
, dims
, subDepth
);
1638 /* check xoffset and width */
1639 if (xoffset
< - (GLint
) destImage
->Border
) {
1640 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1645 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1646 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1651 /* check yoffset and height */
1653 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1654 if (yoffset
< -yBorder
) {
1655 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1659 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1660 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1666 /* check zoffset and depth */
1669 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1670 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1671 0 : destImage
->Border
;
1673 if (zoffset
< -zBorder
) {
1674 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", func
);
1678 depth
= (GLint
) destImage
->Depth
;
1679 if (target
== GL_TEXTURE_CUBE_MAP
)
1681 if (zoffset
+ subDepth
> depth
) {
1682 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", func
);
1688 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1689 * compressed texture images can be updated. But, that restriction may be
1690 * relaxed for particular compressed formats. At this time, all the
1691 * compressed formats supported by Mesa allow sub-textures to be updated
1692 * along compressed block boundaries.
1694 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1696 if (bw
!= 1 || bh
!= 1) {
1697 /* offset must be multiple of block size */
1698 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1699 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1700 "%s%dD(xoffset = %d, yoffset = %d)",
1701 func
, dims
, xoffset
, yoffset
);
1705 /* The size must be a multiple of bw x bh, or we must be using a
1706 * offset+size that exactly hits the edge of the image. This
1707 * is important for small mipmap levels (1x1, 2x1, etc) and for
1710 if ((subWidth
% bw
!= 0) &&
1711 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1712 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1713 "%s%dD(width = %d)", func
, dims
, subWidth
);
1717 if ((subHeight
% bh
!= 0) &&
1718 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1719 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1720 "%s%dD(height = %d)", func
, dims
, subHeight
);
1732 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1733 * specific texture image size checks.
1735 * A hardware driver might override this function if, for example, the
1736 * max 3D texture size is 512x512x64 (i.e. not a cube).
1738 * Note that width, height, depth == 0 is not an error. However, a
1739 * texture with zero width/height/depth will be considered "incomplete"
1740 * and texturing will effectively be disabled.
1742 * \param target any texture target/type
1743 * \param level as passed to glTexImage
1744 * \param format the MESA_FORMAT_x for the tex image
1745 * \param width as passed to glTexImage
1746 * \param height as passed to glTexImage
1747 * \param depth as passed to glTexImage
1748 * \param border as passed to glTexImage
1749 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1752 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1754 GLint width
, GLint height
, GLint depth
, GLint border
)
1756 /* We just check if the image size is less than MaxTextureMbytes.
1757 * Some drivers may do more specific checks.
1759 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1760 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1761 mbytes
*= _mesa_num_tex_faces(target
);
1762 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1767 * Return true if the format is only valid for glCompressedTexImage.
1770 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1773 case GL_ETC1_RGB8_OES
:
1774 case GL_PALETTE4_RGB8_OES
:
1775 case GL_PALETTE4_RGBA8_OES
:
1776 case GL_PALETTE4_R5_G6_B5_OES
:
1777 case GL_PALETTE4_RGBA4_OES
:
1778 case GL_PALETTE4_RGB5_A1_OES
:
1779 case GL_PALETTE8_RGB8_OES
:
1780 case GL_PALETTE8_RGBA8_OES
:
1781 case GL_PALETTE8_R5_G6_B5_OES
:
1782 case GL_PALETTE8_RGBA4_OES
:
1783 case GL_PALETTE8_RGB5_A1_OES
:
1792 * Helper function to determine whether a target and specific compression
1793 * format are supported.
1796 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1799 (void) intFormat
; /* not used yet */
1803 case GL_PROXY_TEXTURE_2D
:
1804 return GL_TRUE
; /* true for any compressed format so far */
1805 case GL_PROXY_TEXTURE_CUBE_MAP
:
1806 case GL_TEXTURE_CUBE_MAP
:
1807 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1808 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1809 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1810 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1811 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1812 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1813 return ctx
->Extensions
.ARB_texture_cube_map
;
1814 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1815 case GL_TEXTURE_2D_ARRAY_EXT
:
1816 return ctx
->Extensions
.EXT_texture_array
;
1817 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1818 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1819 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1827 * Check if the given texture target value is legal for a
1828 * glTexImage1/2/3D call.
1831 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1837 case GL_PROXY_TEXTURE_1D
:
1838 return _mesa_is_desktop_gl(ctx
);
1846 case GL_PROXY_TEXTURE_2D
:
1847 return _mesa_is_desktop_gl(ctx
);
1848 case GL_PROXY_TEXTURE_CUBE_MAP
:
1849 return _mesa_is_desktop_gl(ctx
)
1850 && ctx
->Extensions
.ARB_texture_cube_map
;
1851 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1852 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1853 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1854 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1855 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1856 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1857 return ctx
->Extensions
.ARB_texture_cube_map
;
1858 case GL_TEXTURE_RECTANGLE_NV
:
1859 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1860 return _mesa_is_desktop_gl(ctx
)
1861 && ctx
->Extensions
.NV_texture_rectangle
;
1862 case GL_TEXTURE_1D_ARRAY_EXT
:
1863 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1864 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1872 case GL_PROXY_TEXTURE_3D
:
1873 return _mesa_is_desktop_gl(ctx
);
1874 case GL_TEXTURE_2D_ARRAY_EXT
:
1875 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1876 || _mesa_is_gles3(ctx
);
1877 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1878 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1879 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1880 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1881 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1886 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1893 * Check if the given texture target value is legal for a
1894 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1895 * The difference compared to legal_teximage_target() above is that
1896 * proxy targets are not supported.
1899 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1904 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1909 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1910 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1911 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1912 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1913 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1914 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1915 return ctx
->Extensions
.ARB_texture_cube_map
;
1916 case GL_TEXTURE_RECTANGLE_NV
:
1917 return _mesa_is_desktop_gl(ctx
)
1918 && ctx
->Extensions
.NV_texture_rectangle
;
1919 case GL_TEXTURE_1D_ARRAY_EXT
:
1920 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1928 case GL_TEXTURE_2D_ARRAY_EXT
:
1929 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1930 || _mesa_is_gles3(ctx
);
1931 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1932 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1933 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1935 /* Table 8.15 of the OpenGL 4.5 core profile spec
1936 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1937 * and CopyTextureSubImage3D.
1939 case GL_TEXTURE_CUBE_MAP
:
1945 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1953 * Helper function to determine if a texture object is mutable (in terms
1954 * of GL_ARB_texture_storage).
1957 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1959 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1963 return !texObj
->Immutable
;
1968 * Return expected size of a compressed texture.
1971 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1974 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1975 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1979 * Verify that a texture format is valid with a particular target
1981 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1982 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1985 * \param ctx GL context
1986 * \param target Texture target
1987 * \param internalFormat Internal format of the texture image
1988 * \param dimensions Dimensionality at the caller. This is \b not used
1989 * in the validation. It is only used when logging
1991 * \param caller Base name of the calling function (e.g.,
1992 * "glTexImage" or "glTexStorage").
1994 * \returns true if the combination is legal, false otherwise.
1997 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1998 GLenum target
, GLenum internalFormat
,
1999 unsigned dimensions
,
2002 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2003 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2004 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
2005 * Profile spec says:
2007 * "Textures with a base internal format of DEPTH_COMPONENT or
2008 * DEPTH_STENCIL are supported by texture image specification
2009 * commands only if target is TEXTURE_1D, TEXTURE_2D,
2010 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
2011 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
2012 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
2013 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
2014 * formats in conjunction with any other target will result in an
2015 * INVALID_OPERATION error."
2017 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
2018 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
2020 if (target
!= GL_TEXTURE_1D
&&
2021 target
!= GL_PROXY_TEXTURE_1D
&&
2022 target
!= GL_TEXTURE_2D
&&
2023 target
!= GL_PROXY_TEXTURE_2D
&&
2024 target
!= GL_TEXTURE_1D_ARRAY
&&
2025 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2026 target
!= GL_TEXTURE_2D_ARRAY
&&
2027 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2028 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2029 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2030 !((_mesa_is_cube_face(target
) ||
2031 target
== GL_TEXTURE_CUBE_MAP
||
2032 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2033 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2034 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2035 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2036 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2037 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2038 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2039 "%s%dD(bad target for depth texture)",
2040 caller
, dimensions
);
2049 texture_formats_agree(GLenum internalFormat
,
2052 GLboolean colorFormat
;
2053 GLboolean is_format_depth_or_depthstencil
;
2054 GLboolean is_internalFormat_depth_or_depthstencil
;
2056 /* Even though there are no color-index textures, we still have to support
2057 * uploading color-index data and remapping it to RGB via the
2058 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2060 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2062 is_internalFormat_depth_or_depthstencil
=
2063 _mesa_is_depth_format(internalFormat
) ||
2064 _mesa_is_depthstencil_format(internalFormat
);
2066 is_format_depth_or_depthstencil
=
2067 _mesa_is_depth_format(format
) ||
2068 _mesa_is_depthstencil_format(format
);
2070 colorFormat
= _mesa_is_color_format(format
);
2072 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2075 if (is_internalFormat_depth_or_depthstencil
!=
2076 is_format_depth_or_depthstencil
)
2079 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2086 * Test the glTexImage[123]D() parameters for errors.
2088 * \param ctx GL context.
2089 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2090 * \param target texture target given by the user (already validated).
2091 * \param level image level given by the user.
2092 * \param internalFormat internal format given by the user.
2093 * \param format pixel data format given by the user.
2094 * \param type pixel data type given by the user.
2095 * \param width image width given by the user.
2096 * \param height image height given by the user.
2097 * \param depth image depth given by the user.
2098 * \param border image border given by the user.
2100 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2102 * Verifies each of the parameters against the constants specified in
2103 * __struct gl_contextRec::Const and the supported extensions, and according
2104 * to the OpenGL specification.
2105 * Note that we don't fully error-check the width, height, depth values
2106 * here. That's done in _mesa_legal_texture_dimensions() which is used
2107 * by several other GL entrypoints. Plus, texture dims have a special
2108 * interaction with proxy textures.
2111 texture_error_check( struct gl_context
*ctx
,
2112 GLuint dimensions
, GLenum target
,
2113 GLint level
, GLint internalFormat
,
2114 GLenum format
, GLenum type
,
2115 GLint width
, GLint height
,
2116 GLint depth
, GLint border
)
2120 /* Note: for proxy textures, some error conditions immediately generate
2121 * a GL error in the usual way. But others do not generate a GL error.
2122 * Instead, they cause the width, height, depth, format fields of the
2123 * texture image to be zeroed-out. The GL spec seems to indicate that the
2124 * zero-out behaviour is only used in cases related to memory allocation.
2128 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2129 _mesa_error(ctx
, GL_INVALID_VALUE
,
2130 "glTexImage%dD(level=%d)", dimensions
, level
);
2135 if (border
< 0 || border
> 1 ||
2136 ((ctx
->API
!= API_OPENGL_COMPAT
||
2137 target
== GL_TEXTURE_RECTANGLE_NV
||
2138 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2139 _mesa_error(ctx
, GL_INVALID_VALUE
,
2140 "glTexImage%dD(border=%d)", dimensions
, border
);
2144 if (width
< 0 || height
< 0 || depth
< 0) {
2145 _mesa_error(ctx
, GL_INVALID_VALUE
,
2146 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2150 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2151 * combinations of format, internalFormat, and type that can be used.
2152 * Formats and types that require additional extensions (e.g., GL_FLOAT
2153 * requires GL_OES_texture_float) are filtered elsewhere.
2156 if (_mesa_is_gles(ctx
)) {
2157 if (_mesa_is_gles3(ctx
)) {
2158 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
2161 if (format
!= internalFormat
) {
2162 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2163 "glTexImage%dD(format = %s, internalFormat = %s)",
2165 _mesa_lookup_enum_by_nr(format
),
2166 _mesa_lookup_enum_by_nr(internalFormat
));
2170 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2172 if (err
!= GL_NO_ERROR
) {
2173 _mesa_error(ctx
, err
,
2174 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2176 _mesa_lookup_enum_by_nr(format
),
2177 _mesa_lookup_enum_by_nr(type
),
2178 _mesa_lookup_enum_by_nr(internalFormat
));
2183 /* Check internalFormat */
2184 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2185 _mesa_error(ctx
, GL_INVALID_VALUE
,
2186 "glTexImage%dD(internalFormat=%s)",
2187 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2191 /* Check incoming image format and type */
2192 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2193 if (err
!= GL_NO_ERROR
) {
2194 _mesa_error(ctx
, err
,
2195 "glTexImage%dD(incompatible format = %s, type = %s)",
2196 dimensions
, _mesa_lookup_enum_by_nr(format
),
2197 _mesa_lookup_enum_by_nr(type
));
2201 /* make sure internal format and format basically agree */
2202 if (!texture_formats_agree(internalFormat
, format
)) {
2203 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2204 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2205 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2206 _mesa_lookup_enum_by_nr(format
));
2210 /* additional checks for ycbcr textures */
2211 if (internalFormat
== GL_YCBCR_MESA
) {
2212 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
2213 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2214 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2216 _mesa_snprintf(message
, sizeof(message
),
2217 "glTexImage%dD(format/type YCBCR mismatch)",
2219 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2220 return GL_TRUE
; /* error */
2222 if (target
!= GL_TEXTURE_2D
&&
2223 target
!= GL_PROXY_TEXTURE_2D
&&
2224 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2225 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2226 _mesa_error(ctx
, GL_INVALID_ENUM
,
2227 "glTexImage%dD(bad target for YCbCr texture)",
2233 _mesa_snprintf(message
, sizeof(message
),
2234 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2235 dimensions
, border
);
2236 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2241 /* additional checks for depth textures */
2242 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2243 dimensions
, "glTexImage"))
2246 /* additional checks for compressed textures */
2247 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2248 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2249 _mesa_error(ctx
, GL_INVALID_ENUM
,
2250 "glTexImage%dD(target can't be compressed)", dimensions
);
2253 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2254 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2255 "glTexImage%dD(no compression for format)", dimensions
);
2259 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2260 "glTexImage%dD(border!=0)", dimensions
);
2265 /* additional checks for integer textures */
2266 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2267 (_mesa_is_enum_format_integer(format
) !=
2268 _mesa_is_enum_format_integer(internalFormat
))) {
2269 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2270 "glTexImage%dD(integer/non-integer format mismatch)",
2275 if (!mutable_tex_object(ctx
, target
)) {
2276 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2277 "glTexImage%dD(immutable texture)", dimensions
);
2281 /* if we get here, the parameters are OK */
2287 * Error checking for glCompressedTexImage[123]D().
2288 * Note that the width, height and depth values are not fully error checked
2290 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2293 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2294 GLenum target
, GLint level
,
2295 GLenum internalFormat
, GLsizei width
,
2296 GLsizei height
, GLsizei depth
, GLint border
,
2299 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2301 GLenum error
= GL_NO_ERROR
;
2302 char *reason
= ""; /* no error */
2304 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2306 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
2308 * "The ETC2/EAC texture compression algorithm supports only
2309 * two-dimensional images. If internalformat is an ETC2/EAC format,
2310 * CompressedTexImage3D will generate an INVALID_OPERATION error if
2311 * target is not TEXTURE_2D_ARRAY."
2313 error
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
2317 /* This will detect any invalid internalFormat value */
2318 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2319 _mesa_error(ctx
, GL_INVALID_ENUM
,
2320 "glCompressedTexImage%dD(internalFormat=%s)",
2321 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2325 switch (internalFormat
) {
2326 case GL_PALETTE4_RGB8_OES
:
2327 case GL_PALETTE4_RGBA8_OES
:
2328 case GL_PALETTE4_R5_G6_B5_OES
:
2329 case GL_PALETTE4_RGBA4_OES
:
2330 case GL_PALETTE4_RGB5_A1_OES
:
2331 case GL_PALETTE8_RGB8_OES
:
2332 case GL_PALETTE8_RGBA8_OES
:
2333 case GL_PALETTE8_R5_G6_B5_OES
:
2334 case GL_PALETTE8_RGBA4_OES
:
2335 case GL_PALETTE8_RGB5_A1_OES
:
2336 /* check level (note that level should be zero or less!) */
2337 if (level
> 0 || level
< -maxLevels
) {
2339 error
= GL_INVALID_VALUE
;
2343 if (dimensions
!= 2) {
2344 reason
= "compressed paletted textures must be 2D";
2345 error
= GL_INVALID_OPERATION
;
2349 /* Figure out the expected texture size (in bytes). This will be
2350 * checked against the actual size later.
2352 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2355 /* This is for the benefit of the TestProxyTexImage below. It expects
2356 * level to be non-negative. OES_compressed_paletted_texture uses a
2357 * weird mechanism where the level specified to glCompressedTexImage2D
2358 * is -(n-1) number of levels in the texture, and the data specifies the
2359 * complete mipmap stack. This is done to ensure the palette is the
2360 * same for all levels.
2367 if (level
< 0 || level
>= maxLevels
) {
2369 error
= GL_INVALID_VALUE
;
2373 /* Figure out the expected texture size (in bytes). This will be
2374 * checked against the actual size later.
2376 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2380 /* This should really never fail */
2381 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2382 reason
= "internalFormat";
2383 error
= GL_INVALID_ENUM
;
2387 /* No compressed formats support borders at this time */
2389 reason
= "border != 0";
2390 error
= GL_INVALID_VALUE
;
2394 /* Check for invalid pixel storage modes */
2395 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2397 "glCompressedTexImage")) {
2401 /* check image size in bytes */
2402 if (expectedSize
!= imageSize
) {
2403 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2404 * if <imageSize> is not consistent with the format, dimensions, and
2405 * contents of the specified image.
2407 reason
= "imageSize inconsistant with width/height/format";
2408 error
= GL_INVALID_VALUE
;
2412 if (!mutable_tex_object(ctx
, target
)) {
2413 reason
= "immutable texture";
2414 error
= GL_INVALID_OPERATION
;
2421 /* Note: not all error paths exit through here. */
2422 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2423 dimensions
, reason
);
2430 * Test glTexSubImage[123]D() parameters for errors.
2432 * \param ctx GL context.
2433 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2434 * \param target texture target given by the user (already validated)
2435 * \param level image level given by the user.
2436 * \param xoffset sub-image x offset given by the user.
2437 * \param yoffset sub-image y offset given by the user.
2438 * \param zoffset sub-image z offset given by the user.
2439 * \param format pixel data format given by the user.
2440 * \param type pixel data type given by the user.
2441 * \param width image width given by the user.
2442 * \param height image height given by the user.
2443 * \param depth image depth given by the user.
2445 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2447 * Verifies each of the parameters against the constants specified in
2448 * __struct gl_contextRec::Const and the supported extensions, and according
2449 * to the OpenGL specification.
2452 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2453 struct gl_texture_object
*texObj
,
2454 GLenum target
, GLint level
,
2455 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2456 GLint width
, GLint height
, GLint depth
,
2457 GLenum format
, GLenum type
, bool dsa
)
2459 struct gl_texture_image
*texImage
;
2461 const char* suffix
= dsa
? "ture" : "";
2464 /* must be out of memory */
2465 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTex%sSubImage%dD()",
2466 suffix
, dimensions
);
2470 /* check target (proxies not allowed) */
2471 if (!legal_texsubimage_target(ctx
, dimensions
, target
, dsa
)) {
2472 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sSubImage%uD(target=%s)",
2473 suffix
, dimensions
, _mesa_lookup_enum_by_nr(target
));
2478 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2479 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTex%sSubImage%uD(level=%d)",
2480 suffix
, dimensions
, level
);
2484 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2485 * combinations of format and type that can be used. Formats and types
2486 * that require additional extensions (e.g., GL_FLOAT requires
2487 * GL_OES_texture_float) are filtered elsewhere.
2489 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2490 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2491 if (err
!= GL_NO_ERROR
) {
2492 _mesa_error(ctx
, err
,
2493 "glTex%sSubImage%dD(format = %s, type = %s)",
2494 suffix
, dimensions
, _mesa_lookup_enum_by_nr(format
),
2495 _mesa_lookup_enum_by_nr(type
));
2500 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2501 if (err
!= GL_NO_ERROR
) {
2502 _mesa_error(ctx
, err
,
2503 "glTex%sSubImage%dD(incompatible format = %s, type = %s)",
2504 suffix
, dimensions
, _mesa_lookup_enum_by_nr(format
),
2505 _mesa_lookup_enum_by_nr(type
));
2509 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2511 /* non-existant texture level */
2512 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2513 "glTex%sSubImage%dD(invalid texture image)", suffix
,
2518 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2519 texImage
, xoffset
, yoffset
, zoffset
,
2520 width
, height
, depth
,
2521 dsa
? "glTextureSubImage" :
2526 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2527 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2528 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2529 "glTex%sSubImage%dD(no compression for format)",
2530 suffix
, dimensions
);
2535 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2536 /* both source and dest must be integer-valued, or neither */
2537 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2538 _mesa_is_enum_format_integer(format
)) {
2539 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2540 "glTex%sSubImage%dD(integer/non-integer format mismatch)",
2541 suffix
, dimensions
);
2551 * Test glCopyTexImage[12]D() parameters for errors.
2553 * \param ctx GL context.
2554 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2555 * \param target texture target given by the user.
2556 * \param level image level given by the user.
2557 * \param internalFormat internal format given by the user.
2558 * \param width image width given by the user.
2559 * \param height image height given by the user.
2560 * \param border texture border.
2562 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2564 * Verifies each of the parameters against the constants specified in
2565 * __struct gl_contextRec::Const and the supported extensions, and according
2566 * to the OpenGL specification.
2569 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2570 GLenum target
, GLint level
, GLint internalFormat
,
2571 GLint width
, GLint height
, GLint border
)
2574 GLint rb_base_format
;
2575 struct gl_renderbuffer
*rb
;
2576 GLenum rb_internal_format
;
2579 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2580 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2581 dimensions
, _mesa_lookup_enum_by_nr(target
));
2586 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2587 _mesa_error(ctx
, GL_INVALID_VALUE
,
2588 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2592 /* Check that the source buffer is complete */
2593 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2594 if (ctx
->ReadBuffer
->_Status
== 0) {
2595 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2597 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2598 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2599 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2603 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2604 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2605 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2611 if (border
< 0 || border
> 1 ||
2612 ((ctx
->API
!= API_OPENGL_COMPAT
||
2613 target
== GL_TEXTURE_RECTANGLE_NV
||
2614 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2615 _mesa_error(ctx
, GL_INVALID_VALUE
,
2616 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2620 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2622 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2623 "glCopyTexImage%dD(read buffer)", dimensions
);
2627 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2630 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2631 switch (internalFormat
) {
2636 case GL_LUMINANCE_ALPHA
:
2639 _mesa_error(ctx
, GL_INVALID_VALUE
,
2640 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2641 _mesa_lookup_enum_by_nr(internalFormat
));
2646 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2647 if (baseFormat
< 0) {
2648 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2649 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2650 _mesa_lookup_enum_by_nr(internalFormat
));
2654 rb_internal_format
= rb
->InternalFormat
;
2655 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2656 if (_mesa_is_color_format(internalFormat
)) {
2657 if (rb_base_format
< 0) {
2658 _mesa_error(ctx
, GL_INVALID_VALUE
,
2659 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2660 _mesa_lookup_enum_by_nr(internalFormat
));
2665 if (_mesa_is_gles(ctx
)) {
2667 if (_mesa_base_format_component_count(baseFormat
) >
2668 _mesa_base_format_component_count(rb_base_format
)) {
2671 if (baseFormat
== GL_DEPTH_COMPONENT
||
2672 baseFormat
== GL_DEPTH_STENCIL
||
2673 rb_base_format
== GL_DEPTH_COMPONENT
||
2674 rb_base_format
== GL_DEPTH_STENCIL
||
2675 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2676 baseFormat
== GL_ALPHA
) &&
2677 rb_base_format
!= GL_RGBA
) ||
2678 internalFormat
== GL_RGB9_E5
) {
2681 if (internalFormat
== GL_RGB9_E5
) {
2685 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2686 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2687 _mesa_lookup_enum_by_nr(internalFormat
));
2692 if (_mesa_is_gles3(ctx
)) {
2693 bool rb_is_srgb
= false;
2694 bool dst_is_srgb
= false;
2696 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2697 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2701 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2705 if (rb_is_srgb
!= dst_is_srgb
) {
2706 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2707 * OpenGLES 3.0.0 spec says:
2709 * "The error INVALID_OPERATION is also generated if the
2710 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2711 * framebuffer attachment corresponding to the read buffer
2712 * is LINEAR (see section 6.1.13) and internalformat is
2713 * one of the sRGB formats described in section 3.8.16, or
2714 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2715 * SRGB and internalformat is not one of the sRGB formats."
2717 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2718 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2722 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2723 * types for SNORM formats. Also, conversion to SNORM formats is not
2724 * allowed by Table 3.2 on Page 110.
2726 if(_mesa_is_enum_format_snorm(internalFormat
)) {
2727 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2728 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2729 _mesa_lookup_enum_by_nr(internalFormat
));
2734 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2735 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2736 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2740 /* From the EXT_texture_integer spec:
2742 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2743 * if the texture internalformat is an integer format and the read color
2744 * buffer is not an integer format, or if the internalformat is not an
2745 * integer format and the read color buffer is an integer format."
2747 if (_mesa_is_color_format(internalFormat
)) {
2748 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2749 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2750 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2751 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2752 if (is_int
|| is_rbint
) {
2753 if (is_int
!= is_rbint
) {
2754 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2755 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2757 } else if (_mesa_is_gles(ctx
) &&
2758 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2759 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2760 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2761 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2766 /* From page 138 of OpenGL ES 3.0 spec:
2767 * "The error INVALID_OPERATION is generated if floating-point RGBA
2768 * data is required; if signed integer RGBA data is required and the
2769 * format of the current color buffer is not signed integer; if
2770 * unsigned integer RGBA data is required and the format of the
2771 * current color buffer is not unsigned integer; or if fixed-point
2772 * RGBA data is required and the format of the current color buffer
2773 * is not fixed-point.
2775 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2776 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2777 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2780 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2781 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2782 _mesa_error(ctx
, GL_INVALID_ENUM
,
2783 "glCopyTexImage%dD(target)", dimensions
);
2786 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2787 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2788 "glCopyTexImage%dD(no compression for format)", dimensions
);
2792 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2793 "glCopyTexImage%dD(border!=0)", dimensions
);
2798 if (!mutable_tex_object(ctx
, target
)) {
2799 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2800 "glCopyTexImage%dD(immutable texture)", dimensions
);
2804 /* if we get here, the parameters are OK */
2810 * Test glCopyTexSubImage[12]D() parameters for errors.
2811 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2814 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2815 const struct gl_texture_object
*texObj
,
2816 GLenum target
, GLint level
,
2817 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2818 GLint width
, GLint height
, bool dsa
)
2820 struct gl_texture_image
*texImage
;
2821 const char *suffix
= dsa
? "ture" : "";
2823 /* Check that the source buffer is complete */
2824 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2825 if (ctx
->ReadBuffer
->_Status
== 0) {
2826 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2828 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2829 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2830 "glCopyTex%sSubImage%dD(invalid readbuffer)",
2831 suffix
, dimensions
);
2835 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2836 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2837 "glCopyTex%sSubImage%dD(multisample FBO)", suffix
,
2844 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2845 _mesa_error(ctx
, GL_INVALID_VALUE
,
2846 "glCopyTex%sSubImage%dD(level=%d)", suffix
,
2851 /* Get dest image pointers */
2853 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTex%sSubImage%dD()",
2854 suffix
, dimensions
);
2858 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2860 /* destination image does not exist */
2861 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2862 "glCopyTex%sSubImage%dD(invalid texture image)",
2863 suffix
, dimensions
);
2867 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2868 xoffset
, yoffset
, zoffset
,
2869 width
, height
, 1, dsa
?
2870 "glCompressedTextureSubImage" :
2871 "glCompressedTexSubImage")) {
2875 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2876 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2877 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2878 "glCopyTex%sSubImage%dD(no compression for format)",
2879 suffix
, dimensions
);
2884 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2885 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTex%sSubImage2D", suffix
);
2889 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2890 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2891 "glCopyTex%sSubImage%dD(missing readbuffer, format=0x%x)",
2892 suffix
, dimensions
, texImage
->_BaseFormat
);
2896 /* From the EXT_texture_integer spec:
2898 * "INVALID_OPERATION is generated by CopyTexImage* and
2899 * CopyTexSubImage* if the texture internalformat is an integer format
2900 * and the read color buffer is not an integer format, or if the
2901 * internalformat is not an integer format and the read color buffer
2902 * is an integer format."
2904 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2905 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2907 if (_mesa_is_format_integer_color(rb
->Format
) !=
2908 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2909 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2910 "glCopyTex%sSubImage%dD(integer vs non-integer)",
2911 suffix
, dimensions
);
2916 /* if we get here, the parameters are OK */
2921 /** Callback info for walking over FBO hash table */
2924 struct gl_context
*ctx
;
2925 struct gl_texture_object
*texObj
;
2931 * Check render to texture callback. Called from _mesa_HashWalk().
2934 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2936 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2937 const struct cb_info
*info
= (struct cb_info
*) userData
;
2938 struct gl_context
*ctx
= info
->ctx
;
2939 const struct gl_texture_object
*texObj
= info
->texObj
;
2940 const GLuint level
= info
->level
, face
= info
->face
;
2942 /* If this is a user-created FBO */
2943 if (_mesa_is_user_fbo(fb
)) {
2945 /* check if any of the FBO's attachments point to 'texObj' */
2946 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2947 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2948 if (att
->Type
== GL_TEXTURE
&&
2949 att
->Texture
== texObj
&&
2950 att
->TextureLevel
== level
&&
2951 att
->CubeMapFace
== face
) {
2952 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2953 assert(att
->Renderbuffer
->TexImage
);
2954 /* Mark fb status as indeterminate to force re-validation */
2963 * When a texture image is specified we have to check if it's bound to
2964 * any framebuffer objects (render to texture) in order to detect changes
2965 * in size or format since that effects FBO completeness.
2966 * Any FBOs rendering into the texture must be re-validated.
2969 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2970 struct gl_texture_object
*texObj
,
2971 GLuint face
, GLuint level
)
2973 /* Only check this texture if it's been marked as RenderToTexture */
2974 if (texObj
->_RenderToTexture
) {
2975 struct cb_info info
;
2977 info
.texObj
= texObj
;
2980 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2986 * If the texture object's GenerateMipmap flag is set and we've
2987 * changed the texture base level image, regenerate the rest of the
2988 * mipmap levels now.
2991 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2992 struct gl_texture_object
*texObj
, GLint level
)
2994 if (texObj
->GenerateMipmap
&&
2995 level
== texObj
->BaseLevel
&&
2996 level
< texObj
->MaxLevel
) {
2997 assert(ctx
->Driver
.GenerateMipmap
);
2998 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3003 /** Debug helper: override the user-requested internal format */
3005 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
3008 if (internalFormat
== GL_RGBA16F_ARB
||
3009 internalFormat
== GL_RGBA32F_ARB
) {
3010 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3013 else if (internalFormat
== GL_RGB16F_ARB
||
3014 internalFormat
== GL_RGB32F_ARB
) {
3015 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3018 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3019 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3020 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3021 return GL_LUMINANCE_ALPHA
;
3023 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3024 internalFormat
== GL_LUMINANCE32F_ARB
) {
3025 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3026 return GL_LUMINANCE
;
3028 else if (internalFormat
== GL_ALPHA16F_ARB
||
3029 internalFormat
== GL_ALPHA32F_ARB
) {
3030 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3034 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3035 internalFormat = GL_RGBA;
3039 return internalFormat
;
3042 return internalFormat
;
3048 * Choose the actual hardware format for a texture image.
3049 * Try to use the same format as the previous image level when possible.
3050 * Otherwise, ask the driver for the best format.
3051 * It's important to try to choose a consistant format for all levels
3052 * for efficient texture memory layout/allocation. In particular, this
3053 * comes up during automatic mipmap generation.
3056 _mesa_choose_texture_format(struct gl_context
*ctx
,
3057 struct gl_texture_object
*texObj
,
3058 GLenum target
, GLint level
,
3059 GLenum internalFormat
, GLenum format
, GLenum type
)
3063 /* see if we've already chosen a format for the previous level */
3065 struct gl_texture_image
*prevImage
=
3066 _mesa_select_tex_image(texObj
, target
, level
- 1);
3067 /* See if the prev level is defined and has an internal format which
3068 * matches the new internal format.
3071 prevImage
->Width
> 0 &&
3072 prevImage
->InternalFormat
== internalFormat
) {
3073 /* use the same format */
3074 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3075 return prevImage
->TexFormat
;
3079 /* If the application requested compression to an S3TC format but we don't
3080 * have the DXTn library, force a generic compressed format instead.
3082 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3083 const GLenum before
= internalFormat
;
3085 switch (internalFormat
) {
3086 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3087 if (!ctx
->Mesa_DXTn
)
3088 internalFormat
= GL_COMPRESSED_RGB
;
3090 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3091 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3092 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3093 if (!ctx
->Mesa_DXTn
)
3094 internalFormat
= GL_COMPRESSED_RGBA
;
3100 if (before
!= internalFormat
) {
3102 "DXT compression requested (%s), "
3103 "but libtxc_dxtn library not installed. Using %s "
3105 _mesa_lookup_enum_by_nr(before
),
3106 _mesa_lookup_enum_by_nr(internalFormat
));
3110 /* choose format from scratch */
3111 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3113 assert(f
!= MESA_FORMAT_NONE
);
3119 * Adjust pixel unpack params and image dimensions to strip off the
3120 * one-pixel texture border.
3122 * Gallium and intel don't support texture borders. They've seldem been used
3123 * and seldom been implemented correctly anyway.
3125 * \param unpackNew returns the new pixel unpack parameters
3128 strip_texture_border(GLenum target
,
3129 GLint
*width
, GLint
*height
, GLint
*depth
,
3130 const struct gl_pixelstore_attrib
*unpack
,
3131 struct gl_pixelstore_attrib
*unpackNew
)
3137 *unpackNew
= *unpack
;
3139 if (unpackNew
->RowLength
== 0)
3140 unpackNew
->RowLength
= *width
;
3142 if (unpackNew
->ImageHeight
== 0)
3143 unpackNew
->ImageHeight
= *height
;
3145 assert(*width
>= 3);
3146 unpackNew
->SkipPixels
++; /* skip the border */
3147 *width
= *width
- 2; /* reduce the width by two border pixels */
3149 /* The min height of a texture with a border is 3 */
3150 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3151 unpackNew
->SkipRows
++; /* skip the border */
3152 *height
= *height
- 2; /* reduce the height by two border pixels */
3156 target
!= GL_TEXTURE_2D_ARRAY
&&
3157 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3158 unpackNew
->SkipImages
++; /* skip the border */
3159 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3165 * Common code to implement all the glTexImage1D/2D/3D functions
3166 * as well as glCompressedTexImage1D/2D/3D.
3167 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3168 * \param format the user's image format (only used if !compressed)
3169 * \param type the user's image type (only used if !compressed)
3170 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3173 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3174 GLenum target
, GLint level
, GLint internalFormat
,
3175 GLsizei width
, GLsizei height
, GLsizei depth
,
3176 GLint border
, GLenum format
, GLenum type
,
3177 GLsizei imageSize
, const GLvoid
*pixels
)
3179 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3180 struct gl_pixelstore_attrib unpack_no_border
;
3181 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3182 struct gl_texture_object
*texObj
;
3183 mesa_format texFormat
;
3184 GLboolean dimensionsOK
, sizeOK
;
3186 FLUSH_VERTICES(ctx
, 0);
3188 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3191 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3193 _mesa_lookup_enum_by_nr(target
), level
,
3194 _mesa_lookup_enum_by_nr(internalFormat
),
3195 width
, height
, depth
, border
, pixels
);
3198 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3200 _mesa_lookup_enum_by_nr(target
), level
,
3201 _mesa_lookup_enum_by_nr(internalFormat
),
3202 width
, height
, depth
, border
,
3203 _mesa_lookup_enum_by_nr(format
),
3204 _mesa_lookup_enum_by_nr(type
), pixels
);
3207 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3209 /* target error checking */
3210 if (!legal_teximage_target(ctx
, dims
, target
)) {
3211 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3212 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3216 /* general error checking */
3218 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3220 width
, height
, depth
,
3225 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3226 format
, type
, width
, height
, depth
, border
))
3230 /* Here we convert a cpal compressed image into a regular glTexImage2D
3231 * call by decompressing the texture. If we really want to support cpal
3232 * textures in any driver this would have to be changed.
3234 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3235 switch (internalFormat
) {
3236 case GL_PALETTE4_RGB8_OES
:
3237 case GL_PALETTE4_RGBA8_OES
:
3238 case GL_PALETTE4_R5_G6_B5_OES
:
3239 case GL_PALETTE4_RGBA4_OES
:
3240 case GL_PALETTE4_RGB5_A1_OES
:
3241 case GL_PALETTE8_RGB8_OES
:
3242 case GL_PALETTE8_RGBA8_OES
:
3243 case GL_PALETTE8_R5_G6_B5_OES
:
3244 case GL_PALETTE8_RGBA4_OES
:
3245 case GL_PALETTE8_RGB5_A1_OES
:
3246 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3247 width
, height
, imageSize
, pixels
);
3252 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3256 /* For glCompressedTexImage() the driver has no choice about the
3257 * texture format since we'll never transcode the user's compressed
3258 * image data. The internalFormat was error checked earlier.
3260 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3263 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3264 * internal floating point format for the given base format.
3266 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3267 if (type
== GL_FLOAT
) {
3268 texObj
->_IsFloat
= GL_TRUE
;
3269 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3270 texObj
->_IsHalfFloat
= GL_TRUE
;
3273 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3276 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3277 internalFormat
, format
, type
);
3280 assert(texFormat
!= MESA_FORMAT_NONE
);
3282 /* check that width, height, depth are legal for the mipmap level */
3283 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3284 height
, depth
, border
);
3286 /* check that the texture won't take too much memory, etc */
3287 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3289 width
, height
, depth
, border
);
3291 if (_mesa_is_proxy_texture(target
)) {
3292 /* Proxy texture: just clear or set state depending on error checking */
3293 struct gl_texture_image
*texImage
=
3294 get_proxy_tex_image(ctx
, target
, level
);
3297 return; /* GL_OUT_OF_MEMORY already recorded */
3299 if (dimensionsOK
&& sizeOK
) {
3300 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3301 border
, internalFormat
, texFormat
);
3304 clear_teximage_fields(texImage
);
3308 /* non-proxy target */
3309 const GLuint face
= _mesa_tex_target_to_face(target
);
3310 struct gl_texture_image
*texImage
;
3312 if (!dimensionsOK
) {
3313 _mesa_error(ctx
, GL_INVALID_VALUE
,
3314 "glTexImage%uD(invalid width or height or depth)",
3320 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3321 "glTexImage%uD(image too large)", dims
);
3325 /* Allow a hardware driver to just strip out the border, to provide
3326 * reliable but slightly incorrect hardware rendering instead of
3327 * rarely-tested software fallback rendering.
3329 if (border
&& ctx
->Const
.StripTextureBorder
) {
3330 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3333 unpack
= &unpack_no_border
;
3336 if (ctx
->NewState
& _NEW_PIXEL
)
3337 _mesa_update_state(ctx
);
3339 _mesa_lock_texture(ctx
, texObj
);
3341 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3344 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3347 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3349 _mesa_init_teximage_fields(ctx
, texImage
,
3350 width
, height
, depth
,
3351 border
, internalFormat
, texFormat
);
3353 /* Give the texture to the driver. <pixels> may be null. */
3354 if (width
> 0 && height
> 0 && depth
> 0) {
3356 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3360 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3361 type
, pixels
, unpack
);
3365 check_gen_mipmap(ctx
, target
, texObj
, level
);
3367 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3369 _mesa_dirty_texobj(ctx
, texObj
);
3372 _mesa_unlock_texture(ctx
, texObj
);
3379 * Called from the API. Note that width includes the border.
3382 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3383 GLsizei width
, GLint border
, GLenum format
,
3384 GLenum type
, const GLvoid
*pixels
)
3386 GET_CURRENT_CONTEXT(ctx
);
3387 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3388 border
, format
, type
, 0, pixels
);
3393 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3394 GLsizei width
, GLsizei height
, GLint border
,
3395 GLenum format
, GLenum type
,
3396 const GLvoid
*pixels
)
3398 GET_CURRENT_CONTEXT(ctx
);
3399 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3400 border
, format
, type
, 0, pixels
);
3405 * Called by the API or display list executor.
3406 * Note that width and height include the border.
3409 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3410 GLsizei width
, GLsizei height
, GLsizei depth
,
3411 GLint border
, GLenum format
, GLenum type
,
3412 const GLvoid
*pixels
)
3414 GET_CURRENT_CONTEXT(ctx
);
3415 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3416 width
, height
, depth
,
3417 border
, format
, type
, 0, pixels
);
3422 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3423 GLsizei width
, GLsizei height
, GLsizei depth
,
3424 GLint border
, GLenum format
, GLenum type
,
3425 const GLvoid
*pixels
)
3427 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3428 depth
, border
, format
, type
, pixels
);
3433 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3435 struct gl_texture_object
*texObj
;
3436 struct gl_texture_image
*texImage
;
3438 GET_CURRENT_CONTEXT(ctx
);
3439 FLUSH_VERTICES(ctx
, 0);
3443 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3445 case GL_TEXTURE_EXTERNAL_OES
:
3447 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3450 valid_target
= false;
3454 if (!valid_target
) {
3455 _mesa_error(ctx
, GL_INVALID_ENUM
,
3456 "glEGLImageTargetTexture2D(target=%d)", target
);
3461 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3462 "glEGLImageTargetTexture2D(image=%p)", image
);
3466 if (ctx
->NewState
& _NEW_PIXEL
)
3467 _mesa_update_state(ctx
);
3469 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3473 _mesa_lock_texture(ctx
, texObj
);
3475 if (texObj
->Immutable
) {
3476 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3477 "glEGLImageTargetTexture2D(texture is immutable)");
3478 _mesa_unlock_texture(ctx
, texObj
);
3482 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3484 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3486 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3488 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3489 texObj
, texImage
, image
);
3491 _mesa_dirty_texobj(ctx
, texObj
);
3493 _mesa_unlock_texture(ctx
, texObj
);
3499 * Helper that implements the glTexSubImage1/2/3D()
3500 * and glTextureSubImage1/2/3D() functions.
3503 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3504 struct gl_texture_object
*texObj
,
3505 struct gl_texture_image
*texImage
,
3506 GLenum target
, GLint level
,
3507 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3508 GLsizei width
, GLsizei height
, GLsizei depth
,
3509 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3512 FLUSH_VERTICES(ctx
, 0);
3514 /* check target (proxies not allowed) */
3515 if (!legal_texsubimage_target(ctx
, dims
, target
, dsa
)) {
3516 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sSubImage%uD(target=%s)",
3518 dims
, _mesa_lookup_enum_by_nr(target
));
3522 if (ctx
->NewState
& _NEW_PIXEL
)
3523 _mesa_update_state(ctx
);
3525 _mesa_lock_texture(ctx
, texObj
);
3527 if (width
> 0 && height
> 0 && depth
> 0) {
3528 /* If we have a border, offset=-1 is legal. Bias by border width. */
3531 if (target
!= GL_TEXTURE_2D_ARRAY
)
3532 zoffset
+= texImage
->Border
;
3535 if (target
!= GL_TEXTURE_1D_ARRAY
)
3536 yoffset
+= texImage
->Border
;
3539 xoffset
+= texImage
->Border
;
3542 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3543 xoffset
, yoffset
, zoffset
,
3544 width
, height
, depth
,
3545 format
, type
, pixels
, &ctx
->Unpack
);
3547 check_gen_mipmap(ctx
, target
, texObj
, level
);
3549 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3550 * the texel data, not the texture format, size, etc.
3554 _mesa_unlock_texture(ctx
, texObj
);
3558 * Implement all the glTexSubImage1/2/3D() functions.
3559 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3562 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3563 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3564 GLsizei width
, GLsizei height
, GLsizei depth
,
3565 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3567 struct gl_texture_object
*texObj
;
3568 struct gl_texture_image
*texImage
;
3570 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3574 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3575 xoffset
, yoffset
, zoffset
,
3576 width
, height
, depth
, format
, type
, false)) {
3577 return; /* error was detected */
3580 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3581 /* texsubimage_error_check ensures that texImage is not NULL */
3583 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3584 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3586 _mesa_lookup_enum_by_nr(target
), level
,
3587 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3588 _mesa_lookup_enum_by_nr(format
),
3589 _mesa_lookup_enum_by_nr(type
), pixels
);
3591 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3592 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3593 format
, type
, pixels
, false);
3598 * Implement all the glTextureSubImage1/2/3D() functions.
3599 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3602 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3603 GLuint texture
, GLint level
,
3604 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3605 GLsizei width
, GLsizei height
, GLsizei depth
,
3606 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3608 struct gl_texture_object
*texObj
;
3609 struct gl_texture_image
*texImage
;
3612 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3614 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3615 dims
, texture
, level
,
3616 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3617 _mesa_lookup_enum_by_nr(format
),
3618 _mesa_lookup_enum_by_nr(type
), pixels
);
3620 /* Get the texture object by Name. */
3621 texObj
= _mesa_lookup_texture(ctx
, texture
);
3623 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3628 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3629 xoffset
, yoffset
, zoffset
,
3630 width
, height
, depth
, format
, type
, true)) {
3631 return; /* error was detected */
3635 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3636 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3640 * What do we do if the user created a texture with the following code
3641 * and then called this function with its handle?
3644 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3645 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3646 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3647 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3648 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3649 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3650 * // wrong format, or given the wrong size, etc.
3651 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3652 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3654 * A bug has been filed against the spec for this case. In the
3655 * meantime, we will check for cube completeness.
3657 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3658 * Core Profile spec (30.10.2014):
3659 * "[A] cube map texture is cube complete if the
3660 * following conditions all hold true: The [base level] texture
3661 * images of each of the six cube map faces have identical, positive,
3662 * and square dimensions. The [base level] images were each specified
3663 * with the same internal format."
3665 * It seems reasonable to check for cube completeness of an arbitrary
3666 * level here so that the image data has a consistent format and size.
3668 if (!_mesa_cube_level_complete(texObj
, level
)) {
3669 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3670 "glTextureSubImage%uD(cube map incomplete)",
3675 rowStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3677 /* Copy in each face. */
3678 for (i
= 0; i
< 6; ++i
) {
3679 texImage
= texObj
->Image
[i
][level
];
3682 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3683 level
, xoffset
, yoffset
, zoffset
,
3684 width
, height
, 1, format
,
3685 type
, pixels
, true);
3686 pixels
= (GLubyte
*) pixels
+ rowStride
;
3690 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3693 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3694 level
, xoffset
, yoffset
, zoffset
,
3695 width
, height
, depth
, format
,
3696 type
, pixels
, true);
3702 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3703 GLint xoffset
, GLsizei width
,
3704 GLenum format
, GLenum type
,
3705 const GLvoid
*pixels
)
3707 GET_CURRENT_CONTEXT(ctx
);
3708 texsubimage(ctx
, 1, target
, level
,
3711 format
, type
, pixels
);
3716 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3717 GLint xoffset
, GLint yoffset
,
3718 GLsizei width
, GLsizei height
,
3719 GLenum format
, GLenum type
,
3720 const GLvoid
*pixels
)
3722 GET_CURRENT_CONTEXT(ctx
);
3723 texsubimage(ctx
, 2, target
, level
,
3724 xoffset
, yoffset
, 0,
3726 format
, type
, pixels
);
3732 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3733 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3734 GLsizei width
, GLsizei height
, GLsizei depth
,
3735 GLenum format
, GLenum type
,
3736 const GLvoid
*pixels
)
3738 GET_CURRENT_CONTEXT(ctx
);
3739 texsubimage(ctx
, 3, target
, level
,
3740 xoffset
, yoffset
, zoffset
,
3741 width
, height
, depth
,
3742 format
, type
, pixels
);
3746 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3747 GLint xoffset
, GLsizei width
,
3748 GLenum format
, GLenum type
,
3749 const GLvoid
*pixels
)
3751 GET_CURRENT_CONTEXT(ctx
);
3752 texturesubimage(ctx
, 1, texture
, level
,
3755 format
, type
, pixels
);
3760 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3761 GLint xoffset
, GLint yoffset
,
3762 GLsizei width
, GLsizei height
,
3763 GLenum format
, GLenum type
,
3764 const GLvoid
*pixels
)
3766 GET_CURRENT_CONTEXT(ctx
);
3767 texturesubimage(ctx
, 2, texture
, level
,
3768 xoffset
, yoffset
, 0,
3770 format
, type
, pixels
);
3775 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3776 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3777 GLsizei width
, GLsizei height
, GLsizei depth
,
3778 GLenum format
, GLenum type
,
3779 const GLvoid
*pixels
)
3781 GET_CURRENT_CONTEXT(ctx
);
3782 texturesubimage(ctx
, 3, texture
, level
,
3783 xoffset
, yoffset
, zoffset
,
3784 width
, height
, depth
,
3785 format
, type
, pixels
);
3790 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3791 * from. This depends on whether the texture contains color or depth values.
3793 static struct gl_renderbuffer
*
3794 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3796 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3797 /* reading from depth/stencil buffer */
3798 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3801 /* copying from color buffer */
3802 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3807 copytexsubimage_by_slice(struct gl_context
*ctx
,
3808 struct gl_texture_image
*texImage
,
3810 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3811 struct gl_renderbuffer
*rb
,
3813 GLsizei width
, GLsizei height
)
3815 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3818 /* For 1D arrays, we copy each scanline of the source rectangle into the
3821 assert(zoffset
== 0);
3823 for (slice
= 0; slice
< height
; slice
++) {
3824 assert(yoffset
+ slice
< texImage
->Height
);
3825 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3826 xoffset
, 0, yoffset
+ slice
,
3827 rb
, x
, y
+ slice
, width
, 1);
3830 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3831 xoffset
, yoffset
, zoffset
,
3832 rb
, x
, y
, width
, height
);
3837 formats_differ_in_component_sizes (mesa_format f1
,
3840 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3841 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3842 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3843 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3845 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3846 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3847 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3848 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3850 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3851 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3852 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3853 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3860 * Implement the glCopyTexImage1/2D() functions.
3863 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3864 GLenum target
, GLint level
, GLenum internalFormat
,
3865 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3867 struct gl_texture_object
*texObj
;
3868 struct gl_texture_image
*texImage
;
3869 const GLuint face
= _mesa_tex_target_to_face(target
);
3870 mesa_format texFormat
;
3871 struct gl_renderbuffer
*rb
;
3873 FLUSH_VERTICES(ctx
, 0);
3875 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3876 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3878 _mesa_lookup_enum_by_nr(target
), level
,
3879 _mesa_lookup_enum_by_nr(internalFormat
),
3880 x
, y
, width
, height
, border
);
3882 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3883 _mesa_update_state(ctx
);
3885 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3886 width
, height
, border
))
3889 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3891 _mesa_error(ctx
, GL_INVALID_VALUE
,
3892 "glCopyTexImage%uD(invalid width or height)", dims
);
3896 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3899 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3900 internalFormat
, GL_NONE
, GL_NONE
);
3902 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3904 if (_mesa_is_gles3(ctx
)) {
3905 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3906 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3907 * OpenGL ES 3.0. Khronos bug# 9807.
3909 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3910 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3911 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer and"
3912 " writing to unsized internal format)", dims
);
3916 /* From Page 139 of OpenGL ES 3.0 spec:
3917 * "If internalformat is sized, the internal format of the new texel
3918 * array is internalformat, and this is also the new texel array’s
3919 * effective internal format. If the component sizes of internalformat
3920 * do not exactly match the corresponding component sizes of the source
3921 * buffer’s effective internal format, described below, an
3922 * INVALID_OPERATION error is generated. If internalformat is unsized,
3923 * the internal format of the new texel array is the effective internal
3924 * format of the source buffer, and this is also the new texel array’s
3925 * effective internal format.
3927 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3928 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3929 "glCopyTexImage%uD(componenet size changed in"
3930 " internal format)", dims
);
3935 assert(texFormat
!= MESA_FORMAT_NONE
);
3937 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3939 width
, height
, 1, border
)) {
3940 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3941 "glCopyTexImage%uD(image too large)", dims
);
3945 if (border
&& ctx
->Const
.StripTextureBorder
) {
3947 width
-= border
* 2;
3950 height
-= border
* 2;
3955 _mesa_lock_texture(ctx
, texObj
);
3957 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3960 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3963 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3965 /* Free old texture image */
3966 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3968 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3969 border
, internalFormat
, texFormat
);
3971 if (width
&& height
) {
3972 /* Allocate texture memory (no pixel data yet) */
3973 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3975 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3977 struct gl_renderbuffer
*srcRb
=
3978 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3980 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3982 srcRb
, srcX
, srcY
, width
, height
);
3985 check_gen_mipmap(ctx
, target
, texObj
, level
);
3988 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3990 _mesa_dirty_texobj(ctx
, texObj
);
3993 _mesa_unlock_texture(ctx
, texObj
);
3999 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4000 GLenum internalFormat
,
4002 GLsizei width
, GLint border
)
4004 GET_CURRENT_CONTEXT(ctx
);
4005 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4011 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4012 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4015 GET_CURRENT_CONTEXT(ctx
);
4016 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4017 x
, y
, width
, height
, border
);
4021 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4024 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4025 struct gl_texture_object
*texObj
,
4026 GLenum target
, GLint level
,
4027 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4029 GLsizei width
, GLsizei height
,
4032 struct gl_texture_image
*texImage
;
4034 FLUSH_VERTICES(ctx
, 0);
4036 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4037 _mesa_debug(ctx
, "glCopyTex%sSubImage%uD %s %d %d %d %d %d %d %d %d\n",
4038 dsa
? "ture" : "", dims
,
4039 _mesa_lookup_enum_by_nr(target
),
4040 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4042 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4043 _mesa_update_state(ctx
);
4045 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4046 xoffset
, yoffset
, zoffset
,
4047 width
, height
, dsa
)) {
4051 _mesa_lock_texture(ctx
, texObj
);
4053 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4055 /* If we have a border, offset=-1 is legal. Bias by border width. */
4058 if (target
!= GL_TEXTURE_2D_ARRAY
)
4059 zoffset
+= texImage
->Border
;
4062 if (target
!= GL_TEXTURE_1D_ARRAY
)
4063 yoffset
+= texImage
->Border
;
4066 xoffset
+= texImage
->Border
;
4069 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4071 struct gl_renderbuffer
*srcRb
=
4072 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4074 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4075 xoffset
, yoffset
, zoffset
,
4076 srcRb
, x
, y
, width
, height
);
4078 check_gen_mipmap(ctx
, target
, texObj
, level
);
4080 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4081 * the texel data, not the texture format, size, etc.
4085 _mesa_unlock_texture(ctx
, texObj
);
4089 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4090 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4092 struct gl_texture_object
* texObj
;
4093 GET_CURRENT_CONTEXT(ctx
);
4095 /* Check target (proxies not allowed). Target must be checked prior to
4096 * calling _mesa_get_current_tex_object.
4098 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4099 _mesa_error(ctx
, GL_INVALID_ENUM
,
4100 "glCopyTexSubImage1D(invalid target %s)",
4101 _mesa_lookup_enum_by_nr(target
));
4105 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4109 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4110 x
, y
, width
, 1, false);
4116 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4117 GLint xoffset
, GLint yoffset
,
4118 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4120 struct gl_texture_object
* texObj
;
4121 GET_CURRENT_CONTEXT(ctx
);
4123 /* Check target (proxies not allowed). Target must be checked prior to
4124 * calling _mesa_get_current_tex_object.
4126 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4127 _mesa_error(ctx
, GL_INVALID_ENUM
,
4128 "glCopyTexSubImage2D(invalid target %s)",
4129 _mesa_lookup_enum_by_nr(target
));
4133 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4137 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4138 xoffset
, yoffset
, 0,
4139 x
, y
, width
, height
, false);
4145 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4146 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4147 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4149 struct gl_texture_object
* texObj
;
4150 GET_CURRENT_CONTEXT(ctx
);
4152 /* Check target (proxies not allowed). Target must be checked prior to
4153 * calling _mesa_get_current_tex_object.
4155 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4156 _mesa_error(ctx
, GL_INVALID_ENUM
,
4157 "glCopyTexSubImage3D(invalid target %s)",
4158 _mesa_lookup_enum_by_nr(target
));
4162 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4166 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4167 xoffset
, yoffset
, zoffset
,
4168 x
, y
, width
, height
, false);
4172 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4173 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4175 struct gl_texture_object
* texObj
;
4176 GET_CURRENT_CONTEXT(ctx
);
4178 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage1D");
4182 /* Check target (proxies not allowed). */
4183 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4184 _mesa_error(ctx
, GL_INVALID_ENUM
,
4185 "glCopyTextureSubImage1D(invalid target %s)",
4186 _mesa_lookup_enum_by_nr(texObj
->Target
));
4190 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4191 xoffset
, 0, 0, x
, y
, width
, 1, true);
4195 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4196 GLint xoffset
, GLint yoffset
,
4197 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4199 struct gl_texture_object
* texObj
;
4200 GET_CURRENT_CONTEXT(ctx
);
4202 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage2D");
4206 /* Check target (proxies not allowed). */
4207 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4208 _mesa_error(ctx
, GL_INVALID_ENUM
,
4209 "glCopyTextureSubImage2D(invalid target %s)",
4210 _mesa_lookup_enum_by_nr(texObj
->Target
));
4214 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4215 xoffset
, yoffset
, 0,
4216 x
, y
, width
, height
, true);
4222 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4223 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4224 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4226 struct gl_texture_object
* texObj
;
4227 GET_CURRENT_CONTEXT(ctx
);
4229 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glCopyTextureSubImage3D");
4233 /* Check target (proxies not allowed). */
4234 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4235 _mesa_error(ctx
, GL_INVALID_ENUM
,
4236 "glCopyTextureSubImage3D(invalid target %s)",
4237 _mesa_lookup_enum_by_nr(texObj
->Target
));
4241 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4242 xoffset
, yoffset
, zoffset
,
4243 x
, y
, width
, height
, true);
4247 check_clear_tex_image(struct gl_context
*ctx
,
4248 const char *function
,
4249 struct gl_texture_image
*texImage
,
4250 GLenum format
, GLenum type
,
4252 GLubyte
*clearValue
)
4254 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4255 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4256 GLenum internalFormat
= texImage
->InternalFormat
;
4259 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4260 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4261 "%s(buffer texture)", function
);
4265 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4266 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4267 "%s(compressed texture)", function
);
4271 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4272 if (err
!= GL_NO_ERROR
) {
4273 _mesa_error(ctx
, err
,
4274 "%s(incompatible format = %s, type = %s)",
4276 _mesa_lookup_enum_by_nr(format
),
4277 _mesa_lookup_enum_by_nr(type
));
4281 /* make sure internal format and format basically agree */
4282 if (!texture_formats_agree(internalFormat
, format
)) {
4283 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4284 "%s(incompatible internalFormat = %s, format = %s)",
4286 _mesa_lookup_enum_by_nr(internalFormat
),
4287 _mesa_lookup_enum_by_nr(format
));
4291 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4292 /* both source and dest must be integer-valued, or neither */
4293 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4294 _mesa_is_enum_format_integer(format
)) {
4295 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4296 "%s(integer/non-integer format mismatch)",
4302 if (!_mesa_texstore(ctx
,
4304 texImage
->_BaseFormat
,
4305 texImage
->TexFormat
,
4306 0, /* dstRowStride */
4308 1, 1, 1, /* srcWidth/Height/Depth */
4310 data
? data
: zeroData
,
4311 &ctx
->DefaultPacking
)) {
4312 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4319 static struct gl_texture_object
*
4320 get_tex_obj_for_clear(struct gl_context
*ctx
,
4321 const char *function
,
4324 struct gl_texture_object
*texObj
;
4327 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4331 texObj
= _mesa_lookup_texture(ctx
, texture
);
4333 if (texObj
== NULL
) {
4334 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4338 if (texObj
->Target
== 0) {
4339 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4347 get_tex_images_for_clear(struct gl_context
*ctx
,
4348 const char *function
,
4349 struct gl_texture_object
*texObj
,
4351 struct gl_texture_image
**texImages
)
4356 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4357 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4361 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4362 for (i
= 0; i
< MAX_FACES
; i
++) {
4363 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4365 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4366 if (texImages
[i
] == NULL
) {
4367 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4368 "%s(invalid level)", function
);
4376 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4378 if (texImages
[0] == NULL
) {
4379 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4387 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4388 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4389 GLsizei width
, GLsizei height
, GLsizei depth
,
4390 GLenum format
, GLenum type
, const void *data
)
4392 GET_CURRENT_CONTEXT(ctx
);
4393 struct gl_texture_object
*texObj
;
4394 struct gl_texture_image
*texImages
[MAX_FACES
];
4395 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4397 int minDepth
, maxDepth
;
4399 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4404 _mesa_lock_texture(ctx
, texObj
);
4406 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4407 texObj
, level
, texImages
);
4411 if (numImages
== 1) {
4412 minDepth
= -(int) texImages
[0]->Border
;
4413 maxDepth
= texImages
[0]->Depth
;
4416 maxDepth
= numImages
;
4419 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4420 yoffset
< -(GLint
) texImages
[0]->Border
||
4421 zoffset
< minDepth
||
4425 xoffset
+ width
> texImages
[0]->Width
||
4426 yoffset
+ height
> texImages
[0]->Height
||
4427 zoffset
+ depth
> maxDepth
) {
4428 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4429 "glClearSubTexImage(invalid dimensions)");
4433 if (numImages
== 1) {
4434 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4436 format
, type
, data
, clearValue
[0])) {
4437 ctx
->Driver
.ClearTexSubImage(ctx
,
4439 xoffset
, yoffset
, zoffset
,
4440 width
, height
, depth
,
4441 data
? clearValue
[0] : NULL
);
4444 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4445 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4447 format
, type
, data
, clearValue
[i
]))
4450 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4451 ctx
->Driver
.ClearTexSubImage(ctx
,
4453 xoffset
, yoffset
, 0,
4455 data
? clearValue
[i
] : NULL
);
4460 _mesa_unlock_texture(ctx
, texObj
);
4464 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4465 GLenum format
, GLenum type
, const void *data
)
4467 GET_CURRENT_CONTEXT(ctx
);
4468 struct gl_texture_object
*texObj
;
4469 struct gl_texture_image
*texImages
[MAX_FACES
];
4470 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4473 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4478 _mesa_lock_texture(ctx
, texObj
);
4480 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4481 texObj
, level
, texImages
);
4483 for (i
= 0; i
< numImages
; i
++) {
4484 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4491 for (i
= 0; i
< numImages
; i
++) {
4492 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4493 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4494 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4495 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4496 texImages
[i
]->Width
,
4497 texImages
[i
]->Height
,
4498 texImages
[i
]->Depth
,
4499 data
? clearValue
[i
] : NULL
);
4503 _mesa_unlock_texture(ctx
, texObj
);
4509 /**********************************************************************/
4510 /****** Compressed Textures ******/
4511 /**********************************************************************/
4515 * Target checking for glCompressedTexSubImage[123]D().
4516 * \return GL_TRUE if error, GL_FALSE if no error
4517 * Must come before other error checking so that the texture object can
4518 * be correctly retrieved using _mesa_get_current_tex_object.
4521 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4522 GLint dims
, GLenum format
, bool dsa
,
4527 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4528 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4529 _mesa_lookup_enum_by_nr(target
));
4537 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4538 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4539 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4540 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4541 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4542 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4546 targetOK
= GL_FALSE
;
4551 targetOK
= (target
== GL_TEXTURE_3D
) ||
4552 (target
== GL_TEXTURE_2D_ARRAY
) ||
4553 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
4554 (target
== GL_TEXTURE_CUBE_MAP
&& dsa
);
4556 /* OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4558 * "An INVALID_OPERATION error is generated by
4559 * CompressedTex*SubImage3D if the internal format of the texture is
4560 * one of the EAC, ETC2, or RGTC formats and either border is
4561 * non-zero, or the effective target for the texture is not
4562 * TEXTURE_2D_ARRAY."
4564 if (target
!= GL_TEXTURE_2D_ARRAY
) {
4567 /* These came from _mesa_is_compressed_format in glformats.c. */
4569 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
4570 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
4571 case GL_COMPRESSED_R11_EAC
:
4572 case GL_COMPRESSED_RG11_EAC
:
4573 case GL_COMPRESSED_SIGNED_R11_EAC
:
4574 case GL_COMPRESSED_SIGNED_RG11_EAC
:
4576 case GL_COMPRESSED_RGB8_ETC2
:
4577 case GL_COMPRESSED_SRGB8_ETC2
:
4578 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
4579 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
4581 case GL_COMPRESSED_RED_RGTC1
:
4582 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
4583 case GL_COMPRESSED_RG_RGTC2
:
4584 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
4585 invalidformat
= true;
4588 invalidformat
= false;
4590 if (invalidformat
) {
4591 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4592 "%s(invalid target %s for format %s)", caller
,
4593 _mesa_lookup_enum_by_nr(target
),
4594 _mesa_lookup_enum_by_nr(format
));
4602 /* no 1D compressed textures at this time */
4603 targetOK
= GL_FALSE
;
4608 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4609 _mesa_lookup_enum_by_nr(target
));
4617 * Error checking for glCompressedTexSubImage[123]D().
4618 * \return GL_TRUE if error, GL_FALSE if no error
4621 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4622 const struct gl_texture_object
*texObj
,
4623 GLenum target
, GLint level
,
4624 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4625 GLsizei width
, GLsizei height
, GLsizei depth
,
4626 GLenum format
, GLsizei imageSize
, bool dsa
)
4628 struct gl_texture_image
*texImage
;
4630 const char *suffix
= dsa
? "ture" : "";
4632 /* this will catch any invalid compressed format token */
4633 if (!_mesa_is_compressed_format(ctx
, format
)) {
4634 _mesa_error(ctx
, GL_INVALID_ENUM
,
4635 "glCompressedTex%sSubImage%uD(format)", suffix
, dims
);
4639 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4640 _mesa_error(ctx
, GL_INVALID_VALUE
,
4641 "glCompressedTex%sSubImage%uD(level=%d)",
4642 suffix
, dims
, level
);
4646 /* Check for invalid pixel storage modes */
4647 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4649 dsa
? "glCompressedTextureSubImage" :
4650 "glCompressedTexSubImage")) {
4654 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4655 if (expectedSize
!= imageSize
) {
4656 _mesa_error(ctx
, GL_INVALID_VALUE
,
4657 "glCompressedTex%sSubImage%uD(size=%d)",
4658 suffix
, dims
, imageSize
);
4662 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4664 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4665 "glCompressedTex%sSubImage%uD(invalid texture image)",
4670 if ((GLint
) format
!= texImage
->InternalFormat
) {
4671 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4672 "glCompressedTex%sSubImage%uD(format=0x%x)",
4673 suffix
, dims
, format
);
4677 if (compressedteximage_only_format(ctx
, format
)) {
4678 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4679 "glCompressedTex%sSubImage%uD(format=0x%x cannot be updated)",
4680 suffix
, dims
, format
);
4684 if (error_check_subtexture_dimensions(ctx
, dims
,
4685 texImage
, xoffset
, yoffset
, zoffset
,
4686 width
, height
, depth
,
4687 "glCompressedTexSubImage")) {
4696 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4697 GLenum internalFormat
, GLsizei width
,
4698 GLint border
, GLsizei imageSize
,
4701 GET_CURRENT_CONTEXT(ctx
);
4702 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4703 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4708 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4709 GLenum internalFormat
, GLsizei width
,
4710 GLsizei height
, GLint border
, GLsizei imageSize
,
4713 GET_CURRENT_CONTEXT(ctx
);
4714 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4715 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4720 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4721 GLenum internalFormat
, GLsizei width
,
4722 GLsizei height
, GLsizei depth
, GLint border
,
4723 GLsizei imageSize
, const GLvoid
*data
)
4725 GET_CURRENT_CONTEXT(ctx
);
4726 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4727 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4732 * Common helper for glCompressedTexSubImage1/2/3D() and
4733 * glCompressedTextureSubImage1/2/3D().
4736 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4737 struct gl_texture_object
*texObj
,
4738 struct gl_texture_image
*texImage
,
4739 GLenum target
, GLint level
,
4740 GLint xoffset
, GLint yoffset
,
4742 GLsizei width
, GLsizei height
,
4744 GLenum format
, GLsizei imageSize
,
4747 FLUSH_VERTICES(ctx
, 0);
4749 _mesa_lock_texture(ctx
, texObj
);
4751 if (width
> 0 && height
> 0 && depth
> 0) {
4752 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4753 xoffset
, yoffset
, zoffset
,
4754 width
, height
, depth
,
4755 format
, imageSize
, data
);
4757 check_gen_mipmap(ctx
, target
, texObj
, level
);
4759 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4760 * the texel data, not the texture format, size, etc.
4764 _mesa_unlock_texture(ctx
, texObj
);
4769 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4770 GLsizei width
, GLenum format
,
4771 GLsizei imageSize
, const GLvoid
*data
)
4773 struct gl_texture_object
*texObj
;
4774 struct gl_texture_image
*texImage
;
4776 GET_CURRENT_CONTEXT(ctx
);
4778 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4779 "glCompressedTexSubImage1D")) {
4783 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4787 if (compressed_subtexture_error_check(ctx
, 1, texObj
, target
,
4788 level
, xoffset
, 0, 0,
4790 format
, imageSize
, false)) {
4794 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4797 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
4798 xoffset
, 0, 0, width
, 1, 1,
4799 format
, imageSize
, data
);
4803 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4804 GLsizei width
, GLenum format
,
4805 GLsizei imageSize
, const GLvoid
*data
)
4807 struct gl_texture_object
*texObj
;
4808 struct gl_texture_image
*texImage
;
4810 GET_CURRENT_CONTEXT(ctx
);
4812 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4813 "glCompressedTextureSubImage1D");
4817 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
,
4819 "glCompressedTextureSubImage1D")) {
4823 if (compressed_subtexture_error_check(ctx
, 1, texObj
, texObj
->Target
,
4824 level
, xoffset
, 0, 0,
4826 format
, imageSize
, true)) {
4830 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4833 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
,
4834 texObj
->Target
, level
,
4835 xoffset
, 0, 0, width
, 1, 1,
4836 format
, imageSize
, data
);
4841 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4842 GLint yoffset
, GLsizei width
, GLsizei height
,
4843 GLenum format
, GLsizei imageSize
,
4846 struct gl_texture_object
*texObj
;
4847 struct gl_texture_image
*texImage
;
4849 GET_CURRENT_CONTEXT(ctx
);
4851 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
4852 "glCompressedTexSubImage2D")) {
4856 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4860 if (compressed_subtexture_error_check(ctx
, 2, texObj
, target
,
4861 level
, xoffset
, yoffset
, 0,
4863 format
, imageSize
, false)) {
4868 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4871 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
4872 xoffset
, yoffset
, 0, width
, height
, 1,
4873 format
, imageSize
, data
);
4877 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
4879 GLsizei width
, GLsizei height
,
4880 GLenum format
, GLsizei imageSize
,
4883 struct gl_texture_object
*texObj
;
4884 struct gl_texture_image
*texImage
;
4886 GET_CURRENT_CONTEXT(ctx
);
4888 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4889 "glCompressedTextureSubImage2D");
4893 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
,
4895 "glCompressedTextureSubImage2D")) {
4899 if (compressed_subtexture_error_check(ctx
, 2, texObj
, texObj
->Target
,
4900 level
, xoffset
, yoffset
, 0,
4902 format
, imageSize
, true)) {
4906 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4909 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
,
4910 texObj
->Target
, level
,
4911 xoffset
, yoffset
, 0, width
, height
, 1,
4912 format
, imageSize
, data
);
4916 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4917 GLint yoffset
, GLint zoffset
, GLsizei width
,
4918 GLsizei height
, GLsizei depth
, GLenum format
,
4919 GLsizei imageSize
, const GLvoid
*data
)
4921 struct gl_texture_object
*texObj
;
4922 struct gl_texture_image
*texImage
;
4924 GET_CURRENT_CONTEXT(ctx
);
4926 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
4927 "glCompressedTexSubImage3D")) {
4931 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4935 if (compressed_subtexture_error_check(ctx
, 3, texObj
, target
,
4936 level
, xoffset
, yoffset
, zoffset
,
4937 width
, height
, depth
,
4938 format
, imageSize
, false)) {
4943 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4946 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
4947 xoffset
, yoffset
, zoffset
,
4948 width
, height
, depth
,
4949 format
, imageSize
, data
);
4953 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
4954 GLint yoffset
, GLint zoffset
, GLsizei width
,
4955 GLsizei height
, GLsizei depth
,
4956 GLenum format
, GLsizei imageSize
,
4959 struct gl_texture_object
*texObj
;
4960 struct gl_texture_image
*texImage
;
4962 GET_CURRENT_CONTEXT(ctx
);
4964 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4965 "glCompressedTextureSubImage3D");
4969 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
,
4971 "glCompressedTextureSubImage3D")) {
4975 if (compressed_subtexture_error_check(ctx
, 3, texObj
, texObj
->Target
,
4976 level
, xoffset
, yoffset
, zoffset
,
4977 width
, height
, depth
,
4978 format
, imageSize
, true)) {
4982 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
4983 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4984 const char *pixels
= data
;
4988 /* Make sure the texture object is a proper cube.
4989 * (See texturesubimage in teximage.c for details on why this check is
4992 if (!_mesa_cube_level_complete(texObj
, level
)) {
4993 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4994 "glCompressedTextureSubImage3D(cube map incomplete)");
4998 /* Copy in each face. */
4999 for (i
= 0; i
< 6; ++i
) {
5000 texImage
= texObj
->Image
[i
][level
];
5003 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5004 texObj
->Target
, level
,
5005 xoffset
, yoffset
, zoffset
,
5007 format
, imageSize
, pixels
);
5009 /* Compressed images don't have a client format */
5010 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5012 texImage
->Height
, 1);
5014 pixels
+= image_stride
;
5015 imageSize
-= image_stride
;
5019 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5022 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5023 texObj
->Target
, level
,
5024 xoffset
, yoffset
, zoffset
,
5025 width
, height
, depth
,
5026 format
, imageSize
, data
);
5031 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5033 if (ctx
->API
!= API_OPENGL_CORE
) {
5034 switch (internalFormat
) {
5036 return MESA_FORMAT_A_UNORM8
;
5038 return MESA_FORMAT_A_UNORM16
;
5039 case GL_ALPHA16F_ARB
:
5040 return MESA_FORMAT_A_FLOAT16
;
5041 case GL_ALPHA32F_ARB
:
5042 return MESA_FORMAT_A_FLOAT32
;
5043 case GL_ALPHA8I_EXT
:
5044 return MESA_FORMAT_A_SINT8
;
5045 case GL_ALPHA16I_EXT
:
5046 return MESA_FORMAT_A_SINT16
;
5047 case GL_ALPHA32I_EXT
:
5048 return MESA_FORMAT_A_SINT32
;
5049 case GL_ALPHA8UI_EXT
:
5050 return MESA_FORMAT_A_UINT8
;
5051 case GL_ALPHA16UI_EXT
:
5052 return MESA_FORMAT_A_UINT16
;
5053 case GL_ALPHA32UI_EXT
:
5054 return MESA_FORMAT_A_UINT32
;
5056 return MESA_FORMAT_L_UNORM8
;
5057 case GL_LUMINANCE16
:
5058 return MESA_FORMAT_L_UNORM16
;
5059 case GL_LUMINANCE16F_ARB
:
5060 return MESA_FORMAT_L_FLOAT16
;
5061 case GL_LUMINANCE32F_ARB
:
5062 return MESA_FORMAT_L_FLOAT32
;
5063 case GL_LUMINANCE8I_EXT
:
5064 return MESA_FORMAT_L_SINT8
;
5065 case GL_LUMINANCE16I_EXT
:
5066 return MESA_FORMAT_L_SINT16
;
5067 case GL_LUMINANCE32I_EXT
:
5068 return MESA_FORMAT_L_SINT32
;
5069 case GL_LUMINANCE8UI_EXT
:
5070 return MESA_FORMAT_L_UINT8
;
5071 case GL_LUMINANCE16UI_EXT
:
5072 return MESA_FORMAT_L_UINT16
;
5073 case GL_LUMINANCE32UI_EXT
:
5074 return MESA_FORMAT_L_UINT32
;
5075 case GL_LUMINANCE8_ALPHA8
:
5076 return MESA_FORMAT_L8A8_UNORM
;
5077 case GL_LUMINANCE16_ALPHA16
:
5078 return MESA_FORMAT_L16A16_UNORM
;
5079 case GL_LUMINANCE_ALPHA16F_ARB
:
5080 return MESA_FORMAT_LA_FLOAT16
;
5081 case GL_LUMINANCE_ALPHA32F_ARB
:
5082 return MESA_FORMAT_LA_FLOAT32
;
5083 case GL_LUMINANCE_ALPHA8I_EXT
:
5084 return MESA_FORMAT_LA_SINT8
;
5085 case GL_LUMINANCE_ALPHA16I_EXT
:
5086 return MESA_FORMAT_LA_SINT16
;
5087 case GL_LUMINANCE_ALPHA32I_EXT
:
5088 return MESA_FORMAT_LA_SINT32
;
5089 case GL_LUMINANCE_ALPHA8UI_EXT
:
5090 return MESA_FORMAT_LA_UINT8
;
5091 case GL_LUMINANCE_ALPHA16UI_EXT
:
5092 return MESA_FORMAT_LA_UINT16
;
5093 case GL_LUMINANCE_ALPHA32UI_EXT
:
5094 return MESA_FORMAT_LA_UINT32
;
5096 return MESA_FORMAT_I_UNORM8
;
5097 case GL_INTENSITY16
:
5098 return MESA_FORMAT_I_UNORM16
;
5099 case GL_INTENSITY16F_ARB
:
5100 return MESA_FORMAT_I_FLOAT16
;
5101 case GL_INTENSITY32F_ARB
:
5102 return MESA_FORMAT_I_FLOAT32
;
5103 case GL_INTENSITY8I_EXT
:
5104 return MESA_FORMAT_I_SINT8
;
5105 case GL_INTENSITY16I_EXT
:
5106 return MESA_FORMAT_I_SINT16
;
5107 case GL_INTENSITY32I_EXT
:
5108 return MESA_FORMAT_I_SINT32
;
5109 case GL_INTENSITY8UI_EXT
:
5110 return MESA_FORMAT_I_UINT8
;
5111 case GL_INTENSITY16UI_EXT
:
5112 return MESA_FORMAT_I_UINT16
;
5113 case GL_INTENSITY32UI_EXT
:
5114 return MESA_FORMAT_I_UINT32
;
5120 if (ctx
->API
== API_OPENGL_CORE
&&
5121 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5122 switch (internalFormat
) {
5124 return MESA_FORMAT_RGB_FLOAT32
;
5126 return MESA_FORMAT_RGB_UINT32
;
5128 return MESA_FORMAT_RGB_SINT32
;
5134 switch (internalFormat
) {
5136 return MESA_FORMAT_R8G8B8A8_UNORM
;
5138 return MESA_FORMAT_RGBA_UNORM16
;
5139 case GL_RGBA16F_ARB
:
5140 return MESA_FORMAT_RGBA_FLOAT16
;
5141 case GL_RGBA32F_ARB
:
5142 return MESA_FORMAT_RGBA_FLOAT32
;
5144 return MESA_FORMAT_RGBA_SINT8
;
5145 case GL_RGBA16I_EXT
:
5146 return MESA_FORMAT_RGBA_SINT16
;
5147 case GL_RGBA32I_EXT
:
5148 return MESA_FORMAT_RGBA_SINT32
;
5149 case GL_RGBA8UI_EXT
:
5150 return MESA_FORMAT_RGBA_UINT8
;
5151 case GL_RGBA16UI_EXT
:
5152 return MESA_FORMAT_RGBA_UINT16
;
5153 case GL_RGBA32UI_EXT
:
5154 return MESA_FORMAT_RGBA_UINT32
;
5157 return MESA_FORMAT_R8G8_UNORM
;
5159 return MESA_FORMAT_R16G16_UNORM
;
5161 return MESA_FORMAT_RG_FLOAT16
;
5163 return MESA_FORMAT_RG_FLOAT32
;
5165 return MESA_FORMAT_RG_SINT8
;
5167 return MESA_FORMAT_RG_SINT16
;
5169 return MESA_FORMAT_RG_SINT32
;
5171 return MESA_FORMAT_RG_UINT8
;
5173 return MESA_FORMAT_RG_UINT16
;
5175 return MESA_FORMAT_RG_UINT32
;
5178 return MESA_FORMAT_R_UNORM8
;
5180 return MESA_FORMAT_R_UNORM16
;
5182 return MESA_FORMAT_R_FLOAT16
;
5184 return MESA_FORMAT_R_FLOAT32
;
5186 return MESA_FORMAT_R_SINT8
;
5188 return MESA_FORMAT_R_SINT16
;
5190 return MESA_FORMAT_R_SINT32
;
5192 return MESA_FORMAT_R_UINT8
;
5194 return MESA_FORMAT_R_UINT16
;
5196 return MESA_FORMAT_R_UINT32
;
5199 return MESA_FORMAT_NONE
;
5205 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5206 GLenum internalFormat
)
5208 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5211 if (format
== MESA_FORMAT_NONE
)
5212 return MESA_FORMAT_NONE
;
5214 datatype
= _mesa_get_format_datatype(format
);
5216 /* The GL_ARB_texture_buffer_object spec says:
5218 * "If ARB_texture_float is not supported, references to the
5219 * floating-point internal formats provided by that extension should be
5220 * removed, and such formats may not be passed to TexBufferARB."
5222 * As a result, GL_HALF_FLOAT internal format depends on both
5223 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5225 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5226 !ctx
->Extensions
.ARB_texture_float
)
5227 return MESA_FORMAT_NONE
;
5229 if (!ctx
->Extensions
.ARB_texture_rg
) {
5230 GLenum base_format
= _mesa_get_format_base_format(format
);
5231 if (base_format
== GL_R
|| base_format
== GL_RG
)
5232 return MESA_FORMAT_NONE
;
5235 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5236 GLenum base_format
= _mesa_get_format_base_format(format
);
5237 if (base_format
== GL_RGB
)
5238 return MESA_FORMAT_NONE
;
5245 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5246 struct gl_texture_object
*texObj
,
5247 GLenum internalFormat
,
5248 struct gl_buffer_object
*bufObj
,
5249 GLintptr offset
, GLsizeiptr size
,
5254 /* NOTE: ARB_texture_buffer_object has interactions with
5255 * the compatibility profile that are not implemented.
5257 if (!(ctx
->API
== API_OPENGL_CORE
&&
5258 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5259 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5260 "%s(ARB_texture_buffer_object is not"
5261 " implemented for the compatibility profile)", caller
);
5265 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5266 if (format
== MESA_FORMAT_NONE
) {
5267 _mesa_error(ctx
, GL_INVALID_ENUM
,
5268 "%s(internalFormat 0x%x)", caller
, internalFormat
);
5272 FLUSH_VERTICES(ctx
, 0);
5274 _mesa_lock_texture(ctx
, texObj
);
5276 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5277 texObj
->BufferObjectFormat
= internalFormat
;
5278 texObj
->_BufferObjectFormat
= format
;
5279 texObj
->BufferOffset
= offset
;
5280 texObj
->BufferSize
= size
;
5282 _mesa_unlock_texture(ctx
, texObj
);
5284 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5287 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5292 /** GL_ARB_texture_buffer_object */
5294 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5296 struct gl_texture_object
*texObj
;
5297 struct gl_buffer_object
*bufObj
;
5299 GET_CURRENT_CONTEXT(ctx
);
5301 /* Need to catch this before it gets to _mesa_get_current_tex_object */
5302 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5303 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
5308 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5314 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5318 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5319 buffer
? -1 : 0, "glTexBuffer");
5323 /** GL_ARB_texture_buffer_range */
5325 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5326 GLintptr offset
, GLsizeiptr size
)
5328 struct gl_texture_object
*texObj
;
5329 struct gl_buffer_object
*bufObj
;
5331 GET_CURRENT_CONTEXT(ctx
);
5333 /* Need to catch this before it gets to _mesa_get_current_tex_object */
5334 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5335 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBufferRange(target)");
5339 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
5343 (offset
+ size
) > bufObj
->Size
) {
5344 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
5347 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5348 _mesa_error(ctx
, GL_INVALID_VALUE
,
5349 "glTexBufferRange(invalid offset alignment)");
5352 } else if (buffer
) {
5353 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
5358 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5359 * Textures (PDF page 254):
5360 * "If buffer is zero, then any buffer object attached to the buffer
5361 * texture is detached, the values offset and size are ignored and
5362 * the state for offset and size for the buffer texture are reset to
5369 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5373 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5374 offset
, size
, "glTexBufferRange");
5378 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5380 struct gl_texture_object
*texObj
;
5381 struct gl_buffer_object
*bufObj
;
5383 GET_CURRENT_CONTEXT(ctx
);
5386 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5392 /* Get the texture object by Name. */
5393 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5397 if (texObj
->Target
!= GL_TEXTURE_BUFFER_ARB
) {
5398 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTextureBuffer(target)");
5402 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5403 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5407 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5409 /* Everything that is allowed for renderbuffers,
5410 * except for a base format of GL_STENCIL_INDEX.
5412 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5413 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5417 /** GL_ARB_texture_multisample */
5419 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5422 case GL_TEXTURE_2D_MULTISAMPLE
:
5424 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5425 return dims
== 2 && !dsa
;
5427 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5429 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5430 return dims
== 3 && !dsa
;
5439 _mesa_texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5440 struct gl_texture_object
*texObj
,
5441 GLenum target
, GLsizei samples
,
5442 GLint internalformat
, GLsizei width
,
5443 GLsizei height
, GLsizei depth
,
5444 GLboolean fixedsamplelocations
,
5445 GLboolean immutable
, const char *func
)
5447 struct gl_texture_image
*texImage
;
5448 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5449 mesa_format texFormat
;
5450 GLenum sample_count_error
;
5451 bool dsa
= strstr(func
, "ture") ? true : false;
5453 if (!(ctx
->Extensions
.ARB_texture_multisample
5454 && _mesa_is_desktop_gl(ctx
))) {
5455 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5459 if (!check_multisample_target(dims
, target
, dsa
)) {
5461 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5465 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5470 /* check that the specified internalformat is color/depth/stencil-renderable;
5471 * refer GL3.1 spec 4.4.4
5474 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5475 _mesa_error(ctx
, GL_INVALID_ENUM
,
5476 "%s(internalformat=%s not legal for immutable-format)",
5477 func
, _mesa_lookup_enum_by_nr(internalformat
));
5481 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5482 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5483 "%s(internalformat=%s)",
5484 func
, _mesa_lookup_enum_by_nr(internalformat
));
5488 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5489 internalformat
, samples
);
5490 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5492 /* Page 254 of OpenGL 4.4 spec says:
5493 * "Proxy arrays for two-dimensional multisample and two-dimensional
5494 * multisample array textures are operated on in the same way when
5495 * TexImage2DMultisample is called with target specified as
5496 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5497 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5498 * However, if samples is not supported, then no error is generated.
5500 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5501 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5505 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5506 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5507 "%s(texture object 0)",
5512 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5514 if (texImage
== NULL
) {
5515 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5519 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5520 internalformat
, GL_NONE
, GL_NONE
);
5521 assert(texFormat
!= MESA_FORMAT_NONE
);
5523 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5524 width
, height
, depth
, 0);
5526 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5527 width
, height
, depth
, 0);
5529 if (_mesa_is_proxy_texture(target
)) {
5530 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5531 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5532 internalformat
, texFormat
,
5533 samples
, fixedsamplelocations
);
5536 /* clear all image fields */
5537 clear_teximage_fields(texImage
);
5541 if (!dimensionsOK
) {
5542 _mesa_error(ctx
, GL_INVALID_VALUE
,
5543 "%s(invalid width or height)", func
);
5548 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
5549 "%s(texture too large)", func
);
5553 /* Check if texObj->Immutable is set */
5554 if (texObj
->Immutable
) {
5555 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5559 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5561 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5562 internalformat
, texFormat
,
5563 samples
, fixedsamplelocations
);
5565 if (width
> 0 && height
> 0 && depth
> 0) {
5566 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5567 width
, height
, depth
)) {
5568 /* tidy up the texture image state. strictly speaking,
5569 * we're allowed to just leave this in whatever state we
5570 * like, but being tidy is good.
5572 _mesa_init_teximage_fields(ctx
, texImage
,
5573 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5577 texObj
->Immutable
|= immutable
;
5580 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5583 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5589 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5590 GLenum internalformat
, GLsizei width
,
5591 GLsizei height
, GLboolean fixedsamplelocations
)
5593 struct gl_texture_object
*texObj
;
5594 GET_CURRENT_CONTEXT(ctx
);
5596 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5600 _mesa_texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5601 internalformat
, width
, height
, 1,
5602 fixedsamplelocations
, GL_FALSE
,
5603 "glTexImage2DMultisample");
5608 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5609 GLenum internalformat
, GLsizei width
,
5610 GLsizei height
, GLsizei depth
,
5611 GLboolean fixedsamplelocations
)
5613 struct gl_texture_object
*texObj
;
5614 GET_CURRENT_CONTEXT(ctx
);
5616 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5620 _mesa_texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5621 internalformat
, width
, height
, depth
,
5622 fixedsamplelocations
, GL_FALSE
,
5623 "glTexImage3DMultisample");
5628 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5629 GLenum internalformat
, GLsizei width
,
5630 GLsizei height
, GLboolean fixedsamplelocations
)
5632 struct gl_texture_object
*texObj
;
5633 GET_CURRENT_CONTEXT(ctx
);
5635 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5639 _mesa_texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5640 internalformat
, width
, height
, 1,
5641 fixedsamplelocations
, GL_TRUE
,
5642 "glTexStorage2DMultisample");
5646 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5647 GLenum internalformat
, GLsizei width
,
5648 GLsizei height
, GLsizei depth
,
5649 GLboolean fixedsamplelocations
)
5651 struct gl_texture_object
*texObj
;
5652 GET_CURRENT_CONTEXT(ctx
);
5654 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5658 _mesa_texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5659 internalformat
, width
, height
, depth
,
5660 fixedsamplelocations
, GL_TRUE
,
5661 "glTexStorage3DMultisample");
5665 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5666 GLenum internalformat
, GLsizei width
,
5668 GLboolean fixedsamplelocations
)
5670 struct gl_texture_object
*texObj
;
5671 GET_CURRENT_CONTEXT(ctx
);
5673 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5674 "glTextureStorage2DMultisample");
5678 _mesa_texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5679 internalformat
, width
, height
, 1,
5680 fixedsamplelocations
, GL_TRUE
,
5681 "glTextureStorage2DMultisample");
5685 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5686 GLenum internalformat
, GLsizei width
,
5687 GLsizei height
, GLsizei depth
,
5688 GLboolean fixedsamplelocations
)
5690 struct gl_texture_object
*texObj
;
5691 GET_CURRENT_CONTEXT(ctx
);
5693 /* Get the texture object by Name. */
5694 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5695 "glTextureStorage3DMultisample");
5699 _mesa_texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5700 internalformat
, width
, height
, depth
,
5701 fixedsamplelocations
, GL_TRUE
,
5702 "glTextureStorage3DMultisample");