1 /* $Id: teximage.c,v 1.101 2001/07/16 15:54:23 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 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.
39 #include "texformat.h"
44 #include "swrast/s_span.h" /* XXX SWRAST hack */
51 * Mesa's native texture datatype is GLchan. Native formats are
52 * GL_ALPHA, GL_LUMINANCE, GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, GL_RGBA,
54 * Device drivers are free to implement any internal format they want.
59 static void PrintTexture(const struct gl_texture_image
*img
)
61 #if CHAN_TYPE == GL_FLOAT
62 _mesa_problem(NULL
, "PrintTexture doesn't support float channels");
65 const GLchan
*data
= (const GLchan
*) img
->Data
;
68 printf("No texture data\n");
72 switch (img
->Format
) {
79 case GL_LUMINANCE_ALPHA
:
89 _mesa_problem(NULL
, "error in PrintTexture\n");
93 for (i
= 0; i
< img
->Height
; i
++) {
94 for (j
= 0; j
< img
->Width
; j
++) {
96 printf("%02x ", data
[0]);
98 printf("%02x%02x ", data
[0], data
[1]);
100 printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
102 printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
114 * Compute log base 2 of n.
115 * If n isn't an exact power of two return -1.
116 * If n < 0 return -1.
143 * Given an internal texture format enum or 1, 2, 3, 4 return the
144 * corresponding _base_ internal format: GL_ALPHA, GL_LUMINANCE,
145 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA.
146 * Return -1 if invalid enum.
149 _mesa_base_tex_format( GLcontext
*ctx
, GLint format
)
152 * Ask the driver for the base format, if it doesn't
153 * know, it will return -1;
155 if (ctx
->Driver
.BaseCompressedTexFormat
) {
156 GLint ifmt
= (*ctx
->Driver
.BaseCompressedTexFormat
)(ctx
, format
);
176 case GL_LUMINANCE_ALPHA
:
177 case GL_LUMINANCE4_ALPHA4
:
178 case GL_LUMINANCE6_ALPHA2
:
179 case GL_LUMINANCE8_ALPHA8
:
180 case GL_LUMINANCE12_ALPHA4
:
181 case GL_LUMINANCE12_ALPHA12
:
182 case GL_LUMINANCE16_ALPHA16
:
183 return GL_LUMINANCE_ALPHA
;
211 case GL_COLOR_INDEX1_EXT
:
212 case GL_COLOR_INDEX2_EXT
:
213 case GL_COLOR_INDEX4_EXT
:
214 case GL_COLOR_INDEX8_EXT
:
215 case GL_COLOR_INDEX12_EXT
:
216 case GL_COLOR_INDEX16_EXT
:
217 return GL_COLOR_INDEX
;
218 case GL_DEPTH_COMPONENT
:
219 case GL_DEPTH_COMPONENT16_SGIX
:
220 case GL_DEPTH_COMPONENT24_SGIX
:
221 case GL_DEPTH_COMPONENT32_SGIX
:
222 if (ctx
->Extensions
.SGIX_depth_texture
)
223 return GL_DEPTH_COMPONENT
;
227 return -1; /* error */
233 * Test if the given image format is a color/rgba format. That is,
234 * not color index, depth, stencil, etc.
237 is_color_format(GLenum format
)
252 case GL_LUMINANCE_ALPHA
:
253 case GL_LUMINANCE4_ALPHA4
:
254 case GL_LUMINANCE6_ALPHA2
:
255 case GL_LUMINANCE8_ALPHA8
:
256 case GL_LUMINANCE12_ALPHA4
:
257 case GL_LUMINANCE12_ALPHA12
:
258 case GL_LUMINANCE16_ALPHA16
:
290 is_index_format(GLenum format
)
294 case GL_COLOR_INDEX1_EXT
:
295 case GL_COLOR_INDEX2_EXT
:
296 case GL_COLOR_INDEX4_EXT
:
297 case GL_COLOR_INDEX8_EXT
:
298 case GL_COLOR_INDEX12_EXT
:
299 case GL_COLOR_INDEX16_EXT
:
308 * Return GL_TRUE if internalFormat is a compressed format, return GL_FALSE
312 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
314 if (ctx
->Driver
.BaseCompressedTexFormat
) {
315 GLint b
= (*ctx
->Driver
.BaseCompressedTexFormat
)(ctx
, internalFormat
);
327 * Store a gl_texture_image pointer in a gl_texture_object structure
328 * according to the target and level parameters.
329 * This was basically prompted by the introduction of cube maps.
332 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
333 GLenum target
, GLint level
,
334 struct gl_texture_image
*texImage
)
342 tObj
->Image
[level
] = texImage
;
344 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
345 tObj
->Image
[level
] = texImage
;
347 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
348 tObj
->NegX
[level
] = texImage
;
350 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
351 tObj
->PosY
[level
] = texImage
;
353 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
354 tObj
->NegY
[level
] = texImage
;
356 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
357 tObj
->PosZ
[level
] = texImage
;
359 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
360 tObj
->NegZ
[level
] = texImage
;
363 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
371 * Return new gl_texture_image struct with all fields initialized to zero.
373 struct gl_texture_image
*
374 _mesa_alloc_texture_image( void )
376 return CALLOC_STRUCT(gl_texture_image
);
382 _mesa_free_texture_image( struct gl_texture_image
*teximage
)
384 if (teximage
->Data
) {
385 FREE( teximage
->Data
);
386 teximage
->Data
= NULL
;
393 * Return GL_TRUE if the target is a proxy target.
396 is_proxy_target(GLenum target
)
398 return (target
== GL_PROXY_TEXTURE_1D
||
399 target
== GL_PROXY_TEXTURE_2D
||
400 target
== GL_PROXY_TEXTURE_3D
||
401 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
);
406 * Given a texture unit and a texture target, return the corresponding
409 struct gl_texture_object
*
410 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
415 return texUnit
->Current1D
;
416 case GL_PROXY_TEXTURE_1D
:
417 return ctx
->Texture
.Proxy1D
;
419 return texUnit
->Current2D
;
420 case GL_PROXY_TEXTURE_2D
:
421 return ctx
->Texture
.Proxy2D
;
423 return texUnit
->Current3D
;
424 case GL_PROXY_TEXTURE_3D
:
425 return ctx
->Texture
.Proxy3D
;
426 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
427 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
428 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
429 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
430 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
431 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
432 case GL_TEXTURE_CUBE_MAP_ARB
:
433 return ctx
->Extensions
.ARB_texture_cube_map
434 ? texUnit
->CurrentCubeMap
: NULL
;
435 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
436 return ctx
->Extensions
.ARB_texture_cube_map
437 ? ctx
->Texture
.ProxyCubeMap
: NULL
;
439 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
446 * Return the texture image struct which corresponds to target and level
447 * for the given texture unit.
449 struct gl_texture_image
*
450 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
451 GLenum target
, GLint level
)
454 ASSERT(level
< MAX_TEXTURE_LEVELS
);
457 return texUnit
->Current1D
->Image
[level
];
458 case GL_PROXY_TEXTURE_1D
:
459 return ctx
->Texture
.Proxy1D
->Image
[level
];
461 return texUnit
->Current2D
->Image
[level
];
462 case GL_PROXY_TEXTURE_2D
:
463 return ctx
->Texture
.Proxy2D
->Image
[level
];
465 return texUnit
->Current3D
->Image
[level
];
466 case GL_PROXY_TEXTURE_3D
:
467 return ctx
->Texture
.Proxy3D
->Image
[level
];
468 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
469 if (ctx
->Extensions
.ARB_texture_cube_map
)
470 return texUnit
->CurrentCubeMap
->Image
[level
];
473 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
474 if (ctx
->Extensions
.ARB_texture_cube_map
)
475 return texUnit
->CurrentCubeMap
->NegX
[level
];
478 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
479 if (ctx
->Extensions
.ARB_texture_cube_map
)
480 return texUnit
->CurrentCubeMap
->PosY
[level
];
483 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
484 if (ctx
->Extensions
.ARB_texture_cube_map
)
485 return texUnit
->CurrentCubeMap
->NegY
[level
];
488 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
489 if (ctx
->Extensions
.ARB_texture_cube_map
)
490 return texUnit
->CurrentCubeMap
->PosZ
[level
];
493 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
494 if (ctx
->Extensions
.ARB_texture_cube_map
)
495 return texUnit
->CurrentCubeMap
->NegZ
[level
];
498 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
499 if (ctx
->Extensions
.ARB_texture_cube_map
)
500 return ctx
->Texture
.ProxyCubeMap
->Image
[level
];
504 _mesa_problem(ctx
, "bad target in _mesa_select_tex_image()");
512 * glTexImage[123]D can accept a NULL image pointer. In this case we
513 * create a texture image with unspecified image contents per the OpenGL
517 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
519 const GLint components
= _mesa_components_in_format(format
);
520 const GLint numPixels
= width
* height
* depth
;
521 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
525 * Let's see if anyone finds this. If glTexImage2D() is called with
526 * a NULL image pointer then load the texture image with something
527 * interesting instead of leaving it indeterminate.
530 static const char message
[8][32] = {
534 " X X XXXX XXX XXXXX ",
537 " X X XXXXX XXX X X ",
541 GLubyte
*imgPtr
= data
;
543 for (h
= 0; h
< depth
; h
++) {
544 for (i
= 0; i
< height
; i
++) {
545 GLint srcRow
= 7 - (i
% 8);
546 for (j
= 0; j
< width
; j
++) {
547 GLint srcCol
= j
% 32;
548 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
549 for (k
= 0; k
< components
; k
++) {
564 * Reset the fields of a gl_texture_image struct to zero.
565 * This is called when a proxy texture test fails, we set all the
566 * image members (except DriverData) to zero.
567 * It's also used in glTexImage[123]D as a safeguard to be sure all
568 * required fields get initialized properly by the Driver.TexImage[123]D
572 clear_teximage_fields(struct gl_texture_image
*img
)
588 img
->TexFormat
= &_mesa_null_texformat
;
589 img
->FetchTexel
= NULL
;
590 img
->IsCompressed
= 0;
591 img
->CompressedSize
= 0;
596 * Initialize basic fields of the gl_texture_image struct.
599 _mesa_init_teximage_fields(GLcontext
*ctx
,
600 struct gl_texture_image
*img
,
601 GLsizei width
, GLsizei height
, GLsizei depth
,
602 GLint border
, GLenum internalFormat
)
605 img
->Format
= _mesa_base_tex_format( ctx
, internalFormat
);
606 ASSERT(img
->Format
> 0);
607 img
->IntFormat
= internalFormat
;
608 img
->Border
= border
;
610 img
->Height
= height
;
612 img
->WidthLog2
= logbase2(width
- 2 * border
);
613 if (height
== 1) /* 1-D texture */
616 img
->HeightLog2
= logbase2(height
- 2 * border
);
617 if (depth
== 1) /* 2-D texture */
620 img
->DepthLog2
= logbase2(depth
- 2 * border
);
621 img
->Width2
= 1 << img
->WidthLog2
;
622 img
->Height2
= 1 << img
->HeightLog2
;
623 img
->Depth2
= 1 << img
->DepthLog2
;
624 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
625 img
->IsCompressed
= is_compressed_format(ctx
, internalFormat
);
631 * Test glTexImage[123]D() parameters for errors.
633 * dimensions - must be 1 or 2 or 3
634 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
637 texture_error_check( GLcontext
*ctx
, GLenum target
,
638 GLint level
, GLint internalFormat
,
639 GLenum format
, GLenum type
,
641 GLint width
, GLint height
,
642 GLint depth
, GLint border
)
646 GLint maxLevels
= 0, maxTextureSize
;
648 if (dimensions
== 1) {
649 isProxy
= (GLboolean
) (target
== GL_PROXY_TEXTURE_1D
);
650 if (target
!= GL_TEXTURE_1D
&& !isProxy
) {
651 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
654 maxLevels
= ctx
->Const
.MaxTextureLevels
;
656 else if (dimensions
== 2) {
657 isProxy
= (GLboolean
) (target
== GL_PROXY_TEXTURE_2D
||
658 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
);
659 if (target
!= GL_TEXTURE_2D
&& !isProxy
&&
660 !(ctx
->Extensions
.ARB_texture_cube_map
&&
661 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
662 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
663 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
666 if (target
== GL_PROXY_TEXTURE_2D
&& target
== GL_TEXTURE_2D
)
667 maxLevels
= ctx
->Const
.MaxTextureLevels
;
669 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
671 else if (dimensions
== 3) {
672 isProxy
= (GLboolean
) (target
== GL_PROXY_TEXTURE_3D
);
673 if (target
!= GL_TEXTURE_3D
&& !isProxy
) {
674 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
677 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
680 _mesa_problem( ctx
, "bad dims in texture_error_check" );
684 ASSERT(maxLevels
> 0);
685 maxTextureSize
= 1 << (maxLevels
- 1);
688 if (border
!= 0 && border
!= 1) {
691 sprintf(message
, "glTexImage%dD(border=%d)", dimensions
, border
);
692 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
698 if (width
< 2 * border
|| width
> 2 + maxTextureSize
699 || logbase2( width
- 2 * border
) < 0) {
702 sprintf(message
, "glTexImage%dD(width=%d)", dimensions
, width
);
703 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
709 if (dimensions
>= 2) {
710 if (height
< 2 * border
|| height
> 2 + maxTextureSize
711 || logbase2( height
- 2 * border
) < 0) {
714 sprintf(message
, "glTexImage%dD(height=%d)", dimensions
, height
);
715 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
721 /* For cube map, width must equal height */
722 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
723 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
724 if (width
!= height
) {
726 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexImage2D(width != height)");
733 if (dimensions
>= 3) {
734 if (depth
< 2 * border
|| depth
> 2 + maxTextureSize
735 || logbase2( depth
- 2 * border
) < 0) {
738 sprintf(message
, "glTexImage3D(depth=%d)", depth
);
739 _mesa_error( ctx
, GL_INVALID_VALUE
, message
);
746 if (level
< 0 || level
>= maxLevels
) {
749 sprintf(message
, "glTexImage%dD(level=%d)", dimensions
, level
);
750 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
755 /* For cube map, width must equal height */
756 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
757 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
758 if (width
!= height
) {
759 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexImage2D(width != height)");
764 iformat
= _mesa_base_tex_format( ctx
, internalFormat
);
768 sprintf(message
, "glTexImage%dD(internalFormat=0x%x)", dimensions
,
770 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
777 if (!is_compressed_format( ctx
, internalFormat
) &&
778 !_mesa_is_legal_format_and_type( format
, type
)) {
779 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
780 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
784 sprintf(message
, "glTexImage%dD(format or type)", dimensions
);
785 _mesa_error(ctx
, GL_INVALID_OPERATION
, message
);
790 /* if we get here, the parameters are OK */
797 * Test glTexSubImage[123]D() parameters for errors.
799 * dimensions - must be 1 or 2 or 3
800 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
803 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
804 GLenum target
, GLint level
,
805 GLint xoffset
, GLint yoffset
, GLint zoffset
,
806 GLint width
, GLint height
, GLint depth
,
807 GLenum format
, GLenum type
)
809 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
810 struct gl_texture_image
*destTex
;
812 GLboolean compressed
;
814 if (dimensions
== 1) {
815 if (target
!= GL_TEXTURE_1D
) {
816 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
819 maxLevels
= ctx
->Const
.MaxTextureLevels
;
821 else if (dimensions
== 2) {
822 if (ctx
->Extensions
.ARB_texture_cube_map
) {
823 if ((target
< GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
||
824 target
> GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) &&
825 target
!= GL_TEXTURE_2D
) {
826 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
830 else if (target
!= GL_TEXTURE_2D
) {
831 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
834 if (target
== GL_PROXY_TEXTURE_2D
&& target
== GL_TEXTURE_2D
)
835 maxLevels
= ctx
->Const
.MaxTextureLevels
;
837 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
839 else if (dimensions
== 3) {
840 if (target
!= GL_TEXTURE_3D
) {
841 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
844 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
847 _mesa_problem( ctx
, "bad dims in texture_error_check" );
851 ASSERT(maxLevels
> 0);
853 if (level
< 0 || level
>= maxLevels
) {
855 sprintf(message
, "glTexSubImage2D(level=%d)", level
);
856 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
862 sprintf(message
, "glTexSubImage%dD(width=%d)", dimensions
, width
);
863 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
866 if (height
< 0 && dimensions
> 1) {
868 sprintf(message
, "glTexSubImage%dD(height=%d)", dimensions
, height
);
869 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
872 if (depth
< 0 && dimensions
> 2) {
874 sprintf(message
, "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
875 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
879 destTex
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
882 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage2D");
886 if (xoffset
< -((GLint
)destTex
->Border
)) {
887 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage1/2/3D(xoffset)");
890 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
891 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage1/2/3D(xoffset+width)");
894 if (dimensions
> 1) {
895 if (yoffset
< -((GLint
)destTex
->Border
)) {
896 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage2/3D(yoffset)");
899 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
900 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage2/3D(yoffset+height)");
904 if (dimensions
> 2) {
905 if (zoffset
< -((GLint
)destTex
->Border
)) {
906 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
909 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
910 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
915 compressed
= is_compressed_format(ctx
, destTex
->IntFormat
);
917 if (!compressed
&& !_mesa_is_legal_format_and_type(format
, type
)) {
919 sprintf(message
, "glTexSubImage%dD(format or type)", dimensions
);
920 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
925 if (xoffset
!= -destTex
->Border
) {
926 _mesa_error(ctx
, GL_INVALID_OPERATION
,
927 "glTexSubImage1/2/3D(xoffset != -border");
930 if (dimensions
> 1 && yoffset
!= -destTex
->Border
) {
931 _mesa_error(ctx
, GL_INVALID_OPERATION
,
932 "glTexSubImage2/3D(yoffset != -border");
935 if (dimensions
> 2 && zoffset
!= -destTex
->Border
) {
936 _mesa_error(ctx
, GL_INVALID_OPERATION
,
937 "glTexSubImage3D(zoffset != -border");
947 * Test glCopyTexImage[12]D() parameters for errors.
948 * Input: dimensions - must be 1 or 2 or 3
949 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
952 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
953 GLenum target
, GLint level
, GLint internalFormat
,
954 GLint width
, GLint height
, GLint border
)
957 GLint maxLevels
= 0, maxTextureSize
;
959 if (dimensions
== 1) {
960 if (target
!= GL_TEXTURE_1D
) {
961 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
964 maxLevels
= ctx
->Const
.MaxTextureLevels
;
966 else if (dimensions
== 2) {
967 if (ctx
->Extensions
.ARB_texture_cube_map
) {
968 if ((target
< GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
||
969 target
> GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) &&
970 target
!= GL_TEXTURE_2D
) {
971 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
975 else if (target
!= GL_TEXTURE_2D
) {
976 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
979 if (target
== GL_PROXY_TEXTURE_2D
&& target
== GL_TEXTURE_2D
)
980 maxLevels
= ctx
->Const
.MaxTextureLevels
;
982 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
985 ASSERT(maxLevels
> 0);
986 maxTextureSize
= 1 << (maxLevels
- 1);
989 if (border
!= 0 && border
!= 1) {
991 sprintf(message
, "glCopyTexImage%dD(border)", dimensions
);
992 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
997 if (width
< 2 * border
|| width
> 2 + maxTextureSize
998 || logbase2( width
- 2 * border
) < 0) {
1000 sprintf(message
, "glCopyTexImage%dD(width=%d)", dimensions
, width
);
1001 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1006 if (dimensions
>= 2) {
1007 if (height
< 2 * border
|| height
> 2 + maxTextureSize
1008 || logbase2( height
- 2 * border
) < 0) {
1010 sprintf(message
, "glCopyTexImage%dD(height=%d)", dimensions
, height
);
1011 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1016 /* For cube map, width must equal height */
1017 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1018 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1019 if (width
!= height
) {
1020 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyTexImage2D(width != height)");
1026 if (level
< 0 || level
>= maxLevels
) {
1028 sprintf(message
, "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1029 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1033 iformat
= _mesa_base_tex_format(ctx
, internalFormat
);
1036 sprintf(message
, "glCopyTexImage%dD(internalFormat)", dimensions
);
1037 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1041 /* if we get here, the parameters are OK */
1047 copytexsubimage_error_check( GLcontext
*ctx
, GLuint dimensions
,
1048 GLenum target
, GLint level
,
1049 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1050 GLsizei width
, GLsizei height
)
1052 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1053 struct gl_texture_image
*teximage
;
1054 GLint maxLevels
= 0;
1055 GLboolean compressed
;
1057 if (dimensions
== 1) {
1058 if (target
!= GL_TEXTURE_1D
) {
1059 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1062 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1064 else if (dimensions
== 2) {
1065 if (ctx
->Extensions
.ARB_texture_cube_map
) {
1066 if ((target
< GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
||
1067 target
> GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) &&
1068 target
!= GL_TEXTURE_2D
) {
1069 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1073 else if (target
!= GL_TEXTURE_2D
) {
1074 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1077 if (target
== GL_PROXY_TEXTURE_2D
&& target
== GL_TEXTURE_2D
)
1078 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1080 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1082 else if (dimensions
== 3) {
1083 if (target
!= GL_TEXTURE_3D
) {
1084 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1087 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
1090 ASSERT(maxLevels
> 0);
1092 if (level
< 0 || level
>= maxLevels
) {
1094 sprintf(message
, "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1095 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1101 sprintf(message
, "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1102 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1105 if (dimensions
> 1 && height
< 0) {
1107 sprintf(message
, "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1108 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1112 teximage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1115 sprintf(message
, "glCopyTexSubImage%dD(undefined texture)", dimensions
);
1116 _mesa_error(ctx
, GL_INVALID_OPERATION
, message
);
1120 if (xoffset
< -((GLint
)teximage
->Border
)) {
1122 sprintf(message
, "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1123 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1126 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1128 sprintf(message
, "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1129 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1132 if (dimensions
> 1) {
1133 if (yoffset
< -((GLint
)teximage
->Border
)) {
1135 sprintf(message
, "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1136 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1139 /* NOTE: we're adding the border here, not subtracting! */
1140 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1142 sprintf(message
, "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1143 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1148 if (dimensions
> 2) {
1149 if (zoffset
< -((GLint
)teximage
->Border
)) {
1151 sprintf(message
, "glCopyTexSubImage%dD(zoffset)", dimensions
);
1152 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1155 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1157 sprintf(message
, "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1158 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1163 compressed
= is_compressed_format(ctx
, teximage
->IntFormat
);
1165 if (xoffset
!= -teximage
->Border
) {
1166 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1167 "glCopyTexSubImage1/2/3D(xoffset != -border");
1170 if (dimensions
> 1 && yoffset
!= -teximage
->Border
) {
1171 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1172 "glCopyTexSubImage2/3D(yoffset != -border");
1175 if (dimensions
> 2 && zoffset
!= -teximage
->Border
) {
1176 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1177 "glCopyTexSubImage3D(zoffset != -border");
1182 /* if we get here, the parameters are OK */
1189 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
1190 GLenum type
, GLvoid
*pixels
)
1192 const struct gl_texture_unit
*texUnit
;
1193 const struct gl_texture_object
*texObj
;
1194 struct gl_texture_image
*texImage
;
1195 GLint maxLevels
= 0;
1196 GET_CURRENT_CONTEXT(ctx
);
1197 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1199 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
1200 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1201 if (!texObj
|| is_proxy_target(target
)) {
1202 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
1206 if (target
== GL_TEXTURE_1D
|| target
== GL_TEXTURE_2D
) {
1207 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1209 else if (target
== GL_TEXTURE_3D
) {
1210 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
1213 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1216 ASSERT(maxLevels
> 0);
1218 if (level
< 0 || level
>= maxLevels
) {
1219 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
1223 if (_mesa_sizeof_type(type
) <= 0) {
1224 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
1228 if (_mesa_components_in_format(format
) <= 0 ||
1229 format
== GL_STENCIL_INDEX
) {
1230 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
1234 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
1235 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
1238 if (!ctx
->Extensions
.SGIX_depth_texture
&& format
== GL_DEPTH_COMPONENT
) {
1239 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
1242 /* XXX what if format/type doesn't match texture format/type? */
1247 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1249 /* invalid mipmap level, not an error */
1253 if (!texImage
->Data
) {
1254 /* no image data, not an error */
1259 const GLint width
= texImage
->Width
;
1260 const GLint height
= texImage
->Height
;
1261 const GLint depth
= texImage
->Depth
;
1263 for (img
= 0; img
< depth
; img
++) {
1264 for (row
= 0; row
< height
; row
++) {
1265 /* compute destination address in client memory */
1266 GLvoid
*dest
= _mesa_image_address( &ctx
->Unpack
, pixels
,
1267 width
, height
, format
, type
,
1271 if (format
== GL_COLOR_INDEX
) {
1272 GLuint indexRow
[MAX_WIDTH
];
1274 for (col
= 0; col
< width
; col
++) {
1275 (*texImage
->FetchTexel
)(texImage
, col
, row
, img
,
1276 (GLvoid
*) &indexRow
[col
]);
1278 _mesa_pack_index_span(ctx
, width
, type
, dest
,
1279 indexRow
, &ctx
->Pack
,
1280 0 /* no image transfer */);
1282 else if (format
== GL_DEPTH_COMPONENT
) {
1283 GLfloat depthRow
[MAX_WIDTH
];
1285 for (col
= 0; col
< width
; col
++) {
1286 (*texImage
->FetchTexel
)(texImage
, col
, row
, img
,
1287 (GLvoid
*) &depthRow
[col
]);
1289 _mesa_pack_depth_span(ctx
, width
, dest
, type
,
1290 depthRow
, &ctx
->Pack
);
1293 /* general case: convert row to RGBA format */
1294 GLchan rgba
[MAX_WIDTH
][4];
1296 for (col
= 0; col
< width
; col
++) {
1297 (*texImage
->FetchTexel
)(texImage
, col
, row
, img
,
1298 (GLvoid
*) rgba
[col
]);
1300 _mesa_pack_rgba_span(ctx
, width
, (const GLchan (*)[4])rgba
,
1301 format
, type
, dest
, &ctx
->Pack
,
1302 0 /* no image transfer */);
1312 * Called from the API. Note that width includes the border.
1315 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
1316 GLsizei width
, GLint border
, GLenum format
,
1317 GLenum type
, const GLvoid
*pixels
)
1319 GLsizei postConvWidth
= width
;
1320 GET_CURRENT_CONTEXT(ctx
);
1321 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1323 if (is_color_format(internalFormat
)) {
1324 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
1327 if (target
== GL_TEXTURE_1D
) {
1328 struct gl_texture_unit
*texUnit
;
1329 struct gl_texture_object
*texObj
;
1330 struct gl_texture_image
*texImage
;
1332 if (texture_error_check(ctx
, target
, level
, internalFormat
,
1333 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
1334 return; /* error was recorded */
1337 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1338 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1339 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1342 texImage
= _mesa_alloc_texture_image();
1343 texObj
->Image
[level
] = texImage
;
1345 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
1349 else if (texImage
->Data
) {
1350 /* free the old texture data */
1351 FREE(texImage
->Data
);
1352 texImage
->Data
= NULL
;
1354 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1355 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
, 1, 1,
1356 border
, internalFormat
);
1358 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1359 _mesa_update_state(ctx
);
1361 ASSERT(ctx
->Driver
.TexImage1D
);
1363 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
1364 width
, border
, format
, type
, pixels
,
1365 &ctx
->Unpack
, texObj
, texImage
);
1368 GLubyte
*dummy
= make_null_texture(width
, 1, 1, format
);
1370 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
1372 format
, GL_UNSIGNED_BYTE
, dummy
,
1373 &_mesa_native_packing
, texObj
, texImage
);
1378 ASSERT(texImage
->TexFormat
);
1379 if (!texImage
->FetchTexel
) {
1380 /* If driver didn't explicitly set this, use the default */
1381 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel1D
;
1383 ASSERT(texImage
->FetchTexel
);
1385 if (texImage
->IsCompressed
) {
1386 ASSERT(texImage
->CompressedSize
> 0);
1390 texObj
->Complete
= GL_FALSE
;
1391 ctx
->NewState
|= _NEW_TEXTURE
;
1393 else if (target
== GL_PROXY_TEXTURE_1D
) {
1394 /* Proxy texture: check for errors and update proxy state */
1395 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
1397 postConvWidth
, 1, 1, border
);
1399 struct gl_texture_unit
*texUnit
;
1400 struct gl_texture_image
*texImage
;
1401 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1402 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1403 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
, 1, 1,
1404 border
, internalFormat
);
1405 ASSERT(ctx
->Driver
.TestProxyTexImage
);
1406 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
1407 internalFormat
, format
, type
,
1408 postConvWidth
, 1, 1, border
);
1411 /* if error, clear all proxy texture image parameters */
1412 if (level
>= 0 && level
< ctx
->Const
.MaxTextureLevels
) {
1413 clear_teximage_fields(ctx
->Texture
.Proxy1D
->Image
[level
]);
1418 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1425 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
1426 GLsizei width
, GLsizei height
, GLint border
,
1427 GLenum format
, GLenum type
,
1428 const GLvoid
*pixels
)
1430 GLsizei postConvWidth
= width
, postConvHeight
= height
;
1431 GET_CURRENT_CONTEXT(ctx
);
1432 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1434 if (is_color_format(internalFormat
)) {
1435 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
1439 if (target
== GL_TEXTURE_2D
||
1440 (ctx
->Extensions
.ARB_texture_cube_map
&&
1441 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1442 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1443 /* non-proxy target */
1444 struct gl_texture_unit
*texUnit
;
1445 struct gl_texture_object
*texObj
;
1446 struct gl_texture_image
*texImage
;
1448 if (texture_error_check(ctx
, target
, level
, internalFormat
,
1449 format
, type
, 2, postConvWidth
, postConvHeight
,
1451 return; /* error was recorded */
1454 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1455 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1456 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1459 texImage
= _mesa_alloc_texture_image();
1460 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
1462 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1466 else if (texImage
->Data
) {
1467 /* free the old texture data */
1468 FREE(texImage
->Data
);
1469 texImage
->Data
= NULL
;
1471 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1472 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
, postConvHeight
,
1473 1, border
, internalFormat
);
1475 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1476 _mesa_update_state(ctx
);
1478 ASSERT(ctx
->Driver
.TexImage2D
);
1480 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
1481 width
, height
, border
, format
, type
, pixels
,
1482 &ctx
->Unpack
, texObj
, texImage
);
1485 GLubyte
*dummy
= make_null_texture(width
, height
, 1, format
);
1487 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
1488 width
, height
, border
,
1489 format
, GL_UNSIGNED_BYTE
, dummy
,
1490 &_mesa_native_packing
, texObj
, texImage
);
1495 ASSERT(texImage
->TexFormat
);
1496 if (!texImage
->FetchTexel
) {
1497 /* If driver didn't explicitly set this, use the default */
1498 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel2D
;
1500 ASSERT(texImage
->FetchTexel
);
1502 if (texImage
->IsCompressed
) {
1503 ASSERT(texImage
->CompressedSize
> 0);
1507 texObj
->Complete
= GL_FALSE
;
1508 ctx
->NewState
|= _NEW_TEXTURE
;
1510 else if (target
== GL_PROXY_TEXTURE_2D
) {
1511 /* Proxy texture: check for errors and update proxy state */
1512 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
1514 postConvWidth
, postConvHeight
, 1, border
);
1516 struct gl_texture_unit
*texUnit
;
1517 struct gl_texture_image
*texImage
;
1518 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1519 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1520 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
,
1521 postConvHeight
, 1, border
, internalFormat
);
1522 ASSERT(ctx
->Driver
.TestProxyTexImage
);
1523 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
1524 internalFormat
, format
, type
,
1525 postConvWidth
, postConvHeight
, 1, border
);
1528 /* if error, clear all proxy texture image parameters */
1529 const GLint maxLevels
= (target
== GL_PROXY_TEXTURE_2D
) ?
1530 ctx
->Const
.MaxTextureLevels
: ctx
->Const
.MaxCubeTextureLevels
;
1531 if (level
>= 0 && level
< maxLevels
) {
1532 clear_teximage_fields(ctx
->Texture
.Proxy2D
->Image
[level
]);
1537 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
1544 * Called by the API or display list executor.
1545 * Note that width and height include the border.
1548 _mesa_TexImage3D( GLenum target
, GLint level
, GLenum internalFormat
,
1549 GLsizei width
, GLsizei height
, GLsizei depth
,
1550 GLint border
, GLenum format
, GLenum type
,
1551 const GLvoid
*pixels
)
1553 GET_CURRENT_CONTEXT(ctx
);
1554 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1556 if (target
== GL_TEXTURE_3D
) {
1557 struct gl_texture_unit
*texUnit
;
1558 struct gl_texture_object
*texObj
;
1559 struct gl_texture_image
*texImage
;
1561 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
1562 format
, type
, 3, width
, height
, depth
, border
)) {
1563 return; /* error was recorded */
1566 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1567 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1568 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1571 texImage
= _mesa_alloc_texture_image();
1572 texObj
->Image
[level
] = texImage
;
1574 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
1578 else if (texImage
->Data
) {
1579 FREE(texImage
->Data
);
1580 texImage
->Data
= NULL
;
1582 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1583 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
, border
,
1586 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1587 _mesa_update_state(ctx
);
1589 ASSERT(ctx
->Driver
.TexImage3D
);
1591 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, (GLint
) internalFormat
,
1592 width
, height
, depth
, border
,
1593 format
, type
, pixels
,
1594 &ctx
->Unpack
, texObj
, texImage
);
1597 GLubyte
*dummy
= make_null_texture(width
, height
, depth
, format
);
1599 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
,
1600 (GLint
) internalFormat
,
1601 width
, height
, depth
, border
,
1602 format
, GL_UNSIGNED_BYTE
, dummy
,
1603 &_mesa_native_packing
, texObj
, texImage
);
1608 ASSERT(texImage
->TexFormat
);
1609 if (!texImage
->FetchTexel
) {
1610 /* If driver didn't explicitly set this, use the default */
1611 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel3D
;
1613 ASSERT(texImage
->FetchTexel
);
1615 if (texImage
->IsCompressed
) {
1616 ASSERT(texImage
->CompressedSize
> 0);
1620 texObj
->Complete
= GL_FALSE
;
1621 ctx
->NewState
|= _NEW_TEXTURE
;
1623 else if (target
== GL_PROXY_TEXTURE_3D
) {
1624 /* Proxy texture: check for errors and update proxy state */
1625 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
1626 format
, type
, 3, width
, height
, depth
, border
);
1628 struct gl_texture_unit
*texUnit
;
1629 struct gl_texture_image
*texImage
;
1630 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1631 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1632 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
1633 border
, internalFormat
);
1634 ASSERT(ctx
->Driver
.TestProxyTexImage
);
1635 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
1636 internalFormat
, format
, type
,
1637 width
, height
, depth
, border
);
1640 /* if error, clear all proxy texture image parameters */
1641 if (level
>= 0 && level
< ctx
->Const
.Max3DTextureLevels
) {
1642 clear_teximage_fields(ctx
->Texture
.Proxy3D
->Image
[level
]);
1647 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1654 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
1655 GLsizei width
, GLsizei height
, GLsizei depth
,
1656 GLint border
, GLenum format
, GLenum type
,
1657 const GLvoid
*pixels
)
1659 _mesa_TexImage3D(target
, level
, internalFormat
, width
, height
,
1660 depth
, border
, format
, type
, pixels
);
1666 _mesa_TexSubImage1D( GLenum target
, GLint level
,
1667 GLint xoffset
, GLsizei width
,
1668 GLenum format
, GLenum type
,
1669 const GLvoid
*pixels
)
1671 GLsizei postConvWidth
= width
;
1672 struct gl_texture_unit
*texUnit
;
1673 struct gl_texture_object
*texObj
;
1674 struct gl_texture_image
*texImage
;
1675 GET_CURRENT_CONTEXT(ctx
);
1676 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1678 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1679 _mesa_update_state(ctx
);
1681 /* XXX should test internal format */
1682 if (is_color_format(format
)) {
1683 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
1686 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
1687 postConvWidth
, 1, 1, format
, type
)) {
1688 return; /* error was detected */
1691 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1692 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1693 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1696 if (width
== 0 || !pixels
)
1697 return; /* no-op, not an error */
1699 /* If we have a border, xoffset=-1 is legal. Bias by border width */
1700 xoffset
+= texImage
->Border
;
1702 ASSERT(ctx
->Driver
.TexSubImage1D
);
1703 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
1704 format
, type
, pixels
, &ctx
->Unpack
,
1706 ctx
->NewState
|= _NEW_TEXTURE
;
1711 _mesa_TexSubImage2D( GLenum target
, GLint level
,
1712 GLint xoffset
, GLint yoffset
,
1713 GLsizei width
, GLsizei height
,
1714 GLenum format
, GLenum type
,
1715 const GLvoid
*pixels
)
1717 GLsizei postConvWidth
= width
, postConvHeight
= height
;
1718 struct gl_texture_unit
*texUnit
;
1719 struct gl_texture_object
*texObj
;
1720 struct gl_texture_image
*texImage
;
1721 GET_CURRENT_CONTEXT(ctx
);
1722 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1724 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1725 _mesa_update_state(ctx
);
1727 /* XXX should test internal format */
1728 if (is_color_format(format
)) {
1729 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
1733 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
1734 postConvWidth
, postConvHeight
, 1, format
, type
)) {
1735 return; /* error was detected */
1738 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1739 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1740 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1743 if (width
== 0 || height
== 0 || !pixels
)
1744 return; /* no-op, not an error */
1746 /* If we have a border, xoffset=-1 is legal. Bias by border width */
1747 xoffset
+= texImage
->Border
;
1748 yoffset
+= texImage
->Border
;
1750 ASSERT(ctx
->Driver
.TexSubImage2D
);
1751 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
1752 width
, height
, format
, type
, pixels
,
1753 &ctx
->Unpack
, texObj
, texImage
);
1754 ctx
->NewState
|= _NEW_TEXTURE
;
1760 _mesa_TexSubImage3D( GLenum target
, GLint level
,
1761 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1762 GLsizei width
, GLsizei height
, GLsizei depth
,
1763 GLenum format
, GLenum type
,
1764 const GLvoid
*pixels
)
1766 struct gl_texture_unit
*texUnit
;
1767 struct gl_texture_object
*texObj
;
1768 struct gl_texture_image
*texImage
;
1769 GET_CURRENT_CONTEXT(ctx
);
1770 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1772 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1773 _mesa_update_state(ctx
);
1775 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
1776 width
, height
, depth
, format
, type
)) {
1777 return; /* error was detected */
1780 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1781 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1782 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1785 if (width
== 0 || height
== 0 || height
== 0 || !pixels
)
1786 return; /* no-op, not an error */
1788 /* If we have a border, xoffset=-1 is legal. Bias by border width */
1789 xoffset
+= texImage
->Border
;
1790 yoffset
+= texImage
->Border
;
1791 zoffset
+= texImage
->Border
;
1793 ASSERT(ctx
->Driver
.TexSubImage3D
);
1794 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
1795 xoffset
, yoffset
, zoffset
,
1796 width
, height
, depth
,
1797 format
, type
, pixels
,
1798 &ctx
->Unpack
, texObj
, texImage
);
1799 ctx
->NewState
|= _NEW_TEXTURE
;
1805 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
1806 GLenum internalFormat
,
1808 GLsizei width
, GLint border
)
1810 struct gl_texture_unit
*texUnit
;
1811 struct gl_texture_object
*texObj
;
1812 struct gl_texture_image
*texImage
;
1813 GLsizei postConvWidth
= width
;
1814 GET_CURRENT_CONTEXT(ctx
);
1815 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1817 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1818 _mesa_update_state(ctx
);
1820 if (is_color_format(internalFormat
)) {
1821 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
1824 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
1825 postConvWidth
, 1, border
))
1828 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1829 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1830 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1832 texImage
= _mesa_alloc_texture_image();
1833 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
1835 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
1839 else if (texImage
->Data
) {
1840 /* free the old texture data */
1841 FREE(texImage
->Data
);
1842 texImage
->Data
= NULL
;
1845 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1846 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
, 1, 1,
1847 border
, internalFormat
);
1850 ASSERT(ctx
->Driver
.CopyTexImage1D
);
1851 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
1852 x
, y
, width
, border
);
1854 ASSERT(texImage
->TexFormat
);
1855 if (!texImage
->FetchTexel
) {
1856 /* If driver didn't explicitly set this, use the default */
1857 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel1D
;
1859 ASSERT(texImage
->FetchTexel
);
1862 texObj
->Complete
= GL_FALSE
;
1863 ctx
->NewState
|= _NEW_TEXTURE
;
1869 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
1870 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1873 struct gl_texture_unit
*texUnit
;
1874 struct gl_texture_object
*texObj
;
1875 struct gl_texture_image
*texImage
;
1876 GLsizei postConvWidth
= width
, postConvHeight
= height
;
1877 GET_CURRENT_CONTEXT(ctx
);
1878 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1880 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1881 _mesa_update_state(ctx
);
1883 if (is_color_format(internalFormat
)) {
1884 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
1888 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
1889 postConvWidth
, postConvHeight
, border
))
1892 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1893 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1894 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1896 texImage
= _mesa_alloc_texture_image();
1897 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
1899 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
1903 else if (texImage
->Data
) {
1904 /* free the old texture data */
1905 FREE(texImage
->Data
);
1906 texImage
->Data
= NULL
;
1909 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1910 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
, postConvHeight
, 1,
1911 border
, internalFormat
);
1913 ASSERT(ctx
->Driver
.CopyTexImage2D
);
1914 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
1915 x
, y
, width
, height
, border
);
1917 ASSERT(texImage
->TexFormat
);
1918 if (!texImage
->FetchTexel
) {
1919 /* If driver didn't explicitly set this, use the default */
1920 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel2D
;
1922 ASSERT(texImage
->FetchTexel
);
1925 texObj
->Complete
= GL_FALSE
;
1926 ctx
->NewState
|= _NEW_TEXTURE
;
1932 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
1933 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
1935 struct gl_texture_unit
*texUnit
;
1936 struct gl_texture_object
*texObj
;
1937 struct gl_texture_image
*texImage
;
1938 GLsizei postConvWidth
= width
;
1939 GET_CURRENT_CONTEXT(ctx
);
1940 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1942 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1943 _mesa_update_state(ctx
);
1945 /* XXX should test internal format */
1946 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
1948 if (copytexsubimage_error_check(ctx
, 1, target
, level
,
1949 xoffset
, 0, 0, postConvWidth
, 1))
1952 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1953 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1954 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1956 /* If we have a border, xoffset=-1 is legal. Bias by border width */
1957 xoffset
+= texImage
->Border
;
1959 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
1960 (*ctx
->Driver
.CopyTexSubImage1D
)(ctx
, target
, level
, xoffset
, x
, y
, width
);
1961 ctx
->NewState
|= _NEW_TEXTURE
;
1967 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
1968 GLint xoffset
, GLint yoffset
,
1969 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
1971 struct gl_texture_unit
*texUnit
;
1972 struct gl_texture_object
*texObj
;
1973 struct gl_texture_image
*texImage
;
1974 GLsizei postConvWidth
= width
, postConvHeight
= height
;
1975 GET_CURRENT_CONTEXT(ctx
);
1976 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1978 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1979 _mesa_update_state(ctx
);
1981 /* XXX should test internal format */
1982 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
1984 if (copytexsubimage_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
1985 postConvWidth
, postConvHeight
))
1988 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1989 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1990 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1992 /* If we have a border, xoffset=-1 is legal. Bias by border width */
1993 xoffset
+= texImage
->Border
;
1994 yoffset
+= texImage
->Border
;
1996 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
1997 (*ctx
->Driver
.CopyTexSubImage2D
)(ctx
, target
, level
,
1998 xoffset
, yoffset
, x
, y
, width
, height
);
1999 ctx
->NewState
|= _NEW_TEXTURE
;
2005 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2006 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2007 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2009 struct gl_texture_unit
*texUnit
;
2010 struct gl_texture_object
*texObj
;
2011 struct gl_texture_image
*texImage
;
2012 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2013 GET_CURRENT_CONTEXT(ctx
);
2014 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2016 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2017 _mesa_update_state(ctx
);
2019 /* XXX should test internal format */
2020 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
2022 if (copytexsubimage_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
,
2023 zoffset
, postConvWidth
, postConvHeight
))
2026 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2027 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2028 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2030 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2031 xoffset
+= texImage
->Border
;
2032 yoffset
+= texImage
->Border
;
2033 zoffset
+= texImage
->Border
;
2035 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2036 (*ctx
->Driver
.CopyTexSubImage3D
)(ctx
, target
, level
,
2037 xoffset
, yoffset
, zoffset
,
2038 x
, y
, width
, height
);
2039 ctx
->NewState
|= _NEW_TEXTURE
;
2045 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
2046 GLenum internalFormat
, GLsizei width
,
2047 GLint border
, GLsizei imageSize
,
2050 GET_CURRENT_CONTEXT(ctx
);
2051 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2053 switch (internalFormat
) {
2054 case GL_COMPRESSED_ALPHA_ARB
:
2055 case GL_COMPRESSED_LUMINANCE_ARB
:
2056 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
2057 case GL_COMPRESSED_INTENSITY_ARB
:
2058 case GL_COMPRESSED_RGB_ARB
:
2059 case GL_COMPRESSED_RGBA_ARB
:
2060 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1DARB");
2063 /* silence compiler warning */
2067 if (target
== GL_TEXTURE_1D
) {
2068 struct gl_texture_unit
*texUnit
;
2069 struct gl_texture_object
*texObj
;
2070 struct gl_texture_image
*texImage
;
2072 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2073 GL_NONE
, GL_NONE
, 1, width
, 1, 1, border
)) {
2074 return; /* error in texture image was detected */
2077 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2078 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2079 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2082 texImage
= _mesa_alloc_texture_image();
2083 texObj
->Image
[level
] = texImage
;
2085 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1DARB");
2089 else if (texImage
->Data
) {
2090 FREE(texImage
->Data
);
2091 texImage
->Data
= NULL
;
2094 _mesa_init_teximage_fields(ctx
, texImage
, width
, 1, 1,
2095 border
, internalFormat
);
2097 if (ctx
->Extensions
.ARB_texture_compression
) {
2098 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
2099 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
2100 internalFormat
, width
, border
,
2103 ASSERT(texImage
->CompressedSize
> 0); /* sanity */
2107 texObj
->Complete
= GL_FALSE
;
2108 ctx
->NewState
|= _NEW_TEXTURE
;
2110 else if (target
== GL_PROXY_TEXTURE_1D
) {
2111 /* Proxy texture: check for errors and update proxy state */
2112 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
2113 GL_NONE
, GL_NONE
, 1, width
, 1, 1, border
);
2115 struct gl_texture_unit
*texUnit
;
2116 struct gl_texture_image
*texImage
;
2117 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2118 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2119 _mesa_init_teximage_fields(ctx
, texImage
, width
, 1, 1,
2120 border
, internalFormat
);
2121 ASSERT(ctx
->Driver
.TestProxyTexImage
);
2122 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
2123 internalFormat
, GL_NONE
, GL_NONE
,
2124 width
, 1, 1, border
);
2127 /* if error, clear all proxy texture image parameters */
2128 if (level
>= 0 && level
< ctx
->Const
.MaxTextureLevels
) {
2129 clear_teximage_fields(ctx
->Texture
.Proxy1D
->Image
[level
]);
2134 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1DARB(target)");
2141 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
2142 GLenum internalFormat
, GLsizei width
,
2143 GLsizei height
, GLint border
, GLsizei imageSize
,
2146 GET_CURRENT_CONTEXT(ctx
);
2147 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2149 switch (internalFormat
) {
2150 case GL_COMPRESSED_ALPHA_ARB
:
2151 case GL_COMPRESSED_LUMINANCE_ARB
:
2152 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
2153 case GL_COMPRESSED_INTENSITY_ARB
:
2154 case GL_COMPRESSED_RGB_ARB
:
2155 case GL_COMPRESSED_RGBA_ARB
:
2156 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2DARB");
2159 /* silence compiler warning */
2163 if (target
== GL_TEXTURE_2D
||
2164 (ctx
->Extensions
.ARB_texture_cube_map
&&
2165 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2166 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
2167 struct gl_texture_unit
*texUnit
;
2168 struct gl_texture_object
*texObj
;
2169 struct gl_texture_image
*texImage
;
2171 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2172 GL_NONE
, GL_NONE
, 1, width
, height
, 1, border
)) {
2173 return; /* error in texture image was detected */
2176 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2177 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2178 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2181 texImage
= _mesa_alloc_texture_image();
2182 texObj
->Image
[level
] = texImage
;
2184 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
2188 else if (texImage
->Data
) {
2189 FREE(texImage
->Data
);
2190 texImage
->Data
= NULL
;
2193 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1, border
,
2196 if (ctx
->Extensions
.ARB_texture_compression
) {
2197 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
2198 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
2199 internalFormat
, width
, height
,
2200 border
, imageSize
, data
,
2202 ASSERT(texImage
->CompressedSize
> 0); /* sanity */
2206 texObj
->Complete
= GL_FALSE
;
2207 ctx
->NewState
|= _NEW_TEXTURE
;
2209 else if (target
== GL_PROXY_TEXTURE_2D
) {
2210 /* Proxy texture: check for errors and update proxy state */
2211 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
2212 GL_NONE
, GL_NONE
, 2, width
, height
, 1, border
);
2214 struct gl_texture_unit
*texUnit
;
2215 struct gl_texture_image
*texImage
;
2216 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2217 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2218 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
2219 border
, internalFormat
);
2220 ASSERT(ctx
->Driver
.TestProxyTexImage
);
2221 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
2222 internalFormat
, GL_NONE
, GL_NONE
,
2223 width
, height
, 1, border
);
2226 /* if error, clear all proxy texture image parameters */
2227 const GLint maxLevels
= (target
== GL_PROXY_TEXTURE_2D
) ?
2228 ctx
->Const
.MaxTextureLevels
: ctx
->Const
.MaxCubeTextureLevels
;
2229 if (level
>= 0 && level
< maxLevels
) {
2230 clear_teximage_fields(ctx
->Texture
.Proxy2D
->Image
[level
]);
2235 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2DARB(target)");
2242 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
2243 GLenum internalFormat
, GLsizei width
,
2244 GLsizei height
, GLsizei depth
, GLint border
,
2245 GLsizei imageSize
, const GLvoid
*data
)
2247 GET_CURRENT_CONTEXT(ctx
);
2248 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2250 switch (internalFormat
) {
2251 case GL_COMPRESSED_ALPHA_ARB
:
2252 case GL_COMPRESSED_LUMINANCE_ARB
:
2253 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
2254 case GL_COMPRESSED_INTENSITY_ARB
:
2255 case GL_COMPRESSED_RGB_ARB
:
2256 case GL_COMPRESSED_RGBA_ARB
:
2257 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3DARB");
2260 /* silence compiler warning */
2264 if (target
== GL_TEXTURE_3D
) {
2265 struct gl_texture_unit
*texUnit
;
2266 struct gl_texture_object
*texObj
;
2267 struct gl_texture_image
*texImage
;
2269 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2270 GL_NONE
, GL_NONE
, 1, width
, height
, depth
, border
)) {
2271 return; /* error in texture image was detected */
2274 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2275 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2276 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2279 texImage
= _mesa_alloc_texture_image();
2280 texObj
->Image
[level
] = texImage
;
2282 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3DARB");
2286 else if (texImage
->Data
) {
2287 FREE(texImage
->Data
);
2288 texImage
->Data
= NULL
;
2291 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
, border
,
2294 if (ctx
->Extensions
.ARB_texture_compression
) {
2295 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
2296 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
2298 width
, height
, depth
,
2299 border
, imageSize
, data
,
2301 ASSERT(texImage
->CompressedSize
> 0); /* sanity */
2305 texObj
->Complete
= GL_FALSE
;
2306 ctx
->NewState
|= _NEW_TEXTURE
;
2308 else if (target
== GL_PROXY_TEXTURE_3D
) {
2309 /* Proxy texture: check for errors and update proxy state */
2310 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
2311 GL_NONE
, GL_NONE
, 1, width
, height
, depth
, border
);
2313 struct gl_texture_unit
*texUnit
;
2314 struct gl_texture_image
*texImage
;
2315 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2316 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2317 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
2318 border
, internalFormat
);
2319 ASSERT(ctx
->Driver
.TestProxyTexImage
);
2320 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
2321 internalFormat
, GL_NONE
, GL_NONE
,
2322 width
, height
, depth
, border
);
2325 /* if error, clear all proxy texture image parameters */
2326 if (level
>= 0 && level
< ctx
->Const
.Max3DTextureLevels
) {
2327 clear_teximage_fields(ctx
->Texture
.Proxy3D
->Image
[level
]);
2332 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3DARB(target)");
2339 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
2340 GLsizei width
, GLenum format
,
2341 GLsizei imageSize
, const GLvoid
*data
)
2343 struct gl_texture_unit
*texUnit
;
2344 struct gl_texture_object
*texObj
;
2345 struct gl_texture_image
*texImage
;
2346 GET_CURRENT_CONTEXT(ctx
);
2347 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2349 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2350 width
, 1, 1, format
, GL_NONE
)) {
2351 return; /* error was detected */
2354 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2355 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2356 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2359 if (width
== 0 || !data
)
2360 return; /* no-op, not an error */
2362 if (ctx
->Driver
.CompressedTexSubImage1D
) {
2363 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
2365 format
, imageSize
, data
,
2368 ctx
->NewState
|= _NEW_TEXTURE
;
2373 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
2374 GLint yoffset
, GLsizei width
, GLsizei height
,
2375 GLenum format
, GLsizei imageSize
,
2378 struct gl_texture_unit
*texUnit
;
2379 struct gl_texture_object
*texObj
;
2380 struct gl_texture_image
*texImage
;
2381 GET_CURRENT_CONTEXT(ctx
);
2382 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2384 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2385 width
, height
, 1, format
, GL_NONE
)) {
2386 return; /* error was detected */
2389 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2390 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2391 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2394 if (width
== 0 || height
== 0 || !data
)
2395 return; /* no-op, not an error */
2397 if (ctx
->Driver
.CompressedTexSubImage2D
) {
2398 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
2399 xoffset
, yoffset
, width
, height
,
2400 format
, imageSize
, data
,
2403 ctx
->NewState
|= _NEW_TEXTURE
;
2408 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
2409 GLint yoffset
, GLint zoffset
, GLsizei width
,
2410 GLsizei height
, GLsizei depth
, GLenum format
,
2411 GLsizei imageSize
, const GLvoid
*data
)
2413 struct gl_texture_unit
*texUnit
;
2414 struct gl_texture_object
*texObj
;
2415 struct gl_texture_image
*texImage
;
2416 GET_CURRENT_CONTEXT(ctx
);
2417 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2419 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2420 width
, height
, depth
, format
, GL_NONE
)) {
2421 return; /* error was detected */
2424 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2425 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2426 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2429 if (width
== 0 || height
== 0 || depth
== 0 || !data
)
2430 return; /* no-op, not an error */
2432 if (ctx
->Driver
.CompressedTexSubImage3D
) {
2433 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
2434 xoffset
, yoffset
, zoffset
,
2435 width
, height
, depth
,
2436 format
, imageSize
, data
,
2439 ctx
->NewState
|= _NEW_TEXTURE
;
2444 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
2446 const struct gl_texture_unit
*texUnit
;
2447 const struct gl_texture_object
*texObj
;
2448 struct gl_texture_image
*texImage
;
2450 GET_CURRENT_CONTEXT(ctx
);
2451 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2453 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2454 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2456 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
2460 if (target
== GL_TEXTURE_1D
|| target
== GL_TEXTURE_2D
) {
2461 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2463 else if (target
== GL_TEXTURE_3D
) {
2464 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
2467 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2470 ASSERT(maxLevels
> 0);
2472 if (level
< 0 || level
>= maxLevels
) {
2473 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
2477 if (is_proxy_target(target
)) {
2478 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
2482 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2484 /* probably invalid mipmap level */
2485 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
2489 if (!texImage
->IsCompressed
) {
2490 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetCompressedTexImageARB");
2497 if (ctx
->Extensions
.ARB_texture_compression
) {
2498 ASSERT(ctx
->Driver
.GetCompressedTexImage
);
2499 (*ctx
->Driver
.GetCompressedTexImage
)(ctx
, target
, level
, img
, texObj
,