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
)
682 const GLuint face
= _mesa_tex_target_to_face(target
);
686 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
688 tObj
->Image
[face
][level
] = texImage
;
690 /* Set the 'back' pointer */
691 texImage
->TexObject
= tObj
;
696 * Allocate a texture image structure.
698 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
701 * \return a pointer to gl_texture_image struct with all fields initialized to
704 struct gl_texture_image
*
705 _mesa_new_texture_image( GLcontext
*ctx
)
708 return CALLOC_STRUCT(gl_texture_image
);
713 * Free texture image data.
714 * This function is a fallback called via ctx->Driver.FreeTexImageData().
716 * \param texImage texture image.
718 * Free the texture image data if it's not marked as client data.
721 _mesa_free_texture_image_data(GLcontext
*ctx
,
722 struct gl_texture_image
*texImage
)
726 if (texImage
->Data
&& !texImage
->IsClientData
) {
727 /* free the old texture data */
728 _mesa_free_texmemory(texImage
->Data
);
731 texImage
->Data
= NULL
;
736 * Free texture image.
738 * \param texImage texture image.
740 * Free the texture image structure and the associated image data.
743 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
745 /* Free texImage->Data and/or any other driver-specific texture
748 ASSERT(ctx
->Driver
.FreeTexImageData
);
749 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
751 ASSERT(texImage
->Data
== NULL
);
752 if (texImage
->ImageOffsets
)
753 _mesa_free(texImage
->ImageOffsets
);
754 _mesa_free(texImage
);
759 * Test if a target is a proxy target.
761 * \param target texture target.
763 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
766 _mesa_is_proxy_texture(GLenum target
)
768 return (target
== GL_PROXY_TEXTURE_1D
||
769 target
== GL_PROXY_TEXTURE_2D
||
770 target
== GL_PROXY_TEXTURE_3D
||
771 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
772 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
773 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
774 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
779 * Get the texture object that corresponds to the target of the given texture unit.
781 * \param ctx GL context.
782 * \param texUnit texture unit.
783 * \param target texture target.
785 * \return pointer to the texture object on success, or NULL on failure.
787 * \sa gl_texture_unit.
789 struct gl_texture_object
*
790 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
795 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
796 case GL_PROXY_TEXTURE_1D
:
797 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
799 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
800 case GL_PROXY_TEXTURE_2D
:
801 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
803 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
804 case GL_PROXY_TEXTURE_3D
:
805 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
806 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
807 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
808 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
809 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
810 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
811 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
812 case GL_TEXTURE_CUBE_MAP_ARB
:
813 return ctx
->Extensions
.ARB_texture_cube_map
814 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
815 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
816 return ctx
->Extensions
.ARB_texture_cube_map
817 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
818 case GL_TEXTURE_RECTANGLE_NV
:
819 return ctx
->Extensions
.NV_texture_rectangle
820 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
821 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
822 return ctx
->Extensions
.NV_texture_rectangle
823 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
824 case GL_TEXTURE_1D_ARRAY_EXT
:
825 return ctx
->Extensions
.MESA_texture_array
826 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
827 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
828 return ctx
->Extensions
.MESA_texture_array
829 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
830 case GL_TEXTURE_2D_ARRAY_EXT
:
831 return ctx
->Extensions
.MESA_texture_array
832 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
833 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
834 return ctx
->Extensions
.MESA_texture_array
835 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
837 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
844 * Get the texture image struct which corresponds to target and level
845 * of the given texture unit.
847 * \param ctx GL context.
848 * \param texObj texture unit.
849 * \param target texture target.
850 * \param level image level.
852 * \return pointer to the texture image structure on success, or NULL on failure.
854 * \sa gl_texture_unit.
856 struct gl_texture_image
*
857 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
858 GLenum target
, GLint level
)
862 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
)
865 /* XXX simplify this with _mesa_tex_target_to_face() */
868 case GL_PROXY_TEXTURE_1D
:
870 case GL_PROXY_TEXTURE_2D
:
872 case GL_PROXY_TEXTURE_3D
:
873 return texObj
->Image
[0][level
];
875 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
876 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
877 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
878 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
879 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
880 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
881 if (ctx
->Extensions
.ARB_texture_cube_map
) {
882 GLuint face
= ((GLuint
) target
-
883 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
884 return texObj
->Image
[face
][level
];
889 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
890 if (ctx
->Extensions
.ARB_texture_cube_map
)
891 return texObj
->Image
[0][level
];
895 case GL_TEXTURE_RECTANGLE_NV
:
896 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
897 if (ctx
->Extensions
.NV_texture_rectangle
&& level
== 0)
898 return texObj
->Image
[0][level
];
902 case GL_TEXTURE_1D_ARRAY_EXT
:
903 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
904 case GL_TEXTURE_2D_ARRAY_EXT
:
905 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
906 return (ctx
->Extensions
.MESA_texture_array
)
907 ? texObj
->Image
[0][level
] : NULL
;
916 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
917 * it and install it. Only return NULL if passed a bad parameter or run
920 struct gl_texture_image
*
921 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
922 GLenum target
, GLint level
)
924 struct gl_texture_image
*texImage
;
929 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
931 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
933 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
937 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
945 * Return pointer to the specified proxy texture image.
946 * Note that proxy textures are per-context, not per-texture unit.
947 * \return pointer to texture image or NULL if invalid target, invalid
948 * level, or out of memory.
950 struct gl_texture_image
*
951 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
953 struct gl_texture_image
*texImage
;
960 case GL_PROXY_TEXTURE_1D
:
961 if (level
>= ctx
->Const
.MaxTextureLevels
)
963 texIndex
= TEXTURE_1D_INDEX
;
965 case GL_PROXY_TEXTURE_2D
:
966 if (level
>= ctx
->Const
.MaxTextureLevels
)
968 texIndex
= TEXTURE_2D_INDEX
;
970 case GL_PROXY_TEXTURE_3D
:
971 if (level
>= ctx
->Const
.Max3DTextureLevels
)
973 texIndex
= TEXTURE_3D_INDEX
;
975 case GL_PROXY_TEXTURE_CUBE_MAP
:
976 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
978 texIndex
= TEXTURE_CUBE_INDEX
;
980 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
983 texIndex
= TEXTURE_RECT_INDEX
;
985 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
986 if (level
>= ctx
->Const
.MaxTextureLevels
)
988 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
990 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
991 if (level
>= ctx
->Const
.MaxTextureLevels
)
993 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
999 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
1001 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1003 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1006 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
1007 /* Set the 'back' pointer */
1008 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
1015 * Get the maximum number of allowed mipmap levels.
1017 * \param ctx GL context.
1018 * \param target texture target.
1020 * \return the maximum number of allowed mipmap levels for the given
1021 * texture target, or zero if passed a bad target.
1026 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
1030 case GL_PROXY_TEXTURE_1D
:
1032 case GL_PROXY_TEXTURE_2D
:
1033 case GL_TEXTURE_1D_ARRAY_EXT
:
1034 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1035 case GL_TEXTURE_2D_ARRAY_EXT
:
1036 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1037 return ctx
->Const
.MaxTextureLevels
;
1039 case GL_PROXY_TEXTURE_3D
:
1040 return ctx
->Const
.Max3DTextureLevels
;
1041 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1042 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1043 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1044 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1045 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1046 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1047 case GL_TEXTURE_CUBE_MAP_ARB
:
1048 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1049 return ctx
->Const
.MaxCubeTextureLevels
;
1050 case GL_TEXTURE_RECTANGLE_NV
:
1051 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1054 return 0; /* bad target */
1060 #if 000 /* not used anymore */
1062 * glTexImage[123]D can accept a NULL image pointer. In this case we
1063 * create a texture image with unspecified image contents per the OpenGL
1067 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1069 const GLint components
= _mesa_components_in_format(format
);
1070 const GLint numPixels
= width
* height
* depth
;
1071 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1075 * Let's see if anyone finds this. If glTexImage2D() is called with
1076 * a NULL image pointer then load the texture image with something
1077 * interesting instead of leaving it indeterminate.
1080 static const char message
[8][32] = {
1081 " X X XXXXX XXX X ",
1082 " XX XX X X X X X ",
1084 " X X XXXX XXX XXXXX ",
1087 " X X XXXXX XXX X X ",
1091 GLubyte
*imgPtr
= data
;
1093 for (h
= 0; h
< depth
; h
++) {
1094 for (i
= 0; i
< height
; i
++) {
1095 GLint srcRow
= 7 - (i
% 8);
1096 for (j
= 0; j
< width
; j
++) {
1097 GLint srcCol
= j
% 32;
1098 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1099 for (k
= 0; k
< components
; k
++) {
1115 * Reset the fields of a gl_texture_image struct to zero.
1117 * \param img texture image structure.
1119 * This is called when a proxy texture test fails, we set all the
1120 * image members (except DriverData) to zero.
1121 * It's also used in glTexImage[123]D as a safeguard to be sure all
1122 * required fields get initialized properly by the Driver.TexImage[123]D
1126 clear_teximage_fields(struct gl_texture_image
*img
)
1129 img
->_BaseFormat
= 0;
1130 img
->InternalFormat
= 0;
1136 if (img
->ImageOffsets
) {
1137 _mesa_free(img
->ImageOffsets
);
1138 img
->ImageOffsets
= NULL
;
1144 img
->HeightLog2
= 0;
1147 img
->TexFormat
= &_mesa_null_texformat
;
1148 img
->FetchTexelc
= NULL
;
1149 img
->FetchTexelf
= NULL
;
1150 img
->IsCompressed
= 0;
1151 img
->CompressedSize
= 0;
1156 * Initialize basic fields of the gl_texture_image struct.
1158 * \param ctx GL context.
1159 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1160 * \param img texture image structure to be initialized.
1161 * \param width image width.
1162 * \param height image height.
1163 * \param depth image depth.
1164 * \param border image border.
1165 * \param internalFormat internal format.
1167 * Fills in the fields of \p img with the given information.
1168 * Note: width, height and depth include the border.
1171 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1172 struct gl_texture_image
*img
,
1173 GLsizei width
, GLsizei height
, GLsizei depth
,
1174 GLint border
, GLenum internalFormat
)
1180 ASSERT(height
>= 0);
1183 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1184 ASSERT(img
->_BaseFormat
> 0);
1185 img
->InternalFormat
= internalFormat
;
1186 img
->Border
= border
;
1188 img
->Height
= height
;
1191 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1192 img
->WidthLog2
= logbase2(img
->Width2
);
1194 if (height
== 1) { /* 1-D texture */
1196 img
->HeightLog2
= 0;
1199 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1200 img
->HeightLog2
= logbase2(img
->Height2
);
1203 if (depth
== 1) { /* 2-D texture */
1208 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1209 img
->DepthLog2
= logbase2(img
->Depth2
);
1212 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1214 img
->IsCompressed
= GL_FALSE
;
1215 img
->CompressedSize
= 0;
1217 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1218 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1219 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1220 img
->_IsPowerOfTwo
= GL_TRUE
;
1222 img
->_IsPowerOfTwo
= GL_FALSE
;
1224 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1225 img
->RowStride
= width
;
1226 /* Allocate the ImageOffsets array and initialize to typical values.
1227 * We allocate the array for 1D/2D textures too in order to avoid special-
1228 * case code in the texstore routines.
1230 if (img
->ImageOffsets
)
1231 _mesa_free(img
->ImageOffsets
);
1232 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1233 for (i
= 0; i
< depth
; i
++) {
1234 img
->ImageOffsets
[i
] = i
* width
* height
;
1237 /* Compute Width/Height/DepthScale for mipmap lod computation */
1238 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1239 /* scale = 1.0 since texture coords directly map to texels */
1240 img
->WidthScale
= 1.0;
1241 img
->HeightScale
= 1.0;
1242 img
->DepthScale
= 1.0;
1245 img
->WidthScale
= (GLfloat
) img
->Width
;
1246 img
->HeightScale
= (GLfloat
) img
->Height
;
1247 img
->DepthScale
= (GLfloat
) img
->Depth
;
1253 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1254 * level, width, height and depth against the ctx->Const limits for textures.
1256 * A hardware driver might override this function if, for example, the
1257 * max 3D texture size is 512x512x64 (i.e. not a cube).
1259 * Note that width, height, depth == 0 is not an error. However, a
1260 * texture with zero width/height/depth will be considered "incomplete"
1261 * and texturing will effectively be disabled.
1263 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1264 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1265 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1266 * \param level as passed to glTexImage
1267 * \param internalFormat as passed to glTexImage
1268 * \param format as passed to glTexImage
1269 * \param type as passed to glTexImage
1270 * \param width as passed to glTexImage
1271 * \param height as passed to glTexImage
1272 * \param depth as passed to glTexImage
1273 * \param border as passed to glTexImage
1274 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1277 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1278 GLint internalFormat
, GLenum format
, GLenum type
,
1279 GLint width
, GLint height
, GLint depth
, GLint border
)
1283 (void) internalFormat
;
1288 case GL_PROXY_TEXTURE_1D
:
1289 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1290 if (width
< 2 * border
|| width
> 2 + maxSize
||
1291 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1292 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1293 level
>= ctx
->Const
.MaxTextureLevels
) {
1294 /* bad width or level */
1298 case GL_PROXY_TEXTURE_2D
:
1299 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1300 if (width
< 2 * border
|| width
> 2 + maxSize
||
1301 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1302 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1303 height
< 2 * border
|| height
> 2 + maxSize
||
1304 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1305 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1306 level
>= ctx
->Const
.MaxTextureLevels
) {
1307 /* bad width or height or level */
1311 case GL_PROXY_TEXTURE_3D
:
1312 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 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 height
< 2 * border
|| height
> 2 + maxSize
||
1317 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1318 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1319 depth
< 2 * border
|| depth
> 2 + maxSize
||
1320 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1321 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1322 level
>= ctx
->Const
.Max3DTextureLevels
) {
1323 /* bad width or height or depth or level */
1327 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1328 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1329 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1331 /* bad width or height or level */
1335 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1336 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1337 if (width
< 2 * border
|| width
> 2 + maxSize
||
1338 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1339 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1340 height
< 2 * border
|| height
> 2 + maxSize
||
1341 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1342 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1343 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1344 /* bad width or height */
1348 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1349 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1350 if (width
< 2 * border
|| width
> 2 + maxSize
||
1351 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1352 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1353 level
>= ctx
->Const
.MaxTextureLevels
) {
1354 /* bad width or level */
1358 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1362 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1363 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1364 if (width
< 2 * border
|| width
> 2 + maxSize
||
1365 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1366 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1367 height
< 2 * border
|| height
> 2 + maxSize
||
1368 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1369 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1370 level
>= ctx
->Const
.MaxTextureLevels
) {
1371 /* bad width or height or level */
1374 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1379 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1386 * Helper function to determine whether a target supports compressed textures
1389 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1391 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1392 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1393 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1394 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1395 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1396 || ((ctx
->Extensions
.MESA_texture_array
&&
1397 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1398 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1403 * Test the glTexImage[123]D() parameters for errors.
1405 * \param ctx GL context.
1406 * \param target texture target given by the user.
1407 * \param level image level given by the user.
1408 * \param internalFormat internal format given by the user.
1409 * \param format pixel data format given by the user.
1410 * \param type pixel data type given by the user.
1411 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1412 * \param width image width given by the user.
1413 * \param height image height given by the user.
1414 * \param depth image depth given by the user.
1415 * \param border image border given by the user.
1417 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1419 * Verifies each of the parameters against the constants specified in
1420 * __GLcontextRec::Const and the supported extensions, and according to the
1421 * OpenGL specification.
1424 texture_error_check( GLcontext
*ctx
, GLenum target
,
1425 GLint level
, GLint internalFormat
,
1426 GLenum format
, GLenum type
,
1428 GLint width
, GLint height
,
1429 GLint depth
, GLint border
)
1431 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1432 GLboolean sizeOK
= GL_TRUE
;
1433 GLboolean colorFormat
, indexFormat
;
1434 GLenum proxy_target
;
1436 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1437 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1439 _mesa_error(ctx
, GL_INVALID_VALUE
,
1440 "glTexImage%dD(level=%d)", dimensions
, level
);
1446 if (border
< 0 || border
> 1 ||
1447 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1448 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1450 _mesa_error(ctx
, GL_INVALID_VALUE
,
1451 "glTexImage%dD(border=%d)", dimensions
, border
);
1456 if (width
< 0 || height
< 0 || depth
< 0) {
1458 _mesa_error(ctx
, GL_INVALID_VALUE
,
1459 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1464 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1465 * level, width, height and depth.
1467 if (dimensions
== 1) {
1468 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1469 proxy_target
= GL_PROXY_TEXTURE_1D
;
1474 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1478 else if (dimensions
== 2) {
1480 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1481 proxy_target
= GL_PROXY_TEXTURE_2D
;
1483 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1484 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1485 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1486 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1487 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1490 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1491 sizeOK
= (width
== height
);
1493 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1494 target
== GL_TEXTURE_RECTANGLE_NV
) {
1495 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1496 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1499 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1501 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1502 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1503 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1506 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1510 else if (dimensions
== 3) {
1511 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1512 proxy_target
= GL_PROXY_TEXTURE_3D
;
1514 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1515 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1516 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1519 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1524 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1528 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1529 internalFormat
, format
,
1530 type
, width
, height
,
1534 _mesa_error(ctx
, GL_INVALID_VALUE
,
1535 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1536 dimensions
, level
, width
, height
, depth
);
1541 /* Check internalFormat */
1542 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1544 _mesa_error(ctx
, GL_INVALID_VALUE
,
1545 "glTexImage%dD(internalFormat=0x%x)",
1546 dimensions
, internalFormat
);
1551 /* Check incoming image format and type */
1552 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1553 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1554 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1557 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1558 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1559 dimensions
, format
, type
);
1564 /* make sure internal format and format basically agree */
1565 colorFormat
= _mesa_is_color_format(format
);
1566 indexFormat
= is_index_format(format
);
1567 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1568 (is_index_format(internalFormat
) && !indexFormat
) ||
1569 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1570 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1571 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
)) ||
1572 (is_dudv_format(internalFormat
) != is_dudv_format(format
))) {
1574 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1575 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1576 dimensions
, internalFormat
, format
);
1580 /* additional checks for ycbcr textures */
1581 if (internalFormat
== GL_YCBCR_MESA
) {
1582 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1583 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1584 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1586 _mesa_sprintf(message
,
1587 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1588 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1589 return GL_TRUE
; /* error */
1591 if (target
!= GL_TEXTURE_2D
&&
1592 target
!= GL_PROXY_TEXTURE_2D
&&
1593 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1594 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1596 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1602 _mesa_sprintf(message
,
1603 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1604 dimensions
, border
);
1605 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1611 /* additional checks for depth textures */
1612 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1613 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1614 if (target
!= GL_TEXTURE_1D
&&
1615 target
!= GL_PROXY_TEXTURE_1D
&&
1616 target
!= GL_TEXTURE_2D
&&
1617 target
!= GL_PROXY_TEXTURE_2D
&&
1618 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1619 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1621 _mesa_error(ctx
, GL_INVALID_ENUM
,
1622 "glTexImage(target/internalFormat)");
1627 /* additional checks for compressed textures */
1628 if (is_compressed_format(ctx
, internalFormat
)) {
1629 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1630 _mesa_error(ctx
, GL_INVALID_ENUM
,
1631 "glTexImage%d(target)", dimensions
);
1636 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1637 "glTexImage%D(border!=0)", dimensions
);
1643 /* if we get here, the parameters are OK */
1649 * Test glTexSubImage[123]D() parameters for errors.
1651 * \param ctx GL context.
1652 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1653 * \param target texture target given by the user.
1654 * \param level image level given by the user.
1655 * \param xoffset sub-image x offset given by the user.
1656 * \param yoffset sub-image y offset given by the user.
1657 * \param zoffset sub-image z offset given by the user.
1658 * \param format pixel data format given by the user.
1659 * \param type pixel data type given by the user.
1660 * \param width image width given by the user.
1661 * \param height image height given by the user.
1662 * \param depth image depth given by the user.
1664 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1666 * Verifies each of the parameters against the constants specified in
1667 * __GLcontextRec::Const and the supported extensions, and according to the
1668 * OpenGL specification.
1671 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1672 GLenum target
, GLint level
,
1673 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1674 GLint width
, GLint height
, GLint depth
,
1675 GLenum format
, GLenum type
)
1678 if (dimensions
== 1) {
1679 if (target
!= GL_TEXTURE_1D
) {
1680 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1684 else if (dimensions
== 2) {
1685 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1686 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1687 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1688 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1692 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1693 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1694 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1698 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1699 if (!ctx
->Extensions
.MESA_texture_array
) {
1700 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1704 else if (target
!= GL_TEXTURE_2D
) {
1705 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1709 else if (dimensions
== 3) {
1710 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1711 if (!ctx
->Extensions
.MESA_texture_array
) {
1712 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1716 else if (target
!= GL_TEXTURE_3D
) {
1717 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1722 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1726 /* Basic level check */
1727 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1728 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1733 _mesa_error(ctx
, GL_INVALID_VALUE
,
1734 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1737 if (height
< 0 && dimensions
> 1) {
1738 _mesa_error(ctx
, GL_INVALID_VALUE
,
1739 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1742 if (depth
< 0 && dimensions
> 2) {
1743 _mesa_error(ctx
, GL_INVALID_VALUE
,
1744 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1748 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1749 _mesa_error(ctx
, GL_INVALID_ENUM
,
1750 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1751 dimensions
, format
, type
);
1759 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1760 GLenum target
, GLint level
,
1761 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1762 GLint width
, GLint height
, GLint depth
,
1763 GLenum format
, GLenum type
,
1764 const struct gl_texture_image
*destTex
)
1767 /* undefined image level */
1768 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1772 if (xoffset
< -((GLint
)destTex
->Border
)) {
1773 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1777 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1778 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1782 if (dimensions
> 1) {
1783 if (yoffset
< -((GLint
)destTex
->Border
)) {
1784 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1788 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1789 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1794 if (dimensions
> 2) {
1795 if (zoffset
< -((GLint
)destTex
->Border
)) {
1796 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1799 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1800 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1805 #if FEATURE_EXT_texture_sRGB
1806 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1807 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1808 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1809 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1810 if ((width
& 0x3) || (height
& 0x3) ||
1811 (xoffset
& 0x3) || (yoffset
& 0x3))
1812 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1813 "glTexSubImage%dD(size or offset not multiple of 4)",
1819 if (destTex
->IsCompressed
) {
1820 if (!target_can_be_compressed(ctx
, target
)) {
1821 _mesa_error(ctx
, GL_INVALID_ENUM
,
1822 "glTexSubImage%D(target)", dimensions
);
1825 /* offset must be multiple of 4 */
1826 if ((xoffset
& 3) || (yoffset
& 3)) {
1827 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1828 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1831 /* size must be multiple of 4 or equal to whole texture size */
1832 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1833 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1834 "glTexSubImage%D(width)", dimensions
);
1837 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1838 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1839 "glTexSubImage%D(width)", dimensions
);
1849 * Test glCopyTexImage[12]D() parameters for errors.
1851 * \param ctx GL context.
1852 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1853 * \param target texture target given by the user.
1854 * \param level image level given by the user.
1855 * \param internalFormat internal format given by the user.
1856 * \param width image width given by the user.
1857 * \param height image height given by the user.
1858 * \param border texture border.
1860 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1862 * Verifies each of the parameters against the constants specified in
1863 * __GLcontextRec::Const and the supported extensions, and according to the
1864 * OpenGL specification.
1867 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1868 GLenum target
, GLint level
, GLint internalFormat
,
1869 GLint width
, GLint height
, GLint border
)
1875 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1876 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1877 _mesa_error(ctx
, GL_INVALID_VALUE
,
1878 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1882 /* Check that the source buffer is complete */
1883 if (ctx
->ReadBuffer
->Name
) {
1884 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1885 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1886 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1887 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1893 if (border
< 0 || border
> 1 ||
1894 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1895 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1899 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1901 _mesa_error(ctx
, GL_INVALID_VALUE
,
1902 "glCopyTexImage%dD(internalFormat)", dimensions
);
1906 /* NOTE: the format and type aren't really significant for
1907 * TestProxyTexImage(). Only the internalformat really matters.
1908 if (!_mesa_source_buffer_exists(ctx, format)) {
1909 _mesa_error(ctx, GL_INVALID_OPERATION,
1910 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1917 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1918 * level, width, height and depth.
1920 if (dimensions
== 1) {
1921 if (target
== GL_TEXTURE_1D
) {
1922 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1923 level
, internalFormat
,
1925 width
, 1, 1, border
);
1928 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1932 else if (dimensions
== 2) {
1933 if (target
== GL_TEXTURE_2D
) {
1934 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1935 level
, internalFormat
,
1937 width
, height
, 1, border
);
1939 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1940 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1941 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1942 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1945 sizeOK
= (width
== height
) &&
1946 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1947 level
, internalFormat
, format
, type
,
1948 width
, height
, 1, border
);
1950 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1951 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1952 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1955 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1956 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1957 level
, internalFormat
,
1959 width
, height
, 1, border
);
1961 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1962 if (!ctx
->Extensions
.MESA_texture_array
) {
1963 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1966 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1967 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1968 level
, internalFormat
,
1970 width
, height
, 1, border
);
1973 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1978 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1983 if (dimensions
== 1) {
1984 _mesa_error(ctx
, GL_INVALID_VALUE
,
1985 "glCopyTexImage1D(width=%d)", width
);
1988 ASSERT(dimensions
== 2);
1989 _mesa_error(ctx
, GL_INVALID_VALUE
,
1990 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1995 if (is_compressed_format(ctx
, internalFormat
)) {
1996 if (!target_can_be_compressed(ctx
, target
)) {
1997 _mesa_error(ctx
, GL_INVALID_ENUM
,
1998 "glCopyTexImage%d(target)", dimensions
);
2002 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2003 "glCopyTexImage%D(border!=0)", dimensions
);
2007 else if (is_depth_format(internalFormat
)) {
2008 /* make sure we have depth/stencil buffers */
2009 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2010 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2011 "glCopyTexImage%D(no depth)", dimensions
);
2015 else if (is_depthstencil_format(internalFormat
)) {
2016 /* make sure we have depth/stencil buffers */
2017 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2018 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2019 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2024 /* if we get here, the parameters are OK */
2030 * Test glCopyTexSubImage[12]D() parameters for errors.
2031 * Note that this is the first part of error checking.
2032 * See also copytexsubimage_error_check2() below for the second part.
2034 * \param ctx GL context.
2035 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2036 * \param target texture target given by the user.
2037 * \param level image level given by the user.
2039 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2042 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
2043 GLenum target
, GLint level
)
2045 /* Check that the source buffer is complete */
2046 if (ctx
->ReadBuffer
->Name
) {
2047 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2048 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2049 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2050 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2056 if (dimensions
== 1) {
2057 if (target
!= GL_TEXTURE_1D
) {
2058 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2062 else if (dimensions
== 2) {
2063 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2064 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2065 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2066 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2070 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2071 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2072 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2076 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2077 if (!ctx
->Extensions
.MESA_texture_array
) {
2078 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2082 else if (target
!= GL_TEXTURE_2D
) {
2083 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2087 else if (dimensions
== 3) {
2088 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2089 (!ctx
->Extensions
.MESA_texture_array
))
2090 && (target
!= GL_TEXTURE_3D
)) {
2091 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2097 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2098 _mesa_error(ctx
, GL_INVALID_VALUE
,
2099 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2108 * Second part of error checking for glCopyTexSubImage[12]D().
2109 * \param xoffset sub-image x offset given by the user.
2110 * \param yoffset sub-image y offset given by the user.
2111 * \param zoffset sub-image z offset given by the user.
2112 * \param width image width given by the user.
2113 * \param height image height given by the user.
2116 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2117 GLenum target
, GLint level
,
2118 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2119 GLsizei width
, GLsizei height
,
2120 const struct gl_texture_image
*teximage
)
2122 /* check that dest tex image exists */
2124 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2125 "glCopyTexSubImage%dD(undefined texture level: %d)",
2132 _mesa_error(ctx
, GL_INVALID_VALUE
,
2133 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2136 if (dimensions
> 1 && height
< 0) {
2137 _mesa_error(ctx
, GL_INVALID_VALUE
,
2138 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2142 /* check x/y offsets */
2143 if (xoffset
< -((GLint
)teximage
->Border
)) {
2144 _mesa_error(ctx
, GL_INVALID_VALUE
,
2145 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2148 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2149 _mesa_error(ctx
, GL_INVALID_VALUE
,
2150 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2153 if (dimensions
> 1) {
2154 if (yoffset
< -((GLint
)teximage
->Border
)) {
2155 _mesa_error(ctx
, GL_INVALID_VALUE
,
2156 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2159 /* NOTE: we're adding the border here, not subtracting! */
2160 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2161 _mesa_error(ctx
, GL_INVALID_VALUE
,
2162 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2167 /* check z offset */
2168 if (dimensions
> 2) {
2169 if (zoffset
< -((GLint
)teximage
->Border
)) {
2170 _mesa_error(ctx
, GL_INVALID_VALUE
,
2171 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2174 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2175 _mesa_error(ctx
, GL_INVALID_VALUE
,
2176 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2181 if (teximage
->IsCompressed
) {
2182 if (!target_can_be_compressed(ctx
, target
)) {
2183 _mesa_error(ctx
, GL_INVALID_ENUM
,
2184 "glCopyTexSubImage%d(target)", dimensions
);
2187 /* offset must be multiple of 4 */
2188 if ((xoffset
& 3) || (yoffset
& 3)) {
2189 _mesa_error(ctx
, GL_INVALID_VALUE
,
2190 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2193 /* size must be multiple of 4 */
2194 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2195 _mesa_error(ctx
, GL_INVALID_VALUE
,
2196 "glCopyTexSubImage%D(width)", dimensions
);
2199 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2200 _mesa_error(ctx
, GL_INVALID_VALUE
,
2201 "glCopyTexSubImage%D(height)", dimensions
);
2206 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2207 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2211 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2212 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2213 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2214 dimensions
, teximage
->_BaseFormat
);
2218 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2219 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2220 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2221 "glCopyTexSubImage%D(no depth buffer)",
2226 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2227 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2228 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2229 "glCopyTexSubImage%D(no depth/stencil buffer)",
2235 /* if we get here, the parameters are OK */
2241 * Get texture image. Called by glGetTexImage.
2243 * \param target texture target.
2244 * \param level image level.
2245 * \param format pixel data format for returned image.
2246 * \param type pixel data type for returned image.
2247 * \param pixels returned pixel data.
2250 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2251 GLenum type
, GLvoid
*pixels
)
2253 const struct gl_texture_unit
*texUnit
;
2254 struct gl_texture_object
*texObj
;
2255 struct gl_texture_image
*texImage
;
2256 GLint maxLevels
= 0;
2257 GET_CURRENT_CONTEXT(ctx
);
2258 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2260 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2261 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2262 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2263 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2267 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2268 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2270 if (level
< 0 || level
>= maxLevels
) {
2271 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2275 if (_mesa_sizeof_packed_type(type
) <= 0) {
2276 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2280 if (_mesa_components_in_format(format
) <= 0 ||
2281 format
== GL_STENCIL_INDEX
) {
2282 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2286 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2287 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2291 if (!ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2292 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2296 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2297 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2301 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2302 && is_depthstencil_format(format
)) {
2303 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2307 if (!ctx
->Extensions
.ATI_envmap_bumpmap
2308 && is_dudv_format(format
)) {
2309 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2313 _mesa_lock_texture(ctx
, texObj
);
2315 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2317 /* invalid mipmap level, not an error */
2322 /* Make sure the requested image format is compatible with the
2323 * texture's format. Note that a color index texture can be converted
2324 * to RGBA so that combo is allowed.
2326 if (_mesa_is_color_format(format
)
2327 && !_mesa_is_color_format(texImage
->TexFormat
->BaseFormat
)
2328 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2329 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2332 else if (is_index_format(format
)
2333 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2334 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2337 else if (is_depth_format(format
)
2338 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2339 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2340 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2343 else if (is_ycbcr_format(format
)
2344 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2345 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2348 else if (is_depthstencil_format(format
)
2349 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2350 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2353 else if (is_dudv_format(format
)
2354 && !is_dudv_format(texImage
->TexFormat
->BaseFormat
)) {
2355 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2359 if (ctx
->Pack
.BufferObj
->Name
) {
2360 /* packing texture image into a PBO */
2361 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2362 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2363 texImage
->Height
, texImage
->Depth
,
2364 format
, type
, pixels
)) {
2365 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2366 "glGetTexImage(invalid PBO access)");
2371 /* typically, this will call _mesa_get_teximage() */
2372 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2377 _mesa_unlock_texture(ctx
, texObj
);
2381 /** Callback info for walking over FBO hash table */
2385 struct gl_texture_object
*texObj
;
2391 * Check render to texture callback. Called from _mesa_HashWalk().
2394 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2396 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2397 const struct cb_info
*info
= (struct cb_info
*) userData
;
2398 GLcontext
*ctx
= info
->ctx
;
2399 const struct gl_texture_object
*texObj
= info
->texObj
;
2400 const GLuint level
= info
->level
, face
= info
->face
;
2402 /* If this is a user-created FBO */
2405 /* check if any of the FBO's attachments point to 'texObj' */
2406 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2407 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2408 if (att
->Type
== GL_TEXTURE
&&
2409 att
->Texture
== texObj
&&
2410 att
->TextureLevel
== level
&&
2411 att
->CubeMapFace
== face
) {
2412 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2413 /* Tell driver about the new renderbuffer texture */
2414 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2415 /* Mark fb status as indeterminate to force re-validation */
2424 * When a texture image is specified we have to check if it's bound to
2425 * any framebuffer objects (render to texture) in order to detect changes
2426 * in size or format since that effects FBO completeness.
2427 * Any FBOs rendering into the texture must be re-validated.
2430 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2431 GLuint face
, GLuint level
)
2433 /* Only check this texture if it's been marked as RenderToTexture */
2434 if (texObj
->_RenderToTexture
) {
2435 struct cb_info info
;
2437 info
.texObj
= texObj
;
2440 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2445 /** Debug helper: override the user-requested internal format */
2447 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2450 if (internalFormat
== GL_RGBA16F_ARB
||
2451 internalFormat
== GL_RGBA32F_ARB
) {
2452 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2455 else if (internalFormat
== GL_RGB16F_ARB
||
2456 internalFormat
== GL_RGB32F_ARB
) {
2457 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2460 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2461 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2462 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2463 return GL_LUMINANCE_ALPHA
;
2465 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2466 internalFormat
== GL_LUMINANCE32F_ARB
) {
2467 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2468 return GL_LUMINANCE
;
2470 else if (internalFormat
== GL_ALPHA16F_ARB
||
2471 internalFormat
== GL_ALPHA32F_ARB
) {
2472 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2476 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2477 internalFormat = GL_RGBA;
2481 return internalFormat
;
2484 return internalFormat
;
2490 * Called from the API. Note that width includes the border.
2493 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2494 GLsizei width
, GLint border
, GLenum format
,
2495 GLenum type
, const GLvoid
*pixels
)
2497 GLsizei postConvWidth
= width
;
2498 GET_CURRENT_CONTEXT(ctx
);
2499 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2501 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2503 #if FEATURE_convolve
2504 if (_mesa_is_color_format(internalFormat
)) {
2505 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2509 if (target
== GL_TEXTURE_1D
) {
2510 /* non-proxy target */
2511 struct gl_texture_unit
*texUnit
;
2512 struct gl_texture_object
*texObj
;
2513 struct gl_texture_image
*texImage
;
2514 const GLuint face
= _mesa_tex_target_to_face(target
);
2516 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2517 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2518 return; /* error was recorded */
2521 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2522 _mesa_update_state(ctx
);
2524 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2525 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2526 _mesa_lock_texture(ctx
, texObj
);
2528 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2530 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2534 if (texImage
->Data
) {
2535 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2538 ASSERT(texImage
->Data
== NULL
);
2540 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2541 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2542 postConvWidth
, 1, 1,
2543 border
, internalFormat
);
2545 ASSERT(ctx
->Driver
.TexImage1D
);
2547 /* Give the texture to the driver! <pixels> may be null! */
2548 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2549 width
, border
, format
, type
, pixels
,
2550 &ctx
->Unpack
, texObj
, texImage
);
2552 ASSERT(texImage
->TexFormat
);
2554 update_fbo_texture(ctx
, texObj
, face
, level
);
2557 texObj
->_Complete
= GL_FALSE
;
2558 ctx
->NewState
|= _NEW_TEXTURE
;
2561 _mesa_unlock_texture(ctx
, texObj
);
2563 else if (target
== GL_PROXY_TEXTURE_1D
) {
2564 /* Proxy texture: check for errors and update proxy state */
2565 struct gl_texture_image
*texImage
;
2566 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2567 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2568 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2569 /* when error, clear all proxy texture image parameters */
2571 clear_teximage_fields(texImage
);
2574 /* no error, set the tex image parameters */
2576 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2577 postConvWidth
, 1, 1,
2578 border
, internalFormat
);
2579 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2580 internalFormat
, format
, type
);
2584 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2591 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2592 GLsizei width
, GLsizei height
, GLint border
,
2593 GLenum format
, GLenum type
,
2594 const GLvoid
*pixels
)
2596 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2597 GET_CURRENT_CONTEXT(ctx
);
2598 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2600 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2602 #if FEATURE_convolve
2603 if (_mesa_is_color_format(internalFormat
)) {
2604 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2609 if (target
== GL_TEXTURE_2D
||
2610 (ctx
->Extensions
.ARB_texture_cube_map
&&
2611 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2612 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2613 (ctx
->Extensions
.NV_texture_rectangle
&&
2614 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2615 (ctx
->Extensions
.MESA_texture_array
&&
2616 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2617 /* non-proxy target */
2618 struct gl_texture_unit
*texUnit
;
2619 struct gl_texture_object
*texObj
;
2620 struct gl_texture_image
*texImage
;
2621 const GLuint face
= _mesa_tex_target_to_face(target
);
2623 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2624 format
, type
, 2, postConvWidth
, postConvHeight
,
2626 return; /* error was recorded */
2629 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2630 _mesa_update_state(ctx
);
2632 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2633 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2634 _mesa_lock_texture(ctx
, texObj
);
2636 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2638 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2642 if (texImage
->Data
) {
2643 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2646 ASSERT(texImage
->Data
== NULL
);
2647 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2648 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2649 postConvWidth
, postConvHeight
, 1,
2650 border
, internalFormat
);
2652 ASSERT(ctx
->Driver
.TexImage2D
);
2654 /* Give the texture to the driver! <pixels> may be null! */
2655 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2656 width
, height
, border
, format
, type
, pixels
,
2657 &ctx
->Unpack
, texObj
, texImage
);
2659 ASSERT(texImage
->TexFormat
);
2661 update_fbo_texture(ctx
, texObj
, face
, level
);
2664 texObj
->_Complete
= GL_FALSE
;
2665 ctx
->NewState
|= _NEW_TEXTURE
;
2668 _mesa_unlock_texture(ctx
, texObj
);
2670 else if (target
== GL_PROXY_TEXTURE_2D
||
2671 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2672 ctx
->Extensions
.ARB_texture_cube_map
) ||
2673 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2674 ctx
->Extensions
.NV_texture_rectangle
) ||
2675 (ctx
->Extensions
.MESA_texture_array
&&
2676 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2677 /* Proxy texture: check for errors and update proxy state */
2678 struct gl_texture_image
*texImage
;
2679 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2680 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2681 format
, type
, 2, postConvWidth
, postConvHeight
,
2683 /* when error, clear all proxy texture image parameters */
2685 clear_teximage_fields(texImage
);
2688 /* no error, set the tex image parameters */
2689 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2690 postConvWidth
, postConvHeight
, 1,
2691 border
, internalFormat
);
2692 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2693 internalFormat
, format
, type
);
2697 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2704 * Called by the API or display list executor.
2705 * Note that width and height include the border.
2708 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2709 GLsizei width
, GLsizei height
, GLsizei depth
,
2710 GLint border
, GLenum format
, GLenum type
,
2711 const GLvoid
*pixels
)
2713 GET_CURRENT_CONTEXT(ctx
);
2714 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2716 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2718 if (target
== GL_TEXTURE_3D
||
2719 (ctx
->Extensions
.MESA_texture_array
&&
2720 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2721 /* non-proxy target */
2722 struct gl_texture_unit
*texUnit
;
2723 struct gl_texture_object
*texObj
;
2724 struct gl_texture_image
*texImage
;
2725 const GLuint face
= _mesa_tex_target_to_face(target
);
2727 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2728 format
, type
, 3, width
, height
, depth
, border
)) {
2729 return; /* error was recorded */
2732 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2733 _mesa_update_state(ctx
);
2735 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2736 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2737 _mesa_lock_texture(ctx
, texObj
);
2739 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2741 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2745 if (texImage
->Data
) {
2746 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2749 ASSERT(texImage
->Data
== NULL
);
2750 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2751 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2752 width
, height
, depth
,
2753 border
, internalFormat
);
2755 ASSERT(ctx
->Driver
.TexImage3D
);
2757 /* Give the texture to the driver! <pixels> may be null! */
2758 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2759 width
, height
, depth
, border
, format
, type
,
2760 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2762 ASSERT(texImage
->TexFormat
);
2764 update_fbo_texture(ctx
, texObj
, face
, level
);
2767 texObj
->_Complete
= GL_FALSE
;
2768 ctx
->NewState
|= _NEW_TEXTURE
;
2771 _mesa_unlock_texture(ctx
, texObj
);
2773 else if (target
== GL_PROXY_TEXTURE_3D
||
2774 (ctx
->Extensions
.MESA_texture_array
&&
2775 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2776 /* Proxy texture: check for errors and update proxy state */
2777 struct gl_texture_image
*texImage
;
2778 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2779 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2780 format
, type
, 3, width
, height
, depth
, border
)) {
2781 /* when error, clear all proxy texture image parameters */
2783 clear_teximage_fields(texImage
);
2786 /* no error, set the tex image parameters */
2787 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2788 depth
, border
, internalFormat
);
2789 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2790 internalFormat
, format
, type
);
2794 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2801 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2802 GLsizei width
, GLsizei height
, GLsizei depth
,
2803 GLint border
, GLenum format
, GLenum type
,
2804 const GLvoid
*pixels
)
2806 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2807 depth
, border
, format
, type
, pixels
);
2813 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2814 GLint xoffset
, GLsizei width
,
2815 GLenum format
, GLenum type
,
2816 const GLvoid
*pixels
)
2818 GLsizei postConvWidth
= width
;
2819 struct gl_texture_unit
*texUnit
;
2820 struct gl_texture_object
*texObj
;
2821 struct gl_texture_image
*texImage
= NULL
;
2822 GET_CURRENT_CONTEXT(ctx
);
2823 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2825 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2826 _mesa_update_state(ctx
);
2828 #if FEATURE_convolve
2829 /* XXX should test internal format */
2830 if (_mesa_is_color_format(format
)) {
2831 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2835 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2836 postConvWidth
, 1, 1, format
, type
)) {
2837 return; /* error was detected */
2841 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2842 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2845 _mesa_lock_texture(ctx
, texObj
);
2847 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2849 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2850 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2851 goto out
; /* error was detected */
2855 goto out
; /* no-op, not an error */
2857 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2858 xoffset
+= texImage
->Border
;
2860 ASSERT(ctx
->Driver
.TexSubImage1D
);
2861 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2862 format
, type
, pixels
, &ctx
->Unpack
,
2864 ctx
->NewState
|= _NEW_TEXTURE
;
2867 _mesa_unlock_texture(ctx
, texObj
);
2872 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2873 GLint xoffset
, GLint yoffset
,
2874 GLsizei width
, GLsizei height
,
2875 GLenum format
, GLenum type
,
2876 const GLvoid
*pixels
)
2878 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2879 struct gl_texture_unit
*texUnit
;
2880 struct gl_texture_object
*texObj
;
2881 struct gl_texture_image
*texImage
;
2882 GET_CURRENT_CONTEXT(ctx
);
2883 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2885 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2886 _mesa_update_state(ctx
);
2888 #if FEATURE_convolve
2889 /* XXX should test internal format */
2890 if (_mesa_is_color_format(format
)) {
2891 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2896 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2897 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2898 return; /* error was detected */
2901 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2902 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2903 _mesa_lock_texture(ctx
, texObj
);
2905 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2907 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2908 postConvWidth
, postConvHeight
, 1, format
, type
,
2910 goto out
; /* error was detected */
2913 if (width
== 0 || height
== 0)
2914 goto out
; /* no-op, not an error */
2916 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2917 xoffset
+= texImage
->Border
;
2918 yoffset
+= texImage
->Border
;
2920 ASSERT(ctx
->Driver
.TexSubImage2D
);
2921 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2922 width
, height
, format
, type
, pixels
,
2923 &ctx
->Unpack
, texObj
, texImage
);
2924 ctx
->NewState
|= _NEW_TEXTURE
;
2927 _mesa_unlock_texture(ctx
, texObj
);
2933 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2934 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2935 GLsizei width
, GLsizei height
, GLsizei depth
,
2936 GLenum format
, GLenum type
,
2937 const GLvoid
*pixels
)
2939 struct gl_texture_unit
*texUnit
;
2940 struct gl_texture_object
*texObj
;
2941 struct gl_texture_image
*texImage
;
2942 GET_CURRENT_CONTEXT(ctx
);
2943 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2945 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2946 _mesa_update_state(ctx
);
2948 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2949 width
, height
, depth
, format
, type
)) {
2950 return; /* error was detected */
2953 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2954 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2956 _mesa_lock_texture(ctx
, texObj
);
2958 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2960 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2961 width
, height
, depth
, format
, type
, texImage
)) {
2962 goto out
; /* error was detected */
2965 if (width
== 0 || height
== 0 || height
== 0)
2966 goto out
; /* no-op, not an error */
2968 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2969 xoffset
+= texImage
->Border
;
2970 yoffset
+= texImage
->Border
;
2971 zoffset
+= texImage
->Border
;
2973 ASSERT(ctx
->Driver
.TexSubImage3D
);
2974 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2975 xoffset
, yoffset
, zoffset
,
2976 width
, height
, depth
,
2977 format
, type
, pixels
,
2978 &ctx
->Unpack
, texObj
, texImage
);
2979 ctx
->NewState
|= _NEW_TEXTURE
;
2982 _mesa_unlock_texture(ctx
, texObj
);
2988 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2989 GLenum internalFormat
,
2991 GLsizei width
, GLint border
)
2993 struct gl_texture_unit
*texUnit
;
2994 struct gl_texture_object
*texObj
;
2995 struct gl_texture_image
*texImage
;
2996 GLsizei postConvWidth
= width
;
2997 const GLuint face
= _mesa_tex_target_to_face(target
);
2998 GET_CURRENT_CONTEXT(ctx
);
2999 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3001 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3002 _mesa_update_state(ctx
);
3004 #if FEATURE_convolve
3005 if (_mesa_is_color_format(internalFormat
)) {
3006 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3010 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
3011 postConvWidth
, 1, border
))
3014 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3015 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3016 _mesa_lock_texture(ctx
, texObj
);
3018 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3020 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
3024 if (texImage
->Data
) {
3025 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3028 ASSERT(texImage
->Data
== NULL
);
3030 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3031 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
3032 border
, internalFormat
);
3035 ASSERT(ctx
->Driver
.CopyTexImage1D
);
3036 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
3037 x
, y
, width
, border
);
3039 ASSERT(texImage
->TexFormat
);
3041 update_fbo_texture(ctx
, texObj
, face
, level
);
3044 texObj
->_Complete
= GL_FALSE
;
3045 ctx
->NewState
|= _NEW_TEXTURE
;
3048 _mesa_unlock_texture(ctx
, texObj
);
3054 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3055 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3058 struct gl_texture_unit
*texUnit
;
3059 struct gl_texture_object
*texObj
;
3060 struct gl_texture_image
*texImage
;
3061 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3062 const GLuint face
= _mesa_tex_target_to_face(target
);
3063 GET_CURRENT_CONTEXT(ctx
);
3064 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3066 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3067 _mesa_update_state(ctx
);
3069 #if FEATURE_convolve
3070 if (_mesa_is_color_format(internalFormat
)) {
3071 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
3076 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
3077 postConvWidth
, postConvHeight
, border
))
3080 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3081 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3083 _mesa_lock_texture(ctx
, texObj
);
3085 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3088 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3092 if (texImage
->Data
) {
3093 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3096 ASSERT(texImage
->Data
== NULL
);
3098 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3099 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3100 postConvWidth
, postConvHeight
, 1,
3101 border
, internalFormat
);
3103 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3104 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3105 x
, y
, width
, height
, border
);
3107 ASSERT(texImage
->TexFormat
);
3109 update_fbo_texture(ctx
, texObj
, face
, level
);
3112 texObj
->_Complete
= GL_FALSE
;
3113 ctx
->NewState
|= _NEW_TEXTURE
;
3116 _mesa_unlock_texture(ctx
, texObj
);
3121 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3122 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3124 struct gl_texture_unit
*texUnit
;
3125 struct gl_texture_object
*texObj
;
3126 struct gl_texture_image
*texImage
;
3127 GLsizei postConvWidth
= width
;
3131 GET_CURRENT_CONTEXT(ctx
);
3132 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3134 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3135 _mesa_update_state(ctx
);
3137 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3140 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3141 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3143 _mesa_lock_texture(ctx
, texObj
);
3145 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3147 #if FEATURE_convolve
3148 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3149 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3153 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3154 xoffset
, 0, 0, postConvWidth
, 1,
3159 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3160 xoffset
+= texImage
->Border
;
3162 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3164 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3165 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3166 xoffset
, x
, y
, width
);
3169 ctx
->NewState
|= _NEW_TEXTURE
;
3172 _mesa_unlock_texture(ctx
, texObj
);
3178 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3179 GLint xoffset
, GLint yoffset
,
3180 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3182 struct gl_texture_unit
*texUnit
;
3183 struct gl_texture_object
*texObj
;
3184 struct gl_texture_image
*texImage
;
3185 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3186 GET_CURRENT_CONTEXT(ctx
);
3187 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3189 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3190 _mesa_update_state(ctx
);
3192 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3195 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3196 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3198 _mesa_lock_texture(ctx
, texObj
);
3200 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3202 #if FEATURE_convolve
3203 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3204 _mesa_adjust_image_for_convolution(ctx
, 2,
3205 &postConvWidth
, &postConvHeight
);
3209 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3210 postConvWidth
, postConvHeight
, texImage
))
3213 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3214 xoffset
+= texImage
->Border
;
3215 yoffset
+= texImage
->Border
;
3217 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3219 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3220 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3221 xoffset
, yoffset
, x
, y
, width
, height
);
3224 ctx
->NewState
|= _NEW_TEXTURE
;
3227 _mesa_unlock_texture(ctx
, texObj
);
3233 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3234 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3235 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3237 struct gl_texture_unit
*texUnit
;
3238 struct gl_texture_object
*texObj
;
3239 struct gl_texture_image
*texImage
;
3240 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3241 GET_CURRENT_CONTEXT(ctx
);
3242 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3244 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3245 _mesa_update_state(ctx
);
3247 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3250 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3251 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3253 _mesa_lock_texture(ctx
, texObj
);
3255 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3257 #if FEATURE_convolve
3258 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3259 _mesa_adjust_image_for_convolution(ctx
, 2,
3260 &postConvWidth
, &postConvHeight
);
3264 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3265 zoffset
, postConvWidth
, postConvHeight
,
3269 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3270 xoffset
+= texImage
->Border
;
3271 yoffset
+= texImage
->Border
;
3272 zoffset
+= texImage
->Border
;
3274 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3276 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3277 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3278 xoffset
, yoffset
, zoffset
,
3279 x
, y
, width
, height
);
3282 ctx
->NewState
|= _NEW_TEXTURE
;
3285 _mesa_unlock_texture(ctx
, texObj
);
3291 /**********************************************************************/
3292 /****** Compressed Textures ******/
3293 /**********************************************************************/
3297 * Error checking for glCompressedTexImage[123]D().
3298 * \return error code or GL_NO_ERROR.
3301 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3302 GLenum target
, GLint level
,
3303 GLenum internalFormat
, GLsizei width
,
3304 GLsizei height
, GLsizei depth
, GLint border
,
3307 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3309 if (dimensions
== 1) {
3310 /* 1D compressed textures not allowed */
3311 return GL_INVALID_ENUM
;
3313 else if (dimensions
== 2) {
3314 if (target
== GL_PROXY_TEXTURE_2D
) {
3315 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3317 else if (target
== GL_TEXTURE_2D
) {
3318 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3320 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3321 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3322 return GL_INVALID_ENUM
; /*target*/
3323 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3325 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3326 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3327 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3328 return GL_INVALID_ENUM
; /*target*/
3329 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3332 return GL_INVALID_ENUM
; /*target*/
3335 else if (dimensions
== 3) {
3336 /* 3D compressed textures not allowed */
3337 return GL_INVALID_ENUM
;
3340 maxTextureSize
= 1 << (maxLevels
- 1);
3342 /* This will detect any invalid internalFormat value */
3343 if (!is_compressed_format(ctx
, internalFormat
))
3344 return GL_INVALID_ENUM
;
3346 /* This should really never fail */
3347 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3348 return GL_INVALID_ENUM
;
3351 return GL_INVALID_VALUE
;
3354 * XXX We should probably use the proxy texture error check function here.
3356 if (width
< 1 || width
> maxTextureSize
||
3357 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3358 return GL_INVALID_VALUE
;
3360 if ((height
< 1 || height
> maxTextureSize
||
3361 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3363 return GL_INVALID_VALUE
;
3365 if ((depth
< 1 || depth
> maxTextureSize
||
3366 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3368 return GL_INVALID_VALUE
;
3370 /* For cube map, width must equal height */
3371 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3372 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3373 return GL_INVALID_VALUE
;
3375 if (level
< 0 || level
>= maxLevels
)
3376 return GL_INVALID_VALUE
;
3378 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3379 depth
, internalFormat
);
3380 if (expectedSize
!= imageSize
)
3381 return GL_INVALID_VALUE
;
3383 #if FEATURE_EXT_texture_sRGB
3384 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3385 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3386 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3387 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3389 return GL_INVALID_OPERATION
;
3398 * Error checking for glCompressedTexSubImage[123]D().
3399 * \warning There are some bad assumptions here about the size of compressed
3400 * texture tiles (multiple of 4) used to test the validity of the
3401 * offset and size parameters.
3402 * \return error code or GL_NO_ERROR.
3405 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3406 GLenum target
, GLint level
,
3407 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3408 GLsizei width
, GLsizei height
, GLsizei depth
,
3409 GLenum format
, GLsizei imageSize
)
3411 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3414 if (dimensions
== 1) {
3415 /* 1D compressed textures not allowed */
3416 return GL_INVALID_ENUM
;
3418 else if (dimensions
== 2) {
3419 if (target
== GL_PROXY_TEXTURE_2D
) {
3420 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3422 else if (target
== GL_TEXTURE_2D
) {
3423 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3425 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3426 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3427 return GL_INVALID_ENUM
; /*target*/
3428 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3430 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3431 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3432 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3433 return GL_INVALID_ENUM
; /*target*/
3434 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3437 return GL_INVALID_ENUM
; /*target*/
3440 else if (dimensions
== 3) {
3441 /* 3D compressed textures not allowed */
3442 return GL_INVALID_ENUM
;
3445 maxTextureSize
= 1 << (maxLevels
- 1);
3447 /* this will catch any invalid compressed format token */
3448 if (!is_compressed_format(ctx
, format
))
3449 return GL_INVALID_ENUM
;
3451 if (width
< 1 || width
> maxTextureSize
)
3452 return GL_INVALID_VALUE
;
3454 if ((height
< 1 || height
> maxTextureSize
)
3456 return GL_INVALID_VALUE
;
3458 if (level
< 0 || level
>= maxLevels
)
3459 return GL_INVALID_VALUE
;
3461 /* XXX these tests are specific to the compressed format.
3462 * this code should be generalized in some way.
3464 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3465 return GL_INVALID_VALUE
;
3467 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3468 return GL_INVALID_VALUE
;
3470 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3471 return GL_INVALID_VALUE
;
3473 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3475 if (expectedSize
!= imageSize
)
3476 return GL_INVALID_VALUE
;
3484 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3485 GLenum internalFormat
, GLsizei width
,
3486 GLint border
, GLsizei imageSize
,
3489 GET_CURRENT_CONTEXT(ctx
);
3490 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3492 if (target
== GL_TEXTURE_1D
) {
3493 /* non-proxy target */
3494 struct gl_texture_unit
*texUnit
;
3495 struct gl_texture_object
*texObj
;
3496 struct gl_texture_image
*texImage
;
3497 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3498 internalFormat
, width
, 1, 1, border
, imageSize
);
3500 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3504 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3505 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3507 _mesa_lock_texture(ctx
, texObj
);
3509 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3511 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3515 if (texImage
->Data
) {
3516 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3518 ASSERT(texImage
->Data
== NULL
);
3520 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3521 border
, internalFormat
);
3523 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3524 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3525 internalFormat
, width
, border
,
3530 texObj
->_Complete
= GL_FALSE
;
3531 ctx
->NewState
|= _NEW_TEXTURE
;
3534 _mesa_unlock_texture(ctx
, texObj
);
3536 else if (target
== GL_PROXY_TEXTURE_1D
) {
3537 /* Proxy texture: check for errors and update proxy state */
3538 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3539 internalFormat
, width
, 1, 1, border
, imageSize
);
3541 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3542 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3543 internalFormat
, GL_NONE
, GL_NONE
,
3544 width
, 1, 1, border
);
3547 /* if error, clear all proxy texture image parameters */
3548 struct gl_texture_image
*texImage
;
3549 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3551 clear_teximage_fields(texImage
);
3554 /* store the teximage parameters */
3555 struct gl_texture_unit
*texUnit
;
3556 struct gl_texture_object
*texObj
;
3557 struct gl_texture_image
*texImage
;
3558 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3559 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3561 _mesa_lock_texture(ctx
, texObj
);
3563 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3564 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3565 border
, internalFormat
);
3567 _mesa_unlock_texture(ctx
, texObj
);
3571 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3578 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3579 GLenum internalFormat
, GLsizei width
,
3580 GLsizei height
, GLint border
, GLsizei imageSize
,
3583 GET_CURRENT_CONTEXT(ctx
);
3584 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3586 if (target
== GL_TEXTURE_2D
||
3587 (ctx
->Extensions
.ARB_texture_cube_map
&&
3588 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3589 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3590 /* non-proxy target */
3591 struct gl_texture_unit
*texUnit
;
3592 struct gl_texture_object
*texObj
;
3593 struct gl_texture_image
*texImage
;
3594 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3595 internalFormat
, width
, height
, 1, border
, imageSize
);
3597 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3601 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3602 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3604 _mesa_lock_texture(ctx
, texObj
);
3606 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3608 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3612 if (texImage
->Data
) {
3613 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3615 ASSERT(texImage
->Data
== NULL
);
3617 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3618 border
, internalFormat
);
3620 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3621 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3622 internalFormat
, width
, height
,
3623 border
, imageSize
, data
,
3627 texObj
->_Complete
= GL_FALSE
;
3628 ctx
->NewState
|= _NEW_TEXTURE
;
3631 _mesa_unlock_texture(ctx
, texObj
);
3633 else if (target
== GL_PROXY_TEXTURE_2D
||
3634 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3635 ctx
->Extensions
.ARB_texture_cube_map
)) {
3636 /* Proxy texture: check for errors and update proxy state */
3637 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3638 internalFormat
, width
, height
, 1, border
, imageSize
);
3640 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3641 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3642 internalFormat
, GL_NONE
, GL_NONE
,
3643 width
, height
, 1, border
);
3646 /* if error, clear all proxy texture image parameters */
3647 struct gl_texture_image
*texImage
;
3648 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3650 clear_teximage_fields(texImage
);
3653 /* store the teximage parameters */
3654 struct gl_texture_unit
*texUnit
;
3655 struct gl_texture_object
*texObj
;
3656 struct gl_texture_image
*texImage
;
3657 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3658 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3660 _mesa_lock_texture(ctx
, texObj
);
3662 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3663 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3664 border
, internalFormat
);
3666 _mesa_unlock_texture(ctx
, texObj
);
3670 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3677 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3678 GLenum internalFormat
, GLsizei width
,
3679 GLsizei height
, GLsizei depth
, GLint border
,
3680 GLsizei imageSize
, const GLvoid
*data
)
3682 GET_CURRENT_CONTEXT(ctx
);
3683 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3685 if (target
== GL_TEXTURE_3D
) {
3686 /* non-proxy target */
3687 struct gl_texture_unit
*texUnit
;
3688 struct gl_texture_object
*texObj
;
3689 struct gl_texture_image
*texImage
;
3690 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3691 internalFormat
, width
, height
, depth
, border
, imageSize
);
3693 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3697 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3698 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3699 _mesa_lock_texture(ctx
, texObj
);
3701 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3703 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3707 if (texImage
->Data
) {
3708 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3710 ASSERT(texImage
->Data
== NULL
);
3712 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3713 border
, internalFormat
);
3715 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3716 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3718 width
, height
, depth
,
3719 border
, imageSize
, data
,
3723 texObj
->_Complete
= GL_FALSE
;
3724 ctx
->NewState
|= _NEW_TEXTURE
;
3727 _mesa_unlock_texture(ctx
, texObj
);
3729 else if (target
== GL_PROXY_TEXTURE_3D
) {
3730 /* Proxy texture: check for errors and update proxy state */
3731 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3732 internalFormat
, width
, height
, depth
, border
, imageSize
);
3734 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3735 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3736 internalFormat
, GL_NONE
, GL_NONE
,
3737 width
, height
, depth
, border
);
3740 /* if error, clear all proxy texture image parameters */
3741 struct gl_texture_image
*texImage
;
3742 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3744 clear_teximage_fields(texImage
);
3747 /* store the teximage parameters */
3748 struct gl_texture_unit
*texUnit
;
3749 struct gl_texture_object
*texObj
;
3750 struct gl_texture_image
*texImage
;
3751 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3752 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3753 _mesa_lock_texture(ctx
, texObj
);
3755 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3756 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3757 depth
, border
, internalFormat
);
3759 _mesa_unlock_texture(ctx
, texObj
);
3763 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3770 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3771 GLsizei width
, GLenum format
,
3772 GLsizei imageSize
, const GLvoid
*data
)
3774 struct gl_texture_unit
*texUnit
;
3775 struct gl_texture_object
*texObj
;
3776 struct gl_texture_image
*texImage
;
3778 GET_CURRENT_CONTEXT(ctx
);
3779 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3781 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3782 xoffset
, 0, 0, /* pos */
3783 width
, 1, 1, /* size */
3786 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3790 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3791 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3792 _mesa_lock_texture(ctx
, texObj
);
3794 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3797 if ((GLint
) format
!= texImage
->InternalFormat
) {
3798 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3799 "glCompressedTexSubImage1D(format)");
3803 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3804 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3809 goto out
; /* no-op, not an error */
3811 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3812 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3814 format
, imageSize
, data
,
3817 ctx
->NewState
|= _NEW_TEXTURE
;
3820 _mesa_unlock_texture(ctx
, texObj
);
3825 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3826 GLint yoffset
, GLsizei width
, GLsizei height
,
3827 GLenum format
, GLsizei imageSize
,
3830 struct gl_texture_unit
*texUnit
;
3831 struct gl_texture_object
*texObj
;
3832 struct gl_texture_image
*texImage
;
3834 GET_CURRENT_CONTEXT(ctx
);
3835 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3837 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3838 xoffset
, yoffset
, 0, /* pos */
3839 width
, height
, 1, /* size */
3842 /* XXX proxy target? */
3843 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3847 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3848 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3849 _mesa_lock_texture(ctx
, texObj
);
3851 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3854 if ((GLint
) format
!= texImage
->InternalFormat
) {
3855 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3856 "glCompressedTexSubImage2D(format)");
3860 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3861 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3862 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3866 if (width
== 0 || height
== 0)
3867 goto out
; /* no-op, not an error */
3869 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3870 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3871 xoffset
, yoffset
, width
, height
,
3872 format
, imageSize
, data
,
3875 ctx
->NewState
|= _NEW_TEXTURE
;
3878 _mesa_unlock_texture(ctx
, texObj
);
3883 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3884 GLint yoffset
, GLint zoffset
, GLsizei width
,
3885 GLsizei height
, GLsizei depth
, GLenum format
,
3886 GLsizei imageSize
, const GLvoid
*data
)
3888 struct gl_texture_unit
*texUnit
;
3889 struct gl_texture_object
*texObj
;
3890 struct gl_texture_image
*texImage
;
3892 GET_CURRENT_CONTEXT(ctx
);
3893 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3895 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3896 xoffset
, yoffset
, zoffset
,/*pos*/
3897 width
, height
, depth
, /*size*/
3900 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3904 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3905 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3906 _mesa_lock_texture(ctx
, texObj
);
3908 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3911 if ((GLint
) format
!= texImage
->InternalFormat
) {
3912 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3913 "glCompressedTexSubImage3D(format)");
3917 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3918 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3919 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3920 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3924 if (width
== 0 || height
== 0 || depth
== 0)
3925 goto out
; /* no-op, not an error */
3927 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3928 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3929 xoffset
, yoffset
, zoffset
,
3930 width
, height
, depth
,
3931 format
, imageSize
, data
,
3934 ctx
->NewState
|= _NEW_TEXTURE
;
3937 _mesa_unlock_texture(ctx
, texObj
);
3942 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3944 const struct gl_texture_unit
*texUnit
;
3945 struct gl_texture_object
*texObj
;
3946 struct gl_texture_image
*texImage
;
3948 GET_CURRENT_CONTEXT(ctx
);
3949 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3951 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3952 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3954 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3958 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3959 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3961 if (level
< 0 || level
>= maxLevels
) {
3962 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3966 if (_mesa_is_proxy_texture(target
)) {
3967 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3971 _mesa_lock_texture(ctx
, texObj
);
3973 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3975 if (texImage
->IsCompressed
) {
3976 /* this typically calls _mesa_get_compressed_teximage() */
3977 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3981 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3982 "glGetCompressedTexImageARB");
3986 /* probably invalid mipmap level */
3987 _mesa_error(ctx
, GL_INVALID_VALUE
,
3988 "glGetCompressedTexImageARB(level)");
3991 _mesa_unlock_texture(ctx
, texObj
);