2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
43 #include "multisample.h"
44 #include "pixelstore.h"
46 #include "texcompress.h"
47 #include "texcompress_cpal.h"
51 #include "texstorage.h"
52 #include "textureview.h"
54 #include "glformats.h"
60 * State changes which we care about for glCopyTex[Sub]Image() calls.
61 * In particular, we care about pixel transfer state and buffer state
62 * (such as glReadBuffer to make sure we read from the right renderbuffer).
64 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
67 * Returns a corresponding internal floating point format for a given base
68 * format as specifed by OES_texture_float. In case of GL_FLOAT, the internal
69 * format needs to be a 32 bit component and in case of GL_HALF_FLOAT_OES it
70 * needs to be a 16 bit component.
72 * For example, given base format GL_RGBA, type GL_Float return GL_RGBA32F_ARB.
75 adjust_for_oes_float_texture(GLenum format
, GLenum type
)
85 return GL_ALPHA32F_ARB
;
87 return GL_LUMINANCE32F_ARB
;
88 case GL_LUMINANCE_ALPHA
:
89 return GL_LUMINANCE_ALPHA32F_ARB
;
95 case GL_HALF_FLOAT_OES
:
102 return GL_ALPHA16F_ARB
;
104 return GL_LUMINANCE16F_ARB
;
105 case GL_LUMINANCE_ALPHA
:
106 return GL_LUMINANCE_ALPHA16F_ARB
;
120 * Return the simple base format for a given internal texture format.
121 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
123 * \param ctx GL context.
124 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
126 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
127 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
129 * This is the format which is used during texture application (i.e. the
130 * texture format and env mode determine the arithmetic used.
133 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
135 switch (internalFormat
) {
141 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
148 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
150 case GL_LUMINANCE_ALPHA
:
151 case GL_LUMINANCE4_ALPHA4
:
152 case GL_LUMINANCE6_ALPHA2
:
153 case GL_LUMINANCE8_ALPHA8
:
154 case GL_LUMINANCE12_ALPHA4
:
155 case GL_LUMINANCE12_ALPHA12
:
156 case GL_LUMINANCE16_ALPHA16
:
157 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
163 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
165 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
176 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
190 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
192 if (_mesa_is_gles(ctx
)) {
193 switch (internalFormat
) {
201 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
202 switch (internalFormat
) {
210 if (ctx
->Extensions
.ARB_depth_texture
) {
211 switch (internalFormat
) {
212 case GL_DEPTH_COMPONENT
:
213 case GL_DEPTH_COMPONENT16
:
214 case GL_DEPTH_COMPONENT24
:
215 case GL_DEPTH_COMPONENT32
:
216 return GL_DEPTH_COMPONENT
;
217 case GL_DEPTH_STENCIL
:
218 case GL_DEPTH24_STENCIL8
:
219 return GL_DEPTH_STENCIL
;
225 if (ctx
->Extensions
.ARB_texture_stencil8
) {
226 switch (internalFormat
) {
227 case GL_STENCIL_INDEX
:
228 case GL_STENCIL_INDEX1
:
229 case GL_STENCIL_INDEX4
:
230 case GL_STENCIL_INDEX8
:
231 case GL_STENCIL_INDEX16
:
232 return GL_STENCIL_INDEX
;
238 switch (internalFormat
) {
239 case GL_COMPRESSED_ALPHA
:
241 case GL_COMPRESSED_LUMINANCE
:
243 case GL_COMPRESSED_LUMINANCE_ALPHA
:
244 return GL_LUMINANCE_ALPHA
;
245 case GL_COMPRESSED_INTENSITY
:
247 case GL_COMPRESSED_RGB
:
249 case GL_COMPRESSED_RGBA
:
255 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
256 switch (internalFormat
) {
257 case GL_COMPRESSED_RGB_FXT1_3DFX
:
259 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
266 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
268 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
269 switch (internalFormat
) {
270 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
272 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
273 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
274 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
281 if (_mesa_is_desktop_gl(ctx
)
282 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
283 switch (internalFormat
) {
295 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
296 if (internalFormat
== GL_YCBCR_MESA
)
297 return GL_YCBCR_MESA
;
300 if (ctx
->Extensions
.ARB_texture_float
) {
301 switch (internalFormat
) {
302 case GL_ALPHA16F_ARB
:
303 case GL_ALPHA32F_ARB
:
311 case GL_INTENSITY16F_ARB
:
312 case GL_INTENSITY32F_ARB
:
314 case GL_LUMINANCE16F_ARB
:
315 case GL_LUMINANCE32F_ARB
:
317 case GL_LUMINANCE_ALPHA16F_ARB
:
318 case GL_LUMINANCE_ALPHA32F_ARB
:
319 return GL_LUMINANCE_ALPHA
;
325 if (ctx
->Extensions
.EXT_texture_snorm
) {
326 switch (internalFormat
) {
341 case GL_RGBA16_SNORM
:
344 case GL_ALPHA8_SNORM
:
345 case GL_ALPHA16_SNORM
:
347 case GL_LUMINANCE_SNORM
:
348 case GL_LUMINANCE8_SNORM
:
349 case GL_LUMINANCE16_SNORM
:
351 case GL_LUMINANCE_ALPHA_SNORM
:
352 case GL_LUMINANCE8_ALPHA8_SNORM
:
353 case GL_LUMINANCE16_ALPHA16_SNORM
:
354 return GL_LUMINANCE_ALPHA
;
355 case GL_INTENSITY_SNORM
:
356 case GL_INTENSITY8_SNORM
:
357 case GL_INTENSITY16_SNORM
:
364 if (ctx
->Extensions
.EXT_texture_sRGB
) {
365 switch (internalFormat
) {
368 case GL_COMPRESSED_SRGB_EXT
:
370 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
371 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
372 case GL_SRGB_ALPHA_EXT
:
373 case GL_SRGB8_ALPHA8_EXT
:
374 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
376 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
377 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
378 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
379 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
380 case GL_SLUMINANCE_ALPHA_EXT
:
381 case GL_SLUMINANCE8_ALPHA8_EXT
:
382 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
383 return GL_LUMINANCE_ALPHA
;
384 case GL_SLUMINANCE_EXT
:
385 case GL_SLUMINANCE8_EXT
:
386 case GL_COMPRESSED_SLUMINANCE_EXT
:
393 if (ctx
->Version
>= 30 ||
394 ctx
->Extensions
.EXT_texture_integer
) {
395 switch (internalFormat
) {
397 case GL_RGBA16UI_EXT
:
398 case GL_RGBA32UI_EXT
:
414 if (ctx
->Extensions
.EXT_texture_integer
) {
415 switch (internalFormat
) {
416 case GL_ALPHA8UI_EXT
:
417 case GL_ALPHA16UI_EXT
:
418 case GL_ALPHA32UI_EXT
:
420 case GL_ALPHA16I_EXT
:
421 case GL_ALPHA32I_EXT
:
423 case GL_INTENSITY8UI_EXT
:
424 case GL_INTENSITY16UI_EXT
:
425 case GL_INTENSITY32UI_EXT
:
426 case GL_INTENSITY8I_EXT
:
427 case GL_INTENSITY16I_EXT
:
428 case GL_INTENSITY32I_EXT
:
430 case GL_LUMINANCE8UI_EXT
:
431 case GL_LUMINANCE16UI_EXT
:
432 case GL_LUMINANCE32UI_EXT
:
433 case GL_LUMINANCE8I_EXT
:
434 case GL_LUMINANCE16I_EXT
:
435 case GL_LUMINANCE32I_EXT
:
437 case GL_LUMINANCE_ALPHA8UI_EXT
:
438 case GL_LUMINANCE_ALPHA16UI_EXT
:
439 case GL_LUMINANCE_ALPHA32UI_EXT
:
440 case GL_LUMINANCE_ALPHA8I_EXT
:
441 case GL_LUMINANCE_ALPHA16I_EXT
:
442 case GL_LUMINANCE_ALPHA32I_EXT
:
443 return GL_LUMINANCE_ALPHA
;
449 if (ctx
->Extensions
.ARB_texture_rg
) {
450 switch (internalFormat
) {
453 if (!ctx
->Extensions
.ARB_texture_float
)
462 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
468 case GL_COMPRESSED_RED
:
473 if (!ctx
->Extensions
.ARB_texture_float
)
482 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
488 case GL_COMPRESSED_RG
:
495 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
496 switch (internalFormat
) {
504 if (ctx
->Extensions
.EXT_packed_float
) {
505 switch (internalFormat
) {
506 case GL_R11F_G11F_B10F_EXT
:
513 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
514 switch (internalFormat
) {
515 case GL_DEPTH_COMPONENT32F
:
516 return GL_DEPTH_COMPONENT
;
517 case GL_DEPTH32F_STENCIL8
:
518 return GL_DEPTH_STENCIL
;
524 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
525 switch (internalFormat
) {
526 case GL_COMPRESSED_RED_RGTC1
:
527 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
529 case GL_COMPRESSED_RG_RGTC2
:
530 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
537 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
538 switch (internalFormat
) {
539 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
540 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
542 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
543 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
544 return GL_LUMINANCE_ALPHA
;
550 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
551 switch (internalFormat
) {
552 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
553 return GL_LUMINANCE_ALPHA
;
559 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
560 switch (internalFormat
) {
561 case GL_ETC1_RGB8_OES
:
568 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
569 switch (internalFormat
) {
570 case GL_COMPRESSED_RGB8_ETC2
:
571 case GL_COMPRESSED_SRGB8_ETC2
:
573 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
574 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
575 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
576 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
578 case GL_COMPRESSED_R11_EAC
:
579 case GL_COMPRESSED_SIGNED_R11_EAC
:
581 case GL_COMPRESSED_RG11_EAC
:
582 case GL_COMPRESSED_SIGNED_RG11_EAC
:
589 if (_mesa_is_desktop_gl(ctx
) &&
590 ctx
->Extensions
.ARB_texture_compression_bptc
) {
591 switch (internalFormat
) {
592 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
593 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
595 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
596 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
603 if (ctx
->API
== API_OPENGLES
) {
604 switch (internalFormat
) {
605 case GL_PALETTE4_RGB8_OES
:
606 case GL_PALETTE4_R5_G6_B5_OES
:
607 case GL_PALETTE8_RGB8_OES
:
608 case GL_PALETTE8_R5_G6_B5_OES
:
610 case GL_PALETTE4_RGBA8_OES
:
611 case GL_PALETTE8_RGB5_A1_OES
:
612 case GL_PALETTE4_RGBA4_OES
:
613 case GL_PALETTE4_RGB5_A1_OES
:
614 case GL_PALETTE8_RGBA8_OES
:
615 case GL_PALETTE8_RGBA4_OES
:
622 return -1; /* error */
627 * For cube map faces, return a face index in [0,5].
628 * For other targets return 0;
631 _mesa_tex_target_to_face(GLenum target
)
633 if (_mesa_is_cube_face(target
))
634 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
642 * Install gl_texture_image in a gl_texture_object according to the target
643 * and level parameters.
645 * \param tObj texture object.
646 * \param target texture target.
647 * \param level image level.
648 * \param texImage texture image.
651 set_tex_image(struct gl_texture_object
*tObj
,
652 GLenum target
, GLint level
,
653 struct gl_texture_image
*texImage
)
655 const GLuint face
= _mesa_tex_target_to_face(target
);
659 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
662 tObj
->Image
[face
][level
] = texImage
;
664 /* Set the 'back' pointer */
665 texImage
->TexObject
= tObj
;
666 texImage
->Level
= level
;
667 texImage
->Face
= face
;
672 * Allocate a texture image structure.
674 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
677 * \return a pointer to gl_texture_image struct with all fields initialized to
680 struct gl_texture_image
*
681 _mesa_new_texture_image( struct gl_context
*ctx
)
684 return CALLOC_STRUCT(gl_texture_image
);
689 * Free a gl_texture_image and associated data.
690 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
692 * \param texImage texture image.
694 * Free the texture image structure and the associated image data.
697 _mesa_delete_texture_image(struct gl_context
*ctx
,
698 struct gl_texture_image
*texImage
)
700 /* Free texImage->Data and/or any other driver-specific texture
703 assert(ctx
->Driver
.FreeTextureImageBuffer
);
704 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
710 * Test if a target is a proxy target.
712 * \param target texture target.
714 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
717 _mesa_is_proxy_texture(GLenum target
)
720 static const GLenum targets
[] = {
724 GL_PROXY_TEXTURE_CUBE_MAP
,
725 GL_PROXY_TEXTURE_RECTANGLE
,
726 GL_PROXY_TEXTURE_1D_ARRAY
,
727 GL_PROXY_TEXTURE_2D_ARRAY
,
728 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
729 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
730 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
733 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
734 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
736 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== ARRAY_SIZE(targets
) + 2);
738 for (i
= 0; i
< ARRAY_SIZE(targets
); ++i
)
739 if (target
== targets
[i
])
746 * Test if a target is an array target.
748 * \param target texture target.
750 * \return true if the target is an array target, false otherwise.
753 _mesa_is_array_texture(GLenum target
)
756 case GL_TEXTURE_1D_ARRAY
:
757 case GL_TEXTURE_2D_ARRAY
:
758 case GL_TEXTURE_CUBE_MAP_ARRAY
:
759 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
768 * Return the proxy target which corresponds to the given texture target
771 proxy_target(GLenum target
)
775 case GL_PROXY_TEXTURE_1D
:
776 return GL_PROXY_TEXTURE_1D
;
778 case GL_PROXY_TEXTURE_2D
:
779 return GL_PROXY_TEXTURE_2D
;
781 case GL_PROXY_TEXTURE_3D
:
782 return GL_PROXY_TEXTURE_3D
;
783 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
784 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
785 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
786 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
787 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
788 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
789 case GL_TEXTURE_CUBE_MAP_ARB
:
790 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
791 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
792 case GL_TEXTURE_RECTANGLE_NV
:
793 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
794 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
795 case GL_TEXTURE_1D_ARRAY_EXT
:
796 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
797 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
798 case GL_TEXTURE_2D_ARRAY_EXT
:
799 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
800 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
801 case GL_TEXTURE_CUBE_MAP_ARRAY
:
802 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
803 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
804 case GL_TEXTURE_2D_MULTISAMPLE
:
805 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
806 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
807 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
808 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
809 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
811 _mesa_problem(NULL
, "unexpected target in proxy_target()");
820 * Get a texture image pointer from a texture object, given a texture
821 * target and mipmap level. The target and level parameters should
822 * have already been error-checked.
824 * \param texObj texture unit.
825 * \param target texture target.
826 * \param level image level.
828 * \return pointer to the texture image structure, or NULL on failure.
830 struct gl_texture_image
*
831 _mesa_select_tex_image(const struct gl_texture_object
*texObj
,
832 GLenum target
, GLint level
)
834 const GLuint face
= _mesa_tex_target_to_face(target
);
838 assert(level
< MAX_TEXTURE_LEVELS
);
840 return texObj
->Image
[face
][level
];
845 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
846 * it and install it. Only return NULL if passed a bad parameter or run
849 struct gl_texture_image
*
850 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
851 GLenum target
, GLint level
)
853 struct gl_texture_image
*texImage
;
858 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
860 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
862 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
866 set_tex_image(texObj
, target
, level
, texImage
);
874 * Return pointer to the specified proxy texture image.
875 * Note that proxy textures are per-context, not per-texture unit.
876 * \return pointer to texture image or NULL if invalid target, invalid
877 * level, or out of memory.
879 static struct gl_texture_image
*
880 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
882 struct gl_texture_image
*texImage
;
889 case GL_PROXY_TEXTURE_1D
:
890 if (level
>= ctx
->Const
.MaxTextureLevels
)
892 texIndex
= TEXTURE_1D_INDEX
;
894 case GL_PROXY_TEXTURE_2D
:
895 if (level
>= ctx
->Const
.MaxTextureLevels
)
897 texIndex
= TEXTURE_2D_INDEX
;
899 case GL_PROXY_TEXTURE_3D
:
900 if (level
>= ctx
->Const
.Max3DTextureLevels
)
902 texIndex
= TEXTURE_3D_INDEX
;
904 case GL_PROXY_TEXTURE_CUBE_MAP
:
905 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
907 texIndex
= TEXTURE_CUBE_INDEX
;
909 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
912 texIndex
= TEXTURE_RECT_INDEX
;
914 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
915 if (level
>= ctx
->Const
.MaxTextureLevels
)
917 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
919 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
920 if (level
>= ctx
->Const
.MaxTextureLevels
)
922 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
924 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
925 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
927 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
929 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
932 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
934 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
937 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
943 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
945 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
947 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
950 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
951 /* Set the 'back' pointer */
952 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
959 * Get the maximum number of allowed mipmap levels.
961 * \param ctx GL context.
962 * \param target texture target.
964 * \return the maximum number of allowed mipmap levels for the given
965 * texture target, or zero if passed a bad target.
970 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
974 case GL_PROXY_TEXTURE_1D
:
976 case GL_PROXY_TEXTURE_2D
:
977 return ctx
->Const
.MaxTextureLevels
;
979 case GL_PROXY_TEXTURE_3D
:
980 return ctx
->Const
.Max3DTextureLevels
;
981 case GL_TEXTURE_CUBE_MAP
:
982 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
983 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
984 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
985 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
986 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
987 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
988 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
989 return ctx
->Extensions
.ARB_texture_cube_map
990 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
991 case GL_TEXTURE_RECTANGLE_NV
:
992 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
993 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
994 case GL_TEXTURE_1D_ARRAY_EXT
:
995 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
996 case GL_TEXTURE_2D_ARRAY_EXT
:
997 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
998 return ctx
->Extensions
.EXT_texture_array
999 ? ctx
->Const
.MaxTextureLevels
: 0;
1000 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1001 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1002 return ctx
->Extensions
.ARB_texture_cube_map_array
1003 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1004 case GL_TEXTURE_BUFFER
:
1005 return ctx
->API
== API_OPENGL_CORE
&&
1006 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1007 case GL_TEXTURE_2D_MULTISAMPLE
:
1008 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1009 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1010 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1011 return (_mesa_is_desktop_gl(ctx
) || _mesa_is_gles31(ctx
))
1012 && ctx
->Extensions
.ARB_texture_multisample
1014 case GL_TEXTURE_EXTERNAL_OES
:
1017 return 0; /* bad target */
1023 * Return number of dimensions per mipmap level for the given texture target.
1026 _mesa_get_texture_dimensions(GLenum target
)
1030 case GL_PROXY_TEXTURE_1D
:
1033 case GL_TEXTURE_RECTANGLE
:
1034 case GL_TEXTURE_CUBE_MAP
:
1035 case GL_PROXY_TEXTURE_2D
:
1036 case GL_PROXY_TEXTURE_RECTANGLE
:
1037 case GL_PROXY_TEXTURE_CUBE_MAP
:
1038 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1039 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1040 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1041 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1042 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1043 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1044 case GL_TEXTURE_1D_ARRAY
:
1045 case GL_PROXY_TEXTURE_1D_ARRAY
:
1046 case GL_TEXTURE_EXTERNAL_OES
:
1047 case GL_TEXTURE_2D_MULTISAMPLE
:
1048 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1051 case GL_PROXY_TEXTURE_3D
:
1052 case GL_TEXTURE_2D_ARRAY
:
1053 case GL_PROXY_TEXTURE_2D_ARRAY
:
1054 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1055 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1056 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1057 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1059 case GL_TEXTURE_BUFFER
:
1062 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1070 * Check if a texture target can have more than one layer.
1073 _mesa_tex_target_is_layered(GLenum target
)
1077 case GL_PROXY_TEXTURE_1D
:
1079 case GL_PROXY_TEXTURE_2D
:
1080 case GL_TEXTURE_RECTANGLE
:
1081 case GL_PROXY_TEXTURE_RECTANGLE
:
1082 case GL_TEXTURE_2D_MULTISAMPLE
:
1083 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1084 case GL_TEXTURE_BUFFER
:
1085 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1086 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1087 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1088 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1089 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1090 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1091 case GL_TEXTURE_EXTERNAL_OES
:
1095 case GL_PROXY_TEXTURE_3D
:
1096 case GL_TEXTURE_CUBE_MAP
:
1097 case GL_PROXY_TEXTURE_CUBE_MAP
:
1098 case GL_TEXTURE_1D_ARRAY
:
1099 case GL_PROXY_TEXTURE_1D_ARRAY
:
1100 case GL_TEXTURE_2D_ARRAY
:
1101 case GL_PROXY_TEXTURE_2D_ARRAY
:
1102 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1103 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1104 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1105 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1109 assert(!"Invalid texture target.");
1116 * Return the number of layers present in the given level of an array,
1117 * cubemap or 3D texture. If the texture is not layered return zero.
1120 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1122 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1124 switch (texObj
->Target
) {
1127 case GL_TEXTURE_RECTANGLE
:
1128 case GL_TEXTURE_2D_MULTISAMPLE
:
1129 case GL_TEXTURE_BUFFER
:
1130 case GL_TEXTURE_EXTERNAL_OES
:
1133 case GL_TEXTURE_CUBE_MAP
:
1136 case GL_TEXTURE_1D_ARRAY
: {
1137 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1138 return img
? img
->Height
: 0;
1142 case GL_TEXTURE_2D_ARRAY
:
1143 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1144 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1145 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1146 return img
? img
->Depth
: 0;
1150 assert(!"Invalid texture target.");
1157 * Return the maximum number of mipmap levels for the given target
1158 * and the dimensions.
1159 * The dimensions are expected not to include the border.
1162 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1169 case GL_TEXTURE_1D_ARRAY
:
1170 case GL_PROXY_TEXTURE_1D
:
1171 case GL_PROXY_TEXTURE_1D_ARRAY
:
1174 case GL_TEXTURE_CUBE_MAP
:
1175 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1176 case GL_PROXY_TEXTURE_CUBE_MAP
:
1177 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1181 case GL_TEXTURE_2D_ARRAY
:
1182 case GL_PROXY_TEXTURE_2D
:
1183 case GL_PROXY_TEXTURE_2D_ARRAY
:
1184 size
= MAX2(width
, height
);
1187 case GL_PROXY_TEXTURE_3D
:
1188 size
= MAX3(width
, height
, depth
);
1190 case GL_TEXTURE_RECTANGLE
:
1191 case GL_TEXTURE_EXTERNAL_OES
:
1192 case GL_TEXTURE_2D_MULTISAMPLE
:
1193 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1194 case GL_PROXY_TEXTURE_RECTANGLE
:
1195 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1196 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1203 return _mesa_logbase2(size
) + 1;
1207 #if 000 /* not used anymore */
1209 * glTexImage[123]D can accept a NULL image pointer. In this case we
1210 * create a texture image with unspecified image contents per the OpenGL
1214 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1216 const GLint components
= _mesa_components_in_format(format
);
1217 const GLint numPixels
= width
* height
* depth
;
1218 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1222 * Let's see if anyone finds this. If glTexImage2D() is called with
1223 * a NULL image pointer then load the texture image with something
1224 * interesting instead of leaving it indeterminate.
1227 static const char message
[8][32] = {
1228 " X X XXXXX XXX X ",
1229 " XX XX X X X X X ",
1231 " X X XXXX XXX XXXXX ",
1234 " X X XXXXX XXX X X ",
1238 GLubyte
*imgPtr
= data
;
1240 for (h
= 0; h
< depth
; h
++) {
1241 for (i
= 0; i
< height
; i
++) {
1242 GLint srcRow
= 7 - (i
% 8);
1243 for (j
= 0; j
< width
; j
++) {
1244 GLint srcCol
= j
% 32;
1245 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1246 for (k
= 0; k
< components
; k
++) {
1262 * Set the size and format-related fields of a gl_texture_image struct
1263 * to zero. This is used when a proxy texture test fails.
1266 clear_teximage_fields(struct gl_texture_image
*img
)
1269 img
->_BaseFormat
= 0;
1270 img
->InternalFormat
= 0;
1279 img
->HeightLog2
= 0;
1281 img
->TexFormat
= MESA_FORMAT_NONE
;
1282 img
->NumSamples
= 0;
1283 img
->FixedSampleLocations
= GL_TRUE
;
1288 * Initialize basic fields of the gl_texture_image struct.
1290 * \param ctx GL context.
1291 * \param img texture image structure to be initialized.
1292 * \param width image width.
1293 * \param height image height.
1294 * \param depth image depth.
1295 * \param border image border.
1296 * \param internalFormat internal format.
1297 * \param format the actual hardware format (one of MESA_FORMAT_*)
1298 * \param numSamples number of samples per texel, or zero for non-MS.
1299 * \param fixedSampleLocations are sample locations fixed?
1301 * Fills in the fields of \p img with the given information.
1302 * Note: width, height and depth include the border.
1305 init_teximage_fields_ms(struct gl_context
*ctx
,
1306 struct gl_texture_image
*img
,
1307 GLsizei width
, GLsizei height
, GLsizei depth
,
1308 GLint border
, GLenum internalFormat
,
1310 GLuint numSamples
, GLboolean fixedSampleLocations
)
1315 assert(height
>= 0);
1318 target
= img
->TexObject
->Target
;
1319 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1320 assert(img
->_BaseFormat
!= -1);
1321 img
->InternalFormat
= internalFormat
;
1322 img
->Border
= border
;
1324 img
->Height
= height
;
1327 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1328 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1330 img
->NumSamples
= 0;
1331 img
->FixedSampleLocations
= GL_TRUE
;
1335 case GL_TEXTURE_BUFFER
:
1336 case GL_PROXY_TEXTURE_1D
:
1341 img
->HeightLog2
= 0;
1348 case GL_TEXTURE_1D_ARRAY
:
1349 case GL_PROXY_TEXTURE_1D_ARRAY
:
1350 img
->Height2
= height
; /* no border */
1351 img
->HeightLog2
= 0; /* not used */
1359 case GL_TEXTURE_RECTANGLE
:
1360 case GL_TEXTURE_CUBE_MAP
:
1361 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1362 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1363 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1364 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1365 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1366 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1367 case GL_TEXTURE_EXTERNAL_OES
:
1368 case GL_PROXY_TEXTURE_2D
:
1369 case GL_PROXY_TEXTURE_RECTANGLE
:
1370 case GL_PROXY_TEXTURE_CUBE_MAP
:
1371 case GL_TEXTURE_2D_MULTISAMPLE
:
1372 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1373 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1374 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1381 case GL_TEXTURE_2D_ARRAY
:
1382 case GL_PROXY_TEXTURE_2D_ARRAY
:
1383 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1384 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1385 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1386 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1387 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1388 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1389 img
->Depth2
= depth
; /* no border */
1390 img
->DepthLog2
= 0; /* not used */
1393 case GL_PROXY_TEXTURE_3D
:
1394 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1395 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1396 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1397 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1400 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1405 _mesa_get_tex_max_num_levels(target
,
1406 img
->Width2
, img
->Height2
, img
->Depth2
);
1407 img
->TexFormat
= format
;
1408 img
->NumSamples
= numSamples
;
1409 img
->FixedSampleLocations
= fixedSampleLocations
;
1414 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1415 struct gl_texture_image
*img
,
1416 GLsizei width
, GLsizei height
, GLsizei depth
,
1417 GLint border
, GLenum internalFormat
,
1420 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1421 internalFormat
, format
, 0, GL_TRUE
);
1426 * Free and clear fields of the gl_texture_image struct.
1428 * \param ctx GL context.
1429 * \param texImage texture image structure to be cleared.
1431 * After the call, \p texImage will have no data associated with it. Its
1432 * fields are cleared so that its parent object will test incomplete.
1435 _mesa_clear_texture_image(struct gl_context
*ctx
,
1436 struct gl_texture_image
*texImage
)
1438 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1439 clear_teximage_fields(texImage
);
1444 * Check the width, height, depth and border of a texture image are legal.
1445 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1447 * The target and level parameters will have already been validated.
1448 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1451 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1452 GLint level
, GLint width
, GLint height
,
1453 GLint depth
, GLint border
)
1459 case GL_PROXY_TEXTURE_1D
:
1460 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1461 maxSize
>>= level
; /* level size */
1462 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1464 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1465 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1471 case GL_PROXY_TEXTURE_2D
:
1472 case GL_TEXTURE_2D_MULTISAMPLE
:
1473 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1474 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1476 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1478 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1480 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1481 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1483 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1489 case GL_PROXY_TEXTURE_3D
:
1490 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1492 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1494 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1496 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1498 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1499 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1501 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1503 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1508 case GL_TEXTURE_RECTANGLE_NV
:
1509 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1512 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1513 if (width
< 0 || width
> maxSize
)
1515 if (height
< 0 || height
> maxSize
)
1519 case GL_TEXTURE_CUBE_MAP
:
1520 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1521 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1522 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1523 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1524 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1525 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1526 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1527 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1529 if (width
!= height
)
1531 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1533 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1535 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1536 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1538 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1543 case GL_TEXTURE_1D_ARRAY_EXT
:
1544 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1545 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1547 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1549 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1551 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1552 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1557 case GL_TEXTURE_2D_ARRAY_EXT
:
1558 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1559 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1560 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1561 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1563 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1565 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1567 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1569 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1570 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1572 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1577 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1578 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1579 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1580 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1582 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1584 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1586 if (width
!= height
)
1588 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1590 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1591 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1593 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1598 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1605 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1606 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1607 * \param destImage the destination texture image.
1608 * \return GL_TRUE if error found, GL_FALSE otherwise.
1611 error_check_subtexture_dimensions(struct gl_context
*ctx
, GLuint dims
,
1612 const struct gl_texture_image
*destImage
,
1613 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1614 GLsizei subWidth
, GLsizei subHeight
,
1615 GLsizei subDepth
, const char *func
)
1617 const GLenum target
= destImage
->TexObject
->Target
;
1622 _mesa_error(ctx
, GL_INVALID_VALUE
,
1623 "%s(width=%d)", func
, subWidth
);
1627 if (dims
> 1 && subHeight
< 0) {
1628 _mesa_error(ctx
, GL_INVALID_VALUE
,
1629 "%s(height=%d)", func
, subHeight
);
1633 if (dims
> 2 && subDepth
< 0) {
1634 _mesa_error(ctx
, GL_INVALID_VALUE
,
1635 "%s(depth=%d)", func
, subDepth
);
1639 /* check xoffset and width */
1640 if (xoffset
< - (GLint
) destImage
->Border
) {
1641 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset)", func
);
1645 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1646 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(xoffset+width)", func
);
1650 /* check yoffset and height */
1652 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1653 if (yoffset
< -yBorder
) {
1654 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset)", func
);
1657 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1658 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(yoffset+height)", func
);
1663 /* check zoffset and depth */
1666 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1667 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1668 0 : destImage
->Border
;
1670 if (zoffset
< -zBorder
) {
1671 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset)", func
);
1675 depth
= (GLint
) destImage
->Depth
;
1676 if (target
== GL_TEXTURE_CUBE_MAP
)
1678 if (zoffset
+ subDepth
> depth
) {
1679 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(zoffset+depth)", func
);
1685 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1686 * compressed texture images can be updated. But, that restriction may be
1687 * relaxed for particular compressed formats. At this time, all the
1688 * compressed formats supported by Mesa allow sub-textures to be updated
1689 * along compressed block boundaries.
1691 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1693 if (bw
!= 1 || bh
!= 1) {
1694 /* offset must be multiple of block size */
1695 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1696 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1697 "%s(xoffset = %d, yoffset = %d)",
1698 func
, xoffset
, yoffset
);
1702 /* The size must be a multiple of bw x bh, or we must be using a
1703 * offset+size that exactly hits the edge of the image. This
1704 * is important for small mipmap levels (1x1, 2x1, etc) and for
1707 if ((subWidth
% bw
!= 0) &&
1708 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1709 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1710 "%s(width = %d)", func
, subWidth
);
1714 if ((subHeight
% bh
!= 0) &&
1715 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1716 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1717 "%s(height = %d)", func
, subHeight
);
1729 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1730 * specific texture image size checks.
1732 * A hardware driver might override this function if, for example, the
1733 * max 3D texture size is 512x512x64 (i.e. not a cube).
1735 * Note that width, height, depth == 0 is not an error. However, a
1736 * texture with zero width/height/depth will be considered "incomplete"
1737 * and texturing will effectively be disabled.
1739 * \param target any texture target/type
1740 * \param level as passed to glTexImage
1741 * \param format the MESA_FORMAT_x for the tex image
1742 * \param width as passed to glTexImage
1743 * \param height as passed to glTexImage
1744 * \param depth as passed to glTexImage
1745 * \param border as passed to glTexImage
1746 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1749 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1751 GLint width
, GLint height
, GLint depth
, GLint border
)
1753 /* We just check if the image size is less than MaxTextureMbytes.
1754 * Some drivers may do more specific checks.
1756 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1757 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1758 mbytes
*= _mesa_num_tex_faces(target
);
1759 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1764 * Return true if the format is only valid for glCompressedTexImage.
1767 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1770 case GL_ETC1_RGB8_OES
:
1771 case GL_PALETTE4_RGB8_OES
:
1772 case GL_PALETTE4_RGBA8_OES
:
1773 case GL_PALETTE4_R5_G6_B5_OES
:
1774 case GL_PALETTE4_RGBA4_OES
:
1775 case GL_PALETTE4_RGB5_A1_OES
:
1776 case GL_PALETTE8_RGB8_OES
:
1777 case GL_PALETTE8_RGBA8_OES
:
1778 case GL_PALETTE8_R5_G6_B5_OES
:
1779 case GL_PALETTE8_RGBA4_OES
:
1780 case GL_PALETTE8_RGB5_A1_OES
:
1788 * Return true if the format doesn't support online compression.
1791 _mesa_format_no_online_compression(const struct gl_context
*ctx
, GLenum format
)
1793 return _mesa_is_astc_format(format
) ||
1794 compressedteximage_only_format(ctx
, format
);
1797 /* Writes to an GL error pointer if non-null and returns whether or not the
1798 * error is GL_NO_ERROR */
1800 write_error(GLenum
*err_ptr
, GLenum error
)
1805 return error
== GL_NO_ERROR
;
1809 * Helper function to determine whether a target and specific compression
1810 * format are supported. The error parameter returns GL_NO_ERROR if the
1811 * target can be compressed. Otherwise it returns either GL_INVALID_OPERATION
1812 * or GL_INVALID_ENUM, whichever is more appropriate.
1815 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1816 GLenum intFormat
, GLenum
*error
)
1818 GLboolean target_can_be_compresed
= GL_FALSE
;
1819 mesa_format format
= _mesa_glenum_to_compressed_format(intFormat
);
1820 enum mesa_format_layout layout
= _mesa_get_format_layout(format
);
1824 case GL_PROXY_TEXTURE_2D
:
1825 target_can_be_compresed
= GL_TRUE
; /* true for any compressed format so far */
1827 case GL_PROXY_TEXTURE_CUBE_MAP
:
1828 case GL_TEXTURE_CUBE_MAP
:
1829 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1830 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1831 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1832 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1833 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1834 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1835 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map
;
1837 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1838 case GL_TEXTURE_2D_ARRAY_EXT
:
1839 target_can_be_compresed
= ctx
->Extensions
.EXT_texture_array
;
1841 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1842 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1843 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
1845 * "The ETC2/EAC texture compression algorithm supports only
1846 * two-dimensional images. If internalformat is an ETC2/EAC format,
1847 * glCompressedTexImage3D will generate an INVALID_OPERATION error if
1848 * target is not TEXTURE_2D_ARRAY."
1850 * This should also be applicable for glTexStorage3D(). Other available
1851 * targets for these functions are: TEXTURE_3D and TEXTURE_CUBE_MAP_ARRAY.
1853 if (layout
== MESA_FORMAT_LAYOUT_ETC2
&& _mesa_is_gles3(ctx
))
1854 return write_error(error
, GL_INVALID_OPERATION
);
1856 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_cube_map_array
;
1858 /* From the KHR_texture_compression_astc_hdr spec:
1860 * Add a second new column "3D Tex." which is empty for all non-ASTC
1861 * formats. If only the LDR profile is supported by the
1862 * implementation, this column is also empty for all ASTC formats. If
1863 * both the LDR and HDR profiles are supported only, this column is
1864 * checked for all ASTC formats.
1866 * Add a third new column "Cube Map Array Tex." which is empty for all
1867 * non-ASTC formats, and checked for all ASTC formats.
1871 * 'An INVALID_OPERATION error is generated by CompressedTexImage3D
1872 * if <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the
1873 * "Cube Map Array" column of table 8.19 is *not* checked, or if
1874 * <internalformat> is TEXTURE_3D and the "3D Tex." column of table
1875 * 8.19 is *not* checked'
1877 * The instances of <internalformat> above should say <target>.
1880 /* Throw an INVALID_OPERATION error if the target is
1881 * TEXTURE_CUBE_MAP_ARRAY and the format is not ASTC.
1883 if (target_can_be_compresed
&&
1884 ctx
->Extensions
.KHR_texture_compression_astc_ldr
&&
1885 layout
!= MESA_FORMAT_LAYOUT_ASTC
)
1886 return write_error(error
, GL_INVALID_OPERATION
);
1891 case MESA_FORMAT_LAYOUT_ETC2
:
1892 /* See ETC2/EAC comment in case GL_TEXTURE_CUBE_MAP_ARRAY. */
1893 if (_mesa_is_gles3(ctx
))
1894 return write_error(error
, GL_INVALID_OPERATION
);
1896 case MESA_FORMAT_LAYOUT_BPTC
:
1897 target_can_be_compresed
= ctx
->Extensions
.ARB_texture_compression_bptc
;
1899 case MESA_FORMAT_LAYOUT_ASTC
:
1900 target_can_be_compresed
=
1901 ctx
->Extensions
.KHR_texture_compression_astc_hdr
;
1903 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1904 * and the hdr extension is not supported.
1905 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1907 if (!target_can_be_compresed
)
1908 return write_error(error
, GL_INVALID_OPERATION
);
1911 /* Throw an INVALID_OPERATION error if the target is TEXTURE_3D and
1912 * the format is not ASTC.
1913 * See comment in switch case GL_TEXTURE_CUBE_MAP_ARRAY for more info.
1915 if (ctx
->Extensions
.KHR_texture_compression_astc_ldr
)
1916 return write_error(error
, GL_INVALID_OPERATION
);
1922 return write_error(error
,
1923 target_can_be_compresed
? GL_NO_ERROR
: GL_INVALID_ENUM
);
1928 * Check if the given texture target value is legal for a
1929 * glTexImage1/2/3D call.
1932 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1938 case GL_PROXY_TEXTURE_1D
:
1939 return _mesa_is_desktop_gl(ctx
);
1947 case GL_PROXY_TEXTURE_2D
:
1948 return _mesa_is_desktop_gl(ctx
);
1949 case GL_PROXY_TEXTURE_CUBE_MAP
:
1950 return _mesa_is_desktop_gl(ctx
)
1951 && ctx
->Extensions
.ARB_texture_cube_map
;
1952 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1953 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1954 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1955 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1956 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1957 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1958 return ctx
->Extensions
.ARB_texture_cube_map
;
1959 case GL_TEXTURE_RECTANGLE_NV
:
1960 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1961 return _mesa_is_desktop_gl(ctx
)
1962 && ctx
->Extensions
.NV_texture_rectangle
;
1963 case GL_TEXTURE_1D_ARRAY_EXT
:
1964 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1965 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1973 case GL_PROXY_TEXTURE_3D
:
1974 return _mesa_is_desktop_gl(ctx
);
1975 case GL_TEXTURE_2D_ARRAY_EXT
:
1976 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1977 || _mesa_is_gles3(ctx
);
1978 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1979 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1980 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1981 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1982 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1987 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1994 * Check if the given texture target value is legal for a
1995 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1996 * The difference compared to legal_teximage_target() above is that
1997 * proxy targets are not supported.
2000 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
2005 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
2010 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
2011 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
2012 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
2013 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
2014 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
2015 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
2016 return ctx
->Extensions
.ARB_texture_cube_map
;
2017 case GL_TEXTURE_RECTANGLE_NV
:
2018 return _mesa_is_desktop_gl(ctx
)
2019 && ctx
->Extensions
.NV_texture_rectangle
;
2020 case GL_TEXTURE_1D_ARRAY_EXT
:
2021 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
2029 case GL_TEXTURE_2D_ARRAY_EXT
:
2030 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
2031 || _mesa_is_gles3(ctx
);
2032 case GL_TEXTURE_CUBE_MAP_ARRAY
:
2033 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
2034 return ctx
->Extensions
.ARB_texture_cube_map_array
;
2036 /* Table 8.15 of the OpenGL 4.5 core profile spec
2037 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
2038 * and CopyTextureSubImage3D.
2040 case GL_TEXTURE_CUBE_MAP
:
2046 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
2054 * Helper function to determine if a texture object is mutable (in terms
2055 * of GL_ARB_texture_storage).
2058 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
2060 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
2064 return !texObj
->Immutable
;
2069 * Return expected size of a compressed texture.
2072 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2075 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2076 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2080 * Verify that a texture format is valid with a particular target
2082 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
2083 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
2086 * \param ctx GL context
2087 * \param target Texture target
2088 * \param internalFormat Internal format of the texture image
2089 * \param dimensions Dimensionality at the caller. This is \b not used
2090 * in the validation. It is only used when logging
2092 * \param caller Base name of the calling function (e.g.,
2093 * "glTexImage" or "glTexStorage").
2095 * \returns true if the combination is legal, false otherwise.
2098 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
2099 GLenum target
, GLenum internalFormat
,
2100 unsigned dimensions
,
2103 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2104 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
2105 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_STENCIL_INDEX
) {
2106 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
2107 * Profile spec says:
2109 * "Textures with a base internal format of DEPTH_COMPONENT or
2110 * DEPTH_STENCIL are supported by texture image specification
2111 * commands only if target is TEXTURE_1D, TEXTURE_2D,
2112 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
2113 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
2114 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
2115 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
2116 * formats in conjunction with any other target will result in an
2117 * INVALID_OPERATION error."
2119 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
2120 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
2122 if (target
!= GL_TEXTURE_1D
&&
2123 target
!= GL_PROXY_TEXTURE_1D
&&
2124 target
!= GL_TEXTURE_2D
&&
2125 target
!= GL_PROXY_TEXTURE_2D
&&
2126 target
!= GL_TEXTURE_1D_ARRAY
&&
2127 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2128 target
!= GL_TEXTURE_2D_ARRAY
&&
2129 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2130 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2131 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2132 !((_mesa_is_cube_face(target
) ||
2133 target
== GL_TEXTURE_CUBE_MAP
||
2134 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2135 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2136 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2137 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2138 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2139 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2140 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2141 "%s%dD(bad target for depth texture)",
2142 caller
, dimensions
);
2151 texture_formats_agree(GLenum internalFormat
,
2154 GLboolean colorFormat
;
2155 GLboolean is_format_depth_or_depthstencil
;
2156 GLboolean is_internalFormat_depth_or_depthstencil
;
2158 /* Even though there are no color-index textures, we still have to support
2159 * uploading color-index data and remapping it to RGB via the
2160 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2162 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2164 is_internalFormat_depth_or_depthstencil
=
2165 _mesa_is_depth_format(internalFormat
) ||
2166 _mesa_is_depthstencil_format(internalFormat
);
2168 is_format_depth_or_depthstencil
=
2169 _mesa_is_depth_format(format
) ||
2170 _mesa_is_depthstencil_format(format
);
2172 colorFormat
= _mesa_is_color_format(format
);
2174 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2177 if (is_internalFormat_depth_or_depthstencil
!=
2178 is_format_depth_or_depthstencil
)
2181 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2188 * Test the combination of format, type and internal format arguments of
2189 * different texture operations on GLES.
2191 * \param ctx GL context.
2192 * \param format pixel data format given by the user.
2193 * \param type pixel data type given by the user.
2194 * \param internalFormat internal format given by the user.
2195 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2196 * \param callerName name of the caller function to print in the error message
2198 * \return true if a error is found, false otherwise
2200 * Currently, it is used by texture_error_check() and texsubimage_error_check().
2203 texture_format_error_check_gles(struct gl_context
*ctx
, GLenum format
,
2204 GLenum type
, GLenum internalFormat
,
2205 GLuint dimensions
, const char *callerName
)
2209 if (_mesa_is_gles3(ctx
)) {
2210 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
2212 if (err
!= GL_NO_ERROR
) {
2213 _mesa_error(ctx
, err
,
2214 "%s(format = %s, type = %s, internalformat = %s)",
2215 callerName
, _mesa_enum_to_string(format
),
2216 _mesa_enum_to_string(type
),
2217 _mesa_enum_to_string(internalFormat
));
2222 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2223 if (err
!= GL_NO_ERROR
) {
2224 _mesa_error(ctx
, err
, "%s(format = %s, type = %s)",
2225 callerName
, _mesa_enum_to_string(format
),
2226 _mesa_enum_to_string(type
));
2235 * Test the glTexImage[123]D() parameters for errors.
2237 * \param ctx GL context.
2238 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2239 * \param target texture target given by the user (already validated).
2240 * \param level image level given by the user.
2241 * \param internalFormat internal format given by the user.
2242 * \param format pixel data format given by the user.
2243 * \param type pixel data type given by the user.
2244 * \param width image width given by the user.
2245 * \param height image height given by the user.
2246 * \param depth image depth given by the user.
2247 * \param border image border given by the user.
2249 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2251 * Verifies each of the parameters against the constants specified in
2252 * __struct gl_contextRec::Const and the supported extensions, and according
2253 * to the OpenGL specification.
2254 * Note that we don't fully error-check the width, height, depth values
2255 * here. That's done in _mesa_legal_texture_dimensions() which is used
2256 * by several other GL entrypoints. Plus, texture dims have a special
2257 * interaction with proxy textures.
2260 texture_error_check( struct gl_context
*ctx
,
2261 GLuint dimensions
, GLenum target
,
2262 GLint level
, GLint internalFormat
,
2263 GLenum format
, GLenum type
,
2264 GLint width
, GLint height
,
2265 GLint depth
, GLint border
,
2266 const GLvoid
*pixels
)
2270 /* Note: for proxy textures, some error conditions immediately generate
2271 * a GL error in the usual way. But others do not generate a GL error.
2272 * Instead, they cause the width, height, depth, format fields of the
2273 * texture image to be zeroed-out. The GL spec seems to indicate that the
2274 * zero-out behaviour is only used in cases related to memory allocation.
2278 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2279 _mesa_error(ctx
, GL_INVALID_VALUE
,
2280 "glTexImage%dD(level=%d)", dimensions
, level
);
2285 if (border
< 0 || border
> 1 ||
2286 ((ctx
->API
!= API_OPENGL_COMPAT
||
2287 target
== GL_TEXTURE_RECTANGLE_NV
||
2288 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2289 _mesa_error(ctx
, GL_INVALID_VALUE
,
2290 "glTexImage%dD(border=%d)", dimensions
, border
);
2294 if (width
< 0 || height
< 0 || depth
< 0) {
2295 _mesa_error(ctx
, GL_INVALID_VALUE
,
2296 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2300 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2301 * combinations of format, internalFormat, and type that can be used.
2302 * Formats and types that require additional extensions (e.g., GL_FLOAT
2303 * requires GL_OES_texture_float) are filtered elsewhere.
2305 if (_mesa_is_gles(ctx
) &&
2306 texture_format_error_check_gles(ctx
, format
, type
, internalFormat
,
2307 dimensions
, "glTexImage%dD")) {
2311 /* Check internalFormat */
2312 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2313 _mesa_error(ctx
, GL_INVALID_VALUE
,
2314 "glTexImage%dD(internalFormat=%s)",
2315 dimensions
, _mesa_enum_to_string(internalFormat
));
2319 /* Check incoming image format and type */
2320 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2321 if (err
!= GL_NO_ERROR
) {
2322 _mesa_error(ctx
, err
,
2323 "glTexImage%dD(incompatible format = %s, type = %s)",
2324 dimensions
, _mesa_enum_to_string(format
),
2325 _mesa_enum_to_string(type
));
2329 /* validate the bound PBO, if any */
2330 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2331 width
, height
, depth
, format
, type
,
2332 INT_MAX
, pixels
, "glTexImage")) {
2336 /* make sure internal format and format basically agree */
2337 if (!texture_formats_agree(internalFormat
, format
)) {
2338 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2339 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2340 dimensions
, _mesa_enum_to_string(internalFormat
),
2341 _mesa_enum_to_string(format
));
2345 /* additional checks for ycbcr textures */
2346 if (internalFormat
== GL_YCBCR_MESA
) {
2347 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
2348 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2349 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2351 _mesa_snprintf(message
, sizeof(message
),
2352 "glTexImage%dD(format/type YCBCR mismatch)",
2354 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2355 return GL_TRUE
; /* error */
2357 if (target
!= GL_TEXTURE_2D
&&
2358 target
!= GL_PROXY_TEXTURE_2D
&&
2359 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2360 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2361 _mesa_error(ctx
, GL_INVALID_ENUM
,
2362 "glTexImage%dD(bad target for YCbCr texture)",
2368 _mesa_snprintf(message
, sizeof(message
),
2369 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2370 dimensions
, border
);
2371 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2376 /* additional checks for depth textures */
2377 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2378 dimensions
, "glTexImage"))
2381 /* additional checks for compressed textures */
2382 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2384 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2385 _mesa_error(ctx
, err
,
2386 "glTexImage%dD(target can't be compressed)", dimensions
);
2389 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2390 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2391 "glTexImage%dD(no compression for format)", dimensions
);
2395 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2396 "glTexImage%dD(border!=0)", dimensions
);
2401 /* additional checks for integer textures */
2402 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2403 (_mesa_is_enum_format_integer(format
) !=
2404 _mesa_is_enum_format_integer(internalFormat
))) {
2405 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2406 "glTexImage%dD(integer/non-integer format mismatch)",
2411 if (!mutable_tex_object(ctx
, target
)) {
2412 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2413 "glTexImage%dD(immutable texture)", dimensions
);
2417 /* if we get here, the parameters are OK */
2423 * Error checking for glCompressedTexImage[123]D().
2424 * Note that the width, height and depth values are not fully error checked
2426 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2429 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2430 GLenum target
, GLint level
,
2431 GLenum internalFormat
, GLsizei width
,
2432 GLsizei height
, GLsizei depth
, GLint border
,
2433 GLsizei imageSize
, const GLvoid
*data
)
2435 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2437 GLenum error
= GL_NO_ERROR
;
2438 char *reason
= ""; /* no error */
2440 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &error
)) {
2445 /* This will detect any invalid internalFormat value */
2446 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2447 _mesa_error(ctx
, GL_INVALID_ENUM
,
2448 "glCompressedTexImage%dD(internalFormat=%s)",
2449 dimensions
, _mesa_enum_to_string(internalFormat
));
2453 /* validate the bound PBO, if any */
2454 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2456 "glCompressedTexImage")) {
2460 switch (internalFormat
) {
2461 case GL_PALETTE4_RGB8_OES
:
2462 case GL_PALETTE4_RGBA8_OES
:
2463 case GL_PALETTE4_R5_G6_B5_OES
:
2464 case GL_PALETTE4_RGBA4_OES
:
2465 case GL_PALETTE4_RGB5_A1_OES
:
2466 case GL_PALETTE8_RGB8_OES
:
2467 case GL_PALETTE8_RGBA8_OES
:
2468 case GL_PALETTE8_R5_G6_B5_OES
:
2469 case GL_PALETTE8_RGBA4_OES
:
2470 case GL_PALETTE8_RGB5_A1_OES
:
2471 /* check level (note that level should be zero or less!) */
2472 if (level
> 0 || level
< -maxLevels
) {
2474 error
= GL_INVALID_VALUE
;
2478 if (dimensions
!= 2) {
2479 reason
= "compressed paletted textures must be 2D";
2480 error
= GL_INVALID_OPERATION
;
2484 /* Figure out the expected texture size (in bytes). This will be
2485 * checked against the actual size later.
2487 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2490 /* This is for the benefit of the TestProxyTexImage below. It expects
2491 * level to be non-negative. OES_compressed_paletted_texture uses a
2492 * weird mechanism where the level specified to glCompressedTexImage2D
2493 * is -(n-1) number of levels in the texture, and the data specifies the
2494 * complete mipmap stack. This is done to ensure the palette is the
2495 * same for all levels.
2502 if (level
< 0 || level
>= maxLevels
) {
2504 error
= GL_INVALID_VALUE
;
2508 /* Figure out the expected texture size (in bytes). This will be
2509 * checked against the actual size later.
2511 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2515 /* This should really never fail */
2516 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2517 reason
= "internalFormat";
2518 error
= GL_INVALID_ENUM
;
2522 /* No compressed formats support borders at this time */
2524 reason
= "border != 0";
2525 error
= GL_INVALID_VALUE
;
2529 /* Check for invalid pixel storage modes */
2530 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2532 "glCompressedTexImage")) {
2536 /* check image size in bytes */
2537 if (expectedSize
!= imageSize
) {
2538 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2539 * if <imageSize> is not consistent with the format, dimensions, and
2540 * contents of the specified image.
2542 reason
= "imageSize inconsistant with width/height/format";
2543 error
= GL_INVALID_VALUE
;
2547 if (!mutable_tex_object(ctx
, target
)) {
2548 reason
= "immutable texture";
2549 error
= GL_INVALID_OPERATION
;
2556 /* Note: not all error paths exit through here. */
2557 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2558 dimensions
, reason
);
2565 * Test glTexSubImage[123]D() parameters for errors.
2567 * \param ctx GL context.
2568 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2569 * \param target texture target given by the user (already validated)
2570 * \param level image level given by the user.
2571 * \param xoffset sub-image x offset given by the user.
2572 * \param yoffset sub-image y offset given by the user.
2573 * \param zoffset sub-image z offset given by the user.
2574 * \param format pixel data format given by the user.
2575 * \param type pixel data type given by the user.
2576 * \param width image width given by the user.
2577 * \param height image height given by the user.
2578 * \param depth image depth given by the user.
2580 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2582 * Verifies each of the parameters against the constants specified in
2583 * __struct gl_contextRec::Const and the supported extensions, and according
2584 * to the OpenGL specification.
2587 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2588 struct gl_texture_object
*texObj
,
2589 GLenum target
, GLint level
,
2590 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2591 GLint width
, GLint height
, GLint depth
,
2592 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2593 bool dsa
, const char *callerName
)
2595 struct gl_texture_image
*texImage
;
2599 /* must be out of memory */
2600 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2605 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2606 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2610 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2612 /* non-existant texture level */
2613 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture image)",
2618 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2619 if (err
!= GL_NO_ERROR
) {
2620 _mesa_error(ctx
, err
,
2621 "%s(incompatible format = %s, type = %s)",
2622 callerName
, _mesa_enum_to_string(format
),
2623 _mesa_enum_to_string(type
));
2627 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2628 * combinations of format, internalFormat, and type that can be used.
2629 * Formats and types that require additional extensions (e.g., GL_FLOAT
2630 * requires GL_OES_texture_float) are filtered elsewhere.
2632 if (_mesa_is_gles(ctx
) &&
2633 texture_format_error_check_gles(ctx
, format
, type
,
2634 texImage
->InternalFormat
,
2635 dimensions
, callerName
)) {
2639 /* validate the bound PBO, if any */
2640 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2641 width
, height
, depth
, format
, type
,
2642 INT_MAX
, pixels
, callerName
)) {
2646 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2647 texImage
, xoffset
, yoffset
, zoffset
,
2648 width
, height
, depth
, callerName
)) {
2652 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2653 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2654 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2655 "%s(no compression for format)", callerName
);
2660 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2661 /* both source and dest must be integer-valued, or neither */
2662 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2663 _mesa_is_enum_format_integer(format
)) {
2664 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2665 "%s(integer/non-integer format mismatch)", callerName
);
2675 * Test glCopyTexImage[12]D() parameters for errors.
2677 * \param ctx GL context.
2678 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2679 * \param target texture target given by the user.
2680 * \param level image level given by the user.
2681 * \param internalFormat internal format given by the user.
2682 * \param width image width given by the user.
2683 * \param height image height given by the user.
2684 * \param border texture border.
2686 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2688 * Verifies each of the parameters against the constants specified in
2689 * __struct gl_contextRec::Const and the supported extensions, and according
2690 * to the OpenGL specification.
2693 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2694 GLenum target
, GLint level
, GLint internalFormat
,
2695 GLint width
, GLint height
, GLint border
)
2698 GLint rb_base_format
;
2699 struct gl_renderbuffer
*rb
;
2700 GLenum rb_internal_format
;
2703 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2704 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2705 dimensions
, _mesa_enum_to_string(target
));
2710 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2711 _mesa_error(ctx
, GL_INVALID_VALUE
,
2712 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2716 /* Check that the source buffer is complete */
2717 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2718 if (ctx
->ReadBuffer
->_Status
== 0) {
2719 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2721 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2722 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2723 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2727 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2728 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2729 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2735 if (border
< 0 || border
> 1 ||
2736 ((ctx
->API
!= API_OPENGL_COMPAT
||
2737 target
== GL_TEXTURE_RECTANGLE_NV
||
2738 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2739 _mesa_error(ctx
, GL_INVALID_VALUE
,
2740 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2744 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2747 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2748 switch (internalFormat
) {
2753 case GL_LUMINANCE_ALPHA
:
2756 _mesa_error(ctx
, GL_INVALID_ENUM
,
2757 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2758 _mesa_enum_to_string(internalFormat
));
2763 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2764 if (baseFormat
< 0) {
2765 _mesa_error(ctx
, GL_INVALID_ENUM
,
2766 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2767 _mesa_enum_to_string(internalFormat
));
2771 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2773 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2774 "glCopyTexImage%dD(read buffer)", dimensions
);
2778 rb_internal_format
= rb
->InternalFormat
;
2779 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2780 if (_mesa_is_color_format(internalFormat
)) {
2781 if (rb_base_format
< 0) {
2782 _mesa_error(ctx
, GL_INVALID_VALUE
,
2783 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2784 _mesa_enum_to_string(internalFormat
));
2789 if (_mesa_is_gles(ctx
)) {
2791 if (_mesa_base_format_component_count(baseFormat
) >
2792 _mesa_base_format_component_count(rb_base_format
)) {
2795 if (baseFormat
== GL_DEPTH_COMPONENT
||
2796 baseFormat
== GL_DEPTH_STENCIL
||
2797 rb_base_format
== GL_DEPTH_COMPONENT
||
2798 rb_base_format
== GL_DEPTH_STENCIL
||
2799 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2800 baseFormat
== GL_ALPHA
) &&
2801 rb_base_format
!= GL_RGBA
) ||
2802 internalFormat
== GL_RGB9_E5
) {
2805 if (internalFormat
== GL_RGB9_E5
) {
2809 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2810 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2811 _mesa_enum_to_string(internalFormat
));
2816 if (_mesa_is_gles3(ctx
)) {
2817 bool rb_is_srgb
= false;
2818 bool dst_is_srgb
= false;
2820 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2821 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2825 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2829 if (rb_is_srgb
!= dst_is_srgb
) {
2830 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2831 * OpenGLES 3.0.0 spec says:
2833 * "The error INVALID_OPERATION is also generated if the
2834 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2835 * framebuffer attachment corresponding to the read buffer
2836 * is LINEAR (see section 6.1.13) and internalformat is
2837 * one of the sRGB formats described in section 3.8.16, or
2838 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2839 * SRGB and internalformat is not one of the sRGB formats."
2841 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2842 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2846 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2847 * types for SNORM formats. Also, conversion to SNORM formats is not
2848 * allowed by Table 3.2 on Page 110.
2850 if (_mesa_is_enum_format_snorm(internalFormat
)) {
2851 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2852 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2853 _mesa_enum_to_string(internalFormat
));
2858 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2859 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2860 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2864 /* From the EXT_texture_integer spec:
2866 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2867 * if the texture internalformat is an integer format and the read color
2868 * buffer is not an integer format, or if the internalformat is not an
2869 * integer format and the read color buffer is an integer format."
2871 if (_mesa_is_color_format(internalFormat
)) {
2872 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2873 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2874 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2875 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2876 if (is_int
|| is_rbint
) {
2877 if (is_int
!= is_rbint
) {
2878 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2879 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2881 } else if (_mesa_is_gles(ctx
) &&
2882 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2883 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2884 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2885 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2890 /* From page 138 of OpenGL ES 3.0 spec:
2891 * "The error INVALID_OPERATION is generated if floating-point RGBA
2892 * data is required; if signed integer RGBA data is required and the
2893 * format of the current color buffer is not signed integer; if
2894 * unsigned integer RGBA data is required and the format of the
2895 * current color buffer is not unsigned integer; or if fixed-point
2896 * RGBA data is required and the format of the current color buffer
2897 * is not fixed-point.
2899 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2900 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2901 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2904 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2906 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
, &err
)) {
2907 _mesa_error(ctx
, err
,
2908 "glCopyTexImage%dD(target can't be compressed)", dimensions
);
2911 if (_mesa_format_no_online_compression(ctx
, internalFormat
)) {
2912 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2913 "glCopyTexImage%dD(no compression for format)", dimensions
);
2917 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2918 "glCopyTexImage%dD(border!=0)", dimensions
);
2923 if (!mutable_tex_object(ctx
, target
)) {
2924 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2925 "glCopyTexImage%dD(immutable texture)", dimensions
);
2929 /* if we get here, the parameters are OK */
2935 * Test glCopyTexSubImage[12]D() parameters for errors.
2936 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2939 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2940 const struct gl_texture_object
*texObj
,
2941 GLenum target
, GLint level
,
2942 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2943 GLint width
, GLint height
, const char *caller
)
2945 struct gl_texture_image
*texImage
;
2947 /* Check that the source buffer is complete */
2948 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2949 if (ctx
->ReadBuffer
->_Status
== 0) {
2950 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2952 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2953 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2954 "%s(invalid readbuffer)", caller
);
2958 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2959 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2960 "%s(multisample FBO)", caller
);
2966 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2967 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2971 /* Get dest image pointers */
2973 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", caller
);
2977 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2979 /* destination image does not exist */
2980 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2981 "%s(invalid texture image)", caller
);
2985 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2986 xoffset
, yoffset
, zoffset
,
2987 width
, height
, 1, caller
)) {
2991 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2992 if (_mesa_format_no_online_compression(ctx
, texImage
->InternalFormat
)) {
2993 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2994 "%s(no compression for format)", caller
);
2999 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
3000 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
3004 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
3005 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3006 "%s(missing readbuffer, format=0x%x)", caller
,
3007 texImage
->_BaseFormat
);
3011 /* From the EXT_texture_integer spec:
3013 * "INVALID_OPERATION is generated by CopyTexImage* and
3014 * CopyTexSubImage* if the texture internalformat is an integer format
3015 * and the read color buffer is not an integer format, or if the
3016 * internalformat is not an integer format and the read color buffer
3017 * is an integer format."
3019 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
3020 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
3022 if (_mesa_is_format_integer_color(rb
->Format
) !=
3023 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
3024 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3025 "%s(integer vs non-integer)", caller
);
3030 /* if we get here, the parameters are OK */
3035 /** Callback info for walking over FBO hash table */
3038 struct gl_context
*ctx
;
3039 struct gl_texture_object
*texObj
;
3045 * Check render to texture callback. Called from _mesa_HashWalk().
3048 check_rtt_cb(GLuint key
, void *data
, void *userData
)
3050 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
3051 const struct cb_info
*info
= (struct cb_info
*) userData
;
3052 struct gl_context
*ctx
= info
->ctx
;
3053 const struct gl_texture_object
*texObj
= info
->texObj
;
3054 const GLuint level
= info
->level
, face
= info
->face
;
3056 /* If this is a user-created FBO */
3057 if (_mesa_is_user_fbo(fb
)) {
3059 /* check if any of the FBO's attachments point to 'texObj' */
3060 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
3061 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
3062 if (att
->Type
== GL_TEXTURE
&&
3063 att
->Texture
== texObj
&&
3064 att
->TextureLevel
== level
&&
3065 att
->CubeMapFace
== face
) {
3066 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
3067 assert(att
->Renderbuffer
->TexImage
);
3068 /* Mark fb status as indeterminate to force re-validation */
3077 * When a texture image is specified we have to check if it's bound to
3078 * any framebuffer objects (render to texture) in order to detect changes
3079 * in size or format since that effects FBO completeness.
3080 * Any FBOs rendering into the texture must be re-validated.
3083 _mesa_update_fbo_texture(struct gl_context
*ctx
,
3084 struct gl_texture_object
*texObj
,
3085 GLuint face
, GLuint level
)
3087 /* Only check this texture if it's been marked as RenderToTexture */
3088 if (texObj
->_RenderToTexture
) {
3089 struct cb_info info
;
3091 info
.texObj
= texObj
;
3094 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
3100 * If the texture object's GenerateMipmap flag is set and we've
3101 * changed the texture base level image, regenerate the rest of the
3102 * mipmap levels now.
3105 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
3106 struct gl_texture_object
*texObj
, GLint level
)
3108 if (texObj
->GenerateMipmap
&&
3109 level
== texObj
->BaseLevel
&&
3110 level
< texObj
->MaxLevel
) {
3111 assert(ctx
->Driver
.GenerateMipmap
);
3112 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3117 /** Debug helper: override the user-requested internal format */
3119 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
3122 if (internalFormat
== GL_RGBA16F_ARB
||
3123 internalFormat
== GL_RGBA32F_ARB
) {
3124 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3127 else if (internalFormat
== GL_RGB16F_ARB
||
3128 internalFormat
== GL_RGB32F_ARB
) {
3129 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3132 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3133 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3134 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3135 return GL_LUMINANCE_ALPHA
;
3137 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3138 internalFormat
== GL_LUMINANCE32F_ARB
) {
3139 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3140 return GL_LUMINANCE
;
3142 else if (internalFormat
== GL_ALPHA16F_ARB
||
3143 internalFormat
== GL_ALPHA32F_ARB
) {
3144 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3148 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3149 internalFormat = GL_RGBA;
3153 return internalFormat
;
3156 return internalFormat
;
3162 * Choose the actual hardware format for a texture image.
3163 * Try to use the same format as the previous image level when possible.
3164 * Otherwise, ask the driver for the best format.
3165 * It's important to try to choose a consistant format for all levels
3166 * for efficient texture memory layout/allocation. In particular, this
3167 * comes up during automatic mipmap generation.
3170 _mesa_choose_texture_format(struct gl_context
*ctx
,
3171 struct gl_texture_object
*texObj
,
3172 GLenum target
, GLint level
,
3173 GLenum internalFormat
, GLenum format
, GLenum type
)
3177 /* see if we've already chosen a format for the previous level */
3179 struct gl_texture_image
*prevImage
=
3180 _mesa_select_tex_image(texObj
, target
, level
- 1);
3181 /* See if the prev level is defined and has an internal format which
3182 * matches the new internal format.
3185 prevImage
->Width
> 0 &&
3186 prevImage
->InternalFormat
== internalFormat
) {
3187 /* use the same format */
3188 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3189 return prevImage
->TexFormat
;
3193 /* If the application requested compression to an S3TC format but we don't
3194 * have the DXTn library, force a generic compressed format instead.
3196 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3197 const GLenum before
= internalFormat
;
3199 switch (internalFormat
) {
3200 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3201 if (!ctx
->Mesa_DXTn
)
3202 internalFormat
= GL_COMPRESSED_RGB
;
3204 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3205 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3206 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3207 if (!ctx
->Mesa_DXTn
)
3208 internalFormat
= GL_COMPRESSED_RGBA
;
3214 if (before
!= internalFormat
) {
3216 "DXT compression requested (%s), "
3217 "but libtxc_dxtn library not installed. Using %s "
3219 _mesa_enum_to_string(before
),
3220 _mesa_enum_to_string(internalFormat
));
3224 /* choose format from scratch */
3225 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3227 assert(f
!= MESA_FORMAT_NONE
);
3233 * Adjust pixel unpack params and image dimensions to strip off the
3234 * one-pixel texture border.
3236 * Gallium and intel don't support texture borders. They've seldem been used
3237 * and seldom been implemented correctly anyway.
3239 * \param unpackNew returns the new pixel unpack parameters
3242 strip_texture_border(GLenum target
,
3243 GLint
*width
, GLint
*height
, GLint
*depth
,
3244 const struct gl_pixelstore_attrib
*unpack
,
3245 struct gl_pixelstore_attrib
*unpackNew
)
3251 *unpackNew
= *unpack
;
3253 if (unpackNew
->RowLength
== 0)
3254 unpackNew
->RowLength
= *width
;
3256 if (unpackNew
->ImageHeight
== 0)
3257 unpackNew
->ImageHeight
= *height
;
3259 assert(*width
>= 3);
3260 unpackNew
->SkipPixels
++; /* skip the border */
3261 *width
= *width
- 2; /* reduce the width by two border pixels */
3263 /* The min height of a texture with a border is 3 */
3264 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3265 unpackNew
->SkipRows
++; /* skip the border */
3266 *height
= *height
- 2; /* reduce the height by two border pixels */
3270 target
!= GL_TEXTURE_2D_ARRAY
&&
3271 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3272 unpackNew
->SkipImages
++; /* skip the border */
3273 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3279 * Common code to implement all the glTexImage1D/2D/3D functions
3280 * as well as glCompressedTexImage1D/2D/3D.
3281 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3282 * \param format the user's image format (only used if !compressed)
3283 * \param type the user's image type (only used if !compressed)
3284 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3287 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3288 GLenum target
, GLint level
, GLint internalFormat
,
3289 GLsizei width
, GLsizei height
, GLsizei depth
,
3290 GLint border
, GLenum format
, GLenum type
,
3291 GLsizei imageSize
, const GLvoid
*pixels
)
3293 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3294 struct gl_pixelstore_attrib unpack_no_border
;
3295 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3296 struct gl_texture_object
*texObj
;
3297 mesa_format texFormat
;
3298 GLboolean dimensionsOK
, sizeOK
;
3300 FLUSH_VERTICES(ctx
, 0);
3302 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3305 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3307 _mesa_enum_to_string(target
), level
,
3308 _mesa_enum_to_string(internalFormat
),
3309 width
, height
, depth
, border
, pixels
);
3312 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3314 _mesa_enum_to_string(target
), level
,
3315 _mesa_enum_to_string(internalFormat
),
3316 width
, height
, depth
, border
,
3317 _mesa_enum_to_string(format
),
3318 _mesa_enum_to_string(type
), pixels
);
3321 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3323 /* target error checking */
3324 if (!legal_teximage_target(ctx
, dims
, target
)) {
3325 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3326 func
, dims
, _mesa_enum_to_string(target
));
3330 /* general error checking */
3332 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3334 width
, height
, depth
,
3335 border
, imageSize
, pixels
))
3339 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3340 format
, type
, width
, height
, depth
, border
,
3345 /* Here we convert a cpal compressed image into a regular glTexImage2D
3346 * call by decompressing the texture. If we really want to support cpal
3347 * textures in any driver this would have to be changed.
3349 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3350 switch (internalFormat
) {
3351 case GL_PALETTE4_RGB8_OES
:
3352 case GL_PALETTE4_RGBA8_OES
:
3353 case GL_PALETTE4_R5_G6_B5_OES
:
3354 case GL_PALETTE4_RGBA4_OES
:
3355 case GL_PALETTE4_RGB5_A1_OES
:
3356 case GL_PALETTE8_RGB8_OES
:
3357 case GL_PALETTE8_RGBA8_OES
:
3358 case GL_PALETTE8_R5_G6_B5_OES
:
3359 case GL_PALETTE8_RGBA4_OES
:
3360 case GL_PALETTE8_RGB5_A1_OES
:
3361 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3362 width
, height
, imageSize
, pixels
);
3367 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3371 /* For glCompressedTexImage() the driver has no choice about the
3372 * texture format since we'll never transcode the user's compressed
3373 * image data. The internalFormat was error checked earlier.
3375 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3378 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3379 * internal floating point format for the given base format.
3381 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3382 if (type
== GL_FLOAT
) {
3383 texObj
->_IsFloat
= GL_TRUE
;
3384 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3385 texObj
->_IsHalfFloat
= GL_TRUE
;
3388 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3391 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3392 internalFormat
, format
, type
);
3395 assert(texFormat
!= MESA_FORMAT_NONE
);
3397 /* check that width, height, depth are legal for the mipmap level */
3398 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3399 height
, depth
, border
);
3401 /* check that the texture won't take too much memory, etc */
3402 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3404 width
, height
, depth
, border
);
3406 if (_mesa_is_proxy_texture(target
)) {
3407 /* Proxy texture: just clear or set state depending on error checking */
3408 struct gl_texture_image
*texImage
=
3409 get_proxy_tex_image(ctx
, target
, level
);
3412 return; /* GL_OUT_OF_MEMORY already recorded */
3414 if (dimensionsOK
&& sizeOK
) {
3415 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3416 border
, internalFormat
, texFormat
);
3419 clear_teximage_fields(texImage
);
3423 /* non-proxy target */
3424 const GLuint face
= _mesa_tex_target_to_face(target
);
3425 struct gl_texture_image
*texImage
;
3427 if (!dimensionsOK
) {
3428 _mesa_error(ctx
, GL_INVALID_VALUE
,
3429 "%s%uD(invalid width or height or depth)",
3435 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3436 "%s%uD(image too large: %d x %d x %d, %s format)",
3437 func
, dims
, width
, height
, depth
,
3438 _mesa_enum_to_string(internalFormat
));
3442 /* Allow a hardware driver to just strip out the border, to provide
3443 * reliable but slightly incorrect hardware rendering instead of
3444 * rarely-tested software fallback rendering.
3446 if (border
&& ctx
->Const
.StripTextureBorder
) {
3447 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3450 unpack
= &unpack_no_border
;
3453 if (ctx
->NewState
& _NEW_PIXEL
)
3454 _mesa_update_state(ctx
);
3456 _mesa_lock_texture(ctx
, texObj
);
3458 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3461 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3464 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3466 _mesa_init_teximage_fields(ctx
, texImage
,
3467 width
, height
, depth
,
3468 border
, internalFormat
, texFormat
);
3470 /* Give the texture to the driver. <pixels> may be null. */
3471 if (width
> 0 && height
> 0 && depth
> 0) {
3473 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3477 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3478 type
, pixels
, unpack
);
3482 check_gen_mipmap(ctx
, target
, texObj
, level
);
3484 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3486 _mesa_dirty_texobj(ctx
, texObj
);
3489 _mesa_unlock_texture(ctx
, texObj
);
3496 * Called from the API. Note that width includes the border.
3499 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3500 GLsizei width
, GLint border
, GLenum format
,
3501 GLenum type
, const GLvoid
*pixels
)
3503 GET_CURRENT_CONTEXT(ctx
);
3504 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3505 border
, format
, type
, 0, pixels
);
3510 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3511 GLsizei width
, GLsizei height
, GLint border
,
3512 GLenum format
, GLenum type
,
3513 const GLvoid
*pixels
)
3515 GET_CURRENT_CONTEXT(ctx
);
3516 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3517 border
, format
, type
, 0, pixels
);
3522 * Called by the API or display list executor.
3523 * Note that width and height include the border.
3526 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3527 GLsizei width
, GLsizei height
, GLsizei depth
,
3528 GLint border
, GLenum format
, GLenum type
,
3529 const GLvoid
*pixels
)
3531 GET_CURRENT_CONTEXT(ctx
);
3532 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3533 width
, height
, depth
,
3534 border
, format
, type
, 0, pixels
);
3539 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3540 GLsizei width
, GLsizei height
, GLsizei depth
,
3541 GLint border
, GLenum format
, GLenum type
,
3542 const GLvoid
*pixels
)
3544 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3545 depth
, border
, format
, type
, pixels
);
3550 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3552 struct gl_texture_object
*texObj
;
3553 struct gl_texture_image
*texImage
;
3555 GET_CURRENT_CONTEXT(ctx
);
3556 FLUSH_VERTICES(ctx
, 0);
3560 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3562 case GL_TEXTURE_EXTERNAL_OES
:
3564 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3567 valid_target
= false;
3571 if (!valid_target
) {
3572 _mesa_error(ctx
, GL_INVALID_ENUM
,
3573 "glEGLImageTargetTexture2D(target=%d)", target
);
3578 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3579 "glEGLImageTargetTexture2D(image=%p)", image
);
3583 if (ctx
->NewState
& _NEW_PIXEL
)
3584 _mesa_update_state(ctx
);
3586 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3590 _mesa_lock_texture(ctx
, texObj
);
3592 if (texObj
->Immutable
) {
3593 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3594 "glEGLImageTargetTexture2D(texture is immutable)");
3595 _mesa_unlock_texture(ctx
, texObj
);
3599 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3601 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3603 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3605 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3606 texObj
, texImage
, image
);
3608 _mesa_dirty_texobj(ctx
, texObj
);
3610 _mesa_unlock_texture(ctx
, texObj
);
3615 * Helper that implements the glTexSubImage1/2/3D()
3616 * and glTextureSubImage1/2/3D() functions.
3619 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3620 struct gl_texture_object
*texObj
,
3621 struct gl_texture_image
*texImage
,
3622 GLenum target
, GLint level
,
3623 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3624 GLsizei width
, GLsizei height
, GLsizei depth
,
3625 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3628 FLUSH_VERTICES(ctx
, 0);
3630 if (ctx
->NewState
& _NEW_PIXEL
)
3631 _mesa_update_state(ctx
);
3633 _mesa_lock_texture(ctx
, texObj
);
3635 if (width
> 0 && height
> 0 && depth
> 0) {
3636 /* If we have a border, offset=-1 is legal. Bias by border width. */
3639 if (target
!= GL_TEXTURE_2D_ARRAY
)
3640 zoffset
+= texImage
->Border
;
3643 if (target
!= GL_TEXTURE_1D_ARRAY
)
3644 yoffset
+= texImage
->Border
;
3647 xoffset
+= texImage
->Border
;
3650 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3651 xoffset
, yoffset
, zoffset
,
3652 width
, height
, depth
,
3653 format
, type
, pixels
, &ctx
->Unpack
);
3655 check_gen_mipmap(ctx
, target
, texObj
, level
);
3657 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3658 * the texel data, not the texture format, size, etc.
3662 _mesa_unlock_texture(ctx
, texObj
);
3666 * Implement all the glTexSubImage1/2/3D() functions.
3667 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3670 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3671 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3672 GLsizei width
, GLsizei height
, GLsizei depth
,
3673 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3674 const char *callerName
)
3676 struct gl_texture_object
*texObj
;
3677 struct gl_texture_image
*texImage
;
3679 /* check target (proxies not allowed) */
3680 if (!legal_texsubimage_target(ctx
, dims
, target
, false)) {
3681 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3682 dims
, _mesa_enum_to_string(target
));
3686 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3690 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3691 xoffset
, yoffset
, zoffset
,
3692 width
, height
, depth
, format
, type
,
3693 pixels
, false, callerName
)) {
3694 return; /* error was detected */
3697 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3698 /* texsubimage_error_check ensures that texImage is not NULL */
3700 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3701 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3703 _mesa_enum_to_string(target
), level
,
3704 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3705 _mesa_enum_to_string(format
),
3706 _mesa_enum_to_string(type
), pixels
);
3708 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3709 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3710 format
, type
, pixels
, false);
3715 * Implement all the glTextureSubImage1/2/3D() functions.
3716 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3719 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3720 GLuint texture
, GLint level
,
3721 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3722 GLsizei width
, GLsizei height
, GLsizei depth
,
3723 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3724 const char *callerName
)
3726 struct gl_texture_object
*texObj
;
3727 struct gl_texture_image
*texImage
;
3730 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3732 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3733 dims
, texture
, level
,
3734 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3735 _mesa_enum_to_string(format
),
3736 _mesa_enum_to_string(type
), pixels
);
3738 /* Get the texture object by Name. */
3739 texObj
= _mesa_lookup_texture(ctx
, texture
);
3741 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3746 /* check target (proxies not allowed) */
3747 if (!legal_texsubimage_target(ctx
, dims
, texObj
->Target
, true)) {
3748 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
3749 callerName
, _mesa_enum_to_string(texObj
->Target
));
3753 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3754 xoffset
, yoffset
, zoffset
,
3755 width
, height
, depth
, format
, type
,
3756 pixels
, true, callerName
)) {
3757 return; /* error was detected */
3761 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3762 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3766 * What do we do if the user created a texture with the following code
3767 * and then called this function with its handle?
3770 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3771 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3772 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3773 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3774 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3775 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3776 * // wrong format, or given the wrong size, etc.
3777 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3778 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3780 * A bug has been filed against the spec for this case. In the
3781 * meantime, we will check for cube completeness.
3783 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3784 * Core Profile spec (30.10.2014):
3785 * "[A] cube map texture is cube complete if the
3786 * following conditions all hold true: The [base level] texture
3787 * images of each of the six cube map faces have identical, positive,
3788 * and square dimensions. The [base level] images were each specified
3789 * with the same internal format."
3791 * It seems reasonable to check for cube completeness of an arbitrary
3792 * level here so that the image data has a consistent format and size.
3794 if (!_mesa_cube_level_complete(texObj
, level
)) {
3795 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3796 "glTextureSubImage%uD(cube map incomplete)",
3801 rowStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3803 /* Copy in each face. */
3804 for (i
= 0; i
< 6; ++i
) {
3805 texImage
= texObj
->Image
[i
][level
];
3808 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3809 level
, xoffset
, yoffset
, zoffset
,
3810 width
, height
, 1, format
,
3811 type
, pixels
, true);
3812 pixels
= (GLubyte
*) pixels
+ rowStride
;
3816 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3819 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3820 level
, xoffset
, yoffset
, zoffset
,
3821 width
, height
, depth
, format
,
3822 type
, pixels
, true);
3828 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3829 GLint xoffset
, GLsizei width
,
3830 GLenum format
, GLenum type
,
3831 const GLvoid
*pixels
)
3833 GET_CURRENT_CONTEXT(ctx
);
3834 texsubimage(ctx
, 1, target
, level
,
3837 format
, type
, pixels
, "glTexSubImage1D");
3842 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3843 GLint xoffset
, GLint yoffset
,
3844 GLsizei width
, GLsizei height
,
3845 GLenum format
, GLenum type
,
3846 const GLvoid
*pixels
)
3848 GET_CURRENT_CONTEXT(ctx
);
3849 texsubimage(ctx
, 2, target
, level
,
3850 xoffset
, yoffset
, 0,
3852 format
, type
, pixels
, "glTexSubImage2D");
3858 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3859 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3860 GLsizei width
, GLsizei height
, GLsizei depth
,
3861 GLenum format
, GLenum type
,
3862 const GLvoid
*pixels
)
3864 GET_CURRENT_CONTEXT(ctx
);
3865 texsubimage(ctx
, 3, target
, level
,
3866 xoffset
, yoffset
, zoffset
,
3867 width
, height
, depth
,
3868 format
, type
, pixels
, "glTexSubImage3D");
3872 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3873 GLint xoffset
, GLsizei width
,
3874 GLenum format
, GLenum type
,
3875 const GLvoid
*pixels
)
3877 GET_CURRENT_CONTEXT(ctx
);
3878 texturesubimage(ctx
, 1, texture
, level
,
3881 format
, type
, pixels
, "glTextureSubImage1D");
3886 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3887 GLint xoffset
, GLint yoffset
,
3888 GLsizei width
, GLsizei height
,
3889 GLenum format
, GLenum type
,
3890 const GLvoid
*pixels
)
3892 GET_CURRENT_CONTEXT(ctx
);
3893 texturesubimage(ctx
, 2, texture
, level
,
3894 xoffset
, yoffset
, 0,
3896 format
, type
, pixels
, "glTextureSubImage2D");
3901 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3902 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3903 GLsizei width
, GLsizei height
, GLsizei depth
,
3904 GLenum format
, GLenum type
,
3905 const GLvoid
*pixels
)
3907 GET_CURRENT_CONTEXT(ctx
);
3908 texturesubimage(ctx
, 3, texture
, level
,
3909 xoffset
, yoffset
, zoffset
,
3910 width
, height
, depth
,
3911 format
, type
, pixels
, "glTextureSubImage3D");
3916 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3917 * from. This depends on whether the texture contains color or depth values.
3919 static struct gl_renderbuffer
*
3920 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3922 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3923 /* reading from depth/stencil buffer */
3924 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3927 /* copying from color buffer */
3928 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3933 copytexsubimage_by_slice(struct gl_context
*ctx
,
3934 struct gl_texture_image
*texImage
,
3936 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3937 struct gl_renderbuffer
*rb
,
3939 GLsizei width
, GLsizei height
)
3941 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3944 /* For 1D arrays, we copy each scanline of the source rectangle into the
3947 assert(zoffset
== 0);
3949 for (slice
= 0; slice
< height
; slice
++) {
3950 assert(yoffset
+ slice
< texImage
->Height
);
3951 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3952 xoffset
, 0, yoffset
+ slice
,
3953 rb
, x
, y
+ slice
, width
, 1);
3956 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3957 xoffset
, yoffset
, zoffset
,
3958 rb
, x
, y
, width
, height
);
3963 formats_differ_in_component_sizes(mesa_format f1
, mesa_format f2
)
3965 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3966 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3967 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3968 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3970 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3971 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3972 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3973 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3975 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3976 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3977 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3978 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3985 * Implement the glCopyTexImage1/2D() functions.
3988 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3989 GLenum target
, GLint level
, GLenum internalFormat
,
3990 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3992 struct gl_texture_object
*texObj
;
3993 struct gl_texture_image
*texImage
;
3994 const GLuint face
= _mesa_tex_target_to_face(target
);
3995 mesa_format texFormat
;
3996 struct gl_renderbuffer
*rb
;
3998 FLUSH_VERTICES(ctx
, 0);
4000 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4001 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
4003 _mesa_enum_to_string(target
), level
,
4004 _mesa_enum_to_string(internalFormat
),
4005 x
, y
, width
, height
, border
);
4007 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4008 _mesa_update_state(ctx
);
4010 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
4011 width
, height
, border
))
4014 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
4016 _mesa_error(ctx
, GL_INVALID_VALUE
,
4017 "glCopyTexImage%uD(invalid width or height)", dims
);
4021 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4024 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
4025 internalFormat
, GL_NONE
, GL_NONE
);
4027 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
4029 if (_mesa_is_gles3(ctx
)) {
4030 if (_mesa_is_enum_format_unsized(internalFormat
)) {
4031 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
4032 * OpenGL ES 3.0. Khronos bug# 9807.
4034 if (rb
->InternalFormat
== GL_RGB10_A2
) {
4035 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4036 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer"
4037 " and writing to unsized internal format)", dims
);
4041 /* From Page 139 of OpenGL ES 3.0 spec:
4042 * "If internalformat is sized, the internal format of the new texel
4043 * array is internalformat, and this is also the new texel array’s
4044 * effective internal format. If the component sizes of internalformat
4045 * do not exactly match the corresponding component sizes of the source
4046 * buffer’s effective internal format, described below, an
4047 * INVALID_OPERATION error is generated. If internalformat is unsized,
4048 * the internal format of the new texel array is the effective internal
4049 * format of the source buffer, and this is also the new texel array’s
4050 * effective internal format.
4052 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
4053 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4054 "glCopyTexImage%uD(componenet size changed in"
4055 " internal format)", dims
);
4060 assert(texFormat
!= MESA_FORMAT_NONE
);
4062 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
4064 width
, height
, 1, border
)) {
4065 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4066 "glCopyTexImage%uD(image too large)", dims
);
4070 if (border
&& ctx
->Const
.StripTextureBorder
) {
4072 width
-= border
* 2;
4075 height
-= border
* 2;
4080 _mesa_lock_texture(ctx
, texObj
);
4082 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
4085 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
4088 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
4090 /* Free old texture image */
4091 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4093 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
4094 border
, internalFormat
, texFormat
);
4096 if (width
&& height
) {
4097 /* Allocate texture memory (no pixel data yet) */
4098 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
4100 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
4102 struct gl_renderbuffer
*srcRb
=
4103 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4105 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4107 srcRb
, srcX
, srcY
, width
, height
);
4110 check_gen_mipmap(ctx
, target
, texObj
, level
);
4113 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
4115 _mesa_dirty_texobj(ctx
, texObj
);
4118 _mesa_unlock_texture(ctx
, texObj
);
4124 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4125 GLenum internalFormat
,
4127 GLsizei width
, GLint border
)
4129 GET_CURRENT_CONTEXT(ctx
);
4130 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4136 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4137 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4140 GET_CURRENT_CONTEXT(ctx
);
4141 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4142 x
, y
, width
, height
, border
);
4146 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4149 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4150 struct gl_texture_object
*texObj
,
4151 GLenum target
, GLint level
,
4152 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4154 GLsizei width
, GLsizei height
,
4157 struct gl_texture_image
*texImage
;
4159 FLUSH_VERTICES(ctx
, 0);
4161 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4162 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
4163 _mesa_enum_to_string(target
),
4164 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4166 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4167 _mesa_update_state(ctx
);
4169 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4170 xoffset
, yoffset
, zoffset
,
4171 width
, height
, caller
)) {
4175 _mesa_lock_texture(ctx
, texObj
);
4177 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4179 /* If we have a border, offset=-1 is legal. Bias by border width. */
4182 if (target
!= GL_TEXTURE_2D_ARRAY
)
4183 zoffset
+= texImage
->Border
;
4186 if (target
!= GL_TEXTURE_1D_ARRAY
)
4187 yoffset
+= texImage
->Border
;
4190 xoffset
+= texImage
->Border
;
4193 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4195 struct gl_renderbuffer
*srcRb
=
4196 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4198 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4199 xoffset
, yoffset
, zoffset
,
4200 srcRb
, x
, y
, width
, height
);
4202 check_gen_mipmap(ctx
, target
, texObj
, level
);
4204 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4205 * the texel data, not the texture format, size, etc.
4209 _mesa_unlock_texture(ctx
, texObj
);
4213 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4214 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4216 struct gl_texture_object
* texObj
;
4217 const char *self
= "glCopyTexSubImage1D";
4218 GET_CURRENT_CONTEXT(ctx
);
4220 /* Check target (proxies not allowed). Target must be checked prior to
4221 * calling _mesa_get_current_tex_object.
4223 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4224 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4225 _mesa_enum_to_string(target
));
4229 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4233 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4234 x
, y
, width
, 1, self
);
4240 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4241 GLint xoffset
, GLint yoffset
,
4242 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4244 struct gl_texture_object
* texObj
;
4245 const char *self
= "glCopyTexSubImage2D";
4246 GET_CURRENT_CONTEXT(ctx
);
4248 /* Check target (proxies not allowed). Target must be checked prior to
4249 * calling _mesa_get_current_tex_object.
4251 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4252 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4253 _mesa_enum_to_string(target
));
4257 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4261 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4262 xoffset
, yoffset
, 0,
4263 x
, y
, width
, height
, self
);
4269 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4270 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4271 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4273 struct gl_texture_object
* texObj
;
4274 const char *self
= "glCopyTexSubImage3D";
4275 GET_CURRENT_CONTEXT(ctx
);
4277 /* Check target (proxies not allowed). Target must be checked prior to
4278 * calling _mesa_get_current_tex_object.
4280 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4281 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4282 _mesa_enum_to_string(target
));
4286 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4290 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4291 xoffset
, yoffset
, zoffset
,
4292 x
, y
, width
, height
, self
);
4296 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4297 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4299 struct gl_texture_object
* texObj
;
4300 const char *self
= "glCopyTextureSubImage1D";
4301 GET_CURRENT_CONTEXT(ctx
);
4303 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4307 /* Check target (proxies not allowed). */
4308 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4309 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4310 _mesa_enum_to_string(texObj
->Target
));
4314 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4315 xoffset
, 0, 0, x
, y
, width
, 1, self
);
4319 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4320 GLint xoffset
, GLint yoffset
,
4321 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4323 struct gl_texture_object
* texObj
;
4324 const char *self
= "glCopyTextureSubImage2D";
4325 GET_CURRENT_CONTEXT(ctx
);
4327 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4331 /* Check target (proxies not allowed). */
4332 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4333 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4334 _mesa_enum_to_string(texObj
->Target
));
4338 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4339 xoffset
, yoffset
, 0,
4340 x
, y
, width
, height
, self
);
4346 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4347 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4348 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4350 struct gl_texture_object
* texObj
;
4351 const char *self
= "glCopyTextureSubImage3D";
4352 GET_CURRENT_CONTEXT(ctx
);
4354 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4358 /* Check target (proxies not allowed). */
4359 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4360 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4361 _mesa_enum_to_string(texObj
->Target
));
4365 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4366 /* Act like CopyTexSubImage2D */
4367 _mesa_copy_texture_sub_image(ctx
, 2, texObj
,
4368 GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ zoffset
,
4369 level
, xoffset
, yoffset
, 0,
4370 x
, y
, width
, height
, self
);
4373 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4374 xoffset
, yoffset
, zoffset
,
4375 x
, y
, width
, height
, self
);
4379 check_clear_tex_image(struct gl_context
*ctx
,
4380 const char *function
,
4381 struct gl_texture_image
*texImage
,
4382 GLenum format
, GLenum type
,
4384 GLubyte
*clearValue
)
4386 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4387 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4388 GLenum internalFormat
= texImage
->InternalFormat
;
4391 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4392 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4393 "%s(buffer texture)", function
);
4397 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4398 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4399 "%s(compressed texture)", function
);
4403 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4404 if (err
!= GL_NO_ERROR
) {
4405 _mesa_error(ctx
, err
,
4406 "%s(incompatible format = %s, type = %s)",
4408 _mesa_enum_to_string(format
),
4409 _mesa_enum_to_string(type
));
4413 /* make sure internal format and format basically agree */
4414 if (!texture_formats_agree(internalFormat
, format
)) {
4415 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4416 "%s(incompatible internalFormat = %s, format = %s)",
4418 _mesa_enum_to_string(internalFormat
),
4419 _mesa_enum_to_string(format
));
4423 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4424 /* both source and dest must be integer-valued, or neither */
4425 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4426 _mesa_is_enum_format_integer(format
)) {
4427 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4428 "%s(integer/non-integer format mismatch)",
4434 if (!_mesa_texstore(ctx
,
4436 texImage
->_BaseFormat
,
4437 texImage
->TexFormat
,
4438 0, /* dstRowStride */
4440 1, 1, 1, /* srcWidth/Height/Depth */
4442 data
? data
: zeroData
,
4443 &ctx
->DefaultPacking
)) {
4444 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4451 static struct gl_texture_object
*
4452 get_tex_obj_for_clear(struct gl_context
*ctx
,
4453 const char *function
,
4456 struct gl_texture_object
*texObj
;
4459 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4463 texObj
= _mesa_lookup_texture(ctx
, texture
);
4465 if (texObj
== NULL
) {
4466 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4470 if (texObj
->Target
== 0) {
4471 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4479 get_tex_images_for_clear(struct gl_context
*ctx
,
4480 const char *function
,
4481 struct gl_texture_object
*texObj
,
4483 struct gl_texture_image
**texImages
)
4488 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4489 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4493 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4494 for (i
= 0; i
< MAX_FACES
; i
++) {
4495 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4497 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4498 if (texImages
[i
] == NULL
) {
4499 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4500 "%s(invalid level)", function
);
4508 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4510 if (texImages
[0] == NULL
) {
4511 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4519 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4520 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4521 GLsizei width
, GLsizei height
, GLsizei depth
,
4522 GLenum format
, GLenum type
, const void *data
)
4524 GET_CURRENT_CONTEXT(ctx
);
4525 struct gl_texture_object
*texObj
;
4526 struct gl_texture_image
*texImages
[MAX_FACES
];
4527 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4529 int minDepth
, maxDepth
;
4531 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4536 _mesa_lock_texture(ctx
, texObj
);
4538 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4539 texObj
, level
, texImages
);
4543 if (numImages
== 1) {
4544 minDepth
= -(int) texImages
[0]->Border
;
4545 maxDepth
= texImages
[0]->Depth
;
4548 maxDepth
= numImages
;
4551 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4552 yoffset
< -(GLint
) texImages
[0]->Border
||
4553 zoffset
< minDepth
||
4557 xoffset
+ width
> texImages
[0]->Width
||
4558 yoffset
+ height
> texImages
[0]->Height
||
4559 zoffset
+ depth
> maxDepth
) {
4560 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4561 "glClearSubTexImage(invalid dimensions)");
4565 if (numImages
== 1) {
4566 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4568 format
, type
, data
, clearValue
[0])) {
4569 ctx
->Driver
.ClearTexSubImage(ctx
,
4571 xoffset
, yoffset
, zoffset
,
4572 width
, height
, depth
,
4573 data
? clearValue
[0] : NULL
);
4576 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4577 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4579 format
, type
, data
, clearValue
[i
]))
4582 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4583 ctx
->Driver
.ClearTexSubImage(ctx
,
4585 xoffset
, yoffset
, 0,
4587 data
? clearValue
[i
] : NULL
);
4592 _mesa_unlock_texture(ctx
, texObj
);
4596 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4597 GLenum format
, GLenum type
, const void *data
)
4599 GET_CURRENT_CONTEXT(ctx
);
4600 struct gl_texture_object
*texObj
;
4601 struct gl_texture_image
*texImages
[MAX_FACES
];
4602 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4605 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4610 _mesa_lock_texture(ctx
, texObj
);
4612 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4613 texObj
, level
, texImages
);
4615 for (i
= 0; i
< numImages
; i
++) {
4616 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4623 for (i
= 0; i
< numImages
; i
++) {
4624 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4625 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4626 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4627 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4628 texImages
[i
]->Width
,
4629 texImages
[i
]->Height
,
4630 texImages
[i
]->Depth
,
4631 data
? clearValue
[i
] : NULL
);
4635 _mesa_unlock_texture(ctx
, texObj
);
4641 /**********************************************************************/
4642 /****** Compressed Textures ******/
4643 /**********************************************************************/
4647 * Target checking for glCompressedTexSubImage[123]D().
4648 * \return GL_TRUE if error, GL_FALSE if no error
4649 * Must come before other error checking so that the texture object can
4650 * be correctly retrieved using _mesa_get_current_tex_object.
4653 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4654 GLint dims
, GLenum format
, bool dsa
,
4659 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4660 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4661 _mesa_enum_to_string(target
));
4671 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4672 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4673 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4674 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4675 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4676 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4677 targetOK
= ctx
->Extensions
.ARB_texture_cube_map
;
4680 targetOK
= GL_FALSE
;
4686 case GL_TEXTURE_CUBE_MAP
:
4687 targetOK
= dsa
&& ctx
->Extensions
.ARB_texture_cube_map
;
4689 case GL_TEXTURE_2D_ARRAY
:
4690 targetOK
= _mesa_is_gles3(ctx
) ||
4691 (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
);
4693 case GL_TEXTURE_CUBE_MAP_ARRAY
:
4694 targetOK
= ctx
->Extensions
.ARB_texture_cube_map_array
;
4699 * OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4701 * "An INVALID_OPERATION error is generated by
4702 * CompressedTex*SubImage3D if the internal format of the texture
4703 * is one of the EAC, ETC2, or RGTC formats and either border is
4704 * non-zero, or the effective target for the texture is not
4705 * TEXTURE_2D_ARRAY."
4707 * NOTE: that's probably a spec error. It should probably say
4708 * "... or the effective target for the texture is not
4709 * TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP, nor
4710 * GL_TEXTURE_CUBE_MAP_ARRAY."
4711 * since those targets are 2D images and they support all compression
4714 * Instead of listing all these, just list those which are allowed,
4715 * which is (at this time) only bptc. Otherwise we'd say s3tc (and
4716 * more) are valid here, which they are not, but of course not
4717 * mentioned by core spec.
4720 /* These are the only 3D compression formats supported at this time */
4721 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
4722 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
4723 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
4724 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
4728 /* invalid format */
4729 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4730 "%s(invalid target %s for format %s)", caller
,
4731 _mesa_enum_to_string(target
),
4732 _mesa_enum_to_string(format
));
4737 targetOK
= GL_FALSE
;
4743 /* no 1D compressed textures at this time */
4744 targetOK
= GL_FALSE
;
4749 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4750 _mesa_enum_to_string(target
));
4758 * Error checking for glCompressedTexSubImage[123]D().
4759 * \return GL_TRUE if error, GL_FALSE if no error
4762 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4763 const struct gl_texture_object
*texObj
,
4764 GLenum target
, GLint level
,
4765 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4766 GLsizei width
, GLsizei height
, GLsizei depth
,
4767 GLenum format
, GLsizei imageSize
,
4768 const GLvoid
*data
, const char *callerName
)
4770 struct gl_texture_image
*texImage
;
4773 /* this will catch any invalid compressed format token */
4774 if (!_mesa_is_compressed_format(ctx
, format
)) {
4775 _mesa_error(ctx
, GL_INVALID_ENUM
,
4776 "%s(format)", callerName
);
4780 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4781 _mesa_error(ctx
, GL_INVALID_VALUE
,
4787 /* validate the bound PBO, if any */
4788 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4789 imageSize
, data
, callerName
)) {
4793 /* Check for invalid pixel storage modes */
4794 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4795 &ctx
->Unpack
, callerName
)) {
4799 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4800 if (expectedSize
!= imageSize
) {
4801 _mesa_error(ctx
, GL_INVALID_VALUE
,
4803 callerName
, imageSize
);
4807 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4809 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4810 "%s(invalid texture image)",
4815 if ((GLint
) format
!= texImage
->InternalFormat
) {
4816 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4818 callerName
, format
);
4822 if (compressedteximage_only_format(ctx
, format
)) {
4823 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4824 "%s(format=0x%x cannot be updated)",
4825 callerName
, format
);
4829 if (error_check_subtexture_dimensions(ctx
, dims
,
4830 texImage
, xoffset
, yoffset
, zoffset
,
4831 width
, height
, depth
,
4841 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4842 GLenum internalFormat
, GLsizei width
,
4843 GLint border
, GLsizei imageSize
,
4846 GET_CURRENT_CONTEXT(ctx
);
4847 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4848 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4853 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4854 GLenum internalFormat
, GLsizei width
,
4855 GLsizei height
, GLint border
, GLsizei imageSize
,
4858 GET_CURRENT_CONTEXT(ctx
);
4859 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4860 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4865 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4866 GLenum internalFormat
, GLsizei width
,
4867 GLsizei height
, GLsizei depth
, GLint border
,
4868 GLsizei imageSize
, const GLvoid
*data
)
4870 GET_CURRENT_CONTEXT(ctx
);
4871 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4872 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4877 * Common helper for glCompressedTexSubImage1/2/3D() and
4878 * glCompressedTextureSubImage1/2/3D().
4881 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4882 struct gl_texture_object
*texObj
,
4883 struct gl_texture_image
*texImage
,
4884 GLenum target
, GLint level
,
4885 GLint xoffset
, GLint yoffset
,
4887 GLsizei width
, GLsizei height
,
4889 GLenum format
, GLsizei imageSize
,
4892 FLUSH_VERTICES(ctx
, 0);
4894 _mesa_lock_texture(ctx
, texObj
);
4896 if (width
> 0 && height
> 0 && depth
> 0) {
4897 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4898 xoffset
, yoffset
, zoffset
,
4899 width
, height
, depth
,
4900 format
, imageSize
, data
);
4902 check_gen_mipmap(ctx
, target
, texObj
, level
);
4904 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4905 * the texel data, not the texture format, size, etc.
4909 _mesa_unlock_texture(ctx
, texObj
);
4914 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4915 GLsizei width
, GLenum format
,
4916 GLsizei imageSize
, const GLvoid
*data
)
4918 struct gl_texture_object
*texObj
;
4919 struct gl_texture_image
*texImage
;
4921 GET_CURRENT_CONTEXT(ctx
);
4923 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4924 "glCompressedTexSubImage1D")) {
4928 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4932 if (compressed_subtexture_error_check(ctx
, 1, texObj
, target
,
4933 level
, xoffset
, 0, 0,
4935 format
, imageSize
, data
,
4936 "glCompressedTexSubImage1D")) {
4940 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4943 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
4944 xoffset
, 0, 0, width
, 1, 1,
4945 format
, imageSize
, data
);
4949 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4950 GLsizei width
, GLenum format
,
4951 GLsizei imageSize
, const GLvoid
*data
)
4953 struct gl_texture_object
*texObj
;
4954 struct gl_texture_image
*texImage
;
4956 GET_CURRENT_CONTEXT(ctx
);
4958 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4959 "glCompressedTextureSubImage1D");
4963 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
, true,
4964 "glCompressedTextureSubImage1D")) {
4968 if (compressed_subtexture_error_check(ctx
, 1, texObj
, texObj
->Target
,
4969 level
, xoffset
, 0, 0,
4971 format
, imageSize
, data
,
4972 "glCompressedTextureSubImage1D")) {
4976 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4979 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
,
4980 texObj
->Target
, level
,
4981 xoffset
, 0, 0, width
, 1, 1,
4982 format
, imageSize
, data
);
4987 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4988 GLint yoffset
, GLsizei width
, GLsizei height
,
4989 GLenum format
, GLsizei imageSize
,
4992 struct gl_texture_object
*texObj
;
4993 struct gl_texture_image
*texImage
;
4995 GET_CURRENT_CONTEXT(ctx
);
4997 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
4998 "glCompressedTexSubImage2D")) {
5002 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5006 if (compressed_subtexture_error_check(ctx
, 2, texObj
, target
,
5007 level
, xoffset
, yoffset
, 0,
5009 format
, imageSize
, data
,
5010 "glCompressedTexSubImage2D")) {
5015 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5018 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
5019 xoffset
, yoffset
, 0, width
, height
, 1,
5020 format
, imageSize
, data
);
5024 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
5026 GLsizei width
, GLsizei height
,
5027 GLenum format
, GLsizei imageSize
,
5030 struct gl_texture_object
*texObj
;
5031 struct gl_texture_image
*texImage
;
5033 GET_CURRENT_CONTEXT(ctx
);
5035 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5036 "glCompressedTextureSubImage2D");
5040 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
, true,
5041 "glCompressedTextureSubImage2D")) {
5045 if (compressed_subtexture_error_check(ctx
, 2, texObj
, texObj
->Target
,
5046 level
, xoffset
, yoffset
, 0,
5048 format
, imageSize
, data
,
5049 "glCompressedTextureSubImage2D")) {
5053 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5056 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
,
5057 texObj
->Target
, level
,
5058 xoffset
, yoffset
, 0, width
, height
, 1,
5059 format
, imageSize
, data
);
5063 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
5064 GLint yoffset
, GLint zoffset
, GLsizei width
,
5065 GLsizei height
, GLsizei depth
, GLenum format
,
5066 GLsizei imageSize
, const GLvoid
*data
)
5068 struct gl_texture_object
*texObj
;
5069 struct gl_texture_image
*texImage
;
5071 GET_CURRENT_CONTEXT(ctx
);
5073 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
5074 "glCompressedTexSubImage3D")) {
5078 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5082 if (compressed_subtexture_error_check(ctx
, 3, texObj
, target
,
5083 level
, xoffset
, yoffset
, zoffset
,
5084 width
, height
, depth
,
5085 format
, imageSize
, data
,
5086 "glCompressedTexSubImage3D")) {
5091 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
5094 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
5095 xoffset
, yoffset
, zoffset
,
5096 width
, height
, depth
,
5097 format
, imageSize
, data
);
5101 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
5102 GLint yoffset
, GLint zoffset
, GLsizei width
,
5103 GLsizei height
, GLsizei depth
,
5104 GLenum format
, GLsizei imageSize
,
5107 struct gl_texture_object
*texObj
;
5108 struct gl_texture_image
*texImage
;
5110 GET_CURRENT_CONTEXT(ctx
);
5112 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5113 "glCompressedTextureSubImage3D");
5117 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
, true,
5118 "glCompressedTextureSubImage3D")) {
5122 if (compressed_subtexture_error_check(ctx
, 3, texObj
, texObj
->Target
,
5123 level
, xoffset
, yoffset
, zoffset
,
5124 width
, height
, depth
,
5125 format
, imageSize
, data
,
5126 "glCompressedTextureSubImage3D")) {
5130 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
5131 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
5132 const char *pixels
= data
;
5136 /* Make sure the texture object is a proper cube.
5137 * (See texturesubimage in teximage.c for details on why this check is
5140 if (!_mesa_cube_level_complete(texObj
, level
)) {
5141 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5142 "glCompressedTextureSubImage3D(cube map incomplete)");
5146 /* Copy in each face. */
5147 for (i
= 0; i
< 6; ++i
) {
5148 texImage
= texObj
->Image
[i
][level
];
5151 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5152 texObj
->Target
, level
,
5153 xoffset
, yoffset
, zoffset
,
5155 format
, imageSize
, pixels
);
5157 /* Compressed images don't have a client format */
5158 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5160 texImage
->Height
, 1);
5162 pixels
+= image_stride
;
5163 imageSize
-= image_stride
;
5167 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5170 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5171 texObj
->Target
, level
,
5172 xoffset
, yoffset
, zoffset
,
5173 width
, height
, depth
,
5174 format
, imageSize
, data
);
5179 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5181 if (ctx
->API
!= API_OPENGL_CORE
) {
5182 switch (internalFormat
) {
5184 return MESA_FORMAT_A_UNORM8
;
5186 return MESA_FORMAT_A_UNORM16
;
5187 case GL_ALPHA16F_ARB
:
5188 return MESA_FORMAT_A_FLOAT16
;
5189 case GL_ALPHA32F_ARB
:
5190 return MESA_FORMAT_A_FLOAT32
;
5191 case GL_ALPHA8I_EXT
:
5192 return MESA_FORMAT_A_SINT8
;
5193 case GL_ALPHA16I_EXT
:
5194 return MESA_FORMAT_A_SINT16
;
5195 case GL_ALPHA32I_EXT
:
5196 return MESA_FORMAT_A_SINT32
;
5197 case GL_ALPHA8UI_EXT
:
5198 return MESA_FORMAT_A_UINT8
;
5199 case GL_ALPHA16UI_EXT
:
5200 return MESA_FORMAT_A_UINT16
;
5201 case GL_ALPHA32UI_EXT
:
5202 return MESA_FORMAT_A_UINT32
;
5204 return MESA_FORMAT_L_UNORM8
;
5205 case GL_LUMINANCE16
:
5206 return MESA_FORMAT_L_UNORM16
;
5207 case GL_LUMINANCE16F_ARB
:
5208 return MESA_FORMAT_L_FLOAT16
;
5209 case GL_LUMINANCE32F_ARB
:
5210 return MESA_FORMAT_L_FLOAT32
;
5211 case GL_LUMINANCE8I_EXT
:
5212 return MESA_FORMAT_L_SINT8
;
5213 case GL_LUMINANCE16I_EXT
:
5214 return MESA_FORMAT_L_SINT16
;
5215 case GL_LUMINANCE32I_EXT
:
5216 return MESA_FORMAT_L_SINT32
;
5217 case GL_LUMINANCE8UI_EXT
:
5218 return MESA_FORMAT_L_UINT8
;
5219 case GL_LUMINANCE16UI_EXT
:
5220 return MESA_FORMAT_L_UINT16
;
5221 case GL_LUMINANCE32UI_EXT
:
5222 return MESA_FORMAT_L_UINT32
;
5223 case GL_LUMINANCE8_ALPHA8
:
5224 return MESA_FORMAT_L8A8_UNORM
;
5225 case GL_LUMINANCE16_ALPHA16
:
5226 return MESA_FORMAT_L16A16_UNORM
;
5227 case GL_LUMINANCE_ALPHA16F_ARB
:
5228 return MESA_FORMAT_LA_FLOAT16
;
5229 case GL_LUMINANCE_ALPHA32F_ARB
:
5230 return MESA_FORMAT_LA_FLOAT32
;
5231 case GL_LUMINANCE_ALPHA8I_EXT
:
5232 return MESA_FORMAT_LA_SINT8
;
5233 case GL_LUMINANCE_ALPHA16I_EXT
:
5234 return MESA_FORMAT_LA_SINT16
;
5235 case GL_LUMINANCE_ALPHA32I_EXT
:
5236 return MESA_FORMAT_LA_SINT32
;
5237 case GL_LUMINANCE_ALPHA8UI_EXT
:
5238 return MESA_FORMAT_LA_UINT8
;
5239 case GL_LUMINANCE_ALPHA16UI_EXT
:
5240 return MESA_FORMAT_LA_UINT16
;
5241 case GL_LUMINANCE_ALPHA32UI_EXT
:
5242 return MESA_FORMAT_LA_UINT32
;
5244 return MESA_FORMAT_I_UNORM8
;
5245 case GL_INTENSITY16
:
5246 return MESA_FORMAT_I_UNORM16
;
5247 case GL_INTENSITY16F_ARB
:
5248 return MESA_FORMAT_I_FLOAT16
;
5249 case GL_INTENSITY32F_ARB
:
5250 return MESA_FORMAT_I_FLOAT32
;
5251 case GL_INTENSITY8I_EXT
:
5252 return MESA_FORMAT_I_SINT8
;
5253 case GL_INTENSITY16I_EXT
:
5254 return MESA_FORMAT_I_SINT16
;
5255 case GL_INTENSITY32I_EXT
:
5256 return MESA_FORMAT_I_SINT32
;
5257 case GL_INTENSITY8UI_EXT
:
5258 return MESA_FORMAT_I_UINT8
;
5259 case GL_INTENSITY16UI_EXT
:
5260 return MESA_FORMAT_I_UINT16
;
5261 case GL_INTENSITY32UI_EXT
:
5262 return MESA_FORMAT_I_UINT32
;
5268 if (ctx
->API
== API_OPENGL_CORE
&&
5269 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5270 switch (internalFormat
) {
5272 return MESA_FORMAT_RGB_FLOAT32
;
5274 return MESA_FORMAT_RGB_UINT32
;
5276 return MESA_FORMAT_RGB_SINT32
;
5282 switch (internalFormat
) {
5284 return MESA_FORMAT_R8G8B8A8_UNORM
;
5286 return MESA_FORMAT_RGBA_UNORM16
;
5287 case GL_RGBA16F_ARB
:
5288 return MESA_FORMAT_RGBA_FLOAT16
;
5289 case GL_RGBA32F_ARB
:
5290 return MESA_FORMAT_RGBA_FLOAT32
;
5292 return MESA_FORMAT_RGBA_SINT8
;
5293 case GL_RGBA16I_EXT
:
5294 return MESA_FORMAT_RGBA_SINT16
;
5295 case GL_RGBA32I_EXT
:
5296 return MESA_FORMAT_RGBA_SINT32
;
5297 case GL_RGBA8UI_EXT
:
5298 return MESA_FORMAT_RGBA_UINT8
;
5299 case GL_RGBA16UI_EXT
:
5300 return MESA_FORMAT_RGBA_UINT16
;
5301 case GL_RGBA32UI_EXT
:
5302 return MESA_FORMAT_RGBA_UINT32
;
5305 return MESA_FORMAT_R8G8_UNORM
;
5307 return MESA_FORMAT_R16G16_UNORM
;
5309 return MESA_FORMAT_RG_FLOAT16
;
5311 return MESA_FORMAT_RG_FLOAT32
;
5313 return MESA_FORMAT_RG_SINT8
;
5315 return MESA_FORMAT_RG_SINT16
;
5317 return MESA_FORMAT_RG_SINT32
;
5319 return MESA_FORMAT_RG_UINT8
;
5321 return MESA_FORMAT_RG_UINT16
;
5323 return MESA_FORMAT_RG_UINT32
;
5326 return MESA_FORMAT_R_UNORM8
;
5328 return MESA_FORMAT_R_UNORM16
;
5330 return MESA_FORMAT_R_FLOAT16
;
5332 return MESA_FORMAT_R_FLOAT32
;
5334 return MESA_FORMAT_R_SINT8
;
5336 return MESA_FORMAT_R_SINT16
;
5338 return MESA_FORMAT_R_SINT32
;
5340 return MESA_FORMAT_R_UINT8
;
5342 return MESA_FORMAT_R_UINT16
;
5344 return MESA_FORMAT_R_UINT32
;
5347 return MESA_FORMAT_NONE
;
5353 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5354 GLenum internalFormat
)
5356 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5359 if (format
== MESA_FORMAT_NONE
)
5360 return MESA_FORMAT_NONE
;
5362 datatype
= _mesa_get_format_datatype(format
);
5364 /* The GL_ARB_texture_buffer_object spec says:
5366 * "If ARB_texture_float is not supported, references to the
5367 * floating-point internal formats provided by that extension should be
5368 * removed, and such formats may not be passed to TexBufferARB."
5370 * As a result, GL_HALF_FLOAT internal format depends on both
5371 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5373 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5374 !ctx
->Extensions
.ARB_texture_float
)
5375 return MESA_FORMAT_NONE
;
5377 if (!ctx
->Extensions
.ARB_texture_rg
) {
5378 GLenum base_format
= _mesa_get_format_base_format(format
);
5379 if (base_format
== GL_R
|| base_format
== GL_RG
)
5380 return MESA_FORMAT_NONE
;
5383 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5384 GLenum base_format
= _mesa_get_format_base_format(format
);
5385 if (base_format
== GL_RGB
)
5386 return MESA_FORMAT_NONE
;
5393 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5394 struct gl_texture_object
*texObj
,
5395 GLenum internalFormat
,
5396 struct gl_buffer_object
*bufObj
,
5397 GLintptr offset
, GLsizeiptr size
,
5402 /* NOTE: ARB_texture_buffer_object has interactions with
5403 * the compatibility profile that are not implemented.
5405 if (!(ctx
->API
== API_OPENGL_CORE
&&
5406 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5407 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5408 "%s(ARB_texture_buffer_object is not"
5409 " implemented for the compatibility profile)", caller
);
5413 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5414 if (format
== MESA_FORMAT_NONE
) {
5415 _mesa_error(ctx
, GL_INVALID_ENUM
,
5416 "%s(internalFormat 0x%x)", caller
, internalFormat
);
5420 FLUSH_VERTICES(ctx
, 0);
5422 _mesa_lock_texture(ctx
, texObj
);
5424 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5425 texObj
->BufferObjectFormat
= internalFormat
;
5426 texObj
->_BufferObjectFormat
= format
;
5427 texObj
->BufferOffset
= offset
;
5428 texObj
->BufferSize
= size
;
5430 _mesa_unlock_texture(ctx
, texObj
);
5432 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5435 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5441 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5442 * Return true if it is, and return false if it is not
5443 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5444 * core spec, 02.02.2015, PDF page 245).
5447 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5450 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5451 _mesa_error(ctx
, GL_INVALID_ENUM
,
5452 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5460 * Check for errors related to the texture buffer range.
5461 * Return false if errors are found, true if none are found.
5464 check_texture_buffer_range(struct gl_context
*ctx
,
5465 struct gl_buffer_object
*bufObj
,
5466 GLintptr offset
, GLsizeiptr size
,
5469 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5470 * Textures (PDF page 245):
5471 * "An INVALID_VALUE error is generated if offset is negative, if
5472 * size is less than or equal to zero, or if offset + size is greater
5473 * than the value of BUFFER_SIZE for the buffer bound to target."
5476 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5482 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5487 if (offset
+ size
> bufObj
->Size
) {
5488 _mesa_error(ctx
, GL_INVALID_VALUE
,
5489 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5490 (int) offset
, (int) size
, (int) bufObj
->Size
);
5494 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5495 * Textures (PDF page 245):
5496 * "An INVALID_VALUE error is generated if offset is not an integer
5497 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5499 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5500 _mesa_error(ctx
, GL_INVALID_VALUE
,
5501 "%s(invalid offset alignment)", caller
);
5509 /** GL_ARB_texture_buffer_object */
5511 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5513 struct gl_texture_object
*texObj
;
5514 struct gl_buffer_object
*bufObj
;
5516 GET_CURRENT_CONTEXT(ctx
);
5518 /* Need to catch a bad target before it gets to
5519 * _mesa_get_current_tex_object.
5521 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5525 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5531 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5535 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5536 buffer
? -1 : 0, "glTexBuffer");
5540 /** GL_ARB_texture_buffer_range */
5542 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5543 GLintptr offset
, GLsizeiptr size
)
5545 struct gl_texture_object
*texObj
;
5546 struct gl_buffer_object
*bufObj
;
5548 GET_CURRENT_CONTEXT(ctx
);
5550 /* Need to catch a bad target before it gets to
5551 * _mesa_get_current_tex_object.
5553 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5557 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5561 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5562 "glTexBufferRange"))
5566 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5567 * Textures (PDF page 254):
5568 * "If buffer is zero, then any buffer object attached to the buffer
5569 * texture is detached, the values offset and size are ignored and
5570 * the state for offset and size for the buffer texture are reset to
5578 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5582 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5583 offset
, size
, "glTexBufferRange");
5587 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5589 struct gl_texture_object
*texObj
;
5590 struct gl_buffer_object
*bufObj
;
5592 GET_CURRENT_CONTEXT(ctx
);
5595 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5601 /* Get the texture object by Name. */
5602 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5606 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5609 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5610 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5614 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5615 GLintptr offset
, GLsizeiptr size
)
5617 struct gl_texture_object
*texObj
;
5618 struct gl_buffer_object
*bufObj
;
5620 GET_CURRENT_CONTEXT(ctx
);
5623 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5624 "glTextureBufferRange");
5628 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5629 "glTextureBufferRange"))
5633 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5634 * Textures (PDF page 254):
5635 * "If buffer is zero, then any buffer object attached to the buffer
5636 * texture is detached, the values offset and size are ignored and
5637 * the state for offset and size for the buffer texture are reset to
5645 /* Get the texture object by Name. */
5646 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5650 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5651 "glTextureBufferRange"))
5654 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5655 bufObj
, offset
, size
, "glTextureBufferRange");
5659 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5661 /* Everything that is allowed for renderbuffers,
5662 * except for a base format of GL_STENCIL_INDEX, unless supported.
5664 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5665 if (ctx
->Extensions
.ARB_texture_stencil8
)
5666 return baseFormat
!= 0;
5668 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5672 /** GL_ARB_texture_multisample */
5674 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5677 case GL_TEXTURE_2D_MULTISAMPLE
:
5679 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5680 return dims
== 2 && !dsa
;
5681 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5683 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5684 return dims
== 3 && !dsa
;
5692 texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5693 struct gl_texture_object
*texObj
,
5694 GLenum target
, GLsizei samples
,
5695 GLint internalformat
, GLsizei width
,
5696 GLsizei height
, GLsizei depth
,
5697 GLboolean fixedsamplelocations
,
5698 GLboolean immutable
, const char *func
)
5700 struct gl_texture_image
*texImage
;
5701 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5702 mesa_format texFormat
;
5703 GLenum sample_count_error
;
5704 bool dsa
= strstr(func
, "ture") ? true : false;
5706 if (!((ctx
->Extensions
.ARB_texture_multisample
5707 && _mesa_is_desktop_gl(ctx
))) && !_mesa_is_gles31(ctx
)) {
5708 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5713 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(samples < 1)", func
);
5717 if (!check_multisample_target(dims
, target
, dsa
)) {
5719 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5723 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5728 /* check that the specified internalformat is color/depth/stencil-renderable;
5729 * refer GL3.1 spec 4.4.4
5732 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5733 _mesa_error(ctx
, GL_INVALID_ENUM
,
5734 "%s(internalformat=%s not legal for immutable-format)",
5735 func
, _mesa_enum_to_string(internalformat
));
5739 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5740 /* Page 172 of OpenGL ES 3.1 spec says:
5741 * "An INVALID_ENUM error is generated if sizedinternalformat is not
5742 * color-renderable, depth-renderable, or stencil-renderable (as
5743 * defined in section 9.4).
5745 * (Same error is also defined for desktop OpenGL for multisample
5746 * teximage/texstorage functions.)
5748 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(internalformat=%s)", func
,
5749 _mesa_enum_to_string(internalformat
));
5753 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5754 internalformat
, samples
);
5755 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5757 /* Page 254 of OpenGL 4.4 spec says:
5758 * "Proxy arrays for two-dimensional multisample and two-dimensional
5759 * multisample array textures are operated on in the same way when
5760 * TexImage2DMultisample is called with target specified as
5761 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5762 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5763 * However, if samples is not supported, then no error is generated.
5765 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5766 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5770 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5771 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5772 "%s(texture object 0)",
5777 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5779 if (texImage
== NULL
) {
5780 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5784 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5785 internalformat
, GL_NONE
, GL_NONE
);
5786 assert(texFormat
!= MESA_FORMAT_NONE
);
5788 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5789 width
, height
, depth
, 0);
5791 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5792 width
, height
, depth
, 0);
5794 if (_mesa_is_proxy_texture(target
)) {
5795 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5796 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5797 internalformat
, texFormat
,
5798 samples
, fixedsamplelocations
);
5801 /* clear all image fields */
5802 clear_teximage_fields(texImage
);
5806 if (!dimensionsOK
) {
5807 _mesa_error(ctx
, GL_INVALID_VALUE
,
5808 "%s(invalid width or height)", func
);
5813 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s(texture too large)", func
);
5817 /* Check if texObj->Immutable is set */
5818 if (texObj
->Immutable
) {
5819 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5823 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5825 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5826 internalformat
, texFormat
,
5827 samples
, fixedsamplelocations
);
5829 if (width
> 0 && height
> 0 && depth
> 0) {
5830 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5831 width
, height
, depth
)) {
5832 /* tidy up the texture image state. strictly speaking,
5833 * we're allowed to just leave this in whatever state we
5834 * like, but being tidy is good.
5836 _mesa_init_teximage_fields(ctx
, texImage
,
5837 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5841 texObj
->Immutable
|= immutable
;
5844 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5847 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5853 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5854 GLenum internalformat
, GLsizei width
,
5855 GLsizei height
, GLboolean fixedsamplelocations
)
5857 struct gl_texture_object
*texObj
;
5858 GET_CURRENT_CONTEXT(ctx
);
5860 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5864 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5865 internalformat
, width
, height
, 1,
5866 fixedsamplelocations
, GL_FALSE
,
5867 "glTexImage2DMultisample");
5872 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5873 GLenum internalformat
, GLsizei width
,
5874 GLsizei height
, GLsizei depth
,
5875 GLboolean fixedsamplelocations
)
5877 struct gl_texture_object
*texObj
;
5878 GET_CURRENT_CONTEXT(ctx
);
5880 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5884 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5885 internalformat
, width
, height
, depth
,
5886 fixedsamplelocations
, GL_FALSE
,
5887 "glTexImage3DMultisample");
5891 valid_texstorage_ms_parameters(GLsizei width
, GLsizei height
, GLsizei depth
,
5892 GLsizei samples
, unsigned dims
)
5894 GET_CURRENT_CONTEXT(ctx
);
5896 if (!_mesa_valid_tex_storage_dim(width
, height
, depth
)) {
5897 _mesa_error(ctx
, GL_INVALID_VALUE
,
5898 "glTexStorage%uDMultisample(width=%d,height=%d,depth=%d)",
5899 dims
, width
, height
, depth
);
5906 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5907 GLenum internalformat
, GLsizei width
,
5908 GLsizei height
, GLboolean fixedsamplelocations
)
5910 struct gl_texture_object
*texObj
;
5911 GET_CURRENT_CONTEXT(ctx
);
5913 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5917 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5920 texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5921 internalformat
, width
, height
, 1,
5922 fixedsamplelocations
, GL_TRUE
,
5923 "glTexStorage2DMultisample");
5927 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5928 GLenum internalformat
, GLsizei width
,
5929 GLsizei height
, GLsizei depth
,
5930 GLboolean fixedsamplelocations
)
5932 struct gl_texture_object
*texObj
;
5933 GET_CURRENT_CONTEXT(ctx
);
5935 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5939 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5942 texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5943 internalformat
, width
, height
, depth
,
5944 fixedsamplelocations
, GL_TRUE
,
5945 "glTexStorage3DMultisample");
5949 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5950 GLenum internalformat
, GLsizei width
,
5952 GLboolean fixedsamplelocations
)
5954 struct gl_texture_object
*texObj
;
5955 GET_CURRENT_CONTEXT(ctx
);
5957 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5958 "glTextureStorage2DMultisample");
5962 if (!valid_texstorage_ms_parameters(width
, height
, 1, samples
, 2))
5965 texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5966 internalformat
, width
, height
, 1,
5967 fixedsamplelocations
, GL_TRUE
,
5968 "glTextureStorage2DMultisample");
5972 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5973 GLenum internalformat
, GLsizei width
,
5974 GLsizei height
, GLsizei depth
,
5975 GLboolean fixedsamplelocations
)
5977 struct gl_texture_object
*texObj
;
5978 GET_CURRENT_CONTEXT(ctx
);
5980 /* Get the texture object by Name. */
5981 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5982 "glTextureStorage3DMultisample");
5986 if (!valid_texstorage_ms_parameters(width
, height
, depth
, samples
, 3))
5989 texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5990 internalformat
, width
, height
, depth
,
5991 fixedsamplelocations
, GL_TRUE
,
5992 "glTextureStorage3DMultisample");