2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
40 #include "framebuffer.h"
46 #include "texcompress.h"
47 #include "texformat.h"
55 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
59 _mesa_alloc_texmemory(GLsizei bytes
)
61 return _mesa_align_malloc(bytes
, 512);
66 * Free texture memory allocated with _mesa_alloc_texmemory()
69 _mesa_free_texmemory(void *m
)
78 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
80 #if CHAN_TYPE != GL_UNSIGNED_BYTE
81 _mesa_problem(NULL
, "PrintTexture not supported");
84 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
87 _mesa_printf("No texture data\n");
91 switch (img
->Format
) {
98 case GL_LUMINANCE_ALPHA
:
108 _mesa_problem(NULL
, "error in PrintTexture\n");
112 for (i
= 0; i
< img
->Height
; i
++) {
113 for (j
= 0; j
< img
->Width
; j
++) {
115 _mesa_printf("%02x ", data
[0]);
117 _mesa_printf("%02x%02x ", data
[0], data
[1]);
119 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
121 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
122 data
+= (img
->RowStride
- img
->Width
) * c
;
124 /* XXX use img->ImageStride here */
133 * Compute floor(log_base_2(n)).
134 * If n < 0 return -1.
163 * Return the simple base format for a given internal texture format.
164 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
166 * \param ctx GL context.
167 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
169 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
170 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
172 * This is the format which is used during texture application (i.e. the
173 * texture format and env mode determine the arithmetic used.
176 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
178 switch (internalFormat
) {
193 case GL_LUMINANCE_ALPHA
:
194 case GL_LUMINANCE4_ALPHA4
:
195 case GL_LUMINANCE6_ALPHA2
:
196 case GL_LUMINANCE8_ALPHA8
:
197 case GL_LUMINANCE12_ALPHA4
:
198 case GL_LUMINANCE12_ALPHA12
:
199 case GL_LUMINANCE16_ALPHA16
:
200 return GL_LUMINANCE_ALPHA
;
231 if (ctx
->Extensions
.EXT_paletted_texture
) {
232 switch (internalFormat
) {
234 case GL_COLOR_INDEX1_EXT
:
235 case GL_COLOR_INDEX2_EXT
:
236 case GL_COLOR_INDEX4_EXT
:
237 case GL_COLOR_INDEX8_EXT
:
238 case GL_COLOR_INDEX12_EXT
:
239 case GL_COLOR_INDEX16_EXT
:
240 return GL_COLOR_INDEX
;
246 if (ctx
->Extensions
.ARB_depth_texture
) {
247 switch (internalFormat
) {
248 case GL_DEPTH_COMPONENT
:
249 case GL_DEPTH_COMPONENT16
:
250 case GL_DEPTH_COMPONENT24
:
251 case GL_DEPTH_COMPONENT32
:
252 return GL_DEPTH_COMPONENT
;
258 switch (internalFormat
) {
259 case GL_COMPRESSED_ALPHA
:
261 case GL_COMPRESSED_LUMINANCE
:
263 case GL_COMPRESSED_LUMINANCE_ALPHA
:
264 return GL_LUMINANCE_ALPHA
;
265 case GL_COMPRESSED_INTENSITY
:
267 case GL_COMPRESSED_RGB
:
269 case GL_COMPRESSED_RGBA
:
275 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
276 switch (internalFormat
) {
277 case GL_COMPRESSED_RGB_FXT1_3DFX
:
279 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
286 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
287 switch (internalFormat
) {
288 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
290 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
291 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
292 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
299 if (ctx
->Extensions
.S3_s3tc
) {
300 switch (internalFormat
) {
312 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
313 if (internalFormat
== GL_YCBCR_MESA
)
314 return GL_YCBCR_MESA
;
317 if (ctx
->Extensions
.ARB_texture_float
) {
318 switch (internalFormat
) {
319 case GL_ALPHA16F_ARB
:
320 case GL_ALPHA32F_ARB
:
328 case GL_INTENSITY16F_ARB
:
329 case GL_INTENSITY32F_ARB
:
331 case GL_LUMINANCE16F_ARB
:
332 case GL_LUMINANCE32F_ARB
:
334 case GL_LUMINANCE_ALPHA16F_ARB
:
335 case GL_LUMINANCE_ALPHA32F_ARB
:
336 return GL_LUMINANCE_ALPHA
;
342 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
343 switch (internalFormat
) {
344 case GL_DEPTH_STENCIL_EXT
:
345 case GL_DEPTH24_STENCIL8_EXT
:
346 return GL_DEPTH_STENCIL_EXT
;
352 #if FEATURE_EXT_texture_sRGB
353 if (ctx
->Extensions
.EXT_texture_sRGB
) {
354 switch (internalFormat
) {
357 case GL_COMPRESSED_SRGB_EXT
:
358 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
360 case GL_SRGB_ALPHA_EXT
:
361 case GL_SRGB8_ALPHA8_EXT
:
362 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
363 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
364 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
365 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
367 case GL_SLUMINANCE_ALPHA_EXT
:
368 case GL_SLUMINANCE8_ALPHA8_EXT
:
369 case GL_COMPRESSED_SLUMINANCE_EXT
:
370 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
371 return GL_LUMINANCE_ALPHA
;
372 case GL_SLUMINANCE_EXT
:
373 case GL_SLUMINANCE8_EXT
:
380 #endif /* FEATURE_EXT_texture_sRGB */
382 return -1; /* error */
387 * Test if the given image format is a color/RGBA format (i.e., not color
388 * index, depth, stencil, etc).
389 * \param format the image format value (may by an internal texture format)
390 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
391 * XXX maybe move this func to image.c
394 _mesa_is_color_format(GLenum format
)
412 case GL_LUMINANCE_ALPHA
:
413 case GL_LUMINANCE4_ALPHA4
:
414 case GL_LUMINANCE6_ALPHA2
:
415 case GL_LUMINANCE8_ALPHA8
:
416 case GL_LUMINANCE12_ALPHA4
:
417 case GL_LUMINANCE12_ALPHA12
:
418 case GL_LUMINANCE16_ALPHA16
:
445 /* float texture formats */
446 case GL_ALPHA16F_ARB
:
447 case GL_ALPHA32F_ARB
:
448 case GL_LUMINANCE16F_ARB
:
449 case GL_LUMINANCE32F_ARB
:
450 case GL_LUMINANCE_ALPHA16F_ARB
:
451 case GL_LUMINANCE_ALPHA32F_ARB
:
452 case GL_INTENSITY16F_ARB
:
453 case GL_INTENSITY32F_ARB
:
458 /* compressed formats */
459 case GL_COMPRESSED_ALPHA
:
460 case GL_COMPRESSED_LUMINANCE
:
461 case GL_COMPRESSED_LUMINANCE_ALPHA
:
462 case GL_COMPRESSED_INTENSITY
:
463 case GL_COMPRESSED_RGB
:
464 case GL_COMPRESSED_RGBA
:
469 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
470 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
471 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
472 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
473 case GL_COMPRESSED_RGB_FXT1_3DFX
:
474 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
475 #if FEATURE_EXT_texture_sRGB
478 case GL_SRGB_ALPHA_EXT
:
479 case GL_SRGB8_ALPHA8_EXT
:
480 case GL_SLUMINANCE_ALPHA_EXT
:
481 case GL_SLUMINANCE8_ALPHA8_EXT
:
482 case GL_SLUMINANCE_EXT
:
483 case GL_SLUMINANCE8_EXT
:
484 case GL_COMPRESSED_SRGB_EXT
:
485 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
486 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
487 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
488 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
489 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
490 case GL_COMPRESSED_SLUMINANCE_EXT
:
491 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
492 #endif /* FEATURE_EXT_texture_sRGB */
494 case GL_YCBCR_MESA
: /* not considered to be RGB */
503 * Test if the given image format is a color index format.
506 is_index_format(GLenum format
)
510 case GL_COLOR_INDEX1_EXT
:
511 case GL_COLOR_INDEX2_EXT
:
512 case GL_COLOR_INDEX4_EXT
:
513 case GL_COLOR_INDEX8_EXT
:
514 case GL_COLOR_INDEX12_EXT
:
515 case GL_COLOR_INDEX16_EXT
:
524 * Test if the given image format is a depth component format.
527 is_depth_format(GLenum format
)
530 case GL_DEPTH_COMPONENT16
:
531 case GL_DEPTH_COMPONENT24
:
532 case GL_DEPTH_COMPONENT32
:
533 case GL_DEPTH_COMPONENT
:
542 * Test if the given image format is a YCbCr format.
545 is_ycbcr_format(GLenum format
)
557 * Test if the given image format is a Depth/Stencil format.
560 is_depthstencil_format(GLenum format
)
563 case GL_DEPTH24_STENCIL8_EXT
:
564 case GL_DEPTH_STENCIL_EXT
:
574 * Test if it is a supported compressed format.
576 * \param internalFormat the internal format token provided by the user.
578 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
579 * GL_FALSE otherwise.
581 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
585 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
587 GLint supported
[100]; /* 100 should be plenty */
590 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
592 for (i
= 0; i
< n
; i
++) {
593 if ((GLint
) internalFormat
== supported
[i
]) {
602 * For cube map faces, return a face index in [0,5].
603 * For other targets return 0;
606 _mesa_tex_target_to_face(GLenum target
)
608 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
609 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
610 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
618 * Store a gl_texture_image pointer in a gl_texture_object structure
619 * according to the target and level parameters.
621 * \param tObj texture object.
622 * \param target texture target.
623 * \param level image level.
624 * \param texImage texture image.
626 * This was basically prompted by the introduction of cube maps.
629 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
630 GLenum target
, GLint level
,
631 struct gl_texture_image
*texImage
)
635 /* XXX simplify this with _mesa_tex_target_to_face() */
640 case GL_TEXTURE_1D_ARRAY_EXT
:
641 case GL_TEXTURE_2D_ARRAY_EXT
:
642 tObj
->Image
[0][level
] = texImage
;
644 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
645 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
646 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
647 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
648 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
649 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
651 GLuint face
= ((GLuint
) target
-
652 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
653 tObj
->Image
[face
][level
] = texImage
;
656 case GL_TEXTURE_RECTANGLE_NV
:
658 tObj
->Image
[0][level
] = texImage
;
661 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
664 /* Set the 'back' pointer */
665 texImage
->TexObject
= tObj
;
670 * Allocate a texture image structure.
672 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
675 * \return a pointer to gl_texture_image struct with all fields initialized to
678 struct gl_texture_image
*
679 _mesa_new_texture_image( GLcontext
*ctx
)
682 return CALLOC_STRUCT(gl_texture_image
);
687 * Free texture image data.
688 * This function is a fallback called via ctx->Driver.FreeTexImageData().
690 * \param teximage texture image.
692 * Free the texture image data if it's not marked as client data.
695 _mesa_free_texture_image_data(GLcontext
*ctx
,
696 struct gl_texture_image
*texImage
)
700 if (texImage
->Data
&& !texImage
->IsClientData
) {
701 /* free the old texture data */
702 _mesa_free_texmemory(texImage
->Data
);
705 texImage
->Data
= NULL
;
710 * Free texture image.
712 * \param teximage texture image.
714 * Free the texture image structure and the associated image data.
717 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
719 /* Free texImage->Data and/or any other driver-specific texture
722 ASSERT(ctx
->Driver
.FreeTexImageData
);
723 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
725 ASSERT(texImage
->Data
== NULL
);
726 if (texImage
->ImageOffsets
)
727 _mesa_free(texImage
->ImageOffsets
);
728 _mesa_free(texImage
);
733 * Test if a target is a proxy target.
735 * \param target texture target.
737 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
740 _mesa_is_proxy_texture(GLenum target
)
742 return (target
== GL_PROXY_TEXTURE_1D
||
743 target
== GL_PROXY_TEXTURE_2D
||
744 target
== GL_PROXY_TEXTURE_3D
||
745 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
746 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
747 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
748 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
753 * Get the texture object that corresponds to the target of the given texture unit.
755 * \param ctx GL context.
756 * \param texUnit texture unit.
757 * \param target texture target.
759 * \return pointer to the texture object on success, or NULL on failure.
761 * \sa gl_texture_unit.
763 struct gl_texture_object
*
764 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
769 return texUnit
->Current1D
;
770 case GL_PROXY_TEXTURE_1D
:
771 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
773 return texUnit
->Current2D
;
774 case GL_PROXY_TEXTURE_2D
:
775 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
777 return texUnit
->Current3D
;
778 case GL_PROXY_TEXTURE_3D
:
779 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
780 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
781 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
782 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
783 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
784 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
785 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
786 case GL_TEXTURE_CUBE_MAP_ARB
:
787 return ctx
->Extensions
.ARB_texture_cube_map
788 ? texUnit
->CurrentCubeMap
: NULL
;
789 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
790 return ctx
->Extensions
.ARB_texture_cube_map
791 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
792 case GL_TEXTURE_RECTANGLE_NV
:
793 return ctx
->Extensions
.NV_texture_rectangle
794 ? texUnit
->CurrentRect
: NULL
;
795 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
796 return ctx
->Extensions
.NV_texture_rectangle
797 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
798 case GL_TEXTURE_1D_ARRAY_EXT
:
799 return ctx
->Extensions
.MESA_texture_array
800 ? texUnit
->Current1DArray
: NULL
;
801 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
802 return ctx
->Extensions
.MESA_texture_array
803 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
804 case GL_TEXTURE_2D_ARRAY_EXT
:
805 return ctx
->Extensions
.MESA_texture_array
806 ? texUnit
->Current2DArray
: NULL
;
807 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
808 return ctx
->Extensions
.MESA_texture_array
809 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
811 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
818 * Get the texture image struct which corresponds to target and level
819 * of the given texture unit.
821 * \param ctx GL context.
822 * \param texUnit texture unit.
823 * \param target texture target.
824 * \param level image level.
826 * \return pointer to the texture image structure on success, or NULL on failure.
828 * \sa gl_texture_unit.
830 struct gl_texture_image
*
831 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
832 GLenum target
, GLint level
)
836 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
)
839 /* XXX simplify this with _mesa_tex_target_to_face() */
842 case GL_PROXY_TEXTURE_1D
:
844 case GL_PROXY_TEXTURE_2D
:
846 case GL_PROXY_TEXTURE_3D
:
847 return texObj
->Image
[0][level
];
849 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
850 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
851 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
852 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
853 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
854 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
855 if (ctx
->Extensions
.ARB_texture_cube_map
) {
856 GLuint face
= ((GLuint
) target
-
857 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
858 return texObj
->Image
[face
][level
];
863 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
864 if (ctx
->Extensions
.ARB_texture_cube_map
)
865 return texObj
->Image
[0][level
];
869 case GL_TEXTURE_RECTANGLE_NV
:
870 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
871 if (ctx
->Extensions
.NV_texture_rectangle
&& level
== 0)
872 return texObj
->Image
[0][level
];
876 case GL_TEXTURE_1D_ARRAY_EXT
:
877 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
878 case GL_TEXTURE_2D_ARRAY_EXT
:
879 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
880 return (ctx
->Extensions
.MESA_texture_array
)
881 ? texObj
->Image
[0][level
] : NULL
;
890 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
891 * it and install it. Only return NULL if passed a bad parameter or run
894 struct gl_texture_image
*
895 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
896 GLenum target
, GLint level
)
898 struct gl_texture_image
*texImage
;
903 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
905 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
907 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
911 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
919 * Return pointer to the specified proxy texture image.
920 * Note that proxy textures are per-context, not per-texture unit.
921 * \return pointer to texture image or NULL if invalid target, invalid
922 * level, or out of memory.
924 struct gl_texture_image
*
925 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
927 struct gl_texture_image
*texImage
;
934 case GL_PROXY_TEXTURE_1D
:
935 if (level
>= ctx
->Const
.MaxTextureLevels
)
937 texIndex
= TEXTURE_1D_INDEX
;
939 case GL_PROXY_TEXTURE_2D
:
940 if (level
>= ctx
->Const
.MaxTextureLevels
)
942 texIndex
= TEXTURE_2D_INDEX
;
944 case GL_PROXY_TEXTURE_3D
:
945 if (level
>= ctx
->Const
.Max3DTextureLevels
)
947 texIndex
= TEXTURE_3D_INDEX
;
949 case GL_PROXY_TEXTURE_CUBE_MAP
:
950 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
952 texIndex
= TEXTURE_CUBE_INDEX
;
954 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
957 texIndex
= TEXTURE_RECT_INDEX
;
959 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
960 if (level
>= ctx
->Const
.MaxTextureLevels
)
962 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
964 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
965 if (level
>= ctx
->Const
.MaxTextureLevels
)
967 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
973 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
975 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
977 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
980 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
981 /* Set the 'back' pointer */
982 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
989 * Get the maximum number of allowed mipmap levels.
991 * \param ctx GL context.
992 * \param target texture target.
994 * \return the maximum number of allowed mipmap levels for the given
995 * texture target, or zero if passed a bad target.
1000 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
1004 case GL_PROXY_TEXTURE_1D
:
1006 case GL_PROXY_TEXTURE_2D
:
1007 case GL_TEXTURE_1D_ARRAY_EXT
:
1008 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1009 case GL_TEXTURE_2D_ARRAY_EXT
:
1010 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1011 return ctx
->Const
.MaxTextureLevels
;
1013 case GL_PROXY_TEXTURE_3D
:
1014 return ctx
->Const
.Max3DTextureLevels
;
1015 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1016 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1017 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1018 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1019 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1020 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1021 case GL_TEXTURE_CUBE_MAP_ARB
:
1022 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1023 return ctx
->Const
.MaxCubeTextureLevels
;
1024 case GL_TEXTURE_RECTANGLE_NV
:
1025 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1028 return 0; /* bad target */
1034 #if 000 /* not used anymore */
1036 * glTexImage[123]D can accept a NULL image pointer. In this case we
1037 * create a texture image with unspecified image contents per the OpenGL
1041 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1043 const GLint components
= _mesa_components_in_format(format
);
1044 const GLint numPixels
= width
* height
* depth
;
1045 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1049 * Let's see if anyone finds this. If glTexImage2D() is called with
1050 * a NULL image pointer then load the texture image with something
1051 * interesting instead of leaving it indeterminate.
1054 static const char message
[8][32] = {
1055 " X X XXXXX XXX X ",
1056 " XX XX X X X X X ",
1058 " X X XXXX XXX XXXXX ",
1061 " X X XXXXX XXX X X ",
1065 GLubyte
*imgPtr
= data
;
1067 for (h
= 0; h
< depth
; h
++) {
1068 for (i
= 0; i
< height
; i
++) {
1069 GLint srcRow
= 7 - (i
% 8);
1070 for (j
= 0; j
< width
; j
++) {
1071 GLint srcCol
= j
% 32;
1072 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1073 for (k
= 0; k
< components
; k
++) {
1089 * Reset the fields of a gl_texture_image struct to zero.
1091 * \param img texture image structure.
1093 * This is called when a proxy texture test fails, we set all the
1094 * image members (except DriverData) to zero.
1095 * It's also used in glTexImage[123]D as a safeguard to be sure all
1096 * required fields get initialized properly by the Driver.TexImage[123]D
1100 clear_teximage_fields(struct gl_texture_image
*img
)
1103 img
->_BaseFormat
= 0;
1104 img
->InternalFormat
= 0;
1110 if (img
->ImageOffsets
) {
1111 _mesa_free(img
->ImageOffsets
);
1112 img
->ImageOffsets
= NULL
;
1118 img
->HeightLog2
= 0;
1121 img
->TexFormat
= &_mesa_null_texformat
;
1122 img
->FetchTexelc
= NULL
;
1123 img
->FetchTexelf
= NULL
;
1124 img
->IsCompressed
= 0;
1125 img
->CompressedSize
= 0;
1130 * Initialize basic fields of the gl_texture_image struct.
1132 * \param ctx GL context.
1133 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1134 * \param img texture image structure to be initialized.
1135 * \param width image width.
1136 * \param height image height.
1137 * \param depth image depth.
1138 * \param border image border.
1139 * \param internalFormat internal format.
1141 * Fills in the fields of \p img with the given information.
1142 * Note: width, height and depth include the border.
1145 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1146 struct gl_texture_image
*img
,
1147 GLsizei width
, GLsizei height
, GLsizei depth
,
1148 GLint border
, GLenum internalFormat
)
1154 ASSERT(height
>= 0);
1157 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1158 ASSERT(img
->_BaseFormat
> 0);
1159 img
->InternalFormat
= internalFormat
;
1160 img
->Border
= border
;
1162 img
->Height
= height
;
1165 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1166 img
->WidthLog2
= logbase2(img
->Width2
);
1168 if (height
== 1) { /* 1-D texture */
1170 img
->HeightLog2
= 0;
1173 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1174 img
->HeightLog2
= logbase2(img
->Height2
);
1177 if (depth
== 1) { /* 2-D texture */
1182 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1183 img
->DepthLog2
= logbase2(img
->Depth2
);
1186 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1188 img
->IsCompressed
= GL_FALSE
;
1189 img
->CompressedSize
= 0;
1191 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1192 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1193 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1194 img
->_IsPowerOfTwo
= GL_TRUE
;
1196 img
->_IsPowerOfTwo
= GL_FALSE
;
1198 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1199 img
->RowStride
= width
;
1200 /* Allocate the ImageOffsets array and initialize to typical values.
1201 * We allocate the array for 1D/2D textures too in order to avoid special-
1202 * case code in the texstore routines.
1204 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1205 for (i
= 0; i
< depth
; i
++) {
1206 img
->ImageOffsets
[i
] = i
* width
* height
;
1209 /* Compute Width/Height/DepthScale for mipmap lod computation */
1210 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1211 /* scale = 1.0 since texture coords directly map to texels */
1212 img
->WidthScale
= 1.0;
1213 img
->HeightScale
= 1.0;
1214 img
->DepthScale
= 1.0;
1217 img
->WidthScale
= (GLfloat
) img
->Width
;
1218 img
->HeightScale
= (GLfloat
) img
->Height
;
1219 img
->DepthScale
= (GLfloat
) img
->Depth
;
1225 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1226 * level, width, height and depth against the ctx->Const limits for textures.
1228 * A hardware driver might override this function if, for example, the
1229 * max 3D texture size is 512x512x64 (i.e. not a cube).
1231 * Note that width, height, depth == 0 is not an error. However, a
1232 * texture with zero width/height/depth will be considered "incomplete"
1233 * and texturing will effectively be disabled.
1235 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1236 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1237 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1238 * \param level as passed to glTexImage
1239 * \param internalFormat as passed to glTexImage
1240 * \param format as passed to glTexImage
1241 * \param type as passed to glTexImage
1242 * \param width as passed to glTexImage
1243 * \param height as passed to glTexImage
1244 * \param depth as passed to glTexImage
1245 * \param border as passed to glTexImage
1246 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1249 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1250 GLint internalFormat
, GLenum format
, GLenum type
,
1251 GLint width
, GLint height
, GLint depth
, GLint border
)
1255 (void) internalFormat
;
1260 case GL_PROXY_TEXTURE_1D
:
1261 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1262 if (width
< 2 * border
|| width
> 2 + maxSize
||
1263 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1264 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1265 level
>= ctx
->Const
.MaxTextureLevels
) {
1266 /* bad width or level */
1270 case GL_PROXY_TEXTURE_2D
:
1271 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1272 if (width
< 2 * border
|| width
> 2 + maxSize
||
1273 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1274 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1275 height
< 2 * border
|| height
> 2 + maxSize
||
1276 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1277 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1278 level
>= ctx
->Const
.MaxTextureLevels
) {
1279 /* bad width or height or level */
1283 case GL_PROXY_TEXTURE_3D
:
1284 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1285 if (width
< 2 * border
|| width
> 2 + maxSize
||
1286 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1287 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1288 height
< 2 * border
|| height
> 2 + maxSize
||
1289 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1290 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1291 depth
< 2 * border
|| depth
> 2 + maxSize
||
1292 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1293 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1294 level
>= ctx
->Const
.Max3DTextureLevels
) {
1295 /* bad width or height or depth or level */
1299 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1300 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1301 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1303 /* bad width or height or level */
1307 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1308 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1309 if (width
< 2 * border
|| width
> 2 + maxSize
||
1310 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1311 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1312 height
< 2 * border
|| height
> 2 + maxSize
||
1313 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1314 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1315 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1316 /* bad width or height */
1320 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1321 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1322 if (width
< 2 * border
|| width
> 2 + maxSize
||
1323 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1324 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1325 level
>= ctx
->Const
.MaxTextureLevels
) {
1326 /* bad width or level */
1330 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1334 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1335 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1336 if (width
< 2 * border
|| width
> 2 + maxSize
||
1337 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1338 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1339 height
< 2 * border
|| height
> 2 + maxSize
||
1340 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1341 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1342 level
>= ctx
->Const
.MaxTextureLevels
) {
1343 /* bad width or height or level */
1346 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1351 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1358 * Helper function to determine whether a target supports compressed textures
1361 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1363 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1364 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1365 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1366 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1367 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1368 || ((ctx
->Extensions
.MESA_texture_array
&&
1369 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1370 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1375 * Test the glTexImage[123]D() parameters for errors.
1377 * \param ctx GL context.
1378 * \param target texture target given by the user.
1379 * \param level image level given by the user.
1380 * \param internalFormat internal format given by the user.
1381 * \param format pixel data format given by the user.
1382 * \param type pixel data type given by the user.
1383 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1384 * \param width image width given by the user.
1385 * \param height image height given by the user.
1386 * \param depth image depth given by the user.
1387 * \param border image border given by the user.
1389 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1391 * Verifies each of the parameters against the constants specified in
1392 * __GLcontextRec::Const and the supported extensions, and according to the
1393 * OpenGL specification.
1396 texture_error_check( GLcontext
*ctx
, GLenum target
,
1397 GLint level
, GLint internalFormat
,
1398 GLenum format
, GLenum type
,
1400 GLint width
, GLint height
,
1401 GLint depth
, GLint border
)
1403 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1404 GLboolean sizeOK
= GL_TRUE
;
1405 GLboolean colorFormat
, indexFormat
;
1406 GLenum proxy_target
;
1408 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1409 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1411 _mesa_error(ctx
, GL_INVALID_VALUE
,
1412 "glTexImage%dD(level=%d)", dimensions
, level
);
1418 if (border
< 0 || border
> 1 ||
1419 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1420 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1422 _mesa_error(ctx
, GL_INVALID_VALUE
,
1423 "glTexImage%dD(border=%d)", dimensions
, border
);
1428 if (width
< 0 || height
< 0 || depth
< 0) {
1430 _mesa_error(ctx
, GL_INVALID_VALUE
,
1431 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1436 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1437 * level, width, height and depth.
1439 if (dimensions
== 1) {
1440 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1441 proxy_target
= GL_PROXY_TEXTURE_1D
;
1446 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1450 else if (dimensions
== 2) {
1452 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1453 proxy_target
= GL_PROXY_TEXTURE_2D
;
1455 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1456 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1457 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1458 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1459 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1462 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1463 sizeOK
= (width
== height
);
1465 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1466 target
== GL_TEXTURE_RECTANGLE_NV
) {
1467 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1468 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1471 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1473 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1474 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1475 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1478 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1482 else if (dimensions
== 3) {
1483 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1484 proxy_target
= GL_PROXY_TEXTURE_3D
;
1486 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1487 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1488 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1491 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1496 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1500 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1501 internalFormat
, format
,
1502 type
, width
, height
,
1506 _mesa_error(ctx
, GL_INVALID_VALUE
,
1507 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1508 dimensions
, level
, width
, height
, depth
);
1513 /* Check internalFormat */
1514 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1516 _mesa_error(ctx
, GL_INVALID_VALUE
,
1517 "glTexImage%dD(internalFormat=0x%x)",
1518 dimensions
, internalFormat
);
1523 /* Check incoming image format and type */
1524 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1525 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1526 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1529 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1530 "glTexImage%dD(format or type)", dimensions
);
1535 /* make sure internal format and format basically agree */
1536 colorFormat
= _mesa_is_color_format(format
);
1537 indexFormat
= is_index_format(format
);
1538 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1539 (is_index_format(internalFormat
) && !indexFormat
) ||
1540 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1541 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1542 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
))) {
1544 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1545 "glTexImage(internalFormat/format)");
1549 /* additional checks for ycbcr textures */
1550 if (internalFormat
== GL_YCBCR_MESA
) {
1551 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1552 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1553 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1555 _mesa_sprintf(message
,
1556 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1557 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1558 return GL_TRUE
; /* error */
1560 if (target
!= GL_TEXTURE_2D
&&
1561 target
!= GL_PROXY_TEXTURE_2D
&&
1562 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1563 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1565 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1571 _mesa_sprintf(message
,
1572 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1573 dimensions
, border
);
1574 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1580 /* additional checks for depth textures */
1581 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1582 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1583 if (target
!= GL_TEXTURE_1D
&&
1584 target
!= GL_PROXY_TEXTURE_1D
&&
1585 target
!= GL_TEXTURE_2D
&&
1586 target
!= GL_PROXY_TEXTURE_2D
&&
1587 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1588 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1590 _mesa_error(ctx
, GL_INVALID_ENUM
,
1591 "glTexImage(target/internalFormat)");
1596 /* additional checks for compressed textures */
1597 if (is_compressed_format(ctx
, internalFormat
)) {
1598 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1599 _mesa_error(ctx
, GL_INVALID_ENUM
,
1600 "glTexImage%d(target)", dimensions
);
1605 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1606 "glTexImage%D(border!=0)", dimensions
);
1612 /* if we get here, the parameters are OK */
1618 * Test glTexSubImage[123]D() parameters for errors.
1620 * \param ctx GL context.
1621 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1622 * \param target texture target given by the user.
1623 * \param level image level given by the user.
1624 * \param xoffset sub-image x offset given by the user.
1625 * \param yoffset sub-image y offset given by the user.
1626 * \param zoffset sub-image z offset given by the user.
1627 * \param format pixel data format given by the user.
1628 * \param type pixel data type given by the user.
1629 * \param width image width given by the user.
1630 * \param height image height given by the user.
1631 * \param depth image depth given by the user.
1633 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1635 * Verifies each of the parameters against the constants specified in
1636 * __GLcontextRec::Const and the supported extensions, and according to the
1637 * OpenGL specification.
1640 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1641 GLenum target
, GLint level
,
1642 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1643 GLint width
, GLint height
, GLint depth
,
1644 GLenum format
, GLenum type
)
1647 if (dimensions
== 1) {
1648 if (target
!= GL_TEXTURE_1D
) {
1649 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1653 else if (dimensions
== 2) {
1654 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1655 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1656 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1657 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1661 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1662 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1663 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1667 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1668 if (!ctx
->Extensions
.MESA_texture_array
) {
1669 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1673 else if (target
!= GL_TEXTURE_2D
) {
1674 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1678 else if (dimensions
== 3) {
1679 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1680 if (!ctx
->Extensions
.MESA_texture_array
) {
1681 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1685 else if (target
!= GL_TEXTURE_3D
) {
1686 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1691 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1695 /* Basic level check */
1696 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1697 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1702 _mesa_error(ctx
, GL_INVALID_VALUE
,
1703 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1706 if (height
< 0 && dimensions
> 1) {
1707 _mesa_error(ctx
, GL_INVALID_VALUE
,
1708 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1711 if (depth
< 0 && dimensions
> 2) {
1712 _mesa_error(ctx
, GL_INVALID_VALUE
,
1713 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1717 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1718 _mesa_error(ctx
, GL_INVALID_ENUM
,
1719 "glTexSubImage%dD(format or type)", dimensions
);
1727 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1728 GLenum target
, GLint level
,
1729 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1730 GLint width
, GLint height
, GLint depth
,
1731 GLenum format
, GLenum type
,
1732 const struct gl_texture_image
*destTex
)
1735 /* undefined image level */
1736 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1740 if (xoffset
< -((GLint
)destTex
->Border
)) {
1741 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1745 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1746 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1750 if (dimensions
> 1) {
1751 if (yoffset
< -((GLint
)destTex
->Border
)) {
1752 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1756 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1757 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1762 if (dimensions
> 2) {
1763 if (zoffset
< -((GLint
)destTex
->Border
)) {
1764 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1767 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1768 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1773 #if FEATURE_EXT_texture_sRGB
1774 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1775 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1776 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1777 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1778 if ((width
& 0x3) || (height
& 0x3) ||
1779 (xoffset
& 0x3) || (yoffset
& 0x3))
1780 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1781 "glTexSubImage%dD(size or offset not multiple of 4)",
1787 if (destTex
->IsCompressed
) {
1788 if (!target_can_be_compressed(ctx
, target
)) {
1789 _mesa_error(ctx
, GL_INVALID_ENUM
,
1790 "glTexSubImage%D(target)", dimensions
);
1793 /* offset must be multiple of 4 */
1794 if ((xoffset
& 3) || (yoffset
& 3)) {
1795 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1796 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1799 /* size must be multiple of 4 or equal to whole texture size */
1800 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1801 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1802 "glTexSubImage%D(width)", dimensions
);
1805 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1806 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1807 "glTexSubImage%D(width)", dimensions
);
1817 * Test glCopyTexImage[12]D() parameters for errors.
1819 * \param ctx GL context.
1820 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1821 * \param target texture target given by the user.
1822 * \param level image level given by the user.
1823 * \param internalFormat internal format given by the user.
1824 * \param width image width given by the user.
1825 * \param height image height given by the user.
1826 * \param depth image depth given by the user.
1827 * \param border texture border.
1829 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1831 * Verifies each of the parameters against the constants specified in
1832 * __GLcontextRec::Const and the supported extensions, and according to the
1833 * OpenGL specification.
1836 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1837 GLenum target
, GLint level
, GLint internalFormat
,
1838 GLint width
, GLint height
, GLint border
)
1844 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1845 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1846 _mesa_error(ctx
, GL_INVALID_VALUE
,
1847 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1851 /* Check that the source buffer is complete */
1852 if (ctx
->ReadBuffer
->Name
) {
1853 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1854 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1855 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1856 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1862 if (border
< 0 || border
> 1 ||
1863 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1864 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1868 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1870 _mesa_error(ctx
, GL_INVALID_VALUE
,
1871 "glCopyTexImage%dD(internalFormat)", dimensions
);
1875 /* NOTE: the format and type aren't really significant for
1876 * TestProxyTexImage(). Only the internalformat really matters.
1877 if (!_mesa_source_buffer_exists(ctx, format)) {
1878 _mesa_error(ctx, GL_INVALID_OPERATION,
1879 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1886 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1887 * level, width, height and depth.
1889 if (dimensions
== 1) {
1890 if (target
== GL_TEXTURE_1D
) {
1891 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1892 level
, internalFormat
,
1894 width
, 1, 1, border
);
1897 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1901 else if (dimensions
== 2) {
1902 if (target
== GL_TEXTURE_2D
) {
1903 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1904 level
, internalFormat
,
1906 width
, height
, 1, border
);
1908 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1909 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1910 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1911 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1914 sizeOK
= (width
== height
) &&
1915 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1916 level
, internalFormat
, format
, type
,
1917 width
, height
, 1, border
);
1919 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1920 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1921 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1924 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1925 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1926 level
, internalFormat
,
1928 width
, height
, 1, border
);
1930 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1931 if (!ctx
->Extensions
.MESA_texture_array
) {
1932 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1935 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1936 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1937 level
, internalFormat
,
1939 width
, height
, 1, border
);
1942 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1947 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1952 if (dimensions
== 1) {
1953 _mesa_error(ctx
, GL_INVALID_VALUE
,
1954 "glCopyTexImage1D(width=%d)", width
);
1957 ASSERT(dimensions
== 2);
1958 _mesa_error(ctx
, GL_INVALID_VALUE
,
1959 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1964 if (is_compressed_format(ctx
, internalFormat
)) {
1965 if (!target_can_be_compressed(ctx
, target
)) {
1966 _mesa_error(ctx
, GL_INVALID_ENUM
,
1967 "glCopyTexImage%d(target)", dimensions
);
1971 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1972 "glCopyTexImage%D(border!=0)", dimensions
);
1976 else if (is_depth_format(internalFormat
)) {
1977 /* make sure we have depth/stencil buffers */
1978 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1979 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1980 "glCopyTexImage%D(no depth)", dimensions
);
1984 else if (is_depthstencil_format(internalFormat
)) {
1985 /* make sure we have depth/stencil buffers */
1986 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1987 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1988 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
1993 /* if we get here, the parameters are OK */
1999 * Test glCopyTexSubImage[12]D() parameters for errors.
2000 * Note that this is the first part of error checking.
2001 * See also copytexsubimage_error_check2() below for the second part.
2003 * \param ctx GL context.
2004 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2005 * \param target texture target given by the user.
2006 * \param level image level given by the user.
2008 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2011 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
2012 GLenum target
, GLint level
)
2014 /* Check that the source buffer is complete */
2015 if (ctx
->ReadBuffer
->Name
) {
2016 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2017 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2018 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2019 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2025 if (dimensions
== 1) {
2026 if (target
!= GL_TEXTURE_1D
) {
2027 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2031 else if (dimensions
== 2) {
2032 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2033 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2034 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2035 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2039 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2040 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2041 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2045 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2046 if (!ctx
->Extensions
.MESA_texture_array
) {
2047 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2051 else if (target
!= GL_TEXTURE_2D
) {
2052 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2056 else if (dimensions
== 3) {
2057 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2058 (!ctx
->Extensions
.MESA_texture_array
))
2059 && (target
!= GL_TEXTURE_3D
)) {
2060 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2066 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2067 _mesa_error(ctx
, GL_INVALID_VALUE
,
2068 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2077 * Second part of error checking for glCopyTexSubImage[12]D().
2078 * \param xoffset sub-image x offset given by the user.
2079 * \param yoffset sub-image y offset given by the user.
2080 * \param zoffset sub-image z offset given by the user.
2081 * \param width image width given by the user.
2082 * \param height image height given by the user.
2085 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2086 GLenum target
, GLint level
,
2087 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2088 GLsizei width
, GLsizei height
,
2089 const struct gl_texture_image
*teximage
)
2091 /* check that dest tex image exists */
2093 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2094 "glCopyTexSubImage%dD(undefined texture level: %d)",
2101 _mesa_error(ctx
, GL_INVALID_VALUE
,
2102 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2105 if (dimensions
> 1 && height
< 0) {
2106 _mesa_error(ctx
, GL_INVALID_VALUE
,
2107 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2111 /* check x/y offsets */
2112 if (xoffset
< -((GLint
)teximage
->Border
)) {
2113 _mesa_error(ctx
, GL_INVALID_VALUE
,
2114 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2117 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2118 _mesa_error(ctx
, GL_INVALID_VALUE
,
2119 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2122 if (dimensions
> 1) {
2123 if (yoffset
< -((GLint
)teximage
->Border
)) {
2124 _mesa_error(ctx
, GL_INVALID_VALUE
,
2125 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2128 /* NOTE: we're adding the border here, not subtracting! */
2129 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2130 _mesa_error(ctx
, GL_INVALID_VALUE
,
2131 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2136 /* check z offset */
2137 if (dimensions
> 2) {
2138 if (zoffset
< -((GLint
)teximage
->Border
)) {
2139 _mesa_error(ctx
, GL_INVALID_VALUE
,
2140 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2143 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2144 _mesa_error(ctx
, GL_INVALID_VALUE
,
2145 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2150 if (teximage
->IsCompressed
) {
2151 if (!target_can_be_compressed(ctx
, target
)) {
2152 _mesa_error(ctx
, GL_INVALID_ENUM
,
2153 "glCopyTexSubImage%d(target)", dimensions
);
2156 /* offset must be multiple of 4 */
2157 if ((xoffset
& 3) || (yoffset
& 3)) {
2158 _mesa_error(ctx
, GL_INVALID_VALUE
,
2159 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2162 /* size must be multiple of 4 */
2163 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2164 _mesa_error(ctx
, GL_INVALID_VALUE
,
2165 "glCopyTexSubImage%D(width)", dimensions
);
2168 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2169 _mesa_error(ctx
, GL_INVALID_VALUE
,
2170 "glCopyTexSubImage%D(height)", dimensions
);
2175 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2176 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2180 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2181 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2182 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2183 dimensions
, teximage
->_BaseFormat
);
2187 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2188 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2189 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2190 "glCopyTexSubImage%D(no depth buffer)",
2195 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2196 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2197 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2198 "glCopyTexSubImage%D(no depth/stencil buffer)",
2204 /* if we get here, the parameters are OK */
2210 * Get texture image. Called by glGetTexImage.
2212 * \param target texture target.
2213 * \param level image level.
2214 * \param format pixel data format for returned image.
2215 * \param type pixel data type for returned image.
2216 * \param pixels returned pixel data.
2219 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2220 GLenum type
, GLvoid
*pixels
)
2222 const struct gl_texture_unit
*texUnit
;
2223 struct gl_texture_object
*texObj
;
2224 struct gl_texture_image
*texImage
;
2225 GLint maxLevels
= 0;
2226 GET_CURRENT_CONTEXT(ctx
);
2227 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2229 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2230 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2231 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2232 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2236 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2237 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2239 if (level
< 0 || level
>= maxLevels
) {
2240 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2244 if (_mesa_sizeof_packed_type(type
) <= 0) {
2245 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2249 if (_mesa_components_in_format(format
) <= 0 ||
2250 format
== GL_STENCIL_INDEX
) {
2251 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2255 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2256 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2260 if (!ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2261 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2265 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2266 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2270 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2271 && is_depthstencil_format(format
)) {
2272 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2276 _mesa_lock_texture(ctx
, texObj
);
2278 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2280 /* invalid mipmap level, not an error */
2285 /* Make sure the requested image format is compatible with the
2286 * texture's format. Note that a color index texture can be converted
2287 * to RGBA so that combo is allowed.
2289 if (_mesa_is_color_format(format
)
2290 && !_mesa_is_color_format(texImage
->TexFormat
->BaseFormat
)
2291 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2292 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2295 else if (is_index_format(format
)
2296 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2297 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2300 else if (is_depth_format(format
)
2301 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2302 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2303 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2306 else if (is_ycbcr_format(format
)
2307 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2308 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2311 else if (is_depthstencil_format(format
)
2312 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2313 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2317 if (ctx
->Pack
.BufferObj
->Name
) {
2318 /* packing texture image into a PBO */
2319 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2320 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2321 texImage
->Height
, texImage
->Depth
,
2322 format
, type
, pixels
)) {
2323 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2324 "glGetTexImage(invalid PBO access)");
2329 /* typically, this will call _mesa_get_teximage() */
2330 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2335 _mesa_unlock_texture(ctx
, texObj
);
2339 /** Callback info for walking over FBO hash table */
2343 struct gl_texture_object
*texObj
;
2349 * Check render to texture callback. Called from _mesa_HashWalk().
2352 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2354 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2355 const struct cb_info
*info
= (struct cb_info
*) userData
;
2356 GLcontext
*ctx
= info
->ctx
;
2357 const struct gl_texture_object
*texObj
= info
->texObj
;
2358 const GLuint level
= info
->level
, face
= info
->face
;
2360 /* If this is a user-created FBO */
2363 /* check if any of the FBO's attachments point to 'texObj' */
2364 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2365 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2366 if (att
->Type
== GL_TEXTURE
&&
2367 att
->Texture
== texObj
&&
2368 att
->TextureLevel
== level
&&
2369 att
->CubeMapFace
== face
) {
2370 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2371 /* Tell driver about the new renderbuffer texture */
2372 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2373 /* Mark fb status as indeterminate to force re-validation */
2382 * When a texture image is specified we have to check if it's bound to
2383 * any framebuffer objects (render to texture) in order to detect changes
2384 * in size or format since that effects FBO completeness.
2385 * Any FBOs rendering into the texture must be re-validated.
2388 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2389 GLuint face
, GLuint level
)
2391 /* Only check this texture if it's been marked as RenderToTexture */
2392 if (texObj
->_RenderToTexture
) {
2393 struct cb_info info
;
2395 info
.texObj
= texObj
;
2398 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2405 * Called from the API. Note that width includes the border.
2408 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2409 GLsizei width
, GLint border
, GLenum format
,
2410 GLenum type
, const GLvoid
*pixels
)
2412 GLsizei postConvWidth
= width
;
2413 GET_CURRENT_CONTEXT(ctx
);
2414 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2416 #if FEATURE_convolve
2417 if (_mesa_is_color_format(internalFormat
)) {
2418 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2422 if (target
== GL_TEXTURE_1D
) {
2423 /* non-proxy target */
2424 struct gl_texture_unit
*texUnit
;
2425 struct gl_texture_object
*texObj
;
2426 struct gl_texture_image
*texImage
;
2427 const GLuint face
= _mesa_tex_target_to_face(target
);
2429 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2430 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2431 return; /* error was recorded */
2434 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2435 _mesa_update_state(ctx
);
2437 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2438 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2439 _mesa_lock_texture(ctx
, texObj
);
2441 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2443 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2447 if (texImage
->Data
) {
2448 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2451 ASSERT(texImage
->Data
== NULL
);
2453 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2454 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2455 postConvWidth
, 1, 1,
2456 border
, internalFormat
);
2458 ASSERT(ctx
->Driver
.TexImage1D
);
2460 /* Give the texture to the driver! <pixels> may be null! */
2461 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2462 width
, border
, format
, type
, pixels
,
2463 &ctx
->Unpack
, texObj
, texImage
);
2465 ASSERT(texImage
->TexFormat
);
2467 update_fbo_texture(ctx
, texObj
, face
, level
);
2470 texObj
->_Complete
= GL_FALSE
;
2471 ctx
->NewState
|= _NEW_TEXTURE
;
2474 _mesa_unlock_texture(ctx
, texObj
);
2476 else if (target
== GL_PROXY_TEXTURE_1D
) {
2477 /* Proxy texture: check for errors and update proxy state */
2478 struct gl_texture_image
*texImage
;
2479 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2480 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2481 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2482 /* when error, clear all proxy texture image parameters */
2484 clear_teximage_fields(texImage
);
2487 /* no error, set the tex image parameters */
2489 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2490 postConvWidth
, 1, 1,
2491 border
, internalFormat
);
2492 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2493 internalFormat
, format
, type
);
2497 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2504 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2505 GLsizei width
, GLsizei height
, GLint border
,
2506 GLenum format
, GLenum type
,
2507 const GLvoid
*pixels
)
2509 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2510 GET_CURRENT_CONTEXT(ctx
);
2511 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2513 #if FEATURE_convolve
2514 if (_mesa_is_color_format(internalFormat
)) {
2515 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2520 if (target
== GL_TEXTURE_2D
||
2521 (ctx
->Extensions
.ARB_texture_cube_map
&&
2522 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2523 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2524 (ctx
->Extensions
.NV_texture_rectangle
&&
2525 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2526 (ctx
->Extensions
.MESA_texture_array
&&
2527 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2528 /* non-proxy target */
2529 struct gl_texture_unit
*texUnit
;
2530 struct gl_texture_object
*texObj
;
2531 struct gl_texture_image
*texImage
;
2532 const GLuint face
= _mesa_tex_target_to_face(target
);
2534 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2535 format
, type
, 2, postConvWidth
, postConvHeight
,
2537 return; /* error was recorded */
2540 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2541 _mesa_update_state(ctx
);
2543 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2544 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2545 _mesa_lock_texture(ctx
, texObj
);
2547 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2549 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2553 if (texImage
->Data
) {
2554 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2557 ASSERT(texImage
->Data
== NULL
);
2558 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2559 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2560 postConvWidth
, postConvHeight
, 1,
2561 border
, internalFormat
);
2563 ASSERT(ctx
->Driver
.TexImage2D
);
2565 /* Give the texture to the driver! <pixels> may be null! */
2566 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2567 width
, height
, border
, format
, type
, pixels
,
2568 &ctx
->Unpack
, texObj
, texImage
);
2570 ASSERT(texImage
->TexFormat
);
2572 update_fbo_texture(ctx
, texObj
, face
, level
);
2575 texObj
->_Complete
= GL_FALSE
;
2576 ctx
->NewState
|= _NEW_TEXTURE
;
2579 _mesa_unlock_texture(ctx
, texObj
);
2581 else if (target
== GL_PROXY_TEXTURE_2D
||
2582 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2583 ctx
->Extensions
.ARB_texture_cube_map
) ||
2584 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2585 ctx
->Extensions
.NV_texture_rectangle
) ||
2586 (ctx
->Extensions
.MESA_texture_array
&&
2587 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2588 /* Proxy texture: check for errors and update proxy state */
2589 struct gl_texture_image
*texImage
;
2590 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2591 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2592 format
, type
, 2, postConvWidth
, postConvHeight
,
2594 /* when error, clear all proxy texture image parameters */
2596 clear_teximage_fields(texImage
);
2599 /* no error, set the tex image parameters */
2600 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2601 postConvWidth
, postConvHeight
, 1,
2602 border
, internalFormat
);
2603 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2604 internalFormat
, format
, type
);
2608 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2615 * Called by the API or display list executor.
2616 * Note that width and height include the border.
2619 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2620 GLsizei width
, GLsizei height
, GLsizei depth
,
2621 GLint border
, GLenum format
, GLenum type
,
2622 const GLvoid
*pixels
)
2624 GET_CURRENT_CONTEXT(ctx
);
2625 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2627 if (target
== GL_TEXTURE_3D
||
2628 (ctx
->Extensions
.MESA_texture_array
&&
2629 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2630 /* non-proxy target */
2631 struct gl_texture_unit
*texUnit
;
2632 struct gl_texture_object
*texObj
;
2633 struct gl_texture_image
*texImage
;
2634 const GLuint face
= _mesa_tex_target_to_face(target
);
2636 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2637 format
, type
, 3, width
, height
, depth
, border
)) {
2638 return; /* error was recorded */
2641 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2642 _mesa_update_state(ctx
);
2644 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2645 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2646 _mesa_lock_texture(ctx
, texObj
);
2648 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2650 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2654 if (texImage
->Data
) {
2655 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2658 ASSERT(texImage
->Data
== NULL
);
2659 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2660 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2661 width
, height
, depth
,
2662 border
, internalFormat
);
2664 ASSERT(ctx
->Driver
.TexImage3D
);
2666 /* Give the texture to the driver! <pixels> may be null! */
2667 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2668 width
, height
, depth
, border
, format
, type
,
2669 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2671 ASSERT(texImage
->TexFormat
);
2673 update_fbo_texture(ctx
, texObj
, face
, level
);
2676 texObj
->_Complete
= GL_FALSE
;
2677 ctx
->NewState
|= _NEW_TEXTURE
;
2680 _mesa_unlock_texture(ctx
, texObj
);
2682 else if (target
== GL_PROXY_TEXTURE_3D
||
2683 (ctx
->Extensions
.MESA_texture_array
&&
2684 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2685 /* Proxy texture: check for errors and update proxy state */
2686 struct gl_texture_image
*texImage
;
2687 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2688 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2689 format
, type
, 3, width
, height
, depth
, border
)) {
2690 /* when error, clear all proxy texture image parameters */
2692 clear_teximage_fields(texImage
);
2695 /* no error, set the tex image parameters */
2696 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2697 depth
, border
, internalFormat
);
2698 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2699 internalFormat
, format
, type
);
2703 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2710 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2711 GLsizei width
, GLsizei height
, GLsizei depth
,
2712 GLint border
, GLenum format
, GLenum type
,
2713 const GLvoid
*pixels
)
2715 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2716 depth
, border
, format
, type
, pixels
);
2722 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2723 GLint xoffset
, GLsizei width
,
2724 GLenum format
, GLenum type
,
2725 const GLvoid
*pixels
)
2727 GLsizei postConvWidth
= width
;
2728 struct gl_texture_unit
*texUnit
;
2729 struct gl_texture_object
*texObj
;
2730 struct gl_texture_image
*texImage
= NULL
;
2731 GET_CURRENT_CONTEXT(ctx
);
2732 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2734 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2735 _mesa_update_state(ctx
);
2737 #if FEATURE_convolve
2738 /* XXX should test internal format */
2739 if (_mesa_is_color_format(format
)) {
2740 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2744 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2745 postConvWidth
, 1, 1, format
, type
)) {
2746 return; /* error was detected */
2750 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2751 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2754 _mesa_lock_texture(ctx
, texObj
);
2756 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2758 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2759 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2760 goto out
; /* error was detected */
2764 goto out
; /* no-op, not an error */
2766 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2767 xoffset
+= texImage
->Border
;
2769 ASSERT(ctx
->Driver
.TexSubImage1D
);
2770 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2771 format
, type
, pixels
, &ctx
->Unpack
,
2773 ctx
->NewState
|= _NEW_TEXTURE
;
2776 _mesa_unlock_texture(ctx
, texObj
);
2781 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2782 GLint xoffset
, GLint yoffset
,
2783 GLsizei width
, GLsizei height
,
2784 GLenum format
, GLenum type
,
2785 const GLvoid
*pixels
)
2787 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2788 struct gl_texture_unit
*texUnit
;
2789 struct gl_texture_object
*texObj
;
2790 struct gl_texture_image
*texImage
;
2791 GET_CURRENT_CONTEXT(ctx
);
2792 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2794 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2795 _mesa_update_state(ctx
);
2797 #if FEATURE_convolve
2798 /* XXX should test internal format */
2799 if (_mesa_is_color_format(format
)) {
2800 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2805 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2806 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2807 return; /* error was detected */
2810 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2811 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2812 _mesa_lock_texture(ctx
, texObj
);
2814 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2816 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2817 postConvWidth
, postConvHeight
, 1, format
, type
,
2819 goto out
; /* error was detected */
2822 if (width
== 0 || height
== 0)
2823 goto out
; /* no-op, not an error */
2825 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2826 xoffset
+= texImage
->Border
;
2827 yoffset
+= texImage
->Border
;
2829 ASSERT(ctx
->Driver
.TexSubImage2D
);
2830 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2831 width
, height
, format
, type
, pixels
,
2832 &ctx
->Unpack
, texObj
, texImage
);
2833 ctx
->NewState
|= _NEW_TEXTURE
;
2836 _mesa_unlock_texture(ctx
, texObj
);
2842 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2843 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2844 GLsizei width
, GLsizei height
, GLsizei depth
,
2845 GLenum format
, GLenum type
,
2846 const GLvoid
*pixels
)
2848 struct gl_texture_unit
*texUnit
;
2849 struct gl_texture_object
*texObj
;
2850 struct gl_texture_image
*texImage
;
2851 GET_CURRENT_CONTEXT(ctx
);
2852 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2854 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2855 _mesa_update_state(ctx
);
2857 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2858 width
, height
, depth
, format
, type
)) {
2859 return; /* error was detected */
2862 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2863 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2865 _mesa_lock_texture(ctx
, texObj
);
2867 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2869 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2870 width
, height
, depth
, format
, type
, texImage
)) {
2871 goto out
; /* error was detected */
2874 if (width
== 0 || height
== 0 || height
== 0)
2875 goto out
; /* no-op, not an error */
2877 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2878 xoffset
+= texImage
->Border
;
2879 yoffset
+= texImage
->Border
;
2880 zoffset
+= texImage
->Border
;
2882 ASSERT(ctx
->Driver
.TexSubImage3D
);
2883 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2884 xoffset
, yoffset
, zoffset
,
2885 width
, height
, depth
,
2886 format
, type
, pixels
,
2887 &ctx
->Unpack
, texObj
, texImage
);
2888 ctx
->NewState
|= _NEW_TEXTURE
;
2891 _mesa_unlock_texture(ctx
, texObj
);
2897 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2898 GLenum internalFormat
,
2900 GLsizei width
, GLint border
)
2902 struct gl_texture_unit
*texUnit
;
2903 struct gl_texture_object
*texObj
;
2904 struct gl_texture_image
*texImage
;
2905 GLsizei postConvWidth
= width
;
2906 const GLuint face
= _mesa_tex_target_to_face(target
);
2907 GET_CURRENT_CONTEXT(ctx
);
2908 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2910 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2911 _mesa_update_state(ctx
);
2913 #if FEATURE_convolve
2914 if (_mesa_is_color_format(internalFormat
)) {
2915 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2919 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2920 postConvWidth
, 1, border
))
2923 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2924 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2925 _mesa_lock_texture(ctx
, texObj
);
2927 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2929 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2933 if (texImage
->Data
) {
2934 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2937 ASSERT(texImage
->Data
== NULL
);
2939 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2940 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2941 border
, internalFormat
);
2944 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2945 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2946 x
, y
, width
, border
);
2948 ASSERT(texImage
->TexFormat
);
2950 update_fbo_texture(ctx
, texObj
, face
, level
);
2953 texObj
->_Complete
= GL_FALSE
;
2954 ctx
->NewState
|= _NEW_TEXTURE
;
2957 _mesa_unlock_texture(ctx
, texObj
);
2963 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2964 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2967 struct gl_texture_unit
*texUnit
;
2968 struct gl_texture_object
*texObj
;
2969 struct gl_texture_image
*texImage
;
2970 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2971 const GLuint face
= _mesa_tex_target_to_face(target
);
2972 GET_CURRENT_CONTEXT(ctx
);
2973 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2975 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2976 _mesa_update_state(ctx
);
2978 #if FEATURE_convolve
2979 if (_mesa_is_color_format(internalFormat
)) {
2980 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2985 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2986 postConvWidth
, postConvHeight
, border
))
2989 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2990 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2992 _mesa_lock_texture(ctx
, texObj
);
2994 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2997 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3001 if (texImage
->Data
) {
3002 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3005 ASSERT(texImage
->Data
== NULL
);
3007 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3008 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3009 postConvWidth
, postConvHeight
, 1,
3010 border
, internalFormat
);
3012 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3013 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3014 x
, y
, width
, height
, border
);
3016 ASSERT(texImage
->TexFormat
);
3018 update_fbo_texture(ctx
, texObj
, face
, level
);
3021 texObj
->_Complete
= GL_FALSE
;
3022 ctx
->NewState
|= _NEW_TEXTURE
;
3025 _mesa_unlock_texture(ctx
, texObj
);
3030 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3031 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3033 struct gl_texture_unit
*texUnit
;
3034 struct gl_texture_object
*texObj
;
3035 struct gl_texture_image
*texImage
;
3036 GLsizei postConvWidth
= width
;
3040 GET_CURRENT_CONTEXT(ctx
);
3041 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3043 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3044 _mesa_update_state(ctx
);
3046 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3049 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3050 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3052 _mesa_lock_texture(ctx
, texObj
);
3054 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3056 #if FEATURE_convolve
3057 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3058 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3062 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3063 xoffset
, 0, 0, postConvWidth
, 1,
3068 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3069 xoffset
+= texImage
->Border
;
3071 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3073 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3074 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3075 xoffset
, x
, y
, width
);
3078 ctx
->NewState
|= _NEW_TEXTURE
;
3081 _mesa_unlock_texture(ctx
, texObj
);
3087 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3088 GLint xoffset
, GLint yoffset
,
3089 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3091 struct gl_texture_unit
*texUnit
;
3092 struct gl_texture_object
*texObj
;
3093 struct gl_texture_image
*texImage
;
3094 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3095 GET_CURRENT_CONTEXT(ctx
);
3096 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3098 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3099 _mesa_update_state(ctx
);
3101 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3104 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3105 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3107 _mesa_lock_texture(ctx
, texObj
);
3109 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3111 #if FEATURE_convolve
3112 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3113 _mesa_adjust_image_for_convolution(ctx
, 2,
3114 &postConvWidth
, &postConvHeight
);
3118 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3119 postConvWidth
, postConvHeight
, texImage
))
3122 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3123 xoffset
+= texImage
->Border
;
3124 yoffset
+= texImage
->Border
;
3126 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3128 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3129 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3130 xoffset
, yoffset
, x
, y
, width
, height
);
3133 ctx
->NewState
|= _NEW_TEXTURE
;
3136 _mesa_unlock_texture(ctx
, texObj
);
3142 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3143 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3144 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3146 struct gl_texture_unit
*texUnit
;
3147 struct gl_texture_object
*texObj
;
3148 struct gl_texture_image
*texImage
;
3149 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3150 GET_CURRENT_CONTEXT(ctx
);
3151 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3153 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3154 _mesa_update_state(ctx
);
3156 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3159 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3160 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3162 _mesa_lock_texture(ctx
, texObj
);
3164 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3166 #if FEATURE_convolve
3167 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3168 _mesa_adjust_image_for_convolution(ctx
, 2,
3169 &postConvWidth
, &postConvHeight
);
3173 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3174 zoffset
, postConvWidth
, postConvHeight
,
3178 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3179 xoffset
+= texImage
->Border
;
3180 yoffset
+= texImage
->Border
;
3181 zoffset
+= texImage
->Border
;
3183 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3185 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3186 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3187 xoffset
, yoffset
, zoffset
,
3188 x
, y
, width
, height
);
3191 ctx
->NewState
|= _NEW_TEXTURE
;
3194 _mesa_unlock_texture(ctx
, texObj
);
3200 /**********************************************************************/
3201 /****** Compressed Textures ******/
3202 /**********************************************************************/
3206 * Error checking for glCompressedTexImage[123]D().
3207 * \return error code or GL_NO_ERROR.
3210 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3211 GLenum target
, GLint level
,
3212 GLenum internalFormat
, GLsizei width
,
3213 GLsizei height
, GLsizei depth
, GLint border
,
3216 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3218 if (dimensions
== 1) {
3219 /* 1D compressed textures not allowed */
3220 return GL_INVALID_ENUM
;
3222 else if (dimensions
== 2) {
3223 if (target
== GL_PROXY_TEXTURE_2D
) {
3224 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3226 else if (target
== GL_TEXTURE_2D
) {
3227 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3229 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3230 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3231 return GL_INVALID_ENUM
; /*target*/
3232 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3234 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3235 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3236 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3237 return GL_INVALID_ENUM
; /*target*/
3238 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3241 return GL_INVALID_ENUM
; /*target*/
3244 else if (dimensions
== 3) {
3245 /* 3D compressed textures not allowed */
3246 return GL_INVALID_ENUM
;
3249 maxTextureSize
= 1 << (maxLevels
- 1);
3251 /* This will detect any invalid internalFormat value */
3252 if (!is_compressed_format(ctx
, internalFormat
))
3253 return GL_INVALID_ENUM
;
3255 /* This should really never fail */
3256 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3257 return GL_INVALID_ENUM
;
3260 return GL_INVALID_VALUE
;
3263 * XXX We should probably use the proxy texture error check function here.
3265 if (width
< 1 || width
> maxTextureSize
||
3266 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3267 return GL_INVALID_VALUE
;
3269 if ((height
< 1 || height
> maxTextureSize
||
3270 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3272 return GL_INVALID_VALUE
;
3274 if ((depth
< 1 || depth
> maxTextureSize
||
3275 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3277 return GL_INVALID_VALUE
;
3279 /* For cube map, width must equal height */
3280 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3281 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3282 return GL_INVALID_VALUE
;
3284 if (level
< 0 || level
>= maxLevels
)
3285 return GL_INVALID_VALUE
;
3287 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3288 depth
, internalFormat
);
3289 if (expectedSize
!= imageSize
)
3290 return GL_INVALID_VALUE
;
3292 #if FEATURE_EXT_texture_sRGB
3293 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3294 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3295 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3296 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3298 return GL_INVALID_OPERATION
;
3307 * Error checking for glCompressedTexSubImage[123]D().
3308 * \warning There are some bad assumptions here about the size of compressed
3309 * texture tiles (multiple of 4) used to test the validity of the
3310 * offset and size parameters.
3311 * \return error code or GL_NO_ERROR.
3314 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3315 GLenum target
, GLint level
,
3316 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3317 GLsizei width
, GLsizei height
, GLsizei depth
,
3318 GLenum format
, GLsizei imageSize
)
3320 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3323 if (dimensions
== 1) {
3324 /* 1D compressed textures not allowed */
3325 return GL_INVALID_ENUM
;
3327 else if (dimensions
== 2) {
3328 if (target
== GL_PROXY_TEXTURE_2D
) {
3329 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3331 else if (target
== GL_TEXTURE_2D
) {
3332 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3334 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3335 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3336 return GL_INVALID_ENUM
; /*target*/
3337 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3339 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3340 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3341 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3342 return GL_INVALID_ENUM
; /*target*/
3343 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3346 return GL_INVALID_ENUM
; /*target*/
3349 else if (dimensions
== 3) {
3350 /* 3D compressed textures not allowed */
3351 return GL_INVALID_ENUM
;
3354 maxTextureSize
= 1 << (maxLevels
- 1);
3356 /* this will catch any invalid compressed format token */
3357 if (!is_compressed_format(ctx
, format
))
3358 return GL_INVALID_ENUM
;
3360 if (width
< 1 || width
> maxTextureSize
)
3361 return GL_INVALID_VALUE
;
3363 if ((height
< 1 || height
> maxTextureSize
)
3365 return GL_INVALID_VALUE
;
3367 if (level
< 0 || level
>= maxLevels
)
3368 return GL_INVALID_VALUE
;
3370 /* XXX these tests are specific to the compressed format.
3371 * this code should be generalized in some way.
3373 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3374 return GL_INVALID_VALUE
;
3376 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3377 return GL_INVALID_VALUE
;
3379 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3380 return GL_INVALID_VALUE
;
3382 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3384 if (expectedSize
!= imageSize
)
3385 return GL_INVALID_VALUE
;
3393 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3394 GLenum internalFormat
, GLsizei width
,
3395 GLint border
, GLsizei imageSize
,
3398 GET_CURRENT_CONTEXT(ctx
);
3399 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3401 if (target
== GL_TEXTURE_1D
) {
3402 /* non-proxy target */
3403 struct gl_texture_unit
*texUnit
;
3404 struct gl_texture_object
*texObj
;
3405 struct gl_texture_image
*texImage
;
3406 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3407 internalFormat
, width
, 1, 1, border
, imageSize
);
3409 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3413 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3414 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3416 _mesa_lock_texture(ctx
, texObj
);
3418 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3420 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3424 if (texImage
->Data
) {
3425 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3427 ASSERT(texImage
->Data
== NULL
);
3429 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3430 border
, internalFormat
);
3432 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3433 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3434 internalFormat
, width
, border
,
3439 texObj
->_Complete
= GL_FALSE
;
3440 ctx
->NewState
|= _NEW_TEXTURE
;
3443 _mesa_unlock_texture(ctx
, texObj
);
3445 else if (target
== GL_PROXY_TEXTURE_1D
) {
3446 /* Proxy texture: check for errors and update proxy state */
3447 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3448 internalFormat
, width
, 1, 1, border
, imageSize
);
3450 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3451 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3452 internalFormat
, GL_NONE
, GL_NONE
,
3453 width
, 1, 1, border
);
3456 /* if error, clear all proxy texture image parameters */
3457 struct gl_texture_image
*texImage
;
3458 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3460 clear_teximage_fields(texImage
);
3463 /* store the teximage parameters */
3464 struct gl_texture_unit
*texUnit
;
3465 struct gl_texture_object
*texObj
;
3466 struct gl_texture_image
*texImage
;
3467 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3468 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3470 _mesa_lock_texture(ctx
, texObj
);
3472 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3473 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3474 border
, internalFormat
);
3476 _mesa_unlock_texture(ctx
, texObj
);
3480 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3487 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3488 GLenum internalFormat
, GLsizei width
,
3489 GLsizei height
, GLint border
, GLsizei imageSize
,
3492 GET_CURRENT_CONTEXT(ctx
);
3493 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3495 if (target
== GL_TEXTURE_2D
||
3496 (ctx
->Extensions
.ARB_texture_cube_map
&&
3497 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3498 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3499 /* non-proxy target */
3500 struct gl_texture_unit
*texUnit
;
3501 struct gl_texture_object
*texObj
;
3502 struct gl_texture_image
*texImage
;
3503 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3504 internalFormat
, width
, height
, 1, border
, imageSize
);
3506 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3510 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3511 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3513 _mesa_lock_texture(ctx
, texObj
);
3515 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3517 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3521 if (texImage
->Data
) {
3522 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3524 ASSERT(texImage
->Data
== NULL
);
3526 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3527 border
, internalFormat
);
3529 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3530 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3531 internalFormat
, width
, height
,
3532 border
, imageSize
, data
,
3536 texObj
->_Complete
= GL_FALSE
;
3537 ctx
->NewState
|= _NEW_TEXTURE
;
3540 _mesa_unlock_texture(ctx
, texObj
);
3542 else if (target
== GL_PROXY_TEXTURE_2D
||
3543 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3544 ctx
->Extensions
.ARB_texture_cube_map
)) {
3545 /* Proxy texture: check for errors and update proxy state */
3546 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3547 internalFormat
, width
, height
, 1, border
, imageSize
);
3549 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3550 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3551 internalFormat
, GL_NONE
, GL_NONE
,
3552 width
, height
, 1, border
);
3555 /* if error, clear all proxy texture image parameters */
3556 struct gl_texture_image
*texImage
;
3557 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3559 clear_teximage_fields(texImage
);
3562 /* store the teximage parameters */
3563 struct gl_texture_unit
*texUnit
;
3564 struct gl_texture_object
*texObj
;
3565 struct gl_texture_image
*texImage
;
3566 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3567 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3569 _mesa_lock_texture(ctx
, texObj
);
3571 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3572 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3573 border
, internalFormat
);
3575 _mesa_unlock_texture(ctx
, texObj
);
3579 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3586 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3587 GLenum internalFormat
, GLsizei width
,
3588 GLsizei height
, GLsizei depth
, GLint border
,
3589 GLsizei imageSize
, const GLvoid
*data
)
3591 GET_CURRENT_CONTEXT(ctx
);
3592 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3594 if (target
== GL_TEXTURE_3D
) {
3595 /* non-proxy target */
3596 struct gl_texture_unit
*texUnit
;
3597 struct gl_texture_object
*texObj
;
3598 struct gl_texture_image
*texImage
;
3599 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3600 internalFormat
, width
, height
, depth
, border
, imageSize
);
3602 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3606 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3607 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3608 _mesa_lock_texture(ctx
, texObj
);
3610 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3612 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3616 if (texImage
->Data
) {
3617 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3619 ASSERT(texImage
->Data
== NULL
);
3621 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3622 border
, internalFormat
);
3624 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3625 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3627 width
, height
, depth
,
3628 border
, imageSize
, data
,
3632 texObj
->_Complete
= GL_FALSE
;
3633 ctx
->NewState
|= _NEW_TEXTURE
;
3636 _mesa_unlock_texture(ctx
, texObj
);
3638 else if (target
== GL_PROXY_TEXTURE_3D
) {
3639 /* Proxy texture: check for errors and update proxy state */
3640 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3641 internalFormat
, width
, height
, depth
, border
, imageSize
);
3643 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3644 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3645 internalFormat
, GL_NONE
, GL_NONE
,
3646 width
, height
, depth
, border
);
3649 /* if error, clear all proxy texture image parameters */
3650 struct gl_texture_image
*texImage
;
3651 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3653 clear_teximage_fields(texImage
);
3656 /* store the teximage parameters */
3657 struct gl_texture_unit
*texUnit
;
3658 struct gl_texture_object
*texObj
;
3659 struct gl_texture_image
*texImage
;
3660 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3661 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3662 _mesa_lock_texture(ctx
, texObj
);
3664 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3665 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3666 depth
, border
, internalFormat
);
3668 _mesa_unlock_texture(ctx
, texObj
);
3672 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3679 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3680 GLsizei width
, GLenum format
,
3681 GLsizei imageSize
, const GLvoid
*data
)
3683 struct gl_texture_unit
*texUnit
;
3684 struct gl_texture_object
*texObj
;
3685 struct gl_texture_image
*texImage
;
3687 GET_CURRENT_CONTEXT(ctx
);
3688 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3690 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3691 xoffset
, 0, 0, /* pos */
3692 width
, 1, 1, /* size */
3695 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3699 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3700 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3701 _mesa_lock_texture(ctx
, texObj
);
3703 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3706 if ((GLint
) format
!= texImage
->InternalFormat
) {
3707 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3708 "glCompressedTexSubImage1D(format)");
3712 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3713 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3718 goto out
; /* no-op, not an error */
3720 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3721 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3723 format
, imageSize
, data
,
3726 ctx
->NewState
|= _NEW_TEXTURE
;
3729 _mesa_unlock_texture(ctx
, texObj
);
3734 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3735 GLint yoffset
, GLsizei width
, GLsizei height
,
3736 GLenum format
, GLsizei imageSize
,
3739 struct gl_texture_unit
*texUnit
;
3740 struct gl_texture_object
*texObj
;
3741 struct gl_texture_image
*texImage
;
3743 GET_CURRENT_CONTEXT(ctx
);
3744 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3746 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3747 xoffset
, yoffset
, 0, /* pos */
3748 width
, height
, 1, /* size */
3751 /* XXX proxy target? */
3752 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3756 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3757 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3758 _mesa_lock_texture(ctx
, texObj
);
3760 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3763 if ((GLint
) format
!= texImage
->InternalFormat
) {
3764 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3765 "glCompressedTexSubImage2D(format)");
3769 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3770 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3771 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3775 if (width
== 0 || height
== 0)
3776 goto out
; /* no-op, not an error */
3778 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3779 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3780 xoffset
, yoffset
, width
, height
,
3781 format
, imageSize
, data
,
3784 ctx
->NewState
|= _NEW_TEXTURE
;
3787 _mesa_unlock_texture(ctx
, texObj
);
3792 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3793 GLint yoffset
, GLint zoffset
, GLsizei width
,
3794 GLsizei height
, GLsizei depth
, GLenum format
,
3795 GLsizei imageSize
, const GLvoid
*data
)
3797 struct gl_texture_unit
*texUnit
;
3798 struct gl_texture_object
*texObj
;
3799 struct gl_texture_image
*texImage
;
3801 GET_CURRENT_CONTEXT(ctx
);
3802 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3804 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3805 xoffset
, yoffset
, zoffset
,/*pos*/
3806 width
, height
, depth
, /*size*/
3809 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3813 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3814 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3815 _mesa_lock_texture(ctx
, texObj
);
3817 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3820 if ((GLint
) format
!= texImage
->InternalFormat
) {
3821 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3822 "glCompressedTexSubImage3D(format)");
3826 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3827 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3828 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3829 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3833 if (width
== 0 || height
== 0 || depth
== 0)
3834 goto out
; /* no-op, not an error */
3836 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3837 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3838 xoffset
, yoffset
, zoffset
,
3839 width
, height
, depth
,
3840 format
, imageSize
, data
,
3843 ctx
->NewState
|= _NEW_TEXTURE
;
3846 _mesa_unlock_texture(ctx
, texObj
);
3851 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3853 const struct gl_texture_unit
*texUnit
;
3854 struct gl_texture_object
*texObj
;
3855 struct gl_texture_image
*texImage
;
3857 GET_CURRENT_CONTEXT(ctx
);
3858 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3860 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3861 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3863 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3867 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3868 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3870 if (level
< 0 || level
>= maxLevels
) {
3871 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3875 if (_mesa_is_proxy_texture(target
)) {
3876 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3880 _mesa_lock_texture(ctx
, texObj
);
3882 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3884 if (texImage
->IsCompressed
) {
3885 /* this typically calls _mesa_get_compressed_teximage() */
3886 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3890 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3891 "glGetCompressedTexImageARB");
3895 /* probably invalid mipmap level */
3896 _mesa_error(ctx
, GL_INVALID_VALUE
,
3897 "glGetCompressedTexImageARB(level)");
3900 _mesa_unlock_texture(ctx
, texObj
);