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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "mfeatures.h"
44 #include "texcompress.h"
45 #include "texcompress_cpal.h"
50 #include "glformats.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
63 * Return the simple base format for a given internal texture format.
64 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
66 * \param ctx GL context.
67 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
69 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
70 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
72 * This is the format which is used during texture application (i.e. the
73 * texture format and env mode determine the arithmetic used.
76 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
78 switch (internalFormat
) {
84 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
91 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
93 case GL_LUMINANCE_ALPHA
:
94 case GL_LUMINANCE4_ALPHA4
:
95 case GL_LUMINANCE6_ALPHA2
:
96 case GL_LUMINANCE8_ALPHA8
:
97 case GL_LUMINANCE12_ALPHA4
:
98 case GL_LUMINANCE12_ALPHA12
:
99 case GL_LUMINANCE16_ALPHA16
:
100 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
106 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
108 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
119 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
133 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
135 if (_mesa_is_gles(ctx
)) {
136 switch (internalFormat
) {
144 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
145 switch (internalFormat
) {
153 if (ctx
->Extensions
.ARB_depth_texture
) {
154 switch (internalFormat
) {
155 case GL_DEPTH_COMPONENT
:
156 case GL_DEPTH_COMPONENT16
:
157 case GL_DEPTH_COMPONENT24
:
158 case GL_DEPTH_COMPONENT32
:
159 return GL_DEPTH_COMPONENT
;
165 switch (internalFormat
) {
166 case GL_COMPRESSED_ALPHA
:
168 case GL_COMPRESSED_LUMINANCE
:
170 case GL_COMPRESSED_LUMINANCE_ALPHA
:
171 return GL_LUMINANCE_ALPHA
;
172 case GL_COMPRESSED_INTENSITY
:
174 case GL_COMPRESSED_RGB
:
176 case GL_COMPRESSED_RGBA
:
182 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
183 switch (internalFormat
) {
184 case GL_COMPRESSED_RGB_FXT1_3DFX
:
186 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
193 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
195 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
196 switch (internalFormat
) {
197 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
199 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
200 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
201 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
208 if (_mesa_is_desktop_gl(ctx
)
209 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
210 switch (internalFormat
) {
222 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
223 if (internalFormat
== GL_YCBCR_MESA
)
224 return GL_YCBCR_MESA
;
227 if (ctx
->Extensions
.ARB_texture_float
) {
228 switch (internalFormat
) {
229 case GL_ALPHA16F_ARB
:
230 case GL_ALPHA32F_ARB
:
238 case GL_INTENSITY16F_ARB
:
239 case GL_INTENSITY32F_ARB
:
241 case GL_LUMINANCE16F_ARB
:
242 case GL_LUMINANCE32F_ARB
:
244 case GL_LUMINANCE_ALPHA16F_ARB
:
245 case GL_LUMINANCE_ALPHA32F_ARB
:
246 return GL_LUMINANCE_ALPHA
;
252 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
253 switch (internalFormat
) {
262 if (ctx
->Extensions
.EXT_texture_snorm
) {
263 switch (internalFormat
) {
278 case GL_RGBA16_SNORM
:
281 case GL_ALPHA8_SNORM
:
282 case GL_ALPHA16_SNORM
:
284 case GL_LUMINANCE_SNORM
:
285 case GL_LUMINANCE8_SNORM
:
286 case GL_LUMINANCE16_SNORM
:
288 case GL_LUMINANCE_ALPHA_SNORM
:
289 case GL_LUMINANCE8_ALPHA8_SNORM
:
290 case GL_LUMINANCE16_ALPHA16_SNORM
:
291 return GL_LUMINANCE_ALPHA
;
292 case GL_INTENSITY_SNORM
:
293 case GL_INTENSITY8_SNORM
:
294 case GL_INTENSITY16_SNORM
:
301 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
302 switch (internalFormat
) {
303 case GL_DEPTH_STENCIL_EXT
:
304 case GL_DEPTH24_STENCIL8_EXT
:
305 return GL_DEPTH_STENCIL_EXT
;
311 if (ctx
->Extensions
.EXT_texture_sRGB
) {
312 switch (internalFormat
) {
315 case GL_COMPRESSED_SRGB_EXT
:
316 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
318 case GL_SRGB_ALPHA_EXT
:
319 case GL_SRGB8_ALPHA8_EXT
:
320 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
321 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
322 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
323 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
325 case GL_SLUMINANCE_ALPHA_EXT
:
326 case GL_SLUMINANCE8_ALPHA8_EXT
:
327 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
328 return GL_LUMINANCE_ALPHA
;
329 case GL_SLUMINANCE_EXT
:
330 case GL_SLUMINANCE8_EXT
:
331 case GL_COMPRESSED_SLUMINANCE_EXT
:
338 if (ctx
->Version
>= 30 ||
339 ctx
->Extensions
.EXT_texture_integer
) {
340 switch (internalFormat
) {
342 case GL_RGBA16UI_EXT
:
343 case GL_RGBA32UI_EXT
:
359 if (ctx
->Extensions
.EXT_texture_integer
) {
360 switch (internalFormat
) {
361 case GL_ALPHA8UI_EXT
:
362 case GL_ALPHA16UI_EXT
:
363 case GL_ALPHA32UI_EXT
:
365 case GL_ALPHA16I_EXT
:
366 case GL_ALPHA32I_EXT
:
368 case GL_INTENSITY8UI_EXT
:
369 case GL_INTENSITY16UI_EXT
:
370 case GL_INTENSITY32UI_EXT
:
371 case GL_INTENSITY8I_EXT
:
372 case GL_INTENSITY16I_EXT
:
373 case GL_INTENSITY32I_EXT
:
375 case GL_LUMINANCE8UI_EXT
:
376 case GL_LUMINANCE16UI_EXT
:
377 case GL_LUMINANCE32UI_EXT
:
378 case GL_LUMINANCE8I_EXT
:
379 case GL_LUMINANCE16I_EXT
:
380 case GL_LUMINANCE32I_EXT
:
382 case GL_LUMINANCE_ALPHA8UI_EXT
:
383 case GL_LUMINANCE_ALPHA16UI_EXT
:
384 case GL_LUMINANCE_ALPHA32UI_EXT
:
385 case GL_LUMINANCE_ALPHA8I_EXT
:
386 case GL_LUMINANCE_ALPHA16I_EXT
:
387 case GL_LUMINANCE_ALPHA32I_EXT
:
388 return GL_LUMINANCE_ALPHA
;
394 if (ctx
->Extensions
.ARB_texture_rg
) {
395 switch (internalFormat
) {
397 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
399 if (!ctx
->Extensions
.ARB_half_float_pixel
)
403 if (!ctx
->Extensions
.ARB_texture_float
)
412 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
418 case GL_COMPRESSED_RED
:
422 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
424 if (!ctx
->Extensions
.ARB_half_float_pixel
)
428 if (!ctx
->Extensions
.ARB_texture_float
)
437 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
443 case GL_COMPRESSED_RG
:
450 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
451 switch (internalFormat
) {
459 if (ctx
->Extensions
.EXT_packed_float
) {
460 switch (internalFormat
) {
461 case GL_R11F_G11F_B10F_EXT
:
468 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
469 switch (internalFormat
) {
470 case GL_DEPTH_COMPONENT32F
:
471 return GL_DEPTH_COMPONENT
;
472 case GL_DEPTH32F_STENCIL8
:
473 return GL_DEPTH_STENCIL
;
479 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
480 switch (internalFormat
) {
481 case GL_COMPRESSED_RED_RGTC1
:
482 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
484 case GL_COMPRESSED_RG_RGTC2
:
485 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
492 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
493 switch (internalFormat
) {
494 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
495 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
497 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
498 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
499 return GL_LUMINANCE_ALPHA
;
505 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
506 switch (internalFormat
) {
507 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
508 return GL_LUMINANCE_ALPHA
;
514 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
515 switch (internalFormat
) {
516 case GL_ETC1_RGB8_OES
:
523 if (_mesa_is_gles3(ctx
)) {
524 switch (internalFormat
) {
525 case GL_COMPRESSED_RGB8_ETC2
:
526 case GL_COMPRESSED_SRGB8_ETC2
:
528 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
529 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
530 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
531 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
533 case GL_COMPRESSED_R11_EAC
:
534 case GL_COMPRESSED_SIGNED_R11_EAC
:
536 case GL_COMPRESSED_RG11_EAC
:
537 case GL_COMPRESSED_SIGNED_RG11_EAC
:
544 if (ctx
->API
== API_OPENGLES
) {
545 switch (internalFormat
) {
546 case GL_PALETTE4_RGB8_OES
:
547 case GL_PALETTE4_R5_G6_B5_OES
:
548 case GL_PALETTE8_RGB8_OES
:
549 case GL_PALETTE8_R5_G6_B5_OES
:
551 case GL_PALETTE4_RGBA8_OES
:
552 case GL_PALETTE8_RGB5_A1_OES
:
553 case GL_PALETTE4_RGBA4_OES
:
554 case GL_PALETTE4_RGB5_A1_OES
:
555 case GL_PALETTE8_RGBA8_OES
:
556 case GL_PALETTE8_RGBA4_OES
:
563 return -1; /* error */
568 * For cube map faces, return a face index in [0,5].
569 * For other targets return 0;
572 _mesa_tex_target_to_face(GLenum target
)
574 if (_mesa_is_cube_face(target
))
575 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
583 * Install gl_texture_image in a gl_texture_object according to the target
584 * and level parameters.
586 * \param tObj texture object.
587 * \param target texture target.
588 * \param level image level.
589 * \param texImage texture image.
592 set_tex_image(struct gl_texture_object
*tObj
,
593 GLenum target
, GLint level
,
594 struct gl_texture_image
*texImage
)
596 const GLuint face
= _mesa_tex_target_to_face(target
);
600 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
603 tObj
->Image
[face
][level
] = texImage
;
605 /* Set the 'back' pointer */
606 texImage
->TexObject
= tObj
;
607 texImage
->Level
= level
;
608 texImage
->Face
= face
;
613 * Allocate a texture image structure.
615 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
618 * \return a pointer to gl_texture_image struct with all fields initialized to
621 struct gl_texture_image
*
622 _mesa_new_texture_image( struct gl_context
*ctx
)
625 return CALLOC_STRUCT(gl_texture_image
);
630 * Free a gl_texture_image and associated data.
631 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
633 * \param texImage texture image.
635 * Free the texture image structure and the associated image data.
638 _mesa_delete_texture_image(struct gl_context
*ctx
,
639 struct gl_texture_image
*texImage
)
641 /* Free texImage->Data and/or any other driver-specific texture
644 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
645 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
651 * Test if a target is a proxy target.
653 * \param target texture target.
655 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
658 _mesa_is_proxy_texture(GLenum target
)
661 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
662 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
664 assert(NUM_TEXTURE_TARGETS
== 10 + 2);
666 return (target
== GL_PROXY_TEXTURE_1D
||
667 target
== GL_PROXY_TEXTURE_2D
||
668 target
== GL_PROXY_TEXTURE_3D
||
669 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
670 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
671 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
672 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
673 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
674 target
== GL_PROXY_TEXTURE_2D_MULTISAMPLE
||
675 target
== GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
);
680 * Return the proxy target which corresponds to the given texture target
683 _mesa_get_proxy_target(GLenum target
)
687 case GL_PROXY_TEXTURE_1D
:
688 return GL_PROXY_TEXTURE_1D
;
690 case GL_PROXY_TEXTURE_2D
:
691 return GL_PROXY_TEXTURE_2D
;
693 case GL_PROXY_TEXTURE_3D
:
694 return GL_PROXY_TEXTURE_3D
;
695 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
696 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
697 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
698 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
699 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
700 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
701 case GL_TEXTURE_CUBE_MAP_ARB
:
702 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
703 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
704 case GL_TEXTURE_RECTANGLE_NV
:
705 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
706 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
707 case GL_TEXTURE_1D_ARRAY_EXT
:
708 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
709 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
710 case GL_TEXTURE_2D_ARRAY_EXT
:
711 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
712 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
713 case GL_TEXTURE_CUBE_MAP_ARRAY
:
714 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
715 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
716 case GL_TEXTURE_2D_MULTISAMPLE
:
717 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
718 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
719 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
720 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
721 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
723 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
730 * Get the texture object that corresponds to the target of the given
731 * texture unit. The target should have already been checked for validity.
733 * \param ctx GL context.
734 * \param texUnit texture unit.
735 * \param target texture target.
737 * \return pointer to the texture object on success, or NULL on failure.
739 struct gl_texture_object
*
740 _mesa_select_tex_object(struct gl_context
*ctx
,
741 const struct gl_texture_unit
*texUnit
,
744 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
745 ctx
->Extensions
.EXT_texture_array
);
749 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
750 case GL_PROXY_TEXTURE_1D
:
751 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
753 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
754 case GL_PROXY_TEXTURE_2D
:
755 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
757 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
758 case GL_PROXY_TEXTURE_3D
:
759 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
760 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
761 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
762 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
763 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
764 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
765 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
766 case GL_TEXTURE_CUBE_MAP_ARB
:
767 return ctx
->Extensions
.ARB_texture_cube_map
768 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
769 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
770 return ctx
->Extensions
.ARB_texture_cube_map
771 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
772 case GL_TEXTURE_CUBE_MAP_ARRAY
:
773 return ctx
->Extensions
.ARB_texture_cube_map_array
774 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
775 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
776 return ctx
->Extensions
.ARB_texture_cube_map_array
777 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
778 case GL_TEXTURE_RECTANGLE_NV
:
779 return ctx
->Extensions
.NV_texture_rectangle
780 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
781 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
782 return ctx
->Extensions
.NV_texture_rectangle
783 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
784 case GL_TEXTURE_1D_ARRAY_EXT
:
785 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
786 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
787 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
788 case GL_TEXTURE_2D_ARRAY_EXT
:
789 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
790 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
791 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
792 case GL_TEXTURE_BUFFER
:
793 return ctx
->API
== API_OPENGL_CORE
&&
794 ctx
->Extensions
.ARB_texture_buffer_object
?
795 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
796 case GL_TEXTURE_EXTERNAL_OES
:
797 return ctx
->Extensions
.OES_EGL_image_external
798 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
799 case GL_TEXTURE_2D_MULTISAMPLE
:
800 return ctx
->Extensions
.ARB_texture_multisample
801 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
802 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
803 return ctx
->Extensions
.ARB_texture_multisample
804 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
805 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
806 return ctx
->Extensions
.ARB_texture_multisample
807 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
808 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
809 return ctx
->Extensions
.ARB_texture_multisample
810 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
812 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
819 * Return pointer to texture object for given target on current texture unit.
821 struct gl_texture_object
*
822 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
824 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
825 return _mesa_select_tex_object(ctx
, texUnit
, target
);
830 * Get a texture image pointer from a texture object, given a texture
831 * target and mipmap level. The target and level parameters should
832 * have already been error-checked.
834 * \param ctx GL context.
835 * \param texObj texture unit.
836 * \param target texture target.
837 * \param level image level.
839 * \return pointer to the texture image structure, or NULL on failure.
841 struct gl_texture_image
*
842 _mesa_select_tex_image(struct gl_context
*ctx
,
843 const struct gl_texture_object
*texObj
,
844 GLenum target
, GLint level
)
846 const GLuint face
= _mesa_tex_target_to_face(target
);
850 ASSERT(level
< MAX_TEXTURE_LEVELS
);
852 return texObj
->Image
[face
][level
];
857 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
858 * it and install it. Only return NULL if passed a bad parameter or run
861 struct gl_texture_image
*
862 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
863 GLenum target
, GLint level
)
865 struct gl_texture_image
*texImage
;
870 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
872 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
874 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
878 set_tex_image(texObj
, target
, level
, texImage
);
886 * Return pointer to the specified proxy texture image.
887 * Note that proxy textures are per-context, not per-texture unit.
888 * \return pointer to texture image or NULL if invalid target, invalid
889 * level, or out of memory.
891 static struct gl_texture_image
*
892 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
894 struct gl_texture_image
*texImage
;
901 case GL_PROXY_TEXTURE_1D
:
902 if (level
>= ctx
->Const
.MaxTextureLevels
)
904 texIndex
= TEXTURE_1D_INDEX
;
906 case GL_PROXY_TEXTURE_2D
:
907 if (level
>= ctx
->Const
.MaxTextureLevels
)
909 texIndex
= TEXTURE_2D_INDEX
;
911 case GL_PROXY_TEXTURE_3D
:
912 if (level
>= ctx
->Const
.Max3DTextureLevels
)
914 texIndex
= TEXTURE_3D_INDEX
;
916 case GL_PROXY_TEXTURE_CUBE_MAP
:
917 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
919 texIndex
= TEXTURE_CUBE_INDEX
;
921 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
924 texIndex
= TEXTURE_RECT_INDEX
;
926 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
927 if (level
>= ctx
->Const
.MaxTextureLevels
)
929 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
931 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
932 if (level
>= ctx
->Const
.MaxTextureLevels
)
934 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
936 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
937 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
939 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
941 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
944 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
946 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
949 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
955 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
957 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
959 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
962 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
963 /* Set the 'back' pointer */
964 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
971 * Get the maximum number of allowed mipmap levels.
973 * \param ctx GL context.
974 * \param target texture target.
976 * \return the maximum number of allowed mipmap levels for the given
977 * texture target, or zero if passed a bad target.
982 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
986 case GL_PROXY_TEXTURE_1D
:
988 case GL_PROXY_TEXTURE_2D
:
989 return ctx
->Const
.MaxTextureLevels
;
991 case GL_PROXY_TEXTURE_3D
:
992 return ctx
->Const
.Max3DTextureLevels
;
993 case GL_TEXTURE_CUBE_MAP
:
994 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
995 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
996 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
997 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
998 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
999 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1000 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1001 return ctx
->Extensions
.ARB_texture_cube_map
1002 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1003 case GL_TEXTURE_RECTANGLE_NV
:
1004 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1005 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
1006 case GL_TEXTURE_1D_ARRAY_EXT
:
1007 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1008 case GL_TEXTURE_2D_ARRAY_EXT
:
1009 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1010 return (ctx
->Extensions
.MESA_texture_array
||
1011 ctx
->Extensions
.EXT_texture_array
)
1012 ? ctx
->Const
.MaxTextureLevels
: 0;
1013 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1014 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1015 return ctx
->Extensions
.ARB_texture_cube_map_array
1016 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1017 case GL_TEXTURE_BUFFER
:
1018 return ctx
->API
== API_OPENGL_CORE
&&
1019 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1020 case GL_TEXTURE_2D_MULTISAMPLE
:
1021 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1022 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1023 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1024 return _mesa_is_desktop_gl(ctx
)
1025 && ctx
->Extensions
.ARB_texture_multisample
1027 case GL_TEXTURE_EXTERNAL_OES
:
1030 return 0; /* bad target */
1036 * Return number of dimensions per mipmap level for the given texture target.
1039 _mesa_get_texture_dimensions(GLenum target
)
1043 case GL_PROXY_TEXTURE_1D
:
1046 case GL_TEXTURE_RECTANGLE
:
1047 case GL_TEXTURE_CUBE_MAP
:
1048 case GL_PROXY_TEXTURE_2D
:
1049 case GL_PROXY_TEXTURE_RECTANGLE
:
1050 case GL_PROXY_TEXTURE_CUBE_MAP
:
1051 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1052 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1053 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1054 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1055 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1056 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1057 case GL_TEXTURE_1D_ARRAY
:
1058 case GL_PROXY_TEXTURE_1D_ARRAY
:
1059 case GL_TEXTURE_EXTERNAL_OES
:
1060 case GL_TEXTURE_2D_MULTISAMPLE
:
1061 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1064 case GL_PROXY_TEXTURE_3D
:
1065 case GL_TEXTURE_2D_ARRAY
:
1066 case GL_PROXY_TEXTURE_2D_ARRAY
:
1067 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1068 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1069 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1070 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1072 case GL_TEXTURE_BUFFER
:
1075 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1083 * Return the maximum number of mipmap levels for the given target
1084 * and the dimensions.
1085 * The dimensions are expected not to include the border.
1088 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1095 case GL_TEXTURE_1D_ARRAY
:
1098 case GL_TEXTURE_CUBE_MAP
:
1099 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1100 ASSERT(width
== height
);
1104 case GL_TEXTURE_2D_ARRAY
:
1105 size
= MAX2(width
, height
);
1108 size
= MAX3(width
, height
, depth
);
1110 case GL_TEXTURE_RECTANGLE
:
1111 case GL_TEXTURE_EXTERNAL_OES
:
1112 case GL_TEXTURE_2D_MULTISAMPLE
:
1113 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1120 return _mesa_logbase2(size
) + 1;
1124 #if 000 /* not used anymore */
1126 * glTexImage[123]D can accept a NULL image pointer. In this case we
1127 * create a texture image with unspecified image contents per the OpenGL
1131 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1133 const GLint components
= _mesa_components_in_format(format
);
1134 const GLint numPixels
= width
* height
* depth
;
1135 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1139 * Let's see if anyone finds this. If glTexImage2D() is called with
1140 * a NULL image pointer then load the texture image with something
1141 * interesting instead of leaving it indeterminate.
1144 static const char message
[8][32] = {
1145 " X X XXXXX XXX X ",
1146 " XX XX X X X X X ",
1148 " X X XXXX XXX XXXXX ",
1151 " X X XXXXX XXX X X ",
1155 GLubyte
*imgPtr
= data
;
1157 for (h
= 0; h
< depth
; h
++) {
1158 for (i
= 0; i
< height
; i
++) {
1159 GLint srcRow
= 7 - (i
% 8);
1160 for (j
= 0; j
< width
; j
++) {
1161 GLint srcCol
= j
% 32;
1162 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1163 for (k
= 0; k
< components
; k
++) {
1179 * Set the size and format-related fields of a gl_texture_image struct
1180 * to zero. This is used when a proxy texture test fails.
1183 clear_teximage_fields(struct gl_texture_image
*img
)
1186 img
->_BaseFormat
= 0;
1187 img
->InternalFormat
= 0;
1196 img
->HeightLog2
= 0;
1198 img
->TexFormat
= MESA_FORMAT_NONE
;
1199 img
->NumSamples
= 0;
1200 img
->FixedSampleLocations
= GL_TRUE
;
1205 * Initialize basic fields of the gl_texture_image struct.
1207 * \param ctx GL context.
1208 * \param img texture image structure to be initialized.
1209 * \param width image width.
1210 * \param height image height.
1211 * \param depth image depth.
1212 * \param border image border.
1213 * \param internalFormat internal format.
1214 * \param format the actual hardware format (one of MESA_FORMAT_*)
1216 * Fills in the fields of \p img with the given information.
1217 * Note: width, height and depth include the border.
1220 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1221 struct gl_texture_image
*img
,
1222 GLsizei width
, GLsizei height
, GLsizei depth
,
1223 GLint border
, GLenum internalFormat
,
1229 ASSERT(height
>= 0);
1232 target
= img
->TexObject
->Target
;
1233 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1234 ASSERT(img
->_BaseFormat
> 0);
1235 img
->InternalFormat
= internalFormat
;
1236 img
->Border
= border
;
1238 img
->Height
= height
;
1241 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1242 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1244 img
->NumSamples
= 0;
1245 img
->FixedSampleLocations
= GL_TRUE
;
1249 case GL_TEXTURE_BUFFER
:
1250 case GL_PROXY_TEXTURE_1D
:
1255 img
->HeightLog2
= 0;
1262 case GL_TEXTURE_1D_ARRAY
:
1263 case GL_PROXY_TEXTURE_1D_ARRAY
:
1264 img
->Height2
= height
; /* no border */
1265 img
->HeightLog2
= 0; /* not used */
1273 case GL_TEXTURE_RECTANGLE
:
1274 case GL_TEXTURE_CUBE_MAP
:
1275 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1276 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1277 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1278 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1279 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1280 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1281 case GL_TEXTURE_EXTERNAL_OES
:
1282 case GL_PROXY_TEXTURE_2D
:
1283 case GL_PROXY_TEXTURE_RECTANGLE
:
1284 case GL_PROXY_TEXTURE_CUBE_MAP
:
1285 case GL_TEXTURE_2D_MULTISAMPLE
:
1286 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1287 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1288 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1295 case GL_TEXTURE_2D_ARRAY
:
1296 case GL_PROXY_TEXTURE_2D_ARRAY
:
1297 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1298 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1299 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1300 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1301 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1302 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1303 img
->Depth2
= depth
; /* no border */
1304 img
->DepthLog2
= 0; /* not used */
1307 case GL_PROXY_TEXTURE_3D
:
1308 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1309 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1310 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1311 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1314 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1319 _mesa_get_tex_max_num_levels(target
,
1320 img
->Width2
, img
->Height2
, img
->Depth2
);
1321 img
->TexFormat
= format
;
1326 * Free and clear fields of the gl_texture_image struct.
1328 * \param ctx GL context.
1329 * \param texImage texture image structure to be cleared.
1331 * After the call, \p texImage will have no data associated with it. Its
1332 * fields are cleared so that its parent object will test incomplete.
1335 _mesa_clear_texture_image(struct gl_context
*ctx
,
1336 struct gl_texture_image
*texImage
)
1338 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1339 clear_teximage_fields(texImage
);
1344 * Check the width, height, depth and border of a texture image are legal.
1345 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1347 * The target and level parameters will have already been validated.
1348 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1351 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1352 GLint level
, GLint width
, GLint height
,
1353 GLint depth
, GLint border
)
1359 case GL_PROXY_TEXTURE_1D
:
1360 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1361 maxSize
>>= level
; /* level size */
1362 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1364 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1365 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1371 case GL_PROXY_TEXTURE_2D
:
1372 case GL_TEXTURE_2D_MULTISAMPLE
:
1373 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1374 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1376 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1378 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1380 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1381 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1383 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1389 case GL_PROXY_TEXTURE_3D
:
1390 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1392 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1394 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1396 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1398 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1399 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1401 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1403 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1408 case GL_TEXTURE_RECTANGLE_NV
:
1409 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1412 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1413 if (width
< 0 || width
> maxSize
)
1415 if (height
< 0 || height
> maxSize
)
1419 case GL_TEXTURE_CUBE_MAP
:
1420 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1421 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1422 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1423 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1424 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1425 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1426 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1427 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1429 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1431 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1433 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1434 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1436 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1441 case GL_TEXTURE_1D_ARRAY_EXT
:
1442 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1443 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1445 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1447 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1449 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1450 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1455 case GL_TEXTURE_2D_ARRAY_EXT
:
1456 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1457 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1458 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1459 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1461 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1463 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1465 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1467 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1468 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1470 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1475 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1476 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1477 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1478 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1480 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1482 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1484 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
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 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1501 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1502 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1503 * \param destImage the destination texture image.
1504 * \return GL_TRUE if error found, GL_FALSE otherwise.
1507 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1508 const char *function
, GLuint dims
,
1509 const struct gl_texture_image
*destImage
,
1510 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1511 GLsizei subWidth
, GLsizei subHeight
,
1514 const GLenum target
= destImage
->TexObject
->Target
;
1519 _mesa_error(ctx
, GL_INVALID_VALUE
,
1520 "%s%dD(width=%d)", function
, dims
, subWidth
);
1524 if (dims
> 1 && subHeight
< 0) {
1525 _mesa_error(ctx
, GL_INVALID_VALUE
,
1526 "%s%dD(height=%d)", function
, dims
, subHeight
);
1530 if (dims
> 2 && subDepth
< 0) {
1531 _mesa_error(ctx
, GL_INVALID_VALUE
,
1532 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1536 /* check xoffset and width */
1537 if (xoffset
< -destImage
->Border
) {
1538 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1543 if (xoffset
+ subWidth
> destImage
->Width
) {
1544 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1549 /* check yoffset and height */
1551 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1552 if (yoffset
< -yBorder
) {
1553 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1557 if (yoffset
+ subHeight
> destImage
->Height
) {
1558 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1564 /* check zoffset and depth */
1566 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1567 if (zoffset
< -zBorder
) {
1568 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1571 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1572 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1578 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1579 * compressed texture images can be updated. But, that restriction may be
1580 * relaxed for particular compressed formats. At this time, all the
1581 * compressed formats supported by Mesa allow sub-textures to be updated
1582 * along compressed block boundaries.
1584 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1586 if (bw
!= 1 || bh
!= 1) {
1587 /* offset must be multiple of block size */
1588 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1589 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1590 "%s%dD(xoffset = %d, yoffset = %d)",
1591 function
, dims
, xoffset
, yoffset
);
1595 /* size must be multiple of bw by bh or equal to whole texture size */
1596 if ((subWidth
% bw
!= 0) && subWidth
!= destImage
->Width
) {
1597 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1598 "%s%dD(width = %d)", function
, dims
, subWidth
);
1602 if ((subHeight
% bh
!= 0) && subHeight
!= destImage
->Height
) {
1603 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1604 "%s%dD(height = %d)", function
, dims
, subHeight
);
1616 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1617 * specific texture image size checks.
1619 * A hardware driver might override this function if, for example, the
1620 * max 3D texture size is 512x512x64 (i.e. not a cube).
1622 * Note that width, height, depth == 0 is not an error. However, a
1623 * texture with zero width/height/depth will be considered "incomplete"
1624 * and texturing will effectively be disabled.
1626 * \param target any texture target/type
1627 * \param level as passed to glTexImage
1628 * \param format the MESA_FORMAT_x for the tex image
1629 * \param width as passed to glTexImage
1630 * \param height as passed to glTexImage
1631 * \param depth as passed to glTexImage
1632 * \param border as passed to glTexImage
1633 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1636 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1638 GLint width
, GLint height
, GLint depth
, GLint border
)
1640 /* We just check if the image size is less than MaxTextureMbytes.
1641 * Some drivers may do more specific checks.
1643 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1644 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1645 mbytes
*= _mesa_num_tex_faces(target
);
1646 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1651 * Return true if the format is only valid for glCompressedTexImage.
1654 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1657 case GL_ETC1_RGB8_OES
:
1658 case GL_PALETTE4_RGB8_OES
:
1659 case GL_PALETTE4_RGBA8_OES
:
1660 case GL_PALETTE4_R5_G6_B5_OES
:
1661 case GL_PALETTE4_RGBA4_OES
:
1662 case GL_PALETTE4_RGB5_A1_OES
:
1663 case GL_PALETTE8_RGB8_OES
:
1664 case GL_PALETTE8_RGBA8_OES
:
1665 case GL_PALETTE8_R5_G6_B5_OES
:
1666 case GL_PALETTE8_RGBA4_OES
:
1667 case GL_PALETTE8_RGB5_A1_OES
:
1676 * Helper function to determine whether a target and specific compression
1677 * format are supported.
1680 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1683 (void) intFormat
; /* not used yet */
1687 case GL_PROXY_TEXTURE_2D
:
1688 return GL_TRUE
; /* true for any compressed format so far */
1689 case GL_PROXY_TEXTURE_CUBE_MAP
:
1690 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1691 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1692 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1693 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1694 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1695 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1696 return ctx
->Extensions
.ARB_texture_cube_map
;
1697 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1698 case GL_TEXTURE_2D_ARRAY_EXT
:
1699 return (ctx
->Extensions
.MESA_texture_array
||
1700 ctx
->Extensions
.EXT_texture_array
);
1701 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1702 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1703 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1711 * Check if the given texture target value is legal for a
1712 * glTexImage1/2/3D call.
1715 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1721 case GL_PROXY_TEXTURE_1D
:
1722 return _mesa_is_desktop_gl(ctx
);
1730 case GL_PROXY_TEXTURE_2D
:
1731 return _mesa_is_desktop_gl(ctx
);
1732 case GL_PROXY_TEXTURE_CUBE_MAP
:
1733 return _mesa_is_desktop_gl(ctx
)
1734 && ctx
->Extensions
.ARB_texture_cube_map
;
1735 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1736 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1737 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1738 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1739 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1740 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1741 return ctx
->Extensions
.ARB_texture_cube_map
;
1742 case GL_TEXTURE_RECTANGLE_NV
:
1743 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1744 return _mesa_is_desktop_gl(ctx
)
1745 && ctx
->Extensions
.NV_texture_rectangle
;
1746 case GL_TEXTURE_1D_ARRAY_EXT
:
1747 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1748 return _mesa_is_desktop_gl(ctx
)
1749 && (ctx
->Extensions
.MESA_texture_array
||
1750 ctx
->Extensions
.EXT_texture_array
);
1758 case GL_PROXY_TEXTURE_3D
:
1759 return _mesa_is_desktop_gl(ctx
);
1760 case GL_TEXTURE_2D_ARRAY_EXT
:
1761 return (_mesa_is_desktop_gl(ctx
)
1762 && (ctx
->Extensions
.MESA_texture_array
||
1763 ctx
->Extensions
.EXT_texture_array
))
1764 || _mesa_is_gles3(ctx
);
1765 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1766 return _mesa_is_desktop_gl(ctx
)
1767 && (ctx
->Extensions
.MESA_texture_array
||
1768 ctx
->Extensions
.EXT_texture_array
);
1769 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1770 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1771 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1776 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1783 * Check if the given texture target value is legal for a
1784 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1785 * The difference compared to legal_teximage_target() above is that
1786 * proxy targets are not supported.
1789 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1793 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1798 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1799 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1800 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1801 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1802 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1803 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1804 return ctx
->Extensions
.ARB_texture_cube_map
;
1805 case GL_TEXTURE_RECTANGLE_NV
:
1806 return _mesa_is_desktop_gl(ctx
)
1807 && ctx
->Extensions
.NV_texture_rectangle
;
1808 case GL_TEXTURE_1D_ARRAY_EXT
:
1809 return _mesa_is_desktop_gl(ctx
)
1810 && (ctx
->Extensions
.MESA_texture_array
||
1811 ctx
->Extensions
.EXT_texture_array
);
1819 case GL_TEXTURE_2D_ARRAY_EXT
:
1820 return (_mesa_is_desktop_gl(ctx
)
1821 && (ctx
->Extensions
.MESA_texture_array
||
1822 ctx
->Extensions
.EXT_texture_array
))
1823 || _mesa_is_gles3(ctx
);
1824 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1825 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1826 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1831 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1839 * Helper function to determine if a texture object is mutable (in terms
1840 * of GL_ARB_texture_storage).
1843 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1845 if (ctx
->Extensions
.ARB_texture_storage
) {
1846 struct gl_texture_object
*texObj
=
1847 _mesa_get_current_tex_object(ctx
, target
);
1848 return !texObj
->Immutable
;
1855 * Return expected size of a compressed texture.
1858 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1861 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1862 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1867 * Test the glTexImage[123]D() parameters for errors.
1869 * \param ctx GL context.
1870 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1871 * \param target texture target given by the user (already validated).
1872 * \param level image level given by the user.
1873 * \param internalFormat internal format given by the user.
1874 * \param format pixel data format given by the user.
1875 * \param type pixel data type given by the user.
1876 * \param width image width given by the user.
1877 * \param height image height given by the user.
1878 * \param depth image depth given by the user.
1879 * \param border image border given by the user.
1881 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1883 * Verifies each of the parameters against the constants specified in
1884 * __struct gl_contextRec::Const and the supported extensions, and according
1885 * to the OpenGL specification.
1886 * Note that we don't fully error-check the width, height, depth values
1887 * here. That's done in _mesa_legal_texture_dimensions() which is used
1888 * by several other GL entrypoints. Plus, texture dims have a special
1889 * interaction with proxy textures.
1892 texture_error_check( struct gl_context
*ctx
,
1893 GLuint dimensions
, GLenum target
,
1894 GLint level
, GLint internalFormat
,
1895 GLenum format
, GLenum type
,
1896 GLint width
, GLint height
,
1897 GLint depth
, GLint border
)
1899 GLboolean colorFormat
;
1902 /* Even though there are no color-index textures, we still have to support
1903 * uploading color-index data and remapping it to RGB via the
1904 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1906 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1908 /* Note: for proxy textures, some error conditions immediately generate
1909 * a GL error in the usual way. But others do not generate a GL error.
1910 * Instead, they cause the width, height, depth, format fields of the
1911 * texture image to be zeroed-out. The GL spec seems to indicate that the
1912 * zero-out behaviour is only used in cases related to memory allocation.
1916 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1917 _mesa_error(ctx
, GL_INVALID_VALUE
,
1918 "glTexImage%dD(level=%d)", dimensions
, level
);
1923 if (border
< 0 || border
> 1 ||
1924 ((ctx
->API
!= API_OPENGL_COMPAT
||
1925 target
== GL_TEXTURE_RECTANGLE_NV
||
1926 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1927 _mesa_error(ctx
, GL_INVALID_VALUE
,
1928 "glTexImage%dD(border=%d)", dimensions
, border
);
1932 if (width
< 0 || height
< 0 || depth
< 0) {
1933 _mesa_error(ctx
, GL_INVALID_VALUE
,
1934 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1938 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1939 * combinations of format, internalFormat, and type that can be used.
1940 * Formats and types that require additional extensions (e.g., GL_FLOAT
1941 * requires GL_OES_texture_float) are filtered elsewhere.
1944 if (_mesa_is_gles(ctx
)) {
1945 if (_mesa_is_gles3(ctx
)) {
1946 err
= _mesa_es3_error_check_format_and_type(format
, type
,
1949 if (format
!= internalFormat
) {
1950 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1951 "glTexImage%dD(format = %s, internalFormat = %s)",
1953 _mesa_lookup_enum_by_nr(format
),
1954 _mesa_lookup_enum_by_nr(internalFormat
));
1958 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1960 if (err
!= GL_NO_ERROR
) {
1961 _mesa_error(ctx
, err
,
1962 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
1964 _mesa_lookup_enum_by_nr(format
),
1965 _mesa_lookup_enum_by_nr(type
),
1966 _mesa_lookup_enum_by_nr(internalFormat
));
1971 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1972 _mesa_is_cube_face(target
)) && width
!= height
) {
1973 _mesa_error(ctx
, GL_INVALID_VALUE
,
1974 "glTexImage2D(cube width != height)");
1978 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1979 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && width
!= height
) {
1980 _mesa_error(ctx
, GL_INVALID_VALUE
,
1981 "glTexImage3D(cube array width != height)");
1985 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1986 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && (depth
% 6)) {
1987 _mesa_error(ctx
, GL_INVALID_VALUE
,
1988 "glTexImage3D(cube array depth not multiple of 6)");
1992 /* Check internalFormat */
1993 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1994 _mesa_error(ctx
, GL_INVALID_VALUE
,
1995 "glTexImage%dD(internalFormat=%s)",
1996 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2000 /* Check incoming image format and type */
2001 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2002 if (err
!= GL_NO_ERROR
) {
2003 _mesa_error(ctx
, err
,
2004 "glTexImage%dD(incompatible format = %s, type = %s)",
2005 dimensions
, _mesa_lookup_enum_by_nr(format
),
2006 _mesa_lookup_enum_by_nr(type
));
2010 /* make sure internal format and format basically agree */
2011 colorFormat
= _mesa_is_color_format(format
);
2012 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2013 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2014 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2015 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2016 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2017 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2018 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2019 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2020 _mesa_lookup_enum_by_nr(format
));
2024 /* additional checks for ycbcr textures */
2025 if (internalFormat
== GL_YCBCR_MESA
) {
2026 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2027 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2028 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2030 _mesa_snprintf(message
, sizeof(message
),
2031 "glTexImage%dD(format/type YCBCR mismatch)",
2033 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2034 return GL_TRUE
; /* error */
2036 if (target
!= GL_TEXTURE_2D
&&
2037 target
!= GL_PROXY_TEXTURE_2D
&&
2038 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2039 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2040 _mesa_error(ctx
, GL_INVALID_ENUM
,
2041 "glTexImage%dD(bad target for YCbCr texture)",
2047 _mesa_snprintf(message
, sizeof(message
),
2048 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2049 dimensions
, border
);
2050 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2055 /* additional checks for depth textures */
2056 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2057 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2058 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
2059 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
2060 if (target
!= GL_TEXTURE_1D
&&
2061 target
!= GL_PROXY_TEXTURE_1D
&&
2062 target
!= GL_TEXTURE_2D
&&
2063 target
!= GL_PROXY_TEXTURE_2D
&&
2064 target
!= GL_TEXTURE_1D_ARRAY
&&
2065 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2066 target
!= GL_TEXTURE_2D_ARRAY
&&
2067 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2068 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2069 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2070 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2071 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2072 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2073 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2074 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2075 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2076 _mesa_error(ctx
, GL_INVALID_ENUM
,
2077 "glTexImage%dD(bad target for depth texture)",
2083 /* additional checks for compressed textures */
2084 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2085 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2086 _mesa_error(ctx
, GL_INVALID_ENUM
,
2087 "glTexImage%dD(target can't be compressed)", dimensions
);
2090 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2091 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2092 "glTexImage%dD(no compression for format)", dimensions
);
2096 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2097 "glTexImage%dD(border!=0)", dimensions
);
2102 /* additional checks for integer textures */
2103 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2104 (_mesa_is_enum_format_integer(format
) !=
2105 _mesa_is_enum_format_integer(internalFormat
))) {
2106 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2107 "glTexImage%dD(integer/non-integer format mismatch)",
2112 if (!mutable_tex_object(ctx
, target
)) {
2113 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2114 "glTexImage%dD(immutable texture)", dimensions
);
2118 /* if we get here, the parameters are OK */
2124 * Error checking for glCompressedTexImage[123]D().
2125 * Note that the width, height and depth values are not fully error checked
2127 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2130 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2131 GLenum target
, GLint level
,
2132 GLenum internalFormat
, GLsizei width
,
2133 GLsizei height
, GLsizei depth
, GLint border
,
2136 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2138 GLenum error
= GL_NO_ERROR
;
2139 char *reason
= ""; /* no error */
2141 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2143 error
= GL_INVALID_ENUM
;
2147 /* This will detect any invalid internalFormat value */
2148 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2149 reason
= "internalFormat";
2150 error
= GL_INVALID_ENUM
;
2154 switch (internalFormat
) {
2155 case GL_PALETTE4_RGB8_OES
:
2156 case GL_PALETTE4_RGBA8_OES
:
2157 case GL_PALETTE4_R5_G6_B5_OES
:
2158 case GL_PALETTE4_RGBA4_OES
:
2159 case GL_PALETTE4_RGB5_A1_OES
:
2160 case GL_PALETTE8_RGB8_OES
:
2161 case GL_PALETTE8_RGBA8_OES
:
2162 case GL_PALETTE8_R5_G6_B5_OES
:
2163 case GL_PALETTE8_RGBA4_OES
:
2164 case GL_PALETTE8_RGB5_A1_OES
:
2165 /* check level (note that level should be zero or less!) */
2166 if (level
> 0 || level
< -maxLevels
) {
2168 error
= GL_INVALID_VALUE
;
2172 if (dimensions
!= 2) {
2173 reason
= "compressed paletted textures must be 2D";
2174 error
= GL_INVALID_OPERATION
;
2178 /* Figure out the expected texture size (in bytes). This will be
2179 * checked against the actual size later.
2181 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2184 /* This is for the benefit of the TestProxyTexImage below. It expects
2185 * level to be non-negative. OES_compressed_paletted_texture uses a
2186 * weird mechanism where the level specified to glCompressedTexImage2D
2187 * is -(n-1) number of levels in the texture, and the data specifies the
2188 * complete mipmap stack. This is done to ensure the palette is the
2189 * same for all levels.
2196 if (level
< 0 || level
>= maxLevels
) {
2198 error
= GL_INVALID_VALUE
;
2202 /* Figure out the expected texture size (in bytes). This will be
2203 * checked against the actual size later.
2205 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2209 /* This should really never fail */
2210 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2211 reason
= "internalFormat";
2212 error
= GL_INVALID_ENUM
;
2216 /* No compressed formats support borders at this time */
2218 reason
= "border != 0";
2219 error
= GL_INVALID_VALUE
;
2223 /* For cube map, width must equal height */
2224 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2225 _mesa_is_cube_face(target
)) && width
!= height
) {
2226 reason
= "width != height";
2227 error
= GL_INVALID_VALUE
;
2231 /* check image size in bytes */
2232 if (expectedSize
!= imageSize
) {
2233 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2234 * if <imageSize> is not consistent with the format, dimensions, and
2235 * contents of the specified image.
2237 reason
= "imageSize inconsistant with width/height/format";
2238 error
= GL_INVALID_VALUE
;
2242 if (!mutable_tex_object(ctx
, target
)) {
2243 reason
= "immutable texture";
2244 error
= GL_INVALID_OPERATION
;
2251 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2258 * Test glTexSubImage[123]D() parameters for errors.
2260 * \param ctx GL context.
2261 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2262 * \param target texture target given by the user (already validated)
2263 * \param level image level given by the user.
2264 * \param xoffset sub-image x offset given by the user.
2265 * \param yoffset sub-image y offset given by the user.
2266 * \param zoffset sub-image z offset given by the user.
2267 * \param format pixel data format given by the user.
2268 * \param type pixel data type given by the user.
2269 * \param width image width given by the user.
2270 * \param height image height given by the user.
2271 * \param depth image depth given by the user.
2273 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2275 * Verifies each of the parameters against the constants specified in
2276 * __struct gl_contextRec::Const and the supported extensions, and according
2277 * to the OpenGL specification.
2280 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2281 GLenum target
, GLint level
,
2282 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2283 GLint width
, GLint height
, GLint depth
,
2284 GLenum format
, GLenum type
)
2286 struct gl_texture_object
*texObj
;
2287 struct gl_texture_image
*texImage
;
2290 /* check target (proxies not allowed) */
2291 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2292 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2293 dimensions
, _mesa_lookup_enum_by_nr(target
));
2298 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2299 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2304 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2305 * combinations of format and type that can be used. Formats and types
2306 * that require additional extensions (e.g., GL_FLOAT requires
2307 * GL_OES_texture_float) are filtered elsewhere.
2309 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2310 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2311 if (err
!= GL_NO_ERROR
) {
2312 _mesa_error(ctx
, err
,
2313 "glTexSubImage%dD(format = %s, type = %s)",
2315 _mesa_lookup_enum_by_nr(format
),
2316 _mesa_lookup_enum_by_nr(type
));
2321 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2322 if (err
!= GL_NO_ERROR
) {
2323 _mesa_error(ctx
, err
,
2324 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2325 dimensions
, _mesa_lookup_enum_by_nr(format
),
2326 _mesa_lookup_enum_by_nr(type
));
2330 /* Get dest texture object / image pointers */
2331 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2333 /* must be out of memory */
2334 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2338 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2340 /* non-existant texture level */
2341 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2342 "glTexSubImage%dD(invalid texture image)", dimensions
);
2346 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2347 texImage
, xoffset
, yoffset
, 0,
2348 width
, height
, 1)) {
2352 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2353 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2354 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2355 "glTexSubImage%dD(no compression for format)", dimensions
);
2360 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2361 /* both source and dest must be integer-valued, or neither */
2362 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2363 _mesa_is_enum_format_integer(format
)) {
2364 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2365 "glTexSubImage%dD(integer/non-integer format mismatch)",
2376 * Test glCopyTexImage[12]D() parameters for errors.
2378 * \param ctx GL context.
2379 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2380 * \param target texture target given by the user.
2381 * \param level image level given by the user.
2382 * \param internalFormat internal format given by the user.
2383 * \param width image width given by the user.
2384 * \param height image height given by the user.
2385 * \param border texture border.
2387 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2389 * Verifies each of the parameters against the constants specified in
2390 * __struct gl_contextRec::Const and the supported extensions, and according
2391 * to the OpenGL specification.
2394 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2395 GLenum target
, GLint level
, GLint internalFormat
,
2396 GLint width
, GLint height
, GLint border
)
2399 GLint rb_base_format
;
2400 struct gl_renderbuffer
*rb
;
2401 GLenum rb_internal_format
;
2404 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2405 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2406 dimensions
, _mesa_lookup_enum_by_nr(target
));
2411 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2412 _mesa_error(ctx
, GL_INVALID_VALUE
,
2413 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2417 /* Check that the source buffer is complete */
2418 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2419 if (ctx
->ReadBuffer
->_Status
== 0) {
2420 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2422 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2423 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2424 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2428 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2429 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2430 "glCopyTexImage%dD(multisample FBO)",
2437 if (border
< 0 || border
> 1 ||
2438 ((ctx
->API
!= API_OPENGL_COMPAT
||
2439 target
== GL_TEXTURE_RECTANGLE_NV
||
2440 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2441 _mesa_error(ctx
, GL_INVALID_VALUE
,
2442 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2446 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2448 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2449 "glCopyTexImage%dD(read buffer)", dimensions
);
2453 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2456 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2457 switch (internalFormat
) {
2462 case GL_LUMINANCE_ALPHA
:
2465 _mesa_error(ctx
, GL_INVALID_VALUE
,
2466 "glCopyTexImage%dD(internalFormat)", dimensions
);
2471 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2472 if (baseFormat
< 0) {
2473 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2474 "glCopyTexImage%dD(internalFormat)", dimensions
);
2478 rb_internal_format
= rb
->InternalFormat
;
2479 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2480 if (_mesa_is_color_format(internalFormat
)) {
2481 if (rb_base_format
< 0) {
2482 _mesa_error(ctx
, GL_INVALID_VALUE
,
2483 "glCopyTexImage%dD(internalFormat)", dimensions
);
2488 if (_mesa_is_gles(ctx
)) {
2490 if (_mesa_base_format_component_count(baseFormat
) >
2491 _mesa_base_format_component_count(rb_base_format
)) {
2494 if (baseFormat
== GL_DEPTH_COMPONENT
||
2495 baseFormat
== GL_DEPTH_STENCIL
||
2496 rb_base_format
== GL_DEPTH_COMPONENT
||
2497 rb_base_format
== GL_DEPTH_STENCIL
||
2498 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2499 baseFormat
== GL_ALPHA
) &&
2500 rb_base_format
!= GL_RGBA
) ||
2501 internalFormat
== GL_RGB9_E5
) {
2504 if (internalFormat
== GL_RGB9_E5
) {
2508 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2509 "glCopyTexImage%dD(internalFormat)", dimensions
);
2514 if (_mesa_is_gles3(ctx
)) {
2515 bool rb_is_srgb
= false;
2516 bool dst_is_srgb
= false;
2518 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2519 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2523 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2527 if (rb_is_srgb
!= dst_is_srgb
) {
2528 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2529 * OpenGLES 3.0.0 spec says:
2531 * "The error INVALID_OPERATION is also generated if the
2532 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2533 * framebuffer attachment corresponding to the read buffer
2534 * is LINEAR (see section 6.1.13) and internalformat is
2535 * one of the sRGB formats described in section 3.8.16, or
2536 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2537 * SRGB and internalformat is not one of the sRGB formats."
2539 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2540 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2545 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2546 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2547 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2551 /* From the EXT_texture_integer spec:
2553 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2554 * if the texture internalformat is an integer format and the read color
2555 * buffer is not an integer format, or if the internalformat is not an
2556 * integer format and the read color buffer is an integer format."
2558 if (_mesa_is_color_format(internalFormat
)) {
2559 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2560 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2561 if (is_int
|| is_rbint
) {
2562 if (is_int
!= is_rbint
) {
2563 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2564 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2566 } else if (_mesa_is_gles(ctx
) &&
2567 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2568 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2569 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2570 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2576 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2577 _mesa_is_cube_face(target
)) && width
!= height
) {
2578 _mesa_error(ctx
, GL_INVALID_VALUE
,
2579 "glTexImage2D(cube width != height)");
2583 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2584 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2585 _mesa_error(ctx
, GL_INVALID_ENUM
,
2586 "glCopyTexImage%dD(target)", dimensions
);
2589 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2590 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2591 "glCopyTexImage%dD(no compression for format)", dimensions
);
2595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2596 "glCopyTexImage%dD(border!=0)", dimensions
);
2601 if (!mutable_tex_object(ctx
, target
)) {
2602 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2603 "glCopyTexImage%dD(immutable texture)", dimensions
);
2607 /* if we get here, the parameters are OK */
2613 * Test glCopyTexSubImage[12]D() parameters for errors.
2614 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2617 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2618 GLenum target
, GLint level
,
2619 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2620 GLint width
, GLint height
)
2622 struct gl_texture_object
*texObj
;
2623 struct gl_texture_image
*texImage
;
2625 /* Check that the source buffer is complete */
2626 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2627 if (ctx
->ReadBuffer
->_Status
== 0) {
2628 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2630 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2631 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2632 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2636 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2637 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2638 "glCopyTexSubImage%dD(multisample FBO)",
2644 /* check target (proxies not allowed) */
2645 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2646 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2647 dimensions
, _mesa_lookup_enum_by_nr(target
));
2652 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2653 _mesa_error(ctx
, GL_INVALID_VALUE
,
2654 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2658 /* Get dest texture object / image pointers */
2659 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2661 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2665 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2667 /* destination image does not exist */
2668 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2669 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2673 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2674 dimensions
, texImage
,
2675 xoffset
, yoffset
, zoffset
,
2676 width
, height
, 1)) {
2680 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2681 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2682 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2683 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2688 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2689 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2693 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2694 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2695 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2696 dimensions
, texImage
->_BaseFormat
);
2700 /* From the EXT_texture_integer spec:
2702 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2703 * if the texture internalformat is an integer format and the read color
2704 * buffer is not an integer format, or if the internalformat is not an
2705 * integer format and the read color buffer is an integer format."
2707 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2708 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2710 if (_mesa_is_format_integer_color(rb
->Format
) !=
2711 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2712 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2713 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2718 /* if we get here, the parameters are OK */
2723 /** Callback info for walking over FBO hash table */
2726 struct gl_context
*ctx
;
2727 struct gl_texture_object
*texObj
;
2733 * Check render to texture callback. Called from _mesa_HashWalk().
2736 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2738 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2739 const struct cb_info
*info
= (struct cb_info
*) userData
;
2740 struct gl_context
*ctx
= info
->ctx
;
2741 const struct gl_texture_object
*texObj
= info
->texObj
;
2742 const GLuint level
= info
->level
, face
= info
->face
;
2744 /* If this is a user-created FBO */
2745 if (_mesa_is_user_fbo(fb
)) {
2747 /* check if any of the FBO's attachments point to 'texObj' */
2748 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2749 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2750 if (att
->Type
== GL_TEXTURE
&&
2751 att
->Texture
== texObj
&&
2752 att
->TextureLevel
== level
&&
2753 att
->CubeMapFace
== face
) {
2754 ASSERT(_mesa_get_attachment_teximage(att
));
2755 /* Tell driver about the new renderbuffer texture */
2756 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2757 /* Mark fb status as indeterminate to force re-validation */
2766 * When a texture image is specified we have to check if it's bound to
2767 * any framebuffer objects (render to texture) in order to detect changes
2768 * in size or format since that effects FBO completeness.
2769 * Any FBOs rendering into the texture must be re-validated.
2772 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2773 struct gl_texture_object
*texObj
,
2774 GLuint face
, GLuint level
)
2776 /* Only check this texture if it's been marked as RenderToTexture */
2777 if (texObj
->_RenderToTexture
) {
2778 struct cb_info info
;
2780 info
.texObj
= texObj
;
2783 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2789 * If the texture object's GenerateMipmap flag is set and we've
2790 * changed the texture base level image, regenerate the rest of the
2791 * mipmap levels now.
2794 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2795 struct gl_texture_object
*texObj
, GLint level
)
2797 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2798 if (texObj
->GenerateMipmap
&&
2799 level
== texObj
->BaseLevel
&&
2800 level
< texObj
->MaxLevel
) {
2801 ASSERT(ctx
->Driver
.GenerateMipmap
);
2802 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2807 /** Debug helper: override the user-requested internal format */
2809 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2812 if (internalFormat
== GL_RGBA16F_ARB
||
2813 internalFormat
== GL_RGBA32F_ARB
) {
2814 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2817 else if (internalFormat
== GL_RGB16F_ARB
||
2818 internalFormat
== GL_RGB32F_ARB
) {
2819 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2822 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2823 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2824 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2825 return GL_LUMINANCE_ALPHA
;
2827 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2828 internalFormat
== GL_LUMINANCE32F_ARB
) {
2829 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2830 return GL_LUMINANCE
;
2832 else if (internalFormat
== GL_ALPHA16F_ARB
||
2833 internalFormat
== GL_ALPHA32F_ARB
) {
2834 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2838 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2839 internalFormat = GL_RGBA;
2843 return internalFormat
;
2846 return internalFormat
;
2852 * Choose the actual hardware format for a texture image.
2853 * Try to use the same format as the previous image level when possible.
2854 * Otherwise, ask the driver for the best format.
2855 * It's important to try to choose a consistant format for all levels
2856 * for efficient texture memory layout/allocation. In particular, this
2857 * comes up during automatic mipmap generation.
2860 _mesa_choose_texture_format(struct gl_context
*ctx
,
2861 struct gl_texture_object
*texObj
,
2862 GLenum target
, GLint level
,
2863 GLenum internalFormat
, GLenum format
, GLenum type
)
2867 /* see if we've already chosen a format for the previous level */
2869 struct gl_texture_image
*prevImage
=
2870 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2871 /* See if the prev level is defined and has an internal format which
2872 * matches the new internal format.
2875 prevImage
->Width
> 0 &&
2876 prevImage
->InternalFormat
== internalFormat
) {
2877 /* use the same format */
2878 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2879 return prevImage
->TexFormat
;
2883 /* If the application requested compression to an S3TC format but we don't
2884 * have the DTXn library, force a generic compressed format instead.
2886 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2887 const GLenum before
= internalFormat
;
2889 switch (internalFormat
) {
2890 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2891 if (!ctx
->Mesa_DXTn
)
2892 internalFormat
= GL_COMPRESSED_RGB
;
2894 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2895 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2896 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2897 if (!ctx
->Mesa_DXTn
)
2898 internalFormat
= GL_COMPRESSED_RGBA
;
2904 if (before
!= internalFormat
) {
2906 "DXT compression requested (%s), "
2907 "but libtxc_dxtn library not installed. Using %s "
2909 _mesa_lookup_enum_by_nr(before
),
2910 _mesa_lookup_enum_by_nr(internalFormat
));
2914 /* choose format from scratch */
2915 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2917 ASSERT(f
!= MESA_FORMAT_NONE
);
2922 * Adjust pixel unpack params and image dimensions to strip off the
2923 * one-pixel texture border.
2925 * Gallium and intel don't support texture borders. They've seldem been used
2926 * and seldom been implemented correctly anyway.
2928 * \param unpackNew returns the new pixel unpack parameters
2931 strip_texture_border(GLenum target
,
2932 GLint
*width
, GLint
*height
, GLint
*depth
,
2933 const struct gl_pixelstore_attrib
*unpack
,
2934 struct gl_pixelstore_attrib
*unpackNew
)
2940 *unpackNew
= *unpack
;
2942 if (unpackNew
->RowLength
== 0)
2943 unpackNew
->RowLength
= *width
;
2945 if (unpackNew
->ImageHeight
== 0)
2946 unpackNew
->ImageHeight
= *height
;
2948 assert(*width
>= 3);
2949 unpackNew
->SkipPixels
++; /* skip the border */
2950 *width
= *width
- 2; /* reduce the width by two border pixels */
2952 /* The min height of a texture with a border is 3 */
2953 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2954 unpackNew
->SkipRows
++; /* skip the border */
2955 *height
= *height
- 2; /* reduce the height by two border pixels */
2958 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
&& target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2959 unpackNew
->SkipImages
++; /* skip the border */
2960 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2966 * Common code to implement all the glTexImage1D/2D/3D functions
2967 * as well as glCompressedTexImage1D/2D/3D.
2968 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2969 * \param format the user's image format (only used if !compressed)
2970 * \param type the user's image type (only used if !compressed)
2971 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2974 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2975 GLenum target
, GLint level
, GLint internalFormat
,
2976 GLsizei width
, GLsizei height
, GLsizei depth
,
2977 GLint border
, GLenum format
, GLenum type
,
2978 GLsizei imageSize
, const GLvoid
*pixels
)
2980 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2981 struct gl_pixelstore_attrib unpack_no_border
;
2982 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2983 struct gl_texture_object
*texObj
;
2984 gl_format texFormat
;
2985 GLboolean dimensionsOK
, sizeOK
;
2987 FLUSH_VERTICES(ctx
, 0);
2989 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2992 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2994 _mesa_lookup_enum_by_nr(target
), level
,
2995 _mesa_lookup_enum_by_nr(internalFormat
),
2996 width
, height
, depth
, border
, pixels
);
2999 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3001 _mesa_lookup_enum_by_nr(target
), level
,
3002 _mesa_lookup_enum_by_nr(internalFormat
),
3003 width
, height
, depth
, border
,
3004 _mesa_lookup_enum_by_nr(format
),
3005 _mesa_lookup_enum_by_nr(type
), pixels
);
3008 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3010 /* target error checking */
3011 if (!legal_teximage_target(ctx
, dims
, target
)) {
3012 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3013 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3017 /* general error checking */
3019 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3021 width
, height
, depth
,
3026 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3027 format
, type
, width
, height
, depth
, border
))
3031 /* Here we convert a cpal compressed image into a regular glTexImage2D
3032 * call by decompressing the texture. If we really want to support cpal
3033 * textures in any driver this would have to be changed.
3035 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3036 switch (internalFormat
) {
3037 case GL_PALETTE4_RGB8_OES
:
3038 case GL_PALETTE4_RGBA8_OES
:
3039 case GL_PALETTE4_R5_G6_B5_OES
:
3040 case GL_PALETTE4_RGBA4_OES
:
3041 case GL_PALETTE4_RGB5_A1_OES
:
3042 case GL_PALETTE8_RGB8_OES
:
3043 case GL_PALETTE8_RGBA8_OES
:
3044 case GL_PALETTE8_R5_G6_B5_OES
:
3045 case GL_PALETTE8_RGBA4_OES
:
3046 case GL_PALETTE8_RGB5_A1_OES
:
3047 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3048 width
, height
, imageSize
, pixels
);
3053 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3057 /* For glCompressedTexImage() the driver has no choice about the
3058 * texture format since we'll never transcode the user's compressed
3059 * image data. The internalFormat was error checked earlier.
3061 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3064 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3065 internalFormat
, format
, type
);
3068 assert(texFormat
!= MESA_FORMAT_NONE
);
3070 /* check that width, height, depth are legal for the mipmap level */
3071 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3072 height
, depth
, border
);
3074 /* check that the texture won't take too much memory, etc */
3075 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3077 width
, height
, depth
, border
);
3079 if (_mesa_is_proxy_texture(target
)) {
3080 /* Proxy texture: just clear or set state depending on error checking */
3081 struct gl_texture_image
*texImage
=
3082 get_proxy_tex_image(ctx
, target
, level
);
3085 return; /* GL_OUT_OF_MEMORY already recorded */
3087 if (dimensionsOK
&& sizeOK
) {
3088 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3089 border
, internalFormat
, texFormat
);
3092 clear_teximage_fields(texImage
);
3096 /* non-proxy target */
3097 const GLuint face
= _mesa_tex_target_to_face(target
);
3098 struct gl_texture_image
*texImage
;
3100 if (!dimensionsOK
) {
3101 _mesa_error(ctx
, GL_INVALID_VALUE
,
3102 "glTexImage%uD(invalid width or height or depth)",
3108 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3109 "glTexImage%uD(image too large)", dims
);
3113 /* Allow a hardware driver to just strip out the border, to provide
3114 * reliable but slightly incorrect hardware rendering instead of
3115 * rarely-tested software fallback rendering.
3117 if (border
&& ctx
->Const
.StripTextureBorder
) {
3118 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3121 unpack
= &unpack_no_border
;
3124 if (ctx
->NewState
& _NEW_PIXEL
)
3125 _mesa_update_state(ctx
);
3127 _mesa_lock_texture(ctx
, texObj
);
3129 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3132 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3135 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3137 _mesa_init_teximage_fields(ctx
, texImage
,
3138 width
, height
, depth
,
3139 border
, internalFormat
, texFormat
);
3141 /* Give the texture to the driver. <pixels> may be null. */
3142 if (width
> 0 && height
> 0 && depth
> 0) {
3144 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3148 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3149 type
, pixels
, unpack
);
3153 check_gen_mipmap(ctx
, target
, texObj
, level
);
3155 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3157 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3160 _mesa_unlock_texture(ctx
, texObj
);
3167 * Called from the API. Note that width includes the border.
3170 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3171 GLsizei width
, GLint border
, GLenum format
,
3172 GLenum type
, const GLvoid
*pixels
)
3174 GET_CURRENT_CONTEXT(ctx
);
3175 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3176 border
, format
, type
, 0, pixels
);
3181 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3182 GLsizei width
, GLsizei height
, GLint border
,
3183 GLenum format
, GLenum type
,
3184 const GLvoid
*pixels
)
3186 GET_CURRENT_CONTEXT(ctx
);
3187 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3188 border
, format
, type
, 0, pixels
);
3193 * Called by the API or display list executor.
3194 * Note that width and height include the border.
3197 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3198 GLsizei width
, GLsizei height
, GLsizei depth
,
3199 GLint border
, GLenum format
, GLenum type
,
3200 const GLvoid
*pixels
)
3202 GET_CURRENT_CONTEXT(ctx
);
3203 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3204 width
, height
, depth
,
3205 border
, format
, type
, 0, pixels
);
3210 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3211 GLsizei width
, GLsizei height
, GLsizei depth
,
3212 GLint border
, GLenum format
, GLenum type
,
3213 const GLvoid
*pixels
)
3215 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3216 depth
, border
, format
, type
, pixels
);
3221 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3223 struct gl_texture_object
*texObj
;
3224 struct gl_texture_image
*texImage
;
3226 GET_CURRENT_CONTEXT(ctx
);
3227 FLUSH_VERTICES(ctx
, 0);
3231 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3233 case GL_TEXTURE_EXTERNAL_OES
:
3234 valid_target
= ctx
->Extensions
.OES_EGL_image_external
;
3237 valid_target
= false;
3241 if (!valid_target
) {
3242 _mesa_error(ctx
, GL_INVALID_ENUM
,
3243 "glEGLImageTargetTexture2D(target=%d)", target
);
3248 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3249 "glEGLImageTargetTexture2D(image=%p)", image
);
3253 if (ctx
->NewState
& _NEW_PIXEL
)
3254 _mesa_update_state(ctx
);
3256 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3257 _mesa_lock_texture(ctx
, texObj
);
3259 if (texObj
->Immutable
) {
3260 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3261 "glEGLImageTargetTexture2D(texture is immutable)");
3262 _mesa_unlock_texture(ctx
, texObj
);
3266 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3268 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3270 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3272 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3273 texObj
, texImage
, image
);
3275 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3277 _mesa_unlock_texture(ctx
, texObj
);
3284 * Implement all the glTexSubImage1/2/3D() functions.
3287 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3288 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3289 GLsizei width
, GLsizei height
, GLsizei depth
,
3290 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3292 struct gl_texture_object
*texObj
;
3293 struct gl_texture_image
*texImage
;
3295 FLUSH_VERTICES(ctx
, 0);
3297 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3298 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3300 _mesa_lookup_enum_by_nr(target
), level
,
3301 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3302 _mesa_lookup_enum_by_nr(format
),
3303 _mesa_lookup_enum_by_nr(type
), pixels
);
3305 /* check target (proxies not allowed) */
3306 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3307 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3308 dims
, _mesa_lookup_enum_by_nr(target
));
3312 if (ctx
->NewState
& _NEW_PIXEL
)
3313 _mesa_update_state(ctx
);
3315 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3316 xoffset
, yoffset
, zoffset
,
3317 width
, height
, depth
, format
, type
)) {
3318 return; /* error was detected */
3321 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3323 _mesa_lock_texture(ctx
, texObj
);
3325 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3327 if (width
> 0 && height
> 0 && depth
> 0) {
3328 /* If we have a border, offset=-1 is legal. Bias by border width. */
3331 if (target
!= GL_TEXTURE_2D_ARRAY
)
3332 zoffset
+= texImage
->Border
;
3335 if (target
!= GL_TEXTURE_1D_ARRAY
)
3336 yoffset
+= texImage
->Border
;
3339 xoffset
+= texImage
->Border
;
3342 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3343 xoffset
, yoffset
, zoffset
,
3344 width
, height
, depth
,
3345 format
, type
, pixels
, &ctx
->Unpack
);
3347 check_gen_mipmap(ctx
, target
, texObj
, level
);
3349 ctx
->NewState
|= _NEW_TEXTURE
;
3352 _mesa_unlock_texture(ctx
, texObj
);
3357 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3358 GLint xoffset
, GLsizei width
,
3359 GLenum format
, GLenum type
,
3360 const GLvoid
*pixels
)
3362 GET_CURRENT_CONTEXT(ctx
);
3363 texsubimage(ctx
, 1, target
, level
,
3366 format
, type
, pixels
);
3371 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3372 GLint xoffset
, GLint yoffset
,
3373 GLsizei width
, GLsizei height
,
3374 GLenum format
, GLenum type
,
3375 const GLvoid
*pixels
)
3377 GET_CURRENT_CONTEXT(ctx
);
3378 texsubimage(ctx
, 2, target
, level
,
3379 xoffset
, yoffset
, 0,
3381 format
, type
, pixels
);
3387 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3388 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3389 GLsizei width
, GLsizei height
, GLsizei depth
,
3390 GLenum format
, GLenum type
,
3391 const GLvoid
*pixels
)
3393 GET_CURRENT_CONTEXT(ctx
);
3394 texsubimage(ctx
, 3, target
, level
,
3395 xoffset
, yoffset
, zoffset
,
3396 width
, height
, depth
,
3397 format
, type
, pixels
);
3403 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3404 * from. This depends on whether the texture contains color or depth values.
3406 static struct gl_renderbuffer
*
3407 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3409 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3410 /* reading from depth/stencil buffer */
3411 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3414 /* copying from color buffer */
3415 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3422 * Implement the glCopyTexImage1/2D() functions.
3425 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3426 GLenum target
, GLint level
, GLenum internalFormat
,
3427 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3429 struct gl_texture_object
*texObj
;
3430 struct gl_texture_image
*texImage
;
3431 const GLuint face
= _mesa_tex_target_to_face(target
);
3432 gl_format texFormat
;
3434 FLUSH_VERTICES(ctx
, 0);
3436 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3437 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3439 _mesa_lookup_enum_by_nr(target
), level
,
3440 _mesa_lookup_enum_by_nr(internalFormat
),
3441 x
, y
, width
, height
, border
);
3443 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3444 _mesa_update_state(ctx
);
3446 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3447 width
, height
, border
))
3450 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3452 _mesa_error(ctx
, GL_INVALID_VALUE
,
3453 "glCopyTexImage%uD(invalid width or height)", dims
);
3457 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3460 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3461 internalFormat
, GL_NONE
, GL_NONE
);
3462 assert(texFormat
!= MESA_FORMAT_NONE
);
3464 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3466 width
, height
, 1, border
)) {
3467 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3468 "glCopyTexImage%uD(image too large)", dims
);
3472 if (border
&& ctx
->Const
.StripTextureBorder
) {
3474 width
-= border
* 2;
3477 height
-= border
* 2;
3482 _mesa_lock_texture(ctx
, texObj
);
3484 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3487 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3490 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3492 /* Free old texture image */
3493 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3495 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3496 border
, internalFormat
, texFormat
);
3498 /* Allocate texture memory (no pixel data yet) */
3499 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3501 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3503 struct gl_renderbuffer
*srcRb
=
3504 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3506 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
3507 srcRb
, srcX
, srcY
, width
, height
);
3510 check_gen_mipmap(ctx
, target
, texObj
, level
);
3512 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3514 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3517 _mesa_unlock_texture(ctx
, texObj
);
3523 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3524 GLenum internalFormat
,
3526 GLsizei width
, GLint border
)
3528 GET_CURRENT_CONTEXT(ctx
);
3529 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3535 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3536 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3539 GET_CURRENT_CONTEXT(ctx
);
3540 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3541 x
, y
, width
, height
, border
);
3547 * Implementation for glCopyTexSubImage1/2/3D() functions.
3550 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3551 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3552 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3554 struct gl_texture_object
*texObj
;
3555 struct gl_texture_image
*texImage
;
3557 FLUSH_VERTICES(ctx
, 0);
3559 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3560 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3562 _mesa_lookup_enum_by_nr(target
),
3563 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3565 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3566 _mesa_update_state(ctx
);
3568 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3569 xoffset
, yoffset
, zoffset
, width
, height
)) {
3573 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3575 _mesa_lock_texture(ctx
, texObj
);
3577 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3579 /* If we have a border, offset=-1 is legal. Bias by border width. */
3582 if (target
!= GL_TEXTURE_2D_ARRAY
)
3583 zoffset
+= texImage
->Border
;
3586 if (target
!= GL_TEXTURE_1D_ARRAY
)
3587 yoffset
+= texImage
->Border
;
3590 xoffset
+= texImage
->Border
;
3593 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3595 struct gl_renderbuffer
*srcRb
=
3596 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3598 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3599 xoffset
, yoffset
, zoffset
,
3600 srcRb
, x
, y
, width
, height
);
3602 check_gen_mipmap(ctx
, target
, texObj
, level
);
3604 ctx
->NewState
|= _NEW_TEXTURE
;
3607 _mesa_unlock_texture(ctx
, texObj
);
3612 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3613 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3615 GET_CURRENT_CONTEXT(ctx
);
3616 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3622 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3623 GLint xoffset
, GLint yoffset
,
3624 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3626 GET_CURRENT_CONTEXT(ctx
);
3627 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3634 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3635 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3636 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3638 GET_CURRENT_CONTEXT(ctx
);
3639 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3640 x
, y
, width
, height
);
3646 /**********************************************************************/
3647 /****** Compressed Textures ******/
3648 /**********************************************************************/
3652 * Error checking for glCompressedTexSubImage[123]D().
3653 * \return error code or GL_NO_ERROR.
3656 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3657 GLenum target
, GLint level
,
3658 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3659 GLsizei width
, GLsizei height
, GLsizei depth
,
3660 GLenum format
, GLsizei imageSize
)
3662 struct gl_texture_object
*texObj
;
3663 struct gl_texture_image
*texImage
;
3671 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3672 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3673 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3674 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3675 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3676 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3680 targetOK
= GL_FALSE
;
3685 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3689 /* no 1D compressed textures at this time */
3690 targetOK
= GL_FALSE
;
3695 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3700 /* this will catch any invalid compressed format token */
3701 if (!_mesa_is_compressed_format(ctx
, format
)) {
3702 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3707 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3708 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3713 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3714 if (expectedSize
!= imageSize
) {
3715 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3720 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3722 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3723 "glCompressedTexSubImage%uD()", dims
);
3727 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3729 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3730 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3734 if ((GLint
) format
!= texImage
->InternalFormat
) {
3735 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3736 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3740 if (compressedteximage_only_format(ctx
, format
)) {
3741 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3742 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3747 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3748 texImage
, xoffset
, yoffset
, zoffset
,
3749 width
, height
, depth
)) {
3758 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3759 GLenum internalFormat
, GLsizei width
,
3760 GLint border
, GLsizei imageSize
,
3763 GET_CURRENT_CONTEXT(ctx
);
3764 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3765 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3770 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3771 GLenum internalFormat
, GLsizei width
,
3772 GLsizei height
, GLint border
, GLsizei imageSize
,
3775 GET_CURRENT_CONTEXT(ctx
);
3776 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3777 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3782 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3783 GLenum internalFormat
, GLsizei width
,
3784 GLsizei height
, GLsizei depth
, GLint border
,
3785 GLsizei imageSize
, const GLvoid
*data
)
3787 GET_CURRENT_CONTEXT(ctx
);
3788 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3789 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3794 * Common helper for glCompressedTexSubImage1/2/3D().
3797 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3798 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3799 GLsizei width
, GLsizei height
, GLsizei depth
,
3800 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3802 struct gl_texture_object
*texObj
;
3803 struct gl_texture_image
*texImage
;
3804 GET_CURRENT_CONTEXT(ctx
);
3805 FLUSH_VERTICES(ctx
, 0);
3807 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3808 xoffset
, yoffset
, zoffset
,
3809 width
, height
, depth
,
3810 format
, imageSize
)) {
3814 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3816 _mesa_lock_texture(ctx
, texObj
);
3818 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3821 if (width
> 0 && height
> 0 && depth
> 0) {
3822 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3823 xoffset
, yoffset
, zoffset
,
3824 width
, height
, depth
,
3825 format
, imageSize
, data
);
3827 check_gen_mipmap(ctx
, target
, texObj
, level
);
3829 ctx
->NewState
|= _NEW_TEXTURE
;
3832 _mesa_unlock_texture(ctx
, texObj
);
3837 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3838 GLsizei width
, GLenum format
,
3839 GLsizei imageSize
, const GLvoid
*data
)
3841 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3842 format
, imageSize
, data
);
3847 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3848 GLint yoffset
, GLsizei width
, GLsizei height
,
3849 GLenum format
, GLsizei imageSize
,
3852 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3853 width
, height
, 1, format
, imageSize
, data
);
3858 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3859 GLint yoffset
, GLint zoffset
, GLsizei width
,
3860 GLsizei height
, GLsizei depth
, GLenum format
,
3861 GLsizei imageSize
, const GLvoid
*data
)
3863 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3864 width
, height
, depth
, format
, imageSize
, data
);
3868 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3870 switch (internalFormat
) {
3872 return MESA_FORMAT_A8
;
3874 return MESA_FORMAT_A16
;
3875 case GL_ALPHA16F_ARB
:
3876 return MESA_FORMAT_ALPHA_FLOAT16
;
3877 case GL_ALPHA32F_ARB
:
3878 return MESA_FORMAT_ALPHA_FLOAT32
;
3879 case GL_ALPHA8I_EXT
:
3880 return MESA_FORMAT_ALPHA_INT8
;
3881 case GL_ALPHA16I_EXT
:
3882 return MESA_FORMAT_ALPHA_INT16
;
3883 case GL_ALPHA32I_EXT
:
3884 return MESA_FORMAT_ALPHA_INT32
;
3885 case GL_ALPHA8UI_EXT
:
3886 return MESA_FORMAT_ALPHA_UINT8
;
3887 case GL_ALPHA16UI_EXT
:
3888 return MESA_FORMAT_ALPHA_UINT16
;
3889 case GL_ALPHA32UI_EXT
:
3890 return MESA_FORMAT_ALPHA_UINT32
;
3892 return MESA_FORMAT_L8
;
3893 case GL_LUMINANCE16
:
3894 return MESA_FORMAT_L16
;
3895 case GL_LUMINANCE16F_ARB
:
3896 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3897 case GL_LUMINANCE32F_ARB
:
3898 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3899 case GL_LUMINANCE8I_EXT
:
3900 return MESA_FORMAT_LUMINANCE_INT8
;
3901 case GL_LUMINANCE16I_EXT
:
3902 return MESA_FORMAT_LUMINANCE_INT16
;
3903 case GL_LUMINANCE32I_EXT
:
3904 return MESA_FORMAT_LUMINANCE_INT32
;
3905 case GL_LUMINANCE8UI_EXT
:
3906 return MESA_FORMAT_LUMINANCE_UINT8
;
3907 case GL_LUMINANCE16UI_EXT
:
3908 return MESA_FORMAT_LUMINANCE_UINT16
;
3909 case GL_LUMINANCE32UI_EXT
:
3910 return MESA_FORMAT_LUMINANCE_UINT32
;
3911 case GL_LUMINANCE8_ALPHA8
:
3912 return MESA_FORMAT_AL88
;
3913 case GL_LUMINANCE16_ALPHA16
:
3914 return MESA_FORMAT_AL1616
;
3915 case GL_LUMINANCE_ALPHA16F_ARB
:
3916 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3917 case GL_LUMINANCE_ALPHA32F_ARB
:
3918 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3919 case GL_LUMINANCE_ALPHA8I_EXT
:
3920 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3921 case GL_LUMINANCE_ALPHA16I_EXT
:
3922 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3923 case GL_LUMINANCE_ALPHA32I_EXT
:
3924 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3925 case GL_LUMINANCE_ALPHA8UI_EXT
:
3926 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3927 case GL_LUMINANCE_ALPHA16UI_EXT
:
3928 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3929 case GL_LUMINANCE_ALPHA32UI_EXT
:
3930 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3932 return MESA_FORMAT_I8
;
3933 case GL_INTENSITY16
:
3934 return MESA_FORMAT_I16
;
3935 case GL_INTENSITY16F_ARB
:
3936 return MESA_FORMAT_INTENSITY_FLOAT16
;
3937 case GL_INTENSITY32F_ARB
:
3938 return MESA_FORMAT_INTENSITY_FLOAT32
;
3939 case GL_INTENSITY8I_EXT
:
3940 return MESA_FORMAT_INTENSITY_INT8
;
3941 case GL_INTENSITY16I_EXT
:
3942 return MESA_FORMAT_INTENSITY_INT16
;
3943 case GL_INTENSITY32I_EXT
:
3944 return MESA_FORMAT_INTENSITY_INT32
;
3945 case GL_INTENSITY8UI_EXT
:
3946 return MESA_FORMAT_INTENSITY_UINT8
;
3947 case GL_INTENSITY16UI_EXT
:
3948 return MESA_FORMAT_INTENSITY_UINT16
;
3949 case GL_INTENSITY32UI_EXT
:
3950 return MESA_FORMAT_INTENSITY_UINT32
;
3952 return MESA_FORMAT_RGBA8888_REV
;
3954 return MESA_FORMAT_RGBA_16
;
3955 case GL_RGBA16F_ARB
:
3956 return MESA_FORMAT_RGBA_FLOAT16
;
3957 case GL_RGBA32F_ARB
:
3958 return MESA_FORMAT_RGBA_FLOAT32
;
3960 return MESA_FORMAT_RGBA_INT8
;
3961 case GL_RGBA16I_EXT
:
3962 return MESA_FORMAT_RGBA_INT16
;
3963 case GL_RGBA32I_EXT
:
3964 return MESA_FORMAT_RGBA_INT32
;
3965 case GL_RGBA8UI_EXT
:
3966 return MESA_FORMAT_RGBA_UINT8
;
3967 case GL_RGBA16UI_EXT
:
3968 return MESA_FORMAT_RGBA_UINT16
;
3969 case GL_RGBA32UI_EXT
:
3970 return MESA_FORMAT_RGBA_UINT32
;
3973 return MESA_FORMAT_GR88
;
3975 return MESA_FORMAT_GR1616
;
3977 return MESA_FORMAT_RG_FLOAT16
;
3979 return MESA_FORMAT_RG_FLOAT32
;
3981 return MESA_FORMAT_RG_INT8
;
3983 return MESA_FORMAT_RG_INT16
;
3985 return MESA_FORMAT_RG_INT32
;
3987 return MESA_FORMAT_RG_UINT8
;
3989 return MESA_FORMAT_RG_UINT16
;
3991 return MESA_FORMAT_RG_UINT32
;
3994 return MESA_FORMAT_R8
;
3996 return MESA_FORMAT_R16
;
3998 return MESA_FORMAT_R_FLOAT16
;
4000 return MESA_FORMAT_R_FLOAT32
;
4002 return MESA_FORMAT_R_INT8
;
4004 return MESA_FORMAT_R_INT16
;
4006 return MESA_FORMAT_R_INT32
;
4008 return MESA_FORMAT_R_UINT8
;
4010 return MESA_FORMAT_R_UINT16
;
4012 return MESA_FORMAT_R_UINT32
;
4015 return MESA_FORMAT_RGB_FLOAT32
;
4017 return MESA_FORMAT_RGB_UINT32
;
4019 return MESA_FORMAT_RGB_INT32
;
4022 return MESA_FORMAT_NONE
;
4027 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4029 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4032 if (format
== MESA_FORMAT_NONE
)
4033 return MESA_FORMAT_NONE
;
4035 datatype
= _mesa_get_format_datatype(format
);
4036 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4037 return MESA_FORMAT_NONE
;
4039 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4040 return MESA_FORMAT_NONE
;
4042 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
4043 * any mention of R/RG formats, but they appear in the GL 3.1 core
4046 if (ctx
->Version
<= 30) {
4047 GLenum base_format
= _mesa_get_format_base_format(format
);
4049 if (base_format
== GL_R
|| base_format
== GL_RG
)
4050 return MESA_FORMAT_NONE
;
4053 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4054 GLenum base_format
= _mesa_get_format_base_format(format
);
4055 if (base_format
== GL_RGB
)
4056 return MESA_FORMAT_NONE
;
4063 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4064 struct gl_buffer_object
*bufObj
,
4065 GLintptr offset
, GLsizeiptr size
)
4067 struct gl_texture_object
*texObj
;
4070 FLUSH_VERTICES(ctx
, 0);
4072 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4073 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4077 format
= validate_texbuffer_format(ctx
, internalFormat
);
4078 if (format
== MESA_FORMAT_NONE
) {
4079 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4084 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4086 _mesa_lock_texture(ctx
, texObj
);
4088 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4089 texObj
->BufferObjectFormat
= internalFormat
;
4090 texObj
->_BufferObjectFormat
= format
;
4091 texObj
->BufferOffset
= offset
;
4092 texObj
->BufferSize
= size
;
4094 _mesa_unlock_texture(ctx
, texObj
);
4097 /** GL_ARB_texture_buffer_object */
4099 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4101 struct gl_buffer_object
*bufObj
;
4103 GET_CURRENT_CONTEXT(ctx
);
4105 /* NOTE: ARB_texture_buffer_object has interactions with
4106 * the compatibility profile that are not implemented.
4108 if (!(ctx
->API
== API_OPENGL_CORE
&&
4109 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4110 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4114 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4115 if (!bufObj
&& buffer
) {
4116 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4120 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4123 /** GL_ARB_texture_buffer_range */
4125 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4126 GLintptr offset
, GLsizeiptr size
)
4128 struct gl_buffer_object
*bufObj
;
4130 GET_CURRENT_CONTEXT(ctx
);
4132 if (!(ctx
->API
== API_OPENGL_CORE
&&
4133 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4134 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4138 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4142 (offset
+ size
) > bufObj
->Size
) {
4143 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4146 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4147 _mesa_error(ctx
, GL_INVALID_VALUE
,
4148 "glTexBufferRange(invalid offset alignment)");
4151 } else if (buffer
) {
4152 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4160 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4164 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4166 /* Everything that is allowed for renderbuffers,
4167 * except for a base format of GL_STENCIL_INDEX.
4169 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4170 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4173 /** GL_ARB_texture_multisample */
4175 check_multisample_target(GLuint dims
, GLenum target
)
4178 case GL_TEXTURE_2D_MULTISAMPLE
:
4179 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4182 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4183 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4192 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4193 GLint internalformat
, GLsizei width
, GLsizei height
,
4194 GLsizei depth
, GLboolean fixedsamplelocations
)
4196 struct gl_texture_object
*texObj
;
4197 struct gl_texture_image
*texImage
;
4198 GLboolean sizeOK
, dimensionsOK
;
4199 gl_format texFormat
;
4201 GET_CURRENT_CONTEXT(ctx
);
4203 if (!(ctx
->Extensions
.ARB_texture_multisample
4204 && _mesa_is_desktop_gl(ctx
))) {
4205 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexImage%uDMultisample", dims
);
4209 if (!check_multisample_target(dims
, target
)) {
4210 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uDMultisample(target)", dims
);
4214 /* check that the specified internalformat is color/depth/stencil-renderable;
4215 * refer GL3.1 spec 4.4.4
4218 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4219 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4220 "glTexImage%uDMultisample(internalformat=%s)",
4222 _mesa_lookup_enum_by_nr(internalformat
));
4226 if (_mesa_is_enum_format_integer(internalformat
)) {
4227 if (samples
> ctx
->Const
.MaxIntegerSamples
) {
4228 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4229 "glTexImage%uDMultisample(samples>GL_MAX_INTEGER_SAMPLES)",
4234 else if (_mesa_is_depth_or_stencil_format(internalformat
)) {
4235 if (samples
> ctx
->Const
.MaxDepthTextureSamples
) {
4236 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4237 "glTexImage%uDMultisample(samples>GL_MAX_DEPTH_TEXTURE_SAMPLES)",
4243 if (samples
> ctx
->Const
.MaxColorTextureSamples
) {
4244 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4245 "glTexImage%uDMultisample(samples>GL_MAX_COLOR_TEXTURE_SAMPLES)",
4251 /* TODO: should ask the driver for the exact limit for this internalformat
4252 * once IDR's internalformat_query bits land
4255 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4256 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4258 if (texImage
== NULL
) {
4259 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uDMultisample()", dims
);
4263 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4264 internalformat
, GL_NONE
, GL_NONE
);
4265 assert(texFormat
!= MESA_FORMAT_NONE
);
4267 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4268 width
, height
, depth
, 0);
4270 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4271 width
, height
, depth
, 0);
4273 if (_mesa_is_proxy_texture(target
)) {
4274 if (dimensionsOK
&& sizeOK
) {
4275 _mesa_init_teximage_fields(ctx
, texImage
,
4276 width
, height
, depth
, 0, internalformat
, texFormat
);
4277 texImage
->NumSamples
= samples
;
4278 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4281 /* clear all image fields */
4282 _mesa_init_teximage_fields(ctx
, texImage
,
4283 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4287 if (!dimensionsOK
) {
4288 _mesa_error(ctx
, GL_INVALID_VALUE
,
4289 "glTexImage%uDMultisample(invalid width or height)", dims
);
4294 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4295 "glTexImage%uDMultisample(texture too large)", dims
);
4299 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4301 _mesa_init_teximage_fields(ctx
, texImage
,
4302 width
, height
, depth
, 0, internalformat
, texFormat
);
4304 texImage
->NumSamples
= samples
;
4305 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4307 if (width
> 0 && height
> 0 && depth
> 0) {
4309 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4310 width
, height
, depth
)) {
4311 /* tidy up the texture image state. strictly speaking,
4312 * we're allowed to just leave this in whatever state we
4313 * like, but being tidy is good.
4315 _mesa_init_teximage_fields(ctx
, texImage
,
4316 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4320 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4325 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4326 GLint internalformat
, GLsizei width
,
4327 GLsizei height
, GLboolean fixedsamplelocations
)
4329 teximagemultisample(2, target
, samples
, internalformat
,
4330 width
, height
, 1, fixedsamplelocations
);
4334 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4335 GLint internalformat
, GLsizei width
,
4336 GLsizei height
, GLsizei depth
,
4337 GLboolean fixedsamplelocations
)
4339 teximagemultisample(3, target
, samples
, internalformat
,
4340 width
, height
, depth
, fixedsamplelocations
);