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"
45 #include "texcompress.h"
46 #include "texcompress_cpal.h"
50 #include "texstorage.h"
51 #include "textureview.h"
53 #include "glformats.h"
57 * State changes which we care about for glCopyTex[Sub]Image() calls.
58 * In particular, we care about pixel transfer state and buffer state
59 * (such as glReadBuffer to make sure we read from the right renderbuffer).
61 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
66 * Return the simple base format for a given internal texture format.
67 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
69 * \param ctx GL context.
70 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
72 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
73 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
75 * This is the format which is used during texture application (i.e. the
76 * texture format and env mode determine the arithmetic used.
79 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
81 switch (internalFormat
) {
87 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
94 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
96 case GL_LUMINANCE_ALPHA
:
97 case GL_LUMINANCE4_ALPHA4
:
98 case GL_LUMINANCE6_ALPHA2
:
99 case GL_LUMINANCE8_ALPHA8
:
100 case GL_LUMINANCE12_ALPHA4
:
101 case GL_LUMINANCE12_ALPHA12
:
102 case GL_LUMINANCE16_ALPHA16
:
103 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
109 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
111 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
122 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
136 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
138 if (_mesa_is_gles(ctx
)) {
139 switch (internalFormat
) {
147 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
148 switch (internalFormat
) {
156 if (ctx
->Extensions
.ARB_depth_texture
) {
157 switch (internalFormat
) {
158 case GL_DEPTH_COMPONENT
:
159 case GL_DEPTH_COMPONENT16
:
160 case GL_DEPTH_COMPONENT24
:
161 case GL_DEPTH_COMPONENT32
:
162 return GL_DEPTH_COMPONENT
;
168 switch (internalFormat
) {
169 case GL_COMPRESSED_ALPHA
:
171 case GL_COMPRESSED_LUMINANCE
:
173 case GL_COMPRESSED_LUMINANCE_ALPHA
:
174 return GL_LUMINANCE_ALPHA
;
175 case GL_COMPRESSED_INTENSITY
:
177 case GL_COMPRESSED_RGB
:
179 case GL_COMPRESSED_RGBA
:
185 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
186 switch (internalFormat
) {
187 case GL_COMPRESSED_RGB_FXT1_3DFX
:
189 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
196 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
198 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
199 switch (internalFormat
) {
200 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
202 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
203 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
204 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
211 if (_mesa_is_desktop_gl(ctx
)
212 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
213 switch (internalFormat
) {
225 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
226 if (internalFormat
== GL_YCBCR_MESA
)
227 return GL_YCBCR_MESA
;
230 if (ctx
->Extensions
.ARB_texture_float
) {
231 switch (internalFormat
) {
232 case GL_ALPHA16F_ARB
:
233 case GL_ALPHA32F_ARB
:
241 case GL_INTENSITY16F_ARB
:
242 case GL_INTENSITY32F_ARB
:
244 case GL_LUMINANCE16F_ARB
:
245 case GL_LUMINANCE32F_ARB
:
247 case GL_LUMINANCE_ALPHA16F_ARB
:
248 case GL_LUMINANCE_ALPHA32F_ARB
:
249 return GL_LUMINANCE_ALPHA
;
255 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
256 switch (internalFormat
) {
265 if (ctx
->Extensions
.EXT_texture_snorm
) {
266 switch (internalFormat
) {
281 case GL_RGBA16_SNORM
:
284 case GL_ALPHA8_SNORM
:
285 case GL_ALPHA16_SNORM
:
287 case GL_LUMINANCE_SNORM
:
288 case GL_LUMINANCE8_SNORM
:
289 case GL_LUMINANCE16_SNORM
:
291 case GL_LUMINANCE_ALPHA_SNORM
:
292 case GL_LUMINANCE8_ALPHA8_SNORM
:
293 case GL_LUMINANCE16_ALPHA16_SNORM
:
294 return GL_LUMINANCE_ALPHA
;
295 case GL_INTENSITY_SNORM
:
296 case GL_INTENSITY8_SNORM
:
297 case GL_INTENSITY16_SNORM
:
304 switch (internalFormat
) {
305 case GL_DEPTH_STENCIL
:
306 case GL_DEPTH24_STENCIL8
:
307 return GL_DEPTH_STENCIL
;
312 if (ctx
->Extensions
.EXT_texture_sRGB
) {
313 switch (internalFormat
) {
316 case GL_COMPRESSED_SRGB_EXT
:
318 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
319 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
320 case GL_SRGB_ALPHA_EXT
:
321 case GL_SRGB8_ALPHA8_EXT
:
322 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
324 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
325 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
326 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
327 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
328 case GL_SLUMINANCE_ALPHA_EXT
:
329 case GL_SLUMINANCE8_ALPHA8_EXT
:
330 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
331 return GL_LUMINANCE_ALPHA
;
332 case GL_SLUMINANCE_EXT
:
333 case GL_SLUMINANCE8_EXT
:
334 case GL_COMPRESSED_SLUMINANCE_EXT
:
341 if (ctx
->Version
>= 30 ||
342 ctx
->Extensions
.EXT_texture_integer
) {
343 switch (internalFormat
) {
345 case GL_RGBA16UI_EXT
:
346 case GL_RGBA32UI_EXT
:
362 if (ctx
->Extensions
.EXT_texture_integer
) {
363 switch (internalFormat
) {
364 case GL_ALPHA8UI_EXT
:
365 case GL_ALPHA16UI_EXT
:
366 case GL_ALPHA32UI_EXT
:
368 case GL_ALPHA16I_EXT
:
369 case GL_ALPHA32I_EXT
:
371 case GL_INTENSITY8UI_EXT
:
372 case GL_INTENSITY16UI_EXT
:
373 case GL_INTENSITY32UI_EXT
:
374 case GL_INTENSITY8I_EXT
:
375 case GL_INTENSITY16I_EXT
:
376 case GL_INTENSITY32I_EXT
:
378 case GL_LUMINANCE8UI_EXT
:
379 case GL_LUMINANCE16UI_EXT
:
380 case GL_LUMINANCE32UI_EXT
:
381 case GL_LUMINANCE8I_EXT
:
382 case GL_LUMINANCE16I_EXT
:
383 case GL_LUMINANCE32I_EXT
:
385 case GL_LUMINANCE_ALPHA8UI_EXT
:
386 case GL_LUMINANCE_ALPHA16UI_EXT
:
387 case GL_LUMINANCE_ALPHA32UI_EXT
:
388 case GL_LUMINANCE_ALPHA8I_EXT
:
389 case GL_LUMINANCE_ALPHA16I_EXT
:
390 case GL_LUMINANCE_ALPHA32I_EXT
:
391 return GL_LUMINANCE_ALPHA
;
397 if (ctx
->Extensions
.ARB_texture_rg
) {
398 switch (internalFormat
) {
400 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
402 if (!ctx
->Extensions
.ARB_half_float_pixel
)
406 if (!ctx
->Extensions
.ARB_texture_float
)
415 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
421 case GL_COMPRESSED_RED
:
425 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
427 if (!ctx
->Extensions
.ARB_half_float_pixel
)
431 if (!ctx
->Extensions
.ARB_texture_float
)
440 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
446 case GL_COMPRESSED_RG
:
453 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
454 switch (internalFormat
) {
462 if (ctx
->Extensions
.EXT_packed_float
) {
463 switch (internalFormat
) {
464 case GL_R11F_G11F_B10F_EXT
:
471 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
472 switch (internalFormat
) {
473 case GL_DEPTH_COMPONENT32F
:
474 return GL_DEPTH_COMPONENT
;
475 case GL_DEPTH32F_STENCIL8
:
476 return GL_DEPTH_STENCIL
;
482 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
483 switch (internalFormat
) {
484 case GL_COMPRESSED_RED_RGTC1
:
485 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
487 case GL_COMPRESSED_RG_RGTC2
:
488 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
495 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
496 switch (internalFormat
) {
497 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
498 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
500 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
501 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
502 return GL_LUMINANCE_ALPHA
;
508 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
509 switch (internalFormat
) {
510 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
511 return GL_LUMINANCE_ALPHA
;
517 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
518 switch (internalFormat
) {
519 case GL_ETC1_RGB8_OES
:
526 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
527 switch (internalFormat
) {
528 case GL_COMPRESSED_RGB8_ETC2
:
529 case GL_COMPRESSED_SRGB8_ETC2
:
531 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
532 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
533 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
534 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
536 case GL_COMPRESSED_R11_EAC
:
537 case GL_COMPRESSED_SIGNED_R11_EAC
:
539 case GL_COMPRESSED_RG11_EAC
:
540 case GL_COMPRESSED_SIGNED_RG11_EAC
:
547 if (ctx
->API
== API_OPENGLES
) {
548 switch (internalFormat
) {
549 case GL_PALETTE4_RGB8_OES
:
550 case GL_PALETTE4_R5_G6_B5_OES
:
551 case GL_PALETTE8_RGB8_OES
:
552 case GL_PALETTE8_R5_G6_B5_OES
:
554 case GL_PALETTE4_RGBA8_OES
:
555 case GL_PALETTE8_RGB5_A1_OES
:
556 case GL_PALETTE4_RGBA4_OES
:
557 case GL_PALETTE4_RGB5_A1_OES
:
558 case GL_PALETTE8_RGBA8_OES
:
559 case GL_PALETTE8_RGBA4_OES
:
566 return -1; /* error */
571 * For cube map faces, return a face index in [0,5].
572 * For other targets return 0;
575 _mesa_tex_target_to_face(GLenum target
)
577 if (_mesa_is_cube_face(target
))
578 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
586 * Install gl_texture_image in a gl_texture_object according to the target
587 * and level parameters.
589 * \param tObj texture object.
590 * \param target texture target.
591 * \param level image level.
592 * \param texImage texture image.
595 set_tex_image(struct gl_texture_object
*tObj
,
596 GLenum target
, GLint level
,
597 struct gl_texture_image
*texImage
)
599 const GLuint face
= _mesa_tex_target_to_face(target
);
603 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
606 tObj
->Image
[face
][level
] = texImage
;
608 /* Set the 'back' pointer */
609 texImage
->TexObject
= tObj
;
610 texImage
->Level
= level
;
611 texImage
->Face
= face
;
616 * Allocate a texture image structure.
618 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
621 * \return a pointer to gl_texture_image struct with all fields initialized to
624 struct gl_texture_image
*
625 _mesa_new_texture_image( struct gl_context
*ctx
)
628 return CALLOC_STRUCT(gl_texture_image
);
633 * Free a gl_texture_image and associated data.
634 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
636 * \param texImage texture image.
638 * Free the texture image structure and the associated image data.
641 _mesa_delete_texture_image(struct gl_context
*ctx
,
642 struct gl_texture_image
*texImage
)
644 /* Free texImage->Data and/or any other driver-specific texture
647 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
648 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
654 * Test if a target is a proxy target.
656 * \param target texture target.
658 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
661 _mesa_is_proxy_texture(GLenum target
)
664 static const GLenum targets
[] = {
668 GL_PROXY_TEXTURE_CUBE_MAP
,
669 GL_PROXY_TEXTURE_RECTANGLE
,
670 GL_PROXY_TEXTURE_1D_ARRAY
,
671 GL_PROXY_TEXTURE_2D_ARRAY
,
672 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
673 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
674 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
677 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
678 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
680 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== Elements(targets
) + 2);
682 for (i
= 0; i
< Elements(targets
); ++i
)
683 if (target
== targets
[i
])
690 * Return the proxy target which corresponds to the given texture target
693 proxy_target(GLenum target
)
697 case GL_PROXY_TEXTURE_1D
:
698 return GL_PROXY_TEXTURE_1D
;
700 case GL_PROXY_TEXTURE_2D
:
701 return GL_PROXY_TEXTURE_2D
;
703 case GL_PROXY_TEXTURE_3D
:
704 return GL_PROXY_TEXTURE_3D
;
705 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
706 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
707 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
708 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
709 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
710 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
711 case GL_TEXTURE_CUBE_MAP_ARB
:
712 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
713 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
714 case GL_TEXTURE_RECTANGLE_NV
:
715 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
716 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
717 case GL_TEXTURE_1D_ARRAY_EXT
:
718 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
719 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
720 case GL_TEXTURE_2D_ARRAY_EXT
:
721 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
722 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
723 case GL_TEXTURE_CUBE_MAP_ARRAY
:
724 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
725 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
726 case GL_TEXTURE_2D_MULTISAMPLE
:
727 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
728 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
729 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
730 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
731 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
733 _mesa_problem(NULL
, "unexpected target in proxy_target()");
740 * Return a pointer to the current texture object for the given target
741 * on the current texture unit.
742 * Note: all <target> error checking should have been done by this point.
744 struct gl_texture_object
*
745 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
747 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
748 const GLboolean arrayTex
= ctx
->Extensions
.EXT_texture_array
;
752 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
753 case GL_PROXY_TEXTURE_1D
:
754 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
756 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
757 case GL_PROXY_TEXTURE_2D
:
758 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
760 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
761 case GL_PROXY_TEXTURE_3D
:
762 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
763 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
764 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
765 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
766 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
767 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
768 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
769 case GL_TEXTURE_CUBE_MAP_ARB
:
770 return ctx
->Extensions
.ARB_texture_cube_map
771 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
772 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
773 return ctx
->Extensions
.ARB_texture_cube_map
774 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
775 case GL_TEXTURE_CUBE_MAP_ARRAY
:
776 return ctx
->Extensions
.ARB_texture_cube_map_array
777 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
778 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
779 return ctx
->Extensions
.ARB_texture_cube_map_array
780 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
781 case GL_TEXTURE_RECTANGLE_NV
:
782 return ctx
->Extensions
.NV_texture_rectangle
783 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
784 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
785 return ctx
->Extensions
.NV_texture_rectangle
786 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
787 case GL_TEXTURE_1D_ARRAY_EXT
:
788 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
789 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
790 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
791 case GL_TEXTURE_2D_ARRAY_EXT
:
792 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
793 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
794 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
795 case GL_TEXTURE_BUFFER
:
796 return ctx
->API
== API_OPENGL_CORE
&&
797 ctx
->Extensions
.ARB_texture_buffer_object
?
798 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
799 case GL_TEXTURE_EXTERNAL_OES
:
800 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
801 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
802 case GL_TEXTURE_2D_MULTISAMPLE
:
803 return ctx
->Extensions
.ARB_texture_multisample
804 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
805 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
806 return ctx
->Extensions
.ARB_texture_multisample
807 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
808 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
809 return ctx
->Extensions
.ARB_texture_multisample
810 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
811 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
812 return ctx
->Extensions
.ARB_texture_multisample
813 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
815 _mesa_problem(NULL
, "bad target in _mesa_get_current_tex_object()");
823 * Get a texture image pointer from a texture object, given a texture
824 * target and mipmap level. The target and level parameters should
825 * have already been error-checked.
827 * \param ctx GL context.
828 * \param texObj texture unit.
829 * \param target texture target.
830 * \param level image level.
832 * \return pointer to the texture image structure, or NULL on failure.
834 struct gl_texture_image
*
835 _mesa_select_tex_image(struct gl_context
*ctx
,
836 const struct gl_texture_object
*texObj
,
837 GLenum target
, GLint level
)
839 const GLuint face
= _mesa_tex_target_to_face(target
);
843 ASSERT(level
< MAX_TEXTURE_LEVELS
);
845 return texObj
->Image
[face
][level
];
850 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
851 * it and install it. Only return NULL if passed a bad parameter or run
854 struct gl_texture_image
*
855 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
856 GLenum target
, GLint level
)
858 struct gl_texture_image
*texImage
;
863 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
865 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
867 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
871 set_tex_image(texObj
, target
, level
, texImage
);
879 * Return pointer to the specified proxy texture image.
880 * Note that proxy textures are per-context, not per-texture unit.
881 * \return pointer to texture image or NULL if invalid target, invalid
882 * level, or out of memory.
884 static struct gl_texture_image
*
885 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
887 struct gl_texture_image
*texImage
;
894 case GL_PROXY_TEXTURE_1D
:
895 if (level
>= ctx
->Const
.MaxTextureLevels
)
897 texIndex
= TEXTURE_1D_INDEX
;
899 case GL_PROXY_TEXTURE_2D
:
900 if (level
>= ctx
->Const
.MaxTextureLevels
)
902 texIndex
= TEXTURE_2D_INDEX
;
904 case GL_PROXY_TEXTURE_3D
:
905 if (level
>= ctx
->Const
.Max3DTextureLevels
)
907 texIndex
= TEXTURE_3D_INDEX
;
909 case GL_PROXY_TEXTURE_CUBE_MAP
:
910 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
912 texIndex
= TEXTURE_CUBE_INDEX
;
914 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
917 texIndex
= TEXTURE_RECT_INDEX
;
919 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
920 if (level
>= ctx
->Const
.MaxTextureLevels
)
922 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
924 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
925 if (level
>= ctx
->Const
.MaxTextureLevels
)
927 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
929 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
930 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
932 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
934 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
937 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
939 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
942 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
948 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
950 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
952 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
955 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
956 /* Set the 'back' pointer */
957 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
964 * Get the maximum number of allowed mipmap levels.
966 * \param ctx GL context.
967 * \param target texture target.
969 * \return the maximum number of allowed mipmap levels for the given
970 * texture target, or zero if passed a bad target.
975 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
979 case GL_PROXY_TEXTURE_1D
:
981 case GL_PROXY_TEXTURE_2D
:
982 return ctx
->Const
.MaxTextureLevels
;
984 case GL_PROXY_TEXTURE_3D
:
985 return ctx
->Const
.Max3DTextureLevels
;
986 case GL_TEXTURE_CUBE_MAP
:
987 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
988 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
989 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
990 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
991 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
992 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
993 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
994 return ctx
->Extensions
.ARB_texture_cube_map
995 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
996 case GL_TEXTURE_RECTANGLE_NV
:
997 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
998 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
999 case GL_TEXTURE_1D_ARRAY_EXT
:
1000 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1001 case GL_TEXTURE_2D_ARRAY_EXT
:
1002 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1003 return ctx
->Extensions
.EXT_texture_array
1004 ? ctx
->Const
.MaxTextureLevels
: 0;
1005 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1006 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1007 return ctx
->Extensions
.ARB_texture_cube_map_array
1008 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1009 case GL_TEXTURE_BUFFER
:
1010 return ctx
->API
== API_OPENGL_CORE
&&
1011 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1012 case GL_TEXTURE_2D_MULTISAMPLE
:
1013 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1014 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1015 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1016 return _mesa_is_desktop_gl(ctx
)
1017 && ctx
->Extensions
.ARB_texture_multisample
1019 case GL_TEXTURE_EXTERNAL_OES
:
1022 return 0; /* bad target */
1028 * Return number of dimensions per mipmap level for the given texture target.
1031 _mesa_get_texture_dimensions(GLenum target
)
1035 case GL_PROXY_TEXTURE_1D
:
1038 case GL_TEXTURE_RECTANGLE
:
1039 case GL_TEXTURE_CUBE_MAP
:
1040 case GL_PROXY_TEXTURE_2D
:
1041 case GL_PROXY_TEXTURE_RECTANGLE
:
1042 case GL_PROXY_TEXTURE_CUBE_MAP
:
1043 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1044 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1045 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1046 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1047 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1048 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1049 case GL_TEXTURE_1D_ARRAY
:
1050 case GL_PROXY_TEXTURE_1D_ARRAY
:
1051 case GL_TEXTURE_EXTERNAL_OES
:
1052 case GL_TEXTURE_2D_MULTISAMPLE
:
1053 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1056 case GL_PROXY_TEXTURE_3D
:
1057 case GL_TEXTURE_2D_ARRAY
:
1058 case GL_PROXY_TEXTURE_2D_ARRAY
:
1059 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1060 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1061 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1062 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1064 case GL_TEXTURE_BUFFER
:
1067 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1075 * Check if a texture target can have more than one layer.
1078 _mesa_tex_target_is_layered(GLenum target
)
1082 case GL_PROXY_TEXTURE_1D
:
1084 case GL_PROXY_TEXTURE_2D
:
1085 case GL_TEXTURE_RECTANGLE
:
1086 case GL_PROXY_TEXTURE_RECTANGLE
:
1087 case GL_TEXTURE_2D_MULTISAMPLE
:
1088 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1089 case GL_TEXTURE_BUFFER
:
1090 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1091 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1092 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1093 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1094 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1095 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1096 case GL_TEXTURE_EXTERNAL_OES
:
1100 case GL_PROXY_TEXTURE_3D
:
1101 case GL_TEXTURE_CUBE_MAP
:
1102 case GL_PROXY_TEXTURE_CUBE_MAP
:
1103 case GL_TEXTURE_1D_ARRAY
:
1104 case GL_PROXY_TEXTURE_1D_ARRAY
:
1105 case GL_TEXTURE_2D_ARRAY
:
1106 case GL_PROXY_TEXTURE_2D_ARRAY
:
1107 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1108 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1109 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1110 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1114 assert(!"Invalid texture target.");
1121 * Return the number of layers present in the given level of an array,
1122 * cubemap or 3D texture. If the texture is not layered return zero.
1125 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1127 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1129 switch (texObj
->Target
) {
1132 case GL_TEXTURE_RECTANGLE
:
1133 case GL_TEXTURE_2D_MULTISAMPLE
:
1134 case GL_TEXTURE_BUFFER
:
1135 case GL_TEXTURE_EXTERNAL_OES
:
1138 case GL_TEXTURE_CUBE_MAP
:
1141 case GL_TEXTURE_1D_ARRAY
: {
1142 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1143 return img
? img
->Height
: 0;
1147 case GL_TEXTURE_2D_ARRAY
:
1148 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1149 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1150 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1151 return img
? img
->Depth
: 0;
1155 assert(!"Invalid texture target.");
1162 * Return the maximum number of mipmap levels for the given target
1163 * and the dimensions.
1164 * The dimensions are expected not to include the border.
1167 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1174 case GL_TEXTURE_1D_ARRAY
:
1175 case GL_PROXY_TEXTURE_1D
:
1176 case GL_PROXY_TEXTURE_1D_ARRAY
:
1179 case GL_TEXTURE_CUBE_MAP
:
1180 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1181 case GL_PROXY_TEXTURE_CUBE_MAP
:
1182 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1186 case GL_TEXTURE_2D_ARRAY
:
1187 case GL_PROXY_TEXTURE_2D
:
1188 case GL_PROXY_TEXTURE_2D_ARRAY
:
1189 size
= MAX2(width
, height
);
1192 case GL_PROXY_TEXTURE_3D
:
1193 size
= MAX3(width
, height
, depth
);
1195 case GL_TEXTURE_RECTANGLE
:
1196 case GL_TEXTURE_EXTERNAL_OES
:
1197 case GL_TEXTURE_2D_MULTISAMPLE
:
1198 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1199 case GL_PROXY_TEXTURE_RECTANGLE
:
1200 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1201 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1208 return _mesa_logbase2(size
) + 1;
1212 #if 000 /* not used anymore */
1214 * glTexImage[123]D can accept a NULL image pointer. In this case we
1215 * create a texture image with unspecified image contents per the OpenGL
1219 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1221 const GLint components
= _mesa_components_in_format(format
);
1222 const GLint numPixels
= width
* height
* depth
;
1223 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1227 * Let's see if anyone finds this. If glTexImage2D() is called with
1228 * a NULL image pointer then load the texture image with something
1229 * interesting instead of leaving it indeterminate.
1232 static const char message
[8][32] = {
1233 " X X XXXXX XXX X ",
1234 " XX XX X X X X X ",
1236 " X X XXXX XXX XXXXX ",
1239 " X X XXXXX XXX X X ",
1243 GLubyte
*imgPtr
= data
;
1245 for (h
= 0; h
< depth
; h
++) {
1246 for (i
= 0; i
< height
; i
++) {
1247 GLint srcRow
= 7 - (i
% 8);
1248 for (j
= 0; j
< width
; j
++) {
1249 GLint srcCol
= j
% 32;
1250 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1251 for (k
= 0; k
< components
; k
++) {
1267 * Set the size and format-related fields of a gl_texture_image struct
1268 * to zero. This is used when a proxy texture test fails.
1271 clear_teximage_fields(struct gl_texture_image
*img
)
1274 img
->_BaseFormat
= 0;
1275 img
->InternalFormat
= 0;
1284 img
->HeightLog2
= 0;
1286 img
->TexFormat
= MESA_FORMAT_NONE
;
1287 img
->NumSamples
= 0;
1288 img
->FixedSampleLocations
= GL_TRUE
;
1293 * Initialize basic fields of the gl_texture_image struct.
1295 * \param ctx GL context.
1296 * \param img texture image structure to be initialized.
1297 * \param width image width.
1298 * \param height image height.
1299 * \param depth image depth.
1300 * \param border image border.
1301 * \param internalFormat internal format.
1302 * \param format the actual hardware format (one of MESA_FORMAT_*)
1304 * Fills in the fields of \p img with the given information.
1305 * Note: width, height and depth include the border.
1308 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1309 struct gl_texture_image
*img
,
1310 GLsizei width
, GLsizei height
, GLsizei depth
,
1311 GLint border
, GLenum internalFormat
,
1317 ASSERT(height
>= 0);
1320 target
= img
->TexObject
->Target
;
1321 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1322 ASSERT(img
->_BaseFormat
> 0);
1323 img
->InternalFormat
= internalFormat
;
1324 img
->Border
= border
;
1326 img
->Height
= height
;
1329 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1330 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1332 img
->NumSamples
= 0;
1333 img
->FixedSampleLocations
= GL_TRUE
;
1337 case GL_TEXTURE_BUFFER
:
1338 case GL_PROXY_TEXTURE_1D
:
1343 img
->HeightLog2
= 0;
1350 case GL_TEXTURE_1D_ARRAY
:
1351 case GL_PROXY_TEXTURE_1D_ARRAY
:
1352 img
->Height2
= height
; /* no border */
1353 img
->HeightLog2
= 0; /* not used */
1361 case GL_TEXTURE_RECTANGLE
:
1362 case GL_TEXTURE_CUBE_MAP
:
1363 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1364 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1365 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1366 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1367 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1368 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1369 case GL_TEXTURE_EXTERNAL_OES
:
1370 case GL_PROXY_TEXTURE_2D
:
1371 case GL_PROXY_TEXTURE_RECTANGLE
:
1372 case GL_PROXY_TEXTURE_CUBE_MAP
:
1373 case GL_TEXTURE_2D_MULTISAMPLE
:
1374 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1375 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1376 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1383 case GL_TEXTURE_2D_ARRAY
:
1384 case GL_PROXY_TEXTURE_2D_ARRAY
:
1385 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1386 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1387 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1388 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1389 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1390 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1391 img
->Depth2
= depth
; /* no border */
1392 img
->DepthLog2
= 0; /* not used */
1395 case GL_PROXY_TEXTURE_3D
:
1396 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1397 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1398 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1399 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1402 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1407 _mesa_get_tex_max_num_levels(target
,
1408 img
->Width2
, img
->Height2
, img
->Depth2
);
1409 img
->TexFormat
= format
;
1414 * Free and clear fields of the gl_texture_image struct.
1416 * \param ctx GL context.
1417 * \param texImage texture image structure to be cleared.
1419 * After the call, \p texImage will have no data associated with it. Its
1420 * fields are cleared so that its parent object will test incomplete.
1423 _mesa_clear_texture_image(struct gl_context
*ctx
,
1424 struct gl_texture_image
*texImage
)
1426 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1427 clear_teximage_fields(texImage
);
1432 * Check the width, height, depth and border of a texture image are legal.
1433 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1435 * The target and level parameters will have already been validated.
1436 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1439 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1440 GLint level
, GLint width
, GLint height
,
1441 GLint depth
, GLint border
)
1447 case GL_PROXY_TEXTURE_1D
:
1448 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1449 maxSize
>>= level
; /* level size */
1450 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1452 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1453 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1459 case GL_PROXY_TEXTURE_2D
:
1460 case GL_TEXTURE_2D_MULTISAMPLE
:
1461 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1462 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1464 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1466 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1468 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1469 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1471 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1477 case GL_PROXY_TEXTURE_3D
:
1478 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1480 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1482 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1484 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1486 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1487 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1489 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1491 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1496 case GL_TEXTURE_RECTANGLE_NV
:
1497 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1500 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1501 if (width
< 0 || width
> maxSize
)
1503 if (height
< 0 || height
> maxSize
)
1507 case GL_TEXTURE_CUBE_MAP
:
1508 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1509 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1510 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1511 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1512 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1513 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1514 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1515 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1517 if (width
!= height
)
1519 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1521 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1523 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1524 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1526 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1531 case GL_TEXTURE_1D_ARRAY_EXT
:
1532 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1533 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1535 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1537 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1539 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1540 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1545 case GL_TEXTURE_2D_ARRAY_EXT
:
1546 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1547 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1548 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1549 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1551 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1553 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1555 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1557 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1558 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1560 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1565 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1566 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1567 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1568 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1570 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1572 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1574 if (width
!= height
)
1576 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1578 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1579 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1581 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1586 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1593 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1594 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1595 * \param destImage the destination texture image.
1596 * \return GL_TRUE if error found, GL_FALSE otherwise.
1599 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1600 const char *function
, GLuint dims
,
1601 const struct gl_texture_image
*destImage
,
1602 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1603 GLsizei subWidth
, GLsizei subHeight
,
1606 const GLenum target
= destImage
->TexObject
->Target
;
1611 _mesa_error(ctx
, GL_INVALID_VALUE
,
1612 "%s%dD(width=%d)", function
, dims
, subWidth
);
1616 if (dims
> 1 && subHeight
< 0) {
1617 _mesa_error(ctx
, GL_INVALID_VALUE
,
1618 "%s%dD(height=%d)", function
, dims
, subHeight
);
1622 if (dims
> 2 && subDepth
< 0) {
1623 _mesa_error(ctx
, GL_INVALID_VALUE
,
1624 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1628 /* check xoffset and width */
1629 if (xoffset
< - (GLint
) destImage
->Border
) {
1630 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1635 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1636 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1641 /* check yoffset and height */
1643 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1644 if (yoffset
< -yBorder
) {
1645 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1649 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1650 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1656 /* check zoffset and depth */
1658 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1659 if (zoffset
< -zBorder
) {
1660 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1663 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1664 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1670 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1671 * compressed texture images can be updated. But, that restriction may be
1672 * relaxed for particular compressed formats. At this time, all the
1673 * compressed formats supported by Mesa allow sub-textures to be updated
1674 * along compressed block boundaries.
1676 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1678 if (bw
!= 1 || bh
!= 1) {
1679 /* offset must be multiple of block size */
1680 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1681 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1682 "%s%dD(xoffset = %d, yoffset = %d)",
1683 function
, dims
, xoffset
, yoffset
);
1687 /* The size must be a multiple of bw x bh, or we must be using a
1688 * offset+size that exactly hits the edge of the image. This
1689 * is important for small mipmap levels (1x1, 2x1, etc) and for
1692 if ((subWidth
% bw
!= 0) &&
1693 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1694 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1695 "%s%dD(width = %d)", function
, dims
, subWidth
);
1699 if ((subHeight
% bh
!= 0) &&
1700 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1701 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1702 "%s%dD(height = %d)", function
, dims
, subHeight
);
1714 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1715 * specific texture image size checks.
1717 * A hardware driver might override this function if, for example, the
1718 * max 3D texture size is 512x512x64 (i.e. not a cube).
1720 * Note that width, height, depth == 0 is not an error. However, a
1721 * texture with zero width/height/depth will be considered "incomplete"
1722 * and texturing will effectively be disabled.
1724 * \param target any texture target/type
1725 * \param level as passed to glTexImage
1726 * \param format the MESA_FORMAT_x for the tex image
1727 * \param width as passed to glTexImage
1728 * \param height as passed to glTexImage
1729 * \param depth as passed to glTexImage
1730 * \param border as passed to glTexImage
1731 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1734 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1736 GLint width
, GLint height
, GLint depth
, GLint border
)
1738 /* We just check if the image size is less than MaxTextureMbytes.
1739 * Some drivers may do more specific checks.
1741 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1742 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1743 mbytes
*= _mesa_num_tex_faces(target
);
1744 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1749 * Return true if the format is only valid for glCompressedTexImage.
1752 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1755 case GL_ETC1_RGB8_OES
:
1756 case GL_PALETTE4_RGB8_OES
:
1757 case GL_PALETTE4_RGBA8_OES
:
1758 case GL_PALETTE4_R5_G6_B5_OES
:
1759 case GL_PALETTE4_RGBA4_OES
:
1760 case GL_PALETTE4_RGB5_A1_OES
:
1761 case GL_PALETTE8_RGB8_OES
:
1762 case GL_PALETTE8_RGBA8_OES
:
1763 case GL_PALETTE8_R5_G6_B5_OES
:
1764 case GL_PALETTE8_RGBA4_OES
:
1765 case GL_PALETTE8_RGB5_A1_OES
:
1774 * Helper function to determine whether a target and specific compression
1775 * format are supported.
1778 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1781 (void) intFormat
; /* not used yet */
1785 case GL_PROXY_TEXTURE_2D
:
1786 return GL_TRUE
; /* true for any compressed format so far */
1787 case GL_PROXY_TEXTURE_CUBE_MAP
:
1788 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1789 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1790 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1791 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1792 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1793 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1794 return ctx
->Extensions
.ARB_texture_cube_map
;
1795 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1796 case GL_TEXTURE_2D_ARRAY_EXT
:
1797 return ctx
->Extensions
.EXT_texture_array
;
1798 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1799 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1800 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1808 * Check if the given texture target value is legal for a
1809 * glTexImage1/2/3D call.
1812 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1818 case GL_PROXY_TEXTURE_1D
:
1819 return _mesa_is_desktop_gl(ctx
);
1827 case GL_PROXY_TEXTURE_2D
:
1828 return _mesa_is_desktop_gl(ctx
);
1829 case GL_PROXY_TEXTURE_CUBE_MAP
:
1830 return _mesa_is_desktop_gl(ctx
)
1831 && ctx
->Extensions
.ARB_texture_cube_map
;
1832 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1833 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1834 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1835 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1836 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1837 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1838 return ctx
->Extensions
.ARB_texture_cube_map
;
1839 case GL_TEXTURE_RECTANGLE_NV
:
1840 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1841 return _mesa_is_desktop_gl(ctx
)
1842 && ctx
->Extensions
.NV_texture_rectangle
;
1843 case GL_TEXTURE_1D_ARRAY_EXT
:
1844 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1845 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1853 case GL_PROXY_TEXTURE_3D
:
1854 return _mesa_is_desktop_gl(ctx
);
1855 case GL_TEXTURE_2D_ARRAY_EXT
:
1856 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1857 || _mesa_is_gles3(ctx
);
1858 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1859 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1860 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1861 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1862 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1867 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1874 * Check if the given texture target value is legal for a
1875 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1876 * The difference compared to legal_teximage_target() above is that
1877 * proxy targets are not supported.
1880 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1884 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1889 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1890 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1891 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1892 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1893 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1894 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1895 return ctx
->Extensions
.ARB_texture_cube_map
;
1896 case GL_TEXTURE_RECTANGLE_NV
:
1897 return _mesa_is_desktop_gl(ctx
)
1898 && ctx
->Extensions
.NV_texture_rectangle
;
1899 case GL_TEXTURE_1D_ARRAY_EXT
:
1900 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1908 case GL_TEXTURE_2D_ARRAY_EXT
:
1909 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1910 || _mesa_is_gles3(ctx
);
1911 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1912 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1913 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1918 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1926 * Helper function to determine if a texture object is mutable (in terms
1927 * of GL_ARB_texture_storage).
1930 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1932 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1933 return !texObj
->Immutable
;
1938 * Return expected size of a compressed texture.
1941 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1944 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1945 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1949 * Verify that a texture format is valid with a particular target
1951 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1952 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1955 * \param ctx GL context
1956 * \param target Texture target
1957 * \param internalFormat Internal format of the texture image
1958 * \param dimensions Dimensionality at the caller. This is \b not used
1959 * in the validation. It is only used when logging
1961 * \param caller Base name of the calling function (e.g.,
1962 * "glTexImage" or "glTexStorage").
1964 * \returns true if the combination is legal, false otherwise.
1967 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1968 GLenum target
, GLenum internalFormat
,
1969 unsigned dimensions
,
1972 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1973 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
1974 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1975 * Profile spec says:
1977 * "Textures with a base internal format of DEPTH_COMPONENT or
1978 * DEPTH_STENCIL are supported by texture image specification
1979 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1980 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1981 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1982 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1983 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1984 * formats in conjunction with any other target will result in an
1985 * INVALID_OPERATION error."
1987 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1988 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1990 if (target
!= GL_TEXTURE_1D
&&
1991 target
!= GL_PROXY_TEXTURE_1D
&&
1992 target
!= GL_TEXTURE_2D
&&
1993 target
!= GL_PROXY_TEXTURE_2D
&&
1994 target
!= GL_TEXTURE_1D_ARRAY
&&
1995 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1996 target
!= GL_TEXTURE_2D_ARRAY
&&
1997 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1998 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1999 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2000 !((_mesa_is_cube_face(target
) ||
2001 target
== GL_TEXTURE_CUBE_MAP
||
2002 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2003 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2004 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2005 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2006 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2007 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2008 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2009 "%s%dD(bad target for depth texture)",
2010 caller
, dimensions
);
2019 * Test the glTexImage[123]D() parameters for errors.
2021 * \param ctx GL context.
2022 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2023 * \param target texture target given by the user (already validated).
2024 * \param level image level given by the user.
2025 * \param internalFormat internal format given by the user.
2026 * \param format pixel data format given by the user.
2027 * \param type pixel data type given by the user.
2028 * \param width image width given by the user.
2029 * \param height image height given by the user.
2030 * \param depth image depth given by the user.
2031 * \param border image border given by the user.
2033 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2035 * Verifies each of the parameters against the constants specified in
2036 * __struct gl_contextRec::Const and the supported extensions, and according
2037 * to the OpenGL specification.
2038 * Note that we don't fully error-check the width, height, depth values
2039 * here. That's done in _mesa_legal_texture_dimensions() which is used
2040 * by several other GL entrypoints. Plus, texture dims have a special
2041 * interaction with proxy textures.
2044 texture_error_check( struct gl_context
*ctx
,
2045 GLuint dimensions
, GLenum target
,
2046 GLint level
, GLint internalFormat
,
2047 GLenum format
, GLenum type
,
2048 GLint width
, GLint height
,
2049 GLint depth
, GLint border
)
2051 GLboolean colorFormat
;
2054 /* Even though there are no color-index textures, we still have to support
2055 * uploading color-index data and remapping it to RGB via the
2056 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2058 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2060 /* Note: for proxy textures, some error conditions immediately generate
2061 * a GL error in the usual way. But others do not generate a GL error.
2062 * Instead, they cause the width, height, depth, format fields of the
2063 * texture image to be zeroed-out. The GL spec seems to indicate that the
2064 * zero-out behaviour is only used in cases related to memory allocation.
2068 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2069 _mesa_error(ctx
, GL_INVALID_VALUE
,
2070 "glTexImage%dD(level=%d)", dimensions
, level
);
2075 if (border
< 0 || border
> 1 ||
2076 ((ctx
->API
!= API_OPENGL_COMPAT
||
2077 target
== GL_TEXTURE_RECTANGLE_NV
||
2078 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2079 _mesa_error(ctx
, GL_INVALID_VALUE
,
2080 "glTexImage%dD(border=%d)", dimensions
, border
);
2084 if (width
< 0 || height
< 0 || depth
< 0) {
2085 _mesa_error(ctx
, GL_INVALID_VALUE
,
2086 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2090 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2091 * combinations of format, internalFormat, and type that can be used.
2092 * Formats and types that require additional extensions (e.g., GL_FLOAT
2093 * requires GL_OES_texture_float) are filtered elsewhere.
2096 if (_mesa_is_gles(ctx
)) {
2097 if (_mesa_is_gles3(ctx
)) {
2098 err
= _mesa_es3_error_check_format_and_type(format
, type
,
2101 if (format
!= internalFormat
) {
2102 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2103 "glTexImage%dD(format = %s, internalFormat = %s)",
2105 _mesa_lookup_enum_by_nr(format
),
2106 _mesa_lookup_enum_by_nr(internalFormat
));
2110 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2112 if (err
!= GL_NO_ERROR
) {
2113 _mesa_error(ctx
, err
,
2114 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2116 _mesa_lookup_enum_by_nr(format
),
2117 _mesa_lookup_enum_by_nr(type
),
2118 _mesa_lookup_enum_by_nr(internalFormat
));
2123 /* Check internalFormat */
2124 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2125 _mesa_error(ctx
, GL_INVALID_VALUE
,
2126 "glTexImage%dD(internalFormat=%s)",
2127 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2131 /* Check incoming image format and type */
2132 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2133 if (err
!= GL_NO_ERROR
) {
2134 _mesa_error(ctx
, err
,
2135 "glTexImage%dD(incompatible format = %s, type = %s)",
2136 dimensions
, _mesa_lookup_enum_by_nr(format
),
2137 _mesa_lookup_enum_by_nr(type
));
2141 /* make sure internal format and format basically agree */
2142 colorFormat
= _mesa_is_color_format(format
);
2143 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2144 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2145 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2146 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2147 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2148 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2149 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2150 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2151 _mesa_lookup_enum_by_nr(format
));
2155 /* additional checks for ycbcr textures */
2156 if (internalFormat
== GL_YCBCR_MESA
) {
2157 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2158 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2159 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2161 _mesa_snprintf(message
, sizeof(message
),
2162 "glTexImage%dD(format/type YCBCR mismatch)",
2164 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2165 return GL_TRUE
; /* error */
2167 if (target
!= GL_TEXTURE_2D
&&
2168 target
!= GL_PROXY_TEXTURE_2D
&&
2169 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2170 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2171 _mesa_error(ctx
, GL_INVALID_ENUM
,
2172 "glTexImage%dD(bad target for YCbCr texture)",
2178 _mesa_snprintf(message
, sizeof(message
),
2179 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2180 dimensions
, border
);
2181 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2186 /* additional checks for depth textures */
2187 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2188 dimensions
, "glTexImage"))
2191 /* additional checks for compressed textures */
2192 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2193 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2194 _mesa_error(ctx
, GL_INVALID_ENUM
,
2195 "glTexImage%dD(target can't be compressed)", dimensions
);
2198 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2199 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2200 "glTexImage%dD(no compression for format)", dimensions
);
2204 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2205 "glTexImage%dD(border!=0)", dimensions
);
2210 /* additional checks for integer textures */
2211 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2212 (_mesa_is_enum_format_integer(format
) !=
2213 _mesa_is_enum_format_integer(internalFormat
))) {
2214 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2215 "glTexImage%dD(integer/non-integer format mismatch)",
2220 if (!mutable_tex_object(ctx
, target
)) {
2221 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2222 "glTexImage%dD(immutable texture)", dimensions
);
2226 /* if we get here, the parameters are OK */
2232 * Error checking for glCompressedTexImage[123]D().
2233 * Note that the width, height and depth values are not fully error checked
2235 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2238 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2239 GLenum target
, GLint level
,
2240 GLenum internalFormat
, GLsizei width
,
2241 GLsizei height
, GLsizei depth
, GLint border
,
2244 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2246 GLenum error
= GL_NO_ERROR
;
2247 char *reason
= ""; /* no error */
2249 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2251 error
= GL_INVALID_ENUM
;
2255 /* This will detect any invalid internalFormat value */
2256 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2257 reason
= "internalFormat";
2258 error
= GL_INVALID_ENUM
;
2262 switch (internalFormat
) {
2263 case GL_PALETTE4_RGB8_OES
:
2264 case GL_PALETTE4_RGBA8_OES
:
2265 case GL_PALETTE4_R5_G6_B5_OES
:
2266 case GL_PALETTE4_RGBA4_OES
:
2267 case GL_PALETTE4_RGB5_A1_OES
:
2268 case GL_PALETTE8_RGB8_OES
:
2269 case GL_PALETTE8_RGBA8_OES
:
2270 case GL_PALETTE8_R5_G6_B5_OES
:
2271 case GL_PALETTE8_RGBA4_OES
:
2272 case GL_PALETTE8_RGB5_A1_OES
:
2273 /* check level (note that level should be zero or less!) */
2274 if (level
> 0 || level
< -maxLevels
) {
2276 error
= GL_INVALID_VALUE
;
2280 if (dimensions
!= 2) {
2281 reason
= "compressed paletted textures must be 2D";
2282 error
= GL_INVALID_OPERATION
;
2286 /* Figure out the expected texture size (in bytes). This will be
2287 * checked against the actual size later.
2289 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2292 /* This is for the benefit of the TestProxyTexImage below. It expects
2293 * level to be non-negative. OES_compressed_paletted_texture uses a
2294 * weird mechanism where the level specified to glCompressedTexImage2D
2295 * is -(n-1) number of levels in the texture, and the data specifies the
2296 * complete mipmap stack. This is done to ensure the palette is the
2297 * same for all levels.
2304 if (level
< 0 || level
>= maxLevels
) {
2306 error
= GL_INVALID_VALUE
;
2310 /* Figure out the expected texture size (in bytes). This will be
2311 * checked against the actual size later.
2313 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2317 /* This should really never fail */
2318 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2319 reason
= "internalFormat";
2320 error
= GL_INVALID_ENUM
;
2324 /* No compressed formats support borders at this time */
2326 reason
= "border != 0";
2327 error
= GL_INVALID_VALUE
;
2331 /* check image size in bytes */
2332 if (expectedSize
!= imageSize
) {
2333 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2334 * if <imageSize> is not consistent with the format, dimensions, and
2335 * contents of the specified image.
2337 reason
= "imageSize inconsistant with width/height/format";
2338 error
= GL_INVALID_VALUE
;
2342 if (!mutable_tex_object(ctx
, target
)) {
2343 reason
= "immutable texture";
2344 error
= GL_INVALID_OPERATION
;
2351 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2358 * Test glTexSubImage[123]D() parameters for errors.
2360 * \param ctx GL context.
2361 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2362 * \param target texture target given by the user (already validated)
2363 * \param level image level given by the user.
2364 * \param xoffset sub-image x offset given by the user.
2365 * \param yoffset sub-image y offset given by the user.
2366 * \param zoffset sub-image z offset given by the user.
2367 * \param format pixel data format given by the user.
2368 * \param type pixel data type given by the user.
2369 * \param width image width given by the user.
2370 * \param height image height given by the user.
2371 * \param depth image depth given by the user.
2373 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2375 * Verifies each of the parameters against the constants specified in
2376 * __struct gl_contextRec::Const and the supported extensions, and according
2377 * to the OpenGL specification.
2380 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2381 GLenum target
, GLint level
,
2382 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2383 GLint width
, GLint height
, GLint depth
,
2384 GLenum format
, GLenum type
)
2386 struct gl_texture_object
*texObj
;
2387 struct gl_texture_image
*texImage
;
2390 /* check target (proxies not allowed) */
2391 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2392 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2393 dimensions
, _mesa_lookup_enum_by_nr(target
));
2398 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2399 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2404 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2405 * combinations of format and type that can be used. Formats and types
2406 * that require additional extensions (e.g., GL_FLOAT requires
2407 * GL_OES_texture_float) are filtered elsewhere.
2409 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2410 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2411 if (err
!= GL_NO_ERROR
) {
2412 _mesa_error(ctx
, err
,
2413 "glTexSubImage%dD(format = %s, type = %s)",
2415 _mesa_lookup_enum_by_nr(format
),
2416 _mesa_lookup_enum_by_nr(type
));
2421 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2422 if (err
!= GL_NO_ERROR
) {
2423 _mesa_error(ctx
, err
,
2424 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2425 dimensions
, _mesa_lookup_enum_by_nr(format
),
2426 _mesa_lookup_enum_by_nr(type
));
2430 /* Get dest texture object / image pointers */
2431 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2433 /* must be out of memory */
2434 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2438 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2440 /* non-existant texture level */
2441 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2442 "glTexSubImage%dD(invalid texture image)", dimensions
);
2446 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2447 texImage
, xoffset
, yoffset
, 0,
2448 width
, height
, 1)) {
2452 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2453 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2454 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2455 "glTexSubImage%dD(no compression for format)", dimensions
);
2460 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2461 /* both source and dest must be integer-valued, or neither */
2462 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2463 _mesa_is_enum_format_integer(format
)) {
2464 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2465 "glTexSubImage%dD(integer/non-integer format mismatch)",
2476 * Test glCopyTexImage[12]D() parameters for errors.
2478 * \param ctx GL context.
2479 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2480 * \param target texture target given by the user.
2481 * \param level image level given by the user.
2482 * \param internalFormat internal format given by the user.
2483 * \param width image width given by the user.
2484 * \param height image height given by the user.
2485 * \param border texture border.
2487 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2489 * Verifies each of the parameters against the constants specified in
2490 * __struct gl_contextRec::Const and the supported extensions, and according
2491 * to the OpenGL specification.
2494 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2495 GLenum target
, GLint level
, GLint internalFormat
,
2496 GLint width
, GLint height
, GLint border
)
2499 GLint rb_base_format
;
2500 struct gl_renderbuffer
*rb
;
2501 GLenum rb_internal_format
;
2504 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2505 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2506 dimensions
, _mesa_lookup_enum_by_nr(target
));
2511 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2512 _mesa_error(ctx
, GL_INVALID_VALUE
,
2513 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2517 /* Check that the source buffer is complete */
2518 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2519 if (ctx
->ReadBuffer
->_Status
== 0) {
2520 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2522 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2523 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2524 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2528 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2529 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2530 "glCopyTexImage%dD(multisample FBO)",
2537 if (border
< 0 || border
> 1 ||
2538 ((ctx
->API
!= API_OPENGL_COMPAT
||
2539 target
== GL_TEXTURE_RECTANGLE_NV
||
2540 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2541 _mesa_error(ctx
, GL_INVALID_VALUE
,
2542 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2546 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2548 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2549 "glCopyTexImage%dD(read buffer)", dimensions
);
2553 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2556 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2557 switch (internalFormat
) {
2562 case GL_LUMINANCE_ALPHA
:
2565 _mesa_error(ctx
, GL_INVALID_VALUE
,
2566 "glCopyTexImage%dD(internalFormat)", dimensions
);
2571 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2572 if (baseFormat
< 0) {
2573 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2574 "glCopyTexImage%dD(internalFormat)", dimensions
);
2578 rb_internal_format
= rb
->InternalFormat
;
2579 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2580 if (_mesa_is_color_format(internalFormat
)) {
2581 if (rb_base_format
< 0) {
2582 _mesa_error(ctx
, GL_INVALID_VALUE
,
2583 "glCopyTexImage%dD(internalFormat)", dimensions
);
2588 if (_mesa_is_gles(ctx
)) {
2590 if (_mesa_base_format_component_count(baseFormat
) >
2591 _mesa_base_format_component_count(rb_base_format
)) {
2594 if (baseFormat
== GL_DEPTH_COMPONENT
||
2595 baseFormat
== GL_DEPTH_STENCIL
||
2596 rb_base_format
== GL_DEPTH_COMPONENT
||
2597 rb_base_format
== GL_DEPTH_STENCIL
||
2598 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2599 baseFormat
== GL_ALPHA
) &&
2600 rb_base_format
!= GL_RGBA
) ||
2601 internalFormat
== GL_RGB9_E5
) {
2604 if (internalFormat
== GL_RGB9_E5
) {
2608 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2609 "glCopyTexImage%dD(internalFormat)", dimensions
);
2614 if (_mesa_is_gles3(ctx
)) {
2615 bool rb_is_srgb
= false;
2616 bool dst_is_srgb
= false;
2618 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2619 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2623 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2627 if (rb_is_srgb
!= dst_is_srgb
) {
2628 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2629 * OpenGLES 3.0.0 spec says:
2631 * "The error INVALID_OPERATION is also generated if the
2632 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2633 * framebuffer attachment corresponding to the read buffer
2634 * is LINEAR (see section 6.1.13) and internalformat is
2635 * one of the sRGB formats described in section 3.8.16, or
2636 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2637 * SRGB and internalformat is not one of the sRGB formats."
2639 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2640 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2645 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2646 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2647 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2651 /* From the EXT_texture_integer spec:
2653 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2654 * if the texture internalformat is an integer format and the read color
2655 * buffer is not an integer format, or if the internalformat is not an
2656 * integer format and the read color buffer is an integer format."
2658 if (_mesa_is_color_format(internalFormat
)) {
2659 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2660 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2661 if (is_int
|| is_rbint
) {
2662 if (is_int
!= is_rbint
) {
2663 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2664 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2666 } else if (_mesa_is_gles(ctx
) &&
2667 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2668 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2669 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2670 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2676 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2677 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2678 _mesa_error(ctx
, GL_INVALID_ENUM
,
2679 "glCopyTexImage%dD(target)", dimensions
);
2682 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2683 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2684 "glCopyTexImage%dD(no compression for format)", dimensions
);
2688 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2689 "glCopyTexImage%dD(border!=0)", dimensions
);
2694 if (!mutable_tex_object(ctx
, target
)) {
2695 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2696 "glCopyTexImage%dD(immutable texture)", dimensions
);
2700 /* if we get here, the parameters are OK */
2706 * Test glCopyTexSubImage[12]D() parameters for errors.
2707 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2710 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2711 GLenum target
, GLint level
,
2712 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2713 GLint width
, GLint height
)
2715 struct gl_texture_object
*texObj
;
2716 struct gl_texture_image
*texImage
;
2718 /* Check that the source buffer is complete */
2719 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2720 if (ctx
->ReadBuffer
->_Status
== 0) {
2721 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2723 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2724 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2725 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2729 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2730 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2731 "glCopyTexSubImage%dD(multisample FBO)",
2737 /* check target (proxies not allowed) */
2738 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2739 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2740 dimensions
, _mesa_lookup_enum_by_nr(target
));
2745 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2746 _mesa_error(ctx
, GL_INVALID_VALUE
,
2747 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2751 /* Get dest texture object / image pointers */
2752 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2754 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2758 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2760 /* destination image does not exist */
2761 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2762 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2766 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2767 dimensions
, texImage
,
2768 xoffset
, yoffset
, zoffset
,
2769 width
, height
, 1)) {
2773 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2774 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2775 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2776 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2781 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2782 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2786 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2787 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2788 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2789 dimensions
, texImage
->_BaseFormat
);
2793 /* From the EXT_texture_integer spec:
2795 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2796 * if the texture internalformat is an integer format and the read color
2797 * buffer is not an integer format, or if the internalformat is not an
2798 * integer format and the read color buffer is an integer format."
2800 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2801 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2803 if (_mesa_is_format_integer_color(rb
->Format
) !=
2804 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2805 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2806 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2811 /* if we get here, the parameters are OK */
2816 /** Callback info for walking over FBO hash table */
2819 struct gl_context
*ctx
;
2820 struct gl_texture_object
*texObj
;
2826 * Check render to texture callback. Called from _mesa_HashWalk().
2829 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2831 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2832 const struct cb_info
*info
= (struct cb_info
*) userData
;
2833 struct gl_context
*ctx
= info
->ctx
;
2834 const struct gl_texture_object
*texObj
= info
->texObj
;
2835 const GLuint level
= info
->level
, face
= info
->face
;
2837 /* If this is a user-created FBO */
2838 if (_mesa_is_user_fbo(fb
)) {
2840 /* check if any of the FBO's attachments point to 'texObj' */
2841 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2842 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2843 if (att
->Type
== GL_TEXTURE
&&
2844 att
->Texture
== texObj
&&
2845 att
->TextureLevel
== level
&&
2846 att
->CubeMapFace
== face
) {
2847 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2848 ASSERT(att
->Renderbuffer
->TexImage
);
2849 /* Mark fb status as indeterminate to force re-validation */
2858 * When a texture image is specified we have to check if it's bound to
2859 * any framebuffer objects (render to texture) in order to detect changes
2860 * in size or format since that effects FBO completeness.
2861 * Any FBOs rendering into the texture must be re-validated.
2864 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2865 struct gl_texture_object
*texObj
,
2866 GLuint face
, GLuint level
)
2868 /* Only check this texture if it's been marked as RenderToTexture */
2869 if (texObj
->_RenderToTexture
) {
2870 struct cb_info info
;
2872 info
.texObj
= texObj
;
2875 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2881 * If the texture object's GenerateMipmap flag is set and we've
2882 * changed the texture base level image, regenerate the rest of the
2883 * mipmap levels now.
2886 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2887 struct gl_texture_object
*texObj
, GLint level
)
2889 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2890 if (texObj
->GenerateMipmap
&&
2891 level
== texObj
->BaseLevel
&&
2892 level
< texObj
->MaxLevel
) {
2893 ASSERT(ctx
->Driver
.GenerateMipmap
);
2894 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2899 /** Debug helper: override the user-requested internal format */
2901 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2904 if (internalFormat
== GL_RGBA16F_ARB
||
2905 internalFormat
== GL_RGBA32F_ARB
) {
2906 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2909 else if (internalFormat
== GL_RGB16F_ARB
||
2910 internalFormat
== GL_RGB32F_ARB
) {
2911 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2914 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2915 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2916 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2917 return GL_LUMINANCE_ALPHA
;
2919 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2920 internalFormat
== GL_LUMINANCE32F_ARB
) {
2921 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2922 return GL_LUMINANCE
;
2924 else if (internalFormat
== GL_ALPHA16F_ARB
||
2925 internalFormat
== GL_ALPHA32F_ARB
) {
2926 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2930 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2931 internalFormat = GL_RGBA;
2935 return internalFormat
;
2938 return internalFormat
;
2944 * Choose the actual hardware format for a texture image.
2945 * Try to use the same format as the previous image level when possible.
2946 * Otherwise, ask the driver for the best format.
2947 * It's important to try to choose a consistant format for all levels
2948 * for efficient texture memory layout/allocation. In particular, this
2949 * comes up during automatic mipmap generation.
2952 _mesa_choose_texture_format(struct gl_context
*ctx
,
2953 struct gl_texture_object
*texObj
,
2954 GLenum target
, GLint level
,
2955 GLenum internalFormat
, GLenum format
, GLenum type
)
2959 /* see if we've already chosen a format for the previous level */
2961 struct gl_texture_image
*prevImage
=
2962 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2963 /* See if the prev level is defined and has an internal format which
2964 * matches the new internal format.
2967 prevImage
->Width
> 0 &&
2968 prevImage
->InternalFormat
== internalFormat
) {
2969 /* use the same format */
2970 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2971 return prevImage
->TexFormat
;
2975 /* If the application requested compression to an S3TC format but we don't
2976 * have the DXTn library, force a generic compressed format instead.
2978 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2979 const GLenum before
= internalFormat
;
2981 switch (internalFormat
) {
2982 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2983 if (!ctx
->Mesa_DXTn
)
2984 internalFormat
= GL_COMPRESSED_RGB
;
2986 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2987 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2988 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2989 if (!ctx
->Mesa_DXTn
)
2990 internalFormat
= GL_COMPRESSED_RGBA
;
2996 if (before
!= internalFormat
) {
2998 "DXT compression requested (%s), "
2999 "but libtxc_dxtn library not installed. Using %s "
3001 _mesa_lookup_enum_by_nr(before
),
3002 _mesa_lookup_enum_by_nr(internalFormat
));
3006 /* choose format from scratch */
3007 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
3009 ASSERT(f
!= MESA_FORMAT_NONE
);
3015 * Adjust pixel unpack params and image dimensions to strip off the
3016 * one-pixel texture border.
3018 * Gallium and intel don't support texture borders. They've seldem been used
3019 * and seldom been implemented correctly anyway.
3021 * \param unpackNew returns the new pixel unpack parameters
3024 strip_texture_border(GLenum target
,
3025 GLint
*width
, GLint
*height
, GLint
*depth
,
3026 const struct gl_pixelstore_attrib
*unpack
,
3027 struct gl_pixelstore_attrib
*unpackNew
)
3033 *unpackNew
= *unpack
;
3035 if (unpackNew
->RowLength
== 0)
3036 unpackNew
->RowLength
= *width
;
3038 if (unpackNew
->ImageHeight
== 0)
3039 unpackNew
->ImageHeight
= *height
;
3041 assert(*width
>= 3);
3042 unpackNew
->SkipPixels
++; /* skip the border */
3043 *width
= *width
- 2; /* reduce the width by two border pixels */
3045 /* The min height of a texture with a border is 3 */
3046 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3047 unpackNew
->SkipRows
++; /* skip the border */
3048 *height
= *height
- 2; /* reduce the height by two border pixels */
3052 target
!= GL_TEXTURE_2D_ARRAY
&&
3053 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3054 unpackNew
->SkipImages
++; /* skip the border */
3055 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3061 * Common code to implement all the glTexImage1D/2D/3D functions
3062 * as well as glCompressedTexImage1D/2D/3D.
3063 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3064 * \param format the user's image format (only used if !compressed)
3065 * \param type the user's image type (only used if !compressed)
3066 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3069 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3070 GLenum target
, GLint level
, GLint internalFormat
,
3071 GLsizei width
, GLsizei height
, GLsizei depth
,
3072 GLint border
, GLenum format
, GLenum type
,
3073 GLsizei imageSize
, const GLvoid
*pixels
)
3075 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3076 struct gl_pixelstore_attrib unpack_no_border
;
3077 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3078 struct gl_texture_object
*texObj
;
3079 mesa_format texFormat
;
3080 GLboolean dimensionsOK
, sizeOK
;
3082 FLUSH_VERTICES(ctx
, 0);
3084 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3087 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3089 _mesa_lookup_enum_by_nr(target
), level
,
3090 _mesa_lookup_enum_by_nr(internalFormat
),
3091 width
, height
, depth
, border
, pixels
);
3094 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3096 _mesa_lookup_enum_by_nr(target
), level
,
3097 _mesa_lookup_enum_by_nr(internalFormat
),
3098 width
, height
, depth
, border
,
3099 _mesa_lookup_enum_by_nr(format
),
3100 _mesa_lookup_enum_by_nr(type
), pixels
);
3103 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3105 /* target error checking */
3106 if (!legal_teximage_target(ctx
, dims
, target
)) {
3107 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3108 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3112 /* general error checking */
3114 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3116 width
, height
, depth
,
3121 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3122 format
, type
, width
, height
, depth
, border
))
3126 /* Here we convert a cpal compressed image into a regular glTexImage2D
3127 * call by decompressing the texture. If we really want to support cpal
3128 * textures in any driver this would have to be changed.
3130 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3131 switch (internalFormat
) {
3132 case GL_PALETTE4_RGB8_OES
:
3133 case GL_PALETTE4_RGBA8_OES
:
3134 case GL_PALETTE4_R5_G6_B5_OES
:
3135 case GL_PALETTE4_RGBA4_OES
:
3136 case GL_PALETTE4_RGB5_A1_OES
:
3137 case GL_PALETTE8_RGB8_OES
:
3138 case GL_PALETTE8_RGBA8_OES
:
3139 case GL_PALETTE8_R5_G6_B5_OES
:
3140 case GL_PALETTE8_RGBA4_OES
:
3141 case GL_PALETTE8_RGB5_A1_OES
:
3142 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3143 width
, height
, imageSize
, pixels
);
3148 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3152 /* For glCompressedTexImage() the driver has no choice about the
3153 * texture format since we'll never transcode the user's compressed
3154 * image data. The internalFormat was error checked earlier.
3156 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3159 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3160 internalFormat
, format
, type
);
3163 assert(texFormat
!= MESA_FORMAT_NONE
);
3165 /* check that width, height, depth are legal for the mipmap level */
3166 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3167 height
, depth
, border
);
3169 /* check that the texture won't take too much memory, etc */
3170 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3172 width
, height
, depth
, border
);
3174 if (_mesa_is_proxy_texture(target
)) {
3175 /* Proxy texture: just clear or set state depending on error checking */
3176 struct gl_texture_image
*texImage
=
3177 get_proxy_tex_image(ctx
, target
, level
);
3180 return; /* GL_OUT_OF_MEMORY already recorded */
3182 if (dimensionsOK
&& sizeOK
) {
3183 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3184 border
, internalFormat
, texFormat
);
3187 clear_teximage_fields(texImage
);
3191 /* non-proxy target */
3192 const GLuint face
= _mesa_tex_target_to_face(target
);
3193 struct gl_texture_image
*texImage
;
3195 if (!dimensionsOK
) {
3196 _mesa_error(ctx
, GL_INVALID_VALUE
,
3197 "glTexImage%uD(invalid width or height or depth)",
3203 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3204 "glTexImage%uD(image too large)", dims
);
3208 /* Allow a hardware driver to just strip out the border, to provide
3209 * reliable but slightly incorrect hardware rendering instead of
3210 * rarely-tested software fallback rendering.
3212 if (border
&& ctx
->Const
.StripTextureBorder
) {
3213 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3216 unpack
= &unpack_no_border
;
3219 if (ctx
->NewState
& _NEW_PIXEL
)
3220 _mesa_update_state(ctx
);
3222 _mesa_lock_texture(ctx
, texObj
);
3224 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3227 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3230 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3232 _mesa_init_teximage_fields(ctx
, texImage
,
3233 width
, height
, depth
,
3234 border
, internalFormat
, texFormat
);
3236 /* Give the texture to the driver. <pixels> may be null. */
3237 if (width
> 0 && height
> 0 && depth
> 0) {
3239 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3243 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3244 type
, pixels
, unpack
);
3248 check_gen_mipmap(ctx
, target
, texObj
, level
);
3250 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3252 _mesa_dirty_texobj(ctx
, texObj
);
3255 _mesa_unlock_texture(ctx
, texObj
);
3262 * Called from the API. Note that width includes the border.
3265 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3266 GLsizei width
, GLint border
, GLenum format
,
3267 GLenum type
, const GLvoid
*pixels
)
3269 GET_CURRENT_CONTEXT(ctx
);
3270 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3271 border
, format
, type
, 0, pixels
);
3276 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3277 GLsizei width
, GLsizei height
, GLint border
,
3278 GLenum format
, GLenum type
,
3279 const GLvoid
*pixels
)
3281 GET_CURRENT_CONTEXT(ctx
);
3282 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3283 border
, format
, type
, 0, pixels
);
3288 * Called by the API or display list executor.
3289 * Note that width and height include the border.
3292 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3293 GLsizei width
, GLsizei height
, GLsizei depth
,
3294 GLint border
, GLenum format
, GLenum type
,
3295 const GLvoid
*pixels
)
3297 GET_CURRENT_CONTEXT(ctx
);
3298 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3299 width
, height
, depth
,
3300 border
, format
, type
, 0, pixels
);
3305 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3306 GLsizei width
, GLsizei height
, GLsizei depth
,
3307 GLint border
, GLenum format
, GLenum type
,
3308 const GLvoid
*pixels
)
3310 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3311 depth
, border
, format
, type
, pixels
);
3316 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3318 struct gl_texture_object
*texObj
;
3319 struct gl_texture_image
*texImage
;
3321 GET_CURRENT_CONTEXT(ctx
);
3322 FLUSH_VERTICES(ctx
, 0);
3326 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3328 case GL_TEXTURE_EXTERNAL_OES
:
3330 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3333 valid_target
= false;
3337 if (!valid_target
) {
3338 _mesa_error(ctx
, GL_INVALID_ENUM
,
3339 "glEGLImageTargetTexture2D(target=%d)", target
);
3344 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3345 "glEGLImageTargetTexture2D(image=%p)", image
);
3349 if (ctx
->NewState
& _NEW_PIXEL
)
3350 _mesa_update_state(ctx
);
3352 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3353 _mesa_lock_texture(ctx
, texObj
);
3355 if (texObj
->Immutable
) {
3356 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3357 "glEGLImageTargetTexture2D(texture is immutable)");
3358 _mesa_unlock_texture(ctx
, texObj
);
3362 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3364 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3366 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3368 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3369 texObj
, texImage
, image
);
3371 _mesa_dirty_texobj(ctx
, texObj
);
3373 _mesa_unlock_texture(ctx
, texObj
);
3380 * Implement all the glTexSubImage1/2/3D() functions.
3383 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3384 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3385 GLsizei width
, GLsizei height
, GLsizei depth
,
3386 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3388 struct gl_texture_object
*texObj
;
3389 struct gl_texture_image
*texImage
;
3391 FLUSH_VERTICES(ctx
, 0);
3393 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3394 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3396 _mesa_lookup_enum_by_nr(target
), level
,
3397 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3398 _mesa_lookup_enum_by_nr(format
),
3399 _mesa_lookup_enum_by_nr(type
), pixels
);
3401 /* check target (proxies not allowed) */
3402 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3403 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3404 dims
, _mesa_lookup_enum_by_nr(target
));
3408 if (ctx
->NewState
& _NEW_PIXEL
)
3409 _mesa_update_state(ctx
);
3411 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3412 xoffset
, yoffset
, zoffset
,
3413 width
, height
, depth
, format
, type
)) {
3414 return; /* error was detected */
3417 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3419 _mesa_lock_texture(ctx
, texObj
);
3421 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3423 if (width
> 0 && height
> 0 && depth
> 0) {
3424 /* If we have a border, offset=-1 is legal. Bias by border width. */
3427 if (target
!= GL_TEXTURE_2D_ARRAY
)
3428 zoffset
+= texImage
->Border
;
3431 if (target
!= GL_TEXTURE_1D_ARRAY
)
3432 yoffset
+= texImage
->Border
;
3435 xoffset
+= texImage
->Border
;
3438 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3439 xoffset
, yoffset
, zoffset
,
3440 width
, height
, depth
,
3441 format
, type
, pixels
, &ctx
->Unpack
);
3443 check_gen_mipmap(ctx
, target
, texObj
, level
);
3445 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3446 * the texel data, not the texture format, size, etc.
3450 _mesa_unlock_texture(ctx
, texObj
);
3455 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3456 GLint xoffset
, GLsizei width
,
3457 GLenum format
, GLenum type
,
3458 const GLvoid
*pixels
)
3460 GET_CURRENT_CONTEXT(ctx
);
3461 texsubimage(ctx
, 1, target
, level
,
3464 format
, type
, pixels
);
3469 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3470 GLint xoffset
, GLint yoffset
,
3471 GLsizei width
, GLsizei height
,
3472 GLenum format
, GLenum type
,
3473 const GLvoid
*pixels
)
3475 GET_CURRENT_CONTEXT(ctx
);
3476 texsubimage(ctx
, 2, target
, level
,
3477 xoffset
, yoffset
, 0,
3479 format
, type
, pixels
);
3485 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3486 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3487 GLsizei width
, GLsizei height
, GLsizei depth
,
3488 GLenum format
, GLenum type
,
3489 const GLvoid
*pixels
)
3491 GET_CURRENT_CONTEXT(ctx
);
3492 texsubimage(ctx
, 3, target
, level
,
3493 xoffset
, yoffset
, zoffset
,
3494 width
, height
, depth
,
3495 format
, type
, pixels
);
3501 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3502 * from. This depends on whether the texture contains color or depth values.
3504 static struct gl_renderbuffer
*
3505 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3507 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3508 /* reading from depth/stencil buffer */
3509 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3512 /* copying from color buffer */
3513 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3518 copytexsubimage_by_slice(struct gl_context
*ctx
,
3519 struct gl_texture_image
*texImage
,
3521 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3522 struct gl_renderbuffer
*rb
,
3524 GLsizei width
, GLsizei height
)
3526 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3529 /* For 1D arrays, we copy each scanline of the source rectangle into the
3532 assert(zoffset
== 0);
3534 for (slice
= 0; slice
< height
; slice
++) {
3535 assert(yoffset
+ slice
< texImage
->Height
);
3536 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3537 xoffset
, 0, yoffset
+ slice
,
3538 rb
, x
, y
+ slice
, width
, 1);
3541 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3542 xoffset
, yoffset
, zoffset
,
3543 rb
, x
, y
, width
, height
);
3549 * Implement the glCopyTexImage1/2D() functions.
3552 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3553 GLenum target
, GLint level
, GLenum internalFormat
,
3554 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3556 struct gl_texture_object
*texObj
;
3557 struct gl_texture_image
*texImage
;
3558 const GLuint face
= _mesa_tex_target_to_face(target
);
3559 mesa_format texFormat
;
3561 FLUSH_VERTICES(ctx
, 0);
3563 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3564 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3566 _mesa_lookup_enum_by_nr(target
), level
,
3567 _mesa_lookup_enum_by_nr(internalFormat
),
3568 x
, y
, width
, height
, border
);
3570 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3571 _mesa_update_state(ctx
);
3573 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3574 width
, height
, border
))
3577 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3579 _mesa_error(ctx
, GL_INVALID_VALUE
,
3580 "glCopyTexImage%uD(invalid width or height)", dims
);
3584 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3587 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3588 internalFormat
, GL_NONE
, GL_NONE
);
3589 assert(texFormat
!= MESA_FORMAT_NONE
);
3591 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3593 width
, height
, 1, border
)) {
3594 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3595 "glCopyTexImage%uD(image too large)", dims
);
3599 if (border
&& ctx
->Const
.StripTextureBorder
) {
3601 width
-= border
* 2;
3604 height
-= border
* 2;
3609 _mesa_lock_texture(ctx
, texObj
);
3611 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3614 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3617 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3619 /* Free old texture image */
3620 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3622 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3623 border
, internalFormat
, texFormat
);
3625 if (width
&& height
) {
3626 /* Allocate texture memory (no pixel data yet) */
3627 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3629 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3631 struct gl_renderbuffer
*srcRb
=
3632 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3634 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3636 srcRb
, srcX
, srcY
, width
, height
);
3639 check_gen_mipmap(ctx
, target
, texObj
, level
);
3642 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3644 _mesa_dirty_texobj(ctx
, texObj
);
3647 _mesa_unlock_texture(ctx
, texObj
);
3653 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3654 GLenum internalFormat
,
3656 GLsizei width
, GLint border
)
3658 GET_CURRENT_CONTEXT(ctx
);
3659 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3665 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3666 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3669 GET_CURRENT_CONTEXT(ctx
);
3670 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3671 x
, y
, width
, height
, border
);
3677 * Implementation for glCopyTexSubImage1/2/3D() functions.
3680 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3681 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3682 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3684 struct gl_texture_object
*texObj
;
3685 struct gl_texture_image
*texImage
;
3687 FLUSH_VERTICES(ctx
, 0);
3689 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3690 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3692 _mesa_lookup_enum_by_nr(target
),
3693 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3695 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3696 _mesa_update_state(ctx
);
3698 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3699 xoffset
, yoffset
, zoffset
, width
, height
)) {
3703 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3705 _mesa_lock_texture(ctx
, texObj
);
3707 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3709 /* If we have a border, offset=-1 is legal. Bias by border width. */
3712 if (target
!= GL_TEXTURE_2D_ARRAY
)
3713 zoffset
+= texImage
->Border
;
3716 if (target
!= GL_TEXTURE_1D_ARRAY
)
3717 yoffset
+= texImage
->Border
;
3720 xoffset
+= texImage
->Border
;
3723 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3725 struct gl_renderbuffer
*srcRb
=
3726 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3728 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3729 xoffset
, yoffset
, zoffset
,
3730 srcRb
, x
, y
, width
, height
);
3732 check_gen_mipmap(ctx
, target
, texObj
, level
);
3734 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3735 * the texel data, not the texture format, size, etc.
3739 _mesa_unlock_texture(ctx
, texObj
);
3744 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3745 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3747 GET_CURRENT_CONTEXT(ctx
);
3748 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3754 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3755 GLint xoffset
, GLint yoffset
,
3756 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3758 GET_CURRENT_CONTEXT(ctx
);
3759 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3766 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3767 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3768 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3770 GET_CURRENT_CONTEXT(ctx
);
3771 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3772 x
, y
, width
, height
);
3778 /**********************************************************************/
3779 /****** Compressed Textures ******/
3780 /**********************************************************************/
3784 * Error checking for glCompressedTexSubImage[123]D().
3785 * \return error code or GL_NO_ERROR.
3788 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3789 GLenum target
, GLint level
,
3790 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3791 GLsizei width
, GLsizei height
, GLsizei depth
,
3792 GLenum format
, GLsizei imageSize
)
3794 struct gl_texture_object
*texObj
;
3795 struct gl_texture_image
*texImage
;
3803 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3804 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3805 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3806 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3807 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3808 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3812 targetOK
= GL_FALSE
;
3817 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3821 /* no 1D compressed textures at this time */
3822 targetOK
= GL_FALSE
;
3827 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3832 /* this will catch any invalid compressed format token */
3833 if (!_mesa_is_compressed_format(ctx
, format
)) {
3834 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3839 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3840 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3845 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3846 if (expectedSize
!= imageSize
) {
3847 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3852 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3854 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3855 "glCompressedTexSubImage%uD()", dims
);
3859 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3861 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3862 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3866 if ((GLint
) format
!= texImage
->InternalFormat
) {
3867 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3868 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3872 if (compressedteximage_only_format(ctx
, format
)) {
3873 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3874 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3879 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3880 texImage
, xoffset
, yoffset
, zoffset
,
3881 width
, height
, depth
)) {
3890 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3891 GLenum internalFormat
, GLsizei width
,
3892 GLint border
, GLsizei imageSize
,
3895 GET_CURRENT_CONTEXT(ctx
);
3896 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3897 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3902 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3903 GLenum internalFormat
, GLsizei width
,
3904 GLsizei height
, GLint border
, GLsizei imageSize
,
3907 GET_CURRENT_CONTEXT(ctx
);
3908 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3909 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3914 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3915 GLenum internalFormat
, GLsizei width
,
3916 GLsizei height
, GLsizei depth
, GLint border
,
3917 GLsizei imageSize
, const GLvoid
*data
)
3919 GET_CURRENT_CONTEXT(ctx
);
3920 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3921 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3926 * Common helper for glCompressedTexSubImage1/2/3D().
3929 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3930 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3931 GLsizei width
, GLsizei height
, GLsizei depth
,
3932 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3934 struct gl_texture_object
*texObj
;
3935 struct gl_texture_image
*texImage
;
3936 GET_CURRENT_CONTEXT(ctx
);
3937 FLUSH_VERTICES(ctx
, 0);
3939 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3940 xoffset
, yoffset
, zoffset
,
3941 width
, height
, depth
,
3942 format
, imageSize
)) {
3946 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3948 _mesa_lock_texture(ctx
, texObj
);
3950 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3953 if (width
> 0 && height
> 0 && depth
> 0) {
3954 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3955 xoffset
, yoffset
, zoffset
,
3956 width
, height
, depth
,
3957 format
, imageSize
, data
);
3959 check_gen_mipmap(ctx
, target
, texObj
, level
);
3961 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3962 * the texel data, not the texture format, size, etc.
3966 _mesa_unlock_texture(ctx
, texObj
);
3971 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3972 GLsizei width
, GLenum format
,
3973 GLsizei imageSize
, const GLvoid
*data
)
3975 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3976 format
, imageSize
, data
);
3981 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3982 GLint yoffset
, GLsizei width
, GLsizei height
,
3983 GLenum format
, GLsizei imageSize
,
3986 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3987 width
, height
, 1, format
, imageSize
, data
);
3992 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3993 GLint yoffset
, GLint zoffset
, GLsizei width
,
3994 GLsizei height
, GLsizei depth
, GLenum format
,
3995 GLsizei imageSize
, const GLvoid
*data
)
3997 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3998 width
, height
, depth
, format
, imageSize
, data
);
4002 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4004 if (ctx
->API
!= API_OPENGL_CORE
) {
4005 switch (internalFormat
) {
4007 return MESA_FORMAT_A_UNORM8
;
4009 return MESA_FORMAT_A_UNORM16
;
4010 case GL_ALPHA16F_ARB
:
4011 return MESA_FORMAT_A_FLOAT16
;
4012 case GL_ALPHA32F_ARB
:
4013 return MESA_FORMAT_A_FLOAT32
;
4014 case GL_ALPHA8I_EXT
:
4015 return MESA_FORMAT_A_SINT8
;
4016 case GL_ALPHA16I_EXT
:
4017 return MESA_FORMAT_A_SINT16
;
4018 case GL_ALPHA32I_EXT
:
4019 return MESA_FORMAT_A_SINT32
;
4020 case GL_ALPHA8UI_EXT
:
4021 return MESA_FORMAT_A_UINT8
;
4022 case GL_ALPHA16UI_EXT
:
4023 return MESA_FORMAT_A_UINT16
;
4024 case GL_ALPHA32UI_EXT
:
4025 return MESA_FORMAT_A_UINT32
;
4027 return MESA_FORMAT_L_UNORM8
;
4028 case GL_LUMINANCE16
:
4029 return MESA_FORMAT_L_UNORM16
;
4030 case GL_LUMINANCE16F_ARB
:
4031 return MESA_FORMAT_L_FLOAT16
;
4032 case GL_LUMINANCE32F_ARB
:
4033 return MESA_FORMAT_L_FLOAT32
;
4034 case GL_LUMINANCE8I_EXT
:
4035 return MESA_FORMAT_L_SINT8
;
4036 case GL_LUMINANCE16I_EXT
:
4037 return MESA_FORMAT_L_SINT16
;
4038 case GL_LUMINANCE32I_EXT
:
4039 return MESA_FORMAT_L_SINT32
;
4040 case GL_LUMINANCE8UI_EXT
:
4041 return MESA_FORMAT_L_UINT8
;
4042 case GL_LUMINANCE16UI_EXT
:
4043 return MESA_FORMAT_L_UINT16
;
4044 case GL_LUMINANCE32UI_EXT
:
4045 return MESA_FORMAT_L_UINT32
;
4046 case GL_LUMINANCE8_ALPHA8
:
4047 return MESA_FORMAT_L8A8_UNORM
;
4048 case GL_LUMINANCE16_ALPHA16
:
4049 return MESA_FORMAT_L16A16_UNORM
;
4050 case GL_LUMINANCE_ALPHA16F_ARB
:
4051 return MESA_FORMAT_LA_FLOAT16
;
4052 case GL_LUMINANCE_ALPHA32F_ARB
:
4053 return MESA_FORMAT_LA_FLOAT32
;
4054 case GL_LUMINANCE_ALPHA8I_EXT
:
4055 return MESA_FORMAT_LA_SINT8
;
4056 case GL_LUMINANCE_ALPHA16I_EXT
:
4057 return MESA_FORMAT_LA_SINT8
;
4058 case GL_LUMINANCE_ALPHA32I_EXT
:
4059 return MESA_FORMAT_LA_SINT16
;
4060 case GL_LUMINANCE_ALPHA8UI_EXT
:
4061 return MESA_FORMAT_LA_UINT8
;
4062 case GL_LUMINANCE_ALPHA16UI_EXT
:
4063 return MESA_FORMAT_LA_UINT16
;
4064 case GL_LUMINANCE_ALPHA32UI_EXT
:
4065 return MESA_FORMAT_LA_UINT32
;
4067 return MESA_FORMAT_I_UNORM8
;
4068 case GL_INTENSITY16
:
4069 return MESA_FORMAT_I_UNORM16
;
4070 case GL_INTENSITY16F_ARB
:
4071 return MESA_FORMAT_I_FLOAT16
;
4072 case GL_INTENSITY32F_ARB
:
4073 return MESA_FORMAT_I_FLOAT32
;
4074 case GL_INTENSITY8I_EXT
:
4075 return MESA_FORMAT_I_SINT8
;
4076 case GL_INTENSITY16I_EXT
:
4077 return MESA_FORMAT_I_SINT16
;
4078 case GL_INTENSITY32I_EXT
:
4079 return MESA_FORMAT_I_SINT32
;
4080 case GL_INTENSITY8UI_EXT
:
4081 return MESA_FORMAT_I_UINT8
;
4082 case GL_INTENSITY16UI_EXT
:
4083 return MESA_FORMAT_I_UINT16
;
4084 case GL_INTENSITY32UI_EXT
:
4085 return MESA_FORMAT_I_UINT32
;
4091 if (ctx
->API
== API_OPENGL_CORE
&&
4092 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4093 switch (internalFormat
) {
4095 return MESA_FORMAT_RGB_FLOAT32
;
4097 return MESA_FORMAT_RGB_UINT32
;
4099 return MESA_FORMAT_RGB_SINT32
;
4105 switch (internalFormat
) {
4107 return MESA_FORMAT_R8G8B8A8_UNORM
;
4109 return MESA_FORMAT_RGBA_UNORM16
;
4110 case GL_RGBA16F_ARB
:
4111 return MESA_FORMAT_RGBA_FLOAT16
;
4112 case GL_RGBA32F_ARB
:
4113 return MESA_FORMAT_RGBA_FLOAT32
;
4115 return MESA_FORMAT_RGBA_SINT8
;
4116 case GL_RGBA16I_EXT
:
4117 return MESA_FORMAT_RGBA_SINT16
;
4118 case GL_RGBA32I_EXT
:
4119 return MESA_FORMAT_RGBA_SINT32
;
4120 case GL_RGBA8UI_EXT
:
4121 return MESA_FORMAT_RGBA_UINT8
;
4122 case GL_RGBA16UI_EXT
:
4123 return MESA_FORMAT_RGBA_UINT16
;
4124 case GL_RGBA32UI_EXT
:
4125 return MESA_FORMAT_RGBA_UINT32
;
4128 return MESA_FORMAT_R8G8_UNORM
;
4130 return MESA_FORMAT_R16G16_UNORM
;
4132 return MESA_FORMAT_RG_FLOAT16
;
4134 return MESA_FORMAT_RG_FLOAT32
;
4136 return MESA_FORMAT_RG_SINT8
;
4138 return MESA_FORMAT_RG_SINT16
;
4140 return MESA_FORMAT_RG_SINT32
;
4142 return MESA_FORMAT_RG_UINT8
;
4144 return MESA_FORMAT_RG_UINT16
;
4146 return MESA_FORMAT_RG_UINT32
;
4149 return MESA_FORMAT_R_UNORM8
;
4151 return MESA_FORMAT_R_UNORM16
;
4153 return MESA_FORMAT_R_FLOAT16
;
4155 return MESA_FORMAT_R_FLOAT32
;
4157 return MESA_FORMAT_R_SINT8
;
4159 return MESA_FORMAT_R_SINT16
;
4161 return MESA_FORMAT_R_SINT32
;
4163 return MESA_FORMAT_R_UINT8
;
4165 return MESA_FORMAT_R_UINT16
;
4167 return MESA_FORMAT_R_UINT32
;
4170 return MESA_FORMAT_NONE
;
4176 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4177 GLenum internalFormat
)
4179 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
4182 if (format
== MESA_FORMAT_NONE
)
4183 return MESA_FORMAT_NONE
;
4185 datatype
= _mesa_get_format_datatype(format
);
4186 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4187 return MESA_FORMAT_NONE
;
4189 /* The GL_ARB_texture_buffer_object spec says:
4191 * "If ARB_texture_float is not supported, references to the
4192 * floating-point internal formats provided by that extension should be
4193 * removed, and such formats may not be passed to TexBufferARB."
4195 * As a result, GL_HALF_FLOAT internal format depends on both
4196 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
4198 if (datatype
== GL_HALF_FLOAT
&&
4199 !(ctx
->Extensions
.ARB_half_float_pixel
4200 && ctx
->Extensions
.ARB_texture_float
))
4201 return MESA_FORMAT_NONE
;
4203 if (!ctx
->Extensions
.ARB_texture_rg
) {
4204 GLenum base_format
= _mesa_get_format_base_format(format
);
4205 if (base_format
== GL_R
|| base_format
== GL_RG
)
4206 return MESA_FORMAT_NONE
;
4209 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4210 GLenum base_format
= _mesa_get_format_base_format(format
);
4211 if (base_format
== GL_RGB
)
4212 return MESA_FORMAT_NONE
;
4219 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4220 struct gl_buffer_object
*bufObj
,
4221 GLintptr offset
, GLsizeiptr size
)
4223 struct gl_texture_object
*texObj
;
4226 FLUSH_VERTICES(ctx
, 0);
4228 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4229 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4233 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
4234 if (format
== MESA_FORMAT_NONE
) {
4235 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4240 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4242 _mesa_lock_texture(ctx
, texObj
);
4244 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4245 texObj
->BufferObjectFormat
= internalFormat
;
4246 texObj
->_BufferObjectFormat
= format
;
4247 texObj
->BufferOffset
= offset
;
4248 texObj
->BufferSize
= size
;
4250 _mesa_unlock_texture(ctx
, texObj
);
4254 /** GL_ARB_texture_buffer_object */
4256 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4258 struct gl_buffer_object
*bufObj
;
4260 GET_CURRENT_CONTEXT(ctx
);
4262 /* NOTE: ARB_texture_buffer_object has interactions with
4263 * the compatibility profile that are not implemented.
4265 if (!(ctx
->API
== API_OPENGL_CORE
&&
4266 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4267 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4271 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4272 if (!bufObj
&& buffer
) {
4273 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4277 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4281 /** GL_ARB_texture_buffer_range */
4283 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4284 GLintptr offset
, GLsizeiptr size
)
4286 struct gl_buffer_object
*bufObj
;
4288 GET_CURRENT_CONTEXT(ctx
);
4290 if (!(ctx
->API
== API_OPENGL_CORE
&&
4291 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4292 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4296 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4300 (offset
+ size
) > bufObj
->Size
) {
4301 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4304 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4305 _mesa_error(ctx
, GL_INVALID_VALUE
,
4306 "glTexBufferRange(invalid offset alignment)");
4309 } else if (buffer
) {
4310 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4318 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4323 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4325 /* Everything that is allowed for renderbuffers,
4326 * except for a base format of GL_STENCIL_INDEX.
4328 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4329 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4333 /** GL_ARB_texture_multisample */
4335 check_multisample_target(GLuint dims
, GLenum target
)
4338 case GL_TEXTURE_2D_MULTISAMPLE
:
4339 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4342 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4343 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4353 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4354 GLint internalformat
, GLsizei width
, GLsizei height
,
4355 GLsizei depth
, GLboolean fixedsamplelocations
,
4356 GLboolean immutable
, const char *func
)
4358 struct gl_texture_object
*texObj
;
4359 struct gl_texture_image
*texImage
;
4360 GLboolean sizeOK
, dimensionsOK
;
4361 mesa_format texFormat
;
4362 GLenum sample_count_error
;
4364 GET_CURRENT_CONTEXT(ctx
);
4366 if (!(ctx
->Extensions
.ARB_texture_multisample
4367 && _mesa_is_desktop_gl(ctx
))) {
4368 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4372 if (!check_multisample_target(dims
, target
)) {
4373 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4377 /* check that the specified internalformat is color/depth/stencil-renderable;
4378 * refer GL3.1 spec 4.4.4
4381 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4382 _mesa_error(ctx
, GL_INVALID_ENUM
,
4383 "%s(internalformat=%s not legal for immutable-format)",
4384 func
, _mesa_lookup_enum_by_nr(internalformat
));
4388 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4390 "%s(internalformat=%s)",
4391 func
, _mesa_lookup_enum_by_nr(internalformat
));
4395 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4396 internalformat
, samples
);
4397 if (sample_count_error
!= GL_NO_ERROR
) {
4398 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4402 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4404 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4405 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4406 "%s(texture object 0)",
4411 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4413 if (texImage
== NULL
) {
4414 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4418 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4419 internalformat
, GL_NONE
, GL_NONE
);
4420 assert(texFormat
!= MESA_FORMAT_NONE
);
4422 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4423 width
, height
, depth
, 0);
4425 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4426 width
, height
, depth
, 0);
4428 if (_mesa_is_proxy_texture(target
)) {
4429 if (dimensionsOK
&& sizeOK
) {
4430 _mesa_init_teximage_fields(ctx
, texImage
,
4431 width
, height
, depth
, 0, internalformat
, texFormat
);
4432 texImage
->NumSamples
= samples
;
4433 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4436 /* clear all image fields */
4437 _mesa_init_teximage_fields(ctx
, texImage
,
4438 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4442 if (!dimensionsOK
) {
4443 _mesa_error(ctx
, GL_INVALID_VALUE
,
4444 "%s(invalid width or height)", func
);
4449 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4450 "%s(texture too large)", func
);
4454 /* Check if texObj->Immutable is set */
4455 if (texObj
->Immutable
) {
4456 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4460 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4462 _mesa_init_teximage_fields(ctx
, texImage
,
4463 width
, height
, depth
, 0, internalformat
, texFormat
);
4465 texImage
->NumSamples
= samples
;
4466 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4468 if (width
> 0 && height
> 0 && depth
> 0) {
4469 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4470 width
, height
, depth
)) {
4471 /* tidy up the texture image state. strictly speaking,
4472 * we're allowed to just leave this in whatever state we
4473 * like, but being tidy is good.
4475 _mesa_init_teximage_fields(ctx
, texImage
,
4476 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4480 texObj
->Immutable
= immutable
;
4483 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
4486 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4492 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4493 GLenum internalformat
, GLsizei width
,
4494 GLsizei height
, GLboolean fixedsamplelocations
)
4496 teximagemultisample(2, target
, samples
, internalformat
,
4497 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4498 "glTexImage2DMultisample");
4503 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4504 GLenum internalformat
, GLsizei width
,
4505 GLsizei height
, GLsizei depth
,
4506 GLboolean fixedsamplelocations
)
4508 teximagemultisample(3, target
, samples
, internalformat
,
4509 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4510 "glTexImage3DMultisample");
4515 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4516 GLenum internalformat
, GLsizei width
,
4517 GLsizei height
, GLboolean fixedsamplelocations
)
4519 teximagemultisample(2, target
, samples
, internalformat
,
4520 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4521 "glTexStorage2DMultisample");
4526 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4527 GLenum internalformat
, GLsizei width
,
4528 GLsizei height
, GLsizei depth
,
4529 GLboolean fixedsamplelocations
)
4531 teximagemultisample(3, target
, samples
, internalformat
,
4532 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4533 "glTexStorage3DMultisample");