2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
40 #include "framebuffer.h"
46 #include "texcompress.h"
47 #include "texformat.h"
55 * State changes which we care about for glCopyTex[Sub]Image() calls.
56 * In particular, we care about pixel transfer state and buffer state
57 * (such as glReadBuffer to make sure we read from the right renderbuffer).
59 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
66 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
70 _mesa_alloc_texmemory(GLsizei bytes
)
72 return _mesa_align_malloc(bytes
, 512);
77 * Free texture memory allocated with _mesa_alloc_texmemory()
80 _mesa_free_texmemory(void *m
)
89 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
91 #if CHAN_TYPE != GL_UNSIGNED_BYTE
92 _mesa_problem(NULL
, "PrintTexture not supported");
95 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
98 _mesa_printf("No texture data\n");
102 switch (img
->Format
) {
109 case GL_LUMINANCE_ALPHA
:
119 _mesa_problem(NULL
, "error in PrintTexture\n");
123 for (i
= 0; i
< img
->Height
; i
++) {
124 for (j
= 0; j
< img
->Width
; j
++) {
126 _mesa_printf("%02x ", data
[0]);
128 _mesa_printf("%02x%02x ", data
[0], data
[1]);
130 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
132 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
133 data
+= (img
->RowStride
- img
->Width
) * c
;
135 /* XXX use img->ImageStride here */
144 * Compute floor(log_base_2(n)).
145 * If n < 0 return -1.
174 * Return the simple base format for a given internal texture format.
175 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
177 * \param ctx GL context.
178 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
180 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
181 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
183 * This is the format which is used during texture application (i.e. the
184 * texture format and env mode determine the arithmetic used.
187 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
189 switch (internalFormat
) {
204 case GL_LUMINANCE_ALPHA
:
205 case GL_LUMINANCE4_ALPHA4
:
206 case GL_LUMINANCE6_ALPHA2
:
207 case GL_LUMINANCE8_ALPHA8
:
208 case GL_LUMINANCE12_ALPHA4
:
209 case GL_LUMINANCE12_ALPHA12
:
210 case GL_LUMINANCE16_ALPHA16
:
211 return GL_LUMINANCE_ALPHA
;
242 if (ctx
->Extensions
.EXT_paletted_texture
) {
243 switch (internalFormat
) {
245 case GL_COLOR_INDEX1_EXT
:
246 case GL_COLOR_INDEX2_EXT
:
247 case GL_COLOR_INDEX4_EXT
:
248 case GL_COLOR_INDEX8_EXT
:
249 case GL_COLOR_INDEX12_EXT
:
250 case GL_COLOR_INDEX16_EXT
:
251 return GL_COLOR_INDEX
;
257 if (ctx
->Extensions
.ARB_depth_texture
) {
258 switch (internalFormat
) {
259 case GL_DEPTH_COMPONENT
:
260 case GL_DEPTH_COMPONENT16
:
261 case GL_DEPTH_COMPONENT24
:
262 case GL_DEPTH_COMPONENT32
:
263 return GL_DEPTH_COMPONENT
;
269 switch (internalFormat
) {
270 case GL_COMPRESSED_ALPHA
:
272 case GL_COMPRESSED_LUMINANCE
:
274 case GL_COMPRESSED_LUMINANCE_ALPHA
:
275 return GL_LUMINANCE_ALPHA
;
276 case GL_COMPRESSED_INTENSITY
:
278 case GL_COMPRESSED_RGB
:
280 case GL_COMPRESSED_RGBA
:
286 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
287 switch (internalFormat
) {
288 case GL_COMPRESSED_RGB_FXT1_3DFX
:
290 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
297 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
298 switch (internalFormat
) {
299 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
301 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
302 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
303 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
310 if (ctx
->Extensions
.S3_s3tc
) {
311 switch (internalFormat
) {
323 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
324 if (internalFormat
== GL_YCBCR_MESA
)
325 return GL_YCBCR_MESA
;
328 if (ctx
->Extensions
.ARB_texture_float
) {
329 switch (internalFormat
) {
330 case GL_ALPHA16F_ARB
:
331 case GL_ALPHA32F_ARB
:
339 case GL_INTENSITY16F_ARB
:
340 case GL_INTENSITY32F_ARB
:
342 case GL_LUMINANCE16F_ARB
:
343 case GL_LUMINANCE32F_ARB
:
345 case GL_LUMINANCE_ALPHA16F_ARB
:
346 case GL_LUMINANCE_ALPHA32F_ARB
:
347 return GL_LUMINANCE_ALPHA
;
353 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
354 switch (internalFormat
) {
363 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
364 switch (internalFormat
) {
373 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
374 switch (internalFormat
) {
375 case GL_DEPTH_STENCIL_EXT
:
376 case GL_DEPTH24_STENCIL8_EXT
:
377 return GL_DEPTH_STENCIL_EXT
;
383 #if FEATURE_EXT_texture_sRGB
384 if (ctx
->Extensions
.EXT_texture_sRGB
) {
385 switch (internalFormat
) {
388 case GL_COMPRESSED_SRGB_EXT
:
389 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
391 case GL_SRGB_ALPHA_EXT
:
392 case GL_SRGB8_ALPHA8_EXT
:
393 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
394 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
395 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
396 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
398 case GL_SLUMINANCE_ALPHA_EXT
:
399 case GL_SLUMINANCE8_ALPHA8_EXT
:
400 case GL_COMPRESSED_SLUMINANCE_EXT
:
401 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
402 return GL_LUMINANCE_ALPHA
;
403 case GL_SLUMINANCE_EXT
:
404 case GL_SLUMINANCE8_EXT
:
411 #endif /* FEATURE_EXT_texture_sRGB */
413 return -1; /* error */
418 * Test if the given image format is a color/RGBA format (i.e., not color
419 * index, depth, stencil, etc).
420 * \param format the image format value (may by an internal texture format)
421 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
422 * XXX maybe move this func to image.c
425 _mesa_is_color_format(GLenum format
)
443 case GL_LUMINANCE_ALPHA
:
444 case GL_LUMINANCE4_ALPHA4
:
445 case GL_LUMINANCE6_ALPHA2
:
446 case GL_LUMINANCE8_ALPHA8
:
447 case GL_LUMINANCE12_ALPHA4
:
448 case GL_LUMINANCE12_ALPHA12
:
449 case GL_LUMINANCE16_ALPHA16
:
476 /* float texture formats */
477 case GL_ALPHA16F_ARB
:
478 case GL_ALPHA32F_ARB
:
479 case GL_LUMINANCE16F_ARB
:
480 case GL_LUMINANCE32F_ARB
:
481 case GL_LUMINANCE_ALPHA16F_ARB
:
482 case GL_LUMINANCE_ALPHA32F_ARB
:
483 case GL_INTENSITY16F_ARB
:
484 case GL_INTENSITY32F_ARB
:
489 /* compressed formats */
490 case GL_COMPRESSED_ALPHA
:
491 case GL_COMPRESSED_LUMINANCE
:
492 case GL_COMPRESSED_LUMINANCE_ALPHA
:
493 case GL_COMPRESSED_INTENSITY
:
494 case GL_COMPRESSED_RGB
:
495 case GL_COMPRESSED_RGBA
:
500 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
501 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
502 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
503 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
504 case GL_COMPRESSED_RGB_FXT1_3DFX
:
505 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
506 #if FEATURE_EXT_texture_sRGB
509 case GL_SRGB_ALPHA_EXT
:
510 case GL_SRGB8_ALPHA8_EXT
:
511 case GL_SLUMINANCE_ALPHA_EXT
:
512 case GL_SLUMINANCE8_ALPHA8_EXT
:
513 case GL_SLUMINANCE_EXT
:
514 case GL_SLUMINANCE8_EXT
:
515 case GL_COMPRESSED_SRGB_EXT
:
516 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
517 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
518 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
519 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
520 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
521 case GL_COMPRESSED_SLUMINANCE_EXT
:
522 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
523 #endif /* FEATURE_EXT_texture_sRGB */
525 /* signed texture formats */
529 case GL_YCBCR_MESA
: /* not considered to be RGB */
538 * Test if the given image format is a color index format.
541 is_index_format(GLenum format
)
545 case GL_COLOR_INDEX1_EXT
:
546 case GL_COLOR_INDEX2_EXT
:
547 case GL_COLOR_INDEX4_EXT
:
548 case GL_COLOR_INDEX8_EXT
:
549 case GL_COLOR_INDEX12_EXT
:
550 case GL_COLOR_INDEX16_EXT
:
559 * Test if the given image format is a depth component format.
562 is_depth_format(GLenum format
)
565 case GL_DEPTH_COMPONENT16
:
566 case GL_DEPTH_COMPONENT24
:
567 case GL_DEPTH_COMPONENT32
:
568 case GL_DEPTH_COMPONENT
:
577 * Test if the given image format is a YCbCr format.
580 is_ycbcr_format(GLenum format
)
592 * Test if the given image format is a Depth/Stencil format.
595 is_depthstencil_format(GLenum format
)
598 case GL_DEPTH24_STENCIL8_EXT
:
599 case GL_DEPTH_STENCIL_EXT
:
607 * Test if the given image format is a dudv format.
610 is_dudv_format(GLenum format
)
623 * Test if it is a supported compressed format.
625 * \param internalFormat the internal format token provided by the user.
627 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
628 * GL_FALSE otherwise.
630 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
634 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
636 GLint supported
[100]; /* 100 should be plenty */
639 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
641 for (i
= 0; i
< n
; i
++) {
642 if ((GLint
) internalFormat
== supported
[i
]) {
651 * For cube map faces, return a face index in [0,5].
652 * For other targets return 0;
655 _mesa_tex_target_to_face(GLenum target
)
657 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
658 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
659 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
667 * Store a gl_texture_image pointer in a gl_texture_object structure
668 * according to the target and level parameters.
670 * \param tObj texture object.
671 * \param target texture target.
672 * \param level image level.
673 * \param texImage texture image.
675 * This was basically prompted by the introduction of cube maps.
678 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
679 GLenum target
, GLint level
,
680 struct gl_texture_image
*texImage
)
682 const GLuint face
= _mesa_tex_target_to_face(target
);
686 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
688 tObj
->Image
[face
][level
] = texImage
;
690 /* Set the 'back' pointer */
691 texImage
->TexObject
= tObj
;
696 * Allocate a texture image structure.
698 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
701 * \return a pointer to gl_texture_image struct with all fields initialized to
704 struct gl_texture_image
*
705 _mesa_new_texture_image( GLcontext
*ctx
)
708 return CALLOC_STRUCT(gl_texture_image
);
713 * Free texture image data.
714 * This function is a fallback called via ctx->Driver.FreeTexImageData().
716 * \param texImage texture image.
718 * Free the texture image data if it's not marked as client data.
721 _mesa_free_texture_image_data(GLcontext
*ctx
,
722 struct gl_texture_image
*texImage
)
726 if (texImage
->Data
&& !texImage
->IsClientData
) {
727 /* free the old texture data */
728 _mesa_free_texmemory(texImage
->Data
);
731 texImage
->Data
= NULL
;
736 * Free texture image.
738 * \param texImage texture image.
740 * Free the texture image structure and the associated image data.
743 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
745 /* Free texImage->Data and/or any other driver-specific texture
748 ASSERT(ctx
->Driver
.FreeTexImageData
);
749 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
751 ASSERT(texImage
->Data
== NULL
);
752 if (texImage
->ImageOffsets
)
753 _mesa_free(texImage
->ImageOffsets
);
754 _mesa_free(texImage
);
759 * Test if a target is a proxy target.
761 * \param target texture target.
763 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
766 _mesa_is_proxy_texture(GLenum target
)
768 /* NUM_TEXTURE_TARGETS should match number of terms below */
769 assert(NUM_TEXTURE_TARGETS
== 7);
771 return (target
== GL_PROXY_TEXTURE_1D
||
772 target
== GL_PROXY_TEXTURE_2D
||
773 target
== GL_PROXY_TEXTURE_3D
||
774 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
775 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
776 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
777 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
782 * Return pointer to current texture unit.
783 * This the texture unit set by glActiveTexture(), not glClientActiveTexture().
785 static INLINE
struct gl_texture_unit
*
786 get_current_tex_unit(GLcontext
*ctx
)
788 ASSERT(ctx
->Texture
.CurrentUnit
< Elements(ctx
->Texture
.Unit
));
789 return &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
794 * Get the texture object that corresponds to the target of the given texture unit.
796 * \param ctx GL context.
797 * \param texUnit texture unit.
798 * \param target texture target.
800 * \return pointer to the texture object on success, or NULL on failure.
802 * \sa gl_texture_unit.
804 struct gl_texture_object
*
805 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
810 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
811 case GL_PROXY_TEXTURE_1D
:
812 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
814 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
815 case GL_PROXY_TEXTURE_2D
:
816 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
818 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
819 case GL_PROXY_TEXTURE_3D
:
820 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
821 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
822 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
823 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
824 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
825 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
826 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
827 case GL_TEXTURE_CUBE_MAP_ARB
:
828 return ctx
->Extensions
.ARB_texture_cube_map
829 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
830 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
831 return ctx
->Extensions
.ARB_texture_cube_map
832 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
833 case GL_TEXTURE_RECTANGLE_NV
:
834 return ctx
->Extensions
.NV_texture_rectangle
835 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
836 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
837 return ctx
->Extensions
.NV_texture_rectangle
838 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
839 case GL_TEXTURE_1D_ARRAY_EXT
:
840 return ctx
->Extensions
.MESA_texture_array
841 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
842 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
843 return ctx
->Extensions
.MESA_texture_array
844 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
845 case GL_TEXTURE_2D_ARRAY_EXT
:
846 return ctx
->Extensions
.MESA_texture_array
847 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
848 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
849 return ctx
->Extensions
.MESA_texture_array
850 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
852 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
859 * Get a texture image pointer from a texture object, given a texture
860 * target and mipmap level. The target and level parameters should
861 * have already been error-checked.
863 * \param ctx GL context.
864 * \param texObj texture unit.
865 * \param target texture target.
866 * \param level image level.
868 * \return pointer to the texture image structure, or NULL on failure.
870 struct gl_texture_image
*
871 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
872 GLenum target
, GLint level
)
874 const GLuint face
= _mesa_tex_target_to_face(target
);
878 ASSERT(level
< MAX_TEXTURE_LEVELS
);
880 return texObj
->Image
[face
][level
];
885 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
886 * it and install it. Only return NULL if passed a bad parameter or run
889 struct gl_texture_image
*
890 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
891 GLenum target
, GLint level
)
893 struct gl_texture_image
*texImage
;
898 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
900 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
902 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
906 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
914 * Return pointer to the specified proxy texture image.
915 * Note that proxy textures are per-context, not per-texture unit.
916 * \return pointer to texture image or NULL if invalid target, invalid
917 * level, or out of memory.
919 struct gl_texture_image
*
920 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
922 struct gl_texture_image
*texImage
;
929 case GL_PROXY_TEXTURE_1D
:
930 if (level
>= ctx
->Const
.MaxTextureLevels
)
932 texIndex
= TEXTURE_1D_INDEX
;
934 case GL_PROXY_TEXTURE_2D
:
935 if (level
>= ctx
->Const
.MaxTextureLevels
)
937 texIndex
= TEXTURE_2D_INDEX
;
939 case GL_PROXY_TEXTURE_3D
:
940 if (level
>= ctx
->Const
.Max3DTextureLevels
)
942 texIndex
= TEXTURE_3D_INDEX
;
944 case GL_PROXY_TEXTURE_CUBE_MAP
:
945 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
947 texIndex
= TEXTURE_CUBE_INDEX
;
949 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
952 texIndex
= TEXTURE_RECT_INDEX
;
954 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
955 if (level
>= ctx
->Const
.MaxTextureLevels
)
957 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
959 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
960 if (level
>= ctx
->Const
.MaxTextureLevels
)
962 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
968 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
970 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
972 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
975 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
976 /* Set the 'back' pointer */
977 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
984 * Get the maximum number of allowed mipmap levels.
986 * \param ctx GL context.
987 * \param target texture target.
989 * \return the maximum number of allowed mipmap levels for the given
990 * texture target, or zero if passed a bad target.
995 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
999 case GL_PROXY_TEXTURE_1D
:
1001 case GL_PROXY_TEXTURE_2D
:
1002 case GL_TEXTURE_1D_ARRAY_EXT
:
1003 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1004 case GL_TEXTURE_2D_ARRAY_EXT
:
1005 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1006 return ctx
->Const
.MaxTextureLevels
;
1008 case GL_PROXY_TEXTURE_3D
:
1009 return ctx
->Const
.Max3DTextureLevels
;
1010 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1011 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1012 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1013 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1014 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1015 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1016 case GL_TEXTURE_CUBE_MAP_ARB
:
1017 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1018 return ctx
->Const
.MaxCubeTextureLevels
;
1019 case GL_TEXTURE_RECTANGLE_NV
:
1020 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1023 return 0; /* bad target */
1029 #if 000 /* not used anymore */
1031 * glTexImage[123]D can accept a NULL image pointer. In this case we
1032 * create a texture image with unspecified image contents per the OpenGL
1036 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1038 const GLint components
= _mesa_components_in_format(format
);
1039 const GLint numPixels
= width
* height
* depth
;
1040 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1044 * Let's see if anyone finds this. If glTexImage2D() is called with
1045 * a NULL image pointer then load the texture image with something
1046 * interesting instead of leaving it indeterminate.
1049 static const char message
[8][32] = {
1050 " X X XXXXX XXX X ",
1051 " XX XX X X X X X ",
1053 " X X XXXX XXX XXXXX ",
1056 " X X XXXXX XXX X X ",
1060 GLubyte
*imgPtr
= data
;
1062 for (h
= 0; h
< depth
; h
++) {
1063 for (i
= 0; i
< height
; i
++) {
1064 GLint srcRow
= 7 - (i
% 8);
1065 for (j
= 0; j
< width
; j
++) {
1066 GLint srcCol
= j
% 32;
1067 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1068 for (k
= 0; k
< components
; k
++) {
1084 * Reset the fields of a gl_texture_image struct to zero.
1086 * \param img texture image structure.
1088 * This is called when a proxy texture test fails, we set all the
1089 * image members (except DriverData) to zero.
1090 * It's also used in glTexImage[123]D as a safeguard to be sure all
1091 * required fields get initialized properly by the Driver.TexImage[123]D
1095 clear_teximage_fields(struct gl_texture_image
*img
)
1098 img
->_BaseFormat
= 0;
1099 img
->InternalFormat
= 0;
1105 if (img
->ImageOffsets
) {
1106 _mesa_free(img
->ImageOffsets
);
1107 img
->ImageOffsets
= NULL
;
1113 img
->HeightLog2
= 0;
1116 img
->TexFormat
= &_mesa_null_texformat
;
1117 img
->FetchTexelc
= NULL
;
1118 img
->FetchTexelf
= NULL
;
1119 img
->IsCompressed
= 0;
1120 img
->CompressedSize
= 0;
1125 * Initialize basic fields of the gl_texture_image struct.
1127 * \param ctx GL context.
1128 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1129 * \param img texture image structure to be initialized.
1130 * \param width image width.
1131 * \param height image height.
1132 * \param depth image depth.
1133 * \param border image border.
1134 * \param internalFormat internal format.
1136 * Fills in the fields of \p img with the given information.
1137 * Note: width, height and depth include the border.
1140 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1141 struct gl_texture_image
*img
,
1142 GLsizei width
, GLsizei height
, GLsizei depth
,
1143 GLint border
, GLenum internalFormat
)
1149 ASSERT(height
>= 0);
1152 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1153 ASSERT(img
->_BaseFormat
> 0);
1154 img
->InternalFormat
= internalFormat
;
1155 img
->Border
= border
;
1157 img
->Height
= height
;
1160 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1161 img
->WidthLog2
= logbase2(img
->Width2
);
1163 if (height
== 1) { /* 1-D texture */
1165 img
->HeightLog2
= 0;
1168 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1169 img
->HeightLog2
= logbase2(img
->Height2
);
1172 if (depth
== 1) { /* 2-D texture */
1177 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1178 img
->DepthLog2
= logbase2(img
->Depth2
);
1181 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1183 img
->IsCompressed
= GL_FALSE
;
1184 img
->CompressedSize
= 0;
1186 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1187 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1188 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1189 img
->_IsPowerOfTwo
= GL_TRUE
;
1191 img
->_IsPowerOfTwo
= GL_FALSE
;
1193 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1194 img
->RowStride
= width
;
1195 /* Allocate the ImageOffsets array and initialize to typical values.
1196 * We allocate the array for 1D/2D textures too in order to avoid special-
1197 * case code in the texstore routines.
1199 if (img
->ImageOffsets
)
1200 _mesa_free(img
->ImageOffsets
);
1201 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1202 for (i
= 0; i
< depth
; i
++) {
1203 img
->ImageOffsets
[i
] = i
* width
* height
;
1206 /* Compute Width/Height/DepthScale for mipmap lod computation */
1207 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1208 /* scale = 1.0 since texture coords directly map to texels */
1209 img
->WidthScale
= 1.0;
1210 img
->HeightScale
= 1.0;
1211 img
->DepthScale
= 1.0;
1214 img
->WidthScale
= (GLfloat
) img
->Width
;
1215 img
->HeightScale
= (GLfloat
) img
->Height
;
1216 img
->DepthScale
= (GLfloat
) img
->Depth
;
1222 * Free and clear fields of the gl_texture_image struct.
1224 * \param ctx GL context.
1225 * \param texImage texture image structure to be cleared.
1227 * After the call, \p texImage will have no data associated with it. Its
1228 * fields are cleared so that its parent object will test incomplete.
1231 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
1233 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1234 clear_teximage_fields(texImage
);
1239 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1240 * level, width, height and depth against the ctx->Const limits for textures.
1242 * A hardware driver might override this function if, for example, the
1243 * max 3D texture size is 512x512x64 (i.e. not a cube).
1245 * Note that width, height, depth == 0 is not an error. However, a
1246 * texture with zero width/height/depth will be considered "incomplete"
1247 * and texturing will effectively be disabled.
1249 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1250 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1251 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1252 * \param level as passed to glTexImage
1253 * \param internalFormat as passed to glTexImage
1254 * \param format as passed to glTexImage
1255 * \param type as passed to glTexImage
1256 * \param width as passed to glTexImage
1257 * \param height as passed to glTexImage
1258 * \param depth as passed to glTexImage
1259 * \param border as passed to glTexImage
1260 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1263 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1264 GLint internalFormat
, GLenum format
, GLenum type
,
1265 GLint width
, GLint height
, GLint depth
, GLint border
)
1269 (void) internalFormat
;
1274 case GL_PROXY_TEXTURE_1D
:
1275 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1276 if (width
< 2 * border
|| width
> 2 + maxSize
||
1277 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1278 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1279 level
>= ctx
->Const
.MaxTextureLevels
) {
1280 /* bad width or level */
1284 case GL_PROXY_TEXTURE_2D
:
1285 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1286 if (width
< 2 * border
|| width
> 2 + maxSize
||
1287 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1288 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1289 height
< 2 * border
|| height
> 2 + maxSize
||
1290 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1291 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1292 level
>= ctx
->Const
.MaxTextureLevels
) {
1293 /* bad width or height or level */
1297 case GL_PROXY_TEXTURE_3D
:
1298 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1299 if (width
< 2 * border
|| width
> 2 + maxSize
||
1300 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1301 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1302 height
< 2 * border
|| height
> 2 + maxSize
||
1303 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1304 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1305 depth
< 2 * border
|| depth
> 2 + maxSize
||
1306 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1307 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1308 level
>= ctx
->Const
.Max3DTextureLevels
) {
1309 /* bad width or height or depth or level */
1313 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1314 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1315 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1317 /* bad width or height or level */
1321 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1322 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1323 if (width
< 2 * border
|| width
> 2 + maxSize
||
1324 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1325 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1326 height
< 2 * border
|| height
> 2 + maxSize
||
1327 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1328 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1329 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1330 /* bad width or height */
1334 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1335 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1336 if (width
< 2 * border
|| width
> 2 + maxSize
||
1337 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1338 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1339 level
>= ctx
->Const
.MaxTextureLevels
) {
1340 /* bad width or level */
1344 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1348 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1349 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1350 if (width
< 2 * border
|| width
> 2 + maxSize
||
1351 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1352 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1353 height
< 2 * border
|| height
> 2 + maxSize
||
1354 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1355 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1356 level
>= ctx
->Const
.MaxTextureLevels
) {
1357 /* bad width or height or level */
1360 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1365 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1372 * Helper function to determine whether a target supports compressed textures
1375 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1377 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1378 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1379 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1380 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1381 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1382 || ((ctx
->Extensions
.MESA_texture_array
&&
1383 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1384 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1389 * Test the glTexImage[123]D() parameters for errors.
1391 * \param ctx GL context.
1392 * \param target texture target given by the user.
1393 * \param level image level given by the user.
1394 * \param internalFormat internal format given by the user.
1395 * \param format pixel data format given by the user.
1396 * \param type pixel data type given by the user.
1397 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1398 * \param width image width given by the user.
1399 * \param height image height given by the user.
1400 * \param depth image depth given by the user.
1401 * \param border image border given by the user.
1403 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1405 * Verifies each of the parameters against the constants specified in
1406 * __GLcontextRec::Const and the supported extensions, and according to the
1407 * OpenGL specification.
1410 texture_error_check( GLcontext
*ctx
, GLenum target
,
1411 GLint level
, GLint internalFormat
,
1412 GLenum format
, GLenum type
,
1414 GLint width
, GLint height
,
1415 GLint depth
, GLint border
)
1417 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1418 GLboolean sizeOK
= GL_TRUE
;
1419 GLboolean colorFormat
, indexFormat
;
1420 GLenum proxy_target
;
1422 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1423 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1425 _mesa_error(ctx
, GL_INVALID_VALUE
,
1426 "glTexImage%dD(level=%d)", dimensions
, level
);
1432 if (border
< 0 || border
> 1 ||
1433 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1434 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1436 _mesa_error(ctx
, GL_INVALID_VALUE
,
1437 "glTexImage%dD(border=%d)", dimensions
, border
);
1442 if (width
< 0 || height
< 0 || depth
< 0) {
1444 _mesa_error(ctx
, GL_INVALID_VALUE
,
1445 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1450 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1451 * level, width, height and depth.
1453 if (dimensions
== 1) {
1454 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1455 proxy_target
= GL_PROXY_TEXTURE_1D
;
1460 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1464 else if (dimensions
== 2) {
1466 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1467 proxy_target
= GL_PROXY_TEXTURE_2D
;
1469 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1470 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1471 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1472 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1473 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1476 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1477 sizeOK
= (width
== height
);
1479 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1480 target
== GL_TEXTURE_RECTANGLE_NV
) {
1481 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1482 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1485 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1487 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1488 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1489 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1492 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1496 else if (dimensions
== 3) {
1497 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1498 proxy_target
= GL_PROXY_TEXTURE_3D
;
1500 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1501 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1502 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1505 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1510 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1514 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1515 internalFormat
, format
,
1516 type
, width
, height
,
1520 _mesa_error(ctx
, GL_INVALID_VALUE
,
1521 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1522 dimensions
, level
, width
, height
, depth
);
1527 /* Check internalFormat */
1528 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1530 _mesa_error(ctx
, GL_INVALID_VALUE
,
1531 "glTexImage%dD(internalFormat=0x%x)",
1532 dimensions
, internalFormat
);
1537 /* Check incoming image format and type */
1538 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1539 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1540 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1543 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1544 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1545 dimensions
, format
, type
);
1550 /* make sure internal format and format basically agree */
1551 colorFormat
= _mesa_is_color_format(format
);
1552 indexFormat
= is_index_format(format
);
1553 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1554 (is_index_format(internalFormat
) && !indexFormat
) ||
1555 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1556 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1557 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
)) ||
1558 (is_dudv_format(internalFormat
) != is_dudv_format(format
))) {
1560 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1561 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1562 dimensions
, internalFormat
, format
);
1566 /* additional checks for ycbcr textures */
1567 if (internalFormat
== GL_YCBCR_MESA
) {
1568 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1569 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1570 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1572 _mesa_sprintf(message
,
1573 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1574 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1575 return GL_TRUE
; /* error */
1577 if (target
!= GL_TEXTURE_2D
&&
1578 target
!= GL_PROXY_TEXTURE_2D
&&
1579 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1580 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1582 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1588 _mesa_sprintf(message
,
1589 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1590 dimensions
, border
);
1591 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1597 /* additional checks for depth textures */
1598 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1599 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1600 if (target
!= GL_TEXTURE_1D
&&
1601 target
!= GL_PROXY_TEXTURE_1D
&&
1602 target
!= GL_TEXTURE_2D
&&
1603 target
!= GL_PROXY_TEXTURE_2D
&&
1604 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1605 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1607 _mesa_error(ctx
, GL_INVALID_ENUM
,
1608 "glTexImage(target/internalFormat)");
1613 /* additional checks for compressed textures */
1614 if (is_compressed_format(ctx
, internalFormat
)) {
1615 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1616 _mesa_error(ctx
, GL_INVALID_ENUM
,
1617 "glTexImage%d(target)", dimensions
);
1622 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1623 "glTexImage%D(border!=0)", dimensions
);
1629 /* if we get here, the parameters are OK */
1635 * Test glTexSubImage[123]D() parameters for errors.
1637 * \param ctx GL context.
1638 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1639 * \param target texture target given by the user.
1640 * \param level image level given by the user.
1641 * \param xoffset sub-image x offset given by the user.
1642 * \param yoffset sub-image y offset given by the user.
1643 * \param zoffset sub-image z offset given by the user.
1644 * \param format pixel data format given by the user.
1645 * \param type pixel data type given by the user.
1646 * \param width image width given by the user.
1647 * \param height image height given by the user.
1648 * \param depth image depth given by the user.
1650 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1652 * Verifies each of the parameters against the constants specified in
1653 * __GLcontextRec::Const and the supported extensions, and according to the
1654 * OpenGL specification.
1657 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1658 GLenum target
, GLint level
,
1659 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1660 GLint width
, GLint height
, GLint depth
,
1661 GLenum format
, GLenum type
)
1664 if (dimensions
== 1) {
1665 if (target
!= GL_TEXTURE_1D
) {
1666 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1670 else if (dimensions
== 2) {
1671 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1672 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1673 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1674 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1678 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1679 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1680 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1684 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1685 if (!ctx
->Extensions
.MESA_texture_array
) {
1686 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1690 else if (target
!= GL_TEXTURE_2D
) {
1691 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1695 else if (dimensions
== 3) {
1696 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1697 if (!ctx
->Extensions
.MESA_texture_array
) {
1698 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1702 else if (target
!= GL_TEXTURE_3D
) {
1703 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1708 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1712 /* Basic level check */
1713 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1714 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1719 _mesa_error(ctx
, GL_INVALID_VALUE
,
1720 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1723 if (height
< 0 && dimensions
> 1) {
1724 _mesa_error(ctx
, GL_INVALID_VALUE
,
1725 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1728 if (depth
< 0 && dimensions
> 2) {
1729 _mesa_error(ctx
, GL_INVALID_VALUE
,
1730 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1734 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1735 _mesa_error(ctx
, GL_INVALID_ENUM
,
1736 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1737 dimensions
, format
, type
);
1745 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1746 GLenum target
, GLint level
,
1747 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1748 GLint width
, GLint height
, GLint depth
,
1749 GLenum format
, GLenum type
,
1750 const struct gl_texture_image
*destTex
)
1753 /* undefined image level */
1754 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1758 if (xoffset
< -((GLint
)destTex
->Border
)) {
1759 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1763 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1764 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1768 if (dimensions
> 1) {
1769 if (yoffset
< -((GLint
)destTex
->Border
)) {
1770 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1774 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1775 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1780 if (dimensions
> 2) {
1781 if (zoffset
< -((GLint
)destTex
->Border
)) {
1782 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1785 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1786 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1791 #if FEATURE_EXT_texture_sRGB
1792 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1793 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1794 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1795 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1796 if ((width
& 0x3) || (height
& 0x3) ||
1797 (xoffset
& 0x3) || (yoffset
& 0x3))
1798 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1799 "glTexSubImage%dD(size or offset not multiple of 4)",
1805 if (destTex
->IsCompressed
) {
1806 if (!target_can_be_compressed(ctx
, target
)) {
1807 _mesa_error(ctx
, GL_INVALID_ENUM
,
1808 "glTexSubImage%D(target)", dimensions
);
1811 /* offset must be multiple of 4 */
1812 if ((xoffset
& 3) || (yoffset
& 3)) {
1813 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1814 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1817 /* size must be multiple of 4 or equal to whole texture size */
1818 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1819 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1820 "glTexSubImage%D(width)", dimensions
);
1823 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1824 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1825 "glTexSubImage%D(width)", dimensions
);
1835 * Test glCopyTexImage[12]D() parameters for errors.
1837 * \param ctx GL context.
1838 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1839 * \param target texture target given by the user.
1840 * \param level image level given by the user.
1841 * \param internalFormat internal format given by the user.
1842 * \param width image width given by the user.
1843 * \param height image height given by the user.
1844 * \param border texture border.
1846 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1848 * Verifies each of the parameters against the constants specified in
1849 * __GLcontextRec::Const and the supported extensions, and according to the
1850 * OpenGL specification.
1853 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1854 GLenum target
, GLint level
, GLint internalFormat
,
1855 GLint width
, GLint height
, GLint border
)
1861 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1862 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1863 _mesa_error(ctx
, GL_INVALID_VALUE
,
1864 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1868 /* Check that the source buffer is complete */
1869 if (ctx
->ReadBuffer
->Name
) {
1870 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1871 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1872 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1873 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1879 if (border
< 0 || border
> 1 ||
1880 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1881 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1885 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1887 _mesa_error(ctx
, GL_INVALID_VALUE
,
1888 "glCopyTexImage%dD(internalFormat)", dimensions
);
1892 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1893 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1894 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1898 /* NOTE: the format and type aren't really significant for
1899 * TestProxyTexImage(). Only the internalformat really matters.
1903 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1904 * level, width, height and depth.
1906 if (dimensions
== 1) {
1907 if (target
== GL_TEXTURE_1D
) {
1908 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1909 level
, internalFormat
,
1911 width
, 1, 1, border
);
1914 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1918 else if (dimensions
== 2) {
1919 if (target
== GL_TEXTURE_2D
) {
1920 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1921 level
, internalFormat
,
1923 width
, height
, 1, border
);
1925 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1926 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1927 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1928 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1931 sizeOK
= (width
== height
) &&
1932 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1933 level
, internalFormat
, format
, type
,
1934 width
, height
, 1, border
);
1936 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1937 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1938 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1941 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1942 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1943 level
, internalFormat
,
1945 width
, height
, 1, border
);
1947 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1948 if (!ctx
->Extensions
.MESA_texture_array
) {
1949 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1952 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1953 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1954 level
, internalFormat
,
1956 width
, height
, 1, border
);
1959 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1964 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1969 if (dimensions
== 1) {
1970 _mesa_error(ctx
, GL_INVALID_VALUE
,
1971 "glCopyTexImage1D(width=%d)", width
);
1974 ASSERT(dimensions
== 2);
1975 _mesa_error(ctx
, GL_INVALID_VALUE
,
1976 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1981 if (is_compressed_format(ctx
, internalFormat
)) {
1982 if (!target_can_be_compressed(ctx
, target
)) {
1983 _mesa_error(ctx
, GL_INVALID_ENUM
,
1984 "glCopyTexImage%d(target)", dimensions
);
1988 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1989 "glCopyTexImage%D(border!=0)", dimensions
);
1993 else if (is_depth_format(internalFormat
)) {
1994 /* make sure we have depth/stencil buffers */
1995 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1996 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1997 "glCopyTexImage%D(no depth)", dimensions
);
2001 else if (is_depthstencil_format(internalFormat
)) {
2002 /* make sure we have depth/stencil buffers */
2003 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2004 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2005 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2010 /* if we get here, the parameters are OK */
2016 * Test glCopyTexSubImage[12]D() parameters for errors.
2017 * Note that this is the first part of error checking.
2018 * See also copytexsubimage_error_check2() below for the second part.
2020 * \param ctx GL context.
2021 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2022 * \param target texture target given by the user.
2023 * \param level image level given by the user.
2025 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2028 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
2029 GLenum target
, GLint level
)
2031 /* Check that the source buffer is complete */
2032 if (ctx
->ReadBuffer
->Name
) {
2033 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2034 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2035 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2036 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2042 if (dimensions
== 1) {
2043 if (target
!= GL_TEXTURE_1D
) {
2044 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2048 else if (dimensions
== 2) {
2049 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2050 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2051 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2052 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2056 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2057 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2058 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2062 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2063 if (!ctx
->Extensions
.MESA_texture_array
) {
2064 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2068 else if (target
!= GL_TEXTURE_2D
) {
2069 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2073 else if (dimensions
== 3) {
2074 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2075 (!ctx
->Extensions
.MESA_texture_array
))
2076 && (target
!= GL_TEXTURE_3D
)) {
2077 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2083 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2084 _mesa_error(ctx
, GL_INVALID_VALUE
,
2085 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2094 * Second part of error checking for glCopyTexSubImage[12]D().
2095 * \param xoffset sub-image x offset given by the user.
2096 * \param yoffset sub-image y offset given by the user.
2097 * \param zoffset sub-image z offset given by the user.
2098 * \param width image width given by the user.
2099 * \param height image height given by the user.
2102 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2103 GLenum target
, GLint level
,
2104 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2105 GLsizei width
, GLsizei height
,
2106 const struct gl_texture_image
*teximage
)
2108 /* check that dest tex image exists */
2110 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2111 "glCopyTexSubImage%dD(undefined texture level: %d)",
2118 _mesa_error(ctx
, GL_INVALID_VALUE
,
2119 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2122 if (dimensions
> 1 && height
< 0) {
2123 _mesa_error(ctx
, GL_INVALID_VALUE
,
2124 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2128 /* check x/y offsets */
2129 if (xoffset
< -((GLint
)teximage
->Border
)) {
2130 _mesa_error(ctx
, GL_INVALID_VALUE
,
2131 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2134 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2135 _mesa_error(ctx
, GL_INVALID_VALUE
,
2136 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2139 if (dimensions
> 1) {
2140 if (yoffset
< -((GLint
)teximage
->Border
)) {
2141 _mesa_error(ctx
, GL_INVALID_VALUE
,
2142 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2145 /* NOTE: we're adding the border here, not subtracting! */
2146 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2147 _mesa_error(ctx
, GL_INVALID_VALUE
,
2148 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2153 /* check z offset */
2154 if (dimensions
> 2) {
2155 if (zoffset
< -((GLint
)teximage
->Border
)) {
2156 _mesa_error(ctx
, GL_INVALID_VALUE
,
2157 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2160 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2161 _mesa_error(ctx
, GL_INVALID_VALUE
,
2162 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2167 if (teximage
->IsCompressed
) {
2168 if (!target_can_be_compressed(ctx
, target
)) {
2169 _mesa_error(ctx
, GL_INVALID_ENUM
,
2170 "glCopyTexSubImage%d(target)", dimensions
);
2173 /* offset must be multiple of 4 */
2174 if ((xoffset
& 3) || (yoffset
& 3)) {
2175 _mesa_error(ctx
, GL_INVALID_VALUE
,
2176 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2179 /* size must be multiple of 4 */
2180 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2181 _mesa_error(ctx
, GL_INVALID_VALUE
,
2182 "glCopyTexSubImage%D(width)", dimensions
);
2185 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2186 _mesa_error(ctx
, GL_INVALID_VALUE
,
2187 "glCopyTexSubImage%D(height)", dimensions
);
2192 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2193 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2197 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2198 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2199 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2200 dimensions
, teximage
->_BaseFormat
);
2204 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2205 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2206 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2207 "glCopyTexSubImage%D(no depth buffer)",
2212 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2213 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2214 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2215 "glCopyTexSubImage%D(no depth/stencil buffer)",
2221 /* if we get here, the parameters are OK */
2227 * Do error checking for a glGetTexImage() call.
2228 * \return GL_TRUE if any error, GL_FALSE if no errors.
2231 getteximage_error_check(GLcontext
*ctx
, GLenum target
, GLint level
,
2232 GLenum format
, GLenum type
, GLvoid
*pixels
)
2234 const struct gl_texture_unit
*texUnit
;
2235 struct gl_texture_object
*texObj
;
2236 struct gl_texture_image
*texImage
;
2237 const GLuint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2239 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2241 if (level
< 0 || level
>= maxLevels
) {
2242 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2246 if (_mesa_sizeof_packed_type(type
) <= 0) {
2247 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2251 if (_mesa_components_in_format(format
) <= 0 ||
2252 format
== GL_STENCIL_INDEX
) {
2253 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2257 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2258 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2262 if (!ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2263 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2267 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2268 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2272 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2273 && is_depthstencil_format(format
)) {
2274 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2278 if (!ctx
->Extensions
.ATI_envmap_bumpmap
2279 && is_dudv_format(format
)) {
2280 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2284 texUnit
= get_current_tex_unit(ctx
);
2285 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2287 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2288 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2292 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2298 /* Make sure the requested image format is compatible with the
2299 * texture's format. Note that a color index texture can be converted
2300 * to RGBA so that combo is allowed.
2302 if (_mesa_is_color_format(format
)
2303 && !_mesa_is_color_format(texImage
->TexFormat
->BaseFormat
)
2304 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2305 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2308 else if (is_index_format(format
)
2309 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2310 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2313 else if (is_depth_format(format
)
2314 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2315 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2316 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2319 else if (is_ycbcr_format(format
)
2320 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2321 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2324 else if (is_depthstencil_format(format
)
2325 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2326 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2329 else if (is_dudv_format(format
)
2330 && !is_dudv_format(texImage
->TexFormat
->BaseFormat
)) {
2331 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2335 if (_mesa_is_bufferobj(ctx
->Pack
.BufferObj
)) {
2336 /* packing texture image into a PBO */
2337 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2338 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2339 texImage
->Height
, texImage
->Depth
,
2340 format
, type
, pixels
)) {
2341 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2342 "glGetTexImage(invalid PBO access)");
2353 * Get texture image. Called by glGetTexImage.
2355 * \param target texture target.
2356 * \param level image level.
2357 * \param format pixel data format for returned image.
2358 * \param type pixel data type for returned image.
2359 * \param pixels returned pixel data.
2362 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2363 GLenum type
, GLvoid
*pixels
)
2365 const struct gl_texture_unit
*texUnit
;
2366 struct gl_texture_object
*texObj
;
2367 GET_CURRENT_CONTEXT(ctx
);
2368 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2370 if (getteximage_error_check(ctx
, target
, level
, format
, type
, pixels
)) {
2374 texUnit
= get_current_tex_unit(ctx
);
2375 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2377 _mesa_lock_texture(ctx
, texObj
);
2379 struct gl_texture_image
*texImage
=
2380 _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2382 /* typically, this will call _mesa_get_teximage() */
2383 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2386 _mesa_unlock_texture(ctx
, texObj
);
2390 /** Callback info for walking over FBO hash table */
2394 struct gl_texture_object
*texObj
;
2400 * Check render to texture callback. Called from _mesa_HashWalk().
2403 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2405 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2406 const struct cb_info
*info
= (struct cb_info
*) userData
;
2407 GLcontext
*ctx
= info
->ctx
;
2408 const struct gl_texture_object
*texObj
= info
->texObj
;
2409 const GLuint level
= info
->level
, face
= info
->face
;
2411 /* If this is a user-created FBO */
2414 /* check if any of the FBO's attachments point to 'texObj' */
2415 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2416 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2417 if (att
->Type
== GL_TEXTURE
&&
2418 att
->Texture
== texObj
&&
2419 att
->TextureLevel
== level
&&
2420 att
->CubeMapFace
== face
) {
2421 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2422 /* Tell driver about the new renderbuffer texture */
2423 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2424 /* Mark fb status as indeterminate to force re-validation */
2433 * When a texture image is specified we have to check if it's bound to
2434 * any framebuffer objects (render to texture) in order to detect changes
2435 * in size or format since that effects FBO completeness.
2436 * Any FBOs rendering into the texture must be re-validated.
2439 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2440 GLuint face
, GLuint level
)
2442 /* Only check this texture if it's been marked as RenderToTexture */
2443 if (texObj
->_RenderToTexture
) {
2444 struct cb_info info
;
2446 info
.texObj
= texObj
;
2449 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2454 /** Debug helper: override the user-requested internal format */
2456 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2459 if (internalFormat
== GL_RGBA16F_ARB
||
2460 internalFormat
== GL_RGBA32F_ARB
) {
2461 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2464 else if (internalFormat
== GL_RGB16F_ARB
||
2465 internalFormat
== GL_RGB32F_ARB
) {
2466 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2469 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2470 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2471 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2472 return GL_LUMINANCE_ALPHA
;
2474 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2475 internalFormat
== GL_LUMINANCE32F_ARB
) {
2476 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2477 return GL_LUMINANCE
;
2479 else if (internalFormat
== GL_ALPHA16F_ARB
||
2480 internalFormat
== GL_ALPHA32F_ARB
) {
2481 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2485 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2486 internalFormat = GL_RGBA;
2490 return internalFormat
;
2493 return internalFormat
;
2499 * Called from the API. Note that width includes the border.
2502 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2503 GLsizei width
, GLint border
, GLenum format
,
2504 GLenum type
, const GLvoid
*pixels
)
2506 GLsizei postConvWidth
= width
;
2507 GET_CURRENT_CONTEXT(ctx
);
2508 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2510 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2512 #if FEATURE_convolve
2513 if (_mesa_is_color_format(internalFormat
)) {
2514 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2518 if (target
== GL_TEXTURE_1D
) {
2519 /* non-proxy target */
2520 struct gl_texture_unit
*texUnit
;
2521 struct gl_texture_object
*texObj
;
2522 struct gl_texture_image
*texImage
;
2523 const GLuint face
= _mesa_tex_target_to_face(target
);
2525 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2526 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2527 return; /* error was recorded */
2530 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2531 _mesa_update_state(ctx
);
2533 texUnit
= get_current_tex_unit(ctx
);
2534 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2535 _mesa_lock_texture(ctx
, texObj
);
2537 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2539 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2543 if (texImage
->Data
) {
2544 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2547 ASSERT(texImage
->Data
== NULL
);
2549 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2550 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2551 postConvWidth
, 1, 1,
2552 border
, internalFormat
);
2554 ASSERT(ctx
->Driver
.TexImage1D
);
2556 /* Give the texture to the driver! <pixels> may be null! */
2557 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2558 width
, border
, format
, type
, pixels
,
2559 &ctx
->Unpack
, texObj
, texImage
);
2561 ASSERT(texImage
->TexFormat
);
2563 update_fbo_texture(ctx
, texObj
, face
, level
);
2566 texObj
->_Complete
= GL_FALSE
;
2567 ctx
->NewState
|= _NEW_TEXTURE
;
2570 _mesa_unlock_texture(ctx
, texObj
);
2572 else if (target
== GL_PROXY_TEXTURE_1D
) {
2573 /* Proxy texture: check for errors and update proxy state */
2574 struct gl_texture_image
*texImage
;
2575 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2576 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2577 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2578 /* when error, clear all proxy texture image parameters */
2580 clear_teximage_fields(texImage
);
2583 /* no error, set the tex image parameters */
2585 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2586 postConvWidth
, 1, 1,
2587 border
, internalFormat
);
2588 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2589 internalFormat
, format
, type
);
2593 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2600 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2601 GLsizei width
, GLsizei height
, GLint border
,
2602 GLenum format
, GLenum type
,
2603 const GLvoid
*pixels
)
2605 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2606 GET_CURRENT_CONTEXT(ctx
);
2607 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2609 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2611 #if FEATURE_convolve
2612 if (_mesa_is_color_format(internalFormat
)) {
2613 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2618 if (target
== GL_TEXTURE_2D
||
2619 (ctx
->Extensions
.ARB_texture_cube_map
&&
2620 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2621 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2622 (ctx
->Extensions
.NV_texture_rectangle
&&
2623 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2624 (ctx
->Extensions
.MESA_texture_array
&&
2625 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2626 /* non-proxy target */
2627 struct gl_texture_unit
*texUnit
;
2628 struct gl_texture_object
*texObj
;
2629 struct gl_texture_image
*texImage
;
2630 const GLuint face
= _mesa_tex_target_to_face(target
);
2632 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2633 format
, type
, 2, postConvWidth
, postConvHeight
,
2635 return; /* error was recorded */
2638 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2639 _mesa_update_state(ctx
);
2641 texUnit
= get_current_tex_unit(ctx
);
2642 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2643 _mesa_lock_texture(ctx
, texObj
);
2645 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2647 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2651 if (texImage
->Data
) {
2652 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2655 ASSERT(texImage
->Data
== NULL
);
2656 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2657 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2658 postConvWidth
, postConvHeight
, 1,
2659 border
, internalFormat
);
2661 ASSERT(ctx
->Driver
.TexImage2D
);
2663 /* Give the texture to the driver! <pixels> may be null! */
2664 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2665 width
, height
, border
, format
, type
, pixels
,
2666 &ctx
->Unpack
, texObj
, texImage
);
2668 ASSERT(texImage
->TexFormat
);
2670 update_fbo_texture(ctx
, texObj
, face
, level
);
2673 texObj
->_Complete
= GL_FALSE
;
2674 ctx
->NewState
|= _NEW_TEXTURE
;
2677 _mesa_unlock_texture(ctx
, texObj
);
2679 else if (target
== GL_PROXY_TEXTURE_2D
||
2680 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2681 ctx
->Extensions
.ARB_texture_cube_map
) ||
2682 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2683 ctx
->Extensions
.NV_texture_rectangle
) ||
2684 (ctx
->Extensions
.MESA_texture_array
&&
2685 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2686 /* Proxy texture: check for errors and update proxy state */
2687 struct gl_texture_image
*texImage
;
2688 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2689 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2690 format
, type
, 2, postConvWidth
, postConvHeight
,
2692 /* when error, clear all proxy texture image parameters */
2694 clear_teximage_fields(texImage
);
2697 /* no error, set the tex image parameters */
2698 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2699 postConvWidth
, postConvHeight
, 1,
2700 border
, internalFormat
);
2701 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2702 internalFormat
, format
, type
);
2706 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2713 * Called by the API or display list executor.
2714 * Note that width and height include the border.
2717 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2718 GLsizei width
, GLsizei height
, GLsizei depth
,
2719 GLint border
, GLenum format
, GLenum type
,
2720 const GLvoid
*pixels
)
2722 GET_CURRENT_CONTEXT(ctx
);
2723 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2725 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2727 if (target
== GL_TEXTURE_3D
||
2728 (ctx
->Extensions
.MESA_texture_array
&&
2729 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2730 /* non-proxy target */
2731 struct gl_texture_unit
*texUnit
;
2732 struct gl_texture_object
*texObj
;
2733 struct gl_texture_image
*texImage
;
2734 const GLuint face
= _mesa_tex_target_to_face(target
);
2736 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2737 format
, type
, 3, width
, height
, depth
, border
)) {
2738 return; /* error was recorded */
2741 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2742 _mesa_update_state(ctx
);
2744 texUnit
= get_current_tex_unit(ctx
);
2745 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2746 _mesa_lock_texture(ctx
, texObj
);
2748 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2750 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2754 if (texImage
->Data
) {
2755 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2758 ASSERT(texImage
->Data
== NULL
);
2759 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2760 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2761 width
, height
, depth
,
2762 border
, internalFormat
);
2764 ASSERT(ctx
->Driver
.TexImage3D
);
2766 /* Give the texture to the driver! <pixels> may be null! */
2767 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2768 width
, height
, depth
, border
, format
, type
,
2769 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2771 ASSERT(texImage
->TexFormat
);
2773 update_fbo_texture(ctx
, texObj
, face
, level
);
2776 texObj
->_Complete
= GL_FALSE
;
2777 ctx
->NewState
|= _NEW_TEXTURE
;
2780 _mesa_unlock_texture(ctx
, texObj
);
2782 else if (target
== GL_PROXY_TEXTURE_3D
||
2783 (ctx
->Extensions
.MESA_texture_array
&&
2784 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2785 /* Proxy texture: check for errors and update proxy state */
2786 struct gl_texture_image
*texImage
;
2787 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2788 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2789 format
, type
, 3, width
, height
, depth
, border
)) {
2790 /* when error, clear all proxy texture image parameters */
2792 clear_teximage_fields(texImage
);
2795 /* no error, set the tex image parameters */
2796 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2797 depth
, border
, internalFormat
);
2798 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2799 internalFormat
, format
, type
);
2803 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2810 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2811 GLsizei width
, GLsizei height
, GLsizei depth
,
2812 GLint border
, GLenum format
, GLenum type
,
2813 const GLvoid
*pixels
)
2815 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2816 depth
, border
, format
, type
, pixels
);
2822 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2823 GLint xoffset
, GLsizei width
,
2824 GLenum format
, GLenum type
,
2825 const GLvoid
*pixels
)
2827 GLsizei postConvWidth
= width
;
2828 struct gl_texture_unit
*texUnit
;
2829 struct gl_texture_object
*texObj
;
2830 struct gl_texture_image
*texImage
= NULL
;
2831 GET_CURRENT_CONTEXT(ctx
);
2832 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2834 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2835 _mesa_update_state(ctx
);
2837 #if FEATURE_convolve
2838 /* XXX should test internal format */
2839 if (_mesa_is_color_format(format
)) {
2840 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2844 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2845 postConvWidth
, 1, 1, format
, type
)) {
2846 return; /* error was detected */
2850 texUnit
= get_current_tex_unit(ctx
);
2851 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2854 _mesa_lock_texture(ctx
, texObj
);
2856 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2858 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2859 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2860 goto out
; /* error was detected */
2864 goto out
; /* no-op, not an error */
2866 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2867 xoffset
+= texImage
->Border
;
2869 ASSERT(ctx
->Driver
.TexSubImage1D
);
2870 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2871 format
, type
, pixels
, &ctx
->Unpack
,
2873 ctx
->NewState
|= _NEW_TEXTURE
;
2876 _mesa_unlock_texture(ctx
, texObj
);
2881 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2882 GLint xoffset
, GLint yoffset
,
2883 GLsizei width
, GLsizei height
,
2884 GLenum format
, GLenum type
,
2885 const GLvoid
*pixels
)
2887 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2888 struct gl_texture_unit
*texUnit
;
2889 struct gl_texture_object
*texObj
;
2890 struct gl_texture_image
*texImage
;
2891 GET_CURRENT_CONTEXT(ctx
);
2892 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2894 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2895 _mesa_update_state(ctx
);
2897 #if FEATURE_convolve
2898 /* XXX should test internal format */
2899 if (_mesa_is_color_format(format
)) {
2900 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2905 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2906 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2907 return; /* error was detected */
2910 texUnit
= get_current_tex_unit(ctx
);
2911 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2912 _mesa_lock_texture(ctx
, texObj
);
2914 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2916 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2917 postConvWidth
, postConvHeight
, 1, format
, type
,
2919 goto out
; /* error was detected */
2922 if (width
== 0 || height
== 0)
2923 goto out
; /* no-op, not an error */
2925 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2926 xoffset
+= texImage
->Border
;
2927 yoffset
+= texImage
->Border
;
2929 ASSERT(ctx
->Driver
.TexSubImage2D
);
2930 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2931 width
, height
, format
, type
, pixels
,
2932 &ctx
->Unpack
, texObj
, texImage
);
2933 ctx
->NewState
|= _NEW_TEXTURE
;
2936 _mesa_unlock_texture(ctx
, texObj
);
2942 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2943 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2944 GLsizei width
, GLsizei height
, GLsizei depth
,
2945 GLenum format
, GLenum type
,
2946 const GLvoid
*pixels
)
2948 struct gl_texture_unit
*texUnit
;
2949 struct gl_texture_object
*texObj
;
2950 struct gl_texture_image
*texImage
;
2951 GET_CURRENT_CONTEXT(ctx
);
2952 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2954 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2955 _mesa_update_state(ctx
);
2957 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2958 width
, height
, depth
, format
, type
)) {
2959 return; /* error was detected */
2962 texUnit
= get_current_tex_unit(ctx
);
2963 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2965 _mesa_lock_texture(ctx
, texObj
);
2967 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2969 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2970 width
, height
, depth
, format
, type
, texImage
)) {
2971 goto out
; /* error was detected */
2974 if (width
== 0 || height
== 0 || height
== 0)
2975 goto out
; /* no-op, not an error */
2977 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2978 xoffset
+= texImage
->Border
;
2979 yoffset
+= texImage
->Border
;
2980 zoffset
+= texImage
->Border
;
2982 ASSERT(ctx
->Driver
.TexSubImage3D
);
2983 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2984 xoffset
, yoffset
, zoffset
,
2985 width
, height
, depth
,
2986 format
, type
, pixels
,
2987 &ctx
->Unpack
, texObj
, texImage
);
2988 ctx
->NewState
|= _NEW_TEXTURE
;
2991 _mesa_unlock_texture(ctx
, texObj
);
2997 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2998 GLenum internalFormat
,
3000 GLsizei width
, GLint border
)
3002 struct gl_texture_unit
*texUnit
;
3003 struct gl_texture_object
*texObj
;
3004 struct gl_texture_image
*texImage
;
3005 GLsizei postConvWidth
= width
;
3006 const GLuint face
= _mesa_tex_target_to_face(target
);
3007 GET_CURRENT_CONTEXT(ctx
);
3008 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3010 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3011 _mesa_update_state(ctx
);
3013 #if FEATURE_convolve
3014 if (_mesa_is_color_format(internalFormat
)) {
3015 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3019 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
3020 postConvWidth
, 1, border
))
3023 texUnit
= get_current_tex_unit(ctx
);
3024 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3025 _mesa_lock_texture(ctx
, texObj
);
3027 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3029 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
3033 if (texImage
->Data
) {
3034 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3037 ASSERT(texImage
->Data
== NULL
);
3039 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3040 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
3041 border
, internalFormat
);
3044 ASSERT(ctx
->Driver
.CopyTexImage1D
);
3045 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
3046 x
, y
, width
, border
);
3048 ASSERT(texImage
->TexFormat
);
3050 update_fbo_texture(ctx
, texObj
, face
, level
);
3053 texObj
->_Complete
= GL_FALSE
;
3054 ctx
->NewState
|= _NEW_TEXTURE
;
3057 _mesa_unlock_texture(ctx
, texObj
);
3063 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3064 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3067 struct gl_texture_unit
*texUnit
;
3068 struct gl_texture_object
*texObj
;
3069 struct gl_texture_image
*texImage
;
3070 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3071 const GLuint face
= _mesa_tex_target_to_face(target
);
3072 GET_CURRENT_CONTEXT(ctx
);
3073 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3075 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3076 _mesa_update_state(ctx
);
3078 #if FEATURE_convolve
3079 if (_mesa_is_color_format(internalFormat
)) {
3080 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
3085 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
3086 postConvWidth
, postConvHeight
, border
))
3089 texUnit
= get_current_tex_unit(ctx
);
3090 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3092 _mesa_lock_texture(ctx
, texObj
);
3094 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3097 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3101 if (texImage
->Data
) {
3102 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3105 ASSERT(texImage
->Data
== NULL
);
3107 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3108 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3109 postConvWidth
, postConvHeight
, 1,
3110 border
, internalFormat
);
3112 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3113 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3114 x
, y
, width
, height
, border
);
3116 ASSERT(texImage
->TexFormat
);
3118 update_fbo_texture(ctx
, texObj
, face
, level
);
3121 texObj
->_Complete
= GL_FALSE
;
3122 ctx
->NewState
|= _NEW_TEXTURE
;
3125 _mesa_unlock_texture(ctx
, texObj
);
3130 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3131 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3133 struct gl_texture_unit
*texUnit
;
3134 struct gl_texture_object
*texObj
;
3135 struct gl_texture_image
*texImage
;
3136 GLsizei postConvWidth
= width
;
3140 GET_CURRENT_CONTEXT(ctx
);
3141 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3143 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3144 _mesa_update_state(ctx
);
3146 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3149 texUnit
= get_current_tex_unit(ctx
);
3150 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3152 _mesa_lock_texture(ctx
, texObj
);
3154 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3156 #if FEATURE_convolve
3157 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3158 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3162 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3163 xoffset
, 0, 0, postConvWidth
, 1,
3168 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3169 xoffset
+= texImage
->Border
;
3171 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3173 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3174 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3175 xoffset
, x
, y
, width
);
3178 ctx
->NewState
|= _NEW_TEXTURE
;
3181 _mesa_unlock_texture(ctx
, texObj
);
3187 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3188 GLint xoffset
, GLint yoffset
,
3189 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3191 struct gl_texture_unit
*texUnit
;
3192 struct gl_texture_object
*texObj
;
3193 struct gl_texture_image
*texImage
;
3194 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3195 GET_CURRENT_CONTEXT(ctx
);
3196 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3198 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3199 _mesa_update_state(ctx
);
3201 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3204 texUnit
= get_current_tex_unit(ctx
);
3205 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3207 _mesa_lock_texture(ctx
, texObj
);
3209 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3211 #if FEATURE_convolve
3212 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3213 _mesa_adjust_image_for_convolution(ctx
, 2,
3214 &postConvWidth
, &postConvHeight
);
3218 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3219 postConvWidth
, postConvHeight
, texImage
))
3222 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3223 xoffset
+= texImage
->Border
;
3224 yoffset
+= texImage
->Border
;
3226 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3228 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3229 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3230 xoffset
, yoffset
, x
, y
, width
, height
);
3233 ctx
->NewState
|= _NEW_TEXTURE
;
3236 _mesa_unlock_texture(ctx
, texObj
);
3242 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3243 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3244 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3246 struct gl_texture_unit
*texUnit
;
3247 struct gl_texture_object
*texObj
;
3248 struct gl_texture_image
*texImage
;
3249 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3250 GET_CURRENT_CONTEXT(ctx
);
3251 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3253 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3254 _mesa_update_state(ctx
);
3256 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3259 texUnit
= get_current_tex_unit(ctx
);
3260 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3262 _mesa_lock_texture(ctx
, texObj
);
3264 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3266 #if FEATURE_convolve
3267 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3268 _mesa_adjust_image_for_convolution(ctx
, 2,
3269 &postConvWidth
, &postConvHeight
);
3273 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3274 zoffset
, postConvWidth
, postConvHeight
,
3278 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3279 xoffset
+= texImage
->Border
;
3280 yoffset
+= texImage
->Border
;
3281 zoffset
+= texImage
->Border
;
3283 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3285 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3286 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3287 xoffset
, yoffset
, zoffset
,
3288 x
, y
, width
, height
);
3291 ctx
->NewState
|= _NEW_TEXTURE
;
3294 _mesa_unlock_texture(ctx
, texObj
);
3300 /**********************************************************************/
3301 /****** Compressed Textures ******/
3302 /**********************************************************************/
3306 * Error checking for glCompressedTexImage[123]D().
3307 * \return error code or GL_NO_ERROR.
3310 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3311 GLenum target
, GLint level
,
3312 GLenum internalFormat
, GLsizei width
,
3313 GLsizei height
, GLsizei depth
, GLint border
,
3316 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3318 if (dimensions
== 1) {
3319 /* 1D compressed textures not allowed */
3320 return GL_INVALID_ENUM
;
3322 else if (dimensions
== 2) {
3323 if (target
== GL_PROXY_TEXTURE_2D
) {
3324 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3326 else if (target
== GL_TEXTURE_2D
) {
3327 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3329 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3330 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3331 return GL_INVALID_ENUM
; /*target*/
3332 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3334 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3335 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3336 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3337 return GL_INVALID_ENUM
; /*target*/
3338 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3341 return GL_INVALID_ENUM
; /*target*/
3344 else if (dimensions
== 3) {
3345 /* 3D compressed textures not allowed */
3346 return GL_INVALID_ENUM
;
3349 maxTextureSize
= 1 << (maxLevels
- 1);
3351 /* This will detect any invalid internalFormat value */
3352 if (!is_compressed_format(ctx
, internalFormat
))
3353 return GL_INVALID_ENUM
;
3355 /* This should really never fail */
3356 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3357 return GL_INVALID_ENUM
;
3360 return GL_INVALID_VALUE
;
3363 * XXX We should probably use the proxy texture error check function here.
3365 if (width
< 1 || width
> maxTextureSize
||
3366 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3367 return GL_INVALID_VALUE
;
3369 if ((height
< 1 || height
> maxTextureSize
||
3370 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3372 return GL_INVALID_VALUE
;
3374 if ((depth
< 1 || depth
> maxTextureSize
||
3375 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3377 return GL_INVALID_VALUE
;
3379 /* For cube map, width must equal height */
3380 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3381 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3382 return GL_INVALID_VALUE
;
3384 if (level
< 0 || level
>= maxLevels
)
3385 return GL_INVALID_VALUE
;
3387 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3388 depth
, internalFormat
);
3389 if (expectedSize
!= imageSize
)
3390 return GL_INVALID_VALUE
;
3392 #if FEATURE_EXT_texture_sRGB
3393 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3394 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3395 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3396 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3398 return GL_INVALID_OPERATION
;
3407 * Error checking for glCompressedTexSubImage[123]D().
3408 * \warning There are some bad assumptions here about the size of compressed
3409 * texture tiles (multiple of 4) used to test the validity of the
3410 * offset and size parameters.
3411 * \return error code or GL_NO_ERROR.
3414 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3415 GLenum target
, GLint level
,
3416 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3417 GLsizei width
, GLsizei height
, GLsizei depth
,
3418 GLenum format
, GLsizei imageSize
)
3420 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3423 if (dimensions
== 1) {
3424 /* 1D compressed textures not allowed */
3425 return GL_INVALID_ENUM
;
3427 else if (dimensions
== 2) {
3428 if (target
== GL_PROXY_TEXTURE_2D
) {
3429 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3431 else if (target
== GL_TEXTURE_2D
) {
3432 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3434 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3435 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3436 return GL_INVALID_ENUM
; /*target*/
3437 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3439 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3440 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3441 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3442 return GL_INVALID_ENUM
; /*target*/
3443 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3446 return GL_INVALID_ENUM
; /*target*/
3449 else if (dimensions
== 3) {
3450 /* 3D compressed textures not allowed */
3451 return GL_INVALID_ENUM
;
3454 maxTextureSize
= 1 << (maxLevels
- 1);
3456 /* this will catch any invalid compressed format token */
3457 if (!is_compressed_format(ctx
, format
))
3458 return GL_INVALID_ENUM
;
3460 if (width
< 1 || width
> maxTextureSize
)
3461 return GL_INVALID_VALUE
;
3463 if ((height
< 1 || height
> maxTextureSize
)
3465 return GL_INVALID_VALUE
;
3467 if (level
< 0 || level
>= maxLevels
)
3468 return GL_INVALID_VALUE
;
3470 /* XXX these tests are specific to the compressed format.
3471 * this code should be generalized in some way.
3473 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3474 return GL_INVALID_VALUE
;
3476 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3477 return GL_INVALID_VALUE
;
3479 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3480 return GL_INVALID_VALUE
;
3482 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3484 if (expectedSize
!= imageSize
)
3485 return GL_INVALID_VALUE
;
3493 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3494 GLenum internalFormat
, GLsizei width
,
3495 GLint border
, GLsizei imageSize
,
3498 GET_CURRENT_CONTEXT(ctx
);
3499 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3501 if (target
== GL_TEXTURE_1D
) {
3502 /* non-proxy target */
3503 struct gl_texture_unit
*texUnit
;
3504 struct gl_texture_object
*texObj
;
3505 struct gl_texture_image
*texImage
;
3506 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3507 internalFormat
, width
, 1, 1, border
, imageSize
);
3509 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3513 texUnit
= get_current_tex_unit(ctx
);
3514 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3516 _mesa_lock_texture(ctx
, texObj
);
3518 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3520 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3524 if (texImage
->Data
) {
3525 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3527 ASSERT(texImage
->Data
== NULL
);
3529 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3530 border
, internalFormat
);
3532 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3533 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3534 internalFormat
, width
, border
,
3539 texObj
->_Complete
= GL_FALSE
;
3540 ctx
->NewState
|= _NEW_TEXTURE
;
3543 _mesa_unlock_texture(ctx
, texObj
);
3545 else if (target
== GL_PROXY_TEXTURE_1D
) {
3546 /* Proxy texture: check for errors and update proxy state */
3547 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3548 internalFormat
, width
, 1, 1, border
, imageSize
);
3550 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3551 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3552 internalFormat
, GL_NONE
, GL_NONE
,
3553 width
, 1, 1, border
);
3556 /* if error, clear all proxy texture image parameters */
3557 struct gl_texture_image
*texImage
;
3558 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3560 clear_teximage_fields(texImage
);
3563 /* store the teximage parameters */
3564 struct gl_texture_unit
*texUnit
;
3565 struct gl_texture_object
*texObj
;
3566 struct gl_texture_image
*texImage
;
3567 texUnit
= get_current_tex_unit(ctx
);
3568 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3570 _mesa_lock_texture(ctx
, texObj
);
3572 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3573 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3574 border
, internalFormat
);
3576 _mesa_unlock_texture(ctx
, texObj
);
3580 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3587 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3588 GLenum internalFormat
, GLsizei width
,
3589 GLsizei height
, GLint border
, GLsizei imageSize
,
3592 GET_CURRENT_CONTEXT(ctx
);
3593 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3595 if (target
== GL_TEXTURE_2D
||
3596 (ctx
->Extensions
.ARB_texture_cube_map
&&
3597 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3598 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3599 /* non-proxy target */
3600 struct gl_texture_unit
*texUnit
;
3601 struct gl_texture_object
*texObj
;
3602 struct gl_texture_image
*texImage
;
3603 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3604 internalFormat
, width
, height
, 1, border
, imageSize
);
3606 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3610 texUnit
= get_current_tex_unit(ctx
);
3611 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3613 _mesa_lock_texture(ctx
, texObj
);
3615 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3617 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3621 if (texImage
->Data
) {
3622 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3624 ASSERT(texImage
->Data
== NULL
);
3626 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3627 border
, internalFormat
);
3629 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3630 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3631 internalFormat
, width
, height
,
3632 border
, imageSize
, data
,
3636 texObj
->_Complete
= GL_FALSE
;
3637 ctx
->NewState
|= _NEW_TEXTURE
;
3640 _mesa_unlock_texture(ctx
, texObj
);
3642 else if (target
== GL_PROXY_TEXTURE_2D
||
3643 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3644 ctx
->Extensions
.ARB_texture_cube_map
)) {
3645 /* Proxy texture: check for errors and update proxy state */
3646 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3647 internalFormat
, width
, height
, 1, border
, imageSize
);
3649 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3650 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3651 internalFormat
, GL_NONE
, GL_NONE
,
3652 width
, height
, 1, border
);
3655 /* if error, clear all proxy texture image parameters */
3656 struct gl_texture_image
*texImage
;
3657 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3659 clear_teximage_fields(texImage
);
3662 /* store the teximage parameters */
3663 struct gl_texture_unit
*texUnit
;
3664 struct gl_texture_object
*texObj
;
3665 struct gl_texture_image
*texImage
;
3666 texUnit
= get_current_tex_unit(ctx
);
3667 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3669 _mesa_lock_texture(ctx
, texObj
);
3671 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3672 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3673 border
, internalFormat
);
3675 _mesa_unlock_texture(ctx
, texObj
);
3679 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3686 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3687 GLenum internalFormat
, GLsizei width
,
3688 GLsizei height
, GLsizei depth
, GLint border
,
3689 GLsizei imageSize
, const GLvoid
*data
)
3691 GET_CURRENT_CONTEXT(ctx
);
3692 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3694 if (target
== GL_TEXTURE_3D
) {
3695 /* non-proxy target */
3696 struct gl_texture_unit
*texUnit
;
3697 struct gl_texture_object
*texObj
;
3698 struct gl_texture_image
*texImage
;
3699 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3700 internalFormat
, width
, height
, depth
, border
, imageSize
);
3702 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3706 texUnit
= get_current_tex_unit(ctx
);
3707 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3708 _mesa_lock_texture(ctx
, texObj
);
3710 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3712 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3716 if (texImage
->Data
) {
3717 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3719 ASSERT(texImage
->Data
== NULL
);
3721 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3722 border
, internalFormat
);
3724 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3725 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3727 width
, height
, depth
,
3728 border
, imageSize
, data
,
3732 texObj
->_Complete
= GL_FALSE
;
3733 ctx
->NewState
|= _NEW_TEXTURE
;
3736 _mesa_unlock_texture(ctx
, texObj
);
3738 else if (target
== GL_PROXY_TEXTURE_3D
) {
3739 /* Proxy texture: check for errors and update proxy state */
3740 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3741 internalFormat
, width
, height
, depth
, border
, imageSize
);
3743 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3744 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3745 internalFormat
, GL_NONE
, GL_NONE
,
3746 width
, height
, depth
, border
);
3749 /* if error, clear all proxy texture image parameters */
3750 struct gl_texture_image
*texImage
;
3751 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3753 clear_teximage_fields(texImage
);
3756 /* store the teximage parameters */
3757 struct gl_texture_unit
*texUnit
;
3758 struct gl_texture_object
*texObj
;
3759 struct gl_texture_image
*texImage
;
3760 texUnit
= get_current_tex_unit(ctx
);
3761 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3762 _mesa_lock_texture(ctx
, texObj
);
3764 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3765 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3766 depth
, border
, internalFormat
);
3768 _mesa_unlock_texture(ctx
, texObj
);
3772 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3779 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3780 GLsizei width
, GLenum format
,
3781 GLsizei imageSize
, const GLvoid
*data
)
3783 struct gl_texture_unit
*texUnit
;
3784 struct gl_texture_object
*texObj
;
3785 struct gl_texture_image
*texImage
;
3787 GET_CURRENT_CONTEXT(ctx
);
3788 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3790 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3791 xoffset
, 0, 0, /* pos */
3792 width
, 1, 1, /* size */
3795 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3799 texUnit
= get_current_tex_unit(ctx
);
3800 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3801 _mesa_lock_texture(ctx
, texObj
);
3803 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3806 if ((GLint
) format
!= texImage
->InternalFormat
) {
3807 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3808 "glCompressedTexSubImage1D(format)");
3812 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3813 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3818 goto out
; /* no-op, not an error */
3820 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3821 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3823 format
, imageSize
, data
,
3826 ctx
->NewState
|= _NEW_TEXTURE
;
3829 _mesa_unlock_texture(ctx
, texObj
);
3834 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3835 GLint yoffset
, GLsizei width
, GLsizei height
,
3836 GLenum format
, GLsizei imageSize
,
3839 struct gl_texture_unit
*texUnit
;
3840 struct gl_texture_object
*texObj
;
3841 struct gl_texture_image
*texImage
;
3843 GET_CURRENT_CONTEXT(ctx
);
3844 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3846 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3847 xoffset
, yoffset
, 0, /* pos */
3848 width
, height
, 1, /* size */
3851 /* XXX proxy target? */
3852 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3856 texUnit
= get_current_tex_unit(ctx
);
3857 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3858 _mesa_lock_texture(ctx
, texObj
);
3860 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3863 if ((GLint
) format
!= texImage
->InternalFormat
) {
3864 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3865 "glCompressedTexSubImage2D(format)");
3869 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3870 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3871 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3875 if (width
== 0 || height
== 0)
3876 goto out
; /* no-op, not an error */
3878 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3879 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3880 xoffset
, yoffset
, width
, height
,
3881 format
, imageSize
, data
,
3884 ctx
->NewState
|= _NEW_TEXTURE
;
3887 _mesa_unlock_texture(ctx
, texObj
);
3892 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3893 GLint yoffset
, GLint zoffset
, GLsizei width
,
3894 GLsizei height
, GLsizei depth
, GLenum format
,
3895 GLsizei imageSize
, const GLvoid
*data
)
3897 struct gl_texture_unit
*texUnit
;
3898 struct gl_texture_object
*texObj
;
3899 struct gl_texture_image
*texImage
;
3901 GET_CURRENT_CONTEXT(ctx
);
3902 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3904 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3905 xoffset
, yoffset
, zoffset
,/*pos*/
3906 width
, height
, depth
, /*size*/
3909 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3913 texUnit
= get_current_tex_unit(ctx
);
3914 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3915 _mesa_lock_texture(ctx
, texObj
);
3917 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3920 if ((GLint
) format
!= texImage
->InternalFormat
) {
3921 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3922 "glCompressedTexSubImage3D(format)");
3926 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3927 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3928 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3929 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3933 if (width
== 0 || height
== 0 || depth
== 0)
3934 goto out
; /* no-op, not an error */
3936 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3937 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3938 xoffset
, yoffset
, zoffset
,
3939 width
, height
, depth
,
3940 format
, imageSize
, data
,
3943 ctx
->NewState
|= _NEW_TEXTURE
;
3946 _mesa_unlock_texture(ctx
, texObj
);
3951 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3953 const struct gl_texture_unit
*texUnit
;
3954 struct gl_texture_object
*texObj
;
3955 struct gl_texture_image
*texImage
;
3957 GET_CURRENT_CONTEXT(ctx
);
3958 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3960 texUnit
= get_current_tex_unit(ctx
);
3961 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3963 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3967 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3968 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3970 if (level
< 0 || level
>= maxLevels
) {
3971 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3975 if (_mesa_is_proxy_texture(target
)) {
3976 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3980 _mesa_lock_texture(ctx
, texObj
);
3982 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3984 if (texImage
->IsCompressed
) {
3985 /* this typically calls _mesa_get_compressed_teximage() */
3986 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3990 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3991 "glGetCompressedTexImageARB");
3995 /* probably invalid mipmap level */
3996 _mesa_error(ctx
, GL_INVALID_VALUE
,
3997 "glGetCompressedTexImageARB(level)");
4000 _mesa_unlock_texture(ctx
, texObj
);