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 * Return pointer to current texture unit.
580 * This the texture unit set by glActiveTexture(), not glClientActiveTexture().
582 static INLINE
struct gl_texture_unit
*
583 get_current_tex_unit(GLcontext
*ctx
)
585 ASSERT(ctx
->Texture
.CurrentUnit
< Elements(ctx
->Texture
.Unit
));
586 return &(ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
]);
591 * Get the texture object that corresponds to the target of the given texture unit.
593 * \param ctx GL context.
594 * \param texUnit texture unit.
595 * \param target texture target.
597 * \return pointer to the texture object on success, or NULL on failure.
599 * \sa gl_texture_unit.
601 struct gl_texture_object
*
602 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
607 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
608 case GL_PROXY_TEXTURE_1D
:
609 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
611 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
612 case GL_PROXY_TEXTURE_2D
:
613 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
615 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
616 case GL_PROXY_TEXTURE_3D
:
617 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
618 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
619 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
620 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
621 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
622 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
623 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
624 case GL_TEXTURE_CUBE_MAP_ARB
:
625 return ctx
->Extensions
.ARB_texture_cube_map
626 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
627 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
628 return ctx
->Extensions
.ARB_texture_cube_map
629 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
630 case GL_TEXTURE_RECTANGLE_NV
:
631 return ctx
->Extensions
.NV_texture_rectangle
632 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
633 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
634 return ctx
->Extensions
.NV_texture_rectangle
635 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
636 case GL_TEXTURE_1D_ARRAY_EXT
:
637 return ctx
->Extensions
.MESA_texture_array
638 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
639 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
640 return ctx
->Extensions
.MESA_texture_array
641 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
642 case GL_TEXTURE_2D_ARRAY_EXT
:
643 return ctx
->Extensions
.MESA_texture_array
644 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
645 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
646 return ctx
->Extensions
.MESA_texture_array
647 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
649 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
656 * Get a texture image pointer from a texture object, given a texture
657 * target and mipmap level. The target and level parameters should
658 * have already been error-checked.
660 * \param ctx GL context.
661 * \param texObj texture unit.
662 * \param target texture target.
663 * \param level image level.
665 * \return pointer to the texture image structure, or NULL on failure.
667 struct gl_texture_image
*
668 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
669 GLenum target
, GLint level
)
671 const GLuint face
= _mesa_tex_target_to_face(target
);
675 ASSERT(level
< MAX_TEXTURE_LEVELS
);
677 return texObj
->Image
[face
][level
];
682 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
683 * it and install it. Only return NULL if passed a bad parameter or run
686 struct gl_texture_image
*
687 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
688 GLenum target
, GLint level
)
690 struct gl_texture_image
*texImage
;
695 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
697 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
699 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
703 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
711 * Return pointer to the specified proxy texture image.
712 * Note that proxy textures are per-context, not per-texture unit.
713 * \return pointer to texture image or NULL if invalid target, invalid
714 * level, or out of memory.
716 struct gl_texture_image
*
717 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
719 struct gl_texture_image
*texImage
;
726 case GL_PROXY_TEXTURE_1D
:
727 if (level
>= ctx
->Const
.MaxTextureLevels
)
729 texIndex
= TEXTURE_1D_INDEX
;
731 case GL_PROXY_TEXTURE_2D
:
732 if (level
>= ctx
->Const
.MaxTextureLevels
)
734 texIndex
= TEXTURE_2D_INDEX
;
736 case GL_PROXY_TEXTURE_3D
:
737 if (level
>= ctx
->Const
.Max3DTextureLevels
)
739 texIndex
= TEXTURE_3D_INDEX
;
741 case GL_PROXY_TEXTURE_CUBE_MAP
:
742 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
744 texIndex
= TEXTURE_CUBE_INDEX
;
746 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
749 texIndex
= TEXTURE_RECT_INDEX
;
751 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
752 if (level
>= ctx
->Const
.MaxTextureLevels
)
754 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
756 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
757 if (level
>= ctx
->Const
.MaxTextureLevels
)
759 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
765 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
767 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
769 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
772 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
773 /* Set the 'back' pointer */
774 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
781 * Get the maximum number of allowed mipmap levels.
783 * \param ctx GL context.
784 * \param target texture target.
786 * \return the maximum number of allowed mipmap levels for the given
787 * texture target, or zero if passed a bad target.
792 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
796 case GL_PROXY_TEXTURE_1D
:
798 case GL_PROXY_TEXTURE_2D
:
799 case GL_TEXTURE_1D_ARRAY_EXT
:
800 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
801 case GL_TEXTURE_2D_ARRAY_EXT
:
802 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
803 return ctx
->Const
.MaxTextureLevels
;
805 case GL_PROXY_TEXTURE_3D
:
806 return ctx
->Const
.Max3DTextureLevels
;
807 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
808 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
809 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
810 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
811 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
812 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
813 case GL_TEXTURE_CUBE_MAP_ARB
:
814 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
815 return ctx
->Const
.MaxCubeTextureLevels
;
816 case GL_TEXTURE_RECTANGLE_NV
:
817 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
820 return 0; /* bad target */
826 #if 000 /* not used anymore */
828 * glTexImage[123]D can accept a NULL image pointer. In this case we
829 * create a texture image with unspecified image contents per the OpenGL
833 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
835 const GLint components
= _mesa_components_in_format(format
);
836 const GLint numPixels
= width
* height
* depth
;
837 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
841 * Let's see if anyone finds this. If glTexImage2D() is called with
842 * a NULL image pointer then load the texture image with something
843 * interesting instead of leaving it indeterminate.
846 static const char message
[8][32] = {
850 " X X XXXX XXX XXXXX ",
853 " X X XXXXX XXX X X ",
857 GLubyte
*imgPtr
= data
;
859 for (h
= 0; h
< depth
; h
++) {
860 for (i
= 0; i
< height
; i
++) {
861 GLint srcRow
= 7 - (i
% 8);
862 for (j
= 0; j
< width
; j
++) {
863 GLint srcCol
= j
% 32;
864 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
865 for (k
= 0; k
< components
; k
++) {
881 * Reset the fields of a gl_texture_image struct to zero.
883 * \param img texture image structure.
885 * This is called when a proxy texture test fails, we set all the
886 * image members (except DriverData) to zero.
887 * It's also used in glTexImage[123]D as a safeguard to be sure all
888 * required fields get initialized properly by the Driver.TexImage[123]D
892 clear_teximage_fields(struct gl_texture_image
*img
)
895 img
->_BaseFormat
= 0;
896 img
->InternalFormat
= 0;
902 if (img
->ImageOffsets
) {
903 _mesa_free(img
->ImageOffsets
);
904 img
->ImageOffsets
= NULL
;
913 img
->TexFormat
= &_mesa_null_texformat
;
914 img
->FetchTexelc
= NULL
;
915 img
->FetchTexelf
= NULL
;
916 img
->IsCompressed
= 0;
917 img
->CompressedSize
= 0;
922 * Initialize basic fields of the gl_texture_image struct.
924 * \param ctx GL context.
925 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
926 * \param img texture image structure to be initialized.
927 * \param width image width.
928 * \param height image height.
929 * \param depth image depth.
930 * \param border image border.
931 * \param internalFormat internal format.
933 * Fills in the fields of \p img with the given information.
934 * Note: width, height and depth include the border.
937 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
938 struct gl_texture_image
*img
,
939 GLsizei width
, GLsizei height
, GLsizei depth
,
940 GLint border
, GLenum internalFormat
)
949 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
950 ASSERT(img
->_BaseFormat
> 0);
951 img
->InternalFormat
= internalFormat
;
952 img
->Border
= border
;
954 img
->Height
= height
;
957 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
958 img
->WidthLog2
= logbase2(img
->Width2
);
960 if (height
== 1) { /* 1-D texture */
965 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
966 img
->HeightLog2
= logbase2(img
->Height2
);
969 if (depth
== 1) { /* 2-D texture */
974 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
975 img
->DepthLog2
= logbase2(img
->Depth2
);
978 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
980 img
->IsCompressed
= GL_FALSE
;
981 img
->CompressedSize
= 0;
983 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
984 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
985 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
986 img
->_IsPowerOfTwo
= GL_TRUE
;
988 img
->_IsPowerOfTwo
= GL_FALSE
;
990 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
991 img
->RowStride
= width
;
992 /* Allocate the ImageOffsets array and initialize to typical values.
993 * We allocate the array for 1D/2D textures too in order to avoid special-
994 * case code in the texstore routines.
996 if (img
->ImageOffsets
)
997 _mesa_free(img
->ImageOffsets
);
998 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
999 for (i
= 0; i
< depth
; i
++) {
1000 img
->ImageOffsets
[i
] = i
* width
* height
;
1003 /* Compute Width/Height/DepthScale for mipmap lod computation */
1004 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1005 /* scale = 1.0 since texture coords directly map to texels */
1006 img
->WidthScale
= 1.0;
1007 img
->HeightScale
= 1.0;
1008 img
->DepthScale
= 1.0;
1011 img
->WidthScale
= (GLfloat
) img
->Width
;
1012 img
->HeightScale
= (GLfloat
) img
->Height
;
1013 img
->DepthScale
= (GLfloat
) img
->Depth
;
1019 * Free and clear fields of the gl_texture_image struct.
1021 * \param ctx GL context.
1022 * \param texImage texture image structure to be cleared.
1024 * After the call, \p texImage will have no data associated with it. Its
1025 * fields are cleared so that its parent object will test incomplete.
1028 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
1030 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1031 clear_teximage_fields(texImage
);
1036 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1037 * level, width, height and depth against the ctx->Const limits for textures.
1039 * A hardware driver might override this function if, for example, the
1040 * max 3D texture size is 512x512x64 (i.e. not a cube).
1042 * Note that width, height, depth == 0 is not an error. However, a
1043 * texture with zero width/height/depth will be considered "incomplete"
1044 * and texturing will effectively be disabled.
1046 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1047 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1048 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1049 * \param level as passed to glTexImage
1050 * \param internalFormat as passed to glTexImage
1051 * \param format as passed to glTexImage
1052 * \param type as passed to glTexImage
1053 * \param width as passed to glTexImage
1054 * \param height as passed to glTexImage
1055 * \param depth as passed to glTexImage
1056 * \param border as passed to glTexImage
1057 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1060 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1061 GLint internalFormat
, GLenum format
, GLenum type
,
1062 GLint width
, GLint height
, GLint depth
, GLint border
)
1066 (void) internalFormat
;
1071 case GL_PROXY_TEXTURE_1D
:
1072 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1073 if (width
< 2 * border
|| width
> 2 + maxSize
||
1074 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1075 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1076 level
>= ctx
->Const
.MaxTextureLevels
) {
1077 /* bad width or level */
1081 case GL_PROXY_TEXTURE_2D
:
1082 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1083 if (width
< 2 * border
|| width
> 2 + maxSize
||
1084 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1085 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1086 height
< 2 * border
|| height
> 2 + maxSize
||
1087 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1088 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1089 level
>= ctx
->Const
.MaxTextureLevels
) {
1090 /* bad width or height or level */
1094 case GL_PROXY_TEXTURE_3D
:
1095 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1096 if (width
< 2 * border
|| width
> 2 + maxSize
||
1097 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1098 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1099 height
< 2 * border
|| height
> 2 + maxSize
||
1100 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1101 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1102 depth
< 2 * border
|| depth
> 2 + maxSize
||
1103 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1104 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1105 level
>= ctx
->Const
.Max3DTextureLevels
) {
1106 /* bad width or height or depth or level */
1110 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1111 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1112 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1114 /* bad width or height or level */
1118 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1119 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1120 if (width
< 2 * border
|| width
> 2 + maxSize
||
1121 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1122 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1123 height
< 2 * border
|| height
> 2 + maxSize
||
1124 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1125 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1126 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1127 /* bad width or height */
1131 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1132 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1133 if (width
< 2 * border
|| width
> 2 + maxSize
||
1134 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1135 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1136 level
>= ctx
->Const
.MaxTextureLevels
) {
1137 /* bad width or level */
1141 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1145 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1146 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1147 if (width
< 2 * border
|| width
> 2 + maxSize
||
1148 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1149 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1150 height
< 2 * border
|| height
> 2 + maxSize
||
1151 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1152 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1153 level
>= ctx
->Const
.MaxTextureLevels
) {
1154 /* bad width or height or level */
1157 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1162 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1169 * Helper function to determine whether a target supports compressed textures
1172 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1174 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1175 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1176 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1177 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1178 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1179 || ((ctx
->Extensions
.MESA_texture_array
&&
1180 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1181 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1186 * Test the glTexImage[123]D() parameters for errors.
1188 * \param ctx GL context.
1189 * \param target texture target given by the user.
1190 * \param level image level given by the user.
1191 * \param internalFormat internal format given by the user.
1192 * \param format pixel data format given by the user.
1193 * \param type pixel data type given by the user.
1194 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1195 * \param width image width given by the user.
1196 * \param height image height given by the user.
1197 * \param depth image depth given by the user.
1198 * \param border image border given by the user.
1200 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1202 * Verifies each of the parameters against the constants specified in
1203 * __GLcontextRec::Const and the supported extensions, and according to the
1204 * OpenGL specification.
1207 texture_error_check( GLcontext
*ctx
, GLenum target
,
1208 GLint level
, GLint internalFormat
,
1209 GLenum format
, GLenum type
,
1211 GLint width
, GLint height
,
1212 GLint depth
, GLint border
)
1214 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1215 GLboolean sizeOK
= GL_TRUE
;
1216 GLboolean colorFormat
, indexFormat
;
1217 GLenum proxy_target
;
1219 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1220 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1222 _mesa_error(ctx
, GL_INVALID_VALUE
,
1223 "glTexImage%dD(level=%d)", dimensions
, level
);
1229 if (border
< 0 || border
> 1 ||
1230 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1231 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1233 _mesa_error(ctx
, GL_INVALID_VALUE
,
1234 "glTexImage%dD(border=%d)", dimensions
, border
);
1239 if (width
< 0 || height
< 0 || depth
< 0) {
1241 _mesa_error(ctx
, GL_INVALID_VALUE
,
1242 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1247 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1248 * level, width, height and depth.
1250 if (dimensions
== 1) {
1251 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1252 proxy_target
= GL_PROXY_TEXTURE_1D
;
1257 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1261 else if (dimensions
== 2) {
1263 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1264 proxy_target
= GL_PROXY_TEXTURE_2D
;
1266 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1267 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1268 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1269 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1270 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1273 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1274 sizeOK
= (width
== height
);
1276 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1277 target
== GL_TEXTURE_RECTANGLE_NV
) {
1278 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1279 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1282 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1284 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1285 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1286 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1289 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1293 else if (dimensions
== 3) {
1294 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1295 proxy_target
= GL_PROXY_TEXTURE_3D
;
1297 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1298 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1299 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1302 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1307 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1311 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1312 internalFormat
, format
,
1313 type
, width
, height
,
1317 _mesa_error(ctx
, GL_INVALID_VALUE
,
1318 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1319 dimensions
, level
, width
, height
, depth
);
1324 /* Check internalFormat */
1325 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1327 _mesa_error(ctx
, GL_INVALID_VALUE
,
1328 "glTexImage%dD(internalFormat=0x%x)",
1329 dimensions
, internalFormat
);
1334 /* Check incoming image format and type */
1335 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1336 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1337 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1340 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1341 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1342 dimensions
, format
, type
);
1347 /* make sure internal format and format basically agree */
1348 colorFormat
= _mesa_is_color_format(format
);
1349 indexFormat
= _mesa_is_index_format(format
);
1350 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1351 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1352 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1353 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1354 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1355 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1357 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1358 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1359 dimensions
, internalFormat
, format
);
1363 /* additional checks for ycbcr textures */
1364 if (internalFormat
== GL_YCBCR_MESA
) {
1365 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1366 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1367 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1369 _mesa_sprintf(message
,
1370 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1371 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1372 return GL_TRUE
; /* error */
1374 if (target
!= GL_TEXTURE_2D
&&
1375 target
!= GL_PROXY_TEXTURE_2D
&&
1376 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1377 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1379 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1385 _mesa_sprintf(message
,
1386 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1387 dimensions
, border
);
1388 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1394 /* additional checks for depth textures */
1395 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1396 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1397 if (target
!= GL_TEXTURE_1D
&&
1398 target
!= GL_PROXY_TEXTURE_1D
&&
1399 target
!= GL_TEXTURE_2D
&&
1400 target
!= GL_PROXY_TEXTURE_2D
&&
1401 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1402 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1404 _mesa_error(ctx
, GL_INVALID_ENUM
,
1405 "glTexImage(target/internalFormat)");
1410 /* additional checks for compressed textures */
1411 if (is_compressed_format(ctx
, internalFormat
)) {
1412 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1413 _mesa_error(ctx
, GL_INVALID_ENUM
,
1414 "glTexImage%d(target)", dimensions
);
1419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1420 "glTexImage%D(border!=0)", dimensions
);
1426 /* if we get here, the parameters are OK */
1432 * Test glTexSubImage[123]D() parameters for errors.
1434 * \param ctx GL context.
1435 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1436 * \param target texture target given by the user.
1437 * \param level image level given by the user.
1438 * \param xoffset sub-image x offset given by the user.
1439 * \param yoffset sub-image y offset given by the user.
1440 * \param zoffset sub-image z offset given by the user.
1441 * \param format pixel data format given by the user.
1442 * \param type pixel data type given by the user.
1443 * \param width image width given by the user.
1444 * \param height image height given by the user.
1445 * \param depth image depth given by the user.
1447 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1449 * Verifies each of the parameters against the constants specified in
1450 * __GLcontextRec::Const and the supported extensions, and according to the
1451 * OpenGL specification.
1454 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1455 GLenum target
, GLint level
,
1456 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1457 GLint width
, GLint height
, GLint depth
,
1458 GLenum format
, GLenum type
)
1461 if (dimensions
== 1) {
1462 if (target
!= GL_TEXTURE_1D
) {
1463 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1467 else if (dimensions
== 2) {
1468 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1469 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1470 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1471 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1475 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1476 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1477 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1481 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1482 if (!ctx
->Extensions
.MESA_texture_array
) {
1483 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1487 else if (target
!= GL_TEXTURE_2D
) {
1488 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1492 else if (dimensions
== 3) {
1493 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1494 if (!ctx
->Extensions
.MESA_texture_array
) {
1495 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1499 else if (target
!= GL_TEXTURE_3D
) {
1500 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1505 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1509 /* Basic level check */
1510 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1511 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1516 _mesa_error(ctx
, GL_INVALID_VALUE
,
1517 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1520 if (height
< 0 && dimensions
> 1) {
1521 _mesa_error(ctx
, GL_INVALID_VALUE
,
1522 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1525 if (depth
< 0 && dimensions
> 2) {
1526 _mesa_error(ctx
, GL_INVALID_VALUE
,
1527 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1531 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1532 _mesa_error(ctx
, GL_INVALID_ENUM
,
1533 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1534 dimensions
, format
, type
);
1542 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1543 GLenum target
, GLint level
,
1544 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1545 GLint width
, GLint height
, GLint depth
,
1546 GLenum format
, GLenum type
,
1547 const struct gl_texture_image
*destTex
)
1550 /* undefined image level */
1551 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1555 if (xoffset
< -((GLint
)destTex
->Border
)) {
1556 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1560 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1561 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1565 if (dimensions
> 1) {
1566 if (yoffset
< -((GLint
)destTex
->Border
)) {
1567 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1571 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1572 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1577 if (dimensions
> 2) {
1578 if (zoffset
< -((GLint
)destTex
->Border
)) {
1579 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1582 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1583 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1588 #if FEATURE_EXT_texture_sRGB
1589 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1590 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1591 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1592 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1593 if ((width
& 0x3) || (height
& 0x3) ||
1594 (xoffset
& 0x3) || (yoffset
& 0x3))
1595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1596 "glTexSubImage%dD(size or offset not multiple of 4)",
1602 if (destTex
->IsCompressed
) {
1603 if (!target_can_be_compressed(ctx
, target
)) {
1604 _mesa_error(ctx
, GL_INVALID_ENUM
,
1605 "glTexSubImage%D(target)", dimensions
);
1608 /* offset must be multiple of 4 */
1609 if ((xoffset
& 3) || (yoffset
& 3)) {
1610 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1611 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1614 /* size must be multiple of 4 or equal to whole texture size */
1615 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1616 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1617 "glTexSubImage%D(width)", dimensions
);
1620 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1621 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1622 "glTexSubImage%D(width)", dimensions
);
1632 * Test glCopyTexImage[12]D() parameters for errors.
1634 * \param ctx GL context.
1635 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1636 * \param target texture target given by the user.
1637 * \param level image level given by the user.
1638 * \param internalFormat internal format given by the user.
1639 * \param width image width given by the user.
1640 * \param height image height given by the user.
1641 * \param border texture border.
1643 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1645 * Verifies each of the parameters against the constants specified in
1646 * __GLcontextRec::Const and the supported extensions, and according to the
1647 * OpenGL specification.
1650 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1651 GLenum target
, GLint level
, GLint internalFormat
,
1652 GLint width
, GLint height
, GLint border
)
1658 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1659 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1660 _mesa_error(ctx
, GL_INVALID_VALUE
,
1661 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1665 /* Check that the source buffer is complete */
1666 if (ctx
->ReadBuffer
->Name
) {
1667 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1668 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1669 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1670 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1676 if (border
< 0 || border
> 1 ||
1677 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1678 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1682 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1684 _mesa_error(ctx
, GL_INVALID_VALUE
,
1685 "glCopyTexImage%dD(internalFormat)", dimensions
);
1689 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1690 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1691 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1695 /* NOTE: the format and type aren't really significant for
1696 * TestProxyTexImage(). Only the internalformat really matters.
1700 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1701 * level, width, height and depth.
1703 if (dimensions
== 1) {
1704 if (target
== GL_TEXTURE_1D
) {
1705 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1706 level
, internalFormat
,
1708 width
, 1, 1, border
);
1711 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1715 else if (dimensions
== 2) {
1716 if (target
== GL_TEXTURE_2D
) {
1717 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1718 level
, internalFormat
,
1720 width
, height
, 1, border
);
1722 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1723 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1724 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1725 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1728 sizeOK
= (width
== height
) &&
1729 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1730 level
, internalFormat
, format
, type
,
1731 width
, height
, 1, border
);
1733 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1734 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1735 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1738 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1739 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1740 level
, internalFormat
,
1742 width
, height
, 1, border
);
1744 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1745 if (!ctx
->Extensions
.MESA_texture_array
) {
1746 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1749 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1750 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1751 level
, internalFormat
,
1753 width
, height
, 1, border
);
1756 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1761 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1766 if (dimensions
== 1) {
1767 _mesa_error(ctx
, GL_INVALID_VALUE
,
1768 "glCopyTexImage1D(width=%d)", width
);
1771 ASSERT(dimensions
== 2);
1772 _mesa_error(ctx
, GL_INVALID_VALUE
,
1773 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1778 if (is_compressed_format(ctx
, internalFormat
)) {
1779 if (!target_can_be_compressed(ctx
, target
)) {
1780 _mesa_error(ctx
, GL_INVALID_ENUM
,
1781 "glCopyTexImage%d(target)", dimensions
);
1785 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1786 "glCopyTexImage%D(border!=0)", dimensions
);
1790 else if (_mesa_is_depth_format(internalFormat
)) {
1791 /* make sure we have depth/stencil buffers */
1792 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1793 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1794 "glCopyTexImage%D(no depth)", dimensions
);
1798 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1799 /* make sure we have depth/stencil buffers */
1800 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1801 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1802 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
1807 /* if we get here, the parameters are OK */
1813 * Test glCopyTexSubImage[12]D() parameters for errors.
1814 * Note that this is the first part of error checking.
1815 * See also copytexsubimage_error_check2() below for the second part.
1817 * \param ctx GL context.
1818 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1819 * \param target texture target given by the user.
1820 * \param level image level given by the user.
1822 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1825 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1826 GLenum target
, GLint level
)
1828 /* Check that the source buffer is complete */
1829 if (ctx
->ReadBuffer
->Name
) {
1830 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1831 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1832 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1833 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1839 if (dimensions
== 1) {
1840 if (target
!= GL_TEXTURE_1D
) {
1841 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1845 else if (dimensions
== 2) {
1846 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1847 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1848 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1849 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1853 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1854 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1855 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1859 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1860 if (!ctx
->Extensions
.MESA_texture_array
) {
1861 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1865 else if (target
!= GL_TEXTURE_2D
) {
1866 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1870 else if (dimensions
== 3) {
1871 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1872 (!ctx
->Extensions
.MESA_texture_array
))
1873 && (target
!= GL_TEXTURE_3D
)) {
1874 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1880 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1881 _mesa_error(ctx
, GL_INVALID_VALUE
,
1882 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1891 * Second part of error checking for glCopyTexSubImage[12]D().
1892 * \param xoffset sub-image x offset given by the user.
1893 * \param yoffset sub-image y offset given by the user.
1894 * \param zoffset sub-image z offset given by the user.
1895 * \param width image width given by the user.
1896 * \param height image height given by the user.
1899 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1900 GLenum target
, GLint level
,
1901 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1902 GLsizei width
, GLsizei height
,
1903 const struct gl_texture_image
*teximage
)
1905 /* check that dest tex image exists */
1907 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1908 "glCopyTexSubImage%dD(undefined texture level: %d)",
1915 _mesa_error(ctx
, GL_INVALID_VALUE
,
1916 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1919 if (dimensions
> 1 && height
< 0) {
1920 _mesa_error(ctx
, GL_INVALID_VALUE
,
1921 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1925 /* check x/y offsets */
1926 if (xoffset
< -((GLint
)teximage
->Border
)) {
1927 _mesa_error(ctx
, GL_INVALID_VALUE
,
1928 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1931 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1932 _mesa_error(ctx
, GL_INVALID_VALUE
,
1933 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1936 if (dimensions
> 1) {
1937 if (yoffset
< -((GLint
)teximage
->Border
)) {
1938 _mesa_error(ctx
, GL_INVALID_VALUE
,
1939 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1942 /* NOTE: we're adding the border here, not subtracting! */
1943 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1944 _mesa_error(ctx
, GL_INVALID_VALUE
,
1945 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1950 /* check z offset */
1951 if (dimensions
> 2) {
1952 if (zoffset
< -((GLint
)teximage
->Border
)) {
1953 _mesa_error(ctx
, GL_INVALID_VALUE
,
1954 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1957 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1958 _mesa_error(ctx
, GL_INVALID_VALUE
,
1959 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1964 if (teximage
->IsCompressed
) {
1965 if (!target_can_be_compressed(ctx
, target
)) {
1966 _mesa_error(ctx
, GL_INVALID_ENUM
,
1967 "glCopyTexSubImage%d(target)", dimensions
);
1970 /* offset must be multiple of 4 */
1971 if ((xoffset
& 3) || (yoffset
& 3)) {
1972 _mesa_error(ctx
, GL_INVALID_VALUE
,
1973 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
1976 /* size must be multiple of 4 */
1977 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1978 _mesa_error(ctx
, GL_INVALID_VALUE
,
1979 "glCopyTexSubImage%D(width)", dimensions
);
1982 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1983 _mesa_error(ctx
, GL_INVALID_VALUE
,
1984 "glCopyTexSubImage%D(height)", dimensions
);
1989 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
1990 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1994 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
1995 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1996 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
1997 dimensions
, teximage
->_BaseFormat
);
2001 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2002 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2003 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2004 "glCopyTexSubImage%D(no depth buffer)",
2009 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2010 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2011 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2012 "glCopyTexSubImage%D(no depth/stencil buffer)",
2018 /* if we get here, the parameters are OK */
2023 /** Callback info for walking over FBO hash table */
2027 struct gl_texture_object
*texObj
;
2033 * Check render to texture callback. Called from _mesa_HashWalk().
2036 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2038 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2039 const struct cb_info
*info
= (struct cb_info
*) userData
;
2040 GLcontext
*ctx
= info
->ctx
;
2041 const struct gl_texture_object
*texObj
= info
->texObj
;
2042 const GLuint level
= info
->level
, face
= info
->face
;
2044 /* If this is a user-created FBO */
2047 /* check if any of the FBO's attachments point to 'texObj' */
2048 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2049 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2050 if (att
->Type
== GL_TEXTURE
&&
2051 att
->Texture
== texObj
&&
2052 att
->TextureLevel
== level
&&
2053 att
->CubeMapFace
== face
) {
2054 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2055 /* Tell driver about the new renderbuffer texture */
2056 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2057 /* Mark fb status as indeterminate to force re-validation */
2066 * When a texture image is specified we have to check if it's bound to
2067 * any framebuffer objects (render to texture) in order to detect changes
2068 * in size or format since that effects FBO completeness.
2069 * Any FBOs rendering into the texture must be re-validated.
2072 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2073 GLuint face
, GLuint level
)
2075 /* Only check this texture if it's been marked as RenderToTexture */
2076 if (texObj
->_RenderToTexture
) {
2077 struct cb_info info
;
2079 info
.texObj
= texObj
;
2082 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2087 /** Debug helper: override the user-requested internal format */
2089 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2092 if (internalFormat
== GL_RGBA16F_ARB
||
2093 internalFormat
== GL_RGBA32F_ARB
) {
2094 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2097 else if (internalFormat
== GL_RGB16F_ARB
||
2098 internalFormat
== GL_RGB32F_ARB
) {
2099 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2102 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2103 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2104 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2105 return GL_LUMINANCE_ALPHA
;
2107 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2108 internalFormat
== GL_LUMINANCE32F_ARB
) {
2109 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2110 return GL_LUMINANCE
;
2112 else if (internalFormat
== GL_ALPHA16F_ARB
||
2113 internalFormat
== GL_ALPHA32F_ARB
) {
2114 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2118 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2119 internalFormat = GL_RGBA;
2123 return internalFormat
;
2126 return internalFormat
;
2132 * Called from the API. Note that width includes the border.
2135 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2136 GLsizei width
, GLint border
, GLenum format
,
2137 GLenum type
, const GLvoid
*pixels
)
2139 GLsizei postConvWidth
= width
;
2140 GET_CURRENT_CONTEXT(ctx
);
2141 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2143 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2145 #if FEATURE_convolve
2146 if (_mesa_is_color_format(internalFormat
)) {
2147 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2151 if (target
== GL_TEXTURE_1D
) {
2152 /* non-proxy target */
2153 struct gl_texture_unit
*texUnit
;
2154 struct gl_texture_object
*texObj
;
2155 struct gl_texture_image
*texImage
;
2156 const GLuint face
= _mesa_tex_target_to_face(target
);
2158 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2159 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2160 return; /* error was recorded */
2163 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2164 _mesa_update_state(ctx
);
2166 texUnit
= get_current_tex_unit(ctx
);
2167 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2168 _mesa_lock_texture(ctx
, texObj
);
2170 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2172 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2176 if (texImage
->Data
) {
2177 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2180 ASSERT(texImage
->Data
== NULL
);
2182 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2183 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2184 postConvWidth
, 1, 1,
2185 border
, internalFormat
);
2187 ASSERT(ctx
->Driver
.TexImage1D
);
2189 /* Give the texture to the driver! <pixels> may be null! */
2190 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2191 width
, border
, format
, type
, pixels
,
2192 &ctx
->Unpack
, texObj
, texImage
);
2194 ASSERT(texImage
->TexFormat
);
2196 update_fbo_texture(ctx
, texObj
, face
, level
);
2199 texObj
->_Complete
= GL_FALSE
;
2200 ctx
->NewState
|= _NEW_TEXTURE
;
2203 _mesa_unlock_texture(ctx
, texObj
);
2205 else if (target
== GL_PROXY_TEXTURE_1D
) {
2206 /* Proxy texture: check for errors and update proxy state */
2207 struct gl_texture_image
*texImage
;
2208 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2209 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2210 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2211 /* when error, clear all proxy texture image parameters */
2213 clear_teximage_fields(texImage
);
2216 /* no error, set the tex image parameters */
2218 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2219 postConvWidth
, 1, 1,
2220 border
, internalFormat
);
2221 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2222 internalFormat
, format
, type
);
2226 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2233 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2234 GLsizei width
, GLsizei height
, GLint border
,
2235 GLenum format
, GLenum type
,
2236 const GLvoid
*pixels
)
2238 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2239 GET_CURRENT_CONTEXT(ctx
);
2240 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2242 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2244 #if FEATURE_convolve
2245 if (_mesa_is_color_format(internalFormat
)) {
2246 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2251 if (target
== GL_TEXTURE_2D
||
2252 (ctx
->Extensions
.ARB_texture_cube_map
&&
2253 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2254 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2255 (ctx
->Extensions
.NV_texture_rectangle
&&
2256 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2257 (ctx
->Extensions
.MESA_texture_array
&&
2258 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2259 /* non-proxy target */
2260 struct gl_texture_unit
*texUnit
;
2261 struct gl_texture_object
*texObj
;
2262 struct gl_texture_image
*texImage
;
2263 const GLuint face
= _mesa_tex_target_to_face(target
);
2265 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2266 format
, type
, 2, postConvWidth
, postConvHeight
,
2268 return; /* error was recorded */
2271 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2272 _mesa_update_state(ctx
);
2274 texUnit
= get_current_tex_unit(ctx
);
2275 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2276 _mesa_lock_texture(ctx
, texObj
);
2278 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2280 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2284 if (texImage
->Data
) {
2285 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2288 ASSERT(texImage
->Data
== NULL
);
2289 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2290 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2291 postConvWidth
, postConvHeight
, 1,
2292 border
, internalFormat
);
2294 ASSERT(ctx
->Driver
.TexImage2D
);
2296 /* Give the texture to the driver! <pixels> may be null! */
2297 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2298 width
, height
, border
, format
, type
, pixels
,
2299 &ctx
->Unpack
, texObj
, texImage
);
2301 ASSERT(texImage
->TexFormat
);
2303 update_fbo_texture(ctx
, texObj
, face
, level
);
2306 texObj
->_Complete
= GL_FALSE
;
2307 ctx
->NewState
|= _NEW_TEXTURE
;
2310 _mesa_unlock_texture(ctx
, texObj
);
2312 else if (target
== GL_PROXY_TEXTURE_2D
||
2313 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2314 ctx
->Extensions
.ARB_texture_cube_map
) ||
2315 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2316 ctx
->Extensions
.NV_texture_rectangle
) ||
2317 (ctx
->Extensions
.MESA_texture_array
&&
2318 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2319 /* Proxy texture: check for errors and update proxy state */
2320 struct gl_texture_image
*texImage
;
2321 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2322 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2323 format
, type
, 2, postConvWidth
, postConvHeight
,
2325 /* when error, clear all proxy texture image parameters */
2327 clear_teximage_fields(texImage
);
2330 /* no error, set the tex image parameters */
2331 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2332 postConvWidth
, postConvHeight
, 1,
2333 border
, internalFormat
);
2334 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2335 internalFormat
, format
, type
);
2339 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2346 * Called by the API or display list executor.
2347 * Note that width and height include the border.
2350 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2351 GLsizei width
, GLsizei height
, GLsizei depth
,
2352 GLint border
, GLenum format
, GLenum type
,
2353 const GLvoid
*pixels
)
2355 GET_CURRENT_CONTEXT(ctx
);
2356 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2358 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2360 if (target
== GL_TEXTURE_3D
||
2361 (ctx
->Extensions
.MESA_texture_array
&&
2362 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2363 /* non-proxy target */
2364 struct gl_texture_unit
*texUnit
;
2365 struct gl_texture_object
*texObj
;
2366 struct gl_texture_image
*texImage
;
2367 const GLuint face
= _mesa_tex_target_to_face(target
);
2369 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2370 format
, type
, 3, width
, height
, depth
, border
)) {
2371 return; /* error was recorded */
2374 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2375 _mesa_update_state(ctx
);
2377 texUnit
= get_current_tex_unit(ctx
);
2378 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2379 _mesa_lock_texture(ctx
, texObj
);
2381 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2383 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2387 if (texImage
->Data
) {
2388 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2391 ASSERT(texImage
->Data
== NULL
);
2392 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2393 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2394 width
, height
, depth
,
2395 border
, internalFormat
);
2397 ASSERT(ctx
->Driver
.TexImage3D
);
2399 /* Give the texture to the driver! <pixels> may be null! */
2400 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2401 width
, height
, depth
, border
, format
, type
,
2402 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2404 ASSERT(texImage
->TexFormat
);
2406 update_fbo_texture(ctx
, texObj
, face
, level
);
2409 texObj
->_Complete
= GL_FALSE
;
2410 ctx
->NewState
|= _NEW_TEXTURE
;
2413 _mesa_unlock_texture(ctx
, texObj
);
2415 else if (target
== GL_PROXY_TEXTURE_3D
||
2416 (ctx
->Extensions
.MESA_texture_array
&&
2417 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2418 /* Proxy texture: check for errors and update proxy state */
2419 struct gl_texture_image
*texImage
;
2420 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2421 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2422 format
, type
, 3, width
, height
, depth
, border
)) {
2423 /* when error, clear all proxy texture image parameters */
2425 clear_teximage_fields(texImage
);
2428 /* no error, set the tex image parameters */
2429 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2430 depth
, border
, internalFormat
);
2431 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2432 internalFormat
, format
, type
);
2436 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2443 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2444 GLsizei width
, GLsizei height
, GLsizei depth
,
2445 GLint border
, GLenum format
, GLenum type
,
2446 const GLvoid
*pixels
)
2448 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2449 depth
, border
, format
, type
, pixels
);
2455 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2456 GLint xoffset
, GLsizei width
,
2457 GLenum format
, GLenum type
,
2458 const GLvoid
*pixels
)
2460 GLsizei postConvWidth
= width
;
2461 struct gl_texture_unit
*texUnit
;
2462 struct gl_texture_object
*texObj
;
2463 struct gl_texture_image
*texImage
= NULL
;
2464 GET_CURRENT_CONTEXT(ctx
);
2465 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2467 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2468 _mesa_update_state(ctx
);
2470 #if FEATURE_convolve
2471 /* XXX should test internal format */
2472 if (_mesa_is_color_format(format
)) {
2473 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2477 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2478 postConvWidth
, 1, 1, format
, type
)) {
2479 return; /* error was detected */
2483 texUnit
= get_current_tex_unit(ctx
);
2484 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2487 _mesa_lock_texture(ctx
, texObj
);
2489 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2491 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2492 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2493 goto out
; /* error was detected */
2497 goto out
; /* no-op, not an error */
2499 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2500 xoffset
+= texImage
->Border
;
2502 ASSERT(ctx
->Driver
.TexSubImage1D
);
2503 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2504 format
, type
, pixels
, &ctx
->Unpack
,
2506 ctx
->NewState
|= _NEW_TEXTURE
;
2509 _mesa_unlock_texture(ctx
, texObj
);
2514 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2515 GLint xoffset
, GLint yoffset
,
2516 GLsizei width
, GLsizei height
,
2517 GLenum format
, GLenum type
,
2518 const GLvoid
*pixels
)
2520 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2521 struct gl_texture_unit
*texUnit
;
2522 struct gl_texture_object
*texObj
;
2523 struct gl_texture_image
*texImage
;
2524 GET_CURRENT_CONTEXT(ctx
);
2525 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2527 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2528 _mesa_update_state(ctx
);
2530 #if FEATURE_convolve
2531 /* XXX should test internal format */
2532 if (_mesa_is_color_format(format
)) {
2533 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2538 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2539 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2540 return; /* error was detected */
2543 texUnit
= get_current_tex_unit(ctx
);
2544 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2545 _mesa_lock_texture(ctx
, texObj
);
2547 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2549 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2550 postConvWidth
, postConvHeight
, 1, format
, type
,
2552 goto out
; /* error was detected */
2555 if (width
== 0 || height
== 0)
2556 goto out
; /* no-op, not an error */
2558 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2559 xoffset
+= texImage
->Border
;
2560 yoffset
+= texImage
->Border
;
2562 ASSERT(ctx
->Driver
.TexSubImage2D
);
2563 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2564 width
, height
, format
, type
, pixels
,
2565 &ctx
->Unpack
, texObj
, texImage
);
2566 ctx
->NewState
|= _NEW_TEXTURE
;
2569 _mesa_unlock_texture(ctx
, texObj
);
2575 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2576 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2577 GLsizei width
, GLsizei height
, GLsizei depth
,
2578 GLenum format
, GLenum type
,
2579 const GLvoid
*pixels
)
2581 struct gl_texture_unit
*texUnit
;
2582 struct gl_texture_object
*texObj
;
2583 struct gl_texture_image
*texImage
;
2584 GET_CURRENT_CONTEXT(ctx
);
2585 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2587 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2588 _mesa_update_state(ctx
);
2590 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2591 width
, height
, depth
, format
, type
)) {
2592 return; /* error was detected */
2595 texUnit
= get_current_tex_unit(ctx
);
2596 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2598 _mesa_lock_texture(ctx
, texObj
);
2600 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2602 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2603 width
, height
, depth
, format
, type
, texImage
)) {
2604 goto out
; /* error was detected */
2607 if (width
== 0 || height
== 0 || height
== 0)
2608 goto out
; /* no-op, not an error */
2610 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2611 xoffset
+= texImage
->Border
;
2612 yoffset
+= texImage
->Border
;
2613 zoffset
+= texImage
->Border
;
2615 ASSERT(ctx
->Driver
.TexSubImage3D
);
2616 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2617 xoffset
, yoffset
, zoffset
,
2618 width
, height
, depth
,
2619 format
, type
, pixels
,
2620 &ctx
->Unpack
, texObj
, texImage
);
2621 ctx
->NewState
|= _NEW_TEXTURE
;
2624 _mesa_unlock_texture(ctx
, texObj
);
2630 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2631 GLenum internalFormat
,
2633 GLsizei width
, GLint border
)
2635 struct gl_texture_unit
*texUnit
;
2636 struct gl_texture_object
*texObj
;
2637 struct gl_texture_image
*texImage
;
2638 GLsizei postConvWidth
= width
;
2639 const GLuint face
= _mesa_tex_target_to_face(target
);
2640 GET_CURRENT_CONTEXT(ctx
);
2641 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2643 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2644 _mesa_update_state(ctx
);
2646 #if FEATURE_convolve
2647 if (_mesa_is_color_format(internalFormat
)) {
2648 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2652 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2653 postConvWidth
, 1, border
))
2656 texUnit
= get_current_tex_unit(ctx
);
2657 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2658 _mesa_lock_texture(ctx
, texObj
);
2660 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2662 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2666 if (texImage
->Data
) {
2667 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2670 ASSERT(texImage
->Data
== NULL
);
2672 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2673 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2674 border
, internalFormat
);
2677 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2678 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2679 x
, y
, width
, border
);
2681 ASSERT(texImage
->TexFormat
);
2683 update_fbo_texture(ctx
, texObj
, face
, level
);
2686 texObj
->_Complete
= GL_FALSE
;
2687 ctx
->NewState
|= _NEW_TEXTURE
;
2690 _mesa_unlock_texture(ctx
, texObj
);
2696 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2697 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2700 struct gl_texture_unit
*texUnit
;
2701 struct gl_texture_object
*texObj
;
2702 struct gl_texture_image
*texImage
;
2703 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2704 const GLuint face
= _mesa_tex_target_to_face(target
);
2705 GET_CURRENT_CONTEXT(ctx
);
2706 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2708 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2709 _mesa_update_state(ctx
);
2711 #if FEATURE_convolve
2712 if (_mesa_is_color_format(internalFormat
)) {
2713 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2718 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2719 postConvWidth
, postConvHeight
, border
))
2722 texUnit
= get_current_tex_unit(ctx
);
2723 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2725 _mesa_lock_texture(ctx
, texObj
);
2727 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2730 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2734 if (texImage
->Data
) {
2735 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2738 ASSERT(texImage
->Data
== NULL
);
2740 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2741 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2742 postConvWidth
, postConvHeight
, 1,
2743 border
, internalFormat
);
2745 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2746 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
2747 x
, y
, width
, height
, border
);
2749 ASSERT(texImage
->TexFormat
);
2751 update_fbo_texture(ctx
, texObj
, face
, level
);
2754 texObj
->_Complete
= GL_FALSE
;
2755 ctx
->NewState
|= _NEW_TEXTURE
;
2758 _mesa_unlock_texture(ctx
, texObj
);
2763 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2764 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2766 struct gl_texture_unit
*texUnit
;
2767 struct gl_texture_object
*texObj
;
2768 struct gl_texture_image
*texImage
;
2769 GLsizei postConvWidth
= width
;
2773 GET_CURRENT_CONTEXT(ctx
);
2774 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2776 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2777 _mesa_update_state(ctx
);
2779 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2782 texUnit
= get_current_tex_unit(ctx
);
2783 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2785 _mesa_lock_texture(ctx
, texObj
);
2787 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2789 #if FEATURE_convolve
2790 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2791 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2795 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2796 xoffset
, 0, 0, postConvWidth
, 1,
2801 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2802 xoffset
+= texImage
->Border
;
2804 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2806 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2807 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2808 xoffset
, x
, y
, width
);
2811 ctx
->NewState
|= _NEW_TEXTURE
;
2814 _mesa_unlock_texture(ctx
, texObj
);
2820 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2821 GLint xoffset
, GLint yoffset
,
2822 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2824 struct gl_texture_unit
*texUnit
;
2825 struct gl_texture_object
*texObj
;
2826 struct gl_texture_image
*texImage
;
2827 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2828 GET_CURRENT_CONTEXT(ctx
);
2829 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2831 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2832 _mesa_update_state(ctx
);
2834 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2837 texUnit
= get_current_tex_unit(ctx
);
2838 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2840 _mesa_lock_texture(ctx
, texObj
);
2842 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2844 #if FEATURE_convolve
2845 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2846 _mesa_adjust_image_for_convolution(ctx
, 2,
2847 &postConvWidth
, &postConvHeight
);
2851 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2852 postConvWidth
, postConvHeight
, texImage
))
2855 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2856 xoffset
+= texImage
->Border
;
2857 yoffset
+= texImage
->Border
;
2859 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2861 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2862 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2863 xoffset
, yoffset
, x
, y
, width
, height
);
2866 ctx
->NewState
|= _NEW_TEXTURE
;
2869 _mesa_unlock_texture(ctx
, texObj
);
2875 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2876 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2877 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2879 struct gl_texture_unit
*texUnit
;
2880 struct gl_texture_object
*texObj
;
2881 struct gl_texture_image
*texImage
;
2882 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2883 GET_CURRENT_CONTEXT(ctx
);
2884 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2886 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2887 _mesa_update_state(ctx
);
2889 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2892 texUnit
= get_current_tex_unit(ctx
);
2893 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2895 _mesa_lock_texture(ctx
, texObj
);
2897 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2899 #if FEATURE_convolve
2900 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2901 _mesa_adjust_image_for_convolution(ctx
, 2,
2902 &postConvWidth
, &postConvHeight
);
2906 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2907 zoffset
, postConvWidth
, postConvHeight
,
2911 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2912 xoffset
+= texImage
->Border
;
2913 yoffset
+= texImage
->Border
;
2914 zoffset
+= texImage
->Border
;
2916 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2918 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2919 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2920 xoffset
, yoffset
, zoffset
,
2921 x
, y
, width
, height
);
2924 ctx
->NewState
|= _NEW_TEXTURE
;
2927 _mesa_unlock_texture(ctx
, texObj
);
2933 /**********************************************************************/
2934 /****** Compressed Textures ******/
2935 /**********************************************************************/
2939 * Error checking for glCompressedTexImage[123]D().
2940 * \return error code or GL_NO_ERROR.
2943 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
2944 GLenum target
, GLint level
,
2945 GLenum internalFormat
, GLsizei width
,
2946 GLsizei height
, GLsizei depth
, GLint border
,
2949 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
2951 if (dimensions
== 1) {
2952 /* 1D compressed textures not allowed */
2953 return GL_INVALID_ENUM
;
2955 else if (dimensions
== 2) {
2956 if (target
== GL_PROXY_TEXTURE_2D
) {
2957 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2959 else if (target
== GL_TEXTURE_2D
) {
2960 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2962 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
2963 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2964 return GL_INVALID_ENUM
; /*target*/
2965 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2967 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2968 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2969 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2970 return GL_INVALID_ENUM
; /*target*/
2971 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2974 return GL_INVALID_ENUM
; /*target*/
2977 else if (dimensions
== 3) {
2978 /* 3D compressed textures not allowed */
2979 return GL_INVALID_ENUM
;
2982 maxTextureSize
= 1 << (maxLevels
- 1);
2984 /* This will detect any invalid internalFormat value */
2985 if (!is_compressed_format(ctx
, internalFormat
))
2986 return GL_INVALID_ENUM
;
2988 /* This should really never fail */
2989 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
2990 return GL_INVALID_ENUM
;
2993 return GL_INVALID_VALUE
;
2996 * XXX We should probably use the proxy texture error check function here.
2998 if (width
< 1 || width
> maxTextureSize
||
2999 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3000 return GL_INVALID_VALUE
;
3002 if ((height
< 1 || height
> maxTextureSize
||
3003 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3005 return GL_INVALID_VALUE
;
3007 if ((depth
< 1 || depth
> maxTextureSize
||
3008 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3010 return GL_INVALID_VALUE
;
3012 /* For cube map, width must equal height */
3013 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3014 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3015 return GL_INVALID_VALUE
;
3017 if (level
< 0 || level
>= maxLevels
)
3018 return GL_INVALID_VALUE
;
3020 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3021 depth
, internalFormat
);
3022 if (expectedSize
!= imageSize
)
3023 return GL_INVALID_VALUE
;
3025 #if FEATURE_EXT_texture_sRGB
3026 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3027 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3028 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3029 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3031 return GL_INVALID_OPERATION
;
3040 * Error checking for glCompressedTexSubImage[123]D().
3041 * \warning There are some bad assumptions here about the size of compressed
3042 * texture tiles (multiple of 4) used to test the validity of the
3043 * offset and size parameters.
3044 * \return error code or GL_NO_ERROR.
3047 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3048 GLenum target
, GLint level
,
3049 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3050 GLsizei width
, GLsizei height
, GLsizei depth
,
3051 GLenum format
, GLsizei imageSize
)
3053 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3056 if (dimensions
== 1) {
3057 /* 1D compressed textures not allowed */
3058 return GL_INVALID_ENUM
;
3060 else if (dimensions
== 2) {
3061 if (target
== GL_PROXY_TEXTURE_2D
) {
3062 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3064 else if (target
== GL_TEXTURE_2D
) {
3065 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3067 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3068 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3069 return GL_INVALID_ENUM
; /*target*/
3070 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3072 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3073 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3074 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3075 return GL_INVALID_ENUM
; /*target*/
3076 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3079 return GL_INVALID_ENUM
; /*target*/
3082 else if (dimensions
== 3) {
3083 /* 3D compressed textures not allowed */
3084 return GL_INVALID_ENUM
;
3087 maxTextureSize
= 1 << (maxLevels
- 1);
3089 /* this will catch any invalid compressed format token */
3090 if (!is_compressed_format(ctx
, format
))
3091 return GL_INVALID_ENUM
;
3093 if (width
< 1 || width
> maxTextureSize
)
3094 return GL_INVALID_VALUE
;
3096 if ((height
< 1 || height
> maxTextureSize
)
3098 return GL_INVALID_VALUE
;
3100 if (level
< 0 || level
>= maxLevels
)
3101 return GL_INVALID_VALUE
;
3103 /* XXX these tests are specific to the compressed format.
3104 * this code should be generalized in some way.
3106 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3107 return GL_INVALID_VALUE
;
3109 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3110 return GL_INVALID_VALUE
;
3112 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3113 return GL_INVALID_VALUE
;
3115 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3117 if (expectedSize
!= imageSize
)
3118 return GL_INVALID_VALUE
;
3126 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3127 GLenum internalFormat
, GLsizei width
,
3128 GLint border
, GLsizei imageSize
,
3131 GET_CURRENT_CONTEXT(ctx
);
3132 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3134 if (target
== GL_TEXTURE_1D
) {
3135 /* non-proxy target */
3136 struct gl_texture_unit
*texUnit
;
3137 struct gl_texture_object
*texObj
;
3138 struct gl_texture_image
*texImage
;
3139 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3140 internalFormat
, width
, 1, 1, border
, imageSize
);
3142 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3146 texUnit
= get_current_tex_unit(ctx
);
3147 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3149 _mesa_lock_texture(ctx
, texObj
);
3151 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3153 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3157 if (texImage
->Data
) {
3158 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3160 ASSERT(texImage
->Data
== NULL
);
3162 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3163 border
, internalFormat
);
3165 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3166 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3167 internalFormat
, width
, border
,
3172 texObj
->_Complete
= GL_FALSE
;
3173 ctx
->NewState
|= _NEW_TEXTURE
;
3176 _mesa_unlock_texture(ctx
, texObj
);
3178 else if (target
== GL_PROXY_TEXTURE_1D
) {
3179 /* Proxy texture: check for errors and update proxy state */
3180 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3181 internalFormat
, width
, 1, 1, border
, imageSize
);
3183 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3184 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3185 internalFormat
, GL_NONE
, GL_NONE
,
3186 width
, 1, 1, border
);
3189 /* if error, clear all proxy texture image parameters */
3190 struct gl_texture_image
*texImage
;
3191 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3193 clear_teximage_fields(texImage
);
3196 /* store the teximage parameters */
3197 struct gl_texture_unit
*texUnit
;
3198 struct gl_texture_object
*texObj
;
3199 struct gl_texture_image
*texImage
;
3200 texUnit
= get_current_tex_unit(ctx
);
3201 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3203 _mesa_lock_texture(ctx
, texObj
);
3205 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3206 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3207 border
, internalFormat
);
3209 _mesa_unlock_texture(ctx
, texObj
);
3213 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3220 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3221 GLenum internalFormat
, GLsizei width
,
3222 GLsizei height
, GLint border
, GLsizei imageSize
,
3225 GET_CURRENT_CONTEXT(ctx
);
3226 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3228 if (target
== GL_TEXTURE_2D
||
3229 (ctx
->Extensions
.ARB_texture_cube_map
&&
3230 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3231 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3232 /* non-proxy target */
3233 struct gl_texture_unit
*texUnit
;
3234 struct gl_texture_object
*texObj
;
3235 struct gl_texture_image
*texImage
;
3236 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3237 internalFormat
, width
, height
, 1, border
, imageSize
);
3239 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3243 texUnit
= get_current_tex_unit(ctx
);
3244 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3246 _mesa_lock_texture(ctx
, texObj
);
3248 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3250 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3254 if (texImage
->Data
) {
3255 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3257 ASSERT(texImage
->Data
== NULL
);
3259 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3260 border
, internalFormat
);
3262 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3263 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3264 internalFormat
, width
, height
,
3265 border
, imageSize
, data
,
3269 texObj
->_Complete
= GL_FALSE
;
3270 ctx
->NewState
|= _NEW_TEXTURE
;
3273 _mesa_unlock_texture(ctx
, texObj
);
3275 else if (target
== GL_PROXY_TEXTURE_2D
||
3276 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3277 ctx
->Extensions
.ARB_texture_cube_map
)) {
3278 /* Proxy texture: check for errors and update proxy state */
3279 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3280 internalFormat
, width
, height
, 1, border
, imageSize
);
3282 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3283 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3284 internalFormat
, GL_NONE
, GL_NONE
,
3285 width
, height
, 1, border
);
3288 /* if error, clear all proxy texture image parameters */
3289 struct gl_texture_image
*texImage
;
3290 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3292 clear_teximage_fields(texImage
);
3295 /* store the teximage parameters */
3296 struct gl_texture_unit
*texUnit
;
3297 struct gl_texture_object
*texObj
;
3298 struct gl_texture_image
*texImage
;
3299 texUnit
= get_current_tex_unit(ctx
);
3300 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3302 _mesa_lock_texture(ctx
, texObj
);
3304 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3305 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3306 border
, internalFormat
);
3308 _mesa_unlock_texture(ctx
, texObj
);
3312 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3319 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3320 GLenum internalFormat
, GLsizei width
,
3321 GLsizei height
, GLsizei depth
, GLint border
,
3322 GLsizei imageSize
, const GLvoid
*data
)
3324 GET_CURRENT_CONTEXT(ctx
);
3325 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3327 if (target
== GL_TEXTURE_3D
) {
3328 /* non-proxy target */
3329 struct gl_texture_unit
*texUnit
;
3330 struct gl_texture_object
*texObj
;
3331 struct gl_texture_image
*texImage
;
3332 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3333 internalFormat
, width
, height
, depth
, border
, imageSize
);
3335 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3339 texUnit
= get_current_tex_unit(ctx
);
3340 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3341 _mesa_lock_texture(ctx
, texObj
);
3343 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3345 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3349 if (texImage
->Data
) {
3350 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3352 ASSERT(texImage
->Data
== NULL
);
3354 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3355 border
, internalFormat
);
3357 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3358 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3360 width
, height
, depth
,
3361 border
, imageSize
, data
,
3365 texObj
->_Complete
= GL_FALSE
;
3366 ctx
->NewState
|= _NEW_TEXTURE
;
3369 _mesa_unlock_texture(ctx
, texObj
);
3371 else if (target
== GL_PROXY_TEXTURE_3D
) {
3372 /* Proxy texture: check for errors and update proxy state */
3373 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3374 internalFormat
, width
, height
, depth
, border
, imageSize
);
3376 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3377 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3378 internalFormat
, GL_NONE
, GL_NONE
,
3379 width
, height
, depth
, border
);
3382 /* if error, clear all proxy texture image parameters */
3383 struct gl_texture_image
*texImage
;
3384 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3386 clear_teximage_fields(texImage
);
3389 /* store the teximage parameters */
3390 struct gl_texture_unit
*texUnit
;
3391 struct gl_texture_object
*texObj
;
3392 struct gl_texture_image
*texImage
;
3393 texUnit
= get_current_tex_unit(ctx
);
3394 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3395 _mesa_lock_texture(ctx
, texObj
);
3397 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3398 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3399 depth
, border
, internalFormat
);
3401 _mesa_unlock_texture(ctx
, texObj
);
3405 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3412 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3413 GLsizei width
, GLenum format
,
3414 GLsizei imageSize
, const GLvoid
*data
)
3416 struct gl_texture_unit
*texUnit
;
3417 struct gl_texture_object
*texObj
;
3418 struct gl_texture_image
*texImage
;
3420 GET_CURRENT_CONTEXT(ctx
);
3421 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3423 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3424 xoffset
, 0, 0, /* pos */
3425 width
, 1, 1, /* size */
3428 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3432 texUnit
= get_current_tex_unit(ctx
);
3433 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3434 _mesa_lock_texture(ctx
, texObj
);
3436 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3439 if ((GLint
) format
!= texImage
->InternalFormat
) {
3440 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3441 "glCompressedTexSubImage1D(format)");
3445 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3446 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3451 goto out
; /* no-op, not an error */
3453 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3454 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3456 format
, imageSize
, data
,
3459 ctx
->NewState
|= _NEW_TEXTURE
;
3462 _mesa_unlock_texture(ctx
, texObj
);
3467 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3468 GLint yoffset
, GLsizei width
, GLsizei height
,
3469 GLenum format
, GLsizei imageSize
,
3472 struct gl_texture_unit
*texUnit
;
3473 struct gl_texture_object
*texObj
;
3474 struct gl_texture_image
*texImage
;
3476 GET_CURRENT_CONTEXT(ctx
);
3477 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3479 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3480 xoffset
, yoffset
, 0, /* pos */
3481 width
, height
, 1, /* size */
3484 /* XXX proxy target? */
3485 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3489 texUnit
= get_current_tex_unit(ctx
);
3490 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3491 _mesa_lock_texture(ctx
, texObj
);
3493 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3496 if ((GLint
) format
!= texImage
->InternalFormat
) {
3497 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3498 "glCompressedTexSubImage2D(format)");
3502 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3503 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3504 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3508 if (width
== 0 || height
== 0)
3509 goto out
; /* no-op, not an error */
3511 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3512 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3513 xoffset
, yoffset
, width
, height
,
3514 format
, imageSize
, data
,
3517 ctx
->NewState
|= _NEW_TEXTURE
;
3520 _mesa_unlock_texture(ctx
, texObj
);
3525 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3526 GLint yoffset
, GLint zoffset
, GLsizei width
,
3527 GLsizei height
, GLsizei depth
, GLenum format
,
3528 GLsizei imageSize
, const GLvoid
*data
)
3530 struct gl_texture_unit
*texUnit
;
3531 struct gl_texture_object
*texObj
;
3532 struct gl_texture_image
*texImage
;
3534 GET_CURRENT_CONTEXT(ctx
);
3535 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3537 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3538 xoffset
, yoffset
, zoffset
,/*pos*/
3539 width
, height
, depth
, /*size*/
3542 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3546 texUnit
= get_current_tex_unit(ctx
);
3547 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3548 _mesa_lock_texture(ctx
, texObj
);
3550 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3553 if ((GLint
) format
!= texImage
->InternalFormat
) {
3554 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3555 "glCompressedTexSubImage3D(format)");
3559 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3560 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3561 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3562 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3566 if (width
== 0 || height
== 0 || depth
== 0)
3567 goto out
; /* no-op, not an error */
3569 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3570 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3571 xoffset
, yoffset
, zoffset
,
3572 width
, height
, depth
,
3573 format
, imageSize
, data
,
3576 ctx
->NewState
|= _NEW_TEXTURE
;
3579 _mesa_unlock_texture(ctx
, texObj
);