2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
39 #include "framebuffer.h"
45 #include "texcompress.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
65 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
69 _mesa_alloc_texmemory(GLsizei bytes
)
71 return _mesa_align_malloc(bytes
, 512);
76 * Free texture memory allocated with _mesa_alloc_texmemory()
79 _mesa_free_texmemory(void *m
)
86 * Compute floor(log_base_2(n)).
116 * Return the simple base format for a given internal texture format.
117 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
119 * \param ctx GL context.
120 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
122 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
123 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
125 * This is the format which is used during texture application (i.e. the
126 * texture format and env mode determine the arithmetic used.
128 * XXX this could be static
131 _mesa_base_tex_format( GLcontext
*ctx
, GLint internalFormat
)
133 switch (internalFormat
) {
148 case GL_LUMINANCE_ALPHA
:
149 case GL_LUMINANCE4_ALPHA4
:
150 case GL_LUMINANCE6_ALPHA2
:
151 case GL_LUMINANCE8_ALPHA8
:
152 case GL_LUMINANCE12_ALPHA4
:
153 case GL_LUMINANCE12_ALPHA12
:
154 case GL_LUMINANCE16_ALPHA16
:
155 return GL_LUMINANCE_ALPHA
;
186 if (ctx
->Extensions
.EXT_paletted_texture
) {
187 switch (internalFormat
) {
189 case GL_COLOR_INDEX1_EXT
:
190 case GL_COLOR_INDEX2_EXT
:
191 case GL_COLOR_INDEX4_EXT
:
192 case GL_COLOR_INDEX8_EXT
:
193 case GL_COLOR_INDEX12_EXT
:
194 case GL_COLOR_INDEX16_EXT
:
195 return GL_COLOR_INDEX
;
201 if (ctx
->Extensions
.ARB_depth_texture
) {
202 switch (internalFormat
) {
203 case GL_DEPTH_COMPONENT
:
204 case GL_DEPTH_COMPONENT16
:
205 case GL_DEPTH_COMPONENT24
:
206 case GL_DEPTH_COMPONENT32
:
207 return GL_DEPTH_COMPONENT
;
213 switch (internalFormat
) {
214 case GL_COMPRESSED_ALPHA
:
216 case GL_COMPRESSED_LUMINANCE
:
218 case GL_COMPRESSED_LUMINANCE_ALPHA
:
219 return GL_LUMINANCE_ALPHA
;
220 case GL_COMPRESSED_INTENSITY
:
222 case GL_COMPRESSED_RGB
:
224 case GL_COMPRESSED_RGBA
:
230 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
231 switch (internalFormat
) {
232 case GL_COMPRESSED_RGB_FXT1_3DFX
:
234 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
241 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
242 switch (internalFormat
) {
243 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
245 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
246 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
247 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
254 if (ctx
->Extensions
.S3_s3tc
) {
255 switch (internalFormat
) {
267 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
268 if (internalFormat
== GL_YCBCR_MESA
)
269 return GL_YCBCR_MESA
;
272 if (ctx
->Extensions
.ARB_texture_float
) {
273 switch (internalFormat
) {
274 case GL_ALPHA16F_ARB
:
275 case GL_ALPHA32F_ARB
:
283 case GL_INTENSITY16F_ARB
:
284 case GL_INTENSITY32F_ARB
:
286 case GL_LUMINANCE16F_ARB
:
287 case GL_LUMINANCE32F_ARB
:
289 case GL_LUMINANCE_ALPHA16F_ARB
:
290 case GL_LUMINANCE_ALPHA32F_ARB
:
291 return GL_LUMINANCE_ALPHA
;
297 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
298 switch (internalFormat
) {
307 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
308 switch (internalFormat
) {
317 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
318 switch (internalFormat
) {
319 case GL_DEPTH_STENCIL_EXT
:
320 case GL_DEPTH24_STENCIL8_EXT
:
321 return GL_DEPTH_STENCIL_EXT
;
327 #if FEATURE_EXT_texture_sRGB
328 if (ctx
->Extensions
.EXT_texture_sRGB
) {
329 switch (internalFormat
) {
332 case GL_COMPRESSED_SRGB_EXT
:
333 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
335 case GL_SRGB_ALPHA_EXT
:
336 case GL_SRGB8_ALPHA8_EXT
:
337 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
338 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
339 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
340 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
342 case GL_SLUMINANCE_ALPHA_EXT
:
343 case GL_SLUMINANCE8_ALPHA8_EXT
:
344 case GL_COMPRESSED_SLUMINANCE_EXT
:
345 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
346 return GL_LUMINANCE_ALPHA
;
347 case GL_SLUMINANCE_EXT
:
348 case GL_SLUMINANCE8_EXT
:
355 #endif /* FEATURE_EXT_texture_sRGB */
357 return -1; /* error */
362 * For cube map faces, return a face index in [0,5].
363 * For other targets return 0;
366 _mesa_tex_target_to_face(GLenum target
)
368 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
369 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
370 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
378 * Store a gl_texture_image pointer in a gl_texture_object structure
379 * according to the target and level parameters.
381 * \param tObj texture object.
382 * \param target texture target.
383 * \param level image level.
384 * \param texImage texture image.
386 * This was basically prompted by the introduction of cube maps.
389 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
390 GLenum target
, GLint level
,
391 struct gl_texture_image
*texImage
)
393 const GLuint face
= _mesa_tex_target_to_face(target
);
397 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
399 tObj
->Image
[face
][level
] = texImage
;
401 /* Set the 'back' pointer */
402 texImage
->TexObject
= tObj
;
407 * Allocate a texture image structure.
409 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
412 * \return a pointer to gl_texture_image struct with all fields initialized to
415 struct gl_texture_image
*
416 _mesa_new_texture_image( GLcontext
*ctx
)
419 return CALLOC_STRUCT(gl_texture_image
);
424 * Free texture image data.
425 * This function is a fallback called via ctx->Driver.FreeTexImageData().
427 * \param texImage texture image.
429 * Free the texture image data if it's not marked as client data.
432 _mesa_free_texture_image_data(GLcontext
*ctx
,
433 struct gl_texture_image
*texImage
)
437 if (texImage
->Data
&& !texImage
->IsClientData
) {
438 /* free the old texture data */
439 _mesa_free_texmemory(texImage
->Data
);
442 texImage
->Data
= NULL
;
447 * Free texture image.
449 * \param texImage texture image.
451 * Free the texture image structure and the associated image data.
454 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
456 /* Free texImage->Data and/or any other driver-specific texture
459 ASSERT(ctx
->Driver
.FreeTexImageData
);
460 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
462 ASSERT(texImage
->Data
== NULL
);
463 if (texImage
->ImageOffsets
)
464 free(texImage
->ImageOffsets
);
470 * Test if a target is a proxy target.
472 * \param target texture target.
474 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
477 _mesa_is_proxy_texture(GLenum target
)
479 /* NUM_TEXTURE_TARGETS should match number of terms below */
480 assert(NUM_TEXTURE_TARGETS
== 7);
482 return (target
== GL_PROXY_TEXTURE_1D
||
483 target
== GL_PROXY_TEXTURE_2D
||
484 target
== GL_PROXY_TEXTURE_3D
||
485 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
486 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
487 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
488 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
493 * Get the texture object that corresponds to the target of the given texture unit.
495 * \param ctx GL context.
496 * \param texUnit texture unit.
497 * \param target texture target.
499 * \return pointer to the texture object on success, or NULL on failure.
501 * \sa gl_texture_unit.
503 struct gl_texture_object
*
504 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
509 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
510 case GL_PROXY_TEXTURE_1D
:
511 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
513 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
514 case GL_PROXY_TEXTURE_2D
:
515 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
517 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
518 case GL_PROXY_TEXTURE_3D
:
519 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
520 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
521 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
522 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
523 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
524 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
525 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
526 case GL_TEXTURE_CUBE_MAP_ARB
:
527 return ctx
->Extensions
.ARB_texture_cube_map
528 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
529 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
530 return ctx
->Extensions
.ARB_texture_cube_map
531 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
532 case GL_TEXTURE_RECTANGLE_NV
:
533 return ctx
->Extensions
.NV_texture_rectangle
534 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
535 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
536 return ctx
->Extensions
.NV_texture_rectangle
537 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
538 case GL_TEXTURE_1D_ARRAY_EXT
:
539 return ctx
->Extensions
.MESA_texture_array
540 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
541 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
542 return ctx
->Extensions
.MESA_texture_array
543 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
544 case GL_TEXTURE_2D_ARRAY_EXT
:
545 return ctx
->Extensions
.MESA_texture_array
546 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
547 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
548 return ctx
->Extensions
.MESA_texture_array
549 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
551 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
558 * Return pointer to texture object for given target on current texture unit.
560 struct gl_texture_object
*
561 _mesa_get_current_tex_object(GLcontext
*ctx
, GLenum target
)
563 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
564 return _mesa_select_tex_object(ctx
, texUnit
, target
);
569 * Get a texture image pointer from a texture object, given a texture
570 * target and mipmap level. The target and level parameters should
571 * have already been error-checked.
573 * \param ctx GL context.
574 * \param texObj texture unit.
575 * \param target texture target.
576 * \param level image level.
578 * \return pointer to the texture image structure, or NULL on failure.
580 struct gl_texture_image
*
581 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
582 GLenum target
, GLint level
)
584 const GLuint face
= _mesa_tex_target_to_face(target
);
588 ASSERT(level
< MAX_TEXTURE_LEVELS
);
590 return texObj
->Image
[face
][level
];
595 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
596 * it and install it. Only return NULL if passed a bad parameter or run
599 struct gl_texture_image
*
600 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
601 GLenum target
, GLint level
)
603 struct gl_texture_image
*texImage
;
608 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
610 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
612 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
616 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
624 * Return pointer to the specified proxy texture image.
625 * Note that proxy textures are per-context, not per-texture unit.
626 * \return pointer to texture image or NULL if invalid target, invalid
627 * level, or out of memory.
629 struct gl_texture_image
*
630 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
632 struct gl_texture_image
*texImage
;
639 case GL_PROXY_TEXTURE_1D
:
640 if (level
>= ctx
->Const
.MaxTextureLevels
)
642 texIndex
= TEXTURE_1D_INDEX
;
644 case GL_PROXY_TEXTURE_2D
:
645 if (level
>= ctx
->Const
.MaxTextureLevels
)
647 texIndex
= TEXTURE_2D_INDEX
;
649 case GL_PROXY_TEXTURE_3D
:
650 if (level
>= ctx
->Const
.Max3DTextureLevels
)
652 texIndex
= TEXTURE_3D_INDEX
;
654 case GL_PROXY_TEXTURE_CUBE_MAP
:
655 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
657 texIndex
= TEXTURE_CUBE_INDEX
;
659 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
662 texIndex
= TEXTURE_RECT_INDEX
;
664 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
665 if (level
>= ctx
->Const
.MaxTextureLevels
)
667 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
669 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
670 if (level
>= ctx
->Const
.MaxTextureLevels
)
672 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
678 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
680 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
682 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
685 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
686 /* Set the 'back' pointer */
687 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
694 * Get the maximum number of allowed mipmap levels.
696 * \param ctx GL context.
697 * \param target texture target.
699 * \return the maximum number of allowed mipmap levels for the given
700 * texture target, or zero if passed a bad target.
705 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
709 case GL_PROXY_TEXTURE_1D
:
711 case GL_PROXY_TEXTURE_2D
:
712 return ctx
->Const
.MaxTextureLevels
;
714 case GL_PROXY_TEXTURE_3D
:
715 return ctx
->Const
.Max3DTextureLevels
;
716 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
717 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
718 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
719 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
720 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
721 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
722 case GL_TEXTURE_CUBE_MAP_ARB
:
723 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
724 return ctx
->Extensions
.ARB_texture_cube_map
725 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
726 case GL_TEXTURE_RECTANGLE_NV
:
727 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
728 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
729 case GL_TEXTURE_1D_ARRAY_EXT
:
730 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
731 case GL_TEXTURE_2D_ARRAY_EXT
:
732 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
733 return ctx
->Extensions
.MESA_texture_array
734 ? ctx
->Const
.MaxTextureLevels
: 0;
736 return 0; /* bad target */
742 #if 000 /* not used anymore */
744 * glTexImage[123]D can accept a NULL image pointer. In this case we
745 * create a texture image with unspecified image contents per the OpenGL
749 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
751 const GLint components
= _mesa_components_in_format(format
);
752 const GLint numPixels
= width
* height
* depth
;
753 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
757 * Let's see if anyone finds this. If glTexImage2D() is called with
758 * a NULL image pointer then load the texture image with something
759 * interesting instead of leaving it indeterminate.
762 static const char message
[8][32] = {
766 " X X XXXX XXX XXXXX ",
769 " X X XXXXX XXX X X ",
773 GLubyte
*imgPtr
= data
;
775 for (h
= 0; h
< depth
; h
++) {
776 for (i
= 0; i
< height
; i
++) {
777 GLint srcRow
= 7 - (i
% 8);
778 for (j
= 0; j
< width
; j
++) {
779 GLint srcCol
= j
% 32;
780 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
781 for (k
= 0; k
< components
; k
++) {
797 * Reset the fields of a gl_texture_image struct to zero.
799 * \param img texture image structure.
801 * This is called when a proxy texture test fails, we set all the
802 * image members (except DriverData) to zero.
803 * It's also used in glTexImage[123]D as a safeguard to be sure all
804 * required fields get initialized properly by the Driver.TexImage[123]D
808 clear_teximage_fields(struct gl_texture_image
*img
)
811 img
->_BaseFormat
= 0;
812 img
->InternalFormat
= 0;
818 if (img
->ImageOffsets
) {
819 free(img
->ImageOffsets
);
820 img
->ImageOffsets
= NULL
;
829 img
->TexFormat
= MESA_FORMAT_NONE
;
830 img
->FetchTexelc
= NULL
;
831 img
->FetchTexelf
= NULL
;
836 * Initialize basic fields of the gl_texture_image struct.
838 * \param ctx GL context.
839 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
840 * \param img texture image structure to be initialized.
841 * \param width image width.
842 * \param height image height.
843 * \param depth image depth.
844 * \param border image border.
845 * \param internalFormat internal format.
847 * Fills in the fields of \p img with the given information.
848 * Note: width, height and depth include the border.
851 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
852 struct gl_texture_image
*img
,
853 GLsizei width
, GLsizei height
, GLsizei depth
,
854 GLint border
, GLenum internalFormat
)
863 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
864 ASSERT(img
->_BaseFormat
> 0);
865 img
->InternalFormat
= internalFormat
;
866 img
->Border
= border
;
868 img
->Height
= height
;
871 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
872 img
->WidthLog2
= logbase2(img
->Width2
);
874 if (height
== 1) { /* 1-D texture */
879 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
880 img
->HeightLog2
= logbase2(img
->Height2
);
883 if (depth
== 1) { /* 2-D texture */
888 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
889 img
->DepthLog2
= logbase2(img
->Depth2
);
892 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
894 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
895 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
896 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
897 img
->_IsPowerOfTwo
= GL_TRUE
;
899 img
->_IsPowerOfTwo
= GL_FALSE
;
901 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
902 img
->RowStride
= width
;
903 /* Allocate the ImageOffsets array and initialize to typical values.
904 * We allocate the array for 1D/2D textures too in order to avoid special-
905 * case code in the texstore routines.
907 if (img
->ImageOffsets
)
908 free(img
->ImageOffsets
);
909 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
910 for (i
= 0; i
< depth
; i
++) {
911 img
->ImageOffsets
[i
] = i
* width
* height
;
914 /* Compute Width/Height/DepthScale for mipmap lod computation */
915 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
916 /* scale = 1.0 since texture coords directly map to texels */
917 img
->WidthScale
= 1.0;
918 img
->HeightScale
= 1.0;
919 img
->DepthScale
= 1.0;
922 img
->WidthScale
= (GLfloat
) img
->Width
;
923 img
->HeightScale
= (GLfloat
) img
->Height
;
924 img
->DepthScale
= (GLfloat
) img
->Depth
;
927 img
->FetchTexelc
= NULL
;
928 img
->FetchTexelf
= NULL
;
933 * Free and clear fields of the gl_texture_image struct.
935 * \param ctx GL context.
936 * \param texImage texture image structure to be cleared.
938 * After the call, \p texImage will have no data associated with it. Its
939 * fields are cleared so that its parent object will test incomplete.
942 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
944 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
945 clear_teximage_fields(texImage
);
950 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
951 * level, width, height and depth against the ctx->Const limits for textures.
953 * A hardware driver might override this function if, for example, the
954 * max 3D texture size is 512x512x64 (i.e. not a cube).
956 * Note that width, height, depth == 0 is not an error. However, a
957 * texture with zero width/height/depth will be considered "incomplete"
958 * and texturing will effectively be disabled.
960 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
961 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
962 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
963 * \param level as passed to glTexImage
964 * \param internalFormat as passed to glTexImage
965 * \param format as passed to glTexImage
966 * \param type as passed to glTexImage
967 * \param width as passed to glTexImage
968 * \param height as passed to glTexImage
969 * \param depth as passed to glTexImage
970 * \param border as passed to glTexImage
971 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
974 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
975 GLint internalFormat
, GLenum format
, GLenum type
,
976 GLint width
, GLint height
, GLint depth
, GLint border
)
980 (void) internalFormat
;
985 case GL_PROXY_TEXTURE_1D
:
986 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
987 if (width
< 2 * border
|| width
> 2 + maxSize
||
988 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
989 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
990 level
>= ctx
->Const
.MaxTextureLevels
) {
991 /* bad width or level */
995 case GL_PROXY_TEXTURE_2D
:
996 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
997 if (width
< 2 * border
|| width
> 2 + maxSize
||
998 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
999 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1000 height
< 2 * border
|| height
> 2 + maxSize
||
1001 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1002 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1003 level
>= ctx
->Const
.MaxTextureLevels
) {
1004 /* bad width or height or level */
1008 case GL_PROXY_TEXTURE_3D
:
1009 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1010 if (width
< 2 * border
|| width
> 2 + maxSize
||
1011 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1012 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1013 height
< 2 * border
|| height
> 2 + maxSize
||
1014 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1015 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1016 depth
< 2 * border
|| depth
> 2 + maxSize
||
1017 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1018 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1019 level
>= ctx
->Const
.Max3DTextureLevels
) {
1020 /* bad width or height or depth or level */
1024 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1025 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1026 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1028 /* bad width or height or level */
1032 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1033 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1034 if (width
< 2 * border
|| width
> 2 + maxSize
||
1035 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1036 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1037 height
< 2 * border
|| height
> 2 + maxSize
||
1038 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1039 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1040 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1041 /* bad width or height */
1045 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1046 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1047 if (width
< 2 * border
|| width
> 2 + maxSize
||
1048 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1049 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1050 level
>= ctx
->Const
.MaxTextureLevels
) {
1051 /* bad width or level */
1055 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1059 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1060 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1061 if (width
< 2 * border
|| width
> 2 + maxSize
||
1062 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1063 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1064 height
< 2 * border
|| height
> 2 + maxSize
||
1065 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1066 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1067 level
>= ctx
->Const
.MaxTextureLevels
) {
1068 /* bad width or height or level */
1071 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1076 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1083 * Helper function to determine whether a target supports compressed textures
1086 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1088 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1089 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1090 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1091 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1092 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1093 || ((ctx
->Extensions
.MESA_texture_array
&&
1094 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1095 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1100 * Test the glTexImage[123]D() parameters for errors.
1102 * \param ctx GL context.
1103 * \param target texture target given by the user.
1104 * \param level image level given by the user.
1105 * \param internalFormat internal format given by the user.
1106 * \param format pixel data format given by the user.
1107 * \param type pixel data type given by the user.
1108 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1109 * \param width image width given by the user.
1110 * \param height image height given by the user.
1111 * \param depth image depth given by the user.
1112 * \param border image border given by the user.
1114 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1116 * Verifies each of the parameters against the constants specified in
1117 * __GLcontextRec::Const and the supported extensions, and according to the
1118 * OpenGL specification.
1121 texture_error_check( GLcontext
*ctx
, GLenum target
,
1122 GLint level
, GLint internalFormat
,
1123 GLenum format
, GLenum type
,
1125 GLint width
, GLint height
,
1126 GLint depth
, GLint border
)
1128 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1129 GLboolean sizeOK
= GL_TRUE
;
1130 GLboolean colorFormat
, indexFormat
;
1131 GLenum proxy_target
;
1133 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1134 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1136 _mesa_error(ctx
, GL_INVALID_VALUE
,
1137 "glTexImage%dD(level=%d)", dimensions
, level
);
1143 if (border
< 0 || border
> 1 ||
1144 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1145 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1147 _mesa_error(ctx
, GL_INVALID_VALUE
,
1148 "glTexImage%dD(border=%d)", dimensions
, border
);
1153 if (width
< 0 || height
< 0 || depth
< 0) {
1155 _mesa_error(ctx
, GL_INVALID_VALUE
,
1156 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1161 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1162 * level, width, height and depth.
1164 if (dimensions
== 1) {
1165 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1166 proxy_target
= GL_PROXY_TEXTURE_1D
;
1171 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1175 else if (dimensions
== 2) {
1177 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1178 proxy_target
= GL_PROXY_TEXTURE_2D
;
1180 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1181 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1182 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1183 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1184 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1187 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1188 sizeOK
= (width
== height
);
1190 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1191 target
== GL_TEXTURE_RECTANGLE_NV
) {
1192 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1193 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1196 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1198 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1199 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1200 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1203 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1207 else if (dimensions
== 3) {
1208 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1209 proxy_target
= GL_PROXY_TEXTURE_3D
;
1211 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1212 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1213 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1216 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1221 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1225 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1226 internalFormat
, format
,
1227 type
, width
, height
,
1231 _mesa_error(ctx
, GL_INVALID_VALUE
,
1232 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1233 dimensions
, level
, width
, height
, depth
);
1238 /* Check internalFormat */
1239 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1241 _mesa_error(ctx
, GL_INVALID_VALUE
,
1242 "glTexImage%dD(internalFormat=%s)",
1243 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1248 /* Check incoming image format and type */
1249 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1250 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1251 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1254 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1255 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1256 dimensions
, format
, type
);
1261 /* make sure internal format and format basically agree */
1262 colorFormat
= _mesa_is_color_format(format
);
1263 indexFormat
= _mesa_is_index_format(format
);
1264 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1265 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1266 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1267 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1268 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1269 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1271 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1272 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1273 dimensions
, internalFormat
, format
);
1277 /* additional checks for ycbcr textures */
1278 if (internalFormat
== GL_YCBCR_MESA
) {
1279 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1280 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1281 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1283 _mesa_snprintf(message
, sizeof(message
),
1284 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1285 _mesa_error(ctx
, GL_INVALID_ENUM
, message
);
1286 return GL_TRUE
; /* error */
1288 if (target
!= GL_TEXTURE_2D
&&
1289 target
!= GL_PROXY_TEXTURE_2D
&&
1290 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1291 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1293 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1299 _mesa_snprintf(message
, sizeof(message
),
1300 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1301 dimensions
, border
);
1302 _mesa_error(ctx
, GL_INVALID_VALUE
, message
);
1308 /* additional checks for depth textures */
1309 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1310 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1311 if (target
!= GL_TEXTURE_1D
&&
1312 target
!= GL_PROXY_TEXTURE_1D
&&
1313 target
!= GL_TEXTURE_2D
&&
1314 target
!= GL_PROXY_TEXTURE_2D
&&
1315 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1316 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1318 _mesa_error(ctx
, GL_INVALID_ENUM
,
1319 "glTexImage(target/internalFormat)");
1324 /* additional checks for compressed textures */
1325 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1326 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1327 _mesa_error(ctx
, GL_INVALID_ENUM
,
1328 "glTexImage%dD(target)", dimensions
);
1333 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1334 "glTexImage%dD(border!=0)", dimensions
);
1340 /* if we get here, the parameters are OK */
1346 * Test glTexSubImage[123]D() parameters for errors.
1348 * \param ctx GL context.
1349 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1350 * \param target texture target given by the user.
1351 * \param level image level given by the user.
1352 * \param xoffset sub-image x offset given by the user.
1353 * \param yoffset sub-image y offset given by the user.
1354 * \param zoffset sub-image z offset given by the user.
1355 * \param format pixel data format given by the user.
1356 * \param type pixel data type given by the user.
1357 * \param width image width given by the user.
1358 * \param height image height given by the user.
1359 * \param depth image depth given by the user.
1361 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1363 * Verifies each of the parameters against the constants specified in
1364 * __GLcontextRec::Const and the supported extensions, and according to the
1365 * OpenGL specification.
1368 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1369 GLenum target
, GLint level
,
1370 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1371 GLint width
, GLint height
, GLint depth
,
1372 GLenum format
, GLenum type
)
1375 if (dimensions
== 1) {
1376 if (target
!= GL_TEXTURE_1D
) {
1377 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1381 else if (dimensions
== 2) {
1382 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1383 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1384 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1385 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1389 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1390 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1391 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1395 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1396 if (!ctx
->Extensions
.MESA_texture_array
) {
1397 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1401 else if (target
!= GL_TEXTURE_2D
) {
1402 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1406 else if (dimensions
== 3) {
1407 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1408 if (!ctx
->Extensions
.MESA_texture_array
) {
1409 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1413 else if (target
!= GL_TEXTURE_3D
) {
1414 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1419 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1423 /* Basic level check */
1424 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1425 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1430 _mesa_error(ctx
, GL_INVALID_VALUE
,
1431 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1434 if (height
< 0 && dimensions
> 1) {
1435 _mesa_error(ctx
, GL_INVALID_VALUE
,
1436 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1439 if (depth
< 0 && dimensions
> 2) {
1440 _mesa_error(ctx
, GL_INVALID_VALUE
,
1441 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1445 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1446 _mesa_error(ctx
, GL_INVALID_ENUM
,
1447 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1448 dimensions
, format
, type
);
1457 * Do second part of glTexSubImage which depends on the destination texture.
1458 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1461 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1462 GLenum target
, GLint level
,
1463 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1464 GLint width
, GLint height
, GLint depth
,
1465 GLenum format
, GLenum type
,
1466 const struct gl_texture_image
*destTex
)
1469 /* undefined image level */
1470 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1474 if (xoffset
< -((GLint
)destTex
->Border
)) {
1475 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1479 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1480 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1484 if (dimensions
> 1) {
1485 if (yoffset
< -((GLint
)destTex
->Border
)) {
1486 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1490 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1491 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1496 if (dimensions
> 2) {
1497 if (zoffset
< -((GLint
)destTex
->Border
)) {
1498 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1501 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1502 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1507 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1510 if (!target_can_be_compressed(ctx
, target
)) {
1511 _mesa_error(ctx
, GL_INVALID_ENUM
,
1512 "glTexSubImage%dD(target=%s)", dimensions
,
1513 _mesa_lookup_enum_by_nr(target
));
1517 /* do tests which depend on compression block size */
1518 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1520 /* offset must be multiple of block size */
1521 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1522 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1523 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1524 dimensions
, xoffset
, yoffset
);
1527 /* size must be multiple of bw by bh or equal to whole texture size */
1528 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1529 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1530 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1533 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1534 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1535 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1545 * Test glCopyTexImage[12]D() parameters for errors.
1547 * \param ctx GL context.
1548 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1549 * \param target texture target given by the user.
1550 * \param level image level given by the user.
1551 * \param internalFormat internal format given by the user.
1552 * \param width image width given by the user.
1553 * \param height image height given by the user.
1554 * \param border texture border.
1556 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1558 * Verifies each of the parameters against the constants specified in
1559 * __GLcontextRec::Const and the supported extensions, and according to the
1560 * OpenGL specification.
1563 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1564 GLenum target
, GLint level
, GLint internalFormat
,
1565 GLint width
, GLint height
, GLint border
)
1571 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1572 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1573 _mesa_error(ctx
, GL_INVALID_VALUE
,
1574 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1578 /* Check that the source buffer is complete */
1579 if (ctx
->ReadBuffer
->Name
) {
1580 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1581 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1582 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1583 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1589 if (border
< 0 || border
> 1 ||
1590 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1591 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1595 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1597 _mesa_error(ctx
, GL_INVALID_VALUE
,
1598 "glCopyTexImage%dD(internalFormat)", dimensions
);
1602 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1603 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1604 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1608 /* NOTE: the format and type aren't really significant for
1609 * TestProxyTexImage(). Only the internalformat really matters.
1613 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1614 * level, width, height and depth.
1616 if (dimensions
== 1) {
1617 if (target
== GL_TEXTURE_1D
) {
1618 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1619 level
, internalFormat
,
1621 width
, 1, 1, border
);
1624 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1628 else if (dimensions
== 2) {
1629 if (target
== GL_TEXTURE_2D
) {
1630 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1631 level
, internalFormat
,
1633 width
, height
, 1, border
);
1635 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1636 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1637 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1638 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1641 sizeOK
= (width
== height
) &&
1642 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1643 level
, internalFormat
, format
, type
,
1644 width
, height
, 1, border
);
1646 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1647 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1648 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1651 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1652 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1653 level
, internalFormat
,
1655 width
, height
, 1, border
);
1657 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1658 if (!ctx
->Extensions
.MESA_texture_array
) {
1659 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1662 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1663 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1664 level
, internalFormat
,
1666 width
, height
, 1, border
);
1669 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1674 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1679 if (dimensions
== 1) {
1680 _mesa_error(ctx
, GL_INVALID_VALUE
,
1681 "glCopyTexImage1D(width=%d)", width
);
1684 ASSERT(dimensions
== 2);
1685 _mesa_error(ctx
, GL_INVALID_VALUE
,
1686 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1691 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1692 if (!target_can_be_compressed(ctx
, target
)) {
1693 _mesa_error(ctx
, GL_INVALID_ENUM
,
1694 "glCopyTexImage%dD(target)", dimensions
);
1698 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1699 "glCopyTexImage%dD(border!=0)", dimensions
);
1703 else if (_mesa_is_depth_format(internalFormat
)) {
1704 /* make sure we have depth/stencil buffers */
1705 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1706 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1707 "glCopyTexImage%dD(no depth)", dimensions
);
1711 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1712 /* make sure we have depth/stencil buffers */
1713 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1714 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1715 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
1720 /* if we get here, the parameters are OK */
1726 * Test glCopyTexSubImage[12]D() parameters for errors.
1727 * Note that this is the first part of error checking.
1728 * See also copytexsubimage_error_check2() below for the second part.
1730 * \param ctx GL context.
1731 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1732 * \param target texture target given by the user.
1733 * \param level image level given by the user.
1735 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1738 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1739 GLenum target
, GLint level
)
1741 /* Check that the source buffer is complete */
1742 if (ctx
->ReadBuffer
->Name
) {
1743 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1744 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1745 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1746 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1752 if (dimensions
== 1) {
1753 if (target
!= GL_TEXTURE_1D
) {
1754 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1758 else if (dimensions
== 2) {
1759 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1760 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1761 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1762 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1766 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1767 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1768 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1772 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1773 if (!ctx
->Extensions
.MESA_texture_array
) {
1774 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1778 else if (target
!= GL_TEXTURE_2D
) {
1779 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1783 else if (dimensions
== 3) {
1784 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1785 (!ctx
->Extensions
.MESA_texture_array
))
1786 && (target
!= GL_TEXTURE_3D
)) {
1787 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1793 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1794 _mesa_error(ctx
, GL_INVALID_VALUE
,
1795 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1804 * Second part of error checking for glCopyTexSubImage[12]D().
1805 * \param xoffset sub-image x offset given by the user.
1806 * \param yoffset sub-image y offset given by the user.
1807 * \param zoffset sub-image z offset given by the user.
1808 * \param width image width given by the user.
1809 * \param height image height given by the user.
1812 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1813 GLenum target
, GLint level
,
1814 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1815 GLsizei width
, GLsizei height
,
1816 const struct gl_texture_image
*teximage
)
1818 /* check that dest tex image exists */
1820 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1821 "glCopyTexSubImage%dD(undefined texture level: %d)",
1828 _mesa_error(ctx
, GL_INVALID_VALUE
,
1829 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1832 if (dimensions
> 1 && height
< 0) {
1833 _mesa_error(ctx
, GL_INVALID_VALUE
,
1834 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1838 /* check x/y offsets */
1839 if (xoffset
< -((GLint
)teximage
->Border
)) {
1840 _mesa_error(ctx
, GL_INVALID_VALUE
,
1841 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1844 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1845 _mesa_error(ctx
, GL_INVALID_VALUE
,
1846 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1849 if (dimensions
> 1) {
1850 if (yoffset
< -((GLint
)teximage
->Border
)) {
1851 _mesa_error(ctx
, GL_INVALID_VALUE
,
1852 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1855 /* NOTE: we're adding the border here, not subtracting! */
1856 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1857 _mesa_error(ctx
, GL_INVALID_VALUE
,
1858 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1863 /* check z offset */
1864 if (dimensions
> 2) {
1865 if (zoffset
< -((GLint
)teximage
->Border
)) {
1866 _mesa_error(ctx
, GL_INVALID_VALUE
,
1867 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1870 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1871 _mesa_error(ctx
, GL_INVALID_VALUE
,
1872 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
1877 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
1878 if (!target_can_be_compressed(ctx
, target
)) {
1879 _mesa_error(ctx
, GL_INVALID_ENUM
,
1880 "glCopyTexSubImage%dD(target)", dimensions
);
1883 /* offset must be multiple of 4 */
1884 if ((xoffset
& 3) || (yoffset
& 3)) {
1885 _mesa_error(ctx
, GL_INVALID_VALUE
,
1886 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
1889 /* size must be multiple of 4 */
1890 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
1891 _mesa_error(ctx
, GL_INVALID_VALUE
,
1892 "glCopyTexSubImage%dD(width)", dimensions
);
1895 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
1896 _mesa_error(ctx
, GL_INVALID_VALUE
,
1897 "glCopyTexSubImage%dD(height)", dimensions
);
1902 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
1903 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
1907 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
1908 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1909 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
1910 dimensions
, teximage
->_BaseFormat
);
1914 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
1915 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1916 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1917 "glCopyTexSubImage%dD(no depth buffer)",
1922 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
1923 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1924 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1925 "glCopyTexSubImage%dD(no depth/stencil buffer)",
1931 /* if we get here, the parameters are OK */
1936 /** Callback info for walking over FBO hash table */
1940 struct gl_texture_object
*texObj
;
1946 * Check render to texture callback. Called from _mesa_HashWalk().
1949 check_rtt_cb(GLuint key
, void *data
, void *userData
)
1951 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
1952 const struct cb_info
*info
= (struct cb_info
*) userData
;
1953 GLcontext
*ctx
= info
->ctx
;
1954 const struct gl_texture_object
*texObj
= info
->texObj
;
1955 const GLuint level
= info
->level
, face
= info
->face
;
1957 /* If this is a user-created FBO */
1960 /* check if any of the FBO's attachments point to 'texObj' */
1961 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
1962 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
1963 if (att
->Type
== GL_TEXTURE
&&
1964 att
->Texture
== texObj
&&
1965 att
->TextureLevel
== level
&&
1966 att
->CubeMapFace
== face
) {
1967 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
1968 /* Tell driver about the new renderbuffer texture */
1969 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
1970 /* Mark fb status as indeterminate to force re-validation */
1979 * When a texture image is specified we have to check if it's bound to
1980 * any framebuffer objects (render to texture) in order to detect changes
1981 * in size or format since that effects FBO completeness.
1982 * Any FBOs rendering into the texture must be re-validated.
1985 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
1986 GLuint face
, GLuint level
)
1988 /* Only check this texture if it's been marked as RenderToTexture */
1989 if (texObj
->_RenderToTexture
) {
1990 struct cb_info info
;
1992 info
.texObj
= texObj
;
1995 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2001 * If the texture object's GenerateMipmap flag is set and we've
2002 * changed the texture base level image, regenerate the rest of the
2003 * mipmap levels now.
2006 check_gen_mipmap(GLcontext
*ctx
, GLenum target
,
2007 struct gl_texture_object
*texObj
, GLint level
)
2009 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2010 if (texObj
->GenerateMipmap
&&
2011 level
== texObj
->BaseLevel
&&
2012 level
< texObj
->MaxLevel
) {
2013 ASSERT(ctx
->Driver
.GenerateMipmap
);
2014 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2019 /** Debug helper: override the user-requested internal format */
2021 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2024 if (internalFormat
== GL_RGBA16F_ARB
||
2025 internalFormat
== GL_RGBA32F_ARB
) {
2026 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2029 else if (internalFormat
== GL_RGB16F_ARB
||
2030 internalFormat
== GL_RGB32F_ARB
) {
2031 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2034 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2035 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2036 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2037 return GL_LUMINANCE_ALPHA
;
2039 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2040 internalFormat
== GL_LUMINANCE32F_ARB
) {
2041 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2042 return GL_LUMINANCE
;
2044 else if (internalFormat
== GL_ALPHA16F_ARB
||
2045 internalFormat
== GL_ALPHA32F_ARB
) {
2046 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2050 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2051 internalFormat = GL_RGBA;
2055 return internalFormat
;
2058 return internalFormat
;
2064 * Called from the API. Note that width includes the border.
2067 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2068 GLsizei width
, GLint border
, GLenum format
,
2069 GLenum type
, const GLvoid
*pixels
)
2071 GLsizei postConvWidth
= width
;
2072 GET_CURRENT_CONTEXT(ctx
);
2073 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2075 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2076 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2077 _mesa_lookup_enum_by_nr(target
), level
,
2078 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2079 _mesa_lookup_enum_by_nr(format
),
2080 _mesa_lookup_enum_by_nr(type
), pixels
);
2082 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2084 #if FEATURE_convolve
2085 if (_mesa_is_color_format(internalFormat
)) {
2086 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2090 if (target
== GL_TEXTURE_1D
) {
2091 /* non-proxy target */
2092 struct gl_texture_object
*texObj
;
2093 struct gl_texture_image
*texImage
;
2094 const GLuint face
= _mesa_tex_target_to_face(target
);
2096 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2097 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2098 return; /* error was recorded */
2101 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2102 _mesa_update_state(ctx
);
2104 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2105 _mesa_lock_texture(ctx
, texObj
);
2107 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2109 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2112 if (texImage
->Data
) {
2113 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2116 ASSERT(texImage
->Data
== NULL
);
2118 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2119 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2120 postConvWidth
, 1, 1,
2121 border
, internalFormat
);
2123 /* Choose actual texture format */
2124 texImage
->TexFormat
=
2125 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2127 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2129 /* Give the texture to the driver. <pixels> may be null. */
2130 ASSERT(ctx
->Driver
.TexImage1D
);
2131 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2132 width
, border
, format
, type
, pixels
,
2133 &ctx
->Unpack
, texObj
, texImage
);
2135 ASSERT(texImage
->TexFormat
);
2137 _mesa_set_fetch_functions(texImage
, 1);
2139 check_gen_mipmap(ctx
, target
, texObj
, level
);
2141 update_fbo_texture(ctx
, texObj
, face
, level
);
2144 texObj
->_Complete
= GL_FALSE
;
2145 ctx
->NewState
|= _NEW_TEXTURE
;
2148 _mesa_unlock_texture(ctx
, texObj
);
2150 else if (target
== GL_PROXY_TEXTURE_1D
) {
2151 /* Proxy texture: check for errors and update proxy state */
2152 struct gl_texture_image
*texImage
;
2153 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2154 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2155 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2156 /* when error, clear all proxy texture image parameters */
2158 clear_teximage_fields(texImage
);
2161 /* no error, set the tex image parameters */
2163 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2164 postConvWidth
, 1, 1,
2165 border
, internalFormat
);
2166 texImage
->TexFormat
=
2167 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2171 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2178 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2179 GLsizei width
, GLsizei height
, GLint border
,
2180 GLenum format
, GLenum type
,
2181 const GLvoid
*pixels
)
2183 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2184 GET_CURRENT_CONTEXT(ctx
);
2185 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2187 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2188 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2189 _mesa_lookup_enum_by_nr(target
), level
,
2190 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2191 border
, _mesa_lookup_enum_by_nr(format
),
2192 _mesa_lookup_enum_by_nr(type
), pixels
);
2194 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2196 #if FEATURE_convolve
2197 if (_mesa_is_color_format(internalFormat
)) {
2198 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2203 if (target
== GL_TEXTURE_2D
||
2204 (ctx
->Extensions
.ARB_texture_cube_map
&&
2205 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2206 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2207 (ctx
->Extensions
.NV_texture_rectangle
&&
2208 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2209 (ctx
->Extensions
.MESA_texture_array
&&
2210 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2211 /* non-proxy target */
2212 struct gl_texture_object
*texObj
;
2213 struct gl_texture_image
*texImage
;
2214 const GLuint face
= _mesa_tex_target_to_face(target
);
2216 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2217 format
, type
, 2, postConvWidth
, postConvHeight
,
2219 return; /* error was recorded */
2222 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2223 _mesa_update_state(ctx
);
2225 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2226 _mesa_lock_texture(ctx
, texObj
);
2228 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2230 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2233 if (texImage
->Data
) {
2234 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2237 ASSERT(texImage
->Data
== NULL
);
2238 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2239 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2240 postConvWidth
, postConvHeight
, 1,
2241 border
, internalFormat
);
2243 /* Choose actual texture format */
2244 texImage
->TexFormat
=
2245 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2247 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2249 /* Give the texture to the driver. <pixels> may be null. */
2250 ASSERT(ctx
->Driver
.TexImage2D
);
2251 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2252 width
, height
, border
, format
, type
,
2253 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2255 ASSERT(texImage
->TexFormat
);
2257 _mesa_set_fetch_functions(texImage
, 2);
2259 check_gen_mipmap(ctx
, target
, texObj
, level
);
2261 update_fbo_texture(ctx
, texObj
, face
, level
);
2264 texObj
->_Complete
= GL_FALSE
;
2265 ctx
->NewState
|= _NEW_TEXTURE
;
2268 _mesa_unlock_texture(ctx
, texObj
);
2270 else if (target
== GL_PROXY_TEXTURE_2D
||
2271 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2272 ctx
->Extensions
.ARB_texture_cube_map
) ||
2273 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2274 ctx
->Extensions
.NV_texture_rectangle
) ||
2275 (ctx
->Extensions
.MESA_texture_array
&&
2276 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2277 /* Proxy texture: check for errors and update proxy state */
2278 struct gl_texture_image
*texImage
;
2279 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2280 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2281 format
, type
, 2, postConvWidth
, postConvHeight
,
2283 /* when error, clear all proxy texture image parameters */
2285 clear_teximage_fields(texImage
);
2288 /* no error, set the tex image parameters */
2289 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2290 postConvWidth
, postConvHeight
, 1,
2291 border
, internalFormat
);
2292 texImage
->TexFormat
=
2293 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2297 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2304 * Called by the API or display list executor.
2305 * Note that width and height include the border.
2308 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2309 GLsizei width
, GLsizei height
, GLsizei depth
,
2310 GLint border
, GLenum format
, GLenum type
,
2311 const GLvoid
*pixels
)
2313 GET_CURRENT_CONTEXT(ctx
);
2314 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2316 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2317 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2318 _mesa_lookup_enum_by_nr(target
), level
,
2319 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2320 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2321 _mesa_lookup_enum_by_nr(type
), pixels
);
2323 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2325 if (target
== GL_TEXTURE_3D
||
2326 (ctx
->Extensions
.MESA_texture_array
&&
2327 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2328 /* non-proxy target */
2329 struct gl_texture_object
*texObj
;
2330 struct gl_texture_image
*texImage
;
2331 const GLuint face
= _mesa_tex_target_to_face(target
);
2333 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2334 format
, type
, 3, width
, height
, depth
, border
)) {
2335 return; /* error was recorded */
2338 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2339 _mesa_update_state(ctx
);
2341 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2342 _mesa_lock_texture(ctx
, texObj
);
2344 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2346 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2349 if (texImage
->Data
) {
2350 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2353 ASSERT(texImage
->Data
== NULL
);
2354 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2355 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2356 width
, height
, depth
,
2357 border
, internalFormat
);
2359 /* Choose actual texture format */
2360 texImage
->TexFormat
=
2361 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2363 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2365 /* Give the texture to the driver. <pixels> may be null. */
2366 ASSERT(ctx
->Driver
.TexImage3D
);
2367 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2368 width
, height
, depth
, border
, format
, type
,
2369 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2371 ASSERT(texImage
->TexFormat
);
2373 _mesa_set_fetch_functions(texImage
, 3);
2375 check_gen_mipmap(ctx
, target
, texObj
, level
);
2377 update_fbo_texture(ctx
, texObj
, face
, level
);
2380 texObj
->_Complete
= GL_FALSE
;
2381 ctx
->NewState
|= _NEW_TEXTURE
;
2384 _mesa_unlock_texture(ctx
, texObj
);
2386 else if (target
== GL_PROXY_TEXTURE_3D
||
2387 (ctx
->Extensions
.MESA_texture_array
&&
2388 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2389 /* Proxy texture: check for errors and update proxy state */
2390 struct gl_texture_image
*texImage
;
2391 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2392 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2393 format
, type
, 3, width
, height
, depth
, border
)) {
2394 /* when error, clear all proxy texture image parameters */
2396 clear_teximage_fields(texImage
);
2399 /* no error, set the tex image parameters */
2400 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2401 depth
, border
, internalFormat
);
2402 texImage
->TexFormat
=
2403 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2407 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2414 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2415 GLsizei width
, GLsizei height
, GLsizei depth
,
2416 GLint border
, GLenum format
, GLenum type
,
2417 const GLvoid
*pixels
)
2419 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2420 depth
, border
, format
, type
, pixels
);
2424 #if FEATURE_OES_EGL_image
2426 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2428 struct gl_texture_object
*texObj
;
2429 struct gl_texture_image
*texImage
;
2430 GET_CURRENT_CONTEXT(ctx
);
2431 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2433 if (!ctx
->Extensions
.OES_EGL_image
) {
2434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2435 "glEGLImageTargetTexture2DOES(unsupported)");
2439 if (target
!= GL_TEXTURE_2D
) {
2440 _mesa_error(ctx
, GL_INVALID_ENUM
,
2441 "glEGLImageTargetTexture2D(target=%d)", target
);
2445 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2446 _mesa_update_state(ctx
);
2448 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2449 _mesa_lock_texture(ctx
, texObj
);
2451 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2453 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2456 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2458 ASSERT(texImage
->Data
== NULL
);
2459 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2460 texObj
, texImage
, image
);
2463 texObj
->_Complete
= GL_FALSE
;
2464 ctx
->NewState
|= _NEW_TEXTURE
;
2466 _mesa_unlock_texture(ctx
, texObj
);
2473 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2474 GLint xoffset
, GLsizei width
,
2475 GLenum format
, GLenum type
,
2476 const GLvoid
*pixels
)
2478 GLsizei postConvWidth
= width
;
2479 struct gl_texture_object
*texObj
;
2480 struct gl_texture_image
*texImage
;
2481 GET_CURRENT_CONTEXT(ctx
);
2482 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2484 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2485 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2486 _mesa_lookup_enum_by_nr(target
), level
,
2487 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2488 _mesa_lookup_enum_by_nr(type
), pixels
);
2490 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2491 _mesa_update_state(ctx
);
2493 #if FEATURE_convolve
2494 /* XXX should test internal format */
2495 if (_mesa_is_color_format(format
)) {
2496 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2500 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2501 postConvWidth
, 1, 1, format
, type
)) {
2502 return; /* error was detected */
2506 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2509 _mesa_lock_texture(ctx
, texObj
);
2511 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2513 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2514 postConvWidth
, 1, 1,
2515 format
, type
, texImage
)) {
2516 /* error was recorded */
2518 else if (width
> 0) {
2519 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2520 xoffset
+= texImage
->Border
;
2522 ASSERT(ctx
->Driver
.TexSubImage1D
);
2523 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2524 format
, type
, pixels
, &ctx
->Unpack
,
2527 check_gen_mipmap(ctx
, target
, texObj
, level
);
2529 ctx
->NewState
|= _NEW_TEXTURE
;
2532 _mesa_unlock_texture(ctx
, texObj
);
2537 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2538 GLint xoffset
, GLint yoffset
,
2539 GLsizei width
, GLsizei height
,
2540 GLenum format
, GLenum type
,
2541 const GLvoid
*pixels
)
2543 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2544 struct gl_texture_object
*texObj
;
2545 struct gl_texture_image
*texImage
;
2546 GET_CURRENT_CONTEXT(ctx
);
2547 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2549 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2550 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2551 _mesa_lookup_enum_by_nr(target
), level
,
2552 xoffset
, yoffset
, width
, height
,
2553 _mesa_lookup_enum_by_nr(format
),
2554 _mesa_lookup_enum_by_nr(type
), pixels
);
2556 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2557 _mesa_update_state(ctx
);
2559 #if FEATURE_convolve
2560 /* XXX should test internal format */
2561 if (_mesa_is_color_format(format
)) {
2562 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2567 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2568 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2569 return; /* error was detected */
2572 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2574 _mesa_lock_texture(ctx
, texObj
);
2576 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2578 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2579 postConvWidth
, postConvHeight
, 1,
2580 format
, type
, texImage
)) {
2581 /* error was recorded */
2583 else if (width
> 0 && height
>= 0) {
2584 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2585 xoffset
+= texImage
->Border
;
2586 yoffset
+= texImage
->Border
;
2588 ASSERT(ctx
->Driver
.TexSubImage2D
);
2589 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2590 width
, height
, format
, type
, pixels
,
2591 &ctx
->Unpack
, texObj
, texImage
);
2593 check_gen_mipmap(ctx
, target
, texObj
, level
);
2595 ctx
->NewState
|= _NEW_TEXTURE
;
2598 _mesa_unlock_texture(ctx
, texObj
);
2604 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2605 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2606 GLsizei width
, GLsizei height
, GLsizei depth
,
2607 GLenum format
, GLenum type
,
2608 const GLvoid
*pixels
)
2610 struct gl_texture_object
*texObj
;
2611 struct gl_texture_image
*texImage
;
2612 GET_CURRENT_CONTEXT(ctx
);
2613 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2615 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2616 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2617 _mesa_lookup_enum_by_nr(target
), level
,
2618 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2619 _mesa_lookup_enum_by_nr(format
),
2620 _mesa_lookup_enum_by_nr(type
), pixels
);
2622 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2623 _mesa_update_state(ctx
);
2625 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2626 width
, height
, depth
, format
, type
)) {
2627 return; /* error was detected */
2630 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2632 _mesa_lock_texture(ctx
, texObj
);
2634 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2636 if (subtexture_error_check2(ctx
, 3, target
, level
,
2637 xoffset
, yoffset
, zoffset
,
2638 width
, height
, depth
,
2639 format
, type
, texImage
)) {
2640 /* error was recorded */
2642 else if (width
> 0 && height
> 0 && height
> 0) {
2643 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2644 xoffset
+= texImage
->Border
;
2645 yoffset
+= texImage
->Border
;
2646 zoffset
+= texImage
->Border
;
2648 ASSERT(ctx
->Driver
.TexSubImage3D
);
2649 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2650 xoffset
, yoffset
, zoffset
,
2651 width
, height
, depth
,
2652 format
, type
, pixels
,
2653 &ctx
->Unpack
, texObj
, texImage
);
2655 check_gen_mipmap(ctx
, target
, texObj
, level
);
2657 ctx
->NewState
|= _NEW_TEXTURE
;
2660 _mesa_unlock_texture(ctx
, texObj
);
2666 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2667 GLenum internalFormat
,
2669 GLsizei width
, GLint border
)
2671 struct gl_texture_object
*texObj
;
2672 struct gl_texture_image
*texImage
;
2673 GLsizei postConvWidth
= width
;
2674 const GLuint face
= _mesa_tex_target_to_face(target
);
2675 GET_CURRENT_CONTEXT(ctx
);
2676 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2678 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2679 _mesa_debug(ctx
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2680 _mesa_lookup_enum_by_nr(target
), level
,
2681 _mesa_lookup_enum_by_nr(internalFormat
),
2682 x
, y
, width
, border
);
2684 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2685 _mesa_update_state(ctx
);
2687 #if FEATURE_convolve
2688 if (_mesa_is_color_format(internalFormat
)) {
2689 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2693 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2694 postConvWidth
, 1, border
))
2697 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2699 _mesa_lock_texture(ctx
, texObj
);
2701 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2703 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2706 if (texImage
->Data
) {
2707 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2710 ASSERT(texImage
->Data
== NULL
);
2712 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2713 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2714 border
, internalFormat
);
2716 /* Choose actual texture format */
2717 texImage
->TexFormat
=
2718 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2720 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2722 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2723 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2724 x
, y
, width
, border
);
2726 ASSERT(texImage
->TexFormat
);
2728 _mesa_set_fetch_functions(texImage
, 1);
2730 check_gen_mipmap(ctx
, target
, texObj
, level
);
2732 update_fbo_texture(ctx
, texObj
, face
, level
);
2735 texObj
->_Complete
= GL_FALSE
;
2736 ctx
->NewState
|= _NEW_TEXTURE
;
2739 _mesa_unlock_texture(ctx
, texObj
);
2745 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2746 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2749 struct gl_texture_object
*texObj
;
2750 struct gl_texture_image
*texImage
;
2751 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2752 const GLuint face
= _mesa_tex_target_to_face(target
);
2753 GET_CURRENT_CONTEXT(ctx
);
2754 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2756 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2757 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2758 _mesa_lookup_enum_by_nr(target
), level
,
2759 _mesa_lookup_enum_by_nr(internalFormat
),
2760 x
, y
, width
, height
, border
);
2762 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2763 _mesa_update_state(ctx
);
2765 #if FEATURE_convolve
2766 if (_mesa_is_color_format(internalFormat
)) {
2767 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2772 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2773 postConvWidth
, postConvHeight
, border
))
2776 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2778 _mesa_lock_texture(ctx
, texObj
);
2780 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2783 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2786 if (texImage
->Data
) {
2787 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2790 ASSERT(texImage
->Data
== NULL
);
2792 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2793 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2794 postConvWidth
, postConvHeight
, 1,
2795 border
, internalFormat
);
2797 /* Choose actual texture format */
2798 texImage
->TexFormat
=
2799 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2801 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2803 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2804 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2805 x
, y
, width
, height
, border
);
2807 ASSERT(texImage
->TexFormat
);
2809 _mesa_set_fetch_functions(texImage
, 2);
2811 check_gen_mipmap(ctx
, target
, texObj
, level
);
2813 update_fbo_texture(ctx
, texObj
, face
, level
);
2816 texObj
->_Complete
= GL_FALSE
;
2817 ctx
->NewState
|= _NEW_TEXTURE
;
2820 _mesa_unlock_texture(ctx
, texObj
);
2825 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2826 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2828 struct gl_texture_object
*texObj
;
2829 struct gl_texture_image
*texImage
;
2830 GLsizei postConvWidth
= width
;
2834 GET_CURRENT_CONTEXT(ctx
);
2835 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2837 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2838 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2839 _mesa_lookup_enum_by_nr(target
),
2840 level
, xoffset
, x
, y
, width
);
2842 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2843 _mesa_update_state(ctx
);
2845 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2848 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2850 _mesa_lock_texture(ctx
, texObj
);
2852 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2854 #if FEATURE_convolve
2855 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2856 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2860 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2861 xoffset
, 0, 0, postConvWidth
, 1,
2863 /* error was recorded */
2866 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2867 xoffset
+= texImage
->Border
;
2869 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2871 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2872 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2873 xoffset
, x
, y
, width
);
2875 check_gen_mipmap(ctx
, target
, texObj
, level
);
2877 ctx
->NewState
|= _NEW_TEXTURE
;
2881 _mesa_unlock_texture(ctx
, texObj
);
2887 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2888 GLint xoffset
, GLint yoffset
,
2889 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2891 struct gl_texture_object
*texObj
;
2892 struct gl_texture_image
*texImage
;
2893 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2894 GET_CURRENT_CONTEXT(ctx
);
2895 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2897 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2898 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2899 _mesa_lookup_enum_by_nr(target
),
2900 level
, xoffset
, yoffset
, x
, y
, width
, height
);
2902 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2903 _mesa_update_state(ctx
);
2905 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2908 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2910 _mesa_lock_texture(ctx
, texObj
);
2912 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2914 #if FEATURE_convolve
2915 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2916 _mesa_adjust_image_for_convolution(ctx
, 2,
2917 &postConvWidth
, &postConvHeight
);
2921 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
2922 xoffset
, yoffset
, 0,
2923 postConvWidth
, postConvHeight
,
2925 /* error was recorded */
2928 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2929 xoffset
+= texImage
->Border
;
2930 yoffset
+= texImage
->Border
;
2932 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2934 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2935 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2936 x
, y
, width
, height
);
2938 check_gen_mipmap(ctx
, target
, texObj
, level
);
2940 ctx
->NewState
|= _NEW_TEXTURE
;
2944 _mesa_unlock_texture(ctx
, texObj
);
2950 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2951 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2952 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2954 struct gl_texture_object
*texObj
;
2955 struct gl_texture_image
*texImage
;
2956 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2957 GET_CURRENT_CONTEXT(ctx
);
2958 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2960 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2961 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
2962 _mesa_lookup_enum_by_nr(target
),
2963 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2965 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2966 _mesa_update_state(ctx
);
2968 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2971 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2973 _mesa_lock_texture(ctx
, texObj
);
2975 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2977 #if FEATURE_convolve
2978 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
2979 _mesa_adjust_image_for_convolution(ctx
, 2,
2980 &postConvWidth
, &postConvHeight
);
2984 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2985 zoffset
, postConvWidth
, postConvHeight
,
2987 /* error was recored */
2990 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2991 xoffset
+= texImage
->Border
;
2992 yoffset
+= texImage
->Border
;
2993 zoffset
+= texImage
->Border
;
2995 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2997 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2998 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2999 xoffset
, yoffset
, zoffset
,
3000 x
, y
, width
, height
);
3002 check_gen_mipmap(ctx
, target
, texObj
, level
);
3004 ctx
->NewState
|= _NEW_TEXTURE
;
3008 _mesa_unlock_texture(ctx
, texObj
);
3014 /**********************************************************************/
3015 /****** Compressed Textures ******/
3016 /**********************************************************************/
3020 * Return expected size of a compressed texture.
3023 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3026 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3027 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3032 * Return compressed texture block size, in pixels.
3035 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3037 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3038 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3043 * Error checking for glCompressedTexImage[123]D().
3044 * \return error code or GL_NO_ERROR.
3047 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3048 GLenum target
, GLint level
,
3049 GLenum internalFormat
, GLsizei width
,
3050 GLsizei height
, GLsizei depth
, GLint border
,
3053 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3055 if (dimensions
== 1) {
3056 /* 1D compressed textures not allowed */
3057 return GL_INVALID_ENUM
;
3059 else if (dimensions
== 2) {
3060 if (target
== GL_PROXY_TEXTURE_2D
) {
3061 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3063 else if (target
== GL_TEXTURE_2D
) {
3064 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3066 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3067 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3068 return GL_INVALID_ENUM
; /*target*/
3069 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3071 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3072 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3073 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3074 return GL_INVALID_ENUM
; /*target*/
3075 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3078 return GL_INVALID_ENUM
; /*target*/
3081 else if (dimensions
== 3) {
3082 /* 3D compressed textures not allowed */
3083 return GL_INVALID_ENUM
;
3086 maxTextureSize
= 1 << (maxLevels
- 1);
3088 /* This will detect any invalid internalFormat value */
3089 if (!_mesa_is_compressed_format(ctx
, internalFormat
))
3090 return GL_INVALID_ENUM
;
3092 /* This should really never fail */
3093 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3094 return GL_INVALID_ENUM
;
3097 return GL_INVALID_VALUE
;
3100 * XXX We should probably use the proxy texture error check function here.
3102 if (width
< 1 || width
> maxTextureSize
||
3103 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3104 return GL_INVALID_VALUE
;
3106 if ((height
< 1 || height
> maxTextureSize
||
3107 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3109 return GL_INVALID_VALUE
;
3111 if ((depth
< 1 || depth
> maxTextureSize
||
3112 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3114 return GL_INVALID_VALUE
;
3116 /* For cube map, width must equal height */
3117 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3118 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3119 return GL_INVALID_VALUE
;
3121 if (level
< 0 || level
>= maxLevels
)
3122 return GL_INVALID_VALUE
;
3124 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3125 if (expectedSize
!= imageSize
)
3126 return GL_INVALID_VALUE
;
3128 #if FEATURE_EXT_texture_sRGB
3129 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3130 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3131 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3132 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3134 return GL_INVALID_OPERATION
;
3143 * Error checking for glCompressedTexSubImage[123]D().
3144 * \warning There are some bad assumptions here about the size of compressed
3145 * texture tiles (multiple of 4) used to test the validity of the
3146 * offset and size parameters.
3147 * \return error code or GL_NO_ERROR.
3150 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3151 GLenum target
, GLint level
,
3152 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3153 GLsizei width
, GLsizei height
, GLsizei depth
,
3154 GLenum format
, GLsizei imageSize
)
3156 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3160 if (dimensions
== 1) {
3161 /* 1D compressed textures not allowed */
3162 return GL_INVALID_ENUM
;
3164 else if (dimensions
== 2) {
3165 if (target
== GL_PROXY_TEXTURE_2D
) {
3166 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3168 else if (target
== GL_TEXTURE_2D
) {
3169 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3171 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3172 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3173 return GL_INVALID_ENUM
; /*target*/
3174 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3176 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3177 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3178 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3179 return GL_INVALID_ENUM
; /*target*/
3180 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3183 return GL_INVALID_ENUM
; /*target*/
3186 else if (dimensions
== 3) {
3187 /* 3D compressed textures not allowed */
3188 return GL_INVALID_ENUM
;
3191 maxTextureSize
= 1 << (maxLevels
- 1);
3193 /* this will catch any invalid compressed format token */
3194 if (!_mesa_is_compressed_format(ctx
, format
))
3195 return GL_INVALID_ENUM
;
3197 if (width
< 1 || width
> maxTextureSize
)
3198 return GL_INVALID_VALUE
;
3200 if ((height
< 1 || height
> maxTextureSize
)
3202 return GL_INVALID_VALUE
;
3204 if (level
< 0 || level
>= maxLevels
)
3205 return GL_INVALID_VALUE
;
3208 * do checks which depend on compression block size
3210 get_compressed_block_size(format
, &bw
, &bh
);
3212 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3213 return GL_INVALID_VALUE
;
3215 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3216 return GL_INVALID_VALUE
;
3218 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3219 return GL_INVALID_VALUE
;
3221 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3222 if (expectedSize
!= imageSize
)
3223 return GL_INVALID_VALUE
;
3230 * Do second part of glCompressedTexSubImage error checking.
3231 * \return GL_TRUE if error found, GL_FALSE otherwise.
3234 compressed_subtexture_error_check2(GLcontext
*ctx
, GLuint dims
,
3235 GLsizei width
, GLsizei height
,
3236 GLsizei depth
, GLenum format
,
3237 struct gl_texture_image
*texImage
)
3240 if ((GLint
) format
!= texImage
->InternalFormat
) {
3241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3242 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3246 if (((width
== 1 || width
== 2) &&
3247 width
!= (GLsizei
) texImage
->Width
) ||
3248 (width
> (GLsizei
) texImage
->Width
)) {
3249 _mesa_error(ctx
, GL_INVALID_VALUE
,
3250 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3255 if (((height
== 1 || height
== 2) &&
3256 height
!= (GLsizei
) texImage
->Height
) ||
3257 (height
> (GLsizei
) texImage
->Height
)) {
3258 _mesa_error(ctx
, GL_INVALID_VALUE
,
3259 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3265 if (((depth
== 1 || depth
== 2) &&
3266 depth
!= (GLsizei
) texImage
->Depth
) ||
3267 (depth
> (GLsizei
) texImage
->Depth
)) {
3268 _mesa_error(ctx
, GL_INVALID_VALUE
,
3269 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3280 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3281 GLenum internalFormat
, GLsizei width
,
3282 GLint border
, GLsizei imageSize
,
3285 GET_CURRENT_CONTEXT(ctx
);
3286 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3288 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3289 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3290 _mesa_lookup_enum_by_nr(target
), level
,
3291 _mesa_lookup_enum_by_nr(internalFormat
),
3292 width
, border
, imageSize
, data
);
3294 if (target
== GL_TEXTURE_1D
) {
3295 /* non-proxy target */
3296 struct gl_texture_object
*texObj
;
3297 struct gl_texture_image
*texImage
;
3298 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3299 internalFormat
, width
, 1, 1, border
, imageSize
);
3301 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3305 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3307 _mesa_lock_texture(ctx
, texObj
);
3309 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3311 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3314 if (texImage
->Data
) {
3315 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3317 ASSERT(texImage
->Data
== NULL
);
3319 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3320 border
, internalFormat
);
3322 /* Choose actual texture format */
3323 texImage
->TexFormat
=
3324 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3326 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3328 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3329 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3330 internalFormat
, width
, border
,
3334 _mesa_set_fetch_functions(texImage
, 1);
3336 check_gen_mipmap(ctx
, target
, texObj
, level
);
3339 texObj
->_Complete
= GL_FALSE
;
3340 ctx
->NewState
|= _NEW_TEXTURE
;
3343 _mesa_unlock_texture(ctx
, texObj
);
3345 else if (target
== GL_PROXY_TEXTURE_1D
) {
3346 /* Proxy texture: check for errors and update proxy state */
3347 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3348 internalFormat
, width
, 1, 1, border
, imageSize
);
3350 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3351 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3352 internalFormat
, GL_NONE
, GL_NONE
,
3353 width
, 1, 1, border
);
3356 /* if error, clear all proxy texture image parameters */
3357 struct gl_texture_image
*texImage
;
3358 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3360 clear_teximage_fields(texImage
);
3363 /* store the teximage parameters */
3364 struct gl_texture_object
*texObj
;
3365 struct gl_texture_image
*texImage
;
3367 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3369 _mesa_lock_texture(ctx
, texObj
);
3371 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3372 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3373 border
, internalFormat
);
3375 _mesa_unlock_texture(ctx
, texObj
);
3379 _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
);
3400 switch (internalFormat
) {
3401 case GL_PALETTE4_RGB8_OES
:
3402 case GL_PALETTE4_RGBA8_OES
:
3403 case GL_PALETTE4_R5_G6_B5_OES
:
3404 case GL_PALETTE4_RGBA4_OES
:
3405 case GL_PALETTE4_RGB5_A1_OES
:
3406 case GL_PALETTE8_RGB8_OES
:
3407 case GL_PALETTE8_RGBA8_OES
:
3408 case GL_PALETTE8_R5_G6_B5_OES
:
3409 case GL_PALETTE8_RGBA4_OES
:
3410 case GL_PALETTE8_RGB5_A1_OES
:
3411 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3412 width
, height
, imageSize
, data
);
3417 if (target
== GL_TEXTURE_2D
||
3418 (ctx
->Extensions
.ARB_texture_cube_map
&&
3419 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3420 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3421 /* non-proxy target */
3422 struct gl_texture_object
*texObj
;
3423 struct gl_texture_image
*texImage
;
3425 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3426 internalFormat
, width
, height
, 1, border
, imageSize
);
3428 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3432 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3434 _mesa_lock_texture(ctx
, texObj
);
3436 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3438 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3441 if (texImage
->Data
) {
3442 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3444 ASSERT(texImage
->Data
== NULL
);
3446 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3447 border
, internalFormat
);
3449 /* Choose actual texture format */
3450 texImage
->TexFormat
=
3451 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3453 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3455 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3456 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3457 internalFormat
, width
, height
,
3458 border
, imageSize
, data
,
3461 _mesa_set_fetch_functions(texImage
, 2);
3463 check_gen_mipmap(ctx
, target
, texObj
, level
);
3466 texObj
->_Complete
= GL_FALSE
;
3467 ctx
->NewState
|= _NEW_TEXTURE
;
3470 _mesa_unlock_texture(ctx
, texObj
);
3472 else if (target
== GL_PROXY_TEXTURE_2D
||
3473 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3474 ctx
->Extensions
.ARB_texture_cube_map
)) {
3475 /* Proxy texture: check for errors and update proxy state */
3476 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3477 internalFormat
, width
, height
, 1, border
, imageSize
);
3479 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3480 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3481 internalFormat
, GL_NONE
, GL_NONE
,
3482 width
, height
, 1, border
);
3485 /* if error, clear all proxy texture image parameters */
3486 struct gl_texture_image
*texImage
;
3487 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3489 clear_teximage_fields(texImage
);
3492 /* store the teximage parameters */
3493 struct gl_texture_object
*texObj
;
3494 struct gl_texture_image
*texImage
;
3496 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3498 _mesa_lock_texture(ctx
, texObj
);
3500 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3501 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3502 border
, internalFormat
);
3504 _mesa_unlock_texture(ctx
, texObj
);
3508 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3515 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3516 GLenum internalFormat
, GLsizei width
,
3517 GLsizei height
, GLsizei depth
, GLint border
,
3518 GLsizei imageSize
, const GLvoid
*data
)
3520 GET_CURRENT_CONTEXT(ctx
);
3521 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3523 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3524 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3525 _mesa_lookup_enum_by_nr(target
), level
,
3526 _mesa_lookup_enum_by_nr(internalFormat
),
3527 width
, height
, depth
, border
, imageSize
, data
);
3529 if (target
== GL_TEXTURE_3D
) {
3530 /* non-proxy target */
3531 struct gl_texture_object
*texObj
;
3532 struct gl_texture_image
*texImage
;
3533 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3534 internalFormat
, width
, height
, depth
, border
, imageSize
);
3536 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3540 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3542 _mesa_lock_texture(ctx
, texObj
);
3544 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3546 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3549 if (texImage
->Data
) {
3550 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3552 ASSERT(texImage
->Data
== NULL
);
3554 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3555 width
, height
, depth
,
3556 border
, internalFormat
);
3558 /* Choose actual texture format */
3559 texImage
->TexFormat
=
3560 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3562 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
3564 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3565 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3567 width
, height
, depth
,
3568 border
, imageSize
, data
,
3571 _mesa_set_fetch_functions(texImage
, 3);
3573 check_gen_mipmap(ctx
, target
, texObj
, level
);
3576 texObj
->_Complete
= GL_FALSE
;
3577 ctx
->NewState
|= _NEW_TEXTURE
;
3580 _mesa_unlock_texture(ctx
, texObj
);
3582 else if (target
== GL_PROXY_TEXTURE_3D
) {
3583 /* Proxy texture: check for errors and update proxy state */
3584 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3585 internalFormat
, width
, height
, depth
, border
, imageSize
);
3587 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3588 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3589 internalFormat
, GL_NONE
, GL_NONE
,
3590 width
, height
, depth
, border
);
3593 /* if error, clear all proxy texture image parameters */
3594 struct gl_texture_image
*texImage
;
3595 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3597 clear_teximage_fields(texImage
);
3600 /* store the teximage parameters */
3601 struct gl_texture_object
*texObj
;
3602 struct gl_texture_image
*texImage
;
3604 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3606 _mesa_lock_texture(ctx
, texObj
);
3608 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3609 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3610 depth
, border
, internalFormat
);
3612 _mesa_unlock_texture(ctx
, texObj
);
3616 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3623 * Common helper for glCompressedTexSubImage1/2/3D().
3626 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3627 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3628 GLsizei width
, GLsizei height
, GLsizei depth
,
3629 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3631 struct gl_texture_object
*texObj
;
3632 struct gl_texture_image
*texImage
;
3634 GET_CURRENT_CONTEXT(ctx
);
3635 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3637 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3638 xoffset
, 0, 0, /* pos */
3639 width
, height
, depth
, /* size */
3642 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3646 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3648 _mesa_lock_texture(ctx
, texObj
);
3650 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3653 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3654 format
, texImage
)) {
3655 /* error was recorded */
3657 else if (width
> 0 && height
> 0 && depth
> 0) {
3660 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3661 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3663 format
, imageSize
, data
,
3668 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3669 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3672 format
, imageSize
, data
,
3677 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3678 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3679 xoffset
, yoffset
, zoffset
,
3680 width
, height
, depth
,
3681 format
, imageSize
, data
,
3689 check_gen_mipmap(ctx
, target
, texObj
, level
);
3691 ctx
->NewState
|= _NEW_TEXTURE
;
3694 _mesa_unlock_texture(ctx
, texObj
);
3699 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3700 GLsizei width
, GLenum format
,
3701 GLsizei imageSize
, const GLvoid
*data
)
3703 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3704 format
, imageSize
, data
);
3709 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3710 GLint yoffset
, GLsizei width
, GLsizei height
,
3711 GLenum format
, GLsizei imageSize
,
3714 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3715 width
, height
, 1, format
, imageSize
, data
);
3720 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3721 GLint yoffset
, GLint zoffset
, GLsizei width
,
3722 GLsizei height
, GLsizei depth
, GLenum format
,
3723 GLsizei imageSize
, const GLvoid
*data
)
3725 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3726 width
, height
, depth
, format
, imageSize
, data
);