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
;
1164 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1165 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1166 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1167 img
->WidthLog2
= logbase2(img
->Width2
);
1168 if (height
== 1) /* 1-D texture */
1169 img
->HeightLog2
= 0;
1171 img
->HeightLog2
= logbase2(img
->Height2
);
1172 if (depth
== 1) /* 2-D texture */
1175 img
->DepthLog2
= logbase2(img
->Depth2
);
1176 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1177 img
->IsCompressed
= GL_FALSE
;
1178 img
->CompressedSize
= 0;
1180 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1181 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1182 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1183 img
->_IsPowerOfTwo
= GL_TRUE
;
1185 img
->_IsPowerOfTwo
= GL_FALSE
;
1187 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1188 img
->RowStride
= width
;
1189 /* Allocate the ImageOffsets array and initialize to typical values.
1190 * We allocate the array for 1D/2D textures too in order to avoid special-
1191 * case code in the texstore routines.
1193 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1194 for (i
= 0; i
< depth
; i
++) {
1195 img
->ImageOffsets
[i
] = i
* width
* height
;
1198 /* Compute Width/Height/DepthScale for mipmap lod computation */
1199 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1200 /* scale = 1.0 since texture coords directly map to texels */
1201 img
->WidthScale
= 1.0;
1202 img
->HeightScale
= 1.0;
1203 img
->DepthScale
= 1.0;
1206 img
->WidthScale
= (GLfloat
) img
->Width
;
1207 img
->HeightScale
= (GLfloat
) img
->Height
;
1208 img
->DepthScale
= (GLfloat
) img
->Depth
;
1214 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1215 * level, width, height and depth against the ctx->Const limits for textures.
1217 * A hardware driver might override this function if, for example, the
1218 * max 3D texture size is 512x512x64 (i.e. not a cube).
1220 * Note that width, height, depth == 0 is not an error. However, a
1221 * texture with zero width/height/depth will be considered "incomplete"
1222 * and texturing will effectively be disabled.
1224 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1225 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1226 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1227 * \param level as passed to glTexImage
1228 * \param internalFormat as passed to glTexImage
1229 * \param format as passed to glTexImage
1230 * \param type as passed to glTexImage
1231 * \param width as passed to glTexImage
1232 * \param height as passed to glTexImage
1233 * \param depth as passed to glTexImage
1234 * \param border as passed to glTexImage
1235 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1238 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1239 GLint internalFormat
, GLenum format
, GLenum type
,
1240 GLint width
, GLint height
, GLint depth
, GLint border
)
1244 (void) internalFormat
;
1249 case GL_PROXY_TEXTURE_1D
:
1250 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1251 if (width
< 2 * border
|| width
> 2 + maxSize
||
1252 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1253 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1254 level
>= ctx
->Const
.MaxTextureLevels
) {
1255 /* bad width or level */
1259 case GL_PROXY_TEXTURE_2D
:
1260 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1261 if (width
< 2 * border
|| width
> 2 + maxSize
||
1262 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1263 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1264 height
< 2 * border
|| height
> 2 + maxSize
||
1265 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1266 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1267 level
>= ctx
->Const
.MaxTextureLevels
) {
1268 /* bad width or height or level */
1272 case GL_PROXY_TEXTURE_3D
:
1273 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1274 if (width
< 2 * border
|| width
> 2 + maxSize
||
1275 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1276 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1277 height
< 2 * border
|| height
> 2 + maxSize
||
1278 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1279 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1280 depth
< 2 * border
|| depth
> 2 + maxSize
||
1281 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1282 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1283 level
>= ctx
->Const
.Max3DTextureLevels
) {
1284 /* bad width or height or depth or level */
1288 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1289 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1290 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1292 /* bad width or height or level */
1296 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1297 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1298 if (width
< 2 * border
|| width
> 2 + maxSize
||
1299 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1300 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1301 height
< 2 * border
|| height
> 2 + maxSize
||
1302 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1303 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1304 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1305 /* bad width or height */
1309 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1310 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1311 if (width
< 2 * border
|| width
> 2 + maxSize
||
1312 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1313 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1314 level
>= ctx
->Const
.MaxTextureLevels
) {
1315 /* bad width or level */
1319 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1323 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1324 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1325 if (width
< 2 * border
|| width
> 2 + maxSize
||
1326 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1327 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1328 height
< 2 * border
|| height
> 2 + maxSize
||
1329 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1330 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1331 level
>= ctx
->Const
.MaxTextureLevels
) {
1332 /* bad width or height or level */
1335 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1340 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1347 * Helper function to determine whether a target supports compressed textures
1350 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1352 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1353 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1354 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1355 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1356 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1357 || ((ctx
->Extensions
.MESA_texture_array
&&
1358 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1359 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1364 * Test the glTexImage[123]D() parameters for errors.
1366 * \param ctx GL context.
1367 * \param target texture target given by the user.
1368 * \param level image level given by the user.
1369 * \param internalFormat internal format given by the user.
1370 * \param format pixel data format given by the user.
1371 * \param type pixel data type given by the user.
1372 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1373 * \param width image width given by the user.
1374 * \param height image height given by the user.
1375 * \param depth image depth given by the user.
1376 * \param border image border given by the user.
1378 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1380 * Verifies each of the parameters against the constants specified in
1381 * __GLcontextRec::Const and the supported extensions, and according to the
1382 * OpenGL specification.
1385 texture_error_check( GLcontext
*ctx
, GLenum target
,
1386 GLint level
, GLint internalFormat
,
1387 GLenum format
, GLenum type
,
1389 GLint width
, GLint height
,
1390 GLint depth
, GLint border
)
1392 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1393 GLboolean sizeOK
= GL_TRUE
;
1394 GLboolean colorFormat
, indexFormat
;
1395 GLenum proxy_target
;
1397 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1398 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1400 _mesa_error(ctx
, GL_INVALID_VALUE
,
1401 "glTexImage%dD(level=%d)", dimensions
, level
);
1407 if (border
< 0 || border
> 1 ||
1408 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1409 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1411 _mesa_error(ctx
, GL_INVALID_VALUE
,
1412 "glTexImage%dD(border=%d)", dimensions
, border
);
1417 if (width
< 0 || height
< 0 || depth
< 0) {
1419 _mesa_error(ctx
, GL_INVALID_VALUE
,
1420 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1425 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1426 * level, width, height and depth.
1428 if (dimensions
== 1) {
1429 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1430 proxy_target
= GL_PROXY_TEXTURE_1D
;
1435 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1439 else if (dimensions
== 2) {
1441 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1442 proxy_target
= GL_PROXY_TEXTURE_2D
;
1444 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1445 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1446 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1447 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1448 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1451 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1452 sizeOK
= (width
== height
);
1454 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1455 target
== GL_TEXTURE_RECTANGLE_NV
) {
1456 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1457 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1460 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1462 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1463 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1464 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1467 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1471 else if (dimensions
== 3) {
1472 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1473 proxy_target
= GL_PROXY_TEXTURE_3D
;
1475 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1476 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1477 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1480 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1485 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1489 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1490 internalFormat
, format
,
1491 type
, width
, height
,
1495 _mesa_error(ctx
, GL_INVALID_VALUE
,
1496 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1497 dimensions
, level
, width
, height
, depth
);
1502 /* Check internalFormat */
1503 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1505 _mesa_error(ctx
, GL_INVALID_VALUE
,
1506 "glTexImage%dD(internalFormat=0x%x)",
1507 dimensions
, internalFormat
);
1512 /* Check incoming image format and type */
1513 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1514 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1515 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1518 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1519 "glTexImage%dD(format or type)", dimensions
);
1524 /* make sure internal format and format basically agree */
1525 colorFormat
= _mesa_is_color_format(format
);
1526 indexFormat
= is_index_format(format
);
1527 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1528 (is_index_format(internalFormat
) && !indexFormat
) ||
1529 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1530 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1531 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
))) {
1533 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1534 "glTexImage(internalFormat/format)");
1538 /* additional checks for ycbcr textures */
1539 if (internalFormat
== GL_YCBCR_MESA
) {
1540 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1541 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1542 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1544 _mesa_sprintf(message
,
1545 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1546 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1547 return GL_TRUE
; /* error */
1549 if (target
!= GL_TEXTURE_2D
&&
1550 target
!= GL_PROXY_TEXTURE_2D
&&
1551 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1552 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1554 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1560 _mesa_sprintf(message
,
1561 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1562 dimensions
, border
);
1563 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1569 /* additional checks for depth textures */
1570 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1571 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1572 if (target
!= GL_TEXTURE_1D
&&
1573 target
!= GL_PROXY_TEXTURE_1D
&&
1574 target
!= GL_TEXTURE_2D
&&
1575 target
!= GL_PROXY_TEXTURE_2D
&&
1576 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1577 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1579 _mesa_error(ctx
, GL_INVALID_ENUM
,
1580 "glTexImage(target/internalFormat)");
1585 /* additional checks for compressed textures */
1586 if (is_compressed_format(ctx
, internalFormat
)) {
1587 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1588 _mesa_error(ctx
, GL_INVALID_ENUM
,
1589 "glTexImage%d(target)", dimensions
);
1594 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1595 "glTexImage%D(border!=0)", dimensions
);
1601 /* if we get here, the parameters are OK */
1607 * Test glTexSubImage[123]D() parameters for errors.
1609 * \param ctx GL context.
1610 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1611 * \param target texture target given by the user.
1612 * \param level image level given by the user.
1613 * \param xoffset sub-image x offset given by the user.
1614 * \param yoffset sub-image y offset given by the user.
1615 * \param zoffset sub-image z offset given by the user.
1616 * \param format pixel data format given by the user.
1617 * \param type pixel data type given by the user.
1618 * \param width image width given by the user.
1619 * \param height image height given by the user.
1620 * \param depth image depth given by the user.
1622 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1624 * Verifies each of the parameters against the constants specified in
1625 * __GLcontextRec::Const and the supported extensions, and according to the
1626 * OpenGL specification.
1629 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1630 GLenum target
, GLint level
,
1631 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1632 GLint width
, GLint height
, GLint depth
,
1633 GLenum format
, GLenum type
)
1636 if (dimensions
== 1) {
1637 if (target
!= GL_TEXTURE_1D
) {
1638 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1642 else if (dimensions
== 2) {
1643 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1644 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1645 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1646 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1650 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1651 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1652 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1656 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1657 if (!ctx
->Extensions
.MESA_texture_array
) {
1658 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1662 else if (target
!= GL_TEXTURE_2D
) {
1663 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1667 else if (dimensions
== 3) {
1668 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1669 if (!ctx
->Extensions
.MESA_texture_array
) {
1670 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1674 else if (target
!= GL_TEXTURE_3D
) {
1675 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1680 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1684 /* Basic level check */
1685 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1686 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1691 _mesa_error(ctx
, GL_INVALID_VALUE
,
1692 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1695 if (height
< 0 && dimensions
> 1) {
1696 _mesa_error(ctx
, GL_INVALID_VALUE
,
1697 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1700 if (depth
< 0 && dimensions
> 2) {
1701 _mesa_error(ctx
, GL_INVALID_VALUE
,
1702 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1706 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1707 _mesa_error(ctx
, GL_INVALID_ENUM
,
1708 "glTexSubImage%dD(format or type)", dimensions
);
1716 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1717 GLenum target
, GLint level
,
1718 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1719 GLint width
, GLint height
, GLint depth
,
1720 GLenum format
, GLenum type
,
1721 const struct gl_texture_image
*destTex
)
1724 /* undefined image level */
1725 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1729 if (xoffset
< -((GLint
)destTex
->Border
)) {
1730 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1734 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1735 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1739 if (dimensions
> 1) {
1740 if (yoffset
< -((GLint
)destTex
->Border
)) {
1741 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1745 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1746 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1751 if (dimensions
> 2) {
1752 if (zoffset
< -((GLint
)destTex
->Border
)) {
1753 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1756 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1757 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1762 #if FEATURE_EXT_texture_sRGB
1763 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1764 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1765 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1766 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1767 if ((width
& 0x3) || (height
& 0x3) ||
1768 (xoffset
& 0x3) || (yoffset
& 0x3))
1769 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1770 "glTexSubImage%dD(size or offset not multiple of 4)",
1776 if (destTex
->IsCompressed
) {
1777 if (!target_can_be_compressed(ctx
, target
)) {
1778 _mesa_error(ctx
, GL_INVALID_ENUM
,
1779 "glTexSubImage%D(target)", dimensions
);
1782 /* offset must be multiple of 4 */
1783 if ((xoffset
& 3) || (yoffset
& 3)) {
1784 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1785 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1788 /* size must be multiple of 4 or equal to whole texture size */
1789 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1790 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1791 "glTexSubImage%D(width)", dimensions
);
1794 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1795 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1796 "glTexSubImage%D(width)", dimensions
);
1806 * Test glCopyTexImage[12]D() parameters for errors.
1808 * \param ctx GL context.
1809 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1810 * \param target texture target given by the user.
1811 * \param level image level given by the user.
1812 * \param internalFormat internal format given by the user.
1813 * \param width image width given by the user.
1814 * \param height image height given by the user.
1815 * \param depth image depth given by the user.
1816 * \param border texture border.
1818 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1820 * Verifies each of the parameters against the constants specified in
1821 * __GLcontextRec::Const and the supported extensions, and according to the
1822 * OpenGL specification.
1825 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1826 GLenum target
, GLint level
, GLint internalFormat
,
1827 GLint width
, GLint height
, GLint border
)
1833 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1834 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1835 _mesa_error(ctx
, GL_INVALID_VALUE
,
1836 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1840 /* Check that the source buffer is complete */
1841 if (ctx
->ReadBuffer
->Name
) {
1842 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1843 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1844 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1845 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1851 if (border
< 0 || border
> 1 ||
1852 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1853 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1857 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1859 _mesa_error(ctx
, GL_INVALID_VALUE
,
1860 "glCopyTexImage%dD(internalFormat)", dimensions
);
1864 /* NOTE: the format and type aren't really significant for
1865 * TestProxyTexImage(). Only the internalformat really matters.
1866 if (!_mesa_source_buffer_exists(ctx, format)) {
1867 _mesa_error(ctx, GL_INVALID_OPERATION,
1868 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1875 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1876 * level, width, height and depth.
1878 if (dimensions
== 1) {
1879 if (target
== GL_TEXTURE_1D
) {
1880 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1881 level
, internalFormat
,
1883 width
, 1, 1, border
);
1886 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1890 else if (dimensions
== 2) {
1891 if (target
== GL_TEXTURE_2D
) {
1892 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1893 level
, internalFormat
,
1895 width
, height
, 1, border
);
1897 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1898 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1899 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1900 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1903 sizeOK
= (width
== height
) &&
1904 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1905 level
, internalFormat
, format
, type
,
1906 width
, height
, 1, border
);
1908 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1909 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1910 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1913 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1914 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1915 level
, internalFormat
,
1917 width
, height
, 1, border
);
1919 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1920 if (!ctx
->Extensions
.MESA_texture_array
) {
1921 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1924 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1925 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1926 level
, internalFormat
,
1928 width
, height
, 1, border
);
1931 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1936 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1941 if (dimensions
== 1) {
1942 _mesa_error(ctx
, GL_INVALID_VALUE
,
1943 "glCopyTexImage1D(width=%d)", width
);
1946 ASSERT(dimensions
== 2);
1947 _mesa_error(ctx
, GL_INVALID_VALUE
,
1948 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1953 if (is_compressed_format(ctx
, internalFormat
)) {
1954 if (!target_can_be_compressed(ctx
, target
)) {
1955 _mesa_error(ctx
, GL_INVALID_ENUM
,
1956 "glCopyTexImage%d(target)", dimensions
);
1960 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1961 "glCopyTexImage%D(border!=0)", dimensions
);
1965 else if (is_depth_format(internalFormat
)) {
1966 /* make sure we have depth/stencil buffers */
1967 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1968 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1969 "glCopyTexImage%D(no depth)", dimensions
);
1973 else if (is_depthstencil_format(internalFormat
)) {
1974 /* make sure we have depth/stencil buffers */
1975 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1976 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1977 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
1982 /* if we get here, the parameters are OK */
1988 * Test glCopyTexSubImage[12]D() parameters for errors.
1989 * Note that this is the first part of error checking.
1990 * See also copytexsubimage_error_check2() below for the second part.
1992 * \param ctx GL context.
1993 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1994 * \param target texture target given by the user.
1995 * \param level image level given by the user.
1997 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2000 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
2001 GLenum target
, GLint level
)
2003 /* Check that the source buffer is complete */
2004 if (ctx
->ReadBuffer
->Name
) {
2005 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2006 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2007 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2008 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2014 if (dimensions
== 1) {
2015 if (target
!= GL_TEXTURE_1D
) {
2016 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2020 else if (dimensions
== 2) {
2021 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2022 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2023 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2024 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2028 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2029 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2030 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2034 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2035 if (!ctx
->Extensions
.MESA_texture_array
) {
2036 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2040 else if (target
!= GL_TEXTURE_2D
) {
2041 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2045 else if (dimensions
== 3) {
2046 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2047 (!ctx
->Extensions
.MESA_texture_array
))
2048 && (target
!= GL_TEXTURE_3D
)) {
2049 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2055 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2056 _mesa_error(ctx
, GL_INVALID_VALUE
,
2057 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2066 * Second part of error checking for glCopyTexSubImage[12]D().
2067 * \param xoffset sub-image x offset given by the user.
2068 * \param yoffset sub-image y offset given by the user.
2069 * \param zoffset sub-image z offset given by the user.
2070 * \param width image width given by the user.
2071 * \param height image height given by the user.
2074 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2075 GLenum target
, GLint level
,
2076 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2077 GLsizei width
, GLsizei height
,
2078 const struct gl_texture_image
*teximage
)
2080 /* check that dest tex image exists */
2082 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2083 "glCopyTexSubImage%dD(undefined texture level: %d)",
2090 _mesa_error(ctx
, GL_INVALID_VALUE
,
2091 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2094 if (dimensions
> 1 && height
< 0) {
2095 _mesa_error(ctx
, GL_INVALID_VALUE
,
2096 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2100 /* check x/y offsets */
2101 if (xoffset
< -((GLint
)teximage
->Border
)) {
2102 _mesa_error(ctx
, GL_INVALID_VALUE
,
2103 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2106 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2107 _mesa_error(ctx
, GL_INVALID_VALUE
,
2108 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2111 if (dimensions
> 1) {
2112 if (yoffset
< -((GLint
)teximage
->Border
)) {
2113 _mesa_error(ctx
, GL_INVALID_VALUE
,
2114 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2117 /* NOTE: we're adding the border here, not subtracting! */
2118 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2119 _mesa_error(ctx
, GL_INVALID_VALUE
,
2120 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2125 /* check z offset */
2126 if (dimensions
> 2) {
2127 if (zoffset
< -((GLint
)teximage
->Border
)) {
2128 _mesa_error(ctx
, GL_INVALID_VALUE
,
2129 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2132 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2133 _mesa_error(ctx
, GL_INVALID_VALUE
,
2134 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2139 if (teximage
->IsCompressed
) {
2140 if (!target_can_be_compressed(ctx
, target
)) {
2141 _mesa_error(ctx
, GL_INVALID_ENUM
,
2142 "glCopyTexSubImage%d(target)", dimensions
);
2145 /* offset must be multiple of 4 */
2146 if ((xoffset
& 3) || (yoffset
& 3)) {
2147 _mesa_error(ctx
, GL_INVALID_VALUE
,
2148 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2151 /* size must be multiple of 4 */
2152 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2153 _mesa_error(ctx
, GL_INVALID_VALUE
,
2154 "glCopyTexSubImage%D(width)", dimensions
);
2157 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2158 _mesa_error(ctx
, GL_INVALID_VALUE
,
2159 "glCopyTexSubImage%D(height)", dimensions
);
2164 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2165 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2169 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2170 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2171 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2172 dimensions
, teximage
->_BaseFormat
);
2176 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2177 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2178 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2179 "glCopyTexSubImage%D(no depth buffer)",
2184 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2185 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2186 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2187 "glCopyTexSubImage%D(no depth/stencil buffer)",
2193 /* if we get here, the parameters are OK */
2199 * Get texture image. Called by glGetTexImage.
2201 * \param target texture target.
2202 * \param level image level.
2203 * \param format pixel data format for returned image.
2204 * \param type pixel data type for returned image.
2205 * \param pixels returned pixel data.
2208 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2209 GLenum type
, GLvoid
*pixels
)
2211 const struct gl_texture_unit
*texUnit
;
2212 struct gl_texture_object
*texObj
;
2213 struct gl_texture_image
*texImage
;
2214 GLint maxLevels
= 0;
2215 GET_CURRENT_CONTEXT(ctx
);
2216 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2218 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2219 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2220 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2221 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2225 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2226 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2228 if (level
< 0 || level
>= maxLevels
) {
2229 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2233 if (_mesa_sizeof_packed_type(type
) <= 0) {
2234 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2238 if (_mesa_components_in_format(format
) <= 0 ||
2239 format
== GL_STENCIL_INDEX
) {
2240 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2244 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2245 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2249 if (!ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2250 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2254 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2255 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2259 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2260 && is_depthstencil_format(format
)) {
2261 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2265 _mesa_lock_texture(ctx
, texObj
);
2267 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2269 /* invalid mipmap level, not an error */
2274 /* Make sure the requested image format is compatible with the
2275 * texture's format. Note that a color index texture can be converted
2276 * to RGBA so that combo is allowed.
2278 if (_mesa_is_color_format(format
)
2279 && !_mesa_is_color_format(texImage
->TexFormat
->BaseFormat
)
2280 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2281 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2284 else if (is_index_format(format
)
2285 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2286 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2289 else if (is_depth_format(format
)
2290 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2291 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2292 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2295 else if (is_ycbcr_format(format
)
2296 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2297 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2300 else if (is_depthstencil_format(format
)
2301 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2302 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2306 if (ctx
->Pack
.BufferObj
->Name
) {
2307 /* packing texture image into a PBO */
2308 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2309 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2310 texImage
->Height
, texImage
->Depth
,
2311 format
, type
, pixels
)) {
2312 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2313 "glGetTexImage(invalid PBO access)");
2318 /* typically, this will call _mesa_get_teximage() */
2319 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2324 _mesa_unlock_texture(ctx
, texObj
);
2328 /** Callback info for walking over FBO hash table */
2332 struct gl_texture_object
*texObj
;
2338 * Check render to texture callback. Called from _mesa_HashWalk().
2341 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2343 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2344 const struct cb_info
*info
= (struct cb_info
*) userData
;
2345 GLcontext
*ctx
= info
->ctx
;
2346 const struct gl_texture_object
*texObj
= info
->texObj
;
2347 const GLuint level
= info
->level
, face
= info
->face
;
2349 /* If this is a user-created FBO */
2352 /* check if any of the FBO's attachments point to 'texObj' */
2353 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2354 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2355 if (att
->Type
== GL_TEXTURE
&&
2356 att
->Texture
== texObj
&&
2357 att
->TextureLevel
== level
&&
2358 att
->CubeMapFace
== face
) {
2359 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2360 /* Tell driver about the new renderbuffer texture */
2361 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2362 /* Mark fb status as indeterminate to force re-validation */
2371 * When a texture image is specified we have to check if it's bound to
2372 * any framebuffer objects (render to texture) in order to detect changes
2373 * in size or format since that effects FBO completeness.
2374 * Any FBOs rendering into the texture must be re-validated.
2377 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2378 GLuint face
, GLuint level
)
2380 /* Only check this texture if it's been marked as RenderToTexture */
2381 if (texObj
->_RenderToTexture
) {
2382 struct cb_info info
;
2384 info
.texObj
= texObj
;
2387 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2394 * Called from the API. Note that width includes the border.
2397 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2398 GLsizei width
, GLint border
, GLenum format
,
2399 GLenum type
, const GLvoid
*pixels
)
2401 GLsizei postConvWidth
= width
;
2402 GET_CURRENT_CONTEXT(ctx
);
2403 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2405 #if FEATURE_convolve
2406 if (_mesa_is_color_format(internalFormat
)) {
2407 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2411 if (target
== GL_TEXTURE_1D
) {
2412 /* non-proxy target */
2413 struct gl_texture_unit
*texUnit
;
2414 struct gl_texture_object
*texObj
;
2415 struct gl_texture_image
*texImage
;
2416 const GLuint face
= _mesa_tex_target_to_face(target
);
2418 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2419 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2420 return; /* error was recorded */
2423 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2424 _mesa_update_state(ctx
);
2426 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2427 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2428 _mesa_lock_texture(ctx
, texObj
);
2430 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2432 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2436 if (texImage
->Data
) {
2437 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2440 ASSERT(texImage
->Data
== NULL
);
2442 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2443 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2444 postConvWidth
, 1, 1,
2445 border
, internalFormat
);
2447 ASSERT(ctx
->Driver
.TexImage1D
);
2449 /* Give the texture to the driver! <pixels> may be null! */
2450 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2451 width
, border
, format
, type
, pixels
,
2452 &ctx
->Unpack
, texObj
, texImage
);
2454 ASSERT(texImage
->TexFormat
);
2456 update_fbo_texture(ctx
, texObj
, face
, level
);
2459 texObj
->_Complete
= GL_FALSE
;
2460 ctx
->NewState
|= _NEW_TEXTURE
;
2463 _mesa_unlock_texture(ctx
, texObj
);
2465 else if (target
== GL_PROXY_TEXTURE_1D
) {
2466 /* Proxy texture: check for errors and update proxy state */
2467 struct gl_texture_image
*texImage
;
2468 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2469 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2470 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2471 /* when error, clear all proxy texture image parameters */
2473 clear_teximage_fields(texImage
);
2476 /* no error, set the tex image parameters */
2478 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2479 postConvWidth
, 1, 1,
2480 border
, internalFormat
);
2481 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2482 internalFormat
, format
, type
);
2486 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2493 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2494 GLsizei width
, GLsizei height
, GLint border
,
2495 GLenum format
, GLenum type
,
2496 const GLvoid
*pixels
)
2498 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2499 GET_CURRENT_CONTEXT(ctx
);
2500 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2502 #if FEATURE_convolve
2503 if (_mesa_is_color_format(internalFormat
)) {
2504 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2509 if (target
== GL_TEXTURE_2D
||
2510 (ctx
->Extensions
.ARB_texture_cube_map
&&
2511 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2512 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2513 (ctx
->Extensions
.NV_texture_rectangle
&&
2514 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2515 (ctx
->Extensions
.MESA_texture_array
&&
2516 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2517 /* non-proxy target */
2518 struct gl_texture_unit
*texUnit
;
2519 struct gl_texture_object
*texObj
;
2520 struct gl_texture_image
*texImage
;
2521 const GLuint face
= _mesa_tex_target_to_face(target
);
2523 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2524 format
, type
, 2, postConvWidth
, postConvHeight
,
2526 return; /* error was recorded */
2529 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2530 _mesa_update_state(ctx
);
2532 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2533 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2534 _mesa_lock_texture(ctx
, texObj
);
2536 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2538 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2542 if (texImage
->Data
) {
2543 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2546 ASSERT(texImage
->Data
== NULL
);
2547 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2548 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2549 postConvWidth
, postConvHeight
, 1,
2550 border
, internalFormat
);
2552 ASSERT(ctx
->Driver
.TexImage2D
);
2554 /* Give the texture to the driver! <pixels> may be null! */
2555 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2556 width
, height
, border
, format
, type
, pixels
,
2557 &ctx
->Unpack
, texObj
, texImage
);
2559 ASSERT(texImage
->TexFormat
);
2561 update_fbo_texture(ctx
, texObj
, face
, level
);
2564 texObj
->_Complete
= GL_FALSE
;
2565 ctx
->NewState
|= _NEW_TEXTURE
;
2568 _mesa_unlock_texture(ctx
, texObj
);
2570 else if (target
== GL_PROXY_TEXTURE_2D
||
2571 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2572 ctx
->Extensions
.ARB_texture_cube_map
) ||
2573 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2574 ctx
->Extensions
.NV_texture_rectangle
) ||
2575 (ctx
->Extensions
.MESA_texture_array
&&
2576 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2577 /* Proxy texture: check for errors and update proxy state */
2578 struct gl_texture_image
*texImage
;
2579 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2580 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2581 format
, type
, 2, postConvWidth
, postConvHeight
,
2583 /* when error, clear all proxy texture image parameters */
2585 clear_teximage_fields(texImage
);
2588 /* no error, set the tex image parameters */
2589 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2590 postConvWidth
, postConvHeight
, 1,
2591 border
, internalFormat
);
2592 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2593 internalFormat
, format
, type
);
2597 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2604 * Called by the API or display list executor.
2605 * Note that width and height include the border.
2608 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2609 GLsizei width
, GLsizei height
, GLsizei depth
,
2610 GLint border
, GLenum format
, GLenum type
,
2611 const GLvoid
*pixels
)
2613 GET_CURRENT_CONTEXT(ctx
);
2614 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2616 if (target
== GL_TEXTURE_3D
||
2617 (ctx
->Extensions
.MESA_texture_array
&&
2618 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2619 /* non-proxy target */
2620 struct gl_texture_unit
*texUnit
;
2621 struct gl_texture_object
*texObj
;
2622 struct gl_texture_image
*texImage
;
2623 const GLuint face
= _mesa_tex_target_to_face(target
);
2625 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2626 format
, type
, 3, width
, height
, depth
, border
)) {
2627 return; /* error was recorded */
2630 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2631 _mesa_update_state(ctx
);
2633 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2634 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2635 _mesa_lock_texture(ctx
, texObj
);
2637 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2639 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2643 if (texImage
->Data
) {
2644 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2647 ASSERT(texImage
->Data
== NULL
);
2648 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2649 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2650 width
, height
, depth
,
2651 border
, internalFormat
);
2653 ASSERT(ctx
->Driver
.TexImage3D
);
2655 /* Give the texture to the driver! <pixels> may be null! */
2656 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2657 width
, height
, depth
, border
, format
, type
,
2658 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2660 ASSERT(texImage
->TexFormat
);
2662 update_fbo_texture(ctx
, texObj
, face
, level
);
2665 texObj
->_Complete
= GL_FALSE
;
2666 ctx
->NewState
|= _NEW_TEXTURE
;
2669 _mesa_unlock_texture(ctx
, texObj
);
2671 else if (target
== GL_PROXY_TEXTURE_3D
||
2672 (ctx
->Extensions
.MESA_texture_array
&&
2673 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2674 /* Proxy texture: check for errors and update proxy state */
2675 struct gl_texture_image
*texImage
;
2676 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2677 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2678 format
, type
, 3, width
, height
, depth
, border
)) {
2679 /* when error, clear all proxy texture image parameters */
2681 clear_teximage_fields(texImage
);
2684 /* no error, set the tex image parameters */
2685 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2686 depth
, border
, internalFormat
);
2687 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2688 internalFormat
, format
, type
);
2692 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2699 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2700 GLsizei width
, GLsizei height
, GLsizei depth
,
2701 GLint border
, GLenum format
, GLenum type
,
2702 const GLvoid
*pixels
)
2704 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2705 depth
, border
, format
, type
, pixels
);
2711 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2712 GLint xoffset
, GLsizei width
,
2713 GLenum format
, GLenum type
,
2714 const GLvoid
*pixels
)
2716 GLsizei postConvWidth
= width
;
2717 struct gl_texture_unit
*texUnit
;
2718 struct gl_texture_object
*texObj
;
2719 struct gl_texture_image
*texImage
= NULL
;
2720 GET_CURRENT_CONTEXT(ctx
);
2721 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2723 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2724 _mesa_update_state(ctx
);
2726 #if FEATURE_convolve
2727 /* XXX should test internal format */
2728 if (_mesa_is_color_format(format
)) {
2729 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2733 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2734 postConvWidth
, 1, 1, format
, type
)) {
2735 return; /* error was detected */
2739 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2740 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2743 _mesa_lock_texture(ctx
, texObj
);
2745 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2747 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2748 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2749 goto out
; /* error was detected */
2753 goto out
; /* no-op, not an error */
2755 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2756 xoffset
+= texImage
->Border
;
2758 ASSERT(ctx
->Driver
.TexSubImage1D
);
2759 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2760 format
, type
, pixels
, &ctx
->Unpack
,
2762 ctx
->NewState
|= _NEW_TEXTURE
;
2765 _mesa_unlock_texture(ctx
, texObj
);
2770 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2771 GLint xoffset
, GLint yoffset
,
2772 GLsizei width
, GLsizei height
,
2773 GLenum format
, GLenum type
,
2774 const GLvoid
*pixels
)
2776 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2777 struct gl_texture_unit
*texUnit
;
2778 struct gl_texture_object
*texObj
;
2779 struct gl_texture_image
*texImage
;
2780 GET_CURRENT_CONTEXT(ctx
);
2781 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2783 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2784 _mesa_update_state(ctx
);
2786 #if FEATURE_convolve
2787 /* XXX should test internal format */
2788 if (_mesa_is_color_format(format
)) {
2789 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2794 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2795 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2796 return; /* error was detected */
2799 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2800 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2801 _mesa_lock_texture(ctx
, texObj
);
2803 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2805 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2806 postConvWidth
, postConvHeight
, 1, format
, type
,
2808 goto out
; /* error was detected */
2811 if (width
== 0 || height
== 0)
2812 goto out
; /* no-op, not an error */
2814 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2815 xoffset
+= texImage
->Border
;
2816 yoffset
+= texImage
->Border
;
2818 ASSERT(ctx
->Driver
.TexSubImage2D
);
2819 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2820 width
, height
, format
, type
, pixels
,
2821 &ctx
->Unpack
, texObj
, texImage
);
2822 ctx
->NewState
|= _NEW_TEXTURE
;
2825 _mesa_unlock_texture(ctx
, texObj
);
2831 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2832 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2833 GLsizei width
, GLsizei height
, GLsizei depth
,
2834 GLenum format
, GLenum type
,
2835 const GLvoid
*pixels
)
2837 struct gl_texture_unit
*texUnit
;
2838 struct gl_texture_object
*texObj
;
2839 struct gl_texture_image
*texImage
;
2840 GET_CURRENT_CONTEXT(ctx
);
2841 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2843 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2844 _mesa_update_state(ctx
);
2846 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2847 width
, height
, depth
, format
, type
)) {
2848 return; /* error was detected */
2851 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2852 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2854 _mesa_lock_texture(ctx
, texObj
);
2856 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2858 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2859 width
, height
, depth
, format
, type
, texImage
)) {
2860 goto out
; /* error was detected */
2863 if (width
== 0 || height
== 0 || height
== 0)
2864 goto out
; /* no-op, not an error */
2866 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2867 xoffset
+= texImage
->Border
;
2868 yoffset
+= texImage
->Border
;
2869 zoffset
+= texImage
->Border
;
2871 ASSERT(ctx
->Driver
.TexSubImage3D
);
2872 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2873 xoffset
, yoffset
, zoffset
,
2874 width
, height
, depth
,
2875 format
, type
, pixels
,
2876 &ctx
->Unpack
, texObj
, texImage
);
2877 ctx
->NewState
|= _NEW_TEXTURE
;
2880 _mesa_unlock_texture(ctx
, texObj
);
2886 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2887 GLenum internalFormat
,
2889 GLsizei width
, GLint border
)
2891 struct gl_texture_unit
*texUnit
;
2892 struct gl_texture_object
*texObj
;
2893 struct gl_texture_image
*texImage
;
2894 GLsizei postConvWidth
= width
;
2895 const GLuint face
= _mesa_tex_target_to_face(target
);
2896 GET_CURRENT_CONTEXT(ctx
);
2897 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2899 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2900 _mesa_update_state(ctx
);
2902 #if FEATURE_convolve
2903 if (_mesa_is_color_format(internalFormat
)) {
2904 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2908 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2909 postConvWidth
, 1, border
))
2912 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2913 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2914 _mesa_lock_texture(ctx
, texObj
);
2916 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2918 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2922 if (texImage
->Data
) {
2923 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2926 ASSERT(texImage
->Data
== NULL
);
2928 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2929 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2930 border
, internalFormat
);
2933 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2934 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2935 x
, y
, width
, border
);
2937 ASSERT(texImage
->TexFormat
);
2939 update_fbo_texture(ctx
, texObj
, face
, level
);
2942 texObj
->_Complete
= GL_FALSE
;
2943 ctx
->NewState
|= _NEW_TEXTURE
;
2946 _mesa_unlock_texture(ctx
, texObj
);
2952 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2953 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2956 struct gl_texture_unit
*texUnit
;
2957 struct gl_texture_object
*texObj
;
2958 struct gl_texture_image
*texImage
;
2959 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2960 const GLuint face
= _mesa_tex_target_to_face(target
);
2961 GET_CURRENT_CONTEXT(ctx
);
2962 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2964 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2965 _mesa_update_state(ctx
);
2967 #if FEATURE_convolve
2968 if (_mesa_is_color_format(internalFormat
)) {
2969 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2974 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2975 postConvWidth
, postConvHeight
, border
))
2978 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2979 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2981 _mesa_lock_texture(ctx
, texObj
);
2983 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2986 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2990 if (texImage
->Data
) {
2991 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2994 ASSERT(texImage
->Data
== NULL
);
2996 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2997 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2998 postConvWidth
, postConvHeight
, 1,
2999 border
, internalFormat
);
3001 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3002 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3003 x
, y
, width
, height
, border
);
3005 ASSERT(texImage
->TexFormat
);
3007 update_fbo_texture(ctx
, texObj
, face
, level
);
3010 texObj
->_Complete
= GL_FALSE
;
3011 ctx
->NewState
|= _NEW_TEXTURE
;
3014 _mesa_unlock_texture(ctx
, texObj
);
3019 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3020 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3022 struct gl_texture_unit
*texUnit
;
3023 struct gl_texture_object
*texObj
;
3024 struct gl_texture_image
*texImage
;
3025 GLsizei postConvWidth
= width
;
3029 GET_CURRENT_CONTEXT(ctx
);
3030 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3032 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
3033 _mesa_update_state(ctx
);
3035 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3038 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3039 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3041 _mesa_lock_texture(ctx
, texObj
);
3043 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3045 #if FEATURE_convolve
3046 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3047 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3051 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3052 xoffset
, 0, 0, postConvWidth
, 1,
3057 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3058 xoffset
+= texImage
->Border
;
3060 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3062 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3063 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3064 xoffset
, x
, y
, width
);
3067 ctx
->NewState
|= _NEW_TEXTURE
;
3070 _mesa_unlock_texture(ctx
, texObj
);
3076 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3077 GLint xoffset
, GLint yoffset
,
3078 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3080 struct gl_texture_unit
*texUnit
;
3081 struct gl_texture_object
*texObj
;
3082 struct gl_texture_image
*texImage
;
3083 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3084 GET_CURRENT_CONTEXT(ctx
);
3085 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3087 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
3088 _mesa_update_state(ctx
);
3090 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3093 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3094 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3096 _mesa_lock_texture(ctx
, texObj
);
3098 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3100 #if FEATURE_convolve
3101 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3102 _mesa_adjust_image_for_convolution(ctx
, 2,
3103 &postConvWidth
, &postConvHeight
);
3107 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3108 postConvWidth
, postConvHeight
, texImage
))
3111 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3112 xoffset
+= texImage
->Border
;
3113 yoffset
+= texImage
->Border
;
3115 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3117 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3118 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3119 xoffset
, yoffset
, x
, y
, width
, height
);
3122 ctx
->NewState
|= _NEW_TEXTURE
;
3125 _mesa_unlock_texture(ctx
, texObj
);
3131 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3132 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3133 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3135 struct gl_texture_unit
*texUnit
;
3136 struct gl_texture_object
*texObj
;
3137 struct gl_texture_image
*texImage
;
3138 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3139 GET_CURRENT_CONTEXT(ctx
);
3140 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3142 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
3143 _mesa_update_state(ctx
);
3145 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3148 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3149 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3151 _mesa_lock_texture(ctx
, texObj
);
3153 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3155 #if FEATURE_convolve
3156 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3157 _mesa_adjust_image_for_convolution(ctx
, 2,
3158 &postConvWidth
, &postConvHeight
);
3162 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3163 zoffset
, postConvWidth
, postConvHeight
,
3167 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3168 xoffset
+= texImage
->Border
;
3169 yoffset
+= texImage
->Border
;
3170 zoffset
+= texImage
->Border
;
3172 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3174 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3175 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3176 xoffset
, yoffset
, zoffset
,
3177 x
, y
, width
, height
);
3180 ctx
->NewState
|= _NEW_TEXTURE
;
3183 _mesa_unlock_texture(ctx
, texObj
);
3189 /**********************************************************************/
3190 /****** Compressed Textures ******/
3191 /**********************************************************************/
3195 * Error checking for glCompressedTexImage[123]D().
3196 * \return error code or GL_NO_ERROR.
3199 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3200 GLenum target
, GLint level
,
3201 GLenum internalFormat
, GLsizei width
,
3202 GLsizei height
, GLsizei depth
, GLint border
,
3205 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3207 if (dimensions
== 1) {
3208 /* 1D compressed textures not allowed */
3209 return GL_INVALID_ENUM
;
3211 else if (dimensions
== 2) {
3212 if (target
== GL_PROXY_TEXTURE_2D
) {
3213 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3215 else if (target
== GL_TEXTURE_2D
) {
3216 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3218 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3219 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3220 return GL_INVALID_ENUM
; /*target*/
3221 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3223 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3224 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3225 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3226 return GL_INVALID_ENUM
; /*target*/
3227 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3230 return GL_INVALID_ENUM
; /*target*/
3233 else if (dimensions
== 3) {
3234 /* 3D compressed textures not allowed */
3235 return GL_INVALID_ENUM
;
3238 maxTextureSize
= 1 << (maxLevels
- 1);
3240 /* This will detect any invalid internalFormat value */
3241 if (!is_compressed_format(ctx
, internalFormat
))
3242 return GL_INVALID_ENUM
;
3244 /* This should really never fail */
3245 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3246 return GL_INVALID_ENUM
;
3249 return GL_INVALID_VALUE
;
3252 * XXX We should probably use the proxy texture error check function here.
3254 if (width
< 1 || width
> maxTextureSize
||
3255 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3256 return GL_INVALID_VALUE
;
3258 if ((height
< 1 || height
> maxTextureSize
||
3259 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3261 return GL_INVALID_VALUE
;
3263 if ((depth
< 1 || depth
> maxTextureSize
||
3264 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3266 return GL_INVALID_VALUE
;
3268 /* For cube map, width must equal height */
3269 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3270 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3271 return GL_INVALID_VALUE
;
3273 if (level
< 0 || level
>= maxLevels
)
3274 return GL_INVALID_VALUE
;
3276 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3277 depth
, internalFormat
);
3278 if (expectedSize
!= imageSize
)
3279 return GL_INVALID_VALUE
;
3281 #if FEATURE_EXT_texture_sRGB
3282 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3283 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3284 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3285 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3287 return GL_INVALID_OPERATION
;
3296 * Error checking for glCompressedTexSubImage[123]D().
3297 * \warning There are some bad assumptions here about the size of compressed
3298 * texture tiles (multiple of 4) used to test the validity of the
3299 * offset and size parameters.
3300 * \return error code or GL_NO_ERROR.
3303 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3304 GLenum target
, GLint level
,
3305 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3306 GLsizei width
, GLsizei height
, GLsizei depth
,
3307 GLenum format
, GLsizei imageSize
)
3309 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3312 if (dimensions
== 1) {
3313 /* 1D compressed textures not allowed */
3314 return GL_INVALID_ENUM
;
3316 else if (dimensions
== 2) {
3317 if (target
== GL_PROXY_TEXTURE_2D
) {
3318 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3320 else if (target
== GL_TEXTURE_2D
) {
3321 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3323 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3324 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3325 return GL_INVALID_ENUM
; /*target*/
3326 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3328 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3329 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3330 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3331 return GL_INVALID_ENUM
; /*target*/
3332 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3335 return GL_INVALID_ENUM
; /*target*/
3338 else if (dimensions
== 3) {
3339 /* 3D compressed textures not allowed */
3340 return GL_INVALID_ENUM
;
3343 maxTextureSize
= 1 << (maxLevels
- 1);
3345 /* this will catch any invalid compressed format token */
3346 if (!is_compressed_format(ctx
, format
))
3347 return GL_INVALID_ENUM
;
3349 if (width
< 1 || width
> maxTextureSize
)
3350 return GL_INVALID_VALUE
;
3352 if ((height
< 1 || height
> maxTextureSize
)
3354 return GL_INVALID_VALUE
;
3356 if (level
< 0 || level
>= maxLevels
)
3357 return GL_INVALID_VALUE
;
3359 /* XXX these tests are specific to the compressed format.
3360 * this code should be generalized in some way.
3362 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3363 return GL_INVALID_VALUE
;
3365 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3366 return GL_INVALID_VALUE
;
3368 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3369 return GL_INVALID_VALUE
;
3371 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3373 if (expectedSize
!= imageSize
)
3374 return GL_INVALID_VALUE
;
3382 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3383 GLenum internalFormat
, GLsizei width
,
3384 GLint border
, GLsizei imageSize
,
3387 GET_CURRENT_CONTEXT(ctx
);
3388 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3390 if (target
== GL_TEXTURE_1D
) {
3391 /* non-proxy target */
3392 struct gl_texture_unit
*texUnit
;
3393 struct gl_texture_object
*texObj
;
3394 struct gl_texture_image
*texImage
;
3395 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3396 internalFormat
, width
, 1, 1, border
, imageSize
);
3398 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3402 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3403 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3405 _mesa_lock_texture(ctx
, texObj
);
3407 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3409 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3413 if (texImage
->Data
) {
3414 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3416 ASSERT(texImage
->Data
== NULL
);
3418 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3419 border
, internalFormat
);
3421 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3422 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3423 internalFormat
, width
, border
,
3428 texObj
->_Complete
= GL_FALSE
;
3429 ctx
->NewState
|= _NEW_TEXTURE
;
3432 _mesa_unlock_texture(ctx
, texObj
);
3434 else if (target
== GL_PROXY_TEXTURE_1D
) {
3435 /* Proxy texture: check for errors and update proxy state */
3436 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3437 internalFormat
, width
, 1, 1, border
, imageSize
);
3439 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3440 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3441 internalFormat
, GL_NONE
, GL_NONE
,
3442 width
, 1, 1, border
);
3445 /* if error, clear all proxy texture image parameters */
3446 struct gl_texture_image
*texImage
;
3447 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3449 clear_teximage_fields(texImage
);
3452 /* store the teximage parameters */
3453 struct gl_texture_unit
*texUnit
;
3454 struct gl_texture_object
*texObj
;
3455 struct gl_texture_image
*texImage
;
3456 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3457 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3459 _mesa_lock_texture(ctx
, texObj
);
3461 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3462 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3463 border
, internalFormat
);
3465 _mesa_unlock_texture(ctx
, texObj
);
3469 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3476 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3477 GLenum internalFormat
, GLsizei width
,
3478 GLsizei height
, GLint border
, GLsizei imageSize
,
3481 GET_CURRENT_CONTEXT(ctx
);
3482 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3484 if (target
== GL_TEXTURE_2D
||
3485 (ctx
->Extensions
.ARB_texture_cube_map
&&
3486 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3487 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3488 /* non-proxy target */
3489 struct gl_texture_unit
*texUnit
;
3490 struct gl_texture_object
*texObj
;
3491 struct gl_texture_image
*texImage
;
3492 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3493 internalFormat
, width
, height
, 1, border
, imageSize
);
3495 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3499 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3500 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3502 _mesa_lock_texture(ctx
, texObj
);
3504 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3506 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3510 if (texImage
->Data
) {
3511 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3513 ASSERT(texImage
->Data
== NULL
);
3515 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3516 border
, internalFormat
);
3518 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3519 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3520 internalFormat
, width
, height
,
3521 border
, imageSize
, data
,
3525 texObj
->_Complete
= GL_FALSE
;
3526 ctx
->NewState
|= _NEW_TEXTURE
;
3529 _mesa_unlock_texture(ctx
, texObj
);
3531 else if (target
== GL_PROXY_TEXTURE_2D
||
3532 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3533 ctx
->Extensions
.ARB_texture_cube_map
)) {
3534 /* Proxy texture: check for errors and update proxy state */
3535 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3536 internalFormat
, width
, height
, 1, border
, imageSize
);
3538 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3539 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3540 internalFormat
, GL_NONE
, GL_NONE
,
3541 width
, height
, 1, border
);
3544 /* if error, clear all proxy texture image parameters */
3545 struct gl_texture_image
*texImage
;
3546 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3548 clear_teximage_fields(texImage
);
3551 /* store the teximage parameters */
3552 struct gl_texture_unit
*texUnit
;
3553 struct gl_texture_object
*texObj
;
3554 struct gl_texture_image
*texImage
;
3555 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3556 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3558 _mesa_lock_texture(ctx
, texObj
);
3560 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3561 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3562 border
, internalFormat
);
3564 _mesa_unlock_texture(ctx
, texObj
);
3568 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3575 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3576 GLenum internalFormat
, GLsizei width
,
3577 GLsizei height
, GLsizei depth
, GLint border
,
3578 GLsizei imageSize
, const GLvoid
*data
)
3580 GET_CURRENT_CONTEXT(ctx
);
3581 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3583 if (target
== GL_TEXTURE_3D
) {
3584 /* non-proxy target */
3585 struct gl_texture_unit
*texUnit
;
3586 struct gl_texture_object
*texObj
;
3587 struct gl_texture_image
*texImage
;
3588 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3589 internalFormat
, width
, height
, depth
, border
, imageSize
);
3591 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3595 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3596 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3597 _mesa_lock_texture(ctx
, texObj
);
3599 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3601 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3605 if (texImage
->Data
) {
3606 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3608 ASSERT(texImage
->Data
== NULL
);
3610 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3611 border
, internalFormat
);
3613 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3614 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3616 width
, height
, depth
,
3617 border
, imageSize
, data
,
3621 texObj
->_Complete
= GL_FALSE
;
3622 ctx
->NewState
|= _NEW_TEXTURE
;
3625 _mesa_unlock_texture(ctx
, texObj
);
3627 else if (target
== GL_PROXY_TEXTURE_3D
) {
3628 /* Proxy texture: check for errors and update proxy state */
3629 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3630 internalFormat
, width
, height
, depth
, border
, imageSize
);
3632 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3633 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3634 internalFormat
, GL_NONE
, GL_NONE
,
3635 width
, height
, depth
, border
);
3638 /* if error, clear all proxy texture image parameters */
3639 struct gl_texture_image
*texImage
;
3640 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3642 clear_teximage_fields(texImage
);
3645 /* store the teximage parameters */
3646 struct gl_texture_unit
*texUnit
;
3647 struct gl_texture_object
*texObj
;
3648 struct gl_texture_image
*texImage
;
3649 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3650 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3651 _mesa_lock_texture(ctx
, texObj
);
3653 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3654 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3655 depth
, border
, internalFormat
);
3657 _mesa_unlock_texture(ctx
, texObj
);
3661 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3668 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3669 GLsizei width
, GLenum format
,
3670 GLsizei imageSize
, const GLvoid
*data
)
3672 struct gl_texture_unit
*texUnit
;
3673 struct gl_texture_object
*texObj
;
3674 struct gl_texture_image
*texImage
;
3676 GET_CURRENT_CONTEXT(ctx
);
3677 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3679 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3680 xoffset
, 0, 0, /* pos */
3681 width
, 1, 1, /* size */
3684 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3688 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3689 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3690 _mesa_lock_texture(ctx
, texObj
);
3692 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3695 if ((GLint
) format
!= texImage
->InternalFormat
) {
3696 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3697 "glCompressedTexSubImage1D(format)");
3701 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3702 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3707 goto out
; /* no-op, not an error */
3709 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3710 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3712 format
, imageSize
, data
,
3715 ctx
->NewState
|= _NEW_TEXTURE
;
3718 _mesa_unlock_texture(ctx
, texObj
);
3723 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3724 GLint yoffset
, GLsizei width
, GLsizei height
,
3725 GLenum format
, GLsizei imageSize
,
3728 struct gl_texture_unit
*texUnit
;
3729 struct gl_texture_object
*texObj
;
3730 struct gl_texture_image
*texImage
;
3732 GET_CURRENT_CONTEXT(ctx
);
3733 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3735 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3736 xoffset
, yoffset
, 0, /* pos */
3737 width
, height
, 1, /* size */
3740 /* XXX proxy target? */
3741 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3745 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3746 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3747 _mesa_lock_texture(ctx
, texObj
);
3749 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3752 if ((GLint
) format
!= texImage
->InternalFormat
) {
3753 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3754 "glCompressedTexSubImage2D(format)");
3758 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3759 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3760 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3764 if (width
== 0 || height
== 0)
3765 goto out
; /* no-op, not an error */
3767 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3768 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3769 xoffset
, yoffset
, width
, height
,
3770 format
, imageSize
, data
,
3773 ctx
->NewState
|= _NEW_TEXTURE
;
3776 _mesa_unlock_texture(ctx
, texObj
);
3781 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3782 GLint yoffset
, GLint zoffset
, GLsizei width
,
3783 GLsizei height
, GLsizei depth
, GLenum format
,
3784 GLsizei imageSize
, const GLvoid
*data
)
3786 struct gl_texture_unit
*texUnit
;
3787 struct gl_texture_object
*texObj
;
3788 struct gl_texture_image
*texImage
;
3790 GET_CURRENT_CONTEXT(ctx
);
3791 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3793 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3794 xoffset
, yoffset
, zoffset
,/*pos*/
3795 width
, height
, depth
, /*size*/
3798 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3802 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3803 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3804 _mesa_lock_texture(ctx
, texObj
);
3806 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3809 if ((GLint
) format
!= texImage
->InternalFormat
) {
3810 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3811 "glCompressedTexSubImage3D(format)");
3815 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3816 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3817 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3818 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3822 if (width
== 0 || height
== 0 || depth
== 0)
3823 goto out
; /* no-op, not an error */
3825 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3826 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3827 xoffset
, yoffset
, zoffset
,
3828 width
, height
, depth
,
3829 format
, imageSize
, data
,
3832 ctx
->NewState
|= _NEW_TEXTURE
;
3835 _mesa_unlock_texture(ctx
, texObj
);
3840 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3842 const struct gl_texture_unit
*texUnit
;
3843 struct gl_texture_object
*texObj
;
3844 struct gl_texture_image
*texImage
;
3846 GET_CURRENT_CONTEXT(ctx
);
3847 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3849 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3850 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3852 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3856 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3857 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3859 if (level
< 0 || level
>= maxLevels
) {
3860 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3864 if (_mesa_is_proxy_texture(target
)) {
3865 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3869 _mesa_lock_texture(ctx
, texObj
);
3871 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3873 if (texImage
->IsCompressed
) {
3874 /* this typically calls _mesa_get_compressed_teximage() */
3875 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3879 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3880 "glGetCompressedTexImageARB");
3884 /* probably invalid mipmap level */
3885 _mesa_error(ctx
, GL_INVALID_VALUE
,
3886 "glGetCompressedTexImageARB(level)");
3889 _mesa_unlock_texture(ctx
, texObj
);