2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
39 #include "framebuffer.h"
44 #include "texcompress.h"
45 #include "texformat.h"
53 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
57 _mesa_alloc_texmemory(GLsizei bytes
)
59 return _mesa_align_malloc(bytes
, 512);
64 * Free texture memory allocated with _mesa_alloc_texmemory()
67 _mesa_free_texmemory(void *m
)
76 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
78 #if CHAN_TYPE != GL_UNSIGNED_BYTE
79 _mesa_problem(NULL
, "PrintTexture not supported");
82 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
85 _mesa_printf("No texture data\n");
89 switch (img
->Format
) {
96 case GL_LUMINANCE_ALPHA
:
106 _mesa_problem(NULL
, "error in PrintTexture\n");
110 for (i
= 0; i
< img
->Height
; i
++) {
111 for (j
= 0; j
< img
->Width
; j
++) {
113 _mesa_printf("%02x ", data
[0]);
115 _mesa_printf("%02x%02x ", data
[0], data
[1]);
117 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
119 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
120 data
+= (img
->RowStride
- img
->Width
) * c
;
122 /* XXX use img->ImageStride here */
131 * Compute floor(log_base_2(n)).
132 * If n < 0 return -1.
161 * Return the simple base format for a given internal texture format.
162 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
164 * \param ctx GL context.
165 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
167 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
168 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
170 * This is the format which is used during texture application (i.e. the
171 * texture format and env mode determine the arithmetic used.
174 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
176 switch (internalFormat
) {
191 case GL_LUMINANCE_ALPHA
:
192 case GL_LUMINANCE4_ALPHA4
:
193 case GL_LUMINANCE6_ALPHA2
:
194 case GL_LUMINANCE8_ALPHA8
:
195 case GL_LUMINANCE12_ALPHA4
:
196 case GL_LUMINANCE12_ALPHA12
:
197 case GL_LUMINANCE16_ALPHA16
:
198 return GL_LUMINANCE_ALPHA
;
229 if (ctx
->Extensions
.EXT_paletted_texture
) {
230 switch (internalFormat
) {
232 case GL_COLOR_INDEX1_EXT
:
233 case GL_COLOR_INDEX2_EXT
:
234 case GL_COLOR_INDEX4_EXT
:
235 case GL_COLOR_INDEX8_EXT
:
236 case GL_COLOR_INDEX12_EXT
:
237 case GL_COLOR_INDEX16_EXT
:
238 return GL_COLOR_INDEX
;
244 if (ctx
->Extensions
.SGIX_depth_texture
||
245 ctx
->Extensions
.ARB_depth_texture
) {
246 switch (internalFormat
) {
247 case GL_DEPTH_COMPONENT
:
248 case GL_DEPTH_COMPONENT16_SGIX
:
249 case GL_DEPTH_COMPONENT24_SGIX
:
250 case GL_DEPTH_COMPONENT32_SGIX
:
251 return GL_DEPTH_COMPONENT
;
257 if (ctx
->Extensions
.ARB_texture_compression
) {
258 switch (internalFormat
) {
259 case GL_COMPRESSED_ALPHA
:
261 case GL_COMPRESSED_LUMINANCE
:
263 case GL_COMPRESSED_LUMINANCE_ALPHA
:
264 return GL_LUMINANCE_ALPHA
;
265 case GL_COMPRESSED_INTENSITY
:
267 case GL_COMPRESSED_RGB
:
269 case GL_COMPRESSED_RGBA
:
276 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
277 switch (internalFormat
) {
278 case GL_COMPRESSED_RGB_FXT1_3DFX
:
280 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
287 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
288 switch (internalFormat
) {
289 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
291 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
292 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
293 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
300 if (ctx
->Extensions
.S3_s3tc
) {
301 switch (internalFormat
) {
313 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
314 if (internalFormat
== GL_YCBCR_MESA
)
315 return GL_YCBCR_MESA
;
318 if (ctx
->Extensions
.ARB_texture_float
) {
319 switch (internalFormat
) {
320 case GL_ALPHA16F_ARB
:
321 case GL_ALPHA32F_ARB
:
329 case GL_INTENSITY16F_ARB
:
330 case GL_INTENSITY32F_ARB
:
332 case GL_LUMINANCE16F_ARB
:
333 case GL_LUMINANCE32F_ARB
:
335 case GL_LUMINANCE_ALPHA16F_ARB
:
336 case GL_LUMINANCE_ALPHA32F_ARB
:
337 return GL_LUMINANCE_ALPHA
;
343 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
344 switch (internalFormat
) {
345 case GL_DEPTH_STENCIL_EXT
:
346 case GL_DEPTH24_STENCIL8_EXT
:
347 return GL_DEPTH_STENCIL_EXT
;
353 #if FEATURE_EXT_texture_sRGB
354 if (ctx
->Extensions
.EXT_texture_sRGB
) {
355 switch (internalFormat
) {
358 case GL_COMPRESSED_SRGB_EXT
:
359 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
361 case GL_SRGB_ALPHA_EXT
:
362 case GL_SRGB8_ALPHA8_EXT
:
363 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
364 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
365 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
366 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
368 case GL_SLUMINANCE_ALPHA_EXT
:
369 case GL_SLUMINANCE8_ALPHA8_EXT
:
370 case GL_COMPRESSED_SLUMINANCE_EXT
:
371 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
372 return GL_LUMINANCE_ALPHA
;
373 case GL_SLUMINANCE_EXT
:
374 case GL_SLUMINANCE8_EXT
:
381 #endif /* FEATURE_EXT_texture_sRGB */
383 return -1; /* error */
388 * Test if the given image format is a color/RGBA format (i.e., not color
389 * index, depth, stencil, etc).
390 * \param format the image format value (may by an internal texture format)
391 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
394 is_color_format(GLenum format
)
412 case GL_LUMINANCE_ALPHA
:
413 case GL_LUMINANCE4_ALPHA4
:
414 case GL_LUMINANCE6_ALPHA2
:
415 case GL_LUMINANCE8_ALPHA8
:
416 case GL_LUMINANCE12_ALPHA4
:
417 case GL_LUMINANCE12_ALPHA12
:
418 case GL_LUMINANCE16_ALPHA16
:
445 /* float texture formats */
446 case GL_ALPHA16F_ARB
:
447 case GL_ALPHA32F_ARB
:
448 case GL_LUMINANCE16F_ARB
:
449 case GL_LUMINANCE32F_ARB
:
450 case GL_LUMINANCE_ALPHA16F_ARB
:
451 case GL_LUMINANCE_ALPHA32F_ARB
:
452 case GL_INTENSITY16F_ARB
:
453 case GL_INTENSITY32F_ARB
:
458 /* compressed formats */
459 case GL_COMPRESSED_ALPHA
:
460 case GL_COMPRESSED_LUMINANCE
:
461 case GL_COMPRESSED_LUMINANCE_ALPHA
:
462 case GL_COMPRESSED_INTENSITY
:
463 case GL_COMPRESSED_RGB
:
464 case GL_COMPRESSED_RGBA
:
469 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
470 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
471 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
472 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
473 case GL_COMPRESSED_RGB_FXT1_3DFX
:
474 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
475 #if FEATURE_EXT_texture_sRGB
478 case GL_SRGB_ALPHA_EXT
:
479 case GL_SRGB8_ALPHA8_EXT
:
480 case GL_SLUMINANCE_ALPHA_EXT
:
481 case GL_SLUMINANCE8_ALPHA8_EXT
:
482 case GL_SLUMINANCE_EXT
:
483 case GL_SLUMINANCE8_EXT
:
484 case GL_COMPRESSED_SRGB_EXT
:
485 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
486 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
487 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
488 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
489 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
490 case GL_COMPRESSED_SLUMINANCE_EXT
:
491 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
492 #endif /* FEATURE_EXT_texture_sRGB */
494 case GL_YCBCR_MESA
: /* not considered to be RGB */
502 * Test if the given image format is a color index format.
505 is_index_format(GLenum format
)
509 case GL_COLOR_INDEX1_EXT
:
510 case GL_COLOR_INDEX2_EXT
:
511 case GL_COLOR_INDEX4_EXT
:
512 case GL_COLOR_INDEX8_EXT
:
513 case GL_COLOR_INDEX12_EXT
:
514 case GL_COLOR_INDEX16_EXT
:
523 * Test if the given image format is a depth component format.
526 is_depth_format(GLenum format
)
529 case GL_DEPTH_COMPONENT16_ARB
:
530 case GL_DEPTH_COMPONENT24_ARB
:
531 case GL_DEPTH_COMPONENT32_ARB
:
532 case GL_DEPTH_COMPONENT
:
541 * Test if the given image format is a YCbCr format.
544 is_ycbcr_format(GLenum format
)
556 * Test if the given image format is a Depth/Stencil format.
559 is_depthstencil_format(GLenum format
)
562 case GL_DEPTH24_STENCIL8_EXT
:
563 case GL_DEPTH_STENCIL_EXT
:
573 * Test if it is a supported compressed format.
575 * \param internalFormat the internal format token provided by the user.
577 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
578 * GL_FALSE otherwise.
580 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
584 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
586 GLint supported
[100]; /* 100 should be plenty */
589 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
591 for (i
= 0; i
< n
; i
++) {
592 if ((GLint
) internalFormat
== supported
[i
]) {
601 texture_face(GLenum target
)
603 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
604 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
605 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
613 * Store a gl_texture_image pointer in a gl_texture_object structure
614 * according to the target and level parameters.
616 * \param tObj texture object.
617 * \param target texture target.
618 * \param level image level.
619 * \param texImage texture image.
621 * This was basically prompted by the introduction of cube maps.
624 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
625 GLenum target
, GLint level
,
626 struct gl_texture_image
*texImage
)
634 case GL_TEXTURE_1D_ARRAY_EXT
:
635 case GL_TEXTURE_2D_ARRAY_EXT
:
636 tObj
->Image
[0][level
] = texImage
;
638 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
639 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
640 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
641 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
642 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
643 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
645 GLuint face
= ((GLuint
) target
-
646 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
647 tObj
->Image
[face
][level
] = texImage
;
650 case GL_TEXTURE_RECTANGLE_NV
:
652 tObj
->Image
[0][level
] = texImage
;
655 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
658 /* Set the 'back' pointer */
659 texImage
->TexObject
= tObj
;
664 * Allocate a texture image structure.
666 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
669 * \return a pointer to gl_texture_image struct with all fields initialized to
672 struct gl_texture_image
*
673 _mesa_new_texture_image( GLcontext
*ctx
)
676 return CALLOC_STRUCT(gl_texture_image
);
681 * Free texture image data.
682 * This function is a fallback called via ctx->Driver.FreeTexImageData().
684 * \param teximage texture image.
686 * Free the texture image data if it's not marked as client data.
689 _mesa_free_texture_image_data(GLcontext
*ctx
,
690 struct gl_texture_image
*texImage
)
694 if (texImage
->Data
&& !texImage
->IsClientData
) {
695 /* free the old texture data */
696 _mesa_free_texmemory(texImage
->Data
);
699 texImage
->Data
= NULL
;
704 * Free texture image.
706 * \param teximage texture image.
708 * Free the texture image structure and the associated image data.
711 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
713 /* Free texImage->Data and/or any other driver-specific texture
716 ASSERT(ctx
->Driver
.FreeTexImageData
);
717 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
719 ASSERT(texImage
->Data
== NULL
);
720 if (texImage
->ImageOffsets
)
721 _mesa_free(texImage
->ImageOffsets
);
722 _mesa_free(texImage
);
727 * Test if a target is a proxy target.
729 * \param target texture target.
731 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
734 _mesa_is_proxy_texture(GLenum target
)
736 return (target
== GL_PROXY_TEXTURE_1D
||
737 target
== GL_PROXY_TEXTURE_2D
||
738 target
== GL_PROXY_TEXTURE_3D
||
739 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
740 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
741 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
742 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
747 * Get the texture object that corresponds to the target of the given texture unit.
749 * \param ctx GL context.
750 * \param texUnit texture unit.
751 * \param target texture target.
753 * \return pointer to the texture object on success, or NULL on failure.
755 * \sa gl_texture_unit.
757 struct gl_texture_object
*
758 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
763 return texUnit
->Current1D
;
764 case GL_PROXY_TEXTURE_1D
:
765 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
767 return texUnit
->Current2D
;
768 case GL_PROXY_TEXTURE_2D
:
769 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
771 return texUnit
->Current3D
;
772 case GL_PROXY_TEXTURE_3D
:
773 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
774 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
775 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
776 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
777 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
778 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
779 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
780 case GL_TEXTURE_CUBE_MAP_ARB
:
781 return ctx
->Extensions
.ARB_texture_cube_map
782 ? texUnit
->CurrentCubeMap
: NULL
;
783 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
784 return ctx
->Extensions
.ARB_texture_cube_map
785 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
786 case GL_TEXTURE_RECTANGLE_NV
:
787 return ctx
->Extensions
.NV_texture_rectangle
788 ? texUnit
->CurrentRect
: NULL
;
789 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
790 return ctx
->Extensions
.NV_texture_rectangle
791 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
792 case GL_TEXTURE_1D_ARRAY_EXT
:
793 return ctx
->Extensions
.MESA_texture_array
794 ? texUnit
->Current1DArray
: NULL
;
795 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
796 return ctx
->Extensions
.MESA_texture_array
797 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
798 case GL_TEXTURE_2D_ARRAY_EXT
:
799 return ctx
->Extensions
.MESA_texture_array
800 ? texUnit
->Current2DArray
: NULL
;
801 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
802 return ctx
->Extensions
.MESA_texture_array
803 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
805 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
812 * Get the texture image struct which corresponds to target and level
813 * of the given texture unit.
815 * \param ctx GL context.
816 * \param texUnit texture unit.
817 * \param target texture target.
818 * \param level image level.
820 * \return pointer to the texture image structure on success, or NULL on failure.
822 * \sa gl_texture_unit.
824 struct gl_texture_image
*
825 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
826 GLenum target
, GLint level
)
830 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
)
835 case GL_PROXY_TEXTURE_1D
:
837 case GL_PROXY_TEXTURE_2D
:
839 case GL_PROXY_TEXTURE_3D
:
840 return texObj
->Image
[0][level
];
842 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
843 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
844 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
845 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
846 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
847 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
848 if (ctx
->Extensions
.ARB_texture_cube_map
) {
849 GLuint face
= ((GLuint
) target
-
850 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
851 return texObj
->Image
[face
][level
];
856 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
857 if (ctx
->Extensions
.ARB_texture_cube_map
)
858 return texObj
->Image
[0][level
];
862 case GL_TEXTURE_RECTANGLE_NV
:
863 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
864 if (ctx
->Extensions
.NV_texture_rectangle
&& level
== 0)
865 return texObj
->Image
[0][level
];
869 case GL_TEXTURE_1D_ARRAY_EXT
:
870 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
871 case GL_TEXTURE_2D_ARRAY_EXT
:
872 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
873 return (ctx
->Extensions
.MESA_texture_array
)
874 ? texObj
->Image
[0][level
] : NULL
;
883 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
884 * it and install it. Only return NULL if passed a bad parameter or run
887 struct gl_texture_image
*
888 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
889 GLenum target
, GLint level
)
891 struct gl_texture_image
*texImage
;
896 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
898 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
900 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
904 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
912 * Return pointer to the specified proxy texture image.
913 * Note that proxy textures are per-context, not per-texture unit.
914 * \return pointer to texture image or NULL if invalid target, invalid
915 * level, or out of memory.
917 struct gl_texture_image
*
918 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
920 struct gl_texture_image
*texImage
;
926 case GL_PROXY_TEXTURE_1D
:
927 if (level
>= ctx
->Const
.MaxTextureLevels
)
929 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
]->Image
[0][level
];
931 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
933 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
936 ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
]->Image
[0][level
] = texImage
;
937 /* Set the 'back' pointer */
938 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
941 case GL_PROXY_TEXTURE_2D
:
942 if (level
>= ctx
->Const
.MaxTextureLevels
)
944 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
];
946 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
948 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
951 ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
] = texImage
;
952 /* Set the 'back' pointer */
953 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
956 case GL_PROXY_TEXTURE_3D
:
957 if (level
>= ctx
->Const
.Max3DTextureLevels
)
959 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
]->Image
[0][level
];
961 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
963 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
966 ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
]->Image
[0][level
] = texImage
;
967 /* Set the 'back' pointer */
968 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
971 case GL_PROXY_TEXTURE_CUBE_MAP
:
972 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
974 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
]->Image
[0][level
];
976 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
978 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
981 ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
]->Image
[0][level
] = texImage
;
982 /* Set the 'back' pointer */
983 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
];
986 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
989 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
]->Image
[0][level
];
991 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
993 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
996 ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
]->Image
[0][level
] = texImage
;
997 /* Set the 'back' pointer */
998 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
];
1001 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1002 if (level
>= ctx
->Const
.MaxTextureLevels
)
1004 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
]->Image
[0][level
];
1006 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1008 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1011 ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
]->Image
[0][level
] = texImage
;
1012 /* Set the 'back' pointer */
1013 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
];
1016 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1017 if (level
>= ctx
->Const
.MaxTextureLevels
)
1019 texImage
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
]->Image
[0][level
];
1021 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1023 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1026 ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
]->Image
[0][level
] = texImage
;
1027 /* Set the 'back' pointer */
1028 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
];
1038 * Get the maximum number of allowed mipmap levels.
1040 * \param ctx GL context.
1041 * \param target texture target.
1043 * \return the maximum number of allowed mipmap levels for the given
1044 * texture target, or zero if passed a bad target.
1049 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
1053 case GL_PROXY_TEXTURE_1D
:
1055 case GL_PROXY_TEXTURE_2D
:
1056 case GL_TEXTURE_1D_ARRAY_EXT
:
1057 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1058 case GL_TEXTURE_2D_ARRAY_EXT
:
1059 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1060 return ctx
->Const
.MaxTextureLevels
;
1062 case GL_PROXY_TEXTURE_3D
:
1063 return ctx
->Const
.Max3DTextureLevels
;
1064 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1065 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1066 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1067 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1068 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1069 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1070 case GL_TEXTURE_CUBE_MAP_ARB
:
1071 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1072 return ctx
->Const
.MaxCubeTextureLevels
;
1073 case GL_TEXTURE_RECTANGLE_NV
:
1074 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1077 return 0; /* bad target */
1083 #if 000 /* not used anymore */
1085 * glTexImage[123]D can accept a NULL image pointer. In this case we
1086 * create a texture image with unspecified image contents per the OpenGL
1090 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1092 const GLint components
= _mesa_components_in_format(format
);
1093 const GLint numPixels
= width
* height
* depth
;
1094 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1098 * Let's see if anyone finds this. If glTexImage2D() is called with
1099 * a NULL image pointer then load the texture image with something
1100 * interesting instead of leaving it indeterminate.
1103 static const char message
[8][32] = {
1104 " X X XXXXX XXX X ",
1105 " XX XX X X X X X ",
1107 " X X XXXX XXX XXXXX ",
1110 " X X XXXXX XXX X X ",
1114 GLubyte
*imgPtr
= data
;
1116 for (h
= 0; h
< depth
; h
++) {
1117 for (i
= 0; i
< height
; i
++) {
1118 GLint srcRow
= 7 - (i
% 8);
1119 for (j
= 0; j
< width
; j
++) {
1120 GLint srcCol
= j
% 32;
1121 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1122 for (k
= 0; k
< components
; k
++) {
1138 * Reset the fields of a gl_texture_image struct to zero.
1140 * \param img texture image structure.
1142 * This is called when a proxy texture test fails, we set all the
1143 * image members (except DriverData) to zero.
1144 * It's also used in glTexImage[123]D as a safeguard to be sure all
1145 * required fields get initialized properly by the Driver.TexImage[123]D
1149 clear_teximage_fields(struct gl_texture_image
*img
)
1152 img
->_BaseFormat
= 0;
1153 img
->InternalFormat
= 0;
1159 if (img
->ImageOffsets
) {
1160 _mesa_free(img
->ImageOffsets
);
1161 img
->ImageOffsets
= NULL
;
1167 img
->HeightLog2
= 0;
1170 img
->TexFormat
= &_mesa_null_texformat
;
1171 img
->FetchTexelc
= NULL
;
1172 img
->FetchTexelf
= NULL
;
1173 img
->IsCompressed
= 0;
1174 img
->CompressedSize
= 0;
1179 * Initialize basic fields of the gl_texture_image struct.
1181 * \param ctx GL context.
1182 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1183 * \param img texture image structure to be initialized.
1184 * \param width image width.
1185 * \param height image height.
1186 * \param depth image depth.
1187 * \param border image border.
1188 * \param internalFormat internal format.
1190 * Fills in the fields of \p img with the given information.
1191 * Note: width, height and depth include the border.
1194 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1195 struct gl_texture_image
*img
,
1196 GLsizei width
, GLsizei height
, GLsizei depth
,
1197 GLint border
, GLenum internalFormat
)
1203 ASSERT(height
>= 0);
1206 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1207 ASSERT(img
->_BaseFormat
> 0);
1208 img
->InternalFormat
= internalFormat
;
1209 img
->Border
= border
;
1211 img
->Height
= height
;
1213 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1214 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1215 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1216 img
->WidthLog2
= logbase2(img
->Width2
);
1217 if (height
== 1) /* 1-D texture */
1218 img
->HeightLog2
= 0;
1220 img
->HeightLog2
= logbase2(img
->Height2
);
1221 if (depth
== 1) /* 2-D texture */
1224 img
->DepthLog2
= logbase2(img
->Depth2
);
1225 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1226 img
->IsCompressed
= GL_FALSE
;
1227 img
->CompressedSize
= 0;
1229 if ((width
== 1 || _mesa_bitcount(img
->Width2
) == 1) &&
1230 (height
== 1 || _mesa_bitcount(img
->Height2
) == 1) &&
1231 (depth
== 1 || _mesa_bitcount(img
->Depth2
) == 1))
1232 img
->_IsPowerOfTwo
= GL_TRUE
;
1234 img
->_IsPowerOfTwo
= GL_FALSE
;
1236 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1237 img
->RowStride
= width
;
1238 /* Allocate the ImageOffsets array and initialize to typical values.
1239 * We allocate the array for 1D/2D textures too in order to avoid special-
1240 * case code in the texstore routines.
1242 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1243 for (i
= 0; i
< depth
; i
++) {
1244 img
->ImageOffsets
[i
] = i
* width
* height
;
1247 /* Compute Width/Height/DepthScale for mipmap lod computation */
1248 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1249 /* scale = 1.0 since texture coords directly map to texels */
1250 img
->WidthScale
= 1.0;
1251 img
->HeightScale
= 1.0;
1252 img
->DepthScale
= 1.0;
1255 img
->WidthScale
= (GLfloat
) img
->Width
;
1256 img
->HeightScale
= (GLfloat
) img
->Height
;
1257 img
->DepthScale
= (GLfloat
) img
->Depth
;
1263 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1264 * level, width, height and depth against the ctx->Const limits for textures.
1266 * A hardware driver might override this function if, for example, the
1267 * max 3D texture size is 512x512x64 (i.e. not a cube).
1269 * Note that width, height, depth == 0 is not an error. However, a
1270 * texture with zero width/height/depth will be considered "incomplete"
1271 * and texturing will effectively be disabled.
1273 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1274 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1275 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1276 * \param level as passed to glTexImage
1277 * \param internalFormat as passed to glTexImage
1278 * \param format as passed to glTexImage
1279 * \param type as passed to glTexImage
1280 * \param width as passed to glTexImage
1281 * \param height as passed to glTexImage
1282 * \param depth as passed to glTexImage
1283 * \param border as passed to glTexImage
1284 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1287 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1288 GLint internalFormat
, GLenum format
, GLenum type
,
1289 GLint width
, GLint height
, GLint depth
, GLint border
)
1293 (void) internalFormat
;
1298 case GL_PROXY_TEXTURE_1D
:
1299 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1300 if (width
< 2 * border
|| width
> 2 + maxSize
||
1301 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1302 width
>0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1303 level
>= ctx
->Const
.MaxTextureLevels
) {
1304 /* bad width or level */
1308 case GL_PROXY_TEXTURE_2D
:
1309 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1310 if (width
< 2 * border
|| width
> 2 + maxSize
||
1311 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1312 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1313 height
< 2 * border
|| height
> 2 + maxSize
||
1314 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1315 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1316 level
>= ctx
->Const
.MaxTextureLevels
) {
1317 /* bad width or height or level */
1321 case GL_PROXY_TEXTURE_3D
:
1322 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1323 if (width
< 2 * border
|| width
> 2 + maxSize
||
1324 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1325 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1326 height
< 2 * border
|| height
> 2 + maxSize
||
1327 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1328 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1329 depth
< 2 * border
|| depth
> 2 + maxSize
||
1330 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1331 depth
> 0 && _mesa_bitcount(depth
- 2 * border
) != 1) ||
1332 level
>= ctx
->Const
.Max3DTextureLevels
) {
1333 /* bad width or height or depth or level */
1337 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1338 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1339 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1341 /* bad width or height or level */
1345 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1346 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1347 if (width
< 2 * border
|| width
> 2 + maxSize
||
1348 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1349 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1350 height
< 2 * border
|| height
> 2 + maxSize
||
1351 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1352 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1353 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1354 /* bad width or height */
1358 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1359 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1360 if (width
< 2 * border
|| width
> 2 + maxSize
||
1361 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1362 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1363 level
>= ctx
->Const
.MaxTextureLevels
) {
1364 /* bad width or level */
1368 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1372 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1373 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1374 if (width
< 2 * border
|| width
> 2 + maxSize
||
1375 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1376 width
> 0 && _mesa_bitcount(width
- 2 * border
) != 1) ||
1377 height
< 2 * border
|| height
> 2 + maxSize
||
1378 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1379 height
> 0 && _mesa_bitcount(height
- 2 * border
) != 1) ||
1380 level
>= ctx
->Const
.MaxTextureLevels
) {
1381 /* bad width or height or level */
1384 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1389 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1396 * Helper function to determine whether a target supports compressed textures
1399 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1401 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1402 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1403 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1404 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1405 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1406 || ((ctx
->Extensions
.MESA_texture_array
&&
1407 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1408 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1413 * Test the glTexImage[123]D() parameters for errors.
1415 * \param ctx GL context.
1416 * \param target texture target given by the user.
1417 * \param level image level given by the user.
1418 * \param internalFormat internal format given by the user.
1419 * \param format pixel data format given by the user.
1420 * \param type pixel data type given by the user.
1421 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1422 * \param width image width given by the user.
1423 * \param height image height given by the user.
1424 * \param depth image depth given by the user.
1425 * \param border image border given by the user.
1427 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1429 * Verifies each of the parameters against the constants specified in
1430 * __GLcontextRec::Const and the supported extensions, and according to the
1431 * OpenGL specification.
1434 texture_error_check( GLcontext
*ctx
, GLenum target
,
1435 GLint level
, GLint internalFormat
,
1436 GLenum format
, GLenum type
,
1438 GLint width
, GLint height
,
1439 GLint depth
, GLint border
)
1441 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1442 GLboolean sizeOK
= GL_TRUE
;
1443 GLboolean colorFormat
, indexFormat
;
1444 GLenum proxy_target
;
1446 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1447 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1449 _mesa_error(ctx
, GL_INVALID_VALUE
,
1450 "glTexImage%dD(level=%d)", dimensions
, level
);
1456 if (border
< 0 || border
> 1 ||
1457 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1458 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1460 _mesa_error(ctx
, GL_INVALID_VALUE
,
1461 "glTexImage%dD(border=%d)", dimensions
, border
);
1466 if (width
< 0 || height
< 0 || depth
< 0) {
1468 _mesa_error(ctx
, GL_INVALID_VALUE
,
1469 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1474 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1475 * level, width, height and depth.
1477 if (dimensions
== 1) {
1478 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1479 proxy_target
= GL_PROXY_TEXTURE_1D
;
1484 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1488 else if (dimensions
== 2) {
1490 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1491 proxy_target
= GL_PROXY_TEXTURE_2D
;
1493 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1494 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1495 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1496 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1497 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1500 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1501 sizeOK
= (width
== height
);
1503 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1504 target
== GL_TEXTURE_RECTANGLE_NV
) {
1505 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1506 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1509 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1511 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1512 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1513 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1516 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1520 else if (dimensions
== 3) {
1521 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1522 proxy_target
= GL_PROXY_TEXTURE_3D
;
1524 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1525 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1526 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1529 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1534 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1538 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1539 internalFormat
, format
,
1540 type
, width
, height
,
1544 _mesa_error(ctx
, GL_INVALID_VALUE
,
1545 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1546 dimensions
, level
, width
, height
, depth
);
1551 /* Check internalFormat */
1552 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1554 _mesa_error(ctx
, GL_INVALID_VALUE
,
1555 "glTexImage%dD(internalFormat=0x%x)",
1556 dimensions
, internalFormat
);
1561 /* Check incoming image format and type */
1562 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1563 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1564 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1567 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1568 "glTexImage%dD(format or type)", dimensions
);
1573 /* make sure internal format and format basically agree */
1574 colorFormat
= is_color_format(format
);
1575 indexFormat
= is_index_format(format
);
1576 if ((is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1577 (is_index_format(internalFormat
) && !indexFormat
) ||
1578 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1579 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1580 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
))) {
1582 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1583 "glTexImage(internalFormat/format)");
1587 /* additional checks for ycbcr textures */
1588 if (internalFormat
== GL_YCBCR_MESA
) {
1589 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1590 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1591 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1593 _mesa_sprintf(message
,
1594 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1595 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1596 return GL_TRUE
; /* error */
1598 if (target
!= GL_TEXTURE_2D
&&
1599 target
!= GL_PROXY_TEXTURE_2D
&&
1600 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1601 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1603 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1609 _mesa_sprintf(message
,
1610 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1611 dimensions
, border
);
1612 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1618 /* additional checks for depth textures */
1619 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1620 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1621 if (target
!= GL_TEXTURE_1D
&&
1622 target
!= GL_PROXY_TEXTURE_1D
&&
1623 target
!= GL_TEXTURE_2D
&&
1624 target
!= GL_PROXY_TEXTURE_2D
&&
1625 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1626 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1628 _mesa_error(ctx
, GL_INVALID_ENUM
,
1629 "glTexImage(target/internalFormat)");
1634 /* additional checks for compressed textures */
1635 if (is_compressed_format(ctx
, internalFormat
)) {
1636 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1637 _mesa_error(ctx
, GL_INVALID_ENUM
,
1638 "glTexImage%d(target)", dimensions
);
1643 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1644 "glTexImage%D(border!=0)", dimensions
);
1650 /* if we get here, the parameters are OK */
1656 * Test glTexSubImage[123]D() parameters for errors.
1658 * \param ctx GL context.
1659 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1660 * \param target texture target given by the user.
1661 * \param level image level given by the user.
1662 * \param xoffset sub-image x offset given by the user.
1663 * \param yoffset sub-image y offset given by the user.
1664 * \param zoffset sub-image z offset given by the user.
1665 * \param format pixel data format given by the user.
1666 * \param type pixel data type given by the user.
1667 * \param width image width given by the user.
1668 * \param height image height given by the user.
1669 * \param depth image depth given by the user.
1671 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1673 * Verifies each of the parameters against the constants specified in
1674 * __GLcontextRec::Const and the supported extensions, and according to the
1675 * OpenGL specification.
1678 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1679 GLenum target
, GLint level
,
1680 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1681 GLint width
, GLint height
, GLint depth
,
1682 GLenum format
, GLenum type
)
1685 if (dimensions
== 1) {
1686 if (target
!= GL_TEXTURE_1D
) {
1687 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1691 else if (dimensions
== 2) {
1692 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1693 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1694 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1695 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1699 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1700 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1701 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1705 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1706 if (!ctx
->Extensions
.MESA_texture_array
) {
1707 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1711 else if (target
!= GL_TEXTURE_2D
) {
1712 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1716 else if (dimensions
== 3) {
1717 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1718 if (!ctx
->Extensions
.MESA_texture_array
) {
1719 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1723 else if (target
!= GL_TEXTURE_3D
) {
1724 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1729 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1733 /* Basic level check */
1734 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1735 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1740 _mesa_error(ctx
, GL_INVALID_VALUE
,
1741 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1744 if (height
< 0 && dimensions
> 1) {
1745 _mesa_error(ctx
, GL_INVALID_VALUE
,
1746 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1749 if (depth
< 0 && dimensions
> 2) {
1750 _mesa_error(ctx
, GL_INVALID_VALUE
,
1751 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1755 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1756 _mesa_error(ctx
, GL_INVALID_ENUM
,
1757 "glTexSubImage%dD(format or type)", dimensions
);
1765 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1766 GLenum target
, GLint level
,
1767 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1768 GLint width
, GLint height
, GLint depth
,
1769 GLenum format
, GLenum type
,
1770 const struct gl_texture_image
*destTex
)
1773 /* undefined image level */
1774 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1778 if (xoffset
< -((GLint
)destTex
->Border
)) {
1779 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1783 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1784 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1788 if (dimensions
> 1) {
1789 if (yoffset
< -((GLint
)destTex
->Border
)) {
1790 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1794 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1795 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1800 if (dimensions
> 2) {
1801 if (zoffset
< -((GLint
)destTex
->Border
)) {
1802 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1805 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1806 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1811 #if FEATURE_EXT_texture_sRGB
1812 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1813 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1814 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1815 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1816 if ((width
& 0x3) || (height
& 0x3) ||
1817 (xoffset
& 0x3) || (yoffset
& 0x3))
1818 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1819 "glTexSubImage%dD(size or offset not multiple of 4)",
1825 if (destTex
->IsCompressed
) {
1826 if (!target_can_be_compressed(ctx
, target
)) {
1827 _mesa_error(ctx
, GL_INVALID_ENUM
,
1828 "glTexSubImage%D(target)", dimensions
);
1831 /* offset must be multiple of 4 */
1832 if ((xoffset
& 3) || (yoffset
& 3)) {
1833 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1834 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1837 /* size must be multiple of 4 or equal to whole texture size */
1838 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1839 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1840 "glTexSubImage%D(width)", dimensions
);
1843 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1844 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1845 "glTexSubImage%D(width)", dimensions
);
1855 * Test glCopyTexImage[12]D() parameters for errors.
1857 * \param ctx GL context.
1858 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1859 * \param target texture target given by the user.
1860 * \param level image level given by the user.
1861 * \param internalFormat internal format given by the user.
1862 * \param width image width given by the user.
1863 * \param height image height given by the user.
1864 * \param depth image depth given by the user.
1865 * \param border texture border.
1867 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1869 * Verifies each of the parameters against the constants specified in
1870 * __GLcontextRec::Const and the supported extensions, and according to the
1871 * OpenGL specification.
1874 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1875 GLenum target
, GLint level
, GLint internalFormat
,
1876 GLint width
, GLint height
, GLint border
)
1882 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1883 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1884 _mesa_error(ctx
, GL_INVALID_VALUE
,
1885 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1889 /* Check that the source buffer is complete */
1890 if (ctx
->ReadBuffer
->Name
) {
1891 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1892 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1893 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1894 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1900 if (border
< 0 || border
> 1 ||
1901 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1902 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1906 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1908 _mesa_error(ctx
, GL_INVALID_VALUE
,
1909 "glCopyTexImage%dD(internalFormat)", dimensions
);
1913 /* NOTE: the format and type aren't really significant for
1914 * TestProxyTexImage(). Only the internalformat really matters.
1915 if (!_mesa_source_buffer_exists(ctx, format)) {
1916 _mesa_error(ctx, GL_INVALID_OPERATION,
1917 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1924 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1925 * level, width, height and depth.
1927 if (dimensions
== 1) {
1928 if (target
== GL_TEXTURE_1D
) {
1929 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1930 level
, internalFormat
,
1932 width
, 1, 1, border
);
1935 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1939 else if (dimensions
== 2) {
1940 if (target
== GL_TEXTURE_2D
) {
1941 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1942 level
, internalFormat
,
1944 width
, height
, 1, border
);
1946 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1947 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1948 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1949 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1952 sizeOK
= (width
== height
) &&
1953 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1954 level
, internalFormat
, format
, type
,
1955 width
, height
, 1, border
);
1957 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1958 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1959 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1962 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1963 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1964 level
, internalFormat
,
1966 width
, height
, 1, border
);
1968 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1969 if (!ctx
->Extensions
.MESA_texture_array
) {
1970 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1973 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1974 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1975 level
, internalFormat
,
1977 width
, height
, 1, border
);
1980 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1985 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1990 if (dimensions
== 1) {
1991 _mesa_error(ctx
, GL_INVALID_VALUE
,
1992 "glCopyTexImage1D(width=%d)", width
);
1995 ASSERT(dimensions
== 2);
1996 _mesa_error(ctx
, GL_INVALID_VALUE
,
1997 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2002 if (is_compressed_format(ctx
, internalFormat
)) {
2003 if (!target_can_be_compressed(ctx
, target
)) {
2004 _mesa_error(ctx
, GL_INVALID_ENUM
,
2005 "glCopyTexImage%d(target)", dimensions
);
2009 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2010 "glCopyTexImage%D(border!=0)", dimensions
);
2014 else if (is_depth_format(internalFormat
)) {
2015 /* make sure we have depth/stencil buffers */
2016 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2017 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2018 "glCopyTexImage%D(no depth)", dimensions
);
2022 else if (is_depthstencil_format(internalFormat
)) {
2023 /* make sure we have depth/stencil buffers */
2024 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2025 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2026 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2031 /* if we get here, the parameters are OK */
2037 * Test glCopyTexSubImage[12]D() parameters for errors.
2039 * \param ctx GL context.
2040 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2041 * \param target texture target given by the user.
2042 * \param level image level given by the user.
2043 * \param xoffset sub-image x offset given by the user.
2044 * \param yoffset sub-image y offset given by the user.
2045 * \param zoffset sub-image z offset given by the user.
2046 * \param width image width given by the user.
2047 * \param height image height given by the user.
2049 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2051 * Verifies each of the parameters against the constants specified in
2052 * __GLcontextRec::Const and the supported extensions, and according to the
2053 * OpenGL specification.
2056 copytexsubimage_error_check( GLcontext
*ctx
, GLuint dimensions
,
2057 GLenum target
, GLint level
,
2058 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2059 GLsizei width
, GLsizei height
)
2062 /* Check that the source buffer is complete */
2063 if (ctx
->ReadBuffer
->Name
) {
2064 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2065 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2066 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2067 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2072 if (dimensions
== 1) {
2073 if (target
!= GL_TEXTURE_1D
) {
2074 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2078 else if (dimensions
== 2) {
2079 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2080 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2081 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2082 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2086 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2087 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2088 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2092 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2093 if (!ctx
->Extensions
.MESA_texture_array
) {
2094 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2098 else if (target
!= GL_TEXTURE_2D
) {
2099 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2103 else if (dimensions
== 3) {
2104 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2105 (!ctx
->Extensions
.MESA_texture_array
))
2106 && (target
!= GL_TEXTURE_3D
)) {
2107 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2113 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2114 _mesa_error(ctx
, GL_INVALID_VALUE
,
2115 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2121 _mesa_error(ctx
, GL_INVALID_VALUE
,
2122 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2125 if (dimensions
> 1 && height
< 0) {
2126 _mesa_error(ctx
, GL_INVALID_VALUE
,
2127 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2135 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2136 GLenum target
, GLint level
,
2137 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2138 GLsizei width
, GLsizei height
,
2139 const struct gl_texture_image
*teximage
)
2142 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2143 "glCopyTexSubImage%dD(undefined texture level: %d)",
2148 if (xoffset
< -((GLint
)teximage
->Border
)) {
2149 _mesa_error(ctx
, GL_INVALID_VALUE
,
2150 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2153 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2154 _mesa_error(ctx
, GL_INVALID_VALUE
,
2155 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2158 if (dimensions
> 1) {
2159 if (yoffset
< -((GLint
)teximage
->Border
)) {
2160 _mesa_error(ctx
, GL_INVALID_VALUE
,
2161 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2164 /* NOTE: we're adding the border here, not subtracting! */
2165 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2166 _mesa_error(ctx
, GL_INVALID_VALUE
,
2167 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2172 if (dimensions
> 2) {
2173 if (zoffset
< -((GLint
)teximage
->Border
)) {
2174 _mesa_error(ctx
, GL_INVALID_VALUE
,
2175 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2178 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2179 _mesa_error(ctx
, GL_INVALID_VALUE
,
2180 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2185 if (teximage
->IsCompressed
) {
2186 if (!target_can_be_compressed(ctx
, target
)) {
2187 _mesa_error(ctx
, GL_INVALID_ENUM
,
2188 "glCopyTexSubImage%d(target)", dimensions
);
2191 /* offset must be multiple of 4 */
2192 if ((xoffset
& 3) || (yoffset
& 3)) {
2193 _mesa_error(ctx
, GL_INVALID_VALUE
,
2194 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2197 /* size must be multiple of 4 */
2198 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2199 _mesa_error(ctx
, GL_INVALID_VALUE
,
2200 "glCopyTexSubImage%D(width)", dimensions
);
2203 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2204 _mesa_error(ctx
, GL_INVALID_VALUE
,
2205 "glCopyTexSubImage%D(height)", dimensions
);
2210 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2211 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2215 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2216 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2217 "glCopyTexSubImage%dD(missing readbuffer)", dimensions
);
2221 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2222 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2223 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2224 "glCopyTexSubImage%D(no depth buffer)",
2229 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2230 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2231 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2232 "glCopyTexSubImage%D(no depth/stencil buffer)",
2238 /* if we get here, the parameters are OK */
2244 * Get texture image. Called by glGetTexImage.
2246 * \param target texture target.
2247 * \param level image level.
2248 * \param format pixel data format for returned image.
2249 * \param type pixel data type for returned image.
2250 * \param pixels returned pixel data.
2253 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2254 GLenum type
, GLvoid
*pixels
)
2256 const struct gl_texture_unit
*texUnit
;
2257 struct gl_texture_object
*texObj
;
2258 struct gl_texture_image
*texImage
;
2259 GLint maxLevels
= 0;
2260 GET_CURRENT_CONTEXT(ctx
);
2261 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2263 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2264 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2265 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2266 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2270 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2271 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2273 if (level
< 0 || level
>= maxLevels
) {
2274 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2278 if (_mesa_sizeof_packed_type(type
) <= 0) {
2279 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2283 if (_mesa_components_in_format(format
) <= 0 ||
2284 format
== GL_STENCIL_INDEX
) {
2285 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2289 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2290 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2294 if (!ctx
->Extensions
.SGIX_depth_texture
&&
2295 !ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2296 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2300 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2301 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2305 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2306 && is_depthstencil_format(format
)) {
2307 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2311 _mesa_lock_texture(ctx
, texObj
);
2313 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2315 /* invalid mipmap level, not an error */
2320 /* Make sure the requested image format is compatible with the
2321 * texture's format. Note that a color index texture can be converted
2322 * to RGBA so that combo is allowed.
2324 if (is_color_format(format
)
2325 && !is_color_format(texImage
->TexFormat
->BaseFormat
)
2326 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2327 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2330 else if (is_index_format(format
)
2331 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2332 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2335 else if (is_depth_format(format
)
2336 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2337 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2338 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2341 else if (is_ycbcr_format(format
)
2342 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2343 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2346 else if (is_depthstencil_format(format
)
2347 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2348 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2352 if (ctx
->Pack
.BufferObj
->Name
) {
2353 /* packing texture image into a PBO */
2354 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2355 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2356 texImage
->Height
, texImage
->Depth
,
2357 format
, type
, pixels
)) {
2358 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2359 "glGetTexImage(invalid PBO access)");
2364 /* typically, this will call _mesa_get_teximage() */
2365 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2370 _mesa_unlock_texture(ctx
, texObj
);
2376 * Check if the given texture image is bound to any framebuffer objects
2377 * and update/invalidate them.
2378 * XXX We're only checking the currently bound framebuffer object for now.
2379 * In the future, perhaps struct gl_texture_image should have a pointer (or
2380 * list of pointers (yikes)) to the gl_framebuffer(s) which it's bound to.
2383 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2384 GLuint face
, GLuint level
)
2386 if (ctx
->DrawBuffer
->Name
) {
2388 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2389 struct gl_renderbuffer_attachment
*att
=
2390 ctx
->DrawBuffer
->Attachment
+ i
;
2391 if (att
->Type
== GL_TEXTURE
&&
2392 att
->Texture
== texObj
&&
2393 att
->TextureLevel
== level
&&
2394 att
->CubeMapFace
== face
) {
2395 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2396 /* Tell driver about the new renderbuffer texture */
2397 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2406 * Called from the API. Note that width includes the border.
2409 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2410 GLsizei width
, GLint border
, GLenum format
,
2411 GLenum type
, const GLvoid
*pixels
)
2413 GLsizei postConvWidth
= width
;
2414 GET_CURRENT_CONTEXT(ctx
);
2415 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2417 #if FEATURE_convolve
2418 if (is_color_format(internalFormat
)) {
2419 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2423 if (target
== GL_TEXTURE_1D
) {
2424 /* non-proxy target */
2425 struct gl_texture_unit
*texUnit
;
2426 struct gl_texture_object
*texObj
;
2427 struct gl_texture_image
*texImage
;
2428 const GLuint face
= texture_face(target
);
2430 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2431 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2432 return; /* error was recorded */
2435 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2436 _mesa_update_state(ctx
);
2438 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2439 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2440 _mesa_lock_texture(ctx
, texObj
);
2442 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2444 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2448 if (texImage
->Data
) {
2449 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2452 ASSERT(texImage
->Data
== NULL
);
2454 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2455 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2456 postConvWidth
, 1, 1,
2457 border
, internalFormat
);
2459 ASSERT(ctx
->Driver
.TexImage1D
);
2461 /* Give the texture to the driver! <pixels> may be null! */
2462 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2463 width
, border
, format
, type
, pixels
,
2464 &ctx
->Unpack
, texObj
, texImage
);
2466 ASSERT(texImage
->TexFormat
);
2468 update_fbo_texture(ctx
, texObj
, face
, level
);
2471 texObj
->_Complete
= GL_FALSE
;
2472 ctx
->NewState
|= _NEW_TEXTURE
;
2475 _mesa_unlock_texture(ctx
, texObj
);
2477 else if (target
== GL_PROXY_TEXTURE_1D
) {
2478 /* Proxy texture: check for errors and update proxy state */
2479 struct gl_texture_image
*texImage
;
2480 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2481 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2482 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2483 /* when error, clear all proxy texture image parameters */
2485 clear_teximage_fields(texImage
);
2488 /* no error, set the tex image parameters */
2490 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2491 postConvWidth
, 1, 1,
2492 border
, internalFormat
);
2493 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2494 internalFormat
, format
, type
);
2498 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2505 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2506 GLsizei width
, GLsizei height
, GLint border
,
2507 GLenum format
, GLenum type
,
2508 const GLvoid
*pixels
)
2510 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2511 GET_CURRENT_CONTEXT(ctx
);
2512 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2514 #if FEATURE_convolve
2515 if (is_color_format(internalFormat
)) {
2516 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2521 if (target
== GL_TEXTURE_2D
||
2522 (ctx
->Extensions
.ARB_texture_cube_map
&&
2523 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2524 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2525 (ctx
->Extensions
.NV_texture_rectangle
&&
2526 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2527 (ctx
->Extensions
.MESA_texture_array
&&
2528 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2529 /* non-proxy target */
2530 struct gl_texture_unit
*texUnit
;
2531 struct gl_texture_object
*texObj
;
2532 struct gl_texture_image
*texImage
;
2533 const GLuint face
= texture_face(target
);
2535 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2536 format
, type
, 2, postConvWidth
, postConvHeight
,
2538 return; /* error was recorded */
2541 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2542 _mesa_update_state(ctx
);
2544 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2545 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2546 _mesa_lock_texture(ctx
, texObj
);
2548 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2550 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2554 if (texImage
->Data
) {
2555 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2558 ASSERT(texImage
->Data
== NULL
);
2559 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2560 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2561 postConvWidth
, postConvHeight
, 1,
2562 border
, internalFormat
);
2564 ASSERT(ctx
->Driver
.TexImage2D
);
2566 /* Give the texture to the driver! <pixels> may be null! */
2567 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2568 width
, height
, border
, format
, type
, pixels
,
2569 &ctx
->Unpack
, texObj
, texImage
);
2571 ASSERT(texImage
->TexFormat
);
2573 update_fbo_texture(ctx
, texObj
, face
, level
);
2576 texObj
->_Complete
= GL_FALSE
;
2577 ctx
->NewState
|= _NEW_TEXTURE
;
2580 _mesa_unlock_texture(ctx
, texObj
);
2582 else if (target
== GL_PROXY_TEXTURE_2D
||
2583 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2584 ctx
->Extensions
.ARB_texture_cube_map
) ||
2585 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2586 ctx
->Extensions
.NV_texture_rectangle
) ||
2587 (ctx
->Extensions
.MESA_texture_array
&&
2588 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2589 /* Proxy texture: check for errors and update proxy state */
2590 struct gl_texture_image
*texImage
;
2591 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2592 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2593 format
, type
, 2, postConvWidth
, postConvHeight
,
2595 /* when error, clear all proxy texture image parameters */
2597 clear_teximage_fields(ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
]->Image
[0][level
]);
2600 /* no error, set the tex image parameters */
2601 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2602 postConvWidth
, postConvHeight
, 1,
2603 border
, internalFormat
);
2604 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2605 internalFormat
, format
, type
);
2609 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2616 * Called by the API or display list executor.
2617 * Note that width and height include the border.
2620 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2621 GLsizei width
, GLsizei height
, GLsizei depth
,
2622 GLint border
, GLenum format
, GLenum type
,
2623 const GLvoid
*pixels
)
2625 GET_CURRENT_CONTEXT(ctx
);
2626 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2628 if (target
== GL_TEXTURE_3D
||
2629 (ctx
->Extensions
.MESA_texture_array
&&
2630 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2631 /* non-proxy target */
2632 struct gl_texture_unit
*texUnit
;
2633 struct gl_texture_object
*texObj
;
2634 struct gl_texture_image
*texImage
;
2635 const GLuint face
= texture_face(target
);
2637 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2638 format
, type
, 3, width
, height
, depth
, border
)) {
2639 return; /* error was recorded */
2642 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2643 _mesa_update_state(ctx
);
2645 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2646 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2647 _mesa_lock_texture(ctx
, texObj
);
2649 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2651 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2655 if (texImage
->Data
) {
2656 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2659 ASSERT(texImage
->Data
== NULL
);
2660 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2661 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2662 width
, height
, depth
,
2663 border
, internalFormat
);
2665 ASSERT(ctx
->Driver
.TexImage3D
);
2667 /* Give the texture to the driver! <pixels> may be null! */
2668 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2669 width
, height
, depth
, border
, format
, type
,
2670 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2672 ASSERT(texImage
->TexFormat
);
2674 update_fbo_texture(ctx
, texObj
, face
, level
);
2677 texObj
->_Complete
= GL_FALSE
;
2678 ctx
->NewState
|= _NEW_TEXTURE
;
2681 _mesa_unlock_texture(ctx
, texObj
);
2683 else if (target
== GL_PROXY_TEXTURE_3D
||
2684 (ctx
->Extensions
.MESA_texture_array
&&
2685 target
== GL_PROXY_TEXTURE_2D_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
, 3, width
, height
, depth
, border
)) {
2691 /* when error, clear all proxy texture image parameters */
2693 clear_teximage_fields(texImage
);
2696 /* no error, set the tex image parameters */
2697 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2698 depth
, border
, internalFormat
);
2699 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2700 internalFormat
, format
, type
);
2704 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2711 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2712 GLsizei width
, GLsizei height
, GLsizei depth
,
2713 GLint border
, GLenum format
, GLenum type
,
2714 const GLvoid
*pixels
)
2716 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2717 depth
, border
, format
, type
, pixels
);
2723 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2724 GLint xoffset
, GLsizei width
,
2725 GLenum format
, GLenum type
,
2726 const GLvoid
*pixels
)
2728 GLsizei postConvWidth
= width
;
2729 struct gl_texture_unit
*texUnit
;
2730 struct gl_texture_object
*texObj
;
2731 struct gl_texture_image
*texImage
= NULL
;
2732 GET_CURRENT_CONTEXT(ctx
);
2733 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2735 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2736 _mesa_update_state(ctx
);
2738 #if FEATURE_convolve
2739 /* XXX should test internal format */
2740 if (is_color_format(format
)) {
2741 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2745 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2746 postConvWidth
, 1, 1, format
, type
)) {
2747 return; /* error was detected */
2751 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2752 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2755 _mesa_lock_texture(ctx
, texObj
);
2757 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2759 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2760 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2761 goto out
; /* error was detected */
2765 goto out
; /* no-op, not an error */
2767 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2768 xoffset
+= texImage
->Border
;
2770 ASSERT(ctx
->Driver
.TexSubImage1D
);
2771 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2772 format
, type
, pixels
, &ctx
->Unpack
,
2774 ctx
->NewState
|= _NEW_TEXTURE
;
2777 _mesa_unlock_texture(ctx
, texObj
);
2782 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2783 GLint xoffset
, GLint yoffset
,
2784 GLsizei width
, GLsizei height
,
2785 GLenum format
, GLenum type
,
2786 const GLvoid
*pixels
)
2788 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2789 struct gl_texture_unit
*texUnit
;
2790 struct gl_texture_object
*texObj
;
2791 struct gl_texture_image
*texImage
;
2792 GET_CURRENT_CONTEXT(ctx
);
2793 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2795 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2796 _mesa_update_state(ctx
);
2798 #if FEATURE_convolve
2799 /* XXX should test internal format */
2800 if (is_color_format(format
)) {
2801 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2806 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2807 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2808 return; /* error was detected */
2811 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2812 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2813 _mesa_lock_texture(ctx
, texObj
);
2815 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2817 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2818 postConvWidth
, postConvHeight
, 1, format
, type
,
2820 goto out
; /* error was detected */
2823 if (width
== 0 || height
== 0)
2824 goto out
; /* no-op, not an error */
2826 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2827 xoffset
+= texImage
->Border
;
2828 yoffset
+= texImage
->Border
;
2830 ASSERT(ctx
->Driver
.TexSubImage2D
);
2831 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2832 width
, height
, format
, type
, pixels
,
2833 &ctx
->Unpack
, texObj
, texImage
);
2834 ctx
->NewState
|= _NEW_TEXTURE
;
2837 _mesa_unlock_texture(ctx
, texObj
);
2843 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2844 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2845 GLsizei width
, GLsizei height
, GLsizei depth
,
2846 GLenum format
, GLenum type
,
2847 const GLvoid
*pixels
)
2849 struct gl_texture_unit
*texUnit
;
2850 struct gl_texture_object
*texObj
;
2851 struct gl_texture_image
*texImage
;
2852 GET_CURRENT_CONTEXT(ctx
);
2853 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2855 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2856 _mesa_update_state(ctx
);
2858 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2859 width
, height
, depth
, format
, type
)) {
2860 return; /* error was detected */
2863 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2864 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2866 _mesa_lock_texture(ctx
, texObj
);
2868 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2870 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2871 width
, height
, depth
, format
, type
, texImage
)) {
2872 goto out
; /* error was detected */
2875 if (width
== 0 || height
== 0 || height
== 0)
2876 goto out
; /* no-op, not an error */
2878 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2879 xoffset
+= texImage
->Border
;
2880 yoffset
+= texImage
->Border
;
2881 zoffset
+= texImage
->Border
;
2883 ASSERT(ctx
->Driver
.TexSubImage3D
);
2884 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2885 xoffset
, yoffset
, zoffset
,
2886 width
, height
, depth
,
2887 format
, type
, pixels
,
2888 &ctx
->Unpack
, texObj
, texImage
);
2889 ctx
->NewState
|= _NEW_TEXTURE
;
2892 _mesa_unlock_texture(ctx
, texObj
);
2898 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2899 GLenum internalFormat
,
2901 GLsizei width
, GLint border
)
2903 struct gl_texture_unit
*texUnit
;
2904 struct gl_texture_object
*texObj
;
2905 struct gl_texture_image
*texImage
;
2906 GLsizei postConvWidth
= width
;
2907 const GLuint face
= texture_face(target
);
2908 GET_CURRENT_CONTEXT(ctx
);
2909 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2911 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2912 _mesa_update_state(ctx
);
2914 #if FEATURE_convolve
2915 if (is_color_format(internalFormat
)) {
2916 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2920 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2921 postConvWidth
, 1, border
))
2924 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2925 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2926 _mesa_lock_texture(ctx
, texObj
);
2928 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2930 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2934 if (texImage
->Data
) {
2935 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2938 ASSERT(texImage
->Data
== NULL
);
2940 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2941 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2942 border
, internalFormat
);
2945 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2946 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2947 x
, y
, width
, border
);
2949 ASSERT(texImage
->TexFormat
);
2951 update_fbo_texture(ctx
, texObj
, face
, level
);
2954 texObj
->_Complete
= GL_FALSE
;
2955 ctx
->NewState
|= _NEW_TEXTURE
;
2958 _mesa_unlock_texture(ctx
, texObj
);
2964 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2965 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2968 struct gl_texture_unit
*texUnit
;
2969 struct gl_texture_object
*texObj
;
2970 struct gl_texture_image
*texImage
;
2971 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2972 const GLuint face
= texture_face(target
);
2973 GET_CURRENT_CONTEXT(ctx
);
2974 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2976 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
2977 _mesa_update_state(ctx
);
2979 #if FEATURE_convolve
2980 if (is_color_format(internalFormat
)) {
2981 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2985 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2986 postConvWidth
, postConvHeight
, border
))
2989 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2990 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2992 _mesa_lock_texture(ctx
, texObj
);
2994 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2997 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3001 if (texImage
->Data
) {
3002 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3005 ASSERT(texImage
->Data
== NULL
);
3007 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3008 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3009 postConvWidth
, postConvHeight
, 1,
3010 border
, internalFormat
);
3012 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3013 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3014 x
, y
, width
, height
, border
);
3016 ASSERT(texImage
->TexFormat
);
3018 update_fbo_texture(ctx
, texObj
, face
, level
);
3021 texObj
->_Complete
= GL_FALSE
;
3022 ctx
->NewState
|= _NEW_TEXTURE
;
3025 _mesa_unlock_texture(ctx
, texObj
);
3030 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3031 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3033 struct gl_texture_unit
*texUnit
;
3034 struct gl_texture_object
*texObj
;
3035 struct gl_texture_image
*texImage
;
3036 GLsizei postConvWidth
= width
;
3037 GET_CURRENT_CONTEXT(ctx
);
3038 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3040 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3041 _mesa_update_state(ctx
);
3043 #if FEATURE_convolve
3044 /* XXX should test internal format */
3045 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3048 if (copytexsubimage_error_check(ctx
, 1, target
, level
,
3049 xoffset
, 0, 0, postConvWidth
, 1))
3052 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3053 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3055 _mesa_lock_texture(ctx
, texObj
);
3057 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3059 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3060 xoffset
, 0, 0, postConvWidth
, 1,
3065 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3066 xoffset
+= texImage
->Border
;
3068 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3069 (*ctx
->Driver
.CopyTexSubImage1D
)(ctx
, target
, level
, xoffset
, x
, y
, width
);
3070 ctx
->NewState
|= _NEW_TEXTURE
;
3073 _mesa_unlock_texture(ctx
, texObj
);
3079 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3080 GLint xoffset
, GLint yoffset
,
3081 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3083 struct gl_texture_unit
*texUnit
;
3084 struct gl_texture_object
*texObj
;
3085 struct gl_texture_image
*texImage
;
3086 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3087 GET_CURRENT_CONTEXT(ctx
);
3088 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3090 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3091 _mesa_update_state(ctx
);
3093 #if FEATURE_convolve
3094 /* XXX should test internal format */
3095 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
3098 if (copytexsubimage_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3099 postConvWidth
, postConvHeight
))
3102 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3103 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3105 _mesa_lock_texture(ctx
, texObj
);
3107 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3109 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3110 postConvWidth
, postConvHeight
, texImage
))
3113 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3114 xoffset
+= texImage
->Border
;
3115 yoffset
+= texImage
->Border
;
3117 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3118 (*ctx
->Driver
.CopyTexSubImage2D
)(ctx
, target
, level
,
3119 xoffset
, yoffset
, x
, y
, width
, height
);
3120 ctx
->NewState
|= _NEW_TEXTURE
;
3123 _mesa_unlock_texture(ctx
, texObj
);
3129 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3130 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3131 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3133 struct gl_texture_unit
*texUnit
;
3134 struct gl_texture_object
*texObj
;
3135 struct gl_texture_image
*texImage
;
3136 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3137 GET_CURRENT_CONTEXT(ctx
);
3138 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3140 if (ctx
->NewState
& _IMAGE_NEW_TRANSFER_STATE
)
3141 _mesa_update_state(ctx
);
3143 #if FEATURE_convolve
3144 /* XXX should test internal format */
3145 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
, &postConvHeight
);
3148 if (copytexsubimage_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
,
3149 zoffset
, postConvWidth
, postConvHeight
))
3152 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3153 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3155 _mesa_lock_texture(ctx
, texObj
);
3157 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3159 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3160 zoffset
, postConvWidth
, postConvHeight
,
3164 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3165 xoffset
+= texImage
->Border
;
3166 yoffset
+= texImage
->Border
;
3167 zoffset
+= texImage
->Border
;
3169 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3170 (*ctx
->Driver
.CopyTexSubImage3D
)(ctx
, target
, level
,
3171 xoffset
, yoffset
, zoffset
,
3172 x
, y
, width
, height
);
3173 ctx
->NewState
|= _NEW_TEXTURE
;
3176 _mesa_unlock_texture(ctx
, texObj
);
3182 /**********************************************************************/
3183 /****** Compressed Textures ******/
3184 /**********************************************************************/
3188 * Error checking for glCompressedTexImage[123]D().
3189 * \return error code or GL_NO_ERROR.
3192 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3193 GLenum target
, GLint level
,
3194 GLenum internalFormat
, GLsizei width
,
3195 GLsizei height
, GLsizei depth
, GLint border
,
3198 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3200 if (dimensions
== 1) {
3201 /* 1D compressed textures not allowed */
3202 return GL_INVALID_ENUM
;
3204 else if (dimensions
== 2) {
3205 if (target
== GL_PROXY_TEXTURE_2D
) {
3206 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3208 else if (target
== GL_TEXTURE_2D
) {
3209 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3211 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3212 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3213 return GL_INVALID_ENUM
; /*target*/
3214 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3216 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3217 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3218 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3219 return GL_INVALID_ENUM
; /*target*/
3220 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3223 return GL_INVALID_ENUM
; /*target*/
3226 else if (dimensions
== 3) {
3227 /* 3D compressed textures not allowed */
3228 return GL_INVALID_ENUM
;
3231 maxTextureSize
= 1 << (maxLevels
- 1);
3233 /* This will detect any invalid internalFormat value */
3234 if (!is_compressed_format(ctx
, internalFormat
))
3235 return GL_INVALID_ENUM
;
3237 /* This should really never fail */
3238 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3239 return GL_INVALID_ENUM
;
3242 return GL_INVALID_VALUE
;
3245 * XXX We should probably use the proxy texture error check function here.
3247 if (width
< 1 || width
> maxTextureSize
||
3248 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(width
) != 1))
3249 return GL_INVALID_VALUE
;
3251 if ((height
< 1 || height
> maxTextureSize
||
3252 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(height
) != 1))
3254 return GL_INVALID_VALUE
;
3256 if ((depth
< 1 || depth
> maxTextureSize
||
3257 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& _mesa_bitcount(depth
) != 1))
3259 return GL_INVALID_VALUE
;
3261 /* For cube map, width must equal height */
3262 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3263 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3264 return GL_INVALID_VALUE
;
3266 if (level
< 0 || level
>= maxLevels
)
3267 return GL_INVALID_VALUE
;
3269 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3270 depth
, internalFormat
);
3271 if (expectedSize
!= imageSize
)
3272 return GL_INVALID_VALUE
;
3274 #if FEATURE_EXT_texture_sRGB
3275 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3276 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3277 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3278 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3280 return GL_INVALID_OPERATION
;
3289 * Error checking for glCompressedTexSubImage[123]D().
3290 * \warning There are some bad assumptions here about the size of compressed
3291 * texture tiles (multiple of 4) used to test the validity of the
3292 * offset and size parameters.
3293 * \return error code or GL_NO_ERROR.
3296 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3297 GLenum target
, GLint level
,
3298 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3299 GLsizei width
, GLsizei height
, GLsizei depth
,
3300 GLenum format
, GLsizei imageSize
)
3302 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3305 if (dimensions
== 1) {
3306 /* 1D compressed textures not allowed */
3307 return GL_INVALID_ENUM
;
3309 else if (dimensions
== 2) {
3310 if (target
== GL_PROXY_TEXTURE_2D
) {
3311 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3313 else if (target
== GL_TEXTURE_2D
) {
3314 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3316 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3317 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3318 return GL_INVALID_ENUM
; /*target*/
3319 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3321 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3322 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3323 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3324 return GL_INVALID_ENUM
; /*target*/
3325 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3328 return GL_INVALID_ENUM
; /*target*/
3331 else if (dimensions
== 3) {
3332 /* 3D compressed textures not allowed */
3333 return GL_INVALID_ENUM
;
3336 maxTextureSize
= 1 << (maxLevels
- 1);
3338 /* this will catch any invalid compressed format token */
3339 if (!is_compressed_format(ctx
, format
))
3340 return GL_INVALID_ENUM
;
3342 if (width
< 1 || width
> maxTextureSize
)
3343 return GL_INVALID_VALUE
;
3345 if ((height
< 1 || height
> maxTextureSize
)
3347 return GL_INVALID_VALUE
;
3349 if (level
< 0 || level
>= maxLevels
)
3350 return GL_INVALID_VALUE
;
3352 /* XXX these tests are specific to the compressed format.
3353 * this code should be generalized in some way.
3355 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3356 return GL_INVALID_VALUE
;
3358 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3359 return GL_INVALID_VALUE
;
3361 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3362 return GL_INVALID_VALUE
;
3364 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3366 if (expectedSize
!= imageSize
)
3367 return GL_INVALID_VALUE
;
3375 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3376 GLenum internalFormat
, GLsizei width
,
3377 GLint border
, GLsizei imageSize
,
3380 GET_CURRENT_CONTEXT(ctx
);
3381 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3383 if (target
== GL_TEXTURE_1D
) {
3384 /* non-proxy target */
3385 struct gl_texture_unit
*texUnit
;
3386 struct gl_texture_object
*texObj
;
3387 struct gl_texture_image
*texImage
;
3388 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3389 internalFormat
, width
, 1, 1, border
, imageSize
);
3391 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3395 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3396 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3398 _mesa_lock_texture(ctx
, texObj
);
3400 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3402 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3406 if (texImage
->Data
) {
3407 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3409 ASSERT(texImage
->Data
== NULL
);
3411 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3412 border
, internalFormat
);
3414 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3415 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3416 internalFormat
, width
, border
,
3421 texObj
->_Complete
= GL_FALSE
;
3422 ctx
->NewState
|= _NEW_TEXTURE
;
3425 _mesa_unlock_texture(ctx
, texObj
);
3427 else if (target
== GL_PROXY_TEXTURE_1D
) {
3428 /* Proxy texture: check for errors and update proxy state */
3429 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3430 internalFormat
, width
, 1, 1, border
, imageSize
);
3432 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3433 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3434 internalFormat
, GL_NONE
, GL_NONE
,
3435 width
, 1, 1, border
);
3438 /* if error, clear all proxy texture image parameters */
3439 struct gl_texture_image
*texImage
;
3440 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3442 clear_teximage_fields(texImage
);
3445 /* store the teximage parameters */
3446 struct gl_texture_unit
*texUnit
;
3447 struct gl_texture_object
*texObj
;
3448 struct gl_texture_image
*texImage
;
3449 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3450 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3452 _mesa_lock_texture(ctx
, texObj
);
3454 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3455 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3456 border
, internalFormat
);
3458 _mesa_unlock_texture(ctx
, texObj
);
3462 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3469 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3470 GLenum internalFormat
, GLsizei width
,
3471 GLsizei height
, GLint border
, GLsizei imageSize
,
3474 GET_CURRENT_CONTEXT(ctx
);
3475 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3477 if (target
== GL_TEXTURE_2D
||
3478 (ctx
->Extensions
.ARB_texture_cube_map
&&
3479 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3480 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3481 /* non-proxy target */
3482 struct gl_texture_unit
*texUnit
;
3483 struct gl_texture_object
*texObj
;
3484 struct gl_texture_image
*texImage
;
3485 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3486 internalFormat
, width
, height
, 1, border
, imageSize
);
3488 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3492 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3493 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3495 _mesa_lock_texture(ctx
, texObj
);
3497 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3499 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3503 if (texImage
->Data
) {
3504 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3506 ASSERT(texImage
->Data
== NULL
);
3508 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3509 border
, internalFormat
);
3511 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3512 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3513 internalFormat
, width
, height
,
3514 border
, imageSize
, data
,
3518 texObj
->_Complete
= GL_FALSE
;
3519 ctx
->NewState
|= _NEW_TEXTURE
;
3522 _mesa_unlock_texture(ctx
, texObj
);
3524 else if (target
== GL_PROXY_TEXTURE_2D
||
3525 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3526 ctx
->Extensions
.ARB_texture_cube_map
)) {
3527 /* Proxy texture: check for errors and update proxy state */
3528 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3529 internalFormat
, width
, height
, 1, border
, imageSize
);
3531 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3532 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3533 internalFormat
, GL_NONE
, GL_NONE
,
3534 width
, height
, 1, border
);
3537 /* if error, clear all proxy texture image parameters */
3538 struct gl_texture_image
*texImage
;
3539 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3541 clear_teximage_fields(texImage
);
3544 /* store the teximage parameters */
3545 struct gl_texture_unit
*texUnit
;
3546 struct gl_texture_object
*texObj
;
3547 struct gl_texture_image
*texImage
;
3548 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3549 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3551 _mesa_lock_texture(ctx
, texObj
);
3553 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3554 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3555 border
, internalFormat
);
3557 _mesa_unlock_texture(ctx
, texObj
);
3561 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3568 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3569 GLenum internalFormat
, GLsizei width
,
3570 GLsizei height
, GLsizei depth
, GLint border
,
3571 GLsizei imageSize
, const GLvoid
*data
)
3573 GET_CURRENT_CONTEXT(ctx
);
3574 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3576 if (target
== GL_TEXTURE_3D
) {
3577 /* non-proxy target */
3578 struct gl_texture_unit
*texUnit
;
3579 struct gl_texture_object
*texObj
;
3580 struct gl_texture_image
*texImage
;
3581 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3582 internalFormat
, width
, height
, depth
, border
, imageSize
);
3584 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3588 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3589 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3590 _mesa_lock_texture(ctx
, texObj
);
3592 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3594 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3598 if (texImage
->Data
) {
3599 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3601 ASSERT(texImage
->Data
== NULL
);
3603 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3604 border
, internalFormat
);
3606 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3607 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3609 width
, height
, depth
,
3610 border
, imageSize
, data
,
3614 texObj
->_Complete
= GL_FALSE
;
3615 ctx
->NewState
|= _NEW_TEXTURE
;
3618 _mesa_unlock_texture(ctx
, texObj
);
3620 else if (target
== GL_PROXY_TEXTURE_3D
) {
3621 /* Proxy texture: check for errors and update proxy state */
3622 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3623 internalFormat
, width
, height
, depth
, border
, imageSize
);
3625 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3626 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3627 internalFormat
, GL_NONE
, GL_NONE
,
3628 width
, height
, depth
, border
);
3631 /* if error, clear all proxy texture image parameters */
3632 struct gl_texture_image
*texImage
;
3633 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3635 clear_teximage_fields(texImage
);
3638 /* store the teximage parameters */
3639 struct gl_texture_unit
*texUnit
;
3640 struct gl_texture_object
*texObj
;
3641 struct gl_texture_image
*texImage
;
3642 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3643 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3644 _mesa_lock_texture(ctx
, texObj
);
3646 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3647 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3648 depth
, border
, internalFormat
);
3650 _mesa_unlock_texture(ctx
, texObj
);
3654 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3661 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3662 GLsizei width
, GLenum format
,
3663 GLsizei imageSize
, const GLvoid
*data
)
3665 struct gl_texture_unit
*texUnit
;
3666 struct gl_texture_object
*texObj
;
3667 struct gl_texture_image
*texImage
;
3669 GET_CURRENT_CONTEXT(ctx
);
3670 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3672 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3673 xoffset
, 0, 0, /* pos */
3674 width
, 1, 1, /* size */
3677 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3681 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3682 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3683 _mesa_lock_texture(ctx
, texObj
);
3685 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3688 if ((GLint
) format
!= texImage
->InternalFormat
) {
3689 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3690 "glCompressedTexSubImage1D(format)");
3694 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3695 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3700 goto out
; /* no-op, not an error */
3702 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3703 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3705 format
, imageSize
, data
,
3708 ctx
->NewState
|= _NEW_TEXTURE
;
3711 _mesa_unlock_texture(ctx
, texObj
);
3716 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3717 GLint yoffset
, GLsizei width
, GLsizei height
,
3718 GLenum format
, GLsizei imageSize
,
3721 struct gl_texture_unit
*texUnit
;
3722 struct gl_texture_object
*texObj
;
3723 struct gl_texture_image
*texImage
;
3725 GET_CURRENT_CONTEXT(ctx
);
3726 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3728 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3729 xoffset
, yoffset
, 0, /* pos */
3730 width
, height
, 1, /* size */
3733 /* XXX proxy target? */
3734 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3738 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3739 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3740 _mesa_lock_texture(ctx
, texObj
);
3742 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3745 if ((GLint
) format
!= texImage
->InternalFormat
) {
3746 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3747 "glCompressedTexSubImage2D(format)");
3751 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3752 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3753 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3757 if (width
== 0 || height
== 0)
3758 goto out
; /* no-op, not an error */
3760 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3761 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3762 xoffset
, yoffset
, width
, height
,
3763 format
, imageSize
, data
,
3766 ctx
->NewState
|= _NEW_TEXTURE
;
3769 _mesa_unlock_texture(ctx
, texObj
);
3774 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3775 GLint yoffset
, GLint zoffset
, GLsizei width
,
3776 GLsizei height
, GLsizei depth
, GLenum format
,
3777 GLsizei imageSize
, const GLvoid
*data
)
3779 struct gl_texture_unit
*texUnit
;
3780 struct gl_texture_object
*texObj
;
3781 struct gl_texture_image
*texImage
;
3783 GET_CURRENT_CONTEXT(ctx
);
3784 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3786 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3787 xoffset
, yoffset
, zoffset
,/*pos*/
3788 width
, height
, depth
, /*size*/
3791 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3795 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3796 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3797 _mesa_lock_texture(ctx
, texObj
);
3799 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3802 if ((GLint
) format
!= texImage
->InternalFormat
) {
3803 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3804 "glCompressedTexSubImage3D(format)");
3808 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3809 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3810 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3811 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3815 if (width
== 0 || height
== 0 || depth
== 0)
3816 goto out
; /* no-op, not an error */
3818 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3819 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3820 xoffset
, yoffset
, zoffset
,
3821 width
, height
, depth
,
3822 format
, imageSize
, data
,
3825 ctx
->NewState
|= _NEW_TEXTURE
;
3828 _mesa_unlock_texture(ctx
, texObj
);
3833 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3835 const struct gl_texture_unit
*texUnit
;
3836 struct gl_texture_object
*texObj
;
3837 struct gl_texture_image
*texImage
;
3839 GET_CURRENT_CONTEXT(ctx
);
3840 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3842 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3843 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3845 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3849 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3850 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3852 if (level
< 0 || level
>= maxLevels
) {
3853 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3857 if (_mesa_is_proxy_texture(target
)) {
3858 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3862 _mesa_lock_texture(ctx
, texObj
);
3864 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3866 if (texImage
->IsCompressed
) {
3867 /* this typically calls _mesa_get_compressed_teximage() */
3868 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3872 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3873 "glGetCompressedTexImageARB");
3877 /* probably invalid mipmap level */
3878 _mesa_error(ctx
, GL_INVALID_VALUE
,
3879 "glGetCompressedTexImageARB(level)");
3882 _mesa_unlock_texture(ctx
, texObj
);