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.
186 * XXX this could be static
189 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
191 switch (internalFormat
) {
206 case GL_LUMINANCE_ALPHA
:
207 case GL_LUMINANCE4_ALPHA4
:
208 case GL_LUMINANCE6_ALPHA2
:
209 case GL_LUMINANCE8_ALPHA8
:
210 case GL_LUMINANCE12_ALPHA4
:
211 case GL_LUMINANCE12_ALPHA12
:
212 case GL_LUMINANCE16_ALPHA16
:
213 return GL_LUMINANCE_ALPHA
;
244 if (ctx
->Extensions
.EXT_paletted_texture
) {
245 switch (internalFormat
) {
247 case GL_COLOR_INDEX1_EXT
:
248 case GL_COLOR_INDEX2_EXT
:
249 case GL_COLOR_INDEX4_EXT
:
250 case GL_COLOR_INDEX8_EXT
:
251 case GL_COLOR_INDEX12_EXT
:
252 case GL_COLOR_INDEX16_EXT
:
253 return GL_COLOR_INDEX
;
259 if (ctx
->Extensions
.ARB_depth_texture
) {
260 switch (internalFormat
) {
261 case GL_DEPTH_COMPONENT
:
262 case GL_DEPTH_COMPONENT16
:
263 case GL_DEPTH_COMPONENT24
:
264 case GL_DEPTH_COMPONENT32
:
265 return GL_DEPTH_COMPONENT
;
271 switch (internalFormat
) {
272 case GL_COMPRESSED_ALPHA
:
274 case GL_COMPRESSED_LUMINANCE
:
276 case GL_COMPRESSED_LUMINANCE_ALPHA
:
277 return GL_LUMINANCE_ALPHA
;
278 case GL_COMPRESSED_INTENSITY
:
280 case GL_COMPRESSED_RGB
:
282 case GL_COMPRESSED_RGBA
:
288 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
289 switch (internalFormat
) {
290 case GL_COMPRESSED_RGB_FXT1_3DFX
:
292 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
299 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
300 switch (internalFormat
) {
301 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
303 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
304 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
305 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
312 if (ctx
->Extensions
.S3_s3tc
) {
313 switch (internalFormat
) {
325 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
326 if (internalFormat
== GL_YCBCR_MESA
)
327 return GL_YCBCR_MESA
;
330 if (ctx
->Extensions
.ARB_texture_float
) {
331 switch (internalFormat
) {
332 case GL_ALPHA16F_ARB
:
333 case GL_ALPHA32F_ARB
:
341 case GL_INTENSITY16F_ARB
:
342 case GL_INTENSITY32F_ARB
:
344 case GL_LUMINANCE16F_ARB
:
345 case GL_LUMINANCE32F_ARB
:
347 case GL_LUMINANCE_ALPHA16F_ARB
:
348 case GL_LUMINANCE_ALPHA32F_ARB
:
349 return GL_LUMINANCE_ALPHA
;
355 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
356 switch (internalFormat
) {
365 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
366 switch (internalFormat
) {
375 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
376 switch (internalFormat
) {
377 case GL_DEPTH_STENCIL_EXT
:
378 case GL_DEPTH24_STENCIL8_EXT
:
379 return GL_DEPTH_STENCIL_EXT
;
385 #if FEATURE_EXT_texture_sRGB
386 if (ctx
->Extensions
.EXT_texture_sRGB
) {
387 switch (internalFormat
) {
390 case GL_COMPRESSED_SRGB_EXT
:
391 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
393 case GL_SRGB_ALPHA_EXT
:
394 case GL_SRGB8_ALPHA8_EXT
:
395 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
396 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
397 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
398 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
400 case GL_SLUMINANCE_ALPHA_EXT
:
401 case GL_SLUMINANCE8_ALPHA8_EXT
:
402 case GL_COMPRESSED_SLUMINANCE_EXT
:
403 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
404 return GL_LUMINANCE_ALPHA
;
405 case GL_SLUMINANCE_EXT
:
406 case GL_SLUMINANCE8_EXT
:
413 #endif /* FEATURE_EXT_texture_sRGB */
415 return -1; /* error */
420 * Test if it is a supported compressed format.
422 * \param internalFormat the internal format token provided by the user.
424 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
425 * GL_FALSE otherwise.
427 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
431 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
433 GLint supported
[100]; /* 100 should be plenty */
436 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
438 for (i
= 0; i
< n
; i
++) {
439 if ((GLint
) internalFormat
== supported
[i
]) {
448 * For cube map faces, return a face index in [0,5].
449 * For other targets return 0;
452 _mesa_tex_target_to_face(GLenum target
)
454 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
455 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
456 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
464 * Store a gl_texture_image pointer in a gl_texture_object structure
465 * according to the target and level parameters.
467 * \param tObj texture object.
468 * \param target texture target.
469 * \param level image level.
470 * \param texImage texture image.
472 * This was basically prompted by the introduction of cube maps.
475 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
476 GLenum target
, GLint level
,
477 struct gl_texture_image
*texImage
)
479 const GLuint face
= _mesa_tex_target_to_face(target
);
483 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
485 tObj
->Image
[face
][level
] = texImage
;
487 /* Set the 'back' pointer */
488 texImage
->TexObject
= tObj
;
493 * Allocate a texture image structure.
495 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
498 * \return a pointer to gl_texture_image struct with all fields initialized to
501 struct gl_texture_image
*
502 _mesa_new_texture_image( GLcontext
*ctx
)
505 return CALLOC_STRUCT(gl_texture_image
);
510 * Free texture image data.
511 * This function is a fallback called via ctx->Driver.FreeTexImageData().
513 * \param texImage texture image.
515 * Free the texture image data if it's not marked as client data.
518 _mesa_free_texture_image_data(GLcontext
*ctx
,
519 struct gl_texture_image
*texImage
)
523 if (texImage
->Data
&& !texImage
->IsClientData
) {
524 /* free the old texture data */
525 _mesa_free_texmemory(texImage
->Data
);
528 texImage
->Data
= NULL
;
533 * Free texture image.
535 * \param texImage texture image.
537 * Free the texture image structure and the associated image data.
540 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
542 /* Free texImage->Data and/or any other driver-specific texture
545 ASSERT(ctx
->Driver
.FreeTexImageData
);
546 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
548 ASSERT(texImage
->Data
== NULL
);
549 if (texImage
->ImageOffsets
)
550 _mesa_free(texImage
->ImageOffsets
);
551 _mesa_free(texImage
);
556 * Test if a target is a proxy target.
558 * \param target texture target.
560 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
563 _mesa_is_proxy_texture(GLenum target
)
565 /* NUM_TEXTURE_TARGETS should match number of terms below */
566 assert(NUM_TEXTURE_TARGETS
== 7);
568 return (target
== GL_PROXY_TEXTURE_1D
||
569 target
== GL_PROXY_TEXTURE_2D
||
570 target
== GL_PROXY_TEXTURE_3D
||
571 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
572 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
573 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
574 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
579 * Get the texture object that corresponds to the target of the given texture unit.
581 * \param ctx GL context.
582 * \param texUnit texture unit.
583 * \param target texture target.
585 * \return pointer to the texture object on success, or NULL on failure.
587 * \sa gl_texture_unit.
589 struct gl_texture_object
*
590 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
595 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
596 case GL_PROXY_TEXTURE_1D
:
597 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
599 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
600 case GL_PROXY_TEXTURE_2D
:
601 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
603 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
604 case GL_PROXY_TEXTURE_3D
:
605 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
606 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
607 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
608 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
609 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
610 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
611 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
612 case GL_TEXTURE_CUBE_MAP_ARB
:
613 return ctx
->Extensions
.ARB_texture_cube_map
614 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
615 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
616 return ctx
->Extensions
.ARB_texture_cube_map
617 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
618 case GL_TEXTURE_RECTANGLE_NV
:
619 return ctx
->Extensions
.NV_texture_rectangle
620 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
621 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
622 return ctx
->Extensions
.NV_texture_rectangle
623 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
624 case GL_TEXTURE_1D_ARRAY_EXT
:
625 return ctx
->Extensions
.MESA_texture_array
626 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
627 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
628 return ctx
->Extensions
.MESA_texture_array
629 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
630 case GL_TEXTURE_2D_ARRAY_EXT
:
631 return ctx
->Extensions
.MESA_texture_array
632 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
633 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
634 return ctx
->Extensions
.MESA_texture_array
635 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
637 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
644 * Get a texture image pointer from a texture object, given a texture
645 * target and mipmap level. The target and level parameters should
646 * have already been error-checked.
648 * \param ctx GL context.
649 * \param texObj texture unit.
650 * \param target texture target.
651 * \param level image level.
653 * \return pointer to the texture image structure, or NULL on failure.
655 struct gl_texture_image
*
656 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
657 GLenum target
, GLint level
)
659 const GLuint face
= _mesa_tex_target_to_face(target
);
663 ASSERT(level
< MAX_TEXTURE_LEVELS
);
665 return texObj
->Image
[face
][level
];
670 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
671 * it and install it. Only return NULL if passed a bad parameter or run
674 struct gl_texture_image
*
675 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
676 GLenum target
, GLint level
)
678 struct gl_texture_image
*texImage
;
683 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
685 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
687 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
691 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
699 * Return pointer to the specified proxy texture image.
700 * Note that proxy textures are per-context, not per-texture unit.
701 * \return pointer to texture image or NULL if invalid target, invalid
702 * level, or out of memory.
704 struct gl_texture_image
*
705 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
707 struct gl_texture_image
*texImage
;
714 case GL_PROXY_TEXTURE_1D
:
715 if (level
>= ctx
->Const
.MaxTextureLevels
)
717 texIndex
= TEXTURE_1D_INDEX
;
719 case GL_PROXY_TEXTURE_2D
:
720 if (level
>= ctx
->Const
.MaxTextureLevels
)
722 texIndex
= TEXTURE_2D_INDEX
;
724 case GL_PROXY_TEXTURE_3D
:
725 if (level
>= ctx
->Const
.Max3DTextureLevels
)
727 texIndex
= TEXTURE_3D_INDEX
;
729 case GL_PROXY_TEXTURE_CUBE_MAP
:
730 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
732 texIndex
= TEXTURE_CUBE_INDEX
;
734 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
737 texIndex
= TEXTURE_RECT_INDEX
;
739 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
740 if (level
>= ctx
->Const
.MaxTextureLevels
)
742 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
744 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
745 if (level
>= ctx
->Const
.MaxTextureLevels
)
747 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
753 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
755 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
757 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
760 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
761 /* Set the 'back' pointer */
762 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
769 * Get the maximum number of allowed mipmap levels.
771 * \param ctx GL context.
772 * \param target texture target.
774 * \return the maximum number of allowed mipmap levels for the given
775 * texture target, or zero if passed a bad target.
780 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
784 case GL_PROXY_TEXTURE_1D
:
786 case GL_PROXY_TEXTURE_2D
:
787 return ctx
->Const
.MaxTextureLevels
;
789 case GL_PROXY_TEXTURE_3D
:
790 return ctx
->Const
.Max3DTextureLevels
;
791 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
792 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
793 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
794 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
795 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
796 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
797 case GL_TEXTURE_CUBE_MAP_ARB
:
798 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
799 return ctx
->Extensions
.ARB_texture_cube_map
800 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
801 case GL_TEXTURE_RECTANGLE_NV
:
802 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
803 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
804 case GL_TEXTURE_1D_ARRAY_EXT
:
805 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
806 case GL_TEXTURE_2D_ARRAY_EXT
:
807 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
808 return ctx
->Extensions
.MESA_texture_array
809 ? ctx
->Const
.MaxTextureLevels
: 0;
811 return 0; /* bad target */
817 #if 000 /* not used anymore */
819 * glTexImage[123]D can accept a NULL image pointer. In this case we
820 * create a texture image with unspecified image contents per the OpenGL
824 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
826 const GLint components
= _mesa_components_in_format(format
);
827 const GLint numPixels
= width
* height
* depth
;
828 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
832 * Let's see if anyone finds this. If glTexImage2D() is called with
833 * a NULL image pointer then load the texture image with something
834 * interesting instead of leaving it indeterminate.
837 static const char message
[8][32] = {
841 " X X XXXX XXX XXXXX ",
844 " X X XXXXX XXX X X ",
848 GLubyte
*imgPtr
= data
;
850 for (h
= 0; h
< depth
; h
++) {
851 for (i
= 0; i
< height
; i
++) {
852 GLint srcRow
= 7 - (i
% 8);
853 for (j
= 0; j
< width
; j
++) {
854 GLint srcCol
= j
% 32;
855 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
856 for (k
= 0; k
< components
; k
++) {
872 * Reset the fields of a gl_texture_image struct to zero.
874 * \param img texture image structure.
876 * This is called when a proxy texture test fails, we set all the
877 * image members (except DriverData) to zero.
878 * It's also used in glTexImage[123]D as a safeguard to be sure all
879 * required fields get initialized properly by the Driver.TexImage[123]D
883 clear_teximage_fields(struct gl_texture_image
*img
)
886 img
->_BaseFormat
= 0;
887 img
->InternalFormat
= 0;
893 if (img
->ImageOffsets
) {
894 _mesa_free(img
->ImageOffsets
);
895 img
->ImageOffsets
= NULL
;
904 img
->TexFormat
= &_mesa_null_texformat
;
905 img
->FetchTexelc
= NULL
;
906 img
->FetchTexelf
= NULL
;
907 img
->IsCompressed
= 0;
908 img
->CompressedSize
= 0;
913 * Initialize basic fields of the gl_texture_image struct.
915 * \param ctx GL context.
916 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
917 * \param img texture image structure to be initialized.
918 * \param width image width.
919 * \param height image height.
920 * \param depth image depth.
921 * \param border image border.
922 * \param internalFormat internal format.
924 * Fills in the fields of \p img with the given information.
925 * Note: width, height and depth include the border.
928 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
929 struct gl_texture_image
*img
,
930 GLsizei width
, GLsizei height
, GLsizei depth
,
931 GLint border
, GLenum internalFormat
)
940 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
941 ASSERT(img
->_BaseFormat
> 0);
942 img
->InternalFormat
= internalFormat
;
943 img
->Border
= border
;
945 img
->Height
= height
;
948 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
949 img
->WidthLog2
= logbase2(img
->Width2
);
951 if (height
== 1) { /* 1-D texture */
956 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
957 img
->HeightLog2
= logbase2(img
->Height2
);
960 if (depth
== 1) { /* 2-D texture */
965 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
966 img
->DepthLog2
= logbase2(img
->Depth2
);
969 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
971 img
->IsCompressed
= GL_FALSE
;
972 img
->CompressedSize
= 0;
974 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
975 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
976 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
977 img
->_IsPowerOfTwo
= GL_TRUE
;
979 img
->_IsPowerOfTwo
= GL_FALSE
;
981 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
982 img
->RowStride
= width
;
983 /* Allocate the ImageOffsets array and initialize to typical values.
984 * We allocate the array for 1D/2D textures too in order to avoid special-
985 * case code in the texstore routines.
987 if (img
->ImageOffsets
)
988 _mesa_free(img
->ImageOffsets
);
989 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
990 for (i
= 0; i
< depth
; i
++) {
991 img
->ImageOffsets
[i
] = i
* width
* height
;
994 /* Compute Width/Height/DepthScale for mipmap lod computation */
995 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
996 /* scale = 1.0 since texture coords directly map to texels */
997 img
->WidthScale
= 1.0;
998 img
->HeightScale
= 1.0;
999 img
->DepthScale
= 1.0;
1002 img
->WidthScale
= (GLfloat
) img
->Width
;
1003 img
->HeightScale
= (GLfloat
) img
->Height
;
1004 img
->DepthScale
= (GLfloat
) img
->Depth
;
1010 * Free and clear fields of the gl_texture_image struct.
1012 * \param ctx GL context.
1013 * \param texImage texture image structure to be cleared.
1015 * After the call, \p texImage will have no data associated with it. Its
1016 * fields are cleared so that its parent object will test incomplete.
1019 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
1021 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1022 clear_teximage_fields(texImage
);
1027 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1028 * level, width, height and depth against the ctx->Const limits for textures.
1030 * A hardware driver might override this function if, for example, the
1031 * max 3D texture size is 512x512x64 (i.e. not a cube).
1033 * Note that width, height, depth == 0 is not an error. However, a
1034 * texture with zero width/height/depth will be considered "incomplete"
1035 * and texturing will effectively be disabled.
1037 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1038 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1039 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1040 * \param level as passed to glTexImage
1041 * \param internalFormat as passed to glTexImage
1042 * \param format as passed to glTexImage
1043 * \param type as passed to glTexImage
1044 * \param width as passed to glTexImage
1045 * \param height as passed to glTexImage
1046 * \param depth as passed to glTexImage
1047 * \param border as passed to glTexImage
1048 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1051 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1052 GLint internalFormat
, GLenum format
, GLenum type
,
1053 GLint width
, GLint height
, GLint depth
, GLint border
)
1057 (void) internalFormat
;
1062 case GL_PROXY_TEXTURE_1D
:
1063 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1064 if (width
< 2 * border
|| width
> 2 + maxSize
||
1065 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1066 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1067 level
>= ctx
->Const
.MaxTextureLevels
) {
1068 /* bad width or level */
1072 case GL_PROXY_TEXTURE_2D
:
1073 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1074 if (width
< 2 * border
|| width
> 2 + maxSize
||
1075 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1076 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1077 height
< 2 * border
|| height
> 2 + maxSize
||
1078 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1079 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1080 level
>= ctx
->Const
.MaxTextureLevels
) {
1081 /* bad width or height or level */
1085 case GL_PROXY_TEXTURE_3D
:
1086 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1087 if (width
< 2 * border
|| width
> 2 + maxSize
||
1088 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1089 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1090 height
< 2 * border
|| height
> 2 + maxSize
||
1091 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1092 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1093 depth
< 2 * border
|| depth
> 2 + maxSize
||
1094 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1095 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1096 level
>= ctx
->Const
.Max3DTextureLevels
) {
1097 /* bad width or height or depth or level */
1101 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1102 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1103 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1105 /* bad width or height or level */
1109 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1110 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1111 if (width
< 2 * border
|| width
> 2 + maxSize
||
1112 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1113 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1114 height
< 2 * border
|| height
> 2 + maxSize
||
1115 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1116 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1117 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1118 /* bad width or height */
1122 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1123 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1124 if (width
< 2 * border
|| width
> 2 + maxSize
||
1125 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1126 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1127 level
>= ctx
->Const
.MaxTextureLevels
) {
1128 /* bad width or level */
1132 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1136 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1137 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1138 if (width
< 2 * border
|| width
> 2 + maxSize
||
1139 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1140 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1141 height
< 2 * border
|| height
> 2 + maxSize
||
1142 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1143 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1144 level
>= ctx
->Const
.MaxTextureLevels
) {
1145 /* bad width or height or level */
1148 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1153 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1160 * Helper function to determine whether a target supports compressed textures
1163 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1165 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1166 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1167 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1168 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1169 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1170 || ((ctx
->Extensions
.MESA_texture_array
&&
1171 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1172 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1177 * Test the glTexImage[123]D() parameters for errors.
1179 * \param ctx GL context.
1180 * \param target texture target given by the user.
1181 * \param level image level given by the user.
1182 * \param internalFormat internal format given by the user.
1183 * \param format pixel data format given by the user.
1184 * \param type pixel data type given by the user.
1185 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1186 * \param width image width given by the user.
1187 * \param height image height given by the user.
1188 * \param depth image depth given by the user.
1189 * \param border image border given by the user.
1191 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1193 * Verifies each of the parameters against the constants specified in
1194 * __GLcontextRec::Const and the supported extensions, and according to the
1195 * OpenGL specification.
1198 texture_error_check( GLcontext
*ctx
, GLenum target
,
1199 GLint level
, GLint internalFormat
,
1200 GLenum format
, GLenum type
,
1202 GLint width
, GLint height
,
1203 GLint depth
, GLint border
)
1205 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1206 GLboolean sizeOK
= GL_TRUE
;
1207 GLboolean colorFormat
, indexFormat
;
1208 GLenum proxy_target
;
1210 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1211 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1213 _mesa_error(ctx
, GL_INVALID_VALUE
,
1214 "glTexImage%dD(level=%d)", dimensions
, level
);
1220 if (border
< 0 || border
> 1 ||
1221 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1222 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1224 _mesa_error(ctx
, GL_INVALID_VALUE
,
1225 "glTexImage%dD(border=%d)", dimensions
, border
);
1230 if (width
< 0 || height
< 0 || depth
< 0) {
1232 _mesa_error(ctx
, GL_INVALID_VALUE
,
1233 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1238 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1239 * level, width, height and depth.
1241 if (dimensions
== 1) {
1242 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1243 proxy_target
= GL_PROXY_TEXTURE_1D
;
1248 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1252 else if (dimensions
== 2) {
1254 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1255 proxy_target
= GL_PROXY_TEXTURE_2D
;
1257 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1258 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1259 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1260 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1261 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1264 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1265 sizeOK
= (width
== height
);
1267 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1268 target
== GL_TEXTURE_RECTANGLE_NV
) {
1269 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1270 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1273 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1275 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1276 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1277 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1280 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1284 else if (dimensions
== 3) {
1285 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1286 proxy_target
= GL_PROXY_TEXTURE_3D
;
1288 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1289 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1290 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1293 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1298 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1302 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1303 internalFormat
, format
,
1304 type
, width
, height
,
1308 _mesa_error(ctx
, GL_INVALID_VALUE
,
1309 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1310 dimensions
, level
, width
, height
, depth
);
1315 /* Check internalFormat */
1316 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1318 _mesa_error(ctx
, GL_INVALID_VALUE
,
1319 "glTexImage%dD(internalFormat=0x%x)",
1320 dimensions
, internalFormat
);
1325 /* Check incoming image format and type */
1326 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1327 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1328 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1331 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1332 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1333 dimensions
, format
, type
);
1338 /* make sure internal format and format basically agree */
1339 colorFormat
= _mesa_is_color_format(format
);
1340 indexFormat
= _mesa_is_index_format(format
);
1341 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1342 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1343 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1344 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1345 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1346 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1348 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1349 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1350 dimensions
, internalFormat
, format
);
1354 /* additional checks for ycbcr textures */
1355 if (internalFormat
== GL_YCBCR_MESA
) {
1356 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1357 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1358 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1360 _mesa_sprintf(message
,
1361 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1362 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1363 return GL_TRUE
; /* error */
1365 if (target
!= GL_TEXTURE_2D
&&
1366 target
!= GL_PROXY_TEXTURE_2D
&&
1367 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1368 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1370 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1376 _mesa_sprintf(message
,
1377 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1378 dimensions
, border
);
1379 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1385 /* additional checks for depth textures */
1386 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1387 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1388 if (target
!= GL_TEXTURE_1D
&&
1389 target
!= GL_PROXY_TEXTURE_1D
&&
1390 target
!= GL_TEXTURE_2D
&&
1391 target
!= GL_PROXY_TEXTURE_2D
&&
1392 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1393 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1395 _mesa_error(ctx
, GL_INVALID_ENUM
,
1396 "glTexImage(target/internalFormat)");
1401 /* additional checks for compressed textures */
1402 if (is_compressed_format(ctx
, internalFormat
)) {
1403 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1404 _mesa_error(ctx
, GL_INVALID_ENUM
,
1405 "glTexImage%d(target)", dimensions
);
1410 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1411 "glTexImage%D(border!=0)", dimensions
);
1417 /* if we get here, the parameters are OK */
1423 * Test glTexSubImage[123]D() parameters for errors.
1425 * \param ctx GL context.
1426 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1427 * \param target texture target given by the user.
1428 * \param level image level given by the user.
1429 * \param xoffset sub-image x offset given by the user.
1430 * \param yoffset sub-image y offset given by the user.
1431 * \param zoffset sub-image z offset given by the user.
1432 * \param format pixel data format given by the user.
1433 * \param type pixel data type given by the user.
1434 * \param width image width given by the user.
1435 * \param height image height given by the user.
1436 * \param depth image depth given by the user.
1438 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1440 * Verifies each of the parameters against the constants specified in
1441 * __GLcontextRec::Const and the supported extensions, and according to the
1442 * OpenGL specification.
1445 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1446 GLenum target
, GLint level
,
1447 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1448 GLint width
, GLint height
, GLint depth
,
1449 GLenum format
, GLenum type
)
1452 if (dimensions
== 1) {
1453 if (target
!= GL_TEXTURE_1D
) {
1454 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1458 else if (dimensions
== 2) {
1459 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1460 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1461 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1462 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1466 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1467 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1468 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1472 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1473 if (!ctx
->Extensions
.MESA_texture_array
) {
1474 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1478 else if (target
!= GL_TEXTURE_2D
) {
1479 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1483 else if (dimensions
== 3) {
1484 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1485 if (!ctx
->Extensions
.MESA_texture_array
) {
1486 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1490 else if (target
!= GL_TEXTURE_3D
) {
1491 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1496 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1500 /* Basic level check */
1501 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1502 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1507 _mesa_error(ctx
, GL_INVALID_VALUE
,
1508 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1511 if (height
< 0 && dimensions
> 1) {
1512 _mesa_error(ctx
, GL_INVALID_VALUE
,
1513 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1516 if (depth
< 0 && dimensions
> 2) {
1517 _mesa_error(ctx
, GL_INVALID_VALUE
,
1518 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1522 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1523 _mesa_error(ctx
, GL_INVALID_ENUM
,
1524 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1525 dimensions
, format
, type
);
1533 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1534 GLenum target
, GLint level
,
1535 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1536 GLint width
, GLint height
, GLint depth
,
1537 GLenum format
, GLenum type
,
1538 const struct gl_texture_image
*destTex
)
1541 /* undefined image level */
1542 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1546 if (xoffset
< -((GLint
)destTex
->Border
)) {
1547 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1551 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1552 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1556 if (dimensions
> 1) {
1557 if (yoffset
< -((GLint
)destTex
->Border
)) {
1558 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1562 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1563 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1568 if (dimensions
> 2) {
1569 if (zoffset
< -((GLint
)destTex
->Border
)) {
1570 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1573 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1574 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1579 #if FEATURE_EXT_texture_sRGB
1580 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1581 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1582 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1583 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1584 if ((width
& 0x3) || (height
& 0x3) ||
1585 (xoffset
& 0x3) || (yoffset
& 0x3))
1586 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1587 "glTexSubImage%dD(size or offset not multiple of 4)",
1593 if (destTex
->IsCompressed
) {
1594 if (!target_can_be_compressed(ctx
, target
)) {
1595 _mesa_error(ctx
, GL_INVALID_ENUM
,
1596 "glTexSubImage%D(target)", dimensions
);
1599 /* offset must be multiple of 4 */
1600 if ((xoffset
& 3) || (yoffset
& 3)) {
1601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1602 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1605 /* size must be multiple of 4 or equal to whole texture size */
1606 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1607 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1608 "glTexSubImage%D(width)", dimensions
);
1611 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1612 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1613 "glTexSubImage%D(width)", dimensions
);
1623 * Test glCopyTexImage[12]D() parameters for errors.
1625 * \param ctx GL context.
1626 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1627 * \param target texture target given by the user.
1628 * \param level image level given by the user.
1629 * \param internalFormat internal format given by the user.
1630 * \param width image width given by the user.
1631 * \param height image height given by the user.
1632 * \param border texture border.
1634 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1636 * Verifies each of the parameters against the constants specified in
1637 * __GLcontextRec::Const and the supported extensions, and according to the
1638 * OpenGL specification.
1641 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1642 GLenum target
, GLint level
, GLint internalFormat
,
1643 GLint width
, GLint height
, GLint border
)
1649 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1650 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1651 _mesa_error(ctx
, GL_INVALID_VALUE
,
1652 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1656 /* Check that the source buffer is complete */
1657 if (ctx
->ReadBuffer
->Name
) {
1658 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1659 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1660 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1661 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1667 if (border
< 0 || border
> 1 ||
1668 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1669 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1673 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1675 _mesa_error(ctx
, GL_INVALID_VALUE
,
1676 "glCopyTexImage%dD(internalFormat)", dimensions
);
1680 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1681 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1682 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1686 /* NOTE: the format and type aren't really significant for
1687 * TestProxyTexImage(). Only the internalformat really matters.
1691 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1692 * level, width, height and depth.
1694 if (dimensions
== 1) {
1695 if (target
== GL_TEXTURE_1D
) {
1696 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1697 level
, internalFormat
,
1699 width
, 1, 1, border
);
1702 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1706 else if (dimensions
== 2) {
1707 if (target
== GL_TEXTURE_2D
) {
1708 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1709 level
, internalFormat
,
1711 width
, height
, 1, border
);
1713 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1714 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1715 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1716 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1719 sizeOK
= (width
== height
) &&
1720 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1721 level
, internalFormat
, format
, type
,
1722 width
, height
, 1, border
);
1724 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1725 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1726 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1729 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1730 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1731 level
, internalFormat
,
1733 width
, height
, 1, border
);
1735 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1736 if (!ctx
->Extensions
.MESA_texture_array
) {
1737 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1740 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1741 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1742 level
, internalFormat
,
1744 width
, height
, 1, border
);
1747 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1752 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1757 if (dimensions
== 1) {
1758 _mesa_error(ctx
, GL_INVALID_VALUE
,
1759 "glCopyTexImage1D(width=%d)", width
);
1762 ASSERT(dimensions
== 2);
1763 _mesa_error(ctx
, GL_INVALID_VALUE
,
1764 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1769 if (is_compressed_format(ctx
, internalFormat
)) {
1770 if (!target_can_be_compressed(ctx
, target
)) {
1771 _mesa_error(ctx
, GL_INVALID_ENUM
,
1772 "glCopyTexImage%d(target)", dimensions
);
1776 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1777 "glCopyTexImage%D(border!=0)", dimensions
);
1781 else if (_mesa_is_depth_format(internalFormat
)) {
1782 /* make sure we have depth/stencil buffers */
1783 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1784 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1785 "glCopyTexImage%D(no depth)", dimensions
);
1789 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1790 /* make sure we have depth/stencil buffers */
1791 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1792 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1793 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
1798 /* if we get here, the parameters are OK */
1804 * Test glCopyTexSubImage[12]D() parameters for errors.
1805 * Note that this is the first part of error checking.
1806 * See also copytexsubimage_error_check2() below for the second part.
1808 * \param ctx GL context.
1809 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1810 * \param target texture target given by the user.
1811 * \param level image level given by the user.
1813 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1816 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1817 GLenum target
, GLint level
)
1819 /* Check that the source buffer is complete */
1820 if (ctx
->ReadBuffer
->Name
) {
1821 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1822 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1823 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1824 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1830 if (dimensions
== 1) {
1831 if (target
!= GL_TEXTURE_1D
) {
1832 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1836 else if (dimensions
== 2) {
1837 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1838 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1839 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1840 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1844 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1845 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1846 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1850 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1851 if (!ctx
->Extensions
.MESA_texture_array
) {
1852 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1856 else if (target
!= GL_TEXTURE_2D
) {
1857 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1861 else if (dimensions
== 3) {
1862 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1863 (!ctx
->Extensions
.MESA_texture_array
))
1864 && (target
!= GL_TEXTURE_3D
)) {
1865 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1871 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1872 _mesa_error(ctx
, GL_INVALID_VALUE
,
1873 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1882 * Second part of error checking for glCopyTexSubImage[12]D().
1883 * \param xoffset sub-image x offset given by the user.
1884 * \param yoffset sub-image y offset given by the user.
1885 * \param zoffset sub-image z offset given by the user.
1886 * \param width image width given by the user.
1887 * \param height image height given by the user.
1890 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1891 GLenum target
, GLint level
,
1892 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1893 GLsizei width
, GLsizei height
,
1894 const struct gl_texture_image
*teximage
)
1896 /* check that dest tex image exists */
1898 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1899 "glCopyTexSubImage%dD(undefined texture level: %d)",
1906 _mesa_error(ctx
, GL_INVALID_VALUE
,
1907 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1910 if (dimensions
> 1 && height
< 0) {
1911 _mesa_error(ctx
, GL_INVALID_VALUE
,
1912 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1916 /* check x/y offsets */
1917 if (xoffset
< -((GLint
)teximage
->Border
)) {
1918 _mesa_error(ctx
, GL_INVALID_VALUE
,
1919 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1922 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1923 _mesa_error(ctx
, GL_INVALID_VALUE
,
1924 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1927 if (dimensions
> 1) {
1928 if (yoffset
< -((GLint
)teximage
->Border
)) {
1929 _mesa_error(ctx
, GL_INVALID_VALUE
,
1930 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1933 /* NOTE: we're adding the border here, not subtracting! */
1934 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1935 _mesa_error(ctx
, GL_INVALID_VALUE
,
1936 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1941 /* check z offset */
1942 if (dimensions
> 2) {
1943 if (zoffset
< -((GLint
)teximage
->Border
)) {
1944 _mesa_error(ctx
, GL_INVALID_VALUE
,
1945 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1948 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1949 _mesa_error(ctx
, GL_INVALID_VALUE
,
1950 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1955 if (teximage
->IsCompressed
) {
1956 if (!target_can_be_compressed(ctx
, target
)) {
1957 _mesa_error(ctx
, GL_INVALID_ENUM
,
1958 "glCopyTexSubImage%d(target)", dimensions
);
1961 /* offset must be multiple of 4 */
1962 if ((xoffset
& 3) || (yoffset
& 3)) {
1963 _mesa_error(ctx
, GL_INVALID_VALUE
,
1964 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
1967 /* size must be multiple of 4 */
1968 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1969 _mesa_error(ctx
, GL_INVALID_VALUE
,
1970 "glCopyTexSubImage%D(width)", dimensions
);
1973 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1974 _mesa_error(ctx
, GL_INVALID_VALUE
,
1975 "glCopyTexSubImage%D(height)", dimensions
);
1980 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
1981 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1985 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
1986 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1987 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
1988 dimensions
, teximage
->_BaseFormat
);
1992 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
1993 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1994 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1995 "glCopyTexSubImage%D(no depth buffer)",
2000 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2001 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2002 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2003 "glCopyTexSubImage%D(no depth/stencil buffer)",
2009 /* if we get here, the parameters are OK */
2014 /** Callback info for walking over FBO hash table */
2018 struct gl_texture_object
*texObj
;
2024 * Check render to texture callback. Called from _mesa_HashWalk().
2027 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2029 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2030 const struct cb_info
*info
= (struct cb_info
*) userData
;
2031 GLcontext
*ctx
= info
->ctx
;
2032 const struct gl_texture_object
*texObj
= info
->texObj
;
2033 const GLuint level
= info
->level
, face
= info
->face
;
2035 /* If this is a user-created FBO */
2038 /* check if any of the FBO's attachments point to 'texObj' */
2039 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2040 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2041 if (att
->Type
== GL_TEXTURE
&&
2042 att
->Texture
== texObj
&&
2043 att
->TextureLevel
== level
&&
2044 att
->CubeMapFace
== face
) {
2045 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2046 /* Tell driver about the new renderbuffer texture */
2047 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2048 /* Mark fb status as indeterminate to force re-validation */
2057 * When a texture image is specified we have to check if it's bound to
2058 * any framebuffer objects (render to texture) in order to detect changes
2059 * in size or format since that effects FBO completeness.
2060 * Any FBOs rendering into the texture must be re-validated.
2063 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2064 GLuint face
, GLuint level
)
2066 /* Only check this texture if it's been marked as RenderToTexture */
2067 if (texObj
->_RenderToTexture
) {
2068 struct cb_info info
;
2070 info
.texObj
= texObj
;
2073 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2078 /** Debug helper: override the user-requested internal format */
2080 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2083 if (internalFormat
== GL_RGBA16F_ARB
||
2084 internalFormat
== GL_RGBA32F_ARB
) {
2085 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2088 else if (internalFormat
== GL_RGB16F_ARB
||
2089 internalFormat
== GL_RGB32F_ARB
) {
2090 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2093 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2094 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2095 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2096 return GL_LUMINANCE_ALPHA
;
2098 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2099 internalFormat
== GL_LUMINANCE32F_ARB
) {
2100 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2101 return GL_LUMINANCE
;
2103 else if (internalFormat
== GL_ALPHA16F_ARB
||
2104 internalFormat
== GL_ALPHA32F_ARB
) {
2105 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2109 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2110 internalFormat = GL_RGBA;
2114 return internalFormat
;
2117 return internalFormat
;
2123 * Called from the API. Note that width includes the border.
2126 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2127 GLsizei width
, GLint border
, GLenum format
,
2128 GLenum type
, const GLvoid
*pixels
)
2130 GLsizei postConvWidth
= width
;
2131 GET_CURRENT_CONTEXT(ctx
);
2132 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2134 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2136 #if FEATURE_convolve
2137 if (_mesa_is_color_format(internalFormat
)) {
2138 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2142 if (target
== GL_TEXTURE_1D
) {
2143 /* non-proxy target */
2144 struct gl_texture_unit
*texUnit
;
2145 struct gl_texture_object
*texObj
;
2146 struct gl_texture_image
*texImage
;
2147 const GLuint face
= _mesa_tex_target_to_face(target
);
2149 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2150 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2151 return; /* error was recorded */
2154 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2155 _mesa_update_state(ctx
);
2157 texUnit
= _mesa_get_current_tex_unit(ctx
);
2158 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2159 _mesa_lock_texture(ctx
, texObj
);
2161 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2163 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2167 if (texImage
->Data
) {
2168 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2171 ASSERT(texImage
->Data
== NULL
);
2173 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2174 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2175 postConvWidth
, 1, 1,
2176 border
, internalFormat
);
2178 ASSERT(ctx
->Driver
.TexImage1D
);
2180 /* Give the texture to the driver! <pixels> may be null! */
2181 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2182 width
, border
, format
, type
, pixels
,
2183 &ctx
->Unpack
, texObj
, texImage
);
2185 ASSERT(texImage
->TexFormat
);
2187 update_fbo_texture(ctx
, texObj
, face
, level
);
2190 texObj
->_Complete
= GL_FALSE
;
2191 ctx
->NewState
|= _NEW_TEXTURE
;
2194 _mesa_unlock_texture(ctx
, texObj
);
2196 else if (target
== GL_PROXY_TEXTURE_1D
) {
2197 /* Proxy texture: check for errors and update proxy state */
2198 struct gl_texture_image
*texImage
;
2199 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2200 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2201 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2202 /* when error, clear all proxy texture image parameters */
2204 clear_teximage_fields(texImage
);
2207 /* no error, set the tex image parameters */
2209 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2210 postConvWidth
, 1, 1,
2211 border
, internalFormat
);
2212 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2213 internalFormat
, format
, type
);
2217 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2224 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2225 GLsizei width
, GLsizei height
, GLint border
,
2226 GLenum format
, GLenum type
,
2227 const GLvoid
*pixels
)
2229 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2230 GET_CURRENT_CONTEXT(ctx
);
2231 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2233 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2235 #if FEATURE_convolve
2236 if (_mesa_is_color_format(internalFormat
)) {
2237 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2242 if (target
== GL_TEXTURE_2D
||
2243 (ctx
->Extensions
.ARB_texture_cube_map
&&
2244 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2245 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2246 (ctx
->Extensions
.NV_texture_rectangle
&&
2247 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2248 (ctx
->Extensions
.MESA_texture_array
&&
2249 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2250 /* non-proxy target */
2251 struct gl_texture_unit
*texUnit
;
2252 struct gl_texture_object
*texObj
;
2253 struct gl_texture_image
*texImage
;
2254 const GLuint face
= _mesa_tex_target_to_face(target
);
2256 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2257 format
, type
, 2, postConvWidth
, postConvHeight
,
2259 return; /* error was recorded */
2262 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2263 _mesa_update_state(ctx
);
2265 texUnit
= _mesa_get_current_tex_unit(ctx
);
2266 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2267 _mesa_lock_texture(ctx
, texObj
);
2269 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2271 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2275 if (texImage
->Data
) {
2276 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2279 ASSERT(texImage
->Data
== NULL
);
2280 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2281 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2282 postConvWidth
, postConvHeight
, 1,
2283 border
, internalFormat
);
2285 ASSERT(ctx
->Driver
.TexImage2D
);
2287 /* Give the texture to the driver! <pixels> may be null! */
2288 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2289 width
, height
, border
, format
, type
, pixels
,
2290 &ctx
->Unpack
, texObj
, texImage
);
2292 ASSERT(texImage
->TexFormat
);
2294 update_fbo_texture(ctx
, texObj
, face
, level
);
2297 texObj
->_Complete
= GL_FALSE
;
2298 ctx
->NewState
|= _NEW_TEXTURE
;
2301 _mesa_unlock_texture(ctx
, texObj
);
2303 else if (target
== GL_PROXY_TEXTURE_2D
||
2304 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2305 ctx
->Extensions
.ARB_texture_cube_map
) ||
2306 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2307 ctx
->Extensions
.NV_texture_rectangle
) ||
2308 (ctx
->Extensions
.MESA_texture_array
&&
2309 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2310 /* Proxy texture: check for errors and update proxy state */
2311 struct gl_texture_image
*texImage
;
2312 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2313 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2314 format
, type
, 2, postConvWidth
, postConvHeight
,
2316 /* when error, clear all proxy texture image parameters */
2318 clear_teximage_fields(texImage
);
2321 /* no error, set the tex image parameters */
2322 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2323 postConvWidth
, postConvHeight
, 1,
2324 border
, internalFormat
);
2325 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2326 internalFormat
, format
, type
);
2330 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2337 * Called by the API or display list executor.
2338 * Note that width and height include the border.
2341 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2342 GLsizei width
, GLsizei height
, GLsizei depth
,
2343 GLint border
, GLenum format
, GLenum type
,
2344 const GLvoid
*pixels
)
2346 GET_CURRENT_CONTEXT(ctx
);
2347 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2349 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2351 if (target
== GL_TEXTURE_3D
||
2352 (ctx
->Extensions
.MESA_texture_array
&&
2353 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2354 /* non-proxy target */
2355 struct gl_texture_unit
*texUnit
;
2356 struct gl_texture_object
*texObj
;
2357 struct gl_texture_image
*texImage
;
2358 const GLuint face
= _mesa_tex_target_to_face(target
);
2360 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2361 format
, type
, 3, width
, height
, depth
, border
)) {
2362 return; /* error was recorded */
2365 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2366 _mesa_update_state(ctx
);
2368 texUnit
= _mesa_get_current_tex_unit(ctx
);
2369 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2370 _mesa_lock_texture(ctx
, texObj
);
2372 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2374 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2378 if (texImage
->Data
) {
2379 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2382 ASSERT(texImage
->Data
== NULL
);
2383 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2384 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2385 width
, height
, depth
,
2386 border
, internalFormat
);
2388 ASSERT(ctx
->Driver
.TexImage3D
);
2390 /* Give the texture to the driver! <pixels> may be null! */
2391 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2392 width
, height
, depth
, border
, format
, type
,
2393 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2395 ASSERT(texImage
->TexFormat
);
2397 update_fbo_texture(ctx
, texObj
, face
, level
);
2400 texObj
->_Complete
= GL_FALSE
;
2401 ctx
->NewState
|= _NEW_TEXTURE
;
2404 _mesa_unlock_texture(ctx
, texObj
);
2406 else if (target
== GL_PROXY_TEXTURE_3D
||
2407 (ctx
->Extensions
.MESA_texture_array
&&
2408 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
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
, 3, width
, height
, depth
, border
)) {
2414 /* when error, clear all proxy texture image parameters */
2416 clear_teximage_fields(texImage
);
2419 /* no error, set the tex image parameters */
2420 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2421 depth
, border
, internalFormat
);
2422 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2423 internalFormat
, format
, type
);
2427 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2434 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2435 GLsizei width
, GLsizei height
, GLsizei depth
,
2436 GLint border
, GLenum format
, GLenum type
,
2437 const GLvoid
*pixels
)
2439 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2440 depth
, border
, format
, type
, pixels
);
2446 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2447 GLint xoffset
, GLsizei width
,
2448 GLenum format
, GLenum type
,
2449 const GLvoid
*pixels
)
2451 GLsizei postConvWidth
= width
;
2452 struct gl_texture_unit
*texUnit
;
2453 struct gl_texture_object
*texObj
;
2454 struct gl_texture_image
*texImage
= NULL
;
2455 GET_CURRENT_CONTEXT(ctx
);
2456 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2458 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2459 _mesa_update_state(ctx
);
2461 #if FEATURE_convolve
2462 /* XXX should test internal format */
2463 if (_mesa_is_color_format(format
)) {
2464 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2468 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2469 postConvWidth
, 1, 1, format
, type
)) {
2470 return; /* error was detected */
2474 texUnit
= _mesa_get_current_tex_unit(ctx
);
2475 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2478 _mesa_lock_texture(ctx
, texObj
);
2480 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2482 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2483 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2484 goto out
; /* error was detected */
2488 goto out
; /* no-op, not an error */
2490 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2491 xoffset
+= texImage
->Border
;
2493 ASSERT(ctx
->Driver
.TexSubImage1D
);
2494 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2495 format
, type
, pixels
, &ctx
->Unpack
,
2497 ctx
->NewState
|= _NEW_TEXTURE
;
2500 _mesa_unlock_texture(ctx
, texObj
);
2505 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2506 GLint xoffset
, GLint yoffset
,
2507 GLsizei width
, GLsizei height
,
2508 GLenum format
, GLenum type
,
2509 const GLvoid
*pixels
)
2511 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2512 struct gl_texture_unit
*texUnit
;
2513 struct gl_texture_object
*texObj
;
2514 struct gl_texture_image
*texImage
;
2515 GET_CURRENT_CONTEXT(ctx
);
2516 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2518 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2519 _mesa_update_state(ctx
);
2521 #if FEATURE_convolve
2522 /* XXX should test internal format */
2523 if (_mesa_is_color_format(format
)) {
2524 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2529 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2530 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2531 return; /* error was detected */
2534 texUnit
= _mesa_get_current_tex_unit(ctx
);
2535 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2536 _mesa_lock_texture(ctx
, texObj
);
2538 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2540 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2541 postConvWidth
, postConvHeight
, 1, format
, type
,
2543 goto out
; /* error was detected */
2546 if (width
== 0 || height
== 0)
2547 goto out
; /* no-op, not an error */
2549 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2550 xoffset
+= texImage
->Border
;
2551 yoffset
+= texImage
->Border
;
2553 ASSERT(ctx
->Driver
.TexSubImage2D
);
2554 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2555 width
, height
, format
, type
, pixels
,
2556 &ctx
->Unpack
, texObj
, texImage
);
2557 ctx
->NewState
|= _NEW_TEXTURE
;
2560 _mesa_unlock_texture(ctx
, texObj
);
2566 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2567 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2568 GLsizei width
, GLsizei height
, GLsizei depth
,
2569 GLenum format
, GLenum type
,
2570 const GLvoid
*pixels
)
2572 struct gl_texture_unit
*texUnit
;
2573 struct gl_texture_object
*texObj
;
2574 struct gl_texture_image
*texImage
;
2575 GET_CURRENT_CONTEXT(ctx
);
2576 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2578 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2579 _mesa_update_state(ctx
);
2581 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2582 width
, height
, depth
, format
, type
)) {
2583 return; /* error was detected */
2586 texUnit
= _mesa_get_current_tex_unit(ctx
);
2587 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2589 _mesa_lock_texture(ctx
, texObj
);
2591 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2593 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2594 width
, height
, depth
, format
, type
, texImage
)) {
2595 goto out
; /* error was detected */
2598 if (width
== 0 || height
== 0 || height
== 0)
2599 goto out
; /* no-op, not an error */
2601 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2602 xoffset
+= texImage
->Border
;
2603 yoffset
+= texImage
->Border
;
2604 zoffset
+= texImage
->Border
;
2606 ASSERT(ctx
->Driver
.TexSubImage3D
);
2607 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2608 xoffset
, yoffset
, zoffset
,
2609 width
, height
, depth
,
2610 format
, type
, pixels
,
2611 &ctx
->Unpack
, texObj
, texImage
);
2612 ctx
->NewState
|= _NEW_TEXTURE
;
2615 _mesa_unlock_texture(ctx
, texObj
);
2621 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2622 GLenum internalFormat
,
2624 GLsizei width
, GLint border
)
2626 struct gl_texture_unit
*texUnit
;
2627 struct gl_texture_object
*texObj
;
2628 struct gl_texture_image
*texImage
;
2629 GLsizei postConvWidth
= width
;
2630 const GLuint face
= _mesa_tex_target_to_face(target
);
2631 GET_CURRENT_CONTEXT(ctx
);
2632 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2634 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2635 _mesa_update_state(ctx
);
2637 #if FEATURE_convolve
2638 if (_mesa_is_color_format(internalFormat
)) {
2639 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2643 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2644 postConvWidth
, 1, border
))
2647 texUnit
= _mesa_get_current_tex_unit(ctx
);
2648 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2649 _mesa_lock_texture(ctx
, texObj
);
2651 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2653 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2657 if (texImage
->Data
) {
2658 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2661 ASSERT(texImage
->Data
== NULL
);
2663 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2664 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2665 border
, internalFormat
);
2668 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2669 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2670 x
, y
, width
, border
);
2672 ASSERT(texImage
->TexFormat
);
2674 update_fbo_texture(ctx
, texObj
, face
, level
);
2677 texObj
->_Complete
= GL_FALSE
;
2678 ctx
->NewState
|= _NEW_TEXTURE
;
2681 _mesa_unlock_texture(ctx
, texObj
);
2687 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2688 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2691 struct gl_texture_unit
*texUnit
;
2692 struct gl_texture_object
*texObj
;
2693 struct gl_texture_image
*texImage
;
2694 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2695 const GLuint face
= _mesa_tex_target_to_face(target
);
2696 GET_CURRENT_CONTEXT(ctx
);
2697 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2699 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2700 _mesa_update_state(ctx
);
2702 #if FEATURE_convolve
2703 if (_mesa_is_color_format(internalFormat
)) {
2704 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2709 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2710 postConvWidth
, postConvHeight
, border
))
2713 texUnit
= _mesa_get_current_tex_unit(ctx
);
2714 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2716 _mesa_lock_texture(ctx
, texObj
);
2718 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2721 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2725 if (texImage
->Data
) {
2726 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2729 ASSERT(texImage
->Data
== NULL
);
2731 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2732 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2733 postConvWidth
, postConvHeight
, 1,
2734 border
, internalFormat
);
2736 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2737 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
2738 x
, y
, width
, height
, border
);
2740 ASSERT(texImage
->TexFormat
);
2742 update_fbo_texture(ctx
, texObj
, face
, level
);
2745 texObj
->_Complete
= GL_FALSE
;
2746 ctx
->NewState
|= _NEW_TEXTURE
;
2749 _mesa_unlock_texture(ctx
, texObj
);
2754 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2755 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2757 struct gl_texture_unit
*texUnit
;
2758 struct gl_texture_object
*texObj
;
2759 struct gl_texture_image
*texImage
;
2760 GLsizei postConvWidth
= width
;
2764 GET_CURRENT_CONTEXT(ctx
);
2765 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2767 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2768 _mesa_update_state(ctx
);
2770 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2773 texUnit
= _mesa_get_current_tex_unit(ctx
);
2774 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2776 _mesa_lock_texture(ctx
, texObj
);
2778 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2780 #if FEATURE_convolve
2781 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2782 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2786 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2787 xoffset
, 0, 0, postConvWidth
, 1,
2792 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2793 xoffset
+= texImage
->Border
;
2795 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2797 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2798 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2799 xoffset
, x
, y
, width
);
2802 ctx
->NewState
|= _NEW_TEXTURE
;
2805 _mesa_unlock_texture(ctx
, texObj
);
2811 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2812 GLint xoffset
, GLint yoffset
,
2813 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2815 struct gl_texture_unit
*texUnit
;
2816 struct gl_texture_object
*texObj
;
2817 struct gl_texture_image
*texImage
;
2818 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2819 GET_CURRENT_CONTEXT(ctx
);
2820 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2822 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2823 _mesa_update_state(ctx
);
2825 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2828 texUnit
= _mesa_get_current_tex_unit(ctx
);
2829 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2831 _mesa_lock_texture(ctx
, texObj
);
2833 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2835 #if FEATURE_convolve
2836 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2837 _mesa_adjust_image_for_convolution(ctx
, 2,
2838 &postConvWidth
, &postConvHeight
);
2842 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2843 postConvWidth
, postConvHeight
, texImage
))
2846 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2847 xoffset
+= texImage
->Border
;
2848 yoffset
+= texImage
->Border
;
2850 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2852 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2853 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2854 xoffset
, yoffset
, x
, y
, width
, height
);
2857 ctx
->NewState
|= _NEW_TEXTURE
;
2860 _mesa_unlock_texture(ctx
, texObj
);
2866 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2867 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2868 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2870 struct gl_texture_unit
*texUnit
;
2871 struct gl_texture_object
*texObj
;
2872 struct gl_texture_image
*texImage
;
2873 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2874 GET_CURRENT_CONTEXT(ctx
);
2875 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2877 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2878 _mesa_update_state(ctx
);
2880 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2883 texUnit
= _mesa_get_current_tex_unit(ctx
);
2884 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2886 _mesa_lock_texture(ctx
, texObj
);
2888 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2890 #if FEATURE_convolve
2891 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2892 _mesa_adjust_image_for_convolution(ctx
, 2,
2893 &postConvWidth
, &postConvHeight
);
2897 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2898 zoffset
, postConvWidth
, postConvHeight
,
2902 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2903 xoffset
+= texImage
->Border
;
2904 yoffset
+= texImage
->Border
;
2905 zoffset
+= texImage
->Border
;
2907 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2909 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2910 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2911 xoffset
, yoffset
, zoffset
,
2912 x
, y
, width
, height
);
2915 ctx
->NewState
|= _NEW_TEXTURE
;
2918 _mesa_unlock_texture(ctx
, texObj
);
2924 /**********************************************************************/
2925 /****** Compressed Textures ******/
2926 /**********************************************************************/
2930 * Error checking for glCompressedTexImage[123]D().
2931 * \return error code or GL_NO_ERROR.
2934 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
2935 GLenum target
, GLint level
,
2936 GLenum internalFormat
, GLsizei width
,
2937 GLsizei height
, GLsizei depth
, GLint border
,
2940 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
2942 if (dimensions
== 1) {
2943 /* 1D compressed textures not allowed */
2944 return GL_INVALID_ENUM
;
2946 else if (dimensions
== 2) {
2947 if (target
== GL_PROXY_TEXTURE_2D
) {
2948 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2950 else if (target
== GL_TEXTURE_2D
) {
2951 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2953 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
2954 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2955 return GL_INVALID_ENUM
; /*target*/
2956 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2958 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2959 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2960 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2961 return GL_INVALID_ENUM
; /*target*/
2962 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2965 return GL_INVALID_ENUM
; /*target*/
2968 else if (dimensions
== 3) {
2969 /* 3D compressed textures not allowed */
2970 return GL_INVALID_ENUM
;
2973 maxTextureSize
= 1 << (maxLevels
- 1);
2975 /* This will detect any invalid internalFormat value */
2976 if (!is_compressed_format(ctx
, internalFormat
))
2977 return GL_INVALID_ENUM
;
2979 /* This should really never fail */
2980 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
2981 return GL_INVALID_ENUM
;
2984 return GL_INVALID_VALUE
;
2987 * XXX We should probably use the proxy texture error check function here.
2989 if (width
< 1 || width
> maxTextureSize
||
2990 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
2991 return GL_INVALID_VALUE
;
2993 if ((height
< 1 || height
> maxTextureSize
||
2994 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
2996 return GL_INVALID_VALUE
;
2998 if ((depth
< 1 || depth
> maxTextureSize
||
2999 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3001 return GL_INVALID_VALUE
;
3003 /* For cube map, width must equal height */
3004 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3005 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3006 return GL_INVALID_VALUE
;
3008 if (level
< 0 || level
>= maxLevels
)
3009 return GL_INVALID_VALUE
;
3011 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3012 depth
, internalFormat
);
3013 if (expectedSize
!= imageSize
)
3014 return GL_INVALID_VALUE
;
3016 #if FEATURE_EXT_texture_sRGB
3017 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3018 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3019 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3020 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3022 return GL_INVALID_OPERATION
;
3031 * Error checking for glCompressedTexSubImage[123]D().
3032 * \warning There are some bad assumptions here about the size of compressed
3033 * texture tiles (multiple of 4) used to test the validity of the
3034 * offset and size parameters.
3035 * \return error code or GL_NO_ERROR.
3038 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3039 GLenum target
, GLint level
,
3040 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3041 GLsizei width
, GLsizei height
, GLsizei depth
,
3042 GLenum format
, GLsizei imageSize
)
3044 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3047 if (dimensions
== 1) {
3048 /* 1D compressed textures not allowed */
3049 return GL_INVALID_ENUM
;
3051 else if (dimensions
== 2) {
3052 if (target
== GL_PROXY_TEXTURE_2D
) {
3053 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3055 else if (target
== GL_TEXTURE_2D
) {
3056 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3058 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3059 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3060 return GL_INVALID_ENUM
; /*target*/
3061 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3063 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3064 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3065 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3066 return GL_INVALID_ENUM
; /*target*/
3067 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3070 return GL_INVALID_ENUM
; /*target*/
3073 else if (dimensions
== 3) {
3074 /* 3D compressed textures not allowed */
3075 return GL_INVALID_ENUM
;
3078 maxTextureSize
= 1 << (maxLevels
- 1);
3080 /* this will catch any invalid compressed format token */
3081 if (!is_compressed_format(ctx
, format
))
3082 return GL_INVALID_ENUM
;
3084 if (width
< 1 || width
> maxTextureSize
)
3085 return GL_INVALID_VALUE
;
3087 if ((height
< 1 || height
> maxTextureSize
)
3089 return GL_INVALID_VALUE
;
3091 if (level
< 0 || level
>= maxLevels
)
3092 return GL_INVALID_VALUE
;
3094 /* XXX these tests are specific to the compressed format.
3095 * this code should be generalized in some way.
3097 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3098 return GL_INVALID_VALUE
;
3100 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3101 return GL_INVALID_VALUE
;
3103 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3104 return GL_INVALID_VALUE
;
3106 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3108 if (expectedSize
!= imageSize
)
3109 return GL_INVALID_VALUE
;
3117 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3118 GLenum internalFormat
, GLsizei width
,
3119 GLint border
, GLsizei imageSize
,
3122 GET_CURRENT_CONTEXT(ctx
);
3123 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3125 if (target
== GL_TEXTURE_1D
) {
3126 /* non-proxy target */
3127 struct gl_texture_unit
*texUnit
;
3128 struct gl_texture_object
*texObj
;
3129 struct gl_texture_image
*texImage
;
3130 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3131 internalFormat
, width
, 1, 1, border
, imageSize
);
3133 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3137 texUnit
= _mesa_get_current_tex_unit(ctx
);
3138 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3140 _mesa_lock_texture(ctx
, texObj
);
3142 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3144 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3148 if (texImage
->Data
) {
3149 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3151 ASSERT(texImage
->Data
== NULL
);
3153 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3154 border
, internalFormat
);
3156 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3157 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3158 internalFormat
, width
, border
,
3163 texObj
->_Complete
= GL_FALSE
;
3164 ctx
->NewState
|= _NEW_TEXTURE
;
3167 _mesa_unlock_texture(ctx
, texObj
);
3169 else if (target
== GL_PROXY_TEXTURE_1D
) {
3170 /* Proxy texture: check for errors and update proxy state */
3171 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3172 internalFormat
, width
, 1, 1, border
, imageSize
);
3174 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3175 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3176 internalFormat
, GL_NONE
, GL_NONE
,
3177 width
, 1, 1, border
);
3180 /* if error, clear all proxy texture image parameters */
3181 struct gl_texture_image
*texImage
;
3182 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3184 clear_teximage_fields(texImage
);
3187 /* store the teximage parameters */
3188 struct gl_texture_unit
*texUnit
;
3189 struct gl_texture_object
*texObj
;
3190 struct gl_texture_image
*texImage
;
3191 texUnit
= _mesa_get_current_tex_unit(ctx
);
3192 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3194 _mesa_lock_texture(ctx
, texObj
);
3196 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3197 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3198 border
, internalFormat
);
3200 _mesa_unlock_texture(ctx
, texObj
);
3204 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3211 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3212 GLenum internalFormat
, GLsizei width
,
3213 GLsizei height
, GLint border
, GLsizei imageSize
,
3216 GET_CURRENT_CONTEXT(ctx
);
3217 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3219 if (target
== GL_TEXTURE_2D
||
3220 (ctx
->Extensions
.ARB_texture_cube_map
&&
3221 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3222 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3223 /* non-proxy target */
3224 struct gl_texture_unit
*texUnit
;
3225 struct gl_texture_object
*texObj
;
3226 struct gl_texture_image
*texImage
;
3227 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3228 internalFormat
, width
, height
, 1, border
, imageSize
);
3230 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3234 texUnit
= _mesa_get_current_tex_unit(ctx
);
3235 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3237 _mesa_lock_texture(ctx
, texObj
);
3239 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3241 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3245 if (texImage
->Data
) {
3246 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3248 ASSERT(texImage
->Data
== NULL
);
3250 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3251 border
, internalFormat
);
3253 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3254 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3255 internalFormat
, width
, height
,
3256 border
, imageSize
, data
,
3260 texObj
->_Complete
= GL_FALSE
;
3261 ctx
->NewState
|= _NEW_TEXTURE
;
3264 _mesa_unlock_texture(ctx
, texObj
);
3266 else if (target
== GL_PROXY_TEXTURE_2D
||
3267 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3268 ctx
->Extensions
.ARB_texture_cube_map
)) {
3269 /* Proxy texture: check for errors and update proxy state */
3270 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3271 internalFormat
, width
, height
, 1, border
, imageSize
);
3273 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3274 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3275 internalFormat
, GL_NONE
, GL_NONE
,
3276 width
, height
, 1, border
);
3279 /* if error, clear all proxy texture image parameters */
3280 struct gl_texture_image
*texImage
;
3281 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3283 clear_teximage_fields(texImage
);
3286 /* store the teximage parameters */
3287 struct gl_texture_unit
*texUnit
;
3288 struct gl_texture_object
*texObj
;
3289 struct gl_texture_image
*texImage
;
3290 texUnit
= _mesa_get_current_tex_unit(ctx
);
3291 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3293 _mesa_lock_texture(ctx
, texObj
);
3295 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3296 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3297 border
, internalFormat
);
3299 _mesa_unlock_texture(ctx
, texObj
);
3303 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3310 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3311 GLenum internalFormat
, GLsizei width
,
3312 GLsizei height
, GLsizei depth
, GLint border
,
3313 GLsizei imageSize
, const GLvoid
*data
)
3315 GET_CURRENT_CONTEXT(ctx
);
3316 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3318 if (target
== GL_TEXTURE_3D
) {
3319 /* non-proxy target */
3320 struct gl_texture_unit
*texUnit
;
3321 struct gl_texture_object
*texObj
;
3322 struct gl_texture_image
*texImage
;
3323 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3324 internalFormat
, width
, height
, depth
, border
, imageSize
);
3326 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3330 texUnit
= _mesa_get_current_tex_unit(ctx
);
3331 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3332 _mesa_lock_texture(ctx
, texObj
);
3334 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3336 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3340 if (texImage
->Data
) {
3341 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3343 ASSERT(texImage
->Data
== NULL
);
3345 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3346 border
, internalFormat
);
3348 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3349 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3351 width
, height
, depth
,
3352 border
, imageSize
, data
,
3356 texObj
->_Complete
= GL_FALSE
;
3357 ctx
->NewState
|= _NEW_TEXTURE
;
3360 _mesa_unlock_texture(ctx
, texObj
);
3362 else if (target
== GL_PROXY_TEXTURE_3D
) {
3363 /* Proxy texture: check for errors and update proxy state */
3364 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3365 internalFormat
, width
, height
, depth
, border
, imageSize
);
3367 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3368 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3369 internalFormat
, GL_NONE
, GL_NONE
,
3370 width
, height
, depth
, border
);
3373 /* if error, clear all proxy texture image parameters */
3374 struct gl_texture_image
*texImage
;
3375 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3377 clear_teximage_fields(texImage
);
3380 /* store the teximage parameters */
3381 struct gl_texture_unit
*texUnit
;
3382 struct gl_texture_object
*texObj
;
3383 struct gl_texture_image
*texImage
;
3384 texUnit
= _mesa_get_current_tex_unit(ctx
);
3385 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3386 _mesa_lock_texture(ctx
, texObj
);
3388 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3389 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3390 depth
, border
, internalFormat
);
3392 _mesa_unlock_texture(ctx
, texObj
);
3396 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3403 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3404 GLsizei width
, GLenum format
,
3405 GLsizei imageSize
, const GLvoid
*data
)
3407 struct gl_texture_unit
*texUnit
;
3408 struct gl_texture_object
*texObj
;
3409 struct gl_texture_image
*texImage
;
3411 GET_CURRENT_CONTEXT(ctx
);
3412 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3414 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3415 xoffset
, 0, 0, /* pos */
3416 width
, 1, 1, /* size */
3419 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3423 texUnit
= _mesa_get_current_tex_unit(ctx
);
3424 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3425 _mesa_lock_texture(ctx
, texObj
);
3427 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3430 if ((GLint
) format
!= texImage
->InternalFormat
) {
3431 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3432 "glCompressedTexSubImage1D(format)");
3436 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3437 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3442 goto out
; /* no-op, not an error */
3444 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3445 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3447 format
, imageSize
, data
,
3450 ctx
->NewState
|= _NEW_TEXTURE
;
3453 _mesa_unlock_texture(ctx
, texObj
);
3458 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3459 GLint yoffset
, GLsizei width
, GLsizei height
,
3460 GLenum format
, GLsizei imageSize
,
3463 struct gl_texture_unit
*texUnit
;
3464 struct gl_texture_object
*texObj
;
3465 struct gl_texture_image
*texImage
;
3467 GET_CURRENT_CONTEXT(ctx
);
3468 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3470 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3471 xoffset
, yoffset
, 0, /* pos */
3472 width
, height
, 1, /* size */
3475 /* XXX proxy target? */
3476 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3480 texUnit
= _mesa_get_current_tex_unit(ctx
);
3481 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3482 _mesa_lock_texture(ctx
, texObj
);
3484 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3487 if ((GLint
) format
!= texImage
->InternalFormat
) {
3488 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3489 "glCompressedTexSubImage2D(format)");
3493 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3494 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3495 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3499 if (width
== 0 || height
== 0)
3500 goto out
; /* no-op, not an error */
3502 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3503 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3504 xoffset
, yoffset
, width
, height
,
3505 format
, imageSize
, data
,
3508 ctx
->NewState
|= _NEW_TEXTURE
;
3511 _mesa_unlock_texture(ctx
, texObj
);
3516 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3517 GLint yoffset
, GLint zoffset
, GLsizei width
,
3518 GLsizei height
, GLsizei depth
, GLenum format
,
3519 GLsizei imageSize
, const GLvoid
*data
)
3521 struct gl_texture_unit
*texUnit
;
3522 struct gl_texture_object
*texObj
;
3523 struct gl_texture_image
*texImage
;
3525 GET_CURRENT_CONTEXT(ctx
);
3526 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3528 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3529 xoffset
, yoffset
, zoffset
,/*pos*/
3530 width
, height
, depth
, /*size*/
3533 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3537 texUnit
= _mesa_get_current_tex_unit(ctx
);
3538 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3539 _mesa_lock_texture(ctx
, texObj
);
3541 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3544 if ((GLint
) format
!= texImage
->InternalFormat
) {
3545 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3546 "glCompressedTexSubImage3D(format)");
3550 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3551 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3552 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3553 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3557 if (width
== 0 || height
== 0 || depth
== 0)
3558 goto out
; /* no-op, not an error */
3560 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3561 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3562 xoffset
, yoffset
, zoffset
,
3563 width
, height
, depth
,
3564 format
, imageSize
, data
,
3567 ctx
->NewState
|= _NEW_TEXTURE
;
3570 _mesa_unlock_texture(ctx
, texObj
);