2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
39 #include "framebuffer.h"
45 #include "texcompress.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
65 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
69 _mesa_alloc_texmemory(GLsizei bytes
)
71 return _mesa_align_malloc(bytes
, 512);
76 * Free texture memory allocated with _mesa_alloc_texmemory()
79 _mesa_free_texmemory(void *m
)
86 * Compute floor(log_base_2(n)).
116 * Return the simple base format for a given internal texture format.
117 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
119 * \param ctx GL context.
120 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
122 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
123 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
125 * This is the format which is used during texture application (i.e. the
126 * texture format and env mode determine the arithmetic used.
128 * XXX this could be static
131 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
133 switch (internalFormat
) {
148 case GL_LUMINANCE_ALPHA
:
149 case GL_LUMINANCE4_ALPHA4
:
150 case GL_LUMINANCE6_ALPHA2
:
151 case GL_LUMINANCE8_ALPHA8
:
152 case GL_LUMINANCE12_ALPHA4
:
153 case GL_LUMINANCE12_ALPHA12
:
154 case GL_LUMINANCE16_ALPHA16
:
155 return GL_LUMINANCE_ALPHA
;
186 if (ctx
->Extensions
.EXT_paletted_texture
) {
187 switch (internalFormat
) {
189 case GL_COLOR_INDEX1_EXT
:
190 case GL_COLOR_INDEX2_EXT
:
191 case GL_COLOR_INDEX4_EXT
:
192 case GL_COLOR_INDEX8_EXT
:
193 case GL_COLOR_INDEX12_EXT
:
194 case GL_COLOR_INDEX16_EXT
:
195 return GL_COLOR_INDEX
;
201 if (ctx
->Extensions
.ARB_depth_texture
) {
202 switch (internalFormat
) {
203 case GL_DEPTH_COMPONENT
:
204 case GL_DEPTH_COMPONENT16
:
205 case GL_DEPTH_COMPONENT24
:
206 case GL_DEPTH_COMPONENT32
:
207 return GL_DEPTH_COMPONENT
;
213 switch (internalFormat
) {
214 case GL_COMPRESSED_ALPHA
:
216 case GL_COMPRESSED_LUMINANCE
:
218 case GL_COMPRESSED_LUMINANCE_ALPHA
:
219 return GL_LUMINANCE_ALPHA
;
220 case GL_COMPRESSED_INTENSITY
:
222 case GL_COMPRESSED_RGB
:
224 case GL_COMPRESSED_RGBA
:
230 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
231 switch (internalFormat
) {
232 case GL_COMPRESSED_RGB_FXT1_3DFX
:
234 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
241 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
242 switch (internalFormat
) {
243 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
245 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
246 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
247 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
254 if (ctx
->Extensions
.S3_s3tc
) {
255 switch (internalFormat
) {
267 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
268 if (internalFormat
== GL_YCBCR_MESA
)
269 return GL_YCBCR_MESA
;
272 if (ctx
->Extensions
.ARB_texture_float
) {
273 switch (internalFormat
) {
274 case GL_ALPHA16F_ARB
:
275 case GL_ALPHA32F_ARB
:
283 case GL_INTENSITY16F_ARB
:
284 case GL_INTENSITY32F_ARB
:
286 case GL_LUMINANCE16F_ARB
:
287 case GL_LUMINANCE32F_ARB
:
289 case GL_LUMINANCE_ALPHA16F_ARB
:
290 case GL_LUMINANCE_ALPHA32F_ARB
:
291 return GL_LUMINANCE_ALPHA
;
297 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
298 switch (internalFormat
) {
307 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
308 switch (internalFormat
) {
317 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
318 switch (internalFormat
) {
319 case GL_DEPTH_STENCIL_EXT
:
320 case GL_DEPTH24_STENCIL8_EXT
:
321 return GL_DEPTH_STENCIL_EXT
;
327 #if FEATURE_EXT_texture_sRGB
328 if (ctx
->Extensions
.EXT_texture_sRGB
) {
329 switch (internalFormat
) {
332 case GL_COMPRESSED_SRGB_EXT
:
333 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
335 case GL_SRGB_ALPHA_EXT
:
336 case GL_SRGB8_ALPHA8_EXT
:
337 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
338 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
339 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
340 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
342 case GL_SLUMINANCE_ALPHA_EXT
:
343 case GL_SLUMINANCE8_ALPHA8_EXT
:
344 case GL_COMPRESSED_SLUMINANCE_EXT
:
345 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
346 return GL_LUMINANCE_ALPHA
;
347 case GL_SLUMINANCE_EXT
:
348 case GL_SLUMINANCE8_EXT
:
355 #endif /* FEATURE_EXT_texture_sRGB */
357 return -1; /* error */
362 * Test if it is a supported compressed format.
364 * \param internalFormat the internal format token provided by the user.
366 * \ret GL_TRUE if \p internalFormat is a supported compressed format, or
367 * GL_FALSE otherwise.
369 * Currently only GL_COMPRESSED_RGB_FXT1_3DFX and GL_COMPRESSED_RGBA_FXT1_3DFX
373 is_compressed_format(GLcontext
*ctx
, GLenum internalFormat
)
375 GLint supported
[100]; /* 100 should be plenty */
378 n
= _mesa_get_compressed_formats(ctx
, supported
, GL_TRUE
);
380 for (i
= 0; i
< n
; i
++) {
381 if ((GLint
) internalFormat
== supported
[i
]) {
390 * For cube map faces, return a face index in [0,5].
391 * For other targets return 0;
394 _mesa_tex_target_to_face(GLenum target
)
396 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
397 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
398 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
406 * Store a gl_texture_image pointer in a gl_texture_object structure
407 * according to the target and level parameters.
409 * \param tObj texture object.
410 * \param target texture target.
411 * \param level image level.
412 * \param texImage texture image.
414 * This was basically prompted by the introduction of cube maps.
417 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
418 GLenum target
, GLint level
,
419 struct gl_texture_image
*texImage
)
421 const GLuint face
= _mesa_tex_target_to_face(target
);
425 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
427 tObj
->Image
[face
][level
] = texImage
;
429 /* Set the 'back' pointer */
430 texImage
->TexObject
= tObj
;
435 * Allocate a texture image structure.
437 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
440 * \return a pointer to gl_texture_image struct with all fields initialized to
443 struct gl_texture_image
*
444 _mesa_new_texture_image( GLcontext
*ctx
)
447 return CALLOC_STRUCT(gl_texture_image
);
452 * Free texture image data.
453 * This function is a fallback called via ctx->Driver.FreeTexImageData().
455 * \param texImage texture image.
457 * Free the texture image data if it's not marked as client data.
460 _mesa_free_texture_image_data(GLcontext
*ctx
,
461 struct gl_texture_image
*texImage
)
465 if (texImage
->Data
&& !texImage
->IsClientData
) {
466 /* free the old texture data */
467 _mesa_free_texmemory(texImage
->Data
);
470 texImage
->Data
= NULL
;
475 * Free texture image.
477 * \param texImage texture image.
479 * Free the texture image structure and the associated image data.
482 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
484 /* Free texImage->Data and/or any other driver-specific texture
487 ASSERT(ctx
->Driver
.FreeTexImageData
);
488 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
490 ASSERT(texImage
->Data
== NULL
);
491 if (texImage
->ImageOffsets
)
492 _mesa_free(texImage
->ImageOffsets
);
493 _mesa_free(texImage
);
498 * Test if a target is a proxy target.
500 * \param target texture target.
502 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
505 _mesa_is_proxy_texture(GLenum target
)
507 /* NUM_TEXTURE_TARGETS should match number of terms below */
508 assert(NUM_TEXTURE_TARGETS
== 7);
510 return (target
== GL_PROXY_TEXTURE_1D
||
511 target
== GL_PROXY_TEXTURE_2D
||
512 target
== GL_PROXY_TEXTURE_3D
||
513 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
514 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
515 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
516 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
521 * Get the texture object that corresponds to the target of the given texture unit.
523 * \param ctx GL context.
524 * \param texUnit texture unit.
525 * \param target texture target.
527 * \return pointer to the texture object on success, or NULL on failure.
529 * \sa gl_texture_unit.
531 struct gl_texture_object
*
532 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
537 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
538 case GL_PROXY_TEXTURE_1D
:
539 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
541 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
542 case GL_PROXY_TEXTURE_2D
:
543 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
545 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
546 case GL_PROXY_TEXTURE_3D
:
547 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
548 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
549 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
550 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
551 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
552 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
553 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
554 case GL_TEXTURE_CUBE_MAP_ARB
:
555 return ctx
->Extensions
.ARB_texture_cube_map
556 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
557 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
558 return ctx
->Extensions
.ARB_texture_cube_map
559 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
560 case GL_TEXTURE_RECTANGLE_NV
:
561 return ctx
->Extensions
.NV_texture_rectangle
562 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
563 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
564 return ctx
->Extensions
.NV_texture_rectangle
565 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
566 case GL_TEXTURE_1D_ARRAY_EXT
:
567 return ctx
->Extensions
.MESA_texture_array
568 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
569 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
570 return ctx
->Extensions
.MESA_texture_array
571 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
572 case GL_TEXTURE_2D_ARRAY_EXT
:
573 return ctx
->Extensions
.MESA_texture_array
574 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
575 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
576 return ctx
->Extensions
.MESA_texture_array
577 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
579 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
586 * Return pointer to texture object for given target on current texture unit.
588 struct gl_texture_object
*
589 _mesa_get_current_tex_object(GLcontext
*ctx
, GLenum target
)
591 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
592 return _mesa_select_tex_object(ctx
, texUnit
, target
);
597 * Get a texture image pointer from a texture object, given a texture
598 * target and mipmap level. The target and level parameters should
599 * have already been error-checked.
601 * \param ctx GL context.
602 * \param texObj texture unit.
603 * \param target texture target.
604 * \param level image level.
606 * \return pointer to the texture image structure, or NULL on failure.
608 struct gl_texture_image
*
609 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
610 GLenum target
, GLint level
)
612 const GLuint face
= _mesa_tex_target_to_face(target
);
616 ASSERT(level
< MAX_TEXTURE_LEVELS
);
618 return texObj
->Image
[face
][level
];
623 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
624 * it and install it. Only return NULL if passed a bad parameter or run
627 struct gl_texture_image
*
628 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
629 GLenum target
, GLint level
)
631 struct gl_texture_image
*texImage
;
636 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
638 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
640 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
644 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
652 * Return pointer to the specified proxy texture image.
653 * Note that proxy textures are per-context, not per-texture unit.
654 * \return pointer to texture image or NULL if invalid target, invalid
655 * level, or out of memory.
657 struct gl_texture_image
*
658 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
660 struct gl_texture_image
*texImage
;
667 case GL_PROXY_TEXTURE_1D
:
668 if (level
>= ctx
->Const
.MaxTextureLevels
)
670 texIndex
= TEXTURE_1D_INDEX
;
672 case GL_PROXY_TEXTURE_2D
:
673 if (level
>= ctx
->Const
.MaxTextureLevels
)
675 texIndex
= TEXTURE_2D_INDEX
;
677 case GL_PROXY_TEXTURE_3D
:
678 if (level
>= ctx
->Const
.Max3DTextureLevels
)
680 texIndex
= TEXTURE_3D_INDEX
;
682 case GL_PROXY_TEXTURE_CUBE_MAP
:
683 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
685 texIndex
= TEXTURE_CUBE_INDEX
;
687 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
690 texIndex
= TEXTURE_RECT_INDEX
;
692 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
693 if (level
>= ctx
->Const
.MaxTextureLevels
)
695 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
697 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
698 if (level
>= ctx
->Const
.MaxTextureLevels
)
700 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
706 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
708 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
710 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
713 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
714 /* Set the 'back' pointer */
715 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
722 * Get the maximum number of allowed mipmap levels.
724 * \param ctx GL context.
725 * \param target texture target.
727 * \return the maximum number of allowed mipmap levels for the given
728 * texture target, or zero if passed a bad target.
733 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
737 case GL_PROXY_TEXTURE_1D
:
739 case GL_PROXY_TEXTURE_2D
:
740 return ctx
->Const
.MaxTextureLevels
;
742 case GL_PROXY_TEXTURE_3D
:
743 return ctx
->Const
.Max3DTextureLevels
;
744 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
745 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
746 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
747 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
748 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
749 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
750 case GL_TEXTURE_CUBE_MAP_ARB
:
751 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
752 return ctx
->Extensions
.ARB_texture_cube_map
753 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
754 case GL_TEXTURE_RECTANGLE_NV
:
755 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
756 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
757 case GL_TEXTURE_1D_ARRAY_EXT
:
758 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
759 case GL_TEXTURE_2D_ARRAY_EXT
:
760 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
761 return ctx
->Extensions
.MESA_texture_array
762 ? ctx
->Const
.MaxTextureLevels
: 0;
764 return 0; /* bad target */
770 #if 000 /* not used anymore */
772 * glTexImage[123]D can accept a NULL image pointer. In this case we
773 * create a texture image with unspecified image contents per the OpenGL
777 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
779 const GLint components
= _mesa_components_in_format(format
);
780 const GLint numPixels
= width
* height
* depth
;
781 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
785 * Let's see if anyone finds this. If glTexImage2D() is called with
786 * a NULL image pointer then load the texture image with something
787 * interesting instead of leaving it indeterminate.
790 static const char message
[8][32] = {
794 " X X XXXX XXX XXXXX ",
797 " X X XXXXX XXX X X ",
801 GLubyte
*imgPtr
= data
;
803 for (h
= 0; h
< depth
; h
++) {
804 for (i
= 0; i
< height
; i
++) {
805 GLint srcRow
= 7 - (i
% 8);
806 for (j
= 0; j
< width
; j
++) {
807 GLint srcCol
= j
% 32;
808 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
809 for (k
= 0; k
< components
; k
++) {
825 * Reset the fields of a gl_texture_image struct to zero.
827 * \param img texture image structure.
829 * This is called when a proxy texture test fails, we set all the
830 * image members (except DriverData) to zero.
831 * It's also used in glTexImage[123]D as a safeguard to be sure all
832 * required fields get initialized properly by the Driver.TexImage[123]D
836 clear_teximage_fields(struct gl_texture_image
*img
)
839 img
->_BaseFormat
= 0;
840 img
->InternalFormat
= 0;
846 if (img
->ImageOffsets
) {
847 _mesa_free(img
->ImageOffsets
);
848 img
->ImageOffsets
= NULL
;
857 img
->TexFormat
= MESA_FORMAT_NONE
;
858 img
->FetchTexelc
= NULL
;
859 img
->FetchTexelf
= NULL
;
864 * Initialize basic fields of the gl_texture_image struct.
866 * \param ctx GL context.
867 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
868 * \param img texture image structure to be initialized.
869 * \param width image width.
870 * \param height image height.
871 * \param depth image depth.
872 * \param border image border.
873 * \param internalFormat internal format.
875 * Fills in the fields of \p img with the given information.
876 * Note: width, height and depth include the border.
879 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
880 struct gl_texture_image
*img
,
881 GLsizei width
, GLsizei height
, GLsizei depth
,
882 GLint border
, GLenum internalFormat
)
891 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
892 ASSERT(img
->_BaseFormat
> 0);
893 img
->InternalFormat
= internalFormat
;
894 img
->Border
= border
;
896 img
->Height
= height
;
899 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
900 img
->WidthLog2
= logbase2(img
->Width2
);
902 if (height
== 1) { /* 1-D texture */
907 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
908 img
->HeightLog2
= logbase2(img
->Height2
);
911 if (depth
== 1) { /* 2-D texture */
916 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
917 img
->DepthLog2
= logbase2(img
->Depth2
);
920 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
922 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
923 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
924 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
925 img
->_IsPowerOfTwo
= GL_TRUE
;
927 img
->_IsPowerOfTwo
= GL_FALSE
;
929 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
930 img
->RowStride
= width
;
931 /* Allocate the ImageOffsets array and initialize to typical values.
932 * We allocate the array for 1D/2D textures too in order to avoid special-
933 * case code in the texstore routines.
935 if (img
->ImageOffsets
)
936 _mesa_free(img
->ImageOffsets
);
937 img
->ImageOffsets
= (GLuint
*) _mesa_malloc(depth
* sizeof(GLuint
));
938 for (i
= 0; i
< depth
; i
++) {
939 img
->ImageOffsets
[i
] = i
* width
* height
;
942 /* Compute Width/Height/DepthScale for mipmap lod computation */
943 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
944 /* scale = 1.0 since texture coords directly map to texels */
945 img
->WidthScale
= 1.0;
946 img
->HeightScale
= 1.0;
947 img
->DepthScale
= 1.0;
950 img
->WidthScale
= (GLfloat
) img
->Width
;
951 img
->HeightScale
= (GLfloat
) img
->Height
;
952 img
->DepthScale
= (GLfloat
) img
->Depth
;
955 img
->FetchTexelc
= NULL
;
956 img
->FetchTexelf
= NULL
;
961 * Free and clear fields of the gl_texture_image struct.
963 * \param ctx GL context.
964 * \param texImage texture image structure to be cleared.
966 * After the call, \p texImage will have no data associated with it. Its
967 * fields are cleared so that its parent object will test incomplete.
970 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
972 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
973 clear_teximage_fields(texImage
);
978 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
979 * level, width, height and depth against the ctx->Const limits for textures.
981 * A hardware driver might override this function if, for example, the
982 * max 3D texture size is 512x512x64 (i.e. not a cube).
984 * Note that width, height, depth == 0 is not an error. However, a
985 * texture with zero width/height/depth will be considered "incomplete"
986 * and texturing will effectively be disabled.
988 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
989 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
990 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
991 * \param level as passed to glTexImage
992 * \param internalFormat as passed to glTexImage
993 * \param format as passed to glTexImage
994 * \param type as passed to glTexImage
995 * \param width as passed to glTexImage
996 * \param height as passed to glTexImage
997 * \param depth as passed to glTexImage
998 * \param border as passed to glTexImage
999 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1002 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1003 GLint internalFormat
, GLenum format
, GLenum type
,
1004 GLint width
, GLint height
, GLint depth
, GLint border
)
1008 (void) internalFormat
;
1013 case GL_PROXY_TEXTURE_1D
:
1014 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1015 if (width
< 2 * border
|| width
> 2 + maxSize
||
1016 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1017 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1018 level
>= ctx
->Const
.MaxTextureLevels
) {
1019 /* bad width or level */
1023 case GL_PROXY_TEXTURE_2D
:
1024 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1025 if (width
< 2 * border
|| width
> 2 + maxSize
||
1026 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1027 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1028 height
< 2 * border
|| height
> 2 + maxSize
||
1029 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1030 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1031 level
>= ctx
->Const
.MaxTextureLevels
) {
1032 /* bad width or height or level */
1036 case GL_PROXY_TEXTURE_3D
:
1037 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1038 if (width
< 2 * border
|| width
> 2 + maxSize
||
1039 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1040 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1041 height
< 2 * border
|| height
> 2 + maxSize
||
1042 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1043 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1044 depth
< 2 * border
|| depth
> 2 + maxSize
||
1045 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1046 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1047 level
>= ctx
->Const
.Max3DTextureLevels
) {
1048 /* bad width or height or depth or level */
1052 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1053 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1054 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1056 /* bad width or height or level */
1060 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1061 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1062 if (width
< 2 * border
|| width
> 2 + maxSize
||
1063 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1064 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1065 height
< 2 * border
|| height
> 2 + maxSize
||
1066 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1067 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1068 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1069 /* bad width or height */
1073 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
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 level
>= ctx
->Const
.MaxTextureLevels
) {
1079 /* bad width or level */
1083 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1087 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1088 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1089 if (width
< 2 * border
|| width
> 2 + maxSize
||
1090 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1091 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1092 height
< 2 * border
|| height
> 2 + maxSize
||
1093 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1094 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1095 level
>= ctx
->Const
.MaxTextureLevels
) {
1096 /* bad width or height or level */
1099 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1104 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1111 * Helper function to determine whether a target supports compressed textures
1114 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1116 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1117 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1118 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1119 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1120 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1121 || ((ctx
->Extensions
.MESA_texture_array
&&
1122 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1123 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1128 * Test the glTexImage[123]D() parameters for errors.
1130 * \param ctx GL context.
1131 * \param target texture target given by the user.
1132 * \param level image level given by the user.
1133 * \param internalFormat internal format given by the user.
1134 * \param format pixel data format given by the user.
1135 * \param type pixel data type given by the user.
1136 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1137 * \param width image width given by the user.
1138 * \param height image height given by the user.
1139 * \param depth image depth given by the user.
1140 * \param border image border given by the user.
1142 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1144 * Verifies each of the parameters against the constants specified in
1145 * __GLcontextRec::Const and the supported extensions, and according to the
1146 * OpenGL specification.
1149 texture_error_check( GLcontext
*ctx
, GLenum target
,
1150 GLint level
, GLint internalFormat
,
1151 GLenum format
, GLenum type
,
1153 GLint width
, GLint height
,
1154 GLint depth
, GLint border
)
1156 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1157 GLboolean sizeOK
= GL_TRUE
;
1158 GLboolean colorFormat
, indexFormat
;
1159 GLenum proxy_target
;
1161 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1162 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1164 _mesa_error(ctx
, GL_INVALID_VALUE
,
1165 "glTexImage%dD(level=%d)", dimensions
, level
);
1171 if (border
< 0 || border
> 1 ||
1172 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1173 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1175 _mesa_error(ctx
, GL_INVALID_VALUE
,
1176 "glTexImage%dD(border=%d)", dimensions
, border
);
1181 if (width
< 0 || height
< 0 || depth
< 0) {
1183 _mesa_error(ctx
, GL_INVALID_VALUE
,
1184 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1189 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1190 * level, width, height and depth.
1192 if (dimensions
== 1) {
1193 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1194 proxy_target
= GL_PROXY_TEXTURE_1D
;
1199 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1203 else if (dimensions
== 2) {
1205 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1206 proxy_target
= GL_PROXY_TEXTURE_2D
;
1208 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1209 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1210 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1211 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1212 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1215 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1216 sizeOK
= (width
== height
);
1218 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1219 target
== GL_TEXTURE_RECTANGLE_NV
) {
1220 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1221 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1224 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1226 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1227 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1228 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1231 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1235 else if (dimensions
== 3) {
1236 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1237 proxy_target
= GL_PROXY_TEXTURE_3D
;
1239 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1240 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1241 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1244 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1249 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1253 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1254 internalFormat
, format
,
1255 type
, width
, height
,
1259 _mesa_error(ctx
, GL_INVALID_VALUE
,
1260 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1261 dimensions
, level
, width
, height
, depth
);
1266 /* Check internalFormat */
1267 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1269 _mesa_error(ctx
, GL_INVALID_VALUE
,
1270 "glTexImage%dD(internalFormat=%s)",
1271 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1276 /* Check incoming image format and type */
1277 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1278 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1279 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1282 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1283 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1284 dimensions
, format
, type
);
1289 /* make sure internal format and format basically agree */
1290 colorFormat
= _mesa_is_color_format(format
);
1291 indexFormat
= _mesa_is_index_format(format
);
1292 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1293 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1294 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1295 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1296 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1297 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1299 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1300 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1301 dimensions
, internalFormat
, format
);
1305 /* additional checks for ycbcr textures */
1306 if (internalFormat
== GL_YCBCR_MESA
) {
1307 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1308 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1309 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1311 _mesa_sprintf(message
,
1312 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1313 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1314 return GL_TRUE
; /* error */
1316 if (target
!= GL_TEXTURE_2D
&&
1317 target
!= GL_PROXY_TEXTURE_2D
&&
1318 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1319 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1321 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1327 _mesa_sprintf(message
,
1328 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1329 dimensions
, border
);
1330 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1336 /* additional checks for depth textures */
1337 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1338 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1339 if (target
!= GL_TEXTURE_1D
&&
1340 target
!= GL_PROXY_TEXTURE_1D
&&
1341 target
!= GL_TEXTURE_2D
&&
1342 target
!= GL_PROXY_TEXTURE_2D
&&
1343 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1344 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1346 _mesa_error(ctx
, GL_INVALID_ENUM
,
1347 "glTexImage(target/internalFormat)");
1352 /* additional checks for compressed textures */
1353 if (is_compressed_format(ctx
, internalFormat
)) {
1354 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1355 _mesa_error(ctx
, GL_INVALID_ENUM
,
1356 "glTexImage%d(target)", dimensions
);
1361 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1362 "glTexImage%D(border!=0)", dimensions
);
1368 /* if we get here, the parameters are OK */
1374 * Test glTexSubImage[123]D() parameters for errors.
1376 * \param ctx GL context.
1377 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1378 * \param target texture target given by the user.
1379 * \param level image level given by the user.
1380 * \param xoffset sub-image x offset given by the user.
1381 * \param yoffset sub-image y offset given by the user.
1382 * \param zoffset sub-image z offset given by the user.
1383 * \param format pixel data format given by the user.
1384 * \param type pixel data type given by the user.
1385 * \param width image width given by the user.
1386 * \param height image height given by the user.
1387 * \param depth image depth given by the user.
1389 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1391 * Verifies each of the parameters against the constants specified in
1392 * __GLcontextRec::Const and the supported extensions, and according to the
1393 * OpenGL specification.
1396 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1397 GLenum target
, GLint level
,
1398 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1399 GLint width
, GLint height
, GLint depth
,
1400 GLenum format
, GLenum type
)
1403 if (dimensions
== 1) {
1404 if (target
!= GL_TEXTURE_1D
) {
1405 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1409 else if (dimensions
== 2) {
1410 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1411 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1412 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1413 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1417 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1418 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1419 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1423 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1424 if (!ctx
->Extensions
.MESA_texture_array
) {
1425 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1429 else if (target
!= GL_TEXTURE_2D
) {
1430 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1434 else if (dimensions
== 3) {
1435 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1436 if (!ctx
->Extensions
.MESA_texture_array
) {
1437 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1441 else if (target
!= GL_TEXTURE_3D
) {
1442 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1447 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1451 /* Basic level check */
1452 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1453 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1458 _mesa_error(ctx
, GL_INVALID_VALUE
,
1459 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1462 if (height
< 0 && dimensions
> 1) {
1463 _mesa_error(ctx
, GL_INVALID_VALUE
,
1464 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1467 if (depth
< 0 && dimensions
> 2) {
1468 _mesa_error(ctx
, GL_INVALID_VALUE
,
1469 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1473 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1474 _mesa_error(ctx
, GL_INVALID_ENUM
,
1475 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1476 dimensions
, format
, type
);
1485 * Do second part of glTexSubImage which depends on the destination texture.
1486 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1489 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1490 GLenum target
, GLint level
,
1491 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1492 GLint width
, GLint height
, GLint depth
,
1493 GLenum format
, GLenum type
,
1494 const struct gl_texture_image
*destTex
)
1497 /* undefined image level */
1498 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1502 if (xoffset
< -((GLint
)destTex
->Border
)) {
1503 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1507 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1508 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1512 if (dimensions
> 1) {
1513 if (yoffset
< -((GLint
)destTex
->Border
)) {
1514 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1518 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1519 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1524 if (dimensions
> 2) {
1525 if (zoffset
< -((GLint
)destTex
->Border
)) {
1526 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1529 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1530 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1535 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1538 if (!target_can_be_compressed(ctx
, target
)) {
1539 _mesa_error(ctx
, GL_INVALID_ENUM
,
1540 "glTexSubImage%D(target=%s)", dimensions
,
1541 _mesa_lookup_enum_by_nr(target
));
1545 /* do tests which depend on compression block size */
1546 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1548 /* offset must be multiple of block size */
1549 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1550 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1551 "glTexSubImage%D(xoffset = %d, yoffset = %d)",
1552 dimensions
, xoffset
, yoffset
);
1555 /* size must be multiple of bw by bh or equal to whole texture size */
1556 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1557 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1558 "glTexSubImage%D(width = %d)", dimensions
, width
);
1561 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1562 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1563 "glTexSubImage%D(height = %d)", dimensions
, height
);
1573 * Test glCopyTexImage[12]D() parameters for errors.
1575 * \param ctx GL context.
1576 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1577 * \param target texture target given by the user.
1578 * \param level image level given by the user.
1579 * \param internalFormat internal format given by the user.
1580 * \param width image width given by the user.
1581 * \param height image height given by the user.
1582 * \param border texture border.
1584 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1586 * Verifies each of the parameters against the constants specified in
1587 * __GLcontextRec::Const and the supported extensions, and according to the
1588 * OpenGL specification.
1591 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1592 GLenum target
, GLint level
, GLint internalFormat
,
1593 GLint width
, GLint height
, GLint border
)
1599 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1600 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1601 _mesa_error(ctx
, GL_INVALID_VALUE
,
1602 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1606 /* Check that the source buffer is complete */
1607 if (ctx
->ReadBuffer
->Name
) {
1608 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1609 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1610 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1611 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1617 if (border
< 0 || border
> 1 ||
1618 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1619 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1623 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1625 _mesa_error(ctx
, GL_INVALID_VALUE
,
1626 "glCopyTexImage%dD(internalFormat)", dimensions
);
1630 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1631 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1632 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1636 /* NOTE: the format and type aren't really significant for
1637 * TestProxyTexImage(). Only the internalformat really matters.
1641 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1642 * level, width, height and depth.
1644 if (dimensions
== 1) {
1645 if (target
== GL_TEXTURE_1D
) {
1646 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1647 level
, internalFormat
,
1649 width
, 1, 1, border
);
1652 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1656 else if (dimensions
== 2) {
1657 if (target
== GL_TEXTURE_2D
) {
1658 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1659 level
, internalFormat
,
1661 width
, height
, 1, border
);
1663 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1664 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1665 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1666 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1669 sizeOK
= (width
== height
) &&
1670 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1671 level
, internalFormat
, format
, type
,
1672 width
, height
, 1, border
);
1674 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1675 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1676 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1679 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1680 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1681 level
, internalFormat
,
1683 width
, height
, 1, border
);
1685 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1686 if (!ctx
->Extensions
.MESA_texture_array
) {
1687 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1690 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1691 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1692 level
, internalFormat
,
1694 width
, height
, 1, border
);
1697 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1702 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1707 if (dimensions
== 1) {
1708 _mesa_error(ctx
, GL_INVALID_VALUE
,
1709 "glCopyTexImage1D(width=%d)", width
);
1712 ASSERT(dimensions
== 2);
1713 _mesa_error(ctx
, GL_INVALID_VALUE
,
1714 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1719 if (is_compressed_format(ctx
, internalFormat
)) {
1720 if (!target_can_be_compressed(ctx
, target
)) {
1721 _mesa_error(ctx
, GL_INVALID_ENUM
,
1722 "glCopyTexImage%d(target)", dimensions
);
1726 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1727 "glCopyTexImage%D(border!=0)", dimensions
);
1731 else if (_mesa_is_depth_format(internalFormat
)) {
1732 /* make sure we have depth/stencil buffers */
1733 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1734 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1735 "glCopyTexImage%D(no depth)", dimensions
);
1739 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1740 /* make sure we have depth/stencil buffers */
1741 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1742 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1743 "glCopyTexImage%D(no depth/stencil buffer)", dimensions
);
1748 /* if we get here, the parameters are OK */
1754 * Test glCopyTexSubImage[12]D() parameters for errors.
1755 * Note that this is the first part of error checking.
1756 * See also copytexsubimage_error_check2() below for the second part.
1758 * \param ctx GL context.
1759 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1760 * \param target texture target given by the user.
1761 * \param level image level given by the user.
1763 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1766 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1767 GLenum target
, GLint level
)
1769 /* Check that the source buffer is complete */
1770 if (ctx
->ReadBuffer
->Name
) {
1771 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1772 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1773 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1774 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1780 if (dimensions
== 1) {
1781 if (target
!= GL_TEXTURE_1D
) {
1782 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1786 else if (dimensions
== 2) {
1787 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1788 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1789 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1790 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1794 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1795 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1796 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1800 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1801 if (!ctx
->Extensions
.MESA_texture_array
) {
1802 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1806 else if (target
!= GL_TEXTURE_2D
) {
1807 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1811 else if (dimensions
== 3) {
1812 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1813 (!ctx
->Extensions
.MESA_texture_array
))
1814 && (target
!= GL_TEXTURE_3D
)) {
1815 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1821 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1822 _mesa_error(ctx
, GL_INVALID_VALUE
,
1823 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1832 * Second part of error checking for glCopyTexSubImage[12]D().
1833 * \param xoffset sub-image x offset given by the user.
1834 * \param yoffset sub-image y offset given by the user.
1835 * \param zoffset sub-image z offset given by the user.
1836 * \param width image width given by the user.
1837 * \param height image height given by the user.
1840 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1841 GLenum target
, GLint level
,
1842 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1843 GLsizei width
, GLsizei height
,
1844 const struct gl_texture_image
*teximage
)
1846 /* check that dest tex image exists */
1848 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1849 "glCopyTexSubImage%dD(undefined texture level: %d)",
1856 _mesa_error(ctx
, GL_INVALID_VALUE
,
1857 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1860 if (dimensions
> 1 && height
< 0) {
1861 _mesa_error(ctx
, GL_INVALID_VALUE
,
1862 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1866 /* check x/y offsets */
1867 if (xoffset
< -((GLint
)teximage
->Border
)) {
1868 _mesa_error(ctx
, GL_INVALID_VALUE
,
1869 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1872 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1873 _mesa_error(ctx
, GL_INVALID_VALUE
,
1874 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1877 if (dimensions
> 1) {
1878 if (yoffset
< -((GLint
)teximage
->Border
)) {
1879 _mesa_error(ctx
, GL_INVALID_VALUE
,
1880 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1883 /* NOTE: we're adding the border here, not subtracting! */
1884 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1885 _mesa_error(ctx
, GL_INVALID_VALUE
,
1886 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1891 /* check z offset */
1892 if (dimensions
> 2) {
1893 if (zoffset
< -((GLint
)teximage
->Border
)) {
1894 _mesa_error(ctx
, GL_INVALID_VALUE
,
1895 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1898 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1899 _mesa_error(ctx
, GL_INVALID_VALUE
,
1900 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1905 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
1906 if (!target_can_be_compressed(ctx
, target
)) {
1907 _mesa_error(ctx
, GL_INVALID_ENUM
,
1908 "glCopyTexSubImage%d(target)", dimensions
);
1911 /* offset must be multiple of 4 */
1912 if ((xoffset
& 3) || (yoffset
& 3)) {
1913 _mesa_error(ctx
, GL_INVALID_VALUE
,
1914 "glCopyTexSubImage%D(xoffset or yoffset)", dimensions
);
1917 /* size must be multiple of 4 */
1918 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1919 _mesa_error(ctx
, GL_INVALID_VALUE
,
1920 "glCopyTexSubImage%D(width)", dimensions
);
1923 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1924 _mesa_error(ctx
, GL_INVALID_VALUE
,
1925 "glCopyTexSubImage%D(height)", dimensions
);
1930 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
1931 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1935 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
1936 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1937 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
1938 dimensions
, teximage
->_BaseFormat
);
1942 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
1943 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1944 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1945 "glCopyTexSubImage%D(no depth buffer)",
1950 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
1951 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1952 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1953 "glCopyTexSubImage%D(no depth/stencil buffer)",
1959 /* if we get here, the parameters are OK */
1964 /** Callback info for walking over FBO hash table */
1968 struct gl_texture_object
*texObj
;
1974 * Check render to texture callback. Called from _mesa_HashWalk().
1977 check_rtt_cb(GLuint key
, void *data
, void *userData
)
1979 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1980 const struct cb_info
*info
= (struct cb_info
*) userData
;
1981 GLcontext
*ctx
= info
->ctx
;
1982 const struct gl_texture_object
*texObj
= info
->texObj
;
1983 const GLuint level
= info
->level
, face
= info
->face
;
1985 /* If this is a user-created FBO */
1988 /* check if any of the FBO's attachments point to 'texObj' */
1989 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1990 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1991 if (att
->Type
== GL_TEXTURE
&&
1992 att
->Texture
== texObj
&&
1993 att
->TextureLevel
== level
&&
1994 att
->CubeMapFace
== face
) {
1995 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
1996 /* Tell driver about the new renderbuffer texture */
1997 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
1998 /* Mark fb status as indeterminate to force re-validation */
2007 * When a texture image is specified we have to check if it's bound to
2008 * any framebuffer objects (render to texture) in order to detect changes
2009 * in size or format since that effects FBO completeness.
2010 * Any FBOs rendering into the texture must be re-validated.
2013 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2014 GLuint face
, GLuint level
)
2016 /* Only check this texture if it's been marked as RenderToTexture */
2017 if (texObj
->_RenderToTexture
) {
2018 struct cb_info info
;
2020 info
.texObj
= texObj
;
2023 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2029 * If the texture object's GenerateMipmap flag is set and we've
2030 * changed the texture base level image, regenerate the rest of the
2031 * mipmap levels now.
2034 check_gen_mipmap(GLcontext
*ctx
, GLenum target
,
2035 struct gl_texture_object
*texObj
, GLint level
)
2037 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2038 if (texObj
->GenerateMipmap
&& level
== texObj
->BaseLevel
) {
2039 ASSERT(ctx
->Driver
.GenerateMipmap
);
2040 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2045 /** Debug helper: override the user-requested internal format */
2047 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2050 if (internalFormat
== GL_RGBA16F_ARB
||
2051 internalFormat
== GL_RGBA32F_ARB
) {
2052 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2055 else if (internalFormat
== GL_RGB16F_ARB
||
2056 internalFormat
== GL_RGB32F_ARB
) {
2057 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2060 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2061 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2062 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2063 return GL_LUMINANCE_ALPHA
;
2065 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2066 internalFormat
== GL_LUMINANCE32F_ARB
) {
2067 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2068 return GL_LUMINANCE
;
2070 else if (internalFormat
== GL_ALPHA16F_ARB
||
2071 internalFormat
== GL_ALPHA32F_ARB
) {
2072 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2076 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2077 internalFormat = GL_RGBA;
2081 return internalFormat
;
2084 return internalFormat
;
2090 * Called from the API. Note that width includes the border.
2093 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2094 GLsizei width
, GLint border
, GLenum format
,
2095 GLenum type
, const GLvoid
*pixels
)
2097 GLsizei postConvWidth
= width
;
2098 GET_CURRENT_CONTEXT(ctx
);
2099 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2101 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2102 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2103 _mesa_lookup_enum_by_nr(target
), level
,
2104 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2105 _mesa_lookup_enum_by_nr(format
),
2106 _mesa_lookup_enum_by_nr(type
), pixels
);
2108 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2110 #if FEATURE_convolve
2111 if (_mesa_is_color_format(internalFormat
)) {
2112 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2116 if (target
== GL_TEXTURE_1D
) {
2117 /* non-proxy target */
2118 struct gl_texture_object
*texObj
;
2119 struct gl_texture_image
*texImage
;
2120 const GLuint face
= _mesa_tex_target_to_face(target
);
2122 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2123 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2124 return; /* error was recorded */
2127 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2128 _mesa_update_state(ctx
);
2130 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2131 _mesa_lock_texture(ctx
, texObj
);
2133 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2135 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2138 if (texImage
->Data
) {
2139 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2142 ASSERT(texImage
->Data
== NULL
);
2144 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2145 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2146 postConvWidth
, 1, 1,
2147 border
, internalFormat
);
2149 /* Choose actual texture format */
2150 texImage
->TexFormat
=
2151 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2153 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2155 /* Give the texture to the driver. <pixels> may be null. */
2156 ASSERT(ctx
->Driver
.TexImage1D
);
2157 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2158 width
, border
, format
, type
, pixels
,
2159 &ctx
->Unpack
, texObj
, texImage
);
2161 ASSERT(texImage
->TexFormat
);
2163 _mesa_set_fetch_functions(texImage
, 1);
2165 check_gen_mipmap(ctx
, target
, texObj
, level
);
2167 update_fbo_texture(ctx
, texObj
, face
, level
);
2170 texObj
->_Complete
= GL_FALSE
;
2171 ctx
->NewState
|= _NEW_TEXTURE
;
2174 _mesa_unlock_texture(ctx
, texObj
);
2176 else if (target
== GL_PROXY_TEXTURE_1D
) {
2177 /* Proxy texture: check for errors and update proxy state */
2178 struct gl_texture_image
*texImage
;
2179 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2180 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2181 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2182 /* when error, clear all proxy texture image parameters */
2184 clear_teximage_fields(texImage
);
2187 /* no error, set the tex image parameters */
2189 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2190 postConvWidth
, 1, 1,
2191 border
, internalFormat
);
2192 texImage
->TexFormat
=
2193 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2197 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2204 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2205 GLsizei width
, GLsizei height
, GLint border
,
2206 GLenum format
, GLenum type
,
2207 const GLvoid
*pixels
)
2209 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2210 GET_CURRENT_CONTEXT(ctx
);
2211 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2213 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2214 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2215 _mesa_lookup_enum_by_nr(target
), level
,
2216 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2217 border
, _mesa_lookup_enum_by_nr(format
),
2218 _mesa_lookup_enum_by_nr(type
), pixels
);
2220 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2222 #if FEATURE_convolve
2223 if (_mesa_is_color_format(internalFormat
)) {
2224 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2229 if (target
== GL_TEXTURE_2D
||
2230 (ctx
->Extensions
.ARB_texture_cube_map
&&
2231 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2232 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2233 (ctx
->Extensions
.NV_texture_rectangle
&&
2234 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2235 (ctx
->Extensions
.MESA_texture_array
&&
2236 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2237 /* non-proxy target */
2238 struct gl_texture_object
*texObj
;
2239 struct gl_texture_image
*texImage
;
2240 const GLuint face
= _mesa_tex_target_to_face(target
);
2242 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2243 format
, type
, 2, postConvWidth
, postConvHeight
,
2245 return; /* error was recorded */
2248 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2249 _mesa_update_state(ctx
);
2251 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2252 _mesa_lock_texture(ctx
, texObj
);
2254 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2256 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2259 if (texImage
->Data
) {
2260 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2263 ASSERT(texImage
->Data
== NULL
);
2264 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2265 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2266 postConvWidth
, postConvHeight
, 1,
2267 border
, internalFormat
);
2269 /* Choose actual texture format */
2270 texImage
->TexFormat
=
2271 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2273 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2275 /* Give the texture to the driver. <pixels> may be null. */
2276 ASSERT(ctx
->Driver
.TexImage2D
);
2277 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2278 width
, height
, border
, format
, type
,
2279 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2281 ASSERT(texImage
->TexFormat
);
2283 _mesa_set_fetch_functions(texImage
, 2);
2285 check_gen_mipmap(ctx
, target
, texObj
, level
);
2287 update_fbo_texture(ctx
, texObj
, face
, level
);
2290 texObj
->_Complete
= GL_FALSE
;
2291 ctx
->NewState
|= _NEW_TEXTURE
;
2294 _mesa_unlock_texture(ctx
, texObj
);
2296 else if (target
== GL_PROXY_TEXTURE_2D
||
2297 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2298 ctx
->Extensions
.ARB_texture_cube_map
) ||
2299 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2300 ctx
->Extensions
.NV_texture_rectangle
) ||
2301 (ctx
->Extensions
.MESA_texture_array
&&
2302 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2303 /* Proxy texture: check for errors and update proxy state */
2304 struct gl_texture_image
*texImage
;
2305 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2306 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2307 format
, type
, 2, postConvWidth
, postConvHeight
,
2309 /* when error, clear all proxy texture image parameters */
2311 clear_teximage_fields(texImage
);
2314 /* no error, set the tex image parameters */
2315 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2316 postConvWidth
, postConvHeight
, 1,
2317 border
, internalFormat
);
2318 texImage
->TexFormat
=
2319 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2323 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2330 * Called by the API or display list executor.
2331 * Note that width and height include the border.
2334 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2335 GLsizei width
, GLsizei height
, GLsizei depth
,
2336 GLint border
, GLenum format
, GLenum type
,
2337 const GLvoid
*pixels
)
2339 GET_CURRENT_CONTEXT(ctx
);
2340 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2342 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2343 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2344 _mesa_lookup_enum_by_nr(target
), level
,
2345 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2346 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2347 _mesa_lookup_enum_by_nr(type
), pixels
);
2349 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2351 if (target
== GL_TEXTURE_3D
||
2352 (ctx
->Extensions
.MESA_texture_array
&&
2353 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2354 /* non-proxy target */
2355 struct gl_texture_object
*texObj
;
2356 struct gl_texture_image
*texImage
;
2357 const GLuint face
= _mesa_tex_target_to_face(target
);
2359 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2360 format
, type
, 3, width
, height
, depth
, border
)) {
2361 return; /* error was recorded */
2364 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2365 _mesa_update_state(ctx
);
2367 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2368 _mesa_lock_texture(ctx
, texObj
);
2370 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2372 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2375 if (texImage
->Data
) {
2376 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2379 ASSERT(texImage
->Data
== NULL
);
2380 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2381 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2382 width
, height
, depth
,
2383 border
, internalFormat
);
2385 /* Choose actual texture format */
2386 texImage
->TexFormat
=
2387 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2389 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2391 /* Give the texture to the driver. <pixels> may be null. */
2392 ASSERT(ctx
->Driver
.TexImage3D
);
2393 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2394 width
, height
, depth
, border
, format
, type
,
2395 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2397 ASSERT(texImage
->TexFormat
);
2399 _mesa_set_fetch_functions(texImage
, 3);
2401 check_gen_mipmap(ctx
, target
, texObj
, level
);
2403 update_fbo_texture(ctx
, texObj
, face
, level
);
2406 texObj
->_Complete
= GL_FALSE
;
2407 ctx
->NewState
|= _NEW_TEXTURE
;
2410 _mesa_unlock_texture(ctx
, texObj
);
2412 else if (target
== GL_PROXY_TEXTURE_3D
||
2413 (ctx
->Extensions
.MESA_texture_array
&&
2414 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2415 /* Proxy texture: check for errors and update proxy state */
2416 struct gl_texture_image
*texImage
;
2417 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2418 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2419 format
, type
, 3, width
, height
, depth
, border
)) {
2420 /* when error, clear all proxy texture image parameters */
2422 clear_teximage_fields(texImage
);
2425 /* no error, set the tex image parameters */
2426 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2427 depth
, border
, internalFormat
);
2428 texImage
->TexFormat
=
2429 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2433 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2440 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2441 GLsizei width
, GLsizei height
, GLsizei depth
,
2442 GLint border
, GLenum format
, GLenum type
,
2443 const GLvoid
*pixels
)
2445 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2446 depth
, border
, format
, type
, pixels
);
2452 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2453 GLint xoffset
, GLsizei width
,
2454 GLenum format
, GLenum type
,
2455 const GLvoid
*pixels
)
2457 GLsizei postConvWidth
= width
;
2458 struct gl_texture_object
*texObj
;
2459 struct gl_texture_image
*texImage
;
2460 GET_CURRENT_CONTEXT(ctx
);
2461 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2463 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2464 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2465 _mesa_lookup_enum_by_nr(target
), level
,
2466 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2467 _mesa_lookup_enum_by_nr(type
), pixels
);
2469 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2470 _mesa_update_state(ctx
);
2472 #if FEATURE_convolve
2473 /* XXX should test internal format */
2474 if (_mesa_is_color_format(format
)) {
2475 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2479 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2480 postConvWidth
, 1, 1, format
, type
)) {
2481 return; /* error was detected */
2485 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2488 _mesa_lock_texture(ctx
, texObj
);
2490 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2492 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2493 postConvWidth
, 1, 1,
2494 format
, type
, texImage
)) {
2495 /* error was recorded */
2497 else if (width
> 0) {
2498 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2499 xoffset
+= texImage
->Border
;
2501 ASSERT(ctx
->Driver
.TexSubImage1D
);
2502 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2503 format
, type
, pixels
, &ctx
->Unpack
,
2506 check_gen_mipmap(ctx
, target
, texObj
, level
);
2508 ctx
->NewState
|= _NEW_TEXTURE
;
2511 _mesa_unlock_texture(ctx
, texObj
);
2516 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2517 GLint xoffset
, GLint yoffset
,
2518 GLsizei width
, GLsizei height
,
2519 GLenum format
, GLenum type
,
2520 const GLvoid
*pixels
)
2522 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2523 struct gl_texture_object
*texObj
;
2524 struct gl_texture_image
*texImage
;
2525 GET_CURRENT_CONTEXT(ctx
);
2526 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2528 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2529 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2530 _mesa_lookup_enum_by_nr(target
), level
,
2531 xoffset
, yoffset
, width
, height
,
2532 _mesa_lookup_enum_by_nr(format
),
2533 _mesa_lookup_enum_by_nr(type
), pixels
);
2535 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2536 _mesa_update_state(ctx
);
2538 #if FEATURE_convolve
2539 /* XXX should test internal format */
2540 if (_mesa_is_color_format(format
)) {
2541 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2546 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2547 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2548 return; /* error was detected */
2551 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2553 _mesa_lock_texture(ctx
, texObj
);
2555 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2557 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2558 postConvWidth
, postConvHeight
, 1,
2559 format
, type
, texImage
)) {
2560 /* error was recorded */
2562 else if (width
> 0 && height
>= 0) {
2563 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2564 xoffset
+= texImage
->Border
;
2565 yoffset
+= texImage
->Border
;
2567 ASSERT(ctx
->Driver
.TexSubImage2D
);
2568 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2569 width
, height
, format
, type
, pixels
,
2570 &ctx
->Unpack
, texObj
, texImage
);
2572 check_gen_mipmap(ctx
, target
, texObj
, level
);
2574 ctx
->NewState
|= _NEW_TEXTURE
;
2577 _mesa_unlock_texture(ctx
, texObj
);
2583 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2584 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2585 GLsizei width
, GLsizei height
, GLsizei depth
,
2586 GLenum format
, GLenum type
,
2587 const GLvoid
*pixels
)
2589 struct gl_texture_object
*texObj
;
2590 struct gl_texture_image
*texImage
;
2591 GET_CURRENT_CONTEXT(ctx
);
2592 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2594 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2595 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2596 _mesa_lookup_enum_by_nr(target
), level
,
2597 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2598 _mesa_lookup_enum_by_nr(format
),
2599 _mesa_lookup_enum_by_nr(type
), pixels
);
2601 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2602 _mesa_update_state(ctx
);
2604 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2605 width
, height
, depth
, format
, type
)) {
2606 return; /* error was detected */
2609 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2611 _mesa_lock_texture(ctx
, texObj
);
2613 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2615 if (subtexture_error_check2(ctx
, 3, target
, level
,
2616 xoffset
, yoffset
, zoffset
,
2617 width
, height
, depth
,
2618 format
, type
, texImage
)) {
2619 /* error was recorded */
2621 else if (width
> 0 && height
> 0 && height
> 0) {
2622 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2623 xoffset
+= texImage
->Border
;
2624 yoffset
+= texImage
->Border
;
2625 zoffset
+= texImage
->Border
;
2627 ASSERT(ctx
->Driver
.TexSubImage3D
);
2628 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2629 xoffset
, yoffset
, zoffset
,
2630 width
, height
, depth
,
2631 format
, type
, pixels
,
2632 &ctx
->Unpack
, texObj
, texImage
);
2634 check_gen_mipmap(ctx
, target
, texObj
, level
);
2636 ctx
->NewState
|= _NEW_TEXTURE
;
2639 _mesa_unlock_texture(ctx
, texObj
);
2645 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2646 GLenum internalFormat
,
2648 GLsizei width
, GLint border
)
2650 struct gl_texture_object
*texObj
;
2651 struct gl_texture_image
*texImage
;
2652 GLsizei postConvWidth
= width
;
2653 const GLuint face
= _mesa_tex_target_to_face(target
);
2654 GET_CURRENT_CONTEXT(ctx
);
2655 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2657 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2658 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2659 _mesa_lookup_enum_by_nr(target
), level
,
2660 _mesa_lookup_enum_by_nr(internalFormat
),
2661 x
, y
, width
, border
);
2663 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2664 _mesa_update_state(ctx
);
2666 #if FEATURE_convolve
2667 if (_mesa_is_color_format(internalFormat
)) {
2668 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2672 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2673 postConvWidth
, 1, border
))
2676 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2678 _mesa_lock_texture(ctx
, texObj
);
2680 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2682 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2685 if (texImage
->Data
) {
2686 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2689 ASSERT(texImage
->Data
== NULL
);
2691 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2692 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2693 border
, internalFormat
);
2695 /* Choose actual texture format */
2696 texImage
->TexFormat
=
2697 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2699 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2701 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2702 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2703 x
, y
, width
, border
);
2705 ASSERT(texImage
->TexFormat
);
2707 _mesa_set_fetch_functions(texImage
, 1);
2709 check_gen_mipmap(ctx
, target
, texObj
, level
);
2711 update_fbo_texture(ctx
, texObj
, face
, level
);
2714 texObj
->_Complete
= GL_FALSE
;
2715 ctx
->NewState
|= _NEW_TEXTURE
;
2718 _mesa_unlock_texture(ctx
, texObj
);
2724 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2725 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2728 struct gl_texture_object
*texObj
;
2729 struct gl_texture_image
*texImage
;
2730 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2731 const GLuint face
= _mesa_tex_target_to_face(target
);
2732 GET_CURRENT_CONTEXT(ctx
);
2733 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2735 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2736 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2737 _mesa_lookup_enum_by_nr(target
), level
,
2738 _mesa_lookup_enum_by_nr(internalFormat
),
2739 x
, y
, width
, height
, border
);
2741 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2742 _mesa_update_state(ctx
);
2744 #if FEATURE_convolve
2745 if (_mesa_is_color_format(internalFormat
)) {
2746 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2751 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2752 postConvWidth
, postConvHeight
, border
))
2755 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2757 _mesa_lock_texture(ctx
, texObj
);
2759 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2762 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2765 if (texImage
->Data
) {
2766 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2769 ASSERT(texImage
->Data
== NULL
);
2771 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2772 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2773 postConvWidth
, postConvHeight
, 1,
2774 border
, internalFormat
);
2776 /* Choose actual texture format */
2777 texImage
->TexFormat
=
2778 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2780 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2782 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2783 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2784 x
, y
, width
, height
, border
);
2786 ASSERT(texImage
->TexFormat
);
2788 _mesa_set_fetch_functions(texImage
, 2);
2790 check_gen_mipmap(ctx
, target
, texObj
, level
);
2792 update_fbo_texture(ctx
, texObj
, face
, level
);
2795 texObj
->_Complete
= GL_FALSE
;
2796 ctx
->NewState
|= _NEW_TEXTURE
;
2799 _mesa_unlock_texture(ctx
, texObj
);
2804 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2805 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2807 struct gl_texture_object
*texObj
;
2808 struct gl_texture_image
*texImage
;
2809 GLsizei postConvWidth
= width
;
2813 GET_CURRENT_CONTEXT(ctx
);
2814 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2816 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2817 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2818 _mesa_lookup_enum_by_nr(target
),
2819 level
, xoffset
, x
, y
, width
);
2821 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2822 _mesa_update_state(ctx
);
2824 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2827 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2829 _mesa_lock_texture(ctx
, texObj
);
2831 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2833 #if FEATURE_convolve
2834 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2835 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2839 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2840 xoffset
, 0, 0, postConvWidth
, 1,
2842 /* error was recorded */
2845 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2846 xoffset
+= texImage
->Border
;
2848 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2850 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2851 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2852 xoffset
, x
, y
, width
);
2854 check_gen_mipmap(ctx
, target
, texObj
, level
);
2856 ctx
->NewState
|= _NEW_TEXTURE
;
2860 _mesa_unlock_texture(ctx
, texObj
);
2866 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2867 GLint xoffset
, GLint yoffset
,
2868 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2870 struct gl_texture_object
*texObj
;
2871 struct gl_texture_image
*texImage
;
2872 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2873 GET_CURRENT_CONTEXT(ctx
);
2874 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2876 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2877 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2878 _mesa_lookup_enum_by_nr(target
),
2879 level
, xoffset
, yoffset
, x
, y
, width
, height
);
2881 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2882 _mesa_update_state(ctx
);
2884 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2887 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2889 _mesa_lock_texture(ctx
, texObj
);
2891 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2893 #if FEATURE_convolve
2894 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2895 _mesa_adjust_image_for_convolution(ctx
, 2,
2896 &postConvWidth
, &postConvHeight
);
2900 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
2901 xoffset
, yoffset
, 0,
2902 postConvWidth
, postConvHeight
,
2904 /* error was recorded */
2907 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2908 xoffset
+= texImage
->Border
;
2909 yoffset
+= texImage
->Border
;
2911 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2913 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2914 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2915 x
, y
, width
, height
);
2917 check_gen_mipmap(ctx
, target
, texObj
, level
);
2919 ctx
->NewState
|= _NEW_TEXTURE
;
2923 _mesa_unlock_texture(ctx
, texObj
);
2929 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2930 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2931 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2933 struct gl_texture_object
*texObj
;
2934 struct gl_texture_image
*texImage
;
2935 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2936 GET_CURRENT_CONTEXT(ctx
);
2937 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2939 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2940 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
2941 _mesa_lookup_enum_by_nr(target
),
2942 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2944 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2945 _mesa_update_state(ctx
);
2947 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2950 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2952 _mesa_lock_texture(ctx
, texObj
);
2954 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2956 #if FEATURE_convolve
2957 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2958 _mesa_adjust_image_for_convolution(ctx
, 2,
2959 &postConvWidth
, &postConvHeight
);
2963 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2964 zoffset
, postConvWidth
, postConvHeight
,
2966 /* error was recored */
2969 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2970 xoffset
+= texImage
->Border
;
2971 yoffset
+= texImage
->Border
;
2972 zoffset
+= texImage
->Border
;
2974 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2976 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2977 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2978 xoffset
, yoffset
, zoffset
,
2979 x
, y
, width
, height
);
2981 check_gen_mipmap(ctx
, target
, texObj
, level
);
2983 ctx
->NewState
|= _NEW_TEXTURE
;
2987 _mesa_unlock_texture(ctx
, texObj
);
2993 /**********************************************************************/
2994 /****** Compressed Textures ******/
2995 /**********************************************************************/
2999 * Return expected size of a compressed texture.
3002 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3005 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3006 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3011 * Return compressed texture block size, in pixels.
3014 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3016 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3017 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3022 * Error checking for glCompressedTexImage[123]D().
3023 * \return error code or GL_NO_ERROR.
3026 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3027 GLenum target
, GLint level
,
3028 GLenum internalFormat
, GLsizei width
,
3029 GLsizei height
, GLsizei depth
, GLint border
,
3032 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3034 if (dimensions
== 1) {
3035 /* 1D compressed textures not allowed */
3036 return GL_INVALID_ENUM
;
3038 else if (dimensions
== 2) {
3039 if (target
== GL_PROXY_TEXTURE_2D
) {
3040 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3042 else if (target
== GL_TEXTURE_2D
) {
3043 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3045 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3046 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3047 return GL_INVALID_ENUM
; /*target*/
3048 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3050 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3051 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3052 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3053 return GL_INVALID_ENUM
; /*target*/
3054 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3057 return GL_INVALID_ENUM
; /*target*/
3060 else if (dimensions
== 3) {
3061 /* 3D compressed textures not allowed */
3062 return GL_INVALID_ENUM
;
3065 maxTextureSize
= 1 << (maxLevels
- 1);
3067 /* This will detect any invalid internalFormat value */
3068 if (!is_compressed_format(ctx
, internalFormat
))
3069 return GL_INVALID_ENUM
;
3071 /* This should really never fail */
3072 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3073 return GL_INVALID_ENUM
;
3076 return GL_INVALID_VALUE
;
3079 * XXX We should probably use the proxy texture error check function here.
3081 if (width
< 1 || width
> maxTextureSize
||
3082 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3083 return GL_INVALID_VALUE
;
3085 if ((height
< 1 || height
> maxTextureSize
||
3086 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3088 return GL_INVALID_VALUE
;
3090 if ((depth
< 1 || depth
> maxTextureSize
||
3091 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3093 return GL_INVALID_VALUE
;
3095 /* For cube map, width must equal height */
3096 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3097 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3098 return GL_INVALID_VALUE
;
3100 if (level
< 0 || level
>= maxLevels
)
3101 return GL_INVALID_VALUE
;
3103 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3104 if (expectedSize
!= imageSize
)
3105 return GL_INVALID_VALUE
;
3107 #if FEATURE_EXT_texture_sRGB
3108 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3109 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3110 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3111 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3113 return GL_INVALID_OPERATION
;
3122 * Error checking for glCompressedTexSubImage[123]D().
3123 * \warning There are some bad assumptions here about the size of compressed
3124 * texture tiles (multiple of 4) used to test the validity of the
3125 * offset and size parameters.
3126 * \return error code or GL_NO_ERROR.
3129 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3130 GLenum target
, GLint level
,
3131 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3132 GLsizei width
, GLsizei height
, GLsizei depth
,
3133 GLenum format
, GLsizei imageSize
)
3135 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3139 if (dimensions
== 1) {
3140 /* 1D compressed textures not allowed */
3141 return GL_INVALID_ENUM
;
3143 else if (dimensions
== 2) {
3144 if (target
== GL_PROXY_TEXTURE_2D
) {
3145 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3147 else if (target
== GL_TEXTURE_2D
) {
3148 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3150 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3151 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3152 return GL_INVALID_ENUM
; /*target*/
3153 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3155 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3156 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3157 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3158 return GL_INVALID_ENUM
; /*target*/
3159 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3162 return GL_INVALID_ENUM
; /*target*/
3165 else if (dimensions
== 3) {
3166 /* 3D compressed textures not allowed */
3167 return GL_INVALID_ENUM
;
3170 maxTextureSize
= 1 << (maxLevels
- 1);
3172 /* this will catch any invalid compressed format token */
3173 if (!is_compressed_format(ctx
, format
))
3174 return GL_INVALID_ENUM
;
3176 if (width
< 1 || width
> maxTextureSize
)
3177 return GL_INVALID_VALUE
;
3179 if ((height
< 1 || height
> maxTextureSize
)
3181 return GL_INVALID_VALUE
;
3183 if (level
< 0 || level
>= maxLevels
)
3184 return GL_INVALID_VALUE
;
3187 * do checks which depend on compression block size
3189 get_compressed_block_size(format
, &bw
, &bh
);
3191 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3192 return GL_INVALID_VALUE
;
3194 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3195 return GL_INVALID_VALUE
;
3197 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3198 return GL_INVALID_VALUE
;
3200 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3201 if (expectedSize
!= imageSize
)
3202 return GL_INVALID_VALUE
;
3209 * Do second part of glCompressedTexSubImage error checking.
3210 * \return GL_TRUE if error found, GL_FALSE otherwise.
3213 compressed_subtexture_error_check2(GLcontext
*ctx
, GLuint dims
,
3214 GLsizei width
, GLsizei height
,
3215 GLsizei depth
, GLenum format
,
3216 struct gl_texture_image
*texImage
)
3219 if ((GLint
) format
!= texImage
->InternalFormat
) {
3220 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3221 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3225 if (((width
== 1 || width
== 2) &&
3226 (GLuint
) width
!= texImage
->Width
) ||
3227 (width
> texImage
->Width
)) {
3228 _mesa_error(ctx
, GL_INVALID_VALUE
,
3229 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3234 if (((height
== 1 || height
== 2) &&
3235 (GLuint
) height
!= texImage
->Height
) ||
3236 (height
> texImage
->Height
)) {
3237 _mesa_error(ctx
, GL_INVALID_VALUE
,
3238 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3244 if (((depth
== 1 || depth
== 2) &&
3245 (GLuint
) depth
!= texImage
->Depth
) ||
3246 (depth
> texImage
->Depth
)) {
3247 _mesa_error(ctx
, GL_INVALID_VALUE
,
3248 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3259 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3260 GLenum internalFormat
, GLsizei width
,
3261 GLint border
, GLsizei imageSize
,
3264 GET_CURRENT_CONTEXT(ctx
);
3265 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3267 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3268 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3269 _mesa_lookup_enum_by_nr(target
), level
,
3270 _mesa_lookup_enum_by_nr(internalFormat
),
3271 width
, border
, imageSize
, data
);
3273 if (target
== GL_TEXTURE_1D
) {
3274 /* non-proxy target */
3275 struct gl_texture_object
*texObj
;
3276 struct gl_texture_image
*texImage
;
3277 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3278 internalFormat
, width
, 1, 1, border
, imageSize
);
3280 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3284 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3286 _mesa_lock_texture(ctx
, texObj
);
3288 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3290 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3293 if (texImage
->Data
) {
3294 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3296 ASSERT(texImage
->Data
== NULL
);
3298 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3299 border
, internalFormat
);
3301 /* Choose actual texture format */
3302 texImage
->TexFormat
=
3303 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3305 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3307 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3308 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3309 internalFormat
, width
, border
,
3313 _mesa_set_fetch_functions(texImage
, 1);
3315 check_gen_mipmap(ctx
, target
, texObj
, level
);
3318 texObj
->_Complete
= GL_FALSE
;
3319 ctx
->NewState
|= _NEW_TEXTURE
;
3322 _mesa_unlock_texture(ctx
, texObj
);
3324 else if (target
== GL_PROXY_TEXTURE_1D
) {
3325 /* Proxy texture: check for errors and update proxy state */
3326 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3327 internalFormat
, width
, 1, 1, border
, imageSize
);
3329 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3330 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3331 internalFormat
, GL_NONE
, GL_NONE
,
3332 width
, 1, 1, border
);
3335 /* if error, clear all proxy texture image parameters */
3336 struct gl_texture_image
*texImage
;
3337 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3339 clear_teximage_fields(texImage
);
3342 /* store the teximage parameters */
3343 struct gl_texture_object
*texObj
;
3344 struct gl_texture_image
*texImage
;
3346 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3348 _mesa_lock_texture(ctx
, texObj
);
3350 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3351 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3352 border
, internalFormat
);
3354 _mesa_unlock_texture(ctx
, texObj
);
3358 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3365 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3366 GLenum internalFormat
, GLsizei width
,
3367 GLsizei height
, GLint border
, GLsizei imageSize
,
3370 GET_CURRENT_CONTEXT(ctx
);
3371 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3373 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3374 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3375 _mesa_lookup_enum_by_nr(target
), level
,
3376 _mesa_lookup_enum_by_nr(internalFormat
),
3377 width
, height
, border
, imageSize
, data
);
3379 if (target
== GL_TEXTURE_2D
||
3380 (ctx
->Extensions
.ARB_texture_cube_map
&&
3381 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3382 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3383 /* non-proxy target */
3384 struct gl_texture_object
*texObj
;
3385 struct gl_texture_image
*texImage
;
3387 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3388 internalFormat
, width
, height
, 1, border
, imageSize
);
3390 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3394 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3396 _mesa_lock_texture(ctx
, texObj
);
3398 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3400 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3403 if (texImage
->Data
) {
3404 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3406 ASSERT(texImage
->Data
== NULL
);
3408 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3409 border
, internalFormat
);
3411 /* Choose actual texture format */
3412 texImage
->TexFormat
=
3413 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3415 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3417 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3418 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3419 internalFormat
, width
, height
,
3420 border
, imageSize
, data
,
3423 _mesa_set_fetch_functions(texImage
, 2);
3425 check_gen_mipmap(ctx
, target
, texObj
, level
);
3428 texObj
->_Complete
= GL_FALSE
;
3429 ctx
->NewState
|= _NEW_TEXTURE
;
3432 _mesa_unlock_texture(ctx
, texObj
);
3434 else if (target
== GL_PROXY_TEXTURE_2D
||
3435 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3436 ctx
->Extensions
.ARB_texture_cube_map
)) {
3437 /* Proxy texture: check for errors and update proxy state */
3438 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3439 internalFormat
, width
, height
, 1, border
, imageSize
);
3441 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3442 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3443 internalFormat
, GL_NONE
, GL_NONE
,
3444 width
, height
, 1, border
);
3447 /* if error, clear all proxy texture image parameters */
3448 struct gl_texture_image
*texImage
;
3449 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3451 clear_teximage_fields(texImage
);
3454 /* store the teximage parameters */
3455 struct gl_texture_object
*texObj
;
3456 struct gl_texture_image
*texImage
;
3458 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3460 _mesa_lock_texture(ctx
, texObj
);
3462 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3463 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3464 border
, internalFormat
);
3466 _mesa_unlock_texture(ctx
, texObj
);
3470 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3477 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3478 GLenum internalFormat
, GLsizei width
,
3479 GLsizei height
, GLsizei depth
, GLint border
,
3480 GLsizei imageSize
, const GLvoid
*data
)
3482 GET_CURRENT_CONTEXT(ctx
);
3483 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3485 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3486 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3487 _mesa_lookup_enum_by_nr(target
), level
,
3488 _mesa_lookup_enum_by_nr(internalFormat
),
3489 width
, height
, depth
, border
, imageSize
, data
);
3491 if (target
== GL_TEXTURE_3D
) {
3492 /* non-proxy target */
3493 struct gl_texture_object
*texObj
;
3494 struct gl_texture_image
*texImage
;
3495 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3496 internalFormat
, width
, height
, depth
, border
, imageSize
);
3498 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3502 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3504 _mesa_lock_texture(ctx
, texObj
);
3506 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3508 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3511 if (texImage
->Data
) {
3512 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3514 ASSERT(texImage
->Data
== NULL
);
3516 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3517 width
, height
, depth
,
3518 border
, internalFormat
);
3520 /* Choose actual texture format */
3521 texImage
->TexFormat
=
3522 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3524 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3526 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3527 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3529 width
, height
, depth
,
3530 border
, imageSize
, data
,
3533 _mesa_set_fetch_functions(texImage
, 3);
3535 check_gen_mipmap(ctx
, target
, texObj
, level
);
3538 texObj
->_Complete
= GL_FALSE
;
3539 ctx
->NewState
|= _NEW_TEXTURE
;
3542 _mesa_unlock_texture(ctx
, texObj
);
3544 else if (target
== GL_PROXY_TEXTURE_3D
) {
3545 /* Proxy texture: check for errors and update proxy state */
3546 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3547 internalFormat
, width
, height
, depth
, border
, imageSize
);
3549 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3550 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3551 internalFormat
, GL_NONE
, GL_NONE
,
3552 width
, height
, depth
, border
);
3555 /* if error, clear all proxy texture image parameters */
3556 struct gl_texture_image
*texImage
;
3557 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3559 clear_teximage_fields(texImage
);
3562 /* store the teximage parameters */
3563 struct gl_texture_object
*texObj
;
3564 struct gl_texture_image
*texImage
;
3566 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3568 _mesa_lock_texture(ctx
, texObj
);
3570 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3571 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3572 depth
, border
, internalFormat
);
3574 _mesa_unlock_texture(ctx
, texObj
);
3578 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3585 * Common helper for glCompressedTexSubImage1/2/3D().
3588 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3589 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3590 GLsizei width
, GLsizei height
, GLsizei depth
,
3591 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3593 struct gl_texture_object
*texObj
;
3594 struct gl_texture_image
*texImage
;
3596 GET_CURRENT_CONTEXT(ctx
);
3597 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3599 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3600 xoffset
, 0, 0, /* pos */
3601 width
, height
, depth
, /* size */
3604 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3608 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3610 _mesa_lock_texture(ctx
, texObj
);
3612 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3615 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3616 format
, texImage
)) {
3617 /* error was recorded */
3619 else if (width
> 0 && height
> 0 && depth
> 0) {
3622 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3623 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3625 format
, imageSize
, data
,
3630 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3631 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3634 format
, imageSize
, data
,
3639 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3640 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3641 xoffset
, yoffset
, zoffset
,
3642 width
, height
, depth
,
3643 format
, imageSize
, data
,
3651 check_gen_mipmap(ctx
, target
, texObj
, level
);
3653 ctx
->NewState
|= _NEW_TEXTURE
;
3656 _mesa_unlock_texture(ctx
, texObj
);
3661 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3662 GLsizei width
, GLenum format
,
3663 GLsizei imageSize
, const GLvoid
*data
)
3665 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3666 format
, imageSize
, data
);
3671 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3672 GLint yoffset
, GLsizei width
, GLsizei height
,
3673 GLenum format
, GLsizei imageSize
,
3676 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3677 width
, height
, 1, format
, imageSize
, data
);
3682 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3683 GLint yoffset
, GLint zoffset
, GLsizei width
,
3684 GLsizei height
, GLsizei depth
, GLenum format
,
3685 GLsizei imageSize
, const GLvoid
*data
)
3687 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3688 width
, height
, depth
, format
, imageSize
, data
);