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 switch (internalFormat
) {
257 case GL_COMPRESSED_ALPHA
:
259 case GL_COMPRESSED_LUMINANCE
:
261 case GL_COMPRESSED_LUMINANCE_ALPHA
:
262 return GL_LUMINANCE_ALPHA
;
263 case GL_COMPRESSED_INTENSITY
:
265 case GL_COMPRESSED_RGB
:
267 case GL_COMPRESSED_RGBA
:
273 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
274 switch (internalFormat
) {
275 case GL_COMPRESSED_RGB_FXT1_3DFX
:
277 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
284 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
285 switch (internalFormat
) {
286 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
288 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
289 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
290 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
297 if (ctx
->Extensions
.S3_s3tc
) {
298 switch (internalFormat
) {
310 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
311 if (internalFormat
== GL_YCBCR_MESA
)
312 return GL_YCBCR_MESA
;
315 if (ctx
->Extensions
.ARB_texture_float
) {
316 switch (internalFormat
) {
317 case GL_ALPHA16F_ARB
:
318 case GL_ALPHA32F_ARB
:
326 case GL_INTENSITY16F_ARB
:
327 case GL_INTENSITY32F_ARB
:
329 case GL_LUMINANCE16F_ARB
:
330 case GL_LUMINANCE32F_ARB
:
332 case GL_LUMINANCE_ALPHA16F_ARB
:
333 case GL_LUMINANCE_ALPHA32F_ARB
:
334 return GL_LUMINANCE_ALPHA
;
340 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
341 switch (internalFormat
) {
342 case GL_DEPTH_STENCIL_EXT
:
343 case GL_DEPTH24_STENCIL8_EXT
:
344 return GL_DEPTH_STENCIL_EXT
;
350 #if FEATURE_EXT_texture_sRGB
351 if (ctx
->Extensions
.EXT_texture_sRGB
) {
352 switch (internalFormat
) {
355 case GL_COMPRESSED_SRGB_EXT
:
356 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
358 case GL_SRGB_ALPHA_EXT
:
359 case GL_SRGB8_ALPHA8_EXT
:
360 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
361 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
362 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
363 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
365 case GL_SLUMINANCE_ALPHA_EXT
:
366 case GL_SLUMINANCE8_ALPHA8_EXT
:
367 case GL_COMPRESSED_SLUMINANCE_EXT
:
368 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
369 return GL_LUMINANCE_ALPHA
;
370 case GL_SLUMINANCE_EXT
:
371 case GL_SLUMINANCE8_EXT
:
378 #endif /* FEATURE_EXT_texture_sRGB */
380 return -1; /* error */
385 * Test if the given image format is a color/RGBA format (i.e., not color
386 * index, depth, stencil, etc).
387 * \param format the image format value (may by an internal texture format)
388 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
389 * XXX maybe move this func to image.c
392 _mesa_is_color_format(GLenum format
)
410 case GL_LUMINANCE_ALPHA
:
411 case GL_LUMINANCE4_ALPHA4
:
412 case GL_LUMINANCE6_ALPHA2
:
413 case GL_LUMINANCE8_ALPHA8
:
414 case GL_LUMINANCE12_ALPHA4
:
415 case GL_LUMINANCE12_ALPHA12
:
416 case GL_LUMINANCE16_ALPHA16
:
443 /* float texture formats */
444 case GL_ALPHA16F_ARB
:
445 case GL_ALPHA32F_ARB
:
446 case GL_LUMINANCE16F_ARB
:
447 case GL_LUMINANCE32F_ARB
:
448 case GL_LUMINANCE_ALPHA16F_ARB
:
449 case GL_LUMINANCE_ALPHA32F_ARB
:
450 case GL_INTENSITY16F_ARB
:
451 case GL_INTENSITY32F_ARB
:
456 /* compressed formats */
457 case GL_COMPRESSED_ALPHA
:
458 case GL_COMPRESSED_LUMINANCE
:
459 case GL_COMPRESSED_LUMINANCE_ALPHA
:
460 case GL_COMPRESSED_INTENSITY
:
461 case GL_COMPRESSED_RGB
:
462 case GL_COMPRESSED_RGBA
:
467 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
468 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
469 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
470 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
471 case GL_COMPRESSED_RGB_FXT1_3DFX
:
472 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
473 #if FEATURE_EXT_texture_sRGB
476 case GL_SRGB_ALPHA_EXT
:
477 case GL_SRGB8_ALPHA8_EXT
:
478 case GL_SLUMINANCE_ALPHA_EXT
:
479 case GL_SLUMINANCE8_ALPHA8_EXT
:
480 case GL_SLUMINANCE_EXT
:
481 case GL_SLUMINANCE8_EXT
:
482 case GL_COMPRESSED_SRGB_EXT
:
483 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
484 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
485 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
486 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
487 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
488 case GL_COMPRESSED_SLUMINANCE_EXT
:
489 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
490 #endif /* FEATURE_EXT_texture_sRGB */
492 case GL_YCBCR_MESA
: /* not considered to be RGB */
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
;
1218 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1219 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1220 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1221 img
->WidthLog2
= logbase2(img
->Width2
);
1222 if (height
== 1) /* 1-D texture */
1223 img
->HeightLog2
= 0;
1225 img
->HeightLog2
= logbase2(img
->Height2
);
1226 if (depth
== 1) /* 2-D texture */
1229 img
->DepthLog2
= logbase2(img
->Depth2
);
1230 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1231 img
->IsCompressed
= GL_FALSE
;
1232 img
->CompressedSize
= 0;
1234 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1235 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1236 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1237 img
->_IsPowerOfTwo
= GL_TRUE
;
1239 img
->_IsPowerOfTwo
= GL_FALSE
;
1241 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1242 img
->RowStride
= width
;
1243 /* Allocate the ImageOffsets array and initialize to typical values.
1244 * We allocate the array for 1D/2D textures too in order to avoid special-
1245 * case code in the texstore routines.
1247 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1248 for (i
= 0; i
< depth
; i
++) {
1249 img
->ImageOffsets
[i
] = i
* width
* height
;
1252 /* Compute Width/Height/DepthScale for mipmap lod computation */
1253 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1254 /* scale = 1.0 since texture coords directly map to texels */
1255 img
->WidthScale
= 1.0;
1256 img
->HeightScale
= 1.0;
1257 img
->DepthScale
= 1.0;
1260 img
->WidthScale
= (GLfloat
) img
->Width
;
1261 img
->HeightScale
= (GLfloat
) img
->Height
;
1262 img
->DepthScale
= (GLfloat
) img
->Depth
;
1268 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1269 * level, width, height and depth against the ctx->Const limits for textures.
1271 * A hardware driver might override this function if, for example, the
1272 * max 3D texture size is 512x512x64 (i.e. not a cube).
1274 * Note that width, height, depth == 0 is not an error. However, a
1275 * texture with zero width/height/depth will be considered "incomplete"
1276 * and texturing will effectively be disabled.
1278 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1279 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1280 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1281 * \param level as passed to glTexImage
1282 * \param internalFormat as passed to glTexImage
1283 * \param format as passed to glTexImage
1284 * \param type as passed to glTexImage
1285 * \param width as passed to glTexImage
1286 * \param height as passed to glTexImage
1287 * \param depth as passed to glTexImage
1288 * \param border as passed to glTexImage
1289 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1292 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1293 GLint internalFormat
, GLenum format
, GLenum type
,
1294 GLint width
, GLint height
, GLint depth
, GLint border
)
1298 (void) internalFormat
;
1303 case GL_PROXY_TEXTURE_1D
:
1304 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1305 if (width
< 2 * border
|| width
> 2 + maxSize
||
1306 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1307 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1308 level
>= ctx
->Const
.MaxTextureLevels
) {
1309 /* bad width or level */
1313 case GL_PROXY_TEXTURE_2D
:
1314 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1315 if (width
< 2 * border
|| width
> 2 + maxSize
||
1316 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1317 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1318 height
< 2 * border
|| height
> 2 + maxSize
||
1319 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1320 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1321 level
>= ctx
->Const
.MaxTextureLevels
) {
1322 /* bad width or height or level */
1326 case GL_PROXY_TEXTURE_3D
:
1327 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1328 if (width
< 2 * border
|| width
> 2 + maxSize
||
1329 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1330 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1331 height
< 2 * border
|| height
> 2 + maxSize
||
1332 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1333 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1334 depth
< 2 * border
|| depth
> 2 + maxSize
||
1335 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1336 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1337 level
>= ctx
->Const
.Max3DTextureLevels
) {
1338 /* bad width or height or depth or level */
1342 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1343 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1344 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1346 /* bad width or height or level */
1350 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1351 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1352 if (width
< 2 * border
|| width
> 2 + maxSize
||
1353 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1354 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1355 height
< 2 * border
|| height
> 2 + maxSize
||
1356 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1357 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1358 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1359 /* bad width or height */
1363 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1364 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1365 if (width
< 2 * border
|| width
> 2 + maxSize
||
1366 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1367 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1368 level
>= ctx
->Const
.MaxTextureLevels
) {
1369 /* bad width or level */
1373 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1377 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1378 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1379 if (width
< 2 * border
|| width
> 2 + maxSize
||
1380 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1381 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1382 height
< 2 * border
|| height
> 2 + maxSize
||
1383 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1384 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1385 level
>= ctx
->Const
.MaxTextureLevels
) {
1386 /* bad width or height or level */
1389 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1394 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1401 * Helper function to determine whether a target supports compressed textures
1404 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1406 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1407 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1408 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1409 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1410 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1411 || ((ctx
->Extensions
.MESA_texture_array
&&
1412 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1413 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1418 * Test the glTexImage[123]D() parameters for errors.
1420 * \param ctx GL context.
1421 * \param target texture target given by the user.
1422 * \param level image level given by the user.
1423 * \param internalFormat internal format given by the user.
1424 * \param format pixel data format given by the user.
1425 * \param type pixel data type given by the user.
1426 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1427 * \param width image width given by the user.
1428 * \param height image height given by the user.
1429 * \param depth image depth given by the user.
1430 * \param border image border given by the user.
1432 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1434 * Verifies each of the parameters against the constants specified in
1435 * __GLcontextRec::Const and the supported extensions, and according to the
1436 * OpenGL specification.
1439 texture_error_check( GLcontext
*ctx
, GLenum target
,
1440 GLint level
, GLint internalFormat
,
1441 GLenum format
, GLenum type
,
1443 GLint width
, GLint height
,
1444 GLint depth
, GLint border
)
1446 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1447 GLboolean sizeOK
= GL_TRUE
;
1448 GLboolean colorFormat
, indexFormat
;
1449 GLenum proxy_target
;
1451 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1452 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1454 _mesa_error(ctx
, GL_INVALID_VALUE
,
1455 "glTexImage%dD(level=%d)", dimensions
, level
);
1461 if (border
< 0 || border
> 1 ||
1462 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1463 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1465 _mesa_error(ctx
, GL_INVALID_VALUE
,
1466 "glTexImage%dD(border=%d)", dimensions
, border
);
1471 if (width
< 0 || height
< 0 || depth
< 0) {
1473 _mesa_error(ctx
, GL_INVALID_VALUE
,
1474 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1479 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1480 * level, width, height and depth.
1482 if (dimensions
== 1) {
1483 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1484 proxy_target
= GL_PROXY_TEXTURE_1D
;
1489 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1493 else if (dimensions
== 2) {
1495 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1496 proxy_target
= GL_PROXY_TEXTURE_2D
;
1498 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1499 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1500 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1501 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1502 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1505 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1506 sizeOK
= (width
== height
);
1508 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1509 target
== GL_TEXTURE_RECTANGLE_NV
) {
1510 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1511 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1514 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1516 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1517 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1518 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1521 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1525 else if (dimensions
== 3) {
1526 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1527 proxy_target
= GL_PROXY_TEXTURE_3D
;
1529 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1530 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1531 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1534 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1539 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1543 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1544 internalFormat
, format
,
1545 type
, width
, height
,
1549 _mesa_error(ctx
, GL_INVALID_VALUE
,
1550 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1551 dimensions
, level
, width
, height
, depth
);
1556 /* Check internalFormat */
1557 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1559 _mesa_error(ctx
, GL_INVALID_VALUE
,
1560 "glTexImage%dD(internalFormat=0x%x)",
1561 dimensions
, internalFormat
);
1566 /* Check incoming image format and type */
1567 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1568 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1569 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1572 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1573 "glTexImage%dD(format or type)", dimensions
);
1578 /* make sure internal format and format basically agree */
1579 colorFormat
= _mesa_is_color_format(format
);
1580 indexFormat
= is_index_format(format
);
1581 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1582 (is_index_format(internalFormat
) && !indexFormat
) ||
1583 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1584 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1585 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
))) {
1587 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1588 "glTexImage(internalFormat/format)");
1592 /* additional checks for ycbcr textures */
1593 if (internalFormat
== GL_YCBCR_MESA
) {
1594 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1595 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1596 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1598 _mesa_sprintf(message
,
1599 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1600 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1601 return GL_TRUE
; /* error */
1603 if (target
!= GL_TEXTURE_2D
&&
1604 target
!= GL_PROXY_TEXTURE_2D
&&
1605 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1606 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1608 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1614 _mesa_sprintf(message
,
1615 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1616 dimensions
, border
);
1617 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1623 /* additional checks for depth textures */
1624 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1625 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1626 if (target
!= GL_TEXTURE_1D
&&
1627 target
!= GL_PROXY_TEXTURE_1D
&&
1628 target
!= GL_TEXTURE_2D
&&
1629 target
!= GL_PROXY_TEXTURE_2D
&&
1630 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1631 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1633 _mesa_error(ctx
, GL_INVALID_ENUM
,
1634 "glTexImage(target/internalFormat)");
1639 /* additional checks for compressed textures */
1640 if (is_compressed_format(ctx
, internalFormat
)) {
1641 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1642 _mesa_error(ctx
, GL_INVALID_ENUM
,
1643 "glTexImage%d(target)", dimensions
);
1648 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1649 "glTexImage%D(border!=0)", dimensions
);
1655 /* if we get here, the parameters are OK */
1661 * Test glTexSubImage[123]D() parameters for errors.
1663 * \param ctx GL context.
1664 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1665 * \param target texture target given by the user.
1666 * \param level image level given by the user.
1667 * \param xoffset sub-image x offset given by the user.
1668 * \param yoffset sub-image y offset given by the user.
1669 * \param zoffset sub-image z offset given by the user.
1670 * \param format pixel data format given by the user.
1671 * \param type pixel data type given by the user.
1672 * \param width image width given by the user.
1673 * \param height image height given by the user.
1674 * \param depth image depth given by the user.
1676 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1678 * Verifies each of the parameters against the constants specified in
1679 * __GLcontextRec::Const and the supported extensions, and according to the
1680 * OpenGL specification.
1683 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1684 GLenum target
, GLint level
,
1685 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1686 GLint width
, GLint height
, GLint depth
,
1687 GLenum format
, GLenum type
)
1690 if (dimensions
== 1) {
1691 if (target
!= GL_TEXTURE_1D
) {
1692 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1696 else if (dimensions
== 2) {
1697 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1698 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1699 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1700 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1704 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1705 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1706 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1710 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1711 if (!ctx
->Extensions
.MESA_texture_array
) {
1712 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1716 else if (target
!= GL_TEXTURE_2D
) {
1717 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1721 else if (dimensions
== 3) {
1722 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1723 if (!ctx
->Extensions
.MESA_texture_array
) {
1724 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1728 else if (target
!= GL_TEXTURE_3D
) {
1729 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1734 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1738 /* Basic level check */
1739 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1740 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1745 _mesa_error(ctx
, GL_INVALID_VALUE
,
1746 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1749 if (height
< 0 && dimensions
> 1) {
1750 _mesa_error(ctx
, GL_INVALID_VALUE
,
1751 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1754 if (depth
< 0 && dimensions
> 2) {
1755 _mesa_error(ctx
, GL_INVALID_VALUE
,
1756 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1760 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1761 _mesa_error(ctx
, GL_INVALID_ENUM
,
1762 "glTexSubImage%dD(format or type)", dimensions
);
1770 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1771 GLenum target
, GLint level
,
1772 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1773 GLint width
, GLint height
, GLint depth
,
1774 GLenum format
, GLenum type
,
1775 const struct gl_texture_image
*destTex
)
1778 /* undefined image level */
1779 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1783 if (xoffset
< -((GLint
)destTex
->Border
)) {
1784 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1788 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1789 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1793 if (dimensions
> 1) {
1794 if (yoffset
< -((GLint
)destTex
->Border
)) {
1795 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1799 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1800 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1805 if (dimensions
> 2) {
1806 if (zoffset
< -((GLint
)destTex
->Border
)) {
1807 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1810 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1811 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1816 #if FEATURE_EXT_texture_sRGB
1817 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1818 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1819 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1820 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1821 if ((width
& 0x3) || (height
& 0x3) ||
1822 (xoffset
& 0x3) || (yoffset
& 0x3))
1823 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1824 "glTexSubImage%dD(size or offset not multiple of 4)",
1830 if (destTex
->IsCompressed
) {
1831 if (!target_can_be_compressed(ctx
, target
)) {
1832 _mesa_error(ctx
, GL_INVALID_ENUM
,
1833 "glTexSubImage%D(target)", dimensions
);
1836 /* offset must be multiple of 4 */
1837 if ((xoffset
& 3) || (yoffset
& 3)) {
1838 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1839 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1842 /* size must be multiple of 4 or equal to whole texture size */
1843 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1844 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1845 "glTexSubImage%D(width)", dimensions
);
1848 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1849 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1850 "glTexSubImage%D(width)", dimensions
);
1860 * Test glCopyTexImage[12]D() parameters for errors.
1862 * \param ctx GL context.
1863 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1864 * \param target texture target given by the user.
1865 * \param level image level given by the user.
1866 * \param internalFormat internal format given by the user.
1867 * \param width image width given by the user.
1868 * \param height image height given by the user.
1869 * \param depth image depth given by the user.
1870 * \param border texture border.
1872 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1874 * Verifies each of the parameters against the constants specified in
1875 * __GLcontextRec::Const and the supported extensions, and according to the
1876 * OpenGL specification.
1879 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1880 GLenum target
, GLint level
, GLint internalFormat
,
1881 GLint width
, GLint height
, GLint border
)
1887 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1888 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1889 _mesa_error(ctx
, GL_INVALID_VALUE
,
1890 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1894 /* Check that the source buffer is complete */
1895 if (ctx
->ReadBuffer
->Name
) {
1896 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1897 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1898 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1899 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1905 if (border
< 0 || border
> 1 ||
1906 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1907 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1911 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1913 _mesa_error(ctx
, GL_INVALID_VALUE
,
1914 "glCopyTexImage%dD(internalFormat)", dimensions
);
1918 /* NOTE: the format and type aren't really significant for
1919 * TestProxyTexImage(). Only the internalformat really matters.
1920 if (!_mesa_source_buffer_exists(ctx, format)) {
1921 _mesa_error(ctx, GL_INVALID_OPERATION,
1922 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1929 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1930 * level, width, height and depth.
1932 if (dimensions
== 1) {
1933 if (target
== GL_TEXTURE_1D
) {
1934 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1935 level
, internalFormat
,
1937 width
, 1, 1, border
);
1940 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1944 else if (dimensions
== 2) {
1945 if (target
== GL_TEXTURE_2D
) {
1946 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1947 level
, internalFormat
,
1949 width
, height
, 1, border
);
1951 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1952 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1953 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1954 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1957 sizeOK
= (width
== height
) &&
1958 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1959 level
, internalFormat
, format
, type
,
1960 width
, height
, 1, border
);
1962 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1963 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1964 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1967 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1968 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1969 level
, internalFormat
,
1971 width
, height
, 1, border
);
1973 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1974 if (!ctx
->Extensions
.MESA_texture_array
) {
1975 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1978 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1979 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1980 level
, internalFormat
,
1982 width
, height
, 1, border
);
1985 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1990 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1995 if (dimensions
== 1) {
1996 _mesa_error(ctx
, GL_INVALID_VALUE
,
1997 "glCopyTexImage1D(width=%d)", width
);
2000 ASSERT(dimensions
== 2);
2001 _mesa_error(ctx
, GL_INVALID_VALUE
,
2002 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2007 if (is_compressed_format(ctx
, internalFormat
)) {
2008 if (!target_can_be_compressed(ctx
, target
)) {
2009 _mesa_error(ctx
, GL_INVALID_ENUM
,
2010 "glCopyTexImage%d(target)", dimensions
);
2014 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2015 "glCopyTexImage%D(border!=0)", dimensions
);
2019 else if (is_depth_format(internalFormat
)) {
2020 /* make sure we have depth/stencil buffers */
2021 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2022 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2023 "glCopyTexImage%D(no depth)", dimensions
);
2027 else if (is_depthstencil_format(internalFormat
)) {
2028 /* make sure we have depth/stencil buffers */
2029 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2030 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2031 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2036 /* if we get here, the parameters are OK */
2042 * Test glCopyTexSubImage[12]D() parameters for errors.
2043 * Note that this is the first part of error checking.
2044 * See also copytexsubimage_error_check2() below for the second part.
2046 * \param ctx GL context.
2047 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2048 * \param target texture target given by the user.
2049 * \param level image level given by the user.
2051 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2054 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
2055 GLenum target
, GLint level
)
2057 /* Check that the source buffer is complete */
2058 if (ctx
->ReadBuffer
->Name
) {
2059 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2060 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2061 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2062 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2068 if (dimensions
== 1) {
2069 if (target
!= GL_TEXTURE_1D
) {
2070 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2074 else if (dimensions
== 2) {
2075 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2076 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2077 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2078 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2082 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2083 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2084 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2088 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2089 if (!ctx
->Extensions
.MESA_texture_array
) {
2090 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2094 else if (target
!= GL_TEXTURE_2D
) {
2095 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2099 else if (dimensions
== 3) {
2100 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2101 (!ctx
->Extensions
.MESA_texture_array
))
2102 && (target
!= GL_TEXTURE_3D
)) {
2103 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2109 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2110 _mesa_error(ctx
, GL_INVALID_VALUE
,
2111 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2120 * Second part of error checking for glCopyTexSubImage[12]D().
2121 * \param xoffset sub-image x offset given by the user.
2122 * \param yoffset sub-image y offset given by the user.
2123 * \param zoffset sub-image z offset given by the user.
2124 * \param width image width given by the user.
2125 * \param height image height given by the user.
2128 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2129 GLenum target
, GLint level
,
2130 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2131 GLsizei width
, GLsizei height
,
2132 const struct gl_texture_image
*teximage
)
2134 /* check that dest tex image exists */
2136 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2137 "glCopyTexSubImage%dD(undefined texture level: %d)",
2144 _mesa_error(ctx
, GL_INVALID_VALUE
,
2145 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2148 if (dimensions
> 1 && height
< 0) {
2149 _mesa_error(ctx
, GL_INVALID_VALUE
,
2150 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2154 /* check x/y offsets */
2155 if (xoffset
< -((GLint
)teximage
->Border
)) {
2156 _mesa_error(ctx
, GL_INVALID_VALUE
,
2157 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2160 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2161 _mesa_error(ctx
, GL_INVALID_VALUE
,
2162 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2165 if (dimensions
> 1) {
2166 if (yoffset
< -((GLint
)teximage
->Border
)) {
2167 _mesa_error(ctx
, GL_INVALID_VALUE
,
2168 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2171 /* NOTE: we're adding the border here, not subtracting! */
2172 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2173 _mesa_error(ctx
, GL_INVALID_VALUE
,
2174 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2179 /* check z offset */
2180 if (dimensions
> 2) {
2181 if (zoffset
< -((GLint
)teximage
->Border
)) {
2182 _mesa_error(ctx
, GL_INVALID_VALUE
,
2183 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2186 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2187 _mesa_error(ctx
, GL_INVALID_VALUE
,
2188 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2193 if (teximage
->IsCompressed
) {
2194 if (!target_can_be_compressed(ctx
, target
)) {
2195 _mesa_error(ctx
, GL_INVALID_ENUM
,
2196 "glCopyTexSubImage%d(target)", dimensions
);
2199 /* offset must be multiple of 4 */
2200 if ((xoffset
& 3) || (yoffset
& 3)) {
2201 _mesa_error(ctx
, GL_INVALID_VALUE
,
2202 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2205 /* size must be multiple of 4 */
2206 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2207 _mesa_error(ctx
, GL_INVALID_VALUE
,
2208 "glCopyTexSubImage%D(width)", dimensions
);
2211 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2212 _mesa_error(ctx
, GL_INVALID_VALUE
,
2213 "glCopyTexSubImage%D(height)", dimensions
);
2218 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2219 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2223 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2224 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2225 "glCopyTexSubImage%dD(missing readbuffer)", dimensions
);
2229 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2230 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2231 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2232 "glCopyTexSubImage%D(no depth buffer)",
2237 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2238 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2239 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2240 "glCopyTexSubImage%D(no depth/stencil buffer)",
2246 /* if we get here, the parameters are OK */
2252 * Get texture image. Called by glGetTexImage.
2254 * \param target texture target.
2255 * \param level image level.
2256 * \param format pixel data format for returned image.
2257 * \param type pixel data type for returned image.
2258 * \param pixels returned pixel data.
2261 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2262 GLenum type
, GLvoid
*pixels
)
2264 const struct gl_texture_unit
*texUnit
;
2265 struct gl_texture_object
*texObj
;
2266 struct gl_texture_image
*texImage
;
2267 GLint maxLevels
= 0;
2268 GET_CURRENT_CONTEXT(ctx
);
2269 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2271 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2272 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2273 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2274 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2278 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2279 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2281 if (level
< 0 || level
>= maxLevels
) {
2282 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2286 if (_mesa_sizeof_packed_type(type
) <= 0) {
2287 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2291 if (_mesa_components_in_format(format
) <= 0 ||
2292 format
== GL_STENCIL_INDEX
) {
2293 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2297 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2298 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2302 if (!ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2303 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2307 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2308 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2312 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2313 && is_depthstencil_format(format
)) {
2314 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2318 _mesa_lock_texture(ctx
, texObj
);
2320 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2322 /* invalid mipmap level, not an error */
2327 /* Make sure the requested image format is compatible with the
2328 * texture's format. Note that a color index texture can be converted
2329 * to RGBA so that combo is allowed.
2331 if (_mesa_is_color_format(format
)
2332 && !_mesa_is_color_format(texImage
->TexFormat
->BaseFormat
)
2333 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2334 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2337 else if (is_index_format(format
)
2338 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2339 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2342 else if (is_depth_format(format
)
2343 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2344 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2345 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2348 else if (is_ycbcr_format(format
)
2349 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2350 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2353 else if (is_depthstencil_format(format
)
2354 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2355 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2359 if (ctx
->Pack
.BufferObj
->Name
) {
2360 /* packing texture image into a PBO */
2361 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2362 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2363 texImage
->Height
, texImage
->Depth
,
2364 format
, type
, pixels
)) {
2365 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2366 "glGetTexImage(invalid PBO access)");
2371 /* typically, this will call _mesa_get_teximage() */
2372 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2377 _mesa_unlock_texture(ctx
, texObj
);
2383 * Check if the given texture image is bound to any framebuffer objects
2384 * and update/invalidate them.
2385 * XXX We're only checking the currently bound framebuffer object for now.
2386 * In the future, perhaps struct gl_texture_image should have a pointer (or
2387 * list of pointers (yikes)) to the gl_framebuffer(s) which it's bound to.
2390 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2391 GLuint face
, GLuint level
)
2393 if (ctx
->DrawBuffer
->Name
) {
2395 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2396 struct gl_renderbuffer_attachment
*att
=
2397 ctx
->DrawBuffer
->Attachment
+ i
;
2398 if (att
->Type
== GL_TEXTURE
&&
2399 att
->Texture
== texObj
&&
2400 att
->TextureLevel
== level
&&
2401 att
->CubeMapFace
== face
) {
2402 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2403 /* Tell driver about the new renderbuffer texture */
2404 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2413 * Called from the API. Note that width includes the border.
2416 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2417 GLsizei width
, GLint border
, GLenum format
,
2418 GLenum type
, const GLvoid
*pixels
)
2420 GLsizei postConvWidth
= width
;
2421 GET_CURRENT_CONTEXT(ctx
);
2422 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2424 #if FEATURE_convolve
2425 if (_mesa_is_color_format(internalFormat
)) {
2426 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2430 if (target
== GL_TEXTURE_1D
) {
2431 /* non-proxy target */
2432 struct gl_texture_unit
*texUnit
;
2433 struct gl_texture_object
*texObj
;
2434 struct gl_texture_image
*texImage
;
2435 const GLuint face
= _mesa_tex_target_to_face(target
);
2437 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2438 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2439 return; /* error was recorded */
2442 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2443 _mesa_update_state(ctx
);
2445 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2446 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2447 _mesa_lock_texture(ctx
, texObj
);
2449 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2451 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2455 if (texImage
->Data
) {
2456 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2459 ASSERT(texImage
->Data
== NULL
);
2461 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2462 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2463 postConvWidth
, 1, 1,
2464 border
, internalFormat
);
2466 ASSERT(ctx
->Driver
.TexImage1D
);
2468 /* Give the texture to the driver! <pixels> may be null! */
2469 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2470 width
, border
, format
, type
, pixels
,
2471 &ctx
->Unpack
, texObj
, texImage
);
2473 ASSERT(texImage
->TexFormat
);
2475 update_fbo_texture(ctx
, texObj
, face
, level
);
2478 texObj
->_Complete
= GL_FALSE
;
2479 ctx
->NewState
|= _NEW_TEXTURE
;
2482 _mesa_unlock_texture(ctx
, texObj
);
2484 else if (target
== GL_PROXY_TEXTURE_1D
) {
2485 /* Proxy texture: check for errors and update proxy state */
2486 struct gl_texture_image
*texImage
;
2487 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2488 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2489 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2490 /* when error, clear all proxy texture image parameters */
2492 clear_teximage_fields(texImage
);
2495 /* no error, set the tex image parameters */
2497 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2498 postConvWidth
, 1, 1,
2499 border
, internalFormat
);
2500 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2501 internalFormat
, format
, type
);
2505 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2512 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2513 GLsizei width
, GLsizei height
, GLint border
,
2514 GLenum format
, GLenum type
,
2515 const GLvoid
*pixels
)
2517 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2518 GET_CURRENT_CONTEXT(ctx
);
2519 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2521 #if FEATURE_convolve
2522 if (_mesa_is_color_format(internalFormat
)) {
2523 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2528 if (target
== GL_TEXTURE_2D
||
2529 (ctx
->Extensions
.ARB_texture_cube_map
&&
2530 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2531 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2532 (ctx
->Extensions
.NV_texture_rectangle
&&
2533 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2534 (ctx
->Extensions
.MESA_texture_array
&&
2535 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2536 /* non-proxy target */
2537 struct gl_texture_unit
*texUnit
;
2538 struct gl_texture_object
*texObj
;
2539 struct gl_texture_image
*texImage
;
2540 const GLuint face
= _mesa_tex_target_to_face(target
);
2542 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2543 format
, type
, 2, postConvWidth
, postConvHeight
,
2545 return; /* error was recorded */
2548 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2549 _mesa_update_state(ctx
);
2551 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2552 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2553 _mesa_lock_texture(ctx
, texObj
);
2555 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2557 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2561 if (texImage
->Data
) {
2562 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2565 ASSERT(texImage
->Data
== NULL
);
2566 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2567 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2568 postConvWidth
, postConvHeight
, 1,
2569 border
, internalFormat
);
2571 ASSERT(ctx
->Driver
.TexImage2D
);
2573 /* Give the texture to the driver! <pixels> may be null! */
2574 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2575 width
, height
, border
, format
, type
, pixels
,
2576 &ctx
->Unpack
, texObj
, texImage
);
2578 ASSERT(texImage
->TexFormat
);
2580 update_fbo_texture(ctx
, texObj
, face
, level
);
2583 texObj
->_Complete
= GL_FALSE
;
2584 ctx
->NewState
|= _NEW_TEXTURE
;
2587 _mesa_unlock_texture(ctx
, texObj
);
2589 else if (target
== GL_PROXY_TEXTURE_2D
||
2590 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2591 ctx
->Extensions
.ARB_texture_cube_map
) ||
2592 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2593 ctx
->Extensions
.NV_texture_rectangle
) ||
2594 (ctx
->Extensions
.MESA_texture_array
&&
2595 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2596 /* Proxy texture: check for errors and update proxy state */
2597 struct gl_texture_image
*texImage
;
2598 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2599 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2600 format
, type
, 2, postConvWidth
, postConvHeight
,
2602 /* when error, clear all proxy texture image parameters */
2604 clear_teximage_fields(ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
]);
2607 /* no error, set the tex image parameters */
2608 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2609 postConvWidth
, postConvHeight
, 1,
2610 border
, internalFormat
);
2611 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2612 internalFormat
, format
, type
);
2616 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2623 * Called by the API or display list executor.
2624 * Note that width and height include the border.
2627 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2628 GLsizei width
, GLsizei height
, GLsizei depth
,
2629 GLint border
, GLenum format
, GLenum type
,
2630 const GLvoid
*pixels
)
2632 GET_CURRENT_CONTEXT(ctx
);
2633 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2635 if (target
== GL_TEXTURE_3D
||
2636 (ctx
->Extensions
.MESA_texture_array
&&
2637 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2638 /* non-proxy target */
2639 struct gl_texture_unit
*texUnit
;
2640 struct gl_texture_object
*texObj
;
2641 struct gl_texture_image
*texImage
;
2642 const GLuint face
= _mesa_tex_target_to_face(target
);
2644 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2645 format
, type
, 3, width
, height
, depth
, border
)) {
2646 return; /* error was recorded */
2649 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2650 _mesa_update_state(ctx
);
2652 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2653 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2654 _mesa_lock_texture(ctx
, texObj
);
2656 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2658 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2662 if (texImage
->Data
) {
2663 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2666 ASSERT(texImage
->Data
== NULL
);
2667 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2668 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2669 width
, height
, depth
,
2670 border
, internalFormat
);
2672 ASSERT(ctx
->Driver
.TexImage3D
);
2674 /* Give the texture to the driver! <pixels> may be null! */
2675 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2676 width
, height
, depth
, border
, format
, type
,
2677 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2679 ASSERT(texImage
->TexFormat
);
2681 update_fbo_texture(ctx
, texObj
, face
, level
);
2684 texObj
->_Complete
= GL_FALSE
;
2685 ctx
->NewState
|= _NEW_TEXTURE
;
2688 _mesa_unlock_texture(ctx
, texObj
);
2690 else if (target
== GL_PROXY_TEXTURE_3D
||
2691 (ctx
->Extensions
.MESA_texture_array
&&
2692 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2693 /* Proxy texture: check for errors and update proxy state */
2694 struct gl_texture_image
*texImage
;
2695 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2696 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2697 format
, type
, 3, width
, height
, depth
, border
)) {
2698 /* when error, clear all proxy texture image parameters */
2700 clear_teximage_fields(texImage
);
2703 /* no error, set the tex image parameters */
2704 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2705 depth
, border
, internalFormat
);
2706 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2707 internalFormat
, format
, type
);
2711 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2718 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2719 GLsizei width
, GLsizei height
, GLsizei depth
,
2720 GLint border
, GLenum format
, GLenum type
,
2721 const GLvoid
*pixels
)
2723 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2724 depth
, border
, format
, type
, pixels
);
2730 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2731 GLint xoffset
, GLsizei width
,
2732 GLenum format
, GLenum type
,
2733 const GLvoid
*pixels
)
2735 GLsizei postConvWidth
= width
;
2736 struct gl_texture_unit
*texUnit
;
2737 struct gl_texture_object
*texObj
;
2738 struct gl_texture_image
*texImage
= NULL
;
2739 GET_CURRENT_CONTEXT(ctx
);
2740 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2742 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2743 _mesa_update_state(ctx
);
2745 #if FEATURE_convolve
2746 /* XXX should test internal format */
2747 if (_mesa_is_color_format(format
)) {
2748 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2752 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2753 postConvWidth
, 1, 1, format
, type
)) {
2754 return; /* error was detected */
2758 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2759 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2762 _mesa_lock_texture(ctx
, texObj
);
2764 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2766 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2767 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2768 goto out
; /* error was detected */
2772 goto out
; /* no-op, not an error */
2774 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2775 xoffset
+= texImage
->Border
;
2777 ASSERT(ctx
->Driver
.TexSubImage1D
);
2778 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2779 format
, type
, pixels
, &ctx
->Unpack
,
2781 ctx
->NewState
|= _NEW_TEXTURE
;
2784 _mesa_unlock_texture(ctx
, texObj
);
2789 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2790 GLint xoffset
, GLint yoffset
,
2791 GLsizei width
, GLsizei height
,
2792 GLenum format
, GLenum type
,
2793 const GLvoid
*pixels
)
2795 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2796 struct gl_texture_unit
*texUnit
;
2797 struct gl_texture_object
*texObj
;
2798 struct gl_texture_image
*texImage
;
2799 GET_CURRENT_CONTEXT(ctx
);
2800 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2802 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2803 _mesa_update_state(ctx
);
2805 #if FEATURE_convolve
2806 /* XXX should test internal format */
2807 if (_mesa_is_color_format(format
)) {
2808 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2813 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2814 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2815 return; /* error was detected */
2818 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2819 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2820 _mesa_lock_texture(ctx
, texObj
);
2822 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2824 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2825 postConvWidth
, postConvHeight
, 1, format
, type
,
2827 goto out
; /* error was detected */
2830 if (width
== 0 || height
== 0)
2831 goto out
; /* no-op, not an error */
2833 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2834 xoffset
+= texImage
->Border
;
2835 yoffset
+= texImage
->Border
;
2837 ASSERT(ctx
->Driver
.TexSubImage2D
);
2838 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2839 width
, height
, format
, type
, pixels
,
2840 &ctx
->Unpack
, texObj
, texImage
);
2841 ctx
->NewState
|= _NEW_TEXTURE
;
2844 _mesa_unlock_texture(ctx
, texObj
);
2850 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2851 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2852 GLsizei width
, GLsizei height
, GLsizei depth
,
2853 GLenum format
, GLenum type
,
2854 const GLvoid
*pixels
)
2856 struct gl_texture_unit
*texUnit
;
2857 struct gl_texture_object
*texObj
;
2858 struct gl_texture_image
*texImage
;
2859 GET_CURRENT_CONTEXT(ctx
);
2860 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2862 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2863 _mesa_update_state(ctx
);
2865 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2866 width
, height
, depth
, format
, type
)) {
2867 return; /* error was detected */
2870 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2871 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2873 _mesa_lock_texture(ctx
, texObj
);
2875 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2877 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2878 width
, height
, depth
, format
, type
, texImage
)) {
2879 goto out
; /* error was detected */
2882 if (width
== 0 || height
== 0 || height
== 0)
2883 goto out
; /* no-op, not an error */
2885 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2886 xoffset
+= texImage
->Border
;
2887 yoffset
+= texImage
->Border
;
2888 zoffset
+= texImage
->Border
;
2890 ASSERT(ctx
->Driver
.TexSubImage3D
);
2891 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2892 xoffset
, yoffset
, zoffset
,
2893 width
, height
, depth
,
2894 format
, type
, pixels
,
2895 &ctx
->Unpack
, texObj
, texImage
);
2896 ctx
->NewState
|= _NEW_TEXTURE
;
2899 _mesa_unlock_texture(ctx
, texObj
);
2905 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2906 GLenum internalFormat
,
2908 GLsizei width
, GLint border
)
2910 struct gl_texture_unit
*texUnit
;
2911 struct gl_texture_object
*texObj
;
2912 struct gl_texture_image
*texImage
;
2913 GLsizei postConvWidth
= width
;
2914 const GLuint face
= _mesa_tex_target_to_face(target
);
2915 GET_CURRENT_CONTEXT(ctx
);
2916 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2918 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2919 _mesa_update_state(ctx
);
2921 #if FEATURE_convolve
2922 if (_mesa_is_color_format(internalFormat
)) {
2923 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2927 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2928 postConvWidth
, 1, border
))
2931 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2932 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2933 _mesa_lock_texture(ctx
, texObj
);
2935 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2937 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2941 if (texImage
->Data
) {
2942 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2945 ASSERT(texImage
->Data
== NULL
);
2947 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2948 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2949 border
, internalFormat
);
2952 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2953 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2954 x
, y
, width
, border
);
2956 ASSERT(texImage
->TexFormat
);
2958 update_fbo_texture(ctx
, texObj
, face
, level
);
2961 texObj
->_Complete
= GL_FALSE
;
2962 ctx
->NewState
|= _NEW_TEXTURE
;
2965 _mesa_unlock_texture(ctx
, texObj
);
2971 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2972 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2975 struct gl_texture_unit
*texUnit
;
2976 struct gl_texture_object
*texObj
;
2977 struct gl_texture_image
*texImage
;
2978 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2979 const GLuint face
= _mesa_tex_target_to_face(target
);
2980 GET_CURRENT_CONTEXT(ctx
);
2981 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2983 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2984 _mesa_update_state(ctx
);
2986 #if FEATURE_convolve
2987 if (_mesa_is_color_format(internalFormat
)) {
2988 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2993 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2994 postConvWidth
, postConvHeight
, border
))
2997 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2998 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3000 _mesa_lock_texture(ctx
, texObj
);
3002 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3005 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3009 if (texImage
->Data
) {
3010 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3013 ASSERT(texImage
->Data
== NULL
);
3015 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3016 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3017 postConvWidth
, postConvHeight
, 1,
3018 border
, internalFormat
);
3020 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3021 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3022 x
, y
, width
, height
, border
);
3024 ASSERT(texImage
->TexFormat
);
3026 update_fbo_texture(ctx
, texObj
, face
, level
);
3029 texObj
->_Complete
= GL_FALSE
;
3030 ctx
->NewState
|= _NEW_TEXTURE
;
3033 _mesa_unlock_texture(ctx
, texObj
);
3038 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3039 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3041 struct gl_texture_unit
*texUnit
;
3042 struct gl_texture_object
*texObj
;
3043 struct gl_texture_image
*texImage
;
3044 GLsizei postConvWidth
= width
;
3048 GET_CURRENT_CONTEXT(ctx
);
3049 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3051 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3052 _mesa_update_state(ctx
);
3054 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3057 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3058 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3060 _mesa_lock_texture(ctx
, texObj
);
3062 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3064 #if FEATURE_convolve
3065 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3066 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3070 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3071 xoffset
, 0, 0, postConvWidth
, 1,
3076 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3077 xoffset
+= texImage
->Border
;
3079 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3081 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3082 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3083 xoffset
, x
, y
, width
);
3086 ctx
->NewState
|= _NEW_TEXTURE
;
3089 _mesa_unlock_texture(ctx
, texObj
);
3095 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3096 GLint xoffset
, GLint yoffset
,
3097 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3099 struct gl_texture_unit
*texUnit
;
3100 struct gl_texture_object
*texObj
;
3101 struct gl_texture_image
*texImage
;
3102 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3103 GET_CURRENT_CONTEXT(ctx
);
3104 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3106 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3107 _mesa_update_state(ctx
);
3109 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3112 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3113 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3115 _mesa_lock_texture(ctx
, texObj
);
3117 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3119 #if FEATURE_convolve
3120 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3121 _mesa_adjust_image_for_convolution(ctx
, 2,
3122 &postConvWidth
, &postConvHeight
);
3126 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3127 postConvWidth
, postConvHeight
, texImage
))
3130 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3131 xoffset
+= texImage
->Border
;
3132 yoffset
+= texImage
->Border
;
3134 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3136 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3137 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3138 xoffset
, yoffset
, x
, y
, width
, height
);
3141 ctx
->NewState
|= _NEW_TEXTURE
;
3144 _mesa_unlock_texture(ctx
, texObj
);
3150 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3151 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3152 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3154 struct gl_texture_unit
*texUnit
;
3155 struct gl_texture_object
*texObj
;
3156 struct gl_texture_image
*texImage
;
3157 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3158 GET_CURRENT_CONTEXT(ctx
);
3159 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3161 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3162 _mesa_update_state(ctx
);
3164 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3167 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3168 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3170 _mesa_lock_texture(ctx
, texObj
);
3172 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3174 #if FEATURE_convolve
3175 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3176 _mesa_adjust_image_for_convolution(ctx
, 2,
3177 &postConvWidth
, &postConvHeight
);
3181 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3182 zoffset
, postConvWidth
, postConvHeight
,
3186 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3187 xoffset
+= texImage
->Border
;
3188 yoffset
+= texImage
->Border
;
3189 zoffset
+= texImage
->Border
;
3191 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3193 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3194 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3195 xoffset
, yoffset
, zoffset
,
3196 x
, y
, width
, height
);
3199 ctx
->NewState
|= _NEW_TEXTURE
;
3202 _mesa_unlock_texture(ctx
, texObj
);
3208 /**********************************************************************/
3209 /****** Compressed Textures ******/
3210 /**********************************************************************/
3214 * Error checking for glCompressedTexImage[123]D().
3215 * \return error code or GL_NO_ERROR.
3218 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3219 GLenum target
, GLint level
,
3220 GLenum internalFormat
, GLsizei width
,
3221 GLsizei height
, GLsizei depth
, GLint border
,
3224 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3226 if (dimensions
== 1) {
3227 /* 1D compressed textures not allowed */
3228 return GL_INVALID_ENUM
;
3230 else if (dimensions
== 2) {
3231 if (target
== GL_PROXY_TEXTURE_2D
) {
3232 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3234 else if (target
== GL_TEXTURE_2D
) {
3235 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3237 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3238 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3239 return GL_INVALID_ENUM
; /*target*/
3240 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3242 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3243 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3244 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3245 return GL_INVALID_ENUM
; /*target*/
3246 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3249 return GL_INVALID_ENUM
; /*target*/
3252 else if (dimensions
== 3) {
3253 /* 3D compressed textures not allowed */
3254 return GL_INVALID_ENUM
;
3257 maxTextureSize
= 1 << (maxLevels
- 1);
3259 /* This will detect any invalid internalFormat value */
3260 if (!is_compressed_format(ctx
, internalFormat
))
3261 return GL_INVALID_ENUM
;
3263 /* This should really never fail */
3264 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3265 return GL_INVALID_ENUM
;
3268 return GL_INVALID_VALUE
;
3271 * XXX We should probably use the proxy texture error check function here.
3273 if (width
< 1 || width
> maxTextureSize
||
3274 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3275 return GL_INVALID_VALUE
;
3277 if ((height
< 1 || height
> maxTextureSize
||
3278 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3280 return GL_INVALID_VALUE
;
3282 if ((depth
< 1 || depth
> maxTextureSize
||
3283 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3285 return GL_INVALID_VALUE
;
3287 /* For cube map, width must equal height */
3288 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3289 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3290 return GL_INVALID_VALUE
;
3292 if (level
< 0 || level
>= maxLevels
)
3293 return GL_INVALID_VALUE
;
3295 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3296 depth
, internalFormat
);
3297 if (expectedSize
!= imageSize
)
3298 return GL_INVALID_VALUE
;
3300 #if FEATURE_EXT_texture_sRGB
3301 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3302 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3303 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3304 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3306 return GL_INVALID_OPERATION
;
3315 * Error checking for glCompressedTexSubImage[123]D().
3316 * \warning There are some bad assumptions here about the size of compressed
3317 * texture tiles (multiple of 4) used to test the validity of the
3318 * offset and size parameters.
3319 * \return error code or GL_NO_ERROR.
3322 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3323 GLenum target
, GLint level
,
3324 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3325 GLsizei width
, GLsizei height
, GLsizei depth
,
3326 GLenum format
, GLsizei imageSize
)
3328 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3331 if (dimensions
== 1) {
3332 /* 1D compressed textures not allowed */
3333 return GL_INVALID_ENUM
;
3335 else if (dimensions
== 2) {
3336 if (target
== GL_PROXY_TEXTURE_2D
) {
3337 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3339 else if (target
== GL_TEXTURE_2D
) {
3340 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3342 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3343 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3344 return GL_INVALID_ENUM
; /*target*/
3345 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3347 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3348 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3349 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3350 return GL_INVALID_ENUM
; /*target*/
3351 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3354 return GL_INVALID_ENUM
; /*target*/
3357 else if (dimensions
== 3) {
3358 /* 3D compressed textures not allowed */
3359 return GL_INVALID_ENUM
;
3362 maxTextureSize
= 1 << (maxLevels
- 1);
3364 /* this will catch any invalid compressed format token */
3365 if (!is_compressed_format(ctx
, format
))
3366 return GL_INVALID_ENUM
;
3368 if (width
< 1 || width
> maxTextureSize
)
3369 return GL_INVALID_VALUE
;
3371 if ((height
< 1 || height
> maxTextureSize
)
3373 return GL_INVALID_VALUE
;
3375 if (level
< 0 || level
>= maxLevels
)
3376 return GL_INVALID_VALUE
;
3378 /* XXX these tests are specific to the compressed format.
3379 * this code should be generalized in some way.
3381 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3382 return GL_INVALID_VALUE
;
3384 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3385 return GL_INVALID_VALUE
;
3387 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3388 return GL_INVALID_VALUE
;
3390 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3392 if (expectedSize
!= imageSize
)
3393 return GL_INVALID_VALUE
;
3401 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3402 GLenum internalFormat
, GLsizei width
,
3403 GLint border
, GLsizei imageSize
,
3406 GET_CURRENT_CONTEXT(ctx
);
3407 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3409 if (target
== GL_TEXTURE_1D
) {
3410 /* non-proxy target */
3411 struct gl_texture_unit
*texUnit
;
3412 struct gl_texture_object
*texObj
;
3413 struct gl_texture_image
*texImage
;
3414 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3415 internalFormat
, width
, 1, 1, border
, imageSize
);
3417 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3421 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3422 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3424 _mesa_lock_texture(ctx
, texObj
);
3426 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3428 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3432 if (texImage
->Data
) {
3433 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3435 ASSERT(texImage
->Data
== NULL
);
3437 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3438 border
, internalFormat
);
3440 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3441 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3442 internalFormat
, width
, border
,
3447 texObj
->_Complete
= GL_FALSE
;
3448 ctx
->NewState
|= _NEW_TEXTURE
;
3451 _mesa_unlock_texture(ctx
, texObj
);
3453 else if (target
== GL_PROXY_TEXTURE_1D
) {
3454 /* Proxy texture: check for errors and update proxy state */
3455 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3456 internalFormat
, width
, 1, 1, border
, imageSize
);
3458 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3459 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3460 internalFormat
, GL_NONE
, GL_NONE
,
3461 width
, 1, 1, border
);
3464 /* if error, clear all proxy texture image parameters */
3465 struct gl_texture_image
*texImage
;
3466 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3468 clear_teximage_fields(texImage
);
3471 /* store the teximage parameters */
3472 struct gl_texture_unit
*texUnit
;
3473 struct gl_texture_object
*texObj
;
3474 struct gl_texture_image
*texImage
;
3475 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3476 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3478 _mesa_lock_texture(ctx
, texObj
);
3480 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3481 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3482 border
, internalFormat
);
3484 _mesa_unlock_texture(ctx
, texObj
);
3488 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3495 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3496 GLenum internalFormat
, GLsizei width
,
3497 GLsizei height
, GLint border
, GLsizei imageSize
,
3500 GET_CURRENT_CONTEXT(ctx
);
3501 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3503 if (target
== GL_TEXTURE_2D
||
3504 (ctx
->Extensions
.ARB_texture_cube_map
&&
3505 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3506 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3507 /* non-proxy target */
3508 struct gl_texture_unit
*texUnit
;
3509 struct gl_texture_object
*texObj
;
3510 struct gl_texture_image
*texImage
;
3511 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3512 internalFormat
, width
, height
, 1, border
, imageSize
);
3514 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3518 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3519 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3521 _mesa_lock_texture(ctx
, texObj
);
3523 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3525 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3529 if (texImage
->Data
) {
3530 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3532 ASSERT(texImage
->Data
== NULL
);
3534 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3535 border
, internalFormat
);
3537 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3538 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3539 internalFormat
, width
, height
,
3540 border
, imageSize
, data
,
3544 texObj
->_Complete
= GL_FALSE
;
3545 ctx
->NewState
|= _NEW_TEXTURE
;
3548 _mesa_unlock_texture(ctx
, texObj
);
3550 else if (target
== GL_PROXY_TEXTURE_2D
||
3551 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3552 ctx
->Extensions
.ARB_texture_cube_map
)) {
3553 /* Proxy texture: check for errors and update proxy state */
3554 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3555 internalFormat
, width
, height
, 1, border
, imageSize
);
3557 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3558 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3559 internalFormat
, GL_NONE
, GL_NONE
,
3560 width
, height
, 1, border
);
3563 /* if error, clear all proxy texture image parameters */
3564 struct gl_texture_image
*texImage
;
3565 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3567 clear_teximage_fields(texImage
);
3570 /* store the teximage parameters */
3571 struct gl_texture_unit
*texUnit
;
3572 struct gl_texture_object
*texObj
;
3573 struct gl_texture_image
*texImage
;
3574 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3575 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3577 _mesa_lock_texture(ctx
, texObj
);
3579 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3580 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3581 border
, internalFormat
);
3583 _mesa_unlock_texture(ctx
, texObj
);
3587 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3594 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3595 GLenum internalFormat
, GLsizei width
,
3596 GLsizei height
, GLsizei depth
, GLint border
,
3597 GLsizei imageSize
, const GLvoid
*data
)
3599 GET_CURRENT_CONTEXT(ctx
);
3600 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3602 if (target
== GL_TEXTURE_3D
) {
3603 /* non-proxy target */
3604 struct gl_texture_unit
*texUnit
;
3605 struct gl_texture_object
*texObj
;
3606 struct gl_texture_image
*texImage
;
3607 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3608 internalFormat
, width
, height
, depth
, border
, imageSize
);
3610 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3614 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3615 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3616 _mesa_lock_texture(ctx
, texObj
);
3618 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3620 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3624 if (texImage
->Data
) {
3625 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3627 ASSERT(texImage
->Data
== NULL
);
3629 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3630 border
, internalFormat
);
3632 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3633 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3635 width
, height
, depth
,
3636 border
, imageSize
, data
,
3640 texObj
->_Complete
= GL_FALSE
;
3641 ctx
->NewState
|= _NEW_TEXTURE
;
3644 _mesa_unlock_texture(ctx
, texObj
);
3646 else if (target
== GL_PROXY_TEXTURE_3D
) {
3647 /* Proxy texture: check for errors and update proxy state */
3648 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3649 internalFormat
, width
, height
, depth
, border
, imageSize
);
3651 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3652 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3653 internalFormat
, GL_NONE
, GL_NONE
,
3654 width
, height
, depth
, border
);
3657 /* if error, clear all proxy texture image parameters */
3658 struct gl_texture_image
*texImage
;
3659 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3661 clear_teximage_fields(texImage
);
3664 /* store the teximage parameters */
3665 struct gl_texture_unit
*texUnit
;
3666 struct gl_texture_object
*texObj
;
3667 struct gl_texture_image
*texImage
;
3668 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3669 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3670 _mesa_lock_texture(ctx
, texObj
);
3672 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3673 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3674 depth
, border
, internalFormat
);
3676 _mesa_unlock_texture(ctx
, texObj
);
3680 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3687 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3688 GLsizei width
, GLenum format
,
3689 GLsizei imageSize
, const GLvoid
*data
)
3691 struct gl_texture_unit
*texUnit
;
3692 struct gl_texture_object
*texObj
;
3693 struct gl_texture_image
*texImage
;
3695 GET_CURRENT_CONTEXT(ctx
);
3696 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3698 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3699 xoffset
, 0, 0, /* pos */
3700 width
, 1, 1, /* size */
3703 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3707 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3708 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3709 _mesa_lock_texture(ctx
, texObj
);
3711 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3714 if ((GLint
) format
!= texImage
->InternalFormat
) {
3715 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3716 "glCompressedTexSubImage1D(format)");
3720 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3721 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3726 goto out
; /* no-op, not an error */
3728 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3729 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3731 format
, imageSize
, data
,
3734 ctx
->NewState
|= _NEW_TEXTURE
;
3737 _mesa_unlock_texture(ctx
, texObj
);
3742 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3743 GLint yoffset
, GLsizei width
, GLsizei height
,
3744 GLenum format
, GLsizei imageSize
,
3747 struct gl_texture_unit
*texUnit
;
3748 struct gl_texture_object
*texObj
;
3749 struct gl_texture_image
*texImage
;
3751 GET_CURRENT_CONTEXT(ctx
);
3752 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3754 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3755 xoffset
, yoffset
, 0, /* pos */
3756 width
, height
, 1, /* size */
3759 /* XXX proxy target? */
3760 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3764 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3765 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3766 _mesa_lock_texture(ctx
, texObj
);
3768 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3771 if ((GLint
) format
!= texImage
->InternalFormat
) {
3772 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3773 "glCompressedTexSubImage2D(format)");
3777 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3778 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3779 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3783 if (width
== 0 || height
== 0)
3784 goto out
; /* no-op, not an error */
3786 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3787 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3788 xoffset
, yoffset
, width
, height
,
3789 format
, imageSize
, data
,
3792 ctx
->NewState
|= _NEW_TEXTURE
;
3795 _mesa_unlock_texture(ctx
, texObj
);
3800 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3801 GLint yoffset
, GLint zoffset
, GLsizei width
,
3802 GLsizei height
, GLsizei depth
, GLenum format
,
3803 GLsizei imageSize
, const GLvoid
*data
)
3805 struct gl_texture_unit
*texUnit
;
3806 struct gl_texture_object
*texObj
;
3807 struct gl_texture_image
*texImage
;
3809 GET_CURRENT_CONTEXT(ctx
);
3810 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3812 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3813 xoffset
, yoffset
, zoffset
,/*pos*/
3814 width
, height
, depth
, /*size*/
3817 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3821 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3822 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3823 _mesa_lock_texture(ctx
, texObj
);
3825 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3828 if ((GLint
) format
!= texImage
->InternalFormat
) {
3829 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3830 "glCompressedTexSubImage3D(format)");
3834 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3835 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3836 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3837 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3841 if (width
== 0 || height
== 0 || depth
== 0)
3842 goto out
; /* no-op, not an error */
3844 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3845 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3846 xoffset
, yoffset
, zoffset
,
3847 width
, height
, depth
,
3848 format
, imageSize
, data
,
3851 ctx
->NewState
|= _NEW_TEXTURE
;
3854 _mesa_unlock_texture(ctx
, texObj
);
3859 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3861 const struct gl_texture_unit
*texUnit
;
3862 struct gl_texture_object
*texObj
;
3863 struct gl_texture_image
*texImage
;
3865 GET_CURRENT_CONTEXT(ctx
);
3866 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3868 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3869 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3871 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3875 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3876 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3878 if (level
< 0 || level
>= maxLevels
) {
3879 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3883 if (_mesa_is_proxy_texture(target
)) {
3884 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3888 _mesa_lock_texture(ctx
, texObj
);
3890 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3892 if (texImage
->IsCompressed
) {
3893 /* this typically calls _mesa_get_compressed_teximage() */
3894 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3898 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3899 "glGetCompressedTexImageARB");
3903 /* probably invalid mipmap level */
3904 _mesa_error(ctx
, GL_INVALID_VALUE
,
3905 "glGetCompressedTexImageARB(level)");
3908 _mesa_unlock_texture(ctx
, texObj
);