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
;
1221 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1222 img
->WidthLog2
= logbase2(img
->Width2
);
1224 if (height
== 1) { /* 1-D texture */
1226 img
->HeightLog2
= 0;
1229 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1230 img
->HeightLog2
= logbase2(img
->Height2
);
1233 if (depth
== 1) { /* 2-D texture */
1238 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1239 img
->DepthLog2
= logbase2(img
->Depth2
);
1242 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1244 img
->IsCompressed
= GL_FALSE
;
1245 img
->CompressedSize
= 0;
1247 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1248 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1249 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1250 img
->_IsPowerOfTwo
= GL_TRUE
;
1252 img
->_IsPowerOfTwo
= GL_FALSE
;
1254 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1255 img
->RowStride
= width
;
1256 /* Allocate the ImageOffsets array and initialize to typical values.
1257 * We allocate the array for 1D/2D textures too in order to avoid special-
1258 * case code in the texstore routines.
1260 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1261 for (i
= 0; i
< depth
; i
++) {
1262 img
->ImageOffsets
[i
] = i
* width
* height
;
1265 /* Compute Width/Height/DepthScale for mipmap lod computation */
1266 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1267 /* scale = 1.0 since texture coords directly map to texels */
1268 img
->WidthScale
= 1.0;
1269 img
->HeightScale
= 1.0;
1270 img
->DepthScale
= 1.0;
1273 img
->WidthScale
= (GLfloat
) img
->Width
;
1274 img
->HeightScale
= (GLfloat
) img
->Height
;
1275 img
->DepthScale
= (GLfloat
) img
->Depth
;
1281 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1282 * level, width, height and depth against the ctx->Const limits for textures.
1284 * A hardware driver might override this function if, for example, the
1285 * max 3D texture size is 512x512x64 (i.e. not a cube).
1287 * Note that width, height, depth == 0 is not an error. However, a
1288 * texture with zero width/height/depth will be considered "incomplete"
1289 * and texturing will effectively be disabled.
1291 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1292 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1293 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1294 * \param level as passed to glTexImage
1295 * \param internalFormat as passed to glTexImage
1296 * \param format as passed to glTexImage
1297 * \param type as passed to glTexImage
1298 * \param width as passed to glTexImage
1299 * \param height as passed to glTexImage
1300 * \param depth as passed to glTexImage
1301 * \param border as passed to glTexImage
1302 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1305 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1306 GLint internalFormat
, GLenum format
, GLenum type
,
1307 GLint width
, GLint height
, GLint depth
, GLint border
)
1311 (void) internalFormat
;
1316 case GL_PROXY_TEXTURE_1D
:
1317 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1318 if (width
< 2 * border
|| width
> 2 + maxSize
||
1319 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1320 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1321 level
>= ctx
->Const
.MaxTextureLevels
) {
1322 /* bad width or level */
1326 case GL_PROXY_TEXTURE_2D
:
1327 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1328 if (width
< 2 * border
|| width
> 2 + maxSize
||
1329 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1330 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1331 height
< 2 * border
|| height
> 2 + maxSize
||
1332 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1333 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1334 level
>= ctx
->Const
.MaxTextureLevels
) {
1335 /* bad width or height or level */
1339 case GL_PROXY_TEXTURE_3D
:
1340 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1341 if (width
< 2 * border
|| width
> 2 + maxSize
||
1342 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1343 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1344 height
< 2 * border
|| height
> 2 + maxSize
||
1345 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1346 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1347 depth
< 2 * border
|| depth
> 2 + maxSize
||
1348 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1349 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1350 level
>= ctx
->Const
.Max3DTextureLevels
) {
1351 /* bad width or height or depth or level */
1355 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1356 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1357 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1359 /* bad width or height or level */
1363 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1364 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1365 if (width
< 2 * border
|| width
> 2 + maxSize
||
1366 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1367 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1368 height
< 2 * border
|| height
> 2 + maxSize
||
1369 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1370 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1371 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1372 /* bad width or height */
1376 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1377 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1378 if (width
< 2 * border
|| width
> 2 + maxSize
||
1379 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1380 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1381 level
>= ctx
->Const
.MaxTextureLevels
) {
1382 /* bad width or level */
1386 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1390 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1391 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1392 if (width
< 2 * border
|| width
> 2 + maxSize
||
1393 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1394 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1395 height
< 2 * border
|| height
> 2 + maxSize
||
1396 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1397 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1398 level
>= ctx
->Const
.MaxTextureLevels
) {
1399 /* bad width or height or level */
1402 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1407 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1414 * Helper function to determine whether a target supports compressed textures
1417 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1419 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1420 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1421 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1422 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1423 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1424 || ((ctx
->Extensions
.MESA_texture_array
&&
1425 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1426 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1431 * Test the glTexImage[123]D() parameters for errors.
1433 * \param ctx GL context.
1434 * \param target texture target given by the user.
1435 * \param level image level given by the user.
1436 * \param internalFormat internal format given by the user.
1437 * \param format pixel data format given by the user.
1438 * \param type pixel data type given by the user.
1439 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1440 * \param width image width given by the user.
1441 * \param height image height given by the user.
1442 * \param depth image depth given by the user.
1443 * \param border image border given by the user.
1445 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1447 * Verifies each of the parameters against the constants specified in
1448 * __GLcontextRec::Const and the supported extensions, and according to the
1449 * OpenGL specification.
1452 texture_error_check( GLcontext
*ctx
, GLenum target
,
1453 GLint level
, GLint internalFormat
,
1454 GLenum format
, GLenum type
,
1456 GLint width
, GLint height
,
1457 GLint depth
, GLint border
)
1459 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1460 GLboolean sizeOK
= GL_TRUE
;
1461 GLboolean colorFormat
, indexFormat
;
1462 GLenum proxy_target
;
1464 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1465 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1467 _mesa_error(ctx
, GL_INVALID_VALUE
,
1468 "glTexImage%dD(level=%d)", dimensions
, level
);
1474 if (border
< 0 || border
> 1 ||
1475 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1476 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1478 _mesa_error(ctx
, GL_INVALID_VALUE
,
1479 "glTexImage%dD(border=%d)", dimensions
, border
);
1484 if (width
< 0 || height
< 0 || depth
< 0) {
1486 _mesa_error(ctx
, GL_INVALID_VALUE
,
1487 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1492 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1493 * level, width, height and depth.
1495 if (dimensions
== 1) {
1496 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1497 proxy_target
= GL_PROXY_TEXTURE_1D
;
1502 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1506 else if (dimensions
== 2) {
1508 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1509 proxy_target
= GL_PROXY_TEXTURE_2D
;
1511 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1512 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1513 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1514 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1515 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1518 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1519 sizeOK
= (width
== height
);
1521 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1522 target
== GL_TEXTURE_RECTANGLE_NV
) {
1523 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1524 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1527 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1529 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1530 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1531 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1534 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1538 else if (dimensions
== 3) {
1539 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1540 proxy_target
= GL_PROXY_TEXTURE_3D
;
1542 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1543 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1544 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1547 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1552 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1556 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1557 internalFormat
, format
,
1558 type
, width
, height
,
1562 _mesa_error(ctx
, GL_INVALID_VALUE
,
1563 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1564 dimensions
, level
, width
, height
, depth
);
1569 /* Check internalFormat */
1570 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1572 _mesa_error(ctx
, GL_INVALID_VALUE
,
1573 "glTexImage%dD(internalFormat=0x%x)",
1574 dimensions
, internalFormat
);
1579 /* Check incoming image format and type */
1580 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1581 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1582 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1585 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1586 "glTexImage%dD(format or type)", dimensions
);
1591 /* make sure internal format and format basically agree */
1592 colorFormat
= _mesa_is_color_format(format
);
1593 indexFormat
= is_index_format(format
);
1594 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1595 (is_index_format(internalFormat
) && !indexFormat
) ||
1596 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1597 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1598 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
))) {
1600 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1601 "glTexImage(internalFormat/format)");
1605 /* additional checks for ycbcr textures */
1606 if (internalFormat
== GL_YCBCR_MESA
) {
1607 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1608 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1609 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1611 _mesa_sprintf(message
,
1612 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1613 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1614 return GL_TRUE
; /* error */
1616 if (target
!= GL_TEXTURE_2D
&&
1617 target
!= GL_PROXY_TEXTURE_2D
&&
1618 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1619 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1621 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1627 _mesa_sprintf(message
,
1628 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1629 dimensions
, border
);
1630 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1636 /* additional checks for depth textures */
1637 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1638 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1639 if (target
!= GL_TEXTURE_1D
&&
1640 target
!= GL_PROXY_TEXTURE_1D
&&
1641 target
!= GL_TEXTURE_2D
&&
1642 target
!= GL_PROXY_TEXTURE_2D
&&
1643 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1644 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1646 _mesa_error(ctx
, GL_INVALID_ENUM
,
1647 "glTexImage(target/internalFormat)");
1652 /* additional checks for compressed textures */
1653 if (is_compressed_format(ctx
, internalFormat
)) {
1654 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1655 _mesa_error(ctx
, GL_INVALID_ENUM
,
1656 "glTexImage%d(target)", dimensions
);
1661 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1662 "glTexImage%D(border!=0)", dimensions
);
1668 /* if we get here, the parameters are OK */
1674 * Test glTexSubImage[123]D() parameters for errors.
1676 * \param ctx GL context.
1677 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1678 * \param target texture target given by the user.
1679 * \param level image level given by the user.
1680 * \param xoffset sub-image x offset given by the user.
1681 * \param yoffset sub-image y offset given by the user.
1682 * \param zoffset sub-image z offset given by the user.
1683 * \param format pixel data format given by the user.
1684 * \param type pixel data type given by the user.
1685 * \param width image width given by the user.
1686 * \param height image height given by the user.
1687 * \param depth image depth given by the user.
1689 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1691 * Verifies each of the parameters against the constants specified in
1692 * __GLcontextRec::Const and the supported extensions, and according to the
1693 * OpenGL specification.
1696 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1697 GLenum target
, GLint level
,
1698 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1699 GLint width
, GLint height
, GLint depth
,
1700 GLenum format
, GLenum type
)
1703 if (dimensions
== 1) {
1704 if (target
!= GL_TEXTURE_1D
) {
1705 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1709 else if (dimensions
== 2) {
1710 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1711 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1712 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1713 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1717 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1718 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1719 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1723 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1724 if (!ctx
->Extensions
.MESA_texture_array
) {
1725 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1729 else if (target
!= GL_TEXTURE_2D
) {
1730 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1734 else if (dimensions
== 3) {
1735 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1736 if (!ctx
->Extensions
.MESA_texture_array
) {
1737 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1741 else if (target
!= GL_TEXTURE_3D
) {
1742 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1747 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1751 /* Basic level check */
1752 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1753 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1758 _mesa_error(ctx
, GL_INVALID_VALUE
,
1759 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1762 if (height
< 0 && dimensions
> 1) {
1763 _mesa_error(ctx
, GL_INVALID_VALUE
,
1764 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1767 if (depth
< 0 && dimensions
> 2) {
1768 _mesa_error(ctx
, GL_INVALID_VALUE
,
1769 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1773 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1774 _mesa_error(ctx
, GL_INVALID_ENUM
,
1775 "glTexSubImage%dD(format or type)", dimensions
);
1783 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1784 GLenum target
, GLint level
,
1785 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1786 GLint width
, GLint height
, GLint depth
,
1787 GLenum format
, GLenum type
,
1788 const struct gl_texture_image
*destTex
)
1791 /* undefined image level */
1792 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1796 if (xoffset
< -((GLint
)destTex
->Border
)) {
1797 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1801 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1802 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1806 if (dimensions
> 1) {
1807 if (yoffset
< -((GLint
)destTex
->Border
)) {
1808 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1812 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1813 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1818 if (dimensions
> 2) {
1819 if (zoffset
< -((GLint
)destTex
->Border
)) {
1820 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1823 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1824 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1829 #if FEATURE_EXT_texture_sRGB
1830 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1831 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1832 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1833 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1834 if ((width
& 0x3) || (height
& 0x3) ||
1835 (xoffset
& 0x3) || (yoffset
& 0x3))
1836 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1837 "glTexSubImage%dD(size or offset not multiple of 4)",
1843 if (destTex
->IsCompressed
) {
1844 if (!target_can_be_compressed(ctx
, target
)) {
1845 _mesa_error(ctx
, GL_INVALID_ENUM
,
1846 "glTexSubImage%D(target)", dimensions
);
1849 /* offset must be multiple of 4 */
1850 if ((xoffset
& 3) || (yoffset
& 3)) {
1851 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1852 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1855 /* size must be multiple of 4 or equal to whole texture size */
1856 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1857 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1858 "glTexSubImage%D(width)", dimensions
);
1861 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1862 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1863 "glTexSubImage%D(width)", dimensions
);
1873 * Test glCopyTexImage[12]D() parameters for errors.
1875 * \param ctx GL context.
1876 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1877 * \param target texture target given by the user.
1878 * \param level image level given by the user.
1879 * \param internalFormat internal format given by the user.
1880 * \param width image width given by the user.
1881 * \param height image height given by the user.
1882 * \param depth image depth given by the user.
1883 * \param border texture border.
1885 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1887 * Verifies each of the parameters against the constants specified in
1888 * __GLcontextRec::Const and the supported extensions, and according to the
1889 * OpenGL specification.
1892 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1893 GLenum target
, GLint level
, GLint internalFormat
,
1894 GLint width
, GLint height
, GLint border
)
1900 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1901 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1902 _mesa_error(ctx
, GL_INVALID_VALUE
,
1903 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1907 /* Check that the source buffer is complete */
1908 if (ctx
->ReadBuffer
->Name
) {
1909 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1910 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1911 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1912 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1918 if (border
< 0 || border
> 1 ||
1919 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1920 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1924 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1926 _mesa_error(ctx
, GL_INVALID_VALUE
,
1927 "glCopyTexImage%dD(internalFormat)", dimensions
);
1931 /* NOTE: the format and type aren't really significant for
1932 * TestProxyTexImage(). Only the internalformat really matters.
1933 if (!_mesa_source_buffer_exists(ctx, format)) {
1934 _mesa_error(ctx, GL_INVALID_OPERATION,
1935 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1942 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1943 * level, width, height and depth.
1945 if (dimensions
== 1) {
1946 if (target
== GL_TEXTURE_1D
) {
1947 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1948 level
, internalFormat
,
1950 width
, 1, 1, border
);
1953 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1957 else if (dimensions
== 2) {
1958 if (target
== GL_TEXTURE_2D
) {
1959 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1960 level
, internalFormat
,
1962 width
, height
, 1, border
);
1964 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1965 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1966 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1967 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1970 sizeOK
= (width
== height
) &&
1971 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1972 level
, internalFormat
, format
, type
,
1973 width
, height
, 1, border
);
1975 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1976 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1977 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1980 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1981 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1982 level
, internalFormat
,
1984 width
, height
, 1, border
);
1986 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1987 if (!ctx
->Extensions
.MESA_texture_array
) {
1988 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1991 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1992 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1993 level
, internalFormat
,
1995 width
, height
, 1, border
);
1998 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
2003 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
2008 if (dimensions
== 1) {
2009 _mesa_error(ctx
, GL_INVALID_VALUE
,
2010 "glCopyTexImage1D(width=%d)", width
);
2013 ASSERT(dimensions
== 2);
2014 _mesa_error(ctx
, GL_INVALID_VALUE
,
2015 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2020 if (is_compressed_format(ctx
, internalFormat
)) {
2021 if (!target_can_be_compressed(ctx
, target
)) {
2022 _mesa_error(ctx
, GL_INVALID_ENUM
,
2023 "glCopyTexImage%d(target)", dimensions
);
2027 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2028 "glCopyTexImage%D(border!=0)", dimensions
);
2032 else if (is_depth_format(internalFormat
)) {
2033 /* make sure we have depth/stencil buffers */
2034 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2035 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2036 "glCopyTexImage%D(no depth)", dimensions
);
2040 else if (is_depthstencil_format(internalFormat
)) {
2041 /* make sure we have depth/stencil buffers */
2042 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2043 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2044 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2049 /* if we get here, the parameters are OK */
2055 * Test glCopyTexSubImage[12]D() parameters for errors.
2056 * Note that this is the first part of error checking.
2057 * See also copytexsubimage_error_check2() below for the second part.
2059 * \param ctx GL context.
2060 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2061 * \param target texture target given by the user.
2062 * \param level image level given by the user.
2064 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2067 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
2068 GLenum target
, GLint level
)
2070 /* Check that the source buffer is complete */
2071 if (ctx
->ReadBuffer
->Name
) {
2072 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2073 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2074 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2075 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2081 if (dimensions
== 1) {
2082 if (target
!= GL_TEXTURE_1D
) {
2083 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2087 else if (dimensions
== 2) {
2088 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2089 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2090 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2091 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2095 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2096 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2097 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2101 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2102 if (!ctx
->Extensions
.MESA_texture_array
) {
2103 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2107 else if (target
!= GL_TEXTURE_2D
) {
2108 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2112 else if (dimensions
== 3) {
2113 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2114 (!ctx
->Extensions
.MESA_texture_array
))
2115 && (target
!= GL_TEXTURE_3D
)) {
2116 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2122 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2123 _mesa_error(ctx
, GL_INVALID_VALUE
,
2124 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2133 * Second part of error checking for glCopyTexSubImage[12]D().
2134 * \param xoffset sub-image x offset given by the user.
2135 * \param yoffset sub-image y offset given by the user.
2136 * \param zoffset sub-image z offset given by the user.
2137 * \param width image width given by the user.
2138 * \param height image height given by the user.
2141 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2142 GLenum target
, GLint level
,
2143 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2144 GLsizei width
, GLsizei height
,
2145 const struct gl_texture_image
*teximage
)
2147 /* check that dest tex image exists */
2149 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2150 "glCopyTexSubImage%dD(undefined texture level: %d)",
2157 _mesa_error(ctx
, GL_INVALID_VALUE
,
2158 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2161 if (dimensions
> 1 && height
< 0) {
2162 _mesa_error(ctx
, GL_INVALID_VALUE
,
2163 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2167 /* check x/y offsets */
2168 if (xoffset
< -((GLint
)teximage
->Border
)) {
2169 _mesa_error(ctx
, GL_INVALID_VALUE
,
2170 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2173 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2174 _mesa_error(ctx
, GL_INVALID_VALUE
,
2175 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2178 if (dimensions
> 1) {
2179 if (yoffset
< -((GLint
)teximage
->Border
)) {
2180 _mesa_error(ctx
, GL_INVALID_VALUE
,
2181 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2184 /* NOTE: we're adding the border here, not subtracting! */
2185 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2186 _mesa_error(ctx
, GL_INVALID_VALUE
,
2187 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2192 /* check z offset */
2193 if (dimensions
> 2) {
2194 if (zoffset
< -((GLint
)teximage
->Border
)) {
2195 _mesa_error(ctx
, GL_INVALID_VALUE
,
2196 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2199 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2200 _mesa_error(ctx
, GL_INVALID_VALUE
,
2201 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2206 if (teximage
->IsCompressed
) {
2207 if (!target_can_be_compressed(ctx
, target
)) {
2208 _mesa_error(ctx
, GL_INVALID_ENUM
,
2209 "glCopyTexSubImage%d(target)", dimensions
);
2212 /* offset must be multiple of 4 */
2213 if ((xoffset
& 3) || (yoffset
& 3)) {
2214 _mesa_error(ctx
, GL_INVALID_VALUE
,
2215 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2218 /* size must be multiple of 4 */
2219 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2220 _mesa_error(ctx
, GL_INVALID_VALUE
,
2221 "glCopyTexSubImage%D(width)", dimensions
);
2224 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2225 _mesa_error(ctx
, GL_INVALID_VALUE
,
2226 "glCopyTexSubImage%D(height)", dimensions
);
2231 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2232 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2236 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2237 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2238 "glCopyTexSubImage%dD(missing readbuffer)", dimensions
);
2242 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2243 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2244 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2245 "glCopyTexSubImage%D(no depth buffer)",
2250 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2251 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2252 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2253 "glCopyTexSubImage%D(no depth/stencil buffer)",
2259 /* if we get here, the parameters are OK */
2265 * Get texture image. Called by glGetTexImage.
2267 * \param target texture target.
2268 * \param level image level.
2269 * \param format pixel data format for returned image.
2270 * \param type pixel data type for returned image.
2271 * \param pixels returned pixel data.
2274 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2275 GLenum type
, GLvoid
*pixels
)
2277 const struct gl_texture_unit
*texUnit
;
2278 struct gl_texture_object
*texObj
;
2279 struct gl_texture_image
*texImage
;
2280 GLint maxLevels
= 0;
2281 GET_CURRENT_CONTEXT(ctx
);
2282 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2284 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2285 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2286 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2287 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2291 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2292 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2294 if (level
< 0 || level
>= maxLevels
) {
2295 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2299 if (_mesa_sizeof_packed_type(type
) <= 0) {
2300 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2304 if (_mesa_components_in_format(format
) <= 0 ||
2305 format
== GL_STENCIL_INDEX
) {
2306 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2310 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2311 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2315 if (!ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2316 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2320 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2321 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2325 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2326 && is_depthstencil_format(format
)) {
2327 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2331 _mesa_lock_texture(ctx
, texObj
);
2333 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2335 /* invalid mipmap level, not an error */
2340 /* Make sure the requested image format is compatible with the
2341 * texture's format. Note that a color index texture can be converted
2342 * to RGBA so that combo is allowed.
2344 if (_mesa_is_color_format(format
)
2345 && !_mesa_is_color_format(texImage
->TexFormat
->BaseFormat
)
2346 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2347 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2350 else if (is_index_format(format
)
2351 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2352 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2355 else if (is_depth_format(format
)
2356 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2357 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2358 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2361 else if (is_ycbcr_format(format
)
2362 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2363 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2366 else if (is_depthstencil_format(format
)
2367 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2368 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2372 if (ctx
->Pack
.BufferObj
->Name
) {
2373 /* packing texture image into a PBO */
2374 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2375 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2376 texImage
->Height
, texImage
->Depth
,
2377 format
, type
, pixels
)) {
2378 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2379 "glGetTexImage(invalid PBO access)");
2384 /* typically, this will call _mesa_get_teximage() */
2385 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2390 _mesa_unlock_texture(ctx
, texObj
);
2396 * Check if the given texture image is bound to any framebuffer objects
2397 * and update/invalidate them.
2398 * XXX We're only checking the currently bound framebuffer object for now.
2399 * In the future, perhaps struct gl_texture_image should have a pointer (or
2400 * list of pointers (yikes)) to the gl_framebuffer(s) which it's bound to.
2403 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2404 GLuint face
, GLuint level
)
2406 if (ctx
->DrawBuffer
->Name
) {
2408 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2409 struct gl_renderbuffer_attachment
*att
=
2410 ctx
->DrawBuffer
->Attachment
+ i
;
2411 if (att
->Type
== GL_TEXTURE
&&
2412 att
->Texture
== texObj
&&
2413 att
->TextureLevel
== level
&&
2414 att
->CubeMapFace
== face
) {
2415 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2416 /* Tell driver about the new renderbuffer texture */
2417 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2426 * Called from the API. Note that width includes the border.
2429 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2430 GLsizei width
, GLint border
, GLenum format
,
2431 GLenum type
, const GLvoid
*pixels
)
2433 GLsizei postConvWidth
= width
;
2434 GET_CURRENT_CONTEXT(ctx
);
2435 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2437 #if FEATURE_convolve
2438 if (_mesa_is_color_format(internalFormat
)) {
2439 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2443 if (target
== GL_TEXTURE_1D
) {
2444 /* non-proxy target */
2445 struct gl_texture_unit
*texUnit
;
2446 struct gl_texture_object
*texObj
;
2447 struct gl_texture_image
*texImage
;
2448 const GLuint face
= _mesa_tex_target_to_face(target
);
2450 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2451 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2452 return; /* error was recorded */
2455 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2456 _mesa_update_state(ctx
);
2458 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2459 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2460 _mesa_lock_texture(ctx
, texObj
);
2462 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2464 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2468 if (texImage
->Data
) {
2469 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2472 ASSERT(texImage
->Data
== NULL
);
2474 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2475 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2476 postConvWidth
, 1, 1,
2477 border
, internalFormat
);
2479 ASSERT(ctx
->Driver
.TexImage1D
);
2481 /* Give the texture to the driver! <pixels> may be null! */
2482 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2483 width
, border
, format
, type
, pixels
,
2484 &ctx
->Unpack
, texObj
, texImage
);
2486 ASSERT(texImage
->TexFormat
);
2488 update_fbo_texture(ctx
, texObj
, face
, level
);
2491 texObj
->_Complete
= GL_FALSE
;
2492 ctx
->NewState
|= _NEW_TEXTURE
;
2495 _mesa_unlock_texture(ctx
, texObj
);
2497 else if (target
== GL_PROXY_TEXTURE_1D
) {
2498 /* Proxy texture: check for errors and update proxy state */
2499 struct gl_texture_image
*texImage
;
2500 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2501 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2502 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2503 /* when error, clear all proxy texture image parameters */
2505 clear_teximage_fields(texImage
);
2508 /* no error, set the tex image parameters */
2510 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2511 postConvWidth
, 1, 1,
2512 border
, internalFormat
);
2513 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2514 internalFormat
, format
, type
);
2518 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2525 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2526 GLsizei width
, GLsizei height
, GLint border
,
2527 GLenum format
, GLenum type
,
2528 const GLvoid
*pixels
)
2530 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2531 GET_CURRENT_CONTEXT(ctx
);
2532 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2534 #if FEATURE_convolve
2535 if (_mesa_is_color_format(internalFormat
)) {
2536 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2541 if (target
== GL_TEXTURE_2D
||
2542 (ctx
->Extensions
.ARB_texture_cube_map
&&
2543 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2544 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2545 (ctx
->Extensions
.NV_texture_rectangle
&&
2546 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2547 (ctx
->Extensions
.MESA_texture_array
&&
2548 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2549 /* non-proxy target */
2550 struct gl_texture_unit
*texUnit
;
2551 struct gl_texture_object
*texObj
;
2552 struct gl_texture_image
*texImage
;
2553 const GLuint face
= _mesa_tex_target_to_face(target
);
2555 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2556 format
, type
, 2, postConvWidth
, postConvHeight
,
2558 return; /* error was recorded */
2561 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2562 _mesa_update_state(ctx
);
2564 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2565 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2566 _mesa_lock_texture(ctx
, texObj
);
2568 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2570 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2574 if (texImage
->Data
) {
2575 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2578 ASSERT(texImage
->Data
== NULL
);
2579 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2580 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2581 postConvWidth
, postConvHeight
, 1,
2582 border
, internalFormat
);
2584 ASSERT(ctx
->Driver
.TexImage2D
);
2586 /* Give the texture to the driver! <pixels> may be null! */
2587 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2588 width
, height
, border
, format
, type
, pixels
,
2589 &ctx
->Unpack
, texObj
, texImage
);
2591 ASSERT(texImage
->TexFormat
);
2593 update_fbo_texture(ctx
, texObj
, face
, level
);
2596 texObj
->_Complete
= GL_FALSE
;
2597 ctx
->NewState
|= _NEW_TEXTURE
;
2600 _mesa_unlock_texture(ctx
, texObj
);
2602 else if (target
== GL_PROXY_TEXTURE_2D
||
2603 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2604 ctx
->Extensions
.ARB_texture_cube_map
) ||
2605 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2606 ctx
->Extensions
.NV_texture_rectangle
) ||
2607 (ctx
->Extensions
.MESA_texture_array
&&
2608 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2609 /* Proxy texture: check for errors and update proxy state */
2610 struct gl_texture_image
*texImage
;
2611 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2612 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2613 format
, type
, 2, postConvWidth
, postConvHeight
,
2615 /* when error, clear all proxy texture image parameters */
2617 clear_teximage_fields(ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
]);
2620 /* no error, set the tex image parameters */
2621 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2622 postConvWidth
, postConvHeight
, 1,
2623 border
, internalFormat
);
2624 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2625 internalFormat
, format
, type
);
2629 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2636 * Called by the API or display list executor.
2637 * Note that width and height include the border.
2640 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2641 GLsizei width
, GLsizei height
, GLsizei depth
,
2642 GLint border
, GLenum format
, GLenum type
,
2643 const GLvoid
*pixels
)
2645 GET_CURRENT_CONTEXT(ctx
);
2646 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2648 if (target
== GL_TEXTURE_3D
||
2649 (ctx
->Extensions
.MESA_texture_array
&&
2650 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2651 /* non-proxy target */
2652 struct gl_texture_unit
*texUnit
;
2653 struct gl_texture_object
*texObj
;
2654 struct gl_texture_image
*texImage
;
2655 const GLuint face
= _mesa_tex_target_to_face(target
);
2657 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2658 format
, type
, 3, width
, height
, depth
, border
)) {
2659 return; /* error was recorded */
2662 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2663 _mesa_update_state(ctx
);
2665 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2666 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2667 _mesa_lock_texture(ctx
, texObj
);
2669 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2671 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2675 if (texImage
->Data
) {
2676 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2679 ASSERT(texImage
->Data
== NULL
);
2680 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2681 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2682 width
, height
, depth
,
2683 border
, internalFormat
);
2685 ASSERT(ctx
->Driver
.TexImage3D
);
2687 /* Give the texture to the driver! <pixels> may be null! */
2688 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2689 width
, height
, depth
, border
, format
, type
,
2690 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2692 ASSERT(texImage
->TexFormat
);
2694 update_fbo_texture(ctx
, texObj
, face
, level
);
2697 texObj
->_Complete
= GL_FALSE
;
2698 ctx
->NewState
|= _NEW_TEXTURE
;
2701 _mesa_unlock_texture(ctx
, texObj
);
2703 else if (target
== GL_PROXY_TEXTURE_3D
||
2704 (ctx
->Extensions
.MESA_texture_array
&&
2705 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2706 /* Proxy texture: check for errors and update proxy state */
2707 struct gl_texture_image
*texImage
;
2708 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2709 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2710 format
, type
, 3, width
, height
, depth
, border
)) {
2711 /* when error, clear all proxy texture image parameters */
2713 clear_teximage_fields(texImage
);
2716 /* no error, set the tex image parameters */
2717 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2718 depth
, border
, internalFormat
);
2719 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2720 internalFormat
, format
, type
);
2724 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2731 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2732 GLsizei width
, GLsizei height
, GLsizei depth
,
2733 GLint border
, GLenum format
, GLenum type
,
2734 const GLvoid
*pixels
)
2736 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2737 depth
, border
, format
, type
, pixels
);
2743 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2744 GLint xoffset
, GLsizei width
,
2745 GLenum format
, GLenum type
,
2746 const GLvoid
*pixels
)
2748 GLsizei postConvWidth
= width
;
2749 struct gl_texture_unit
*texUnit
;
2750 struct gl_texture_object
*texObj
;
2751 struct gl_texture_image
*texImage
= NULL
;
2752 GET_CURRENT_CONTEXT(ctx
);
2753 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2755 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2756 _mesa_update_state(ctx
);
2758 #if FEATURE_convolve
2759 /* XXX should test internal format */
2760 if (_mesa_is_color_format(format
)) {
2761 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2765 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2766 postConvWidth
, 1, 1, format
, type
)) {
2767 return; /* error was detected */
2771 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2772 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2775 _mesa_lock_texture(ctx
, texObj
);
2777 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2779 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2780 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2781 goto out
; /* error was detected */
2785 goto out
; /* no-op, not an error */
2787 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2788 xoffset
+= texImage
->Border
;
2790 ASSERT(ctx
->Driver
.TexSubImage1D
);
2791 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2792 format
, type
, pixels
, &ctx
->Unpack
,
2794 ctx
->NewState
|= _NEW_TEXTURE
;
2797 _mesa_unlock_texture(ctx
, texObj
);
2802 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2803 GLint xoffset
, GLint yoffset
,
2804 GLsizei width
, GLsizei height
,
2805 GLenum format
, GLenum type
,
2806 const GLvoid
*pixels
)
2808 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2809 struct gl_texture_unit
*texUnit
;
2810 struct gl_texture_object
*texObj
;
2811 struct gl_texture_image
*texImage
;
2812 GET_CURRENT_CONTEXT(ctx
);
2813 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2815 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2816 _mesa_update_state(ctx
);
2818 #if FEATURE_convolve
2819 /* XXX should test internal format */
2820 if (_mesa_is_color_format(format
)) {
2821 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2826 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2827 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2828 return; /* error was detected */
2831 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2832 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2833 _mesa_lock_texture(ctx
, texObj
);
2835 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2837 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2838 postConvWidth
, postConvHeight
, 1, format
, type
,
2840 goto out
; /* error was detected */
2843 if (width
== 0 || height
== 0)
2844 goto out
; /* no-op, not an error */
2846 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2847 xoffset
+= texImage
->Border
;
2848 yoffset
+= texImage
->Border
;
2850 ASSERT(ctx
->Driver
.TexSubImage2D
);
2851 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2852 width
, height
, format
, type
, pixels
,
2853 &ctx
->Unpack
, texObj
, texImage
);
2854 ctx
->NewState
|= _NEW_TEXTURE
;
2857 _mesa_unlock_texture(ctx
, texObj
);
2863 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2864 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2865 GLsizei width
, GLsizei height
, GLsizei depth
,
2866 GLenum format
, GLenum type
,
2867 const GLvoid
*pixels
)
2869 struct gl_texture_unit
*texUnit
;
2870 struct gl_texture_object
*texObj
;
2871 struct gl_texture_image
*texImage
;
2872 GET_CURRENT_CONTEXT(ctx
);
2873 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2875 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2876 _mesa_update_state(ctx
);
2878 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2879 width
, height
, depth
, format
, type
)) {
2880 return; /* error was detected */
2883 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2884 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2886 _mesa_lock_texture(ctx
, texObj
);
2888 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2890 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2891 width
, height
, depth
, format
, type
, texImage
)) {
2892 goto out
; /* error was detected */
2895 if (width
== 0 || height
== 0 || height
== 0)
2896 goto out
; /* no-op, not an error */
2898 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2899 xoffset
+= texImage
->Border
;
2900 yoffset
+= texImage
->Border
;
2901 zoffset
+= texImage
->Border
;
2903 ASSERT(ctx
->Driver
.TexSubImage3D
);
2904 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2905 xoffset
, yoffset
, zoffset
,
2906 width
, height
, depth
,
2907 format
, type
, pixels
,
2908 &ctx
->Unpack
, texObj
, texImage
);
2909 ctx
->NewState
|= _NEW_TEXTURE
;
2912 _mesa_unlock_texture(ctx
, texObj
);
2918 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2919 GLenum internalFormat
,
2921 GLsizei width
, GLint border
)
2923 struct gl_texture_unit
*texUnit
;
2924 struct gl_texture_object
*texObj
;
2925 struct gl_texture_image
*texImage
;
2926 GLsizei postConvWidth
= width
;
2927 const GLuint face
= _mesa_tex_target_to_face(target
);
2928 GET_CURRENT_CONTEXT(ctx
);
2929 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2931 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2932 _mesa_update_state(ctx
);
2934 #if FEATURE_convolve
2935 if (_mesa_is_color_format(internalFormat
)) {
2936 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2940 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2941 postConvWidth
, 1, border
))
2944 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2945 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2946 _mesa_lock_texture(ctx
, texObj
);
2948 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2950 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2954 if (texImage
->Data
) {
2955 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2958 ASSERT(texImage
->Data
== NULL
);
2960 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2961 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2962 border
, internalFormat
);
2965 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2966 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2967 x
, y
, width
, border
);
2969 ASSERT(texImage
->TexFormat
);
2971 update_fbo_texture(ctx
, texObj
, face
, level
);
2974 texObj
->_Complete
= GL_FALSE
;
2975 ctx
->NewState
|= _NEW_TEXTURE
;
2978 _mesa_unlock_texture(ctx
, texObj
);
2984 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2985 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2988 struct gl_texture_unit
*texUnit
;
2989 struct gl_texture_object
*texObj
;
2990 struct gl_texture_image
*texImage
;
2991 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2992 const GLuint face
= _mesa_tex_target_to_face(target
);
2993 GET_CURRENT_CONTEXT(ctx
);
2994 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2996 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2997 _mesa_update_state(ctx
);
2999 #if FEATURE_convolve
3000 if (_mesa_is_color_format(internalFormat
)) {
3001 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
3006 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
3007 postConvWidth
, postConvHeight
, border
))
3010 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3011 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3013 _mesa_lock_texture(ctx
, texObj
);
3015 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3018 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3022 if (texImage
->Data
) {
3023 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3026 ASSERT(texImage
->Data
== NULL
);
3028 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3029 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3030 postConvWidth
, postConvHeight
, 1,
3031 border
, internalFormat
);
3033 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3034 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3035 x
, y
, width
, height
, border
);
3037 ASSERT(texImage
->TexFormat
);
3039 update_fbo_texture(ctx
, texObj
, face
, level
);
3042 texObj
->_Complete
= GL_FALSE
;
3043 ctx
->NewState
|= _NEW_TEXTURE
;
3046 _mesa_unlock_texture(ctx
, texObj
);
3051 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3052 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3054 struct gl_texture_unit
*texUnit
;
3055 struct gl_texture_object
*texObj
;
3056 struct gl_texture_image
*texImage
;
3057 GLsizei postConvWidth
= width
;
3061 GET_CURRENT_CONTEXT(ctx
);
3062 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3064 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3065 _mesa_update_state(ctx
);
3067 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3070 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3071 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3073 _mesa_lock_texture(ctx
, texObj
);
3075 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3077 #if FEATURE_convolve
3078 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3079 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3083 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3084 xoffset
, 0, 0, postConvWidth
, 1,
3089 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3090 xoffset
+= texImage
->Border
;
3092 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3094 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3095 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3096 xoffset
, x
, y
, width
);
3099 ctx
->NewState
|= _NEW_TEXTURE
;
3102 _mesa_unlock_texture(ctx
, texObj
);
3108 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3109 GLint xoffset
, GLint yoffset
,
3110 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3112 struct gl_texture_unit
*texUnit
;
3113 struct gl_texture_object
*texObj
;
3114 struct gl_texture_image
*texImage
;
3115 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3116 GET_CURRENT_CONTEXT(ctx
);
3117 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3119 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3120 _mesa_update_state(ctx
);
3122 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3125 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3126 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3128 _mesa_lock_texture(ctx
, texObj
);
3130 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3132 #if FEATURE_convolve
3133 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3134 _mesa_adjust_image_for_convolution(ctx
, 2,
3135 &postConvWidth
, &postConvHeight
);
3139 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3140 postConvWidth
, postConvHeight
, texImage
))
3143 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3144 xoffset
+= texImage
->Border
;
3145 yoffset
+= texImage
->Border
;
3147 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3149 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3150 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3151 xoffset
, yoffset
, x
, y
, width
, height
);
3154 ctx
->NewState
|= _NEW_TEXTURE
;
3157 _mesa_unlock_texture(ctx
, texObj
);
3163 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3164 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3165 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3167 struct gl_texture_unit
*texUnit
;
3168 struct gl_texture_object
*texObj
;
3169 struct gl_texture_image
*texImage
;
3170 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3171 GET_CURRENT_CONTEXT(ctx
);
3172 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3174 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3175 _mesa_update_state(ctx
);
3177 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3180 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3181 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3183 _mesa_lock_texture(ctx
, texObj
);
3185 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3187 #if FEATURE_convolve
3188 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3189 _mesa_adjust_image_for_convolution(ctx
, 2,
3190 &postConvWidth
, &postConvHeight
);
3194 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3195 zoffset
, postConvWidth
, postConvHeight
,
3199 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3200 xoffset
+= texImage
->Border
;
3201 yoffset
+= texImage
->Border
;
3202 zoffset
+= texImage
->Border
;
3204 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3206 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3207 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3208 xoffset
, yoffset
, zoffset
,
3209 x
, y
, width
, height
);
3212 ctx
->NewState
|= _NEW_TEXTURE
;
3215 _mesa_unlock_texture(ctx
, texObj
);
3221 /**********************************************************************/
3222 /****** Compressed Textures ******/
3223 /**********************************************************************/
3227 * Error checking for glCompressedTexImage[123]D().
3228 * \return error code or GL_NO_ERROR.
3231 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3232 GLenum target
, GLint level
,
3233 GLenum internalFormat
, GLsizei width
,
3234 GLsizei height
, GLsizei depth
, GLint border
,
3237 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3239 if (dimensions
== 1) {
3240 /* 1D compressed textures not allowed */
3241 return GL_INVALID_ENUM
;
3243 else if (dimensions
== 2) {
3244 if (target
== GL_PROXY_TEXTURE_2D
) {
3245 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3247 else if (target
== GL_TEXTURE_2D
) {
3248 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3250 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3251 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3252 return GL_INVALID_ENUM
; /*target*/
3253 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3255 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3256 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3257 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3258 return GL_INVALID_ENUM
; /*target*/
3259 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3262 return GL_INVALID_ENUM
; /*target*/
3265 else if (dimensions
== 3) {
3266 /* 3D compressed textures not allowed */
3267 return GL_INVALID_ENUM
;
3270 maxTextureSize
= 1 << (maxLevels
- 1);
3272 /* This will detect any invalid internalFormat value */
3273 if (!is_compressed_format(ctx
, internalFormat
))
3274 return GL_INVALID_ENUM
;
3276 /* This should really never fail */
3277 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3278 return GL_INVALID_ENUM
;
3281 return GL_INVALID_VALUE
;
3284 * XXX We should probably use the proxy texture error check function here.
3286 if (width
< 1 || width
> maxTextureSize
||
3287 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3288 return GL_INVALID_VALUE
;
3290 if ((height
< 1 || height
> maxTextureSize
||
3291 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3293 return GL_INVALID_VALUE
;
3295 if ((depth
< 1 || depth
> maxTextureSize
||
3296 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3298 return GL_INVALID_VALUE
;
3300 /* For cube map, width must equal height */
3301 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3302 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3303 return GL_INVALID_VALUE
;
3305 if (level
< 0 || level
>= maxLevels
)
3306 return GL_INVALID_VALUE
;
3308 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3309 depth
, internalFormat
);
3310 if (expectedSize
!= imageSize
)
3311 return GL_INVALID_VALUE
;
3313 #if FEATURE_EXT_texture_sRGB
3314 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3315 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3316 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3317 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3319 return GL_INVALID_OPERATION
;
3328 * Error checking for glCompressedTexSubImage[123]D().
3329 * \warning There are some bad assumptions here about the size of compressed
3330 * texture tiles (multiple of 4) used to test the validity of the
3331 * offset and size parameters.
3332 * \return error code or GL_NO_ERROR.
3335 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3336 GLenum target
, GLint level
,
3337 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3338 GLsizei width
, GLsizei height
, GLsizei depth
,
3339 GLenum format
, GLsizei imageSize
)
3341 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3344 if (dimensions
== 1) {
3345 /* 1D compressed textures not allowed */
3346 return GL_INVALID_ENUM
;
3348 else if (dimensions
== 2) {
3349 if (target
== GL_PROXY_TEXTURE_2D
) {
3350 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3352 else if (target
== GL_TEXTURE_2D
) {
3353 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3355 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3356 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3357 return GL_INVALID_ENUM
; /*target*/
3358 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3360 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3361 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3362 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3363 return GL_INVALID_ENUM
; /*target*/
3364 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3367 return GL_INVALID_ENUM
; /*target*/
3370 else if (dimensions
== 3) {
3371 /* 3D compressed textures not allowed */
3372 return GL_INVALID_ENUM
;
3375 maxTextureSize
= 1 << (maxLevels
- 1);
3377 /* this will catch any invalid compressed format token */
3378 if (!is_compressed_format(ctx
, format
))
3379 return GL_INVALID_ENUM
;
3381 if (width
< 1 || width
> maxTextureSize
)
3382 return GL_INVALID_VALUE
;
3384 if ((height
< 1 || height
> maxTextureSize
)
3386 return GL_INVALID_VALUE
;
3388 if (level
< 0 || level
>= maxLevels
)
3389 return GL_INVALID_VALUE
;
3391 /* XXX these tests are specific to the compressed format.
3392 * this code should be generalized in some way.
3394 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3395 return GL_INVALID_VALUE
;
3397 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3398 return GL_INVALID_VALUE
;
3400 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3401 return GL_INVALID_VALUE
;
3403 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3405 if (expectedSize
!= imageSize
)
3406 return GL_INVALID_VALUE
;
3414 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3415 GLenum internalFormat
, GLsizei width
,
3416 GLint border
, GLsizei imageSize
,
3419 GET_CURRENT_CONTEXT(ctx
);
3420 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3422 if (target
== GL_TEXTURE_1D
) {
3423 /* non-proxy target */
3424 struct gl_texture_unit
*texUnit
;
3425 struct gl_texture_object
*texObj
;
3426 struct gl_texture_image
*texImage
;
3427 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3428 internalFormat
, width
, 1, 1, border
, imageSize
);
3430 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3434 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3435 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3437 _mesa_lock_texture(ctx
, texObj
);
3439 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3441 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3445 if (texImage
->Data
) {
3446 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3448 ASSERT(texImage
->Data
== NULL
);
3450 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3451 border
, internalFormat
);
3453 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3454 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3455 internalFormat
, width
, border
,
3460 texObj
->_Complete
= GL_FALSE
;
3461 ctx
->NewState
|= _NEW_TEXTURE
;
3464 _mesa_unlock_texture(ctx
, texObj
);
3466 else if (target
== GL_PROXY_TEXTURE_1D
) {
3467 /* Proxy texture: check for errors and update proxy state */
3468 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3469 internalFormat
, width
, 1, 1, border
, imageSize
);
3471 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3472 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3473 internalFormat
, GL_NONE
, GL_NONE
,
3474 width
, 1, 1, border
);
3477 /* if error, clear all proxy texture image parameters */
3478 struct gl_texture_image
*texImage
;
3479 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3481 clear_teximage_fields(texImage
);
3484 /* store the teximage parameters */
3485 struct gl_texture_unit
*texUnit
;
3486 struct gl_texture_object
*texObj
;
3487 struct gl_texture_image
*texImage
;
3488 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3489 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3491 _mesa_lock_texture(ctx
, texObj
);
3493 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3494 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3495 border
, internalFormat
);
3497 _mesa_unlock_texture(ctx
, texObj
);
3501 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3508 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3509 GLenum internalFormat
, GLsizei width
,
3510 GLsizei height
, GLint border
, GLsizei imageSize
,
3513 GET_CURRENT_CONTEXT(ctx
);
3514 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3516 if (target
== GL_TEXTURE_2D
||
3517 (ctx
->Extensions
.ARB_texture_cube_map
&&
3518 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3519 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3520 /* non-proxy target */
3521 struct gl_texture_unit
*texUnit
;
3522 struct gl_texture_object
*texObj
;
3523 struct gl_texture_image
*texImage
;
3524 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3525 internalFormat
, width
, height
, 1, border
, imageSize
);
3527 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3531 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3532 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3534 _mesa_lock_texture(ctx
, texObj
);
3536 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3538 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3542 if (texImage
->Data
) {
3543 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3545 ASSERT(texImage
->Data
== NULL
);
3547 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3548 border
, internalFormat
);
3550 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3551 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3552 internalFormat
, width
, height
,
3553 border
, imageSize
, data
,
3557 texObj
->_Complete
= GL_FALSE
;
3558 ctx
->NewState
|= _NEW_TEXTURE
;
3561 _mesa_unlock_texture(ctx
, texObj
);
3563 else if (target
== GL_PROXY_TEXTURE_2D
||
3564 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3565 ctx
->Extensions
.ARB_texture_cube_map
)) {
3566 /* Proxy texture: check for errors and update proxy state */
3567 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3568 internalFormat
, width
, height
, 1, border
, imageSize
);
3570 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3571 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3572 internalFormat
, GL_NONE
, GL_NONE
,
3573 width
, height
, 1, border
);
3576 /* if error, clear all proxy texture image parameters */
3577 struct gl_texture_image
*texImage
;
3578 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3580 clear_teximage_fields(texImage
);
3583 /* store the teximage parameters */
3584 struct gl_texture_unit
*texUnit
;
3585 struct gl_texture_object
*texObj
;
3586 struct gl_texture_image
*texImage
;
3587 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3588 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3590 _mesa_lock_texture(ctx
, texObj
);
3592 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3593 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3594 border
, internalFormat
);
3596 _mesa_unlock_texture(ctx
, texObj
);
3600 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3607 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3608 GLenum internalFormat
, GLsizei width
,
3609 GLsizei height
, GLsizei depth
, GLint border
,
3610 GLsizei imageSize
, const GLvoid
*data
)
3612 GET_CURRENT_CONTEXT(ctx
);
3613 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3615 if (target
== GL_TEXTURE_3D
) {
3616 /* non-proxy target */
3617 struct gl_texture_unit
*texUnit
;
3618 struct gl_texture_object
*texObj
;
3619 struct gl_texture_image
*texImage
;
3620 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3621 internalFormat
, width
, height
, depth
, border
, imageSize
);
3623 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3627 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3628 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3629 _mesa_lock_texture(ctx
, texObj
);
3631 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3633 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3637 if (texImage
->Data
) {
3638 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3640 ASSERT(texImage
->Data
== NULL
);
3642 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3643 border
, internalFormat
);
3645 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3646 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3648 width
, height
, depth
,
3649 border
, imageSize
, data
,
3653 texObj
->_Complete
= GL_FALSE
;
3654 ctx
->NewState
|= _NEW_TEXTURE
;
3657 _mesa_unlock_texture(ctx
, texObj
);
3659 else if (target
== GL_PROXY_TEXTURE_3D
) {
3660 /* Proxy texture: check for errors and update proxy state */
3661 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3662 internalFormat
, width
, height
, depth
, border
, imageSize
);
3664 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3665 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3666 internalFormat
, GL_NONE
, GL_NONE
,
3667 width
, height
, depth
, border
);
3670 /* if error, clear all proxy texture image parameters */
3671 struct gl_texture_image
*texImage
;
3672 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3674 clear_teximage_fields(texImage
);
3677 /* store the teximage parameters */
3678 struct gl_texture_unit
*texUnit
;
3679 struct gl_texture_object
*texObj
;
3680 struct gl_texture_image
*texImage
;
3681 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3682 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3683 _mesa_lock_texture(ctx
, texObj
);
3685 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3686 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3687 depth
, border
, internalFormat
);
3689 _mesa_unlock_texture(ctx
, texObj
);
3693 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3700 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3701 GLsizei width
, GLenum format
,
3702 GLsizei imageSize
, const GLvoid
*data
)
3704 struct gl_texture_unit
*texUnit
;
3705 struct gl_texture_object
*texObj
;
3706 struct gl_texture_image
*texImage
;
3708 GET_CURRENT_CONTEXT(ctx
);
3709 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3711 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3712 xoffset
, 0, 0, /* pos */
3713 width
, 1, 1, /* size */
3716 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3720 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3721 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3722 _mesa_lock_texture(ctx
, texObj
);
3724 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3727 if ((GLint
) format
!= texImage
->InternalFormat
) {
3728 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3729 "glCompressedTexSubImage1D(format)");
3733 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3734 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3739 goto out
; /* no-op, not an error */
3741 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3742 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3744 format
, imageSize
, data
,
3747 ctx
->NewState
|= _NEW_TEXTURE
;
3750 _mesa_unlock_texture(ctx
, texObj
);
3755 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3756 GLint yoffset
, GLsizei width
, GLsizei height
,
3757 GLenum format
, GLsizei imageSize
,
3760 struct gl_texture_unit
*texUnit
;
3761 struct gl_texture_object
*texObj
;
3762 struct gl_texture_image
*texImage
;
3764 GET_CURRENT_CONTEXT(ctx
);
3765 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3767 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3768 xoffset
, yoffset
, 0, /* pos */
3769 width
, height
, 1, /* size */
3772 /* XXX proxy target? */
3773 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3777 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3778 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3779 _mesa_lock_texture(ctx
, texObj
);
3781 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3784 if ((GLint
) format
!= texImage
->InternalFormat
) {
3785 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3786 "glCompressedTexSubImage2D(format)");
3790 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3791 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3792 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3796 if (width
== 0 || height
== 0)
3797 goto out
; /* no-op, not an error */
3799 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3800 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3801 xoffset
, yoffset
, width
, height
,
3802 format
, imageSize
, data
,
3805 ctx
->NewState
|= _NEW_TEXTURE
;
3808 _mesa_unlock_texture(ctx
, texObj
);
3813 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3814 GLint yoffset
, GLint zoffset
, GLsizei width
,
3815 GLsizei height
, GLsizei depth
, GLenum format
,
3816 GLsizei imageSize
, const GLvoid
*data
)
3818 struct gl_texture_unit
*texUnit
;
3819 struct gl_texture_object
*texObj
;
3820 struct gl_texture_image
*texImage
;
3822 GET_CURRENT_CONTEXT(ctx
);
3823 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3825 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3826 xoffset
, yoffset
, zoffset
,/*pos*/
3827 width
, height
, depth
, /*size*/
3830 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3834 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3835 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3836 _mesa_lock_texture(ctx
, texObj
);
3838 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3841 if ((GLint
) format
!= texImage
->InternalFormat
) {
3842 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3843 "glCompressedTexSubImage3D(format)");
3847 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3848 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3849 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3850 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3854 if (width
== 0 || height
== 0 || depth
== 0)
3855 goto out
; /* no-op, not an error */
3857 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3858 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3859 xoffset
, yoffset
, zoffset
,
3860 width
, height
, depth
,
3861 format
, imageSize
, data
,
3864 ctx
->NewState
|= _NEW_TEXTURE
;
3867 _mesa_unlock_texture(ctx
, texObj
);
3872 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3874 const struct gl_texture_unit
*texUnit
;
3875 struct gl_texture_object
*texObj
;
3876 struct gl_texture_image
*texImage
;
3878 GET_CURRENT_CONTEXT(ctx
);
3879 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3881 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3882 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3884 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3888 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3889 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3891 if (level
< 0 || level
>= maxLevels
) {
3892 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3896 if (_mesa_is_proxy_texture(target
)) {
3897 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3901 _mesa_lock_texture(ctx
, texObj
);
3903 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3905 if (texImage
->IsCompressed
) {
3906 /* this typically calls _mesa_get_compressed_teximage() */
3907 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3911 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3912 "glGetCompressedTexImageARB");
3916 /* probably invalid mipmap level */
3917 _mesa_error(ctx
, GL_INVALID_VALUE
,
3918 "glGetCompressedTexImageARB(level)");
3921 _mesa_unlock_texture(ctx
, texObj
);