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"
38 #include "framebuffer.h"
44 #include "texcompress.h"
53 * State changes which we care about for glCopyTex[Sub]Image() calls.
54 * In particular, we care about pixel transfer state and buffer state
55 * (such as glReadBuffer to make sure we read from the right renderbuffer).
57 #define NEW_COPY_TEX_STATE (_MESA_NEW_TRANSFER_STATE | \
64 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
68 _mesa_alloc_texmemory(GLsizei bytes
)
70 return _mesa_align_malloc(bytes
, 512);
75 * Free texture memory allocated with _mesa_alloc_texmemory()
78 _mesa_free_texmemory(void *m
)
85 * Compute floor(log_base_2(n)).
115 * Return the simple base format for a given internal texture format.
116 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
118 * \param ctx GL context.
119 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
121 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
122 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
124 * This is the format which is used during texture application (i.e. the
125 * texture format and env mode determine the arithmetic used.
127 * XXX this could be static
130 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
132 switch (internalFormat
) {
147 case GL_LUMINANCE_ALPHA
:
148 case GL_LUMINANCE4_ALPHA4
:
149 case GL_LUMINANCE6_ALPHA2
:
150 case GL_LUMINANCE8_ALPHA8
:
151 case GL_LUMINANCE12_ALPHA4
:
152 case GL_LUMINANCE12_ALPHA12
:
153 case GL_LUMINANCE16_ALPHA16
:
154 return GL_LUMINANCE_ALPHA
;
185 if (ctx
->Extensions
.EXT_paletted_texture
) {
186 switch (internalFormat
) {
188 case GL_COLOR_INDEX1_EXT
:
189 case GL_COLOR_INDEX2_EXT
:
190 case GL_COLOR_INDEX4_EXT
:
191 case GL_COLOR_INDEX8_EXT
:
192 case GL_COLOR_INDEX12_EXT
:
193 case GL_COLOR_INDEX16_EXT
:
194 return GL_COLOR_INDEX
;
200 if (ctx
->Extensions
.ARB_depth_texture
) {
201 switch (internalFormat
) {
202 case GL_DEPTH_COMPONENT
:
203 case GL_DEPTH_COMPONENT16
:
204 case GL_DEPTH_COMPONENT24
:
205 case GL_DEPTH_COMPONENT32
:
206 return GL_DEPTH_COMPONENT
;
212 switch (internalFormat
) {
213 case GL_COMPRESSED_ALPHA
:
215 case GL_COMPRESSED_LUMINANCE
:
217 case GL_COMPRESSED_LUMINANCE_ALPHA
:
218 return GL_LUMINANCE_ALPHA
;
219 case GL_COMPRESSED_INTENSITY
:
221 case GL_COMPRESSED_RGB
:
223 case GL_COMPRESSED_RGBA
:
229 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
230 switch (internalFormat
) {
231 case GL_COMPRESSED_RGB_FXT1_3DFX
:
233 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
240 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
241 switch (internalFormat
) {
242 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
244 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
245 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
246 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
253 if (ctx
->Extensions
.S3_s3tc
) {
254 switch (internalFormat
) {
266 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
267 if (internalFormat
== GL_YCBCR_MESA
)
268 return GL_YCBCR_MESA
;
271 if (ctx
->Extensions
.ARB_texture_float
) {
272 switch (internalFormat
) {
273 case GL_ALPHA16F_ARB
:
274 case GL_ALPHA32F_ARB
:
282 case GL_INTENSITY16F_ARB
:
283 case GL_INTENSITY32F_ARB
:
285 case GL_LUMINANCE16F_ARB
:
286 case GL_LUMINANCE32F_ARB
:
288 case GL_LUMINANCE_ALPHA16F_ARB
:
289 case GL_LUMINANCE_ALPHA32F_ARB
:
290 return GL_LUMINANCE_ALPHA
;
296 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
297 switch (internalFormat
) {
306 if (ctx
->Extensions
.MESA_texture_signed_rgba
) {
307 switch (internalFormat
) {
316 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
317 switch (internalFormat
) {
318 case GL_DEPTH_STENCIL_EXT
:
319 case GL_DEPTH24_STENCIL8_EXT
:
320 return GL_DEPTH_STENCIL_EXT
;
326 #if FEATURE_EXT_texture_sRGB
327 if (ctx
->Extensions
.EXT_texture_sRGB
) {
328 switch (internalFormat
) {
331 case GL_COMPRESSED_SRGB_EXT
:
332 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
334 case GL_SRGB_ALPHA_EXT
:
335 case GL_SRGB8_ALPHA8_EXT
:
336 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
337 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
338 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
339 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
341 case GL_SLUMINANCE_ALPHA_EXT
:
342 case GL_SLUMINANCE8_ALPHA8_EXT
:
343 case GL_COMPRESSED_SLUMINANCE_EXT
:
344 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
345 return GL_LUMINANCE_ALPHA
;
346 case GL_SLUMINANCE_EXT
:
347 case GL_SLUMINANCE8_EXT
:
353 #endif /* FEATURE_EXT_texture_sRGB */
355 if (ctx
->Extensions
.EXT_texture_integer
) {
356 switch (internalFormat
) {
358 case GL_RGBA16UI_EXT
:
359 case GL_RGBA32UI_EXT
:
371 case GL_ALPHA8UI_EXT
:
372 case GL_ALPHA16UI_EXT
:
373 case GL_ALPHA32UI_EXT
:
375 case GL_ALPHA16I_EXT
:
376 case GL_ALPHA32I_EXT
:
378 case GL_INTENSITY8UI_EXT
:
379 case GL_INTENSITY16UI_EXT
:
380 case GL_INTENSITY32UI_EXT
:
381 case GL_INTENSITY8I_EXT
:
382 case GL_INTENSITY16I_EXT
:
383 case GL_INTENSITY32I_EXT
:
385 case GL_LUMINANCE8UI_EXT
:
386 case GL_LUMINANCE16UI_EXT
:
387 case GL_LUMINANCE32UI_EXT
:
388 case GL_LUMINANCE8I_EXT
:
389 case GL_LUMINANCE16I_EXT
:
390 case GL_LUMINANCE32I_EXT
:
392 case GL_LUMINANCE_ALPHA8UI_EXT
:
393 case GL_LUMINANCE_ALPHA16UI_EXT
:
394 case GL_LUMINANCE_ALPHA32UI_EXT
:
395 case GL_LUMINANCE_ALPHA8I_EXT
:
396 case GL_LUMINANCE_ALPHA16I_EXT
:
397 case GL_LUMINANCE_ALPHA32I_EXT
:
398 return GL_LUMINANCE_ALPHA
;
404 if (ctx
->Extensions
.ARB_texture_rg
) {
405 switch (internalFormat
) {
407 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
409 if (!ctx
->Extensions
.ARB_half_float_pixel
)
413 if (!ctx
->Extensions
.ARB_texture_float
)
422 if (!ctx
->Extensions
.EXT_texture_integer
)
428 case GL_COMPRESSED_RED
:
432 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
434 if (!ctx
->Extensions
.ARB_half_float_pixel
)
438 if (!ctx
->Extensions
.ARB_texture_float
)
447 if (!ctx
->Extensions
.EXT_texture_integer
)
453 case GL_COMPRESSED_RG
:
460 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
461 switch (internalFormat
) {
469 if (ctx
->Extensions
.EXT_packed_float
) {
470 switch (internalFormat
) {
471 case GL_R11F_G11F_B10F_EXT
:
478 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
479 switch (internalFormat
) {
480 case GL_DEPTH_COMPONENT32F
:
481 return GL_DEPTH_COMPONENT
;
482 case GL_DEPTH32F_STENCIL8
:
483 return GL_DEPTH_STENCIL
;
489 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
490 switch (internalFormat
) {
491 case GL_COMPRESSED_RED_RGTC1
:
492 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
494 case GL_COMPRESSED_RG_RGTC2
:
495 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
502 return -1; /* error */
507 * For cube map faces, return a face index in [0,5].
508 * For other targets return 0;
511 _mesa_tex_target_to_face(GLenum target
)
513 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
514 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
515 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
523 * Store a gl_texture_image pointer in a gl_texture_object structure
524 * according to the target and level parameters.
526 * \param tObj texture object.
527 * \param target texture target.
528 * \param level image level.
529 * \param texImage texture image.
531 * This was basically prompted by the introduction of cube maps.
534 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
535 GLenum target
, GLint level
,
536 struct gl_texture_image
*texImage
)
538 const GLuint face
= _mesa_tex_target_to_face(target
);
542 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
544 tObj
->Image
[face
][level
] = texImage
;
546 /* Set the 'back' pointer */
547 texImage
->TexObject
= tObj
;
552 * Allocate a texture image structure.
554 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
557 * \return a pointer to gl_texture_image struct with all fields initialized to
560 struct gl_texture_image
*
561 _mesa_new_texture_image( struct gl_context
*ctx
)
564 return CALLOC_STRUCT(gl_texture_image
);
569 * Free texture image data.
570 * This function is a fallback called via ctx->Driver.FreeTexImageData().
572 * \param texImage texture image.
574 * Free the texture image data if it's not marked as client data.
577 _mesa_free_texture_image_data(struct gl_context
*ctx
,
578 struct gl_texture_image
*texImage
)
582 if (texImage
->Data
&& !texImage
->IsClientData
) {
583 /* free the old texture data */
584 _mesa_free_texmemory(texImage
->Data
);
587 texImage
->Data
= NULL
;
592 * Free texture image.
594 * \param texImage texture image.
596 * Free the texture image structure and the associated image data.
599 _mesa_delete_texture_image(struct gl_context
*ctx
,
600 struct gl_texture_image
*texImage
)
602 /* Free texImage->Data and/or any other driver-specific texture
605 ASSERT(ctx
->Driver
.FreeTexImageData
);
606 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
608 ASSERT(texImage
->Data
== NULL
);
609 if (texImage
->ImageOffsets
)
610 free(texImage
->ImageOffsets
);
616 * Test if a target is a proxy target.
618 * \param target texture target.
620 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
623 _mesa_is_proxy_texture(GLenum target
)
625 /* NUM_TEXTURE_TARGETS should match number of terms below */
626 assert(NUM_TEXTURE_TARGETS
== 7);
628 return (target
== GL_PROXY_TEXTURE_1D
||
629 target
== GL_PROXY_TEXTURE_2D
||
630 target
== GL_PROXY_TEXTURE_3D
||
631 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
632 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
633 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
634 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
639 * Return the proxy target which corresponds to the given texture target
642 get_proxy_target(GLenum target
)
646 case GL_PROXY_TEXTURE_1D
:
647 return GL_PROXY_TEXTURE_1D
;
649 case GL_PROXY_TEXTURE_2D
:
650 return GL_PROXY_TEXTURE_2D
;
652 case GL_PROXY_TEXTURE_3D
:
653 return GL_PROXY_TEXTURE_3D
;
654 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
655 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
656 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
657 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
658 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
659 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
660 case GL_TEXTURE_CUBE_MAP_ARB
:
661 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
662 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
663 case GL_TEXTURE_RECTANGLE_NV
:
664 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
665 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
666 case GL_TEXTURE_1D_ARRAY_EXT
:
667 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
668 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
669 case GL_TEXTURE_2D_ARRAY_EXT
:
670 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
671 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
673 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
680 * Get the texture object that corresponds to the target of the given
683 * \param ctx GL context.
684 * \param texUnit texture unit.
685 * \param target texture target.
687 * \return pointer to the texture object on success, or NULL on failure.
689 * \sa gl_texture_unit.
691 struct gl_texture_object
*
692 _mesa_select_tex_object(struct gl_context
*ctx
,
693 const struct gl_texture_unit
*texUnit
,
698 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
699 case GL_PROXY_TEXTURE_1D
:
700 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
702 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
703 case GL_PROXY_TEXTURE_2D
:
704 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
706 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
707 case GL_PROXY_TEXTURE_3D
:
708 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
709 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
710 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
711 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
712 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
713 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
714 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
715 case GL_TEXTURE_CUBE_MAP_ARB
:
716 return ctx
->Extensions
.ARB_texture_cube_map
717 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
718 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
719 return ctx
->Extensions
.ARB_texture_cube_map
720 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
721 case GL_TEXTURE_RECTANGLE_NV
:
722 return ctx
->Extensions
.NV_texture_rectangle
723 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
724 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
725 return ctx
->Extensions
.NV_texture_rectangle
726 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
727 case GL_TEXTURE_1D_ARRAY_EXT
:
728 return ctx
->Extensions
.MESA_texture_array
729 ? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
730 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
731 return ctx
->Extensions
.MESA_texture_array
732 ? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
733 case GL_TEXTURE_2D_ARRAY_EXT
:
734 return ctx
->Extensions
.MESA_texture_array
735 ? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
736 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
737 return ctx
->Extensions
.MESA_texture_array
738 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
740 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
747 * Return pointer to texture object for given target on current texture unit.
749 struct gl_texture_object
*
750 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
752 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
753 return _mesa_select_tex_object(ctx
, texUnit
, target
);
758 * Get a texture image pointer from a texture object, given a texture
759 * target and mipmap level. The target and level parameters should
760 * have already been error-checked.
762 * \param ctx GL context.
763 * \param texObj texture unit.
764 * \param target texture target.
765 * \param level image level.
767 * \return pointer to the texture image structure, or NULL on failure.
769 struct gl_texture_image
*
770 _mesa_select_tex_image(struct gl_context
*ctx
,
771 const struct gl_texture_object
*texObj
,
772 GLenum target
, GLint level
)
774 const GLuint face
= _mesa_tex_target_to_face(target
);
778 ASSERT(level
< MAX_TEXTURE_LEVELS
);
780 return texObj
->Image
[face
][level
];
785 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
786 * it and install it. Only return NULL if passed a bad parameter or run
789 struct gl_texture_image
*
790 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
791 GLenum target
, GLint level
)
793 struct gl_texture_image
*texImage
;
798 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
800 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
802 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
806 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
814 * Return pointer to the specified proxy texture image.
815 * Note that proxy textures are per-context, not per-texture unit.
816 * \return pointer to texture image or NULL if invalid target, invalid
817 * level, or out of memory.
819 struct gl_texture_image
*
820 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
822 struct gl_texture_image
*texImage
;
829 case GL_PROXY_TEXTURE_1D
:
830 if (level
>= ctx
->Const
.MaxTextureLevels
)
832 texIndex
= TEXTURE_1D_INDEX
;
834 case GL_PROXY_TEXTURE_2D
:
835 if (level
>= ctx
->Const
.MaxTextureLevels
)
837 texIndex
= TEXTURE_2D_INDEX
;
839 case GL_PROXY_TEXTURE_3D
:
840 if (level
>= ctx
->Const
.Max3DTextureLevels
)
842 texIndex
= TEXTURE_3D_INDEX
;
844 case GL_PROXY_TEXTURE_CUBE_MAP
:
845 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
847 texIndex
= TEXTURE_CUBE_INDEX
;
849 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
852 texIndex
= TEXTURE_RECT_INDEX
;
854 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
855 if (level
>= ctx
->Const
.MaxTextureLevels
)
857 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
859 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
860 if (level
>= ctx
->Const
.MaxTextureLevels
)
862 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
868 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
870 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
872 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
875 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
876 /* Set the 'back' pointer */
877 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
884 * Get the maximum number of allowed mipmap levels.
886 * \param ctx GL context.
887 * \param target texture target.
889 * \return the maximum number of allowed mipmap levels for the given
890 * texture target, or zero if passed a bad target.
895 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
899 case GL_PROXY_TEXTURE_1D
:
901 case GL_PROXY_TEXTURE_2D
:
902 return ctx
->Const
.MaxTextureLevels
;
904 case GL_PROXY_TEXTURE_3D
:
905 return ctx
->Const
.Max3DTextureLevels
;
906 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
907 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
908 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
909 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
910 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
911 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
912 case GL_TEXTURE_CUBE_MAP_ARB
:
913 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
914 return ctx
->Extensions
.ARB_texture_cube_map
915 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
916 case GL_TEXTURE_RECTANGLE_NV
:
917 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
918 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
919 case GL_TEXTURE_1D_ARRAY_EXT
:
920 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
921 case GL_TEXTURE_2D_ARRAY_EXT
:
922 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
923 return ctx
->Extensions
.MESA_texture_array
924 ? ctx
->Const
.MaxTextureLevels
: 0;
926 return 0; /* bad target */
932 * Return number of dimensions per mipmap level for the given texture target.
935 get_texture_dimensions(GLenum target
)
939 case GL_PROXY_TEXTURE_1D
:
942 case GL_TEXTURE_RECTANGLE
:
943 case GL_TEXTURE_CUBE_MAP
:
944 case GL_PROXY_TEXTURE_2D
:
945 case GL_PROXY_TEXTURE_RECTANGLE
:
946 case GL_PROXY_TEXTURE_CUBE_MAP
:
947 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
948 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
949 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
950 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
951 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
952 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
953 case GL_TEXTURE_1D_ARRAY
:
954 case GL_PROXY_TEXTURE_1D_ARRAY
:
957 case GL_PROXY_TEXTURE_3D
:
958 case GL_TEXTURE_2D_ARRAY
:
959 case GL_PROXY_TEXTURE_2D_ARRAY
:
962 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
971 #if 000 /* not used anymore */
973 * glTexImage[123]D can accept a NULL image pointer. In this case we
974 * create a texture image with unspecified image contents per the OpenGL
978 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
980 const GLint components
= _mesa_components_in_format(format
);
981 const GLint numPixels
= width
* height
* depth
;
982 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
986 * Let's see if anyone finds this. If glTexImage2D() is called with
987 * a NULL image pointer then load the texture image with something
988 * interesting instead of leaving it indeterminate.
991 static const char message
[8][32] = {
995 " X X XXXX XXX XXXXX ",
998 " X X XXXXX XXX X X ",
1002 GLubyte
*imgPtr
= data
;
1004 for (h
= 0; h
< depth
; h
++) {
1005 for (i
= 0; i
< height
; i
++) {
1006 GLint srcRow
= 7 - (i
% 8);
1007 for (j
= 0; j
< width
; j
++) {
1008 GLint srcCol
= j
% 32;
1009 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1010 for (k
= 0; k
< components
; k
++) {
1026 * Reset the fields of a gl_texture_image struct to zero.
1028 * \param img texture image structure.
1030 * This is called when a proxy texture test fails, we set all the
1031 * image members (except DriverData) to zero.
1032 * It's also used in glTexImage[123]D as a safeguard to be sure all
1033 * required fields get initialized properly by the Driver.TexImage[123]D
1037 clear_teximage_fields(struct gl_texture_image
*img
)
1040 img
->_BaseFormat
= 0;
1041 img
->InternalFormat
= 0;
1047 if (img
->ImageOffsets
) {
1048 free(img
->ImageOffsets
);
1049 img
->ImageOffsets
= NULL
;
1055 img
->HeightLog2
= 0;
1058 img
->TexFormat
= MESA_FORMAT_NONE
;
1059 img
->FetchTexelc
= NULL
;
1060 img
->FetchTexelf
= NULL
;
1065 * Initialize basic fields of the gl_texture_image struct.
1067 * \param ctx GL context.
1068 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1069 * \param img texture image structure to be initialized.
1070 * \param width image width.
1071 * \param height image height.
1072 * \param depth image depth.
1073 * \param border image border.
1074 * \param internalFormat internal format.
1075 * \param format the actual hardware format (one of MESA_FORMAT_*)
1077 * Fills in the fields of \p img with the given information.
1078 * Note: width, height and depth include the border.
1081 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1082 struct gl_texture_image
*img
,
1083 GLsizei width
, GLsizei height
, GLsizei depth
,
1084 GLint border
, GLenum internalFormat
,
1091 ASSERT(height
>= 0);
1094 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1095 ASSERT(img
->_BaseFormat
> 0);
1096 img
->InternalFormat
= internalFormat
;
1097 img
->Border
= border
;
1099 img
->Height
= height
;
1102 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1103 img
->WidthLog2
= logbase2(img
->Width2
);
1105 if (height
== 1) { /* 1-D texture */
1107 img
->HeightLog2
= 0;
1110 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1111 img
->HeightLog2
= logbase2(img
->Height2
);
1114 if (depth
== 1) { /* 2-D texture */
1119 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1120 img
->DepthLog2
= logbase2(img
->Depth2
);
1123 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1125 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1126 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1127 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1128 img
->_IsPowerOfTwo
= GL_TRUE
;
1130 img
->_IsPowerOfTwo
= GL_FALSE
;
1132 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1133 img
->RowStride
= width
;
1134 /* Allocate the ImageOffsets array and initialize to typical values.
1135 * We allocate the array for 1D/2D textures too in order to avoid special-
1136 * case code in the texstore routines.
1138 if (img
->ImageOffsets
)
1139 free(img
->ImageOffsets
);
1140 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1141 for (i
= 0; i
< depth
; i
++) {
1142 img
->ImageOffsets
[i
] = i
* width
* height
;
1145 /* Compute Width/Height/DepthScale for mipmap lod computation */
1146 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1147 /* scale = 1.0 since texture coords directly map to texels */
1148 img
->WidthScale
= 1.0;
1149 img
->HeightScale
= 1.0;
1150 img
->DepthScale
= 1.0;
1153 img
->WidthScale
= (GLfloat
) img
->Width
;
1154 img
->HeightScale
= (GLfloat
) img
->Height
;
1155 img
->DepthScale
= (GLfloat
) img
->Depth
;
1158 img
->TexFormat
= format
;
1160 dims
= get_texture_dimensions(target
);
1162 _mesa_set_fetch_functions(img
, dims
);
1167 * Free and clear fields of the gl_texture_image struct.
1169 * \param ctx GL context.
1170 * \param texImage texture image structure to be cleared.
1172 * After the call, \p texImage will have no data associated with it. Its
1173 * fields are cleared so that its parent object will test incomplete.
1176 _mesa_clear_texture_image(struct gl_context
*ctx
,
1177 struct gl_texture_image
*texImage
)
1179 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1180 clear_teximage_fields(texImage
);
1185 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1186 * level, width, height and depth against the ctx->Const limits for textures.
1188 * A hardware driver might override this function if, for example, the
1189 * max 3D texture size is 512x512x64 (i.e. not a cube).
1191 * Note that width, height, depth == 0 is not an error. However, a
1192 * texture with zero width/height/depth will be considered "incomplete"
1193 * and texturing will effectively be disabled.
1195 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1196 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1197 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1198 * \param level as passed to glTexImage
1199 * \param internalFormat as passed to glTexImage
1200 * \param format as passed to glTexImage
1201 * \param type as passed to glTexImage
1202 * \param width as passed to glTexImage
1203 * \param height as passed to glTexImage
1204 * \param depth as passed to glTexImage
1205 * \param border as passed to glTexImage
1206 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1209 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1210 GLint internalFormat
, GLenum format
, GLenum type
,
1211 GLint width
, GLint height
, GLint depth
, GLint border
)
1215 (void) internalFormat
;
1220 case GL_PROXY_TEXTURE_1D
:
1221 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1222 if (width
< 2 * border
|| width
> 2 + maxSize
||
1223 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1224 width
>0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1225 level
>= ctx
->Const
.MaxTextureLevels
) {
1226 /* bad width or level */
1230 case GL_PROXY_TEXTURE_2D
:
1231 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1232 if (width
< 2 * border
|| width
> 2 + maxSize
||
1233 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1234 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1235 height
< 2 * border
|| height
> 2 + maxSize
||
1236 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1237 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1238 level
>= ctx
->Const
.MaxTextureLevels
) {
1239 /* bad width or height or level */
1243 case GL_PROXY_TEXTURE_3D
:
1244 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1245 if (width
< 2 * border
|| width
> 2 + maxSize
||
1246 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1247 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1248 height
< 2 * border
|| height
> 2 + maxSize
||
1249 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1250 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1251 depth
< 2 * border
|| depth
> 2 + maxSize
||
1252 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1253 depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
)) ||
1254 level
>= ctx
->Const
.Max3DTextureLevels
) {
1255 /* bad width or height or depth or level */
1259 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1260 if (width
< 0 || width
> ctx
->Const
.MaxTextureRectSize
||
1261 height
< 0 || height
> ctx
->Const
.MaxTextureRectSize
||
1263 /* bad width or height or level */
1267 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1268 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1269 if (width
< 2 * border
|| width
> 2 + maxSize
||
1270 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1271 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1272 height
< 2 * border
|| height
> 2 + maxSize
||
1273 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1274 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1275 level
>= ctx
->Const
.MaxCubeTextureLevels
) {
1276 /* bad width or height */
1280 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1281 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1282 if (width
< 2 * border
|| width
> 2 + maxSize
||
1283 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1284 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1285 level
>= ctx
->Const
.MaxTextureLevels
) {
1286 /* bad width or level */
1290 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
) {
1294 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1295 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1296 if (width
< 2 * border
|| width
> 2 + maxSize
||
1297 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1298 width
> 0 && !_mesa_is_pow_two(width
- 2 * border
)) ||
1299 height
< 2 * border
|| height
> 2 + maxSize
||
1300 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&&
1301 height
> 0 && !_mesa_is_pow_two(height
- 2 * border
)) ||
1302 level
>= ctx
->Const
.MaxTextureLevels
) {
1303 /* bad width or height or level */
1306 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
) {
1311 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1318 * Check if the memory used by the texture would exceed the driver's limit.
1319 * This lets us support a max 3D texture size of 8K (for example) but
1320 * prevents allocating a full 8K x 8K x 8K texture.
1321 * XXX this could be rolled into the proxy texture size test (above) but
1322 * we don't have the actual texture internal format at that point.
1325 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1326 GLint width
, GLint height
, GLint depth
)
1328 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1329 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1330 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1336 * Helper function to determine whether a target supports compressed textures
1339 target_can_be_compressed(struct gl_context
*ctx
, GLenum target
)
1343 case GL_PROXY_TEXTURE_2D
:
1345 case GL_PROXY_TEXTURE_CUBE_MAP
:
1346 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1347 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1348 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1349 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1350 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1351 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1352 return ctx
->Extensions
.ARB_texture_cube_map
;
1353 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1354 case GL_TEXTURE_2D_ARRAY_EXT
:
1355 return ctx
->Extensions
.MESA_texture_array
;
1363 * Check if the given texture target value is legal for a
1364 * glTexImage1/2/3D call.
1367 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1373 case GL_PROXY_TEXTURE_1D
:
1381 case GL_PROXY_TEXTURE_2D
:
1383 case GL_PROXY_TEXTURE_CUBE_MAP
:
1384 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1385 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1386 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1387 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1388 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1389 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1390 return ctx
->Extensions
.ARB_texture_cube_map
;
1391 case GL_TEXTURE_RECTANGLE_NV
:
1392 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1393 return ctx
->Extensions
.NV_texture_rectangle
;
1394 case GL_TEXTURE_1D_ARRAY_EXT
:
1395 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1396 return ctx
->Extensions
.MESA_texture_array
;
1403 case GL_PROXY_TEXTURE_3D
:
1405 case GL_TEXTURE_2D_ARRAY_EXT
:
1406 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1407 return ctx
->Extensions
.MESA_texture_array
;
1412 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1419 * Check if the given texture target value is legal for a
1420 * glCopyTexImage1/2D call.
1423 legal_copyteximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1427 return target
== GL_TEXTURE_1D
;
1432 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1433 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1434 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1435 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1436 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1437 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1438 return ctx
->Extensions
.ARB_texture_cube_map
;
1439 case GL_TEXTURE_RECTANGLE_NV
:
1440 return ctx
->Extensions
.NV_texture_rectangle
;
1441 case GL_TEXTURE_1D_ARRAY_EXT
:
1442 return ctx
->Extensions
.MESA_texture_array
;
1447 _mesa_problem(ctx
, "invalid dims=%u in legal_copyteximage_target()", dims
);
1454 * Test the glTexImage[123]D() parameters for errors.
1456 * \param ctx GL context.
1457 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1458 * \param target texture target given by the user.
1459 * \param level image level given by the user.
1460 * \param internalFormat internal format given by the user.
1461 * \param format pixel data format given by the user.
1462 * \param type pixel data type given by the user.
1463 * \param width image width given by the user.
1464 * \param height image height given by the user.
1465 * \param depth image depth given by the user.
1466 * \param border image border given by the user.
1468 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1470 * Verifies each of the parameters against the constants specified in
1471 * __struct gl_contextRec::Const and the supported extensions, and according
1472 * to the OpenGL specification.
1475 texture_error_check( struct gl_context
*ctx
,
1476 GLuint dimensions
, GLenum target
,
1477 GLint level
, GLint internalFormat
,
1478 GLenum format
, GLenum type
,
1479 GLint width
, GLint height
,
1480 GLint depth
, GLint border
)
1482 const GLenum proxyTarget
= get_proxy_target(target
);
1483 const GLboolean isProxy
= target
== proxyTarget
;
1484 GLboolean sizeOK
= GL_TRUE
;
1485 GLboolean colorFormat
, indexFormat
;
1487 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1488 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1490 _mesa_error(ctx
, GL_INVALID_VALUE
,
1491 "glTexImage%dD(level=%d)", dimensions
, level
);
1497 if (border
< 0 || border
> 1 ||
1498 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1499 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1501 _mesa_error(ctx
, GL_INVALID_VALUE
,
1502 "glTexImage%dD(border=%d)", dimensions
, border
);
1507 if (width
< 0 || height
< 0 || depth
< 0) {
1509 _mesa_error(ctx
, GL_INVALID_VALUE
,
1510 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1515 /* Do this simple check before calling the TestProxyTexImage() function */
1516 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1517 sizeOK
= (width
== height
);
1521 * Use the proxy texture driver hook to see if the size/level/etc are
1524 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1525 internalFormat
, format
,
1526 type
, width
, height
,
1530 _mesa_error(ctx
, GL_INVALID_VALUE
,
1531 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1532 dimensions
, level
, width
, height
, depth
);
1537 /* Check internalFormat */
1538 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1540 _mesa_error(ctx
, GL_INVALID_VALUE
,
1541 "glTexImage%dD(internalFormat=%s)",
1542 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1547 /* Check incoming image format and type */
1548 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1549 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1550 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1551 * GL_EXT_texture_integer extension, some combinations should generate
1552 * GL_INVALID_ENUM instead (grr!).
1555 GLenum error
= _mesa_is_integer_format(format
)
1556 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1557 _mesa_error(ctx
, error
,
1558 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1559 dimensions
, format
, type
);
1564 /* make sure internal format and format basically agree */
1565 colorFormat
= _mesa_is_color_format(format
);
1566 indexFormat
= _mesa_is_index_format(format
);
1567 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1568 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1569 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1570 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1571 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1572 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1574 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1575 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1576 dimensions
, internalFormat
, format
);
1580 /* additional checks for ycbcr textures */
1581 if (internalFormat
== GL_YCBCR_MESA
) {
1582 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1583 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1584 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1586 _mesa_snprintf(message
, sizeof(message
),
1587 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1588 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1589 return GL_TRUE
; /* error */
1591 if (target
!= GL_TEXTURE_2D
&&
1592 target
!= GL_PROXY_TEXTURE_2D
&&
1593 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1594 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1596 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1602 _mesa_snprintf(message
, sizeof(message
),
1603 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1604 dimensions
, border
);
1605 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1611 /* additional checks for depth textures */
1612 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1613 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1614 if (target
!= GL_TEXTURE_1D
&&
1615 target
!= GL_PROXY_TEXTURE_1D
&&
1616 target
!= GL_TEXTURE_2D
&&
1617 target
!= GL_PROXY_TEXTURE_2D
&&
1618 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1619 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1621 _mesa_error(ctx
, GL_INVALID_ENUM
,
1622 "glTexImage(target/internalFormat)");
1627 /* additional checks for compressed textures */
1628 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1629 if (!target_can_be_compressed(ctx
, target
) && !isProxy
) {
1630 _mesa_error(ctx
, GL_INVALID_ENUM
,
1631 "glTexImage%dD(target)", dimensions
);
1636 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1637 "glTexImage%dD(border!=0)", dimensions
);
1643 /* additional checks for integer textures */
1644 if (ctx
->Extensions
.EXT_texture_integer
&&
1645 (_mesa_is_integer_format(format
) !=
1646 _mesa_is_integer_format(internalFormat
))) {
1648 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1649 "glTexImage%dD(integer/non-integer format mismatch)",
1655 /* if we get here, the parameters are OK */
1661 * Test glTexSubImage[123]D() parameters for errors.
1663 * \param ctx GL context.
1664 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1665 * \param target texture target given by the user.
1666 * \param level image level given by the user.
1667 * \param xoffset sub-image x offset given by the user.
1668 * \param yoffset sub-image y offset given by the user.
1669 * \param zoffset sub-image z offset given by the user.
1670 * \param format pixel data format given by the user.
1671 * \param type pixel data type given by the user.
1672 * \param width image width given by the user.
1673 * \param height image height given by the user.
1674 * \param depth image depth given by the user.
1676 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1678 * Verifies each of the parameters against the constants specified in
1679 * __struct gl_contextRec::Const and the supported extensions, and according
1680 * to the OpenGL specification.
1683 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1684 GLenum target
, GLint level
,
1685 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1686 GLint width
, GLint height
, GLint depth
,
1687 GLenum format
, GLenum type
)
1689 /* Basic level check */
1690 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1691 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1695 /* Check for negative sizes */
1697 _mesa_error(ctx
, GL_INVALID_VALUE
,
1698 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1701 if (height
< 0 && dimensions
> 1) {
1702 _mesa_error(ctx
, GL_INVALID_VALUE
,
1703 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1706 if (depth
< 0 && dimensions
> 2) {
1707 _mesa_error(ctx
, GL_INVALID_VALUE
,
1708 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1712 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1713 /* As with the glTexImage2D check above, the error code here
1714 * depends on texture integer.
1716 GLenum error
= _mesa_is_integer_format(format
)
1717 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1718 _mesa_error(ctx
, error
,
1719 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1720 dimensions
, format
, type
);
1729 * Do second part of glTexSubImage which depends on the destination texture.
1730 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1733 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1734 GLenum target
, GLint level
,
1735 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1736 GLint width
, GLint height
, GLint depth
,
1737 GLenum format
, GLenum type
,
1738 const struct gl_texture_image
*destTex
)
1741 /* undefined image level */
1742 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1746 if (xoffset
< -((GLint
)destTex
->Border
)) {
1747 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1751 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1752 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1756 if (dimensions
> 1) {
1757 if (yoffset
< -((GLint
)destTex
->Border
)) {
1758 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1762 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1763 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1768 if (dimensions
> 2) {
1769 if (zoffset
< -((GLint
)destTex
->Border
)) {
1770 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1773 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1774 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1779 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1782 if (!target_can_be_compressed(ctx
, target
)) {
1783 _mesa_error(ctx
, GL_INVALID_ENUM
,
1784 "glTexSubImage%dD(target=%s)", dimensions
,
1785 _mesa_lookup_enum_by_nr(target
));
1789 /* do tests which depend on compression block size */
1790 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1792 /* offset must be multiple of block size */
1793 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1794 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1795 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1796 dimensions
, xoffset
, yoffset
);
1799 /* size must be multiple of bw by bh or equal to whole texture size */
1800 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1801 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1802 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1805 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1806 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1807 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1817 * Test glCopyTexImage[12]D() parameters for errors.
1819 * \param ctx GL context.
1820 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1821 * \param target texture target given by the user.
1822 * \param level image level given by the user.
1823 * \param internalFormat internal format given by the user.
1824 * \param width image width given by the user.
1825 * \param height image height given by the user.
1826 * \param border texture border.
1828 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1830 * Verifies each of the parameters against the constants specified in
1831 * __struct gl_contextRec::Const and the supported extensions, and according
1832 * to the OpenGL specification.
1835 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1836 GLenum target
, GLint level
, GLint internalFormat
,
1837 GLint width
, GLint height
, GLint border
)
1839 const GLenum proxyTarget
= get_proxy_target(target
);
1840 const GLenum type
= GL_FLOAT
;
1845 if (!legal_copyteximage_target(ctx
, dimensions
, target
)) {
1846 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1847 dimensions
, _mesa_lookup_enum_by_nr(target
));
1851 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1852 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1853 _mesa_error(ctx
, GL_INVALID_VALUE
,
1854 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1858 /* Check that the source buffer is complete */
1859 if (ctx
->ReadBuffer
->Name
) {
1860 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1861 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1862 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1863 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1869 if (border
< 0 || border
> 1 ||
1870 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1871 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1875 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1877 _mesa_error(ctx
, GL_INVALID_VALUE
,
1878 "glCopyTexImage%dD(internalFormat)", dimensions
);
1882 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1883 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1884 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1888 /* Do size, level checking */
1889 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1890 ? (width
== height
) : 1;
1892 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1893 internalFormat
, format
,
1894 type
, width
, height
,
1898 if (dimensions
== 1) {
1899 _mesa_error(ctx
, GL_INVALID_VALUE
,
1900 "glCopyTexImage1D(width=%d)", width
);
1903 ASSERT(dimensions
== 2);
1904 _mesa_error(ctx
, GL_INVALID_VALUE
,
1905 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1910 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1911 if (!target_can_be_compressed(ctx
, target
)) {
1912 _mesa_error(ctx
, GL_INVALID_ENUM
,
1913 "glCopyTexImage%dD(target)", dimensions
);
1917 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1918 "glCopyTexImage%dD(border!=0)", dimensions
);
1922 else if (_mesa_is_depth_format(internalFormat
)) {
1923 /* make sure we have depth/stencil buffers */
1924 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1925 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1926 "glCopyTexImage%dD(no depth)", dimensions
);
1930 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1931 /* make sure we have depth/stencil buffers */
1932 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1933 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1934 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
1939 /* if we get here, the parameters are OK */
1945 * Test glCopyTexSubImage[12]D() parameters for errors.
1946 * Note that this is the first part of error checking.
1947 * See also copytexsubimage_error_check2() below for the second part.
1949 * \param ctx GL context.
1950 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1951 * \param target texture target given by the user.
1952 * \param level image level given by the user.
1954 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1957 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
1958 GLenum target
, GLint level
)
1960 /* Check that the source buffer is complete */
1961 if (ctx
->ReadBuffer
->Name
) {
1962 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1963 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1964 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1965 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1971 if (dimensions
== 1) {
1972 if (target
!= GL_TEXTURE_1D
) {
1973 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage1D(target)" );
1977 else if (dimensions
== 2) {
1978 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
1979 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
1980 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1981 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1985 else if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1986 if (!ctx
->Extensions
.NV_texture_rectangle
) {
1987 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1991 else if (target
== GL_TEXTURE_1D_ARRAY_EXT
) {
1992 if (!ctx
->Extensions
.MESA_texture_array
) {
1993 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
1997 else if (target
!= GL_TEXTURE_2D
) {
1998 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage2D(target)" );
2002 else if (dimensions
== 3) {
2003 if (((target
!= GL_TEXTURE_2D_ARRAY_EXT
) ||
2004 (!ctx
->Extensions
.MESA_texture_array
))
2005 && (target
!= GL_TEXTURE_3D
)) {
2006 _mesa_error( ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage3D(target)" );
2012 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2013 _mesa_error(ctx
, GL_INVALID_VALUE
,
2014 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2023 * Second part of error checking for glCopyTexSubImage[12]D().
2024 * \param xoffset sub-image x offset given by the user.
2025 * \param yoffset sub-image y offset given by the user.
2026 * \param zoffset sub-image z offset given by the user.
2027 * \param width image width given by the user.
2028 * \param height image height given by the user.
2031 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2032 GLenum target
, GLint level
,
2033 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2034 GLsizei width
, GLsizei height
,
2035 const struct gl_texture_image
*teximage
)
2037 /* check that dest tex image exists */
2039 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2040 "glCopyTexSubImage%dD(undefined texture level: %d)",
2047 _mesa_error(ctx
, GL_INVALID_VALUE
,
2048 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2051 if (dimensions
> 1 && height
< 0) {
2052 _mesa_error(ctx
, GL_INVALID_VALUE
,
2053 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2057 /* check x/y offsets */
2058 if (xoffset
< -((GLint
)teximage
->Border
)) {
2059 _mesa_error(ctx
, GL_INVALID_VALUE
,
2060 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2063 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2064 _mesa_error(ctx
, GL_INVALID_VALUE
,
2065 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2068 if (dimensions
> 1) {
2069 if (yoffset
< -((GLint
)teximage
->Border
)) {
2070 _mesa_error(ctx
, GL_INVALID_VALUE
,
2071 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2074 /* NOTE: we're adding the border here, not subtracting! */
2075 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2076 _mesa_error(ctx
, GL_INVALID_VALUE
,
2077 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2082 /* check z offset */
2083 if (dimensions
> 2) {
2084 if (zoffset
< -((GLint
)teximage
->Border
)) {
2085 _mesa_error(ctx
, GL_INVALID_VALUE
,
2086 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2089 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2090 _mesa_error(ctx
, GL_INVALID_VALUE
,
2091 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2096 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2097 if (!target_can_be_compressed(ctx
, target
)) {
2098 _mesa_error(ctx
, GL_INVALID_ENUM
,
2099 "glCopyTexSubImage%dD(target)", dimensions
);
2102 /* offset must be multiple of 4 */
2103 if ((xoffset
& 3) || (yoffset
& 3)) {
2104 _mesa_error(ctx
, GL_INVALID_VALUE
,
2105 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2108 /* size must be multiple of 4 */
2109 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2110 _mesa_error(ctx
, GL_INVALID_VALUE
,
2111 "glCopyTexSubImage%dD(width)", dimensions
);
2114 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2115 _mesa_error(ctx
, GL_INVALID_VALUE
,
2116 "glCopyTexSubImage%dD(height)", dimensions
);
2121 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2122 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2126 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2127 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2128 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2129 dimensions
, teximage
->_BaseFormat
);
2133 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2134 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2135 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2136 "glCopyTexSubImage%dD(no depth buffer)",
2141 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2142 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2143 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2144 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2150 /* If copying into an integer texture, the source buffer must also be
2153 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2154 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2155 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2156 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2157 "glCopyTexSubImage%dD(source buffer is not integer format)",
2163 /* if we get here, the parameters are OK */
2168 /** Callback info for walking over FBO hash table */
2171 struct gl_context
*ctx
;
2172 struct gl_texture_object
*texObj
;
2178 * Check render to texture callback. Called from _mesa_HashWalk().
2181 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2183 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2184 const struct cb_info
*info
= (struct cb_info
*) userData
;
2185 struct gl_context
*ctx
= info
->ctx
;
2186 const struct gl_texture_object
*texObj
= info
->texObj
;
2187 const GLuint level
= info
->level
, face
= info
->face
;
2189 /* If this is a user-created FBO */
2192 /* check if any of the FBO's attachments point to 'texObj' */
2193 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2194 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2195 if (att
->Type
== GL_TEXTURE
&&
2196 att
->Texture
== texObj
&&
2197 att
->TextureLevel
== level
&&
2198 att
->CubeMapFace
== face
) {
2199 ASSERT(att
->Texture
->Image
[att
->CubeMapFace
][att
->TextureLevel
]);
2200 /* Tell driver about the new renderbuffer texture */
2201 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2202 /* Mark fb status as indeterminate to force re-validation */
2211 * When a texture image is specified we have to check if it's bound to
2212 * any framebuffer objects (render to texture) in order to detect changes
2213 * in size or format since that effects FBO completeness.
2214 * Any FBOs rendering into the texture must be re-validated.
2217 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2218 GLuint face
, GLuint level
)
2220 /* Only check this texture if it's been marked as RenderToTexture */
2221 if (texObj
->_RenderToTexture
) {
2222 struct cb_info info
;
2224 info
.texObj
= texObj
;
2227 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2233 * If the texture object's GenerateMipmap flag is set and we've
2234 * changed the texture base level image, regenerate the rest of the
2235 * mipmap levels now.
2238 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2239 struct gl_texture_object
*texObj
, GLint level
)
2241 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2242 if (texObj
->GenerateMipmap
&&
2243 level
== texObj
->BaseLevel
&&
2244 level
< texObj
->MaxLevel
) {
2245 ASSERT(ctx
->Driver
.GenerateMipmap
);
2246 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2251 /** Debug helper: override the user-requested internal format */
2253 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2256 if (internalFormat
== GL_RGBA16F_ARB
||
2257 internalFormat
== GL_RGBA32F_ARB
) {
2258 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2261 else if (internalFormat
== GL_RGB16F_ARB
||
2262 internalFormat
== GL_RGB32F_ARB
) {
2263 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2266 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2267 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2268 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2269 return GL_LUMINANCE_ALPHA
;
2271 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2272 internalFormat
== GL_LUMINANCE32F_ARB
) {
2273 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2274 return GL_LUMINANCE
;
2276 else if (internalFormat
== GL_ALPHA16F_ARB
||
2277 internalFormat
== GL_ALPHA32F_ARB
) {
2278 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2282 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2283 internalFormat = GL_RGBA;
2287 return internalFormat
;
2290 return internalFormat
;
2296 * Choose the actual hardware format for a texture image.
2297 * Try to use the same format as the previous image level when possible.
2298 * Otherwise, ask the driver for the best format.
2299 * It's important to try to choose a consistant format for all levels
2300 * for efficient texture memory layout/allocation. In particular, this
2301 * comes up during automatic mipmap generation.
2304 _mesa_choose_texture_format(struct gl_context
*ctx
,
2305 struct gl_texture_object
*texObj
,
2306 GLenum target
, GLint level
,
2307 GLenum internalFormat
, GLenum format
, GLenum type
)
2311 /* see if we've already chosen a format for the previous level */
2313 struct gl_texture_image
*prevImage
=
2314 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2315 /* See if the prev level is defined and has an internal format which
2316 * matches the new internal format.
2319 prevImage
->Width
> 0 &&
2320 prevImage
->InternalFormat
== internalFormat
) {
2321 /* use the same format */
2322 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2323 return prevImage
->TexFormat
;
2327 /* choose format from scratch */
2328 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2329 ASSERT(f
!= MESA_FORMAT_NONE
);
2335 * Common code to implement all the glTexImage1D/2D/3D functions.
2338 teximage(struct gl_context
*ctx
, GLuint dims
,
2339 GLenum target
, GLint level
, GLint internalFormat
,
2340 GLsizei width
, GLsizei height
, GLsizei depth
,
2341 GLint border
, GLenum format
, GLenum type
,
2342 const GLvoid
*pixels
)
2346 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2348 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2349 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2351 _mesa_lookup_enum_by_nr(target
), level
,
2352 _mesa_lookup_enum_by_nr(internalFormat
),
2353 width
, height
, depth
, border
,
2354 _mesa_lookup_enum_by_nr(format
),
2355 _mesa_lookup_enum_by_nr(type
), pixels
);
2357 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2359 /* target error checking */
2360 if (!legal_teximage_target(ctx
, dims
, target
)) {
2361 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2362 dims
, _mesa_lookup_enum_by_nr(target
));
2366 /* general error checking */
2367 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2368 format
, type
, width
, height
, depth
, border
);
2370 if (_mesa_is_proxy_texture(target
)) {
2371 /* Proxy texture: just clear or set state depending on error checking */
2372 struct gl_texture_image
*texImage
=
2373 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2376 /* when error, clear all proxy texture image parameters */
2378 clear_teximage_fields(texImage
);
2381 /* no error, set the tex image parameters */
2382 struct gl_texture_object
*texObj
=
2383 _mesa_get_current_tex_object(ctx
, target
);
2384 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2389 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2390 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2391 depth
, border
, internalFormat
,
2394 else if (texImage
) {
2395 clear_teximage_fields(texImage
);
2400 /* non-proxy target */
2401 const GLuint face
= _mesa_tex_target_to_face(target
);
2402 struct gl_texture_object
*texObj
;
2403 struct gl_texture_image
*texImage
;
2406 return; /* error was recorded */
2409 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2410 _mesa_update_state(ctx
);
2412 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2414 _mesa_lock_texture(ctx
, texObj
);
2416 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2419 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2422 gl_format texFormat
;
2424 if (texImage
->Data
) {
2425 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2428 ASSERT(texImage
->Data
== NULL
);
2429 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2430 internalFormat
, format
,
2433 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2434 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2435 width
, height
, depth
,
2436 border
, internalFormat
, texFormat
);
2438 /* Give the texture to the driver. <pixels> may be null. */
2439 ASSERT(ctx
->Driver
.TexImage3D
);
2442 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2443 width
, border
, format
,
2444 type
, pixels
, &ctx
->Unpack
, texObj
,
2448 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2449 width
, height
, border
, format
,
2450 type
, pixels
, &ctx
->Unpack
, texObj
,
2454 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2455 width
, height
, depth
, border
, format
,
2456 type
, pixels
, &ctx
->Unpack
, texObj
,
2460 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2463 check_gen_mipmap(ctx
, target
, texObj
, level
);
2465 update_fbo_texture(ctx
, texObj
, face
, level
);
2468 texObj
->_Complete
= GL_FALSE
;
2469 ctx
->NewState
|= _NEW_TEXTURE
;
2472 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2476 _mesa_unlock_texture(ctx
, texObj
);
2482 * Called from the API. Note that width includes the border.
2485 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2486 GLsizei width
, GLint border
, GLenum format
,
2487 GLenum type
, const GLvoid
*pixels
)
2489 GET_CURRENT_CONTEXT(ctx
);
2490 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2491 border
, format
, type
, pixels
);
2496 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2497 GLsizei width
, GLsizei height
, GLint border
,
2498 GLenum format
, GLenum type
,
2499 const GLvoid
*pixels
)
2501 GET_CURRENT_CONTEXT(ctx
);
2502 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2503 border
, format
, type
, pixels
);
2508 * Called by the API or display list executor.
2509 * Note that width and height include the border.
2512 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2513 GLsizei width
, GLsizei height
, GLsizei depth
,
2514 GLint border
, GLenum format
, GLenum type
,
2515 const GLvoid
*pixels
)
2517 GET_CURRENT_CONTEXT(ctx
);
2518 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2519 border
, format
, type
, pixels
);
2524 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2525 GLsizei width
, GLsizei height
, GLsizei depth
,
2526 GLint border
, GLenum format
, GLenum type
,
2527 const GLvoid
*pixels
)
2529 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2530 depth
, border
, format
, type
, pixels
);
2534 #if FEATURE_OES_EGL_image
2536 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2538 struct gl_texture_object
*texObj
;
2539 struct gl_texture_image
*texImage
;
2540 GET_CURRENT_CONTEXT(ctx
);
2541 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2543 if (!ctx
->Extensions
.OES_EGL_image
) {
2544 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2545 "glEGLImageTargetTexture2DOES(unsupported)");
2549 if (target
!= GL_TEXTURE_2D
) {
2550 _mesa_error(ctx
, GL_INVALID_ENUM
,
2551 "glEGLImageTargetTexture2D(target=%d)", target
);
2555 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2556 _mesa_update_state(ctx
);
2558 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2559 _mesa_lock_texture(ctx
, texObj
);
2561 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2563 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2566 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2568 ASSERT(texImage
->Data
== NULL
);
2569 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2570 texObj
, texImage
, image
);
2573 texObj
->_Complete
= GL_FALSE
;
2574 ctx
->NewState
|= _NEW_TEXTURE
;
2576 _mesa_unlock_texture(ctx
, texObj
);
2584 * Implement all the glTexSubImage1/2/3D() functions.
2587 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2588 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2589 GLsizei width
, GLsizei height
, GLsizei depth
,
2590 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2592 struct gl_texture_object
*texObj
;
2593 struct gl_texture_image
*texImage
;
2595 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2597 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2598 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2600 _mesa_lookup_enum_by_nr(target
), level
,
2601 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2602 _mesa_lookup_enum_by_nr(format
),
2603 _mesa_lookup_enum_by_nr(type
), pixels
);
2605 /* check target (proxies not allowed) */
2606 if (!legal_teximage_target(ctx
, dims
, target
) ||
2607 _mesa_is_proxy_texture(target
)) {
2608 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2609 dims
, _mesa_lookup_enum_by_nr(target
));
2613 if (ctx
->NewState
& _MESA_NEW_TRANSFER_STATE
)
2614 _mesa_update_state(ctx
);
2616 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2617 width
, height
, depth
, format
, type
)) {
2618 return; /* error was detected */
2621 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2623 _mesa_lock_texture(ctx
, texObj
);
2625 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2627 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2628 xoffset
, yoffset
, zoffset
,
2629 width
, height
, depth
,
2630 format
, type
, texImage
)) {
2631 /* error was recorded */
2633 else if (width
> 0 && height
> 0 && height
> 0) {
2634 /* If we have a border, offset=-1 is legal. Bias by border width. */
2637 zoffset
+= texImage
->Border
;
2640 yoffset
+= texImage
->Border
;
2643 xoffset
+= texImage
->Border
;
2648 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2650 format
, type
, pixels
,
2651 &ctx
->Unpack
, texObj
, texImage
);
2654 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2655 xoffset
, yoffset
, width
, height
,
2656 format
, type
, pixels
,
2657 &ctx
->Unpack
, texObj
, texImage
);
2660 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2661 xoffset
, yoffset
, zoffset
,
2662 width
, height
, depth
,
2663 format
, type
, pixels
,
2664 &ctx
->Unpack
, texObj
, texImage
);
2667 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2670 check_gen_mipmap(ctx
, target
, texObj
, level
);
2672 ctx
->NewState
|= _NEW_TEXTURE
;
2675 _mesa_unlock_texture(ctx
, texObj
);
2680 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2681 GLint xoffset
, GLsizei width
,
2682 GLenum format
, GLenum type
,
2683 const GLvoid
*pixels
)
2685 GET_CURRENT_CONTEXT(ctx
);
2686 texsubimage(ctx
, 1, target
, level
,
2689 format
, type
, pixels
);
2694 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2695 GLint xoffset
, GLint yoffset
,
2696 GLsizei width
, GLsizei height
,
2697 GLenum format
, GLenum type
,
2698 const GLvoid
*pixels
)
2700 GET_CURRENT_CONTEXT(ctx
);
2701 texsubimage(ctx
, 2, target
, level
,
2702 xoffset
, yoffset
, 0,
2704 format
, type
, pixels
);
2710 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2711 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2712 GLsizei width
, GLsizei height
, GLsizei depth
,
2713 GLenum format
, GLenum type
,
2714 const GLvoid
*pixels
)
2716 GET_CURRENT_CONTEXT(ctx
);
2717 texsubimage(ctx
, 3, target
, level
,
2718 xoffset
, yoffset
, zoffset
,
2719 width
, height
, depth
,
2720 format
, type
, pixels
);
2726 * Implement the glCopyTexImage1/2D() functions.
2729 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2730 GLenum target
, GLint level
, GLenum internalFormat
,
2731 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2733 struct gl_texture_object
*texObj
;
2734 struct gl_texture_image
*texImage
;
2735 const GLuint face
= _mesa_tex_target_to_face(target
);
2737 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2739 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2740 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2742 _mesa_lookup_enum_by_nr(target
), level
,
2743 _mesa_lookup_enum_by_nr(internalFormat
),
2744 x
, y
, width
, height
, border
);
2746 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2747 _mesa_update_state(ctx
);
2749 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2750 width
, height
, border
))
2753 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2755 _mesa_lock_texture(ctx
, texObj
);
2757 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2760 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2763 gl_format texFormat
;
2765 if (texImage
->Data
) {
2766 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2769 ASSERT(texImage
->Data
== NULL
);
2771 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2772 internalFormat
, GL_NONE
,
2775 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2776 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2777 border
, internalFormat
, texFormat
);
2779 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2781 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2782 x
, y
, width
, border
);
2784 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2785 x
, y
, width
, height
, border
);
2787 check_gen_mipmap(ctx
, target
, texObj
, level
);
2789 update_fbo_texture(ctx
, texObj
, face
, level
);
2792 texObj
->_Complete
= GL_FALSE
;
2793 ctx
->NewState
|= _NEW_TEXTURE
;
2796 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2800 _mesa_unlock_texture(ctx
, texObj
);
2806 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2807 GLenum internalFormat
,
2809 GLsizei width
, GLint border
)
2811 GET_CURRENT_CONTEXT(ctx
);
2812 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2818 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2819 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2822 GET_CURRENT_CONTEXT(ctx
);
2823 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2824 x
, y
, width
, height
, border
);
2829 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2830 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2832 struct gl_texture_object
*texObj
;
2833 struct gl_texture_image
*texImage
;
2837 GET_CURRENT_CONTEXT(ctx
);
2838 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2840 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2841 _mesa_debug(ctx
, "glCopyTexSubImage1D %s %d %d %d %d %d\n",
2842 _mesa_lookup_enum_by_nr(target
),
2843 level
, xoffset
, x
, y
, width
);
2845 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2846 _mesa_update_state(ctx
);
2848 if (copytexsubimage_error_check1(ctx
, 1, target
, level
))
2851 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2853 _mesa_lock_texture(ctx
, texObj
);
2855 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2857 if (copytexsubimage_error_check2(ctx
, 1, target
, level
,
2858 xoffset
, 0, 0, width
, 1, texImage
)) {
2859 /* error was recorded */
2862 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2863 xoffset
+= texImage
->Border
;
2865 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2867 ASSERT(ctx
->Driver
.CopyTexSubImage1D
);
2868 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2869 xoffset
, x
, y
, width
);
2871 check_gen_mipmap(ctx
, target
, texObj
, level
);
2873 ctx
->NewState
|= _NEW_TEXTURE
;
2877 _mesa_unlock_texture(ctx
, texObj
);
2883 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2884 GLint xoffset
, GLint yoffset
,
2885 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2887 struct gl_texture_object
*texObj
;
2888 struct gl_texture_image
*texImage
;
2889 GET_CURRENT_CONTEXT(ctx
);
2890 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2892 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2893 _mesa_debug(ctx
, "glCopyTexSubImage2D %s %d %d %d %d %d %d %d\n",
2894 _mesa_lookup_enum_by_nr(target
),
2895 level
, xoffset
, yoffset
, x
, y
, width
, height
);
2897 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2898 _mesa_update_state(ctx
);
2900 if (copytexsubimage_error_check1(ctx
, 2, target
, level
))
2903 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2905 _mesa_lock_texture(ctx
, texObj
);
2907 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2909 if (copytexsubimage_error_check2(ctx
, 2, target
, level
,
2910 xoffset
, yoffset
, 0,
2911 width
, height
, texImage
)) {
2912 /* error was recorded */
2915 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2916 xoffset
+= texImage
->Border
;
2917 yoffset
+= texImage
->Border
;
2919 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2921 ASSERT(ctx
->Driver
.CopyTexSubImage2D
);
2922 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, xoffset
, yoffset
,
2923 x
, y
, width
, height
);
2925 check_gen_mipmap(ctx
, target
, texObj
, level
);
2927 ctx
->NewState
|= _NEW_TEXTURE
;
2931 _mesa_unlock_texture(ctx
, texObj
);
2937 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2938 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2939 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2941 struct gl_texture_object
*texObj
;
2942 struct gl_texture_image
*texImage
;
2943 GET_CURRENT_CONTEXT(ctx
);
2944 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2946 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2947 _mesa_debug(ctx
, "glCopyTexSubImage3D %s %d %d %d %d %d %d %d %d\n",
2948 _mesa_lookup_enum_by_nr(target
),
2949 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2951 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2952 _mesa_update_state(ctx
);
2954 if (copytexsubimage_error_check1(ctx
, 3, target
, level
))
2957 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2959 _mesa_lock_texture(ctx
, texObj
);
2961 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2963 if (copytexsubimage_error_check2(ctx
, 3, target
, level
, xoffset
, yoffset
,
2964 zoffset
, width
, height
, texImage
)) {
2965 /* error was recored */
2968 /* If we have a border, xoffset=-1 is legal. Bias by border width */
2969 xoffset
+= texImage
->Border
;
2970 yoffset
+= texImage
->Border
;
2971 zoffset
+= texImage
->Border
;
2973 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2975 ASSERT(ctx
->Driver
.CopyTexSubImage3D
);
2976 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2977 xoffset
, yoffset
, zoffset
,
2978 x
, y
, width
, height
);
2980 check_gen_mipmap(ctx
, target
, texObj
, level
);
2982 ctx
->NewState
|= _NEW_TEXTURE
;
2986 _mesa_unlock_texture(ctx
, texObj
);
2992 /**********************************************************************/
2993 /****** Compressed Textures ******/
2994 /**********************************************************************/
2998 * Return expected size of a compressed texture.
3001 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3004 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3005 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3010 * Return compressed texture block size, in pixels.
3013 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3015 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3016 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3021 * Error checking for glCompressedTexImage[123]D().
3022 * \return error code or GL_NO_ERROR.
3025 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3026 GLenum target
, GLint level
,
3027 GLenum internalFormat
, GLsizei width
,
3028 GLsizei height
, GLsizei depth
, GLint border
,
3031 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3033 if (dimensions
== 1) {
3034 /* 1D compressed textures not allowed */
3035 return GL_INVALID_ENUM
;
3037 else if (dimensions
== 2) {
3038 if (target
== GL_PROXY_TEXTURE_2D
) {
3039 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3041 else if (target
== GL_TEXTURE_2D
) {
3042 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3044 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3045 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3046 return GL_INVALID_ENUM
; /*target*/
3047 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3049 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3050 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3051 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3052 return GL_INVALID_ENUM
; /*target*/
3053 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3056 return GL_INVALID_ENUM
; /*target*/
3059 else if (dimensions
== 3) {
3060 /* 3D compressed textures not allowed */
3061 return GL_INVALID_ENUM
;
3065 return GL_INVALID_ENUM
;
3068 maxTextureSize
= 1 << (maxLevels
- 1);
3070 /* This will detect any invalid internalFormat value */
3071 if (!_mesa_is_compressed_format(ctx
, internalFormat
))
3072 return GL_INVALID_ENUM
;
3074 /* This should really never fail */
3075 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3076 return GL_INVALID_ENUM
;
3079 return GL_INVALID_VALUE
;
3082 * XXX We should probably use the proxy texture error check function here.
3084 if (width
< 1 || width
> maxTextureSize
||
3085 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(width
)))
3086 return GL_INVALID_VALUE
;
3088 if ((height
< 1 || height
> maxTextureSize
||
3089 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(height
)))
3091 return GL_INVALID_VALUE
;
3093 if ((depth
< 1 || depth
> maxTextureSize
||
3094 (!ctx
->Extensions
.ARB_texture_non_power_of_two
&& !_mesa_is_pow_two(depth
)))
3096 return GL_INVALID_VALUE
;
3098 /* For cube map, width must equal height */
3099 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3100 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3101 return GL_INVALID_VALUE
;
3103 if (level
< 0 || level
>= maxLevels
)
3104 return GL_INVALID_VALUE
;
3106 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3107 if (expectedSize
!= imageSize
)
3108 return GL_INVALID_VALUE
;
3110 #if FEATURE_EXT_texture_sRGB
3111 if ((internalFormat
== GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
||
3112 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
||
3113 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
||
3114 internalFormat
== GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
)
3116 return GL_INVALID_OPERATION
;
3125 * Error checking for glCompressedTexSubImage[123]D().
3126 * \warning There are some bad assumptions here about the size of compressed
3127 * texture tiles (multiple of 4) used to test the validity of the
3128 * offset and size parameters.
3129 * \return error code or GL_NO_ERROR.
3132 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3133 GLenum target
, GLint level
,
3134 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3135 GLsizei width
, GLsizei height
, GLsizei depth
,
3136 GLenum format
, GLsizei imageSize
)
3138 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3142 if (dimensions
== 1) {
3143 /* 1D compressed textures not allowed */
3144 return GL_INVALID_ENUM
;
3146 else if (dimensions
== 2) {
3147 if (target
== GL_PROXY_TEXTURE_2D
) {
3148 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3150 else if (target
== GL_TEXTURE_2D
) {
3151 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3153 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3154 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3155 return GL_INVALID_ENUM
; /*target*/
3156 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3158 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3159 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3160 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3161 return GL_INVALID_ENUM
; /*target*/
3162 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3165 return GL_INVALID_ENUM
; /*target*/
3168 else if (dimensions
== 3) {
3169 /* 3D compressed textures not allowed */
3170 return GL_INVALID_ENUM
;
3173 maxTextureSize
= 1 << (maxLevels
- 1);
3175 /* this will catch any invalid compressed format token */
3176 if (!_mesa_is_compressed_format(ctx
, format
))
3177 return GL_INVALID_ENUM
;
3179 if (width
< 1 || width
> maxTextureSize
)
3180 return GL_INVALID_VALUE
;
3182 if ((height
< 1 || height
> maxTextureSize
)
3184 return GL_INVALID_VALUE
;
3186 if (level
< 0 || level
>= maxLevels
)
3187 return GL_INVALID_VALUE
;
3190 * do checks which depend on compression block size
3192 get_compressed_block_size(format
, &bw
, &bh
);
3194 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3195 return GL_INVALID_VALUE
;
3197 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3198 return GL_INVALID_VALUE
;
3200 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3201 return GL_INVALID_VALUE
;
3203 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3204 if (expectedSize
!= imageSize
)
3205 return GL_INVALID_VALUE
;
3212 * Do second part of glCompressedTexSubImage error checking.
3213 * \return GL_TRUE if error found, GL_FALSE otherwise.
3216 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3217 GLsizei width
, GLsizei height
,
3218 GLsizei depth
, GLenum format
,
3219 struct gl_texture_image
*texImage
)
3222 if ((GLint
) format
!= texImage
->InternalFormat
) {
3223 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3224 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3228 if (((width
== 1 || width
== 2) &&
3229 width
!= (GLsizei
) texImage
->Width
) ||
3230 (width
> (GLsizei
) texImage
->Width
)) {
3231 _mesa_error(ctx
, GL_INVALID_VALUE
,
3232 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3237 if (((height
== 1 || height
== 2) &&
3238 height
!= (GLsizei
) texImage
->Height
) ||
3239 (height
> (GLsizei
) texImage
->Height
)) {
3240 _mesa_error(ctx
, GL_INVALID_VALUE
,
3241 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3247 if (((depth
== 1 || depth
== 2) &&
3248 depth
!= (GLsizei
) texImage
->Depth
) ||
3249 (depth
> (GLsizei
) texImage
->Depth
)) {
3250 _mesa_error(ctx
, GL_INVALID_VALUE
,
3251 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3262 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3263 GLenum internalFormat
, GLsizei width
,
3264 GLint border
, GLsizei imageSize
,
3267 GET_CURRENT_CONTEXT(ctx
);
3268 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3270 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3271 _mesa_debug(ctx
, "glCompressedTexImage1DARB %s %d %s %d %d %d %p\n",
3272 _mesa_lookup_enum_by_nr(target
), level
,
3273 _mesa_lookup_enum_by_nr(internalFormat
),
3274 width
, border
, imageSize
, data
);
3276 if (target
== GL_TEXTURE_1D
) {
3277 /* non-proxy target */
3278 struct gl_texture_object
*texObj
;
3279 struct gl_texture_image
*texImage
;
3280 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3281 internalFormat
, width
, 1, 1, border
, imageSize
);
3283 _mesa_error(ctx
, error
, "glCompressedTexImage1D");
3287 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3289 _mesa_lock_texture(ctx
, texObj
);
3291 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3293 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3296 gl_format texFormat
;
3298 if (texImage
->Data
) {
3299 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3301 ASSERT(texImage
->Data
== NULL
);
3303 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3304 internalFormat
, GL_NONE
,
3307 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
3308 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3309 border
, internalFormat
, texFormat
);
3311 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3312 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3313 internalFormat
, width
, border
,
3317 check_gen_mipmap(ctx
, target
, texObj
, level
);
3320 texObj
->_Complete
= GL_FALSE
;
3321 ctx
->NewState
|= _NEW_TEXTURE
;
3324 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage1D");
3328 _mesa_unlock_texture(ctx
, texObj
);
3330 else if (target
== GL_PROXY_TEXTURE_1D
) {
3331 /* Proxy texture: check for errors and update proxy state */
3332 GLenum error
= compressed_texture_error_check(ctx
, 1, target
, level
,
3333 internalFormat
, width
, 1, 1, border
, imageSize
);
3335 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3336 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3337 internalFormat
, GL_NONE
, GL_NONE
,
3338 width
, 1, 1, border
);
3341 /* if error, clear all proxy texture image parameters */
3342 struct gl_texture_image
*texImage
;
3343 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3345 clear_teximage_fields(texImage
);
3348 /* store the teximage parameters */
3349 struct gl_texture_object
*texObj
;
3350 struct gl_texture_image
*texImage
;
3351 gl_format texFormat
;
3353 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3355 _mesa_lock_texture(ctx
, texObj
);
3357 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3358 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3359 internalFormat
, GL_NONE
,
3361 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
3362 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, 1, 1,
3363 border
, internalFormat
, texFormat
);
3365 else if (texImage
) {
3366 clear_teximage_fields(texImage
);
3369 _mesa_unlock_texture(ctx
, texObj
);
3373 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage1D(target)");
3379 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3380 GLenum internalFormat
, GLsizei width
,
3381 GLsizei height
, GLint border
, GLsizei imageSize
,
3384 GET_CURRENT_CONTEXT(ctx
);
3385 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3387 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3388 _mesa_debug(ctx
, "glCompressedTexImage2DARB %s %d %s %d %d %d %d %p\n",
3389 _mesa_lookup_enum_by_nr(target
), level
,
3390 _mesa_lookup_enum_by_nr(internalFormat
),
3391 width
, height
, border
, imageSize
, data
);
3394 switch (internalFormat
) {
3395 case GL_PALETTE4_RGB8_OES
:
3396 case GL_PALETTE4_RGBA8_OES
:
3397 case GL_PALETTE4_R5_G6_B5_OES
:
3398 case GL_PALETTE4_RGBA4_OES
:
3399 case GL_PALETTE4_RGB5_A1_OES
:
3400 case GL_PALETTE8_RGB8_OES
:
3401 case GL_PALETTE8_RGBA8_OES
:
3402 case GL_PALETTE8_R5_G6_B5_OES
:
3403 case GL_PALETTE8_RGBA4_OES
:
3404 case GL_PALETTE8_RGB5_A1_OES
:
3405 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3406 width
, height
, imageSize
, data
);
3411 if (target
== GL_TEXTURE_2D
||
3412 (ctx
->Extensions
.ARB_texture_cube_map
&&
3413 target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3414 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)) {
3415 /* non-proxy target */
3416 struct gl_texture_object
*texObj
;
3417 struct gl_texture_image
*texImage
;
3419 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3420 internalFormat
, width
, height
, 1, border
, imageSize
);
3422 _mesa_error(ctx
, error
, "glCompressedTexImage2D");
3426 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3428 _mesa_lock_texture(ctx
, texObj
);
3430 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3432 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3435 gl_format texFormat
;
3437 if (texImage
->Data
) {
3438 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3440 ASSERT(texImage
->Data
== NULL
);
3442 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3443 internalFormat
, GL_NONE
,
3446 if (legal_texture_size(ctx
, texFormat
, width
, 1, 1)) {
3447 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
,
3448 height
, 1, border
, internalFormat
,
3451 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3452 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3453 internalFormat
, width
, height
,
3454 border
, imageSize
, data
,
3457 check_gen_mipmap(ctx
, target
, texObj
, level
);
3460 texObj
->_Complete
= GL_FALSE
;
3461 ctx
->NewState
|= _NEW_TEXTURE
;
3464 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3468 _mesa_unlock_texture(ctx
, texObj
);
3470 else if (target
== GL_PROXY_TEXTURE_2D
||
3471 (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
&&
3472 ctx
->Extensions
.ARB_texture_cube_map
)) {
3473 /* Proxy texture: check for errors and update proxy state */
3474 GLenum error
= compressed_texture_error_check(ctx
, 2, target
, level
,
3475 internalFormat
, width
, height
, 1, border
, imageSize
);
3477 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3478 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3479 internalFormat
, GL_NONE
, GL_NONE
,
3480 width
, height
, 1, border
);
3483 /* if error, clear all proxy texture image parameters */
3484 struct gl_texture_image
*texImage
;
3485 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3487 clear_teximage_fields(texImage
);
3490 /* store the teximage parameters */
3491 struct gl_texture_object
*texObj
;
3492 struct gl_texture_image
*texImage
;
3493 gl_format texFormat
;
3495 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3497 _mesa_lock_texture(ctx
, texObj
);
3499 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3500 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3501 internalFormat
, GL_NONE
,
3503 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
3504 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
,
3505 height
, 1, border
, internalFormat
,
3509 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2D");
3512 _mesa_unlock_texture(ctx
, texObj
);
3516 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage2D(target)");
3523 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3524 GLenum internalFormat
, GLsizei width
,
3525 GLsizei height
, GLsizei depth
, GLint border
,
3526 GLsizei imageSize
, const GLvoid
*data
)
3528 GET_CURRENT_CONTEXT(ctx
);
3529 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3531 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3532 _mesa_debug(ctx
, "glCompressedTexImage3DARB %s %d %s %d %d %d %d %d %p\n",
3533 _mesa_lookup_enum_by_nr(target
), level
,
3534 _mesa_lookup_enum_by_nr(internalFormat
),
3535 width
, height
, depth
, border
, imageSize
, data
);
3537 if (target
== GL_TEXTURE_3D
) {
3538 /* non-proxy target */
3539 struct gl_texture_object
*texObj
;
3540 struct gl_texture_image
*texImage
;
3541 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3542 internalFormat
, width
, height
, depth
, border
, imageSize
);
3544 _mesa_error(ctx
, error
, "glCompressedTexImage3D");
3548 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3550 _mesa_lock_texture(ctx
, texObj
);
3552 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3554 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3557 gl_format texFormat
;
3559 if (texImage
->Data
) {
3560 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3562 ASSERT(texImage
->Data
== NULL
);
3564 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3565 internalFormat
, GL_NONE
,
3568 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3569 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3570 width
, height
, depth
,
3571 border
, internalFormat
, texFormat
);
3573 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3574 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3576 width
, height
, depth
,
3577 border
, imageSize
, data
,
3580 check_gen_mipmap(ctx
, target
, texObj
, level
);
3583 texObj
->_Complete
= GL_FALSE
;
3584 ctx
->NewState
|= _NEW_TEXTURE
;
3587 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage3D");
3591 _mesa_unlock_texture(ctx
, texObj
);
3593 else if (target
== GL_PROXY_TEXTURE_3D
) {
3594 /* Proxy texture: check for errors and update proxy state */
3595 GLenum error
= compressed_texture_error_check(ctx
, 3, target
, level
,
3596 internalFormat
, width
, height
, depth
, border
, imageSize
);
3598 ASSERT(ctx
->Driver
.TestProxyTexImage
);
3599 error
= !(*ctx
->Driver
.TestProxyTexImage
)(ctx
, target
, level
,
3600 internalFormat
, GL_NONE
, GL_NONE
,
3601 width
, height
, depth
, border
);
3604 /* if error, clear all proxy texture image parameters */
3605 struct gl_texture_image
*texImage
;
3606 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3608 clear_teximage_fields(texImage
);
3611 /* store the teximage parameters */
3612 struct gl_texture_object
*texObj
;
3613 struct gl_texture_image
*texImage
;
3614 gl_format texFormat
;
3616 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3618 _mesa_lock_texture(ctx
, texObj
);
3620 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3621 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3622 internalFormat
, GL_NONE
,
3624 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3625 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3626 depth
, border
, internalFormat
,
3629 else if (texImage
) {
3630 clear_teximage_fields(texImage
);
3633 _mesa_unlock_texture(ctx
, texObj
);
3637 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage3D(target)");
3644 * Common helper for glCompressedTexSubImage1/2/3D().
3647 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3648 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3649 GLsizei width
, GLsizei height
, GLsizei depth
,
3650 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3652 struct gl_texture_object
*texObj
;
3653 struct gl_texture_image
*texImage
;
3655 GET_CURRENT_CONTEXT(ctx
);
3656 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3658 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3659 xoffset
, 0, 0, /* pos */
3660 width
, height
, depth
, /* size */
3663 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3667 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3669 _mesa_lock_texture(ctx
, texObj
);
3671 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3674 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3675 format
, texImage
)) {
3676 /* error was recorded */
3678 else if (width
> 0 && height
> 0 && depth
> 0) {
3681 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3682 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3684 format
, imageSize
, data
,
3689 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3690 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3693 format
, imageSize
, data
,
3698 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3699 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3700 xoffset
, yoffset
, zoffset
,
3701 width
, height
, depth
,
3702 format
, imageSize
, data
,
3710 check_gen_mipmap(ctx
, target
, texObj
, level
);
3712 ctx
->NewState
|= _NEW_TEXTURE
;
3715 _mesa_unlock_texture(ctx
, texObj
);
3720 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3721 GLsizei width
, GLenum format
,
3722 GLsizei imageSize
, const GLvoid
*data
)
3724 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3725 format
, imageSize
, data
);
3730 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3731 GLint yoffset
, GLsizei width
, GLsizei height
,
3732 GLenum format
, GLsizei imageSize
,
3735 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3736 width
, height
, 1, format
, imageSize
, data
);
3741 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3742 GLint yoffset
, GLint zoffset
, GLsizei width
,
3743 GLsizei height
, GLsizei depth
, GLenum format
,
3744 GLsizei imageSize
, const GLvoid
*data
)
3746 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3747 width
, height
, depth
, format
, imageSize
, data
);