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"
43 #include "mfeatures.h"
45 #include "texcompress.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
63 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
67 _mesa_alloc_texmemory(GLsizei bytes
)
69 return _mesa_align_malloc(bytes
, 512);
74 * Free texture memory allocated with _mesa_alloc_texmemory()
77 _mesa_free_texmemory(void *m
)
84 * Return the simple base format for a given internal texture format.
85 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
87 * \param ctx GL context.
88 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
90 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
91 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
93 * This is the format which is used during texture application (i.e. the
94 * texture format and env mode determine the arithmetic used.
96 * XXX this could be static
99 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
101 switch (internalFormat
) {
116 case GL_LUMINANCE_ALPHA
:
117 case GL_LUMINANCE4_ALPHA4
:
118 case GL_LUMINANCE6_ALPHA2
:
119 case GL_LUMINANCE8_ALPHA8
:
120 case GL_LUMINANCE12_ALPHA4
:
121 case GL_LUMINANCE12_ALPHA12
:
122 case GL_LUMINANCE16_ALPHA16
:
123 return GL_LUMINANCE_ALPHA
;
154 if (ctx
->Extensions
.EXT_texture_format_BGRA8888
) {
155 switch (internalFormat
) {
163 if (ctx
->Extensions
.EXT_paletted_texture
) {
164 switch (internalFormat
) {
166 case GL_COLOR_INDEX1_EXT
:
167 case GL_COLOR_INDEX2_EXT
:
168 case GL_COLOR_INDEX4_EXT
:
169 case GL_COLOR_INDEX8_EXT
:
170 case GL_COLOR_INDEX12_EXT
:
171 case GL_COLOR_INDEX16_EXT
:
172 return GL_COLOR_INDEX
;
178 if (ctx
->Extensions
.ARB_depth_texture
) {
179 switch (internalFormat
) {
180 case GL_DEPTH_COMPONENT
:
181 case GL_DEPTH_COMPONENT16
:
182 case GL_DEPTH_COMPONENT24
:
183 case GL_DEPTH_COMPONENT32
:
184 return GL_DEPTH_COMPONENT
;
190 switch (internalFormat
) {
191 case GL_COMPRESSED_ALPHA
:
193 case GL_COMPRESSED_LUMINANCE
:
195 case GL_COMPRESSED_LUMINANCE_ALPHA
:
196 return GL_LUMINANCE_ALPHA
;
197 case GL_COMPRESSED_INTENSITY
:
199 case GL_COMPRESSED_RGB
:
201 case GL_COMPRESSED_RGBA
:
207 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
208 switch (internalFormat
) {
209 case GL_COMPRESSED_RGB_FXT1_3DFX
:
211 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
218 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
219 switch (internalFormat
) {
220 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
222 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
223 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
224 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
231 if (ctx
->Extensions
.S3_s3tc
) {
232 switch (internalFormat
) {
244 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
245 if (internalFormat
== GL_YCBCR_MESA
)
246 return GL_YCBCR_MESA
;
249 if (ctx
->Extensions
.ARB_texture_float
) {
250 switch (internalFormat
) {
251 case GL_ALPHA16F_ARB
:
252 case GL_ALPHA32F_ARB
:
260 case GL_INTENSITY16F_ARB
:
261 case GL_INTENSITY32F_ARB
:
263 case GL_LUMINANCE16F_ARB
:
264 case GL_LUMINANCE32F_ARB
:
266 case GL_LUMINANCE_ALPHA16F_ARB
:
267 case GL_LUMINANCE_ALPHA32F_ARB
:
268 return GL_LUMINANCE_ALPHA
;
274 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
275 switch (internalFormat
) {
284 if (ctx
->Extensions
.EXT_texture_snorm
) {
285 switch (internalFormat
) {
300 case GL_RGBA16_SNORM
:
303 case GL_ALPHA8_SNORM
:
304 case GL_ALPHA16_SNORM
:
306 case GL_LUMINANCE_SNORM
:
307 case GL_LUMINANCE8_SNORM
:
308 case GL_LUMINANCE16_SNORM
:
310 case GL_LUMINANCE_ALPHA_SNORM
:
311 case GL_LUMINANCE8_ALPHA8_SNORM
:
312 case GL_LUMINANCE16_ALPHA16_SNORM
:
313 return GL_LUMINANCE_ALPHA
;
314 case GL_INTENSITY_SNORM
:
315 case GL_INTENSITY8_SNORM
:
316 case GL_INTENSITY16_SNORM
:
323 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
324 switch (internalFormat
) {
325 case GL_DEPTH_STENCIL_EXT
:
326 case GL_DEPTH24_STENCIL8_EXT
:
327 return GL_DEPTH_STENCIL_EXT
;
333 #if FEATURE_EXT_texture_sRGB
334 if (ctx
->Extensions
.EXT_texture_sRGB
) {
335 switch (internalFormat
) {
338 case GL_COMPRESSED_SRGB_EXT
:
339 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
341 case GL_SRGB_ALPHA_EXT
:
342 case GL_SRGB8_ALPHA8_EXT
:
343 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
344 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
345 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
346 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
348 case GL_SLUMINANCE_ALPHA_EXT
:
349 case GL_SLUMINANCE8_ALPHA8_EXT
:
350 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
351 return GL_LUMINANCE_ALPHA
;
352 case GL_SLUMINANCE_EXT
:
353 case GL_SLUMINANCE8_EXT
:
354 case GL_COMPRESSED_SLUMINANCE_EXT
:
360 #endif /* FEATURE_EXT_texture_sRGB */
362 if (ctx
->Extensions
.EXT_texture_integer
) {
363 switch (internalFormat
) {
365 case GL_RGBA16UI_EXT
:
366 case GL_RGBA32UI_EXT
:
378 case GL_ALPHA8UI_EXT
:
379 case GL_ALPHA16UI_EXT
:
380 case GL_ALPHA32UI_EXT
:
382 case GL_ALPHA16I_EXT
:
383 case GL_ALPHA32I_EXT
:
385 case GL_INTENSITY8UI_EXT
:
386 case GL_INTENSITY16UI_EXT
:
387 case GL_INTENSITY32UI_EXT
:
388 case GL_INTENSITY8I_EXT
:
389 case GL_INTENSITY16I_EXT
:
390 case GL_INTENSITY32I_EXT
:
392 case GL_LUMINANCE8UI_EXT
:
393 case GL_LUMINANCE16UI_EXT
:
394 case GL_LUMINANCE32UI_EXT
:
395 case GL_LUMINANCE8I_EXT
:
396 case GL_LUMINANCE16I_EXT
:
397 case GL_LUMINANCE32I_EXT
:
399 case GL_LUMINANCE_ALPHA8UI_EXT
:
400 case GL_LUMINANCE_ALPHA16UI_EXT
:
401 case GL_LUMINANCE_ALPHA32UI_EXT
:
402 case GL_LUMINANCE_ALPHA8I_EXT
:
403 case GL_LUMINANCE_ALPHA16I_EXT
:
404 case GL_LUMINANCE_ALPHA32I_EXT
:
405 return GL_LUMINANCE_ALPHA
;
411 if (ctx
->Extensions
.ARB_texture_rg
) {
412 switch (internalFormat
) {
414 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
416 if (!ctx
->Extensions
.ARB_half_float_pixel
)
420 if (!ctx
->Extensions
.ARB_texture_float
)
429 if (!ctx
->Extensions
.EXT_texture_integer
)
435 case GL_COMPRESSED_RED
:
439 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
441 if (!ctx
->Extensions
.ARB_half_float_pixel
)
445 if (!ctx
->Extensions
.ARB_texture_float
)
454 if (!ctx
->Extensions
.EXT_texture_integer
)
460 case GL_COMPRESSED_RG
:
467 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
468 switch (internalFormat
) {
476 if (ctx
->Extensions
.EXT_packed_float
) {
477 switch (internalFormat
) {
478 case GL_R11F_G11F_B10F_EXT
:
485 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
486 switch (internalFormat
) {
487 case GL_DEPTH_COMPONENT32F
:
488 return GL_DEPTH_COMPONENT
;
489 case GL_DEPTH32F_STENCIL8
:
490 return GL_DEPTH_STENCIL
;
496 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
497 switch (internalFormat
) {
498 case GL_COMPRESSED_RED_RGTC1
:
499 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
501 case GL_COMPRESSED_RG_RGTC2
:
502 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
509 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
510 switch (internalFormat
) {
511 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
512 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
514 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
515 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
516 return GL_LUMINANCE_ALPHA
;
522 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
523 switch (internalFormat
) {
524 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
525 return GL_LUMINANCE_ALPHA
;
531 return -1; /* error */
536 * For cube map faces, return a face index in [0,5].
537 * For other targets return 0;
540 _mesa_tex_target_to_face(GLenum target
)
542 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
543 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
544 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
552 * Store a gl_texture_image pointer in a gl_texture_object structure
553 * according to the target and level parameters.
555 * \param tObj texture object.
556 * \param target texture target.
557 * \param level image level.
558 * \param texImage texture image.
560 * This was basically prompted by the introduction of cube maps.
563 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
564 GLenum target
, GLint level
,
565 struct gl_texture_image
*texImage
)
567 const GLuint face
= _mesa_tex_target_to_face(target
);
571 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
573 tObj
->Image
[face
][level
] = texImage
;
575 /* Set the 'back' pointer */
576 texImage
->TexObject
= tObj
;
581 * Allocate a texture image structure.
583 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
586 * \return a pointer to gl_texture_image struct with all fields initialized to
589 struct gl_texture_image
*
590 _mesa_new_texture_image( struct gl_context
*ctx
)
593 return CALLOC_STRUCT(gl_texture_image
);
598 * Free texture image data.
599 * This function is a fallback called via ctx->Driver.FreeTexImageData().
601 * \param texImage texture image.
603 * Free the texture image data if it's not marked as client data.
606 _mesa_free_texture_image_data(struct gl_context
*ctx
,
607 struct gl_texture_image
*texImage
)
611 if (texImage
->Data
&& !texImage
->IsClientData
) {
612 /* free the old texture data */
613 _mesa_free_texmemory(texImage
->Data
);
616 texImage
->Data
= NULL
;
621 * Free texture image.
623 * \param texImage texture image.
625 * Free the texture image structure and the associated image data.
628 _mesa_delete_texture_image(struct gl_context
*ctx
,
629 struct gl_texture_image
*texImage
)
631 /* Free texImage->Data and/or any other driver-specific texture
634 ASSERT(ctx
->Driver
.FreeTexImageData
);
635 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
637 ASSERT(texImage
->Data
== NULL
);
638 if (texImage
->ImageOffsets
)
639 free(texImage
->ImageOffsets
);
645 * Test if a target is a proxy target.
647 * \param target texture target.
649 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
652 _mesa_is_proxy_texture(GLenum target
)
654 /* NUM_TEXTURE_TARGETS should match number of terms below,
655 * except there's no proxy for GL_TEXTURE_BUFFER.
657 assert(NUM_TEXTURE_TARGETS
== 8);
659 return (target
== GL_PROXY_TEXTURE_1D
||
660 target
== GL_PROXY_TEXTURE_2D
||
661 target
== GL_PROXY_TEXTURE_3D
||
662 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
663 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
664 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
665 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
670 * Return the proxy target which corresponds to the given texture target
673 get_proxy_target(GLenum target
)
677 case GL_PROXY_TEXTURE_1D
:
678 return GL_PROXY_TEXTURE_1D
;
680 case GL_PROXY_TEXTURE_2D
:
681 return GL_PROXY_TEXTURE_2D
;
683 case GL_PROXY_TEXTURE_3D
:
684 return GL_PROXY_TEXTURE_3D
;
685 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
686 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
687 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
688 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
689 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
690 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
691 case GL_TEXTURE_CUBE_MAP_ARB
:
692 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
693 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
694 case GL_TEXTURE_RECTANGLE_NV
:
695 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
696 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
697 case GL_TEXTURE_1D_ARRAY_EXT
:
698 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
699 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
700 case GL_TEXTURE_2D_ARRAY_EXT
:
701 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
702 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
704 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
711 * Get the texture object that corresponds to the target of the given
714 * \param ctx GL context.
715 * \param texUnit texture unit.
716 * \param target texture target.
718 * \return pointer to the texture object on success, or NULL on failure.
720 * \sa gl_texture_unit.
722 struct gl_texture_object
*
723 _mesa_select_tex_object(struct gl_context
*ctx
,
724 const struct gl_texture_unit
*texUnit
,
727 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
728 ctx
->Extensions
.EXT_texture_array
);
732 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
733 case GL_PROXY_TEXTURE_1D
:
734 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
736 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
737 case GL_PROXY_TEXTURE_2D
:
738 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
740 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
741 case GL_PROXY_TEXTURE_3D
:
742 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
743 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
744 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
745 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
746 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
747 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
748 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
749 case GL_TEXTURE_CUBE_MAP_ARB
:
750 return ctx
->Extensions
.ARB_texture_cube_map
751 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
752 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
753 return ctx
->Extensions
.ARB_texture_cube_map
754 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
755 case GL_TEXTURE_RECTANGLE_NV
:
756 return ctx
->Extensions
.NV_texture_rectangle
757 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
758 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
759 return ctx
->Extensions
.NV_texture_rectangle
760 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
761 case GL_TEXTURE_1D_ARRAY_EXT
:
762 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
763 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
764 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
765 case GL_TEXTURE_2D_ARRAY_EXT
:
766 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
767 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
768 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
769 case GL_TEXTURE_BUFFER
:
770 return ctx
->Extensions
.ARB_texture_buffer_object
771 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
773 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
780 * Return pointer to texture object for given target on current texture unit.
782 struct gl_texture_object
*
783 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
785 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
786 return _mesa_select_tex_object(ctx
, texUnit
, target
);
791 * Get a texture image pointer from a texture object, given a texture
792 * target and mipmap level. The target and level parameters should
793 * have already been error-checked.
795 * \param ctx GL context.
796 * \param texObj texture unit.
797 * \param target texture target.
798 * \param level image level.
800 * \return pointer to the texture image structure, or NULL on failure.
802 struct gl_texture_image
*
803 _mesa_select_tex_image(struct gl_context
*ctx
,
804 const struct gl_texture_object
*texObj
,
805 GLenum target
, GLint level
)
807 const GLuint face
= _mesa_tex_target_to_face(target
);
811 ASSERT(level
< MAX_TEXTURE_LEVELS
);
813 return texObj
->Image
[face
][level
];
818 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
819 * it and install it. Only return NULL if passed a bad parameter or run
822 struct gl_texture_image
*
823 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
824 GLenum target
, GLint level
)
826 struct gl_texture_image
*texImage
;
831 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
833 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
835 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
839 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
847 * Return pointer to the specified proxy texture image.
848 * Note that proxy textures are per-context, not per-texture unit.
849 * \return pointer to texture image or NULL if invalid target, invalid
850 * level, or out of memory.
852 struct gl_texture_image
*
853 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
855 struct gl_texture_image
*texImage
;
862 case GL_PROXY_TEXTURE_1D
:
863 if (level
>= ctx
->Const
.MaxTextureLevels
)
865 texIndex
= TEXTURE_1D_INDEX
;
867 case GL_PROXY_TEXTURE_2D
:
868 if (level
>= ctx
->Const
.MaxTextureLevels
)
870 texIndex
= TEXTURE_2D_INDEX
;
872 case GL_PROXY_TEXTURE_3D
:
873 if (level
>= ctx
->Const
.Max3DTextureLevels
)
875 texIndex
= TEXTURE_3D_INDEX
;
877 case GL_PROXY_TEXTURE_CUBE_MAP
:
878 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
880 texIndex
= TEXTURE_CUBE_INDEX
;
882 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
885 texIndex
= TEXTURE_RECT_INDEX
;
887 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
888 if (level
>= ctx
->Const
.MaxTextureLevels
)
890 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
892 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
893 if (level
>= ctx
->Const
.MaxTextureLevels
)
895 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
901 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
903 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
905 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
908 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
909 /* Set the 'back' pointer */
910 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
917 * Get the maximum number of allowed mipmap levels.
919 * \param ctx GL context.
920 * \param target texture target.
922 * \return the maximum number of allowed mipmap levels for the given
923 * texture target, or zero if passed a bad target.
928 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
932 case GL_PROXY_TEXTURE_1D
:
934 case GL_PROXY_TEXTURE_2D
:
935 return ctx
->Const
.MaxTextureLevels
;
937 case GL_PROXY_TEXTURE_3D
:
938 return ctx
->Const
.Max3DTextureLevels
;
939 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
940 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
941 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
942 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
943 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
944 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
945 case GL_TEXTURE_CUBE_MAP_ARB
:
946 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
947 return ctx
->Extensions
.ARB_texture_cube_map
948 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
949 case GL_TEXTURE_RECTANGLE_NV
:
950 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
951 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
952 case GL_TEXTURE_1D_ARRAY_EXT
:
953 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
954 case GL_TEXTURE_2D_ARRAY_EXT
:
955 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
956 return (ctx
->Extensions
.MESA_texture_array
||
957 ctx
->Extensions
.EXT_texture_array
)
958 ? ctx
->Const
.MaxTextureLevels
: 0;
959 case GL_TEXTURE_BUFFER
:
962 return 0; /* bad target */
968 * Return number of dimensions per mipmap level for the given texture target.
971 _mesa_get_texture_dimensions(GLenum target
)
975 case GL_PROXY_TEXTURE_1D
:
978 case GL_TEXTURE_RECTANGLE
:
979 case GL_TEXTURE_CUBE_MAP
:
980 case GL_PROXY_TEXTURE_2D
:
981 case GL_PROXY_TEXTURE_RECTANGLE
:
982 case GL_PROXY_TEXTURE_CUBE_MAP
:
983 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
984 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
985 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
986 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
987 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
988 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
989 case GL_TEXTURE_1D_ARRAY
:
990 case GL_PROXY_TEXTURE_1D_ARRAY
:
993 case GL_PROXY_TEXTURE_3D
:
994 case GL_TEXTURE_2D_ARRAY
:
995 case GL_PROXY_TEXTURE_2D_ARRAY
:
997 case GL_TEXTURE_BUFFER
:
1000 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1009 #if 000 /* not used anymore */
1011 * glTexImage[123]D can accept a NULL image pointer. In this case we
1012 * create a texture image with unspecified image contents per the OpenGL
1016 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1018 const GLint components
= _mesa_components_in_format(format
);
1019 const GLint numPixels
= width
* height
* depth
;
1020 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1024 * Let's see if anyone finds this. If glTexImage2D() is called with
1025 * a NULL image pointer then load the texture image with something
1026 * interesting instead of leaving it indeterminate.
1029 static const char message
[8][32] = {
1030 " X X XXXXX XXX X ",
1031 " XX XX X X X X X ",
1033 " X X XXXX XXX XXXXX ",
1036 " X X XXXXX XXX X X ",
1040 GLubyte
*imgPtr
= data
;
1042 for (h
= 0; h
< depth
; h
++) {
1043 for (i
= 0; i
< height
; i
++) {
1044 GLint srcRow
= 7 - (i
% 8);
1045 for (j
= 0; j
< width
; j
++) {
1046 GLint srcCol
= j
% 32;
1047 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1048 for (k
= 0; k
< components
; k
++) {
1064 * Reset the fields of a gl_texture_image struct to zero.
1066 * \param img texture image structure.
1068 * This is called when a proxy texture test fails, we set all the
1069 * image members (except DriverData) to zero.
1070 * It's also used in glTexImage[123]D as a safeguard to be sure all
1071 * required fields get initialized properly by the Driver.TexImage[123]D
1075 clear_teximage_fields(struct gl_texture_image
*img
)
1078 img
->_BaseFormat
= 0;
1079 img
->InternalFormat
= 0;
1085 if (img
->ImageOffsets
) {
1086 free(img
->ImageOffsets
);
1087 img
->ImageOffsets
= NULL
;
1093 img
->HeightLog2
= 0;
1096 img
->TexFormat
= MESA_FORMAT_NONE
;
1097 img
->FetchTexelc
= NULL
;
1098 img
->FetchTexelf
= NULL
;
1103 * Initialize basic fields of the gl_texture_image struct.
1105 * \param ctx GL context.
1106 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1107 * \param img texture image structure to be initialized.
1108 * \param width image width.
1109 * \param height image height.
1110 * \param depth image depth.
1111 * \param border image border.
1112 * \param internalFormat internal format.
1113 * \param format the actual hardware format (one of MESA_FORMAT_*)
1115 * Fills in the fields of \p img with the given information.
1116 * Note: width, height and depth include the border.
1119 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1120 struct gl_texture_image
*img
,
1121 GLsizei width
, GLsizei height
, GLsizei depth
,
1122 GLint border
, GLenum internalFormat
,
1129 ASSERT(height
>= 0);
1132 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1133 ASSERT(img
->_BaseFormat
> 0);
1134 img
->InternalFormat
= internalFormat
;
1135 img
->Border
= border
;
1137 img
->Height
= height
;
1140 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1141 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1143 if (height
== 1) { /* 1-D texture */
1145 img
->HeightLog2
= 0;
1148 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1149 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1152 if (depth
== 1) { /* 2-D texture */
1157 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1158 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1161 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1163 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1164 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1165 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1166 img
->_IsPowerOfTwo
= GL_TRUE
;
1168 img
->_IsPowerOfTwo
= GL_FALSE
;
1170 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1171 img
->RowStride
= width
;
1172 /* Allocate the ImageOffsets array and initialize to typical values.
1173 * We allocate the array for 1D/2D textures too in order to avoid special-
1174 * case code in the texstore routines.
1176 if (img
->ImageOffsets
)
1177 free(img
->ImageOffsets
);
1178 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1179 for (i
= 0; i
< depth
; i
++) {
1180 img
->ImageOffsets
[i
] = i
* width
* height
;
1183 /* Compute Width/Height/DepthScale for mipmap lod computation */
1184 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1185 /* scale = 1.0 since texture coords directly map to texels */
1186 img
->WidthScale
= 1.0;
1187 img
->HeightScale
= 1.0;
1188 img
->DepthScale
= 1.0;
1191 img
->WidthScale
= (GLfloat
) img
->Width
;
1192 img
->HeightScale
= (GLfloat
) img
->Height
;
1193 img
->DepthScale
= (GLfloat
) img
->Depth
;
1196 img
->TexFormat
= format
;
1198 dims
= _mesa_get_texture_dimensions(target
);
1200 _mesa_set_fetch_functions(img
, dims
);
1205 * Free and clear fields of the gl_texture_image struct.
1207 * \param ctx GL context.
1208 * \param texImage texture image structure to be cleared.
1210 * After the call, \p texImage will have no data associated with it. Its
1211 * fields are cleared so that its parent object will test incomplete.
1214 _mesa_clear_texture_image(struct gl_context
*ctx
,
1215 struct gl_texture_image
*texImage
)
1217 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1218 clear_teximage_fields(texImage
);
1223 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1224 * level, width, height and depth against the ctx->Const limits for textures.
1226 * A hardware driver might override this function if, for example, the
1227 * max 3D texture size is 512x512x64 (i.e. not a cube).
1229 * Note that width, height, depth == 0 is not an error. However, a
1230 * texture with zero width/height/depth will be considered "incomplete"
1231 * and texturing will effectively be disabled.
1233 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1234 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1235 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1236 * \param level as passed to glTexImage
1237 * \param internalFormat as passed to glTexImage
1238 * \param format as passed to glTexImage
1239 * \param type as passed to glTexImage
1240 * \param width as passed to glTexImage
1241 * \param height as passed to glTexImage
1242 * \param depth as passed to glTexImage
1243 * \param border as passed to glTexImage
1244 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1247 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1248 GLint internalFormat
, GLenum format
, GLenum type
,
1249 GLint width
, GLint height
, GLint depth
, GLint border
)
1253 (void) internalFormat
;
1258 case GL_PROXY_TEXTURE_1D
:
1259 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1260 if (width
< 2 * border
|| width
> 2 + maxSize
)
1262 if (level
>= ctx
->Const
.MaxTextureLevels
)
1264 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1265 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1270 case GL_PROXY_TEXTURE_2D
:
1271 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1272 if (width
< 2 * border
|| width
> 2 + maxSize
)
1274 if (height
< 2 * border
|| height
> 2 + maxSize
)
1276 if (level
>= ctx
->Const
.MaxTextureLevels
)
1278 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1279 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1281 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1286 case GL_PROXY_TEXTURE_3D
:
1287 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1288 if (width
< 2 * border
|| width
> 2 + maxSize
)
1290 if (height
< 2 * border
|| height
> 2 + maxSize
)
1292 if (depth
< 2 * border
|| depth
> 2 + maxSize
)
1294 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1296 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1297 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1299 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1301 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1306 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1307 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1308 if (width
< 0 || width
> maxSize
)
1310 if (height
< 0 || height
> maxSize
)
1316 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1317 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1318 if (width
< 2 * border
|| width
> 2 + maxSize
)
1320 if (height
< 2 * border
|| height
> 2 + maxSize
)
1322 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1324 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1325 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1327 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1332 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1333 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1334 if (width
< 2 * border
|| width
> 2 + maxSize
)
1336 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1338 if (level
>= ctx
->Const
.MaxTextureLevels
)
1340 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1341 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1346 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1347 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1348 if (width
< 2 * border
|| width
> 2 + maxSize
)
1350 if (height
< 2 * border
|| height
> 2 + maxSize
)
1352 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1354 if (level
>= ctx
->Const
.MaxTextureLevels
)
1356 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1357 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1359 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1365 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1372 * Check if the memory used by the texture would exceed the driver's limit.
1373 * This lets us support a max 3D texture size of 8K (for example) but
1374 * prevents allocating a full 8K x 8K x 8K texture.
1375 * XXX this could be rolled into the proxy texture size test (above) but
1376 * we don't have the actual texture internal format at that point.
1379 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1380 GLint width
, GLint height
, GLint depth
)
1382 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1383 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1384 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1390 * Helper function to determine whether a target and specific compression
1391 * format are supported.
1394 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1397 (void) intFormat
; /* not used yet */
1401 case GL_PROXY_TEXTURE_2D
:
1402 return GL_TRUE
; /* true for any compressed format so far */
1403 case GL_PROXY_TEXTURE_CUBE_MAP
:
1404 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1405 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1406 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1407 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1408 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1409 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1410 return ctx
->Extensions
.ARB_texture_cube_map
;
1411 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1412 case GL_TEXTURE_2D_ARRAY_EXT
:
1413 return (ctx
->Extensions
.MESA_texture_array
||
1414 ctx
->Extensions
.EXT_texture_array
);
1422 * Check if the given texture target value is legal for a
1423 * glTexImage1/2/3D call.
1426 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1432 case GL_PROXY_TEXTURE_1D
:
1440 case GL_PROXY_TEXTURE_2D
:
1442 case GL_PROXY_TEXTURE_CUBE_MAP
:
1443 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1444 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1445 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1446 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1447 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1448 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1449 return ctx
->Extensions
.ARB_texture_cube_map
;
1450 case GL_TEXTURE_RECTANGLE_NV
:
1451 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1452 return ctx
->Extensions
.NV_texture_rectangle
;
1453 case GL_TEXTURE_1D_ARRAY_EXT
:
1454 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1455 return (ctx
->Extensions
.MESA_texture_array
||
1456 ctx
->Extensions
.EXT_texture_array
);
1463 case GL_PROXY_TEXTURE_3D
:
1465 case GL_TEXTURE_2D_ARRAY_EXT
:
1466 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1467 return (ctx
->Extensions
.MESA_texture_array
||
1468 ctx
->Extensions
.EXT_texture_array
);
1473 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1480 * Check if the given texture target value is legal for a
1481 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1482 * The difference compared to legal_teximage_target() above is that
1483 * proxy targets are not supported.
1486 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1490 return target
== GL_TEXTURE_1D
;
1495 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1496 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1497 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1498 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1499 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1500 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1501 return ctx
->Extensions
.ARB_texture_cube_map
;
1502 case GL_TEXTURE_RECTANGLE_NV
:
1503 return ctx
->Extensions
.NV_texture_rectangle
;
1504 case GL_TEXTURE_1D_ARRAY_EXT
:
1505 return (ctx
->Extensions
.MESA_texture_array
||
1506 ctx
->Extensions
.EXT_texture_array
);
1514 case GL_TEXTURE_2D_ARRAY_EXT
:
1515 return (ctx
->Extensions
.MESA_texture_array
||
1516 ctx
->Extensions
.EXT_texture_array
);
1521 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1529 * Test the glTexImage[123]D() parameters for errors.
1531 * \param ctx GL context.
1532 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1533 * \param target texture target given by the user.
1534 * \param level image level given by the user.
1535 * \param internalFormat internal format given by the user.
1536 * \param format pixel data format given by the user.
1537 * \param type pixel data type given by the user.
1538 * \param width image width given by the user.
1539 * \param height image height given by the user.
1540 * \param depth image depth given by the user.
1541 * \param border image border given by the user.
1543 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1545 * Verifies each of the parameters against the constants specified in
1546 * __struct gl_contextRec::Const and the supported extensions, and according
1547 * to the OpenGL specification.
1550 texture_error_check( struct gl_context
*ctx
,
1551 GLuint dimensions
, GLenum target
,
1552 GLint level
, GLint internalFormat
,
1553 GLenum format
, GLenum type
,
1554 GLint width
, GLint height
,
1555 GLint depth
, GLint border
)
1557 const GLenum proxyTarget
= get_proxy_target(target
);
1558 const GLboolean isProxy
= target
== proxyTarget
;
1559 GLboolean sizeOK
= GL_TRUE
;
1560 GLboolean colorFormat
, indexFormat
;
1562 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1563 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1565 _mesa_error(ctx
, GL_INVALID_VALUE
,
1566 "glTexImage%dD(level=%d)", dimensions
, level
);
1572 if (border
< 0 || border
> 1 ||
1573 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1574 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1576 _mesa_error(ctx
, GL_INVALID_VALUE
,
1577 "glTexImage%dD(border=%d)", dimensions
, border
);
1582 if (width
< 0 || height
< 0 || depth
< 0) {
1584 _mesa_error(ctx
, GL_INVALID_VALUE
,
1585 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1590 /* Do this simple check before calling the TestProxyTexImage() function */
1591 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1592 sizeOK
= (width
== height
);
1596 * Use the proxy texture driver hook to see if the size/level/etc are
1599 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1600 internalFormat
, format
,
1601 type
, width
, height
,
1605 _mesa_error(ctx
, GL_INVALID_VALUE
,
1606 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1607 dimensions
, level
, width
, height
, depth
);
1612 /* Check internalFormat */
1613 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1615 _mesa_error(ctx
, GL_INVALID_VALUE
,
1616 "glTexImage%dD(internalFormat=%s)",
1617 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1622 /* Check incoming image format and type */
1623 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1624 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1625 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1626 * GL_EXT_texture_integer extension, some combinations should generate
1627 * GL_INVALID_ENUM instead (grr!).
1630 GLenum error
= _mesa_is_integer_format(format
)
1631 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1632 _mesa_error(ctx
, error
,
1633 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1634 dimensions
, format
, type
);
1639 /* make sure internal format and format basically agree */
1640 colorFormat
= _mesa_is_color_format(format
);
1641 indexFormat
= _mesa_is_index_format(format
);
1642 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1643 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1644 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1645 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1646 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1647 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1649 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1650 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1651 dimensions
, internalFormat
, format
);
1655 /* additional checks for ycbcr textures */
1656 if (internalFormat
== GL_YCBCR_MESA
) {
1657 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1658 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1659 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1661 _mesa_snprintf(message
, sizeof(message
),
1662 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1663 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1664 return GL_TRUE
; /* error */
1666 if (target
!= GL_TEXTURE_2D
&&
1667 target
!= GL_PROXY_TEXTURE_2D
&&
1668 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1669 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1671 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1677 _mesa_snprintf(message
, sizeof(message
),
1678 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1679 dimensions
, border
);
1680 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1686 /* additional checks for depth textures */
1687 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1688 /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */
1689 if (target
!= GL_TEXTURE_1D
&&
1690 target
!= GL_PROXY_TEXTURE_1D
&&
1691 target
!= GL_TEXTURE_2D
&&
1692 target
!= GL_PROXY_TEXTURE_2D
&&
1693 target
!= GL_TEXTURE_1D_ARRAY
&&
1694 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1695 target
!= GL_TEXTURE_2D_ARRAY
&&
1696 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1697 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1698 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1700 _mesa_error(ctx
, GL_INVALID_ENUM
,
1701 "glTexImage(target/internalFormat)");
1706 /* additional checks for compressed textures */
1707 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1708 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1710 _mesa_error(ctx
, GL_INVALID_ENUM
,
1711 "glTexImage%dD(target)", dimensions
);
1716 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1717 "glTexImage%dD(border!=0)", dimensions
);
1723 /* additional checks for integer textures */
1724 if (ctx
->Extensions
.EXT_texture_integer
&&
1725 (_mesa_is_integer_format(format
) !=
1726 _mesa_is_integer_format(internalFormat
))) {
1728 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1729 "glTexImage%dD(integer/non-integer format mismatch)",
1735 /* if we get here, the parameters are OK */
1741 * Test glTexSubImage[123]D() parameters for errors.
1743 * \param ctx GL context.
1744 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1745 * \param target texture target given by the user.
1746 * \param level image level given by the user.
1747 * \param xoffset sub-image x offset given by the user.
1748 * \param yoffset sub-image y offset given by the user.
1749 * \param zoffset sub-image z offset given by the user.
1750 * \param format pixel data format given by the user.
1751 * \param type pixel data type given by the user.
1752 * \param width image width given by the user.
1753 * \param height image height given by the user.
1754 * \param depth image depth given by the user.
1756 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1758 * Verifies each of the parameters against the constants specified in
1759 * __struct gl_contextRec::Const and the supported extensions, and according
1760 * to the OpenGL specification.
1763 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1764 GLenum target
, GLint level
,
1765 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1766 GLint width
, GLint height
, GLint depth
,
1767 GLenum format
, GLenum type
)
1769 /* Basic level check */
1770 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1771 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1775 /* Check for negative sizes */
1777 _mesa_error(ctx
, GL_INVALID_VALUE
,
1778 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1781 if (height
< 0 && dimensions
> 1) {
1782 _mesa_error(ctx
, GL_INVALID_VALUE
,
1783 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1786 if (depth
< 0 && dimensions
> 2) {
1787 _mesa_error(ctx
, GL_INVALID_VALUE
,
1788 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1792 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1793 /* As with the glTexImage2D check above, the error code here
1794 * depends on texture integer.
1796 GLenum error
= _mesa_is_integer_format(format
)
1797 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1798 _mesa_error(ctx
, error
,
1799 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1800 dimensions
, format
, type
);
1809 * Do second part of glTexSubImage which depends on the destination texture.
1810 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1813 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1814 GLenum target
, GLint level
,
1815 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1816 GLint width
, GLint height
, GLint depth
,
1817 GLenum format
, GLenum type
,
1818 const struct gl_texture_image
*destTex
)
1821 /* undefined image level */
1822 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1826 if (xoffset
< -((GLint
)destTex
->Border
)) {
1827 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1831 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1832 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1836 if (dimensions
> 1) {
1837 if (yoffset
< -((GLint
)destTex
->Border
)) {
1838 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1842 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1843 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1848 if (dimensions
> 2) {
1849 if (zoffset
< -((GLint
)destTex
->Border
)) {
1850 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1853 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1854 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1859 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1862 /* do tests which depend on compression block size */
1863 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1865 /* offset must be multiple of block size */
1866 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1867 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1868 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1869 dimensions
, xoffset
, yoffset
);
1872 /* size must be multiple of bw by bh or equal to whole texture size */
1873 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1874 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1875 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1878 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1879 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1880 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1890 * Test glCopyTexImage[12]D() parameters for errors.
1892 * \param ctx GL context.
1893 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1894 * \param target texture target given by the user.
1895 * \param level image level given by the user.
1896 * \param internalFormat internal format given by the user.
1897 * \param width image width given by the user.
1898 * \param height image height given by the user.
1899 * \param border texture border.
1901 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1903 * Verifies each of the parameters against the constants specified in
1904 * __struct gl_contextRec::Const and the supported extensions, and according
1905 * to the OpenGL specification.
1908 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1909 GLenum target
, GLint level
, GLint internalFormat
,
1910 GLint width
, GLint height
, GLint border
)
1912 const GLenum proxyTarget
= get_proxy_target(target
);
1913 const GLenum type
= GL_FLOAT
;
1918 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1919 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1920 dimensions
, _mesa_lookup_enum_by_nr(target
));
1924 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1925 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1926 _mesa_error(ctx
, GL_INVALID_VALUE
,
1927 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1931 /* Check that the source buffer is complete */
1932 if (ctx
->ReadBuffer
->Name
) {
1933 if (ctx
->ReadBuffer
->_Status
== 0) {
1934 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1936 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1937 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1938 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1944 if (border
< 0 || border
> 1 ||
1945 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1946 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1950 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1952 _mesa_error(ctx
, GL_INVALID_VALUE
,
1953 "glCopyTexImage%dD(internalFormat)", dimensions
);
1957 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1958 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1959 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1963 /* Do size, level checking */
1964 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1965 ? (width
== height
) : 1;
1967 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1968 internalFormat
, format
,
1969 type
, width
, height
,
1973 if (dimensions
== 1) {
1974 _mesa_error(ctx
, GL_INVALID_VALUE
,
1975 "glCopyTexImage1D(width=%d)", width
);
1978 ASSERT(dimensions
== 2);
1979 _mesa_error(ctx
, GL_INVALID_VALUE
,
1980 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1985 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1986 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1987 _mesa_error(ctx
, GL_INVALID_ENUM
,
1988 "glCopyTexImage%dD(target)", dimensions
);
1992 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1993 "glCopyTexImage%dD(border!=0)", dimensions
);
1997 else if (_mesa_is_depth_format(internalFormat
)) {
1998 /* make sure we have depth/stencil buffers */
1999 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2000 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2001 "glCopyTexImage%dD(no depth)", dimensions
);
2005 else if (_mesa_is_depthstencil_format(internalFormat
)) {
2006 /* make sure we have depth/stencil buffers */
2007 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2008 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2009 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
2014 /* if we get here, the parameters are OK */
2020 * Test glCopyTexSubImage[12]D() parameters for errors.
2021 * Note that this is the first part of error checking.
2022 * See also copytexsubimage_error_check2() below for the second part.
2024 * \param ctx GL context.
2025 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2026 * \param target texture target given by the user.
2027 * \param level image level given by the user.
2029 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2032 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2033 GLenum target
, GLint level
)
2035 /* Check that the source buffer is complete */
2036 if (ctx
->ReadBuffer
->Name
) {
2037 if (ctx
->ReadBuffer
->_Status
== 0) {
2038 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2040 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2041 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2042 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2047 /* check target (proxies not allowed) */
2048 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2049 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2050 dimensions
, _mesa_lookup_enum_by_nr(target
));
2055 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2056 _mesa_error(ctx
, GL_INVALID_VALUE
,
2057 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2066 * Second part of error checking for glCopyTexSubImage[12]D().
2067 * \param xoffset sub-image x offset given by the user.
2068 * \param yoffset sub-image y offset given by the user.
2069 * \param zoffset sub-image z offset given by the user.
2070 * \param width image width given by the user.
2071 * \param height image height given by the user.
2074 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2075 GLenum target
, GLint level
,
2076 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2077 GLsizei width
, GLsizei height
,
2078 const struct gl_texture_image
*teximage
)
2080 /* check that dest tex image exists */
2082 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2083 "glCopyTexSubImage%dD(undefined texture level: %d)",
2090 _mesa_error(ctx
, GL_INVALID_VALUE
,
2091 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2094 if (dimensions
> 1 && height
< 0) {
2095 _mesa_error(ctx
, GL_INVALID_VALUE
,
2096 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2100 /* check x/y offsets */
2101 if (xoffset
< -((GLint
)teximage
->Border
)) {
2102 _mesa_error(ctx
, GL_INVALID_VALUE
,
2103 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2106 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2107 _mesa_error(ctx
, GL_INVALID_VALUE
,
2108 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2111 if (dimensions
> 1) {
2112 if (yoffset
< -((GLint
)teximage
->Border
)) {
2113 _mesa_error(ctx
, GL_INVALID_VALUE
,
2114 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2117 /* NOTE: we're adding the border here, not subtracting! */
2118 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2119 _mesa_error(ctx
, GL_INVALID_VALUE
,
2120 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2125 /* check z offset */
2126 if (dimensions
> 2) {
2127 if (zoffset
< -((GLint
)teximage
->Border
)) {
2128 _mesa_error(ctx
, GL_INVALID_VALUE
,
2129 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2132 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2133 _mesa_error(ctx
, GL_INVALID_VALUE
,
2134 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2139 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2140 /* offset must be multiple of 4 */
2141 if ((xoffset
& 3) || (yoffset
& 3)) {
2142 _mesa_error(ctx
, GL_INVALID_VALUE
,
2143 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2146 /* size must be multiple of 4 */
2147 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2148 _mesa_error(ctx
, GL_INVALID_VALUE
,
2149 "glCopyTexSubImage%dD(width)", dimensions
);
2152 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2153 _mesa_error(ctx
, GL_INVALID_VALUE
,
2154 "glCopyTexSubImage%dD(height)", dimensions
);
2159 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2160 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2164 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2165 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2166 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2167 dimensions
, teximage
->_BaseFormat
);
2171 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2172 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2173 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2174 "glCopyTexSubImage%dD(no depth buffer)",
2179 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2180 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2181 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2182 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2188 /* If copying into an integer texture, the source buffer must also be
2191 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2192 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2193 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2194 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2195 "glCopyTexSubImage%dD(source buffer is not integer format)",
2201 /* if we get here, the parameters are OK */
2206 /** Callback info for walking over FBO hash table */
2209 struct gl_context
*ctx
;
2210 struct gl_texture_object
*texObj
;
2216 * Check render to texture callback. Called from _mesa_HashWalk().
2219 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2221 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2222 const struct cb_info
*info
= (struct cb_info
*) userData
;
2223 struct gl_context
*ctx
= info
->ctx
;
2224 const struct gl_texture_object
*texObj
= info
->texObj
;
2225 const GLuint level
= info
->level
, face
= info
->face
;
2227 /* If this is a user-created FBO */
2230 /* check if any of the FBO's attachments point to 'texObj' */
2231 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2232 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2233 if (att
->Type
== GL_TEXTURE
&&
2234 att
->Texture
== texObj
&&
2235 att
->TextureLevel
== level
&&
2236 att
->CubeMapFace
== face
) {
2237 ASSERT(_mesa_get_attachment_teximage(att
));
2238 /* Tell driver about the new renderbuffer texture */
2239 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2240 /* Mark fb status as indeterminate to force re-validation */
2249 * When a texture image is specified we have to check if it's bound to
2250 * any framebuffer objects (render to texture) in order to detect changes
2251 * in size or format since that effects FBO completeness.
2252 * Any FBOs rendering into the texture must be re-validated.
2255 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2256 GLuint face
, GLuint level
)
2258 /* Only check this texture if it's been marked as RenderToTexture */
2259 if (texObj
->_RenderToTexture
) {
2260 struct cb_info info
;
2262 info
.texObj
= texObj
;
2265 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2271 * If the texture object's GenerateMipmap flag is set and we've
2272 * changed the texture base level image, regenerate the rest of the
2273 * mipmap levels now.
2276 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2277 struct gl_texture_object
*texObj
, GLint level
)
2279 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2280 if (texObj
->GenerateMipmap
&&
2281 level
== texObj
->BaseLevel
&&
2282 level
< texObj
->MaxLevel
) {
2283 ASSERT(ctx
->Driver
.GenerateMipmap
);
2284 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2289 /** Debug helper: override the user-requested internal format */
2291 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2294 if (internalFormat
== GL_RGBA16F_ARB
||
2295 internalFormat
== GL_RGBA32F_ARB
) {
2296 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2299 else if (internalFormat
== GL_RGB16F_ARB
||
2300 internalFormat
== GL_RGB32F_ARB
) {
2301 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2304 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2305 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2306 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2307 return GL_LUMINANCE_ALPHA
;
2309 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2310 internalFormat
== GL_LUMINANCE32F_ARB
) {
2311 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2312 return GL_LUMINANCE
;
2314 else if (internalFormat
== GL_ALPHA16F_ARB
||
2315 internalFormat
== GL_ALPHA32F_ARB
) {
2316 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2320 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2321 internalFormat = GL_RGBA;
2325 return internalFormat
;
2328 return internalFormat
;
2334 * Choose the actual hardware format for a texture image.
2335 * Try to use the same format as the previous image level when possible.
2336 * Otherwise, ask the driver for the best format.
2337 * It's important to try to choose a consistant format for all levels
2338 * for efficient texture memory layout/allocation. In particular, this
2339 * comes up during automatic mipmap generation.
2342 _mesa_choose_texture_format(struct gl_context
*ctx
,
2343 struct gl_texture_object
*texObj
,
2344 GLenum target
, GLint level
,
2345 GLenum internalFormat
, GLenum format
, GLenum type
)
2349 /* see if we've already chosen a format for the previous level */
2351 struct gl_texture_image
*prevImage
=
2352 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2353 /* See if the prev level is defined and has an internal format which
2354 * matches the new internal format.
2357 prevImage
->Width
> 0 &&
2358 prevImage
->InternalFormat
== internalFormat
) {
2359 /* use the same format */
2360 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2361 return prevImage
->TexFormat
;
2365 /* choose format from scratch */
2366 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2367 ASSERT(f
!= MESA_FORMAT_NONE
);
2373 * Common code to implement all the glTexImage1D/2D/3D functions.
2376 teximage(struct gl_context
*ctx
, GLuint dims
,
2377 GLenum target
, GLint level
, GLint internalFormat
,
2378 GLsizei width
, GLsizei height
, GLsizei depth
,
2379 GLint border
, GLenum format
, GLenum type
,
2380 const GLvoid
*pixels
)
2384 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2386 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2387 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2389 _mesa_lookup_enum_by_nr(target
), level
,
2390 _mesa_lookup_enum_by_nr(internalFormat
),
2391 width
, height
, depth
, border
,
2392 _mesa_lookup_enum_by_nr(format
),
2393 _mesa_lookup_enum_by_nr(type
), pixels
);
2395 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2397 /* target error checking */
2398 if (!legal_teximage_target(ctx
, dims
, target
)) {
2399 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2400 dims
, _mesa_lookup_enum_by_nr(target
));
2404 /* general error checking */
2405 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2406 format
, type
, width
, height
, depth
, border
);
2408 if (_mesa_is_proxy_texture(target
)) {
2409 /* Proxy texture: just clear or set state depending on error checking */
2410 struct gl_texture_image
*texImage
=
2411 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2414 /* when error, clear all proxy texture image parameters */
2416 clear_teximage_fields(texImage
);
2419 /* no error, set the tex image parameters */
2420 struct gl_texture_object
*texObj
=
2421 _mesa_get_current_tex_object(ctx
, target
);
2422 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2427 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2428 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2429 depth
, border
, internalFormat
,
2432 else if (texImage
) {
2433 clear_teximage_fields(texImage
);
2438 /* non-proxy target */
2439 const GLuint face
= _mesa_tex_target_to_face(target
);
2440 struct gl_texture_object
*texObj
;
2441 struct gl_texture_image
*texImage
;
2444 return; /* error was recorded */
2447 if (ctx
->NewState
& _NEW_PIXEL
)
2448 _mesa_update_state(ctx
);
2450 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2452 _mesa_lock_texture(ctx
, texObj
);
2454 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2457 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2460 gl_format texFormat
;
2462 if (texImage
->Data
) {
2463 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2466 ASSERT(texImage
->Data
== NULL
);
2467 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2468 internalFormat
, format
,
2471 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2472 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2473 width
, height
, depth
,
2474 border
, internalFormat
, texFormat
);
2476 /* Give the texture to the driver. <pixels> may be null. */
2477 ASSERT(ctx
->Driver
.TexImage3D
);
2480 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2481 width
, border
, format
,
2482 type
, pixels
, &ctx
->Unpack
, texObj
,
2486 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2487 width
, height
, border
, format
,
2488 type
, pixels
, &ctx
->Unpack
, texObj
,
2492 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2493 width
, height
, depth
, border
, format
,
2494 type
, pixels
, &ctx
->Unpack
, texObj
,
2498 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2501 check_gen_mipmap(ctx
, target
, texObj
, level
);
2503 update_fbo_texture(ctx
, texObj
, face
, level
);
2506 texObj
->_Complete
= GL_FALSE
;
2507 ctx
->NewState
|= _NEW_TEXTURE
;
2510 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2514 _mesa_unlock_texture(ctx
, texObj
);
2520 * Called from the API. Note that width includes the border.
2523 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2524 GLsizei width
, GLint border
, GLenum format
,
2525 GLenum type
, const GLvoid
*pixels
)
2527 GET_CURRENT_CONTEXT(ctx
);
2528 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2529 border
, format
, type
, pixels
);
2534 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2535 GLsizei width
, GLsizei height
, GLint border
,
2536 GLenum format
, GLenum type
,
2537 const GLvoid
*pixels
)
2539 GET_CURRENT_CONTEXT(ctx
);
2540 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2541 border
, format
, type
, pixels
);
2546 * Called by the API or display list executor.
2547 * Note that width and height include the border.
2550 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2551 GLsizei width
, GLsizei height
, GLsizei depth
,
2552 GLint border
, GLenum format
, GLenum type
,
2553 const GLvoid
*pixels
)
2555 GET_CURRENT_CONTEXT(ctx
);
2556 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2557 border
, format
, type
, pixels
);
2562 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2563 GLsizei width
, GLsizei height
, GLsizei depth
,
2564 GLint border
, GLenum format
, GLenum type
,
2565 const GLvoid
*pixels
)
2567 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2568 depth
, border
, format
, type
, pixels
);
2572 #if FEATURE_OES_EGL_image
2574 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2576 struct gl_texture_object
*texObj
;
2577 struct gl_texture_image
*texImage
;
2578 GET_CURRENT_CONTEXT(ctx
);
2579 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2581 if (!ctx
->Extensions
.OES_EGL_image
) {
2582 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2583 "glEGLImageTargetTexture2DOES(unsupported)");
2587 if (target
!= GL_TEXTURE_2D
) {
2588 _mesa_error(ctx
, GL_INVALID_ENUM
,
2589 "glEGLImageTargetTexture2D(target=%d)", target
);
2593 if (ctx
->NewState
& _NEW_PIXEL
)
2594 _mesa_update_state(ctx
);
2596 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2597 _mesa_lock_texture(ctx
, texObj
);
2599 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2601 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2604 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2606 ASSERT(texImage
->Data
== NULL
);
2607 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2608 texObj
, texImage
, image
);
2611 texObj
->_Complete
= GL_FALSE
;
2612 ctx
->NewState
|= _NEW_TEXTURE
;
2614 _mesa_unlock_texture(ctx
, texObj
);
2622 * Implement all the glTexSubImage1/2/3D() functions.
2625 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2626 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2627 GLsizei width
, GLsizei height
, GLsizei depth
,
2628 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2630 struct gl_texture_object
*texObj
;
2631 struct gl_texture_image
*texImage
;
2633 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2635 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2636 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2638 _mesa_lookup_enum_by_nr(target
), level
,
2639 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2640 _mesa_lookup_enum_by_nr(format
),
2641 _mesa_lookup_enum_by_nr(type
), pixels
);
2643 /* check target (proxies not allowed) */
2644 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2645 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2646 dims
, _mesa_lookup_enum_by_nr(target
));
2650 if (ctx
->NewState
& _NEW_PIXEL
)
2651 _mesa_update_state(ctx
);
2653 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2654 width
, height
, depth
, format
, type
)) {
2655 return; /* error was detected */
2658 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2660 _mesa_lock_texture(ctx
, texObj
);
2662 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2664 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2665 xoffset
, yoffset
, zoffset
,
2666 width
, height
, depth
,
2667 format
, type
, texImage
)) {
2668 /* error was recorded */
2670 else if (width
> 0 && height
> 0 && depth
> 0) {
2671 /* If we have a border, offset=-1 is legal. Bias by border width. */
2674 zoffset
+= texImage
->Border
;
2677 yoffset
+= texImage
->Border
;
2680 xoffset
+= texImage
->Border
;
2685 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2687 format
, type
, pixels
,
2688 &ctx
->Unpack
, texObj
, texImage
);
2691 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2692 xoffset
, yoffset
, width
, height
,
2693 format
, type
, pixels
,
2694 &ctx
->Unpack
, texObj
, texImage
);
2697 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2698 xoffset
, yoffset
, zoffset
,
2699 width
, height
, depth
,
2700 format
, type
, pixels
,
2701 &ctx
->Unpack
, texObj
, texImage
);
2704 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2707 check_gen_mipmap(ctx
, target
, texObj
, level
);
2709 ctx
->NewState
|= _NEW_TEXTURE
;
2712 _mesa_unlock_texture(ctx
, texObj
);
2717 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2718 GLint xoffset
, GLsizei width
,
2719 GLenum format
, GLenum type
,
2720 const GLvoid
*pixels
)
2722 GET_CURRENT_CONTEXT(ctx
);
2723 texsubimage(ctx
, 1, target
, level
,
2726 format
, type
, pixels
);
2731 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2732 GLint xoffset
, GLint yoffset
,
2733 GLsizei width
, GLsizei height
,
2734 GLenum format
, GLenum type
,
2735 const GLvoid
*pixels
)
2737 GET_CURRENT_CONTEXT(ctx
);
2738 texsubimage(ctx
, 2, target
, level
,
2739 xoffset
, yoffset
, 0,
2741 format
, type
, pixels
);
2747 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2748 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2749 GLsizei width
, GLsizei height
, GLsizei depth
,
2750 GLenum format
, GLenum type
,
2751 const GLvoid
*pixels
)
2753 GET_CURRENT_CONTEXT(ctx
);
2754 texsubimage(ctx
, 3, target
, level
,
2755 xoffset
, yoffset
, zoffset
,
2756 width
, height
, depth
,
2757 format
, type
, pixels
);
2763 * Implement the glCopyTexImage1/2D() functions.
2766 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2767 GLenum target
, GLint level
, GLenum internalFormat
,
2768 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2770 struct gl_texture_object
*texObj
;
2771 struct gl_texture_image
*texImage
;
2772 const GLuint face
= _mesa_tex_target_to_face(target
);
2774 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2776 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2777 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2779 _mesa_lookup_enum_by_nr(target
), level
,
2780 _mesa_lookup_enum_by_nr(internalFormat
),
2781 x
, y
, width
, height
, border
);
2783 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2784 _mesa_update_state(ctx
);
2786 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2787 width
, height
, border
))
2790 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2792 _mesa_lock_texture(ctx
, texObj
);
2794 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2797 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2800 gl_format texFormat
;
2802 if (texImage
->Data
) {
2803 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2806 ASSERT(texImage
->Data
== NULL
);
2808 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2809 internalFormat
, GL_NONE
,
2812 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2813 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2814 border
, internalFormat
, texFormat
);
2816 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2818 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2819 x
, y
, width
, border
);
2821 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2822 x
, y
, width
, height
, border
);
2824 check_gen_mipmap(ctx
, target
, texObj
, level
);
2826 update_fbo_texture(ctx
, texObj
, face
, level
);
2829 texObj
->_Complete
= GL_FALSE
;
2830 ctx
->NewState
|= _NEW_TEXTURE
;
2833 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2837 _mesa_unlock_texture(ctx
, texObj
);
2843 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2844 GLenum internalFormat
,
2846 GLsizei width
, GLint border
)
2848 GET_CURRENT_CONTEXT(ctx
);
2849 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2855 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2856 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2859 GET_CURRENT_CONTEXT(ctx
);
2860 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2861 x
, y
, width
, height
, border
);
2867 * Implementation for glCopyTexSubImage1/2/3D() functions.
2870 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2871 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2872 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2874 struct gl_texture_object
*texObj
;
2875 struct gl_texture_image
*texImage
;
2877 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2879 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2880 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2882 _mesa_lookup_enum_by_nr(target
),
2883 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2885 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2886 _mesa_update_state(ctx
);
2888 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2891 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2893 _mesa_lock_texture(ctx
, texObj
);
2895 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2897 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2898 zoffset
, width
, height
, texImage
)) {
2899 /* error was recored */
2902 /* If we have a border, offset=-1 is legal. Bias by border width. */
2905 zoffset
+= texImage
->Border
;
2908 yoffset
+= texImage
->Border
;
2911 xoffset
+= texImage
->Border
;
2914 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2918 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2919 xoffset
, x
, y
, width
);
2922 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2924 x
, y
, width
, height
);
2927 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2928 xoffset
, yoffset
, zoffset
,
2929 x
, y
, width
, height
);
2932 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
2935 check_gen_mipmap(ctx
, target
, texObj
, level
);
2937 ctx
->NewState
|= _NEW_TEXTURE
;
2941 _mesa_unlock_texture(ctx
, texObj
);
2946 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2947 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2949 GET_CURRENT_CONTEXT(ctx
);
2950 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
2956 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2957 GLint xoffset
, GLint yoffset
,
2958 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2960 GET_CURRENT_CONTEXT(ctx
);
2961 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
2968 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2969 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2970 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2972 GET_CURRENT_CONTEXT(ctx
);
2973 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2974 x
, y
, width
, height
);
2980 /**********************************************************************/
2981 /****** Compressed Textures ******/
2982 /**********************************************************************/
2986 * Return expected size of a compressed texture.
2989 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2992 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2993 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2998 * Return compressed texture block size, in pixels.
3001 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3003 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3004 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3009 * Error checking for glCompressedTexImage[123]D().
3010 * \param reason returns reason for error, if any
3011 * \return error code or GL_NO_ERROR.
3014 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3015 GLenum target
, GLint level
,
3016 GLenum internalFormat
, GLsizei width
,
3017 GLsizei height
, GLsizei depth
, GLint border
,
3018 GLsizei imageSize
, char **reason
)
3020 const GLenum proxyTarget
= get_proxy_target(target
);
3021 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3024 *reason
= ""; /* no error */
3027 if (level
< 0 || level
>= maxLevels
) {
3029 return GL_INVALID_VALUE
;
3032 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3034 return GL_INVALID_ENUM
;
3037 /* This will detect any invalid internalFormat value */
3038 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3039 *reason
= "internalFormat";
3040 return GL_INVALID_ENUM
;
3043 /* This should really never fail */
3044 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3045 *reason
= "internalFormat";
3046 return GL_INVALID_ENUM
;
3049 /* No compressed formats support borders at this time */
3051 *reason
= "border != 0";
3052 return GL_INVALID_VALUE
;
3055 /* For cube map, width must equal height */
3056 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3057 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
) {
3058 *reason
= "width != height";
3059 return GL_INVALID_VALUE
;
3062 /* check image size against compression block size */
3064 gl_format texFormat
=
3065 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3069 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3070 if ((width
> bw
&& width
% bw
> 0) ||
3071 (height
> bh
&& height
% bh
> 0)) {
3073 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3074 * generated [...] if any parameter combinations are not
3075 * supported by the specific compressed internal format.
3077 *reason
= "invalid width or height for compression format";
3078 return GL_INVALID_OPERATION
;
3082 /* check image sizes */
3083 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3084 internalFormat
, GL_NONE
, GL_NONE
,
3085 width
, height
, depth
, border
)) {
3086 /* See error comment above */
3087 *reason
= "invalid width, height or format";
3088 return GL_INVALID_OPERATION
;
3091 /* check image size in bytes */
3092 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3093 if (expectedSize
!= imageSize
) {
3094 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3095 * if <imageSize> is not consistent with the format, dimensions, and
3096 * contents of the specified image.
3098 *reason
= "imageSize inconsistant with width/height/format";
3099 return GL_INVALID_VALUE
;
3107 * Error checking for glCompressedTexSubImage[123]D().
3108 * \warning There are some bad assumptions here about the size of compressed
3109 * texture tiles (multiple of 4) used to test the validity of the
3110 * offset and size parameters.
3111 * \return error code or GL_NO_ERROR.
3114 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3115 GLenum target
, GLint level
,
3116 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3117 GLsizei width
, GLsizei height
, GLsizei depth
,
3118 GLenum format
, GLsizei imageSize
)
3120 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3124 if (dimensions
== 1) {
3125 /* 1D compressed textures not allowed */
3126 return GL_INVALID_ENUM
;
3128 else if (dimensions
== 2) {
3129 if (target
== GL_PROXY_TEXTURE_2D
) {
3130 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3132 else if (target
== GL_TEXTURE_2D
) {
3133 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3135 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3136 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3137 return GL_INVALID_ENUM
; /*target*/
3138 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3140 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3141 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3142 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3143 return GL_INVALID_ENUM
; /*target*/
3144 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3147 return GL_INVALID_ENUM
; /*target*/
3150 else if (dimensions
== 3) {
3151 /* 3D compressed textures not allowed */
3152 return GL_INVALID_ENUM
;
3155 maxTextureSize
= 1 << (maxLevels
- 1);
3157 /* this will catch any invalid compressed format token */
3158 if (!_mesa_is_compressed_format(ctx
, format
))
3159 return GL_INVALID_ENUM
;
3161 if (width
< 1 || width
> maxTextureSize
)
3162 return GL_INVALID_VALUE
;
3164 if ((height
< 1 || height
> maxTextureSize
)
3166 return GL_INVALID_VALUE
;
3168 if (level
< 0 || level
>= maxLevels
)
3169 return GL_INVALID_VALUE
;
3172 * do checks which depend on compression block size
3174 get_compressed_block_size(format
, &bw
, &bh
);
3176 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3177 return GL_INVALID_VALUE
;
3179 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3180 return GL_INVALID_VALUE
;
3182 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3183 return GL_INVALID_VALUE
;
3185 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3186 if (expectedSize
!= imageSize
)
3187 return GL_INVALID_VALUE
;
3194 * Do second part of glCompressedTexSubImage error checking.
3195 * \return GL_TRUE if error found, GL_FALSE otherwise.
3198 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3199 GLsizei width
, GLsizei height
,
3200 GLsizei depth
, GLenum format
,
3201 struct gl_texture_image
*texImage
)
3204 if ((GLint
) format
!= texImage
->InternalFormat
) {
3205 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3206 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3210 if (((width
== 1 || width
== 2) &&
3211 width
!= (GLsizei
) texImage
->Width
) ||
3212 (width
> (GLsizei
) texImage
->Width
)) {
3213 _mesa_error(ctx
, GL_INVALID_VALUE
,
3214 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3219 if (((height
== 1 || height
== 2) &&
3220 height
!= (GLsizei
) texImage
->Height
) ||
3221 (height
> (GLsizei
) texImage
->Height
)) {
3222 _mesa_error(ctx
, GL_INVALID_VALUE
,
3223 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3229 if (((depth
== 1 || depth
== 2) &&
3230 depth
!= (GLsizei
) texImage
->Depth
) ||
3231 (depth
> (GLsizei
) texImage
->Depth
)) {
3232 _mesa_error(ctx
, GL_INVALID_VALUE
,
3233 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3243 * Implementation of the glCompressedTexImage1/2/3D() functions.
3246 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3247 GLenum target
, GLint level
,
3248 GLenum internalFormat
, GLsizei width
,
3249 GLsizei height
, GLsizei depth
, GLint border
,
3250 GLsizei imageSize
, const GLvoid
*data
)
3255 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3257 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3259 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3261 _mesa_lookup_enum_by_nr(target
), level
,
3262 _mesa_lookup_enum_by_nr(internalFormat
),
3263 width
, height
, depth
, border
, imageSize
, data
);
3266 if (!legal_teximage_target(ctx
, dims
, target
)) {
3267 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3268 dims
, _mesa_lookup_enum_by_nr(target
));
3272 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3273 internalFormat
, width
, height
, depth
,
3274 border
, imageSize
, &reason
);
3277 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3282 /* XXX this is kind of a hack */
3284 switch (internalFormat
) {
3285 case GL_PALETTE4_RGB8_OES
:
3286 case GL_PALETTE4_RGBA8_OES
:
3287 case GL_PALETTE4_R5_G6_B5_OES
:
3288 case GL_PALETTE4_RGBA4_OES
:
3289 case GL_PALETTE4_RGB5_A1_OES
:
3290 case GL_PALETTE8_RGB8_OES
:
3291 case GL_PALETTE8_RGBA8_OES
:
3292 case GL_PALETTE8_R5_G6_B5_OES
:
3293 case GL_PALETTE8_RGBA4_OES
:
3294 case GL_PALETTE8_RGB5_A1_OES
:
3295 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3296 width
, height
, imageSize
, data
);
3302 if (_mesa_is_proxy_texture(target
)) {
3303 /* Proxy texture: just check for errors and update proxy state */
3304 struct gl_texture_image
*texImage
;
3307 struct gl_texture_object
*texObj
=
3308 _mesa_get_current_tex_object(ctx
, target
);
3309 gl_format texFormat
=
3310 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3311 internalFormat
, GL_NONE
, GL_NONE
);
3312 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3313 error
= GL_OUT_OF_MEMORY
;
3317 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3320 /* if error, clear all proxy texture image parameters */
3321 clear_teximage_fields(texImage
);
3324 /* no error: store the teximage parameters */
3325 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3326 depth
, border
, internalFormat
,
3332 /* non-proxy target */
3333 struct gl_texture_object
*texObj
;
3334 struct gl_texture_image
*texImage
;
3337 _mesa_error(ctx
, error
, "glCompressedTexImage%uD", dims
);
3341 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3343 _mesa_lock_texture(ctx
, texObj
);
3345 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3347 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3348 "glCompressedTexImage%uD", dims
);
3351 gl_format texFormat
;
3353 if (texImage
->Data
) {
3354 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3356 ASSERT(texImage
->Data
== NULL
);
3358 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3359 internalFormat
, GL_NONE
,
3362 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3363 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3364 width
, height
, depth
,
3365 border
, internalFormat
, texFormat
);
3369 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3370 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3373 border
, imageSize
, data
,
3377 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3378 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3381 border
, imageSize
, data
,
3385 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3386 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3388 width
, height
, depth
,
3389 border
, imageSize
, data
,
3393 _mesa_problem(ctx
, "bad dims in compressedteximage");
3396 check_gen_mipmap(ctx
, target
, texObj
, level
);
3399 texObj
->_Complete
= GL_FALSE
;
3400 ctx
->NewState
|= _NEW_TEXTURE
;
3403 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3404 "glCompressedTexImage%uD", dims
);
3408 _mesa_unlock_texture(ctx
, texObj
);
3414 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3415 GLenum internalFormat
, GLsizei width
,
3416 GLint border
, GLsizei imageSize
,
3419 GET_CURRENT_CONTEXT(ctx
);
3420 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3421 width
, 1, 1, border
, imageSize
, data
);
3426 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3427 GLenum internalFormat
, GLsizei width
,
3428 GLsizei height
, GLint border
, GLsizei imageSize
,
3431 GET_CURRENT_CONTEXT(ctx
);
3432 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3433 width
, height
, 1, border
, imageSize
, data
);
3438 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3439 GLenum internalFormat
, GLsizei width
,
3440 GLsizei height
, GLsizei depth
, GLint border
,
3441 GLsizei imageSize
, const GLvoid
*data
)
3443 GET_CURRENT_CONTEXT(ctx
);
3444 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3445 width
, height
, depth
, border
, imageSize
, data
);
3450 * Common helper for glCompressedTexSubImage1/2/3D().
3453 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3454 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3455 GLsizei width
, GLsizei height
, GLsizei depth
,
3456 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3458 struct gl_texture_object
*texObj
;
3459 struct gl_texture_image
*texImage
;
3461 GET_CURRENT_CONTEXT(ctx
);
3462 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3464 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3465 xoffset
, 0, 0, /* pos */
3466 width
, height
, depth
, /* size */
3469 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3473 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3475 _mesa_lock_texture(ctx
, texObj
);
3477 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3480 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3481 format
, texImage
)) {
3482 /* error was recorded */
3484 else if (width
> 0 && height
> 0 && depth
> 0) {
3487 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3488 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3490 format
, imageSize
, data
,
3495 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3496 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3499 format
, imageSize
, data
,
3504 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3505 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3506 xoffset
, yoffset
, zoffset
,
3507 width
, height
, depth
,
3508 format
, imageSize
, data
,
3516 check_gen_mipmap(ctx
, target
, texObj
, level
);
3518 ctx
->NewState
|= _NEW_TEXTURE
;
3521 _mesa_unlock_texture(ctx
, texObj
);
3526 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3527 GLsizei width
, GLenum format
,
3528 GLsizei imageSize
, const GLvoid
*data
)
3530 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3531 format
, imageSize
, data
);
3536 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3537 GLint yoffset
, GLsizei width
, GLsizei height
,
3538 GLenum format
, GLsizei imageSize
,
3541 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3542 width
, height
, 1, format
, imageSize
, data
);
3547 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3548 GLint yoffset
, GLint zoffset
, GLsizei width
,
3549 GLsizei height
, GLsizei depth
, GLenum format
,
3550 GLsizei imageSize
, const GLvoid
*data
)
3552 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3553 width
, height
, depth
, format
, imageSize
, data
);
3558 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3559 * return the basic data type and number of components for the format.
3560 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3563 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3564 GLenum
*datatype
, GLuint
*components
)
3566 switch (internalFormat
) {
3568 *datatype
= GL_UNSIGNED_BYTE
;
3572 *datatype
= GL_UNSIGNED_SHORT
;
3575 case GL_ALPHA16F_ARB
:
3576 *datatype
= GL_HALF_FLOAT
;
3579 case GL_ALPHA32F_ARB
:
3580 *datatype
= GL_FLOAT
;
3583 case GL_ALPHA8I_EXT
:
3584 *datatype
= GL_BYTE
;
3587 case GL_ALPHA16I_EXT
:
3588 *datatype
= GL_SHORT
;
3591 case GL_ALPHA32I_EXT
:
3595 case GL_ALPHA8UI_EXT
:
3596 *datatype
= GL_UNSIGNED_BYTE
;
3599 case GL_ALPHA16UI_EXT
:
3600 *datatype
= GL_UNSIGNED_SHORT
;
3603 case GL_ALPHA32UI_EXT
:
3604 *datatype
= GL_UNSIGNED_INT
;
3608 *datatype
= GL_UNSIGNED_BYTE
;
3611 case GL_LUMINANCE16
:
3612 *datatype
= GL_UNSIGNED_SHORT
;
3615 case GL_LUMINANCE16F_ARB
:
3616 *datatype
= GL_HALF_FLOAT
;
3619 case GL_LUMINANCE32F_ARB
:
3620 *datatype
= GL_FLOAT
;
3623 case GL_LUMINANCE8I_EXT
:
3624 *datatype
= GL_BYTE
;
3627 case GL_LUMINANCE16I_EXT
:
3628 *datatype
= GL_SHORT
;
3631 case GL_LUMINANCE32I_EXT
:
3635 case GL_LUMINANCE8UI_EXT
:
3636 *datatype
= GL_UNSIGNED_BYTE
;
3639 case GL_LUMINANCE16UI_EXT
:
3640 *datatype
= GL_UNSIGNED_SHORT
;
3643 case GL_LUMINANCE32UI_EXT
:
3644 *datatype
= GL_UNSIGNED_INT
;
3647 case GL_LUMINANCE8_ALPHA8
:
3648 *datatype
= GL_UNSIGNED_BYTE
;
3651 case GL_LUMINANCE16_ALPHA16
:
3652 *datatype
= GL_UNSIGNED_SHORT
;
3655 case GL_LUMINANCE_ALPHA16F_ARB
:
3656 *datatype
= GL_HALF_FLOAT
;
3659 case GL_LUMINANCE_ALPHA32F_ARB
:
3660 *datatype
= GL_FLOAT
;
3663 case GL_LUMINANCE_ALPHA8I_EXT
:
3664 *datatype
= GL_BYTE
;
3667 case GL_LUMINANCE_ALPHA16I_EXT
:
3668 *datatype
= GL_SHORT
;
3671 case GL_LUMINANCE_ALPHA32I_EXT
:
3675 case GL_LUMINANCE_ALPHA8UI_EXT
:
3676 *datatype
= GL_UNSIGNED_BYTE
;
3679 case GL_LUMINANCE_ALPHA16UI_EXT
:
3680 *datatype
= GL_UNSIGNED_SHORT
;
3683 case GL_LUMINANCE_ALPHA32UI_EXT
:
3684 *datatype
= GL_UNSIGNED_INT
;
3688 *datatype
= GL_UNSIGNED_BYTE
;
3691 case GL_INTENSITY16
:
3692 *datatype
= GL_UNSIGNED_SHORT
;
3695 case GL_INTENSITY16F_ARB
:
3696 *datatype
= GL_HALF_FLOAT
;
3699 case GL_INTENSITY32F_ARB
:
3700 *datatype
= GL_FLOAT
;
3703 case GL_INTENSITY8I_EXT
:
3704 *datatype
= GL_BYTE
;
3707 case GL_INTENSITY16I_EXT
:
3708 *datatype
= GL_SHORT
;
3711 case GL_INTENSITY32I_EXT
:
3715 case GL_INTENSITY8UI_EXT
:
3716 *datatype
= GL_UNSIGNED_BYTE
;
3719 case GL_INTENSITY16UI_EXT
:
3720 *datatype
= GL_UNSIGNED_SHORT
;
3723 case GL_INTENSITY32UI_EXT
:
3724 *datatype
= GL_UNSIGNED_INT
;
3728 *datatype
= GL_UNSIGNED_BYTE
;
3732 *datatype
= GL_UNSIGNED_SHORT
;
3735 case GL_RGBA16F_ARB
:
3736 *datatype
= GL_HALF_FLOAT
;
3739 case GL_RGBA32F_ARB
:
3740 *datatype
= GL_FLOAT
;
3744 *datatype
= GL_BYTE
;
3747 case GL_RGBA16I_EXT
:
3748 *datatype
= GL_SHORT
;
3751 case GL_RGBA32I_EXT
:
3755 case GL_RGBA8UI_EXT
:
3756 *datatype
= GL_UNSIGNED_BYTE
;
3759 case GL_RGBA16UI_EXT
:
3760 *datatype
= GL_UNSIGNED_SHORT
;
3763 case GL_RGBA32UI_EXT
:
3764 *datatype
= GL_UNSIGNED_INT
;
3771 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3774 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3781 /** GL_ARB_texture_buffer_object */
3783 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3785 struct gl_texture_object
*texObj
;
3786 struct gl_buffer_object
*bufObj
;
3790 GET_CURRENT_CONTEXT(ctx
);
3791 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3793 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3794 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3798 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3799 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3803 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3804 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3809 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3810 if (buffer
&& !bufObj
) {
3811 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3815 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3817 _mesa_lock_texture(ctx
, texObj
);
3819 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3820 texObj
->BufferObjectFormat
= internalFormat
;
3822 _mesa_unlock_texture(ctx
, texObj
);