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
);
2079 /** Debug helper: override the user-requested internal format */
2081 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2084 if (internalFormat
== GL_RGBA16F_ARB
||
2085 internalFormat
== GL_RGBA32F_ARB
) {
2086 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2089 else if (internalFormat
== GL_RGB16F_ARB
||
2090 internalFormat
== GL_RGB32F_ARB
) {
2091 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2094 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2095 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2096 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2097 return GL_LUMINANCE_ALPHA
;
2099 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2100 internalFormat
== GL_LUMINANCE32F_ARB
) {
2101 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2102 return GL_LUMINANCE
;
2104 else if (internalFormat
== GL_ALPHA16F_ARB
||
2105 internalFormat
== GL_ALPHA32F_ARB
) {
2106 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2110 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2111 internalFormat = GL_RGBA;
2115 return internalFormat
;
2118 return internalFormat
;
2124 * Called from the API. Note that width includes the border.
2127 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2128 GLsizei width
, GLint border
, GLenum format
,
2129 GLenum type
, const GLvoid
*pixels
)
2131 GLsizei postConvWidth
= width
;
2132 GET_CURRENT_CONTEXT(ctx
);
2133 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2135 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2136 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2137 _mesa_lookup_enum_by_nr(target
), level
,
2138 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2139 _mesa_lookup_enum_by_nr(format
),
2140 _mesa_lookup_enum_by_nr(type
), pixels
);
2142 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2144 #if FEATURE_convolve
2145 if (_mesa_is_color_format(internalFormat
)) {
2146 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2150 if (target
== GL_TEXTURE_1D
) {
2151 /* non-proxy target */
2152 struct gl_texture_unit
*texUnit
;
2153 struct gl_texture_object
*texObj
;
2154 struct gl_texture_image
*texImage
;
2155 const GLuint face
= _mesa_tex_target_to_face(target
);
2157 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2158 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2159 return; /* error was recorded */
2162 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2163 _mesa_update_state(ctx
);
2165 texUnit
= _mesa_get_current_tex_unit(ctx
);
2166 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2167 _mesa_lock_texture(ctx
, texObj
);
2169 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2171 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2175 if (texImage
->Data
) {
2176 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2179 ASSERT(texImage
->Data
== NULL
);
2181 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2182 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2183 postConvWidth
, 1, 1,
2184 border
, internalFormat
);
2186 ASSERT(ctx
->Driver
.TexImage1D
);
2188 /* Give the texture to the driver! <pixels> may be null! */
2189 (*ctx
->Driver
.TexImage1D
)(ctx
, target
, level
, internalFormat
,
2190 width
, border
, format
, type
, pixels
,
2191 &ctx
->Unpack
, texObj
, texImage
);
2193 ASSERT(texImage
->TexFormat
);
2195 update_fbo_texture(ctx
, texObj
, face
, level
);
2198 texObj
->_Complete
= GL_FALSE
;
2199 ctx
->NewState
|= _NEW_TEXTURE
;
2202 _mesa_unlock_texture(ctx
, texObj
);
2204 else if (target
== GL_PROXY_TEXTURE_1D
) {
2205 /* Proxy texture: check for errors and update proxy state */
2206 struct gl_texture_image
*texImage
;
2207 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2208 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2209 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2210 /* when error, clear all proxy texture image parameters */
2212 clear_teximage_fields(texImage
);
2215 /* no error, set the tex image parameters */
2217 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2218 postConvWidth
, 1, 1,
2219 border
, internalFormat
);
2220 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2221 internalFormat
, format
, type
);
2225 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2232 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2233 GLsizei width
, GLsizei height
, GLint border
,
2234 GLenum format
, GLenum type
,
2235 const GLvoid
*pixels
)
2237 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2238 GET_CURRENT_CONTEXT(ctx
);
2239 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2241 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2242 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2243 _mesa_lookup_enum_by_nr(target
), level
,
2244 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2245 border
, _mesa_lookup_enum_by_nr(format
),
2246 _mesa_lookup_enum_by_nr(type
), pixels
);
2248 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2250 #if FEATURE_convolve
2251 if (_mesa_is_color_format(internalFormat
)) {
2252 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2257 if (target
== GL_TEXTURE_2D
||
2258 (ctx
->Extensions
.ARB_texture_cube_map
&&
2259 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2260 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2261 (ctx
->Extensions
.NV_texture_rectangle
&&
2262 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2263 (ctx
->Extensions
.MESA_texture_array
&&
2264 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2265 /* non-proxy target */
2266 struct gl_texture_unit
*texUnit
;
2267 struct gl_texture_object
*texObj
;
2268 struct gl_texture_image
*texImage
;
2269 const GLuint face
= _mesa_tex_target_to_face(target
);
2271 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2272 format
, type
, 2, postConvWidth
, postConvHeight
,
2274 return; /* error was recorded */
2277 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2278 _mesa_update_state(ctx
);
2280 texUnit
= _mesa_get_current_tex_unit(ctx
);
2281 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2282 _mesa_lock_texture(ctx
, texObj
);
2284 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2286 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2290 if (texImage
->Data
) {
2291 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2294 ASSERT(texImage
->Data
== NULL
);
2295 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2296 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2297 postConvWidth
, postConvHeight
, 1,
2298 border
, internalFormat
);
2300 ASSERT(ctx
->Driver
.TexImage2D
);
2302 /* Give the texture to the driver! <pixels> may be null! */
2303 (*ctx
->Driver
.TexImage2D
)(ctx
, target
, level
, internalFormat
,
2304 width
, height
, border
, format
, type
, pixels
,
2305 &ctx
->Unpack
, texObj
, texImage
);
2307 ASSERT(texImage
->TexFormat
);
2309 update_fbo_texture(ctx
, texObj
, face
, level
);
2312 texObj
->_Complete
= GL_FALSE
;
2313 ctx
->NewState
|= _NEW_TEXTURE
;
2316 _mesa_unlock_texture(ctx
, texObj
);
2318 else if (target
== GL_PROXY_TEXTURE_2D
||
2319 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2320 ctx
->Extensions
.ARB_texture_cube_map
) ||
2321 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2322 ctx
->Extensions
.NV_texture_rectangle
) ||
2323 (ctx
->Extensions
.MESA_texture_array
&&
2324 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2325 /* Proxy texture: check for errors and update proxy state */
2326 struct gl_texture_image
*texImage
;
2327 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2328 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2329 format
, type
, 2, postConvWidth
, postConvHeight
,
2331 /* when error, clear all proxy texture image parameters */
2333 clear_teximage_fields(texImage
);
2336 /* no error, set the tex image parameters */
2337 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2338 postConvWidth
, postConvHeight
, 1,
2339 border
, internalFormat
);
2340 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2341 internalFormat
, format
, type
);
2345 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2352 * Called by the API or display list executor.
2353 * Note that width and height include the border.
2356 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2357 GLsizei width
, GLsizei height
, GLsizei depth
,
2358 GLint border
, GLenum format
, GLenum type
,
2359 const GLvoid
*pixels
)
2361 GET_CURRENT_CONTEXT(ctx
);
2362 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2364 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2365 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2366 _mesa_lookup_enum_by_nr(target
), level
,
2367 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2368 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2369 _mesa_lookup_enum_by_nr(type
), pixels
);
2371 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2373 if (target
== GL_TEXTURE_3D
||
2374 (ctx
->Extensions
.MESA_texture_array
&&
2375 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2376 /* non-proxy target */
2377 struct gl_texture_unit
*texUnit
;
2378 struct gl_texture_object
*texObj
;
2379 struct gl_texture_image
*texImage
;
2380 const GLuint face
= _mesa_tex_target_to_face(target
);
2382 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2383 format
, type
, 3, width
, height
, depth
, border
)) {
2384 return; /* error was recorded */
2387 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2388 _mesa_update_state(ctx
);
2390 texUnit
= _mesa_get_current_tex_unit(ctx
);
2391 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2392 _mesa_lock_texture(ctx
, texObj
);
2394 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2396 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2400 if (texImage
->Data
) {
2401 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2404 ASSERT(texImage
->Data
== NULL
);
2405 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2406 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2407 width
, height
, depth
,
2408 border
, internalFormat
);
2410 ASSERT(ctx
->Driver
.TexImage3D
);
2412 /* Give the texture to the driver! <pixels> may be null! */
2413 (*ctx
->Driver
.TexImage3D
)(ctx
, target
, level
, internalFormat
,
2414 width
, height
, depth
, border
, format
, type
,
2415 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2417 ASSERT(texImage
->TexFormat
);
2419 update_fbo_texture(ctx
, texObj
, face
, level
);
2422 texObj
->_Complete
= GL_FALSE
;
2423 ctx
->NewState
|= _NEW_TEXTURE
;
2426 _mesa_unlock_texture(ctx
, texObj
);
2428 else if (target
== GL_PROXY_TEXTURE_3D
||
2429 (ctx
->Extensions
.MESA_texture_array
&&
2430 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2431 /* Proxy texture: check for errors and update proxy state */
2432 struct gl_texture_image
*texImage
;
2433 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2434 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2435 format
, type
, 3, width
, height
, depth
, border
)) {
2436 /* when error, clear all proxy texture image parameters */
2438 clear_teximage_fields(texImage
);
2441 /* no error, set the tex image parameters */
2442 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2443 depth
, border
, internalFormat
);
2444 texImage
->TexFormat
= (*ctx
->Driver
.ChooseTextureFormat
)(ctx
,
2445 internalFormat
, format
, type
);
2449 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2456 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2457 GLsizei width
, GLsizei height
, GLsizei depth
,
2458 GLint border
, GLenum format
, GLenum type
,
2459 const GLvoid
*pixels
)
2461 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2462 depth
, border
, format
, type
, pixels
);
2468 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2469 GLint xoffset
, GLsizei width
,
2470 GLenum format
, GLenum type
,
2471 const GLvoid
*pixels
)
2473 GLsizei postConvWidth
= width
;
2474 struct gl_texture_unit
*texUnit
;
2475 struct gl_texture_object
*texObj
;
2476 struct gl_texture_image
*texImage
= NULL
;
2477 GET_CURRENT_CONTEXT(ctx
);
2478 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2480 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2481 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2482 _mesa_lookup_enum_by_nr(target
), level
,
2483 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2484 _mesa_lookup_enum_by_nr(type
), pixels
);
2486 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2487 _mesa_update_state(ctx
);
2489 #if FEATURE_convolve
2490 /* XXX should test internal format */
2491 if (_mesa_is_color_format(format
)) {
2492 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2496 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2497 postConvWidth
, 1, 1, format
, type
)) {
2498 return; /* error was detected */
2502 texUnit
= _mesa_get_current_tex_unit(ctx
);
2503 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2506 _mesa_lock_texture(ctx
, texObj
);
2508 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2510 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2511 postConvWidth
, 1, 1, format
, type
, texImage
)) {
2512 goto out
; /* error was detected */
2516 goto out
; /* no-op, not an error */
2518 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2519 xoffset
+= texImage
->Border
;
2521 ASSERT(ctx
->Driver
.TexSubImage1D
);
2522 (*ctx
->Driver
.TexSubImage1D
)(ctx
, target
, level
, xoffset
, width
,
2523 format
, type
, pixels
, &ctx
->Unpack
,
2525 ctx
->NewState
|= _NEW_TEXTURE
;
2528 _mesa_unlock_texture(ctx
, texObj
);
2533 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2534 GLint xoffset
, GLint yoffset
,
2535 GLsizei width
, GLsizei height
,
2536 GLenum format
, GLenum type
,
2537 const GLvoid
*pixels
)
2539 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2540 struct gl_texture_unit
*texUnit
;
2541 struct gl_texture_object
*texObj
;
2542 struct gl_texture_image
*texImage
;
2543 GET_CURRENT_CONTEXT(ctx
);
2544 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2546 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2547 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2548 _mesa_lookup_enum_by_nr(target
), level
,
2549 xoffset
, yoffset
, width
, height
,
2550 _mesa_lookup_enum_by_nr(format
),
2551 _mesa_lookup_enum_by_nr(type
), pixels
);
2553 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2554 _mesa_update_state(ctx
);
2556 #if FEATURE_convolve
2557 /* XXX should test internal format */
2558 if (_mesa_is_color_format(format
)) {
2559 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2564 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2565 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2566 return; /* error was detected */
2569 texUnit
= _mesa_get_current_tex_unit(ctx
);
2570 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2571 _mesa_lock_texture(ctx
, texObj
);
2573 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2575 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2576 postConvWidth
, postConvHeight
, 1, format
, type
,
2578 goto out
; /* error was detected */
2581 if (width
== 0 || height
== 0)
2582 goto out
; /* no-op, not an error */
2584 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2585 xoffset
+= texImage
->Border
;
2586 yoffset
+= texImage
->Border
;
2588 ASSERT(ctx
->Driver
.TexSubImage2D
);
2589 (*ctx
->Driver
.TexSubImage2D
)(ctx
, target
, level
, xoffset
, yoffset
,
2590 width
, height
, format
, type
, pixels
,
2591 &ctx
->Unpack
, texObj
, texImage
);
2592 ctx
->NewState
|= _NEW_TEXTURE
;
2595 _mesa_unlock_texture(ctx
, texObj
);
2601 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2602 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2603 GLsizei width
, GLsizei height
, GLsizei depth
,
2604 GLenum format
, GLenum type
,
2605 const GLvoid
*pixels
)
2607 struct gl_texture_unit
*texUnit
;
2608 struct gl_texture_object
*texObj
;
2609 struct gl_texture_image
*texImage
;
2610 GET_CURRENT_CONTEXT(ctx
);
2611 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2613 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2614 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2615 _mesa_lookup_enum_by_nr(target
), level
,
2616 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2617 _mesa_lookup_enum_by_nr(format
),
2618 _mesa_lookup_enum_by_nr(type
), pixels
);
2620 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2621 _mesa_update_state(ctx
);
2623 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2624 width
, height
, depth
, format
, type
)) {
2625 return; /* error was detected */
2628 texUnit
= _mesa_get_current_tex_unit(ctx
);
2629 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2631 _mesa_lock_texture(ctx
, texObj
);
2633 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2635 if (subtexture_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2636 width
, height
, depth
, format
, type
, texImage
)) {
2637 goto out
; /* error was detected */
2640 if (width
== 0 || height
== 0 || height
== 0)
2641 goto out
; /* no-op, not an error */
2643 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2644 xoffset
+= texImage
->Border
;
2645 yoffset
+= texImage
->Border
;
2646 zoffset
+= texImage
->Border
;
2648 ASSERT(ctx
->Driver
.TexSubImage3D
);
2649 (*ctx
->Driver
.TexSubImage3D
)(ctx
, target
, level
,
2650 xoffset
, yoffset
, zoffset
,
2651 width
, height
, depth
,
2652 format
, type
, pixels
,
2653 &ctx
->Unpack
, texObj
, texImage
);
2654 ctx
->NewState
|= _NEW_TEXTURE
;
2657 _mesa_unlock_texture(ctx
, texObj
);
2663 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2664 GLenum internalFormat
,
2666 GLsizei width
, GLint border
)
2668 struct gl_texture_unit
*texUnit
;
2669 struct gl_texture_object
*texObj
;
2670 struct gl_texture_image
*texImage
;
2671 GLsizei postConvWidth
= width
;
2672 const GLuint face
= _mesa_tex_target_to_face(target
);
2673 GET_CURRENT_CONTEXT(ctx
);
2674 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2676 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2677 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2678 _mesa_lookup_enum_by_nr(target
), level
,
2679 _mesa_lookup_enum_by_nr(internalFormat
),
2680 x
, y
, width
, border
);
2682 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2683 _mesa_update_state(ctx
);
2685 #if FEATURE_convolve
2686 if (_mesa_is_color_format(internalFormat
)) {
2687 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2691 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2692 postConvWidth
, 1, border
))
2695 texUnit
= _mesa_get_current_tex_unit(ctx
);
2696 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2697 _mesa_lock_texture(ctx
, texObj
);
2699 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2701 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2705 if (texImage
->Data
) {
2706 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2709 ASSERT(texImage
->Data
== NULL
);
2711 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2712 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2713 border
, internalFormat
);
2716 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2717 (*ctx
->Driver
.CopyTexImage1D
)(ctx
, target
, level
, internalFormat
,
2718 x
, y
, width
, border
);
2720 ASSERT(texImage
->TexFormat
);
2722 update_fbo_texture(ctx
, texObj
, face
, level
);
2725 texObj
->_Complete
= GL_FALSE
;
2726 ctx
->NewState
|= _NEW_TEXTURE
;
2729 _mesa_unlock_texture(ctx
, texObj
);
2735 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2736 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2739 struct gl_texture_unit
*texUnit
;
2740 struct gl_texture_object
*texObj
;
2741 struct gl_texture_image
*texImage
;
2742 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2743 const GLuint face
= _mesa_tex_target_to_face(target
);
2744 GET_CURRENT_CONTEXT(ctx
);
2745 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2747 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2748 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2749 _mesa_lookup_enum_by_nr(target
), level
,
2750 _mesa_lookup_enum_by_nr(internalFormat
),
2751 x
, y
, width
, height
, border
);
2753 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2754 _mesa_update_state(ctx
);
2756 #if FEATURE_convolve
2757 if (_mesa_is_color_format(internalFormat
)) {
2758 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2763 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2764 postConvWidth
, postConvHeight
, border
))
2767 texUnit
= _mesa_get_current_tex_unit(ctx
);
2768 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2770 _mesa_lock_texture(ctx
, texObj
);
2772 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2775 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2779 if (texImage
->Data
) {
2780 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2783 ASSERT(texImage
->Data
== NULL
);
2785 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2786 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2787 postConvWidth
, postConvHeight
, 1,
2788 border
, internalFormat
);
2790 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2791 (*ctx
->Driver
.CopyTexImage2D
)(ctx
, target
, level
, internalFormat
,
2792 x
, y
, width
, height
, border
);
2794 ASSERT(texImage
->TexFormat
);
2796 update_fbo_texture(ctx
, texObj
, face
, level
);
2799 texObj
->_Complete
= GL_FALSE
;
2800 ctx
->NewState
|= _NEW_TEXTURE
;
2803 _mesa_unlock_texture(ctx
, texObj
);
2808 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2809 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2811 struct gl_texture_unit
*texUnit
;
2812 struct gl_texture_object
*texObj
;
2813 struct gl_texture_image
*texImage
;
2814 GLsizei postConvWidth
= width
;
2818 GET_CURRENT_CONTEXT(ctx
);
2819 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2821 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2822 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2823 _mesa_lookup_enum_by_nr(target
),
2824 level
, xoffset
, x
, y
, width
);
2826 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2827 _mesa_update_state(ctx
);
2829 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2832 texUnit
= _mesa_get_current_tex_unit(ctx
);
2833 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2835 _mesa_lock_texture(ctx
, texObj
);
2837 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2839 #if FEATURE_convolve
2840 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2841 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2845 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2846 xoffset
, 0, 0, postConvWidth
, 1,
2851 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2852 xoffset
+= texImage
->Border
;
2854 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2856 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2857 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2858 xoffset
, x
, y
, width
);
2861 ctx
->NewState
|= _NEW_TEXTURE
;
2864 _mesa_unlock_texture(ctx
, texObj
);
2870 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2871 GLint xoffset
, GLint yoffset
,
2872 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2874 struct gl_texture_unit
*texUnit
;
2875 struct gl_texture_object
*texObj
;
2876 struct gl_texture_image
*texImage
;
2877 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2878 GET_CURRENT_CONTEXT(ctx
);
2879 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2881 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2882 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2883 _mesa_lookup_enum_by_nr(target
),
2884 level
, xoffset
, yoffset
, x
, y
, width
, height
);
2886 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2887 _mesa_update_state(ctx
);
2889 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2892 texUnit
= _mesa_get_current_tex_unit(ctx
);
2893 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2895 _mesa_lock_texture(ctx
, texObj
);
2897 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2899 #if FEATURE_convolve
2900 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2901 _mesa_adjust_image_for_convolution(ctx
, 2,
2902 &postConvWidth
, &postConvHeight
);
2906 if (copytexsubimage_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2907 postConvWidth
, postConvHeight
, texImage
))
2910 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2911 xoffset
+= texImage
->Border
;
2912 yoffset
+= texImage
->Border
;
2914 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2916 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2917 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2918 xoffset
, yoffset
, x
, y
, width
, height
);
2921 ctx
->NewState
|= _NEW_TEXTURE
;
2924 _mesa_unlock_texture(ctx
, texObj
);
2930 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2931 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2932 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2934 struct gl_texture_unit
*texUnit
;
2935 struct gl_texture_object
*texObj
;
2936 struct gl_texture_image
*texImage
;
2937 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2938 GET_CURRENT_CONTEXT(ctx
);
2939 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2941 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2942 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
2943 _mesa_lookup_enum_by_nr(target
),
2944 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2946 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2947 _mesa_update_state(ctx
);
2949 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2952 texUnit
= _mesa_get_current_tex_unit(ctx
);
2953 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
2955 _mesa_lock_texture(ctx
, texObj
);
2957 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2959 #if FEATURE_convolve
2960 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2961 _mesa_adjust_image_for_convolution(ctx
, 2,
2962 &postConvWidth
, &postConvHeight
);
2966 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2967 zoffset
, postConvWidth
, postConvHeight
,
2971 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2972 xoffset
+= texImage
->Border
;
2973 yoffset
+= texImage
->Border
;
2974 zoffset
+= texImage
->Border
;
2976 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2978 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2979 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2980 xoffset
, yoffset
, zoffset
,
2981 x
, y
, width
, height
);
2984 ctx
->NewState
|= _NEW_TEXTURE
;
2987 _mesa_unlock_texture(ctx
, texObj
);
2993 /**********************************************************************/
2994 /****** Compressed Textures ******/
2995 /**********************************************************************/
2999 * Error checking for glCompressedTexImage[123]D().
3000 * \return error code or GL_NO_ERROR.
3003 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3004 GLenum target
, GLint level
,
3005 GLenum internalFormat
, GLsizei width
,
3006 GLsizei height
, GLsizei depth
, GLint border
,
3009 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3011 if (dimensions
== 1) {
3012 /* 1D compressed textures not allowed */
3013 return GL_INVALID_ENUM
;
3015 else if (dimensions
== 2) {
3016 if (target
== GL_PROXY_TEXTURE_2D
) {
3017 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3019 else if (target
== GL_TEXTURE_2D
) {
3020 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3022 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3023 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3024 return GL_INVALID_ENUM
; /*target*/
3025 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3027 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3028 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3029 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3030 return GL_INVALID_ENUM
; /*target*/
3031 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3034 return GL_INVALID_ENUM
; /*target*/
3037 else if (dimensions
== 3) {
3038 /* 3D compressed textures not allowed */
3039 return GL_INVALID_ENUM
;
3042 maxTextureSize
= 1 << (maxLevels
- 1);
3044 /* This will detect any invalid internalFormat value */
3045 if (!is_compressed_format(ctx
, internalFormat
))
3046 return GL_INVALID_ENUM
;
3048 /* This should really never fail */
3049 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3050 return GL_INVALID_ENUM
;
3053 return GL_INVALID_VALUE
;
3056 * XXX We should probably use the proxy texture error check function here.
3058 if (width
< 1 || width
> maxTextureSize
||
3059 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3060 return GL_INVALID_VALUE
;
3062 if ((height
< 1 || height
> maxTextureSize
||
3063 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3065 return GL_INVALID_VALUE
;
3067 if ((depth
< 1 || depth
> maxTextureSize
||
3068 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3070 return GL_INVALID_VALUE
;
3072 /* For cube map, width must equal height */
3073 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3074 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3075 return GL_INVALID_VALUE
;
3077 if (level
< 0 || level
>= maxLevels
)
3078 return GL_INVALID_VALUE
;
3080 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3081 depth
, internalFormat
);
3082 if (expectedSize
!= imageSize
)
3083 return GL_INVALID_VALUE
;
3085 #if FEATURE_EXT_texture_sRGB
3086 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3087 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3088 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3089 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3091 return GL_INVALID_OPERATION
;
3100 * Error checking for glCompressedTexSubImage[123]D().
3101 * \warning There are some bad assumptions here about the size of compressed
3102 * texture tiles (multiple of 4) used to test the validity of the
3103 * offset and size parameters.
3104 * \return error code or GL_NO_ERROR.
3107 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3108 GLenum target
, GLint level
,
3109 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3110 GLsizei width
, GLsizei height
, GLsizei depth
,
3111 GLenum format
, GLsizei imageSize
)
3113 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3116 if (dimensions
== 1) {
3117 /* 1D compressed textures not allowed */
3118 return GL_INVALID_ENUM
;
3120 else if (dimensions
== 2) {
3121 if (target
== GL_PROXY_TEXTURE_2D
) {
3122 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3124 else if (target
== GL_TEXTURE_2D
) {
3125 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3127 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3128 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3129 return GL_INVALID_ENUM
; /*target*/
3130 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3132 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3133 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3134 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3135 return GL_INVALID_ENUM
; /*target*/
3136 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3139 return GL_INVALID_ENUM
; /*target*/
3142 else if (dimensions
== 3) {
3143 /* 3D compressed textures not allowed */
3144 return GL_INVALID_ENUM
;
3147 maxTextureSize
= 1 << (maxLevels
- 1);
3149 /* this will catch any invalid compressed format token */
3150 if (!is_compressed_format(ctx
, format
))
3151 return GL_INVALID_ENUM
;
3153 if (width
< 1 || width
> maxTextureSize
)
3154 return GL_INVALID_VALUE
;
3156 if ((height
< 1 || height
> maxTextureSize
)
3158 return GL_INVALID_VALUE
;
3160 if (level
< 0 || level
>= maxLevels
)
3161 return GL_INVALID_VALUE
;
3163 /* XXX these tests are specific to the compressed format.
3164 * this code should be generalized in some way.
3166 if ((xoffset
& 3) != 0 || (yoffset
& 3) != 0)
3167 return GL_INVALID_VALUE
;
3169 if ((width
& 3) != 0 && width
!= 2 && width
!= 1)
3170 return GL_INVALID_VALUE
;
3172 if ((height
& 3) != 0 && height
!= 2 && height
!= 1)
3173 return GL_INVALID_VALUE
;
3175 expectedSize
= _mesa_compressed_texture_size_glenum(ctx
, width
, height
,
3177 if (expectedSize
!= imageSize
)
3178 return GL_INVALID_VALUE
;
3186 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3187 GLenum internalFormat
, GLsizei width
,
3188 GLint border
, GLsizei imageSize
,
3191 GET_CURRENT_CONTEXT(ctx
);
3192 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3194 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3195 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3196 _mesa_lookup_enum_by_nr(target
), level
,
3197 _mesa_lookup_enum_by_nr(internalFormat
),
3198 width
, border
, imageSize
, data
);
3200 if (target
== GL_TEXTURE_1D
) {
3201 /* non-proxy target */
3202 struct gl_texture_unit
*texUnit
;
3203 struct gl_texture_object
*texObj
;
3204 struct gl_texture_image
*texImage
;
3205 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3206 internalFormat
, width
, 1, 1, border
, imageSize
);
3208 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3212 texUnit
= _mesa_get_current_tex_unit(ctx
);
3213 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3215 _mesa_lock_texture(ctx
, texObj
);
3217 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3219 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3223 if (texImage
->Data
) {
3224 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3226 ASSERT(texImage
->Data
== NULL
);
3228 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3229 border
, internalFormat
);
3231 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3232 (*ctx
->Driver
.CompressedTexImage1D
)(ctx
, target
, level
,
3233 internalFormat
, width
, border
,
3238 texObj
->_Complete
= GL_FALSE
;
3239 ctx
->NewState
|= _NEW_TEXTURE
;
3242 _mesa_unlock_texture(ctx
, texObj
);
3244 else if (target
== GL_PROXY_TEXTURE_1D
) {
3245 /* Proxy texture: check for errors and update proxy state */
3246 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3247 internalFormat
, width
, 1, 1, border
, imageSize
);
3249 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3250 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3251 internalFormat
, GL_NONE
, GL_NONE
,
3252 width
, 1, 1, border
);
3255 /* if error, clear all proxy texture image parameters */
3256 struct gl_texture_image
*texImage
;
3257 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3259 clear_teximage_fields(texImage
);
3262 /* store the teximage parameters */
3263 struct gl_texture_unit
*texUnit
;
3264 struct gl_texture_object
*texObj
;
3265 struct gl_texture_image
*texImage
;
3266 texUnit
= _mesa_get_current_tex_unit(ctx
);
3267 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3269 _mesa_lock_texture(ctx
, texObj
);
3271 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3272 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3273 border
, internalFormat
);
3275 _mesa_unlock_texture(ctx
, texObj
);
3279 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3286 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3287 GLenum internalFormat
, GLsizei width
,
3288 GLsizei height
, GLint border
, GLsizei imageSize
,
3291 GET_CURRENT_CONTEXT(ctx
);
3292 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3294 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3295 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3296 _mesa_lookup_enum_by_nr(target
), level
,
3297 _mesa_lookup_enum_by_nr(internalFormat
),
3298 width
, height
, border
, imageSize
, data
);
3300 if (target
== GL_TEXTURE_2D
||
3301 (ctx
->Extensions
.ARB_texture_cube_map
&&
3302 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3303 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3304 /* non-proxy target */
3305 struct gl_texture_unit
*texUnit
;
3306 struct gl_texture_object
*texObj
;
3307 struct gl_texture_image
*texImage
;
3308 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3309 internalFormat
, width
, height
, 1, border
, imageSize
);
3311 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3315 texUnit
= _mesa_get_current_tex_unit(ctx
);
3316 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3318 _mesa_lock_texture(ctx
, texObj
);
3320 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3322 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3326 if (texImage
->Data
) {
3327 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3329 ASSERT(texImage
->Data
== NULL
);
3331 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3332 border
, internalFormat
);
3334 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3335 (*ctx
->Driver
.CompressedTexImage2D
)(ctx
, target
, level
,
3336 internalFormat
, width
, height
,
3337 border
, imageSize
, data
,
3341 texObj
->_Complete
= GL_FALSE
;
3342 ctx
->NewState
|= _NEW_TEXTURE
;
3345 _mesa_unlock_texture(ctx
, texObj
);
3347 else if (target
== GL_PROXY_TEXTURE_2D
||
3348 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3349 ctx
->Extensions
.ARB_texture_cube_map
)) {
3350 /* Proxy texture: check for errors and update proxy state */
3351 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3352 internalFormat
, width
, height
, 1, border
, imageSize
);
3354 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3355 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3356 internalFormat
, GL_NONE
, GL_NONE
,
3357 width
, height
, 1, border
);
3360 /* if error, clear all proxy texture image parameters */
3361 struct gl_texture_image
*texImage
;
3362 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3364 clear_teximage_fields(texImage
);
3367 /* store the teximage parameters */
3368 struct gl_texture_unit
*texUnit
;
3369 struct gl_texture_object
*texObj
;
3370 struct gl_texture_image
*texImage
;
3371 texUnit
= _mesa_get_current_tex_unit(ctx
);
3372 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3374 _mesa_lock_texture(ctx
, texObj
);
3376 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3377 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3378 border
, internalFormat
);
3380 _mesa_unlock_texture(ctx
, texObj
);
3384 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3391 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3392 GLenum internalFormat
, GLsizei width
,
3393 GLsizei height
, GLsizei depth
, GLint border
,
3394 GLsizei imageSize
, const GLvoid
*data
)
3396 GET_CURRENT_CONTEXT(ctx
);
3397 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3399 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3400 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3401 _mesa_lookup_enum_by_nr(target
), level
,
3402 _mesa_lookup_enum_by_nr(internalFormat
),
3403 width
, height
, depth
, border
, imageSize
, data
);
3405 if (target
== GL_TEXTURE_3D
) {
3406 /* non-proxy target */
3407 struct gl_texture_unit
*texUnit
;
3408 struct gl_texture_object
*texObj
;
3409 struct gl_texture_image
*texImage
;
3410 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3411 internalFormat
, width
, height
, depth
, border
, imageSize
);
3413 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3417 texUnit
= _mesa_get_current_tex_unit(ctx
);
3418 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3419 _mesa_lock_texture(ctx
, texObj
);
3421 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3423 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3427 if (texImage
->Data
) {
3428 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3430 ASSERT(texImage
->Data
== NULL
);
3432 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, depth
,
3433 border
, internalFormat
);
3435 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3436 (*ctx
->Driver
.CompressedTexImage3D
)(ctx
, target
, level
,
3438 width
, height
, depth
,
3439 border
, imageSize
, data
,
3443 texObj
->_Complete
= GL_FALSE
;
3444 ctx
->NewState
|= _NEW_TEXTURE
;
3447 _mesa_unlock_texture(ctx
, texObj
);
3449 else if (target
== GL_PROXY_TEXTURE_3D
) {
3450 /* Proxy texture: check for errors and update proxy state */
3451 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3452 internalFormat
, width
, height
, depth
, border
, imageSize
);
3454 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3455 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3456 internalFormat
, GL_NONE
, GL_NONE
,
3457 width
, height
, depth
, border
);
3460 /* if error, clear all proxy texture image parameters */
3461 struct gl_texture_image
*texImage
;
3462 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3464 clear_teximage_fields(texImage
);
3467 /* store the teximage parameters */
3468 struct gl_texture_unit
*texUnit
;
3469 struct gl_texture_object
*texObj
;
3470 struct gl_texture_image
*texImage
;
3471 texUnit
= _mesa_get_current_tex_unit(ctx
);
3472 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3473 _mesa_lock_texture(ctx
, texObj
);
3475 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3476 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3477 depth
, border
, internalFormat
);
3479 _mesa_unlock_texture(ctx
, texObj
);
3483 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3490 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3491 GLsizei width
, GLenum format
,
3492 GLsizei imageSize
, const GLvoid
*data
)
3494 struct gl_texture_unit
*texUnit
;
3495 struct gl_texture_object
*texObj
;
3496 struct gl_texture_image
*texImage
;
3498 GET_CURRENT_CONTEXT(ctx
);
3499 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3501 error
= compressed_subtexture_error_check(ctx
, 1, target
, level
,
3502 xoffset
, 0, 0, /* pos */
3503 width
, 1, 1, /* size */
3506 _mesa_error(ctx
, error
, "glCompressedTexSubImage1D");
3510 texUnit
= _mesa_get_current_tex_unit(ctx
);
3511 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3512 _mesa_lock_texture(ctx
, texObj
);
3514 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3517 if ((GLint
) format
!= texImage
->InternalFormat
) {
3518 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3519 "glCompressedTexSubImage1D(format)");
3523 if ((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) {
3524 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage1D(width)");
3529 goto out
; /* no-op, not an error */
3531 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3532 (*ctx
->Driver
.CompressedTexSubImage1D
)(ctx
, target
, level
,
3534 format
, imageSize
, data
,
3537 ctx
->NewState
|= _NEW_TEXTURE
;
3540 _mesa_unlock_texture(ctx
, texObj
);
3545 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3546 GLint yoffset
, GLsizei width
, GLsizei height
,
3547 GLenum format
, GLsizei imageSize
,
3550 struct gl_texture_unit
*texUnit
;
3551 struct gl_texture_object
*texObj
;
3552 struct gl_texture_image
*texImage
;
3554 GET_CURRENT_CONTEXT(ctx
);
3555 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3557 error
= compressed_subtexture_error_check(ctx
, 2, target
, level
,
3558 xoffset
, yoffset
, 0, /* pos */
3559 width
, height
, 1, /* size */
3562 /* XXX proxy target? */
3563 _mesa_error(ctx
, error
, "glCompressedTexSubImage2D");
3567 texUnit
= _mesa_get_current_tex_unit(ctx
);
3568 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3569 _mesa_lock_texture(ctx
, texObj
);
3571 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3574 if ((GLint
) format
!= texImage
->InternalFormat
) {
3575 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3576 "glCompressedTexSubImage2D(format)");
3580 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3581 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
)) {
3582 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage2D(size)");
3586 if (width
== 0 || height
== 0)
3587 goto out
; /* no-op, not an error */
3589 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3590 (*ctx
->Driver
.CompressedTexSubImage2D
)(ctx
, target
, level
,
3591 xoffset
, yoffset
, width
, height
,
3592 format
, imageSize
, data
,
3595 ctx
->NewState
|= _NEW_TEXTURE
;
3598 _mesa_unlock_texture(ctx
, texObj
);
3603 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3604 GLint yoffset
, GLint zoffset
, GLsizei width
,
3605 GLsizei height
, GLsizei depth
, GLenum format
,
3606 GLsizei imageSize
, const GLvoid
*data
)
3608 struct gl_texture_unit
*texUnit
;
3609 struct gl_texture_object
*texObj
;
3610 struct gl_texture_image
*texImage
;
3612 GET_CURRENT_CONTEXT(ctx
);
3613 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3615 error
= compressed_subtexture_error_check(ctx
, 3, target
, level
,
3616 xoffset
, yoffset
, zoffset
,/*pos*/
3617 width
, height
, depth
, /*size*/
3620 _mesa_error(ctx
, error
, "glCompressedTexSubImage3D");
3624 texUnit
= _mesa_get_current_tex_unit(ctx
);
3625 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
3626 _mesa_lock_texture(ctx
, texObj
);
3628 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3631 if ((GLint
) format
!= texImage
->InternalFormat
) {
3632 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3633 "glCompressedTexSubImage3D(format)");
3637 if (((width
== 1 || width
== 2) && (GLuint
) width
!= texImage
->Width
) ||
3638 ((height
== 1 || height
== 2) && (GLuint
) height
!= texImage
->Height
) ||
3639 ((depth
== 1 || depth
== 2) && (GLuint
) depth
!= texImage
->Depth
)) {
3640 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage3D(size)");
3644 if (width
== 0 || height
== 0 || depth
== 0)
3645 goto out
; /* no-op, not an error */
3647 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3648 (*ctx
->Driver
.CompressedTexSubImage3D
)(ctx
, target
, level
,
3649 xoffset
, yoffset
, zoffset
,
3650 width
, height
, depth
,
3651 format
, imageSize
, data
,
3654 ctx
->NewState
|= _NEW_TEXTURE
;
3657 _mesa_unlock_texture(ctx
, texObj
);