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"
41 #include "framebuffer.h"
47 #include "texcompress.h"
48 #include "texformat.h"
56 * State changes which we care about for glCopyTex[Sub]Image() calls.
57 * In particular, we care about pixel transfer state and buffer state
58 * (such as glReadBuffer to make sure we read from the right renderbuffer).
60 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
67 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
71 _mesa_alloc_texmemory(GLsizei bytes
)
73 return _mesa_align_malloc(bytes
, 512);
78 * Free texture memory allocated with _mesa_alloc_texmemory()
81 _mesa_free_texmemory(void *m
)
90 static void PrintTexture(GLcontext
*ctx
, const struct gl_texture_image
*img
)
92 #if CHAN_TYPE != GL_UNSIGNED_BYTE
93 _mesa_problem(NULL
, "PrintTexture not supported");
96 const GLubyte
*data
= (const GLubyte
*) img
->Data
;
99 _mesa_printf("No texture data\n");
103 switch (img
->Format
) {
110 case GL_LUMINANCE_ALPHA
:
120 _mesa_problem(NULL
, "error in PrintTexture\n");
124 for (i
= 0; i
< img
->Height
; i
++) {
125 for (j
= 0; j
< img
->Width
; j
++) {
127 _mesa_printf("%02x ", data
[0]);
129 _mesa_printf("%02x%02x ", data
[0], data
[1]);
131 _mesa_printf("%02x%02x%02x ", data
[0], data
[1], data
[2]);
133 _mesa_printf("%02x%02x%02x%02x ", data
[0], data
[1], data
[2], data
[3]);
134 data
+= (img
->RowStride
- img
->Width
) * c
;
136 /* XXX use img->ImageStride here */
145 * Compute floor(log_base_2(n)).
146 * If n < 0 return -1.
175 * Return the simple base format for a given internal texture format.
176 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
178 * \param ctx GL context.
179 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
181 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
182 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
184 * This is the format which is used during texture application (i.e. the
185 * texture format and env mode determine the arithmetic used.
187 * XXX this could be static
190 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
192 switch (internalFormat
) {
207 case GL_LUMINANCE_ALPHA
:
208 case GL_LUMINANCE4_ALPHA4
:
209 case GL_LUMINANCE6_ALPHA2
:
210 case GL_LUMINANCE8_ALPHA8
:
211 case GL_LUMINANCE12_ALPHA4
:
212 case GL_LUMINANCE12_ALPHA12
:
213 case GL_LUMINANCE16_ALPHA16
:
214 return GL_LUMINANCE_ALPHA
;
245 if (ctx
->Extensions
.EXT_paletted_texture
) {
246 switch (internalFormat
) {
248 case GL_COLOR_INDEX1_EXT
:
249 case GL_COLOR_INDEX2_EXT
:
250 case GL_COLOR_INDEX4_EXT
:
251 case GL_COLOR_INDEX8_EXT
:
252 case GL_COLOR_INDEX12_EXT
:
253 case GL_COLOR_INDEX16_EXT
:
254 return GL_COLOR_INDEX
;
260 if (ctx
->Extensions
.ARB_depth_texture
) {
261 switch (internalFormat
) {
262 case GL_DEPTH_COMPONENT
:
263 case GL_DEPTH_COMPONENT16
:
264 case GL_DEPTH_COMPONENT24
:
265 case GL_DEPTH_COMPONENT32
:
266 return GL_DEPTH_COMPONENT
;
272 switch (internalFormat
) {
273 case GL_COMPRESSED_ALPHA
:
275 case GL_COMPRESSED_LUMINANCE
:
277 case GL_COMPRESSED_LUMINANCE_ALPHA
:
278 return GL_LUMINANCE_ALPHA
;
279 case GL_COMPRESSED_INTENSITY
:
281 case GL_COMPRESSED_RGB
:
283 case GL_COMPRESSED_RGBA
:
289 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
290 switch (internalFormat
) {
291 case GL_COMPRESSED_RGB_FXT1_3DFX
:
293 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
300 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
301 switch (internalFormat
) {
302 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
304 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
305 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
306 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
313 if (ctx
->Extensions
.S3_s3tc
) {
314 switch (internalFormat
) {
326 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
327 if (internalFormat
== GL_YCBCR_MESA
)
328 return GL_YCBCR_MESA
;
331 if (ctx
->Extensions
.ARB_texture_float
) {
332 switch (internalFormat
) {
333 case GL_ALPHA16F_ARB
:
334 case GL_ALPHA32F_ARB
:
342 case GL_INTENSITY16F_ARB
:
343 case GL_INTENSITY32F_ARB
:
345 case GL_LUMINANCE16F_ARB
:
346 case GL_LUMINANCE32F_ARB
:
348 case GL_LUMINANCE_ALPHA16F_ARB
:
349 case GL_LUMINANCE_ALPHA32F_ARB
:
350 return GL_LUMINANCE_ALPHA
;
356 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
357 switch (internalFormat
) {
366 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
367 switch (internalFormat
) {
376 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
377 switch (internalFormat
) {
378 case GL_DEPTH_STENCIL_EXT
:
379 case GL_DEPTH24_STENCIL8_EXT
:
380 return GL_DEPTH_STENCIL_EXT
;
386 #if FEATURE_EXT_texture_sRGB
387 if (ctx
->Extensions
.EXT_texture_sRGB
) {
388 switch (internalFormat
) {
391 case GL_COMPRESSED_SRGB_EXT
:
392 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
394 case GL_SRGB_ALPHA_EXT
:
395 case GL_SRGB8_ALPHA8_EXT
:
396 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
397 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
398 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
399 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
401 case GL_SLUMINANCE_ALPHA_EXT
:
402 case GL_SLUMINANCE8_ALPHA8_EXT
:
403 case GL_COMPRESSED_SLUMINANCE_EXT
:
404 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
405 return GL_LUMINANCE_ALPHA
;
406 case GL_SLUMINANCE_EXT
:
407 case GL_SLUMINANCE8_EXT
:
414 #endif /* FEATURE_EXT_texture_sRGB */
416 return -1; /* error */
421 * Test if it is a supported compressed format.
423 * \param internalFormat the internal format token provided by the user.
425 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
426 * GL_FALSE otherwise.
428 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
432 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
434 GLint supported
[100]; /* 100 should be plenty */
437 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
439 for (i
= 0; i
< n
; i
++) {
440 if ((GLint
) internalFormat
== supported
[i
]) {
449 * For cube map faces, return a face index in [0,5].
450 * For other targets return 0;
453 _mesa_tex_target_to_face(GLenum target
)
455 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
456 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
457 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
465 * Store a gl_texture_image pointer in a gl_texture_object structure
466 * according to the target and level parameters.
468 * \param tObj texture object.
469 * \param target texture target.
470 * \param level image level.
471 * \param texImage texture image.
473 * This was basically prompted by the introduction of cube maps.
476 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
477 GLenum target
, GLint level
,
478 struct gl_texture_image
*texImage
)
480 const GLuint face
= _mesa_tex_target_to_face(target
);
484 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
486 tObj
->Image
[face
][level
] = texImage
;
488 /* Set the 'back' pointer */
489 texImage
->TexObject
= tObj
;
494 * Allocate a texture image structure.
496 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
499 * \return a pointer to gl_texture_image struct with all fields initialized to
502 struct gl_texture_image
*
503 _mesa_new_texture_image( GLcontext
*ctx
)
506 return CALLOC_STRUCT(gl_texture_image
);
511 * Free texture image data.
512 * This function is a fallback called via ctx->Driver.FreeTexImageData().
514 * \param texImage texture image.
516 * Free the texture image data if it's not marked as client data.
519 _mesa_free_texture_image_data(GLcontext
*ctx
,
520 struct gl_texture_image
*texImage
)
524 if (texImage
->Data
&& !texImage
->IsClientData
) {
525 /* free the old texture data */
526 _mesa_free_texmemory(texImage
->Data
);
529 texImage
->Data
= NULL
;
534 * Free texture image.
536 * \param texImage texture image.
538 * Free the texture image structure and the associated image data.
541 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
543 /* Free texImage->Data and/or any other driver-specific texture
546 ASSERT(ctx
->Driver
.FreeTexImageData
);
547 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
549 ASSERT(texImage
->Data
== NULL
);
550 if (texImage
->ImageOffsets
)
551 _mesa_free(texImage
->ImageOffsets
);
552 _mesa_free(texImage
);
557 * Test if a target is a proxy target.
559 * \param target texture target.
561 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
564 _mesa_is_proxy_texture(GLenum target
)
566 /* NUM_TEXTURE_TARGETS should match number of terms below */
567 assert(NUM_TEXTURE_TARGETS
== 7);
569 return (target
== GL_PROXY_TEXTURE_1D
||
570 target
== GL_PROXY_TEXTURE_2D
||
571 target
== GL_PROXY_TEXTURE_3D
||
572 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
573 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
574 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
575 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
580 * Get the texture object that corresponds to the target of the given texture unit.
582 * \param ctx GL context.
583 * \param texUnit texture unit.
584 * \param target texture target.
586 * \return pointer to the texture object on success, or NULL on failure.
588 * \sa gl_texture_unit.
590 struct gl_texture_object
*
591 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
596 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
597 case GL_PROXY_TEXTURE_1D
:
598 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
600 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
601 case GL_PROXY_TEXTURE_2D
:
602 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
604 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
605 case GL_PROXY_TEXTURE_3D
:
606 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
607 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
608 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
609 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
610 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
611 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
612 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
613 case GL_TEXTURE_CUBE_MAP_ARB
:
614 return ctx
->Extensions
.ARB_texture_cube_map
615 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
616 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
617 return ctx
->Extensions
.ARB_texture_cube_map
618 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
619 case GL_TEXTURE_RECTANGLE_NV
:
620 return ctx
->Extensions
.NV_texture_rectangle
621 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
622 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
623 return ctx
->Extensions
.NV_texture_rectangle
624 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
625 case GL_TEXTURE_1D_ARRAY_EXT
:
626 return ctx
->Extensions
.MESA_texture_array
627 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
628 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
629 return ctx
->Extensions
.MESA_texture_array
630 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
631 case GL_TEXTURE_2D_ARRAY_EXT
:
632 return ctx
->Extensions
.MESA_texture_array
633 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
634 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
635 return ctx
->Extensions
.MESA_texture_array
636 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
638 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
645 * Get a texture image pointer from a texture object, given a texture
646 * target and mipmap level. The target and level parameters should
647 * have already been error-checked.
649 * \param ctx GL context.
650 * \param texObj texture unit.
651 * \param target texture target.
652 * \param level image level.
654 * \return pointer to the texture image structure, or NULL on failure.
656 struct gl_texture_image
*
657 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
658 GLenum target
, GLint level
)
660 const GLuint face
= _mesa_tex_target_to_face(target
);
664 ASSERT(level
< MAX_TEXTURE_LEVELS
);
666 return texObj
->Image
[face
][level
];
671 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
672 * it and install it. Only return NULL if passed a bad parameter or run
675 struct gl_texture_image
*
676 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
677 GLenum target
, GLint level
)
679 struct gl_texture_image
*texImage
;
684 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
686 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
688 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
692 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
700 * Return pointer to the specified proxy texture image.
701 * Note that proxy textures are per-context, not per-texture unit.
702 * \return pointer to texture image or NULL if invalid target, invalid
703 * level, or out of memory.
705 struct gl_texture_image
*
706 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
708 struct gl_texture_image
*texImage
;
715 case GL_PROXY_TEXTURE_1D
:
716 if (level
>= ctx
->Const
.MaxTextureLevels
)
718 texIndex
= TEXTURE_1D_INDEX
;
720 case GL_PROXY_TEXTURE_2D
:
721 if (level
>= ctx
->Const
.MaxTextureLevels
)
723 texIndex
= TEXTURE_2D_INDEX
;
725 case GL_PROXY_TEXTURE_3D
:
726 if (level
>= ctx
->Const
.Max3DTextureLevels
)
728 texIndex
= TEXTURE_3D_INDEX
;
730 case GL_PROXY_TEXTURE_CUBE_MAP
:
731 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
733 texIndex
= TEXTURE_CUBE_INDEX
;
735 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
738 texIndex
= TEXTURE_RECT_INDEX
;
740 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
741 if (level
>= ctx
->Const
.MaxTextureLevels
)
743 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
745 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
746 if (level
>= ctx
->Const
.MaxTextureLevels
)
748 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
754 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
756 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
758 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
761 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
762 /* Set the 'back' pointer */
763 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
770 * Get the maximum number of allowed mipmap levels.
772 * \param ctx GL context.
773 * \param target texture target.
775 * \return the maximum number of allowed mipmap levels for the given
776 * texture target, or zero if passed a bad target.
781 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
785 case GL_PROXY_TEXTURE_1D
:
787 case GL_PROXY_TEXTURE_2D
:
788 return ctx
->Const
.MaxTextureLevels
;
790 case GL_PROXY_TEXTURE_3D
:
791 return ctx
->Const
.Max3DTextureLevels
;
792 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
793 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
794 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
795 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
796 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
797 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
798 case GL_TEXTURE_CUBE_MAP_ARB
:
799 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
800 return ctx
->Extensions
.ARB_texture_cube_map
801 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
802 case GL_TEXTURE_RECTANGLE_NV
:
803 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
804 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
805 case GL_TEXTURE_1D_ARRAY_EXT
:
806 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
807 case GL_TEXTURE_2D_ARRAY_EXT
:
808 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
809 return ctx
->Extensions
.MESA_texture_array
810 ? ctx
->Const
.MaxTextureLevels
: 0;
812 return 0; /* bad target */
818 #if 000 /* not used anymore */
820 * glTexImage[123]D can accept a NULL image pointer. In this case we
821 * create a texture image with unspecified image contents per the OpenGL
825 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
827 const GLint components
= _mesa_components_in_format(format
);
828 const GLint numPixels
= width
* height
* depth
;
829 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
833 * Let's see if anyone finds this. If glTexImage2D() is called with
834 * a NULL image pointer then load the texture image with something
835 * interesting instead of leaving it indeterminate.
838 static const char message
[8][32] = {
842 " X X XXXX XXX XXXXX ",
845 " X X XXXXX XXX X X ",
849 GLubyte
*imgPtr
= data
;
851 for (h
= 0; h
< depth
; h
++) {
852 for (i
= 0; i
< height
; i
++) {
853 GLint srcRow
= 7 - (i
% 8);
854 for (j
= 0; j
< width
; j
++) {
855 GLint srcCol
= j
% 32;
856 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
857 for (k
= 0; k
< components
; k
++) {
873 * Reset the fields of a gl_texture_image struct to zero.
875 * \param img texture image structure.
877 * This is called when a proxy texture test fails, we set all the
878 * image members (except DriverData) to zero.
879 * It's also used in glTexImage[123]D as a safeguard to be sure all
880 * required fields get initialized properly by the Driver.TexImage[123]D
884 clear_teximage_fields(struct gl_texture_image
*img
)
887 img
->_BaseFormat
= 0;
888 img
->InternalFormat
= 0;
894 if (img
->ImageOffsets
) {
895 _mesa_free(img
->ImageOffsets
);
896 img
->ImageOffsets
= NULL
;
905 img
->TexFormat
= &_mesa_null_texformat
;
906 img
->FetchTexelc
= NULL
;
907 img
->FetchTexelf
= NULL
;
908 img
->IsCompressed
= 0;
909 img
->CompressedSize
= 0;
914 * Initialize basic fields of the gl_texture_image struct.
916 * \param ctx GL context.
917 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
918 * \param img texture image structure to be initialized.
919 * \param width image width.
920 * \param height image height.
921 * \param depth image depth.
922 * \param border image border.
923 * \param internalFormat internal format.
925 * Fills in the fields of \p img with the given information.
926 * Note: width, height and depth include the border.
929 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
930 struct gl_texture_image
*img
,
931 GLsizei width
, GLsizei height
, GLsizei depth
,
932 GLint border
, GLenum internalFormat
)
941 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
942 ASSERT(img
->_BaseFormat
> 0);
943 img
->InternalFormat
= internalFormat
;
944 img
->Border
= border
;
946 img
->Height
= height
;
949 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
950 img
->WidthLog2
= logbase2(img
->Width2
);
952 if (height
== 1) { /* 1-D texture */
957 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
958 img
->HeightLog2
= logbase2(img
->Height2
);
961 if (depth
== 1) { /* 2-D texture */
966 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
967 img
->DepthLog2
= logbase2(img
->Depth2
);
970 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
972 img
->IsCompressed
= GL_FALSE
;
973 img
->CompressedSize
= 0;
975 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
976 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
977 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
978 img
->_IsPowerOfTwo
= GL_TRUE
;
980 img
->_IsPowerOfTwo
= GL_FALSE
;
982 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
983 img
->RowStride
= width
;
984 /* Allocate the ImageOffsets array and initialize to typical values.
985 * We allocate the array for 1D/2D textures too in order to avoid special-
986 * case code in the texstore routines.
988 if (img
->ImageOffsets
)
989 _mesa_free(img
->ImageOffsets
);
990 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
991 for (i
= 0; i
< depth
; i
++) {
992 img
->ImageOffsets
[i
] = i
* width
* height
;
995 /* Compute Width/Height/DepthScale for mipmap lod computation */
996 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
997 /* scale = 1.0 since texture coords directly map to texels */
998 img
->WidthScale
= 1.0;
999 img
->HeightScale
= 1.0;
1000 img
->DepthScale
= 1.0;
1003 img
->WidthScale
= (GLfloat
) img
->Width
;
1004 img
->HeightScale
= (GLfloat
) img
->Height
;
1005 img
->DepthScale
= (GLfloat
) img
->Depth
;
1011 * Free and clear fields of the gl_texture_image struct.
1013 * \param ctx GL context.
1014 * \param texImage texture image structure to be cleared.
1016 * After the call, \p texImage will have no data associated with it. Its
1017 * fields are cleared so that its parent object will test incomplete.
1020 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
1022 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1023 clear_teximage_fields(texImage
);
1028 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1029 * level, width, height and depth against the ctx->Const limits for textures.
1031 * A hardware driver might override this function if, for example, the
1032 * max 3D texture size is 512x512x64 (i.e. not a cube).
1034 * Note that width, height, depth == 0 is not an error. However, a
1035 * texture with zero width/height/depth will be considered "incomplete"
1036 * and texturing will effectively be disabled.
1038 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1039 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1040 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1041 * \param level as passed to glTexImage
1042 * \param internalFormat as passed to glTexImage
1043 * \param format as passed to glTexImage
1044 * \param type as passed to glTexImage
1045 * \param width as passed to glTexImage
1046 * \param height as passed to glTexImage
1047 * \param depth as passed to glTexImage
1048 * \param border as passed to glTexImage
1049 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1052 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1053 GLint internalFormat
, GLenum format
, GLenum type
,
1054 GLint width
, GLint height
, GLint depth
, GLint border
)
1058 (void) internalFormat
;
1063 case GL_PROXY_TEXTURE_1D
:
1064 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1065 if (width
< 2 * border
|| width
> 2 + maxSize
||
1066 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1067 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1068 level
>= ctx
->Const
.MaxTextureLevels
) {
1069 /* bad width or level */
1073 case GL_PROXY_TEXTURE_2D
:
1074 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1075 if (width
< 2 * border
|| width
> 2 + maxSize
||
1076 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1077 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1078 height
< 2 * border
|| height
> 2 + maxSize
||
1079 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1080 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1081 level
>= ctx
->Const
.MaxTextureLevels
) {
1082 /* bad width or height or level */
1086 case GL_PROXY_TEXTURE_3D
:
1087 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1088 if (width
< 2 * border
|| width
> 2 + maxSize
||
1089 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1090 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1091 height
< 2 * border
|| height
> 2 + maxSize
||
1092 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1093 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1094 depth
< 2 * border
|| depth
> 2 + maxSize
||
1095 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1096 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1097 level
>= ctx
->Const
.Max3DTextureLevels
) {
1098 /* bad width or height or depth or level */
1102 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1103 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1104 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1106 /* bad width or height or level */
1110 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1111 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1112 if (width
< 2 * border
|| width
> 2 + maxSize
||
1113 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1114 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1115 height
< 2 * border
|| height
> 2 + maxSize
||
1116 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1117 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1118 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1119 /* bad width or height */
1123 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1124 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1125 if (width
< 2 * border
|| width
> 2 + maxSize
||
1126 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1127 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1128 level
>= ctx
->Const
.MaxTextureLevels
) {
1129 /* bad width or level */
1133 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1137 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1138 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1139 if (width
< 2 * border
|| width
> 2 + maxSize
||
1140 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1141 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1142 height
< 2 * border
|| height
> 2 + maxSize
||
1143 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1144 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1145 level
>= ctx
->Const
.MaxTextureLevels
) {
1146 /* bad width or height or level */
1149 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1154 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1161 * Helper function to determine whether a target supports compressed textures
1164 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1166 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1167 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1168 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1169 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1170 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1171 || ((ctx
->Extensions
.MESA_texture_array
&&
1172 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1173 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1178 * Test the glTexImage[123]D() parameters for errors.
1180 * \param ctx GL context.
1181 * \param target texture target given by the user.
1182 * \param level image level given by the user.
1183 * \param internalFormat internal format given by the user.
1184 * \param format pixel data format given by the user.
1185 * \param type pixel data type given by the user.
1186 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1187 * \param width image width given by the user.
1188 * \param height image height given by the user.
1189 * \param depth image depth given by the user.
1190 * \param border image border given by the user.
1192 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1194 * Verifies each of the parameters against the constants specified in
1195 * __GLcontextRec::Const and the supported extensions, and according to the
1196 * OpenGL specification.
1199 texture_error_check( GLcontext
*ctx
, GLenum target
,
1200 GLint level
, GLint internalFormat
,
1201 GLenum format
, GLenum type
,
1203 GLint width
, GLint height
,
1204 GLint depth
, GLint border
)
1206 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1207 GLboolean sizeOK
= GL_TRUE
;
1208 GLboolean colorFormat
, indexFormat
;
1209 GLenum proxy_target
;
1211 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1212 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1214 _mesa_error(ctx
, GL_INVALID_VALUE
,
1215 "glTexImage%dD(level=%d)", dimensions
, level
);
1221 if (border
< 0 || border
> 1 ||
1222 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1223 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1225 _mesa_error(ctx
, GL_INVALID_VALUE
,
1226 "glTexImage%dD(border=%d)", dimensions
, border
);
1231 if (width
< 0 || height
< 0 || depth
< 0) {
1233 _mesa_error(ctx
, GL_INVALID_VALUE
,
1234 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1239 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1240 * level, width, height and depth.
1242 if (dimensions
== 1) {
1243 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1244 proxy_target
= GL_PROXY_TEXTURE_1D
;
1249 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1253 else if (dimensions
== 2) {
1255 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1256 proxy_target
= GL_PROXY_TEXTURE_2D
;
1258 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1259 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1260 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1261 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1262 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1265 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1266 sizeOK
= (width
== height
);
1268 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1269 target
== GL_TEXTURE_RECTANGLE_NV
) {
1270 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1271 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1274 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1276 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1277 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1278 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1281 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1285 else if (dimensions
== 3) {
1286 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1287 proxy_target
= GL_PROXY_TEXTURE_3D
;
1289 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1290 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1291 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1294 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1299 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1303 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1304 internalFormat
, format
,
1305 type
, width
, height
,
1309 _mesa_error(ctx
, GL_INVALID_VALUE
,
1310 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1311 dimensions
, level
, width
, height
, depth
);
1316 /* Check internalFormat */
1317 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1319 _mesa_error(ctx
, GL_INVALID_VALUE
,
1320 "glTexImage%dD(internalFormat=0x%x)",
1321 dimensions
, internalFormat
);
1326 /* Check incoming image format and type */
1327 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1328 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1329 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1332 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1333 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1334 dimensions
, format
, type
);
1339 /* make sure internal format and format basically agree */
1340 colorFormat
= _mesa_is_color_format(format
);
1341 indexFormat
= _mesa_is_index_format(format
);
1342 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1343 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1344 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1345 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1346 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1347 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1349 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1350 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1351 dimensions
, internalFormat
, format
);
1355 /* additional checks for ycbcr textures */
1356 if (internalFormat
== GL_YCBCR_MESA
) {
1357 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1358 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1359 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1361 _mesa_sprintf(message
,
1362 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1363 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1364 return GL_TRUE
; /* error */
1366 if (target
!= GL_TEXTURE_2D
&&
1367 target
!= GL_PROXY_TEXTURE_2D
&&
1368 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1369 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1371 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1377 _mesa_sprintf(message
,
1378 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1379 dimensions
, border
);
1380 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1386 /* additional checks for depth textures */
1387 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1388 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1389 if (target
!= GL_TEXTURE_1D
&&
1390 target
!= GL_PROXY_TEXTURE_1D
&&
1391 target
!= GL_TEXTURE_2D
&&
1392 target
!= GL_PROXY_TEXTURE_2D
&&
1393 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1394 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1396 _mesa_error(ctx
, GL_INVALID_ENUM
,
1397 "glTexImage(target/internalFormat)");
1402 /* additional checks for compressed textures */
1403 if (is_compressed_format(ctx
, internalFormat
)) {
1404 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1405 _mesa_error(ctx
, GL_INVALID_ENUM
,
1406 "glTexImage%d(target)", dimensions
);
1411 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1412 "glTexImage%D(border!=0)", dimensions
);
1418 /* if we get here, the parameters are OK */
1424 * Test glTexSubImage[123]D() parameters for errors.
1426 * \param ctx GL context.
1427 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1428 * \param target texture target given by the user.
1429 * \param level image level given by the user.
1430 * \param xoffset sub-image x offset given by the user.
1431 * \param yoffset sub-image y offset given by the user.
1432 * \param zoffset sub-image z offset given by the user.
1433 * \param format pixel data format given by the user.
1434 * \param type pixel data type given by the user.
1435 * \param width image width given by the user.
1436 * \param height image height given by the user.
1437 * \param depth image depth given by the user.
1439 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1441 * Verifies each of the parameters against the constants specified in
1442 * __GLcontextRec::Const and the supported extensions, and according to the
1443 * OpenGL specification.
1446 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1447 GLenum target
, GLint level
,
1448 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1449 GLint width
, GLint height
, GLint depth
,
1450 GLenum format
, GLenum type
)
1453 if (dimensions
== 1) {
1454 if (target
!= GL_TEXTURE_1D
) {
1455 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1459 else if (dimensions
== 2) {
1460 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1461 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1462 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1463 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1467 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1468 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1469 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1473 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1474 if (!ctx
->Extensions
.MESA_texture_array
) {
1475 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1479 else if (target
!= GL_TEXTURE_2D
) {
1480 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1484 else if (dimensions
== 3) {
1485 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1486 if (!ctx
->Extensions
.MESA_texture_array
) {
1487 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1491 else if (target
!= GL_TEXTURE_3D
) {
1492 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1497 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1501 /* Basic level check */
1502 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1503 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1508 _mesa_error(ctx
, GL_INVALID_VALUE
,
1509 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1512 if (height
< 0 && dimensions
> 1) {
1513 _mesa_error(ctx
, GL_INVALID_VALUE
,
1514 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1517 if (depth
< 0 && dimensions
> 2) {
1518 _mesa_error(ctx
, GL_INVALID_VALUE
,
1519 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1523 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1524 _mesa_error(ctx
, GL_INVALID_ENUM
,
1525 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1526 dimensions
, format
, type
);
1534 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1535 GLenum target
, GLint level
,
1536 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1537 GLint width
, GLint height
, GLint depth
,
1538 GLenum format
, GLenum type
,
1539 const struct gl_texture_image
*destTex
)
1542 /* undefined image level */
1543 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1547 if (xoffset
< -((GLint
)destTex
->Border
)) {
1548 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1552 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1553 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1557 if (dimensions
> 1) {
1558 if (yoffset
< -((GLint
)destTex
->Border
)) {
1559 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1563 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1564 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1569 if (dimensions
> 2) {
1570 if (zoffset
< -((GLint
)destTex
->Border
)) {
1571 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1574 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1575 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1580 #if FEATURE_EXT_texture_sRGB
1581 if (destTex
->InternalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
1582 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
1583 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
1584 destTex
->InternalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
) {
1585 if ((width
& 0x3) || (height
& 0x3) ||
1586 (xoffset
& 0x3) || (yoffset
& 0x3))
1587 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1588 "glTexSubImage%dD(size or offset not multiple of 4)",
1594 if (destTex
->IsCompressed
) {
1595 if (!target_can_be_compressed(ctx
, target
)) {
1596 _mesa_error(ctx
, GL_INVALID_ENUM
,
1597 "glTexSubImage%D(target)", dimensions
);
1600 /* offset must be multiple of 4 */
1601 if ((xoffset
& 3) || (yoffset
& 3)) {
1602 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1603 "glTexSubImage%D(xoffset or yoffset)", dimensions
);
1606 /* size must be multiple of 4 or equal to whole texture size */
1607 if ((width
& 3) && (GLuint
) width
!= destTex
->Width
) {
1608 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1609 "glTexSubImage%D(width)", dimensions
);
1612 if ((height
& 3) && (GLuint
) height
!= destTex
->Height
) {
1613 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1614 "glTexSubImage%D(width)", dimensions
);
1624 * Test glCopyTexImage[12]D() parameters for errors.
1626 * \param ctx GL context.
1627 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1628 * \param target texture target given by the user.
1629 * \param level image level given by the user.
1630 * \param internalFormat internal format given by the user.
1631 * \param width image width given by the user.
1632 * \param height image height given by the user.
1633 * \param border texture border.
1635 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1637 * Verifies each of the parameters against the constants specified in
1638 * __GLcontextRec::Const and the supported extensions, and according to the
1639 * OpenGL specification.
1642 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1643 GLenum target
, GLint level
, GLint internalFormat
,
1644 GLint width
, GLint height
, GLint border
)
1650 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1651 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1652 _mesa_error(ctx
, GL_INVALID_VALUE
,
1653 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1657 /* Check that the source buffer is complete */
1658 if (ctx
->ReadBuffer
->Name
) {
1659 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1660 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1661 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1662 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1668 if (border
< 0 || border
> 1 ||
1669 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1670 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1674 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1676 _mesa_error(ctx
, GL_INVALID_VALUE
,
1677 "glCopyTexImage%dD(internalFormat)", dimensions
);
1681 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1682 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1683 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1687 /* NOTE: the format and type aren't really significant for
1688 * TestProxyTexImage(). Only the internalformat really matters.
1692 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1693 * level, width, height and depth.
1695 if (dimensions
== 1) {
1696 if (target
== GL_TEXTURE_1D
) {
1697 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1698 level
, internalFormat
,
1700 width
, 1, 1, border
);
1703 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1707 else if (dimensions
== 2) {
1708 if (target
== GL_TEXTURE_2D
) {
1709 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1710 level
, internalFormat
,
1712 width
, height
, 1, border
);
1714 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1715 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1716 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1717 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1720 sizeOK
= (width
== height
) &&
1721 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1722 level
, internalFormat
, format
, type
,
1723 width
, height
, 1, border
);
1725 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1726 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1727 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1730 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1731 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1732 level
, internalFormat
,
1734 width
, height
, 1, border
);
1736 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1737 if (!ctx
->Extensions
.MESA_texture_array
) {
1738 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1741 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1742 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1743 level
, internalFormat
,
1745 width
, height
, 1, border
);
1748 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1753 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1758 if (dimensions
== 1) {
1759 _mesa_error(ctx
, GL_INVALID_VALUE
,
1760 "glCopyTexImage1D(width=%d)", width
);
1763 ASSERT(dimensions
== 2);
1764 _mesa_error(ctx
, GL_INVALID_VALUE
,
1765 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1770 if (is_compressed_format(ctx
, internalFormat
)) {
1771 if (!target_can_be_compressed(ctx
, target
)) {
1772 _mesa_error(ctx
, GL_INVALID_ENUM
,
1773 "glCopyTexImage%d(target)", dimensions
);
1777 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1778 "glCopyTexImage%D(border!=0)", dimensions
);
1782 else if (_mesa_is_depth_format(internalFormat
)) {
1783 /* make sure we have depth/stencil buffers */
1784 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1785 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1786 "glCopyTexImage%D(no depth)", dimensions
);
1790 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1791 /* make sure we have depth/stencil buffers */
1792 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1793 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1794 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
1799 /* if we get here, the parameters are OK */
1805 * Test glCopyTexSubImage[12]D() parameters for errors.
1806 * Note that this is the first part of error checking.
1807 * See also copytexsubimage_error_check2() below for the second part.
1809 * \param ctx GL context.
1810 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1811 * \param target texture target given by the user.
1812 * \param level image level given by the user.
1814 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1817 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1818 GLenum target
, GLint level
)
1820 /* Check that the source buffer is complete */
1821 if (ctx
->ReadBuffer
->Name
) {
1822 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1823 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1824 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1825 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1831 if (dimensions
== 1) {
1832 if (target
!= GL_TEXTURE_1D
) {
1833 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1837 else if (dimensions
== 2) {
1838 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1839 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1840 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1841 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1845 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1846 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1847 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1851 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1852 if (!ctx
->Extensions
.MESA_texture_array
) {
1853 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1857 else if (target
!= GL_TEXTURE_2D
) {
1858 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1862 else if (dimensions
== 3) {
1863 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1864 (!ctx
->Extensions
.MESA_texture_array
))
1865 && (target
!= GL_TEXTURE_3D
)) {
1866 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1872 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1873 _mesa_error(ctx
, GL_INVALID_VALUE
,
1874 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1883 * Second part of error checking for glCopyTexSubImage[12]D().
1884 * \param xoffset sub-image x offset given by the user.
1885 * \param yoffset sub-image y offset given by the user.
1886 * \param zoffset sub-image z offset given by the user.
1887 * \param width image width given by the user.
1888 * \param height image height given by the user.
1891 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1892 GLenum target
, GLint level
,
1893 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1894 GLsizei width
, GLsizei height
,
1895 const struct gl_texture_image
*teximage
)
1897 /* check that dest tex image exists */
1899 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1900 "glCopyTexSubImage%dD(undefined texture level: %d)",
1907 _mesa_error(ctx
, GL_INVALID_VALUE
,
1908 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1911 if (dimensions
> 1 && height
< 0) {
1912 _mesa_error(ctx
, GL_INVALID_VALUE
,
1913 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1917 /* check x/y offsets */
1918 if (xoffset
< -((GLint
)teximage
->Border
)) {
1919 _mesa_error(ctx
, GL_INVALID_VALUE
,
1920 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1923 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1924 _mesa_error(ctx
, GL_INVALID_VALUE
,
1925 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1928 if (dimensions
> 1) {
1929 if (yoffset
< -((GLint
)teximage
->Border
)) {
1930 _mesa_error(ctx
, GL_INVALID_VALUE
,
1931 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1934 /* NOTE: we're adding the border here, not subtracting! */
1935 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1936 _mesa_error(ctx
, GL_INVALID_VALUE
,
1937 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1942 /* check z offset */
1943 if (dimensions
> 2) {
1944 if (zoffset
< -((GLint
)teximage
->Border
)) {
1945 _mesa_error(ctx
, GL_INVALID_VALUE
,
1946 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1949 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1950 _mesa_error(ctx
, GL_INVALID_VALUE
,
1951 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1956 if (teximage
->IsCompressed
) {
1957 if (!target_can_be_compressed(ctx
, target
)) {
1958 _mesa_error(ctx
, GL_INVALID_ENUM
,
1959 "glCopyTexSubImage%d(target)", dimensions
);
1962 /* offset must be multiple of 4 */
1963 if ((xoffset
& 3) || (yoffset
& 3)) {
1964 _mesa_error(ctx
, GL_INVALID_VALUE
,
1965 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
1968 /* size must be multiple of 4 */
1969 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1970 _mesa_error(ctx
, GL_INVALID_VALUE
,
1971 "glCopyTexSubImage%D(width)", dimensions
);
1974 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1975 _mesa_error(ctx
, GL_INVALID_VALUE
,
1976 "glCopyTexSubImage%D(height)", dimensions
);
1981 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
1982 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1986 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
1987 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1988 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
1989 dimensions
, teximage
->_BaseFormat
);
1993 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
1994 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1995 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1996 "glCopyTexSubImage%D(no depth buffer)",
2001 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2002 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2003 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2004 "glCopyTexSubImage%D(no depth/stencil buffer)",
2010 /* if we get here, the parameters are OK */
2015 /** Callback info for walking over FBO hash table */
2019 struct gl_texture_object
*texObj
;
2025 * Check render to texture callback. Called from _mesa_HashWalk().
2028 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2030 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2031 const struct cb_info
*info
= (struct cb_info
*) userData
;
2032 GLcontext
*ctx
= info
->ctx
;
2033 const struct gl_texture_object
*texObj
= info
->texObj
;
2034 const GLuint level
= info
->level
, face
= info
->face
;
2036 /* If this is a user-created FBO */
2039 /* check if any of the FBO's attachments point to 'texObj' */
2040 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2041 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2042 if (att
->Type
== GL_TEXTURE
&&
2043 att
->Texture
== texObj
&&
2044 att
->TextureLevel
== level
&&
2045 att
->CubeMapFace
== face
) {
2046 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2047 /* Tell driver about the new renderbuffer texture */
2048 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2049 /* Mark fb status as indeterminate to force re-validation */
2058 * When a texture image is specified we have to check if it's bound to
2059 * any framebuffer objects (render to texture) in order to detect changes
2060 * in size or format since that effects FBO completeness.
2061 * Any FBOs rendering into the texture must be re-validated.
2064 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2065 GLuint face
, GLuint level
)
2067 /* Only check this texture if it's been marked as RenderToTexture */
2068 if (texObj
->_RenderToTexture
) {
2069 struct cb_info info
;
2071 info
.texObj
= texObj
;
2074 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2080 * If the texture object's GenerateMipmap flag is set and we've
2081 * changed the texture base level image, regenerate the rest of the
2082 * mipmap levels now.
2085 check_gen_mipmap(GLcontext
*ctx
, GLenum target
,
2086 struct gl_texture_object
*texObj
, GLint level
)
2088 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2089 if (texObj
->GenerateMipmap
&& level
== texObj
->BaseLevel
) {
2090 ASSERT(ctx
->Driver
.GenerateMipmap
);
2091 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2096 /** Debug helper: override the user-requested internal format */
2098 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2101 if (internalFormat
== GL_RGBA16F_ARB
||
2102 internalFormat
== GL_RGBA32F_ARB
) {
2103 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2106 else if (internalFormat
== GL_RGB16F_ARB
||
2107 internalFormat
== GL_RGB32F_ARB
) {
2108 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2111 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2112 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2113 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2114 return GL_LUMINANCE_ALPHA
;
2116 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2117 internalFormat
== GL_LUMINANCE32F_ARB
) {
2118 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2119 return GL_LUMINANCE
;
2121 else if (internalFormat
== GL_ALPHA16F_ARB
||
2122 internalFormat
== GL_ALPHA32F_ARB
) {
2123 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2127 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2128 internalFormat = GL_RGBA;
2132 return internalFormat
;
2135 return internalFormat
;
2141 * Called from the API. Note that width includes the border.
2144 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2145 GLsizei width
, GLint border
, GLenum format
,
2146 GLenum type
, const GLvoid
*pixels
)
2148 GLsizei postConvWidth
= width
;
2149 GET_CURRENT_CONTEXT(ctx
);
2150 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2152 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2153 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2154 _mesa_lookup_enum_by_nr(target
), level
,
2155 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2156 _mesa_lookup_enum_by_nr(format
),
2157 _mesa_lookup_enum_by_nr(type
), pixels
);
2159 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2161 #if FEATURE_convolve
2162 if (_mesa_is_color_format(internalFormat
)) {
2163 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2167 if (target
== GL_TEXTURE_1D
) {
2168 /* non-proxy target */
2169 struct gl_texture_unit
*texUnit
;
2170 struct gl_texture_object
*texObj
;
2171 struct gl_texture_image
*texImage
;
2172 const GLuint face
= _mesa_tex_target_to_face(target
);
2174 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2175 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2176 return; /* error was recorded */
2179 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2180 _mesa_update_state(ctx
);
2182 texUnit
= _mesa_get_current_tex_unit(ctx
);
2183 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2184 _mesa_lock_texture(ctx
, texObj
);
2186 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2188 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2191 if (texImage
->Data
) {
2192 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2195 ASSERT(texImage
->Data
== NULL
);
2197 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2198 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2199 postConvWidth
, 1, 1,
2200 border
, internalFormat
);
2202 /* Give the texture to the driver. <pixels> may be null. */
2203 ASSERT(ctx
->Driver
.TexImage1D
);
2204 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2205 width
, border
, format
, type
, pixels
,
2206 &ctx
->Unpack
, texObj
, texImage
);
2208 ASSERT(texImage
->TexFormat
);
2210 check_gen_mipmap(ctx
, target
, texObj
, level
);
2212 update_fbo_texture(ctx
, texObj
, face
, level
);
2215 texObj
->_Complete
= GL_FALSE
;
2216 ctx
->NewState
|= _NEW_TEXTURE
;
2219 _mesa_unlock_texture(ctx
, texObj
);
2221 else if (target
== GL_PROXY_TEXTURE_1D
) {
2222 /* Proxy texture: check for errors and update proxy state */
2223 struct gl_texture_image
*texImage
;
2224 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2225 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2226 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2227 /* when error, clear all proxy texture image parameters */
2229 clear_teximage_fields(texImage
);
2232 /* no error, set the tex image parameters */
2234 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2235 postConvWidth
, 1, 1,
2236 border
, internalFormat
);
2237 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2238 internalFormat
, format
, type
);
2242 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2249 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2250 GLsizei width
, GLsizei height
, GLint border
,
2251 GLenum format
, GLenum type
,
2252 const GLvoid
*pixels
)
2254 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2255 GET_CURRENT_CONTEXT(ctx
);
2256 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2258 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2259 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2260 _mesa_lookup_enum_by_nr(target
), level
,
2261 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2262 border
, _mesa_lookup_enum_by_nr(format
),
2263 _mesa_lookup_enum_by_nr(type
), pixels
);
2265 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2267 #if FEATURE_convolve
2268 if (_mesa_is_color_format(internalFormat
)) {
2269 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2274 if (target
== GL_TEXTURE_2D
||
2275 (ctx
->Extensions
.ARB_texture_cube_map
&&
2276 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2277 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2278 (ctx
->Extensions
.NV_texture_rectangle
&&
2279 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2280 (ctx
->Extensions
.MESA_texture_array
&&
2281 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2282 /* non-proxy target */
2283 struct gl_texture_unit
*texUnit
;
2284 struct gl_texture_object
*texObj
;
2285 struct gl_texture_image
*texImage
;
2286 const GLuint face
= _mesa_tex_target_to_face(target
);
2288 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2289 format
, type
, 2, postConvWidth
, postConvHeight
,
2291 return; /* error was recorded */
2294 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2295 _mesa_update_state(ctx
);
2297 texUnit
= _mesa_get_current_tex_unit(ctx
);
2298 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2299 _mesa_lock_texture(ctx
, texObj
);
2301 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2303 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2306 if (texImage
->Data
) {
2307 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2310 ASSERT(texImage
->Data
== NULL
);
2311 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2312 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2313 postConvWidth
, postConvHeight
, 1,
2314 border
, internalFormat
);
2316 /* Give the texture to the driver. <pixels> may be null. */
2317 ASSERT(ctx
->Driver
.TexImage2D
);
2318 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2319 width
, height
, border
, format
, type
,
2320 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2322 ASSERT(texImage
->TexFormat
);
2324 check_gen_mipmap(ctx
, target
, texObj
, level
);
2326 update_fbo_texture(ctx
, texObj
, face
, level
);
2329 texObj
->_Complete
= GL_FALSE
;
2330 ctx
->NewState
|= _NEW_TEXTURE
;
2333 _mesa_unlock_texture(ctx
, texObj
);
2335 else if (target
== GL_PROXY_TEXTURE_2D
||
2336 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2337 ctx
->Extensions
.ARB_texture_cube_map
) ||
2338 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2339 ctx
->Extensions
.NV_texture_rectangle
) ||
2340 (ctx
->Extensions
.MESA_texture_array
&&
2341 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2342 /* Proxy texture: check for errors and update proxy state */
2343 struct gl_texture_image
*texImage
;
2344 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2345 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2346 format
, type
, 2, postConvWidth
, postConvHeight
,
2348 /* when error, clear all proxy texture image parameters */
2350 clear_teximage_fields(texImage
);
2353 /* no error, set the tex image parameters */
2354 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2355 postConvWidth
, postConvHeight
, 1,
2356 border
, internalFormat
);
2357 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2358 internalFormat
, format
, type
);
2362 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2369 * Called by the API or display list executor.
2370 * Note that width and height include the border.
2373 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2374 GLsizei width
, GLsizei height
, GLsizei depth
,
2375 GLint border
, GLenum format
, GLenum type
,
2376 const GLvoid
*pixels
)
2378 GET_CURRENT_CONTEXT(ctx
);
2379 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2381 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2382 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2383 _mesa_lookup_enum_by_nr(target
), level
,
2384 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2385 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2386 _mesa_lookup_enum_by_nr(type
), pixels
);
2388 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2390 if (target
== GL_TEXTURE_3D
||
2391 (ctx
->Extensions
.MESA_texture_array
&&
2392 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2393 /* non-proxy target */
2394 struct gl_texture_unit
*texUnit
;
2395 struct gl_texture_object
*texObj
;
2396 struct gl_texture_image
*texImage
;
2397 const GLuint face
= _mesa_tex_target_to_face(target
);
2399 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2400 format
, type
, 3, width
, height
, depth
, border
)) {
2401 return; /* error was recorded */
2404 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2405 _mesa_update_state(ctx
);
2407 texUnit
= _mesa_get_current_tex_unit(ctx
);
2408 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2409 _mesa_lock_texture(ctx
, texObj
);
2411 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2413 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2416 if (texImage
->Data
) {
2417 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2420 ASSERT(texImage
->Data
== NULL
);
2421 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2422 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2423 width
, height
, depth
,
2424 border
, internalFormat
);
2426 /* Give the texture to the driver. <pixels> may be null. */
2427 ASSERT(ctx
->Driver
.TexImage3D
);
2428 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2429 width
, height
, depth
, border
, format
, type
,
2430 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2432 ASSERT(texImage
->TexFormat
);
2434 check_gen_mipmap(ctx
, target
, texObj
, level
);
2436 update_fbo_texture(ctx
, texObj
, face
, level
);
2439 texObj
->_Complete
= GL_FALSE
;
2440 ctx
->NewState
|= _NEW_TEXTURE
;
2443 _mesa_unlock_texture(ctx
, texObj
);
2445 else if (target
== GL_PROXY_TEXTURE_3D
||
2446 (ctx
->Extensions
.MESA_texture_array
&&
2447 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2448 /* Proxy texture: check for errors and update proxy state */
2449 struct gl_texture_image
*texImage
;
2450 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2451 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2452 format
, type
, 3, width
, height
, depth
, border
)) {
2453 /* when error, clear all proxy texture image parameters */
2455 clear_teximage_fields(texImage
);
2458 /* no error, set the tex image parameters */
2459 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2460 depth
, border
, internalFormat
);
2461 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2462 internalFormat
, format
, type
);
2466 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2473 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2474 GLsizei width
, GLsizei height
, GLsizei depth
,
2475 GLint border
, GLenum format
, GLenum type
,
2476 const GLvoid
*pixels
)
2478 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2479 depth
, border
, format
, type
, pixels
);
2485 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2486 GLint xoffset
, GLsizei width
,
2487 GLenum format
, GLenum type
,
2488 const GLvoid
*pixels
)
2490 GLsizei postConvWidth
= width
;
2491 struct gl_texture_unit
*texUnit
;
2492 struct gl_texture_object
*texObj
;
2493 struct gl_texture_image
*texImage
= NULL
;
2494 GET_CURRENT_CONTEXT(ctx
);
2495 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2497 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2498 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2499 _mesa_lookup_enum_by_nr(target
), level
,
2500 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2501 _mesa_lookup_enum_by_nr(type
), pixels
);
2503 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2504 _mesa_update_state(ctx
);
2506 #if FEATURE_convolve
2507 /* XXX should test internal format */
2508 if (_mesa_is_color_format(format
)) {
2509 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2513 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2514 postConvWidth
, 1, 1, format
, type
)) {
2515 return; /* error was detected */
2519 texUnit
= _mesa_get_current_tex_unit(ctx
);
2520 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2523 _mesa_lock_texture(ctx
, texObj
);
2525 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2527 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2528 postConvWidth
, 1, 1,
2529 format
, type
, texImage
)) {
2530 /* error was recorded */
2532 else if (width
> 0) {
2533 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2534 xoffset
+= texImage
->Border
;
2536 ASSERT(ctx
->Driver
.TexSubImage1D
);
2537 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2538 format
, type
, pixels
, &ctx
->Unpack
,
2541 check_gen_mipmap(ctx
, target
, texObj
, level
);
2543 ctx
->NewState
|= _NEW_TEXTURE
;
2546 _mesa_unlock_texture(ctx
, texObj
);
2551 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2552 GLint xoffset
, GLint yoffset
,
2553 GLsizei width
, GLsizei height
,
2554 GLenum format
, GLenum type
,
2555 const GLvoid
*pixels
)
2557 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2558 struct gl_texture_unit
*texUnit
;
2559 struct gl_texture_object
*texObj
;
2560 struct gl_texture_image
*texImage
;
2561 GET_CURRENT_CONTEXT(ctx
);
2562 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2564 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2565 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2566 _mesa_lookup_enum_by_nr(target
), level
,
2567 xoffset
, yoffset
, width
, height
,
2568 _mesa_lookup_enum_by_nr(format
),
2569 _mesa_lookup_enum_by_nr(type
), pixels
);
2571 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2572 _mesa_update_state(ctx
);
2574 #if FEATURE_convolve
2575 /* XXX should test internal format */
2576 if (_mesa_is_color_format(format
)) {
2577 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2582 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2583 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2584 return; /* error was detected */
2587 texUnit
= _mesa_get_current_tex_unit(ctx
);
2588 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2590 _mesa_lock_texture(ctx
, texObj
);
2592 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2594 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2595 postConvWidth
, postConvHeight
, 1,
2596 format
, type
, texImage
)) {
2597 /* error was recorded */
2599 else if (width
> 0 && height
>= 0) {
2600 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2601 xoffset
+= texImage
->Border
;
2602 yoffset
+= texImage
->Border
;
2604 ASSERT(ctx
->Driver
.TexSubImage2D
);
2605 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2606 width
, height
, format
, type
, pixels
,
2607 &ctx
->Unpack
, texObj
, texImage
);
2609 check_gen_mipmap(ctx
, target
, texObj
, level
);
2611 ctx
->NewState
|= _NEW_TEXTURE
;
2614 _mesa_unlock_texture(ctx
, texObj
);
2620 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2621 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2622 GLsizei width
, GLsizei height
, GLsizei depth
,
2623 GLenum format
, GLenum type
,
2624 const GLvoid
*pixels
)
2626 struct gl_texture_unit
*texUnit
;
2627 struct gl_texture_object
*texObj
;
2628 struct gl_texture_image
*texImage
;
2629 GET_CURRENT_CONTEXT(ctx
);
2630 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2632 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2633 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2634 _mesa_lookup_enum_by_nr(target
), level
,
2635 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2636 _mesa_lookup_enum_by_nr(format
),
2637 _mesa_lookup_enum_by_nr(type
), pixels
);
2639 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2640 _mesa_update_state(ctx
);
2642 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2643 width
, height
, depth
, format
, type
)) {
2644 return; /* error was detected */
2647 texUnit
= _mesa_get_current_tex_unit(ctx
);
2648 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2650 _mesa_lock_texture(ctx
, texObj
);
2652 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2654 if (subtexture_error_check2(ctx
, 3, target
, level
,
2655 xoffset
, yoffset
, zoffset
,
2656 width
, height
, depth
,
2657 format
, type
, texImage
)) {
2658 /* error was recorded */
2660 else if (width
> 0 && height
> 0 && height
> 0) {
2661 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2662 xoffset
+= texImage
->Border
;
2663 yoffset
+= texImage
->Border
;
2664 zoffset
+= texImage
->Border
;
2666 ASSERT(ctx
->Driver
.TexSubImage3D
);
2667 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2668 xoffset
, yoffset
, zoffset
,
2669 width
, height
, depth
,
2670 format
, type
, pixels
,
2671 &ctx
->Unpack
, texObj
, texImage
);
2673 check_gen_mipmap(ctx
, target
, texObj
, level
);
2675 ctx
->NewState
|= _NEW_TEXTURE
;
2678 _mesa_unlock_texture(ctx
, texObj
);
2684 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2685 GLenum internalFormat
,
2687 GLsizei width
, GLint border
)
2689 struct gl_texture_unit
*texUnit
;
2690 struct gl_texture_object
*texObj
;
2691 struct gl_texture_image
*texImage
;
2692 GLsizei postConvWidth
= width
;
2693 const GLuint face
= _mesa_tex_target_to_face(target
);
2694 GET_CURRENT_CONTEXT(ctx
);
2695 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2697 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2698 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2699 _mesa_lookup_enum_by_nr(target
), level
,
2700 _mesa_lookup_enum_by_nr(internalFormat
),
2701 x
, y
, width
, border
);
2703 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2704 _mesa_update_state(ctx
);
2706 #if FEATURE_convolve
2707 if (_mesa_is_color_format(internalFormat
)) {
2708 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2712 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2713 postConvWidth
, 1, border
))
2716 texUnit
= _mesa_get_current_tex_unit(ctx
);
2717 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2719 _mesa_lock_texture(ctx
, texObj
);
2721 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2723 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2726 if (texImage
->Data
) {
2727 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2730 ASSERT(texImage
->Data
== NULL
);
2732 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2733 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2734 border
, internalFormat
);
2736 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2737 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2738 x
, y
, width
, border
);
2740 ASSERT(texImage
->TexFormat
);
2742 check_gen_mipmap(ctx
, target
, texObj
, level
);
2744 update_fbo_texture(ctx
, texObj
, face
, level
);
2747 texObj
->_Complete
= GL_FALSE
;
2748 ctx
->NewState
|= _NEW_TEXTURE
;
2751 _mesa_unlock_texture(ctx
, texObj
);
2757 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2758 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2761 struct gl_texture_unit
*texUnit
;
2762 struct gl_texture_object
*texObj
;
2763 struct gl_texture_image
*texImage
;
2764 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2765 const GLuint face
= _mesa_tex_target_to_face(target
);
2766 GET_CURRENT_CONTEXT(ctx
);
2767 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2769 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2770 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2771 _mesa_lookup_enum_by_nr(target
), level
,
2772 _mesa_lookup_enum_by_nr(internalFormat
),
2773 x
, y
, width
, height
, border
);
2775 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2776 _mesa_update_state(ctx
);
2778 #if FEATURE_convolve
2779 if (_mesa_is_color_format(internalFormat
)) {
2780 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2785 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2786 postConvWidth
, postConvHeight
, border
))
2789 texUnit
= _mesa_get_current_tex_unit(ctx
);
2790 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2792 _mesa_lock_texture(ctx
, texObj
);
2794 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2797 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2800 if (texImage
->Data
) {
2801 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2804 ASSERT(texImage
->Data
== NULL
);
2806 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2807 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2808 postConvWidth
, postConvHeight
, 1,
2809 border
, internalFormat
);
2811 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2812 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2813 x
, y
, width
, height
, border
);
2815 ASSERT(texImage
->TexFormat
);
2817 check_gen_mipmap(ctx
, target
, texObj
, level
);
2819 update_fbo_texture(ctx
, texObj
, face
, level
);
2822 texObj
->_Complete
= GL_FALSE
;
2823 ctx
->NewState
|= _NEW_TEXTURE
;
2826 _mesa_unlock_texture(ctx
, texObj
);
2831 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2832 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2834 struct gl_texture_unit
*texUnit
;
2835 struct gl_texture_object
*texObj
;
2836 struct gl_texture_image
*texImage
;
2837 GLsizei postConvWidth
= width
;
2841 GET_CURRENT_CONTEXT(ctx
);
2842 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2844 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2845 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2846 _mesa_lookup_enum_by_nr(target
),
2847 level
, xoffset
, x
, y
, width
);
2849 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2850 _mesa_update_state(ctx
);
2852 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2855 texUnit
= _mesa_get_current_tex_unit(ctx
);
2856 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2858 _mesa_lock_texture(ctx
, texObj
);
2860 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2862 #if FEATURE_convolve
2863 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2864 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2868 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2869 xoffset
, 0, 0, postConvWidth
, 1,
2871 /* error was recorded */
2874 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2875 xoffset
+= texImage
->Border
;
2877 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2879 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2880 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2881 xoffset
, x
, y
, width
);
2883 check_gen_mipmap(ctx
, target
, texObj
, level
);
2885 ctx
->NewState
|= _NEW_TEXTURE
;
2889 _mesa_unlock_texture(ctx
, texObj
);
2895 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2896 GLint xoffset
, GLint yoffset
,
2897 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2899 struct gl_texture_unit
*texUnit
;
2900 struct gl_texture_object
*texObj
;
2901 struct gl_texture_image
*texImage
;
2902 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2903 GET_CURRENT_CONTEXT(ctx
);
2904 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2906 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2907 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2908 _mesa_lookup_enum_by_nr(target
),
2909 level
, xoffset
, yoffset
, x
, y
, width
, height
);
2911 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2912 _mesa_update_state(ctx
);
2914 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2917 texUnit
= _mesa_get_current_tex_unit(ctx
);
2918 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2920 _mesa_lock_texture(ctx
, texObj
);
2922 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2924 #if FEATURE_convolve
2925 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2926 _mesa_adjust_image_for_convolution(ctx
, 2,
2927 &postConvWidth
, &postConvHeight
);
2931 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
2932 xoffset
, yoffset
, 0,
2933 postConvWidth
, postConvHeight
,
2935 /* error was recorded */
2938 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2939 xoffset
+= texImage
->Border
;
2940 yoffset
+= texImage
->Border
;
2942 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2944 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2945 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2946 x
, y
, width
, height
);
2948 check_gen_mipmap(ctx
, target
, texObj
, level
);
2950 ctx
->NewState
|= _NEW_TEXTURE
;
2954 _mesa_unlock_texture(ctx
, texObj
);
2960 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2961 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2962 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2964 struct gl_texture_unit
*texUnit
;
2965 struct gl_texture_object
*texObj
;
2966 struct gl_texture_image
*texImage
;
2967 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2968 GET_CURRENT_CONTEXT(ctx
);
2969 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2971 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2972 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
2973 _mesa_lookup_enum_by_nr(target
),
2974 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2976 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2977 _mesa_update_state(ctx
);
2979 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2982 texUnit
= _mesa_get_current_tex_unit(ctx
);
2983 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2985 _mesa_lock_texture(ctx
, texObj
);
2987 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2989 #if FEATURE_convolve
2990 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2991 _mesa_adjust_image_for_convolution(ctx
, 2,
2992 &postConvWidth
, &postConvHeight
);
2996 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2997 zoffset
, postConvWidth
, postConvHeight
,
2999 /* error was recored */
3002 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3003 xoffset
+= texImage
->Border
;
3004 yoffset
+= texImage
->Border
;
3005 zoffset
+= texImage
->Border
;
3007 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3009 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3010 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3011 xoffset
, yoffset
, zoffset
,
3012 x
, y
, width
, height
);
3014 check_gen_mipmap(ctx
, target
, texObj
, level
);
3016 ctx
->NewState
|= _NEW_TEXTURE
;
3020 _mesa_unlock_texture(ctx
, texObj
);
3026 /**********************************************************************/
3027 /****** Compressed Textures ******/
3028 /**********************************************************************/
3032 * Error checking for glCompressedTexImage[123]D().
3033 * \return error code or GL_NO_ERROR.
3036 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3037 GLenum target
, GLint level
,
3038 GLenum internalFormat
, GLsizei width
,
3039 GLsizei height
, GLsizei depth
, GLint border
,
3042 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3044 if (dimensions
== 1) {
3045 /* 1D compressed textures not allowed */
3046 return GL_INVALID_ENUM
;
3048 else if (dimensions
== 2) {
3049 if (target
== GL_PROXY_TEXTURE_2D
) {
3050 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3052 else if (target
== GL_TEXTURE_2D
) {
3053 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3055 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3056 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3057 return GL_INVALID_ENUM
; /*target*/
3058 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3060 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3061 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3062 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3063 return GL_INVALID_ENUM
; /*target*/
3064 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3067 return GL_INVALID_ENUM
; /*target*/
3070 else if (dimensions
== 3) {
3071 /* 3D compressed textures not allowed */
3072 return GL_INVALID_ENUM
;
3075 maxTextureSize
= 1 << (maxLevels
- 1);
3077 /* This will detect any invalid internalFormat value */
3078 if (!is_compressed_format(ctx
, internalFormat
))
3079 return GL_INVALID_ENUM
;
3081 /* This should really never fail */
3082 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3083 return GL_INVALID_ENUM
;
3086 return GL_INVALID_VALUE
;
3089 * XXX We should probably use the proxy texture error check function here.
3091 if (width
< 1 || width
> maxTextureSize
||
3092 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3093 return GL_INVALID_VALUE
;
3095 if ((height
< 1 || height
> maxTextureSize
||
3096 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3098 return GL_INVALID_VALUE
;
3100 if ((depth
< 1 || depth
> maxTextureSize
||
3101 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3103 return GL_INVALID_VALUE
;
3105 /* For cube map, width must equal height */
3106 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3107 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3108 return GL_INVALID_VALUE
;
3110 if (level
< 0 || level
>= maxLevels
)
3111 return GL_INVALID_VALUE
;
3113 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3114 depth
, internalFormat
);
3115 if (expectedSize
!= imageSize
)
3116 return GL_INVALID_VALUE
;
3118 #if FEATURE_EXT_texture_sRGB
3119 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3120 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3121 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3122 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3124 return GL_INVALID_OPERATION
;
3133 * Error checking for glCompressedTexSubImage[123]D().
3134 * \warning There are some bad assumptions here about the size of compressed
3135 * texture tiles (multiple of 4) used to test the validity of the
3136 * offset and size parameters.
3137 * \return error code or GL_NO_ERROR.
3140 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3141 GLenum target
, GLint level
,
3142 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3143 GLsizei width
, GLsizei height
, GLsizei depth
,
3144 GLenum format
, GLsizei imageSize
)
3146 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3149 if (dimensions
== 1) {
3150 /* 1D compressed textures not allowed */
3151 return GL_INVALID_ENUM
;
3153 else if (dimensions
== 2) {
3154 if (target
== GL_PROXY_TEXTURE_2D
) {
3155 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3157 else if (target
== GL_TEXTURE_2D
) {
3158 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3160 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3161 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3162 return GL_INVALID_ENUM
; /*target*/
3163 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3165 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3166 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3167 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3168 return GL_INVALID_ENUM
; /*target*/
3169 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3172 return GL_INVALID_ENUM
; /*target*/
3175 else if (dimensions
== 3) {
3176 /* 3D compressed textures not allowed */
3177 return GL_INVALID_ENUM
;
3180 maxTextureSize
= 1 << (maxLevels
- 1);
3182 /* this will catch any invalid compressed format token */
3183 if (!is_compressed_format(ctx
, format
))
3184 return GL_INVALID_ENUM
;
3186 if (width
< 1 || width
> maxTextureSize
)
3187 return GL_INVALID_VALUE
;
3189 if ((height
< 1 || height
> maxTextureSize
)
3191 return GL_INVALID_VALUE
;
3193 if (level
< 0 || level
>= maxLevels
)
3194 return GL_INVALID_VALUE
;
3196 /* XXX these tests are specific to the compressed format.
3197 * this code should be generalized in some way.
3199 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3200 return GL_INVALID_VALUE
;
3202 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3203 return GL_INVALID_VALUE
;
3205 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3206 return GL_INVALID_VALUE
;
3208 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3210 if (expectedSize
!= imageSize
)
3211 return GL_INVALID_VALUE
;
3219 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3220 GLenum internalFormat
, GLsizei width
,
3221 GLint border
, GLsizei imageSize
,
3224 GET_CURRENT_CONTEXT(ctx
);
3225 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3227 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3228 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3229 _mesa_lookup_enum_by_nr(target
), level
,
3230 _mesa_lookup_enum_by_nr(internalFormat
),
3231 width
, border
, imageSize
, data
);
3233 if (target
== GL_TEXTURE_1D
) {
3234 /* non-proxy target */
3235 struct gl_texture_unit
*texUnit
;
3236 struct gl_texture_object
*texObj
;
3237 struct gl_texture_image
*texImage
;
3238 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3239 internalFormat
, width
, 1, 1, border
, imageSize
);
3241 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3245 texUnit
= _mesa_get_current_tex_unit(ctx
);
3246 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3248 _mesa_lock_texture(ctx
, texObj
);
3250 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3252 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3255 if (texImage
->Data
) {
3256 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3258 ASSERT(texImage
->Data
== NULL
);
3260 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3261 border
, internalFormat
);
3263 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3264 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3265 internalFormat
, width
, border
,
3269 check_gen_mipmap(ctx
, target
, texObj
, level
);
3272 texObj
->_Complete
= GL_FALSE
;
3273 ctx
->NewState
|= _NEW_TEXTURE
;
3276 _mesa_unlock_texture(ctx
, texObj
);
3278 else if (target
== GL_PROXY_TEXTURE_1D
) {
3279 /* Proxy texture: check for errors and update proxy state */
3280 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3281 internalFormat
, width
, 1, 1, border
, imageSize
);
3283 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3284 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3285 internalFormat
, GL_NONE
, GL_NONE
,
3286 width
, 1, 1, border
);
3289 /* if error, clear all proxy texture image parameters */
3290 struct gl_texture_image
*texImage
;
3291 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3293 clear_teximage_fields(texImage
);
3296 /* store the teximage parameters */
3297 struct gl_texture_unit
*texUnit
;
3298 struct gl_texture_object
*texObj
;
3299 struct gl_texture_image
*texImage
;
3300 texUnit
= _mesa_get_current_tex_unit(ctx
);
3301 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3303 _mesa_lock_texture(ctx
, texObj
);
3305 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3306 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3307 border
, internalFormat
);
3309 _mesa_unlock_texture(ctx
, texObj
);
3313 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3320 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3321 GLenum internalFormat
, GLsizei width
,
3322 GLsizei height
, GLint border
, GLsizei imageSize
,
3325 GET_CURRENT_CONTEXT(ctx
);
3326 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3328 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3329 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3330 _mesa_lookup_enum_by_nr(target
), level
,
3331 _mesa_lookup_enum_by_nr(internalFormat
),
3332 width
, height
, border
, imageSize
, data
);
3334 if (target
== GL_TEXTURE_2D
||
3335 (ctx
->Extensions
.ARB_texture_cube_map
&&
3336 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3337 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3338 /* non-proxy target */
3339 struct gl_texture_unit
*texUnit
;
3340 struct gl_texture_object
*texObj
;
3341 struct gl_texture_image
*texImage
;
3342 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3343 internalFormat
, width
, height
, 1, border
, imageSize
);
3345 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3349 texUnit
= _mesa_get_current_tex_unit(ctx
);
3350 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3352 _mesa_lock_texture(ctx
, texObj
);
3354 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3356 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3359 if (texImage
->Data
) {
3360 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3362 ASSERT(texImage
->Data
== NULL
);
3364 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3365 border
, internalFormat
);
3367 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3368 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3369 internalFormat
, width
, height
,
3370 border
, imageSize
, data
,
3373 check_gen_mipmap(ctx
, target
, texObj
, level
);
3376 texObj
->_Complete
= GL_FALSE
;
3377 ctx
->NewState
|= _NEW_TEXTURE
;
3380 _mesa_unlock_texture(ctx
, texObj
);
3382 else if (target
== GL_PROXY_TEXTURE_2D
||
3383 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3384 ctx
->Extensions
.ARB_texture_cube_map
)) {
3385 /* Proxy texture: check for errors and update proxy state */
3386 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3387 internalFormat
, width
, height
, 1, border
, imageSize
);
3389 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3390 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3391 internalFormat
, GL_NONE
, GL_NONE
,
3392 width
, height
, 1, border
);
3395 /* if error, clear all proxy texture image parameters */
3396 struct gl_texture_image
*texImage
;
3397 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3399 clear_teximage_fields(texImage
);
3402 /* store the teximage parameters */
3403 struct gl_texture_unit
*texUnit
;
3404 struct gl_texture_object
*texObj
;
3405 struct gl_texture_image
*texImage
;
3406 texUnit
= _mesa_get_current_tex_unit(ctx
);
3407 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3409 _mesa_lock_texture(ctx
, texObj
);
3411 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3412 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3413 border
, internalFormat
);
3415 _mesa_unlock_texture(ctx
, texObj
);
3419 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3426 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3427 GLenum internalFormat
, GLsizei width
,
3428 GLsizei height
, GLsizei depth
, GLint border
,
3429 GLsizei imageSize
, const GLvoid
*data
)
3431 GET_CURRENT_CONTEXT(ctx
);
3432 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3434 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3435 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3436 _mesa_lookup_enum_by_nr(target
), level
,
3437 _mesa_lookup_enum_by_nr(internalFormat
),
3438 width
, height
, depth
, border
, imageSize
, data
);
3440 if (target
== GL_TEXTURE_3D
) {
3441 /* non-proxy target */
3442 struct gl_texture_unit
*texUnit
;
3443 struct gl_texture_object
*texObj
;
3444 struct gl_texture_image
*texImage
;
3445 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3446 internalFormat
, width
, height
, depth
, border
, imageSize
);
3448 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3452 texUnit
= _mesa_get_current_tex_unit(ctx
);
3453 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3454 _mesa_lock_texture(ctx
, texObj
);
3456 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3458 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3461 if (texImage
->Data
) {
3462 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3464 ASSERT(texImage
->Data
== NULL
);
3466 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3467 width
, height
, depth
,
3468 border
, internalFormat
);
3470 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3471 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3473 width
, height
, depth
,
3474 border
, imageSize
, data
,
3477 check_gen_mipmap(ctx
, target
, texObj
, level
);
3480 texObj
->_Complete
= GL_FALSE
;
3481 ctx
->NewState
|= _NEW_TEXTURE
;
3484 _mesa_unlock_texture(ctx
, texObj
);
3486 else if (target
== GL_PROXY_TEXTURE_3D
) {
3487 /* Proxy texture: check for errors and update proxy state */
3488 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3489 internalFormat
, width
, height
, depth
, border
, imageSize
);
3491 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3492 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3493 internalFormat
, GL_NONE
, GL_NONE
,
3494 width
, height
, depth
, border
);
3497 /* if error, clear all proxy texture image parameters */
3498 struct gl_texture_image
*texImage
;
3499 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3501 clear_teximage_fields(texImage
);
3504 /* store the teximage parameters */
3505 struct gl_texture_unit
*texUnit
;
3506 struct gl_texture_object
*texObj
;
3507 struct gl_texture_image
*texImage
;
3508 texUnit
= _mesa_get_current_tex_unit(ctx
);
3509 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3510 _mesa_lock_texture(ctx
, texObj
);
3512 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3513 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3514 depth
, border
, internalFormat
);
3516 _mesa_unlock_texture(ctx
, texObj
);
3520 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3527 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3528 GLsizei width
, GLenum format
,
3529 GLsizei imageSize
, const GLvoid
*data
)
3531 struct gl_texture_unit
*texUnit
;
3532 struct gl_texture_object
*texObj
;
3533 struct gl_texture_image
*texImage
;
3535 GET_CURRENT_CONTEXT(ctx
);
3536 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3538 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3539 xoffset
, 0, 0, /* pos */
3540 width
, 1, 1, /* size */
3543 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3547 texUnit
= _mesa_get_current_tex_unit(ctx
);
3548 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3550 _mesa_lock_texture(ctx
, texObj
);
3552 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3555 if ((GLint
) format
!= texImage
->InternalFormat
) {
3556 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3557 "glCompressedTexSubImage1D(format)");
3559 else if ((width
== 1 || width
== 2) &&
3560 (GLuint
) width
!= texImage
->Width
) {
3561 _mesa_error(ctx
, GL_INVALID_VALUE
,
3562 "glCompressedTexSubImage1D(width)");
3564 else if (width
> 0) {
3565 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3566 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3568 format
, imageSize
, data
,
3572 check_gen_mipmap(ctx
, target
, texObj
, level
);
3574 ctx
->NewState
|= _NEW_TEXTURE
;
3577 _mesa_unlock_texture(ctx
, texObj
);
3582 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3583 GLint yoffset
, GLsizei width
, GLsizei height
,
3584 GLenum format
, GLsizei imageSize
,
3587 struct gl_texture_unit
*texUnit
;
3588 struct gl_texture_object
*texObj
;
3589 struct gl_texture_image
*texImage
;
3591 GET_CURRENT_CONTEXT(ctx
);
3592 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3594 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3595 xoffset
, yoffset
, 0, /* pos */
3596 width
, height
, 1, /* size */
3599 /* XXX proxy target? */
3600 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3604 texUnit
= _mesa_get_current_tex_unit(ctx
);
3605 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3607 _mesa_lock_texture(ctx
, texObj
);
3609 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3612 if ((GLint
) format
!= texImage
->InternalFormat
) {
3613 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3614 "glCompressedTexSubImage2D(format)");
3616 else if (((width
== 1 || width
== 2)
3617 && (GLuint
) width
!= texImage
->Width
) ||
3618 ((height
== 1 || height
== 2)
3619 && (GLuint
) height
!= texImage
->Height
)) {
3620 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3622 else if (width
> 0 && height
> 0) {
3623 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3624 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3625 xoffset
, yoffset
, width
, height
,
3626 format
, imageSize
, data
,
3630 check_gen_mipmap(ctx
, target
, texObj
, level
);
3632 ctx
->NewState
|= _NEW_TEXTURE
;
3635 _mesa_unlock_texture(ctx
, texObj
);
3640 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3641 GLint yoffset
, GLint zoffset
, GLsizei width
,
3642 GLsizei height
, GLsizei depth
, GLenum format
,
3643 GLsizei imageSize
, const GLvoid
*data
)
3645 struct gl_texture_unit
*texUnit
;
3646 struct gl_texture_object
*texObj
;
3647 struct gl_texture_image
*texImage
;
3649 GET_CURRENT_CONTEXT(ctx
);
3650 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3652 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3653 xoffset
, yoffset
, zoffset
,/*pos*/
3654 width
, height
, depth
, /*size*/
3657 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3661 texUnit
= _mesa_get_current_tex_unit(ctx
);
3662 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3664 _mesa_lock_texture(ctx
, texObj
);
3666 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3669 if ((GLint
) format
!= texImage
->InternalFormat
) {
3670 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3671 "glCompressedTexSubImage3D(format)");
3673 else if (((width
== 1 || width
== 2)
3674 && (GLuint
) width
!= texImage
->Width
) ||
3675 ((height
== 1 || height
== 2)
3676 && (GLuint
) height
!= texImage
->Height
) ||
3677 ((depth
== 1 || depth
== 2)
3678 && (GLuint
) depth
!= texImage
->Depth
)) {
3679 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3681 else if (width
> 0 && height
> 0 && depth
> 0) {
3682 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3683 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3684 xoffset
, yoffset
, zoffset
,
3685 width
, height
, depth
,
3686 format
, imageSize
, data
,
3690 check_gen_mipmap(ctx
, target
, texObj
, level
);
3692 ctx
->NewState
|= _NEW_TEXTURE
;
3695 _mesa_unlock_texture(ctx
, texObj
);