2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
40 #include "framebuffer.h"
46 #include "texcompress.h"
47 #include "texformat.h"
55 * State changes which we care about for glCopyTex[Sub]Image() calls.
56 * In particular, we care about pixel transfer state and buffer state
57 * (such as glReadBuffer to make sure we read from the right renderbuffer).
59 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
66 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
70 _mesa_alloc_texmemory(GLsizei bytes
)
72 return _mesa_align_malloc(bytes
, 512);
77 * Free texture memory allocated with _mesa_alloc_texmemory()
80 _mesa_free_texmemory(void *m
)
89 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
91 #if CHAN_TYPE != GL_UNSIGNED_BYTE
92 _mesa_problem(NULL
, "PrintTexture not supported");
95 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
98 _mesa_printf("No texture data\n");
102 switch (img
->Format
) {
109 case GL_LUMINANCE_ALPHA
:
119 _mesa_problem(NULL
, "error in PrintTexture\n");
123 for (i
= 0; i
< img
->Height
; i
++) {
124 for (j
= 0; j
< img
->Width
; j
++) {
126 _mesa_printf("%02x ", data
[0]);
128 _mesa_printf("%02x%02x ", data
[0], data
[1]);
130 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
132 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
133 data
+= (img
->RowStride
- img
->Width
) * c
;
135 /* XXX use img->ImageStride here */
144 * Compute floor(log_base_2(n)).
145 * If n < 0 return -1.
174 * Return the simple base format for a given internal texture format.
175 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
177 * \param ctx GL context.
178 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
180 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
181 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
183 * This is the format which is used during texture application (i.e. the
184 * texture format and env mode determine the arithmetic used.
187 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
189 switch (internalFormat
) {
204 case GL_LUMINANCE_ALPHA
:
205 case GL_LUMINANCE4_ALPHA4
:
206 case GL_LUMINANCE6_ALPHA2
:
207 case GL_LUMINANCE8_ALPHA8
:
208 case GL_LUMINANCE12_ALPHA4
:
209 case GL_LUMINANCE12_ALPHA12
:
210 case GL_LUMINANCE16_ALPHA16
:
211 return GL_LUMINANCE_ALPHA
;
242 if (ctx
->Extensions
.EXT_paletted_texture
) {
243 switch (internalFormat
) {
245 case GL_COLOR_INDEX1_EXT
:
246 case GL_COLOR_INDEX2_EXT
:
247 case GL_COLOR_INDEX4_EXT
:
248 case GL_COLOR_INDEX8_EXT
:
249 case GL_COLOR_INDEX12_EXT
:
250 case GL_COLOR_INDEX16_EXT
:
251 return GL_COLOR_INDEX
;
257 if (ctx
->Extensions
.ARB_depth_texture
) {
258 switch (internalFormat
) {
259 case GL_DEPTH_COMPONENT
:
260 case GL_DEPTH_COMPONENT16
:
261 case GL_DEPTH_COMPONENT24
:
262 case GL_DEPTH_COMPONENT32
:
263 return GL_DEPTH_COMPONENT
;
269 switch (internalFormat
) {
270 case GL_COMPRESSED_ALPHA
:
272 case GL_COMPRESSED_LUMINANCE
:
274 case GL_COMPRESSED_LUMINANCE_ALPHA
:
275 return GL_LUMINANCE_ALPHA
;
276 case GL_COMPRESSED_INTENSITY
:
278 case GL_COMPRESSED_RGB
:
280 case GL_COMPRESSED_RGBA
:
286 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
287 switch (internalFormat
) {
288 case GL_COMPRESSED_RGB_FXT1_3DFX
:
290 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
297 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
298 switch (internalFormat
) {
299 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
301 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
302 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
303 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
310 if (ctx
->Extensions
.S3_s3tc
) {
311 switch (internalFormat
) {
323 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
324 if (internalFormat
== GL_YCBCR_MESA
)
325 return GL_YCBCR_MESA
;
328 if (ctx
->Extensions
.ARB_texture_float
) {
329 switch (internalFormat
) {
330 case GL_ALPHA16F_ARB
:
331 case GL_ALPHA32F_ARB
:
339 case GL_INTENSITY16F_ARB
:
340 case GL_INTENSITY32F_ARB
:
342 case GL_LUMINANCE16F_ARB
:
343 case GL_LUMINANCE32F_ARB
:
345 case GL_LUMINANCE_ALPHA16F_ARB
:
346 case GL_LUMINANCE_ALPHA32F_ARB
:
347 return GL_LUMINANCE_ALPHA
;
353 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
354 switch (internalFormat
) {
363 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
364 switch (internalFormat
) {
373 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
374 switch (internalFormat
) {
375 case GL_DEPTH_STENCIL_EXT
:
376 case GL_DEPTH24_STENCIL8_EXT
:
377 return GL_DEPTH_STENCIL_EXT
;
383 #if FEATURE_EXT_texture_sRGB
384 if (ctx
->Extensions
.EXT_texture_sRGB
) {
385 switch (internalFormat
) {
388 case GL_COMPRESSED_SRGB_EXT
:
389 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
391 case GL_SRGB_ALPHA_EXT
:
392 case GL_SRGB8_ALPHA8_EXT
:
393 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
394 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
395 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
396 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
398 case GL_SLUMINANCE_ALPHA_EXT
:
399 case GL_SLUMINANCE8_ALPHA8_EXT
:
400 case GL_COMPRESSED_SLUMINANCE_EXT
:
401 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
402 return GL_LUMINANCE_ALPHA
;
403 case GL_SLUMINANCE_EXT
:
404 case GL_SLUMINANCE8_EXT
:
411 #endif /* FEATURE_EXT_texture_sRGB */
413 return -1; /* error */
418 * Test if the given image format is a color/RGBA format (i.e., not color
419 * index, depth, stencil, etc).
420 * \param format the image format value (may by an internal texture format)
421 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
422 * XXX maybe move this func to image.c
425 _mesa_is_color_format(GLenum format
)
443 case GL_LUMINANCE_ALPHA
:
444 case GL_LUMINANCE4_ALPHA4
:
445 case GL_LUMINANCE6_ALPHA2
:
446 case GL_LUMINANCE8_ALPHA8
:
447 case GL_LUMINANCE12_ALPHA4
:
448 case GL_LUMINANCE12_ALPHA12
:
449 case GL_LUMINANCE16_ALPHA16
:
476 /* float texture formats */
477 case GL_ALPHA16F_ARB
:
478 case GL_ALPHA32F_ARB
:
479 case GL_LUMINANCE16F_ARB
:
480 case GL_LUMINANCE32F_ARB
:
481 case GL_LUMINANCE_ALPHA16F_ARB
:
482 case GL_LUMINANCE_ALPHA32F_ARB
:
483 case GL_INTENSITY16F_ARB
:
484 case GL_INTENSITY32F_ARB
:
489 /* compressed formats */
490 case GL_COMPRESSED_ALPHA
:
491 case GL_COMPRESSED_LUMINANCE
:
492 case GL_COMPRESSED_LUMINANCE_ALPHA
:
493 case GL_COMPRESSED_INTENSITY
:
494 case GL_COMPRESSED_RGB
:
495 case GL_COMPRESSED_RGBA
:
500 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
501 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
502 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
503 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
504 case GL_COMPRESSED_RGB_FXT1_3DFX
:
505 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
506 #if FEATURE_EXT_texture_sRGB
509 case GL_SRGB_ALPHA_EXT
:
510 case GL_SRGB8_ALPHA8_EXT
:
511 case GL_SLUMINANCE_ALPHA_EXT
:
512 case GL_SLUMINANCE8_ALPHA8_EXT
:
513 case GL_SLUMINANCE_EXT
:
514 case GL_SLUMINANCE8_EXT
:
515 case GL_COMPRESSED_SRGB_EXT
:
516 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
517 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
518 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
519 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
520 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
521 case GL_COMPRESSED_SLUMINANCE_EXT
:
522 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
523 #endif /* FEATURE_EXT_texture_sRGB */
525 /* signed texture formats */
529 case GL_YCBCR_MESA
: /* not considered to be RGB */
538 * Test if the given image format is a color index format.
541 _mesa_is_index_format(GLenum format
)
545 case GL_COLOR_INDEX1_EXT
:
546 case GL_COLOR_INDEX2_EXT
:
547 case GL_COLOR_INDEX4_EXT
:
548 case GL_COLOR_INDEX8_EXT
:
549 case GL_COLOR_INDEX12_EXT
:
550 case GL_COLOR_INDEX16_EXT
:
559 * Test if the given image format is a depth component format.
562 _mesa_is_depth_format(GLenum format
)
565 case GL_DEPTH_COMPONENT16
:
566 case GL_DEPTH_COMPONENT24
:
567 case GL_DEPTH_COMPONENT32
:
568 case GL_DEPTH_COMPONENT
:
577 * Test if the given image format is a YCbCr format.
580 _mesa_is_ycbcr_format(GLenum format
)
592 * Test if the given image format is a Depth/Stencil format.
595 _mesa_is_depthstencil_format(GLenum format
)
598 case GL_DEPTH24_STENCIL8_EXT
:
599 case GL_DEPTH_STENCIL_EXT
:
607 * Test if the given image format is a dudv format.
610 _mesa_is_dudv_format(GLenum format
)
623 * Test if it is a supported compressed format.
625 * \param internalFormat the internal format token provided by the user.
627 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
628 * GL_FALSE otherwise.
630 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
634 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
636 GLint supported
[100]; /* 100 should be plenty */
639 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
641 for (i
= 0; i
< n
; i
++) {
642 if ((GLint
) internalFormat
== supported
[i
]) {
651 * For cube map faces, return a face index in [0,5].
652 * For other targets return 0;
655 _mesa_tex_target_to_face(GLenum target
)
657 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
658 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
659 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
667 * Store a gl_texture_image pointer in a gl_texture_object structure
668 * according to the target and level parameters.
670 * \param tObj texture object.
671 * \param target texture target.
672 * \param level image level.
673 * \param texImage texture image.
675 * This was basically prompted by the introduction of cube maps.
678 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
679 GLenum target
, GLint level
,
680 struct gl_texture_image
*texImage
)
682 const GLuint face
= _mesa_tex_target_to_face(target
);
686 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
688 tObj
->Image
[face
][level
] = texImage
;
690 /* Set the 'back' pointer */
691 texImage
->TexObject
= tObj
;
696 * Allocate a texture image structure.
698 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
701 * \return a pointer to gl_texture_image struct with all fields initialized to
704 struct gl_texture_image
*
705 _mesa_new_texture_image( GLcontext
*ctx
)
708 return CALLOC_STRUCT(gl_texture_image
);
713 * Free texture image data.
714 * This function is a fallback called via ctx->Driver.FreeTexImageData().
716 * \param texImage texture image.
718 * Free the texture image data if it's not marked as client data.
721 _mesa_free_texture_image_data(GLcontext
*ctx
,
722 struct gl_texture_image
*texImage
)
726 if (texImage
->Data
&& !texImage
->IsClientData
) {
727 /* free the old texture data */
728 _mesa_free_texmemory(texImage
->Data
);
731 texImage
->Data
= NULL
;
736 * Free texture image.
738 * \param texImage texture image.
740 * Free the texture image structure and the associated image data.
743 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
745 /* Free texImage->Data and/or any other driver-specific texture
748 ASSERT(ctx
->Driver
.FreeTexImageData
);
749 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
751 ASSERT(texImage
->Data
== NULL
);
752 if (texImage
->ImageOffsets
)
753 _mesa_free(texImage
->ImageOffsets
);
754 _mesa_free(texImage
);
759 * Test if a target is a proxy target.
761 * \param target texture target.
763 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
766 _mesa_is_proxy_texture(GLenum target
)
768 /* NUM_TEXTURE_TARGETS should match number of terms below */
769 assert(NUM_TEXTURE_TARGETS
== 7);
771 return (target
== GL_PROXY_TEXTURE_1D
||
772 target
== GL_PROXY_TEXTURE_2D
||
773 target
== GL_PROXY_TEXTURE_3D
||
774 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
775 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
776 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
777 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
782 * Return pointer to current texture unit.
783 * This the texture unit set by glActiveTexture(), not glClientActiveTexture().
785 static INLINE
struct gl_texture_unit
*
786 get_current_tex_unit(GLcontext
*ctx
)
788 ASSERT(ctx
->Texture
.CurrentUnit
< Elements(ctx
->Texture
.Unit
));
789 return &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
794 * Get the texture object that corresponds to the target of the given texture unit.
796 * \param ctx GL context.
797 * \param texUnit texture unit.
798 * \param target texture target.
800 * \return pointer to the texture object on success, or NULL on failure.
802 * \sa gl_texture_unit.
804 struct gl_texture_object
*
805 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
810 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
811 case GL_PROXY_TEXTURE_1D
:
812 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
814 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
815 case GL_PROXY_TEXTURE_2D
:
816 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
818 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
819 case GL_PROXY_TEXTURE_3D
:
820 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
821 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
822 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
823 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
824 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
825 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
826 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
827 case GL_TEXTURE_CUBE_MAP_ARB
:
828 return ctx
->Extensions
.ARB_texture_cube_map
829 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
830 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
831 return ctx
->Extensions
.ARB_texture_cube_map
832 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
833 case GL_TEXTURE_RECTANGLE_NV
:
834 return ctx
->Extensions
.NV_texture_rectangle
835 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
836 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
837 return ctx
->Extensions
.NV_texture_rectangle
838 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
839 case GL_TEXTURE_1D_ARRAY_EXT
:
840 return ctx
->Extensions
.MESA_texture_array
841 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
842 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
843 return ctx
->Extensions
.MESA_texture_array
844 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
845 case GL_TEXTURE_2D_ARRAY_EXT
:
846 return ctx
->Extensions
.MESA_texture_array
847 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
848 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
849 return ctx
->Extensions
.MESA_texture_array
850 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
852 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
859 * Get a texture image pointer from a texture object, given a texture
860 * target and mipmap level. The target and level parameters should
861 * have already been error-checked.
863 * \param ctx GL context.
864 * \param texObj texture unit.
865 * \param target texture target.
866 * \param level image level.
868 * \return pointer to the texture image structure, or NULL on failure.
870 struct gl_texture_image
*
871 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
872 GLenum target
, GLint level
)
874 const GLuint face
= _mesa_tex_target_to_face(target
);
878 ASSERT(level
< MAX_TEXTURE_LEVELS
);
880 return texObj
->Image
[face
][level
];
885 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
886 * it and install it. Only return NULL if passed a bad parameter or run
889 struct gl_texture_image
*
890 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
891 GLenum target
, GLint level
)
893 struct gl_texture_image
*texImage
;
898 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
900 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
902 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
906 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
914 * Return pointer to the specified proxy texture image.
915 * Note that proxy textures are per-context, not per-texture unit.
916 * \return pointer to texture image or NULL if invalid target, invalid
917 * level, or out of memory.
919 struct gl_texture_image
*
920 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
922 struct gl_texture_image
*texImage
;
929 case GL_PROXY_TEXTURE_1D
:
930 if (level
>= ctx
->Const
.MaxTextureLevels
)
932 texIndex
= TEXTURE_1D_INDEX
;
934 case GL_PROXY_TEXTURE_2D
:
935 if (level
>= ctx
->Const
.MaxTextureLevels
)
937 texIndex
= TEXTURE_2D_INDEX
;
939 case GL_PROXY_TEXTURE_3D
:
940 if (level
>= ctx
->Const
.Max3DTextureLevels
)
942 texIndex
= TEXTURE_3D_INDEX
;
944 case GL_PROXY_TEXTURE_CUBE_MAP
:
945 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
947 texIndex
= TEXTURE_CUBE_INDEX
;
949 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
952 texIndex
= TEXTURE_RECT_INDEX
;
954 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
955 if (level
>= ctx
->Const
.MaxTextureLevels
)
957 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
959 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
960 if (level
>= ctx
->Const
.MaxTextureLevels
)
962 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
968 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
970 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
972 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
975 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
976 /* Set the 'back' pointer */
977 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
984 * Get the maximum number of allowed mipmap levels.
986 * \param ctx GL context.
987 * \param target texture target.
989 * \return the maximum number of allowed mipmap levels for the given
990 * texture target, or zero if passed a bad target.
995 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
999 case GL_PROXY_TEXTURE_1D
:
1001 case GL_PROXY_TEXTURE_2D
:
1002 case GL_TEXTURE_1D_ARRAY_EXT
:
1003 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1004 case GL_TEXTURE_2D_ARRAY_EXT
:
1005 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1006 return ctx
->Const
.MaxTextureLevels
;
1008 case GL_PROXY_TEXTURE_3D
:
1009 return ctx
->Const
.Max3DTextureLevels
;
1010 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1011 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1012 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1013 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1014 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1015 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1016 case GL_TEXTURE_CUBE_MAP_ARB
:
1017 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1018 return ctx
->Const
.MaxCubeTextureLevels
;
1019 case GL_TEXTURE_RECTANGLE_NV
:
1020 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1023 return 0; /* bad target */
1029 #if 000 /* not used anymore */
1031 * glTexImage[123]D can accept a NULL image pointer. In this case we
1032 * create a texture image with unspecified image contents per the OpenGL
1036 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1038 const GLint components
= _mesa_components_in_format(format
);
1039 const GLint numPixels
= width
* height
* depth
;
1040 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1044 * Let's see if anyone finds this. If glTexImage2D() is called with
1045 * a NULL image pointer then load the texture image with something
1046 * interesting instead of leaving it indeterminate.
1049 static const char message
[8][32] = {
1050 " X X XXXXX XXX X ",
1051 " XX XX X X X X X ",
1053 " X X XXXX XXX XXXXX ",
1056 " X X XXXXX XXX X X ",
1060 GLubyte
*imgPtr
= data
;
1062 for (h
= 0; h
< depth
; h
++) {
1063 for (i
= 0; i
< height
; i
++) {
1064 GLint srcRow
= 7 - (i
% 8);
1065 for (j
= 0; j
< width
; j
++) {
1066 GLint srcCol
= j
% 32;
1067 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1068 for (k
= 0; k
< components
; k
++) {
1084 * Reset the fields of a gl_texture_image struct to zero.
1086 * \param img texture image structure.
1088 * This is called when a proxy texture test fails, we set all the
1089 * image members (except DriverData) to zero.
1090 * It's also used in glTexImage[123]D as a safeguard to be sure all
1091 * required fields get initialized properly by the Driver.TexImage[123]D
1095 clear_teximage_fields(struct gl_texture_image
*img
)
1098 img
->_BaseFormat
= 0;
1099 img
->InternalFormat
= 0;
1105 if (img
->ImageOffsets
) {
1106 _mesa_free(img
->ImageOffsets
);
1107 img
->ImageOffsets
= NULL
;
1113 img
->HeightLog2
= 0;
1116 img
->TexFormat
= &_mesa_null_texformat
;
1117 img
->FetchTexelc
= NULL
;
1118 img
->FetchTexelf
= NULL
;
1119 img
->IsCompressed
= 0;
1120 img
->CompressedSize
= 0;
1125 * Initialize basic fields of the gl_texture_image struct.
1127 * \param ctx GL context.
1128 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1129 * \param img texture image structure to be initialized.
1130 * \param width image width.
1131 * \param height image height.
1132 * \param depth image depth.
1133 * \param border image border.
1134 * \param internalFormat internal format.
1136 * Fills in the fields of \p img with the given information.
1137 * Note: width, height and depth include the border.
1140 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
1141 struct gl_texture_image
*img
,
1142 GLsizei width
, GLsizei height
, GLsizei depth
,
1143 GLint border
, GLenum internalFormat
)
1149 ASSERT(height
>= 0);
1152 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1153 ASSERT(img
->_BaseFormat
> 0);
1154 img
->InternalFormat
= internalFormat
;
1155 img
->Border
= border
;
1157 img
->Height
= height
;
1160 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1161 img
->WidthLog2
= logbase2(img
->Width2
);
1163 if (height
== 1) { /* 1-D texture */
1165 img
->HeightLog2
= 0;
1168 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1169 img
->HeightLog2
= logbase2(img
->Height2
);
1172 if (depth
== 1) { /* 2-D texture */
1177 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1178 img
->DepthLog2
= logbase2(img
->Depth2
);
1181 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1183 img
->IsCompressed
= GL_FALSE
;
1184 img
->CompressedSize
= 0;
1186 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1187 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1188 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1189 img
->_IsPowerOfTwo
= GL_TRUE
;
1191 img
->_IsPowerOfTwo
= GL_FALSE
;
1193 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1194 img
->RowStride
= width
;
1195 /* Allocate the ImageOffsets array and initialize to typical values.
1196 * We allocate the array for 1D/2D textures too in order to avoid special-
1197 * case code in the texstore routines.
1199 if (img
->ImageOffsets
)
1200 _mesa_free(img
->ImageOffsets
);
1201 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
1202 for (i
= 0; i
< depth
; i
++) {
1203 img
->ImageOffsets
[i
] = i
* width
* height
;
1206 /* Compute Width/Height/DepthScale for mipmap lod computation */
1207 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1208 /* scale = 1.0 since texture coords directly map to texels */
1209 img
->WidthScale
= 1.0;
1210 img
->HeightScale
= 1.0;
1211 img
->DepthScale
= 1.0;
1214 img
->WidthScale
= (GLfloat
) img
->Width
;
1215 img
->HeightScale
= (GLfloat
) img
->Height
;
1216 img
->DepthScale
= (GLfloat
) img
->Depth
;
1222 * Free and clear fields of the gl_texture_image struct.
1224 * \param ctx GL context.
1225 * \param texImage texture image structure to be cleared.
1227 * After the call, \p texImage will have no data associated with it. Its
1228 * fields are cleared so that its parent object will test incomplete.
1231 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
1233 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1234 clear_teximage_fields(texImage
);
1239 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1240 * level, width, height and depth against the ctx->Const limits for textures.
1242 * A hardware driver might override this function if, for example, the
1243 * max 3D texture size is 512x512x64 (i.e. not a cube).
1245 * Note that width, height, depth == 0 is not an error. However, a
1246 * texture with zero width/height/depth will be considered "incomplete"
1247 * and texturing will effectively be disabled.
1249 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1250 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1251 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1252 * \param level as passed to glTexImage
1253 * \param internalFormat as passed to glTexImage
1254 * \param format as passed to glTexImage
1255 * \param type as passed to glTexImage
1256 * \param width as passed to glTexImage
1257 * \param height as passed to glTexImage
1258 * \param depth as passed to glTexImage
1259 * \param border as passed to glTexImage
1260 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1263 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1264 GLint internalFormat
, GLenum format
, GLenum type
,
1265 GLint width
, GLint height
, GLint depth
, GLint border
)
1269 (void) internalFormat
;
1274 case GL_PROXY_TEXTURE_1D
:
1275 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1276 if (width
< 2 * border
|| width
> 2 + maxSize
||
1277 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1278 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1279 level
>= ctx
->Const
.MaxTextureLevels
) {
1280 /* bad width or level */
1284 case GL_PROXY_TEXTURE_2D
:
1285 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1286 if (width
< 2 * border
|| width
> 2 + maxSize
||
1287 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1288 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1289 height
< 2 * border
|| height
> 2 + maxSize
||
1290 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1291 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1292 level
>= ctx
->Const
.MaxTextureLevels
) {
1293 /* bad width or height or level */
1297 case GL_PROXY_TEXTURE_3D
:
1298 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1299 if (width
< 2 * border
|| width
> 2 + maxSize
||
1300 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1301 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1302 height
< 2 * border
|| height
> 2 + maxSize
||
1303 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1304 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1305 depth
< 2 * border
|| depth
> 2 + maxSize
||
1306 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1307 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1308 level
>= ctx
->Const
.Max3DTextureLevels
) {
1309 /* bad width or height or depth or level */
1313 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1314 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1315 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1317 /* bad width or height or level */
1321 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1322 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1323 if (width
< 2 * border
|| width
> 2 + maxSize
||
1324 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1325 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1326 height
< 2 * border
|| height
> 2 + maxSize
||
1327 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1328 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1329 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1330 /* bad width or height */
1334 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1335 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1336 if (width
< 2 * border
|| width
> 2 + maxSize
||
1337 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1338 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1339 level
>= ctx
->Const
.MaxTextureLevels
) {
1340 /* bad width or level */
1344 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1348 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1349 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1350 if (width
< 2 * border
|| width
> 2 + maxSize
||
1351 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1352 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1353 height
< 2 * border
|| height
> 2 + maxSize
||
1354 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1355 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1356 level
>= ctx
->Const
.MaxTextureLevels
) {
1357 /* bad width or height or level */
1360 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1365 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1372 * Helper function to determine whether a target supports compressed textures
1375 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1377 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1378 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1379 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1380 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1381 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1382 || ((ctx
->Extensions
.MESA_texture_array
&&
1383 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1384 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1389 * Test the glTexImage[123]D() parameters for errors.
1391 * \param ctx GL context.
1392 * \param target texture target given by the user.
1393 * \param level image level given by the user.
1394 * \param internalFormat internal format given by the user.
1395 * \param format pixel data format given by the user.
1396 * \param type pixel data type given by the user.
1397 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1398 * \param width image width given by the user.
1399 * \param height image height given by the user.
1400 * \param depth image depth given by the user.
1401 * \param border image border given by the user.
1403 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1405 * Verifies each of the parameters against the constants specified in
1406 * __GLcontextRec::Const and the supported extensions, and according to the
1407 * OpenGL specification.
1410 texture_error_check( GLcontext
*ctx
, GLenum target
,
1411 GLint level
, GLint internalFormat
,
1412 GLenum format
, GLenum type
,
1414 GLint width
, GLint height
,
1415 GLint depth
, GLint border
)
1417 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1418 GLboolean sizeOK
= GL_TRUE
;
1419 GLboolean colorFormat
, indexFormat
;
1420 GLenum proxy_target
;
1422 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1423 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1425 _mesa_error(ctx
, GL_INVALID_VALUE
,
1426 "glTexImage%dD(level=%d)", dimensions
, level
);
1432 if (border
< 0 || border
> 1 ||
1433 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1434 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1436 _mesa_error(ctx
, GL_INVALID_VALUE
,
1437 "glTexImage%dD(border=%d)", dimensions
, border
);
1442 if (width
< 0 || height
< 0 || depth
< 0) {
1444 _mesa_error(ctx
, GL_INVALID_VALUE
,
1445 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1450 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1451 * level, width, height and depth.
1453 if (dimensions
== 1) {
1454 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1455 proxy_target
= GL_PROXY_TEXTURE_1D
;
1460 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1464 else if (dimensions
== 2) {
1466 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1467 proxy_target
= GL_PROXY_TEXTURE_2D
;
1469 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1470 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1471 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1472 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1473 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1476 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1477 sizeOK
= (width
== height
);
1479 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1480 target
== GL_TEXTURE_RECTANGLE_NV
) {
1481 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1482 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1485 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1487 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1488 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1489 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1492 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1496 else if (dimensions
== 3) {
1497 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1498 proxy_target
= GL_PROXY_TEXTURE_3D
;
1500 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1501 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1502 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1505 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1510 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1514 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1515 internalFormat
, format
,
1516 type
, width
, height
,
1520 _mesa_error(ctx
, GL_INVALID_VALUE
,
1521 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1522 dimensions
, level
, width
, height
, depth
);
1527 /* Check internalFormat */
1528 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1530 _mesa_error(ctx
, GL_INVALID_VALUE
,
1531 "glTexImage%dD(internalFormat=0x%x)",
1532 dimensions
, internalFormat
);
1537 /* Check incoming image format and type */
1538 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1539 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1540 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1543 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1544 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1545 dimensions
, format
, type
);
1550 /* make sure internal format and format basically agree */
1551 colorFormat
= _mesa_is_color_format(format
);
1552 indexFormat
= _mesa_is_index_format(format
);
1553 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1554 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1555 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1556 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1557 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1558 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1560 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1561 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1562 dimensions
, internalFormat
, format
);
1566 /* additional checks for ycbcr textures */
1567 if (internalFormat
== GL_YCBCR_MESA
) {
1568 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1569 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1570 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1572 _mesa_sprintf(message
,
1573 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1574 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1575 return GL_TRUE
; /* error */
1577 if (target
!= GL_TEXTURE_2D
&&
1578 target
!= GL_PROXY_TEXTURE_2D
&&
1579 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1580 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1582 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1588 _mesa_sprintf(message
,
1589 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1590 dimensions
, border
);
1591 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1597 /* additional checks for depth textures */
1598 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1599 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1600 if (target
!= GL_TEXTURE_1D
&&
1601 target
!= GL_PROXY_TEXTURE_1D
&&
1602 target
!= GL_TEXTURE_2D
&&
1603 target
!= GL_PROXY_TEXTURE_2D
&&
1604 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1605 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1607 _mesa_error(ctx
, GL_INVALID_ENUM
,
1608 "glTexImage(target/internalFormat)");
1613 /* additional checks for compressed textures */
1614 if (is_compressed_format(ctx
, internalFormat
)) {
1615 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1616 _mesa_error(ctx
, GL_INVALID_ENUM
,
1617 "glTexImage%d(target)", dimensions
);
1622 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1623 "glTexImage%D(border!=0)", dimensions
);
1629 /* if we get here, the parameters are OK */
1635 * Test glTexSubImage[123]D() parameters for errors.
1637 * \param ctx GL context.
1638 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1639 * \param target texture target given by the user.
1640 * \param level image level given by the user.
1641 * \param xoffset sub-image x offset given by the user.
1642 * \param yoffset sub-image y offset given by the user.
1643 * \param zoffset sub-image z offset given by the user.
1644 * \param format pixel data format given by the user.
1645 * \param type pixel data type given by the user.
1646 * \param width image width given by the user.
1647 * \param height image height given by the user.
1648 * \param depth image depth given by the user.
1650 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1652 * Verifies each of the parameters against the constants specified in
1653 * __GLcontextRec::Const and the supported extensions, and according to the
1654 * OpenGL specification.
1657 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1658 GLenum target
, GLint level
,
1659 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1660 GLint width
, GLint height
, GLint depth
,
1661 GLenum format
, GLenum type
)
1664 if (dimensions
== 1) {
1665 if (target
!= GL_TEXTURE_1D
) {
1666 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1670 else if (dimensions
== 2) {
1671 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1672 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1673 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1674 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1678 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1679 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1680 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1684 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1685 if (!ctx
->Extensions
.MESA_texture_array
) {
1686 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1690 else if (target
!= GL_TEXTURE_2D
) {
1691 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1695 else if (dimensions
== 3) {
1696 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1697 if (!ctx
->Extensions
.MESA_texture_array
) {
1698 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1702 else if (target
!= GL_TEXTURE_3D
) {
1703 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1708 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1712 /* Basic level check */
1713 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1714 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1719 _mesa_error(ctx
, GL_INVALID_VALUE
,
1720 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1723 if (height
< 0 && dimensions
> 1) {
1724 _mesa_error(ctx
, GL_INVALID_VALUE
,
1725 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1728 if (depth
< 0 && dimensions
> 2) {
1729 _mesa_error(ctx
, GL_INVALID_VALUE
,
1730 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1734 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1735 _mesa_error(ctx
, GL_INVALID_ENUM
,
1736 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1737 dimensions
, format
, type
);
1745 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1746 GLenum target
, GLint level
,
1747 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1748 GLint width
, GLint height
, GLint depth
,
1749 GLenum format
, GLenum type
,
1750 const struct gl_texture_image
*destTex
)
1753 /* undefined image level */
1754 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1758 if (xoffset
< -((GLint
)destTex
->Border
)) {
1759 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1763 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1764 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1768 if (dimensions
> 1) {
1769 if (yoffset
< -((GLint
)destTex
->Border
)) {
1770 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1774 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1775 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1780 if (dimensions
> 2) {
1781 if (zoffset
< -((GLint
)destTex
->Border
)) {
1782 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1785 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1786 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1791 #if FEATURE_EXT_texture_sRGB
1792 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1793 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1794 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1795 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1796 if ((width
& 0x3) || (height
& 0x3) ||
1797 (xoffset
& 0x3) || (yoffset
& 0x3))
1798 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1799 "glTexSubImage%dD(size or offset not multiple of 4)",
1805 if (destTex
->IsCompressed
) {
1806 if (!target_can_be_compressed(ctx
, target
)) {
1807 _mesa_error(ctx
, GL_INVALID_ENUM
,
1808 "glTexSubImage%D(target)", dimensions
);
1811 /* offset must be multiple of 4 */
1812 if ((xoffset
& 3) || (yoffset
& 3)) {
1813 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1814 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1817 /* size must be multiple of 4 or equal to whole texture size */
1818 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1819 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1820 "glTexSubImage%D(width)", dimensions
);
1823 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1824 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1825 "glTexSubImage%D(width)", dimensions
);
1835 * Test glCopyTexImage[12]D() parameters for errors.
1837 * \param ctx GL context.
1838 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1839 * \param target texture target given by the user.
1840 * \param level image level given by the user.
1841 * \param internalFormat internal format given by the user.
1842 * \param width image width given by the user.
1843 * \param height image height given by the user.
1844 * \param border texture border.
1846 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1848 * Verifies each of the parameters against the constants specified in
1849 * __GLcontextRec::Const and the supported extensions, and according to the
1850 * OpenGL specification.
1853 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1854 GLenum target
, GLint level
, GLint internalFormat
,
1855 GLint width
, GLint height
, GLint border
)
1861 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1862 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1863 _mesa_error(ctx
, GL_INVALID_VALUE
,
1864 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1868 /* Check that the source buffer is complete */
1869 if (ctx
->ReadBuffer
->Name
) {
1870 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1871 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1872 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1873 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1879 if (border
< 0 || border
> 1 ||
1880 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1881 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1885 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1887 _mesa_error(ctx
, GL_INVALID_VALUE
,
1888 "glCopyTexImage%dD(internalFormat)", dimensions
);
1892 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1893 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1894 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1898 /* NOTE: the format and type aren't really significant for
1899 * TestProxyTexImage(). Only the internalformat really matters.
1903 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1904 * level, width, height and depth.
1906 if (dimensions
== 1) {
1907 if (target
== GL_TEXTURE_1D
) {
1908 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1909 level
, internalFormat
,
1911 width
, 1, 1, border
);
1914 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1918 else if (dimensions
== 2) {
1919 if (target
== GL_TEXTURE_2D
) {
1920 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1921 level
, internalFormat
,
1923 width
, height
, 1, border
);
1925 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1926 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1927 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1928 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1931 sizeOK
= (width
== height
) &&
1932 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1933 level
, internalFormat
, format
, type
,
1934 width
, height
, 1, border
);
1936 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1937 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1938 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1941 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1942 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1943 level
, internalFormat
,
1945 width
, height
, 1, border
);
1947 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1948 if (!ctx
->Extensions
.MESA_texture_array
) {
1949 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1952 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1953 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1954 level
, internalFormat
,
1956 width
, height
, 1, border
);
1959 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1964 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1969 if (dimensions
== 1) {
1970 _mesa_error(ctx
, GL_INVALID_VALUE
,
1971 "glCopyTexImage1D(width=%d)", width
);
1974 ASSERT(dimensions
== 2);
1975 _mesa_error(ctx
, GL_INVALID_VALUE
,
1976 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1981 if (is_compressed_format(ctx
, internalFormat
)) {
1982 if (!target_can_be_compressed(ctx
, target
)) {
1983 _mesa_error(ctx
, GL_INVALID_ENUM
,
1984 "glCopyTexImage%d(target)", dimensions
);
1988 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1989 "glCopyTexImage%D(border!=0)", dimensions
);
1993 else if (_mesa_is_depth_format(internalFormat
)) {
1994 /* make sure we have depth/stencil buffers */
1995 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1996 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1997 "glCopyTexImage%D(no depth)", dimensions
);
2001 else if (_mesa_is_depthstencil_format(internalFormat
)) {
2002 /* make sure we have depth/stencil buffers */
2003 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2004 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2005 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
2010 /* if we get here, the parameters are OK */
2016 * Test glCopyTexSubImage[12]D() parameters for errors.
2017 * Note that this is the first part of error checking.
2018 * See also copytexsubimage_error_check2() below for the second part.
2020 * \param ctx GL context.
2021 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2022 * \param target texture target given by the user.
2023 * \param level image level given by the user.
2025 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2028 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
2029 GLenum target
, GLint level
)
2031 /* Check that the source buffer is complete */
2032 if (ctx
->ReadBuffer
->Name
) {
2033 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2034 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2035 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2036 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2042 if (dimensions
== 1) {
2043 if (target
!= GL_TEXTURE_1D
) {
2044 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
2048 else if (dimensions
== 2) {
2049 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2050 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2051 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
2052 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2056 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
2057 if (!ctx
->Extensions
.NV_texture_rectangle
) {
2058 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2062 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
2063 if (!ctx
->Extensions
.MESA_texture_array
) {
2064 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2068 else if (target
!= GL_TEXTURE_2D
) {
2069 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2073 else if (dimensions
== 3) {
2074 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2075 (!ctx
->Extensions
.MESA_texture_array
))
2076 && (target
!= GL_TEXTURE_3D
)) {
2077 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2083 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2084 _mesa_error(ctx
, GL_INVALID_VALUE
,
2085 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2094 * Second part of error checking for glCopyTexSubImage[12]D().
2095 * \param xoffset sub-image x offset given by the user.
2096 * \param yoffset sub-image y offset given by the user.
2097 * \param zoffset sub-image z offset given by the user.
2098 * \param width image width given by the user.
2099 * \param height image height given by the user.
2102 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
2103 GLenum target
, GLint level
,
2104 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2105 GLsizei width
, GLsizei height
,
2106 const struct gl_texture_image
*teximage
)
2108 /* check that dest tex image exists */
2110 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2111 "glCopyTexSubImage%dD(undefined texture level: %d)",
2118 _mesa_error(ctx
, GL_INVALID_VALUE
,
2119 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2122 if (dimensions
> 1 && height
< 0) {
2123 _mesa_error(ctx
, GL_INVALID_VALUE
,
2124 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2128 /* check x/y offsets */
2129 if (xoffset
< -((GLint
)teximage
->Border
)) {
2130 _mesa_error(ctx
, GL_INVALID_VALUE
,
2131 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2134 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2135 _mesa_error(ctx
, GL_INVALID_VALUE
,
2136 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2139 if (dimensions
> 1) {
2140 if (yoffset
< -((GLint
)teximage
->Border
)) {
2141 _mesa_error(ctx
, GL_INVALID_VALUE
,
2142 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2145 /* NOTE: we're adding the border here, not subtracting! */
2146 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2147 _mesa_error(ctx
, GL_INVALID_VALUE
,
2148 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2153 /* check z offset */
2154 if (dimensions
> 2) {
2155 if (zoffset
< -((GLint
)teximage
->Border
)) {
2156 _mesa_error(ctx
, GL_INVALID_VALUE
,
2157 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2160 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2161 _mesa_error(ctx
, GL_INVALID_VALUE
,
2162 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2167 if (teximage
->IsCompressed
) {
2168 if (!target_can_be_compressed(ctx
, target
)) {
2169 _mesa_error(ctx
, GL_INVALID_ENUM
,
2170 "glCopyTexSubImage%d(target)", dimensions
);
2173 /* offset must be multiple of 4 */
2174 if ((xoffset
& 3) || (yoffset
& 3)) {
2175 _mesa_error(ctx
, GL_INVALID_VALUE
,
2176 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
2179 /* size must be multiple of 4 */
2180 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2181 _mesa_error(ctx
, GL_INVALID_VALUE
,
2182 "glCopyTexSubImage%D(width)", dimensions
);
2185 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2186 _mesa_error(ctx
, GL_INVALID_VALUE
,
2187 "glCopyTexSubImage%D(height)", dimensions
);
2192 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2193 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2197 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2198 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2199 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2200 dimensions
, teximage
->_BaseFormat
);
2204 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2205 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2206 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2207 "glCopyTexSubImage%D(no depth buffer)",
2212 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2213 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2214 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2215 "glCopyTexSubImage%D(no depth/stencil buffer)",
2221 /* if we get here, the parameters are OK */
2226 /** Callback info for walking over FBO hash table */
2230 struct gl_texture_object
*texObj
;
2236 * Check render to texture callback. Called from _mesa_HashWalk().
2239 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2241 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2242 const struct cb_info
*info
= (struct cb_info
*) userData
;
2243 GLcontext
*ctx
= info
->ctx
;
2244 const struct gl_texture_object
*texObj
= info
->texObj
;
2245 const GLuint level
= info
->level
, face
= info
->face
;
2247 /* If this is a user-created FBO */
2250 /* check if any of the FBO's attachments point to 'texObj' */
2251 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2252 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2253 if (att
->Type
== GL_TEXTURE
&&
2254 att
->Texture
== texObj
&&
2255 att
->TextureLevel
== level
&&
2256 att
->CubeMapFace
== face
) {
2257 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2258 /* Tell driver about the new renderbuffer texture */
2259 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2260 /* Mark fb status as indeterminate to force re-validation */
2269 * When a texture image is specified we have to check if it's bound to
2270 * any framebuffer objects (render to texture) in order to detect changes
2271 * in size or format since that effects FBO completeness.
2272 * Any FBOs rendering into the texture must be re-validated.
2275 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2276 GLuint face
, GLuint level
)
2278 /* Only check this texture if it's been marked as RenderToTexture */
2279 if (texObj
->_RenderToTexture
) {
2280 struct cb_info info
;
2282 info
.texObj
= texObj
;
2285 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2290 /** Debug helper: override the user-requested internal format */
2292 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2295 if (internalFormat
== GL_RGBA16F_ARB
||
2296 internalFormat
== GL_RGBA32F_ARB
) {
2297 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2300 else if (internalFormat
== GL_RGB16F_ARB
||
2301 internalFormat
== GL_RGB32F_ARB
) {
2302 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2305 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2306 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2307 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2308 return GL_LUMINANCE_ALPHA
;
2310 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2311 internalFormat
== GL_LUMINANCE32F_ARB
) {
2312 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2313 return GL_LUMINANCE
;
2315 else if (internalFormat
== GL_ALPHA16F_ARB
||
2316 internalFormat
== GL_ALPHA32F_ARB
) {
2317 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2321 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2322 internalFormat = GL_RGBA;
2326 return internalFormat
;
2329 return internalFormat
;
2335 * Called from the API. Note that width includes the border.
2338 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2339 GLsizei width
, GLint border
, GLenum format
,
2340 GLenum type
, const GLvoid
*pixels
)
2342 GLsizei postConvWidth
= width
;
2343 GET_CURRENT_CONTEXT(ctx
);
2344 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2346 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2348 #if FEATURE_convolve
2349 if (_mesa_is_color_format(internalFormat
)) {
2350 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2354 if (target
== GL_TEXTURE_1D
) {
2355 /* non-proxy target */
2356 struct gl_texture_unit
*texUnit
;
2357 struct gl_texture_object
*texObj
;
2358 struct gl_texture_image
*texImage
;
2359 const GLuint face
= _mesa_tex_target_to_face(target
);
2361 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2362 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2363 return; /* error was recorded */
2366 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2367 _mesa_update_state(ctx
);
2369 texUnit
= get_current_tex_unit(ctx
);
2370 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2371 _mesa_lock_texture(ctx
, texObj
);
2373 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2375 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2379 if (texImage
->Data
) {
2380 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2383 ASSERT(texImage
->Data
== NULL
);
2385 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2386 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2387 postConvWidth
, 1, 1,
2388 border
, internalFormat
);
2390 ASSERT(ctx
->Driver
.TexImage1D
);
2392 /* Give the texture to the driver! <pixels> may be null! */
2393 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2394 width
, border
, format
, type
, pixels
,
2395 &ctx
->Unpack
, texObj
, texImage
);
2397 ASSERT(texImage
->TexFormat
);
2399 update_fbo_texture(ctx
, texObj
, face
, level
);
2402 texObj
->_Complete
= GL_FALSE
;
2403 ctx
->NewState
|= _NEW_TEXTURE
;
2406 _mesa_unlock_texture(ctx
, texObj
);
2408 else if (target
== GL_PROXY_TEXTURE_1D
) {
2409 /* Proxy texture: check for errors and update proxy state */
2410 struct gl_texture_image
*texImage
;
2411 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2412 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2413 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2414 /* when error, clear all proxy texture image parameters */
2416 clear_teximage_fields(texImage
);
2419 /* no error, set the tex image parameters */
2421 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2422 postConvWidth
, 1, 1,
2423 border
, internalFormat
);
2424 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2425 internalFormat
, format
, type
);
2429 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2436 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2437 GLsizei width
, GLsizei height
, GLint border
,
2438 GLenum format
, GLenum type
,
2439 const GLvoid
*pixels
)
2441 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2442 GET_CURRENT_CONTEXT(ctx
);
2443 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2445 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2447 #if FEATURE_convolve
2448 if (_mesa_is_color_format(internalFormat
)) {
2449 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2454 if (target
== GL_TEXTURE_2D
||
2455 (ctx
->Extensions
.ARB_texture_cube_map
&&
2456 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2457 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2458 (ctx
->Extensions
.NV_texture_rectangle
&&
2459 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2460 (ctx
->Extensions
.MESA_texture_array
&&
2461 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2462 /* non-proxy target */
2463 struct gl_texture_unit
*texUnit
;
2464 struct gl_texture_object
*texObj
;
2465 struct gl_texture_image
*texImage
;
2466 const GLuint face
= _mesa_tex_target_to_face(target
);
2468 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2469 format
, type
, 2, postConvWidth
, postConvHeight
,
2471 return; /* error was recorded */
2474 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2475 _mesa_update_state(ctx
);
2477 texUnit
= get_current_tex_unit(ctx
);
2478 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2479 _mesa_lock_texture(ctx
, texObj
);
2481 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2483 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2487 if (texImage
->Data
) {
2488 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2491 ASSERT(texImage
->Data
== NULL
);
2492 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2493 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2494 postConvWidth
, postConvHeight
, 1,
2495 border
, internalFormat
);
2497 ASSERT(ctx
->Driver
.TexImage2D
);
2499 /* Give the texture to the driver! <pixels> may be null! */
2500 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2501 width
, height
, border
, format
, type
, pixels
,
2502 &ctx
->Unpack
, texObj
, texImage
);
2504 ASSERT(texImage
->TexFormat
);
2506 update_fbo_texture(ctx
, texObj
, face
, level
);
2509 texObj
->_Complete
= GL_FALSE
;
2510 ctx
->NewState
|= _NEW_TEXTURE
;
2513 _mesa_unlock_texture(ctx
, texObj
);
2515 else if (target
== GL_PROXY_TEXTURE_2D
||
2516 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2517 ctx
->Extensions
.ARB_texture_cube_map
) ||
2518 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2519 ctx
->Extensions
.NV_texture_rectangle
) ||
2520 (ctx
->Extensions
.MESA_texture_array
&&
2521 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2522 /* Proxy texture: check for errors and update proxy state */
2523 struct gl_texture_image
*texImage
;
2524 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2525 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2526 format
, type
, 2, postConvWidth
, postConvHeight
,
2528 /* when error, clear all proxy texture image parameters */
2530 clear_teximage_fields(texImage
);
2533 /* no error, set the tex image parameters */
2534 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2535 postConvWidth
, postConvHeight
, 1,
2536 border
, internalFormat
);
2537 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2538 internalFormat
, format
, type
);
2542 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2549 * Called by the API or display list executor.
2550 * Note that width and height include the border.
2553 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2554 GLsizei width
, GLsizei height
, GLsizei depth
,
2555 GLint border
, GLenum format
, GLenum type
,
2556 const GLvoid
*pixels
)
2558 GET_CURRENT_CONTEXT(ctx
);
2559 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2561 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2563 if (target
== GL_TEXTURE_3D
||
2564 (ctx
->Extensions
.MESA_texture_array
&&
2565 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2566 /* non-proxy target */
2567 struct gl_texture_unit
*texUnit
;
2568 struct gl_texture_object
*texObj
;
2569 struct gl_texture_image
*texImage
;
2570 const GLuint face
= _mesa_tex_target_to_face(target
);
2572 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2573 format
, type
, 3, width
, height
, depth
, border
)) {
2574 return; /* error was recorded */
2577 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2578 _mesa_update_state(ctx
);
2580 texUnit
= get_current_tex_unit(ctx
);
2581 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2582 _mesa_lock_texture(ctx
, texObj
);
2584 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2586 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2590 if (texImage
->Data
) {
2591 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2594 ASSERT(texImage
->Data
== NULL
);
2595 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2596 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2597 width
, height
, depth
,
2598 border
, internalFormat
);
2600 ASSERT(ctx
->Driver
.TexImage3D
);
2602 /* Give the texture to the driver! <pixels> may be null! */
2603 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2604 width
, height
, depth
, border
, format
, type
,
2605 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2607 ASSERT(texImage
->TexFormat
);
2609 update_fbo_texture(ctx
, texObj
, face
, level
);
2612 texObj
->_Complete
= GL_FALSE
;
2613 ctx
->NewState
|= _NEW_TEXTURE
;
2616 _mesa_unlock_texture(ctx
, texObj
);
2618 else if (target
== GL_PROXY_TEXTURE_3D
||
2619 (ctx
->Extensions
.MESA_texture_array
&&
2620 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2621 /* Proxy texture: check for errors and update proxy state */
2622 struct gl_texture_image
*texImage
;
2623 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2624 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2625 format
, type
, 3, width
, height
, depth
, border
)) {
2626 /* when error, clear all proxy texture image parameters */
2628 clear_teximage_fields(texImage
);
2631 /* no error, set the tex image parameters */
2632 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2633 depth
, border
, internalFormat
);
2634 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2635 internalFormat
, format
, type
);
2639 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2646 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2647 GLsizei width
, GLsizei height
, GLsizei depth
,
2648 GLint border
, GLenum format
, GLenum type
,
2649 const GLvoid
*pixels
)
2651 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2652 depth
, border
, format
, type
, pixels
);
2658 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2659 GLint xoffset
, GLsizei width
,
2660 GLenum format
, GLenum type
,
2661 const GLvoid
*pixels
)
2663 GLsizei postConvWidth
= width
;
2664 struct gl_texture_unit
*texUnit
;
2665 struct gl_texture_object
*texObj
;
2666 struct gl_texture_image
*texImage
= NULL
;
2667 GET_CURRENT_CONTEXT(ctx
);
2668 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2670 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2671 _mesa_update_state(ctx
);
2673 #if FEATURE_convolve
2674 /* XXX should test internal format */
2675 if (_mesa_is_color_format(format
)) {
2676 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2680 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2681 postConvWidth
, 1, 1, format
, type
)) {
2682 return; /* error was detected */
2686 texUnit
= get_current_tex_unit(ctx
);
2687 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2690 _mesa_lock_texture(ctx
, texObj
);
2692 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2694 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2695 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2696 goto out
; /* error was detected */
2700 goto out
; /* no-op, not an error */
2702 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2703 xoffset
+= texImage
->Border
;
2705 ASSERT(ctx
->Driver
.TexSubImage1D
);
2706 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2707 format
, type
, pixels
, &ctx
->Unpack
,
2709 ctx
->NewState
|= _NEW_TEXTURE
;
2712 _mesa_unlock_texture(ctx
, texObj
);
2717 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2718 GLint xoffset
, GLint yoffset
,
2719 GLsizei width
, GLsizei height
,
2720 GLenum format
, GLenum type
,
2721 const GLvoid
*pixels
)
2723 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2724 struct gl_texture_unit
*texUnit
;
2725 struct gl_texture_object
*texObj
;
2726 struct gl_texture_image
*texImage
;
2727 GET_CURRENT_CONTEXT(ctx
);
2728 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2730 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2731 _mesa_update_state(ctx
);
2733 #if FEATURE_convolve
2734 /* XXX should test internal format */
2735 if (_mesa_is_color_format(format
)) {
2736 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2741 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2742 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2743 return; /* error was detected */
2746 texUnit
= get_current_tex_unit(ctx
);
2747 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2748 _mesa_lock_texture(ctx
, texObj
);
2750 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2752 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2753 postConvWidth
, postConvHeight
, 1, format
, type
,
2755 goto out
; /* error was detected */
2758 if (width
== 0 || height
== 0)
2759 goto out
; /* no-op, not an error */
2761 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2762 xoffset
+= texImage
->Border
;
2763 yoffset
+= texImage
->Border
;
2765 ASSERT(ctx
->Driver
.TexSubImage2D
);
2766 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2767 width
, height
, format
, type
, pixels
,
2768 &ctx
->Unpack
, texObj
, texImage
);
2769 ctx
->NewState
|= _NEW_TEXTURE
;
2772 _mesa_unlock_texture(ctx
, texObj
);
2778 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2779 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2780 GLsizei width
, GLsizei height
, GLsizei depth
,
2781 GLenum format
, GLenum type
,
2782 const GLvoid
*pixels
)
2784 struct gl_texture_unit
*texUnit
;
2785 struct gl_texture_object
*texObj
;
2786 struct gl_texture_image
*texImage
;
2787 GET_CURRENT_CONTEXT(ctx
);
2788 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2790 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2791 _mesa_update_state(ctx
);
2793 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2794 width
, height
, depth
, format
, type
)) {
2795 return; /* error was detected */
2798 texUnit
= get_current_tex_unit(ctx
);
2799 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2801 _mesa_lock_texture(ctx
, texObj
);
2803 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2805 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2806 width
, height
, depth
, format
, type
, texImage
)) {
2807 goto out
; /* error was detected */
2810 if (width
== 0 || height
== 0 || height
== 0)
2811 goto out
; /* no-op, not an error */
2813 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2814 xoffset
+= texImage
->Border
;
2815 yoffset
+= texImage
->Border
;
2816 zoffset
+= texImage
->Border
;
2818 ASSERT(ctx
->Driver
.TexSubImage3D
);
2819 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2820 xoffset
, yoffset
, zoffset
,
2821 width
, height
, depth
,
2822 format
, type
, pixels
,
2823 &ctx
->Unpack
, texObj
, texImage
);
2824 ctx
->NewState
|= _NEW_TEXTURE
;
2827 _mesa_unlock_texture(ctx
, texObj
);
2833 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2834 GLenum internalFormat
,
2836 GLsizei width
, GLint border
)
2838 struct gl_texture_unit
*texUnit
;
2839 struct gl_texture_object
*texObj
;
2840 struct gl_texture_image
*texImage
;
2841 GLsizei postConvWidth
= width
;
2842 const GLuint face
= _mesa_tex_target_to_face(target
);
2843 GET_CURRENT_CONTEXT(ctx
);
2844 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2846 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2847 _mesa_update_state(ctx
);
2849 #if FEATURE_convolve
2850 if (_mesa_is_color_format(internalFormat
)) {
2851 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2855 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2856 postConvWidth
, 1, border
))
2859 texUnit
= get_current_tex_unit(ctx
);
2860 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2861 _mesa_lock_texture(ctx
, texObj
);
2863 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2865 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2869 if (texImage
->Data
) {
2870 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2873 ASSERT(texImage
->Data
== NULL
);
2875 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2876 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2877 border
, internalFormat
);
2880 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2881 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2882 x
, y
, width
, border
);
2884 ASSERT(texImage
->TexFormat
);
2886 update_fbo_texture(ctx
, texObj
, face
, level
);
2889 texObj
->_Complete
= GL_FALSE
;
2890 ctx
->NewState
|= _NEW_TEXTURE
;
2893 _mesa_unlock_texture(ctx
, texObj
);
2899 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2900 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2903 struct gl_texture_unit
*texUnit
;
2904 struct gl_texture_object
*texObj
;
2905 struct gl_texture_image
*texImage
;
2906 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2907 const GLuint face
= _mesa_tex_target_to_face(target
);
2908 GET_CURRENT_CONTEXT(ctx
);
2909 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2911 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2912 _mesa_update_state(ctx
);
2914 #if FEATURE_convolve
2915 if (_mesa_is_color_format(internalFormat
)) {
2916 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2921 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2922 postConvWidth
, postConvHeight
, border
))
2925 texUnit
= get_current_tex_unit(ctx
);
2926 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2928 _mesa_lock_texture(ctx
, texObj
);
2930 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2933 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2937 if (texImage
->Data
) {
2938 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2941 ASSERT(texImage
->Data
== NULL
);
2943 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2944 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2945 postConvWidth
, postConvHeight
, 1,
2946 border
, internalFormat
);
2948 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2949 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
2950 x
, y
, width
, height
, border
);
2952 ASSERT(texImage
->TexFormat
);
2954 update_fbo_texture(ctx
, texObj
, face
, level
);
2957 texObj
->_Complete
= GL_FALSE
;
2958 ctx
->NewState
|= _NEW_TEXTURE
;
2961 _mesa_unlock_texture(ctx
, texObj
);
2966 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2967 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2969 struct gl_texture_unit
*texUnit
;
2970 struct gl_texture_object
*texObj
;
2971 struct gl_texture_image
*texImage
;
2972 GLsizei postConvWidth
= width
;
2976 GET_CURRENT_CONTEXT(ctx
);
2977 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2979 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2980 _mesa_update_state(ctx
);
2982 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2985 texUnit
= get_current_tex_unit(ctx
);
2986 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2988 _mesa_lock_texture(ctx
, texObj
);
2990 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2992 #if FEATURE_convolve
2993 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2994 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2998 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2999 xoffset
, 0, 0, postConvWidth
, 1,
3004 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3005 xoffset
+= texImage
->Border
;
3007 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3009 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3010 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3011 xoffset
, x
, y
, width
);
3014 ctx
->NewState
|= _NEW_TEXTURE
;
3017 _mesa_unlock_texture(ctx
, texObj
);
3023 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3024 GLint xoffset
, GLint yoffset
,
3025 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3027 struct gl_texture_unit
*texUnit
;
3028 struct gl_texture_object
*texObj
;
3029 struct gl_texture_image
*texImage
;
3030 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3031 GET_CURRENT_CONTEXT(ctx
);
3032 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3034 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3035 _mesa_update_state(ctx
);
3037 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3040 texUnit
= get_current_tex_unit(ctx
);
3041 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3043 _mesa_lock_texture(ctx
, texObj
);
3045 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3047 #if FEATURE_convolve
3048 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3049 _mesa_adjust_image_for_convolution(ctx
, 2,
3050 &postConvWidth
, &postConvHeight
);
3054 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
3055 postConvWidth
, postConvHeight
, texImage
))
3058 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3059 xoffset
+= texImage
->Border
;
3060 yoffset
+= texImage
->Border
;
3062 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3064 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3065 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
3066 xoffset
, yoffset
, x
, y
, width
, height
);
3069 ctx
->NewState
|= _NEW_TEXTURE
;
3072 _mesa_unlock_texture(ctx
, texObj
);
3078 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3079 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3080 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3082 struct gl_texture_unit
*texUnit
;
3083 struct gl_texture_object
*texObj
;
3084 struct gl_texture_image
*texImage
;
3085 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3086 GET_CURRENT_CONTEXT(ctx
);
3087 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3089 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3090 _mesa_update_state(ctx
);
3092 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3095 texUnit
= get_current_tex_unit(ctx
);
3096 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3098 _mesa_lock_texture(ctx
, texObj
);
3100 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3102 #if FEATURE_convolve
3103 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3104 _mesa_adjust_image_for_convolution(ctx
, 2,
3105 &postConvWidth
, &postConvHeight
);
3109 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3110 zoffset
, postConvWidth
, postConvHeight
,
3114 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3115 xoffset
+= texImage
->Border
;
3116 yoffset
+= texImage
->Border
;
3117 zoffset
+= texImage
->Border
;
3119 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3121 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3122 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3123 xoffset
, yoffset
, zoffset
,
3124 x
, y
, width
, height
);
3127 ctx
->NewState
|= _NEW_TEXTURE
;
3130 _mesa_unlock_texture(ctx
, texObj
);
3136 /**********************************************************************/
3137 /****** Compressed Textures ******/
3138 /**********************************************************************/
3142 * Error checking for glCompressedTexImage[123]D().
3143 * \return error code or GL_NO_ERROR.
3146 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3147 GLenum target
, GLint level
,
3148 GLenum internalFormat
, GLsizei width
,
3149 GLsizei height
, GLsizei depth
, GLint border
,
3152 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3154 if (dimensions
== 1) {
3155 /* 1D compressed textures not allowed */
3156 return GL_INVALID_ENUM
;
3158 else if (dimensions
== 2) {
3159 if (target
== GL_PROXY_TEXTURE_2D
) {
3160 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3162 else if (target
== GL_TEXTURE_2D
) {
3163 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3165 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3166 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3167 return GL_INVALID_ENUM
; /*target*/
3168 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3170 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3171 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3172 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3173 return GL_INVALID_ENUM
; /*target*/
3174 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3177 return GL_INVALID_ENUM
; /*target*/
3180 else if (dimensions
== 3) {
3181 /* 3D compressed textures not allowed */
3182 return GL_INVALID_ENUM
;
3185 maxTextureSize
= 1 << (maxLevels
- 1);
3187 /* This will detect any invalid internalFormat value */
3188 if (!is_compressed_format(ctx
, internalFormat
))
3189 return GL_INVALID_ENUM
;
3191 /* This should really never fail */
3192 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3193 return GL_INVALID_ENUM
;
3196 return GL_INVALID_VALUE
;
3199 * XXX We should probably use the proxy texture error check function here.
3201 if (width
< 1 || width
> maxTextureSize
||
3202 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3203 return GL_INVALID_VALUE
;
3205 if ((height
< 1 || height
> maxTextureSize
||
3206 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3208 return GL_INVALID_VALUE
;
3210 if ((depth
< 1 || depth
> maxTextureSize
||
3211 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3213 return GL_INVALID_VALUE
;
3215 /* For cube map, width must equal height */
3216 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3217 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3218 return GL_INVALID_VALUE
;
3220 if (level
< 0 || level
>= maxLevels
)
3221 return GL_INVALID_VALUE
;
3223 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3224 depth
, internalFormat
);
3225 if (expectedSize
!= imageSize
)
3226 return GL_INVALID_VALUE
;
3228 #if FEATURE_EXT_texture_sRGB
3229 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3230 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3231 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3232 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3234 return GL_INVALID_OPERATION
;
3243 * Error checking for glCompressedTexSubImage[123]D().
3244 * \warning There are some bad assumptions here about the size of compressed
3245 * texture tiles (multiple of 4) used to test the validity of the
3246 * offset and size parameters.
3247 * \return error code or GL_NO_ERROR.
3250 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3251 GLenum target
, GLint level
,
3252 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3253 GLsizei width
, GLsizei height
, GLsizei depth
,
3254 GLenum format
, GLsizei imageSize
)
3256 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3259 if (dimensions
== 1) {
3260 /* 1D compressed textures not allowed */
3261 return GL_INVALID_ENUM
;
3263 else if (dimensions
== 2) {
3264 if (target
== GL_PROXY_TEXTURE_2D
) {
3265 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3267 else if (target
== GL_TEXTURE_2D
) {
3268 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3270 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3271 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3272 return GL_INVALID_ENUM
; /*target*/
3273 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3275 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3276 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3277 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3278 return GL_INVALID_ENUM
; /*target*/
3279 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3282 return GL_INVALID_ENUM
; /*target*/
3285 else if (dimensions
== 3) {
3286 /* 3D compressed textures not allowed */
3287 return GL_INVALID_ENUM
;
3290 maxTextureSize
= 1 << (maxLevels
- 1);
3292 /* this will catch any invalid compressed format token */
3293 if (!is_compressed_format(ctx
, format
))
3294 return GL_INVALID_ENUM
;
3296 if (width
< 1 || width
> maxTextureSize
)
3297 return GL_INVALID_VALUE
;
3299 if ((height
< 1 || height
> maxTextureSize
)
3301 return GL_INVALID_VALUE
;
3303 if (level
< 0 || level
>= maxLevels
)
3304 return GL_INVALID_VALUE
;
3306 /* XXX these tests are specific to the compressed format.
3307 * this code should be generalized in some way.
3309 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3310 return GL_INVALID_VALUE
;
3312 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3313 return GL_INVALID_VALUE
;
3315 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3316 return GL_INVALID_VALUE
;
3318 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3320 if (expectedSize
!= imageSize
)
3321 return GL_INVALID_VALUE
;
3329 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3330 GLenum internalFormat
, GLsizei width
,
3331 GLint border
, GLsizei imageSize
,
3334 GET_CURRENT_CONTEXT(ctx
);
3335 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3337 if (target
== GL_TEXTURE_1D
) {
3338 /* non-proxy target */
3339 struct gl_texture_unit
*texUnit
;
3340 struct gl_texture_object
*texObj
;
3341 struct gl_texture_image
*texImage
;
3342 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3343 internalFormat
, width
, 1, 1, border
, imageSize
);
3345 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3349 texUnit
= get_current_tex_unit(ctx
);
3350 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3352 _mesa_lock_texture(ctx
, texObj
);
3354 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3356 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3360 if (texImage
->Data
) {
3361 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3363 ASSERT(texImage
->Data
== NULL
);
3365 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3366 border
, internalFormat
);
3368 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3369 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3370 internalFormat
, width
, border
,
3375 texObj
->_Complete
= GL_FALSE
;
3376 ctx
->NewState
|= _NEW_TEXTURE
;
3379 _mesa_unlock_texture(ctx
, texObj
);
3381 else if (target
== GL_PROXY_TEXTURE_1D
) {
3382 /* Proxy texture: check for errors and update proxy state */
3383 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3384 internalFormat
, width
, 1, 1, border
, imageSize
);
3386 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3387 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3388 internalFormat
, GL_NONE
, GL_NONE
,
3389 width
, 1, 1, border
);
3392 /* if error, clear all proxy texture image parameters */
3393 struct gl_texture_image
*texImage
;
3394 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3396 clear_teximage_fields(texImage
);
3399 /* store the teximage parameters */
3400 struct gl_texture_unit
*texUnit
;
3401 struct gl_texture_object
*texObj
;
3402 struct gl_texture_image
*texImage
;
3403 texUnit
= get_current_tex_unit(ctx
);
3404 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3406 _mesa_lock_texture(ctx
, texObj
);
3408 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3409 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3410 border
, internalFormat
);
3412 _mesa_unlock_texture(ctx
, texObj
);
3416 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3423 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3424 GLenum internalFormat
, GLsizei width
,
3425 GLsizei height
, GLint border
, GLsizei imageSize
,
3428 GET_CURRENT_CONTEXT(ctx
);
3429 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3431 if (target
== GL_TEXTURE_2D
||
3432 (ctx
->Extensions
.ARB_texture_cube_map
&&
3433 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3434 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3435 /* non-proxy target */
3436 struct gl_texture_unit
*texUnit
;
3437 struct gl_texture_object
*texObj
;
3438 struct gl_texture_image
*texImage
;
3439 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3440 internalFormat
, width
, height
, 1, border
, imageSize
);
3442 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3446 texUnit
= get_current_tex_unit(ctx
);
3447 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3449 _mesa_lock_texture(ctx
, texObj
);
3451 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3453 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3457 if (texImage
->Data
) {
3458 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3460 ASSERT(texImage
->Data
== NULL
);
3462 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3463 border
, internalFormat
);
3465 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3466 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3467 internalFormat
, width
, height
,
3468 border
, imageSize
, data
,
3472 texObj
->_Complete
= GL_FALSE
;
3473 ctx
->NewState
|= _NEW_TEXTURE
;
3476 _mesa_unlock_texture(ctx
, texObj
);
3478 else if (target
== GL_PROXY_TEXTURE_2D
||
3479 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3480 ctx
->Extensions
.ARB_texture_cube_map
)) {
3481 /* Proxy texture: check for errors and update proxy state */
3482 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3483 internalFormat
, width
, height
, 1, border
, imageSize
);
3485 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3486 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3487 internalFormat
, GL_NONE
, GL_NONE
,
3488 width
, height
, 1, border
);
3491 /* if error, clear all proxy texture image parameters */
3492 struct gl_texture_image
*texImage
;
3493 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3495 clear_teximage_fields(texImage
);
3498 /* store the teximage parameters */
3499 struct gl_texture_unit
*texUnit
;
3500 struct gl_texture_object
*texObj
;
3501 struct gl_texture_image
*texImage
;
3502 texUnit
= get_current_tex_unit(ctx
);
3503 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3505 _mesa_lock_texture(ctx
, texObj
);
3507 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3508 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3509 border
, internalFormat
);
3511 _mesa_unlock_texture(ctx
, texObj
);
3515 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3522 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3523 GLenum internalFormat
, GLsizei width
,
3524 GLsizei height
, GLsizei depth
, GLint border
,
3525 GLsizei imageSize
, const GLvoid
*data
)
3527 GET_CURRENT_CONTEXT(ctx
);
3528 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3530 if (target
== GL_TEXTURE_3D
) {
3531 /* non-proxy target */
3532 struct gl_texture_unit
*texUnit
;
3533 struct gl_texture_object
*texObj
;
3534 struct gl_texture_image
*texImage
;
3535 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3536 internalFormat
, width
, height
, depth
, border
, imageSize
);
3538 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3542 texUnit
= get_current_tex_unit(ctx
);
3543 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3544 _mesa_lock_texture(ctx
, texObj
);
3546 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3548 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3552 if (texImage
->Data
) {
3553 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3555 ASSERT(texImage
->Data
== NULL
);
3557 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3558 border
, internalFormat
);
3560 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3561 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3563 width
, height
, depth
,
3564 border
, imageSize
, data
,
3568 texObj
->_Complete
= GL_FALSE
;
3569 ctx
->NewState
|= _NEW_TEXTURE
;
3572 _mesa_unlock_texture(ctx
, texObj
);
3574 else if (target
== GL_PROXY_TEXTURE_3D
) {
3575 /* Proxy texture: check for errors and update proxy state */
3576 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3577 internalFormat
, width
, height
, depth
, border
, imageSize
);
3579 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3580 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3581 internalFormat
, GL_NONE
, GL_NONE
,
3582 width
, height
, depth
, border
);
3585 /* if error, clear all proxy texture image parameters */
3586 struct gl_texture_image
*texImage
;
3587 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3589 clear_teximage_fields(texImage
);
3592 /* store the teximage parameters */
3593 struct gl_texture_unit
*texUnit
;
3594 struct gl_texture_object
*texObj
;
3595 struct gl_texture_image
*texImage
;
3596 texUnit
= get_current_tex_unit(ctx
);
3597 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3598 _mesa_lock_texture(ctx
, texObj
);
3600 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3601 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3602 depth
, border
, internalFormat
);
3604 _mesa_unlock_texture(ctx
, texObj
);
3608 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3615 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3616 GLsizei width
, GLenum format
,
3617 GLsizei imageSize
, const GLvoid
*data
)
3619 struct gl_texture_unit
*texUnit
;
3620 struct gl_texture_object
*texObj
;
3621 struct gl_texture_image
*texImage
;
3623 GET_CURRENT_CONTEXT(ctx
);
3624 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3626 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3627 xoffset
, 0, 0, /* pos */
3628 width
, 1, 1, /* size */
3631 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3635 texUnit
= get_current_tex_unit(ctx
);
3636 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3637 _mesa_lock_texture(ctx
, texObj
);
3639 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3642 if ((GLint
) format
!= texImage
->InternalFormat
) {
3643 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3644 "glCompressedTexSubImage1D(format)");
3648 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3649 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3654 goto out
; /* no-op, not an error */
3656 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3657 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3659 format
, imageSize
, data
,
3662 ctx
->NewState
|= _NEW_TEXTURE
;
3665 _mesa_unlock_texture(ctx
, texObj
);
3670 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3671 GLint yoffset
, GLsizei width
, GLsizei height
,
3672 GLenum format
, GLsizei imageSize
,
3675 struct gl_texture_unit
*texUnit
;
3676 struct gl_texture_object
*texObj
;
3677 struct gl_texture_image
*texImage
;
3679 GET_CURRENT_CONTEXT(ctx
);
3680 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3682 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3683 xoffset
, yoffset
, 0, /* pos */
3684 width
, height
, 1, /* size */
3687 /* XXX proxy target? */
3688 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3692 texUnit
= get_current_tex_unit(ctx
);
3693 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3694 _mesa_lock_texture(ctx
, texObj
);
3696 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3699 if ((GLint
) format
!= texImage
->InternalFormat
) {
3700 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3701 "glCompressedTexSubImage2D(format)");
3705 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3706 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3707 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3711 if (width
== 0 || height
== 0)
3712 goto out
; /* no-op, not an error */
3714 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3715 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3716 xoffset
, yoffset
, width
, height
,
3717 format
, imageSize
, data
,
3720 ctx
->NewState
|= _NEW_TEXTURE
;
3723 _mesa_unlock_texture(ctx
, texObj
);
3728 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3729 GLint yoffset
, GLint zoffset
, GLsizei width
,
3730 GLsizei height
, GLsizei depth
, GLenum format
,
3731 GLsizei imageSize
, const GLvoid
*data
)
3733 struct gl_texture_unit
*texUnit
;
3734 struct gl_texture_object
*texObj
;
3735 struct gl_texture_image
*texImage
;
3737 GET_CURRENT_CONTEXT(ctx
);
3738 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3740 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3741 xoffset
, yoffset
, zoffset
,/*pos*/
3742 width
, height
, depth
, /*size*/
3745 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3749 texUnit
= get_current_tex_unit(ctx
);
3750 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3751 _mesa_lock_texture(ctx
, texObj
);
3753 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3756 if ((GLint
) format
!= texImage
->InternalFormat
) {
3757 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3758 "glCompressedTexSubImage3D(format)");
3762 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3763 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3764 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3765 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3769 if (width
== 0 || height
== 0 || depth
== 0)
3770 goto out
; /* no-op, not an error */
3772 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3773 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3774 xoffset
, yoffset
, zoffset
,
3775 width
, height
, depth
,
3776 format
, imageSize
, data
,
3779 ctx
->NewState
|= _NEW_TEXTURE
;
3782 _mesa_unlock_texture(ctx
, texObj
);