2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
40 #include "framebuffer.h"
46 #include "texcompress.h"
47 #include "texformat.h"
55 * State changes which we care about for glCopyTex[Sub]Image() calls.
56 * In particular, we care about pixel transfer state and buffer state
57 * (such as glReadBuffer to make sure we read from the right renderbuffer).
59 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
66 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
70 _mesa_alloc_texmemory(GLsizei bytes
)
72 return _mesa_align_malloc(bytes
, 512);
77 * Free texture memory allocated with _mesa_alloc_texmemory()
80 _mesa_free_texmemory(void *m
)
89 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
91 #if CHAN_TYPE != GL_UNSIGNED_BYTE
92 _mesa_problem(NULL
, "PrintTexture not supported");
95 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
98 _mesa_printf("No texture data\n");
102 switch (img
->Format
) {
109 case GL_LUMINANCE_ALPHA
:
119 _mesa_problem(NULL
, "error in PrintTexture\n");
123 for (i
= 0; i
< img
->Height
; i
++) {
124 for (j
= 0; j
< img
->Width
; j
++) {
126 _mesa_printf("%02x ", data
[0]);
128 _mesa_printf("%02x%02x ", data
[0], data
[1]);
130 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
132 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
133 data
+= (img
->RowStride
- img
->Width
) * c
;
135 /* XXX use img->ImageStride here */
144 * Compute floor(log_base_2(n)).
145 * If n < 0 return -1.
174 * Return the simple base format for a given internal texture format.
175 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
177 * \param ctx GL context.
178 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
180 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
181 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
183 * This is the format which is used during texture application (i.e. the
184 * texture format and env mode determine the arithmetic used.
187 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
189 switch (internalFormat
) {
204 case GL_LUMINANCE_ALPHA
:
205 case GL_LUMINANCE4_ALPHA4
:
206 case GL_LUMINANCE6_ALPHA2
:
207 case GL_LUMINANCE8_ALPHA8
:
208 case GL_LUMINANCE12_ALPHA4
:
209 case GL_LUMINANCE12_ALPHA12
:
210 case GL_LUMINANCE16_ALPHA16
:
211 return GL_LUMINANCE_ALPHA
;
242 if (ctx
->Extensions
.EXT_paletted_texture
) {
243 switch (internalFormat
) {
245 case GL_COLOR_INDEX1_EXT
:
246 case GL_COLOR_INDEX2_EXT
:
247 case GL_COLOR_INDEX4_EXT
:
248 case GL_COLOR_INDEX8_EXT
:
249 case GL_COLOR_INDEX12_EXT
:
250 case GL_COLOR_INDEX16_EXT
:
251 return GL_COLOR_INDEX
;
257 if (ctx
->Extensions
.ARB_depth_texture
) {
258 switch (internalFormat
) {
259 case GL_DEPTH_COMPONENT
:
260 case GL_DEPTH_COMPONENT16
:
261 case GL_DEPTH_COMPONENT24
:
262 case GL_DEPTH_COMPONENT32
:
263 return GL_DEPTH_COMPONENT
;
269 switch (internalFormat
) {
270 case GL_COMPRESSED_ALPHA
:
272 case GL_COMPRESSED_LUMINANCE
:
274 case GL_COMPRESSED_LUMINANCE_ALPHA
:
275 return GL_LUMINANCE_ALPHA
;
276 case GL_COMPRESSED_INTENSITY
:
278 case GL_COMPRESSED_RGB
:
280 case GL_COMPRESSED_RGBA
:
286 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
287 switch (internalFormat
) {
288 case GL_COMPRESSED_RGB_FXT1_3DFX
:
290 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
297 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
298 switch (internalFormat
) {
299 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
301 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
302 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
303 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
310 if (ctx
->Extensions
.S3_s3tc
) {
311 switch (internalFormat
) {
323 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
324 if (internalFormat
== GL_YCBCR_MESA
)
325 return GL_YCBCR_MESA
;
328 if (ctx
->Extensions
.ARB_texture_float
) {
329 switch (internalFormat
) {
330 case GL_ALPHA16F_ARB
:
331 case GL_ALPHA32F_ARB
:
339 case GL_INTENSITY16F_ARB
:
340 case GL_INTENSITY32F_ARB
:
342 case GL_LUMINANCE16F_ARB
:
343 case GL_LUMINANCE32F_ARB
:
345 case GL_LUMINANCE_ALPHA16F_ARB
:
346 case GL_LUMINANCE_ALPHA32F_ARB
:
347 return GL_LUMINANCE_ALPHA
;
353 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
354 switch (internalFormat
) {
363 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
364 switch (internalFormat
) {
373 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
374 switch (internalFormat
) {
375 case GL_DEPTH_STENCIL_EXT
:
376 case GL_DEPTH24_STENCIL8_EXT
:
377 return GL_DEPTH_STENCIL_EXT
;
383 #if FEATURE_EXT_texture_sRGB
384 if (ctx
->Extensions
.EXT_texture_sRGB
) {
385 switch (internalFormat
) {
388 case GL_COMPRESSED_SRGB_EXT
:
389 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
391 case GL_SRGB_ALPHA_EXT
:
392 case GL_SRGB8_ALPHA8_EXT
:
393 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
394 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
395 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
396 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
398 case GL_SLUMINANCE_ALPHA_EXT
:
399 case GL_SLUMINANCE8_ALPHA8_EXT
:
400 case GL_COMPRESSED_SLUMINANCE_EXT
:
401 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
402 return GL_LUMINANCE_ALPHA
;
403 case GL_SLUMINANCE_EXT
:
404 case GL_SLUMINANCE8_EXT
:
411 #endif /* FEATURE_EXT_texture_sRGB */
413 return -1; /* error */
418 * Test if the given image format is a color/RGBA format (i.e., not color
419 * index, depth, stencil, etc).
420 * \param format the image format value (may by an internal texture format)
421 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
422 * XXX maybe move this func to image.c
425 _mesa_is_color_format(GLenum format
)
443 case GL_LUMINANCE_ALPHA
:
444 case GL_LUMINANCE4_ALPHA4
:
445 case GL_LUMINANCE6_ALPHA2
:
446 case GL_LUMINANCE8_ALPHA8
:
447 case GL_LUMINANCE12_ALPHA4
:
448 case GL_LUMINANCE12_ALPHA12
:
449 case GL_LUMINANCE16_ALPHA16
:
476 /* float texture formats */
477 case GL_ALPHA16F_ARB
:
478 case GL_ALPHA32F_ARB
:
479 case GL_LUMINANCE16F_ARB
:
480 case GL_LUMINANCE32F_ARB
:
481 case GL_LUMINANCE_ALPHA16F_ARB
:
482 case GL_LUMINANCE_ALPHA32F_ARB
:
483 case GL_INTENSITY16F_ARB
:
484 case GL_INTENSITY32F_ARB
:
489 /* compressed formats */
490 case GL_COMPRESSED_ALPHA
:
491 case GL_COMPRESSED_LUMINANCE
:
492 case GL_COMPRESSED_LUMINANCE_ALPHA
:
493 case GL_COMPRESSED_INTENSITY
:
494 case GL_COMPRESSED_RGB
:
495 case GL_COMPRESSED_RGBA
:
500 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
501 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
502 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
503 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
504 case GL_COMPRESSED_RGB_FXT1_3DFX
:
505 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
506 #if FEATURE_EXT_texture_sRGB
509 case GL_SRGB_ALPHA_EXT
:
510 case GL_SRGB8_ALPHA8_EXT
:
511 case GL_SLUMINANCE_ALPHA_EXT
:
512 case GL_SLUMINANCE8_ALPHA8_EXT
:
513 case GL_SLUMINANCE_EXT
:
514 case GL_SLUMINANCE8_EXT
:
515 case GL_COMPRESSED_SRGB_EXT
:
516 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
517 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
518 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
519 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
520 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
521 case GL_COMPRESSED_SLUMINANCE_EXT
:
522 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
523 #endif /* FEATURE_EXT_texture_sRGB */
525 /* signed texture formats */
529 case GL_YCBCR_MESA
: /* not considered to be RGB */
538 * Test if the given image format is a color index format.
541 is_index_format(GLenum format
)
545 case GL_COLOR_INDEX1_EXT
:
546 case GL_COLOR_INDEX2_EXT
:
547 case GL_COLOR_INDEX4_EXT
:
548 case GL_COLOR_INDEX8_EXT
:
549 case GL_COLOR_INDEX12_EXT
:
550 case GL_COLOR_INDEX16_EXT
:
559 * Test if the given image format is a depth component format.
562 is_depth_format(GLenum format
)
565 case GL_DEPTH_COMPONENT16
:
566 case GL_DEPTH_COMPONENT24
:
567 case GL_DEPTH_COMPONENT32
:
568 case GL_DEPTH_COMPONENT
:
577 * Test if the given image format is a YCbCr format.
580 is_ycbcr_format(GLenum format
)
592 * Test if the given image format is a Depth/Stencil format.
595 is_depthstencil_format(GLenum format
)
598 case GL_DEPTH24_STENCIL8_EXT
:
599 case GL_DEPTH_STENCIL_EXT
:
607 * Test if the given image format is a dudv format.
610 is_dudv_format(GLenum format
)
623 * Test if it is a supported compressed format.
625 * \param internalFormat the internal format token provided by the user.
627 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
628 * GL_FALSE otherwise.
630 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
634 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
636 GLint supported
[100]; /* 100 should be plenty */
639 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
641 for (i
= 0; i
< n
; i
++) {
642 if ((GLint
) internalFormat
== supported
[i
]) {
651 * For cube map faces, return a face index in [0,5].
652 * For other targets return 0;
655 _mesa_tex_target_to_face(GLenum target
)
657 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
658 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
659 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
667 * Store a gl_texture_image pointer in a gl_texture_object structure
668 * according to the target and level parameters.
670 * \param tObj texture object.
671 * \param target texture target.
672 * \param level image level.
673 * \param texImage texture image.
675 * This was basically prompted by the introduction of cube maps.
678 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
679 GLenum target
, GLint level
,
680 struct gl_texture_image
*texImage
)
684 /* XXX simplify this with _mesa_tex_target_to_face() */
689 case GL_TEXTURE_1D_ARRAY_EXT
:
690 case GL_TEXTURE_2D_ARRAY_EXT
:
691 tObj
->Image
[0][level
] = texImage
;
693 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
694 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
695 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
696 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
697 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
698 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
700 GLuint face
= ((GLuint
) target
-
701 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
702 tObj
->Image
[face
][level
] = texImage
;
705 case GL_TEXTURE_RECTANGLE_NV
:
707 tObj
->Image
[0][level
] = texImage
;
710 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
713 /* Set the 'back' pointer */
714 texImage
->TexObject
= tObj
;
719 * Allocate a texture image structure.
721 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
724 * \return a pointer to gl_texture_image struct with all fields initialized to
727 struct gl_texture_image
*
728 _mesa_new_texture_image( GLcontext
*ctx
)
731 return CALLOC_STRUCT(gl_texture_image
);
736 * Free texture image data.
737 * This function is a fallback called via ctx->Driver.FreeTexImageData().
739 * \param texImage texture image.
741 * Free the texture image data if it's not marked as client data.
744 _mesa_free_texture_image_data(GLcontext
*ctx
,
745 struct gl_texture_image
*texImage
)
749 if (texImage
->Data
&& !texImage
->IsClientData
) {
750 /* free the old texture data */
751 _mesa_free_texmemory(texImage
->Data
);
754 texImage
->Data
= NULL
;
759 * Free texture image.
761 * \param texImage texture image.
763 * Free the texture image structure and the associated image data.
766 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
768 /* Free texImage->Data and/or any other driver-specific texture
771 ASSERT(ctx
->Driver
.FreeTexImageData
);
772 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
774 ASSERT(texImage
->Data
== NULL
);
775 if (texImage
->ImageOffsets
)
776 _mesa_free(texImage
->ImageOffsets
);
777 _mesa_free(texImage
);
782 * Test if a target is a proxy target.
784 * \param target texture target.
786 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
789 _mesa_is_proxy_texture(GLenum target
)
791 return (target
== GL_PROXY_TEXTURE_1D
||
792 target
== GL_PROXY_TEXTURE_2D
||
793 target
== GL_PROXY_TEXTURE_3D
||
794 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
795 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
796 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
797 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
802 * Get the texture object that corresponds to the target of the given texture unit.
804 * \param ctx GL context.
805 * \param texUnit texture unit.
806 * \param target texture target.
808 * \return pointer to the texture object on success, or NULL on failure.
810 * \sa gl_texture_unit.
812 struct gl_texture_object
*
813 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
818 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
819 case GL_PROXY_TEXTURE_1D
:
820 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
822 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
823 case GL_PROXY_TEXTURE_2D
:
824 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
826 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
827 case GL_PROXY_TEXTURE_3D
:
828 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
829 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
830 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
831 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
832 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
833 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
834 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
835 case GL_TEXTURE_CUBE_MAP_ARB
:
836 return ctx
->Extensions
.ARB_texture_cube_map
837 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
838 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
839 return ctx
->Extensions
.ARB_texture_cube_map
840 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
841 case GL_TEXTURE_RECTANGLE_NV
:
842 return ctx
->Extensions
.NV_texture_rectangle
843 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
844 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
845 return ctx
->Extensions
.NV_texture_rectangle
846 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
847 case GL_TEXTURE_1D_ARRAY_EXT
:
848 return ctx
->Extensions
.MESA_texture_array
849 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
850 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
851 return ctx
->Extensions
.MESA_texture_array
852 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
853 case GL_TEXTURE_2D_ARRAY_EXT
:
854 return ctx
->Extensions
.MESA_texture_array
855 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
856 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
857 return ctx
->Extensions
.MESA_texture_array
858 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
860 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
867 * Get the texture image struct which corresponds to target and level
868 * of the given texture unit.
870 * \param ctx GL context.
871 * \param texObj texture unit.
872 * \param target texture target.
873 * \param level image level.
875 * \return pointer to the texture image structure on success, or NULL on failure.
877 * \sa gl_texture_unit.
879 struct gl_texture_image
*
880 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
881 GLenum target
, GLint level
)
885 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
)
888 /* XXX simplify this with _mesa_tex_target_to_face() */
891 case GL_PROXY_TEXTURE_1D
:
893 case GL_PROXY_TEXTURE_2D
:
895 case GL_PROXY_TEXTURE_3D
:
896 return texObj
->Image
[0][level
];
898 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
899 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
900 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
901 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
902 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
903 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
904 if (ctx
->Extensions
.ARB_texture_cube_map
) {
905 GLuint face
= ((GLuint
) target
-
906 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
907 return texObj
->Image
[face
][level
];
912 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
913 if (ctx
->Extensions
.ARB_texture_cube_map
)
914 return texObj
->Image
[0][level
];
918 case GL_TEXTURE_RECTANGLE_NV
:
919 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
920 if (ctx
->Extensions
.NV_texture_rectangle
&& level
== 0)
921 return texObj
->Image
[0][level
];
925 case GL_TEXTURE_1D_ARRAY_EXT
:
926 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
927 case GL_TEXTURE_2D_ARRAY_EXT
:
928 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
929 return (ctx
->Extensions
.MESA_texture_array
)
930 ? texObj
->Image
[0][level
] : NULL
;
939 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
940 * it and install it. Only return NULL if passed a bad parameter or run
943 struct gl_texture_image
*
944 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
945 GLenum target
, GLint level
)
947 struct gl_texture_image
*texImage
;
952 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
954 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
956 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
960 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
968 * Return pointer to the specified proxy texture image.
969 * Note that proxy textures are per-context, not per-texture unit.
970 * \return pointer to texture image or NULL if invalid target, invalid
971 * level, or out of memory.
973 struct gl_texture_image
*
974 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
976 struct gl_texture_image
*texImage
;
983 case GL_PROXY_TEXTURE_1D
:
984 if (level
>= ctx
->Const
.MaxTextureLevels
)
986 texIndex
= TEXTURE_1D_INDEX
;
988 case GL_PROXY_TEXTURE_2D
:
989 if (level
>= ctx
->Const
.MaxTextureLevels
)
991 texIndex
= TEXTURE_2D_INDEX
;
993 case GL_PROXY_TEXTURE_3D
:
994 if (level
>= ctx
->Const
.Max3DTextureLevels
)
996 texIndex
= TEXTURE_3D_INDEX
;
998 case GL_PROXY_TEXTURE_CUBE_MAP
:
999 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1001 texIndex
= TEXTURE_CUBE_INDEX
;
1003 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1006 texIndex
= TEXTURE_RECT_INDEX
;
1008 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1009 if (level
>= ctx
->Const
.MaxTextureLevels
)
1011 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
1013 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1014 if (level
>= ctx
->Const
.MaxTextureLevels
)
1016 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
1022 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
1024 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1026 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1029 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
1030 /* Set the 'back' pointer */
1031 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
1038 * Get the maximum number of allowed mipmap levels.
1040 * \param ctx GL context.
1041 * \param target texture target.
1043 * \return the maximum number of allowed mipmap levels for the given
1044 * texture target, or zero if passed a bad target.
1049 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
1053 case GL_PROXY_TEXTURE_1D
:
1055 case GL_PROXY_TEXTURE_2D
:
1056 case GL_TEXTURE_1D_ARRAY_EXT
:
1057 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1058 case GL_TEXTURE_2D_ARRAY_EXT
:
1059 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1060 return ctx
->Const
.MaxTextureLevels
;
1062 case GL_PROXY_TEXTURE_3D
:
1063 return ctx
->Const
.Max3DTextureLevels
;
1064 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1065 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1066 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1067 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1068 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1069 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1070 case GL_TEXTURE_CUBE_MAP_ARB
:
1071 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1072 return ctx
->Const
.MaxCubeTextureLevels
;
1073 case GL_TEXTURE_RECTANGLE_NV
:
1074 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1077 return 0; /* bad target */
1083 #if 000 /* not used anymore */
1085 * glTexImage[123]D can accept a NULL image pointer. In this case we
1086 * create a texture image with unspecified image contents per the OpenGL
1090 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1092 const GLint components
= _mesa_components_in_format(format
);
1093 const GLint numPixels
= width
* height
* depth
;
1094 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1098 * Let's see if anyone finds this. If glTexImage2D() is called with
1099 * a NULL image pointer then load the texture image with something
1100 * interesting instead of leaving it indeterminate.
1103 static const char message
[8][32] = {
1104 " X X XXXXX XXX X ",
1105 " XX XX X X X X X ",
1107 " X X XXXX XXX XXXXX ",
1110 " X X XXXXX XXX X X ",
1114 GLubyte
*imgPtr
= data
;
1116 for (h
= 0; h
< depth
; h
++) {
1117 for (i
= 0; i
< height
; i
++) {
1118 GLint srcRow
= 7 - (i
% 8);
1119 for (j
= 0; j
< width
; j
++) {
1120 GLint srcCol
= j
% 32;
1121 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1122 for (k
= 0; k
< components
; k
++) {
1138 * Reset the fields of a gl_texture_image struct to zero.
1140 * \param img texture image structure.
1142 * This is called when a proxy texture test fails, we set all the
1143 * image members (except DriverData) to zero.
1144 * It's also used in glTexImage[123]D as a safeguard to be sure all
1145 * required fields get initialized properly by the Driver.TexImage[123]D
1149 clear_teximage_fields(struct gl_texture_image
*img
)
1152 img
->_BaseFormat
= 0;
1153 img
->InternalFormat
= 0;
1159 if (img
->ImageOffsets
) {
1160 _mesa_free(img
->ImageOffsets
);
1161 img
->ImageOffsets
= NULL
;
1167 img
->HeightLog2
= 0;
1170 img
->TexFormat
= &_mesa_null_texformat
;
1171 img
->FetchTexelc
= NULL
;
1172 img
->FetchTexelf
= NULL
;
1173 img
->IsCompressed
= 0;
1174 img
->CompressedSize
= 0;
1179 * Initialize basic fields of the gl_texture_image struct.
1181 * \param ctx GL context.
1182 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1183 * \param img texture image structure to be initialized.
1184 * \param width image width.
1185 * \param height image height.
1186 * \param depth image depth.
1187 * \param border image border.
1188 * \param internalFormat internal format.
1190 * Fills in the fields of \p img with the given information.
1191 * Note: width, height and depth include the border.
1194 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1195 struct gl_texture_image
*img
,
1196 GLsizei width
, GLsizei height
, GLsizei depth
,
1197 GLint border
, GLenum internalFormat
)
1203 ASSERT(height
>= 0);
1206 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1207 ASSERT(img
->_BaseFormat
> 0);
1208 img
->InternalFormat
= internalFormat
;
1209 img
->Border
= border
;
1211 img
->Height
= height
;
1214 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1215 img
->WidthLog2
= logbase2(img
->Width2
);
1217 if (height
== 1) { /* 1-D texture */
1219 img
->HeightLog2
= 0;
1222 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1223 img
->HeightLog2
= logbase2(img
->Height2
);
1226 if (depth
== 1) { /* 2-D texture */
1231 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1232 img
->DepthLog2
= logbase2(img
->Depth2
);
1235 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1237 img
->IsCompressed
= GL_FALSE
;
1238 img
->CompressedSize
= 0;
1240 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1241 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1242 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1243 img
->_IsPowerOfTwo
= GL_TRUE
;
1245 img
->_IsPowerOfTwo
= GL_FALSE
;
1247 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1248 img
->RowStride
= width
;
1249 /* Allocate the ImageOffsets array and initialize to typical values.
1250 * We allocate the array for 1D/2D textures too in order to avoid special-
1251 * case code in the texstore routines.
1253 if (img
->ImageOffsets
)
1254 _mesa_free(img
->ImageOffsets
);
1255 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1256 for (i
= 0; i
< depth
; i
++) {
1257 img
->ImageOffsets
[i
] = i
* width
* height
;
1260 /* Compute Width/Height/DepthScale for mipmap lod computation */
1261 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1262 /* scale = 1.0 since texture coords directly map to texels */
1263 img
->WidthScale
= 1.0;
1264 img
->HeightScale
= 1.0;
1265 img
->DepthScale
= 1.0;
1268 img
->WidthScale
= (GLfloat
) img
->Width
;
1269 img
->HeightScale
= (GLfloat
) img
->Height
;
1270 img
->DepthScale
= (GLfloat
) img
->Depth
;
1276 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1277 * level, width, height and depth against the ctx->Const limits for textures.
1279 * A hardware driver might override this function if, for example, the
1280 * max 3D texture size is 512x512x64 (i.e. not a cube).
1282 * Note that width, height, depth == 0 is not an error. However, a
1283 * texture with zero width/height/depth will be considered "incomplete"
1284 * and texturing will effectively be disabled.
1286 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1287 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1288 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1289 * \param level as passed to glTexImage
1290 * \param internalFormat as passed to glTexImage
1291 * \param format as passed to glTexImage
1292 * \param type as passed to glTexImage
1293 * \param width as passed to glTexImage
1294 * \param height as passed to glTexImage
1295 * \param depth as passed to glTexImage
1296 * \param border as passed to glTexImage
1297 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1300 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1301 GLint internalFormat
, GLenum format
, GLenum type
,
1302 GLint width
, GLint height
, GLint depth
, GLint border
)
1306 (void) internalFormat
;
1311 case GL_PROXY_TEXTURE_1D
:
1312 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1313 if (width
< 2 * border
|| width
> 2 + maxSize
||
1314 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1315 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1316 level
>= ctx
->Const
.MaxTextureLevels
) {
1317 /* bad width or level */
1321 case GL_PROXY_TEXTURE_2D
:
1322 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1323 if (width
< 2 * border
|| width
> 2 + maxSize
||
1324 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1325 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1326 height
< 2 * border
|| height
> 2 + maxSize
||
1327 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1328 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1329 level
>= ctx
->Const
.MaxTextureLevels
) {
1330 /* bad width or height or level */
1334 case GL_PROXY_TEXTURE_3D
:
1335 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1336 if (width
< 2 * border
|| width
> 2 + maxSize
||
1337 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1338 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1339 height
< 2 * border
|| height
> 2 + maxSize
||
1340 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1341 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1342 depth
< 2 * border
|| depth
> 2 + maxSize
||
1343 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1344 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1345 level
>= ctx
->Const
.Max3DTextureLevels
) {
1346 /* bad width or height or depth or level */
1350 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1351 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1352 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1354 /* bad width or height or level */
1358 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1359 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1360 if (width
< 2 * border
|| width
> 2 + maxSize
||
1361 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1362 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1363 height
< 2 * border
|| height
> 2 + maxSize
||
1364 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1365 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1366 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1367 /* bad width or height */
1371 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1372 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1373 if (width
< 2 * border
|| width
> 2 + maxSize
||
1374 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1375 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1376 level
>= ctx
->Const
.MaxTextureLevels
) {
1377 /* bad width or level */
1381 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1385 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1386 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1387 if (width
< 2 * border
|| width
> 2 + maxSize
||
1388 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1389 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1390 height
< 2 * border
|| height
> 2 + maxSize
||
1391 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1392 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1393 level
>= ctx
->Const
.MaxTextureLevels
) {
1394 /* bad width or height or level */
1397 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1402 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1409 * Helper function to determine whether a target supports compressed textures
1412 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1414 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1415 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1416 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1417 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1418 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1419 || ((ctx
->Extensions
.MESA_texture_array
&&
1420 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1421 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1426 * Test the glTexImage[123]D() parameters for errors.
1428 * \param ctx GL context.
1429 * \param target texture target given by the user.
1430 * \param level image level given by the user.
1431 * \param internalFormat internal format given by the user.
1432 * \param format pixel data format given by the user.
1433 * \param type pixel data type given by the user.
1434 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1435 * \param width image width given by the user.
1436 * \param height image height given by the user.
1437 * \param depth image depth given by the user.
1438 * \param border image border given by the user.
1440 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1442 * Verifies each of the parameters against the constants specified in
1443 * __GLcontextRec::Const and the supported extensions, and according to the
1444 * OpenGL specification.
1447 texture_error_check( GLcontext
*ctx
, GLenum target
,
1448 GLint level
, GLint internalFormat
,
1449 GLenum format
, GLenum type
,
1451 GLint width
, GLint height
,
1452 GLint depth
, GLint border
)
1454 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1455 GLboolean sizeOK
= GL_TRUE
;
1456 GLboolean colorFormat
, indexFormat
;
1457 GLenum proxy_target
;
1459 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1460 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1462 _mesa_error(ctx
, GL_INVALID_VALUE
,
1463 "glTexImage%dD(level=%d)", dimensions
, level
);
1469 if (border
< 0 || border
> 1 ||
1470 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1471 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1473 _mesa_error(ctx
, GL_INVALID_VALUE
,
1474 "glTexImage%dD(border=%d)", dimensions
, border
);
1479 if (width
< 0 || height
< 0 || depth
< 0) {
1481 _mesa_error(ctx
, GL_INVALID_VALUE
,
1482 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1487 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1488 * level, width, height and depth.
1490 if (dimensions
== 1) {
1491 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1492 proxy_target
= GL_PROXY_TEXTURE_1D
;
1497 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1501 else if (dimensions
== 2) {
1503 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1504 proxy_target
= GL_PROXY_TEXTURE_2D
;
1506 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1507 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1508 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1509 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1510 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1513 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1514 sizeOK
= (width
== height
);
1516 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1517 target
== GL_TEXTURE_RECTANGLE_NV
) {
1518 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1519 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1522 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1524 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1525 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1526 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1529 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1533 else if (dimensions
== 3) {
1534 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1535 proxy_target
= GL_PROXY_TEXTURE_3D
;
1537 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1538 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1539 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1542 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1547 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1551 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1552 internalFormat
, format
,
1553 type
, width
, height
,
1557 _mesa_error(ctx
, GL_INVALID_VALUE
,
1558 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1559 dimensions
, level
, width
, height
, depth
);
1564 /* Check internalFormat */
1565 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1567 _mesa_error(ctx
, GL_INVALID_VALUE
,
1568 "glTexImage%dD(internalFormat=0x%x)",
1569 dimensions
, internalFormat
);
1574 /* Check incoming image format and type */
1575 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1576 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1577 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1580 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1581 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1582 dimensions
, format
, type
);
1587 /* make sure internal format and format basically agree */
1588 colorFormat
= _mesa_is_color_format(format
);
1589 indexFormat
= is_index_format(format
);
1590 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1591 (is_index_format(internalFormat
) && !indexFormat
) ||
1592 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1593 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1594 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
)) ||
1595 (is_dudv_format(internalFormat
) != is_dudv_format(format
))) {
1597 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1598 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1599 dimensions
, internalFormat
, format
);
1603 /* additional checks for ycbcr textures */
1604 if (internalFormat
== GL_YCBCR_MESA
) {
1605 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1606 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1607 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1609 _mesa_sprintf(message
,
1610 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1611 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1612 return GL_TRUE
; /* error */
1614 if (target
!= GL_TEXTURE_2D
&&
1615 target
!= GL_PROXY_TEXTURE_2D
&&
1616 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1617 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1619 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1625 _mesa_sprintf(message
,
1626 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1627 dimensions
, border
);
1628 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1634 /* additional checks for depth textures */
1635 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1636 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1637 if (target
!= GL_TEXTURE_1D
&&
1638 target
!= GL_PROXY_TEXTURE_1D
&&
1639 target
!= GL_TEXTURE_2D
&&
1640 target
!= GL_PROXY_TEXTURE_2D
&&
1641 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1642 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1644 _mesa_error(ctx
, GL_INVALID_ENUM
,
1645 "glTexImage(target/internalFormat)");
1650 /* additional checks for compressed textures */
1651 if (is_compressed_format(ctx
, internalFormat
)) {
1652 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1653 _mesa_error(ctx
, GL_INVALID_ENUM
,
1654 "glTexImage%d(target)", dimensions
);
1659 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1660 "glTexImage%D(border!=0)", dimensions
);
1666 /* if we get here, the parameters are OK */
1672 * Test glTexSubImage[123]D() parameters for errors.
1674 * \param ctx GL context.
1675 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1676 * \param target texture target given by the user.
1677 * \param level image level given by the user.
1678 * \param xoffset sub-image x offset given by the user.
1679 * \param yoffset sub-image y offset given by the user.
1680 * \param zoffset sub-image z offset given by the user.
1681 * \param format pixel data format given by the user.
1682 * \param type pixel data type given by the user.
1683 * \param width image width given by the user.
1684 * \param height image height given by the user.
1685 * \param depth image depth given by the user.
1687 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1689 * Verifies each of the parameters against the constants specified in
1690 * __GLcontextRec::Const and the supported extensions, and according to the
1691 * OpenGL specification.
1694 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1695 GLenum target
, GLint level
,
1696 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1697 GLint width
, GLint height
, GLint depth
,
1698 GLenum format
, GLenum type
)
1701 if (dimensions
== 1) {
1702 if (target
!= GL_TEXTURE_1D
) {
1703 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1707 else if (dimensions
== 2) {
1708 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1709 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1710 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1711 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1715 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1716 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1717 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1721 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1722 if (!ctx
->Extensions
.MESA_texture_array
) {
1723 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1727 else if (target
!= GL_TEXTURE_2D
) {
1728 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1732 else if (dimensions
== 3) {
1733 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1734 if (!ctx
->Extensions
.MESA_texture_array
) {
1735 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1739 else if (target
!= GL_TEXTURE_3D
) {
1740 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1745 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1749 /* Basic level check */
1750 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1751 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1756 _mesa_error(ctx
, GL_INVALID_VALUE
,
1757 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1760 if (height
< 0 && dimensions
> 1) {
1761 _mesa_error(ctx
, GL_INVALID_VALUE
,
1762 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1765 if (depth
< 0 && dimensions
> 2) {
1766 _mesa_error(ctx
, GL_INVALID_VALUE
,
1767 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1771 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1772 _mesa_error(ctx
, GL_INVALID_ENUM
,
1773 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1774 dimensions
, format
, type
);
1782 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1783 GLenum target
, GLint level
,
1784 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1785 GLint width
, GLint height
, GLint depth
,
1786 GLenum format
, GLenum type
,
1787 const struct gl_texture_image
*destTex
)
1790 /* undefined image level */
1791 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1795 if (xoffset
< -((GLint
)destTex
->Border
)) {
1796 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1800 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1801 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1805 if (dimensions
> 1) {
1806 if (yoffset
< -((GLint
)destTex
->Border
)) {
1807 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1811 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1812 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1817 if (dimensions
> 2) {
1818 if (zoffset
< -((GLint
)destTex
->Border
)) {
1819 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1822 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1823 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1828 #if FEATURE_EXT_texture_sRGB
1829 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1830 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1831 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1832 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1833 if ((width
& 0x3) || (height
& 0x3) ||
1834 (xoffset
& 0x3) || (yoffset
& 0x3))
1835 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1836 "glTexSubImage%dD(size or offset not multiple of 4)",
1842 if (destTex
->IsCompressed
) {
1843 if (!target_can_be_compressed(ctx
, target
)) {
1844 _mesa_error(ctx
, GL_INVALID_ENUM
,
1845 "glTexSubImage%D(target)", dimensions
);
1848 /* offset must be multiple of 4 */
1849 if ((xoffset
& 3) || (yoffset
& 3)) {
1850 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1851 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1854 /* size must be multiple of 4 or equal to whole texture size */
1855 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1856 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1857 "glTexSubImage%D(width)", dimensions
);
1860 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1861 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1862 "glTexSubImage%D(width)", dimensions
);
1872 * Test glCopyTexImage[12]D() parameters for errors.
1874 * \param ctx GL context.
1875 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1876 * \param target texture target given by the user.
1877 * \param level image level given by the user.
1878 * \param internalFormat internal format given by the user.
1879 * \param width image width given by the user.
1880 * \param height image height given by the user.
1881 * \param border texture border.
1883 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1885 * Verifies each of the parameters against the constants specified in
1886 * __GLcontextRec::Const and the supported extensions, and according to the
1887 * OpenGL specification.
1890 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1891 GLenum target
, GLint level
, GLint internalFormat
,
1892 GLint width
, GLint height
, GLint border
)
1898 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1899 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1900 _mesa_error(ctx
, GL_INVALID_VALUE
,
1901 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1905 /* Check that the source buffer is complete */
1906 if (ctx
->ReadBuffer
->Name
) {
1907 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1908 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1909 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1910 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1916 if (border
< 0 || border
> 1 ||
1917 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1918 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1922 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1924 _mesa_error(ctx
, GL_INVALID_VALUE
,
1925 "glCopyTexImage%dD(internalFormat)", dimensions
);
1929 /* NOTE: the format and type aren't really significant for
1930 * TestProxyTexImage(). Only the internalformat really matters.
1931 if (!_mesa_source_buffer_exists(ctx, format)) {
1932 _mesa_error(ctx, GL_INVALID_OPERATION,
1933 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1940 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1941 * level, width, height and depth.
1943 if (dimensions
== 1) {
1944 if (target
== GL_TEXTURE_1D
) {
1945 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1946 level
, internalFormat
,
1948 width
, 1, 1, border
);
1951 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1955 else if (dimensions
== 2) {
1956 if (target
== GL_TEXTURE_2D
) {
1957 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1958 level
, internalFormat
,
1960 width
, height
, 1, border
);
1962 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1963 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1964 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1965 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1968 sizeOK
= (width
== height
) &&
1969 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1970 level
, internalFormat
, format
, type
,
1971 width
, height
, 1, border
);
1973 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1974 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1975 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1978 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1979 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1980 level
, internalFormat
,
1982 width
, height
, 1, border
);
1984 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1985 if (!ctx
->Extensions
.MESA_texture_array
) {
1986 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1989 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1990 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1991 level
, internalFormat
,
1993 width
, height
, 1, border
);
1996 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
2001 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
2006 if (dimensions
== 1) {
2007 _mesa_error(ctx
, GL_INVALID_VALUE
,
2008 "glCopyTexImage1D(width=%d)", width
);
2011 ASSERT(dimensions
== 2);
2012 _mesa_error(ctx
, GL_INVALID_VALUE
,
2013 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2018 if (is_compressed_format(ctx
, internalFormat
)) {
2019 if (!target_can_be_compressed(ctx
, target
)) {
2020 _mesa_error(ctx
, GL_INVALID_ENUM
,
2021 "glCopyTexImage%d(target)", dimensions
);
2025 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2026 "glCopyTexImage%D(border!=0)", dimensions
);
2030 else if (is_depth_format(internalFormat
)) {
2031 /* make sure we have depth/stencil buffers */
2032 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2033 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2034 "glCopyTexImage%D(no depth)", dimensions
);
2038 else if (is_depthstencil_format(internalFormat
)) {
2039 /* make sure we have depth/stencil buffers */
2040 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2041 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2042 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2047 /* if we get here, the parameters are OK */
2053 * Test glCopyTexSubImage[12]D() parameters for errors.
2054 * Note that this is the first part of error checking.
2055 * See also copytexsubimage_error_check2() below for the second part.
2057 * \param ctx GL context.
2058 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2059 * \param target texture target given by the user.
2060 * \param level image level given by the user.
2062 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2065 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
2066 GLenum target
, GLint level
)
2068 /* Check that the source buffer is complete */
2069 if (ctx
->ReadBuffer
->Name
) {
2070 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2071 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2072 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2073 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2079 if (dimensions
== 1) {
2080 if (target
!= GL_TEXTURE_1D
) {
2081 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2085 else if (dimensions
== 2) {
2086 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2087 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2088 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2089 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2093 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2094 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2095 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2099 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2100 if (!ctx
->Extensions
.MESA_texture_array
) {
2101 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2105 else if (target
!= GL_TEXTURE_2D
) {
2106 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2110 else if (dimensions
== 3) {
2111 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2112 (!ctx
->Extensions
.MESA_texture_array
))
2113 && (target
!= GL_TEXTURE_3D
)) {
2114 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2120 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2121 _mesa_error(ctx
, GL_INVALID_VALUE
,
2122 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2131 * Second part of error checking for glCopyTexSubImage[12]D().
2132 * \param xoffset sub-image x offset given by the user.
2133 * \param yoffset sub-image y offset given by the user.
2134 * \param zoffset sub-image z offset given by the user.
2135 * \param width image width given by the user.
2136 * \param height image height given by the user.
2139 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2140 GLenum target
, GLint level
,
2141 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2142 GLsizei width
, GLsizei height
,
2143 const struct gl_texture_image
*teximage
)
2145 /* check that dest tex image exists */
2147 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2148 "glCopyTexSubImage%dD(undefined texture level: %d)",
2155 _mesa_error(ctx
, GL_INVALID_VALUE
,
2156 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2159 if (dimensions
> 1 && height
< 0) {
2160 _mesa_error(ctx
, GL_INVALID_VALUE
,
2161 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2165 /* check x/y offsets */
2166 if (xoffset
< -((GLint
)teximage
->Border
)) {
2167 _mesa_error(ctx
, GL_INVALID_VALUE
,
2168 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2171 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2172 _mesa_error(ctx
, GL_INVALID_VALUE
,
2173 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2176 if (dimensions
> 1) {
2177 if (yoffset
< -((GLint
)teximage
->Border
)) {
2178 _mesa_error(ctx
, GL_INVALID_VALUE
,
2179 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2182 /* NOTE: we're adding the border here, not subtracting! */
2183 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2184 _mesa_error(ctx
, GL_INVALID_VALUE
,
2185 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2190 /* check z offset */
2191 if (dimensions
> 2) {
2192 if (zoffset
< -((GLint
)teximage
->Border
)) {
2193 _mesa_error(ctx
, GL_INVALID_VALUE
,
2194 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2197 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2198 _mesa_error(ctx
, GL_INVALID_VALUE
,
2199 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2204 if (teximage
->IsCompressed
) {
2205 if (!target_can_be_compressed(ctx
, target
)) {
2206 _mesa_error(ctx
, GL_INVALID_ENUM
,
2207 "glCopyTexSubImage%d(target)", dimensions
);
2210 /* offset must be multiple of 4 */
2211 if ((xoffset
& 3) || (yoffset
& 3)) {
2212 _mesa_error(ctx
, GL_INVALID_VALUE
,
2213 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2216 /* size must be multiple of 4 */
2217 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2218 _mesa_error(ctx
, GL_INVALID_VALUE
,
2219 "glCopyTexSubImage%D(width)", dimensions
);
2222 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2223 _mesa_error(ctx
, GL_INVALID_VALUE
,
2224 "glCopyTexSubImage%D(height)", dimensions
);
2229 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2230 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2234 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2235 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2236 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2237 dimensions
, teximage
->_BaseFormat
);
2241 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2242 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2243 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2244 "glCopyTexSubImage%D(no depth buffer)",
2249 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2250 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2251 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2252 "glCopyTexSubImage%D(no depth/stencil buffer)",
2258 /* if we get here, the parameters are OK */
2264 * Get texture image. Called by glGetTexImage.
2266 * \param target texture target.
2267 * \param level image level.
2268 * \param format pixel data format for returned image.
2269 * \param type pixel data type for returned image.
2270 * \param pixels returned pixel data.
2273 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2274 GLenum type
, GLvoid
*pixels
)
2276 const struct gl_texture_unit
*texUnit
;
2277 struct gl_texture_object
*texObj
;
2278 struct gl_texture_image
*texImage
;
2279 GLint maxLevels
= 0;
2280 GET_CURRENT_CONTEXT(ctx
);
2281 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2283 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2284 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2285 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2286 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2290 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2291 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2293 if (level
< 0 || level
>= maxLevels
) {
2294 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2298 if (_mesa_sizeof_packed_type(type
) <= 0) {
2299 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2303 if (_mesa_components_in_format(format
) <= 0 ||
2304 format
== GL_STENCIL_INDEX
) {
2305 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2309 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2310 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2314 if (!ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2315 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2319 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2320 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2324 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2325 && is_depthstencil_format(format
)) {
2326 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2330 if (!ctx
->Extensions
.ATI_envmap_bumpmap
2331 && is_dudv_format(format
)) {
2332 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2336 _mesa_lock_texture(ctx
, texObj
);
2338 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2340 /* invalid mipmap level, not an error */
2345 /* Make sure the requested image format is compatible with the
2346 * texture's format. Note that a color index texture can be converted
2347 * to RGBA so that combo is allowed.
2349 if (_mesa_is_color_format(format
)
2350 && !_mesa_is_color_format(texImage
->TexFormat
->BaseFormat
)
2351 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2352 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2355 else if (is_index_format(format
)
2356 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2357 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2360 else if (is_depth_format(format
)
2361 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2362 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2363 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2366 else if (is_ycbcr_format(format
)
2367 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2368 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2371 else if (is_depthstencil_format(format
)
2372 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2373 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2376 else if (is_dudv_format(format
)
2377 && !is_dudv_format(texImage
->TexFormat
->BaseFormat
)) {
2378 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2382 if (ctx
->Pack
.BufferObj
->Name
) {
2383 /* packing texture image into a PBO */
2384 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2385 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2386 texImage
->Height
, texImage
->Depth
,
2387 format
, type
, pixels
)) {
2388 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2389 "glGetTexImage(invalid PBO access)");
2394 /* typically, this will call _mesa_get_teximage() */
2395 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2400 _mesa_unlock_texture(ctx
, texObj
);
2404 /** Callback info for walking over FBO hash table */
2408 struct gl_texture_object
*texObj
;
2414 * Check render to texture callback. Called from _mesa_HashWalk().
2417 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2419 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2420 const struct cb_info
*info
= (struct cb_info
*) userData
;
2421 GLcontext
*ctx
= info
->ctx
;
2422 const struct gl_texture_object
*texObj
= info
->texObj
;
2423 const GLuint level
= info
->level
, face
= info
->face
;
2425 /* If this is a user-created FBO */
2428 /* check if any of the FBO's attachments point to 'texObj' */
2429 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2430 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2431 if (att
->Type
== GL_TEXTURE
&&
2432 att
->Texture
== texObj
&&
2433 att
->TextureLevel
== level
&&
2434 att
->CubeMapFace
== face
) {
2435 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2436 /* Tell driver about the new renderbuffer texture */
2437 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2438 /* Mark fb status as indeterminate to force re-validation */
2447 * When a texture image is specified we have to check if it's bound to
2448 * any framebuffer objects (render to texture) in order to detect changes
2449 * in size or format since that effects FBO completeness.
2450 * Any FBOs rendering into the texture must be re-validated.
2453 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2454 GLuint face
, GLuint level
)
2456 /* Only check this texture if it's been marked as RenderToTexture */
2457 if (texObj
->_RenderToTexture
) {
2458 struct cb_info info
;
2460 info
.texObj
= texObj
;
2463 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2468 /** Debug helper: override the user-requested internal format */
2470 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2473 if (internalFormat
== GL_RGBA16F_ARB
||
2474 internalFormat
== GL_RGBA32F_ARB
) {
2475 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2478 else if (internalFormat
== GL_RGB16F_ARB
||
2479 internalFormat
== GL_RGB32F_ARB
) {
2480 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2483 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2484 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2485 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2486 return GL_LUMINANCE_ALPHA
;
2488 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2489 internalFormat
== GL_LUMINANCE32F_ARB
) {
2490 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2491 return GL_LUMINANCE
;
2493 else if (internalFormat
== GL_ALPHA16F_ARB
||
2494 internalFormat
== GL_ALPHA32F_ARB
) {
2495 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2499 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2500 internalFormat = GL_RGBA;
2504 return internalFormat
;
2507 return internalFormat
;
2513 * Called from the API. Note that width includes the border.
2516 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2517 GLsizei width
, GLint border
, GLenum format
,
2518 GLenum type
, const GLvoid
*pixels
)
2520 GLsizei postConvWidth
= width
;
2521 GET_CURRENT_CONTEXT(ctx
);
2522 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2524 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2526 #if FEATURE_convolve
2527 if (_mesa_is_color_format(internalFormat
)) {
2528 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2532 if (target
== GL_TEXTURE_1D
) {
2533 /* non-proxy target */
2534 struct gl_texture_unit
*texUnit
;
2535 struct gl_texture_object
*texObj
;
2536 struct gl_texture_image
*texImage
;
2537 const GLuint face
= _mesa_tex_target_to_face(target
);
2539 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2540 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2541 return; /* error was recorded */
2544 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2545 _mesa_update_state(ctx
);
2547 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2548 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2549 _mesa_lock_texture(ctx
, texObj
);
2551 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2553 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2557 if (texImage
->Data
) {
2558 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2561 ASSERT(texImage
->Data
== NULL
);
2563 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2564 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2565 postConvWidth
, 1, 1,
2566 border
, internalFormat
);
2568 ASSERT(ctx
->Driver
.TexImage1D
);
2570 /* Give the texture to the driver! <pixels> may be null! */
2571 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2572 width
, border
, format
, type
, pixels
,
2573 &ctx
->Unpack
, texObj
, texImage
);
2575 ASSERT(texImage
->TexFormat
);
2577 update_fbo_texture(ctx
, texObj
, face
, level
);
2580 texObj
->_Complete
= GL_FALSE
;
2581 ctx
->NewState
|= _NEW_TEXTURE
;
2584 _mesa_unlock_texture(ctx
, texObj
);
2586 else if (target
== GL_PROXY_TEXTURE_1D
) {
2587 /* Proxy texture: check for errors and update proxy state */
2588 struct gl_texture_image
*texImage
;
2589 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2590 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2591 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2592 /* when error, clear all proxy texture image parameters */
2594 clear_teximage_fields(texImage
);
2597 /* no error, set the tex image parameters */
2599 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2600 postConvWidth
, 1, 1,
2601 border
, internalFormat
);
2602 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2603 internalFormat
, format
, type
);
2607 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2614 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2615 GLsizei width
, GLsizei height
, GLint border
,
2616 GLenum format
, GLenum type
,
2617 const GLvoid
*pixels
)
2619 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2620 GET_CURRENT_CONTEXT(ctx
);
2621 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2623 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2625 #if FEATURE_convolve
2626 if (_mesa_is_color_format(internalFormat
)) {
2627 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2632 if (target
== GL_TEXTURE_2D
||
2633 (ctx
->Extensions
.ARB_texture_cube_map
&&
2634 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2635 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2636 (ctx
->Extensions
.NV_texture_rectangle
&&
2637 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2638 (ctx
->Extensions
.MESA_texture_array
&&
2639 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2640 /* non-proxy target */
2641 struct gl_texture_unit
*texUnit
;
2642 struct gl_texture_object
*texObj
;
2643 struct gl_texture_image
*texImage
;
2644 const GLuint face
= _mesa_tex_target_to_face(target
);
2646 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2647 format
, type
, 2, postConvWidth
, postConvHeight
,
2649 return; /* error was recorded */
2652 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2653 _mesa_update_state(ctx
);
2655 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2656 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2657 _mesa_lock_texture(ctx
, texObj
);
2659 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2661 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2665 if (texImage
->Data
) {
2666 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2669 ASSERT(texImage
->Data
== NULL
);
2670 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2671 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2672 postConvWidth
, postConvHeight
, 1,
2673 border
, internalFormat
);
2675 ASSERT(ctx
->Driver
.TexImage2D
);
2677 /* Give the texture to the driver! <pixels> may be null! */
2678 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2679 width
, height
, border
, format
, type
, pixels
,
2680 &ctx
->Unpack
, texObj
, texImage
);
2682 ASSERT(texImage
->TexFormat
);
2684 update_fbo_texture(ctx
, texObj
, face
, level
);
2687 texObj
->_Complete
= GL_FALSE
;
2688 ctx
->NewState
|= _NEW_TEXTURE
;
2691 _mesa_unlock_texture(ctx
, texObj
);
2693 else if (target
== GL_PROXY_TEXTURE_2D
||
2694 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2695 ctx
->Extensions
.ARB_texture_cube_map
) ||
2696 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2697 ctx
->Extensions
.NV_texture_rectangle
) ||
2698 (ctx
->Extensions
.MESA_texture_array
&&
2699 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2700 /* Proxy texture: check for errors and update proxy state */
2701 struct gl_texture_image
*texImage
;
2702 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2703 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2704 format
, type
, 2, postConvWidth
, postConvHeight
,
2706 /* when error, clear all proxy texture image parameters */
2708 clear_teximage_fields(texImage
);
2711 /* no error, set the tex image parameters */
2712 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2713 postConvWidth
, postConvHeight
, 1,
2714 border
, internalFormat
);
2715 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2716 internalFormat
, format
, type
);
2720 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2727 * Called by the API or display list executor.
2728 * Note that width and height include the border.
2731 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2732 GLsizei width
, GLsizei height
, GLsizei depth
,
2733 GLint border
, GLenum format
, GLenum type
,
2734 const GLvoid
*pixels
)
2736 GET_CURRENT_CONTEXT(ctx
);
2737 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2739 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2741 if (target
== GL_TEXTURE_3D
||
2742 (ctx
->Extensions
.MESA_texture_array
&&
2743 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2744 /* non-proxy target */
2745 struct gl_texture_unit
*texUnit
;
2746 struct gl_texture_object
*texObj
;
2747 struct gl_texture_image
*texImage
;
2748 const GLuint face
= _mesa_tex_target_to_face(target
);
2750 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2751 format
, type
, 3, width
, height
, depth
, border
)) {
2752 return; /* error was recorded */
2755 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2756 _mesa_update_state(ctx
);
2758 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2759 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2760 _mesa_lock_texture(ctx
, texObj
);
2762 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2764 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2768 if (texImage
->Data
) {
2769 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2772 ASSERT(texImage
->Data
== NULL
);
2773 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2774 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2775 width
, height
, depth
,
2776 border
, internalFormat
);
2778 ASSERT(ctx
->Driver
.TexImage3D
);
2780 /* Give the texture to the driver! <pixels> may be null! */
2781 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2782 width
, height
, depth
, border
, format
, type
,
2783 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2785 ASSERT(texImage
->TexFormat
);
2787 update_fbo_texture(ctx
, texObj
, face
, level
);
2790 texObj
->_Complete
= GL_FALSE
;
2791 ctx
->NewState
|= _NEW_TEXTURE
;
2794 _mesa_unlock_texture(ctx
, texObj
);
2796 else if (target
== GL_PROXY_TEXTURE_3D
||
2797 (ctx
->Extensions
.MESA_texture_array
&&
2798 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2799 /* Proxy texture: check for errors and update proxy state */
2800 struct gl_texture_image
*texImage
;
2801 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2802 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2803 format
, type
, 3, width
, height
, depth
, border
)) {
2804 /* when error, clear all proxy texture image parameters */
2806 clear_teximage_fields(texImage
);
2809 /* no error, set the tex image parameters */
2810 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2811 depth
, border
, internalFormat
);
2812 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2813 internalFormat
, format
, type
);
2817 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2824 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2825 GLsizei width
, GLsizei height
, GLsizei depth
,
2826 GLint border
, GLenum format
, GLenum type
,
2827 const GLvoid
*pixels
)
2829 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2830 depth
, border
, format
, type
, pixels
);
2836 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2837 GLint xoffset
, GLsizei width
,
2838 GLenum format
, GLenum type
,
2839 const GLvoid
*pixels
)
2841 GLsizei postConvWidth
= width
;
2842 struct gl_texture_unit
*texUnit
;
2843 struct gl_texture_object
*texObj
;
2844 struct gl_texture_image
*texImage
= NULL
;
2845 GET_CURRENT_CONTEXT(ctx
);
2846 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2848 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2849 _mesa_update_state(ctx
);
2851 #if FEATURE_convolve
2852 /* XXX should test internal format */
2853 if (_mesa_is_color_format(format
)) {
2854 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2858 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2859 postConvWidth
, 1, 1, format
, type
)) {
2860 return; /* error was detected */
2864 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2865 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2868 _mesa_lock_texture(ctx
, texObj
);
2870 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2872 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2873 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2874 goto out
; /* error was detected */
2878 goto out
; /* no-op, not an error */
2880 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2881 xoffset
+= texImage
->Border
;
2883 ASSERT(ctx
->Driver
.TexSubImage1D
);
2884 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2885 format
, type
, pixels
, &ctx
->Unpack
,
2887 ctx
->NewState
|= _NEW_TEXTURE
;
2890 _mesa_unlock_texture(ctx
, texObj
);
2895 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2896 GLint xoffset
, GLint yoffset
,
2897 GLsizei width
, GLsizei height
,
2898 GLenum format
, GLenum type
,
2899 const GLvoid
*pixels
)
2901 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2902 struct gl_texture_unit
*texUnit
;
2903 struct gl_texture_object
*texObj
;
2904 struct gl_texture_image
*texImage
;
2905 GET_CURRENT_CONTEXT(ctx
);
2906 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2908 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2909 _mesa_update_state(ctx
);
2911 #if FEATURE_convolve
2912 /* XXX should test internal format */
2913 if (_mesa_is_color_format(format
)) {
2914 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2919 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2920 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2921 return; /* error was detected */
2924 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2925 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2926 _mesa_lock_texture(ctx
, texObj
);
2928 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2930 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2931 postConvWidth
, postConvHeight
, 1, format
, type
,
2933 goto out
; /* error was detected */
2936 if (width
== 0 || height
== 0)
2937 goto out
; /* no-op, not an error */
2939 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2940 xoffset
+= texImage
->Border
;
2941 yoffset
+= texImage
->Border
;
2943 ASSERT(ctx
->Driver
.TexSubImage2D
);
2944 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2945 width
, height
, format
, type
, pixels
,
2946 &ctx
->Unpack
, texObj
, texImage
);
2947 ctx
->NewState
|= _NEW_TEXTURE
;
2950 _mesa_unlock_texture(ctx
, texObj
);
2956 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2957 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2958 GLsizei width
, GLsizei height
, GLsizei depth
,
2959 GLenum format
, GLenum type
,
2960 const GLvoid
*pixels
)
2962 struct gl_texture_unit
*texUnit
;
2963 struct gl_texture_object
*texObj
;
2964 struct gl_texture_image
*texImage
;
2965 GET_CURRENT_CONTEXT(ctx
);
2966 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2968 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2969 _mesa_update_state(ctx
);
2971 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2972 width
, height
, depth
, format
, type
)) {
2973 return; /* error was detected */
2976 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2977 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2979 _mesa_lock_texture(ctx
, texObj
);
2981 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2983 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2984 width
, height
, depth
, format
, type
, texImage
)) {
2985 goto out
; /* error was detected */
2988 if (width
== 0 || height
== 0 || height
== 0)
2989 goto out
; /* no-op, not an error */
2991 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2992 xoffset
+= texImage
->Border
;
2993 yoffset
+= texImage
->Border
;
2994 zoffset
+= texImage
->Border
;
2996 ASSERT(ctx
->Driver
.TexSubImage3D
);
2997 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2998 xoffset
, yoffset
, zoffset
,
2999 width
, height
, depth
,
3000 format
, type
, pixels
,
3001 &ctx
->Unpack
, texObj
, texImage
);
3002 ctx
->NewState
|= _NEW_TEXTURE
;
3005 _mesa_unlock_texture(ctx
, texObj
);
3011 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3012 GLenum internalFormat
,
3014 GLsizei width
, GLint border
)
3016 struct gl_texture_unit
*texUnit
;
3017 struct gl_texture_object
*texObj
;
3018 struct gl_texture_image
*texImage
;
3019 GLsizei postConvWidth
= width
;
3020 const GLuint face
= _mesa_tex_target_to_face(target
);
3021 GET_CURRENT_CONTEXT(ctx
);
3022 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3024 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3025 _mesa_update_state(ctx
);
3027 #if FEATURE_convolve
3028 if (_mesa_is_color_format(internalFormat
)) {
3029 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3033 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
3034 postConvWidth
, 1, border
))
3037 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3038 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3039 _mesa_lock_texture(ctx
, texObj
);
3041 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3043 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
3047 if (texImage
->Data
) {
3048 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3051 ASSERT(texImage
->Data
== NULL
);
3053 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3054 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
3055 border
, internalFormat
);
3058 ASSERT(ctx
->Driver
.CopyTexImage1D
);
3059 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
3060 x
, y
, width
, border
);
3062 ASSERT(texImage
->TexFormat
);
3064 update_fbo_texture(ctx
, texObj
, face
, level
);
3067 texObj
->_Complete
= GL_FALSE
;
3068 ctx
->NewState
|= _NEW_TEXTURE
;
3071 _mesa_unlock_texture(ctx
, texObj
);
3077 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3078 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3081 struct gl_texture_unit
*texUnit
;
3082 struct gl_texture_object
*texObj
;
3083 struct gl_texture_image
*texImage
;
3084 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3085 const GLuint face
= _mesa_tex_target_to_face(target
);
3086 GET_CURRENT_CONTEXT(ctx
);
3087 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3089 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3090 _mesa_update_state(ctx
);
3092 #if FEATURE_convolve
3093 if (_mesa_is_color_format(internalFormat
)) {
3094 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
3099 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
3100 postConvWidth
, postConvHeight
, border
))
3103 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3104 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3106 _mesa_lock_texture(ctx
, texObj
);
3108 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3111 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3115 if (texImage
->Data
) {
3116 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3119 ASSERT(texImage
->Data
== NULL
);
3121 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3122 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3123 postConvWidth
, postConvHeight
, 1,
3124 border
, internalFormat
);
3126 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3127 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3128 x
, y
, width
, height
, border
);
3130 ASSERT(texImage
->TexFormat
);
3132 update_fbo_texture(ctx
, texObj
, face
, level
);
3135 texObj
->_Complete
= GL_FALSE
;
3136 ctx
->NewState
|= _NEW_TEXTURE
;
3139 _mesa_unlock_texture(ctx
, texObj
);
3144 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3145 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3147 struct gl_texture_unit
*texUnit
;
3148 struct gl_texture_object
*texObj
;
3149 struct gl_texture_image
*texImage
;
3150 GLsizei postConvWidth
= width
;
3154 GET_CURRENT_CONTEXT(ctx
);
3155 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3157 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3158 _mesa_update_state(ctx
);
3160 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3163 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3164 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3166 _mesa_lock_texture(ctx
, texObj
);
3168 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3170 #if FEATURE_convolve
3171 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3172 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3176 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3177 xoffset
, 0, 0, postConvWidth
, 1,
3182 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3183 xoffset
+= texImage
->Border
;
3185 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3187 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3188 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3189 xoffset
, x
, y
, width
);
3192 ctx
->NewState
|= _NEW_TEXTURE
;
3195 _mesa_unlock_texture(ctx
, texObj
);
3201 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3202 GLint xoffset
, GLint yoffset
,
3203 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3205 struct gl_texture_unit
*texUnit
;
3206 struct gl_texture_object
*texObj
;
3207 struct gl_texture_image
*texImage
;
3208 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3209 GET_CURRENT_CONTEXT(ctx
);
3210 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3212 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3213 _mesa_update_state(ctx
);
3215 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3218 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3219 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3221 _mesa_lock_texture(ctx
, texObj
);
3223 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3225 #if FEATURE_convolve
3226 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3227 _mesa_adjust_image_for_convolution(ctx
, 2,
3228 &postConvWidth
, &postConvHeight
);
3232 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3233 postConvWidth
, postConvHeight
, texImage
))
3236 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3237 xoffset
+= texImage
->Border
;
3238 yoffset
+= texImage
->Border
;
3240 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3242 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3243 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3244 xoffset
, yoffset
, x
, y
, width
, height
);
3247 ctx
->NewState
|= _NEW_TEXTURE
;
3250 _mesa_unlock_texture(ctx
, texObj
);
3256 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3257 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3258 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3260 struct gl_texture_unit
*texUnit
;
3261 struct gl_texture_object
*texObj
;
3262 struct gl_texture_image
*texImage
;
3263 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3264 GET_CURRENT_CONTEXT(ctx
);
3265 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3267 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3268 _mesa_update_state(ctx
);
3270 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3273 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3274 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3276 _mesa_lock_texture(ctx
, texObj
);
3278 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3280 #if FEATURE_convolve
3281 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3282 _mesa_adjust_image_for_convolution(ctx
, 2,
3283 &postConvWidth
, &postConvHeight
);
3287 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3288 zoffset
, postConvWidth
, postConvHeight
,
3292 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3293 xoffset
+= texImage
->Border
;
3294 yoffset
+= texImage
->Border
;
3295 zoffset
+= texImage
->Border
;
3297 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3299 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3300 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3301 xoffset
, yoffset
, zoffset
,
3302 x
, y
, width
, height
);
3305 ctx
->NewState
|= _NEW_TEXTURE
;
3308 _mesa_unlock_texture(ctx
, texObj
);
3314 /**********************************************************************/
3315 /****** Compressed Textures ******/
3316 /**********************************************************************/
3320 * Error checking for glCompressedTexImage[123]D().
3321 * \return error code or GL_NO_ERROR.
3324 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3325 GLenum target
, GLint level
,
3326 GLenum internalFormat
, GLsizei width
,
3327 GLsizei height
, GLsizei depth
, GLint border
,
3330 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3332 if (dimensions
== 1) {
3333 /* 1D compressed textures not allowed */
3334 return GL_INVALID_ENUM
;
3336 else if (dimensions
== 2) {
3337 if (target
== GL_PROXY_TEXTURE_2D
) {
3338 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3340 else if (target
== GL_TEXTURE_2D
) {
3341 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3343 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3344 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3345 return GL_INVALID_ENUM
; /*target*/
3346 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3348 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3349 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3350 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3351 return GL_INVALID_ENUM
; /*target*/
3352 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3355 return GL_INVALID_ENUM
; /*target*/
3358 else if (dimensions
== 3) {
3359 /* 3D compressed textures not allowed */
3360 return GL_INVALID_ENUM
;
3363 maxTextureSize
= 1 << (maxLevels
- 1);
3365 /* This will detect any invalid internalFormat value */
3366 if (!is_compressed_format(ctx
, internalFormat
))
3367 return GL_INVALID_ENUM
;
3369 /* This should really never fail */
3370 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3371 return GL_INVALID_ENUM
;
3374 return GL_INVALID_VALUE
;
3377 * XXX We should probably use the proxy texture error check function here.
3379 if (width
< 1 || width
> maxTextureSize
||
3380 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3381 return GL_INVALID_VALUE
;
3383 if ((height
< 1 || height
> maxTextureSize
||
3384 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3386 return GL_INVALID_VALUE
;
3388 if ((depth
< 1 || depth
> maxTextureSize
||
3389 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3391 return GL_INVALID_VALUE
;
3393 /* For cube map, width must equal height */
3394 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3395 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3396 return GL_INVALID_VALUE
;
3398 if (level
< 0 || level
>= maxLevels
)
3399 return GL_INVALID_VALUE
;
3401 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3402 depth
, internalFormat
);
3403 if (expectedSize
!= imageSize
)
3404 return GL_INVALID_VALUE
;
3406 #if FEATURE_EXT_texture_sRGB
3407 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3408 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3409 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3410 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3412 return GL_INVALID_OPERATION
;
3421 * Error checking for glCompressedTexSubImage[123]D().
3422 * \warning There are some bad assumptions here about the size of compressed
3423 * texture tiles (multiple of 4) used to test the validity of the
3424 * offset and size parameters.
3425 * \return error code or GL_NO_ERROR.
3428 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3429 GLenum target
, GLint level
,
3430 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3431 GLsizei width
, GLsizei height
, GLsizei depth
,
3432 GLenum format
, GLsizei imageSize
)
3434 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3437 if (dimensions
== 1) {
3438 /* 1D compressed textures not allowed */
3439 return GL_INVALID_ENUM
;
3441 else if (dimensions
== 2) {
3442 if (target
== GL_PROXY_TEXTURE_2D
) {
3443 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3445 else if (target
== GL_TEXTURE_2D
) {
3446 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3448 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3449 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3450 return GL_INVALID_ENUM
; /*target*/
3451 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3453 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3454 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3455 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3456 return GL_INVALID_ENUM
; /*target*/
3457 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3460 return GL_INVALID_ENUM
; /*target*/
3463 else if (dimensions
== 3) {
3464 /* 3D compressed textures not allowed */
3465 return GL_INVALID_ENUM
;
3468 maxTextureSize
= 1 << (maxLevels
- 1);
3470 /* this will catch any invalid compressed format token */
3471 if (!is_compressed_format(ctx
, format
))
3472 return GL_INVALID_ENUM
;
3474 if (width
< 1 || width
> maxTextureSize
)
3475 return GL_INVALID_VALUE
;
3477 if ((height
< 1 || height
> maxTextureSize
)
3479 return GL_INVALID_VALUE
;
3481 if (level
< 0 || level
>= maxLevels
)
3482 return GL_INVALID_VALUE
;
3484 /* XXX these tests are specific to the compressed format.
3485 * this code should be generalized in some way.
3487 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3488 return GL_INVALID_VALUE
;
3490 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3491 return GL_INVALID_VALUE
;
3493 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3494 return GL_INVALID_VALUE
;
3496 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3498 if (expectedSize
!= imageSize
)
3499 return GL_INVALID_VALUE
;
3507 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3508 GLenum internalFormat
, GLsizei width
,
3509 GLint border
, GLsizei imageSize
,
3512 GET_CURRENT_CONTEXT(ctx
);
3513 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3515 if (target
== GL_TEXTURE_1D
) {
3516 /* non-proxy target */
3517 struct gl_texture_unit
*texUnit
;
3518 struct gl_texture_object
*texObj
;
3519 struct gl_texture_image
*texImage
;
3520 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3521 internalFormat
, width
, 1, 1, border
, imageSize
);
3523 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3527 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3528 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3530 _mesa_lock_texture(ctx
, texObj
);
3532 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3534 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3538 if (texImage
->Data
) {
3539 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3541 ASSERT(texImage
->Data
== NULL
);
3543 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3544 border
, internalFormat
);
3546 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3547 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3548 internalFormat
, width
, border
,
3553 texObj
->_Complete
= GL_FALSE
;
3554 ctx
->NewState
|= _NEW_TEXTURE
;
3557 _mesa_unlock_texture(ctx
, texObj
);
3559 else if (target
== GL_PROXY_TEXTURE_1D
) {
3560 /* Proxy texture: check for errors and update proxy state */
3561 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3562 internalFormat
, width
, 1, 1, border
, imageSize
);
3564 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3565 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3566 internalFormat
, GL_NONE
, GL_NONE
,
3567 width
, 1, 1, border
);
3570 /* if error, clear all proxy texture image parameters */
3571 struct gl_texture_image
*texImage
;
3572 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3574 clear_teximage_fields(texImage
);
3577 /* store the teximage parameters */
3578 struct gl_texture_unit
*texUnit
;
3579 struct gl_texture_object
*texObj
;
3580 struct gl_texture_image
*texImage
;
3581 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3582 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3584 _mesa_lock_texture(ctx
, texObj
);
3586 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3587 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3588 border
, internalFormat
);
3590 _mesa_unlock_texture(ctx
, texObj
);
3594 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3601 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3602 GLenum internalFormat
, GLsizei width
,
3603 GLsizei height
, GLint border
, GLsizei imageSize
,
3606 GET_CURRENT_CONTEXT(ctx
);
3607 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3609 if (target
== GL_TEXTURE_2D
||
3610 (ctx
->Extensions
.ARB_texture_cube_map
&&
3611 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3612 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3613 /* non-proxy target */
3614 struct gl_texture_unit
*texUnit
;
3615 struct gl_texture_object
*texObj
;
3616 struct gl_texture_image
*texImage
;
3617 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3618 internalFormat
, width
, height
, 1, border
, imageSize
);
3620 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3624 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3625 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3627 _mesa_lock_texture(ctx
, texObj
);
3629 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3631 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3635 if (texImage
->Data
) {
3636 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3638 ASSERT(texImage
->Data
== NULL
);
3640 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3641 border
, internalFormat
);
3643 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3644 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3645 internalFormat
, width
, height
,
3646 border
, imageSize
, data
,
3650 texObj
->_Complete
= GL_FALSE
;
3651 ctx
->NewState
|= _NEW_TEXTURE
;
3654 _mesa_unlock_texture(ctx
, texObj
);
3656 else if (target
== GL_PROXY_TEXTURE_2D
||
3657 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3658 ctx
->Extensions
.ARB_texture_cube_map
)) {
3659 /* Proxy texture: check for errors and update proxy state */
3660 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3661 internalFormat
, width
, height
, 1, border
, imageSize
);
3663 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3664 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3665 internalFormat
, GL_NONE
, GL_NONE
,
3666 width
, height
, 1, border
);
3669 /* if error, clear all proxy texture image parameters */
3670 struct gl_texture_image
*texImage
;
3671 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3673 clear_teximage_fields(texImage
);
3676 /* store the teximage parameters */
3677 struct gl_texture_unit
*texUnit
;
3678 struct gl_texture_object
*texObj
;
3679 struct gl_texture_image
*texImage
;
3680 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3681 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3683 _mesa_lock_texture(ctx
, texObj
);
3685 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3686 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3687 border
, internalFormat
);
3689 _mesa_unlock_texture(ctx
, texObj
);
3693 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3700 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3701 GLenum internalFormat
, GLsizei width
,
3702 GLsizei height
, GLsizei depth
, GLint border
,
3703 GLsizei imageSize
, const GLvoid
*data
)
3705 GET_CURRENT_CONTEXT(ctx
);
3706 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3708 if (target
== GL_TEXTURE_3D
) {
3709 /* non-proxy target */
3710 struct gl_texture_unit
*texUnit
;
3711 struct gl_texture_object
*texObj
;
3712 struct gl_texture_image
*texImage
;
3713 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3714 internalFormat
, width
, height
, depth
, border
, imageSize
);
3716 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3720 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3721 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3722 _mesa_lock_texture(ctx
, texObj
);
3724 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3726 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3730 if (texImage
->Data
) {
3731 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3733 ASSERT(texImage
->Data
== NULL
);
3735 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3736 border
, internalFormat
);
3738 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3739 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3741 width
, height
, depth
,
3742 border
, imageSize
, data
,
3746 texObj
->_Complete
= GL_FALSE
;
3747 ctx
->NewState
|= _NEW_TEXTURE
;
3750 _mesa_unlock_texture(ctx
, texObj
);
3752 else if (target
== GL_PROXY_TEXTURE_3D
) {
3753 /* Proxy texture: check for errors and update proxy state */
3754 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3755 internalFormat
, width
, height
, depth
, border
, imageSize
);
3757 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3758 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3759 internalFormat
, GL_NONE
, GL_NONE
,
3760 width
, height
, depth
, border
);
3763 /* if error, clear all proxy texture image parameters */
3764 struct gl_texture_image
*texImage
;
3765 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3767 clear_teximage_fields(texImage
);
3770 /* store the teximage parameters */
3771 struct gl_texture_unit
*texUnit
;
3772 struct gl_texture_object
*texObj
;
3773 struct gl_texture_image
*texImage
;
3774 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3775 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3776 _mesa_lock_texture(ctx
, texObj
);
3778 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3779 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3780 depth
, border
, internalFormat
);
3782 _mesa_unlock_texture(ctx
, texObj
);
3786 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3793 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3794 GLsizei width
, GLenum format
,
3795 GLsizei imageSize
, const GLvoid
*data
)
3797 struct gl_texture_unit
*texUnit
;
3798 struct gl_texture_object
*texObj
;
3799 struct gl_texture_image
*texImage
;
3801 GET_CURRENT_CONTEXT(ctx
);
3802 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3804 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3805 xoffset
, 0, 0, /* pos */
3806 width
, 1, 1, /* size */
3809 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3813 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3814 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3815 _mesa_lock_texture(ctx
, texObj
);
3817 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3820 if ((GLint
) format
!= texImage
->InternalFormat
) {
3821 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3822 "glCompressedTexSubImage1D(format)");
3826 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3827 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3832 goto out
; /* no-op, not an error */
3834 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3835 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3837 format
, imageSize
, data
,
3840 ctx
->NewState
|= _NEW_TEXTURE
;
3843 _mesa_unlock_texture(ctx
, texObj
);
3848 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3849 GLint yoffset
, GLsizei width
, GLsizei height
,
3850 GLenum format
, GLsizei imageSize
,
3853 struct gl_texture_unit
*texUnit
;
3854 struct gl_texture_object
*texObj
;
3855 struct gl_texture_image
*texImage
;
3857 GET_CURRENT_CONTEXT(ctx
);
3858 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3860 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3861 xoffset
, yoffset
, 0, /* pos */
3862 width
, height
, 1, /* size */
3865 /* XXX proxy target? */
3866 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3870 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3871 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3872 _mesa_lock_texture(ctx
, texObj
);
3874 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3877 if ((GLint
) format
!= texImage
->InternalFormat
) {
3878 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3879 "glCompressedTexSubImage2D(format)");
3883 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3884 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3885 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3889 if (width
== 0 || height
== 0)
3890 goto out
; /* no-op, not an error */
3892 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3893 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3894 xoffset
, yoffset
, width
, height
,
3895 format
, imageSize
, data
,
3898 ctx
->NewState
|= _NEW_TEXTURE
;
3901 _mesa_unlock_texture(ctx
, texObj
);
3906 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3907 GLint yoffset
, GLint zoffset
, GLsizei width
,
3908 GLsizei height
, GLsizei depth
, GLenum format
,
3909 GLsizei imageSize
, const GLvoid
*data
)
3911 struct gl_texture_unit
*texUnit
;
3912 struct gl_texture_object
*texObj
;
3913 struct gl_texture_image
*texImage
;
3915 GET_CURRENT_CONTEXT(ctx
);
3916 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3918 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3919 xoffset
, yoffset
, zoffset
,/*pos*/
3920 width
, height
, depth
, /*size*/
3923 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3927 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3928 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3929 _mesa_lock_texture(ctx
, texObj
);
3931 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3934 if ((GLint
) format
!= texImage
->InternalFormat
) {
3935 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3936 "glCompressedTexSubImage3D(format)");
3940 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3941 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3942 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3943 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3947 if (width
== 0 || height
== 0 || depth
== 0)
3948 goto out
; /* no-op, not an error */
3950 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3951 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3952 xoffset
, yoffset
, zoffset
,
3953 width
, height
, depth
,
3954 format
, imageSize
, data
,
3957 ctx
->NewState
|= _NEW_TEXTURE
;
3960 _mesa_unlock_texture(ctx
, texObj
);
3965 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3967 const struct gl_texture_unit
*texUnit
;
3968 struct gl_texture_object
*texObj
;
3969 struct gl_texture_image
*texImage
;
3971 GET_CURRENT_CONTEXT(ctx
);
3972 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3974 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3975 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3977 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3981 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3982 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3984 if (level
< 0 || level
>= maxLevels
) {
3985 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3989 if (_mesa_is_proxy_texture(target
)) {
3990 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3994 _mesa_lock_texture(ctx
, texObj
);
3996 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3998 if (texImage
->IsCompressed
) {
3999 /* this typically calls _mesa_get_compressed_teximage() */
4000 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
4004 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4005 "glGetCompressedTexImageARB");
4009 /* probably invalid mipmap level */
4010 _mesa_error(ctx
, GL_INVALID_VALUE
,
4011 "glGetCompressedTexImageARB(level)");
4014 _mesa_unlock_texture(ctx
, texObj
);