2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
43 #include "multisample.h"
45 #include "texcompress.h"
46 #include "texcompress_cpal.h"
50 #include "texstorage.h"
51 #include "textureview.h"
53 #include "glformats.h"
57 * State changes which we care about for glCopyTex[Sub]Image() calls.
58 * In particular, we care about pixel transfer state and buffer state
59 * (such as glReadBuffer to make sure we read from the right renderbuffer).
61 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
66 * Return the simple base format for a given internal texture format.
67 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
69 * \param ctx GL context.
70 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
72 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
73 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
75 * This is the format which is used during texture application (i.e. the
76 * texture format and env mode determine the arithmetic used.
79 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
81 switch (internalFormat
) {
87 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
94 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
96 case GL_LUMINANCE_ALPHA
:
97 case GL_LUMINANCE4_ALPHA4
:
98 case GL_LUMINANCE6_ALPHA2
:
99 case GL_LUMINANCE8_ALPHA8
:
100 case GL_LUMINANCE12_ALPHA4
:
101 case GL_LUMINANCE12_ALPHA12
:
102 case GL_LUMINANCE16_ALPHA16
:
103 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
109 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
111 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
122 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
136 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
138 if (_mesa_is_gles(ctx
)) {
139 switch (internalFormat
) {
147 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
148 switch (internalFormat
) {
156 if (ctx
->Extensions
.ARB_depth_texture
) {
157 switch (internalFormat
) {
158 case GL_DEPTH_COMPONENT
:
159 case GL_DEPTH_COMPONENT16
:
160 case GL_DEPTH_COMPONENT24
:
161 case GL_DEPTH_COMPONENT32
:
162 return GL_DEPTH_COMPONENT
;
168 switch (internalFormat
) {
169 case GL_COMPRESSED_ALPHA
:
171 case GL_COMPRESSED_LUMINANCE
:
173 case GL_COMPRESSED_LUMINANCE_ALPHA
:
174 return GL_LUMINANCE_ALPHA
;
175 case GL_COMPRESSED_INTENSITY
:
177 case GL_COMPRESSED_RGB
:
179 case GL_COMPRESSED_RGBA
:
185 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
186 switch (internalFormat
) {
187 case GL_COMPRESSED_RGB_FXT1_3DFX
:
189 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
196 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
198 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
199 switch (internalFormat
) {
200 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
202 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
203 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
204 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
211 if (_mesa_is_desktop_gl(ctx
)
212 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
213 switch (internalFormat
) {
225 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
226 if (internalFormat
== GL_YCBCR_MESA
)
227 return GL_YCBCR_MESA
;
230 if (ctx
->Extensions
.ARB_texture_float
) {
231 switch (internalFormat
) {
232 case GL_ALPHA16F_ARB
:
233 case GL_ALPHA32F_ARB
:
241 case GL_INTENSITY16F_ARB
:
242 case GL_INTENSITY32F_ARB
:
244 case GL_LUMINANCE16F_ARB
:
245 case GL_LUMINANCE32F_ARB
:
247 case GL_LUMINANCE_ALPHA16F_ARB
:
248 case GL_LUMINANCE_ALPHA32F_ARB
:
249 return GL_LUMINANCE_ALPHA
;
255 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
256 switch (internalFormat
) {
265 if (ctx
->Extensions
.EXT_texture_snorm
) {
266 switch (internalFormat
) {
281 case GL_RGBA16_SNORM
:
284 case GL_ALPHA8_SNORM
:
285 case GL_ALPHA16_SNORM
:
287 case GL_LUMINANCE_SNORM
:
288 case GL_LUMINANCE8_SNORM
:
289 case GL_LUMINANCE16_SNORM
:
291 case GL_LUMINANCE_ALPHA_SNORM
:
292 case GL_LUMINANCE8_ALPHA8_SNORM
:
293 case GL_LUMINANCE16_ALPHA16_SNORM
:
294 return GL_LUMINANCE_ALPHA
;
295 case GL_INTENSITY_SNORM
:
296 case GL_INTENSITY8_SNORM
:
297 case GL_INTENSITY16_SNORM
:
304 switch (internalFormat
) {
305 case GL_DEPTH_STENCIL
:
306 case GL_DEPTH24_STENCIL8
:
307 return GL_DEPTH_STENCIL
;
312 if (ctx
->Extensions
.EXT_texture_sRGB
) {
313 switch (internalFormat
) {
316 case GL_COMPRESSED_SRGB_EXT
:
318 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
319 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
320 case GL_SRGB_ALPHA_EXT
:
321 case GL_SRGB8_ALPHA8_EXT
:
322 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
324 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
325 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
326 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
327 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
328 case GL_SLUMINANCE_ALPHA_EXT
:
329 case GL_SLUMINANCE8_ALPHA8_EXT
:
330 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
331 return GL_LUMINANCE_ALPHA
;
332 case GL_SLUMINANCE_EXT
:
333 case GL_SLUMINANCE8_EXT
:
334 case GL_COMPRESSED_SLUMINANCE_EXT
:
341 if (ctx
->Version
>= 30 ||
342 ctx
->Extensions
.EXT_texture_integer
) {
343 switch (internalFormat
) {
345 case GL_RGBA16UI_EXT
:
346 case GL_RGBA32UI_EXT
:
362 if (ctx
->Extensions
.EXT_texture_integer
) {
363 switch (internalFormat
) {
364 case GL_ALPHA8UI_EXT
:
365 case GL_ALPHA16UI_EXT
:
366 case GL_ALPHA32UI_EXT
:
368 case GL_ALPHA16I_EXT
:
369 case GL_ALPHA32I_EXT
:
371 case GL_INTENSITY8UI_EXT
:
372 case GL_INTENSITY16UI_EXT
:
373 case GL_INTENSITY32UI_EXT
:
374 case GL_INTENSITY8I_EXT
:
375 case GL_INTENSITY16I_EXT
:
376 case GL_INTENSITY32I_EXT
:
378 case GL_LUMINANCE8UI_EXT
:
379 case GL_LUMINANCE16UI_EXT
:
380 case GL_LUMINANCE32UI_EXT
:
381 case GL_LUMINANCE8I_EXT
:
382 case GL_LUMINANCE16I_EXT
:
383 case GL_LUMINANCE32I_EXT
:
385 case GL_LUMINANCE_ALPHA8UI_EXT
:
386 case GL_LUMINANCE_ALPHA16UI_EXT
:
387 case GL_LUMINANCE_ALPHA32UI_EXT
:
388 case GL_LUMINANCE_ALPHA8I_EXT
:
389 case GL_LUMINANCE_ALPHA16I_EXT
:
390 case GL_LUMINANCE_ALPHA32I_EXT
:
391 return GL_LUMINANCE_ALPHA
;
397 if (ctx
->Extensions
.ARB_texture_rg
) {
398 switch (internalFormat
) {
400 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
402 if (!ctx
->Extensions
.ARB_half_float_pixel
)
406 if (!ctx
->Extensions
.ARB_texture_float
)
415 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
421 case GL_COMPRESSED_RED
:
425 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
427 if (!ctx
->Extensions
.ARB_half_float_pixel
)
431 if (!ctx
->Extensions
.ARB_texture_float
)
440 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
446 case GL_COMPRESSED_RG
:
453 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
454 switch (internalFormat
) {
462 if (ctx
->Extensions
.EXT_packed_float
) {
463 switch (internalFormat
) {
464 case GL_R11F_G11F_B10F_EXT
:
471 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
472 switch (internalFormat
) {
473 case GL_DEPTH_COMPONENT32F
:
474 return GL_DEPTH_COMPONENT
;
475 case GL_DEPTH32F_STENCIL8
:
476 return GL_DEPTH_STENCIL
;
482 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
483 switch (internalFormat
) {
484 case GL_COMPRESSED_RED_RGTC1
:
485 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
487 case GL_COMPRESSED_RG_RGTC2
:
488 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
495 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
496 switch (internalFormat
) {
497 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
498 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
500 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
501 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
502 return GL_LUMINANCE_ALPHA
;
508 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
509 switch (internalFormat
) {
510 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
511 return GL_LUMINANCE_ALPHA
;
517 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
518 switch (internalFormat
) {
519 case GL_ETC1_RGB8_OES
:
526 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
527 switch (internalFormat
) {
528 case GL_COMPRESSED_RGB8_ETC2
:
529 case GL_COMPRESSED_SRGB8_ETC2
:
531 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
532 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
533 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
534 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
536 case GL_COMPRESSED_R11_EAC
:
537 case GL_COMPRESSED_SIGNED_R11_EAC
:
539 case GL_COMPRESSED_RG11_EAC
:
540 case GL_COMPRESSED_SIGNED_RG11_EAC
:
547 if (ctx
->API
== API_OPENGLES
) {
548 switch (internalFormat
) {
549 case GL_PALETTE4_RGB8_OES
:
550 case GL_PALETTE4_R5_G6_B5_OES
:
551 case GL_PALETTE8_RGB8_OES
:
552 case GL_PALETTE8_R5_G6_B5_OES
:
554 case GL_PALETTE4_RGBA8_OES
:
555 case GL_PALETTE8_RGB5_A1_OES
:
556 case GL_PALETTE4_RGBA4_OES
:
557 case GL_PALETTE4_RGB5_A1_OES
:
558 case GL_PALETTE8_RGBA8_OES
:
559 case GL_PALETTE8_RGBA4_OES
:
566 return -1; /* error */
571 * For cube map faces, return a face index in [0,5].
572 * For other targets return 0;
575 _mesa_tex_target_to_face(GLenum target
)
577 if (_mesa_is_cube_face(target
))
578 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
586 * Install gl_texture_image in a gl_texture_object according to the target
587 * and level parameters.
589 * \param tObj texture object.
590 * \param target texture target.
591 * \param level image level.
592 * \param texImage texture image.
595 set_tex_image(struct gl_texture_object
*tObj
,
596 GLenum target
, GLint level
,
597 struct gl_texture_image
*texImage
)
599 const GLuint face
= _mesa_tex_target_to_face(target
);
603 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
606 tObj
->Image
[face
][level
] = texImage
;
608 /* Set the 'back' pointer */
609 texImage
->TexObject
= tObj
;
610 texImage
->Level
= level
;
611 texImage
->Face
= face
;
616 * Allocate a texture image structure.
618 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
621 * \return a pointer to gl_texture_image struct with all fields initialized to
624 struct gl_texture_image
*
625 _mesa_new_texture_image( struct gl_context
*ctx
)
628 return CALLOC_STRUCT(gl_texture_image
);
633 * Free a gl_texture_image and associated data.
634 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
636 * \param texImage texture image.
638 * Free the texture image structure and the associated image data.
641 _mesa_delete_texture_image(struct gl_context
*ctx
,
642 struct gl_texture_image
*texImage
)
644 /* Free texImage->Data and/or any other driver-specific texture
647 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
648 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
654 * Test if a target is a proxy target.
656 * \param target texture target.
658 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
661 _mesa_is_proxy_texture(GLenum target
)
664 static const GLenum targets
[] = {
668 GL_PROXY_TEXTURE_CUBE_MAP
,
669 GL_PROXY_TEXTURE_RECTANGLE
,
670 GL_PROXY_TEXTURE_1D_ARRAY
,
671 GL_PROXY_TEXTURE_2D_ARRAY
,
672 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
673 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
674 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
677 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
678 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
680 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== Elements(targets
) + 2);
682 for (i
= 0; i
< Elements(targets
); ++i
)
683 if (target
== targets
[i
])
690 * Return the proxy target which corresponds to the given texture target
693 _mesa_get_proxy_target(GLenum target
)
697 case GL_PROXY_TEXTURE_1D
:
698 return GL_PROXY_TEXTURE_1D
;
700 case GL_PROXY_TEXTURE_2D
:
701 return GL_PROXY_TEXTURE_2D
;
703 case GL_PROXY_TEXTURE_3D
:
704 return GL_PROXY_TEXTURE_3D
;
705 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
706 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
707 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
708 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
709 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
710 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
711 case GL_TEXTURE_CUBE_MAP_ARB
:
712 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
713 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
714 case GL_TEXTURE_RECTANGLE_NV
:
715 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
716 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
717 case GL_TEXTURE_1D_ARRAY_EXT
:
718 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
719 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
720 case GL_TEXTURE_2D_ARRAY_EXT
:
721 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
722 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
723 case GL_TEXTURE_CUBE_MAP_ARRAY
:
724 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
725 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
726 case GL_TEXTURE_2D_MULTISAMPLE
:
727 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
728 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
729 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
730 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
731 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
733 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
740 * Get the texture object that corresponds to the target of the given
741 * texture unit. The target should have already been checked for validity.
743 * \param ctx GL context.
744 * \param texUnit texture unit.
745 * \param target texture target.
747 * \return pointer to the texture object on success, or NULL on failure.
749 struct gl_texture_object
*
750 _mesa_select_tex_object(struct gl_context
*ctx
,
751 const struct gl_texture_unit
*texUnit
,
754 const GLboolean arrayTex
= ctx
->Extensions
.EXT_texture_array
;
758 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
759 case GL_PROXY_TEXTURE_1D
:
760 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
762 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
763 case GL_PROXY_TEXTURE_2D
:
764 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
766 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
767 case GL_PROXY_TEXTURE_3D
:
768 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
769 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
770 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
771 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
772 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
773 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
774 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
775 case GL_TEXTURE_CUBE_MAP_ARB
:
776 return ctx
->Extensions
.ARB_texture_cube_map
777 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
778 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
779 return ctx
->Extensions
.ARB_texture_cube_map
780 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
781 case GL_TEXTURE_CUBE_MAP_ARRAY
:
782 return ctx
->Extensions
.ARB_texture_cube_map_array
783 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
784 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
785 return ctx
->Extensions
.ARB_texture_cube_map_array
786 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
787 case GL_TEXTURE_RECTANGLE_NV
:
788 return ctx
->Extensions
.NV_texture_rectangle
789 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
790 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
791 return ctx
->Extensions
.NV_texture_rectangle
792 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
793 case GL_TEXTURE_1D_ARRAY_EXT
:
794 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
795 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
796 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
797 case GL_TEXTURE_2D_ARRAY_EXT
:
798 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
799 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
800 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
801 case GL_TEXTURE_BUFFER
:
802 return ctx
->API
== API_OPENGL_CORE
&&
803 ctx
->Extensions
.ARB_texture_buffer_object
?
804 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
805 case GL_TEXTURE_EXTERNAL_OES
:
806 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
807 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
808 case GL_TEXTURE_2D_MULTISAMPLE
:
809 return ctx
->Extensions
.ARB_texture_multisample
810 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
811 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
812 return ctx
->Extensions
.ARB_texture_multisample
813 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
814 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
815 return ctx
->Extensions
.ARB_texture_multisample
816 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
817 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
818 return ctx
->Extensions
.ARB_texture_multisample
819 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
821 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
828 * Return pointer to texture object for given target on current texture unit.
830 struct gl_texture_object
*
831 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
833 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
834 return _mesa_select_tex_object(ctx
, texUnit
, target
);
839 * Get a texture image pointer from a texture object, given a texture
840 * target and mipmap level. The target and level parameters should
841 * have already been error-checked.
843 * \param ctx GL context.
844 * \param texObj texture unit.
845 * \param target texture target.
846 * \param level image level.
848 * \return pointer to the texture image structure, or NULL on failure.
850 struct gl_texture_image
*
851 _mesa_select_tex_image(struct gl_context
*ctx
,
852 const struct gl_texture_object
*texObj
,
853 GLenum target
, GLint level
)
855 const GLuint face
= _mesa_tex_target_to_face(target
);
859 ASSERT(level
< MAX_TEXTURE_LEVELS
);
861 return texObj
->Image
[face
][level
];
866 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
867 * it and install it. Only return NULL if passed a bad parameter or run
870 struct gl_texture_image
*
871 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
872 GLenum target
, GLint level
)
874 struct gl_texture_image
*texImage
;
879 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
881 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
883 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
887 set_tex_image(texObj
, target
, level
, texImage
);
895 * Return pointer to the specified proxy texture image.
896 * Note that proxy textures are per-context, not per-texture unit.
897 * \return pointer to texture image or NULL if invalid target, invalid
898 * level, or out of memory.
900 static struct gl_texture_image
*
901 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
903 struct gl_texture_image
*texImage
;
910 case GL_PROXY_TEXTURE_1D
:
911 if (level
>= ctx
->Const
.MaxTextureLevels
)
913 texIndex
= TEXTURE_1D_INDEX
;
915 case GL_PROXY_TEXTURE_2D
:
916 if (level
>= ctx
->Const
.MaxTextureLevels
)
918 texIndex
= TEXTURE_2D_INDEX
;
920 case GL_PROXY_TEXTURE_3D
:
921 if (level
>= ctx
->Const
.Max3DTextureLevels
)
923 texIndex
= TEXTURE_3D_INDEX
;
925 case GL_PROXY_TEXTURE_CUBE_MAP
:
926 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
928 texIndex
= TEXTURE_CUBE_INDEX
;
930 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
933 texIndex
= TEXTURE_RECT_INDEX
;
935 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
936 if (level
>= ctx
->Const
.MaxTextureLevels
)
938 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
940 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
941 if (level
>= ctx
->Const
.MaxTextureLevels
)
943 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
945 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
946 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
948 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
950 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
953 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
955 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
958 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
964 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
966 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
968 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
971 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
972 /* Set the 'back' pointer */
973 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
980 * Get the maximum number of allowed mipmap levels.
982 * \param ctx GL context.
983 * \param target texture target.
985 * \return the maximum number of allowed mipmap levels for the given
986 * texture target, or zero if passed a bad target.
991 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
995 case GL_PROXY_TEXTURE_1D
:
997 case GL_PROXY_TEXTURE_2D
:
998 return ctx
->Const
.MaxTextureLevels
;
1000 case GL_PROXY_TEXTURE_3D
:
1001 return ctx
->Const
.Max3DTextureLevels
;
1002 case GL_TEXTURE_CUBE_MAP
:
1003 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1004 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1005 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1006 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1007 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1008 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1009 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1010 return ctx
->Extensions
.ARB_texture_cube_map
1011 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1012 case GL_TEXTURE_RECTANGLE_NV
:
1013 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1014 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
1015 case GL_TEXTURE_1D_ARRAY_EXT
:
1016 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1017 case GL_TEXTURE_2D_ARRAY_EXT
:
1018 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1019 return ctx
->Extensions
.EXT_texture_array
1020 ? ctx
->Const
.MaxTextureLevels
: 0;
1021 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1022 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1023 return ctx
->Extensions
.ARB_texture_cube_map_array
1024 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1025 case GL_TEXTURE_BUFFER
:
1026 return ctx
->API
== API_OPENGL_CORE
&&
1027 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1028 case GL_TEXTURE_2D_MULTISAMPLE
:
1029 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1030 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1031 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1032 return _mesa_is_desktop_gl(ctx
)
1033 && ctx
->Extensions
.ARB_texture_multisample
1035 case GL_TEXTURE_EXTERNAL_OES
:
1038 return 0; /* bad target */
1044 * Return number of dimensions per mipmap level for the given texture target.
1047 _mesa_get_texture_dimensions(GLenum target
)
1051 case GL_PROXY_TEXTURE_1D
:
1054 case GL_TEXTURE_RECTANGLE
:
1055 case GL_TEXTURE_CUBE_MAP
:
1056 case GL_PROXY_TEXTURE_2D
:
1057 case GL_PROXY_TEXTURE_RECTANGLE
:
1058 case GL_PROXY_TEXTURE_CUBE_MAP
:
1059 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1060 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1061 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1062 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1063 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1064 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1065 case GL_TEXTURE_1D_ARRAY
:
1066 case GL_PROXY_TEXTURE_1D_ARRAY
:
1067 case GL_TEXTURE_EXTERNAL_OES
:
1068 case GL_TEXTURE_2D_MULTISAMPLE
:
1069 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1072 case GL_PROXY_TEXTURE_3D
:
1073 case GL_TEXTURE_2D_ARRAY
:
1074 case GL_PROXY_TEXTURE_2D_ARRAY
:
1075 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1076 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1077 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1078 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1080 case GL_TEXTURE_BUFFER
:
1083 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1091 * Check if a texture target can have more than one layer.
1094 _mesa_tex_target_is_layered(GLenum target
)
1098 case GL_PROXY_TEXTURE_1D
:
1100 case GL_PROXY_TEXTURE_2D
:
1101 case GL_TEXTURE_RECTANGLE
:
1102 case GL_PROXY_TEXTURE_RECTANGLE
:
1103 case GL_TEXTURE_2D_MULTISAMPLE
:
1104 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1105 case GL_TEXTURE_BUFFER
:
1106 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1107 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1108 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1109 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1110 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1111 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1112 case GL_TEXTURE_EXTERNAL_OES
:
1116 case GL_PROXY_TEXTURE_3D
:
1117 case GL_TEXTURE_CUBE_MAP
:
1118 case GL_PROXY_TEXTURE_CUBE_MAP
:
1119 case GL_TEXTURE_1D_ARRAY
:
1120 case GL_PROXY_TEXTURE_1D_ARRAY
:
1121 case GL_TEXTURE_2D_ARRAY
:
1122 case GL_PROXY_TEXTURE_2D_ARRAY
:
1123 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1124 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1125 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1126 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1130 assert(!"Invalid texture target.");
1137 * Return the number of layers present in the given level of an array,
1138 * cubemap or 3D texture. If the texture is not layered return zero.
1141 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1143 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1145 switch (texObj
->Target
) {
1148 case GL_TEXTURE_RECTANGLE
:
1149 case GL_TEXTURE_2D_MULTISAMPLE
:
1150 case GL_TEXTURE_BUFFER
:
1151 case GL_TEXTURE_EXTERNAL_OES
:
1154 case GL_TEXTURE_CUBE_MAP
:
1157 case GL_TEXTURE_1D_ARRAY
: {
1158 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1159 return img
? img
->Height
: 0;
1163 case GL_TEXTURE_2D_ARRAY
:
1164 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1165 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1166 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1167 return img
? img
->Depth
: 0;
1171 assert(!"Invalid texture target.");
1178 * Return the maximum number of mipmap levels for the given target
1179 * and the dimensions.
1180 * The dimensions are expected not to include the border.
1183 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1190 case GL_TEXTURE_1D_ARRAY
:
1191 case GL_PROXY_TEXTURE_1D
:
1192 case GL_PROXY_TEXTURE_1D_ARRAY
:
1195 case GL_TEXTURE_CUBE_MAP
:
1196 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1197 case GL_PROXY_TEXTURE_CUBE_MAP
:
1198 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1202 case GL_TEXTURE_2D_ARRAY
:
1203 case GL_PROXY_TEXTURE_2D
:
1204 case GL_PROXY_TEXTURE_2D_ARRAY
:
1205 size
= MAX2(width
, height
);
1208 case GL_PROXY_TEXTURE_3D
:
1209 size
= MAX3(width
, height
, depth
);
1211 case GL_TEXTURE_RECTANGLE
:
1212 case GL_TEXTURE_EXTERNAL_OES
:
1213 case GL_TEXTURE_2D_MULTISAMPLE
:
1214 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1215 case GL_PROXY_TEXTURE_RECTANGLE
:
1216 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1217 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1224 return _mesa_logbase2(size
) + 1;
1228 #if 000 /* not used anymore */
1230 * glTexImage[123]D can accept a NULL image pointer. In this case we
1231 * create a texture image with unspecified image contents per the OpenGL
1235 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1237 const GLint components
= _mesa_components_in_format(format
);
1238 const GLint numPixels
= width
* height
* depth
;
1239 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1243 * Let's see if anyone finds this. If glTexImage2D() is called with
1244 * a NULL image pointer then load the texture image with something
1245 * interesting instead of leaving it indeterminate.
1248 static const char message
[8][32] = {
1249 " X X XXXXX XXX X ",
1250 " XX XX X X X X X ",
1252 " X X XXXX XXX XXXXX ",
1255 " X X XXXXX XXX X X ",
1259 GLubyte
*imgPtr
= data
;
1261 for (h
= 0; h
< depth
; h
++) {
1262 for (i
= 0; i
< height
; i
++) {
1263 GLint srcRow
= 7 - (i
% 8);
1264 for (j
= 0; j
< width
; j
++) {
1265 GLint srcCol
= j
% 32;
1266 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1267 for (k
= 0; k
< components
; k
++) {
1283 * Set the size and format-related fields of a gl_texture_image struct
1284 * to zero. This is used when a proxy texture test fails.
1287 clear_teximage_fields(struct gl_texture_image
*img
)
1290 img
->_BaseFormat
= 0;
1291 img
->InternalFormat
= 0;
1300 img
->HeightLog2
= 0;
1302 img
->TexFormat
= MESA_FORMAT_NONE
;
1303 img
->NumSamples
= 0;
1304 img
->FixedSampleLocations
= GL_TRUE
;
1309 * Initialize basic fields of the gl_texture_image struct.
1311 * \param ctx GL context.
1312 * \param img texture image structure to be initialized.
1313 * \param width image width.
1314 * \param height image height.
1315 * \param depth image depth.
1316 * \param border image border.
1317 * \param internalFormat internal format.
1318 * \param format the actual hardware format (one of MESA_FORMAT_*)
1320 * Fills in the fields of \p img with the given information.
1321 * Note: width, height and depth include the border.
1324 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1325 struct gl_texture_image
*img
,
1326 GLsizei width
, GLsizei height
, GLsizei depth
,
1327 GLint border
, GLenum internalFormat
,
1333 ASSERT(height
>= 0);
1336 target
= img
->TexObject
->Target
;
1337 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1338 ASSERT(img
->_BaseFormat
> 0);
1339 img
->InternalFormat
= internalFormat
;
1340 img
->Border
= border
;
1342 img
->Height
= height
;
1345 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1346 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1348 img
->NumSamples
= 0;
1349 img
->FixedSampleLocations
= GL_TRUE
;
1353 case GL_TEXTURE_BUFFER
:
1354 case GL_PROXY_TEXTURE_1D
:
1359 img
->HeightLog2
= 0;
1366 case GL_TEXTURE_1D_ARRAY
:
1367 case GL_PROXY_TEXTURE_1D_ARRAY
:
1368 img
->Height2
= height
; /* no border */
1369 img
->HeightLog2
= 0; /* not used */
1377 case GL_TEXTURE_RECTANGLE
:
1378 case GL_TEXTURE_CUBE_MAP
:
1379 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1380 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1381 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1382 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1383 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1384 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1385 case GL_TEXTURE_EXTERNAL_OES
:
1386 case GL_PROXY_TEXTURE_2D
:
1387 case GL_PROXY_TEXTURE_RECTANGLE
:
1388 case GL_PROXY_TEXTURE_CUBE_MAP
:
1389 case GL_TEXTURE_2D_MULTISAMPLE
:
1390 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1391 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1392 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1399 case GL_TEXTURE_2D_ARRAY
:
1400 case GL_PROXY_TEXTURE_2D_ARRAY
:
1401 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1402 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1403 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1404 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1405 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1406 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1407 img
->Depth2
= depth
; /* no border */
1408 img
->DepthLog2
= 0; /* not used */
1411 case GL_PROXY_TEXTURE_3D
:
1412 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1413 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1414 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1415 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1418 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1423 _mesa_get_tex_max_num_levels(target
,
1424 img
->Width2
, img
->Height2
, img
->Depth2
);
1425 img
->TexFormat
= format
;
1430 * Free and clear fields of the gl_texture_image struct.
1432 * \param ctx GL context.
1433 * \param texImage texture image structure to be cleared.
1435 * After the call, \p texImage will have no data associated with it. Its
1436 * fields are cleared so that its parent object will test incomplete.
1439 _mesa_clear_texture_image(struct gl_context
*ctx
,
1440 struct gl_texture_image
*texImage
)
1442 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1443 clear_teximage_fields(texImage
);
1448 * Check the width, height, depth and border of a texture image are legal.
1449 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1451 * The target and level parameters will have already been validated.
1452 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1455 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1456 GLint level
, GLint width
, GLint height
,
1457 GLint depth
, GLint border
)
1463 case GL_PROXY_TEXTURE_1D
:
1464 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1465 maxSize
>>= level
; /* level size */
1466 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1468 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1469 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1475 case GL_PROXY_TEXTURE_2D
:
1476 case GL_TEXTURE_2D_MULTISAMPLE
:
1477 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1478 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1480 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1482 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1484 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1485 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1487 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1493 case GL_PROXY_TEXTURE_3D
:
1494 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1496 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1498 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1500 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1502 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1503 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1505 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1507 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1512 case GL_TEXTURE_RECTANGLE_NV
:
1513 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1516 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1517 if (width
< 0 || width
> maxSize
)
1519 if (height
< 0 || height
> maxSize
)
1523 case GL_TEXTURE_CUBE_MAP
:
1524 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1525 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1526 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1527 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1528 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1529 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1530 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1531 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1533 if (width
!= height
)
1535 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1537 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1539 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1540 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1542 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1547 case GL_TEXTURE_1D_ARRAY_EXT
:
1548 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1549 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1551 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1553 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1555 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1556 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1561 case GL_TEXTURE_2D_ARRAY_EXT
:
1562 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1563 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1564 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1565 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1567 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1569 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1571 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1573 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1574 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1576 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1581 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1582 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1583 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1584 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1586 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1588 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1590 if (width
!= height
)
1592 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1594 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1595 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1597 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1602 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1609 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1610 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1611 * \param destImage the destination texture image.
1612 * \return GL_TRUE if error found, GL_FALSE otherwise.
1615 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1616 const char *function
, GLuint dims
,
1617 const struct gl_texture_image
*destImage
,
1618 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1619 GLsizei subWidth
, GLsizei subHeight
,
1622 const GLenum target
= destImage
->TexObject
->Target
;
1627 _mesa_error(ctx
, GL_INVALID_VALUE
,
1628 "%s%dD(width=%d)", function
, dims
, subWidth
);
1632 if (dims
> 1 && subHeight
< 0) {
1633 _mesa_error(ctx
, GL_INVALID_VALUE
,
1634 "%s%dD(height=%d)", function
, dims
, subHeight
);
1638 if (dims
> 2 && subDepth
< 0) {
1639 _mesa_error(ctx
, GL_INVALID_VALUE
,
1640 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1644 /* check xoffset and width */
1645 if (xoffset
< - (GLint
) destImage
->Border
) {
1646 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1651 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1652 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1657 /* check yoffset and height */
1659 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1660 if (yoffset
< -yBorder
) {
1661 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1665 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1666 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1672 /* check zoffset and depth */
1674 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1675 if (zoffset
< -zBorder
) {
1676 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1679 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1680 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1686 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1687 * compressed texture images can be updated. But, that restriction may be
1688 * relaxed for particular compressed formats. At this time, all the
1689 * compressed formats supported by Mesa allow sub-textures to be updated
1690 * along compressed block boundaries.
1692 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1694 if (bw
!= 1 || bh
!= 1) {
1695 /* offset must be multiple of block size */
1696 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1697 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1698 "%s%dD(xoffset = %d, yoffset = %d)",
1699 function
, dims
, xoffset
, yoffset
);
1703 /* The size must be a multiple of bw x bh, or we must be using a
1704 * offset+size that exactly hits the edge of the image. This
1705 * is important for small mipmap levels (1x1, 2x1, etc) and for
1708 if ((subWidth
% bw
!= 0) &&
1709 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1710 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1711 "%s%dD(width = %d)", function
, dims
, subWidth
);
1715 if ((subHeight
% bh
!= 0) &&
1716 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1717 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1718 "%s%dD(height = %d)", function
, dims
, subHeight
);
1730 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1731 * specific texture image size checks.
1733 * A hardware driver might override this function if, for example, the
1734 * max 3D texture size is 512x512x64 (i.e. not a cube).
1736 * Note that width, height, depth == 0 is not an error. However, a
1737 * texture with zero width/height/depth will be considered "incomplete"
1738 * and texturing will effectively be disabled.
1740 * \param target any texture target/type
1741 * \param level as passed to glTexImage
1742 * \param format the MESA_FORMAT_x for the tex image
1743 * \param width as passed to glTexImage
1744 * \param height as passed to glTexImage
1745 * \param depth as passed to glTexImage
1746 * \param border as passed to glTexImage
1747 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1750 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1752 GLint width
, GLint height
, GLint depth
, GLint border
)
1754 /* We just check if the image size is less than MaxTextureMbytes.
1755 * Some drivers may do more specific checks.
1757 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1758 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1759 mbytes
*= _mesa_num_tex_faces(target
);
1760 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1765 * Return true if the format is only valid for glCompressedTexImage.
1768 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1771 case GL_ETC1_RGB8_OES
:
1772 case GL_PALETTE4_RGB8_OES
:
1773 case GL_PALETTE4_RGBA8_OES
:
1774 case GL_PALETTE4_R5_G6_B5_OES
:
1775 case GL_PALETTE4_RGBA4_OES
:
1776 case GL_PALETTE4_RGB5_A1_OES
:
1777 case GL_PALETTE8_RGB8_OES
:
1778 case GL_PALETTE8_RGBA8_OES
:
1779 case GL_PALETTE8_R5_G6_B5_OES
:
1780 case GL_PALETTE8_RGBA4_OES
:
1781 case GL_PALETTE8_RGB5_A1_OES
:
1790 * Helper function to determine whether a target and specific compression
1791 * format are supported.
1794 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1797 (void) intFormat
; /* not used yet */
1801 case GL_PROXY_TEXTURE_2D
:
1802 return GL_TRUE
; /* true for any compressed format so far */
1803 case GL_PROXY_TEXTURE_CUBE_MAP
:
1804 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1805 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1806 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1807 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1808 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1809 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1810 return ctx
->Extensions
.ARB_texture_cube_map
;
1811 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1812 case GL_TEXTURE_2D_ARRAY_EXT
:
1813 return ctx
->Extensions
.EXT_texture_array
;
1814 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1815 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1816 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1824 * Check if the given texture target value is legal for a
1825 * glTexImage1/2/3D call.
1828 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1834 case GL_PROXY_TEXTURE_1D
:
1835 return _mesa_is_desktop_gl(ctx
);
1843 case GL_PROXY_TEXTURE_2D
:
1844 return _mesa_is_desktop_gl(ctx
);
1845 case GL_PROXY_TEXTURE_CUBE_MAP
:
1846 return _mesa_is_desktop_gl(ctx
)
1847 && ctx
->Extensions
.ARB_texture_cube_map
;
1848 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1850 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1851 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1852 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1853 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1854 return ctx
->Extensions
.ARB_texture_cube_map
;
1855 case GL_TEXTURE_RECTANGLE_NV
:
1856 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1857 return _mesa_is_desktop_gl(ctx
)
1858 && ctx
->Extensions
.NV_texture_rectangle
;
1859 case GL_TEXTURE_1D_ARRAY_EXT
:
1860 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1861 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1869 case GL_PROXY_TEXTURE_3D
:
1870 return _mesa_is_desktop_gl(ctx
);
1871 case GL_TEXTURE_2D_ARRAY_EXT
:
1872 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1873 || _mesa_is_gles3(ctx
);
1874 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1875 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1876 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1877 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1878 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1883 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1890 * Check if the given texture target value is legal for a
1891 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1892 * The difference compared to legal_teximage_target() above is that
1893 * proxy targets are not supported.
1896 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1900 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1905 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1906 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1907 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1908 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1909 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1910 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1911 return ctx
->Extensions
.ARB_texture_cube_map
;
1912 case GL_TEXTURE_RECTANGLE_NV
:
1913 return _mesa_is_desktop_gl(ctx
)
1914 && ctx
->Extensions
.NV_texture_rectangle
;
1915 case GL_TEXTURE_1D_ARRAY_EXT
:
1916 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1924 case GL_TEXTURE_2D_ARRAY_EXT
:
1925 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1926 || _mesa_is_gles3(ctx
);
1927 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1928 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1929 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1934 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1942 * Helper function to determine if a texture object is mutable (in terms
1943 * of GL_ARB_texture_storage).
1946 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1948 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1949 return !texObj
->Immutable
;
1954 * Return expected size of a compressed texture.
1957 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1960 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1961 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1965 * Verify that a texture format is valid with a particular target
1967 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1968 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1971 * \param ctx GL context
1972 * \param target Texture target
1973 * \param internalFormat Internal format of the texture image
1974 * \param dimensions Dimensionality at the caller. This is \b not used
1975 * in the validation. It is only used when logging
1977 * \param caller Base name of the calling function (e.g.,
1978 * "glTexImage" or "glTexStorage").
1980 * \returns true if the combination is legal, false otherwise.
1983 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1984 GLenum target
, GLenum internalFormat
,
1985 unsigned dimensions
,
1988 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1989 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
1990 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1991 * Profile spec says:
1993 * "Textures with a base internal format of DEPTH_COMPONENT or
1994 * DEPTH_STENCIL are supported by texture image specification
1995 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1996 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1997 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1998 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1999 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
2000 * formats in conjunction with any other target will result in an
2001 * INVALID_OPERATION error."
2003 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
2004 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
2006 if (target
!= GL_TEXTURE_1D
&&
2007 target
!= GL_PROXY_TEXTURE_1D
&&
2008 target
!= GL_TEXTURE_2D
&&
2009 target
!= GL_PROXY_TEXTURE_2D
&&
2010 target
!= GL_TEXTURE_1D_ARRAY
&&
2011 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2012 target
!= GL_TEXTURE_2D_ARRAY
&&
2013 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2014 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2015 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2016 !((_mesa_is_cube_face(target
) ||
2017 target
== GL_TEXTURE_CUBE_MAP
||
2018 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2019 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2020 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2021 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2022 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2023 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2024 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2025 "%s%dD(bad target for depth texture)",
2026 caller
, dimensions
);
2035 * Test the glTexImage[123]D() parameters for errors.
2037 * \param ctx GL context.
2038 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2039 * \param target texture target given by the user (already validated).
2040 * \param level image level given by the user.
2041 * \param internalFormat internal format given by the user.
2042 * \param format pixel data format given by the user.
2043 * \param type pixel data type given by the user.
2044 * \param width image width given by the user.
2045 * \param height image height given by the user.
2046 * \param depth image depth given by the user.
2047 * \param border image border given by the user.
2049 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2051 * Verifies each of the parameters against the constants specified in
2052 * __struct gl_contextRec::Const and the supported extensions, and according
2053 * to the OpenGL specification.
2054 * Note that we don't fully error-check the width, height, depth values
2055 * here. That's done in _mesa_legal_texture_dimensions() which is used
2056 * by several other GL entrypoints. Plus, texture dims have a special
2057 * interaction with proxy textures.
2060 texture_error_check( struct gl_context
*ctx
,
2061 GLuint dimensions
, GLenum target
,
2062 GLint level
, GLint internalFormat
,
2063 GLenum format
, GLenum type
,
2064 GLint width
, GLint height
,
2065 GLint depth
, GLint border
)
2067 GLboolean colorFormat
;
2070 /* Even though there are no color-index textures, we still have to support
2071 * uploading color-index data and remapping it to RGB via the
2072 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2074 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2076 /* Note: for proxy textures, some error conditions immediately generate
2077 * a GL error in the usual way. But others do not generate a GL error.
2078 * Instead, they cause the width, height, depth, format fields of the
2079 * texture image to be zeroed-out. The GL spec seems to indicate that the
2080 * zero-out behaviour is only used in cases related to memory allocation.
2084 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2085 _mesa_error(ctx
, GL_INVALID_VALUE
,
2086 "glTexImage%dD(level=%d)", dimensions
, level
);
2091 if (border
< 0 || border
> 1 ||
2092 ((ctx
->API
!= API_OPENGL_COMPAT
||
2093 target
== GL_TEXTURE_RECTANGLE_NV
||
2094 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2095 _mesa_error(ctx
, GL_INVALID_VALUE
,
2096 "glTexImage%dD(border=%d)", dimensions
, border
);
2100 if (width
< 0 || height
< 0 || depth
< 0) {
2101 _mesa_error(ctx
, GL_INVALID_VALUE
,
2102 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2106 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2107 * combinations of format, internalFormat, and type that can be used.
2108 * Formats and types that require additional extensions (e.g., GL_FLOAT
2109 * requires GL_OES_texture_float) are filtered elsewhere.
2112 if (_mesa_is_gles(ctx
)) {
2113 if (_mesa_is_gles3(ctx
)) {
2114 err
= _mesa_es3_error_check_format_and_type(format
, type
,
2117 if (format
!= internalFormat
) {
2118 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2119 "glTexImage%dD(format = %s, internalFormat = %s)",
2121 _mesa_lookup_enum_by_nr(format
),
2122 _mesa_lookup_enum_by_nr(internalFormat
));
2126 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2128 if (err
!= GL_NO_ERROR
) {
2129 _mesa_error(ctx
, err
,
2130 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2132 _mesa_lookup_enum_by_nr(format
),
2133 _mesa_lookup_enum_by_nr(type
),
2134 _mesa_lookup_enum_by_nr(internalFormat
));
2139 /* Check internalFormat */
2140 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2141 _mesa_error(ctx
, GL_INVALID_VALUE
,
2142 "glTexImage%dD(internalFormat=%s)",
2143 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2147 /* Check incoming image format and type */
2148 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2149 if (err
!= GL_NO_ERROR
) {
2150 _mesa_error(ctx
, err
,
2151 "glTexImage%dD(incompatible format = %s, type = %s)",
2152 dimensions
, _mesa_lookup_enum_by_nr(format
),
2153 _mesa_lookup_enum_by_nr(type
));
2157 /* make sure internal format and format basically agree */
2158 colorFormat
= _mesa_is_color_format(format
);
2159 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2160 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2161 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2162 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2163 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2164 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2165 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2166 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2167 _mesa_lookup_enum_by_nr(format
));
2171 /* additional checks for ycbcr textures */
2172 if (internalFormat
== GL_YCBCR_MESA
) {
2173 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2174 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2175 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2177 _mesa_snprintf(message
, sizeof(message
),
2178 "glTexImage%dD(format/type YCBCR mismatch)",
2180 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2181 return GL_TRUE
; /* error */
2183 if (target
!= GL_TEXTURE_2D
&&
2184 target
!= GL_PROXY_TEXTURE_2D
&&
2185 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2186 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2187 _mesa_error(ctx
, GL_INVALID_ENUM
,
2188 "glTexImage%dD(bad target for YCbCr texture)",
2194 _mesa_snprintf(message
, sizeof(message
),
2195 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2196 dimensions
, border
);
2197 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2202 /* additional checks for depth textures */
2203 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2204 dimensions
, "glTexImage"))
2207 /* additional checks for compressed textures */
2208 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2209 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2210 _mesa_error(ctx
, GL_INVALID_ENUM
,
2211 "glTexImage%dD(target can't be compressed)", dimensions
);
2214 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2215 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2216 "glTexImage%dD(no compression for format)", dimensions
);
2220 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2221 "glTexImage%dD(border!=0)", dimensions
);
2226 /* additional checks for integer textures */
2227 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2228 (_mesa_is_enum_format_integer(format
) !=
2229 _mesa_is_enum_format_integer(internalFormat
))) {
2230 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2231 "glTexImage%dD(integer/non-integer format mismatch)",
2236 if (!mutable_tex_object(ctx
, target
)) {
2237 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2238 "glTexImage%dD(immutable texture)", dimensions
);
2242 /* if we get here, the parameters are OK */
2248 * Error checking for glCompressedTexImage[123]D().
2249 * Note that the width, height and depth values are not fully error checked
2251 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2254 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2255 GLenum target
, GLint level
,
2256 GLenum internalFormat
, GLsizei width
,
2257 GLsizei height
, GLsizei depth
, GLint border
,
2260 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2262 GLenum error
= GL_NO_ERROR
;
2263 char *reason
= ""; /* no error */
2265 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2267 error
= GL_INVALID_ENUM
;
2271 /* This will detect any invalid internalFormat value */
2272 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2273 reason
= "internalFormat";
2274 error
= GL_INVALID_ENUM
;
2278 switch (internalFormat
) {
2279 case GL_PALETTE4_RGB8_OES
:
2280 case GL_PALETTE4_RGBA8_OES
:
2281 case GL_PALETTE4_R5_G6_B5_OES
:
2282 case GL_PALETTE4_RGBA4_OES
:
2283 case GL_PALETTE4_RGB5_A1_OES
:
2284 case GL_PALETTE8_RGB8_OES
:
2285 case GL_PALETTE8_RGBA8_OES
:
2286 case GL_PALETTE8_R5_G6_B5_OES
:
2287 case GL_PALETTE8_RGBA4_OES
:
2288 case GL_PALETTE8_RGB5_A1_OES
:
2289 /* check level (note that level should be zero or less!) */
2290 if (level
> 0 || level
< -maxLevels
) {
2292 error
= GL_INVALID_VALUE
;
2296 if (dimensions
!= 2) {
2297 reason
= "compressed paletted textures must be 2D";
2298 error
= GL_INVALID_OPERATION
;
2302 /* Figure out the expected texture size (in bytes). This will be
2303 * checked against the actual size later.
2305 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2308 /* This is for the benefit of the TestProxyTexImage below. It expects
2309 * level to be non-negative. OES_compressed_paletted_texture uses a
2310 * weird mechanism where the level specified to glCompressedTexImage2D
2311 * is -(n-1) number of levels in the texture, and the data specifies the
2312 * complete mipmap stack. This is done to ensure the palette is the
2313 * same for all levels.
2320 if (level
< 0 || level
>= maxLevels
) {
2322 error
= GL_INVALID_VALUE
;
2326 /* Figure out the expected texture size (in bytes). This will be
2327 * checked against the actual size later.
2329 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2333 /* This should really never fail */
2334 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2335 reason
= "internalFormat";
2336 error
= GL_INVALID_ENUM
;
2340 /* No compressed formats support borders at this time */
2342 reason
= "border != 0";
2343 error
= GL_INVALID_VALUE
;
2347 /* check image size in bytes */
2348 if (expectedSize
!= imageSize
) {
2349 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2350 * if <imageSize> is not consistent with the format, dimensions, and
2351 * contents of the specified image.
2353 reason
= "imageSize inconsistant with width/height/format";
2354 error
= GL_INVALID_VALUE
;
2358 if (!mutable_tex_object(ctx
, target
)) {
2359 reason
= "immutable texture";
2360 error
= GL_INVALID_OPERATION
;
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)", dimensions
);
2587 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2588 if (baseFormat
< 0) {
2589 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2590 "glCopyTexImage%dD(internalFormat)", dimensions
);
2594 rb_internal_format
= rb
->InternalFormat
;
2595 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2596 if (_mesa_is_color_format(internalFormat
)) {
2597 if (rb_base_format
< 0) {
2598 _mesa_error(ctx
, GL_INVALID_VALUE
,
2599 "glCopyTexImage%dD(internalFormat)", dimensions
);
2604 if (_mesa_is_gles(ctx
)) {
2606 if (_mesa_base_format_component_count(baseFormat
) >
2607 _mesa_base_format_component_count(rb_base_format
)) {
2610 if (baseFormat
== GL_DEPTH_COMPONENT
||
2611 baseFormat
== GL_DEPTH_STENCIL
||
2612 rb_base_format
== GL_DEPTH_COMPONENT
||
2613 rb_base_format
== GL_DEPTH_STENCIL
||
2614 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2615 baseFormat
== GL_ALPHA
) &&
2616 rb_base_format
!= GL_RGBA
) ||
2617 internalFormat
== GL_RGB9_E5
) {
2620 if (internalFormat
== GL_RGB9_E5
) {
2624 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2625 "glCopyTexImage%dD(internalFormat)", dimensions
);
2630 if (_mesa_is_gles3(ctx
)) {
2631 bool rb_is_srgb
= false;
2632 bool dst_is_srgb
= false;
2634 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2635 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2639 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2643 if (rb_is_srgb
!= dst_is_srgb
) {
2644 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2645 * OpenGLES 3.0.0 spec says:
2647 * "The error INVALID_OPERATION is also generated if the
2648 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2649 * framebuffer attachment corresponding to the read buffer
2650 * is LINEAR (see section 6.1.13) and internalformat is
2651 * one of the sRGB formats described in section 3.8.16, or
2652 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2653 * SRGB and internalformat is not one of the sRGB formats."
2655 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2656 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2661 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2662 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2663 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2667 /* From the EXT_texture_integer spec:
2669 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2670 * if the texture internalformat is an integer format and the read color
2671 * buffer is not an integer format, or if the internalformat is not an
2672 * integer format and the read color buffer is an integer format."
2674 if (_mesa_is_color_format(internalFormat
)) {
2675 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2676 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2677 if (is_int
|| is_rbint
) {
2678 if (is_int
!= is_rbint
) {
2679 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2680 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2682 } else if (_mesa_is_gles(ctx
) &&
2683 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2684 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2685 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2686 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2692 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2693 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2694 _mesa_error(ctx
, GL_INVALID_ENUM
,
2695 "glCopyTexImage%dD(target)", dimensions
);
2698 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2699 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2700 "glCopyTexImage%dD(no compression for format)", dimensions
);
2704 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2705 "glCopyTexImage%dD(border!=0)", dimensions
);
2710 if (!mutable_tex_object(ctx
, target
)) {
2711 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2712 "glCopyTexImage%dD(immutable texture)", dimensions
);
2716 /* if we get here, the parameters are OK */
2722 * Test glCopyTexSubImage[12]D() parameters for errors.
2723 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2726 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2727 GLenum target
, GLint level
,
2728 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2729 GLint width
, GLint height
)
2731 struct gl_texture_object
*texObj
;
2732 struct gl_texture_image
*texImage
;
2734 /* Check that the source buffer is complete */
2735 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2736 if (ctx
->ReadBuffer
->_Status
== 0) {
2737 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2739 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2740 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2741 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2745 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2746 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2747 "glCopyTexSubImage%dD(multisample FBO)",
2753 /* check target (proxies not allowed) */
2754 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2755 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2756 dimensions
, _mesa_lookup_enum_by_nr(target
));
2761 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2762 _mesa_error(ctx
, GL_INVALID_VALUE
,
2763 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2767 /* Get dest texture object / image pointers */
2768 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2770 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2774 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2776 /* destination image does not exist */
2777 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2778 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2782 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2783 dimensions
, texImage
,
2784 xoffset
, yoffset
, zoffset
,
2785 width
, height
, 1)) {
2789 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2790 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2791 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2792 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2797 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2798 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2802 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2803 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2804 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2805 dimensions
, texImage
->_BaseFormat
);
2809 /* From the EXT_texture_integer spec:
2811 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2812 * if the texture internalformat is an integer format and the read color
2813 * buffer is not an integer format, or if the internalformat is not an
2814 * integer format and the read color buffer is an integer format."
2816 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2817 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2819 if (_mesa_is_format_integer_color(rb
->Format
) !=
2820 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2821 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2822 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2827 /* if we get here, the parameters are OK */
2832 /** Callback info for walking over FBO hash table */
2835 struct gl_context
*ctx
;
2836 struct gl_texture_object
*texObj
;
2842 * Check render to texture callback. Called from _mesa_HashWalk().
2845 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2847 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2848 const struct cb_info
*info
= (struct cb_info
*) userData
;
2849 struct gl_context
*ctx
= info
->ctx
;
2850 const struct gl_texture_object
*texObj
= info
->texObj
;
2851 const GLuint level
= info
->level
, face
= info
->face
;
2853 /* If this is a user-created FBO */
2854 if (_mesa_is_user_fbo(fb
)) {
2856 /* check if any of the FBO's attachments point to 'texObj' */
2857 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2858 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2859 if (att
->Type
== GL_TEXTURE
&&
2860 att
->Texture
== texObj
&&
2861 att
->TextureLevel
== level
&&
2862 att
->CubeMapFace
== face
) {
2863 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2864 ASSERT(att
->Renderbuffer
->TexImage
);
2865 /* Mark fb status as indeterminate to force re-validation */
2874 * When a texture image is specified we have to check if it's bound to
2875 * any framebuffer objects (render to texture) in order to detect changes
2876 * in size or format since that effects FBO completeness.
2877 * Any FBOs rendering into the texture must be re-validated.
2880 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2881 struct gl_texture_object
*texObj
,
2882 GLuint face
, GLuint level
)
2884 /* Only check this texture if it's been marked as RenderToTexture */
2885 if (texObj
->_RenderToTexture
) {
2886 struct cb_info info
;
2888 info
.texObj
= texObj
;
2891 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2897 * If the texture object's GenerateMipmap flag is set and we've
2898 * changed the texture base level image, regenerate the rest of the
2899 * mipmap levels now.
2902 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2903 struct gl_texture_object
*texObj
, GLint level
)
2905 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2906 if (texObj
->GenerateMipmap
&&
2907 level
== texObj
->BaseLevel
&&
2908 level
< texObj
->MaxLevel
) {
2909 ASSERT(ctx
->Driver
.GenerateMipmap
);
2910 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2915 /** Debug helper: override the user-requested internal format */
2917 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2920 if (internalFormat
== GL_RGBA16F_ARB
||
2921 internalFormat
== GL_RGBA32F_ARB
) {
2922 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2925 else if (internalFormat
== GL_RGB16F_ARB
||
2926 internalFormat
== GL_RGB32F_ARB
) {
2927 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2930 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2931 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2932 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2933 return GL_LUMINANCE_ALPHA
;
2935 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2936 internalFormat
== GL_LUMINANCE32F_ARB
) {
2937 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2938 return GL_LUMINANCE
;
2940 else if (internalFormat
== GL_ALPHA16F_ARB
||
2941 internalFormat
== GL_ALPHA32F_ARB
) {
2942 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2946 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2947 internalFormat = GL_RGBA;
2951 return internalFormat
;
2954 return internalFormat
;
2960 * Choose the actual hardware format for a texture image.
2961 * Try to use the same format as the previous image level when possible.
2962 * Otherwise, ask the driver for the best format.
2963 * It's important to try to choose a consistant format for all levels
2964 * for efficient texture memory layout/allocation. In particular, this
2965 * comes up during automatic mipmap generation.
2968 _mesa_choose_texture_format(struct gl_context
*ctx
,
2969 struct gl_texture_object
*texObj
,
2970 GLenum target
, GLint level
,
2971 GLenum internalFormat
, GLenum format
, GLenum type
)
2975 /* see if we've already chosen a format for the previous level */
2977 struct gl_texture_image
*prevImage
=
2978 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2979 /* See if the prev level is defined and has an internal format which
2980 * matches the new internal format.
2983 prevImage
->Width
> 0 &&
2984 prevImage
->InternalFormat
== internalFormat
) {
2985 /* use the same format */
2986 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2987 return prevImage
->TexFormat
;
2991 /* If the application requested compression to an S3TC format but we don't
2992 * have the DXTn library, force a generic compressed format instead.
2994 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2995 const GLenum before
= internalFormat
;
2997 switch (internalFormat
) {
2998 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2999 if (!ctx
->Mesa_DXTn
)
3000 internalFormat
= GL_COMPRESSED_RGB
;
3002 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3003 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3004 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3005 if (!ctx
->Mesa_DXTn
)
3006 internalFormat
= GL_COMPRESSED_RGBA
;
3012 if (before
!= internalFormat
) {
3014 "DXT compression requested (%s), "
3015 "but libtxc_dxtn library not installed. Using %s "
3017 _mesa_lookup_enum_by_nr(before
),
3018 _mesa_lookup_enum_by_nr(internalFormat
));
3022 /* choose format from scratch */
3023 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
3025 ASSERT(f
!= MESA_FORMAT_NONE
);
3031 * Adjust pixel unpack params and image dimensions to strip off the
3032 * one-pixel texture border.
3034 * Gallium and intel don't support texture borders. They've seldem been used
3035 * and seldom been implemented correctly anyway.
3037 * \param unpackNew returns the new pixel unpack parameters
3040 strip_texture_border(GLenum target
,
3041 GLint
*width
, GLint
*height
, GLint
*depth
,
3042 const struct gl_pixelstore_attrib
*unpack
,
3043 struct gl_pixelstore_attrib
*unpackNew
)
3049 *unpackNew
= *unpack
;
3051 if (unpackNew
->RowLength
== 0)
3052 unpackNew
->RowLength
= *width
;
3054 if (unpackNew
->ImageHeight
== 0)
3055 unpackNew
->ImageHeight
= *height
;
3057 assert(*width
>= 3);
3058 unpackNew
->SkipPixels
++; /* skip the border */
3059 *width
= *width
- 2; /* reduce the width by two border pixels */
3061 /* The min height of a texture with a border is 3 */
3062 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3063 unpackNew
->SkipRows
++; /* skip the border */
3064 *height
= *height
- 2; /* reduce the height by two border pixels */
3068 target
!= GL_TEXTURE_2D_ARRAY
&&
3069 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3070 unpackNew
->SkipImages
++; /* skip the border */
3071 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3077 * Common code to implement all the glTexImage1D/2D/3D functions
3078 * as well as glCompressedTexImage1D/2D/3D.
3079 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3080 * \param format the user's image format (only used if !compressed)
3081 * \param type the user's image type (only used if !compressed)
3082 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3085 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3086 GLenum target
, GLint level
, GLint internalFormat
,
3087 GLsizei width
, GLsizei height
, GLsizei depth
,
3088 GLint border
, GLenum format
, GLenum type
,
3089 GLsizei imageSize
, const GLvoid
*pixels
)
3091 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3092 struct gl_pixelstore_attrib unpack_no_border
;
3093 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3094 struct gl_texture_object
*texObj
;
3095 mesa_format texFormat
;
3096 GLboolean dimensionsOK
, sizeOK
;
3098 FLUSH_VERTICES(ctx
, 0);
3100 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3103 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3105 _mesa_lookup_enum_by_nr(target
), level
,
3106 _mesa_lookup_enum_by_nr(internalFormat
),
3107 width
, height
, depth
, border
, pixels
);
3110 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3112 _mesa_lookup_enum_by_nr(target
), level
,
3113 _mesa_lookup_enum_by_nr(internalFormat
),
3114 width
, height
, depth
, border
,
3115 _mesa_lookup_enum_by_nr(format
),
3116 _mesa_lookup_enum_by_nr(type
), pixels
);
3119 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3121 /* target error checking */
3122 if (!legal_teximage_target(ctx
, dims
, target
)) {
3123 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3124 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3128 /* general error checking */
3130 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3132 width
, height
, depth
,
3137 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3138 format
, type
, width
, height
, depth
, border
))
3142 /* Here we convert a cpal compressed image into a regular glTexImage2D
3143 * call by decompressing the texture. If we really want to support cpal
3144 * textures in any driver this would have to be changed.
3146 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3147 switch (internalFormat
) {
3148 case GL_PALETTE4_RGB8_OES
:
3149 case GL_PALETTE4_RGBA8_OES
:
3150 case GL_PALETTE4_R5_G6_B5_OES
:
3151 case GL_PALETTE4_RGBA4_OES
:
3152 case GL_PALETTE4_RGB5_A1_OES
:
3153 case GL_PALETTE8_RGB8_OES
:
3154 case GL_PALETTE8_RGBA8_OES
:
3155 case GL_PALETTE8_R5_G6_B5_OES
:
3156 case GL_PALETTE8_RGBA4_OES
:
3157 case GL_PALETTE8_RGB5_A1_OES
:
3158 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3159 width
, height
, imageSize
, pixels
);
3164 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3168 /* For glCompressedTexImage() the driver has no choice about the
3169 * texture format since we'll never transcode the user's compressed
3170 * image data. The internalFormat was error checked earlier.
3172 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3175 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3176 internalFormat
, format
, type
);
3179 assert(texFormat
!= MESA_FORMAT_NONE
);
3181 /* check that width, height, depth are legal for the mipmap level */
3182 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3183 height
, depth
, border
);
3185 /* check that the texture won't take too much memory, etc */
3186 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3188 width
, height
, depth
, border
);
3190 if (_mesa_is_proxy_texture(target
)) {
3191 /* Proxy texture: just clear or set state depending on error checking */
3192 struct gl_texture_image
*texImage
=
3193 get_proxy_tex_image(ctx
, target
, level
);
3196 return; /* GL_OUT_OF_MEMORY already recorded */
3198 if (dimensionsOK
&& sizeOK
) {
3199 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3200 border
, internalFormat
, texFormat
);
3203 clear_teximage_fields(texImage
);
3207 /* non-proxy target */
3208 const GLuint face
= _mesa_tex_target_to_face(target
);
3209 struct gl_texture_image
*texImage
;
3211 if (!dimensionsOK
) {
3212 _mesa_error(ctx
, GL_INVALID_VALUE
,
3213 "glTexImage%uD(invalid width or height or depth)",
3219 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3220 "glTexImage%uD(image too large)", dims
);
3224 /* Allow a hardware driver to just strip out the border, to provide
3225 * reliable but slightly incorrect hardware rendering instead of
3226 * rarely-tested software fallback rendering.
3228 if (border
&& ctx
->Const
.StripTextureBorder
) {
3229 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3232 unpack
= &unpack_no_border
;
3235 if (ctx
->NewState
& _NEW_PIXEL
)
3236 _mesa_update_state(ctx
);
3238 _mesa_lock_texture(ctx
, texObj
);
3240 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3243 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3246 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3248 _mesa_init_teximage_fields(ctx
, texImage
,
3249 width
, height
, depth
,
3250 border
, internalFormat
, texFormat
);
3252 /* Give the texture to the driver. <pixels> may be null. */
3253 if (width
> 0 && height
> 0 && depth
> 0) {
3255 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3259 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3260 type
, pixels
, unpack
);
3264 check_gen_mipmap(ctx
, target
, texObj
, level
);
3266 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3268 _mesa_dirty_texobj(ctx
, texObj
);
3271 _mesa_unlock_texture(ctx
, texObj
);
3278 * Called from the API. Note that width includes the border.
3281 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3282 GLsizei width
, GLint border
, GLenum format
,
3283 GLenum type
, const GLvoid
*pixels
)
3285 GET_CURRENT_CONTEXT(ctx
);
3286 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3287 border
, format
, type
, 0, pixels
);
3292 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3293 GLsizei width
, GLsizei height
, GLint border
,
3294 GLenum format
, GLenum type
,
3295 const GLvoid
*pixels
)
3297 GET_CURRENT_CONTEXT(ctx
);
3298 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3299 border
, format
, type
, 0, pixels
);
3304 * Called by the API or display list executor.
3305 * Note that width and height include the border.
3308 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3309 GLsizei width
, GLsizei height
, GLsizei depth
,
3310 GLint border
, GLenum format
, GLenum type
,
3311 const GLvoid
*pixels
)
3313 GET_CURRENT_CONTEXT(ctx
);
3314 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3315 width
, height
, depth
,
3316 border
, format
, type
, 0, pixels
);
3321 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3322 GLsizei width
, GLsizei height
, GLsizei depth
,
3323 GLint border
, GLenum format
, GLenum type
,
3324 const GLvoid
*pixels
)
3326 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3327 depth
, border
, format
, type
, pixels
);
3332 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3334 struct gl_texture_object
*texObj
;
3335 struct gl_texture_image
*texImage
;
3337 GET_CURRENT_CONTEXT(ctx
);
3338 FLUSH_VERTICES(ctx
, 0);
3342 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3344 case GL_TEXTURE_EXTERNAL_OES
:
3346 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3349 valid_target
= false;
3353 if (!valid_target
) {
3354 _mesa_error(ctx
, GL_INVALID_ENUM
,
3355 "glEGLImageTargetTexture2D(target=%d)", target
);
3360 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3361 "glEGLImageTargetTexture2D(image=%p)", image
);
3365 if (ctx
->NewState
& _NEW_PIXEL
)
3366 _mesa_update_state(ctx
);
3368 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3369 _mesa_lock_texture(ctx
, texObj
);
3371 if (texObj
->Immutable
) {
3372 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3373 "glEGLImageTargetTexture2D(texture is immutable)");
3374 _mesa_unlock_texture(ctx
, texObj
);
3378 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3380 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3382 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3384 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3385 texObj
, texImage
, image
);
3387 _mesa_dirty_texobj(ctx
, texObj
);
3389 _mesa_unlock_texture(ctx
, texObj
);
3396 * Implement all the glTexSubImage1/2/3D() functions.
3399 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3400 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3401 GLsizei width
, GLsizei height
, GLsizei depth
,
3402 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3404 struct gl_texture_object
*texObj
;
3405 struct gl_texture_image
*texImage
;
3407 FLUSH_VERTICES(ctx
, 0);
3409 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3410 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3412 _mesa_lookup_enum_by_nr(target
), level
,
3413 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3414 _mesa_lookup_enum_by_nr(format
),
3415 _mesa_lookup_enum_by_nr(type
), pixels
);
3417 /* check target (proxies not allowed) */
3418 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3419 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3420 dims
, _mesa_lookup_enum_by_nr(target
));
3424 if (ctx
->NewState
& _NEW_PIXEL
)
3425 _mesa_update_state(ctx
);
3427 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3428 xoffset
, yoffset
, zoffset
,
3429 width
, height
, depth
, format
, type
)) {
3430 return; /* error was detected */
3433 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3435 _mesa_lock_texture(ctx
, texObj
);
3437 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3439 if (width
> 0 && height
> 0 && depth
> 0) {
3440 /* If we have a border, offset=-1 is legal. Bias by border width. */
3443 if (target
!= GL_TEXTURE_2D_ARRAY
)
3444 zoffset
+= texImage
->Border
;
3447 if (target
!= GL_TEXTURE_1D_ARRAY
)
3448 yoffset
+= texImage
->Border
;
3451 xoffset
+= texImage
->Border
;
3454 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3455 xoffset
, yoffset
, zoffset
,
3456 width
, height
, depth
,
3457 format
, type
, pixels
, &ctx
->Unpack
);
3459 check_gen_mipmap(ctx
, target
, texObj
, level
);
3461 ctx
->NewState
|= _NEW_TEXTURE
;
3464 _mesa_unlock_texture(ctx
, texObj
);
3469 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3470 GLint xoffset
, GLsizei width
,
3471 GLenum format
, GLenum type
,
3472 const GLvoid
*pixels
)
3474 GET_CURRENT_CONTEXT(ctx
);
3475 texsubimage(ctx
, 1, target
, level
,
3478 format
, type
, pixels
);
3483 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3484 GLint xoffset
, GLint yoffset
,
3485 GLsizei width
, GLsizei height
,
3486 GLenum format
, GLenum type
,
3487 const GLvoid
*pixels
)
3489 GET_CURRENT_CONTEXT(ctx
);
3490 texsubimage(ctx
, 2, target
, level
,
3491 xoffset
, yoffset
, 0,
3493 format
, type
, pixels
);
3499 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3500 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3501 GLsizei width
, GLsizei height
, GLsizei depth
,
3502 GLenum format
, GLenum type
,
3503 const GLvoid
*pixels
)
3505 GET_CURRENT_CONTEXT(ctx
);
3506 texsubimage(ctx
, 3, target
, level
,
3507 xoffset
, yoffset
, zoffset
,
3508 width
, height
, depth
,
3509 format
, type
, pixels
);
3515 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3516 * from. This depends on whether the texture contains color or depth values.
3518 static struct gl_renderbuffer
*
3519 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3521 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3522 /* reading from depth/stencil buffer */
3523 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3526 /* copying from color buffer */
3527 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3532 copytexsubimage_by_slice(struct gl_context
*ctx
,
3533 struct gl_texture_image
*texImage
,
3535 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3536 struct gl_renderbuffer
*rb
,
3538 GLsizei width
, GLsizei height
)
3540 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3543 /* For 1D arrays, we copy each scanline of the source rectangle into the
3546 assert(zoffset
== 0);
3548 for (slice
= 0; slice
< height
; slice
++) {
3549 assert(yoffset
+ slice
< texImage
->Height
);
3550 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3551 xoffset
, 0, yoffset
+ slice
,
3552 rb
, x
, y
+ slice
, width
, 1);
3555 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3556 xoffset
, yoffset
, zoffset
,
3557 rb
, x
, y
, width
, height
);
3563 * Implement the glCopyTexImage1/2D() functions.
3566 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3567 GLenum target
, GLint level
, GLenum internalFormat
,
3568 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3570 struct gl_texture_object
*texObj
;
3571 struct gl_texture_image
*texImage
;
3572 const GLuint face
= _mesa_tex_target_to_face(target
);
3573 mesa_format texFormat
;
3575 FLUSH_VERTICES(ctx
, 0);
3577 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3578 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3580 _mesa_lookup_enum_by_nr(target
), level
,
3581 _mesa_lookup_enum_by_nr(internalFormat
),
3582 x
, y
, width
, height
, border
);
3584 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3585 _mesa_update_state(ctx
);
3587 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3588 width
, height
, border
))
3591 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3593 _mesa_error(ctx
, GL_INVALID_VALUE
,
3594 "glCopyTexImage%uD(invalid width or height)", dims
);
3598 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3601 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3602 internalFormat
, GL_NONE
, GL_NONE
);
3603 assert(texFormat
!= MESA_FORMAT_NONE
);
3605 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3607 width
, height
, 1, border
)) {
3608 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3609 "glCopyTexImage%uD(image too large)", dims
);
3613 if (border
&& ctx
->Const
.StripTextureBorder
) {
3615 width
-= border
* 2;
3618 height
-= border
* 2;
3623 _mesa_lock_texture(ctx
, texObj
);
3625 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3628 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3631 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3633 /* Free old texture image */
3634 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3636 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3637 border
, internalFormat
, texFormat
);
3639 if (width
&& height
) {
3640 /* Allocate texture memory (no pixel data yet) */
3641 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3643 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3645 struct gl_renderbuffer
*srcRb
=
3646 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3648 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3650 srcRb
, srcX
, srcY
, width
, height
);
3653 check_gen_mipmap(ctx
, target
, texObj
, level
);
3656 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3658 _mesa_dirty_texobj(ctx
, texObj
);
3661 _mesa_unlock_texture(ctx
, texObj
);
3667 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3668 GLenum internalFormat
,
3670 GLsizei width
, GLint border
)
3672 GET_CURRENT_CONTEXT(ctx
);
3673 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3679 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3680 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3683 GET_CURRENT_CONTEXT(ctx
);
3684 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3685 x
, y
, width
, height
, border
);
3691 * Implementation for glCopyTexSubImage1/2/3D() functions.
3694 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3695 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3696 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3698 struct gl_texture_object
*texObj
;
3699 struct gl_texture_image
*texImage
;
3701 FLUSH_VERTICES(ctx
, 0);
3703 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3704 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3706 _mesa_lookup_enum_by_nr(target
),
3707 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3709 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3710 _mesa_update_state(ctx
);
3712 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3713 xoffset
, yoffset
, zoffset
, width
, height
)) {
3717 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3719 _mesa_lock_texture(ctx
, texObj
);
3721 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3723 /* If we have a border, offset=-1 is legal. Bias by border width. */
3726 if (target
!= GL_TEXTURE_2D_ARRAY
)
3727 zoffset
+= texImage
->Border
;
3730 if (target
!= GL_TEXTURE_1D_ARRAY
)
3731 yoffset
+= texImage
->Border
;
3734 xoffset
+= texImage
->Border
;
3737 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3739 struct gl_renderbuffer
*srcRb
=
3740 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3742 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3743 xoffset
, yoffset
, zoffset
,
3744 srcRb
, x
, y
, width
, height
);
3746 check_gen_mipmap(ctx
, target
, texObj
, level
);
3748 ctx
->NewState
|= _NEW_TEXTURE
;
3751 _mesa_unlock_texture(ctx
, texObj
);
3756 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3757 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3759 GET_CURRENT_CONTEXT(ctx
);
3760 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3766 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3767 GLint xoffset
, GLint yoffset
,
3768 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3770 GET_CURRENT_CONTEXT(ctx
);
3771 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3778 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3779 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3780 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3782 GET_CURRENT_CONTEXT(ctx
);
3783 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3784 x
, y
, width
, height
);
3790 /**********************************************************************/
3791 /****** Compressed Textures ******/
3792 /**********************************************************************/
3796 * Error checking for glCompressedTexSubImage[123]D().
3797 * \return error code or GL_NO_ERROR.
3800 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3801 GLenum target
, GLint level
,
3802 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3803 GLsizei width
, GLsizei height
, GLsizei depth
,
3804 GLenum format
, GLsizei imageSize
)
3806 struct gl_texture_object
*texObj
;
3807 struct gl_texture_image
*texImage
;
3815 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3816 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3817 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3818 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3819 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3820 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3824 targetOK
= GL_FALSE
;
3829 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3833 /* no 1D compressed textures at this time */
3834 targetOK
= GL_FALSE
;
3839 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3844 /* this will catch any invalid compressed format token */
3845 if (!_mesa_is_compressed_format(ctx
, format
)) {
3846 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3851 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3852 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3857 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3858 if (expectedSize
!= imageSize
) {
3859 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3864 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3866 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3867 "glCompressedTexSubImage%uD()", dims
);
3871 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3873 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3874 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3878 if ((GLint
) format
!= texImage
->InternalFormat
) {
3879 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3880 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3884 if (compressedteximage_only_format(ctx
, format
)) {
3885 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3886 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3891 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3892 texImage
, xoffset
, yoffset
, zoffset
,
3893 width
, height
, depth
)) {
3902 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3903 GLenum internalFormat
, GLsizei width
,
3904 GLint border
, GLsizei imageSize
,
3907 GET_CURRENT_CONTEXT(ctx
);
3908 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3909 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3914 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3915 GLenum internalFormat
, GLsizei width
,
3916 GLsizei height
, GLint border
, GLsizei imageSize
,
3919 GET_CURRENT_CONTEXT(ctx
);
3920 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3921 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3926 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3927 GLenum internalFormat
, GLsizei width
,
3928 GLsizei height
, GLsizei depth
, GLint border
,
3929 GLsizei imageSize
, const GLvoid
*data
)
3931 GET_CURRENT_CONTEXT(ctx
);
3932 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3933 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3938 * Common helper for glCompressedTexSubImage1/2/3D().
3941 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3942 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3943 GLsizei width
, GLsizei height
, GLsizei depth
,
3944 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3946 struct gl_texture_object
*texObj
;
3947 struct gl_texture_image
*texImage
;
3948 GET_CURRENT_CONTEXT(ctx
);
3949 FLUSH_VERTICES(ctx
, 0);
3951 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3952 xoffset
, yoffset
, zoffset
,
3953 width
, height
, depth
,
3954 format
, imageSize
)) {
3958 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3960 _mesa_lock_texture(ctx
, texObj
);
3962 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3965 if (width
> 0 && height
> 0 && depth
> 0) {
3966 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3967 xoffset
, yoffset
, zoffset
,
3968 width
, height
, depth
,
3969 format
, imageSize
, data
);
3971 check_gen_mipmap(ctx
, target
, texObj
, level
);
3973 ctx
->NewState
|= _NEW_TEXTURE
;
3976 _mesa_unlock_texture(ctx
, texObj
);
3981 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3982 GLsizei width
, GLenum format
,
3983 GLsizei imageSize
, const GLvoid
*data
)
3985 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3986 format
, imageSize
, data
);
3991 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3992 GLint yoffset
, GLsizei width
, GLsizei height
,
3993 GLenum format
, GLsizei imageSize
,
3996 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3997 width
, height
, 1, format
, imageSize
, data
);
4002 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4003 GLint yoffset
, GLint zoffset
, GLsizei width
,
4004 GLsizei height
, GLsizei depth
, GLenum format
,
4005 GLsizei imageSize
, const GLvoid
*data
)
4007 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
4008 width
, height
, depth
, format
, imageSize
, data
);
4012 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4014 if (ctx
->API
!= API_OPENGL_CORE
) {
4015 switch (internalFormat
) {
4017 return MESA_FORMAT_A_UNORM8
;
4019 return MESA_FORMAT_A_UNORM16
;
4020 case GL_ALPHA16F_ARB
:
4021 return MESA_FORMAT_ALPHA_FLOAT16
;
4022 case GL_ALPHA32F_ARB
:
4023 return MESA_FORMAT_ALPHA_FLOAT32
;
4024 case GL_ALPHA8I_EXT
:
4025 return MESA_FORMAT_ALPHA_INT8
;
4026 case GL_ALPHA16I_EXT
:
4027 return MESA_FORMAT_ALPHA_INT16
;
4028 case GL_ALPHA32I_EXT
:
4029 return MESA_FORMAT_ALPHA_INT32
;
4030 case GL_ALPHA8UI_EXT
:
4031 return MESA_FORMAT_ALPHA_UINT8
;
4032 case GL_ALPHA16UI_EXT
:
4033 return MESA_FORMAT_ALPHA_UINT16
;
4034 case GL_ALPHA32UI_EXT
:
4035 return MESA_FORMAT_ALPHA_UINT32
;
4037 return MESA_FORMAT_L_UNORM8
;
4038 case GL_LUMINANCE16
:
4039 return MESA_FORMAT_L_UNORM16
;
4040 case GL_LUMINANCE16F_ARB
:
4041 return MESA_FORMAT_LUMINANCE_FLOAT16
;
4042 case GL_LUMINANCE32F_ARB
:
4043 return MESA_FORMAT_LUMINANCE_FLOAT32
;
4044 case GL_LUMINANCE8I_EXT
:
4045 return MESA_FORMAT_LUMINANCE_INT8
;
4046 case GL_LUMINANCE16I_EXT
:
4047 return MESA_FORMAT_LUMINANCE_INT16
;
4048 case GL_LUMINANCE32I_EXT
:
4049 return MESA_FORMAT_LUMINANCE_INT32
;
4050 case GL_LUMINANCE8UI_EXT
:
4051 return MESA_FORMAT_LUMINANCE_UINT8
;
4052 case GL_LUMINANCE16UI_EXT
:
4053 return MESA_FORMAT_LUMINANCE_UINT16
;
4054 case GL_LUMINANCE32UI_EXT
:
4055 return MESA_FORMAT_LUMINANCE_UINT32
;
4056 case GL_LUMINANCE8_ALPHA8
:
4057 return MESA_FORMAT_AL88
;
4058 case GL_LUMINANCE16_ALPHA16
:
4059 return MESA_FORMAT_AL1616
;
4060 case GL_LUMINANCE_ALPHA16F_ARB
:
4061 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
4062 case GL_LUMINANCE_ALPHA32F_ARB
:
4063 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
4064 case GL_LUMINANCE_ALPHA8I_EXT
:
4065 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
4066 case GL_LUMINANCE_ALPHA16I_EXT
:
4067 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
4068 case GL_LUMINANCE_ALPHA32I_EXT
:
4069 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
4070 case GL_LUMINANCE_ALPHA8UI_EXT
:
4071 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
4072 case GL_LUMINANCE_ALPHA16UI_EXT
:
4073 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
4074 case GL_LUMINANCE_ALPHA32UI_EXT
:
4075 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
4077 return MESA_FORMAT_I_UNORM8
;
4078 case GL_INTENSITY16
:
4079 return MESA_FORMAT_I_UNORM16
;
4080 case GL_INTENSITY16F_ARB
:
4081 return MESA_FORMAT_INTENSITY_FLOAT16
;
4082 case GL_INTENSITY32F_ARB
:
4083 return MESA_FORMAT_INTENSITY_FLOAT32
;
4084 case GL_INTENSITY8I_EXT
:
4085 return MESA_FORMAT_INTENSITY_INT8
;
4086 case GL_INTENSITY16I_EXT
:
4087 return MESA_FORMAT_INTENSITY_INT16
;
4088 case GL_INTENSITY32I_EXT
:
4089 return MESA_FORMAT_INTENSITY_INT32
;
4090 case GL_INTENSITY8UI_EXT
:
4091 return MESA_FORMAT_INTENSITY_UINT8
;
4092 case GL_INTENSITY16UI_EXT
:
4093 return MESA_FORMAT_INTENSITY_UINT16
;
4094 case GL_INTENSITY32UI_EXT
:
4095 return MESA_FORMAT_INTENSITY_UINT32
;
4101 if (ctx
->API
== API_OPENGL_CORE
&&
4102 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4103 switch (internalFormat
) {
4105 return MESA_FORMAT_RGB_FLOAT32
;
4107 return MESA_FORMAT_RGB_UINT32
;
4109 return MESA_FORMAT_RGB_INT32
;
4115 switch (internalFormat
) {
4117 return MESA_FORMAT_R8G8B8A8_UNORM
;
4119 return MESA_FORMAT_RGBA_UNORM16
;
4120 case GL_RGBA16F_ARB
:
4121 return MESA_FORMAT_RGBA_FLOAT16
;
4122 case GL_RGBA32F_ARB
:
4123 return MESA_FORMAT_RGBA_FLOAT32
;
4125 return MESA_FORMAT_RGBA_INT8
;
4126 case GL_RGBA16I_EXT
:
4127 return MESA_FORMAT_RGBA_INT16
;
4128 case GL_RGBA32I_EXT
:
4129 return MESA_FORMAT_RGBA_INT32
;
4130 case GL_RGBA8UI_EXT
:
4131 return MESA_FORMAT_RGBA_UINT8
;
4132 case GL_RGBA16UI_EXT
:
4133 return MESA_FORMAT_RGBA_UINT16
;
4134 case GL_RGBA32UI_EXT
:
4135 return MESA_FORMAT_RGBA_UINT32
;
4138 return MESA_FORMAT_GR88
;
4140 return MESA_FORMAT_GR1616
;
4142 return MESA_FORMAT_RG_FLOAT16
;
4144 return MESA_FORMAT_RG_FLOAT32
;
4146 return MESA_FORMAT_RG_INT8
;
4148 return MESA_FORMAT_RG_INT16
;
4150 return MESA_FORMAT_RG_INT32
;
4152 return MESA_FORMAT_RG_UINT8
;
4154 return MESA_FORMAT_RG_UINT16
;
4156 return MESA_FORMAT_RG_UINT32
;
4159 return MESA_FORMAT_R_UNORM8
;
4161 return MESA_FORMAT_R_UNORM16
;
4163 return MESA_FORMAT_R_FLOAT16
;
4165 return MESA_FORMAT_R_FLOAT32
;
4167 return MESA_FORMAT_R_INT8
;
4169 return MESA_FORMAT_R_INT16
;
4171 return MESA_FORMAT_R_INT32
;
4173 return MESA_FORMAT_R_UINT8
;
4175 return MESA_FORMAT_R_UINT16
;
4177 return MESA_FORMAT_R_UINT32
;
4180 return MESA_FORMAT_NONE
;
4186 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4187 GLenum internalFormat
)
4189 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
4192 if (format
== MESA_FORMAT_NONE
)
4193 return MESA_FORMAT_NONE
;
4195 datatype
= _mesa_get_format_datatype(format
);
4196 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4197 return MESA_FORMAT_NONE
;
4199 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4200 return MESA_FORMAT_NONE
;
4202 if (!ctx
->Extensions
.ARB_texture_rg
) {
4203 GLenum base_format
= _mesa_get_format_base_format(format
);
4204 if (base_format
== GL_R
|| base_format
== GL_RG
)
4205 return MESA_FORMAT_NONE
;
4208 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4209 GLenum base_format
= _mesa_get_format_base_format(format
);
4210 if (base_format
== GL_RGB
)
4211 return MESA_FORMAT_NONE
;
4218 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4219 struct gl_buffer_object
*bufObj
,
4220 GLintptr offset
, GLsizeiptr size
)
4222 struct gl_texture_object
*texObj
;
4225 FLUSH_VERTICES(ctx
, 0);
4227 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4228 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4232 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
4233 if (format
== MESA_FORMAT_NONE
) {
4234 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4239 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4241 _mesa_lock_texture(ctx
, texObj
);
4243 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4244 texObj
->BufferObjectFormat
= internalFormat
;
4245 texObj
->_BufferObjectFormat
= format
;
4246 texObj
->BufferOffset
= offset
;
4247 texObj
->BufferSize
= size
;
4249 _mesa_unlock_texture(ctx
, texObj
);
4253 /** GL_ARB_texture_buffer_object */
4255 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4257 struct gl_buffer_object
*bufObj
;
4259 GET_CURRENT_CONTEXT(ctx
);
4261 /* NOTE: ARB_texture_buffer_object has interactions with
4262 * the compatibility profile that are not implemented.
4264 if (!(ctx
->API
== API_OPENGL_CORE
&&
4265 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4266 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4270 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4271 if (!bufObj
&& buffer
) {
4272 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4276 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4280 /** GL_ARB_texture_buffer_range */
4282 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4283 GLintptr offset
, GLsizeiptr size
)
4285 struct gl_buffer_object
*bufObj
;
4287 GET_CURRENT_CONTEXT(ctx
);
4289 if (!(ctx
->API
== API_OPENGL_CORE
&&
4290 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4291 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4295 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4299 (offset
+ size
) > bufObj
->Size
) {
4300 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4303 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4304 _mesa_error(ctx
, GL_INVALID_VALUE
,
4305 "glTexBufferRange(invalid offset alignment)");
4308 } else if (buffer
) {
4309 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4317 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4322 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4324 /* Everything that is allowed for renderbuffers,
4325 * except for a base format of GL_STENCIL_INDEX.
4327 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4328 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4332 /** GL_ARB_texture_multisample */
4334 check_multisample_target(GLuint dims
, GLenum target
)
4337 case GL_TEXTURE_2D_MULTISAMPLE
:
4338 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4341 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4342 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4352 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4353 GLint internalformat
, GLsizei width
, GLsizei height
,
4354 GLsizei depth
, GLboolean fixedsamplelocations
,
4355 GLboolean immutable
, const char *func
)
4357 struct gl_texture_object
*texObj
;
4358 struct gl_texture_image
*texImage
;
4359 GLboolean sizeOK
, dimensionsOK
;
4360 mesa_format texFormat
;
4361 GLenum sample_count_error
;
4363 GET_CURRENT_CONTEXT(ctx
);
4365 if (!(ctx
->Extensions
.ARB_texture_multisample
4366 && _mesa_is_desktop_gl(ctx
))) {
4367 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4371 if (!check_multisample_target(dims
, target
)) {
4372 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4376 /* check that the specified internalformat is color/depth/stencil-renderable;
4377 * refer GL3.1 spec 4.4.4
4380 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4381 _mesa_error(ctx
, GL_INVALID_ENUM
,
4382 "%s(internalformat=%s not legal for immutable-format)",
4383 func
, _mesa_lookup_enum_by_nr(internalformat
));
4387 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4388 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4389 "%s(internalformat=%s)",
4390 func
, _mesa_lookup_enum_by_nr(internalformat
));
4394 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4395 internalformat
, samples
);
4396 if (sample_count_error
!= GL_NO_ERROR
) {
4397 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4401 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4403 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4404 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4405 "%s(texture object 0)",
4410 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4412 if (texImage
== NULL
) {
4413 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4417 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4418 internalformat
, GL_NONE
, GL_NONE
);
4419 assert(texFormat
!= MESA_FORMAT_NONE
);
4421 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4422 width
, height
, depth
, 0);
4424 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4425 width
, height
, depth
, 0);
4427 if (_mesa_is_proxy_texture(target
)) {
4428 if (dimensionsOK
&& sizeOK
) {
4429 _mesa_init_teximage_fields(ctx
, texImage
,
4430 width
, height
, depth
, 0, internalformat
, texFormat
);
4431 texImage
->NumSamples
= samples
;
4432 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4435 /* clear all image fields */
4436 _mesa_init_teximage_fields(ctx
, texImage
,
4437 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4441 if (!dimensionsOK
) {
4442 _mesa_error(ctx
, GL_INVALID_VALUE
,
4443 "%s(invalid width or height)", func
);
4448 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4449 "%s(texture too large)", func
);
4453 /* Check if texObj->Immutable is set */
4454 if (texObj
->Immutable
) {
4455 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4459 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4461 _mesa_init_teximage_fields(ctx
, texImage
,
4462 width
, height
, depth
, 0, internalformat
, texFormat
);
4464 texImage
->NumSamples
= samples
;
4465 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4467 if (width
> 0 && height
> 0 && depth
> 0) {
4468 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4469 width
, height
, depth
)) {
4470 /* tidy up the texture image state. strictly speaking,
4471 * we're allowed to just leave this in whatever state we
4472 * like, but being tidy is good.
4474 _mesa_init_teximage_fields(ctx
, texImage
,
4475 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4479 texObj
->Immutable
= immutable
;
4482 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
4485 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4491 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4492 GLenum internalformat
, GLsizei width
,
4493 GLsizei height
, GLboolean fixedsamplelocations
)
4495 teximagemultisample(2, target
, samples
, internalformat
,
4496 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4497 "glTexImage2DMultisample");
4502 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4503 GLenum internalformat
, GLsizei width
,
4504 GLsizei height
, GLsizei depth
,
4505 GLboolean fixedsamplelocations
)
4507 teximagemultisample(3, target
, samples
, internalformat
,
4508 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4509 "glTexImage3DMultisample");
4514 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4515 GLenum internalformat
, GLsizei width
,
4516 GLsizei height
, GLboolean fixedsamplelocations
)
4518 teximagemultisample(2, target
, samples
, internalformat
,
4519 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4520 "glTexStorage2DMultisample");
4525 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4526 GLenum internalformat
, GLsizei width
,
4527 GLsizei height
, GLsizei depth
,
4528 GLboolean fixedsamplelocations
)
4530 teximagemultisample(3, target
, samples
, internalformat
,
4531 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4532 "glTexStorage3DMultisample");