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 * Return the maximum number of mipmap levels for the given target
1092 * and the dimensions.
1093 * The dimensions are expected not to include the border.
1096 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1103 case GL_TEXTURE_1D_ARRAY
:
1104 case GL_PROXY_TEXTURE_1D
:
1105 case GL_PROXY_TEXTURE_1D_ARRAY
:
1108 case GL_TEXTURE_CUBE_MAP
:
1109 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1110 case GL_PROXY_TEXTURE_CUBE_MAP
:
1111 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1115 case GL_TEXTURE_2D_ARRAY
:
1116 case GL_PROXY_TEXTURE_2D
:
1117 case GL_PROXY_TEXTURE_2D_ARRAY
:
1118 size
= MAX2(width
, height
);
1121 case GL_PROXY_TEXTURE_3D
:
1122 size
= MAX3(width
, height
, depth
);
1124 case GL_TEXTURE_RECTANGLE
:
1125 case GL_TEXTURE_EXTERNAL_OES
:
1126 case GL_TEXTURE_2D_MULTISAMPLE
:
1127 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1128 case GL_PROXY_TEXTURE_RECTANGLE
:
1129 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1130 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1137 return _mesa_logbase2(size
) + 1;
1141 #if 000 /* not used anymore */
1143 * glTexImage[123]D can accept a NULL image pointer. In this case we
1144 * create a texture image with unspecified image contents per the OpenGL
1148 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1150 const GLint components
= _mesa_components_in_format(format
);
1151 const GLint numPixels
= width
* height
* depth
;
1152 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1156 * Let's see if anyone finds this. If glTexImage2D() is called with
1157 * a NULL image pointer then load the texture image with something
1158 * interesting instead of leaving it indeterminate.
1161 static const char message
[8][32] = {
1162 " X X XXXXX XXX X ",
1163 " XX XX X X X X X ",
1165 " X X XXXX XXX XXXXX ",
1168 " X X XXXXX XXX X X ",
1172 GLubyte
*imgPtr
= data
;
1174 for (h
= 0; h
< depth
; h
++) {
1175 for (i
= 0; i
< height
; i
++) {
1176 GLint srcRow
= 7 - (i
% 8);
1177 for (j
= 0; j
< width
; j
++) {
1178 GLint srcCol
= j
% 32;
1179 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1180 for (k
= 0; k
< components
; k
++) {
1196 * Set the size and format-related fields of a gl_texture_image struct
1197 * to zero. This is used when a proxy texture test fails.
1200 clear_teximage_fields(struct gl_texture_image
*img
)
1203 img
->_BaseFormat
= 0;
1204 img
->InternalFormat
= 0;
1213 img
->HeightLog2
= 0;
1215 img
->TexFormat
= MESA_FORMAT_NONE
;
1216 img
->NumSamples
= 0;
1217 img
->FixedSampleLocations
= GL_TRUE
;
1222 * Initialize basic fields of the gl_texture_image struct.
1224 * \param ctx GL context.
1225 * \param img texture image structure to be initialized.
1226 * \param width image width.
1227 * \param height image height.
1228 * \param depth image depth.
1229 * \param border image border.
1230 * \param internalFormat internal format.
1231 * \param format the actual hardware format (one of MESA_FORMAT_*)
1233 * Fills in the fields of \p img with the given information.
1234 * Note: width, height and depth include the border.
1237 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1238 struct gl_texture_image
*img
,
1239 GLsizei width
, GLsizei height
, GLsizei depth
,
1240 GLint border
, GLenum internalFormat
,
1246 ASSERT(height
>= 0);
1249 target
= img
->TexObject
->Target
;
1250 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1251 ASSERT(img
->_BaseFormat
> 0);
1252 img
->InternalFormat
= internalFormat
;
1253 img
->Border
= border
;
1255 img
->Height
= height
;
1258 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1259 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1261 img
->NumSamples
= 0;
1262 img
->FixedSampleLocations
= GL_TRUE
;
1266 case GL_TEXTURE_BUFFER
:
1267 case GL_PROXY_TEXTURE_1D
:
1272 img
->HeightLog2
= 0;
1279 case GL_TEXTURE_1D_ARRAY
:
1280 case GL_PROXY_TEXTURE_1D_ARRAY
:
1281 img
->Height2
= height
; /* no border */
1282 img
->HeightLog2
= 0; /* not used */
1290 case GL_TEXTURE_RECTANGLE
:
1291 case GL_TEXTURE_CUBE_MAP
:
1292 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1293 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1294 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1295 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1296 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1297 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1298 case GL_TEXTURE_EXTERNAL_OES
:
1299 case GL_PROXY_TEXTURE_2D
:
1300 case GL_PROXY_TEXTURE_RECTANGLE
:
1301 case GL_PROXY_TEXTURE_CUBE_MAP
:
1302 case GL_TEXTURE_2D_MULTISAMPLE
:
1303 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1304 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1305 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1312 case GL_TEXTURE_2D_ARRAY
:
1313 case GL_PROXY_TEXTURE_2D_ARRAY
:
1314 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1315 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1316 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1317 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1318 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1319 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1320 img
->Depth2
= depth
; /* no border */
1321 img
->DepthLog2
= 0; /* not used */
1324 case GL_PROXY_TEXTURE_3D
:
1325 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1326 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1327 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1328 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1331 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1336 _mesa_get_tex_max_num_levels(target
,
1337 img
->Width2
, img
->Height2
, img
->Depth2
);
1338 img
->TexFormat
= format
;
1343 * Free and clear fields of the gl_texture_image struct.
1345 * \param ctx GL context.
1346 * \param texImage texture image structure to be cleared.
1348 * After the call, \p texImage will have no data associated with it. Its
1349 * fields are cleared so that its parent object will test incomplete.
1352 _mesa_clear_texture_image(struct gl_context
*ctx
,
1353 struct gl_texture_image
*texImage
)
1355 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1356 clear_teximage_fields(texImage
);
1361 * Check the width, height, depth and border of a texture image are legal.
1362 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1364 * The target and level parameters will have already been validated.
1365 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1368 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1369 GLint level
, GLint width
, GLint height
,
1370 GLint depth
, GLint border
)
1376 case GL_PROXY_TEXTURE_1D
:
1377 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1378 maxSize
>>= level
; /* level size */
1379 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1381 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1382 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1388 case GL_PROXY_TEXTURE_2D
:
1389 case GL_TEXTURE_2D_MULTISAMPLE
:
1390 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1391 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1393 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1395 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1397 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1398 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1400 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1406 case GL_PROXY_TEXTURE_3D
:
1407 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1409 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1411 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1413 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1415 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1416 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1418 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1420 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1425 case GL_TEXTURE_RECTANGLE_NV
:
1426 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1429 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1430 if (width
< 0 || width
> maxSize
)
1432 if (height
< 0 || height
> maxSize
)
1436 case GL_TEXTURE_CUBE_MAP
:
1437 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1438 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1439 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1440 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1441 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1442 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1443 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1444 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1446 if (width
!= height
)
1448 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1450 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1452 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1453 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1455 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1460 case GL_TEXTURE_1D_ARRAY_EXT
:
1461 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1462 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1464 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1466 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1468 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1469 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1474 case GL_TEXTURE_2D_ARRAY_EXT
:
1475 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1476 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1477 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
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 (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1486 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1487 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1489 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1494 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1495 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1496 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1497 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1499 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1501 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1503 if (width
!= height
)
1505 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1507 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1508 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1510 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1515 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1522 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1523 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1524 * \param destImage the destination texture image.
1525 * \return GL_TRUE if error found, GL_FALSE otherwise.
1528 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1529 const char *function
, GLuint dims
,
1530 const struct gl_texture_image
*destImage
,
1531 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1532 GLsizei subWidth
, GLsizei subHeight
,
1535 const GLenum target
= destImage
->TexObject
->Target
;
1540 _mesa_error(ctx
, GL_INVALID_VALUE
,
1541 "%s%dD(width=%d)", function
, dims
, subWidth
);
1545 if (dims
> 1 && subHeight
< 0) {
1546 _mesa_error(ctx
, GL_INVALID_VALUE
,
1547 "%s%dD(height=%d)", function
, dims
, subHeight
);
1551 if (dims
> 2 && subDepth
< 0) {
1552 _mesa_error(ctx
, GL_INVALID_VALUE
,
1553 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1557 /* check xoffset and width */
1558 if (xoffset
< - (GLint
) destImage
->Border
) {
1559 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1564 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1565 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1570 /* check yoffset and height */
1572 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1573 if (yoffset
< -yBorder
) {
1574 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1578 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1579 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1585 /* check zoffset and depth */
1587 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1588 if (zoffset
< -zBorder
) {
1589 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1592 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1593 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1599 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1600 * compressed texture images can be updated. But, that restriction may be
1601 * relaxed for particular compressed formats. At this time, all the
1602 * compressed formats supported by Mesa allow sub-textures to be updated
1603 * along compressed block boundaries.
1605 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1607 if (bw
!= 1 || bh
!= 1) {
1608 /* offset must be multiple of block size */
1609 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1610 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1611 "%s%dD(xoffset = %d, yoffset = %d)",
1612 function
, dims
, xoffset
, yoffset
);
1616 /* The size must be a multiple of bw x bh, or we must be using a
1617 * offset+size that exactly hits the edge of the image. This
1618 * is important for small mipmap levels (1x1, 2x1, etc) and for
1621 if ((subWidth
% bw
!= 0) &&
1622 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1623 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1624 "%s%dD(width = %d)", function
, dims
, subWidth
);
1628 if ((subHeight
% bh
!= 0) &&
1629 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1630 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1631 "%s%dD(height = %d)", function
, dims
, subHeight
);
1643 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1644 * specific texture image size checks.
1646 * A hardware driver might override this function if, for example, the
1647 * max 3D texture size is 512x512x64 (i.e. not a cube).
1649 * Note that width, height, depth == 0 is not an error. However, a
1650 * texture with zero width/height/depth will be considered "incomplete"
1651 * and texturing will effectively be disabled.
1653 * \param target any texture target/type
1654 * \param level as passed to glTexImage
1655 * \param format the MESA_FORMAT_x for the tex image
1656 * \param width as passed to glTexImage
1657 * \param height as passed to glTexImage
1658 * \param depth as passed to glTexImage
1659 * \param border as passed to glTexImage
1660 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1663 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1665 GLint width
, GLint height
, GLint depth
, GLint border
)
1667 /* We just check if the image size is less than MaxTextureMbytes.
1668 * Some drivers may do more specific checks.
1670 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1671 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1672 mbytes
*= _mesa_num_tex_faces(target
);
1673 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1678 * Return true if the format is only valid for glCompressedTexImage.
1681 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1684 case GL_ETC1_RGB8_OES
:
1685 case GL_PALETTE4_RGB8_OES
:
1686 case GL_PALETTE4_RGBA8_OES
:
1687 case GL_PALETTE4_R5_G6_B5_OES
:
1688 case GL_PALETTE4_RGBA4_OES
:
1689 case GL_PALETTE4_RGB5_A1_OES
:
1690 case GL_PALETTE8_RGB8_OES
:
1691 case GL_PALETTE8_RGBA8_OES
:
1692 case GL_PALETTE8_R5_G6_B5_OES
:
1693 case GL_PALETTE8_RGBA4_OES
:
1694 case GL_PALETTE8_RGB5_A1_OES
:
1703 * Helper function to determine whether a target and specific compression
1704 * format are supported.
1707 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1710 (void) intFormat
; /* not used yet */
1714 case GL_PROXY_TEXTURE_2D
:
1715 return GL_TRUE
; /* true for any compressed format so far */
1716 case GL_PROXY_TEXTURE_CUBE_MAP
:
1717 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1718 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1719 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1720 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1721 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1722 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1723 return ctx
->Extensions
.ARB_texture_cube_map
;
1724 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1725 case GL_TEXTURE_2D_ARRAY_EXT
:
1726 return ctx
->Extensions
.EXT_texture_array
;
1727 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1728 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1729 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1737 * Check if the given texture target value is legal for a
1738 * glTexImage1/2/3D call.
1741 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1747 case GL_PROXY_TEXTURE_1D
:
1748 return _mesa_is_desktop_gl(ctx
);
1756 case GL_PROXY_TEXTURE_2D
:
1757 return _mesa_is_desktop_gl(ctx
);
1758 case GL_PROXY_TEXTURE_CUBE_MAP
:
1759 return _mesa_is_desktop_gl(ctx
)
1760 && ctx
->Extensions
.ARB_texture_cube_map
;
1761 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1762 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1763 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1764 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1765 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1766 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1767 return ctx
->Extensions
.ARB_texture_cube_map
;
1768 case GL_TEXTURE_RECTANGLE_NV
:
1769 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1770 return _mesa_is_desktop_gl(ctx
)
1771 && ctx
->Extensions
.NV_texture_rectangle
;
1772 case GL_TEXTURE_1D_ARRAY_EXT
:
1773 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1774 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1782 case GL_PROXY_TEXTURE_3D
:
1783 return _mesa_is_desktop_gl(ctx
);
1784 case GL_TEXTURE_2D_ARRAY_EXT
:
1785 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1786 || _mesa_is_gles3(ctx
);
1787 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1788 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1789 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1790 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1791 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1796 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1803 * Check if the given texture target value is legal for a
1804 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1805 * The difference compared to legal_teximage_target() above is that
1806 * proxy targets are not supported.
1809 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1813 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1818 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1819 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1820 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1821 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1822 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1823 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1824 return ctx
->Extensions
.ARB_texture_cube_map
;
1825 case GL_TEXTURE_RECTANGLE_NV
:
1826 return _mesa_is_desktop_gl(ctx
)
1827 && ctx
->Extensions
.NV_texture_rectangle
;
1828 case GL_TEXTURE_1D_ARRAY_EXT
:
1829 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1837 case GL_TEXTURE_2D_ARRAY_EXT
:
1838 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1839 || _mesa_is_gles3(ctx
);
1840 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1841 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1842 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1847 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1855 * Helper function to determine if a texture object is mutable (in terms
1856 * of GL_ARB_texture_storage).
1859 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1861 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1862 return !texObj
->Immutable
;
1867 * Return expected size of a compressed texture.
1870 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1873 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1874 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1879 * Test the glTexImage[123]D() parameters for errors.
1881 * \param ctx GL context.
1882 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1883 * \param target texture target given by the user (already validated).
1884 * \param level image level given by the user.
1885 * \param internalFormat internal format given by the user.
1886 * \param format pixel data format given by the user.
1887 * \param type pixel data type given by the user.
1888 * \param width image width given by the user.
1889 * \param height image height given by the user.
1890 * \param depth image depth given by the user.
1891 * \param border image border given by the user.
1893 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1895 * Verifies each of the parameters against the constants specified in
1896 * __struct gl_contextRec::Const and the supported extensions, and according
1897 * to the OpenGL specification.
1898 * Note that we don't fully error-check the width, height, depth values
1899 * here. That's done in _mesa_legal_texture_dimensions() which is used
1900 * by several other GL entrypoints. Plus, texture dims have a special
1901 * interaction with proxy textures.
1904 texture_error_check( struct gl_context
*ctx
,
1905 GLuint dimensions
, GLenum target
,
1906 GLint level
, GLint internalFormat
,
1907 GLenum format
, GLenum type
,
1908 GLint width
, GLint height
,
1909 GLint depth
, GLint border
)
1911 GLboolean colorFormat
;
1914 /* Even though there are no color-index textures, we still have to support
1915 * uploading color-index data and remapping it to RGB via the
1916 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1918 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1920 /* Note: for proxy textures, some error conditions immediately generate
1921 * a GL error in the usual way. But others do not generate a GL error.
1922 * Instead, they cause the width, height, depth, format fields of the
1923 * texture image to be zeroed-out. The GL spec seems to indicate that the
1924 * zero-out behaviour is only used in cases related to memory allocation.
1928 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1929 _mesa_error(ctx
, GL_INVALID_VALUE
,
1930 "glTexImage%dD(level=%d)", dimensions
, level
);
1935 if (border
< 0 || border
> 1 ||
1936 ((ctx
->API
!= API_OPENGL_COMPAT
||
1937 target
== GL_TEXTURE_RECTANGLE_NV
||
1938 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1939 _mesa_error(ctx
, GL_INVALID_VALUE
,
1940 "glTexImage%dD(border=%d)", dimensions
, border
);
1944 if (width
< 0 || height
< 0 || depth
< 0) {
1945 _mesa_error(ctx
, GL_INVALID_VALUE
,
1946 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1950 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1951 * combinations of format, internalFormat, and type that can be used.
1952 * Formats and types that require additional extensions (e.g., GL_FLOAT
1953 * requires GL_OES_texture_float) are filtered elsewhere.
1956 if (_mesa_is_gles(ctx
)) {
1957 if (_mesa_is_gles3(ctx
)) {
1958 err
= _mesa_es3_error_check_format_and_type(format
, type
,
1961 if (format
!= internalFormat
) {
1962 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1963 "glTexImage%dD(format = %s, internalFormat = %s)",
1965 _mesa_lookup_enum_by_nr(format
),
1966 _mesa_lookup_enum_by_nr(internalFormat
));
1970 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1972 if (err
!= GL_NO_ERROR
) {
1973 _mesa_error(ctx
, err
,
1974 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
1976 _mesa_lookup_enum_by_nr(format
),
1977 _mesa_lookup_enum_by_nr(type
),
1978 _mesa_lookup_enum_by_nr(internalFormat
));
1983 /* Check internalFormat */
1984 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1985 _mesa_error(ctx
, GL_INVALID_VALUE
,
1986 "glTexImage%dD(internalFormat=%s)",
1987 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1991 /* Check incoming image format and type */
1992 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1993 if (err
!= GL_NO_ERROR
) {
1994 _mesa_error(ctx
, err
,
1995 "glTexImage%dD(incompatible format = %s, type = %s)",
1996 dimensions
, _mesa_lookup_enum_by_nr(format
),
1997 _mesa_lookup_enum_by_nr(type
));
2001 /* make sure internal format and format basically agree */
2002 colorFormat
= _mesa_is_color_format(format
);
2003 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2004 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2005 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2006 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2007 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2008 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2009 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2010 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2011 _mesa_lookup_enum_by_nr(format
));
2015 /* additional checks for ycbcr textures */
2016 if (internalFormat
== GL_YCBCR_MESA
) {
2017 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2018 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2019 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2021 _mesa_snprintf(message
, sizeof(message
),
2022 "glTexImage%dD(format/type YCBCR mismatch)",
2024 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2025 return GL_TRUE
; /* error */
2027 if (target
!= GL_TEXTURE_2D
&&
2028 target
!= GL_PROXY_TEXTURE_2D
&&
2029 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2030 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2031 _mesa_error(ctx
, GL_INVALID_ENUM
,
2032 "glTexImage%dD(bad target for YCbCr texture)",
2038 _mesa_snprintf(message
, sizeof(message
),
2039 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2040 dimensions
, border
);
2041 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2046 /* additional checks for depth textures */
2047 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2048 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2049 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
2050 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
2051 if (target
!= GL_TEXTURE_1D
&&
2052 target
!= GL_PROXY_TEXTURE_1D
&&
2053 target
!= GL_TEXTURE_2D
&&
2054 target
!= GL_PROXY_TEXTURE_2D
&&
2055 target
!= GL_TEXTURE_1D_ARRAY
&&
2056 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2057 target
!= GL_TEXTURE_2D_ARRAY
&&
2058 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2059 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2060 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2061 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2062 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2063 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2064 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2065 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2066 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2067 _mesa_error(ctx
, GL_INVALID_ENUM
,
2068 "glTexImage%dD(bad target for depth texture)",
2074 /* additional checks for compressed textures */
2075 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2076 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2077 _mesa_error(ctx
, GL_INVALID_ENUM
,
2078 "glTexImage%dD(target can't be compressed)", dimensions
);
2081 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2082 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2083 "glTexImage%dD(no compression for format)", dimensions
);
2087 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2088 "glTexImage%dD(border!=0)", dimensions
);
2093 /* additional checks for integer textures */
2094 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2095 (_mesa_is_enum_format_integer(format
) !=
2096 _mesa_is_enum_format_integer(internalFormat
))) {
2097 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2098 "glTexImage%dD(integer/non-integer format mismatch)",
2103 if (!mutable_tex_object(ctx
, target
)) {
2104 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2105 "glTexImage%dD(immutable texture)", dimensions
);
2109 /* if we get here, the parameters are OK */
2115 * Error checking for glCompressedTexImage[123]D().
2116 * Note that the width, height and depth values are not fully error checked
2118 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2121 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2122 GLenum target
, GLint level
,
2123 GLenum internalFormat
, GLsizei width
,
2124 GLsizei height
, GLsizei depth
, GLint border
,
2127 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2129 GLenum error
= GL_NO_ERROR
;
2130 char *reason
= ""; /* no error */
2132 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2134 error
= GL_INVALID_ENUM
;
2138 /* This will detect any invalid internalFormat value */
2139 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2140 reason
= "internalFormat";
2141 error
= GL_INVALID_ENUM
;
2145 switch (internalFormat
) {
2146 case GL_PALETTE4_RGB8_OES
:
2147 case GL_PALETTE4_RGBA8_OES
:
2148 case GL_PALETTE4_R5_G6_B5_OES
:
2149 case GL_PALETTE4_RGBA4_OES
:
2150 case GL_PALETTE4_RGB5_A1_OES
:
2151 case GL_PALETTE8_RGB8_OES
:
2152 case GL_PALETTE8_RGBA8_OES
:
2153 case GL_PALETTE8_R5_G6_B5_OES
:
2154 case GL_PALETTE8_RGBA4_OES
:
2155 case GL_PALETTE8_RGB5_A1_OES
:
2156 /* check level (note that level should be zero or less!) */
2157 if (level
> 0 || level
< -maxLevels
) {
2159 error
= GL_INVALID_VALUE
;
2163 if (dimensions
!= 2) {
2164 reason
= "compressed paletted textures must be 2D";
2165 error
= GL_INVALID_OPERATION
;
2169 /* Figure out the expected texture size (in bytes). This will be
2170 * checked against the actual size later.
2172 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2175 /* This is for the benefit of the TestProxyTexImage below. It expects
2176 * level to be non-negative. OES_compressed_paletted_texture uses a
2177 * weird mechanism where the level specified to glCompressedTexImage2D
2178 * is -(n-1) number of levels in the texture, and the data specifies the
2179 * complete mipmap stack. This is done to ensure the palette is the
2180 * same for all levels.
2187 if (level
< 0 || level
>= maxLevels
) {
2189 error
= GL_INVALID_VALUE
;
2193 /* Figure out the expected texture size (in bytes). This will be
2194 * checked against the actual size later.
2196 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2200 /* This should really never fail */
2201 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2202 reason
= "internalFormat";
2203 error
= GL_INVALID_ENUM
;
2207 /* No compressed formats support borders at this time */
2209 reason
= "border != 0";
2210 error
= GL_INVALID_VALUE
;
2214 /* check image size in bytes */
2215 if (expectedSize
!= imageSize
) {
2216 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2217 * if <imageSize> is not consistent with the format, dimensions, and
2218 * contents of the specified image.
2220 reason
= "imageSize inconsistant with width/height/format";
2221 error
= GL_INVALID_VALUE
;
2225 if (!mutable_tex_object(ctx
, target
)) {
2226 reason
= "immutable texture";
2227 error
= GL_INVALID_OPERATION
;
2234 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2241 * Test glTexSubImage[123]D() parameters for errors.
2243 * \param ctx GL context.
2244 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2245 * \param target texture target given by the user (already validated)
2246 * \param level image level given by the user.
2247 * \param xoffset sub-image x offset given by the user.
2248 * \param yoffset sub-image y offset given by the user.
2249 * \param zoffset sub-image z offset given by the user.
2250 * \param format pixel data format given by the user.
2251 * \param type pixel data type given by the user.
2252 * \param width image width given by the user.
2253 * \param height image height given by the user.
2254 * \param depth image depth given by the user.
2256 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2258 * Verifies each of the parameters against the constants specified in
2259 * __struct gl_contextRec::Const and the supported extensions, and according
2260 * to the OpenGL specification.
2263 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2264 GLenum target
, GLint level
,
2265 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2266 GLint width
, GLint height
, GLint depth
,
2267 GLenum format
, GLenum type
)
2269 struct gl_texture_object
*texObj
;
2270 struct gl_texture_image
*texImage
;
2273 /* check target (proxies not allowed) */
2274 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2275 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2276 dimensions
, _mesa_lookup_enum_by_nr(target
));
2281 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2282 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2287 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2288 * combinations of format and type that can be used. Formats and types
2289 * that require additional extensions (e.g., GL_FLOAT requires
2290 * GL_OES_texture_float) are filtered elsewhere.
2292 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2293 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2294 if (err
!= GL_NO_ERROR
) {
2295 _mesa_error(ctx
, err
,
2296 "glTexSubImage%dD(format = %s, type = %s)",
2298 _mesa_lookup_enum_by_nr(format
),
2299 _mesa_lookup_enum_by_nr(type
));
2304 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2305 if (err
!= GL_NO_ERROR
) {
2306 _mesa_error(ctx
, err
,
2307 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2308 dimensions
, _mesa_lookup_enum_by_nr(format
),
2309 _mesa_lookup_enum_by_nr(type
));
2313 /* Get dest texture object / image pointers */
2314 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2316 /* must be out of memory */
2317 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2321 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2323 /* non-existant texture level */
2324 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2325 "glTexSubImage%dD(invalid texture image)", dimensions
);
2329 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2330 texImage
, xoffset
, yoffset
, 0,
2331 width
, height
, 1)) {
2335 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2336 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2337 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2338 "glTexSubImage%dD(no compression for format)", dimensions
);
2343 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2344 /* both source and dest must be integer-valued, or neither */
2345 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2346 _mesa_is_enum_format_integer(format
)) {
2347 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2348 "glTexSubImage%dD(integer/non-integer format mismatch)",
2359 * Test glCopyTexImage[12]D() parameters for errors.
2361 * \param ctx GL context.
2362 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2363 * \param target texture target given by the user.
2364 * \param level image level given by the user.
2365 * \param internalFormat internal format given by the user.
2366 * \param width image width given by the user.
2367 * \param height image height given by the user.
2368 * \param border texture border.
2370 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2372 * Verifies each of the parameters against the constants specified in
2373 * __struct gl_contextRec::Const and the supported extensions, and according
2374 * to the OpenGL specification.
2377 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2378 GLenum target
, GLint level
, GLint internalFormat
,
2379 GLint width
, GLint height
, GLint border
)
2382 GLint rb_base_format
;
2383 struct gl_renderbuffer
*rb
;
2384 GLenum rb_internal_format
;
2387 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2388 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2389 dimensions
, _mesa_lookup_enum_by_nr(target
));
2394 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2395 _mesa_error(ctx
, GL_INVALID_VALUE
,
2396 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2400 /* Check that the source buffer is complete */
2401 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2402 if (ctx
->ReadBuffer
->_Status
== 0) {
2403 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2405 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2406 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2407 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2411 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2412 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2413 "glCopyTexImage%dD(multisample FBO)",
2420 if (border
< 0 || border
> 1 ||
2421 ((ctx
->API
!= API_OPENGL_COMPAT
||
2422 target
== GL_TEXTURE_RECTANGLE_NV
||
2423 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2424 _mesa_error(ctx
, GL_INVALID_VALUE
,
2425 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2429 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2431 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2432 "glCopyTexImage%dD(read buffer)", dimensions
);
2436 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2439 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2440 switch (internalFormat
) {
2445 case GL_LUMINANCE_ALPHA
:
2448 _mesa_error(ctx
, GL_INVALID_VALUE
,
2449 "glCopyTexImage%dD(internalFormat)", dimensions
);
2454 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2455 if (baseFormat
< 0) {
2456 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2457 "glCopyTexImage%dD(internalFormat)", dimensions
);
2461 rb_internal_format
= rb
->InternalFormat
;
2462 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2463 if (_mesa_is_color_format(internalFormat
)) {
2464 if (rb_base_format
< 0) {
2465 _mesa_error(ctx
, GL_INVALID_VALUE
,
2466 "glCopyTexImage%dD(internalFormat)", dimensions
);
2471 if (_mesa_is_gles(ctx
)) {
2473 if (_mesa_base_format_component_count(baseFormat
) >
2474 _mesa_base_format_component_count(rb_base_format
)) {
2477 if (baseFormat
== GL_DEPTH_COMPONENT
||
2478 baseFormat
== GL_DEPTH_STENCIL
||
2479 rb_base_format
== GL_DEPTH_COMPONENT
||
2480 rb_base_format
== GL_DEPTH_STENCIL
||
2481 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2482 baseFormat
== GL_ALPHA
) &&
2483 rb_base_format
!= GL_RGBA
) ||
2484 internalFormat
== GL_RGB9_E5
) {
2487 if (internalFormat
== GL_RGB9_E5
) {
2491 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2492 "glCopyTexImage%dD(internalFormat)", dimensions
);
2497 if (_mesa_is_gles3(ctx
)) {
2498 bool rb_is_srgb
= false;
2499 bool dst_is_srgb
= false;
2501 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2502 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2506 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2510 if (rb_is_srgb
!= dst_is_srgb
) {
2511 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2512 * OpenGLES 3.0.0 spec says:
2514 * "The error INVALID_OPERATION is also generated if the
2515 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2516 * framebuffer attachment corresponding to the read buffer
2517 * is LINEAR (see section 6.1.13) and internalformat is
2518 * one of the sRGB formats described in section 3.8.16, or
2519 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2520 * SRGB and internalformat is not one of the sRGB formats."
2522 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2523 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2528 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2529 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2530 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2534 /* From the EXT_texture_integer spec:
2536 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2537 * if the texture internalformat is an integer format and the read color
2538 * buffer is not an integer format, or if the internalformat is not an
2539 * integer format and the read color buffer is an integer format."
2541 if (_mesa_is_color_format(internalFormat
)) {
2542 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2543 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2544 if (is_int
|| is_rbint
) {
2545 if (is_int
!= is_rbint
) {
2546 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2547 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2549 } else if (_mesa_is_gles(ctx
) &&
2550 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2551 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2552 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2553 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2559 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2560 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2561 _mesa_error(ctx
, GL_INVALID_ENUM
,
2562 "glCopyTexImage%dD(target)", dimensions
);
2565 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2566 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2567 "glCopyTexImage%dD(no compression for format)", dimensions
);
2571 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2572 "glCopyTexImage%dD(border!=0)", dimensions
);
2577 if (!mutable_tex_object(ctx
, target
)) {
2578 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2579 "glCopyTexImage%dD(immutable texture)", dimensions
);
2583 /* if we get here, the parameters are OK */
2589 * Test glCopyTexSubImage[12]D() parameters for errors.
2590 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2593 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2594 GLenum target
, GLint level
,
2595 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2596 GLint width
, GLint height
)
2598 struct gl_texture_object
*texObj
;
2599 struct gl_texture_image
*texImage
;
2601 /* Check that the source buffer is complete */
2602 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2603 if (ctx
->ReadBuffer
->_Status
== 0) {
2604 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2606 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2607 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2608 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2612 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2613 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2614 "glCopyTexSubImage%dD(multisample FBO)",
2620 /* check target (proxies not allowed) */
2621 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2622 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2623 dimensions
, _mesa_lookup_enum_by_nr(target
));
2628 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2629 _mesa_error(ctx
, GL_INVALID_VALUE
,
2630 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2634 /* Get dest texture object / image pointers */
2635 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2637 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2641 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2643 /* destination image does not exist */
2644 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2645 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2649 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2650 dimensions
, texImage
,
2651 xoffset
, yoffset
, zoffset
,
2652 width
, height
, 1)) {
2656 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2657 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2658 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2659 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2664 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2665 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2669 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2670 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2671 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2672 dimensions
, texImage
->_BaseFormat
);
2676 /* From the EXT_texture_integer spec:
2678 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2679 * if the texture internalformat is an integer format and the read color
2680 * buffer is not an integer format, or if the internalformat is not an
2681 * integer format and the read color buffer is an integer format."
2683 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2684 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2686 if (_mesa_is_format_integer_color(rb
->Format
) !=
2687 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2688 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2689 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2694 /* if we get here, the parameters are OK */
2699 /** Callback info for walking over FBO hash table */
2702 struct gl_context
*ctx
;
2703 struct gl_texture_object
*texObj
;
2709 * Check render to texture callback. Called from _mesa_HashWalk().
2712 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2714 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2715 const struct cb_info
*info
= (struct cb_info
*) userData
;
2716 struct gl_context
*ctx
= info
->ctx
;
2717 const struct gl_texture_object
*texObj
= info
->texObj
;
2718 const GLuint level
= info
->level
, face
= info
->face
;
2720 /* If this is a user-created FBO */
2721 if (_mesa_is_user_fbo(fb
)) {
2723 /* check if any of the FBO's attachments point to 'texObj' */
2724 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2725 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2726 if (att
->Type
== GL_TEXTURE
&&
2727 att
->Texture
== texObj
&&
2728 att
->TextureLevel
== level
&&
2729 att
->CubeMapFace
== face
) {
2730 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2731 ASSERT(att
->Renderbuffer
->TexImage
);
2732 /* Mark fb status as indeterminate to force re-validation */
2741 * When a texture image is specified we have to check if it's bound to
2742 * any framebuffer objects (render to texture) in order to detect changes
2743 * in size or format since that effects FBO completeness.
2744 * Any FBOs rendering into the texture must be re-validated.
2747 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2748 struct gl_texture_object
*texObj
,
2749 GLuint face
, GLuint level
)
2751 /* Only check this texture if it's been marked as RenderToTexture */
2752 if (texObj
->_RenderToTexture
) {
2753 struct cb_info info
;
2755 info
.texObj
= texObj
;
2758 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2764 * If the texture object's GenerateMipmap flag is set and we've
2765 * changed the texture base level image, regenerate the rest of the
2766 * mipmap levels now.
2769 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2770 struct gl_texture_object
*texObj
, GLint level
)
2772 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2773 if (texObj
->GenerateMipmap
&&
2774 level
== texObj
->BaseLevel
&&
2775 level
< texObj
->MaxLevel
) {
2776 ASSERT(ctx
->Driver
.GenerateMipmap
);
2777 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2782 /** Debug helper: override the user-requested internal format */
2784 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2787 if (internalFormat
== GL_RGBA16F_ARB
||
2788 internalFormat
== GL_RGBA32F_ARB
) {
2789 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2792 else if (internalFormat
== GL_RGB16F_ARB
||
2793 internalFormat
== GL_RGB32F_ARB
) {
2794 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2797 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2798 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2799 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2800 return GL_LUMINANCE_ALPHA
;
2802 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2803 internalFormat
== GL_LUMINANCE32F_ARB
) {
2804 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2805 return GL_LUMINANCE
;
2807 else if (internalFormat
== GL_ALPHA16F_ARB
||
2808 internalFormat
== GL_ALPHA32F_ARB
) {
2809 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2813 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2814 internalFormat = GL_RGBA;
2818 return internalFormat
;
2821 return internalFormat
;
2827 * Choose the actual hardware format for a texture image.
2828 * Try to use the same format as the previous image level when possible.
2829 * Otherwise, ask the driver for the best format.
2830 * It's important to try to choose a consistant format for all levels
2831 * for efficient texture memory layout/allocation. In particular, this
2832 * comes up during automatic mipmap generation.
2835 _mesa_choose_texture_format(struct gl_context
*ctx
,
2836 struct gl_texture_object
*texObj
,
2837 GLenum target
, GLint level
,
2838 GLenum internalFormat
, GLenum format
, GLenum type
)
2842 /* see if we've already chosen a format for the previous level */
2844 struct gl_texture_image
*prevImage
=
2845 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2846 /* See if the prev level is defined and has an internal format which
2847 * matches the new internal format.
2850 prevImage
->Width
> 0 &&
2851 prevImage
->InternalFormat
== internalFormat
) {
2852 /* use the same format */
2853 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2854 return prevImage
->TexFormat
;
2858 /* If the application requested compression to an S3TC format but we don't
2859 * have the DXTn library, force a generic compressed format instead.
2861 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2862 const GLenum before
= internalFormat
;
2864 switch (internalFormat
) {
2865 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2866 if (!ctx
->Mesa_DXTn
)
2867 internalFormat
= GL_COMPRESSED_RGB
;
2869 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2870 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2871 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2872 if (!ctx
->Mesa_DXTn
)
2873 internalFormat
= GL_COMPRESSED_RGBA
;
2879 if (before
!= internalFormat
) {
2881 "DXT compression requested (%s), "
2882 "but libtxc_dxtn library not installed. Using %s "
2884 _mesa_lookup_enum_by_nr(before
),
2885 _mesa_lookup_enum_by_nr(internalFormat
));
2889 /* choose format from scratch */
2890 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2892 ASSERT(f
!= MESA_FORMAT_NONE
);
2898 * Adjust pixel unpack params and image dimensions to strip off the
2899 * one-pixel texture border.
2901 * Gallium and intel don't support texture borders. They've seldem been used
2902 * and seldom been implemented correctly anyway.
2904 * \param unpackNew returns the new pixel unpack parameters
2907 strip_texture_border(GLenum target
,
2908 GLint
*width
, GLint
*height
, GLint
*depth
,
2909 const struct gl_pixelstore_attrib
*unpack
,
2910 struct gl_pixelstore_attrib
*unpackNew
)
2916 *unpackNew
= *unpack
;
2918 if (unpackNew
->RowLength
== 0)
2919 unpackNew
->RowLength
= *width
;
2921 if (unpackNew
->ImageHeight
== 0)
2922 unpackNew
->ImageHeight
= *height
;
2924 assert(*width
>= 3);
2925 unpackNew
->SkipPixels
++; /* skip the border */
2926 *width
= *width
- 2; /* reduce the width by two border pixels */
2928 /* The min height of a texture with a border is 3 */
2929 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2930 unpackNew
->SkipRows
++; /* skip the border */
2931 *height
= *height
- 2; /* reduce the height by two border pixels */
2935 target
!= GL_TEXTURE_2D_ARRAY
&&
2936 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2937 unpackNew
->SkipImages
++; /* skip the border */
2938 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2944 * Common code to implement all the glTexImage1D/2D/3D functions
2945 * as well as glCompressedTexImage1D/2D/3D.
2946 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2947 * \param format the user's image format (only used if !compressed)
2948 * \param type the user's image type (only used if !compressed)
2949 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2952 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2953 GLenum target
, GLint level
, GLint internalFormat
,
2954 GLsizei width
, GLsizei height
, GLsizei depth
,
2955 GLint border
, GLenum format
, GLenum type
,
2956 GLsizei imageSize
, const GLvoid
*pixels
)
2958 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2959 struct gl_pixelstore_attrib unpack_no_border
;
2960 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2961 struct gl_texture_object
*texObj
;
2962 gl_format texFormat
;
2963 GLboolean dimensionsOK
, sizeOK
;
2965 FLUSH_VERTICES(ctx
, 0);
2967 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2970 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2972 _mesa_lookup_enum_by_nr(target
), level
,
2973 _mesa_lookup_enum_by_nr(internalFormat
),
2974 width
, height
, depth
, border
, pixels
);
2977 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2979 _mesa_lookup_enum_by_nr(target
), level
,
2980 _mesa_lookup_enum_by_nr(internalFormat
),
2981 width
, height
, depth
, border
,
2982 _mesa_lookup_enum_by_nr(format
),
2983 _mesa_lookup_enum_by_nr(type
), pixels
);
2986 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2988 /* target error checking */
2989 if (!legal_teximage_target(ctx
, dims
, target
)) {
2990 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2991 func
, dims
, _mesa_lookup_enum_by_nr(target
));
2995 /* general error checking */
2997 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2999 width
, height
, depth
,
3004 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3005 format
, type
, width
, height
, depth
, border
))
3009 /* Here we convert a cpal compressed image into a regular glTexImage2D
3010 * call by decompressing the texture. If we really want to support cpal
3011 * textures in any driver this would have to be changed.
3013 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3014 switch (internalFormat
) {
3015 case GL_PALETTE4_RGB8_OES
:
3016 case GL_PALETTE4_RGBA8_OES
:
3017 case GL_PALETTE4_R5_G6_B5_OES
:
3018 case GL_PALETTE4_RGBA4_OES
:
3019 case GL_PALETTE4_RGB5_A1_OES
:
3020 case GL_PALETTE8_RGB8_OES
:
3021 case GL_PALETTE8_RGBA8_OES
:
3022 case GL_PALETTE8_R5_G6_B5_OES
:
3023 case GL_PALETTE8_RGBA4_OES
:
3024 case GL_PALETTE8_RGB5_A1_OES
:
3025 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3026 width
, height
, imageSize
, pixels
);
3031 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3035 /* For glCompressedTexImage() the driver has no choice about the
3036 * texture format since we'll never transcode the user's compressed
3037 * image data. The internalFormat was error checked earlier.
3039 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3042 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3043 internalFormat
, format
, type
);
3046 assert(texFormat
!= MESA_FORMAT_NONE
);
3048 /* check that width, height, depth are legal for the mipmap level */
3049 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3050 height
, depth
, border
);
3052 /* check that the texture won't take too much memory, etc */
3053 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3055 width
, height
, depth
, border
);
3057 if (_mesa_is_proxy_texture(target
)) {
3058 /* Proxy texture: just clear or set state depending on error checking */
3059 struct gl_texture_image
*texImage
=
3060 get_proxy_tex_image(ctx
, target
, level
);
3063 return; /* GL_OUT_OF_MEMORY already recorded */
3065 if (dimensionsOK
&& sizeOK
) {
3066 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3067 border
, internalFormat
, texFormat
);
3070 clear_teximage_fields(texImage
);
3074 /* non-proxy target */
3075 const GLuint face
= _mesa_tex_target_to_face(target
);
3076 struct gl_texture_image
*texImage
;
3078 if (!dimensionsOK
) {
3079 _mesa_error(ctx
, GL_INVALID_VALUE
,
3080 "glTexImage%uD(invalid width or height or depth)",
3086 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3087 "glTexImage%uD(image too large)", dims
);
3091 /* Allow a hardware driver to just strip out the border, to provide
3092 * reliable but slightly incorrect hardware rendering instead of
3093 * rarely-tested software fallback rendering.
3095 if (border
&& ctx
->Const
.StripTextureBorder
) {
3096 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3099 unpack
= &unpack_no_border
;
3102 if (ctx
->NewState
& _NEW_PIXEL
)
3103 _mesa_update_state(ctx
);
3105 _mesa_lock_texture(ctx
, texObj
);
3107 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3110 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3113 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3115 _mesa_init_teximage_fields(ctx
, texImage
,
3116 width
, height
, depth
,
3117 border
, internalFormat
, texFormat
);
3119 /* Give the texture to the driver. <pixels> may be null. */
3120 if (width
> 0 && height
> 0 && depth
> 0) {
3122 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3126 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3127 type
, pixels
, unpack
);
3131 check_gen_mipmap(ctx
, target
, texObj
, level
);
3133 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3135 _mesa_dirty_texobj(ctx
, texObj
);
3138 _mesa_unlock_texture(ctx
, texObj
);
3145 * Called from the API. Note that width includes the border.
3148 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3149 GLsizei width
, GLint border
, GLenum format
,
3150 GLenum type
, const GLvoid
*pixels
)
3152 GET_CURRENT_CONTEXT(ctx
);
3153 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3154 border
, format
, type
, 0, pixels
);
3159 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3160 GLsizei width
, GLsizei height
, GLint border
,
3161 GLenum format
, GLenum type
,
3162 const GLvoid
*pixels
)
3164 GET_CURRENT_CONTEXT(ctx
);
3165 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3166 border
, format
, type
, 0, pixels
);
3171 * Called by the API or display list executor.
3172 * Note that width and height include the border.
3175 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3176 GLsizei width
, GLsizei height
, GLsizei depth
,
3177 GLint border
, GLenum format
, GLenum type
,
3178 const GLvoid
*pixels
)
3180 GET_CURRENT_CONTEXT(ctx
);
3181 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3182 width
, height
, depth
,
3183 border
, format
, type
, 0, pixels
);
3188 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3189 GLsizei width
, GLsizei height
, GLsizei depth
,
3190 GLint border
, GLenum format
, GLenum type
,
3191 const GLvoid
*pixels
)
3193 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3194 depth
, border
, format
, type
, pixels
);
3199 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3201 struct gl_texture_object
*texObj
;
3202 struct gl_texture_image
*texImage
;
3204 GET_CURRENT_CONTEXT(ctx
);
3205 FLUSH_VERTICES(ctx
, 0);
3209 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3211 case GL_TEXTURE_EXTERNAL_OES
:
3213 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3216 valid_target
= false;
3220 if (!valid_target
) {
3221 _mesa_error(ctx
, GL_INVALID_ENUM
,
3222 "glEGLImageTargetTexture2D(target=%d)", target
);
3227 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3228 "glEGLImageTargetTexture2D(image=%p)", image
);
3232 if (ctx
->NewState
& _NEW_PIXEL
)
3233 _mesa_update_state(ctx
);
3235 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3236 _mesa_lock_texture(ctx
, texObj
);
3238 if (texObj
->Immutable
) {
3239 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3240 "glEGLImageTargetTexture2D(texture is immutable)");
3241 _mesa_unlock_texture(ctx
, texObj
);
3245 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3247 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3249 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3251 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3252 texObj
, texImage
, image
);
3254 _mesa_dirty_texobj(ctx
, texObj
);
3256 _mesa_unlock_texture(ctx
, texObj
);
3263 * Implement all the glTexSubImage1/2/3D() functions.
3266 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3267 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3268 GLsizei width
, GLsizei height
, GLsizei depth
,
3269 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3271 struct gl_texture_object
*texObj
;
3272 struct gl_texture_image
*texImage
;
3274 FLUSH_VERTICES(ctx
, 0);
3276 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3277 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3279 _mesa_lookup_enum_by_nr(target
), level
,
3280 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3281 _mesa_lookup_enum_by_nr(format
),
3282 _mesa_lookup_enum_by_nr(type
), pixels
);
3284 /* check target (proxies not allowed) */
3285 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3286 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3287 dims
, _mesa_lookup_enum_by_nr(target
));
3291 if (ctx
->NewState
& _NEW_PIXEL
)
3292 _mesa_update_state(ctx
);
3294 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3295 xoffset
, yoffset
, zoffset
,
3296 width
, height
, depth
, format
, type
)) {
3297 return; /* error was detected */
3300 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3302 _mesa_lock_texture(ctx
, texObj
);
3304 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3306 if (width
> 0 && height
> 0 && depth
> 0) {
3307 /* If we have a border, offset=-1 is legal. Bias by border width. */
3310 if (target
!= GL_TEXTURE_2D_ARRAY
)
3311 zoffset
+= texImage
->Border
;
3314 if (target
!= GL_TEXTURE_1D_ARRAY
)
3315 yoffset
+= texImage
->Border
;
3318 xoffset
+= texImage
->Border
;
3321 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3322 xoffset
, yoffset
, zoffset
,
3323 width
, height
, depth
,
3324 format
, type
, pixels
, &ctx
->Unpack
);
3326 check_gen_mipmap(ctx
, target
, texObj
, level
);
3328 ctx
->NewState
|= _NEW_TEXTURE
;
3331 _mesa_unlock_texture(ctx
, texObj
);
3336 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3337 GLint xoffset
, GLsizei width
,
3338 GLenum format
, GLenum type
,
3339 const GLvoid
*pixels
)
3341 GET_CURRENT_CONTEXT(ctx
);
3342 texsubimage(ctx
, 1, target
, level
,
3345 format
, type
, pixels
);
3350 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3351 GLint xoffset
, GLint yoffset
,
3352 GLsizei width
, GLsizei height
,
3353 GLenum format
, GLenum type
,
3354 const GLvoid
*pixels
)
3356 GET_CURRENT_CONTEXT(ctx
);
3357 texsubimage(ctx
, 2, target
, level
,
3358 xoffset
, yoffset
, 0,
3360 format
, type
, pixels
);
3366 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3367 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3368 GLsizei width
, GLsizei height
, GLsizei depth
,
3369 GLenum format
, GLenum type
,
3370 const GLvoid
*pixels
)
3372 GET_CURRENT_CONTEXT(ctx
);
3373 texsubimage(ctx
, 3, target
, level
,
3374 xoffset
, yoffset
, zoffset
,
3375 width
, height
, depth
,
3376 format
, type
, pixels
);
3382 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3383 * from. This depends on whether the texture contains color or depth values.
3385 static struct gl_renderbuffer
*
3386 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3388 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3389 /* reading from depth/stencil buffer */
3390 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3393 /* copying from color buffer */
3394 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3399 copytexsubimage_by_slice(struct gl_context
*ctx
,
3400 struct gl_texture_image
*texImage
,
3402 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3403 struct gl_renderbuffer
*rb
,
3405 GLsizei width
, GLsizei height
)
3407 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3410 /* For 1D arrays, we copy each scanline of the source rectangle into the
3413 assert(zoffset
== 0);
3415 for (slice
= 0; slice
< height
; slice
++) {
3416 assert(yoffset
+ slice
< texImage
->Height
);
3417 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3418 xoffset
, 0, yoffset
+ slice
,
3419 rb
, x
, y
+ slice
, width
, 1);
3422 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3423 xoffset
, yoffset
, zoffset
,
3424 rb
, x
, y
, width
, height
);
3430 * Implement the glCopyTexImage1/2D() functions.
3433 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3434 GLenum target
, GLint level
, GLenum internalFormat
,
3435 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3437 struct gl_texture_object
*texObj
;
3438 struct gl_texture_image
*texImage
;
3439 const GLuint face
= _mesa_tex_target_to_face(target
);
3440 gl_format texFormat
;
3442 FLUSH_VERTICES(ctx
, 0);
3444 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3445 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3447 _mesa_lookup_enum_by_nr(target
), level
,
3448 _mesa_lookup_enum_by_nr(internalFormat
),
3449 x
, y
, width
, height
, border
);
3451 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3452 _mesa_update_state(ctx
);
3454 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3455 width
, height
, border
))
3458 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3460 _mesa_error(ctx
, GL_INVALID_VALUE
,
3461 "glCopyTexImage%uD(invalid width or height)", dims
);
3465 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3468 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3469 internalFormat
, GL_NONE
, GL_NONE
);
3470 assert(texFormat
!= MESA_FORMAT_NONE
);
3472 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3474 width
, height
, 1, border
)) {
3475 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3476 "glCopyTexImage%uD(image too large)", dims
);
3480 if (border
&& ctx
->Const
.StripTextureBorder
) {
3482 width
-= border
* 2;
3485 height
-= border
* 2;
3490 _mesa_lock_texture(ctx
, texObj
);
3492 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3495 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3498 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3500 /* Free old texture image */
3501 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3503 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3504 border
, internalFormat
, texFormat
);
3506 if (width
&& height
) {
3507 /* Allocate texture memory (no pixel data yet) */
3508 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3510 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3512 struct gl_renderbuffer
*srcRb
=
3513 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3515 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3517 srcRb
, srcX
, srcY
, width
, height
);
3520 check_gen_mipmap(ctx
, target
, texObj
, level
);
3523 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3525 _mesa_dirty_texobj(ctx
, texObj
);
3528 _mesa_unlock_texture(ctx
, texObj
);
3534 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3535 GLenum internalFormat
,
3537 GLsizei width
, GLint border
)
3539 GET_CURRENT_CONTEXT(ctx
);
3540 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3546 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3547 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3550 GET_CURRENT_CONTEXT(ctx
);
3551 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3552 x
, y
, width
, height
, border
);
3558 * Implementation for glCopyTexSubImage1/2/3D() functions.
3561 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3562 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3563 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3565 struct gl_texture_object
*texObj
;
3566 struct gl_texture_image
*texImage
;
3568 FLUSH_VERTICES(ctx
, 0);
3570 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3571 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3573 _mesa_lookup_enum_by_nr(target
),
3574 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3576 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3577 _mesa_update_state(ctx
);
3579 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3580 xoffset
, yoffset
, zoffset
, width
, height
)) {
3584 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3586 _mesa_lock_texture(ctx
, texObj
);
3588 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3590 /* If we have a border, offset=-1 is legal. Bias by border width. */
3593 if (target
!= GL_TEXTURE_2D_ARRAY
)
3594 zoffset
+= texImage
->Border
;
3597 if (target
!= GL_TEXTURE_1D_ARRAY
)
3598 yoffset
+= texImage
->Border
;
3601 xoffset
+= texImage
->Border
;
3604 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3606 struct gl_renderbuffer
*srcRb
=
3607 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3609 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3610 xoffset
, yoffset
, zoffset
,
3611 srcRb
, x
, y
, width
, height
);
3613 check_gen_mipmap(ctx
, target
, texObj
, level
);
3615 ctx
->NewState
|= _NEW_TEXTURE
;
3618 _mesa_unlock_texture(ctx
, texObj
);
3623 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3624 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3626 GET_CURRENT_CONTEXT(ctx
);
3627 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3633 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3634 GLint xoffset
, GLint yoffset
,
3635 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3637 GET_CURRENT_CONTEXT(ctx
);
3638 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3645 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3646 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3647 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3649 GET_CURRENT_CONTEXT(ctx
);
3650 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3651 x
, y
, width
, height
);
3657 /**********************************************************************/
3658 /****** Compressed Textures ******/
3659 /**********************************************************************/
3663 * Error checking for glCompressedTexSubImage[123]D().
3664 * \return error code or GL_NO_ERROR.
3667 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3668 GLenum target
, GLint level
,
3669 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3670 GLsizei width
, GLsizei height
, GLsizei depth
,
3671 GLenum format
, GLsizei imageSize
)
3673 struct gl_texture_object
*texObj
;
3674 struct gl_texture_image
*texImage
;
3682 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3683 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3684 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3685 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3686 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3687 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3691 targetOK
= GL_FALSE
;
3696 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3700 /* no 1D compressed textures at this time */
3701 targetOK
= GL_FALSE
;
3706 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3711 /* this will catch any invalid compressed format token */
3712 if (!_mesa_is_compressed_format(ctx
, format
)) {
3713 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3718 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3719 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3724 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3725 if (expectedSize
!= imageSize
) {
3726 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3731 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3733 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3734 "glCompressedTexSubImage%uD()", dims
);
3738 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3740 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3741 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3745 if ((GLint
) format
!= texImage
->InternalFormat
) {
3746 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3747 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3751 if (compressedteximage_only_format(ctx
, format
)) {
3752 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3753 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3758 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3759 texImage
, xoffset
, yoffset
, zoffset
,
3760 width
, height
, depth
)) {
3769 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3770 GLenum internalFormat
, GLsizei width
,
3771 GLint border
, GLsizei imageSize
,
3774 GET_CURRENT_CONTEXT(ctx
);
3775 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3776 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3781 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3782 GLenum internalFormat
, GLsizei width
,
3783 GLsizei height
, GLint border
, GLsizei imageSize
,
3786 GET_CURRENT_CONTEXT(ctx
);
3787 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3788 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3793 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3794 GLenum internalFormat
, GLsizei width
,
3795 GLsizei height
, GLsizei depth
, GLint border
,
3796 GLsizei imageSize
, const GLvoid
*data
)
3798 GET_CURRENT_CONTEXT(ctx
);
3799 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3800 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3805 * Common helper for glCompressedTexSubImage1/2/3D().
3808 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3809 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3810 GLsizei width
, GLsizei height
, GLsizei depth
,
3811 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3813 struct gl_texture_object
*texObj
;
3814 struct gl_texture_image
*texImage
;
3815 GET_CURRENT_CONTEXT(ctx
);
3816 FLUSH_VERTICES(ctx
, 0);
3818 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3819 xoffset
, yoffset
, zoffset
,
3820 width
, height
, depth
,
3821 format
, imageSize
)) {
3825 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3827 _mesa_lock_texture(ctx
, texObj
);
3829 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3832 if (width
> 0 && height
> 0 && depth
> 0) {
3833 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3834 xoffset
, yoffset
, zoffset
,
3835 width
, height
, depth
,
3836 format
, imageSize
, data
);
3838 check_gen_mipmap(ctx
, target
, texObj
, level
);
3840 ctx
->NewState
|= _NEW_TEXTURE
;
3843 _mesa_unlock_texture(ctx
, texObj
);
3848 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3849 GLsizei width
, GLenum format
,
3850 GLsizei imageSize
, const GLvoid
*data
)
3852 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3853 format
, imageSize
, data
);
3858 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3859 GLint yoffset
, GLsizei width
, GLsizei height
,
3860 GLenum format
, GLsizei imageSize
,
3863 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3864 width
, height
, 1, format
, imageSize
, data
);
3869 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3870 GLint yoffset
, GLint zoffset
, GLsizei width
,
3871 GLsizei height
, GLsizei depth
, GLenum format
,
3872 GLsizei imageSize
, const GLvoid
*data
)
3874 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3875 width
, height
, depth
, format
, imageSize
, data
);
3879 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3881 if (ctx
->API
!= API_OPENGL_CORE
) {
3882 switch (internalFormat
) {
3884 return MESA_FORMAT_A8
;
3886 return MESA_FORMAT_A16
;
3887 case GL_ALPHA16F_ARB
:
3888 return MESA_FORMAT_ALPHA_FLOAT16
;
3889 case GL_ALPHA32F_ARB
:
3890 return MESA_FORMAT_ALPHA_FLOAT32
;
3891 case GL_ALPHA8I_EXT
:
3892 return MESA_FORMAT_ALPHA_INT8
;
3893 case GL_ALPHA16I_EXT
:
3894 return MESA_FORMAT_ALPHA_INT16
;
3895 case GL_ALPHA32I_EXT
:
3896 return MESA_FORMAT_ALPHA_INT32
;
3897 case GL_ALPHA8UI_EXT
:
3898 return MESA_FORMAT_ALPHA_UINT8
;
3899 case GL_ALPHA16UI_EXT
:
3900 return MESA_FORMAT_ALPHA_UINT16
;
3901 case GL_ALPHA32UI_EXT
:
3902 return MESA_FORMAT_ALPHA_UINT32
;
3904 return MESA_FORMAT_L8
;
3905 case GL_LUMINANCE16
:
3906 return MESA_FORMAT_L16
;
3907 case GL_LUMINANCE16F_ARB
:
3908 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3909 case GL_LUMINANCE32F_ARB
:
3910 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3911 case GL_LUMINANCE8I_EXT
:
3912 return MESA_FORMAT_LUMINANCE_INT8
;
3913 case GL_LUMINANCE16I_EXT
:
3914 return MESA_FORMAT_LUMINANCE_INT16
;
3915 case GL_LUMINANCE32I_EXT
:
3916 return MESA_FORMAT_LUMINANCE_INT32
;
3917 case GL_LUMINANCE8UI_EXT
:
3918 return MESA_FORMAT_LUMINANCE_UINT8
;
3919 case GL_LUMINANCE16UI_EXT
:
3920 return MESA_FORMAT_LUMINANCE_UINT16
;
3921 case GL_LUMINANCE32UI_EXT
:
3922 return MESA_FORMAT_LUMINANCE_UINT32
;
3923 case GL_LUMINANCE8_ALPHA8
:
3924 return MESA_FORMAT_AL88
;
3925 case GL_LUMINANCE16_ALPHA16
:
3926 return MESA_FORMAT_AL1616
;
3927 case GL_LUMINANCE_ALPHA16F_ARB
:
3928 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3929 case GL_LUMINANCE_ALPHA32F_ARB
:
3930 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3931 case GL_LUMINANCE_ALPHA8I_EXT
:
3932 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3933 case GL_LUMINANCE_ALPHA16I_EXT
:
3934 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3935 case GL_LUMINANCE_ALPHA32I_EXT
:
3936 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3937 case GL_LUMINANCE_ALPHA8UI_EXT
:
3938 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3939 case GL_LUMINANCE_ALPHA16UI_EXT
:
3940 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3941 case GL_LUMINANCE_ALPHA32UI_EXT
:
3942 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3944 return MESA_FORMAT_I8
;
3945 case GL_INTENSITY16
:
3946 return MESA_FORMAT_I16
;
3947 case GL_INTENSITY16F_ARB
:
3948 return MESA_FORMAT_INTENSITY_FLOAT16
;
3949 case GL_INTENSITY32F_ARB
:
3950 return MESA_FORMAT_INTENSITY_FLOAT32
;
3951 case GL_INTENSITY8I_EXT
:
3952 return MESA_FORMAT_INTENSITY_INT8
;
3953 case GL_INTENSITY16I_EXT
:
3954 return MESA_FORMAT_INTENSITY_INT16
;
3955 case GL_INTENSITY32I_EXT
:
3956 return MESA_FORMAT_INTENSITY_INT32
;
3957 case GL_INTENSITY8UI_EXT
:
3958 return MESA_FORMAT_INTENSITY_UINT8
;
3959 case GL_INTENSITY16UI_EXT
:
3960 return MESA_FORMAT_INTENSITY_UINT16
;
3961 case GL_INTENSITY32UI_EXT
:
3962 return MESA_FORMAT_INTENSITY_UINT32
;
3968 if (ctx
->API
== API_OPENGL_CORE
&&
3969 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
3970 switch (internalFormat
) {
3972 return MESA_FORMAT_RGB_FLOAT32
;
3974 return MESA_FORMAT_RGB_UINT32
;
3976 return MESA_FORMAT_RGB_INT32
;
3982 switch (internalFormat
) {
3984 return MESA_FORMAT_RGBA8888_REV
;
3986 return MESA_FORMAT_RGBA_16
;
3987 case GL_RGBA16F_ARB
:
3988 return MESA_FORMAT_RGBA_FLOAT16
;
3989 case GL_RGBA32F_ARB
:
3990 return MESA_FORMAT_RGBA_FLOAT32
;
3992 return MESA_FORMAT_RGBA_INT8
;
3993 case GL_RGBA16I_EXT
:
3994 return MESA_FORMAT_RGBA_INT16
;
3995 case GL_RGBA32I_EXT
:
3996 return MESA_FORMAT_RGBA_INT32
;
3997 case GL_RGBA8UI_EXT
:
3998 return MESA_FORMAT_RGBA_UINT8
;
3999 case GL_RGBA16UI_EXT
:
4000 return MESA_FORMAT_RGBA_UINT16
;
4001 case GL_RGBA32UI_EXT
:
4002 return MESA_FORMAT_RGBA_UINT32
;
4005 return MESA_FORMAT_GR88
;
4007 return MESA_FORMAT_GR1616
;
4009 return MESA_FORMAT_RG_FLOAT16
;
4011 return MESA_FORMAT_RG_FLOAT32
;
4013 return MESA_FORMAT_RG_INT8
;
4015 return MESA_FORMAT_RG_INT16
;
4017 return MESA_FORMAT_RG_INT32
;
4019 return MESA_FORMAT_RG_UINT8
;
4021 return MESA_FORMAT_RG_UINT16
;
4023 return MESA_FORMAT_RG_UINT32
;
4026 return MESA_FORMAT_R8
;
4028 return MESA_FORMAT_R16
;
4030 return MESA_FORMAT_R_FLOAT16
;
4032 return MESA_FORMAT_R_FLOAT32
;
4034 return MESA_FORMAT_R_INT8
;
4036 return MESA_FORMAT_R_INT16
;
4038 return MESA_FORMAT_R_INT32
;
4040 return MESA_FORMAT_R_UINT8
;
4042 return MESA_FORMAT_R_UINT16
;
4044 return MESA_FORMAT_R_UINT32
;
4047 return MESA_FORMAT_NONE
;
4053 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4054 GLenum internalFormat
)
4056 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4059 if (format
== MESA_FORMAT_NONE
)
4060 return MESA_FORMAT_NONE
;
4062 datatype
= _mesa_get_format_datatype(format
);
4063 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4064 return MESA_FORMAT_NONE
;
4066 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4067 return MESA_FORMAT_NONE
;
4069 if (!ctx
->Extensions
.ARB_texture_rg
) {
4070 GLenum base_format
= _mesa_get_format_base_format(format
);
4071 if (base_format
== GL_R
|| base_format
== GL_RG
)
4072 return MESA_FORMAT_NONE
;
4075 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4076 GLenum base_format
= _mesa_get_format_base_format(format
);
4077 if (base_format
== GL_RGB
)
4078 return MESA_FORMAT_NONE
;
4085 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4086 struct gl_buffer_object
*bufObj
,
4087 GLintptr offset
, GLsizeiptr size
)
4089 struct gl_texture_object
*texObj
;
4092 FLUSH_VERTICES(ctx
, 0);
4094 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4095 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4099 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
4100 if (format
== MESA_FORMAT_NONE
) {
4101 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4106 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4108 _mesa_lock_texture(ctx
, texObj
);
4110 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4111 texObj
->BufferObjectFormat
= internalFormat
;
4112 texObj
->_BufferObjectFormat
= format
;
4113 texObj
->BufferOffset
= offset
;
4114 texObj
->BufferSize
= size
;
4116 _mesa_unlock_texture(ctx
, texObj
);
4120 /** GL_ARB_texture_buffer_object */
4122 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4124 struct gl_buffer_object
*bufObj
;
4126 GET_CURRENT_CONTEXT(ctx
);
4128 /* NOTE: ARB_texture_buffer_object has interactions with
4129 * the compatibility profile that are not implemented.
4131 if (!(ctx
->API
== API_OPENGL_CORE
&&
4132 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4133 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4137 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4138 if (!bufObj
&& buffer
) {
4139 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4143 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4147 /** GL_ARB_texture_buffer_range */
4149 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4150 GLintptr offset
, GLsizeiptr size
)
4152 struct gl_buffer_object
*bufObj
;
4154 GET_CURRENT_CONTEXT(ctx
);
4156 if (!(ctx
->API
== API_OPENGL_CORE
&&
4157 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4158 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4162 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4166 (offset
+ size
) > bufObj
->Size
) {
4167 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4170 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4171 _mesa_error(ctx
, GL_INVALID_VALUE
,
4172 "glTexBufferRange(invalid offset alignment)");
4175 } else if (buffer
) {
4176 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4184 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4189 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4191 /* Everything that is allowed for renderbuffers,
4192 * except for a base format of GL_STENCIL_INDEX.
4194 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4195 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4199 /** GL_ARB_texture_multisample */
4201 check_multisample_target(GLuint dims
, GLenum target
)
4204 case GL_TEXTURE_2D_MULTISAMPLE
:
4205 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4208 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4209 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4219 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4220 GLint internalformat
, GLsizei width
, GLsizei height
,
4221 GLsizei depth
, GLboolean fixedsamplelocations
,
4222 GLboolean immutable
, const char *func
)
4224 struct gl_texture_object
*texObj
;
4225 struct gl_texture_image
*texImage
;
4226 GLboolean sizeOK
, dimensionsOK
;
4227 gl_format texFormat
;
4228 GLenum sample_count_error
;
4230 GET_CURRENT_CONTEXT(ctx
);
4232 if (!(ctx
->Extensions
.ARB_texture_multisample
4233 && _mesa_is_desktop_gl(ctx
))) {
4234 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4238 if (!check_multisample_target(dims
, target
)) {
4239 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4243 /* check that the specified internalformat is color/depth/stencil-renderable;
4244 * refer GL3.1 spec 4.4.4
4247 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4248 _mesa_error(ctx
, GL_INVALID_ENUM
,
4249 "%s(internalformat=%s not legal for immutable-format)",
4250 func
, _mesa_lookup_enum_by_nr(internalformat
));
4254 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4255 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4256 "%s(internalformat=%s)",
4257 func
, _mesa_lookup_enum_by_nr(internalformat
));
4261 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4262 internalformat
, samples
);
4263 if (sample_count_error
!= GL_NO_ERROR
) {
4264 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4268 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4270 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4271 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4272 "%s(texture object 0)",
4277 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4279 if (texImage
== NULL
) {
4280 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4284 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4285 internalformat
, GL_NONE
, GL_NONE
);
4286 assert(texFormat
!= MESA_FORMAT_NONE
);
4288 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4289 width
, height
, depth
, 0);
4291 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4292 width
, height
, depth
, 0);
4294 if (_mesa_is_proxy_texture(target
)) {
4295 if (dimensionsOK
&& sizeOK
) {
4296 _mesa_init_teximage_fields(ctx
, texImage
,
4297 width
, height
, depth
, 0, internalformat
, texFormat
);
4298 texImage
->NumSamples
= samples
;
4299 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4302 /* clear all image fields */
4303 _mesa_init_teximage_fields(ctx
, texImage
,
4304 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4308 if (!dimensionsOK
) {
4309 _mesa_error(ctx
, GL_INVALID_VALUE
,
4310 "%s(invalid width or height)", func
);
4315 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4316 "%s(texture too large)", func
);
4320 /* Check if texObj->Immutable is set */
4321 if (texObj
->Immutable
) {
4322 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4326 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4328 _mesa_init_teximage_fields(ctx
, texImage
,
4329 width
, height
, depth
, 0, internalformat
, texFormat
);
4331 texImage
->NumSamples
= samples
;
4332 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4334 if (width
> 0 && height
> 0 && depth
> 0) {
4335 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4336 width
, height
, depth
)) {
4337 /* tidy up the texture image state. strictly speaking,
4338 * we're allowed to just leave this in whatever state we
4339 * like, but being tidy is good.
4341 _mesa_init_teximage_fields(ctx
, texImage
,
4342 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4346 texObj
->Immutable
= immutable
;
4349 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
4352 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4358 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4359 GLenum internalformat
, GLsizei width
,
4360 GLsizei height
, GLboolean fixedsamplelocations
)
4362 teximagemultisample(2, target
, samples
, internalformat
,
4363 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4364 "glTexImage2DMultisample");
4369 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4370 GLenum internalformat
, GLsizei width
,
4371 GLsizei height
, GLsizei depth
,
4372 GLboolean fixedsamplelocations
)
4374 teximagemultisample(3, target
, samples
, internalformat
,
4375 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4376 "glTexImage3DMultisample");
4381 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4382 GLenum internalformat
, GLsizei width
,
4383 GLsizei height
, GLboolean fixedsamplelocations
)
4385 teximagemultisample(2, target
, samples
, internalformat
,
4386 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4387 "glTexStorage2DMultisample");
4392 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4393 GLenum internalformat
, GLsizei width
,
4394 GLsizei height
, GLsizei depth
,
4395 GLboolean fixedsamplelocations
)
4397 teximagemultisample(3, target
, samples
, internalformat
,
4398 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4399 "glTexStorage3DMultisample");