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.
393 is_color_format(GLenum format
)
411 case GL_LUMINANCE_ALPHA
:
412 case GL_LUMINANCE4_ALPHA4
:
413 case GL_LUMINANCE6_ALPHA2
:
414 case GL_LUMINANCE8_ALPHA8
:
415 case GL_LUMINANCE12_ALPHA4
:
416 case GL_LUMINANCE12_ALPHA12
:
417 case GL_LUMINANCE16_ALPHA16
:
444 /* float texture formats */
445 case GL_ALPHA16F_ARB
:
446 case GL_ALPHA32F_ARB
:
447 case GL_LUMINANCE16F_ARB
:
448 case GL_LUMINANCE32F_ARB
:
449 case GL_LUMINANCE_ALPHA16F_ARB
:
450 case GL_LUMINANCE_ALPHA32F_ARB
:
451 case GL_INTENSITY16F_ARB
:
452 case GL_INTENSITY32F_ARB
:
457 /* compressed formats */
458 case GL_COMPRESSED_ALPHA
:
459 case GL_COMPRESSED_LUMINANCE
:
460 case GL_COMPRESSED_LUMINANCE_ALPHA
:
461 case GL_COMPRESSED_INTENSITY
:
462 case GL_COMPRESSED_RGB
:
463 case GL_COMPRESSED_RGBA
:
468 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
469 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
470 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
471 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
472 case GL_COMPRESSED_RGB_FXT1_3DFX
:
473 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
474 #if FEATURE_EXT_texture_sRGB
477 case GL_SRGB_ALPHA_EXT
:
478 case GL_SRGB8_ALPHA8_EXT
:
479 case GL_SLUMINANCE_ALPHA_EXT
:
480 case GL_SLUMINANCE8_ALPHA8_EXT
:
481 case GL_SLUMINANCE_EXT
:
482 case GL_SLUMINANCE8_EXT
:
483 case GL_COMPRESSED_SRGB_EXT
:
484 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
485 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
486 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
487 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
488 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
489 case GL_COMPRESSED_SLUMINANCE_EXT
:
490 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
491 #endif /* FEATURE_EXT_texture_sRGB */
493 case GL_YCBCR_MESA
: /* not considered to be RGB */
501 * Test if the given image format is a color index format.
504 is_index_format(GLenum format
)
508 case GL_COLOR_INDEX1_EXT
:
509 case GL_COLOR_INDEX2_EXT
:
510 case GL_COLOR_INDEX4_EXT
:
511 case GL_COLOR_INDEX8_EXT
:
512 case GL_COLOR_INDEX12_EXT
:
513 case GL_COLOR_INDEX16_EXT
:
522 * Test if the given image format is a depth component format.
525 is_depth_format(GLenum format
)
528 case GL_DEPTH_COMPONENT16
:
529 case GL_DEPTH_COMPONENT24
:
530 case GL_DEPTH_COMPONENT32
:
531 case GL_DEPTH_COMPONENT
:
540 * Test if the given image format is a YCbCr format.
543 is_ycbcr_format(GLenum format
)
555 * Test if the given image format is a Depth/Stencil format.
558 is_depthstencil_format(GLenum format
)
561 case GL_DEPTH24_STENCIL8_EXT
:
562 case GL_DEPTH_STENCIL_EXT
:
572 * Test if it is a supported compressed format.
574 * \param internalFormat the internal format token provided by the user.
576 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
577 * GL_FALSE otherwise.
579 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
583 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
585 GLint supported
[100]; /* 100 should be plenty */
588 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
590 for (i
= 0; i
< n
; i
++) {
591 if ((GLint
) internalFormat
== supported
[i
]) {
600 * For cube map faces, return a face index in [0,5].
601 * For other targets return 0;
604 _mesa_tex_target_to_face(GLenum target
)
606 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
607 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
608 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
616 * Store a gl_texture_image pointer in a gl_texture_object structure
617 * according to the target and level parameters.
619 * \param tObj texture object.
620 * \param target texture target.
621 * \param level image level.
622 * \param texImage texture image.
624 * This was basically prompted by the introduction of cube maps.
627 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
628 GLenum target
, GLint level
,
629 struct gl_texture_image
*texImage
)
633 /* XXX simplify this with _mesa_tex_target_to_face() */
638 case GL_TEXTURE_1D_ARRAY_EXT
:
639 case GL_TEXTURE_2D_ARRAY_EXT
:
640 tObj
->Image
[0][level
] = texImage
;
642 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
643 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
644 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
645 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
646 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
647 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
649 GLuint face
= ((GLuint
) target
-
650 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
651 tObj
->Image
[face
][level
] = texImage
;
654 case GL_TEXTURE_RECTANGLE_NV
:
656 tObj
->Image
[0][level
] = texImage
;
659 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
662 /* Set the 'back' pointer */
663 texImage
->TexObject
= tObj
;
668 * Allocate a texture image structure.
670 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
673 * \return a pointer to gl_texture_image struct with all fields initialized to
676 struct gl_texture_image
*
677 _mesa_new_texture_image( GLcontext
*ctx
)
680 return CALLOC_STRUCT(gl_texture_image
);
685 * Free texture image data.
686 * This function is a fallback called via ctx->Driver.FreeTexImageData().
688 * \param teximage texture image.
690 * Free the texture image data if it's not marked as client data.
693 _mesa_free_texture_image_data(GLcontext
*ctx
,
694 struct gl_texture_image
*texImage
)
698 if (texImage
->Data
&& !texImage
->IsClientData
) {
699 /* free the old texture data */
700 _mesa_free_texmemory(texImage
->Data
);
703 texImage
->Data
= NULL
;
708 * Free texture image.
710 * \param teximage texture image.
712 * Free the texture image structure and the associated image data.
715 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
717 /* Free texImage->Data and/or any other driver-specific texture
720 ASSERT(ctx
->Driver
.FreeTexImageData
);
721 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
723 ASSERT(texImage
->Data
== NULL
);
724 if (texImage
->ImageOffsets
)
725 _mesa_free(texImage
->ImageOffsets
);
726 _mesa_free(texImage
);
731 * Test if a target is a proxy target.
733 * \param target texture target.
735 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
738 _mesa_is_proxy_texture(GLenum target
)
740 return (target
== GL_PROXY_TEXTURE_1D
||
741 target
== GL_PROXY_TEXTURE_2D
||
742 target
== GL_PROXY_TEXTURE_3D
||
743 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
744 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
745 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
746 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
751 * Get the texture object that corresponds to the target of the given texture unit.
753 * \param ctx GL context.
754 * \param texUnit texture unit.
755 * \param target texture target.
757 * \return pointer to the texture object on success, or NULL on failure.
759 * \sa gl_texture_unit.
761 struct gl_texture_object
*
762 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
767 return texUnit
->Current1D
;
768 case GL_PROXY_TEXTURE_1D
:
769 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
771 return texUnit
->Current2D
;
772 case GL_PROXY_TEXTURE_2D
:
773 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
775 return texUnit
->Current3D
;
776 case GL_PROXY_TEXTURE_3D
:
777 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
778 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
779 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
780 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
781 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
782 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
783 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
784 case GL_TEXTURE_CUBE_MAP_ARB
:
785 return ctx
->Extensions
.ARB_texture_cube_map
786 ? texUnit
->CurrentCubeMap
: NULL
;
787 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
788 return ctx
->Extensions
.ARB_texture_cube_map
789 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
790 case GL_TEXTURE_RECTANGLE_NV
:
791 return ctx
->Extensions
.NV_texture_rectangle
792 ? texUnit
->CurrentRect
: NULL
;
793 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
794 return ctx
->Extensions
.NV_texture_rectangle
795 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
796 case GL_TEXTURE_1D_ARRAY_EXT
:
797 return ctx
->Extensions
.MESA_texture_array
798 ? texUnit
->Current1DArray
: NULL
;
799 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
800 return ctx
->Extensions
.MESA_texture_array
801 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
802 case GL_TEXTURE_2D_ARRAY_EXT
:
803 return ctx
->Extensions
.MESA_texture_array
804 ? texUnit
->Current2DArray
: NULL
;
805 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
806 return ctx
->Extensions
.MESA_texture_array
807 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
809 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
816 * Get the texture image struct which corresponds to target and level
817 * of the given texture unit.
819 * \param ctx GL context.
820 * \param texUnit texture unit.
821 * \param target texture target.
822 * \param level image level.
824 * \return pointer to the texture image structure on success, or NULL on failure.
826 * \sa gl_texture_unit.
828 struct gl_texture_image
*
829 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
830 GLenum target
, GLint level
)
834 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
)
837 /* XXX simplify this with _mesa_tex_target_to_face() */
840 case GL_PROXY_TEXTURE_1D
:
842 case GL_PROXY_TEXTURE_2D
:
844 case GL_PROXY_TEXTURE_3D
:
845 return texObj
->Image
[0][level
];
847 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
848 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
849 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
850 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
851 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
852 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
853 if (ctx
->Extensions
.ARB_texture_cube_map
) {
854 GLuint face
= ((GLuint
) target
-
855 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
856 return texObj
->Image
[face
][level
];
861 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
862 if (ctx
->Extensions
.ARB_texture_cube_map
)
863 return texObj
->Image
[0][level
];
867 case GL_TEXTURE_RECTANGLE_NV
:
868 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
869 if (ctx
->Extensions
.NV_texture_rectangle
&& level
== 0)
870 return texObj
->Image
[0][level
];
874 case GL_TEXTURE_1D_ARRAY_EXT
:
875 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
876 case GL_TEXTURE_2D_ARRAY_EXT
:
877 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
878 return (ctx
->Extensions
.MESA_texture_array
)
879 ? texObj
->Image
[0][level
] : NULL
;
888 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
889 * it and install it. Only return NULL if passed a bad parameter or run
892 struct gl_texture_image
*
893 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
894 GLenum target
, GLint level
)
896 struct gl_texture_image
*texImage
;
901 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
903 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
905 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
909 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
917 * Return pointer to the specified proxy texture image.
918 * Note that proxy textures are per-context, not per-texture unit.
919 * \return pointer to texture image or NULL if invalid target, invalid
920 * level, or out of memory.
922 struct gl_texture_image
*
923 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
925 struct gl_texture_image
*texImage
;
931 case GL_PROXY_TEXTURE_1D
:
932 if (level
>= ctx
->Const
.MaxTextureLevels
)
934 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
]->Image
[0][level
];
936 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
938 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
941 ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
]->Image
[0][level
] = texImage
;
942 /* Set the 'back' pointer */
943 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
946 case GL_PROXY_TEXTURE_2D
:
947 if (level
>= ctx
->Const
.MaxTextureLevels
)
949 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
];
951 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
953 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
956 ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
] = texImage
;
957 /* Set the 'back' pointer */
958 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
961 case GL_PROXY_TEXTURE_3D
:
962 if (level
>= ctx
->Const
.Max3DTextureLevels
)
964 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
]->Image
[0][level
];
966 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
968 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
971 ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
]->Image
[0][level
] = texImage
;
972 /* Set the 'back' pointer */
973 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
976 case GL_PROXY_TEXTURE_CUBE_MAP
:
977 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
979 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
]->Image
[0][level
];
981 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
983 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
986 ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
]->Image
[0][level
] = texImage
;
987 /* Set the 'back' pointer */
988 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
];
991 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
994 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
]->Image
[0][level
];
996 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
998 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1001 ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
]->Image
[0][level
] = texImage
;
1002 /* Set the 'back' pointer */
1003 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
];
1006 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1007 if (level
>= ctx
->Const
.MaxTextureLevels
)
1009 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
]->Image
[0][level
];
1011 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1013 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1016 ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
]->Image
[0][level
] = texImage
;
1017 /* Set the 'back' pointer */
1018 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
];
1021 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1022 if (level
>= ctx
->Const
.MaxTextureLevels
)
1024 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
]->Image
[0][level
];
1026 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1028 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1031 ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
]->Image
[0][level
] = texImage
;
1032 /* Set the 'back' pointer */
1033 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
];
1043 * Get the maximum number of allowed mipmap levels.
1045 * \param ctx GL context.
1046 * \param target texture target.
1048 * \return the maximum number of allowed mipmap levels for the given
1049 * texture target, or zero if passed a bad target.
1054 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
1058 case GL_PROXY_TEXTURE_1D
:
1060 case GL_PROXY_TEXTURE_2D
:
1061 case GL_TEXTURE_1D_ARRAY_EXT
:
1062 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1063 case GL_TEXTURE_2D_ARRAY_EXT
:
1064 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1065 return ctx
->Const
.MaxTextureLevels
;
1067 case GL_PROXY_TEXTURE_3D
:
1068 return ctx
->Const
.Max3DTextureLevels
;
1069 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1070 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1071 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1072 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1073 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1074 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1075 case GL_TEXTURE_CUBE_MAP_ARB
:
1076 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1077 return ctx
->Const
.MaxCubeTextureLevels
;
1078 case GL_TEXTURE_RECTANGLE_NV
:
1079 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1082 return 0; /* bad target */
1088 #if 000 /* not used anymore */
1090 * glTexImage[123]D can accept a NULL image pointer. In this case we
1091 * create a texture image with unspecified image contents per the OpenGL
1095 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1097 const GLint components
= _mesa_components_in_format(format
);
1098 const GLint numPixels
= width
* height
* depth
;
1099 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1103 * Let's see if anyone finds this. If glTexImage2D() is called with
1104 * a NULL image pointer then load the texture image with something
1105 * interesting instead of leaving it indeterminate.
1108 static const char message
[8][32] = {
1109 " X X XXXXX XXX X ",
1110 " XX XX X X X X X ",
1112 " X X XXXX XXX XXXXX ",
1115 " X X XXXXX XXX X X ",
1119 GLubyte
*imgPtr
= data
;
1121 for (h
= 0; h
< depth
; h
++) {
1122 for (i
= 0; i
< height
; i
++) {
1123 GLint srcRow
= 7 - (i
% 8);
1124 for (j
= 0; j
< width
; j
++) {
1125 GLint srcCol
= j
% 32;
1126 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1127 for (k
= 0; k
< components
; k
++) {
1143 * Reset the fields of a gl_texture_image struct to zero.
1145 * \param img texture image structure.
1147 * This is called when a proxy texture test fails, we set all the
1148 * image members (except DriverData) to zero.
1149 * It's also used in glTexImage[123]D as a safeguard to be sure all
1150 * required fields get initialized properly by the Driver.TexImage[123]D
1154 clear_teximage_fields(struct gl_texture_image
*img
)
1157 img
->_BaseFormat
= 0;
1158 img
->InternalFormat
= 0;
1164 if (img
->ImageOffsets
) {
1165 _mesa_free(img
->ImageOffsets
);
1166 img
->ImageOffsets
= NULL
;
1172 img
->HeightLog2
= 0;
1175 img
->TexFormat
= &_mesa_null_texformat
;
1176 img
->FetchTexelc
= NULL
;
1177 img
->FetchTexelf
= NULL
;
1178 img
->IsCompressed
= 0;
1179 img
->CompressedSize
= 0;
1184 * Initialize basic fields of the gl_texture_image struct.
1186 * \param ctx GL context.
1187 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1188 * \param img texture image structure to be initialized.
1189 * \param width image width.
1190 * \param height image height.
1191 * \param depth image depth.
1192 * \param border image border.
1193 * \param internalFormat internal format.
1195 * Fills in the fields of \p img with the given information.
1196 * Note: width, height and depth include the border.
1199 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1200 struct gl_texture_image
*img
,
1201 GLsizei width
, GLsizei height
, GLsizei depth
,
1202 GLint border
, GLenum internalFormat
)
1208 ASSERT(height
>= 0);
1211 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1212 ASSERT(img
->_BaseFormat
> 0);
1213 img
->InternalFormat
= internalFormat
;
1214 img
->Border
= border
;
1216 img
->Height
= height
;
1219 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1220 img
->WidthLog2
= logbase2(img
->Width2
);
1222 if (height
== 1) { /* 1-D texture */
1224 img
->HeightLog2
= 0;
1227 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1228 img
->HeightLog2
= logbase2(img
->Height2
);
1231 if (depth
== 1) { /* 2-D texture */
1236 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1237 img
->DepthLog2
= logbase2(img
->Depth2
);
1240 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1242 img
->IsCompressed
= GL_FALSE
;
1243 img
->CompressedSize
= 0;
1245 if ((width
== 1 || _mesa_bitcount(img
->Width2
) == 1) &&
1246 (height
== 1 || _mesa_bitcount(img
->Height2
) == 1) &&
1247 (depth
== 1 || _mesa_bitcount(img
->Depth2
) == 1))
1248 img
->_IsPowerOfTwo
= GL_TRUE
;
1250 img
->_IsPowerOfTwo
= GL_FALSE
;
1252 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1253 img
->RowStride
= width
;
1254 /* Allocate the ImageOffsets array and initialize to typical values.
1255 * We allocate the array for 1D/2D textures too in order to avoid special-
1256 * case code in the texstore routines.
1258 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1259 for (i
= 0; i
< depth
; i
++) {
1260 img
->ImageOffsets
[i
] = i
* width
* height
;
1263 /* Compute Width/Height/DepthScale for mipmap lod computation */
1264 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1265 /* scale = 1.0 since texture coords directly map to texels */
1266 img
->WidthScale
= 1.0;
1267 img
->HeightScale
= 1.0;
1268 img
->DepthScale
= 1.0;
1271 img
->WidthScale
= (GLfloat
) img
->Width
;
1272 img
->HeightScale
= (GLfloat
) img
->Height
;
1273 img
->DepthScale
= (GLfloat
) img
->Depth
;
1279 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1280 * level, width, height and depth against the ctx->Const limits for textures.
1282 * A hardware driver might override this function if, for example, the
1283 * max 3D texture size is 512x512x64 (i.e. not a cube).
1285 * Note that width, height, depth == 0 is not an error. However, a
1286 * texture with zero width/height/depth will be considered "incomplete"
1287 * and texturing will effectively be disabled.
1289 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1290 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1291 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1292 * \param level as passed to glTexImage
1293 * \param internalFormat as passed to glTexImage
1294 * \param format as passed to glTexImage
1295 * \param type as passed to glTexImage
1296 * \param width as passed to glTexImage
1297 * \param height as passed to glTexImage
1298 * \param depth as passed to glTexImage
1299 * \param border as passed to glTexImage
1300 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1303 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1304 GLint internalFormat
, GLenum format
, GLenum type
,
1305 GLint width
, GLint height
, GLint depth
, GLint border
)
1309 (void) internalFormat
;
1314 case GL_PROXY_TEXTURE_1D
:
1315 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1316 if (width
< 2 * border
|| width
> 2 + maxSize
||
1317 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1318 width
>0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1319 level
>= ctx
->Const
.MaxTextureLevels
) {
1320 /* bad width or level */
1324 case GL_PROXY_TEXTURE_2D
:
1325 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1326 if (width
< 2 * border
|| width
> 2 + maxSize
||
1327 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1328 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1329 height
< 2 * border
|| height
> 2 + maxSize
||
1330 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1331 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1332 level
>= ctx
->Const
.MaxTextureLevels
) {
1333 /* bad width or height or level */
1337 case GL_PROXY_TEXTURE_3D
:
1338 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1339 if (width
< 2 * border
|| width
> 2 + maxSize
||
1340 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1341 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1342 height
< 2 * border
|| height
> 2 + maxSize
||
1343 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1344 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1345 depth
< 2 * border
|| depth
> 2 + maxSize
||
1346 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1347 depth
> 0 && _mesa_bitcount(depth
- 2 * border
) != 1) ||
1348 level
>= ctx
->Const
.Max3DTextureLevels
) {
1349 /* bad width or height or depth or level */
1353 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1354 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1355 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1357 /* bad width or height or level */
1361 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1362 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1363 if (width
< 2 * border
|| width
> 2 + maxSize
||
1364 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1365 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1366 height
< 2 * border
|| height
> 2 + maxSize
||
1367 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1368 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1369 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1370 /* bad width or height */
1374 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1375 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1376 if (width
< 2 * border
|| width
> 2 + maxSize
||
1377 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1378 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1379 level
>= ctx
->Const
.MaxTextureLevels
) {
1380 /* bad width or level */
1384 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1388 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1389 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1390 if (width
< 2 * border
|| width
> 2 + maxSize
||
1391 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1392 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1393 height
< 2 * border
|| height
> 2 + maxSize
||
1394 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1395 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1396 level
>= ctx
->Const
.MaxTextureLevels
) {
1397 /* bad width or height or level */
1400 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1405 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1412 * Helper function to determine whether a target supports compressed textures
1415 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1417 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1418 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1419 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1420 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1421 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1422 || ((ctx
->Extensions
.MESA_texture_array
&&
1423 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1424 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1429 * Test the glTexImage[123]D() parameters for errors.
1431 * \param ctx GL context.
1432 * \param target texture target given by the user.
1433 * \param level image level given by the user.
1434 * \param internalFormat internal format given by the user.
1435 * \param format pixel data format given by the user.
1436 * \param type pixel data type given by the user.
1437 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1438 * \param width image width given by the user.
1439 * \param height image height given by the user.
1440 * \param depth image depth given by the user.
1441 * \param border image border given by the user.
1443 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1445 * Verifies each of the parameters against the constants specified in
1446 * __GLcontextRec::Const and the supported extensions, and according to the
1447 * OpenGL specification.
1450 texture_error_check( GLcontext
*ctx
, GLenum target
,
1451 GLint level
, GLint internalFormat
,
1452 GLenum format
, GLenum type
,
1454 GLint width
, GLint height
,
1455 GLint depth
, GLint border
)
1457 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1458 GLboolean sizeOK
= GL_TRUE
;
1459 GLboolean colorFormat
, indexFormat
;
1460 GLenum proxy_target
;
1462 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1463 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1465 _mesa_error(ctx
, GL_INVALID_VALUE
,
1466 "glTexImage%dD(level=%d)", dimensions
, level
);
1472 if (border
< 0 || border
> 1 ||
1473 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1474 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1476 _mesa_error(ctx
, GL_INVALID_VALUE
,
1477 "glTexImage%dD(border=%d)", dimensions
, border
);
1482 if (width
< 0 || height
< 0 || depth
< 0) {
1484 _mesa_error(ctx
, GL_INVALID_VALUE
,
1485 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1490 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1491 * level, width, height and depth.
1493 if (dimensions
== 1) {
1494 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1495 proxy_target
= GL_PROXY_TEXTURE_1D
;
1500 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1504 else if (dimensions
== 2) {
1506 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1507 proxy_target
= GL_PROXY_TEXTURE_2D
;
1509 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1510 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1511 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1512 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1513 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1516 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1517 sizeOK
= (width
== height
);
1519 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1520 target
== GL_TEXTURE_RECTANGLE_NV
) {
1521 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1522 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1525 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1527 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1528 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1529 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1532 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1536 else if (dimensions
== 3) {
1537 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1538 proxy_target
= GL_PROXY_TEXTURE_3D
;
1540 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1541 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1542 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1545 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1550 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1554 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1555 internalFormat
, format
,
1556 type
, width
, height
,
1560 _mesa_error(ctx
, GL_INVALID_VALUE
,
1561 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1562 dimensions
, level
, width
, height
, depth
);
1567 /* Check internalFormat */
1568 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1570 _mesa_error(ctx
, GL_INVALID_VALUE
,
1571 "glTexImage%dD(internalFormat=0x%x)",
1572 dimensions
, internalFormat
);
1577 /* Check incoming image format and type */
1578 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1579 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1580 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1583 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1584 "glTexImage%dD(format or type)", dimensions
);
1589 /* make sure internal format and format basically agree */
1590 colorFormat
= is_color_format(format
);
1591 indexFormat
= is_index_format(format
);
1592 if ((is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1593 (is_index_format(internalFormat
) && !indexFormat
) ||
1594 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1595 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1596 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
))) {
1598 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1599 "glTexImage(internalFormat/format)");
1603 /* additional checks for ycbcr textures */
1604 if (internalFormat
== GL_YCBCR_MESA
) {
1605 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1606 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1607 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1609 _mesa_sprintf(message
,
1610 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1611 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1612 return GL_TRUE
; /* error */
1614 if (target
!= GL_TEXTURE_2D
&&
1615 target
!= GL_PROXY_TEXTURE_2D
&&
1616 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1617 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1619 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1625 _mesa_sprintf(message
,
1626 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1627 dimensions
, border
);
1628 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1634 /* additional checks for depth textures */
1635 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1636 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1637 if (target
!= GL_TEXTURE_1D
&&
1638 target
!= GL_PROXY_TEXTURE_1D
&&
1639 target
!= GL_TEXTURE_2D
&&
1640 target
!= GL_PROXY_TEXTURE_2D
&&
1641 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1642 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1644 _mesa_error(ctx
, GL_INVALID_ENUM
,
1645 "glTexImage(target/internalFormat)");
1650 /* additional checks for compressed textures */
1651 if (is_compressed_format(ctx
, internalFormat
)) {
1652 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1653 _mesa_error(ctx
, GL_INVALID_ENUM
,
1654 "glTexImage%d(target)", dimensions
);
1659 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1660 "glTexImage%D(border!=0)", dimensions
);
1666 /* if we get here, the parameters are OK */
1672 * Test glTexSubImage[123]D() parameters for errors.
1674 * \param ctx GL context.
1675 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1676 * \param target texture target given by the user.
1677 * \param level image level given by the user.
1678 * \param xoffset sub-image x offset given by the user.
1679 * \param yoffset sub-image y offset given by the user.
1680 * \param zoffset sub-image z offset given by the user.
1681 * \param format pixel data format given by the user.
1682 * \param type pixel data type given by the user.
1683 * \param width image width given by the user.
1684 * \param height image height given by the user.
1685 * \param depth image depth given by the user.
1687 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1689 * Verifies each of the parameters against the constants specified in
1690 * __GLcontextRec::Const and the supported extensions, and according to the
1691 * OpenGL specification.
1694 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1695 GLenum target
, GLint level
,
1696 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1697 GLint width
, GLint height
, GLint depth
,
1698 GLenum format
, GLenum type
)
1701 if (dimensions
== 1) {
1702 if (target
!= GL_TEXTURE_1D
) {
1703 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1707 else if (dimensions
== 2) {
1708 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1709 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1710 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1711 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1715 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1716 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1717 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1721 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1722 if (!ctx
->Extensions
.MESA_texture_array
) {
1723 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1727 else if (target
!= GL_TEXTURE_2D
) {
1728 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1732 else if (dimensions
== 3) {
1733 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1734 if (!ctx
->Extensions
.MESA_texture_array
) {
1735 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1739 else if (target
!= GL_TEXTURE_3D
) {
1740 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1745 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1749 /* Basic level check */
1750 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1751 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1756 _mesa_error(ctx
, GL_INVALID_VALUE
,
1757 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1760 if (height
< 0 && dimensions
> 1) {
1761 _mesa_error(ctx
, GL_INVALID_VALUE
,
1762 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1765 if (depth
< 0 && dimensions
> 2) {
1766 _mesa_error(ctx
, GL_INVALID_VALUE
,
1767 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1771 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1772 _mesa_error(ctx
, GL_INVALID_ENUM
,
1773 "glTexSubImage%dD(format or type)", dimensions
);
1781 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1782 GLenum target
, GLint level
,
1783 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1784 GLint width
, GLint height
, GLint depth
,
1785 GLenum format
, GLenum type
,
1786 const struct gl_texture_image
*destTex
)
1789 /* undefined image level */
1790 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1794 if (xoffset
< -((GLint
)destTex
->Border
)) {
1795 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1799 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1800 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1804 if (dimensions
> 1) {
1805 if (yoffset
< -((GLint
)destTex
->Border
)) {
1806 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1810 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1811 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1816 if (dimensions
> 2) {
1817 if (zoffset
< -((GLint
)destTex
->Border
)) {
1818 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1821 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1822 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1827 #if FEATURE_EXT_texture_sRGB
1828 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1829 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1830 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1831 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1832 if ((width
& 0x3) || (height
& 0x3) ||
1833 (xoffset
& 0x3) || (yoffset
& 0x3))
1834 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1835 "glTexSubImage%dD(size or offset not multiple of 4)",
1841 if (destTex
->IsCompressed
) {
1842 if (!target_can_be_compressed(ctx
, target
)) {
1843 _mesa_error(ctx
, GL_INVALID_ENUM
,
1844 "glTexSubImage%D(target)", dimensions
);
1847 /* offset must be multiple of 4 */
1848 if ((xoffset
& 3) || (yoffset
& 3)) {
1849 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1850 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1853 /* size must be multiple of 4 or equal to whole texture size */
1854 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1855 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1856 "glTexSubImage%D(width)", dimensions
);
1859 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1860 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1861 "glTexSubImage%D(width)", dimensions
);
1871 * Test glCopyTexImage[12]D() parameters for errors.
1873 * \param ctx GL context.
1874 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1875 * \param target texture target given by the user.
1876 * \param level image level given by the user.
1877 * \param internalFormat internal format given by the user.
1878 * \param width image width given by the user.
1879 * \param height image height given by the user.
1880 * \param depth image depth given by the user.
1881 * \param border texture border.
1883 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1885 * Verifies each of the parameters against the constants specified in
1886 * __GLcontextRec::Const and the supported extensions, and according to the
1887 * OpenGL specification.
1890 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1891 GLenum target
, GLint level
, GLint internalFormat
,
1892 GLint width
, GLint height
, GLint border
)
1898 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1899 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1900 _mesa_error(ctx
, GL_INVALID_VALUE
,
1901 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1905 /* Check that the source buffer is complete */
1906 if (ctx
->ReadBuffer
->Name
) {
1907 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1908 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1909 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1910 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1916 if (border
< 0 || border
> 1 ||
1917 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1918 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1922 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1924 _mesa_error(ctx
, GL_INVALID_VALUE
,
1925 "glCopyTexImage%dD(internalFormat)", dimensions
);
1929 /* NOTE: the format and type aren't really significant for
1930 * TestProxyTexImage(). Only the internalformat really matters.
1931 if (!_mesa_source_buffer_exists(ctx, format)) {
1932 _mesa_error(ctx, GL_INVALID_OPERATION,
1933 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1940 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1941 * level, width, height and depth.
1943 if (dimensions
== 1) {
1944 if (target
== GL_TEXTURE_1D
) {
1945 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1946 level
, internalFormat
,
1948 width
, 1, 1, border
);
1951 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1955 else if (dimensions
== 2) {
1956 if (target
== GL_TEXTURE_2D
) {
1957 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1958 level
, internalFormat
,
1960 width
, height
, 1, border
);
1962 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1963 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1964 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1965 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1968 sizeOK
= (width
== height
) &&
1969 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1970 level
, internalFormat
, format
, type
,
1971 width
, height
, 1, border
);
1973 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1974 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1975 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1978 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1979 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1980 level
, internalFormat
,
1982 width
, height
, 1, border
);
1984 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1985 if (!ctx
->Extensions
.MESA_texture_array
) {
1986 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1989 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1990 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1991 level
, internalFormat
,
1993 width
, height
, 1, border
);
1996 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
2001 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
2006 if (dimensions
== 1) {
2007 _mesa_error(ctx
, GL_INVALID_VALUE
,
2008 "glCopyTexImage1D(width=%d)", width
);
2011 ASSERT(dimensions
== 2);
2012 _mesa_error(ctx
, GL_INVALID_VALUE
,
2013 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2018 if (is_compressed_format(ctx
, internalFormat
)) {
2019 if (!target_can_be_compressed(ctx
, target
)) {
2020 _mesa_error(ctx
, GL_INVALID_ENUM
,
2021 "glCopyTexImage%d(target)", dimensions
);
2025 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2026 "glCopyTexImage%D(border!=0)", dimensions
);
2030 else if (is_depth_format(internalFormat
)) {
2031 /* make sure we have depth/stencil buffers */
2032 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2033 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2034 "glCopyTexImage%D(no depth)", dimensions
);
2038 else if (is_depthstencil_format(internalFormat
)) {
2039 /* make sure we have depth/stencil buffers */
2040 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2041 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2042 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2047 /* if we get here, the parameters are OK */
2053 * Test glCopyTexSubImage[12]D() parameters for errors.
2055 * \param ctx GL context.
2056 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2057 * \param target texture target given by the user.
2058 * \param level image level given by the user.
2059 * \param xoffset sub-image x offset given by the user.
2060 * \param yoffset sub-image y offset given by the user.
2061 * \param zoffset sub-image z offset given by the user.
2062 * \param width image width given by the user.
2063 * \param height image height given by the user.
2065 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2067 * Verifies each of the parameters against the constants specified in
2068 * __GLcontextRec::Const and the supported extensions, and according to the
2069 * OpenGL specification.
2072 copytexsubimage_error_check( GLcontext
*ctx
, GLuint dimensions
,
2073 GLenum target
, GLint level
,
2074 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2075 GLsizei width
, GLsizei height
)
2078 /* Check that the source buffer is complete */
2079 if (ctx
->ReadBuffer
->Name
) {
2080 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2081 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2082 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2083 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2088 if (dimensions
== 1) {
2089 if (target
!= GL_TEXTURE_1D
) {
2090 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2094 else if (dimensions
== 2) {
2095 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2096 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2097 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2098 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2102 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2103 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2104 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2108 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2109 if (!ctx
->Extensions
.MESA_texture_array
) {
2110 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2114 else if (target
!= GL_TEXTURE_2D
) {
2115 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2119 else if (dimensions
== 3) {
2120 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2121 (!ctx
->Extensions
.MESA_texture_array
))
2122 && (target
!= GL_TEXTURE_3D
)) {
2123 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2129 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2130 _mesa_error(ctx
, GL_INVALID_VALUE
,
2131 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2137 _mesa_error(ctx
, GL_INVALID_VALUE
,
2138 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2141 if (dimensions
> 1 && height
< 0) {
2142 _mesa_error(ctx
, GL_INVALID_VALUE
,
2143 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2151 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2152 GLenum target
, GLint level
,
2153 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2154 GLsizei width
, GLsizei height
,
2155 const struct gl_texture_image
*teximage
)
2158 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2159 "glCopyTexSubImage%dD(undefined texture level: %d)",
2164 if (xoffset
< -((GLint
)teximage
->Border
)) {
2165 _mesa_error(ctx
, GL_INVALID_VALUE
,
2166 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2169 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2170 _mesa_error(ctx
, GL_INVALID_VALUE
,
2171 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2174 if (dimensions
> 1) {
2175 if (yoffset
< -((GLint
)teximage
->Border
)) {
2176 _mesa_error(ctx
, GL_INVALID_VALUE
,
2177 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2180 /* NOTE: we're adding the border here, not subtracting! */
2181 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2182 _mesa_error(ctx
, GL_INVALID_VALUE
,
2183 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2188 if (dimensions
> 2) {
2189 if (zoffset
< -((GLint
)teximage
->Border
)) {
2190 _mesa_error(ctx
, GL_INVALID_VALUE
,
2191 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2194 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2195 _mesa_error(ctx
, GL_INVALID_VALUE
,
2196 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2201 if (teximage
->IsCompressed
) {
2202 if (!target_can_be_compressed(ctx
, target
)) {
2203 _mesa_error(ctx
, GL_INVALID_ENUM
,
2204 "glCopyTexSubImage%d(target)", dimensions
);
2207 /* offset must be multiple of 4 */
2208 if ((xoffset
& 3) || (yoffset
& 3)) {
2209 _mesa_error(ctx
, GL_INVALID_VALUE
,
2210 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2213 /* size must be multiple of 4 */
2214 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2215 _mesa_error(ctx
, GL_INVALID_VALUE
,
2216 "glCopyTexSubImage%D(width)", dimensions
);
2219 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2220 _mesa_error(ctx
, GL_INVALID_VALUE
,
2221 "glCopyTexSubImage%D(height)", dimensions
);
2226 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2227 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2231 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2232 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2233 "glCopyTexSubImage%dD(missing readbuffer)", dimensions
);
2237 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2238 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2239 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2240 "glCopyTexSubImage%D(no depth buffer)",
2245 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2246 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2247 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2248 "glCopyTexSubImage%D(no depth/stencil buffer)",
2254 /* if we get here, the parameters are OK */
2260 * Get texture image. Called by glGetTexImage.
2262 * \param target texture target.
2263 * \param level image level.
2264 * \param format pixel data format for returned image.
2265 * \param type pixel data type for returned image.
2266 * \param pixels returned pixel data.
2269 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2270 GLenum type
, GLvoid
*pixels
)
2272 const struct gl_texture_unit
*texUnit
;
2273 struct gl_texture_object
*texObj
;
2274 struct gl_texture_image
*texImage
;
2275 GLint maxLevels
= 0;
2276 GET_CURRENT_CONTEXT(ctx
);
2277 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2279 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2280 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2281 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2282 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2286 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2287 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2289 if (level
< 0 || level
>= maxLevels
) {
2290 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2294 if (_mesa_sizeof_packed_type(type
) <= 0) {
2295 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2299 if (_mesa_components_in_format(format
) <= 0 ||
2300 format
== GL_STENCIL_INDEX
) {
2301 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2305 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2306 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2310 if (!ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2311 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2315 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2316 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2320 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2321 && is_depthstencil_format(format
)) {
2322 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2326 _mesa_lock_texture(ctx
, texObj
);
2328 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2330 /* invalid mipmap level, not an error */
2335 /* Make sure the requested image format is compatible with the
2336 * texture's format. Note that a color index texture can be converted
2337 * to RGBA so that combo is allowed.
2339 if (is_color_format(format
)
2340 && !is_color_format(texImage
->TexFormat
->BaseFormat
)
2341 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2342 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2345 else if (is_index_format(format
)
2346 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2347 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2350 else if (is_depth_format(format
)
2351 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2352 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2353 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2356 else if (is_ycbcr_format(format
)
2357 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2358 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2361 else if (is_depthstencil_format(format
)
2362 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2363 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2367 if (ctx
->Pack
.BufferObj
->Name
) {
2368 /* packing texture image into a PBO */
2369 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2370 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2371 texImage
->Height
, texImage
->Depth
,
2372 format
, type
, pixels
)) {
2373 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2374 "glGetTexImage(invalid PBO access)");
2379 /* typically, this will call _mesa_get_teximage() */
2380 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2385 _mesa_unlock_texture(ctx
, texObj
);
2391 * Check if the given texture image is bound to any framebuffer objects
2392 * and update/invalidate them.
2393 * XXX We're only checking the currently bound framebuffer object for now.
2394 * In the future, perhaps struct gl_texture_image should have a pointer (or
2395 * list of pointers (yikes)) to the gl_framebuffer(s) which it's bound to.
2398 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2399 GLuint face
, GLuint level
)
2401 if (ctx
->DrawBuffer
->Name
) {
2403 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2404 struct gl_renderbuffer_attachment
*att
=
2405 ctx
->DrawBuffer
->Attachment
+ i
;
2406 if (att
->Type
== GL_TEXTURE
&&
2407 att
->Texture
== texObj
&&
2408 att
->TextureLevel
== level
&&
2409 att
->CubeMapFace
== face
) {
2410 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2411 /* Tell driver about the new renderbuffer texture */
2412 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2421 * Called from the API. Note that width includes the border.
2424 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2425 GLsizei width
, GLint border
, GLenum format
,
2426 GLenum type
, const GLvoid
*pixels
)
2428 GLsizei postConvWidth
= width
;
2429 GET_CURRENT_CONTEXT(ctx
);
2430 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2432 #if FEATURE_convolve
2433 if (is_color_format(internalFormat
)) {
2434 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2438 if (target
== GL_TEXTURE_1D
) {
2439 /* non-proxy target */
2440 struct gl_texture_unit
*texUnit
;
2441 struct gl_texture_object
*texObj
;
2442 struct gl_texture_image
*texImage
;
2443 const GLuint face
= _mesa_tex_target_to_face(target
);
2445 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2446 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2447 return; /* error was recorded */
2450 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2451 _mesa_update_state(ctx
);
2453 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2454 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2455 _mesa_lock_texture(ctx
, texObj
);
2457 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2459 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2463 if (texImage
->Data
) {
2464 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2467 ASSERT(texImage
->Data
== NULL
);
2469 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2470 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2471 postConvWidth
, 1, 1,
2472 border
, internalFormat
);
2474 ASSERT(ctx
->Driver
.TexImage1D
);
2476 /* Give the texture to the driver! <pixels> may be null! */
2477 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2478 width
, border
, format
, type
, pixels
,
2479 &ctx
->Unpack
, texObj
, texImage
);
2481 ASSERT(texImage
->TexFormat
);
2483 update_fbo_texture(ctx
, texObj
, face
, level
);
2486 texObj
->_Complete
= GL_FALSE
;
2487 ctx
->NewState
|= _NEW_TEXTURE
;
2490 _mesa_unlock_texture(ctx
, texObj
);
2492 else if (target
== GL_PROXY_TEXTURE_1D
) {
2493 /* Proxy texture: check for errors and update proxy state */
2494 struct gl_texture_image
*texImage
;
2495 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2496 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2497 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2498 /* when error, clear all proxy texture image parameters */
2500 clear_teximage_fields(texImage
);
2503 /* no error, set the tex image parameters */
2505 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2506 postConvWidth
, 1, 1,
2507 border
, internalFormat
);
2508 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2509 internalFormat
, format
, type
);
2513 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2520 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2521 GLsizei width
, GLsizei height
, GLint border
,
2522 GLenum format
, GLenum type
,
2523 const GLvoid
*pixels
)
2525 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2526 GET_CURRENT_CONTEXT(ctx
);
2527 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2529 #if FEATURE_convolve
2530 if (is_color_format(internalFormat
)) {
2531 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2536 if (target
== GL_TEXTURE_2D
||
2537 (ctx
->Extensions
.ARB_texture_cube_map
&&
2538 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2539 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2540 (ctx
->Extensions
.NV_texture_rectangle
&&
2541 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2542 (ctx
->Extensions
.MESA_texture_array
&&
2543 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2544 /* non-proxy target */
2545 struct gl_texture_unit
*texUnit
;
2546 struct gl_texture_object
*texObj
;
2547 struct gl_texture_image
*texImage
;
2548 const GLuint face
= _mesa_tex_target_to_face(target
);
2550 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2551 format
, type
, 2, postConvWidth
, postConvHeight
,
2553 return; /* error was recorded */
2556 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2557 _mesa_update_state(ctx
);
2559 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2560 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2561 _mesa_lock_texture(ctx
, texObj
);
2563 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2565 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2569 if (texImage
->Data
) {
2570 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2573 ASSERT(texImage
->Data
== NULL
);
2574 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2575 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2576 postConvWidth
, postConvHeight
, 1,
2577 border
, internalFormat
);
2579 ASSERT(ctx
->Driver
.TexImage2D
);
2581 /* Give the texture to the driver! <pixels> may be null! */
2582 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2583 width
, height
, border
, format
, type
, pixels
,
2584 &ctx
->Unpack
, texObj
, texImage
);
2586 ASSERT(texImage
->TexFormat
);
2588 update_fbo_texture(ctx
, texObj
, face
, level
);
2591 texObj
->_Complete
= GL_FALSE
;
2592 ctx
->NewState
|= _NEW_TEXTURE
;
2595 _mesa_unlock_texture(ctx
, texObj
);
2597 else if (target
== GL_PROXY_TEXTURE_2D
||
2598 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2599 ctx
->Extensions
.ARB_texture_cube_map
) ||
2600 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2601 ctx
->Extensions
.NV_texture_rectangle
) ||
2602 (ctx
->Extensions
.MESA_texture_array
&&
2603 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2604 /* Proxy texture: check for errors and update proxy state */
2605 struct gl_texture_image
*texImage
;
2606 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2607 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2608 format
, type
, 2, postConvWidth
, postConvHeight
,
2610 /* when error, clear all proxy texture image parameters */
2612 clear_teximage_fields(ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
]);
2615 /* no error, set the tex image parameters */
2616 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2617 postConvWidth
, postConvHeight
, 1,
2618 border
, internalFormat
);
2619 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2620 internalFormat
, format
, type
);
2624 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2631 * Called by the API or display list executor.
2632 * Note that width and height include the border.
2635 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2636 GLsizei width
, GLsizei height
, GLsizei depth
,
2637 GLint border
, GLenum format
, GLenum type
,
2638 const GLvoid
*pixels
)
2640 GET_CURRENT_CONTEXT(ctx
);
2641 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2643 if (target
== GL_TEXTURE_3D
||
2644 (ctx
->Extensions
.MESA_texture_array
&&
2645 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2646 /* non-proxy target */
2647 struct gl_texture_unit
*texUnit
;
2648 struct gl_texture_object
*texObj
;
2649 struct gl_texture_image
*texImage
;
2650 const GLuint face
= _mesa_tex_target_to_face(target
);
2652 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2653 format
, type
, 3, width
, height
, depth
, border
)) {
2654 return; /* error was recorded */
2657 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2658 _mesa_update_state(ctx
);
2660 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2661 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2662 _mesa_lock_texture(ctx
, texObj
);
2664 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2666 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2670 if (texImage
->Data
) {
2671 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2674 ASSERT(texImage
->Data
== NULL
);
2675 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2676 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2677 width
, height
, depth
,
2678 border
, internalFormat
);
2680 ASSERT(ctx
->Driver
.TexImage3D
);
2682 /* Give the texture to the driver! <pixels> may be null! */
2683 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2684 width
, height
, depth
, border
, format
, type
,
2685 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2687 ASSERT(texImage
->TexFormat
);
2689 update_fbo_texture(ctx
, texObj
, face
, level
);
2692 texObj
->_Complete
= GL_FALSE
;
2693 ctx
->NewState
|= _NEW_TEXTURE
;
2696 _mesa_unlock_texture(ctx
, texObj
);
2698 else if (target
== GL_PROXY_TEXTURE_3D
||
2699 (ctx
->Extensions
.MESA_texture_array
&&
2700 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2701 /* Proxy texture: check for errors and update proxy state */
2702 struct gl_texture_image
*texImage
;
2703 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2704 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2705 format
, type
, 3, width
, height
, depth
, border
)) {
2706 /* when error, clear all proxy texture image parameters */
2708 clear_teximage_fields(texImage
);
2711 /* no error, set the tex image parameters */
2712 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2713 depth
, border
, internalFormat
);
2714 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2715 internalFormat
, format
, type
);
2719 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2726 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2727 GLsizei width
, GLsizei height
, GLsizei depth
,
2728 GLint border
, GLenum format
, GLenum type
,
2729 const GLvoid
*pixels
)
2731 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2732 depth
, border
, format
, type
, pixels
);
2738 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2739 GLint xoffset
, GLsizei width
,
2740 GLenum format
, GLenum type
,
2741 const GLvoid
*pixels
)
2743 GLsizei postConvWidth
= width
;
2744 struct gl_texture_unit
*texUnit
;
2745 struct gl_texture_object
*texObj
;
2746 struct gl_texture_image
*texImage
= NULL
;
2747 GET_CURRENT_CONTEXT(ctx
);
2748 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2750 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2751 _mesa_update_state(ctx
);
2753 #if FEATURE_convolve
2754 /* XXX should test internal format */
2755 if (is_color_format(format
)) {
2756 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2760 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2761 postConvWidth
, 1, 1, format
, type
)) {
2762 return; /* error was detected */
2766 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2767 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2770 _mesa_lock_texture(ctx
, texObj
);
2772 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2774 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2775 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2776 goto out
; /* error was detected */
2780 goto out
; /* no-op, not an error */
2782 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2783 xoffset
+= texImage
->Border
;
2785 ASSERT(ctx
->Driver
.TexSubImage1D
);
2786 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2787 format
, type
, pixels
, &ctx
->Unpack
,
2789 ctx
->NewState
|= _NEW_TEXTURE
;
2792 _mesa_unlock_texture(ctx
, texObj
);
2797 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2798 GLint xoffset
, GLint yoffset
,
2799 GLsizei width
, GLsizei height
,
2800 GLenum format
, GLenum type
,
2801 const GLvoid
*pixels
)
2803 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2804 struct gl_texture_unit
*texUnit
;
2805 struct gl_texture_object
*texObj
;
2806 struct gl_texture_image
*texImage
;
2807 GET_CURRENT_CONTEXT(ctx
);
2808 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2810 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2811 _mesa_update_state(ctx
);
2813 #if FEATURE_convolve
2814 /* XXX should test internal format */
2815 if (is_color_format(format
)) {
2816 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2821 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2822 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2823 return; /* error was detected */
2826 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2827 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2828 _mesa_lock_texture(ctx
, texObj
);
2830 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2832 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2833 postConvWidth
, postConvHeight
, 1, format
, type
,
2835 goto out
; /* error was detected */
2838 if (width
== 0 || height
== 0)
2839 goto out
; /* no-op, not an error */
2841 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2842 xoffset
+= texImage
->Border
;
2843 yoffset
+= texImage
->Border
;
2845 ASSERT(ctx
->Driver
.TexSubImage2D
);
2846 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2847 width
, height
, format
, type
, pixels
,
2848 &ctx
->Unpack
, texObj
, texImage
);
2849 ctx
->NewState
|= _NEW_TEXTURE
;
2852 _mesa_unlock_texture(ctx
, texObj
);
2858 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2859 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2860 GLsizei width
, GLsizei height
, GLsizei depth
,
2861 GLenum format
, GLenum type
,
2862 const GLvoid
*pixels
)
2864 struct gl_texture_unit
*texUnit
;
2865 struct gl_texture_object
*texObj
;
2866 struct gl_texture_image
*texImage
;
2867 GET_CURRENT_CONTEXT(ctx
);
2868 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2870 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2871 _mesa_update_state(ctx
);
2873 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2874 width
, height
, depth
, format
, type
)) {
2875 return; /* error was detected */
2878 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2879 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2881 _mesa_lock_texture(ctx
, texObj
);
2883 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2885 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2886 width
, height
, depth
, format
, type
, texImage
)) {
2887 goto out
; /* error was detected */
2890 if (width
== 0 || height
== 0 || height
== 0)
2891 goto out
; /* no-op, not an error */
2893 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2894 xoffset
+= texImage
->Border
;
2895 yoffset
+= texImage
->Border
;
2896 zoffset
+= texImage
->Border
;
2898 ASSERT(ctx
->Driver
.TexSubImage3D
);
2899 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2900 xoffset
, yoffset
, zoffset
,
2901 width
, height
, depth
,
2902 format
, type
, pixels
,
2903 &ctx
->Unpack
, texObj
, texImage
);
2904 ctx
->NewState
|= _NEW_TEXTURE
;
2907 _mesa_unlock_texture(ctx
, texObj
);
2913 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2914 GLenum internalFormat
,
2916 GLsizei width
, GLint border
)
2918 struct gl_texture_unit
*texUnit
;
2919 struct gl_texture_object
*texObj
;
2920 struct gl_texture_image
*texImage
;
2921 GLsizei postConvWidth
= width
;
2922 const GLuint face
= _mesa_tex_target_to_face(target
);
2923 GET_CURRENT_CONTEXT(ctx
);
2924 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2926 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2927 _mesa_update_state(ctx
);
2929 #if FEATURE_convolve
2930 if (is_color_format(internalFormat
)) {
2931 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2935 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2936 postConvWidth
, 1, border
))
2939 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2940 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2941 _mesa_lock_texture(ctx
, texObj
);
2943 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2945 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2949 if (texImage
->Data
) {
2950 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2953 ASSERT(texImage
->Data
== NULL
);
2955 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2956 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2957 border
, internalFormat
);
2960 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2961 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2962 x
, y
, width
, border
);
2964 ASSERT(texImage
->TexFormat
);
2966 update_fbo_texture(ctx
, texObj
, face
, level
);
2969 texObj
->_Complete
= GL_FALSE
;
2970 ctx
->NewState
|= _NEW_TEXTURE
;
2973 _mesa_unlock_texture(ctx
, texObj
);
2979 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2980 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2983 struct gl_texture_unit
*texUnit
;
2984 struct gl_texture_object
*texObj
;
2985 struct gl_texture_image
*texImage
;
2986 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2987 const GLuint face
= _mesa_tex_target_to_face(target
);
2988 GET_CURRENT_CONTEXT(ctx
);
2989 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2991 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2992 _mesa_update_state(ctx
);
2994 #if FEATURE_convolve
2995 if (is_color_format(internalFormat
)) {
2996 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
3000 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
3001 postConvWidth
, postConvHeight
, border
))
3004 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3005 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3007 _mesa_lock_texture(ctx
, texObj
);
3009 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3012 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3016 if (texImage
->Data
) {
3017 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3020 ASSERT(texImage
->Data
== NULL
);
3022 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3023 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3024 postConvWidth
, postConvHeight
, 1,
3025 border
, internalFormat
);
3027 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3028 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3029 x
, y
, width
, height
, border
);
3031 ASSERT(texImage
->TexFormat
);
3033 update_fbo_texture(ctx
, texObj
, face
, level
);
3036 texObj
->_Complete
= GL_FALSE
;
3037 ctx
->NewState
|= _NEW_TEXTURE
;
3040 _mesa_unlock_texture(ctx
, texObj
);
3045 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3046 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3048 struct gl_texture_unit
*texUnit
;
3049 struct gl_texture_object
*texObj
;
3050 struct gl_texture_image
*texImage
;
3051 GLsizei postConvWidth
= width
;
3055 GET_CURRENT_CONTEXT(ctx
);
3056 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3058 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3059 _mesa_update_state(ctx
);
3061 #if FEATURE_convolve
3062 /* XXX should test internal format */
3063 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3066 if (copytexsubimage_error_check(ctx
, 1, target
, level
,
3067 xoffset
, 0, 0, postConvWidth
, 1))
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 (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3078 xoffset
, 0, 0, postConvWidth
, 1,
3083 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3084 xoffset
+= texImage
->Border
;
3086 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3088 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3089 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3090 xoffset
, x
, y
, width
);
3093 ctx
->NewState
|= _NEW_TEXTURE
;
3096 _mesa_unlock_texture(ctx
, texObj
);
3102 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3103 GLint xoffset
, GLint yoffset
,
3104 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3106 struct gl_texture_unit
*texUnit
;
3107 struct gl_texture_object
*texObj
;
3108 struct gl_texture_image
*texImage
;
3109 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3110 GET_CURRENT_CONTEXT(ctx
);
3111 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3113 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3114 _mesa_update_state(ctx
);
3116 #if FEATURE_convolve
3117 /* XXX should test internal format */
3118 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
3121 if (copytexsubimage_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3122 postConvWidth
, postConvHeight
))
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 (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3133 postConvWidth
, postConvHeight
, texImage
))
3136 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3137 xoffset
+= texImage
->Border
;
3138 yoffset
+= texImage
->Border
;
3140 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3142 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3143 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3144 xoffset
, yoffset
, x
, y
, width
, height
);
3147 ctx
->NewState
|= _NEW_TEXTURE
;
3150 _mesa_unlock_texture(ctx
, texObj
);
3156 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3157 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3158 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3160 struct gl_texture_unit
*texUnit
;
3161 struct gl_texture_object
*texObj
;
3162 struct gl_texture_image
*texImage
;
3163 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3164 GET_CURRENT_CONTEXT(ctx
);
3165 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3167 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3168 _mesa_update_state(ctx
);
3170 #if FEATURE_convolve
3171 /* XXX should test internal format */
3172 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
3175 if (copytexsubimage_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
,
3176 zoffset
, postConvWidth
, postConvHeight
))
3179 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3180 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3182 _mesa_lock_texture(ctx
, texObj
);
3184 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3186 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3187 zoffset
, postConvWidth
, postConvHeight
,
3191 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3192 xoffset
+= texImage
->Border
;
3193 yoffset
+= texImage
->Border
;
3194 zoffset
+= texImage
->Border
;
3196 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3198 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3199 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3200 xoffset
, yoffset
, zoffset
,
3201 x
, y
, width
, height
);
3204 ctx
->NewState
|= _NEW_TEXTURE
;
3207 _mesa_unlock_texture(ctx
, texObj
);
3213 /**********************************************************************/
3214 /****** Compressed Textures ******/
3215 /**********************************************************************/
3219 * Error checking for glCompressedTexImage[123]D().
3220 * \return error code or GL_NO_ERROR.
3223 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3224 GLenum target
, GLint level
,
3225 GLenum internalFormat
, GLsizei width
,
3226 GLsizei height
, GLsizei depth
, GLint border
,
3229 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3231 if (dimensions
== 1) {
3232 /* 1D compressed textures not allowed */
3233 return GL_INVALID_ENUM
;
3235 else if (dimensions
== 2) {
3236 if (target
== GL_PROXY_TEXTURE_2D
) {
3237 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3239 else if (target
== GL_TEXTURE_2D
) {
3240 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3242 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3243 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3244 return GL_INVALID_ENUM
; /*target*/
3245 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3247 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3248 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3249 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3250 return GL_INVALID_ENUM
; /*target*/
3251 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3254 return GL_INVALID_ENUM
; /*target*/
3257 else if (dimensions
== 3) {
3258 /* 3D compressed textures not allowed */
3259 return GL_INVALID_ENUM
;
3262 maxTextureSize
= 1 << (maxLevels
- 1);
3264 /* This will detect any invalid internalFormat value */
3265 if (!is_compressed_format(ctx
, internalFormat
))
3266 return GL_INVALID_ENUM
;
3268 /* This should really never fail */
3269 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3270 return GL_INVALID_ENUM
;
3273 return GL_INVALID_VALUE
;
3276 * XXX We should probably use the proxy texture error check function here.
3278 if (width
< 1 || width
> maxTextureSize
||
3279 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(width
) != 1))
3280 return GL_INVALID_VALUE
;
3282 if ((height
< 1 || height
> maxTextureSize
||
3283 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(height
) != 1))
3285 return GL_INVALID_VALUE
;
3287 if ((depth
< 1 || depth
> maxTextureSize
||
3288 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(depth
) != 1))
3290 return GL_INVALID_VALUE
;
3292 /* For cube map, width must equal height */
3293 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3294 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3295 return GL_INVALID_VALUE
;
3297 if (level
< 0 || level
>= maxLevels
)
3298 return GL_INVALID_VALUE
;
3300 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3301 depth
, internalFormat
);
3302 if (expectedSize
!= imageSize
)
3303 return GL_INVALID_VALUE
;
3305 #if FEATURE_EXT_texture_sRGB
3306 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3307 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3308 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3309 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3311 return GL_INVALID_OPERATION
;
3320 * Error checking for glCompressedTexSubImage[123]D().
3321 * \warning There are some bad assumptions here about the size of compressed
3322 * texture tiles (multiple of 4) used to test the validity of the
3323 * offset and size parameters.
3324 * \return error code or GL_NO_ERROR.
3327 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3328 GLenum target
, GLint level
,
3329 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3330 GLsizei width
, GLsizei height
, GLsizei depth
,
3331 GLenum format
, GLsizei imageSize
)
3333 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3336 if (dimensions
== 1) {
3337 /* 1D compressed textures not allowed */
3338 return GL_INVALID_ENUM
;
3340 else if (dimensions
== 2) {
3341 if (target
== GL_PROXY_TEXTURE_2D
) {
3342 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3344 else if (target
== GL_TEXTURE_2D
) {
3345 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3347 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3348 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3349 return GL_INVALID_ENUM
; /*target*/
3350 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3352 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3353 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3354 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3355 return GL_INVALID_ENUM
; /*target*/
3356 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3359 return GL_INVALID_ENUM
; /*target*/
3362 else if (dimensions
== 3) {
3363 /* 3D compressed textures not allowed */
3364 return GL_INVALID_ENUM
;
3367 maxTextureSize
= 1 << (maxLevels
- 1);
3369 /* this will catch any invalid compressed format token */
3370 if (!is_compressed_format(ctx
, format
))
3371 return GL_INVALID_ENUM
;
3373 if (width
< 1 || width
> maxTextureSize
)
3374 return GL_INVALID_VALUE
;
3376 if ((height
< 1 || height
> maxTextureSize
)
3378 return GL_INVALID_VALUE
;
3380 if (level
< 0 || level
>= maxLevels
)
3381 return GL_INVALID_VALUE
;
3383 /* XXX these tests are specific to the compressed format.
3384 * this code should be generalized in some way.
3386 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3387 return GL_INVALID_VALUE
;
3389 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3390 return GL_INVALID_VALUE
;
3392 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3393 return GL_INVALID_VALUE
;
3395 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3397 if (expectedSize
!= imageSize
)
3398 return GL_INVALID_VALUE
;
3406 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3407 GLenum internalFormat
, GLsizei width
,
3408 GLint border
, GLsizei imageSize
,
3411 GET_CURRENT_CONTEXT(ctx
);
3412 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3414 if (target
== GL_TEXTURE_1D
) {
3415 /* non-proxy target */
3416 struct gl_texture_unit
*texUnit
;
3417 struct gl_texture_object
*texObj
;
3418 struct gl_texture_image
*texImage
;
3419 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3420 internalFormat
, width
, 1, 1, border
, imageSize
);
3422 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3426 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3427 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3429 _mesa_lock_texture(ctx
, texObj
);
3431 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3433 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3437 if (texImage
->Data
) {
3438 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3440 ASSERT(texImage
->Data
== NULL
);
3442 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3443 border
, internalFormat
);
3445 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3446 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3447 internalFormat
, width
, border
,
3452 texObj
->_Complete
= GL_FALSE
;
3453 ctx
->NewState
|= _NEW_TEXTURE
;
3456 _mesa_unlock_texture(ctx
, texObj
);
3458 else if (target
== GL_PROXY_TEXTURE_1D
) {
3459 /* Proxy texture: check for errors and update proxy state */
3460 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3461 internalFormat
, width
, 1, 1, border
, imageSize
);
3463 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3464 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3465 internalFormat
, GL_NONE
, GL_NONE
,
3466 width
, 1, 1, border
);
3469 /* if error, clear all proxy texture image parameters */
3470 struct gl_texture_image
*texImage
;
3471 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3473 clear_teximage_fields(texImage
);
3476 /* store the teximage parameters */
3477 struct gl_texture_unit
*texUnit
;
3478 struct gl_texture_object
*texObj
;
3479 struct gl_texture_image
*texImage
;
3480 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3481 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3483 _mesa_lock_texture(ctx
, texObj
);
3485 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3486 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3487 border
, internalFormat
);
3489 _mesa_unlock_texture(ctx
, texObj
);
3493 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3500 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3501 GLenum internalFormat
, GLsizei width
,
3502 GLsizei height
, GLint border
, GLsizei imageSize
,
3505 GET_CURRENT_CONTEXT(ctx
);
3506 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3508 if (target
== GL_TEXTURE_2D
||
3509 (ctx
->Extensions
.ARB_texture_cube_map
&&
3510 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3511 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3512 /* non-proxy target */
3513 struct gl_texture_unit
*texUnit
;
3514 struct gl_texture_object
*texObj
;
3515 struct gl_texture_image
*texImage
;
3516 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3517 internalFormat
, width
, height
, 1, border
, imageSize
);
3519 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3523 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3524 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3526 _mesa_lock_texture(ctx
, texObj
);
3528 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3530 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3534 if (texImage
->Data
) {
3535 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3537 ASSERT(texImage
->Data
== NULL
);
3539 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3540 border
, internalFormat
);
3542 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3543 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3544 internalFormat
, width
, height
,
3545 border
, imageSize
, data
,
3549 texObj
->_Complete
= GL_FALSE
;
3550 ctx
->NewState
|= _NEW_TEXTURE
;
3553 _mesa_unlock_texture(ctx
, texObj
);
3555 else if (target
== GL_PROXY_TEXTURE_2D
||
3556 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3557 ctx
->Extensions
.ARB_texture_cube_map
)) {
3558 /* Proxy texture: check for errors and update proxy state */
3559 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3560 internalFormat
, width
, height
, 1, border
, imageSize
);
3562 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3563 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3564 internalFormat
, GL_NONE
, GL_NONE
,
3565 width
, height
, 1, border
);
3568 /* if error, clear all proxy texture image parameters */
3569 struct gl_texture_image
*texImage
;
3570 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3572 clear_teximage_fields(texImage
);
3575 /* store the teximage parameters */
3576 struct gl_texture_unit
*texUnit
;
3577 struct gl_texture_object
*texObj
;
3578 struct gl_texture_image
*texImage
;
3579 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3580 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3582 _mesa_lock_texture(ctx
, texObj
);
3584 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3585 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3586 border
, internalFormat
);
3588 _mesa_unlock_texture(ctx
, texObj
);
3592 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3599 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3600 GLenum internalFormat
, GLsizei width
,
3601 GLsizei height
, GLsizei depth
, GLint border
,
3602 GLsizei imageSize
, const GLvoid
*data
)
3604 GET_CURRENT_CONTEXT(ctx
);
3605 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3607 if (target
== GL_TEXTURE_3D
) {
3608 /* non-proxy target */
3609 struct gl_texture_unit
*texUnit
;
3610 struct gl_texture_object
*texObj
;
3611 struct gl_texture_image
*texImage
;
3612 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3613 internalFormat
, width
, height
, depth
, border
, imageSize
);
3615 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3619 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3620 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3621 _mesa_lock_texture(ctx
, texObj
);
3623 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3625 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3629 if (texImage
->Data
) {
3630 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3632 ASSERT(texImage
->Data
== NULL
);
3634 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3635 border
, internalFormat
);
3637 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3638 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3640 width
, height
, depth
,
3641 border
, imageSize
, data
,
3645 texObj
->_Complete
= GL_FALSE
;
3646 ctx
->NewState
|= _NEW_TEXTURE
;
3649 _mesa_unlock_texture(ctx
, texObj
);
3651 else if (target
== GL_PROXY_TEXTURE_3D
) {
3652 /* Proxy texture: check for errors and update proxy state */
3653 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3654 internalFormat
, width
, height
, depth
, border
, imageSize
);
3656 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3657 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3658 internalFormat
, GL_NONE
, GL_NONE
,
3659 width
, height
, depth
, border
);
3662 /* if error, clear all proxy texture image parameters */
3663 struct gl_texture_image
*texImage
;
3664 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3666 clear_teximage_fields(texImage
);
3669 /* store the teximage parameters */
3670 struct gl_texture_unit
*texUnit
;
3671 struct gl_texture_object
*texObj
;
3672 struct gl_texture_image
*texImage
;
3673 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3674 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3675 _mesa_lock_texture(ctx
, texObj
);
3677 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3678 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3679 depth
, border
, internalFormat
);
3681 _mesa_unlock_texture(ctx
, texObj
);
3685 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3692 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3693 GLsizei width
, GLenum format
,
3694 GLsizei imageSize
, const GLvoid
*data
)
3696 struct gl_texture_unit
*texUnit
;
3697 struct gl_texture_object
*texObj
;
3698 struct gl_texture_image
*texImage
;
3700 GET_CURRENT_CONTEXT(ctx
);
3701 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3703 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3704 xoffset
, 0, 0, /* pos */
3705 width
, 1, 1, /* size */
3708 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3712 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3713 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3714 _mesa_lock_texture(ctx
, texObj
);
3716 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3719 if ((GLint
) format
!= texImage
->InternalFormat
) {
3720 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3721 "glCompressedTexSubImage1D(format)");
3725 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3726 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3731 goto out
; /* no-op, not an error */
3733 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3734 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3736 format
, imageSize
, data
,
3739 ctx
->NewState
|= _NEW_TEXTURE
;
3742 _mesa_unlock_texture(ctx
, texObj
);
3747 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3748 GLint yoffset
, GLsizei width
, GLsizei height
,
3749 GLenum format
, GLsizei imageSize
,
3752 struct gl_texture_unit
*texUnit
;
3753 struct gl_texture_object
*texObj
;
3754 struct gl_texture_image
*texImage
;
3756 GET_CURRENT_CONTEXT(ctx
);
3757 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3759 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3760 xoffset
, yoffset
, 0, /* pos */
3761 width
, height
, 1, /* size */
3764 /* XXX proxy target? */
3765 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3769 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3770 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3771 _mesa_lock_texture(ctx
, texObj
);
3773 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3776 if ((GLint
) format
!= texImage
->InternalFormat
) {
3777 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3778 "glCompressedTexSubImage2D(format)");
3782 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3783 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3784 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3788 if (width
== 0 || height
== 0)
3789 goto out
; /* no-op, not an error */
3791 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3792 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3793 xoffset
, yoffset
, width
, height
,
3794 format
, imageSize
, data
,
3797 ctx
->NewState
|= _NEW_TEXTURE
;
3800 _mesa_unlock_texture(ctx
, texObj
);
3805 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3806 GLint yoffset
, GLint zoffset
, GLsizei width
,
3807 GLsizei height
, GLsizei depth
, GLenum format
,
3808 GLsizei imageSize
, const GLvoid
*data
)
3810 struct gl_texture_unit
*texUnit
;
3811 struct gl_texture_object
*texObj
;
3812 struct gl_texture_image
*texImage
;
3814 GET_CURRENT_CONTEXT(ctx
);
3815 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3817 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3818 xoffset
, yoffset
, zoffset
,/*pos*/
3819 width
, height
, depth
, /*size*/
3822 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3826 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3827 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3828 _mesa_lock_texture(ctx
, texObj
);
3830 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3833 if ((GLint
) format
!= texImage
->InternalFormat
) {
3834 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3835 "glCompressedTexSubImage3D(format)");
3839 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3840 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3841 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3842 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3846 if (width
== 0 || height
== 0 || depth
== 0)
3847 goto out
; /* no-op, not an error */
3849 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3850 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3851 xoffset
, yoffset
, zoffset
,
3852 width
, height
, depth
,
3853 format
, imageSize
, data
,
3856 ctx
->NewState
|= _NEW_TEXTURE
;
3859 _mesa_unlock_texture(ctx
, texObj
);
3864 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3866 const struct gl_texture_unit
*texUnit
;
3867 struct gl_texture_object
*texObj
;
3868 struct gl_texture_image
*texImage
;
3870 GET_CURRENT_CONTEXT(ctx
);
3871 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3873 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3874 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3876 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3880 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3881 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3883 if (level
< 0 || level
>= maxLevels
) {
3884 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3888 if (_mesa_is_proxy_texture(target
)) {
3889 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3893 _mesa_lock_texture(ctx
, texObj
);
3895 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3897 if (texImage
->IsCompressed
) {
3898 /* this typically calls _mesa_get_compressed_teximage() */
3899 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3903 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3904 "glGetCompressedTexImageARB");
3908 /* probably invalid mipmap level */
3909 _mesa_error(ctx
, GL_INVALID_VALUE
,
3910 "glGetCompressedTexImageARB(level)");
3913 _mesa_unlock_texture(ctx
, texObj
);