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"
39 #include "framebuffer.h"
45 #include "texcompress.h"
46 #include "texformat.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
65 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
69 _mesa_alloc_texmemory(GLsizei bytes
)
71 return _mesa_align_malloc(bytes
, 512);
76 * Free texture memory allocated with _mesa_alloc_texmemory()
79 _mesa_free_texmemory(void *m
)
88 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
90 #if CHAN_TYPE != GL_UNSIGNED_BYTE
91 _mesa_problem(NULL
, "PrintTexture not supported");
94 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
97 _mesa_printf("No texture data\n");
101 switch (img
->Format
) {
108 case GL_LUMINANCE_ALPHA
:
118 _mesa_problem(NULL
, "error in PrintTexture\n");
122 for (i
= 0; i
< img
->Height
; i
++) {
123 for (j
= 0; j
< img
->Width
; j
++) {
125 _mesa_printf("%02x ", data
[0]);
127 _mesa_printf("%02x%02x ", data
[0], data
[1]);
129 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
131 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
132 data
+= (img
->RowStride
- img
->Width
) * c
;
134 /* XXX use img->ImageStride here */
143 * Compute floor(log_base_2(n)).
144 * If n < 0 return -1.
173 * Return the simple base format for a given internal texture format.
174 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
176 * \param ctx GL context.
177 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
179 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
180 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
182 * This is the format which is used during texture application (i.e. the
183 * texture format and env mode determine the arithmetic used.
185 * XXX this could be static
188 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
190 switch (internalFormat
) {
205 case GL_LUMINANCE_ALPHA
:
206 case GL_LUMINANCE4_ALPHA4
:
207 case GL_LUMINANCE6_ALPHA2
:
208 case GL_LUMINANCE8_ALPHA8
:
209 case GL_LUMINANCE12_ALPHA4
:
210 case GL_LUMINANCE12_ALPHA12
:
211 case GL_LUMINANCE16_ALPHA16
:
212 return GL_LUMINANCE_ALPHA
;
243 if (ctx
->Extensions
.EXT_paletted_texture
) {
244 switch (internalFormat
) {
246 case GL_COLOR_INDEX1_EXT
:
247 case GL_COLOR_INDEX2_EXT
:
248 case GL_COLOR_INDEX4_EXT
:
249 case GL_COLOR_INDEX8_EXT
:
250 case GL_COLOR_INDEX12_EXT
:
251 case GL_COLOR_INDEX16_EXT
:
252 return GL_COLOR_INDEX
;
258 if (ctx
->Extensions
.ARB_depth_texture
) {
259 switch (internalFormat
) {
260 case GL_DEPTH_COMPONENT
:
261 case GL_DEPTH_COMPONENT16
:
262 case GL_DEPTH_COMPONENT24
:
263 case GL_DEPTH_COMPONENT32
:
264 return GL_DEPTH_COMPONENT
;
270 switch (internalFormat
) {
271 case GL_COMPRESSED_ALPHA
:
273 case GL_COMPRESSED_LUMINANCE
:
275 case GL_COMPRESSED_LUMINANCE_ALPHA
:
276 return GL_LUMINANCE_ALPHA
;
277 case GL_COMPRESSED_INTENSITY
:
279 case GL_COMPRESSED_RGB
:
281 case GL_COMPRESSED_RGBA
:
287 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
288 switch (internalFormat
) {
289 case GL_COMPRESSED_RGB_FXT1_3DFX
:
291 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
298 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
299 switch (internalFormat
) {
300 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
302 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
303 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
304 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
311 if (ctx
->Extensions
.S3_s3tc
) {
312 switch (internalFormat
) {
324 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
325 if (internalFormat
== GL_YCBCR_MESA
)
326 return GL_YCBCR_MESA
;
329 if (ctx
->Extensions
.ARB_texture_float
) {
330 switch (internalFormat
) {
331 case GL_ALPHA16F_ARB
:
332 case GL_ALPHA32F_ARB
:
340 case GL_INTENSITY16F_ARB
:
341 case GL_INTENSITY32F_ARB
:
343 case GL_LUMINANCE16F_ARB
:
344 case GL_LUMINANCE32F_ARB
:
346 case GL_LUMINANCE_ALPHA16F_ARB
:
347 case GL_LUMINANCE_ALPHA32F_ARB
:
348 return GL_LUMINANCE_ALPHA
;
354 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
355 switch (internalFormat
) {
364 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
365 switch (internalFormat
) {
374 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
375 switch (internalFormat
) {
376 case GL_DEPTH_STENCIL_EXT
:
377 case GL_DEPTH24_STENCIL8_EXT
:
378 return GL_DEPTH_STENCIL_EXT
;
384 #if FEATURE_EXT_texture_sRGB
385 if (ctx
->Extensions
.EXT_texture_sRGB
) {
386 switch (internalFormat
) {
389 case GL_COMPRESSED_SRGB_EXT
:
390 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
392 case GL_SRGB_ALPHA_EXT
:
393 case GL_SRGB8_ALPHA8_EXT
:
394 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
395 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
396 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
397 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
399 case GL_SLUMINANCE_ALPHA_EXT
:
400 case GL_SLUMINANCE8_ALPHA8_EXT
:
401 case GL_COMPRESSED_SLUMINANCE_EXT
:
402 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
403 return GL_LUMINANCE_ALPHA
;
404 case GL_SLUMINANCE_EXT
:
405 case GL_SLUMINANCE8_EXT
:
412 #endif /* FEATURE_EXT_texture_sRGB */
414 return -1; /* error */
419 * Test if it is a supported compressed format.
421 * \param internalFormat the internal format token provided by the user.
423 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
424 * GL_FALSE otherwise.
426 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
430 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
432 GLint supported
[100]; /* 100 should be plenty */
435 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
437 for (i
= 0; i
< n
; i
++) {
438 if ((GLint
) internalFormat
== supported
[i
]) {
447 * For cube map faces, return a face index in [0,5].
448 * For other targets return 0;
451 _mesa_tex_target_to_face(GLenum target
)
453 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
454 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
455 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
463 * Store a gl_texture_image pointer in a gl_texture_object structure
464 * according to the target and level parameters.
466 * \param tObj texture object.
467 * \param target texture target.
468 * \param level image level.
469 * \param texImage texture image.
471 * This was basically prompted by the introduction of cube maps.
474 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
475 GLenum target
, GLint level
,
476 struct gl_texture_image
*texImage
)
478 const GLuint face
= _mesa_tex_target_to_face(target
);
482 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
484 tObj
->Image
[face
][level
] = texImage
;
486 /* Set the 'back' pointer */
487 texImage
->TexObject
= tObj
;
492 * Allocate a texture image structure.
494 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
497 * \return a pointer to gl_texture_image struct with all fields initialized to
500 struct gl_texture_image
*
501 _mesa_new_texture_image( GLcontext
*ctx
)
504 return CALLOC_STRUCT(gl_texture_image
);
509 * Free texture image data.
510 * This function is a fallback called via ctx->Driver.FreeTexImageData().
512 * \param texImage texture image.
514 * Free the texture image data if it's not marked as client data.
517 _mesa_free_texture_image_data(GLcontext
*ctx
,
518 struct gl_texture_image
*texImage
)
522 if (texImage
->Data
&& !texImage
->IsClientData
) {
523 /* free the old texture data */
524 _mesa_free_texmemory(texImage
->Data
);
527 texImage
->Data
= NULL
;
532 * Free texture image.
534 * \param texImage texture image.
536 * Free the texture image structure and the associated image data.
539 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
541 /* Free texImage->Data and/or any other driver-specific texture
544 ASSERT(ctx
->Driver
.FreeTexImageData
);
545 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
547 ASSERT(texImage
->Data
== NULL
);
548 if (texImage
->ImageOffsets
)
549 _mesa_free(texImage
->ImageOffsets
);
550 _mesa_free(texImage
);
555 * Test if a target is a proxy target.
557 * \param target texture target.
559 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
562 _mesa_is_proxy_texture(GLenum target
)
564 /* NUM_TEXTURE_TARGETS should match number of terms below */
565 assert(NUM_TEXTURE_TARGETS
== 7);
567 return (target
== GL_PROXY_TEXTURE_1D
||
568 target
== GL_PROXY_TEXTURE_2D
||
569 target
== GL_PROXY_TEXTURE_3D
||
570 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
571 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
572 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
573 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
578 * Get the texture object that corresponds to the target of the given texture unit.
580 * \param ctx GL context.
581 * \param texUnit texture unit.
582 * \param target texture target.
584 * \return pointer to the texture object on success, or NULL on failure.
586 * \sa gl_texture_unit.
588 struct gl_texture_object
*
589 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
594 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
595 case GL_PROXY_TEXTURE_1D
:
596 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
598 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
599 case GL_PROXY_TEXTURE_2D
:
600 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
602 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
603 case GL_PROXY_TEXTURE_3D
:
604 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
605 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
606 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
607 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
608 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
609 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
610 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
611 case GL_TEXTURE_CUBE_MAP_ARB
:
612 return ctx
->Extensions
.ARB_texture_cube_map
613 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
614 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
615 return ctx
->Extensions
.ARB_texture_cube_map
616 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
617 case GL_TEXTURE_RECTANGLE_NV
:
618 return ctx
->Extensions
.NV_texture_rectangle
619 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
620 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
621 return ctx
->Extensions
.NV_texture_rectangle
622 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
623 case GL_TEXTURE_1D_ARRAY_EXT
:
624 return ctx
->Extensions
.MESA_texture_array
625 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
626 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
627 return ctx
->Extensions
.MESA_texture_array
628 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
629 case GL_TEXTURE_2D_ARRAY_EXT
:
630 return ctx
->Extensions
.MESA_texture_array
631 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
632 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
633 return ctx
->Extensions
.MESA_texture_array
634 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
636 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
643 * Get a texture image pointer from a texture object, given a texture
644 * target and mipmap level. The target and level parameters should
645 * have already been error-checked.
647 * \param ctx GL context.
648 * \param texObj texture unit.
649 * \param target texture target.
650 * \param level image level.
652 * \return pointer to the texture image structure, or NULL on failure.
654 struct gl_texture_image
*
655 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
656 GLenum target
, GLint level
)
658 const GLuint face
= _mesa_tex_target_to_face(target
);
662 ASSERT(level
< MAX_TEXTURE_LEVELS
);
664 return texObj
->Image
[face
][level
];
669 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
670 * it and install it. Only return NULL if passed a bad parameter or run
673 struct gl_texture_image
*
674 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
675 GLenum target
, GLint level
)
677 struct gl_texture_image
*texImage
;
682 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
684 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
686 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
690 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
698 * Return pointer to the specified proxy texture image.
699 * Note that proxy textures are per-context, not per-texture unit.
700 * \return pointer to texture image or NULL if invalid target, invalid
701 * level, or out of memory.
703 struct gl_texture_image
*
704 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
706 struct gl_texture_image
*texImage
;
713 case GL_PROXY_TEXTURE_1D
:
714 if (level
>= ctx
->Const
.MaxTextureLevels
)
716 texIndex
= TEXTURE_1D_INDEX
;
718 case GL_PROXY_TEXTURE_2D
:
719 if (level
>= ctx
->Const
.MaxTextureLevels
)
721 texIndex
= TEXTURE_2D_INDEX
;
723 case GL_PROXY_TEXTURE_3D
:
724 if (level
>= ctx
->Const
.Max3DTextureLevels
)
726 texIndex
= TEXTURE_3D_INDEX
;
728 case GL_PROXY_TEXTURE_CUBE_MAP
:
729 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
731 texIndex
= TEXTURE_CUBE_INDEX
;
733 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
736 texIndex
= TEXTURE_RECT_INDEX
;
738 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
739 if (level
>= ctx
->Const
.MaxTextureLevels
)
741 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
743 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
744 if (level
>= ctx
->Const
.MaxTextureLevels
)
746 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
752 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
754 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
756 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
759 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
760 /* Set the 'back' pointer */
761 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
768 * Get the maximum number of allowed mipmap levels.
770 * \param ctx GL context.
771 * \param target texture target.
773 * \return the maximum number of allowed mipmap levels for the given
774 * texture target, or zero if passed a bad target.
779 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
783 case GL_PROXY_TEXTURE_1D
:
785 case GL_PROXY_TEXTURE_2D
:
786 return ctx
->Const
.MaxTextureLevels
;
788 case GL_PROXY_TEXTURE_3D
:
789 return ctx
->Const
.Max3DTextureLevels
;
790 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
791 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
792 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
793 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
794 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
795 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
796 case GL_TEXTURE_CUBE_MAP_ARB
:
797 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
798 return ctx
->Extensions
.ARB_texture_cube_map
799 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
800 case GL_TEXTURE_RECTANGLE_NV
:
801 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
802 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
803 case GL_TEXTURE_1D_ARRAY_EXT
:
804 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
805 case GL_TEXTURE_2D_ARRAY_EXT
:
806 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
807 return ctx
->Extensions
.MESA_texture_array
808 ? ctx
->Const
.MaxTextureLevels
: 0;
810 return 0; /* bad target */
816 #if 000 /* not used anymore */
818 * glTexImage[123]D can accept a NULL image pointer. In this case we
819 * create a texture image with unspecified image contents per the OpenGL
823 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
825 const GLint components
= _mesa_components_in_format(format
);
826 const GLint numPixels
= width
* height
* depth
;
827 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
831 * Let's see if anyone finds this. If glTexImage2D() is called with
832 * a NULL image pointer then load the texture image with something
833 * interesting instead of leaving it indeterminate.
836 static const char message
[8][32] = {
840 " X X XXXX XXX XXXXX ",
843 " X X XXXXX XXX X X ",
847 GLubyte
*imgPtr
= data
;
849 for (h
= 0; h
< depth
; h
++) {
850 for (i
= 0; i
< height
; i
++) {
851 GLint srcRow
= 7 - (i
% 8);
852 for (j
= 0; j
< width
; j
++) {
853 GLint srcCol
= j
% 32;
854 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
855 for (k
= 0; k
< components
; k
++) {
871 * Reset the fields of a gl_texture_image struct to zero.
873 * \param img texture image structure.
875 * This is called when a proxy texture test fails, we set all the
876 * image members (except DriverData) to zero.
877 * It's also used in glTexImage[123]D as a safeguard to be sure all
878 * required fields get initialized properly by the Driver.TexImage[123]D
882 clear_teximage_fields(struct gl_texture_image
*img
)
885 img
->_BaseFormat
= 0;
886 img
->InternalFormat
= 0;
892 if (img
->ImageOffsets
) {
893 _mesa_free(img
->ImageOffsets
);
894 img
->ImageOffsets
= NULL
;
903 img
->TexFormat
= MESA_FORMAT_NONE
;
904 img
->FetchTexelc
= NULL
;
905 img
->FetchTexelf
= NULL
;
906 img
->CompressedSize
= 0;
911 * Initialize basic fields of the gl_texture_image struct.
913 * \param ctx GL context.
914 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
915 * \param img texture image structure to be initialized.
916 * \param width image width.
917 * \param height image height.
918 * \param depth image depth.
919 * \param border image border.
920 * \param internalFormat internal format.
922 * Fills in the fields of \p img with the given information.
923 * Note: width, height and depth include the border.
926 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
927 struct gl_texture_image
*img
,
928 GLsizei width
, GLsizei height
, GLsizei depth
,
929 GLint border
, GLenum internalFormat
)
938 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
939 ASSERT(img
->_BaseFormat
> 0);
940 img
->InternalFormat
= internalFormat
;
941 img
->Border
= border
;
943 img
->Height
= height
;
946 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
947 img
->WidthLog2
= logbase2(img
->Width2
);
949 if (height
== 1) { /* 1-D texture */
954 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
955 img
->HeightLog2
= logbase2(img
->Height2
);
958 if (depth
== 1) { /* 2-D texture */
963 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
964 img
->DepthLog2
= logbase2(img
->Depth2
);
967 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
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 (_mesa_is_format_compressed(destTex
->TexFormat
)) {
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 (_mesa_is_format_compressed(teximage
->TexFormat
)) {
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
);
2076 * If the texture object's GenerateMipmap flag is set and we've
2077 * changed the texture base level image, regenerate the rest of the
2078 * mipmap levels now.
2081 check_gen_mipmap(GLcontext
*ctx
, GLenum target
,
2082 struct gl_texture_object
*texObj
, GLint level
)
2084 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2085 if (texObj
->GenerateMipmap
&& level
== texObj
->BaseLevel
) {
2086 ASSERT(ctx
->Driver
.GenerateMipmap
);
2087 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2092 /** Debug helper: override the user-requested internal format */
2094 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2097 if (internalFormat
== GL_RGBA16F_ARB
||
2098 internalFormat
== GL_RGBA32F_ARB
) {
2099 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2102 else if (internalFormat
== GL_RGB16F_ARB
||
2103 internalFormat
== GL_RGB32F_ARB
) {
2104 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2107 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2108 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2109 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2110 return GL_LUMINANCE_ALPHA
;
2112 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2113 internalFormat
== GL_LUMINANCE32F_ARB
) {
2114 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2115 return GL_LUMINANCE
;
2117 else if (internalFormat
== GL_ALPHA16F_ARB
||
2118 internalFormat
== GL_ALPHA32F_ARB
) {
2119 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2123 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2124 internalFormat = GL_RGBA;
2128 return internalFormat
;
2131 return internalFormat
;
2137 * Called from the API. Note that width includes the border.
2140 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2141 GLsizei width
, GLint border
, GLenum format
,
2142 GLenum type
, const GLvoid
*pixels
)
2144 GLsizei postConvWidth
= width
;
2145 GET_CURRENT_CONTEXT(ctx
);
2146 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2148 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2149 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2150 _mesa_lookup_enum_by_nr(target
), level
,
2151 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2152 _mesa_lookup_enum_by_nr(format
),
2153 _mesa_lookup_enum_by_nr(type
), pixels
);
2155 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2157 #if FEATURE_convolve
2158 if (_mesa_is_color_format(internalFormat
)) {
2159 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2163 if (target
== GL_TEXTURE_1D
) {
2164 /* non-proxy target */
2165 struct gl_texture_unit
*texUnit
;
2166 struct gl_texture_object
*texObj
;
2167 struct gl_texture_image
*texImage
;
2168 const GLuint face
= _mesa_tex_target_to_face(target
);
2170 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2171 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2172 return; /* error was recorded */
2175 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2176 _mesa_update_state(ctx
);
2178 texUnit
= _mesa_get_current_tex_unit(ctx
);
2179 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2180 _mesa_lock_texture(ctx
, texObj
);
2182 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2184 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2187 if (texImage
->Data
) {
2188 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2191 ASSERT(texImage
->Data
== NULL
);
2193 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2194 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2195 postConvWidth
, 1, 1,
2196 border
, internalFormat
);
2198 /* Give the texture to the driver. <pixels> may be null. */
2199 ASSERT(ctx
->Driver
.TexImage1D
);
2200 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2201 width
, border
, format
, type
, pixels
,
2202 &ctx
->Unpack
, texObj
, texImage
);
2204 ASSERT(texImage
->TexFormat
);
2206 check_gen_mipmap(ctx
, target
, texObj
, level
);
2208 update_fbo_texture(ctx
, texObj
, face
, level
);
2211 texObj
->_Complete
= GL_FALSE
;
2212 ctx
->NewState
|= _NEW_TEXTURE
;
2215 _mesa_unlock_texture(ctx
, texObj
);
2217 else if (target
== GL_PROXY_TEXTURE_1D
) {
2218 /* Proxy texture: check for errors and update proxy state */
2219 struct gl_texture_image
*texImage
;
2220 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2221 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2222 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2223 /* when error, clear all proxy texture image parameters */
2225 clear_teximage_fields(texImage
);
2228 /* no error, set the tex image parameters */
2230 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2231 postConvWidth
, 1, 1,
2232 border
, internalFormat
);
2233 texImage
->TexFormat
=
2234 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2238 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2245 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2246 GLsizei width
, GLsizei height
, GLint border
,
2247 GLenum format
, GLenum type
,
2248 const GLvoid
*pixels
)
2250 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2251 GET_CURRENT_CONTEXT(ctx
);
2252 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2254 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2255 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2256 _mesa_lookup_enum_by_nr(target
), level
,
2257 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2258 border
, _mesa_lookup_enum_by_nr(format
),
2259 _mesa_lookup_enum_by_nr(type
), pixels
);
2261 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2263 #if FEATURE_convolve
2264 if (_mesa_is_color_format(internalFormat
)) {
2265 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2270 if (target
== GL_TEXTURE_2D
||
2271 (ctx
->Extensions
.ARB_texture_cube_map
&&
2272 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2273 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2274 (ctx
->Extensions
.NV_texture_rectangle
&&
2275 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2276 (ctx
->Extensions
.MESA_texture_array
&&
2277 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2278 /* non-proxy target */
2279 struct gl_texture_unit
*texUnit
;
2280 struct gl_texture_object
*texObj
;
2281 struct gl_texture_image
*texImage
;
2282 const GLuint face
= _mesa_tex_target_to_face(target
);
2284 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2285 format
, type
, 2, postConvWidth
, postConvHeight
,
2287 return; /* error was recorded */
2290 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2291 _mesa_update_state(ctx
);
2293 texUnit
= _mesa_get_current_tex_unit(ctx
);
2294 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2295 _mesa_lock_texture(ctx
, texObj
);
2297 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2299 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2302 if (texImage
->Data
) {
2303 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2306 ASSERT(texImage
->Data
== NULL
);
2307 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2308 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2309 postConvWidth
, postConvHeight
, 1,
2310 border
, internalFormat
);
2312 /* Give the texture to the driver. <pixels> may be null. */
2313 ASSERT(ctx
->Driver
.TexImage2D
);
2314 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2315 width
, height
, border
, format
, type
,
2316 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2318 ASSERT(texImage
->TexFormat
);
2320 check_gen_mipmap(ctx
, target
, texObj
, level
);
2322 update_fbo_texture(ctx
, texObj
, face
, level
);
2325 texObj
->_Complete
= GL_FALSE
;
2326 ctx
->NewState
|= _NEW_TEXTURE
;
2329 _mesa_unlock_texture(ctx
, texObj
);
2331 else if (target
== GL_PROXY_TEXTURE_2D
||
2332 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2333 ctx
->Extensions
.ARB_texture_cube_map
) ||
2334 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2335 ctx
->Extensions
.NV_texture_rectangle
) ||
2336 (ctx
->Extensions
.MESA_texture_array
&&
2337 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2338 /* Proxy texture: check for errors and update proxy state */
2339 struct gl_texture_image
*texImage
;
2340 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2341 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2342 format
, type
, 2, postConvWidth
, postConvHeight
,
2344 /* when error, clear all proxy texture image parameters */
2346 clear_teximage_fields(texImage
);
2349 /* no error, set the tex image parameters */
2350 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2351 postConvWidth
, postConvHeight
, 1,
2352 border
, internalFormat
);
2353 texImage
->TexFormat
=
2354 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2358 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2365 * Called by the API or display list executor.
2366 * Note that width and height include the border.
2369 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2370 GLsizei width
, GLsizei height
, GLsizei depth
,
2371 GLint border
, GLenum format
, GLenum type
,
2372 const GLvoid
*pixels
)
2374 GET_CURRENT_CONTEXT(ctx
);
2375 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2377 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2378 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2379 _mesa_lookup_enum_by_nr(target
), level
,
2380 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2381 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2382 _mesa_lookup_enum_by_nr(type
), pixels
);
2384 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2386 if (target
== GL_TEXTURE_3D
||
2387 (ctx
->Extensions
.MESA_texture_array
&&
2388 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2389 /* non-proxy target */
2390 struct gl_texture_unit
*texUnit
;
2391 struct gl_texture_object
*texObj
;
2392 struct gl_texture_image
*texImage
;
2393 const GLuint face
= _mesa_tex_target_to_face(target
);
2395 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2396 format
, type
, 3, width
, height
, depth
, border
)) {
2397 return; /* error was recorded */
2400 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2401 _mesa_update_state(ctx
);
2403 texUnit
= _mesa_get_current_tex_unit(ctx
);
2404 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2405 _mesa_lock_texture(ctx
, texObj
);
2407 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2409 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2412 if (texImage
->Data
) {
2413 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2416 ASSERT(texImage
->Data
== NULL
);
2417 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2418 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2419 width
, height
, depth
,
2420 border
, internalFormat
);
2422 /* Give the texture to the driver. <pixels> may be null. */
2423 ASSERT(ctx
->Driver
.TexImage3D
);
2424 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2425 width
, height
, depth
, border
, format
, type
,
2426 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2428 ASSERT(texImage
->TexFormat
);
2430 check_gen_mipmap(ctx
, target
, texObj
, level
);
2432 update_fbo_texture(ctx
, texObj
, face
, level
);
2435 texObj
->_Complete
= GL_FALSE
;
2436 ctx
->NewState
|= _NEW_TEXTURE
;
2439 _mesa_unlock_texture(ctx
, texObj
);
2441 else if (target
== GL_PROXY_TEXTURE_3D
||
2442 (ctx
->Extensions
.MESA_texture_array
&&
2443 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2444 /* Proxy texture: check for errors and update proxy state */
2445 struct gl_texture_image
*texImage
;
2446 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2447 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2448 format
, type
, 3, width
, height
, depth
, border
)) {
2449 /* when error, clear all proxy texture image parameters */
2451 clear_teximage_fields(texImage
);
2454 /* no error, set the tex image parameters */
2455 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2456 depth
, border
, internalFormat
);
2457 texImage
->TexFormat
=
2458 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2462 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2469 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2470 GLsizei width
, GLsizei height
, GLsizei depth
,
2471 GLint border
, GLenum format
, GLenum type
,
2472 const GLvoid
*pixels
)
2474 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2475 depth
, border
, format
, type
, pixels
);
2481 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2482 GLint xoffset
, GLsizei width
,
2483 GLenum format
, GLenum type
,
2484 const GLvoid
*pixels
)
2486 GLsizei postConvWidth
= width
;
2487 struct gl_texture_unit
*texUnit
;
2488 struct gl_texture_object
*texObj
;
2489 struct gl_texture_image
*texImage
= NULL
;
2490 GET_CURRENT_CONTEXT(ctx
);
2491 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2493 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2494 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2495 _mesa_lookup_enum_by_nr(target
), level
,
2496 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2497 _mesa_lookup_enum_by_nr(type
), pixels
);
2499 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2500 _mesa_update_state(ctx
);
2502 #if FEATURE_convolve
2503 /* XXX should test internal format */
2504 if (_mesa_is_color_format(format
)) {
2505 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2509 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2510 postConvWidth
, 1, 1, format
, type
)) {
2511 return; /* error was detected */
2515 texUnit
= _mesa_get_current_tex_unit(ctx
);
2516 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2519 _mesa_lock_texture(ctx
, texObj
);
2521 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2523 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2524 postConvWidth
, 1, 1,
2525 format
, type
, texImage
)) {
2526 /* error was recorded */
2528 else if (width
> 0) {
2529 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2530 xoffset
+= texImage
->Border
;
2532 ASSERT(ctx
->Driver
.TexSubImage1D
);
2533 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2534 format
, type
, pixels
, &ctx
->Unpack
,
2537 check_gen_mipmap(ctx
, target
, texObj
, level
);
2539 ctx
->NewState
|= _NEW_TEXTURE
;
2542 _mesa_unlock_texture(ctx
, texObj
);
2547 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2548 GLint xoffset
, GLint yoffset
,
2549 GLsizei width
, GLsizei height
,
2550 GLenum format
, GLenum type
,
2551 const GLvoid
*pixels
)
2553 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2554 struct gl_texture_unit
*texUnit
;
2555 struct gl_texture_object
*texObj
;
2556 struct gl_texture_image
*texImage
;
2557 GET_CURRENT_CONTEXT(ctx
);
2558 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2560 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2561 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2562 _mesa_lookup_enum_by_nr(target
), level
,
2563 xoffset
, yoffset
, width
, height
,
2564 _mesa_lookup_enum_by_nr(format
),
2565 _mesa_lookup_enum_by_nr(type
), pixels
);
2567 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2568 _mesa_update_state(ctx
);
2570 #if FEATURE_convolve
2571 /* XXX should test internal format */
2572 if (_mesa_is_color_format(format
)) {
2573 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2578 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2579 postConvWidth
, postConvHeight
, 1, 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
, 2, target
, level
, xoffset
, yoffset
, 0,
2591 postConvWidth
, postConvHeight
, 1,
2592 format
, type
, texImage
)) {
2593 /* error was recorded */
2595 else if (width
> 0 && height
>= 0) {
2596 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2597 xoffset
+= texImage
->Border
;
2598 yoffset
+= texImage
->Border
;
2600 ASSERT(ctx
->Driver
.TexSubImage2D
);
2601 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2602 width
, height
, format
, type
, pixels
,
2603 &ctx
->Unpack
, texObj
, texImage
);
2605 check_gen_mipmap(ctx
, target
, texObj
, level
);
2607 ctx
->NewState
|= _NEW_TEXTURE
;
2610 _mesa_unlock_texture(ctx
, texObj
);
2616 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2617 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2618 GLsizei width
, GLsizei height
, GLsizei depth
,
2619 GLenum format
, GLenum type
,
2620 const GLvoid
*pixels
)
2622 struct gl_texture_unit
*texUnit
;
2623 struct gl_texture_object
*texObj
;
2624 struct gl_texture_image
*texImage
;
2625 GET_CURRENT_CONTEXT(ctx
);
2626 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2628 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2629 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2630 _mesa_lookup_enum_by_nr(target
), level
,
2631 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2632 _mesa_lookup_enum_by_nr(format
),
2633 _mesa_lookup_enum_by_nr(type
), pixels
);
2635 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2636 _mesa_update_state(ctx
);
2638 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2639 width
, height
, depth
, format
, type
)) {
2640 return; /* error was detected */
2643 texUnit
= _mesa_get_current_tex_unit(ctx
);
2644 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2646 _mesa_lock_texture(ctx
, texObj
);
2648 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2650 if (subtexture_error_check2(ctx
, 3, target
, level
,
2651 xoffset
, yoffset
, zoffset
,
2652 width
, height
, depth
,
2653 format
, type
, texImage
)) {
2654 /* error was recorded */
2656 else if (width
> 0 && height
> 0 && height
> 0) {
2657 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2658 xoffset
+= texImage
->Border
;
2659 yoffset
+= texImage
->Border
;
2660 zoffset
+= texImage
->Border
;
2662 ASSERT(ctx
->Driver
.TexSubImage3D
);
2663 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2664 xoffset
, yoffset
, zoffset
,
2665 width
, height
, depth
,
2666 format
, type
, pixels
,
2667 &ctx
->Unpack
, texObj
, texImage
);
2669 check_gen_mipmap(ctx
, target
, texObj
, level
);
2671 ctx
->NewState
|= _NEW_TEXTURE
;
2674 _mesa_unlock_texture(ctx
, texObj
);
2680 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2681 GLenum internalFormat
,
2683 GLsizei width
, GLint border
)
2685 struct gl_texture_unit
*texUnit
;
2686 struct gl_texture_object
*texObj
;
2687 struct gl_texture_image
*texImage
;
2688 GLsizei postConvWidth
= width
;
2689 const GLuint face
= _mesa_tex_target_to_face(target
);
2690 GET_CURRENT_CONTEXT(ctx
);
2691 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2693 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2694 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2695 _mesa_lookup_enum_by_nr(target
), level
,
2696 _mesa_lookup_enum_by_nr(internalFormat
),
2697 x
, y
, width
, border
);
2699 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2700 _mesa_update_state(ctx
);
2702 #if FEATURE_convolve
2703 if (_mesa_is_color_format(internalFormat
)) {
2704 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2708 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2709 postConvWidth
, 1, border
))
2712 texUnit
= _mesa_get_current_tex_unit(ctx
);
2713 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2715 _mesa_lock_texture(ctx
, texObj
);
2717 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2719 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
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
, postConvWidth
, 1, 1,
2730 border
, internalFormat
);
2732 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2733 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2734 x
, y
, width
, border
);
2736 ASSERT(texImage
->TexFormat
);
2738 check_gen_mipmap(ctx
, target
, texObj
, level
);
2740 update_fbo_texture(ctx
, texObj
, face
, level
);
2743 texObj
->_Complete
= GL_FALSE
;
2744 ctx
->NewState
|= _NEW_TEXTURE
;
2747 _mesa_unlock_texture(ctx
, texObj
);
2753 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2754 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2757 struct gl_texture_unit
*texUnit
;
2758 struct gl_texture_object
*texObj
;
2759 struct gl_texture_image
*texImage
;
2760 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2761 const GLuint face
= _mesa_tex_target_to_face(target
);
2762 GET_CURRENT_CONTEXT(ctx
);
2763 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2765 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2766 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2767 _mesa_lookup_enum_by_nr(target
), level
,
2768 _mesa_lookup_enum_by_nr(internalFormat
),
2769 x
, y
, width
, height
, border
);
2771 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2772 _mesa_update_state(ctx
);
2774 #if FEATURE_convolve
2775 if (_mesa_is_color_format(internalFormat
)) {
2776 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2781 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2782 postConvWidth
, postConvHeight
, border
))
2785 texUnit
= _mesa_get_current_tex_unit(ctx
);
2786 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2788 _mesa_lock_texture(ctx
, texObj
);
2790 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2793 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2796 if (texImage
->Data
) {
2797 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2800 ASSERT(texImage
->Data
== NULL
);
2802 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2803 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2804 postConvWidth
, postConvHeight
, 1,
2805 border
, internalFormat
);
2807 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2808 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2809 x
, y
, width
, height
, border
);
2811 ASSERT(texImage
->TexFormat
);
2813 check_gen_mipmap(ctx
, target
, texObj
, level
);
2815 update_fbo_texture(ctx
, texObj
, face
, level
);
2818 texObj
->_Complete
= GL_FALSE
;
2819 ctx
->NewState
|= _NEW_TEXTURE
;
2822 _mesa_unlock_texture(ctx
, texObj
);
2827 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2828 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2830 struct gl_texture_unit
*texUnit
;
2831 struct gl_texture_object
*texObj
;
2832 struct gl_texture_image
*texImage
;
2833 GLsizei postConvWidth
= width
;
2837 GET_CURRENT_CONTEXT(ctx
);
2838 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2840 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2841 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2842 _mesa_lookup_enum_by_nr(target
),
2843 level
, xoffset
, x
, y
, width
);
2845 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2846 _mesa_update_state(ctx
);
2848 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2851 texUnit
= _mesa_get_current_tex_unit(ctx
);
2852 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2854 _mesa_lock_texture(ctx
, texObj
);
2856 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2858 #if FEATURE_convolve
2859 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2860 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2864 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2865 xoffset
, 0, 0, postConvWidth
, 1,
2867 /* error was recorded */
2870 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2871 xoffset
+= texImage
->Border
;
2873 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2875 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2876 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2877 xoffset
, x
, y
, width
);
2879 check_gen_mipmap(ctx
, target
, texObj
, level
);
2881 ctx
->NewState
|= _NEW_TEXTURE
;
2885 _mesa_unlock_texture(ctx
, texObj
);
2891 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2892 GLint xoffset
, GLint yoffset
,
2893 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2895 struct gl_texture_unit
*texUnit
;
2896 struct gl_texture_object
*texObj
;
2897 struct gl_texture_image
*texImage
;
2898 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2899 GET_CURRENT_CONTEXT(ctx
);
2900 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2902 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2903 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2904 _mesa_lookup_enum_by_nr(target
),
2905 level
, xoffset
, yoffset
, x
, y
, width
, height
);
2907 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2908 _mesa_update_state(ctx
);
2910 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2913 texUnit
= _mesa_get_current_tex_unit(ctx
);
2914 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2916 _mesa_lock_texture(ctx
, texObj
);
2918 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2920 #if FEATURE_convolve
2921 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2922 _mesa_adjust_image_for_convolution(ctx
, 2,
2923 &postConvWidth
, &postConvHeight
);
2927 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
2928 xoffset
, yoffset
, 0,
2929 postConvWidth
, postConvHeight
,
2931 /* error was recorded */
2934 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2935 xoffset
+= texImage
->Border
;
2936 yoffset
+= texImage
->Border
;
2938 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2940 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2941 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2942 x
, y
, width
, height
);
2944 check_gen_mipmap(ctx
, target
, texObj
, level
);
2946 ctx
->NewState
|= _NEW_TEXTURE
;
2950 _mesa_unlock_texture(ctx
, texObj
);
2956 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2957 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2958 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2960 struct gl_texture_unit
*texUnit
;
2961 struct gl_texture_object
*texObj
;
2962 struct gl_texture_image
*texImage
;
2963 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2964 GET_CURRENT_CONTEXT(ctx
);
2965 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2967 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2968 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
2969 _mesa_lookup_enum_by_nr(target
),
2970 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2972 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2973 _mesa_update_state(ctx
);
2975 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2978 texUnit
= _mesa_get_current_tex_unit(ctx
);
2979 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2981 _mesa_lock_texture(ctx
, texObj
);
2983 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2985 #if FEATURE_convolve
2986 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2987 _mesa_adjust_image_for_convolution(ctx
, 2,
2988 &postConvWidth
, &postConvHeight
);
2992 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2993 zoffset
, postConvWidth
, postConvHeight
,
2995 /* error was recored */
2998 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2999 xoffset
+= texImage
->Border
;
3000 yoffset
+= texImage
->Border
;
3001 zoffset
+= texImage
->Border
;
3003 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3005 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3006 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3007 xoffset
, yoffset
, zoffset
,
3008 x
, y
, width
, height
);
3010 check_gen_mipmap(ctx
, target
, texObj
, level
);
3012 ctx
->NewState
|= _NEW_TEXTURE
;
3016 _mesa_unlock_texture(ctx
, texObj
);
3022 /**********************************************************************/
3023 /****** Compressed Textures ******/
3024 /**********************************************************************/
3028 * Error checking for glCompressedTexImage[123]D().
3029 * \return error code or GL_NO_ERROR.
3032 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3033 GLenum target
, GLint level
,
3034 GLenum internalFormat
, GLsizei width
,
3035 GLsizei height
, GLsizei depth
, GLint border
,
3038 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3040 if (dimensions
== 1) {
3041 /* 1D compressed textures not allowed */
3042 return GL_INVALID_ENUM
;
3044 else if (dimensions
== 2) {
3045 if (target
== GL_PROXY_TEXTURE_2D
) {
3046 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3048 else if (target
== GL_TEXTURE_2D
) {
3049 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3051 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3052 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3053 return GL_INVALID_ENUM
; /*target*/
3054 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3056 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3057 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3058 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3059 return GL_INVALID_ENUM
; /*target*/
3060 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3063 return GL_INVALID_ENUM
; /*target*/
3066 else if (dimensions
== 3) {
3067 /* 3D compressed textures not allowed */
3068 return GL_INVALID_ENUM
;
3071 maxTextureSize
= 1 << (maxLevels
- 1);
3073 /* This will detect any invalid internalFormat value */
3074 if (!is_compressed_format(ctx
, internalFormat
))
3075 return GL_INVALID_ENUM
;
3077 /* This should really never fail */
3078 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3079 return GL_INVALID_ENUM
;
3082 return GL_INVALID_VALUE
;
3085 * XXX We should probably use the proxy texture error check function here.
3087 if (width
< 1 || width
> maxTextureSize
||
3088 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3089 return GL_INVALID_VALUE
;
3091 if ((height
< 1 || height
> maxTextureSize
||
3092 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3094 return GL_INVALID_VALUE
;
3096 if ((depth
< 1 || depth
> maxTextureSize
||
3097 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3099 return GL_INVALID_VALUE
;
3101 /* For cube map, width must equal height */
3102 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3103 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3104 return GL_INVALID_VALUE
;
3106 if (level
< 0 || level
>= maxLevels
)
3107 return GL_INVALID_VALUE
;
3109 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3110 depth
, internalFormat
);
3111 if (expectedSize
!= imageSize
)
3112 return GL_INVALID_VALUE
;
3114 #if FEATURE_EXT_texture_sRGB
3115 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3116 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3117 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3118 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3120 return GL_INVALID_OPERATION
;
3129 * Error checking for glCompressedTexSubImage[123]D().
3130 * \warning There are some bad assumptions here about the size of compressed
3131 * texture tiles (multiple of 4) used to test the validity of the
3132 * offset and size parameters.
3133 * \return error code or GL_NO_ERROR.
3136 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3137 GLenum target
, GLint level
,
3138 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3139 GLsizei width
, GLsizei height
, GLsizei depth
,
3140 GLenum format
, GLsizei imageSize
)
3142 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3145 if (dimensions
== 1) {
3146 /* 1D compressed textures not allowed */
3147 return GL_INVALID_ENUM
;
3149 else if (dimensions
== 2) {
3150 if (target
== GL_PROXY_TEXTURE_2D
) {
3151 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3153 else if (target
== GL_TEXTURE_2D
) {
3154 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3156 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3157 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3158 return GL_INVALID_ENUM
; /*target*/
3159 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3161 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3162 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3163 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3164 return GL_INVALID_ENUM
; /*target*/
3165 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3168 return GL_INVALID_ENUM
; /*target*/
3171 else if (dimensions
== 3) {
3172 /* 3D compressed textures not allowed */
3173 return GL_INVALID_ENUM
;
3176 maxTextureSize
= 1 << (maxLevels
- 1);
3178 /* this will catch any invalid compressed format token */
3179 if (!is_compressed_format(ctx
, format
))
3180 return GL_INVALID_ENUM
;
3182 if (width
< 1 || width
> maxTextureSize
)
3183 return GL_INVALID_VALUE
;
3185 if ((height
< 1 || height
> maxTextureSize
)
3187 return GL_INVALID_VALUE
;
3189 if (level
< 0 || level
>= maxLevels
)
3190 return GL_INVALID_VALUE
;
3192 /* XXX these tests are specific to the compressed format.
3193 * this code should be generalized in some way.
3195 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3196 return GL_INVALID_VALUE
;
3198 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3199 return GL_INVALID_VALUE
;
3201 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3202 return GL_INVALID_VALUE
;
3204 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3206 if (expectedSize
!= imageSize
)
3207 return GL_INVALID_VALUE
;
3215 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3216 GLenum internalFormat
, GLsizei width
,
3217 GLint border
, GLsizei imageSize
,
3220 GET_CURRENT_CONTEXT(ctx
);
3221 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3223 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3224 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3225 _mesa_lookup_enum_by_nr(target
), level
,
3226 _mesa_lookup_enum_by_nr(internalFormat
),
3227 width
, border
, imageSize
, data
);
3229 if (target
== GL_TEXTURE_1D
) {
3230 /* non-proxy target */
3231 struct gl_texture_unit
*texUnit
;
3232 struct gl_texture_object
*texObj
;
3233 struct gl_texture_image
*texImage
;
3234 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3235 internalFormat
, width
, 1, 1, border
, imageSize
);
3237 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3241 texUnit
= _mesa_get_current_tex_unit(ctx
);
3242 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3244 _mesa_lock_texture(ctx
, texObj
);
3246 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3248 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3251 if (texImage
->Data
) {
3252 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3254 ASSERT(texImage
->Data
== NULL
);
3256 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3257 border
, internalFormat
);
3259 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3260 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3261 internalFormat
, width
, border
,
3265 check_gen_mipmap(ctx
, target
, texObj
, level
);
3268 texObj
->_Complete
= GL_FALSE
;
3269 ctx
->NewState
|= _NEW_TEXTURE
;
3272 _mesa_unlock_texture(ctx
, texObj
);
3274 else if (target
== GL_PROXY_TEXTURE_1D
) {
3275 /* Proxy texture: check for errors and update proxy state */
3276 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3277 internalFormat
, width
, 1, 1, border
, imageSize
);
3279 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3280 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3281 internalFormat
, GL_NONE
, GL_NONE
,
3282 width
, 1, 1, border
);
3285 /* if error, clear all proxy texture image parameters */
3286 struct gl_texture_image
*texImage
;
3287 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3289 clear_teximage_fields(texImage
);
3292 /* store the teximage parameters */
3293 struct gl_texture_unit
*texUnit
;
3294 struct gl_texture_object
*texObj
;
3295 struct gl_texture_image
*texImage
;
3296 texUnit
= _mesa_get_current_tex_unit(ctx
);
3297 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3299 _mesa_lock_texture(ctx
, texObj
);
3301 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3302 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3303 border
, internalFormat
);
3305 _mesa_unlock_texture(ctx
, texObj
);
3309 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3316 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3317 GLenum internalFormat
, GLsizei width
,
3318 GLsizei height
, GLint border
, GLsizei imageSize
,
3321 GET_CURRENT_CONTEXT(ctx
);
3322 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3324 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3325 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3326 _mesa_lookup_enum_by_nr(target
), level
,
3327 _mesa_lookup_enum_by_nr(internalFormat
),
3328 width
, height
, border
, imageSize
, data
);
3330 if (target
== GL_TEXTURE_2D
||
3331 (ctx
->Extensions
.ARB_texture_cube_map
&&
3332 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3333 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3334 /* non-proxy target */
3335 struct gl_texture_unit
*texUnit
;
3336 struct gl_texture_object
*texObj
;
3337 struct gl_texture_image
*texImage
;
3338 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3339 internalFormat
, width
, height
, 1, border
, imageSize
);
3341 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3345 texUnit
= _mesa_get_current_tex_unit(ctx
);
3346 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3348 _mesa_lock_texture(ctx
, texObj
);
3350 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3352 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3355 if (texImage
->Data
) {
3356 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3358 ASSERT(texImage
->Data
== NULL
);
3360 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3361 border
, internalFormat
);
3363 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3364 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3365 internalFormat
, width
, height
,
3366 border
, imageSize
, data
,
3369 check_gen_mipmap(ctx
, target
, texObj
, level
);
3372 texObj
->_Complete
= GL_FALSE
;
3373 ctx
->NewState
|= _NEW_TEXTURE
;
3376 _mesa_unlock_texture(ctx
, texObj
);
3378 else if (target
== GL_PROXY_TEXTURE_2D
||
3379 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3380 ctx
->Extensions
.ARB_texture_cube_map
)) {
3381 /* Proxy texture: check for errors and update proxy state */
3382 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3383 internalFormat
, width
, height
, 1, border
, imageSize
);
3385 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3386 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3387 internalFormat
, GL_NONE
, GL_NONE
,
3388 width
, height
, 1, border
);
3391 /* if error, clear all proxy texture image parameters */
3392 struct gl_texture_image
*texImage
;
3393 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3395 clear_teximage_fields(texImage
);
3398 /* store the teximage parameters */
3399 struct gl_texture_unit
*texUnit
;
3400 struct gl_texture_object
*texObj
;
3401 struct gl_texture_image
*texImage
;
3402 texUnit
= _mesa_get_current_tex_unit(ctx
);
3403 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3405 _mesa_lock_texture(ctx
, texObj
);
3407 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3408 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3409 border
, internalFormat
);
3411 _mesa_unlock_texture(ctx
, texObj
);
3415 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3422 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3423 GLenum internalFormat
, GLsizei width
,
3424 GLsizei height
, GLsizei depth
, GLint border
,
3425 GLsizei imageSize
, const GLvoid
*data
)
3427 GET_CURRENT_CONTEXT(ctx
);
3428 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3430 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3431 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3432 _mesa_lookup_enum_by_nr(target
), level
,
3433 _mesa_lookup_enum_by_nr(internalFormat
),
3434 width
, height
, depth
, border
, imageSize
, data
);
3436 if (target
== GL_TEXTURE_3D
) {
3437 /* non-proxy target */
3438 struct gl_texture_unit
*texUnit
;
3439 struct gl_texture_object
*texObj
;
3440 struct gl_texture_image
*texImage
;
3441 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3442 internalFormat
, width
, height
, depth
, border
, imageSize
);
3444 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3448 texUnit
= _mesa_get_current_tex_unit(ctx
);
3449 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3450 _mesa_lock_texture(ctx
, texObj
);
3452 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3454 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3457 if (texImage
->Data
) {
3458 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3460 ASSERT(texImage
->Data
== NULL
);
3462 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3463 width
, height
, depth
,
3464 border
, internalFormat
);
3466 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3467 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3469 width
, height
, depth
,
3470 border
, imageSize
, data
,
3473 check_gen_mipmap(ctx
, target
, texObj
, level
);
3476 texObj
->_Complete
= GL_FALSE
;
3477 ctx
->NewState
|= _NEW_TEXTURE
;
3480 _mesa_unlock_texture(ctx
, texObj
);
3482 else if (target
== GL_PROXY_TEXTURE_3D
) {
3483 /* Proxy texture: check for errors and update proxy state */
3484 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3485 internalFormat
, width
, height
, depth
, border
, imageSize
);
3487 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3488 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3489 internalFormat
, GL_NONE
, GL_NONE
,
3490 width
, height
, depth
, border
);
3493 /* if error, clear all proxy texture image parameters */
3494 struct gl_texture_image
*texImage
;
3495 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3497 clear_teximage_fields(texImage
);
3500 /* store the teximage parameters */
3501 struct gl_texture_unit
*texUnit
;
3502 struct gl_texture_object
*texObj
;
3503 struct gl_texture_image
*texImage
;
3504 texUnit
= _mesa_get_current_tex_unit(ctx
);
3505 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3506 _mesa_lock_texture(ctx
, texObj
);
3508 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3509 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3510 depth
, border
, internalFormat
);
3512 _mesa_unlock_texture(ctx
, texObj
);
3516 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3523 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3524 GLsizei width
, GLenum format
,
3525 GLsizei imageSize
, const GLvoid
*data
)
3527 struct gl_texture_unit
*texUnit
;
3528 struct gl_texture_object
*texObj
;
3529 struct gl_texture_image
*texImage
;
3531 GET_CURRENT_CONTEXT(ctx
);
3532 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3534 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3535 xoffset
, 0, 0, /* pos */
3536 width
, 1, 1, /* size */
3539 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3543 texUnit
= _mesa_get_current_tex_unit(ctx
);
3544 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3546 _mesa_lock_texture(ctx
, texObj
);
3548 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3551 if ((GLint
) format
!= texImage
->InternalFormat
) {
3552 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3553 "glCompressedTexSubImage1D(format)");
3555 else if ((width
== 1 || width
== 2) &&
3556 (GLuint
) width
!= texImage
->Width
) {
3557 _mesa_error(ctx
, GL_INVALID_VALUE
,
3558 "glCompressedTexSubImage1D(width)");
3560 else if (width
> 0) {
3561 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3562 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3564 format
, imageSize
, data
,
3568 check_gen_mipmap(ctx
, target
, texObj
, level
);
3570 ctx
->NewState
|= _NEW_TEXTURE
;
3573 _mesa_unlock_texture(ctx
, texObj
);
3578 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3579 GLint yoffset
, GLsizei width
, GLsizei height
,
3580 GLenum format
, GLsizei imageSize
,
3583 struct gl_texture_unit
*texUnit
;
3584 struct gl_texture_object
*texObj
;
3585 struct gl_texture_image
*texImage
;
3587 GET_CURRENT_CONTEXT(ctx
);
3588 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3590 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3591 xoffset
, yoffset
, 0, /* pos */
3592 width
, height
, 1, /* size */
3595 /* XXX proxy target? */
3596 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3600 texUnit
= _mesa_get_current_tex_unit(ctx
);
3601 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3603 _mesa_lock_texture(ctx
, texObj
);
3605 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3608 if ((GLint
) format
!= texImage
->InternalFormat
) {
3609 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3610 "glCompressedTexSubImage2D(format)");
3612 else if (((width
== 1 || width
== 2)
3613 && (GLuint
) width
!= texImage
->Width
) ||
3614 ((height
== 1 || height
== 2)
3615 && (GLuint
) height
!= texImage
->Height
)) {
3616 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3618 else if (width
> 0 && height
> 0) {
3619 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3620 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3621 xoffset
, yoffset
, width
, height
,
3622 format
, imageSize
, data
,
3626 check_gen_mipmap(ctx
, target
, texObj
, level
);
3628 ctx
->NewState
|= _NEW_TEXTURE
;
3631 _mesa_unlock_texture(ctx
, texObj
);
3636 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3637 GLint yoffset
, GLint zoffset
, GLsizei width
,
3638 GLsizei height
, GLsizei depth
, GLenum format
,
3639 GLsizei imageSize
, const GLvoid
*data
)
3641 struct gl_texture_unit
*texUnit
;
3642 struct gl_texture_object
*texObj
;
3643 struct gl_texture_image
*texImage
;
3645 GET_CURRENT_CONTEXT(ctx
);
3646 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3648 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3649 xoffset
, yoffset
, zoffset
,/*pos*/
3650 width
, height
, depth
, /*size*/
3653 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3657 texUnit
= _mesa_get_current_tex_unit(ctx
);
3658 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3660 _mesa_lock_texture(ctx
, texObj
);
3662 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3665 if ((GLint
) format
!= texImage
->InternalFormat
) {
3666 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3667 "glCompressedTexSubImage3D(format)");
3669 else if (((width
== 1 || width
== 2)
3670 && (GLuint
) width
!= texImage
->Width
) ||
3671 ((height
== 1 || height
== 2)
3672 && (GLuint
) height
!= texImage
->Height
) ||
3673 ((depth
== 1 || depth
== 2)
3674 && (GLuint
) depth
!= texImage
->Depth
)) {
3675 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3677 else if (width
> 0 && height
> 0 && depth
> 0) {
3678 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3679 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3680 xoffset
, yoffset
, zoffset
,
3681 width
, height
, depth
,
3682 format
, imageSize
, data
,
3686 check_gen_mipmap(ctx
, target
, texObj
, level
);
3688 ctx
->NewState
|= _NEW_TEXTURE
;
3691 _mesa_unlock_texture(ctx
, texObj
);