2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "texcompress.h"
43 #include "texformat.h"
51 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
55 _mesa_alloc_texmemory(GLsizei bytes
)
57 return _mesa_align_malloc(bytes
, 512);
62 * Free texture memory allocated with _mesa_alloc_texmemory()
65 _mesa_free_texmemory(void *m
)
74 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
76 #if CHAN_TYPE != GL_UNSIGNED_BYTE
77 _mesa_problem(NULL
, "PrintTexture not supported");
80 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
83 _mesa_printf("No texture data\n");
87 switch (img
->Format
) {
94 case GL_LUMINANCE_ALPHA
:
104 _mesa_problem(NULL
, "error in PrintTexture\n");
108 for (i
= 0; i
< img
->Height
; i
++) {
109 for (j
= 0; j
< img
->Width
; j
++) {
111 _mesa_printf("%02x ", data
[0]);
113 _mesa_printf("%02x%02x ", data
[0], data
[1]);
115 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
117 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
118 data
+= (img
->RowStride
- img
->Width
) * c
;
120 /* XXX use img->ImageStride here */
129 * Compute floor(log_base_2(n)).
130 * If n < 0 return -1.
159 * Return the simple base format for a given internal texture format.
160 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
162 * \param ctx GL context.
163 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
165 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
166 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
168 * This is the format which is used during texture application (i.e. the
169 * texture format and env mode determine the arithmetic used.
172 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
174 switch (internalFormat
) {
189 case GL_LUMINANCE_ALPHA
:
190 case GL_LUMINANCE4_ALPHA4
:
191 case GL_LUMINANCE6_ALPHA2
:
192 case GL_LUMINANCE8_ALPHA8
:
193 case GL_LUMINANCE12_ALPHA4
:
194 case GL_LUMINANCE12_ALPHA12
:
195 case GL_LUMINANCE16_ALPHA16
:
196 return GL_LUMINANCE_ALPHA
;
227 if (ctx
->Extensions
.EXT_paletted_texture
) {
228 switch (internalFormat
) {
230 case GL_COLOR_INDEX1_EXT
:
231 case GL_COLOR_INDEX2_EXT
:
232 case GL_COLOR_INDEX4_EXT
:
233 case GL_COLOR_INDEX8_EXT
:
234 case GL_COLOR_INDEX12_EXT
:
235 case GL_COLOR_INDEX16_EXT
:
236 return GL_COLOR_INDEX
;
242 if (ctx
->Extensions
.SGIX_depth_texture
||
243 ctx
->Extensions
.ARB_depth_texture
) {
244 switch (internalFormat
) {
245 case GL_DEPTH_COMPONENT
:
246 case GL_DEPTH_COMPONENT16_SGIX
:
247 case GL_DEPTH_COMPONENT24_SGIX
:
248 case GL_DEPTH_COMPONENT32_SGIX
:
249 return GL_DEPTH_COMPONENT
;
255 if (ctx
->Extensions
.ARB_texture_compression
) {
256 switch (internalFormat
) {
257 case GL_COMPRESSED_ALPHA
:
259 case GL_COMPRESSED_LUMINANCE
:
261 case GL_COMPRESSED_LUMINANCE_ALPHA
:
262 return GL_LUMINANCE_ALPHA
;
263 case GL_COMPRESSED_INTENSITY
:
265 case GL_COMPRESSED_RGB
:
267 case GL_COMPRESSED_RGBA
:
274 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
275 switch (internalFormat
) {
276 case GL_COMPRESSED_RGB_FXT1_3DFX
:
278 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
285 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
286 switch (internalFormat
) {
287 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
289 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
290 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
291 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
298 if (ctx
->Extensions
.S3_s3tc
) {
299 switch (internalFormat
) {
311 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
312 if (internalFormat
== GL_YCBCR_MESA
)
313 return GL_YCBCR_MESA
;
316 if (ctx
->Extensions
.ARB_texture_float
) {
317 switch (internalFormat
) {
318 case GL_ALPHA16F_ARB
:
319 case GL_ALPHA32F_ARB
:
327 case GL_INTENSITY16F_ARB
:
328 case GL_INTENSITY32F_ARB
:
330 case GL_LUMINANCE16F_ARB
:
331 case GL_LUMINANCE32F_ARB
:
333 case GL_LUMINANCE_ALPHA16F_ARB
:
334 case GL_LUMINANCE_ALPHA32F_ARB
:
335 return GL_LUMINANCE_ALPHA
;
341 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
342 switch (internalFormat
) {
343 case GL_DEPTH_STENCIL_EXT
:
344 case GL_DEPTH24_STENCIL8_EXT
:
345 return GL_DEPTH_STENCIL_EXT
;
351 #if FEATURE_EXT_texture_sRGB
352 if (ctx
->Extensions
.EXT_texture_sRGB
) {
353 switch (internalFormat
) {
356 case GL_COMPRESSED_SRGB_EXT
:
357 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
359 case GL_SRGB_ALPHA_EXT
:
360 case GL_SRGB8_ALPHA8_EXT
:
361 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
362 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
363 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
364 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
366 case GL_SLUMINANCE_ALPHA_EXT
:
367 case GL_SLUMINANCE8_ALPHA8_EXT
:
368 case GL_COMPRESSED_SLUMINANCE_EXT
:
369 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
370 return GL_LUMINANCE_ALPHA
;
371 case GL_SLUMINANCE_EXT
:
372 case GL_SLUMINANCE8_EXT
:
379 #endif /* FEATURE_EXT_texture_sRGB */
381 return -1; /* error */
386 * Test if the given image format is a color/RGBA format (i.e., not color
387 * index, depth, stencil, etc).
388 * \param format the image format value (may by an internal texture format)
389 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
392 is_color_format(GLenum format
)
410 case GL_LUMINANCE_ALPHA
:
411 case GL_LUMINANCE4_ALPHA4
:
412 case GL_LUMINANCE6_ALPHA2
:
413 case GL_LUMINANCE8_ALPHA8
:
414 case GL_LUMINANCE12_ALPHA4
:
415 case GL_LUMINANCE12_ALPHA12
:
416 case GL_LUMINANCE16_ALPHA16
:
443 /* float texture formats */
444 case GL_ALPHA16F_ARB
:
445 case GL_ALPHA32F_ARB
:
446 case GL_LUMINANCE16F_ARB
:
447 case GL_LUMINANCE32F_ARB
:
448 case GL_LUMINANCE_ALPHA16F_ARB
:
449 case GL_LUMINANCE_ALPHA32F_ARB
:
450 case GL_INTENSITY16F_ARB
:
451 case GL_INTENSITY32F_ARB
:
456 /* compressed formats */
457 case GL_COMPRESSED_ALPHA
:
458 case GL_COMPRESSED_LUMINANCE
:
459 case GL_COMPRESSED_LUMINANCE_ALPHA
:
460 case GL_COMPRESSED_INTENSITY
:
461 case GL_COMPRESSED_RGB
:
462 case GL_COMPRESSED_RGBA
:
467 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
468 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
469 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
470 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
471 case GL_COMPRESSED_RGB_FXT1_3DFX
:
472 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
473 #if FEATURE_EXT_texture_sRGB
476 case GL_SRGB_ALPHA_EXT
:
477 case GL_SRGB8_ALPHA8_EXT
:
478 case GL_SLUMINANCE_ALPHA_EXT
:
479 case GL_SLUMINANCE8_ALPHA8_EXT
:
480 case GL_SLUMINANCE_EXT
:
481 case GL_SLUMINANCE8_EXT
:
482 case GL_COMPRESSED_SRGB_EXT
:
483 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
484 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
485 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
486 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
487 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
488 case GL_COMPRESSED_SLUMINANCE_EXT
:
489 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
490 #endif /* FEATURE_EXT_texture_sRGB */
492 case GL_YCBCR_MESA
: /* not considered to be RGB */
500 * Test if the given image format is a color index format.
503 is_index_format(GLenum format
)
507 case GL_COLOR_INDEX1_EXT
:
508 case GL_COLOR_INDEX2_EXT
:
509 case GL_COLOR_INDEX4_EXT
:
510 case GL_COLOR_INDEX8_EXT
:
511 case GL_COLOR_INDEX12_EXT
:
512 case GL_COLOR_INDEX16_EXT
:
521 * Test if the given image format is a depth component format.
524 is_depth_format(GLenum format
)
527 case GL_DEPTH_COMPONENT16_ARB
:
528 case GL_DEPTH_COMPONENT24_ARB
:
529 case GL_DEPTH_COMPONENT32_ARB
:
530 case GL_DEPTH_COMPONENT
:
539 * Test if the given image format is a YCbCr format.
542 is_ycbcr_format(GLenum format
)
554 * Test if the given image format is a Depth/Stencil format.
557 is_depthstencil_format(GLenum format
)
560 case GL_DEPTH24_STENCIL8_EXT
:
561 case GL_DEPTH_STENCIL_EXT
:
571 * Test if it is a supported compressed format.
573 * \param internalFormat the internal format token provided by the user.
575 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
576 * GL_FALSE otherwise.
578 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
582 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
584 GLint supported
[100]; /* 100 should be plenty */
587 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
589 for (i
= 0; i
< n
; i
++) {
590 if ((GLint
) internalFormat
== supported
[i
]) {
599 * For cube map faces, return a face index in [0,5].
600 * For other targets return 0;
603 _mesa_tex_target_to_face(GLenum target
)
605 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
606 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
607 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
615 * Store a gl_texture_image pointer in a gl_texture_object structure
616 * according to the target and level parameters.
618 * \param tObj texture object.
619 * \param target texture target.
620 * \param level image level.
621 * \param texImage texture image.
623 * This was basically prompted by the introduction of cube maps.
626 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
627 GLenum target
, GLint level
,
628 struct gl_texture_image
*texImage
)
632 /* XXX simplify this with _mesa_tex_target_to_face() */
637 case GL_TEXTURE_1D_ARRAY_EXT
:
638 case GL_TEXTURE_2D_ARRAY_EXT
:
639 tObj
->Image
[0][level
] = texImage
;
641 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
642 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
643 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
644 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
645 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
646 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
648 GLuint face
= ((GLuint
) target
-
649 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
650 tObj
->Image
[face
][level
] = texImage
;
653 case GL_TEXTURE_RECTANGLE_NV
:
655 tObj
->Image
[0][level
] = texImage
;
658 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
661 /* Set the 'back' pointer */
662 texImage
->TexObject
= tObj
;
667 * Allocate a texture image structure.
669 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
672 * \return a pointer to gl_texture_image struct with all fields initialized to
675 struct gl_texture_image
*
676 _mesa_new_texture_image( GLcontext
*ctx
)
679 return CALLOC_STRUCT(gl_texture_image
);
684 * Free texture image data.
685 * This function is a fallback called via ctx->Driver.FreeTexImageData().
687 * \param teximage texture image.
689 * Free the texture image data if it's not marked as client data.
692 _mesa_free_texture_image_data(GLcontext
*ctx
,
693 struct gl_texture_image
*texImage
)
697 if (texImage
->Data
&& !texImage
->IsClientData
) {
698 /* free the old texture data */
699 _mesa_free_texmemory(texImage
->Data
);
702 texImage
->Data
= NULL
;
707 * Free texture image.
709 * \param teximage texture image.
711 * Free the texture image structure and the associated image data.
714 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
716 /* Free texImage->Data and/or any other driver-specific texture
719 ASSERT(ctx
->Driver
.FreeTexImageData
);
720 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
722 ASSERT(texImage
->Data
== NULL
);
723 if (texImage
->ImageOffsets
)
724 _mesa_free(texImage
->ImageOffsets
);
725 _mesa_free(texImage
);
730 * Test if a target is a proxy target.
732 * \param target texture target.
734 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
737 _mesa_is_proxy_texture(GLenum target
)
739 return (target
== GL_PROXY_TEXTURE_1D
||
740 target
== GL_PROXY_TEXTURE_2D
||
741 target
== GL_PROXY_TEXTURE_3D
||
742 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
743 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
744 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
745 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
750 * Get the texture object that corresponds to the target of the given texture unit.
752 * \param ctx GL context.
753 * \param texUnit texture unit.
754 * \param target texture target.
756 * \return pointer to the texture object on success, or NULL on failure.
758 * \sa gl_texture_unit.
760 struct gl_texture_object
*
761 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
766 return texUnit
->Current1D
;
767 case GL_PROXY_TEXTURE_1D
:
768 return ctx
->Texture
.Proxy1D
;
770 return texUnit
->Current2D
;
771 case GL_PROXY_TEXTURE_2D
:
772 return ctx
->Texture
.Proxy2D
;
774 return texUnit
->Current3D
;
775 case GL_PROXY_TEXTURE_3D
:
776 return ctx
->Texture
.Proxy3D
;
777 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
778 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
779 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
780 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
781 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
782 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
783 case GL_TEXTURE_CUBE_MAP_ARB
:
784 return ctx
->Extensions
.ARB_texture_cube_map
785 ? texUnit
->CurrentCubeMap
: NULL
;
786 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
787 return ctx
->Extensions
.ARB_texture_cube_map
788 ? ctx
->Texture
.ProxyCubeMap
: NULL
;
789 case GL_TEXTURE_RECTANGLE_NV
:
790 return ctx
->Extensions
.NV_texture_rectangle
791 ? texUnit
->CurrentRect
: NULL
;
792 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
793 return ctx
->Extensions
.NV_texture_rectangle
794 ? ctx
->Texture
.ProxyRect
: NULL
;
795 case GL_TEXTURE_1D_ARRAY_EXT
:
796 return ctx
->Extensions
.MESA_texture_array
797 ? texUnit
->Current1DArray
: NULL
;
798 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
799 return ctx
->Extensions
.MESA_texture_array
800 ? ctx
->Texture
.Proxy1DArray
: NULL
;
801 case GL_TEXTURE_2D_ARRAY_EXT
:
802 return ctx
->Extensions
.MESA_texture_array
803 ? texUnit
->Current2DArray
: NULL
;
804 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
805 return ctx
->Extensions
.MESA_texture_array
806 ? ctx
->Texture
.Proxy2DArray
: NULL
;
808 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
815 * Get the texture image struct which corresponds to target and level
816 * of the given texture unit.
818 * \param ctx GL context.
819 * \param texUnit texture unit.
820 * \param target texture target.
821 * \param level image level.
823 * \return pointer to the texture image structure on success, or NULL on failure.
825 * \sa gl_texture_unit.
827 struct gl_texture_image
*
828 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
829 GLenum target
, GLint level
)
833 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
)
836 /* XXX simplify this with _mesa_tex_target_to_face() */
839 case GL_PROXY_TEXTURE_1D
:
841 case GL_PROXY_TEXTURE_2D
:
843 case GL_PROXY_TEXTURE_3D
:
844 return texObj
->Image
[0][level
];
846 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
847 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
848 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
849 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
850 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
851 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
852 if (ctx
->Extensions
.ARB_texture_cube_map
) {
853 GLuint face
= ((GLuint
) target
-
854 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
855 return texObj
->Image
[face
][level
];
860 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
861 if (ctx
->Extensions
.ARB_texture_cube_map
)
862 return texObj
->Image
[0][level
];
866 case GL_TEXTURE_RECTANGLE_NV
:
867 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
868 if (ctx
->Extensions
.NV_texture_rectangle
&& level
== 0)
869 return texObj
->Image
[0][level
];
873 case GL_TEXTURE_1D_ARRAY_EXT
:
874 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
875 case GL_TEXTURE_2D_ARRAY_EXT
:
876 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
877 return (ctx
->Extensions
.MESA_texture_array
)
878 ? texObj
->Image
[0][level
] : NULL
;
887 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
888 * it and install it. Only return NULL if passed a bad parameter or run
891 struct gl_texture_image
*
892 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
893 GLenum target
, GLint level
)
895 struct gl_texture_image
*texImage
;
900 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
902 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
904 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
908 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
916 * Return pointer to the specified proxy texture image.
917 * Note that proxy textures are per-context, not per-texture unit.
918 * \return pointer to texture image or NULL if invalid target, invalid
919 * level, or out of memory.
921 struct gl_texture_image
*
922 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
924 struct gl_texture_image
*texImage
;
930 case GL_PROXY_TEXTURE_1D
:
931 if (level
>= ctx
->Const
.MaxTextureLevels
)
933 texImage
= ctx
->Texture
.Proxy1D
->Image
[0][level
];
935 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
937 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
940 ctx
->Texture
.Proxy1D
->Image
[0][level
] = texImage
;
941 /* Set the 'back' pointer */
942 texImage
->TexObject
= ctx
->Texture
.Proxy1D
;
945 case GL_PROXY_TEXTURE_2D
:
946 if (level
>= ctx
->Const
.MaxTextureLevels
)
948 texImage
= ctx
->Texture
.Proxy2D
->Image
[0][level
];
950 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
952 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
955 ctx
->Texture
.Proxy2D
->Image
[0][level
] = texImage
;
956 /* Set the 'back' pointer */
957 texImage
->TexObject
= ctx
->Texture
.Proxy2D
;
960 case GL_PROXY_TEXTURE_3D
:
961 if (level
>= ctx
->Const
.Max3DTextureLevels
)
963 texImage
= ctx
->Texture
.Proxy3D
->Image
[0][level
];
965 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
967 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
970 ctx
->Texture
.Proxy3D
->Image
[0][level
] = texImage
;
971 /* Set the 'back' pointer */
972 texImage
->TexObject
= ctx
->Texture
.Proxy3D
;
975 case GL_PROXY_TEXTURE_CUBE_MAP
:
976 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
978 texImage
= ctx
->Texture
.ProxyCubeMap
->Image
[0][level
];
980 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
982 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
985 ctx
->Texture
.ProxyCubeMap
->Image
[0][level
] = texImage
;
986 /* Set the 'back' pointer */
987 texImage
->TexObject
= ctx
->Texture
.ProxyCubeMap
;
990 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
993 texImage
= ctx
->Texture
.ProxyRect
->Image
[0][level
];
995 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
997 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1000 ctx
->Texture
.ProxyRect
->Image
[0][level
] = texImage
;
1001 /* Set the 'back' pointer */
1002 texImage
->TexObject
= ctx
->Texture
.ProxyRect
;
1005 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1006 if (level
>= ctx
->Const
.MaxTextureLevels
)
1008 texImage
= ctx
->Texture
.Proxy1DArray
->Image
[0][level
];
1010 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1012 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1015 ctx
->Texture
.Proxy1DArray
->Image
[0][level
] = texImage
;
1016 /* Set the 'back' pointer */
1017 texImage
->TexObject
= ctx
->Texture
.Proxy1DArray
;
1020 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1021 if (level
>= ctx
->Const
.MaxTextureLevels
)
1023 texImage
= ctx
->Texture
.Proxy2DArray
->Image
[0][level
];
1025 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1027 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1030 ctx
->Texture
.Proxy2DArray
->Image
[0][level
] = texImage
;
1031 /* Set the 'back' pointer */
1032 texImage
->TexObject
= ctx
->Texture
.Proxy2DArray
;
1042 * Get the maximum number of allowed mipmap levels.
1044 * \param ctx GL context.
1045 * \param target texture target.
1047 * \return the maximum number of allowed mipmap levels for the given
1048 * texture target, or zero if passed a bad target.
1053 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
1057 case GL_PROXY_TEXTURE_1D
:
1059 case GL_PROXY_TEXTURE_2D
:
1060 case GL_TEXTURE_1D_ARRAY_EXT
:
1061 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1062 case GL_TEXTURE_2D_ARRAY_EXT
:
1063 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1064 return ctx
->Const
.MaxTextureLevels
;
1066 case GL_PROXY_TEXTURE_3D
:
1067 return ctx
->Const
.Max3DTextureLevels
;
1068 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1069 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1070 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1071 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1072 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1073 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1074 case GL_TEXTURE_CUBE_MAP_ARB
:
1075 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1076 return ctx
->Const
.MaxCubeTextureLevels
;
1077 case GL_TEXTURE_RECTANGLE_NV
:
1078 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1081 return 0; /* bad target */
1087 #if 000 /* not used anymore */
1089 * glTexImage[123]D can accept a NULL image pointer. In this case we
1090 * create a texture image with unspecified image contents per the OpenGL
1094 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1096 const GLint components
= _mesa_components_in_format(format
);
1097 const GLint numPixels
= width
* height
* depth
;
1098 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1102 * Let's see if anyone finds this. If glTexImage2D() is called with
1103 * a NULL image pointer then load the texture image with something
1104 * interesting instead of leaving it indeterminate.
1107 static const char message
[8][32] = {
1108 " X X XXXXX XXX X ",
1109 " XX XX X X X X X ",
1111 " X X XXXX XXX XXXXX ",
1114 " X X XXXXX XXX X X ",
1118 GLubyte
*imgPtr
= data
;
1120 for (h
= 0; h
< depth
; h
++) {
1121 for (i
= 0; i
< height
; i
++) {
1122 GLint srcRow
= 7 - (i
% 8);
1123 for (j
= 0; j
< width
; j
++) {
1124 GLint srcCol
= j
% 32;
1125 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1126 for (k
= 0; k
< components
; k
++) {
1142 * Reset the fields of a gl_texture_image struct to zero.
1144 * \param img texture image structure.
1146 * This is called when a proxy texture test fails, we set all the
1147 * image members (except DriverData) to zero.
1148 * It's also used in glTexImage[123]D as a safeguard to be sure all
1149 * required fields get initialized properly by the Driver.TexImage[123]D
1153 clear_teximage_fields(struct gl_texture_image
*img
)
1156 img
->_BaseFormat
= 0;
1157 img
->InternalFormat
= 0;
1163 if (img
->ImageOffsets
) {
1164 _mesa_free(img
->ImageOffsets
);
1165 img
->ImageOffsets
= NULL
;
1171 img
->HeightLog2
= 0;
1174 img
->TexFormat
= &_mesa_null_texformat
;
1175 img
->FetchTexelc
= NULL
;
1176 img
->FetchTexelf
= NULL
;
1177 img
->IsCompressed
= 0;
1178 img
->CompressedSize
= 0;
1183 * Initialize basic fields of the gl_texture_image struct.
1185 * \param ctx GL context.
1186 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1187 * \param img texture image structure to be initialized.
1188 * \param width image width.
1189 * \param height image height.
1190 * \param depth image depth.
1191 * \param border image border.
1192 * \param internalFormat internal format.
1194 * Fills in the fields of \p img with the given information.
1195 * Note: width, height and depth include the border.
1198 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1199 struct gl_texture_image
*img
,
1200 GLsizei width
, GLsizei height
, GLsizei depth
,
1201 GLint border
, GLenum internalFormat
)
1207 ASSERT(height
>= 0);
1210 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1211 ASSERT(img
->_BaseFormat
> 0);
1212 img
->InternalFormat
= internalFormat
;
1213 img
->Border
= border
;
1215 img
->Height
= height
;
1217 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1218 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1219 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1220 img
->WidthLog2
= logbase2(img
->Width2
);
1221 if (height
== 1) /* 1-D texture */
1222 img
->HeightLog2
= 0;
1224 img
->HeightLog2
= logbase2(img
->Height2
);
1225 if (depth
== 1) /* 2-D texture */
1228 img
->DepthLog2
= logbase2(img
->Depth2
);
1229 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1230 img
->IsCompressed
= GL_FALSE
;
1231 img
->CompressedSize
= 0;
1233 if ((width
== 1 || _mesa_bitcount(img
->Width2
) == 1) &&
1234 (height
== 1 || _mesa_bitcount(img
->Height2
) == 1) &&
1235 (depth
== 1 || _mesa_bitcount(img
->Depth2
) == 1))
1236 img
->_IsPowerOfTwo
= GL_TRUE
;
1238 img
->_IsPowerOfTwo
= GL_FALSE
;
1240 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1241 img
->RowStride
= width
;
1242 /* Allocate the ImageOffsets array and initialize to typical values.
1243 * We allocate the array for 1D/2D textures too in order to avoid special-
1244 * case code in the texstore routines.
1246 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1247 for (i
= 0; i
< depth
; i
++) {
1248 img
->ImageOffsets
[i
] = i
* width
* height
;
1251 /* Compute Width/Height/DepthScale for mipmap lod computation */
1252 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1253 /* scale = 1.0 since texture coords directly map to texels */
1254 img
->WidthScale
= 1.0;
1255 img
->HeightScale
= 1.0;
1256 img
->DepthScale
= 1.0;
1259 img
->WidthScale
= (GLfloat
) img
->Width
;
1260 img
->HeightScale
= (GLfloat
) img
->Height
;
1261 img
->DepthScale
= (GLfloat
) img
->Depth
;
1267 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1268 * level, width, height and depth against the ctx->Const limits for textures.
1270 * A hardware driver might override this function if, for example, the
1271 * max 3D texture size is 512x512x64 (i.e. not a cube).
1273 * Note that width, height, depth == 0 is not an error. However, a
1274 * texture with zero width/height/depth will be considered "incomplete"
1275 * and texturing will effectively be disabled.
1277 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1278 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1279 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1280 * \param level as passed to glTexImage
1281 * \param internalFormat as passed to glTexImage
1282 * \param format as passed to glTexImage
1283 * \param type as passed to glTexImage
1284 * \param width as passed to glTexImage
1285 * \param height as passed to glTexImage
1286 * \param depth as passed to glTexImage
1287 * \param border as passed to glTexImage
1288 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1291 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1292 GLint internalFormat
, GLenum format
, GLenum type
,
1293 GLint width
, GLint height
, GLint depth
, GLint border
)
1297 (void) internalFormat
;
1302 case GL_PROXY_TEXTURE_1D
:
1303 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1304 if (width
< 2 * border
|| width
> 2 + maxSize
||
1305 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1306 width
>0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1307 level
>= ctx
->Const
.MaxTextureLevels
) {
1308 /* bad width or level */
1312 case GL_PROXY_TEXTURE_2D
:
1313 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1314 if (width
< 2 * border
|| width
> 2 + maxSize
||
1315 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1316 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1317 height
< 2 * border
|| height
> 2 + maxSize
||
1318 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1319 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1320 level
>= ctx
->Const
.MaxTextureLevels
) {
1321 /* bad width or height or level */
1325 case GL_PROXY_TEXTURE_3D
:
1326 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1327 if (width
< 2 * border
|| width
> 2 + maxSize
||
1328 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1329 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1330 height
< 2 * border
|| height
> 2 + maxSize
||
1331 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1332 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1333 depth
< 2 * border
|| depth
> 2 + maxSize
||
1334 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1335 depth
> 0 && _mesa_bitcount(depth
- 2 * border
) != 1) ||
1336 level
>= ctx
->Const
.Max3DTextureLevels
) {
1337 /* bad width or height or depth or level */
1341 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1342 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1343 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1345 /* bad width or height or level */
1349 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1350 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1351 if (width
< 2 * border
|| width
> 2 + maxSize
||
1352 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1353 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1354 height
< 2 * border
|| height
> 2 + maxSize
||
1355 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1356 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1357 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1358 /* bad width or height */
1362 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1363 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1364 if (width
< 2 * border
|| width
> 2 + maxSize
||
1365 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1366 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1367 level
>= ctx
->Const
.MaxTextureLevels
) {
1368 /* bad width or level */
1372 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1376 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1377 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1378 if (width
< 2 * border
|| width
> 2 + maxSize
||
1379 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1380 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1381 height
< 2 * border
|| height
> 2 + maxSize
||
1382 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1383 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1384 level
>= ctx
->Const
.MaxTextureLevels
) {
1385 /* bad width or height or level */
1388 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1393 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1400 * Helper function to determine whether a target supports compressed textures
1403 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1405 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1406 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1407 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1408 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1409 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1410 || ((ctx
->Extensions
.MESA_texture_array
&&
1411 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1412 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1417 * Test the glTexImage[123]D() parameters for errors.
1419 * \param ctx GL context.
1420 * \param target texture target given by the user.
1421 * \param level image level given by the user.
1422 * \param internalFormat internal format given by the user.
1423 * \param format pixel data format given by the user.
1424 * \param type pixel data type given by the user.
1425 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1426 * \param width image width given by the user.
1427 * \param height image height given by the user.
1428 * \param depth image depth given by the user.
1429 * \param border image border given by the user.
1431 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1433 * Verifies each of the parameters against the constants specified in
1434 * __GLcontextRec::Const and the supported extensions, and according to the
1435 * OpenGL specification.
1438 texture_error_check( GLcontext
*ctx
, GLenum target
,
1439 GLint level
, GLint internalFormat
,
1440 GLenum format
, GLenum type
,
1442 GLint width
, GLint height
,
1443 GLint depth
, GLint border
)
1445 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1446 GLboolean sizeOK
= GL_TRUE
;
1447 GLboolean colorFormat
, indexFormat
;
1448 GLenum proxy_target
;
1450 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1451 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1453 _mesa_error(ctx
, GL_INVALID_VALUE
,
1454 "glTexImage%dD(level=%d)", dimensions
, level
);
1460 if (border
< 0 || border
> 1 ||
1461 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1462 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1464 _mesa_error(ctx
, GL_INVALID_VALUE
,
1465 "glTexImage%dD(border=%d)", dimensions
, border
);
1470 if (width
< 0 || height
< 0 || depth
< 0) {
1472 _mesa_error(ctx
, GL_INVALID_VALUE
,
1473 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1478 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1479 * level, width, height and depth.
1481 if (dimensions
== 1) {
1482 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1483 proxy_target
= GL_PROXY_TEXTURE_1D
;
1488 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1492 else if (dimensions
== 2) {
1494 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1495 proxy_target
= GL_PROXY_TEXTURE_2D
;
1497 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1498 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1499 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1500 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1501 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1504 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1505 sizeOK
= (width
== height
);
1507 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1508 target
== GL_TEXTURE_RECTANGLE_NV
) {
1509 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1510 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1513 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1515 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1516 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1517 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1520 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1524 else if (dimensions
== 3) {
1525 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1526 proxy_target
= GL_PROXY_TEXTURE_3D
;
1528 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1529 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1530 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1533 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1538 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1542 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1543 internalFormat
, format
,
1544 type
, width
, height
,
1548 _mesa_error(ctx
, GL_INVALID_VALUE
,
1549 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1550 dimensions
, level
, width
, height
, depth
);
1555 /* Check internalFormat */
1556 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1558 _mesa_error(ctx
, GL_INVALID_VALUE
,
1559 "glTexImage%dD(internalFormat=0x%x)",
1560 dimensions
, internalFormat
);
1565 /* Check incoming image format and type */
1566 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1567 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1568 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1571 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1572 "glTexImage%dD(format or type)", dimensions
);
1577 /* make sure internal format and format basically agree */
1578 colorFormat
= is_color_format(format
);
1579 indexFormat
= is_index_format(format
);
1580 if ((is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1581 (is_index_format(internalFormat
) && !indexFormat
) ||
1582 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1583 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1584 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
))) {
1586 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1587 "glTexImage(internalFormat/format)");
1591 /* additional checks for ycbcr textures */
1592 if (internalFormat
== GL_YCBCR_MESA
) {
1593 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1594 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1595 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1597 _mesa_sprintf(message
,
1598 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1599 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1600 return GL_TRUE
; /* error */
1602 if (target
!= GL_TEXTURE_2D
&&
1603 target
!= GL_PROXY_TEXTURE_2D
&&
1604 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1605 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1607 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1613 _mesa_sprintf(message
,
1614 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1615 dimensions
, border
);
1616 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1622 /* additional checks for depth textures */
1623 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1624 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1625 if (target
!= GL_TEXTURE_1D
&&
1626 target
!= GL_PROXY_TEXTURE_1D
&&
1627 target
!= GL_TEXTURE_2D
&&
1628 target
!= GL_PROXY_TEXTURE_2D
&&
1629 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1630 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1632 _mesa_error(ctx
, GL_INVALID_ENUM
,
1633 "glTexImage(target/internalFormat)");
1638 /* additional checks for compressed textures */
1639 if (is_compressed_format(ctx
, internalFormat
)) {
1640 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1641 _mesa_error(ctx
, GL_INVALID_ENUM
,
1642 "glTexImage%d(target)", dimensions
);
1647 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1648 "glTexImage%D(border!=0)", dimensions
);
1654 /* if we get here, the parameters are OK */
1660 * Test glTexSubImage[123]D() parameters for errors.
1662 * \param ctx GL context.
1663 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1664 * \param target texture target given by the user.
1665 * \param level image level given by the user.
1666 * \param xoffset sub-image x offset given by the user.
1667 * \param yoffset sub-image y offset given by the user.
1668 * \param zoffset sub-image z offset given by the user.
1669 * \param format pixel data format given by the user.
1670 * \param type pixel data type given by the user.
1671 * \param width image width given by the user.
1672 * \param height image height given by the user.
1673 * \param depth image depth given by the user.
1675 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1677 * Verifies each of the parameters against the constants specified in
1678 * __GLcontextRec::Const and the supported extensions, and according to the
1679 * OpenGL specification.
1682 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1683 GLenum target
, GLint level
,
1684 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1685 GLint width
, GLint height
, GLint depth
,
1686 GLenum format
, GLenum type
)
1689 if (dimensions
== 1) {
1690 if (target
!= GL_TEXTURE_1D
) {
1691 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1695 else if (dimensions
== 2) {
1696 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1697 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1698 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1699 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1703 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1704 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1705 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1709 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1710 if (!ctx
->Extensions
.MESA_texture_array
) {
1711 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1715 else if (target
!= GL_TEXTURE_2D
) {
1716 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1720 else if (dimensions
== 3) {
1721 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1722 if (!ctx
->Extensions
.MESA_texture_array
) {
1723 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1727 else if (target
!= GL_TEXTURE_3D
) {
1728 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1733 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1737 /* Basic level check */
1738 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1739 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1744 _mesa_error(ctx
, GL_INVALID_VALUE
,
1745 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1748 if (height
< 0 && dimensions
> 1) {
1749 _mesa_error(ctx
, GL_INVALID_VALUE
,
1750 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1753 if (depth
< 0 && dimensions
> 2) {
1754 _mesa_error(ctx
, GL_INVALID_VALUE
,
1755 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1759 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1760 _mesa_error(ctx
, GL_INVALID_ENUM
,
1761 "glTexSubImage%dD(format or type)", dimensions
);
1769 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1770 GLenum target
, GLint level
,
1771 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1772 GLint width
, GLint height
, GLint depth
,
1773 GLenum format
, GLenum type
,
1774 const struct gl_texture_image
*destTex
)
1777 /* undefined image level */
1778 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1782 if (xoffset
< -((GLint
)destTex
->Border
)) {
1783 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1787 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1788 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1792 if (dimensions
> 1) {
1793 if (yoffset
< -((GLint
)destTex
->Border
)) {
1794 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1798 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1799 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1804 if (dimensions
> 2) {
1805 if (zoffset
< -((GLint
)destTex
->Border
)) {
1806 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1809 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1810 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1815 #if FEATURE_EXT_texture_sRGB
1816 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1817 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1818 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1819 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1820 if ((width
& 0x3) || (height
& 0x3) ||
1821 (xoffset
& 0x3) || (yoffset
& 0x3))
1822 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1823 "glTexSubImage%dD(size or offset not multiple of 4)",
1829 if (destTex
->IsCompressed
) {
1830 if (!target_can_be_compressed(ctx
, target
)) {
1831 _mesa_error(ctx
, GL_INVALID_ENUM
,
1832 "glTexSubImage%D(target)", dimensions
);
1835 /* offset must be multiple of 4 */
1836 if ((xoffset
& 3) || (yoffset
& 3)) {
1837 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1838 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1841 /* size must be multiple of 4 or equal to whole texture size */
1842 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1843 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1844 "glTexSubImage%D(width)", dimensions
);
1847 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1848 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1849 "glTexSubImage%D(width)", dimensions
);
1859 * Test glCopyTexImage[12]D() parameters for errors.
1861 * \param ctx GL context.
1862 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1863 * \param target texture target given by the user.
1864 * \param level image level given by the user.
1865 * \param internalFormat internal format given by the user.
1866 * \param width image width given by the user.
1867 * \param height image height given by the user.
1868 * \param depth image depth given by the user.
1869 * \param border texture border.
1871 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1873 * Verifies each of the parameters against the constants specified in
1874 * __GLcontextRec::Const and the supported extensions, and according to the
1875 * OpenGL specification.
1878 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1879 GLenum target
, GLint level
, GLint internalFormat
,
1880 GLint width
, GLint height
, GLint border
)
1886 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1887 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1888 _mesa_error(ctx
, GL_INVALID_VALUE
,
1889 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1893 /* Check that the source buffer is complete */
1894 if (ctx
->ReadBuffer
->Name
) {
1895 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1896 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1897 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1898 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1904 if (border
< 0 || border
> 1 ||
1905 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1906 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1910 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1912 _mesa_error(ctx
, GL_INVALID_VALUE
,
1913 "glCopyTexImage%dD(internalFormat)", dimensions
);
1917 /* NOTE: the format and type aren't really significant for
1918 * TestProxyTexImage(). Only the internalformat really matters.
1919 if (!_mesa_source_buffer_exists(ctx, format)) {
1920 _mesa_error(ctx, GL_INVALID_OPERATION,
1921 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1928 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1929 * level, width, height and depth.
1931 if (dimensions
== 1) {
1932 if (target
== GL_TEXTURE_1D
) {
1933 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1934 level
, internalFormat
,
1936 width
, 1, 1, border
);
1939 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1943 else if (dimensions
== 2) {
1944 if (target
== GL_TEXTURE_2D
) {
1945 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1946 level
, internalFormat
,
1948 width
, height
, 1, border
);
1950 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1951 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1952 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1953 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1956 sizeOK
= (width
== height
) &&
1957 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1958 level
, internalFormat
, format
, type
,
1959 width
, height
, 1, border
);
1961 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1962 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1963 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1966 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1967 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1968 level
, internalFormat
,
1970 width
, height
, 1, border
);
1972 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1973 if (!ctx
->Extensions
.MESA_texture_array
) {
1974 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1977 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1978 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1979 level
, internalFormat
,
1981 width
, height
, 1, border
);
1984 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1989 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1994 if (dimensions
== 1) {
1995 _mesa_error(ctx
, GL_INVALID_VALUE
,
1996 "glCopyTexImage1D(width=%d)", width
);
1999 ASSERT(dimensions
== 2);
2000 _mesa_error(ctx
, GL_INVALID_VALUE
,
2001 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2006 if (is_compressed_format(ctx
, internalFormat
)) {
2007 if (target
!= GL_TEXTURE_2D
) {
2008 _mesa_error(ctx
, GL_INVALID_ENUM
,
2009 "glCopyTexImage%d(target)", dimensions
);
2013 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2014 "glCopyTexImage%D(border!=0)", dimensions
);
2018 else if (is_depth_format(internalFormat
)) {
2019 /* make sure we have depth/stencil buffers */
2020 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2021 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2022 "glCopyTexImage%D(no depth)", dimensions
);
2026 else if (is_depthstencil_format(internalFormat
)) {
2027 /* make sure we have depth/stencil buffers */
2028 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2029 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2030 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2035 /* if we get here, the parameters are OK */
2041 * Test glCopyTexSubImage[12]D() parameters for errors.
2043 * \param ctx GL context.
2044 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2045 * \param target texture target given by the user.
2046 * \param level image level given by the user.
2047 * \param xoffset sub-image x offset given by the user.
2048 * \param yoffset sub-image y offset given by the user.
2049 * \param zoffset sub-image z offset given by the user.
2050 * \param width image width given by the user.
2051 * \param height image height given by the user.
2053 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2055 * Verifies each of the parameters against the constants specified in
2056 * __GLcontextRec::Const and the supported extensions, and according to the
2057 * OpenGL specification.
2060 copytexsubimage_error_check( GLcontext
*ctx
, GLuint dimensions
,
2061 GLenum target
, GLint level
,
2062 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2063 GLsizei width
, GLsizei height
)
2066 /* Check that the source buffer is complete */
2067 if (ctx
->ReadBuffer
->Name
) {
2068 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2069 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2070 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2071 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2076 if (dimensions
== 1) {
2077 if (target
!= GL_TEXTURE_1D
) {
2078 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2082 else if (dimensions
== 2) {
2083 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2084 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2085 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2086 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2090 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2091 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2092 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2096 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2097 if (!ctx
->Extensions
.MESA_texture_array
) {
2098 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2102 else if (target
!= GL_TEXTURE_2D
) {
2103 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2107 else if (dimensions
== 3) {
2108 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2109 (!ctx
->Extensions
.MESA_texture_array
))
2110 && (target
!= GL_TEXTURE_3D
)) {
2111 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2117 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2118 _mesa_error(ctx
, GL_INVALID_VALUE
,
2119 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2125 _mesa_error(ctx
, GL_INVALID_VALUE
,
2126 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2129 if (dimensions
> 1 && height
< 0) {
2130 _mesa_error(ctx
, GL_INVALID_VALUE
,
2131 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2139 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2140 GLenum target
, GLint level
,
2141 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2142 GLsizei width
, GLsizei height
,
2143 const struct gl_texture_image
*teximage
)
2146 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2147 "glCopyTexSubImage%dD(undefined texture level: %d)",
2152 if (xoffset
< -((GLint
)teximage
->Border
)) {
2153 _mesa_error(ctx
, GL_INVALID_VALUE
,
2154 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2157 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2158 _mesa_error(ctx
, GL_INVALID_VALUE
,
2159 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2162 if (dimensions
> 1) {
2163 if (yoffset
< -((GLint
)teximage
->Border
)) {
2164 _mesa_error(ctx
, GL_INVALID_VALUE
,
2165 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2168 /* NOTE: we're adding the border here, not subtracting! */
2169 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2170 _mesa_error(ctx
, GL_INVALID_VALUE
,
2171 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2176 if (dimensions
> 2) {
2177 if (zoffset
< -((GLint
)teximage
->Border
)) {
2178 _mesa_error(ctx
, GL_INVALID_VALUE
,
2179 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2182 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2183 _mesa_error(ctx
, GL_INVALID_VALUE
,
2184 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2189 if (teximage
->IsCompressed
) {
2190 if (target
!= GL_TEXTURE_2D
) {
2191 _mesa_error(ctx
, GL_INVALID_ENUM
,
2192 "glCopyTexSubImage%d(target)", dimensions
);
2195 /* offset must be multiple of 4 */
2196 if ((xoffset
& 3) || (yoffset
& 3)) {
2197 _mesa_error(ctx
, GL_INVALID_VALUE
,
2198 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2201 /* size must be multiple of 4 */
2202 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2203 _mesa_error(ctx
, GL_INVALID_VALUE
,
2204 "glCopyTexSubImage%D(width)", dimensions
);
2207 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2208 _mesa_error(ctx
, GL_INVALID_VALUE
,
2209 "glCopyTexSubImage%D(height)", dimensions
);
2214 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2215 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2219 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2220 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2221 "glCopyTexSubImage%dD(missing readbuffer)", dimensions
);
2225 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2226 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2227 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2228 "glCopyTexSubImage%D(no depth buffer)",
2233 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2234 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2235 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2236 "glCopyTexSubImage%D(no depth/stencil buffer)",
2242 /* if we get here, the parameters are OK */
2248 * Get texture image. Called by glGetTexImage.
2250 * \param target texture target.
2251 * \param level image level.
2252 * \param format pixel data format for returned image.
2253 * \param type pixel data type for returned image.
2254 * \param pixels returned pixel data.
2257 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2258 GLenum type
, GLvoid
*pixels
)
2260 const struct gl_texture_unit
*texUnit
;
2261 struct gl_texture_object
*texObj
;
2262 struct gl_texture_image
*texImage
;
2263 GLint maxLevels
= 0;
2264 GET_CURRENT_CONTEXT(ctx
);
2265 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2267 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2268 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2269 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2270 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2274 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2275 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2277 if (level
< 0 || level
>= maxLevels
) {
2278 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2282 if (_mesa_sizeof_packed_type(type
) <= 0) {
2283 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2287 if (_mesa_components_in_format(format
) <= 0 ||
2288 format
== GL_STENCIL_INDEX
) {
2289 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2293 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2294 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2298 if (!ctx
->Extensions
.SGIX_depth_texture
&&
2299 !ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2300 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2304 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2305 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2309 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2310 && is_depthstencil_format(format
)) {
2311 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2318 _mesa_lock_texture(ctx
, texObj
);
2320 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2322 /* invalid mipmap level, not an error */
2327 /* Make sure the requested image format is compatible with the
2328 * texture's format. Note that a color index texture can be converted
2329 * to RGBA so that combo is allowed.
2331 if (is_color_format(format
)
2332 && !is_color_format(texImage
->TexFormat
->BaseFormat
)
2333 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2334 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2337 else if (is_index_format(format
)
2338 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2339 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2342 else if (is_depth_format(format
)
2343 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2344 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2345 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2348 else if (is_ycbcr_format(format
)
2349 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2350 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2353 else if (is_depthstencil_format(format
)
2354 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2355 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2359 if (ctx
->Pack
.BufferObj
->Name
) {
2360 /* packing texture image into a PBO */
2361 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2362 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2363 texImage
->Height
, texImage
->Depth
,
2364 format
, type
, pixels
)) {
2365 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2366 "glGetTexImage(invalid PBO access)");
2371 /* typically, this will call _mesa_get_teximage() */
2372 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2377 _mesa_unlock_texture(ctx
, texObj
);
2383 * Check if the given texture image is bound to any framebuffer objects
2384 * and update/invalidate them.
2385 * XXX We're only checking the currently bound framebuffer object for now.
2386 * In the future, perhaps struct gl_texture_image should have a pointer (or
2387 * list of pointers (yikes)) to the gl_framebuffer(s) which it's bound to.
2390 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2391 GLuint face
, GLuint level
)
2393 if (ctx
->DrawBuffer
->Name
) {
2395 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2396 struct gl_renderbuffer_attachment
*att
=
2397 ctx
->DrawBuffer
->Attachment
+ i
;
2398 if (att
->Type
== GL_TEXTURE
&&
2399 att
->Texture
== texObj
&&
2400 att
->TextureLevel
== level
&&
2401 att
->CubeMapFace
== face
) {
2402 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2403 /* Tell driver about the new renderbuffer texture */
2404 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2413 * Called from the API. Note that width includes the border.
2416 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2417 GLsizei width
, GLint border
, GLenum format
,
2418 GLenum type
, const GLvoid
*pixels
)
2420 GLsizei postConvWidth
= width
;
2421 GET_CURRENT_CONTEXT(ctx
);
2422 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2424 if (is_color_format(internalFormat
)) {
2425 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2428 if (target
== GL_TEXTURE_1D
) {
2429 /* non-proxy target */
2430 struct gl_texture_unit
*texUnit
;
2431 struct gl_texture_object
*texObj
;
2432 struct gl_texture_image
*texImage
;
2433 const GLuint face
= _mesa_tex_target_to_face(target
);
2435 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2436 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2437 return; /* error was recorded */
2440 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2441 _mesa_update_state(ctx
);
2443 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2444 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2445 _mesa_lock_texture(ctx
, texObj
);
2447 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2449 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2453 if (texImage
->Data
) {
2454 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2457 ASSERT(texImage
->Data
== NULL
);
2459 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2460 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2461 postConvWidth
, 1, 1,
2462 border
, internalFormat
);
2464 ASSERT(ctx
->Driver
.TexImage1D
);
2466 /* Give the texture to the driver! <pixels> may be null! */
2467 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2468 width
, border
, format
, type
, pixels
,
2469 &ctx
->Unpack
, texObj
, texImage
);
2471 ASSERT(texImage
->TexFormat
);
2473 update_fbo_texture(ctx
, texObj
, face
, level
);
2476 texObj
->_Complete
= GL_FALSE
;
2477 ctx
->NewState
|= _NEW_TEXTURE
;
2480 _mesa_unlock_texture(ctx
, texObj
);
2482 else if (target
== GL_PROXY_TEXTURE_1D
) {
2483 /* Proxy texture: check for errors and update proxy state */
2484 struct gl_texture_image
*texImage
;
2485 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2486 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2487 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2488 /* when error, clear all proxy texture image parameters */
2490 clear_teximage_fields(texImage
);
2493 /* no error, set the tex image parameters */
2495 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2496 postConvWidth
, 1, 1,
2497 border
, internalFormat
);
2498 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2499 internalFormat
, format
, type
);
2503 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2510 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2511 GLsizei width
, GLsizei height
, GLint border
,
2512 GLenum format
, GLenum type
,
2513 const GLvoid
*pixels
)
2515 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2516 GET_CURRENT_CONTEXT(ctx
);
2517 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2519 if (is_color_format(internalFormat
)) {
2520 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2524 if (target
== GL_TEXTURE_2D
||
2525 (ctx
->Extensions
.ARB_texture_cube_map
&&
2526 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2527 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2528 (ctx
->Extensions
.NV_texture_rectangle
&&
2529 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2530 (ctx
->Extensions
.MESA_texture_array
&&
2531 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2532 /* non-proxy target */
2533 struct gl_texture_unit
*texUnit
;
2534 struct gl_texture_object
*texObj
;
2535 struct gl_texture_image
*texImage
;
2536 const GLuint face
= _mesa_tex_target_to_face(target
);
2538 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2539 format
, type
, 2, postConvWidth
, postConvHeight
,
2541 return; /* error was recorded */
2544 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2545 _mesa_update_state(ctx
);
2547 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2548 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2549 _mesa_lock_texture(ctx
, texObj
);
2551 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2553 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2557 if (texImage
->Data
) {
2558 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2561 ASSERT(texImage
->Data
== NULL
);
2562 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2563 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2564 postConvWidth
, postConvHeight
, 1,
2565 border
, internalFormat
);
2567 ASSERT(ctx
->Driver
.TexImage2D
);
2569 /* Give the texture to the driver! <pixels> may be null! */
2570 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2571 width
, height
, border
, format
, type
, pixels
,
2572 &ctx
->Unpack
, texObj
, texImage
);
2574 ASSERT(texImage
->TexFormat
);
2576 update_fbo_texture(ctx
, texObj
, face
, level
);
2579 texObj
->_Complete
= GL_FALSE
;
2580 ctx
->NewState
|= _NEW_TEXTURE
;
2583 _mesa_unlock_texture(ctx
, texObj
);
2585 else if (target
== GL_PROXY_TEXTURE_2D
||
2586 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2587 ctx
->Extensions
.ARB_texture_cube_map
) ||
2588 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2589 ctx
->Extensions
.NV_texture_rectangle
) ||
2590 (ctx
->Extensions
.MESA_texture_array
&&
2591 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2592 /* Proxy texture: check for errors and update proxy state */
2593 struct gl_texture_image
*texImage
;
2594 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2595 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2596 format
, type
, 2, postConvWidth
, postConvHeight
,
2598 /* when error, clear all proxy texture image parameters */
2600 clear_teximage_fields(ctx
->Texture
.Proxy2D
->Image
[0][level
]);
2603 /* no error, set the tex image parameters */
2604 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2605 postConvWidth
, postConvHeight
, 1,
2606 border
, internalFormat
);
2607 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2608 internalFormat
, format
, type
);
2612 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2619 * Called by the API or display list executor.
2620 * Note that width and height include the border.
2623 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2624 GLsizei width
, GLsizei height
, GLsizei depth
,
2625 GLint border
, GLenum format
, GLenum type
,
2626 const GLvoid
*pixels
)
2628 GET_CURRENT_CONTEXT(ctx
);
2629 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2631 if (target
== GL_TEXTURE_3D
||
2632 (ctx
->Extensions
.MESA_texture_array
&&
2633 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2634 /* non-proxy target */
2635 struct gl_texture_unit
*texUnit
;
2636 struct gl_texture_object
*texObj
;
2637 struct gl_texture_image
*texImage
;
2638 const GLuint face
= _mesa_tex_target_to_face(target
);
2640 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2641 format
, type
, 3, width
, height
, depth
, border
)) {
2642 return; /* error was recorded */
2645 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2646 _mesa_update_state(ctx
);
2648 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2649 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2650 _mesa_lock_texture(ctx
, texObj
);
2652 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2654 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2658 if (texImage
->Data
) {
2659 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2662 ASSERT(texImage
->Data
== NULL
);
2663 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2664 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2665 width
, height
, depth
,
2666 border
, internalFormat
);
2668 ASSERT(ctx
->Driver
.TexImage3D
);
2670 /* Give the texture to the driver! <pixels> may be null! */
2671 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2672 width
, height
, depth
, border
, format
, type
,
2673 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2675 ASSERT(texImage
->TexFormat
);
2677 update_fbo_texture(ctx
, texObj
, face
, level
);
2680 texObj
->_Complete
= GL_FALSE
;
2681 ctx
->NewState
|= _NEW_TEXTURE
;
2684 _mesa_unlock_texture(ctx
, texObj
);
2686 else if (target
== GL_PROXY_TEXTURE_3D
||
2687 (ctx
->Extensions
.MESA_texture_array
&&
2688 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2689 /* Proxy texture: check for errors and update proxy state */
2690 struct gl_texture_image
*texImage
;
2691 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2692 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2693 format
, type
, 3, width
, height
, depth
, border
)) {
2694 /* when error, clear all proxy texture image parameters */
2696 clear_teximage_fields(texImage
);
2699 /* no error, set the tex image parameters */
2700 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2701 border
, internalFormat
);
2702 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2703 internalFormat
, format
, type
);
2707 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2714 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2715 GLsizei width
, GLsizei height
, GLsizei depth
,
2716 GLint border
, GLenum format
, GLenum type
,
2717 const GLvoid
*pixels
)
2719 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2720 depth
, border
, format
, type
, pixels
);
2726 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2727 GLint xoffset
, GLsizei width
,
2728 GLenum format
, GLenum type
,
2729 const GLvoid
*pixels
)
2731 GLsizei postConvWidth
= width
;
2732 struct gl_texture_unit
*texUnit
;
2733 struct gl_texture_object
*texObj
;
2734 struct gl_texture_image
*texImage
= NULL
;
2735 GET_CURRENT_CONTEXT(ctx
);
2736 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2738 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2739 _mesa_update_state(ctx
);
2741 /* XXX should test internal format */
2742 if (is_color_format(format
)) {
2743 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2746 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2747 postConvWidth
, 1, 1, format
, type
)) {
2748 return; /* error was detected */
2752 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2753 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2756 _mesa_lock_texture(ctx
, texObj
);
2758 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2760 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2761 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2762 goto out
; /* error was detected */
2766 goto out
; /* no-op, not an error */
2768 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2769 xoffset
+= texImage
->Border
;
2771 ASSERT(ctx
->Driver
.TexSubImage1D
);
2772 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2773 format
, type
, pixels
, &ctx
->Unpack
,
2775 ctx
->NewState
|= _NEW_TEXTURE
;
2778 _mesa_unlock_texture(ctx
, texObj
);
2783 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2784 GLint xoffset
, GLint yoffset
,
2785 GLsizei width
, GLsizei height
,
2786 GLenum format
, GLenum type
,
2787 const GLvoid
*pixels
)
2789 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2790 struct gl_texture_unit
*texUnit
;
2791 struct gl_texture_object
*texObj
;
2792 struct gl_texture_image
*texImage
;
2793 GET_CURRENT_CONTEXT(ctx
);
2794 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2796 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2797 _mesa_update_state(ctx
);
2799 /* XXX should test internal format */
2800 if (is_color_format(format
)) {
2801 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2805 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2806 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2807 return; /* error was detected */
2810 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2811 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2812 _mesa_lock_texture(ctx
, texObj
);
2814 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2816 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2817 postConvWidth
, postConvHeight
, 1, format
, type
,
2819 goto out
; /* error was detected */
2822 if (width
== 0 || height
== 0)
2823 goto out
; /* no-op, not an error */
2825 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2826 xoffset
+= texImage
->Border
;
2827 yoffset
+= texImage
->Border
;
2829 ASSERT(ctx
->Driver
.TexSubImage2D
);
2830 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2831 width
, height
, format
, type
, pixels
,
2832 &ctx
->Unpack
, texObj
, texImage
);
2833 ctx
->NewState
|= _NEW_TEXTURE
;
2836 _mesa_unlock_texture(ctx
, texObj
);
2842 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2843 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2844 GLsizei width
, GLsizei height
, GLsizei depth
,
2845 GLenum format
, GLenum type
,
2846 const GLvoid
*pixels
)
2848 struct gl_texture_unit
*texUnit
;
2849 struct gl_texture_object
*texObj
;
2850 struct gl_texture_image
*texImage
;
2851 GET_CURRENT_CONTEXT(ctx
);
2852 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2854 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2855 _mesa_update_state(ctx
);
2857 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2858 width
, height
, depth
, format
, type
)) {
2859 return; /* error was detected */
2862 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2863 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2865 _mesa_lock_texture(ctx
, texObj
);
2867 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2869 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2870 width
, height
, depth
, format
, type
, texImage
)) {
2871 goto out
; /* error was detected */
2874 if (width
== 0 || height
== 0 || height
== 0)
2875 goto out
; /* no-op, not an error */
2877 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2878 xoffset
+= texImage
->Border
;
2879 yoffset
+= texImage
->Border
;
2880 zoffset
+= texImage
->Border
;
2882 ASSERT(ctx
->Driver
.TexSubImage3D
);
2883 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2884 xoffset
, yoffset
, zoffset
,
2885 width
, height
, depth
,
2886 format
, type
, pixels
,
2887 &ctx
->Unpack
, texObj
, texImage
);
2888 ctx
->NewState
|= _NEW_TEXTURE
;
2891 _mesa_unlock_texture(ctx
, texObj
);
2897 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2898 GLenum internalFormat
,
2900 GLsizei width
, GLint border
)
2902 struct gl_texture_unit
*texUnit
;
2903 struct gl_texture_object
*texObj
;
2904 struct gl_texture_image
*texImage
;
2905 GLsizei postConvWidth
= width
;
2906 const GLuint face
= _mesa_tex_target_to_face(target
);
2907 GET_CURRENT_CONTEXT(ctx
);
2908 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2910 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2911 _mesa_update_state(ctx
);
2913 if (is_color_format(internalFormat
)) {
2914 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2917 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2918 postConvWidth
, 1, border
))
2921 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2922 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2923 _mesa_lock_texture(ctx
, texObj
);
2925 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2927 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2931 if (texImage
->Data
) {
2932 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2935 ASSERT(texImage
->Data
== NULL
);
2937 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2938 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2939 border
, internalFormat
);
2942 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2943 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2944 x
, y
, width
, border
);
2946 ASSERT(texImage
->TexFormat
);
2948 update_fbo_texture(ctx
, texObj
, face
, level
);
2951 texObj
->_Complete
= GL_FALSE
;
2952 ctx
->NewState
|= _NEW_TEXTURE
;
2955 _mesa_unlock_texture(ctx
, texObj
);
2961 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2962 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2965 struct gl_texture_unit
*texUnit
;
2966 struct gl_texture_object
*texObj
;
2967 struct gl_texture_image
*texImage
;
2968 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2969 const GLuint face
= _mesa_tex_target_to_face(target
);
2970 GET_CURRENT_CONTEXT(ctx
);
2971 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2973 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2974 _mesa_update_state(ctx
);
2976 if (is_color_format(internalFormat
)) {
2977 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2981 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2982 postConvWidth
, postConvHeight
, border
))
2985 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2986 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2988 _mesa_lock_texture(ctx
, texObj
);
2990 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2993 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2997 if (texImage
->Data
) {
2998 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3001 ASSERT(texImage
->Data
== NULL
);
3003 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3004 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3005 postConvWidth
, postConvHeight
, 1,
3006 border
, internalFormat
);
3008 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3009 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3010 x
, y
, width
, height
, border
);
3012 ASSERT(texImage
->TexFormat
);
3014 update_fbo_texture(ctx
, texObj
, face
, level
);
3017 texObj
->_Complete
= GL_FALSE
;
3018 ctx
->NewState
|= _NEW_TEXTURE
;
3021 _mesa_unlock_texture(ctx
, texObj
);
3026 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3027 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3029 struct gl_texture_unit
*texUnit
;
3030 struct gl_texture_object
*texObj
;
3031 struct gl_texture_image
*texImage
;
3032 GLsizei postConvWidth
= width
;
3036 GET_CURRENT_CONTEXT(ctx
);
3037 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3039 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3040 _mesa_update_state(ctx
);
3042 /* XXX should test internal format */
3043 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3045 if (copytexsubimage_error_check(ctx
, 1, target
, level
,
3046 xoffset
, 0, 0, postConvWidth
, 1))
3049 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3050 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3052 _mesa_lock_texture(ctx
, texObj
);
3054 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3056 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3057 xoffset
, 0, 0, postConvWidth
, 1,
3062 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3063 xoffset
+= texImage
->Border
;
3065 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3067 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3068 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3069 xoffset
, x
, y
, width
);
3072 ctx
->NewState
|= _NEW_TEXTURE
;
3075 _mesa_unlock_texture(ctx
, texObj
);
3081 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3082 GLint xoffset
, GLint yoffset
,
3083 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3085 struct gl_texture_unit
*texUnit
;
3086 struct gl_texture_object
*texObj
;
3087 struct gl_texture_image
*texImage
;
3088 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3089 GET_CURRENT_CONTEXT(ctx
);
3090 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3092 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3093 _mesa_update_state(ctx
);
3095 /* XXX should test internal format */
3096 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
3098 if (copytexsubimage_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3099 postConvWidth
, postConvHeight
))
3102 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3103 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3105 _mesa_lock_texture(ctx
, texObj
);
3107 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3109 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3110 postConvWidth
, postConvHeight
, texImage
))
3113 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3114 xoffset
+= texImage
->Border
;
3115 yoffset
+= texImage
->Border
;
3117 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3119 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3120 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3121 xoffset
, yoffset
, x
, y
, width
, height
);
3124 ctx
->NewState
|= _NEW_TEXTURE
;
3127 _mesa_unlock_texture(ctx
, texObj
);
3133 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3134 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3135 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3137 struct gl_texture_unit
*texUnit
;
3138 struct gl_texture_object
*texObj
;
3139 struct gl_texture_image
*texImage
;
3140 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3141 GET_CURRENT_CONTEXT(ctx
);
3142 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3144 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3145 _mesa_update_state(ctx
);
3147 /* XXX should test internal format */
3148 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
3150 if (copytexsubimage_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
,
3151 zoffset
, postConvWidth
, postConvHeight
))
3154 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3155 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3157 _mesa_lock_texture(ctx
, texObj
);
3159 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3161 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3162 zoffset
, postConvWidth
, postConvHeight
,
3166 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3167 xoffset
+= texImage
->Border
;
3168 yoffset
+= texImage
->Border
;
3169 zoffset
+= texImage
->Border
;
3171 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3173 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3174 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3175 xoffset
, yoffset
, zoffset
,
3176 x
, y
, width
, height
);
3179 ctx
->NewState
|= _NEW_TEXTURE
;
3182 _mesa_unlock_texture(ctx
, texObj
);
3188 /**********************************************************************/
3189 /****** Compressed Textures ******/
3190 /**********************************************************************/
3194 * Error checking for glCompressedTexImage[123]D().
3195 * \return error code or GL_NO_ERROR.
3198 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3199 GLenum target
, GLint level
,
3200 GLenum internalFormat
, GLsizei width
,
3201 GLsizei height
, GLsizei depth
, GLint border
,
3204 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3206 if (dimensions
== 1) {
3207 /* 1D compressed textures not allowed */
3208 return GL_INVALID_ENUM
;
3210 else if (dimensions
== 2) {
3211 if (target
== GL_PROXY_TEXTURE_2D
) {
3212 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3214 else if (target
== GL_TEXTURE_2D
) {
3215 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3217 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3218 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3219 return GL_INVALID_ENUM
; /*target*/
3220 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3222 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3223 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3224 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3225 return GL_INVALID_ENUM
; /*target*/
3226 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3229 return GL_INVALID_ENUM
; /*target*/
3232 else if (dimensions
== 3) {
3233 /* 3D compressed textures not allowed */
3234 return GL_INVALID_ENUM
;
3237 maxTextureSize
= 1 << (maxLevels
- 1);
3239 /* This will detect any invalid internalFormat value */
3240 if (!is_compressed_format(ctx
, internalFormat
))
3241 return GL_INVALID_ENUM
;
3243 /* This should really never fail */
3244 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3245 return GL_INVALID_ENUM
;
3248 return GL_INVALID_VALUE
;
3251 * XXX We should probably use the proxy texture error check function here.
3253 if (width
< 1 || width
> maxTextureSize
||
3254 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(width
) != 1))
3255 return GL_INVALID_VALUE
;
3257 if ((height
< 1 || height
> maxTextureSize
||
3258 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(height
) != 1))
3260 return GL_INVALID_VALUE
;
3262 if ((depth
< 1 || depth
> maxTextureSize
||
3263 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(depth
) != 1))
3265 return GL_INVALID_VALUE
;
3267 /* For cube map, width must equal height */
3268 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3269 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3270 return GL_INVALID_VALUE
;
3272 if (level
< 0 || level
>= maxLevels
)
3273 return GL_INVALID_VALUE
;
3275 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3276 depth
, internalFormat
);
3277 if (expectedSize
!= imageSize
)
3278 return GL_INVALID_VALUE
;
3280 #if FEATURE_EXT_texture_sRGB
3281 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3282 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3283 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3284 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3286 return GL_INVALID_OPERATION
;
3295 * Error checking for glCompressedTexSubImage[123]D().
3296 * \warning There are some bad assumptions here about the size of compressed
3297 * texture tiles (multiple of 4) used to test the validity of the
3298 * offset and size parameters.
3299 * \return error code or GL_NO_ERROR.
3302 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3303 GLenum target
, GLint level
,
3304 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3305 GLsizei width
, GLsizei height
, GLsizei depth
,
3306 GLenum format
, GLsizei imageSize
)
3308 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3311 if (dimensions
== 1) {
3312 /* 1D compressed textures not allowed */
3313 return GL_INVALID_ENUM
;
3315 else if (dimensions
== 2) {
3316 if (target
== GL_PROXY_TEXTURE_2D
) {
3317 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3319 else if (target
== GL_TEXTURE_2D
) {
3320 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3322 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3323 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3324 return GL_INVALID_ENUM
; /*target*/
3325 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3327 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3328 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3329 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3330 return GL_INVALID_ENUM
; /*target*/
3331 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3334 return GL_INVALID_ENUM
; /*target*/
3337 else if (dimensions
== 3) {
3338 /* 3D compressed textures not allowed */
3339 return GL_INVALID_ENUM
;
3342 maxTextureSize
= 1 << (maxLevels
- 1);
3344 /* this will catch any invalid compressed format token */
3345 if (!is_compressed_format(ctx
, format
))
3346 return GL_INVALID_ENUM
;
3348 if (width
< 1 || width
> maxTextureSize
)
3349 return GL_INVALID_VALUE
;
3351 if ((height
< 1 || height
> maxTextureSize
)
3353 return GL_INVALID_VALUE
;
3355 if (level
< 0 || level
>= maxLevels
)
3356 return GL_INVALID_VALUE
;
3358 /* XXX these tests are specific to the compressed format.
3359 * this code should be generalized in some way.
3361 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3362 return GL_INVALID_VALUE
;
3364 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3365 return GL_INVALID_VALUE
;
3367 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3368 return GL_INVALID_VALUE
;
3370 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3372 if (expectedSize
!= imageSize
)
3373 return GL_INVALID_VALUE
;
3381 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3382 GLenum internalFormat
, GLsizei width
,
3383 GLint border
, GLsizei imageSize
,
3386 GET_CURRENT_CONTEXT(ctx
);
3387 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3389 if (target
== GL_TEXTURE_1D
) {
3390 /* non-proxy target */
3391 struct gl_texture_unit
*texUnit
;
3392 struct gl_texture_object
*texObj
;
3393 struct gl_texture_image
*texImage
;
3394 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3395 internalFormat
, width
, 1, 1, border
, imageSize
);
3397 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3401 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3402 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3404 _mesa_lock_texture(ctx
, texObj
);
3406 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3408 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3412 if (texImage
->Data
) {
3413 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3415 ASSERT(texImage
->Data
== NULL
);
3417 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3418 border
, internalFormat
);
3420 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3421 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3422 internalFormat
, width
, border
,
3427 texObj
->_Complete
= GL_FALSE
;
3428 ctx
->NewState
|= _NEW_TEXTURE
;
3431 _mesa_unlock_texture(ctx
, texObj
);
3433 else if (target
== GL_PROXY_TEXTURE_1D
) {
3434 /* Proxy texture: check for errors and update proxy state */
3435 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3436 internalFormat
, width
, 1, 1, border
, imageSize
);
3438 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3439 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3440 internalFormat
, GL_NONE
, GL_NONE
,
3441 width
, 1, 1, border
);
3444 /* if error, clear all proxy texture image parameters */
3445 struct gl_texture_image
*texImage
;
3446 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3448 clear_teximage_fields(texImage
);
3451 /* store the teximage parameters */
3452 struct gl_texture_unit
*texUnit
;
3453 struct gl_texture_object
*texObj
;
3454 struct gl_texture_image
*texImage
;
3455 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3456 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3458 _mesa_lock_texture(ctx
, texObj
);
3460 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3461 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3462 border
, internalFormat
);
3464 _mesa_unlock_texture(ctx
, texObj
);
3468 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3475 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3476 GLenum internalFormat
, GLsizei width
,
3477 GLsizei height
, GLint border
, GLsizei imageSize
,
3480 GET_CURRENT_CONTEXT(ctx
);
3481 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3483 if (target
== GL_TEXTURE_2D
||
3484 (ctx
->Extensions
.ARB_texture_cube_map
&&
3485 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3486 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3487 /* non-proxy target */
3488 struct gl_texture_unit
*texUnit
;
3489 struct gl_texture_object
*texObj
;
3490 struct gl_texture_image
*texImage
;
3491 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3492 internalFormat
, width
, height
, 1, border
, imageSize
);
3494 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3498 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3499 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3501 _mesa_lock_texture(ctx
, texObj
);
3503 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3505 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3509 if (texImage
->Data
) {
3510 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3512 ASSERT(texImage
->Data
== NULL
);
3514 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3515 border
, internalFormat
);
3517 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3518 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3519 internalFormat
, width
, height
,
3520 border
, imageSize
, data
,
3524 texObj
->_Complete
= GL_FALSE
;
3525 ctx
->NewState
|= _NEW_TEXTURE
;
3528 _mesa_unlock_texture(ctx
, texObj
);
3530 else if (target
== GL_PROXY_TEXTURE_2D
||
3531 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3532 ctx
->Extensions
.ARB_texture_cube_map
)) {
3533 /* Proxy texture: check for errors and update proxy state */
3534 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3535 internalFormat
, width
, height
, 1, border
, imageSize
);
3537 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3538 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3539 internalFormat
, GL_NONE
, GL_NONE
,
3540 width
, height
, 1, border
);
3543 /* if error, clear all proxy texture image parameters */
3544 struct gl_texture_image
*texImage
;
3545 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3547 clear_teximage_fields(texImage
);
3550 /* store the teximage parameters */
3551 struct gl_texture_unit
*texUnit
;
3552 struct gl_texture_object
*texObj
;
3553 struct gl_texture_image
*texImage
;
3554 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3555 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3557 _mesa_lock_texture(ctx
, texObj
);
3559 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3560 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3561 border
, internalFormat
);
3563 _mesa_unlock_texture(ctx
, texObj
);
3567 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3574 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3575 GLenum internalFormat
, GLsizei width
,
3576 GLsizei height
, GLsizei depth
, GLint border
,
3577 GLsizei imageSize
, const GLvoid
*data
)
3579 GET_CURRENT_CONTEXT(ctx
);
3580 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3582 if (target
== GL_TEXTURE_3D
) {
3583 /* non-proxy target */
3584 struct gl_texture_unit
*texUnit
;
3585 struct gl_texture_object
*texObj
;
3586 struct gl_texture_image
*texImage
;
3587 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3588 internalFormat
, width
, height
, depth
, border
, imageSize
);
3590 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3594 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3595 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3596 _mesa_lock_texture(ctx
, texObj
);
3598 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3600 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3604 if (texImage
->Data
) {
3605 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3607 ASSERT(texImage
->Data
== NULL
);
3609 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3610 border
, internalFormat
);
3612 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3613 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3615 width
, height
, depth
,
3616 border
, imageSize
, data
,
3620 texObj
->_Complete
= GL_FALSE
;
3621 ctx
->NewState
|= _NEW_TEXTURE
;
3624 _mesa_unlock_texture(ctx
, texObj
);
3626 else if (target
== GL_PROXY_TEXTURE_3D
) {
3627 /* Proxy texture: check for errors and update proxy state */
3628 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3629 internalFormat
, width
, height
, depth
, border
, imageSize
);
3631 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3632 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3633 internalFormat
, GL_NONE
, GL_NONE
,
3634 width
, height
, depth
, border
);
3637 /* if error, clear all proxy texture image parameters */
3638 struct gl_texture_image
*texImage
;
3639 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3641 clear_teximage_fields(texImage
);
3644 /* store the teximage parameters */
3645 struct gl_texture_unit
*texUnit
;
3646 struct gl_texture_object
*texObj
;
3647 struct gl_texture_image
*texImage
;
3648 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3649 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3650 _mesa_lock_texture(ctx
, texObj
);
3652 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3653 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3654 depth
, border
, internalFormat
);
3656 _mesa_unlock_texture(ctx
, texObj
);
3660 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3667 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3668 GLsizei width
, GLenum format
,
3669 GLsizei imageSize
, const GLvoid
*data
)
3671 struct gl_texture_unit
*texUnit
;
3672 struct gl_texture_object
*texObj
;
3673 struct gl_texture_image
*texImage
;
3675 GET_CURRENT_CONTEXT(ctx
);
3676 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3678 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3679 xoffset
, 0, 0, /* pos */
3680 width
, 1, 1, /* size */
3683 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3687 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3688 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3689 _mesa_lock_texture(ctx
, texObj
);
3691 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3694 if ((GLint
) format
!= texImage
->InternalFormat
) {
3695 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3696 "glCompressedTexSubImage1D(format)");
3700 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3701 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3706 goto out
; /* no-op, not an error */
3708 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3709 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3711 format
, imageSize
, data
,
3714 ctx
->NewState
|= _NEW_TEXTURE
;
3717 _mesa_unlock_texture(ctx
, texObj
);
3722 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3723 GLint yoffset
, GLsizei width
, GLsizei height
,
3724 GLenum format
, GLsizei imageSize
,
3727 struct gl_texture_unit
*texUnit
;
3728 struct gl_texture_object
*texObj
;
3729 struct gl_texture_image
*texImage
;
3731 GET_CURRENT_CONTEXT(ctx
);
3732 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3734 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3735 xoffset
, yoffset
, 0, /* pos */
3736 width
, height
, 1, /* size */
3739 /* XXX proxy target? */
3740 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3744 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3745 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3746 _mesa_lock_texture(ctx
, texObj
);
3748 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3751 if ((GLint
) format
!= texImage
->InternalFormat
) {
3752 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3753 "glCompressedTexSubImage2D(format)");
3757 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3758 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3759 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3763 if (width
== 0 || height
== 0)
3764 goto out
; /* no-op, not an error */
3766 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3767 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3768 xoffset
, yoffset
, width
, height
,
3769 format
, imageSize
, data
,
3772 ctx
->NewState
|= _NEW_TEXTURE
;
3775 _mesa_unlock_texture(ctx
, texObj
);
3780 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3781 GLint yoffset
, GLint zoffset
, GLsizei width
,
3782 GLsizei height
, GLsizei depth
, GLenum format
,
3783 GLsizei imageSize
, const GLvoid
*data
)
3785 struct gl_texture_unit
*texUnit
;
3786 struct gl_texture_object
*texObj
;
3787 struct gl_texture_image
*texImage
;
3789 GET_CURRENT_CONTEXT(ctx
);
3790 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3792 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3793 xoffset
, yoffset
, zoffset
,/*pos*/
3794 width
, height
, depth
, /*size*/
3797 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3801 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3802 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3803 _mesa_lock_texture(ctx
, texObj
);
3805 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3808 if ((GLint
) format
!= texImage
->InternalFormat
) {
3809 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3810 "glCompressedTexSubImage3D(format)");
3814 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3815 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3816 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3817 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3821 if (width
== 0 || height
== 0 || depth
== 0)
3822 goto out
; /* no-op, not an error */
3824 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3825 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3826 xoffset
, yoffset
, zoffset
,
3827 width
, height
, depth
,
3828 format
, imageSize
, data
,
3831 ctx
->NewState
|= _NEW_TEXTURE
;
3834 _mesa_unlock_texture(ctx
, texObj
);
3839 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3841 const struct gl_texture_unit
*texUnit
;
3842 struct gl_texture_object
*texObj
;
3843 struct gl_texture_image
*texImage
;
3845 GET_CURRENT_CONTEXT(ctx
);
3846 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3848 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3849 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3851 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3855 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3856 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3858 if (level
< 0 || level
>= maxLevels
) {
3859 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3863 if (_mesa_is_proxy_texture(target
)) {
3864 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3868 _mesa_lock_texture(ctx
, texObj
);
3870 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3872 if (texImage
->IsCompressed
) {
3873 /* this typically calls _mesa_get_compressed_teximage() */
3874 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3878 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3879 "glGetCompressedTexImageARB");
3883 /* probably invalid mipmap level */
3884 _mesa_error(ctx
, GL_INVALID_VALUE
,
3885 "glGetCompressedTexImageARB(level)");
3888 _mesa_unlock_texture(ctx
, texObj
);