2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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 images manipulation functions.
30 * \note Mesa's native texture data type is GLchan. Native formats are
31 * GL_ALPHA, GL_LUMINANCE, GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, GL_RGBA, and
34 * \note Device drivers are free to implement any internal format they want.
39 #include "bufferobj.h"
46 #include "texcompress.h"
47 #include "texformat.h"
55 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
57 #if CHAN_TYPE == GL_FLOAT
58 _mesa_problem(NULL
, "PrintTexture doesn't support float channels");
61 const GLchan
*data
= (const GLchan
*) img
->Data
;
64 _mesa_printf("No texture data\n");
68 switch (img
->Format
) {
75 case GL_LUMINANCE_ALPHA
:
85 _mesa_problem(NULL
, "error in PrintTexture\n");
89 for (i
= 0; i
< img
->Height
; i
++) {
90 for (j
= 0; j
< img
->Width
; j
++) {
92 _mesa_printf("%02x ", data
[0]);
94 _mesa_printf("%02x%02x ", data
[0], data
[1]);
96 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
98 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
99 data
+= (img
->RowStride
- img
->Width
) * c
;
109 * Compute floor(log_base_2(n)).
110 * If n < 0 return -1.
139 * Return the simple base format for a given internal texture format.
140 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
142 * \param ctx GL context.
143 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
145 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
146 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
148 * This is the format which is used during texture application (i.e. the
149 * texture format and env mode determine the arithmetic used.
152 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
154 switch (internalFormat
) {
169 case GL_LUMINANCE_ALPHA
:
170 case GL_LUMINANCE4_ALPHA4
:
171 case GL_LUMINANCE6_ALPHA2
:
172 case GL_LUMINANCE8_ALPHA8
:
173 case GL_LUMINANCE12_ALPHA4
:
174 case GL_LUMINANCE12_ALPHA12
:
175 case GL_LUMINANCE16_ALPHA16
:
176 return GL_LUMINANCE_ALPHA
;
207 if (ctx
->Extensions
.EXT_paletted_texture
) {
208 switch (internalFormat
) {
210 case GL_COLOR_INDEX1_EXT
:
211 case GL_COLOR_INDEX2_EXT
:
212 case GL_COLOR_INDEX4_EXT
:
213 case GL_COLOR_INDEX8_EXT
:
214 case GL_COLOR_INDEX12_EXT
:
215 case GL_COLOR_INDEX16_EXT
:
216 return GL_COLOR_INDEX
;
222 if (ctx
->Extensions
.SGIX_depth_texture
) {
223 switch (internalFormat
) {
224 case GL_DEPTH_COMPONENT
:
225 case GL_DEPTH_COMPONENT16_SGIX
:
226 case GL_DEPTH_COMPONENT24_SGIX
:
227 case GL_DEPTH_COMPONENT32_SGIX
:
228 return GL_DEPTH_COMPONENT
;
234 if (ctx
->Extensions
.ARB_texture_compression
) {
235 switch (internalFormat
) {
236 case GL_COMPRESSED_ALPHA
:
238 case GL_COMPRESSED_LUMINANCE
:
240 case GL_COMPRESSED_LUMINANCE_ALPHA
:
241 return GL_LUMINANCE_ALPHA
;
242 case GL_COMPRESSED_INTENSITY
:
244 case GL_COMPRESSED_RGB
:
246 case GL_COMPRESSED_RGBA
:
253 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
254 switch (internalFormat
) {
255 case GL_COMPRESSED_RGB_FXT1_3DFX
:
257 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
264 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
265 switch (internalFormat
) {
266 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
268 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
269 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
270 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
277 if (ctx
->Extensions
.S3_s3tc
) {
278 switch (internalFormat
) {
290 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
291 if (internalFormat
== GL_YCBCR_MESA
)
292 return GL_YCBCR_MESA
;
295 if (ctx
->Extensions
.ARB_texture_float
) {
296 switch (internalFormat
) {
297 case GL_ALPHA16F_ARB
:
298 case GL_ALPHA32F_ARB
:
306 case GL_INTENSITY16F_ARB
:
307 case GL_INTENSITY32F_ARB
:
309 case GL_LUMINANCE16F_ARB
:
310 case GL_LUMINANCE32F_ARB
:
312 case GL_LUMINANCE_ALPHA16F_ARB
:
313 case GL_LUMINANCE_ALPHA32F_ARB
:
314 return GL_LUMINANCE_ALPHA
;
320 return -1; /* error */
325 * Test if the given image format is a color/RGBA format (i.e., not color
326 * index, depth, stencil, etc).
327 * \param format the image format value (may by an internal texture format)
328 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
331 is_color_format(GLenum format
)
349 case GL_LUMINANCE_ALPHA
:
350 case GL_LUMINANCE4_ALPHA4
:
351 case GL_LUMINANCE6_ALPHA2
:
352 case GL_LUMINANCE8_ALPHA8
:
353 case GL_LUMINANCE12_ALPHA4
:
354 case GL_LUMINANCE12_ALPHA12
:
355 case GL_LUMINANCE16_ALPHA16
:
382 /* float texture formats */
383 case GL_ALPHA16F_ARB
:
384 case GL_ALPHA32F_ARB
:
385 case GL_LUMINANCE16F_ARB
:
386 case GL_LUMINANCE32F_ARB
:
387 case GL_LUMINANCE_ALPHA16F_ARB
:
388 case GL_LUMINANCE_ALPHA32F_ARB
:
389 case GL_INTENSITY16F_ARB
:
390 case GL_INTENSITY32F_ARB
:
395 /* compressed formats */
396 case GL_COMPRESSED_ALPHA
:
397 case GL_COMPRESSED_LUMINANCE
:
398 case GL_COMPRESSED_LUMINANCE_ALPHA
:
399 case GL_COMPRESSED_INTENSITY
:
400 case GL_COMPRESSED_RGB
:
401 case GL_COMPRESSED_RGBA
:
406 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
407 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
408 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
409 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
410 case GL_COMPRESSED_RGB_FXT1_3DFX
:
411 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
413 case GL_YCBCR_MESA
: /* not considered to be RGB */
421 * Test if the given image format is a color index format.
424 is_index_format(GLenum format
)
428 case GL_COLOR_INDEX1_EXT
:
429 case GL_COLOR_INDEX2_EXT
:
430 case GL_COLOR_INDEX4_EXT
:
431 case GL_COLOR_INDEX8_EXT
:
432 case GL_COLOR_INDEX12_EXT
:
433 case GL_COLOR_INDEX16_EXT
:
442 * Test if the given image format is a depth component format.
445 is_depth_format(GLenum format
)
448 case GL_DEPTH_COMPONENT16_ARB
:
449 case GL_DEPTH_COMPONENT24_ARB
:
450 case GL_DEPTH_COMPONENT32_ARB
:
451 case GL_DEPTH_COMPONENT
:
460 * Test if the given image format is a YCbCr format.
463 is_ycbcr_format(GLenum format
)
475 * Test if it is a supported compressed format.
477 * \param internalFormat the internal format token provided by the user.
479 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
480 * GL_FALSE otherwise.
482 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
486 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
489 switch (internalFormat
) {
490 case GL_COMPRESSED_RGB_FXT1_3DFX
:
491 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
492 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
493 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
494 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
495 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
508 * Store a gl_texture_image pointer in a gl_texture_object structure
509 * according to the target and level parameters.
511 * \param tObj texture object.
512 * \param target texture target.
513 * \param level image level.
514 * \param texImage texture image.
516 * This was basically prompted by the introduction of cube maps.
519 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
520 GLenum target
, GLint level
,
521 struct gl_texture_image
*texImage
)
529 tObj
->Image
[0][level
] = texImage
;
531 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
532 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
533 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
534 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
535 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
536 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
: {
537 GLuint face
= ((GLuint
) target
-
538 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
539 tObj
->Image
[face
][level
] = texImage
;
542 case GL_TEXTURE_RECTANGLE_NV
:
544 tObj
->Image
[0][level
] = texImage
;
547 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
550 /* Set the 'back' pointer */
551 texImage
->TexObject
= tObj
;
556 * Allocate a texture image structure.
558 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
561 * \return a pointer to gl_texture_image struct with all fields initialized to
564 struct gl_texture_image
*
565 _mesa_new_texture_image( GLcontext
*ctx
)
568 return CALLOC_STRUCT(gl_texture_image
);
573 * Free texture image.
575 * \param teximage texture image.
577 * Free the texture image structure and the associated image data if it's not
578 * marked as client data.
581 _mesa_delete_texture_image( struct gl_texture_image
*teximage
)
583 if (teximage
->Data
&& !teximage
->IsClientData
) {
584 MESA_PBUFFER_FREE( teximage
->Data
);
585 teximage
->Data
= NULL
;
592 * Test if a target is a proxy target.
594 * \param target texture target.
596 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
599 is_proxy_target(GLenum target
)
601 return (target
== GL_PROXY_TEXTURE_1D
||
602 target
== GL_PROXY_TEXTURE_2D
||
603 target
== GL_PROXY_TEXTURE_3D
||
604 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
605 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
);
610 * Get the texture object that corresponds to the target of the given texture unit.
612 * \param ctx GL context.
613 * \param texUnit texture unit.
614 * \param target texture target.
616 * \return pointer to the texture object on success, or NULL on failure.
618 * \sa gl_texture_unit.
620 struct gl_texture_object
*
621 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
626 return texUnit
->Current1D
;
627 case GL_PROXY_TEXTURE_1D
:
628 return ctx
->Texture
.Proxy1D
;
630 return texUnit
->Current2D
;
631 case GL_PROXY_TEXTURE_2D
:
632 return ctx
->Texture
.Proxy2D
;
634 return texUnit
->Current3D
;
635 case GL_PROXY_TEXTURE_3D
:
636 return ctx
->Texture
.Proxy3D
;
637 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
638 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
639 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
640 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
641 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
642 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
643 case GL_TEXTURE_CUBE_MAP_ARB
:
644 return ctx
->Extensions
.ARB_texture_cube_map
645 ? texUnit
->CurrentCubeMap
: NULL
;
646 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
647 return ctx
->Extensions
.ARB_texture_cube_map
648 ? ctx
->Texture
.ProxyCubeMap
: NULL
;
649 case GL_TEXTURE_RECTANGLE_NV
:
650 return ctx
->Extensions
.NV_texture_rectangle
651 ? texUnit
->CurrentRect
: NULL
;
652 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
653 return ctx
->Extensions
.NV_texture_rectangle
654 ? ctx
->Texture
.ProxyRect
: NULL
;
656 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
663 * Get the texture image struct which corresponds to target and level
664 * of the given texture unit.
666 * \param ctx GL context.
667 * \param texUnit texture unit.
668 * \param target texture target.
669 * \param level image level.
671 * \return pointer to the texture image structure on success, or NULL on failure.
673 * \sa gl_texture_unit.
675 struct gl_texture_image
*
676 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
677 GLenum target
, GLint level
)
680 ASSERT(level
< MAX_TEXTURE_LEVELS
);
683 return texUnit
->Current1D
->Image
[0][level
];
684 case GL_PROXY_TEXTURE_1D
:
685 return ctx
->Texture
.Proxy1D
->Image
[0][level
];
687 return texUnit
->Current2D
->Image
[0][level
];
688 case GL_PROXY_TEXTURE_2D
:
689 return ctx
->Texture
.Proxy2D
->Image
[0][level
];
691 return texUnit
->Current3D
->Image
[0][level
];
692 case GL_PROXY_TEXTURE_3D
:
693 return ctx
->Texture
.Proxy3D
->Image
[0][level
];
694 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
695 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
696 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
697 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
698 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
699 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
700 if (ctx
->Extensions
.ARB_texture_cube_map
) {
701 GLuint face
= ((GLuint
) target
-
702 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
703 return texUnit
->CurrentCubeMap
->Image
[face
][level
];
707 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
708 if (ctx
->Extensions
.ARB_texture_cube_map
)
709 return ctx
->Texture
.ProxyCubeMap
->Image
[0][level
];
712 case GL_TEXTURE_RECTANGLE_NV
:
713 if (ctx
->Extensions
.NV_texture_rectangle
) {
715 return texUnit
->CurrentRect
->Image
[0][level
];
720 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
721 if (ctx
->Extensions
.NV_texture_rectangle
) {
723 return ctx
->Texture
.ProxyRect
->Image
[0][level
];
729 _mesa_problem(ctx
, "bad target in _mesa_select_tex_image()");
736 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
737 * it and install it. Only return NULL if passed a bad parameter or run
740 struct gl_texture_image
*
741 _mesa_get_tex_image(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
742 GLenum target
, GLint level
)
744 struct gl_texture_image
*texImage
;
745 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
747 struct gl_texture_object
*texObj
;
748 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
750 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
753 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
755 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
762 * Return pointer to the specified proxy texture image.
763 * Note that proxy textures are per-context, not per-texture unit.
764 * \return pointer to texture image or NULL if invalid target, invalid
765 * level, or out of memory.
767 struct gl_texture_image
*
768 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
770 struct gl_texture_image
*texImage
;
776 case GL_PROXY_TEXTURE_1D
:
777 if (level
>= ctx
->Const
.MaxTextureLevels
)
779 texImage
= ctx
->Texture
.Proxy1D
->Image
[0][level
];
781 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
783 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
786 ctx
->Texture
.Proxy1D
->Image
[0][level
] = texImage
;
787 /* Set the 'back' pointer */
788 texImage
->TexObject
= ctx
->Texture
.Proxy1D
;
791 case GL_PROXY_TEXTURE_2D
:
792 if (level
>= ctx
->Const
.MaxTextureLevels
)
794 texImage
= ctx
->Texture
.Proxy2D
->Image
[0][level
];
796 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
798 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
801 ctx
->Texture
.Proxy2D
->Image
[0][level
] = texImage
;
802 /* Set the 'back' pointer */
803 texImage
->TexObject
= ctx
->Texture
.Proxy2D
;
806 case GL_PROXY_TEXTURE_3D
:
807 if (level
>= ctx
->Const
.Max3DTextureLevels
)
809 texImage
= ctx
->Texture
.Proxy3D
->Image
[0][level
];
811 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
813 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
816 ctx
->Texture
.Proxy3D
->Image
[0][level
] = texImage
;
817 /* Set the 'back' pointer */
818 texImage
->TexObject
= ctx
->Texture
.Proxy3D
;
821 case GL_PROXY_TEXTURE_CUBE_MAP
:
822 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
824 texImage
= ctx
->Texture
.ProxyCubeMap
->Image
[0][level
];
826 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
828 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
831 ctx
->Texture
.ProxyCubeMap
->Image
[0][level
] = texImage
;
832 /* Set the 'back' pointer */
833 texImage
->TexObject
= ctx
->Texture
.ProxyCubeMap
;
836 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
839 texImage
= ctx
->Texture
.ProxyRect
->Image
[0][level
];
841 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
843 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
846 ctx
->Texture
.ProxyRect
->Image
[0][level
] = texImage
;
847 /* Set the 'back' pointer */
848 texImage
->TexObject
= ctx
->Texture
.ProxyRect
;
858 * Get the maximum number of allowed mipmap levels.
860 * \param ctx GL context.
861 * \param target texture target.
863 * \return the maximum number of allowed mipmap levels for the given
864 * texture target, or zero if passed a bad target.
869 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
873 case GL_PROXY_TEXTURE_1D
:
875 case GL_PROXY_TEXTURE_2D
:
876 return ctx
->Const
.MaxTextureLevels
;
878 case GL_PROXY_TEXTURE_3D
:
879 return ctx
->Const
.Max3DTextureLevels
;
880 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
881 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
882 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
883 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
884 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
885 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
886 case GL_TEXTURE_CUBE_MAP_ARB
:
887 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
888 return ctx
->Const
.MaxCubeTextureLevels
;
889 case GL_TEXTURE_RECTANGLE_NV
:
890 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
893 return 0; /* bad target */
899 #if 000 /* not used anymore */
901 * glTexImage[123]D can accept a NULL image pointer. In this case we
902 * create a texture image with unspecified image contents per the OpenGL
906 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
908 const GLint components
= _mesa_components_in_format(format
);
909 const GLint numPixels
= width
* height
* depth
;
910 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
914 * Let's see if anyone finds this. If glTexImage2D() is called with
915 * a NULL image pointer then load the texture image with something
916 * interesting instead of leaving it indeterminate.
919 static const char message
[8][32] = {
923 " X X XXXX XXX XXXXX ",
926 " X X XXXXX XXX X X ",
930 GLubyte
*imgPtr
= data
;
932 for (h
= 0; h
< depth
; h
++) {
933 for (i
= 0; i
< height
; i
++) {
934 GLint srcRow
= 7 - (i
% 8);
935 for (j
= 0; j
< width
; j
++) {
936 GLint srcCol
= j
% 32;
937 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
938 for (k
= 0; k
< components
; k
++) {
954 * Reset the fields of a gl_texture_image struct to zero.
956 * \param img texture image structure.
958 * This is called when a proxy texture test fails, we set all the
959 * image members (except DriverData) to zero.
960 * It's also used in glTexImage[123]D as a safeguard to be sure all
961 * required fields get initialized properly by the Driver.TexImage[123]D
965 clear_teximage_fields(struct gl_texture_image
*img
)
982 img
->TexFormat
= &_mesa_null_texformat
;
983 img
->FetchTexelc
= NULL
;
984 img
->FetchTexelf
= NULL
;
985 img
->IsCompressed
= 0;
986 img
->CompressedSize
= 0;
991 * Initialize basic fields of the gl_texture_image struct.
993 * \param ctx GL context.
994 * \param target texture target.
995 * \param img texture image structure to be initialized.
996 * \param width image width.
997 * \param height image height.
998 * \param depth image depth.
999 * \param border image border.
1000 * \param internalFormat internal format.
1002 * Fills in the fields of \p img with the given information.
1003 * Note: width, height and depth include the border.
1006 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1007 struct gl_texture_image
*img
,
1008 GLsizei width
, GLsizei height
, GLsizei depth
,
1009 GLint border
, GLenum internalFormat
)
1012 img
->Format
= _mesa_base_tex_format( ctx
, internalFormat
);
1013 ASSERT(img
->Format
> 0);
1014 img
->IntFormat
= internalFormat
;
1015 img
->Border
= border
;
1017 img
->Height
= height
;
1019 img
->RowStride
= width
;
1020 img
->WidthLog2
= logbase2(width
- 2 * border
);
1021 if (height
== 1) /* 1-D texture */
1022 img
->HeightLog2
= 0;
1024 img
->HeightLog2
= logbase2(height
- 2 * border
);
1025 if (depth
== 1) /* 2-D texture */
1028 img
->DepthLog2
= logbase2(depth
- 2 * border
);
1029 img
->Width2
= width
- 2 * border
; /*1 << img->WidthLog2;*/
1030 img
->Height2
= height
- 2 * border
; /*1 << img->HeightLog2;*/
1031 img
->Depth2
= depth
- 2 * border
; /*1 << img->DepthLog2;*/
1032 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1033 img
->IsCompressed
= is_compressed_format(ctx
, internalFormat
);
1034 if (img
->IsCompressed
)
1035 img
->CompressedSize
= ctx
->Driver
.CompressedTextureSize(ctx
, width
,
1036 height
, depth
, internalFormat
);
1038 img
->CompressedSize
= 0;
1040 if ((width
== 1 || _mesa_bitcount(width
- 2 * border
) == 1) &&
1041 (height
== 1 || _mesa_bitcount(height
- 2 * border
) == 1) &&
1042 (depth
== 1 || _mesa_bitcount(depth
- 2 * border
) == 1))
1043 img
->_IsPowerOfTwo
= GL_TRUE
;
1045 img
->_IsPowerOfTwo
= GL_FALSE
;
1047 /* Compute Width/Height/DepthScale for mipmap lod computation */
1048 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1049 /* scale = 1.0 since texture coords directly map to texels */
1050 img
->WidthScale
= 1.0;
1051 img
->HeightScale
= 1.0;
1052 img
->DepthScale
= 1.0;
1055 img
->WidthScale
= (GLfloat
) img
->Width
;
1056 img
->HeightScale
= (GLfloat
) img
->Height
;
1057 img
->DepthScale
= (GLfloat
) img
->Depth
;
1063 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1064 * level, width, height and depth against the ctx->Const limits for textures.
1066 * A hardware driver might override this function if, for example, the
1067 * max 3D texture size is 512x512x64 (i.e. not a cube).
1069 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1070 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1071 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1072 * \param level as passed to glTexImage
1073 * \param internalFormat as passed to glTexImage
1074 * \param format as passed to glTexImage
1075 * \param type as passed to glTexImage
1076 * \param width as passed to glTexImage
1077 * \param height as passed to glTexImage
1078 * \param depth as passed to glTexImage
1079 * \param border as passed to glTexImage
1080 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1083 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1084 GLint internalFormat
, GLenum format
, GLenum type
,
1085 GLint width
, GLint height
, GLint depth
, GLint border
)
1089 (void) internalFormat
;
1094 case GL_PROXY_TEXTURE_1D
:
1095 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1096 if (width
< 2 * border
|| width
> 2 + maxSize
||
1097 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1098 _mesa_bitcount(width
- 2 * border
) != 1) ||
1099 level
>= ctx
->Const
.MaxTextureLevels
) {
1100 /* bad width or level */
1104 case GL_PROXY_TEXTURE_2D
:
1105 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1106 if (width
< 2 * border
|| width
> 2 + maxSize
||
1107 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1108 _mesa_bitcount(width
- 2 * border
) != 1) ||
1109 height
< 2 * border
|| height
> 2 + maxSize
||
1110 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1111 _mesa_bitcount(height
- 2 * border
) != 1) ||
1112 level
>= ctx
->Const
.MaxTextureLevels
) {
1113 /* bad width or height or level */
1117 case GL_PROXY_TEXTURE_3D
:
1118 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1119 if (width
< 2 * border
|| width
> 2 + maxSize
||
1120 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1121 _mesa_bitcount(width
- 2 * border
) != 1) ||
1122 height
< 2 * border
|| height
> 2 + maxSize
||
1123 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1124 _mesa_bitcount(height
- 2 * border
) != 1) ||
1125 depth
< 2 * border
|| depth
> 2 + maxSize
||
1126 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1127 _mesa_bitcount(depth
- 2 * border
) != 1) ||
1128 level
>= ctx
->Const
.Max3DTextureLevels
) {
1129 /* bad width or height or depth or level */
1133 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1134 if (width
< 1 || width
> ctx
->Const
.MaxTextureRectSize
||
1135 height
< 1 || height
> ctx
->Const
.MaxTextureRectSize
||
1137 /* bad width or height or level */
1141 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1142 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1143 if (width
< 2 * border
|| width
> 2 + maxSize
||
1144 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1145 _mesa_bitcount(width
- 2 * border
) != 1) ||
1146 height
< 2 * border
|| height
> 2 + maxSize
||
1147 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1148 _mesa_bitcount(height
- 2 * border
) != 1) ||
1149 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1150 /* bad width or height */
1155 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1162 * Test the glTexImage[123]D() parameters for errors.
1164 * \param ctx GL context.
1165 * \param target texture target given by the user.
1166 * \param level image level given by the user.
1167 * \param internalFormat internal format given by the user.
1168 * \param format pixel data format given by the user.
1169 * \param type pixel data type given by the user.
1170 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1171 * \param width image width given by the user.
1172 * \param height image height given by the user.
1173 * \param depth image depth given by the user.
1174 * \param border image border given by the user.
1176 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1178 * Verifies each of the parameters against the constants specified in
1179 * __GLcontextRec::Const and the supported extensions, and according to the
1180 * OpenGL specification.
1183 texture_error_check( GLcontext
*ctx
, GLenum target
,
1184 GLint level
, GLint internalFormat
,
1185 GLenum format
, GLenum type
,
1187 GLint width
, GLint height
,
1188 GLint depth
, GLint border
)
1190 const GLboolean isProxy
= is_proxy_target(target
);
1193 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1194 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1196 _mesa_error(ctx
, GL_INVALID_VALUE
,
1197 "glTexImage%dD(level=%d)", dimensions
, level
);
1203 if (border
< 0 || border
> 1 ||
1204 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1205 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1207 _mesa_error(ctx
, GL_INVALID_VALUE
,
1208 "glTexImage%dD(border=%d)", dimensions
, border
);
1213 if (width
< 0 || height
< 0 || depth
< 0) {
1215 _mesa_error(ctx
, GL_INVALID_VALUE
,
1216 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1221 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1222 * level, width, height and depth.
1224 if (dimensions
== 1) {
1225 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1226 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1227 level
, internalFormat
,
1229 width
, 1, 1, border
);
1232 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1236 else if (dimensions
== 2) {
1237 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1238 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1239 level
, internalFormat
,
1241 width
, height
, 1, border
);
1243 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1244 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1245 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1246 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1247 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1250 sizeOK
= (width
== height
) &&
1251 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1252 level
, internalFormat
, format
, type
,
1253 width
, height
, 1, border
);
1255 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1256 target
== GL_TEXTURE_RECTANGLE_NV
) {
1257 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1258 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1261 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1262 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1263 level
, internalFormat
,
1265 width
, height
, 1, border
);
1268 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1272 else if (dimensions
== 3) {
1273 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1274 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_3D
,
1275 level
, internalFormat
,
1277 width
, height
, depth
, border
);
1280 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1285 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1291 _mesa_error(ctx
, GL_INVALID_VALUE
,
1292 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1293 dimensions
, level
, width
, height
, depth
);
1298 /* Check internalFormat */
1299 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1301 _mesa_error(ctx
, GL_INVALID_VALUE
,
1302 "glTexImage%dD(internalFormat=0x%x)",
1303 dimensions
, internalFormat
);
1308 /* Check incoming image format and type */
1309 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1310 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1311 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1314 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1315 "glTexImage%dD(format or type)", dimensions
);
1320 /* make sure internal format and format basically agree */
1321 if ((is_color_format(internalFormat
) != is_color_format(format
)) ||
1322 (is_index_format(internalFormat
) != is_index_format(format
)) ||
1323 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1324 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
))) {
1326 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1327 "glTexImage(internalFormat/format)");
1331 /* additional checks for ycbcr textures */
1332 if (internalFormat
== GL_YCBCR_MESA
) {
1333 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1334 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1335 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1337 _mesa_sprintf(message
,
1338 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1339 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1340 return GL_TRUE
; /* error */
1342 if (target
!= GL_TEXTURE_2D
&&
1343 target
!= GL_PROXY_TEXTURE_2D
&&
1344 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1345 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1347 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1353 _mesa_sprintf(message
,
1354 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1355 dimensions
, border
);
1356 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1362 /* additional checks for depth textures */
1363 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1364 /* Only 1D and 2D textures supported */
1365 if (target
!= GL_TEXTURE_1D
&&
1366 target
!= GL_PROXY_TEXTURE_1D
&&
1367 target
!= GL_TEXTURE_2D
&&
1368 target
!= GL_PROXY_TEXTURE_2D
) {
1370 _mesa_error(ctx
, GL_INVALID_ENUM
,
1371 "glTexImage(target/internalFormat)");
1376 /* additional checks for compressed textures */
1377 if (is_compressed_format(ctx
, internalFormat
)) {
1378 if (target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
) {
1381 else if (ctx
->Extensions
.ARB_texture_cube_map
&&
1382 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1383 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1384 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))) {
1389 _mesa_error(ctx
, GL_INVALID_ENUM
,
1390 "glTexImage%d(target)", dimensions
);
1396 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1397 "glTexImage%D(border!=0)", dimensions
);
1403 /* if we get here, the parameters are OK */
1409 * Test glTexSubImage[123]D() parameters for errors.
1411 * \param ctx GL context.
1412 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1413 * \param target texture target given by the user.
1414 * \param level image level given by the user.
1415 * \param xoffset sub-image x offset given by the user.
1416 * \param yoffset sub-image y offset given by the user.
1417 * \param zoffset sub-image z offset given by the user.
1418 * \param format pixel data format given by the user.
1419 * \param type pixel data type given by the user.
1420 * \param width image width given by the user.
1421 * \param height image height given by the user.
1422 * \param depth image depth given by the user.
1424 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1426 * Verifies each of the parameters against the constants specified in
1427 * __GLcontextRec::Const and the supported extensions, and according to the
1428 * OpenGL specification.
1431 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1432 GLenum target
, GLint level
,
1433 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1434 GLint width
, GLint height
, GLint depth
,
1435 GLenum format
, GLenum type
)
1437 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1438 struct gl_texture_image
*destTex
;
1441 if (dimensions
== 1) {
1442 if (target
!= GL_TEXTURE_1D
) {
1443 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1447 else if (dimensions
== 2) {
1448 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1449 target
<=GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1450 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1451 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1455 else if (ctx
->Extensions
.NV_texture_rectangle
&&
1456 target
== GL_TEXTURE_RECTANGLE_NV
) {
1457 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1458 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1462 else if (target
!= GL_TEXTURE_2D
) {
1463 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1467 else if (dimensions
== 3) {
1468 if (target
!= GL_TEXTURE_3D
) {
1469 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1474 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1478 /* Basic level check */
1479 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1480 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1485 _mesa_error(ctx
, GL_INVALID_VALUE
,
1486 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1489 if (height
< 0 && dimensions
> 1) {
1490 _mesa_error(ctx
, GL_INVALID_VALUE
,
1491 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1494 if (depth
< 0 && dimensions
> 2) {
1495 _mesa_error(ctx
, GL_INVALID_VALUE
,
1496 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1500 destTex
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1503 /* undefined image level */
1504 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1508 if (xoffset
< -((GLint
)destTex
->Border
)) {
1509 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1513 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1514 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1518 if (dimensions
> 1) {
1519 if (yoffset
< -((GLint
)destTex
->Border
)) {
1520 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1524 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1525 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1530 if (dimensions
> 2) {
1531 if (zoffset
< -((GLint
)destTex
->Border
)) {
1532 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1535 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1536 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1541 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1542 _mesa_error(ctx
, GL_INVALID_ENUM
,
1543 "glTexSubImage%dD(format or type)", dimensions
);
1547 if (destTex
->IsCompressed
) {
1548 const struct gl_texture_unit
*texUnit
;
1549 const struct gl_texture_image
*texImage
;
1550 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1551 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1553 if (target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
) {
1556 else if (ctx
->Extensions
.ARB_texture_cube_map
&&
1557 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1558 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1559 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))) {
1563 _mesa_error(ctx
, GL_INVALID_ENUM
,
1564 "glTexSubImage%D(target)", dimensions
);
1567 /* offset must be multiple of 4 */
1568 if ((xoffset
& 3) || (yoffset
& 3)) {
1569 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1570 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1573 /* size must be multiple of 4 or equal to whole texture size */
1574 if ((width
& 3) && (GLuint
) width
!= texImage
->Width
) {
1575 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1576 "glTexSubImage%D(width)", dimensions
);
1579 if ((height
& 3) && (GLuint
) height
!= texImage
->Height
) {
1580 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1581 "glTexSubImage%D(width)", dimensions
);
1591 * Test glCopyTexImage[12]D() parameters for errors.
1593 * \param ctx GL context.
1594 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1595 * \param target texture target given by the user.
1596 * \param level image level given by the user.
1597 * \param internalFormat internal format given by the user.
1598 * \param width image width given by the user.
1599 * \param height image height given by the user.
1600 * \param depth image depth given by the user.
1601 * \param border texture border.
1603 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1605 * Verifies each of the parameters against the constants specified in
1606 * __GLcontextRec::Const and the supported extensions, and according to the
1607 * OpenGL specification.
1610 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1611 GLenum target
, GLint level
, GLint internalFormat
,
1612 GLint width
, GLint height
, GLint border
)
1614 GLenum format
, type
;
1617 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1618 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1619 _mesa_error(ctx
, GL_INVALID_VALUE
,
1620 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1625 if (border
< 0 || border
> 1 ||
1626 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1627 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1631 /* The format and type aren't really significant here, but we need to pass
1632 * something to TestProxyTexImage().
1634 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1637 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1638 * level, width, height and depth.
1640 if (dimensions
== 1) {
1641 if (target
== GL_TEXTURE_1D
) {
1642 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1643 level
, internalFormat
,
1645 width
, 1, 1, border
);
1648 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1652 else if (dimensions
== 2) {
1653 if (target
== GL_TEXTURE_2D
) {
1654 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1655 level
, internalFormat
,
1657 width
, height
, 1, border
);
1659 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1660 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1661 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1662 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1665 sizeOK
= (width
== height
) &&
1666 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1667 level
, internalFormat
, format
, type
,
1668 width
, height
, 1, border
);
1670 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1671 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1672 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1675 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1676 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1677 level
, internalFormat
,
1679 width
, height
, 1, border
);
1682 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1687 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1692 if (dimensions
== 1) {
1693 _mesa_error(ctx
, GL_INVALID_VALUE
,
1694 "glCopyTexImage1D(width=%d)", width
);
1697 ASSERT(dimensions
== 2);
1698 _mesa_error(ctx
, GL_INVALID_VALUE
,
1699 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1704 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1705 _mesa_error(ctx
, GL_INVALID_VALUE
,
1706 "glCopyTexImage%dD(internalFormat)", dimensions
);
1710 if (is_compressed_format(ctx
, internalFormat
)) {
1711 if (target
!= GL_TEXTURE_2D
) {
1712 _mesa_error(ctx
, GL_INVALID_ENUM
,
1713 "glCopyTexImage%d(target)", dimensions
);
1717 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1718 "glCopyTexImage%D(border!=0)", dimensions
);
1723 /* if we get here, the parameters are OK */
1729 * Test glCopyTexImage[12]D() parameters for errors.
1731 * \param ctx GL context.
1732 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1733 * \param target texture target given by the user.
1734 * \param level image level given by the user.
1735 * \param xoffset sub-image x offset given by the user.
1736 * \param yoffset sub-image y offset given by the user.
1737 * \param zoffset sub-image z offset given by the user.
1738 * \param width image width given by the user.
1739 * \param height image height given by the user.
1741 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1743 * Verifies each of the parameters against the constants specified in
1744 * __GLcontextRec::Const and the supported extensions, and according to the
1745 * OpenGL specification.
1748 copytexsubimage_error_check( GLcontext
*ctx
, GLuint dimensions
,
1749 GLenum target
, GLint level
,
1750 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1751 GLsizei width
, GLsizei height
)
1753 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1754 struct gl_texture_image
*teximage
;
1757 if (dimensions
== 1) {
1758 if (target
!= GL_TEXTURE_1D
) {
1759 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1763 else if (dimensions
== 2) {
1764 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1765 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1766 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1767 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1771 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1772 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1773 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1777 else if (target
!= GL_TEXTURE_2D
) {
1778 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1782 else if (dimensions
== 3) {
1783 if (target
!= GL_TEXTURE_3D
) {
1784 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1790 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1791 _mesa_error(ctx
, GL_INVALID_VALUE
,
1792 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1798 _mesa_error(ctx
, GL_INVALID_VALUE
,
1799 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1802 if (dimensions
> 1 && height
< 0) {
1803 _mesa_error(ctx
, GL_INVALID_VALUE
,
1804 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1808 teximage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1810 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1811 "glCopyTexSubImage%dD(undefined texture level: %d)",
1816 if (xoffset
< -((GLint
)teximage
->Border
)) {
1817 _mesa_error(ctx
, GL_INVALID_VALUE
,
1818 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1821 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1822 _mesa_error(ctx
, GL_INVALID_VALUE
,
1823 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1826 if (dimensions
> 1) {
1827 if (yoffset
< -((GLint
)teximage
->Border
)) {
1828 _mesa_error(ctx
, GL_INVALID_VALUE
,
1829 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1832 /* NOTE: we're adding the border here, not subtracting! */
1833 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1834 _mesa_error(ctx
, GL_INVALID_VALUE
,
1835 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1840 if (dimensions
> 2) {
1841 if (zoffset
< -((GLint
)teximage
->Border
)) {
1842 _mesa_error(ctx
, GL_INVALID_VALUE
,
1843 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1846 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1847 _mesa_error(ctx
, GL_INVALID_VALUE
,
1848 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1853 if (teximage
->IsCompressed
) {
1854 if (target
!= GL_TEXTURE_2D
) {
1855 _mesa_error(ctx
, GL_INVALID_ENUM
,
1856 "glCopyTexSubImage%d(target)", dimensions
);
1859 /* offset must be multiple of 4 */
1860 if ((xoffset
& 3) || (yoffset
& 3)) {
1861 _mesa_error(ctx
, GL_INVALID_VALUE
,
1862 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
1865 /* size must be multiple of 4 */
1866 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1867 _mesa_error(ctx
, GL_INVALID_VALUE
,
1868 "glCopyTexSubImage%D(width)", dimensions
);
1871 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1872 _mesa_error(ctx
, GL_INVALID_VALUE
,
1873 "glCopyTexSubImage%D(height)", dimensions
);
1878 if (teximage
->IntFormat
== GL_YCBCR_MESA
) {
1879 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1883 /* if we get here, the parameters are OK */
1889 * Get texture image. Called by glGetTexImage.
1891 * \param target texture target.
1892 * \param level image level.
1893 * \param format pixel data format for returned image.
1894 * \param type pixel data type for returned image.
1895 * \param pixels returned pixel data.
1898 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
1899 GLenum type
, GLvoid
*pixels
)
1901 const struct gl_texture_unit
*texUnit
;
1902 const struct gl_texture_object
*texObj
;
1903 const struct gl_texture_image
*texImage
;
1904 GLint maxLevels
= 0;
1906 GET_CURRENT_CONTEXT(ctx
);
1907 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1909 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
1910 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1911 if (!texObj
|| is_proxy_target(target
)) {
1912 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
1916 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1917 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
1919 if (level
< 0 || level
>= maxLevels
) {
1920 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
1924 if (_mesa_sizeof_packed_type(type
) <= 0) {
1925 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
1929 if (_mesa_components_in_format(format
) <= 0 ||
1930 format
== GL_STENCIL_INDEX
) {
1931 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
1935 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
1936 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
1939 if (!ctx
->Extensions
.SGIX_depth_texture
&& is_depth_format(format
)) {
1940 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
1943 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
1944 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
1950 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1952 /* invalid mipmap level, not an error */
1956 /* Make sure the requested image format is compatible with the
1959 if (is_color_format(format
)
1960 && !is_color_format(texImage
->TexFormat
->BaseFormat
)) {
1961 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
1964 else if (is_index_format(format
)
1965 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
1966 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
1969 else if (is_depth_format(format
)
1970 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)) {
1971 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
1974 else if (is_ycbcr_format(format
)
1975 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
1976 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
1980 dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
1982 /* XXX - someday the rest of this function should be moved into a
1983 * fallback routine called via ctx->Driver.GetTexImage()
1986 if (ctx
->Pack
.BufferObj
->Name
) {
1987 /* pack texture image into a PBO */
1989 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
1990 texImage
->Height
, texImage
->Depth
,
1991 format
, type
, pixels
)) {
1992 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1993 "glGetTexImage(invalid PBO access)");
1996 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
1998 ctx
->Pack
.BufferObj
);
2000 /* buffer is already mapped - that's an error */
2001 _mesa_error(ctx
, GL_INVALID_OPERATION
,"glGetTexImage(PBO is mapped)");
2004 pixels
= ADD_POINTERS(buf
, pixels
);
2012 * XXX Move this code into a new driver fall-back function
2015 const GLint width
= texImage
->Width
;
2016 const GLint height
= texImage
->Height
;
2017 const GLint depth
= texImage
->Depth
;
2019 for (img
= 0; img
< depth
; img
++) {
2020 for (row
= 0; row
< height
; row
++) {
2021 /* compute destination address in client memory */
2022 GLvoid
*dest
= _mesa_image_address( dimensions
, &ctx
->Pack
, pixels
,
2023 width
, height
, format
, type
,
2027 if (format
== GL_COLOR_INDEX
) {
2028 GLuint indexRow
[MAX_WIDTH
];
2030 /* Can't use FetchTexel here because that returns RGBA */
2031 if (texImage
->TexFormat
->IndexBits
== 8) {
2032 const GLubyte
*src
= (const GLubyte
*) texImage
->Data
;
2033 for (col
= 0; col
< width
; col
++) {
2034 indexRow
[col
] = src
[texImage
->Width
*
2035 (img
* texImage
->Height
+ row
) + col
];
2038 else if (texImage
->TexFormat
->IndexBits
== 16) {
2039 const GLushort
*src
= (const GLushort
*) texImage
->Data
;
2040 for (col
= 0; col
< width
; col
++) {
2041 indexRow
[col
] = src
[texImage
->Width
*
2042 (img
* texImage
->Height
+ row
) + col
];
2047 "Color index problem in _mesa_GetTexImage");
2049 _mesa_pack_index_span(ctx
, width
, type
, dest
,
2050 indexRow
, &ctx
->Pack
,
2051 0 /* no image transfer */);
2053 else if (format
== GL_DEPTH_COMPONENT
) {
2054 GLfloat depthRow
[MAX_WIDTH
];
2056 for (col
= 0; col
< width
; col
++) {
2057 (*texImage
->FetchTexelf
)(texImage
, col
, row
, img
,
2060 _mesa_pack_depth_span(ctx
, width
, dest
, type
,
2061 depthRow
, &ctx
->Pack
);
2063 else if (format
== GL_YCBCR_MESA
) {
2064 /* No pixel transfer */
2065 const GLint rowstride
= texImage
->RowStride
;
2067 (const GLushort
*) texImage
->Data
+ row
* rowstride
,
2068 width
* sizeof(GLushort
));
2069 /* check for byte swapping */
2070 if ((texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_YCBCR
2071 && type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ||
2072 (texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_YCBCR_REV
2073 && type
== GL_UNSIGNED_SHORT_8_8_MESA
)) {
2074 if (!ctx
->Pack
.SwapBytes
)
2075 _mesa_swap2((GLushort
*) dest
, width
);
2077 else if (ctx
->Pack
.SwapBytes
) {
2078 _mesa_swap2((GLushort
*) dest
, width
);
2082 /* general case: convert row to RGBA format */
2083 GLfloat rgba
[MAX_WIDTH
][4];
2085 for (col
= 0; col
< width
; col
++) {
2086 (*texImage
->FetchTexelf
)(texImage
, col
, row
, img
, rgba
[col
]);
2088 _mesa_pack_rgba_span_float(ctx
, width
,
2089 (const GLfloat (*)[4]) rgba
,
2090 format
, type
, dest
, &ctx
->Pack
,
2091 0 /* no image transfer */);
2097 if (ctx
->Pack
.BufferObj
->Name
) {
2098 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
2099 ctx
->Pack
.BufferObj
);
2106 * Called from the API. Note that width includes the border.
2109 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2110 GLsizei width
, GLint border
, GLenum format
,
2111 GLenum type
, const GLvoid
*pixels
)
2113 GLsizei postConvWidth
= width
;
2114 GET_CURRENT_CONTEXT(ctx
);
2115 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2117 if (is_color_format(internalFormat
)) {
2118 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2121 if (target
== GL_TEXTURE_1D
) {
2122 struct gl_texture_unit
*texUnit
;
2123 struct gl_texture_object
*texObj
;
2124 struct gl_texture_image
*texImage
;
2126 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2127 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2128 return; /* error was recorded */
2131 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2132 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2133 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2136 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2139 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2140 /* free the old texture data */
2141 MESA_PBUFFER_FREE(texImage
->Data
);
2143 texImage
->Data
= NULL
;
2144 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2145 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2146 postConvWidth
, 1, 1,
2147 border
, internalFormat
);
2149 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2150 _mesa_update_state(ctx
);
2152 ASSERT(ctx
->Driver
.TexImage1D
);
2154 /* Give the texture to the driver! <pixels> may be null! */
2155 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2156 width
, border
, format
, type
, pixels
,
2157 &ctx
->Unpack
, texObj
, texImage
);
2159 ASSERT(texImage
->TexFormat
);
2161 /* If driver didn't explicitly set this, use the defaults */
2162 if (!texImage
->FetchTexelc
)
2163 texImage
->FetchTexelc
= texImage
->TexFormat
->FetchTexel1D
;
2164 if (!texImage
->FetchTexelf
)
2165 texImage
->FetchTexelf
= texImage
->TexFormat
->FetchTexel1Df
;
2166 ASSERT(texImage
->FetchTexelc
);
2167 ASSERT(texImage
->FetchTexelf
);
2170 texObj
->Complete
= GL_FALSE
;
2171 ctx
->NewState
|= _NEW_TEXTURE
;
2173 else if (target
== GL_PROXY_TEXTURE_1D
) {
2174 /* Proxy texture: check for errors and update proxy state */
2175 struct gl_texture_image
*texImage
;
2176 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2177 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2178 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2179 /* when error, clear all proxy texture image parameters */
2181 clear_teximage_fields(texImage
);
2184 /* no error, set the tex image parameters */
2186 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2187 postConvWidth
, 1, 1,
2188 border
, internalFormat
);
2189 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2190 internalFormat
, format
, type
);
2194 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2201 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2202 GLsizei width
, GLsizei height
, GLint border
,
2203 GLenum format
, GLenum type
,
2204 const GLvoid
*pixels
)
2206 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2207 GET_CURRENT_CONTEXT(ctx
);
2208 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2210 if (is_color_format(internalFormat
)) {
2211 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2215 if (target
== GL_TEXTURE_2D
||
2216 (ctx
->Extensions
.ARB_texture_cube_map
&&
2217 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2218 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2219 (ctx
->Extensions
.NV_texture_rectangle
&&
2220 target
== GL_TEXTURE_RECTANGLE_NV
)) {
2221 /* non-proxy target */
2222 struct gl_texture_unit
*texUnit
;
2223 struct gl_texture_object
*texObj
;
2224 struct gl_texture_image
*texImage
;
2226 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2227 format
, type
, 2, postConvWidth
, postConvHeight
,
2229 return; /* error was recorded */
2232 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2233 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2234 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2236 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2239 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2240 /* free the old texture data */
2241 MESA_PBUFFER_FREE(texImage
->Data
);
2243 texImage
->Data
= NULL
;
2244 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2245 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2246 postConvWidth
, postConvHeight
, 1,
2247 border
, internalFormat
);
2249 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2250 _mesa_update_state(ctx
);
2252 ASSERT(ctx
->Driver
.TexImage2D
);
2254 /* Give the texture to the driver! <pixels> may be null! */
2255 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2256 width
, height
, border
, format
, type
, pixels
,
2257 &ctx
->Unpack
, texObj
, texImage
);
2259 ASSERT(texImage
->TexFormat
);
2261 /* If driver didn't explicitly set these, use the defaults */
2262 if (!texImage
->FetchTexelc
)
2263 texImage
->FetchTexelc
= texImage
->TexFormat
->FetchTexel2D
;
2264 if (!texImage
->FetchTexelf
)
2265 texImage
->FetchTexelf
= texImage
->TexFormat
->FetchTexel2Df
;
2266 ASSERT(texImage
->FetchTexelc
);
2267 ASSERT(texImage
->FetchTexelf
);
2270 texObj
->Complete
= GL_FALSE
;
2271 ctx
->NewState
|= _NEW_TEXTURE
;
2273 else if (target
== GL_PROXY_TEXTURE_2D
||
2274 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2275 ctx
->Extensions
.ARB_texture_cube_map
) ||
2276 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2277 ctx
->Extensions
.NV_texture_rectangle
)) {
2278 /* Proxy texture: check for errors and update proxy state */
2279 struct gl_texture_image
*texImage
;
2280 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2281 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2282 format
, type
, 2, postConvWidth
, postConvHeight
,
2284 /* when error, clear all proxy texture image parameters */
2286 clear_teximage_fields(ctx
->Texture
.Proxy2D
->Image
[0][level
]);
2289 /* no error, set the tex image parameters */
2290 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2291 postConvWidth
, postConvHeight
, 1,
2292 border
, internalFormat
);
2293 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2294 internalFormat
, format
, type
);
2298 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2305 * Called by the API or display list executor.
2306 * Note that width and height include the border.
2309 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2310 GLsizei width
, GLsizei height
, GLsizei depth
,
2311 GLint border
, GLenum format
, GLenum type
,
2312 const GLvoid
*pixels
)
2314 GET_CURRENT_CONTEXT(ctx
);
2315 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2317 if (target
== GL_TEXTURE_3D
) {
2318 struct gl_texture_unit
*texUnit
;
2319 struct gl_texture_object
*texObj
;
2320 struct gl_texture_image
*texImage
;
2322 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2323 format
, type
, 3, width
, height
, depth
, border
)) {
2324 return; /* error was recorded */
2327 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2328 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2329 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2331 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2334 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2335 MESA_PBUFFER_FREE(texImage
->Data
);
2337 texImage
->Data
= NULL
;
2338 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2339 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2340 width
, height
, depth
,
2341 border
, internalFormat
);
2343 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2344 _mesa_update_state(ctx
);
2346 ASSERT(ctx
->Driver
.TexImage3D
);
2348 /* Give the texture to the driver! <pixels> may be null! */
2349 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2350 width
, height
, depth
, border
, format
, type
,
2351 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2353 ASSERT(texImage
->TexFormat
);
2355 /* If driver didn't explicitly set these, use the defaults */
2356 if (!texImage
->FetchTexelc
)
2357 texImage
->FetchTexelc
= texImage
->TexFormat
->FetchTexel3D
;
2358 if (!texImage
->FetchTexelf
)
2359 texImage
->FetchTexelf
= texImage
->TexFormat
->FetchTexel3Df
;
2360 ASSERT(texImage
->FetchTexelc
);
2361 ASSERT(texImage
->FetchTexelf
);
2364 texObj
->Complete
= GL_FALSE
;
2365 ctx
->NewState
|= _NEW_TEXTURE
;
2367 else if (target
== GL_PROXY_TEXTURE_3D
) {
2368 /* Proxy texture: check for errors and update proxy state */
2369 struct gl_texture_image
*texImage
;
2370 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2371 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2372 format
, type
, 3, width
, height
, depth
, border
)) {
2373 /* when error, clear all proxy texture image parameters */
2375 clear_teximage_fields(texImage
);
2378 /* no error, set the tex image parameters */
2379 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2380 border
, internalFormat
);
2381 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2382 internalFormat
, format
, type
);
2386 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2393 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2394 GLsizei width
, GLsizei height
, GLsizei depth
,
2395 GLint border
, GLenum format
, GLenum type
,
2396 const GLvoid
*pixels
)
2398 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2399 depth
, border
, format
, type
, pixels
);
2405 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2406 GLint xoffset
, GLsizei width
,
2407 GLenum format
, GLenum type
,
2408 const GLvoid
*pixels
)
2410 GLsizei postConvWidth
= width
;
2411 struct gl_texture_unit
*texUnit
;
2412 struct gl_texture_object
*texObj
;
2413 struct gl_texture_image
*texImage
;
2414 GET_CURRENT_CONTEXT(ctx
);
2415 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2417 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2418 _mesa_update_state(ctx
);
2420 /* XXX should test internal format */
2421 if (is_color_format(format
)) {
2422 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2425 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2426 postConvWidth
, 1, 1, format
, type
)) {
2427 return; /* error was detected */
2430 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2431 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2432 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2436 return; /* no-op, not an error */
2438 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2439 xoffset
+= texImage
->Border
;
2441 ASSERT(ctx
->Driver
.TexSubImage1D
);
2442 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2443 format
, type
, pixels
, &ctx
->Unpack
,
2445 ctx
->NewState
|= _NEW_TEXTURE
;
2450 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2451 GLint xoffset
, GLint yoffset
,
2452 GLsizei width
, GLsizei height
,
2453 GLenum format
, GLenum type
,
2454 const GLvoid
*pixels
)
2456 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2457 struct gl_texture_unit
*texUnit
;
2458 struct gl_texture_object
*texObj
;
2459 struct gl_texture_image
*texImage
;
2460 GET_CURRENT_CONTEXT(ctx
);
2461 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2463 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2464 _mesa_update_state(ctx
);
2466 /* XXX should test internal format */
2467 if (is_color_format(format
)) {
2468 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2472 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2473 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2474 return; /* error was detected */
2477 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2478 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2479 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2482 if (width
== 0 || height
== 0)
2483 return; /* no-op, not an error */
2485 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2486 xoffset
+= texImage
->Border
;
2487 yoffset
+= texImage
->Border
;
2489 ASSERT(ctx
->Driver
.TexSubImage2D
);
2490 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2491 width
, height
, format
, type
, pixels
,
2492 &ctx
->Unpack
, texObj
, texImage
);
2493 ctx
->NewState
|= _NEW_TEXTURE
;
2499 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2500 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2501 GLsizei width
, GLsizei height
, GLsizei depth
,
2502 GLenum format
, GLenum type
,
2503 const GLvoid
*pixels
)
2505 struct gl_texture_unit
*texUnit
;
2506 struct gl_texture_object
*texObj
;
2507 struct gl_texture_image
*texImage
;
2508 GET_CURRENT_CONTEXT(ctx
);
2509 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2511 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2512 _mesa_update_state(ctx
);
2514 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2515 width
, height
, depth
, format
, type
)) {
2516 return; /* error was detected */
2519 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2520 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2521 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2524 if (width
== 0 || height
== 0 || height
== 0)
2525 return; /* no-op, not an error */
2527 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2528 xoffset
+= texImage
->Border
;
2529 yoffset
+= texImage
->Border
;
2530 zoffset
+= texImage
->Border
;
2532 ASSERT(ctx
->Driver
.TexSubImage3D
);
2533 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2534 xoffset
, yoffset
, zoffset
,
2535 width
, height
, depth
,
2536 format
, type
, pixels
,
2537 &ctx
->Unpack
, texObj
, texImage
);
2538 ctx
->NewState
|= _NEW_TEXTURE
;
2544 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2545 GLenum internalFormat
,
2547 GLsizei width
, GLint border
)
2549 struct gl_texture_unit
*texUnit
;
2550 struct gl_texture_object
*texObj
;
2551 struct gl_texture_image
*texImage
;
2552 GLsizei postConvWidth
= width
;
2553 GET_CURRENT_CONTEXT(ctx
);
2554 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2556 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2557 _mesa_update_state(ctx
);
2559 if (is_color_format(internalFormat
)) {
2560 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2563 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2564 postConvWidth
, 1, border
))
2567 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2568 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2569 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2571 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2574 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2575 /* free the old texture data */
2576 MESA_PBUFFER_FREE(texImage
->Data
);
2578 texImage
->Data
= NULL
;
2580 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2581 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2582 border
, internalFormat
);
2585 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2586 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2587 x
, y
, width
, border
);
2589 ASSERT(texImage
->TexFormat
);
2591 /* If driver didn't explicitly set these, use the defaults */
2592 if (!texImage
->FetchTexelc
)
2593 texImage
->FetchTexelc
= texImage
->TexFormat
->FetchTexel1D
;
2594 if (!texImage
->FetchTexelf
)
2595 texImage
->FetchTexelf
= texImage
->TexFormat
->FetchTexel1Df
;
2596 ASSERT(texImage
->FetchTexelc
);
2597 ASSERT(texImage
->FetchTexelf
);
2600 texObj
->Complete
= GL_FALSE
;
2601 ctx
->NewState
|= _NEW_TEXTURE
;
2607 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2608 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2611 struct gl_texture_unit
*texUnit
;
2612 struct gl_texture_object
*texObj
;
2613 struct gl_texture_image
*texImage
;
2614 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2615 GET_CURRENT_CONTEXT(ctx
);
2616 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2618 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2619 _mesa_update_state(ctx
);
2621 if (is_color_format(internalFormat
)) {
2622 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2626 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2627 postConvWidth
, postConvHeight
, border
))
2630 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2631 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2632 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2634 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2637 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2638 /* free the old texture data */
2639 MESA_PBUFFER_FREE(texImage
->Data
);
2641 texImage
->Data
= NULL
;
2643 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2644 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2645 postConvWidth
, postConvHeight
, 1,
2646 border
, internalFormat
);
2648 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2649 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
2650 x
, y
, width
, height
, border
);
2652 ASSERT(texImage
->TexFormat
);
2654 /* If driver didn't explicitly set these, use the defaults */
2655 if (!texImage
->FetchTexelc
)
2656 texImage
->FetchTexelc
= texImage
->TexFormat
->FetchTexel2D
;
2657 if (!texImage
->FetchTexelf
)
2658 texImage
->FetchTexelf
= texImage
->TexFormat
->FetchTexel2Df
;
2659 ASSERT(texImage
->FetchTexelc
);
2660 ASSERT(texImage
->FetchTexelf
);
2663 texObj
->Complete
= GL_FALSE
;
2664 ctx
->NewState
|= _NEW_TEXTURE
;
2670 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2671 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2673 struct gl_texture_unit
*texUnit
;
2674 struct gl_texture_image
*texImage
;
2675 GLsizei postConvWidth
= width
;
2676 GET_CURRENT_CONTEXT(ctx
);
2677 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2679 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2680 _mesa_update_state(ctx
);
2682 /* XXX should test internal format */
2683 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2685 if (copytexsubimage_error_check(ctx
, 1, target
, level
,
2686 xoffset
, 0, 0, postConvWidth
, 1))
2689 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2690 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2693 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2694 xoffset
+= texImage
->Border
;
2696 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2697 (*ctx
->Driver
.CopyTexSubImage1D
)(ctx
, target
, level
, xoffset
, x
, y
, width
);
2698 ctx
->NewState
|= _NEW_TEXTURE
;
2704 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2705 GLint xoffset
, GLint yoffset
,
2706 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2708 struct gl_texture_unit
*texUnit
;
2709 struct gl_texture_image
*texImage
;
2710 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2711 GET_CURRENT_CONTEXT(ctx
);
2712 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2714 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2715 _mesa_update_state(ctx
);
2717 /* XXX should test internal format */
2718 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
2720 if (copytexsubimage_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2721 postConvWidth
, postConvHeight
))
2724 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2725 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2728 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2729 xoffset
+= texImage
->Border
;
2730 yoffset
+= texImage
->Border
;
2732 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2733 (*ctx
->Driver
.CopyTexSubImage2D
)(ctx
, target
, level
,
2734 xoffset
, yoffset
, x
, y
, width
, height
);
2735 ctx
->NewState
|= _NEW_TEXTURE
;
2741 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2742 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2743 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2745 struct gl_texture_unit
*texUnit
;
2746 struct gl_texture_image
*texImage
;
2747 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2748 GET_CURRENT_CONTEXT(ctx
);
2749 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2751 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2752 _mesa_update_state(ctx
);
2754 /* XXX should test internal format */
2755 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
2757 if (copytexsubimage_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
,
2758 zoffset
, postConvWidth
, postConvHeight
))
2761 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2762 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2765 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2766 xoffset
+= texImage
->Border
;
2767 yoffset
+= texImage
->Border
;
2768 zoffset
+= texImage
->Border
;
2770 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2771 (*ctx
->Driver
.CopyTexSubImage3D
)(ctx
, target
, level
,
2772 xoffset
, yoffset
, zoffset
,
2773 x
, y
, width
, height
);
2774 ctx
->NewState
|= _NEW_TEXTURE
;
2780 /**********************************************************************/
2781 /****** Compressed Textures ******/
2782 /**********************************************************************/
2786 * Error checking for glCompressedTexImage[123]D().
2787 * \return error code or GL_NO_ERROR.
2790 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
2791 GLenum target
, GLint level
,
2792 GLenum internalFormat
, GLsizei width
,
2793 GLsizei height
, GLsizei depth
, GLint border
,
2796 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
2798 if (dimensions
== 1) {
2799 /* 1D compressed textures not allowed */
2800 return GL_INVALID_ENUM
;
2802 else if (dimensions
== 2) {
2803 if (target
== GL_PROXY_TEXTURE_2D
) {
2804 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2806 else if (target
== GL_TEXTURE_2D
) {
2807 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2809 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
2810 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2811 return GL_INVALID_ENUM
; /*target*/
2812 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2814 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2815 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2816 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2817 return GL_INVALID_ENUM
; /*target*/
2818 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2821 return GL_INVALID_ENUM
; /*target*/
2824 else if (dimensions
== 3) {
2825 /* 3D compressed textures not allowed */
2826 return GL_INVALID_ENUM
;
2829 maxTextureSize
= 1 << (maxLevels
- 1);
2831 if (!is_compressed_format(ctx
, internalFormat
))
2832 return GL_INVALID_ENUM
;
2834 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
2835 return GL_INVALID_ENUM
;
2838 return GL_INVALID_VALUE
;
2841 * XXX We should probably use the proxy texture error check function here.
2843 if (width
< 1 || width
> maxTextureSize
||
2844 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& logbase2(width
) < 0))
2845 return GL_INVALID_VALUE
;
2847 if ((height
< 1 || height
> maxTextureSize
||
2848 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& logbase2(height
) < 0))
2850 return GL_INVALID_VALUE
;
2852 if ((depth
< 1 || depth
> maxTextureSize
||
2853 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& logbase2(depth
) < 0))
2855 return GL_INVALID_VALUE
;
2857 /* For cube map, width must equal height */
2858 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2859 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
2860 return GL_INVALID_VALUE
;
2862 if (level
< 0 || level
>= maxLevels
)
2863 return GL_INVALID_VALUE
;
2865 expectedSize
= ctx
->Driver
.CompressedTextureSize(ctx
, width
, height
, depth
,
2867 if (expectedSize
!= imageSize
)
2868 return GL_INVALID_VALUE
;
2875 * Error checking for glCompressedTexSubImage[123]D().
2876 * \warning There are some bad assumptions here about the size of compressed
2877 * texture tiles (multiple of 4) used to test the validity of the
2878 * offset and size parameters.
2879 * \return error code or GL_NO_ERROR.
2882 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
2883 GLenum target
, GLint level
,
2884 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2885 GLsizei width
, GLsizei height
, GLsizei depth
,
2886 GLenum format
, GLsizei imageSize
)
2888 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
2891 if (dimensions
== 1) {
2892 /* 1D compressed textures not allowed */
2893 return GL_INVALID_ENUM
;
2895 else if (dimensions
== 2) {
2896 if (target
== GL_PROXY_TEXTURE_2D
) {
2897 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2899 else if (target
== GL_TEXTURE_2D
) {
2900 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2902 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
2903 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2904 return GL_INVALID_ENUM
; /*target*/
2905 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2907 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2908 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2909 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2910 return GL_INVALID_ENUM
; /*target*/
2911 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2914 return GL_INVALID_ENUM
; /*target*/
2917 else if (dimensions
== 3) {
2918 /* 3D compressed textures not allowed */
2919 return GL_INVALID_ENUM
;
2922 maxTextureSize
= 1 << (maxLevels
- 1);
2924 if (!is_compressed_format(ctx
, format
))
2925 return GL_INVALID_ENUM
;
2927 if (width
< 1 || width
> maxTextureSize
)
2928 return GL_INVALID_VALUE
;
2930 if ((height
< 1 || height
> maxTextureSize
)
2932 return GL_INVALID_VALUE
;
2934 if (level
< 0 || level
>= maxLevels
)
2935 return GL_INVALID_VALUE
;
2937 /* XXX these tests are specific to the compressed format.
2938 * this code should be generalized in some way.
2940 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
2941 return GL_INVALID_VALUE
;
2943 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
2944 return GL_INVALID_VALUE
;
2946 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
2947 return GL_INVALID_VALUE
;
2949 expectedSize
= ctx
->Driver
.CompressedTextureSize(ctx
, width
, height
, depth
,
2951 if (expectedSize
!= imageSize
)
2952 return GL_INVALID_VALUE
;
2960 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
2961 GLenum internalFormat
, GLsizei width
,
2962 GLint border
, GLsizei imageSize
,
2965 GET_CURRENT_CONTEXT(ctx
);
2966 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2968 if (target
== GL_TEXTURE_1D
) {
2969 struct gl_texture_unit
*texUnit
;
2970 struct gl_texture_object
*texObj
;
2971 struct gl_texture_image
*texImage
;
2972 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
2973 internalFormat
, width
, 1, 1, border
, imageSize
);
2975 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
2979 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2980 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2981 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
2983 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
2986 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2987 MESA_PBUFFER_FREE(texImage
->Data
);
2989 texImage
->Data
= NULL
;
2991 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
2992 border
, internalFormat
);
2994 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
2995 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
2996 internalFormat
, width
, border
,
3001 texObj
->Complete
= GL_FALSE
;
3002 ctx
->NewState
|= _NEW_TEXTURE
;
3004 else if (target
== GL_PROXY_TEXTURE_1D
) {
3005 /* Proxy texture: check for errors and update proxy state */
3006 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3007 internalFormat
, width
, 1, 1, border
, imageSize
);
3009 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3010 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3011 internalFormat
, GL_NONE
, GL_NONE
,
3012 width
, 1, 1, border
);
3015 /* if error, clear all proxy texture image parameters */
3016 struct gl_texture_image
*texImage
;
3017 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3019 clear_teximage_fields(texImage
);
3022 /* store the teximage parameters */
3023 struct gl_texture_unit
*texUnit
;
3024 struct gl_texture_image
*texImage
;
3025 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3026 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3027 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3028 border
, internalFormat
);
3032 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3039 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3040 GLenum internalFormat
, GLsizei width
,
3041 GLsizei height
, GLint border
, GLsizei imageSize
,
3044 GET_CURRENT_CONTEXT(ctx
);
3045 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3047 if (target
== GL_TEXTURE_2D
||
3048 (ctx
->Extensions
.ARB_texture_cube_map
&&
3049 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3050 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3051 struct gl_texture_unit
*texUnit
;
3052 struct gl_texture_object
*texObj
;
3053 struct gl_texture_image
*texImage
;
3054 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3055 internalFormat
, width
, height
, 1, border
, imageSize
);
3057 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3061 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3062 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3063 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
3065 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3068 else if (texImage
->Data
&& !texImage
->IsClientData
) {
3069 MESA_PBUFFER_FREE(texImage
->Data
);
3071 texImage
->Data
= NULL
;
3073 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3074 border
, internalFormat
);
3076 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3077 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3078 internalFormat
, width
, height
,
3079 border
, imageSize
, data
,
3083 texObj
->Complete
= GL_FALSE
;
3084 ctx
->NewState
|= _NEW_TEXTURE
;
3086 else if (target
== GL_PROXY_TEXTURE_2D
||
3087 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3088 ctx
->Extensions
.ARB_texture_cube_map
)) {
3089 /* Proxy texture: check for errors and update proxy state */
3090 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3091 internalFormat
, width
, height
, 1, border
, imageSize
);
3093 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3094 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3095 internalFormat
, GL_NONE
, GL_NONE
,
3096 width
, height
, 1, border
);
3099 /* if error, clear all proxy texture image parameters */
3100 struct gl_texture_image
*texImage
;
3101 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3103 clear_teximage_fields(texImage
);
3106 /* store the teximage parameters */
3107 struct gl_texture_unit
*texUnit
;
3108 struct gl_texture_image
*texImage
;
3109 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3110 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3111 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3112 border
, internalFormat
);
3116 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3123 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3124 GLenum internalFormat
, GLsizei width
,
3125 GLsizei height
, GLsizei depth
, GLint border
,
3126 GLsizei imageSize
, const GLvoid
*data
)
3128 GET_CURRENT_CONTEXT(ctx
);
3129 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3131 if (target
== GL_TEXTURE_3D
) {
3132 struct gl_texture_unit
*texUnit
;
3133 struct gl_texture_object
*texObj
;
3134 struct gl_texture_image
*texImage
;
3135 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3136 internalFormat
, width
, height
, depth
, border
, imageSize
);
3138 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3142 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3143 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3144 texImage
= _mesa_get_tex_image(ctx
, texUnit
, target
, level
);
3146 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3149 else if (texImage
->Data
&& !texImage
->IsClientData
) {
3150 MESA_PBUFFER_FREE(texImage
->Data
);
3152 texImage
->Data
= NULL
;
3154 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3155 border
, internalFormat
);
3157 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3158 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3160 width
, height
, depth
,
3161 border
, imageSize
, data
,
3165 texObj
->Complete
= GL_FALSE
;
3166 ctx
->NewState
|= _NEW_TEXTURE
;
3168 else if (target
== GL_PROXY_TEXTURE_3D
) {
3169 /* Proxy texture: check for errors and update proxy state */
3170 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3171 internalFormat
, width
, height
, depth
, border
, imageSize
);
3173 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3174 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3175 internalFormat
, GL_NONE
, GL_NONE
,
3176 width
, height
, depth
, border
);
3179 /* if error, clear all proxy texture image parameters */
3180 struct gl_texture_image
*texImage
;
3181 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3183 clear_teximage_fields(texImage
);
3186 /* store the teximage parameters */
3187 struct gl_texture_unit
*texUnit
;
3188 struct gl_texture_image
*texImage
;
3189 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3190 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3191 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3192 depth
, border
, internalFormat
);
3196 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3203 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3204 GLsizei width
, GLenum format
,
3205 GLsizei imageSize
, const GLvoid
*data
)
3207 struct gl_texture_unit
*texUnit
;
3208 struct gl_texture_object
*texObj
;
3209 struct gl_texture_image
*texImage
;
3211 GET_CURRENT_CONTEXT(ctx
);
3212 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3214 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3215 xoffset
, 0, 0, width
, 1, 1, format
, imageSize
);
3217 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3221 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3222 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3223 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3226 if ((GLint
) format
!= texImage
->IntFormat
) {
3227 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3228 "glCompressedTexSubImage1D(format)");
3232 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3233 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3238 return; /* no-op, not an error */
3240 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3241 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3243 format
, imageSize
, data
,
3246 ctx
->NewState
|= _NEW_TEXTURE
;
3251 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3252 GLint yoffset
, GLsizei width
, GLsizei height
,
3253 GLenum format
, GLsizei imageSize
,
3256 struct gl_texture_unit
*texUnit
;
3257 struct gl_texture_object
*texObj
;
3258 struct gl_texture_image
*texImage
;
3260 GET_CURRENT_CONTEXT(ctx
);
3261 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3263 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3264 xoffset
, yoffset
, 0, width
, height
, 1, format
, imageSize
);
3266 /* XXX proxy target? */
3267 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3271 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3272 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3273 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3276 if ((GLint
) format
!= texImage
->IntFormat
) {
3277 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3278 "glCompressedTexSubImage2D(format)");
3282 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3283 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3284 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3288 if (width
== 0 || height
== 0)
3289 return; /* no-op, not an error */
3291 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3292 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3293 xoffset
, yoffset
, width
, height
,
3294 format
, imageSize
, data
,
3297 ctx
->NewState
|= _NEW_TEXTURE
;
3302 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3303 GLint yoffset
, GLint zoffset
, GLsizei width
,
3304 GLsizei height
, GLsizei depth
, GLenum format
,
3305 GLsizei imageSize
, const GLvoid
*data
)
3307 struct gl_texture_unit
*texUnit
;
3308 struct gl_texture_object
*texObj
;
3309 struct gl_texture_image
*texImage
;
3311 GET_CURRENT_CONTEXT(ctx
);
3312 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3314 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3315 xoffset
, yoffset
, zoffset
, width
, height
, depth
, format
, imageSize
);
3317 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3321 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3322 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3323 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3326 if ((GLint
) format
!= texImage
->IntFormat
) {
3327 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3328 "glCompressedTexSubImage3D(format)");
3332 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3333 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3334 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3335 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3339 if (width
== 0 || height
== 0 || depth
== 0)
3340 return; /* no-op, not an error */
3342 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3343 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3344 xoffset
, yoffset
, zoffset
,
3345 width
, height
, depth
,
3346 format
, imageSize
, data
,
3349 ctx
->NewState
|= _NEW_TEXTURE
;
3354 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3356 const struct gl_texture_unit
*texUnit
;
3357 const struct gl_texture_object
*texObj
;
3358 struct gl_texture_image
*texImage
;
3360 GET_CURRENT_CONTEXT(ctx
);
3361 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3363 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3364 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3366 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3370 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3371 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3373 if (level
< 0 || level
>= maxLevels
) {
3374 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3378 if (is_proxy_target(target
)) {
3379 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3383 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
3385 /* probably invalid mipmap level */
3386 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3390 if (!texImage
->IsCompressed
) {
3391 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetCompressedTexImageARB");
3395 /* XXX - someday the rest of this function should be moved into a
3396 * fallback routine called via ctx->Driver.GetCompressedTexImage()
3399 if (ctx
->Pack
.BufferObj
->Name
) {
3400 /* pack texture image into a PBO */
3402 if ((const GLubyte
*) img
+ texImage
->CompressedSize
>
3403 (const GLubyte
*) ctx
->Pack
.BufferObj
->Size
) {
3404 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3405 "glGetCompressedTexImage(invalid PBO access)");
3408 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
3410 ctx
->Pack
.BufferObj
);
3412 /* buffer is already mapped - that's an error */
3413 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3414 "glGetCompressedTexImage(PBO is mapped)");
3417 img
= ADD_POINTERS(buf
, img
);
3424 /* just memcpy, no pixelstore or pixel transfer */
3425 MEMCPY(img
, texImage
->Data
, texImage
->CompressedSize
);
3427 if (ctx
->Pack
.BufferObj
->Name
) {
3428 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
3429 ctx
->Pack
.BufferObj
);