2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "texcompress.h"
43 #include "texformat.h"
51 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
55 _mesa_alloc_texmemory(GLsizei bytes
)
57 return _mesa_align_malloc(bytes
, 512);
62 * Free texture memory allocated with _mesa_alloc_texmemory()
65 _mesa_free_texmemory(void *m
)
74 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
76 #if CHAN_TYPE == GL_FLOAT
77 _mesa_problem(NULL
, "PrintTexture doesn't support float channels");
80 const GLchan
*data
= (const GLchan
*) img
->Data
;
83 _mesa_printf("No texture data\n");
87 switch (img
->Format
) {
94 case GL_LUMINANCE_ALPHA
:
104 _mesa_problem(NULL
, "error in PrintTexture\n");
108 for (i
= 0; i
< img
->Height
; i
++) {
109 for (j
= 0; j
< img
->Width
; j
++) {
111 _mesa_printf("%02x ", data
[0]);
113 _mesa_printf("%02x%02x ", data
[0], data
[1]);
115 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
117 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
118 data
+= (img
->RowStride
- img
->Width
) * c
;
120 /* XXX use img->ImageStride here */
129 * Compute floor(log_base_2(n)).
130 * If n < 0 return -1.
159 * Return the simple base format for a given internal texture format.
160 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
162 * \param ctx GL context.
163 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
165 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
166 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
168 * This is the format which is used during texture application (i.e. the
169 * texture format and env mode determine the arithmetic used.
172 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
174 switch (internalFormat
) {
189 case GL_LUMINANCE_ALPHA
:
190 case GL_LUMINANCE4_ALPHA4
:
191 case GL_LUMINANCE6_ALPHA2
:
192 case GL_LUMINANCE8_ALPHA8
:
193 case GL_LUMINANCE12_ALPHA4
:
194 case GL_LUMINANCE12_ALPHA12
:
195 case GL_LUMINANCE16_ALPHA16
:
196 return GL_LUMINANCE_ALPHA
;
227 if (ctx
->Extensions
.EXT_paletted_texture
) {
228 switch (internalFormat
) {
230 case GL_COLOR_INDEX1_EXT
:
231 case GL_COLOR_INDEX2_EXT
:
232 case GL_COLOR_INDEX4_EXT
:
233 case GL_COLOR_INDEX8_EXT
:
234 case GL_COLOR_INDEX12_EXT
:
235 case GL_COLOR_INDEX16_EXT
:
236 return GL_COLOR_INDEX
;
242 if (ctx
->Extensions
.SGIX_depth_texture
||
243 ctx
->Extensions
.ARB_depth_texture
) {
244 switch (internalFormat
) {
245 case GL_DEPTH_COMPONENT
:
246 case GL_DEPTH_COMPONENT16_SGIX
:
247 case GL_DEPTH_COMPONENT24_SGIX
:
248 case GL_DEPTH_COMPONENT32_SGIX
:
249 return GL_DEPTH_COMPONENT
;
255 if (ctx
->Extensions
.ARB_texture_compression
) {
256 switch (internalFormat
) {
257 case GL_COMPRESSED_ALPHA
:
259 case GL_COMPRESSED_LUMINANCE
:
261 case GL_COMPRESSED_LUMINANCE_ALPHA
:
262 return GL_LUMINANCE_ALPHA
;
263 case GL_COMPRESSED_INTENSITY
:
265 case GL_COMPRESSED_RGB
:
267 case GL_COMPRESSED_RGBA
:
274 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
275 switch (internalFormat
) {
276 case GL_COMPRESSED_RGB_FXT1_3DFX
:
278 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
285 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
286 switch (internalFormat
) {
287 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
289 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
290 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
291 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
298 if (ctx
->Extensions
.S3_s3tc
) {
299 switch (internalFormat
) {
311 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
312 if (internalFormat
== GL_YCBCR_MESA
)
313 return GL_YCBCR_MESA
;
316 if (ctx
->Extensions
.ARB_texture_float
) {
317 switch (internalFormat
) {
318 case GL_ALPHA16F_ARB
:
319 case GL_ALPHA32F_ARB
:
327 case GL_INTENSITY16F_ARB
:
328 case GL_INTENSITY32F_ARB
:
330 case GL_LUMINANCE16F_ARB
:
331 case GL_LUMINANCE32F_ARB
:
333 case GL_LUMINANCE_ALPHA16F_ARB
:
334 case GL_LUMINANCE_ALPHA32F_ARB
:
335 return GL_LUMINANCE_ALPHA
;
341 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
342 switch (internalFormat
) {
343 case GL_DEPTH_STENCIL_EXT
:
344 case GL_DEPTH24_STENCIL8_EXT
:
345 return GL_DEPTH_STENCIL_EXT
;
351 return -1; /* error */
356 * Test if the given image format is a color/RGBA format (i.e., not color
357 * index, depth, stencil, etc).
358 * \param format the image format value (may by an internal texture format)
359 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
362 is_color_format(GLenum format
)
380 case GL_LUMINANCE_ALPHA
:
381 case GL_LUMINANCE4_ALPHA4
:
382 case GL_LUMINANCE6_ALPHA2
:
383 case GL_LUMINANCE8_ALPHA8
:
384 case GL_LUMINANCE12_ALPHA4
:
385 case GL_LUMINANCE12_ALPHA12
:
386 case GL_LUMINANCE16_ALPHA16
:
413 /* float texture formats */
414 case GL_ALPHA16F_ARB
:
415 case GL_ALPHA32F_ARB
:
416 case GL_LUMINANCE16F_ARB
:
417 case GL_LUMINANCE32F_ARB
:
418 case GL_LUMINANCE_ALPHA16F_ARB
:
419 case GL_LUMINANCE_ALPHA32F_ARB
:
420 case GL_INTENSITY16F_ARB
:
421 case GL_INTENSITY32F_ARB
:
426 /* compressed formats */
427 case GL_COMPRESSED_ALPHA
:
428 case GL_COMPRESSED_LUMINANCE
:
429 case GL_COMPRESSED_LUMINANCE_ALPHA
:
430 case GL_COMPRESSED_INTENSITY
:
431 case GL_COMPRESSED_RGB
:
432 case GL_COMPRESSED_RGBA
:
437 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
438 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
439 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
440 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
441 case GL_COMPRESSED_RGB_FXT1_3DFX
:
442 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
444 case GL_YCBCR_MESA
: /* not considered to be RGB */
452 * Test if the given image format is a color index format.
455 is_index_format(GLenum format
)
459 case GL_COLOR_INDEX1_EXT
:
460 case GL_COLOR_INDEX2_EXT
:
461 case GL_COLOR_INDEX4_EXT
:
462 case GL_COLOR_INDEX8_EXT
:
463 case GL_COLOR_INDEX12_EXT
:
464 case GL_COLOR_INDEX16_EXT
:
473 * Test if the given image format is a depth component format.
476 is_depth_format(GLenum format
)
479 case GL_DEPTH_COMPONENT16_ARB
:
480 case GL_DEPTH_COMPONENT24_ARB
:
481 case GL_DEPTH_COMPONENT32_ARB
:
482 case GL_DEPTH_COMPONENT
:
491 * Test if the given image format is a YCbCr format.
494 is_ycbcr_format(GLenum format
)
506 * Test if the given image format is a Depth/Stencil format.
509 is_depthstencil_format(GLenum format
)
512 case GL_DEPTH24_STENCIL8_EXT
:
513 case GL_DEPTH_STENCIL_EXT
:
523 * Test if it is a supported compressed format.
525 * \param internalFormat the internal format token provided by the user.
527 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
528 * GL_FALSE otherwise.
530 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
534 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
537 switch (internalFormat
) {
538 case GL_COMPRESSED_RGB_FXT1_3DFX
:
539 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
540 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
541 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
542 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
543 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
556 texture_face(GLenum target
)
558 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
559 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
560 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
568 * Store a gl_texture_image pointer in a gl_texture_object structure
569 * according to the target and level parameters.
571 * \param tObj texture object.
572 * \param target texture target.
573 * \param level image level.
574 * \param texImage texture image.
576 * This was basically prompted by the introduction of cube maps.
579 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
580 GLenum target
, GLint level
,
581 struct gl_texture_image
*texImage
)
589 tObj
->Image
[0][level
] = texImage
;
591 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
592 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
593 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
594 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
595 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
596 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
598 GLuint face
= ((GLuint
) target
-
599 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
600 tObj
->Image
[face
][level
] = texImage
;
603 case GL_TEXTURE_RECTANGLE_NV
:
605 tObj
->Image
[0][level
] = texImage
;
608 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
611 /* Set the 'back' pointer */
612 texImage
->TexObject
= tObj
;
617 * Allocate a texture image structure.
619 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
622 * \return a pointer to gl_texture_image struct with all fields initialized to
625 struct gl_texture_image
*
626 _mesa_new_texture_image( GLcontext
*ctx
)
629 return CALLOC_STRUCT(gl_texture_image
);
634 * Free texture image data.
635 * This function is a fallback called via ctx->Driver.FreeTexImageData().
637 * \param teximage texture image.
639 * Free the texture image data if it's not marked as client data.
642 _mesa_free_texture_image_data(GLcontext
*ctx
,
643 struct gl_texture_image
*texImage
)
645 if (texImage
->Data
&& !texImage
->IsClientData
) {
646 /* free the old texture data */
647 _mesa_free_texmemory(texImage
->Data
);
650 texImage
->Data
= NULL
;
655 * Free texture image.
657 * \param teximage texture image.
659 * Free the texture image structure and the associated image data.
662 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
664 if (texImage
->Data
) {
665 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
667 ASSERT(texImage
->Data
== NULL
);
673 * Test if a target is a proxy target.
675 * \param target texture target.
677 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
680 _mesa_is_proxy_texture(GLenum target
)
682 return (target
== GL_PROXY_TEXTURE_1D
||
683 target
== GL_PROXY_TEXTURE_2D
||
684 target
== GL_PROXY_TEXTURE_3D
||
685 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
686 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
);
691 * Get the texture object that corresponds to the target of the given texture unit.
693 * \param ctx GL context.
694 * \param texUnit texture unit.
695 * \param target texture target.
697 * \return pointer to the texture object on success, or NULL on failure.
699 * \sa gl_texture_unit.
701 struct gl_texture_object
*
702 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
707 return texUnit
->Current1D
;
708 case GL_PROXY_TEXTURE_1D
:
709 return ctx
->Texture
.Proxy1D
;
711 return texUnit
->Current2D
;
712 case GL_PROXY_TEXTURE_2D
:
713 return ctx
->Texture
.Proxy2D
;
715 return texUnit
->Current3D
;
716 case GL_PROXY_TEXTURE_3D
:
717 return ctx
->Texture
.Proxy3D
;
718 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
719 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
720 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
721 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
722 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
723 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
724 case GL_TEXTURE_CUBE_MAP_ARB
:
725 return ctx
->Extensions
.ARB_texture_cube_map
726 ? texUnit
->CurrentCubeMap
: NULL
;
727 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
728 return ctx
->Extensions
.ARB_texture_cube_map
729 ? ctx
->Texture
.ProxyCubeMap
: NULL
;
730 case GL_TEXTURE_RECTANGLE_NV
:
731 return ctx
->Extensions
.NV_texture_rectangle
732 ? texUnit
->CurrentRect
: NULL
;
733 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
734 return ctx
->Extensions
.NV_texture_rectangle
735 ? ctx
->Texture
.ProxyRect
: NULL
;
737 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
744 * Get the texture image struct which corresponds to target and level
745 * of the given texture unit.
747 * \param ctx GL context.
748 * \param texUnit texture unit.
749 * \param target texture target.
750 * \param level image level.
752 * \return pointer to the texture image structure on success, or NULL on failure.
754 * \sa gl_texture_unit.
756 struct gl_texture_image
*
757 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
758 GLenum target
, GLint level
)
761 ASSERT(level
< MAX_TEXTURE_LEVELS
);
764 return texUnit
->Current1D
->Image
[0][level
];
765 case GL_PROXY_TEXTURE_1D
:
766 return ctx
->Texture
.Proxy1D
->Image
[0][level
];
768 return texUnit
->Current2D
->Image
[0][level
];
769 case GL_PROXY_TEXTURE_2D
:
770 return ctx
->Texture
.Proxy2D
->Image
[0][level
];
772 return texUnit
->Current3D
->Image
[0][level
];
773 case GL_PROXY_TEXTURE_3D
:
774 return ctx
->Texture
.Proxy3D
->Image
[0][level
];
775 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
776 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
777 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
778 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
779 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
780 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
781 if (ctx
->Extensions
.ARB_texture_cube_map
) {
782 GLuint face
= ((GLuint
) target
-
783 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
784 return texUnit
->CurrentCubeMap
->Image
[face
][level
];
788 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
789 if (ctx
->Extensions
.ARB_texture_cube_map
)
790 return ctx
->Texture
.ProxyCubeMap
->Image
[0][level
];
793 case GL_TEXTURE_RECTANGLE_NV
:
794 if (ctx
->Extensions
.NV_texture_rectangle
) {
796 return texUnit
->CurrentRect
->Image
[0][level
];
801 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
802 if (ctx
->Extensions
.NV_texture_rectangle
) {
804 return ctx
->Texture
.ProxyRect
->Image
[0][level
];
810 _mesa_problem(ctx
, "bad target in _mesa_select_tex_image()");
817 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
818 * it and install it. Only return NULL if passed a bad parameter or run
821 struct gl_texture_image
*
822 _mesa_get_tex_image(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
823 GLenum target
, GLint level
)
825 struct gl_texture_image
*texImage
;
826 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
828 struct gl_texture_object
*texObj
;
829 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
831 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
834 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
836 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
843 * Return pointer to the specified proxy texture image.
844 * Note that proxy textures are per-context, not per-texture unit.
845 * \return pointer to texture image or NULL if invalid target, invalid
846 * level, or out of memory.
848 struct gl_texture_image
*
849 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
851 struct gl_texture_image
*texImage
;
857 case GL_PROXY_TEXTURE_1D
:
858 if (level
>= ctx
->Const
.MaxTextureLevels
)
860 texImage
= ctx
->Texture
.Proxy1D
->Image
[0][level
];
862 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
864 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
867 ctx
->Texture
.Proxy1D
->Image
[0][level
] = texImage
;
868 /* Set the 'back' pointer */
869 texImage
->TexObject
= ctx
->Texture
.Proxy1D
;
872 case GL_PROXY_TEXTURE_2D
:
873 if (level
>= ctx
->Const
.MaxTextureLevels
)
875 texImage
= ctx
->Texture
.Proxy2D
->Image
[0][level
];
877 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
879 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
882 ctx
->Texture
.Proxy2D
->Image
[0][level
] = texImage
;
883 /* Set the 'back' pointer */
884 texImage
->TexObject
= ctx
->Texture
.Proxy2D
;
887 case GL_PROXY_TEXTURE_3D
:
888 if (level
>= ctx
->Const
.Max3DTextureLevels
)
890 texImage
= ctx
->Texture
.Proxy3D
->Image
[0][level
];
892 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
894 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
897 ctx
->Texture
.Proxy3D
->Image
[0][level
] = texImage
;
898 /* Set the 'back' pointer */
899 texImage
->TexObject
= ctx
->Texture
.Proxy3D
;
902 case GL_PROXY_TEXTURE_CUBE_MAP
:
903 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
905 texImage
= ctx
->Texture
.ProxyCubeMap
->Image
[0][level
];
907 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
909 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
912 ctx
->Texture
.ProxyCubeMap
->Image
[0][level
] = texImage
;
913 /* Set the 'back' pointer */
914 texImage
->TexObject
= ctx
->Texture
.ProxyCubeMap
;
917 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
920 texImage
= ctx
->Texture
.ProxyRect
->Image
[0][level
];
922 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
924 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
927 ctx
->Texture
.ProxyRect
->Image
[0][level
] = texImage
;
928 /* Set the 'back' pointer */
929 texImage
->TexObject
= ctx
->Texture
.ProxyRect
;
939 * Get the maximum number of allowed mipmap levels.
941 * \param ctx GL context.
942 * \param target texture target.
944 * \return the maximum number of allowed mipmap levels for the given
945 * texture target, or zero if passed a bad target.
950 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
954 case GL_PROXY_TEXTURE_1D
:
956 case GL_PROXY_TEXTURE_2D
:
957 return ctx
->Const
.MaxTextureLevels
;
959 case GL_PROXY_TEXTURE_3D
:
960 return ctx
->Const
.Max3DTextureLevels
;
961 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
962 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
963 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
964 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
965 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
966 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
967 case GL_TEXTURE_CUBE_MAP_ARB
:
968 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
969 return ctx
->Const
.MaxCubeTextureLevels
;
970 case GL_TEXTURE_RECTANGLE_NV
:
971 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
974 return 0; /* bad target */
980 #if 000 /* not used anymore */
982 * glTexImage[123]D can accept a NULL image pointer. In this case we
983 * create a texture image with unspecified image contents per the OpenGL
987 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
989 const GLint components
= _mesa_components_in_format(format
);
990 const GLint numPixels
= width
* height
* depth
;
991 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
995 * Let's see if anyone finds this. If glTexImage2D() is called with
996 * a NULL image pointer then load the texture image with something
997 * interesting instead of leaving it indeterminate.
1000 static const char message
[8][32] = {
1001 " X X XXXXX XXX X ",
1002 " XX XX X X X X X ",
1004 " X X XXXX XXX XXXXX ",
1007 " X X XXXXX XXX X X ",
1011 GLubyte
*imgPtr
= data
;
1013 for (h
= 0; h
< depth
; h
++) {
1014 for (i
= 0; i
< height
; i
++) {
1015 GLint srcRow
= 7 - (i
% 8);
1016 for (j
= 0; j
< width
; j
++) {
1017 GLint srcCol
= j
% 32;
1018 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1019 for (k
= 0; k
< components
; k
++) {
1035 * Reset the fields of a gl_texture_image struct to zero.
1037 * \param img texture image structure.
1039 * This is called when a proxy texture test fails, we set all the
1040 * image members (except DriverData) to zero.
1041 * It's also used in glTexImage[123]D as a safeguard to be sure all
1042 * required fields get initialized properly by the Driver.TexImage[123]D
1046 clear_teximage_fields(struct gl_texture_image
*img
)
1049 img
->_BaseFormat
= 0;
1050 img
->InternalFormat
= 0;
1056 img
->ImageStride
= 0;
1061 img
->HeightLog2
= 0;
1064 img
->TexFormat
= &_mesa_null_texformat
;
1065 img
->FetchTexelc
= NULL
;
1066 img
->FetchTexelf
= NULL
;
1067 img
->IsCompressed
= 0;
1068 img
->CompressedSize
= 0;
1073 * Initialize basic fields of the gl_texture_image struct.
1075 * \param ctx GL context.
1076 * \param target texture target.
1077 * \param img texture image structure to be initialized.
1078 * \param width image width.
1079 * \param height image height.
1080 * \param depth image depth.
1081 * \param border image border.
1082 * \param internalFormat internal format.
1084 * Fills in the fields of \p img with the given information.
1085 * Note: width, height and depth include the border.
1088 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1089 struct gl_texture_image
*img
,
1090 GLsizei width
, GLsizei height
, GLsizei depth
,
1091 GLint border
, GLenum internalFormat
)
1094 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1095 ASSERT(img
->_BaseFormat
> 0);
1096 img
->InternalFormat
= internalFormat
;
1097 img
->Border
= border
;
1099 img
->Height
= height
;
1101 img
->RowStride
= width
;
1102 img
->ImageStride
= width
* height
;
1103 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1104 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1105 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1106 img
->WidthLog2
= logbase2(img
->Width2
);
1107 if (height
== 1) /* 1-D texture */
1108 img
->HeightLog2
= 0;
1110 img
->HeightLog2
= logbase2(img
->Height2
);
1111 if (depth
== 1) /* 2-D texture */
1114 img
->DepthLog2
= logbase2(img
->Depth2
);
1115 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1116 img
->IsCompressed
= GL_FALSE
;
1117 img
->CompressedSize
= 0;
1119 if ((width
== 1 || _mesa_bitcount(img
->Width2
) == 1) &&
1120 (height
== 1 || _mesa_bitcount(img
->Height2
) == 1) &&
1121 (depth
== 1 || _mesa_bitcount(img
->Depth2
) == 1))
1122 img
->_IsPowerOfTwo
= GL_TRUE
;
1124 img
->_IsPowerOfTwo
= GL_FALSE
;
1126 /* Compute Width/Height/DepthScale for mipmap lod computation */
1127 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1128 /* scale = 1.0 since texture coords directly map to texels */
1129 img
->WidthScale
= 1.0;
1130 img
->HeightScale
= 1.0;
1131 img
->DepthScale
= 1.0;
1134 img
->WidthScale
= (GLfloat
) img
->Width
;
1135 img
->HeightScale
= (GLfloat
) img
->Height
;
1136 img
->DepthScale
= (GLfloat
) img
->Depth
;
1142 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1143 * level, width, height and depth against the ctx->Const limits for textures.
1145 * A hardware driver might override this function if, for example, the
1146 * max 3D texture size is 512x512x64 (i.e. not a cube).
1148 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1149 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1150 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1151 * \param level as passed to glTexImage
1152 * \param internalFormat as passed to glTexImage
1153 * \param format as passed to glTexImage
1154 * \param type as passed to glTexImage
1155 * \param width as passed to glTexImage
1156 * \param height as passed to glTexImage
1157 * \param depth as passed to glTexImage
1158 * \param border as passed to glTexImage
1159 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1162 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1163 GLint internalFormat
, GLenum format
, GLenum type
,
1164 GLint width
, GLint height
, GLint depth
, GLint border
)
1168 (void) internalFormat
;
1173 case GL_PROXY_TEXTURE_1D
:
1174 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1175 if (width
< 2 * border
|| width
> 2 + maxSize
||
1176 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1177 _mesa_bitcount(width
- 2 * border
) != 1) ||
1178 level
>= ctx
->Const
.MaxTextureLevels
) {
1179 /* bad width or level */
1183 case GL_PROXY_TEXTURE_2D
:
1184 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1185 if (width
< 2 * border
|| width
> 2 + maxSize
||
1186 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1187 _mesa_bitcount(width
- 2 * border
) != 1) ||
1188 height
< 2 * border
|| height
> 2 + maxSize
||
1189 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1190 _mesa_bitcount(height
- 2 * border
) != 1) ||
1191 level
>= ctx
->Const
.MaxTextureLevels
) {
1192 /* bad width or height or level */
1196 case GL_PROXY_TEXTURE_3D
:
1197 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1198 if (width
< 2 * border
|| width
> 2 + maxSize
||
1199 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1200 _mesa_bitcount(width
- 2 * border
) != 1) ||
1201 height
< 2 * border
|| height
> 2 + maxSize
||
1202 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1203 _mesa_bitcount(height
- 2 * border
) != 1) ||
1204 depth
< 2 * border
|| depth
> 2 + maxSize
||
1205 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1206 _mesa_bitcount(depth
- 2 * border
) != 1) ||
1207 level
>= ctx
->Const
.Max3DTextureLevels
) {
1208 /* bad width or height or depth or level */
1212 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1213 if (width
< 1 || width
> ctx
->Const
.MaxTextureRectSize
||
1214 height
< 1 || height
> ctx
->Const
.MaxTextureRectSize
||
1216 /* bad width or height or level */
1220 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1221 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1222 if (width
< 2 * border
|| width
> 2 + maxSize
||
1223 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1224 _mesa_bitcount(width
- 2 * border
) != 1) ||
1225 height
< 2 * border
|| height
> 2 + maxSize
||
1226 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1227 _mesa_bitcount(height
- 2 * border
) != 1) ||
1228 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1229 /* bad width or height */
1234 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1241 * Test the glTexImage[123]D() parameters for errors.
1243 * \param ctx GL context.
1244 * \param target texture target given by the user.
1245 * \param level image level given by the user.
1246 * \param internalFormat internal format given by the user.
1247 * \param format pixel data format given by the user.
1248 * \param type pixel data type given by the user.
1249 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1250 * \param width image width given by the user.
1251 * \param height image height given by the user.
1252 * \param depth image depth given by the user.
1253 * \param border image border given by the user.
1255 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1257 * Verifies each of the parameters against the constants specified in
1258 * __GLcontextRec::Const and the supported extensions, and according to the
1259 * OpenGL specification.
1262 texture_error_check( GLcontext
*ctx
, GLenum target
,
1263 GLint level
, GLint internalFormat
,
1264 GLenum format
, GLenum type
,
1266 GLint width
, GLint height
,
1267 GLint depth
, GLint border
)
1269 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1271 GLboolean colorFormat
, indexFormat
;
1273 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1274 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1276 _mesa_error(ctx
, GL_INVALID_VALUE
,
1277 "glTexImage%dD(level=%d)", dimensions
, level
);
1283 if (border
< 0 || border
> 1 ||
1284 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1285 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1287 _mesa_error(ctx
, GL_INVALID_VALUE
,
1288 "glTexImage%dD(border=%d)", dimensions
, border
);
1293 if (width
< 0 || height
< 0 || depth
< 0) {
1295 _mesa_error(ctx
, GL_INVALID_VALUE
,
1296 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1301 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1302 * level, width, height and depth.
1304 if (dimensions
== 1) {
1305 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1306 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1307 level
, internalFormat
,
1309 width
, 1, 1, border
);
1312 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1316 else if (dimensions
== 2) {
1317 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1318 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1319 level
, internalFormat
,
1321 width
, height
, 1, border
);
1323 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1324 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1325 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1326 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1327 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1330 sizeOK
= (width
== height
) &&
1331 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1332 level
, internalFormat
, format
, type
,
1333 width
, height
, 1, border
);
1335 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1336 target
== GL_TEXTURE_RECTANGLE_NV
) {
1337 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1338 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1341 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1342 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1343 level
, internalFormat
,
1345 width
, height
, 1, border
);
1348 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1352 else if (dimensions
== 3) {
1353 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1354 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_3D
,
1355 level
, internalFormat
,
1357 width
, height
, depth
, border
);
1360 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1365 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1371 _mesa_error(ctx
, GL_INVALID_VALUE
,
1372 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1373 dimensions
, level
, width
, height
, depth
);
1378 /* Check internalFormat */
1379 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1381 _mesa_error(ctx
, GL_INVALID_VALUE
,
1382 "glTexImage%dD(internalFormat=0x%x)",
1383 dimensions
, internalFormat
);
1388 /* Check incoming image format and type */
1389 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1390 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1391 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1394 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1395 "glTexImage%dD(format or type)", dimensions
);
1400 /* make sure internal format and format basically agree */
1401 colorFormat
= is_color_format(format
);
1402 indexFormat
= is_index_format(format
);
1403 if ((is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1404 (is_index_format(internalFormat
) && !indexFormat
) ||
1405 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1406 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1407 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
))) {
1409 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1410 "glTexImage(internalFormat/format)");
1414 /* additional checks for ycbcr textures */
1415 if (internalFormat
== GL_YCBCR_MESA
) {
1416 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1417 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1418 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1420 _mesa_sprintf(message
,
1421 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1422 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1423 return GL_TRUE
; /* error */
1425 if (target
!= GL_TEXTURE_2D
&&
1426 target
!= GL_PROXY_TEXTURE_2D
&&
1427 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1428 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1430 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1436 _mesa_sprintf(message
,
1437 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1438 dimensions
, border
);
1439 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1445 /* additional checks for depth textures */
1446 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1447 /* Only 1D and 2D textures supported */
1448 if (target
!= GL_TEXTURE_1D
&&
1449 target
!= GL_PROXY_TEXTURE_1D
&&
1450 target
!= GL_TEXTURE_2D
&&
1451 target
!= GL_PROXY_TEXTURE_2D
) {
1453 _mesa_error(ctx
, GL_INVALID_ENUM
,
1454 "glTexImage(target/internalFormat)");
1459 /* additional checks for compressed textures */
1460 if (is_compressed_format(ctx
, internalFormat
)) {
1461 if (target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
) {
1464 else if (ctx
->Extensions
.ARB_texture_cube_map
&&
1465 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1466 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1467 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))) {
1472 _mesa_error(ctx
, GL_INVALID_ENUM
,
1473 "glTexImage%d(target)", dimensions
);
1479 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1480 "glTexImage%D(border!=0)", dimensions
);
1486 /* if we get here, the parameters are OK */
1492 * Test glTexSubImage[123]D() parameters for errors.
1494 * \param ctx GL context.
1495 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1496 * \param target texture target given by the user.
1497 * \param level image level given by the user.
1498 * \param xoffset sub-image x offset given by the user.
1499 * \param yoffset sub-image y offset given by the user.
1500 * \param zoffset sub-image z offset given by the user.
1501 * \param format pixel data format given by the user.
1502 * \param type pixel data type given by the user.
1503 * \param width image width given by the user.
1504 * \param height image height given by the user.
1505 * \param depth image depth given by the user.
1507 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1509 * Verifies each of the parameters against the constants specified in
1510 * __GLcontextRec::Const and the supported extensions, and according to the
1511 * OpenGL specification.
1514 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1515 GLenum target
, GLint level
,
1516 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1517 GLint width
, GLint height
, GLint depth
,
1518 GLenum format
, GLenum type
)
1520 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1521 struct gl_texture_image
*destTex
;
1524 if (dimensions
== 1) {
1525 if (target
!= GL_TEXTURE_1D
) {
1526 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1530 else if (dimensions
== 2) {
1531 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1532 target
<=GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1533 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1534 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1538 else if (ctx
->Extensions
.NV_texture_rectangle
&&
1539 target
== GL_TEXTURE_RECTANGLE_NV
) {
1540 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1541 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1545 else if (target
!= GL_TEXTURE_2D
) {
1546 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1550 else if (dimensions
== 3) {
1551 if (target
!= GL_TEXTURE_3D
) {
1552 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1557 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1561 /* Basic level check */
1562 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1563 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1568 _mesa_error(ctx
, GL_INVALID_VALUE
,
1569 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1572 if (height
< 0 && dimensions
> 1) {
1573 _mesa_error(ctx
, GL_INVALID_VALUE
,
1574 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1577 if (depth
< 0 && dimensions
> 2) {
1578 _mesa_error(ctx
, GL_INVALID_VALUE
,
1579 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1583 destTex
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1586 /* undefined image level */
1587 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1591 if (xoffset
< -((GLint
)destTex
->Border
)) {
1592 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1596 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1597 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1601 if (dimensions
> 1) {
1602 if (yoffset
< -((GLint
)destTex
->Border
)) {
1603 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1607 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1608 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1613 if (dimensions
> 2) {
1614 if (zoffset
< -((GLint
)destTex
->Border
)) {
1615 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1618 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1619 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1624 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1625 _mesa_error(ctx
, GL_INVALID_ENUM
,
1626 "glTexSubImage%dD(format or type)", dimensions
);
1630 if (destTex
->IsCompressed
) {
1631 const struct gl_texture_unit
*texUnit
;
1632 const struct gl_texture_image
*texImage
;
1633 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1634 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1636 if (target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
) {
1639 else if (ctx
->Extensions
.ARB_texture_cube_map
&&
1640 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1641 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1642 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))) {
1646 _mesa_error(ctx
, GL_INVALID_ENUM
,
1647 "glTexSubImage%D(target)", dimensions
);
1650 /* offset must be multiple of 4 */
1651 if ((xoffset
& 3) || (yoffset
& 3)) {
1652 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1653 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1656 /* size must be multiple of 4 or equal to whole texture size */
1657 if ((width
& 3) && (GLuint
) width
!= texImage
->Width
) {
1658 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1659 "glTexSubImage%D(width)", dimensions
);
1662 if ((height
& 3) && (GLuint
) height
!= texImage
->Height
) {
1663 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1664 "glTexSubImage%D(width)", dimensions
);
1674 * Test glCopyTexImage[12]D() parameters for errors.
1676 * \param ctx GL context.
1677 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1678 * \param target texture target given by the user.
1679 * \param level image level given by the user.
1680 * \param internalFormat internal format given by the user.
1681 * \param width image width given by the user.
1682 * \param height image height given by the user.
1683 * \param depth image depth given by the user.
1684 * \param border texture border.
1686 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1688 * Verifies each of the parameters against the constants specified in
1689 * __GLcontextRec::Const and the supported extensions, and according to the
1690 * OpenGL specification.
1693 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1694 GLenum target
, GLint level
, GLint internalFormat
,
1695 GLint width
, GLint height
, GLint border
)
1701 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1702 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1703 /* Check that the source buffer is complete */
1704 if (ctx
->ReadBuffer
->Name
) {
1705 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1706 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1707 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1708 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1713 _mesa_error(ctx
, GL_INVALID_VALUE
,
1714 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1719 if (border
< 0 || border
> 1 ||
1720 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1721 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1725 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1727 _mesa_error(ctx
, GL_INVALID_VALUE
,
1728 "glCopyTexImage%dD(internalFormat)", dimensions
);
1732 /* NOTE: the format and type aren't really significant for
1733 * TestProxyTexImage(). Only the internalformat really matters.
1734 if (!_mesa_source_buffer_exists(ctx, format)) {
1735 _mesa_error(ctx, GL_INVALID_OPERATION,
1736 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1743 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1744 * level, width, height and depth.
1746 if (dimensions
== 1) {
1747 if (target
== GL_TEXTURE_1D
) {
1748 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1749 level
, internalFormat
,
1751 width
, 1, 1, border
);
1754 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1758 else if (dimensions
== 2) {
1759 if (target
== GL_TEXTURE_2D
) {
1760 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1761 level
, internalFormat
,
1763 width
, height
, 1, border
);
1765 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1766 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1767 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1768 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1771 sizeOK
= (width
== height
) &&
1772 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1773 level
, internalFormat
, format
, type
,
1774 width
, height
, 1, border
);
1776 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1777 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1778 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1781 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1782 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1783 level
, internalFormat
,
1785 width
, height
, 1, border
);
1788 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1793 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1798 if (dimensions
== 1) {
1799 _mesa_error(ctx
, GL_INVALID_VALUE
,
1800 "glCopyTexImage1D(width=%d)", width
);
1803 ASSERT(dimensions
== 2);
1804 _mesa_error(ctx
, GL_INVALID_VALUE
,
1805 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1810 if (is_compressed_format(ctx
, internalFormat
)) {
1811 if (target
!= GL_TEXTURE_2D
) {
1812 _mesa_error(ctx
, GL_INVALID_ENUM
,
1813 "glCopyTexImage%d(target)", dimensions
);
1817 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1818 "glCopyTexImage%D(border!=0)", dimensions
);
1822 else if (is_depth_format(internalFormat
)) {
1823 /* make sure we have depth/stencil buffers */
1824 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1825 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1826 "glCopyTexImage%D(no depth)", dimensions
);
1830 else if (is_depthstencil_format(internalFormat
)) {
1831 /* make sure we have depth/stencil buffers */
1832 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1833 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1834 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
1839 /* if we get here, the parameters are OK */
1845 * Test glCopyTexSubImage[12]D() parameters for errors.
1847 * \param ctx GL context.
1848 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1849 * \param target texture target given by the user.
1850 * \param level image level given by the user.
1851 * \param xoffset sub-image x offset given by the user.
1852 * \param yoffset sub-image y offset given by the user.
1853 * \param zoffset sub-image z offset given by the user.
1854 * \param width image width given by the user.
1855 * \param height image height given by the user.
1857 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1859 * Verifies each of the parameters against the constants specified in
1860 * __GLcontextRec::Const and the supported extensions, and according to the
1861 * OpenGL specification.
1864 copytexsubimage_error_check( GLcontext
*ctx
, GLuint dimensions
,
1865 GLenum target
, GLint level
,
1866 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1867 GLsizei width
, GLsizei height
)
1869 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1870 struct gl_texture_image
*teximage
;
1873 /* Check that the source buffer is complete */
1874 if (ctx
->ReadBuffer
->Name
) {
1875 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1876 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1877 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1878 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1883 if (dimensions
== 1) {
1884 if (target
!= GL_TEXTURE_1D
) {
1885 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1889 else if (dimensions
== 2) {
1890 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1891 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1892 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1893 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1897 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1898 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1899 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1903 else if (target
!= GL_TEXTURE_2D
) {
1904 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1908 else if (dimensions
== 3) {
1909 if (target
!= GL_TEXTURE_3D
) {
1910 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1916 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1917 _mesa_error(ctx
, GL_INVALID_VALUE
,
1918 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1924 _mesa_error(ctx
, GL_INVALID_VALUE
,
1925 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1928 if (dimensions
> 1 && height
< 0) {
1929 _mesa_error(ctx
, GL_INVALID_VALUE
,
1930 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1934 teximage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1936 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1937 "glCopyTexSubImage%dD(undefined texture level: %d)",
1942 if (xoffset
< -((GLint
)teximage
->Border
)) {
1943 _mesa_error(ctx
, GL_INVALID_VALUE
,
1944 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1947 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1948 _mesa_error(ctx
, GL_INVALID_VALUE
,
1949 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1952 if (dimensions
> 1) {
1953 if (yoffset
< -((GLint
)teximage
->Border
)) {
1954 _mesa_error(ctx
, GL_INVALID_VALUE
,
1955 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1958 /* NOTE: we're adding the border here, not subtracting! */
1959 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1960 _mesa_error(ctx
, GL_INVALID_VALUE
,
1961 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1966 if (dimensions
> 2) {
1967 if (zoffset
< -((GLint
)teximage
->Border
)) {
1968 _mesa_error(ctx
, GL_INVALID_VALUE
,
1969 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1972 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1973 _mesa_error(ctx
, GL_INVALID_VALUE
,
1974 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1979 if (teximage
->IsCompressed
) {
1980 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
1981 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1982 "glCopyTexSubImage%dD(missing readbuffer)", dimensions
);
1986 if (target
!= GL_TEXTURE_2D
) {
1987 _mesa_error(ctx
, GL_INVALID_ENUM
,
1988 "glCopyTexSubImage%d(target)", dimensions
);
1991 /* offset must be multiple of 4 */
1992 if ((xoffset
& 3) || (yoffset
& 3)) {
1993 _mesa_error(ctx
, GL_INVALID_VALUE
,
1994 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
1997 /* size must be multiple of 4 */
1998 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1999 _mesa_error(ctx
, GL_INVALID_VALUE
,
2000 "glCopyTexSubImage%D(width)", dimensions
);
2003 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2004 _mesa_error(ctx
, GL_INVALID_VALUE
,
2005 "glCopyTexSubImage%D(height)", dimensions
);
2010 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2011 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2015 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2016 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2017 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2018 "glCopyTexSubImage%D(no depth buffer)",
2023 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2024 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2025 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2026 "glCopyTexSubImage%D(no depth/stencil buffer)",
2032 /* if we get here, the parameters are OK */
2038 * Get texture image. Called by glGetTexImage.
2040 * \param target texture target.
2041 * \param level image level.
2042 * \param format pixel data format for returned image.
2043 * \param type pixel data type for returned image.
2044 * \param pixels returned pixel data.
2047 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2048 GLenum type
, GLvoid
*pixels
)
2050 const struct gl_texture_unit
*texUnit
;
2051 struct gl_texture_object
*texObj
;
2052 struct gl_texture_image
*texImage
;
2053 GLint maxLevels
= 0;
2054 GET_CURRENT_CONTEXT(ctx
);
2055 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2057 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2058 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2059 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2060 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2064 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2065 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2067 if (level
< 0 || level
>= maxLevels
) {
2068 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2072 if (_mesa_sizeof_packed_type(type
) <= 0) {
2073 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2077 if (_mesa_components_in_format(format
) <= 0 ||
2078 format
== GL_STENCIL_INDEX
) {
2079 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2083 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2084 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2087 if (!ctx
->Extensions
.SGIX_depth_texture
&&
2088 !ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2089 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2092 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2093 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2096 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2097 && is_depthstencil_format(format
)) {
2098 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2104 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2106 /* invalid mipmap level, not an error */
2110 /* Make sure the requested image format is compatible with the
2111 * texture's format. Note that a color index texture can be converted
2112 * to RGBA so that combo is allowed.
2114 if (is_color_format(format
)
2115 && !is_color_format(texImage
->TexFormat
->BaseFormat
)
2116 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2117 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2120 else if (is_index_format(format
)
2121 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2122 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2125 else if (is_depth_format(format
)
2126 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2127 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2128 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2131 else if (is_ycbcr_format(format
)
2132 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2133 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2136 else if (is_depthstencil_format(format
)
2137 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2138 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2142 /* typically, this will call _mesa_get_teximage() */
2143 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2150 * Check if the given texture image is bound to any framebuffer objects
2151 * and update/invalidate them.
2152 * XXX We're only checking the currently bound framebuffer object for now.
2153 * In the future, perhaps struct gl_texture_image should have a pointer (or
2154 * list of pointers (yikes)) to the gl_framebuffer(s) which it's bound to.
2157 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2158 GLuint face
, GLuint level
)
2160 if (ctx
->DrawBuffer
->Name
) {
2162 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2163 struct gl_renderbuffer_attachment
*att
=
2164 ctx
->DrawBuffer
->Attachment
+ i
;
2165 if (att
->Type
== GL_TEXTURE
&&
2166 att
->Texture
== texObj
&&
2167 att
->TextureLevel
== level
&&
2168 att
->CubeMapFace
== face
) {
2169 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2170 /* Tell driver about the new renderbuffer texture */
2171 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2180 * Called from the API. Note that width includes the border.
2183 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2184 GLsizei width
, GLint border
, GLenum format
,
2185 GLenum type
, const GLvoid
*pixels
)
2187 GLsizei postConvWidth
= width
;
2188 GET_CURRENT_CONTEXT(ctx
);
2189 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2191 if (is_color_format(internalFormat
)) {
2192 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2195 if (target
== GL_TEXTURE_1D
) {
2196 /* non-proxy target */
2197 struct gl_texture_unit
*texUnit
;
2198 struct gl_texture_object
*texObj
;
2199 struct gl_texture_image
*texImage
;
2200 const GLuint face
= texture_face(target
);
2202 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2203 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2204 return; /* error was recorded */
2207 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2208 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2209 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2212 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2215 else if (texImage
->Data
) {
2216 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2218 ASSERT(texImage
->Data
== NULL
);
2219 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2220 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2221 postConvWidth
, 1, 1,
2222 border
, internalFormat
);
2224 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2225 _mesa_update_state(ctx
);
2227 ASSERT(ctx
->Driver
.TexImage1D
);
2229 /* Give the texture to the driver! <pixels> may be null! */
2230 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2231 width
, border
, format
, type
, pixels
,
2232 &ctx
->Unpack
, texObj
, texImage
);
2234 ASSERT(texImage
->TexFormat
);
2236 update_fbo_texture(ctx
, texObj
, face
, level
);
2239 texObj
->Complete
= GL_FALSE
;
2240 ctx
->NewState
|= _NEW_TEXTURE
;
2242 else if (target
== GL_PROXY_TEXTURE_1D
) {
2243 /* Proxy texture: check for errors and update proxy state */
2244 struct gl_texture_image
*texImage
;
2245 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2246 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2247 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2248 /* when error, clear all proxy texture image parameters */
2250 clear_teximage_fields(texImage
);
2253 /* no error, set the tex image parameters */
2255 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2256 postConvWidth
, 1, 1,
2257 border
, internalFormat
);
2258 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2259 internalFormat
, format
, type
);
2263 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2270 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2271 GLsizei width
, GLsizei height
, GLint border
,
2272 GLenum format
, GLenum type
,
2273 const GLvoid
*pixels
)
2275 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2276 GET_CURRENT_CONTEXT(ctx
);
2277 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2279 if (is_color_format(internalFormat
)) {
2280 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2284 if (target
== GL_TEXTURE_2D
||
2285 (ctx
->Extensions
.ARB_texture_cube_map
&&
2286 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2287 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2288 (ctx
->Extensions
.NV_texture_rectangle
&&
2289 target
== GL_TEXTURE_RECTANGLE_NV
)) {
2290 /* non-proxy target */
2291 struct gl_texture_unit
*texUnit
;
2292 struct gl_texture_object
*texObj
;
2293 struct gl_texture_image
*texImage
;
2294 const GLuint face
= texture_face(target
);
2296 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2297 format
, type
, 2, postConvWidth
, postConvHeight
,
2299 return; /* error was recorded */
2302 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2303 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2304 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2306 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2309 else if (texImage
->Data
) {
2310 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2312 ASSERT(texImage
->Data
== NULL
);
2313 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2314 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2315 postConvWidth
, postConvHeight
, 1,
2316 border
, internalFormat
);
2318 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2319 _mesa_update_state(ctx
);
2321 ASSERT(ctx
->Driver
.TexImage2D
);
2323 /* Give the texture to the driver! <pixels> may be null! */
2324 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2325 width
, height
, border
, format
, type
, pixels
,
2326 &ctx
->Unpack
, texObj
, texImage
);
2328 ASSERT(texImage
->TexFormat
);
2330 update_fbo_texture(ctx
, texObj
, face
, level
);
2333 texObj
->Complete
= GL_FALSE
;
2334 ctx
->NewState
|= _NEW_TEXTURE
;
2336 else if (target
== GL_PROXY_TEXTURE_2D
||
2337 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2338 ctx
->Extensions
.ARB_texture_cube_map
) ||
2339 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2340 ctx
->Extensions
.NV_texture_rectangle
)) {
2341 /* Proxy texture: check for errors and update proxy state */
2342 struct gl_texture_image
*texImage
;
2343 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2344 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2345 format
, type
, 2, postConvWidth
, postConvHeight
,
2347 /* when error, clear all proxy texture image parameters */
2349 clear_teximage_fields(ctx
->Texture
.Proxy2D
->Image
[0][level
]);
2352 /* no error, set the tex image parameters */
2353 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2354 postConvWidth
, postConvHeight
, 1,
2355 border
, internalFormat
);
2356 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2357 internalFormat
, format
, type
);
2361 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2368 * Called by the API or display list executor.
2369 * Note that width and height include the border.
2372 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2373 GLsizei width
, GLsizei height
, GLsizei depth
,
2374 GLint border
, GLenum format
, GLenum type
,
2375 const GLvoid
*pixels
)
2377 GET_CURRENT_CONTEXT(ctx
);
2378 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2380 if (target
== GL_TEXTURE_3D
) {
2381 /* non-proxy target */
2382 struct gl_texture_unit
*texUnit
;
2383 struct gl_texture_object
*texObj
;
2384 struct gl_texture_image
*texImage
;
2385 const GLuint face
= texture_face(target
);
2387 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2388 format
, type
, 3, width
, height
, depth
, border
)) {
2389 return; /* error was recorded */
2392 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2393 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2394 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2396 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2399 else if (texImage
->Data
) {
2400 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2402 ASSERT(texImage
->Data
== NULL
);
2403 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2404 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2405 width
, height
, depth
,
2406 border
, internalFormat
);
2408 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2409 _mesa_update_state(ctx
);
2411 ASSERT(ctx
->Driver
.TexImage3D
);
2413 /* Give the texture to the driver! <pixels> may be null! */
2414 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2415 width
, height
, depth
, border
, format
, type
,
2416 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2418 ASSERT(texImage
->TexFormat
);
2420 update_fbo_texture(ctx
, texObj
, face
, level
);
2423 texObj
->Complete
= GL_FALSE
;
2424 ctx
->NewState
|= _NEW_TEXTURE
;
2426 else if (target
== GL_PROXY_TEXTURE_3D
) {
2427 /* Proxy texture: check for errors and update proxy state */
2428 struct gl_texture_image
*texImage
;
2429 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2430 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2431 format
, type
, 3, width
, height
, depth
, border
)) {
2432 /* when error, clear all proxy texture image parameters */
2434 clear_teximage_fields(texImage
);
2437 /* no error, set the tex image parameters */
2438 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2439 border
, internalFormat
);
2440 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2441 internalFormat
, format
, type
);
2445 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2452 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2453 GLsizei width
, GLsizei height
, GLsizei depth
,
2454 GLint border
, GLenum format
, GLenum type
,
2455 const GLvoid
*pixels
)
2457 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2458 depth
, border
, format
, type
, pixels
);
2464 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2465 GLint xoffset
, GLsizei width
,
2466 GLenum format
, GLenum type
,
2467 const GLvoid
*pixels
)
2469 GLsizei postConvWidth
= width
;
2470 struct gl_texture_unit
*texUnit
;
2471 struct gl_texture_object
*texObj
;
2472 struct gl_texture_image
*texImage
;
2473 GET_CURRENT_CONTEXT(ctx
);
2474 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2476 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2477 _mesa_update_state(ctx
);
2479 /* XXX should test internal format */
2480 if (is_color_format(format
)) {
2481 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2484 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2485 postConvWidth
, 1, 1, format
, type
)) {
2486 return; /* error was detected */
2489 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2490 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2491 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2495 return; /* no-op, not an error */
2497 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2498 xoffset
+= texImage
->Border
;
2500 ASSERT(ctx
->Driver
.TexSubImage1D
);
2501 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2502 format
, type
, pixels
, &ctx
->Unpack
,
2504 ctx
->NewState
|= _NEW_TEXTURE
;
2509 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2510 GLint xoffset
, GLint yoffset
,
2511 GLsizei width
, GLsizei height
,
2512 GLenum format
, GLenum type
,
2513 const GLvoid
*pixels
)
2515 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2516 struct gl_texture_unit
*texUnit
;
2517 struct gl_texture_object
*texObj
;
2518 struct gl_texture_image
*texImage
;
2519 GET_CURRENT_CONTEXT(ctx
);
2520 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2522 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2523 _mesa_update_state(ctx
);
2525 /* XXX should test internal format */
2526 if (is_color_format(format
)) {
2527 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2531 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2532 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2533 return; /* error was detected */
2536 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2537 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2538 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2541 if (width
== 0 || height
== 0)
2542 return; /* no-op, not an error */
2544 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2545 xoffset
+= texImage
->Border
;
2546 yoffset
+= texImage
->Border
;
2548 ASSERT(ctx
->Driver
.TexSubImage2D
);
2549 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2550 width
, height
, format
, type
, pixels
,
2551 &ctx
->Unpack
, texObj
, texImage
);
2552 ctx
->NewState
|= _NEW_TEXTURE
;
2558 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2559 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2560 GLsizei width
, GLsizei height
, GLsizei depth
,
2561 GLenum format
, GLenum type
,
2562 const GLvoid
*pixels
)
2564 struct gl_texture_unit
*texUnit
;
2565 struct gl_texture_object
*texObj
;
2566 struct gl_texture_image
*texImage
;
2567 GET_CURRENT_CONTEXT(ctx
);
2568 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2570 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2571 _mesa_update_state(ctx
);
2573 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2574 width
, height
, depth
, format
, type
)) {
2575 return; /* error was detected */
2578 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2579 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2580 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2583 if (width
== 0 || height
== 0 || height
== 0)
2584 return; /* no-op, not an error */
2586 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2587 xoffset
+= texImage
->Border
;
2588 yoffset
+= texImage
->Border
;
2589 zoffset
+= texImage
->Border
;
2591 ASSERT(ctx
->Driver
.TexSubImage3D
);
2592 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2593 xoffset
, yoffset
, zoffset
,
2594 width
, height
, depth
,
2595 format
, type
, pixels
,
2596 &ctx
->Unpack
, texObj
, texImage
);
2597 ctx
->NewState
|= _NEW_TEXTURE
;
2603 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2604 GLenum internalFormat
,
2606 GLsizei width
, GLint border
)
2608 struct gl_texture_unit
*texUnit
;
2609 struct gl_texture_object
*texObj
;
2610 struct gl_texture_image
*texImage
;
2611 GLsizei postConvWidth
= width
;
2612 const GLuint face
= texture_face(target
);
2613 GET_CURRENT_CONTEXT(ctx
);
2614 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2616 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2617 _mesa_update_state(ctx
);
2619 if (is_color_format(internalFormat
)) {
2620 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2623 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2624 postConvWidth
, 1, border
))
2627 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2628 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2629 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2631 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2634 else if (texImage
->Data
) {
2635 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2637 ASSERT(texImage
->Data
== NULL
);
2639 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2640 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2641 border
, internalFormat
);
2644 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2645 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2646 x
, y
, width
, border
);
2648 ASSERT(texImage
->TexFormat
);
2650 update_fbo_texture(ctx
, texObj
, face
, level
);
2653 texObj
->Complete
= GL_FALSE
;
2654 ctx
->NewState
|= _NEW_TEXTURE
;
2660 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2661 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2664 struct gl_texture_unit
*texUnit
;
2665 struct gl_texture_object
*texObj
;
2666 struct gl_texture_image
*texImage
;
2667 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2668 const GLuint face
= texture_face(target
);
2669 GET_CURRENT_CONTEXT(ctx
);
2670 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2672 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2673 _mesa_update_state(ctx
);
2675 if (is_color_format(internalFormat
)) {
2676 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2680 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2681 postConvWidth
, postConvHeight
, border
))
2684 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2685 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2686 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2688 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2691 else if (texImage
->Data
) {
2692 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2694 ASSERT(texImage
->Data
== NULL
);
2696 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2697 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2698 postConvWidth
, postConvHeight
, 1,
2699 border
, internalFormat
);
2701 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2702 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
2703 x
, y
, width
, height
, border
);
2705 ASSERT(texImage
->TexFormat
);
2707 update_fbo_texture(ctx
, texObj
, face
, level
);
2710 texObj
->Complete
= GL_FALSE
;
2711 ctx
->NewState
|= _NEW_TEXTURE
;
2717 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2718 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2720 struct gl_texture_unit
*texUnit
;
2721 struct gl_texture_image
*texImage
;
2722 GLsizei postConvWidth
= width
;
2723 GET_CURRENT_CONTEXT(ctx
);
2724 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2726 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2727 _mesa_update_state(ctx
);
2729 /* XXX should test internal format */
2730 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2732 if (copytexsubimage_error_check(ctx
, 1, target
, level
,
2733 xoffset
, 0, 0, postConvWidth
, 1))
2736 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2737 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2740 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2741 xoffset
+= texImage
->Border
;
2743 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2744 (*ctx
->Driver
.CopyTexSubImage1D
)(ctx
, target
, level
, xoffset
, x
, y
, width
);
2745 ctx
->NewState
|= _NEW_TEXTURE
;
2751 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2752 GLint xoffset
, GLint yoffset
,
2753 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2755 struct gl_texture_unit
*texUnit
;
2756 struct gl_texture_image
*texImage
;
2757 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2758 GET_CURRENT_CONTEXT(ctx
);
2759 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2761 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2762 _mesa_update_state(ctx
);
2764 /* XXX should test internal format */
2765 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
2767 if (copytexsubimage_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2768 postConvWidth
, postConvHeight
))
2771 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2772 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2775 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2776 xoffset
+= texImage
->Border
;
2777 yoffset
+= texImage
->Border
;
2779 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2780 (*ctx
->Driver
.CopyTexSubImage2D
)(ctx
, target
, level
,
2781 xoffset
, yoffset
, x
, y
, width
, height
);
2782 ctx
->NewState
|= _NEW_TEXTURE
;
2788 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2789 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2790 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2792 struct gl_texture_unit
*texUnit
;
2793 struct gl_texture_image
*texImage
;
2794 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2795 GET_CURRENT_CONTEXT(ctx
);
2796 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2798 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2799 _mesa_update_state(ctx
);
2801 /* XXX should test internal format */
2802 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
2804 if (copytexsubimage_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
,
2805 zoffset
, postConvWidth
, postConvHeight
))
2808 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2809 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2812 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2813 xoffset
+= texImage
->Border
;
2814 yoffset
+= texImage
->Border
;
2815 zoffset
+= texImage
->Border
;
2817 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2818 (*ctx
->Driver
.CopyTexSubImage3D
)(ctx
, target
, level
,
2819 xoffset
, yoffset
, zoffset
,
2820 x
, y
, width
, height
);
2821 ctx
->NewState
|= _NEW_TEXTURE
;
2827 /**********************************************************************/
2828 /****** Compressed Textures ******/
2829 /**********************************************************************/
2833 * Error checking for glCompressedTexImage[123]D().
2834 * \return error code or GL_NO_ERROR.
2837 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
2838 GLenum target
, GLint level
,
2839 GLenum internalFormat
, GLsizei width
,
2840 GLsizei height
, GLsizei depth
, GLint border
,
2843 GLint
/**expectedSize,**/ maxLevels
= 0, maxTextureSize
;
2845 if (dimensions
== 1) {
2846 /* 1D compressed textures not allowed */
2847 return GL_INVALID_ENUM
;
2849 else if (dimensions
== 2) {
2850 if (target
== GL_PROXY_TEXTURE_2D
) {
2851 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2853 else if (target
== GL_TEXTURE_2D
) {
2854 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2856 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
2857 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2858 return GL_INVALID_ENUM
; /*target*/
2859 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2861 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2862 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2863 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2864 return GL_INVALID_ENUM
; /*target*/
2865 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2868 return GL_INVALID_ENUM
; /*target*/
2871 else if (dimensions
== 3) {
2872 /* 3D compressed textures not allowed */
2873 return GL_INVALID_ENUM
;
2876 maxTextureSize
= 1 << (maxLevels
- 1);
2878 if (!is_compressed_format(ctx
, internalFormat
))
2879 return GL_INVALID_ENUM
;
2881 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
2882 return GL_INVALID_ENUM
;
2885 return GL_INVALID_VALUE
;
2888 * XXX We should probably use the proxy texture error check function here.
2890 if (width
< 1 || width
> maxTextureSize
||
2891 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(width
) != 1))
2892 return GL_INVALID_VALUE
;
2894 if ((height
< 1 || height
> maxTextureSize
||
2895 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(height
) != 1))
2897 return GL_INVALID_VALUE
;
2899 if ((depth
< 1 || depth
> maxTextureSize
||
2900 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(depth
) != 1))
2902 return GL_INVALID_VALUE
;
2904 /* For cube map, width must equal height */
2905 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2906 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
2907 return GL_INVALID_VALUE
;
2909 if (level
< 0 || level
>= maxLevels
)
2910 return GL_INVALID_VALUE
;
2913 /* XXX need to renable this code someday! */
2914 expectedSize
= ctx
->Driver
.CompressedTextureSize(ctx
, width
, height
, depth
,
2916 if (expectedSize
!= imageSize
)
2917 return GL_INVALID_VALUE
;
2925 * Error checking for glCompressedTexSubImage[123]D().
2926 * \warning There are some bad assumptions here about the size of compressed
2927 * texture tiles (multiple of 4) used to test the validity of the
2928 * offset and size parameters.
2929 * \return error code or GL_NO_ERROR.
2932 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
2933 GLenum target
, GLint level
,
2934 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2935 GLsizei width
, GLsizei height
, GLsizei depth
,
2936 GLenum format
, GLsizei imageSize
)
2938 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
2941 if (dimensions
== 1) {
2942 /* 1D compressed textures not allowed */
2943 return GL_INVALID_ENUM
;
2945 else if (dimensions
== 2) {
2946 if (target
== GL_PROXY_TEXTURE_2D
) {
2947 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2949 else if (target
== GL_TEXTURE_2D
) {
2950 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2952 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
2953 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2954 return GL_INVALID_ENUM
; /*target*/
2955 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2957 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2958 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2959 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2960 return GL_INVALID_ENUM
; /*target*/
2961 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2964 return GL_INVALID_ENUM
; /*target*/
2967 else if (dimensions
== 3) {
2968 /* 3D compressed textures not allowed */
2969 return GL_INVALID_ENUM
;
2972 maxTextureSize
= 1 << (maxLevels
- 1);
2974 if (!is_compressed_format(ctx
, format
))
2975 return GL_INVALID_ENUM
;
2977 if (width
< 1 || width
> maxTextureSize
)
2978 return GL_INVALID_VALUE
;
2980 if ((height
< 1 || height
> maxTextureSize
)
2982 return GL_INVALID_VALUE
;
2984 if (level
< 0 || level
>= maxLevels
)
2985 return GL_INVALID_VALUE
;
2987 /* XXX these tests are specific to the compressed format.
2988 * this code should be generalized in some way.
2990 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
2991 return GL_INVALID_VALUE
;
2993 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
2994 return GL_INVALID_VALUE
;
2996 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
2997 return GL_INVALID_VALUE
;
2999 expectedSize
= ctx
->Driver
.CompressedTextureSize(ctx
, width
, height
, depth
,
3001 if (expectedSize
!= imageSize
)
3002 return GL_INVALID_VALUE
;
3010 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3011 GLenum internalFormat
, GLsizei width
,
3012 GLint border
, GLsizei imageSize
,
3015 GET_CURRENT_CONTEXT(ctx
);
3016 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3018 if (target
== GL_TEXTURE_1D
) {
3019 /* non-proxy target */
3020 struct gl_texture_unit
*texUnit
;
3021 struct gl_texture_object
*texObj
;
3022 struct gl_texture_image
*texImage
;
3023 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3024 internalFormat
, width
, 1, 1, border
, imageSize
);
3026 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3030 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3031 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3032 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
3034 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3037 else if (texImage
->Data
) {
3038 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3040 ASSERT(texImage
->Data
== NULL
);
3042 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3043 border
, internalFormat
);
3045 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3046 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3047 internalFormat
, width
, border
,
3052 texObj
->Complete
= GL_FALSE
;
3053 ctx
->NewState
|= _NEW_TEXTURE
;
3055 else if (target
== GL_PROXY_TEXTURE_1D
) {
3056 /* Proxy texture: check for errors and update proxy state */
3057 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3058 internalFormat
, width
, 1, 1, border
, imageSize
);
3060 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3061 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3062 internalFormat
, GL_NONE
, GL_NONE
,
3063 width
, 1, 1, border
);
3066 /* if error, clear all proxy texture image parameters */
3067 struct gl_texture_image
*texImage
;
3068 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3070 clear_teximage_fields(texImage
);
3073 /* store the teximage parameters */
3074 struct gl_texture_unit
*texUnit
;
3075 struct gl_texture_image
*texImage
;
3076 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3077 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3078 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3079 border
, internalFormat
);
3083 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3090 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3091 GLenum internalFormat
, GLsizei width
,
3092 GLsizei height
, GLint border
, GLsizei imageSize
,
3095 GET_CURRENT_CONTEXT(ctx
);
3096 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3098 if (target
== GL_TEXTURE_2D
||
3099 (ctx
->Extensions
.ARB_texture_cube_map
&&
3100 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3101 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3102 /* non-proxy target */
3103 struct gl_texture_unit
*texUnit
;
3104 struct gl_texture_object
*texObj
;
3105 struct gl_texture_image
*texImage
;
3106 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3107 internalFormat
, width
, height
, 1, border
, imageSize
);
3109 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3113 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3114 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3115 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
3117 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3120 else if (texImage
->Data
) {
3121 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3123 ASSERT(texImage
->Data
== NULL
);
3125 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3126 border
, internalFormat
);
3128 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3129 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3130 internalFormat
, width
, height
,
3131 border
, imageSize
, data
,
3135 texObj
->Complete
= GL_FALSE
;
3136 ctx
->NewState
|= _NEW_TEXTURE
;
3138 else if (target
== GL_PROXY_TEXTURE_2D
||
3139 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3140 ctx
->Extensions
.ARB_texture_cube_map
)) {
3141 /* Proxy texture: check for errors and update proxy state */
3142 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3143 internalFormat
, width
, height
, 1, border
, imageSize
);
3145 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3146 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3147 internalFormat
, GL_NONE
, GL_NONE
,
3148 width
, height
, 1, border
);
3151 /* if error, clear all proxy texture image parameters */
3152 struct gl_texture_image
*texImage
;
3153 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3155 clear_teximage_fields(texImage
);
3158 /* store the teximage parameters */
3159 struct gl_texture_unit
*texUnit
;
3160 struct gl_texture_image
*texImage
;
3161 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3162 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3163 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3164 border
, internalFormat
);
3168 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3175 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3176 GLenum internalFormat
, GLsizei width
,
3177 GLsizei height
, GLsizei depth
, GLint border
,
3178 GLsizei imageSize
, const GLvoid
*data
)
3180 GET_CURRENT_CONTEXT(ctx
);
3181 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3183 if (target
== GL_TEXTURE_3D
) {
3184 /* non-proxy target */
3185 struct gl_texture_unit
*texUnit
;
3186 struct gl_texture_object
*texObj
;
3187 struct gl_texture_image
*texImage
;
3188 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3189 internalFormat
, width
, height
, depth
, border
, imageSize
);
3191 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3195 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3196 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3197 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
3199 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3202 else if (texImage
->Data
) {
3203 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3205 ASSERT(texImage
->Data
== NULL
);
3207 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3208 border
, internalFormat
);
3210 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3211 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3213 width
, height
, depth
,
3214 border
, imageSize
, data
,
3218 texObj
->Complete
= GL_FALSE
;
3219 ctx
->NewState
|= _NEW_TEXTURE
;
3221 else if (target
== GL_PROXY_TEXTURE_3D
) {
3222 /* Proxy texture: check for errors and update proxy state */
3223 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3224 internalFormat
, width
, height
, depth
, border
, imageSize
);
3226 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3227 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3228 internalFormat
, GL_NONE
, GL_NONE
,
3229 width
, height
, depth
, border
);
3232 /* if error, clear all proxy texture image parameters */
3233 struct gl_texture_image
*texImage
;
3234 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3236 clear_teximage_fields(texImage
);
3239 /* store the teximage parameters */
3240 struct gl_texture_unit
*texUnit
;
3241 struct gl_texture_image
*texImage
;
3242 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3243 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3244 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3245 depth
, border
, internalFormat
);
3249 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3256 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3257 GLsizei width
, GLenum format
,
3258 GLsizei imageSize
, const GLvoid
*data
)
3260 struct gl_texture_unit
*texUnit
;
3261 struct gl_texture_object
*texObj
;
3262 struct gl_texture_image
*texImage
;
3264 GET_CURRENT_CONTEXT(ctx
);
3265 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3267 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3268 xoffset
, 0, 0, width
, 1, 1, format
, imageSize
);
3270 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3274 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3275 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3276 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3279 if ((GLint
) format
!= texImage
->InternalFormat
) {
3280 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3281 "glCompressedTexSubImage1D(format)");
3285 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3286 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3291 return; /* no-op, not an error */
3293 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3294 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3296 format
, imageSize
, data
,
3299 ctx
->NewState
|= _NEW_TEXTURE
;
3304 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3305 GLint yoffset
, GLsizei width
, GLsizei height
,
3306 GLenum format
, GLsizei imageSize
,
3309 struct gl_texture_unit
*texUnit
;
3310 struct gl_texture_object
*texObj
;
3311 struct gl_texture_image
*texImage
;
3313 GET_CURRENT_CONTEXT(ctx
);
3314 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3316 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3317 xoffset
, yoffset
, 0, width
, height
, 1, format
, imageSize
);
3319 /* XXX proxy target? */
3320 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3324 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3325 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3326 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3329 if ((GLint
) format
!= texImage
->InternalFormat
) {
3330 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3331 "glCompressedTexSubImage2D(format)");
3335 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3336 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3337 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3341 if (width
== 0 || height
== 0)
3342 return; /* no-op, not an error */
3344 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3345 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3346 xoffset
, yoffset
, width
, height
,
3347 format
, imageSize
, data
,
3350 ctx
->NewState
|= _NEW_TEXTURE
;
3355 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3356 GLint yoffset
, GLint zoffset
, GLsizei width
,
3357 GLsizei height
, GLsizei depth
, GLenum format
,
3358 GLsizei imageSize
, const GLvoid
*data
)
3360 struct gl_texture_unit
*texUnit
;
3361 struct gl_texture_object
*texObj
;
3362 struct gl_texture_image
*texImage
;
3364 GET_CURRENT_CONTEXT(ctx
);
3365 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3367 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3368 xoffset
, yoffset
, zoffset
, width
, height
, depth
, format
, imageSize
);
3370 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3374 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3375 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3376 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3379 if ((GLint
) format
!= texImage
->InternalFormat
) {
3380 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3381 "glCompressedTexSubImage3D(format)");
3385 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3386 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3387 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3388 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3392 if (width
== 0 || height
== 0 || depth
== 0)
3393 return; /* no-op, not an error */
3395 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3396 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3397 xoffset
, yoffset
, zoffset
,
3398 width
, height
, depth
,
3399 format
, imageSize
, data
,
3402 ctx
->NewState
|= _NEW_TEXTURE
;
3407 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3409 const struct gl_texture_unit
*texUnit
;
3410 const struct gl_texture_object
*texObj
;
3411 struct gl_texture_image
*texImage
;
3413 GET_CURRENT_CONTEXT(ctx
);
3414 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3416 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3417 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3419 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3423 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3424 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3426 if (level
< 0 || level
>= maxLevels
) {
3427 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3431 if (_mesa_is_proxy_texture(target
)) {
3432 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3436 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3438 /* probably invalid mipmap level */
3439 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3443 if (!texImage
->IsCompressed
) {
3444 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetCompressedTexImageARB");
3448 /* this typically calls _mesa_get_compressed_teximage() */
3449 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
, texObj
,texImage
);