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"
53 * State changes which we care about for glCopyTex[Sub]Image() calls.
54 * In particular, we care about pixel transfer state and buffer state
55 * (such as glReadBuffer to make sure we read from the right renderbuffer).
57 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
64 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
68 _mesa_alloc_texmemory(GLsizei bytes
)
70 return _mesa_align_malloc(bytes
, 512);
75 * Free texture memory allocated with _mesa_alloc_texmemory()
78 _mesa_free_texmemory(void *m
)
85 * Compute floor(log_base_2(n)).
115 * Return the simple base format for a given internal texture format.
116 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
118 * \param ctx GL context.
119 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
121 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
122 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
124 * This is the format which is used during texture application (i.e. the
125 * texture format and env mode determine the arithmetic used.
127 * XXX this could be static
130 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
132 switch (internalFormat
) {
147 case GL_LUMINANCE_ALPHA
:
148 case GL_LUMINANCE4_ALPHA4
:
149 case GL_LUMINANCE6_ALPHA2
:
150 case GL_LUMINANCE8_ALPHA8
:
151 case GL_LUMINANCE12_ALPHA4
:
152 case GL_LUMINANCE12_ALPHA12
:
153 case GL_LUMINANCE16_ALPHA16
:
154 return GL_LUMINANCE_ALPHA
;
185 if (ctx
->Extensions
.EXT_paletted_texture
) {
186 switch (internalFormat
) {
188 case GL_COLOR_INDEX1_EXT
:
189 case GL_COLOR_INDEX2_EXT
:
190 case GL_COLOR_INDEX4_EXT
:
191 case GL_COLOR_INDEX8_EXT
:
192 case GL_COLOR_INDEX12_EXT
:
193 case GL_COLOR_INDEX16_EXT
:
194 return GL_COLOR_INDEX
;
200 if (ctx
->Extensions
.ARB_depth_texture
) {
201 switch (internalFormat
) {
202 case GL_DEPTH_COMPONENT
:
203 case GL_DEPTH_COMPONENT16
:
204 case GL_DEPTH_COMPONENT24
:
205 case GL_DEPTH_COMPONENT32
:
206 return GL_DEPTH_COMPONENT
;
212 switch (internalFormat
) {
213 case GL_COMPRESSED_ALPHA
:
215 case GL_COMPRESSED_LUMINANCE
:
217 case GL_COMPRESSED_LUMINANCE_ALPHA
:
218 return GL_LUMINANCE_ALPHA
;
219 case GL_COMPRESSED_INTENSITY
:
221 case GL_COMPRESSED_RGB
:
223 case GL_COMPRESSED_RGBA
:
229 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
230 switch (internalFormat
) {
231 case GL_COMPRESSED_RGB_FXT1_3DFX
:
233 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
240 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
241 switch (internalFormat
) {
242 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
244 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
245 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
246 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
253 if (ctx
->Extensions
.S3_s3tc
) {
254 switch (internalFormat
) {
266 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
267 if (internalFormat
== GL_YCBCR_MESA
)
268 return GL_YCBCR_MESA
;
271 if (ctx
->Extensions
.ARB_texture_float
) {
272 switch (internalFormat
) {
273 case GL_ALPHA16F_ARB
:
274 case GL_ALPHA32F_ARB
:
282 case GL_INTENSITY16F_ARB
:
283 case GL_INTENSITY32F_ARB
:
285 case GL_LUMINANCE16F_ARB
:
286 case GL_LUMINANCE32F_ARB
:
288 case GL_LUMINANCE_ALPHA16F_ARB
:
289 case GL_LUMINANCE_ALPHA32F_ARB
:
290 return GL_LUMINANCE_ALPHA
;
296 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
297 switch (internalFormat
) {
306 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
307 switch (internalFormat
) {
316 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
317 switch (internalFormat
) {
318 case GL_DEPTH_STENCIL_EXT
:
319 case GL_DEPTH24_STENCIL8_EXT
:
320 return GL_DEPTH_STENCIL_EXT
;
326 #if FEATURE_EXT_texture_sRGB
327 if (ctx
->Extensions
.EXT_texture_sRGB
) {
328 switch (internalFormat
) {
331 case GL_COMPRESSED_SRGB_EXT
:
332 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
334 case GL_SRGB_ALPHA_EXT
:
335 case GL_SRGB8_ALPHA8_EXT
:
336 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
337 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
338 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
339 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
341 case GL_SLUMINANCE_ALPHA_EXT
:
342 case GL_SLUMINANCE8_ALPHA8_EXT
:
343 case GL_COMPRESSED_SLUMINANCE_EXT
:
344 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
345 return GL_LUMINANCE_ALPHA
;
346 case GL_SLUMINANCE_EXT
:
347 case GL_SLUMINANCE8_EXT
:
354 #endif /* FEATURE_EXT_texture_sRGB */
356 return -1; /* error */
361 * For cube map faces, return a face index in [0,5].
362 * For other targets return 0;
365 _mesa_tex_target_to_face(GLenum target
)
367 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
368 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
369 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
377 * Store a gl_texture_image pointer in a gl_texture_object structure
378 * according to the target and level parameters.
380 * \param tObj texture object.
381 * \param target texture target.
382 * \param level image level.
383 * \param texImage texture image.
385 * This was basically prompted by the introduction of cube maps.
388 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
389 GLenum target
, GLint level
,
390 struct gl_texture_image
*texImage
)
392 const GLuint face
= _mesa_tex_target_to_face(target
);
396 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
398 tObj
->Image
[face
][level
] = texImage
;
400 /* Set the 'back' pointer */
401 texImage
->TexObject
= tObj
;
406 * Allocate a texture image structure.
408 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
411 * \return a pointer to gl_texture_image struct with all fields initialized to
414 struct gl_texture_image
*
415 _mesa_new_texture_image( GLcontext
*ctx
)
418 return CALLOC_STRUCT(gl_texture_image
);
423 * Free texture image data.
424 * This function is a fallback called via ctx->Driver.FreeTexImageData().
426 * \param texImage texture image.
428 * Free the texture image data if it's not marked as client data.
431 _mesa_free_texture_image_data(GLcontext
*ctx
,
432 struct gl_texture_image
*texImage
)
436 if (texImage
->Data
&& !texImage
->IsClientData
) {
437 /* free the old texture data */
438 _mesa_free_texmemory(texImage
->Data
);
441 texImage
->Data
= NULL
;
446 * Free texture image.
448 * \param texImage texture image.
450 * Free the texture image structure and the associated image data.
453 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
455 /* Free texImage->Data and/or any other driver-specific texture
458 ASSERT(ctx
->Driver
.FreeTexImageData
);
459 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
461 ASSERT(texImage
->Data
== NULL
);
462 if (texImage
->ImageOffsets
)
463 free(texImage
->ImageOffsets
);
469 * Test if a target is a proxy target.
471 * \param target texture target.
473 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
476 _mesa_is_proxy_texture(GLenum target
)
478 /* NUM_TEXTURE_TARGETS should match number of terms below */
479 assert(NUM_TEXTURE_TARGETS
== 7);
481 return (target
== GL_PROXY_TEXTURE_1D
||
482 target
== GL_PROXY_TEXTURE_2D
||
483 target
== GL_PROXY_TEXTURE_3D
||
484 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
485 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
486 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
487 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
492 * Get the texture object that corresponds to the target of the given texture unit.
494 * \param ctx GL context.
495 * \param texUnit texture unit.
496 * \param target texture target.
498 * \return pointer to the texture object on success, or NULL on failure.
500 * \sa gl_texture_unit.
502 struct gl_texture_object
*
503 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
508 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
509 case GL_PROXY_TEXTURE_1D
:
510 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
512 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
513 case GL_PROXY_TEXTURE_2D
:
514 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
516 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
517 case GL_PROXY_TEXTURE_3D
:
518 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
519 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
520 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
521 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
522 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
523 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
524 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
525 case GL_TEXTURE_CUBE_MAP_ARB
:
526 return ctx
->Extensions
.ARB_texture_cube_map
527 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
528 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
529 return ctx
->Extensions
.ARB_texture_cube_map
530 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
531 case GL_TEXTURE_RECTANGLE_NV
:
532 return ctx
->Extensions
.NV_texture_rectangle
533 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
534 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
535 return ctx
->Extensions
.NV_texture_rectangle
536 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
537 case GL_TEXTURE_1D_ARRAY_EXT
:
538 return ctx
->Extensions
.MESA_texture_array
539 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
540 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
541 return ctx
->Extensions
.MESA_texture_array
542 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
543 case GL_TEXTURE_2D_ARRAY_EXT
:
544 return ctx
->Extensions
.MESA_texture_array
545 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
546 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
547 return ctx
->Extensions
.MESA_texture_array
548 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
550 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
557 * Return pointer to texture object for given target on current texture unit.
559 struct gl_texture_object
*
560 _mesa_get_current_tex_object(GLcontext
*ctx
, GLenum target
)
562 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
563 return _mesa_select_tex_object(ctx
, texUnit
, target
);
568 * Get a texture image pointer from a texture object, given a texture
569 * target and mipmap level. The target and level parameters should
570 * have already been error-checked.
572 * \param ctx GL context.
573 * \param texObj texture unit.
574 * \param target texture target.
575 * \param level image level.
577 * \return pointer to the texture image structure, or NULL on failure.
579 struct gl_texture_image
*
580 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
581 GLenum target
, GLint level
)
583 const GLuint face
= _mesa_tex_target_to_face(target
);
587 ASSERT(level
< MAX_TEXTURE_LEVELS
);
589 return texObj
->Image
[face
][level
];
594 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
595 * it and install it. Only return NULL if passed a bad parameter or run
598 struct gl_texture_image
*
599 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
600 GLenum target
, GLint level
)
602 struct gl_texture_image
*texImage
;
607 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
609 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
611 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
615 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
623 * Return pointer to the specified proxy texture image.
624 * Note that proxy textures are per-context, not per-texture unit.
625 * \return pointer to texture image or NULL if invalid target, invalid
626 * level, or out of memory.
628 struct gl_texture_image
*
629 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
631 struct gl_texture_image
*texImage
;
638 case GL_PROXY_TEXTURE_1D
:
639 if (level
>= ctx
->Const
.MaxTextureLevels
)
641 texIndex
= TEXTURE_1D_INDEX
;
643 case GL_PROXY_TEXTURE_2D
:
644 if (level
>= ctx
->Const
.MaxTextureLevels
)
646 texIndex
= TEXTURE_2D_INDEX
;
648 case GL_PROXY_TEXTURE_3D
:
649 if (level
>= ctx
->Const
.Max3DTextureLevels
)
651 texIndex
= TEXTURE_3D_INDEX
;
653 case GL_PROXY_TEXTURE_CUBE_MAP
:
654 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
656 texIndex
= TEXTURE_CUBE_INDEX
;
658 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
661 texIndex
= TEXTURE_RECT_INDEX
;
663 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
664 if (level
>= ctx
->Const
.MaxTextureLevels
)
666 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
668 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
669 if (level
>= ctx
->Const
.MaxTextureLevels
)
671 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
677 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
679 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
681 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
684 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
685 /* Set the 'back' pointer */
686 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
693 * Get the maximum number of allowed mipmap levels.
695 * \param ctx GL context.
696 * \param target texture target.
698 * \return the maximum number of allowed mipmap levels for the given
699 * texture target, or zero if passed a bad target.
704 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
708 case GL_PROXY_TEXTURE_1D
:
710 case GL_PROXY_TEXTURE_2D
:
711 return ctx
->Const
.MaxTextureLevels
;
713 case GL_PROXY_TEXTURE_3D
:
714 return ctx
->Const
.Max3DTextureLevels
;
715 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
716 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
717 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
718 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
719 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
720 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
721 case GL_TEXTURE_CUBE_MAP_ARB
:
722 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
723 return ctx
->Extensions
.ARB_texture_cube_map
724 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
725 case GL_TEXTURE_RECTANGLE_NV
:
726 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
727 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
728 case GL_TEXTURE_1D_ARRAY_EXT
:
729 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
730 case GL_TEXTURE_2D_ARRAY_EXT
:
731 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
732 return ctx
->Extensions
.MESA_texture_array
733 ? ctx
->Const
.MaxTextureLevels
: 0;
735 return 0; /* bad target */
741 #if 000 /* not used anymore */
743 * glTexImage[123]D can accept a NULL image pointer. In this case we
744 * create a texture image with unspecified image contents per the OpenGL
748 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
750 const GLint components
= _mesa_components_in_format(format
);
751 const GLint numPixels
= width
* height
* depth
;
752 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
756 * Let's see if anyone finds this. If glTexImage2D() is called with
757 * a NULL image pointer then load the texture image with something
758 * interesting instead of leaving it indeterminate.
761 static const char message
[8][32] = {
765 " X X XXXX XXX XXXXX ",
768 " X X XXXXX XXX X X ",
772 GLubyte
*imgPtr
= data
;
774 for (h
= 0; h
< depth
; h
++) {
775 for (i
= 0; i
< height
; i
++) {
776 GLint srcRow
= 7 - (i
% 8);
777 for (j
= 0; j
< width
; j
++) {
778 GLint srcCol
= j
% 32;
779 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
780 for (k
= 0; k
< components
; k
++) {
796 * Reset the fields of a gl_texture_image struct to zero.
798 * \param img texture image structure.
800 * This is called when a proxy texture test fails, we set all the
801 * image members (except DriverData) to zero.
802 * It's also used in glTexImage[123]D as a safeguard to be sure all
803 * required fields get initialized properly by the Driver.TexImage[123]D
807 clear_teximage_fields(struct gl_texture_image
*img
)
810 img
->_BaseFormat
= 0;
811 img
->InternalFormat
= 0;
817 if (img
->ImageOffsets
) {
818 free(img
->ImageOffsets
);
819 img
->ImageOffsets
= NULL
;
828 img
->TexFormat
= MESA_FORMAT_NONE
;
829 img
->FetchTexelc
= NULL
;
830 img
->FetchTexelf
= NULL
;
835 * Initialize basic fields of the gl_texture_image struct.
837 * \param ctx GL context.
838 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
839 * \param img texture image structure to be initialized.
840 * \param width image width.
841 * \param height image height.
842 * \param depth image depth.
843 * \param border image border.
844 * \param internalFormat internal format.
846 * Fills in the fields of \p img with the given information.
847 * Note: width, height and depth include the border.
850 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
851 struct gl_texture_image
*img
,
852 GLsizei width
, GLsizei height
, GLsizei depth
,
853 GLint border
, GLenum internalFormat
)
862 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
863 ASSERT(img
->_BaseFormat
> 0);
864 img
->InternalFormat
= internalFormat
;
865 img
->Border
= border
;
867 img
->Height
= height
;
870 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
871 img
->WidthLog2
= logbase2(img
->Width2
);
873 if (height
== 1) { /* 1-D texture */
878 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
879 img
->HeightLog2
= logbase2(img
->Height2
);
882 if (depth
== 1) { /* 2-D texture */
887 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
888 img
->DepthLog2
= logbase2(img
->Depth2
);
891 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
893 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
894 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
895 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
896 img
->_IsPowerOfTwo
= GL_TRUE
;
898 img
->_IsPowerOfTwo
= GL_FALSE
;
900 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
901 img
->RowStride
= width
;
902 /* Allocate the ImageOffsets array and initialize to typical values.
903 * We allocate the array for 1D/2D textures too in order to avoid special-
904 * case code in the texstore routines.
906 if (img
->ImageOffsets
)
907 free(img
->ImageOffsets
);
908 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
909 for (i
= 0; i
< depth
; i
++) {
910 img
->ImageOffsets
[i
] = i
* width
* height
;
913 /* Compute Width/Height/DepthScale for mipmap lod computation */
914 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
915 /* scale = 1.0 since texture coords directly map to texels */
916 img
->WidthScale
= 1.0;
917 img
->HeightScale
= 1.0;
918 img
->DepthScale
= 1.0;
921 img
->WidthScale
= (GLfloat
) img
->Width
;
922 img
->HeightScale
= (GLfloat
) img
->Height
;
923 img
->DepthScale
= (GLfloat
) img
->Depth
;
926 img
->FetchTexelc
= NULL
;
927 img
->FetchTexelf
= NULL
;
932 * Free and clear fields of the gl_texture_image struct.
934 * \param ctx GL context.
935 * \param texImage texture image structure to be cleared.
937 * After the call, \p texImage will have no data associated with it. Its
938 * fields are cleared so that its parent object will test incomplete.
941 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
943 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
944 clear_teximage_fields(texImage
);
949 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
950 * level, width, height and depth against the ctx->Const limits for textures.
952 * A hardware driver might override this function if, for example, the
953 * max 3D texture size is 512x512x64 (i.e. not a cube).
955 * Note that width, height, depth == 0 is not an error. However, a
956 * texture with zero width/height/depth will be considered "incomplete"
957 * and texturing will effectively be disabled.
959 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
960 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
961 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
962 * \param level as passed to glTexImage
963 * \param internalFormat as passed to glTexImage
964 * \param format as passed to glTexImage
965 * \param type as passed to glTexImage
966 * \param width as passed to glTexImage
967 * \param height as passed to glTexImage
968 * \param depth as passed to glTexImage
969 * \param border as passed to glTexImage
970 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
973 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
974 GLint internalFormat
, GLenum format
, GLenum type
,
975 GLint width
, GLint height
, GLint depth
, GLint border
)
979 (void) internalFormat
;
984 case GL_PROXY_TEXTURE_1D
:
985 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
986 if (width
< 2 * border
|| width
> 2 + maxSize
||
987 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
988 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
989 level
>= ctx
->Const
.MaxTextureLevels
) {
990 /* bad width or level */
994 case GL_PROXY_TEXTURE_2D
:
995 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
996 if (width
< 2 * border
|| width
> 2 + maxSize
||
997 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
998 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
999 height
< 2 * border
|| height
> 2 + maxSize
||
1000 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1001 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1002 level
>= ctx
->Const
.MaxTextureLevels
) {
1003 /* bad width or height or level */
1007 case GL_PROXY_TEXTURE_3D
:
1008 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1009 if (width
< 2 * border
|| width
> 2 + maxSize
||
1010 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1011 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1012 height
< 2 * border
|| height
> 2 + maxSize
||
1013 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1014 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1015 depth
< 2 * border
|| depth
> 2 + maxSize
||
1016 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1017 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1018 level
>= ctx
->Const
.Max3DTextureLevels
) {
1019 /* bad width or height or depth or level */
1023 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1024 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1025 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1027 /* bad width or height or level */
1031 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1032 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1033 if (width
< 2 * border
|| width
> 2 + maxSize
||
1034 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1035 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1036 height
< 2 * border
|| height
> 2 + maxSize
||
1037 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1038 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1039 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1040 /* bad width or height */
1044 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1045 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1046 if (width
< 2 * border
|| width
> 2 + maxSize
||
1047 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1048 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1049 level
>= ctx
->Const
.MaxTextureLevels
) {
1050 /* bad width or level */
1054 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1058 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1059 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1060 if (width
< 2 * border
|| width
> 2 + maxSize
||
1061 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1062 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1063 height
< 2 * border
|| height
> 2 + maxSize
||
1064 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1065 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1066 level
>= ctx
->Const
.MaxTextureLevels
) {
1067 /* bad width or height or level */
1070 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1075 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1082 * Helper function to determine whether a target supports compressed textures
1085 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1087 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1088 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1089 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1090 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1091 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1092 || ((ctx
->Extensions
.MESA_texture_array
&&
1093 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1094 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1099 * Test the glTexImage[123]D() parameters for errors.
1101 * \param ctx GL context.
1102 * \param target texture target given by the user.
1103 * \param level image level given by the user.
1104 * \param internalFormat internal format given by the user.
1105 * \param format pixel data format given by the user.
1106 * \param type pixel data type given by the user.
1107 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1108 * \param width image width given by the user.
1109 * \param height image height given by the user.
1110 * \param depth image depth given by the user.
1111 * \param border image border given by the user.
1113 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1115 * Verifies each of the parameters against the constants specified in
1116 * __GLcontextRec::Const and the supported extensions, and according to the
1117 * OpenGL specification.
1120 texture_error_check( GLcontext
*ctx
, GLenum target
,
1121 GLint level
, GLint internalFormat
,
1122 GLenum format
, GLenum type
,
1124 GLint width
, GLint height
,
1125 GLint depth
, GLint border
)
1127 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1128 GLboolean sizeOK
= GL_TRUE
;
1129 GLboolean colorFormat
, indexFormat
;
1130 GLenum proxy_target
;
1132 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1133 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1135 _mesa_error(ctx
, GL_INVALID_VALUE
,
1136 "glTexImage%dD(level=%d)", dimensions
, level
);
1142 if (border
< 0 || border
> 1 ||
1143 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1144 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1146 _mesa_error(ctx
, GL_INVALID_VALUE
,
1147 "glTexImage%dD(border=%d)", dimensions
, border
);
1152 if (width
< 0 || height
< 0 || depth
< 0) {
1154 _mesa_error(ctx
, GL_INVALID_VALUE
,
1155 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1160 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1161 * level, width, height and depth.
1163 if (dimensions
== 1) {
1164 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1165 proxy_target
= GL_PROXY_TEXTURE_1D
;
1170 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1174 else if (dimensions
== 2) {
1176 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1177 proxy_target
= GL_PROXY_TEXTURE_2D
;
1179 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1180 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1181 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1182 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1183 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1186 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1187 sizeOK
= (width
== height
);
1189 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1190 target
== GL_TEXTURE_RECTANGLE_NV
) {
1191 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1192 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1195 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1197 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1198 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1199 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1202 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1206 else if (dimensions
== 3) {
1207 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1208 proxy_target
= GL_PROXY_TEXTURE_3D
;
1210 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1211 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1212 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1215 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1220 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1224 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1225 internalFormat
, format
,
1226 type
, width
, height
,
1230 _mesa_error(ctx
, GL_INVALID_VALUE
,
1231 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1232 dimensions
, level
, width
, height
, depth
);
1237 /* Check internalFormat */
1238 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1240 _mesa_error(ctx
, GL_INVALID_VALUE
,
1241 "glTexImage%dD(internalFormat=%s)",
1242 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1247 /* Check incoming image format and type */
1248 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1249 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1250 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1253 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1254 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1255 dimensions
, format
, type
);
1260 /* make sure internal format and format basically agree */
1261 colorFormat
= _mesa_is_color_format(format
);
1262 indexFormat
= _mesa_is_index_format(format
);
1263 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1264 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1265 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1266 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1267 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1268 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1270 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1271 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1272 dimensions
, internalFormat
, format
);
1276 /* additional checks for ycbcr textures */
1277 if (internalFormat
== GL_YCBCR_MESA
) {
1278 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1279 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1280 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1283 "glTexImage%d(format/type YCBCR mismatch", dimensions
);
1284 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1285 return GL_TRUE
; /* error */
1287 if (target
!= GL_TEXTURE_2D
&&
1288 target
!= GL_PROXY_TEXTURE_2D
&&
1289 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1290 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1292 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1299 "glTexImage%d(format=GL_YCBCR_MESA and border=%d)",
1300 dimensions
, border
);
1301 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1307 /* additional checks for depth textures */
1308 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1309 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1310 if (target
!= GL_TEXTURE_1D
&&
1311 target
!= GL_PROXY_TEXTURE_1D
&&
1312 target
!= GL_TEXTURE_2D
&&
1313 target
!= GL_PROXY_TEXTURE_2D
&&
1314 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1315 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1317 _mesa_error(ctx
, GL_INVALID_ENUM
,
1318 "glTexImage(target/internalFormat)");
1323 /* additional checks for compressed textures */
1324 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1325 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1326 _mesa_error(ctx
, GL_INVALID_ENUM
,
1327 "glTexImage%d(target)", dimensions
);
1332 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1333 "glTexImage%dD(border!=0)", dimensions
);
1339 /* if we get here, the parameters are OK */
1345 * Test glTexSubImage[123]D() parameters for errors.
1347 * \param ctx GL context.
1348 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1349 * \param target texture target given by the user.
1350 * \param level image level given by the user.
1351 * \param xoffset sub-image x offset given by the user.
1352 * \param yoffset sub-image y offset given by the user.
1353 * \param zoffset sub-image z offset given by the user.
1354 * \param format pixel data format given by the user.
1355 * \param type pixel data type given by the user.
1356 * \param width image width given by the user.
1357 * \param height image height given by the user.
1358 * \param depth image depth given by the user.
1360 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1362 * Verifies each of the parameters against the constants specified in
1363 * __GLcontextRec::Const and the supported extensions, and according to the
1364 * OpenGL specification.
1367 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1368 GLenum target
, GLint level
,
1369 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1370 GLint width
, GLint height
, GLint depth
,
1371 GLenum format
, GLenum type
)
1374 if (dimensions
== 1) {
1375 if (target
!= GL_TEXTURE_1D
) {
1376 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1380 else if (dimensions
== 2) {
1381 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1382 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1383 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1384 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1388 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1389 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1390 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1394 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1395 if (!ctx
->Extensions
.MESA_texture_array
) {
1396 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1400 else if (target
!= GL_TEXTURE_2D
) {
1401 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1405 else if (dimensions
== 3) {
1406 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1407 if (!ctx
->Extensions
.MESA_texture_array
) {
1408 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1412 else if (target
!= GL_TEXTURE_3D
) {
1413 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1418 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1422 /* Basic level check */
1423 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1424 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1429 _mesa_error(ctx
, GL_INVALID_VALUE
,
1430 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1433 if (height
< 0 && dimensions
> 1) {
1434 _mesa_error(ctx
, GL_INVALID_VALUE
,
1435 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1438 if (depth
< 0 && dimensions
> 2) {
1439 _mesa_error(ctx
, GL_INVALID_VALUE
,
1440 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1444 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1445 _mesa_error(ctx
, GL_INVALID_ENUM
,
1446 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1447 dimensions
, format
, type
);
1456 * Do second part of glTexSubImage which depends on the destination texture.
1457 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1460 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1461 GLenum target
, GLint level
,
1462 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1463 GLint width
, GLint height
, GLint depth
,
1464 GLenum format
, GLenum type
,
1465 const struct gl_texture_image
*destTex
)
1468 /* undefined image level */
1469 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1473 if (xoffset
< -((GLint
)destTex
->Border
)) {
1474 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1478 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1479 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1483 if (dimensions
> 1) {
1484 if (yoffset
< -((GLint
)destTex
->Border
)) {
1485 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1489 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1490 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1495 if (dimensions
> 2) {
1496 if (zoffset
< -((GLint
)destTex
->Border
)) {
1497 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1500 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1501 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1506 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1509 if (!target_can_be_compressed(ctx
, target
)) {
1510 _mesa_error(ctx
, GL_INVALID_ENUM
,
1511 "glTexSubImage%dD(target=%s)", dimensions
,
1512 _mesa_lookup_enum_by_nr(target
));
1516 /* do tests which depend on compression block size */
1517 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1519 /* offset must be multiple of block size */
1520 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1521 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1522 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1523 dimensions
, xoffset
, yoffset
);
1526 /* size must be multiple of bw by bh or equal to whole texture size */
1527 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1528 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1529 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1532 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1533 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1534 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1544 * Test glCopyTexImage[12]D() parameters for errors.
1546 * \param ctx GL context.
1547 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1548 * \param target texture target given by the user.
1549 * \param level image level given by the user.
1550 * \param internalFormat internal format given by the user.
1551 * \param width image width given by the user.
1552 * \param height image height given by the user.
1553 * \param border texture border.
1555 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1557 * Verifies each of the parameters against the constants specified in
1558 * __GLcontextRec::Const and the supported extensions, and according to the
1559 * OpenGL specification.
1562 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1563 GLenum target
, GLint level
, GLint internalFormat
,
1564 GLint width
, GLint height
, GLint border
)
1570 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1571 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1572 _mesa_error(ctx
, GL_INVALID_VALUE
,
1573 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1577 /* Check that the source buffer is complete */
1578 if (ctx
->ReadBuffer
->Name
) {
1579 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1580 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1581 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1582 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1588 if (border
< 0 || border
> 1 ||
1589 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1590 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1594 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1596 _mesa_error(ctx
, GL_INVALID_VALUE
,
1597 "glCopyTexImage%dD(internalFormat)", dimensions
);
1601 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1602 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1603 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1607 /* NOTE: the format and type aren't really significant for
1608 * TestProxyTexImage(). Only the internalformat really matters.
1612 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1613 * level, width, height and depth.
1615 if (dimensions
== 1) {
1616 if (target
== GL_TEXTURE_1D
) {
1617 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1618 level
, internalFormat
,
1620 width
, 1, 1, border
);
1623 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1627 else if (dimensions
== 2) {
1628 if (target
== GL_TEXTURE_2D
) {
1629 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1630 level
, internalFormat
,
1632 width
, height
, 1, border
);
1634 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1635 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1636 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1637 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1640 sizeOK
= (width
== height
) &&
1641 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1642 level
, internalFormat
, format
, type
,
1643 width
, height
, 1, border
);
1645 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1646 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1647 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1650 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1651 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1652 level
, internalFormat
,
1654 width
, height
, 1, border
);
1656 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1657 if (!ctx
->Extensions
.MESA_texture_array
) {
1658 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1661 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1662 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1663 level
, internalFormat
,
1665 width
, height
, 1, border
);
1668 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1673 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1678 if (dimensions
== 1) {
1679 _mesa_error(ctx
, GL_INVALID_VALUE
,
1680 "glCopyTexImage1D(width=%d)", width
);
1683 ASSERT(dimensions
== 2);
1684 _mesa_error(ctx
, GL_INVALID_VALUE
,
1685 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1690 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1691 if (!target_can_be_compressed(ctx
, target
)) {
1692 _mesa_error(ctx
, GL_INVALID_ENUM
,
1693 "glCopyTexImage%d(target)", dimensions
);
1697 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1698 "glCopyTexImage%dD(border!=0)", dimensions
);
1702 else if (_mesa_is_depth_format(internalFormat
)) {
1703 /* make sure we have depth/stencil buffers */
1704 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1705 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1706 "glCopyTexImage%dD(no depth)", dimensions
);
1710 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1711 /* make sure we have depth/stencil buffers */
1712 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1713 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1714 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
1719 /* if we get here, the parameters are OK */
1725 * Test glCopyTexSubImage[12]D() parameters for errors.
1726 * Note that this is the first part of error checking.
1727 * See also copytexsubimage_error_check2() below for the second part.
1729 * \param ctx GL context.
1730 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1731 * \param target texture target given by the user.
1732 * \param level image level given by the user.
1734 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1737 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1738 GLenum target
, GLint level
)
1740 /* Check that the source buffer is complete */
1741 if (ctx
->ReadBuffer
->Name
) {
1742 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1743 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1744 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1745 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1751 if (dimensions
== 1) {
1752 if (target
!= GL_TEXTURE_1D
) {
1753 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1757 else if (dimensions
== 2) {
1758 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1759 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1760 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1761 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1765 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1766 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1767 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1771 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1772 if (!ctx
->Extensions
.MESA_texture_array
) {
1773 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1777 else if (target
!= GL_TEXTURE_2D
) {
1778 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1782 else if (dimensions
== 3) {
1783 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1784 (!ctx
->Extensions
.MESA_texture_array
))
1785 && (target
!= GL_TEXTURE_3D
)) {
1786 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1792 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1793 _mesa_error(ctx
, GL_INVALID_VALUE
,
1794 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1803 * Second part of error checking for glCopyTexSubImage[12]D().
1804 * \param xoffset sub-image x offset given by the user.
1805 * \param yoffset sub-image y offset given by the user.
1806 * \param zoffset sub-image z offset given by the user.
1807 * \param width image width given by the user.
1808 * \param height image height given by the user.
1811 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1812 GLenum target
, GLint level
,
1813 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1814 GLsizei width
, GLsizei height
,
1815 const struct gl_texture_image
*teximage
)
1817 /* check that dest tex image exists */
1819 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1820 "glCopyTexSubImage%dD(undefined texture level: %d)",
1827 _mesa_error(ctx
, GL_INVALID_VALUE
,
1828 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1831 if (dimensions
> 1 && height
< 0) {
1832 _mesa_error(ctx
, GL_INVALID_VALUE
,
1833 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1837 /* check x/y offsets */
1838 if (xoffset
< -((GLint
)teximage
->Border
)) {
1839 _mesa_error(ctx
, GL_INVALID_VALUE
,
1840 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1843 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1844 _mesa_error(ctx
, GL_INVALID_VALUE
,
1845 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1848 if (dimensions
> 1) {
1849 if (yoffset
< -((GLint
)teximage
->Border
)) {
1850 _mesa_error(ctx
, GL_INVALID_VALUE
,
1851 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1854 /* NOTE: we're adding the border here, not subtracting! */
1855 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1856 _mesa_error(ctx
, GL_INVALID_VALUE
,
1857 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1862 /* check z offset */
1863 if (dimensions
> 2) {
1864 if (zoffset
< -((GLint
)teximage
->Border
)) {
1865 _mesa_error(ctx
, GL_INVALID_VALUE
,
1866 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1869 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1870 _mesa_error(ctx
, GL_INVALID_VALUE
,
1871 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1876 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
1877 if (!target_can_be_compressed(ctx
, target
)) {
1878 _mesa_error(ctx
, GL_INVALID_ENUM
,
1879 "glCopyTexSubImage%d(target)", dimensions
);
1882 /* offset must be multiple of 4 */
1883 if ((xoffset
& 3) || (yoffset
& 3)) {
1884 _mesa_error(ctx
, GL_INVALID_VALUE
,
1885 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
1888 /* size must be multiple of 4 */
1889 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1890 _mesa_error(ctx
, GL_INVALID_VALUE
,
1891 "glCopyTexSubImage%dD(width)", dimensions
);
1894 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1895 _mesa_error(ctx
, GL_INVALID_VALUE
,
1896 "glCopyTexSubImage%dD(height)", dimensions
);
1901 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
1902 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1906 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
1907 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1908 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
1909 dimensions
, teximage
->_BaseFormat
);
1913 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
1914 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1915 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1916 "glCopyTexSubImage%dD(no depth buffer)",
1921 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
1922 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1923 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1924 "glCopyTexSubImage%dD(no depth/stencil buffer)",
1930 /* if we get here, the parameters are OK */
1935 /** Callback info for walking over FBO hash table */
1939 struct gl_texture_object
*texObj
;
1945 * Check render to texture callback. Called from _mesa_HashWalk().
1948 check_rtt_cb(GLuint key
, void *data
, void *userData
)
1950 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1951 const struct cb_info
*info
= (struct cb_info
*) userData
;
1952 GLcontext
*ctx
= info
->ctx
;
1953 const struct gl_texture_object
*texObj
= info
->texObj
;
1954 const GLuint level
= info
->level
, face
= info
->face
;
1956 /* If this is a user-created FBO */
1959 /* check if any of the FBO's attachments point to 'texObj' */
1960 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1961 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1962 if (att
->Type
== GL_TEXTURE
&&
1963 att
->Texture
== texObj
&&
1964 att
->TextureLevel
== level
&&
1965 att
->CubeMapFace
== face
) {
1966 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
1967 /* Tell driver about the new renderbuffer texture */
1968 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
1969 /* Mark fb status as indeterminate to force re-validation */
1978 * When a texture image is specified we have to check if it's bound to
1979 * any framebuffer objects (render to texture) in order to detect changes
1980 * in size or format since that effects FBO completeness.
1981 * Any FBOs rendering into the texture must be re-validated.
1984 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
1985 GLuint face
, GLuint level
)
1987 /* Only check this texture if it's been marked as RenderToTexture */
1988 if (texObj
->_RenderToTexture
) {
1989 struct cb_info info
;
1991 info
.texObj
= texObj
;
1994 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2000 * If the texture object's GenerateMipmap flag is set and we've
2001 * changed the texture base level image, regenerate the rest of the
2002 * mipmap levels now.
2005 check_gen_mipmap(GLcontext
*ctx
, GLenum target
,
2006 struct gl_texture_object
*texObj
, GLint level
)
2008 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2009 if (texObj
->GenerateMipmap
&&
2010 level
== texObj
->BaseLevel
&&
2011 level
< texObj
->MaxLevel
) {
2012 ASSERT(ctx
->Driver
.GenerateMipmap
);
2013 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2018 /** Debug helper: override the user-requested internal format */
2020 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2023 if (internalFormat
== GL_RGBA16F_ARB
||
2024 internalFormat
== GL_RGBA32F_ARB
) {
2025 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2028 else if (internalFormat
== GL_RGB16F_ARB
||
2029 internalFormat
== GL_RGB32F_ARB
) {
2030 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2033 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2034 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2035 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2036 return GL_LUMINANCE_ALPHA
;
2038 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2039 internalFormat
== GL_LUMINANCE32F_ARB
) {
2040 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2041 return GL_LUMINANCE
;
2043 else if (internalFormat
== GL_ALPHA16F_ARB
||
2044 internalFormat
== GL_ALPHA32F_ARB
) {
2045 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2049 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2050 internalFormat = GL_RGBA;
2054 return internalFormat
;
2057 return internalFormat
;
2063 * Called from the API. Note that width includes the border.
2066 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2067 GLsizei width
, GLint border
, GLenum format
,
2068 GLenum type
, const GLvoid
*pixels
)
2070 GLsizei postConvWidth
= width
;
2071 GET_CURRENT_CONTEXT(ctx
);
2072 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2074 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2075 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2076 _mesa_lookup_enum_by_nr(target
), level
,
2077 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2078 _mesa_lookup_enum_by_nr(format
),
2079 _mesa_lookup_enum_by_nr(type
), pixels
);
2081 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2083 #if FEATURE_convolve
2084 if (_mesa_is_color_format(internalFormat
)) {
2085 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2089 if (target
== GL_TEXTURE_1D
) {
2090 /* non-proxy target */
2091 struct gl_texture_object
*texObj
;
2092 struct gl_texture_image
*texImage
;
2093 const GLuint face
= _mesa_tex_target_to_face(target
);
2095 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2096 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2097 return; /* error was recorded */
2100 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2101 _mesa_update_state(ctx
);
2103 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2104 _mesa_lock_texture(ctx
, texObj
);
2106 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2108 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2111 if (texImage
->Data
) {
2112 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2115 ASSERT(texImage
->Data
== NULL
);
2117 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2118 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2119 postConvWidth
, 1, 1,
2120 border
, internalFormat
);
2122 /* Choose actual texture format */
2123 texImage
->TexFormat
=
2124 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2126 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2128 /* Give the texture to the driver. <pixels> may be null. */
2129 ASSERT(ctx
->Driver
.TexImage1D
);
2130 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2131 width
, border
, format
, type
, pixels
,
2132 &ctx
->Unpack
, texObj
, texImage
);
2134 ASSERT(texImage
->TexFormat
);
2136 _mesa_set_fetch_functions(texImage
, 1);
2138 check_gen_mipmap(ctx
, target
, texObj
, level
);
2140 update_fbo_texture(ctx
, texObj
, face
, level
);
2143 texObj
->_Complete
= GL_FALSE
;
2144 ctx
->NewState
|= _NEW_TEXTURE
;
2147 _mesa_unlock_texture(ctx
, texObj
);
2149 else if (target
== GL_PROXY_TEXTURE_1D
) {
2150 /* Proxy texture: check for errors and update proxy state */
2151 struct gl_texture_image
*texImage
;
2152 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2153 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2154 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2155 /* when error, clear all proxy texture image parameters */
2157 clear_teximage_fields(texImage
);
2160 /* no error, set the tex image parameters */
2162 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2163 postConvWidth
, 1, 1,
2164 border
, internalFormat
);
2165 texImage
->TexFormat
=
2166 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2170 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2177 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2178 GLsizei width
, GLsizei height
, GLint border
,
2179 GLenum format
, GLenum type
,
2180 const GLvoid
*pixels
)
2182 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2183 GET_CURRENT_CONTEXT(ctx
);
2184 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2186 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2187 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2188 _mesa_lookup_enum_by_nr(target
), level
,
2189 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2190 border
, _mesa_lookup_enum_by_nr(format
),
2191 _mesa_lookup_enum_by_nr(type
), pixels
);
2193 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2195 #if FEATURE_convolve
2196 if (_mesa_is_color_format(internalFormat
)) {
2197 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2202 if (target
== GL_TEXTURE_2D
||
2203 (ctx
->Extensions
.ARB_texture_cube_map
&&
2204 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2205 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2206 (ctx
->Extensions
.NV_texture_rectangle
&&
2207 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2208 (ctx
->Extensions
.MESA_texture_array
&&
2209 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2210 /* non-proxy target */
2211 struct gl_texture_object
*texObj
;
2212 struct gl_texture_image
*texImage
;
2213 const GLuint face
= _mesa_tex_target_to_face(target
);
2215 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2216 format
, type
, 2, postConvWidth
, postConvHeight
,
2218 return; /* error was recorded */
2221 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2222 _mesa_update_state(ctx
);
2224 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2225 _mesa_lock_texture(ctx
, texObj
);
2227 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2229 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2232 if (texImage
->Data
) {
2233 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2236 ASSERT(texImage
->Data
== NULL
);
2237 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2238 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2239 postConvWidth
, postConvHeight
, 1,
2240 border
, internalFormat
);
2242 /* Choose actual texture format */
2243 texImage
->TexFormat
=
2244 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2246 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2248 /* Give the texture to the driver. <pixels> may be null. */
2249 ASSERT(ctx
->Driver
.TexImage2D
);
2250 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2251 width
, height
, border
, format
, type
,
2252 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2254 ASSERT(texImage
->TexFormat
);
2256 _mesa_set_fetch_functions(texImage
, 2);
2258 check_gen_mipmap(ctx
, target
, texObj
, level
);
2260 update_fbo_texture(ctx
, texObj
, face
, level
);
2263 texObj
->_Complete
= GL_FALSE
;
2264 ctx
->NewState
|= _NEW_TEXTURE
;
2267 _mesa_unlock_texture(ctx
, texObj
);
2269 else if (target
== GL_PROXY_TEXTURE_2D
||
2270 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2271 ctx
->Extensions
.ARB_texture_cube_map
) ||
2272 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2273 ctx
->Extensions
.NV_texture_rectangle
) ||
2274 (ctx
->Extensions
.MESA_texture_array
&&
2275 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2276 /* Proxy texture: check for errors and update proxy state */
2277 struct gl_texture_image
*texImage
;
2278 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2279 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2280 format
, type
, 2, postConvWidth
, postConvHeight
,
2282 /* when error, clear all proxy texture image parameters */
2284 clear_teximage_fields(texImage
);
2287 /* no error, set the tex image parameters */
2288 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2289 postConvWidth
, postConvHeight
, 1,
2290 border
, internalFormat
);
2291 texImage
->TexFormat
=
2292 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2296 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2303 * Called by the API or display list executor.
2304 * Note that width and height include the border.
2307 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2308 GLsizei width
, GLsizei height
, GLsizei depth
,
2309 GLint border
, GLenum format
, GLenum type
,
2310 const GLvoid
*pixels
)
2312 GET_CURRENT_CONTEXT(ctx
);
2313 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2315 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2316 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2317 _mesa_lookup_enum_by_nr(target
), level
,
2318 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2319 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2320 _mesa_lookup_enum_by_nr(type
), pixels
);
2322 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2324 if (target
== GL_TEXTURE_3D
||
2325 (ctx
->Extensions
.MESA_texture_array
&&
2326 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2327 /* non-proxy target */
2328 struct gl_texture_object
*texObj
;
2329 struct gl_texture_image
*texImage
;
2330 const GLuint face
= _mesa_tex_target_to_face(target
);
2332 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2333 format
, type
, 3, width
, height
, depth
, border
)) {
2334 return; /* error was recorded */
2337 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2338 _mesa_update_state(ctx
);
2340 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2341 _mesa_lock_texture(ctx
, texObj
);
2343 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2345 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2348 if (texImage
->Data
) {
2349 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2352 ASSERT(texImage
->Data
== NULL
);
2353 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2354 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2355 width
, height
, depth
,
2356 border
, internalFormat
);
2358 /* Choose actual texture format */
2359 texImage
->TexFormat
=
2360 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2362 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2364 /* Give the texture to the driver. <pixels> may be null. */
2365 ASSERT(ctx
->Driver
.TexImage3D
);
2366 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2367 width
, height
, depth
, border
, format
, type
,
2368 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2370 ASSERT(texImage
->TexFormat
);
2372 _mesa_set_fetch_functions(texImage
, 3);
2374 check_gen_mipmap(ctx
, target
, texObj
, level
);
2376 update_fbo_texture(ctx
, texObj
, face
, level
);
2379 texObj
->_Complete
= GL_FALSE
;
2380 ctx
->NewState
|= _NEW_TEXTURE
;
2383 _mesa_unlock_texture(ctx
, texObj
);
2385 else if (target
== GL_PROXY_TEXTURE_3D
||
2386 (ctx
->Extensions
.MESA_texture_array
&&
2387 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2388 /* Proxy texture: check for errors and update proxy state */
2389 struct gl_texture_image
*texImage
;
2390 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2391 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2392 format
, type
, 3, width
, height
, depth
, border
)) {
2393 /* when error, clear all proxy texture image parameters */
2395 clear_teximage_fields(texImage
);
2398 /* no error, set the tex image parameters */
2399 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2400 depth
, border
, internalFormat
);
2401 texImage
->TexFormat
=
2402 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2406 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2413 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2414 GLsizei width
, GLsizei height
, GLsizei depth
,
2415 GLint border
, GLenum format
, GLenum type
,
2416 const GLvoid
*pixels
)
2418 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2419 depth
, border
, format
, type
, pixels
);
2423 #if FEATURE_OES_EGL_image
2425 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2427 struct gl_texture_object
*texObj
;
2428 struct gl_texture_image
*texImage
;
2429 GET_CURRENT_CONTEXT(ctx
);
2430 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2432 if (!ctx
->Extensions
.OES_EGL_image
) {
2433 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2434 "glEGLImageTargetTexture2DOES(unsupported)");
2438 if (target
!= GL_TEXTURE_2D
) {
2439 _mesa_error(ctx
, GL_INVALID_ENUM
,
2440 "glEGLImageTargetTexture2D(target=%d)", target
);
2444 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2445 _mesa_update_state(ctx
);
2447 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2448 _mesa_lock_texture(ctx
, texObj
);
2450 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2452 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2455 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2457 ASSERT(texImage
->Data
== NULL
);
2458 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2459 texObj
, texImage
, image
);
2462 texObj
->_Complete
= GL_FALSE
;
2463 ctx
->NewState
|= _NEW_TEXTURE
;
2465 _mesa_unlock_texture(ctx
, texObj
);
2472 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2473 GLint xoffset
, GLsizei width
,
2474 GLenum format
, GLenum type
,
2475 const GLvoid
*pixels
)
2477 GLsizei postConvWidth
= width
;
2478 struct gl_texture_object
*texObj
;
2479 struct gl_texture_image
*texImage
;
2480 GET_CURRENT_CONTEXT(ctx
);
2481 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2483 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2484 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2485 _mesa_lookup_enum_by_nr(target
), level
,
2486 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2487 _mesa_lookup_enum_by_nr(type
), pixels
);
2489 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2490 _mesa_update_state(ctx
);
2492 #if FEATURE_convolve
2493 /* XXX should test internal format */
2494 if (_mesa_is_color_format(format
)) {
2495 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2499 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2500 postConvWidth
, 1, 1, format
, type
)) {
2501 return; /* error was detected */
2505 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2508 _mesa_lock_texture(ctx
, texObj
);
2510 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2512 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2513 postConvWidth
, 1, 1,
2514 format
, type
, texImage
)) {
2515 /* error was recorded */
2517 else if (width
> 0) {
2518 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2519 xoffset
+= texImage
->Border
;
2521 ASSERT(ctx
->Driver
.TexSubImage1D
);
2522 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2523 format
, type
, pixels
, &ctx
->Unpack
,
2526 check_gen_mipmap(ctx
, target
, texObj
, level
);
2528 ctx
->NewState
|= _NEW_TEXTURE
;
2531 _mesa_unlock_texture(ctx
, texObj
);
2536 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2537 GLint xoffset
, GLint yoffset
,
2538 GLsizei width
, GLsizei height
,
2539 GLenum format
, GLenum type
,
2540 const GLvoid
*pixels
)
2542 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2543 struct gl_texture_object
*texObj
;
2544 struct gl_texture_image
*texImage
;
2545 GET_CURRENT_CONTEXT(ctx
);
2546 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2548 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2549 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2550 _mesa_lookup_enum_by_nr(target
), level
,
2551 xoffset
, yoffset
, width
, height
,
2552 _mesa_lookup_enum_by_nr(format
),
2553 _mesa_lookup_enum_by_nr(type
), pixels
);
2555 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2556 _mesa_update_state(ctx
);
2558 #if FEATURE_convolve
2559 /* XXX should test internal format */
2560 if (_mesa_is_color_format(format
)) {
2561 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2566 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2567 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2568 return; /* error was detected */
2571 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2573 _mesa_lock_texture(ctx
, texObj
);
2575 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2577 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2578 postConvWidth
, postConvHeight
, 1,
2579 format
, type
, texImage
)) {
2580 /* error was recorded */
2582 else if (width
> 0 && height
>= 0) {
2583 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2584 xoffset
+= texImage
->Border
;
2585 yoffset
+= texImage
->Border
;
2587 ASSERT(ctx
->Driver
.TexSubImage2D
);
2588 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2589 width
, height
, format
, type
, pixels
,
2590 &ctx
->Unpack
, texObj
, texImage
);
2592 check_gen_mipmap(ctx
, target
, texObj
, level
);
2594 ctx
->NewState
|= _NEW_TEXTURE
;
2597 _mesa_unlock_texture(ctx
, texObj
);
2603 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2604 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2605 GLsizei width
, GLsizei height
, GLsizei depth
,
2606 GLenum format
, GLenum type
,
2607 const GLvoid
*pixels
)
2609 struct gl_texture_object
*texObj
;
2610 struct gl_texture_image
*texImage
;
2611 GET_CURRENT_CONTEXT(ctx
);
2612 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2614 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2615 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2616 _mesa_lookup_enum_by_nr(target
), level
,
2617 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2618 _mesa_lookup_enum_by_nr(format
),
2619 _mesa_lookup_enum_by_nr(type
), pixels
);
2621 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2622 _mesa_update_state(ctx
);
2624 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2625 width
, height
, depth
, format
, type
)) {
2626 return; /* error was detected */
2629 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2631 _mesa_lock_texture(ctx
, texObj
);
2633 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2635 if (subtexture_error_check2(ctx
, 3, target
, level
,
2636 xoffset
, yoffset
, zoffset
,
2637 width
, height
, depth
,
2638 format
, type
, texImage
)) {
2639 /* error was recorded */
2641 else if (width
> 0 && height
> 0 && height
> 0) {
2642 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2643 xoffset
+= texImage
->Border
;
2644 yoffset
+= texImage
->Border
;
2645 zoffset
+= texImage
->Border
;
2647 ASSERT(ctx
->Driver
.TexSubImage3D
);
2648 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2649 xoffset
, yoffset
, zoffset
,
2650 width
, height
, depth
,
2651 format
, type
, pixels
,
2652 &ctx
->Unpack
, texObj
, texImage
);
2654 check_gen_mipmap(ctx
, target
, texObj
, level
);
2656 ctx
->NewState
|= _NEW_TEXTURE
;
2659 _mesa_unlock_texture(ctx
, texObj
);
2665 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2666 GLenum internalFormat
,
2668 GLsizei width
, GLint border
)
2670 struct gl_texture_object
*texObj
;
2671 struct gl_texture_image
*texImage
;
2672 GLsizei postConvWidth
= width
;
2673 const GLuint face
= _mesa_tex_target_to_face(target
);
2674 GET_CURRENT_CONTEXT(ctx
);
2675 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2677 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2678 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2679 _mesa_lookup_enum_by_nr(target
), level
,
2680 _mesa_lookup_enum_by_nr(internalFormat
),
2681 x
, y
, width
, border
);
2683 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2684 _mesa_update_state(ctx
);
2686 #if FEATURE_convolve
2687 if (_mesa_is_color_format(internalFormat
)) {
2688 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2692 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2693 postConvWidth
, 1, border
))
2696 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2698 _mesa_lock_texture(ctx
, texObj
);
2700 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2702 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2705 if (texImage
->Data
) {
2706 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2709 ASSERT(texImage
->Data
== NULL
);
2711 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2712 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2713 border
, internalFormat
);
2715 /* Choose actual texture format */
2716 texImage
->TexFormat
=
2717 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2719 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2721 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2722 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2723 x
, y
, width
, border
);
2725 ASSERT(texImage
->TexFormat
);
2727 _mesa_set_fetch_functions(texImage
, 1);
2729 check_gen_mipmap(ctx
, target
, texObj
, level
);
2731 update_fbo_texture(ctx
, texObj
, face
, level
);
2734 texObj
->_Complete
= GL_FALSE
;
2735 ctx
->NewState
|= _NEW_TEXTURE
;
2738 _mesa_unlock_texture(ctx
, texObj
);
2744 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2745 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2748 struct gl_texture_object
*texObj
;
2749 struct gl_texture_image
*texImage
;
2750 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2751 const GLuint face
= _mesa_tex_target_to_face(target
);
2752 GET_CURRENT_CONTEXT(ctx
);
2753 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2755 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2756 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2757 _mesa_lookup_enum_by_nr(target
), level
,
2758 _mesa_lookup_enum_by_nr(internalFormat
),
2759 x
, y
, width
, height
, border
);
2761 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2762 _mesa_update_state(ctx
);
2764 #if FEATURE_convolve
2765 if (_mesa_is_color_format(internalFormat
)) {
2766 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2771 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2772 postConvWidth
, postConvHeight
, border
))
2775 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2777 _mesa_lock_texture(ctx
, texObj
);
2779 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2782 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2785 if (texImage
->Data
) {
2786 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2789 ASSERT(texImage
->Data
== NULL
);
2791 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2792 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2793 postConvWidth
, postConvHeight
, 1,
2794 border
, internalFormat
);
2796 /* Choose actual texture format */
2797 texImage
->TexFormat
=
2798 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2800 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2802 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2803 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2804 x
, y
, width
, height
, border
);
2806 ASSERT(texImage
->TexFormat
);
2808 _mesa_set_fetch_functions(texImage
, 2);
2810 check_gen_mipmap(ctx
, target
, texObj
, level
);
2812 update_fbo_texture(ctx
, texObj
, face
, level
);
2815 texObj
->_Complete
= GL_FALSE
;
2816 ctx
->NewState
|= _NEW_TEXTURE
;
2819 _mesa_unlock_texture(ctx
, texObj
);
2824 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2825 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2827 struct gl_texture_object
*texObj
;
2828 struct gl_texture_image
*texImage
;
2829 GLsizei postConvWidth
= width
;
2833 GET_CURRENT_CONTEXT(ctx
);
2834 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2836 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2837 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2838 _mesa_lookup_enum_by_nr(target
),
2839 level
, xoffset
, x
, y
, width
);
2841 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2842 _mesa_update_state(ctx
);
2844 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2847 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2849 _mesa_lock_texture(ctx
, texObj
);
2851 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2853 #if FEATURE_convolve
2854 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2855 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2859 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2860 xoffset
, 0, 0, postConvWidth
, 1,
2862 /* error was recorded */
2865 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2866 xoffset
+= texImage
->Border
;
2868 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2870 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2871 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2872 xoffset
, x
, y
, width
);
2874 check_gen_mipmap(ctx
, target
, texObj
, level
);
2876 ctx
->NewState
|= _NEW_TEXTURE
;
2880 _mesa_unlock_texture(ctx
, texObj
);
2886 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2887 GLint xoffset
, GLint yoffset
,
2888 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2890 struct gl_texture_object
*texObj
;
2891 struct gl_texture_image
*texImage
;
2892 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2893 GET_CURRENT_CONTEXT(ctx
);
2894 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2896 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2897 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2898 _mesa_lookup_enum_by_nr(target
),
2899 level
, xoffset
, yoffset
, x
, y
, width
, height
);
2901 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2902 _mesa_update_state(ctx
);
2904 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2907 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2909 _mesa_lock_texture(ctx
, texObj
);
2911 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2913 #if FEATURE_convolve
2914 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2915 _mesa_adjust_image_for_convolution(ctx
, 2,
2916 &postConvWidth
, &postConvHeight
);
2920 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
2921 xoffset
, yoffset
, 0,
2922 postConvWidth
, postConvHeight
,
2924 /* error was recorded */
2927 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2928 xoffset
+= texImage
->Border
;
2929 yoffset
+= texImage
->Border
;
2931 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2933 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2934 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2935 x
, y
, width
, height
);
2937 check_gen_mipmap(ctx
, target
, texObj
, level
);
2939 ctx
->NewState
|= _NEW_TEXTURE
;
2943 _mesa_unlock_texture(ctx
, texObj
);
2949 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2950 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2951 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2953 struct gl_texture_object
*texObj
;
2954 struct gl_texture_image
*texImage
;
2955 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2956 GET_CURRENT_CONTEXT(ctx
);
2957 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2959 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2960 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
2961 _mesa_lookup_enum_by_nr(target
),
2962 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2964 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2965 _mesa_update_state(ctx
);
2967 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2970 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2972 _mesa_lock_texture(ctx
, texObj
);
2974 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2976 #if FEATURE_convolve
2977 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2978 _mesa_adjust_image_for_convolution(ctx
, 2,
2979 &postConvWidth
, &postConvHeight
);
2983 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2984 zoffset
, postConvWidth
, postConvHeight
,
2986 /* error was recored */
2989 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2990 xoffset
+= texImage
->Border
;
2991 yoffset
+= texImage
->Border
;
2992 zoffset
+= texImage
->Border
;
2994 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2996 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2997 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2998 xoffset
, yoffset
, zoffset
,
2999 x
, y
, width
, height
);
3001 check_gen_mipmap(ctx
, target
, texObj
, level
);
3003 ctx
->NewState
|= _NEW_TEXTURE
;
3007 _mesa_unlock_texture(ctx
, texObj
);
3013 /**********************************************************************/
3014 /****** Compressed Textures ******/
3015 /**********************************************************************/
3019 * Return expected size of a compressed texture.
3022 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3025 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3026 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3031 * Return compressed texture block size, in pixels.
3034 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3036 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3037 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3042 * Error checking for glCompressedTexImage[123]D().
3043 * \return error code or GL_NO_ERROR.
3046 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3047 GLenum target
, GLint level
,
3048 GLenum internalFormat
, GLsizei width
,
3049 GLsizei height
, GLsizei depth
, GLint border
,
3052 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3054 if (dimensions
== 1) {
3055 /* 1D compressed textures not allowed */
3056 return GL_INVALID_ENUM
;
3058 else if (dimensions
== 2) {
3059 if (target
== GL_PROXY_TEXTURE_2D
) {
3060 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3062 else if (target
== GL_TEXTURE_2D
) {
3063 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3065 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3066 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3067 return GL_INVALID_ENUM
; /*target*/
3068 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3070 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3071 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3072 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3073 return GL_INVALID_ENUM
; /*target*/
3074 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3077 return GL_INVALID_ENUM
; /*target*/
3080 else if (dimensions
== 3) {
3081 /* 3D compressed textures not allowed */
3082 return GL_INVALID_ENUM
;
3085 maxTextureSize
= 1 << (maxLevels
- 1);
3087 /* This will detect any invalid internalFormat value */
3088 if (!_mesa_is_compressed_format(ctx
, internalFormat
))
3089 return GL_INVALID_ENUM
;
3091 /* This should really never fail */
3092 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3093 return GL_INVALID_ENUM
;
3096 return GL_INVALID_VALUE
;
3099 * XXX We should probably use the proxy texture error check function here.
3101 if (width
< 1 || width
> maxTextureSize
||
3102 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3103 return GL_INVALID_VALUE
;
3105 if ((height
< 1 || height
> maxTextureSize
||
3106 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3108 return GL_INVALID_VALUE
;
3110 if ((depth
< 1 || depth
> maxTextureSize
||
3111 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3113 return GL_INVALID_VALUE
;
3115 /* For cube map, width must equal height */
3116 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3117 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3118 return GL_INVALID_VALUE
;
3120 if (level
< 0 || level
>= maxLevels
)
3121 return GL_INVALID_VALUE
;
3123 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3124 if (expectedSize
!= imageSize
)
3125 return GL_INVALID_VALUE
;
3127 #if FEATURE_EXT_texture_sRGB
3128 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3129 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3130 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3131 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3133 return GL_INVALID_OPERATION
;
3142 * Error checking for glCompressedTexSubImage[123]D().
3143 * \warning There are some bad assumptions here about the size of compressed
3144 * texture tiles (multiple of 4) used to test the validity of the
3145 * offset and size parameters.
3146 * \return error code or GL_NO_ERROR.
3149 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3150 GLenum target
, GLint level
,
3151 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3152 GLsizei width
, GLsizei height
, GLsizei depth
,
3153 GLenum format
, GLsizei imageSize
)
3155 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3159 if (dimensions
== 1) {
3160 /* 1D compressed textures not allowed */
3161 return GL_INVALID_ENUM
;
3163 else if (dimensions
== 2) {
3164 if (target
== GL_PROXY_TEXTURE_2D
) {
3165 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3167 else if (target
== GL_TEXTURE_2D
) {
3168 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3170 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3171 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3172 return GL_INVALID_ENUM
; /*target*/
3173 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3175 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3176 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3177 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3178 return GL_INVALID_ENUM
; /*target*/
3179 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3182 return GL_INVALID_ENUM
; /*target*/
3185 else if (dimensions
== 3) {
3186 /* 3D compressed textures not allowed */
3187 return GL_INVALID_ENUM
;
3190 maxTextureSize
= 1 << (maxLevels
- 1);
3192 /* this will catch any invalid compressed format token */
3193 if (!_mesa_is_compressed_format(ctx
, format
))
3194 return GL_INVALID_ENUM
;
3196 if (width
< 1 || width
> maxTextureSize
)
3197 return GL_INVALID_VALUE
;
3199 if ((height
< 1 || height
> maxTextureSize
)
3201 return GL_INVALID_VALUE
;
3203 if (level
< 0 || level
>= maxLevels
)
3204 return GL_INVALID_VALUE
;
3207 * do checks which depend on compression block size
3209 get_compressed_block_size(format
, &bw
, &bh
);
3211 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3212 return GL_INVALID_VALUE
;
3214 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3215 return GL_INVALID_VALUE
;
3217 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3218 return GL_INVALID_VALUE
;
3220 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3221 if (expectedSize
!= imageSize
)
3222 return GL_INVALID_VALUE
;
3229 * Do second part of glCompressedTexSubImage error checking.
3230 * \return GL_TRUE if error found, GL_FALSE otherwise.
3233 compressed_subtexture_error_check2(GLcontext
*ctx
, GLuint dims
,
3234 GLsizei width
, GLsizei height
,
3235 GLsizei depth
, GLenum format
,
3236 struct gl_texture_image
*texImage
)
3239 if ((GLint
) format
!= texImage
->InternalFormat
) {
3240 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3241 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3245 if (((width
== 1 || width
== 2) &&
3246 width
!= (GLsizei
) texImage
->Width
) ||
3247 (width
> (GLsizei
) texImage
->Width
)) {
3248 _mesa_error(ctx
, GL_INVALID_VALUE
,
3249 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3254 if (((height
== 1 || height
== 2) &&
3255 height
!= (GLsizei
) texImage
->Height
) ||
3256 (height
> (GLsizei
) texImage
->Height
)) {
3257 _mesa_error(ctx
, GL_INVALID_VALUE
,
3258 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3264 if (((depth
== 1 || depth
== 2) &&
3265 depth
!= (GLsizei
) texImage
->Depth
) ||
3266 (depth
> (GLsizei
) texImage
->Depth
)) {
3267 _mesa_error(ctx
, GL_INVALID_VALUE
,
3268 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3279 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3280 GLenum internalFormat
, GLsizei width
,
3281 GLint border
, GLsizei imageSize
,
3284 GET_CURRENT_CONTEXT(ctx
);
3285 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3287 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3288 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3289 _mesa_lookup_enum_by_nr(target
), level
,
3290 _mesa_lookup_enum_by_nr(internalFormat
),
3291 width
, border
, imageSize
, data
);
3293 if (target
== GL_TEXTURE_1D
) {
3294 /* non-proxy target */
3295 struct gl_texture_object
*texObj
;
3296 struct gl_texture_image
*texImage
;
3297 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3298 internalFormat
, width
, 1, 1, border
, imageSize
);
3300 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3304 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3306 _mesa_lock_texture(ctx
, texObj
);
3308 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3310 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3313 if (texImage
->Data
) {
3314 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3316 ASSERT(texImage
->Data
== NULL
);
3318 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3319 border
, internalFormat
);
3321 /* Choose actual texture format */
3322 texImage
->TexFormat
=
3323 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3325 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3327 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3328 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3329 internalFormat
, width
, border
,
3333 _mesa_set_fetch_functions(texImage
, 1);
3335 check_gen_mipmap(ctx
, target
, texObj
, level
);
3338 texObj
->_Complete
= GL_FALSE
;
3339 ctx
->NewState
|= _NEW_TEXTURE
;
3342 _mesa_unlock_texture(ctx
, texObj
);
3344 else if (target
== GL_PROXY_TEXTURE_1D
) {
3345 /* Proxy texture: check for errors and update proxy state */
3346 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3347 internalFormat
, width
, 1, 1, border
, imageSize
);
3349 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3350 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3351 internalFormat
, GL_NONE
, GL_NONE
,
3352 width
, 1, 1, border
);
3355 /* if error, clear all proxy texture image parameters */
3356 struct gl_texture_image
*texImage
;
3357 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3359 clear_teximage_fields(texImage
);
3362 /* store the teximage parameters */
3363 struct gl_texture_object
*texObj
;
3364 struct gl_texture_image
*texImage
;
3366 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3368 _mesa_lock_texture(ctx
, texObj
);
3370 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3371 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3372 border
, internalFormat
);
3374 _mesa_unlock_texture(ctx
, texObj
);
3378 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3385 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3386 GLenum internalFormat
, GLsizei width
,
3387 GLsizei height
, GLint border
, GLsizei imageSize
,
3390 GET_CURRENT_CONTEXT(ctx
);
3391 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3393 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3394 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3395 _mesa_lookup_enum_by_nr(target
), level
,
3396 _mesa_lookup_enum_by_nr(internalFormat
),
3397 width
, height
, border
, imageSize
, data
);
3399 if (target
== GL_TEXTURE_2D
||
3400 (ctx
->Extensions
.ARB_texture_cube_map
&&
3401 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3402 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3403 /* non-proxy target */
3404 struct gl_texture_object
*texObj
;
3405 struct gl_texture_image
*texImage
;
3407 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3408 internalFormat
, width
, height
, 1, border
, imageSize
);
3410 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3414 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3416 _mesa_lock_texture(ctx
, texObj
);
3418 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3420 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3423 if (texImage
->Data
) {
3424 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3426 ASSERT(texImage
->Data
== NULL
);
3428 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3429 border
, internalFormat
);
3431 /* Choose actual texture format */
3432 texImage
->TexFormat
=
3433 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3435 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3437 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3438 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3439 internalFormat
, width
, height
,
3440 border
, imageSize
, data
,
3443 _mesa_set_fetch_functions(texImage
, 2);
3445 check_gen_mipmap(ctx
, target
, texObj
, level
);
3448 texObj
->_Complete
= GL_FALSE
;
3449 ctx
->NewState
|= _NEW_TEXTURE
;
3452 _mesa_unlock_texture(ctx
, texObj
);
3454 else if (target
== GL_PROXY_TEXTURE_2D
||
3455 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3456 ctx
->Extensions
.ARB_texture_cube_map
)) {
3457 /* Proxy texture: check for errors and update proxy state */
3458 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3459 internalFormat
, width
, height
, 1, border
, imageSize
);
3461 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3462 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3463 internalFormat
, GL_NONE
, GL_NONE
,
3464 width
, height
, 1, border
);
3467 /* if error, clear all proxy texture image parameters */
3468 struct gl_texture_image
*texImage
;
3469 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3471 clear_teximage_fields(texImage
);
3474 /* store the teximage parameters */
3475 struct gl_texture_object
*texObj
;
3476 struct gl_texture_image
*texImage
;
3478 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3480 _mesa_lock_texture(ctx
, texObj
);
3482 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3483 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3484 border
, internalFormat
);
3486 _mesa_unlock_texture(ctx
, texObj
);
3490 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3497 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3498 GLenum internalFormat
, GLsizei width
,
3499 GLsizei height
, GLsizei depth
, GLint border
,
3500 GLsizei imageSize
, const GLvoid
*data
)
3502 GET_CURRENT_CONTEXT(ctx
);
3503 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3505 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3506 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3507 _mesa_lookup_enum_by_nr(target
), level
,
3508 _mesa_lookup_enum_by_nr(internalFormat
),
3509 width
, height
, depth
, border
, imageSize
, data
);
3511 if (target
== GL_TEXTURE_3D
) {
3512 /* non-proxy target */
3513 struct gl_texture_object
*texObj
;
3514 struct gl_texture_image
*texImage
;
3515 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3516 internalFormat
, width
, height
, depth
, border
, imageSize
);
3518 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3522 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3524 _mesa_lock_texture(ctx
, texObj
);
3526 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3528 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3531 if (texImage
->Data
) {
3532 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3534 ASSERT(texImage
->Data
== NULL
);
3536 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3537 width
, height
, depth
,
3538 border
, internalFormat
);
3540 /* Choose actual texture format */
3541 texImage
->TexFormat
=
3542 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3544 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3546 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3547 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3549 width
, height
, depth
,
3550 border
, imageSize
, data
,
3553 _mesa_set_fetch_functions(texImage
, 3);
3555 check_gen_mipmap(ctx
, target
, texObj
, level
);
3558 texObj
->_Complete
= GL_FALSE
;
3559 ctx
->NewState
|= _NEW_TEXTURE
;
3562 _mesa_unlock_texture(ctx
, texObj
);
3564 else if (target
== GL_PROXY_TEXTURE_3D
) {
3565 /* Proxy texture: check for errors and update proxy state */
3566 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3567 internalFormat
, width
, height
, depth
, border
, imageSize
);
3569 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3570 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3571 internalFormat
, GL_NONE
, GL_NONE
,
3572 width
, height
, depth
, border
);
3575 /* if error, clear all proxy texture image parameters */
3576 struct gl_texture_image
*texImage
;
3577 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3579 clear_teximage_fields(texImage
);
3582 /* store the teximage parameters */
3583 struct gl_texture_object
*texObj
;
3584 struct gl_texture_image
*texImage
;
3586 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3588 _mesa_lock_texture(ctx
, texObj
);
3590 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3591 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3592 depth
, border
, internalFormat
);
3594 _mesa_unlock_texture(ctx
, texObj
);
3598 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3605 * Common helper for glCompressedTexSubImage1/2/3D().
3608 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3609 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3610 GLsizei width
, GLsizei height
, GLsizei depth
,
3611 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3613 struct gl_texture_object
*texObj
;
3614 struct gl_texture_image
*texImage
;
3616 GET_CURRENT_CONTEXT(ctx
);
3617 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3619 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3620 xoffset
, 0, 0, /* pos */
3621 width
, height
, depth
, /* size */
3624 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3628 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3630 _mesa_lock_texture(ctx
, texObj
);
3632 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3635 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3636 format
, texImage
)) {
3637 /* error was recorded */
3639 else if (width
> 0 && height
> 0 && depth
> 0) {
3642 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3643 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3645 format
, imageSize
, data
,
3650 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3651 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3654 format
, imageSize
, data
,
3659 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3660 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3661 xoffset
, yoffset
, zoffset
,
3662 width
, height
, depth
,
3663 format
, imageSize
, data
,
3671 check_gen_mipmap(ctx
, target
, texObj
, level
);
3673 ctx
->NewState
|= _NEW_TEXTURE
;
3676 _mesa_unlock_texture(ctx
, texObj
);
3681 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3682 GLsizei width
, GLenum format
,
3683 GLsizei imageSize
, const GLvoid
*data
)
3685 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3686 format
, imageSize
, data
);
3691 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3692 GLint yoffset
, GLsizei width
, GLsizei height
,
3693 GLenum format
, GLsizei imageSize
,
3696 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3697 width
, height
, 1, format
, imageSize
, data
);
3702 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3703 GLint yoffset
, GLint zoffset
, GLsizei width
,
3704 GLsizei height
, GLsizei depth
, GLenum format
,
3705 GLsizei imageSize
, const GLvoid
*data
)
3707 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3708 width
, height
, depth
, format
, imageSize
, data
);