1 /* $Id: teximage.c,v 1.106 2001/11/18 22:48:13 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()");
511 #if 000 /* not used anymore */
513 * glTexImage[123]D can accept a NULL image pointer. In this case we
514 * create a texture image with unspecified image contents per the OpenGL
518 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
520 const GLint components
= _mesa_components_in_format(format
);
521 const GLint numPixels
= width
* height
* depth
;
522 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
526 * Let's see if anyone finds this. If glTexImage2D() is called with
527 * a NULL image pointer then load the texture image with something
528 * interesting instead of leaving it indeterminate.
531 static const char message
[8][32] = {
535 " X X XXXX XXX XXXXX ",
538 " X X XXXXX XXX X X ",
542 GLubyte
*imgPtr
= data
;
544 for (h
= 0; h
< depth
; h
++) {
545 for (i
= 0; i
< height
; i
++) {
546 GLint srcRow
= 7 - (i
% 8);
547 for (j
= 0; j
< width
; j
++) {
548 GLint srcCol
= j
% 32;
549 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
550 for (k
= 0; k
< components
; k
++) {
566 * Reset the fields of a gl_texture_image struct to zero.
567 * This is called when a proxy texture test fails, we set all the
568 * image members (except DriverData) to zero.
569 * It's also used in glTexImage[123]D as a safeguard to be sure all
570 * required fields get initialized properly by the Driver.TexImage[123]D
574 clear_teximage_fields(struct gl_texture_image
*img
)
590 img
->TexFormat
= &_mesa_null_texformat
;
591 img
->FetchTexel
= NULL
;
592 img
->IsCompressed
= 0;
593 img
->CompressedSize
= 0;
598 * Initialize basic fields of the gl_texture_image struct.
601 _mesa_init_teximage_fields(GLcontext
*ctx
,
602 struct gl_texture_image
*img
,
603 GLsizei width
, GLsizei height
, GLsizei depth
,
604 GLint border
, GLenum internalFormat
)
607 img
->Format
= _mesa_base_tex_format( ctx
, internalFormat
);
608 ASSERT(img
->Format
> 0);
609 img
->IntFormat
= internalFormat
;
610 img
->Border
= border
;
612 img
->Height
= height
;
614 img
->WidthLog2
= logbase2(width
- 2 * border
);
615 if (height
== 1) /* 1-D texture */
618 img
->HeightLog2
= logbase2(height
- 2 * border
);
619 if (depth
== 1) /* 2-D texture */
622 img
->DepthLog2
= logbase2(depth
- 2 * border
);
623 img
->Width2
= 1 << img
->WidthLog2
;
624 img
->Height2
= 1 << img
->HeightLog2
;
625 img
->Depth2
= 1 << img
->DepthLog2
;
626 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
627 img
->IsCompressed
= is_compressed_format(ctx
, internalFormat
);
633 * Test glTexImage[123]D() parameters for errors.
635 * dimensions - must be 1 or 2 or 3
636 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
639 texture_error_check( GLcontext
*ctx
, GLenum target
,
640 GLint level
, GLint internalFormat
,
641 GLenum format
, GLenum type
,
643 GLint width
, GLint height
,
644 GLint depth
, GLint border
)
648 GLint maxLevels
= 0, maxTextureSize
;
650 if (dimensions
== 1) {
651 isProxy
= (GLboolean
) (target
== GL_PROXY_TEXTURE_1D
);
652 if (target
!= GL_TEXTURE_1D
&& !isProxy
) {
653 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
656 maxLevels
= ctx
->Const
.MaxTextureLevels
;
658 else if (dimensions
== 2) {
659 isProxy
= (GLboolean
) (target
== GL_PROXY_TEXTURE_2D
||
660 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
);
661 if (target
!= GL_TEXTURE_2D
&& !isProxy
&&
662 !(ctx
->Extensions
.ARB_texture_cube_map
&&
663 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
664 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
665 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
668 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
)
669 maxLevels
= ctx
->Const
.MaxTextureLevels
;
671 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
673 else if (dimensions
== 3) {
674 isProxy
= (GLboolean
) (target
== GL_PROXY_TEXTURE_3D
);
675 if (target
!= GL_TEXTURE_3D
&& !isProxy
) {
676 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
679 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
682 _mesa_problem( ctx
, "bad dims in texture_error_check" );
686 ASSERT(maxLevels
> 0);
687 maxTextureSize
= 1 << (maxLevels
- 1);
690 if (border
!= 0 && border
!= 1) {
693 sprintf(message
, "glTexImage%dD(border=%d)", dimensions
, border
);
694 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
700 if (width
< 2 * border
|| width
> 2 + maxTextureSize
701 || logbase2( width
- 2 * border
) < 0) {
704 sprintf(message
, "glTexImage%dD(width=%d)", dimensions
, width
);
705 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
711 if (dimensions
>= 2) {
712 if (height
< 2 * border
|| height
> 2 + maxTextureSize
713 || logbase2( height
- 2 * border
) < 0) {
716 sprintf(message
, "glTexImage%dD(height=%d)", dimensions
, height
);
717 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
723 /* For cube map, width must equal height */
724 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
725 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
726 if (width
!= height
) {
728 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexImage2D(width != height)");
735 if (dimensions
>= 3) {
736 if (depth
< 2 * border
|| depth
> 2 + maxTextureSize
737 || logbase2( depth
- 2 * border
) < 0) {
740 sprintf(message
, "glTexImage3D(depth=%d)", depth
);
741 _mesa_error( ctx
, GL_INVALID_VALUE
, message
);
748 if (level
< 0 || level
>= maxLevels
) {
751 sprintf(message
, "glTexImage%dD(level=%d)", dimensions
, level
);
752 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
757 /* For cube map, width must equal height */
758 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
759 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
760 if (width
!= height
) {
761 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexImage2D(width != height)");
766 iformat
= _mesa_base_tex_format( ctx
, internalFormat
);
770 sprintf(message
, "glTexImage%dD(internalFormat=0x%x)", dimensions
,
772 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
779 if (!is_compressed_format( ctx
, internalFormat
) &&
780 !_mesa_is_legal_format_and_type( format
, type
)) {
781 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
782 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
786 sprintf(message
, "glTexImage%dD(format or type)", dimensions
);
787 _mesa_error(ctx
, GL_INVALID_OPERATION
, message
);
792 /* if we get here, the parameters are OK */
799 * Test glTexSubImage[123]D() parameters for errors.
801 * dimensions - must be 1 or 2 or 3
802 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
805 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
806 GLenum target
, GLint level
,
807 GLint xoffset
, GLint yoffset
, GLint zoffset
,
808 GLint width
, GLint height
, GLint depth
,
809 GLenum format
, GLenum type
)
811 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
812 struct gl_texture_image
*destTex
;
814 GLboolean compressed
;
816 if (dimensions
== 1) {
817 if (target
!= GL_TEXTURE_1D
) {
818 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
821 maxLevels
= ctx
->Const
.MaxTextureLevels
;
823 else if (dimensions
== 2) {
824 if (ctx
->Extensions
.ARB_texture_cube_map
) {
825 if ((target
< GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
||
826 target
> GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) &&
827 target
!= GL_TEXTURE_2D
) {
828 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
832 else if (target
!= GL_TEXTURE_2D
) {
833 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
836 if (target
== GL_PROXY_TEXTURE_2D
&& target
== GL_TEXTURE_2D
)
837 maxLevels
= ctx
->Const
.MaxTextureLevels
;
839 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
841 else if (dimensions
== 3) {
842 if (target
!= GL_TEXTURE_3D
) {
843 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
846 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
849 _mesa_problem( ctx
, "bad dims in texture_error_check" );
853 ASSERT(maxLevels
> 0);
855 if (level
< 0 || level
>= maxLevels
) {
857 sprintf(message
, "glTexSubImage2D(level=%d)", level
);
858 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
864 sprintf(message
, "glTexSubImage%dD(width=%d)", dimensions
, width
);
865 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
868 if (height
< 0 && dimensions
> 1) {
870 sprintf(message
, "glTexSubImage%dD(height=%d)", dimensions
, height
);
871 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
874 if (depth
< 0 && dimensions
> 2) {
876 sprintf(message
, "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
877 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
881 destTex
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
884 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage2D");
888 if (xoffset
< -((GLint
)destTex
->Border
)) {
889 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage1/2/3D(xoffset)");
892 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
893 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage1/2/3D(xoffset+width)");
896 if (dimensions
> 1) {
897 if (yoffset
< -((GLint
)destTex
->Border
)) {
898 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage2/3D(yoffset)");
901 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
902 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage2/3D(yoffset+height)");
906 if (dimensions
> 2) {
907 if (zoffset
< -((GLint
)destTex
->Border
)) {
908 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
911 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
912 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
917 compressed
= is_compressed_format(ctx
, destTex
->IntFormat
);
919 if (!compressed
&& !_mesa_is_legal_format_and_type(format
, type
)) {
921 sprintf(message
, "glTexSubImage%dD(format or type)", dimensions
);
922 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
927 if (xoffset
!= -((GLint
)destTex
->Border
)) {
928 _mesa_error(ctx
, GL_INVALID_OPERATION
,
929 "glTexSubImage1/2/3D(xoffset != -border");
932 if (dimensions
> 1 && yoffset
!= -((GLint
)destTex
->Border
)) {
933 _mesa_error(ctx
, GL_INVALID_OPERATION
,
934 "glTexSubImage2/3D(yoffset != -border");
937 if (dimensions
> 2 && zoffset
!= -((GLint
)destTex
->Border
)) {
938 _mesa_error(ctx
, GL_INVALID_OPERATION
,
939 "glTexSubImage3D(zoffset != -border");
949 * Test glCopyTexImage[12]D() parameters for errors.
950 * Input: dimensions - must be 1 or 2 or 3
951 * Return: GL_TRUE = an error was detected, GL_FALSE = no errors
954 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
955 GLenum target
, GLint level
, GLint internalFormat
,
956 GLint width
, GLint height
, GLint border
)
959 GLint maxLevels
= 0, maxTextureSize
;
961 if (dimensions
== 1) {
962 if (target
!= GL_TEXTURE_1D
) {
963 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
966 maxLevels
= ctx
->Const
.MaxTextureLevels
;
968 else if (dimensions
== 2) {
969 if (ctx
->Extensions
.ARB_texture_cube_map
) {
970 if ((target
< GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
||
971 target
> GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) &&
972 target
!= GL_TEXTURE_2D
) {
973 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
977 else if (target
!= GL_TEXTURE_2D
) {
978 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
981 if (target
== GL_PROXY_TEXTURE_2D
&& target
== GL_TEXTURE_2D
)
982 maxLevels
= ctx
->Const
.MaxTextureLevels
;
984 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
987 ASSERT(maxLevels
> 0);
988 maxTextureSize
= 1 << (maxLevels
- 1);
991 if (border
!= 0 && border
!= 1) {
993 sprintf(message
, "glCopyTexImage%dD(border)", dimensions
);
994 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
999 if (width
< 2 * border
|| width
> 2 + maxTextureSize
1000 || logbase2( width
- 2 * border
) < 0) {
1002 sprintf(message
, "glCopyTexImage%dD(width=%d)", dimensions
, width
);
1003 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1008 if (dimensions
>= 2) {
1009 if (height
< 2 * border
|| height
> 2 + maxTextureSize
1010 || logbase2( height
- 2 * border
) < 0) {
1012 sprintf(message
, "glCopyTexImage%dD(height=%d)", dimensions
, height
);
1013 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1018 /* For cube map, width must equal height */
1019 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1020 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1021 if (width
!= height
) {
1022 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCopyTexImage2D(width != height)");
1028 if (level
< 0 || level
>= maxLevels
) {
1030 sprintf(message
, "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1031 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1035 iformat
= _mesa_base_tex_format(ctx
, internalFormat
);
1038 sprintf(message
, "glCopyTexImage%dD(internalFormat)", dimensions
);
1039 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1043 /* if we get here, the parameters are OK */
1049 copytexsubimage_error_check( GLcontext
*ctx
, GLuint dimensions
,
1050 GLenum target
, GLint level
,
1051 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1052 GLsizei width
, GLsizei height
)
1054 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1055 struct gl_texture_image
*teximage
;
1056 GLint maxLevels
= 0;
1057 GLboolean compressed
;
1059 if (dimensions
== 1) {
1060 if (target
!= GL_TEXTURE_1D
) {
1061 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1064 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1066 else if (dimensions
== 2) {
1067 if (ctx
->Extensions
.ARB_texture_cube_map
) {
1068 if ((target
< GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
||
1069 target
> GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) &&
1070 target
!= GL_TEXTURE_2D
) {
1071 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1075 else if (target
!= GL_TEXTURE_2D
) {
1076 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1079 if (target
== GL_PROXY_TEXTURE_2D
&& target
== GL_TEXTURE_2D
)
1080 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1082 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1084 else if (dimensions
== 3) {
1085 if (target
!= GL_TEXTURE_3D
) {
1086 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1089 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
1092 ASSERT(maxLevels
> 0);
1094 if (level
< 0 || level
>= maxLevels
) {
1096 sprintf(message
, "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1097 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1103 sprintf(message
, "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1104 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1107 if (dimensions
> 1 && height
< 0) {
1109 sprintf(message
, "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1110 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1114 teximage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1117 sprintf(message
, "glCopyTexSubImage%dD(undefined texture)", dimensions
);
1118 _mesa_error(ctx
, GL_INVALID_OPERATION
, message
);
1122 if (xoffset
< -((GLint
)teximage
->Border
)) {
1124 sprintf(message
, "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1125 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1128 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1130 sprintf(message
, "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1131 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1134 if (dimensions
> 1) {
1135 if (yoffset
< -((GLint
)teximage
->Border
)) {
1137 sprintf(message
, "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1138 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1141 /* NOTE: we're adding the border here, not subtracting! */
1142 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1144 sprintf(message
, "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1145 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1150 if (dimensions
> 2) {
1151 if (zoffset
< -((GLint
)teximage
->Border
)) {
1153 sprintf(message
, "glCopyTexSubImage%dD(zoffset)", dimensions
);
1154 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1157 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1159 sprintf(message
, "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1160 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1165 compressed
= is_compressed_format(ctx
, teximage
->IntFormat
);
1167 if (xoffset
!= -((GLint
)teximage
->Border
)) {
1168 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1169 "glCopyTexSubImage1/2/3D(xoffset != -border");
1172 if (dimensions
> 1 && yoffset
!= -((GLint
)teximage
->Border
)) {
1173 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1174 "glCopyTexSubImage2/3D(yoffset != -border");
1177 if (dimensions
> 2 && zoffset
!= -((GLint
)teximage
->Border
)) {
1178 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1179 "glCopyTexSubImage3D(zoffset != -border");
1184 /* if we get here, the parameters are OK */
1191 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
1192 GLenum type
, GLvoid
*pixels
)
1194 const struct gl_texture_unit
*texUnit
;
1195 const struct gl_texture_object
*texObj
;
1196 struct gl_texture_image
*texImage
;
1197 GLint maxLevels
= 0;
1198 GET_CURRENT_CONTEXT(ctx
);
1199 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1201 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
1202 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1203 if (!texObj
|| is_proxy_target(target
)) {
1204 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
1208 if (target
== GL_TEXTURE_1D
|| target
== GL_TEXTURE_2D
) {
1209 maxLevels
= ctx
->Const
.MaxTextureLevels
;
1211 else if (target
== GL_TEXTURE_3D
) {
1212 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
1215 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
1218 ASSERT(maxLevels
> 0);
1220 if (level
< 0 || level
>= maxLevels
) {
1221 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
1225 if (_mesa_sizeof_type(type
) <= 0) {
1226 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
1230 if (_mesa_components_in_format(format
) <= 0 ||
1231 format
== GL_STENCIL_INDEX
) {
1232 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
1236 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
1237 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
1240 if (!ctx
->Extensions
.SGIX_depth_texture
&& format
== GL_DEPTH_COMPONENT
) {
1241 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
1244 /* XXX what if format/type doesn't match texture format/type? */
1249 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1251 /* invalid mipmap level, not an error */
1255 if (!texImage
->Data
) {
1256 /* no image data, not an error */
1261 const GLint width
= texImage
->Width
;
1262 const GLint height
= texImage
->Height
;
1263 const GLint depth
= texImage
->Depth
;
1265 for (img
= 0; img
< depth
; img
++) {
1266 for (row
= 0; row
< height
; row
++) {
1267 /* compute destination address in client memory */
1268 GLvoid
*dest
= _mesa_image_address( &ctx
->Unpack
, pixels
,
1269 width
, height
, format
, type
,
1273 if (format
== GL_COLOR_INDEX
) {
1274 GLuint indexRow
[MAX_WIDTH
];
1276 for (col
= 0; col
< width
; col
++) {
1277 (*texImage
->FetchTexel
)(texImage
, col
, row
, img
,
1278 (GLvoid
*) &indexRow
[col
]);
1280 _mesa_pack_index_span(ctx
, width
, type
, dest
,
1281 indexRow
, &ctx
->Pack
,
1282 0 /* no image transfer */);
1284 else if (format
== GL_DEPTH_COMPONENT
) {
1285 GLfloat depthRow
[MAX_WIDTH
];
1287 for (col
= 0; col
< width
; col
++) {
1288 (*texImage
->FetchTexel
)(texImage
, col
, row
, img
,
1289 (GLvoid
*) &depthRow
[col
]);
1291 _mesa_pack_depth_span(ctx
, width
, dest
, type
,
1292 depthRow
, &ctx
->Pack
);
1295 /* general case: convert row to RGBA format */
1296 GLchan rgba
[MAX_WIDTH
][4];
1298 for (col
= 0; col
< width
; col
++) {
1299 (*texImage
->FetchTexel
)(texImage
, col
, row
, img
,
1300 (GLvoid
*) rgba
[col
]);
1302 _mesa_pack_rgba_span(ctx
, width
, (const GLchan (*)[4])rgba
,
1303 format
, type
, dest
, &ctx
->Pack
,
1304 0 /* no image transfer */);
1314 * Called from the API. Note that width includes the border.
1317 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
1318 GLsizei width
, GLint border
, GLenum format
,
1319 GLenum type
, const GLvoid
*pixels
)
1321 GLsizei postConvWidth
= width
;
1322 GET_CURRENT_CONTEXT(ctx
);
1323 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1325 if (is_color_format(internalFormat
)) {
1326 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
1329 if (target
== GL_TEXTURE_1D
) {
1330 struct gl_texture_unit
*texUnit
;
1331 struct gl_texture_object
*texObj
;
1332 struct gl_texture_image
*texImage
;
1334 if (texture_error_check(ctx
, target
, level
, internalFormat
,
1335 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
1336 return; /* error was recorded */
1339 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1340 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1341 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1344 texImage
= _mesa_alloc_texture_image();
1345 texObj
->Image
[level
] = texImage
;
1347 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
1351 else if (texImage
->Data
) {
1352 /* free the old texture data */
1353 FREE(texImage
->Data
);
1354 texImage
->Data
= NULL
;
1356 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1357 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
, 1, 1,
1358 border
, internalFormat
);
1360 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1361 _mesa_update_state(ctx
);
1363 ASSERT(ctx
->Driver
.TexImage1D
);
1365 #if 0 /* don't make default teximage anymore */
1367 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
1368 width
, border
, format
, type
, pixels
,
1369 &ctx
->Unpack
, texObj
, texImage
);
1372 GLubyte
*dummy
= make_null_texture(width
, 1, 1, format
);
1374 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
1376 format
, GL_UNSIGNED_BYTE
, dummy
,
1377 &_mesa_native_packing
, texObj
, texImage
);
1382 /* <pixels> may be null! */
1383 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
1384 width
, border
, format
, type
, pixels
,
1385 &ctx
->Unpack
, texObj
, texImage
);
1388 ASSERT(texImage
->TexFormat
);
1389 if (!texImage
->FetchTexel
) {
1390 /* If driver didn't explicitly set this, use the default */
1391 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel1D
;
1393 ASSERT(texImage
->FetchTexel
);
1395 if (texImage
->IsCompressed
) {
1396 ASSERT(texImage
->CompressedSize
> 0);
1400 texObj
->Complete
= GL_FALSE
;
1401 ctx
->NewState
|= _NEW_TEXTURE
;
1403 else if (target
== GL_PROXY_TEXTURE_1D
) {
1404 /* Proxy texture: check for errors and update proxy state */
1405 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
1407 postConvWidth
, 1, 1, border
);
1409 struct gl_texture_unit
*texUnit
;
1410 struct gl_texture_image
*texImage
;
1411 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1412 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1413 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
, 1, 1,
1414 border
, internalFormat
);
1415 ASSERT(ctx
->Driver
.TestProxyTexImage
);
1416 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
1417 internalFormat
, format
, type
,
1418 postConvWidth
, 1, 1, border
);
1421 /* if error, clear all proxy texture image parameters */
1422 if (level
>= 0 && level
< ctx
->Const
.MaxTextureLevels
) {
1423 clear_teximage_fields(ctx
->Texture
.Proxy1D
->Image
[level
]);
1428 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1435 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
1436 GLsizei width
, GLsizei height
, GLint border
,
1437 GLenum format
, GLenum type
,
1438 const GLvoid
*pixels
)
1440 GLsizei postConvWidth
= width
, postConvHeight
= height
;
1441 GET_CURRENT_CONTEXT(ctx
);
1442 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1444 if (is_color_format(internalFormat
)) {
1445 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
1449 if (target
== GL_TEXTURE_2D
||
1450 (ctx
->Extensions
.ARB_texture_cube_map
&&
1451 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1452 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1453 /* non-proxy target */
1454 struct gl_texture_unit
*texUnit
;
1455 struct gl_texture_object
*texObj
;
1456 struct gl_texture_image
*texImage
;
1458 if (texture_error_check(ctx
, target
, level
, internalFormat
,
1459 format
, type
, 2, postConvWidth
, postConvHeight
,
1461 return; /* error was recorded */
1464 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1465 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1466 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1469 texImage
= _mesa_alloc_texture_image();
1470 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
1472 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
1476 else if (texImage
->Data
) {
1477 /* free the old texture data */
1478 FREE(texImage
->Data
);
1479 texImage
->Data
= NULL
;
1481 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1482 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
, postConvHeight
,
1483 1, border
, internalFormat
);
1485 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1486 _mesa_update_state(ctx
);
1488 ASSERT(ctx
->Driver
.TexImage2D
);
1490 #if 0 /* don't make default teximage anymore */
1492 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
1493 width
, height
, border
, format
, type
, pixels
,
1494 &ctx
->Unpack
, texObj
, texImage
);
1497 GLubyte
*dummy
= make_null_texture(width
, height
, 1, format
);
1499 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
1500 width
, height
, border
,
1501 format
, GL_UNSIGNED_BYTE
, dummy
,
1502 &_mesa_native_packing
, texObj
, texImage
);
1507 /* <pixels> may be null! */
1508 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
1509 width
, height
, border
, format
, type
, pixels
,
1510 &ctx
->Unpack
, texObj
, texImage
);
1513 ASSERT(texImage
->TexFormat
);
1514 if (!texImage
->FetchTexel
) {
1515 /* If driver didn't explicitly set this, use the default */
1516 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel2D
;
1518 ASSERT(texImage
->FetchTexel
);
1520 if (texImage
->IsCompressed
) {
1521 ASSERT(texImage
->CompressedSize
> 0);
1525 texObj
->Complete
= GL_FALSE
;
1526 ctx
->NewState
|= _NEW_TEXTURE
;
1528 else if (target
== GL_PROXY_TEXTURE_2D
||
1529 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
1530 ctx
->Extensions
.ARB_texture_cube_map
)) {
1531 /* Proxy texture: check for errors and update proxy state */
1532 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
1534 postConvWidth
, postConvHeight
, 1, border
);
1536 struct gl_texture_unit
*texUnit
;
1537 struct gl_texture_image
*texImage
;
1538 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1539 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1540 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
,
1541 postConvHeight
, 1, border
, internalFormat
);
1542 ASSERT(ctx
->Driver
.TestProxyTexImage
);
1543 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
1544 internalFormat
, format
, type
,
1545 postConvWidth
, postConvHeight
, 1, border
);
1548 /* if error, clear all proxy texture image parameters */
1549 const GLint maxLevels
= (target
== GL_PROXY_TEXTURE_2D
) ?
1550 ctx
->Const
.MaxTextureLevels
: ctx
->Const
.MaxCubeTextureLevels
;
1551 if (level
>= 0 && level
< maxLevels
) {
1552 clear_teximage_fields(ctx
->Texture
.Proxy2D
->Image
[level
]);
1557 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
1564 * Called by the API or display list executor.
1565 * Note that width and height include the border.
1568 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
1569 GLsizei width
, GLsizei height
, GLsizei depth
,
1570 GLint border
, GLenum format
, GLenum type
,
1571 const GLvoid
*pixels
)
1573 GET_CURRENT_CONTEXT(ctx
);
1574 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1576 if (target
== GL_TEXTURE_3D
) {
1577 struct gl_texture_unit
*texUnit
;
1578 struct gl_texture_object
*texObj
;
1579 struct gl_texture_image
*texImage
;
1581 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
1582 format
, type
, 3, width
, height
, depth
, border
)) {
1583 return; /* error was recorded */
1586 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1587 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1588 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1591 texImage
= _mesa_alloc_texture_image();
1592 texObj
->Image
[level
] = texImage
;
1594 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
1598 else if (texImage
->Data
) {
1599 FREE(texImage
->Data
);
1600 texImage
->Data
= NULL
;
1602 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1603 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
, border
,
1606 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1607 _mesa_update_state(ctx
);
1609 ASSERT(ctx
->Driver
.TexImage3D
);
1611 #if 0 /* don't make default teximage anymore */
1613 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, (GLint
) internalFormat
,
1614 width
, height
, depth
, border
,
1615 format
, type
, pixels
,
1616 &ctx
->Unpack
, texObj
, texImage
);
1619 GLubyte
*dummy
= make_null_texture(width
, height
, depth
, format
);
1621 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
,
1622 (GLint
) internalFormat
,
1623 width
, height
, depth
, border
,
1624 format
, GL_UNSIGNED_BYTE
, dummy
,
1625 &_mesa_native_packing
, texObj
, texImage
);
1630 /* <pixels> may be null! */
1631 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
1632 width
, height
, depth
, border
, format
, type
,
1633 pixels
, &ctx
->Unpack
, texObj
, texImage
);
1636 ASSERT(texImage
->TexFormat
);
1637 if (!texImage
->FetchTexel
) {
1638 /* If driver didn't explicitly set this, use the default */
1639 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel3D
;
1641 ASSERT(texImage
->FetchTexel
);
1643 if (texImage
->IsCompressed
) {
1644 ASSERT(texImage
->CompressedSize
> 0);
1648 texObj
->Complete
= GL_FALSE
;
1649 ctx
->NewState
|= _NEW_TEXTURE
;
1651 else if (target
== GL_PROXY_TEXTURE_3D
) {
1652 /* Proxy texture: check for errors and update proxy state */
1653 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
1654 format
, type
, 3, width
, height
, depth
, border
);
1656 struct gl_texture_unit
*texUnit
;
1657 struct gl_texture_image
*texImage
;
1658 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1659 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1660 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
1661 border
, internalFormat
);
1662 ASSERT(ctx
->Driver
.TestProxyTexImage
);
1663 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
1664 internalFormat
, format
, type
,
1665 width
, height
, depth
, border
);
1668 /* if error, clear all proxy texture image parameters */
1669 if (level
>= 0 && level
< ctx
->Const
.Max3DTextureLevels
) {
1670 clear_teximage_fields(ctx
->Texture
.Proxy3D
->Image
[level
]);
1675 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1682 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
1683 GLsizei width
, GLsizei height
, GLsizei depth
,
1684 GLint border
, GLenum format
, GLenum type
,
1685 const GLvoid
*pixels
)
1687 _mesa_TexImage3D(target
, level
, internalFormat
, width
, height
,
1688 depth
, border
, format
, type
, pixels
);
1694 _mesa_TexSubImage1D( GLenum target
, GLint level
,
1695 GLint xoffset
, GLsizei width
,
1696 GLenum format
, GLenum type
,
1697 const GLvoid
*pixels
)
1699 GLsizei postConvWidth
= width
;
1700 struct gl_texture_unit
*texUnit
;
1701 struct gl_texture_object
*texObj
;
1702 struct gl_texture_image
*texImage
;
1703 GET_CURRENT_CONTEXT(ctx
);
1704 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1706 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1707 _mesa_update_state(ctx
);
1709 /* XXX should test internal format */
1710 if (is_color_format(format
)) {
1711 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
1714 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
1715 postConvWidth
, 1, 1, format
, type
)) {
1716 return; /* error was detected */
1719 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1720 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1721 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1724 if (width
== 0 || !pixels
)
1725 return; /* no-op, not an error */
1727 /* If we have a border, xoffset=-1 is legal. Bias by border width */
1728 xoffset
+= texImage
->Border
;
1730 ASSERT(ctx
->Driver
.TexSubImage1D
);
1731 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
1732 format
, type
, pixels
, &ctx
->Unpack
,
1734 ctx
->NewState
|= _NEW_TEXTURE
;
1739 _mesa_TexSubImage2D( GLenum target
, GLint level
,
1740 GLint xoffset
, GLint yoffset
,
1741 GLsizei width
, GLsizei height
,
1742 GLenum format
, GLenum type
,
1743 const GLvoid
*pixels
)
1745 GLsizei postConvWidth
= width
, postConvHeight
= height
;
1746 struct gl_texture_unit
*texUnit
;
1747 struct gl_texture_object
*texObj
;
1748 struct gl_texture_image
*texImage
;
1749 GET_CURRENT_CONTEXT(ctx
);
1750 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1752 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1753 _mesa_update_state(ctx
);
1755 /* XXX should test internal format */
1756 if (is_color_format(format
)) {
1757 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
1761 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
1762 postConvWidth
, postConvHeight
, 1, format
, type
)) {
1763 return; /* error was detected */
1766 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1767 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1768 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1771 if (width
== 0 || height
== 0 || !pixels
)
1772 return; /* no-op, not an error */
1774 /* If we have a border, xoffset=-1 is legal. Bias by border width */
1775 xoffset
+= texImage
->Border
;
1776 yoffset
+= texImage
->Border
;
1778 ASSERT(ctx
->Driver
.TexSubImage2D
);
1779 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
1780 width
, height
, format
, type
, pixels
,
1781 &ctx
->Unpack
, texObj
, texImage
);
1782 ctx
->NewState
|= _NEW_TEXTURE
;
1788 _mesa_TexSubImage3D( GLenum target
, GLint level
,
1789 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1790 GLsizei width
, GLsizei height
, GLsizei depth
,
1791 GLenum format
, GLenum type
,
1792 const GLvoid
*pixels
)
1794 struct gl_texture_unit
*texUnit
;
1795 struct gl_texture_object
*texObj
;
1796 struct gl_texture_image
*texImage
;
1797 GET_CURRENT_CONTEXT(ctx
);
1798 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1800 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1801 _mesa_update_state(ctx
);
1803 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
1804 width
, height
, depth
, format
, type
)) {
1805 return; /* error was detected */
1808 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1809 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1810 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1813 if (width
== 0 || height
== 0 || height
== 0 || !pixels
)
1814 return; /* no-op, not an error */
1816 /* If we have a border, xoffset=-1 is legal. Bias by border width */
1817 xoffset
+= texImage
->Border
;
1818 yoffset
+= texImage
->Border
;
1819 zoffset
+= texImage
->Border
;
1821 ASSERT(ctx
->Driver
.TexSubImage3D
);
1822 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
1823 xoffset
, yoffset
, zoffset
,
1824 width
, height
, depth
,
1825 format
, type
, pixels
,
1826 &ctx
->Unpack
, texObj
, texImage
);
1827 ctx
->NewState
|= _NEW_TEXTURE
;
1833 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
1834 GLenum internalFormat
,
1836 GLsizei width
, GLint border
)
1838 struct gl_texture_unit
*texUnit
;
1839 struct gl_texture_object
*texObj
;
1840 struct gl_texture_image
*texImage
;
1841 GLsizei postConvWidth
= width
;
1842 GET_CURRENT_CONTEXT(ctx
);
1843 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1845 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1846 _mesa_update_state(ctx
);
1848 if (is_color_format(internalFormat
)) {
1849 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
1852 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
1853 postConvWidth
, 1, border
))
1856 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1857 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1858 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1860 texImage
= _mesa_alloc_texture_image();
1861 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
1863 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
1867 else if (texImage
->Data
) {
1868 /* free the old texture data */
1869 FREE(texImage
->Data
);
1870 texImage
->Data
= NULL
;
1873 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1874 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
, 1, 1,
1875 border
, internalFormat
);
1878 ASSERT(ctx
->Driver
.CopyTexImage1D
);
1879 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
1880 x
, y
, width
, border
);
1882 ASSERT(texImage
->TexFormat
);
1883 if (!texImage
->FetchTexel
) {
1884 /* If driver didn't explicitly set this, use the default */
1885 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel1D
;
1887 ASSERT(texImage
->FetchTexel
);
1890 texObj
->Complete
= GL_FALSE
;
1891 ctx
->NewState
|= _NEW_TEXTURE
;
1897 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
1898 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
1901 struct gl_texture_unit
*texUnit
;
1902 struct gl_texture_object
*texObj
;
1903 struct gl_texture_image
*texImage
;
1904 GLsizei postConvWidth
= width
, postConvHeight
= height
;
1905 GET_CURRENT_CONTEXT(ctx
);
1906 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1908 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1909 _mesa_update_state(ctx
);
1911 if (is_color_format(internalFormat
)) {
1912 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
1916 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
1917 postConvWidth
, postConvHeight
, border
))
1920 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1921 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1922 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1924 texImage
= _mesa_alloc_texture_image();
1925 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
1927 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
1931 else if (texImage
->Data
) {
1932 /* free the old texture data */
1933 FREE(texImage
->Data
);
1934 texImage
->Data
= NULL
;
1937 clear_teximage_fields(texImage
); /* not really needed, but helpful */
1938 _mesa_init_teximage_fields(ctx
, texImage
, postConvWidth
, postConvHeight
, 1,
1939 border
, internalFormat
);
1941 ASSERT(ctx
->Driver
.CopyTexImage2D
);
1942 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
1943 x
, y
, width
, height
, border
);
1945 ASSERT(texImage
->TexFormat
);
1946 if (!texImage
->FetchTexel
) {
1947 /* If driver didn't explicitly set this, use the default */
1948 texImage
->FetchTexel
= texImage
->TexFormat
->FetchTexel2D
;
1950 ASSERT(texImage
->FetchTexel
);
1953 texObj
->Complete
= GL_FALSE
;
1954 ctx
->NewState
|= _NEW_TEXTURE
;
1960 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
1961 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
1963 struct gl_texture_unit
*texUnit
;
1964 struct gl_texture_object
*texObj
;
1965 struct gl_texture_image
*texImage
;
1966 GLsizei postConvWidth
= width
;
1967 GET_CURRENT_CONTEXT(ctx
);
1968 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
1970 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
1971 _mesa_update_state(ctx
);
1973 /* XXX should test internal format */
1974 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
1976 if (copytexsubimage_error_check(ctx
, 1, target
, level
,
1977 xoffset
, 0, 0, postConvWidth
, 1))
1980 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1981 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
1982 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
1984 /* If we have a border, xoffset=-1 is legal. Bias by border width */
1985 xoffset
+= texImage
->Border
;
1987 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
1988 (*ctx
->Driver
.CopyTexSubImage1D
)(ctx
, target
, level
, xoffset
, x
, y
, width
);
1989 ctx
->NewState
|= _NEW_TEXTURE
;
1995 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
1996 GLint xoffset
, GLint yoffset
,
1997 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
1999 struct gl_texture_unit
*texUnit
;
2000 struct gl_texture_object
*texObj
;
2001 struct gl_texture_image
*texImage
;
2002 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2003 GET_CURRENT_CONTEXT(ctx
);
2004 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2006 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2007 _mesa_update_state(ctx
);
2009 /* XXX should test internal format */
2010 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
2012 if (copytexsubimage_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2013 postConvWidth
, postConvHeight
))
2016 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2017 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2018 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2020 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2021 xoffset
+= texImage
->Border
;
2022 yoffset
+= texImage
->Border
;
2024 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2025 (*ctx
->Driver
.CopyTexSubImage2D
)(ctx
, target
, level
,
2026 xoffset
, yoffset
, x
, y
, width
, height
);
2027 ctx
->NewState
|= _NEW_TEXTURE
;
2033 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2034 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2035 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2037 struct gl_texture_unit
*texUnit
;
2038 struct gl_texture_object
*texObj
;
2039 struct gl_texture_image
*texImage
;
2040 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2041 GET_CURRENT_CONTEXT(ctx
);
2042 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2044 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2045 _mesa_update_state(ctx
);
2047 /* XXX should test internal format */
2048 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
2050 if (copytexsubimage_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
,
2051 zoffset
, postConvWidth
, postConvHeight
))
2054 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2055 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2056 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2058 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2059 xoffset
+= texImage
->Border
;
2060 yoffset
+= texImage
->Border
;
2061 zoffset
+= texImage
->Border
;
2063 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2064 (*ctx
->Driver
.CopyTexSubImage3D
)(ctx
, target
, level
,
2065 xoffset
, yoffset
, zoffset
,
2066 x
, y
, width
, height
);
2067 ctx
->NewState
|= _NEW_TEXTURE
;
2073 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
2074 GLenum internalFormat
, GLsizei width
,
2075 GLint border
, GLsizei imageSize
,
2078 GET_CURRENT_CONTEXT(ctx
);
2079 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2081 switch (internalFormat
) {
2082 case GL_COMPRESSED_ALPHA_ARB
:
2083 case GL_COMPRESSED_LUMINANCE_ARB
:
2084 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
2085 case GL_COMPRESSED_INTENSITY_ARB
:
2086 case GL_COMPRESSED_RGB_ARB
:
2087 case GL_COMPRESSED_RGBA_ARB
:
2088 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1DARB");
2091 /* silence compiler warning */
2095 if (target
== GL_TEXTURE_1D
) {
2096 struct gl_texture_unit
*texUnit
;
2097 struct gl_texture_object
*texObj
;
2098 struct gl_texture_image
*texImage
;
2100 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2101 GL_NONE
, GL_NONE
, 1, width
, 1, 1, border
)) {
2102 return; /* error in texture image was detected */
2105 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2106 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2107 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2110 texImage
= _mesa_alloc_texture_image();
2111 texObj
->Image
[level
] = texImage
;
2113 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1DARB");
2117 else if (texImage
->Data
) {
2118 FREE(texImage
->Data
);
2119 texImage
->Data
= NULL
;
2122 _mesa_init_teximage_fields(ctx
, texImage
, width
, 1, 1,
2123 border
, internalFormat
);
2125 if (ctx
->Extensions
.ARB_texture_compression
) {
2126 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
2127 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
2128 internalFormat
, width
, border
,
2131 ASSERT(texImage
->CompressedSize
> 0); /* sanity */
2135 texObj
->Complete
= GL_FALSE
;
2136 ctx
->NewState
|= _NEW_TEXTURE
;
2138 else if (target
== GL_PROXY_TEXTURE_1D
) {
2139 /* Proxy texture: check for errors and update proxy state */
2140 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
2141 GL_NONE
, GL_NONE
, 1, width
, 1, 1, border
);
2143 struct gl_texture_unit
*texUnit
;
2144 struct gl_texture_image
*texImage
;
2145 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2146 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2147 _mesa_init_teximage_fields(ctx
, texImage
, width
, 1, 1,
2148 border
, internalFormat
);
2149 ASSERT(ctx
->Driver
.TestProxyTexImage
);
2150 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
2151 internalFormat
, GL_NONE
, GL_NONE
,
2152 width
, 1, 1, border
);
2155 /* if error, clear all proxy texture image parameters */
2156 if (level
>= 0 && level
< ctx
->Const
.MaxTextureLevels
) {
2157 clear_teximage_fields(ctx
->Texture
.Proxy1D
->Image
[level
]);
2162 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1DARB(target)");
2169 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
2170 GLenum internalFormat
, GLsizei width
,
2171 GLsizei height
, GLint border
, GLsizei imageSize
,
2174 GET_CURRENT_CONTEXT(ctx
);
2175 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2177 switch (internalFormat
) {
2178 case GL_COMPRESSED_ALPHA_ARB
:
2179 case GL_COMPRESSED_LUMINANCE_ARB
:
2180 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
2181 case GL_COMPRESSED_INTENSITY_ARB
:
2182 case GL_COMPRESSED_RGB_ARB
:
2183 case GL_COMPRESSED_RGBA_ARB
:
2184 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2DARB");
2187 /* silence compiler warning */
2191 if (target
== GL_TEXTURE_2D
||
2192 (ctx
->Extensions
.ARB_texture_cube_map
&&
2193 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2194 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
2195 struct gl_texture_unit
*texUnit
;
2196 struct gl_texture_object
*texObj
;
2197 struct gl_texture_image
*texImage
;
2199 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2200 GL_NONE
, GL_NONE
, 1, width
, height
, 1, border
)) {
2201 return; /* error in texture image was detected */
2204 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2205 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2206 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2209 texImage
= _mesa_alloc_texture_image();
2210 texObj
->Image
[level
] = texImage
;
2212 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
2216 else if (texImage
->Data
) {
2217 FREE(texImage
->Data
);
2218 texImage
->Data
= NULL
;
2221 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1, border
,
2224 if (ctx
->Extensions
.ARB_texture_compression
) {
2225 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
2226 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
2227 internalFormat
, width
, height
,
2228 border
, imageSize
, data
,
2230 ASSERT(texImage
->CompressedSize
> 0); /* sanity */
2234 texObj
->Complete
= GL_FALSE
;
2235 ctx
->NewState
|= _NEW_TEXTURE
;
2237 else if (target
== GL_PROXY_TEXTURE_2D
) {
2238 /* Proxy texture: check for errors and update proxy state */
2239 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
2240 GL_NONE
, GL_NONE
, 2, width
, height
, 1, border
);
2242 struct gl_texture_unit
*texUnit
;
2243 struct gl_texture_image
*texImage
;
2244 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2245 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2246 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
2247 border
, internalFormat
);
2248 ASSERT(ctx
->Driver
.TestProxyTexImage
);
2249 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
2250 internalFormat
, GL_NONE
, GL_NONE
,
2251 width
, height
, 1, border
);
2254 /* if error, clear all proxy texture image parameters */
2255 const GLint maxLevels
= (target
== GL_PROXY_TEXTURE_2D
) ?
2256 ctx
->Const
.MaxTextureLevels
: ctx
->Const
.MaxCubeTextureLevels
;
2257 if (level
>= 0 && level
< maxLevels
) {
2258 clear_teximage_fields(ctx
->Texture
.Proxy2D
->Image
[level
]);
2263 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2DARB(target)");
2270 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
2271 GLenum internalFormat
, GLsizei width
,
2272 GLsizei height
, GLsizei depth
, GLint border
,
2273 GLsizei imageSize
, const GLvoid
*data
)
2275 GET_CURRENT_CONTEXT(ctx
);
2276 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2278 switch (internalFormat
) {
2279 case GL_COMPRESSED_ALPHA_ARB
:
2280 case GL_COMPRESSED_LUMINANCE_ARB
:
2281 case GL_COMPRESSED_LUMINANCE_ALPHA_ARB
:
2282 case GL_COMPRESSED_INTENSITY_ARB
:
2283 case GL_COMPRESSED_RGB_ARB
:
2284 case GL_COMPRESSED_RGBA_ARB
:
2285 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3DARB");
2288 /* silence compiler warning */
2292 if (target
== GL_TEXTURE_3D
) {
2293 struct gl_texture_unit
*texUnit
;
2294 struct gl_texture_object
*texObj
;
2295 struct gl_texture_image
*texImage
;
2297 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2298 GL_NONE
, GL_NONE
, 1, width
, height
, depth
, border
)) {
2299 return; /* error in texture image was detected */
2302 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2303 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2304 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2307 texImage
= _mesa_alloc_texture_image();
2308 texObj
->Image
[level
] = texImage
;
2310 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3DARB");
2314 else if (texImage
->Data
) {
2315 FREE(texImage
->Data
);
2316 texImage
->Data
= NULL
;
2319 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
, border
,
2322 if (ctx
->Extensions
.ARB_texture_compression
) {
2323 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
2324 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
2326 width
, height
, depth
,
2327 border
, imageSize
, data
,
2329 ASSERT(texImage
->CompressedSize
> 0); /* sanity */
2333 texObj
->Complete
= GL_FALSE
;
2334 ctx
->NewState
|= _NEW_TEXTURE
;
2336 else if (target
== GL_PROXY_TEXTURE_3D
) {
2337 /* Proxy texture: check for errors and update proxy state */
2338 GLenum error
= texture_error_check(ctx
, target
, level
, internalFormat
,
2339 GL_NONE
, GL_NONE
, 1, width
, height
, depth
, border
);
2341 struct gl_texture_unit
*texUnit
;
2342 struct gl_texture_image
*texImage
;
2343 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2344 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2345 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
2346 border
, internalFormat
);
2347 ASSERT(ctx
->Driver
.TestProxyTexImage
);
2348 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
2349 internalFormat
, GL_NONE
, GL_NONE
,
2350 width
, height
, depth
, border
);
2353 /* if error, clear all proxy texture image parameters */
2354 if (level
>= 0 && level
< ctx
->Const
.Max3DTextureLevels
) {
2355 clear_teximage_fields(ctx
->Texture
.Proxy3D
->Image
[level
]);
2360 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3DARB(target)");
2367 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
2368 GLsizei width
, GLenum format
,
2369 GLsizei imageSize
, const GLvoid
*data
)
2371 struct gl_texture_unit
*texUnit
;
2372 struct gl_texture_object
*texObj
;
2373 struct gl_texture_image
*texImage
;
2374 GET_CURRENT_CONTEXT(ctx
);
2375 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2377 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2378 width
, 1, 1, format
, GL_NONE
)) {
2379 return; /* error was detected */
2382 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2383 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2384 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2387 if (width
== 0 || !data
)
2388 return; /* no-op, not an error */
2390 if (ctx
->Driver
.CompressedTexSubImage1D
) {
2391 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
2393 format
, imageSize
, data
,
2396 ctx
->NewState
|= _NEW_TEXTURE
;
2401 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
2402 GLint yoffset
, GLsizei width
, GLsizei height
,
2403 GLenum format
, GLsizei imageSize
,
2406 struct gl_texture_unit
*texUnit
;
2407 struct gl_texture_object
*texObj
;
2408 struct gl_texture_image
*texImage
;
2409 GET_CURRENT_CONTEXT(ctx
);
2410 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2412 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2413 width
, height
, 1, format
, GL_NONE
)) {
2414 return; /* error was detected */
2417 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2418 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2419 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2422 if (width
== 0 || height
== 0 || !data
)
2423 return; /* no-op, not an error */
2425 if (ctx
->Driver
.CompressedTexSubImage2D
) {
2426 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
2427 xoffset
, yoffset
, width
, height
,
2428 format
, imageSize
, data
,
2431 ctx
->NewState
|= _NEW_TEXTURE
;
2436 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
2437 GLint yoffset
, GLint zoffset
, GLsizei width
,
2438 GLsizei height
, GLsizei depth
, GLenum format
,
2439 GLsizei imageSize
, const GLvoid
*data
)
2441 struct gl_texture_unit
*texUnit
;
2442 struct gl_texture_object
*texObj
;
2443 struct gl_texture_image
*texImage
;
2444 GET_CURRENT_CONTEXT(ctx
);
2445 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2447 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2448 width
, height
, depth
, format
, GL_NONE
)) {
2449 return; /* error was detected */
2452 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2453 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2454 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2457 if (width
== 0 || height
== 0 || depth
== 0 || !data
)
2458 return; /* no-op, not an error */
2460 if (ctx
->Driver
.CompressedTexSubImage3D
) {
2461 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
2462 xoffset
, yoffset
, zoffset
,
2463 width
, height
, depth
,
2464 format
, imageSize
, data
,
2467 ctx
->NewState
|= _NEW_TEXTURE
;
2472 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
2474 const struct gl_texture_unit
*texUnit
;
2475 const struct gl_texture_object
*texObj
;
2476 struct gl_texture_image
*texImage
;
2478 GET_CURRENT_CONTEXT(ctx
);
2479 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2481 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2482 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2484 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
2488 if (target
== GL_TEXTURE_1D
|| target
== GL_TEXTURE_2D
) {
2489 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2491 else if (target
== GL_TEXTURE_3D
) {
2492 maxLevels
= ctx
->Const
.Max3DTextureLevels
;
2495 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2498 ASSERT(maxLevels
> 0);
2500 if (level
< 0 || level
>= maxLevels
) {
2501 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
2505 if (is_proxy_target(target
)) {
2506 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
2510 texImage
= _mesa_select_tex_image(ctx
, texUnit
, target
, level
);
2512 /* probably invalid mipmap level */
2513 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
2517 if (!texImage
->IsCompressed
) {
2518 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetCompressedTexImageARB");
2525 if (ctx
->Extensions
.ARB_texture_compression
) {
2526 ASSERT(ctx
->Driver
.GetCompressedTexImage
);
2527 (*ctx
->Driver
.GetCompressedTexImage
)(ctx
, target
, level
, img
, texObj
,