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
;
163 case GL_DEPTH_STENCIL
:
164 case GL_DEPTH24_STENCIL8
:
165 return GL_DEPTH_STENCIL
;
171 switch (internalFormat
) {
172 case GL_COMPRESSED_ALPHA
:
174 case GL_COMPRESSED_LUMINANCE
:
176 case GL_COMPRESSED_LUMINANCE_ALPHA
:
177 return GL_LUMINANCE_ALPHA
;
178 case GL_COMPRESSED_INTENSITY
:
180 case GL_COMPRESSED_RGB
:
182 case GL_COMPRESSED_RGBA
:
188 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
189 switch (internalFormat
) {
190 case GL_COMPRESSED_RGB_FXT1_3DFX
:
192 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
199 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
201 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
202 switch (internalFormat
) {
203 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
205 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
206 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
207 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
214 if (_mesa_is_desktop_gl(ctx
)
215 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
216 switch (internalFormat
) {
228 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
229 if (internalFormat
== GL_YCBCR_MESA
)
230 return GL_YCBCR_MESA
;
233 if (ctx
->Extensions
.ARB_texture_float
) {
234 switch (internalFormat
) {
235 case GL_ALPHA16F_ARB
:
236 case GL_ALPHA32F_ARB
:
244 case GL_INTENSITY16F_ARB
:
245 case GL_INTENSITY32F_ARB
:
247 case GL_LUMINANCE16F_ARB
:
248 case GL_LUMINANCE32F_ARB
:
250 case GL_LUMINANCE_ALPHA16F_ARB
:
251 case GL_LUMINANCE_ALPHA32F_ARB
:
252 return GL_LUMINANCE_ALPHA
;
258 if (ctx
->Extensions
.EXT_texture_snorm
) {
259 switch (internalFormat
) {
274 case GL_RGBA16_SNORM
:
277 case GL_ALPHA8_SNORM
:
278 case GL_ALPHA16_SNORM
:
280 case GL_LUMINANCE_SNORM
:
281 case GL_LUMINANCE8_SNORM
:
282 case GL_LUMINANCE16_SNORM
:
284 case GL_LUMINANCE_ALPHA_SNORM
:
285 case GL_LUMINANCE8_ALPHA8_SNORM
:
286 case GL_LUMINANCE16_ALPHA16_SNORM
:
287 return GL_LUMINANCE_ALPHA
;
288 case GL_INTENSITY_SNORM
:
289 case GL_INTENSITY8_SNORM
:
290 case GL_INTENSITY16_SNORM
:
297 if (ctx
->Extensions
.EXT_texture_sRGB
) {
298 switch (internalFormat
) {
301 case GL_COMPRESSED_SRGB_EXT
:
303 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
304 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
305 case GL_SRGB_ALPHA_EXT
:
306 case GL_SRGB8_ALPHA8_EXT
:
307 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
309 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
310 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
311 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
312 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
313 case GL_SLUMINANCE_ALPHA_EXT
:
314 case GL_SLUMINANCE8_ALPHA8_EXT
:
315 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
316 return GL_LUMINANCE_ALPHA
;
317 case GL_SLUMINANCE_EXT
:
318 case GL_SLUMINANCE8_EXT
:
319 case GL_COMPRESSED_SLUMINANCE_EXT
:
326 if (ctx
->Version
>= 30 ||
327 ctx
->Extensions
.EXT_texture_integer
) {
328 switch (internalFormat
) {
330 case GL_RGBA16UI_EXT
:
331 case GL_RGBA32UI_EXT
:
347 if (ctx
->Extensions
.EXT_texture_integer
) {
348 switch (internalFormat
) {
349 case GL_ALPHA8UI_EXT
:
350 case GL_ALPHA16UI_EXT
:
351 case GL_ALPHA32UI_EXT
:
353 case GL_ALPHA16I_EXT
:
354 case GL_ALPHA32I_EXT
:
356 case GL_INTENSITY8UI_EXT
:
357 case GL_INTENSITY16UI_EXT
:
358 case GL_INTENSITY32UI_EXT
:
359 case GL_INTENSITY8I_EXT
:
360 case GL_INTENSITY16I_EXT
:
361 case GL_INTENSITY32I_EXT
:
363 case GL_LUMINANCE8UI_EXT
:
364 case GL_LUMINANCE16UI_EXT
:
365 case GL_LUMINANCE32UI_EXT
:
366 case GL_LUMINANCE8I_EXT
:
367 case GL_LUMINANCE16I_EXT
:
368 case GL_LUMINANCE32I_EXT
:
370 case GL_LUMINANCE_ALPHA8UI_EXT
:
371 case GL_LUMINANCE_ALPHA16UI_EXT
:
372 case GL_LUMINANCE_ALPHA32UI_EXT
:
373 case GL_LUMINANCE_ALPHA8I_EXT
:
374 case GL_LUMINANCE_ALPHA16I_EXT
:
375 case GL_LUMINANCE_ALPHA32I_EXT
:
376 return GL_LUMINANCE_ALPHA
;
382 if (ctx
->Extensions
.ARB_texture_rg
) {
383 switch (internalFormat
) {
386 if (!ctx
->Extensions
.ARB_texture_float
)
395 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
401 case GL_COMPRESSED_RED
:
406 if (!ctx
->Extensions
.ARB_texture_float
)
415 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
421 case GL_COMPRESSED_RG
:
428 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
429 switch (internalFormat
) {
437 if (ctx
->Extensions
.EXT_packed_float
) {
438 switch (internalFormat
) {
439 case GL_R11F_G11F_B10F_EXT
:
446 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
447 switch (internalFormat
) {
448 case GL_DEPTH_COMPONENT32F
:
449 return GL_DEPTH_COMPONENT
;
450 case GL_DEPTH32F_STENCIL8
:
451 return GL_DEPTH_STENCIL
;
457 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
458 switch (internalFormat
) {
459 case GL_COMPRESSED_RED_RGTC1
:
460 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
462 case GL_COMPRESSED_RG_RGTC2
:
463 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
470 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
471 switch (internalFormat
) {
472 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
473 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
475 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
476 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
477 return GL_LUMINANCE_ALPHA
;
483 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
484 switch (internalFormat
) {
485 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
486 return GL_LUMINANCE_ALPHA
;
492 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
493 switch (internalFormat
) {
494 case GL_ETC1_RGB8_OES
:
501 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
502 switch (internalFormat
) {
503 case GL_COMPRESSED_RGB8_ETC2
:
504 case GL_COMPRESSED_SRGB8_ETC2
:
506 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
507 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
508 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
509 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
511 case GL_COMPRESSED_R11_EAC
:
512 case GL_COMPRESSED_SIGNED_R11_EAC
:
514 case GL_COMPRESSED_RG11_EAC
:
515 case GL_COMPRESSED_SIGNED_RG11_EAC
:
522 if (ctx
->API
== API_OPENGLES
) {
523 switch (internalFormat
) {
524 case GL_PALETTE4_RGB8_OES
:
525 case GL_PALETTE4_R5_G6_B5_OES
:
526 case GL_PALETTE8_RGB8_OES
:
527 case GL_PALETTE8_R5_G6_B5_OES
:
529 case GL_PALETTE4_RGBA8_OES
:
530 case GL_PALETTE8_RGB5_A1_OES
:
531 case GL_PALETTE4_RGBA4_OES
:
532 case GL_PALETTE4_RGB5_A1_OES
:
533 case GL_PALETTE8_RGBA8_OES
:
534 case GL_PALETTE8_RGBA4_OES
:
541 return -1; /* error */
546 * For cube map faces, return a face index in [0,5].
547 * For other targets return 0;
550 _mesa_tex_target_to_face(GLenum target
)
552 if (_mesa_is_cube_face(target
))
553 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
561 * Install gl_texture_image in a gl_texture_object according to the target
562 * and level parameters.
564 * \param tObj texture object.
565 * \param target texture target.
566 * \param level image level.
567 * \param texImage texture image.
570 set_tex_image(struct gl_texture_object
*tObj
,
571 GLenum target
, GLint level
,
572 struct gl_texture_image
*texImage
)
574 const GLuint face
= _mesa_tex_target_to_face(target
);
578 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
581 tObj
->Image
[face
][level
] = texImage
;
583 /* Set the 'back' pointer */
584 texImage
->TexObject
= tObj
;
585 texImage
->Level
= level
;
586 texImage
->Face
= face
;
591 * Allocate a texture image structure.
593 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
596 * \return a pointer to gl_texture_image struct with all fields initialized to
599 struct gl_texture_image
*
600 _mesa_new_texture_image( struct gl_context
*ctx
)
603 return CALLOC_STRUCT(gl_texture_image
);
608 * Free a gl_texture_image and associated data.
609 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
611 * \param texImage texture image.
613 * Free the texture image structure and the associated image data.
616 _mesa_delete_texture_image(struct gl_context
*ctx
,
617 struct gl_texture_image
*texImage
)
619 /* Free texImage->Data and/or any other driver-specific texture
622 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
623 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
629 * Test if a target is a proxy target.
631 * \param target texture target.
633 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
636 _mesa_is_proxy_texture(GLenum target
)
639 static const GLenum targets
[] = {
643 GL_PROXY_TEXTURE_CUBE_MAP
,
644 GL_PROXY_TEXTURE_RECTANGLE
,
645 GL_PROXY_TEXTURE_1D_ARRAY
,
646 GL_PROXY_TEXTURE_2D_ARRAY
,
647 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
648 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
649 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
652 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
653 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
655 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== Elements(targets
) + 2);
657 for (i
= 0; i
< Elements(targets
); ++i
)
658 if (target
== targets
[i
])
665 * Return the proxy target which corresponds to the given texture target
668 proxy_target(GLenum target
)
672 case GL_PROXY_TEXTURE_1D
:
673 return GL_PROXY_TEXTURE_1D
;
675 case GL_PROXY_TEXTURE_2D
:
676 return GL_PROXY_TEXTURE_2D
;
678 case GL_PROXY_TEXTURE_3D
:
679 return GL_PROXY_TEXTURE_3D
;
680 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
681 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
682 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
683 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
684 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
685 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
686 case GL_TEXTURE_CUBE_MAP_ARB
:
687 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
688 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
689 case GL_TEXTURE_RECTANGLE_NV
:
690 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
691 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
692 case GL_TEXTURE_1D_ARRAY_EXT
:
693 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
694 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
695 case GL_TEXTURE_2D_ARRAY_EXT
:
696 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
697 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
698 case GL_TEXTURE_CUBE_MAP_ARRAY
:
699 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
700 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
701 case GL_TEXTURE_2D_MULTISAMPLE
:
702 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
703 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
704 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
705 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
706 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
708 _mesa_problem(NULL
, "unexpected target in proxy_target()");
715 * Return a pointer to the current texture object for the given target
716 * on the current texture unit.
717 * Note: all <target> error checking should have been done by this point.
719 struct gl_texture_object
*
720 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
722 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
723 const GLboolean arrayTex
= ctx
->Extensions
.EXT_texture_array
;
727 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
728 case GL_PROXY_TEXTURE_1D
:
729 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
731 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
732 case GL_PROXY_TEXTURE_2D
:
733 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
735 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
736 case GL_PROXY_TEXTURE_3D
:
737 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
738 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
739 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
740 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
741 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
742 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
743 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
744 case GL_TEXTURE_CUBE_MAP_ARB
:
745 return ctx
->Extensions
.ARB_texture_cube_map
746 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
747 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
748 return ctx
->Extensions
.ARB_texture_cube_map
749 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
750 case GL_TEXTURE_CUBE_MAP_ARRAY
:
751 return ctx
->Extensions
.ARB_texture_cube_map_array
752 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
753 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
754 return ctx
->Extensions
.ARB_texture_cube_map_array
755 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
756 case GL_TEXTURE_RECTANGLE_NV
:
757 return ctx
->Extensions
.NV_texture_rectangle
758 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
759 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
760 return ctx
->Extensions
.NV_texture_rectangle
761 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
762 case GL_TEXTURE_1D_ARRAY_EXT
:
763 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
764 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
765 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
766 case GL_TEXTURE_2D_ARRAY_EXT
:
767 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
768 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
769 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
770 case GL_TEXTURE_BUFFER
:
771 return ctx
->API
== API_OPENGL_CORE
&&
772 ctx
->Extensions
.ARB_texture_buffer_object
?
773 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
774 case GL_TEXTURE_EXTERNAL_OES
:
775 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
776 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
777 case GL_TEXTURE_2D_MULTISAMPLE
:
778 return ctx
->Extensions
.ARB_texture_multisample
779 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
780 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
781 return ctx
->Extensions
.ARB_texture_multisample
782 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
783 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
784 return ctx
->Extensions
.ARB_texture_multisample
785 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
786 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
787 return ctx
->Extensions
.ARB_texture_multisample
788 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
790 _mesa_problem(NULL
, "bad target in _mesa_get_current_tex_object()");
798 * Get a texture image pointer from a texture object, given a texture
799 * target and mipmap level. The target and level parameters should
800 * have already been error-checked.
802 * \param ctx GL context.
803 * \param texObj texture unit.
804 * \param target texture target.
805 * \param level image level.
807 * \return pointer to the texture image structure, or NULL on failure.
809 struct gl_texture_image
*
810 _mesa_select_tex_image(struct gl_context
*ctx
,
811 const struct gl_texture_object
*texObj
,
812 GLenum target
, GLint level
)
814 const GLuint face
= _mesa_tex_target_to_face(target
);
818 ASSERT(level
< MAX_TEXTURE_LEVELS
);
820 return texObj
->Image
[face
][level
];
825 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
826 * it and install it. Only return NULL if passed a bad parameter or run
829 struct gl_texture_image
*
830 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
831 GLenum target
, GLint level
)
833 struct gl_texture_image
*texImage
;
838 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
840 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
842 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
846 set_tex_image(texObj
, target
, level
, texImage
);
854 * Return pointer to the specified proxy texture image.
855 * Note that proxy textures are per-context, not per-texture unit.
856 * \return pointer to texture image or NULL if invalid target, invalid
857 * level, or out of memory.
859 static struct gl_texture_image
*
860 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
862 struct gl_texture_image
*texImage
;
869 case GL_PROXY_TEXTURE_1D
:
870 if (level
>= ctx
->Const
.MaxTextureLevels
)
872 texIndex
= TEXTURE_1D_INDEX
;
874 case GL_PROXY_TEXTURE_2D
:
875 if (level
>= ctx
->Const
.MaxTextureLevels
)
877 texIndex
= TEXTURE_2D_INDEX
;
879 case GL_PROXY_TEXTURE_3D
:
880 if (level
>= ctx
->Const
.Max3DTextureLevels
)
882 texIndex
= TEXTURE_3D_INDEX
;
884 case GL_PROXY_TEXTURE_CUBE_MAP
:
885 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
887 texIndex
= TEXTURE_CUBE_INDEX
;
889 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
892 texIndex
= TEXTURE_RECT_INDEX
;
894 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
895 if (level
>= ctx
->Const
.MaxTextureLevels
)
897 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
899 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
900 if (level
>= ctx
->Const
.MaxTextureLevels
)
902 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
904 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
905 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
907 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
909 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
912 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
914 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
917 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
923 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
925 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
927 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
930 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
931 /* Set the 'back' pointer */
932 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
939 * Get the maximum number of allowed mipmap levels.
941 * \param ctx GL context.
942 * \param target texture target.
944 * \return the maximum number of allowed mipmap levels for the given
945 * texture target, or zero if passed a bad target.
950 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
954 case GL_PROXY_TEXTURE_1D
:
956 case GL_PROXY_TEXTURE_2D
:
957 return ctx
->Const
.MaxTextureLevels
;
959 case GL_PROXY_TEXTURE_3D
:
960 return ctx
->Const
.Max3DTextureLevels
;
961 case GL_TEXTURE_CUBE_MAP
:
962 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
963 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
964 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
965 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
966 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
967 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
968 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
969 return ctx
->Extensions
.ARB_texture_cube_map
970 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
971 case GL_TEXTURE_RECTANGLE_NV
:
972 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
973 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
974 case GL_TEXTURE_1D_ARRAY_EXT
:
975 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
976 case GL_TEXTURE_2D_ARRAY_EXT
:
977 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
978 return ctx
->Extensions
.EXT_texture_array
979 ? ctx
->Const
.MaxTextureLevels
: 0;
980 case GL_TEXTURE_CUBE_MAP_ARRAY
:
981 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
982 return ctx
->Extensions
.ARB_texture_cube_map_array
983 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
984 case GL_TEXTURE_BUFFER
:
985 return ctx
->API
== API_OPENGL_CORE
&&
986 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
987 case GL_TEXTURE_2D_MULTISAMPLE
:
988 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
989 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
990 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
991 return _mesa_is_desktop_gl(ctx
)
992 && ctx
->Extensions
.ARB_texture_multisample
994 case GL_TEXTURE_EXTERNAL_OES
:
997 return 0; /* bad target */
1003 * Return number of dimensions per mipmap level for the given texture target.
1006 _mesa_get_texture_dimensions(GLenum target
)
1010 case GL_PROXY_TEXTURE_1D
:
1013 case GL_TEXTURE_RECTANGLE
:
1014 case GL_TEXTURE_CUBE_MAP
:
1015 case GL_PROXY_TEXTURE_2D
:
1016 case GL_PROXY_TEXTURE_RECTANGLE
:
1017 case GL_PROXY_TEXTURE_CUBE_MAP
:
1018 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1019 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1020 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1021 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1022 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1023 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1024 case GL_TEXTURE_1D_ARRAY
:
1025 case GL_PROXY_TEXTURE_1D_ARRAY
:
1026 case GL_TEXTURE_EXTERNAL_OES
:
1027 case GL_TEXTURE_2D_MULTISAMPLE
:
1028 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1031 case GL_PROXY_TEXTURE_3D
:
1032 case GL_TEXTURE_2D_ARRAY
:
1033 case GL_PROXY_TEXTURE_2D_ARRAY
:
1034 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1035 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1036 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1037 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1039 case GL_TEXTURE_BUFFER
:
1042 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1050 * Check if a texture target can have more than one layer.
1053 _mesa_tex_target_is_layered(GLenum target
)
1057 case GL_PROXY_TEXTURE_1D
:
1059 case GL_PROXY_TEXTURE_2D
:
1060 case GL_TEXTURE_RECTANGLE
:
1061 case GL_PROXY_TEXTURE_RECTANGLE
:
1062 case GL_TEXTURE_2D_MULTISAMPLE
:
1063 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1064 case GL_TEXTURE_BUFFER
:
1065 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1066 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1067 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1068 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1069 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1070 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1071 case GL_TEXTURE_EXTERNAL_OES
:
1075 case GL_PROXY_TEXTURE_3D
:
1076 case GL_TEXTURE_CUBE_MAP
:
1077 case GL_PROXY_TEXTURE_CUBE_MAP
:
1078 case GL_TEXTURE_1D_ARRAY
:
1079 case GL_PROXY_TEXTURE_1D_ARRAY
:
1080 case GL_TEXTURE_2D_ARRAY
:
1081 case GL_PROXY_TEXTURE_2D_ARRAY
:
1082 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1083 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1084 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1085 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1089 assert(!"Invalid texture target.");
1096 * Return the number of layers present in the given level of an array,
1097 * cubemap or 3D texture. If the texture is not layered return zero.
1100 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1102 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1104 switch (texObj
->Target
) {
1107 case GL_TEXTURE_RECTANGLE
:
1108 case GL_TEXTURE_2D_MULTISAMPLE
:
1109 case GL_TEXTURE_BUFFER
:
1110 case GL_TEXTURE_EXTERNAL_OES
:
1113 case GL_TEXTURE_CUBE_MAP
:
1116 case GL_TEXTURE_1D_ARRAY
: {
1117 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1118 return img
? img
->Height
: 0;
1122 case GL_TEXTURE_2D_ARRAY
:
1123 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1124 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1125 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1126 return img
? img
->Depth
: 0;
1130 assert(!"Invalid texture target.");
1137 * Return the maximum number of mipmap levels for the given target
1138 * and the dimensions.
1139 * The dimensions are expected not to include the border.
1142 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1149 case GL_TEXTURE_1D_ARRAY
:
1150 case GL_PROXY_TEXTURE_1D
:
1151 case GL_PROXY_TEXTURE_1D_ARRAY
:
1154 case GL_TEXTURE_CUBE_MAP
:
1155 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1156 case GL_PROXY_TEXTURE_CUBE_MAP
:
1157 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1161 case GL_TEXTURE_2D_ARRAY
:
1162 case GL_PROXY_TEXTURE_2D
:
1163 case GL_PROXY_TEXTURE_2D_ARRAY
:
1164 size
= MAX2(width
, height
);
1167 case GL_PROXY_TEXTURE_3D
:
1168 size
= MAX3(width
, height
, depth
);
1170 case GL_TEXTURE_RECTANGLE
:
1171 case GL_TEXTURE_EXTERNAL_OES
:
1172 case GL_TEXTURE_2D_MULTISAMPLE
:
1173 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1174 case GL_PROXY_TEXTURE_RECTANGLE
:
1175 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1176 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1183 return _mesa_logbase2(size
) + 1;
1187 #if 000 /* not used anymore */
1189 * glTexImage[123]D can accept a NULL image pointer. In this case we
1190 * create a texture image with unspecified image contents per the OpenGL
1194 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1196 const GLint components
= _mesa_components_in_format(format
);
1197 const GLint numPixels
= width
* height
* depth
;
1198 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1202 * Let's see if anyone finds this. If glTexImage2D() is called with
1203 * a NULL image pointer then load the texture image with something
1204 * interesting instead of leaving it indeterminate.
1207 static const char message
[8][32] = {
1208 " X X XXXXX XXX X ",
1209 " XX XX X X X X X ",
1211 " X X XXXX XXX XXXXX ",
1214 " X X XXXXX XXX X X ",
1218 GLubyte
*imgPtr
= data
;
1220 for (h
= 0; h
< depth
; h
++) {
1221 for (i
= 0; i
< height
; i
++) {
1222 GLint srcRow
= 7 - (i
% 8);
1223 for (j
= 0; j
< width
; j
++) {
1224 GLint srcCol
= j
% 32;
1225 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1226 for (k
= 0; k
< components
; k
++) {
1242 * Set the size and format-related fields of a gl_texture_image struct
1243 * to zero. This is used when a proxy texture test fails.
1246 clear_teximage_fields(struct gl_texture_image
*img
)
1249 img
->_BaseFormat
= 0;
1250 img
->InternalFormat
= 0;
1259 img
->HeightLog2
= 0;
1261 img
->TexFormat
= MESA_FORMAT_NONE
;
1262 img
->NumSamples
= 0;
1263 img
->FixedSampleLocations
= GL_TRUE
;
1268 * Initialize basic fields of the gl_texture_image struct.
1270 * \param ctx GL context.
1271 * \param img texture image structure to be initialized.
1272 * \param width image width.
1273 * \param height image height.
1274 * \param depth image depth.
1275 * \param border image border.
1276 * \param internalFormat internal format.
1277 * \param format the actual hardware format (one of MESA_FORMAT_*)
1278 * \param numSamples number of samples per texel, or zero for non-MS.
1279 * \param fixedSampleLocations are sample locations fixed?
1281 * Fills in the fields of \p img with the given information.
1282 * Note: width, height and depth include the border.
1285 init_teximage_fields_ms(struct gl_context
*ctx
,
1286 struct gl_texture_image
*img
,
1287 GLsizei width
, GLsizei height
, GLsizei depth
,
1288 GLint border
, GLenum internalFormat
,
1290 GLuint numSamples
, GLboolean fixedSampleLocations
)
1295 ASSERT(height
>= 0);
1298 target
= img
->TexObject
->Target
;
1299 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1300 ASSERT(img
->_BaseFormat
> 0);
1301 img
->InternalFormat
= internalFormat
;
1302 img
->Border
= border
;
1304 img
->Height
= height
;
1307 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1308 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1310 img
->NumSamples
= 0;
1311 img
->FixedSampleLocations
= GL_TRUE
;
1315 case GL_TEXTURE_BUFFER
:
1316 case GL_PROXY_TEXTURE_1D
:
1321 img
->HeightLog2
= 0;
1328 case GL_TEXTURE_1D_ARRAY
:
1329 case GL_PROXY_TEXTURE_1D_ARRAY
:
1330 img
->Height2
= height
; /* no border */
1331 img
->HeightLog2
= 0; /* not used */
1339 case GL_TEXTURE_RECTANGLE
:
1340 case GL_TEXTURE_CUBE_MAP
:
1341 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1342 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1343 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1344 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1345 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1346 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1347 case GL_TEXTURE_EXTERNAL_OES
:
1348 case GL_PROXY_TEXTURE_2D
:
1349 case GL_PROXY_TEXTURE_RECTANGLE
:
1350 case GL_PROXY_TEXTURE_CUBE_MAP
:
1351 case GL_TEXTURE_2D_MULTISAMPLE
:
1352 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1353 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1354 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1361 case GL_TEXTURE_2D_ARRAY
:
1362 case GL_PROXY_TEXTURE_2D_ARRAY
:
1363 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1364 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1365 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1366 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1367 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1368 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1369 img
->Depth2
= depth
; /* no border */
1370 img
->DepthLog2
= 0; /* not used */
1373 case GL_PROXY_TEXTURE_3D
:
1374 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1375 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1376 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1377 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1380 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1385 _mesa_get_tex_max_num_levels(target
,
1386 img
->Width2
, img
->Height2
, img
->Depth2
);
1387 img
->TexFormat
= format
;
1388 img
->NumSamples
= numSamples
;
1389 img
->FixedSampleLocations
= fixedSampleLocations
;
1394 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1395 struct gl_texture_image
*img
,
1396 GLsizei width
, GLsizei height
, GLsizei depth
,
1397 GLint border
, GLenum internalFormat
,
1400 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1401 internalFormat
, format
, 0, GL_TRUE
);
1406 * Free and clear fields of the gl_texture_image struct.
1408 * \param ctx GL context.
1409 * \param texImage texture image structure to be cleared.
1411 * After the call, \p texImage will have no data associated with it. Its
1412 * fields are cleared so that its parent object will test incomplete.
1415 _mesa_clear_texture_image(struct gl_context
*ctx
,
1416 struct gl_texture_image
*texImage
)
1418 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1419 clear_teximage_fields(texImage
);
1424 * Check the width, height, depth and border of a texture image are legal.
1425 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1427 * The target and level parameters will have already been validated.
1428 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1431 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1432 GLint level
, GLint width
, GLint height
,
1433 GLint depth
, GLint border
)
1439 case GL_PROXY_TEXTURE_1D
:
1440 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1441 maxSize
>>= level
; /* level size */
1442 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1444 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1445 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1451 case GL_PROXY_TEXTURE_2D
:
1452 case GL_TEXTURE_2D_MULTISAMPLE
:
1453 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1454 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1456 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1458 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1460 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1461 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1463 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1469 case GL_PROXY_TEXTURE_3D
:
1470 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1472 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1474 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1476 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1478 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1479 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1481 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1483 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1488 case GL_TEXTURE_RECTANGLE_NV
:
1489 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1492 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1493 if (width
< 0 || width
> maxSize
)
1495 if (height
< 0 || height
> maxSize
)
1499 case GL_TEXTURE_CUBE_MAP
:
1500 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1501 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1502 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1503 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1504 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1505 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1506 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1507 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1509 if (width
!= height
)
1511 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1513 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1515 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1516 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1518 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1523 case GL_TEXTURE_1D_ARRAY_EXT
:
1524 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1525 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1527 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1529 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1531 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1532 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1537 case GL_TEXTURE_2D_ARRAY_EXT
:
1538 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1539 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1540 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1541 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1543 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1545 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1547 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1549 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1550 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1552 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1557 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1558 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1559 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1560 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1562 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1564 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1566 if (width
!= height
)
1568 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1570 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1571 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1573 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1578 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1585 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1586 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1587 * \param destImage the destination texture image.
1588 * \return GL_TRUE if error found, GL_FALSE otherwise.
1591 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1592 const char *function
, GLuint dims
,
1593 const struct gl_texture_image
*destImage
,
1594 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1595 GLsizei subWidth
, GLsizei subHeight
,
1598 const GLenum target
= destImage
->TexObject
->Target
;
1603 _mesa_error(ctx
, GL_INVALID_VALUE
,
1604 "%s%dD(width=%d)", function
, dims
, subWidth
);
1608 if (dims
> 1 && subHeight
< 0) {
1609 _mesa_error(ctx
, GL_INVALID_VALUE
,
1610 "%s%dD(height=%d)", function
, dims
, subHeight
);
1614 if (dims
> 2 && subDepth
< 0) {
1615 _mesa_error(ctx
, GL_INVALID_VALUE
,
1616 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1620 /* check xoffset and width */
1621 if (xoffset
< - (GLint
) destImage
->Border
) {
1622 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1627 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1628 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1633 /* check yoffset and height */
1635 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1636 if (yoffset
< -yBorder
) {
1637 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1641 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1642 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1648 /* check zoffset and depth */
1650 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1651 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1652 0 : destImage
->Border
;
1654 if (zoffset
< -zBorder
) {
1655 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1658 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1659 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1665 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1666 * compressed texture images can be updated. But, that restriction may be
1667 * relaxed for particular compressed formats. At this time, all the
1668 * compressed formats supported by Mesa allow sub-textures to be updated
1669 * along compressed block boundaries.
1671 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1673 if (bw
!= 1 || bh
!= 1) {
1674 /* offset must be multiple of block size */
1675 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1676 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1677 "%s%dD(xoffset = %d, yoffset = %d)",
1678 function
, dims
, xoffset
, yoffset
);
1682 /* The size must be a multiple of bw x bh, or we must be using a
1683 * offset+size that exactly hits the edge of the image. This
1684 * is important for small mipmap levels (1x1, 2x1, etc) and for
1687 if ((subWidth
% bw
!= 0) &&
1688 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1689 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1690 "%s%dD(width = %d)", function
, dims
, subWidth
);
1694 if ((subHeight
% bh
!= 0) &&
1695 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1696 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1697 "%s%dD(height = %d)", function
, dims
, subHeight
);
1709 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1710 * specific texture image size checks.
1712 * A hardware driver might override this function if, for example, the
1713 * max 3D texture size is 512x512x64 (i.e. not a cube).
1715 * Note that width, height, depth == 0 is not an error. However, a
1716 * texture with zero width/height/depth will be considered "incomplete"
1717 * and texturing will effectively be disabled.
1719 * \param target any texture target/type
1720 * \param level as passed to glTexImage
1721 * \param format the MESA_FORMAT_x for the tex image
1722 * \param width as passed to glTexImage
1723 * \param height as passed to glTexImage
1724 * \param depth as passed to glTexImage
1725 * \param border as passed to glTexImage
1726 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1729 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1731 GLint width
, GLint height
, GLint depth
, GLint border
)
1733 /* We just check if the image size is less than MaxTextureMbytes.
1734 * Some drivers may do more specific checks.
1736 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1737 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1738 mbytes
*= _mesa_num_tex_faces(target
);
1739 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1744 * Return true if the format is only valid for glCompressedTexImage.
1747 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1750 case GL_ETC1_RGB8_OES
:
1751 case GL_PALETTE4_RGB8_OES
:
1752 case GL_PALETTE4_RGBA8_OES
:
1753 case GL_PALETTE4_R5_G6_B5_OES
:
1754 case GL_PALETTE4_RGBA4_OES
:
1755 case GL_PALETTE4_RGB5_A1_OES
:
1756 case GL_PALETTE8_RGB8_OES
:
1757 case GL_PALETTE8_RGBA8_OES
:
1758 case GL_PALETTE8_R5_G6_B5_OES
:
1759 case GL_PALETTE8_RGBA4_OES
:
1760 case GL_PALETTE8_RGB5_A1_OES
:
1769 * Helper function to determine whether a target and specific compression
1770 * format are supported.
1773 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1776 (void) intFormat
; /* not used yet */
1780 case GL_PROXY_TEXTURE_2D
:
1781 return GL_TRUE
; /* true for any compressed format so far */
1782 case GL_PROXY_TEXTURE_CUBE_MAP
:
1783 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1784 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1785 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1786 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1787 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1788 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1789 return ctx
->Extensions
.ARB_texture_cube_map
;
1790 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1791 case GL_TEXTURE_2D_ARRAY_EXT
:
1792 return ctx
->Extensions
.EXT_texture_array
;
1793 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1794 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1795 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1803 * Check if the given texture target value is legal for a
1804 * glTexImage1/2/3D call.
1807 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1813 case GL_PROXY_TEXTURE_1D
:
1814 return _mesa_is_desktop_gl(ctx
);
1822 case GL_PROXY_TEXTURE_2D
:
1823 return _mesa_is_desktop_gl(ctx
);
1824 case GL_PROXY_TEXTURE_CUBE_MAP
:
1825 return _mesa_is_desktop_gl(ctx
)
1826 && ctx
->Extensions
.ARB_texture_cube_map
;
1827 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1828 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1829 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1830 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1831 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1832 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1833 return ctx
->Extensions
.ARB_texture_cube_map
;
1834 case GL_TEXTURE_RECTANGLE_NV
:
1835 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1836 return _mesa_is_desktop_gl(ctx
)
1837 && ctx
->Extensions
.NV_texture_rectangle
;
1838 case GL_TEXTURE_1D_ARRAY_EXT
:
1839 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1840 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1848 case GL_PROXY_TEXTURE_3D
:
1849 return _mesa_is_desktop_gl(ctx
);
1850 case GL_TEXTURE_2D_ARRAY_EXT
:
1851 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1852 || _mesa_is_gles3(ctx
);
1853 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1854 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1855 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1856 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1857 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1862 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1869 * Check if the given texture target value is legal for a
1870 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1871 * The difference compared to legal_teximage_target() above is that
1872 * proxy targets are not supported.
1875 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1879 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1884 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1885 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1886 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1887 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1888 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1889 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1890 return ctx
->Extensions
.ARB_texture_cube_map
;
1891 case GL_TEXTURE_RECTANGLE_NV
:
1892 return _mesa_is_desktop_gl(ctx
)
1893 && ctx
->Extensions
.NV_texture_rectangle
;
1894 case GL_TEXTURE_1D_ARRAY_EXT
:
1895 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1903 case GL_TEXTURE_2D_ARRAY_EXT
:
1904 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1905 || _mesa_is_gles3(ctx
);
1906 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1907 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1908 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1913 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1921 * Helper function to determine if a texture object is mutable (in terms
1922 * of GL_ARB_texture_storage).
1925 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1927 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1928 return !texObj
->Immutable
;
1933 * Return expected size of a compressed texture.
1936 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1939 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1940 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1944 * Verify that a texture format is valid with a particular target
1946 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1947 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1950 * \param ctx GL context
1951 * \param target Texture target
1952 * \param internalFormat Internal format of the texture image
1953 * \param dimensions Dimensionality at the caller. This is \b not used
1954 * in the validation. It is only used when logging
1956 * \param caller Base name of the calling function (e.g.,
1957 * "glTexImage" or "glTexStorage").
1959 * \returns true if the combination is legal, false otherwise.
1962 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1963 GLenum target
, GLenum internalFormat
,
1964 unsigned dimensions
,
1967 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1968 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
1969 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1970 * Profile spec says:
1972 * "Textures with a base internal format of DEPTH_COMPONENT or
1973 * DEPTH_STENCIL are supported by texture image specification
1974 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1975 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1976 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1977 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1978 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1979 * formats in conjunction with any other target will result in an
1980 * INVALID_OPERATION error."
1982 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1983 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1985 if (target
!= GL_TEXTURE_1D
&&
1986 target
!= GL_PROXY_TEXTURE_1D
&&
1987 target
!= GL_TEXTURE_2D
&&
1988 target
!= GL_PROXY_TEXTURE_2D
&&
1989 target
!= GL_TEXTURE_1D_ARRAY
&&
1990 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1991 target
!= GL_TEXTURE_2D_ARRAY
&&
1992 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1993 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1994 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1995 !((_mesa_is_cube_face(target
) ||
1996 target
== GL_TEXTURE_CUBE_MAP
||
1997 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1998 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
1999 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2000 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2001 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2002 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2003 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2004 "%s%dD(bad target for depth texture)",
2005 caller
, dimensions
);
2014 texture_formats_agree(GLenum internalFormat
,
2017 GLboolean colorFormat
;
2018 GLboolean is_format_depth_or_depthstencil
;
2019 GLboolean is_internalFormat_depth_or_depthstencil
;
2021 /* Even though there are no color-index textures, we still have to support
2022 * uploading color-index data and remapping it to RGB via the
2023 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2025 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2027 is_internalFormat_depth_or_depthstencil
=
2028 _mesa_is_depth_format(internalFormat
) ||
2029 _mesa_is_depthstencil_format(internalFormat
);
2031 is_format_depth_or_depthstencil
=
2032 _mesa_is_depth_format(format
) ||
2033 _mesa_is_depthstencil_format(format
);
2035 colorFormat
= _mesa_is_color_format(format
);
2037 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2040 if (is_internalFormat_depth_or_depthstencil
!=
2041 is_format_depth_or_depthstencil
)
2044 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2051 * Test the glTexImage[123]D() parameters for errors.
2053 * \param ctx GL context.
2054 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2055 * \param target texture target given by the user (already validated).
2056 * \param level image level given by the user.
2057 * \param internalFormat internal format given by the user.
2058 * \param format pixel data format given by the user.
2059 * \param type pixel data type given by the user.
2060 * \param width image width given by the user.
2061 * \param height image height given by the user.
2062 * \param depth image depth given by the user.
2063 * \param border image border given by the user.
2065 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2067 * Verifies each of the parameters against the constants specified in
2068 * __struct gl_contextRec::Const and the supported extensions, and according
2069 * to the OpenGL specification.
2070 * Note that we don't fully error-check the width, height, depth values
2071 * here. That's done in _mesa_legal_texture_dimensions() which is used
2072 * by several other GL entrypoints. Plus, texture dims have a special
2073 * interaction with proxy textures.
2076 texture_error_check( struct gl_context
*ctx
,
2077 GLuint dimensions
, GLenum target
,
2078 GLint level
, GLint internalFormat
,
2079 GLenum format
, GLenum type
,
2080 GLint width
, GLint height
,
2081 GLint depth
, GLint border
)
2085 /* Note: for proxy textures, some error conditions immediately generate
2086 * a GL error in the usual way. But others do not generate a GL error.
2087 * Instead, they cause the width, height, depth, format fields of the
2088 * texture image to be zeroed-out. The GL spec seems to indicate that the
2089 * zero-out behaviour is only used in cases related to memory allocation.
2093 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2094 _mesa_error(ctx
, GL_INVALID_VALUE
,
2095 "glTexImage%dD(level=%d)", dimensions
, level
);
2100 if (border
< 0 || border
> 1 ||
2101 ((ctx
->API
!= API_OPENGL_COMPAT
||
2102 target
== GL_TEXTURE_RECTANGLE_NV
||
2103 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2104 _mesa_error(ctx
, GL_INVALID_VALUE
,
2105 "glTexImage%dD(border=%d)", dimensions
, border
);
2109 if (width
< 0 || height
< 0 || depth
< 0) {
2110 _mesa_error(ctx
, GL_INVALID_VALUE
,
2111 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2115 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2116 * combinations of format, internalFormat, and type that can be used.
2117 * Formats and types that require additional extensions (e.g., GL_FLOAT
2118 * requires GL_OES_texture_float) are filtered elsewhere.
2121 if (_mesa_is_gles(ctx
)) {
2122 if (_mesa_is_gles3(ctx
)) {
2123 err
= _mesa_es3_error_check_format_and_type(format
, type
,
2126 if (format
!= internalFormat
) {
2127 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2128 "glTexImage%dD(format = %s, internalFormat = %s)",
2130 _mesa_lookup_enum_by_nr(format
),
2131 _mesa_lookup_enum_by_nr(internalFormat
));
2135 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2137 if (err
!= GL_NO_ERROR
) {
2138 _mesa_error(ctx
, err
,
2139 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2141 _mesa_lookup_enum_by_nr(format
),
2142 _mesa_lookup_enum_by_nr(type
),
2143 _mesa_lookup_enum_by_nr(internalFormat
));
2148 /* Check internalFormat */
2149 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2150 _mesa_error(ctx
, GL_INVALID_VALUE
,
2151 "glTexImage%dD(internalFormat=%s)",
2152 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2156 /* Check incoming image format and type */
2157 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2158 if (err
!= GL_NO_ERROR
) {
2159 _mesa_error(ctx
, err
,
2160 "glTexImage%dD(incompatible format = %s, type = %s)",
2161 dimensions
, _mesa_lookup_enum_by_nr(format
),
2162 _mesa_lookup_enum_by_nr(type
));
2166 /* make sure internal format and format basically agree */
2167 if (!texture_formats_agree(internalFormat
, format
)) {
2168 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2169 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2170 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2171 _mesa_lookup_enum_by_nr(format
));
2175 /* additional checks for ycbcr textures */
2176 if (internalFormat
== GL_YCBCR_MESA
) {
2177 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2178 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2179 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2181 _mesa_snprintf(message
, sizeof(message
),
2182 "glTexImage%dD(format/type YCBCR mismatch)",
2184 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2185 return GL_TRUE
; /* error */
2187 if (target
!= GL_TEXTURE_2D
&&
2188 target
!= GL_PROXY_TEXTURE_2D
&&
2189 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2190 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2191 _mesa_error(ctx
, GL_INVALID_ENUM
,
2192 "glTexImage%dD(bad target for YCbCr texture)",
2198 _mesa_snprintf(message
, sizeof(message
),
2199 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2200 dimensions
, border
);
2201 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2206 /* additional checks for depth textures */
2207 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2208 dimensions
, "glTexImage"))
2211 /* additional checks for compressed textures */
2212 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2213 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2214 _mesa_error(ctx
, GL_INVALID_ENUM
,
2215 "glTexImage%dD(target can't be compressed)", dimensions
);
2218 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2219 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2220 "glTexImage%dD(no compression for format)", dimensions
);
2224 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2225 "glTexImage%dD(border!=0)", dimensions
);
2230 /* additional checks for integer textures */
2231 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2232 (_mesa_is_enum_format_integer(format
) !=
2233 _mesa_is_enum_format_integer(internalFormat
))) {
2234 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2235 "glTexImage%dD(integer/non-integer format mismatch)",
2240 if (!mutable_tex_object(ctx
, target
)) {
2241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2242 "glTexImage%dD(immutable texture)", dimensions
);
2246 /* if we get here, the parameters are OK */
2252 _mesa_compressed_texture_pixel_storage_error_check(struct gl_context
*ctx
,
2254 struct gl_pixelstore_attrib
*packing
,
2257 if (!_mesa_is_desktop_gl(ctx
) || !packing
->CompressedBlockSize
)
2260 if (packing
->CompressedBlockWidth
&& packing
->SkipPixels
% packing
->CompressedBlockWidth
) {
2261 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2262 "%s(skip-pixels %% block-width)", caller
);
2266 if (dimensions
> 1 && packing
->CompressedBlockHeight
&& packing
->SkipRows
% packing
->CompressedBlockHeight
) {
2267 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2268 "%s(skip-rows %% block-height)", caller
);
2272 if (dimensions
> 2 && packing
->CompressedBlockDepth
&& packing
->SkipImages
% packing
->CompressedBlockDepth
) {
2273 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2274 "%s(skip-images %% block-depth)", caller
);
2282 * Error checking for glCompressedTexImage[123]D().
2283 * Note that the width, height and depth values are not fully error checked
2285 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2288 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2289 GLenum target
, GLint level
,
2290 GLenum internalFormat
, GLsizei width
,
2291 GLsizei height
, GLsizei depth
, GLint border
,
2294 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2296 GLenum error
= GL_NO_ERROR
;
2297 char *reason
= ""; /* no error */
2299 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2301 error
= GL_INVALID_ENUM
;
2305 /* This will detect any invalid internalFormat value */
2306 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2307 _mesa_error(ctx
, GL_INVALID_ENUM
,
2308 "glCompressedTexImage%dD(internalFormat=%s)",
2309 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2313 switch (internalFormat
) {
2314 case GL_PALETTE4_RGB8_OES
:
2315 case GL_PALETTE4_RGBA8_OES
:
2316 case GL_PALETTE4_R5_G6_B5_OES
:
2317 case GL_PALETTE4_RGBA4_OES
:
2318 case GL_PALETTE4_RGB5_A1_OES
:
2319 case GL_PALETTE8_RGB8_OES
:
2320 case GL_PALETTE8_RGBA8_OES
:
2321 case GL_PALETTE8_R5_G6_B5_OES
:
2322 case GL_PALETTE8_RGBA4_OES
:
2323 case GL_PALETTE8_RGB5_A1_OES
:
2324 /* check level (note that level should be zero or less!) */
2325 if (level
> 0 || level
< -maxLevels
) {
2327 error
= GL_INVALID_VALUE
;
2331 if (dimensions
!= 2) {
2332 reason
= "compressed paletted textures must be 2D";
2333 error
= GL_INVALID_OPERATION
;
2337 /* Figure out the expected texture size (in bytes). This will be
2338 * checked against the actual size later.
2340 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2343 /* This is for the benefit of the TestProxyTexImage below. It expects
2344 * level to be non-negative. OES_compressed_paletted_texture uses a
2345 * weird mechanism where the level specified to glCompressedTexImage2D
2346 * is -(n-1) number of levels in the texture, and the data specifies the
2347 * complete mipmap stack. This is done to ensure the palette is the
2348 * same for all levels.
2355 if (level
< 0 || level
>= maxLevels
) {
2357 error
= GL_INVALID_VALUE
;
2361 /* Figure out the expected texture size (in bytes). This will be
2362 * checked against the actual size later.
2364 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2368 /* This should really never fail */
2369 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2370 reason
= "internalFormat";
2371 error
= GL_INVALID_ENUM
;
2375 /* No compressed formats support borders at this time */
2377 reason
= "border != 0";
2378 error
= GL_INVALID_VALUE
;
2382 /* Check for invalid pixel storage modes */
2383 if (!_mesa_compressed_texture_pixel_storage_error_check(ctx
, dimensions
,
2385 "glCompressedTexImage")) {
2389 /* check image size in bytes */
2390 if (expectedSize
!= imageSize
) {
2391 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2392 * if <imageSize> is not consistent with the format, dimensions, and
2393 * contents of the specified image.
2395 reason
= "imageSize inconsistant with width/height/format";
2396 error
= GL_INVALID_VALUE
;
2400 if (!mutable_tex_object(ctx
, target
)) {
2401 reason
= "immutable texture";
2402 error
= GL_INVALID_OPERATION
;
2409 /* Note: not all error paths exit through here. */
2410 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2417 * Test glTexSubImage[123]D() parameters for errors.
2419 * \param ctx GL context.
2420 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2421 * \param target texture target given by the user (already validated)
2422 * \param level image level given by the user.
2423 * \param xoffset sub-image x offset given by the user.
2424 * \param yoffset sub-image y offset given by the user.
2425 * \param zoffset sub-image z offset given by the user.
2426 * \param format pixel data format given by the user.
2427 * \param type pixel data type given by the user.
2428 * \param width image width given by the user.
2429 * \param height image height given by the user.
2430 * \param depth image depth given by the user.
2432 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2434 * Verifies each of the parameters against the constants specified in
2435 * __struct gl_contextRec::Const and the supported extensions, and according
2436 * to the OpenGL specification.
2439 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2440 GLenum target
, GLint level
,
2441 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2442 GLint width
, GLint height
, GLint depth
,
2443 GLenum format
, GLenum type
)
2445 struct gl_texture_object
*texObj
;
2446 struct gl_texture_image
*texImage
;
2449 /* check target (proxies not allowed) */
2450 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2451 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2452 dimensions
, _mesa_lookup_enum_by_nr(target
));
2457 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2458 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2463 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2464 * combinations of format and type that can be used. Formats and types
2465 * that require additional extensions (e.g., GL_FLOAT requires
2466 * GL_OES_texture_float) are filtered elsewhere.
2468 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2469 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2470 if (err
!= GL_NO_ERROR
) {
2471 _mesa_error(ctx
, err
,
2472 "glTexSubImage%dD(format = %s, type = %s)",
2474 _mesa_lookup_enum_by_nr(format
),
2475 _mesa_lookup_enum_by_nr(type
));
2480 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2481 if (err
!= GL_NO_ERROR
) {
2482 _mesa_error(ctx
, err
,
2483 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2484 dimensions
, _mesa_lookup_enum_by_nr(format
),
2485 _mesa_lookup_enum_by_nr(type
));
2489 /* Get dest texture object / image pointers */
2490 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2492 /* must be out of memory */
2493 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2497 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2499 /* non-existant texture level */
2500 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2501 "glTexSubImage%dD(invalid texture image)", dimensions
);
2505 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2506 texImage
, xoffset
, yoffset
, 0,
2507 width
, height
, 1)) {
2511 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2512 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2513 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2514 "glTexSubImage%dD(no compression for format)", dimensions
);
2519 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2520 /* both source and dest must be integer-valued, or neither */
2521 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2522 _mesa_is_enum_format_integer(format
)) {
2523 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2524 "glTexSubImage%dD(integer/non-integer format mismatch)",
2535 * Test glCopyTexImage[12]D() parameters for errors.
2537 * \param ctx GL context.
2538 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2539 * \param target texture target given by the user.
2540 * \param level image level given by the user.
2541 * \param internalFormat internal format given by the user.
2542 * \param width image width given by the user.
2543 * \param height image height given by the user.
2544 * \param border texture border.
2546 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2548 * Verifies each of the parameters against the constants specified in
2549 * __struct gl_contextRec::Const and the supported extensions, and according
2550 * to the OpenGL specification.
2553 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2554 GLenum target
, GLint level
, GLint internalFormat
,
2555 GLint width
, GLint height
, GLint border
)
2558 GLint rb_base_format
;
2559 struct gl_renderbuffer
*rb
;
2560 GLenum rb_internal_format
;
2563 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2564 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2565 dimensions
, _mesa_lookup_enum_by_nr(target
));
2570 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2571 _mesa_error(ctx
, GL_INVALID_VALUE
,
2572 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2576 /* Check that the source buffer is complete */
2577 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2578 if (ctx
->ReadBuffer
->_Status
== 0) {
2579 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2581 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2582 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2583 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2587 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2588 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2589 "glCopyTexImage%dD(multisample FBO)",
2596 if (border
< 0 || border
> 1 ||
2597 ((ctx
->API
!= API_OPENGL_COMPAT
||
2598 target
== GL_TEXTURE_RECTANGLE_NV
||
2599 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2600 _mesa_error(ctx
, GL_INVALID_VALUE
,
2601 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2605 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2607 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2608 "glCopyTexImage%dD(read buffer)", dimensions
);
2612 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2615 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2616 switch (internalFormat
) {
2621 case GL_LUMINANCE_ALPHA
:
2624 _mesa_error(ctx
, GL_INVALID_VALUE
,
2625 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2626 _mesa_lookup_enum_by_nr(internalFormat
));
2631 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2632 if (baseFormat
< 0) {
2633 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2634 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2635 _mesa_lookup_enum_by_nr(internalFormat
));
2639 rb_internal_format
= rb
->InternalFormat
;
2640 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2641 if (_mesa_is_color_format(internalFormat
)) {
2642 if (rb_base_format
< 0) {
2643 _mesa_error(ctx
, GL_INVALID_VALUE
,
2644 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2645 _mesa_lookup_enum_by_nr(internalFormat
));
2650 if (_mesa_is_gles(ctx
)) {
2652 if (_mesa_base_format_component_count(baseFormat
) >
2653 _mesa_base_format_component_count(rb_base_format
)) {
2656 if (baseFormat
== GL_DEPTH_COMPONENT
||
2657 baseFormat
== GL_DEPTH_STENCIL
||
2658 rb_base_format
== GL_DEPTH_COMPONENT
||
2659 rb_base_format
== GL_DEPTH_STENCIL
||
2660 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2661 baseFormat
== GL_ALPHA
) &&
2662 rb_base_format
!= GL_RGBA
) ||
2663 internalFormat
== GL_RGB9_E5
) {
2666 if (internalFormat
== GL_RGB9_E5
) {
2670 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2671 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2672 _mesa_lookup_enum_by_nr(internalFormat
));
2677 if (_mesa_is_gles3(ctx
)) {
2678 bool rb_is_srgb
= false;
2679 bool dst_is_srgb
= false;
2681 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2682 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2686 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2690 if (rb_is_srgb
!= dst_is_srgb
) {
2691 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2692 * OpenGLES 3.0.0 spec says:
2694 * "The error INVALID_OPERATION is also generated if the
2695 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2696 * framebuffer attachment corresponding to the read buffer
2697 * is LINEAR (see section 6.1.13) and internalformat is
2698 * one of the sRGB formats described in section 3.8.16, or
2699 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2700 * SRGB and internalformat is not one of the sRGB formats."
2702 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2703 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2708 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2709 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2710 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2714 /* From the EXT_texture_integer spec:
2716 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2717 * if the texture internalformat is an integer format and the read color
2718 * buffer is not an integer format, or if the internalformat is not an
2719 * integer format and the read color buffer is an integer format."
2721 if (_mesa_is_color_format(internalFormat
)) {
2722 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2723 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2724 if (is_int
|| is_rbint
) {
2725 if (is_int
!= is_rbint
) {
2726 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2727 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2729 } else if (_mesa_is_gles(ctx
) &&
2730 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2731 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2732 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2733 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2739 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2740 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2741 _mesa_error(ctx
, GL_INVALID_ENUM
,
2742 "glCopyTexImage%dD(target)", dimensions
);
2745 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2746 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2747 "glCopyTexImage%dD(no compression for format)", dimensions
);
2751 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2752 "glCopyTexImage%dD(border!=0)", dimensions
);
2757 if (!mutable_tex_object(ctx
, target
)) {
2758 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2759 "glCopyTexImage%dD(immutable texture)", dimensions
);
2763 /* if we get here, the parameters are OK */
2769 * Test glCopyTexSubImage[12]D() parameters for errors.
2770 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2773 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2774 GLenum target
, GLint level
,
2775 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2776 GLint width
, GLint height
)
2778 struct gl_texture_object
*texObj
;
2779 struct gl_texture_image
*texImage
;
2781 /* Check that the source buffer is complete */
2782 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2783 if (ctx
->ReadBuffer
->_Status
== 0) {
2784 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2786 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2787 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2788 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2792 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2793 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2794 "glCopyTexSubImage%dD(multisample FBO)",
2800 /* check target (proxies not allowed) */
2801 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2802 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2803 dimensions
, _mesa_lookup_enum_by_nr(target
));
2808 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2809 _mesa_error(ctx
, GL_INVALID_VALUE
,
2810 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2814 /* Get dest texture object / image pointers */
2815 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2817 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2821 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2823 /* destination image does not exist */
2824 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2825 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2829 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2830 dimensions
, texImage
,
2831 xoffset
, yoffset
, zoffset
,
2832 width
, height
, 1)) {
2836 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2837 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2838 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2839 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2844 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2845 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2849 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2850 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2851 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2852 dimensions
, texImage
->_BaseFormat
);
2856 /* From the EXT_texture_integer spec:
2858 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2859 * if the texture internalformat is an integer format and the read color
2860 * buffer is not an integer format, or if the internalformat is not an
2861 * integer format and the read color buffer is an integer format."
2863 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2864 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2866 if (_mesa_is_format_integer_color(rb
->Format
) !=
2867 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2868 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2869 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2874 /* if we get here, the parameters are OK */
2879 /** Callback info for walking over FBO hash table */
2882 struct gl_context
*ctx
;
2883 struct gl_texture_object
*texObj
;
2889 * Check render to texture callback. Called from _mesa_HashWalk().
2892 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2894 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2895 const struct cb_info
*info
= (struct cb_info
*) userData
;
2896 struct gl_context
*ctx
= info
->ctx
;
2897 const struct gl_texture_object
*texObj
= info
->texObj
;
2898 const GLuint level
= info
->level
, face
= info
->face
;
2900 /* If this is a user-created FBO */
2901 if (_mesa_is_user_fbo(fb
)) {
2903 /* check if any of the FBO's attachments point to 'texObj' */
2904 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2905 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2906 if (att
->Type
== GL_TEXTURE
&&
2907 att
->Texture
== texObj
&&
2908 att
->TextureLevel
== level
&&
2909 att
->CubeMapFace
== face
) {
2910 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2911 ASSERT(att
->Renderbuffer
->TexImage
);
2912 /* Mark fb status as indeterminate to force re-validation */
2921 * When a texture image is specified we have to check if it's bound to
2922 * any framebuffer objects (render to texture) in order to detect changes
2923 * in size or format since that effects FBO completeness.
2924 * Any FBOs rendering into the texture must be re-validated.
2927 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2928 struct gl_texture_object
*texObj
,
2929 GLuint face
, GLuint level
)
2931 /* Only check this texture if it's been marked as RenderToTexture */
2932 if (texObj
->_RenderToTexture
) {
2933 struct cb_info info
;
2935 info
.texObj
= texObj
;
2938 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2944 * If the texture object's GenerateMipmap flag is set and we've
2945 * changed the texture base level image, regenerate the rest of the
2946 * mipmap levels now.
2949 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2950 struct gl_texture_object
*texObj
, GLint level
)
2952 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2953 if (texObj
->GenerateMipmap
&&
2954 level
== texObj
->BaseLevel
&&
2955 level
< texObj
->MaxLevel
) {
2956 ASSERT(ctx
->Driver
.GenerateMipmap
);
2957 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2962 /** Debug helper: override the user-requested internal format */
2964 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2967 if (internalFormat
== GL_RGBA16F_ARB
||
2968 internalFormat
== GL_RGBA32F_ARB
) {
2969 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2972 else if (internalFormat
== GL_RGB16F_ARB
||
2973 internalFormat
== GL_RGB32F_ARB
) {
2974 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2977 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2978 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2979 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2980 return GL_LUMINANCE_ALPHA
;
2982 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2983 internalFormat
== GL_LUMINANCE32F_ARB
) {
2984 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2985 return GL_LUMINANCE
;
2987 else if (internalFormat
== GL_ALPHA16F_ARB
||
2988 internalFormat
== GL_ALPHA32F_ARB
) {
2989 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2993 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2994 internalFormat = GL_RGBA;
2998 return internalFormat
;
3001 return internalFormat
;
3007 * Choose the actual hardware format for a texture image.
3008 * Try to use the same format as the previous image level when possible.
3009 * Otherwise, ask the driver for the best format.
3010 * It's important to try to choose a consistant format for all levels
3011 * for efficient texture memory layout/allocation. In particular, this
3012 * comes up during automatic mipmap generation.
3015 _mesa_choose_texture_format(struct gl_context
*ctx
,
3016 struct gl_texture_object
*texObj
,
3017 GLenum target
, GLint level
,
3018 GLenum internalFormat
, GLenum format
, GLenum type
)
3022 /* see if we've already chosen a format for the previous level */
3024 struct gl_texture_image
*prevImage
=
3025 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
3026 /* See if the prev level is defined and has an internal format which
3027 * matches the new internal format.
3030 prevImage
->Width
> 0 &&
3031 prevImage
->InternalFormat
== internalFormat
) {
3032 /* use the same format */
3033 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3034 return prevImage
->TexFormat
;
3038 /* If the application requested compression to an S3TC format but we don't
3039 * have the DXTn library, force a generic compressed format instead.
3041 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3042 const GLenum before
= internalFormat
;
3044 switch (internalFormat
) {
3045 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3046 if (!ctx
->Mesa_DXTn
)
3047 internalFormat
= GL_COMPRESSED_RGB
;
3049 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3050 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3051 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3052 if (!ctx
->Mesa_DXTn
)
3053 internalFormat
= GL_COMPRESSED_RGBA
;
3059 if (before
!= internalFormat
) {
3061 "DXT compression requested (%s), "
3062 "but libtxc_dxtn library not installed. Using %s "
3064 _mesa_lookup_enum_by_nr(before
),
3065 _mesa_lookup_enum_by_nr(internalFormat
));
3069 /* choose format from scratch */
3070 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3072 ASSERT(f
!= MESA_FORMAT_NONE
);
3078 * Adjust pixel unpack params and image dimensions to strip off the
3079 * one-pixel texture border.
3081 * Gallium and intel don't support texture borders. They've seldem been used
3082 * and seldom been implemented correctly anyway.
3084 * \param unpackNew returns the new pixel unpack parameters
3087 strip_texture_border(GLenum target
,
3088 GLint
*width
, GLint
*height
, GLint
*depth
,
3089 const struct gl_pixelstore_attrib
*unpack
,
3090 struct gl_pixelstore_attrib
*unpackNew
)
3096 *unpackNew
= *unpack
;
3098 if (unpackNew
->RowLength
== 0)
3099 unpackNew
->RowLength
= *width
;
3101 if (unpackNew
->ImageHeight
== 0)
3102 unpackNew
->ImageHeight
= *height
;
3104 assert(*width
>= 3);
3105 unpackNew
->SkipPixels
++; /* skip the border */
3106 *width
= *width
- 2; /* reduce the width by two border pixels */
3108 /* The min height of a texture with a border is 3 */
3109 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3110 unpackNew
->SkipRows
++; /* skip the border */
3111 *height
= *height
- 2; /* reduce the height by two border pixels */
3115 target
!= GL_TEXTURE_2D_ARRAY
&&
3116 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3117 unpackNew
->SkipImages
++; /* skip the border */
3118 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3124 * Common code to implement all the glTexImage1D/2D/3D functions
3125 * as well as glCompressedTexImage1D/2D/3D.
3126 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3127 * \param format the user's image format (only used if !compressed)
3128 * \param type the user's image type (only used if !compressed)
3129 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3132 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3133 GLenum target
, GLint level
, GLint internalFormat
,
3134 GLsizei width
, GLsizei height
, GLsizei depth
,
3135 GLint border
, GLenum format
, GLenum type
,
3136 GLsizei imageSize
, const GLvoid
*pixels
)
3138 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3139 struct gl_pixelstore_attrib unpack_no_border
;
3140 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3141 struct gl_texture_object
*texObj
;
3142 mesa_format texFormat
;
3143 GLboolean dimensionsOK
, sizeOK
;
3145 FLUSH_VERTICES(ctx
, 0);
3147 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3150 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3152 _mesa_lookup_enum_by_nr(target
), level
,
3153 _mesa_lookup_enum_by_nr(internalFormat
),
3154 width
, height
, depth
, border
, pixels
);
3157 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3159 _mesa_lookup_enum_by_nr(target
), level
,
3160 _mesa_lookup_enum_by_nr(internalFormat
),
3161 width
, height
, depth
, border
,
3162 _mesa_lookup_enum_by_nr(format
),
3163 _mesa_lookup_enum_by_nr(type
), pixels
);
3166 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3168 /* target error checking */
3169 if (!legal_teximage_target(ctx
, dims
, target
)) {
3170 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3171 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3175 /* general error checking */
3177 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3179 width
, height
, depth
,
3184 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3185 format
, type
, width
, height
, depth
, border
))
3189 /* Here we convert a cpal compressed image into a regular glTexImage2D
3190 * call by decompressing the texture. If we really want to support cpal
3191 * textures in any driver this would have to be changed.
3193 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3194 switch (internalFormat
) {
3195 case GL_PALETTE4_RGB8_OES
:
3196 case GL_PALETTE4_RGBA8_OES
:
3197 case GL_PALETTE4_R5_G6_B5_OES
:
3198 case GL_PALETTE4_RGBA4_OES
:
3199 case GL_PALETTE4_RGB5_A1_OES
:
3200 case GL_PALETTE8_RGB8_OES
:
3201 case GL_PALETTE8_RGBA8_OES
:
3202 case GL_PALETTE8_R5_G6_B5_OES
:
3203 case GL_PALETTE8_RGBA4_OES
:
3204 case GL_PALETTE8_RGB5_A1_OES
:
3205 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3206 width
, height
, imageSize
, pixels
);
3211 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3215 /* For glCompressedTexImage() the driver has no choice about the
3216 * texture format since we'll never transcode the user's compressed
3217 * image data. The internalFormat was error checked earlier.
3219 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3222 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3223 internalFormat
, format
, type
);
3226 assert(texFormat
!= MESA_FORMAT_NONE
);
3228 /* check that width, height, depth are legal for the mipmap level */
3229 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3230 height
, depth
, border
);
3232 /* check that the texture won't take too much memory, etc */
3233 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3235 width
, height
, depth
, border
);
3237 if (_mesa_is_proxy_texture(target
)) {
3238 /* Proxy texture: just clear or set state depending on error checking */
3239 struct gl_texture_image
*texImage
=
3240 get_proxy_tex_image(ctx
, target
, level
);
3243 return; /* GL_OUT_OF_MEMORY already recorded */
3245 if (dimensionsOK
&& sizeOK
) {
3246 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3247 border
, internalFormat
, texFormat
);
3250 clear_teximage_fields(texImage
);
3254 /* non-proxy target */
3255 const GLuint face
= _mesa_tex_target_to_face(target
);
3256 struct gl_texture_image
*texImage
;
3258 if (!dimensionsOK
) {
3259 _mesa_error(ctx
, GL_INVALID_VALUE
,
3260 "glTexImage%uD(invalid width or height or depth)",
3266 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3267 "glTexImage%uD(image too large)", dims
);
3271 /* Allow a hardware driver to just strip out the border, to provide
3272 * reliable but slightly incorrect hardware rendering instead of
3273 * rarely-tested software fallback rendering.
3275 if (border
&& ctx
->Const
.StripTextureBorder
) {
3276 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3279 unpack
= &unpack_no_border
;
3282 if (ctx
->NewState
& _NEW_PIXEL
)
3283 _mesa_update_state(ctx
);
3285 _mesa_lock_texture(ctx
, texObj
);
3287 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3290 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3293 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3295 _mesa_init_teximage_fields(ctx
, texImage
,
3296 width
, height
, depth
,
3297 border
, internalFormat
, texFormat
);
3299 /* Give the texture to the driver. <pixels> may be null. */
3300 if (width
> 0 && height
> 0 && depth
> 0) {
3302 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3306 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3307 type
, pixels
, unpack
);
3311 check_gen_mipmap(ctx
, target
, texObj
, level
);
3313 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3315 _mesa_dirty_texobj(ctx
, texObj
);
3318 _mesa_unlock_texture(ctx
, texObj
);
3325 * Called from the API. Note that width includes the border.
3328 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3329 GLsizei width
, GLint border
, GLenum format
,
3330 GLenum type
, const GLvoid
*pixels
)
3332 GET_CURRENT_CONTEXT(ctx
);
3333 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3334 border
, format
, type
, 0, pixels
);
3339 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3340 GLsizei width
, GLsizei height
, GLint border
,
3341 GLenum format
, GLenum type
,
3342 const GLvoid
*pixels
)
3344 GET_CURRENT_CONTEXT(ctx
);
3345 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3346 border
, format
, type
, 0, pixels
);
3351 * Called by the API or display list executor.
3352 * Note that width and height include the border.
3355 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3356 GLsizei width
, GLsizei height
, GLsizei depth
,
3357 GLint border
, GLenum format
, GLenum type
,
3358 const GLvoid
*pixels
)
3360 GET_CURRENT_CONTEXT(ctx
);
3361 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3362 width
, height
, depth
,
3363 border
, format
, type
, 0, pixels
);
3368 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3369 GLsizei width
, GLsizei height
, GLsizei depth
,
3370 GLint border
, GLenum format
, GLenum type
,
3371 const GLvoid
*pixels
)
3373 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3374 depth
, border
, format
, type
, pixels
);
3379 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3381 struct gl_texture_object
*texObj
;
3382 struct gl_texture_image
*texImage
;
3384 GET_CURRENT_CONTEXT(ctx
);
3385 FLUSH_VERTICES(ctx
, 0);
3389 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3391 case GL_TEXTURE_EXTERNAL_OES
:
3393 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3396 valid_target
= false;
3400 if (!valid_target
) {
3401 _mesa_error(ctx
, GL_INVALID_ENUM
,
3402 "glEGLImageTargetTexture2D(target=%d)", target
);
3407 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3408 "glEGLImageTargetTexture2D(image=%p)", image
);
3412 if (ctx
->NewState
& _NEW_PIXEL
)
3413 _mesa_update_state(ctx
);
3415 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3416 _mesa_lock_texture(ctx
, texObj
);
3418 if (texObj
->Immutable
) {
3419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3420 "glEGLImageTargetTexture2D(texture is immutable)");
3421 _mesa_unlock_texture(ctx
, texObj
);
3425 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3427 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3429 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3431 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3432 texObj
, texImage
, image
);
3434 _mesa_dirty_texobj(ctx
, texObj
);
3436 _mesa_unlock_texture(ctx
, texObj
);
3443 * Implement all the glTexSubImage1/2/3D() functions.
3446 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3447 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3448 GLsizei width
, GLsizei height
, GLsizei depth
,
3449 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3451 struct gl_texture_object
*texObj
;
3452 struct gl_texture_image
*texImage
;
3454 FLUSH_VERTICES(ctx
, 0);
3456 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3457 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3459 _mesa_lookup_enum_by_nr(target
), level
,
3460 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3461 _mesa_lookup_enum_by_nr(format
),
3462 _mesa_lookup_enum_by_nr(type
), pixels
);
3464 /* check target (proxies not allowed) */
3465 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3466 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3467 dims
, _mesa_lookup_enum_by_nr(target
));
3471 if (ctx
->NewState
& _NEW_PIXEL
)
3472 _mesa_update_state(ctx
);
3474 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3475 xoffset
, yoffset
, zoffset
,
3476 width
, height
, depth
, format
, type
)) {
3477 return; /* error was detected */
3480 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3482 _mesa_lock_texture(ctx
, texObj
);
3484 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3486 if (width
> 0 && height
> 0 && depth
> 0) {
3487 /* If we have a border, offset=-1 is legal. Bias by border width. */
3490 if (target
!= GL_TEXTURE_2D_ARRAY
)
3491 zoffset
+= texImage
->Border
;
3494 if (target
!= GL_TEXTURE_1D_ARRAY
)
3495 yoffset
+= texImage
->Border
;
3498 xoffset
+= texImage
->Border
;
3501 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3502 xoffset
, yoffset
, zoffset
,
3503 width
, height
, depth
,
3504 format
, type
, pixels
, &ctx
->Unpack
);
3506 check_gen_mipmap(ctx
, target
, texObj
, level
);
3508 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3509 * the texel data, not the texture format, size, etc.
3513 _mesa_unlock_texture(ctx
, texObj
);
3518 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3519 GLint xoffset
, GLsizei width
,
3520 GLenum format
, GLenum type
,
3521 const GLvoid
*pixels
)
3523 GET_CURRENT_CONTEXT(ctx
);
3524 texsubimage(ctx
, 1, target
, level
,
3527 format
, type
, pixels
);
3532 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3533 GLint xoffset
, GLint yoffset
,
3534 GLsizei width
, GLsizei height
,
3535 GLenum format
, GLenum type
,
3536 const GLvoid
*pixels
)
3538 GET_CURRENT_CONTEXT(ctx
);
3539 texsubimage(ctx
, 2, target
, level
,
3540 xoffset
, yoffset
, 0,
3542 format
, type
, pixels
);
3548 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3549 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3550 GLsizei width
, GLsizei height
, GLsizei depth
,
3551 GLenum format
, GLenum type
,
3552 const GLvoid
*pixels
)
3554 GET_CURRENT_CONTEXT(ctx
);
3555 texsubimage(ctx
, 3, target
, level
,
3556 xoffset
, yoffset
, zoffset
,
3557 width
, height
, depth
,
3558 format
, type
, pixels
);
3564 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3565 * from. This depends on whether the texture contains color or depth values.
3567 static struct gl_renderbuffer
*
3568 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3570 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3571 /* reading from depth/stencil buffer */
3572 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3575 /* copying from color buffer */
3576 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3581 copytexsubimage_by_slice(struct gl_context
*ctx
,
3582 struct gl_texture_image
*texImage
,
3584 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3585 struct gl_renderbuffer
*rb
,
3587 GLsizei width
, GLsizei height
)
3589 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3592 /* For 1D arrays, we copy each scanline of the source rectangle into the
3595 assert(zoffset
== 0);
3597 for (slice
= 0; slice
< height
; slice
++) {
3598 assert(yoffset
+ slice
< texImage
->Height
);
3599 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3600 xoffset
, 0, yoffset
+ slice
,
3601 rb
, x
, y
+ slice
, width
, 1);
3604 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3605 xoffset
, yoffset
, zoffset
,
3606 rb
, x
, y
, width
, height
);
3612 * Implement the glCopyTexImage1/2D() functions.
3615 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3616 GLenum target
, GLint level
, GLenum internalFormat
,
3617 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3619 struct gl_texture_object
*texObj
;
3620 struct gl_texture_image
*texImage
;
3621 const GLuint face
= _mesa_tex_target_to_face(target
);
3622 mesa_format texFormat
;
3624 FLUSH_VERTICES(ctx
, 0);
3626 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3627 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3629 _mesa_lookup_enum_by_nr(target
), level
,
3630 _mesa_lookup_enum_by_nr(internalFormat
),
3631 x
, y
, width
, height
, border
);
3633 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3634 _mesa_update_state(ctx
);
3636 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3637 width
, height
, border
))
3640 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3642 _mesa_error(ctx
, GL_INVALID_VALUE
,
3643 "glCopyTexImage%uD(invalid width or height)", dims
);
3647 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3650 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3651 internalFormat
, GL_NONE
, GL_NONE
);
3652 assert(texFormat
!= MESA_FORMAT_NONE
);
3654 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3656 width
, height
, 1, border
)) {
3657 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3658 "glCopyTexImage%uD(image too large)", dims
);
3662 if (border
&& ctx
->Const
.StripTextureBorder
) {
3664 width
-= border
* 2;
3667 height
-= border
* 2;
3672 _mesa_lock_texture(ctx
, texObj
);
3674 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3677 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3680 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3682 /* Free old texture image */
3683 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3685 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3686 border
, internalFormat
, texFormat
);
3688 if (width
&& height
) {
3689 /* Allocate texture memory (no pixel data yet) */
3690 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3692 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3694 struct gl_renderbuffer
*srcRb
=
3695 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3697 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3699 srcRb
, srcX
, srcY
, width
, height
);
3702 check_gen_mipmap(ctx
, target
, texObj
, level
);
3705 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3707 _mesa_dirty_texobj(ctx
, texObj
);
3710 _mesa_unlock_texture(ctx
, texObj
);
3716 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3717 GLenum internalFormat
,
3719 GLsizei width
, GLint border
)
3721 GET_CURRENT_CONTEXT(ctx
);
3722 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3728 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3729 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3732 GET_CURRENT_CONTEXT(ctx
);
3733 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3734 x
, y
, width
, height
, border
);
3740 * Implementation for glCopyTexSubImage1/2/3D() functions.
3743 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3744 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3745 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3747 struct gl_texture_object
*texObj
;
3748 struct gl_texture_image
*texImage
;
3750 FLUSH_VERTICES(ctx
, 0);
3752 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3753 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3755 _mesa_lookup_enum_by_nr(target
),
3756 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3758 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3759 _mesa_update_state(ctx
);
3761 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3762 xoffset
, yoffset
, zoffset
, width
, height
)) {
3766 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3768 _mesa_lock_texture(ctx
, texObj
);
3770 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3772 /* If we have a border, offset=-1 is legal. Bias by border width. */
3775 if (target
!= GL_TEXTURE_2D_ARRAY
)
3776 zoffset
+= texImage
->Border
;
3779 if (target
!= GL_TEXTURE_1D_ARRAY
)
3780 yoffset
+= texImage
->Border
;
3783 xoffset
+= texImage
->Border
;
3786 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3788 struct gl_renderbuffer
*srcRb
=
3789 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3791 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3792 xoffset
, yoffset
, zoffset
,
3793 srcRb
, x
, y
, width
, height
);
3795 check_gen_mipmap(ctx
, target
, texObj
, level
);
3797 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3798 * the texel data, not the texture format, size, etc.
3802 _mesa_unlock_texture(ctx
, texObj
);
3807 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3808 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3810 GET_CURRENT_CONTEXT(ctx
);
3811 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3817 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3818 GLint xoffset
, GLint yoffset
,
3819 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3821 GET_CURRENT_CONTEXT(ctx
);
3822 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3829 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3830 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3831 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3833 GET_CURRENT_CONTEXT(ctx
);
3834 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3835 x
, y
, width
, height
);
3839 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
3840 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3841 GLsizei width
, GLsizei height
, GLsizei depth
,
3842 GLenum format
, GLenum type
, const void *data
)
3848 _mesa_ClearTexImage( GLuint texture
, GLint level
,
3849 GLenum format
, GLenum type
, const void *data
)
3857 /**********************************************************************/
3858 /****** Compressed Textures ******/
3859 /**********************************************************************/
3863 * Error checking for glCompressedTexSubImage[123]D().
3864 * \return error code or GL_NO_ERROR.
3867 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3868 GLenum target
, GLint level
,
3869 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3870 GLsizei width
, GLsizei height
, GLsizei depth
,
3871 GLenum format
, GLsizei imageSize
)
3873 struct gl_texture_object
*texObj
;
3874 struct gl_texture_image
*texImage
;
3882 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3883 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3884 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3885 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3886 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3887 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3891 targetOK
= GL_FALSE
;
3896 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3900 /* no 1D compressed textures at this time */
3901 targetOK
= GL_FALSE
;
3906 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexSubImage%uD(target)",
3911 /* this will catch any invalid compressed format token */
3912 if (!_mesa_is_compressed_format(ctx
, format
)) {
3913 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3918 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3919 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage%uD(level=%d)",
3924 /* Check for invalid pixel storage modes */
3925 if (!_mesa_compressed_texture_pixel_storage_error_check(ctx
, dims
,
3927 "glCompressedTexSubImage")) {
3932 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3933 if (expectedSize
!= imageSize
) {
3934 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage%uD(size=%d)",
3939 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3941 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3942 "glCompressedTexSubImage%uD()", dims
);
3946 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3948 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3949 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3953 if ((GLint
) format
!= texImage
->InternalFormat
) {
3954 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3955 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3959 if (compressedteximage_only_format(ctx
, format
)) {
3960 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3961 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3966 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3967 texImage
, xoffset
, yoffset
, zoffset
,
3968 width
, height
, depth
)) {
3977 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3978 GLenum internalFormat
, GLsizei width
,
3979 GLint border
, GLsizei imageSize
,
3982 GET_CURRENT_CONTEXT(ctx
);
3983 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3984 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3989 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3990 GLenum internalFormat
, GLsizei width
,
3991 GLsizei height
, GLint border
, GLsizei imageSize
,
3994 GET_CURRENT_CONTEXT(ctx
);
3995 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3996 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4001 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4002 GLenum internalFormat
, GLsizei width
,
4003 GLsizei height
, GLsizei depth
, GLint border
,
4004 GLsizei imageSize
, const GLvoid
*data
)
4006 GET_CURRENT_CONTEXT(ctx
);
4007 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4008 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4013 * Common helper for glCompressedTexSubImage1/2/3D().
4016 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
4017 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4018 GLsizei width
, GLsizei height
, GLsizei depth
,
4019 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
4021 struct gl_texture_object
*texObj
;
4022 struct gl_texture_image
*texImage
;
4023 GET_CURRENT_CONTEXT(ctx
);
4024 FLUSH_VERTICES(ctx
, 0);
4026 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
4027 xoffset
, yoffset
, zoffset
,
4028 width
, height
, depth
,
4029 format
, imageSize
)) {
4033 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4035 _mesa_lock_texture(ctx
, texObj
);
4037 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
4040 if (width
> 0 && height
> 0 && depth
> 0) {
4041 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4042 xoffset
, yoffset
, zoffset
,
4043 width
, height
, depth
,
4044 format
, imageSize
, data
);
4046 check_gen_mipmap(ctx
, target
, texObj
, level
);
4048 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4049 * the texel data, not the texture format, size, etc.
4053 _mesa_unlock_texture(ctx
, texObj
);
4058 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4059 GLsizei width
, GLenum format
,
4060 GLsizei imageSize
, const GLvoid
*data
)
4062 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
4063 format
, imageSize
, data
);
4068 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4069 GLint yoffset
, GLsizei width
, GLsizei height
,
4070 GLenum format
, GLsizei imageSize
,
4073 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
4074 width
, height
, 1, format
, imageSize
, data
);
4079 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4080 GLint yoffset
, GLint zoffset
, GLsizei width
,
4081 GLsizei height
, GLsizei depth
, GLenum format
,
4082 GLsizei imageSize
, const GLvoid
*data
)
4084 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
4085 width
, height
, depth
, format
, imageSize
, data
);
4089 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4091 if (ctx
->API
!= API_OPENGL_CORE
) {
4092 switch (internalFormat
) {
4094 return MESA_FORMAT_A_UNORM8
;
4096 return MESA_FORMAT_A_UNORM16
;
4097 case GL_ALPHA16F_ARB
:
4098 return MESA_FORMAT_A_FLOAT16
;
4099 case GL_ALPHA32F_ARB
:
4100 return MESA_FORMAT_A_FLOAT32
;
4101 case GL_ALPHA8I_EXT
:
4102 return MESA_FORMAT_A_SINT8
;
4103 case GL_ALPHA16I_EXT
:
4104 return MESA_FORMAT_A_SINT16
;
4105 case GL_ALPHA32I_EXT
:
4106 return MESA_FORMAT_A_SINT32
;
4107 case GL_ALPHA8UI_EXT
:
4108 return MESA_FORMAT_A_UINT8
;
4109 case GL_ALPHA16UI_EXT
:
4110 return MESA_FORMAT_A_UINT16
;
4111 case GL_ALPHA32UI_EXT
:
4112 return MESA_FORMAT_A_UINT32
;
4114 return MESA_FORMAT_L_UNORM8
;
4115 case GL_LUMINANCE16
:
4116 return MESA_FORMAT_L_UNORM16
;
4117 case GL_LUMINANCE16F_ARB
:
4118 return MESA_FORMAT_L_FLOAT16
;
4119 case GL_LUMINANCE32F_ARB
:
4120 return MESA_FORMAT_L_FLOAT32
;
4121 case GL_LUMINANCE8I_EXT
:
4122 return MESA_FORMAT_L_SINT8
;
4123 case GL_LUMINANCE16I_EXT
:
4124 return MESA_FORMAT_L_SINT16
;
4125 case GL_LUMINANCE32I_EXT
:
4126 return MESA_FORMAT_L_SINT32
;
4127 case GL_LUMINANCE8UI_EXT
:
4128 return MESA_FORMAT_L_UINT8
;
4129 case GL_LUMINANCE16UI_EXT
:
4130 return MESA_FORMAT_L_UINT16
;
4131 case GL_LUMINANCE32UI_EXT
:
4132 return MESA_FORMAT_L_UINT32
;
4133 case GL_LUMINANCE8_ALPHA8
:
4134 return MESA_FORMAT_L8A8_UNORM
;
4135 case GL_LUMINANCE16_ALPHA16
:
4136 return MESA_FORMAT_L16A16_UNORM
;
4137 case GL_LUMINANCE_ALPHA16F_ARB
:
4138 return MESA_FORMAT_LA_FLOAT16
;
4139 case GL_LUMINANCE_ALPHA32F_ARB
:
4140 return MESA_FORMAT_LA_FLOAT32
;
4141 case GL_LUMINANCE_ALPHA8I_EXT
:
4142 return MESA_FORMAT_LA_SINT8
;
4143 case GL_LUMINANCE_ALPHA16I_EXT
:
4144 return MESA_FORMAT_LA_SINT8
;
4145 case GL_LUMINANCE_ALPHA32I_EXT
:
4146 return MESA_FORMAT_LA_SINT16
;
4147 case GL_LUMINANCE_ALPHA8UI_EXT
:
4148 return MESA_FORMAT_LA_UINT8
;
4149 case GL_LUMINANCE_ALPHA16UI_EXT
:
4150 return MESA_FORMAT_LA_UINT16
;
4151 case GL_LUMINANCE_ALPHA32UI_EXT
:
4152 return MESA_FORMAT_LA_UINT32
;
4154 return MESA_FORMAT_I_UNORM8
;
4155 case GL_INTENSITY16
:
4156 return MESA_FORMAT_I_UNORM16
;
4157 case GL_INTENSITY16F_ARB
:
4158 return MESA_FORMAT_I_FLOAT16
;
4159 case GL_INTENSITY32F_ARB
:
4160 return MESA_FORMAT_I_FLOAT32
;
4161 case GL_INTENSITY8I_EXT
:
4162 return MESA_FORMAT_I_SINT8
;
4163 case GL_INTENSITY16I_EXT
:
4164 return MESA_FORMAT_I_SINT16
;
4165 case GL_INTENSITY32I_EXT
:
4166 return MESA_FORMAT_I_SINT32
;
4167 case GL_INTENSITY8UI_EXT
:
4168 return MESA_FORMAT_I_UINT8
;
4169 case GL_INTENSITY16UI_EXT
:
4170 return MESA_FORMAT_I_UINT16
;
4171 case GL_INTENSITY32UI_EXT
:
4172 return MESA_FORMAT_I_UINT32
;
4178 if (ctx
->API
== API_OPENGL_CORE
&&
4179 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4180 switch (internalFormat
) {
4182 return MESA_FORMAT_RGB_FLOAT32
;
4184 return MESA_FORMAT_RGB_UINT32
;
4186 return MESA_FORMAT_RGB_SINT32
;
4192 switch (internalFormat
) {
4194 return MESA_FORMAT_R8G8B8A8_UNORM
;
4196 return MESA_FORMAT_RGBA_UNORM16
;
4197 case GL_RGBA16F_ARB
:
4198 return MESA_FORMAT_RGBA_FLOAT16
;
4199 case GL_RGBA32F_ARB
:
4200 return MESA_FORMAT_RGBA_FLOAT32
;
4202 return MESA_FORMAT_RGBA_SINT8
;
4203 case GL_RGBA16I_EXT
:
4204 return MESA_FORMAT_RGBA_SINT16
;
4205 case GL_RGBA32I_EXT
:
4206 return MESA_FORMAT_RGBA_SINT32
;
4207 case GL_RGBA8UI_EXT
:
4208 return MESA_FORMAT_RGBA_UINT8
;
4209 case GL_RGBA16UI_EXT
:
4210 return MESA_FORMAT_RGBA_UINT16
;
4211 case GL_RGBA32UI_EXT
:
4212 return MESA_FORMAT_RGBA_UINT32
;
4215 return MESA_FORMAT_R8G8_UNORM
;
4217 return MESA_FORMAT_R16G16_UNORM
;
4219 return MESA_FORMAT_RG_FLOAT16
;
4221 return MESA_FORMAT_RG_FLOAT32
;
4223 return MESA_FORMAT_RG_SINT8
;
4225 return MESA_FORMAT_RG_SINT16
;
4227 return MESA_FORMAT_RG_SINT32
;
4229 return MESA_FORMAT_RG_UINT8
;
4231 return MESA_FORMAT_RG_UINT16
;
4233 return MESA_FORMAT_RG_UINT32
;
4236 return MESA_FORMAT_R_UNORM8
;
4238 return MESA_FORMAT_R_UNORM16
;
4240 return MESA_FORMAT_R_FLOAT16
;
4242 return MESA_FORMAT_R_FLOAT32
;
4244 return MESA_FORMAT_R_SINT8
;
4246 return MESA_FORMAT_R_SINT16
;
4248 return MESA_FORMAT_R_SINT32
;
4250 return MESA_FORMAT_R_UINT8
;
4252 return MESA_FORMAT_R_UINT16
;
4254 return MESA_FORMAT_R_UINT32
;
4257 return MESA_FORMAT_NONE
;
4263 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4264 GLenum internalFormat
)
4266 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
4269 if (format
== MESA_FORMAT_NONE
)
4270 return MESA_FORMAT_NONE
;
4272 datatype
= _mesa_get_format_datatype(format
);
4274 /* The GL_ARB_texture_buffer_object spec says:
4276 * "If ARB_texture_float is not supported, references to the
4277 * floating-point internal formats provided by that extension should be
4278 * removed, and such formats may not be passed to TexBufferARB."
4280 * As a result, GL_HALF_FLOAT internal format depends on both
4281 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
4283 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
4284 !ctx
->Extensions
.ARB_texture_float
)
4285 return MESA_FORMAT_NONE
;
4287 if (!ctx
->Extensions
.ARB_texture_rg
) {
4288 GLenum base_format
= _mesa_get_format_base_format(format
);
4289 if (base_format
== GL_R
|| base_format
== GL_RG
)
4290 return MESA_FORMAT_NONE
;
4293 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4294 GLenum base_format
= _mesa_get_format_base_format(format
);
4295 if (base_format
== GL_RGB
)
4296 return MESA_FORMAT_NONE
;
4303 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4304 struct gl_buffer_object
*bufObj
,
4305 GLintptr offset
, GLsizeiptr size
)
4307 struct gl_texture_object
*texObj
;
4310 FLUSH_VERTICES(ctx
, 0);
4312 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4313 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4317 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
4318 if (format
== MESA_FORMAT_NONE
) {
4319 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4324 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4326 _mesa_lock_texture(ctx
, texObj
);
4328 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4329 texObj
->BufferObjectFormat
= internalFormat
;
4330 texObj
->_BufferObjectFormat
= format
;
4331 texObj
->BufferOffset
= offset
;
4332 texObj
->BufferSize
= size
;
4334 _mesa_unlock_texture(ctx
, texObj
);
4338 /** GL_ARB_texture_buffer_object */
4340 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4342 struct gl_buffer_object
*bufObj
;
4344 GET_CURRENT_CONTEXT(ctx
);
4346 /* NOTE: ARB_texture_buffer_object has interactions with
4347 * the compatibility profile that are not implemented.
4349 if (!(ctx
->API
== API_OPENGL_CORE
&&
4350 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4351 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4355 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4356 if (!bufObj
&& buffer
) {
4357 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4361 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4365 /** GL_ARB_texture_buffer_range */
4367 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4368 GLintptr offset
, GLsizeiptr size
)
4370 struct gl_buffer_object
*bufObj
;
4372 GET_CURRENT_CONTEXT(ctx
);
4374 if (!(ctx
->API
== API_OPENGL_CORE
&&
4375 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4376 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4380 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4384 (offset
+ size
) > bufObj
->Size
) {
4385 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4388 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4389 _mesa_error(ctx
, GL_INVALID_VALUE
,
4390 "glTexBufferRange(invalid offset alignment)");
4393 } else if (buffer
) {
4394 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4402 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4407 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4409 /* Everything that is allowed for renderbuffers,
4410 * except for a base format of GL_STENCIL_INDEX.
4412 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4413 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4417 /** GL_ARB_texture_multisample */
4419 check_multisample_target(GLuint dims
, GLenum target
)
4422 case GL_TEXTURE_2D_MULTISAMPLE
:
4423 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4426 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4427 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4437 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4438 GLint internalformat
, GLsizei width
, GLsizei height
,
4439 GLsizei depth
, GLboolean fixedsamplelocations
,
4440 GLboolean immutable
, const char *func
)
4442 struct gl_texture_object
*texObj
;
4443 struct gl_texture_image
*texImage
;
4444 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
4445 mesa_format texFormat
;
4446 GLenum sample_count_error
;
4448 GET_CURRENT_CONTEXT(ctx
);
4450 if (!(ctx
->Extensions
.ARB_texture_multisample
4451 && _mesa_is_desktop_gl(ctx
))) {
4452 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4456 if (!check_multisample_target(dims
, target
)) {
4457 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4461 /* check that the specified internalformat is color/depth/stencil-renderable;
4462 * refer GL3.1 spec 4.4.4
4465 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4466 _mesa_error(ctx
, GL_INVALID_ENUM
,
4467 "%s(internalformat=%s not legal for immutable-format)",
4468 func
, _mesa_lookup_enum_by_nr(internalformat
));
4472 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4473 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4474 "%s(internalformat=%s)",
4475 func
, _mesa_lookup_enum_by_nr(internalformat
));
4479 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4480 internalformat
, samples
);
4481 samplesOK
= sample_count_error
== GL_NO_ERROR
;
4483 /* Page 254 of OpenGL 4.4 spec says:
4484 * "Proxy arrays for two-dimensional multisample and two-dimensional
4485 * multisample array textures are operated on in the same way when
4486 * TexImage2DMultisample is called with target specified as
4487 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
4488 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
4489 * However, if samples is not supported, then no error is generated.
4491 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
4492 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4496 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4498 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4499 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4500 "%s(texture object 0)",
4505 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4507 if (texImage
== NULL
) {
4508 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4512 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4513 internalformat
, GL_NONE
, GL_NONE
);
4514 assert(texFormat
!= MESA_FORMAT_NONE
);
4516 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4517 width
, height
, depth
, 0);
4519 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4520 width
, height
, depth
, 0);
4522 if (_mesa_is_proxy_texture(target
)) {
4523 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
4524 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
4525 internalformat
, texFormat
,
4526 samples
, fixedsamplelocations
);
4529 /* clear all image fields */
4530 clear_teximage_fields(texImage
);
4534 if (!dimensionsOK
) {
4535 _mesa_error(ctx
, GL_INVALID_VALUE
,
4536 "%s(invalid width or height)", func
);
4541 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4542 "%s(texture too large)", func
);
4546 /* Check if texObj->Immutable is set */
4547 if (texObj
->Immutable
) {
4548 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4552 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4554 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
4555 internalformat
, texFormat
,
4556 samples
, fixedsamplelocations
);
4558 if (width
> 0 && height
> 0 && depth
> 0) {
4559 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4560 width
, height
, depth
)) {
4561 /* tidy up the texture image state. strictly speaking,
4562 * we're allowed to just leave this in whatever state we
4563 * like, but being tidy is good.
4565 _mesa_init_teximage_fields(ctx
, texImage
,
4566 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4570 texObj
->Immutable
= immutable
;
4573 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
4576 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4582 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4583 GLenum internalformat
, GLsizei width
,
4584 GLsizei height
, GLboolean fixedsamplelocations
)
4586 teximagemultisample(2, target
, samples
, internalformat
,
4587 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4588 "glTexImage2DMultisample");
4593 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4594 GLenum internalformat
, GLsizei width
,
4595 GLsizei height
, GLsizei depth
,
4596 GLboolean fixedsamplelocations
)
4598 teximagemultisample(3, target
, samples
, internalformat
,
4599 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4600 "glTexImage3DMultisample");
4605 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4606 GLenum internalformat
, GLsizei width
,
4607 GLsizei height
, GLboolean fixedsamplelocations
)
4609 teximagemultisample(2, target
, samples
, internalformat
,
4610 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4611 "glTexStorage2DMultisample");
4616 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4617 GLenum internalformat
, GLsizei width
,
4618 GLsizei height
, GLsizei depth
,
4619 GLboolean fixedsamplelocations
)
4621 teximagemultisample(3, target
, samples
, internalformat
,
4622 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4623 "glTexStorage3DMultisample");