2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
40 #include "framebuffer.h"
46 #include "texcompress.h"
47 #include "texformat.h"
55 * State changes which we care about for glCopyTex[Sub]Image() calls.
56 * In particular, we care about pixel transfer state and buffer state
57 * (such as glReadBuffer to make sure we read from the right renderbuffer).
59 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
66 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
70 _mesa_alloc_texmemory(GLsizei bytes
)
72 return _mesa_align_malloc(bytes
, 512);
77 * Free texture memory allocated with _mesa_alloc_texmemory()
80 _mesa_free_texmemory(void *m
)
89 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
91 #if CHAN_TYPE != GL_UNSIGNED_BYTE
92 _mesa_problem(NULL
, "PrintTexture not supported");
95 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
98 _mesa_printf("No texture data\n");
102 switch (img
->Format
) {
109 case GL_LUMINANCE_ALPHA
:
119 _mesa_problem(NULL
, "error in PrintTexture\n");
123 for (i
= 0; i
< img
->Height
; i
++) {
124 for (j
= 0; j
< img
->Width
; j
++) {
126 _mesa_printf("%02x ", data
[0]);
128 _mesa_printf("%02x%02x ", data
[0], data
[1]);
130 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
132 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
133 data
+= (img
->RowStride
- img
->Width
) * c
;
135 /* XXX use img->ImageStride here */
144 * Compute floor(log_base_2(n)).
145 * If n < 0 return -1.
174 * Return the simple base format for a given internal texture format.
175 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
177 * \param ctx GL context.
178 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
180 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
181 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
183 * This is the format which is used during texture application (i.e. the
184 * texture format and env mode determine the arithmetic used.
186 * XXX this could be static
189 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
191 switch (internalFormat
) {
206 case GL_LUMINANCE_ALPHA
:
207 case GL_LUMINANCE4_ALPHA4
:
208 case GL_LUMINANCE6_ALPHA2
:
209 case GL_LUMINANCE8_ALPHA8
:
210 case GL_LUMINANCE12_ALPHA4
:
211 case GL_LUMINANCE12_ALPHA12
:
212 case GL_LUMINANCE16_ALPHA16
:
213 return GL_LUMINANCE_ALPHA
;
244 if (ctx
->Extensions
.EXT_paletted_texture
) {
245 switch (internalFormat
) {
247 case GL_COLOR_INDEX1_EXT
:
248 case GL_COLOR_INDEX2_EXT
:
249 case GL_COLOR_INDEX4_EXT
:
250 case GL_COLOR_INDEX8_EXT
:
251 case GL_COLOR_INDEX12_EXT
:
252 case GL_COLOR_INDEX16_EXT
:
253 return GL_COLOR_INDEX
;
259 if (ctx
->Extensions
.ARB_depth_texture
) {
260 switch (internalFormat
) {
261 case GL_DEPTH_COMPONENT
:
262 case GL_DEPTH_COMPONENT16
:
263 case GL_DEPTH_COMPONENT24
:
264 case GL_DEPTH_COMPONENT32
:
265 return GL_DEPTH_COMPONENT
;
271 switch (internalFormat
) {
272 case GL_COMPRESSED_ALPHA
:
274 case GL_COMPRESSED_LUMINANCE
:
276 case GL_COMPRESSED_LUMINANCE_ALPHA
:
277 return GL_LUMINANCE_ALPHA
;
278 case GL_COMPRESSED_INTENSITY
:
280 case GL_COMPRESSED_RGB
:
282 case GL_COMPRESSED_RGBA
:
288 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
289 switch (internalFormat
) {
290 case GL_COMPRESSED_RGB_FXT1_3DFX
:
292 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
299 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
300 switch (internalFormat
) {
301 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
303 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
304 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
305 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
312 if (ctx
->Extensions
.S3_s3tc
) {
313 switch (internalFormat
) {
325 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
326 if (internalFormat
== GL_YCBCR_MESA
)
327 return GL_YCBCR_MESA
;
330 if (ctx
->Extensions
.ARB_texture_float
) {
331 switch (internalFormat
) {
332 case GL_ALPHA16F_ARB
:
333 case GL_ALPHA32F_ARB
:
341 case GL_INTENSITY16F_ARB
:
342 case GL_INTENSITY32F_ARB
:
344 case GL_LUMINANCE16F_ARB
:
345 case GL_LUMINANCE32F_ARB
:
347 case GL_LUMINANCE_ALPHA16F_ARB
:
348 case GL_LUMINANCE_ALPHA32F_ARB
:
349 return GL_LUMINANCE_ALPHA
;
355 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
356 switch (internalFormat
) {
365 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
366 switch (internalFormat
) {
375 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
376 switch (internalFormat
) {
377 case GL_DEPTH_STENCIL_EXT
:
378 case GL_DEPTH24_STENCIL8_EXT
:
379 return GL_DEPTH_STENCIL_EXT
;
385 #if FEATURE_EXT_texture_sRGB
386 if (ctx
->Extensions
.EXT_texture_sRGB
) {
387 switch (internalFormat
) {
390 case GL_COMPRESSED_SRGB_EXT
:
391 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
393 case GL_SRGB_ALPHA_EXT
:
394 case GL_SRGB8_ALPHA8_EXT
:
395 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
396 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
397 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
398 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
400 case GL_SLUMINANCE_ALPHA_EXT
:
401 case GL_SLUMINANCE8_ALPHA8_EXT
:
402 case GL_COMPRESSED_SLUMINANCE_EXT
:
403 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
404 return GL_LUMINANCE_ALPHA
;
405 case GL_SLUMINANCE_EXT
:
406 case GL_SLUMINANCE8_EXT
:
413 #endif /* FEATURE_EXT_texture_sRGB */
415 return -1; /* error */
420 * Test if it is a supported compressed format.
422 * \param internalFormat the internal format token provided by the user.
424 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
425 * GL_FALSE otherwise.
427 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
431 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
433 GLint supported
[100]; /* 100 should be plenty */
436 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
438 for (i
= 0; i
< n
; i
++) {
439 if ((GLint
) internalFormat
== supported
[i
]) {
448 * For cube map faces, return a face index in [0,5].
449 * For other targets return 0;
452 _mesa_tex_target_to_face(GLenum target
)
454 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
455 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
456 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
464 * Store a gl_texture_image pointer in a gl_texture_object structure
465 * according to the target and level parameters.
467 * \param tObj texture object.
468 * \param target texture target.
469 * \param level image level.
470 * \param texImage texture image.
472 * This was basically prompted by the introduction of cube maps.
475 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
476 GLenum target
, GLint level
,
477 struct gl_texture_image
*texImage
)
479 const GLuint face
= _mesa_tex_target_to_face(target
);
483 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
485 tObj
->Image
[face
][level
] = texImage
;
487 /* Set the 'back' pointer */
488 texImage
->TexObject
= tObj
;
493 * Allocate a texture image structure.
495 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
498 * \return a pointer to gl_texture_image struct with all fields initialized to
501 struct gl_texture_image
*
502 _mesa_new_texture_image( GLcontext
*ctx
)
505 return CALLOC_STRUCT(gl_texture_image
);
510 * Free texture image data.
511 * This function is a fallback called via ctx->Driver.FreeTexImageData().
513 * \param texImage texture image.
515 * Free the texture image data if it's not marked as client data.
518 _mesa_free_texture_image_data(GLcontext
*ctx
,
519 struct gl_texture_image
*texImage
)
523 if (texImage
->Data
&& !texImage
->IsClientData
) {
524 /* free the old texture data */
525 _mesa_free_texmemory(texImage
->Data
);
528 texImage
->Data
= NULL
;
533 * Free texture image.
535 * \param texImage texture image.
537 * Free the texture image structure and the associated image data.
540 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
542 /* Free texImage->Data and/or any other driver-specific texture
545 ASSERT(ctx
->Driver
.FreeTexImageData
);
546 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
548 ASSERT(texImage
->Data
== NULL
);
549 if (texImage
->ImageOffsets
)
550 _mesa_free(texImage
->ImageOffsets
);
551 _mesa_free(texImage
);
556 * Test if a target is a proxy target.
558 * \param target texture target.
560 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
563 _mesa_is_proxy_texture(GLenum target
)
565 /* NUM_TEXTURE_TARGETS should match number of terms below */
566 assert(NUM_TEXTURE_TARGETS
== 7);
568 return (target
== GL_PROXY_TEXTURE_1D
||
569 target
== GL_PROXY_TEXTURE_2D
||
570 target
== GL_PROXY_TEXTURE_3D
||
571 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
572 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
573 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
574 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
579 * Get the texture object that corresponds to the target of the given texture unit.
581 * \param ctx GL context.
582 * \param texUnit texture unit.
583 * \param target texture target.
585 * \return pointer to the texture object on success, or NULL on failure.
587 * \sa gl_texture_unit.
589 struct gl_texture_object
*
590 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
595 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
596 case GL_PROXY_TEXTURE_1D
:
597 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
599 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
600 case GL_PROXY_TEXTURE_2D
:
601 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
603 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
604 case GL_PROXY_TEXTURE_3D
:
605 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
606 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
607 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
608 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
609 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
610 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
611 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
612 case GL_TEXTURE_CUBE_MAP_ARB
:
613 return ctx
->Extensions
.ARB_texture_cube_map
614 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
615 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
616 return ctx
->Extensions
.ARB_texture_cube_map
617 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
618 case GL_TEXTURE_RECTANGLE_NV
:
619 return ctx
->Extensions
.NV_texture_rectangle
620 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
621 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
622 return ctx
->Extensions
.NV_texture_rectangle
623 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
624 case GL_TEXTURE_1D_ARRAY_EXT
:
625 return ctx
->Extensions
.MESA_texture_array
626 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
627 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
628 return ctx
->Extensions
.MESA_texture_array
629 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
630 case GL_TEXTURE_2D_ARRAY_EXT
:
631 return ctx
->Extensions
.MESA_texture_array
632 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
633 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
634 return ctx
->Extensions
.MESA_texture_array
635 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
637 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
644 * Get a texture image pointer from a texture object, given a texture
645 * target and mipmap level. The target and level parameters should
646 * have already been error-checked.
648 * \param ctx GL context.
649 * \param texObj texture unit.
650 * \param target texture target.
651 * \param level image level.
653 * \return pointer to the texture image structure, or NULL on failure.
655 struct gl_texture_image
*
656 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
657 GLenum target
, GLint level
)
659 const GLuint face
= _mesa_tex_target_to_face(target
);
663 ASSERT(level
< MAX_TEXTURE_LEVELS
);
665 return texObj
->Image
[face
][level
];
670 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
671 * it and install it. Only return NULL if passed a bad parameter or run
674 struct gl_texture_image
*
675 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
676 GLenum target
, GLint level
)
678 struct gl_texture_image
*texImage
;
683 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
685 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
687 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
691 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
699 * Return pointer to the specified proxy texture image.
700 * Note that proxy textures are per-context, not per-texture unit.
701 * \return pointer to texture image or NULL if invalid target, invalid
702 * level, or out of memory.
704 struct gl_texture_image
*
705 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
707 struct gl_texture_image
*texImage
;
714 case GL_PROXY_TEXTURE_1D
:
715 if (level
>= ctx
->Const
.MaxTextureLevels
)
717 texIndex
= TEXTURE_1D_INDEX
;
719 case GL_PROXY_TEXTURE_2D
:
720 if (level
>= ctx
->Const
.MaxTextureLevels
)
722 texIndex
= TEXTURE_2D_INDEX
;
724 case GL_PROXY_TEXTURE_3D
:
725 if (level
>= ctx
->Const
.Max3DTextureLevels
)
727 texIndex
= TEXTURE_3D_INDEX
;
729 case GL_PROXY_TEXTURE_CUBE_MAP
:
730 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
732 texIndex
= TEXTURE_CUBE_INDEX
;
734 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
737 texIndex
= TEXTURE_RECT_INDEX
;
739 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
740 if (level
>= ctx
->Const
.MaxTextureLevels
)
742 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
744 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
745 if (level
>= ctx
->Const
.MaxTextureLevels
)
747 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
753 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
755 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
757 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
760 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
761 /* Set the 'back' pointer */
762 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
769 * Get the maximum number of allowed mipmap levels.
771 * \param ctx GL context.
772 * \param target texture target.
774 * \return the maximum number of allowed mipmap levels for the given
775 * texture target, or zero if passed a bad target.
780 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
784 case GL_PROXY_TEXTURE_1D
:
786 case GL_PROXY_TEXTURE_2D
:
787 case GL_TEXTURE_1D_ARRAY_EXT
:
788 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
789 case GL_TEXTURE_2D_ARRAY_EXT
:
790 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
791 return ctx
->Const
.MaxTextureLevels
;
793 case GL_PROXY_TEXTURE_3D
:
794 return ctx
->Const
.Max3DTextureLevels
;
795 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
796 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
797 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
798 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
799 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
800 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
801 case GL_TEXTURE_CUBE_MAP_ARB
:
802 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
803 return ctx
->Const
.MaxCubeTextureLevels
;
804 case GL_TEXTURE_RECTANGLE_NV
:
805 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
808 return 0; /* bad target */
814 #if 000 /* not used anymore */
816 * glTexImage[123]D can accept a NULL image pointer. In this case we
817 * create a texture image with unspecified image contents per the OpenGL
821 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
823 const GLint components
= _mesa_components_in_format(format
);
824 const GLint numPixels
= width
* height
* depth
;
825 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
829 * Let's see if anyone finds this. If glTexImage2D() is called with
830 * a NULL image pointer then load the texture image with something
831 * interesting instead of leaving it indeterminate.
834 static const char message
[8][32] = {
838 " X X XXXX XXX XXXXX ",
841 " X X XXXXX XXX X X ",
845 GLubyte
*imgPtr
= data
;
847 for (h
= 0; h
< depth
; h
++) {
848 for (i
= 0; i
< height
; i
++) {
849 GLint srcRow
= 7 - (i
% 8);
850 for (j
= 0; j
< width
; j
++) {
851 GLint srcCol
= j
% 32;
852 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
853 for (k
= 0; k
< components
; k
++) {
869 * Reset the fields of a gl_texture_image struct to zero.
871 * \param img texture image structure.
873 * This is called when a proxy texture test fails, we set all the
874 * image members (except DriverData) to zero.
875 * It's also used in glTexImage[123]D as a safeguard to be sure all
876 * required fields get initialized properly by the Driver.TexImage[123]D
880 clear_teximage_fields(struct gl_texture_image
*img
)
883 img
->_BaseFormat
= 0;
884 img
->InternalFormat
= 0;
890 if (img
->ImageOffsets
) {
891 _mesa_free(img
->ImageOffsets
);
892 img
->ImageOffsets
= NULL
;
901 img
->TexFormat
= &_mesa_null_texformat
;
902 img
->FetchTexelc
= NULL
;
903 img
->FetchTexelf
= NULL
;
904 img
->IsCompressed
= 0;
905 img
->CompressedSize
= 0;
910 * Initialize basic fields of the gl_texture_image struct.
912 * \param ctx GL context.
913 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
914 * \param img texture image structure to be initialized.
915 * \param width image width.
916 * \param height image height.
917 * \param depth image depth.
918 * \param border image border.
919 * \param internalFormat internal format.
921 * Fills in the fields of \p img with the given information.
922 * Note: width, height and depth include the border.
925 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
926 struct gl_texture_image
*img
,
927 GLsizei width
, GLsizei height
, GLsizei depth
,
928 GLint border
, GLenum internalFormat
)
937 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
938 ASSERT(img
->_BaseFormat
> 0);
939 img
->InternalFormat
= internalFormat
;
940 img
->Border
= border
;
942 img
->Height
= height
;
945 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
946 img
->WidthLog2
= logbase2(img
->Width2
);
948 if (height
== 1) { /* 1-D texture */
953 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
954 img
->HeightLog2
= logbase2(img
->Height2
);
957 if (depth
== 1) { /* 2-D texture */
962 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
963 img
->DepthLog2
= logbase2(img
->Depth2
);
966 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
968 img
->IsCompressed
= GL_FALSE
;
969 img
->CompressedSize
= 0;
971 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
972 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
973 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
974 img
->_IsPowerOfTwo
= GL_TRUE
;
976 img
->_IsPowerOfTwo
= GL_FALSE
;
978 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
979 img
->RowStride
= width
;
980 /* Allocate the ImageOffsets array and initialize to typical values.
981 * We allocate the array for 1D/2D textures too in order to avoid special-
982 * case code in the texstore routines.
984 if (img
->ImageOffsets
)
985 _mesa_free(img
->ImageOffsets
);
986 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
987 for (i
= 0; i
< depth
; i
++) {
988 img
->ImageOffsets
[i
] = i
* width
* height
;
991 /* Compute Width/Height/DepthScale for mipmap lod computation */
992 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
993 /* scale = 1.0 since texture coords directly map to texels */
994 img
->WidthScale
= 1.0;
995 img
->HeightScale
= 1.0;
996 img
->DepthScale
= 1.0;
999 img
->WidthScale
= (GLfloat
) img
->Width
;
1000 img
->HeightScale
= (GLfloat
) img
->Height
;
1001 img
->DepthScale
= (GLfloat
) img
->Depth
;
1007 * Free and clear fields of the gl_texture_image struct.
1009 * \param ctx GL context.
1010 * \param texImage texture image structure to be cleared.
1012 * After the call, \p texImage will have no data associated with it. Its
1013 * fields are cleared so that its parent object will test incomplete.
1016 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
1018 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1019 clear_teximage_fields(texImage
);
1024 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1025 * level, width, height and depth against the ctx->Const limits for textures.
1027 * A hardware driver might override this function if, for example, the
1028 * max 3D texture size is 512x512x64 (i.e. not a cube).
1030 * Note that width, height, depth == 0 is not an error. However, a
1031 * texture with zero width/height/depth will be considered "incomplete"
1032 * and texturing will effectively be disabled.
1034 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1035 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1036 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1037 * \param level as passed to glTexImage
1038 * \param internalFormat as passed to glTexImage
1039 * \param format as passed to glTexImage
1040 * \param type as passed to glTexImage
1041 * \param width as passed to glTexImage
1042 * \param height as passed to glTexImage
1043 * \param depth as passed to glTexImage
1044 * \param border as passed to glTexImage
1045 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1048 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1049 GLint internalFormat
, GLenum format
, GLenum type
,
1050 GLint width
, GLint height
, GLint depth
, GLint border
)
1054 (void) internalFormat
;
1059 case GL_PROXY_TEXTURE_1D
:
1060 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1061 if (width
< 2 * border
|| width
> 2 + maxSize
||
1062 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1063 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1064 level
>= ctx
->Const
.MaxTextureLevels
) {
1065 /* bad width or level */
1069 case GL_PROXY_TEXTURE_2D
:
1070 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1071 if (width
< 2 * border
|| width
> 2 + maxSize
||
1072 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1073 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1074 height
< 2 * border
|| height
> 2 + maxSize
||
1075 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1076 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1077 level
>= ctx
->Const
.MaxTextureLevels
) {
1078 /* bad width or height or level */
1082 case GL_PROXY_TEXTURE_3D
:
1083 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1084 if (width
< 2 * border
|| width
> 2 + maxSize
||
1085 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1086 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1087 height
< 2 * border
|| height
> 2 + maxSize
||
1088 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1089 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1090 depth
< 2 * border
|| depth
> 2 + maxSize
||
1091 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1092 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1093 level
>= ctx
->Const
.Max3DTextureLevels
) {
1094 /* bad width or height or depth or level */
1098 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1099 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1100 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1102 /* bad width or height or level */
1106 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1107 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1108 if (width
< 2 * border
|| width
> 2 + maxSize
||
1109 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1110 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1111 height
< 2 * border
|| height
> 2 + maxSize
||
1112 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1113 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1114 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1115 /* bad width or height */
1119 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1120 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1121 if (width
< 2 * border
|| width
> 2 + maxSize
||
1122 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1123 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1124 level
>= ctx
->Const
.MaxTextureLevels
) {
1125 /* bad width or level */
1129 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1133 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1134 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1135 if (width
< 2 * border
|| width
> 2 + maxSize
||
1136 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1137 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1138 height
< 2 * border
|| height
> 2 + maxSize
||
1139 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1140 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1141 level
>= ctx
->Const
.MaxTextureLevels
) {
1142 /* bad width or height or level */
1145 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1150 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1157 * Helper function to determine whether a target supports compressed textures
1160 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1162 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1163 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1164 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1165 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1166 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1167 || ((ctx
->Extensions
.MESA_texture_array
&&
1168 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1169 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1174 * Test the glTexImage[123]D() parameters for errors.
1176 * \param ctx GL context.
1177 * \param target texture target given by the user.
1178 * \param level image level given by the user.
1179 * \param internalFormat internal format given by the user.
1180 * \param format pixel data format given by the user.
1181 * \param type pixel data type given by the user.
1182 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1183 * \param width image width given by the user.
1184 * \param height image height given by the user.
1185 * \param depth image depth given by the user.
1186 * \param border image border given by the user.
1188 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1190 * Verifies each of the parameters against the constants specified in
1191 * __GLcontextRec::Const and the supported extensions, and according to the
1192 * OpenGL specification.
1195 texture_error_check( GLcontext
*ctx
, GLenum target
,
1196 GLint level
, GLint internalFormat
,
1197 GLenum format
, GLenum type
,
1199 GLint width
, GLint height
,
1200 GLint depth
, GLint border
)
1202 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1203 GLboolean sizeOK
= GL_TRUE
;
1204 GLboolean colorFormat
, indexFormat
;
1205 GLenum proxy_target
;
1207 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1208 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1210 _mesa_error(ctx
, GL_INVALID_VALUE
,
1211 "glTexImage%dD(level=%d)", dimensions
, level
);
1217 if (border
< 0 || border
> 1 ||
1218 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1219 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1221 _mesa_error(ctx
, GL_INVALID_VALUE
,
1222 "glTexImage%dD(border=%d)", dimensions
, border
);
1227 if (width
< 0 || height
< 0 || depth
< 0) {
1229 _mesa_error(ctx
, GL_INVALID_VALUE
,
1230 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1235 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1236 * level, width, height and depth.
1238 if (dimensions
== 1) {
1239 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1240 proxy_target
= GL_PROXY_TEXTURE_1D
;
1245 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1249 else if (dimensions
== 2) {
1251 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1252 proxy_target
= GL_PROXY_TEXTURE_2D
;
1254 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1255 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1256 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1257 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1258 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1261 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1262 sizeOK
= (width
== height
);
1264 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1265 target
== GL_TEXTURE_RECTANGLE_NV
) {
1266 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1267 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1270 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1272 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1273 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1274 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1277 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1281 else if (dimensions
== 3) {
1282 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1283 proxy_target
= GL_PROXY_TEXTURE_3D
;
1285 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1286 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1287 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1290 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1295 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1299 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1300 internalFormat
, format
,
1301 type
, width
, height
,
1305 _mesa_error(ctx
, GL_INVALID_VALUE
,
1306 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1307 dimensions
, level
, width
, height
, depth
);
1312 /* Check internalFormat */
1313 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1315 _mesa_error(ctx
, GL_INVALID_VALUE
,
1316 "glTexImage%dD(internalFormat=0x%x)",
1317 dimensions
, internalFormat
);
1322 /* Check incoming image format and type */
1323 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1324 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1325 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1328 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1329 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1330 dimensions
, format
, type
);
1335 /* make sure internal format and format basically agree */
1336 colorFormat
= _mesa_is_color_format(format
);
1337 indexFormat
= _mesa_is_index_format(format
);
1338 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1339 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1340 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1341 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1342 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1343 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1345 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1346 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1347 dimensions
, internalFormat
, format
);
1351 /* additional checks for ycbcr textures */
1352 if (internalFormat
== GL_YCBCR_MESA
) {
1353 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1354 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1355 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1357 _mesa_sprintf(message
,
1358 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1359 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1360 return GL_TRUE
; /* error */
1362 if (target
!= GL_TEXTURE_2D
&&
1363 target
!= GL_PROXY_TEXTURE_2D
&&
1364 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1365 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1367 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1373 _mesa_sprintf(message
,
1374 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1375 dimensions
, border
);
1376 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1382 /* additional checks for depth textures */
1383 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1384 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1385 if (target
!= GL_TEXTURE_1D
&&
1386 target
!= GL_PROXY_TEXTURE_1D
&&
1387 target
!= GL_TEXTURE_2D
&&
1388 target
!= GL_PROXY_TEXTURE_2D
&&
1389 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1390 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1392 _mesa_error(ctx
, GL_INVALID_ENUM
,
1393 "glTexImage(target/internalFormat)");
1398 /* additional checks for compressed textures */
1399 if (is_compressed_format(ctx
, internalFormat
)) {
1400 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1401 _mesa_error(ctx
, GL_INVALID_ENUM
,
1402 "glTexImage%d(target)", dimensions
);
1407 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1408 "glTexImage%D(border!=0)", dimensions
);
1414 /* if we get here, the parameters are OK */
1420 * Test glTexSubImage[123]D() parameters for errors.
1422 * \param ctx GL context.
1423 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1424 * \param target texture target given by the user.
1425 * \param level image level given by the user.
1426 * \param xoffset sub-image x offset given by the user.
1427 * \param yoffset sub-image y offset given by the user.
1428 * \param zoffset sub-image z offset given by the user.
1429 * \param format pixel data format given by the user.
1430 * \param type pixel data type given by the user.
1431 * \param width image width given by the user.
1432 * \param height image height given by the user.
1433 * \param depth image depth given by the user.
1435 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1437 * Verifies each of the parameters against the constants specified in
1438 * __GLcontextRec::Const and the supported extensions, and according to the
1439 * OpenGL specification.
1442 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1443 GLenum target
, GLint level
,
1444 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1445 GLint width
, GLint height
, GLint depth
,
1446 GLenum format
, GLenum type
)
1449 if (dimensions
== 1) {
1450 if (target
!= GL_TEXTURE_1D
) {
1451 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1455 else if (dimensions
== 2) {
1456 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1457 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1458 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1459 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1463 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1464 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1465 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1469 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1470 if (!ctx
->Extensions
.MESA_texture_array
) {
1471 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1475 else if (target
!= GL_TEXTURE_2D
) {
1476 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1480 else if (dimensions
== 3) {
1481 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1482 if (!ctx
->Extensions
.MESA_texture_array
) {
1483 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1487 else if (target
!= GL_TEXTURE_3D
) {
1488 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1493 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1497 /* Basic level check */
1498 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1499 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1504 _mesa_error(ctx
, GL_INVALID_VALUE
,
1505 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1508 if (height
< 0 && dimensions
> 1) {
1509 _mesa_error(ctx
, GL_INVALID_VALUE
,
1510 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1513 if (depth
< 0 && dimensions
> 2) {
1514 _mesa_error(ctx
, GL_INVALID_VALUE
,
1515 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1519 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1520 _mesa_error(ctx
, GL_INVALID_ENUM
,
1521 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1522 dimensions
, format
, type
);
1530 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1531 GLenum target
, GLint level
,
1532 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1533 GLint width
, GLint height
, GLint depth
,
1534 GLenum format
, GLenum type
,
1535 const struct gl_texture_image
*destTex
)
1538 /* undefined image level */
1539 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1543 if (xoffset
< -((GLint
)destTex
->Border
)) {
1544 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1548 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1549 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1553 if (dimensions
> 1) {
1554 if (yoffset
< -((GLint
)destTex
->Border
)) {
1555 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1559 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1560 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1565 if (dimensions
> 2) {
1566 if (zoffset
< -((GLint
)destTex
->Border
)) {
1567 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1570 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1571 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1576 #if FEATURE_EXT_texture_sRGB
1577 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1578 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1579 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1580 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1581 if ((width
& 0x3) || (height
& 0x3) ||
1582 (xoffset
& 0x3) || (yoffset
& 0x3))
1583 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1584 "glTexSubImage%dD(size or offset not multiple of 4)",
1590 if (destTex
->IsCompressed
) {
1591 if (!target_can_be_compressed(ctx
, target
)) {
1592 _mesa_error(ctx
, GL_INVALID_ENUM
,
1593 "glTexSubImage%D(target)", dimensions
);
1596 /* offset must be multiple of 4 */
1597 if ((xoffset
& 3) || (yoffset
& 3)) {
1598 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1599 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1602 /* size must be multiple of 4 or equal to whole texture size */
1603 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1604 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1605 "glTexSubImage%D(width)", dimensions
);
1608 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1609 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1610 "glTexSubImage%D(width)", dimensions
);
1620 * Test glCopyTexImage[12]D() parameters for errors.
1622 * \param ctx GL context.
1623 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1624 * \param target texture target given by the user.
1625 * \param level image level given by the user.
1626 * \param internalFormat internal format given by the user.
1627 * \param width image width given by the user.
1628 * \param height image height given by the user.
1629 * \param border texture border.
1631 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1633 * Verifies each of the parameters against the constants specified in
1634 * __GLcontextRec::Const and the supported extensions, and according to the
1635 * OpenGL specification.
1638 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1639 GLenum target
, GLint level
, GLint internalFormat
,
1640 GLint width
, GLint height
, GLint border
)
1646 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1647 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1648 _mesa_error(ctx
, GL_INVALID_VALUE
,
1649 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1653 /* Check that the source buffer is complete */
1654 if (ctx
->ReadBuffer
->Name
) {
1655 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1656 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1657 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1658 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1664 if (border
< 0 || border
> 1 ||
1665 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1666 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1670 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1672 _mesa_error(ctx
, GL_INVALID_VALUE
,
1673 "glCopyTexImage%dD(internalFormat)", dimensions
);
1677 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1678 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1679 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1683 /* NOTE: the format and type aren't really significant for
1684 * TestProxyTexImage(). Only the internalformat really matters.
1688 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1689 * level, width, height and depth.
1691 if (dimensions
== 1) {
1692 if (target
== GL_TEXTURE_1D
) {
1693 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1694 level
, internalFormat
,
1696 width
, 1, 1, border
);
1699 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1703 else if (dimensions
== 2) {
1704 if (target
== GL_TEXTURE_2D
) {
1705 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1706 level
, internalFormat
,
1708 width
, height
, 1, border
);
1710 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1711 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1712 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1713 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1716 sizeOK
= (width
== height
) &&
1717 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1718 level
, internalFormat
, format
, type
,
1719 width
, height
, 1, border
);
1721 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1722 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1723 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1726 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1727 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1728 level
, internalFormat
,
1730 width
, height
, 1, border
);
1732 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1733 if (!ctx
->Extensions
.MESA_texture_array
) {
1734 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1737 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1738 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1739 level
, internalFormat
,
1741 width
, height
, 1, border
);
1744 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1749 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1754 if (dimensions
== 1) {
1755 _mesa_error(ctx
, GL_INVALID_VALUE
,
1756 "glCopyTexImage1D(width=%d)", width
);
1759 ASSERT(dimensions
== 2);
1760 _mesa_error(ctx
, GL_INVALID_VALUE
,
1761 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1766 if (is_compressed_format(ctx
, internalFormat
)) {
1767 if (!target_can_be_compressed(ctx
, target
)) {
1768 _mesa_error(ctx
, GL_INVALID_ENUM
,
1769 "glCopyTexImage%d(target)", dimensions
);
1773 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1774 "glCopyTexImage%D(border!=0)", dimensions
);
1778 else if (_mesa_is_depth_format(internalFormat
)) {
1779 /* make sure we have depth/stencil buffers */
1780 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1781 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1782 "glCopyTexImage%D(no depth)", dimensions
);
1786 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1787 /* make sure we have depth/stencil buffers */
1788 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1789 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1790 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
1795 /* if we get here, the parameters are OK */
1801 * Test glCopyTexSubImage[12]D() parameters for errors.
1802 * Note that this is the first part of error checking.
1803 * See also copytexsubimage_error_check2() below for the second part.
1805 * \param ctx GL context.
1806 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1807 * \param target texture target given by the user.
1808 * \param level image level given by the user.
1810 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1813 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1814 GLenum target
, GLint level
)
1816 /* Check that the source buffer is complete */
1817 if (ctx
->ReadBuffer
->Name
) {
1818 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1819 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1820 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1821 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1827 if (dimensions
== 1) {
1828 if (target
!= GL_TEXTURE_1D
) {
1829 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1833 else if (dimensions
== 2) {
1834 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1835 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1836 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1837 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1841 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1842 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1843 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1847 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1848 if (!ctx
->Extensions
.MESA_texture_array
) {
1849 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1853 else if (target
!= GL_TEXTURE_2D
) {
1854 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1858 else if (dimensions
== 3) {
1859 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1860 (!ctx
->Extensions
.MESA_texture_array
))
1861 && (target
!= GL_TEXTURE_3D
)) {
1862 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1868 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1869 _mesa_error(ctx
, GL_INVALID_VALUE
,
1870 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1879 * Second part of error checking for glCopyTexSubImage[12]D().
1880 * \param xoffset sub-image x offset given by the user.
1881 * \param yoffset sub-image y offset given by the user.
1882 * \param zoffset sub-image z offset given by the user.
1883 * \param width image width given by the user.
1884 * \param height image height given by the user.
1887 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1888 GLenum target
, GLint level
,
1889 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1890 GLsizei width
, GLsizei height
,
1891 const struct gl_texture_image
*teximage
)
1893 /* check that dest tex image exists */
1895 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1896 "glCopyTexSubImage%dD(undefined texture level: %d)",
1903 _mesa_error(ctx
, GL_INVALID_VALUE
,
1904 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1907 if (dimensions
> 1 && height
< 0) {
1908 _mesa_error(ctx
, GL_INVALID_VALUE
,
1909 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1913 /* check x/y offsets */
1914 if (xoffset
< -((GLint
)teximage
->Border
)) {
1915 _mesa_error(ctx
, GL_INVALID_VALUE
,
1916 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1919 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1920 _mesa_error(ctx
, GL_INVALID_VALUE
,
1921 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1924 if (dimensions
> 1) {
1925 if (yoffset
< -((GLint
)teximage
->Border
)) {
1926 _mesa_error(ctx
, GL_INVALID_VALUE
,
1927 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1930 /* NOTE: we're adding the border here, not subtracting! */
1931 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1932 _mesa_error(ctx
, GL_INVALID_VALUE
,
1933 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1938 /* check z offset */
1939 if (dimensions
> 2) {
1940 if (zoffset
< -((GLint
)teximage
->Border
)) {
1941 _mesa_error(ctx
, GL_INVALID_VALUE
,
1942 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1945 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1946 _mesa_error(ctx
, GL_INVALID_VALUE
,
1947 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1952 if (teximage
->IsCompressed
) {
1953 if (!target_can_be_compressed(ctx
, target
)) {
1954 _mesa_error(ctx
, GL_INVALID_ENUM
,
1955 "glCopyTexSubImage%d(target)", dimensions
);
1958 /* offset must be multiple of 4 */
1959 if ((xoffset
& 3) || (yoffset
& 3)) {
1960 _mesa_error(ctx
, GL_INVALID_VALUE
,
1961 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
1964 /* size must be multiple of 4 */
1965 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1966 _mesa_error(ctx
, GL_INVALID_VALUE
,
1967 "glCopyTexSubImage%D(width)", dimensions
);
1970 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1971 _mesa_error(ctx
, GL_INVALID_VALUE
,
1972 "glCopyTexSubImage%D(height)", dimensions
);
1977 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
1978 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1982 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
1983 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1984 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
1985 dimensions
, teximage
->_BaseFormat
);
1989 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
1990 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1991 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1992 "glCopyTexSubImage%D(no depth buffer)",
1997 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
1998 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1999 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2000 "glCopyTexSubImage%D(no depth/stencil buffer)",
2006 /* if we get here, the parameters are OK */
2011 /** Callback info for walking over FBO hash table */
2015 struct gl_texture_object
*texObj
;
2021 * Check render to texture callback. Called from _mesa_HashWalk().
2024 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2026 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2027 const struct cb_info
*info
= (struct cb_info
*) userData
;
2028 GLcontext
*ctx
= info
->ctx
;
2029 const struct gl_texture_object
*texObj
= info
->texObj
;
2030 const GLuint level
= info
->level
, face
= info
->face
;
2032 /* If this is a user-created FBO */
2035 /* check if any of the FBO's attachments point to 'texObj' */
2036 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2037 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2038 if (att
->Type
== GL_TEXTURE
&&
2039 att
->Texture
== texObj
&&
2040 att
->TextureLevel
== level
&&
2041 att
->CubeMapFace
== face
) {
2042 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2043 /* Tell driver about the new renderbuffer texture */
2044 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2045 /* Mark fb status as indeterminate to force re-validation */
2054 * When a texture image is specified we have to check if it's bound to
2055 * any framebuffer objects (render to texture) in order to detect changes
2056 * in size or format since that effects FBO completeness.
2057 * Any FBOs rendering into the texture must be re-validated.
2060 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2061 GLuint face
, GLuint level
)
2063 /* Only check this texture if it's been marked as RenderToTexture */
2064 if (texObj
->_RenderToTexture
) {
2065 struct cb_info info
;
2067 info
.texObj
= texObj
;
2070 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2075 /** Debug helper: override the user-requested internal format */
2077 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2080 if (internalFormat
== GL_RGBA16F_ARB
||
2081 internalFormat
== GL_RGBA32F_ARB
) {
2082 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2085 else if (internalFormat
== GL_RGB16F_ARB
||
2086 internalFormat
== GL_RGB32F_ARB
) {
2087 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2090 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2091 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2092 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2093 return GL_LUMINANCE_ALPHA
;
2095 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2096 internalFormat
== GL_LUMINANCE32F_ARB
) {
2097 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2098 return GL_LUMINANCE
;
2100 else if (internalFormat
== GL_ALPHA16F_ARB
||
2101 internalFormat
== GL_ALPHA32F_ARB
) {
2102 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2106 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2107 internalFormat = GL_RGBA;
2111 return internalFormat
;
2114 return internalFormat
;
2120 * Called from the API. Note that width includes the border.
2123 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2124 GLsizei width
, GLint border
, GLenum format
,
2125 GLenum type
, const GLvoid
*pixels
)
2127 GLsizei postConvWidth
= width
;
2128 GET_CURRENT_CONTEXT(ctx
);
2129 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2131 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2133 #if FEATURE_convolve
2134 if (_mesa_is_color_format(internalFormat
)) {
2135 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2139 if (target
== GL_TEXTURE_1D
) {
2140 /* non-proxy target */
2141 struct gl_texture_unit
*texUnit
;
2142 struct gl_texture_object
*texObj
;
2143 struct gl_texture_image
*texImage
;
2144 const GLuint face
= _mesa_tex_target_to_face(target
);
2146 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2147 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2148 return; /* error was recorded */
2151 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2152 _mesa_update_state(ctx
);
2154 texUnit
= _mesa_get_current_tex_unit(ctx
);
2155 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2156 _mesa_lock_texture(ctx
, texObj
);
2158 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2160 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2164 if (texImage
->Data
) {
2165 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2168 ASSERT(texImage
->Data
== NULL
);
2170 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2171 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2172 postConvWidth
, 1, 1,
2173 border
, internalFormat
);
2175 ASSERT(ctx
->Driver
.TexImage1D
);
2177 /* Give the texture to the driver! <pixels> may be null! */
2178 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2179 width
, border
, format
, type
, pixels
,
2180 &ctx
->Unpack
, texObj
, texImage
);
2182 ASSERT(texImage
->TexFormat
);
2184 update_fbo_texture(ctx
, texObj
, face
, level
);
2187 texObj
->_Complete
= GL_FALSE
;
2188 ctx
->NewState
|= _NEW_TEXTURE
;
2191 _mesa_unlock_texture(ctx
, texObj
);
2193 else if (target
== GL_PROXY_TEXTURE_1D
) {
2194 /* Proxy texture: check for errors and update proxy state */
2195 struct gl_texture_image
*texImage
;
2196 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2197 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2198 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2199 /* when error, clear all proxy texture image parameters */
2201 clear_teximage_fields(texImage
);
2204 /* no error, set the tex image parameters */
2206 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2207 postConvWidth
, 1, 1,
2208 border
, internalFormat
);
2209 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2210 internalFormat
, format
, type
);
2214 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2221 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2222 GLsizei width
, GLsizei height
, GLint border
,
2223 GLenum format
, GLenum type
,
2224 const GLvoid
*pixels
)
2226 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2227 GET_CURRENT_CONTEXT(ctx
);
2228 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2230 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2232 #if FEATURE_convolve
2233 if (_mesa_is_color_format(internalFormat
)) {
2234 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2239 if (target
== GL_TEXTURE_2D
||
2240 (ctx
->Extensions
.ARB_texture_cube_map
&&
2241 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2242 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2243 (ctx
->Extensions
.NV_texture_rectangle
&&
2244 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2245 (ctx
->Extensions
.MESA_texture_array
&&
2246 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2247 /* non-proxy target */
2248 struct gl_texture_unit
*texUnit
;
2249 struct gl_texture_object
*texObj
;
2250 struct gl_texture_image
*texImage
;
2251 const GLuint face
= _mesa_tex_target_to_face(target
);
2253 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2254 format
, type
, 2, postConvWidth
, postConvHeight
,
2256 return; /* error was recorded */
2259 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2260 _mesa_update_state(ctx
);
2262 texUnit
= _mesa_get_current_tex_unit(ctx
);
2263 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2264 _mesa_lock_texture(ctx
, texObj
);
2266 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2268 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2272 if (texImage
->Data
) {
2273 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2276 ASSERT(texImage
->Data
== NULL
);
2277 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2278 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2279 postConvWidth
, postConvHeight
, 1,
2280 border
, internalFormat
);
2282 ASSERT(ctx
->Driver
.TexImage2D
);
2284 /* Give the texture to the driver! <pixels> may be null! */
2285 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2286 width
, height
, border
, format
, type
, pixels
,
2287 &ctx
->Unpack
, texObj
, texImage
);
2289 ASSERT(texImage
->TexFormat
);
2291 update_fbo_texture(ctx
, texObj
, face
, level
);
2294 texObj
->_Complete
= GL_FALSE
;
2295 ctx
->NewState
|= _NEW_TEXTURE
;
2298 _mesa_unlock_texture(ctx
, texObj
);
2300 else if (target
== GL_PROXY_TEXTURE_2D
||
2301 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2302 ctx
->Extensions
.ARB_texture_cube_map
) ||
2303 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2304 ctx
->Extensions
.NV_texture_rectangle
) ||
2305 (ctx
->Extensions
.MESA_texture_array
&&
2306 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2307 /* Proxy texture: check for errors and update proxy state */
2308 struct gl_texture_image
*texImage
;
2309 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2310 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2311 format
, type
, 2, postConvWidth
, postConvHeight
,
2313 /* when error, clear all proxy texture image parameters */
2315 clear_teximage_fields(texImage
);
2318 /* no error, set the tex image parameters */
2319 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2320 postConvWidth
, postConvHeight
, 1,
2321 border
, internalFormat
);
2322 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2323 internalFormat
, format
, type
);
2327 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2334 * Called by the API or display list executor.
2335 * Note that width and height include the border.
2338 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2339 GLsizei width
, GLsizei height
, GLsizei depth
,
2340 GLint border
, GLenum format
, GLenum type
,
2341 const GLvoid
*pixels
)
2343 GET_CURRENT_CONTEXT(ctx
);
2344 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2346 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2348 if (target
== GL_TEXTURE_3D
||
2349 (ctx
->Extensions
.MESA_texture_array
&&
2350 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2351 /* non-proxy target */
2352 struct gl_texture_unit
*texUnit
;
2353 struct gl_texture_object
*texObj
;
2354 struct gl_texture_image
*texImage
;
2355 const GLuint face
= _mesa_tex_target_to_face(target
);
2357 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2358 format
, type
, 3, width
, height
, depth
, border
)) {
2359 return; /* error was recorded */
2362 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2363 _mesa_update_state(ctx
);
2365 texUnit
= _mesa_get_current_tex_unit(ctx
);
2366 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2367 _mesa_lock_texture(ctx
, texObj
);
2369 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2371 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2375 if (texImage
->Data
) {
2376 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2379 ASSERT(texImage
->Data
== NULL
);
2380 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2381 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2382 width
, height
, depth
,
2383 border
, internalFormat
);
2385 ASSERT(ctx
->Driver
.TexImage3D
);
2387 /* Give the texture to the driver! <pixels> may be null! */
2388 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2389 width
, height
, depth
, border
, format
, type
,
2390 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2392 ASSERT(texImage
->TexFormat
);
2394 update_fbo_texture(ctx
, texObj
, face
, level
);
2397 texObj
->_Complete
= GL_FALSE
;
2398 ctx
->NewState
|= _NEW_TEXTURE
;
2401 _mesa_unlock_texture(ctx
, texObj
);
2403 else if (target
== GL_PROXY_TEXTURE_3D
||
2404 (ctx
->Extensions
.MESA_texture_array
&&
2405 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2406 /* Proxy texture: check for errors and update proxy state */
2407 struct gl_texture_image
*texImage
;
2408 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2409 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2410 format
, type
, 3, width
, height
, depth
, border
)) {
2411 /* when error, clear all proxy texture image parameters */
2413 clear_teximage_fields(texImage
);
2416 /* no error, set the tex image parameters */
2417 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2418 depth
, border
, internalFormat
);
2419 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2420 internalFormat
, format
, type
);
2424 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2431 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2432 GLsizei width
, GLsizei height
, GLsizei depth
,
2433 GLint border
, GLenum format
, GLenum type
,
2434 const GLvoid
*pixels
)
2436 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2437 depth
, border
, format
, type
, pixels
);
2443 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2444 GLint xoffset
, GLsizei width
,
2445 GLenum format
, GLenum type
,
2446 const GLvoid
*pixels
)
2448 GLsizei postConvWidth
= width
;
2449 struct gl_texture_unit
*texUnit
;
2450 struct gl_texture_object
*texObj
;
2451 struct gl_texture_image
*texImage
= NULL
;
2452 GET_CURRENT_CONTEXT(ctx
);
2453 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2455 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2456 _mesa_update_state(ctx
);
2458 #if FEATURE_convolve
2459 /* XXX should test internal format */
2460 if (_mesa_is_color_format(format
)) {
2461 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2465 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2466 postConvWidth
, 1, 1, format
, type
)) {
2467 return; /* error was detected */
2471 texUnit
= _mesa_get_current_tex_unit(ctx
);
2472 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2475 _mesa_lock_texture(ctx
, texObj
);
2477 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2479 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2480 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2481 goto out
; /* error was detected */
2485 goto out
; /* no-op, not an error */
2487 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2488 xoffset
+= texImage
->Border
;
2490 ASSERT(ctx
->Driver
.TexSubImage1D
);
2491 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2492 format
, type
, pixels
, &ctx
->Unpack
,
2494 ctx
->NewState
|= _NEW_TEXTURE
;
2497 _mesa_unlock_texture(ctx
, texObj
);
2502 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2503 GLint xoffset
, GLint yoffset
,
2504 GLsizei width
, GLsizei height
,
2505 GLenum format
, GLenum type
,
2506 const GLvoid
*pixels
)
2508 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2509 struct gl_texture_unit
*texUnit
;
2510 struct gl_texture_object
*texObj
;
2511 struct gl_texture_image
*texImage
;
2512 GET_CURRENT_CONTEXT(ctx
);
2513 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2515 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2516 _mesa_update_state(ctx
);
2518 #if FEATURE_convolve
2519 /* XXX should test internal format */
2520 if (_mesa_is_color_format(format
)) {
2521 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2526 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2527 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2528 return; /* error was detected */
2531 texUnit
= _mesa_get_current_tex_unit(ctx
);
2532 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2533 _mesa_lock_texture(ctx
, texObj
);
2535 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2537 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2538 postConvWidth
, postConvHeight
, 1, format
, type
,
2540 goto out
; /* error was detected */
2543 if (width
== 0 || height
== 0)
2544 goto out
; /* no-op, not an error */
2546 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2547 xoffset
+= texImage
->Border
;
2548 yoffset
+= texImage
->Border
;
2550 ASSERT(ctx
->Driver
.TexSubImage2D
);
2551 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2552 width
, height
, format
, type
, pixels
,
2553 &ctx
->Unpack
, texObj
, texImage
);
2554 ctx
->NewState
|= _NEW_TEXTURE
;
2557 _mesa_unlock_texture(ctx
, texObj
);
2563 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2564 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2565 GLsizei width
, GLsizei height
, GLsizei depth
,
2566 GLenum format
, GLenum type
,
2567 const GLvoid
*pixels
)
2569 struct gl_texture_unit
*texUnit
;
2570 struct gl_texture_object
*texObj
;
2571 struct gl_texture_image
*texImage
;
2572 GET_CURRENT_CONTEXT(ctx
);
2573 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2575 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2576 _mesa_update_state(ctx
);
2578 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2579 width
, height
, depth
, format
, type
)) {
2580 return; /* error was detected */
2583 texUnit
= _mesa_get_current_tex_unit(ctx
);
2584 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2586 _mesa_lock_texture(ctx
, texObj
);
2588 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2590 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2591 width
, height
, depth
, format
, type
, texImage
)) {
2592 goto out
; /* error was detected */
2595 if (width
== 0 || height
== 0 || height
== 0)
2596 goto out
; /* no-op, not an error */
2598 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2599 xoffset
+= texImage
->Border
;
2600 yoffset
+= texImage
->Border
;
2601 zoffset
+= texImage
->Border
;
2603 ASSERT(ctx
->Driver
.TexSubImage3D
);
2604 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2605 xoffset
, yoffset
, zoffset
,
2606 width
, height
, depth
,
2607 format
, type
, pixels
,
2608 &ctx
->Unpack
, texObj
, texImage
);
2609 ctx
->NewState
|= _NEW_TEXTURE
;
2612 _mesa_unlock_texture(ctx
, texObj
);
2618 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2619 GLenum internalFormat
,
2621 GLsizei width
, GLint border
)
2623 struct gl_texture_unit
*texUnit
;
2624 struct gl_texture_object
*texObj
;
2625 struct gl_texture_image
*texImage
;
2626 GLsizei postConvWidth
= width
;
2627 const GLuint face
= _mesa_tex_target_to_face(target
);
2628 GET_CURRENT_CONTEXT(ctx
);
2629 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2631 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2632 _mesa_update_state(ctx
);
2634 #if FEATURE_convolve
2635 if (_mesa_is_color_format(internalFormat
)) {
2636 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2640 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2641 postConvWidth
, 1, border
))
2644 texUnit
= _mesa_get_current_tex_unit(ctx
);
2645 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2646 _mesa_lock_texture(ctx
, texObj
);
2648 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2650 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2654 if (texImage
->Data
) {
2655 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2658 ASSERT(texImage
->Data
== NULL
);
2660 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2661 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2662 border
, internalFormat
);
2665 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2666 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2667 x
, y
, width
, border
);
2669 ASSERT(texImage
->TexFormat
);
2671 update_fbo_texture(ctx
, texObj
, face
, level
);
2674 texObj
->_Complete
= GL_FALSE
;
2675 ctx
->NewState
|= _NEW_TEXTURE
;
2678 _mesa_unlock_texture(ctx
, texObj
);
2684 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2685 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2688 struct gl_texture_unit
*texUnit
;
2689 struct gl_texture_object
*texObj
;
2690 struct gl_texture_image
*texImage
;
2691 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2692 const GLuint face
= _mesa_tex_target_to_face(target
);
2693 GET_CURRENT_CONTEXT(ctx
);
2694 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2696 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2697 _mesa_update_state(ctx
);
2699 #if FEATURE_convolve
2700 if (_mesa_is_color_format(internalFormat
)) {
2701 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2706 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2707 postConvWidth
, postConvHeight
, border
))
2710 texUnit
= _mesa_get_current_tex_unit(ctx
);
2711 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2713 _mesa_lock_texture(ctx
, texObj
);
2715 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2718 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2722 if (texImage
->Data
) {
2723 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2726 ASSERT(texImage
->Data
== NULL
);
2728 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2729 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2730 postConvWidth
, postConvHeight
, 1,
2731 border
, internalFormat
);
2733 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2734 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
2735 x
, y
, width
, height
, border
);
2737 ASSERT(texImage
->TexFormat
);
2739 update_fbo_texture(ctx
, texObj
, face
, level
);
2742 texObj
->_Complete
= GL_FALSE
;
2743 ctx
->NewState
|= _NEW_TEXTURE
;
2746 _mesa_unlock_texture(ctx
, texObj
);
2751 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2752 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2754 struct gl_texture_unit
*texUnit
;
2755 struct gl_texture_object
*texObj
;
2756 struct gl_texture_image
*texImage
;
2757 GLsizei postConvWidth
= width
;
2761 GET_CURRENT_CONTEXT(ctx
);
2762 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2764 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2765 _mesa_update_state(ctx
);
2767 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2770 texUnit
= _mesa_get_current_tex_unit(ctx
);
2771 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2773 _mesa_lock_texture(ctx
, texObj
);
2775 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2777 #if FEATURE_convolve
2778 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2779 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2783 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2784 xoffset
, 0, 0, postConvWidth
, 1,
2789 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2790 xoffset
+= texImage
->Border
;
2792 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2794 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2795 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2796 xoffset
, x
, y
, width
);
2799 ctx
->NewState
|= _NEW_TEXTURE
;
2802 _mesa_unlock_texture(ctx
, texObj
);
2808 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2809 GLint xoffset
, GLint yoffset
,
2810 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2812 struct gl_texture_unit
*texUnit
;
2813 struct gl_texture_object
*texObj
;
2814 struct gl_texture_image
*texImage
;
2815 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2816 GET_CURRENT_CONTEXT(ctx
);
2817 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2819 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2820 _mesa_update_state(ctx
);
2822 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2825 texUnit
= _mesa_get_current_tex_unit(ctx
);
2826 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2828 _mesa_lock_texture(ctx
, texObj
);
2830 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2832 #if FEATURE_convolve
2833 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2834 _mesa_adjust_image_for_convolution(ctx
, 2,
2835 &postConvWidth
, &postConvHeight
);
2839 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2840 postConvWidth
, postConvHeight
, texImage
))
2843 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2844 xoffset
+= texImage
->Border
;
2845 yoffset
+= texImage
->Border
;
2847 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2849 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2850 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2851 xoffset
, yoffset
, x
, y
, width
, height
);
2854 ctx
->NewState
|= _NEW_TEXTURE
;
2857 _mesa_unlock_texture(ctx
, texObj
);
2863 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2864 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2865 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2867 struct gl_texture_unit
*texUnit
;
2868 struct gl_texture_object
*texObj
;
2869 struct gl_texture_image
*texImage
;
2870 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2871 GET_CURRENT_CONTEXT(ctx
);
2872 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2874 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2875 _mesa_update_state(ctx
);
2877 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2880 texUnit
= _mesa_get_current_tex_unit(ctx
);
2881 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2883 _mesa_lock_texture(ctx
, texObj
);
2885 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2887 #if FEATURE_convolve
2888 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2889 _mesa_adjust_image_for_convolution(ctx
, 2,
2890 &postConvWidth
, &postConvHeight
);
2894 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2895 zoffset
, postConvWidth
, postConvHeight
,
2899 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2900 xoffset
+= texImage
->Border
;
2901 yoffset
+= texImage
->Border
;
2902 zoffset
+= texImage
->Border
;
2904 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2906 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2907 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2908 xoffset
, yoffset
, zoffset
,
2909 x
, y
, width
, height
);
2912 ctx
->NewState
|= _NEW_TEXTURE
;
2915 _mesa_unlock_texture(ctx
, texObj
);
2921 /**********************************************************************/
2922 /****** Compressed Textures ******/
2923 /**********************************************************************/
2927 * Error checking for glCompressedTexImage[123]D().
2928 * \return error code or GL_NO_ERROR.
2931 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
2932 GLenum target
, GLint level
,
2933 GLenum internalFormat
, GLsizei width
,
2934 GLsizei height
, GLsizei depth
, GLint border
,
2937 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
2939 if (dimensions
== 1) {
2940 /* 1D compressed textures not allowed */
2941 return GL_INVALID_ENUM
;
2943 else if (dimensions
== 2) {
2944 if (target
== GL_PROXY_TEXTURE_2D
) {
2945 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2947 else if (target
== GL_TEXTURE_2D
) {
2948 maxLevels
= ctx
->Const
.MaxTextureLevels
;
2950 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
2951 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2952 return GL_INVALID_ENUM
; /*target*/
2953 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2955 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2956 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
2957 if (!ctx
->Extensions
.ARB_texture_cube_map
)
2958 return GL_INVALID_ENUM
; /*target*/
2959 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
2962 return GL_INVALID_ENUM
; /*target*/
2965 else if (dimensions
== 3) {
2966 /* 3D compressed textures not allowed */
2967 return GL_INVALID_ENUM
;
2970 maxTextureSize
= 1 << (maxLevels
- 1);
2972 /* This will detect any invalid internalFormat value */
2973 if (!is_compressed_format(ctx
, internalFormat
))
2974 return GL_INVALID_ENUM
;
2976 /* This should really never fail */
2977 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
2978 return GL_INVALID_ENUM
;
2981 return GL_INVALID_VALUE
;
2984 * XXX We should probably use the proxy texture error check function here.
2986 if (width
< 1 || width
> maxTextureSize
||
2987 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
2988 return GL_INVALID_VALUE
;
2990 if ((height
< 1 || height
> maxTextureSize
||
2991 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
2993 return GL_INVALID_VALUE
;
2995 if ((depth
< 1 || depth
> maxTextureSize
||
2996 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
2998 return GL_INVALID_VALUE
;
3000 /* For cube map, width must equal height */
3001 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3002 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3003 return GL_INVALID_VALUE
;
3005 if (level
< 0 || level
>= maxLevels
)
3006 return GL_INVALID_VALUE
;
3008 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3009 depth
, internalFormat
);
3010 if (expectedSize
!= imageSize
)
3011 return GL_INVALID_VALUE
;
3013 #if FEATURE_EXT_texture_sRGB
3014 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3015 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3016 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3017 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3019 return GL_INVALID_OPERATION
;
3028 * Error checking for glCompressedTexSubImage[123]D().
3029 * \warning There are some bad assumptions here about the size of compressed
3030 * texture tiles (multiple of 4) used to test the validity of the
3031 * offset and size parameters.
3032 * \return error code or GL_NO_ERROR.
3035 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3036 GLenum target
, GLint level
,
3037 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3038 GLsizei width
, GLsizei height
, GLsizei depth
,
3039 GLenum format
, GLsizei imageSize
)
3041 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3044 if (dimensions
== 1) {
3045 /* 1D compressed textures not allowed */
3046 return GL_INVALID_ENUM
;
3048 else if (dimensions
== 2) {
3049 if (target
== GL_PROXY_TEXTURE_2D
) {
3050 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3052 else if (target
== GL_TEXTURE_2D
) {
3053 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3055 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3056 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3057 return GL_INVALID_ENUM
; /*target*/
3058 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3060 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3061 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3062 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3063 return GL_INVALID_ENUM
; /*target*/
3064 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3067 return GL_INVALID_ENUM
; /*target*/
3070 else if (dimensions
== 3) {
3071 /* 3D compressed textures not allowed */
3072 return GL_INVALID_ENUM
;
3075 maxTextureSize
= 1 << (maxLevels
- 1);
3077 /* this will catch any invalid compressed format token */
3078 if (!is_compressed_format(ctx
, format
))
3079 return GL_INVALID_ENUM
;
3081 if (width
< 1 || width
> maxTextureSize
)
3082 return GL_INVALID_VALUE
;
3084 if ((height
< 1 || height
> maxTextureSize
)
3086 return GL_INVALID_VALUE
;
3088 if (level
< 0 || level
>= maxLevels
)
3089 return GL_INVALID_VALUE
;
3091 /* XXX these tests are specific to the compressed format.
3092 * this code should be generalized in some way.
3094 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3095 return GL_INVALID_VALUE
;
3097 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3098 return GL_INVALID_VALUE
;
3100 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3101 return GL_INVALID_VALUE
;
3103 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3105 if (expectedSize
!= imageSize
)
3106 return GL_INVALID_VALUE
;
3114 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3115 GLenum internalFormat
, GLsizei width
,
3116 GLint border
, GLsizei imageSize
,
3119 GET_CURRENT_CONTEXT(ctx
);
3120 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3122 if (target
== GL_TEXTURE_1D
) {
3123 /* non-proxy target */
3124 struct gl_texture_unit
*texUnit
;
3125 struct gl_texture_object
*texObj
;
3126 struct gl_texture_image
*texImage
;
3127 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3128 internalFormat
, width
, 1, 1, border
, imageSize
);
3130 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3134 texUnit
= _mesa_get_current_tex_unit(ctx
);
3135 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3137 _mesa_lock_texture(ctx
, texObj
);
3139 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3141 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3145 if (texImage
->Data
) {
3146 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3148 ASSERT(texImage
->Data
== NULL
);
3150 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3151 border
, internalFormat
);
3153 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3154 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3155 internalFormat
, width
, border
,
3160 texObj
->_Complete
= GL_FALSE
;
3161 ctx
->NewState
|= _NEW_TEXTURE
;
3164 _mesa_unlock_texture(ctx
, texObj
);
3166 else if (target
== GL_PROXY_TEXTURE_1D
) {
3167 /* Proxy texture: check for errors and update proxy state */
3168 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3169 internalFormat
, width
, 1, 1, border
, imageSize
);
3171 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3172 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3173 internalFormat
, GL_NONE
, GL_NONE
,
3174 width
, 1, 1, border
);
3177 /* if error, clear all proxy texture image parameters */
3178 struct gl_texture_image
*texImage
;
3179 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3181 clear_teximage_fields(texImage
);
3184 /* store the teximage parameters */
3185 struct gl_texture_unit
*texUnit
;
3186 struct gl_texture_object
*texObj
;
3187 struct gl_texture_image
*texImage
;
3188 texUnit
= _mesa_get_current_tex_unit(ctx
);
3189 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3191 _mesa_lock_texture(ctx
, texObj
);
3193 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3194 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3195 border
, internalFormat
);
3197 _mesa_unlock_texture(ctx
, texObj
);
3201 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3208 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3209 GLenum internalFormat
, GLsizei width
,
3210 GLsizei height
, GLint border
, GLsizei imageSize
,
3213 GET_CURRENT_CONTEXT(ctx
);
3214 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3216 if (target
== GL_TEXTURE_2D
||
3217 (ctx
->Extensions
.ARB_texture_cube_map
&&
3218 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3219 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3220 /* non-proxy target */
3221 struct gl_texture_unit
*texUnit
;
3222 struct gl_texture_object
*texObj
;
3223 struct gl_texture_image
*texImage
;
3224 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3225 internalFormat
, width
, height
, 1, border
, imageSize
);
3227 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3231 texUnit
= _mesa_get_current_tex_unit(ctx
);
3232 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3234 _mesa_lock_texture(ctx
, texObj
);
3236 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3238 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3242 if (texImage
->Data
) {
3243 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3245 ASSERT(texImage
->Data
== NULL
);
3247 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3248 border
, internalFormat
);
3250 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3251 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3252 internalFormat
, width
, height
,
3253 border
, imageSize
, data
,
3257 texObj
->_Complete
= GL_FALSE
;
3258 ctx
->NewState
|= _NEW_TEXTURE
;
3261 _mesa_unlock_texture(ctx
, texObj
);
3263 else if (target
== GL_PROXY_TEXTURE_2D
||
3264 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3265 ctx
->Extensions
.ARB_texture_cube_map
)) {
3266 /* Proxy texture: check for errors and update proxy state */
3267 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3268 internalFormat
, width
, height
, 1, border
, imageSize
);
3270 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3271 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3272 internalFormat
, GL_NONE
, GL_NONE
,
3273 width
, height
, 1, border
);
3276 /* if error, clear all proxy texture image parameters */
3277 struct gl_texture_image
*texImage
;
3278 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3280 clear_teximage_fields(texImage
);
3283 /* store the teximage parameters */
3284 struct gl_texture_unit
*texUnit
;
3285 struct gl_texture_object
*texObj
;
3286 struct gl_texture_image
*texImage
;
3287 texUnit
= _mesa_get_current_tex_unit(ctx
);
3288 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3290 _mesa_lock_texture(ctx
, texObj
);
3292 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3293 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3294 border
, internalFormat
);
3296 _mesa_unlock_texture(ctx
, texObj
);
3300 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3307 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3308 GLenum internalFormat
, GLsizei width
,
3309 GLsizei height
, GLsizei depth
, GLint border
,
3310 GLsizei imageSize
, const GLvoid
*data
)
3312 GET_CURRENT_CONTEXT(ctx
);
3313 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3315 if (target
== GL_TEXTURE_3D
) {
3316 /* non-proxy target */
3317 struct gl_texture_unit
*texUnit
;
3318 struct gl_texture_object
*texObj
;
3319 struct gl_texture_image
*texImage
;
3320 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3321 internalFormat
, width
, height
, depth
, border
, imageSize
);
3323 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3327 texUnit
= _mesa_get_current_tex_unit(ctx
);
3328 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3329 _mesa_lock_texture(ctx
, texObj
);
3331 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3333 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3337 if (texImage
->Data
) {
3338 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3340 ASSERT(texImage
->Data
== NULL
);
3342 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3343 border
, internalFormat
);
3345 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3346 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3348 width
, height
, depth
,
3349 border
, imageSize
, data
,
3353 texObj
->_Complete
= GL_FALSE
;
3354 ctx
->NewState
|= _NEW_TEXTURE
;
3357 _mesa_unlock_texture(ctx
, texObj
);
3359 else if (target
== GL_PROXY_TEXTURE_3D
) {
3360 /* Proxy texture: check for errors and update proxy state */
3361 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3362 internalFormat
, width
, height
, depth
, border
, imageSize
);
3364 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3365 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3366 internalFormat
, GL_NONE
, GL_NONE
,
3367 width
, height
, depth
, border
);
3370 /* if error, clear all proxy texture image parameters */
3371 struct gl_texture_image
*texImage
;
3372 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3374 clear_teximage_fields(texImage
);
3377 /* store the teximage parameters */
3378 struct gl_texture_unit
*texUnit
;
3379 struct gl_texture_object
*texObj
;
3380 struct gl_texture_image
*texImage
;
3381 texUnit
= _mesa_get_current_tex_unit(ctx
);
3382 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3383 _mesa_lock_texture(ctx
, texObj
);
3385 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3386 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3387 depth
, border
, internalFormat
);
3389 _mesa_unlock_texture(ctx
, texObj
);
3393 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3400 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3401 GLsizei width
, GLenum format
,
3402 GLsizei imageSize
, const GLvoid
*data
)
3404 struct gl_texture_unit
*texUnit
;
3405 struct gl_texture_object
*texObj
;
3406 struct gl_texture_image
*texImage
;
3408 GET_CURRENT_CONTEXT(ctx
);
3409 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3411 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3412 xoffset
, 0, 0, /* pos */
3413 width
, 1, 1, /* size */
3416 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3420 texUnit
= _mesa_get_current_tex_unit(ctx
);
3421 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3422 _mesa_lock_texture(ctx
, texObj
);
3424 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3427 if ((GLint
) format
!= texImage
->InternalFormat
) {
3428 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3429 "glCompressedTexSubImage1D(format)");
3433 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3434 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3439 goto out
; /* no-op, not an error */
3441 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3442 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3444 format
, imageSize
, data
,
3447 ctx
->NewState
|= _NEW_TEXTURE
;
3450 _mesa_unlock_texture(ctx
, texObj
);
3455 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3456 GLint yoffset
, GLsizei width
, GLsizei height
,
3457 GLenum format
, GLsizei imageSize
,
3460 struct gl_texture_unit
*texUnit
;
3461 struct gl_texture_object
*texObj
;
3462 struct gl_texture_image
*texImage
;
3464 GET_CURRENT_CONTEXT(ctx
);
3465 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3467 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3468 xoffset
, yoffset
, 0, /* pos */
3469 width
, height
, 1, /* size */
3472 /* XXX proxy target? */
3473 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3477 texUnit
= _mesa_get_current_tex_unit(ctx
);
3478 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3479 _mesa_lock_texture(ctx
, texObj
);
3481 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3484 if ((GLint
) format
!= texImage
->InternalFormat
) {
3485 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3486 "glCompressedTexSubImage2D(format)");
3490 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3491 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3492 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3496 if (width
== 0 || height
== 0)
3497 goto out
; /* no-op, not an error */
3499 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3500 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3501 xoffset
, yoffset
, width
, height
,
3502 format
, imageSize
, data
,
3505 ctx
->NewState
|= _NEW_TEXTURE
;
3508 _mesa_unlock_texture(ctx
, texObj
);
3513 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3514 GLint yoffset
, GLint zoffset
, GLsizei width
,
3515 GLsizei height
, GLsizei depth
, GLenum format
,
3516 GLsizei imageSize
, const GLvoid
*data
)
3518 struct gl_texture_unit
*texUnit
;
3519 struct gl_texture_object
*texObj
;
3520 struct gl_texture_image
*texImage
;
3522 GET_CURRENT_CONTEXT(ctx
);
3523 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3525 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3526 xoffset
, yoffset
, zoffset
,/*pos*/
3527 width
, height
, depth
, /*size*/
3530 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3534 texUnit
= _mesa_get_current_tex_unit(ctx
);
3535 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3536 _mesa_lock_texture(ctx
, texObj
);
3538 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3541 if ((GLint
) format
!= texImage
->InternalFormat
) {
3542 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3543 "glCompressedTexSubImage3D(format)");
3547 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3548 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3549 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3550 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3554 if (width
== 0 || height
== 0 || depth
== 0)
3555 goto out
; /* no-op, not an error */
3557 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3558 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3559 xoffset
, yoffset
, zoffset
,
3560 width
, height
, depth
,
3561 format
, imageSize
, data
,
3564 ctx
->NewState
|= _NEW_TEXTURE
;
3567 _mesa_unlock_texture(ctx
, texObj
);