2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
39 #include "framebuffer.h"
45 #include "texcompress.h"
46 #include "texformat.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
65 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
69 _mesa_alloc_texmemory(GLsizei bytes
)
71 return _mesa_align_malloc(bytes
, 512);
76 * Free texture memory allocated with _mesa_alloc_texmemory()
79 _mesa_free_texmemory(void *m
)
88 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
90 #if CHAN_TYPE != GL_UNSIGNED_BYTE
91 _mesa_problem(NULL
, "PrintTexture not supported");
94 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
97 _mesa_printf("No texture data\n");
101 switch (img
->Format
) {
108 case GL_LUMINANCE_ALPHA
:
118 _mesa_problem(NULL
, "error in PrintTexture\n");
122 for (i
= 0; i
< img
->Height
; i
++) {
123 for (j
= 0; j
< img
->Width
; j
++) {
125 _mesa_printf("%02x ", data
[0]);
127 _mesa_printf("%02x%02x ", data
[0], data
[1]);
129 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
131 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
132 data
+= (img
->RowStride
- img
->Width
) * c
;
134 /* XXX use img->ImageStride here */
143 * Compute floor(log_base_2(n)).
144 * If n < 0 return -1.
173 * Return the simple base format for a given internal texture format.
174 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
176 * \param ctx GL context.
177 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
179 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
180 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
182 * This is the format which is used during texture application (i.e. the
183 * texture format and env mode determine the arithmetic used.
185 * XXX this could be static
188 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
190 switch (internalFormat
) {
205 case GL_LUMINANCE_ALPHA
:
206 case GL_LUMINANCE4_ALPHA4
:
207 case GL_LUMINANCE6_ALPHA2
:
208 case GL_LUMINANCE8_ALPHA8
:
209 case GL_LUMINANCE12_ALPHA4
:
210 case GL_LUMINANCE12_ALPHA12
:
211 case GL_LUMINANCE16_ALPHA16
:
212 return GL_LUMINANCE_ALPHA
;
243 if (ctx
->Extensions
.EXT_paletted_texture
) {
244 switch (internalFormat
) {
246 case GL_COLOR_INDEX1_EXT
:
247 case GL_COLOR_INDEX2_EXT
:
248 case GL_COLOR_INDEX4_EXT
:
249 case GL_COLOR_INDEX8_EXT
:
250 case GL_COLOR_INDEX12_EXT
:
251 case GL_COLOR_INDEX16_EXT
:
252 return GL_COLOR_INDEX
;
258 if (ctx
->Extensions
.ARB_depth_texture
) {
259 switch (internalFormat
) {
260 case GL_DEPTH_COMPONENT
:
261 case GL_DEPTH_COMPONENT16
:
262 case GL_DEPTH_COMPONENT24
:
263 case GL_DEPTH_COMPONENT32
:
264 return GL_DEPTH_COMPONENT
;
270 switch (internalFormat
) {
271 case GL_COMPRESSED_ALPHA
:
273 case GL_COMPRESSED_LUMINANCE
:
275 case GL_COMPRESSED_LUMINANCE_ALPHA
:
276 return GL_LUMINANCE_ALPHA
;
277 case GL_COMPRESSED_INTENSITY
:
279 case GL_COMPRESSED_RGB
:
281 case GL_COMPRESSED_RGBA
:
287 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
288 switch (internalFormat
) {
289 case GL_COMPRESSED_RGB_FXT1_3DFX
:
291 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
298 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
299 switch (internalFormat
) {
300 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
302 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
303 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
304 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
311 if (ctx
->Extensions
.S3_s3tc
) {
312 switch (internalFormat
) {
324 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
325 if (internalFormat
== GL_YCBCR_MESA
)
326 return GL_YCBCR_MESA
;
329 if (ctx
->Extensions
.ARB_texture_float
) {
330 switch (internalFormat
) {
331 case GL_ALPHA16F_ARB
:
332 case GL_ALPHA32F_ARB
:
340 case GL_INTENSITY16F_ARB
:
341 case GL_INTENSITY32F_ARB
:
343 case GL_LUMINANCE16F_ARB
:
344 case GL_LUMINANCE32F_ARB
:
346 case GL_LUMINANCE_ALPHA16F_ARB
:
347 case GL_LUMINANCE_ALPHA32F_ARB
:
348 return GL_LUMINANCE_ALPHA
;
354 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
355 switch (internalFormat
) {
364 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
365 switch (internalFormat
) {
374 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
375 switch (internalFormat
) {
376 case GL_DEPTH_STENCIL_EXT
:
377 case GL_DEPTH24_STENCIL8_EXT
:
378 return GL_DEPTH_STENCIL_EXT
;
384 #if FEATURE_EXT_texture_sRGB
385 if (ctx
->Extensions
.EXT_texture_sRGB
) {
386 switch (internalFormat
) {
389 case GL_COMPRESSED_SRGB_EXT
:
390 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
392 case GL_SRGB_ALPHA_EXT
:
393 case GL_SRGB8_ALPHA8_EXT
:
394 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
395 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
396 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
397 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
399 case GL_SLUMINANCE_ALPHA_EXT
:
400 case GL_SLUMINANCE8_ALPHA8_EXT
:
401 case GL_COMPRESSED_SLUMINANCE_EXT
:
402 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
403 return GL_LUMINANCE_ALPHA
;
404 case GL_SLUMINANCE_EXT
:
405 case GL_SLUMINANCE8_EXT
:
412 #endif /* FEATURE_EXT_texture_sRGB */
414 return -1; /* error */
419 * Test if it is a supported compressed format.
421 * \param internalFormat the internal format token provided by the user.
423 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
424 * GL_FALSE otherwise.
426 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
430 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
432 GLint supported
[100]; /* 100 should be plenty */
435 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
437 for (i
= 0; i
< n
; i
++) {
438 if ((GLint
) internalFormat
== supported
[i
]) {
447 * For cube map faces, return a face index in [0,5].
448 * For other targets return 0;
451 _mesa_tex_target_to_face(GLenum target
)
453 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
454 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
455 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
463 * Store a gl_texture_image pointer in a gl_texture_object structure
464 * according to the target and level parameters.
466 * \param tObj texture object.
467 * \param target texture target.
468 * \param level image level.
469 * \param texImage texture image.
471 * This was basically prompted by the introduction of cube maps.
474 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
475 GLenum target
, GLint level
,
476 struct gl_texture_image
*texImage
)
478 const GLuint face
= _mesa_tex_target_to_face(target
);
482 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
484 tObj
->Image
[face
][level
] = texImage
;
486 /* Set the 'back' pointer */
487 texImage
->TexObject
= tObj
;
492 * Allocate a texture image structure.
494 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
497 * \return a pointer to gl_texture_image struct with all fields initialized to
500 struct gl_texture_image
*
501 _mesa_new_texture_image( GLcontext
*ctx
)
504 return CALLOC_STRUCT(gl_texture_image
);
509 * Free texture image data.
510 * This function is a fallback called via ctx->Driver.FreeTexImageData().
512 * \param texImage texture image.
514 * Free the texture image data if it's not marked as client data.
517 _mesa_free_texture_image_data(GLcontext
*ctx
,
518 struct gl_texture_image
*texImage
)
522 if (texImage
->Data
&& !texImage
->IsClientData
) {
523 /* free the old texture data */
524 _mesa_free_texmemory(texImage
->Data
);
527 texImage
->Data
= NULL
;
532 * Free texture image.
534 * \param texImage texture image.
536 * Free the texture image structure and the associated image data.
539 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
541 /* Free texImage->Data and/or any other driver-specific texture
544 ASSERT(ctx
->Driver
.FreeTexImageData
);
545 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
547 ASSERT(texImage
->Data
== NULL
);
548 if (texImage
->ImageOffsets
)
549 _mesa_free(texImage
->ImageOffsets
);
550 _mesa_free(texImage
);
555 * Test if a target is a proxy target.
557 * \param target texture target.
559 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
562 _mesa_is_proxy_texture(GLenum target
)
564 /* NUM_TEXTURE_TARGETS should match number of terms below */
565 assert(NUM_TEXTURE_TARGETS
== 7);
567 return (target
== GL_PROXY_TEXTURE_1D
||
568 target
== GL_PROXY_TEXTURE_2D
||
569 target
== GL_PROXY_TEXTURE_3D
||
570 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
571 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
572 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
573 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
578 * Get the texture object that corresponds to the target of the given texture unit.
580 * \param ctx GL context.
581 * \param texUnit texture unit.
582 * \param target texture target.
584 * \return pointer to the texture object on success, or NULL on failure.
586 * \sa gl_texture_unit.
588 struct gl_texture_object
*
589 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
594 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
595 case GL_PROXY_TEXTURE_1D
:
596 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
598 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
599 case GL_PROXY_TEXTURE_2D
:
600 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
602 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
603 case GL_PROXY_TEXTURE_3D
:
604 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
605 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
606 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
607 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
608 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
609 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
610 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
611 case GL_TEXTURE_CUBE_MAP_ARB
:
612 return ctx
->Extensions
.ARB_texture_cube_map
613 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
614 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
615 return ctx
->Extensions
.ARB_texture_cube_map
616 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
617 case GL_TEXTURE_RECTANGLE_NV
:
618 return ctx
->Extensions
.NV_texture_rectangle
619 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
620 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
621 return ctx
->Extensions
.NV_texture_rectangle
622 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
623 case GL_TEXTURE_1D_ARRAY_EXT
:
624 return ctx
->Extensions
.MESA_texture_array
625 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
626 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
627 return ctx
->Extensions
.MESA_texture_array
628 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
629 case GL_TEXTURE_2D_ARRAY_EXT
:
630 return ctx
->Extensions
.MESA_texture_array
631 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
632 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
633 return ctx
->Extensions
.MESA_texture_array
634 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
636 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
643 * Get a texture image pointer from a texture object, given a texture
644 * target and mipmap level. The target and level parameters should
645 * have already been error-checked.
647 * \param ctx GL context.
648 * \param texObj texture unit.
649 * \param target texture target.
650 * \param level image level.
652 * \return pointer to the texture image structure, or NULL on failure.
654 struct gl_texture_image
*
655 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
656 GLenum target
, GLint level
)
658 const GLuint face
= _mesa_tex_target_to_face(target
);
662 ASSERT(level
< MAX_TEXTURE_LEVELS
);
664 return texObj
->Image
[face
][level
];
669 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
670 * it and install it. Only return NULL if passed a bad parameter or run
673 struct gl_texture_image
*
674 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
675 GLenum target
, GLint level
)
677 struct gl_texture_image
*texImage
;
682 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
684 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
686 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
690 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
698 * Return pointer to the specified proxy texture image.
699 * Note that proxy textures are per-context, not per-texture unit.
700 * \return pointer to texture image or NULL if invalid target, invalid
701 * level, or out of memory.
703 struct gl_texture_image
*
704 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
706 struct gl_texture_image
*texImage
;
713 case GL_PROXY_TEXTURE_1D
:
714 if (level
>= ctx
->Const
.MaxTextureLevels
)
716 texIndex
= TEXTURE_1D_INDEX
;
718 case GL_PROXY_TEXTURE_2D
:
719 if (level
>= ctx
->Const
.MaxTextureLevels
)
721 texIndex
= TEXTURE_2D_INDEX
;
723 case GL_PROXY_TEXTURE_3D
:
724 if (level
>= ctx
->Const
.Max3DTextureLevels
)
726 texIndex
= TEXTURE_3D_INDEX
;
728 case GL_PROXY_TEXTURE_CUBE_MAP
:
729 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
731 texIndex
= TEXTURE_CUBE_INDEX
;
733 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
736 texIndex
= TEXTURE_RECT_INDEX
;
738 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
739 if (level
>= ctx
->Const
.MaxTextureLevels
)
741 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
743 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
744 if (level
>= ctx
->Const
.MaxTextureLevels
)
746 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
752 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
754 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
756 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
759 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
760 /* Set the 'back' pointer */
761 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
768 * Get the maximum number of allowed mipmap levels.
770 * \param ctx GL context.
771 * \param target texture target.
773 * \return the maximum number of allowed mipmap levels for the given
774 * texture target, or zero if passed a bad target.
779 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
783 case GL_PROXY_TEXTURE_1D
:
785 case GL_PROXY_TEXTURE_2D
:
786 return ctx
->Const
.MaxTextureLevels
;
788 case GL_PROXY_TEXTURE_3D
:
789 return ctx
->Const
.Max3DTextureLevels
;
790 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
791 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
792 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
793 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
794 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
795 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
796 case GL_TEXTURE_CUBE_MAP_ARB
:
797 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
798 return ctx
->Extensions
.ARB_texture_cube_map
799 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
800 case GL_TEXTURE_RECTANGLE_NV
:
801 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
802 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
803 case GL_TEXTURE_1D_ARRAY_EXT
:
804 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
805 case GL_TEXTURE_2D_ARRAY_EXT
:
806 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
807 return ctx
->Extensions
.MESA_texture_array
808 ? ctx
->Const
.MaxTextureLevels
: 0;
810 return 0; /* bad target */
816 #if 000 /* not used anymore */
818 * glTexImage[123]D can accept a NULL image pointer. In this case we
819 * create a texture image with unspecified image contents per the OpenGL
823 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
825 const GLint components
= _mesa_components_in_format(format
);
826 const GLint numPixels
= width
* height
* depth
;
827 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
831 * Let's see if anyone finds this. If glTexImage2D() is called with
832 * a NULL image pointer then load the texture image with something
833 * interesting instead of leaving it indeterminate.
836 static const char message
[8][32] = {
840 " X X XXXX XXX XXXXX ",
843 " X X XXXXX XXX X X ",
847 GLubyte
*imgPtr
= data
;
849 for (h
= 0; h
< depth
; h
++) {
850 for (i
= 0; i
< height
; i
++) {
851 GLint srcRow
= 7 - (i
% 8);
852 for (j
= 0; j
< width
; j
++) {
853 GLint srcCol
= j
% 32;
854 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
855 for (k
= 0; k
< components
; k
++) {
871 * Reset the fields of a gl_texture_image struct to zero.
873 * \param img texture image structure.
875 * This is called when a proxy texture test fails, we set all the
876 * image members (except DriverData) to zero.
877 * It's also used in glTexImage[123]D as a safeguard to be sure all
878 * required fields get initialized properly by the Driver.TexImage[123]D
882 clear_teximage_fields(struct gl_texture_image
*img
)
885 img
->_BaseFormat
= 0;
886 img
->InternalFormat
= 0;
892 if (img
->ImageOffsets
) {
893 _mesa_free(img
->ImageOffsets
);
894 img
->ImageOffsets
= NULL
;
903 img
->TexFormat
= &_mesa_null_texformat
;
904 img
->FetchTexelc
= NULL
;
905 img
->FetchTexelf
= NULL
;
906 img
->IsCompressed
= 0;
907 img
->CompressedSize
= 0;
912 * Initialize basic fields of the gl_texture_image struct.
914 * \param ctx GL context.
915 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
916 * \param img texture image structure to be initialized.
917 * \param width image width.
918 * \param height image height.
919 * \param depth image depth.
920 * \param border image border.
921 * \param internalFormat internal format.
923 * Fills in the fields of \p img with the given information.
924 * Note: width, height and depth include the border.
927 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
928 struct gl_texture_image
*img
,
929 GLsizei width
, GLsizei height
, GLsizei depth
,
930 GLint border
, GLenum internalFormat
)
939 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
940 ASSERT(img
->_BaseFormat
> 0);
941 img
->InternalFormat
= internalFormat
;
942 img
->Border
= border
;
944 img
->Height
= height
;
947 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
948 img
->WidthLog2
= logbase2(img
->Width2
);
950 if (height
== 1) { /* 1-D texture */
955 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
956 img
->HeightLog2
= logbase2(img
->Height2
);
959 if (depth
== 1) { /* 2-D texture */
964 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
965 img
->DepthLog2
= logbase2(img
->Depth2
);
968 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
970 img
->IsCompressed
= GL_FALSE
;
971 img
->CompressedSize
= 0;
973 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
974 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
975 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
976 img
->_IsPowerOfTwo
= GL_TRUE
;
978 img
->_IsPowerOfTwo
= GL_FALSE
;
980 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
981 img
->RowStride
= width
;
982 /* Allocate the ImageOffsets array and initialize to typical values.
983 * We allocate the array for 1D/2D textures too in order to avoid special-
984 * case code in the texstore routines.
986 if (img
->ImageOffsets
)
987 _mesa_free(img
->ImageOffsets
);
988 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
989 for (i
= 0; i
< depth
; i
++) {
990 img
->ImageOffsets
[i
] = i
* width
* height
;
993 /* Compute Width/Height/DepthScale for mipmap lod computation */
994 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
995 /* scale = 1.0 since texture coords directly map to texels */
996 img
->WidthScale
= 1.0;
997 img
->HeightScale
= 1.0;
998 img
->DepthScale
= 1.0;
1001 img
->WidthScale
= (GLfloat
) img
->Width
;
1002 img
->HeightScale
= (GLfloat
) img
->Height
;
1003 img
->DepthScale
= (GLfloat
) img
->Depth
;
1009 * Free and clear fields of the gl_texture_image struct.
1011 * \param ctx GL context.
1012 * \param texImage texture image structure to be cleared.
1014 * After the call, \p texImage will have no data associated with it. Its
1015 * fields are cleared so that its parent object will test incomplete.
1018 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
1020 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1021 clear_teximage_fields(texImage
);
1026 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1027 * level, width, height and depth against the ctx->Const limits for textures.
1029 * A hardware driver might override this function if, for example, the
1030 * max 3D texture size is 512x512x64 (i.e. not a cube).
1032 * Note that width, height, depth == 0 is not an error. However, a
1033 * texture with zero width/height/depth will be considered "incomplete"
1034 * and texturing will effectively be disabled.
1036 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1037 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1038 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1039 * \param level as passed to glTexImage
1040 * \param internalFormat as passed to glTexImage
1041 * \param format as passed to glTexImage
1042 * \param type as passed to glTexImage
1043 * \param width as passed to glTexImage
1044 * \param height as passed to glTexImage
1045 * \param depth as passed to glTexImage
1046 * \param border as passed to glTexImage
1047 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1050 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1051 GLint internalFormat
, GLenum format
, GLenum type
,
1052 GLint width
, GLint height
, GLint depth
, GLint border
)
1056 (void) internalFormat
;
1061 case GL_PROXY_TEXTURE_1D
:
1062 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1063 if (width
< 2 * border
|| width
> 2 + maxSize
||
1064 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1065 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1066 level
>= ctx
->Const
.MaxTextureLevels
) {
1067 /* bad width or level */
1071 case GL_PROXY_TEXTURE_2D
:
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 height
< 2 * border
|| height
> 2 + maxSize
||
1077 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1078 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1079 level
>= ctx
->Const
.MaxTextureLevels
) {
1080 /* bad width or height or level */
1084 case GL_PROXY_TEXTURE_3D
:
1085 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1086 if (width
< 2 * border
|| width
> 2 + maxSize
||
1087 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1088 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1089 height
< 2 * border
|| height
> 2 + maxSize
||
1090 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1091 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1092 depth
< 2 * border
|| depth
> 2 + maxSize
||
1093 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1094 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1095 level
>= ctx
->Const
.Max3DTextureLevels
) {
1096 /* bad width or height or depth or level */
1100 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1101 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1102 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1104 /* bad width or height or level */
1108 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1109 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1110 if (width
< 2 * border
|| width
> 2 + maxSize
||
1111 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1112 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1113 height
< 2 * border
|| height
> 2 + maxSize
||
1114 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1115 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1116 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1117 /* bad width or height */
1121 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1122 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1123 if (width
< 2 * border
|| width
> 2 + maxSize
||
1124 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1125 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1126 level
>= ctx
->Const
.MaxTextureLevels
) {
1127 /* bad width or level */
1131 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1135 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1136 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1137 if (width
< 2 * border
|| width
> 2 + maxSize
||
1138 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1139 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1140 height
< 2 * border
|| height
> 2 + maxSize
||
1141 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1142 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1143 level
>= ctx
->Const
.MaxTextureLevels
) {
1144 /* bad width or height or level */
1147 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1152 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1159 * Helper function to determine whether a target supports compressed textures
1162 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1164 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1165 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1166 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1167 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1168 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1169 || ((ctx
->Extensions
.MESA_texture_array
&&
1170 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1171 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1176 * Test the glTexImage[123]D() parameters for errors.
1178 * \param ctx GL context.
1179 * \param target texture target given by the user.
1180 * \param level image level given by the user.
1181 * \param internalFormat internal format given by the user.
1182 * \param format pixel data format given by the user.
1183 * \param type pixel data type given by the user.
1184 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1185 * \param width image width given by the user.
1186 * \param height image height given by the user.
1187 * \param depth image depth given by the user.
1188 * \param border image border given by the user.
1190 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1192 * Verifies each of the parameters against the constants specified in
1193 * __GLcontextRec::Const and the supported extensions, and according to the
1194 * OpenGL specification.
1197 texture_error_check( GLcontext
*ctx
, GLenum target
,
1198 GLint level
, GLint internalFormat
,
1199 GLenum format
, GLenum type
,
1201 GLint width
, GLint height
,
1202 GLint depth
, GLint border
)
1204 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1205 GLboolean sizeOK
= GL_TRUE
;
1206 GLboolean colorFormat
, indexFormat
;
1207 GLenum proxy_target
;
1209 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1210 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1212 _mesa_error(ctx
, GL_INVALID_VALUE
,
1213 "glTexImage%dD(level=%d)", dimensions
, level
);
1219 if (border
< 0 || border
> 1 ||
1220 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1221 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1223 _mesa_error(ctx
, GL_INVALID_VALUE
,
1224 "glTexImage%dD(border=%d)", dimensions
, border
);
1229 if (width
< 0 || height
< 0 || depth
< 0) {
1231 _mesa_error(ctx
, GL_INVALID_VALUE
,
1232 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1237 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1238 * level, width, height and depth.
1240 if (dimensions
== 1) {
1241 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1242 proxy_target
= GL_PROXY_TEXTURE_1D
;
1247 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1251 else if (dimensions
== 2) {
1253 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1254 proxy_target
= GL_PROXY_TEXTURE_2D
;
1256 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1257 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1258 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1259 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1260 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1263 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1264 sizeOK
= (width
== height
);
1266 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1267 target
== GL_TEXTURE_RECTANGLE_NV
) {
1268 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1269 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1272 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1274 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1275 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1276 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1279 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1283 else if (dimensions
== 3) {
1284 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1285 proxy_target
= GL_PROXY_TEXTURE_3D
;
1287 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1288 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1289 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1292 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1297 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1301 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1302 internalFormat
, format
,
1303 type
, width
, height
,
1307 _mesa_error(ctx
, GL_INVALID_VALUE
,
1308 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1309 dimensions
, level
, width
, height
, depth
);
1314 /* Check internalFormat */
1315 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1317 _mesa_error(ctx
, GL_INVALID_VALUE
,
1318 "glTexImage%dD(internalFormat=0x%x)",
1319 dimensions
, internalFormat
);
1324 /* Check incoming image format and type */
1325 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1326 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1327 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1330 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1331 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1332 dimensions
, format
, type
);
1337 /* make sure internal format and format basically agree */
1338 colorFormat
= _mesa_is_color_format(format
);
1339 indexFormat
= _mesa_is_index_format(format
);
1340 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1341 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1342 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1343 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1344 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1345 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1347 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1348 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1349 dimensions
, internalFormat
, format
);
1353 /* additional checks for ycbcr textures */
1354 if (internalFormat
== GL_YCBCR_MESA
) {
1355 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1356 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1357 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1359 _mesa_sprintf(message
,
1360 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1361 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1362 return GL_TRUE
; /* error */
1364 if (target
!= GL_TEXTURE_2D
&&
1365 target
!= GL_PROXY_TEXTURE_2D
&&
1366 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1367 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1369 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1375 _mesa_sprintf(message
,
1376 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1377 dimensions
, border
);
1378 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1384 /* additional checks for depth textures */
1385 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1386 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1387 if (target
!= GL_TEXTURE_1D
&&
1388 target
!= GL_PROXY_TEXTURE_1D
&&
1389 target
!= GL_TEXTURE_2D
&&
1390 target
!= GL_PROXY_TEXTURE_2D
&&
1391 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1392 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1394 _mesa_error(ctx
, GL_INVALID_ENUM
,
1395 "glTexImage(target/internalFormat)");
1400 /* additional checks for compressed textures */
1401 if (is_compressed_format(ctx
, internalFormat
)) {
1402 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1403 _mesa_error(ctx
, GL_INVALID_ENUM
,
1404 "glTexImage%d(target)", dimensions
);
1409 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1410 "glTexImage%D(border!=0)", dimensions
);
1416 /* if we get here, the parameters are OK */
1422 * Test glTexSubImage[123]D() parameters for errors.
1424 * \param ctx GL context.
1425 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1426 * \param target texture target given by the user.
1427 * \param level image level given by the user.
1428 * \param xoffset sub-image x offset given by the user.
1429 * \param yoffset sub-image y offset given by the user.
1430 * \param zoffset sub-image z offset given by the user.
1431 * \param format pixel data format given by the user.
1432 * \param type pixel data type given by the user.
1433 * \param width image width given by the user.
1434 * \param height image height given by the user.
1435 * \param depth image depth given by the user.
1437 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1439 * Verifies each of the parameters against the constants specified in
1440 * __GLcontextRec::Const and the supported extensions, and according to the
1441 * OpenGL specification.
1444 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1445 GLenum target
, GLint level
,
1446 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1447 GLint width
, GLint height
, GLint depth
,
1448 GLenum format
, GLenum type
)
1451 if (dimensions
== 1) {
1452 if (target
!= GL_TEXTURE_1D
) {
1453 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1457 else if (dimensions
== 2) {
1458 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1459 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1460 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1461 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1465 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1466 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1467 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1471 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1472 if (!ctx
->Extensions
.MESA_texture_array
) {
1473 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1477 else if (target
!= GL_TEXTURE_2D
) {
1478 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1482 else if (dimensions
== 3) {
1483 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1484 if (!ctx
->Extensions
.MESA_texture_array
) {
1485 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1489 else if (target
!= GL_TEXTURE_3D
) {
1490 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1495 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1499 /* Basic level check */
1500 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1501 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1506 _mesa_error(ctx
, GL_INVALID_VALUE
,
1507 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1510 if (height
< 0 && dimensions
> 1) {
1511 _mesa_error(ctx
, GL_INVALID_VALUE
,
1512 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1515 if (depth
< 0 && dimensions
> 2) {
1516 _mesa_error(ctx
, GL_INVALID_VALUE
,
1517 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1521 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1522 _mesa_error(ctx
, GL_INVALID_ENUM
,
1523 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1524 dimensions
, format
, type
);
1532 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1533 GLenum target
, GLint level
,
1534 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1535 GLint width
, GLint height
, GLint depth
,
1536 GLenum format
, GLenum type
,
1537 const struct gl_texture_image
*destTex
)
1540 /* undefined image level */
1541 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1545 if (xoffset
< -((GLint
)destTex
->Border
)) {
1546 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1550 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1551 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1555 if (dimensions
> 1) {
1556 if (yoffset
< -((GLint
)destTex
->Border
)) {
1557 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1561 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1562 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1567 if (dimensions
> 2) {
1568 if (zoffset
< -((GLint
)destTex
->Border
)) {
1569 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1572 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1573 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1578 #if FEATURE_EXT_texture_sRGB
1579 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1580 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1581 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1582 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1583 if ((width
& 0x3) || (height
& 0x3) ||
1584 (xoffset
& 0x3) || (yoffset
& 0x3))
1585 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1586 "glTexSubImage%dD(size or offset not multiple of 4)",
1592 if (destTex
->IsCompressed
) {
1593 if (!target_can_be_compressed(ctx
, target
)) {
1594 _mesa_error(ctx
, GL_INVALID_ENUM
,
1595 "glTexSubImage%D(target)", dimensions
);
1598 /* offset must be multiple of 4 */
1599 if ((xoffset
& 3) || (yoffset
& 3)) {
1600 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1601 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1604 /* size must be multiple of 4 or equal to whole texture size */
1605 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1606 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1607 "glTexSubImage%D(width)", dimensions
);
1610 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1611 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1612 "glTexSubImage%D(width)", dimensions
);
1622 * Test glCopyTexImage[12]D() parameters for errors.
1624 * \param ctx GL context.
1625 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1626 * \param target texture target given by the user.
1627 * \param level image level given by the user.
1628 * \param internalFormat internal format given by the user.
1629 * \param width image width given by the user.
1630 * \param height image height given by the user.
1631 * \param border texture border.
1633 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1635 * Verifies each of the parameters against the constants specified in
1636 * __GLcontextRec::Const and the supported extensions, and according to the
1637 * OpenGL specification.
1640 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1641 GLenum target
, GLint level
, GLint internalFormat
,
1642 GLint width
, GLint height
, GLint border
)
1648 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1649 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1650 _mesa_error(ctx
, GL_INVALID_VALUE
,
1651 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1655 /* Check that the source buffer is complete */
1656 if (ctx
->ReadBuffer
->Name
) {
1657 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1658 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1659 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1660 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1666 if (border
< 0 || border
> 1 ||
1667 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1668 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1672 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1674 _mesa_error(ctx
, GL_INVALID_VALUE
,
1675 "glCopyTexImage%dD(internalFormat)", dimensions
);
1679 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1680 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1681 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1685 /* NOTE: the format and type aren't really significant for
1686 * TestProxyTexImage(). Only the internalformat really matters.
1690 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1691 * level, width, height and depth.
1693 if (dimensions
== 1) {
1694 if (target
== GL_TEXTURE_1D
) {
1695 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1696 level
, internalFormat
,
1698 width
, 1, 1, border
);
1701 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1705 else if (dimensions
== 2) {
1706 if (target
== GL_TEXTURE_2D
) {
1707 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1708 level
, internalFormat
,
1710 width
, height
, 1, border
);
1712 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1713 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1714 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1715 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1718 sizeOK
= (width
== height
) &&
1719 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1720 level
, internalFormat
, format
, type
,
1721 width
, height
, 1, border
);
1723 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1724 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1725 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1728 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1729 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1730 level
, internalFormat
,
1732 width
, height
, 1, border
);
1734 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1735 if (!ctx
->Extensions
.MESA_texture_array
) {
1736 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1739 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1740 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1741 level
, internalFormat
,
1743 width
, height
, 1, border
);
1746 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1751 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1756 if (dimensions
== 1) {
1757 _mesa_error(ctx
, GL_INVALID_VALUE
,
1758 "glCopyTexImage1D(width=%d)", width
);
1761 ASSERT(dimensions
== 2);
1762 _mesa_error(ctx
, GL_INVALID_VALUE
,
1763 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1768 if (is_compressed_format(ctx
, internalFormat
)) {
1769 if (!target_can_be_compressed(ctx
, target
)) {
1770 _mesa_error(ctx
, GL_INVALID_ENUM
,
1771 "glCopyTexImage%d(target)", dimensions
);
1775 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1776 "glCopyTexImage%D(border!=0)", dimensions
);
1780 else if (_mesa_is_depth_format(internalFormat
)) {
1781 /* make sure we have depth/stencil buffers */
1782 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1783 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1784 "glCopyTexImage%D(no depth)", dimensions
);
1788 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1789 /* make sure we have depth/stencil buffers */
1790 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1791 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1792 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
1797 /* if we get here, the parameters are OK */
1803 * Test glCopyTexSubImage[12]D() parameters for errors.
1804 * Note that this is the first part of error checking.
1805 * See also copytexsubimage_error_check2() below for the second part.
1807 * \param ctx GL context.
1808 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1809 * \param target texture target given by the user.
1810 * \param level image level given by the user.
1812 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1815 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1816 GLenum target
, GLint level
)
1818 /* Check that the source buffer is complete */
1819 if (ctx
->ReadBuffer
->Name
) {
1820 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1821 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1822 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1823 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1829 if (dimensions
== 1) {
1830 if (target
!= GL_TEXTURE_1D
) {
1831 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1835 else if (dimensions
== 2) {
1836 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1837 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1838 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1839 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1843 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1844 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1845 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1849 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1850 if (!ctx
->Extensions
.MESA_texture_array
) {
1851 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1855 else if (target
!= GL_TEXTURE_2D
) {
1856 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1860 else if (dimensions
== 3) {
1861 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1862 (!ctx
->Extensions
.MESA_texture_array
))
1863 && (target
!= GL_TEXTURE_3D
)) {
1864 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1870 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1871 _mesa_error(ctx
, GL_INVALID_VALUE
,
1872 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1881 * Second part of error checking for glCopyTexSubImage[12]D().
1882 * \param xoffset sub-image x offset given by the user.
1883 * \param yoffset sub-image y offset given by the user.
1884 * \param zoffset sub-image z offset given by the user.
1885 * \param width image width given by the user.
1886 * \param height image height given by the user.
1889 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1890 GLenum target
, GLint level
,
1891 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1892 GLsizei width
, GLsizei height
,
1893 const struct gl_texture_image
*teximage
)
1895 /* check that dest tex image exists */
1897 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1898 "glCopyTexSubImage%dD(undefined texture level: %d)",
1905 _mesa_error(ctx
, GL_INVALID_VALUE
,
1906 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1909 if (dimensions
> 1 && height
< 0) {
1910 _mesa_error(ctx
, GL_INVALID_VALUE
,
1911 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1915 /* check x/y offsets */
1916 if (xoffset
< -((GLint
)teximage
->Border
)) {
1917 _mesa_error(ctx
, GL_INVALID_VALUE
,
1918 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1921 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1922 _mesa_error(ctx
, GL_INVALID_VALUE
,
1923 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1926 if (dimensions
> 1) {
1927 if (yoffset
< -((GLint
)teximage
->Border
)) {
1928 _mesa_error(ctx
, GL_INVALID_VALUE
,
1929 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1932 /* NOTE: we're adding the border here, not subtracting! */
1933 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1934 _mesa_error(ctx
, GL_INVALID_VALUE
,
1935 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1940 /* check z offset */
1941 if (dimensions
> 2) {
1942 if (zoffset
< -((GLint
)teximage
->Border
)) {
1943 _mesa_error(ctx
, GL_INVALID_VALUE
,
1944 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1947 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1948 _mesa_error(ctx
, GL_INVALID_VALUE
,
1949 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1954 if (teximage
->IsCompressed
) {
1955 if (!target_can_be_compressed(ctx
, target
)) {
1956 _mesa_error(ctx
, GL_INVALID_ENUM
,
1957 "glCopyTexSubImage%d(target)", dimensions
);
1960 /* offset must be multiple of 4 */
1961 if ((xoffset
& 3) || (yoffset
& 3)) {
1962 _mesa_error(ctx
, GL_INVALID_VALUE
,
1963 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
1966 /* size must be multiple of 4 */
1967 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1968 _mesa_error(ctx
, GL_INVALID_VALUE
,
1969 "glCopyTexSubImage%D(width)", dimensions
);
1972 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1973 _mesa_error(ctx
, GL_INVALID_VALUE
,
1974 "glCopyTexSubImage%D(height)", dimensions
);
1979 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
1980 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1984 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
1985 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1986 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
1987 dimensions
, teximage
->_BaseFormat
);
1991 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
1992 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1993 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1994 "glCopyTexSubImage%D(no depth buffer)",
1999 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2000 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2001 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2002 "glCopyTexSubImage%D(no depth/stencil buffer)",
2008 /* if we get here, the parameters are OK */
2013 /** Callback info for walking over FBO hash table */
2017 struct gl_texture_object
*texObj
;
2023 * Check render to texture callback. Called from _mesa_HashWalk().
2026 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2028 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2029 const struct cb_info
*info
= (struct cb_info
*) userData
;
2030 GLcontext
*ctx
= info
->ctx
;
2031 const struct gl_texture_object
*texObj
= info
->texObj
;
2032 const GLuint level
= info
->level
, face
= info
->face
;
2034 /* If this is a user-created FBO */
2037 /* check if any of the FBO's attachments point to 'texObj' */
2038 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2039 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2040 if (att
->Type
== GL_TEXTURE
&&
2041 att
->Texture
== texObj
&&
2042 att
->TextureLevel
== level
&&
2043 att
->CubeMapFace
== face
) {
2044 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2045 /* Tell driver about the new renderbuffer texture */
2046 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2047 /* Mark fb status as indeterminate to force re-validation */
2056 * When a texture image is specified we have to check if it's bound to
2057 * any framebuffer objects (render to texture) in order to detect changes
2058 * in size or format since that effects FBO completeness.
2059 * Any FBOs rendering into the texture must be re-validated.
2062 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2063 GLuint face
, GLuint level
)
2065 /* Only check this texture if it's been marked as RenderToTexture */
2066 if (texObj
->_RenderToTexture
) {
2067 struct cb_info info
;
2069 info
.texObj
= texObj
;
2072 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2078 * If the texture object's GenerateMipmap flag is set and we've
2079 * changed the texture base level image, regenerate the rest of the
2080 * mipmap levels now.
2083 check_gen_mipmap(GLcontext
*ctx
, GLenum target
,
2084 struct gl_texture_object
*texObj
, GLint level
)
2086 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2087 if (texObj
->GenerateMipmap
&& level
== texObj
->BaseLevel
) {
2088 ASSERT(ctx
->Driver
.GenerateMipmap
);
2089 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2094 /** Debug helper: override the user-requested internal format */
2096 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2099 if (internalFormat
== GL_RGBA16F_ARB
||
2100 internalFormat
== GL_RGBA32F_ARB
) {
2101 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2104 else if (internalFormat
== GL_RGB16F_ARB
||
2105 internalFormat
== GL_RGB32F_ARB
) {
2106 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2109 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2110 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2111 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2112 return GL_LUMINANCE_ALPHA
;
2114 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2115 internalFormat
== GL_LUMINANCE32F_ARB
) {
2116 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2117 return GL_LUMINANCE
;
2119 else if (internalFormat
== GL_ALPHA16F_ARB
||
2120 internalFormat
== GL_ALPHA32F_ARB
) {
2121 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2125 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2126 internalFormat = GL_RGBA;
2130 return internalFormat
;
2133 return internalFormat
;
2139 * Called from the API. Note that width includes the border.
2142 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2143 GLsizei width
, GLint border
, GLenum format
,
2144 GLenum type
, const GLvoid
*pixels
)
2146 GLsizei postConvWidth
= width
;
2147 GET_CURRENT_CONTEXT(ctx
);
2148 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2150 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2151 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2152 _mesa_lookup_enum_by_nr(target
), level
,
2153 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2154 _mesa_lookup_enum_by_nr(format
),
2155 _mesa_lookup_enum_by_nr(type
), pixels
);
2157 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2159 #if FEATURE_convolve
2160 if (_mesa_is_color_format(internalFormat
)) {
2161 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2165 if (target
== GL_TEXTURE_1D
) {
2166 /* non-proxy target */
2167 struct gl_texture_unit
*texUnit
;
2168 struct gl_texture_object
*texObj
;
2169 struct gl_texture_image
*texImage
;
2170 const GLuint face
= _mesa_tex_target_to_face(target
);
2172 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2173 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2174 return; /* error was recorded */
2177 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2178 _mesa_update_state(ctx
);
2180 texUnit
= _mesa_get_current_tex_unit(ctx
);
2181 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2182 _mesa_lock_texture(ctx
, texObj
);
2184 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2186 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2189 if (texImage
->Data
) {
2190 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2193 ASSERT(texImage
->Data
== NULL
);
2195 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2196 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2197 postConvWidth
, 1, 1,
2198 border
, internalFormat
);
2200 /* Give the texture to the driver. <pixels> may be null. */
2201 ASSERT(ctx
->Driver
.TexImage1D
);
2202 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2203 width
, border
, format
, type
, pixels
,
2204 &ctx
->Unpack
, texObj
, texImage
);
2206 ASSERT(texImage
->TexFormat
);
2208 check_gen_mipmap(ctx
, target
, texObj
, level
);
2210 update_fbo_texture(ctx
, texObj
, face
, level
);
2213 texObj
->_Complete
= GL_FALSE
;
2214 ctx
->NewState
|= _NEW_TEXTURE
;
2217 _mesa_unlock_texture(ctx
, texObj
);
2219 else if (target
== GL_PROXY_TEXTURE_1D
) {
2220 /* Proxy texture: check for errors and update proxy state */
2221 struct gl_texture_image
*texImage
;
2222 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2223 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2224 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2225 /* when error, clear all proxy texture image parameters */
2227 clear_teximage_fields(texImage
);
2230 /* no error, set the tex image parameters */
2232 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2233 postConvWidth
, 1, 1,
2234 border
, internalFormat
);
2235 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2236 internalFormat
, format
, type
);
2240 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2247 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2248 GLsizei width
, GLsizei height
, GLint border
,
2249 GLenum format
, GLenum type
,
2250 const GLvoid
*pixels
)
2252 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2253 GET_CURRENT_CONTEXT(ctx
);
2254 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2256 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2257 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2258 _mesa_lookup_enum_by_nr(target
), level
,
2259 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2260 border
, _mesa_lookup_enum_by_nr(format
),
2261 _mesa_lookup_enum_by_nr(type
), pixels
);
2263 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2265 #if FEATURE_convolve
2266 if (_mesa_is_color_format(internalFormat
)) {
2267 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2272 if (target
== GL_TEXTURE_2D
||
2273 (ctx
->Extensions
.ARB_texture_cube_map
&&
2274 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2275 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2276 (ctx
->Extensions
.NV_texture_rectangle
&&
2277 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2278 (ctx
->Extensions
.MESA_texture_array
&&
2279 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2280 /* non-proxy target */
2281 struct gl_texture_unit
*texUnit
;
2282 struct gl_texture_object
*texObj
;
2283 struct gl_texture_image
*texImage
;
2284 const GLuint face
= _mesa_tex_target_to_face(target
);
2286 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2287 format
, type
, 2, postConvWidth
, postConvHeight
,
2289 return; /* error was recorded */
2292 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2293 _mesa_update_state(ctx
);
2295 texUnit
= _mesa_get_current_tex_unit(ctx
);
2296 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2297 _mesa_lock_texture(ctx
, texObj
);
2299 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2301 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2304 if (texImage
->Data
) {
2305 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2308 ASSERT(texImage
->Data
== NULL
);
2309 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2310 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2311 postConvWidth
, postConvHeight
, 1,
2312 border
, internalFormat
);
2314 /* Give the texture to the driver. <pixels> may be null. */
2315 ASSERT(ctx
->Driver
.TexImage2D
);
2316 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2317 width
, height
, border
, format
, type
,
2318 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2320 ASSERT(texImage
->TexFormat
);
2322 check_gen_mipmap(ctx
, target
, texObj
, level
);
2324 update_fbo_texture(ctx
, texObj
, face
, level
);
2327 texObj
->_Complete
= GL_FALSE
;
2328 ctx
->NewState
|= _NEW_TEXTURE
;
2331 _mesa_unlock_texture(ctx
, texObj
);
2333 else if (target
== GL_PROXY_TEXTURE_2D
||
2334 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2335 ctx
->Extensions
.ARB_texture_cube_map
) ||
2336 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2337 ctx
->Extensions
.NV_texture_rectangle
) ||
2338 (ctx
->Extensions
.MESA_texture_array
&&
2339 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2340 /* Proxy texture: check for errors and update proxy state */
2341 struct gl_texture_image
*texImage
;
2342 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2343 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2344 format
, type
, 2, postConvWidth
, postConvHeight
,
2346 /* when error, clear all proxy texture image parameters */
2348 clear_teximage_fields(texImage
);
2351 /* no error, set the tex image parameters */
2352 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2353 postConvWidth
, postConvHeight
, 1,
2354 border
, internalFormat
);
2355 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2356 internalFormat
, format
, type
);
2360 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2367 * Called by the API or display list executor.
2368 * Note that width and height include the border.
2371 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2372 GLsizei width
, GLsizei height
, GLsizei depth
,
2373 GLint border
, GLenum format
, GLenum type
,
2374 const GLvoid
*pixels
)
2376 GET_CURRENT_CONTEXT(ctx
);
2377 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2379 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2380 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2381 _mesa_lookup_enum_by_nr(target
), level
,
2382 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2383 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2384 _mesa_lookup_enum_by_nr(type
), pixels
);
2386 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2388 if (target
== GL_TEXTURE_3D
||
2389 (ctx
->Extensions
.MESA_texture_array
&&
2390 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2391 /* non-proxy target */
2392 struct gl_texture_unit
*texUnit
;
2393 struct gl_texture_object
*texObj
;
2394 struct gl_texture_image
*texImage
;
2395 const GLuint face
= _mesa_tex_target_to_face(target
);
2397 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2398 format
, type
, 3, width
, height
, depth
, border
)) {
2399 return; /* error was recorded */
2402 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2403 _mesa_update_state(ctx
);
2405 texUnit
= _mesa_get_current_tex_unit(ctx
);
2406 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2407 _mesa_lock_texture(ctx
, texObj
);
2409 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2411 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2414 if (texImage
->Data
) {
2415 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2418 ASSERT(texImage
->Data
== NULL
);
2419 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2420 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2421 width
, height
, depth
,
2422 border
, internalFormat
);
2424 /* Give the texture to the driver. <pixels> may be null. */
2425 ASSERT(ctx
->Driver
.TexImage3D
);
2426 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2427 width
, height
, depth
, border
, format
, type
,
2428 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2430 ASSERT(texImage
->TexFormat
);
2432 check_gen_mipmap(ctx
, target
, texObj
, level
);
2434 update_fbo_texture(ctx
, texObj
, face
, level
);
2437 texObj
->_Complete
= GL_FALSE
;
2438 ctx
->NewState
|= _NEW_TEXTURE
;
2441 _mesa_unlock_texture(ctx
, texObj
);
2443 else if (target
== GL_PROXY_TEXTURE_3D
||
2444 (ctx
->Extensions
.MESA_texture_array
&&
2445 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2446 /* Proxy texture: check for errors and update proxy state */
2447 struct gl_texture_image
*texImage
;
2448 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2449 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2450 format
, type
, 3, width
, height
, depth
, border
)) {
2451 /* when error, clear all proxy texture image parameters */
2453 clear_teximage_fields(texImage
);
2456 /* no error, set the tex image parameters */
2457 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2458 depth
, border
, internalFormat
);
2459 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2460 internalFormat
, format
, type
);
2464 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2471 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2472 GLsizei width
, GLsizei height
, GLsizei depth
,
2473 GLint border
, GLenum format
, GLenum type
,
2474 const GLvoid
*pixels
)
2476 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2477 depth
, border
, format
, type
, pixels
);
2483 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2484 GLint xoffset
, GLsizei width
,
2485 GLenum format
, GLenum type
,
2486 const GLvoid
*pixels
)
2488 GLsizei postConvWidth
= width
;
2489 struct gl_texture_unit
*texUnit
;
2490 struct gl_texture_object
*texObj
;
2491 struct gl_texture_image
*texImage
= NULL
;
2492 GET_CURRENT_CONTEXT(ctx
);
2493 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2495 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2496 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2497 _mesa_lookup_enum_by_nr(target
), level
,
2498 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2499 _mesa_lookup_enum_by_nr(type
), pixels
);
2501 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2502 _mesa_update_state(ctx
);
2504 #if FEATURE_convolve
2505 /* XXX should test internal format */
2506 if (_mesa_is_color_format(format
)) {
2507 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2511 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2512 postConvWidth
, 1, 1, format
, type
)) {
2513 return; /* error was detected */
2517 texUnit
= _mesa_get_current_tex_unit(ctx
);
2518 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2521 _mesa_lock_texture(ctx
, texObj
);
2523 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2525 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2526 postConvWidth
, 1, 1,
2527 format
, type
, texImage
)) {
2528 /* error was recorded */
2530 else if (width
> 0) {
2531 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2532 xoffset
+= texImage
->Border
;
2534 ASSERT(ctx
->Driver
.TexSubImage1D
);
2535 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2536 format
, type
, pixels
, &ctx
->Unpack
,
2539 check_gen_mipmap(ctx
, target
, texObj
, level
);
2541 ctx
->NewState
|= _NEW_TEXTURE
;
2544 _mesa_unlock_texture(ctx
, texObj
);
2549 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2550 GLint xoffset
, GLint yoffset
,
2551 GLsizei width
, GLsizei height
,
2552 GLenum format
, GLenum type
,
2553 const GLvoid
*pixels
)
2555 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2556 struct gl_texture_unit
*texUnit
;
2557 struct gl_texture_object
*texObj
;
2558 struct gl_texture_image
*texImage
;
2559 GET_CURRENT_CONTEXT(ctx
);
2560 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2562 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2563 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2564 _mesa_lookup_enum_by_nr(target
), level
,
2565 xoffset
, yoffset
, width
, height
,
2566 _mesa_lookup_enum_by_nr(format
),
2567 _mesa_lookup_enum_by_nr(type
), pixels
);
2569 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2570 _mesa_update_state(ctx
);
2572 #if FEATURE_convolve
2573 /* XXX should test internal format */
2574 if (_mesa_is_color_format(format
)) {
2575 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2580 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2581 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2582 return; /* error was detected */
2585 texUnit
= _mesa_get_current_tex_unit(ctx
);
2586 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2588 _mesa_lock_texture(ctx
, texObj
);
2590 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2592 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2593 postConvWidth
, postConvHeight
, 1,
2594 format
, type
, texImage
)) {
2595 /* error was recorded */
2597 else if (width
> 0 && height
>= 0) {
2598 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2599 xoffset
+= texImage
->Border
;
2600 yoffset
+= texImage
->Border
;
2602 ASSERT(ctx
->Driver
.TexSubImage2D
);
2603 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2604 width
, height
, format
, type
, pixels
,
2605 &ctx
->Unpack
, texObj
, texImage
);
2607 check_gen_mipmap(ctx
, target
, texObj
, level
);
2609 ctx
->NewState
|= _NEW_TEXTURE
;
2612 _mesa_unlock_texture(ctx
, texObj
);
2618 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2619 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2620 GLsizei width
, GLsizei height
, GLsizei depth
,
2621 GLenum format
, GLenum type
,
2622 const GLvoid
*pixels
)
2624 struct gl_texture_unit
*texUnit
;
2625 struct gl_texture_object
*texObj
;
2626 struct gl_texture_image
*texImage
;
2627 GET_CURRENT_CONTEXT(ctx
);
2628 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2630 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2631 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2632 _mesa_lookup_enum_by_nr(target
), level
,
2633 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2634 _mesa_lookup_enum_by_nr(format
),
2635 _mesa_lookup_enum_by_nr(type
), pixels
);
2637 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2638 _mesa_update_state(ctx
);
2640 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2641 width
, height
, depth
, format
, type
)) {
2642 return; /* error was detected */
2645 texUnit
= _mesa_get_current_tex_unit(ctx
);
2646 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2648 _mesa_lock_texture(ctx
, texObj
);
2650 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2652 if (subtexture_error_check2(ctx
, 3, target
, level
,
2653 xoffset
, yoffset
, zoffset
,
2654 width
, height
, depth
,
2655 format
, type
, texImage
)) {
2656 /* error was recorded */
2658 else if (width
> 0 && height
> 0 && height
> 0) {
2659 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2660 xoffset
+= texImage
->Border
;
2661 yoffset
+= texImage
->Border
;
2662 zoffset
+= texImage
->Border
;
2664 ASSERT(ctx
->Driver
.TexSubImage3D
);
2665 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2666 xoffset
, yoffset
, zoffset
,
2667 width
, height
, depth
,
2668 format
, type
, pixels
,
2669 &ctx
->Unpack
, texObj
, texImage
);
2671 check_gen_mipmap(ctx
, target
, texObj
, level
);
2673 ctx
->NewState
|= _NEW_TEXTURE
;
2676 _mesa_unlock_texture(ctx
, texObj
);
2682 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2683 GLenum internalFormat
,
2685 GLsizei width
, GLint border
)
2687 struct gl_texture_unit
*texUnit
;
2688 struct gl_texture_object
*texObj
;
2689 struct gl_texture_image
*texImage
;
2690 GLsizei postConvWidth
= width
;
2691 const GLuint face
= _mesa_tex_target_to_face(target
);
2692 GET_CURRENT_CONTEXT(ctx
);
2693 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2695 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2696 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2697 _mesa_lookup_enum_by_nr(target
), level
,
2698 _mesa_lookup_enum_by_nr(internalFormat
),
2699 x
, y
, width
, border
);
2701 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2702 _mesa_update_state(ctx
);
2704 #if FEATURE_convolve
2705 if (_mesa_is_color_format(internalFormat
)) {
2706 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2710 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2711 postConvWidth
, 1, border
))
2714 texUnit
= _mesa_get_current_tex_unit(ctx
);
2715 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2717 _mesa_lock_texture(ctx
, texObj
);
2719 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2721 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2724 if (texImage
->Data
) {
2725 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2728 ASSERT(texImage
->Data
== NULL
);
2730 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2731 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2732 border
, internalFormat
);
2734 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2735 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2736 x
, y
, width
, border
);
2738 ASSERT(texImage
->TexFormat
);
2740 check_gen_mipmap(ctx
, target
, texObj
, level
);
2742 update_fbo_texture(ctx
, texObj
, face
, level
);
2745 texObj
->_Complete
= GL_FALSE
;
2746 ctx
->NewState
|= _NEW_TEXTURE
;
2749 _mesa_unlock_texture(ctx
, texObj
);
2755 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2756 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2759 struct gl_texture_unit
*texUnit
;
2760 struct gl_texture_object
*texObj
;
2761 struct gl_texture_image
*texImage
;
2762 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2763 const GLuint face
= _mesa_tex_target_to_face(target
);
2764 GET_CURRENT_CONTEXT(ctx
);
2765 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2767 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2768 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2769 _mesa_lookup_enum_by_nr(target
), level
,
2770 _mesa_lookup_enum_by_nr(internalFormat
),
2771 x
, y
, width
, height
, border
);
2773 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2774 _mesa_update_state(ctx
);
2776 #if FEATURE_convolve
2777 if (_mesa_is_color_format(internalFormat
)) {
2778 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2783 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2784 postConvWidth
, postConvHeight
, border
))
2787 texUnit
= _mesa_get_current_tex_unit(ctx
);
2788 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2790 _mesa_lock_texture(ctx
, texObj
);
2792 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2795 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2798 if (texImage
->Data
) {
2799 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2802 ASSERT(texImage
->Data
== NULL
);
2804 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2805 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2806 postConvWidth
, postConvHeight
, 1,
2807 border
, internalFormat
);
2809 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2810 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2811 x
, y
, width
, height
, border
);
2813 ASSERT(texImage
->TexFormat
);
2815 check_gen_mipmap(ctx
, target
, texObj
, level
);
2817 update_fbo_texture(ctx
, texObj
, face
, level
);
2820 texObj
->_Complete
= GL_FALSE
;
2821 ctx
->NewState
|= _NEW_TEXTURE
;
2824 _mesa_unlock_texture(ctx
, texObj
);
2829 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2830 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2832 struct gl_texture_unit
*texUnit
;
2833 struct gl_texture_object
*texObj
;
2834 struct gl_texture_image
*texImage
;
2835 GLsizei postConvWidth
= width
;
2839 GET_CURRENT_CONTEXT(ctx
);
2840 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2842 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2843 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2844 _mesa_lookup_enum_by_nr(target
),
2845 level
, xoffset
, x
, y
, width
);
2847 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2848 _mesa_update_state(ctx
);
2850 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2853 texUnit
= _mesa_get_current_tex_unit(ctx
);
2854 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2856 _mesa_lock_texture(ctx
, texObj
);
2858 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2860 #if FEATURE_convolve
2861 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2862 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2866 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2867 xoffset
, 0, 0, postConvWidth
, 1,
2869 /* error was recorded */
2872 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2873 xoffset
+= texImage
->Border
;
2875 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2877 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2878 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2879 xoffset
, x
, y
, width
);
2881 check_gen_mipmap(ctx
, target
, texObj
, level
);
2883 ctx
->NewState
|= _NEW_TEXTURE
;
2887 _mesa_unlock_texture(ctx
, texObj
);
2893 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2894 GLint xoffset
, GLint yoffset
,
2895 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2897 struct gl_texture_unit
*texUnit
;
2898 struct gl_texture_object
*texObj
;
2899 struct gl_texture_image
*texImage
;
2900 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2901 GET_CURRENT_CONTEXT(ctx
);
2902 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2904 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2905 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2906 _mesa_lookup_enum_by_nr(target
),
2907 level
, xoffset
, yoffset
, x
, y
, width
, height
);
2909 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2910 _mesa_update_state(ctx
);
2912 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2915 texUnit
= _mesa_get_current_tex_unit(ctx
);
2916 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2918 _mesa_lock_texture(ctx
, texObj
);
2920 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2922 #if FEATURE_convolve
2923 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2924 _mesa_adjust_image_for_convolution(ctx
, 2,
2925 &postConvWidth
, &postConvHeight
);
2929 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
2930 xoffset
, yoffset
, 0,
2931 postConvWidth
, postConvHeight
,
2933 /* error was recorded */
2936 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2937 xoffset
+= texImage
->Border
;
2938 yoffset
+= texImage
->Border
;
2940 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2942 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2943 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2944 x
, y
, width
, height
);
2946 check_gen_mipmap(ctx
, target
, texObj
, level
);
2948 ctx
->NewState
|= _NEW_TEXTURE
;
2952 _mesa_unlock_texture(ctx
, texObj
);
2958 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2959 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2960 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2962 struct gl_texture_unit
*texUnit
;
2963 struct gl_texture_object
*texObj
;
2964 struct gl_texture_image
*texImage
;
2965 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2966 GET_CURRENT_CONTEXT(ctx
);
2967 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2969 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2970 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
2971 _mesa_lookup_enum_by_nr(target
),
2972 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2974 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2975 _mesa_update_state(ctx
);
2977 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2980 texUnit
= _mesa_get_current_tex_unit(ctx
);
2981 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2983 _mesa_lock_texture(ctx
, texObj
);
2985 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2987 #if FEATURE_convolve
2988 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2989 _mesa_adjust_image_for_convolution(ctx
, 2,
2990 &postConvWidth
, &postConvHeight
);
2994 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2995 zoffset
, postConvWidth
, postConvHeight
,
2997 /* error was recored */
3000 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3001 xoffset
+= texImage
->Border
;
3002 yoffset
+= texImage
->Border
;
3003 zoffset
+= texImage
->Border
;
3005 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3007 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3008 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3009 xoffset
, yoffset
, zoffset
,
3010 x
, y
, width
, height
);
3012 check_gen_mipmap(ctx
, target
, texObj
, level
);
3014 ctx
->NewState
|= _NEW_TEXTURE
;
3018 _mesa_unlock_texture(ctx
, texObj
);
3024 /**********************************************************************/
3025 /****** Compressed Textures ******/
3026 /**********************************************************************/
3030 * Error checking for glCompressedTexImage[123]D().
3031 * \return error code or GL_NO_ERROR.
3034 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3035 GLenum target
, GLint level
,
3036 GLenum internalFormat
, GLsizei width
,
3037 GLsizei height
, GLsizei depth
, GLint border
,
3040 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3042 if (dimensions
== 1) {
3043 /* 1D compressed textures not allowed */
3044 return GL_INVALID_ENUM
;
3046 else if (dimensions
== 2) {
3047 if (target
== GL_PROXY_TEXTURE_2D
) {
3048 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3050 else if (target
== GL_TEXTURE_2D
) {
3051 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3053 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3054 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3055 return GL_INVALID_ENUM
; /*target*/
3056 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3058 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3059 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3060 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3061 return GL_INVALID_ENUM
; /*target*/
3062 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3065 return GL_INVALID_ENUM
; /*target*/
3068 else if (dimensions
== 3) {
3069 /* 3D compressed textures not allowed */
3070 return GL_INVALID_ENUM
;
3073 maxTextureSize
= 1 << (maxLevels
- 1);
3075 /* This will detect any invalid internalFormat value */
3076 if (!is_compressed_format(ctx
, internalFormat
))
3077 return GL_INVALID_ENUM
;
3079 /* This should really never fail */
3080 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3081 return GL_INVALID_ENUM
;
3084 return GL_INVALID_VALUE
;
3087 * XXX We should probably use the proxy texture error check function here.
3089 if (width
< 1 || width
> maxTextureSize
||
3090 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3091 return GL_INVALID_VALUE
;
3093 if ((height
< 1 || height
> maxTextureSize
||
3094 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3096 return GL_INVALID_VALUE
;
3098 if ((depth
< 1 || depth
> maxTextureSize
||
3099 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3101 return GL_INVALID_VALUE
;
3103 /* For cube map, width must equal height */
3104 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3105 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3106 return GL_INVALID_VALUE
;
3108 if (level
< 0 || level
>= maxLevels
)
3109 return GL_INVALID_VALUE
;
3111 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3112 depth
, internalFormat
);
3113 if (expectedSize
!= imageSize
)
3114 return GL_INVALID_VALUE
;
3116 #if FEATURE_EXT_texture_sRGB
3117 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3118 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3119 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3120 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3122 return GL_INVALID_OPERATION
;
3131 * Error checking for glCompressedTexSubImage[123]D().
3132 * \warning There are some bad assumptions here about the size of compressed
3133 * texture tiles (multiple of 4) used to test the validity of the
3134 * offset and size parameters.
3135 * \return error code or GL_NO_ERROR.
3138 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3139 GLenum target
, GLint level
,
3140 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3141 GLsizei width
, GLsizei height
, GLsizei depth
,
3142 GLenum format
, GLsizei imageSize
)
3144 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3147 if (dimensions
== 1) {
3148 /* 1D compressed textures not allowed */
3149 return GL_INVALID_ENUM
;
3151 else if (dimensions
== 2) {
3152 if (target
== GL_PROXY_TEXTURE_2D
) {
3153 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3155 else if (target
== GL_TEXTURE_2D
) {
3156 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3158 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3159 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3160 return GL_INVALID_ENUM
; /*target*/
3161 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3163 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3164 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3165 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3166 return GL_INVALID_ENUM
; /*target*/
3167 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3170 return GL_INVALID_ENUM
; /*target*/
3173 else if (dimensions
== 3) {
3174 /* 3D compressed textures not allowed */
3175 return GL_INVALID_ENUM
;
3178 maxTextureSize
= 1 << (maxLevels
- 1);
3180 /* this will catch any invalid compressed format token */
3181 if (!is_compressed_format(ctx
, format
))
3182 return GL_INVALID_ENUM
;
3184 if (width
< 1 || width
> maxTextureSize
)
3185 return GL_INVALID_VALUE
;
3187 if ((height
< 1 || height
> maxTextureSize
)
3189 return GL_INVALID_VALUE
;
3191 if (level
< 0 || level
>= maxLevels
)
3192 return GL_INVALID_VALUE
;
3194 /* XXX these tests are specific to the compressed format.
3195 * this code should be generalized in some way.
3197 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3198 return GL_INVALID_VALUE
;
3200 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3201 return GL_INVALID_VALUE
;
3203 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3204 return GL_INVALID_VALUE
;
3206 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3208 if (expectedSize
!= imageSize
)
3209 return GL_INVALID_VALUE
;
3217 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3218 GLenum internalFormat
, GLsizei width
,
3219 GLint border
, GLsizei imageSize
,
3222 GET_CURRENT_CONTEXT(ctx
);
3223 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3225 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3226 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3227 _mesa_lookup_enum_by_nr(target
), level
,
3228 _mesa_lookup_enum_by_nr(internalFormat
),
3229 width
, border
, imageSize
, data
);
3231 if (target
== GL_TEXTURE_1D
) {
3232 /* non-proxy target */
3233 struct gl_texture_unit
*texUnit
;
3234 struct gl_texture_object
*texObj
;
3235 struct gl_texture_image
*texImage
;
3236 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3237 internalFormat
, width
, 1, 1, border
, imageSize
);
3239 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3243 texUnit
= _mesa_get_current_tex_unit(ctx
);
3244 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3246 _mesa_lock_texture(ctx
, texObj
);
3248 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3250 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3253 if (texImage
->Data
) {
3254 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3256 ASSERT(texImage
->Data
== NULL
);
3258 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3259 border
, internalFormat
);
3261 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3262 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3263 internalFormat
, width
, border
,
3267 check_gen_mipmap(ctx
, target
, texObj
, level
);
3270 texObj
->_Complete
= GL_FALSE
;
3271 ctx
->NewState
|= _NEW_TEXTURE
;
3274 _mesa_unlock_texture(ctx
, texObj
);
3276 else if (target
== GL_PROXY_TEXTURE_1D
) {
3277 /* Proxy texture: check for errors and update proxy state */
3278 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3279 internalFormat
, width
, 1, 1, border
, imageSize
);
3281 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3282 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3283 internalFormat
, GL_NONE
, GL_NONE
,
3284 width
, 1, 1, border
);
3287 /* if error, clear all proxy texture image parameters */
3288 struct gl_texture_image
*texImage
;
3289 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3291 clear_teximage_fields(texImage
);
3294 /* store the teximage parameters */
3295 struct gl_texture_unit
*texUnit
;
3296 struct gl_texture_object
*texObj
;
3297 struct gl_texture_image
*texImage
;
3298 texUnit
= _mesa_get_current_tex_unit(ctx
);
3299 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3301 _mesa_lock_texture(ctx
, texObj
);
3303 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3304 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3305 border
, internalFormat
);
3307 _mesa_unlock_texture(ctx
, texObj
);
3311 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3318 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3319 GLenum internalFormat
, GLsizei width
,
3320 GLsizei height
, 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
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3328 _mesa_lookup_enum_by_nr(target
), level
,
3329 _mesa_lookup_enum_by_nr(internalFormat
),
3330 width
, height
, border
, imageSize
, data
);
3332 if (target
== GL_TEXTURE_2D
||
3333 (ctx
->Extensions
.ARB_texture_cube_map
&&
3334 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3335 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3336 /* non-proxy target */
3337 struct gl_texture_unit
*texUnit
;
3338 struct gl_texture_object
*texObj
;
3339 struct gl_texture_image
*texImage
;
3340 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3341 internalFormat
, width
, height
, 1, border
, imageSize
);
3343 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3347 texUnit
= _mesa_get_current_tex_unit(ctx
);
3348 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3350 _mesa_lock_texture(ctx
, texObj
);
3352 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3354 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3357 if (texImage
->Data
) {
3358 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3360 ASSERT(texImage
->Data
== NULL
);
3362 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3363 border
, internalFormat
);
3365 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3366 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3367 internalFormat
, width
, height
,
3368 border
, imageSize
, data
,
3371 check_gen_mipmap(ctx
, target
, texObj
, level
);
3374 texObj
->_Complete
= GL_FALSE
;
3375 ctx
->NewState
|= _NEW_TEXTURE
;
3378 _mesa_unlock_texture(ctx
, texObj
);
3380 else if (target
== GL_PROXY_TEXTURE_2D
||
3381 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3382 ctx
->Extensions
.ARB_texture_cube_map
)) {
3383 /* Proxy texture: check for errors and update proxy state */
3384 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3385 internalFormat
, width
, height
, 1, border
, imageSize
);
3387 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3388 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3389 internalFormat
, GL_NONE
, GL_NONE
,
3390 width
, height
, 1, border
);
3393 /* if error, clear all proxy texture image parameters */
3394 struct gl_texture_image
*texImage
;
3395 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3397 clear_teximage_fields(texImage
);
3400 /* store the teximage parameters */
3401 struct gl_texture_unit
*texUnit
;
3402 struct gl_texture_object
*texObj
;
3403 struct gl_texture_image
*texImage
;
3404 texUnit
= _mesa_get_current_tex_unit(ctx
);
3405 texObj
= _mesa_select_tex_object(ctx
, texUnit
, 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
, height
, 1,
3411 border
, internalFormat
);
3413 _mesa_unlock_texture(ctx
, texObj
);
3417 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3424 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3425 GLenum internalFormat
, GLsizei width
,
3426 GLsizei height
, GLsizei depth
, GLint border
,
3427 GLsizei imageSize
, const GLvoid
*data
)
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
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3434 _mesa_lookup_enum_by_nr(target
), level
,
3435 _mesa_lookup_enum_by_nr(internalFormat
),
3436 width
, height
, depth
, border
, imageSize
, data
);
3438 if (target
== GL_TEXTURE_3D
) {
3439 /* non-proxy target */
3440 struct gl_texture_unit
*texUnit
;
3441 struct gl_texture_object
*texObj
;
3442 struct gl_texture_image
*texImage
;
3443 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3444 internalFormat
, width
, height
, depth
, border
, imageSize
);
3446 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3450 texUnit
= _mesa_get_current_tex_unit(ctx
);
3451 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3452 _mesa_lock_texture(ctx
, texObj
);
3454 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3456 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3459 if (texImage
->Data
) {
3460 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3462 ASSERT(texImage
->Data
== NULL
);
3464 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3465 width
, height
, depth
,
3466 border
, internalFormat
);
3468 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3469 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3471 width
, height
, depth
,
3472 border
, imageSize
, data
,
3475 check_gen_mipmap(ctx
, target
, texObj
, level
);
3478 texObj
->_Complete
= GL_FALSE
;
3479 ctx
->NewState
|= _NEW_TEXTURE
;
3482 _mesa_unlock_texture(ctx
, texObj
);
3484 else if (target
== GL_PROXY_TEXTURE_3D
) {
3485 /* Proxy texture: check for errors and update proxy state */
3486 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3487 internalFormat
, width
, height
, depth
, border
, imageSize
);
3489 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3490 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3491 internalFormat
, GL_NONE
, GL_NONE
,
3492 width
, height
, depth
, border
);
3495 /* if error, clear all proxy texture image parameters */
3496 struct gl_texture_image
*texImage
;
3497 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3499 clear_teximage_fields(texImage
);
3502 /* store the teximage parameters */
3503 struct gl_texture_unit
*texUnit
;
3504 struct gl_texture_object
*texObj
;
3505 struct gl_texture_image
*texImage
;
3506 texUnit
= _mesa_get_current_tex_unit(ctx
);
3507 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3508 _mesa_lock_texture(ctx
, texObj
);
3510 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3511 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3512 depth
, border
, internalFormat
);
3514 _mesa_unlock_texture(ctx
, texObj
);
3518 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3525 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3526 GLsizei width
, GLenum format
,
3527 GLsizei imageSize
, const GLvoid
*data
)
3529 struct gl_texture_unit
*texUnit
;
3530 struct gl_texture_object
*texObj
;
3531 struct gl_texture_image
*texImage
;
3533 GET_CURRENT_CONTEXT(ctx
);
3534 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3536 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3537 xoffset
, 0, 0, /* pos */
3538 width
, 1, 1, /* size */
3541 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3545 texUnit
= _mesa_get_current_tex_unit(ctx
);
3546 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3548 _mesa_lock_texture(ctx
, texObj
);
3550 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3553 if ((GLint
) format
!= texImage
->InternalFormat
) {
3554 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3555 "glCompressedTexSubImage1D(format)");
3557 else if ((width
== 1 || width
== 2) &&
3558 (GLuint
) width
!= texImage
->Width
) {
3559 _mesa_error(ctx
, GL_INVALID_VALUE
,
3560 "glCompressedTexSubImage1D(width)");
3562 else if (width
> 0) {
3563 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3564 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3566 format
, imageSize
, data
,
3570 check_gen_mipmap(ctx
, target
, texObj
, level
);
3572 ctx
->NewState
|= _NEW_TEXTURE
;
3575 _mesa_unlock_texture(ctx
, texObj
);
3580 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3581 GLint yoffset
, GLsizei width
, GLsizei height
,
3582 GLenum format
, GLsizei imageSize
,
3585 struct gl_texture_unit
*texUnit
;
3586 struct gl_texture_object
*texObj
;
3587 struct gl_texture_image
*texImage
;
3589 GET_CURRENT_CONTEXT(ctx
);
3590 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3592 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3593 xoffset
, yoffset
, 0, /* pos */
3594 width
, height
, 1, /* size */
3597 /* XXX proxy target? */
3598 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3602 texUnit
= _mesa_get_current_tex_unit(ctx
);
3603 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3605 _mesa_lock_texture(ctx
, texObj
);
3607 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3610 if ((GLint
) format
!= texImage
->InternalFormat
) {
3611 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3612 "glCompressedTexSubImage2D(format)");
3614 else if (((width
== 1 || width
== 2)
3615 && (GLuint
) width
!= texImage
->Width
) ||
3616 ((height
== 1 || height
== 2)
3617 && (GLuint
) height
!= texImage
->Height
)) {
3618 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3620 else if (width
> 0 && height
> 0) {
3621 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3622 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3623 xoffset
, yoffset
, width
, height
,
3624 format
, imageSize
, data
,
3628 check_gen_mipmap(ctx
, target
, texObj
, level
);
3630 ctx
->NewState
|= _NEW_TEXTURE
;
3633 _mesa_unlock_texture(ctx
, texObj
);
3638 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3639 GLint yoffset
, GLint zoffset
, GLsizei width
,
3640 GLsizei height
, GLsizei depth
, GLenum format
,
3641 GLsizei imageSize
, const GLvoid
*data
)
3643 struct gl_texture_unit
*texUnit
;
3644 struct gl_texture_object
*texObj
;
3645 struct gl_texture_image
*texImage
;
3647 GET_CURRENT_CONTEXT(ctx
);
3648 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3650 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3651 xoffset
, yoffset
, zoffset
,/*pos*/
3652 width
, height
, depth
, /*size*/
3655 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3659 texUnit
= _mesa_get_current_tex_unit(ctx
);
3660 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3662 _mesa_lock_texture(ctx
, texObj
);
3664 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3667 if ((GLint
) format
!= texImage
->InternalFormat
) {
3668 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3669 "glCompressedTexSubImage3D(format)");
3671 else if (((width
== 1 || width
== 2)
3672 && (GLuint
) width
!= texImage
->Width
) ||
3673 ((height
== 1 || height
== 2)
3674 && (GLuint
) height
!= texImage
->Height
) ||
3675 ((depth
== 1 || depth
== 2)
3676 && (GLuint
) depth
!= texImage
->Depth
)) {
3677 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3679 else if (width
> 0 && height
> 0 && depth
> 0) {
3680 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3681 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3682 xoffset
, yoffset
, zoffset
,
3683 width
, height
, depth
,
3684 format
, imageSize
, data
,
3688 check_gen_mipmap(ctx
, target
, texObj
, level
);
3690 ctx
->NewState
|= _NEW_TEXTURE
;
3693 _mesa_unlock_texture(ctx
, texObj
);