2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
40 #include "framebuffer.h"
46 #include "texcompress.h"
47 #include "texformat.h"
55 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
59 _mesa_alloc_texmemory(GLsizei bytes
)
61 return _mesa_align_malloc(bytes
, 512);
66 * Free texture memory allocated with _mesa_alloc_texmemory()
69 _mesa_free_texmemory(void *m
)
78 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
80 #if CHAN_TYPE != GL_UNSIGNED_BYTE
81 _mesa_problem(NULL
, "PrintTexture not supported");
84 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
87 _mesa_printf("No texture data\n");
91 switch (img
->Format
) {
98 case GL_LUMINANCE_ALPHA
:
108 _mesa_problem(NULL
, "error in PrintTexture\n");
112 for (i
= 0; i
< img
->Height
; i
++) {
113 for (j
= 0; j
< img
->Width
; j
++) {
115 _mesa_printf("%02x ", data
[0]);
117 _mesa_printf("%02x%02x ", data
[0], data
[1]);
119 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
121 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
122 data
+= (img
->RowStride
- img
->Width
) * c
;
124 /* XXX use img->ImageStride here */
133 * Compute floor(log_base_2(n)).
134 * If n < 0 return -1.
163 * Return the simple base format for a given internal texture format.
164 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
166 * \param ctx GL context.
167 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
169 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
170 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
172 * This is the format which is used during texture application (i.e. the
173 * texture format and env mode determine the arithmetic used.
176 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
178 switch (internalFormat
) {
193 case GL_LUMINANCE_ALPHA
:
194 case GL_LUMINANCE4_ALPHA4
:
195 case GL_LUMINANCE6_ALPHA2
:
196 case GL_LUMINANCE8_ALPHA8
:
197 case GL_LUMINANCE12_ALPHA4
:
198 case GL_LUMINANCE12_ALPHA12
:
199 case GL_LUMINANCE16_ALPHA16
:
200 return GL_LUMINANCE_ALPHA
;
231 if (ctx
->Extensions
.EXT_paletted_texture
) {
232 switch (internalFormat
) {
234 case GL_COLOR_INDEX1_EXT
:
235 case GL_COLOR_INDEX2_EXT
:
236 case GL_COLOR_INDEX4_EXT
:
237 case GL_COLOR_INDEX8_EXT
:
238 case GL_COLOR_INDEX12_EXT
:
239 case GL_COLOR_INDEX16_EXT
:
240 return GL_COLOR_INDEX
;
246 if (ctx
->Extensions
.ARB_depth_texture
) {
247 switch (internalFormat
) {
248 case GL_DEPTH_COMPONENT
:
249 case GL_DEPTH_COMPONENT16
:
250 case GL_DEPTH_COMPONENT24
:
251 case GL_DEPTH_COMPONENT32
:
252 return GL_DEPTH_COMPONENT
;
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
:
275 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
276 switch (internalFormat
) {
277 case GL_COMPRESSED_RGB_FXT1_3DFX
:
279 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
286 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
287 switch (internalFormat
) {
288 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
290 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
291 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
292 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
299 if (ctx
->Extensions
.S3_s3tc
) {
300 switch (internalFormat
) {
312 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
313 if (internalFormat
== GL_YCBCR_MESA
)
314 return GL_YCBCR_MESA
;
317 if (ctx
->Extensions
.ARB_texture_float
) {
318 switch (internalFormat
) {
319 case GL_ALPHA16F_ARB
:
320 case GL_ALPHA32F_ARB
:
328 case GL_INTENSITY16F_ARB
:
329 case GL_INTENSITY32F_ARB
:
331 case GL_LUMINANCE16F_ARB
:
332 case GL_LUMINANCE32F_ARB
:
334 case GL_LUMINANCE_ALPHA16F_ARB
:
335 case GL_LUMINANCE_ALPHA32F_ARB
:
336 return GL_LUMINANCE_ALPHA
;
342 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
343 switch (internalFormat
) {
352 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
353 switch (internalFormat
) {
362 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
363 switch (internalFormat
) {
364 case GL_DEPTH_STENCIL_EXT
:
365 case GL_DEPTH24_STENCIL8_EXT
:
366 return GL_DEPTH_STENCIL_EXT
;
372 #if FEATURE_EXT_texture_sRGB
373 if (ctx
->Extensions
.EXT_texture_sRGB
) {
374 switch (internalFormat
) {
377 case GL_COMPRESSED_SRGB_EXT
:
378 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
380 case GL_SRGB_ALPHA_EXT
:
381 case GL_SRGB8_ALPHA8_EXT
:
382 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
383 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
384 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
385 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
387 case GL_SLUMINANCE_ALPHA_EXT
:
388 case GL_SLUMINANCE8_ALPHA8_EXT
:
389 case GL_COMPRESSED_SLUMINANCE_EXT
:
390 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
391 return GL_LUMINANCE_ALPHA
;
392 case GL_SLUMINANCE_EXT
:
393 case GL_SLUMINANCE8_EXT
:
400 #endif /* FEATURE_EXT_texture_sRGB */
402 return -1; /* error */
407 * Test if the given image format is a color/RGBA format (i.e., not color
408 * index, depth, stencil, etc).
409 * \param format the image format value (may by an internal texture format)
410 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
411 * XXX maybe move this func to image.c
414 _mesa_is_color_format(GLenum format
)
432 case GL_LUMINANCE_ALPHA
:
433 case GL_LUMINANCE4_ALPHA4
:
434 case GL_LUMINANCE6_ALPHA2
:
435 case GL_LUMINANCE8_ALPHA8
:
436 case GL_LUMINANCE12_ALPHA4
:
437 case GL_LUMINANCE12_ALPHA12
:
438 case GL_LUMINANCE16_ALPHA16
:
465 /* float texture formats */
466 case GL_ALPHA16F_ARB
:
467 case GL_ALPHA32F_ARB
:
468 case GL_LUMINANCE16F_ARB
:
469 case GL_LUMINANCE32F_ARB
:
470 case GL_LUMINANCE_ALPHA16F_ARB
:
471 case GL_LUMINANCE_ALPHA32F_ARB
:
472 case GL_INTENSITY16F_ARB
:
473 case GL_INTENSITY32F_ARB
:
478 /* compressed formats */
479 case GL_COMPRESSED_ALPHA
:
480 case GL_COMPRESSED_LUMINANCE
:
481 case GL_COMPRESSED_LUMINANCE_ALPHA
:
482 case GL_COMPRESSED_INTENSITY
:
483 case GL_COMPRESSED_RGB
:
484 case GL_COMPRESSED_RGBA
:
489 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
490 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
491 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
492 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
493 case GL_COMPRESSED_RGB_FXT1_3DFX
:
494 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
495 #if FEATURE_EXT_texture_sRGB
498 case GL_SRGB_ALPHA_EXT
:
499 case GL_SRGB8_ALPHA8_EXT
:
500 case GL_SLUMINANCE_ALPHA_EXT
:
501 case GL_SLUMINANCE8_ALPHA8_EXT
:
502 case GL_SLUMINANCE_EXT
:
503 case GL_SLUMINANCE8_EXT
:
504 case GL_COMPRESSED_SRGB_EXT
:
505 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
506 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
507 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
508 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
509 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
510 case GL_COMPRESSED_SLUMINANCE_EXT
:
511 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
512 #endif /* FEATURE_EXT_texture_sRGB */
514 /* signed texture formats */
518 case GL_YCBCR_MESA
: /* not considered to be RGB */
527 * Test if the given image format is a color index format.
530 is_index_format(GLenum format
)
534 case GL_COLOR_INDEX1_EXT
:
535 case GL_COLOR_INDEX2_EXT
:
536 case GL_COLOR_INDEX4_EXT
:
537 case GL_COLOR_INDEX8_EXT
:
538 case GL_COLOR_INDEX12_EXT
:
539 case GL_COLOR_INDEX16_EXT
:
548 * Test if the given image format is a depth component format.
551 is_depth_format(GLenum format
)
554 case GL_DEPTH_COMPONENT16
:
555 case GL_DEPTH_COMPONENT24
:
556 case GL_DEPTH_COMPONENT32
:
557 case GL_DEPTH_COMPONENT
:
566 * Test if the given image format is a YCbCr format.
569 is_ycbcr_format(GLenum format
)
581 * Test if the given image format is a Depth/Stencil format.
584 is_depthstencil_format(GLenum format
)
587 case GL_DEPTH24_STENCIL8_EXT
:
588 case GL_DEPTH_STENCIL_EXT
:
596 * Test if the given image format is a dudv format.
599 is_dudv_format(GLenum format
)
612 * Test if it is a supported compressed format.
614 * \param internalFormat the internal format token provided by the user.
616 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
617 * GL_FALSE otherwise.
619 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
623 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
625 GLint supported
[100]; /* 100 should be plenty */
628 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
630 for (i
= 0; i
< n
; i
++) {
631 if ((GLint
) internalFormat
== supported
[i
]) {
640 * For cube map faces, return a face index in [0,5].
641 * For other targets return 0;
644 _mesa_tex_target_to_face(GLenum target
)
646 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
647 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
648 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
656 * Store a gl_texture_image pointer in a gl_texture_object structure
657 * according to the target and level parameters.
659 * \param tObj texture object.
660 * \param target texture target.
661 * \param level image level.
662 * \param texImage texture image.
664 * This was basically prompted by the introduction of cube maps.
667 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
668 GLenum target
, GLint level
,
669 struct gl_texture_image
*texImage
)
673 /* XXX simplify this with _mesa_tex_target_to_face() */
678 case GL_TEXTURE_1D_ARRAY_EXT
:
679 case GL_TEXTURE_2D_ARRAY_EXT
:
680 tObj
->Image
[0][level
] = texImage
;
682 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
683 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
684 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
685 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
686 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
687 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
689 GLuint face
= ((GLuint
) target
-
690 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
691 tObj
->Image
[face
][level
] = texImage
;
694 case GL_TEXTURE_RECTANGLE_NV
:
696 tObj
->Image
[0][level
] = texImage
;
699 _mesa_problem(NULL
, "bad target in _mesa_set_tex_image()");
702 /* Set the 'back' pointer */
703 texImage
->TexObject
= tObj
;
708 * Allocate a texture image structure.
710 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
713 * \return a pointer to gl_texture_image struct with all fields initialized to
716 struct gl_texture_image
*
717 _mesa_new_texture_image( GLcontext
*ctx
)
720 return CALLOC_STRUCT(gl_texture_image
);
725 * Free texture image data.
726 * This function is a fallback called via ctx->Driver.FreeTexImageData().
728 * \param texImage texture image.
730 * Free the texture image data if it's not marked as client data.
733 _mesa_free_texture_image_data(GLcontext
*ctx
,
734 struct gl_texture_image
*texImage
)
738 if (texImage
->Data
&& !texImage
->IsClientData
) {
739 /* free the old texture data */
740 _mesa_free_texmemory(texImage
->Data
);
743 texImage
->Data
= NULL
;
748 * Free texture image.
750 * \param texImage texture image.
752 * Free the texture image structure and the associated image data.
755 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
757 /* Free texImage->Data and/or any other driver-specific texture
760 ASSERT(ctx
->Driver
.FreeTexImageData
);
761 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
763 ASSERT(texImage
->Data
== NULL
);
764 if (texImage
->ImageOffsets
)
765 _mesa_free(texImage
->ImageOffsets
);
766 _mesa_free(texImage
);
771 * Test if a target is a proxy target.
773 * \param target texture target.
775 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
778 _mesa_is_proxy_texture(GLenum target
)
780 return (target
== GL_PROXY_TEXTURE_1D
||
781 target
== GL_PROXY_TEXTURE_2D
||
782 target
== GL_PROXY_TEXTURE_3D
||
783 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
784 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
785 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
786 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
791 * Get the texture object that corresponds to the target of the given texture unit.
793 * \param ctx GL context.
794 * \param texUnit texture unit.
795 * \param target texture target.
797 * \return pointer to the texture object on success, or NULL on failure.
799 * \sa gl_texture_unit.
801 struct gl_texture_object
*
802 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
807 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
808 case GL_PROXY_TEXTURE_1D
:
809 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
811 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
812 case GL_PROXY_TEXTURE_2D
:
813 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
815 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
816 case GL_PROXY_TEXTURE_3D
:
817 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
818 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
819 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
820 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
821 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
822 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
823 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
824 case GL_TEXTURE_CUBE_MAP_ARB
:
825 return ctx
->Extensions
.ARB_texture_cube_map
826 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
827 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
828 return ctx
->Extensions
.ARB_texture_cube_map
829 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
830 case GL_TEXTURE_RECTANGLE_NV
:
831 return ctx
->Extensions
.NV_texture_rectangle
832 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
833 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
834 return ctx
->Extensions
.NV_texture_rectangle
835 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
836 case GL_TEXTURE_1D_ARRAY_EXT
:
837 return ctx
->Extensions
.MESA_texture_array
838 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
839 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
840 return ctx
->Extensions
.MESA_texture_array
841 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
842 case GL_TEXTURE_2D_ARRAY_EXT
:
843 return ctx
->Extensions
.MESA_texture_array
844 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
845 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
846 return ctx
->Extensions
.MESA_texture_array
847 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
849 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
856 * Get the texture image struct which corresponds to target and level
857 * of the given texture unit.
859 * \param ctx GL context.
860 * \param texObj texture unit.
861 * \param target texture target.
862 * \param level image level.
864 * \return pointer to the texture image structure on success, or NULL on failure.
866 * \sa gl_texture_unit.
868 struct gl_texture_image
*
869 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
870 GLenum target
, GLint level
)
874 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
)
877 /* XXX simplify this with _mesa_tex_target_to_face() */
880 case GL_PROXY_TEXTURE_1D
:
882 case GL_PROXY_TEXTURE_2D
:
884 case GL_PROXY_TEXTURE_3D
:
885 return texObj
->Image
[0][level
];
887 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
888 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
889 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
890 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
891 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
892 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
893 if (ctx
->Extensions
.ARB_texture_cube_map
) {
894 GLuint face
= ((GLuint
) target
-
895 (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
);
896 return texObj
->Image
[face
][level
];
901 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
902 if (ctx
->Extensions
.ARB_texture_cube_map
)
903 return texObj
->Image
[0][level
];
907 case GL_TEXTURE_RECTANGLE_NV
:
908 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
909 if (ctx
->Extensions
.NV_texture_rectangle
&& level
== 0)
910 return texObj
->Image
[0][level
];
914 case GL_TEXTURE_1D_ARRAY_EXT
:
915 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
916 case GL_TEXTURE_2D_ARRAY_EXT
:
917 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
918 return (ctx
->Extensions
.MESA_texture_array
)
919 ? texObj
->Image
[0][level
] : NULL
;
928 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
929 * it and install it. Only return NULL if passed a bad parameter or run
932 struct gl_texture_image
*
933 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
934 GLenum target
, GLint level
)
936 struct gl_texture_image
*texImage
;
941 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
943 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
945 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
949 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
957 * Return pointer to the specified proxy texture image.
958 * Note that proxy textures are per-context, not per-texture unit.
959 * \return pointer to texture image or NULL if invalid target, invalid
960 * level, or out of memory.
962 struct gl_texture_image
*
963 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
965 struct gl_texture_image
*texImage
;
972 case GL_PROXY_TEXTURE_1D
:
973 if (level
>= ctx
->Const
.MaxTextureLevels
)
975 texIndex
= TEXTURE_1D_INDEX
;
977 case GL_PROXY_TEXTURE_2D
:
978 if (level
>= ctx
->Const
.MaxTextureLevels
)
980 texIndex
= TEXTURE_2D_INDEX
;
982 case GL_PROXY_TEXTURE_3D
:
983 if (level
>= ctx
->Const
.Max3DTextureLevels
)
985 texIndex
= TEXTURE_3D_INDEX
;
987 case GL_PROXY_TEXTURE_CUBE_MAP
:
988 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
990 texIndex
= TEXTURE_CUBE_INDEX
;
992 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
995 texIndex
= TEXTURE_RECT_INDEX
;
997 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
998 if (level
>= ctx
->Const
.MaxTextureLevels
)
1000 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
1002 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1003 if (level
>= ctx
->Const
.MaxTextureLevels
)
1005 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
1011 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
1013 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
1015 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
1018 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
1019 /* Set the 'back' pointer */
1020 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
1027 * Get the maximum number of allowed mipmap levels.
1029 * \param ctx GL context.
1030 * \param target texture target.
1032 * \return the maximum number of allowed mipmap levels for the given
1033 * texture target, or zero if passed a bad target.
1038 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
1042 case GL_PROXY_TEXTURE_1D
:
1044 case GL_PROXY_TEXTURE_2D
:
1045 case GL_TEXTURE_1D_ARRAY_EXT
:
1046 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1047 case GL_TEXTURE_2D_ARRAY_EXT
:
1048 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1049 return ctx
->Const
.MaxTextureLevels
;
1051 case GL_PROXY_TEXTURE_3D
:
1052 return ctx
->Const
.Max3DTextureLevels
;
1053 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1054 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1055 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1056 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1057 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1058 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1059 case GL_TEXTURE_CUBE_MAP_ARB
:
1060 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1061 return ctx
->Const
.MaxCubeTextureLevels
;
1062 case GL_TEXTURE_RECTANGLE_NV
:
1063 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1066 return 0; /* bad target */
1072 #if 000 /* not used anymore */
1074 * glTexImage[123]D can accept a NULL image pointer. In this case we
1075 * create a texture image with unspecified image contents per the OpenGL
1079 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1081 const GLint components
= _mesa_components_in_format(format
);
1082 const GLint numPixels
= width
* height
* depth
;
1083 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1087 * Let's see if anyone finds this. If glTexImage2D() is called with
1088 * a NULL image pointer then load the texture image with something
1089 * interesting instead of leaving it indeterminate.
1092 static const char message
[8][32] = {
1093 " X X XXXXX XXX X ",
1094 " XX XX X X X X X ",
1096 " X X XXXX XXX XXXXX ",
1099 " X X XXXXX XXX X X ",
1103 GLubyte
*imgPtr
= data
;
1105 for (h
= 0; h
< depth
; h
++) {
1106 for (i
= 0; i
< height
; i
++) {
1107 GLint srcRow
= 7 - (i
% 8);
1108 for (j
= 0; j
< width
; j
++) {
1109 GLint srcCol
= j
% 32;
1110 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1111 for (k
= 0; k
< components
; k
++) {
1127 * Reset the fields of a gl_texture_image struct to zero.
1129 * \param img texture image structure.
1131 * This is called when a proxy texture test fails, we set all the
1132 * image members (except DriverData) to zero.
1133 * It's also used in glTexImage[123]D as a safeguard to be sure all
1134 * required fields get initialized properly by the Driver.TexImage[123]D
1138 clear_teximage_fields(struct gl_texture_image
*img
)
1141 img
->_BaseFormat
= 0;
1142 img
->InternalFormat
= 0;
1148 if (img
->ImageOffsets
) {
1149 _mesa_free(img
->ImageOffsets
);
1150 img
->ImageOffsets
= NULL
;
1156 img
->HeightLog2
= 0;
1159 img
->TexFormat
= &_mesa_null_texformat
;
1160 img
->FetchTexelc
= NULL
;
1161 img
->FetchTexelf
= NULL
;
1162 img
->IsCompressed
= 0;
1163 img
->CompressedSize
= 0;
1168 * Initialize basic fields of the gl_texture_image struct.
1170 * \param ctx GL context.
1171 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1172 * \param img texture image structure to be initialized.
1173 * \param width image width.
1174 * \param height image height.
1175 * \param depth image depth.
1176 * \param border image border.
1177 * \param internalFormat internal format.
1179 * Fills in the fields of \p img with the given information.
1180 * Note: width, height and depth include the border.
1183 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1184 struct gl_texture_image
*img
,
1185 GLsizei width
, GLsizei height
, GLsizei depth
,
1186 GLint border
, GLenum internalFormat
)
1192 ASSERT(height
>= 0);
1195 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1196 ASSERT(img
->_BaseFormat
> 0);
1197 img
->InternalFormat
= internalFormat
;
1198 img
->Border
= border
;
1200 img
->Height
= height
;
1203 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1204 img
->WidthLog2
= logbase2(img
->Width2
);
1206 if (height
== 1) { /* 1-D texture */
1208 img
->HeightLog2
= 0;
1211 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1212 img
->HeightLog2
= logbase2(img
->Height2
);
1215 if (depth
== 1) { /* 2-D texture */
1220 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1221 img
->DepthLog2
= logbase2(img
->Depth2
);
1224 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1226 img
->IsCompressed
= GL_FALSE
;
1227 img
->CompressedSize
= 0;
1229 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1230 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1231 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
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_is_pow_two(width
- 2 * border
)) ||
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_is_pow_two(width
- 2 * border
)) ||
1313 height
< 2 * border
|| height
> 2 + maxSize
||
1314 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1315 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
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_is_pow_two(width
- 2 * border
)) ||
1326 height
< 2 * border
|| height
> 2 + maxSize
||
1327 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1328 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1329 depth
< 2 * border
|| depth
> 2 + maxSize
||
1330 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1331 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
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_is_pow_two(width
- 2 * border
)) ||
1350 height
< 2 * border
|| height
> 2 + maxSize
||
1351 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1352 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
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_is_pow_two(width
- 2 * border
)) ||
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_is_pow_two(width
- 2 * border
)) ||
1377 height
< 2 * border
|| height
> 2 + maxSize
||
1378 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1379 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
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(incompatible format 0x%x, type 0x%x)",
1569 dimensions
, format
, type
);
1574 /* make sure internal format and format basically agree */
1575 colorFormat
= _mesa_is_color_format(format
);
1576 indexFormat
= is_index_format(format
);
1577 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1578 (is_index_format(internalFormat
) && !indexFormat
) ||
1579 (is_depth_format(internalFormat
) != is_depth_format(format
)) ||
1580 (is_ycbcr_format(internalFormat
) != is_ycbcr_format(format
)) ||
1581 (is_depthstencil_format(internalFormat
) != is_depthstencil_format(format
)) ||
1582 (is_dudv_format(internalFormat
) != is_dudv_format(format
))) {
1584 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1585 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1586 dimensions
, internalFormat
, format
);
1590 /* additional checks for ycbcr textures */
1591 if (internalFormat
== GL_YCBCR_MESA
) {
1592 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1593 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1594 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1596 _mesa_sprintf(message
,
1597 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1598 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1599 return GL_TRUE
; /* error */
1601 if (target
!= GL_TEXTURE_2D
&&
1602 target
!= GL_PROXY_TEXTURE_2D
&&
1603 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1604 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1606 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1612 _mesa_sprintf(message
,
1613 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1614 dimensions
, border
);
1615 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1621 /* additional checks for depth textures */
1622 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1623 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1624 if (target
!= GL_TEXTURE_1D
&&
1625 target
!= GL_PROXY_TEXTURE_1D
&&
1626 target
!= GL_TEXTURE_2D
&&
1627 target
!= GL_PROXY_TEXTURE_2D
&&
1628 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1629 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1631 _mesa_error(ctx
, GL_INVALID_ENUM
,
1632 "glTexImage(target/internalFormat)");
1637 /* additional checks for compressed textures */
1638 if (is_compressed_format(ctx
, internalFormat
)) {
1639 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1640 _mesa_error(ctx
, GL_INVALID_ENUM
,
1641 "glTexImage%d(target)", dimensions
);
1646 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1647 "glTexImage%D(border!=0)", dimensions
);
1653 /* if we get here, the parameters are OK */
1659 * Test glTexSubImage[123]D() parameters for errors.
1661 * \param ctx GL context.
1662 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1663 * \param target texture target given by the user.
1664 * \param level image level given by the user.
1665 * \param xoffset sub-image x offset given by the user.
1666 * \param yoffset sub-image y offset given by the user.
1667 * \param zoffset sub-image z offset given by the user.
1668 * \param format pixel data format given by the user.
1669 * \param type pixel data type given by the user.
1670 * \param width image width given by the user.
1671 * \param height image height given by the user.
1672 * \param depth image depth given by the user.
1674 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1676 * Verifies each of the parameters against the constants specified in
1677 * __GLcontextRec::Const and the supported extensions, and according to the
1678 * OpenGL specification.
1681 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1682 GLenum target
, GLint level
,
1683 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1684 GLint width
, GLint height
, GLint depth
,
1685 GLenum format
, GLenum type
)
1688 if (dimensions
== 1) {
1689 if (target
!= GL_TEXTURE_1D
) {
1690 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1694 else if (dimensions
== 2) {
1695 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1696 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1697 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1698 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1702 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1703 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1704 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1708 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1709 if (!ctx
->Extensions
.MESA_texture_array
) {
1710 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1714 else if (target
!= GL_TEXTURE_2D
) {
1715 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1719 else if (dimensions
== 3) {
1720 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1721 if (!ctx
->Extensions
.MESA_texture_array
) {
1722 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1726 else if (target
!= GL_TEXTURE_3D
) {
1727 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1732 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1736 /* Basic level check */
1737 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1738 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1743 _mesa_error(ctx
, GL_INVALID_VALUE
,
1744 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1747 if (height
< 0 && dimensions
> 1) {
1748 _mesa_error(ctx
, GL_INVALID_VALUE
,
1749 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1752 if (depth
< 0 && dimensions
> 2) {
1753 _mesa_error(ctx
, GL_INVALID_VALUE
,
1754 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1758 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1759 _mesa_error(ctx
, GL_INVALID_ENUM
,
1760 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1761 dimensions
, format
, type
);
1769 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1770 GLenum target
, GLint level
,
1771 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1772 GLint width
, GLint height
, GLint depth
,
1773 GLenum format
, GLenum type
,
1774 const struct gl_texture_image
*destTex
)
1777 /* undefined image level */
1778 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1782 if (xoffset
< -((GLint
)destTex
->Border
)) {
1783 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1787 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1788 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1792 if (dimensions
> 1) {
1793 if (yoffset
< -((GLint
)destTex
->Border
)) {
1794 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1798 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1799 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1804 if (dimensions
> 2) {
1805 if (zoffset
< -((GLint
)destTex
->Border
)) {
1806 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1809 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1810 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1815 #if FEATURE_EXT_texture_sRGB
1816 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1817 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1818 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1819 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1820 if ((width
& 0x3) || (height
& 0x3) ||
1821 (xoffset
& 0x3) || (yoffset
& 0x3))
1822 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1823 "glTexSubImage%dD(size or offset not multiple of 4)",
1829 if (destTex
->IsCompressed
) {
1830 if (!target_can_be_compressed(ctx
, target
)) {
1831 _mesa_error(ctx
, GL_INVALID_ENUM
,
1832 "glTexSubImage%D(target)", dimensions
);
1835 /* offset must be multiple of 4 */
1836 if ((xoffset
& 3) || (yoffset
& 3)) {
1837 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1838 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1841 /* size must be multiple of 4 or equal to whole texture size */
1842 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1843 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1844 "glTexSubImage%D(width)", dimensions
);
1847 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1848 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1849 "glTexSubImage%D(width)", dimensions
);
1859 * Test glCopyTexImage[12]D() parameters for errors.
1861 * \param ctx GL context.
1862 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1863 * \param target texture target given by the user.
1864 * \param level image level given by the user.
1865 * \param internalFormat internal format given by the user.
1866 * \param width image width given by the user.
1867 * \param height image height given by the user.
1868 * \param border texture border.
1870 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1872 * Verifies each of the parameters against the constants specified in
1873 * __GLcontextRec::Const and the supported extensions, and according to the
1874 * OpenGL specification.
1877 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1878 GLenum target
, GLint level
, GLint internalFormat
,
1879 GLint width
, GLint height
, GLint border
)
1885 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1886 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1887 _mesa_error(ctx
, GL_INVALID_VALUE
,
1888 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1892 /* Check that the source buffer is complete */
1893 if (ctx
->ReadBuffer
->Name
) {
1894 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1895 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1896 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1897 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1903 if (border
< 0 || border
> 1 ||
1904 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1905 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1909 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1911 _mesa_error(ctx
, GL_INVALID_VALUE
,
1912 "glCopyTexImage%dD(internalFormat)", dimensions
);
1916 /* NOTE: the format and type aren't really significant for
1917 * TestProxyTexImage(). Only the internalformat really matters.
1918 if (!_mesa_source_buffer_exists(ctx, format)) {
1919 _mesa_error(ctx, GL_INVALID_OPERATION,
1920 "glCopyTexImage%dD(missing readbuffer)", dimensions);
1927 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1928 * level, width, height and depth.
1930 if (dimensions
== 1) {
1931 if (target
== GL_TEXTURE_1D
) {
1932 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1933 level
, internalFormat
,
1935 width
, 1, 1, border
);
1938 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1942 else if (dimensions
== 2) {
1943 if (target
== GL_TEXTURE_2D
) {
1944 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1945 level
, internalFormat
,
1947 width
, height
, 1, border
);
1949 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1950 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1951 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1952 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1955 sizeOK
= (width
== height
) &&
1956 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1957 level
, internalFormat
, format
, type
,
1958 width
, height
, 1, border
);
1960 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1961 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1962 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1965 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1966 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1967 level
, internalFormat
,
1969 width
, height
, 1, border
);
1971 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1972 if (!ctx
->Extensions
.MESA_texture_array
) {
1973 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1976 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1977 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1978 level
, internalFormat
,
1980 width
, height
, 1, border
);
1983 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1988 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1993 if (dimensions
== 1) {
1994 _mesa_error(ctx
, GL_INVALID_VALUE
,
1995 "glCopyTexImage1D(width=%d)", width
);
1998 ASSERT(dimensions
== 2);
1999 _mesa_error(ctx
, GL_INVALID_VALUE
,
2000 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2005 if (is_compressed_format(ctx
, internalFormat
)) {
2006 if (!target_can_be_compressed(ctx
, target
)) {
2007 _mesa_error(ctx
, GL_INVALID_ENUM
,
2008 "glCopyTexImage%d(target)", dimensions
);
2012 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2013 "glCopyTexImage%D(border!=0)", dimensions
);
2017 else if (is_depth_format(internalFormat
)) {
2018 /* make sure we have depth/stencil buffers */
2019 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2020 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2021 "glCopyTexImage%D(no depth)", dimensions
);
2025 else if (is_depthstencil_format(internalFormat
)) {
2026 /* make sure we have depth/stencil buffers */
2027 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2028 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2029 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2034 /* if we get here, the parameters are OK */
2040 * Test glCopyTexSubImage[12]D() parameters for errors.
2041 * Note that this is the first part of error checking.
2042 * See also copytexsubimage_error_check2() below for the second part.
2044 * \param ctx GL context.
2045 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2046 * \param target texture target given by the user.
2047 * \param level image level given by the user.
2049 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2052 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
2053 GLenum target
, GLint level
)
2055 /* Check that the source buffer is complete */
2056 if (ctx
->ReadBuffer
->Name
) {
2057 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2058 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2059 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2060 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2066 if (dimensions
== 1) {
2067 if (target
!= GL_TEXTURE_1D
) {
2068 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2072 else if (dimensions
== 2) {
2073 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2074 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2075 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2076 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2080 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2081 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2082 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2086 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2087 if (!ctx
->Extensions
.MESA_texture_array
) {
2088 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2092 else if (target
!= GL_TEXTURE_2D
) {
2093 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2097 else if (dimensions
== 3) {
2098 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2099 (!ctx
->Extensions
.MESA_texture_array
))
2100 && (target
!= GL_TEXTURE_3D
)) {
2101 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2107 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2108 _mesa_error(ctx
, GL_INVALID_VALUE
,
2109 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2118 * Second part of error checking for glCopyTexSubImage[12]D().
2119 * \param xoffset sub-image x offset given by the user.
2120 * \param yoffset sub-image y offset given by the user.
2121 * \param zoffset sub-image z offset given by the user.
2122 * \param width image width given by the user.
2123 * \param height image height given by the user.
2126 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2127 GLenum target
, GLint level
,
2128 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2129 GLsizei width
, GLsizei height
,
2130 const struct gl_texture_image
*teximage
)
2132 /* check that dest tex image exists */
2134 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2135 "glCopyTexSubImage%dD(undefined texture level: %d)",
2142 _mesa_error(ctx
, GL_INVALID_VALUE
,
2143 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2146 if (dimensions
> 1 && height
< 0) {
2147 _mesa_error(ctx
, GL_INVALID_VALUE
,
2148 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2152 /* check x/y offsets */
2153 if (xoffset
< -((GLint
)teximage
->Border
)) {
2154 _mesa_error(ctx
, GL_INVALID_VALUE
,
2155 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2158 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2159 _mesa_error(ctx
, GL_INVALID_VALUE
,
2160 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2163 if (dimensions
> 1) {
2164 if (yoffset
< -((GLint
)teximage
->Border
)) {
2165 _mesa_error(ctx
, GL_INVALID_VALUE
,
2166 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2169 /* NOTE: we're adding the border here, not subtracting! */
2170 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2171 _mesa_error(ctx
, GL_INVALID_VALUE
,
2172 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2177 /* check z offset */
2178 if (dimensions
> 2) {
2179 if (zoffset
< -((GLint
)teximage
->Border
)) {
2180 _mesa_error(ctx
, GL_INVALID_VALUE
,
2181 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2184 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2185 _mesa_error(ctx
, GL_INVALID_VALUE
,
2186 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2191 if (teximage
->IsCompressed
) {
2192 if (!target_can_be_compressed(ctx
, target
)) {
2193 _mesa_error(ctx
, GL_INVALID_ENUM
,
2194 "glCopyTexSubImage%d(target)", dimensions
);
2197 /* offset must be multiple of 4 */
2198 if ((xoffset
& 3) || (yoffset
& 3)) {
2199 _mesa_error(ctx
, GL_INVALID_VALUE
,
2200 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2203 /* size must be multiple of 4 */
2204 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2205 _mesa_error(ctx
, GL_INVALID_VALUE
,
2206 "glCopyTexSubImage%D(width)", dimensions
);
2209 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2210 _mesa_error(ctx
, GL_INVALID_VALUE
,
2211 "glCopyTexSubImage%D(height)", dimensions
);
2216 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2217 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2221 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2222 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2223 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2224 dimensions
, teximage
->_BaseFormat
);
2228 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2229 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2230 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2231 "glCopyTexSubImage%D(no depth buffer)",
2236 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2237 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2238 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2239 "glCopyTexSubImage%D(no depth/stencil buffer)",
2245 /* if we get here, the parameters are OK */
2251 * Get texture image. Called by glGetTexImage.
2253 * \param target texture target.
2254 * \param level image level.
2255 * \param format pixel data format for returned image.
2256 * \param type pixel data type for returned image.
2257 * \param pixels returned pixel data.
2260 _mesa_GetTexImage( GLenum target
, GLint level
, GLenum format
,
2261 GLenum type
, GLvoid
*pixels
)
2263 const struct gl_texture_unit
*texUnit
;
2264 struct gl_texture_object
*texObj
;
2265 struct gl_texture_image
*texImage
;
2266 GLint maxLevels
= 0;
2267 GET_CURRENT_CONTEXT(ctx
);
2268 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2270 texUnit
= &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
2271 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2272 if (!texObj
|| _mesa_is_proxy_texture(target
)) {
2273 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(target)");
2277 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2278 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
2280 if (level
< 0 || level
>= maxLevels
) {
2281 _mesa_error( ctx
, GL_INVALID_VALUE
, "glGetTexImage(level)" );
2285 if (_mesa_sizeof_packed_type(type
) <= 0) {
2286 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(type)" );
2290 if (_mesa_components_in_format(format
) <= 0 ||
2291 format
== GL_STENCIL_INDEX
) {
2292 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)" );
2296 if (!ctx
->Extensions
.EXT_paletted_texture
&& is_index_format(format
)) {
2297 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2301 if (!ctx
->Extensions
.ARB_depth_texture
&& is_depth_format(format
)) {
2302 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2306 if (!ctx
->Extensions
.MESA_ycbcr_texture
&& is_ycbcr_format(format
)) {
2307 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2311 if (!ctx
->Extensions
.EXT_packed_depth_stencil
2312 && is_depthstencil_format(format
)) {
2313 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2317 if (!ctx
->Extensions
.ATI_envmap_bumpmap
2318 && is_dudv_format(format
)) {
2319 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexImage(format)");
2323 _mesa_lock_texture(ctx
, texObj
);
2325 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2327 /* invalid mipmap level, not an error */
2332 /* Make sure the requested image format is compatible with the
2333 * texture's format. Note that a color index texture can be converted
2334 * to RGBA so that combo is allowed.
2336 if (_mesa_is_color_format(format
)
2337 && !_mesa_is_color_format(texImage
->TexFormat
->BaseFormat
)
2338 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2339 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2342 else if (is_index_format(format
)
2343 && !is_index_format(texImage
->TexFormat
->BaseFormat
)) {
2344 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2347 else if (is_depth_format(format
)
2348 && !is_depth_format(texImage
->TexFormat
->BaseFormat
)
2349 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2350 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2353 else if (is_ycbcr_format(format
)
2354 && !is_ycbcr_format(texImage
->TexFormat
->BaseFormat
)) {
2355 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2358 else if (is_depthstencil_format(format
)
2359 && !is_depthstencil_format(texImage
->TexFormat
->BaseFormat
)) {
2360 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2363 else if (is_dudv_format(format
)
2364 && !is_dudv_format(texImage
->TexFormat
->BaseFormat
)) {
2365 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexImage(format mismatch)");
2369 if (ctx
->Pack
.BufferObj
->Name
) {
2370 /* packing texture image into a PBO */
2371 const GLuint dimensions
= (target
== GL_TEXTURE_3D
) ? 3 : 2;
2372 if (!_mesa_validate_pbo_access(dimensions
, &ctx
->Pack
, texImage
->Width
,
2373 texImage
->Height
, texImage
->Depth
,
2374 format
, type
, pixels
)) {
2375 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2376 "glGetTexImage(invalid PBO access)");
2381 /* typically, this will call _mesa_get_teximage() */
2382 ctx
->Driver
.GetTexImage(ctx
, target
, level
, format
, type
, pixels
,
2387 _mesa_unlock_texture(ctx
, texObj
);
2391 /** Callback info for walking over FBO hash table */
2395 struct gl_texture_object
*texObj
;
2401 * Check render to texture callback. Called from _mesa_HashWalk().
2404 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2406 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2407 const struct cb_info
*info
= (struct cb_info
*) userData
;
2408 GLcontext
*ctx
= info
->ctx
;
2409 const struct gl_texture_object
*texObj
= info
->texObj
;
2410 const GLuint level
= info
->level
, face
= info
->face
;
2412 /* If this is a user-created FBO */
2415 /* check if any of the FBO's attachments point to 'texObj' */
2416 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2417 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2418 if (att
->Type
== GL_TEXTURE
&&
2419 att
->Texture
== texObj
&&
2420 att
->TextureLevel
== level
&&
2421 att
->CubeMapFace
== face
) {
2422 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2423 /* Tell driver about the new renderbuffer texture */
2424 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2425 /* Mark fb status as indeterminate to force re-validation */
2434 * When a texture image is specified we have to check if it's bound to
2435 * any framebuffer objects (render to texture) in order to detect changes
2436 * in size or format since that effects FBO completeness.
2437 * Any FBOs rendering into the texture must be re-validated.
2440 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2441 GLuint face
, GLuint level
)
2443 /* Only check this texture if it's been marked as RenderToTexture */
2444 if (texObj
->_RenderToTexture
) {
2445 struct cb_info info
;
2447 info
.texObj
= texObj
;
2450 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2455 /** Debug helper: override the user-requested internal format */
2457 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2460 if (internalFormat
== GL_RGBA16F_ARB
||
2461 internalFormat
== GL_RGBA32F_ARB
) {
2462 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2465 else if (internalFormat
== GL_RGB16F_ARB
||
2466 internalFormat
== GL_RGB32F_ARB
) {
2467 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2470 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2471 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2472 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2473 return GL_LUMINANCE_ALPHA
;
2475 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2476 internalFormat
== GL_LUMINANCE32F_ARB
) {
2477 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2478 return GL_LUMINANCE
;
2480 else if (internalFormat
== GL_ALPHA16F_ARB
||
2481 internalFormat
== GL_ALPHA32F_ARB
) {
2482 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2486 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2487 internalFormat = GL_RGBA;
2491 return internalFormat
;
2494 return internalFormat
;
2500 * Called from the API. Note that width includes the border.
2503 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2504 GLsizei width
, GLint border
, GLenum format
,
2505 GLenum type
, const GLvoid
*pixels
)
2507 GLsizei postConvWidth
= width
;
2508 GET_CURRENT_CONTEXT(ctx
);
2509 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2511 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2513 #if FEATURE_convolve
2514 if (_mesa_is_color_format(internalFormat
)) {
2515 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2519 if (target
== GL_TEXTURE_1D
) {
2520 /* non-proxy target */
2521 struct gl_texture_unit
*texUnit
;
2522 struct gl_texture_object
*texObj
;
2523 struct gl_texture_image
*texImage
;
2524 const GLuint face
= _mesa_tex_target_to_face(target
);
2526 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2527 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2528 return; /* error was recorded */
2531 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2532 _mesa_update_state(ctx
);
2534 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2535 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2536 _mesa_lock_texture(ctx
, texObj
);
2538 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2540 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2544 if (texImage
->Data
) {
2545 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2548 ASSERT(texImage
->Data
== NULL
);
2550 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2551 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2552 postConvWidth
, 1, 1,
2553 border
, internalFormat
);
2555 ASSERT(ctx
->Driver
.TexImage1D
);
2557 /* Give the texture to the driver! <pixels> may be null! */
2558 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2559 width
, border
, format
, type
, pixels
,
2560 &ctx
->Unpack
, texObj
, texImage
);
2562 ASSERT(texImage
->TexFormat
);
2564 update_fbo_texture(ctx
, texObj
, face
, level
);
2567 texObj
->_Complete
= GL_FALSE
;
2568 ctx
->NewState
|= _NEW_TEXTURE
;
2571 _mesa_unlock_texture(ctx
, texObj
);
2573 else if (target
== GL_PROXY_TEXTURE_1D
) {
2574 /* Proxy texture: check for errors and update proxy state */
2575 struct gl_texture_image
*texImage
;
2576 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2577 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2578 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2579 /* when error, clear all proxy texture image parameters */
2581 clear_teximage_fields(texImage
);
2584 /* no error, set the tex image parameters */
2586 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2587 postConvWidth
, 1, 1,
2588 border
, internalFormat
);
2589 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2590 internalFormat
, format
, type
);
2594 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2601 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2602 GLsizei width
, GLsizei height
, GLint border
,
2603 GLenum format
, GLenum type
,
2604 const GLvoid
*pixels
)
2606 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2607 GET_CURRENT_CONTEXT(ctx
);
2608 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2610 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2612 #if FEATURE_convolve
2613 if (_mesa_is_color_format(internalFormat
)) {
2614 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2619 if (target
== GL_TEXTURE_2D
||
2620 (ctx
->Extensions
.ARB_texture_cube_map
&&
2621 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2622 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2623 (ctx
->Extensions
.NV_texture_rectangle
&&
2624 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2625 (ctx
->Extensions
.MESA_texture_array
&&
2626 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2627 /* non-proxy target */
2628 struct gl_texture_unit
*texUnit
;
2629 struct gl_texture_object
*texObj
;
2630 struct gl_texture_image
*texImage
;
2631 const GLuint face
= _mesa_tex_target_to_face(target
);
2633 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2634 format
, type
, 2, postConvWidth
, postConvHeight
,
2636 return; /* error was recorded */
2639 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2640 _mesa_update_state(ctx
);
2642 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2643 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2644 _mesa_lock_texture(ctx
, texObj
);
2646 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2648 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2652 if (texImage
->Data
) {
2653 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2656 ASSERT(texImage
->Data
== NULL
);
2657 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2658 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2659 postConvWidth
, postConvHeight
, 1,
2660 border
, internalFormat
);
2662 ASSERT(ctx
->Driver
.TexImage2D
);
2664 /* Give the texture to the driver! <pixels> may be null! */
2665 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2666 width
, height
, border
, format
, type
, pixels
,
2667 &ctx
->Unpack
, texObj
, texImage
);
2669 ASSERT(texImage
->TexFormat
);
2671 update_fbo_texture(ctx
, texObj
, face
, level
);
2674 texObj
->_Complete
= GL_FALSE
;
2675 ctx
->NewState
|= _NEW_TEXTURE
;
2678 _mesa_unlock_texture(ctx
, texObj
);
2680 else if (target
== GL_PROXY_TEXTURE_2D
||
2681 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2682 ctx
->Extensions
.ARB_texture_cube_map
) ||
2683 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2684 ctx
->Extensions
.NV_texture_rectangle
) ||
2685 (ctx
->Extensions
.MESA_texture_array
&&
2686 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2687 /* Proxy texture: check for errors and update proxy state */
2688 struct gl_texture_image
*texImage
;
2689 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2690 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2691 format
, type
, 2, postConvWidth
, postConvHeight
,
2693 /* when error, clear all proxy texture image parameters */
2695 clear_teximage_fields(texImage
);
2698 /* no error, set the tex image parameters */
2699 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2700 postConvWidth
, postConvHeight
, 1,
2701 border
, internalFormat
);
2702 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2703 internalFormat
, format
, type
);
2707 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2714 * Called by the API or display list executor.
2715 * Note that width and height include the border.
2718 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2719 GLsizei width
, GLsizei height
, GLsizei depth
,
2720 GLint border
, GLenum format
, GLenum type
,
2721 const GLvoid
*pixels
)
2723 GET_CURRENT_CONTEXT(ctx
);
2724 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2726 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2728 if (target
== GL_TEXTURE_3D
||
2729 (ctx
->Extensions
.MESA_texture_array
&&
2730 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2731 /* non-proxy target */
2732 struct gl_texture_unit
*texUnit
;
2733 struct gl_texture_object
*texObj
;
2734 struct gl_texture_image
*texImage
;
2735 const GLuint face
= _mesa_tex_target_to_face(target
);
2737 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2738 format
, type
, 3, width
, height
, depth
, border
)) {
2739 return; /* error was recorded */
2742 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2743 _mesa_update_state(ctx
);
2745 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2746 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2747 _mesa_lock_texture(ctx
, texObj
);
2749 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2751 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2755 if (texImage
->Data
) {
2756 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2759 ASSERT(texImage
->Data
== NULL
);
2760 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2761 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2762 width
, height
, depth
,
2763 border
, internalFormat
);
2765 ASSERT(ctx
->Driver
.TexImage3D
);
2767 /* Give the texture to the driver! <pixels> may be null! */
2768 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2769 width
, height
, depth
, border
, format
, type
,
2770 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2772 ASSERT(texImage
->TexFormat
);
2774 update_fbo_texture(ctx
, texObj
, face
, level
);
2777 texObj
->_Complete
= GL_FALSE
;
2778 ctx
->NewState
|= _NEW_TEXTURE
;
2781 _mesa_unlock_texture(ctx
, texObj
);
2783 else if (target
== GL_PROXY_TEXTURE_3D
||
2784 (ctx
->Extensions
.MESA_texture_array
&&
2785 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2786 /* Proxy texture: check for errors and update proxy state */
2787 struct gl_texture_image
*texImage
;
2788 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2789 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2790 format
, type
, 3, width
, height
, depth
, border
)) {
2791 /* when error, clear all proxy texture image parameters */
2793 clear_teximage_fields(texImage
);
2796 /* no error, set the tex image parameters */
2797 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2798 depth
, border
, internalFormat
);
2799 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2800 internalFormat
, format
, type
);
2804 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2811 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2812 GLsizei width
, GLsizei height
, GLsizei depth
,
2813 GLint border
, GLenum format
, GLenum type
,
2814 const GLvoid
*pixels
)
2816 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2817 depth
, border
, format
, type
, pixels
);
2823 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2824 GLint xoffset
, GLsizei width
,
2825 GLenum format
, GLenum type
,
2826 const GLvoid
*pixels
)
2828 GLsizei postConvWidth
= width
;
2829 struct gl_texture_unit
*texUnit
;
2830 struct gl_texture_object
*texObj
;
2831 struct gl_texture_image
*texImage
= NULL
;
2832 GET_CURRENT_CONTEXT(ctx
);
2833 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2835 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2836 _mesa_update_state(ctx
);
2838 #if FEATURE_convolve
2839 /* XXX should test internal format */
2840 if (_mesa_is_color_format(format
)) {
2841 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2845 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2846 postConvWidth
, 1, 1, format
, type
)) {
2847 return; /* error was detected */
2851 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2852 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2855 _mesa_lock_texture(ctx
, texObj
);
2857 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2859 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2860 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2861 goto out
; /* error was detected */
2865 goto out
; /* no-op, not an error */
2867 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2868 xoffset
+= texImage
->Border
;
2870 ASSERT(ctx
->Driver
.TexSubImage1D
);
2871 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2872 format
, type
, pixels
, &ctx
->Unpack
,
2874 ctx
->NewState
|= _NEW_TEXTURE
;
2877 _mesa_unlock_texture(ctx
, texObj
);
2882 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2883 GLint xoffset
, GLint yoffset
,
2884 GLsizei width
, GLsizei height
,
2885 GLenum format
, GLenum type
,
2886 const GLvoid
*pixels
)
2888 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2889 struct gl_texture_unit
*texUnit
;
2890 struct gl_texture_object
*texObj
;
2891 struct gl_texture_image
*texImage
;
2892 GET_CURRENT_CONTEXT(ctx
);
2893 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2895 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2896 _mesa_update_state(ctx
);
2898 #if FEATURE_convolve
2899 /* XXX should test internal format */
2900 if (_mesa_is_color_format(format
)) {
2901 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2906 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2907 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2908 return; /* error was detected */
2911 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2912 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2913 _mesa_lock_texture(ctx
, texObj
);
2915 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2917 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2918 postConvWidth
, postConvHeight
, 1, format
, type
,
2920 goto out
; /* error was detected */
2923 if (width
== 0 || height
== 0)
2924 goto out
; /* no-op, not an error */
2926 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2927 xoffset
+= texImage
->Border
;
2928 yoffset
+= texImage
->Border
;
2930 ASSERT(ctx
->Driver
.TexSubImage2D
);
2931 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2932 width
, height
, format
, type
, pixels
,
2933 &ctx
->Unpack
, texObj
, texImage
);
2934 ctx
->NewState
|= _NEW_TEXTURE
;
2937 _mesa_unlock_texture(ctx
, texObj
);
2943 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2944 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2945 GLsizei width
, GLsizei height
, GLsizei depth
,
2946 GLenum format
, GLenum type
,
2947 const GLvoid
*pixels
)
2949 struct gl_texture_unit
*texUnit
;
2950 struct gl_texture_object
*texObj
;
2951 struct gl_texture_image
*texImage
;
2952 GET_CURRENT_CONTEXT(ctx
);
2953 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2955 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2956 _mesa_update_state(ctx
);
2958 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2959 width
, height
, depth
, format
, type
)) {
2960 return; /* error was detected */
2963 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
2964 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2966 _mesa_lock_texture(ctx
, texObj
);
2968 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2970 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2971 width
, height
, depth
, format
, type
, texImage
)) {
2972 goto out
; /* error was detected */
2975 if (width
== 0 || height
== 0 || height
== 0)
2976 goto out
; /* no-op, not an error */
2978 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2979 xoffset
+= texImage
->Border
;
2980 yoffset
+= texImage
->Border
;
2981 zoffset
+= texImage
->Border
;
2983 ASSERT(ctx
->Driver
.TexSubImage3D
);
2984 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2985 xoffset
, yoffset
, zoffset
,
2986 width
, height
, depth
,
2987 format
, type
, pixels
,
2988 &ctx
->Unpack
, texObj
, texImage
);
2989 ctx
->NewState
|= _NEW_TEXTURE
;
2992 _mesa_unlock_texture(ctx
, texObj
);
2998 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2999 GLenum internalFormat
,
3001 GLsizei width
, GLint border
)
3003 struct gl_texture_unit
*texUnit
;
3004 struct gl_texture_object
*texObj
;
3005 struct gl_texture_image
*texImage
;
3006 GLsizei postConvWidth
= width
;
3007 const GLuint face
= _mesa_tex_target_to_face(target
);
3008 GET_CURRENT_CONTEXT(ctx
);
3009 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3011 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
3012 _mesa_update_state(ctx
);
3014 #if FEATURE_convolve
3015 if (_mesa_is_color_format(internalFormat
)) {
3016 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3020 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
3021 postConvWidth
, 1, border
))
3024 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3025 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3026 _mesa_lock_texture(ctx
, texObj
);
3028 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3030 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
3034 if (texImage
->Data
) {
3035 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3038 ASSERT(texImage
->Data
== NULL
);
3040 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3041 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
3042 border
, internalFormat
);
3045 ASSERT(ctx
->Driver
.CopyTexImage1D
);
3046 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
3047 x
, y
, width
, border
);
3049 ASSERT(texImage
->TexFormat
);
3051 update_fbo_texture(ctx
, texObj
, face
, level
);
3054 texObj
->_Complete
= GL_FALSE
;
3055 ctx
->NewState
|= _NEW_TEXTURE
;
3058 _mesa_unlock_texture(ctx
, texObj
);
3064 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3065 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3068 struct gl_texture_unit
*texUnit
;
3069 struct gl_texture_object
*texObj
;
3070 struct gl_texture_image
*texImage
;
3071 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3072 const GLuint face
= _mesa_tex_target_to_face(target
);
3073 GET_CURRENT_CONTEXT(ctx
);
3074 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3076 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
3077 _mesa_update_state(ctx
);
3079 #if FEATURE_convolve
3080 if (_mesa_is_color_format(internalFormat
)) {
3081 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
3086 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
3087 postConvWidth
, postConvHeight
, border
))
3090 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3091 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3093 _mesa_lock_texture(ctx
, texObj
);
3095 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3098 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
3102 if (texImage
->Data
) {
3103 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3106 ASSERT(texImage
->Data
== NULL
);
3108 clear_teximage_fields(texImage
); /* not really needed, but helpful */
3109 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3110 postConvWidth
, postConvHeight
, 1,
3111 border
, internalFormat
);
3113 ASSERT(ctx
->Driver
.CopyTexImage2D
);
3114 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
3115 x
, y
, width
, height
, border
);
3117 ASSERT(texImage
->TexFormat
);
3119 update_fbo_texture(ctx
, texObj
, face
, level
);
3122 texObj
->_Complete
= GL_FALSE
;
3123 ctx
->NewState
|= _NEW_TEXTURE
;
3126 _mesa_unlock_texture(ctx
, texObj
);
3131 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3132 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3134 struct gl_texture_unit
*texUnit
;
3135 struct gl_texture_object
*texObj
;
3136 struct gl_texture_image
*texImage
;
3137 GLsizei postConvWidth
= width
;
3141 GET_CURRENT_CONTEXT(ctx
);
3142 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3144 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
3145 _mesa_update_state(ctx
);
3147 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3150 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3151 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3153 _mesa_lock_texture(ctx
, texObj
);
3155 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3157 #if FEATURE_convolve
3158 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3159 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3163 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3164 xoffset
, 0, 0, postConvWidth
, 1,
3169 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3170 xoffset
+= texImage
->Border
;
3172 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3174 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3175 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3176 xoffset
, x
, y
, width
);
3179 ctx
->NewState
|= _NEW_TEXTURE
;
3182 _mesa_unlock_texture(ctx
, texObj
);
3188 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3189 GLint xoffset
, GLint yoffset
,
3190 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3192 struct gl_texture_unit
*texUnit
;
3193 struct gl_texture_object
*texObj
;
3194 struct gl_texture_image
*texImage
;
3195 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3196 GET_CURRENT_CONTEXT(ctx
);
3197 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3199 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
3200 _mesa_update_state(ctx
);
3202 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3205 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3206 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3208 _mesa_lock_texture(ctx
, texObj
);
3210 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3212 #if FEATURE_convolve
3213 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3214 _mesa_adjust_image_for_convolution(ctx
, 2,
3215 &postConvWidth
, &postConvHeight
);
3219 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3220 postConvWidth
, postConvHeight
, texImage
))
3223 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3224 xoffset
+= texImage
->Border
;
3225 yoffset
+= texImage
->Border
;
3227 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3229 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3230 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3231 xoffset
, yoffset
, x
, y
, width
, height
);
3234 ctx
->NewState
|= _NEW_TEXTURE
;
3237 _mesa_unlock_texture(ctx
, texObj
);
3243 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3244 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3245 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3247 struct gl_texture_unit
*texUnit
;
3248 struct gl_texture_object
*texObj
;
3249 struct gl_texture_image
*texImage
;
3250 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3251 GET_CURRENT_CONTEXT(ctx
);
3252 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3254 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
3255 _mesa_update_state(ctx
);
3257 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3260 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3261 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3263 _mesa_lock_texture(ctx
, texObj
);
3265 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3267 #if FEATURE_convolve
3268 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3269 _mesa_adjust_image_for_convolution(ctx
, 2,
3270 &postConvWidth
, &postConvHeight
);
3274 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3275 zoffset
, postConvWidth
, postConvHeight
,
3279 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3280 xoffset
+= texImage
->Border
;
3281 yoffset
+= texImage
->Border
;
3282 zoffset
+= texImage
->Border
;
3284 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3286 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3287 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3288 xoffset
, yoffset
, zoffset
,
3289 x
, y
, width
, height
);
3292 ctx
->NewState
|= _NEW_TEXTURE
;
3295 _mesa_unlock_texture(ctx
, texObj
);
3301 /**********************************************************************/
3302 /****** Compressed Textures ******/
3303 /**********************************************************************/
3307 * Error checking for glCompressedTexImage[123]D().
3308 * \return error code or GL_NO_ERROR.
3311 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3312 GLenum target
, GLint level
,
3313 GLenum internalFormat
, GLsizei width
,
3314 GLsizei height
, GLsizei depth
, GLint border
,
3317 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3319 if (dimensions
== 1) {
3320 /* 1D compressed textures not allowed */
3321 return GL_INVALID_ENUM
;
3323 else if (dimensions
== 2) {
3324 if (target
== GL_PROXY_TEXTURE_2D
) {
3325 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3327 else if (target
== GL_TEXTURE_2D
) {
3328 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3330 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3331 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3332 return GL_INVALID_ENUM
; /*target*/
3333 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3335 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3336 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3337 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3338 return GL_INVALID_ENUM
; /*target*/
3339 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3342 return GL_INVALID_ENUM
; /*target*/
3345 else if (dimensions
== 3) {
3346 /* 3D compressed textures not allowed */
3347 return GL_INVALID_ENUM
;
3350 maxTextureSize
= 1 << (maxLevels
- 1);
3352 /* This will detect any invalid internalFormat value */
3353 if (!is_compressed_format(ctx
, internalFormat
))
3354 return GL_INVALID_ENUM
;
3356 /* This should really never fail */
3357 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3358 return GL_INVALID_ENUM
;
3361 return GL_INVALID_VALUE
;
3364 * XXX We should probably use the proxy texture error check function here.
3366 if (width
< 1 || width
> maxTextureSize
||
3367 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3368 return GL_INVALID_VALUE
;
3370 if ((height
< 1 || height
> maxTextureSize
||
3371 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3373 return GL_INVALID_VALUE
;
3375 if ((depth
< 1 || depth
> maxTextureSize
||
3376 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3378 return GL_INVALID_VALUE
;
3380 /* For cube map, width must equal height */
3381 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3382 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3383 return GL_INVALID_VALUE
;
3385 if (level
< 0 || level
>= maxLevels
)
3386 return GL_INVALID_VALUE
;
3388 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3389 depth
, internalFormat
);
3390 if (expectedSize
!= imageSize
)
3391 return GL_INVALID_VALUE
;
3393 #if FEATURE_EXT_texture_sRGB
3394 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3395 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3396 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3397 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3399 return GL_INVALID_OPERATION
;
3408 * Error checking for glCompressedTexSubImage[123]D().
3409 * \warning There are some bad assumptions here about the size of compressed
3410 * texture tiles (multiple of 4) used to test the validity of the
3411 * offset and size parameters.
3412 * \return error code or GL_NO_ERROR.
3415 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3416 GLenum target
, GLint level
,
3417 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3418 GLsizei width
, GLsizei height
, GLsizei depth
,
3419 GLenum format
, GLsizei imageSize
)
3421 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3424 if (dimensions
== 1) {
3425 /* 1D compressed textures not allowed */
3426 return GL_INVALID_ENUM
;
3428 else if (dimensions
== 2) {
3429 if (target
== GL_PROXY_TEXTURE_2D
) {
3430 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3432 else if (target
== GL_TEXTURE_2D
) {
3433 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3435 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3436 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3437 return GL_INVALID_ENUM
; /*target*/
3438 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3440 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3441 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3442 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3443 return GL_INVALID_ENUM
; /*target*/
3444 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3447 return GL_INVALID_ENUM
; /*target*/
3450 else if (dimensions
== 3) {
3451 /* 3D compressed textures not allowed */
3452 return GL_INVALID_ENUM
;
3455 maxTextureSize
= 1 << (maxLevels
- 1);
3457 /* this will catch any invalid compressed format token */
3458 if (!is_compressed_format(ctx
, format
))
3459 return GL_INVALID_ENUM
;
3461 if (width
< 1 || width
> maxTextureSize
)
3462 return GL_INVALID_VALUE
;
3464 if ((height
< 1 || height
> maxTextureSize
)
3466 return GL_INVALID_VALUE
;
3468 if (level
< 0 || level
>= maxLevels
)
3469 return GL_INVALID_VALUE
;
3471 /* XXX these tests are specific to the compressed format.
3472 * this code should be generalized in some way.
3474 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3475 return GL_INVALID_VALUE
;
3477 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3478 return GL_INVALID_VALUE
;
3480 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3481 return GL_INVALID_VALUE
;
3483 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3485 if (expectedSize
!= imageSize
)
3486 return GL_INVALID_VALUE
;
3494 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3495 GLenum internalFormat
, GLsizei width
,
3496 GLint border
, GLsizei imageSize
,
3499 GET_CURRENT_CONTEXT(ctx
);
3500 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3502 if (target
== GL_TEXTURE_1D
) {
3503 /* non-proxy target */
3504 struct gl_texture_unit
*texUnit
;
3505 struct gl_texture_object
*texObj
;
3506 struct gl_texture_image
*texImage
;
3507 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3508 internalFormat
, width
, 1, 1, border
, imageSize
);
3510 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3514 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3515 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3517 _mesa_lock_texture(ctx
, texObj
);
3519 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3521 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3525 if (texImage
->Data
) {
3526 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3528 ASSERT(texImage
->Data
== NULL
);
3530 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3531 border
, internalFormat
);
3533 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3534 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3535 internalFormat
, width
, border
,
3540 texObj
->_Complete
= GL_FALSE
;
3541 ctx
->NewState
|= _NEW_TEXTURE
;
3544 _mesa_unlock_texture(ctx
, texObj
);
3546 else if (target
== GL_PROXY_TEXTURE_1D
) {
3547 /* Proxy texture: check for errors and update proxy state */
3548 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3549 internalFormat
, width
, 1, 1, border
, imageSize
);
3551 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3552 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3553 internalFormat
, GL_NONE
, GL_NONE
,
3554 width
, 1, 1, border
);
3557 /* if error, clear all proxy texture image parameters */
3558 struct gl_texture_image
*texImage
;
3559 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3561 clear_teximage_fields(texImage
);
3564 /* store the teximage parameters */
3565 struct gl_texture_unit
*texUnit
;
3566 struct gl_texture_object
*texObj
;
3567 struct gl_texture_image
*texImage
;
3568 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3569 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3571 _mesa_lock_texture(ctx
, texObj
);
3573 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3574 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3575 border
, internalFormat
);
3577 _mesa_unlock_texture(ctx
, texObj
);
3581 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3588 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3589 GLenum internalFormat
, GLsizei width
,
3590 GLsizei height
, GLint border
, GLsizei imageSize
,
3593 GET_CURRENT_CONTEXT(ctx
);
3594 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3596 if (target
== GL_TEXTURE_2D
||
3597 (ctx
->Extensions
.ARB_texture_cube_map
&&
3598 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3599 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3600 /* non-proxy target */
3601 struct gl_texture_unit
*texUnit
;
3602 struct gl_texture_object
*texObj
;
3603 struct gl_texture_image
*texImage
;
3604 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3605 internalFormat
, width
, height
, 1, border
, imageSize
);
3607 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3611 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3612 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3614 _mesa_lock_texture(ctx
, texObj
);
3616 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3618 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3622 if (texImage
->Data
) {
3623 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3625 ASSERT(texImage
->Data
== NULL
);
3627 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3628 border
, internalFormat
);
3630 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3631 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3632 internalFormat
, width
, height
,
3633 border
, imageSize
, data
,
3637 texObj
->_Complete
= GL_FALSE
;
3638 ctx
->NewState
|= _NEW_TEXTURE
;
3641 _mesa_unlock_texture(ctx
, texObj
);
3643 else if (target
== GL_PROXY_TEXTURE_2D
||
3644 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3645 ctx
->Extensions
.ARB_texture_cube_map
)) {
3646 /* Proxy texture: check for errors and update proxy state */
3647 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3648 internalFormat
, width
, height
, 1, border
, imageSize
);
3650 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3651 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3652 internalFormat
, GL_NONE
, GL_NONE
,
3653 width
, height
, 1, border
);
3656 /* if error, clear all proxy texture image parameters */
3657 struct gl_texture_image
*texImage
;
3658 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3660 clear_teximage_fields(texImage
);
3663 /* store the teximage parameters */
3664 struct gl_texture_unit
*texUnit
;
3665 struct gl_texture_object
*texObj
;
3666 struct gl_texture_image
*texImage
;
3667 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3668 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3670 _mesa_lock_texture(ctx
, texObj
);
3672 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3673 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3674 border
, internalFormat
);
3676 _mesa_unlock_texture(ctx
, texObj
);
3680 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3687 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3688 GLenum internalFormat
, GLsizei width
,
3689 GLsizei height
, GLsizei depth
, GLint border
,
3690 GLsizei imageSize
, const GLvoid
*data
)
3692 GET_CURRENT_CONTEXT(ctx
);
3693 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3695 if (target
== GL_TEXTURE_3D
) {
3696 /* non-proxy target */
3697 struct gl_texture_unit
*texUnit
;
3698 struct gl_texture_object
*texObj
;
3699 struct gl_texture_image
*texImage
;
3700 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3701 internalFormat
, width
, height
, depth
, border
, imageSize
);
3703 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3707 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3708 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3709 _mesa_lock_texture(ctx
, texObj
);
3711 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3713 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3717 if (texImage
->Data
) {
3718 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3720 ASSERT(texImage
->Data
== NULL
);
3722 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3723 border
, internalFormat
);
3725 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3726 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3728 width
, height
, depth
,
3729 border
, imageSize
, data
,
3733 texObj
->_Complete
= GL_FALSE
;
3734 ctx
->NewState
|= _NEW_TEXTURE
;
3737 _mesa_unlock_texture(ctx
, texObj
);
3739 else if (target
== GL_PROXY_TEXTURE_3D
) {
3740 /* Proxy texture: check for errors and update proxy state */
3741 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3742 internalFormat
, width
, height
, depth
, border
, imageSize
);
3744 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3745 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3746 internalFormat
, GL_NONE
, GL_NONE
,
3747 width
, height
, depth
, border
);
3750 /* if error, clear all proxy texture image parameters */
3751 struct gl_texture_image
*texImage
;
3752 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3754 clear_teximage_fields(texImage
);
3757 /* store the teximage parameters */
3758 struct gl_texture_unit
*texUnit
;
3759 struct gl_texture_object
*texObj
;
3760 struct gl_texture_image
*texImage
;
3761 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3762 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3763 _mesa_lock_texture(ctx
, texObj
);
3765 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3766 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3767 depth
, border
, internalFormat
);
3769 _mesa_unlock_texture(ctx
, texObj
);
3773 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3780 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3781 GLsizei width
, GLenum format
,
3782 GLsizei imageSize
, const GLvoid
*data
)
3784 struct gl_texture_unit
*texUnit
;
3785 struct gl_texture_object
*texObj
;
3786 struct gl_texture_image
*texImage
;
3788 GET_CURRENT_CONTEXT(ctx
);
3789 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3791 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3792 xoffset
, 0, 0, /* pos */
3793 width
, 1, 1, /* size */
3796 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3800 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3801 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3802 _mesa_lock_texture(ctx
, texObj
);
3804 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3807 if ((GLint
) format
!= texImage
->InternalFormat
) {
3808 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3809 "glCompressedTexSubImage1D(format)");
3813 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3814 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3819 goto out
; /* no-op, not an error */
3821 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3822 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3824 format
, imageSize
, data
,
3827 ctx
->NewState
|= _NEW_TEXTURE
;
3830 _mesa_unlock_texture(ctx
, texObj
);
3835 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3836 GLint yoffset
, GLsizei width
, GLsizei height
,
3837 GLenum format
, GLsizei imageSize
,
3840 struct gl_texture_unit
*texUnit
;
3841 struct gl_texture_object
*texObj
;
3842 struct gl_texture_image
*texImage
;
3844 GET_CURRENT_CONTEXT(ctx
);
3845 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3847 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3848 xoffset
, yoffset
, 0, /* pos */
3849 width
, height
, 1, /* size */
3852 /* XXX proxy target? */
3853 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3857 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3858 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3859 _mesa_lock_texture(ctx
, texObj
);
3861 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3864 if ((GLint
) format
!= texImage
->InternalFormat
) {
3865 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3866 "glCompressedTexSubImage2D(format)");
3870 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3871 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3872 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3876 if (width
== 0 || height
== 0)
3877 goto out
; /* no-op, not an error */
3879 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3880 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3881 xoffset
, yoffset
, width
, height
,
3882 format
, imageSize
, data
,
3885 ctx
->NewState
|= _NEW_TEXTURE
;
3888 _mesa_unlock_texture(ctx
, texObj
);
3893 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3894 GLint yoffset
, GLint zoffset
, GLsizei width
,
3895 GLsizei height
, GLsizei depth
, GLenum format
,
3896 GLsizei imageSize
, const GLvoid
*data
)
3898 struct gl_texture_unit
*texUnit
;
3899 struct gl_texture_object
*texObj
;
3900 struct gl_texture_image
*texImage
;
3902 GET_CURRENT_CONTEXT(ctx
);
3903 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3905 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3906 xoffset
, yoffset
, zoffset
,/*pos*/
3907 width
, height
, depth
, /*size*/
3910 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3914 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3915 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3916 _mesa_lock_texture(ctx
, texObj
);
3918 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3921 if ((GLint
) format
!= texImage
->InternalFormat
) {
3922 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3923 "glCompressedTexSubImage3D(format)");
3927 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3928 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3929 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3930 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3934 if (width
== 0 || height
== 0 || depth
== 0)
3935 goto out
; /* no-op, not an error */
3937 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3938 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3939 xoffset
, yoffset
, zoffset
,
3940 width
, height
, depth
,
3941 format
, imageSize
, data
,
3944 ctx
->NewState
|= _NEW_TEXTURE
;
3947 _mesa_unlock_texture(ctx
, texObj
);
3952 _mesa_GetCompressedTexImageARB(GLenum target
, GLint level
, GLvoid
*img
)
3954 const struct gl_texture_unit
*texUnit
;
3955 struct gl_texture_object
*texObj
;
3956 struct gl_texture_image
*texImage
;
3958 GET_CURRENT_CONTEXT(ctx
);
3959 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3961 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
3962 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3964 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB");
3968 maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3969 ASSERT(maxLevels
> 0); /* 0 indicates bad target, caught above */
3971 if (level
< 0 || level
>= maxLevels
) {
3972 _mesa_error(ctx
, GL_INVALID_VALUE
, "glGetCompressedTexImageARB(level)");
3976 if (_mesa_is_proxy_texture(target
)) {
3977 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetCompressedTexImageARB(target)");
3981 _mesa_lock_texture(ctx
, texObj
);
3983 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3985 if (texImage
->IsCompressed
) {
3986 /* this typically calls _mesa_get_compressed_teximage() */
3987 ctx
->Driver
.GetCompressedTexImage(ctx
, target
, level
, img
,
3991 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3992 "glGetCompressedTexImageARB");
3996 /* probably invalid mipmap level */
3997 _mesa_error(ctx
, GL_INVALID_VALUE
,
3998 "glGetCompressedTexImageARB(level)");
4001 _mesa_unlock_texture(ctx
, texObj
);