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
&&
2039 level
== texObj
->BaseLevel
&&
2040 level
< texObj
->MaxLevel
) {
2041 ASSERT(ctx
->Driver
.GenerateMipmap
);
2042 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2047 /** Debug helper: override the user-requested internal format */
2049 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2052 if (internalFormat
== GL_RGBA16F_ARB
||
2053 internalFormat
== GL_RGBA32F_ARB
) {
2054 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2057 else if (internalFormat
== GL_RGB16F_ARB
||
2058 internalFormat
== GL_RGB32F_ARB
) {
2059 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2062 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2063 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2064 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2065 return GL_LUMINANCE_ALPHA
;
2067 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2068 internalFormat
== GL_LUMINANCE32F_ARB
) {
2069 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2070 return GL_LUMINANCE
;
2072 else if (internalFormat
== GL_ALPHA16F_ARB
||
2073 internalFormat
== GL_ALPHA32F_ARB
) {
2074 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2078 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2079 internalFormat = GL_RGBA;
2083 return internalFormat
;
2086 return internalFormat
;
2092 * Called from the API. Note that width includes the border.
2095 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2096 GLsizei width
, GLint border
, GLenum format
,
2097 GLenum type
, const GLvoid
*pixels
)
2099 GLsizei postConvWidth
= width
;
2100 GET_CURRENT_CONTEXT(ctx
);
2101 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2103 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2104 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2105 _mesa_lookup_enum_by_nr(target
), level
,
2106 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2107 _mesa_lookup_enum_by_nr(format
),
2108 _mesa_lookup_enum_by_nr(type
), pixels
);
2110 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2112 #if FEATURE_convolve
2113 if (_mesa_is_color_format(internalFormat
)) {
2114 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2118 if (target
== GL_TEXTURE_1D
) {
2119 /* non-proxy target */
2120 struct gl_texture_object
*texObj
;
2121 struct gl_texture_image
*texImage
;
2122 const GLuint face
= _mesa_tex_target_to_face(target
);
2124 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2125 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2126 return; /* error was recorded */
2129 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2130 _mesa_update_state(ctx
);
2132 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2133 _mesa_lock_texture(ctx
, texObj
);
2135 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2137 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2140 if (texImage
->Data
) {
2141 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2144 ASSERT(texImage
->Data
== NULL
);
2146 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2147 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2148 postConvWidth
, 1, 1,
2149 border
, internalFormat
);
2151 /* Choose actual texture format */
2152 texImage
->TexFormat
=
2153 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2155 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2157 /* Give the texture to the driver. <pixels> may be null. */
2158 ASSERT(ctx
->Driver
.TexImage1D
);
2159 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2160 width
, border
, format
, type
, pixels
,
2161 &ctx
->Unpack
, texObj
, texImage
);
2163 ASSERT(texImage
->TexFormat
);
2165 _mesa_set_fetch_functions(texImage
, 1);
2167 check_gen_mipmap(ctx
, target
, texObj
, level
);
2169 update_fbo_texture(ctx
, texObj
, face
, level
);
2172 texObj
->_Complete
= GL_FALSE
;
2173 ctx
->NewState
|= _NEW_TEXTURE
;
2176 _mesa_unlock_texture(ctx
, texObj
);
2178 else if (target
== GL_PROXY_TEXTURE_1D
) {
2179 /* Proxy texture: check for errors and update proxy state */
2180 struct gl_texture_image
*texImage
;
2181 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2182 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2183 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2184 /* when error, clear all proxy texture image parameters */
2186 clear_teximage_fields(texImage
);
2189 /* no error, set the tex image parameters */
2191 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2192 postConvWidth
, 1, 1,
2193 border
, internalFormat
);
2194 texImage
->TexFormat
=
2195 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2199 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2206 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2207 GLsizei width
, GLsizei height
, GLint border
,
2208 GLenum format
, GLenum type
,
2209 const GLvoid
*pixels
)
2211 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2212 GET_CURRENT_CONTEXT(ctx
);
2213 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2215 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2216 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2217 _mesa_lookup_enum_by_nr(target
), level
,
2218 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2219 border
, _mesa_lookup_enum_by_nr(format
),
2220 _mesa_lookup_enum_by_nr(type
), pixels
);
2222 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2224 #if FEATURE_convolve
2225 if (_mesa_is_color_format(internalFormat
)) {
2226 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2231 if (target
== GL_TEXTURE_2D
||
2232 (ctx
->Extensions
.ARB_texture_cube_map
&&
2233 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2234 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2235 (ctx
->Extensions
.NV_texture_rectangle
&&
2236 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2237 (ctx
->Extensions
.MESA_texture_array
&&
2238 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2239 /* non-proxy target */
2240 struct gl_texture_object
*texObj
;
2241 struct gl_texture_image
*texImage
;
2242 const GLuint face
= _mesa_tex_target_to_face(target
);
2244 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2245 format
, type
, 2, postConvWidth
, postConvHeight
,
2247 return; /* error was recorded */
2250 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2251 _mesa_update_state(ctx
);
2253 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2254 _mesa_lock_texture(ctx
, texObj
);
2256 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2258 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2261 if (texImage
->Data
) {
2262 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2265 ASSERT(texImage
->Data
== NULL
);
2266 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2267 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2268 postConvWidth
, postConvHeight
, 1,
2269 border
, internalFormat
);
2271 /* Choose actual texture format */
2272 texImage
->TexFormat
=
2273 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2275 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2277 /* Give the texture to the driver. <pixels> may be null. */
2278 ASSERT(ctx
->Driver
.TexImage2D
);
2279 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2280 width
, height
, border
, format
, type
,
2281 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2283 ASSERT(texImage
->TexFormat
);
2285 _mesa_set_fetch_functions(texImage
, 2);
2287 check_gen_mipmap(ctx
, target
, texObj
, level
);
2289 update_fbo_texture(ctx
, texObj
, face
, level
);
2292 texObj
->_Complete
= GL_FALSE
;
2293 ctx
->NewState
|= _NEW_TEXTURE
;
2296 _mesa_unlock_texture(ctx
, texObj
);
2298 else if (target
== GL_PROXY_TEXTURE_2D
||
2299 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2300 ctx
->Extensions
.ARB_texture_cube_map
) ||
2301 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2302 ctx
->Extensions
.NV_texture_rectangle
) ||
2303 (ctx
->Extensions
.MESA_texture_array
&&
2304 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2305 /* Proxy texture: check for errors and update proxy state */
2306 struct gl_texture_image
*texImage
;
2307 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2308 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2309 format
, type
, 2, postConvWidth
, postConvHeight
,
2311 /* when error, clear all proxy texture image parameters */
2313 clear_teximage_fields(texImage
);
2316 /* no error, set the tex image parameters */
2317 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2318 postConvWidth
, postConvHeight
, 1,
2319 border
, internalFormat
);
2320 texImage
->TexFormat
=
2321 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2325 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2332 * Called by the API or display list executor.
2333 * Note that width and height include the border.
2336 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2337 GLsizei width
, GLsizei height
, GLsizei depth
,
2338 GLint border
, GLenum format
, GLenum type
,
2339 const GLvoid
*pixels
)
2341 GET_CURRENT_CONTEXT(ctx
);
2342 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2344 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2345 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2346 _mesa_lookup_enum_by_nr(target
), level
,
2347 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2348 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2349 _mesa_lookup_enum_by_nr(type
), pixels
);
2351 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2353 if (target
== GL_TEXTURE_3D
||
2354 (ctx
->Extensions
.MESA_texture_array
&&
2355 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2356 /* non-proxy target */
2357 struct gl_texture_object
*texObj
;
2358 struct gl_texture_image
*texImage
;
2359 const GLuint face
= _mesa_tex_target_to_face(target
);
2361 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2362 format
, type
, 3, width
, height
, depth
, border
)) {
2363 return; /* error was recorded */
2366 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2367 _mesa_update_state(ctx
);
2369 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2370 _mesa_lock_texture(ctx
, texObj
);
2372 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2374 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2377 if (texImage
->Data
) {
2378 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2381 ASSERT(texImage
->Data
== NULL
);
2382 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2383 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2384 width
, height
, depth
,
2385 border
, internalFormat
);
2387 /* Choose actual texture format */
2388 texImage
->TexFormat
=
2389 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2391 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2393 /* Give the texture to the driver. <pixels> may be null. */
2394 ASSERT(ctx
->Driver
.TexImage3D
);
2395 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2396 width
, height
, depth
, border
, format
, type
,
2397 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2399 ASSERT(texImage
->TexFormat
);
2401 _mesa_set_fetch_functions(texImage
, 3);
2403 check_gen_mipmap(ctx
, target
, texObj
, level
);
2405 update_fbo_texture(ctx
, texObj
, face
, level
);
2408 texObj
->_Complete
= GL_FALSE
;
2409 ctx
->NewState
|= _NEW_TEXTURE
;
2412 _mesa_unlock_texture(ctx
, texObj
);
2414 else if (target
== GL_PROXY_TEXTURE_3D
||
2415 (ctx
->Extensions
.MESA_texture_array
&&
2416 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2417 /* Proxy texture: check for errors and update proxy state */
2418 struct gl_texture_image
*texImage
;
2419 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2420 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2421 format
, type
, 3, width
, height
, depth
, border
)) {
2422 /* when error, clear all proxy texture image parameters */
2424 clear_teximage_fields(texImage
);
2427 /* no error, set the tex image parameters */
2428 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2429 depth
, border
, internalFormat
);
2430 texImage
->TexFormat
=
2431 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2435 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2442 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2443 GLsizei width
, GLsizei height
, GLsizei depth
,
2444 GLint border
, GLenum format
, GLenum type
,
2445 const GLvoid
*pixels
)
2447 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2448 depth
, border
, format
, type
, pixels
);
2454 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2455 GLint xoffset
, GLsizei width
,
2456 GLenum format
, GLenum type
,
2457 const GLvoid
*pixels
)
2459 GLsizei postConvWidth
= width
;
2460 struct gl_texture_object
*texObj
;
2461 struct gl_texture_image
*texImage
;
2462 GET_CURRENT_CONTEXT(ctx
);
2463 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2465 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2466 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2467 _mesa_lookup_enum_by_nr(target
), level
,
2468 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2469 _mesa_lookup_enum_by_nr(type
), pixels
);
2471 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2472 _mesa_update_state(ctx
);
2474 #if FEATURE_convolve
2475 /* XXX should test internal format */
2476 if (_mesa_is_color_format(format
)) {
2477 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2481 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2482 postConvWidth
, 1, 1, format
, type
)) {
2483 return; /* error was detected */
2487 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2490 _mesa_lock_texture(ctx
, texObj
);
2492 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2494 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2495 postConvWidth
, 1, 1,
2496 format
, type
, texImage
)) {
2497 /* error was recorded */
2499 else if (width
> 0) {
2500 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2501 xoffset
+= texImage
->Border
;
2503 ASSERT(ctx
->Driver
.TexSubImage1D
);
2504 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2505 format
, type
, pixels
, &ctx
->Unpack
,
2508 check_gen_mipmap(ctx
, target
, texObj
, level
);
2510 ctx
->NewState
|= _NEW_TEXTURE
;
2513 _mesa_unlock_texture(ctx
, texObj
);
2518 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2519 GLint xoffset
, GLint yoffset
,
2520 GLsizei width
, GLsizei height
,
2521 GLenum format
, GLenum type
,
2522 const GLvoid
*pixels
)
2524 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2525 struct gl_texture_object
*texObj
;
2526 struct gl_texture_image
*texImage
;
2527 GET_CURRENT_CONTEXT(ctx
);
2528 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2530 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2531 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2532 _mesa_lookup_enum_by_nr(target
), level
,
2533 xoffset
, yoffset
, width
, height
,
2534 _mesa_lookup_enum_by_nr(format
),
2535 _mesa_lookup_enum_by_nr(type
), pixels
);
2537 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2538 _mesa_update_state(ctx
);
2540 #if FEATURE_convolve
2541 /* XXX should test internal format */
2542 if (_mesa_is_color_format(format
)) {
2543 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2548 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2549 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2550 return; /* error was detected */
2553 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2555 _mesa_lock_texture(ctx
, texObj
);
2557 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2559 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2560 postConvWidth
, postConvHeight
, 1,
2561 format
, type
, texImage
)) {
2562 /* error was recorded */
2564 else if (width
> 0 && height
>= 0) {
2565 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2566 xoffset
+= texImage
->Border
;
2567 yoffset
+= texImage
->Border
;
2569 ASSERT(ctx
->Driver
.TexSubImage2D
);
2570 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2571 width
, height
, format
, type
, pixels
,
2572 &ctx
->Unpack
, texObj
, texImage
);
2574 check_gen_mipmap(ctx
, target
, texObj
, level
);
2576 ctx
->NewState
|= _NEW_TEXTURE
;
2579 _mesa_unlock_texture(ctx
, texObj
);
2585 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2586 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2587 GLsizei width
, GLsizei height
, GLsizei depth
,
2588 GLenum format
, GLenum type
,
2589 const GLvoid
*pixels
)
2591 struct gl_texture_object
*texObj
;
2592 struct gl_texture_image
*texImage
;
2593 GET_CURRENT_CONTEXT(ctx
);
2594 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2596 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2597 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2598 _mesa_lookup_enum_by_nr(target
), level
,
2599 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2600 _mesa_lookup_enum_by_nr(format
),
2601 _mesa_lookup_enum_by_nr(type
), pixels
);
2603 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2604 _mesa_update_state(ctx
);
2606 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2607 width
, height
, depth
, format
, type
)) {
2608 return; /* error was detected */
2611 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2613 _mesa_lock_texture(ctx
, texObj
);
2615 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2617 if (subtexture_error_check2(ctx
, 3, target
, level
,
2618 xoffset
, yoffset
, zoffset
,
2619 width
, height
, depth
,
2620 format
, type
, texImage
)) {
2621 /* error was recorded */
2623 else if (width
> 0 && height
> 0 && height
> 0) {
2624 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2625 xoffset
+= texImage
->Border
;
2626 yoffset
+= texImage
->Border
;
2627 zoffset
+= texImage
->Border
;
2629 ASSERT(ctx
->Driver
.TexSubImage3D
);
2630 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2631 xoffset
, yoffset
, zoffset
,
2632 width
, height
, depth
,
2633 format
, type
, pixels
,
2634 &ctx
->Unpack
, texObj
, texImage
);
2636 check_gen_mipmap(ctx
, target
, texObj
, level
);
2638 ctx
->NewState
|= _NEW_TEXTURE
;
2641 _mesa_unlock_texture(ctx
, texObj
);
2647 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2648 GLenum internalFormat
,
2650 GLsizei width
, GLint border
)
2652 struct gl_texture_object
*texObj
;
2653 struct gl_texture_image
*texImage
;
2654 GLsizei postConvWidth
= width
;
2655 const GLuint face
= _mesa_tex_target_to_face(target
);
2656 GET_CURRENT_CONTEXT(ctx
);
2657 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2659 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2660 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2661 _mesa_lookup_enum_by_nr(target
), level
,
2662 _mesa_lookup_enum_by_nr(internalFormat
),
2663 x
, y
, width
, border
);
2665 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2666 _mesa_update_state(ctx
);
2668 #if FEATURE_convolve
2669 if (_mesa_is_color_format(internalFormat
)) {
2670 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2674 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2675 postConvWidth
, 1, border
))
2678 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2680 _mesa_lock_texture(ctx
, texObj
);
2682 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2684 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2687 if (texImage
->Data
) {
2688 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2691 ASSERT(texImage
->Data
== NULL
);
2693 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2694 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2695 border
, internalFormat
);
2697 /* Choose actual texture format */
2698 texImage
->TexFormat
=
2699 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2701 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2703 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2704 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2705 x
, y
, width
, border
);
2707 ASSERT(texImage
->TexFormat
);
2709 _mesa_set_fetch_functions(texImage
, 1);
2711 check_gen_mipmap(ctx
, target
, texObj
, level
);
2713 update_fbo_texture(ctx
, texObj
, face
, level
);
2716 texObj
->_Complete
= GL_FALSE
;
2717 ctx
->NewState
|= _NEW_TEXTURE
;
2720 _mesa_unlock_texture(ctx
, texObj
);
2726 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2727 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2730 struct gl_texture_object
*texObj
;
2731 struct gl_texture_image
*texImage
;
2732 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2733 const GLuint face
= _mesa_tex_target_to_face(target
);
2734 GET_CURRENT_CONTEXT(ctx
);
2735 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2737 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2738 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2739 _mesa_lookup_enum_by_nr(target
), level
,
2740 _mesa_lookup_enum_by_nr(internalFormat
),
2741 x
, y
, width
, height
, border
);
2743 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2744 _mesa_update_state(ctx
);
2746 #if FEATURE_convolve
2747 if (_mesa_is_color_format(internalFormat
)) {
2748 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2753 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2754 postConvWidth
, postConvHeight
, border
))
2757 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2759 _mesa_lock_texture(ctx
, texObj
);
2761 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2764 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2767 if (texImage
->Data
) {
2768 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2771 ASSERT(texImage
->Data
== NULL
);
2773 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2774 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2775 postConvWidth
, postConvHeight
, 1,
2776 border
, internalFormat
);
2778 /* Choose actual texture format */
2779 texImage
->TexFormat
=
2780 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2782 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2784 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2785 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2786 x
, y
, width
, height
, border
);
2788 ASSERT(texImage
->TexFormat
);
2790 _mesa_set_fetch_functions(texImage
, 2);
2792 check_gen_mipmap(ctx
, target
, texObj
, level
);
2794 update_fbo_texture(ctx
, texObj
, face
, level
);
2797 texObj
->_Complete
= GL_FALSE
;
2798 ctx
->NewState
|= _NEW_TEXTURE
;
2801 _mesa_unlock_texture(ctx
, texObj
);
2806 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2807 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2809 struct gl_texture_object
*texObj
;
2810 struct gl_texture_image
*texImage
;
2811 GLsizei postConvWidth
= width
;
2815 GET_CURRENT_CONTEXT(ctx
);
2816 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2818 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2819 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2820 _mesa_lookup_enum_by_nr(target
),
2821 level
, xoffset
, x
, y
, width
);
2823 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2824 _mesa_update_state(ctx
);
2826 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2829 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2831 _mesa_lock_texture(ctx
, texObj
);
2833 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2835 #if FEATURE_convolve
2836 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2837 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2841 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2842 xoffset
, 0, 0, postConvWidth
, 1,
2844 /* error was recorded */
2847 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2848 xoffset
+= texImage
->Border
;
2850 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2852 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2853 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2854 xoffset
, x
, y
, width
);
2856 check_gen_mipmap(ctx
, target
, texObj
, level
);
2858 ctx
->NewState
|= _NEW_TEXTURE
;
2862 _mesa_unlock_texture(ctx
, texObj
);
2868 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2869 GLint xoffset
, GLint yoffset
,
2870 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2872 struct gl_texture_object
*texObj
;
2873 struct gl_texture_image
*texImage
;
2874 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2875 GET_CURRENT_CONTEXT(ctx
);
2876 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2878 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2879 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2880 _mesa_lookup_enum_by_nr(target
),
2881 level
, xoffset
, yoffset
, x
, y
, width
, height
);
2883 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2884 _mesa_update_state(ctx
);
2886 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2889 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2891 _mesa_lock_texture(ctx
, texObj
);
2893 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2895 #if FEATURE_convolve
2896 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2897 _mesa_adjust_image_for_convolution(ctx
, 2,
2898 &postConvWidth
, &postConvHeight
);
2902 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
2903 xoffset
, yoffset
, 0,
2904 postConvWidth
, postConvHeight
,
2906 /* error was recorded */
2909 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2910 xoffset
+= texImage
->Border
;
2911 yoffset
+= texImage
->Border
;
2913 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2915 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2916 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2917 x
, y
, width
, height
);
2919 check_gen_mipmap(ctx
, target
, texObj
, level
);
2921 ctx
->NewState
|= _NEW_TEXTURE
;
2925 _mesa_unlock_texture(ctx
, texObj
);
2931 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2932 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2933 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2935 struct gl_texture_object
*texObj
;
2936 struct gl_texture_image
*texImage
;
2937 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2938 GET_CURRENT_CONTEXT(ctx
);
2939 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2941 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2942 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
2943 _mesa_lookup_enum_by_nr(target
),
2944 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2946 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2947 _mesa_update_state(ctx
);
2949 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2952 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2954 _mesa_lock_texture(ctx
, texObj
);
2956 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2958 #if FEATURE_convolve
2959 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2960 _mesa_adjust_image_for_convolution(ctx
, 2,
2961 &postConvWidth
, &postConvHeight
);
2965 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2966 zoffset
, postConvWidth
, postConvHeight
,
2968 /* error was recored */
2971 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2972 xoffset
+= texImage
->Border
;
2973 yoffset
+= texImage
->Border
;
2974 zoffset
+= texImage
->Border
;
2976 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2978 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2979 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2980 xoffset
, yoffset
, zoffset
,
2981 x
, y
, width
, height
);
2983 check_gen_mipmap(ctx
, target
, texObj
, level
);
2985 ctx
->NewState
|= _NEW_TEXTURE
;
2989 _mesa_unlock_texture(ctx
, texObj
);
2995 /**********************************************************************/
2996 /****** Compressed Textures ******/
2997 /**********************************************************************/
3001 * Return expected size of a compressed texture.
3004 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3007 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3008 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3013 * Return compressed texture block size, in pixels.
3016 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3018 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3019 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3024 * Error checking for glCompressedTexImage[123]D().
3025 * \return error code or GL_NO_ERROR.
3028 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3029 GLenum target
, GLint level
,
3030 GLenum internalFormat
, GLsizei width
,
3031 GLsizei height
, GLsizei depth
, GLint border
,
3034 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3036 if (dimensions
== 1) {
3037 /* 1D compressed textures not allowed */
3038 return GL_INVALID_ENUM
;
3040 else if (dimensions
== 2) {
3041 if (target
== GL_PROXY_TEXTURE_2D
) {
3042 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3044 else if (target
== GL_TEXTURE_2D
) {
3045 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3047 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3048 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3049 return GL_INVALID_ENUM
; /*target*/
3050 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3052 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3053 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3054 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3055 return GL_INVALID_ENUM
; /*target*/
3056 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3059 return GL_INVALID_ENUM
; /*target*/
3062 else if (dimensions
== 3) {
3063 /* 3D compressed textures not allowed */
3064 return GL_INVALID_ENUM
;
3067 maxTextureSize
= 1 << (maxLevels
- 1);
3069 /* This will detect any invalid internalFormat value */
3070 if (!is_compressed_format(ctx
, internalFormat
))
3071 return GL_INVALID_ENUM
;
3073 /* This should really never fail */
3074 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3075 return GL_INVALID_ENUM
;
3078 return GL_INVALID_VALUE
;
3081 * XXX We should probably use the proxy texture error check function here.
3083 if (width
< 1 || width
> maxTextureSize
||
3084 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3085 return GL_INVALID_VALUE
;
3087 if ((height
< 1 || height
> maxTextureSize
||
3088 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3090 return GL_INVALID_VALUE
;
3092 if ((depth
< 1 || depth
> maxTextureSize
||
3093 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3095 return GL_INVALID_VALUE
;
3097 /* For cube map, width must equal height */
3098 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3099 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3100 return GL_INVALID_VALUE
;
3102 if (level
< 0 || level
>= maxLevels
)
3103 return GL_INVALID_VALUE
;
3105 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3106 if (expectedSize
!= imageSize
)
3107 return GL_INVALID_VALUE
;
3109 #if FEATURE_EXT_texture_sRGB
3110 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3111 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3112 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3113 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3115 return GL_INVALID_OPERATION
;
3124 * Error checking for glCompressedTexSubImage[123]D().
3125 * \warning There are some bad assumptions here about the size of compressed
3126 * texture tiles (multiple of 4) used to test the validity of the
3127 * offset and size parameters.
3128 * \return error code or GL_NO_ERROR.
3131 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3132 GLenum target
, GLint level
,
3133 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3134 GLsizei width
, GLsizei height
, GLsizei depth
,
3135 GLenum format
, GLsizei imageSize
)
3137 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3141 if (dimensions
== 1) {
3142 /* 1D compressed textures not allowed */
3143 return GL_INVALID_ENUM
;
3145 else if (dimensions
== 2) {
3146 if (target
== GL_PROXY_TEXTURE_2D
) {
3147 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3149 else if (target
== GL_TEXTURE_2D
) {
3150 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3152 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3153 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3154 return GL_INVALID_ENUM
; /*target*/
3155 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3157 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3158 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3159 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3160 return GL_INVALID_ENUM
; /*target*/
3161 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3164 return GL_INVALID_ENUM
; /*target*/
3167 else if (dimensions
== 3) {
3168 /* 3D compressed textures not allowed */
3169 return GL_INVALID_ENUM
;
3172 maxTextureSize
= 1 << (maxLevels
- 1);
3174 /* this will catch any invalid compressed format token */
3175 if (!is_compressed_format(ctx
, format
))
3176 return GL_INVALID_ENUM
;
3178 if (width
< 1 || width
> maxTextureSize
)
3179 return GL_INVALID_VALUE
;
3181 if ((height
< 1 || height
> maxTextureSize
)
3183 return GL_INVALID_VALUE
;
3185 if (level
< 0 || level
>= maxLevels
)
3186 return GL_INVALID_VALUE
;
3189 * do checks which depend on compression block size
3191 get_compressed_block_size(format
, &bw
, &bh
);
3193 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3194 return GL_INVALID_VALUE
;
3196 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3197 return GL_INVALID_VALUE
;
3199 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3200 return GL_INVALID_VALUE
;
3202 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3203 if (expectedSize
!= imageSize
)
3204 return GL_INVALID_VALUE
;
3211 * Do second part of glCompressedTexSubImage error checking.
3212 * \return GL_TRUE if error found, GL_FALSE otherwise.
3215 compressed_subtexture_error_check2(GLcontext
*ctx
, GLuint dims
,
3216 GLsizei width
, GLsizei height
,
3217 GLsizei depth
, GLenum format
,
3218 struct gl_texture_image
*texImage
)
3221 if ((GLint
) format
!= texImage
->InternalFormat
) {
3222 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3223 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3227 if (((width
== 1 || width
== 2) &&
3228 (GLuint
) width
!= texImage
->Width
) ||
3229 (width
> texImage
->Width
)) {
3230 _mesa_error(ctx
, GL_INVALID_VALUE
,
3231 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3236 if (((height
== 1 || height
== 2) &&
3237 (GLuint
) height
!= texImage
->Height
) ||
3238 (height
> texImage
->Height
)) {
3239 _mesa_error(ctx
, GL_INVALID_VALUE
,
3240 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3246 if (((depth
== 1 || depth
== 2) &&
3247 (GLuint
) depth
!= texImage
->Depth
) ||
3248 (depth
> texImage
->Depth
)) {
3249 _mesa_error(ctx
, GL_INVALID_VALUE
,
3250 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3261 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3262 GLenum internalFormat
, GLsizei width
,
3263 GLint border
, GLsizei imageSize
,
3266 GET_CURRENT_CONTEXT(ctx
);
3267 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3269 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3270 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3271 _mesa_lookup_enum_by_nr(target
), level
,
3272 _mesa_lookup_enum_by_nr(internalFormat
),
3273 width
, border
, imageSize
, data
);
3275 if (target
== GL_TEXTURE_1D
) {
3276 /* non-proxy target */
3277 struct gl_texture_object
*texObj
;
3278 struct gl_texture_image
*texImage
;
3279 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3280 internalFormat
, width
, 1, 1, border
, imageSize
);
3282 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3286 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3288 _mesa_lock_texture(ctx
, texObj
);
3290 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3292 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3295 if (texImage
->Data
) {
3296 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3298 ASSERT(texImage
->Data
== NULL
);
3300 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3301 border
, internalFormat
);
3303 /* Choose actual texture format */
3304 texImage
->TexFormat
=
3305 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3307 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3309 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3310 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3311 internalFormat
, width
, border
,
3315 _mesa_set_fetch_functions(texImage
, 1);
3317 check_gen_mipmap(ctx
, target
, texObj
, level
);
3320 texObj
->_Complete
= GL_FALSE
;
3321 ctx
->NewState
|= _NEW_TEXTURE
;
3324 _mesa_unlock_texture(ctx
, texObj
);
3326 else if (target
== GL_PROXY_TEXTURE_1D
) {
3327 /* Proxy texture: check for errors and update proxy state */
3328 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3329 internalFormat
, width
, 1, 1, border
, imageSize
);
3331 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3332 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3333 internalFormat
, GL_NONE
, GL_NONE
,
3334 width
, 1, 1, border
);
3337 /* if error, clear all proxy texture image parameters */
3338 struct gl_texture_image
*texImage
;
3339 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3341 clear_teximage_fields(texImage
);
3344 /* store the teximage parameters */
3345 struct gl_texture_object
*texObj
;
3346 struct gl_texture_image
*texImage
;
3348 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3350 _mesa_lock_texture(ctx
, texObj
);
3352 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3353 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3354 border
, internalFormat
);
3356 _mesa_unlock_texture(ctx
, texObj
);
3360 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3367 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3368 GLenum internalFormat
, GLsizei width
,
3369 GLsizei height
, GLint border
, GLsizei imageSize
,
3372 GET_CURRENT_CONTEXT(ctx
);
3373 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3375 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3376 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3377 _mesa_lookup_enum_by_nr(target
), level
,
3378 _mesa_lookup_enum_by_nr(internalFormat
),
3379 width
, height
, border
, imageSize
, data
);
3381 if (target
== GL_TEXTURE_2D
||
3382 (ctx
->Extensions
.ARB_texture_cube_map
&&
3383 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3384 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3385 /* non-proxy target */
3386 struct gl_texture_object
*texObj
;
3387 struct gl_texture_image
*texImage
;
3389 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3390 internalFormat
, width
, height
, 1, border
, imageSize
);
3392 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3396 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3398 _mesa_lock_texture(ctx
, texObj
);
3400 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3402 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3405 if (texImage
->Data
) {
3406 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3408 ASSERT(texImage
->Data
== NULL
);
3410 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3411 border
, internalFormat
);
3413 /* Choose actual texture format */
3414 texImage
->TexFormat
=
3415 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3417 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3419 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3420 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3421 internalFormat
, width
, height
,
3422 border
, imageSize
, data
,
3425 _mesa_set_fetch_functions(texImage
, 2);
3427 check_gen_mipmap(ctx
, target
, texObj
, level
);
3430 texObj
->_Complete
= GL_FALSE
;
3431 ctx
->NewState
|= _NEW_TEXTURE
;
3434 _mesa_unlock_texture(ctx
, texObj
);
3436 else if (target
== GL_PROXY_TEXTURE_2D
||
3437 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3438 ctx
->Extensions
.ARB_texture_cube_map
)) {
3439 /* Proxy texture: check for errors and update proxy state */
3440 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3441 internalFormat
, width
, height
, 1, border
, imageSize
);
3443 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3444 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3445 internalFormat
, GL_NONE
, GL_NONE
,
3446 width
, height
, 1, border
);
3449 /* if error, clear all proxy texture image parameters */
3450 struct gl_texture_image
*texImage
;
3451 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3453 clear_teximage_fields(texImage
);
3456 /* store the teximage parameters */
3457 struct gl_texture_object
*texObj
;
3458 struct gl_texture_image
*texImage
;
3460 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3462 _mesa_lock_texture(ctx
, texObj
);
3464 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3465 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3466 border
, internalFormat
);
3468 _mesa_unlock_texture(ctx
, texObj
);
3472 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3479 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3480 GLenum internalFormat
, GLsizei width
,
3481 GLsizei height
, GLsizei depth
, GLint border
,
3482 GLsizei imageSize
, const GLvoid
*data
)
3484 GET_CURRENT_CONTEXT(ctx
);
3485 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3487 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3488 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3489 _mesa_lookup_enum_by_nr(target
), level
,
3490 _mesa_lookup_enum_by_nr(internalFormat
),
3491 width
, height
, depth
, border
, imageSize
, data
);
3493 if (target
== GL_TEXTURE_3D
) {
3494 /* non-proxy target */
3495 struct gl_texture_object
*texObj
;
3496 struct gl_texture_image
*texImage
;
3497 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3498 internalFormat
, width
, height
, depth
, border
, imageSize
);
3500 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3504 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3506 _mesa_lock_texture(ctx
, texObj
);
3508 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3510 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3513 if (texImage
->Data
) {
3514 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3516 ASSERT(texImage
->Data
== NULL
);
3518 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3519 width
, height
, depth
,
3520 border
, internalFormat
);
3522 /* Choose actual texture format */
3523 texImage
->TexFormat
=
3524 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3526 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3528 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3529 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3531 width
, height
, depth
,
3532 border
, imageSize
, data
,
3535 _mesa_set_fetch_functions(texImage
, 3);
3537 check_gen_mipmap(ctx
, target
, texObj
, level
);
3540 texObj
->_Complete
= GL_FALSE
;
3541 ctx
->NewState
|= _NEW_TEXTURE
;
3544 _mesa_unlock_texture(ctx
, texObj
);
3546 else if (target
== GL_PROXY_TEXTURE_3D
) {
3547 /* Proxy texture: check for errors and update proxy state */
3548 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3549 internalFormat
, width
, height
, depth
, border
, imageSize
);
3551 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3552 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3553 internalFormat
, GL_NONE
, GL_NONE
,
3554 width
, height
, depth
, border
);
3557 /* if error, clear all proxy texture image parameters */
3558 struct gl_texture_image
*texImage
;
3559 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3561 clear_teximage_fields(texImage
);
3564 /* store the teximage parameters */
3565 struct gl_texture_object
*texObj
;
3566 struct gl_texture_image
*texImage
;
3568 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3570 _mesa_lock_texture(ctx
, texObj
);
3572 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3573 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3574 depth
, border
, internalFormat
);
3576 _mesa_unlock_texture(ctx
, texObj
);
3580 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3587 * Common helper for glCompressedTexSubImage1/2/3D().
3590 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3591 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3592 GLsizei width
, GLsizei height
, GLsizei depth
,
3593 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3595 struct gl_texture_object
*texObj
;
3596 struct gl_texture_image
*texImage
;
3598 GET_CURRENT_CONTEXT(ctx
);
3599 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3601 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3602 xoffset
, 0, 0, /* pos */
3603 width
, height
, depth
, /* size */
3606 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3610 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3612 _mesa_lock_texture(ctx
, texObj
);
3614 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3617 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3618 format
, texImage
)) {
3619 /* error was recorded */
3621 else if (width
> 0 && height
> 0 && depth
> 0) {
3624 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3625 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3627 format
, imageSize
, data
,
3632 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3633 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3636 format
, imageSize
, data
,
3641 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3642 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3643 xoffset
, yoffset
, zoffset
,
3644 width
, height
, depth
,
3645 format
, imageSize
, data
,
3653 check_gen_mipmap(ctx
, target
, texObj
, level
);
3655 ctx
->NewState
|= _NEW_TEXTURE
;
3658 _mesa_unlock_texture(ctx
, texObj
);
3663 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3664 GLsizei width
, GLenum format
,
3665 GLsizei imageSize
, const GLvoid
*data
)
3667 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3668 format
, imageSize
, data
);
3673 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3674 GLint yoffset
, GLsizei width
, GLsizei height
,
3675 GLenum format
, GLsizei imageSize
,
3678 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3679 width
, height
, 1, format
, imageSize
, data
);
3684 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3685 GLint yoffset
, GLint zoffset
, GLsizei width
,
3686 GLsizei height
, GLsizei depth
, GLenum format
,
3687 GLsizei imageSize
, const GLvoid
*data
)
3689 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3690 width
, height
, depth
, format
, imageSize
, data
);