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_stencil_texturing
) {
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
)
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
:
1789 * Helper function to determine whether a target and specific compression
1790 * format are supported.
1793 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1796 (void) intFormat
; /* not used yet */
1800 case GL_PROXY_TEXTURE_2D
:
1801 return GL_TRUE
; /* true for any compressed format so far */
1802 case GL_PROXY_TEXTURE_CUBE_MAP
:
1803 case GL_TEXTURE_CUBE_MAP
:
1804 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1805 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1806 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1807 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1808 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1809 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1810 return ctx
->Extensions
.ARB_texture_cube_map
;
1811 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1812 case GL_TEXTURE_2D_ARRAY_EXT
:
1813 return ctx
->Extensions
.EXT_texture_array
;
1814 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1815 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1816 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1824 * Check if the given texture target value is legal for a
1825 * glTexImage1/2/3D call.
1828 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1834 case GL_PROXY_TEXTURE_1D
:
1835 return _mesa_is_desktop_gl(ctx
);
1843 case GL_PROXY_TEXTURE_2D
:
1844 return _mesa_is_desktop_gl(ctx
);
1845 case GL_PROXY_TEXTURE_CUBE_MAP
:
1846 return _mesa_is_desktop_gl(ctx
)
1847 && ctx
->Extensions
.ARB_texture_cube_map
;
1848 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1850 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1851 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1852 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1853 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1854 return ctx
->Extensions
.ARB_texture_cube_map
;
1855 case GL_TEXTURE_RECTANGLE_NV
:
1856 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1857 return _mesa_is_desktop_gl(ctx
)
1858 && ctx
->Extensions
.NV_texture_rectangle
;
1859 case GL_TEXTURE_1D_ARRAY_EXT
:
1860 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1861 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1869 case GL_PROXY_TEXTURE_3D
:
1870 return _mesa_is_desktop_gl(ctx
);
1871 case GL_TEXTURE_2D_ARRAY_EXT
:
1872 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1873 || _mesa_is_gles3(ctx
);
1874 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1875 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1876 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1877 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1878 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1883 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1890 * Check if the given texture target value is legal for a
1891 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1892 * The difference compared to legal_teximage_target() above is that
1893 * proxy targets are not supported.
1896 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
,
1901 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1906 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1907 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1908 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1909 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1910 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1911 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1912 return ctx
->Extensions
.ARB_texture_cube_map
;
1913 case GL_TEXTURE_RECTANGLE_NV
:
1914 return _mesa_is_desktop_gl(ctx
)
1915 && ctx
->Extensions
.NV_texture_rectangle
;
1916 case GL_TEXTURE_1D_ARRAY_EXT
:
1917 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1925 case GL_TEXTURE_2D_ARRAY_EXT
:
1926 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1927 || _mesa_is_gles3(ctx
);
1928 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1929 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1930 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1932 /* Table 8.15 of the OpenGL 4.5 core profile spec
1933 * (20141030) says that TEXTURE_CUBE_MAP is valid for TextureSubImage3D
1934 * and CopyTextureSubImage3D.
1936 case GL_TEXTURE_CUBE_MAP
:
1942 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1950 * Helper function to determine if a texture object is mutable (in terms
1951 * of GL_ARB_texture_storage).
1954 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1956 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1960 return !texObj
->Immutable
;
1965 * Return expected size of a compressed texture.
1968 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1971 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1972 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1976 * Verify that a texture format is valid with a particular target
1978 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1979 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1982 * \param ctx GL context
1983 * \param target Texture target
1984 * \param internalFormat Internal format of the texture image
1985 * \param dimensions Dimensionality at the caller. This is \b not used
1986 * in the validation. It is only used when logging
1988 * \param caller Base name of the calling function (e.g.,
1989 * "glTexImage" or "glTexStorage").
1991 * \returns true if the combination is legal, false otherwise.
1994 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1995 GLenum target
, GLenum internalFormat
,
1996 unsigned dimensions
,
1999 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2000 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2001 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
2002 * Profile spec says:
2004 * "Textures with a base internal format of DEPTH_COMPONENT or
2005 * DEPTH_STENCIL are supported by texture image specification
2006 * commands only if target is TEXTURE_1D, TEXTURE_2D,
2007 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
2008 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
2009 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
2010 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
2011 * formats in conjunction with any other target will result in an
2012 * INVALID_OPERATION error."
2014 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
2015 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
2017 if (target
!= GL_TEXTURE_1D
&&
2018 target
!= GL_PROXY_TEXTURE_1D
&&
2019 target
!= GL_TEXTURE_2D
&&
2020 target
!= GL_PROXY_TEXTURE_2D
&&
2021 target
!= GL_TEXTURE_1D_ARRAY
&&
2022 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2023 target
!= GL_TEXTURE_2D_ARRAY
&&
2024 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2025 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2026 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2027 !((_mesa_is_cube_face(target
) ||
2028 target
== GL_TEXTURE_CUBE_MAP
||
2029 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2030 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2031 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2032 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2033 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2034 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2035 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2036 "%s%dD(bad target for depth texture)",
2037 caller
, dimensions
);
2046 texture_formats_agree(GLenum internalFormat
,
2049 GLboolean colorFormat
;
2050 GLboolean is_format_depth_or_depthstencil
;
2051 GLboolean is_internalFormat_depth_or_depthstencil
;
2053 /* Even though there are no color-index textures, we still have to support
2054 * uploading color-index data and remapping it to RGB via the
2055 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2057 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2059 is_internalFormat_depth_or_depthstencil
=
2060 _mesa_is_depth_format(internalFormat
) ||
2061 _mesa_is_depthstencil_format(internalFormat
);
2063 is_format_depth_or_depthstencil
=
2064 _mesa_is_depth_format(format
) ||
2065 _mesa_is_depthstencil_format(format
);
2067 colorFormat
= _mesa_is_color_format(format
);
2069 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2072 if (is_internalFormat_depth_or_depthstencil
!=
2073 is_format_depth_or_depthstencil
)
2076 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2083 * Test the glTexImage[123]D() parameters for errors.
2085 * \param ctx GL context.
2086 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2087 * \param target texture target given by the user (already validated).
2088 * \param level image level given by the user.
2089 * \param internalFormat internal format given by the user.
2090 * \param format pixel data format given by the user.
2091 * \param type pixel data type given by the user.
2092 * \param width image width given by the user.
2093 * \param height image height given by the user.
2094 * \param depth image depth given by the user.
2095 * \param border image border given by the user.
2097 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2099 * Verifies each of the parameters against the constants specified in
2100 * __struct gl_contextRec::Const and the supported extensions, and according
2101 * to the OpenGL specification.
2102 * Note that we don't fully error-check the width, height, depth values
2103 * here. That's done in _mesa_legal_texture_dimensions() which is used
2104 * by several other GL entrypoints. Plus, texture dims have a special
2105 * interaction with proxy textures.
2108 texture_error_check( struct gl_context
*ctx
,
2109 GLuint dimensions
, GLenum target
,
2110 GLint level
, GLint internalFormat
,
2111 GLenum format
, GLenum type
,
2112 GLint width
, GLint height
,
2113 GLint depth
, GLint border
,
2114 const GLvoid
*pixels
)
2118 /* Note: for proxy textures, some error conditions immediately generate
2119 * a GL error in the usual way. But others do not generate a GL error.
2120 * Instead, they cause the width, height, depth, format fields of the
2121 * texture image to be zeroed-out. The GL spec seems to indicate that the
2122 * zero-out behaviour is only used in cases related to memory allocation.
2126 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2127 _mesa_error(ctx
, GL_INVALID_VALUE
,
2128 "glTexImage%dD(level=%d)", dimensions
, level
);
2133 if (border
< 0 || border
> 1 ||
2134 ((ctx
->API
!= API_OPENGL_COMPAT
||
2135 target
== GL_TEXTURE_RECTANGLE_NV
||
2136 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2137 _mesa_error(ctx
, GL_INVALID_VALUE
,
2138 "glTexImage%dD(border=%d)", dimensions
, border
);
2142 if (width
< 0 || height
< 0 || depth
< 0) {
2143 _mesa_error(ctx
, GL_INVALID_VALUE
,
2144 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2148 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2149 * combinations of format, internalFormat, and type that can be used.
2150 * Formats and types that require additional extensions (e.g., GL_FLOAT
2151 * requires GL_OES_texture_float) are filtered elsewhere.
2154 if (_mesa_is_gles(ctx
)) {
2155 if (_mesa_is_gles3(ctx
)) {
2156 err
= _mesa_es3_error_check_format_and_type(ctx
, format
, type
,
2159 if (format
!= internalFormat
) {
2160 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2161 "glTexImage%dD(format = %s, internalFormat = %s)",
2163 _mesa_lookup_enum_by_nr(format
),
2164 _mesa_lookup_enum_by_nr(internalFormat
));
2168 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2170 if (err
!= GL_NO_ERROR
) {
2171 _mesa_error(ctx
, err
,
2172 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2174 _mesa_lookup_enum_by_nr(format
),
2175 _mesa_lookup_enum_by_nr(type
),
2176 _mesa_lookup_enum_by_nr(internalFormat
));
2181 /* Check internalFormat */
2182 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2183 _mesa_error(ctx
, GL_INVALID_VALUE
,
2184 "glTexImage%dD(internalFormat=%s)",
2185 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2189 /* Check incoming image format and type */
2190 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2191 if (err
!= GL_NO_ERROR
) {
2192 _mesa_error(ctx
, err
,
2193 "glTexImage%dD(incompatible format = %s, type = %s)",
2194 dimensions
, _mesa_lookup_enum_by_nr(format
),
2195 _mesa_lookup_enum_by_nr(type
));
2199 /* validate the bound PBO, if any */
2200 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2201 width
, height
, depth
, format
, type
,
2202 INT_MAX
, pixels
, "glTexImage")) {
2206 /* make sure internal format and format basically agree */
2207 if (!texture_formats_agree(internalFormat
, format
)) {
2208 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2209 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2210 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2211 _mesa_lookup_enum_by_nr(format
));
2215 /* additional checks for ycbcr textures */
2216 if (internalFormat
== GL_YCBCR_MESA
) {
2217 assert(ctx
->Extensions
.MESA_ycbcr_texture
);
2218 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2219 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2221 _mesa_snprintf(message
, sizeof(message
),
2222 "glTexImage%dD(format/type YCBCR mismatch)",
2224 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2225 return GL_TRUE
; /* error */
2227 if (target
!= GL_TEXTURE_2D
&&
2228 target
!= GL_PROXY_TEXTURE_2D
&&
2229 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2230 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2231 _mesa_error(ctx
, GL_INVALID_ENUM
,
2232 "glTexImage%dD(bad target for YCbCr texture)",
2238 _mesa_snprintf(message
, sizeof(message
),
2239 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2240 dimensions
, border
);
2241 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2246 /* additional checks for depth textures */
2247 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2248 dimensions
, "glTexImage"))
2251 /* additional checks for compressed textures */
2252 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2253 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2254 _mesa_error(ctx
, GL_INVALID_ENUM
,
2255 "glTexImage%dD(target can't be compressed)", dimensions
);
2258 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2259 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2260 "glTexImage%dD(no compression for format)", dimensions
);
2264 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2265 "glTexImage%dD(border!=0)", dimensions
);
2270 /* additional checks for integer textures */
2271 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2272 (_mesa_is_enum_format_integer(format
) !=
2273 _mesa_is_enum_format_integer(internalFormat
))) {
2274 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2275 "glTexImage%dD(integer/non-integer format mismatch)",
2280 if (!mutable_tex_object(ctx
, target
)) {
2281 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2282 "glTexImage%dD(immutable texture)", dimensions
);
2286 /* if we get here, the parameters are OK */
2292 * Error checking for glCompressedTexImage[123]D().
2293 * Note that the width, height and depth values are not fully error checked
2295 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2298 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2299 GLenum target
, GLint level
,
2300 GLenum internalFormat
, GLsizei width
,
2301 GLsizei height
, GLsizei depth
, GLint border
,
2302 GLsizei imageSize
, const GLvoid
*data
)
2304 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2306 GLenum error
= GL_NO_ERROR
;
2307 char *reason
= ""; /* no error */
2309 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2311 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
2313 * "The ETC2/EAC texture compression algorithm supports only
2314 * two-dimensional images. If internalformat is an ETC2/EAC format,
2315 * CompressedTexImage3D will generate an INVALID_OPERATION error if
2316 * target is not TEXTURE_2D_ARRAY."
2318 error
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
2322 /* This will detect any invalid internalFormat value */
2323 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2324 _mesa_error(ctx
, GL_INVALID_ENUM
,
2325 "glCompressedTexImage%dD(internalFormat=%s)",
2326 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2330 /* validate the bound PBO, if any */
2331 if (!_mesa_validate_pbo_source_compressed(ctx
, dimensions
, &ctx
->Unpack
,
2333 "glCompressedTexImage")) {
2337 switch (internalFormat
) {
2338 case GL_PALETTE4_RGB8_OES
:
2339 case GL_PALETTE4_RGBA8_OES
:
2340 case GL_PALETTE4_R5_G6_B5_OES
:
2341 case GL_PALETTE4_RGBA4_OES
:
2342 case GL_PALETTE4_RGB5_A1_OES
:
2343 case GL_PALETTE8_RGB8_OES
:
2344 case GL_PALETTE8_RGBA8_OES
:
2345 case GL_PALETTE8_R5_G6_B5_OES
:
2346 case GL_PALETTE8_RGBA4_OES
:
2347 case GL_PALETTE8_RGB5_A1_OES
:
2348 /* check level (note that level should be zero or less!) */
2349 if (level
> 0 || level
< -maxLevels
) {
2351 error
= GL_INVALID_VALUE
;
2355 if (dimensions
!= 2) {
2356 reason
= "compressed paletted textures must be 2D";
2357 error
= GL_INVALID_OPERATION
;
2361 /* Figure out the expected texture size (in bytes). This will be
2362 * checked against the actual size later.
2364 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2367 /* This is for the benefit of the TestProxyTexImage below. It expects
2368 * level to be non-negative. OES_compressed_paletted_texture uses a
2369 * weird mechanism where the level specified to glCompressedTexImage2D
2370 * is -(n-1) number of levels in the texture, and the data specifies the
2371 * complete mipmap stack. This is done to ensure the palette is the
2372 * same for all levels.
2379 if (level
< 0 || level
>= maxLevels
) {
2381 error
= GL_INVALID_VALUE
;
2385 /* Figure out the expected texture size (in bytes). This will be
2386 * checked against the actual size later.
2388 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2392 /* This should really never fail */
2393 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2394 reason
= "internalFormat";
2395 error
= GL_INVALID_ENUM
;
2399 /* No compressed formats support borders at this time */
2401 reason
= "border != 0";
2402 error
= GL_INVALID_VALUE
;
2406 /* Check for invalid pixel storage modes */
2407 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2409 "glCompressedTexImage")) {
2413 /* check image size in bytes */
2414 if (expectedSize
!= imageSize
) {
2415 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2416 * if <imageSize> is not consistent with the format, dimensions, and
2417 * contents of the specified image.
2419 reason
= "imageSize inconsistant with width/height/format";
2420 error
= GL_INVALID_VALUE
;
2424 if (!mutable_tex_object(ctx
, target
)) {
2425 reason
= "immutable texture";
2426 error
= GL_INVALID_OPERATION
;
2433 /* Note: not all error paths exit through here. */
2434 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)",
2435 dimensions
, reason
);
2442 * Test glTexSubImage[123]D() parameters for errors.
2444 * \param ctx GL context.
2445 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2446 * \param target texture target given by the user (already validated)
2447 * \param level image level given by the user.
2448 * \param xoffset sub-image x offset given by the user.
2449 * \param yoffset sub-image y offset given by the user.
2450 * \param zoffset sub-image z offset given by the user.
2451 * \param format pixel data format given by the user.
2452 * \param type pixel data type given by the user.
2453 * \param width image width given by the user.
2454 * \param height image height given by the user.
2455 * \param depth image depth given by the user.
2457 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2459 * Verifies each of the parameters against the constants specified in
2460 * __struct gl_contextRec::Const and the supported extensions, and according
2461 * to the OpenGL specification.
2464 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2465 struct gl_texture_object
*texObj
,
2466 GLenum target
, GLint level
,
2467 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2468 GLint width
, GLint height
, GLint depth
,
2469 GLenum format
, GLenum type
, const GLvoid
*pixels
,
2470 bool dsa
, const char *callerName
)
2472 struct gl_texture_image
*texImage
;
2476 /* must be out of memory */
2477 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", callerName
);
2481 /* check target (proxies not allowed) */
2482 if (!legal_texsubimage_target(ctx
, dimensions
, target
, dsa
)) {
2483 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target=%s)",
2484 callerName
, _mesa_lookup_enum_by_nr(target
));
2489 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2490 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", callerName
, level
);
2494 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2495 * combinations of format and type that can be used. Formats and types
2496 * that require additional extensions (e.g., GL_FLOAT requires
2497 * GL_OES_texture_float) are filtered elsewhere.
2499 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2500 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2501 if (err
!= GL_NO_ERROR
) {
2502 _mesa_error(ctx
, err
, "%s(format = %s, type = %s)",
2503 callerName
, _mesa_lookup_enum_by_nr(format
),
2504 _mesa_lookup_enum_by_nr(type
));
2509 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2510 if (err
!= GL_NO_ERROR
) {
2511 _mesa_error(ctx
, err
,
2512 "%s(incompatible format = %s, type = %s)",
2513 callerName
, _mesa_lookup_enum_by_nr(format
),
2514 _mesa_lookup_enum_by_nr(type
));
2518 /* validate the bound PBO, if any */
2519 if (!_mesa_validate_pbo_source(ctx
, dimensions
, &ctx
->Unpack
,
2520 width
, height
, depth
, format
, type
,
2521 INT_MAX
, pixels
, callerName
)) {
2525 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2527 /* non-existant texture level */
2528 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid texture image)",
2533 if (error_check_subtexture_dimensions(ctx
, dimensions
,
2534 texImage
, xoffset
, yoffset
, zoffset
,
2535 width
, height
, depth
, callerName
)) {
2539 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2540 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2541 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2542 "%s(no compression for format)", callerName
);
2547 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2548 /* both source and dest must be integer-valued, or neither */
2549 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2550 _mesa_is_enum_format_integer(format
)) {
2551 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2552 "%s(integer/non-integer format mismatch)", callerName
);
2562 * Test glCopyTexImage[12]D() parameters for errors.
2564 * \param ctx GL context.
2565 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2566 * \param target texture target given by the user.
2567 * \param level image level given by the user.
2568 * \param internalFormat internal format given by the user.
2569 * \param width image width given by the user.
2570 * \param height image height given by the user.
2571 * \param border texture border.
2573 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2575 * Verifies each of the parameters against the constants specified in
2576 * __struct gl_contextRec::Const and the supported extensions, and according
2577 * to the OpenGL specification.
2580 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2581 GLenum target
, GLint level
, GLint internalFormat
,
2582 GLint width
, GLint height
, GLint border
)
2585 GLint rb_base_format
;
2586 struct gl_renderbuffer
*rb
;
2587 GLenum rb_internal_format
;
2590 if (!legal_texsubimage_target(ctx
, dimensions
, target
, false)) {
2591 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2592 dimensions
, _mesa_lookup_enum_by_nr(target
));
2597 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2598 _mesa_error(ctx
, GL_INVALID_VALUE
,
2599 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2603 /* Check that the source buffer is complete */
2604 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2605 if (ctx
->ReadBuffer
->_Status
== 0) {
2606 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2608 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2609 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2610 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2614 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2615 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2616 "glCopyTexImage%dD(multisample FBO)", dimensions
);
2622 if (border
< 0 || border
> 1 ||
2623 ((ctx
->API
!= API_OPENGL_COMPAT
||
2624 target
== GL_TEXTURE_RECTANGLE_NV
||
2625 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2626 _mesa_error(ctx
, GL_INVALID_VALUE
,
2627 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2631 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2633 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2634 "glCopyTexImage%dD(read buffer)", dimensions
);
2638 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2641 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2642 switch (internalFormat
) {
2647 case GL_LUMINANCE_ALPHA
:
2650 _mesa_error(ctx
, GL_INVALID_VALUE
,
2651 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2652 _mesa_lookup_enum_by_nr(internalFormat
));
2657 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2658 if (baseFormat
< 0) {
2659 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2660 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2661 _mesa_lookup_enum_by_nr(internalFormat
));
2665 rb_internal_format
= rb
->InternalFormat
;
2666 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2667 if (_mesa_is_color_format(internalFormat
)) {
2668 if (rb_base_format
< 0) {
2669 _mesa_error(ctx
, GL_INVALID_VALUE
,
2670 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2671 _mesa_lookup_enum_by_nr(internalFormat
));
2676 if (_mesa_is_gles(ctx
)) {
2678 if (_mesa_base_format_component_count(baseFormat
) >
2679 _mesa_base_format_component_count(rb_base_format
)) {
2682 if (baseFormat
== GL_DEPTH_COMPONENT
||
2683 baseFormat
== GL_DEPTH_STENCIL
||
2684 rb_base_format
== GL_DEPTH_COMPONENT
||
2685 rb_base_format
== GL_DEPTH_STENCIL
||
2686 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2687 baseFormat
== GL_ALPHA
) &&
2688 rb_base_format
!= GL_RGBA
) ||
2689 internalFormat
== GL_RGB9_E5
) {
2692 if (internalFormat
== GL_RGB9_E5
) {
2696 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2697 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2698 _mesa_lookup_enum_by_nr(internalFormat
));
2703 if (_mesa_is_gles3(ctx
)) {
2704 bool rb_is_srgb
= false;
2705 bool dst_is_srgb
= false;
2707 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2708 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2712 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2716 if (rb_is_srgb
!= dst_is_srgb
) {
2717 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2718 * OpenGLES 3.0.0 spec says:
2720 * "The error INVALID_OPERATION is also generated if the
2721 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2722 * framebuffer attachment corresponding to the read buffer
2723 * is LINEAR (see section 6.1.13) and internalformat is
2724 * one of the sRGB formats described in section 3.8.16, or
2725 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2726 * SRGB and internalformat is not one of the sRGB formats."
2728 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2729 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2733 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2734 * types for SNORM formats. Also, conversion to SNORM formats is not
2735 * allowed by Table 3.2 on Page 110.
2737 if(_mesa_is_enum_format_snorm(internalFormat
)) {
2738 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2739 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2740 _mesa_lookup_enum_by_nr(internalFormat
));
2745 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2746 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2747 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2751 /* From the EXT_texture_integer spec:
2753 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2754 * if the texture internalformat is an integer format and the read color
2755 * buffer is not an integer format, or if the internalformat is not an
2756 * integer format and the read color buffer is an integer format."
2758 if (_mesa_is_color_format(internalFormat
)) {
2759 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2760 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2761 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2762 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2763 if (is_int
|| is_rbint
) {
2764 if (is_int
!= is_rbint
) {
2765 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2766 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2768 } else if (_mesa_is_gles(ctx
) &&
2769 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2770 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2771 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2772 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2777 /* From page 138 of OpenGL ES 3.0 spec:
2778 * "The error INVALID_OPERATION is generated if floating-point RGBA
2779 * data is required; if signed integer RGBA data is required and the
2780 * format of the current color buffer is not signed integer; if
2781 * unsigned integer RGBA data is required and the format of the
2782 * current color buffer is not unsigned integer; or if fixed-point
2783 * RGBA data is required and the format of the current color buffer
2784 * is not fixed-point.
2786 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2787 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2788 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2791 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2792 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2793 _mesa_error(ctx
, GL_INVALID_ENUM
,
2794 "glCopyTexImage%dD(target)", dimensions
);
2797 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2798 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2799 "glCopyTexImage%dD(no compression for format)", dimensions
);
2803 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2804 "glCopyTexImage%dD(border!=0)", dimensions
);
2809 if (!mutable_tex_object(ctx
, target
)) {
2810 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2811 "glCopyTexImage%dD(immutable texture)", dimensions
);
2815 /* if we get here, the parameters are OK */
2821 * Test glCopyTexSubImage[12]D() parameters for errors.
2822 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2825 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2826 const struct gl_texture_object
*texObj
,
2827 GLenum target
, GLint level
,
2828 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2829 GLint width
, GLint height
, const char *caller
)
2831 struct gl_texture_image
*texImage
;
2833 /* Check that the source buffer is complete */
2834 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2835 if (ctx
->ReadBuffer
->_Status
== 0) {
2836 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2838 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2839 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2840 "%s(invalid readbuffer)", caller
);
2844 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2845 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2846 "%s(multisample FBO)", caller
);
2852 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2853 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(level=%d)", caller
, level
);
2857 /* Get dest image pointers */
2859 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", caller
);
2863 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
2865 /* destination image does not exist */
2866 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2867 "%s(invalid texture image)", caller
);
2871 if (error_check_subtexture_dimensions(ctx
, dimensions
, texImage
,
2872 xoffset
, yoffset
, zoffset
,
2873 width
, height
, 1, caller
)) {
2877 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2878 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2879 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2880 "%s(no compression for format)", caller
);
2885 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2886 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s()", caller
);
2890 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2891 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2892 "%s(missing readbuffer, format=0x%x)", caller
,
2893 texImage
->_BaseFormat
);
2897 /* From the EXT_texture_integer spec:
2899 * "INVALID_OPERATION is generated by CopyTexImage* and
2900 * CopyTexSubImage* if the texture internalformat is an integer format
2901 * and the read color buffer is not an integer format, or if the
2902 * internalformat is not an integer format and the read color buffer
2903 * is an integer format."
2905 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2906 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2908 if (_mesa_is_format_integer_color(rb
->Format
) !=
2909 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2910 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2911 "%s(integer vs non-integer)", caller
);
2916 /* if we get here, the parameters are OK */
2921 /** Callback info for walking over FBO hash table */
2924 struct gl_context
*ctx
;
2925 struct gl_texture_object
*texObj
;
2931 * Check render to texture callback. Called from _mesa_HashWalk().
2934 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2936 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2937 const struct cb_info
*info
= (struct cb_info
*) userData
;
2938 struct gl_context
*ctx
= info
->ctx
;
2939 const struct gl_texture_object
*texObj
= info
->texObj
;
2940 const GLuint level
= info
->level
, face
= info
->face
;
2942 /* If this is a user-created FBO */
2943 if (_mesa_is_user_fbo(fb
)) {
2945 /* check if any of the FBO's attachments point to 'texObj' */
2946 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2947 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2948 if (att
->Type
== GL_TEXTURE
&&
2949 att
->Texture
== texObj
&&
2950 att
->TextureLevel
== level
&&
2951 att
->CubeMapFace
== face
) {
2952 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2953 assert(att
->Renderbuffer
->TexImage
);
2954 /* Mark fb status as indeterminate to force re-validation */
2963 * When a texture image is specified we have to check if it's bound to
2964 * any framebuffer objects (render to texture) in order to detect changes
2965 * in size or format since that effects FBO completeness.
2966 * Any FBOs rendering into the texture must be re-validated.
2969 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2970 struct gl_texture_object
*texObj
,
2971 GLuint face
, GLuint level
)
2973 /* Only check this texture if it's been marked as RenderToTexture */
2974 if (texObj
->_RenderToTexture
) {
2975 struct cb_info info
;
2977 info
.texObj
= texObj
;
2980 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2986 * If the texture object's GenerateMipmap flag is set and we've
2987 * changed the texture base level image, regenerate the rest of the
2988 * mipmap levels now.
2991 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2992 struct gl_texture_object
*texObj
, GLint level
)
2994 if (texObj
->GenerateMipmap
&&
2995 level
== texObj
->BaseLevel
&&
2996 level
< texObj
->MaxLevel
) {
2997 assert(ctx
->Driver
.GenerateMipmap
);
2998 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3003 /** Debug helper: override the user-requested internal format */
3005 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
3008 if (internalFormat
== GL_RGBA16F_ARB
||
3009 internalFormat
== GL_RGBA32F_ARB
) {
3010 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3013 else if (internalFormat
== GL_RGB16F_ARB
||
3014 internalFormat
== GL_RGB32F_ARB
) {
3015 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3018 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3019 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3020 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3021 return GL_LUMINANCE_ALPHA
;
3023 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3024 internalFormat
== GL_LUMINANCE32F_ARB
) {
3025 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3026 return GL_LUMINANCE
;
3028 else if (internalFormat
== GL_ALPHA16F_ARB
||
3029 internalFormat
== GL_ALPHA32F_ARB
) {
3030 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3034 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3035 internalFormat = GL_RGBA;
3039 return internalFormat
;
3042 return internalFormat
;
3048 * Choose the actual hardware format for a texture image.
3049 * Try to use the same format as the previous image level when possible.
3050 * Otherwise, ask the driver for the best format.
3051 * It's important to try to choose a consistant format for all levels
3052 * for efficient texture memory layout/allocation. In particular, this
3053 * comes up during automatic mipmap generation.
3056 _mesa_choose_texture_format(struct gl_context
*ctx
,
3057 struct gl_texture_object
*texObj
,
3058 GLenum target
, GLint level
,
3059 GLenum internalFormat
, GLenum format
, GLenum type
)
3063 /* see if we've already chosen a format for the previous level */
3065 struct gl_texture_image
*prevImage
=
3066 _mesa_select_tex_image(texObj
, target
, level
- 1);
3067 /* See if the prev level is defined and has an internal format which
3068 * matches the new internal format.
3071 prevImage
->Width
> 0 &&
3072 prevImage
->InternalFormat
== internalFormat
) {
3073 /* use the same format */
3074 assert(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3075 return prevImage
->TexFormat
;
3079 /* If the application requested compression to an S3TC format but we don't
3080 * have the DXTn library, force a generic compressed format instead.
3082 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3083 const GLenum before
= internalFormat
;
3085 switch (internalFormat
) {
3086 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3087 if (!ctx
->Mesa_DXTn
)
3088 internalFormat
= GL_COMPRESSED_RGB
;
3090 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3091 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3092 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3093 if (!ctx
->Mesa_DXTn
)
3094 internalFormat
= GL_COMPRESSED_RGBA
;
3100 if (before
!= internalFormat
) {
3102 "DXT compression requested (%s), "
3103 "but libtxc_dxtn library not installed. Using %s "
3105 _mesa_lookup_enum_by_nr(before
),
3106 _mesa_lookup_enum_by_nr(internalFormat
));
3110 /* choose format from scratch */
3111 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3113 assert(f
!= MESA_FORMAT_NONE
);
3119 * Adjust pixel unpack params and image dimensions to strip off the
3120 * one-pixel texture border.
3122 * Gallium and intel don't support texture borders. They've seldem been used
3123 * and seldom been implemented correctly anyway.
3125 * \param unpackNew returns the new pixel unpack parameters
3128 strip_texture_border(GLenum target
,
3129 GLint
*width
, GLint
*height
, GLint
*depth
,
3130 const struct gl_pixelstore_attrib
*unpack
,
3131 struct gl_pixelstore_attrib
*unpackNew
)
3137 *unpackNew
= *unpack
;
3139 if (unpackNew
->RowLength
== 0)
3140 unpackNew
->RowLength
= *width
;
3142 if (unpackNew
->ImageHeight
== 0)
3143 unpackNew
->ImageHeight
= *height
;
3145 assert(*width
>= 3);
3146 unpackNew
->SkipPixels
++; /* skip the border */
3147 *width
= *width
- 2; /* reduce the width by two border pixels */
3149 /* The min height of a texture with a border is 3 */
3150 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3151 unpackNew
->SkipRows
++; /* skip the border */
3152 *height
= *height
- 2; /* reduce the height by two border pixels */
3156 target
!= GL_TEXTURE_2D_ARRAY
&&
3157 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3158 unpackNew
->SkipImages
++; /* skip the border */
3159 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3165 * Common code to implement all the glTexImage1D/2D/3D functions
3166 * as well as glCompressedTexImage1D/2D/3D.
3167 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3168 * \param format the user's image format (only used if !compressed)
3169 * \param type the user's image type (only used if !compressed)
3170 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3173 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3174 GLenum target
, GLint level
, GLint internalFormat
,
3175 GLsizei width
, GLsizei height
, GLsizei depth
,
3176 GLint border
, GLenum format
, GLenum type
,
3177 GLsizei imageSize
, const GLvoid
*pixels
)
3179 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3180 struct gl_pixelstore_attrib unpack_no_border
;
3181 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3182 struct gl_texture_object
*texObj
;
3183 mesa_format texFormat
;
3184 GLboolean dimensionsOK
, sizeOK
;
3186 FLUSH_VERTICES(ctx
, 0);
3188 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3191 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3193 _mesa_lookup_enum_by_nr(target
), level
,
3194 _mesa_lookup_enum_by_nr(internalFormat
),
3195 width
, height
, depth
, border
, pixels
);
3198 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3200 _mesa_lookup_enum_by_nr(target
), level
,
3201 _mesa_lookup_enum_by_nr(internalFormat
),
3202 width
, height
, depth
, border
,
3203 _mesa_lookup_enum_by_nr(format
),
3204 _mesa_lookup_enum_by_nr(type
), pixels
);
3207 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3209 /* target error checking */
3210 if (!legal_teximage_target(ctx
, dims
, target
)) {
3211 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3212 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3216 /* general error checking */
3218 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3220 width
, height
, depth
,
3221 border
, imageSize
, pixels
))
3225 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3226 format
, type
, width
, height
, depth
, border
,
3231 /* Here we convert a cpal compressed image into a regular glTexImage2D
3232 * call by decompressing the texture. If we really want to support cpal
3233 * textures in any driver this would have to be changed.
3235 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3236 switch (internalFormat
) {
3237 case GL_PALETTE4_RGB8_OES
:
3238 case GL_PALETTE4_RGBA8_OES
:
3239 case GL_PALETTE4_R5_G6_B5_OES
:
3240 case GL_PALETTE4_RGBA4_OES
:
3241 case GL_PALETTE4_RGB5_A1_OES
:
3242 case GL_PALETTE8_RGB8_OES
:
3243 case GL_PALETTE8_RGBA8_OES
:
3244 case GL_PALETTE8_R5_G6_B5_OES
:
3245 case GL_PALETTE8_RGBA4_OES
:
3246 case GL_PALETTE8_RGB5_A1_OES
:
3247 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3248 width
, height
, imageSize
, pixels
);
3253 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3257 /* For glCompressedTexImage() the driver has no choice about the
3258 * texture format since we'll never transcode the user's compressed
3259 * image data. The internalFormat was error checked earlier.
3261 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3264 /* In case of HALF_FLOAT_OES or FLOAT_OES, find corresponding sized
3265 * internal floating point format for the given base format.
3267 if (_mesa_is_gles(ctx
) && format
== internalFormat
) {
3268 if (type
== GL_FLOAT
) {
3269 texObj
->_IsFloat
= GL_TRUE
;
3270 } else if (type
== GL_HALF_FLOAT_OES
|| type
== GL_HALF_FLOAT
) {
3271 texObj
->_IsHalfFloat
= GL_TRUE
;
3274 internalFormat
= adjust_for_oes_float_texture(format
, type
);
3277 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3278 internalFormat
, format
, type
);
3281 assert(texFormat
!= MESA_FORMAT_NONE
);
3283 /* check that width, height, depth are legal for the mipmap level */
3284 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3285 height
, depth
, border
);
3287 /* check that the texture won't take too much memory, etc */
3288 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3290 width
, height
, depth
, border
);
3292 if (_mesa_is_proxy_texture(target
)) {
3293 /* Proxy texture: just clear or set state depending on error checking */
3294 struct gl_texture_image
*texImage
=
3295 get_proxy_tex_image(ctx
, target
, level
);
3298 return; /* GL_OUT_OF_MEMORY already recorded */
3300 if (dimensionsOK
&& sizeOK
) {
3301 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3302 border
, internalFormat
, texFormat
);
3305 clear_teximage_fields(texImage
);
3309 /* non-proxy target */
3310 const GLuint face
= _mesa_tex_target_to_face(target
);
3311 struct gl_texture_image
*texImage
;
3313 if (!dimensionsOK
) {
3314 _mesa_error(ctx
, GL_INVALID_VALUE
,
3315 "glTexImage%uD(invalid width or height or depth)",
3321 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3322 "glTexImage%uD(image too large)", dims
);
3326 /* Allow a hardware driver to just strip out the border, to provide
3327 * reliable but slightly incorrect hardware rendering instead of
3328 * rarely-tested software fallback rendering.
3330 if (border
&& ctx
->Const
.StripTextureBorder
) {
3331 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3334 unpack
= &unpack_no_border
;
3337 if (ctx
->NewState
& _NEW_PIXEL
)
3338 _mesa_update_state(ctx
);
3340 _mesa_lock_texture(ctx
, texObj
);
3342 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3345 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3348 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3350 _mesa_init_teximage_fields(ctx
, texImage
,
3351 width
, height
, depth
,
3352 border
, internalFormat
, texFormat
);
3354 /* Give the texture to the driver. <pixels> may be null. */
3355 if (width
> 0 && height
> 0 && depth
> 0) {
3357 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3361 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3362 type
, pixels
, unpack
);
3366 check_gen_mipmap(ctx
, target
, texObj
, level
);
3368 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3370 _mesa_dirty_texobj(ctx
, texObj
);
3373 _mesa_unlock_texture(ctx
, texObj
);
3380 * Called from the API. Note that width includes the border.
3383 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3384 GLsizei width
, GLint border
, GLenum format
,
3385 GLenum type
, const GLvoid
*pixels
)
3387 GET_CURRENT_CONTEXT(ctx
);
3388 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3389 border
, format
, type
, 0, pixels
);
3394 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3395 GLsizei width
, GLsizei height
, GLint border
,
3396 GLenum format
, GLenum type
,
3397 const GLvoid
*pixels
)
3399 GET_CURRENT_CONTEXT(ctx
);
3400 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3401 border
, format
, type
, 0, pixels
);
3406 * Called by the API or display list executor.
3407 * Note that width and height include the border.
3410 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3411 GLsizei width
, GLsizei height
, GLsizei depth
,
3412 GLint border
, GLenum format
, GLenum type
,
3413 const GLvoid
*pixels
)
3415 GET_CURRENT_CONTEXT(ctx
);
3416 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3417 width
, height
, depth
,
3418 border
, format
, type
, 0, pixels
);
3423 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3424 GLsizei width
, GLsizei height
, GLsizei depth
,
3425 GLint border
, GLenum format
, GLenum type
,
3426 const GLvoid
*pixels
)
3428 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3429 depth
, border
, format
, type
, pixels
);
3434 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3436 struct gl_texture_object
*texObj
;
3437 struct gl_texture_image
*texImage
;
3439 GET_CURRENT_CONTEXT(ctx
);
3440 FLUSH_VERTICES(ctx
, 0);
3444 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3446 case GL_TEXTURE_EXTERNAL_OES
:
3448 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3451 valid_target
= false;
3455 if (!valid_target
) {
3456 _mesa_error(ctx
, GL_INVALID_ENUM
,
3457 "glEGLImageTargetTexture2D(target=%d)", target
);
3462 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3463 "glEGLImageTargetTexture2D(image=%p)", image
);
3467 if (ctx
->NewState
& _NEW_PIXEL
)
3468 _mesa_update_state(ctx
);
3470 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3474 _mesa_lock_texture(ctx
, texObj
);
3476 if (texObj
->Immutable
) {
3477 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3478 "glEGLImageTargetTexture2D(texture is immutable)");
3479 _mesa_unlock_texture(ctx
, texObj
);
3483 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3485 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3487 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3489 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3490 texObj
, texImage
, image
);
3492 _mesa_dirty_texobj(ctx
, texObj
);
3494 _mesa_unlock_texture(ctx
, texObj
);
3500 * Helper that implements the glTexSubImage1/2/3D()
3501 * and glTextureSubImage1/2/3D() functions.
3504 _mesa_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
3505 struct gl_texture_object
*texObj
,
3506 struct gl_texture_image
*texImage
,
3507 GLenum target
, GLint level
,
3508 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3509 GLsizei width
, GLsizei height
, GLsizei depth
,
3510 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3513 FLUSH_VERTICES(ctx
, 0);
3515 /* check target (proxies not allowed) */
3516 if (!legal_texsubimage_target(ctx
, dims
, target
, dsa
)) {
3517 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTex%sSubImage%uD(target=%s)",
3519 dims
, _mesa_lookup_enum_by_nr(target
));
3523 if (ctx
->NewState
& _NEW_PIXEL
)
3524 _mesa_update_state(ctx
);
3526 _mesa_lock_texture(ctx
, texObj
);
3528 if (width
> 0 && height
> 0 && depth
> 0) {
3529 /* If we have a border, offset=-1 is legal. Bias by border width. */
3532 if (target
!= GL_TEXTURE_2D_ARRAY
)
3533 zoffset
+= texImage
->Border
;
3536 if (target
!= GL_TEXTURE_1D_ARRAY
)
3537 yoffset
+= texImage
->Border
;
3540 xoffset
+= texImage
->Border
;
3543 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3544 xoffset
, yoffset
, zoffset
,
3545 width
, height
, depth
,
3546 format
, type
, pixels
, &ctx
->Unpack
);
3548 check_gen_mipmap(ctx
, target
, texObj
, level
);
3550 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3551 * the texel data, not the texture format, size, etc.
3555 _mesa_unlock_texture(ctx
, texObj
);
3559 * Implement all the glTexSubImage1/2/3D() functions.
3560 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3563 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3564 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3565 GLsizei width
, GLsizei height
, GLsizei depth
,
3566 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3567 const char *callerName
)
3569 struct gl_texture_object
*texObj
;
3570 struct gl_texture_image
*texImage
;
3572 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3576 if (texsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
3577 xoffset
, yoffset
, zoffset
,
3578 width
, height
, depth
, format
, type
,
3579 pixels
, false, callerName
)) {
3580 return; /* error was detected */
3583 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
3584 /* texsubimage_error_check ensures that texImage is not NULL */
3586 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3587 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3589 _mesa_lookup_enum_by_nr(target
), level
,
3590 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3591 _mesa_lookup_enum_by_nr(format
),
3592 _mesa_lookup_enum_by_nr(type
), pixels
);
3594 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, target
, level
,
3595 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3596 format
, type
, pixels
, false);
3601 * Implement all the glTextureSubImage1/2/3D() functions.
3602 * Must split this out this way because of GL_TEXTURE_CUBE_MAP.
3605 texturesubimage(struct gl_context
*ctx
, GLuint dims
,
3606 GLuint texture
, GLint level
,
3607 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3608 GLsizei width
, GLsizei height
, GLsizei depth
,
3609 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3610 const char *callerName
)
3612 struct gl_texture_object
*texObj
;
3613 struct gl_texture_image
*texImage
;
3616 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3618 "glTextureSubImage%uD %d %d %d %d %d %d %d %d %s %s %p\n",
3619 dims
, texture
, level
,
3620 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3621 _mesa_lookup_enum_by_nr(format
),
3622 _mesa_lookup_enum_by_nr(type
), pixels
);
3624 /* Get the texture object by Name. */
3625 texObj
= _mesa_lookup_texture(ctx
, texture
);
3627 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTextureSubImage%uD(texture)",
3632 if (texsubimage_error_check(ctx
, dims
, texObj
, texObj
->Target
, level
,
3633 xoffset
, yoffset
, zoffset
,
3634 width
, height
, depth
, format
, type
,
3635 pixels
, true, callerName
)) {
3636 return; /* error was detected */
3640 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
3641 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
3645 * What do we do if the user created a texture with the following code
3646 * and then called this function with its handle?
3649 * glCreateTextures(GL_TEXTURE_CUBE_MAP, 1, &tex);
3650 * glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
3651 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, ...);
3652 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, ...);
3653 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, ...);
3654 * // Note: GL_TEXTURE_CUBE_MAP_NEGATIVE_Y not set, or given the
3655 * // wrong format, or given the wrong size, etc.
3656 * glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, ...);
3657 * glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, ...);
3659 * A bug has been filed against the spec for this case. In the
3660 * meantime, we will check for cube completeness.
3662 * According to Section 8.17 Texture Completeness in the OpenGL 4.5
3663 * Core Profile spec (30.10.2014):
3664 * "[A] cube map texture is cube complete if the
3665 * following conditions all hold true: The [base level] texture
3666 * images of each of the six cube map faces have identical, positive,
3667 * and square dimensions. The [base level] images were each specified
3668 * with the same internal format."
3670 * It seems reasonable to check for cube completeness of an arbitrary
3671 * level here so that the image data has a consistent format and size.
3673 if (!_mesa_cube_level_complete(texObj
, level
)) {
3674 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3675 "glTextureSubImage%uD(cube map incomplete)",
3680 rowStride
= _mesa_image_image_stride(&ctx
->Unpack
, width
, height
,
3682 /* Copy in each face. */
3683 for (i
= 0; i
< 6; ++i
) {
3684 texImage
= texObj
->Image
[i
][level
];
3687 _mesa_texture_sub_image(ctx
, 3, texObj
, texImage
, texObj
->Target
,
3688 level
, xoffset
, yoffset
, zoffset
,
3689 width
, height
, 1, format
,
3690 type
, pixels
, true);
3691 pixels
= (GLubyte
*) pixels
+ rowStride
;
3695 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
3698 _mesa_texture_sub_image(ctx
, dims
, texObj
, texImage
, texObj
->Target
,
3699 level
, xoffset
, yoffset
, zoffset
,
3700 width
, height
, depth
, format
,
3701 type
, pixels
, true);
3707 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3708 GLint xoffset
, GLsizei width
,
3709 GLenum format
, GLenum type
,
3710 const GLvoid
*pixels
)
3712 GET_CURRENT_CONTEXT(ctx
);
3713 texsubimage(ctx
, 1, target
, level
,
3716 format
, type
, pixels
, "glTexSubImage1D");
3721 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3722 GLint xoffset
, GLint yoffset
,
3723 GLsizei width
, GLsizei height
,
3724 GLenum format
, GLenum type
,
3725 const GLvoid
*pixels
)
3727 GET_CURRENT_CONTEXT(ctx
);
3728 texsubimage(ctx
, 2, target
, level
,
3729 xoffset
, yoffset
, 0,
3731 format
, type
, pixels
, "glTexSubImage2D");
3737 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3738 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3739 GLsizei width
, GLsizei height
, GLsizei depth
,
3740 GLenum format
, GLenum type
,
3741 const GLvoid
*pixels
)
3743 GET_CURRENT_CONTEXT(ctx
);
3744 texsubimage(ctx
, 3, target
, level
,
3745 xoffset
, yoffset
, zoffset
,
3746 width
, height
, depth
,
3747 format
, type
, pixels
, "glTexSubImage3D");
3751 _mesa_TextureSubImage1D(GLuint texture
, GLint level
,
3752 GLint xoffset
, GLsizei width
,
3753 GLenum format
, GLenum type
,
3754 const GLvoid
*pixels
)
3756 GET_CURRENT_CONTEXT(ctx
);
3757 texturesubimage(ctx
, 1, texture
, level
,
3760 format
, type
, pixels
, "glTextureSubImage1D");
3765 _mesa_TextureSubImage2D(GLuint texture
, GLint level
,
3766 GLint xoffset
, GLint yoffset
,
3767 GLsizei width
, GLsizei height
,
3768 GLenum format
, GLenum type
,
3769 const GLvoid
*pixels
)
3771 GET_CURRENT_CONTEXT(ctx
);
3772 texturesubimage(ctx
, 2, texture
, level
,
3773 xoffset
, yoffset
, 0,
3775 format
, type
, pixels
, "glTextureSubImage2D");
3780 _mesa_TextureSubImage3D(GLuint texture
, GLint level
,
3781 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3782 GLsizei width
, GLsizei height
, GLsizei depth
,
3783 GLenum format
, GLenum type
,
3784 const GLvoid
*pixels
)
3786 GET_CURRENT_CONTEXT(ctx
);
3787 texturesubimage(ctx
, 3, texture
, level
,
3788 xoffset
, yoffset
, zoffset
,
3789 width
, height
, depth
,
3790 format
, type
, pixels
, "glTextureSubImage3D");
3795 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3796 * from. This depends on whether the texture contains color or depth values.
3798 static struct gl_renderbuffer
*
3799 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3801 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3802 /* reading from depth/stencil buffer */
3803 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3806 /* copying from color buffer */
3807 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3812 copytexsubimage_by_slice(struct gl_context
*ctx
,
3813 struct gl_texture_image
*texImage
,
3815 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3816 struct gl_renderbuffer
*rb
,
3818 GLsizei width
, GLsizei height
)
3820 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3823 /* For 1D arrays, we copy each scanline of the source rectangle into the
3826 assert(zoffset
== 0);
3828 for (slice
= 0; slice
< height
; slice
++) {
3829 assert(yoffset
+ slice
< texImage
->Height
);
3830 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3831 xoffset
, 0, yoffset
+ slice
,
3832 rb
, x
, y
+ slice
, width
, 1);
3835 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3836 xoffset
, yoffset
, zoffset
,
3837 rb
, x
, y
, width
, height
);
3842 formats_differ_in_component_sizes (mesa_format f1
,
3845 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3846 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3847 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3848 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3850 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3851 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3852 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3853 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3855 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3856 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3857 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3858 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3865 * Implement the glCopyTexImage1/2D() functions.
3868 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3869 GLenum target
, GLint level
, GLenum internalFormat
,
3870 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3872 struct gl_texture_object
*texObj
;
3873 struct gl_texture_image
*texImage
;
3874 const GLuint face
= _mesa_tex_target_to_face(target
);
3875 mesa_format texFormat
;
3876 struct gl_renderbuffer
*rb
;
3878 FLUSH_VERTICES(ctx
, 0);
3880 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3881 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3883 _mesa_lookup_enum_by_nr(target
), level
,
3884 _mesa_lookup_enum_by_nr(internalFormat
),
3885 x
, y
, width
, height
, border
);
3887 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3888 _mesa_update_state(ctx
);
3890 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3891 width
, height
, border
))
3894 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3896 _mesa_error(ctx
, GL_INVALID_VALUE
,
3897 "glCopyTexImage%uD(invalid width or height)", dims
);
3901 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3904 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3905 internalFormat
, GL_NONE
, GL_NONE
);
3907 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3909 if (_mesa_is_gles3(ctx
)) {
3910 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3911 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3912 * OpenGL ES 3.0. Khronos bug# 9807.
3914 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3915 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3916 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer and"
3917 " writing to unsized internal format)", dims
);
3921 /* From Page 139 of OpenGL ES 3.0 spec:
3922 * "If internalformat is sized, the internal format of the new texel
3923 * array is internalformat, and this is also the new texel array’s
3924 * effective internal format. If the component sizes of internalformat
3925 * do not exactly match the corresponding component sizes of the source
3926 * buffer’s effective internal format, described below, an
3927 * INVALID_OPERATION error is generated. If internalformat is unsized,
3928 * the internal format of the new texel array is the effective internal
3929 * format of the source buffer, and this is also the new texel array’s
3930 * effective internal format.
3932 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3933 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3934 "glCopyTexImage%uD(componenet size changed in"
3935 " internal format)", dims
);
3940 assert(texFormat
!= MESA_FORMAT_NONE
);
3942 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3944 width
, height
, 1, border
)) {
3945 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3946 "glCopyTexImage%uD(image too large)", dims
);
3950 if (border
&& ctx
->Const
.StripTextureBorder
) {
3952 width
-= border
* 2;
3955 height
-= border
* 2;
3960 _mesa_lock_texture(ctx
, texObj
);
3962 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3965 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3968 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3970 /* Free old texture image */
3971 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3973 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3974 border
, internalFormat
, texFormat
);
3976 if (width
&& height
) {
3977 /* Allocate texture memory (no pixel data yet) */
3978 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3980 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3982 struct gl_renderbuffer
*srcRb
=
3983 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3985 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3987 srcRb
, srcX
, srcY
, width
, height
);
3990 check_gen_mipmap(ctx
, target
, texObj
, level
);
3993 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3995 _mesa_dirty_texobj(ctx
, texObj
);
3998 _mesa_unlock_texture(ctx
, texObj
);
4004 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
4005 GLenum internalFormat
,
4007 GLsizei width
, GLint border
)
4009 GET_CURRENT_CONTEXT(ctx
);
4010 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
4016 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
4017 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
4020 GET_CURRENT_CONTEXT(ctx
);
4021 copyteximage(ctx
, 2, target
, level
, internalFormat
,
4022 x
, y
, width
, height
, border
);
4026 * Implementation for glCopyTex(ture)SubImage1/2/3D() functions.
4029 _mesa_copy_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4030 struct gl_texture_object
*texObj
,
4031 GLenum target
, GLint level
,
4032 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4034 GLsizei width
, GLsizei height
,
4037 struct gl_texture_image
*texImage
;
4039 FLUSH_VERTICES(ctx
, 0);
4041 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
4042 _mesa_debug(ctx
, "%s %s %d %d %d %d %d %d %d %d\n", caller
,
4043 _mesa_lookup_enum_by_nr(target
),
4044 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
4046 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
4047 _mesa_update_state(ctx
);
4049 if (copytexsubimage_error_check(ctx
, dims
, texObj
, target
, level
,
4050 xoffset
, yoffset
, zoffset
,
4051 width
, height
, caller
)) {
4055 _mesa_lock_texture(ctx
, texObj
);
4057 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4059 /* If we have a border, offset=-1 is legal. Bias by border width. */
4062 if (target
!= GL_TEXTURE_2D_ARRAY
)
4063 zoffset
+= texImage
->Border
;
4066 if (target
!= GL_TEXTURE_1D_ARRAY
)
4067 yoffset
+= texImage
->Border
;
4070 xoffset
+= texImage
->Border
;
4073 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
4075 struct gl_renderbuffer
*srcRb
=
4076 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
4078 copytexsubimage_by_slice(ctx
, texImage
, dims
,
4079 xoffset
, yoffset
, zoffset
,
4080 srcRb
, x
, y
, width
, height
);
4082 check_gen_mipmap(ctx
, target
, texObj
, level
);
4084 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4085 * the texel data, not the texture format, size, etc.
4089 _mesa_unlock_texture(ctx
, texObj
);
4093 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
4094 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4096 struct gl_texture_object
* texObj
;
4097 const char *self
= "glCopyTexSubImage1D";
4098 GET_CURRENT_CONTEXT(ctx
);
4100 /* Check target (proxies not allowed). Target must be checked prior to
4101 * calling _mesa_get_current_tex_object.
4103 if (!legal_texsubimage_target(ctx
, 1, target
, false)) {
4104 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4105 _mesa_lookup_enum_by_nr(target
));
4109 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4113 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, target
, level
, xoffset
, 0, 0,
4114 x
, y
, width
, 1, self
);
4120 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
4121 GLint xoffset
, GLint yoffset
,
4122 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4124 struct gl_texture_object
* texObj
;
4125 const char *self
= "glCopyTexSubImage2D";
4126 GET_CURRENT_CONTEXT(ctx
);
4128 /* Check target (proxies not allowed). Target must be checked prior to
4129 * calling _mesa_get_current_tex_object.
4131 if (!legal_texsubimage_target(ctx
, 2, target
, false)) {
4132 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4133 _mesa_lookup_enum_by_nr(target
));
4137 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4141 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, target
, level
,
4142 xoffset
, yoffset
, 0,
4143 x
, y
, width
, height
, self
);
4149 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
4150 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4151 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4153 struct gl_texture_object
* texObj
;
4154 const char *self
= "glCopyTexSubImage3D";
4155 GET_CURRENT_CONTEXT(ctx
);
4157 /* Check target (proxies not allowed). Target must be checked prior to
4158 * calling _mesa_get_current_tex_object.
4160 if (!legal_texsubimage_target(ctx
, 3, target
, false)) {
4161 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4162 _mesa_lookup_enum_by_nr(target
));
4166 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4170 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, target
, level
,
4171 xoffset
, yoffset
, zoffset
,
4172 x
, y
, width
, height
, self
);
4176 _mesa_CopyTextureSubImage1D(GLuint texture
, GLint level
,
4177 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
4179 struct gl_texture_object
* texObj
;
4180 const char *self
= "glCopyTextureSubImage1D";
4181 GET_CURRENT_CONTEXT(ctx
);
4183 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4187 /* Check target (proxies not allowed). */
4188 if (!legal_texsubimage_target(ctx
, 1, texObj
->Target
, true)) {
4189 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4190 _mesa_lookup_enum_by_nr(texObj
->Target
));
4194 _mesa_copy_texture_sub_image(ctx
, 1, texObj
, texObj
->Target
, level
,
4195 xoffset
, 0, 0, x
, y
, width
, 1, self
);
4199 _mesa_CopyTextureSubImage2D(GLuint texture
, GLint level
,
4200 GLint xoffset
, GLint yoffset
,
4201 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4203 struct gl_texture_object
* texObj
;
4204 const char *self
= "glCopyTextureSubImage2D";
4205 GET_CURRENT_CONTEXT(ctx
);
4207 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4211 /* Check target (proxies not allowed). */
4212 if (!legal_texsubimage_target(ctx
, 2, texObj
->Target
, true)) {
4213 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4214 _mesa_lookup_enum_by_nr(texObj
->Target
));
4218 _mesa_copy_texture_sub_image(ctx
, 2, texObj
, texObj
->Target
, level
,
4219 xoffset
, yoffset
, 0,
4220 x
, y
, width
, height
, self
);
4226 _mesa_CopyTextureSubImage3D(GLuint texture
, GLint level
,
4227 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4228 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
4230 struct gl_texture_object
* texObj
;
4231 const char *self
= "glCopyTextureSubImage3D";
4232 GET_CURRENT_CONTEXT(ctx
);
4234 texObj
= _mesa_lookup_texture_err(ctx
, texture
, self
);
4238 /* Check target (proxies not allowed). */
4239 if (!legal_texsubimage_target(ctx
, 3, texObj
->Target
, true)) {
4240 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", self
,
4241 _mesa_lookup_enum_by_nr(texObj
->Target
));
4245 _mesa_copy_texture_sub_image(ctx
, 3, texObj
, texObj
->Target
, level
,
4246 xoffset
, yoffset
, zoffset
,
4247 x
, y
, width
, height
, self
);
4251 check_clear_tex_image(struct gl_context
*ctx
,
4252 const char *function
,
4253 struct gl_texture_image
*texImage
,
4254 GLenum format
, GLenum type
,
4256 GLubyte
*clearValue
)
4258 struct gl_texture_object
*texObj
= texImage
->TexObject
;
4259 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
4260 GLenum internalFormat
= texImage
->InternalFormat
;
4263 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
4264 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4265 "%s(buffer texture)", function
);
4269 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
4270 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4271 "%s(compressed texture)", function
);
4275 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
4276 if (err
!= GL_NO_ERROR
) {
4277 _mesa_error(ctx
, err
,
4278 "%s(incompatible format = %s, type = %s)",
4280 _mesa_lookup_enum_by_nr(format
),
4281 _mesa_lookup_enum_by_nr(type
));
4285 /* make sure internal format and format basically agree */
4286 if (!texture_formats_agree(internalFormat
, format
)) {
4287 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4288 "%s(incompatible internalFormat = %s, format = %s)",
4290 _mesa_lookup_enum_by_nr(internalFormat
),
4291 _mesa_lookup_enum_by_nr(format
));
4295 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
4296 /* both source and dest must be integer-valued, or neither */
4297 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
4298 _mesa_is_enum_format_integer(format
)) {
4299 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4300 "%s(integer/non-integer format mismatch)",
4306 if (!_mesa_texstore(ctx
,
4308 texImage
->_BaseFormat
,
4309 texImage
->TexFormat
,
4310 0, /* dstRowStride */
4312 1, 1, 1, /* srcWidth/Height/Depth */
4314 data
? data
: zeroData
,
4315 &ctx
->DefaultPacking
)) {
4316 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4323 static struct gl_texture_object
*
4324 get_tex_obj_for_clear(struct gl_context
*ctx
,
4325 const char *function
,
4328 struct gl_texture_object
*texObj
;
4331 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4335 texObj
= _mesa_lookup_texture(ctx
, texture
);
4337 if (texObj
== NULL
) {
4338 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4342 if (texObj
->Target
== 0) {
4343 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4351 get_tex_images_for_clear(struct gl_context
*ctx
,
4352 const char *function
,
4353 struct gl_texture_object
*texObj
,
4355 struct gl_texture_image
**texImages
)
4360 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4361 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4365 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4366 for (i
= 0; i
< MAX_FACES
; i
++) {
4367 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4369 texImages
[i
] = _mesa_select_tex_image(texObj
, target
, level
);
4370 if (texImages
[i
] == NULL
) {
4371 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4372 "%s(invalid level)", function
);
4380 texImages
[0] = _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4382 if (texImages
[0] == NULL
) {
4383 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4391 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4392 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4393 GLsizei width
, GLsizei height
, GLsizei depth
,
4394 GLenum format
, GLenum type
, const void *data
)
4396 GET_CURRENT_CONTEXT(ctx
);
4397 struct gl_texture_object
*texObj
;
4398 struct gl_texture_image
*texImages
[MAX_FACES
];
4399 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4401 int minDepth
, maxDepth
;
4403 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4408 _mesa_lock_texture(ctx
, texObj
);
4410 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4411 texObj
, level
, texImages
);
4415 if (numImages
== 1) {
4416 minDepth
= -(int) texImages
[0]->Border
;
4417 maxDepth
= texImages
[0]->Depth
;
4420 maxDepth
= numImages
;
4423 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4424 yoffset
< -(GLint
) texImages
[0]->Border
||
4425 zoffset
< minDepth
||
4429 xoffset
+ width
> texImages
[0]->Width
||
4430 yoffset
+ height
> texImages
[0]->Height
||
4431 zoffset
+ depth
> maxDepth
) {
4432 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4433 "glClearSubTexImage(invalid dimensions)");
4437 if (numImages
== 1) {
4438 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4440 format
, type
, data
, clearValue
[0])) {
4441 ctx
->Driver
.ClearTexSubImage(ctx
,
4443 xoffset
, yoffset
, zoffset
,
4444 width
, height
, depth
,
4445 data
? clearValue
[0] : NULL
);
4448 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4449 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4451 format
, type
, data
, clearValue
[i
]))
4454 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4455 ctx
->Driver
.ClearTexSubImage(ctx
,
4457 xoffset
, yoffset
, 0,
4459 data
? clearValue
[i
] : NULL
);
4464 _mesa_unlock_texture(ctx
, texObj
);
4468 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4469 GLenum format
, GLenum type
, const void *data
)
4471 GET_CURRENT_CONTEXT(ctx
);
4472 struct gl_texture_object
*texObj
;
4473 struct gl_texture_image
*texImages
[MAX_FACES
];
4474 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4477 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4482 _mesa_lock_texture(ctx
, texObj
);
4484 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4485 texObj
, level
, texImages
);
4487 for (i
= 0; i
< numImages
; i
++) {
4488 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4495 for (i
= 0; i
< numImages
; i
++) {
4496 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4497 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4498 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4499 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4500 texImages
[i
]->Width
,
4501 texImages
[i
]->Height
,
4502 texImages
[i
]->Depth
,
4503 data
? clearValue
[i
] : NULL
);
4507 _mesa_unlock_texture(ctx
, texObj
);
4513 /**********************************************************************/
4514 /****** Compressed Textures ******/
4515 /**********************************************************************/
4519 * Target checking for glCompressedTexSubImage[123]D().
4520 * \return GL_TRUE if error, GL_FALSE if no error
4521 * Must come before other error checking so that the texture object can
4522 * be correctly retrieved using _mesa_get_current_tex_object.
4525 compressed_subtexture_target_check(struct gl_context
*ctx
, GLenum target
,
4526 GLint dims
, GLenum format
, bool dsa
,
4531 if (dsa
&& target
== GL_TEXTURE_RECTANGLE
) {
4532 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid target %s)", caller
,
4533 _mesa_lookup_enum_by_nr(target
));
4541 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4542 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4543 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4544 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4545 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4546 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4550 targetOK
= GL_FALSE
;
4555 targetOK
= (target
== GL_TEXTURE_3D
) ||
4556 (target
== GL_TEXTURE_2D_ARRAY
) ||
4557 (target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ||
4558 (target
== GL_TEXTURE_CUBE_MAP
&& dsa
);
4560 /* OpenGL 4.5 spec (30.10.2014) says in Section 8.7 Compressed Texture
4562 * "An INVALID_OPERATION error is generated by
4563 * CompressedTex*SubImage3D if the internal format of the texture is
4564 * one of the EAC, ETC2, or RGTC formats and either border is
4565 * non-zero, or the effective target for the texture is not
4566 * TEXTURE_2D_ARRAY."
4568 if (target
!= GL_TEXTURE_2D_ARRAY
) {
4571 /* These came from _mesa_is_compressed_format in glformats.c. */
4573 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
4574 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
4575 case GL_COMPRESSED_R11_EAC
:
4576 case GL_COMPRESSED_RG11_EAC
:
4577 case GL_COMPRESSED_SIGNED_R11_EAC
:
4578 case GL_COMPRESSED_SIGNED_RG11_EAC
:
4580 case GL_COMPRESSED_RGB8_ETC2
:
4581 case GL_COMPRESSED_SRGB8_ETC2
:
4582 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
4583 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
4585 case GL_COMPRESSED_RED_RGTC1
:
4586 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
4587 case GL_COMPRESSED_RG_RGTC2
:
4588 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
4589 invalidformat
= true;
4592 invalidformat
= false;
4594 if (invalidformat
) {
4595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4596 "%s(invalid target %s for format %s)", caller
,
4597 _mesa_lookup_enum_by_nr(target
),
4598 _mesa_lookup_enum_by_nr(format
));
4606 /* no 1D compressed textures at this time */
4607 targetOK
= GL_FALSE
;
4612 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(invalid target %s)", caller
,
4613 _mesa_lookup_enum_by_nr(target
));
4621 * Error checking for glCompressedTexSubImage[123]D().
4622 * \return GL_TRUE if error, GL_FALSE if no error
4625 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4626 const struct gl_texture_object
*texObj
,
4627 GLenum target
, GLint level
,
4628 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4629 GLsizei width
, GLsizei height
, GLsizei depth
,
4630 GLenum format
, GLsizei imageSize
,
4631 const GLvoid
*data
, const char *callerName
)
4633 struct gl_texture_image
*texImage
;
4636 /* this will catch any invalid compressed format token */
4637 if (!_mesa_is_compressed_format(ctx
, format
)) {
4638 _mesa_error(ctx
, GL_INVALID_ENUM
,
4639 "%s(format)", callerName
);
4643 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4644 _mesa_error(ctx
, GL_INVALID_VALUE
,
4650 /* validate the bound PBO, if any */
4651 if (!_mesa_validate_pbo_source_compressed(ctx
, dims
, &ctx
->Unpack
,
4652 imageSize
, data
, callerName
)) {
4656 /* Check for invalid pixel storage modes */
4657 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4658 &ctx
->Unpack
, callerName
)) {
4662 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4663 if (expectedSize
!= imageSize
) {
4664 _mesa_error(ctx
, GL_INVALID_VALUE
,
4666 callerName
, imageSize
);
4670 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4672 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4673 "%s(invalid texture image)",
4678 if ((GLint
) format
!= texImage
->InternalFormat
) {
4679 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4681 callerName
, format
);
4685 if (compressedteximage_only_format(ctx
, format
)) {
4686 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4687 "%s(format=0x%x cannot be updated)",
4688 callerName
, format
);
4692 if (error_check_subtexture_dimensions(ctx
, dims
,
4693 texImage
, xoffset
, yoffset
, zoffset
,
4694 width
, height
, depth
,
4704 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4705 GLenum internalFormat
, GLsizei width
,
4706 GLint border
, GLsizei imageSize
,
4709 GET_CURRENT_CONTEXT(ctx
);
4710 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4711 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4716 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4717 GLenum internalFormat
, GLsizei width
,
4718 GLsizei height
, GLint border
, GLsizei imageSize
,
4721 GET_CURRENT_CONTEXT(ctx
);
4722 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4723 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4728 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4729 GLenum internalFormat
, GLsizei width
,
4730 GLsizei height
, GLsizei depth
, GLint border
,
4731 GLsizei imageSize
, const GLvoid
*data
)
4733 GET_CURRENT_CONTEXT(ctx
);
4734 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4735 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4740 * Common helper for glCompressedTexSubImage1/2/3D() and
4741 * glCompressedTextureSubImage1/2/3D().
4744 _mesa_compressed_texture_sub_image(struct gl_context
*ctx
, GLuint dims
,
4745 struct gl_texture_object
*texObj
,
4746 struct gl_texture_image
*texImage
,
4747 GLenum target
, GLint level
,
4748 GLint xoffset
, GLint yoffset
,
4750 GLsizei width
, GLsizei height
,
4752 GLenum format
, GLsizei imageSize
,
4755 FLUSH_VERTICES(ctx
, 0);
4757 _mesa_lock_texture(ctx
, texObj
);
4759 if (width
> 0 && height
> 0 && depth
> 0) {
4760 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4761 xoffset
, yoffset
, zoffset
,
4762 width
, height
, depth
,
4763 format
, imageSize
, data
);
4765 check_gen_mipmap(ctx
, target
, texObj
, level
);
4767 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4768 * the texel data, not the texture format, size, etc.
4772 _mesa_unlock_texture(ctx
, texObj
);
4777 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4778 GLsizei width
, GLenum format
,
4779 GLsizei imageSize
, const GLvoid
*data
)
4781 struct gl_texture_object
*texObj
;
4782 struct gl_texture_image
*texImage
;
4784 GET_CURRENT_CONTEXT(ctx
);
4786 if (compressed_subtexture_target_check(ctx
, target
, 1, format
, false,
4787 "glCompressedTexSubImage1D")) {
4791 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4795 if (compressed_subtexture_error_check(ctx
, 1, texObj
, target
,
4796 level
, xoffset
, 0, 0,
4798 format
, imageSize
, data
,
4799 "glCompressedTexSubImage1D")) {
4803 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4806 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
, target
, level
,
4807 xoffset
, 0, 0, width
, 1, 1,
4808 format
, imageSize
, data
);
4812 _mesa_CompressedTextureSubImage1D(GLuint texture
, GLint level
, GLint xoffset
,
4813 GLsizei width
, GLenum format
,
4814 GLsizei imageSize
, const GLvoid
*data
)
4816 struct gl_texture_object
*texObj
;
4817 struct gl_texture_image
*texImage
;
4819 GET_CURRENT_CONTEXT(ctx
);
4821 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4822 "glCompressedTextureSubImage1D");
4826 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 1, format
,
4828 "glCompressedTextureSubImage1D")) {
4832 if (compressed_subtexture_error_check(ctx
, 1, texObj
, texObj
->Target
,
4833 level
, xoffset
, 0, 0,
4835 format
, imageSize
, data
,
4836 "glCompressedTextureSubImage1D")) {
4840 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4843 _mesa_compressed_texture_sub_image(ctx
, 1, texObj
, texImage
,
4844 texObj
->Target
, level
,
4845 xoffset
, 0, 0, width
, 1, 1,
4846 format
, imageSize
, data
);
4851 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4852 GLint yoffset
, GLsizei width
, GLsizei height
,
4853 GLenum format
, GLsizei imageSize
,
4856 struct gl_texture_object
*texObj
;
4857 struct gl_texture_image
*texImage
;
4859 GET_CURRENT_CONTEXT(ctx
);
4861 if (compressed_subtexture_target_check(ctx
, target
, 2, format
, false,
4862 "glCompressedTexSubImage2D")) {
4866 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4870 if (compressed_subtexture_error_check(ctx
, 2, texObj
, target
,
4871 level
, xoffset
, yoffset
, 0,
4873 format
, imageSize
, data
,
4874 "glCompressedTexSubImage2D")) {
4879 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4882 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
, target
, level
,
4883 xoffset
, yoffset
, 0, width
, height
, 1,
4884 format
, imageSize
, data
);
4888 _mesa_CompressedTextureSubImage2D(GLuint texture
, GLint level
, GLint xoffset
,
4890 GLsizei width
, GLsizei height
,
4891 GLenum format
, GLsizei imageSize
,
4894 struct gl_texture_object
*texObj
;
4895 struct gl_texture_image
*texImage
;
4897 GET_CURRENT_CONTEXT(ctx
);
4899 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4900 "glCompressedTextureSubImage2D");
4904 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 2, format
,
4906 "glCompressedTextureSubImage2D")) {
4910 if (compressed_subtexture_error_check(ctx
, 2, texObj
, texObj
->Target
,
4911 level
, xoffset
, yoffset
, 0,
4913 format
, imageSize
, data
,
4914 "glCompressedTextureSubImage2D")) {
4918 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
4921 _mesa_compressed_texture_sub_image(ctx
, 2, texObj
, texImage
,
4922 texObj
->Target
, level
,
4923 xoffset
, yoffset
, 0, width
, height
, 1,
4924 format
, imageSize
, data
);
4928 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4929 GLint yoffset
, GLint zoffset
, GLsizei width
,
4930 GLsizei height
, GLsizei depth
, GLenum format
,
4931 GLsizei imageSize
, const GLvoid
*data
)
4933 struct gl_texture_object
*texObj
;
4934 struct gl_texture_image
*texImage
;
4936 GET_CURRENT_CONTEXT(ctx
);
4938 if (compressed_subtexture_target_check(ctx
, target
, 3, format
, false,
4939 "glCompressedTexSubImage3D")) {
4943 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4947 if (compressed_subtexture_error_check(ctx
, 3, texObj
, target
,
4948 level
, xoffset
, yoffset
, zoffset
,
4949 width
, height
, depth
,
4950 format
, imageSize
, data
,
4951 "glCompressedTexSubImage3D")) {
4956 texImage
= _mesa_select_tex_image(texObj
, target
, level
);
4959 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
, target
, level
,
4960 xoffset
, yoffset
, zoffset
,
4961 width
, height
, depth
,
4962 format
, imageSize
, data
);
4966 _mesa_CompressedTextureSubImage3D(GLuint texture
, GLint level
, GLint xoffset
,
4967 GLint yoffset
, GLint zoffset
, GLsizei width
,
4968 GLsizei height
, GLsizei depth
,
4969 GLenum format
, GLsizei imageSize
,
4972 struct gl_texture_object
*texObj
;
4973 struct gl_texture_image
*texImage
;
4975 GET_CURRENT_CONTEXT(ctx
);
4977 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
4978 "glCompressedTextureSubImage3D");
4982 if (compressed_subtexture_target_check(ctx
, texObj
->Target
, 3, format
,
4984 "glCompressedTextureSubImage3D")) {
4988 if (compressed_subtexture_error_check(ctx
, 3, texObj
, texObj
->Target
,
4989 level
, xoffset
, yoffset
, zoffset
,
4990 width
, height
, depth
,
4991 format
, imageSize
, data
,
4992 "glCompressedTextureSubImage3D")) {
4996 /* Must handle special case GL_TEXTURE_CUBE_MAP. */
4997 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4998 const char *pixels
= data
;
5002 /* Make sure the texture object is a proper cube.
5003 * (See texturesubimage in teximage.c for details on why this check is
5006 if (!_mesa_cube_level_complete(texObj
, level
)) {
5007 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5008 "glCompressedTextureSubImage3D(cube map incomplete)");
5012 /* Copy in each face. */
5013 for (i
= 0; i
< 6; ++i
) {
5014 texImage
= texObj
->Image
[i
][level
];
5017 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5018 texObj
->Target
, level
,
5019 xoffset
, yoffset
, zoffset
,
5021 format
, imageSize
, pixels
);
5023 /* Compressed images don't have a client format */
5024 image_stride
= _mesa_format_image_size(texImage
->TexFormat
,
5026 texImage
->Height
, 1);
5028 pixels
+= image_stride
;
5029 imageSize
-= image_stride
;
5033 texImage
= _mesa_select_tex_image(texObj
, texObj
->Target
, level
);
5036 _mesa_compressed_texture_sub_image(ctx
, 3, texObj
, texImage
,
5037 texObj
->Target
, level
,
5038 xoffset
, yoffset
, zoffset
,
5039 width
, height
, depth
,
5040 format
, imageSize
, data
);
5045 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
5047 if (ctx
->API
!= API_OPENGL_CORE
) {
5048 switch (internalFormat
) {
5050 return MESA_FORMAT_A_UNORM8
;
5052 return MESA_FORMAT_A_UNORM16
;
5053 case GL_ALPHA16F_ARB
:
5054 return MESA_FORMAT_A_FLOAT16
;
5055 case GL_ALPHA32F_ARB
:
5056 return MESA_FORMAT_A_FLOAT32
;
5057 case GL_ALPHA8I_EXT
:
5058 return MESA_FORMAT_A_SINT8
;
5059 case GL_ALPHA16I_EXT
:
5060 return MESA_FORMAT_A_SINT16
;
5061 case GL_ALPHA32I_EXT
:
5062 return MESA_FORMAT_A_SINT32
;
5063 case GL_ALPHA8UI_EXT
:
5064 return MESA_FORMAT_A_UINT8
;
5065 case GL_ALPHA16UI_EXT
:
5066 return MESA_FORMAT_A_UINT16
;
5067 case GL_ALPHA32UI_EXT
:
5068 return MESA_FORMAT_A_UINT32
;
5070 return MESA_FORMAT_L_UNORM8
;
5071 case GL_LUMINANCE16
:
5072 return MESA_FORMAT_L_UNORM16
;
5073 case GL_LUMINANCE16F_ARB
:
5074 return MESA_FORMAT_L_FLOAT16
;
5075 case GL_LUMINANCE32F_ARB
:
5076 return MESA_FORMAT_L_FLOAT32
;
5077 case GL_LUMINANCE8I_EXT
:
5078 return MESA_FORMAT_L_SINT8
;
5079 case GL_LUMINANCE16I_EXT
:
5080 return MESA_FORMAT_L_SINT16
;
5081 case GL_LUMINANCE32I_EXT
:
5082 return MESA_FORMAT_L_SINT32
;
5083 case GL_LUMINANCE8UI_EXT
:
5084 return MESA_FORMAT_L_UINT8
;
5085 case GL_LUMINANCE16UI_EXT
:
5086 return MESA_FORMAT_L_UINT16
;
5087 case GL_LUMINANCE32UI_EXT
:
5088 return MESA_FORMAT_L_UINT32
;
5089 case GL_LUMINANCE8_ALPHA8
:
5090 return MESA_FORMAT_L8A8_UNORM
;
5091 case GL_LUMINANCE16_ALPHA16
:
5092 return MESA_FORMAT_L16A16_UNORM
;
5093 case GL_LUMINANCE_ALPHA16F_ARB
:
5094 return MESA_FORMAT_LA_FLOAT16
;
5095 case GL_LUMINANCE_ALPHA32F_ARB
:
5096 return MESA_FORMAT_LA_FLOAT32
;
5097 case GL_LUMINANCE_ALPHA8I_EXT
:
5098 return MESA_FORMAT_LA_SINT8
;
5099 case GL_LUMINANCE_ALPHA16I_EXT
:
5100 return MESA_FORMAT_LA_SINT16
;
5101 case GL_LUMINANCE_ALPHA32I_EXT
:
5102 return MESA_FORMAT_LA_SINT32
;
5103 case GL_LUMINANCE_ALPHA8UI_EXT
:
5104 return MESA_FORMAT_LA_UINT8
;
5105 case GL_LUMINANCE_ALPHA16UI_EXT
:
5106 return MESA_FORMAT_LA_UINT16
;
5107 case GL_LUMINANCE_ALPHA32UI_EXT
:
5108 return MESA_FORMAT_LA_UINT32
;
5110 return MESA_FORMAT_I_UNORM8
;
5111 case GL_INTENSITY16
:
5112 return MESA_FORMAT_I_UNORM16
;
5113 case GL_INTENSITY16F_ARB
:
5114 return MESA_FORMAT_I_FLOAT16
;
5115 case GL_INTENSITY32F_ARB
:
5116 return MESA_FORMAT_I_FLOAT32
;
5117 case GL_INTENSITY8I_EXT
:
5118 return MESA_FORMAT_I_SINT8
;
5119 case GL_INTENSITY16I_EXT
:
5120 return MESA_FORMAT_I_SINT16
;
5121 case GL_INTENSITY32I_EXT
:
5122 return MESA_FORMAT_I_SINT32
;
5123 case GL_INTENSITY8UI_EXT
:
5124 return MESA_FORMAT_I_UINT8
;
5125 case GL_INTENSITY16UI_EXT
:
5126 return MESA_FORMAT_I_UINT16
;
5127 case GL_INTENSITY32UI_EXT
:
5128 return MESA_FORMAT_I_UINT32
;
5134 if (ctx
->API
== API_OPENGL_CORE
&&
5135 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5136 switch (internalFormat
) {
5138 return MESA_FORMAT_RGB_FLOAT32
;
5140 return MESA_FORMAT_RGB_UINT32
;
5142 return MESA_FORMAT_RGB_SINT32
;
5148 switch (internalFormat
) {
5150 return MESA_FORMAT_R8G8B8A8_UNORM
;
5152 return MESA_FORMAT_RGBA_UNORM16
;
5153 case GL_RGBA16F_ARB
:
5154 return MESA_FORMAT_RGBA_FLOAT16
;
5155 case GL_RGBA32F_ARB
:
5156 return MESA_FORMAT_RGBA_FLOAT32
;
5158 return MESA_FORMAT_RGBA_SINT8
;
5159 case GL_RGBA16I_EXT
:
5160 return MESA_FORMAT_RGBA_SINT16
;
5161 case GL_RGBA32I_EXT
:
5162 return MESA_FORMAT_RGBA_SINT32
;
5163 case GL_RGBA8UI_EXT
:
5164 return MESA_FORMAT_RGBA_UINT8
;
5165 case GL_RGBA16UI_EXT
:
5166 return MESA_FORMAT_RGBA_UINT16
;
5167 case GL_RGBA32UI_EXT
:
5168 return MESA_FORMAT_RGBA_UINT32
;
5171 return MESA_FORMAT_R8G8_UNORM
;
5173 return MESA_FORMAT_R16G16_UNORM
;
5175 return MESA_FORMAT_RG_FLOAT16
;
5177 return MESA_FORMAT_RG_FLOAT32
;
5179 return MESA_FORMAT_RG_SINT8
;
5181 return MESA_FORMAT_RG_SINT16
;
5183 return MESA_FORMAT_RG_SINT32
;
5185 return MESA_FORMAT_RG_UINT8
;
5187 return MESA_FORMAT_RG_UINT16
;
5189 return MESA_FORMAT_RG_UINT32
;
5192 return MESA_FORMAT_R_UNORM8
;
5194 return MESA_FORMAT_R_UNORM16
;
5196 return MESA_FORMAT_R_FLOAT16
;
5198 return MESA_FORMAT_R_FLOAT32
;
5200 return MESA_FORMAT_R_SINT8
;
5202 return MESA_FORMAT_R_SINT16
;
5204 return MESA_FORMAT_R_SINT32
;
5206 return MESA_FORMAT_R_UINT8
;
5208 return MESA_FORMAT_R_UINT16
;
5210 return MESA_FORMAT_R_UINT32
;
5213 return MESA_FORMAT_NONE
;
5219 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
5220 GLenum internalFormat
)
5222 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
5225 if (format
== MESA_FORMAT_NONE
)
5226 return MESA_FORMAT_NONE
;
5228 datatype
= _mesa_get_format_datatype(format
);
5230 /* The GL_ARB_texture_buffer_object spec says:
5232 * "If ARB_texture_float is not supported, references to the
5233 * floating-point internal formats provided by that extension should be
5234 * removed, and such formats may not be passed to TexBufferARB."
5236 * As a result, GL_HALF_FLOAT internal format depends on both
5237 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
5239 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
5240 !ctx
->Extensions
.ARB_texture_float
)
5241 return MESA_FORMAT_NONE
;
5243 if (!ctx
->Extensions
.ARB_texture_rg
) {
5244 GLenum base_format
= _mesa_get_format_base_format(format
);
5245 if (base_format
== GL_R
|| base_format
== GL_RG
)
5246 return MESA_FORMAT_NONE
;
5249 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
5250 GLenum base_format
= _mesa_get_format_base_format(format
);
5251 if (base_format
== GL_RGB
)
5252 return MESA_FORMAT_NONE
;
5259 _mesa_texture_buffer_range(struct gl_context
*ctx
,
5260 struct gl_texture_object
*texObj
,
5261 GLenum internalFormat
,
5262 struct gl_buffer_object
*bufObj
,
5263 GLintptr offset
, GLsizeiptr size
,
5268 /* NOTE: ARB_texture_buffer_object has interactions with
5269 * the compatibility profile that are not implemented.
5271 if (!(ctx
->API
== API_OPENGL_CORE
&&
5272 ctx
->Extensions
.ARB_texture_buffer_object
)) {
5273 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5274 "%s(ARB_texture_buffer_object is not"
5275 " implemented for the compatibility profile)", caller
);
5279 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
5280 if (format
== MESA_FORMAT_NONE
) {
5281 _mesa_error(ctx
, GL_INVALID_ENUM
,
5282 "%s(internalFormat 0x%x)", caller
, internalFormat
);
5286 FLUSH_VERTICES(ctx
, 0);
5288 _mesa_lock_texture(ctx
, texObj
);
5290 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
5291 texObj
->BufferObjectFormat
= internalFormat
;
5292 texObj
->_BufferObjectFormat
= format
;
5293 texObj
->BufferOffset
= offset
;
5294 texObj
->BufferSize
= size
;
5296 _mesa_unlock_texture(ctx
, texObj
);
5298 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
5301 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
5307 * Make sure the texture buffer target is GL_TEXTURE_BUFFER.
5308 * Return true if it is, and return false if it is not
5309 * (and throw INVALID ENUM as dictated in the OpenGL 4.5
5310 * core spec, 02.02.2015, PDF page 245).
5313 check_texture_buffer_target(struct gl_context
*ctx
, GLenum target
,
5316 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
5317 _mesa_error(ctx
, GL_INVALID_ENUM
,
5318 "%s(texture target is not GL_TEXTURE_BUFFER)", caller
);
5326 * Check for errors related to the texture buffer range.
5327 * Return false if errors are found, true if none are found.
5330 check_texture_buffer_range(struct gl_context
*ctx
,
5331 struct gl_buffer_object
*bufObj
,
5332 GLintptr offset
, GLsizeiptr size
,
5335 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5336 * Textures (PDF page 245):
5337 * "An INVALID_VALUE error is generated if offset is negative, if
5338 * size is less than or equal to zero, or if offset + size is greater
5339 * than the value of BUFFER_SIZE for the buffer bound to target."
5342 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(offset=%d < 0)", caller
,
5348 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s(size=%d <= 0)", caller
,
5353 if (offset
+ size
> bufObj
->Size
) {
5354 _mesa_error(ctx
, GL_INVALID_VALUE
,
5355 "%s(offset=%d + size=%d > buffer_size=%d)", caller
,
5356 (int) offset
, (int) size
, (int) bufObj
->Size
);
5360 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5361 * Textures (PDF page 245):
5362 * "An INVALID_VALUE error is generated if offset is not an integer
5363 * multiple of the value of TEXTURE_BUFFER_OFFSET_ALIGNMENT."
5365 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
5366 _mesa_error(ctx
, GL_INVALID_VALUE
,
5367 "%s(invalid offset alignment)", caller
);
5375 /** GL_ARB_texture_buffer_object */
5377 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
5379 struct gl_texture_object
*texObj
;
5380 struct gl_buffer_object
*bufObj
;
5382 GET_CURRENT_CONTEXT(ctx
);
5384 /* Need to catch a bad target before it gets to
5385 * _mesa_get_current_tex_object.
5387 if (!check_texture_buffer_target(ctx
, target
, "glTexBuffer"))
5391 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBuffer");
5397 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5401 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
, 0,
5402 buffer
? -1 : 0, "glTexBuffer");
5406 /** GL_ARB_texture_buffer_range */
5408 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
5409 GLintptr offset
, GLsizeiptr size
)
5411 struct gl_texture_object
*texObj
;
5412 struct gl_buffer_object
*bufObj
;
5414 GET_CURRENT_CONTEXT(ctx
);
5416 /* Need to catch a bad target before it gets to
5417 * _mesa_get_current_tex_object.
5419 if (!check_texture_buffer_target(ctx
, target
, "glTexBufferRange"))
5423 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTexBufferRange");
5427 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5428 "glTexBufferRange"))
5433 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5434 * Textures (PDF page 254):
5435 * "If buffer is zero, then any buffer object attached to the buffer
5436 * texture is detached, the values offset and size are ignored and
5437 * the state for offset and size for the buffer texture are reset to
5445 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5449 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
, bufObj
,
5450 offset
, size
, "glTexBufferRange");
5454 _mesa_TextureBuffer(GLuint texture
, GLenum internalFormat
, GLuint buffer
)
5456 struct gl_texture_object
*texObj
;
5457 struct gl_buffer_object
*bufObj
;
5459 GET_CURRENT_CONTEXT(ctx
);
5462 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
, "glTextureBuffer");
5468 /* Get the texture object by Name. */
5469 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBuffer");
5473 if (!check_texture_buffer_target(ctx
, texObj
->Target
, "glTextureBuffer"))
5476 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5477 bufObj
, 0, buffer
? -1 : 0, "glTextureBuffer");
5481 _mesa_TextureBufferRange(GLuint texture
, GLenum internalFormat
, GLuint buffer
,
5482 GLintptr offset
, GLsizeiptr size
)
5484 struct gl_texture_object
*texObj
;
5485 struct gl_buffer_object
*bufObj
;
5487 GET_CURRENT_CONTEXT(ctx
);
5490 bufObj
= _mesa_lookup_bufferobj_err(ctx
, buffer
,
5491 "glTextureBufferRange");
5495 if (!check_texture_buffer_range(ctx
, bufObj
, offset
, size
,
5496 "glTextureBufferRange"))
5501 /* OpenGL 4.5 core spec (02.02.2015) says in Section 8.9 Buffer
5502 * Textures (PDF page 254):
5503 * "If buffer is zero, then any buffer object attached to the buffer
5504 * texture is detached, the values offset and size are ignored and
5505 * the state for offset and size for the buffer texture are reset to
5513 /* Get the texture object by Name. */
5514 texObj
= _mesa_lookup_texture_err(ctx
, texture
, "glTextureBufferRange");
5518 if (!check_texture_buffer_target(ctx
, texObj
->Target
,
5519 "glTextureBufferRange"))
5522 _mesa_texture_buffer_range(ctx
, texObj
, internalFormat
,
5523 bufObj
, offset
, size
, "glTextureBufferRange");
5527 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
5529 /* Everything that is allowed for renderbuffers,
5530 * except for a base format of GL_STENCIL_INDEX.
5532 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
5533 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
5537 /** GL_ARB_texture_multisample */
5539 check_multisample_target(GLuint dims
, GLenum target
, bool dsa
)
5542 case GL_TEXTURE_2D_MULTISAMPLE
:
5544 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
5545 return dims
== 2 && !dsa
;
5547 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5549 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
5550 return dims
== 3 && !dsa
;
5559 _mesa_texture_image_multisample(struct gl_context
*ctx
, GLuint dims
,
5560 struct gl_texture_object
*texObj
,
5561 GLenum target
, GLsizei samples
,
5562 GLint internalformat
, GLsizei width
,
5563 GLsizei height
, GLsizei depth
,
5564 GLboolean fixedsamplelocations
,
5565 GLboolean immutable
, const char *func
)
5567 struct gl_texture_image
*texImage
;
5568 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
5569 mesa_format texFormat
;
5570 GLenum sample_count_error
;
5571 bool dsa
= strstr(func
, "ture") ? true : false;
5573 if (!(ctx
->Extensions
.ARB_texture_multisample
5574 && _mesa_is_desktop_gl(ctx
))) {
5575 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
5579 if (!check_multisample_target(dims
, target
, dsa
)) {
5581 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(target)", func
);
5585 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
5590 /* check that the specified internalformat is color/depth/stencil-renderable;
5591 * refer GL3.1 spec 4.4.4
5594 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
5595 _mesa_error(ctx
, GL_INVALID_ENUM
,
5596 "%s(internalformat=%s not legal for immutable-format)",
5597 func
, _mesa_lookup_enum_by_nr(internalformat
));
5601 if (!is_renderable_texture_format(ctx
, internalformat
)) {
5602 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5603 "%s(internalformat=%s)",
5604 func
, _mesa_lookup_enum_by_nr(internalformat
));
5608 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
5609 internalformat
, samples
);
5610 samplesOK
= sample_count_error
== GL_NO_ERROR
;
5612 /* Page 254 of OpenGL 4.4 spec says:
5613 * "Proxy arrays for two-dimensional multisample and two-dimensional
5614 * multisample array textures are operated on in the same way when
5615 * TexImage2DMultisample is called with target specified as
5616 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
5617 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
5618 * However, if samples is not supported, then no error is generated.
5620 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
5621 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
5625 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
5626 _mesa_error(ctx
, GL_INVALID_OPERATION
,
5627 "%s(texture object 0)",
5632 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
5634 if (texImage
== NULL
) {
5635 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
5639 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
5640 internalformat
, GL_NONE
, GL_NONE
);
5641 assert(texFormat
!= MESA_FORMAT_NONE
);
5643 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
5644 width
, height
, depth
, 0);
5646 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
5647 width
, height
, depth
, 0);
5649 if (_mesa_is_proxy_texture(target
)) {
5650 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
5651 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5652 internalformat
, texFormat
,
5653 samples
, fixedsamplelocations
);
5656 /* clear all image fields */
5657 clear_teximage_fields(texImage
);
5661 if (!dimensionsOK
) {
5662 _mesa_error(ctx
, GL_INVALID_VALUE
,
5663 "%s(invalid width or height)", func
);
5668 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
5669 "%s(texture too large)", func
);
5673 /* Check if texObj->Immutable is set */
5674 if (texObj
->Immutable
) {
5675 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
5679 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
5681 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
5682 internalformat
, texFormat
,
5683 samples
, fixedsamplelocations
);
5685 if (width
> 0 && height
> 0 && depth
> 0) {
5686 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
5687 width
, height
, depth
)) {
5688 /* tidy up the texture image state. strictly speaking,
5689 * we're allowed to just leave this in whatever state we
5690 * like, but being tidy is good.
5692 _mesa_init_teximage_fields(ctx
, texImage
,
5693 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
5697 texObj
->Immutable
|= immutable
;
5700 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
5703 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
5709 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
5710 GLenum internalformat
, GLsizei width
,
5711 GLsizei height
, GLboolean fixedsamplelocations
)
5713 struct gl_texture_object
*texObj
;
5714 GET_CURRENT_CONTEXT(ctx
);
5716 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5720 _mesa_texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5721 internalformat
, width
, height
, 1,
5722 fixedsamplelocations
, GL_FALSE
,
5723 "glTexImage2DMultisample");
5728 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
5729 GLenum internalformat
, GLsizei width
,
5730 GLsizei height
, GLsizei depth
,
5731 GLboolean fixedsamplelocations
)
5733 struct gl_texture_object
*texObj
;
5734 GET_CURRENT_CONTEXT(ctx
);
5736 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5740 _mesa_texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5741 internalformat
, width
, height
, depth
,
5742 fixedsamplelocations
, GL_FALSE
,
5743 "glTexImage3DMultisample");
5748 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
5749 GLenum internalformat
, GLsizei width
,
5750 GLsizei height
, GLboolean fixedsamplelocations
)
5752 struct gl_texture_object
*texObj
;
5753 GET_CURRENT_CONTEXT(ctx
);
5755 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5759 _mesa_texture_image_multisample(ctx
, 2, texObj
, target
, samples
,
5760 internalformat
, width
, height
, 1,
5761 fixedsamplelocations
, GL_TRUE
,
5762 "glTexStorage2DMultisample");
5766 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
5767 GLenum internalformat
, GLsizei width
,
5768 GLsizei height
, GLsizei depth
,
5769 GLboolean fixedsamplelocations
)
5771 struct gl_texture_object
*texObj
;
5772 GET_CURRENT_CONTEXT(ctx
);
5774 texObj
= _mesa_get_current_tex_object(ctx
, target
);
5778 _mesa_texture_image_multisample(ctx
, 3, texObj
, target
, samples
,
5779 internalformat
, width
, height
, depth
,
5780 fixedsamplelocations
, GL_TRUE
,
5781 "glTexStorage3DMultisample");
5785 _mesa_TextureStorage2DMultisample(GLuint texture
, GLsizei samples
,
5786 GLenum internalformat
, GLsizei width
,
5788 GLboolean fixedsamplelocations
)
5790 struct gl_texture_object
*texObj
;
5791 GET_CURRENT_CONTEXT(ctx
);
5793 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5794 "glTextureStorage2DMultisample");
5798 _mesa_texture_image_multisample(ctx
, 2, texObj
, texObj
->Target
, samples
,
5799 internalformat
, width
, height
, 1,
5800 fixedsamplelocations
, GL_TRUE
,
5801 "glTextureStorage2DMultisample");
5805 _mesa_TextureStorage3DMultisample(GLuint texture
, GLsizei samples
,
5806 GLenum internalformat
, GLsizei width
,
5807 GLsizei height
, GLsizei depth
,
5808 GLboolean fixedsamplelocations
)
5810 struct gl_texture_object
*texObj
;
5811 GET_CURRENT_CONTEXT(ctx
);
5813 /* Get the texture object by Name. */
5814 texObj
= _mesa_lookup_texture_err(ctx
, texture
,
5815 "glTextureStorage3DMultisample");
5819 _mesa_texture_image_multisample(ctx
, 3, texObj
, texObj
->Target
, samples
,
5820 internalformat
, width
, height
, depth
,
5821 fixedsamplelocations
, GL_TRUE
,
5822 "glTextureStorage3DMultisample");