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
:
354 #endif /* FEATURE_EXT_texture_sRGB */
356 if (ctx
->Extensions
.EXT_texture_integer
) {
357 switch (internalFormat
) {
359 case GL_RGBA16UI_EXT
:
360 case GL_RGBA32UI_EXT
:
372 case GL_ALPHA8UI_EXT
:
373 case GL_ALPHA16UI_EXT
:
374 case GL_ALPHA32UI_EXT
:
376 case GL_ALPHA16I_EXT
:
377 case GL_ALPHA32I_EXT
:
379 case GL_INTENSITY8UI_EXT
:
380 case GL_INTENSITY16UI_EXT
:
381 case GL_INTENSITY32UI_EXT
:
382 case GL_INTENSITY8I_EXT
:
383 case GL_INTENSITY16I_EXT
:
384 case GL_INTENSITY32I_EXT
:
386 case GL_LUMINANCE8UI_EXT
:
387 case GL_LUMINANCE16UI_EXT
:
388 case GL_LUMINANCE32UI_EXT
:
389 case GL_LUMINANCE8I_EXT
:
390 case GL_LUMINANCE16I_EXT
:
391 case GL_LUMINANCE32I_EXT
:
393 case GL_LUMINANCE_ALPHA8UI_EXT
:
394 case GL_LUMINANCE_ALPHA16UI_EXT
:
395 case GL_LUMINANCE_ALPHA32UI_EXT
:
396 case GL_LUMINANCE_ALPHA8I_EXT
:
397 case GL_LUMINANCE_ALPHA16I_EXT
:
398 case GL_LUMINANCE_ALPHA32I_EXT
:
399 return GL_LUMINANCE_ALPHA
;
405 if (ctx
->Extensions
.ARB_texture_rg
) {
406 switch (internalFormat
) {
436 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
437 switch (internalFormat
) {
445 if (ctx
->Extensions
.EXT_packed_float
) {
446 switch (internalFormat
) {
447 case GL_R11F_G11F_B10F_EXT
:
454 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
455 switch (internalFormat
) {
456 case GL_DEPTH_COMPONENT32F
:
457 return GL_DEPTH_COMPONENT
;
458 case GL_DEPTH32F_STENCIL8
:
459 return GL_DEPTH_STENCIL
;
465 if (ctx
->Extensions
.EXT_texture_compression_rgtc
) {
466 switch (internalFormat
) {
467 case GL_COMPRESSED_RED
:
468 case GL_COMPRESSED_RED_RGTC1_EXT
:
469 case GL_COMPRESSED_SIGNED_RED_RGTC1_EXT
:
471 case GL_COMPRESSED_RG
:
472 case GL_COMPRESSED_RED_GREEN_RGTC2_EXT
:
473 case GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT
:
480 return -1; /* error */
485 * For cube map faces, return a face index in [0,5].
486 * For other targets return 0;
489 _mesa_tex_target_to_face(GLenum target
)
491 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
492 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
493 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
501 * Store a gl_texture_image pointer in a gl_texture_object structure
502 * according to the target and level parameters.
504 * \param tObj texture object.
505 * \param target texture target.
506 * \param level image level.
507 * \param texImage texture image.
509 * This was basically prompted by the introduction of cube maps.
512 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
513 GLenum target
, GLint level
,
514 struct gl_texture_image
*texImage
)
516 const GLuint face
= _mesa_tex_target_to_face(target
);
520 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
522 tObj
->Image
[face
][level
] = texImage
;
524 /* Set the 'back' pointer */
525 texImage
->TexObject
= tObj
;
530 * Allocate a texture image structure.
532 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
535 * \return a pointer to gl_texture_image struct with all fields initialized to
538 struct gl_texture_image
*
539 _mesa_new_texture_image( GLcontext
*ctx
)
542 return CALLOC_STRUCT(gl_texture_image
);
547 * Free texture image data.
548 * This function is a fallback called via ctx->Driver.FreeTexImageData().
550 * \param texImage texture image.
552 * Free the texture image data if it's not marked as client data.
555 _mesa_free_texture_image_data(GLcontext
*ctx
,
556 struct gl_texture_image
*texImage
)
560 if (texImage
->Data
&& !texImage
->IsClientData
) {
561 /* free the old texture data */
562 _mesa_free_texmemory(texImage
->Data
);
565 texImage
->Data
= NULL
;
570 * Free texture image.
572 * \param texImage texture image.
574 * Free the texture image structure and the associated image data.
577 _mesa_delete_texture_image( GLcontext
*ctx
, struct gl_texture_image
*texImage
)
579 /* Free texImage->Data and/or any other driver-specific texture
582 ASSERT(ctx
->Driver
.FreeTexImageData
);
583 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
585 ASSERT(texImage
->Data
== NULL
);
586 if (texImage
->ImageOffsets
)
587 free(texImage
->ImageOffsets
);
593 * Test if a target is a proxy target.
595 * \param target texture target.
597 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
600 _mesa_is_proxy_texture(GLenum target
)
602 /* NUM_TEXTURE_TARGETS should match number of terms below */
603 assert(NUM_TEXTURE_TARGETS
== 7);
605 return (target
== GL_PROXY_TEXTURE_1D
||
606 target
== GL_PROXY_TEXTURE_2D
||
607 target
== GL_PROXY_TEXTURE_3D
||
608 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
609 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
610 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
611 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
616 * Get the texture object that corresponds to the target of the given texture unit.
618 * \param ctx GL context.
619 * \param texUnit texture unit.
620 * \param target texture target.
622 * \return pointer to the texture object on success, or NULL on failure.
624 * \sa gl_texture_unit.
626 struct gl_texture_object
*
627 _mesa_select_tex_object(GLcontext
*ctx
, const struct gl_texture_unit
*texUnit
,
632 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
633 case GL_PROXY_TEXTURE_1D
:
634 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
636 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
637 case GL_PROXY_TEXTURE_2D
:
638 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
640 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
641 case GL_PROXY_TEXTURE_3D
:
642 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
643 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
644 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
645 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
646 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
647 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
648 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
649 case GL_TEXTURE_CUBE_MAP_ARB
:
650 return ctx
->Extensions
.ARB_texture_cube_map
651 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
652 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
653 return ctx
->Extensions
.ARB_texture_cube_map
654 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
655 case GL_TEXTURE_RECTANGLE_NV
:
656 return ctx
->Extensions
.NV_texture_rectangle
657 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
658 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
659 return ctx
->Extensions
.NV_texture_rectangle
660 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
661 case GL_TEXTURE_1D_ARRAY_EXT
:
662 return ctx
->Extensions
.MESA_texture_array
663 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
664 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
665 return ctx
->Extensions
.MESA_texture_array
666 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
667 case GL_TEXTURE_2D_ARRAY_EXT
:
668 return ctx
->Extensions
.MESA_texture_array
669 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
670 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
671 return ctx
->Extensions
.MESA_texture_array
672 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
674 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
681 * Return pointer to texture object for given target on current texture unit.
683 struct gl_texture_object
*
684 _mesa_get_current_tex_object(GLcontext
*ctx
, GLenum target
)
686 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
687 return _mesa_select_tex_object(ctx
, texUnit
, target
);
692 * Get a texture image pointer from a texture object, given a texture
693 * target and mipmap level. The target and level parameters should
694 * have already been error-checked.
696 * \param ctx GL context.
697 * \param texObj texture unit.
698 * \param target texture target.
699 * \param level image level.
701 * \return pointer to the texture image structure, or NULL on failure.
703 struct gl_texture_image
*
704 _mesa_select_tex_image(GLcontext
*ctx
, const struct gl_texture_object
*texObj
,
705 GLenum target
, GLint level
)
707 const GLuint face
= _mesa_tex_target_to_face(target
);
711 ASSERT(level
< MAX_TEXTURE_LEVELS
);
713 return texObj
->Image
[face
][level
];
718 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
719 * it and install it. Only return NULL if passed a bad parameter or run
722 struct gl_texture_image
*
723 _mesa_get_tex_image(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
724 GLenum target
, GLint level
)
726 struct gl_texture_image
*texImage
;
731 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
733 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
735 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
739 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
747 * Return pointer to the specified proxy texture image.
748 * Note that proxy textures are per-context, not per-texture unit.
749 * \return pointer to texture image or NULL if invalid target, invalid
750 * level, or out of memory.
752 struct gl_texture_image
*
753 _mesa_get_proxy_tex_image(GLcontext
*ctx
, GLenum target
, GLint level
)
755 struct gl_texture_image
*texImage
;
762 case GL_PROXY_TEXTURE_1D
:
763 if (level
>= ctx
->Const
.MaxTextureLevels
)
765 texIndex
= TEXTURE_1D_INDEX
;
767 case GL_PROXY_TEXTURE_2D
:
768 if (level
>= ctx
->Const
.MaxTextureLevels
)
770 texIndex
= TEXTURE_2D_INDEX
;
772 case GL_PROXY_TEXTURE_3D
:
773 if (level
>= ctx
->Const
.Max3DTextureLevels
)
775 texIndex
= TEXTURE_3D_INDEX
;
777 case GL_PROXY_TEXTURE_CUBE_MAP
:
778 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
780 texIndex
= TEXTURE_CUBE_INDEX
;
782 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
785 texIndex
= TEXTURE_RECT_INDEX
;
787 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
788 if (level
>= ctx
->Const
.MaxTextureLevels
)
790 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
792 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
793 if (level
>= ctx
->Const
.MaxTextureLevels
)
795 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
801 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
803 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
805 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
808 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
809 /* Set the 'back' pointer */
810 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
817 * Get the maximum number of allowed mipmap levels.
819 * \param ctx GL context.
820 * \param target texture target.
822 * \return the maximum number of allowed mipmap levels for the given
823 * texture target, or zero if passed a bad target.
828 _mesa_max_texture_levels(GLcontext
*ctx
, GLenum target
)
832 case GL_PROXY_TEXTURE_1D
:
834 case GL_PROXY_TEXTURE_2D
:
835 return ctx
->Const
.MaxTextureLevels
;
837 case GL_PROXY_TEXTURE_3D
:
838 return ctx
->Const
.Max3DTextureLevels
;
839 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
840 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
841 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
842 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
843 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
844 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
845 case GL_TEXTURE_CUBE_MAP_ARB
:
846 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
847 return ctx
->Extensions
.ARB_texture_cube_map
848 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
849 case GL_TEXTURE_RECTANGLE_NV
:
850 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
851 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
852 case GL_TEXTURE_1D_ARRAY_EXT
:
853 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
854 case GL_TEXTURE_2D_ARRAY_EXT
:
855 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
856 return ctx
->Extensions
.MESA_texture_array
857 ? ctx
->Const
.MaxTextureLevels
: 0;
859 return 0; /* bad target */
865 #if 000 /* not used anymore */
867 * glTexImage[123]D can accept a NULL image pointer. In this case we
868 * create a texture image with unspecified image contents per the OpenGL
872 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
874 const GLint components
= _mesa_components_in_format(format
);
875 const GLint numPixels
= width
* height
* depth
;
876 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
880 * Let's see if anyone finds this. If glTexImage2D() is called with
881 * a NULL image pointer then load the texture image with something
882 * interesting instead of leaving it indeterminate.
885 static const char message
[8][32] = {
889 " X X XXXX XXX XXXXX ",
892 " X X XXXXX XXX X X ",
896 GLubyte
*imgPtr
= data
;
898 for (h
= 0; h
< depth
; h
++) {
899 for (i
= 0; i
< height
; i
++) {
900 GLint srcRow
= 7 - (i
% 8);
901 for (j
= 0; j
< width
; j
++) {
902 GLint srcCol
= j
% 32;
903 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
904 for (k
= 0; k
< components
; k
++) {
920 * Reset the fields of a gl_texture_image struct to zero.
922 * \param img texture image structure.
924 * This is called when a proxy texture test fails, we set all the
925 * image members (except DriverData) to zero.
926 * It's also used in glTexImage[123]D as a safeguard to be sure all
927 * required fields get initialized properly by the Driver.TexImage[123]D
931 clear_teximage_fields(struct gl_texture_image
*img
)
934 img
->_BaseFormat
= 0;
935 img
->InternalFormat
= 0;
941 if (img
->ImageOffsets
) {
942 free(img
->ImageOffsets
);
943 img
->ImageOffsets
= NULL
;
952 img
->TexFormat
= MESA_FORMAT_NONE
;
953 img
->FetchTexelc
= NULL
;
954 img
->FetchTexelf
= NULL
;
959 * Initialize basic fields of the gl_texture_image struct.
961 * \param ctx GL context.
962 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
963 * \param img texture image structure to be initialized.
964 * \param width image width.
965 * \param height image height.
966 * \param depth image depth.
967 * \param border image border.
968 * \param internalFormat internal format.
970 * Fills in the fields of \p img with the given information.
971 * Note: width, height and depth include the border.
974 _mesa_init_teximage_fields(GLcontext
*ctx
, GLenum target
,
975 struct gl_texture_image
*img
,
976 GLsizei width
, GLsizei height
, GLsizei depth
,
977 GLint border
, GLenum internalFormat
)
986 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
987 ASSERT(img
->_BaseFormat
> 0);
988 img
->InternalFormat
= internalFormat
;
989 img
->Border
= border
;
991 img
->Height
= height
;
994 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
995 img
->WidthLog2
= logbase2(img
->Width2
);
997 if (height
== 1) { /* 1-D texture */
1002 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1003 img
->HeightLog2
= logbase2(img
->Height2
);
1006 if (depth
== 1) { /* 2-D texture */
1011 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1012 img
->DepthLog2
= logbase2(img
->Depth2
);
1015 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1017 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1018 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1019 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1020 img
->_IsPowerOfTwo
= GL_TRUE
;
1022 img
->_IsPowerOfTwo
= GL_FALSE
;
1024 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1025 img
->RowStride
= width
;
1026 /* Allocate the ImageOffsets array and initialize to typical values.
1027 * We allocate the array for 1D/2D textures too in order to avoid special-
1028 * case code in the texstore routines.
1030 if (img
->ImageOffsets
)
1031 free(img
->ImageOffsets
);
1032 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1033 for (i
= 0; i
< depth
; i
++) {
1034 img
->ImageOffsets
[i
] = i
* width
* height
;
1037 /* Compute Width/Height/DepthScale for mipmap lod computation */
1038 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1039 /* scale = 1.0 since texture coords directly map to texels */
1040 img
->WidthScale
= 1.0;
1041 img
->HeightScale
= 1.0;
1042 img
->DepthScale
= 1.0;
1045 img
->WidthScale
= (GLfloat
) img
->Width
;
1046 img
->HeightScale
= (GLfloat
) img
->Height
;
1047 img
->DepthScale
= (GLfloat
) img
->Depth
;
1050 img
->FetchTexelc
= NULL
;
1051 img
->FetchTexelf
= NULL
;
1056 * Free and clear fields of the gl_texture_image struct.
1058 * \param ctx GL context.
1059 * \param texImage texture image structure to be cleared.
1061 * After the call, \p texImage will have no data associated with it. Its
1062 * fields are cleared so that its parent object will test incomplete.
1065 _mesa_clear_texture_image(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
1067 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1068 clear_teximage_fields(texImage
);
1073 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1074 * level, width, height and depth against the ctx->Const limits for textures.
1076 * A hardware driver might override this function if, for example, the
1077 * max 3D texture size is 512x512x64 (i.e. not a cube).
1079 * Note that width, height, depth == 0 is not an error. However, a
1080 * texture with zero width/height/depth will be considered "incomplete"
1081 * and texturing will effectively be disabled.
1083 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1084 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1085 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1086 * \param level as passed to glTexImage
1087 * \param internalFormat as passed to glTexImage
1088 * \param format as passed to glTexImage
1089 * \param type as passed to glTexImage
1090 * \param width as passed to glTexImage
1091 * \param height as passed to glTexImage
1092 * \param depth as passed to glTexImage
1093 * \param border as passed to glTexImage
1094 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1097 _mesa_test_proxy_teximage(GLcontext
*ctx
, GLenum target
, GLint level
,
1098 GLint internalFormat
, GLenum format
, GLenum type
,
1099 GLint width
, GLint height
, GLint depth
, GLint border
)
1103 (void) internalFormat
;
1108 case GL_PROXY_TEXTURE_1D
:
1109 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1110 if (width
< 2 * border
|| width
> 2 + maxSize
||
1111 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1112 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1113 level
>= ctx
->Const
.MaxTextureLevels
) {
1114 /* bad width or level */
1118 case GL_PROXY_TEXTURE_2D
:
1119 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1120 if (width
< 2 * border
|| width
> 2 + maxSize
||
1121 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1122 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1123 height
< 2 * border
|| height
> 2 + maxSize
||
1124 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1125 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1126 level
>= ctx
->Const
.MaxTextureLevels
) {
1127 /* bad width or height or level */
1131 case GL_PROXY_TEXTURE_3D
:
1132 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1133 if (width
< 2 * border
|| width
> 2 + maxSize
||
1134 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1135 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1136 height
< 2 * border
|| height
> 2 + maxSize
||
1137 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1138 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1139 depth
< 2 * border
|| depth
> 2 + maxSize
||
1140 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1141 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1142 level
>= ctx
->Const
.Max3DTextureLevels
) {
1143 /* bad width or height or depth or level */
1147 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1148 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1149 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1151 /* bad width or height or level */
1155 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1156 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1157 if (width
< 2 * border
|| width
> 2 + maxSize
||
1158 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1159 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1160 height
< 2 * border
|| height
> 2 + maxSize
||
1161 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1162 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1163 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1164 /* bad width or height */
1168 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1169 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1170 if (width
< 2 * border
|| width
> 2 + maxSize
||
1171 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1172 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1173 level
>= ctx
->Const
.MaxTextureLevels
) {
1174 /* bad width or level */
1178 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1182 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1183 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1184 if (width
< 2 * border
|| width
> 2 + maxSize
||
1185 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1186 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1187 height
< 2 * border
|| height
> 2 + maxSize
||
1188 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1189 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1190 level
>= ctx
->Const
.MaxTextureLevels
) {
1191 /* bad width or height or level */
1194 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1199 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1206 * Helper function to determine whether a target supports compressed textures
1209 target_can_be_compressed(GLcontext
*ctx
, GLenum target
)
1211 return (((target
== GL_TEXTURE_2D
|| target
== GL_PROXY_TEXTURE_2D
))
1212 || ((ctx
->Extensions
.ARB_texture_cube_map
&&
1213 (target
== GL_PROXY_TEXTURE_CUBE_MAP
||
1214 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X
&&
1215 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
))))
1216 || ((ctx
->Extensions
.MESA_texture_array
&&
1217 ((target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
) ||
1218 (target
== GL_TEXTURE_2D_ARRAY_EXT
)))));
1223 * Test the glTexImage[123]D() parameters for errors.
1225 * \param ctx GL context.
1226 * \param target texture target given by the user.
1227 * \param level image level given by the user.
1228 * \param internalFormat internal format given by the user.
1229 * \param format pixel data format given by the user.
1230 * \param type pixel data type given by the user.
1231 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1232 * \param width image width given by the user.
1233 * \param height image height given by the user.
1234 * \param depth image depth given by the user.
1235 * \param border image border given by the user.
1237 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1239 * Verifies each of the parameters against the constants specified in
1240 * __GLcontextRec::Const and the supported extensions, and according to the
1241 * OpenGL specification.
1244 texture_error_check( GLcontext
*ctx
, GLenum target
,
1245 GLint level
, GLint internalFormat
,
1246 GLenum format
, GLenum type
,
1248 GLint width
, GLint height
,
1249 GLint depth
, GLint border
)
1251 const GLboolean isProxy
= _mesa_is_proxy_texture(target
);
1252 GLboolean sizeOK
= GL_TRUE
;
1253 GLboolean colorFormat
, indexFormat
;
1254 GLenum proxy_target
;
1256 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1257 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1259 _mesa_error(ctx
, GL_INVALID_VALUE
,
1260 "glTexImage%dD(level=%d)", dimensions
, level
);
1266 if (border
< 0 || border
> 1 ||
1267 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1268 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1270 _mesa_error(ctx
, GL_INVALID_VALUE
,
1271 "glTexImage%dD(border=%d)", dimensions
, border
);
1276 if (width
< 0 || height
< 0 || depth
< 0) {
1278 _mesa_error(ctx
, GL_INVALID_VALUE
,
1279 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1284 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1285 * level, width, height and depth.
1287 if (dimensions
== 1) {
1288 if (target
== GL_PROXY_TEXTURE_1D
|| target
== GL_TEXTURE_1D
) {
1289 proxy_target
= GL_PROXY_TEXTURE_1D
;
1294 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
1298 else if (dimensions
== 2) {
1300 if (target
== GL_PROXY_TEXTURE_2D
|| target
== GL_TEXTURE_2D
) {
1301 proxy_target
= GL_PROXY_TEXTURE_2D
;
1303 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1304 (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1305 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
1306 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1307 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1310 proxy_target
= GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
1311 sizeOK
= (width
== height
);
1313 else if (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
1314 target
== GL_TEXTURE_RECTANGLE_NV
) {
1315 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1316 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1319 proxy_target
= GL_PROXY_TEXTURE_RECTANGLE_NV
;
1321 else if (target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
1322 target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1323 proxy_target
= GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
1326 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)");
1330 else if (dimensions
== 3) {
1331 if (target
== GL_PROXY_TEXTURE_3D
|| target
== GL_TEXTURE_3D
) {
1332 proxy_target
= GL_PROXY_TEXTURE_3D
;
1334 else if (target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
1335 target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1336 proxy_target
= GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
1339 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
1344 _mesa_problem( ctx
, "bad dims in texture_error_check" );
1348 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target
, level
,
1349 internalFormat
, format
,
1350 type
, width
, height
,
1354 _mesa_error(ctx
, GL_INVALID_VALUE
,
1355 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1356 dimensions
, level
, width
, height
, depth
);
1361 /* Check internalFormat */
1362 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1364 _mesa_error(ctx
, GL_INVALID_VALUE
,
1365 "glTexImage%dD(internalFormat=%s)",
1366 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1371 /* Check incoming image format and type */
1372 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1373 /* Yes, generate GL_INVALID_OPERATION, not GL_INVALID_ENUM, if there
1374 * is a type/format mismatch. See 1.2 spec page 94, sec 3.6.4.
1377 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1378 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1379 dimensions
, format
, type
);
1384 /* make sure internal format and format basically agree */
1385 colorFormat
= _mesa_is_color_format(format
);
1386 indexFormat
= _mesa_is_index_format(format
);
1387 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1388 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1389 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1390 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1391 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1392 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1394 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1395 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1396 dimensions
, internalFormat
, format
);
1400 /* additional checks for ycbcr textures */
1401 if (internalFormat
== GL_YCBCR_MESA
) {
1402 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1403 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1404 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1406 _mesa_snprintf(message
, sizeof(message
),
1407 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1408 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1409 return GL_TRUE
; /* error */
1411 if (target
!= GL_TEXTURE_2D
&&
1412 target
!= GL_PROXY_TEXTURE_2D
&&
1413 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1414 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1416 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1422 _mesa_snprintf(message
, sizeof(message
),
1423 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1424 dimensions
, border
);
1425 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1431 /* additional checks for depth textures */
1432 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1433 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1434 if (target
!= GL_TEXTURE_1D
&&
1435 target
!= GL_PROXY_TEXTURE_1D
&&
1436 target
!= GL_TEXTURE_2D
&&
1437 target
!= GL_PROXY_TEXTURE_2D
&&
1438 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1439 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1441 _mesa_error(ctx
, GL_INVALID_ENUM
,
1442 "glTexImage(target/internalFormat)");
1447 /* additional checks for compressed textures */
1448 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1449 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1450 _mesa_error(ctx
, GL_INVALID_ENUM
,
1451 "glTexImage%dD(target)", dimensions
);
1456 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1457 "glTexImage%dD(border!=0)", dimensions
);
1463 /* if we get here, the parameters are OK */
1469 * Test glTexSubImage[123]D() parameters for errors.
1471 * \param ctx GL context.
1472 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1473 * \param target texture target given by the user.
1474 * \param level image level given by the user.
1475 * \param xoffset sub-image x offset given by the user.
1476 * \param yoffset sub-image y offset given by the user.
1477 * \param zoffset sub-image z offset given by the user.
1478 * \param format pixel data format given by the user.
1479 * \param type pixel data type given by the user.
1480 * \param width image width given by the user.
1481 * \param height image height given by the user.
1482 * \param depth image depth given by the user.
1484 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1486 * Verifies each of the parameters against the constants specified in
1487 * __GLcontextRec::Const and the supported extensions, and according to the
1488 * OpenGL specification.
1491 subtexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1492 GLenum target
, GLint level
,
1493 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1494 GLint width
, GLint height
, GLint depth
,
1495 GLenum format
, GLenum type
)
1498 if (dimensions
== 1) {
1499 if (target
!= GL_TEXTURE_1D
) {
1500 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage1D(target)" );
1504 else if (dimensions
== 2) {
1505 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1506 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1507 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1508 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1512 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1513 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1514 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1518 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1519 if (!ctx
->Extensions
.MESA_texture_array
) {
1520 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1524 else if (target
!= GL_TEXTURE_2D
) {
1525 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(target)" );
1529 else if (dimensions
== 3) {
1530 if (target
== GL_TEXTURE_2D_ARRAY_EXT
) {
1531 if (!ctx
->Extensions
.MESA_texture_array
) {
1532 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1536 else if (target
!= GL_TEXTURE_3D
) {
1537 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexSubImage3D(target)" );
1542 _mesa_problem( ctx
, "invalid dims in texture_error_check" );
1546 /* Basic level check */
1547 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1548 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1553 _mesa_error(ctx
, GL_INVALID_VALUE
,
1554 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1557 if (height
< 0 && dimensions
> 1) {
1558 _mesa_error(ctx
, GL_INVALID_VALUE
,
1559 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1562 if (depth
< 0 && dimensions
> 2) {
1563 _mesa_error(ctx
, GL_INVALID_VALUE
,
1564 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1568 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1569 _mesa_error(ctx
, GL_INVALID_ENUM
,
1570 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1571 dimensions
, format
, type
);
1580 * Do second part of glTexSubImage which depends on the destination texture.
1581 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1584 subtexture_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1585 GLenum target
, GLint level
,
1586 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1587 GLint width
, GLint height
, GLint depth
,
1588 GLenum format
, GLenum type
,
1589 const struct gl_texture_image
*destTex
)
1592 /* undefined image level */
1593 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1597 if (xoffset
< -((GLint
)destTex
->Border
)) {
1598 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1602 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1603 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1607 if (dimensions
> 1) {
1608 if (yoffset
< -((GLint
)destTex
->Border
)) {
1609 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1613 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1614 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1619 if (dimensions
> 2) {
1620 if (zoffset
< -((GLint
)destTex
->Border
)) {
1621 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1624 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1625 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1630 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1633 if (!target_can_be_compressed(ctx
, target
)) {
1634 _mesa_error(ctx
, GL_INVALID_ENUM
,
1635 "glTexSubImage%dD(target=%s)", dimensions
,
1636 _mesa_lookup_enum_by_nr(target
));
1640 /* do tests which depend on compression block size */
1641 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1643 /* offset must be multiple of block size */
1644 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1645 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1646 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1647 dimensions
, xoffset
, yoffset
);
1650 /* size must be multiple of bw by bh or equal to whole texture size */
1651 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1652 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1653 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1656 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1657 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1658 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1668 * Test glCopyTexImage[12]D() parameters for errors.
1670 * \param ctx GL context.
1671 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1672 * \param target texture target given by the user.
1673 * \param level image level given by the user.
1674 * \param internalFormat internal format given by the user.
1675 * \param width image width given by the user.
1676 * \param height image height given by the user.
1677 * \param border texture border.
1679 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1681 * Verifies each of the parameters against the constants specified in
1682 * __GLcontextRec::Const and the supported extensions, and according to the
1683 * OpenGL specification.
1686 copytexture_error_check( GLcontext
*ctx
, GLuint dimensions
,
1687 GLenum target
, GLint level
, GLint internalFormat
,
1688 GLint width
, GLint height
, GLint border
)
1694 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1695 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1696 _mesa_error(ctx
, GL_INVALID_VALUE
,
1697 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1701 /* Check that the source buffer is complete */
1702 if (ctx
->ReadBuffer
->Name
) {
1703 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1704 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1705 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1706 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1712 if (border
< 0 || border
> 1 ||
1713 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1714 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1718 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1720 _mesa_error(ctx
, GL_INVALID_VALUE
,
1721 "glCopyTexImage%dD(internalFormat)", dimensions
);
1725 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1726 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1727 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1731 /* NOTE: the format and type aren't really significant for
1732 * TestProxyTexImage(). Only the internalformat really matters.
1736 /* Check target and call ctx->Driver.TestProxyTexImage() to check the
1737 * level, width, height and depth.
1739 if (dimensions
== 1) {
1740 if (target
== GL_TEXTURE_1D
) {
1741 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_1D
,
1742 level
, internalFormat
,
1744 width
, 1, 1, border
);
1747 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage1D(target)" );
1751 else if (dimensions
== 2) {
1752 if (target
== GL_TEXTURE_2D
) {
1753 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_2D
,
1754 level
, internalFormat
,
1756 width
, height
, 1, border
);
1758 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1759 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1760 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1761 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1764 sizeOK
= (width
== height
) &&
1765 ctx
->Driver
.TestProxyTexImage(ctx
, GL_PROXY_TEXTURE_CUBE_MAP_ARB
,
1766 level
, internalFormat
, format
, type
,
1767 width
, height
, 1, border
);
1769 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1770 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1771 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1774 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1775 GL_PROXY_TEXTURE_RECTANGLE_NV
,
1776 level
, internalFormat
,
1778 width
, height
, 1, border
);
1780 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1781 if (!ctx
->Extensions
.MESA_texture_array
) {
1782 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)");
1785 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
,
1786 GL_PROXY_TEXTURE_1D_ARRAY_EXT
,
1787 level
, internalFormat
,
1789 width
, height
, 1, border
);
1792 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexImage2D(target)" );
1797 _mesa_problem(ctx
, "invalid dimensions in copytexture_error_check");
1802 if (dimensions
== 1) {
1803 _mesa_error(ctx
, GL_INVALID_VALUE
,
1804 "glCopyTexImage1D(width=%d)", width
);
1807 ASSERT(dimensions
== 2);
1808 _mesa_error(ctx
, GL_INVALID_VALUE
,
1809 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1814 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1815 if (!target_can_be_compressed(ctx
, target
)) {
1816 _mesa_error(ctx
, GL_INVALID_ENUM
,
1817 "glCopyTexImage%dD(target)", dimensions
);
1821 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1822 "glCopyTexImage%dD(border!=0)", dimensions
);
1826 else if (_mesa_is_depth_format(internalFormat
)) {
1827 /* make sure we have depth/stencil buffers */
1828 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1829 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1830 "glCopyTexImage%dD(no depth)", dimensions
);
1834 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1835 /* make sure we have depth/stencil buffers */
1836 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1837 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1838 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
1843 /* if we get here, the parameters are OK */
1849 * Test glCopyTexSubImage[12]D() parameters for errors.
1850 * Note that this is the first part of error checking.
1851 * See also copytexsubimage_error_check2() below for the second part.
1853 * \param ctx GL context.
1854 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1855 * \param target texture target given by the user.
1856 * \param level image level given by the user.
1858 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1861 copytexsubimage_error_check1( GLcontext
*ctx
, GLuint dimensions
,
1862 GLenum target
, GLint level
)
1864 /* Check that the source buffer is complete */
1865 if (ctx
->ReadBuffer
->Name
) {
1866 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1867 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1868 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1869 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1875 if (dimensions
== 1) {
1876 if (target
!= GL_TEXTURE_1D
) {
1877 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1881 else if (dimensions
== 2) {
1882 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1883 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1884 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1885 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1889 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1890 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1891 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1895 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1896 if (!ctx
->Extensions
.MESA_texture_array
) {
1897 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1901 else if (target
!= GL_TEXTURE_2D
) {
1902 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1906 else if (dimensions
== 3) {
1907 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
1908 (!ctx
->Extensions
.MESA_texture_array
))
1909 && (target
!= GL_TEXTURE_3D
)) {
1910 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
1916 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1917 _mesa_error(ctx
, GL_INVALID_VALUE
,
1918 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1927 * Second part of error checking for glCopyTexSubImage[12]D().
1928 * \param xoffset sub-image x offset given by the user.
1929 * \param yoffset sub-image y offset given by the user.
1930 * \param zoffset sub-image z offset given by the user.
1931 * \param width image width given by the user.
1932 * \param height image height given by the user.
1935 copytexsubimage_error_check2( GLcontext
*ctx
, GLuint dimensions
,
1936 GLenum target
, GLint level
,
1937 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1938 GLsizei width
, GLsizei height
,
1939 const struct gl_texture_image
*teximage
)
1941 /* check that dest tex image exists */
1943 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1944 "glCopyTexSubImage%dD(undefined texture level: %d)",
1951 _mesa_error(ctx
, GL_INVALID_VALUE
,
1952 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
1955 if (dimensions
> 1 && height
< 0) {
1956 _mesa_error(ctx
, GL_INVALID_VALUE
,
1957 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
1961 /* check x/y offsets */
1962 if (xoffset
< -((GLint
)teximage
->Border
)) {
1963 _mesa_error(ctx
, GL_INVALID_VALUE
,
1964 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
1967 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
1968 _mesa_error(ctx
, GL_INVALID_VALUE
,
1969 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
1972 if (dimensions
> 1) {
1973 if (yoffset
< -((GLint
)teximage
->Border
)) {
1974 _mesa_error(ctx
, GL_INVALID_VALUE
,
1975 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
1978 /* NOTE: we're adding the border here, not subtracting! */
1979 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
1980 _mesa_error(ctx
, GL_INVALID_VALUE
,
1981 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
1986 /* check z offset */
1987 if (dimensions
> 2) {
1988 if (zoffset
< -((GLint
)teximage
->Border
)) {
1989 _mesa_error(ctx
, GL_INVALID_VALUE
,
1990 "glCopyTexSubImage%dD(zoffset)", dimensions
);
1993 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
1994 _mesa_error(ctx
, GL_INVALID_VALUE
,
1995 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2000 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2001 if (!target_can_be_compressed(ctx
, target
)) {
2002 _mesa_error(ctx
, GL_INVALID_ENUM
,
2003 "glCopyTexSubImage%dD(target)", dimensions
);
2006 /* offset must be multiple of 4 */
2007 if ((xoffset
& 3) || (yoffset
& 3)) {
2008 _mesa_error(ctx
, GL_INVALID_VALUE
,
2009 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2012 /* size must be multiple of 4 */
2013 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2014 _mesa_error(ctx
, GL_INVALID_VALUE
,
2015 "glCopyTexSubImage%dD(width)", dimensions
);
2018 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2019 _mesa_error(ctx
, GL_INVALID_VALUE
,
2020 "glCopyTexSubImage%dD(height)", dimensions
);
2025 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2026 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2030 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2031 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2032 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2033 dimensions
, teximage
->_BaseFormat
);
2037 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2038 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2039 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2040 "glCopyTexSubImage%dD(no depth buffer)",
2045 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2046 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2047 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2048 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2054 /* if we get here, the parameters are OK */
2059 /** Callback info for walking over FBO hash table */
2063 struct gl_texture_object
*texObj
;
2069 * Check render to texture callback. Called from _mesa_HashWalk().
2072 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2074 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2075 const struct cb_info
*info
= (struct cb_info
*) userData
;
2076 GLcontext
*ctx
= info
->ctx
;
2077 const struct gl_texture_object
*texObj
= info
->texObj
;
2078 const GLuint level
= info
->level
, face
= info
->face
;
2080 /* If this is a user-created FBO */
2083 /* check if any of the FBO's attachments point to 'texObj' */
2084 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2085 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2086 if (att
->Type
== GL_TEXTURE
&&
2087 att
->Texture
== texObj
&&
2088 att
->TextureLevel
== level
&&
2089 att
->CubeMapFace
== face
) {
2090 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2091 /* Tell driver about the new renderbuffer texture */
2092 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2093 /* Mark fb status as indeterminate to force re-validation */
2102 * When a texture image is specified we have to check if it's bound to
2103 * any framebuffer objects (render to texture) in order to detect changes
2104 * in size or format since that effects FBO completeness.
2105 * Any FBOs rendering into the texture must be re-validated.
2108 update_fbo_texture(GLcontext
*ctx
, struct gl_texture_object
*texObj
,
2109 GLuint face
, GLuint level
)
2111 /* Only check this texture if it's been marked as RenderToTexture */
2112 if (texObj
->_RenderToTexture
) {
2113 struct cb_info info
;
2115 info
.texObj
= texObj
;
2118 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2124 * If the texture object's GenerateMipmap flag is set and we've
2125 * changed the texture base level image, regenerate the rest of the
2126 * mipmap levels now.
2129 check_gen_mipmap(GLcontext
*ctx
, GLenum target
,
2130 struct gl_texture_object
*texObj
, GLint level
)
2132 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2133 if (texObj
->GenerateMipmap
&&
2134 level
== texObj
->BaseLevel
&&
2135 level
< texObj
->MaxLevel
) {
2136 ASSERT(ctx
->Driver
.GenerateMipmap
);
2137 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2142 /** Debug helper: override the user-requested internal format */
2144 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2147 if (internalFormat
== GL_RGBA16F_ARB
||
2148 internalFormat
== GL_RGBA32F_ARB
) {
2149 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2152 else if (internalFormat
== GL_RGB16F_ARB
||
2153 internalFormat
== GL_RGB32F_ARB
) {
2154 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2157 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2158 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2159 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2160 return GL_LUMINANCE_ALPHA
;
2162 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2163 internalFormat
== GL_LUMINANCE32F_ARB
) {
2164 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2165 return GL_LUMINANCE
;
2167 else if (internalFormat
== GL_ALPHA16F_ARB
||
2168 internalFormat
== GL_ALPHA32F_ARB
) {
2169 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2173 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2174 internalFormat = GL_RGBA;
2178 return internalFormat
;
2181 return internalFormat
;
2187 * Choose the actual hardware format for a texture image.
2188 * Try to use the same format as the previous image level when possible.
2189 * Otherwise, ask the driver for the best format.
2190 * It's important to try to choose a consistant format for all levels
2191 * for efficient texture memory layout/allocation. In particular, this
2192 * comes up during automatic mipmap generation.
2195 _mesa_choose_texture_format(GLcontext
*ctx
,
2196 struct gl_texture_object
*texObj
,
2197 struct gl_texture_image
*texImage
,
2198 GLenum target
, GLint level
,
2199 GLenum internalFormat
, GLenum format
, GLenum type
)
2201 /* see if we've already chosen a format for the previous level */
2203 struct gl_texture_image
*prevImage
=
2204 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2205 /* See if the prev level is defined and has an internal format which
2206 * matches the new internal format.
2209 prevImage
->Width
> 0 &&
2210 prevImage
->InternalFormat
== internalFormat
) {
2211 /* use the same format */
2212 texImage
->TexFormat
= prevImage
->TexFormat
;
2217 /* choose format from scratch */
2218 texImage
->TexFormat
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
2220 ASSERT(texImage
->TexFormat
!= MESA_FORMAT_NONE
);
2226 * Called from the API. Note that width includes the border.
2229 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2230 GLsizei width
, GLint border
, GLenum format
,
2231 GLenum type
, const GLvoid
*pixels
)
2233 GLsizei postConvWidth
= width
;
2234 GET_CURRENT_CONTEXT(ctx
);
2235 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2237 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2238 _mesa_debug(ctx
, "glTexImage1D %s %d %s %d %d %s %s %p\n",
2239 _mesa_lookup_enum_by_nr(target
), level
,
2240 _mesa_lookup_enum_by_nr(internalFormat
), width
, border
,
2241 _mesa_lookup_enum_by_nr(format
),
2242 _mesa_lookup_enum_by_nr(type
), pixels
);
2244 internalFormat
= override_internal_format(internalFormat
, width
, 1);
2246 #if FEATURE_convolve
2247 if (_mesa_is_color_format(internalFormat
)) {
2248 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2252 if (target
== GL_TEXTURE_1D
) {
2253 /* non-proxy target */
2254 struct gl_texture_object
*texObj
;
2255 struct gl_texture_image
*texImage
;
2256 const GLuint face
= _mesa_tex_target_to_face(target
);
2258 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2259 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2260 return; /* error was recorded */
2263 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2264 _mesa_update_state(ctx
);
2266 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2267 _mesa_lock_texture(ctx
, texObj
);
2269 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2271 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
2274 if (texImage
->Data
) {
2275 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2278 ASSERT(texImage
->Data
== NULL
);
2280 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2281 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2282 postConvWidth
, 1, 1,
2283 border
, internalFormat
);
2285 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
2286 internalFormat
, format
, type
);
2288 /* Give the texture to the driver. <pixels> may be null. */
2289 ASSERT(ctx
->Driver
.TexImage1D
);
2290 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2291 width
, border
, format
, type
, pixels
,
2292 &ctx
->Unpack
, texObj
, texImage
);
2294 ASSERT(texImage
->TexFormat
);
2296 _mesa_set_fetch_functions(texImage
, 1);
2298 check_gen_mipmap(ctx
, target
, texObj
, level
);
2300 update_fbo_texture(ctx
, texObj
, face
, level
);
2303 texObj
->_Complete
= GL_FALSE
;
2304 ctx
->NewState
|= _NEW_TEXTURE
;
2307 _mesa_unlock_texture(ctx
, texObj
);
2309 else if (target
== GL_PROXY_TEXTURE_1D
) {
2310 /* Proxy texture: check for errors and update proxy state */
2311 struct gl_texture_image
*texImage
;
2312 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2313 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2314 format
, type
, 1, postConvWidth
, 1, 1, border
)) {
2315 /* when error, clear all proxy texture image parameters */
2317 clear_teximage_fields(texImage
);
2320 /* no error, set the tex image parameters */
2321 struct gl_texture_object
*texObj
=
2322 _mesa_get_current_tex_object(ctx
, target
);
2324 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2325 postConvWidth
, 1, 1,
2326 border
, internalFormat
);
2327 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
2328 internalFormat
, format
, type
);
2332 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage1D(target)" );
2339 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2340 GLsizei width
, GLsizei height
, GLint border
,
2341 GLenum format
, GLenum type
,
2342 const GLvoid
*pixels
)
2344 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2345 GET_CURRENT_CONTEXT(ctx
);
2346 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2348 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2349 _mesa_debug(ctx
, "glTexImage2D %s %d %s %d %d %d %s %s %p\n",
2350 _mesa_lookup_enum_by_nr(target
), level
,
2351 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2352 border
, _mesa_lookup_enum_by_nr(format
),
2353 _mesa_lookup_enum_by_nr(type
), pixels
);
2355 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2357 #if FEATURE_convolve
2358 if (_mesa_is_color_format(internalFormat
)) {
2359 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2364 if (target
== GL_TEXTURE_2D
||
2365 (ctx
->Extensions
.ARB_texture_cube_map
&&
2366 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
2367 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) ||
2368 (ctx
->Extensions
.NV_texture_rectangle
&&
2369 target
== GL_TEXTURE_RECTANGLE_NV
) ||
2370 (ctx
->Extensions
.MESA_texture_array
&&
2371 target
== GL_TEXTURE_1D_ARRAY_EXT
)) {
2372 /* non-proxy target */
2373 struct gl_texture_object
*texObj
;
2374 struct gl_texture_image
*texImage
;
2375 const GLuint face
= _mesa_tex_target_to_face(target
);
2377 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2378 format
, type
, 2, postConvWidth
, postConvHeight
,
2380 return; /* error was recorded */
2383 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2384 _mesa_update_state(ctx
);
2386 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2387 _mesa_lock_texture(ctx
, texObj
);
2389 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2391 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
2394 if (texImage
->Data
) {
2395 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2398 ASSERT(texImage
->Data
== NULL
);
2399 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2400 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2401 postConvWidth
, postConvHeight
, 1,
2402 border
, internalFormat
);
2404 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
2405 internalFormat
, format
, type
);
2407 /* Give the texture to the driver. <pixels> may be null. */
2408 ASSERT(ctx
->Driver
.TexImage2D
);
2409 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2410 width
, height
, border
, format
, type
,
2411 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2413 ASSERT(texImage
->TexFormat
);
2415 _mesa_set_fetch_functions(texImage
, 2);
2417 check_gen_mipmap(ctx
, target
, texObj
, level
);
2419 update_fbo_texture(ctx
, texObj
, face
, level
);
2422 texObj
->_Complete
= GL_FALSE
;
2423 ctx
->NewState
|= _NEW_TEXTURE
;
2426 _mesa_unlock_texture(ctx
, texObj
);
2428 else if (target
== GL_PROXY_TEXTURE_2D
||
2429 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
2430 ctx
->Extensions
.ARB_texture_cube_map
) ||
2431 (target
== GL_PROXY_TEXTURE_RECTANGLE_NV
&&
2432 ctx
->Extensions
.NV_texture_rectangle
) ||
2433 (ctx
->Extensions
.MESA_texture_array
&&
2434 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
)) {
2435 /* Proxy texture: check for errors and update proxy state */
2436 struct gl_texture_image
*texImage
;
2437 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2438 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2439 format
, type
, 2, postConvWidth
, postConvHeight
,
2441 /* when error, clear all proxy texture image parameters */
2443 clear_teximage_fields(texImage
);
2446 /* no error, set the tex image parameters */
2447 struct gl_texture_object
*texObj
=
2448 _mesa_get_current_tex_object(ctx
, target
);
2449 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2450 postConvWidth
, postConvHeight
, 1,
2451 border
, internalFormat
);
2452 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
2453 internalFormat
, format
, type
);
2457 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage2D(target)" );
2464 * Called by the API or display list executor.
2465 * Note that width and height include the border.
2468 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2469 GLsizei width
, GLsizei height
, GLsizei depth
,
2470 GLint border
, GLenum format
, GLenum type
,
2471 const GLvoid
*pixels
)
2473 GET_CURRENT_CONTEXT(ctx
);
2474 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2476 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2477 _mesa_debug(ctx
, "glTexImage3D %s %d %s %d %d %d %d %s %s %p\n",
2478 _mesa_lookup_enum_by_nr(target
), level
,
2479 _mesa_lookup_enum_by_nr(internalFormat
), width
, height
,
2480 depth
, border
, _mesa_lookup_enum_by_nr(format
),
2481 _mesa_lookup_enum_by_nr(type
), pixels
);
2483 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2485 if (target
== GL_TEXTURE_3D
||
2486 (ctx
->Extensions
.MESA_texture_array
&&
2487 target
== GL_TEXTURE_2D_ARRAY_EXT
)) {
2488 /* non-proxy target */
2489 struct gl_texture_object
*texObj
;
2490 struct gl_texture_image
*texImage
;
2491 const GLuint face
= _mesa_tex_target_to_face(target
);
2493 if (texture_error_check(ctx
, target
, level
, (GLint
) internalFormat
,
2494 format
, type
, 3, width
, height
, depth
, border
)) {
2495 return; /* error was recorded */
2498 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2499 _mesa_update_state(ctx
);
2501 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2502 _mesa_lock_texture(ctx
, texObj
);
2504 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2506 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
2509 if (texImage
->Data
) {
2510 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2513 ASSERT(texImage
->Data
== NULL
);
2514 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2515 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2516 width
, height
, depth
,
2517 border
, internalFormat
);
2519 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
2520 internalFormat
, format
, type
);
2522 /* Give the texture to the driver. <pixels> may be null. */
2523 ASSERT(ctx
->Driver
.TexImage3D
);
2524 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2525 width
, height
, depth
, border
, format
, type
,
2526 pixels
, &ctx
->Unpack
, texObj
, texImage
);
2528 ASSERT(texImage
->TexFormat
);
2530 _mesa_set_fetch_functions(texImage
, 3);
2532 check_gen_mipmap(ctx
, target
, texObj
, level
);
2534 update_fbo_texture(ctx
, texObj
, face
, level
);
2537 texObj
->_Complete
= GL_FALSE
;
2538 ctx
->NewState
|= _NEW_TEXTURE
;
2541 _mesa_unlock_texture(ctx
, texObj
);
2543 else if (target
== GL_PROXY_TEXTURE_3D
||
2544 (ctx
->Extensions
.MESA_texture_array
&&
2545 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
)) {
2546 /* Proxy texture: check for errors and update proxy state */
2547 struct gl_texture_image
*texImage
;
2548 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
2549 if (texture_error_check(ctx
, target
, level
, internalFormat
,
2550 format
, type
, 3, width
, height
, depth
, border
)) {
2551 /* when error, clear all proxy texture image parameters */
2553 clear_teximage_fields(texImage
);
2556 /* no error, set the tex image parameters */
2557 struct gl_texture_object
*texObj
=
2558 _mesa_get_current_tex_object(ctx
, target
);
2559 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2560 depth
, border
, internalFormat
);
2561 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
2562 internalFormat
, format
, type
);
2566 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexImage3D(target)" );
2573 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2574 GLsizei width
, GLsizei height
, GLsizei depth
,
2575 GLint border
, GLenum format
, GLenum type
,
2576 const GLvoid
*pixels
)
2578 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2579 depth
, border
, format
, type
, pixels
);
2583 #if FEATURE_OES_EGL_image
2585 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2587 struct gl_texture_object
*texObj
;
2588 struct gl_texture_image
*texImage
;
2589 GET_CURRENT_CONTEXT(ctx
);
2590 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2592 if (!ctx
->Extensions
.OES_EGL_image
) {
2593 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2594 "glEGLImageTargetTexture2DOES(unsupported)");
2598 if (target
!= GL_TEXTURE_2D
) {
2599 _mesa_error(ctx
, GL_INVALID_ENUM
,
2600 "glEGLImageTargetTexture2D(target=%d)", target
);
2604 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2605 _mesa_update_state(ctx
);
2607 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2608 _mesa_lock_texture(ctx
, texObj
);
2610 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2612 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2615 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2617 ASSERT(texImage
->Data
== NULL
);
2618 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2619 texObj
, texImage
, image
);
2622 texObj
->_Complete
= GL_FALSE
;
2623 ctx
->NewState
|= _NEW_TEXTURE
;
2625 _mesa_unlock_texture(ctx
, texObj
);
2632 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2633 GLint xoffset
, GLsizei width
,
2634 GLenum format
, GLenum type
,
2635 const GLvoid
*pixels
)
2637 GLsizei postConvWidth
= width
;
2638 struct gl_texture_object
*texObj
;
2639 struct gl_texture_image
*texImage
;
2640 GET_CURRENT_CONTEXT(ctx
);
2641 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2643 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2644 _mesa_debug(ctx
, "glTexSubImage1D %s %d %d %d %s %s %p\n",
2645 _mesa_lookup_enum_by_nr(target
), level
,
2646 xoffset
, width
, _mesa_lookup_enum_by_nr(format
),
2647 _mesa_lookup_enum_by_nr(type
), pixels
);
2649 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2650 _mesa_update_state(ctx
);
2652 #if FEATURE_convolve
2653 /* XXX should test internal format */
2654 if (_mesa_is_color_format(format
)) {
2655 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2659 if (subtexture_error_check(ctx
, 1, target
, level
, xoffset
, 0, 0,
2660 postConvWidth
, 1, 1, format
, type
)) {
2661 return; /* error was detected */
2665 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2668 _mesa_lock_texture(ctx
, texObj
);
2670 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2672 if (subtexture_error_check2(ctx
, 1, target
, level
, xoffset
, 0, 0,
2673 postConvWidth
, 1, 1,
2674 format
, type
, texImage
)) {
2675 /* error was recorded */
2677 else if (width
> 0) {
2678 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2679 xoffset
+= texImage
->Border
;
2681 ASSERT(ctx
->Driver
.TexSubImage1D
);
2682 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
, xoffset
, width
,
2683 format
, type
, pixels
, &ctx
->Unpack
,
2686 check_gen_mipmap(ctx
, target
, texObj
, level
);
2688 ctx
->NewState
|= _NEW_TEXTURE
;
2691 _mesa_unlock_texture(ctx
, texObj
);
2696 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2697 GLint xoffset
, GLint yoffset
,
2698 GLsizei width
, GLsizei height
,
2699 GLenum format
, GLenum type
,
2700 const GLvoid
*pixels
)
2702 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2703 struct gl_texture_object
*texObj
;
2704 struct gl_texture_image
*texImage
;
2705 GET_CURRENT_CONTEXT(ctx
);
2706 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2708 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2709 _mesa_debug(ctx
, "glTexSubImage2D %s %d %d %d %d %d %s %s %p\n",
2710 _mesa_lookup_enum_by_nr(target
), level
,
2711 xoffset
, yoffset
, width
, height
,
2712 _mesa_lookup_enum_by_nr(format
),
2713 _mesa_lookup_enum_by_nr(type
), pixels
);
2715 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2716 _mesa_update_state(ctx
);
2718 #if FEATURE_convolve
2719 /* XXX should test internal format */
2720 if (_mesa_is_color_format(format
)) {
2721 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2726 if (subtexture_error_check(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2727 postConvWidth
, postConvHeight
, 1, format
, type
)) {
2728 return; /* error was detected */
2731 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2733 _mesa_lock_texture(ctx
, texObj
);
2735 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2737 if (subtexture_error_check2(ctx
, 2, target
, level
, xoffset
, yoffset
, 0,
2738 postConvWidth
, postConvHeight
, 1,
2739 format
, type
, texImage
)) {
2740 /* error was recorded */
2742 else if (width
> 0 && height
>= 0) {
2743 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2744 xoffset
+= texImage
->Border
;
2745 yoffset
+= texImage
->Border
;
2747 ASSERT(ctx
->Driver
.TexSubImage2D
);
2748 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2749 width
, height
, format
, type
, pixels
,
2750 &ctx
->Unpack
, texObj
, texImage
);
2752 check_gen_mipmap(ctx
, target
, texObj
, level
);
2754 ctx
->NewState
|= _NEW_TEXTURE
;
2757 _mesa_unlock_texture(ctx
, texObj
);
2763 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2764 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2765 GLsizei width
, GLsizei height
, GLsizei depth
,
2766 GLenum format
, GLenum type
,
2767 const GLvoid
*pixels
)
2769 struct gl_texture_object
*texObj
;
2770 struct gl_texture_image
*texImage
;
2771 GET_CURRENT_CONTEXT(ctx
);
2772 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2774 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2775 _mesa_debug(ctx
, "glTexSubImage3D %s %d %d %d %d %d %d %d %s %s %p\n",
2776 _mesa_lookup_enum_by_nr(target
), level
,
2777 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2778 _mesa_lookup_enum_by_nr(format
),
2779 _mesa_lookup_enum_by_nr(type
), pixels
);
2781 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2782 _mesa_update_state(ctx
);
2784 if (subtexture_error_check(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2785 width
, height
, depth
, format
, type
)) {
2786 return; /* error was detected */
2789 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2791 _mesa_lock_texture(ctx
, texObj
);
2793 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2795 if (subtexture_error_check2(ctx
, 3, target
, level
,
2796 xoffset
, yoffset
, zoffset
,
2797 width
, height
, depth
,
2798 format
, type
, texImage
)) {
2799 /* error was recorded */
2801 else if (width
> 0 && height
> 0 && height
> 0) {
2802 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2803 xoffset
+= texImage
->Border
;
2804 yoffset
+= texImage
->Border
;
2805 zoffset
+= texImage
->Border
;
2807 ASSERT(ctx
->Driver
.TexSubImage3D
);
2808 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2809 xoffset
, yoffset
, zoffset
,
2810 width
, height
, depth
,
2811 format
, type
, pixels
,
2812 &ctx
->Unpack
, texObj
, texImage
);
2814 check_gen_mipmap(ctx
, target
, texObj
, level
);
2816 ctx
->NewState
|= _NEW_TEXTURE
;
2819 _mesa_unlock_texture(ctx
, texObj
);
2825 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2826 GLenum internalFormat
,
2828 GLsizei width
, GLint border
)
2830 struct gl_texture_object
*texObj
;
2831 struct gl_texture_image
*texImage
;
2832 GLsizei postConvWidth
= width
;
2833 const GLuint face
= _mesa_tex_target_to_face(target
);
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
, "glCopyTexImage1D %s %d %s %d %d %d %d\n",
2839 _mesa_lookup_enum_by_nr(target
), level
,
2840 _mesa_lookup_enum_by_nr(internalFormat
),
2841 x
, y
, width
, border
);
2843 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2844 _mesa_update_state(ctx
);
2846 #if FEATURE_convolve
2847 if (_mesa_is_color_format(internalFormat
)) {
2848 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
2852 if (copytexture_error_check(ctx
, 1, target
, level
, internalFormat
,
2853 postConvWidth
, 1, border
))
2856 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2858 _mesa_lock_texture(ctx
, texObj
);
2860 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2862 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage1D");
2865 if (texImage
->Data
) {
2866 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2869 ASSERT(texImage
->Data
== NULL
);
2871 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2872 _mesa_init_teximage_fields(ctx
, target
, texImage
, postConvWidth
, 1, 1,
2873 border
, internalFormat
);
2875 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
2876 internalFormat
, GL_NONE
, GL_NONE
);
2878 ASSERT(ctx
->Driver
.CopyTexImage1D
);
2879 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2880 x
, y
, width
, border
);
2882 ASSERT(texImage
->TexFormat
);
2884 _mesa_set_fetch_functions(texImage
, 1);
2886 check_gen_mipmap(ctx
, target
, texObj
, level
);
2888 update_fbo_texture(ctx
, texObj
, face
, level
);
2891 texObj
->_Complete
= GL_FALSE
;
2892 ctx
->NewState
|= _NEW_TEXTURE
;
2895 _mesa_unlock_texture(ctx
, texObj
);
2901 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2902 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2905 struct gl_texture_object
*texObj
;
2906 struct gl_texture_image
*texImage
;
2907 GLsizei postConvWidth
= width
, postConvHeight
= height
;
2908 const GLuint face
= _mesa_tex_target_to_face(target
);
2909 GET_CURRENT_CONTEXT(ctx
);
2910 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2912 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2913 _mesa_debug(ctx
, "glCopyTexImage2D %s %d %s %d %d %d %d %d\n",
2914 _mesa_lookup_enum_by_nr(target
), level
,
2915 _mesa_lookup_enum_by_nr(internalFormat
),
2916 x
, y
, width
, height
, border
);
2918 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2919 _mesa_update_state(ctx
);
2921 #if FEATURE_convolve
2922 if (_mesa_is_color_format(internalFormat
)) {
2923 _mesa_adjust_image_for_convolution(ctx
, 2, &postConvWidth
,
2928 if (copytexture_error_check(ctx
, 2, target
, level
, internalFormat
,
2929 postConvWidth
, postConvHeight
, border
))
2932 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2934 _mesa_lock_texture(ctx
, texObj
);
2936 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2939 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage2D");
2942 if (texImage
->Data
) {
2943 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2946 ASSERT(texImage
->Data
== NULL
);
2948 clear_teximage_fields(texImage
); /* not really needed, but helpful */
2949 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2950 postConvWidth
, postConvHeight
, 1,
2951 border
, internalFormat
);
2953 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
2954 internalFormat
, GL_NONE
, GL_NONE
);
2956 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2957 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2958 x
, y
, width
, height
, border
);
2960 ASSERT(texImage
->TexFormat
);
2962 _mesa_set_fetch_functions(texImage
, 2);
2964 check_gen_mipmap(ctx
, target
, texObj
, level
);
2966 update_fbo_texture(ctx
, texObj
, face
, level
);
2969 texObj
->_Complete
= GL_FALSE
;
2970 ctx
->NewState
|= _NEW_TEXTURE
;
2973 _mesa_unlock_texture(ctx
, texObj
);
2978 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2979 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2981 struct gl_texture_object
*texObj
;
2982 struct gl_texture_image
*texImage
;
2983 GLsizei postConvWidth
= width
;
2987 GET_CURRENT_CONTEXT(ctx
);
2988 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2990 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2991 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2992 _mesa_lookup_enum_by_nr(target
),
2993 level
, xoffset
, x
, y
, width
);
2995 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2996 _mesa_update_state(ctx
);
2998 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
3001 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3003 _mesa_lock_texture(ctx
, texObj
);
3005 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3007 #if FEATURE_convolve
3008 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3009 _mesa_adjust_image_for_convolution(ctx
, 1, &postConvWidth
, NULL
);
3013 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
3014 xoffset
, 0, 0, postConvWidth
, 1,
3016 /* error was recorded */
3019 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3020 xoffset
+= texImage
->Border
;
3022 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3024 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
3025 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
3026 xoffset
, x
, y
, width
);
3028 check_gen_mipmap(ctx
, target
, texObj
, level
);
3030 ctx
->NewState
|= _NEW_TEXTURE
;
3034 _mesa_unlock_texture(ctx
, texObj
);
3040 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3041 GLint xoffset
, GLint yoffset
,
3042 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3044 struct gl_texture_object
*texObj
;
3045 struct gl_texture_image
*texImage
;
3046 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3047 GET_CURRENT_CONTEXT(ctx
);
3048 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3050 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3051 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
3052 _mesa_lookup_enum_by_nr(target
),
3053 level
, xoffset
, yoffset
, x
, y
, width
, height
);
3055 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3056 _mesa_update_state(ctx
);
3058 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
3061 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3063 _mesa_lock_texture(ctx
, texObj
);
3065 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3067 #if FEATURE_convolve
3068 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3069 _mesa_adjust_image_for_convolution(ctx
, 2,
3070 &postConvWidth
, &postConvHeight
);
3074 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
3075 xoffset
, yoffset
, 0,
3076 postConvWidth
, postConvHeight
,
3078 /* error was recorded */
3081 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3082 xoffset
+= texImage
->Border
;
3083 yoffset
+= texImage
->Border
;
3085 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3087 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
3088 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
3089 x
, y
, width
, height
);
3091 check_gen_mipmap(ctx
, target
, texObj
, level
);
3093 ctx
->NewState
|= _NEW_TEXTURE
;
3097 _mesa_unlock_texture(ctx
, texObj
);
3103 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3104 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3105 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3107 struct gl_texture_object
*texObj
;
3108 struct gl_texture_image
*texImage
;
3109 GLsizei postConvWidth
= width
, postConvHeight
= height
;
3110 GET_CURRENT_CONTEXT(ctx
);
3111 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3113 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3114 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
3115 _mesa_lookup_enum_by_nr(target
),
3116 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3118 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3119 _mesa_update_state(ctx
);
3121 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
3124 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3126 _mesa_lock_texture(ctx
, texObj
);
3128 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3130 #if FEATURE_convolve
3131 if (texImage
&& _mesa_is_color_format(texImage
->InternalFormat
)) {
3132 _mesa_adjust_image_for_convolution(ctx
, 2,
3133 &postConvWidth
, &postConvHeight
);
3137 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
3138 zoffset
, postConvWidth
, postConvHeight
,
3140 /* error was recored */
3143 /* If we have a border, xoffset=-1 is legal. Bias by border width */
3144 xoffset
+= texImage
->Border
;
3145 yoffset
+= texImage
->Border
;
3146 zoffset
+= texImage
->Border
;
3148 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3150 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
3151 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
3152 xoffset
, yoffset
, zoffset
,
3153 x
, y
, width
, height
);
3155 check_gen_mipmap(ctx
, target
, texObj
, level
);
3157 ctx
->NewState
|= _NEW_TEXTURE
;
3161 _mesa_unlock_texture(ctx
, texObj
);
3167 /**********************************************************************/
3168 /****** Compressed Textures ******/
3169 /**********************************************************************/
3173 * Return expected size of a compressed texture.
3176 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3179 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3180 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3185 * Return compressed texture block size, in pixels.
3188 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3190 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3191 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3196 * Error checking for glCompressedTexImage[123]D().
3197 * \return error code or GL_NO_ERROR.
3200 compressed_texture_error_check(GLcontext
*ctx
, GLint dimensions
,
3201 GLenum target
, GLint level
,
3202 GLenum internalFormat
, GLsizei width
,
3203 GLsizei height
, GLsizei depth
, GLint border
,
3206 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3208 if (dimensions
== 1) {
3209 /* 1D compressed textures not allowed */
3210 return GL_INVALID_ENUM
;
3212 else if (dimensions
== 2) {
3213 if (target
== GL_PROXY_TEXTURE_2D
) {
3214 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3216 else if (target
== GL_TEXTURE_2D
) {
3217 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3219 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3220 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3221 return GL_INVALID_ENUM
; /*target*/
3222 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3224 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3225 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3226 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3227 return GL_INVALID_ENUM
; /*target*/
3228 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3231 return GL_INVALID_ENUM
; /*target*/
3234 else if (dimensions
== 3) {
3235 /* 3D compressed textures not allowed */
3236 return GL_INVALID_ENUM
;
3240 return GL_INVALID_ENUM
;
3243 maxTextureSize
= 1 << (maxLevels
- 1);
3245 /* This will detect any invalid internalFormat value */
3246 if (!_mesa_is_compressed_format(ctx
, internalFormat
))
3247 return GL_INVALID_ENUM
;
3249 /* This should really never fail */
3250 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3251 return GL_INVALID_ENUM
;
3254 return GL_INVALID_VALUE
;
3257 * XXX We should probably use the proxy texture error check function here.
3259 if (width
< 1 || width
> maxTextureSize
||
3260 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3261 return GL_INVALID_VALUE
;
3263 if ((height
< 1 || height
> maxTextureSize
||
3264 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3266 return GL_INVALID_VALUE
;
3268 if ((depth
< 1 || depth
> maxTextureSize
||
3269 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3271 return GL_INVALID_VALUE
;
3273 /* For cube map, width must equal height */
3274 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3275 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3276 return GL_INVALID_VALUE
;
3278 if (level
< 0 || level
>= maxLevels
)
3279 return GL_INVALID_VALUE
;
3281 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3282 if (expectedSize
!= imageSize
)
3283 return GL_INVALID_VALUE
;
3285 #if FEATURE_EXT_texture_sRGB
3286 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3287 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3288 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3289 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3291 return GL_INVALID_OPERATION
;
3300 * Error checking for glCompressedTexSubImage[123]D().
3301 * \warning There are some bad assumptions here about the size of compressed
3302 * texture tiles (multiple of 4) used to test the validity of the
3303 * offset and size parameters.
3304 * \return error code or GL_NO_ERROR.
3307 compressed_subtexture_error_check(GLcontext
*ctx
, GLint dimensions
,
3308 GLenum target
, GLint level
,
3309 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3310 GLsizei width
, GLsizei height
, GLsizei depth
,
3311 GLenum format
, GLsizei imageSize
)
3313 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3317 if (dimensions
== 1) {
3318 /* 1D compressed textures not allowed */
3319 return GL_INVALID_ENUM
;
3321 else if (dimensions
== 2) {
3322 if (target
== GL_PROXY_TEXTURE_2D
) {
3323 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3325 else if (target
== GL_TEXTURE_2D
) {
3326 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3328 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3329 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3330 return GL_INVALID_ENUM
; /*target*/
3331 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3333 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3334 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3335 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3336 return GL_INVALID_ENUM
; /*target*/
3337 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3340 return GL_INVALID_ENUM
; /*target*/
3343 else if (dimensions
== 3) {
3344 /* 3D compressed textures not allowed */
3345 return GL_INVALID_ENUM
;
3348 maxTextureSize
= 1 << (maxLevels
- 1);
3350 /* this will catch any invalid compressed format token */
3351 if (!_mesa_is_compressed_format(ctx
, format
))
3352 return GL_INVALID_ENUM
;
3354 if (width
< 1 || width
> maxTextureSize
)
3355 return GL_INVALID_VALUE
;
3357 if ((height
< 1 || height
> maxTextureSize
)
3359 return GL_INVALID_VALUE
;
3361 if (level
< 0 || level
>= maxLevels
)
3362 return GL_INVALID_VALUE
;
3365 * do checks which depend on compression block size
3367 get_compressed_block_size(format
, &bw
, &bh
);
3369 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3370 return GL_INVALID_VALUE
;
3372 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3373 return GL_INVALID_VALUE
;
3375 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3376 return GL_INVALID_VALUE
;
3378 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3379 if (expectedSize
!= imageSize
)
3380 return GL_INVALID_VALUE
;
3387 * Do second part of glCompressedTexSubImage error checking.
3388 * \return GL_TRUE if error found, GL_FALSE otherwise.
3391 compressed_subtexture_error_check2(GLcontext
*ctx
, GLuint dims
,
3392 GLsizei width
, GLsizei height
,
3393 GLsizei depth
, GLenum format
,
3394 struct gl_texture_image
*texImage
)
3397 if ((GLint
) format
!= texImage
->InternalFormat
) {
3398 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3399 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3403 if (((width
== 1 || width
== 2) &&
3404 width
!= (GLsizei
) texImage
->Width
) ||
3405 (width
> (GLsizei
) texImage
->Width
)) {
3406 _mesa_error(ctx
, GL_INVALID_VALUE
,
3407 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3412 if (((height
== 1 || height
== 2) &&
3413 height
!= (GLsizei
) texImage
->Height
) ||
3414 (height
> (GLsizei
) texImage
->Height
)) {
3415 _mesa_error(ctx
, GL_INVALID_VALUE
,
3416 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3422 if (((depth
== 1 || depth
== 2) &&
3423 depth
!= (GLsizei
) texImage
->Depth
) ||
3424 (depth
> (GLsizei
) texImage
->Depth
)) {
3425 _mesa_error(ctx
, GL_INVALID_VALUE
,
3426 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3437 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3438 GLenum internalFormat
, GLsizei width
,
3439 GLint border
, GLsizei imageSize
,
3442 GET_CURRENT_CONTEXT(ctx
);
3443 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3445 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3446 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3447 _mesa_lookup_enum_by_nr(target
), level
,
3448 _mesa_lookup_enum_by_nr(internalFormat
),
3449 width
, border
, imageSize
, data
);
3451 if (target
== GL_TEXTURE_1D
) {
3452 /* non-proxy target */
3453 struct gl_texture_object
*texObj
;
3454 struct gl_texture_image
*texImage
;
3455 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3456 internalFormat
, width
, 1, 1, border
, imageSize
);
3458 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3462 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3464 _mesa_lock_texture(ctx
, texObj
);
3466 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3468 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3471 if (texImage
->Data
) {
3472 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3474 ASSERT(texImage
->Data
== NULL
);
3476 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3477 border
, internalFormat
);
3479 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
3480 internalFormat
, GL_NONE
, GL_NONE
);
3482 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3483 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3484 internalFormat
, width
, border
,
3488 _mesa_set_fetch_functions(texImage
, 1);
3490 check_gen_mipmap(ctx
, target
, texObj
, level
);
3493 texObj
->_Complete
= GL_FALSE
;
3494 ctx
->NewState
|= _NEW_TEXTURE
;
3497 _mesa_unlock_texture(ctx
, texObj
);
3499 else if (target
== GL_PROXY_TEXTURE_1D
) {
3500 /* Proxy texture: check for errors and update proxy state */
3501 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3502 internalFormat
, width
, 1, 1, border
, imageSize
);
3504 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3505 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3506 internalFormat
, GL_NONE
, GL_NONE
,
3507 width
, 1, 1, border
);
3510 /* if error, clear all proxy texture image parameters */
3511 struct gl_texture_image
*texImage
;
3512 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3514 clear_teximage_fields(texImage
);
3517 /* store the teximage parameters */
3518 struct gl_texture_object
*texObj
;
3519 struct gl_texture_image
*texImage
;
3521 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3523 _mesa_lock_texture(ctx
, texObj
);
3525 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3526 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3527 border
, internalFormat
);
3528 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
3529 internalFormat
, GL_NONE
, GL_NONE
);
3531 _mesa_unlock_texture(ctx
, texObj
);
3535 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3541 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3542 GLenum internalFormat
, GLsizei width
,
3543 GLsizei height
, GLint border
, GLsizei imageSize
,
3546 GET_CURRENT_CONTEXT(ctx
);
3547 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3549 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3550 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3551 _mesa_lookup_enum_by_nr(target
), level
,
3552 _mesa_lookup_enum_by_nr(internalFormat
),
3553 width
, height
, border
, imageSize
, data
);
3556 switch (internalFormat
) {
3557 case GL_PALETTE4_RGB8_OES
:
3558 case GL_PALETTE4_RGBA8_OES
:
3559 case GL_PALETTE4_R5_G6_B5_OES
:
3560 case GL_PALETTE4_RGBA4_OES
:
3561 case GL_PALETTE4_RGB5_A1_OES
:
3562 case GL_PALETTE8_RGB8_OES
:
3563 case GL_PALETTE8_RGBA8_OES
:
3564 case GL_PALETTE8_R5_G6_B5_OES
:
3565 case GL_PALETTE8_RGBA4_OES
:
3566 case GL_PALETTE8_RGB5_A1_OES
:
3567 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3568 width
, height
, imageSize
, data
);
3573 if (target
== GL_TEXTURE_2D
||
3574 (ctx
->Extensions
.ARB_texture_cube_map
&&
3575 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3576 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3577 /* non-proxy target */
3578 struct gl_texture_object
*texObj
;
3579 struct gl_texture_image
*texImage
;
3581 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3582 internalFormat
, width
, height
, 1, border
, imageSize
);
3584 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3588 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3590 _mesa_lock_texture(ctx
, texObj
);
3592 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3594 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3597 if (texImage
->Data
) {
3598 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3600 ASSERT(texImage
->Data
== NULL
);
3602 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3603 border
, internalFormat
);
3605 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
3606 internalFormat
, GL_NONE
, GL_NONE
);
3608 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3609 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3610 internalFormat
, width
, height
,
3611 border
, imageSize
, data
,
3614 _mesa_set_fetch_functions(texImage
, 2);
3616 check_gen_mipmap(ctx
, target
, texObj
, level
);
3619 texObj
->_Complete
= GL_FALSE
;
3620 ctx
->NewState
|= _NEW_TEXTURE
;
3623 _mesa_unlock_texture(ctx
, texObj
);
3625 else if (target
== GL_PROXY_TEXTURE_2D
||
3626 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3627 ctx
->Extensions
.ARB_texture_cube_map
)) {
3628 /* Proxy texture: check for errors and update proxy state */
3629 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3630 internalFormat
, width
, height
, 1, border
, imageSize
);
3632 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3633 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3634 internalFormat
, GL_NONE
, GL_NONE
,
3635 width
, height
, 1, border
);
3638 /* if error, clear all proxy texture image parameters */
3639 struct gl_texture_image
*texImage
;
3640 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3642 clear_teximage_fields(texImage
);
3645 /* store the teximage parameters */
3646 struct gl_texture_object
*texObj
;
3647 struct gl_texture_image
*texImage
;
3649 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3651 _mesa_lock_texture(ctx
, texObj
);
3653 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3654 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
3655 border
, internalFormat
);
3656 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
3657 internalFormat
, GL_NONE
, GL_NONE
);
3659 _mesa_unlock_texture(ctx
, texObj
);
3663 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3670 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3671 GLenum internalFormat
, GLsizei width
,
3672 GLsizei height
, GLsizei depth
, GLint border
,
3673 GLsizei imageSize
, const GLvoid
*data
)
3675 GET_CURRENT_CONTEXT(ctx
);
3676 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3678 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3679 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3680 _mesa_lookup_enum_by_nr(target
), level
,
3681 _mesa_lookup_enum_by_nr(internalFormat
),
3682 width
, height
, depth
, border
, imageSize
, data
);
3684 if (target
== GL_TEXTURE_3D
) {
3685 /* non-proxy target */
3686 struct gl_texture_object
*texObj
;
3687 struct gl_texture_image
*texImage
;
3688 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3689 internalFormat
, width
, height
, depth
, border
, imageSize
);
3691 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3695 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3697 _mesa_lock_texture(ctx
, texObj
);
3699 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3701 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3704 if (texImage
->Data
) {
3705 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3707 ASSERT(texImage
->Data
== NULL
);
3709 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3710 width
, height
, depth
,
3711 border
, internalFormat
);
3713 /* Choose actual texture format */
3714 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
3715 internalFormat
, GL_NONE
, GL_NONE
);
3717 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3718 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3720 width
, height
, depth
,
3721 border
, imageSize
, data
,
3724 _mesa_set_fetch_functions(texImage
, 3);
3726 check_gen_mipmap(ctx
, target
, texObj
, level
);
3729 texObj
->_Complete
= GL_FALSE
;
3730 ctx
->NewState
|= _NEW_TEXTURE
;
3733 _mesa_unlock_texture(ctx
, texObj
);
3735 else if (target
== GL_PROXY_TEXTURE_3D
) {
3736 /* Proxy texture: check for errors and update proxy state */
3737 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3738 internalFormat
, width
, height
, depth
, border
, imageSize
);
3740 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3741 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3742 internalFormat
, GL_NONE
, GL_NONE
,
3743 width
, height
, depth
, border
);
3746 /* if error, clear all proxy texture image parameters */
3747 struct gl_texture_image
*texImage
;
3748 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3750 clear_teximage_fields(texImage
);
3753 /* store the teximage parameters */
3754 struct gl_texture_object
*texObj
;
3755 struct gl_texture_image
*texImage
;
3757 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3759 _mesa_lock_texture(ctx
, texObj
);
3761 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3762 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3763 depth
, border
, internalFormat
);
3764 _mesa_choose_texture_format(ctx
, texObj
, texImage
, target
, level
,
3765 internalFormat
, GL_NONE
, GL_NONE
);
3767 _mesa_unlock_texture(ctx
, texObj
);
3771 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3778 * Common helper for glCompressedTexSubImage1/2/3D().
3781 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3782 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3783 GLsizei width
, GLsizei height
, GLsizei depth
,
3784 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3786 struct gl_texture_object
*texObj
;
3787 struct gl_texture_image
*texImage
;
3789 GET_CURRENT_CONTEXT(ctx
);
3790 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3792 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3793 xoffset
, 0, 0, /* pos */
3794 width
, height
, depth
, /* size */
3797 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3801 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3803 _mesa_lock_texture(ctx
, texObj
);
3805 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3808 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3809 format
, texImage
)) {
3810 /* error was recorded */
3812 else if (width
> 0 && height
> 0 && depth
> 0) {
3815 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3816 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3818 format
, imageSize
, data
,
3823 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3824 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3827 format
, imageSize
, data
,
3832 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3833 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3834 xoffset
, yoffset
, zoffset
,
3835 width
, height
, depth
,
3836 format
, imageSize
, data
,
3844 check_gen_mipmap(ctx
, target
, texObj
, level
);
3846 ctx
->NewState
|= _NEW_TEXTURE
;
3849 _mesa_unlock_texture(ctx
, texObj
);
3854 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3855 GLsizei width
, GLenum format
,
3856 GLsizei imageSize
, const GLvoid
*data
)
3858 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3859 format
, imageSize
, data
);
3864 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3865 GLint yoffset
, GLsizei width
, GLsizei height
,
3866 GLenum format
, GLsizei imageSize
,
3869 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3870 width
, height
, 1, format
, imageSize
, data
);
3875 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3876 GLint yoffset
, GLint zoffset
, GLsizei width
,
3877 GLsizei height
, GLsizei depth
, GLenum format
,
3878 GLsizei imageSize
, const GLvoid
*data
)
3880 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3881 width
, height
, depth
, format
, imageSize
, data
);