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
.ATI_envmap_bumpmap
) {
259 switch (internalFormat
) {
268 if (ctx
->Extensions
.EXT_texture_snorm
) {
269 switch (internalFormat
) {
284 case GL_RGBA16_SNORM
:
287 case GL_ALPHA8_SNORM
:
288 case GL_ALPHA16_SNORM
:
290 case GL_LUMINANCE_SNORM
:
291 case GL_LUMINANCE8_SNORM
:
292 case GL_LUMINANCE16_SNORM
:
294 case GL_LUMINANCE_ALPHA_SNORM
:
295 case GL_LUMINANCE8_ALPHA8_SNORM
:
296 case GL_LUMINANCE16_ALPHA16_SNORM
:
297 return GL_LUMINANCE_ALPHA
;
298 case GL_INTENSITY_SNORM
:
299 case GL_INTENSITY8_SNORM
:
300 case GL_INTENSITY16_SNORM
:
307 if (ctx
->Extensions
.EXT_texture_sRGB
) {
308 switch (internalFormat
) {
311 case GL_COMPRESSED_SRGB_EXT
:
313 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
314 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
315 case GL_SRGB_ALPHA_EXT
:
316 case GL_SRGB8_ALPHA8_EXT
:
317 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
319 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
320 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
321 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
322 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
323 case GL_SLUMINANCE_ALPHA_EXT
:
324 case GL_SLUMINANCE8_ALPHA8_EXT
:
325 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
326 return GL_LUMINANCE_ALPHA
;
327 case GL_SLUMINANCE_EXT
:
328 case GL_SLUMINANCE8_EXT
:
329 case GL_COMPRESSED_SLUMINANCE_EXT
:
336 if (ctx
->Version
>= 30 ||
337 ctx
->Extensions
.EXT_texture_integer
) {
338 switch (internalFormat
) {
340 case GL_RGBA16UI_EXT
:
341 case GL_RGBA32UI_EXT
:
357 if (ctx
->Extensions
.EXT_texture_integer
) {
358 switch (internalFormat
) {
359 case GL_ALPHA8UI_EXT
:
360 case GL_ALPHA16UI_EXT
:
361 case GL_ALPHA32UI_EXT
:
363 case GL_ALPHA16I_EXT
:
364 case GL_ALPHA32I_EXT
:
366 case GL_INTENSITY8UI_EXT
:
367 case GL_INTENSITY16UI_EXT
:
368 case GL_INTENSITY32UI_EXT
:
369 case GL_INTENSITY8I_EXT
:
370 case GL_INTENSITY16I_EXT
:
371 case GL_INTENSITY32I_EXT
:
373 case GL_LUMINANCE8UI_EXT
:
374 case GL_LUMINANCE16UI_EXT
:
375 case GL_LUMINANCE32UI_EXT
:
376 case GL_LUMINANCE8I_EXT
:
377 case GL_LUMINANCE16I_EXT
:
378 case GL_LUMINANCE32I_EXT
:
380 case GL_LUMINANCE_ALPHA8UI_EXT
:
381 case GL_LUMINANCE_ALPHA16UI_EXT
:
382 case GL_LUMINANCE_ALPHA32UI_EXT
:
383 case GL_LUMINANCE_ALPHA8I_EXT
:
384 case GL_LUMINANCE_ALPHA16I_EXT
:
385 case GL_LUMINANCE_ALPHA32I_EXT
:
386 return GL_LUMINANCE_ALPHA
;
392 if (ctx
->Extensions
.ARB_texture_rg
) {
393 switch (internalFormat
) {
396 if (!ctx
->Extensions
.ARB_texture_float
)
405 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
411 case GL_COMPRESSED_RED
:
416 if (!ctx
->Extensions
.ARB_texture_float
)
425 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
431 case GL_COMPRESSED_RG
:
438 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
439 switch (internalFormat
) {
447 if (ctx
->Extensions
.EXT_packed_float
) {
448 switch (internalFormat
) {
449 case GL_R11F_G11F_B10F_EXT
:
456 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
457 switch (internalFormat
) {
458 case GL_DEPTH_COMPONENT32F
:
459 return GL_DEPTH_COMPONENT
;
460 case GL_DEPTH32F_STENCIL8
:
461 return GL_DEPTH_STENCIL
;
467 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
468 switch (internalFormat
) {
469 case GL_COMPRESSED_RED_RGTC1
:
470 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
472 case GL_COMPRESSED_RG_RGTC2
:
473 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
480 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
481 switch (internalFormat
) {
482 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
483 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
485 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
486 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
487 return GL_LUMINANCE_ALPHA
;
493 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
494 switch (internalFormat
) {
495 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
496 return GL_LUMINANCE_ALPHA
;
502 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
503 switch (internalFormat
) {
504 case GL_ETC1_RGB8_OES
:
511 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
512 switch (internalFormat
) {
513 case GL_COMPRESSED_RGB8_ETC2
:
514 case GL_COMPRESSED_SRGB8_ETC2
:
516 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
517 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
518 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
519 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
521 case GL_COMPRESSED_R11_EAC
:
522 case GL_COMPRESSED_SIGNED_R11_EAC
:
524 case GL_COMPRESSED_RG11_EAC
:
525 case GL_COMPRESSED_SIGNED_RG11_EAC
:
532 if (ctx
->API
== API_OPENGLES
) {
533 switch (internalFormat
) {
534 case GL_PALETTE4_RGB8_OES
:
535 case GL_PALETTE4_R5_G6_B5_OES
:
536 case GL_PALETTE8_RGB8_OES
:
537 case GL_PALETTE8_R5_G6_B5_OES
:
539 case GL_PALETTE4_RGBA8_OES
:
540 case GL_PALETTE8_RGB5_A1_OES
:
541 case GL_PALETTE4_RGBA4_OES
:
542 case GL_PALETTE4_RGB5_A1_OES
:
543 case GL_PALETTE8_RGBA8_OES
:
544 case GL_PALETTE8_RGBA4_OES
:
551 return -1; /* error */
556 * For cube map faces, return a face index in [0,5].
557 * For other targets return 0;
560 _mesa_tex_target_to_face(GLenum target
)
562 if (_mesa_is_cube_face(target
))
563 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
571 * Install gl_texture_image in a gl_texture_object according to the target
572 * and level parameters.
574 * \param tObj texture object.
575 * \param target texture target.
576 * \param level image level.
577 * \param texImage texture image.
580 set_tex_image(struct gl_texture_object
*tObj
,
581 GLenum target
, GLint level
,
582 struct gl_texture_image
*texImage
)
584 const GLuint face
= _mesa_tex_target_to_face(target
);
588 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
591 tObj
->Image
[face
][level
] = texImage
;
593 /* Set the 'back' pointer */
594 texImage
->TexObject
= tObj
;
595 texImage
->Level
= level
;
596 texImage
->Face
= face
;
601 * Allocate a texture image structure.
603 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
606 * \return a pointer to gl_texture_image struct with all fields initialized to
609 struct gl_texture_image
*
610 _mesa_new_texture_image( struct gl_context
*ctx
)
613 return CALLOC_STRUCT(gl_texture_image
);
618 * Free a gl_texture_image and associated data.
619 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
621 * \param texImage texture image.
623 * Free the texture image structure and the associated image data.
626 _mesa_delete_texture_image(struct gl_context
*ctx
,
627 struct gl_texture_image
*texImage
)
629 /* Free texImage->Data and/or any other driver-specific texture
632 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
633 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
639 * Test if a target is a proxy target.
641 * \param target texture target.
643 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
646 _mesa_is_proxy_texture(GLenum target
)
649 static const GLenum targets
[] = {
653 GL_PROXY_TEXTURE_CUBE_MAP
,
654 GL_PROXY_TEXTURE_RECTANGLE
,
655 GL_PROXY_TEXTURE_1D_ARRAY
,
656 GL_PROXY_TEXTURE_2D_ARRAY
,
657 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
658 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
659 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
662 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
663 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
665 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== Elements(targets
) + 2);
667 for (i
= 0; i
< Elements(targets
); ++i
)
668 if (target
== targets
[i
])
675 * Return the proxy target which corresponds to the given texture target
678 proxy_target(GLenum target
)
682 case GL_PROXY_TEXTURE_1D
:
683 return GL_PROXY_TEXTURE_1D
;
685 case GL_PROXY_TEXTURE_2D
:
686 return GL_PROXY_TEXTURE_2D
;
688 case GL_PROXY_TEXTURE_3D
:
689 return GL_PROXY_TEXTURE_3D
;
690 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
691 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
692 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
693 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
694 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
695 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
696 case GL_TEXTURE_CUBE_MAP_ARB
:
697 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
698 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
699 case GL_TEXTURE_RECTANGLE_NV
:
700 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
701 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
702 case GL_TEXTURE_1D_ARRAY_EXT
:
703 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
704 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
705 case GL_TEXTURE_2D_ARRAY_EXT
:
706 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
707 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
708 case GL_TEXTURE_CUBE_MAP_ARRAY
:
709 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
710 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
711 case GL_TEXTURE_2D_MULTISAMPLE
:
712 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
713 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
714 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
715 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
716 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
718 _mesa_problem(NULL
, "unexpected target in proxy_target()");
725 * Return a pointer to the current texture object for the given target
726 * on the current texture unit.
727 * Note: all <target> error checking should have been done by this point.
729 struct gl_texture_object
*
730 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
732 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
733 const GLboolean arrayTex
= ctx
->Extensions
.EXT_texture_array
;
737 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
738 case GL_PROXY_TEXTURE_1D
:
739 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
741 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
742 case GL_PROXY_TEXTURE_2D
:
743 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
745 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
746 case GL_PROXY_TEXTURE_3D
:
747 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
748 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
749 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
750 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
751 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
752 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
753 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
754 case GL_TEXTURE_CUBE_MAP_ARB
:
755 return ctx
->Extensions
.ARB_texture_cube_map
756 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
757 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
758 return ctx
->Extensions
.ARB_texture_cube_map
759 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
760 case GL_TEXTURE_CUBE_MAP_ARRAY
:
761 return ctx
->Extensions
.ARB_texture_cube_map_array
762 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
763 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
764 return ctx
->Extensions
.ARB_texture_cube_map_array
765 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
766 case GL_TEXTURE_RECTANGLE_NV
:
767 return ctx
->Extensions
.NV_texture_rectangle
768 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
769 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
770 return ctx
->Extensions
.NV_texture_rectangle
771 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
772 case GL_TEXTURE_1D_ARRAY_EXT
:
773 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
774 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
775 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
776 case GL_TEXTURE_2D_ARRAY_EXT
:
777 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
778 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
779 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
780 case GL_TEXTURE_BUFFER
:
781 return ctx
->API
== API_OPENGL_CORE
&&
782 ctx
->Extensions
.ARB_texture_buffer_object
?
783 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
784 case GL_TEXTURE_EXTERNAL_OES
:
785 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
786 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
787 case GL_TEXTURE_2D_MULTISAMPLE
:
788 return ctx
->Extensions
.ARB_texture_multisample
789 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
790 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
791 return ctx
->Extensions
.ARB_texture_multisample
792 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
793 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
794 return ctx
->Extensions
.ARB_texture_multisample
795 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
796 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
797 return ctx
->Extensions
.ARB_texture_multisample
798 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
800 _mesa_problem(NULL
, "bad target in _mesa_get_current_tex_object()");
808 * Get a texture image pointer from a texture object, given a texture
809 * target and mipmap level. The target and level parameters should
810 * have already been error-checked.
812 * \param ctx GL context.
813 * \param texObj texture unit.
814 * \param target texture target.
815 * \param level image level.
817 * \return pointer to the texture image structure, or NULL on failure.
819 struct gl_texture_image
*
820 _mesa_select_tex_image(struct gl_context
*ctx
,
821 const struct gl_texture_object
*texObj
,
822 GLenum target
, GLint level
)
824 const GLuint face
= _mesa_tex_target_to_face(target
);
828 ASSERT(level
< MAX_TEXTURE_LEVELS
);
830 return texObj
->Image
[face
][level
];
835 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
836 * it and install it. Only return NULL if passed a bad parameter or run
839 struct gl_texture_image
*
840 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
841 GLenum target
, GLint level
)
843 struct gl_texture_image
*texImage
;
848 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
850 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
852 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
856 set_tex_image(texObj
, target
, level
, texImage
);
864 * Return pointer to the specified proxy texture image.
865 * Note that proxy textures are per-context, not per-texture unit.
866 * \return pointer to texture image or NULL if invalid target, invalid
867 * level, or out of memory.
869 static struct gl_texture_image
*
870 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
872 struct gl_texture_image
*texImage
;
879 case GL_PROXY_TEXTURE_1D
:
880 if (level
>= ctx
->Const
.MaxTextureLevels
)
882 texIndex
= TEXTURE_1D_INDEX
;
884 case GL_PROXY_TEXTURE_2D
:
885 if (level
>= ctx
->Const
.MaxTextureLevels
)
887 texIndex
= TEXTURE_2D_INDEX
;
889 case GL_PROXY_TEXTURE_3D
:
890 if (level
>= ctx
->Const
.Max3DTextureLevels
)
892 texIndex
= TEXTURE_3D_INDEX
;
894 case GL_PROXY_TEXTURE_CUBE_MAP
:
895 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
897 texIndex
= TEXTURE_CUBE_INDEX
;
899 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
902 texIndex
= TEXTURE_RECT_INDEX
;
904 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
905 if (level
>= ctx
->Const
.MaxTextureLevels
)
907 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
909 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
910 if (level
>= ctx
->Const
.MaxTextureLevels
)
912 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
914 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
915 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
917 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
919 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
922 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
924 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
927 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
933 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
935 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
937 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
940 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
941 /* Set the 'back' pointer */
942 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
949 * Get the maximum number of allowed mipmap levels.
951 * \param ctx GL context.
952 * \param target texture target.
954 * \return the maximum number of allowed mipmap levels for the given
955 * texture target, or zero if passed a bad target.
960 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
964 case GL_PROXY_TEXTURE_1D
:
966 case GL_PROXY_TEXTURE_2D
:
967 return ctx
->Const
.MaxTextureLevels
;
969 case GL_PROXY_TEXTURE_3D
:
970 return ctx
->Const
.Max3DTextureLevels
;
971 case GL_TEXTURE_CUBE_MAP
:
972 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
973 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
974 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
975 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
976 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
977 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
978 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
979 return ctx
->Extensions
.ARB_texture_cube_map
980 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
981 case GL_TEXTURE_RECTANGLE_NV
:
982 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
983 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
984 case GL_TEXTURE_1D_ARRAY_EXT
:
985 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
986 case GL_TEXTURE_2D_ARRAY_EXT
:
987 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
988 return ctx
->Extensions
.EXT_texture_array
989 ? ctx
->Const
.MaxTextureLevels
: 0;
990 case GL_TEXTURE_CUBE_MAP_ARRAY
:
991 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
992 return ctx
->Extensions
.ARB_texture_cube_map_array
993 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
994 case GL_TEXTURE_BUFFER
:
995 return ctx
->API
== API_OPENGL_CORE
&&
996 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
997 case GL_TEXTURE_2D_MULTISAMPLE
:
998 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
999 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1000 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1001 return _mesa_is_desktop_gl(ctx
)
1002 && ctx
->Extensions
.ARB_texture_multisample
1004 case GL_TEXTURE_EXTERNAL_OES
:
1007 return 0; /* bad target */
1013 * Return number of dimensions per mipmap level for the given texture target.
1016 _mesa_get_texture_dimensions(GLenum target
)
1020 case GL_PROXY_TEXTURE_1D
:
1023 case GL_TEXTURE_RECTANGLE
:
1024 case GL_TEXTURE_CUBE_MAP
:
1025 case GL_PROXY_TEXTURE_2D
:
1026 case GL_PROXY_TEXTURE_RECTANGLE
:
1027 case GL_PROXY_TEXTURE_CUBE_MAP
:
1028 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1029 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1030 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1031 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1032 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1033 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1034 case GL_TEXTURE_1D_ARRAY
:
1035 case GL_PROXY_TEXTURE_1D_ARRAY
:
1036 case GL_TEXTURE_EXTERNAL_OES
:
1037 case GL_TEXTURE_2D_MULTISAMPLE
:
1038 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1041 case GL_PROXY_TEXTURE_3D
:
1042 case GL_TEXTURE_2D_ARRAY
:
1043 case GL_PROXY_TEXTURE_2D_ARRAY
:
1044 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1045 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1046 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1047 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1049 case GL_TEXTURE_BUFFER
:
1052 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1060 * Check if a texture target can have more than one layer.
1063 _mesa_tex_target_is_layered(GLenum target
)
1067 case GL_PROXY_TEXTURE_1D
:
1069 case GL_PROXY_TEXTURE_2D
:
1070 case GL_TEXTURE_RECTANGLE
:
1071 case GL_PROXY_TEXTURE_RECTANGLE
:
1072 case GL_TEXTURE_2D_MULTISAMPLE
:
1073 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1074 case GL_TEXTURE_BUFFER
:
1075 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1076 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1077 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1078 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1079 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1080 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1081 case GL_TEXTURE_EXTERNAL_OES
:
1085 case GL_PROXY_TEXTURE_3D
:
1086 case GL_TEXTURE_CUBE_MAP
:
1087 case GL_PROXY_TEXTURE_CUBE_MAP
:
1088 case GL_TEXTURE_1D_ARRAY
:
1089 case GL_PROXY_TEXTURE_1D_ARRAY
:
1090 case GL_TEXTURE_2D_ARRAY
:
1091 case GL_PROXY_TEXTURE_2D_ARRAY
:
1092 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1093 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1094 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1095 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1099 assert(!"Invalid texture target.");
1106 * Return the number of layers present in the given level of an array,
1107 * cubemap or 3D texture. If the texture is not layered return zero.
1110 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1112 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1114 switch (texObj
->Target
) {
1117 case GL_TEXTURE_RECTANGLE
:
1118 case GL_TEXTURE_2D_MULTISAMPLE
:
1119 case GL_TEXTURE_BUFFER
:
1120 case GL_TEXTURE_EXTERNAL_OES
:
1123 case GL_TEXTURE_CUBE_MAP
:
1126 case GL_TEXTURE_1D_ARRAY
: {
1127 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1128 return img
? img
->Height
: 0;
1132 case GL_TEXTURE_2D_ARRAY
:
1133 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1134 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1135 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1136 return img
? img
->Depth
: 0;
1140 assert(!"Invalid texture target.");
1147 * Return the maximum number of mipmap levels for the given target
1148 * and the dimensions.
1149 * The dimensions are expected not to include the border.
1152 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1159 case GL_TEXTURE_1D_ARRAY
:
1160 case GL_PROXY_TEXTURE_1D
:
1161 case GL_PROXY_TEXTURE_1D_ARRAY
:
1164 case GL_TEXTURE_CUBE_MAP
:
1165 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1166 case GL_PROXY_TEXTURE_CUBE_MAP
:
1167 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1171 case GL_TEXTURE_2D_ARRAY
:
1172 case GL_PROXY_TEXTURE_2D
:
1173 case GL_PROXY_TEXTURE_2D_ARRAY
:
1174 size
= MAX2(width
, height
);
1177 case GL_PROXY_TEXTURE_3D
:
1178 size
= MAX3(width
, height
, depth
);
1180 case GL_TEXTURE_RECTANGLE
:
1181 case GL_TEXTURE_EXTERNAL_OES
:
1182 case GL_TEXTURE_2D_MULTISAMPLE
:
1183 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1184 case GL_PROXY_TEXTURE_RECTANGLE
:
1185 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1186 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1193 return _mesa_logbase2(size
) + 1;
1197 #if 000 /* not used anymore */
1199 * glTexImage[123]D can accept a NULL image pointer. In this case we
1200 * create a texture image with unspecified image contents per the OpenGL
1204 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1206 const GLint components
= _mesa_components_in_format(format
);
1207 const GLint numPixels
= width
* height
* depth
;
1208 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1212 * Let's see if anyone finds this. If glTexImage2D() is called with
1213 * a NULL image pointer then load the texture image with something
1214 * interesting instead of leaving it indeterminate.
1217 static const char message
[8][32] = {
1218 " X X XXXXX XXX X ",
1219 " XX XX X X X X X ",
1221 " X X XXXX XXX XXXXX ",
1224 " X X XXXXX XXX X X ",
1228 GLubyte
*imgPtr
= data
;
1230 for (h
= 0; h
< depth
; h
++) {
1231 for (i
= 0; i
< height
; i
++) {
1232 GLint srcRow
= 7 - (i
% 8);
1233 for (j
= 0; j
< width
; j
++) {
1234 GLint srcCol
= j
% 32;
1235 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1236 for (k
= 0; k
< components
; k
++) {
1252 * Set the size and format-related fields of a gl_texture_image struct
1253 * to zero. This is used when a proxy texture test fails.
1256 clear_teximage_fields(struct gl_texture_image
*img
)
1259 img
->_BaseFormat
= 0;
1260 img
->InternalFormat
= 0;
1269 img
->HeightLog2
= 0;
1271 img
->TexFormat
= MESA_FORMAT_NONE
;
1272 img
->NumSamples
= 0;
1273 img
->FixedSampleLocations
= GL_TRUE
;
1278 * Initialize basic fields of the gl_texture_image struct.
1280 * \param ctx GL context.
1281 * \param img texture image structure to be initialized.
1282 * \param width image width.
1283 * \param height image height.
1284 * \param depth image depth.
1285 * \param border image border.
1286 * \param internalFormat internal format.
1287 * \param format the actual hardware format (one of MESA_FORMAT_*)
1288 * \param numSamples number of samples per texel, or zero for non-MS.
1289 * \param fixedSampleLocations are sample locations fixed?
1291 * Fills in the fields of \p img with the given information.
1292 * Note: width, height and depth include the border.
1295 init_teximage_fields_ms(struct gl_context
*ctx
,
1296 struct gl_texture_image
*img
,
1297 GLsizei width
, GLsizei height
, GLsizei depth
,
1298 GLint border
, GLenum internalFormat
,
1300 GLuint numSamples
, GLboolean fixedSampleLocations
)
1305 ASSERT(height
>= 0);
1308 target
= img
->TexObject
->Target
;
1309 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1310 ASSERT(img
->_BaseFormat
> 0);
1311 img
->InternalFormat
= internalFormat
;
1312 img
->Border
= border
;
1314 img
->Height
= height
;
1317 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1318 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1320 img
->NumSamples
= 0;
1321 img
->FixedSampleLocations
= GL_TRUE
;
1325 case GL_TEXTURE_BUFFER
:
1326 case GL_PROXY_TEXTURE_1D
:
1331 img
->HeightLog2
= 0;
1338 case GL_TEXTURE_1D_ARRAY
:
1339 case GL_PROXY_TEXTURE_1D_ARRAY
:
1340 img
->Height2
= height
; /* no border */
1341 img
->HeightLog2
= 0; /* not used */
1349 case GL_TEXTURE_RECTANGLE
:
1350 case GL_TEXTURE_CUBE_MAP
:
1351 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1352 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1353 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1354 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1355 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1356 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1357 case GL_TEXTURE_EXTERNAL_OES
:
1358 case GL_PROXY_TEXTURE_2D
:
1359 case GL_PROXY_TEXTURE_RECTANGLE
:
1360 case GL_PROXY_TEXTURE_CUBE_MAP
:
1361 case GL_TEXTURE_2D_MULTISAMPLE
:
1362 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1363 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1364 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1371 case GL_TEXTURE_2D_ARRAY
:
1372 case GL_PROXY_TEXTURE_2D_ARRAY
:
1373 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1374 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1375 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1376 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1377 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1378 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1379 img
->Depth2
= depth
; /* no border */
1380 img
->DepthLog2
= 0; /* not used */
1383 case GL_PROXY_TEXTURE_3D
:
1384 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1385 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1386 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1387 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1390 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1395 _mesa_get_tex_max_num_levels(target
,
1396 img
->Width2
, img
->Height2
, img
->Depth2
);
1397 img
->TexFormat
= format
;
1398 img
->NumSamples
= numSamples
;
1399 img
->FixedSampleLocations
= fixedSampleLocations
;
1404 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1405 struct gl_texture_image
*img
,
1406 GLsizei width
, GLsizei height
, GLsizei depth
,
1407 GLint border
, GLenum internalFormat
,
1410 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1411 internalFormat
, format
, 0, GL_TRUE
);
1416 * Free and clear fields of the gl_texture_image struct.
1418 * \param ctx GL context.
1419 * \param texImage texture image structure to be cleared.
1421 * After the call, \p texImage will have no data associated with it. Its
1422 * fields are cleared so that its parent object will test incomplete.
1425 _mesa_clear_texture_image(struct gl_context
*ctx
,
1426 struct gl_texture_image
*texImage
)
1428 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1429 clear_teximage_fields(texImage
);
1434 * Check the width, height, depth and border of a texture image are legal.
1435 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1437 * The target and level parameters will have already been validated.
1438 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1441 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1442 GLint level
, GLint width
, GLint height
,
1443 GLint depth
, GLint border
)
1449 case GL_PROXY_TEXTURE_1D
:
1450 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1451 maxSize
>>= level
; /* level size */
1452 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1454 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1455 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1461 case GL_PROXY_TEXTURE_2D
:
1462 case GL_TEXTURE_2D_MULTISAMPLE
:
1463 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1464 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1466 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1468 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1470 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1471 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1473 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1479 case GL_PROXY_TEXTURE_3D
:
1480 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1482 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1484 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1486 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1488 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1489 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1491 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1493 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1498 case GL_TEXTURE_RECTANGLE_NV
:
1499 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1502 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1503 if (width
< 0 || width
> maxSize
)
1505 if (height
< 0 || height
> maxSize
)
1509 case GL_TEXTURE_CUBE_MAP
:
1510 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1511 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1512 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1513 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1514 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1515 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1516 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1517 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1519 if (width
!= height
)
1521 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1523 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1525 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1526 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1528 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1533 case GL_TEXTURE_1D_ARRAY_EXT
:
1534 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1535 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1537 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1539 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1541 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1542 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1547 case GL_TEXTURE_2D_ARRAY_EXT
:
1548 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1549 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1550 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1551 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1553 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1555 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1557 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1559 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1560 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1562 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1567 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1568 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1569 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1570 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1572 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1574 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1576 if (width
!= height
)
1578 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1580 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1581 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1583 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1588 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1595 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1596 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1597 * \param destImage the destination texture image.
1598 * \return GL_TRUE if error found, GL_FALSE otherwise.
1601 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1602 const char *function
, GLuint dims
,
1603 const struct gl_texture_image
*destImage
,
1604 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1605 GLsizei subWidth
, GLsizei subHeight
,
1608 const GLenum target
= destImage
->TexObject
->Target
;
1613 _mesa_error(ctx
, GL_INVALID_VALUE
,
1614 "%s%dD(width=%d)", function
, dims
, subWidth
);
1618 if (dims
> 1 && subHeight
< 0) {
1619 _mesa_error(ctx
, GL_INVALID_VALUE
,
1620 "%s%dD(height=%d)", function
, dims
, subHeight
);
1624 if (dims
> 2 && subDepth
< 0) {
1625 _mesa_error(ctx
, GL_INVALID_VALUE
,
1626 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1630 /* check xoffset and width */
1631 if (xoffset
< - (GLint
) destImage
->Border
) {
1632 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1637 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1638 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1643 /* check yoffset and height */
1645 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1646 if (yoffset
< -yBorder
) {
1647 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1651 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1652 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1658 /* check zoffset and depth */
1660 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1661 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1662 0 : destImage
->Border
;
1664 if (zoffset
< -zBorder
) {
1665 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1668 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1669 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1675 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1676 * compressed texture images can be updated. But, that restriction may be
1677 * relaxed for particular compressed formats. At this time, all the
1678 * compressed formats supported by Mesa allow sub-textures to be updated
1679 * along compressed block boundaries.
1681 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1683 if (bw
!= 1 || bh
!= 1) {
1684 /* offset must be multiple of block size */
1685 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1686 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1687 "%s%dD(xoffset = %d, yoffset = %d)",
1688 function
, dims
, xoffset
, yoffset
);
1692 /* The size must be a multiple of bw x bh, or we must be using a
1693 * offset+size that exactly hits the edge of the image. This
1694 * is important for small mipmap levels (1x1, 2x1, etc) and for
1697 if ((subWidth
% bw
!= 0) &&
1698 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1699 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1700 "%s%dD(width = %d)", function
, dims
, subWidth
);
1704 if ((subHeight
% bh
!= 0) &&
1705 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1706 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1707 "%s%dD(height = %d)", function
, dims
, subHeight
);
1719 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1720 * specific texture image size checks.
1722 * A hardware driver might override this function if, for example, the
1723 * max 3D texture size is 512x512x64 (i.e. not a cube).
1725 * Note that width, height, depth == 0 is not an error. However, a
1726 * texture with zero width/height/depth will be considered "incomplete"
1727 * and texturing will effectively be disabled.
1729 * \param target any texture target/type
1730 * \param level as passed to glTexImage
1731 * \param format the MESA_FORMAT_x for the tex image
1732 * \param width as passed to glTexImage
1733 * \param height as passed to glTexImage
1734 * \param depth as passed to glTexImage
1735 * \param border as passed to glTexImage
1736 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1739 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1741 GLint width
, GLint height
, GLint depth
, GLint border
)
1743 /* We just check if the image size is less than MaxTextureMbytes.
1744 * Some drivers may do more specific checks.
1746 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1747 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1748 mbytes
*= _mesa_num_tex_faces(target
);
1749 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1754 * Return true if the format is only valid for glCompressedTexImage.
1757 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1760 case GL_ETC1_RGB8_OES
:
1761 case GL_PALETTE4_RGB8_OES
:
1762 case GL_PALETTE4_RGBA8_OES
:
1763 case GL_PALETTE4_R5_G6_B5_OES
:
1764 case GL_PALETTE4_RGBA4_OES
:
1765 case GL_PALETTE4_RGB5_A1_OES
:
1766 case GL_PALETTE8_RGB8_OES
:
1767 case GL_PALETTE8_RGBA8_OES
:
1768 case GL_PALETTE8_R5_G6_B5_OES
:
1769 case GL_PALETTE8_RGBA4_OES
:
1770 case GL_PALETTE8_RGB5_A1_OES
:
1779 * Helper function to determine whether a target and specific compression
1780 * format are supported.
1783 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1786 (void) intFormat
; /* not used yet */
1790 case GL_PROXY_TEXTURE_2D
:
1791 return GL_TRUE
; /* true for any compressed format so far */
1792 case GL_PROXY_TEXTURE_CUBE_MAP
:
1793 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1794 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1795 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1796 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1797 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1798 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1799 return ctx
->Extensions
.ARB_texture_cube_map
;
1800 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1801 case GL_TEXTURE_2D_ARRAY_EXT
:
1802 return ctx
->Extensions
.EXT_texture_array
;
1803 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1804 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1805 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1813 * Check if the given texture target value is legal for a
1814 * glTexImage1/2/3D call.
1817 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1823 case GL_PROXY_TEXTURE_1D
:
1824 return _mesa_is_desktop_gl(ctx
);
1832 case GL_PROXY_TEXTURE_2D
:
1833 return _mesa_is_desktop_gl(ctx
);
1834 case GL_PROXY_TEXTURE_CUBE_MAP
:
1835 return _mesa_is_desktop_gl(ctx
)
1836 && ctx
->Extensions
.ARB_texture_cube_map
;
1837 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1838 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1839 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1840 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1841 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1842 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1843 return ctx
->Extensions
.ARB_texture_cube_map
;
1844 case GL_TEXTURE_RECTANGLE_NV
:
1845 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1846 return _mesa_is_desktop_gl(ctx
)
1847 && ctx
->Extensions
.NV_texture_rectangle
;
1848 case GL_TEXTURE_1D_ARRAY_EXT
:
1849 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1850 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1858 case GL_PROXY_TEXTURE_3D
:
1859 return _mesa_is_desktop_gl(ctx
);
1860 case GL_TEXTURE_2D_ARRAY_EXT
:
1861 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1862 || _mesa_is_gles3(ctx
);
1863 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1864 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1865 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1866 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1867 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1872 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1879 * Check if the given texture target value is legal for a
1880 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1881 * The difference compared to legal_teximage_target() above is that
1882 * proxy targets are not supported.
1885 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1889 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1894 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1895 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1896 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1897 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1898 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1899 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1900 return ctx
->Extensions
.ARB_texture_cube_map
;
1901 case GL_TEXTURE_RECTANGLE_NV
:
1902 return _mesa_is_desktop_gl(ctx
)
1903 && ctx
->Extensions
.NV_texture_rectangle
;
1904 case GL_TEXTURE_1D_ARRAY_EXT
:
1905 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1913 case GL_TEXTURE_2D_ARRAY_EXT
:
1914 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1915 || _mesa_is_gles3(ctx
);
1916 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1917 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1918 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1923 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1931 * Helper function to determine if a texture object is mutable (in terms
1932 * of GL_ARB_texture_storage).
1935 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1937 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1938 return !texObj
->Immutable
;
1943 * Return expected size of a compressed texture.
1946 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1949 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1950 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1954 * Verify that a texture format is valid with a particular target
1956 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1957 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1960 * \param ctx GL context
1961 * \param target Texture target
1962 * \param internalFormat Internal format of the texture image
1963 * \param dimensions Dimensionality at the caller. This is \b not used
1964 * in the validation. It is only used when logging
1966 * \param caller Base name of the calling function (e.g.,
1967 * "glTexImage" or "glTexStorage").
1969 * \returns true if the combination is legal, false otherwise.
1972 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1973 GLenum target
, GLenum internalFormat
,
1974 unsigned dimensions
,
1977 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1978 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
1979 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1980 * Profile spec says:
1982 * "Textures with a base internal format of DEPTH_COMPONENT or
1983 * DEPTH_STENCIL are supported by texture image specification
1984 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1985 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1986 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1987 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1988 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1989 * formats in conjunction with any other target will result in an
1990 * INVALID_OPERATION error."
1992 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1993 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1995 if (target
!= GL_TEXTURE_1D
&&
1996 target
!= GL_PROXY_TEXTURE_1D
&&
1997 target
!= GL_TEXTURE_2D
&&
1998 target
!= GL_PROXY_TEXTURE_2D
&&
1999 target
!= GL_TEXTURE_1D_ARRAY
&&
2000 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2001 target
!= GL_TEXTURE_2D_ARRAY
&&
2002 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2003 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2004 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2005 !((_mesa_is_cube_face(target
) ||
2006 target
== GL_TEXTURE_CUBE_MAP
||
2007 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2008 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2009 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2010 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2011 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2012 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2013 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2014 "%s%dD(bad target for depth texture)",
2015 caller
, dimensions
);
2024 * Test the glTexImage[123]D() parameters for errors.
2026 * \param ctx GL context.
2027 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2028 * \param target texture target given by the user (already validated).
2029 * \param level image level given by the user.
2030 * \param internalFormat internal format given by the user.
2031 * \param format pixel data format given by the user.
2032 * \param type pixel data type given by the user.
2033 * \param width image width given by the user.
2034 * \param height image height given by the user.
2035 * \param depth image depth given by the user.
2036 * \param border image border given by the user.
2038 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2040 * Verifies each of the parameters against the constants specified in
2041 * __struct gl_contextRec::Const and the supported extensions, and according
2042 * to the OpenGL specification.
2043 * Note that we don't fully error-check the width, height, depth values
2044 * here. That's done in _mesa_legal_texture_dimensions() which is used
2045 * by several other GL entrypoints. Plus, texture dims have a special
2046 * interaction with proxy textures.
2049 texture_error_check( struct gl_context
*ctx
,
2050 GLuint dimensions
, GLenum target
,
2051 GLint level
, GLint internalFormat
,
2052 GLenum format
, GLenum type
,
2053 GLint width
, GLint height
,
2054 GLint depth
, GLint border
)
2056 GLboolean colorFormat
;
2057 GLboolean is_format_depth_or_depthstencil
;
2058 GLboolean is_internalFormat_depth_or_depthstencil
;
2061 /* Even though there are no color-index textures, we still have to support
2062 * uploading color-index data and remapping it to RGB via the
2063 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2065 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2067 /* Note: for proxy textures, some error conditions immediately generate
2068 * a GL error in the usual way. But others do not generate a GL error.
2069 * Instead, they cause the width, height, depth, format fields of the
2070 * texture image to be zeroed-out. The GL spec seems to indicate that the
2071 * zero-out behaviour is only used in cases related to memory allocation.
2075 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2076 _mesa_error(ctx
, GL_INVALID_VALUE
,
2077 "glTexImage%dD(level=%d)", dimensions
, level
);
2082 if (border
< 0 || border
> 1 ||
2083 ((ctx
->API
!= API_OPENGL_COMPAT
||
2084 target
== GL_TEXTURE_RECTANGLE_NV
||
2085 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2086 _mesa_error(ctx
, GL_INVALID_VALUE
,
2087 "glTexImage%dD(border=%d)", dimensions
, border
);
2091 if (width
< 0 || height
< 0 || depth
< 0) {
2092 _mesa_error(ctx
, GL_INVALID_VALUE
,
2093 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2097 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2098 * combinations of format, internalFormat, and type that can be used.
2099 * Formats and types that require additional extensions (e.g., GL_FLOAT
2100 * requires GL_OES_texture_float) are filtered elsewhere.
2103 if (_mesa_is_gles(ctx
)) {
2104 if (_mesa_is_gles3(ctx
)) {
2105 err
= _mesa_es3_error_check_format_and_type(format
, type
,
2108 if (format
!= internalFormat
) {
2109 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2110 "glTexImage%dD(format = %s, internalFormat = %s)",
2112 _mesa_lookup_enum_by_nr(format
),
2113 _mesa_lookup_enum_by_nr(internalFormat
));
2117 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2119 if (err
!= GL_NO_ERROR
) {
2120 _mesa_error(ctx
, err
,
2121 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2123 _mesa_lookup_enum_by_nr(format
),
2124 _mesa_lookup_enum_by_nr(type
),
2125 _mesa_lookup_enum_by_nr(internalFormat
));
2130 /* Check internalFormat */
2131 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2132 _mesa_error(ctx
, GL_INVALID_VALUE
,
2133 "glTexImage%dD(internalFormat=%s)",
2134 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2138 /* Check incoming image format and type */
2139 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2140 if (err
!= GL_NO_ERROR
) {
2141 _mesa_error(ctx
, err
,
2142 "glTexImage%dD(incompatible format = %s, type = %s)",
2143 dimensions
, _mesa_lookup_enum_by_nr(format
),
2144 _mesa_lookup_enum_by_nr(type
));
2148 /* make sure internal format and format basically agree */
2149 is_internalFormat_depth_or_depthstencil
=
2150 _mesa_is_depth_format(internalFormat
) ||
2151 _mesa_is_depthstencil_format(internalFormat
);
2153 is_format_depth_or_depthstencil
=
2154 _mesa_is_depth_format(format
) ||
2155 _mesa_is_depthstencil_format(format
);
2157 colorFormat
= _mesa_is_color_format(format
);
2158 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2159 (is_internalFormat_depth_or_depthstencil
!= is_format_depth_or_depthstencil
) ||
2160 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2161 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2162 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2163 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2164 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2165 _mesa_lookup_enum_by_nr(format
));
2169 /* additional checks for ycbcr textures */
2170 if (internalFormat
== GL_YCBCR_MESA
) {
2171 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2172 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2173 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2175 _mesa_snprintf(message
, sizeof(message
),
2176 "glTexImage%dD(format/type YCBCR mismatch)",
2178 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2179 return GL_TRUE
; /* error */
2181 if (target
!= GL_TEXTURE_2D
&&
2182 target
!= GL_PROXY_TEXTURE_2D
&&
2183 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2184 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2185 _mesa_error(ctx
, GL_INVALID_ENUM
,
2186 "glTexImage%dD(bad target for YCbCr texture)",
2192 _mesa_snprintf(message
, sizeof(message
),
2193 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2194 dimensions
, border
);
2195 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2200 /* additional checks for depth textures */
2201 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2202 dimensions
, "glTexImage"))
2205 /* additional checks for compressed textures */
2206 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2207 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2208 _mesa_error(ctx
, GL_INVALID_ENUM
,
2209 "glTexImage%dD(target can't be compressed)", dimensions
);
2212 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2213 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2214 "glTexImage%dD(no compression for format)", dimensions
);
2218 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2219 "glTexImage%dD(border!=0)", dimensions
);
2224 /* additional checks for integer textures */
2225 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2226 (_mesa_is_enum_format_integer(format
) !=
2227 _mesa_is_enum_format_integer(internalFormat
))) {
2228 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2229 "glTexImage%dD(integer/non-integer format mismatch)",
2234 if (!mutable_tex_object(ctx
, target
)) {
2235 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2236 "glTexImage%dD(immutable texture)", dimensions
);
2240 /* if we get here, the parameters are OK */
2246 * Error checking for glCompressedTexImage[123]D().
2247 * Note that the width, height and depth values are not fully error checked
2249 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2252 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2253 GLenum target
, GLint level
,
2254 GLenum internalFormat
, GLsizei width
,
2255 GLsizei height
, GLsizei depth
, GLint border
,
2258 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2260 GLenum error
= GL_NO_ERROR
;
2261 char *reason
= ""; /* no error */
2263 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2265 error
= GL_INVALID_ENUM
;
2269 /* This will detect any invalid internalFormat value */
2270 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2271 _mesa_error(ctx
, GL_INVALID_ENUM
,
2272 "glCompressedTexImage%dD(internalFormat=%s)",
2273 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2277 switch (internalFormat
) {
2278 case GL_PALETTE4_RGB8_OES
:
2279 case GL_PALETTE4_RGBA8_OES
:
2280 case GL_PALETTE4_R5_G6_B5_OES
:
2281 case GL_PALETTE4_RGBA4_OES
:
2282 case GL_PALETTE4_RGB5_A1_OES
:
2283 case GL_PALETTE8_RGB8_OES
:
2284 case GL_PALETTE8_RGBA8_OES
:
2285 case GL_PALETTE8_R5_G6_B5_OES
:
2286 case GL_PALETTE8_RGBA4_OES
:
2287 case GL_PALETTE8_RGB5_A1_OES
:
2288 /* check level (note that level should be zero or less!) */
2289 if (level
> 0 || level
< -maxLevels
) {
2291 error
= GL_INVALID_VALUE
;
2295 if (dimensions
!= 2) {
2296 reason
= "compressed paletted textures must be 2D";
2297 error
= GL_INVALID_OPERATION
;
2301 /* Figure out the expected texture size (in bytes). This will be
2302 * checked against the actual size later.
2304 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2307 /* This is for the benefit of the TestProxyTexImage below. It expects
2308 * level to be non-negative. OES_compressed_paletted_texture uses a
2309 * weird mechanism where the level specified to glCompressedTexImage2D
2310 * is -(n-1) number of levels in the texture, and the data specifies the
2311 * complete mipmap stack. This is done to ensure the palette is the
2312 * same for all levels.
2319 if (level
< 0 || level
>= maxLevels
) {
2321 error
= GL_INVALID_VALUE
;
2325 /* Figure out the expected texture size (in bytes). This will be
2326 * checked against the actual size later.
2328 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2332 /* This should really never fail */
2333 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2334 reason
= "internalFormat";
2335 error
= GL_INVALID_ENUM
;
2339 /* No compressed formats support borders at this time */
2341 reason
= "border != 0";
2342 error
= GL_INVALID_VALUE
;
2346 /* check image size in bytes */
2347 if (expectedSize
!= imageSize
) {
2348 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2349 * if <imageSize> is not consistent with the format, dimensions, and
2350 * contents of the specified image.
2352 reason
= "imageSize inconsistant with width/height/format";
2353 error
= GL_INVALID_VALUE
;
2357 if (!mutable_tex_object(ctx
, target
)) {
2358 reason
= "immutable texture";
2359 error
= GL_INVALID_OPERATION
;
2366 /* Note: not all error paths exit through here. */
2367 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2374 * Test glTexSubImage[123]D() parameters for errors.
2376 * \param ctx GL context.
2377 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2378 * \param target texture target given by the user (already validated)
2379 * \param level image level given by the user.
2380 * \param xoffset sub-image x offset given by the user.
2381 * \param yoffset sub-image y offset given by the user.
2382 * \param zoffset sub-image z offset given by the user.
2383 * \param format pixel data format given by the user.
2384 * \param type pixel data type given by the user.
2385 * \param width image width given by the user.
2386 * \param height image height given by the user.
2387 * \param depth image depth given by the user.
2389 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2391 * Verifies each of the parameters against the constants specified in
2392 * __struct gl_contextRec::Const and the supported extensions, and according
2393 * to the OpenGL specification.
2396 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2397 GLenum target
, GLint level
,
2398 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2399 GLint width
, GLint height
, GLint depth
,
2400 GLenum format
, GLenum type
)
2402 struct gl_texture_object
*texObj
;
2403 struct gl_texture_image
*texImage
;
2406 /* check target (proxies not allowed) */
2407 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2408 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2409 dimensions
, _mesa_lookup_enum_by_nr(target
));
2414 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2415 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2420 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2421 * combinations of format and type that can be used. Formats and types
2422 * that require additional extensions (e.g., GL_FLOAT requires
2423 * GL_OES_texture_float) are filtered elsewhere.
2425 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2426 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2427 if (err
!= GL_NO_ERROR
) {
2428 _mesa_error(ctx
, err
,
2429 "glTexSubImage%dD(format = %s, type = %s)",
2431 _mesa_lookup_enum_by_nr(format
),
2432 _mesa_lookup_enum_by_nr(type
));
2437 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2438 if (err
!= GL_NO_ERROR
) {
2439 _mesa_error(ctx
, err
,
2440 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2441 dimensions
, _mesa_lookup_enum_by_nr(format
),
2442 _mesa_lookup_enum_by_nr(type
));
2446 /* Get dest texture object / image pointers */
2447 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2449 /* must be out of memory */
2450 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2454 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2456 /* non-existant texture level */
2457 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2458 "glTexSubImage%dD(invalid texture image)", dimensions
);
2462 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2463 texImage
, xoffset
, yoffset
, 0,
2464 width
, height
, 1)) {
2468 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2469 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2470 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2471 "glTexSubImage%dD(no compression for format)", dimensions
);
2476 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2477 /* both source and dest must be integer-valued, or neither */
2478 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2479 _mesa_is_enum_format_integer(format
)) {
2480 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2481 "glTexSubImage%dD(integer/non-integer format mismatch)",
2492 * Test glCopyTexImage[12]D() parameters for errors.
2494 * \param ctx GL context.
2495 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2496 * \param target texture target given by the user.
2497 * \param level image level given by the user.
2498 * \param internalFormat internal format given by the user.
2499 * \param width image width given by the user.
2500 * \param height image height given by the user.
2501 * \param border texture border.
2503 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2505 * Verifies each of the parameters against the constants specified in
2506 * __struct gl_contextRec::Const and the supported extensions, and according
2507 * to the OpenGL specification.
2510 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2511 GLenum target
, GLint level
, GLint internalFormat
,
2512 GLint width
, GLint height
, GLint border
)
2515 GLint rb_base_format
;
2516 struct gl_renderbuffer
*rb
;
2517 GLenum rb_internal_format
;
2520 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2521 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2522 dimensions
, _mesa_lookup_enum_by_nr(target
));
2527 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2528 _mesa_error(ctx
, GL_INVALID_VALUE
,
2529 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2533 /* Check that the source buffer is complete */
2534 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2535 if (ctx
->ReadBuffer
->_Status
== 0) {
2536 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2538 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2539 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2540 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2544 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2545 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2546 "glCopyTexImage%dD(multisample FBO)",
2553 if (border
< 0 || border
> 1 ||
2554 ((ctx
->API
!= API_OPENGL_COMPAT
||
2555 target
== GL_TEXTURE_RECTANGLE_NV
||
2556 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2557 _mesa_error(ctx
, GL_INVALID_VALUE
,
2558 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2562 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2564 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2565 "glCopyTexImage%dD(read buffer)", dimensions
);
2569 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2572 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2573 switch (internalFormat
) {
2578 case GL_LUMINANCE_ALPHA
:
2581 _mesa_error(ctx
, GL_INVALID_VALUE
,
2582 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2583 _mesa_lookup_enum_by_nr(internalFormat
));
2588 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2589 if (baseFormat
< 0) {
2590 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2591 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2592 _mesa_lookup_enum_by_nr(internalFormat
));
2596 rb_internal_format
= rb
->InternalFormat
;
2597 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2598 if (_mesa_is_color_format(internalFormat
)) {
2599 if (rb_base_format
< 0) {
2600 _mesa_error(ctx
, GL_INVALID_VALUE
,
2601 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2602 _mesa_lookup_enum_by_nr(internalFormat
));
2607 if (_mesa_is_gles(ctx
)) {
2609 if (_mesa_base_format_component_count(baseFormat
) >
2610 _mesa_base_format_component_count(rb_base_format
)) {
2613 if (baseFormat
== GL_DEPTH_COMPONENT
||
2614 baseFormat
== GL_DEPTH_STENCIL
||
2615 rb_base_format
== GL_DEPTH_COMPONENT
||
2616 rb_base_format
== GL_DEPTH_STENCIL
||
2617 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2618 baseFormat
== GL_ALPHA
) &&
2619 rb_base_format
!= GL_RGBA
) ||
2620 internalFormat
== GL_RGB9_E5
) {
2623 if (internalFormat
== GL_RGB9_E5
) {
2627 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2628 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2629 _mesa_lookup_enum_by_nr(internalFormat
));
2634 if (_mesa_is_gles3(ctx
)) {
2635 bool rb_is_srgb
= false;
2636 bool dst_is_srgb
= false;
2638 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2639 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2643 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2647 if (rb_is_srgb
!= dst_is_srgb
) {
2648 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2649 * OpenGLES 3.0.0 spec says:
2651 * "The error INVALID_OPERATION is also generated if the
2652 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2653 * framebuffer attachment corresponding to the read buffer
2654 * is LINEAR (see section 6.1.13) and internalformat is
2655 * one of the sRGB formats described in section 3.8.16, or
2656 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2657 * SRGB and internalformat is not one of the sRGB formats."
2659 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2660 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2665 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2666 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2667 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2671 /* From the EXT_texture_integer spec:
2673 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2674 * if the texture internalformat is an integer format and the read color
2675 * buffer is not an integer format, or if the internalformat is not an
2676 * integer format and the read color buffer is an integer format."
2678 if (_mesa_is_color_format(internalFormat
)) {
2679 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2680 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2681 if (is_int
|| is_rbint
) {
2682 if (is_int
!= is_rbint
) {
2683 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2684 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2686 } else if (_mesa_is_gles(ctx
) &&
2687 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2688 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2689 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2690 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2696 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2697 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2698 _mesa_error(ctx
, GL_INVALID_ENUM
,
2699 "glCopyTexImage%dD(target)", dimensions
);
2702 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2703 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2704 "glCopyTexImage%dD(no compression for format)", dimensions
);
2708 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2709 "glCopyTexImage%dD(border!=0)", dimensions
);
2714 if (!mutable_tex_object(ctx
, target
)) {
2715 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2716 "glCopyTexImage%dD(immutable texture)", dimensions
);
2720 /* if we get here, the parameters are OK */
2726 * Test glCopyTexSubImage[12]D() parameters for errors.
2727 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2730 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2731 GLenum target
, GLint level
,
2732 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2733 GLint width
, GLint height
)
2735 struct gl_texture_object
*texObj
;
2736 struct gl_texture_image
*texImage
;
2738 /* Check that the source buffer is complete */
2739 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2740 if (ctx
->ReadBuffer
->_Status
== 0) {
2741 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2743 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2744 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2745 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2749 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2750 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2751 "glCopyTexSubImage%dD(multisample FBO)",
2757 /* check target (proxies not allowed) */
2758 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2759 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2760 dimensions
, _mesa_lookup_enum_by_nr(target
));
2765 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2766 _mesa_error(ctx
, GL_INVALID_VALUE
,
2767 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2771 /* Get dest texture object / image pointers */
2772 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2774 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2778 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2780 /* destination image does not exist */
2781 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2782 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2786 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2787 dimensions
, texImage
,
2788 xoffset
, yoffset
, zoffset
,
2789 width
, height
, 1)) {
2793 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2794 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2795 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2796 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2801 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2802 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2806 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2807 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2808 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2809 dimensions
, texImage
->_BaseFormat
);
2813 /* From the EXT_texture_integer spec:
2815 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2816 * if the texture internalformat is an integer format and the read color
2817 * buffer is not an integer format, or if the internalformat is not an
2818 * integer format and the read color buffer is an integer format."
2820 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2821 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2823 if (_mesa_is_format_integer_color(rb
->Format
) !=
2824 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2825 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2826 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2831 /* if we get here, the parameters are OK */
2836 /** Callback info for walking over FBO hash table */
2839 struct gl_context
*ctx
;
2840 struct gl_texture_object
*texObj
;
2846 * Check render to texture callback. Called from _mesa_HashWalk().
2849 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2851 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2852 const struct cb_info
*info
= (struct cb_info
*) userData
;
2853 struct gl_context
*ctx
= info
->ctx
;
2854 const struct gl_texture_object
*texObj
= info
->texObj
;
2855 const GLuint level
= info
->level
, face
= info
->face
;
2857 /* If this is a user-created FBO */
2858 if (_mesa_is_user_fbo(fb
)) {
2860 /* check if any of the FBO's attachments point to 'texObj' */
2861 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2862 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2863 if (att
->Type
== GL_TEXTURE
&&
2864 att
->Texture
== texObj
&&
2865 att
->TextureLevel
== level
&&
2866 att
->CubeMapFace
== face
) {
2867 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2868 ASSERT(att
->Renderbuffer
->TexImage
);
2869 /* Mark fb status as indeterminate to force re-validation */
2878 * When a texture image is specified we have to check if it's bound to
2879 * any framebuffer objects (render to texture) in order to detect changes
2880 * in size or format since that effects FBO completeness.
2881 * Any FBOs rendering into the texture must be re-validated.
2884 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2885 struct gl_texture_object
*texObj
,
2886 GLuint face
, GLuint level
)
2888 /* Only check this texture if it's been marked as RenderToTexture */
2889 if (texObj
->_RenderToTexture
) {
2890 struct cb_info info
;
2892 info
.texObj
= texObj
;
2895 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2901 * If the texture object's GenerateMipmap flag is set and we've
2902 * changed the texture base level image, regenerate the rest of the
2903 * mipmap levels now.
2906 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2907 struct gl_texture_object
*texObj
, GLint level
)
2909 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2910 if (texObj
->GenerateMipmap
&&
2911 level
== texObj
->BaseLevel
&&
2912 level
< texObj
->MaxLevel
) {
2913 ASSERT(ctx
->Driver
.GenerateMipmap
);
2914 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2919 /** Debug helper: override the user-requested internal format */
2921 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2924 if (internalFormat
== GL_RGBA16F_ARB
||
2925 internalFormat
== GL_RGBA32F_ARB
) {
2926 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2929 else if (internalFormat
== GL_RGB16F_ARB
||
2930 internalFormat
== GL_RGB32F_ARB
) {
2931 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2934 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2935 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2936 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2937 return GL_LUMINANCE_ALPHA
;
2939 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2940 internalFormat
== GL_LUMINANCE32F_ARB
) {
2941 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2942 return GL_LUMINANCE
;
2944 else if (internalFormat
== GL_ALPHA16F_ARB
||
2945 internalFormat
== GL_ALPHA32F_ARB
) {
2946 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2950 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2951 internalFormat = GL_RGBA;
2955 return internalFormat
;
2958 return internalFormat
;
2964 * Choose the actual hardware format for a texture image.
2965 * Try to use the same format as the previous image level when possible.
2966 * Otherwise, ask the driver for the best format.
2967 * It's important to try to choose a consistant format for all levels
2968 * for efficient texture memory layout/allocation. In particular, this
2969 * comes up during automatic mipmap generation.
2972 _mesa_choose_texture_format(struct gl_context
*ctx
,
2973 struct gl_texture_object
*texObj
,
2974 GLenum target
, GLint level
,
2975 GLenum internalFormat
, GLenum format
, GLenum type
)
2979 /* see if we've already chosen a format for the previous level */
2981 struct gl_texture_image
*prevImage
=
2982 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2983 /* See if the prev level is defined and has an internal format which
2984 * matches the new internal format.
2987 prevImage
->Width
> 0 &&
2988 prevImage
->InternalFormat
== internalFormat
) {
2989 /* use the same format */
2990 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2991 return prevImage
->TexFormat
;
2995 /* If the application requested compression to an S3TC format but we don't
2996 * have the DXTn library, force a generic compressed format instead.
2998 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2999 const GLenum before
= internalFormat
;
3001 switch (internalFormat
) {
3002 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3003 if (!ctx
->Mesa_DXTn
)
3004 internalFormat
= GL_COMPRESSED_RGB
;
3006 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3007 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3008 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3009 if (!ctx
->Mesa_DXTn
)
3010 internalFormat
= GL_COMPRESSED_RGBA
;
3016 if (before
!= internalFormat
) {
3018 "DXT compression requested (%s), "
3019 "but libtxc_dxtn library not installed. Using %s "
3021 _mesa_lookup_enum_by_nr(before
),
3022 _mesa_lookup_enum_by_nr(internalFormat
));
3026 /* choose format from scratch */
3027 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3029 ASSERT(f
!= MESA_FORMAT_NONE
);
3035 * Adjust pixel unpack params and image dimensions to strip off the
3036 * one-pixel texture border.
3038 * Gallium and intel don't support texture borders. They've seldem been used
3039 * and seldom been implemented correctly anyway.
3041 * \param unpackNew returns the new pixel unpack parameters
3044 strip_texture_border(GLenum target
,
3045 GLint
*width
, GLint
*height
, GLint
*depth
,
3046 const struct gl_pixelstore_attrib
*unpack
,
3047 struct gl_pixelstore_attrib
*unpackNew
)
3053 *unpackNew
= *unpack
;
3055 if (unpackNew
->RowLength
== 0)
3056 unpackNew
->RowLength
= *width
;
3058 if (unpackNew
->ImageHeight
== 0)
3059 unpackNew
->ImageHeight
= *height
;
3061 assert(*width
>= 3);
3062 unpackNew
->SkipPixels
++; /* skip the border */
3063 *width
= *width
- 2; /* reduce the width by two border pixels */
3065 /* The min height of a texture with a border is 3 */
3066 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3067 unpackNew
->SkipRows
++; /* skip the border */
3068 *height
= *height
- 2; /* reduce the height by two border pixels */
3072 target
!= GL_TEXTURE_2D_ARRAY
&&
3073 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3074 unpackNew
->SkipImages
++; /* skip the border */
3075 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3081 * Common code to implement all the glTexImage1D/2D/3D functions
3082 * as well as glCompressedTexImage1D/2D/3D.
3083 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3084 * \param format the user's image format (only used if !compressed)
3085 * \param type the user's image type (only used if !compressed)
3086 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3089 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3090 GLenum target
, GLint level
, GLint internalFormat
,
3091 GLsizei width
, GLsizei height
, GLsizei depth
,
3092 GLint border
, GLenum format
, GLenum type
,
3093 GLsizei imageSize
, const GLvoid
*pixels
)
3095 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3096 struct gl_pixelstore_attrib unpack_no_border
;
3097 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3098 struct gl_texture_object
*texObj
;
3099 mesa_format texFormat
;
3100 GLboolean dimensionsOK
, sizeOK
;
3102 FLUSH_VERTICES(ctx
, 0);
3104 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3107 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3109 _mesa_lookup_enum_by_nr(target
), level
,
3110 _mesa_lookup_enum_by_nr(internalFormat
),
3111 width
, height
, depth
, border
, pixels
);
3114 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3116 _mesa_lookup_enum_by_nr(target
), level
,
3117 _mesa_lookup_enum_by_nr(internalFormat
),
3118 width
, height
, depth
, border
,
3119 _mesa_lookup_enum_by_nr(format
),
3120 _mesa_lookup_enum_by_nr(type
), pixels
);
3123 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3125 /* target error checking */
3126 if (!legal_teximage_target(ctx
, dims
, target
)) {
3127 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3128 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3132 /* general error checking */
3134 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3136 width
, height
, depth
,
3141 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3142 format
, type
, width
, height
, depth
, border
))
3146 /* Here we convert a cpal compressed image into a regular glTexImage2D
3147 * call by decompressing the texture. If we really want to support cpal
3148 * textures in any driver this would have to be changed.
3150 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3151 switch (internalFormat
) {
3152 case GL_PALETTE4_RGB8_OES
:
3153 case GL_PALETTE4_RGBA8_OES
:
3154 case GL_PALETTE4_R5_G6_B5_OES
:
3155 case GL_PALETTE4_RGBA4_OES
:
3156 case GL_PALETTE4_RGB5_A1_OES
:
3157 case GL_PALETTE8_RGB8_OES
:
3158 case GL_PALETTE8_RGBA8_OES
:
3159 case GL_PALETTE8_R5_G6_B5_OES
:
3160 case GL_PALETTE8_RGBA4_OES
:
3161 case GL_PALETTE8_RGB5_A1_OES
:
3162 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3163 width
, height
, imageSize
, pixels
);
3168 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3172 /* For glCompressedTexImage() the driver has no choice about the
3173 * texture format since we'll never transcode the user's compressed
3174 * image data. The internalFormat was error checked earlier.
3176 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3179 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3180 internalFormat
, format
, type
);
3183 assert(texFormat
!= MESA_FORMAT_NONE
);
3185 /* check that width, height, depth are legal for the mipmap level */
3186 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3187 height
, depth
, border
);
3189 /* check that the texture won't take too much memory, etc */
3190 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3192 width
, height
, depth
, border
);
3194 if (_mesa_is_proxy_texture(target
)) {
3195 /* Proxy texture: just clear or set state depending on error checking */
3196 struct gl_texture_image
*texImage
=
3197 get_proxy_tex_image(ctx
, target
, level
);
3200 return; /* GL_OUT_OF_MEMORY already recorded */
3202 if (dimensionsOK
&& sizeOK
) {
3203 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3204 border
, internalFormat
, texFormat
);
3207 clear_teximage_fields(texImage
);
3211 /* non-proxy target */
3212 const GLuint face
= _mesa_tex_target_to_face(target
);
3213 struct gl_texture_image
*texImage
;
3215 if (!dimensionsOK
) {
3216 _mesa_error(ctx
, GL_INVALID_VALUE
,
3217 "glTexImage%uD(invalid width or height or depth)",
3223 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3224 "glTexImage%uD(image too large)", dims
);
3228 /* Allow a hardware driver to just strip out the border, to provide
3229 * reliable but slightly incorrect hardware rendering instead of
3230 * rarely-tested software fallback rendering.
3232 if (border
&& ctx
->Const
.StripTextureBorder
) {
3233 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3236 unpack
= &unpack_no_border
;
3239 if (ctx
->NewState
& _NEW_PIXEL
)
3240 _mesa_update_state(ctx
);
3242 _mesa_lock_texture(ctx
, texObj
);
3244 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3247 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3250 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3252 _mesa_init_teximage_fields(ctx
, texImage
,
3253 width
, height
, depth
,
3254 border
, internalFormat
, texFormat
);
3256 /* Give the texture to the driver. <pixels> may be null. */
3257 if (width
> 0 && height
> 0 && depth
> 0) {
3259 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3263 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3264 type
, pixels
, unpack
);
3268 check_gen_mipmap(ctx
, target
, texObj
, level
);
3270 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3272 _mesa_dirty_texobj(ctx
, texObj
);
3275 _mesa_unlock_texture(ctx
, texObj
);
3282 * Called from the API. Note that width includes the border.
3285 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3286 GLsizei width
, GLint border
, GLenum format
,
3287 GLenum type
, const GLvoid
*pixels
)
3289 GET_CURRENT_CONTEXT(ctx
);
3290 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3291 border
, format
, type
, 0, pixels
);
3296 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3297 GLsizei width
, GLsizei height
, GLint border
,
3298 GLenum format
, GLenum type
,
3299 const GLvoid
*pixels
)
3301 GET_CURRENT_CONTEXT(ctx
);
3302 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3303 border
, format
, type
, 0, pixels
);
3308 * Called by the API or display list executor.
3309 * Note that width and height include the border.
3312 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3313 GLsizei width
, GLsizei height
, GLsizei depth
,
3314 GLint border
, GLenum format
, GLenum type
,
3315 const GLvoid
*pixels
)
3317 GET_CURRENT_CONTEXT(ctx
);
3318 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3319 width
, height
, depth
,
3320 border
, format
, type
, 0, pixels
);
3325 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3326 GLsizei width
, GLsizei height
, GLsizei depth
,
3327 GLint border
, GLenum format
, GLenum type
,
3328 const GLvoid
*pixels
)
3330 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3331 depth
, border
, format
, type
, pixels
);
3336 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3338 struct gl_texture_object
*texObj
;
3339 struct gl_texture_image
*texImage
;
3341 GET_CURRENT_CONTEXT(ctx
);
3342 FLUSH_VERTICES(ctx
, 0);
3346 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3348 case GL_TEXTURE_EXTERNAL_OES
:
3350 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3353 valid_target
= false;
3357 if (!valid_target
) {
3358 _mesa_error(ctx
, GL_INVALID_ENUM
,
3359 "glEGLImageTargetTexture2D(target=%d)", target
);
3364 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3365 "glEGLImageTargetTexture2D(image=%p)", image
);
3369 if (ctx
->NewState
& _NEW_PIXEL
)
3370 _mesa_update_state(ctx
);
3372 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3373 _mesa_lock_texture(ctx
, texObj
);
3375 if (texObj
->Immutable
) {
3376 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3377 "glEGLImageTargetTexture2D(texture is immutable)");
3378 _mesa_unlock_texture(ctx
, texObj
);
3382 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3384 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3386 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3388 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3389 texObj
, texImage
, image
);
3391 _mesa_dirty_texobj(ctx
, texObj
);
3393 _mesa_unlock_texture(ctx
, texObj
);
3400 * Implement all the glTexSubImage1/2/3D() functions.
3403 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3404 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3405 GLsizei width
, GLsizei height
, GLsizei depth
,
3406 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3408 struct gl_texture_object
*texObj
;
3409 struct gl_texture_image
*texImage
;
3411 FLUSH_VERTICES(ctx
, 0);
3413 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3414 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3416 _mesa_lookup_enum_by_nr(target
), level
,
3417 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3418 _mesa_lookup_enum_by_nr(format
),
3419 _mesa_lookup_enum_by_nr(type
), pixels
);
3421 /* check target (proxies not allowed) */
3422 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3423 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3424 dims
, _mesa_lookup_enum_by_nr(target
));
3428 if (ctx
->NewState
& _NEW_PIXEL
)
3429 _mesa_update_state(ctx
);
3431 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3432 xoffset
, yoffset
, zoffset
,
3433 width
, height
, depth
, format
, type
)) {
3434 return; /* error was detected */
3437 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3439 _mesa_lock_texture(ctx
, texObj
);
3441 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3443 if (width
> 0 && height
> 0 && depth
> 0) {
3444 /* If we have a border, offset=-1 is legal. Bias by border width. */
3447 if (target
!= GL_TEXTURE_2D_ARRAY
)
3448 zoffset
+= texImage
->Border
;
3451 if (target
!= GL_TEXTURE_1D_ARRAY
)
3452 yoffset
+= texImage
->Border
;
3455 xoffset
+= texImage
->Border
;
3458 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3459 xoffset
, yoffset
, zoffset
,
3460 width
, height
, depth
,
3461 format
, type
, pixels
, &ctx
->Unpack
);
3463 check_gen_mipmap(ctx
, target
, texObj
, level
);
3465 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3466 * the texel data, not the texture format, size, etc.
3470 _mesa_unlock_texture(ctx
, texObj
);
3475 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3476 GLint xoffset
, GLsizei width
,
3477 GLenum format
, GLenum type
,
3478 const GLvoid
*pixels
)
3480 GET_CURRENT_CONTEXT(ctx
);
3481 texsubimage(ctx
, 1, target
, level
,
3484 format
, type
, pixels
);
3489 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3490 GLint xoffset
, GLint yoffset
,
3491 GLsizei width
, GLsizei height
,
3492 GLenum format
, GLenum type
,
3493 const GLvoid
*pixels
)
3495 GET_CURRENT_CONTEXT(ctx
);
3496 texsubimage(ctx
, 2, target
, level
,
3497 xoffset
, yoffset
, 0,
3499 format
, type
, pixels
);
3505 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3506 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3507 GLsizei width
, GLsizei height
, GLsizei depth
,
3508 GLenum format
, GLenum type
,
3509 const GLvoid
*pixels
)
3511 GET_CURRENT_CONTEXT(ctx
);
3512 texsubimage(ctx
, 3, target
, level
,
3513 xoffset
, yoffset
, zoffset
,
3514 width
, height
, depth
,
3515 format
, type
, pixels
);
3521 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3522 * from. This depends on whether the texture contains color or depth values.
3524 static struct gl_renderbuffer
*
3525 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3527 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3528 /* reading from depth/stencil buffer */
3529 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3532 /* copying from color buffer */
3533 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3538 copytexsubimage_by_slice(struct gl_context
*ctx
,
3539 struct gl_texture_image
*texImage
,
3541 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3542 struct gl_renderbuffer
*rb
,
3544 GLsizei width
, GLsizei height
)
3546 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3549 /* For 1D arrays, we copy each scanline of the source rectangle into the
3552 assert(zoffset
== 0);
3554 for (slice
= 0; slice
< height
; slice
++) {
3555 assert(yoffset
+ slice
< texImage
->Height
);
3556 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3557 xoffset
, 0, yoffset
+ slice
,
3558 rb
, x
, y
+ slice
, width
, 1);
3561 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3562 xoffset
, yoffset
, zoffset
,
3563 rb
, x
, y
, width
, height
);
3569 * Implement the glCopyTexImage1/2D() functions.
3572 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3573 GLenum target
, GLint level
, GLenum internalFormat
,
3574 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3576 struct gl_texture_object
*texObj
;
3577 struct gl_texture_image
*texImage
;
3578 const GLuint face
= _mesa_tex_target_to_face(target
);
3579 mesa_format texFormat
;
3581 FLUSH_VERTICES(ctx
, 0);
3583 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3584 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3586 _mesa_lookup_enum_by_nr(target
), level
,
3587 _mesa_lookup_enum_by_nr(internalFormat
),
3588 x
, y
, width
, height
, border
);
3590 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3591 _mesa_update_state(ctx
);
3593 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3594 width
, height
, border
))
3597 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3599 _mesa_error(ctx
, GL_INVALID_VALUE
,
3600 "glCopyTexImage%uD(invalid width or height)", dims
);
3604 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3607 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3608 internalFormat
, GL_NONE
, GL_NONE
);
3609 assert(texFormat
!= MESA_FORMAT_NONE
);
3611 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3613 width
, height
, 1, border
)) {
3614 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3615 "glCopyTexImage%uD(image too large)", dims
);
3619 if (border
&& ctx
->Const
.StripTextureBorder
) {
3621 width
-= border
* 2;
3624 height
-= border
* 2;
3629 _mesa_lock_texture(ctx
, texObj
);
3631 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3634 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3637 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3639 /* Free old texture image */
3640 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3642 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3643 border
, internalFormat
, texFormat
);
3645 if (width
&& height
) {
3646 /* Allocate texture memory (no pixel data yet) */
3647 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3649 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3651 struct gl_renderbuffer
*srcRb
=
3652 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3654 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3656 srcRb
, srcX
, srcY
, width
, height
);
3659 check_gen_mipmap(ctx
, target
, texObj
, level
);
3662 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3664 _mesa_dirty_texobj(ctx
, texObj
);
3667 _mesa_unlock_texture(ctx
, texObj
);
3673 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3674 GLenum internalFormat
,
3676 GLsizei width
, GLint border
)
3678 GET_CURRENT_CONTEXT(ctx
);
3679 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3685 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3686 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3689 GET_CURRENT_CONTEXT(ctx
);
3690 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3691 x
, y
, width
, height
, border
);
3697 * Implementation for glCopyTexSubImage1/2/3D() functions.
3700 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3701 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3702 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3704 struct gl_texture_object
*texObj
;
3705 struct gl_texture_image
*texImage
;
3707 FLUSH_VERTICES(ctx
, 0);
3709 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3710 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3712 _mesa_lookup_enum_by_nr(target
),
3713 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3715 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3716 _mesa_update_state(ctx
);
3718 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3719 xoffset
, yoffset
, zoffset
, width
, height
)) {
3723 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3725 _mesa_lock_texture(ctx
, texObj
);
3727 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3729 /* If we have a border, offset=-1 is legal. Bias by border width. */
3732 if (target
!= GL_TEXTURE_2D_ARRAY
)
3733 zoffset
+= texImage
->Border
;
3736 if (target
!= GL_TEXTURE_1D_ARRAY
)
3737 yoffset
+= texImage
->Border
;
3740 xoffset
+= texImage
->Border
;
3743 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3745 struct gl_renderbuffer
*srcRb
=
3746 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3748 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3749 xoffset
, yoffset
, zoffset
,
3750 srcRb
, x
, y
, width
, height
);
3752 check_gen_mipmap(ctx
, target
, texObj
, level
);
3754 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3755 * the texel data, not the texture format, size, etc.
3759 _mesa_unlock_texture(ctx
, texObj
);
3764 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3765 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3767 GET_CURRENT_CONTEXT(ctx
);
3768 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3774 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3775 GLint xoffset
, GLint yoffset
,
3776 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3778 GET_CURRENT_CONTEXT(ctx
);
3779 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3786 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3787 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3788 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3790 GET_CURRENT_CONTEXT(ctx
);
3791 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3792 x
, y
, width
, height
);
3798 /**********************************************************************/
3799 /****** Compressed Textures ******/
3800 /**********************************************************************/
3804 * Error checking for glCompressedTexSubImage[123]D().
3805 * \return error code or GL_NO_ERROR.
3808 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3809 GLenum target
, GLint level
,
3810 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3811 GLsizei width
, GLsizei height
, GLsizei depth
,
3812 GLenum format
, GLsizei imageSize
)
3814 struct gl_texture_object
*texObj
;
3815 struct gl_texture_image
*texImage
;
3823 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3824 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3825 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3826 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3827 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3828 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3832 targetOK
= GL_FALSE
;
3837 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3841 /* no 1D compressed textures at this time */
3842 targetOK
= GL_FALSE
;
3847 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexSubImage%uD(target)",
3852 /* this will catch any invalid compressed format token */
3853 if (!_mesa_is_compressed_format(ctx
, format
)) {
3854 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3859 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3860 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage%uD(level=%d)",
3865 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3866 if (expectedSize
!= imageSize
) {
3867 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage%uD(size=%d)",
3872 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3874 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3875 "glCompressedTexSubImage%uD()", dims
);
3879 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3881 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3882 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3886 if ((GLint
) format
!= texImage
->InternalFormat
) {
3887 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3888 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3892 if (compressedteximage_only_format(ctx
, format
)) {
3893 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3894 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3899 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3900 texImage
, xoffset
, yoffset
, zoffset
,
3901 width
, height
, depth
)) {
3910 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3911 GLenum internalFormat
, GLsizei width
,
3912 GLint border
, GLsizei imageSize
,
3915 GET_CURRENT_CONTEXT(ctx
);
3916 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3917 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3922 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3923 GLenum internalFormat
, GLsizei width
,
3924 GLsizei height
, GLint border
, GLsizei imageSize
,
3927 GET_CURRENT_CONTEXT(ctx
);
3928 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3929 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3934 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3935 GLenum internalFormat
, GLsizei width
,
3936 GLsizei height
, GLsizei depth
, GLint border
,
3937 GLsizei imageSize
, const GLvoid
*data
)
3939 GET_CURRENT_CONTEXT(ctx
);
3940 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3941 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3946 * Common helper for glCompressedTexSubImage1/2/3D().
3949 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3950 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3951 GLsizei width
, GLsizei height
, GLsizei depth
,
3952 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3954 struct gl_texture_object
*texObj
;
3955 struct gl_texture_image
*texImage
;
3956 GET_CURRENT_CONTEXT(ctx
);
3957 FLUSH_VERTICES(ctx
, 0);
3959 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3960 xoffset
, yoffset
, zoffset
,
3961 width
, height
, depth
,
3962 format
, imageSize
)) {
3966 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3968 _mesa_lock_texture(ctx
, texObj
);
3970 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3973 if (width
> 0 && height
> 0 && depth
> 0) {
3974 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3975 xoffset
, yoffset
, zoffset
,
3976 width
, height
, depth
,
3977 format
, imageSize
, data
);
3979 check_gen_mipmap(ctx
, target
, texObj
, level
);
3981 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3982 * the texel data, not the texture format, size, etc.
3986 _mesa_unlock_texture(ctx
, texObj
);
3991 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3992 GLsizei width
, GLenum format
,
3993 GLsizei imageSize
, const GLvoid
*data
)
3995 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3996 format
, imageSize
, data
);
4001 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4002 GLint yoffset
, GLsizei width
, GLsizei height
,
4003 GLenum format
, GLsizei imageSize
,
4006 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
4007 width
, height
, 1, format
, imageSize
, data
);
4012 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4013 GLint yoffset
, GLint zoffset
, GLsizei width
,
4014 GLsizei height
, GLsizei depth
, GLenum format
,
4015 GLsizei imageSize
, const GLvoid
*data
)
4017 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
4018 width
, height
, depth
, format
, imageSize
, data
);
4022 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4024 if (ctx
->API
!= API_OPENGL_CORE
) {
4025 switch (internalFormat
) {
4027 return MESA_FORMAT_A_UNORM8
;
4029 return MESA_FORMAT_A_UNORM16
;
4030 case GL_ALPHA16F_ARB
:
4031 return MESA_FORMAT_A_FLOAT16
;
4032 case GL_ALPHA32F_ARB
:
4033 return MESA_FORMAT_A_FLOAT32
;
4034 case GL_ALPHA8I_EXT
:
4035 return MESA_FORMAT_A_SINT8
;
4036 case GL_ALPHA16I_EXT
:
4037 return MESA_FORMAT_A_SINT16
;
4038 case GL_ALPHA32I_EXT
:
4039 return MESA_FORMAT_A_SINT32
;
4040 case GL_ALPHA8UI_EXT
:
4041 return MESA_FORMAT_A_UINT8
;
4042 case GL_ALPHA16UI_EXT
:
4043 return MESA_FORMAT_A_UINT16
;
4044 case GL_ALPHA32UI_EXT
:
4045 return MESA_FORMAT_A_UINT32
;
4047 return MESA_FORMAT_L_UNORM8
;
4048 case GL_LUMINANCE16
:
4049 return MESA_FORMAT_L_UNORM16
;
4050 case GL_LUMINANCE16F_ARB
:
4051 return MESA_FORMAT_L_FLOAT16
;
4052 case GL_LUMINANCE32F_ARB
:
4053 return MESA_FORMAT_L_FLOAT32
;
4054 case GL_LUMINANCE8I_EXT
:
4055 return MESA_FORMAT_L_SINT8
;
4056 case GL_LUMINANCE16I_EXT
:
4057 return MESA_FORMAT_L_SINT16
;
4058 case GL_LUMINANCE32I_EXT
:
4059 return MESA_FORMAT_L_SINT32
;
4060 case GL_LUMINANCE8UI_EXT
:
4061 return MESA_FORMAT_L_UINT8
;
4062 case GL_LUMINANCE16UI_EXT
:
4063 return MESA_FORMAT_L_UINT16
;
4064 case GL_LUMINANCE32UI_EXT
:
4065 return MESA_FORMAT_L_UINT32
;
4066 case GL_LUMINANCE8_ALPHA8
:
4067 return MESA_FORMAT_L8A8_UNORM
;
4068 case GL_LUMINANCE16_ALPHA16
:
4069 return MESA_FORMAT_L16A16_UNORM
;
4070 case GL_LUMINANCE_ALPHA16F_ARB
:
4071 return MESA_FORMAT_LA_FLOAT16
;
4072 case GL_LUMINANCE_ALPHA32F_ARB
:
4073 return MESA_FORMAT_LA_FLOAT32
;
4074 case GL_LUMINANCE_ALPHA8I_EXT
:
4075 return MESA_FORMAT_LA_SINT8
;
4076 case GL_LUMINANCE_ALPHA16I_EXT
:
4077 return MESA_FORMAT_LA_SINT8
;
4078 case GL_LUMINANCE_ALPHA32I_EXT
:
4079 return MESA_FORMAT_LA_SINT16
;
4080 case GL_LUMINANCE_ALPHA8UI_EXT
:
4081 return MESA_FORMAT_LA_UINT8
;
4082 case GL_LUMINANCE_ALPHA16UI_EXT
:
4083 return MESA_FORMAT_LA_UINT16
;
4084 case GL_LUMINANCE_ALPHA32UI_EXT
:
4085 return MESA_FORMAT_LA_UINT32
;
4087 return MESA_FORMAT_I_UNORM8
;
4088 case GL_INTENSITY16
:
4089 return MESA_FORMAT_I_UNORM16
;
4090 case GL_INTENSITY16F_ARB
:
4091 return MESA_FORMAT_I_FLOAT16
;
4092 case GL_INTENSITY32F_ARB
:
4093 return MESA_FORMAT_I_FLOAT32
;
4094 case GL_INTENSITY8I_EXT
:
4095 return MESA_FORMAT_I_SINT8
;
4096 case GL_INTENSITY16I_EXT
:
4097 return MESA_FORMAT_I_SINT16
;
4098 case GL_INTENSITY32I_EXT
:
4099 return MESA_FORMAT_I_SINT32
;
4100 case GL_INTENSITY8UI_EXT
:
4101 return MESA_FORMAT_I_UINT8
;
4102 case GL_INTENSITY16UI_EXT
:
4103 return MESA_FORMAT_I_UINT16
;
4104 case GL_INTENSITY32UI_EXT
:
4105 return MESA_FORMAT_I_UINT32
;
4111 if (ctx
->API
== API_OPENGL_CORE
&&
4112 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4113 switch (internalFormat
) {
4115 return MESA_FORMAT_RGB_FLOAT32
;
4117 return MESA_FORMAT_RGB_UINT32
;
4119 return MESA_FORMAT_RGB_SINT32
;
4125 switch (internalFormat
) {
4127 return MESA_FORMAT_R8G8B8A8_UNORM
;
4129 return MESA_FORMAT_RGBA_UNORM16
;
4130 case GL_RGBA16F_ARB
:
4131 return MESA_FORMAT_RGBA_FLOAT16
;
4132 case GL_RGBA32F_ARB
:
4133 return MESA_FORMAT_RGBA_FLOAT32
;
4135 return MESA_FORMAT_RGBA_SINT8
;
4136 case GL_RGBA16I_EXT
:
4137 return MESA_FORMAT_RGBA_SINT16
;
4138 case GL_RGBA32I_EXT
:
4139 return MESA_FORMAT_RGBA_SINT32
;
4140 case GL_RGBA8UI_EXT
:
4141 return MESA_FORMAT_RGBA_UINT8
;
4142 case GL_RGBA16UI_EXT
:
4143 return MESA_FORMAT_RGBA_UINT16
;
4144 case GL_RGBA32UI_EXT
:
4145 return MESA_FORMAT_RGBA_UINT32
;
4148 return MESA_FORMAT_R8G8_UNORM
;
4150 return MESA_FORMAT_R16G16_UNORM
;
4152 return MESA_FORMAT_RG_FLOAT16
;
4154 return MESA_FORMAT_RG_FLOAT32
;
4156 return MESA_FORMAT_RG_SINT8
;
4158 return MESA_FORMAT_RG_SINT16
;
4160 return MESA_FORMAT_RG_SINT32
;
4162 return MESA_FORMAT_RG_UINT8
;
4164 return MESA_FORMAT_RG_UINT16
;
4166 return MESA_FORMAT_RG_UINT32
;
4169 return MESA_FORMAT_R_UNORM8
;
4171 return MESA_FORMAT_R_UNORM16
;
4173 return MESA_FORMAT_R_FLOAT16
;
4175 return MESA_FORMAT_R_FLOAT32
;
4177 return MESA_FORMAT_R_SINT8
;
4179 return MESA_FORMAT_R_SINT16
;
4181 return MESA_FORMAT_R_SINT32
;
4183 return MESA_FORMAT_R_UINT8
;
4185 return MESA_FORMAT_R_UINT16
;
4187 return MESA_FORMAT_R_UINT32
;
4190 return MESA_FORMAT_NONE
;
4196 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4197 GLenum internalFormat
)
4199 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
4202 if (format
== MESA_FORMAT_NONE
)
4203 return MESA_FORMAT_NONE
;
4205 datatype
= _mesa_get_format_datatype(format
);
4207 /* The GL_ARB_texture_buffer_object spec says:
4209 * "If ARB_texture_float is not supported, references to the
4210 * floating-point internal formats provided by that extension should be
4211 * removed, and such formats may not be passed to TexBufferARB."
4213 * As a result, GL_HALF_FLOAT internal format depends on both
4214 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
4216 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
4217 !ctx
->Extensions
.ARB_texture_float
)
4218 return MESA_FORMAT_NONE
;
4220 if (!ctx
->Extensions
.ARB_texture_rg
) {
4221 GLenum base_format
= _mesa_get_format_base_format(format
);
4222 if (base_format
== GL_R
|| base_format
== GL_RG
)
4223 return MESA_FORMAT_NONE
;
4226 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4227 GLenum base_format
= _mesa_get_format_base_format(format
);
4228 if (base_format
== GL_RGB
)
4229 return MESA_FORMAT_NONE
;
4236 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4237 struct gl_buffer_object
*bufObj
,
4238 GLintptr offset
, GLsizeiptr size
)
4240 struct gl_texture_object
*texObj
;
4243 FLUSH_VERTICES(ctx
, 0);
4245 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4246 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4250 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
4251 if (format
== MESA_FORMAT_NONE
) {
4252 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4257 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4259 _mesa_lock_texture(ctx
, texObj
);
4261 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4262 texObj
->BufferObjectFormat
= internalFormat
;
4263 texObj
->_BufferObjectFormat
= format
;
4264 texObj
->BufferOffset
= offset
;
4265 texObj
->BufferSize
= size
;
4267 _mesa_unlock_texture(ctx
, texObj
);
4271 /** GL_ARB_texture_buffer_object */
4273 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4275 struct gl_buffer_object
*bufObj
;
4277 GET_CURRENT_CONTEXT(ctx
);
4279 /* NOTE: ARB_texture_buffer_object has interactions with
4280 * the compatibility profile that are not implemented.
4282 if (!(ctx
->API
== API_OPENGL_CORE
&&
4283 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4284 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4288 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4289 if (!bufObj
&& buffer
) {
4290 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4294 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4298 /** GL_ARB_texture_buffer_range */
4300 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4301 GLintptr offset
, GLsizeiptr size
)
4303 struct gl_buffer_object
*bufObj
;
4305 GET_CURRENT_CONTEXT(ctx
);
4307 if (!(ctx
->API
== API_OPENGL_CORE
&&
4308 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4309 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4313 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4317 (offset
+ size
) > bufObj
->Size
) {
4318 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4321 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4322 _mesa_error(ctx
, GL_INVALID_VALUE
,
4323 "glTexBufferRange(invalid offset alignment)");
4326 } else if (buffer
) {
4327 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4335 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4340 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4342 /* Everything that is allowed for renderbuffers,
4343 * except for a base format of GL_STENCIL_INDEX.
4345 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4346 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4350 /** GL_ARB_texture_multisample */
4352 check_multisample_target(GLuint dims
, GLenum target
)
4355 case GL_TEXTURE_2D_MULTISAMPLE
:
4356 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4359 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4360 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4370 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4371 GLint internalformat
, GLsizei width
, GLsizei height
,
4372 GLsizei depth
, GLboolean fixedsamplelocations
,
4373 GLboolean immutable
, const char *func
)
4375 struct gl_texture_object
*texObj
;
4376 struct gl_texture_image
*texImage
;
4377 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
4378 mesa_format texFormat
;
4379 GLenum sample_count_error
;
4381 GET_CURRENT_CONTEXT(ctx
);
4383 if (!(ctx
->Extensions
.ARB_texture_multisample
4384 && _mesa_is_desktop_gl(ctx
))) {
4385 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4389 if (!check_multisample_target(dims
, target
)) {
4390 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4394 /* check that the specified internalformat is color/depth/stencil-renderable;
4395 * refer GL3.1 spec 4.4.4
4398 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4399 _mesa_error(ctx
, GL_INVALID_ENUM
,
4400 "%s(internalformat=%s not legal for immutable-format)",
4401 func
, _mesa_lookup_enum_by_nr(internalformat
));
4405 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4406 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4407 "%s(internalformat=%s)",
4408 func
, _mesa_lookup_enum_by_nr(internalformat
));
4412 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4413 internalformat
, samples
);
4414 samplesOK
= sample_count_error
== GL_NO_ERROR
;
4416 /* Page 254 of OpenGL 4.4 spec says:
4417 * "Proxy arrays for two-dimensional multisample and two-dimensional
4418 * multisample array textures are operated on in the same way when
4419 * TexImage2DMultisample is called with target specified as
4420 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
4421 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
4422 * However, if samples is not supported, then no error is generated.
4424 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
4425 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4429 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4431 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4432 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4433 "%s(texture object 0)",
4438 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4440 if (texImage
== NULL
) {
4441 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4445 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4446 internalformat
, GL_NONE
, GL_NONE
);
4447 assert(texFormat
!= MESA_FORMAT_NONE
);
4449 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4450 width
, height
, depth
, 0);
4452 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4453 width
, height
, depth
, 0);
4455 if (_mesa_is_proxy_texture(target
)) {
4456 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
4457 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
4458 internalformat
, texFormat
,
4459 samples
, fixedsamplelocations
);
4462 /* clear all image fields */
4463 clear_teximage_fields(texImage
);
4467 if (!dimensionsOK
) {
4468 _mesa_error(ctx
, GL_INVALID_VALUE
,
4469 "%s(invalid width or height)", func
);
4474 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4475 "%s(texture too large)", func
);
4479 /* Check if texObj->Immutable is set */
4480 if (texObj
->Immutable
) {
4481 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4485 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4487 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
4488 internalformat
, texFormat
,
4489 samples
, fixedsamplelocations
);
4491 if (width
> 0 && height
> 0 && depth
> 0) {
4492 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4493 width
, height
, depth
)) {
4494 /* tidy up the texture image state. strictly speaking,
4495 * we're allowed to just leave this in whatever state we
4496 * like, but being tidy is good.
4498 _mesa_init_teximage_fields(ctx
, texImage
,
4499 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4503 texObj
->Immutable
= immutable
;
4506 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
4509 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4515 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4516 GLenum internalformat
, GLsizei width
,
4517 GLsizei height
, GLboolean fixedsamplelocations
)
4519 teximagemultisample(2, target
, samples
, internalformat
,
4520 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4521 "glTexImage2DMultisample");
4526 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4527 GLenum internalformat
, GLsizei width
,
4528 GLsizei height
, GLsizei depth
,
4529 GLboolean fixedsamplelocations
)
4531 teximagemultisample(3, target
, samples
, internalformat
,
4532 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4533 "glTexImage3DMultisample");
4538 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4539 GLenum internalformat
, GLsizei width
,
4540 GLsizei height
, GLboolean fixedsamplelocations
)
4542 teximagemultisample(2, target
, samples
, internalformat
,
4543 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4544 "glTexStorage2DMultisample");
4549 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4550 GLenum internalformat
, GLsizei width
,
4551 GLsizei height
, GLsizei depth
,
4552 GLboolean fixedsamplelocations
)
4554 teximagemultisample(3, target
, samples
, internalformat
,
4555 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4556 "glTexStorage3DMultisample");