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"
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
;
910 * Initialize basic fields of the gl_texture_image struct.
912 * \param ctx GL context.
913 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
914 * \param img texture image structure to be initialized.
915 * \param width image width.
916 * \param height image height.
917 * \param depth image depth.
918 * \param border image border.
919 * \param internalFormat internal format.
921 * Fills in the fields of \p img with the given information.
922 * Note: width, height and depth include the border.
925 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
926 struct gl_texture_image
*img
,
927 GLsizei width
, GLsizei height
, GLsizei depth
,
928 GLint border
, GLenum internalFormat
)
937 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
938 ASSERT(img
->_BaseFormat
> 0);
939 img
->InternalFormat
= internalFormat
;
940 img
->Border
= border
;
942 img
->Height
= height
;
945 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
946 img
->WidthLog2
= logbase2(img
->Width2
);
948 if (height
== 1) { /* 1-D texture */
953 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
954 img
->HeightLog2
= logbase2(img
->Height2
);
957 if (depth
== 1) { /* 2-D texture */
962 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
963 img
->DepthLog2
= logbase2(img
->Depth2
);
966 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
968 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
969 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
970 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
971 img
->_IsPowerOfTwo
= GL_TRUE
;
973 img
->_IsPowerOfTwo
= GL_FALSE
;
975 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
976 img
->RowStride
= width
;
977 /* Allocate the ImageOffsets array and initialize to typical values.
978 * We allocate the array for 1D/2D textures too in order to avoid special-
979 * case code in the texstore routines.
981 if (img
->ImageOffsets
)
982 _mesa_free(img
->ImageOffsets
);
983 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
984 for (i
= 0; i
< depth
; i
++) {
985 img
->ImageOffsets
[i
] = i
* width
* height
;
988 /* Compute Width/Height/DepthScale for mipmap lod computation */
989 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
990 /* scale = 1.0 since texture coords directly map to texels */
991 img
->WidthScale
= 1.0;
992 img
->HeightScale
= 1.0;
993 img
->DepthScale
= 1.0;
996 img
->WidthScale
= (GLfloat
) img
->Width
;
997 img
->HeightScale
= (GLfloat
) img
->Height
;
998 img
->DepthScale
= (GLfloat
) img
->Depth
;
1001 img
->FetchTexelc
= NULL
;
1002 img
->FetchTexelf
= NULL
;
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 * Return pointer to texture object for given target on current texture unit.
1026 static struct gl_texture_object
*
1027 get_current_tex_object(GLcontext
*ctx
, GLenum target
)
1029 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
1030 return _mesa_select_tex_object(ctx
, texUnit
, target
);
1036 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1037 * level, width, height and depth against the ctx->Const limits for textures.
1039 * A hardware driver might override this function if, for example, the
1040 * max 3D texture size is 512x512x64 (i.e. not a cube).
1042 * Note that width, height, depth == 0 is not an error. However, a
1043 * texture with zero width/height/depth will be considered "incomplete"
1044 * and texturing will effectively be disabled.
1046 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1047 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1048 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1049 * \param level as passed to glTexImage
1050 * \param internalFormat as passed to glTexImage
1051 * \param format as passed to glTexImage
1052 * \param type as passed to glTexImage
1053 * \param width as passed to glTexImage
1054 * \param height as passed to glTexImage
1055 * \param depth as passed to glTexImage
1056 * \param border as passed to glTexImage
1057 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1060 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1061 GLint internalFormat
, GLenum format
, GLenum type
,
1062 GLint width
, GLint height
, GLint depth
, GLint border
)
1066 (void) internalFormat
;
1071 case GL_PROXY_TEXTURE_1D
:
1072 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1073 if (width
< 2 * border
|| width
> 2 + maxSize
||
1074 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1075 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1076 level
>= ctx
->Const
.MaxTextureLevels
) {
1077 /* bad width or level */
1081 case GL_PROXY_TEXTURE_2D
:
1082 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1083 if (width
< 2 * border
|| width
> 2 + maxSize
||
1084 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1085 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1086 height
< 2 * border
|| height
> 2 + maxSize
||
1087 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1088 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1089 level
>= ctx
->Const
.MaxTextureLevels
) {
1090 /* bad width or height or level */
1094 case GL_PROXY_TEXTURE_3D
:
1095 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1096 if (width
< 2 * border
|| width
> 2 + maxSize
||
1097 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1098 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1099 height
< 2 * border
|| height
> 2 + maxSize
||
1100 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1101 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1102 depth
< 2 * border
|| depth
> 2 + maxSize
||
1103 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1104 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1105 level
>= ctx
->Const
.Max3DTextureLevels
) {
1106 /* bad width or height or depth or level */
1110 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1111 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1112 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1114 /* bad width or height or level */
1118 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1119 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1120 if (width
< 2 * border
|| width
> 2 + maxSize
||
1121 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1122 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1123 height
< 2 * border
|| height
> 2 + maxSize
||
1124 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1125 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1126 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1127 /* bad width or height */
1131 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1132 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1133 if (width
< 2 * border
|| width
> 2 + maxSize
||
1134 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1135 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1136 level
>= ctx
->Const
.MaxTextureLevels
) {
1137 /* bad width or level */
1141 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1145 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1146 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1147 if (width
< 2 * border
|| width
> 2 + maxSize
||
1148 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1149 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1150 height
< 2 * border
|| height
> 2 + maxSize
||
1151 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1152 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1153 level
>= ctx
->Const
.MaxTextureLevels
) {
1154 /* bad width or height or level */
1157 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1162 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1169 * Helper function to determine whether a target supports compressed textures
1172 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1174 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1175 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1176 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1177 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1178 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1179 || ((ctx
->Extensions
.MESA_texture_array
&&
1180 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1181 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1186 * Test the glTexImage[123]D() parameters for errors.
1188 * \param ctx GL context.
1189 * \param target texture target given by the user.
1190 * \param level image level given by the user.
1191 * \param internalFormat internal format given by the user.
1192 * \param format pixel data format given by the user.
1193 * \param type pixel data type given by the user.
1194 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1195 * \param width image width given by the user.
1196 * \param height image height given by the user.
1197 * \param depth image depth given by the user.
1198 * \param border image border given by the user.
1200 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1202 * Verifies each of the parameters against the constants specified in
1203 * __GLcontextRec::Const and the supported extensions, and according to the
1204 * OpenGL specification.
1207 texture_error_check( GLcontext
*ctx
, GLenum target
,
1208 GLint level
, GLint internalFormat
,
1209 GLenum format
, GLenum type
,
1211 GLint width
, GLint height
,
1212 GLint depth
, GLint border
)
1214 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1215 GLboolean sizeOK
= GL_TRUE
;
1216 GLboolean colorFormat
, indexFormat
;
1217 GLenum proxy_target
;
1219 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1220 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1222 _mesa_error(ctx
, GL_INVALID_VALUE
,
1223 "glTexImage%dD(level=%d)", dimensions
, level
);
1229 if (border
< 0 || border
> 1 ||
1230 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1231 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1233 _mesa_error(ctx
, GL_INVALID_VALUE
,
1234 "glTexImage%dD(border=%d)", dimensions
, border
);
1239 if (width
< 0 || height
< 0 || depth
< 0) {
1241 _mesa_error(ctx
, GL_INVALID_VALUE
,
1242 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1247 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1248 * level, width, height and depth.
1250 if (dimensions
== 1) {
1251 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1252 proxy_target
= GL_PROXY_TEXTURE_1D
;
1257 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1261 else if (dimensions
== 2) {
1263 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1264 proxy_target
= GL_PROXY_TEXTURE_2D
;
1266 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1267 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1268 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1269 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1270 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1273 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1274 sizeOK
= (width
== height
);
1276 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1277 target
== GL_TEXTURE_RECTANGLE_NV
) {
1278 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1279 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1282 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1284 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1285 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1286 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1289 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1293 else if (dimensions
== 3) {
1294 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1295 proxy_target
= GL_PROXY_TEXTURE_3D
;
1297 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1298 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1299 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1302 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1307 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1311 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1312 internalFormat
, format
,
1313 type
, width
, height
,
1317 _mesa_error(ctx
, GL_INVALID_VALUE
,
1318 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1319 dimensions
, level
, width
, height
, depth
);
1324 /* Check internalFormat */
1325 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1327 _mesa_error(ctx
, GL_INVALID_VALUE
,
1328 "glTexImage%dD(internalFormat=0x%x)",
1329 dimensions
, internalFormat
);
1334 /* Check incoming image format and type */
1335 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1336 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1337 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1340 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1341 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1342 dimensions
, format
, type
);
1347 /* make sure internal format and format basically agree */
1348 colorFormat
= _mesa_is_color_format(format
);
1349 indexFormat
= _mesa_is_index_format(format
);
1350 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1351 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1352 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1353 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1354 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1355 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1357 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1358 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1359 dimensions
, internalFormat
, format
);
1363 /* additional checks for ycbcr textures */
1364 if (internalFormat
== GL_YCBCR_MESA
) {
1365 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1366 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1367 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1369 _mesa_sprintf(message
,
1370 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1371 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1372 return GL_TRUE
; /* error */
1374 if (target
!= GL_TEXTURE_2D
&&
1375 target
!= GL_PROXY_TEXTURE_2D
&&
1376 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1377 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1379 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1385 _mesa_sprintf(message
,
1386 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1387 dimensions
, border
);
1388 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1394 /* additional checks for depth textures */
1395 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1396 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1397 if (target
!= GL_TEXTURE_1D
&&
1398 target
!= GL_PROXY_TEXTURE_1D
&&
1399 target
!= GL_TEXTURE_2D
&&
1400 target
!= GL_PROXY_TEXTURE_2D
&&
1401 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1402 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1404 _mesa_error(ctx
, GL_INVALID_ENUM
,
1405 "glTexImage(target/internalFormat)");
1410 /* additional checks for compressed textures */
1411 if (is_compressed_format(ctx
, internalFormat
)) {
1412 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1413 _mesa_error(ctx
, GL_INVALID_ENUM
,
1414 "glTexImage%d(target)", dimensions
);
1419 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1420 "glTexImage%D(border!=0)", dimensions
);
1426 /* if we get here, the parameters are OK */
1432 * Test glTexSubImage[123]D() parameters for errors.
1434 * \param ctx GL context.
1435 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1436 * \param target texture target given by the user.
1437 * \param level image level given by the user.
1438 * \param xoffset sub-image x offset given by the user.
1439 * \param yoffset sub-image y offset given by the user.
1440 * \param zoffset sub-image z offset given by the user.
1441 * \param format pixel data format given by the user.
1442 * \param type pixel data type given by the user.
1443 * \param width image width given by the user.
1444 * \param height image height given by the user.
1445 * \param depth image depth given by the user.
1447 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1449 * Verifies each of the parameters against the constants specified in
1450 * __GLcontextRec::Const and the supported extensions, and according to the
1451 * OpenGL specification.
1454 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1455 GLenum target
, GLint level
,
1456 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1457 GLint width
, GLint height
, GLint depth
,
1458 GLenum format
, GLenum type
)
1461 if (dimensions
== 1) {
1462 if (target
!= GL_TEXTURE_1D
) {
1463 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1467 else if (dimensions
== 2) {
1468 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1469 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1470 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1471 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1475 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1476 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1477 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1481 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1482 if (!ctx
->Extensions
.MESA_texture_array
) {
1483 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1487 else if (target
!= GL_TEXTURE_2D
) {
1488 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1492 else if (dimensions
== 3) {
1493 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1494 if (!ctx
->Extensions
.MESA_texture_array
) {
1495 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1499 else if (target
!= GL_TEXTURE_3D
) {
1500 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1505 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1509 /* Basic level check */
1510 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1511 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1516 _mesa_error(ctx
, GL_INVALID_VALUE
,
1517 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1520 if (height
< 0 && dimensions
> 1) {
1521 _mesa_error(ctx
, GL_INVALID_VALUE
,
1522 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1525 if (depth
< 0 && dimensions
> 2) {
1526 _mesa_error(ctx
, GL_INVALID_VALUE
,
1527 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1531 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1532 _mesa_error(ctx
, GL_INVALID_ENUM
,
1533 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1534 dimensions
, format
, type
);
1542 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1543 GLenum target
, GLint level
,
1544 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1545 GLint width
, GLint height
, GLint depth
,
1546 GLenum format
, GLenum type
,
1547 const struct gl_texture_image
*destTex
)
1550 /* undefined image level */
1551 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1555 if (xoffset
< -((GLint
)destTex
->Border
)) {
1556 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1560 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1561 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1565 if (dimensions
> 1) {
1566 if (yoffset
< -((GLint
)destTex
->Border
)) {
1567 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1571 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1572 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1577 if (dimensions
> 2) {
1578 if (zoffset
< -((GLint
)destTex
->Border
)) {
1579 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1582 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1583 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1588 #if FEATURE_EXT_texture_sRGB
1589 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1590 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1591 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1592 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1593 if ((width
& 0x3) || (height
& 0x3) ||
1594 (xoffset
& 0x3) || (yoffset
& 0x3))
1595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1596 "glTexSubImage%dD(size or offset not multiple of 4)",
1602 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1603 if (!target_can_be_compressed(ctx
, target
)) {
1604 _mesa_error(ctx
, GL_INVALID_ENUM
,
1605 "glTexSubImage%D(target)", dimensions
);
1608 /* offset must be multiple of 4 */
1609 if ((xoffset
& 3) || (yoffset
& 3)) {
1610 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1611 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1614 /* size must be multiple of 4 or equal to whole texture size */
1615 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1616 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1617 "glTexSubImage%D(width)", dimensions
);
1620 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1621 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1622 "glTexSubImage%D(width)", dimensions
);
1632 * Test glCopyTexImage[12]D() parameters for errors.
1634 * \param ctx GL context.
1635 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1636 * \param target texture target given by the user.
1637 * \param level image level given by the user.
1638 * \param internalFormat internal format given by the user.
1639 * \param width image width given by the user.
1640 * \param height image height given by the user.
1641 * \param border texture border.
1643 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1645 * Verifies each of the parameters against the constants specified in
1646 * __GLcontextRec::Const and the supported extensions, and according to the
1647 * OpenGL specification.
1650 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1651 GLenum target
, GLint level
, GLint internalFormat
,
1652 GLint width
, GLint height
, GLint border
)
1658 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1659 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1660 _mesa_error(ctx
, GL_INVALID_VALUE
,
1661 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1665 /* Check that the source buffer is complete */
1666 if (ctx
->ReadBuffer
->Name
) {
1667 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1668 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1669 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1670 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1676 if (border
< 0 || border
> 1 ||
1677 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1678 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1682 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1684 _mesa_error(ctx
, GL_INVALID_VALUE
,
1685 "glCopyTexImage%dD(internalFormat)", dimensions
);
1689 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1690 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1691 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1695 /* NOTE: the format and type aren't really significant for
1696 * TestProxyTexImage(). Only the internalformat really matters.
1700 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1701 * level, width, height and depth.
1703 if (dimensions
== 1) {
1704 if (target
== GL_TEXTURE_1D
) {
1705 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1706 level
, internalFormat
,
1708 width
, 1, 1, border
);
1711 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1715 else if (dimensions
== 2) {
1716 if (target
== GL_TEXTURE_2D
) {
1717 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1718 level
, internalFormat
,
1720 width
, height
, 1, border
);
1722 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1723 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1724 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1725 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1728 sizeOK
= (width
== height
) &&
1729 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1730 level
, internalFormat
, format
, type
,
1731 width
, height
, 1, border
);
1733 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1734 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1735 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1738 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1739 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1740 level
, internalFormat
,
1742 width
, height
, 1, border
);
1744 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1745 if (!ctx
->Extensions
.MESA_texture_array
) {
1746 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1749 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1750 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1751 level
, internalFormat
,
1753 width
, height
, 1, border
);
1756 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1761 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1766 if (dimensions
== 1) {
1767 _mesa_error(ctx
, GL_INVALID_VALUE
,
1768 "glCopyTexImage1D(width=%d)", width
);
1771 ASSERT(dimensions
== 2);
1772 _mesa_error(ctx
, GL_INVALID_VALUE
,
1773 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1778 if (is_compressed_format(ctx
, internalFormat
)) {
1779 if (!target_can_be_compressed(ctx
, target
)) {
1780 _mesa_error(ctx
, GL_INVALID_ENUM
,
1781 "glCopyTexImage%d(target)", dimensions
);
1785 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1786 "glCopyTexImage%D(border!=0)", dimensions
);
1790 else if (_mesa_is_depth_format(internalFormat
)) {
1791 /* make sure we have depth/stencil buffers */
1792 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1793 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1794 "glCopyTexImage%D(no depth)", dimensions
);
1798 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1799 /* make sure we have depth/stencil buffers */
1800 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1801 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1802 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
1807 /* if we get here, the parameters are OK */
1813 * Test glCopyTexSubImage[12]D() parameters for errors.
1814 * Note that this is the first part of error checking.
1815 * See also copytexsubimage_error_check2() below for the second part.
1817 * \param ctx GL context.
1818 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1819 * \param target texture target given by the user.
1820 * \param level image level given by the user.
1822 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1825 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1826 GLenum target
, GLint level
)
1828 /* Check that the source buffer is complete */
1829 if (ctx
->ReadBuffer
->Name
) {
1830 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1831 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1832 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1833 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1839 if (dimensions
== 1) {
1840 if (target
!= GL_TEXTURE_1D
) {
1841 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1845 else if (dimensions
== 2) {
1846 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1847 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1848 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1849 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1853 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1854 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1855 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1859 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1860 if (!ctx
->Extensions
.MESA_texture_array
) {
1861 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1865 else if (target
!= GL_TEXTURE_2D
) {
1866 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1870 else if (dimensions
== 3) {
1871 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1872 (!ctx
->Extensions
.MESA_texture_array
))
1873 && (target
!= GL_TEXTURE_3D
)) {
1874 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1880 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1881 _mesa_error(ctx
, GL_INVALID_VALUE
,
1882 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1891 * Second part of error checking for glCopyTexSubImage[12]D().
1892 * \param xoffset sub-image x offset given by the user.
1893 * \param yoffset sub-image y offset given by the user.
1894 * \param zoffset sub-image z offset given by the user.
1895 * \param width image width given by the user.
1896 * \param height image height given by the user.
1899 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1900 GLenum target
, GLint level
,
1901 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1902 GLsizei width
, GLsizei height
,
1903 const struct gl_texture_image
*teximage
)
1905 /* check that dest tex image exists */
1907 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1908 "glCopyTexSubImage%dD(undefined texture level: %d)",
1915 _mesa_error(ctx
, GL_INVALID_VALUE
,
1916 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1919 if (dimensions
> 1 && height
< 0) {
1920 _mesa_error(ctx
, GL_INVALID_VALUE
,
1921 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1925 /* check x/y offsets */
1926 if (xoffset
< -((GLint
)teximage
->Border
)) {
1927 _mesa_error(ctx
, GL_INVALID_VALUE
,
1928 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1931 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1932 _mesa_error(ctx
, GL_INVALID_VALUE
,
1933 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1936 if (dimensions
> 1) {
1937 if (yoffset
< -((GLint
)teximage
->Border
)) {
1938 _mesa_error(ctx
, GL_INVALID_VALUE
,
1939 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1942 /* NOTE: we're adding the border here, not subtracting! */
1943 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1944 _mesa_error(ctx
, GL_INVALID_VALUE
,
1945 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1950 /* check z offset */
1951 if (dimensions
> 2) {
1952 if (zoffset
< -((GLint
)teximage
->Border
)) {
1953 _mesa_error(ctx
, GL_INVALID_VALUE
,
1954 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1957 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1958 _mesa_error(ctx
, GL_INVALID_VALUE
,
1959 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1964 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
1965 if (!target_can_be_compressed(ctx
, target
)) {
1966 _mesa_error(ctx
, GL_INVALID_ENUM
,
1967 "glCopyTexSubImage%d(target)", dimensions
);
1970 /* offset must be multiple of 4 */
1971 if ((xoffset
& 3) || (yoffset
& 3)) {
1972 _mesa_error(ctx
, GL_INVALID_VALUE
,
1973 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
1976 /* size must be multiple of 4 */
1977 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1978 _mesa_error(ctx
, GL_INVALID_VALUE
,
1979 "glCopyTexSubImage%D(width)", dimensions
);
1982 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1983 _mesa_error(ctx
, GL_INVALID_VALUE
,
1984 "glCopyTexSubImage%D(height)", dimensions
);
1989 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
1990 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1994 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
1995 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1996 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
1997 dimensions
, teximage
->_BaseFormat
);
2001 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2002 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2003 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2004 "glCopyTexSubImage%D(no depth buffer)",
2009 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2010 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2011 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2012 "glCopyTexSubImage%D(no depth/stencil buffer)",
2018 /* if we get here, the parameters are OK */
2023 /** Callback info for walking over FBO hash table */
2027 struct gl_texture_object
*texObj
;
2033 * Check render to texture callback. Called from _mesa_HashWalk().
2036 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2038 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2039 const struct cb_info
*info
= (struct cb_info
*) userData
;
2040 GLcontext
*ctx
= info
->ctx
;
2041 const struct gl_texture_object
*texObj
= info
->texObj
;
2042 const GLuint level
= info
->level
, face
= info
->face
;
2044 /* If this is a user-created FBO */
2047 /* check if any of the FBO's attachments point to 'texObj' */
2048 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2049 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2050 if (att
->Type
== GL_TEXTURE
&&
2051 att
->Texture
== texObj
&&
2052 att
->TextureLevel
== level
&&
2053 att
->CubeMapFace
== face
) {
2054 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2055 /* Tell driver about the new renderbuffer texture */
2056 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2057 /* Mark fb status as indeterminate to force re-validation */
2066 * When a texture image is specified we have to check if it's bound to
2067 * any framebuffer objects (render to texture) in order to detect changes
2068 * in size or format since that effects FBO completeness.
2069 * Any FBOs rendering into the texture must be re-validated.
2072 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2073 GLuint face
, GLuint level
)
2075 /* Only check this texture if it's been marked as RenderToTexture */
2076 if (texObj
->_RenderToTexture
) {
2077 struct cb_info info
;
2079 info
.texObj
= texObj
;
2082 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2088 * If the texture object's GenerateMipmap flag is set and we've
2089 * changed the texture base level image, regenerate the rest of the
2090 * mipmap levels now.
2093 check_gen_mipmap(GLcontext
*ctx
, GLenum target
,
2094 struct gl_texture_object
*texObj
, GLint level
)
2096 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2097 if (texObj
->GenerateMipmap
&& level
== texObj
->BaseLevel
) {
2098 ASSERT(ctx
->Driver
.GenerateMipmap
);
2099 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2104 /** Debug helper: override the user-requested internal format */
2106 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2109 if (internalFormat
== GL_RGBA16F_ARB
||
2110 internalFormat
== GL_RGBA32F_ARB
) {
2111 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2114 else if (internalFormat
== GL_RGB16F_ARB
||
2115 internalFormat
== GL_RGB32F_ARB
) {
2116 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2119 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2120 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2121 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2122 return GL_LUMINANCE_ALPHA
;
2124 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2125 internalFormat
== GL_LUMINANCE32F_ARB
) {
2126 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2127 return GL_LUMINANCE
;
2129 else if (internalFormat
== GL_ALPHA16F_ARB
||
2130 internalFormat
== GL_ALPHA32F_ARB
) {
2131 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2135 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2136 internalFormat = GL_RGBA;
2140 return internalFormat
;
2143 return internalFormat
;
2149 * Called from the API. Note that width includes the border.
2152 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2153 GLsizei width
, GLint border
, GLenum format
,
2154 GLenum type
, const GLvoid
*pixels
)
2156 GLsizei postConvWidth
= width
;
2157 GET_CURRENT_CONTEXT(ctx
);
2158 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2160 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2161 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2162 _mesa_lookup_enum_by_nr(target
), level
,
2163 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2164 _mesa_lookup_enum_by_nr(format
),
2165 _mesa_lookup_enum_by_nr(type
), pixels
);
2167 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2169 #if FEATURE_convolve
2170 if (_mesa_is_color_format(internalFormat
)) {
2171 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2175 if (target
== GL_TEXTURE_1D
) {
2176 /* non-proxy target */
2177 struct gl_texture_object
*texObj
;
2178 struct gl_texture_image
*texImage
;
2179 const GLuint face
= _mesa_tex_target_to_face(target
);
2181 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2182 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2183 return; /* error was recorded */
2186 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2187 _mesa_update_state(ctx
);
2189 texObj
= get_current_tex_object(ctx
, target
);
2190 _mesa_lock_texture(ctx
, texObj
);
2192 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2194 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2197 if (texImage
->Data
) {
2198 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2201 ASSERT(texImage
->Data
== NULL
);
2203 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2204 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2205 postConvWidth
, 1, 1,
2206 border
, internalFormat
);
2208 /* Choose actual texture format */
2209 texImage
->TexFormat
=
2210 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2212 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2214 /* Give the texture to the driver. <pixels> may be null. */
2215 ASSERT(ctx
->Driver
.TexImage1D
);
2216 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2217 width
, border
, format
, type
, pixels
,
2218 &ctx
->Unpack
, texObj
, texImage
);
2220 ASSERT(texImage
->TexFormat
);
2222 _mesa_set_fetch_functions(texImage
, 1);
2224 check_gen_mipmap(ctx
, target
, texObj
, level
);
2226 update_fbo_texture(ctx
, texObj
, face
, level
);
2229 texObj
->_Complete
= GL_FALSE
;
2230 ctx
->NewState
|= _NEW_TEXTURE
;
2233 _mesa_unlock_texture(ctx
, texObj
);
2235 else if (target
== GL_PROXY_TEXTURE_1D
) {
2236 /* Proxy texture: check for errors and update proxy state */
2237 struct gl_texture_image
*texImage
;
2238 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2239 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2240 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2241 /* when error, clear all proxy texture image parameters */
2243 clear_teximage_fields(texImage
);
2246 /* no error, set the tex image parameters */
2248 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2249 postConvWidth
, 1, 1,
2250 border
, internalFormat
);
2251 texImage
->TexFormat
=
2252 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2256 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2263 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2264 GLsizei width
, GLsizei height
, GLint border
,
2265 GLenum format
, GLenum type
,
2266 const GLvoid
*pixels
)
2268 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2269 GET_CURRENT_CONTEXT(ctx
);
2270 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2272 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2273 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2274 _mesa_lookup_enum_by_nr(target
), level
,
2275 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2276 border
, _mesa_lookup_enum_by_nr(format
),
2277 _mesa_lookup_enum_by_nr(type
), pixels
);
2279 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2281 #if FEATURE_convolve
2282 if (_mesa_is_color_format(internalFormat
)) {
2283 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2288 if (target
== GL_TEXTURE_2D
||
2289 (ctx
->Extensions
.ARB_texture_cube_map
&&
2290 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2291 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2292 (ctx
->Extensions
.NV_texture_rectangle
&&
2293 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2294 (ctx
->Extensions
.MESA_texture_array
&&
2295 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2296 /* non-proxy target */
2297 struct gl_texture_object
*texObj
;
2298 struct gl_texture_image
*texImage
;
2299 const GLuint face
= _mesa_tex_target_to_face(target
);
2301 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2302 format
, type
, 2, postConvWidth
, postConvHeight
,
2304 return; /* error was recorded */
2307 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2308 _mesa_update_state(ctx
);
2310 texObj
= get_current_tex_object(ctx
, target
);
2311 _mesa_lock_texture(ctx
, texObj
);
2313 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2315 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2318 if (texImage
->Data
) {
2319 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2322 ASSERT(texImage
->Data
== NULL
);
2323 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2324 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2325 postConvWidth
, postConvHeight
, 1,
2326 border
, internalFormat
);
2328 /* Choose actual texture format */
2329 texImage
->TexFormat
=
2330 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2332 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2334 /* Give the texture to the driver. <pixels> may be null. */
2335 ASSERT(ctx
->Driver
.TexImage2D
);
2336 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2337 width
, height
, border
, format
, type
,
2338 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2340 ASSERT(texImage
->TexFormat
);
2342 _mesa_set_fetch_functions(texImage
, 2);
2344 check_gen_mipmap(ctx
, target
, texObj
, level
);
2346 update_fbo_texture(ctx
, texObj
, face
, level
);
2349 texObj
->_Complete
= GL_FALSE
;
2350 ctx
->NewState
|= _NEW_TEXTURE
;
2353 _mesa_unlock_texture(ctx
, texObj
);
2355 else if (target
== GL_PROXY_TEXTURE_2D
||
2356 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2357 ctx
->Extensions
.ARB_texture_cube_map
) ||
2358 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2359 ctx
->Extensions
.NV_texture_rectangle
) ||
2360 (ctx
->Extensions
.MESA_texture_array
&&
2361 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2362 /* Proxy texture: check for errors and update proxy state */
2363 struct gl_texture_image
*texImage
;
2364 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2365 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2366 format
, type
, 2, postConvWidth
, postConvHeight
,
2368 /* when error, clear all proxy texture image parameters */
2370 clear_teximage_fields(texImage
);
2373 /* no error, set the tex image parameters */
2374 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2375 postConvWidth
, postConvHeight
, 1,
2376 border
, internalFormat
);
2377 texImage
->TexFormat
=
2378 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2382 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2389 * Called by the API or display list executor.
2390 * Note that width and height include the border.
2393 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2394 GLsizei width
, GLsizei height
, GLsizei depth
,
2395 GLint border
, GLenum format
, GLenum type
,
2396 const GLvoid
*pixels
)
2398 GET_CURRENT_CONTEXT(ctx
);
2399 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2401 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2402 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2403 _mesa_lookup_enum_by_nr(target
), level
,
2404 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2405 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2406 _mesa_lookup_enum_by_nr(type
), pixels
);
2408 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2410 if (target
== GL_TEXTURE_3D
||
2411 (ctx
->Extensions
.MESA_texture_array
&&
2412 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2413 /* non-proxy target */
2414 struct gl_texture_object
*texObj
;
2415 struct gl_texture_image
*texImage
;
2416 const GLuint face
= _mesa_tex_target_to_face(target
);
2418 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2419 format
, type
, 3, width
, height
, depth
, border
)) {
2420 return; /* error was recorded */
2423 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2424 _mesa_update_state(ctx
);
2426 texObj
= get_current_tex_object(ctx
, target
);
2427 _mesa_lock_texture(ctx
, texObj
);
2429 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2431 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2434 if (texImage
->Data
) {
2435 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2438 ASSERT(texImage
->Data
== NULL
);
2439 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2440 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2441 width
, height
, depth
,
2442 border
, internalFormat
);
2444 /* Choose actual texture format */
2445 texImage
->TexFormat
=
2446 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2448 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2450 /* Give the texture to the driver. <pixels> may be null. */
2451 ASSERT(ctx
->Driver
.TexImage3D
);
2452 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2453 width
, height
, depth
, border
, format
, type
,
2454 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2456 ASSERT(texImage
->TexFormat
);
2458 _mesa_set_fetch_functions(texImage
, 3);
2460 check_gen_mipmap(ctx
, target
, texObj
, level
);
2462 update_fbo_texture(ctx
, texObj
, face
, level
);
2465 texObj
->_Complete
= GL_FALSE
;
2466 ctx
->NewState
|= _NEW_TEXTURE
;
2469 _mesa_unlock_texture(ctx
, texObj
);
2471 else if (target
== GL_PROXY_TEXTURE_3D
||
2472 (ctx
->Extensions
.MESA_texture_array
&&
2473 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2474 /* Proxy texture: check for errors and update proxy state */
2475 struct gl_texture_image
*texImage
;
2476 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2477 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2478 format
, type
, 3, width
, height
, depth
, border
)) {
2479 /* when error, clear all proxy texture image parameters */
2481 clear_teximage_fields(texImage
);
2484 /* no error, set the tex image parameters */
2485 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2486 depth
, border
, internalFormat
);
2487 texImage
->TexFormat
=
2488 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2492 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2499 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2500 GLsizei width
, GLsizei height
, GLsizei depth
,
2501 GLint border
, GLenum format
, GLenum type
,
2502 const GLvoid
*pixels
)
2504 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2505 depth
, border
, format
, type
, pixels
);
2511 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2512 GLint xoffset
, GLsizei width
,
2513 GLenum format
, GLenum type
,
2514 const GLvoid
*pixels
)
2516 GLsizei postConvWidth
= width
;
2517 struct gl_texture_object
*texObj
;
2518 struct gl_texture_image
*texImage
= NULL
;
2519 GET_CURRENT_CONTEXT(ctx
);
2520 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2522 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2523 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2524 _mesa_lookup_enum_by_nr(target
), level
,
2525 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2526 _mesa_lookup_enum_by_nr(type
), pixels
);
2528 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2529 _mesa_update_state(ctx
);
2531 #if FEATURE_convolve
2532 /* XXX should test internal format */
2533 if (_mesa_is_color_format(format
)) {
2534 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2538 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2539 postConvWidth
, 1, 1, format
, type
)) {
2540 return; /* error was detected */
2544 texObj
= get_current_tex_object(ctx
, target
);
2547 _mesa_lock_texture(ctx
, texObj
);
2549 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2551 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2552 postConvWidth
, 1, 1,
2553 format
, type
, texImage
)) {
2554 /* error was recorded */
2556 else if (width
> 0) {
2557 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2558 xoffset
+= texImage
->Border
;
2560 ASSERT(ctx
->Driver
.TexSubImage1D
);
2561 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2562 format
, type
, pixels
, &ctx
->Unpack
,
2565 check_gen_mipmap(ctx
, target
, texObj
, level
);
2567 ctx
->NewState
|= _NEW_TEXTURE
;
2570 _mesa_unlock_texture(ctx
, texObj
);
2575 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2576 GLint xoffset
, GLint yoffset
,
2577 GLsizei width
, GLsizei height
,
2578 GLenum format
, GLenum type
,
2579 const GLvoid
*pixels
)
2581 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2582 struct gl_texture_object
*texObj
;
2583 struct gl_texture_image
*texImage
;
2584 GET_CURRENT_CONTEXT(ctx
);
2585 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2587 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2588 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2589 _mesa_lookup_enum_by_nr(target
), level
,
2590 xoffset
, yoffset
, width
, height
,
2591 _mesa_lookup_enum_by_nr(format
),
2592 _mesa_lookup_enum_by_nr(type
), pixels
);
2594 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2595 _mesa_update_state(ctx
);
2597 #if FEATURE_convolve
2598 /* XXX should test internal format */
2599 if (_mesa_is_color_format(format
)) {
2600 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2605 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2606 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2607 return; /* error was detected */
2610 texObj
= get_current_tex_object(ctx
, target
);
2612 _mesa_lock_texture(ctx
, texObj
);
2614 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2616 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2617 postConvWidth
, postConvHeight
, 1,
2618 format
, type
, texImage
)) {
2619 /* error was recorded */
2621 else if (width
> 0 && height
>= 0) {
2622 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2623 xoffset
+= texImage
->Border
;
2624 yoffset
+= texImage
->Border
;
2626 ASSERT(ctx
->Driver
.TexSubImage2D
);
2627 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2628 width
, height
, format
, type
, pixels
,
2629 &ctx
->Unpack
, texObj
, texImage
);
2631 check_gen_mipmap(ctx
, target
, texObj
, level
);
2633 ctx
->NewState
|= _NEW_TEXTURE
;
2636 _mesa_unlock_texture(ctx
, texObj
);
2642 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2643 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2644 GLsizei width
, GLsizei height
, GLsizei depth
,
2645 GLenum format
, GLenum type
,
2646 const GLvoid
*pixels
)
2648 struct gl_texture_object
*texObj
;
2649 struct gl_texture_image
*texImage
;
2650 GET_CURRENT_CONTEXT(ctx
);
2651 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2653 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2654 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2655 _mesa_lookup_enum_by_nr(target
), level
,
2656 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2657 _mesa_lookup_enum_by_nr(format
),
2658 _mesa_lookup_enum_by_nr(type
), pixels
);
2660 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2661 _mesa_update_state(ctx
);
2663 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2664 width
, height
, depth
, format
, type
)) {
2665 return; /* error was detected */
2668 texObj
= get_current_tex_object(ctx
, target
);
2670 _mesa_lock_texture(ctx
, texObj
);
2672 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2674 if (subtexture_error_check2(ctx
, 3, target
, level
,
2675 xoffset
, yoffset
, zoffset
,
2676 width
, height
, depth
,
2677 format
, type
, texImage
)) {
2678 /* error was recorded */
2680 else if (width
> 0 && height
> 0 && height
> 0) {
2681 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2682 xoffset
+= texImage
->Border
;
2683 yoffset
+= texImage
->Border
;
2684 zoffset
+= texImage
->Border
;
2686 ASSERT(ctx
->Driver
.TexSubImage3D
);
2687 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2688 xoffset
, yoffset
, zoffset
,
2689 width
, height
, depth
,
2690 format
, type
, pixels
,
2691 &ctx
->Unpack
, texObj
, texImage
);
2693 check_gen_mipmap(ctx
, target
, texObj
, level
);
2695 ctx
->NewState
|= _NEW_TEXTURE
;
2698 _mesa_unlock_texture(ctx
, texObj
);
2704 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2705 GLenum internalFormat
,
2707 GLsizei width
, GLint border
)
2709 struct gl_texture_object
*texObj
;
2710 struct gl_texture_image
*texImage
;
2711 GLsizei postConvWidth
= width
;
2712 const GLuint face
= _mesa_tex_target_to_face(target
);
2713 GET_CURRENT_CONTEXT(ctx
);
2714 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2716 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2717 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2718 _mesa_lookup_enum_by_nr(target
), level
,
2719 _mesa_lookup_enum_by_nr(internalFormat
),
2720 x
, y
, width
, border
);
2722 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2723 _mesa_update_state(ctx
);
2725 #if FEATURE_convolve
2726 if (_mesa_is_color_format(internalFormat
)) {
2727 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2731 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2732 postConvWidth
, 1, border
))
2735 texObj
= get_current_tex_object(ctx
, target
);
2737 _mesa_lock_texture(ctx
, texObj
);
2739 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2741 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2744 if (texImage
->Data
) {
2745 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2748 ASSERT(texImage
->Data
== NULL
);
2750 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2751 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2752 border
, internalFormat
);
2754 /* Choose actual texture format */
2755 texImage
->TexFormat
=
2756 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2758 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2760 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2761 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2762 x
, y
, width
, border
);
2764 ASSERT(texImage
->TexFormat
);
2766 _mesa_set_fetch_functions(texImage
, 1);
2768 check_gen_mipmap(ctx
, target
, texObj
, level
);
2770 update_fbo_texture(ctx
, texObj
, face
, level
);
2773 texObj
->_Complete
= GL_FALSE
;
2774 ctx
->NewState
|= _NEW_TEXTURE
;
2777 _mesa_unlock_texture(ctx
, texObj
);
2783 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2784 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2787 struct gl_texture_object
*texObj
;
2788 struct gl_texture_image
*texImage
;
2789 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2790 const GLuint face
= _mesa_tex_target_to_face(target
);
2791 GET_CURRENT_CONTEXT(ctx
);
2792 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2794 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2795 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2796 _mesa_lookup_enum_by_nr(target
), level
,
2797 _mesa_lookup_enum_by_nr(internalFormat
),
2798 x
, y
, width
, height
, border
);
2800 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2801 _mesa_update_state(ctx
);
2803 #if FEATURE_convolve
2804 if (_mesa_is_color_format(internalFormat
)) {
2805 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2810 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2811 postConvWidth
, postConvHeight
, border
))
2814 texObj
= get_current_tex_object(ctx
, target
);
2816 _mesa_lock_texture(ctx
, texObj
);
2818 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2821 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2824 if (texImage
->Data
) {
2825 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2828 ASSERT(texImage
->Data
== NULL
);
2830 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2831 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2832 postConvWidth
, postConvHeight
, 1,
2833 border
, internalFormat
);
2835 /* Choose actual texture format */
2836 texImage
->TexFormat
=
2837 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2839 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2841 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2842 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2843 x
, y
, width
, height
, border
);
2845 ASSERT(texImage
->TexFormat
);
2847 _mesa_set_fetch_functions(texImage
, 2);
2849 check_gen_mipmap(ctx
, target
, texObj
, level
);
2851 update_fbo_texture(ctx
, texObj
, face
, level
);
2854 texObj
->_Complete
= GL_FALSE
;
2855 ctx
->NewState
|= _NEW_TEXTURE
;
2858 _mesa_unlock_texture(ctx
, texObj
);
2863 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2864 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2866 struct gl_texture_object
*texObj
;
2867 struct gl_texture_image
*texImage
;
2868 GLsizei postConvWidth
= width
;
2872 GET_CURRENT_CONTEXT(ctx
);
2873 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2875 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2876 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2877 _mesa_lookup_enum_by_nr(target
),
2878 level
, xoffset
, x
, y
, width
);
2880 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2881 _mesa_update_state(ctx
);
2883 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2886 texObj
= get_current_tex_object(ctx
, target
);
2888 _mesa_lock_texture(ctx
, texObj
);
2890 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2892 #if FEATURE_convolve
2893 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2894 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2898 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2899 xoffset
, 0, 0, postConvWidth
, 1,
2901 /* error was recorded */
2904 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2905 xoffset
+= texImage
->Border
;
2907 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2909 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2910 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2911 xoffset
, x
, y
, width
);
2913 check_gen_mipmap(ctx
, target
, texObj
, level
);
2915 ctx
->NewState
|= _NEW_TEXTURE
;
2919 _mesa_unlock_texture(ctx
, texObj
);
2925 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2926 GLint xoffset
, GLint yoffset
,
2927 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2929 struct gl_texture_object
*texObj
;
2930 struct gl_texture_image
*texImage
;
2931 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2932 GET_CURRENT_CONTEXT(ctx
);
2933 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2935 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2936 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2937 _mesa_lookup_enum_by_nr(target
),
2938 level
, xoffset
, yoffset
, x
, y
, width
, height
);
2940 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2941 _mesa_update_state(ctx
);
2943 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2946 texObj
= get_current_tex_object(ctx
, target
);
2948 _mesa_lock_texture(ctx
, texObj
);
2950 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2952 #if FEATURE_convolve
2953 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2954 _mesa_adjust_image_for_convolution(ctx
, 2,
2955 &postConvWidth
, &postConvHeight
);
2959 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
2960 xoffset
, yoffset
, 0,
2961 postConvWidth
, postConvHeight
,
2963 /* error was recorded */
2966 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2967 xoffset
+= texImage
->Border
;
2968 yoffset
+= texImage
->Border
;
2970 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2972 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2973 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2974 x
, y
, width
, height
);
2976 check_gen_mipmap(ctx
, target
, texObj
, level
);
2978 ctx
->NewState
|= _NEW_TEXTURE
;
2982 _mesa_unlock_texture(ctx
, texObj
);
2988 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2989 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2990 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2992 struct gl_texture_object
*texObj
;
2993 struct gl_texture_image
*texImage
;
2994 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2995 GET_CURRENT_CONTEXT(ctx
);
2996 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2998 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2999 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
3000 _mesa_lookup_enum_by_nr(target
),
3001 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3003 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3004 _mesa_update_state(ctx
);
3006 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3009 texObj
= get_current_tex_object(ctx
, target
);
3011 _mesa_lock_texture(ctx
, texObj
);
3013 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3015 #if FEATURE_convolve
3016 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3017 _mesa_adjust_image_for_convolution(ctx
, 2,
3018 &postConvWidth
, &postConvHeight
);
3022 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3023 zoffset
, postConvWidth
, postConvHeight
,
3025 /* error was recored */
3028 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3029 xoffset
+= texImage
->Border
;
3030 yoffset
+= texImage
->Border
;
3031 zoffset
+= texImage
->Border
;
3033 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3035 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3036 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3037 xoffset
, yoffset
, zoffset
,
3038 x
, y
, width
, height
);
3040 check_gen_mipmap(ctx
, target
, texObj
, level
);
3042 ctx
->NewState
|= _NEW_TEXTURE
;
3046 _mesa_unlock_texture(ctx
, texObj
);
3052 /**********************************************************************/
3053 /****** Compressed Textures ******/
3054 /**********************************************************************/
3058 * Return expected size of a compressed texture.
3061 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3064 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3065 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3070 * Return compressed texture block size, in pixels.
3073 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3075 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3076 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3081 * Error checking for glCompressedTexImage[123]D().
3082 * \return error code or GL_NO_ERROR.
3085 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3086 GLenum target
, GLint level
,
3087 GLenum internalFormat
, GLsizei width
,
3088 GLsizei height
, GLsizei depth
, GLint border
,
3091 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3093 if (dimensions
== 1) {
3094 /* 1D compressed textures not allowed */
3095 return GL_INVALID_ENUM
;
3097 else if (dimensions
== 2) {
3098 if (target
== GL_PROXY_TEXTURE_2D
) {
3099 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3101 else if (target
== GL_TEXTURE_2D
) {
3102 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3104 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3105 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3106 return GL_INVALID_ENUM
; /*target*/
3107 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3109 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3110 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3111 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3112 return GL_INVALID_ENUM
; /*target*/
3113 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3116 return GL_INVALID_ENUM
; /*target*/
3119 else if (dimensions
== 3) {
3120 /* 3D compressed textures not allowed */
3121 return GL_INVALID_ENUM
;
3124 maxTextureSize
= 1 << (maxLevels
- 1);
3126 /* This will detect any invalid internalFormat value */
3127 if (!is_compressed_format(ctx
, internalFormat
))
3128 return GL_INVALID_ENUM
;
3130 /* This should really never fail */
3131 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3132 return GL_INVALID_ENUM
;
3135 return GL_INVALID_VALUE
;
3138 * XXX We should probably use the proxy texture error check function here.
3140 if (width
< 1 || width
> maxTextureSize
||
3141 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3142 return GL_INVALID_VALUE
;
3144 if ((height
< 1 || height
> maxTextureSize
||
3145 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3147 return GL_INVALID_VALUE
;
3149 if ((depth
< 1 || depth
> maxTextureSize
||
3150 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3152 return GL_INVALID_VALUE
;
3154 /* For cube map, width must equal height */
3155 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3156 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3157 return GL_INVALID_VALUE
;
3159 if (level
< 0 || level
>= maxLevels
)
3160 return GL_INVALID_VALUE
;
3162 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3163 if (expectedSize
!= imageSize
)
3164 return GL_INVALID_VALUE
;
3166 #if FEATURE_EXT_texture_sRGB
3167 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3168 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3169 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3170 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3172 return GL_INVALID_OPERATION
;
3181 * Error checking for glCompressedTexSubImage[123]D().
3182 * \warning There are some bad assumptions here about the size of compressed
3183 * texture tiles (multiple of 4) used to test the validity of the
3184 * offset and size parameters.
3185 * \return error code or GL_NO_ERROR.
3188 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3189 GLenum target
, GLint level
,
3190 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3191 GLsizei width
, GLsizei height
, GLsizei depth
,
3192 GLenum format
, GLsizei imageSize
)
3194 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3198 if (dimensions
== 1) {
3199 /* 1D compressed textures not allowed */
3200 return GL_INVALID_ENUM
;
3202 else if (dimensions
== 2) {
3203 if (target
== GL_PROXY_TEXTURE_2D
) {
3204 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3206 else if (target
== GL_TEXTURE_2D
) {
3207 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3209 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3210 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3211 return GL_INVALID_ENUM
; /*target*/
3212 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3214 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3215 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3216 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3217 return GL_INVALID_ENUM
; /*target*/
3218 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3221 return GL_INVALID_ENUM
; /*target*/
3224 else if (dimensions
== 3) {
3225 /* 3D compressed textures not allowed */
3226 return GL_INVALID_ENUM
;
3229 maxTextureSize
= 1 << (maxLevels
- 1);
3231 /* this will catch any invalid compressed format token */
3232 if (!is_compressed_format(ctx
, format
))
3233 return GL_INVALID_ENUM
;
3235 if (width
< 1 || width
> maxTextureSize
)
3236 return GL_INVALID_VALUE
;
3238 if ((height
< 1 || height
> maxTextureSize
)
3240 return GL_INVALID_VALUE
;
3242 if (level
< 0 || level
>= maxLevels
)
3243 return GL_INVALID_VALUE
;
3246 * do checks which depend on compression block size
3248 get_compressed_block_size(format
, &bw
, &bh
);
3250 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3251 return GL_INVALID_VALUE
;
3253 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3254 return GL_INVALID_VALUE
;
3256 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3257 return GL_INVALID_VALUE
;
3259 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3260 if (expectedSize
!= imageSize
)
3261 return GL_INVALID_VALUE
;
3268 * Do second part of glCompressedTexSubImage error checking.
3269 * \return GL_TRUE if error found, GL_FALSE otherwise.
3272 compressed_subtexture_error_check2(GLcontext
*ctx
, GLuint dims
,
3273 GLsizei width
, GLsizei height
,
3274 GLsizei depth
, GLenum format
,
3275 struct gl_texture_image
*texImage
)
3278 if ((GLint
) format
!= texImage
->InternalFormat
) {
3279 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3280 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3284 if (((width
== 1 || width
== 2) &&
3285 (GLuint
) width
!= texImage
->Width
) ||
3286 (width
> texImage
->Width
)) {
3287 _mesa_error(ctx
, GL_INVALID_VALUE
,
3288 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3293 if (((height
== 1 || height
== 2) &&
3294 (GLuint
) height
!= texImage
->Height
) ||
3295 (height
> texImage
->Height
)) {
3296 _mesa_error(ctx
, GL_INVALID_VALUE
,
3297 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3303 if (((depth
== 1 || depth
== 2) &&
3304 (GLuint
) depth
!= texImage
->Depth
) ||
3305 (depth
> texImage
->Depth
)) {
3306 _mesa_error(ctx
, GL_INVALID_VALUE
,
3307 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3318 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3319 GLenum internalFormat
, GLsizei width
,
3320 GLint border
, GLsizei imageSize
,
3323 GET_CURRENT_CONTEXT(ctx
);
3324 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3326 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3327 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3328 _mesa_lookup_enum_by_nr(target
), level
,
3329 _mesa_lookup_enum_by_nr(internalFormat
),
3330 width
, border
, imageSize
, data
);
3332 if (target
== GL_TEXTURE_1D
) {
3333 /* non-proxy target */
3334 struct gl_texture_object
*texObj
;
3335 struct gl_texture_image
*texImage
;
3336 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3337 internalFormat
, width
, 1, 1, border
, imageSize
);
3339 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3343 texObj
= get_current_tex_object(ctx
, target
);
3345 _mesa_lock_texture(ctx
, texObj
);
3347 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3349 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3352 if (texImage
->Data
) {
3353 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3355 ASSERT(texImage
->Data
== NULL
);
3357 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3358 border
, internalFormat
);
3360 /* Choose actual texture format */
3361 texImage
->TexFormat
=
3362 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3364 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3366 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3367 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3368 internalFormat
, width
, border
,
3372 _mesa_set_fetch_functions(texImage
, 1);
3374 check_gen_mipmap(ctx
, target
, texObj
, level
);
3377 texObj
->_Complete
= GL_FALSE
;
3378 ctx
->NewState
|= _NEW_TEXTURE
;
3381 _mesa_unlock_texture(ctx
, texObj
);
3383 else if (target
== GL_PROXY_TEXTURE_1D
) {
3384 /* Proxy texture: check for errors and update proxy state */
3385 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3386 internalFormat
, width
, 1, 1, border
, imageSize
);
3388 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3389 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3390 internalFormat
, GL_NONE
, GL_NONE
,
3391 width
, 1, 1, border
);
3394 /* if error, clear all proxy texture image parameters */
3395 struct gl_texture_image
*texImage
;
3396 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3398 clear_teximage_fields(texImage
);
3401 /* store the teximage parameters */
3402 struct gl_texture_object
*texObj
;
3403 struct gl_texture_image
*texImage
;
3405 texObj
= get_current_tex_object(ctx
, target
);
3407 _mesa_lock_texture(ctx
, texObj
);
3409 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3410 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3411 border
, internalFormat
);
3413 _mesa_unlock_texture(ctx
, texObj
);
3417 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3424 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3425 GLenum internalFormat
, GLsizei width
,
3426 GLsizei height
, GLint border
, GLsizei imageSize
,
3429 GET_CURRENT_CONTEXT(ctx
);
3430 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3432 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3433 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3434 _mesa_lookup_enum_by_nr(target
), level
,
3435 _mesa_lookup_enum_by_nr(internalFormat
),
3436 width
, height
, border
, imageSize
, data
);
3438 if (target
== GL_TEXTURE_2D
||
3439 (ctx
->Extensions
.ARB_texture_cube_map
&&
3440 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3441 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3442 /* non-proxy target */
3443 struct gl_texture_object
*texObj
;
3444 struct gl_texture_image
*texImage
;
3446 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3447 internalFormat
, width
, height
, 1, border
, imageSize
);
3449 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3453 texObj
= get_current_tex_object(ctx
, target
);
3455 _mesa_lock_texture(ctx
, texObj
);
3457 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3459 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3462 if (texImage
->Data
) {
3463 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3465 ASSERT(texImage
->Data
== NULL
);
3467 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3468 border
, internalFormat
);
3470 /* Choose actual texture format */
3471 texImage
->TexFormat
=
3472 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3474 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3476 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3477 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3478 internalFormat
, width
, height
,
3479 border
, imageSize
, data
,
3482 _mesa_set_fetch_functions(texImage
, 2);
3484 check_gen_mipmap(ctx
, target
, texObj
, level
);
3487 texObj
->_Complete
= GL_FALSE
;
3488 ctx
->NewState
|= _NEW_TEXTURE
;
3491 _mesa_unlock_texture(ctx
, texObj
);
3493 else if (target
== GL_PROXY_TEXTURE_2D
||
3494 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3495 ctx
->Extensions
.ARB_texture_cube_map
)) {
3496 /* Proxy texture: check for errors and update proxy state */
3497 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3498 internalFormat
, width
, height
, 1, border
, imageSize
);
3500 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3501 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3502 internalFormat
, GL_NONE
, GL_NONE
,
3503 width
, height
, 1, border
);
3506 /* if error, clear all proxy texture image parameters */
3507 struct gl_texture_image
*texImage
;
3508 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3510 clear_teximage_fields(texImage
);
3513 /* store the teximage parameters */
3514 struct gl_texture_object
*texObj
;
3515 struct gl_texture_image
*texImage
;
3517 texObj
= get_current_tex_object(ctx
, target
);
3519 _mesa_lock_texture(ctx
, texObj
);
3521 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3522 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3523 border
, internalFormat
);
3525 _mesa_unlock_texture(ctx
, texObj
);
3529 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3536 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3537 GLenum internalFormat
, GLsizei width
,
3538 GLsizei height
, GLsizei depth
, GLint border
,
3539 GLsizei imageSize
, const GLvoid
*data
)
3541 GET_CURRENT_CONTEXT(ctx
);
3542 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3544 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3545 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3546 _mesa_lookup_enum_by_nr(target
), level
,
3547 _mesa_lookup_enum_by_nr(internalFormat
),
3548 width
, height
, depth
, border
, imageSize
, data
);
3550 if (target
== GL_TEXTURE_3D
) {
3551 /* non-proxy target */
3552 struct gl_texture_object
*texObj
;
3553 struct gl_texture_image
*texImage
;
3554 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3555 internalFormat
, width
, height
, depth
, border
, imageSize
);
3557 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3561 texObj
= get_current_tex_object(ctx
, target
);
3563 _mesa_lock_texture(ctx
, texObj
);
3565 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3567 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3570 if (texImage
->Data
) {
3571 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3573 ASSERT(texImage
->Data
== NULL
);
3575 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3576 width
, height
, depth
,
3577 border
, internalFormat
);
3579 /* Choose actual texture format */
3580 texImage
->TexFormat
=
3581 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3583 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3585 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3586 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3588 width
, height
, depth
,
3589 border
, imageSize
, data
,
3592 _mesa_set_fetch_functions(texImage
, 3);
3594 check_gen_mipmap(ctx
, target
, texObj
, level
);
3597 texObj
->_Complete
= GL_FALSE
;
3598 ctx
->NewState
|= _NEW_TEXTURE
;
3601 _mesa_unlock_texture(ctx
, texObj
);
3603 else if (target
== GL_PROXY_TEXTURE_3D
) {
3604 /* Proxy texture: check for errors and update proxy state */
3605 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3606 internalFormat
, width
, height
, depth
, border
, imageSize
);
3608 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3609 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3610 internalFormat
, GL_NONE
, GL_NONE
,
3611 width
, height
, depth
, border
);
3614 /* if error, clear all proxy texture image parameters */
3615 struct gl_texture_image
*texImage
;
3616 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3618 clear_teximage_fields(texImage
);
3621 /* store the teximage parameters */
3622 struct gl_texture_object
*texObj
;
3623 struct gl_texture_image
*texImage
;
3625 texObj
= get_current_tex_object(ctx
, target
);
3627 _mesa_lock_texture(ctx
, texObj
);
3629 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3630 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3631 depth
, border
, internalFormat
);
3633 _mesa_unlock_texture(ctx
, texObj
);
3637 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3644 * Common helper for glCompressedTexSubImage1/2/3D().
3647 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3648 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3649 GLsizei width
, GLsizei height
, GLsizei depth
,
3650 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3652 struct gl_texture_object
*texObj
;
3653 struct gl_texture_image
*texImage
;
3655 GET_CURRENT_CONTEXT(ctx
);
3656 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3658 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3659 xoffset
, 0, 0, /* pos */
3660 width
, height
, depth
, /* size */
3663 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3667 texObj
= get_current_tex_object(ctx
, target
);
3669 _mesa_lock_texture(ctx
, texObj
);
3671 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3674 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3675 format
, texImage
)) {
3676 /* error was recorded */
3678 else if (width
> 0 && height
> 0 && depth
> 0) {
3681 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3682 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3684 format
, imageSize
, data
,
3689 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3690 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3693 format
, imageSize
, data
,
3698 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3699 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3700 xoffset
, yoffset
, zoffset
,
3701 width
, height
, depth
,
3702 format
, imageSize
, data
,
3710 check_gen_mipmap(ctx
, target
, texObj
, level
);
3712 ctx
->NewState
|= _NEW_TEXTURE
;
3715 _mesa_unlock_texture(ctx
, texObj
);
3720 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3721 GLsizei width
, GLenum format
,
3722 GLsizei imageSize
, const GLvoid
*data
)
3724 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3725 format
, imageSize
, data
);
3730 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3731 GLint yoffset
, GLsizei width
, GLsizei height
,
3732 GLenum format
, GLsizei imageSize
,
3735 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3736 width
, height
, 1, format
, imageSize
, data
);
3741 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3742 GLint yoffset
, GLint zoffset
, GLsizei width
,
3743 GLsizei height
, GLsizei depth
, GLenum format
,
3744 GLsizei imageSize
, const GLvoid
*data
)
3746 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3747 width
, height
, depth
, format
, imageSize
, data
);