1 /* $Id: teximage.c,v 1.125 2003/01/08 16:24:05 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35 #include "texcompress.h"
36 #include "texformat.h"
46 * Mesa's native texture datatype is GLchan. Native formats are
47 * GL_ALPHA, GL_LUMINANCE, GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, GL_RGBA,
49 * Device drivers are free to implement any internal format they want.
54 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
56 #if CHAN_TYPE == GL_FLOAT
57 _mesa_problem(NULL
, "PrintTexture doesn't support float channels");
60 const GLchan
*data
= (const GLchan
*) img
->Data
;
63 _mesa_printf("No texture data\n");
67 switch (img
->Format
) {
74 case GL_LUMINANCE_ALPHA
:
84 _mesa_problem(NULL
, "error in PrintTexture\n");
88 for (i
= 0; i
< img
->Height
; i
++) {
89 for (j
= 0; j
< img
->Width
; j
++) {
91 _mesa_printf("%02x ", data
[0]);
93 _mesa_printf("%02x%02x ", data
[0], data
[1]);
95 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
97 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
98 data
+= (img
->RowStride
- img
->Width
) * c
;
109 * Compute log base 2 of n.
110 * If n isn't an exact power of two return -1.
111 * If n < 0 return -1.
138 * Given an internal texture format enum or 1, 2, 3, 4 return the
139 * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE,
140 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA.
142 * This is the format which is used during texture application (i.e. the
143 * texture format and env mode determine the arithmetic used.
145 * Return -1 if invalid enum.
148 _mesa_base_tex_format( GLcontext
*ctx
, GLint format
)
151 * Ask the driver for the base format, if it doesn't
152 * know, it will return -1;
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
;
204 case GL_COLOR_INDEX1_EXT
:
205 case GL_COLOR_INDEX2_EXT
:
206 case GL_COLOR_INDEX4_EXT
:
207 case GL_COLOR_INDEX8_EXT
:
208 case GL_COLOR_INDEX12_EXT
:
209 case GL_COLOR_INDEX16_EXT
:
210 if (ctx
->Extensions
.EXT_paletted_texture
)
211 return GL_COLOR_INDEX
;
214 case GL_DEPTH_COMPONENT
:
215 case GL_DEPTH_COMPONENT16_SGIX
:
216 case GL_DEPTH_COMPONENT24_SGIX
:
217 case GL_DEPTH_COMPONENT32_SGIX
:
218 if (ctx
->Extensions
.SGIX_depth_texture
)
219 return GL_DEPTH_COMPONENT
;
223 /* GL_ARB_texture_compression */
224 case GL_COMPRESSED_ALPHA
:
225 if (ctx
->Extensions
.ARB_texture_compression
)
229 case GL_COMPRESSED_LUMINANCE
:
230 if (ctx
->Extensions
.ARB_texture_compression
)
234 case GL_COMPRESSED_LUMINANCE_ALPHA
:
235 if (ctx
->Extensions
.ARB_texture_compression
)
236 return GL_LUMINANCE_ALPHA
;
239 case GL_COMPRESSED_INTENSITY
:
240 if (ctx
->Extensions
.ARB_texture_compression
)
244 case GL_COMPRESSED_RGB
:
245 if (ctx
->Extensions
.ARB_texture_compression
)
249 case GL_COMPRESSED_RGBA
:
250 if (ctx
->Extensions
.ARB_texture_compression
)
254 case GL_COMPRESSED_RGB_FXT1_3DFX
:
255 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
259 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
260 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
)
266 if (ctx
->Extensions
.MESA_ycbcr_texture
)
267 return GL_YCBCR_MESA
;
272 return -1; /* error */
278 * Test if the given image format is a color/rgba format. That is,
279 * not color index, depth, stencil, etc.
282 is_color_format(GLenum format
)
297 case GL_LUMINANCE_ALPHA
:
298 case GL_LUMINANCE4_ALPHA4
:
299 case GL_LUMINANCE6_ALPHA2
:
300 case GL_LUMINANCE8_ALPHA8
:
301 case GL_LUMINANCE12_ALPHA4
:
302 case GL_LUMINANCE12_ALPHA12
:
303 case GL_LUMINANCE16_ALPHA16
:
328 case GL_YCBCR_MESA
: /* not considered to be RGB */
336 is_index_format(GLenum format
)
340 case GL_COLOR_INDEX1_EXT
:
341 case GL_COLOR_INDEX2_EXT
:
342 case GL_COLOR_INDEX4_EXT
:
343 case GL_COLOR_INDEX8_EXT
:
344 case GL_COLOR_INDEX12_EXT
:
345 case GL_COLOR_INDEX16_EXT
:
354 * Return GL_TRUE if internalFormat is a supported compressed format,
355 * return GL_FALSE otherwise.
356 * \param - internalFormat - the internal format token provided by the user
359 is_compressed_format(GLenum internalFormat
)
361 switch (internalFormat
) {
362 case GL_COMPRESSED_RGB_FXT1_3DFX
:
363 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
372 * Store a gl_texture_image pointer in a gl_texture_object structure
373 * according to the target and level parameters.
374 * This was basically prompted by the introduction of cube maps.
377 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
378 GLenum target
, GLint level
,
379 struct gl_texture_image
*texImage
)
387 tObj
->Image
[level
] = texImage
;
389 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
390 tObj
->Image
[level
] = texImage
;
392 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
393 tObj
->NegX
[level
] = texImage
;
395 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
396 tObj
->PosY
[level
] = texImage
;
398 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
399 tObj
->NegY
[level
] = texImage
;
401 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
402 tObj
->PosZ
[level
] = texImage
;
404 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
405 tObj
->NegZ
[level
] = texImage
;
407 case GL_TEXTURE_RECTANGLE_NV
:
409 tObj
->Image
[level
] = texImage
;
412 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
420 * Return new gl_texture_image struct with all fields initialized to zero.
422 struct gl_texture_image
*
423 _mesa_alloc_texture_image( void )
425 return CALLOC_STRUCT(gl_texture_image
);
431 _mesa_free_texture_image( struct gl_texture_image
*teximage
)
433 if (teximage
->Data
&& !teximage
->IsClientData
) {
434 MESA_PBUFFER_FREE( teximage
->Data
);
435 teximage
->Data
= NULL
;
442 * Return GL_TRUE if the target is a proxy target.
445 is_proxy_target(GLenum target
)
447 return (target
== GL_PROXY_TEXTURE_1D
||
448 target
== GL_PROXY_TEXTURE_2D
||
449 target
== GL_PROXY_TEXTURE_3D
||
450 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
);
455 * Given a texture unit and a texture target, return the corresponding
458 struct gl_texture_object
*
459 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
464 return texUnit
->Current1D
;
465 case GL_PROXY_TEXTURE_1D
:
466 return ctx
->Texture
.Proxy1D
;
468 return texUnit
->Current2D
;
469 case GL_PROXY_TEXTURE_2D
:
470 return ctx
->Texture
.Proxy2D
;
472 return texUnit
->Current3D
;
473 case GL_PROXY_TEXTURE_3D
:
474 return ctx
->Texture
.Proxy3D
;
475 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
476 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
477 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
478 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
479 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
480 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
481 case GL_TEXTURE_CUBE_MAP_ARB
:
482 return ctx
->Extensions
.ARB_texture_cube_map
483 ? texUnit
->CurrentCubeMap
: NULL
;
484 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
485 return ctx
->Extensions
.ARB_texture_cube_map
486 ? ctx
->Texture
.ProxyCubeMap
: NULL
;
487 case GL_TEXTURE_RECTANGLE_NV
:
488 return ctx
->Extensions
.NV_texture_rectangle
489 ? texUnit
->CurrentRect
: NULL
;
490 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
491 return ctx
->Extensions
.NV_texture_rectangle
492 ? ctx
->Texture
.ProxyRect
: NULL
;
494 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
501 * Return the texture image struct which corresponds to target and level
502 * for the given texture unit.
504 struct gl_texture_image
*
505 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
506 GLenum target
, GLint level
)
509 ASSERT(level
< MAX_TEXTURE_LEVELS
);
512 return texUnit
->Current1D
->Image
[level
];
513 case GL_PROXY_TEXTURE_1D
:
514 return ctx
->Texture
.Proxy1D
->Image
[level
];
516 return texUnit
->Current2D
->Image
[level
];
517 case GL_PROXY_TEXTURE_2D
:
518 return ctx
->Texture
.Proxy2D
->Image
[level
];
520 return texUnit
->Current3D
->Image
[level
];
521 case GL_PROXY_TEXTURE_3D
:
522 return ctx
->Texture
.Proxy3D
->Image
[level
];
523 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
524 if (ctx
->Extensions
.ARB_texture_cube_map
)
525 return texUnit
->CurrentCubeMap
->Image
[level
];
528 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
529 if (ctx
->Extensions
.ARB_texture_cube_map
)
530 return texUnit
->CurrentCubeMap
->NegX
[level
];
533 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
534 if (ctx
->Extensions
.ARB_texture_cube_map
)
535 return texUnit
->CurrentCubeMap
->PosY
[level
];
538 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
539 if (ctx
->Extensions
.ARB_texture_cube_map
)
540 return texUnit
->CurrentCubeMap
->NegY
[level
];
543 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
544 if (ctx
->Extensions
.ARB_texture_cube_map
)
545 return texUnit
->CurrentCubeMap
->PosZ
[level
];
548 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
549 if (ctx
->Extensions
.ARB_texture_cube_map
)
550 return texUnit
->CurrentCubeMap
->NegZ
[level
];
553 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
554 if (ctx
->Extensions
.ARB_texture_cube_map
)
555 return ctx
->Texture
.ProxyCubeMap
->Image
[level
];
558 case GL_TEXTURE_RECTANGLE_NV
:
559 if (ctx
->Extensions
.NV_texture_rectangle
) {
561 return texUnit
->CurrentRect
->Image
[level
];
566 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
567 if (ctx
->Extensions
.NV_texture_rectangle
) {
569 return ctx
->Texture
.ProxyRect
->Image
[level
];
575 _mesa_problem(ctx
, "bad target in _mesa_select_tex_image()");
582 * Return the maximum number of allows mipmap levels for the given
586 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
590 case GL_PROXY_TEXTURE_1D
:
592 case GL_PROXY_TEXTURE_2D
:
593 return ctx
->Const
.MaxTextureLevels
;
595 case GL_PROXY_TEXTURE_3D
:
596 return ctx
->Const
.Max3DTextureLevels
;
597 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
598 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
599 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
600 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
601 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
602 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
603 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
604 return ctx
->Const
.MaxCubeTextureLevels
;
606 case GL_TEXTURE_RECTANGLE_NV
:
607 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
611 return 0; /* bad target */
617 #if 000 /* not used anymore */
619 * glTexImage[123]D can accept a NULL image pointer. In this case we
620 * create a texture image with unspecified image contents per the OpenGL
624 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
626 const GLint components
= _mesa_components_in_format(format
);
627 const GLint numPixels
= width
* height
* depth
;
628 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
632 * Let's see if anyone finds this. If glTexImage2D() is called with
633 * a NULL image pointer then load the texture image with something
634 * interesting instead of leaving it indeterminate.
637 static const char message
[8][32] = {
641 " X X XXXX XXX XXXXX ",
644 " X X XXXXX XXX X X ",
648 GLubyte
*imgPtr
= data
;
650 for (h
= 0; h
< depth
; h
++) {
651 for (i
= 0; i
< height
; i
++) {
652 GLint srcRow
= 7 - (i
% 8);
653 for (j
= 0; j
< width
; j
++) {
654 GLint srcCol
= j
% 32;
655 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
656 for (k
= 0; k
< components
; k
++) {
672 * Reset the fields of a gl_texture_image struct to zero.
673 * This is called when a proxy texture test fails, we set all the
674 * image members (except DriverData) to zero.
675 * It's also used in glTexImage[123]D as a safeguard to be sure all
676 * required fields get initialized properly by the Driver.TexImage[123]D
680 clear_teximage_fields(struct gl_texture_image
*img
)
697 img
->TexFormat
= &_mesa_null_texformat
;
698 img
->FetchTexel
= NULL
;
699 img
->IsCompressed
= 0;
700 img
->CompressedSize
= 0;
705 * Initialize basic fields of the gl_texture_image struct.
708 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
709 struct gl_texture_image
*img
,
710 GLsizei width
, GLsizei height
, GLsizei depth
,
711 GLint border
, GLenum internalFormat
)
714 img
->Format
= _mesa_base_tex_format( ctx
, internalFormat
);
715 ASSERT(img
->Format
> 0);
716 img
->IntFormat
= internalFormat
;
717 img
->Border
= border
;
719 img
->Height
= height
;
721 img
->RowStride
= width
;
722 img
->WidthLog2
= logbase2(width
- 2 * border
);
723 if (height
== 1) /* 1-D texture */
726 img
->HeightLog2
= logbase2(height
- 2 * border
);
727 if (depth
== 1) /* 2-D texture */
730 img
->DepthLog2
= logbase2(depth
- 2 * border
);
731 img
->Width2
= 1 << img
->WidthLog2
;
732 img
->Height2
= 1 << img
->HeightLog2
;
733 img
->Depth2
= 1 << img
->DepthLog2
;
734 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
735 img
->IsCompressed
= is_compressed_format(internalFormat
);
736 if (img
->IsCompressed
)
737 img
->CompressedSize
= _mesa_compressed_texture_size(ctx
, width
, height
,
738 depth
, internalFormat
);
740 img
->CompressedSize
= 0;
742 /* Compute Width/Height/DepthScale for mipmap lod computation */
743 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
744 /* scale = 1.0 since texture coords directly map to texels */
745 img
->WidthScale
= 1.0;
746 img
->HeightScale
= 1.0;
747 img
->DepthScale
= 1.0;
750 img
->WidthScale
= (GLfloat
) img
->Width
;
751 img
->HeightScale
= (GLfloat
) img
->Height
;
752 img
->DepthScale
= (GLfloat
) img
->Depth
;
759 * Test glTexImage[123]D() parameters for errors.
761 * dimensions - must be 1 or 2 or 3
762 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
765 texture_error_check( GLcontext
*ctx
, GLenum target
,
766 GLint level
, GLint internalFormat
,
767 GLenum format
, GLenum type
,
769 GLint width
, GLint height
,
770 GLint depth
, GLint border
)
773 GLint maxLevels
= 0, maxTextureSize
;
775 if (dimensions
== 1) {
776 if (target
== GL_PROXY_TEXTURE_1D
) {
779 else if (target
== GL_TEXTURE_1D
) {
783 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
786 maxLevels
= ctx
->Const
.MaxTextureLevels
;
788 else if (dimensions
== 2) {
789 if (target
== GL_PROXY_TEXTURE_2D
) {
791 maxLevels
= ctx
->Const
.MaxTextureLevels
;
793 else if (target
== GL_TEXTURE_2D
) {
795 maxLevels
= ctx
->Const
.MaxTextureLevels
;
797 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
798 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
799 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
803 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
805 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
806 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
807 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
808 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
812 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
814 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) {
815 if (!ctx
->Extensions
.NV_texture_rectangle
) {
816 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
822 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
823 if (!ctx
->Extensions
.NV_texture_rectangle
) {
824 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
831 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
835 else if (dimensions
== 3) {
836 if (target
== GL_PROXY_TEXTURE_3D
) {
839 else if (target
== GL_TEXTURE_3D
) {
843 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
846 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
849 _mesa_problem( ctx
, "bad dims in texture_error_check" );
853 ASSERT(maxLevels
> 0);
854 maxTextureSize
= 1 << (maxLevels
- 1);
857 if (border
!= 0 && border
!= 1) {
859 _mesa_error(ctx
, GL_INVALID_VALUE
,
860 "glTexImage%dD(border=%d)", dimensions
, border
);
864 if ((target
== GL_TEXTURE_RECTANGLE_NV
||
865 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0) {
870 if (target
== GL_TEXTURE_RECTANGLE_NV
||
871 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) {
872 if (width
< 1 || width
> ctx
->Const
.MaxTextureRectSize
) {
874 _mesa_error(ctx
, GL_INVALID_VALUE
,
875 "glTexImage%dD(width=%d)", dimensions
, width
);
880 else if (width
< 2 * border
|| width
> 2 + maxTextureSize
881 || logbase2( width
- 2 * border
) < 0) {
883 _mesa_error(ctx
, GL_INVALID_VALUE
,
884 "glTexImage%dD(width=%d)", dimensions
, width
);
890 if (target
== GL_TEXTURE_RECTANGLE_NV
||
891 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) {
892 if (height
< 1 || height
> ctx
->Const
.MaxTextureRectSize
) {
894 _mesa_error(ctx
, GL_INVALID_VALUE
,
895 "glTexImage%dD(height=%d)", dimensions
, height
);
900 else if (dimensions
>= 2) {
901 if (height
< 2 * border
|| height
> 2 + maxTextureSize
902 || logbase2( height
- 2 * border
) < 0) {
904 _mesa_error(ctx
, GL_INVALID_VALUE
,
905 "glTexImage%dD(height=%d)", dimensions
, height
);
911 /* For cube map, width must equal height */
912 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
913 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
914 if (width
!= height
) {
916 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexImage2D(width != height)");
923 if (dimensions
>= 3) {
924 if (depth
< 2 * border
|| depth
> 2 + maxTextureSize
925 || logbase2( depth
- 2 * border
) < 0) {
927 _mesa_error( ctx
, GL_INVALID_VALUE
,
928 "glTexImage3D(depth=%d)", depth
);
935 if (target
== GL_TEXTURE_RECTANGLE_NV
||
936 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) {
939 _mesa_error(ctx
, GL_INVALID_VALUE
,
940 "glTexImage2D(level=%d)", level
);
945 else if (level
< 0 || level
>= maxLevels
) {
947 _mesa_error(ctx
, GL_INVALID_VALUE
,
948 "glTexImage%dD(level=%d)", dimensions
, level
);
953 /* For cube map, width must equal height */
954 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
955 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
956 if (width
!= height
) {
957 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexImage2D(width != height)");
962 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
964 _mesa_error(ctx
, GL_INVALID_VALUE
,
965 "glTexImage%dD(internalFormat=0x%x)",
966 dimensions
, internalFormat
);
971 if (!_mesa_is_legal_format_and_type(format
, type
)) {
972 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
973 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
976 _mesa_error(ctx
, GL_INVALID_OPERATION
,
977 "glTexImage%dD(format or type)", dimensions
);
982 if (format
== GL_YCBCR_MESA
|| internalFormat
== GL_YCBCR_MESA
) {
983 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
984 if (format
!= GL_YCBCR_MESA
||
985 internalFormat
!= GL_YCBCR_MESA
||
986 (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
987 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
)) {
989 _mesa_sprintf(message
,
990 "glTexImage%d(format/type/internalFormat YCBCR mismatch",
992 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
993 return GL_TRUE
; /* error */
995 if (target
!= GL_TEXTURE_2D
&&
996 target
!= GL_PROXY_TEXTURE_2D
&&
997 target
!= GL_TEXTURE_RECTANGLE_NV
&&
998 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1000 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1006 _mesa_sprintf(message
,
1007 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1008 dimensions
, border
);
1009 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1015 if (is_compressed_format(internalFormat
)) {
1016 if (target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
) {
1019 else if (ctx
->Extensions
.ARB_texture_cube_map
&&
1020 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1021 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1022 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))) {
1027 _mesa_error(ctx
, GL_INVALID_ENUM
,
1028 "glTexImage%d(target)", dimensions
);
1034 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1035 "glTexImage%D(border!=0)", dimensions
);
1041 /* if we get here, the parameters are OK */
1048 * Test glTexSubImage[123]D() parameters for errors.
1050 * dimensions - must be 1 or 2 or 3
1051 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
1054 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1055 GLenum target
, GLint level
,
1056 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1057 GLint width
, GLint height
, GLint depth
,
1058 GLenum format
, GLenum type
)
1060 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1061 struct gl_texture_image
*destTex
;
1062 GLint maxLevels
= 0;
1064 if (dimensions
== 1) {
1065 if (target
== GL_TEXTURE_1D
) {
1066 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1069 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1073 else if (dimensions
== 2) {
1074 if (ctx
->Extensions
.ARB_texture_cube_map
&&
1075 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1076 target
<=GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1077 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1079 else if (ctx
->Extensions
.NV_texture_rectangle
&&
1080 target
== GL_TEXTURE_RECTANGLE_NV
) {
1083 else if (target
== GL_TEXTURE_2D
) {
1084 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1087 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1091 else if (dimensions
== 3) {
1092 if (target
== GL_TEXTURE_3D
) {
1093 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
1096 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1101 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1105 ASSERT(maxLevels
> 0);
1107 if (level
< 0 || level
>= maxLevels
) {
1108 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1113 _mesa_error(ctx
, GL_INVALID_VALUE
,
1114 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1117 if (height
< 0 && dimensions
> 1) {
1118 _mesa_error(ctx
, GL_INVALID_VALUE
,
1119 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1122 if (depth
< 0 && dimensions
> 2) {
1123 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1127 destTex
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1130 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage2D");
1134 if (xoffset
< -((GLint
)destTex
->Border
)) {
1135 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage1/2/3D(xoffset)");
1138 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1139 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage1/2/3D(xoffset+width)");
1142 if (dimensions
> 1) {
1143 if (yoffset
< -((GLint
)destTex
->Border
)) {
1144 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage2/3D(yoffset)");
1147 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1148 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage2/3D(yoffset+height)");
1152 if (dimensions
> 2) {
1153 if (zoffset
< -((GLint
)destTex
->Border
)) {
1154 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1157 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1158 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1163 if (!_mesa_is_legal_format_and_type(format
, type
)) {
1164 _mesa_error(ctx
, GL_INVALID_ENUM
,
1165 "glTexSubImage%dD(format or type)", dimensions
);
1169 if (destTex
->IsCompressed
) {
1170 const struct gl_texture_unit
*texUnit
;
1171 const struct gl_texture_object
*texObj
;
1172 const struct gl_texture_image
*texImage
;
1173 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1174 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1175 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1177 if (target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
) {
1180 else if (ctx
->Extensions
.ARB_texture_cube_map
&&
1181 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1182 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1183 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))) {
1187 _mesa_error(ctx
, GL_INVALID_ENUM
,
1188 "glTexSubImage%D(target)", dimensions
);
1191 /* offset must be multiple of 4 */
1192 if ((xoffset
& 3) || (yoffset
& 3)) {
1193 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1194 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1197 /* size must be multiple of 4 or equal to whole texture size */
1198 if ((width
& 3) && (GLuint
) width
!= texImage
->Width
) {
1199 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1200 "glTexSubImage%D(width)", dimensions
);
1203 if ((height
& 3) && (GLuint
) height
!= texImage
->Height
) {
1204 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1205 "glTexSubImage%D(width)", dimensions
);
1215 * Test glCopyTexImage[12]D() parameters for errors.
1216 * Input: dimensions - must be 1 or 2 or 3
1217 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
1220 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1221 GLenum target
, GLint level
, GLint internalFormat
,
1222 GLint width
, GLint height
, GLint border
)
1224 GLint maxLevels
= 0, maxTextureSize
;
1226 if (dimensions
== 1) {
1227 if (target
!= GL_TEXTURE_1D
) {
1228 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1231 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1233 else if (dimensions
== 2) {
1234 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1235 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1236 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1237 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1241 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1242 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1243 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1247 else if (target
!= GL_TEXTURE_2D
) {
1248 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1251 if (target
== GL_TEXTURE_2D
)
1252 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1253 else if (target
== GL_TEXTURE_RECTANGLE_NV
)
1256 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1259 ASSERT(maxLevels
> 0);
1260 maxTextureSize
= 1 << (maxLevels
- 1);
1263 if (border
!= 0 && border
!= 1) {
1264 _mesa_error(ctx
, GL_INVALID_VALUE
,
1265 "glCopyTexImage%dD(border)", dimensions
);
1270 if (width
< 2 * border
|| width
> 2 + maxTextureSize
1271 || logbase2( width
- 2 * border
) < 0) {
1272 _mesa_error(ctx
, GL_INVALID_VALUE
,
1273 "glCopyTexImage%dD(width=%d)", dimensions
, width
);
1278 if (dimensions
>= 2) {
1279 if (height
< 2 * border
|| height
> 2 + maxTextureSize
1280 || logbase2( height
- 2 * border
) < 0) {
1281 _mesa_error(ctx
, GL_INVALID_VALUE
,
1282 "glCopyTexImage%dD(height=%d)", dimensions
, height
);
1287 /* For cube map, width must equal height */
1288 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1289 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1290 if (width
!= height
) {
1291 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyTexImage2D(width != height)");
1297 if (level
< 0 || level
>= maxLevels
) {
1298 _mesa_error(ctx
, GL_INVALID_VALUE
,
1299 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1303 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1304 _mesa_error(ctx
, GL_INVALID_VALUE
,
1305 "glCopyTexImage%dD(internalFormat)", dimensions
);
1309 if (is_compressed_format(internalFormat
)) {
1310 if (target
!= GL_TEXTURE_2D
) {
1311 _mesa_error(ctx
, GL_INVALID_ENUM
,
1312 "glCopyTexImage%d(target)", dimensions
);
1316 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1317 "glCopyTexImage%D(border!=0)", dimensions
);
1322 /* if we get here, the parameters are OK */
1328 copytexsubimage_error_check( GLcontext
*ctx
, GLuint dimensions
,
1329 GLenum target
, GLint level
,
1330 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1331 GLsizei width
, GLsizei height
)
1333 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1334 struct gl_texture_image
*teximage
;
1335 GLint maxLevels
= 0;
1337 if (dimensions
== 1) {
1338 if (target
!= GL_TEXTURE_1D
) {
1339 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1342 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1344 else if (dimensions
== 2) {
1345 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1346 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1347 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1348 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1352 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1353 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1354 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1358 else if (target
!= GL_TEXTURE_2D
) {
1359 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1362 if (target
== GL_TEXTURE_2D
)
1363 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1364 else if (target
== GL_TEXTURE_RECTANGLE_NV
)
1367 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1369 else if (dimensions
== 3) {
1370 if (target
!= GL_TEXTURE_3D
) {
1371 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1374 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
1377 ASSERT(maxLevels
> 0);
1379 if (level
< 0 || level
>= maxLevels
) {
1380 _mesa_error(ctx
, GL_INVALID_VALUE
,
1381 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1386 _mesa_error(ctx
, GL_INVALID_VALUE
,
1387 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1390 if (dimensions
> 1 && height
< 0) {
1391 _mesa_error(ctx
, GL_INVALID_VALUE
,
1392 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1396 teximage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1398 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1399 "glCopyTexSubImage%dD(undefined texture level: %d)",
1404 if (xoffset
< -((GLint
)teximage
->Border
)) {
1405 _mesa_error(ctx
, GL_INVALID_VALUE
,
1406 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1409 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1410 _mesa_error(ctx
, GL_INVALID_VALUE
,
1411 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1414 if (dimensions
> 1) {
1415 if (yoffset
< -((GLint
)teximage
->Border
)) {
1416 _mesa_error(ctx
, GL_INVALID_VALUE
,
1417 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1420 /* NOTE: we're adding the border here, not subtracting! */
1421 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1422 _mesa_error(ctx
, GL_INVALID_VALUE
,
1423 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1428 if (dimensions
> 2) {
1429 if (zoffset
< -((GLint
)teximage
->Border
)) {
1430 _mesa_error(ctx
, GL_INVALID_VALUE
,
1431 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1434 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1435 _mesa_error(ctx
, GL_INVALID_VALUE
,
1436 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1441 if (teximage
->IsCompressed
) {
1442 if (target
!= GL_TEXTURE_2D
) {
1443 _mesa_error(ctx
, GL_INVALID_ENUM
,
1444 "glCopyTexSubImage%d(target)", dimensions
);
1447 /* offset must be multiple of 4 */
1448 if ((xoffset
& 3) || (yoffset
& 3)) {
1449 _mesa_error(ctx
, GL_INVALID_VALUE
,
1450 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
1453 /* size must be multiple of 4 */
1454 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1455 _mesa_error(ctx
, GL_INVALID_VALUE
,
1456 "glCopyTexSubImage%D(width)", dimensions
);
1459 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1460 _mesa_error(ctx
, GL_INVALID_VALUE
,
1461 "glCopyTexSubImage%D(height)", dimensions
);
1466 if (teximage
->IntFormat
== GL_YCBCR_MESA
) {
1467 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1471 /* if we get here, the parameters are OK */
1478 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
1479 GLenum type
, GLvoid
*pixels
)
1481 const struct gl_texture_unit
*texUnit
;
1482 const struct gl_texture_object
*texObj
;
1483 const struct gl_texture_image
*texImage
;
1484 GLint maxLevels
= 0;
1485 GET_CURRENT_CONTEXT(ctx
);
1486 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1488 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
1489 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1490 if (!texObj
|| is_proxy_target(target
)) {
1491 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
1495 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1496 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
1498 if (level
< 0 || level
>= maxLevels
) {
1499 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
1503 if (_mesa_sizeof_packed_type(type
) <= 0) {
1504 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
1508 if (_mesa_components_in_format(format
) <= 0 ||
1509 format
== GL_STENCIL_INDEX
) {
1510 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
1514 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
1515 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
1518 if (!ctx
->Extensions
.SGIX_depth_texture
&& format
== GL_DEPTH_COMPONENT
) {
1519 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
1522 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& format
== GL_YCBCR_MESA
) {
1523 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
1526 /* XXX what if format/type doesn't match texture format/type? */
1531 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1533 /* invalid mipmap level, not an error */
1537 if (!texImage
->Data
) {
1538 /* no image data, not an error */
1543 const GLint width
= texImage
->Width
;
1544 const GLint height
= texImage
->Height
;
1545 const GLint depth
= texImage
->Depth
;
1547 for (img
= 0; img
< depth
; img
++) {
1548 for (row
= 0; row
< height
; row
++) {
1549 /* compute destination address in client memory */
1550 GLvoid
*dest
= _mesa_image_address( &ctx
->Pack
, pixels
,
1551 width
, height
, format
, type
,
1555 if (format
== GL_COLOR_INDEX
) {
1556 GLuint indexRow
[MAX_WIDTH
];
1558 for (col
= 0; col
< width
; col
++) {
1559 (*texImage
->FetchTexel
)(texImage
, col
, row
, img
,
1560 (GLvoid
*) &indexRow
[col
]);
1562 _mesa_pack_index_span(ctx
, width
, type
, dest
,
1563 indexRow
, &ctx
->Pack
,
1564 0 /* no image transfer */);
1566 else if (format
== GL_DEPTH_COMPONENT
) {
1567 GLfloat depthRow
[MAX_WIDTH
];
1569 for (col
= 0; col
< width
; col
++) {
1570 (*texImage
->FetchTexel
)(texImage
, col
, row
, img
,
1571 (GLvoid
*) &depthRow
[col
]);
1573 _mesa_pack_depth_span(ctx
, width
, dest
, type
,
1574 depthRow
, &ctx
->Pack
);
1576 else if (format
== GL_YCBCR_MESA
) {
1577 /* No pixel transfer */
1578 const GLint rowstride
= texImage
->RowStride
;
1580 (const GLushort
*) texImage
->Data
+ row
* rowstride
,
1581 width
* sizeof(GLushort
));
1582 /* check for byte swapping */
1583 if ((texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_YCBCR
1584 && type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ||
1585 (texImage
->TexFormat
->MesaFormat
== MESA_FORMAT_YCBCR_REV
1586 && type
== GL_UNSIGNED_SHORT_8_8_MESA
)) {
1587 if (!ctx
->Pack
.SwapBytes
)
1588 _mesa_swap2((GLushort
*) dest
, width
);
1590 else if (ctx
->Pack
.SwapBytes
) {
1591 _mesa_swap2((GLushort
*) dest
, width
);
1595 /* general case: convert row to RGBA format */
1596 GLchan rgba
[MAX_WIDTH
][4];
1598 for (col
= 0; col
< width
; col
++) {
1599 (*texImage
->FetchTexel
)(texImage
, col
, row
, img
,
1600 (GLvoid
*) rgba
[col
]);
1602 _mesa_pack_rgba_span(ctx
, width
, (const GLchan (*)[4])rgba
,
1603 format
, type
, dest
, &ctx
->Pack
,
1604 0 /* no image transfer */);
1614 * Called from the API. Note that width includes the border.
1617 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
1618 GLsizei width
, GLint border
, GLenum format
,
1619 GLenum type
, const GLvoid
*pixels
)
1621 GLsizei postConvWidth
= width
;
1622 GET_CURRENT_CONTEXT(ctx
);
1623 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1625 if (is_color_format(internalFormat
)) {
1626 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
1629 if (target
== GL_TEXTURE_1D
) {
1630 struct gl_texture_unit
*texUnit
;
1631 struct gl_texture_object
*texObj
;
1632 struct gl_texture_image
*texImage
;
1634 if (texture_error_check(ctx
, target
, level
, internalFormat
,
1635 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
1636 return; /* error was recorded */
1639 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1640 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1641 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1644 texImage
= _mesa_alloc_texture_image();
1645 texObj
->Image
[level
] = texImage
;
1647 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
1651 else if (texImage
->Data
&& !texImage
->IsClientData
) {
1652 /* free the old texture data */
1653 MESA_PBUFFER_FREE(texImage
->Data
);
1655 texImage
->Data
= NULL
;
1656 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1657 _mesa_init_teximage_fields(ctx
, target
, texImage
,
1658 postConvWidth
, 1, 1,
1659 border
, internalFormat
);
1661 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1662 _mesa_update_state(ctx
);
1664 ASSERT(ctx
->Driver
.TexImage1D
);
1666 /* Give the texture to the driver! <pixels> may be null! */
1667 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
1668 width
, border
, format
, type
, pixels
,
1669 &ctx
->Unpack
, texObj
, texImage
);
1671 ASSERT(texImage
->TexFormat
);
1672 if (!texImage
->FetchTexel
) {
1673 /* If driver didn't explicitly set this, use the default */
1674 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel1D
;
1676 ASSERT(texImage
->FetchTexel
);
1679 texObj
->Complete
= GL_FALSE
;
1680 ctx
->NewState
|= _NEW_TEXTURE
;
1682 else if (target
== GL_PROXY_TEXTURE_1D
) {
1683 /* Proxy texture: check for errors and update proxy state */
1684 GLboolean error
= texture_error_check(ctx
, target
, level
, internalFormat
,
1685 format
, type
, 1, postConvWidth
, 1, 1, border
);
1687 ASSERT(ctx
->Driver
.TestProxyTexImage
);
1688 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
1689 internalFormat
, format
, type
,
1690 postConvWidth
, 1, 1, border
);
1693 /* if error, clear all proxy texture image parameters */
1694 if (level
>= 0 && level
< ctx
->Const
.MaxTextureLevels
) {
1695 clear_teximage_fields(ctx
->Texture
.Proxy1D
->Image
[level
]);
1699 /* no error, set the tex image parameters */
1700 struct gl_texture_unit
*texUnit
;
1701 struct gl_texture_image
*texImage
;
1702 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1703 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1704 _mesa_init_teximage_fields(ctx
, target
, texImage
,
1705 postConvWidth
, 1, 1,
1706 border
, internalFormat
);
1710 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1717 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
1718 GLsizei width
, GLsizei height
, GLint border
,
1719 GLenum format
, GLenum type
,
1720 const GLvoid
*pixels
)
1722 GLsizei postConvWidth
= width
, postConvHeight
= height
;
1723 GET_CURRENT_CONTEXT(ctx
);
1724 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1726 if (is_color_format(internalFormat
)) {
1727 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
1731 if (target
== GL_TEXTURE_2D
||
1732 (ctx
->Extensions
.ARB_texture_cube_map
&&
1733 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1734 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
1735 (ctx
->Extensions
.NV_texture_rectangle
&&
1736 target
== GL_TEXTURE_RECTANGLE_NV
)) {
1737 /* non-proxy target */
1738 struct gl_texture_unit
*texUnit
;
1739 struct gl_texture_object
*texObj
;
1740 struct gl_texture_image
*texImage
;
1742 if (texture_error_check(ctx
, target
, level
, internalFormat
,
1743 format
, type
, 2, postConvWidth
, postConvHeight
,
1745 return; /* error was recorded */
1748 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1749 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1750 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1753 texImage
= _mesa_alloc_texture_image();
1754 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
1756 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1760 else if (texImage
->Data
&& !texImage
->IsClientData
) {
1761 /* free the old texture data */
1762 MESA_PBUFFER_FREE(texImage
->Data
);
1764 texImage
->Data
= NULL
;
1765 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1766 _mesa_init_teximage_fields(ctx
, target
, texImage
,
1767 postConvWidth
, postConvHeight
, 1,
1768 border
, internalFormat
);
1770 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1771 _mesa_update_state(ctx
);
1773 ASSERT(ctx
->Driver
.TexImage2D
);
1775 /* Give the texture to the driver! <pixels> may be null! */
1776 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
1777 width
, height
, border
, format
, type
, pixels
,
1778 &ctx
->Unpack
, texObj
, texImage
);
1780 ASSERT(texImage
->TexFormat
);
1781 if (!texImage
->FetchTexel
) {
1782 /* If driver didn't explicitly set this, use the default */
1783 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel2D
;
1785 ASSERT(texImage
->FetchTexel
);
1788 texObj
->Complete
= GL_FALSE
;
1789 ctx
->NewState
|= _NEW_TEXTURE
;
1791 else if (target
== GL_PROXY_TEXTURE_2D
||
1792 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
1793 ctx
->Extensions
.ARB_texture_cube_map
) ||
1794 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
1795 ctx
->Extensions
.NV_texture_rectangle
)) {
1796 /* Proxy texture: check for errors and update proxy state */
1797 GLboolean error
= texture_error_check(ctx
, target
, level
, internalFormat
,
1798 format
, type
, 2, postConvWidth
, postConvHeight
, 1, border
);
1800 ASSERT(ctx
->Driver
.TestProxyTexImage
);
1801 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
1802 internalFormat
, format
, type
,
1803 postConvWidth
, postConvHeight
, 1, border
);
1806 /* if error, clear all proxy texture image parameters */
1807 const GLint maxLevels
= (target
== GL_PROXY_TEXTURE_2D
) ?
1808 ctx
->Const
.MaxTextureLevels
: ctx
->Const
.MaxCubeTextureLevels
;
1809 if (level
>= 0 && level
< maxLevels
) {
1810 clear_teximage_fields(ctx
->Texture
.Proxy2D
->Image
[level
]);
1814 /* no error, set the tex image parameters */
1815 struct gl_texture_unit
*texUnit
;
1816 struct gl_texture_image
*texImage
;
1817 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1818 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1819 _mesa_init_teximage_fields(ctx
, target
, texImage
,
1820 postConvWidth
, postConvHeight
, 1,
1821 border
, internalFormat
);
1825 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
1832 * Called by the API or display list executor.
1833 * Note that width and height include the border.
1836 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
1837 GLsizei width
, GLsizei height
, GLsizei depth
,
1838 GLint border
, GLenum format
, GLenum type
,
1839 const GLvoid
*pixels
)
1841 GET_CURRENT_CONTEXT(ctx
);
1842 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1844 if (target
== GL_TEXTURE_3D
) {
1845 struct gl_texture_unit
*texUnit
;
1846 struct gl_texture_object
*texObj
;
1847 struct gl_texture_image
*texImage
;
1849 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
1850 format
, type
, 3, width
, height
, depth
, border
)) {
1851 return; /* error was recorded */
1854 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1855 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1856 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1859 texImage
= _mesa_alloc_texture_image();
1860 texObj
->Image
[level
] = texImage
;
1862 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
1866 else if (texImage
->Data
&& !texImage
->IsClientData
) {
1867 MESA_PBUFFER_FREE(texImage
->Data
);
1869 texImage
->Data
= NULL
;
1870 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1871 _mesa_init_teximage_fields(ctx
, target
, texImage
,
1872 width
, height
, depth
,
1873 border
, internalFormat
);
1875 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1876 _mesa_update_state(ctx
);
1878 ASSERT(ctx
->Driver
.TexImage3D
);
1880 /* Give the texture to the driver! <pixels> may be null! */
1881 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
1882 width
, height
, depth
, border
, format
, type
,
1883 pixels
, &ctx
->Unpack
, texObj
, texImage
);
1885 ASSERT(texImage
->TexFormat
);
1886 if (!texImage
->FetchTexel
) {
1887 /* If driver didn't explicitly set this, use the default */
1888 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel3D
;
1890 ASSERT(texImage
->FetchTexel
);
1893 texObj
->Complete
= GL_FALSE
;
1894 ctx
->NewState
|= _NEW_TEXTURE
;
1896 else if (target
== GL_PROXY_TEXTURE_3D
) {
1897 /* Proxy texture: check for errors and update proxy state */
1898 GLboolean error
= texture_error_check(ctx
, target
, level
, internalFormat
,
1899 format
, type
, 3, width
, height
, depth
, border
);
1901 ASSERT(ctx
->Driver
.TestProxyTexImage
);
1902 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
1903 internalFormat
, format
, type
,
1904 width
, height
, depth
, border
);
1907 /* if error, clear all proxy texture image parameters */
1908 if (level
>= 0 && level
< ctx
->Const
.Max3DTextureLevels
) {
1909 clear_teximage_fields(ctx
->Texture
.Proxy3D
->Image
[level
]);
1913 /* no error, set the tex image parameters */
1914 struct gl_texture_unit
*texUnit
;
1915 struct gl_texture_image
*texImage
;
1916 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1917 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1918 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
1919 border
, internalFormat
);
1923 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1930 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
1931 GLsizei width
, GLsizei height
, GLsizei depth
,
1932 GLint border
, GLenum format
, GLenum type
,
1933 const GLvoid
*pixels
)
1935 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
1936 depth
, border
, format
, type
, pixels
);
1942 _mesa_TexSubImage1D( GLenum target
, GLint level
,
1943 GLint xoffset
, GLsizei width
,
1944 GLenum format
, GLenum type
,
1945 const GLvoid
*pixels
)
1947 GLsizei postConvWidth
= width
;
1948 struct gl_texture_unit
*texUnit
;
1949 struct gl_texture_object
*texObj
;
1950 struct gl_texture_image
*texImage
;
1951 GET_CURRENT_CONTEXT(ctx
);
1952 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1954 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1955 _mesa_update_state(ctx
);
1957 /* XXX should test internal format */
1958 if (is_color_format(format
)) {
1959 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
1962 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
1963 postConvWidth
, 1, 1, format
, type
)) {
1964 return; /* error was detected */
1967 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1968 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1969 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1972 if (width
== 0 || !pixels
)
1973 return; /* no-op, not an error */
1975 /* If we have a border, xoffset=-1 is legal. Bias by border width */
1976 xoffset
+= texImage
->Border
;
1978 ASSERT(ctx
->Driver
.TexSubImage1D
);
1979 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
1980 format
, type
, pixels
, &ctx
->Unpack
,
1982 ctx
->NewState
|= _NEW_TEXTURE
;
1987 _mesa_TexSubImage2D( GLenum target
, GLint level
,
1988 GLint xoffset
, GLint yoffset
,
1989 GLsizei width
, GLsizei height
,
1990 GLenum format
, GLenum type
,
1991 const GLvoid
*pixels
)
1993 GLsizei postConvWidth
= width
, postConvHeight
= height
;
1994 struct gl_texture_unit
*texUnit
;
1995 struct gl_texture_object
*texObj
;
1996 struct gl_texture_image
*texImage
;
1997 GET_CURRENT_CONTEXT(ctx
);
1998 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2000 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2001 _mesa_update_state(ctx
);
2003 /* XXX should test internal format */
2004 if (is_color_format(format
)) {
2005 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2009 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2010 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2011 return; /* error was detected */
2014 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2015 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2016 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2019 if (width
== 0 || height
== 0 || !pixels
)
2020 return; /* no-op, not an error */
2022 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2023 xoffset
+= texImage
->Border
;
2024 yoffset
+= texImage
->Border
;
2026 ASSERT(ctx
->Driver
.TexSubImage2D
);
2027 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2028 width
, height
, format
, type
, pixels
,
2029 &ctx
->Unpack
, texObj
, texImage
);
2030 ctx
->NewState
|= _NEW_TEXTURE
;
2036 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2037 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2038 GLsizei width
, GLsizei height
, GLsizei depth
,
2039 GLenum format
, GLenum type
,
2040 const GLvoid
*pixels
)
2042 struct gl_texture_unit
*texUnit
;
2043 struct gl_texture_object
*texObj
;
2044 struct gl_texture_image
*texImage
;
2045 GET_CURRENT_CONTEXT(ctx
);
2046 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2048 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2049 _mesa_update_state(ctx
);
2051 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2052 width
, height
, depth
, format
, type
)) {
2053 return; /* error was detected */
2056 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2057 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2058 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2061 if (width
== 0 || height
== 0 || height
== 0 || !pixels
)
2062 return; /* no-op, not an error */
2064 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2065 xoffset
+= texImage
->Border
;
2066 yoffset
+= texImage
->Border
;
2067 zoffset
+= texImage
->Border
;
2069 ASSERT(ctx
->Driver
.TexSubImage3D
);
2070 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2071 xoffset
, yoffset
, zoffset
,
2072 width
, height
, depth
,
2073 format
, type
, pixels
,
2074 &ctx
->Unpack
, texObj
, texImage
);
2075 ctx
->NewState
|= _NEW_TEXTURE
;
2081 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2082 GLenum internalFormat
,
2084 GLsizei width
, GLint border
)
2086 struct gl_texture_unit
*texUnit
;
2087 struct gl_texture_object
*texObj
;
2088 struct gl_texture_image
*texImage
;
2089 GLsizei postConvWidth
= width
;
2090 GET_CURRENT_CONTEXT(ctx
);
2091 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2093 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2094 _mesa_update_state(ctx
);
2096 if (is_color_format(internalFormat
)) {
2097 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2100 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2101 postConvWidth
, 1, border
))
2104 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2105 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2106 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2108 texImage
= _mesa_alloc_texture_image();
2109 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
2111 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2115 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2116 /* free the old texture data */
2117 MESA_PBUFFER_FREE(texImage
->Data
);
2119 texImage
->Data
= NULL
;
2121 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2122 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2123 border
, internalFormat
);
2126 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2127 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2128 x
, y
, width
, border
);
2130 ASSERT(texImage
->TexFormat
);
2131 if (!texImage
->FetchTexel
) {
2132 /* If driver didn't explicitly set this, use the default */
2133 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel1D
;
2135 ASSERT(texImage
->FetchTexel
);
2138 texObj
->Complete
= GL_FALSE
;
2139 ctx
->NewState
|= _NEW_TEXTURE
;
2145 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2146 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2149 struct gl_texture_unit
*texUnit
;
2150 struct gl_texture_object
*texObj
;
2151 struct gl_texture_image
*texImage
;
2152 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2153 GET_CURRENT_CONTEXT(ctx
);
2154 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2156 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2157 _mesa_update_state(ctx
);
2159 if (is_color_format(internalFormat
)) {
2160 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2164 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2165 postConvWidth
, postConvHeight
, border
))
2168 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2169 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2170 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2172 texImage
= _mesa_alloc_texture_image();
2173 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
2175 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2179 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2180 /* free the old texture data */
2181 MESA_PBUFFER_FREE(texImage
->Data
);
2183 texImage
->Data
= NULL
;
2185 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2186 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2187 postConvWidth
, postConvHeight
, 1,
2188 border
, internalFormat
);
2190 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2191 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
2192 x
, y
, width
, height
, border
);
2194 ASSERT(texImage
->TexFormat
);
2195 if (!texImage
->FetchTexel
) {
2196 /* If driver didn't explicitly set this, use the default */
2197 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel2D
;
2199 ASSERT(texImage
->FetchTexel
);
2202 texObj
->Complete
= GL_FALSE
;
2203 ctx
->NewState
|= _NEW_TEXTURE
;
2209 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2210 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2212 struct gl_texture_unit
*texUnit
;
2213 struct gl_texture_object
*texObj
;
2214 struct gl_texture_image
*texImage
;
2215 GLsizei postConvWidth
= width
;
2216 GET_CURRENT_CONTEXT(ctx
);
2217 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2219 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2220 _mesa_update_state(ctx
);
2222 /* XXX should test internal format */
2223 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2225 if (copytexsubimage_error_check(ctx
, 1, target
, level
,
2226 xoffset
, 0, 0, postConvWidth
, 1))
2229 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2230 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2231 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2233 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2234 xoffset
+= texImage
->Border
;
2236 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2237 (*ctx
->Driver
.CopyTexSubImage1D
)(ctx
, target
, level
, xoffset
, x
, y
, width
);
2238 ctx
->NewState
|= _NEW_TEXTURE
;
2244 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2245 GLint xoffset
, GLint yoffset
,
2246 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2248 struct gl_texture_unit
*texUnit
;
2249 struct gl_texture_object
*texObj
;
2250 struct gl_texture_image
*texImage
;
2251 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2252 GET_CURRENT_CONTEXT(ctx
);
2253 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2255 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2256 _mesa_update_state(ctx
);
2258 /* XXX should test internal format */
2259 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
2261 if (copytexsubimage_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2262 postConvWidth
, postConvHeight
))
2265 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2266 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2267 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2269 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2270 xoffset
+= texImage
->Border
;
2271 yoffset
+= texImage
->Border
;
2273 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2274 (*ctx
->Driver
.CopyTexSubImage2D
)(ctx
, target
, level
,
2275 xoffset
, yoffset
, x
, y
, width
, height
);
2276 ctx
->NewState
|= _NEW_TEXTURE
;
2282 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2283 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2284 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2286 struct gl_texture_unit
*texUnit
;
2287 struct gl_texture_object
*texObj
;
2288 struct gl_texture_image
*texImage
;
2289 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2290 GET_CURRENT_CONTEXT(ctx
);
2291 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2293 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2294 _mesa_update_state(ctx
);
2296 /* XXX should test internal format */
2297 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
2299 if (copytexsubimage_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
,
2300 zoffset
, postConvWidth
, postConvHeight
))
2303 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2304 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2305 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2307 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2308 xoffset
+= texImage
->Border
;
2309 yoffset
+= texImage
->Border
;
2310 zoffset
+= texImage
->Border
;
2312 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2313 (*ctx
->Driver
.CopyTexSubImage3D
)(ctx
, target
, level
,
2314 xoffset
, yoffset
, zoffset
,
2315 x
, y
, width
, height
);
2316 ctx
->NewState
|= _NEW_TEXTURE
;
2322 /**********************************************************************/
2323 /****** Compressed Textures ******/
2324 /**********************************************************************/
2328 * Error checking for glCompressedTexImage[123]D().
2329 * \return error code or GL_NO_ERROR.
2332 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
2333 GLenum target
, GLint level
,
2334 GLenum internalFormat
, GLsizei width
,
2335 GLsizei height
, GLsizei depth
, GLint border
,
2338 GLboolean isProxy
= GL_FALSE
;
2339 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
2341 if (dimensions
== 1) {
2342 /* 1D compressed textures not allowed */
2343 return GL_INVALID_ENUM
;
2345 else if (dimensions
== 2) {
2346 if (target
== GL_PROXY_TEXTURE_2D
) {
2347 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2350 else if (target
== GL_TEXTURE_2D
) {
2351 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2353 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
2354 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2355 return GL_INVALID_ENUM
; /*target*/
2356 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2359 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2360 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2361 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2362 return GL_INVALID_ENUM
; /*target*/
2363 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2366 return GL_INVALID_ENUM
; /*target*/
2369 else if (dimensions
== 3) {
2370 /* 3D compressed textures not allowed */
2371 return GL_INVALID_ENUM
;
2374 maxTextureSize
= 1 << (maxLevels
- 1);
2376 if (!is_compressed_format(internalFormat
))
2377 return GL_INVALID_ENUM
;
2380 return GL_INVALID_VALUE
;
2382 if (width
< 1 || width
> maxTextureSize
|| logbase2(width
) < 0)
2383 return GL_INVALID_VALUE
;
2385 if ((height
< 1 || height
> maxTextureSize
|| logbase2(height
) < 0)
2387 return GL_INVALID_VALUE
;
2389 if ((depth
< 1 || depth
> maxTextureSize
|| logbase2(depth
) < 0)
2391 return GL_INVALID_VALUE
;
2393 /* For cube map, width must equal height */
2394 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2395 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
2396 return GL_INVALID_VALUE
;
2398 if (level
< 0 || level
>= maxLevels
)
2399 return GL_INVALID_VALUE
;
2401 expectedSize
= _mesa_compressed_texture_size(ctx
, width
, height
, depth
,
2403 if (expectedSize
!= imageSize
)
2404 return GL_INVALID_VALUE
;
2411 * Error checking for glCompressedTexSubImage[123]D().
2412 * \return error code or GL_NO_ERROR.
2415 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
2416 GLenum target
, GLint level
,
2417 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2418 GLsizei width
, GLsizei height
, GLsizei depth
,
2419 GLenum format
, GLsizei imageSize
)
2421 GLboolean isProxy
= GL_FALSE
;
2422 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
2424 if (dimensions
== 1) {
2425 /* 1D compressed textures not allowed */
2426 return GL_INVALID_ENUM
;
2428 else if (dimensions
== 2) {
2429 if (target
== GL_PROXY_TEXTURE_2D
) {
2430 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2433 else if (target
== GL_TEXTURE_2D
) {
2434 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2436 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
2437 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2438 return GL_INVALID_ENUM
; /*target*/
2439 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2442 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2443 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2444 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2445 return GL_INVALID_ENUM
; /*target*/
2446 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2449 return GL_INVALID_ENUM
; /*target*/
2452 else if (dimensions
== 3) {
2453 /* 3D compressed textures not allowed */
2454 return GL_INVALID_ENUM
;
2457 maxTextureSize
= 1 << (maxLevels
- 1);
2459 if (!is_compressed_format(format
))
2460 return GL_INVALID_ENUM
;
2462 if (width
< 1 || width
> maxTextureSize
|| logbase2(width
) < 0)
2463 return GL_INVALID_VALUE
;
2465 if ((height
< 1 || height
> maxTextureSize
|| logbase2(height
) < 0)
2467 return GL_INVALID_VALUE
;
2469 if (level
< 0 || level
>= maxLevels
)
2470 return GL_INVALID_VALUE
;
2472 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
2473 return GL_INVALID_VALUE
;
2475 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
2476 return GL_INVALID_VALUE
;
2478 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
2479 return GL_INVALID_VALUE
;
2481 expectedSize
= _mesa_compressed_texture_size(ctx
, width
, height
, depth
,
2483 if (expectedSize
!= imageSize
)
2484 return GL_INVALID_VALUE
;
2492 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
2493 GLenum internalFormat
, GLsizei width
,
2494 GLint border
, GLsizei imageSize
,
2497 GET_CURRENT_CONTEXT(ctx
);
2498 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2500 if (target
== GL_TEXTURE_1D
) {
2501 struct gl_texture_unit
*texUnit
;
2502 struct gl_texture_object
*texObj
;
2503 struct gl_texture_image
*texImage
;
2504 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
2505 internalFormat
, width
, 1, 1, border
, imageSize
);
2507 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
2511 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2512 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2513 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2516 texImage
= _mesa_alloc_texture_image();
2517 texObj
->Image
[level
] = texImage
;
2519 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
2523 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2524 MESA_PBUFFER_FREE(texImage
->Data
);
2526 texImage
->Data
= NULL
;
2528 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
2529 border
, internalFormat
);
2531 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
2532 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
2533 internalFormat
, width
, border
,
2538 texObj
->Complete
= GL_FALSE
;
2539 ctx
->NewState
|= _NEW_TEXTURE
;
2541 else if (target
== GL_PROXY_TEXTURE_1D
) {
2542 /* Proxy texture: check for errors and update proxy state */
2543 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
2544 internalFormat
, width
, 1, 1, border
, imageSize
);
2546 ASSERT(ctx
->Driver
.TestProxyTexImage
);
2547 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
2548 internalFormat
, GL_NONE
, GL_NONE
,
2549 width
, 1, 1, border
);
2552 /* if error, clear all proxy texture image parameters */
2553 if (level
>= 0 && level
< ctx
->Const
.MaxTextureLevels
) {
2554 clear_teximage_fields(ctx
->Texture
.Proxy1D
->Image
[level
]);
2558 /* store the teximage parameters */
2559 struct gl_texture_unit
*texUnit
;
2560 struct gl_texture_image
*texImage
;
2561 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2562 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2563 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
2564 border
, internalFormat
);
2568 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
2575 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
2576 GLenum internalFormat
, GLsizei width
,
2577 GLsizei height
, GLint border
, GLsizei imageSize
,
2580 GET_CURRENT_CONTEXT(ctx
);
2581 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2583 if (target
== GL_TEXTURE_2D
||
2584 (ctx
->Extensions
.ARB_texture_cube_map
&&
2585 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2586 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
2587 struct gl_texture_unit
*texUnit
;
2588 struct gl_texture_object
*texObj
;
2589 struct gl_texture_image
*texImage
;
2590 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
2591 internalFormat
, width
, height
, 1, border
, imageSize
);
2593 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
2597 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2598 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2599 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2602 texImage
= _mesa_alloc_texture_image();
2603 texObj
->Image
[level
] = texImage
;
2605 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
2609 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2610 MESA_PBUFFER_FREE(texImage
->Data
);
2612 texImage
->Data
= NULL
;
2614 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2615 border
, internalFormat
);
2617 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
2618 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
2619 internalFormat
, width
, height
,
2620 border
, imageSize
, data
,
2624 texObj
->Complete
= GL_FALSE
;
2625 ctx
->NewState
|= _NEW_TEXTURE
;
2627 else if (target
== GL_PROXY_TEXTURE_2D
||
2628 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2629 ctx
->Extensions
.ARB_texture_cube_map
)) {
2630 /* Proxy texture: check for errors and update proxy state */
2631 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
2632 internalFormat
, width
, height
, 1, border
, imageSize
);
2634 ASSERT(ctx
->Driver
.TestProxyTexImage
);
2635 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
2636 internalFormat
, GL_NONE
, GL_NONE
,
2637 width
, height
, 1, border
);
2640 /* if error, clear all proxy texture image parameters */
2641 const GLint maxLevels
= (target
== GL_PROXY_TEXTURE_2D
) ?
2642 ctx
->Const
.MaxTextureLevels
: ctx
->Const
.MaxCubeTextureLevels
;
2643 if (level
>= 0 && level
< maxLevels
) {
2644 clear_teximage_fields(ctx
->Texture
.Proxy2D
->Image
[level
]);
2648 /* store the teximage parameters */
2649 struct gl_texture_unit
*texUnit
;
2650 struct gl_texture_image
*texImage
;
2651 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2652 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2653 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2654 border
, internalFormat
);
2658 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
2665 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
2666 GLenum internalFormat
, GLsizei width
,
2667 GLsizei height
, GLsizei depth
, GLint border
,
2668 GLsizei imageSize
, const GLvoid
*data
)
2670 GET_CURRENT_CONTEXT(ctx
);
2671 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2673 if (target
== GL_TEXTURE_3D
) {
2674 struct gl_texture_unit
*texUnit
;
2675 struct gl_texture_object
*texObj
;
2676 struct gl_texture_image
*texImage
;
2677 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
2678 internalFormat
, width
, height
, depth
, border
, imageSize
);
2680 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
2684 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2685 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2686 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2689 texImage
= _mesa_alloc_texture_image();
2690 texObj
->Image
[level
] = texImage
;
2692 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
2696 else if (texImage
->Data
&& !texImage
->IsClientData
) {
2697 MESA_PBUFFER_FREE(texImage
->Data
);
2699 texImage
->Data
= NULL
;
2701 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
2702 border
, internalFormat
);
2704 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
2705 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
2707 width
, height
, depth
,
2708 border
, imageSize
, data
,
2712 texObj
->Complete
= GL_FALSE
;
2713 ctx
->NewState
|= _NEW_TEXTURE
;
2715 else if (target
== GL_PROXY_TEXTURE_3D
) {
2716 /* Proxy texture: check for errors and update proxy state */
2717 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
2718 internalFormat
, width
, height
, depth
, border
, imageSize
);
2720 ASSERT(ctx
->Driver
.TestProxyTexImage
);
2721 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
2722 internalFormat
, GL_NONE
, GL_NONE
,
2723 width
, height
, depth
, border
);
2726 /* if error, clear all proxy texture image parameters */
2727 if (level
>= 0 && level
< ctx
->Const
.Max3DTextureLevels
) {
2728 clear_teximage_fields(ctx
->Texture
.Proxy3D
->Image
[level
]);
2732 /* store the teximage parameters */
2733 struct gl_texture_unit
*texUnit
;
2734 struct gl_texture_image
*texImage
;
2735 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2736 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2737 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2738 depth
, border
, internalFormat
);
2742 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
2749 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
2750 GLsizei width
, GLenum format
,
2751 GLsizei imageSize
, const GLvoid
*data
)
2753 struct gl_texture_unit
*texUnit
;
2754 struct gl_texture_object
*texObj
;
2755 struct gl_texture_image
*texImage
;
2757 GET_CURRENT_CONTEXT(ctx
);
2758 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2760 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
2761 xoffset
, 0, 0, width
, 1, 1, format
, imageSize
);
2763 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
2767 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2768 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2769 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2772 if ((GLint
) format
!= texImage
->IntFormat
) {
2773 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2774 "glCompressedTexSubImage1D(format)");
2778 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
2779 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
2783 if (width
== 0 || !data
)
2784 return; /* no-op, not an error */
2786 if (ctx
->Driver
.CompressedTexSubImage1D
) {
2787 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
2789 format
, imageSize
, data
,
2792 ctx
->NewState
|= _NEW_TEXTURE
;
2797 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
2798 GLint yoffset
, GLsizei width
, GLsizei height
,
2799 GLenum format
, GLsizei imageSize
,
2802 struct gl_texture_unit
*texUnit
;
2803 struct gl_texture_object
*texObj
;
2804 struct gl_texture_image
*texImage
;
2806 GET_CURRENT_CONTEXT(ctx
);
2807 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2809 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
2810 xoffset
, yoffset
, 0, width
, height
, 1, format
, imageSize
);
2812 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
2816 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2817 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2818 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2821 if ((GLint
) format
!= texImage
->IntFormat
) {
2822 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2823 "glCompressedTexSubImage2D(format)");
2827 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
2828 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
2829 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
2833 if (width
== 0 || height
== 0 || !data
)
2834 return; /* no-op, not an error */
2836 if (ctx
->Driver
.CompressedTexSubImage2D
) {
2837 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
2838 xoffset
, yoffset
, width
, height
,
2839 format
, imageSize
, data
,
2842 ctx
->NewState
|= _NEW_TEXTURE
;
2847 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
2848 GLint yoffset
, GLint zoffset
, GLsizei width
,
2849 GLsizei height
, GLsizei depth
, GLenum format
,
2850 GLsizei imageSize
, const GLvoid
*data
)
2852 struct gl_texture_unit
*texUnit
;
2853 struct gl_texture_object
*texObj
;
2854 struct gl_texture_image
*texImage
;
2856 GET_CURRENT_CONTEXT(ctx
);
2857 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2859 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
2860 xoffset
, yoffset
, zoffset
, width
, height
, depth
, format
, imageSize
);
2862 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
2866 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2867 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2868 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2871 if ((GLint
) format
!= texImage
->IntFormat
) {
2872 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2873 "glCompressedTexSubImage3D(format)");
2877 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
2878 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
2879 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
2880 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
2884 if (width
== 0 || height
== 0 || depth
== 0 || !data
)
2885 return; /* no-op, not an error */
2887 if (ctx
->Driver
.CompressedTexSubImage3D
) {
2888 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
2889 xoffset
, yoffset
, zoffset
,
2890 width
, height
, depth
,
2891 format
, imageSize
, data
,
2894 ctx
->NewState
|= _NEW_TEXTURE
;
2899 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
2901 const struct gl_texture_unit
*texUnit
;
2902 const struct gl_texture_object
*texObj
;
2903 struct gl_texture_image
*texImage
;
2905 GET_CURRENT_CONTEXT(ctx
);
2906 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2908 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2909 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2911 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
2915 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2916 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2918 if (level
< 0 || level
>= maxLevels
) {
2919 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
2923 if (is_proxy_target(target
)) {
2924 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
2928 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2930 /* probably invalid mipmap level */
2931 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
2935 if (!texImage
->IsCompressed
) {
2936 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetCompressedTexImageARB");
2943 /* just memcpy, no pixelstore or pixel transfer */
2944 MEMCPY(img
, texImage
->Data
, texImage
->CompressedSize
);