2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 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"
39 #include "framebuffer.h"
44 #include "texcompress.h"
45 #include "texformat.h"
53 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
57 _mesa_alloc_texmemory(GLsizei bytes
)
59 return _mesa_align_malloc(bytes
, 512);
64 * Free texture memory allocated with _mesa_alloc_texmemory()
67 _mesa_free_texmemory(void *m
)
76 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
78 #if CHAN_TYPE != GL_UNSIGNED_BYTE
79 _mesa_problem(NULL
, "PrintTexture not supported");
82 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
85 _mesa_printf("No texture data\n");
89 switch (img
->Format
) {
96 case GL_LUMINANCE_ALPHA
:
106 _mesa_problem(NULL
, "error in PrintTexture\n");
110 for (i
= 0; i
< img
->Height
; i
++) {
111 for (j
= 0; j
< img
->Width
; j
++) {
113 _mesa_printf("%02x ", data
[0]);
115 _mesa_printf("%02x%02x ", data
[0], data
[1]);
117 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
119 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
120 data
+= (img
->RowStride
- img
->Width
) * c
;
122 /* XXX use img->ImageStride here */
131 * Compute floor(log_base_2(n)).
132 * If n < 0 return -1.
161 * Return the simple base format for a given internal texture format.
162 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
164 * \param ctx GL context.
165 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
167 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
168 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
170 * This is the format which is used during texture application (i.e. the
171 * texture format and env mode determine the arithmetic used.
174 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
176 switch (internalFormat
) {
191 case GL_LUMINANCE_ALPHA
:
192 case GL_LUMINANCE4_ALPHA4
:
193 case GL_LUMINANCE6_ALPHA2
:
194 case GL_LUMINANCE8_ALPHA8
:
195 case GL_LUMINANCE12_ALPHA4
:
196 case GL_LUMINANCE12_ALPHA12
:
197 case GL_LUMINANCE16_ALPHA16
:
198 return GL_LUMINANCE_ALPHA
;
229 if (ctx
->Extensions
.EXT_paletted_texture
) {
230 switch (internalFormat
) {
232 case GL_COLOR_INDEX1_EXT
:
233 case GL_COLOR_INDEX2_EXT
:
234 case GL_COLOR_INDEX4_EXT
:
235 case GL_COLOR_INDEX8_EXT
:
236 case GL_COLOR_INDEX12_EXT
:
237 case GL_COLOR_INDEX16_EXT
:
238 return GL_COLOR_INDEX
;
244 if (ctx
->Extensions
.ARB_depth_texture
) {
245 switch (internalFormat
) {
246 case GL_DEPTH_COMPONENT
:
247 case GL_DEPTH_COMPONENT16
:
248 case GL_DEPTH_COMPONENT24
:
249 case GL_DEPTH_COMPONENT32
:
250 return GL_DEPTH_COMPONENT
;
256 if (ctx
->Extensions
.ARB_texture_compression
) {
257 switch (internalFormat
) {
258 case GL_COMPRESSED_ALPHA
:
260 case GL_COMPRESSED_LUMINANCE
:
262 case GL_COMPRESSED_LUMINANCE_ALPHA
:
263 return GL_LUMINANCE_ALPHA
;
264 case GL_COMPRESSED_INTENSITY
:
266 case GL_COMPRESSED_RGB
:
268 case GL_COMPRESSED_RGBA
:
275 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
276 switch (internalFormat
) {
277 case GL_COMPRESSED_RGB_FXT1_3DFX
:
279 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
286 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
287 switch (internalFormat
) {
288 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
290 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
291 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
292 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
299 if (ctx
->Extensions
.S3_s3tc
) {
300 switch (internalFormat
) {
312 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
313 if (internalFormat
== GL_YCBCR_MESA
)
314 return GL_YCBCR_MESA
;
317 if (ctx
->Extensions
.ARB_texture_float
) {
318 switch (internalFormat
) {
319 case GL_ALPHA16F_ARB
:
320 case GL_ALPHA32F_ARB
:
328 case GL_INTENSITY16F_ARB
:
329 case GL_INTENSITY32F_ARB
:
331 case GL_LUMINANCE16F_ARB
:
332 case GL_LUMINANCE32F_ARB
:
334 case GL_LUMINANCE_ALPHA16F_ARB
:
335 case GL_LUMINANCE_ALPHA32F_ARB
:
336 return GL_LUMINANCE_ALPHA
;
342 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
343 switch (internalFormat
) {
344 case GL_DEPTH_STENCIL_EXT
:
345 case GL_DEPTH24_STENCIL8_EXT
:
346 return GL_DEPTH_STENCIL_EXT
;
352 #if FEATURE_EXT_texture_sRGB
353 if (ctx
->Extensions
.EXT_texture_sRGB
) {
354 switch (internalFormat
) {
357 case GL_COMPRESSED_SRGB_EXT
:
358 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
360 case GL_SRGB_ALPHA_EXT
:
361 case GL_SRGB8_ALPHA8_EXT
:
362 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
363 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
364 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
365 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
367 case GL_SLUMINANCE_ALPHA_EXT
:
368 case GL_SLUMINANCE8_ALPHA8_EXT
:
369 case GL_COMPRESSED_SLUMINANCE_EXT
:
370 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
371 return GL_LUMINANCE_ALPHA
;
372 case GL_SLUMINANCE_EXT
:
373 case GL_SLUMINANCE8_EXT
:
380 #endif /* FEATURE_EXT_texture_sRGB */
382 return -1; /* error */
387 * Test if the given image format is a color/RGBA format (i.e., not color
388 * index, depth, stencil, etc).
389 * \param format the image format value (may by an internal texture format)
390 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
391 * XXX maybe move this func to image.c
394 _mesa_is_color_format(GLenum format
)
412 case GL_LUMINANCE_ALPHA
:
413 case GL_LUMINANCE4_ALPHA4
:
414 case GL_LUMINANCE6_ALPHA2
:
415 case GL_LUMINANCE8_ALPHA8
:
416 case GL_LUMINANCE12_ALPHA4
:
417 case GL_LUMINANCE12_ALPHA12
:
418 case GL_LUMINANCE16_ALPHA16
:
445 /* float texture formats */
446 case GL_ALPHA16F_ARB
:
447 case GL_ALPHA32F_ARB
:
448 case GL_LUMINANCE16F_ARB
:
449 case GL_LUMINANCE32F_ARB
:
450 case GL_LUMINANCE_ALPHA16F_ARB
:
451 case GL_LUMINANCE_ALPHA32F_ARB
:
452 case GL_INTENSITY16F_ARB
:
453 case GL_INTENSITY32F_ARB
:
458 /* compressed formats */
459 case GL_COMPRESSED_ALPHA
:
460 case GL_COMPRESSED_LUMINANCE
:
461 case GL_COMPRESSED_LUMINANCE_ALPHA
:
462 case GL_COMPRESSED_INTENSITY
:
463 case GL_COMPRESSED_RGB
:
464 case GL_COMPRESSED_RGBA
:
469 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
470 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
471 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
472 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
473 case GL_COMPRESSED_RGB_FXT1_3DFX
:
474 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
475 #if FEATURE_EXT_texture_sRGB
478 case GL_SRGB_ALPHA_EXT
:
479 case GL_SRGB8_ALPHA8_EXT
:
480 case GL_SLUMINANCE_ALPHA_EXT
:
481 case GL_SLUMINANCE8_ALPHA8_EXT
:
482 case GL_SLUMINANCE_EXT
:
483 case GL_SLUMINANCE8_EXT
:
484 case GL_COMPRESSED_SRGB_EXT
:
485 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
486 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
487 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
488 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
489 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
490 case GL_COMPRESSED_SLUMINANCE_EXT
:
491 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
492 #endif /* FEATURE_EXT_texture_sRGB */
494 case GL_YCBCR_MESA
: /* not considered to be RGB */
503 * Test if the given image format is a color index format.
506 is_index_format(GLenum format
)
510 case GL_COLOR_INDEX1_EXT
:
511 case GL_COLOR_INDEX2_EXT
:
512 case GL_COLOR_INDEX4_EXT
:
513 case GL_COLOR_INDEX8_EXT
:
514 case GL_COLOR_INDEX12_EXT
:
515 case GL_COLOR_INDEX16_EXT
:
524 * Test if the given image format is a depth component format.
527 is_depth_format(GLenum format
)
530 case GL_DEPTH_COMPONENT16
:
531 case GL_DEPTH_COMPONENT24
:
532 case GL_DEPTH_COMPONENT32
:
533 case GL_DEPTH_COMPONENT
:
542 * Test if the given image format is a YCbCr format.
545 is_ycbcr_format(GLenum format
)
557 * Test if the given image format is a Depth/Stencil format.
560 is_depthstencil_format(GLenum format
)
563 case GL_DEPTH24_STENCIL8_EXT
:
564 case GL_DEPTH_STENCIL_EXT
:
574 * Test if it is a supported compressed format.
576 * \param internalFormat the internal format token provided by the user.
578 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
579 * GL_FALSE otherwise.
581 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
585 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
587 GLint supported
[100]; /* 100 should be plenty */
590 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
592 for (i
= 0; i
< n
; i
++) {
593 if ((GLint
) internalFormat
== supported
[i
]) {
602 * For cube map faces, return a face index in [0,5].
603 * For other targets return 0;
606 _mesa_tex_target_to_face(GLenum target
)
608 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
609 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
610 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
618 * Store a gl_texture_image pointer in a gl_texture_object structure
619 * according to the target and level parameters.
621 * \param tObj texture object.
622 * \param target texture target.
623 * \param level image level.
624 * \param texImage texture image.
626 * This was basically prompted by the introduction of cube maps.
629 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
630 GLenum target
, GLint level
,
631 struct gl_texture_image
*texImage
)
635 /* XXX simplify this with _mesa_tex_target_to_face() */
640 case GL_TEXTURE_1D_ARRAY_EXT
:
641 case GL_TEXTURE_2D_ARRAY_EXT
:
642 tObj
->Image
[0][level
] = texImage
;
644 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
645 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
646 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
647 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
648 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
649 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
651 GLuint face
= ((GLuint
) target
-
652 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
653 tObj
->Image
[face
][level
] = texImage
;
656 case GL_TEXTURE_RECTANGLE_NV
:
658 tObj
->Image
[0][level
] = texImage
;
661 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
664 /* Set the 'back' pointer */
665 texImage
->TexObject
= tObj
;
670 * Allocate a texture image structure.
672 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
675 * \return a pointer to gl_texture_image struct with all fields initialized to
678 struct gl_texture_image
*
679 _mesa_new_texture_image( GLcontext
*ctx
)
682 return CALLOC_STRUCT(gl_texture_image
);
687 * Free texture image data.
688 * This function is a fallback called via ctx->Driver.FreeTexImageData().
690 * \param teximage texture image.
692 * Free the texture image data if it's not marked as client data.
695 _mesa_free_texture_image_data(GLcontext
*ctx
,
696 struct gl_texture_image
*texImage
)
700 if (texImage
->Data
&& !texImage
->IsClientData
) {
701 /* free the old texture data */
702 _mesa_free_texmemory(texImage
->Data
);
705 texImage
->Data
= NULL
;
710 * Free texture image.
712 * \param teximage texture image.
714 * Free the texture image structure and the associated image data.
717 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
719 /* Free texImage->Data and/or any other driver-specific texture
722 ASSERT(ctx
->Driver
.FreeTexImageData
);
723 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
725 ASSERT(texImage
->Data
== NULL
);
726 if (texImage
->ImageOffsets
)
727 _mesa_free(texImage
->ImageOffsets
);
728 _mesa_free(texImage
);
733 * Test if a target is a proxy target.
735 * \param target texture target.
737 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
740 _mesa_is_proxy_texture(GLenum target
)
742 return (target
== GL_PROXY_TEXTURE_1D
||
743 target
== GL_PROXY_TEXTURE_2D
||
744 target
== GL_PROXY_TEXTURE_3D
||
745 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
746 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
747 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
748 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
753 * Get the texture object that corresponds to the target of the given texture unit.
755 * \param ctx GL context.
756 * \param texUnit texture unit.
757 * \param target texture target.
759 * \return pointer to the texture object on success, or NULL on failure.
761 * \sa gl_texture_unit.
763 struct gl_texture_object
*
764 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
769 return texUnit
->Current1D
;
770 case GL_PROXY_TEXTURE_1D
:
771 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
773 return texUnit
->Current2D
;
774 case GL_PROXY_TEXTURE_2D
:
775 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
777 return texUnit
->Current3D
;
778 case GL_PROXY_TEXTURE_3D
:
779 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
780 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
781 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
782 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
783 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
784 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
785 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
786 case GL_TEXTURE_CUBE_MAP_ARB
:
787 return ctx
->Extensions
.ARB_texture_cube_map
788 ? texUnit
->CurrentCubeMap
: NULL
;
789 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
790 return ctx
->Extensions
.ARB_texture_cube_map
791 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
792 case GL_TEXTURE_RECTANGLE_NV
:
793 return ctx
->Extensions
.NV_texture_rectangle
794 ? texUnit
->CurrentRect
: NULL
;
795 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
796 return ctx
->Extensions
.NV_texture_rectangle
797 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
798 case GL_TEXTURE_1D_ARRAY_EXT
:
799 return ctx
->Extensions
.MESA_texture_array
800 ? texUnit
->Current1DArray
: NULL
;
801 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
802 return ctx
->Extensions
.MESA_texture_array
803 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
804 case GL_TEXTURE_2D_ARRAY_EXT
:
805 return ctx
->Extensions
.MESA_texture_array
806 ? texUnit
->Current2DArray
: NULL
;
807 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
808 return ctx
->Extensions
.MESA_texture_array
809 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
811 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
818 * Get the texture image struct which corresponds to target and level
819 * of the given texture unit.
821 * \param ctx GL context.
822 * \param texUnit texture unit.
823 * \param target texture target.
824 * \param level image level.
826 * \return pointer to the texture image structure on success, or NULL on failure.
828 * \sa gl_texture_unit.
830 struct gl_texture_image
*
831 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
832 GLenum target
, GLint level
)
836 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
)
839 /* XXX simplify this with _mesa_tex_target_to_face() */
842 case GL_PROXY_TEXTURE_1D
:
844 case GL_PROXY_TEXTURE_2D
:
846 case GL_PROXY_TEXTURE_3D
:
847 return texObj
->Image
[0][level
];
849 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
850 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
851 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
852 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
853 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
854 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
855 if (ctx
->Extensions
.ARB_texture_cube_map
) {
856 GLuint face
= ((GLuint
) target
-
857 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
858 return texObj
->Image
[face
][level
];
863 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
864 if (ctx
->Extensions
.ARB_texture_cube_map
)
865 return texObj
->Image
[0][level
];
869 case GL_TEXTURE_RECTANGLE_NV
:
870 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
871 if (ctx
->Extensions
.NV_texture_rectangle
&& level
== 0)
872 return texObj
->Image
[0][level
];
876 case GL_TEXTURE_1D_ARRAY_EXT
:
877 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
878 case GL_TEXTURE_2D_ARRAY_EXT
:
879 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
880 return (ctx
->Extensions
.MESA_texture_array
)
881 ? texObj
->Image
[0][level
] : NULL
;
890 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
891 * it and install it. Only return NULL if passed a bad parameter or run
894 struct gl_texture_image
*
895 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
896 GLenum target
, GLint level
)
898 struct gl_texture_image
*texImage
;
903 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
905 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
907 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
911 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
919 * Return pointer to the specified proxy texture image.
920 * Note that proxy textures are per-context, not per-texture unit.
921 * \return pointer to texture image or NULL if invalid target, invalid
922 * level, or out of memory.
924 struct gl_texture_image
*
925 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
927 struct gl_texture_image
*texImage
;
933 case GL_PROXY_TEXTURE_1D
:
934 if (level
>= ctx
->Const
.MaxTextureLevels
)
936 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
]->Image
[0][level
];
938 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
940 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
943 ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
]->Image
[0][level
] = texImage
;
944 /* Set the 'back' pointer */
945 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
948 case GL_PROXY_TEXTURE_2D
:
949 if (level
>= ctx
->Const
.MaxTextureLevels
)
951 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
];
953 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
955 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
958 ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
] = texImage
;
959 /* Set the 'back' pointer */
960 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
963 case GL_PROXY_TEXTURE_3D
:
964 if (level
>= ctx
->Const
.Max3DTextureLevels
)
966 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
]->Image
[0][level
];
968 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
970 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
973 ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
]->Image
[0][level
] = texImage
;
974 /* Set the 'back' pointer */
975 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
978 case GL_PROXY_TEXTURE_CUBE_MAP
:
979 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
981 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
]->Image
[0][level
];
983 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
985 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
988 ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
]->Image
[0][level
] = texImage
;
989 /* Set the 'back' pointer */
990 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
];
993 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
996 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
]->Image
[0][level
];
998 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1000 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1003 ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
]->Image
[0][level
] = texImage
;
1004 /* Set the 'back' pointer */
1005 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
];
1008 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1009 if (level
>= ctx
->Const
.MaxTextureLevels
)
1011 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
]->Image
[0][level
];
1013 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1015 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1018 ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
]->Image
[0][level
] = texImage
;
1019 /* Set the 'back' pointer */
1020 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
];
1023 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1024 if (level
>= ctx
->Const
.MaxTextureLevels
)
1026 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
]->Image
[0][level
];
1028 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1030 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1033 ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
]->Image
[0][level
] = texImage
;
1034 /* Set the 'back' pointer */
1035 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
];
1045 * Get the maximum number of allowed mipmap levels.
1047 * \param ctx GL context.
1048 * \param target texture target.
1050 * \return the maximum number of allowed mipmap levels for the given
1051 * texture target, or zero if passed a bad target.
1056 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
1060 case GL_PROXY_TEXTURE_1D
:
1062 case GL_PROXY_TEXTURE_2D
:
1063 case GL_TEXTURE_1D_ARRAY_EXT
:
1064 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1065 case GL_TEXTURE_2D_ARRAY_EXT
:
1066 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1067 return ctx
->Const
.MaxTextureLevels
;
1069 case GL_PROXY_TEXTURE_3D
:
1070 return ctx
->Const
.Max3DTextureLevels
;
1071 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1072 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1073 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1074 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1075 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1076 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1077 case GL_TEXTURE_CUBE_MAP_ARB
:
1078 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1079 return ctx
->Const
.MaxCubeTextureLevels
;
1080 case GL_TEXTURE_RECTANGLE_NV
:
1081 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1084 return 0; /* bad target */
1090 #if 000 /* not used anymore */
1092 * glTexImage[123]D can accept a NULL image pointer. In this case we
1093 * create a texture image with unspecified image contents per the OpenGL
1097 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1099 const GLint components
= _mesa_components_in_format(format
);
1100 const GLint numPixels
= width
* height
* depth
;
1101 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1105 * Let's see if anyone finds this. If glTexImage2D() is called with
1106 * a NULL image pointer then load the texture image with something
1107 * interesting instead of leaving it indeterminate.
1110 static const char message
[8][32] = {
1111 " X X XXXXX XXX X ",
1112 " XX XX X X X X X ",
1114 " X X XXXX XXX XXXXX ",
1117 " X X XXXXX XXX X X ",
1121 GLubyte
*imgPtr
= data
;
1123 for (h
= 0; h
< depth
; h
++) {
1124 for (i
= 0; i
< height
; i
++) {
1125 GLint srcRow
= 7 - (i
% 8);
1126 for (j
= 0; j
< width
; j
++) {
1127 GLint srcCol
= j
% 32;
1128 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1129 for (k
= 0; k
< components
; k
++) {
1145 * Reset the fields of a gl_texture_image struct to zero.
1147 * \param img texture image structure.
1149 * This is called when a proxy texture test fails, we set all the
1150 * image members (except DriverData) to zero.
1151 * It's also used in glTexImage[123]D as a safeguard to be sure all
1152 * required fields get initialized properly by the Driver.TexImage[123]D
1156 clear_teximage_fields(struct gl_texture_image
*img
)
1159 img
->_BaseFormat
= 0;
1160 img
->InternalFormat
= 0;
1166 if (img
->ImageOffsets
) {
1167 _mesa_free(img
->ImageOffsets
);
1168 img
->ImageOffsets
= NULL
;
1174 img
->HeightLog2
= 0;
1177 img
->TexFormat
= &_mesa_null_texformat
;
1178 img
->FetchTexelc
= NULL
;
1179 img
->FetchTexelf
= NULL
;
1180 img
->IsCompressed
= 0;
1181 img
->CompressedSize
= 0;
1186 * Initialize basic fields of the gl_texture_image struct.
1188 * \param ctx GL context.
1189 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1190 * \param img texture image structure to be initialized.
1191 * \param width image width.
1192 * \param height image height.
1193 * \param depth image depth.
1194 * \param border image border.
1195 * \param internalFormat internal format.
1197 * Fills in the fields of \p img with the given information.
1198 * Note: width, height and depth include the border.
1201 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1202 struct gl_texture_image
*img
,
1203 GLsizei width
, GLsizei height
, GLsizei depth
,
1204 GLint border
, GLenum internalFormat
)
1210 ASSERT(height
>= 0);
1213 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1214 ASSERT(img
->_BaseFormat
> 0);
1215 img
->InternalFormat
= internalFormat
;
1216 img
->Border
= border
;
1218 img
->Height
= height
;
1220 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1221 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1222 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1223 img
->WidthLog2
= logbase2(img
->Width2
);
1224 if (height
== 1) /* 1-D texture */
1225 img
->HeightLog2
= 0;
1227 img
->HeightLog2
= logbase2(img
->Height2
);
1228 if (depth
== 1) /* 2-D texture */
1231 img
->DepthLog2
= logbase2(img
->Depth2
);
1232 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1233 img
->IsCompressed
= GL_FALSE
;
1234 img
->CompressedSize
= 0;
1236 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1237 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1238 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1239 img
->_IsPowerOfTwo
= GL_TRUE
;
1241 img
->_IsPowerOfTwo
= GL_FALSE
;
1243 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1244 img
->RowStride
= width
;
1245 /* Allocate the ImageOffsets array and initialize to typical values.
1246 * We allocate the array for 1D/2D textures too in order to avoid special-
1247 * case code in the texstore routines.
1249 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1250 for (i
= 0; i
< depth
; i
++) {
1251 img
->ImageOffsets
[i
] = i
* width
* height
;
1254 /* Compute Width/Height/DepthScale for mipmap lod computation */
1255 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1256 /* scale = 1.0 since texture coords directly map to texels */
1257 img
->WidthScale
= 1.0;
1258 img
->HeightScale
= 1.0;
1259 img
->DepthScale
= 1.0;
1262 img
->WidthScale
= (GLfloat
) img
->Width
;
1263 img
->HeightScale
= (GLfloat
) img
->Height
;
1264 img
->DepthScale
= (GLfloat
) img
->Depth
;
1270 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1271 * level, width, height and depth against the ctx->Const limits for textures.
1273 * A hardware driver might override this function if, for example, the
1274 * max 3D texture size is 512x512x64 (i.e. not a cube).
1276 * Note that width, height, depth == 0 is not an error. However, a
1277 * texture with zero width/height/depth will be considered "incomplete"
1278 * and texturing will effectively be disabled.
1280 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1281 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1282 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1283 * \param level as passed to glTexImage
1284 * \param internalFormat as passed to glTexImage
1285 * \param format as passed to glTexImage
1286 * \param type as passed to glTexImage
1287 * \param width as passed to glTexImage
1288 * \param height as passed to glTexImage
1289 * \param depth as passed to glTexImage
1290 * \param border as passed to glTexImage
1291 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1294 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1295 GLint internalFormat
, GLenum format
, GLenum type
,
1296 GLint width
, GLint height
, GLint depth
, GLint border
)
1300 (void) internalFormat
;
1305 case GL_PROXY_TEXTURE_1D
:
1306 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1307 if (width
< 2 * border
|| width
> 2 + maxSize
||
1308 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1309 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1310 level
>= ctx
->Const
.MaxTextureLevels
) {
1311 /* bad width or level */
1315 case GL_PROXY_TEXTURE_2D
:
1316 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1317 if (width
< 2 * border
|| width
> 2 + maxSize
||
1318 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1319 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1320 height
< 2 * border
|| height
> 2 + maxSize
||
1321 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1322 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1323 level
>= ctx
->Const
.MaxTextureLevels
) {
1324 /* bad width or height or level */
1328 case GL_PROXY_TEXTURE_3D
:
1329 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1330 if (width
< 2 * border
|| width
> 2 + maxSize
||
1331 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1332 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1333 height
< 2 * border
|| height
> 2 + maxSize
||
1334 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1335 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1336 depth
< 2 * border
|| depth
> 2 + maxSize
||
1337 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1338 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1339 level
>= ctx
->Const
.Max3DTextureLevels
) {
1340 /* bad width or height or depth or level */
1344 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1345 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1346 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1348 /* bad width or height or level */
1352 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1353 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1354 if (width
< 2 * border
|| width
> 2 + maxSize
||
1355 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1356 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1357 height
< 2 * border
|| height
> 2 + maxSize
||
1358 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1359 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1360 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1361 /* bad width or height */
1365 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1366 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1367 if (width
< 2 * border
|| width
> 2 + maxSize
||
1368 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1369 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1370 level
>= ctx
->Const
.MaxTextureLevels
) {
1371 /* bad width or level */
1375 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1379 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1380 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1381 if (width
< 2 * border
|| width
> 2 + maxSize
||
1382 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1383 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1384 height
< 2 * border
|| height
> 2 + maxSize
||
1385 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1386 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1387 level
>= ctx
->Const
.MaxTextureLevels
) {
1388 /* bad width or height or level */
1391 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1396 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1403 * Helper function to determine whether a target supports compressed textures
1406 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1408 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1409 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1410 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1411 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1412 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1413 || ((ctx
->Extensions
.MESA_texture_array
&&
1414 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1415 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1420 * Test the glTexImage[123]D() parameters for errors.
1422 * \param ctx GL context.
1423 * \param target texture target given by the user.
1424 * \param level image level given by the user.
1425 * \param internalFormat internal format given by the user.
1426 * \param format pixel data format given by the user.
1427 * \param type pixel data type given by the user.
1428 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1429 * \param width image width given by the user.
1430 * \param height image height given by the user.
1431 * \param depth image depth given by the user.
1432 * \param border image border given by the user.
1434 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1436 * Verifies each of the parameters against the constants specified in
1437 * __GLcontextRec::Const and the supported extensions, and according to the
1438 * OpenGL specification.
1441 texture_error_check( GLcontext
*ctx
, GLenum target
,
1442 GLint level
, GLint internalFormat
,
1443 GLenum format
, GLenum type
,
1445 GLint width
, GLint height
,
1446 GLint depth
, GLint border
)
1448 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1449 GLboolean sizeOK
= GL_TRUE
;
1450 GLboolean colorFormat
, indexFormat
;
1451 GLenum proxy_target
;
1453 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1454 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1456 _mesa_error(ctx
, GL_INVALID_VALUE
,
1457 "glTexImage%dD(level=%d)", dimensions
, level
);
1463 if (border
< 0 || border
> 1 ||
1464 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1465 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1467 _mesa_error(ctx
, GL_INVALID_VALUE
,
1468 "glTexImage%dD(border=%d)", dimensions
, border
);
1473 if (width
< 0 || height
< 0 || depth
< 0) {
1475 _mesa_error(ctx
, GL_INVALID_VALUE
,
1476 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1481 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1482 * level, width, height and depth.
1484 if (dimensions
== 1) {
1485 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1486 proxy_target
= GL_PROXY_TEXTURE_1D
;
1491 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1495 else if (dimensions
== 2) {
1497 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1498 proxy_target
= GL_PROXY_TEXTURE_2D
;
1500 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1501 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1502 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1503 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1504 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1507 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1508 sizeOK
= (width
== height
);
1510 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1511 target
== GL_TEXTURE_RECTANGLE_NV
) {
1512 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1513 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1516 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1518 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1519 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1520 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1523 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1527 else if (dimensions
== 3) {
1528 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1529 proxy_target
= GL_PROXY_TEXTURE_3D
;
1531 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1532 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1533 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1536 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1541 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1545 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1546 internalFormat
, format
,
1547 type
, width
, height
,
1551 _mesa_error(ctx
, GL_INVALID_VALUE
,
1552 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1553 dimensions
, level
, width
, height
, depth
);
1558 /* Check internalFormat */
1559 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1561 _mesa_error(ctx
, GL_INVALID_VALUE
,
1562 "glTexImage%dD(internalFormat=0x%x)",
1563 dimensions
, internalFormat
);
1568 /* Check incoming image format and type */
1569 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1570 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1571 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1574 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1575 "glTexImage%dD(format or type)", dimensions
);
1580 /* make sure internal format and format basically agree */
1581 colorFormat
= _mesa_is_color_format(format
);
1582 indexFormat
= is_index_format(format
);
1583 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1584 (is_index_format(internalFormat
) && !indexFormat
) ||
1585 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1586 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1587 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
))) {
1589 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1590 "glTexImage(internalFormat/format)");
1594 /* additional checks for ycbcr textures */
1595 if (internalFormat
== GL_YCBCR_MESA
) {
1596 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1597 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1598 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1600 _mesa_sprintf(message
,
1601 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1602 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1603 return GL_TRUE
; /* error */
1605 if (target
!= GL_TEXTURE_2D
&&
1606 target
!= GL_PROXY_TEXTURE_2D
&&
1607 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1608 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1610 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1616 _mesa_sprintf(message
,
1617 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1618 dimensions
, border
);
1619 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1625 /* additional checks for depth textures */
1626 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1627 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1628 if (target
!= GL_TEXTURE_1D
&&
1629 target
!= GL_PROXY_TEXTURE_1D
&&
1630 target
!= GL_TEXTURE_2D
&&
1631 target
!= GL_PROXY_TEXTURE_2D
&&
1632 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1633 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1635 _mesa_error(ctx
, GL_INVALID_ENUM
,
1636 "glTexImage(target/internalFormat)");
1641 /* additional checks for compressed textures */
1642 if (is_compressed_format(ctx
, internalFormat
)) {
1643 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1644 _mesa_error(ctx
, GL_INVALID_ENUM
,
1645 "glTexImage%d(target)", dimensions
);
1650 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1651 "glTexImage%D(border!=0)", dimensions
);
1657 /* if we get here, the parameters are OK */
1663 * Test glTexSubImage[123]D() parameters for errors.
1665 * \param ctx GL context.
1666 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1667 * \param target texture target given by the user.
1668 * \param level image level given by the user.
1669 * \param xoffset sub-image x offset given by the user.
1670 * \param yoffset sub-image y offset given by the user.
1671 * \param zoffset sub-image z offset given by the user.
1672 * \param format pixel data format given by the user.
1673 * \param type pixel data type given by the user.
1674 * \param width image width given by the user.
1675 * \param height image height given by the user.
1676 * \param depth image depth given by the user.
1678 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1680 * Verifies each of the parameters against the constants specified in
1681 * __GLcontextRec::Const and the supported extensions, and according to the
1682 * OpenGL specification.
1685 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1686 GLenum target
, GLint level
,
1687 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1688 GLint width
, GLint height
, GLint depth
,
1689 GLenum format
, GLenum type
)
1692 if (dimensions
== 1) {
1693 if (target
!= GL_TEXTURE_1D
) {
1694 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1698 else if (dimensions
== 2) {
1699 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1700 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1701 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1702 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1706 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1707 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1708 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1712 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1713 if (!ctx
->Extensions
.MESA_texture_array
) {
1714 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1718 else if (target
!= GL_TEXTURE_2D
) {
1719 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1723 else if (dimensions
== 3) {
1724 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1725 if (!ctx
->Extensions
.MESA_texture_array
) {
1726 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1730 else if (target
!= GL_TEXTURE_3D
) {
1731 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1736 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1740 /* Basic level check */
1741 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1742 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1747 _mesa_error(ctx
, GL_INVALID_VALUE
,
1748 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1751 if (height
< 0 && dimensions
> 1) {
1752 _mesa_error(ctx
, GL_INVALID_VALUE
,
1753 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1756 if (depth
< 0 && dimensions
> 2) {
1757 _mesa_error(ctx
, GL_INVALID_VALUE
,
1758 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1762 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1763 _mesa_error(ctx
, GL_INVALID_ENUM
,
1764 "glTexSubImage%dD(format or type)", dimensions
);
1772 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1773 GLenum target
, GLint level
,
1774 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1775 GLint width
, GLint height
, GLint depth
,
1776 GLenum format
, GLenum type
,
1777 const struct gl_texture_image
*destTex
)
1780 /* undefined image level */
1781 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1785 if (xoffset
< -((GLint
)destTex
->Border
)) {
1786 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1790 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1791 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1795 if (dimensions
> 1) {
1796 if (yoffset
< -((GLint
)destTex
->Border
)) {
1797 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1801 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1802 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1807 if (dimensions
> 2) {
1808 if (zoffset
< -((GLint
)destTex
->Border
)) {
1809 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1812 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1813 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1818 #if FEATURE_EXT_texture_sRGB
1819 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1820 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1821 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1822 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1823 if ((width
& 0x3) || (height
& 0x3) ||
1824 (xoffset
& 0x3) || (yoffset
& 0x3))
1825 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1826 "glTexSubImage%dD(size or offset not multiple of 4)",
1832 if (destTex
->IsCompressed
) {
1833 if (!target_can_be_compressed(ctx
, target
)) {
1834 _mesa_error(ctx
, GL_INVALID_ENUM
,
1835 "glTexSubImage%D(target)", dimensions
);
1838 /* offset must be multiple of 4 */
1839 if ((xoffset
& 3) || (yoffset
& 3)) {
1840 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1841 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1844 /* size must be multiple of 4 or equal to whole texture size */
1845 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1846 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1847 "glTexSubImage%D(width)", dimensions
);
1850 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1851 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1852 "glTexSubImage%D(width)", dimensions
);
1862 * Test glCopyTexImage[12]D() parameters for errors.
1864 * \param ctx GL context.
1865 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1866 * \param target texture target given by the user.
1867 * \param level image level given by the user.
1868 * \param internalFormat internal format given by the user.
1869 * \param width image width given by the user.
1870 * \param height image height given by the user.
1871 * \param depth image depth given by the user.
1872 * \param border texture border.
1874 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1876 * Verifies each of the parameters against the constants specified in
1877 * __GLcontextRec::Const and the supported extensions, and according to the
1878 * OpenGL specification.
1881 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1882 GLenum target
, GLint level
, GLint internalFormat
,
1883 GLint width
, GLint height
, GLint border
)
1889 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1890 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1891 _mesa_error(ctx
, GL_INVALID_VALUE
,
1892 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1896 /* Check that the source buffer is complete */
1897 if (ctx
->ReadBuffer
->Name
) {
1898 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1899 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1900 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1901 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1907 if (border
< 0 || border
> 1 ||
1908 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1909 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1913 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1915 _mesa_error(ctx
, GL_INVALID_VALUE
,
1916 "glCopyTexImage%dD(internalFormat)", dimensions
);
1920 /* NOTE: the format and type aren't really significant for
1921 * TestProxyTexImage(). Only the internalformat really matters.
1922 if (!_mesa_source_buffer_exists(ctx, format)) {
1923 _mesa_error(ctx, GL_INVALID_OPERATION,
1924 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1931 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1932 * level, width, height and depth.
1934 if (dimensions
== 1) {
1935 if (target
== GL_TEXTURE_1D
) {
1936 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1937 level
, internalFormat
,
1939 width
, 1, 1, border
);
1942 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1946 else if (dimensions
== 2) {
1947 if (target
== GL_TEXTURE_2D
) {
1948 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1949 level
, internalFormat
,
1951 width
, height
, 1, border
);
1953 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1954 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1955 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1956 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1959 sizeOK
= (width
== height
) &&
1960 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1961 level
, internalFormat
, format
, type
,
1962 width
, height
, 1, border
);
1964 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1965 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1966 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1969 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1970 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1971 level
, internalFormat
,
1973 width
, height
, 1, border
);
1975 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1976 if (!ctx
->Extensions
.MESA_texture_array
) {
1977 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1980 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1981 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1982 level
, internalFormat
,
1984 width
, height
, 1, border
);
1987 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1992 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1997 if (dimensions
== 1) {
1998 _mesa_error(ctx
, GL_INVALID_VALUE
,
1999 "glCopyTexImage1D(width=%d)", width
);
2002 ASSERT(dimensions
== 2);
2003 _mesa_error(ctx
, GL_INVALID_VALUE
,
2004 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2009 if (is_compressed_format(ctx
, internalFormat
)) {
2010 if (!target_can_be_compressed(ctx
, target
)) {
2011 _mesa_error(ctx
, GL_INVALID_ENUM
,
2012 "glCopyTexImage%d(target)", dimensions
);
2016 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2017 "glCopyTexImage%D(border!=0)", dimensions
);
2021 else if (is_depth_format(internalFormat
)) {
2022 /* make sure we have depth/stencil buffers */
2023 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2024 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2025 "glCopyTexImage%D(no depth)", dimensions
);
2029 else if (is_depthstencil_format(internalFormat
)) {
2030 /* make sure we have depth/stencil buffers */
2031 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2032 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2033 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2038 /* if we get here, the parameters are OK */
2044 * Test glCopyTexSubImage[12]D() parameters for errors.
2045 * Note that this is the first part of error checking.
2046 * See also copytexsubimage_error_check2() below for the second part.
2048 * \param ctx GL context.
2049 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2050 * \param target texture target given by the user.
2051 * \param level image level given by the user.
2053 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2056 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
2057 GLenum target
, GLint level
)
2059 /* Check that the source buffer is complete */
2060 if (ctx
->ReadBuffer
->Name
) {
2061 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2062 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2063 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2064 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2070 if (dimensions
== 1) {
2071 if (target
!= GL_TEXTURE_1D
) {
2072 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2076 else if (dimensions
== 2) {
2077 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2078 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2079 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2080 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2084 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2085 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2086 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2090 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2091 if (!ctx
->Extensions
.MESA_texture_array
) {
2092 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2096 else if (target
!= GL_TEXTURE_2D
) {
2097 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2101 else if (dimensions
== 3) {
2102 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2103 (!ctx
->Extensions
.MESA_texture_array
))
2104 && (target
!= GL_TEXTURE_3D
)) {
2105 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2111 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2112 _mesa_error(ctx
, GL_INVALID_VALUE
,
2113 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2122 * Second part of error checking for glCopyTexSubImage[12]D().
2123 * \param xoffset sub-image x offset given by the user.
2124 * \param yoffset sub-image y offset given by the user.
2125 * \param zoffset sub-image z offset given by the user.
2126 * \param width image width given by the user.
2127 * \param height image height given by the user.
2130 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2131 GLenum target
, GLint level
,
2132 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2133 GLsizei width
, GLsizei height
,
2134 const struct gl_texture_image
*teximage
)
2136 /* check that dest tex image exists */
2138 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2139 "glCopyTexSubImage%dD(undefined texture level: %d)",
2146 _mesa_error(ctx
, GL_INVALID_VALUE
,
2147 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2150 if (dimensions
> 1 && height
< 0) {
2151 _mesa_error(ctx
, GL_INVALID_VALUE
,
2152 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2156 /* check x/y offsets */
2157 if (xoffset
< -((GLint
)teximage
->Border
)) {
2158 _mesa_error(ctx
, GL_INVALID_VALUE
,
2159 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2162 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2163 _mesa_error(ctx
, GL_INVALID_VALUE
,
2164 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2167 if (dimensions
> 1) {
2168 if (yoffset
< -((GLint
)teximage
->Border
)) {
2169 _mesa_error(ctx
, GL_INVALID_VALUE
,
2170 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2173 /* NOTE: we're adding the border here, not subtracting! */
2174 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2175 _mesa_error(ctx
, GL_INVALID_VALUE
,
2176 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2181 /* check z offset */
2182 if (dimensions
> 2) {
2183 if (zoffset
< -((GLint
)teximage
->Border
)) {
2184 _mesa_error(ctx
, GL_INVALID_VALUE
,
2185 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2188 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2189 _mesa_error(ctx
, GL_INVALID_VALUE
,
2190 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2195 if (teximage
->IsCompressed
) {
2196 if (!target_can_be_compressed(ctx
, target
)) {
2197 _mesa_error(ctx
, GL_INVALID_ENUM
,
2198 "glCopyTexSubImage%d(target)", dimensions
);
2201 /* offset must be multiple of 4 */
2202 if ((xoffset
& 3) || (yoffset
& 3)) {
2203 _mesa_error(ctx
, GL_INVALID_VALUE
,
2204 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2207 /* size must be multiple of 4 */
2208 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2209 _mesa_error(ctx
, GL_INVALID_VALUE
,
2210 "glCopyTexSubImage%D(width)", dimensions
);
2213 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2214 _mesa_error(ctx
, GL_INVALID_VALUE
,
2215 "glCopyTexSubImage%D(height)", dimensions
);
2220 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2221 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2225 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2226 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2227 "glCopyTexSubImage%dD(missing readbuffer)", dimensions
);
2231 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2232 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2233 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2234 "glCopyTexSubImage%D(no depth buffer)",
2239 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2240 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2242 "glCopyTexSubImage%D(no depth/stencil buffer)",
2248 /* if we get here, the parameters are OK */
2254 * Get texture image. Called by glGetTexImage.
2256 * \param target texture target.
2257 * \param level image level.
2258 * \param format pixel data format for returned image.
2259 * \param type pixel data type for returned image.
2260 * \param pixels returned pixel data.
2263 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2264 GLenum type
, GLvoid
*pixels
)
2266 const struct gl_texture_unit
*texUnit
;
2267 struct gl_texture_object
*texObj
;
2268 struct gl_texture_image
*texImage
;
2269 GLint maxLevels
= 0;
2270 GET_CURRENT_CONTEXT(ctx
);
2271 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2273 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2274 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2275 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2276 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2280 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2281 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2283 if (level
< 0 || level
>= maxLevels
) {
2284 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2288 if (_mesa_sizeof_packed_type(type
) <= 0) {
2289 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2293 if (_mesa_components_in_format(format
) <= 0 ||
2294 format
== GL_STENCIL_INDEX
) {
2295 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2299 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2300 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2304 if (!ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2305 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2309 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2310 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2314 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2315 && is_depthstencil_format(format
)) {
2316 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2320 _mesa_lock_texture(ctx
, texObj
);
2322 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2324 /* invalid mipmap level, not an error */
2329 /* Make sure the requested image format is compatible with the
2330 * texture's format. Note that a color index texture can be converted
2331 * to RGBA so that combo is allowed.
2333 if (_mesa_is_color_format(format
)
2334 && !_mesa_is_color_format(texImage
->TexFormat
->BaseFormat
)
2335 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2336 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2339 else if (is_index_format(format
)
2340 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2341 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2344 else if (is_depth_format(format
)
2345 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2346 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2347 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2350 else if (is_ycbcr_format(format
)
2351 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2352 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2355 else if (is_depthstencil_format(format
)
2356 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2357 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2361 if (ctx
->Pack
.BufferObj
->Name
) {
2362 /* packing texture image into a PBO */
2363 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2364 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2365 texImage
->Height
, texImage
->Depth
,
2366 format
, type
, pixels
)) {
2367 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2368 "glGetTexImage(invalid PBO access)");
2373 /* typically, this will call _mesa_get_teximage() */
2374 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2379 _mesa_unlock_texture(ctx
, texObj
);
2385 * Check if the given texture image is bound to any framebuffer objects
2386 * and update/invalidate them.
2387 * XXX We're only checking the currently bound framebuffer object for now.
2388 * In the future, perhaps struct gl_texture_image should have a pointer (or
2389 * list of pointers (yikes)) to the gl_framebuffer(s) which it's bound to.
2392 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2393 GLuint face
, GLuint level
)
2395 if (ctx
->DrawBuffer
->Name
) {
2397 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2398 struct gl_renderbuffer_attachment
*att
=
2399 ctx
->DrawBuffer
->Attachment
+ i
;
2400 if (att
->Type
== GL_TEXTURE
&&
2401 att
->Texture
== texObj
&&
2402 att
->TextureLevel
== level
&&
2403 att
->CubeMapFace
== face
) {
2404 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2405 /* Tell driver about the new renderbuffer texture */
2406 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2415 * Called from the API. Note that width includes the border.
2418 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2419 GLsizei width
, GLint border
, GLenum format
,
2420 GLenum type
, const GLvoid
*pixels
)
2422 GLsizei postConvWidth
= width
;
2423 GET_CURRENT_CONTEXT(ctx
);
2424 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2426 #if FEATURE_convolve
2427 if (_mesa_is_color_format(internalFormat
)) {
2428 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2432 if (target
== GL_TEXTURE_1D
) {
2433 /* non-proxy target */
2434 struct gl_texture_unit
*texUnit
;
2435 struct gl_texture_object
*texObj
;
2436 struct gl_texture_image
*texImage
;
2437 const GLuint face
= _mesa_tex_target_to_face(target
);
2439 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2440 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2441 return; /* error was recorded */
2444 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2445 _mesa_update_state(ctx
);
2447 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2448 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2449 _mesa_lock_texture(ctx
, texObj
);
2451 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2453 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2457 if (texImage
->Data
) {
2458 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2461 ASSERT(texImage
->Data
== NULL
);
2463 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2464 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2465 postConvWidth
, 1, 1,
2466 border
, internalFormat
);
2468 ASSERT(ctx
->Driver
.TexImage1D
);
2470 /* Give the texture to the driver! <pixels> may be null! */
2471 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2472 width
, border
, format
, type
, pixels
,
2473 &ctx
->Unpack
, texObj
, texImage
);
2475 ASSERT(texImage
->TexFormat
);
2477 update_fbo_texture(ctx
, texObj
, face
, level
);
2480 texObj
->_Complete
= GL_FALSE
;
2481 ctx
->NewState
|= _NEW_TEXTURE
;
2484 _mesa_unlock_texture(ctx
, texObj
);
2486 else if (target
== GL_PROXY_TEXTURE_1D
) {
2487 /* Proxy texture: check for errors and update proxy state */
2488 struct gl_texture_image
*texImage
;
2489 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2490 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2491 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2492 /* when error, clear all proxy texture image parameters */
2494 clear_teximage_fields(texImage
);
2497 /* no error, set the tex image parameters */
2499 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2500 postConvWidth
, 1, 1,
2501 border
, internalFormat
);
2502 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2503 internalFormat
, format
, type
);
2507 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2514 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2515 GLsizei width
, GLsizei height
, GLint border
,
2516 GLenum format
, GLenum type
,
2517 const GLvoid
*pixels
)
2519 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2520 GET_CURRENT_CONTEXT(ctx
);
2521 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2523 #if FEATURE_convolve
2524 if (_mesa_is_color_format(internalFormat
)) {
2525 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2530 if (target
== GL_TEXTURE_2D
||
2531 (ctx
->Extensions
.ARB_texture_cube_map
&&
2532 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2533 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2534 (ctx
->Extensions
.NV_texture_rectangle
&&
2535 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2536 (ctx
->Extensions
.MESA_texture_array
&&
2537 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2538 /* non-proxy target */
2539 struct gl_texture_unit
*texUnit
;
2540 struct gl_texture_object
*texObj
;
2541 struct gl_texture_image
*texImage
;
2542 const GLuint face
= _mesa_tex_target_to_face(target
);
2544 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2545 format
, type
, 2, postConvWidth
, postConvHeight
,
2547 return; /* error was recorded */
2550 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2551 _mesa_update_state(ctx
);
2553 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2554 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2555 _mesa_lock_texture(ctx
, texObj
);
2557 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2559 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2563 if (texImage
->Data
) {
2564 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2567 ASSERT(texImage
->Data
== NULL
);
2568 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2569 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2570 postConvWidth
, postConvHeight
, 1,
2571 border
, internalFormat
);
2573 ASSERT(ctx
->Driver
.TexImage2D
);
2575 /* Give the texture to the driver! <pixels> may be null! */
2576 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2577 width
, height
, border
, format
, type
, pixels
,
2578 &ctx
->Unpack
, texObj
, texImage
);
2580 ASSERT(texImage
->TexFormat
);
2582 update_fbo_texture(ctx
, texObj
, face
, level
);
2585 texObj
->_Complete
= GL_FALSE
;
2586 ctx
->NewState
|= _NEW_TEXTURE
;
2589 _mesa_unlock_texture(ctx
, texObj
);
2591 else if (target
== GL_PROXY_TEXTURE_2D
||
2592 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2593 ctx
->Extensions
.ARB_texture_cube_map
) ||
2594 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2595 ctx
->Extensions
.NV_texture_rectangle
) ||
2596 (ctx
->Extensions
.MESA_texture_array
&&
2597 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2598 /* Proxy texture: check for errors and update proxy state */
2599 struct gl_texture_image
*texImage
;
2600 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2601 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2602 format
, type
, 2, postConvWidth
, postConvHeight
,
2604 /* when error, clear all proxy texture image parameters */
2606 clear_teximage_fields(ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
]);
2609 /* no error, set the tex image parameters */
2610 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2611 postConvWidth
, postConvHeight
, 1,
2612 border
, internalFormat
);
2613 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2614 internalFormat
, format
, type
);
2618 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2625 * Called by the API or display list executor.
2626 * Note that width and height include the border.
2629 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2630 GLsizei width
, GLsizei height
, GLsizei depth
,
2631 GLint border
, GLenum format
, GLenum type
,
2632 const GLvoid
*pixels
)
2634 GET_CURRENT_CONTEXT(ctx
);
2635 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2637 if (target
== GL_TEXTURE_3D
||
2638 (ctx
->Extensions
.MESA_texture_array
&&
2639 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2640 /* non-proxy target */
2641 struct gl_texture_unit
*texUnit
;
2642 struct gl_texture_object
*texObj
;
2643 struct gl_texture_image
*texImage
;
2644 const GLuint face
= _mesa_tex_target_to_face(target
);
2646 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2647 format
, type
, 3, width
, height
, depth
, border
)) {
2648 return; /* error was recorded */
2651 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2652 _mesa_update_state(ctx
);
2654 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2655 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2656 _mesa_lock_texture(ctx
, texObj
);
2658 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2660 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2664 if (texImage
->Data
) {
2665 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2668 ASSERT(texImage
->Data
== NULL
);
2669 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2670 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2671 width
, height
, depth
,
2672 border
, internalFormat
);
2674 ASSERT(ctx
->Driver
.TexImage3D
);
2676 /* Give the texture to the driver! <pixels> may be null! */
2677 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2678 width
, height
, depth
, border
, format
, type
,
2679 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2681 ASSERT(texImage
->TexFormat
);
2683 update_fbo_texture(ctx
, texObj
, face
, level
);
2686 texObj
->_Complete
= GL_FALSE
;
2687 ctx
->NewState
|= _NEW_TEXTURE
;
2690 _mesa_unlock_texture(ctx
, texObj
);
2692 else if (target
== GL_PROXY_TEXTURE_3D
||
2693 (ctx
->Extensions
.MESA_texture_array
&&
2694 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2695 /* Proxy texture: check for errors and update proxy state */
2696 struct gl_texture_image
*texImage
;
2697 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2698 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2699 format
, type
, 3, width
, height
, depth
, border
)) {
2700 /* when error, clear all proxy texture image parameters */
2702 clear_teximage_fields(texImage
);
2705 /* no error, set the tex image parameters */
2706 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2707 depth
, border
, internalFormat
);
2708 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2709 internalFormat
, format
, type
);
2713 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2720 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2721 GLsizei width
, GLsizei height
, GLsizei depth
,
2722 GLint border
, GLenum format
, GLenum type
,
2723 const GLvoid
*pixels
)
2725 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2726 depth
, border
, format
, type
, pixels
);
2732 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2733 GLint xoffset
, GLsizei width
,
2734 GLenum format
, GLenum type
,
2735 const GLvoid
*pixels
)
2737 GLsizei postConvWidth
= width
;
2738 struct gl_texture_unit
*texUnit
;
2739 struct gl_texture_object
*texObj
;
2740 struct gl_texture_image
*texImage
= NULL
;
2741 GET_CURRENT_CONTEXT(ctx
);
2742 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2744 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2745 _mesa_update_state(ctx
);
2747 #if FEATURE_convolve
2748 /* XXX should test internal format */
2749 if (_mesa_is_color_format(format
)) {
2750 _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 #if FEATURE_convolve
2808 /* XXX should test internal format */
2809 if (_mesa_is_color_format(format
)) {
2810 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2815 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2816 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2817 return; /* error was detected */
2820 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2821 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2822 _mesa_lock_texture(ctx
, texObj
);
2824 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2826 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2827 postConvWidth
, postConvHeight
, 1, format
, type
,
2829 goto out
; /* error was detected */
2832 if (width
== 0 || height
== 0)
2833 goto out
; /* no-op, not an error */
2835 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2836 xoffset
+= texImage
->Border
;
2837 yoffset
+= texImage
->Border
;
2839 ASSERT(ctx
->Driver
.TexSubImage2D
);
2840 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2841 width
, height
, format
, type
, pixels
,
2842 &ctx
->Unpack
, texObj
, texImage
);
2843 ctx
->NewState
|= _NEW_TEXTURE
;
2846 _mesa_unlock_texture(ctx
, texObj
);
2852 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2853 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2854 GLsizei width
, GLsizei height
, GLsizei depth
,
2855 GLenum format
, GLenum type
,
2856 const GLvoid
*pixels
)
2858 struct gl_texture_unit
*texUnit
;
2859 struct gl_texture_object
*texObj
;
2860 struct gl_texture_image
*texImage
;
2861 GET_CURRENT_CONTEXT(ctx
);
2862 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2864 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2865 _mesa_update_state(ctx
);
2867 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2868 width
, height
, depth
, format
, type
)) {
2869 return; /* error was detected */
2872 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2873 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2875 _mesa_lock_texture(ctx
, texObj
);
2877 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2879 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2880 width
, height
, depth
, format
, type
, texImage
)) {
2881 goto out
; /* error was detected */
2884 if (width
== 0 || height
== 0 || height
== 0)
2885 goto out
; /* no-op, not an error */
2887 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2888 xoffset
+= texImage
->Border
;
2889 yoffset
+= texImage
->Border
;
2890 zoffset
+= texImage
->Border
;
2892 ASSERT(ctx
->Driver
.TexSubImage3D
);
2893 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2894 xoffset
, yoffset
, zoffset
,
2895 width
, height
, depth
,
2896 format
, type
, pixels
,
2897 &ctx
->Unpack
, texObj
, texImage
);
2898 ctx
->NewState
|= _NEW_TEXTURE
;
2901 _mesa_unlock_texture(ctx
, texObj
);
2907 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2908 GLenum internalFormat
,
2910 GLsizei width
, GLint border
)
2912 struct gl_texture_unit
*texUnit
;
2913 struct gl_texture_object
*texObj
;
2914 struct gl_texture_image
*texImage
;
2915 GLsizei postConvWidth
= width
;
2916 const GLuint face
= _mesa_tex_target_to_face(target
);
2917 GET_CURRENT_CONTEXT(ctx
);
2918 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2920 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2921 _mesa_update_state(ctx
);
2923 #if FEATURE_convolve
2924 if (_mesa_is_color_format(internalFormat
)) {
2925 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2929 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2930 postConvWidth
, 1, border
))
2933 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2934 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2935 _mesa_lock_texture(ctx
, texObj
);
2937 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2939 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2943 if (texImage
->Data
) {
2944 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2947 ASSERT(texImage
->Data
== NULL
);
2949 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2950 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2951 border
, internalFormat
);
2954 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2955 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2956 x
, y
, width
, border
);
2958 ASSERT(texImage
->TexFormat
);
2960 update_fbo_texture(ctx
, texObj
, face
, level
);
2963 texObj
->_Complete
= GL_FALSE
;
2964 ctx
->NewState
|= _NEW_TEXTURE
;
2967 _mesa_unlock_texture(ctx
, texObj
);
2973 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2974 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2977 struct gl_texture_unit
*texUnit
;
2978 struct gl_texture_object
*texObj
;
2979 struct gl_texture_image
*texImage
;
2980 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2981 const GLuint face
= _mesa_tex_target_to_face(target
);
2982 GET_CURRENT_CONTEXT(ctx
);
2983 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2985 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2986 _mesa_update_state(ctx
);
2988 #if FEATURE_convolve
2989 if (_mesa_is_color_format(internalFormat
)) {
2990 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2995 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2996 postConvWidth
, postConvHeight
, border
))
2999 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3000 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3002 _mesa_lock_texture(ctx
, texObj
);
3004 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3007 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3011 if (texImage
->Data
) {
3012 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3015 ASSERT(texImage
->Data
== NULL
);
3017 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3018 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3019 postConvWidth
, postConvHeight
, 1,
3020 border
, internalFormat
);
3022 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3023 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3024 x
, y
, width
, height
, border
);
3026 ASSERT(texImage
->TexFormat
);
3028 update_fbo_texture(ctx
, texObj
, face
, level
);
3031 texObj
->_Complete
= GL_FALSE
;
3032 ctx
->NewState
|= _NEW_TEXTURE
;
3035 _mesa_unlock_texture(ctx
, texObj
);
3040 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3041 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3043 struct gl_texture_unit
*texUnit
;
3044 struct gl_texture_object
*texObj
;
3045 struct gl_texture_image
*texImage
;
3046 GLsizei postConvWidth
= width
;
3050 GET_CURRENT_CONTEXT(ctx
);
3051 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3053 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3054 _mesa_update_state(ctx
);
3056 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3059 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3060 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3062 _mesa_lock_texture(ctx
, texObj
);
3064 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3066 #if FEATURE_convolve
3067 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3068 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3072 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3073 xoffset
, 0, 0, postConvWidth
, 1,
3078 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3079 xoffset
+= texImage
->Border
;
3081 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3083 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3084 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3085 xoffset
, x
, y
, width
);
3088 ctx
->NewState
|= _NEW_TEXTURE
;
3091 _mesa_unlock_texture(ctx
, texObj
);
3097 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3098 GLint xoffset
, GLint yoffset
,
3099 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3101 struct gl_texture_unit
*texUnit
;
3102 struct gl_texture_object
*texObj
;
3103 struct gl_texture_image
*texImage
;
3104 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3105 GET_CURRENT_CONTEXT(ctx
);
3106 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3108 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3109 _mesa_update_state(ctx
);
3111 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3114 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3115 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3117 _mesa_lock_texture(ctx
, texObj
);
3119 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3121 #if FEATURE_convolve
3122 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3123 _mesa_adjust_image_for_convolution(ctx
, 2,
3124 &postConvWidth
, &postConvHeight
);
3128 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3129 postConvWidth
, postConvHeight
, texImage
))
3132 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3133 xoffset
+= texImage
->Border
;
3134 yoffset
+= texImage
->Border
;
3136 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3138 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3139 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3140 xoffset
, yoffset
, x
, y
, width
, height
);
3143 ctx
->NewState
|= _NEW_TEXTURE
;
3146 _mesa_unlock_texture(ctx
, texObj
);
3152 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3153 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3154 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3156 struct gl_texture_unit
*texUnit
;
3157 struct gl_texture_object
*texObj
;
3158 struct gl_texture_image
*texImage
;
3159 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3160 GET_CURRENT_CONTEXT(ctx
);
3161 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3163 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3164 _mesa_update_state(ctx
);
3166 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3169 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3170 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3172 _mesa_lock_texture(ctx
, texObj
);
3174 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3176 #if FEATURE_convolve
3177 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3178 _mesa_adjust_image_for_convolution(ctx
, 2,
3179 &postConvWidth
, &postConvHeight
);
3183 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3184 zoffset
, postConvWidth
, postConvHeight
,
3188 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3189 xoffset
+= texImage
->Border
;
3190 yoffset
+= texImage
->Border
;
3191 zoffset
+= texImage
->Border
;
3193 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3195 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3196 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3197 xoffset
, yoffset
, zoffset
,
3198 x
, y
, width
, height
);
3201 ctx
->NewState
|= _NEW_TEXTURE
;
3204 _mesa_unlock_texture(ctx
, texObj
);
3210 /**********************************************************************/
3211 /****** Compressed Textures ******/
3212 /**********************************************************************/
3216 * Error checking for glCompressedTexImage[123]D().
3217 * \return error code or GL_NO_ERROR.
3220 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3221 GLenum target
, GLint level
,
3222 GLenum internalFormat
, GLsizei width
,
3223 GLsizei height
, GLsizei depth
, GLint border
,
3226 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3228 if (dimensions
== 1) {
3229 /* 1D compressed textures not allowed */
3230 return GL_INVALID_ENUM
;
3232 else if (dimensions
== 2) {
3233 if (target
== GL_PROXY_TEXTURE_2D
) {
3234 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3236 else if (target
== GL_TEXTURE_2D
) {
3237 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3239 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3240 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3241 return GL_INVALID_ENUM
; /*target*/
3242 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3244 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3245 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3246 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3247 return GL_INVALID_ENUM
; /*target*/
3248 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3251 return GL_INVALID_ENUM
; /*target*/
3254 else if (dimensions
== 3) {
3255 /* 3D compressed textures not allowed */
3256 return GL_INVALID_ENUM
;
3259 maxTextureSize
= 1 << (maxLevels
- 1);
3261 /* This will detect any invalid internalFormat value */
3262 if (!is_compressed_format(ctx
, internalFormat
))
3263 return GL_INVALID_ENUM
;
3265 /* This should really never fail */
3266 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3267 return GL_INVALID_ENUM
;
3270 return GL_INVALID_VALUE
;
3273 * XXX We should probably use the proxy texture error check function here.
3275 if (width
< 1 || width
> maxTextureSize
||
3276 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3277 return GL_INVALID_VALUE
;
3279 if ((height
< 1 || height
> maxTextureSize
||
3280 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3282 return GL_INVALID_VALUE
;
3284 if ((depth
< 1 || depth
> maxTextureSize
||
3285 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3287 return GL_INVALID_VALUE
;
3289 /* For cube map, width must equal height */
3290 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3291 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3292 return GL_INVALID_VALUE
;
3294 if (level
< 0 || level
>= maxLevels
)
3295 return GL_INVALID_VALUE
;
3297 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3298 depth
, internalFormat
);
3299 if (expectedSize
!= imageSize
)
3300 return GL_INVALID_VALUE
;
3302 #if FEATURE_EXT_texture_sRGB
3303 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3304 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3305 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3306 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3308 return GL_INVALID_OPERATION
;
3317 * Error checking for glCompressedTexSubImage[123]D().
3318 * \warning There are some bad assumptions here about the size of compressed
3319 * texture tiles (multiple of 4) used to test the validity of the
3320 * offset and size parameters.
3321 * \return error code or GL_NO_ERROR.
3324 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3325 GLenum target
, GLint level
,
3326 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3327 GLsizei width
, GLsizei height
, GLsizei depth
,
3328 GLenum format
, GLsizei imageSize
)
3330 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3333 if (dimensions
== 1) {
3334 /* 1D compressed textures not allowed */
3335 return GL_INVALID_ENUM
;
3337 else if (dimensions
== 2) {
3338 if (target
== GL_PROXY_TEXTURE_2D
) {
3339 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3341 else if (target
== GL_TEXTURE_2D
) {
3342 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3344 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3345 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3346 return GL_INVALID_ENUM
; /*target*/
3347 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3349 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3350 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3351 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3352 return GL_INVALID_ENUM
; /*target*/
3353 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3356 return GL_INVALID_ENUM
; /*target*/
3359 else if (dimensions
== 3) {
3360 /* 3D compressed textures not allowed */
3361 return GL_INVALID_ENUM
;
3364 maxTextureSize
= 1 << (maxLevels
- 1);
3366 /* this will catch any invalid compressed format token */
3367 if (!is_compressed_format(ctx
, format
))
3368 return GL_INVALID_ENUM
;
3370 if (width
< 1 || width
> maxTextureSize
)
3371 return GL_INVALID_VALUE
;
3373 if ((height
< 1 || height
> maxTextureSize
)
3375 return GL_INVALID_VALUE
;
3377 if (level
< 0 || level
>= maxLevels
)
3378 return GL_INVALID_VALUE
;
3380 /* XXX these tests are specific to the compressed format.
3381 * this code should be generalized in some way.
3383 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3384 return GL_INVALID_VALUE
;
3386 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3387 return GL_INVALID_VALUE
;
3389 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3390 return GL_INVALID_VALUE
;
3392 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3394 if (expectedSize
!= imageSize
)
3395 return GL_INVALID_VALUE
;
3403 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3404 GLenum internalFormat
, GLsizei width
,
3405 GLint border
, GLsizei imageSize
,
3408 GET_CURRENT_CONTEXT(ctx
);
3409 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3411 if (target
== GL_TEXTURE_1D
) {
3412 /* non-proxy target */
3413 struct gl_texture_unit
*texUnit
;
3414 struct gl_texture_object
*texObj
;
3415 struct gl_texture_image
*texImage
;
3416 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3417 internalFormat
, width
, 1, 1, border
, imageSize
);
3419 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3423 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3424 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3426 _mesa_lock_texture(ctx
, texObj
);
3428 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3430 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3434 if (texImage
->Data
) {
3435 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3437 ASSERT(texImage
->Data
== NULL
);
3439 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3440 border
, internalFormat
);
3442 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3443 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3444 internalFormat
, width
, border
,
3449 texObj
->_Complete
= GL_FALSE
;
3450 ctx
->NewState
|= _NEW_TEXTURE
;
3453 _mesa_unlock_texture(ctx
, texObj
);
3455 else if (target
== GL_PROXY_TEXTURE_1D
) {
3456 /* Proxy texture: check for errors and update proxy state */
3457 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3458 internalFormat
, width
, 1, 1, border
, imageSize
);
3460 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3461 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3462 internalFormat
, GL_NONE
, GL_NONE
,
3463 width
, 1, 1, border
);
3466 /* if error, clear all proxy texture image parameters */
3467 struct gl_texture_image
*texImage
;
3468 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3470 clear_teximage_fields(texImage
);
3473 /* store the teximage parameters */
3474 struct gl_texture_unit
*texUnit
;
3475 struct gl_texture_object
*texObj
;
3476 struct gl_texture_image
*texImage
;
3477 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3478 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3480 _mesa_lock_texture(ctx
, texObj
);
3482 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3483 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3484 border
, internalFormat
);
3486 _mesa_unlock_texture(ctx
, texObj
);
3490 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3497 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3498 GLenum internalFormat
, GLsizei width
,
3499 GLsizei height
, GLint border
, GLsizei imageSize
,
3502 GET_CURRENT_CONTEXT(ctx
);
3503 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3505 if (target
== GL_TEXTURE_2D
||
3506 (ctx
->Extensions
.ARB_texture_cube_map
&&
3507 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3508 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3509 /* non-proxy target */
3510 struct gl_texture_unit
*texUnit
;
3511 struct gl_texture_object
*texObj
;
3512 struct gl_texture_image
*texImage
;
3513 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3514 internalFormat
, width
, height
, 1, border
, imageSize
);
3516 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3520 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3521 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3523 _mesa_lock_texture(ctx
, texObj
);
3525 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3527 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3531 if (texImage
->Data
) {
3532 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3534 ASSERT(texImage
->Data
== NULL
);
3536 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3537 border
, internalFormat
);
3539 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3540 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3541 internalFormat
, width
, height
,
3542 border
, imageSize
, data
,
3546 texObj
->_Complete
= GL_FALSE
;
3547 ctx
->NewState
|= _NEW_TEXTURE
;
3550 _mesa_unlock_texture(ctx
, texObj
);
3552 else if (target
== GL_PROXY_TEXTURE_2D
||
3553 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3554 ctx
->Extensions
.ARB_texture_cube_map
)) {
3555 /* Proxy texture: check for errors and update proxy state */
3556 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3557 internalFormat
, width
, height
, 1, border
, imageSize
);
3559 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3560 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3561 internalFormat
, GL_NONE
, GL_NONE
,
3562 width
, height
, 1, border
);
3565 /* if error, clear all proxy texture image parameters */
3566 struct gl_texture_image
*texImage
;
3567 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3569 clear_teximage_fields(texImage
);
3572 /* store the teximage parameters */
3573 struct gl_texture_unit
*texUnit
;
3574 struct gl_texture_object
*texObj
;
3575 struct gl_texture_image
*texImage
;
3576 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3577 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3579 _mesa_lock_texture(ctx
, texObj
);
3581 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3582 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3583 border
, internalFormat
);
3585 _mesa_unlock_texture(ctx
, texObj
);
3589 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3596 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3597 GLenum internalFormat
, GLsizei width
,
3598 GLsizei height
, GLsizei depth
, GLint border
,
3599 GLsizei imageSize
, const GLvoid
*data
)
3601 GET_CURRENT_CONTEXT(ctx
);
3602 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3604 if (target
== GL_TEXTURE_3D
) {
3605 /* non-proxy target */
3606 struct gl_texture_unit
*texUnit
;
3607 struct gl_texture_object
*texObj
;
3608 struct gl_texture_image
*texImage
;
3609 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3610 internalFormat
, width
, height
, depth
, border
, imageSize
);
3612 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3616 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3617 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3618 _mesa_lock_texture(ctx
, texObj
);
3620 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3622 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3626 if (texImage
->Data
) {
3627 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3629 ASSERT(texImage
->Data
== NULL
);
3631 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3632 border
, internalFormat
);
3634 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3635 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3637 width
, height
, depth
,
3638 border
, imageSize
, data
,
3642 texObj
->_Complete
= GL_FALSE
;
3643 ctx
->NewState
|= _NEW_TEXTURE
;
3646 _mesa_unlock_texture(ctx
, texObj
);
3648 else if (target
== GL_PROXY_TEXTURE_3D
) {
3649 /* Proxy texture: check for errors and update proxy state */
3650 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3651 internalFormat
, width
, height
, depth
, border
, imageSize
);
3653 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3654 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3655 internalFormat
, GL_NONE
, GL_NONE
,
3656 width
, height
, depth
, border
);
3659 /* if error, clear all proxy texture image parameters */
3660 struct gl_texture_image
*texImage
;
3661 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3663 clear_teximage_fields(texImage
);
3666 /* store the teximage parameters */
3667 struct gl_texture_unit
*texUnit
;
3668 struct gl_texture_object
*texObj
;
3669 struct gl_texture_image
*texImage
;
3670 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3671 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3672 _mesa_lock_texture(ctx
, texObj
);
3674 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3675 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3676 depth
, border
, internalFormat
);
3678 _mesa_unlock_texture(ctx
, texObj
);
3682 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3689 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3690 GLsizei width
, GLenum format
,
3691 GLsizei imageSize
, const GLvoid
*data
)
3693 struct gl_texture_unit
*texUnit
;
3694 struct gl_texture_object
*texObj
;
3695 struct gl_texture_image
*texImage
;
3697 GET_CURRENT_CONTEXT(ctx
);
3698 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3700 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3701 xoffset
, 0, 0, /* pos */
3702 width
, 1, 1, /* size */
3705 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3709 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3710 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3711 _mesa_lock_texture(ctx
, texObj
);
3713 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3716 if ((GLint
) format
!= texImage
->InternalFormat
) {
3717 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3718 "glCompressedTexSubImage1D(format)");
3722 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3723 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3728 goto out
; /* no-op, not an error */
3730 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3731 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3733 format
, imageSize
, data
,
3736 ctx
->NewState
|= _NEW_TEXTURE
;
3739 _mesa_unlock_texture(ctx
, texObj
);
3744 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3745 GLint yoffset
, GLsizei width
, GLsizei height
,
3746 GLenum format
, GLsizei imageSize
,
3749 struct gl_texture_unit
*texUnit
;
3750 struct gl_texture_object
*texObj
;
3751 struct gl_texture_image
*texImage
;
3753 GET_CURRENT_CONTEXT(ctx
);
3754 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3756 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3757 xoffset
, yoffset
, 0, /* pos */
3758 width
, height
, 1, /* size */
3761 /* XXX proxy target? */
3762 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3766 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3767 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3768 _mesa_lock_texture(ctx
, texObj
);
3770 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3773 if ((GLint
) format
!= texImage
->InternalFormat
) {
3774 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3775 "glCompressedTexSubImage2D(format)");
3779 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3780 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3781 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3785 if (width
== 0 || height
== 0)
3786 goto out
; /* no-op, not an error */
3788 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3789 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3790 xoffset
, yoffset
, width
, height
,
3791 format
, imageSize
, data
,
3794 ctx
->NewState
|= _NEW_TEXTURE
;
3797 _mesa_unlock_texture(ctx
, texObj
);
3802 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3803 GLint yoffset
, GLint zoffset
, GLsizei width
,
3804 GLsizei height
, GLsizei depth
, GLenum format
,
3805 GLsizei imageSize
, const GLvoid
*data
)
3807 struct gl_texture_unit
*texUnit
;
3808 struct gl_texture_object
*texObj
;
3809 struct gl_texture_image
*texImage
;
3811 GET_CURRENT_CONTEXT(ctx
);
3812 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3814 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3815 xoffset
, yoffset
, zoffset
,/*pos*/
3816 width
, height
, depth
, /*size*/
3819 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3823 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3824 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3825 _mesa_lock_texture(ctx
, texObj
);
3827 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3830 if ((GLint
) format
!= texImage
->InternalFormat
) {
3831 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3832 "glCompressedTexSubImage3D(format)");
3836 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3837 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3838 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3839 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3843 if (width
== 0 || height
== 0 || depth
== 0)
3844 goto out
; /* no-op, not an error */
3846 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3847 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3848 xoffset
, yoffset
, zoffset
,
3849 width
, height
, depth
,
3850 format
, imageSize
, data
,
3853 ctx
->NewState
|= _NEW_TEXTURE
;
3856 _mesa_unlock_texture(ctx
, texObj
);
3861 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3863 const struct gl_texture_unit
*texUnit
;
3864 struct gl_texture_object
*texObj
;
3865 struct gl_texture_image
*texImage
;
3867 GET_CURRENT_CONTEXT(ctx
);
3868 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3870 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3871 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3873 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3877 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3878 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3880 if (level
< 0 || level
>= maxLevels
) {
3881 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3885 if (_mesa_is_proxy_texture(target
)) {
3886 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3890 _mesa_lock_texture(ctx
, texObj
);
3892 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3894 if (texImage
->IsCompressed
) {
3895 /* this typically calls _mesa_get_compressed_teximage() */
3896 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3900 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3901 "glGetCompressedTexImageARB");
3905 /* probably invalid mipmap level */
3906 _mesa_error(ctx
, GL_INVALID_VALUE
,
3907 "glGetCompressedTexImageARB(level)");
3910 _mesa_unlock_texture(ctx
, texObj
);