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 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1961 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1966 * Test the glTexImage[123]D() parameters for errors.
1968 * \param ctx GL context.
1969 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1970 * \param target texture target given by the user (already validated).
1971 * \param level image level given by the user.
1972 * \param internalFormat internal format given by the user.
1973 * \param format pixel data format given by the user.
1974 * \param type pixel data type given by the user.
1975 * \param width image width given by the user.
1976 * \param height image height given by the user.
1977 * \param depth image depth given by the user.
1978 * \param border image border given by the user.
1980 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1982 * Verifies each of the parameters against the constants specified in
1983 * __struct gl_contextRec::Const and the supported extensions, and according
1984 * to the OpenGL specification.
1985 * Note that we don't fully error-check the width, height, depth values
1986 * here. That's done in _mesa_legal_texture_dimensions() which is used
1987 * by several other GL entrypoints. Plus, texture dims have a special
1988 * interaction with proxy textures.
1991 texture_error_check( struct gl_context
*ctx
,
1992 GLuint dimensions
, GLenum target
,
1993 GLint level
, GLint internalFormat
,
1994 GLenum format
, GLenum type
,
1995 GLint width
, GLint height
,
1996 GLint depth
, GLint border
)
1998 GLboolean colorFormat
;
2001 /* Even though there are no color-index textures, we still have to support
2002 * uploading color-index data and remapping it to RGB via the
2003 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2005 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2007 /* Note: for proxy textures, some error conditions immediately generate
2008 * a GL error in the usual way. But others do not generate a GL error.
2009 * Instead, they cause the width, height, depth, format fields of the
2010 * texture image to be zeroed-out. The GL spec seems to indicate that the
2011 * zero-out behaviour is only used in cases related to memory allocation.
2015 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2016 _mesa_error(ctx
, GL_INVALID_VALUE
,
2017 "glTexImage%dD(level=%d)", dimensions
, level
);
2022 if (border
< 0 || border
> 1 ||
2023 ((ctx
->API
!= API_OPENGL_COMPAT
||
2024 target
== GL_TEXTURE_RECTANGLE_NV
||
2025 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2026 _mesa_error(ctx
, GL_INVALID_VALUE
,
2027 "glTexImage%dD(border=%d)", dimensions
, border
);
2031 if (width
< 0 || height
< 0 || depth
< 0) {
2032 _mesa_error(ctx
, GL_INVALID_VALUE
,
2033 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2037 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2038 * combinations of format, internalFormat, and type that can be used.
2039 * Formats and types that require additional extensions (e.g., GL_FLOAT
2040 * requires GL_OES_texture_float) are filtered elsewhere.
2043 if (_mesa_is_gles(ctx
)) {
2044 if (_mesa_is_gles3(ctx
)) {
2045 err
= _mesa_es3_error_check_format_and_type(format
, type
,
2048 if (format
!= internalFormat
) {
2049 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2050 "glTexImage%dD(format = %s, internalFormat = %s)",
2052 _mesa_lookup_enum_by_nr(format
),
2053 _mesa_lookup_enum_by_nr(internalFormat
));
2057 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2059 if (err
!= GL_NO_ERROR
) {
2060 _mesa_error(ctx
, err
,
2061 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2063 _mesa_lookup_enum_by_nr(format
),
2064 _mesa_lookup_enum_by_nr(type
),
2065 _mesa_lookup_enum_by_nr(internalFormat
));
2070 /* Check internalFormat */
2071 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2072 _mesa_error(ctx
, GL_INVALID_VALUE
,
2073 "glTexImage%dD(internalFormat=%s)",
2074 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2078 /* Check incoming image format and type */
2079 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2080 if (err
!= GL_NO_ERROR
) {
2081 _mesa_error(ctx
, err
,
2082 "glTexImage%dD(incompatible format = %s, type = %s)",
2083 dimensions
, _mesa_lookup_enum_by_nr(format
),
2084 _mesa_lookup_enum_by_nr(type
));
2088 /* make sure internal format and format basically agree */
2089 colorFormat
= _mesa_is_color_format(format
);
2090 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2091 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2092 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2093 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2094 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2095 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2096 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2097 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2098 _mesa_lookup_enum_by_nr(format
));
2102 /* additional checks for ycbcr textures */
2103 if (internalFormat
== GL_YCBCR_MESA
) {
2104 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2105 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2106 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2108 _mesa_snprintf(message
, sizeof(message
),
2109 "glTexImage%dD(format/type YCBCR mismatch)",
2111 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2112 return GL_TRUE
; /* error */
2114 if (target
!= GL_TEXTURE_2D
&&
2115 target
!= GL_PROXY_TEXTURE_2D
&&
2116 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2117 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2118 _mesa_error(ctx
, GL_INVALID_ENUM
,
2119 "glTexImage%dD(bad target for YCbCr texture)",
2125 _mesa_snprintf(message
, sizeof(message
),
2126 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2127 dimensions
, border
);
2128 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2133 /* additional checks for depth textures */
2134 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2135 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2136 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
2137 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
2138 if (target
!= GL_TEXTURE_1D
&&
2139 target
!= GL_PROXY_TEXTURE_1D
&&
2140 target
!= GL_TEXTURE_2D
&&
2141 target
!= GL_PROXY_TEXTURE_2D
&&
2142 target
!= GL_TEXTURE_1D_ARRAY
&&
2143 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2144 target
!= GL_TEXTURE_2D_ARRAY
&&
2145 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2146 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2147 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2148 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2149 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2150 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2151 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2152 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2153 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2154 _mesa_error(ctx
, GL_INVALID_ENUM
,
2155 "glTexImage%dD(bad target for depth texture)",
2161 /* additional checks for compressed textures */
2162 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2163 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2164 _mesa_error(ctx
, GL_INVALID_ENUM
,
2165 "glTexImage%dD(target can't be compressed)", dimensions
);
2168 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2169 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2170 "glTexImage%dD(no compression for format)", dimensions
);
2174 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2175 "glTexImage%dD(border!=0)", dimensions
);
2180 /* additional checks for integer textures */
2181 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2182 (_mesa_is_enum_format_integer(format
) !=
2183 _mesa_is_enum_format_integer(internalFormat
))) {
2184 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2185 "glTexImage%dD(integer/non-integer format mismatch)",
2190 if (!mutable_tex_object(ctx
, target
)) {
2191 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2192 "glTexImage%dD(immutable texture)", dimensions
);
2196 /* if we get here, the parameters are OK */
2202 * Error checking for glCompressedTexImage[123]D().
2203 * Note that the width, height and depth values are not fully error checked
2205 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2208 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2209 GLenum target
, GLint level
,
2210 GLenum internalFormat
, GLsizei width
,
2211 GLsizei height
, GLsizei depth
, GLint border
,
2214 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2216 GLenum error
= GL_NO_ERROR
;
2217 char *reason
= ""; /* no error */
2219 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2221 error
= GL_INVALID_ENUM
;
2225 /* This will detect any invalid internalFormat value */
2226 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2227 reason
= "internalFormat";
2228 error
= GL_INVALID_ENUM
;
2232 switch (internalFormat
) {
2233 case GL_PALETTE4_RGB8_OES
:
2234 case GL_PALETTE4_RGBA8_OES
:
2235 case GL_PALETTE4_R5_G6_B5_OES
:
2236 case GL_PALETTE4_RGBA4_OES
:
2237 case GL_PALETTE4_RGB5_A1_OES
:
2238 case GL_PALETTE8_RGB8_OES
:
2239 case GL_PALETTE8_RGBA8_OES
:
2240 case GL_PALETTE8_R5_G6_B5_OES
:
2241 case GL_PALETTE8_RGBA4_OES
:
2242 case GL_PALETTE8_RGB5_A1_OES
:
2243 /* check level (note that level should be zero or less!) */
2244 if (level
> 0 || level
< -maxLevels
) {
2246 error
= GL_INVALID_VALUE
;
2250 if (dimensions
!= 2) {
2251 reason
= "compressed paletted textures must be 2D";
2252 error
= GL_INVALID_OPERATION
;
2256 /* Figure out the expected texture size (in bytes). This will be
2257 * checked against the actual size later.
2259 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2262 /* This is for the benefit of the TestProxyTexImage below. It expects
2263 * level to be non-negative. OES_compressed_paletted_texture uses a
2264 * weird mechanism where the level specified to glCompressedTexImage2D
2265 * is -(n-1) number of levels in the texture, and the data specifies the
2266 * complete mipmap stack. This is done to ensure the palette is the
2267 * same for all levels.
2274 if (level
< 0 || level
>= maxLevels
) {
2276 error
= GL_INVALID_VALUE
;
2280 /* Figure out the expected texture size (in bytes). This will be
2281 * checked against the actual size later.
2283 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2287 /* This should really never fail */
2288 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2289 reason
= "internalFormat";
2290 error
= GL_INVALID_ENUM
;
2294 /* No compressed formats support borders at this time */
2296 reason
= "border != 0";
2297 error
= GL_INVALID_VALUE
;
2301 /* check image size in bytes */
2302 if (expectedSize
!= imageSize
) {
2303 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2304 * if <imageSize> is not consistent with the format, dimensions, and
2305 * contents of the specified image.
2307 reason
= "imageSize inconsistant with width/height/format";
2308 error
= GL_INVALID_VALUE
;
2312 if (!mutable_tex_object(ctx
, target
)) {
2313 reason
= "immutable texture";
2314 error
= GL_INVALID_OPERATION
;
2321 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2328 * Test glTexSubImage[123]D() parameters for errors.
2330 * \param ctx GL context.
2331 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2332 * \param target texture target given by the user (already validated)
2333 * \param level image level given by the user.
2334 * \param xoffset sub-image x offset given by the user.
2335 * \param yoffset sub-image y offset given by the user.
2336 * \param zoffset sub-image z offset given by the user.
2337 * \param format pixel data format given by the user.
2338 * \param type pixel data type given by the user.
2339 * \param width image width given by the user.
2340 * \param height image height given by the user.
2341 * \param depth image depth given by the user.
2343 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2345 * Verifies each of the parameters against the constants specified in
2346 * __struct gl_contextRec::Const and the supported extensions, and according
2347 * to the OpenGL specification.
2350 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2351 GLenum target
, GLint level
,
2352 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2353 GLint width
, GLint height
, GLint depth
,
2354 GLenum format
, GLenum type
)
2356 struct gl_texture_object
*texObj
;
2357 struct gl_texture_image
*texImage
;
2360 /* check target (proxies not allowed) */
2361 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2362 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2363 dimensions
, _mesa_lookup_enum_by_nr(target
));
2368 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2369 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2374 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2375 * combinations of format and type that can be used. Formats and types
2376 * that require additional extensions (e.g., GL_FLOAT requires
2377 * GL_OES_texture_float) are filtered elsewhere.
2379 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2380 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2381 if (err
!= GL_NO_ERROR
) {
2382 _mesa_error(ctx
, err
,
2383 "glTexSubImage%dD(format = %s, type = %s)",
2385 _mesa_lookup_enum_by_nr(format
),
2386 _mesa_lookup_enum_by_nr(type
));
2391 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2392 if (err
!= GL_NO_ERROR
) {
2393 _mesa_error(ctx
, err
,
2394 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2395 dimensions
, _mesa_lookup_enum_by_nr(format
),
2396 _mesa_lookup_enum_by_nr(type
));
2400 /* Get dest texture object / image pointers */
2401 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2403 /* must be out of memory */
2404 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2408 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2410 /* non-existant texture level */
2411 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2412 "glTexSubImage%dD(invalid texture image)", dimensions
);
2416 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2417 texImage
, xoffset
, yoffset
, 0,
2418 width
, height
, 1)) {
2422 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2423 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2424 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2425 "glTexSubImage%dD(no compression for format)", dimensions
);
2430 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2431 /* both source and dest must be integer-valued, or neither */
2432 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2433 _mesa_is_enum_format_integer(format
)) {
2434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2435 "glTexSubImage%dD(integer/non-integer format mismatch)",
2446 * Test glCopyTexImage[12]D() parameters for errors.
2448 * \param ctx GL context.
2449 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2450 * \param target texture target given by the user.
2451 * \param level image level given by the user.
2452 * \param internalFormat internal format given by the user.
2453 * \param width image width given by the user.
2454 * \param height image height given by the user.
2455 * \param border texture border.
2457 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2459 * Verifies each of the parameters against the constants specified in
2460 * __struct gl_contextRec::Const and the supported extensions, and according
2461 * to the OpenGL specification.
2464 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2465 GLenum target
, GLint level
, GLint internalFormat
,
2466 GLint width
, GLint height
, GLint border
)
2469 GLint rb_base_format
;
2470 struct gl_renderbuffer
*rb
;
2471 GLenum rb_internal_format
;
2474 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2475 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2476 dimensions
, _mesa_lookup_enum_by_nr(target
));
2481 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2482 _mesa_error(ctx
, GL_INVALID_VALUE
,
2483 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2487 /* Check that the source buffer is complete */
2488 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2489 if (ctx
->ReadBuffer
->_Status
== 0) {
2490 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2492 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2493 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2494 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2498 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2499 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2500 "glCopyTexImage%dD(multisample FBO)",
2507 if (border
< 0 || border
> 1 ||
2508 ((ctx
->API
!= API_OPENGL_COMPAT
||
2509 target
== GL_TEXTURE_RECTANGLE_NV
||
2510 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2511 _mesa_error(ctx
, GL_INVALID_VALUE
,
2512 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2516 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2518 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2519 "glCopyTexImage%dD(read buffer)", dimensions
);
2523 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2526 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2527 switch (internalFormat
) {
2532 case GL_LUMINANCE_ALPHA
:
2535 _mesa_error(ctx
, GL_INVALID_VALUE
,
2536 "glCopyTexImage%dD(internalFormat)", dimensions
);
2541 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2542 if (baseFormat
< 0) {
2543 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2544 "glCopyTexImage%dD(internalFormat)", dimensions
);
2548 rb_internal_format
= rb
->InternalFormat
;
2549 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2550 if (_mesa_is_color_format(internalFormat
)) {
2551 if (rb_base_format
< 0) {
2552 _mesa_error(ctx
, GL_INVALID_VALUE
,
2553 "glCopyTexImage%dD(internalFormat)", dimensions
);
2558 if (_mesa_is_gles(ctx
)) {
2560 if (_mesa_base_format_component_count(baseFormat
) >
2561 _mesa_base_format_component_count(rb_base_format
)) {
2564 if (baseFormat
== GL_DEPTH_COMPONENT
||
2565 baseFormat
== GL_DEPTH_STENCIL
||
2566 rb_base_format
== GL_DEPTH_COMPONENT
||
2567 rb_base_format
== GL_DEPTH_STENCIL
||
2568 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2569 baseFormat
== GL_ALPHA
) &&
2570 rb_base_format
!= GL_RGBA
) ||
2571 internalFormat
== GL_RGB9_E5
) {
2574 if (internalFormat
== GL_RGB9_E5
) {
2578 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2579 "glCopyTexImage%dD(internalFormat)", dimensions
);
2584 if (_mesa_is_gles3(ctx
)) {
2585 bool rb_is_srgb
= false;
2586 bool dst_is_srgb
= false;
2588 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2589 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2593 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2597 if (rb_is_srgb
!= dst_is_srgb
) {
2598 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2599 * OpenGLES 3.0.0 spec says:
2601 * "The error INVALID_OPERATION is also generated if the
2602 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2603 * framebuffer attachment corresponding to the read buffer
2604 * is LINEAR (see section 6.1.13) and internalformat is
2605 * one of the sRGB formats described in section 3.8.16, or
2606 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2607 * SRGB and internalformat is not one of the sRGB formats."
2609 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2610 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2615 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2616 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2617 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2621 /* From the EXT_texture_integer spec:
2623 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2624 * if the texture internalformat is an integer format and the read color
2625 * buffer is not an integer format, or if the internalformat is not an
2626 * integer format and the read color buffer is an integer format."
2628 if (_mesa_is_color_format(internalFormat
)) {
2629 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2630 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2631 if (is_int
|| is_rbint
) {
2632 if (is_int
!= is_rbint
) {
2633 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2634 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2636 } else if (_mesa_is_gles(ctx
) &&
2637 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2638 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2639 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2640 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2646 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2647 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2648 _mesa_error(ctx
, GL_INVALID_ENUM
,
2649 "glCopyTexImage%dD(target)", dimensions
);
2652 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2653 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2654 "glCopyTexImage%dD(no compression for format)", dimensions
);
2658 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2659 "glCopyTexImage%dD(border!=0)", dimensions
);
2664 if (!mutable_tex_object(ctx
, target
)) {
2665 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2666 "glCopyTexImage%dD(immutable texture)", dimensions
);
2670 /* if we get here, the parameters are OK */
2676 * Test glCopyTexSubImage[12]D() parameters for errors.
2677 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2680 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2681 GLenum target
, GLint level
,
2682 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2683 GLint width
, GLint height
)
2685 struct gl_texture_object
*texObj
;
2686 struct gl_texture_image
*texImage
;
2688 /* Check that the source buffer is complete */
2689 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2690 if (ctx
->ReadBuffer
->_Status
== 0) {
2691 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2693 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2694 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2695 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2699 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2700 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2701 "glCopyTexSubImage%dD(multisample FBO)",
2707 /* check target (proxies not allowed) */
2708 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2709 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2710 dimensions
, _mesa_lookup_enum_by_nr(target
));
2715 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2716 _mesa_error(ctx
, GL_INVALID_VALUE
,
2717 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2721 /* Get dest texture object / image pointers */
2722 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2724 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2728 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2730 /* destination image does not exist */
2731 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2732 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2736 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2737 dimensions
, texImage
,
2738 xoffset
, yoffset
, zoffset
,
2739 width
, height
, 1)) {
2743 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2744 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2745 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2746 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2751 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2752 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2756 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2757 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2758 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2759 dimensions
, texImage
->_BaseFormat
);
2763 /* From the EXT_texture_integer spec:
2765 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2766 * if the texture internalformat is an integer format and the read color
2767 * buffer is not an integer format, or if the internalformat is not an
2768 * integer format and the read color buffer is an integer format."
2770 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2771 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2773 if (_mesa_is_format_integer_color(rb
->Format
) !=
2774 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2775 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2776 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2781 /* if we get here, the parameters are OK */
2786 /** Callback info for walking over FBO hash table */
2789 struct gl_context
*ctx
;
2790 struct gl_texture_object
*texObj
;
2796 * Check render to texture callback. Called from _mesa_HashWalk().
2799 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2801 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2802 const struct cb_info
*info
= (struct cb_info
*) userData
;
2803 struct gl_context
*ctx
= info
->ctx
;
2804 const struct gl_texture_object
*texObj
= info
->texObj
;
2805 const GLuint level
= info
->level
, face
= info
->face
;
2807 /* If this is a user-created FBO */
2808 if (_mesa_is_user_fbo(fb
)) {
2810 /* check if any of the FBO's attachments point to 'texObj' */
2811 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2812 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2813 if (att
->Type
== GL_TEXTURE
&&
2814 att
->Texture
== texObj
&&
2815 att
->TextureLevel
== level
&&
2816 att
->CubeMapFace
== face
) {
2817 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2818 ASSERT(att
->Renderbuffer
->TexImage
);
2819 /* Mark fb status as indeterminate to force re-validation */
2828 * When a texture image is specified we have to check if it's bound to
2829 * any framebuffer objects (render to texture) in order to detect changes
2830 * in size or format since that effects FBO completeness.
2831 * Any FBOs rendering into the texture must be re-validated.
2834 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2835 struct gl_texture_object
*texObj
,
2836 GLuint face
, GLuint level
)
2838 /* Only check this texture if it's been marked as RenderToTexture */
2839 if (texObj
->_RenderToTexture
) {
2840 struct cb_info info
;
2842 info
.texObj
= texObj
;
2845 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2851 * If the texture object's GenerateMipmap flag is set and we've
2852 * changed the texture base level image, regenerate the rest of the
2853 * mipmap levels now.
2856 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2857 struct gl_texture_object
*texObj
, GLint level
)
2859 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2860 if (texObj
->GenerateMipmap
&&
2861 level
== texObj
->BaseLevel
&&
2862 level
< texObj
->MaxLevel
) {
2863 ASSERT(ctx
->Driver
.GenerateMipmap
);
2864 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2869 /** Debug helper: override the user-requested internal format */
2871 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2874 if (internalFormat
== GL_RGBA16F_ARB
||
2875 internalFormat
== GL_RGBA32F_ARB
) {
2876 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2879 else if (internalFormat
== GL_RGB16F_ARB
||
2880 internalFormat
== GL_RGB32F_ARB
) {
2881 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2884 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2885 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2886 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2887 return GL_LUMINANCE_ALPHA
;
2889 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2890 internalFormat
== GL_LUMINANCE32F_ARB
) {
2891 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2892 return GL_LUMINANCE
;
2894 else if (internalFormat
== GL_ALPHA16F_ARB
||
2895 internalFormat
== GL_ALPHA32F_ARB
) {
2896 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2900 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2901 internalFormat = GL_RGBA;
2905 return internalFormat
;
2908 return internalFormat
;
2914 * Choose the actual hardware format for a texture image.
2915 * Try to use the same format as the previous image level when possible.
2916 * Otherwise, ask the driver for the best format.
2917 * It's important to try to choose a consistant format for all levels
2918 * for efficient texture memory layout/allocation. In particular, this
2919 * comes up during automatic mipmap generation.
2922 _mesa_choose_texture_format(struct gl_context
*ctx
,
2923 struct gl_texture_object
*texObj
,
2924 GLenum target
, GLint level
,
2925 GLenum internalFormat
, GLenum format
, GLenum type
)
2929 /* see if we've already chosen a format for the previous level */
2931 struct gl_texture_image
*prevImage
=
2932 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2933 /* See if the prev level is defined and has an internal format which
2934 * matches the new internal format.
2937 prevImage
->Width
> 0 &&
2938 prevImage
->InternalFormat
== internalFormat
) {
2939 /* use the same format */
2940 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2941 return prevImage
->TexFormat
;
2945 /* If the application requested compression to an S3TC format but we don't
2946 * have the DXTn library, force a generic compressed format instead.
2948 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2949 const GLenum before
= internalFormat
;
2951 switch (internalFormat
) {
2952 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2953 if (!ctx
->Mesa_DXTn
)
2954 internalFormat
= GL_COMPRESSED_RGB
;
2956 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2957 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2958 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2959 if (!ctx
->Mesa_DXTn
)
2960 internalFormat
= GL_COMPRESSED_RGBA
;
2966 if (before
!= internalFormat
) {
2968 "DXT compression requested (%s), "
2969 "but libtxc_dxtn library not installed. Using %s "
2971 _mesa_lookup_enum_by_nr(before
),
2972 _mesa_lookup_enum_by_nr(internalFormat
));
2976 /* choose format from scratch */
2977 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2979 ASSERT(f
!= MESA_FORMAT_NONE
);
2985 * Adjust pixel unpack params and image dimensions to strip off the
2986 * one-pixel texture border.
2988 * Gallium and intel don't support texture borders. They've seldem been used
2989 * and seldom been implemented correctly anyway.
2991 * \param unpackNew returns the new pixel unpack parameters
2994 strip_texture_border(GLenum target
,
2995 GLint
*width
, GLint
*height
, GLint
*depth
,
2996 const struct gl_pixelstore_attrib
*unpack
,
2997 struct gl_pixelstore_attrib
*unpackNew
)
3003 *unpackNew
= *unpack
;
3005 if (unpackNew
->RowLength
== 0)
3006 unpackNew
->RowLength
= *width
;
3008 if (unpackNew
->ImageHeight
== 0)
3009 unpackNew
->ImageHeight
= *height
;
3011 assert(*width
>= 3);
3012 unpackNew
->SkipPixels
++; /* skip the border */
3013 *width
= *width
- 2; /* reduce the width by two border pixels */
3015 /* The min height of a texture with a border is 3 */
3016 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3017 unpackNew
->SkipRows
++; /* skip the border */
3018 *height
= *height
- 2; /* reduce the height by two border pixels */
3022 target
!= GL_TEXTURE_2D_ARRAY
&&
3023 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3024 unpackNew
->SkipImages
++; /* skip the border */
3025 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3031 * Common code to implement all the glTexImage1D/2D/3D functions
3032 * as well as glCompressedTexImage1D/2D/3D.
3033 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3034 * \param format the user's image format (only used if !compressed)
3035 * \param type the user's image type (only used if !compressed)
3036 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3039 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3040 GLenum target
, GLint level
, GLint internalFormat
,
3041 GLsizei width
, GLsizei height
, GLsizei depth
,
3042 GLint border
, GLenum format
, GLenum type
,
3043 GLsizei imageSize
, const GLvoid
*pixels
)
3045 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3046 struct gl_pixelstore_attrib unpack_no_border
;
3047 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3048 struct gl_texture_object
*texObj
;
3049 gl_format texFormat
;
3050 GLboolean dimensionsOK
, sizeOK
;
3052 FLUSH_VERTICES(ctx
, 0);
3054 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3057 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3059 _mesa_lookup_enum_by_nr(target
), level
,
3060 _mesa_lookup_enum_by_nr(internalFormat
),
3061 width
, height
, depth
, border
, pixels
);
3064 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3066 _mesa_lookup_enum_by_nr(target
), level
,
3067 _mesa_lookup_enum_by_nr(internalFormat
),
3068 width
, height
, depth
, border
,
3069 _mesa_lookup_enum_by_nr(format
),
3070 _mesa_lookup_enum_by_nr(type
), pixels
);
3073 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3075 /* target error checking */
3076 if (!legal_teximage_target(ctx
, dims
, target
)) {
3077 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3078 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3082 /* general error checking */
3084 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3086 width
, height
, depth
,
3091 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3092 format
, type
, width
, height
, depth
, border
))
3096 /* Here we convert a cpal compressed image into a regular glTexImage2D
3097 * call by decompressing the texture. If we really want to support cpal
3098 * textures in any driver this would have to be changed.
3100 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3101 switch (internalFormat
) {
3102 case GL_PALETTE4_RGB8_OES
:
3103 case GL_PALETTE4_RGBA8_OES
:
3104 case GL_PALETTE4_R5_G6_B5_OES
:
3105 case GL_PALETTE4_RGBA4_OES
:
3106 case GL_PALETTE4_RGB5_A1_OES
:
3107 case GL_PALETTE8_RGB8_OES
:
3108 case GL_PALETTE8_RGBA8_OES
:
3109 case GL_PALETTE8_R5_G6_B5_OES
:
3110 case GL_PALETTE8_RGBA4_OES
:
3111 case GL_PALETTE8_RGB5_A1_OES
:
3112 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3113 width
, height
, imageSize
, pixels
);
3118 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3122 /* For glCompressedTexImage() the driver has no choice about the
3123 * texture format since we'll never transcode the user's compressed
3124 * image data. The internalFormat was error checked earlier.
3126 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3129 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3130 internalFormat
, format
, type
);
3133 assert(texFormat
!= MESA_FORMAT_NONE
);
3135 /* check that width, height, depth are legal for the mipmap level */
3136 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3137 height
, depth
, border
);
3139 /* check that the texture won't take too much memory, etc */
3140 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3142 width
, height
, depth
, border
);
3144 if (_mesa_is_proxy_texture(target
)) {
3145 /* Proxy texture: just clear or set state depending on error checking */
3146 struct gl_texture_image
*texImage
=
3147 get_proxy_tex_image(ctx
, target
, level
);
3150 return; /* GL_OUT_OF_MEMORY already recorded */
3152 if (dimensionsOK
&& sizeOK
) {
3153 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3154 border
, internalFormat
, texFormat
);
3157 clear_teximage_fields(texImage
);
3161 /* non-proxy target */
3162 const GLuint face
= _mesa_tex_target_to_face(target
);
3163 struct gl_texture_image
*texImage
;
3165 if (!dimensionsOK
) {
3166 _mesa_error(ctx
, GL_INVALID_VALUE
,
3167 "glTexImage%uD(invalid width or height or depth)",
3173 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3174 "glTexImage%uD(image too large)", dims
);
3178 /* Allow a hardware driver to just strip out the border, to provide
3179 * reliable but slightly incorrect hardware rendering instead of
3180 * rarely-tested software fallback rendering.
3182 if (border
&& ctx
->Const
.StripTextureBorder
) {
3183 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3186 unpack
= &unpack_no_border
;
3189 if (ctx
->NewState
& _NEW_PIXEL
)
3190 _mesa_update_state(ctx
);
3192 _mesa_lock_texture(ctx
, texObj
);
3194 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3197 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3200 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3202 _mesa_init_teximage_fields(ctx
, texImage
,
3203 width
, height
, depth
,
3204 border
, internalFormat
, texFormat
);
3206 /* Give the texture to the driver. <pixels> may be null. */
3207 if (width
> 0 && height
> 0 && depth
> 0) {
3209 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3213 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3214 type
, pixels
, unpack
);
3218 check_gen_mipmap(ctx
, target
, texObj
, level
);
3220 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3222 _mesa_dirty_texobj(ctx
, texObj
);
3225 _mesa_unlock_texture(ctx
, texObj
);
3232 * Called from the API. Note that width includes the border.
3235 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3236 GLsizei width
, GLint border
, GLenum format
,
3237 GLenum type
, const GLvoid
*pixels
)
3239 GET_CURRENT_CONTEXT(ctx
);
3240 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3241 border
, format
, type
, 0, pixels
);
3246 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3247 GLsizei width
, GLsizei height
, GLint border
,
3248 GLenum format
, GLenum type
,
3249 const GLvoid
*pixels
)
3251 GET_CURRENT_CONTEXT(ctx
);
3252 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3253 border
, format
, type
, 0, pixels
);
3258 * Called by the API or display list executor.
3259 * Note that width and height include the border.
3262 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3263 GLsizei width
, GLsizei height
, GLsizei depth
,
3264 GLint border
, GLenum format
, GLenum type
,
3265 const GLvoid
*pixels
)
3267 GET_CURRENT_CONTEXT(ctx
);
3268 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3269 width
, height
, depth
,
3270 border
, format
, type
, 0, pixels
);
3275 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3276 GLsizei width
, GLsizei height
, GLsizei depth
,
3277 GLint border
, GLenum format
, GLenum type
,
3278 const GLvoid
*pixels
)
3280 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3281 depth
, border
, format
, type
, pixels
);
3286 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3288 struct gl_texture_object
*texObj
;
3289 struct gl_texture_image
*texImage
;
3291 GET_CURRENT_CONTEXT(ctx
);
3292 FLUSH_VERTICES(ctx
, 0);
3296 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3298 case GL_TEXTURE_EXTERNAL_OES
:
3300 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3303 valid_target
= false;
3307 if (!valid_target
) {
3308 _mesa_error(ctx
, GL_INVALID_ENUM
,
3309 "glEGLImageTargetTexture2D(target=%d)", target
);
3314 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3315 "glEGLImageTargetTexture2D(image=%p)", image
);
3319 if (ctx
->NewState
& _NEW_PIXEL
)
3320 _mesa_update_state(ctx
);
3322 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3323 _mesa_lock_texture(ctx
, texObj
);
3325 if (texObj
->Immutable
) {
3326 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3327 "glEGLImageTargetTexture2D(texture is immutable)");
3328 _mesa_unlock_texture(ctx
, texObj
);
3332 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3334 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3336 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3338 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3339 texObj
, texImage
, image
);
3341 _mesa_dirty_texobj(ctx
, texObj
);
3343 _mesa_unlock_texture(ctx
, texObj
);
3350 * Implement all the glTexSubImage1/2/3D() functions.
3353 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3354 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3355 GLsizei width
, GLsizei height
, GLsizei depth
,
3356 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3358 struct gl_texture_object
*texObj
;
3359 struct gl_texture_image
*texImage
;
3361 FLUSH_VERTICES(ctx
, 0);
3363 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3364 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3366 _mesa_lookup_enum_by_nr(target
), level
,
3367 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3368 _mesa_lookup_enum_by_nr(format
),
3369 _mesa_lookup_enum_by_nr(type
), pixels
);
3371 /* check target (proxies not allowed) */
3372 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3373 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3374 dims
, _mesa_lookup_enum_by_nr(target
));
3378 if (ctx
->NewState
& _NEW_PIXEL
)
3379 _mesa_update_state(ctx
);
3381 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3382 xoffset
, yoffset
, zoffset
,
3383 width
, height
, depth
, format
, type
)) {
3384 return; /* error was detected */
3387 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3389 _mesa_lock_texture(ctx
, texObj
);
3391 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3393 if (width
> 0 && height
> 0 && depth
> 0) {
3394 /* If we have a border, offset=-1 is legal. Bias by border width. */
3397 if (target
!= GL_TEXTURE_2D_ARRAY
)
3398 zoffset
+= texImage
->Border
;
3401 if (target
!= GL_TEXTURE_1D_ARRAY
)
3402 yoffset
+= texImage
->Border
;
3405 xoffset
+= texImage
->Border
;
3408 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3409 xoffset
, yoffset
, zoffset
,
3410 width
, height
, depth
,
3411 format
, type
, pixels
, &ctx
->Unpack
);
3413 check_gen_mipmap(ctx
, target
, texObj
, level
);
3415 ctx
->NewState
|= _NEW_TEXTURE
;
3418 _mesa_unlock_texture(ctx
, texObj
);
3423 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3424 GLint xoffset
, GLsizei width
,
3425 GLenum format
, GLenum type
,
3426 const GLvoid
*pixels
)
3428 GET_CURRENT_CONTEXT(ctx
);
3429 texsubimage(ctx
, 1, target
, level
,
3432 format
, type
, pixels
);
3437 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3438 GLint xoffset
, GLint yoffset
,
3439 GLsizei width
, GLsizei height
,
3440 GLenum format
, GLenum type
,
3441 const GLvoid
*pixels
)
3443 GET_CURRENT_CONTEXT(ctx
);
3444 texsubimage(ctx
, 2, target
, level
,
3445 xoffset
, yoffset
, 0,
3447 format
, type
, pixels
);
3453 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3454 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3455 GLsizei width
, GLsizei height
, GLsizei depth
,
3456 GLenum format
, GLenum type
,
3457 const GLvoid
*pixels
)
3459 GET_CURRENT_CONTEXT(ctx
);
3460 texsubimage(ctx
, 3, target
, level
,
3461 xoffset
, yoffset
, zoffset
,
3462 width
, height
, depth
,
3463 format
, type
, pixels
);
3469 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3470 * from. This depends on whether the texture contains color or depth values.
3472 static struct gl_renderbuffer
*
3473 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3475 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3476 /* reading from depth/stencil buffer */
3477 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3480 /* copying from color buffer */
3481 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3486 copytexsubimage_by_slice(struct gl_context
*ctx
,
3487 struct gl_texture_image
*texImage
,
3489 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3490 struct gl_renderbuffer
*rb
,
3492 GLsizei width
, GLsizei height
)
3494 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3497 /* For 1D arrays, we copy each scanline of the source rectangle into the
3500 assert(zoffset
== 0);
3502 for (slice
= 0; slice
< height
; slice
++) {
3503 assert(yoffset
+ slice
< texImage
->Height
);
3504 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3505 xoffset
, 0, yoffset
+ slice
,
3506 rb
, x
, y
+ slice
, width
, 1);
3509 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3510 xoffset
, yoffset
, zoffset
,
3511 rb
, x
, y
, width
, height
);
3517 * Implement the glCopyTexImage1/2D() functions.
3520 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3521 GLenum target
, GLint level
, GLenum internalFormat
,
3522 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3524 struct gl_texture_object
*texObj
;
3525 struct gl_texture_image
*texImage
;
3526 const GLuint face
= _mesa_tex_target_to_face(target
);
3527 gl_format texFormat
;
3529 FLUSH_VERTICES(ctx
, 0);
3531 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3532 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3534 _mesa_lookup_enum_by_nr(target
), level
,
3535 _mesa_lookup_enum_by_nr(internalFormat
),
3536 x
, y
, width
, height
, border
);
3538 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3539 _mesa_update_state(ctx
);
3541 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3542 width
, height
, border
))
3545 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3547 _mesa_error(ctx
, GL_INVALID_VALUE
,
3548 "glCopyTexImage%uD(invalid width or height)", dims
);
3552 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3555 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3556 internalFormat
, GL_NONE
, GL_NONE
);
3557 assert(texFormat
!= MESA_FORMAT_NONE
);
3559 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3561 width
, height
, 1, border
)) {
3562 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3563 "glCopyTexImage%uD(image too large)", dims
);
3567 if (border
&& ctx
->Const
.StripTextureBorder
) {
3569 width
-= border
* 2;
3572 height
-= border
* 2;
3577 _mesa_lock_texture(ctx
, texObj
);
3579 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3582 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3585 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3587 /* Free old texture image */
3588 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3590 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3591 border
, internalFormat
, texFormat
);
3593 if (width
&& height
) {
3594 /* Allocate texture memory (no pixel data yet) */
3595 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3597 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3599 struct gl_renderbuffer
*srcRb
=
3600 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3602 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3604 srcRb
, srcX
, srcY
, width
, height
);
3607 check_gen_mipmap(ctx
, target
, texObj
, level
);
3610 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3612 _mesa_dirty_texobj(ctx
, texObj
);
3615 _mesa_unlock_texture(ctx
, texObj
);
3621 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3622 GLenum internalFormat
,
3624 GLsizei width
, GLint border
)
3626 GET_CURRENT_CONTEXT(ctx
);
3627 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3633 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3634 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3637 GET_CURRENT_CONTEXT(ctx
);
3638 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3639 x
, y
, width
, height
, border
);
3645 * Implementation for glCopyTexSubImage1/2/3D() functions.
3648 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3649 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3650 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3652 struct gl_texture_object
*texObj
;
3653 struct gl_texture_image
*texImage
;
3655 FLUSH_VERTICES(ctx
, 0);
3657 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3658 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3660 _mesa_lookup_enum_by_nr(target
),
3661 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3663 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3664 _mesa_update_state(ctx
);
3666 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3667 xoffset
, yoffset
, zoffset
, width
, height
)) {
3671 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3673 _mesa_lock_texture(ctx
, texObj
);
3675 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3677 /* If we have a border, offset=-1 is legal. Bias by border width. */
3680 if (target
!= GL_TEXTURE_2D_ARRAY
)
3681 zoffset
+= texImage
->Border
;
3684 if (target
!= GL_TEXTURE_1D_ARRAY
)
3685 yoffset
+= texImage
->Border
;
3688 xoffset
+= texImage
->Border
;
3691 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3693 struct gl_renderbuffer
*srcRb
=
3694 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3696 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3697 xoffset
, yoffset
, zoffset
,
3698 srcRb
, x
, y
, width
, height
);
3700 check_gen_mipmap(ctx
, target
, texObj
, level
);
3702 ctx
->NewState
|= _NEW_TEXTURE
;
3705 _mesa_unlock_texture(ctx
, texObj
);
3710 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3711 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3713 GET_CURRENT_CONTEXT(ctx
);
3714 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3720 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3721 GLint xoffset
, GLint yoffset
,
3722 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3724 GET_CURRENT_CONTEXT(ctx
);
3725 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3732 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3733 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3734 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3736 GET_CURRENT_CONTEXT(ctx
);
3737 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3738 x
, y
, width
, height
);
3744 /**********************************************************************/
3745 /****** Compressed Textures ******/
3746 /**********************************************************************/
3750 * Error checking for glCompressedTexSubImage[123]D().
3751 * \return error code or GL_NO_ERROR.
3754 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3755 GLenum target
, GLint level
,
3756 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3757 GLsizei width
, GLsizei height
, GLsizei depth
,
3758 GLenum format
, GLsizei imageSize
)
3760 struct gl_texture_object
*texObj
;
3761 struct gl_texture_image
*texImage
;
3769 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3770 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3771 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3772 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3773 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3774 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3778 targetOK
= GL_FALSE
;
3783 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3787 /* no 1D compressed textures at this time */
3788 targetOK
= GL_FALSE
;
3793 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3798 /* this will catch any invalid compressed format token */
3799 if (!_mesa_is_compressed_format(ctx
, format
)) {
3800 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3805 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3806 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3811 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3812 if (expectedSize
!= imageSize
) {
3813 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3818 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3820 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3821 "glCompressedTexSubImage%uD()", dims
);
3825 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3827 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3828 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3832 if ((GLint
) format
!= texImage
->InternalFormat
) {
3833 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3834 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3838 if (compressedteximage_only_format(ctx
, format
)) {
3839 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3840 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3845 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3846 texImage
, xoffset
, yoffset
, zoffset
,
3847 width
, height
, depth
)) {
3856 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3857 GLenum internalFormat
, GLsizei width
,
3858 GLint border
, GLsizei imageSize
,
3861 GET_CURRENT_CONTEXT(ctx
);
3862 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3863 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3868 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3869 GLenum internalFormat
, GLsizei width
,
3870 GLsizei height
, GLint border
, GLsizei imageSize
,
3873 GET_CURRENT_CONTEXT(ctx
);
3874 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3875 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3880 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3881 GLenum internalFormat
, GLsizei width
,
3882 GLsizei height
, GLsizei depth
, GLint border
,
3883 GLsizei imageSize
, const GLvoid
*data
)
3885 GET_CURRENT_CONTEXT(ctx
);
3886 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3887 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3892 * Common helper for glCompressedTexSubImage1/2/3D().
3895 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3896 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3897 GLsizei width
, GLsizei height
, GLsizei depth
,
3898 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3900 struct gl_texture_object
*texObj
;
3901 struct gl_texture_image
*texImage
;
3902 GET_CURRENT_CONTEXT(ctx
);
3903 FLUSH_VERTICES(ctx
, 0);
3905 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3906 xoffset
, yoffset
, zoffset
,
3907 width
, height
, depth
,
3908 format
, imageSize
)) {
3912 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3914 _mesa_lock_texture(ctx
, texObj
);
3916 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3919 if (width
> 0 && height
> 0 && depth
> 0) {
3920 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3921 xoffset
, yoffset
, zoffset
,
3922 width
, height
, depth
,
3923 format
, imageSize
, data
);
3925 check_gen_mipmap(ctx
, target
, texObj
, level
);
3927 ctx
->NewState
|= _NEW_TEXTURE
;
3930 _mesa_unlock_texture(ctx
, texObj
);
3935 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3936 GLsizei width
, GLenum format
,
3937 GLsizei imageSize
, const GLvoid
*data
)
3939 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3940 format
, imageSize
, data
);
3945 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3946 GLint yoffset
, GLsizei width
, GLsizei height
,
3947 GLenum format
, GLsizei imageSize
,
3950 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3951 width
, height
, 1, format
, imageSize
, data
);
3956 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3957 GLint yoffset
, GLint zoffset
, GLsizei width
,
3958 GLsizei height
, GLsizei depth
, GLenum format
,
3959 GLsizei imageSize
, const GLvoid
*data
)
3961 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3962 width
, height
, depth
, format
, imageSize
, data
);
3966 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3968 if (ctx
->API
!= API_OPENGL_CORE
) {
3969 switch (internalFormat
) {
3971 return MESA_FORMAT_A8
;
3973 return MESA_FORMAT_A16
;
3974 case GL_ALPHA16F_ARB
:
3975 return MESA_FORMAT_ALPHA_FLOAT16
;
3976 case GL_ALPHA32F_ARB
:
3977 return MESA_FORMAT_ALPHA_FLOAT32
;
3978 case GL_ALPHA8I_EXT
:
3979 return MESA_FORMAT_ALPHA_INT8
;
3980 case GL_ALPHA16I_EXT
:
3981 return MESA_FORMAT_ALPHA_INT16
;
3982 case GL_ALPHA32I_EXT
:
3983 return MESA_FORMAT_ALPHA_INT32
;
3984 case GL_ALPHA8UI_EXT
:
3985 return MESA_FORMAT_ALPHA_UINT8
;
3986 case GL_ALPHA16UI_EXT
:
3987 return MESA_FORMAT_ALPHA_UINT16
;
3988 case GL_ALPHA32UI_EXT
:
3989 return MESA_FORMAT_ALPHA_UINT32
;
3991 return MESA_FORMAT_L8
;
3992 case GL_LUMINANCE16
:
3993 return MESA_FORMAT_L16
;
3994 case GL_LUMINANCE16F_ARB
:
3995 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3996 case GL_LUMINANCE32F_ARB
:
3997 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3998 case GL_LUMINANCE8I_EXT
:
3999 return MESA_FORMAT_LUMINANCE_INT8
;
4000 case GL_LUMINANCE16I_EXT
:
4001 return MESA_FORMAT_LUMINANCE_INT16
;
4002 case GL_LUMINANCE32I_EXT
:
4003 return MESA_FORMAT_LUMINANCE_INT32
;
4004 case GL_LUMINANCE8UI_EXT
:
4005 return MESA_FORMAT_LUMINANCE_UINT8
;
4006 case GL_LUMINANCE16UI_EXT
:
4007 return MESA_FORMAT_LUMINANCE_UINT16
;
4008 case GL_LUMINANCE32UI_EXT
:
4009 return MESA_FORMAT_LUMINANCE_UINT32
;
4010 case GL_LUMINANCE8_ALPHA8
:
4011 return MESA_FORMAT_AL88
;
4012 case GL_LUMINANCE16_ALPHA16
:
4013 return MESA_FORMAT_AL1616
;
4014 case GL_LUMINANCE_ALPHA16F_ARB
:
4015 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
4016 case GL_LUMINANCE_ALPHA32F_ARB
:
4017 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
4018 case GL_LUMINANCE_ALPHA8I_EXT
:
4019 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
4020 case GL_LUMINANCE_ALPHA16I_EXT
:
4021 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
4022 case GL_LUMINANCE_ALPHA32I_EXT
:
4023 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
4024 case GL_LUMINANCE_ALPHA8UI_EXT
:
4025 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
4026 case GL_LUMINANCE_ALPHA16UI_EXT
:
4027 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
4028 case GL_LUMINANCE_ALPHA32UI_EXT
:
4029 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
4031 return MESA_FORMAT_I8
;
4032 case GL_INTENSITY16
:
4033 return MESA_FORMAT_I16
;
4034 case GL_INTENSITY16F_ARB
:
4035 return MESA_FORMAT_INTENSITY_FLOAT16
;
4036 case GL_INTENSITY32F_ARB
:
4037 return MESA_FORMAT_INTENSITY_FLOAT32
;
4038 case GL_INTENSITY8I_EXT
:
4039 return MESA_FORMAT_INTENSITY_INT8
;
4040 case GL_INTENSITY16I_EXT
:
4041 return MESA_FORMAT_INTENSITY_INT16
;
4042 case GL_INTENSITY32I_EXT
:
4043 return MESA_FORMAT_INTENSITY_INT32
;
4044 case GL_INTENSITY8UI_EXT
:
4045 return MESA_FORMAT_INTENSITY_UINT8
;
4046 case GL_INTENSITY16UI_EXT
:
4047 return MESA_FORMAT_INTENSITY_UINT16
;
4048 case GL_INTENSITY32UI_EXT
:
4049 return MESA_FORMAT_INTENSITY_UINT32
;
4055 if (ctx
->API
== API_OPENGL_CORE
&&
4056 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4057 switch (internalFormat
) {
4059 return MESA_FORMAT_RGB_FLOAT32
;
4061 return MESA_FORMAT_RGB_UINT32
;
4063 return MESA_FORMAT_RGB_INT32
;
4069 switch (internalFormat
) {
4071 return MESA_FORMAT_RGBA8888_REV
;
4073 return MESA_FORMAT_RGBA_16
;
4074 case GL_RGBA16F_ARB
:
4075 return MESA_FORMAT_RGBA_FLOAT16
;
4076 case GL_RGBA32F_ARB
:
4077 return MESA_FORMAT_RGBA_FLOAT32
;
4079 return MESA_FORMAT_RGBA_INT8
;
4080 case GL_RGBA16I_EXT
:
4081 return MESA_FORMAT_RGBA_INT16
;
4082 case GL_RGBA32I_EXT
:
4083 return MESA_FORMAT_RGBA_INT32
;
4084 case GL_RGBA8UI_EXT
:
4085 return MESA_FORMAT_RGBA_UINT8
;
4086 case GL_RGBA16UI_EXT
:
4087 return MESA_FORMAT_RGBA_UINT16
;
4088 case GL_RGBA32UI_EXT
:
4089 return MESA_FORMAT_RGBA_UINT32
;
4092 return MESA_FORMAT_GR88
;
4094 return MESA_FORMAT_GR1616
;
4096 return MESA_FORMAT_RG_FLOAT16
;
4098 return MESA_FORMAT_RG_FLOAT32
;
4100 return MESA_FORMAT_RG_INT8
;
4102 return MESA_FORMAT_RG_INT16
;
4104 return MESA_FORMAT_RG_INT32
;
4106 return MESA_FORMAT_RG_UINT8
;
4108 return MESA_FORMAT_RG_UINT16
;
4110 return MESA_FORMAT_RG_UINT32
;
4113 return MESA_FORMAT_R8
;
4115 return MESA_FORMAT_R16
;
4117 return MESA_FORMAT_R_FLOAT16
;
4119 return MESA_FORMAT_R_FLOAT32
;
4121 return MESA_FORMAT_R_INT8
;
4123 return MESA_FORMAT_R_INT16
;
4125 return MESA_FORMAT_R_INT32
;
4127 return MESA_FORMAT_R_UINT8
;
4129 return MESA_FORMAT_R_UINT16
;
4131 return MESA_FORMAT_R_UINT32
;
4134 return MESA_FORMAT_NONE
;
4140 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4141 GLenum internalFormat
)
4143 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4146 if (format
== MESA_FORMAT_NONE
)
4147 return MESA_FORMAT_NONE
;
4149 datatype
= _mesa_get_format_datatype(format
);
4150 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4151 return MESA_FORMAT_NONE
;
4153 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4154 return MESA_FORMAT_NONE
;
4156 if (!ctx
->Extensions
.ARB_texture_rg
) {
4157 GLenum base_format
= _mesa_get_format_base_format(format
);
4158 if (base_format
== GL_R
|| base_format
== GL_RG
)
4159 return MESA_FORMAT_NONE
;
4162 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4163 GLenum base_format
= _mesa_get_format_base_format(format
);
4164 if (base_format
== GL_RGB
)
4165 return MESA_FORMAT_NONE
;
4172 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4173 struct gl_buffer_object
*bufObj
,
4174 GLintptr offset
, GLsizeiptr size
)
4176 struct gl_texture_object
*texObj
;
4179 FLUSH_VERTICES(ctx
, 0);
4181 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4182 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4186 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
4187 if (format
== MESA_FORMAT_NONE
) {
4188 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4193 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4195 _mesa_lock_texture(ctx
, texObj
);
4197 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4198 texObj
->BufferObjectFormat
= internalFormat
;
4199 texObj
->_BufferObjectFormat
= format
;
4200 texObj
->BufferOffset
= offset
;
4201 texObj
->BufferSize
= size
;
4203 _mesa_unlock_texture(ctx
, texObj
);
4207 /** GL_ARB_texture_buffer_object */
4209 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4211 struct gl_buffer_object
*bufObj
;
4213 GET_CURRENT_CONTEXT(ctx
);
4215 /* NOTE: ARB_texture_buffer_object has interactions with
4216 * the compatibility profile that are not implemented.
4218 if (!(ctx
->API
== API_OPENGL_CORE
&&
4219 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4220 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4224 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4225 if (!bufObj
&& buffer
) {
4226 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4230 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4234 /** GL_ARB_texture_buffer_range */
4236 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4237 GLintptr offset
, GLsizeiptr size
)
4239 struct gl_buffer_object
*bufObj
;
4241 GET_CURRENT_CONTEXT(ctx
);
4243 if (!(ctx
->API
== API_OPENGL_CORE
&&
4244 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4245 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4249 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4253 (offset
+ size
) > bufObj
->Size
) {
4254 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4257 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4258 _mesa_error(ctx
, GL_INVALID_VALUE
,
4259 "glTexBufferRange(invalid offset alignment)");
4262 } else if (buffer
) {
4263 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4271 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4276 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4278 /* Everything that is allowed for renderbuffers,
4279 * except for a base format of GL_STENCIL_INDEX.
4281 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4282 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4286 /** GL_ARB_texture_multisample */
4288 check_multisample_target(GLuint dims
, GLenum target
)
4291 case GL_TEXTURE_2D_MULTISAMPLE
:
4292 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4295 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4296 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4306 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4307 GLint internalformat
, GLsizei width
, GLsizei height
,
4308 GLsizei depth
, GLboolean fixedsamplelocations
,
4309 GLboolean immutable
, const char *func
)
4311 struct gl_texture_object
*texObj
;
4312 struct gl_texture_image
*texImage
;
4313 GLboolean sizeOK
, dimensionsOK
;
4314 gl_format texFormat
;
4315 GLenum sample_count_error
;
4317 GET_CURRENT_CONTEXT(ctx
);
4319 if (!(ctx
->Extensions
.ARB_texture_multisample
4320 && _mesa_is_desktop_gl(ctx
))) {
4321 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4325 if (!check_multisample_target(dims
, target
)) {
4326 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4330 /* check that the specified internalformat is color/depth/stencil-renderable;
4331 * refer GL3.1 spec 4.4.4
4334 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4335 _mesa_error(ctx
, GL_INVALID_ENUM
,
4336 "%s(internalformat=%s not legal for immutable-format)",
4337 func
, _mesa_lookup_enum_by_nr(internalformat
));
4341 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4342 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4343 "%s(internalformat=%s)",
4344 func
, _mesa_lookup_enum_by_nr(internalformat
));
4348 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4349 internalformat
, samples
);
4350 if (sample_count_error
!= GL_NO_ERROR
) {
4351 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4355 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4357 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4358 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4359 "%s(texture object 0)",
4364 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4366 if (texImage
== NULL
) {
4367 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4371 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4372 internalformat
, GL_NONE
, GL_NONE
);
4373 assert(texFormat
!= MESA_FORMAT_NONE
);
4375 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4376 width
, height
, depth
, 0);
4378 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4379 width
, height
, depth
, 0);
4381 if (_mesa_is_proxy_texture(target
)) {
4382 if (dimensionsOK
&& sizeOK
) {
4383 _mesa_init_teximage_fields(ctx
, texImage
,
4384 width
, height
, depth
, 0, internalformat
, texFormat
);
4385 texImage
->NumSamples
= samples
;
4386 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4389 /* clear all image fields */
4390 _mesa_init_teximage_fields(ctx
, texImage
,
4391 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4395 if (!dimensionsOK
) {
4396 _mesa_error(ctx
, GL_INVALID_VALUE
,
4397 "%s(invalid width or height)", func
);
4402 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4403 "%s(texture too large)", func
);
4407 /* Check if texObj->Immutable is set */
4408 if (texObj
->Immutable
) {
4409 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4413 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4415 _mesa_init_teximage_fields(ctx
, texImage
,
4416 width
, height
, depth
, 0, internalformat
, texFormat
);
4418 texImage
->NumSamples
= samples
;
4419 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4421 if (width
> 0 && height
> 0 && depth
> 0) {
4422 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4423 width
, height
, depth
)) {
4424 /* tidy up the texture image state. strictly speaking,
4425 * we're allowed to just leave this in whatever state we
4426 * like, but being tidy is good.
4428 _mesa_init_teximage_fields(ctx
, texImage
,
4429 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4433 texObj
->Immutable
= immutable
;
4436 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
4439 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4445 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4446 GLenum internalformat
, GLsizei width
,
4447 GLsizei height
, GLboolean fixedsamplelocations
)
4449 teximagemultisample(2, target
, samples
, internalformat
,
4450 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4451 "glTexImage2DMultisample");
4456 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4457 GLenum internalformat
, GLsizei width
,
4458 GLsizei height
, GLsizei depth
,
4459 GLboolean fixedsamplelocations
)
4461 teximagemultisample(3, target
, samples
, internalformat
,
4462 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4463 "glTexImage3DMultisample");
4468 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4469 GLenum internalformat
, GLsizei width
,
4470 GLsizei height
, GLboolean fixedsamplelocations
)
4472 teximagemultisample(2, target
, samples
, internalformat
,
4473 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4474 "glTexStorage2DMultisample");
4479 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4480 GLenum internalformat
, GLsizei width
,
4481 GLsizei height
, GLsizei depth
,
4482 GLboolean fixedsamplelocations
)
4484 teximagemultisample(3, target
, samples
, internalformat
,
4485 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4486 "glTexStorage3DMultisample");