2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
43 #include "multisample.h"
44 #include "pixelstore.h"
46 #include "texcompress.h"
47 #include "texcompress_cpal.h"
51 #include "texstorage.h"
52 #include "textureview.h"
54 #include "glformats.h"
59 * State changes which we care about for glCopyTex[Sub]Image() calls.
60 * In particular, we care about pixel transfer state and buffer state
61 * (such as glReadBuffer to make sure we read from the right renderbuffer).
63 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
68 * Return the simple base format for a given internal texture format.
69 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
71 * \param ctx GL context.
72 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
74 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
75 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
77 * This is the format which is used during texture application (i.e. the
78 * texture format and env mode determine the arithmetic used.
81 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
83 switch (internalFormat
) {
89 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
96 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
98 case GL_LUMINANCE_ALPHA
:
99 case GL_LUMINANCE4_ALPHA4
:
100 case GL_LUMINANCE6_ALPHA2
:
101 case GL_LUMINANCE8_ALPHA8
:
102 case GL_LUMINANCE12_ALPHA4
:
103 case GL_LUMINANCE12_ALPHA12
:
104 case GL_LUMINANCE16_ALPHA16
:
105 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
111 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
113 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
124 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
138 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
140 if (_mesa_is_gles(ctx
)) {
141 switch (internalFormat
) {
149 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
150 switch (internalFormat
) {
158 if (ctx
->Extensions
.ARB_depth_texture
) {
159 switch (internalFormat
) {
160 case GL_DEPTH_COMPONENT
:
161 case GL_DEPTH_COMPONENT16
:
162 case GL_DEPTH_COMPONENT24
:
163 case GL_DEPTH_COMPONENT32
:
164 return GL_DEPTH_COMPONENT
;
165 case GL_DEPTH_STENCIL
:
166 case GL_DEPTH24_STENCIL8
:
167 return GL_DEPTH_STENCIL
;
173 switch (internalFormat
) {
174 case GL_COMPRESSED_ALPHA
:
176 case GL_COMPRESSED_LUMINANCE
:
178 case GL_COMPRESSED_LUMINANCE_ALPHA
:
179 return GL_LUMINANCE_ALPHA
;
180 case GL_COMPRESSED_INTENSITY
:
182 case GL_COMPRESSED_RGB
:
184 case GL_COMPRESSED_RGBA
:
190 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
191 switch (internalFormat
) {
192 case GL_COMPRESSED_RGB_FXT1_3DFX
:
194 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
201 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
203 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
204 switch (internalFormat
) {
205 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
207 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
208 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
209 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
216 if (_mesa_is_desktop_gl(ctx
)
217 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
218 switch (internalFormat
) {
230 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
231 if (internalFormat
== GL_YCBCR_MESA
)
232 return GL_YCBCR_MESA
;
235 if (ctx
->Extensions
.ARB_texture_float
) {
236 switch (internalFormat
) {
237 case GL_ALPHA16F_ARB
:
238 case GL_ALPHA32F_ARB
:
246 case GL_INTENSITY16F_ARB
:
247 case GL_INTENSITY32F_ARB
:
249 case GL_LUMINANCE16F_ARB
:
250 case GL_LUMINANCE32F_ARB
:
252 case GL_LUMINANCE_ALPHA16F_ARB
:
253 case GL_LUMINANCE_ALPHA32F_ARB
:
254 return GL_LUMINANCE_ALPHA
;
260 if (ctx
->Extensions
.EXT_texture_snorm
) {
261 switch (internalFormat
) {
276 case GL_RGBA16_SNORM
:
279 case GL_ALPHA8_SNORM
:
280 case GL_ALPHA16_SNORM
:
282 case GL_LUMINANCE_SNORM
:
283 case GL_LUMINANCE8_SNORM
:
284 case GL_LUMINANCE16_SNORM
:
286 case GL_LUMINANCE_ALPHA_SNORM
:
287 case GL_LUMINANCE8_ALPHA8_SNORM
:
288 case GL_LUMINANCE16_ALPHA16_SNORM
:
289 return GL_LUMINANCE_ALPHA
;
290 case GL_INTENSITY_SNORM
:
291 case GL_INTENSITY8_SNORM
:
292 case GL_INTENSITY16_SNORM
:
299 if (ctx
->Extensions
.EXT_texture_sRGB
) {
300 switch (internalFormat
) {
303 case GL_COMPRESSED_SRGB_EXT
:
305 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
306 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
307 case GL_SRGB_ALPHA_EXT
:
308 case GL_SRGB8_ALPHA8_EXT
:
309 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
311 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
312 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
313 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
314 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
315 case GL_SLUMINANCE_ALPHA_EXT
:
316 case GL_SLUMINANCE8_ALPHA8_EXT
:
317 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
318 return GL_LUMINANCE_ALPHA
;
319 case GL_SLUMINANCE_EXT
:
320 case GL_SLUMINANCE8_EXT
:
321 case GL_COMPRESSED_SLUMINANCE_EXT
:
328 if (ctx
->Version
>= 30 ||
329 ctx
->Extensions
.EXT_texture_integer
) {
330 switch (internalFormat
) {
332 case GL_RGBA16UI_EXT
:
333 case GL_RGBA32UI_EXT
:
349 if (ctx
->Extensions
.EXT_texture_integer
) {
350 switch (internalFormat
) {
351 case GL_ALPHA8UI_EXT
:
352 case GL_ALPHA16UI_EXT
:
353 case GL_ALPHA32UI_EXT
:
355 case GL_ALPHA16I_EXT
:
356 case GL_ALPHA32I_EXT
:
358 case GL_INTENSITY8UI_EXT
:
359 case GL_INTENSITY16UI_EXT
:
360 case GL_INTENSITY32UI_EXT
:
361 case GL_INTENSITY8I_EXT
:
362 case GL_INTENSITY16I_EXT
:
363 case GL_INTENSITY32I_EXT
:
365 case GL_LUMINANCE8UI_EXT
:
366 case GL_LUMINANCE16UI_EXT
:
367 case GL_LUMINANCE32UI_EXT
:
368 case GL_LUMINANCE8I_EXT
:
369 case GL_LUMINANCE16I_EXT
:
370 case GL_LUMINANCE32I_EXT
:
372 case GL_LUMINANCE_ALPHA8UI_EXT
:
373 case GL_LUMINANCE_ALPHA16UI_EXT
:
374 case GL_LUMINANCE_ALPHA32UI_EXT
:
375 case GL_LUMINANCE_ALPHA8I_EXT
:
376 case GL_LUMINANCE_ALPHA16I_EXT
:
377 case GL_LUMINANCE_ALPHA32I_EXT
:
378 return GL_LUMINANCE_ALPHA
;
384 if (ctx
->Extensions
.ARB_texture_rg
) {
385 switch (internalFormat
) {
388 if (!ctx
->Extensions
.ARB_texture_float
)
397 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
403 case GL_COMPRESSED_RED
:
408 if (!ctx
->Extensions
.ARB_texture_float
)
417 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
423 case GL_COMPRESSED_RG
:
430 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
431 switch (internalFormat
) {
439 if (ctx
->Extensions
.EXT_packed_float
) {
440 switch (internalFormat
) {
441 case GL_R11F_G11F_B10F_EXT
:
448 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
449 switch (internalFormat
) {
450 case GL_DEPTH_COMPONENT32F
:
451 return GL_DEPTH_COMPONENT
;
452 case GL_DEPTH32F_STENCIL8
:
453 return GL_DEPTH_STENCIL
;
459 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
460 switch (internalFormat
) {
461 case GL_COMPRESSED_RED_RGTC1
:
462 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
464 case GL_COMPRESSED_RG_RGTC2
:
465 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
472 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
473 switch (internalFormat
) {
474 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
475 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
477 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
478 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
479 return GL_LUMINANCE_ALPHA
;
485 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
486 switch (internalFormat
) {
487 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
488 return GL_LUMINANCE_ALPHA
;
494 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
495 switch (internalFormat
) {
496 case GL_ETC1_RGB8_OES
:
503 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
504 switch (internalFormat
) {
505 case GL_COMPRESSED_RGB8_ETC2
:
506 case GL_COMPRESSED_SRGB8_ETC2
:
508 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
509 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
510 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
511 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
513 case GL_COMPRESSED_R11_EAC
:
514 case GL_COMPRESSED_SIGNED_R11_EAC
:
516 case GL_COMPRESSED_RG11_EAC
:
517 case GL_COMPRESSED_SIGNED_RG11_EAC
:
524 if (_mesa_is_desktop_gl(ctx
) &&
525 ctx
->Extensions
.ARB_texture_compression_bptc
) {
526 switch (internalFormat
) {
527 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
528 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
530 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
531 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
538 if (ctx
->API
== API_OPENGLES
) {
539 switch (internalFormat
) {
540 case GL_PALETTE4_RGB8_OES
:
541 case GL_PALETTE4_R5_G6_B5_OES
:
542 case GL_PALETTE8_RGB8_OES
:
543 case GL_PALETTE8_R5_G6_B5_OES
:
545 case GL_PALETTE4_RGBA8_OES
:
546 case GL_PALETTE8_RGB5_A1_OES
:
547 case GL_PALETTE4_RGBA4_OES
:
548 case GL_PALETTE4_RGB5_A1_OES
:
549 case GL_PALETTE8_RGBA8_OES
:
550 case GL_PALETTE8_RGBA4_OES
:
557 return -1; /* error */
562 * For cube map faces, return a face index in [0,5].
563 * For other targets return 0;
566 _mesa_tex_target_to_face(GLenum target
)
568 if (_mesa_is_cube_face(target
))
569 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
577 * Install gl_texture_image in a gl_texture_object according to the target
578 * and level parameters.
580 * \param tObj texture object.
581 * \param target texture target.
582 * \param level image level.
583 * \param texImage texture image.
586 set_tex_image(struct gl_texture_object
*tObj
,
587 GLenum target
, GLint level
,
588 struct gl_texture_image
*texImage
)
590 const GLuint face
= _mesa_tex_target_to_face(target
);
594 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
597 tObj
->Image
[face
][level
] = texImage
;
599 /* Set the 'back' pointer */
600 texImage
->TexObject
= tObj
;
601 texImage
->Level
= level
;
602 texImage
->Face
= face
;
607 * Allocate a texture image structure.
609 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
612 * \return a pointer to gl_texture_image struct with all fields initialized to
615 struct gl_texture_image
*
616 _mesa_new_texture_image( struct gl_context
*ctx
)
619 return CALLOC_STRUCT(gl_texture_image
);
624 * Free a gl_texture_image and associated data.
625 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
627 * \param texImage texture image.
629 * Free the texture image structure and the associated image data.
632 _mesa_delete_texture_image(struct gl_context
*ctx
,
633 struct gl_texture_image
*texImage
)
635 /* Free texImage->Data and/or any other driver-specific texture
638 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
639 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
645 * Test if a target is a proxy target.
647 * \param target texture target.
649 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
652 _mesa_is_proxy_texture(GLenum target
)
655 static const GLenum targets
[] = {
659 GL_PROXY_TEXTURE_CUBE_MAP
,
660 GL_PROXY_TEXTURE_RECTANGLE
,
661 GL_PROXY_TEXTURE_1D_ARRAY
,
662 GL_PROXY_TEXTURE_2D_ARRAY
,
663 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
664 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
665 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
668 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
669 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
671 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== Elements(targets
) + 2);
673 for (i
= 0; i
< Elements(targets
); ++i
)
674 if (target
== targets
[i
])
681 * Return the proxy target which corresponds to the given texture target
684 proxy_target(GLenum target
)
688 case GL_PROXY_TEXTURE_1D
:
689 return GL_PROXY_TEXTURE_1D
;
691 case GL_PROXY_TEXTURE_2D
:
692 return GL_PROXY_TEXTURE_2D
;
694 case GL_PROXY_TEXTURE_3D
:
695 return GL_PROXY_TEXTURE_3D
;
696 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
697 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
698 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
699 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
700 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
701 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
702 case GL_TEXTURE_CUBE_MAP_ARB
:
703 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
704 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
705 case GL_TEXTURE_RECTANGLE_NV
:
706 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
707 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
708 case GL_TEXTURE_1D_ARRAY_EXT
:
709 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
710 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
711 case GL_TEXTURE_2D_ARRAY_EXT
:
712 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
713 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
714 case GL_TEXTURE_CUBE_MAP_ARRAY
:
715 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
716 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
717 case GL_TEXTURE_2D_MULTISAMPLE
:
718 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
719 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
720 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
721 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
722 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
724 _mesa_problem(NULL
, "unexpected target in proxy_target()");
731 * Return a pointer to the current texture object for the given target
732 * on the current texture unit.
733 * Note: all <target> error checking should have been done by this point.
735 struct gl_texture_object
*
736 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
738 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
739 const GLboolean arrayTex
= ctx
->Extensions
.EXT_texture_array
;
743 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
744 case GL_PROXY_TEXTURE_1D
:
745 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
747 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
748 case GL_PROXY_TEXTURE_2D
:
749 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
751 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
752 case GL_PROXY_TEXTURE_3D
:
753 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
754 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
755 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
756 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
757 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
758 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
759 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
760 case GL_TEXTURE_CUBE_MAP_ARB
:
761 return ctx
->Extensions
.ARB_texture_cube_map
762 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
763 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
764 return ctx
->Extensions
.ARB_texture_cube_map
765 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
766 case GL_TEXTURE_CUBE_MAP_ARRAY
:
767 return ctx
->Extensions
.ARB_texture_cube_map_array
768 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
769 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
770 return ctx
->Extensions
.ARB_texture_cube_map_array
771 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
772 case GL_TEXTURE_RECTANGLE_NV
:
773 return ctx
->Extensions
.NV_texture_rectangle
774 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
775 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
776 return ctx
->Extensions
.NV_texture_rectangle
777 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
778 case GL_TEXTURE_1D_ARRAY_EXT
:
779 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
780 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
781 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
782 case GL_TEXTURE_2D_ARRAY_EXT
:
783 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
784 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
785 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
786 case GL_TEXTURE_BUFFER
:
787 return ctx
->API
== API_OPENGL_CORE
&&
788 ctx
->Extensions
.ARB_texture_buffer_object
?
789 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
790 case GL_TEXTURE_EXTERNAL_OES
:
791 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
792 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
793 case GL_TEXTURE_2D_MULTISAMPLE
:
794 return ctx
->Extensions
.ARB_texture_multisample
795 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
796 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
797 return ctx
->Extensions
.ARB_texture_multisample
798 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
799 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
800 return ctx
->Extensions
.ARB_texture_multisample
801 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
802 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
803 return ctx
->Extensions
.ARB_texture_multisample
804 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
806 _mesa_problem(NULL
, "bad target in _mesa_get_current_tex_object()");
814 * Get a texture image pointer from a texture object, given a texture
815 * target and mipmap level. The target and level parameters should
816 * have already been error-checked.
818 * \param ctx GL context.
819 * \param texObj texture unit.
820 * \param target texture target.
821 * \param level image level.
823 * \return pointer to the texture image structure, or NULL on failure.
825 struct gl_texture_image
*
826 _mesa_select_tex_image(struct gl_context
*ctx
,
827 const struct gl_texture_object
*texObj
,
828 GLenum target
, GLint level
)
830 const GLuint face
= _mesa_tex_target_to_face(target
);
834 ASSERT(level
< MAX_TEXTURE_LEVELS
);
836 return texObj
->Image
[face
][level
];
841 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
842 * it and install it. Only return NULL if passed a bad parameter or run
845 struct gl_texture_image
*
846 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
847 GLenum target
, GLint level
)
849 struct gl_texture_image
*texImage
;
854 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
856 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
858 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
862 set_tex_image(texObj
, target
, level
, texImage
);
870 * Return pointer to the specified proxy texture image.
871 * Note that proxy textures are per-context, not per-texture unit.
872 * \return pointer to texture image or NULL if invalid target, invalid
873 * level, or out of memory.
875 static struct gl_texture_image
*
876 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
878 struct gl_texture_image
*texImage
;
885 case GL_PROXY_TEXTURE_1D
:
886 if (level
>= ctx
->Const
.MaxTextureLevels
)
888 texIndex
= TEXTURE_1D_INDEX
;
890 case GL_PROXY_TEXTURE_2D
:
891 if (level
>= ctx
->Const
.MaxTextureLevels
)
893 texIndex
= TEXTURE_2D_INDEX
;
895 case GL_PROXY_TEXTURE_3D
:
896 if (level
>= ctx
->Const
.Max3DTextureLevels
)
898 texIndex
= TEXTURE_3D_INDEX
;
900 case GL_PROXY_TEXTURE_CUBE_MAP
:
901 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
903 texIndex
= TEXTURE_CUBE_INDEX
;
905 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
908 texIndex
= TEXTURE_RECT_INDEX
;
910 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
911 if (level
>= ctx
->Const
.MaxTextureLevels
)
913 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
915 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
916 if (level
>= ctx
->Const
.MaxTextureLevels
)
918 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
920 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
921 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
923 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
925 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
928 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
930 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
933 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
939 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
941 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
943 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
946 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
947 /* Set the 'back' pointer */
948 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
955 * Get the maximum number of allowed mipmap levels.
957 * \param ctx GL context.
958 * \param target texture target.
960 * \return the maximum number of allowed mipmap levels for the given
961 * texture target, or zero if passed a bad target.
966 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
970 case GL_PROXY_TEXTURE_1D
:
972 case GL_PROXY_TEXTURE_2D
:
973 return ctx
->Const
.MaxTextureLevels
;
975 case GL_PROXY_TEXTURE_3D
:
976 return ctx
->Const
.Max3DTextureLevels
;
977 case GL_TEXTURE_CUBE_MAP
:
978 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
979 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
980 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
981 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
982 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
983 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
984 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
985 return ctx
->Extensions
.ARB_texture_cube_map
986 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
987 case GL_TEXTURE_RECTANGLE_NV
:
988 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
989 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
990 case GL_TEXTURE_1D_ARRAY_EXT
:
991 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
992 case GL_TEXTURE_2D_ARRAY_EXT
:
993 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
994 return ctx
->Extensions
.EXT_texture_array
995 ? ctx
->Const
.MaxTextureLevels
: 0;
996 case GL_TEXTURE_CUBE_MAP_ARRAY
:
997 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
998 return ctx
->Extensions
.ARB_texture_cube_map_array
999 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1000 case GL_TEXTURE_BUFFER
:
1001 return ctx
->API
== API_OPENGL_CORE
&&
1002 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1003 case GL_TEXTURE_2D_MULTISAMPLE
:
1004 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1005 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1006 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1007 return _mesa_is_desktop_gl(ctx
)
1008 && ctx
->Extensions
.ARB_texture_multisample
1010 case GL_TEXTURE_EXTERNAL_OES
:
1013 return 0; /* bad target */
1019 * Return number of dimensions per mipmap level for the given texture target.
1022 _mesa_get_texture_dimensions(GLenum target
)
1026 case GL_PROXY_TEXTURE_1D
:
1029 case GL_TEXTURE_RECTANGLE
:
1030 case GL_TEXTURE_CUBE_MAP
:
1031 case GL_PROXY_TEXTURE_2D
:
1032 case GL_PROXY_TEXTURE_RECTANGLE
:
1033 case GL_PROXY_TEXTURE_CUBE_MAP
:
1034 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1035 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1036 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1037 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1038 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1039 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1040 case GL_TEXTURE_1D_ARRAY
:
1041 case GL_PROXY_TEXTURE_1D_ARRAY
:
1042 case GL_TEXTURE_EXTERNAL_OES
:
1043 case GL_TEXTURE_2D_MULTISAMPLE
:
1044 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1047 case GL_PROXY_TEXTURE_3D
:
1048 case GL_TEXTURE_2D_ARRAY
:
1049 case GL_PROXY_TEXTURE_2D_ARRAY
:
1050 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1051 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1052 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1053 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1055 case GL_TEXTURE_BUFFER
:
1058 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1066 * Check if a texture target can have more than one layer.
1069 _mesa_tex_target_is_layered(GLenum target
)
1073 case GL_PROXY_TEXTURE_1D
:
1075 case GL_PROXY_TEXTURE_2D
:
1076 case GL_TEXTURE_RECTANGLE
:
1077 case GL_PROXY_TEXTURE_RECTANGLE
:
1078 case GL_TEXTURE_2D_MULTISAMPLE
:
1079 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1080 case GL_TEXTURE_BUFFER
:
1081 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1082 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1083 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1084 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1085 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1086 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1087 case GL_TEXTURE_EXTERNAL_OES
:
1091 case GL_PROXY_TEXTURE_3D
:
1092 case GL_TEXTURE_CUBE_MAP
:
1093 case GL_PROXY_TEXTURE_CUBE_MAP
:
1094 case GL_TEXTURE_1D_ARRAY
:
1095 case GL_PROXY_TEXTURE_1D_ARRAY
:
1096 case GL_TEXTURE_2D_ARRAY
:
1097 case GL_PROXY_TEXTURE_2D_ARRAY
:
1098 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1099 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1100 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1101 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1105 assert(!"Invalid texture target.");
1112 * Return the number of layers present in the given level of an array,
1113 * cubemap or 3D texture. If the texture is not layered return zero.
1116 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1118 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1120 switch (texObj
->Target
) {
1123 case GL_TEXTURE_RECTANGLE
:
1124 case GL_TEXTURE_2D_MULTISAMPLE
:
1125 case GL_TEXTURE_BUFFER
:
1126 case GL_TEXTURE_EXTERNAL_OES
:
1129 case GL_TEXTURE_CUBE_MAP
:
1132 case GL_TEXTURE_1D_ARRAY
: {
1133 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1134 return img
? img
->Height
: 0;
1138 case GL_TEXTURE_2D_ARRAY
:
1139 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1140 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1141 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1142 return img
? img
->Depth
: 0;
1146 assert(!"Invalid texture target.");
1153 * Return the maximum number of mipmap levels for the given target
1154 * and the dimensions.
1155 * The dimensions are expected not to include the border.
1158 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1165 case GL_TEXTURE_1D_ARRAY
:
1166 case GL_PROXY_TEXTURE_1D
:
1167 case GL_PROXY_TEXTURE_1D_ARRAY
:
1170 case GL_TEXTURE_CUBE_MAP
:
1171 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1172 case GL_PROXY_TEXTURE_CUBE_MAP
:
1173 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1177 case GL_TEXTURE_2D_ARRAY
:
1178 case GL_PROXY_TEXTURE_2D
:
1179 case GL_PROXY_TEXTURE_2D_ARRAY
:
1180 size
= MAX2(width
, height
);
1183 case GL_PROXY_TEXTURE_3D
:
1184 size
= MAX3(width
, height
, depth
);
1186 case GL_TEXTURE_RECTANGLE
:
1187 case GL_TEXTURE_EXTERNAL_OES
:
1188 case GL_TEXTURE_2D_MULTISAMPLE
:
1189 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1190 case GL_PROXY_TEXTURE_RECTANGLE
:
1191 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1192 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1199 return _mesa_logbase2(size
) + 1;
1203 #if 000 /* not used anymore */
1205 * glTexImage[123]D can accept a NULL image pointer. In this case we
1206 * create a texture image with unspecified image contents per the OpenGL
1210 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1212 const GLint components
= _mesa_components_in_format(format
);
1213 const GLint numPixels
= width
* height
* depth
;
1214 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1218 * Let's see if anyone finds this. If glTexImage2D() is called with
1219 * a NULL image pointer then load the texture image with something
1220 * interesting instead of leaving it indeterminate.
1223 static const char message
[8][32] = {
1224 " X X XXXXX XXX X ",
1225 " XX XX X X X X X ",
1227 " X X XXXX XXX XXXXX ",
1230 " X X XXXXX XXX X X ",
1234 GLubyte
*imgPtr
= data
;
1236 for (h
= 0; h
< depth
; h
++) {
1237 for (i
= 0; i
< height
; i
++) {
1238 GLint srcRow
= 7 - (i
% 8);
1239 for (j
= 0; j
< width
; j
++) {
1240 GLint srcCol
= j
% 32;
1241 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1242 for (k
= 0; k
< components
; k
++) {
1258 * Set the size and format-related fields of a gl_texture_image struct
1259 * to zero. This is used when a proxy texture test fails.
1262 clear_teximage_fields(struct gl_texture_image
*img
)
1265 img
->_BaseFormat
= 0;
1266 img
->InternalFormat
= 0;
1275 img
->HeightLog2
= 0;
1277 img
->TexFormat
= MESA_FORMAT_NONE
;
1278 img
->NumSamples
= 0;
1279 img
->FixedSampleLocations
= GL_TRUE
;
1284 * Initialize basic fields of the gl_texture_image struct.
1286 * \param ctx GL context.
1287 * \param img texture image structure to be initialized.
1288 * \param width image width.
1289 * \param height image height.
1290 * \param depth image depth.
1291 * \param border image border.
1292 * \param internalFormat internal format.
1293 * \param format the actual hardware format (one of MESA_FORMAT_*)
1294 * \param numSamples number of samples per texel, or zero for non-MS.
1295 * \param fixedSampleLocations are sample locations fixed?
1297 * Fills in the fields of \p img with the given information.
1298 * Note: width, height and depth include the border.
1301 init_teximage_fields_ms(struct gl_context
*ctx
,
1302 struct gl_texture_image
*img
,
1303 GLsizei width
, GLsizei height
, GLsizei depth
,
1304 GLint border
, GLenum internalFormat
,
1306 GLuint numSamples
, GLboolean fixedSampleLocations
)
1311 ASSERT(height
>= 0);
1314 target
= img
->TexObject
->Target
;
1315 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1316 ASSERT(img
->_BaseFormat
> 0);
1317 img
->InternalFormat
= internalFormat
;
1318 img
->Border
= border
;
1320 img
->Height
= height
;
1323 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1324 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1326 img
->NumSamples
= 0;
1327 img
->FixedSampleLocations
= GL_TRUE
;
1331 case GL_TEXTURE_BUFFER
:
1332 case GL_PROXY_TEXTURE_1D
:
1337 img
->HeightLog2
= 0;
1344 case GL_TEXTURE_1D_ARRAY
:
1345 case GL_PROXY_TEXTURE_1D_ARRAY
:
1346 img
->Height2
= height
; /* no border */
1347 img
->HeightLog2
= 0; /* not used */
1355 case GL_TEXTURE_RECTANGLE
:
1356 case GL_TEXTURE_CUBE_MAP
:
1357 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1358 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1359 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1360 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1361 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1362 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1363 case GL_TEXTURE_EXTERNAL_OES
:
1364 case GL_PROXY_TEXTURE_2D
:
1365 case GL_PROXY_TEXTURE_RECTANGLE
:
1366 case GL_PROXY_TEXTURE_CUBE_MAP
:
1367 case GL_TEXTURE_2D_MULTISAMPLE
:
1368 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1369 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1370 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1377 case GL_TEXTURE_2D_ARRAY
:
1378 case GL_PROXY_TEXTURE_2D_ARRAY
:
1379 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1380 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1381 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1382 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1383 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1384 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1385 img
->Depth2
= depth
; /* no border */
1386 img
->DepthLog2
= 0; /* not used */
1389 case GL_PROXY_TEXTURE_3D
:
1390 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1391 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1392 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1393 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1396 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1401 _mesa_get_tex_max_num_levels(target
,
1402 img
->Width2
, img
->Height2
, img
->Depth2
);
1403 img
->TexFormat
= format
;
1404 img
->NumSamples
= numSamples
;
1405 img
->FixedSampleLocations
= fixedSampleLocations
;
1410 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1411 struct gl_texture_image
*img
,
1412 GLsizei width
, GLsizei height
, GLsizei depth
,
1413 GLint border
, GLenum internalFormat
,
1416 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1417 internalFormat
, format
, 0, GL_TRUE
);
1422 * Free and clear fields of the gl_texture_image struct.
1424 * \param ctx GL context.
1425 * \param texImage texture image structure to be cleared.
1427 * After the call, \p texImage will have no data associated with it. Its
1428 * fields are cleared so that its parent object will test incomplete.
1431 _mesa_clear_texture_image(struct gl_context
*ctx
,
1432 struct gl_texture_image
*texImage
)
1434 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1435 clear_teximage_fields(texImage
);
1440 * Check the width, height, depth and border of a texture image are legal.
1441 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1443 * The target and level parameters will have already been validated.
1444 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1447 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1448 GLint level
, GLint width
, GLint height
,
1449 GLint depth
, GLint border
)
1455 case GL_PROXY_TEXTURE_1D
:
1456 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1457 maxSize
>>= level
; /* level size */
1458 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1460 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1461 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1467 case GL_PROXY_TEXTURE_2D
:
1468 case GL_TEXTURE_2D_MULTISAMPLE
:
1469 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1470 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1472 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1474 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1476 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1477 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1479 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1485 case GL_PROXY_TEXTURE_3D
:
1486 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1488 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1490 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1492 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1494 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1495 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1497 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1499 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1504 case GL_TEXTURE_RECTANGLE_NV
:
1505 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1508 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1509 if (width
< 0 || width
> maxSize
)
1511 if (height
< 0 || height
> maxSize
)
1515 case GL_TEXTURE_CUBE_MAP
:
1516 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1517 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1518 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1519 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1520 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1521 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1522 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1523 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1525 if (width
!= height
)
1527 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1529 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1531 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1532 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1534 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1539 case GL_TEXTURE_1D_ARRAY_EXT
:
1540 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1541 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1543 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1545 if (height
< 0 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1547 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1548 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1553 case GL_TEXTURE_2D_ARRAY_EXT
:
1554 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1555 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1556 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1557 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1559 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1561 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1563 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1565 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1566 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1568 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1573 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1574 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1575 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1576 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1578 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1580 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1582 if (width
!= height
)
1584 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1586 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1587 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1589 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1594 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1601 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1602 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1603 * \param destImage the destination texture image.
1604 * \return GL_TRUE if error found, GL_FALSE otherwise.
1607 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1608 const char *function
, GLuint dims
,
1609 const struct gl_texture_image
*destImage
,
1610 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1611 GLsizei subWidth
, GLsizei subHeight
,
1614 const GLenum target
= destImage
->TexObject
->Target
;
1619 _mesa_error(ctx
, GL_INVALID_VALUE
,
1620 "%s%dD(width=%d)", function
, dims
, subWidth
);
1624 if (dims
> 1 && subHeight
< 0) {
1625 _mesa_error(ctx
, GL_INVALID_VALUE
,
1626 "%s%dD(height=%d)", function
, dims
, subHeight
);
1630 if (dims
> 2 && subDepth
< 0) {
1631 _mesa_error(ctx
, GL_INVALID_VALUE
,
1632 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1636 /* check xoffset and width */
1637 if (xoffset
< - (GLint
) destImage
->Border
) {
1638 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1643 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1644 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1649 /* check yoffset and height */
1651 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1652 if (yoffset
< -yBorder
) {
1653 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1657 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1658 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1664 /* check zoffset and depth */
1666 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1667 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1668 0 : destImage
->Border
;
1670 if (zoffset
< -zBorder
) {
1671 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1674 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1675 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1681 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1682 * compressed texture images can be updated. But, that restriction may be
1683 * relaxed for particular compressed formats. At this time, all the
1684 * compressed formats supported by Mesa allow sub-textures to be updated
1685 * along compressed block boundaries.
1687 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1689 if (bw
!= 1 || bh
!= 1) {
1690 /* offset must be multiple of block size */
1691 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1692 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1693 "%s%dD(xoffset = %d, yoffset = %d)",
1694 function
, dims
, xoffset
, yoffset
);
1698 /* The size must be a multiple of bw x bh, or we must be using a
1699 * offset+size that exactly hits the edge of the image. This
1700 * is important for small mipmap levels (1x1, 2x1, etc) and for
1703 if ((subWidth
% bw
!= 0) &&
1704 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1705 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1706 "%s%dD(width = %d)", function
, dims
, subWidth
);
1710 if ((subHeight
% bh
!= 0) &&
1711 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1712 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1713 "%s%dD(height = %d)", function
, dims
, subHeight
);
1725 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1726 * specific texture image size checks.
1728 * A hardware driver might override this function if, for example, the
1729 * max 3D texture size is 512x512x64 (i.e. not a cube).
1731 * Note that width, height, depth == 0 is not an error. However, a
1732 * texture with zero width/height/depth will be considered "incomplete"
1733 * and texturing will effectively be disabled.
1735 * \param target any texture target/type
1736 * \param level as passed to glTexImage
1737 * \param format the MESA_FORMAT_x for the tex image
1738 * \param width as passed to glTexImage
1739 * \param height as passed to glTexImage
1740 * \param depth as passed to glTexImage
1741 * \param border as passed to glTexImage
1742 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1745 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1747 GLint width
, GLint height
, GLint depth
, GLint border
)
1749 /* We just check if the image size is less than MaxTextureMbytes.
1750 * Some drivers may do more specific checks.
1752 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1753 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1754 mbytes
*= _mesa_num_tex_faces(target
);
1755 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1760 * Return true if the format is only valid for glCompressedTexImage.
1763 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1766 case GL_ETC1_RGB8_OES
:
1767 case GL_PALETTE4_RGB8_OES
:
1768 case GL_PALETTE4_RGBA8_OES
:
1769 case GL_PALETTE4_R5_G6_B5_OES
:
1770 case GL_PALETTE4_RGBA4_OES
:
1771 case GL_PALETTE4_RGB5_A1_OES
:
1772 case GL_PALETTE8_RGB8_OES
:
1773 case GL_PALETTE8_RGBA8_OES
:
1774 case GL_PALETTE8_R5_G6_B5_OES
:
1775 case GL_PALETTE8_RGBA4_OES
:
1776 case GL_PALETTE8_RGB5_A1_OES
:
1785 * Helper function to determine whether a target and specific compression
1786 * format are supported.
1789 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1792 (void) intFormat
; /* not used yet */
1796 case GL_PROXY_TEXTURE_2D
:
1797 return GL_TRUE
; /* true for any compressed format so far */
1798 case GL_PROXY_TEXTURE_CUBE_MAP
:
1799 case GL_TEXTURE_CUBE_MAP
:
1800 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1801 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1802 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1803 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1804 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1805 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1806 return ctx
->Extensions
.ARB_texture_cube_map
;
1807 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1808 case GL_TEXTURE_2D_ARRAY_EXT
:
1809 return ctx
->Extensions
.EXT_texture_array
;
1810 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1811 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1812 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1820 * Check if the given texture target value is legal for a
1821 * glTexImage1/2/3D call.
1824 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1830 case GL_PROXY_TEXTURE_1D
:
1831 return _mesa_is_desktop_gl(ctx
);
1839 case GL_PROXY_TEXTURE_2D
:
1840 return _mesa_is_desktop_gl(ctx
);
1841 case GL_PROXY_TEXTURE_CUBE_MAP
:
1842 return _mesa_is_desktop_gl(ctx
)
1843 && ctx
->Extensions
.ARB_texture_cube_map
;
1844 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1845 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1846 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1847 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1848 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1850 return ctx
->Extensions
.ARB_texture_cube_map
;
1851 case GL_TEXTURE_RECTANGLE_NV
:
1852 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1853 return _mesa_is_desktop_gl(ctx
)
1854 && ctx
->Extensions
.NV_texture_rectangle
;
1855 case GL_TEXTURE_1D_ARRAY_EXT
:
1856 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1857 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1865 case GL_PROXY_TEXTURE_3D
:
1866 return _mesa_is_desktop_gl(ctx
);
1867 case GL_TEXTURE_2D_ARRAY_EXT
:
1868 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1869 || _mesa_is_gles3(ctx
);
1870 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1871 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1872 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1873 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1874 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1879 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1886 * Check if the given texture target value is legal for a
1887 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1888 * The difference compared to legal_teximage_target() above is that
1889 * proxy targets are not supported.
1892 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1896 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1901 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1902 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1903 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1904 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1905 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1906 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1907 return ctx
->Extensions
.ARB_texture_cube_map
;
1908 case GL_TEXTURE_RECTANGLE_NV
:
1909 return _mesa_is_desktop_gl(ctx
)
1910 && ctx
->Extensions
.NV_texture_rectangle
;
1911 case GL_TEXTURE_1D_ARRAY_EXT
:
1912 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1920 case GL_TEXTURE_2D_ARRAY_EXT
:
1921 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1922 || _mesa_is_gles3(ctx
);
1923 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1924 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1925 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1930 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1938 * Helper function to determine if a texture object is mutable (in terms
1939 * of GL_ARB_texture_storage).
1942 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1944 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1945 return !texObj
->Immutable
;
1950 * Return expected size of a compressed texture.
1953 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1956 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1957 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1961 * Verify that a texture format is valid with a particular target
1963 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1964 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1967 * \param ctx GL context
1968 * \param target Texture target
1969 * \param internalFormat Internal format of the texture image
1970 * \param dimensions Dimensionality at the caller. This is \b not used
1971 * in the validation. It is only used when logging
1973 * \param caller Base name of the calling function (e.g.,
1974 * "glTexImage" or "glTexStorage").
1976 * \returns true if the combination is legal, false otherwise.
1979 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1980 GLenum target
, GLenum internalFormat
,
1981 unsigned dimensions
,
1984 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1985 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
1986 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1987 * Profile spec says:
1989 * "Textures with a base internal format of DEPTH_COMPONENT or
1990 * DEPTH_STENCIL are supported by texture image specification
1991 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1992 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1993 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1994 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1995 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1996 * formats in conjunction with any other target will result in an
1997 * INVALID_OPERATION error."
1999 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
2000 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
2002 if (target
!= GL_TEXTURE_1D
&&
2003 target
!= GL_PROXY_TEXTURE_1D
&&
2004 target
!= GL_TEXTURE_2D
&&
2005 target
!= GL_PROXY_TEXTURE_2D
&&
2006 target
!= GL_TEXTURE_1D_ARRAY
&&
2007 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2008 target
!= GL_TEXTURE_2D_ARRAY
&&
2009 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2010 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2011 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2012 !((_mesa_is_cube_face(target
) ||
2013 target
== GL_TEXTURE_CUBE_MAP
||
2014 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2015 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2016 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2017 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2018 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2019 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2020 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2021 "%s%dD(bad target for depth texture)",
2022 caller
, dimensions
);
2031 texture_formats_agree(GLenum internalFormat
,
2034 GLboolean colorFormat
;
2035 GLboolean is_format_depth_or_depthstencil
;
2036 GLboolean is_internalFormat_depth_or_depthstencil
;
2038 /* Even though there are no color-index textures, we still have to support
2039 * uploading color-index data and remapping it to RGB via the
2040 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2042 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2044 is_internalFormat_depth_or_depthstencil
=
2045 _mesa_is_depth_format(internalFormat
) ||
2046 _mesa_is_depthstencil_format(internalFormat
);
2048 is_format_depth_or_depthstencil
=
2049 _mesa_is_depth_format(format
) ||
2050 _mesa_is_depthstencil_format(format
);
2052 colorFormat
= _mesa_is_color_format(format
);
2054 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2057 if (is_internalFormat_depth_or_depthstencil
!=
2058 is_format_depth_or_depthstencil
)
2061 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2068 * Test the glTexImage[123]D() parameters for errors.
2070 * \param ctx GL context.
2071 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2072 * \param target texture target given by the user (already validated).
2073 * \param level image level given by the user.
2074 * \param internalFormat internal format given by the user.
2075 * \param format pixel data format given by the user.
2076 * \param type pixel data type given by the user.
2077 * \param width image width given by the user.
2078 * \param height image height given by the user.
2079 * \param depth image depth given by the user.
2080 * \param border image border given by the user.
2082 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2084 * Verifies each of the parameters against the constants specified in
2085 * __struct gl_contextRec::Const and the supported extensions, and according
2086 * to the OpenGL specification.
2087 * Note that we don't fully error-check the width, height, depth values
2088 * here. That's done in _mesa_legal_texture_dimensions() which is used
2089 * by several other GL entrypoints. Plus, texture dims have a special
2090 * interaction with proxy textures.
2093 texture_error_check( struct gl_context
*ctx
,
2094 GLuint dimensions
, GLenum target
,
2095 GLint level
, GLint internalFormat
,
2096 GLenum format
, GLenum type
,
2097 GLint width
, GLint height
,
2098 GLint depth
, GLint border
)
2102 /* Note: for proxy textures, some error conditions immediately generate
2103 * a GL error in the usual way. But others do not generate a GL error.
2104 * Instead, they cause the width, height, depth, format fields of the
2105 * texture image to be zeroed-out. The GL spec seems to indicate that the
2106 * zero-out behaviour is only used in cases related to memory allocation.
2110 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2111 _mesa_error(ctx
, GL_INVALID_VALUE
,
2112 "glTexImage%dD(level=%d)", dimensions
, level
);
2117 if (border
< 0 || border
> 1 ||
2118 ((ctx
->API
!= API_OPENGL_COMPAT
||
2119 target
== GL_TEXTURE_RECTANGLE_NV
||
2120 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2121 _mesa_error(ctx
, GL_INVALID_VALUE
,
2122 "glTexImage%dD(border=%d)", dimensions
, border
);
2126 if (width
< 0 || height
< 0 || depth
< 0) {
2127 _mesa_error(ctx
, GL_INVALID_VALUE
,
2128 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2132 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2133 * combinations of format, internalFormat, and type that can be used.
2134 * Formats and types that require additional extensions (e.g., GL_FLOAT
2135 * requires GL_OES_texture_float) are filtered elsewhere.
2138 if (_mesa_is_gles(ctx
)) {
2139 if (_mesa_is_gles3(ctx
)) {
2140 err
= _mesa_es3_error_check_format_and_type(format
, type
,
2143 if (format
!= internalFormat
) {
2144 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2145 "glTexImage%dD(format = %s, internalFormat = %s)",
2147 _mesa_lookup_enum_by_nr(format
),
2148 _mesa_lookup_enum_by_nr(internalFormat
));
2152 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2154 if (err
!= GL_NO_ERROR
) {
2155 _mesa_error(ctx
, err
,
2156 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2158 _mesa_lookup_enum_by_nr(format
),
2159 _mesa_lookup_enum_by_nr(type
),
2160 _mesa_lookup_enum_by_nr(internalFormat
));
2165 /* Check internalFormat */
2166 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2167 _mesa_error(ctx
, GL_INVALID_VALUE
,
2168 "glTexImage%dD(internalFormat=%s)",
2169 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2173 /* Check incoming image format and type */
2174 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2175 if (err
!= GL_NO_ERROR
) {
2176 _mesa_error(ctx
, err
,
2177 "glTexImage%dD(incompatible format = %s, type = %s)",
2178 dimensions
, _mesa_lookup_enum_by_nr(format
),
2179 _mesa_lookup_enum_by_nr(type
));
2183 /* make sure internal format and format basically agree */
2184 if (!texture_formats_agree(internalFormat
, format
)) {
2185 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2186 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2187 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2188 _mesa_lookup_enum_by_nr(format
));
2192 /* additional checks for ycbcr textures */
2193 if (internalFormat
== GL_YCBCR_MESA
) {
2194 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2195 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2196 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2198 _mesa_snprintf(message
, sizeof(message
),
2199 "glTexImage%dD(format/type YCBCR mismatch)",
2201 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2202 return GL_TRUE
; /* error */
2204 if (target
!= GL_TEXTURE_2D
&&
2205 target
!= GL_PROXY_TEXTURE_2D
&&
2206 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2207 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2208 _mesa_error(ctx
, GL_INVALID_ENUM
,
2209 "glTexImage%dD(bad target for YCbCr texture)",
2215 _mesa_snprintf(message
, sizeof(message
),
2216 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2217 dimensions
, border
);
2218 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2223 /* additional checks for depth textures */
2224 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2225 dimensions
, "glTexImage"))
2228 /* additional checks for compressed textures */
2229 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2230 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2231 _mesa_error(ctx
, GL_INVALID_ENUM
,
2232 "glTexImage%dD(target can't be compressed)", dimensions
);
2235 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2236 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2237 "glTexImage%dD(no compression for format)", dimensions
);
2241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2242 "glTexImage%dD(border!=0)", dimensions
);
2247 /* additional checks for integer textures */
2248 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2249 (_mesa_is_enum_format_integer(format
) !=
2250 _mesa_is_enum_format_integer(internalFormat
))) {
2251 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2252 "glTexImage%dD(integer/non-integer format mismatch)",
2257 if (!mutable_tex_object(ctx
, target
)) {
2258 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2259 "glTexImage%dD(immutable texture)", dimensions
);
2263 /* if we get here, the parameters are OK */
2269 * Error checking for glCompressedTexImage[123]D().
2270 * Note that the width, height and depth values are not fully error checked
2272 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2275 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2276 GLenum target
, GLint level
,
2277 GLenum internalFormat
, GLsizei width
,
2278 GLsizei height
, GLsizei depth
, GLint border
,
2281 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2283 GLenum error
= GL_NO_ERROR
;
2284 char *reason
= ""; /* no error */
2286 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2288 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
2290 * "The ETC2/EAC texture compression algorithm supports only
2291 * two-dimensional images. If internalformat is an ETC2/EAC format,
2292 * CompressedTexImage3D will generate an INVALID_OPERATION error if
2293 * target is not TEXTURE_2D_ARRAY."
2295 error
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
2299 /* This will detect any invalid internalFormat value */
2300 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2301 _mesa_error(ctx
, GL_INVALID_ENUM
,
2302 "glCompressedTexImage%dD(internalFormat=%s)",
2303 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2307 switch (internalFormat
) {
2308 case GL_PALETTE4_RGB8_OES
:
2309 case GL_PALETTE4_RGBA8_OES
:
2310 case GL_PALETTE4_R5_G6_B5_OES
:
2311 case GL_PALETTE4_RGBA4_OES
:
2312 case GL_PALETTE4_RGB5_A1_OES
:
2313 case GL_PALETTE8_RGB8_OES
:
2314 case GL_PALETTE8_RGBA8_OES
:
2315 case GL_PALETTE8_R5_G6_B5_OES
:
2316 case GL_PALETTE8_RGBA4_OES
:
2317 case GL_PALETTE8_RGB5_A1_OES
:
2318 /* check level (note that level should be zero or less!) */
2319 if (level
> 0 || level
< -maxLevels
) {
2321 error
= GL_INVALID_VALUE
;
2325 if (dimensions
!= 2) {
2326 reason
= "compressed paletted textures must be 2D";
2327 error
= GL_INVALID_OPERATION
;
2331 /* Figure out the expected texture size (in bytes). This will be
2332 * checked against the actual size later.
2334 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2337 /* This is for the benefit of the TestProxyTexImage below. It expects
2338 * level to be non-negative. OES_compressed_paletted_texture uses a
2339 * weird mechanism where the level specified to glCompressedTexImage2D
2340 * is -(n-1) number of levels in the texture, and the data specifies the
2341 * complete mipmap stack. This is done to ensure the palette is the
2342 * same for all levels.
2349 if (level
< 0 || level
>= maxLevels
) {
2351 error
= GL_INVALID_VALUE
;
2355 /* Figure out the expected texture size (in bytes). This will be
2356 * checked against the actual size later.
2358 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2362 /* This should really never fail */
2363 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2364 reason
= "internalFormat";
2365 error
= GL_INVALID_ENUM
;
2369 /* No compressed formats support borders at this time */
2371 reason
= "border != 0";
2372 error
= GL_INVALID_VALUE
;
2376 /* Check for invalid pixel storage modes */
2377 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dimensions
,
2379 "glCompressedTexImage")) {
2383 /* check image size in bytes */
2384 if (expectedSize
!= imageSize
) {
2385 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2386 * if <imageSize> is not consistent with the format, dimensions, and
2387 * contents of the specified image.
2389 reason
= "imageSize inconsistant with width/height/format";
2390 error
= GL_INVALID_VALUE
;
2394 if (!mutable_tex_object(ctx
, target
)) {
2395 reason
= "immutable texture";
2396 error
= GL_INVALID_OPERATION
;
2403 /* Note: not all error paths exit through here. */
2404 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2411 * Test glTexSubImage[123]D() parameters for errors.
2413 * \param ctx GL context.
2414 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2415 * \param target texture target given by the user (already validated)
2416 * \param level image level given by the user.
2417 * \param xoffset sub-image x offset given by the user.
2418 * \param yoffset sub-image y offset given by the user.
2419 * \param zoffset sub-image z offset given by the user.
2420 * \param format pixel data format given by the user.
2421 * \param type pixel data type given by the user.
2422 * \param width image width given by the user.
2423 * \param height image height given by the user.
2424 * \param depth image depth given by the user.
2426 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2428 * Verifies each of the parameters against the constants specified in
2429 * __struct gl_contextRec::Const and the supported extensions, and according
2430 * to the OpenGL specification.
2433 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2434 GLenum target
, GLint level
,
2435 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2436 GLint width
, GLint height
, GLint depth
,
2437 GLenum format
, GLenum type
)
2439 struct gl_texture_object
*texObj
;
2440 struct gl_texture_image
*texImage
;
2443 /* check target (proxies not allowed) */
2444 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2445 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2446 dimensions
, _mesa_lookup_enum_by_nr(target
));
2451 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2452 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%uD(level=%d)",
2457 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2458 * combinations of format and type that can be used. Formats and types
2459 * that require additional extensions (e.g., GL_FLOAT requires
2460 * GL_OES_texture_float) are filtered elsewhere.
2462 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2463 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2464 if (err
!= GL_NO_ERROR
) {
2465 _mesa_error(ctx
, err
,
2466 "glTexSubImage%dD(format = %s, type = %s)",
2468 _mesa_lookup_enum_by_nr(format
),
2469 _mesa_lookup_enum_by_nr(type
));
2474 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2475 if (err
!= GL_NO_ERROR
) {
2476 _mesa_error(ctx
, err
,
2477 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2478 dimensions
, _mesa_lookup_enum_by_nr(format
),
2479 _mesa_lookup_enum_by_nr(type
));
2483 /* Get dest texture object / image pointers */
2484 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2486 /* must be out of memory */
2487 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2491 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2493 /* non-existant texture level */
2494 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2495 "glTexSubImage%dD(invalid texture image)", dimensions
);
2499 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2500 texImage
, xoffset
, yoffset
, 0,
2501 width
, height
, 1)) {
2505 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2506 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2507 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2508 "glTexSubImage%dD(no compression for format)", dimensions
);
2513 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2514 /* both source and dest must be integer-valued, or neither */
2515 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2516 _mesa_is_enum_format_integer(format
)) {
2517 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2518 "glTexSubImage%dD(integer/non-integer format mismatch)",
2529 * Test glCopyTexImage[12]D() parameters for errors.
2531 * \param ctx GL context.
2532 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2533 * \param target texture target given by the user.
2534 * \param level image level given by the user.
2535 * \param internalFormat internal format given by the user.
2536 * \param width image width given by the user.
2537 * \param height image height given by the user.
2538 * \param border texture border.
2540 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2542 * Verifies each of the parameters against the constants specified in
2543 * __struct gl_contextRec::Const and the supported extensions, and according
2544 * to the OpenGL specification.
2547 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2548 GLenum target
, GLint level
, GLint internalFormat
,
2549 GLint width
, GLint height
, GLint border
)
2552 GLint rb_base_format
;
2553 struct gl_renderbuffer
*rb
;
2554 GLenum rb_internal_format
;
2557 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2558 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2559 dimensions
, _mesa_lookup_enum_by_nr(target
));
2564 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2565 _mesa_error(ctx
, GL_INVALID_VALUE
,
2566 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2570 /* Check that the source buffer is complete */
2571 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2572 if (ctx
->ReadBuffer
->_Status
== 0) {
2573 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2575 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2576 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2577 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2581 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2582 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2583 "glCopyTexImage%dD(multisample FBO)",
2590 if (border
< 0 || border
> 1 ||
2591 ((ctx
->API
!= API_OPENGL_COMPAT
||
2592 target
== GL_TEXTURE_RECTANGLE_NV
||
2593 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2594 _mesa_error(ctx
, GL_INVALID_VALUE
,
2595 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2599 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2602 "glCopyTexImage%dD(read buffer)", dimensions
);
2606 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2609 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2610 switch (internalFormat
) {
2615 case GL_LUMINANCE_ALPHA
:
2618 _mesa_error(ctx
, GL_INVALID_VALUE
,
2619 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2620 _mesa_lookup_enum_by_nr(internalFormat
));
2625 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2626 if (baseFormat
< 0) {
2627 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2628 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2629 _mesa_lookup_enum_by_nr(internalFormat
));
2633 rb_internal_format
= rb
->InternalFormat
;
2634 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2635 if (_mesa_is_color_format(internalFormat
)) {
2636 if (rb_base_format
< 0) {
2637 _mesa_error(ctx
, GL_INVALID_VALUE
,
2638 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2639 _mesa_lookup_enum_by_nr(internalFormat
));
2644 if (_mesa_is_gles(ctx
)) {
2646 if (_mesa_base_format_component_count(baseFormat
) >
2647 _mesa_base_format_component_count(rb_base_format
)) {
2650 if (baseFormat
== GL_DEPTH_COMPONENT
||
2651 baseFormat
== GL_DEPTH_STENCIL
||
2652 rb_base_format
== GL_DEPTH_COMPONENT
||
2653 rb_base_format
== GL_DEPTH_STENCIL
||
2654 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2655 baseFormat
== GL_ALPHA
) &&
2656 rb_base_format
!= GL_RGBA
) ||
2657 internalFormat
== GL_RGB9_E5
) {
2660 if (internalFormat
== GL_RGB9_E5
) {
2664 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2665 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2666 _mesa_lookup_enum_by_nr(internalFormat
));
2671 if (_mesa_is_gles3(ctx
)) {
2672 bool rb_is_srgb
= false;
2673 bool dst_is_srgb
= false;
2675 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2676 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2680 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2684 if (rb_is_srgb
!= dst_is_srgb
) {
2685 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2686 * OpenGLES 3.0.0 spec says:
2688 * "The error INVALID_OPERATION is also generated if the
2689 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2690 * framebuffer attachment corresponding to the read buffer
2691 * is LINEAR (see section 6.1.13) and internalformat is
2692 * one of the sRGB formats described in section 3.8.16, or
2693 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2694 * SRGB and internalformat is not one of the sRGB formats."
2696 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2697 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2701 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2702 * types for SNORM formats. Also, conversion to SNORM formats is not
2703 * allowed by Table 3.2 on Page 110.
2705 if(_mesa_is_enum_format_snorm(internalFormat
)) {
2706 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2707 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2708 _mesa_lookup_enum_by_nr(internalFormat
));
2713 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2714 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2715 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2719 /* From the EXT_texture_integer spec:
2721 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2722 * if the texture internalformat is an integer format and the read color
2723 * buffer is not an integer format, or if the internalformat is not an
2724 * integer format and the read color buffer is an integer format."
2726 if (_mesa_is_color_format(internalFormat
)) {
2727 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2728 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2729 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2730 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2731 if (is_int
|| is_rbint
) {
2732 if (is_int
!= is_rbint
) {
2733 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2734 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2736 } else if (_mesa_is_gles(ctx
) &&
2737 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2738 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2739 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2740 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2745 /* From page 138 of OpenGL ES 3.0 spec:
2746 * "The error INVALID_OPERATION is generated if floating-point RGBA
2747 * data is required; if signed integer RGBA data is required and the
2748 * format of the current color buffer is not signed integer; if
2749 * unsigned integer RGBA data is required and the format of the
2750 * current color buffer is not unsigned integer; or if fixed-point
2751 * RGBA data is required and the format of the current color buffer
2752 * is not fixed-point.
2754 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2755 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2756 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2759 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2760 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2761 _mesa_error(ctx
, GL_INVALID_ENUM
,
2762 "glCopyTexImage%dD(target)", dimensions
);
2765 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2766 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2767 "glCopyTexImage%dD(no compression for format)", dimensions
);
2771 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2772 "glCopyTexImage%dD(border!=0)", dimensions
);
2777 if (!mutable_tex_object(ctx
, target
)) {
2778 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2779 "glCopyTexImage%dD(immutable texture)", dimensions
);
2783 /* if we get here, the parameters are OK */
2789 * Test glCopyTexSubImage[12]D() parameters for errors.
2790 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2793 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2794 GLenum target
, GLint level
,
2795 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2796 GLint width
, GLint height
)
2798 struct gl_texture_object
*texObj
;
2799 struct gl_texture_image
*texImage
;
2801 /* Check that the source buffer is complete */
2802 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2803 if (ctx
->ReadBuffer
->_Status
== 0) {
2804 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2806 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2807 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2808 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2812 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2813 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2814 "glCopyTexSubImage%dD(multisample FBO)",
2820 /* check target (proxies not allowed) */
2821 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2822 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2823 dimensions
, _mesa_lookup_enum_by_nr(target
));
2828 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2829 _mesa_error(ctx
, GL_INVALID_VALUE
,
2830 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2834 /* Get dest texture object / image pointers */
2835 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2837 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2841 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2843 /* destination image does not exist */
2844 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2845 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2849 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2850 dimensions
, texImage
,
2851 xoffset
, yoffset
, zoffset
,
2852 width
, height
, 1)) {
2856 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2857 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2858 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2859 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2864 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2865 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2869 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2870 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2871 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2872 dimensions
, texImage
->_BaseFormat
);
2876 /* From the EXT_texture_integer spec:
2878 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2879 * if the texture internalformat is an integer format and the read color
2880 * buffer is not an integer format, or if the internalformat is not an
2881 * integer format and the read color buffer is an integer format."
2883 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2884 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2886 if (_mesa_is_format_integer_color(rb
->Format
) !=
2887 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2888 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2889 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2894 /* if we get here, the parameters are OK */
2899 /** Callback info for walking over FBO hash table */
2902 struct gl_context
*ctx
;
2903 struct gl_texture_object
*texObj
;
2909 * Check render to texture callback. Called from _mesa_HashWalk().
2912 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2914 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2915 const struct cb_info
*info
= (struct cb_info
*) userData
;
2916 struct gl_context
*ctx
= info
->ctx
;
2917 const struct gl_texture_object
*texObj
= info
->texObj
;
2918 const GLuint level
= info
->level
, face
= info
->face
;
2920 /* If this is a user-created FBO */
2921 if (_mesa_is_user_fbo(fb
)) {
2923 /* check if any of the FBO's attachments point to 'texObj' */
2924 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2925 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2926 if (att
->Type
== GL_TEXTURE
&&
2927 att
->Texture
== texObj
&&
2928 att
->TextureLevel
== level
&&
2929 att
->CubeMapFace
== face
) {
2930 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2931 ASSERT(att
->Renderbuffer
->TexImage
);
2932 /* Mark fb status as indeterminate to force re-validation */
2941 * When a texture image is specified we have to check if it's bound to
2942 * any framebuffer objects (render to texture) in order to detect changes
2943 * in size or format since that effects FBO completeness.
2944 * Any FBOs rendering into the texture must be re-validated.
2947 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2948 struct gl_texture_object
*texObj
,
2949 GLuint face
, GLuint level
)
2951 /* Only check this texture if it's been marked as RenderToTexture */
2952 if (texObj
->_RenderToTexture
) {
2953 struct cb_info info
;
2955 info
.texObj
= texObj
;
2958 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2964 * If the texture object's GenerateMipmap flag is set and we've
2965 * changed the texture base level image, regenerate the rest of the
2966 * mipmap levels now.
2969 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2970 struct gl_texture_object
*texObj
, GLint level
)
2972 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2973 if (texObj
->GenerateMipmap
&&
2974 level
== texObj
->BaseLevel
&&
2975 level
< texObj
->MaxLevel
) {
2976 ASSERT(ctx
->Driver
.GenerateMipmap
);
2977 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2982 /** Debug helper: override the user-requested internal format */
2984 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2987 if (internalFormat
== GL_RGBA16F_ARB
||
2988 internalFormat
== GL_RGBA32F_ARB
) {
2989 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2992 else if (internalFormat
== GL_RGB16F_ARB
||
2993 internalFormat
== GL_RGB32F_ARB
) {
2994 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2997 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2998 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2999 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3000 return GL_LUMINANCE_ALPHA
;
3002 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3003 internalFormat
== GL_LUMINANCE32F_ARB
) {
3004 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3005 return GL_LUMINANCE
;
3007 else if (internalFormat
== GL_ALPHA16F_ARB
||
3008 internalFormat
== GL_ALPHA32F_ARB
) {
3009 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3013 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3014 internalFormat = GL_RGBA;
3018 return internalFormat
;
3021 return internalFormat
;
3027 * Choose the actual hardware format for a texture image.
3028 * Try to use the same format as the previous image level when possible.
3029 * Otherwise, ask the driver for the best format.
3030 * It's important to try to choose a consistant format for all levels
3031 * for efficient texture memory layout/allocation. In particular, this
3032 * comes up during automatic mipmap generation.
3035 _mesa_choose_texture_format(struct gl_context
*ctx
,
3036 struct gl_texture_object
*texObj
,
3037 GLenum target
, GLint level
,
3038 GLenum internalFormat
, GLenum format
, GLenum type
)
3042 /* see if we've already chosen a format for the previous level */
3044 struct gl_texture_image
*prevImage
=
3045 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
3046 /* See if the prev level is defined and has an internal format which
3047 * matches the new internal format.
3050 prevImage
->Width
> 0 &&
3051 prevImage
->InternalFormat
== internalFormat
) {
3052 /* use the same format */
3053 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3054 return prevImage
->TexFormat
;
3058 /* If the application requested compression to an S3TC format but we don't
3059 * have the DXTn library, force a generic compressed format instead.
3061 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3062 const GLenum before
= internalFormat
;
3064 switch (internalFormat
) {
3065 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3066 if (!ctx
->Mesa_DXTn
)
3067 internalFormat
= GL_COMPRESSED_RGB
;
3069 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3070 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3071 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3072 if (!ctx
->Mesa_DXTn
)
3073 internalFormat
= GL_COMPRESSED_RGBA
;
3079 if (before
!= internalFormat
) {
3081 "DXT compression requested (%s), "
3082 "but libtxc_dxtn library not installed. Using %s "
3084 _mesa_lookup_enum_by_nr(before
),
3085 _mesa_lookup_enum_by_nr(internalFormat
));
3089 /* choose format from scratch */
3090 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3092 ASSERT(f
!= MESA_FORMAT_NONE
);
3098 * Adjust pixel unpack params and image dimensions to strip off the
3099 * one-pixel texture border.
3101 * Gallium and intel don't support texture borders. They've seldem been used
3102 * and seldom been implemented correctly anyway.
3104 * \param unpackNew returns the new pixel unpack parameters
3107 strip_texture_border(GLenum target
,
3108 GLint
*width
, GLint
*height
, GLint
*depth
,
3109 const struct gl_pixelstore_attrib
*unpack
,
3110 struct gl_pixelstore_attrib
*unpackNew
)
3116 *unpackNew
= *unpack
;
3118 if (unpackNew
->RowLength
== 0)
3119 unpackNew
->RowLength
= *width
;
3121 if (unpackNew
->ImageHeight
== 0)
3122 unpackNew
->ImageHeight
= *height
;
3124 assert(*width
>= 3);
3125 unpackNew
->SkipPixels
++; /* skip the border */
3126 *width
= *width
- 2; /* reduce the width by two border pixels */
3128 /* The min height of a texture with a border is 3 */
3129 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3130 unpackNew
->SkipRows
++; /* skip the border */
3131 *height
= *height
- 2; /* reduce the height by two border pixels */
3135 target
!= GL_TEXTURE_2D_ARRAY
&&
3136 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3137 unpackNew
->SkipImages
++; /* skip the border */
3138 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3144 * Common code to implement all the glTexImage1D/2D/3D functions
3145 * as well as glCompressedTexImage1D/2D/3D.
3146 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3147 * \param format the user's image format (only used if !compressed)
3148 * \param type the user's image type (only used if !compressed)
3149 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3152 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3153 GLenum target
, GLint level
, GLint internalFormat
,
3154 GLsizei width
, GLsizei height
, GLsizei depth
,
3155 GLint border
, GLenum format
, GLenum type
,
3156 GLsizei imageSize
, const GLvoid
*pixels
)
3158 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3159 struct gl_pixelstore_attrib unpack_no_border
;
3160 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3161 struct gl_texture_object
*texObj
;
3162 mesa_format texFormat
;
3163 GLboolean dimensionsOK
, sizeOK
;
3165 FLUSH_VERTICES(ctx
, 0);
3167 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3170 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3172 _mesa_lookup_enum_by_nr(target
), level
,
3173 _mesa_lookup_enum_by_nr(internalFormat
),
3174 width
, height
, depth
, border
, pixels
);
3177 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3179 _mesa_lookup_enum_by_nr(target
), level
,
3180 _mesa_lookup_enum_by_nr(internalFormat
),
3181 width
, height
, depth
, border
,
3182 _mesa_lookup_enum_by_nr(format
),
3183 _mesa_lookup_enum_by_nr(type
), pixels
);
3186 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3188 /* target error checking */
3189 if (!legal_teximage_target(ctx
, dims
, target
)) {
3190 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3191 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3195 /* general error checking */
3197 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3199 width
, height
, depth
,
3204 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3205 format
, type
, width
, height
, depth
, border
))
3209 /* Here we convert a cpal compressed image into a regular glTexImage2D
3210 * call by decompressing the texture. If we really want to support cpal
3211 * textures in any driver this would have to be changed.
3213 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3214 switch (internalFormat
) {
3215 case GL_PALETTE4_RGB8_OES
:
3216 case GL_PALETTE4_RGBA8_OES
:
3217 case GL_PALETTE4_R5_G6_B5_OES
:
3218 case GL_PALETTE4_RGBA4_OES
:
3219 case GL_PALETTE4_RGB5_A1_OES
:
3220 case GL_PALETTE8_RGB8_OES
:
3221 case GL_PALETTE8_RGBA8_OES
:
3222 case GL_PALETTE8_R5_G6_B5_OES
:
3223 case GL_PALETTE8_RGBA4_OES
:
3224 case GL_PALETTE8_RGB5_A1_OES
:
3225 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3226 width
, height
, imageSize
, pixels
);
3231 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3235 /* For glCompressedTexImage() the driver has no choice about the
3236 * texture format since we'll never transcode the user's compressed
3237 * image data. The internalFormat was error checked earlier.
3239 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3242 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3243 internalFormat
, format
, type
);
3246 assert(texFormat
!= MESA_FORMAT_NONE
);
3248 /* check that width, height, depth are legal for the mipmap level */
3249 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3250 height
, depth
, border
);
3252 /* check that the texture won't take too much memory, etc */
3253 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3255 width
, height
, depth
, border
);
3257 if (_mesa_is_proxy_texture(target
)) {
3258 /* Proxy texture: just clear or set state depending on error checking */
3259 struct gl_texture_image
*texImage
=
3260 get_proxy_tex_image(ctx
, target
, level
);
3263 return; /* GL_OUT_OF_MEMORY already recorded */
3265 if (dimensionsOK
&& sizeOK
) {
3266 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3267 border
, internalFormat
, texFormat
);
3270 clear_teximage_fields(texImage
);
3274 /* non-proxy target */
3275 const GLuint face
= _mesa_tex_target_to_face(target
);
3276 struct gl_texture_image
*texImage
;
3278 if (!dimensionsOK
) {
3279 _mesa_error(ctx
, GL_INVALID_VALUE
,
3280 "glTexImage%uD(invalid width or height or depth)",
3286 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3287 "glTexImage%uD(image too large)", dims
);
3291 /* Allow a hardware driver to just strip out the border, to provide
3292 * reliable but slightly incorrect hardware rendering instead of
3293 * rarely-tested software fallback rendering.
3295 if (border
&& ctx
->Const
.StripTextureBorder
) {
3296 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3299 unpack
= &unpack_no_border
;
3302 if (ctx
->NewState
& _NEW_PIXEL
)
3303 _mesa_update_state(ctx
);
3305 _mesa_lock_texture(ctx
, texObj
);
3307 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3310 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3313 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3315 _mesa_init_teximage_fields(ctx
, texImage
,
3316 width
, height
, depth
,
3317 border
, internalFormat
, texFormat
);
3319 /* Give the texture to the driver. <pixels> may be null. */
3320 if (width
> 0 && height
> 0 && depth
> 0) {
3322 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3326 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3327 type
, pixels
, unpack
);
3331 check_gen_mipmap(ctx
, target
, texObj
, level
);
3333 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3335 _mesa_dirty_texobj(ctx
, texObj
);
3338 _mesa_unlock_texture(ctx
, texObj
);
3345 * Called from the API. Note that width includes the border.
3348 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3349 GLsizei width
, GLint border
, GLenum format
,
3350 GLenum type
, const GLvoid
*pixels
)
3352 GET_CURRENT_CONTEXT(ctx
);
3353 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3354 border
, format
, type
, 0, pixels
);
3359 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3360 GLsizei width
, GLsizei height
, GLint border
,
3361 GLenum format
, GLenum type
,
3362 const GLvoid
*pixels
)
3364 GET_CURRENT_CONTEXT(ctx
);
3365 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3366 border
, format
, type
, 0, pixels
);
3371 * Called by the API or display list executor.
3372 * Note that width and height include the border.
3375 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3376 GLsizei width
, GLsizei height
, GLsizei depth
,
3377 GLint border
, GLenum format
, GLenum type
,
3378 const GLvoid
*pixels
)
3380 GET_CURRENT_CONTEXT(ctx
);
3381 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3382 width
, height
, depth
,
3383 border
, format
, type
, 0, pixels
);
3388 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3389 GLsizei width
, GLsizei height
, GLsizei depth
,
3390 GLint border
, GLenum format
, GLenum type
,
3391 const GLvoid
*pixels
)
3393 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3394 depth
, border
, format
, type
, pixels
);
3399 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3401 struct gl_texture_object
*texObj
;
3402 struct gl_texture_image
*texImage
;
3404 GET_CURRENT_CONTEXT(ctx
);
3405 FLUSH_VERTICES(ctx
, 0);
3409 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3411 case GL_TEXTURE_EXTERNAL_OES
:
3413 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3416 valid_target
= false;
3420 if (!valid_target
) {
3421 _mesa_error(ctx
, GL_INVALID_ENUM
,
3422 "glEGLImageTargetTexture2D(target=%d)", target
);
3427 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3428 "glEGLImageTargetTexture2D(image=%p)", image
);
3432 if (ctx
->NewState
& _NEW_PIXEL
)
3433 _mesa_update_state(ctx
);
3435 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3436 _mesa_lock_texture(ctx
, texObj
);
3438 if (texObj
->Immutable
) {
3439 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3440 "glEGLImageTargetTexture2D(texture is immutable)");
3441 _mesa_unlock_texture(ctx
, texObj
);
3445 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3447 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3449 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3451 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3452 texObj
, texImage
, image
);
3454 _mesa_dirty_texobj(ctx
, texObj
);
3456 _mesa_unlock_texture(ctx
, texObj
);
3463 * Implement all the glTexSubImage1/2/3D() functions.
3466 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3467 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3468 GLsizei width
, GLsizei height
, GLsizei depth
,
3469 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3471 struct gl_texture_object
*texObj
;
3472 struct gl_texture_image
*texImage
;
3474 FLUSH_VERTICES(ctx
, 0);
3476 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3477 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3479 _mesa_lookup_enum_by_nr(target
), level
,
3480 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3481 _mesa_lookup_enum_by_nr(format
),
3482 _mesa_lookup_enum_by_nr(type
), pixels
);
3484 /* check target (proxies not allowed) */
3485 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3486 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3487 dims
, _mesa_lookup_enum_by_nr(target
));
3491 if (ctx
->NewState
& _NEW_PIXEL
)
3492 _mesa_update_state(ctx
);
3494 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3495 xoffset
, yoffset
, zoffset
,
3496 width
, height
, depth
, format
, type
)) {
3497 return; /* error was detected */
3500 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3502 _mesa_lock_texture(ctx
, texObj
);
3504 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3506 if (width
> 0 && height
> 0 && depth
> 0) {
3507 /* If we have a border, offset=-1 is legal. Bias by border width. */
3510 if (target
!= GL_TEXTURE_2D_ARRAY
)
3511 zoffset
+= texImage
->Border
;
3514 if (target
!= GL_TEXTURE_1D_ARRAY
)
3515 yoffset
+= texImage
->Border
;
3518 xoffset
+= texImage
->Border
;
3521 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3522 xoffset
, yoffset
, zoffset
,
3523 width
, height
, depth
,
3524 format
, type
, pixels
, &ctx
->Unpack
);
3526 check_gen_mipmap(ctx
, target
, texObj
, level
);
3528 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3529 * the texel data, not the texture format, size, etc.
3533 _mesa_unlock_texture(ctx
, texObj
);
3538 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3539 GLint xoffset
, GLsizei width
,
3540 GLenum format
, GLenum type
,
3541 const GLvoid
*pixels
)
3543 GET_CURRENT_CONTEXT(ctx
);
3544 texsubimage(ctx
, 1, target
, level
,
3547 format
, type
, pixels
);
3552 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3553 GLint xoffset
, GLint yoffset
,
3554 GLsizei width
, GLsizei height
,
3555 GLenum format
, GLenum type
,
3556 const GLvoid
*pixels
)
3558 GET_CURRENT_CONTEXT(ctx
);
3559 texsubimage(ctx
, 2, target
, level
,
3560 xoffset
, yoffset
, 0,
3562 format
, type
, pixels
);
3568 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3569 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3570 GLsizei width
, GLsizei height
, GLsizei depth
,
3571 GLenum format
, GLenum type
,
3572 const GLvoid
*pixels
)
3574 GET_CURRENT_CONTEXT(ctx
);
3575 texsubimage(ctx
, 3, target
, level
,
3576 xoffset
, yoffset
, zoffset
,
3577 width
, height
, depth
,
3578 format
, type
, pixels
);
3584 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3585 * from. This depends on whether the texture contains color or depth values.
3587 static struct gl_renderbuffer
*
3588 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3590 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3591 /* reading from depth/stencil buffer */
3592 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3595 /* copying from color buffer */
3596 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3601 copytexsubimage_by_slice(struct gl_context
*ctx
,
3602 struct gl_texture_image
*texImage
,
3604 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3605 struct gl_renderbuffer
*rb
,
3607 GLsizei width
, GLsizei height
)
3609 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3612 /* For 1D arrays, we copy each scanline of the source rectangle into the
3615 assert(zoffset
== 0);
3617 for (slice
= 0; slice
< height
; slice
++) {
3618 assert(yoffset
+ slice
< texImage
->Height
);
3619 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3620 xoffset
, 0, yoffset
+ slice
,
3621 rb
, x
, y
+ slice
, width
, 1);
3624 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3625 xoffset
, yoffset
, zoffset
,
3626 rb
, x
, y
, width
, height
);
3631 formats_differ_in_component_sizes (mesa_format f1
,
3634 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3635 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3636 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3637 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3639 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3640 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3641 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3642 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3644 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3645 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3646 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3647 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3654 * Implement the glCopyTexImage1/2D() functions.
3657 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3658 GLenum target
, GLint level
, GLenum internalFormat
,
3659 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3661 struct gl_texture_object
*texObj
;
3662 struct gl_texture_image
*texImage
;
3663 const GLuint face
= _mesa_tex_target_to_face(target
);
3664 mesa_format texFormat
;
3665 struct gl_renderbuffer
*rb
;
3667 FLUSH_VERTICES(ctx
, 0);
3669 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3670 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3672 _mesa_lookup_enum_by_nr(target
), level
,
3673 _mesa_lookup_enum_by_nr(internalFormat
),
3674 x
, y
, width
, height
, border
);
3676 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3677 _mesa_update_state(ctx
);
3679 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3680 width
, height
, border
))
3683 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3685 _mesa_error(ctx
, GL_INVALID_VALUE
,
3686 "glCopyTexImage%uD(invalid width or height)", dims
);
3690 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3693 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3694 internalFormat
, GL_NONE
, GL_NONE
);
3696 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3698 if (_mesa_is_gles3(ctx
)) {
3699 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3700 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3701 * OpenGL ES 3.0. Khronos bug# 9807.
3703 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3704 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3705 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer and"
3706 " writing to unsized internal format)", dims
);
3710 /* From Page 139 of OpenGL ES 3.0 spec:
3711 * "If internalformat is sized, the internal format of the new texel
3712 * array is internalformat, and this is also the new texel array’s
3713 * effective internal format. If the component sizes of internalformat
3714 * do not exactly match the corresponding component sizes of the source
3715 * buffer’s effective internal format, described below, an
3716 * INVALID_OPERATION error is generated. If internalformat is unsized,
3717 * the internal format of the new texel array is the effective internal
3718 * format of the source buffer, and this is also the new texel array’s
3719 * effective internal format.
3721 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3722 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3723 "glCopyTexImage%uD(componenet size changed in"
3724 " internal format)", dims
);
3729 assert(texFormat
!= MESA_FORMAT_NONE
);
3731 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3733 width
, height
, 1, border
)) {
3734 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3735 "glCopyTexImage%uD(image too large)", dims
);
3739 if (border
&& ctx
->Const
.StripTextureBorder
) {
3741 width
-= border
* 2;
3744 height
-= border
* 2;
3749 _mesa_lock_texture(ctx
, texObj
);
3751 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3754 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3757 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3759 /* Free old texture image */
3760 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3762 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3763 border
, internalFormat
, texFormat
);
3765 if (width
&& height
) {
3766 /* Allocate texture memory (no pixel data yet) */
3767 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3769 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3771 struct gl_renderbuffer
*srcRb
=
3772 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3774 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3776 srcRb
, srcX
, srcY
, width
, height
);
3779 check_gen_mipmap(ctx
, target
, texObj
, level
);
3782 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3784 _mesa_dirty_texobj(ctx
, texObj
);
3787 _mesa_unlock_texture(ctx
, texObj
);
3793 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3794 GLenum internalFormat
,
3796 GLsizei width
, GLint border
)
3798 GET_CURRENT_CONTEXT(ctx
);
3799 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3805 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3806 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3809 GET_CURRENT_CONTEXT(ctx
);
3810 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3811 x
, y
, width
, height
, border
);
3817 * Implementation for glCopyTexSubImage1/2/3D() functions.
3820 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3821 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3822 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3824 struct gl_texture_object
*texObj
;
3825 struct gl_texture_image
*texImage
;
3827 FLUSH_VERTICES(ctx
, 0);
3829 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3830 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3832 _mesa_lookup_enum_by_nr(target
),
3833 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3835 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3836 _mesa_update_state(ctx
);
3838 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3839 xoffset
, yoffset
, zoffset
, width
, height
)) {
3843 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3845 _mesa_lock_texture(ctx
, texObj
);
3847 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3849 /* If we have a border, offset=-1 is legal. Bias by border width. */
3852 if (target
!= GL_TEXTURE_2D_ARRAY
)
3853 zoffset
+= texImage
->Border
;
3856 if (target
!= GL_TEXTURE_1D_ARRAY
)
3857 yoffset
+= texImage
->Border
;
3860 xoffset
+= texImage
->Border
;
3863 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3865 struct gl_renderbuffer
*srcRb
=
3866 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3868 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3869 xoffset
, yoffset
, zoffset
,
3870 srcRb
, x
, y
, width
, height
);
3872 check_gen_mipmap(ctx
, target
, texObj
, level
);
3874 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3875 * the texel data, not the texture format, size, etc.
3879 _mesa_unlock_texture(ctx
, texObj
);
3884 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3885 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3887 GET_CURRENT_CONTEXT(ctx
);
3888 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3894 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3895 GLint xoffset
, GLint yoffset
,
3896 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3898 GET_CURRENT_CONTEXT(ctx
);
3899 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3906 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3907 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3908 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3910 GET_CURRENT_CONTEXT(ctx
);
3911 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3912 x
, y
, width
, height
);
3916 check_clear_tex_image(struct gl_context
*ctx
,
3917 const char *function
,
3918 struct gl_texture_image
*texImage
,
3919 GLenum format
, GLenum type
,
3921 GLubyte
*clearValue
)
3923 struct gl_texture_object
*texObj
= texImage
->TexObject
;
3924 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
3925 GLenum internalFormat
= texImage
->InternalFormat
;
3928 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
3929 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3930 "%s(buffer texture)", function
);
3934 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
3935 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3936 "%s(compressed texture)", function
);
3940 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
3941 if (err
!= GL_NO_ERROR
) {
3942 _mesa_error(ctx
, err
,
3943 "%s(incompatible format = %s, type = %s)",
3945 _mesa_lookup_enum_by_nr(format
),
3946 _mesa_lookup_enum_by_nr(type
));
3950 /* make sure internal format and format basically agree */
3951 if (!texture_formats_agree(internalFormat
, format
)) {
3952 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3953 "%s(incompatible internalFormat = %s, format = %s)",
3955 _mesa_lookup_enum_by_nr(internalFormat
),
3956 _mesa_lookup_enum_by_nr(format
));
3960 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
3961 /* both source and dest must be integer-valued, or neither */
3962 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
3963 _mesa_is_enum_format_integer(format
)) {
3964 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3965 "%s(integer/non-integer format mismatch)",
3971 if (!_mesa_texstore(ctx
,
3973 texImage
->_BaseFormat
,
3974 texImage
->TexFormat
,
3975 0, /* dstRowStride */
3977 1, 1, 1, /* srcWidth/Height/Depth */
3979 data
? data
: zeroData
,
3980 &ctx
->DefaultPacking
)) {
3981 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
3988 static struct gl_texture_object
*
3989 get_tex_obj_for_clear(struct gl_context
*ctx
,
3990 const char *function
,
3993 struct gl_texture_object
*texObj
;
3996 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4000 texObj
= _mesa_lookup_texture(ctx
, texture
);
4002 if (texObj
== NULL
) {
4003 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4007 if (texObj
->Target
== 0) {
4008 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4016 get_tex_images_for_clear(struct gl_context
*ctx
,
4017 const char *function
,
4018 struct gl_texture_object
*texObj
,
4020 struct gl_texture_image
**texImages
)
4025 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4026 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4030 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4031 for (i
= 0; i
< MAX_FACES
; i
++) {
4032 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4034 texImages
[i
] = _mesa_select_tex_image(ctx
, texObj
, target
, level
);
4035 if (texImages
[i
] == NULL
) {
4036 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4037 "%s(invalid level)", function
);
4045 texImages
[0] = _mesa_select_tex_image(ctx
, texObj
, texObj
->Target
, level
);
4047 if (texImages
[0] == NULL
) {
4048 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4056 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4057 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4058 GLsizei width
, GLsizei height
, GLsizei depth
,
4059 GLenum format
, GLenum type
, const void *data
)
4061 GET_CURRENT_CONTEXT(ctx
);
4062 struct gl_texture_object
*texObj
;
4063 struct gl_texture_image
*texImages
[MAX_FACES
];
4064 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4066 int minDepth
, maxDepth
;
4068 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4073 _mesa_lock_texture(ctx
, texObj
);
4075 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4076 texObj
, level
, texImages
);
4080 if (numImages
== 1) {
4081 minDepth
= -(int) texImages
[0]->Border
;
4082 maxDepth
= texImages
[0]->Depth
;
4085 maxDepth
= numImages
;
4088 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4089 yoffset
< -(GLint
) texImages
[0]->Border
||
4090 zoffset
< minDepth
||
4094 xoffset
+ width
> texImages
[0]->Width
||
4095 yoffset
+ height
> texImages
[0]->Height
||
4096 zoffset
+ depth
> maxDepth
) {
4097 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4098 "glClearSubTexImage(invalid dimensions)");
4102 if (numImages
== 1) {
4103 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4105 format
, type
, data
, clearValue
[0])) {
4106 ctx
->Driver
.ClearTexSubImage(ctx
,
4108 xoffset
, yoffset
, zoffset
,
4109 width
, height
, depth
,
4110 data
? clearValue
[0] : NULL
);
4113 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4114 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4116 format
, type
, data
, clearValue
[i
]))
4119 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4120 ctx
->Driver
.ClearTexSubImage(ctx
,
4122 xoffset
, yoffset
, 0,
4124 data
? clearValue
[i
] : NULL
);
4129 _mesa_unlock_texture(ctx
, texObj
);
4133 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4134 GLenum format
, GLenum type
, const void *data
)
4136 GET_CURRENT_CONTEXT(ctx
);
4137 struct gl_texture_object
*texObj
;
4138 struct gl_texture_image
*texImages
[MAX_FACES
];
4139 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4142 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4147 _mesa_lock_texture(ctx
, texObj
);
4149 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4150 texObj
, level
, texImages
);
4152 for (i
= 0; i
< numImages
; i
++) {
4153 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4160 for (i
= 0; i
< numImages
; i
++) {
4161 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4162 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4163 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4164 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4165 texImages
[i
]->Width
,
4166 texImages
[i
]->Height
,
4167 texImages
[i
]->Depth
,
4168 data
? clearValue
[i
] : NULL
);
4172 _mesa_unlock_texture(ctx
, texObj
);
4178 /**********************************************************************/
4179 /****** Compressed Textures ******/
4180 /**********************************************************************/
4184 * Error checking for glCompressedTexSubImage[123]D().
4185 * \return GL_TRUE if error, GL_FALSE if no error
4188 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4189 GLenum target
, GLint level
,
4190 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4191 GLsizei width
, GLsizei height
, GLsizei depth
,
4192 GLenum format
, GLsizei imageSize
)
4194 struct gl_texture_object
*texObj
;
4195 struct gl_texture_image
*texImage
;
4203 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4204 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4205 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4206 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4207 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4208 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4212 targetOK
= GL_FALSE
;
4217 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
4221 /* no 1D compressed textures at this time */
4222 targetOK
= GL_FALSE
;
4227 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexSubImage%uD(target)",
4232 /* this will catch any invalid compressed format token */
4233 if (!_mesa_is_compressed_format(ctx
, format
)) {
4234 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
4239 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4240 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage%uD(level=%d)",
4245 /* Check for invalid pixel storage modes */
4246 if (!_mesa_compressed_pixel_storage_error_check(ctx
, dims
,
4248 "glCompressedTexSubImage")) {
4252 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4253 if (expectedSize
!= imageSize
) {
4254 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage%uD(size=%d)",
4259 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4261 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4262 "glCompressedTexSubImage%uD()", dims
);
4266 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
4268 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4269 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
4273 if ((GLint
) format
!= texImage
->InternalFormat
) {
4274 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4275 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
4279 if (compressedteximage_only_format(ctx
, format
)) {
4280 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4281 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
4286 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
4287 texImage
, xoffset
, yoffset
, zoffset
,
4288 width
, height
, depth
)) {
4297 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4298 GLenum internalFormat
, GLsizei width
,
4299 GLint border
, GLsizei imageSize
,
4302 GET_CURRENT_CONTEXT(ctx
);
4303 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4304 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4309 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4310 GLenum internalFormat
, GLsizei width
,
4311 GLsizei height
, GLint border
, GLsizei imageSize
,
4314 GET_CURRENT_CONTEXT(ctx
);
4315 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4316 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4321 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4322 GLenum internalFormat
, GLsizei width
,
4323 GLsizei height
, GLsizei depth
, GLint border
,
4324 GLsizei imageSize
, const GLvoid
*data
)
4326 GET_CURRENT_CONTEXT(ctx
);
4327 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4328 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4333 * Common helper for glCompressedTexSubImage1/2/3D().
4336 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
4337 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4338 GLsizei width
, GLsizei height
, GLsizei depth
,
4339 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
4341 struct gl_texture_object
*texObj
;
4342 struct gl_texture_image
*texImage
;
4343 GET_CURRENT_CONTEXT(ctx
);
4344 FLUSH_VERTICES(ctx
, 0);
4346 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
4347 xoffset
, yoffset
, zoffset
,
4348 width
, height
, depth
,
4349 format
, imageSize
)) {
4353 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4355 _mesa_lock_texture(ctx
, texObj
);
4357 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
4360 if (width
> 0 && height
> 0 && depth
> 0) {
4361 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4362 xoffset
, yoffset
, zoffset
,
4363 width
, height
, depth
,
4364 format
, imageSize
, data
);
4366 check_gen_mipmap(ctx
, target
, texObj
, level
);
4368 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4369 * the texel data, not the texture format, size, etc.
4373 _mesa_unlock_texture(ctx
, texObj
);
4378 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4379 GLsizei width
, GLenum format
,
4380 GLsizei imageSize
, const GLvoid
*data
)
4382 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
4383 format
, imageSize
, data
);
4388 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4389 GLint yoffset
, GLsizei width
, GLsizei height
,
4390 GLenum format
, GLsizei imageSize
,
4393 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
4394 width
, height
, 1, format
, imageSize
, data
);
4399 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4400 GLint yoffset
, GLint zoffset
, GLsizei width
,
4401 GLsizei height
, GLsizei depth
, GLenum format
,
4402 GLsizei imageSize
, const GLvoid
*data
)
4404 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
4405 width
, height
, depth
, format
, imageSize
, data
);
4409 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4411 if (ctx
->API
!= API_OPENGL_CORE
) {
4412 switch (internalFormat
) {
4414 return MESA_FORMAT_A_UNORM8
;
4416 return MESA_FORMAT_A_UNORM16
;
4417 case GL_ALPHA16F_ARB
:
4418 return MESA_FORMAT_A_FLOAT16
;
4419 case GL_ALPHA32F_ARB
:
4420 return MESA_FORMAT_A_FLOAT32
;
4421 case GL_ALPHA8I_EXT
:
4422 return MESA_FORMAT_A_SINT8
;
4423 case GL_ALPHA16I_EXT
:
4424 return MESA_FORMAT_A_SINT16
;
4425 case GL_ALPHA32I_EXT
:
4426 return MESA_FORMAT_A_SINT32
;
4427 case GL_ALPHA8UI_EXT
:
4428 return MESA_FORMAT_A_UINT8
;
4429 case GL_ALPHA16UI_EXT
:
4430 return MESA_FORMAT_A_UINT16
;
4431 case GL_ALPHA32UI_EXT
:
4432 return MESA_FORMAT_A_UINT32
;
4434 return MESA_FORMAT_L_UNORM8
;
4435 case GL_LUMINANCE16
:
4436 return MESA_FORMAT_L_UNORM16
;
4437 case GL_LUMINANCE16F_ARB
:
4438 return MESA_FORMAT_L_FLOAT16
;
4439 case GL_LUMINANCE32F_ARB
:
4440 return MESA_FORMAT_L_FLOAT32
;
4441 case GL_LUMINANCE8I_EXT
:
4442 return MESA_FORMAT_L_SINT8
;
4443 case GL_LUMINANCE16I_EXT
:
4444 return MESA_FORMAT_L_SINT16
;
4445 case GL_LUMINANCE32I_EXT
:
4446 return MESA_FORMAT_L_SINT32
;
4447 case GL_LUMINANCE8UI_EXT
:
4448 return MESA_FORMAT_L_UINT8
;
4449 case GL_LUMINANCE16UI_EXT
:
4450 return MESA_FORMAT_L_UINT16
;
4451 case GL_LUMINANCE32UI_EXT
:
4452 return MESA_FORMAT_L_UINT32
;
4453 case GL_LUMINANCE8_ALPHA8
:
4454 return MESA_FORMAT_L8A8_UNORM
;
4455 case GL_LUMINANCE16_ALPHA16
:
4456 return MESA_FORMAT_L16A16_UNORM
;
4457 case GL_LUMINANCE_ALPHA16F_ARB
:
4458 return MESA_FORMAT_LA_FLOAT16
;
4459 case GL_LUMINANCE_ALPHA32F_ARB
:
4460 return MESA_FORMAT_LA_FLOAT32
;
4461 case GL_LUMINANCE_ALPHA8I_EXT
:
4462 return MESA_FORMAT_LA_SINT8
;
4463 case GL_LUMINANCE_ALPHA16I_EXT
:
4464 return MESA_FORMAT_LA_SINT8
;
4465 case GL_LUMINANCE_ALPHA32I_EXT
:
4466 return MESA_FORMAT_LA_SINT16
;
4467 case GL_LUMINANCE_ALPHA8UI_EXT
:
4468 return MESA_FORMAT_LA_UINT8
;
4469 case GL_LUMINANCE_ALPHA16UI_EXT
:
4470 return MESA_FORMAT_LA_UINT16
;
4471 case GL_LUMINANCE_ALPHA32UI_EXT
:
4472 return MESA_FORMAT_LA_UINT32
;
4474 return MESA_FORMAT_I_UNORM8
;
4475 case GL_INTENSITY16
:
4476 return MESA_FORMAT_I_UNORM16
;
4477 case GL_INTENSITY16F_ARB
:
4478 return MESA_FORMAT_I_FLOAT16
;
4479 case GL_INTENSITY32F_ARB
:
4480 return MESA_FORMAT_I_FLOAT32
;
4481 case GL_INTENSITY8I_EXT
:
4482 return MESA_FORMAT_I_SINT8
;
4483 case GL_INTENSITY16I_EXT
:
4484 return MESA_FORMAT_I_SINT16
;
4485 case GL_INTENSITY32I_EXT
:
4486 return MESA_FORMAT_I_SINT32
;
4487 case GL_INTENSITY8UI_EXT
:
4488 return MESA_FORMAT_I_UINT8
;
4489 case GL_INTENSITY16UI_EXT
:
4490 return MESA_FORMAT_I_UINT16
;
4491 case GL_INTENSITY32UI_EXT
:
4492 return MESA_FORMAT_I_UINT32
;
4498 if (ctx
->API
== API_OPENGL_CORE
&&
4499 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4500 switch (internalFormat
) {
4502 return MESA_FORMAT_RGB_FLOAT32
;
4504 return MESA_FORMAT_RGB_UINT32
;
4506 return MESA_FORMAT_RGB_SINT32
;
4512 switch (internalFormat
) {
4514 return MESA_FORMAT_R8G8B8A8_UNORM
;
4516 return MESA_FORMAT_RGBA_UNORM16
;
4517 case GL_RGBA16F_ARB
:
4518 return MESA_FORMAT_RGBA_FLOAT16
;
4519 case GL_RGBA32F_ARB
:
4520 return MESA_FORMAT_RGBA_FLOAT32
;
4522 return MESA_FORMAT_RGBA_SINT8
;
4523 case GL_RGBA16I_EXT
:
4524 return MESA_FORMAT_RGBA_SINT16
;
4525 case GL_RGBA32I_EXT
:
4526 return MESA_FORMAT_RGBA_SINT32
;
4527 case GL_RGBA8UI_EXT
:
4528 return MESA_FORMAT_RGBA_UINT8
;
4529 case GL_RGBA16UI_EXT
:
4530 return MESA_FORMAT_RGBA_UINT16
;
4531 case GL_RGBA32UI_EXT
:
4532 return MESA_FORMAT_RGBA_UINT32
;
4535 return MESA_FORMAT_R8G8_UNORM
;
4537 return MESA_FORMAT_R16G16_UNORM
;
4539 return MESA_FORMAT_RG_FLOAT16
;
4541 return MESA_FORMAT_RG_FLOAT32
;
4543 return MESA_FORMAT_RG_SINT8
;
4545 return MESA_FORMAT_RG_SINT16
;
4547 return MESA_FORMAT_RG_SINT32
;
4549 return MESA_FORMAT_RG_UINT8
;
4551 return MESA_FORMAT_RG_UINT16
;
4553 return MESA_FORMAT_RG_UINT32
;
4556 return MESA_FORMAT_R_UNORM8
;
4558 return MESA_FORMAT_R_UNORM16
;
4560 return MESA_FORMAT_R_FLOAT16
;
4562 return MESA_FORMAT_R_FLOAT32
;
4564 return MESA_FORMAT_R_SINT8
;
4566 return MESA_FORMAT_R_SINT16
;
4568 return MESA_FORMAT_R_SINT32
;
4570 return MESA_FORMAT_R_UINT8
;
4572 return MESA_FORMAT_R_UINT16
;
4574 return MESA_FORMAT_R_UINT32
;
4577 return MESA_FORMAT_NONE
;
4583 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4584 GLenum internalFormat
)
4586 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
4589 if (format
== MESA_FORMAT_NONE
)
4590 return MESA_FORMAT_NONE
;
4592 datatype
= _mesa_get_format_datatype(format
);
4594 /* The GL_ARB_texture_buffer_object spec says:
4596 * "If ARB_texture_float is not supported, references to the
4597 * floating-point internal formats provided by that extension should be
4598 * removed, and such formats may not be passed to TexBufferARB."
4600 * As a result, GL_HALF_FLOAT internal format depends on both
4601 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
4603 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
4604 !ctx
->Extensions
.ARB_texture_float
)
4605 return MESA_FORMAT_NONE
;
4607 if (!ctx
->Extensions
.ARB_texture_rg
) {
4608 GLenum base_format
= _mesa_get_format_base_format(format
);
4609 if (base_format
== GL_R
|| base_format
== GL_RG
)
4610 return MESA_FORMAT_NONE
;
4613 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4614 GLenum base_format
= _mesa_get_format_base_format(format
);
4615 if (base_format
== GL_RGB
)
4616 return MESA_FORMAT_NONE
;
4623 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4624 struct gl_buffer_object
*bufObj
,
4625 GLintptr offset
, GLsizeiptr size
)
4627 struct gl_texture_object
*texObj
;
4630 FLUSH_VERTICES(ctx
, 0);
4632 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4633 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4637 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
4638 if (format
== MESA_FORMAT_NONE
) {
4639 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4644 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4646 _mesa_lock_texture(ctx
, texObj
);
4648 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4649 texObj
->BufferObjectFormat
= internalFormat
;
4650 texObj
->_BufferObjectFormat
= format
;
4651 texObj
->BufferOffset
= offset
;
4652 texObj
->BufferSize
= size
;
4654 _mesa_unlock_texture(ctx
, texObj
);
4656 ctx
->NewDriverState
|= ctx
->DriverFlags
.NewTextureBuffer
;
4659 bufObj
->UsageHistory
|= USAGE_TEXTURE_BUFFER
;
4664 /** GL_ARB_texture_buffer_object */
4666 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4668 struct gl_buffer_object
*bufObj
;
4670 GET_CURRENT_CONTEXT(ctx
);
4672 /* NOTE: ARB_texture_buffer_object has interactions with
4673 * the compatibility profile that are not implemented.
4675 if (!(ctx
->API
== API_OPENGL_CORE
&&
4676 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4677 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4681 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4682 if (!bufObj
&& buffer
) {
4683 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4687 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4691 /** GL_ARB_texture_buffer_range */
4693 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4694 GLintptr offset
, GLsizeiptr size
)
4696 struct gl_buffer_object
*bufObj
;
4698 GET_CURRENT_CONTEXT(ctx
);
4700 if (!(ctx
->API
== API_OPENGL_CORE
&&
4701 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4702 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4706 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4710 (offset
+ size
) > bufObj
->Size
) {
4711 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4714 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4715 _mesa_error(ctx
, GL_INVALID_VALUE
,
4716 "glTexBufferRange(invalid offset alignment)");
4719 } else if (buffer
) {
4720 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4728 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4733 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4735 /* Everything that is allowed for renderbuffers,
4736 * except for a base format of GL_STENCIL_INDEX.
4738 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4739 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4743 /** GL_ARB_texture_multisample */
4745 check_multisample_target(GLuint dims
, GLenum target
)
4748 case GL_TEXTURE_2D_MULTISAMPLE
:
4749 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4752 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4753 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4763 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4764 GLint internalformat
, GLsizei width
, GLsizei height
,
4765 GLsizei depth
, GLboolean fixedsamplelocations
,
4766 GLboolean immutable
, const char *func
)
4768 struct gl_texture_object
*texObj
;
4769 struct gl_texture_image
*texImage
;
4770 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
4771 mesa_format texFormat
;
4772 GLenum sample_count_error
;
4774 GET_CURRENT_CONTEXT(ctx
);
4776 if (!(ctx
->Extensions
.ARB_texture_multisample
4777 && _mesa_is_desktop_gl(ctx
))) {
4778 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4782 if (!check_multisample_target(dims
, target
)) {
4783 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4787 /* check that the specified internalformat is color/depth/stencil-renderable;
4788 * refer GL3.1 spec 4.4.4
4791 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4792 _mesa_error(ctx
, GL_INVALID_ENUM
,
4793 "%s(internalformat=%s not legal for immutable-format)",
4794 func
, _mesa_lookup_enum_by_nr(internalformat
));
4798 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4799 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4800 "%s(internalformat=%s)",
4801 func
, _mesa_lookup_enum_by_nr(internalformat
));
4805 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4806 internalformat
, samples
);
4807 samplesOK
= sample_count_error
== GL_NO_ERROR
;
4809 /* Page 254 of OpenGL 4.4 spec says:
4810 * "Proxy arrays for two-dimensional multisample and two-dimensional
4811 * multisample array textures are operated on in the same way when
4812 * TexImage2DMultisample is called with target specified as
4813 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
4814 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
4815 * However, if samples is not supported, then no error is generated.
4817 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
4818 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4822 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4824 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4825 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4826 "%s(texture object 0)",
4831 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4833 if (texImage
== NULL
) {
4834 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4838 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4839 internalformat
, GL_NONE
, GL_NONE
);
4840 assert(texFormat
!= MESA_FORMAT_NONE
);
4842 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4843 width
, height
, depth
, 0);
4845 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4846 width
, height
, depth
, 0);
4848 if (_mesa_is_proxy_texture(target
)) {
4849 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
4850 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
4851 internalformat
, texFormat
,
4852 samples
, fixedsamplelocations
);
4855 /* clear all image fields */
4856 clear_teximage_fields(texImage
);
4860 if (!dimensionsOK
) {
4861 _mesa_error(ctx
, GL_INVALID_VALUE
,
4862 "%s(invalid width or height)", func
);
4867 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4868 "%s(texture too large)", func
);
4872 /* Check if texObj->Immutable is set */
4873 if (texObj
->Immutable
) {
4874 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4878 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4880 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
4881 internalformat
, texFormat
,
4882 samples
, fixedsamplelocations
);
4884 if (width
> 0 && height
> 0 && depth
> 0) {
4885 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4886 width
, height
, depth
)) {
4887 /* tidy up the texture image state. strictly speaking,
4888 * we're allowed to just leave this in whatever state we
4889 * like, but being tidy is good.
4891 _mesa_init_teximage_fields(ctx
, texImage
,
4892 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4896 texObj
->Immutable
= immutable
;
4899 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
4902 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4908 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4909 GLenum internalformat
, GLsizei width
,
4910 GLsizei height
, GLboolean fixedsamplelocations
)
4912 teximagemultisample(2, target
, samples
, internalformat
,
4913 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4914 "glTexImage2DMultisample");
4919 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4920 GLenum internalformat
, GLsizei width
,
4921 GLsizei height
, GLsizei depth
,
4922 GLboolean fixedsamplelocations
)
4924 teximagemultisample(3, target
, samples
, internalformat
,
4925 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4926 "glTexImage3DMultisample");
4931 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4932 GLenum internalformat
, GLsizei width
,
4933 GLsizei height
, GLboolean fixedsamplelocations
)
4935 teximagemultisample(2, target
, samples
, internalformat
,
4936 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4937 "glTexStorage2DMultisample");
4941 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4942 GLenum internalformat
, GLsizei width
,
4943 GLsizei height
, GLsizei depth
,
4944 GLboolean fixedsamplelocations
)
4946 teximagemultisample(3, target
, samples
, internalformat
,
4947 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4948 "glTexStorage3DMultisample");