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
;
1218 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1219 img
->WidthLog2
= logbase2(img
->Width2
);
1221 if (height
== 1) { /* 1-D texture */
1223 img
->HeightLog2
= 0;
1226 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1227 img
->HeightLog2
= logbase2(img
->Height2
);
1230 if (depth
== 1) { /* 2-D texture */
1235 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1236 img
->DepthLog2
= logbase2(img
->Depth2
);
1239 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1241 img
->IsCompressed
= GL_FALSE
;
1242 img
->CompressedSize
= 0;
1244 if ((width
== 1 || _mesa_bitcount(img
->Width2
) == 1) &&
1245 (height
== 1 || _mesa_bitcount(img
->Height2
) == 1) &&
1246 (depth
== 1 || _mesa_bitcount(img
->Depth2
) == 1))
1247 img
->_IsPowerOfTwo
= GL_TRUE
;
1249 img
->_IsPowerOfTwo
= GL_FALSE
;
1251 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1252 img
->RowStride
= width
;
1253 /* Allocate the ImageOffsets array and initialize to typical values.
1254 * We allocate the array for 1D/2D textures too in order to avoid special-
1255 * case code in the texstore routines.
1257 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1258 for (i
= 0; i
< depth
; i
++) {
1259 img
->ImageOffsets
[i
] = i
* width
* height
;
1262 /* Compute Width/Height/DepthScale for mipmap lod computation */
1263 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1264 /* scale = 1.0 since texture coords directly map to texels */
1265 img
->WidthScale
= 1.0;
1266 img
->HeightScale
= 1.0;
1267 img
->DepthScale
= 1.0;
1270 img
->WidthScale
= (GLfloat
) img
->Width
;
1271 img
->HeightScale
= (GLfloat
) img
->Height
;
1272 img
->DepthScale
= (GLfloat
) img
->Depth
;
1278 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1279 * level, width, height and depth against the ctx->Const limits for textures.
1281 * A hardware driver might override this function if, for example, the
1282 * max 3D texture size is 512x512x64 (i.e. not a cube).
1284 * Note that width, height, depth == 0 is not an error. However, a
1285 * texture with zero width/height/depth will be considered "incomplete"
1286 * and texturing will effectively be disabled.
1288 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1289 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1290 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1291 * \param level as passed to glTexImage
1292 * \param internalFormat as passed to glTexImage
1293 * \param format as passed to glTexImage
1294 * \param type as passed to glTexImage
1295 * \param width as passed to glTexImage
1296 * \param height as passed to glTexImage
1297 * \param depth as passed to glTexImage
1298 * \param border as passed to glTexImage
1299 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1302 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1303 GLint internalFormat
, GLenum format
, GLenum type
,
1304 GLint width
, GLint height
, GLint depth
, GLint border
)
1308 (void) internalFormat
;
1313 case GL_PROXY_TEXTURE_1D
:
1314 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1315 if (width
< 2 * border
|| width
> 2 + maxSize
||
1316 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1317 width
>0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1318 level
>= ctx
->Const
.MaxTextureLevels
) {
1319 /* bad width or level */
1323 case GL_PROXY_TEXTURE_2D
:
1324 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1325 if (width
< 2 * border
|| width
> 2 + maxSize
||
1326 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1327 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1328 height
< 2 * border
|| height
> 2 + maxSize
||
1329 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1330 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1331 level
>= ctx
->Const
.MaxTextureLevels
) {
1332 /* bad width or height or level */
1336 case GL_PROXY_TEXTURE_3D
:
1337 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1338 if (width
< 2 * border
|| width
> 2 + maxSize
||
1339 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1340 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1341 height
< 2 * border
|| height
> 2 + maxSize
||
1342 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1343 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1344 depth
< 2 * border
|| depth
> 2 + maxSize
||
1345 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1346 depth
> 0 && _mesa_bitcount(depth
- 2 * border
) != 1) ||
1347 level
>= ctx
->Const
.Max3DTextureLevels
) {
1348 /* bad width or height or depth or level */
1352 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1353 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1354 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1356 /* bad width or height or level */
1360 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1361 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1362 if (width
< 2 * border
|| width
> 2 + maxSize
||
1363 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1364 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1365 height
< 2 * border
|| height
> 2 + maxSize
||
1366 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1367 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1368 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1369 /* bad width or height */
1373 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1374 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1375 if (width
< 2 * border
|| width
> 2 + maxSize
||
1376 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1377 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1378 level
>= ctx
->Const
.MaxTextureLevels
) {
1379 /* bad width or level */
1383 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1387 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1388 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1389 if (width
< 2 * border
|| width
> 2 + maxSize
||
1390 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1391 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1392 height
< 2 * border
|| height
> 2 + maxSize
||
1393 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1394 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1395 level
>= ctx
->Const
.MaxTextureLevels
) {
1396 /* bad width or height or level */
1399 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1404 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1411 * Helper function to determine whether a target supports compressed textures
1414 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1416 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1417 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1418 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1419 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1420 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1421 || ((ctx
->Extensions
.MESA_texture_array
&&
1422 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1423 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1428 * Test the glTexImage[123]D() parameters for errors.
1430 * \param ctx GL context.
1431 * \param target texture target given by the user.
1432 * \param level image level given by the user.
1433 * \param internalFormat internal format given by the user.
1434 * \param format pixel data format given by the user.
1435 * \param type pixel data type given by the user.
1436 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1437 * \param width image width given by the user.
1438 * \param height image height given by the user.
1439 * \param depth image depth given by the user.
1440 * \param border image border given by the user.
1442 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1444 * Verifies each of the parameters against the constants specified in
1445 * __GLcontextRec::Const and the supported extensions, and according to the
1446 * OpenGL specification.
1449 texture_error_check( GLcontext
*ctx
, GLenum target
,
1450 GLint level
, GLint internalFormat
,
1451 GLenum format
, GLenum type
,
1453 GLint width
, GLint height
,
1454 GLint depth
, GLint border
)
1456 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1457 GLboolean sizeOK
= GL_TRUE
;
1458 GLboolean colorFormat
, indexFormat
;
1459 GLenum proxy_target
;
1461 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1462 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1464 _mesa_error(ctx
, GL_INVALID_VALUE
,
1465 "glTexImage%dD(level=%d)", dimensions
, level
);
1471 if (border
< 0 || border
> 1 ||
1472 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1473 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1475 _mesa_error(ctx
, GL_INVALID_VALUE
,
1476 "glTexImage%dD(border=%d)", dimensions
, border
);
1481 if (width
< 0 || height
< 0 || depth
< 0) {
1483 _mesa_error(ctx
, GL_INVALID_VALUE
,
1484 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1489 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1490 * level, width, height and depth.
1492 if (dimensions
== 1) {
1493 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1494 proxy_target
= GL_PROXY_TEXTURE_1D
;
1499 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1503 else if (dimensions
== 2) {
1505 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1506 proxy_target
= GL_PROXY_TEXTURE_2D
;
1508 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1509 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1510 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1511 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1512 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1515 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1516 sizeOK
= (width
== height
);
1518 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1519 target
== GL_TEXTURE_RECTANGLE_NV
) {
1520 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1521 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1524 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1526 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1527 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1528 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1531 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1535 else if (dimensions
== 3) {
1536 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1537 proxy_target
= GL_PROXY_TEXTURE_3D
;
1539 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1540 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1541 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1544 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1549 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1553 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1554 internalFormat
, format
,
1555 type
, width
, height
,
1559 _mesa_error(ctx
, GL_INVALID_VALUE
,
1560 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1561 dimensions
, level
, width
, height
, depth
);
1566 /* Check internalFormat */
1567 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1569 _mesa_error(ctx
, GL_INVALID_VALUE
,
1570 "glTexImage%dD(internalFormat=0x%x)",
1571 dimensions
, internalFormat
);
1576 /* Check incoming image format and type */
1577 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1578 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1579 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1582 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1583 "glTexImage%dD(format or type)", dimensions
);
1588 /* make sure internal format and format basically agree */
1589 colorFormat
= is_color_format(format
);
1590 indexFormat
= is_index_format(format
);
1591 if ((is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1592 (is_index_format(internalFormat
) && !indexFormat
) ||
1593 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1594 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1595 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
))) {
1597 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1598 "glTexImage(internalFormat/format)");
1602 /* additional checks for ycbcr textures */
1603 if (internalFormat
== GL_YCBCR_MESA
) {
1604 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1605 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1606 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1608 _mesa_sprintf(message
,
1609 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1610 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1611 return GL_TRUE
; /* error */
1613 if (target
!= GL_TEXTURE_2D
&&
1614 target
!= GL_PROXY_TEXTURE_2D
&&
1615 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1616 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1618 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1624 _mesa_sprintf(message
,
1625 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1626 dimensions
, border
);
1627 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1633 /* additional checks for depth textures */
1634 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1635 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1636 if (target
!= GL_TEXTURE_1D
&&
1637 target
!= GL_PROXY_TEXTURE_1D
&&
1638 target
!= GL_TEXTURE_2D
&&
1639 target
!= GL_PROXY_TEXTURE_2D
&&
1640 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1641 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1643 _mesa_error(ctx
, GL_INVALID_ENUM
,
1644 "glTexImage(target/internalFormat)");
1649 /* additional checks for compressed textures */
1650 if (is_compressed_format(ctx
, internalFormat
)) {
1651 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1652 _mesa_error(ctx
, GL_INVALID_ENUM
,
1653 "glTexImage%d(target)", dimensions
);
1658 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1659 "glTexImage%D(border!=0)", dimensions
);
1665 /* if we get here, the parameters are OK */
1671 * Test glTexSubImage[123]D() parameters for errors.
1673 * \param ctx GL context.
1674 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1675 * \param target texture target given by the user.
1676 * \param level image level given by the user.
1677 * \param xoffset sub-image x offset given by the user.
1678 * \param yoffset sub-image y offset given by the user.
1679 * \param zoffset sub-image z offset given by the user.
1680 * \param format pixel data format given by the user.
1681 * \param type pixel data type given by the user.
1682 * \param width image width given by the user.
1683 * \param height image height given by the user.
1684 * \param depth image depth given by the user.
1686 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1688 * Verifies each of the parameters against the constants specified in
1689 * __GLcontextRec::Const and the supported extensions, and according to the
1690 * OpenGL specification.
1693 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1694 GLenum target
, GLint level
,
1695 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1696 GLint width
, GLint height
, GLint depth
,
1697 GLenum format
, GLenum type
)
1700 if (dimensions
== 1) {
1701 if (target
!= GL_TEXTURE_1D
) {
1702 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1706 else if (dimensions
== 2) {
1707 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1708 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1709 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1710 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1714 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1715 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1716 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1720 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1721 if (!ctx
->Extensions
.MESA_texture_array
) {
1722 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1726 else if (target
!= GL_TEXTURE_2D
) {
1727 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1731 else if (dimensions
== 3) {
1732 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1733 if (!ctx
->Extensions
.MESA_texture_array
) {
1734 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1738 else if (target
!= GL_TEXTURE_3D
) {
1739 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1744 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1748 /* Basic level check */
1749 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1750 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1755 _mesa_error(ctx
, GL_INVALID_VALUE
,
1756 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1759 if (height
< 0 && dimensions
> 1) {
1760 _mesa_error(ctx
, GL_INVALID_VALUE
,
1761 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1764 if (depth
< 0 && dimensions
> 2) {
1765 _mesa_error(ctx
, GL_INVALID_VALUE
,
1766 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1770 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1771 _mesa_error(ctx
, GL_INVALID_ENUM
,
1772 "glTexSubImage%dD(format or type)", dimensions
);
1780 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1781 GLenum target
, GLint level
,
1782 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1783 GLint width
, GLint height
, GLint depth
,
1784 GLenum format
, GLenum type
,
1785 const struct gl_texture_image
*destTex
)
1788 /* undefined image level */
1789 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1793 if (xoffset
< -((GLint
)destTex
->Border
)) {
1794 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1798 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1799 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1803 if (dimensions
> 1) {
1804 if (yoffset
< -((GLint
)destTex
->Border
)) {
1805 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1809 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1810 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1815 if (dimensions
> 2) {
1816 if (zoffset
< -((GLint
)destTex
->Border
)) {
1817 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1820 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1821 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1826 #if FEATURE_EXT_texture_sRGB
1827 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1828 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1829 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1830 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1831 if ((width
& 0x3) || (height
& 0x3) ||
1832 (xoffset
& 0x3) || (yoffset
& 0x3))
1833 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1834 "glTexSubImage%dD(size or offset not multiple of 4)",
1840 if (destTex
->IsCompressed
) {
1841 if (!target_can_be_compressed(ctx
, target
)) {
1842 _mesa_error(ctx
, GL_INVALID_ENUM
,
1843 "glTexSubImage%D(target)", dimensions
);
1846 /* offset must be multiple of 4 */
1847 if ((xoffset
& 3) || (yoffset
& 3)) {
1848 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1849 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1852 /* size must be multiple of 4 or equal to whole texture size */
1853 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1854 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1855 "glTexSubImage%D(width)", dimensions
);
1858 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1859 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1860 "glTexSubImage%D(width)", dimensions
);
1870 * Test glCopyTexImage[12]D() parameters for errors.
1872 * \param ctx GL context.
1873 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1874 * \param target texture target given by the user.
1875 * \param level image level given by the user.
1876 * \param internalFormat internal format given by the user.
1877 * \param width image width given by the user.
1878 * \param height image height given by the user.
1879 * \param depth image depth given by the user.
1880 * \param border texture border.
1882 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1884 * Verifies each of the parameters against the constants specified in
1885 * __GLcontextRec::Const and the supported extensions, and according to the
1886 * OpenGL specification.
1889 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1890 GLenum target
, GLint level
, GLint internalFormat
,
1891 GLint width
, GLint height
, GLint border
)
1897 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1898 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1899 _mesa_error(ctx
, GL_INVALID_VALUE
,
1900 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1904 /* Check that the source buffer is complete */
1905 if (ctx
->ReadBuffer
->Name
) {
1906 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1907 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1908 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1909 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1915 if (border
< 0 || border
> 1 ||
1916 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1917 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1921 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1923 _mesa_error(ctx
, GL_INVALID_VALUE
,
1924 "glCopyTexImage%dD(internalFormat)", dimensions
);
1928 /* NOTE: the format and type aren't really significant for
1929 * TestProxyTexImage(). Only the internalformat really matters.
1930 if (!_mesa_source_buffer_exists(ctx, format)) {
1931 _mesa_error(ctx, GL_INVALID_OPERATION,
1932 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1939 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1940 * level, width, height and depth.
1942 if (dimensions
== 1) {
1943 if (target
== GL_TEXTURE_1D
) {
1944 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1945 level
, internalFormat
,
1947 width
, 1, 1, border
);
1950 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1954 else if (dimensions
== 2) {
1955 if (target
== GL_TEXTURE_2D
) {
1956 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1957 level
, internalFormat
,
1959 width
, height
, 1, border
);
1961 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1962 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1963 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1964 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1967 sizeOK
= (width
== height
) &&
1968 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1969 level
, internalFormat
, format
, type
,
1970 width
, height
, 1, border
);
1972 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1973 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1974 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1977 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1978 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1979 level
, internalFormat
,
1981 width
, height
, 1, border
);
1983 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1984 if (!ctx
->Extensions
.MESA_texture_array
) {
1985 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1988 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1989 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1990 level
, internalFormat
,
1992 width
, height
, 1, border
);
1995 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
2000 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
2005 if (dimensions
== 1) {
2006 _mesa_error(ctx
, GL_INVALID_VALUE
,
2007 "glCopyTexImage1D(width=%d)", width
);
2010 ASSERT(dimensions
== 2);
2011 _mesa_error(ctx
, GL_INVALID_VALUE
,
2012 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2017 if (is_compressed_format(ctx
, internalFormat
)) {
2018 if (target
!= GL_TEXTURE_2D
) {
2019 _mesa_error(ctx
, GL_INVALID_ENUM
,
2020 "glCopyTexImage%d(target)", dimensions
);
2024 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2025 "glCopyTexImage%D(border!=0)", dimensions
);
2029 else if (is_depth_format(internalFormat
)) {
2030 /* make sure we have depth/stencil buffers */
2031 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2032 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2033 "glCopyTexImage%D(no depth)", dimensions
);
2037 else if (is_depthstencil_format(internalFormat
)) {
2038 /* make sure we have depth/stencil buffers */
2039 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2040 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2041 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2046 /* if we get here, the parameters are OK */
2052 * Test glCopyTexSubImage[12]D() parameters for errors.
2054 * \param ctx GL context.
2055 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2056 * \param target texture target given by the user.
2057 * \param level image level given by the user.
2058 * \param xoffset sub-image x offset given by the user.
2059 * \param yoffset sub-image y offset given by the user.
2060 * \param zoffset sub-image z offset given by the user.
2061 * \param width image width given by the user.
2062 * \param height image height given by the user.
2064 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2066 * Verifies each of the parameters against the constants specified in
2067 * __GLcontextRec::Const and the supported extensions, and according to the
2068 * OpenGL specification.
2071 copytexsubimage_error_check( GLcontext
*ctx
, GLuint dimensions
,
2072 GLenum target
, GLint level
,
2073 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2074 GLsizei width
, GLsizei height
)
2077 /* Check that the source buffer is complete */
2078 if (ctx
->ReadBuffer
->Name
) {
2079 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2080 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2081 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2082 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2087 if (dimensions
== 1) {
2088 if (target
!= GL_TEXTURE_1D
) {
2089 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2093 else if (dimensions
== 2) {
2094 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2095 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2096 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2097 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2101 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2102 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2103 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2107 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2108 if (!ctx
->Extensions
.MESA_texture_array
) {
2109 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2113 else if (target
!= GL_TEXTURE_2D
) {
2114 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2118 else if (dimensions
== 3) {
2119 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2120 (!ctx
->Extensions
.MESA_texture_array
))
2121 && (target
!= GL_TEXTURE_3D
)) {
2122 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2128 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2129 _mesa_error(ctx
, GL_INVALID_VALUE
,
2130 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2136 _mesa_error(ctx
, GL_INVALID_VALUE
,
2137 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2140 if (dimensions
> 1 && height
< 0) {
2141 _mesa_error(ctx
, GL_INVALID_VALUE
,
2142 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2150 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2151 GLenum target
, GLint level
,
2152 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2153 GLsizei width
, GLsizei height
,
2154 const struct gl_texture_image
*teximage
)
2157 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2158 "glCopyTexSubImage%dD(undefined texture level: %d)",
2163 if (xoffset
< -((GLint
)teximage
->Border
)) {
2164 _mesa_error(ctx
, GL_INVALID_VALUE
,
2165 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2168 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2169 _mesa_error(ctx
, GL_INVALID_VALUE
,
2170 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2173 if (dimensions
> 1) {
2174 if (yoffset
< -((GLint
)teximage
->Border
)) {
2175 _mesa_error(ctx
, GL_INVALID_VALUE
,
2176 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2179 /* NOTE: we're adding the border here, not subtracting! */
2180 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2181 _mesa_error(ctx
, GL_INVALID_VALUE
,
2182 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2187 if (dimensions
> 2) {
2188 if (zoffset
< -((GLint
)teximage
->Border
)) {
2189 _mesa_error(ctx
, GL_INVALID_VALUE
,
2190 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2193 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2194 _mesa_error(ctx
, GL_INVALID_VALUE
,
2195 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2200 if (teximage
->IsCompressed
) {
2201 if (target
!= GL_TEXTURE_2D
) {
2202 _mesa_error(ctx
, GL_INVALID_ENUM
,
2203 "glCopyTexSubImage%d(target)", dimensions
);
2206 /* offset must be multiple of 4 */
2207 if ((xoffset
& 3) || (yoffset
& 3)) {
2208 _mesa_error(ctx
, GL_INVALID_VALUE
,
2209 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2212 /* size must be multiple of 4 */
2213 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2214 _mesa_error(ctx
, GL_INVALID_VALUE
,
2215 "glCopyTexSubImage%D(width)", dimensions
);
2218 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2219 _mesa_error(ctx
, GL_INVALID_VALUE
,
2220 "glCopyTexSubImage%D(height)", dimensions
);
2225 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2226 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2230 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2231 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2232 "glCopyTexSubImage%dD(missing readbuffer)", dimensions
);
2236 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2237 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2238 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2239 "glCopyTexSubImage%D(no depth buffer)",
2244 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2245 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2246 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2247 "glCopyTexSubImage%D(no depth/stencil buffer)",
2253 /* if we get here, the parameters are OK */
2259 * Get texture image. Called by glGetTexImage.
2261 * \param target texture target.
2262 * \param level image level.
2263 * \param format pixel data format for returned image.
2264 * \param type pixel data type for returned image.
2265 * \param pixels returned pixel data.
2268 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2269 GLenum type
, GLvoid
*pixels
)
2271 const struct gl_texture_unit
*texUnit
;
2272 struct gl_texture_object
*texObj
;
2273 struct gl_texture_image
*texImage
;
2274 GLint maxLevels
= 0;
2275 GET_CURRENT_CONTEXT(ctx
);
2276 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2278 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2279 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2280 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2281 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2285 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2286 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2288 if (level
< 0 || level
>= maxLevels
) {
2289 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2293 if (_mesa_sizeof_packed_type(type
) <= 0) {
2294 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2298 if (_mesa_components_in_format(format
) <= 0 ||
2299 format
== GL_STENCIL_INDEX
) {
2300 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2304 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2305 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2309 if (!ctx
->Extensions
.SGIX_depth_texture
&&
2310 !ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2311 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2315 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2316 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2320 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2321 && is_depthstencil_format(format
)) {
2322 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2326 _mesa_lock_texture(ctx
, texObj
);
2328 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2330 /* invalid mipmap level, not an error */
2335 /* Make sure the requested image format is compatible with the
2336 * texture's format. Note that a color index texture can be converted
2337 * to RGBA so that combo is allowed.
2339 if (is_color_format(format
)
2340 && !is_color_format(texImage
->TexFormat
->BaseFormat
)
2341 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2342 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2345 else if (is_index_format(format
)
2346 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2347 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2350 else if (is_depth_format(format
)
2351 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2352 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2353 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2356 else if (is_ycbcr_format(format
)
2357 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2358 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2361 else if (is_depthstencil_format(format
)
2362 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2363 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2367 if (ctx
->Pack
.BufferObj
->Name
) {
2368 /* packing texture image into a PBO */
2369 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2370 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2371 texImage
->Height
, texImage
->Depth
,
2372 format
, type
, pixels
)) {
2373 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2374 "glGetTexImage(invalid PBO access)");
2379 /* typically, this will call _mesa_get_teximage() */
2380 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2385 _mesa_unlock_texture(ctx
, texObj
);
2391 * Check if the given texture image is bound to any framebuffer objects
2392 * and update/invalidate them.
2393 * XXX We're only checking the currently bound framebuffer object for now.
2394 * In the future, perhaps struct gl_texture_image should have a pointer (or
2395 * list of pointers (yikes)) to the gl_framebuffer(s) which it's bound to.
2398 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2399 GLuint face
, GLuint level
)
2401 if (ctx
->DrawBuffer
->Name
) {
2403 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2404 struct gl_renderbuffer_attachment
*att
=
2405 ctx
->DrawBuffer
->Attachment
+ i
;
2406 if (att
->Type
== GL_TEXTURE
&&
2407 att
->Texture
== texObj
&&
2408 att
->TextureLevel
== level
&&
2409 att
->CubeMapFace
== face
) {
2410 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2411 /* Tell driver about the new renderbuffer texture */
2412 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2421 * Called from the API. Note that width includes the border.
2424 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2425 GLsizei width
, GLint border
, GLenum format
,
2426 GLenum type
, const GLvoid
*pixels
)
2428 GLsizei postConvWidth
= width
;
2429 GET_CURRENT_CONTEXT(ctx
);
2430 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2432 if (is_color_format(internalFormat
)) {
2433 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2436 if (target
== GL_TEXTURE_1D
) {
2437 /* non-proxy target */
2438 struct gl_texture_unit
*texUnit
;
2439 struct gl_texture_object
*texObj
;
2440 struct gl_texture_image
*texImage
;
2441 const GLuint face
= _mesa_tex_target_to_face(target
);
2443 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2444 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2445 return; /* error was recorded */
2448 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2449 _mesa_update_state(ctx
);
2451 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2452 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2453 _mesa_lock_texture(ctx
, texObj
);
2455 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2457 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2461 if (texImage
->Data
) {
2462 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2465 ASSERT(texImage
->Data
== NULL
);
2467 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2468 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2469 postConvWidth
, 1, 1,
2470 border
, internalFormat
);
2472 ASSERT(ctx
->Driver
.TexImage1D
);
2474 /* Give the texture to the driver! <pixels> may be null! */
2475 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2476 width
, border
, format
, type
, pixels
,
2477 &ctx
->Unpack
, texObj
, texImage
);
2479 ASSERT(texImage
->TexFormat
);
2481 update_fbo_texture(ctx
, texObj
, face
, level
);
2484 texObj
->_Complete
= GL_FALSE
;
2485 ctx
->NewState
|= _NEW_TEXTURE
;
2488 _mesa_unlock_texture(ctx
, texObj
);
2490 else if (target
== GL_PROXY_TEXTURE_1D
) {
2491 /* Proxy texture: check for errors and update proxy state */
2492 struct gl_texture_image
*texImage
;
2493 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2494 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2495 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2496 /* when error, clear all proxy texture image parameters */
2498 clear_teximage_fields(texImage
);
2501 /* no error, set the tex image parameters */
2503 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2504 postConvWidth
, 1, 1,
2505 border
, internalFormat
);
2506 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2507 internalFormat
, format
, type
);
2511 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2518 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2519 GLsizei width
, GLsizei height
, GLint border
,
2520 GLenum format
, GLenum type
,
2521 const GLvoid
*pixels
)
2523 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2524 GET_CURRENT_CONTEXT(ctx
);
2525 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2527 if (is_color_format(internalFormat
)) {
2528 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2532 if (target
== GL_TEXTURE_2D
||
2533 (ctx
->Extensions
.ARB_texture_cube_map
&&
2534 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2535 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2536 (ctx
->Extensions
.NV_texture_rectangle
&&
2537 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2538 (ctx
->Extensions
.MESA_texture_array
&&
2539 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2540 /* non-proxy target */
2541 struct gl_texture_unit
*texUnit
;
2542 struct gl_texture_object
*texObj
;
2543 struct gl_texture_image
*texImage
;
2544 const GLuint face
= _mesa_tex_target_to_face(target
);
2546 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2547 format
, type
, 2, postConvWidth
, postConvHeight
,
2549 return; /* error was recorded */
2552 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2553 _mesa_update_state(ctx
);
2555 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2556 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2557 _mesa_lock_texture(ctx
, texObj
);
2559 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2561 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2565 if (texImage
->Data
) {
2566 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2569 ASSERT(texImage
->Data
== NULL
);
2570 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2571 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2572 postConvWidth
, postConvHeight
, 1,
2573 border
, internalFormat
);
2575 ASSERT(ctx
->Driver
.TexImage2D
);
2577 /* Give the texture to the driver! <pixels> may be null! */
2578 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2579 width
, height
, border
, format
, type
, pixels
,
2580 &ctx
->Unpack
, texObj
, texImage
);
2582 ASSERT(texImage
->TexFormat
);
2584 update_fbo_texture(ctx
, texObj
, face
, level
);
2587 texObj
->_Complete
= GL_FALSE
;
2588 ctx
->NewState
|= _NEW_TEXTURE
;
2591 _mesa_unlock_texture(ctx
, texObj
);
2593 else if (target
== GL_PROXY_TEXTURE_2D
||
2594 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2595 ctx
->Extensions
.ARB_texture_cube_map
) ||
2596 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2597 ctx
->Extensions
.NV_texture_rectangle
) ||
2598 (ctx
->Extensions
.MESA_texture_array
&&
2599 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2600 /* Proxy texture: check for errors and update proxy state */
2601 struct gl_texture_image
*texImage
;
2602 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2603 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2604 format
, type
, 2, postConvWidth
, postConvHeight
,
2606 /* when error, clear all proxy texture image parameters */
2608 clear_teximage_fields(ctx
->Texture
.Proxy2D
->Image
[0][level
]);
2611 /* no error, set the tex image parameters */
2612 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2613 postConvWidth
, postConvHeight
, 1,
2614 border
, internalFormat
);
2615 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2616 internalFormat
, format
, type
);
2620 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2627 * Called by the API or display list executor.
2628 * Note that width and height include the border.
2631 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2632 GLsizei width
, GLsizei height
, GLsizei depth
,
2633 GLint border
, GLenum format
, GLenum type
,
2634 const GLvoid
*pixels
)
2636 GET_CURRENT_CONTEXT(ctx
);
2637 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2639 if (target
== GL_TEXTURE_3D
||
2640 (ctx
->Extensions
.MESA_texture_array
&&
2641 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2642 /* non-proxy target */
2643 struct gl_texture_unit
*texUnit
;
2644 struct gl_texture_object
*texObj
;
2645 struct gl_texture_image
*texImage
;
2646 const GLuint face
= _mesa_tex_target_to_face(target
);
2648 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2649 format
, type
, 3, width
, height
, depth
, border
)) {
2650 return; /* error was recorded */
2653 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2654 _mesa_update_state(ctx
);
2656 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2657 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2658 _mesa_lock_texture(ctx
, texObj
);
2660 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2662 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2666 if (texImage
->Data
) {
2667 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2670 ASSERT(texImage
->Data
== NULL
);
2671 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2672 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2673 width
, height
, depth
,
2674 border
, internalFormat
);
2676 ASSERT(ctx
->Driver
.TexImage3D
);
2678 /* Give the texture to the driver! <pixels> may be null! */
2679 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2680 width
, height
, depth
, border
, format
, type
,
2681 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2683 ASSERT(texImage
->TexFormat
);
2685 update_fbo_texture(ctx
, texObj
, face
, level
);
2688 texObj
->_Complete
= GL_FALSE
;
2689 ctx
->NewState
|= _NEW_TEXTURE
;
2692 _mesa_unlock_texture(ctx
, texObj
);
2694 else if (target
== GL_PROXY_TEXTURE_3D
||
2695 (ctx
->Extensions
.MESA_texture_array
&&
2696 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2697 /* Proxy texture: check for errors and update proxy state */
2698 struct gl_texture_image
*texImage
;
2699 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2700 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2701 format
, type
, 3, width
, height
, depth
, border
)) {
2702 /* when error, clear all proxy texture image parameters */
2704 clear_teximage_fields(texImage
);
2707 /* no error, set the tex image parameters */
2708 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2709 border
, internalFormat
);
2710 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2711 internalFormat
, format
, type
);
2715 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2722 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2723 GLsizei width
, GLsizei height
, GLsizei depth
,
2724 GLint border
, GLenum format
, GLenum type
,
2725 const GLvoid
*pixels
)
2727 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2728 depth
, border
, format
, type
, pixels
);
2734 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2735 GLint xoffset
, GLsizei width
,
2736 GLenum format
, GLenum type
,
2737 const GLvoid
*pixels
)
2739 GLsizei postConvWidth
= width
;
2740 struct gl_texture_unit
*texUnit
;
2741 struct gl_texture_object
*texObj
;
2742 struct gl_texture_image
*texImage
= NULL
;
2743 GET_CURRENT_CONTEXT(ctx
);
2744 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2746 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2747 _mesa_update_state(ctx
);
2749 /* XXX should test internal format */
2750 if (is_color_format(format
)) {
2751 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2754 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2755 postConvWidth
, 1, 1, format
, type
)) {
2756 return; /* error was detected */
2760 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2761 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2764 _mesa_lock_texture(ctx
, texObj
);
2766 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2768 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2769 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2770 goto out
; /* error was detected */
2774 goto out
; /* no-op, not an error */
2776 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2777 xoffset
+= texImage
->Border
;
2779 ASSERT(ctx
->Driver
.TexSubImage1D
);
2780 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2781 format
, type
, pixels
, &ctx
->Unpack
,
2783 ctx
->NewState
|= _NEW_TEXTURE
;
2786 _mesa_unlock_texture(ctx
, texObj
);
2791 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2792 GLint xoffset
, GLint yoffset
,
2793 GLsizei width
, GLsizei height
,
2794 GLenum format
, GLenum type
,
2795 const GLvoid
*pixels
)
2797 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2798 struct gl_texture_unit
*texUnit
;
2799 struct gl_texture_object
*texObj
;
2800 struct gl_texture_image
*texImage
;
2801 GET_CURRENT_CONTEXT(ctx
);
2802 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2804 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2805 _mesa_update_state(ctx
);
2807 /* XXX should test internal format */
2808 if (is_color_format(format
)) {
2809 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2813 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2814 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2815 return; /* error was detected */
2818 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2819 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2820 _mesa_lock_texture(ctx
, texObj
);
2822 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2824 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2825 postConvWidth
, postConvHeight
, 1, format
, type
,
2827 goto out
; /* error was detected */
2830 if (width
== 0 || height
== 0)
2831 goto out
; /* no-op, not an error */
2833 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2834 xoffset
+= texImage
->Border
;
2835 yoffset
+= texImage
->Border
;
2837 ASSERT(ctx
->Driver
.TexSubImage2D
);
2838 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2839 width
, height
, format
, type
, pixels
,
2840 &ctx
->Unpack
, texObj
, texImage
);
2841 ctx
->NewState
|= _NEW_TEXTURE
;
2844 _mesa_unlock_texture(ctx
, texObj
);
2850 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2851 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2852 GLsizei width
, GLsizei height
, GLsizei depth
,
2853 GLenum format
, GLenum type
,
2854 const GLvoid
*pixels
)
2856 struct gl_texture_unit
*texUnit
;
2857 struct gl_texture_object
*texObj
;
2858 struct gl_texture_image
*texImage
;
2859 GET_CURRENT_CONTEXT(ctx
);
2860 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2862 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2863 _mesa_update_state(ctx
);
2865 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2866 width
, height
, depth
, format
, type
)) {
2867 return; /* error was detected */
2870 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2871 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2873 _mesa_lock_texture(ctx
, texObj
);
2875 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2877 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2878 width
, height
, depth
, format
, type
, texImage
)) {
2879 goto out
; /* error was detected */
2882 if (width
== 0 || height
== 0 || height
== 0)
2883 goto out
; /* no-op, not an error */
2885 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2886 xoffset
+= texImage
->Border
;
2887 yoffset
+= texImage
->Border
;
2888 zoffset
+= texImage
->Border
;
2890 ASSERT(ctx
->Driver
.TexSubImage3D
);
2891 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2892 xoffset
, yoffset
, zoffset
,
2893 width
, height
, depth
,
2894 format
, type
, pixels
,
2895 &ctx
->Unpack
, texObj
, texImage
);
2896 ctx
->NewState
|= _NEW_TEXTURE
;
2899 _mesa_unlock_texture(ctx
, texObj
);
2905 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2906 GLenum internalFormat
,
2908 GLsizei width
, GLint border
)
2910 struct gl_texture_unit
*texUnit
;
2911 struct gl_texture_object
*texObj
;
2912 struct gl_texture_image
*texImage
;
2913 GLsizei postConvWidth
= width
;
2914 const GLuint face
= _mesa_tex_target_to_face(target
);
2915 GET_CURRENT_CONTEXT(ctx
);
2916 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2918 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2919 _mesa_update_state(ctx
);
2921 if (is_color_format(internalFormat
)) {
2922 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2925 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2926 postConvWidth
, 1, border
))
2929 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2930 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2931 _mesa_lock_texture(ctx
, texObj
);
2933 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2935 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2939 if (texImage
->Data
) {
2940 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2943 ASSERT(texImage
->Data
== NULL
);
2945 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2946 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2947 border
, internalFormat
);
2950 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2951 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2952 x
, y
, width
, border
);
2954 ASSERT(texImage
->TexFormat
);
2956 update_fbo_texture(ctx
, texObj
, face
, level
);
2959 texObj
->_Complete
= GL_FALSE
;
2960 ctx
->NewState
|= _NEW_TEXTURE
;
2963 _mesa_unlock_texture(ctx
, texObj
);
2969 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2970 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2973 struct gl_texture_unit
*texUnit
;
2974 struct gl_texture_object
*texObj
;
2975 struct gl_texture_image
*texImage
;
2976 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2977 const GLuint face
= _mesa_tex_target_to_face(target
);
2978 GET_CURRENT_CONTEXT(ctx
);
2979 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2981 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2982 _mesa_update_state(ctx
);
2984 if (is_color_format(internalFormat
)) {
2985 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2989 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2990 postConvWidth
, postConvHeight
, border
))
2993 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2994 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2996 _mesa_lock_texture(ctx
, texObj
);
2998 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3001 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3005 if (texImage
->Data
) {
3006 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3009 ASSERT(texImage
->Data
== NULL
);
3011 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3012 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3013 postConvWidth
, postConvHeight
, 1,
3014 border
, internalFormat
);
3016 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3017 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3018 x
, y
, width
, height
, border
);
3020 ASSERT(texImage
->TexFormat
);
3022 update_fbo_texture(ctx
, texObj
, face
, level
);
3025 texObj
->_Complete
= GL_FALSE
;
3026 ctx
->NewState
|= _NEW_TEXTURE
;
3029 _mesa_unlock_texture(ctx
, texObj
);
3034 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3035 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3037 struct gl_texture_unit
*texUnit
;
3038 struct gl_texture_object
*texObj
;
3039 struct gl_texture_image
*texImage
;
3040 GLsizei postConvWidth
= width
;
3044 GET_CURRENT_CONTEXT(ctx
);
3045 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3047 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3048 _mesa_update_state(ctx
);
3050 /* XXX should test internal format */
3051 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3053 if (copytexsubimage_error_check(ctx
, 1, target
, level
,
3054 xoffset
, 0, 0, postConvWidth
, 1))
3057 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3058 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3060 _mesa_lock_texture(ctx
, texObj
);
3062 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3064 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3065 xoffset
, 0, 0, postConvWidth
, 1,
3070 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3071 xoffset
+= texImage
->Border
;
3073 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3075 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3076 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3077 xoffset
, x
, y
, width
);
3080 ctx
->NewState
|= _NEW_TEXTURE
;
3083 _mesa_unlock_texture(ctx
, texObj
);
3089 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3090 GLint xoffset
, GLint yoffset
,
3091 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3093 struct gl_texture_unit
*texUnit
;
3094 struct gl_texture_object
*texObj
;
3095 struct gl_texture_image
*texImage
;
3096 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3097 GET_CURRENT_CONTEXT(ctx
);
3098 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3100 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3101 _mesa_update_state(ctx
);
3103 /* XXX should test internal format */
3104 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
3106 if (copytexsubimage_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3107 postConvWidth
, postConvHeight
))
3110 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3111 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3113 _mesa_lock_texture(ctx
, texObj
);
3115 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3117 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3118 postConvWidth
, postConvHeight
, texImage
))
3121 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3122 xoffset
+= texImage
->Border
;
3123 yoffset
+= texImage
->Border
;
3125 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3127 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3128 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3129 xoffset
, yoffset
, x
, y
, width
, height
);
3132 ctx
->NewState
|= _NEW_TEXTURE
;
3135 _mesa_unlock_texture(ctx
, texObj
);
3141 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3142 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3143 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3145 struct gl_texture_unit
*texUnit
;
3146 struct gl_texture_object
*texObj
;
3147 struct gl_texture_image
*texImage
;
3148 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3149 GET_CURRENT_CONTEXT(ctx
);
3150 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3152 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3153 _mesa_update_state(ctx
);
3155 /* XXX should test internal format */
3156 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
3158 if (copytexsubimage_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
,
3159 zoffset
, postConvWidth
, postConvHeight
))
3162 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3163 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3165 _mesa_lock_texture(ctx
, texObj
);
3167 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3169 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3170 zoffset
, postConvWidth
, postConvHeight
,
3174 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3175 xoffset
+= texImage
->Border
;
3176 yoffset
+= texImage
->Border
;
3177 zoffset
+= texImage
->Border
;
3179 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3181 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3182 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3183 xoffset
, yoffset
, zoffset
,
3184 x
, y
, width
, height
);
3187 ctx
->NewState
|= _NEW_TEXTURE
;
3190 _mesa_unlock_texture(ctx
, texObj
);
3196 /**********************************************************************/
3197 /****** Compressed Textures ******/
3198 /**********************************************************************/
3202 * Error checking for glCompressedTexImage[123]D().
3203 * \return error code or GL_NO_ERROR.
3206 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3207 GLenum target
, GLint level
,
3208 GLenum internalFormat
, GLsizei width
,
3209 GLsizei height
, GLsizei depth
, GLint border
,
3212 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3214 if (dimensions
== 1) {
3215 /* 1D compressed textures not allowed */
3216 return GL_INVALID_ENUM
;
3218 else if (dimensions
== 2) {
3219 if (target
== GL_PROXY_TEXTURE_2D
) {
3220 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3222 else if (target
== GL_TEXTURE_2D
) {
3223 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3225 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3226 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3227 return GL_INVALID_ENUM
; /*target*/
3228 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3230 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3231 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3232 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3233 return GL_INVALID_ENUM
; /*target*/
3234 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3237 return GL_INVALID_ENUM
; /*target*/
3240 else if (dimensions
== 3) {
3241 /* 3D compressed textures not allowed */
3242 return GL_INVALID_ENUM
;
3245 maxTextureSize
= 1 << (maxLevels
- 1);
3247 /* This will detect any invalid internalFormat value */
3248 if (!is_compressed_format(ctx
, internalFormat
))
3249 return GL_INVALID_ENUM
;
3251 /* This should really never fail */
3252 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3253 return GL_INVALID_ENUM
;
3256 return GL_INVALID_VALUE
;
3259 * XXX We should probably use the proxy texture error check function here.
3261 if (width
< 1 || width
> maxTextureSize
||
3262 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(width
) != 1))
3263 return GL_INVALID_VALUE
;
3265 if ((height
< 1 || height
> maxTextureSize
||
3266 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(height
) != 1))
3268 return GL_INVALID_VALUE
;
3270 if ((depth
< 1 || depth
> maxTextureSize
||
3271 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(depth
) != 1))
3273 return GL_INVALID_VALUE
;
3275 /* For cube map, width must equal height */
3276 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3277 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3278 return GL_INVALID_VALUE
;
3280 if (level
< 0 || level
>= maxLevels
)
3281 return GL_INVALID_VALUE
;
3283 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3284 depth
, internalFormat
);
3285 if (expectedSize
!= imageSize
)
3286 return GL_INVALID_VALUE
;
3288 #if FEATURE_EXT_texture_sRGB
3289 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3290 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3291 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3292 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3294 return GL_INVALID_OPERATION
;
3303 * Error checking for glCompressedTexSubImage[123]D().
3304 * \warning There are some bad assumptions here about the size of compressed
3305 * texture tiles (multiple of 4) used to test the validity of the
3306 * offset and size parameters.
3307 * \return error code or GL_NO_ERROR.
3310 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3311 GLenum target
, GLint level
,
3312 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3313 GLsizei width
, GLsizei height
, GLsizei depth
,
3314 GLenum format
, GLsizei imageSize
)
3316 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3319 if (dimensions
== 1) {
3320 /* 1D compressed textures not allowed */
3321 return GL_INVALID_ENUM
;
3323 else if (dimensions
== 2) {
3324 if (target
== GL_PROXY_TEXTURE_2D
) {
3325 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3327 else if (target
== GL_TEXTURE_2D
) {
3328 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3330 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3331 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3332 return GL_INVALID_ENUM
; /*target*/
3333 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3335 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3336 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3337 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3338 return GL_INVALID_ENUM
; /*target*/
3339 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3342 return GL_INVALID_ENUM
; /*target*/
3345 else if (dimensions
== 3) {
3346 /* 3D compressed textures not allowed */
3347 return GL_INVALID_ENUM
;
3350 maxTextureSize
= 1 << (maxLevels
- 1);
3352 /* this will catch any invalid compressed format token */
3353 if (!is_compressed_format(ctx
, format
))
3354 return GL_INVALID_ENUM
;
3356 if (width
< 1 || width
> maxTextureSize
)
3357 return GL_INVALID_VALUE
;
3359 if ((height
< 1 || height
> maxTextureSize
)
3361 return GL_INVALID_VALUE
;
3363 if (level
< 0 || level
>= maxLevels
)
3364 return GL_INVALID_VALUE
;
3366 /* XXX these tests are specific to the compressed format.
3367 * this code should be generalized in some way.
3369 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3370 return GL_INVALID_VALUE
;
3372 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3373 return GL_INVALID_VALUE
;
3375 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3376 return GL_INVALID_VALUE
;
3378 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3380 if (expectedSize
!= imageSize
)
3381 return GL_INVALID_VALUE
;
3389 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3390 GLenum internalFormat
, GLsizei width
,
3391 GLint border
, GLsizei imageSize
,
3394 GET_CURRENT_CONTEXT(ctx
);
3395 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3397 if (target
== GL_TEXTURE_1D
) {
3398 /* non-proxy target */
3399 struct gl_texture_unit
*texUnit
;
3400 struct gl_texture_object
*texObj
;
3401 struct gl_texture_image
*texImage
;
3402 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3403 internalFormat
, width
, 1, 1, border
, imageSize
);
3405 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3409 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3410 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3412 _mesa_lock_texture(ctx
, texObj
);
3414 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3416 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3420 if (texImage
->Data
) {
3421 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3423 ASSERT(texImage
->Data
== NULL
);
3425 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3426 border
, internalFormat
);
3428 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3429 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3430 internalFormat
, width
, border
,
3435 texObj
->_Complete
= GL_FALSE
;
3436 ctx
->NewState
|= _NEW_TEXTURE
;
3439 _mesa_unlock_texture(ctx
, texObj
);
3441 else if (target
== GL_PROXY_TEXTURE_1D
) {
3442 /* Proxy texture: check for errors and update proxy state */
3443 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3444 internalFormat
, width
, 1, 1, border
, imageSize
);
3446 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3447 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3448 internalFormat
, GL_NONE
, GL_NONE
,
3449 width
, 1, 1, border
);
3452 /* if error, clear all proxy texture image parameters */
3453 struct gl_texture_image
*texImage
;
3454 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3456 clear_teximage_fields(texImage
);
3459 /* store the teximage parameters */
3460 struct gl_texture_unit
*texUnit
;
3461 struct gl_texture_object
*texObj
;
3462 struct gl_texture_image
*texImage
;
3463 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3464 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3466 _mesa_lock_texture(ctx
, texObj
);
3468 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3469 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3470 border
, internalFormat
);
3472 _mesa_unlock_texture(ctx
, texObj
);
3476 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3483 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3484 GLenum internalFormat
, GLsizei width
,
3485 GLsizei height
, GLint border
, GLsizei imageSize
,
3488 GET_CURRENT_CONTEXT(ctx
);
3489 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3491 if (target
== GL_TEXTURE_2D
||
3492 (ctx
->Extensions
.ARB_texture_cube_map
&&
3493 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3494 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3495 /* non-proxy target */
3496 struct gl_texture_unit
*texUnit
;
3497 struct gl_texture_object
*texObj
;
3498 struct gl_texture_image
*texImage
;
3499 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3500 internalFormat
, width
, height
, 1, border
, imageSize
);
3502 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3506 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3507 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3509 _mesa_lock_texture(ctx
, texObj
);
3511 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3513 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3517 if (texImage
->Data
) {
3518 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3520 ASSERT(texImage
->Data
== NULL
);
3522 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3523 border
, internalFormat
);
3525 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3526 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3527 internalFormat
, width
, height
,
3528 border
, imageSize
, data
,
3532 texObj
->_Complete
= GL_FALSE
;
3533 ctx
->NewState
|= _NEW_TEXTURE
;
3536 _mesa_unlock_texture(ctx
, texObj
);
3538 else if (target
== GL_PROXY_TEXTURE_2D
||
3539 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3540 ctx
->Extensions
.ARB_texture_cube_map
)) {
3541 /* Proxy texture: check for errors and update proxy state */
3542 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3543 internalFormat
, width
, height
, 1, border
, imageSize
);
3545 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3546 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3547 internalFormat
, GL_NONE
, GL_NONE
,
3548 width
, height
, 1, border
);
3551 /* if error, clear all proxy texture image parameters */
3552 struct gl_texture_image
*texImage
;
3553 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3555 clear_teximage_fields(texImage
);
3558 /* store the teximage parameters */
3559 struct gl_texture_unit
*texUnit
;
3560 struct gl_texture_object
*texObj
;
3561 struct gl_texture_image
*texImage
;
3562 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3563 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3565 _mesa_lock_texture(ctx
, texObj
);
3567 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3568 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3569 border
, internalFormat
);
3571 _mesa_unlock_texture(ctx
, texObj
);
3575 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3582 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3583 GLenum internalFormat
, GLsizei width
,
3584 GLsizei height
, GLsizei depth
, GLint border
,
3585 GLsizei imageSize
, const GLvoid
*data
)
3587 GET_CURRENT_CONTEXT(ctx
);
3588 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3590 if (target
== GL_TEXTURE_3D
) {
3591 /* non-proxy target */
3592 struct gl_texture_unit
*texUnit
;
3593 struct gl_texture_object
*texObj
;
3594 struct gl_texture_image
*texImage
;
3595 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3596 internalFormat
, width
, height
, depth
, border
, imageSize
);
3598 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3602 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3603 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3604 _mesa_lock_texture(ctx
, texObj
);
3606 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3608 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3612 if (texImage
->Data
) {
3613 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3615 ASSERT(texImage
->Data
== NULL
);
3617 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3618 border
, internalFormat
);
3620 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3621 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3623 width
, height
, depth
,
3624 border
, imageSize
, data
,
3628 texObj
->_Complete
= GL_FALSE
;
3629 ctx
->NewState
|= _NEW_TEXTURE
;
3632 _mesa_unlock_texture(ctx
, texObj
);
3634 else if (target
== GL_PROXY_TEXTURE_3D
) {
3635 /* Proxy texture: check for errors and update proxy state */
3636 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3637 internalFormat
, width
, height
, depth
, border
, imageSize
);
3639 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3640 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3641 internalFormat
, GL_NONE
, GL_NONE
,
3642 width
, height
, depth
, border
);
3645 /* if error, clear all proxy texture image parameters */
3646 struct gl_texture_image
*texImage
;
3647 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3649 clear_teximage_fields(texImage
);
3652 /* store the teximage parameters */
3653 struct gl_texture_unit
*texUnit
;
3654 struct gl_texture_object
*texObj
;
3655 struct gl_texture_image
*texImage
;
3656 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3657 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3658 _mesa_lock_texture(ctx
, texObj
);
3660 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3661 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3662 depth
, border
, internalFormat
);
3664 _mesa_unlock_texture(ctx
, texObj
);
3668 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3675 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3676 GLsizei width
, GLenum format
,
3677 GLsizei imageSize
, const GLvoid
*data
)
3679 struct gl_texture_unit
*texUnit
;
3680 struct gl_texture_object
*texObj
;
3681 struct gl_texture_image
*texImage
;
3683 GET_CURRENT_CONTEXT(ctx
);
3684 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3686 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3687 xoffset
, 0, 0, /* pos */
3688 width
, 1, 1, /* size */
3691 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3695 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3696 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3697 _mesa_lock_texture(ctx
, texObj
);
3699 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3702 if ((GLint
) format
!= texImage
->InternalFormat
) {
3703 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3704 "glCompressedTexSubImage1D(format)");
3708 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3709 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3714 goto out
; /* no-op, not an error */
3716 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3717 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3719 format
, imageSize
, data
,
3722 ctx
->NewState
|= _NEW_TEXTURE
;
3725 _mesa_unlock_texture(ctx
, texObj
);
3730 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3731 GLint yoffset
, GLsizei width
, GLsizei height
,
3732 GLenum format
, GLsizei imageSize
,
3735 struct gl_texture_unit
*texUnit
;
3736 struct gl_texture_object
*texObj
;
3737 struct gl_texture_image
*texImage
;
3739 GET_CURRENT_CONTEXT(ctx
);
3740 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3742 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3743 xoffset
, yoffset
, 0, /* pos */
3744 width
, height
, 1, /* size */
3747 /* XXX proxy target? */
3748 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3752 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3753 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3754 _mesa_lock_texture(ctx
, texObj
);
3756 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3759 if ((GLint
) format
!= texImage
->InternalFormat
) {
3760 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3761 "glCompressedTexSubImage2D(format)");
3765 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3766 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3767 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3771 if (width
== 0 || height
== 0)
3772 goto out
; /* no-op, not an error */
3774 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3775 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3776 xoffset
, yoffset
, width
, height
,
3777 format
, imageSize
, data
,
3780 ctx
->NewState
|= _NEW_TEXTURE
;
3783 _mesa_unlock_texture(ctx
, texObj
);
3788 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3789 GLint yoffset
, GLint zoffset
, GLsizei width
,
3790 GLsizei height
, GLsizei depth
, GLenum format
,
3791 GLsizei imageSize
, const GLvoid
*data
)
3793 struct gl_texture_unit
*texUnit
;
3794 struct gl_texture_object
*texObj
;
3795 struct gl_texture_image
*texImage
;
3797 GET_CURRENT_CONTEXT(ctx
);
3798 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3800 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3801 xoffset
, yoffset
, zoffset
,/*pos*/
3802 width
, height
, depth
, /*size*/
3805 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3809 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3810 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3811 _mesa_lock_texture(ctx
, texObj
);
3813 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3816 if ((GLint
) format
!= texImage
->InternalFormat
) {
3817 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3818 "glCompressedTexSubImage3D(format)");
3822 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3823 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3824 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3825 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3829 if (width
== 0 || height
== 0 || depth
== 0)
3830 goto out
; /* no-op, not an error */
3832 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3833 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3834 xoffset
, yoffset
, zoffset
,
3835 width
, height
, depth
,
3836 format
, imageSize
, data
,
3839 ctx
->NewState
|= _NEW_TEXTURE
;
3842 _mesa_unlock_texture(ctx
, texObj
);
3847 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3849 const struct gl_texture_unit
*texUnit
;
3850 struct gl_texture_object
*texObj
;
3851 struct gl_texture_image
*texImage
;
3853 GET_CURRENT_CONTEXT(ctx
);
3854 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3856 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3857 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3859 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3863 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3864 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3866 if (level
< 0 || level
>= maxLevels
) {
3867 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3871 if (_mesa_is_proxy_texture(target
)) {
3872 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3876 _mesa_lock_texture(ctx
, texObj
);
3878 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3880 if (texImage
->IsCompressed
) {
3881 /* this typically calls _mesa_get_compressed_teximage() */
3882 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3886 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3887 "glGetCompressedTexImageARB");
3891 /* probably invalid mipmap level */
3892 _mesa_error(ctx
, GL_INVALID_VALUE
,
3893 "glGetCompressedTexImageARB(level)");
3896 _mesa_unlock_texture(ctx
, texObj
);