2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "mfeatures.h"
44 #include "texcompress.h"
52 * State changes which we care about for glCopyTex[Sub]Image() calls.
53 * In particular, we care about pixel transfer state and buffer state
54 * (such as glReadBuffer to make sure we read from the right renderbuffer).
56 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
61 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
65 _mesa_alloc_texmemory(GLsizei bytes
)
67 return _mesa_align_malloc(bytes
, 512);
72 * Free texture memory allocated with _mesa_alloc_texmemory()
75 _mesa_free_texmemory(void *m
)
82 * Return the simple base format for a given internal texture format.
83 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
85 * \param ctx GL context.
86 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
88 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
89 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
91 * This is the format which is used during texture application (i.e. the
92 * texture format and env mode determine the arithmetic used.
94 * XXX this could be static
97 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
99 switch (internalFormat
) {
114 case GL_LUMINANCE_ALPHA
:
115 case GL_LUMINANCE4_ALPHA4
:
116 case GL_LUMINANCE6_ALPHA2
:
117 case GL_LUMINANCE8_ALPHA8
:
118 case GL_LUMINANCE12_ALPHA4
:
119 case GL_LUMINANCE12_ALPHA12
:
120 case GL_LUMINANCE16_ALPHA16
:
121 return GL_LUMINANCE_ALPHA
;
152 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
154 if (ctx
->API
!= API_OPENGL
) {
155 switch (internalFormat
) {
163 if (ctx
->Extensions
.ARB_depth_texture
) {
164 switch (internalFormat
) {
165 case GL_DEPTH_COMPONENT
:
166 case GL_DEPTH_COMPONENT16
:
167 case GL_DEPTH_COMPONENT24
:
168 case GL_DEPTH_COMPONENT32
:
169 return GL_DEPTH_COMPONENT
;
175 switch (internalFormat
) {
176 case GL_COMPRESSED_ALPHA
:
178 case GL_COMPRESSED_LUMINANCE
:
180 case GL_COMPRESSED_LUMINANCE_ALPHA
:
181 return GL_LUMINANCE_ALPHA
;
182 case GL_COMPRESSED_INTENSITY
:
184 case GL_COMPRESSED_RGB
:
186 case GL_COMPRESSED_RGBA
:
192 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
193 switch (internalFormat
) {
194 case GL_COMPRESSED_RGB_FXT1_3DFX
:
196 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
203 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
204 switch (internalFormat
) {
205 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
207 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
208 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
209 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
216 if (ctx
->Extensions
.S3_s3tc
) {
217 switch (internalFormat
) {
229 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
230 if (internalFormat
== GL_YCBCR_MESA
)
231 return GL_YCBCR_MESA
;
234 if (ctx
->Extensions
.ARB_texture_float
) {
235 switch (internalFormat
) {
236 case GL_ALPHA16F_ARB
:
237 case GL_ALPHA32F_ARB
:
245 case GL_INTENSITY16F_ARB
:
246 case GL_INTENSITY32F_ARB
:
248 case GL_LUMINANCE16F_ARB
:
249 case GL_LUMINANCE32F_ARB
:
251 case GL_LUMINANCE_ALPHA16F_ARB
:
252 case GL_LUMINANCE_ALPHA32F_ARB
:
253 return GL_LUMINANCE_ALPHA
;
259 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
260 switch (internalFormat
) {
269 if (ctx
->Extensions
.EXT_texture_snorm
) {
270 switch (internalFormat
) {
285 case GL_RGBA16_SNORM
:
288 case GL_ALPHA8_SNORM
:
289 case GL_ALPHA16_SNORM
:
291 case GL_LUMINANCE_SNORM
:
292 case GL_LUMINANCE8_SNORM
:
293 case GL_LUMINANCE16_SNORM
:
295 case GL_LUMINANCE_ALPHA_SNORM
:
296 case GL_LUMINANCE8_ALPHA8_SNORM
:
297 case GL_LUMINANCE16_ALPHA16_SNORM
:
298 return GL_LUMINANCE_ALPHA
;
299 case GL_INTENSITY_SNORM
:
300 case GL_INTENSITY8_SNORM
:
301 case GL_INTENSITY16_SNORM
:
308 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
309 switch (internalFormat
) {
310 case GL_DEPTH_STENCIL_EXT
:
311 case GL_DEPTH24_STENCIL8_EXT
:
312 return GL_DEPTH_STENCIL_EXT
;
318 #if FEATURE_EXT_texture_sRGB
319 if (ctx
->Extensions
.EXT_texture_sRGB
) {
320 switch (internalFormat
) {
323 case GL_COMPRESSED_SRGB_EXT
:
324 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
326 case GL_SRGB_ALPHA_EXT
:
327 case GL_SRGB8_ALPHA8_EXT
:
328 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
329 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
330 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
331 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
333 case GL_SLUMINANCE_ALPHA_EXT
:
334 case GL_SLUMINANCE8_ALPHA8_EXT
:
335 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
336 return GL_LUMINANCE_ALPHA
;
337 case GL_SLUMINANCE_EXT
:
338 case GL_SLUMINANCE8_EXT
:
339 case GL_COMPRESSED_SLUMINANCE_EXT
:
345 #endif /* FEATURE_EXT_texture_sRGB */
347 if (ctx
->Extensions
.EXT_texture_integer
) {
348 switch (internalFormat
) {
350 case GL_RGBA16UI_EXT
:
351 case GL_RGBA32UI_EXT
:
363 case GL_ALPHA8UI_EXT
:
364 case GL_ALPHA16UI_EXT
:
365 case GL_ALPHA32UI_EXT
:
367 case GL_ALPHA16I_EXT
:
368 case GL_ALPHA32I_EXT
:
370 case GL_INTENSITY8UI_EXT
:
371 case GL_INTENSITY16UI_EXT
:
372 case GL_INTENSITY32UI_EXT
:
373 case GL_INTENSITY8I_EXT
:
374 case GL_INTENSITY16I_EXT
:
375 case GL_INTENSITY32I_EXT
:
377 case GL_LUMINANCE8UI_EXT
:
378 case GL_LUMINANCE16UI_EXT
:
379 case GL_LUMINANCE32UI_EXT
:
380 case GL_LUMINANCE8I_EXT
:
381 case GL_LUMINANCE16I_EXT
:
382 case GL_LUMINANCE32I_EXT
:
384 case GL_LUMINANCE_ALPHA8UI_EXT
:
385 case GL_LUMINANCE_ALPHA16UI_EXT
:
386 case GL_LUMINANCE_ALPHA32UI_EXT
:
387 case GL_LUMINANCE_ALPHA8I_EXT
:
388 case GL_LUMINANCE_ALPHA16I_EXT
:
389 case GL_LUMINANCE_ALPHA32I_EXT
:
390 return GL_LUMINANCE_ALPHA
;
396 if (ctx
->Extensions
.ARB_texture_rg
) {
397 switch (internalFormat
) {
399 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
401 if (!ctx
->Extensions
.ARB_half_float_pixel
)
405 if (!ctx
->Extensions
.ARB_texture_float
)
414 if (!ctx
->Extensions
.EXT_texture_integer
)
420 case GL_COMPRESSED_RED
:
424 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
426 if (!ctx
->Extensions
.ARB_half_float_pixel
)
430 if (!ctx
->Extensions
.ARB_texture_float
)
439 if (!ctx
->Extensions
.EXT_texture_integer
)
445 case GL_COMPRESSED_RG
:
452 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
453 switch (internalFormat
) {
461 if (ctx
->Extensions
.EXT_packed_float
) {
462 switch (internalFormat
) {
463 case GL_R11F_G11F_B10F_EXT
:
470 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
471 switch (internalFormat
) {
472 case GL_DEPTH_COMPONENT32F
:
473 return GL_DEPTH_COMPONENT
;
474 case GL_DEPTH32F_STENCIL8
:
475 return GL_DEPTH_STENCIL
;
481 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
482 switch (internalFormat
) {
483 case GL_COMPRESSED_RED_RGTC1
:
484 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
486 case GL_COMPRESSED_RG_RGTC2
:
487 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
494 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
495 switch (internalFormat
) {
496 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
497 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
499 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
500 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
501 return GL_LUMINANCE_ALPHA
;
507 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
508 switch (internalFormat
) {
509 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
510 return GL_LUMINANCE_ALPHA
;
516 if (ctx
->API
== API_OPENGLES
) {
517 switch (internalFormat
) {
518 case GL_PALETTE4_RGB8_OES
:
519 case GL_PALETTE4_R5_G6_B5_OES
:
520 case GL_PALETTE8_RGB8_OES
:
521 case GL_PALETTE8_R5_G6_B5_OES
:
523 case GL_PALETTE4_RGBA8_OES
:
524 case GL_PALETTE8_RGB5_A1_OES
:
525 case GL_PALETTE4_RGBA4_OES
:
526 case GL_PALETTE4_RGB5_A1_OES
:
527 case GL_PALETTE8_RGBA8_OES
:
528 case GL_PALETTE8_RGBA4_OES
:
535 return -1; /* error */
540 * For cube map faces, return a face index in [0,5].
541 * For other targets return 0;
544 _mesa_tex_target_to_face(GLenum target
)
546 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
547 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
548 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
556 * Store a gl_texture_image pointer in a gl_texture_object structure
557 * according to the target and level parameters.
559 * \param tObj texture object.
560 * \param target texture target.
561 * \param level image level.
562 * \param texImage texture image.
565 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
566 GLenum target
, GLint level
,
567 struct gl_texture_image
*texImage
)
569 const GLuint face
= _mesa_tex_target_to_face(target
);
573 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
575 tObj
->Image
[face
][level
] = texImage
;
577 /* Set the 'back' pointer */
578 texImage
->TexObject
= tObj
;
579 texImage
->Level
= level
;
580 texImage
->Face
= face
;
585 * Allocate a texture image structure.
587 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
590 * \return a pointer to gl_texture_image struct with all fields initialized to
593 struct gl_texture_image
*
594 _mesa_new_texture_image( struct gl_context
*ctx
)
597 return CALLOC_STRUCT(gl_texture_image
);
602 * Free texture image data.
603 * This function is a fallback called via ctx->Driver.FreeTextureImageBuffer().
605 * \param texImage texture image.
607 * Free the texture image data if it's not marked as client data.
610 _mesa_free_texture_image_data(struct gl_context
*ctx
,
611 struct gl_texture_image
*texImage
)
616 if (texImage
->Data
) {
617 /* free the old texture data */
618 _mesa_free_texmemory(texImage
->Data
);
621 texImage
->Data
= NULL
;
627 * Free a gl_texture_image and associated data.
628 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
630 * \param texImage texture image.
632 * Free the texture image structure and the associated image data.
635 _mesa_delete_texture_image(struct gl_context
*ctx
,
636 struct gl_texture_image
*texImage
)
638 /* Free texImage->Data and/or any other driver-specific texture
641 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
642 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
645 ASSERT(texImage
->Data
== NULL
);
646 if (texImage
->ImageOffsets
)
647 free(texImage
->ImageOffsets
);
654 * Test if a target is a proxy target.
656 * \param target texture target.
658 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
661 _mesa_is_proxy_texture(GLenum target
)
663 /* NUM_TEXTURE_TARGETS should match number of terms below,
664 * except there's no proxy for GL_TEXTURE_BUFFER.
666 assert(NUM_TEXTURE_TARGETS
== 8);
668 return (target
== GL_PROXY_TEXTURE_1D
||
669 target
== GL_PROXY_TEXTURE_2D
||
670 target
== GL_PROXY_TEXTURE_3D
||
671 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
672 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
673 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
674 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
679 * Return the proxy target which corresponds to the given texture target
682 get_proxy_target(GLenum target
)
686 case GL_PROXY_TEXTURE_1D
:
687 return GL_PROXY_TEXTURE_1D
;
689 case GL_PROXY_TEXTURE_2D
:
690 return GL_PROXY_TEXTURE_2D
;
692 case GL_PROXY_TEXTURE_3D
:
693 return GL_PROXY_TEXTURE_3D
;
694 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
695 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
696 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
697 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
698 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
699 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
700 case GL_TEXTURE_CUBE_MAP_ARB
:
701 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
702 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
703 case GL_TEXTURE_RECTANGLE_NV
:
704 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
705 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
706 case GL_TEXTURE_1D_ARRAY_EXT
:
707 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
708 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
709 case GL_TEXTURE_2D_ARRAY_EXT
:
710 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
711 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
713 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
720 * Get the texture object that corresponds to the target of the given
721 * texture unit. The target should have already been checked for validity.
723 * \param ctx GL context.
724 * \param texUnit texture unit.
725 * \param target texture target.
727 * \return pointer to the texture object on success, or NULL on failure.
729 struct gl_texture_object
*
730 _mesa_select_tex_object(struct gl_context
*ctx
,
731 const struct gl_texture_unit
*texUnit
,
734 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
735 ctx
->Extensions
.EXT_texture_array
);
739 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
740 case GL_PROXY_TEXTURE_1D
:
741 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
743 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
744 case GL_PROXY_TEXTURE_2D
:
745 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
747 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
748 case GL_PROXY_TEXTURE_3D
:
749 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
750 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
751 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
752 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
753 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
754 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
755 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
756 case GL_TEXTURE_CUBE_MAP_ARB
:
757 return ctx
->Extensions
.ARB_texture_cube_map
758 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
759 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
760 return ctx
->Extensions
.ARB_texture_cube_map
761 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
762 case GL_TEXTURE_RECTANGLE_NV
:
763 return ctx
->Extensions
.NV_texture_rectangle
764 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
765 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
766 return ctx
->Extensions
.NV_texture_rectangle
767 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
768 case GL_TEXTURE_1D_ARRAY_EXT
:
769 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
770 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
771 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
772 case GL_TEXTURE_2D_ARRAY_EXT
:
773 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
774 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
775 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
776 case GL_TEXTURE_BUFFER
:
777 return ctx
->Extensions
.ARB_texture_buffer_object
778 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
780 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
787 * Return pointer to texture object for given target on current texture unit.
789 struct gl_texture_object
*
790 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
792 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
793 return _mesa_select_tex_object(ctx
, texUnit
, target
);
798 * Get a texture image pointer from a texture object, given a texture
799 * target and mipmap level. The target and level parameters should
800 * have already been error-checked.
802 * \param ctx GL context.
803 * \param texObj texture unit.
804 * \param target texture target.
805 * \param level image level.
807 * \return pointer to the texture image structure, or NULL on failure.
809 struct gl_texture_image
*
810 _mesa_select_tex_image(struct gl_context
*ctx
,
811 const struct gl_texture_object
*texObj
,
812 GLenum target
, GLint level
)
814 const GLuint face
= _mesa_tex_target_to_face(target
);
818 ASSERT(level
< MAX_TEXTURE_LEVELS
);
820 return texObj
->Image
[face
][level
];
825 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
826 * it and install it. Only return NULL if passed a bad parameter or run
829 struct gl_texture_image
*
830 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
831 GLenum target
, GLint level
)
833 struct gl_texture_image
*texImage
;
838 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
840 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
842 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
846 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
854 * Return pointer to the specified proxy texture image.
855 * Note that proxy textures are per-context, not per-texture unit.
856 * \return pointer to texture image or NULL if invalid target, invalid
857 * level, or out of memory.
859 struct gl_texture_image
*
860 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
862 struct gl_texture_image
*texImage
;
869 case GL_PROXY_TEXTURE_1D
:
870 if (level
>= ctx
->Const
.MaxTextureLevels
)
872 texIndex
= TEXTURE_1D_INDEX
;
874 case GL_PROXY_TEXTURE_2D
:
875 if (level
>= ctx
->Const
.MaxTextureLevels
)
877 texIndex
= TEXTURE_2D_INDEX
;
879 case GL_PROXY_TEXTURE_3D
:
880 if (level
>= ctx
->Const
.Max3DTextureLevels
)
882 texIndex
= TEXTURE_3D_INDEX
;
884 case GL_PROXY_TEXTURE_CUBE_MAP
:
885 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
887 texIndex
= TEXTURE_CUBE_INDEX
;
889 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
892 texIndex
= TEXTURE_RECT_INDEX
;
894 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
895 if (level
>= ctx
->Const
.MaxTextureLevels
)
897 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
899 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
900 if (level
>= ctx
->Const
.MaxTextureLevels
)
902 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
908 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
910 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
912 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
915 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
916 /* Set the 'back' pointer */
917 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
924 * Get the maximum number of allowed mipmap levels.
926 * \param ctx GL context.
927 * \param target texture target.
929 * \return the maximum number of allowed mipmap levels for the given
930 * texture target, or zero if passed a bad target.
935 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
939 case GL_PROXY_TEXTURE_1D
:
941 case GL_PROXY_TEXTURE_2D
:
942 return ctx
->Const
.MaxTextureLevels
;
944 case GL_PROXY_TEXTURE_3D
:
945 return ctx
->Const
.Max3DTextureLevels
;
946 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
947 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
948 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
949 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
950 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
951 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
952 case GL_TEXTURE_CUBE_MAP_ARB
:
953 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
954 return ctx
->Extensions
.ARB_texture_cube_map
955 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
956 case GL_TEXTURE_RECTANGLE_NV
:
957 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
958 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
959 case GL_TEXTURE_1D_ARRAY_EXT
:
960 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
961 case GL_TEXTURE_2D_ARRAY_EXT
:
962 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
963 return (ctx
->Extensions
.MESA_texture_array
||
964 ctx
->Extensions
.EXT_texture_array
)
965 ? ctx
->Const
.MaxTextureLevels
: 0;
966 case GL_TEXTURE_BUFFER
:
969 return 0; /* bad target */
975 * Return number of dimensions per mipmap level for the given texture target.
978 _mesa_get_texture_dimensions(GLenum target
)
982 case GL_PROXY_TEXTURE_1D
:
985 case GL_TEXTURE_RECTANGLE
:
986 case GL_TEXTURE_CUBE_MAP
:
987 case GL_PROXY_TEXTURE_2D
:
988 case GL_PROXY_TEXTURE_RECTANGLE
:
989 case GL_PROXY_TEXTURE_CUBE_MAP
:
990 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
991 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
992 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
993 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
994 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
995 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
996 case GL_TEXTURE_1D_ARRAY
:
997 case GL_PROXY_TEXTURE_1D_ARRAY
:
1000 case GL_PROXY_TEXTURE_3D
:
1001 case GL_TEXTURE_2D_ARRAY
:
1002 case GL_PROXY_TEXTURE_2D_ARRAY
:
1004 case GL_TEXTURE_BUFFER
:
1007 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1016 #if 000 /* not used anymore */
1018 * glTexImage[123]D can accept a NULL image pointer. In this case we
1019 * create a texture image with unspecified image contents per the OpenGL
1023 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1025 const GLint components
= _mesa_components_in_format(format
);
1026 const GLint numPixels
= width
* height
* depth
;
1027 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1031 * Let's see if anyone finds this. If glTexImage2D() is called with
1032 * a NULL image pointer then load the texture image with something
1033 * interesting instead of leaving it indeterminate.
1036 static const char message
[8][32] = {
1037 " X X XXXXX XXX X ",
1038 " XX XX X X X X X ",
1040 " X X XXXX XXX XXXXX ",
1043 " X X XXXXX XXX X X ",
1047 GLubyte
*imgPtr
= data
;
1049 for (h
= 0; h
< depth
; h
++) {
1050 for (i
= 0; i
< height
; i
++) {
1051 GLint srcRow
= 7 - (i
% 8);
1052 for (j
= 0; j
< width
; j
++) {
1053 GLint srcCol
= j
% 32;
1054 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1055 for (k
= 0; k
< components
; k
++) {
1071 * Reset the fields of a gl_texture_image struct to zero.
1073 * \param img texture image structure.
1075 * This is called when a proxy texture test fails, we set all the
1076 * image members (except DriverData) to zero.
1077 * It's also used in glTexImage[123]D as a safeguard to be sure all
1078 * required fields get initialized properly by the Driver.TexImage[123]D
1082 clear_teximage_fields(struct gl_texture_image
*img
)
1085 img
->_BaseFormat
= 0;
1086 img
->InternalFormat
= 0;
1093 if (img
->ImageOffsets
) {
1094 free(img
->ImageOffsets
);
1095 img
->ImageOffsets
= NULL
;
1102 img
->HeightLog2
= 0;
1104 img
->TexFormat
= MESA_FORMAT_NONE
;
1109 * Initialize basic fields of the gl_texture_image struct.
1111 * \param ctx GL context.
1112 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1113 * \param img texture image structure to be initialized.
1114 * \param width image width.
1115 * \param height image height.
1116 * \param depth image depth.
1117 * \param border image border.
1118 * \param internalFormat internal format.
1119 * \param format the actual hardware format (one of MESA_FORMAT_*)
1121 * Fills in the fields of \p img with the given information.
1122 * Note: width, height and depth include the border.
1125 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1126 struct gl_texture_image
*img
,
1127 GLsizei width
, GLsizei height
, GLsizei depth
,
1128 GLint border
, GLenum internalFormat
,
1133 ASSERT(height
>= 0);
1136 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1137 ASSERT(img
->_BaseFormat
> 0);
1138 img
->InternalFormat
= internalFormat
;
1139 img
->Border
= border
;
1141 img
->Height
= height
;
1144 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1145 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1147 if (height
== 1) { /* 1-D texture */
1149 img
->HeightLog2
= 0;
1152 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1153 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1156 if (depth
== 1) { /* 2-D texture */
1161 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1162 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1165 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1168 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1169 img
->RowStride
= width
;
1170 /* Allocate the ImageOffsets array and initialize to typical values.
1171 * We allocate the array for 1D/2D textures too in order to avoid special-
1172 * case code in the texstore routines.
1174 if (img
->ImageOffsets
)
1175 free(img
->ImageOffsets
);
1176 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1177 for (i
= 0; i
< depth
; i
++) {
1178 img
->ImageOffsets
[i
] = i
* width
* height
;
1182 img
->TexFormat
= format
;
1187 * Free and clear fields of the gl_texture_image struct.
1189 * \param ctx GL context.
1190 * \param texImage texture image structure to be cleared.
1192 * After the call, \p texImage will have no data associated with it. Its
1193 * fields are cleared so that its parent object will test incomplete.
1196 _mesa_clear_texture_image(struct gl_context
*ctx
,
1197 struct gl_texture_image
*texImage
)
1199 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1200 clear_teximage_fields(texImage
);
1205 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1206 * level, width, height and depth against the ctx->Const limits for textures.
1208 * A hardware driver might override this function if, for example, the
1209 * max 3D texture size is 512x512x64 (i.e. not a cube).
1211 * Note that width, height, depth == 0 is not an error. However, a
1212 * texture with zero width/height/depth will be considered "incomplete"
1213 * and texturing will effectively be disabled.
1215 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1216 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1217 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1218 * \param level as passed to glTexImage
1219 * \param internalFormat as passed to glTexImage
1220 * \param format as passed to glTexImage
1221 * \param type as passed to glTexImage
1222 * \param width as passed to glTexImage
1223 * \param height as passed to glTexImage
1224 * \param depth as passed to glTexImage
1225 * \param border as passed to glTexImage
1226 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1229 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1230 GLint internalFormat
, GLenum format
, GLenum type
,
1231 GLint width
, GLint height
, GLint depth
, GLint border
)
1235 (void) internalFormat
;
1240 case GL_PROXY_TEXTURE_1D
:
1241 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1242 if (width
< 2 * border
|| width
> 2 + maxSize
)
1244 if (level
>= ctx
->Const
.MaxTextureLevels
)
1246 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1247 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1252 case GL_PROXY_TEXTURE_2D
:
1253 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1254 if (width
< 2 * border
|| width
> 2 + maxSize
)
1256 if (height
< 2 * border
|| height
> 2 + maxSize
)
1258 if (level
>= ctx
->Const
.MaxTextureLevels
)
1260 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1261 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1263 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1268 case GL_PROXY_TEXTURE_3D
:
1269 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1270 if (width
< 2 * border
|| width
> 2 + maxSize
)
1272 if (height
< 2 * border
|| height
> 2 + maxSize
)
1274 if (depth
< 2 * border
|| depth
> 2 + maxSize
)
1276 if (level
>= ctx
->Const
.Max3DTextureLevels
)
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
))
1283 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1288 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1289 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1290 if (width
< 0 || width
> maxSize
)
1292 if (height
< 0 || height
> maxSize
)
1298 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1299 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1300 if (width
< 2 * border
|| width
> 2 + maxSize
)
1302 if (height
< 2 * border
|| height
> 2 + maxSize
)
1304 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1306 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1307 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1309 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1314 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1315 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1316 if (width
< 2 * border
|| width
> 2 + maxSize
)
1318 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1320 if (level
>= ctx
->Const
.MaxTextureLevels
)
1322 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1323 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1328 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1329 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1330 if (width
< 2 * border
|| width
> 2 + maxSize
)
1332 if (height
< 2 * border
|| height
> 2 + maxSize
)
1334 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1336 if (level
>= ctx
->Const
.MaxTextureLevels
)
1338 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1339 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1341 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1347 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1354 * Check if the memory used by the texture would exceed the driver's limit.
1355 * This lets us support a max 3D texture size of 8K (for example) but
1356 * prevents allocating a full 8K x 8K x 8K texture.
1357 * XXX this could be rolled into the proxy texture size test (above) but
1358 * we don't have the actual texture internal format at that point.
1361 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1362 GLint width
, GLint height
, GLint depth
)
1364 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1365 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1366 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1372 * Helper function to determine whether a target and specific compression
1373 * format are supported.
1376 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1379 (void) intFormat
; /* not used yet */
1383 case GL_PROXY_TEXTURE_2D
:
1384 return GL_TRUE
; /* true for any compressed format so far */
1385 case GL_PROXY_TEXTURE_CUBE_MAP
:
1386 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1387 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1388 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1389 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1390 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1391 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1392 return ctx
->Extensions
.ARB_texture_cube_map
;
1393 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1394 case GL_TEXTURE_2D_ARRAY_EXT
:
1395 return (ctx
->Extensions
.MESA_texture_array
||
1396 ctx
->Extensions
.EXT_texture_array
);
1404 * Check if the given texture target value is legal for a
1405 * glTexImage1/2/3D call.
1408 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1414 case GL_PROXY_TEXTURE_1D
:
1422 case GL_PROXY_TEXTURE_2D
:
1424 case GL_PROXY_TEXTURE_CUBE_MAP
:
1425 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1426 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1427 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1428 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1429 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1430 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1431 return ctx
->Extensions
.ARB_texture_cube_map
;
1432 case GL_TEXTURE_RECTANGLE_NV
:
1433 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1434 return ctx
->Extensions
.NV_texture_rectangle
;
1435 case GL_TEXTURE_1D_ARRAY_EXT
:
1436 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1437 return (ctx
->Extensions
.MESA_texture_array
||
1438 ctx
->Extensions
.EXT_texture_array
);
1445 case GL_PROXY_TEXTURE_3D
:
1447 case GL_TEXTURE_2D_ARRAY_EXT
:
1448 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1449 return (ctx
->Extensions
.MESA_texture_array
||
1450 ctx
->Extensions
.EXT_texture_array
);
1455 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1462 * Check if the given texture target value is legal for a
1463 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1464 * The difference compared to legal_teximage_target() above is that
1465 * proxy targets are not supported.
1468 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1472 return target
== GL_TEXTURE_1D
;
1477 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1478 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1479 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1480 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1481 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1482 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1483 return ctx
->Extensions
.ARB_texture_cube_map
;
1484 case GL_TEXTURE_RECTANGLE_NV
:
1485 return ctx
->Extensions
.NV_texture_rectangle
;
1486 case GL_TEXTURE_1D_ARRAY_EXT
:
1487 return (ctx
->Extensions
.MESA_texture_array
||
1488 ctx
->Extensions
.EXT_texture_array
);
1496 case GL_TEXTURE_2D_ARRAY_EXT
:
1497 return (ctx
->Extensions
.MESA_texture_array
||
1498 ctx
->Extensions
.EXT_texture_array
);
1503 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1511 * Test the glTexImage[123]D() parameters for errors.
1513 * \param ctx GL context.
1514 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1515 * \param target texture target given by the user.
1516 * \param level image level given by the user.
1517 * \param internalFormat internal format given by the user.
1518 * \param format pixel data format given by the user.
1519 * \param type pixel data type given by the user.
1520 * \param width image width given by the user.
1521 * \param height image height given by the user.
1522 * \param depth image depth given by the user.
1523 * \param border image border given by the user.
1525 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1527 * Verifies each of the parameters against the constants specified in
1528 * __struct gl_contextRec::Const and the supported extensions, and according
1529 * to the OpenGL specification.
1532 texture_error_check( struct gl_context
*ctx
,
1533 GLuint dimensions
, GLenum target
,
1534 GLint level
, GLint internalFormat
,
1535 GLenum format
, GLenum type
,
1536 GLint width
, GLint height
,
1537 GLint depth
, GLint border
)
1539 const GLenum proxyTarget
= get_proxy_target(target
);
1540 const GLboolean isProxy
= target
== proxyTarget
;
1541 GLboolean sizeOK
= GL_TRUE
;
1542 GLboolean colorFormat
;
1544 /* Even though there are no color-index textures, we still have to support
1545 * uploading color-index data and remapping it to RGB via the
1546 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1548 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1550 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1551 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1553 _mesa_error(ctx
, GL_INVALID_VALUE
,
1554 "glTexImage%dD(level=%d)", dimensions
, level
);
1560 if (border
< 0 || border
> 1 ||
1561 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1562 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1564 _mesa_error(ctx
, GL_INVALID_VALUE
,
1565 "glTexImage%dD(border=%d)", dimensions
, border
);
1570 if (width
< 0 || height
< 0 || depth
< 0) {
1572 _mesa_error(ctx
, GL_INVALID_VALUE
,
1573 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1578 /* Do this simple check before calling the TestProxyTexImage() function */
1579 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1580 sizeOK
= (width
== height
);
1584 * Use the proxy texture driver hook to see if the size/level/etc are
1587 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1588 internalFormat
, format
,
1589 type
, width
, height
,
1593 _mesa_error(ctx
, GL_INVALID_VALUE
,
1594 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1595 dimensions
, level
, width
, height
, depth
);
1600 /* Check internalFormat */
1601 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1603 _mesa_error(ctx
, GL_INVALID_VALUE
,
1604 "glTexImage%dD(internalFormat=%s)",
1605 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1610 /* Check incoming image format and type */
1611 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1612 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1613 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1614 * GL_EXT_texture_integer extension, some combinations should generate
1615 * GL_INVALID_ENUM instead (grr!).
1618 GLenum error
= _mesa_is_integer_format(format
)
1619 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1620 _mesa_error(ctx
, error
,
1621 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1622 dimensions
, format
, type
);
1627 /* make sure internal format and format basically agree */
1628 colorFormat
= _mesa_is_color_format(format
);
1629 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1630 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1631 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1632 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1633 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1635 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1636 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1637 dimensions
, internalFormat
, format
);
1641 /* additional checks for ycbcr textures */
1642 if (internalFormat
== GL_YCBCR_MESA
) {
1643 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1644 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1645 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1647 _mesa_snprintf(message
, sizeof(message
),
1648 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1649 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1650 return GL_TRUE
; /* error */
1652 if (target
!= GL_TEXTURE_2D
&&
1653 target
!= GL_PROXY_TEXTURE_2D
&&
1654 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1655 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1657 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1663 _mesa_snprintf(message
, sizeof(message
),
1664 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1665 dimensions
, border
);
1666 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1672 /* additional checks for depth textures */
1673 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1674 /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */
1675 if (target
!= GL_TEXTURE_1D
&&
1676 target
!= GL_PROXY_TEXTURE_1D
&&
1677 target
!= GL_TEXTURE_2D
&&
1678 target
!= GL_PROXY_TEXTURE_2D
&&
1679 target
!= GL_TEXTURE_1D_ARRAY
&&
1680 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1681 target
!= GL_TEXTURE_2D_ARRAY
&&
1682 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1683 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1684 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1686 _mesa_error(ctx
, GL_INVALID_ENUM
,
1687 "glTexImage(target/internalFormat)");
1692 /* additional checks for compressed textures */
1693 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1694 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1696 _mesa_error(ctx
, GL_INVALID_ENUM
,
1697 "glTexImage%dD(target)", dimensions
);
1702 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1703 "glTexImage%dD(border!=0)", dimensions
);
1709 /* additional checks for integer textures */
1710 if (ctx
->Extensions
.EXT_texture_integer
&&
1711 (_mesa_is_integer_format(format
) !=
1712 _mesa_is_integer_format(internalFormat
))) {
1714 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1715 "glTexImage%dD(integer/non-integer format mismatch)",
1721 /* if we get here, the parameters are OK */
1727 * Test glTexSubImage[123]D() parameters for errors.
1729 * \param ctx GL context.
1730 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1731 * \param target texture target given by the user.
1732 * \param level image level given by the user.
1733 * \param xoffset sub-image x offset given by the user.
1734 * \param yoffset sub-image y offset given by the user.
1735 * \param zoffset sub-image z offset given by the user.
1736 * \param format pixel data format given by the user.
1737 * \param type pixel data type given by the user.
1738 * \param width image width given by the user.
1739 * \param height image height given by the user.
1740 * \param depth image depth given by the user.
1742 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1744 * Verifies each of the parameters against the constants specified in
1745 * __struct gl_contextRec::Const and the supported extensions, and according
1746 * to the OpenGL specification.
1749 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1750 GLenum target
, GLint level
,
1751 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1752 GLint width
, GLint height
, GLint depth
,
1753 GLenum format
, GLenum type
)
1755 /* Basic level check */
1756 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1757 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1761 /* Check for negative sizes */
1763 _mesa_error(ctx
, GL_INVALID_VALUE
,
1764 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1767 if (height
< 0 && dimensions
> 1) {
1768 _mesa_error(ctx
, GL_INVALID_VALUE
,
1769 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1772 if (depth
< 0 && dimensions
> 2) {
1773 _mesa_error(ctx
, GL_INVALID_VALUE
,
1774 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1778 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1779 /* As with the glTexImage2D check above, the error code here
1780 * depends on texture integer.
1782 GLenum error
= _mesa_is_integer_format(format
)
1783 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1784 _mesa_error(ctx
, error
,
1785 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1786 dimensions
, format
, type
);
1795 * Do second part of glTexSubImage which depends on the destination texture.
1796 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1799 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1800 GLenum target
, GLint level
,
1801 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1802 GLint width
, GLint height
, GLint depth
,
1803 GLenum format
, GLenum type
,
1804 const struct gl_texture_image
*destTex
)
1807 /* undefined image level */
1808 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1812 if (xoffset
< -((GLint
)destTex
->Border
)) {
1813 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1817 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1818 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1822 if (dimensions
> 1) {
1823 if (yoffset
< -((GLint
)destTex
->Border
)) {
1824 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1828 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1829 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1834 if (dimensions
> 2) {
1835 if (zoffset
< -((GLint
)destTex
->Border
)) {
1836 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1839 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1840 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1845 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1848 /* do tests which depend on compression block size */
1849 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1851 /* offset must be multiple of block size */
1852 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1853 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1854 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1855 dimensions
, xoffset
, yoffset
);
1858 /* size must be multiple of bw by bh or equal to whole texture size */
1859 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1860 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1861 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1864 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1865 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1866 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1876 * Test glCopyTexImage[12]D() parameters for errors.
1878 * \param ctx GL context.
1879 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1880 * \param target texture target given by the user.
1881 * \param level image level given by the user.
1882 * \param internalFormat internal format given by the user.
1883 * \param width image width given by the user.
1884 * \param height image height given by the user.
1885 * \param border texture border.
1887 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1889 * Verifies each of the parameters against the constants specified in
1890 * __struct gl_contextRec::Const and the supported extensions, and according
1891 * to the OpenGL specification.
1894 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1895 GLenum target
, GLint level
, GLint internalFormat
,
1896 GLint width
, GLint height
, GLint border
)
1898 const GLenum proxyTarget
= get_proxy_target(target
);
1899 const GLenum type
= GL_FLOAT
;
1904 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1905 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1906 dimensions
, _mesa_lookup_enum_by_nr(target
));
1910 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1911 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1912 _mesa_error(ctx
, GL_INVALID_VALUE
,
1913 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1917 /* Check that the source buffer is complete */
1918 if (ctx
->ReadBuffer
->Name
) {
1919 if (ctx
->ReadBuffer
->_Status
== 0) {
1920 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1922 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1923 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1924 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1930 if (border
< 0 || border
> 1 ||
1931 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1932 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1936 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1937 if (baseFormat
< 0) {
1938 _mesa_error(ctx
, GL_INVALID_VALUE
,
1939 "glCopyTexImage%dD(internalFormat)", dimensions
);
1943 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
1944 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1945 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1949 /* Do size, level checking */
1950 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1951 ? (width
== height
) : 1;
1953 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1954 internalFormat
, baseFormat
,
1955 type
, width
, height
,
1959 if (dimensions
== 1) {
1960 _mesa_error(ctx
, GL_INVALID_VALUE
,
1961 "glCopyTexImage1D(width=%d)", width
);
1964 ASSERT(dimensions
== 2);
1965 _mesa_error(ctx
, GL_INVALID_VALUE
,
1966 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1971 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1972 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1973 _mesa_error(ctx
, GL_INVALID_ENUM
,
1974 "glCopyTexImage%dD(target)", dimensions
);
1978 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1979 "glCopyTexImage%dD(border!=0)", dimensions
);
1984 /* if we get here, the parameters are OK */
1990 * Test glCopyTexSubImage[12]D() parameters for errors.
1991 * Note that this is the first part of error checking.
1992 * See also copytexsubimage_error_check2() below for the second part.
1994 * \param ctx GL context.
1995 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1996 * \param target texture target given by the user.
1997 * \param level image level given by the user.
1999 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2002 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2003 GLenum target
, GLint level
)
2005 /* Check that the source buffer is complete */
2006 if (ctx
->ReadBuffer
->Name
) {
2007 if (ctx
->ReadBuffer
->_Status
== 0) {
2008 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2010 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2011 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2012 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2017 /* check target (proxies not allowed) */
2018 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2019 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2020 dimensions
, _mesa_lookup_enum_by_nr(target
));
2025 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2026 _mesa_error(ctx
, GL_INVALID_VALUE
,
2027 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2036 * Second part of error checking for glCopyTexSubImage[12]D().
2037 * \param xoffset sub-image x offset given by the user.
2038 * \param yoffset sub-image y offset given by the user.
2039 * \param zoffset sub-image z offset given by the user.
2040 * \param width image width given by the user.
2041 * \param height image height given by the user.
2044 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2045 GLenum target
, GLint level
,
2046 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2047 GLsizei width
, GLsizei height
,
2048 const struct gl_texture_image
*teximage
)
2050 /* check that dest tex image exists */
2052 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2053 "glCopyTexSubImage%dD(undefined texture level: %d)",
2060 _mesa_error(ctx
, GL_INVALID_VALUE
,
2061 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2064 if (dimensions
> 1 && height
< 0) {
2065 _mesa_error(ctx
, GL_INVALID_VALUE
,
2066 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2070 /* check x/y offsets */
2071 if (xoffset
< -((GLint
)teximage
->Border
)) {
2072 _mesa_error(ctx
, GL_INVALID_VALUE
,
2073 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2076 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2077 _mesa_error(ctx
, GL_INVALID_VALUE
,
2078 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2081 if (dimensions
> 1) {
2082 if (yoffset
< -((GLint
)teximage
->Border
)) {
2083 _mesa_error(ctx
, GL_INVALID_VALUE
,
2084 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2087 /* NOTE: we're adding the border here, not subtracting! */
2088 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2089 _mesa_error(ctx
, GL_INVALID_VALUE
,
2090 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2095 /* check z offset */
2096 if (dimensions
> 2) {
2097 if (zoffset
< -((GLint
)teximage
->Border
)) {
2098 _mesa_error(ctx
, GL_INVALID_VALUE
,
2099 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2102 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2103 _mesa_error(ctx
, GL_INVALID_VALUE
,
2104 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2109 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2110 /* offset must be multiple of 4 */
2111 if ((xoffset
& 3) || (yoffset
& 3)) {
2112 _mesa_error(ctx
, GL_INVALID_VALUE
,
2113 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2116 /* size must be multiple of 4 */
2117 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2118 _mesa_error(ctx
, GL_INVALID_VALUE
,
2119 "glCopyTexSubImage%dD(width)", dimensions
);
2122 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2123 _mesa_error(ctx
, GL_INVALID_VALUE
,
2124 "glCopyTexSubImage%dD(height)", dimensions
);
2129 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2130 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2134 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2135 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2136 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2137 dimensions
, teximage
->_BaseFormat
);
2141 /* If copying into an integer texture, the source buffer must also be
2144 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2145 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2146 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2147 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2148 "glCopyTexSubImage%dD(source buffer is not integer format)",
2154 /* if we get here, the parameters are OK */
2159 /** Callback info for walking over FBO hash table */
2162 struct gl_context
*ctx
;
2163 struct gl_texture_object
*texObj
;
2169 * Check render to texture callback. Called from _mesa_HashWalk().
2172 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2174 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2175 const struct cb_info
*info
= (struct cb_info
*) userData
;
2176 struct gl_context
*ctx
= info
->ctx
;
2177 const struct gl_texture_object
*texObj
= info
->texObj
;
2178 const GLuint level
= info
->level
, face
= info
->face
;
2180 /* If this is a user-created FBO */
2183 /* check if any of the FBO's attachments point to 'texObj' */
2184 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2185 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2186 if (att
->Type
== GL_TEXTURE
&&
2187 att
->Texture
== texObj
&&
2188 att
->TextureLevel
== level
&&
2189 att
->CubeMapFace
== face
) {
2190 ASSERT(_mesa_get_attachment_teximage(att
));
2191 /* Tell driver about the new renderbuffer texture */
2192 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2193 /* Mark fb status as indeterminate to force re-validation */
2202 * When a texture image is specified we have to check if it's bound to
2203 * any framebuffer objects (render to texture) in order to detect changes
2204 * in size or format since that effects FBO completeness.
2205 * Any FBOs rendering into the texture must be re-validated.
2208 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2209 GLuint face
, GLuint level
)
2211 /* Only check this texture if it's been marked as RenderToTexture */
2212 if (texObj
->_RenderToTexture
) {
2213 struct cb_info info
;
2215 info
.texObj
= texObj
;
2218 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2224 * If the texture object's GenerateMipmap flag is set and we've
2225 * changed the texture base level image, regenerate the rest of the
2226 * mipmap levels now.
2229 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2230 struct gl_texture_object
*texObj
, GLint level
)
2232 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2233 if (texObj
->GenerateMipmap
&&
2234 level
== texObj
->BaseLevel
&&
2235 level
< texObj
->MaxLevel
) {
2236 ASSERT(ctx
->Driver
.GenerateMipmap
);
2237 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2242 /** Debug helper: override the user-requested internal format */
2244 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2247 if (internalFormat
== GL_RGBA16F_ARB
||
2248 internalFormat
== GL_RGBA32F_ARB
) {
2249 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2252 else if (internalFormat
== GL_RGB16F_ARB
||
2253 internalFormat
== GL_RGB32F_ARB
) {
2254 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2257 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2258 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2259 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2260 return GL_LUMINANCE_ALPHA
;
2262 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2263 internalFormat
== GL_LUMINANCE32F_ARB
) {
2264 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2265 return GL_LUMINANCE
;
2267 else if (internalFormat
== GL_ALPHA16F_ARB
||
2268 internalFormat
== GL_ALPHA32F_ARB
) {
2269 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2273 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2274 internalFormat = GL_RGBA;
2278 return internalFormat
;
2281 return internalFormat
;
2287 * Choose the actual hardware format for a texture image.
2288 * Try to use the same format as the previous image level when possible.
2289 * Otherwise, ask the driver for the best format.
2290 * It's important to try to choose a consistant format for all levels
2291 * for efficient texture memory layout/allocation. In particular, this
2292 * comes up during automatic mipmap generation.
2295 _mesa_choose_texture_format(struct gl_context
*ctx
,
2296 struct gl_texture_object
*texObj
,
2297 GLenum target
, GLint level
,
2298 GLenum internalFormat
, GLenum format
, GLenum type
)
2302 /* see if we've already chosen a format for the previous level */
2304 struct gl_texture_image
*prevImage
=
2305 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2306 /* See if the prev level is defined and has an internal format which
2307 * matches the new internal format.
2310 prevImage
->Width
> 0 &&
2311 prevImage
->InternalFormat
== internalFormat
) {
2312 /* use the same format */
2313 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2314 return prevImage
->TexFormat
;
2318 /* choose format from scratch */
2319 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2320 ASSERT(f
!= MESA_FORMAT_NONE
);
2326 * Common code to implement all the glTexImage1D/2D/3D functions.
2329 teximage(struct gl_context
*ctx
, GLuint dims
,
2330 GLenum target
, GLint level
, GLint internalFormat
,
2331 GLsizei width
, GLsizei height
, GLsizei depth
,
2332 GLint border
, GLenum format
, GLenum type
,
2333 const GLvoid
*pixels
)
2337 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2339 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2340 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2342 _mesa_lookup_enum_by_nr(target
), level
,
2343 _mesa_lookup_enum_by_nr(internalFormat
),
2344 width
, height
, depth
, border
,
2345 _mesa_lookup_enum_by_nr(format
),
2346 _mesa_lookup_enum_by_nr(type
), pixels
);
2348 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2350 /* target error checking */
2351 if (!legal_teximage_target(ctx
, dims
, target
)) {
2352 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2353 dims
, _mesa_lookup_enum_by_nr(target
));
2357 /* general error checking */
2358 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2359 format
, type
, width
, height
, depth
, border
);
2361 if (_mesa_is_proxy_texture(target
)) {
2362 /* Proxy texture: just clear or set state depending on error checking */
2363 struct gl_texture_image
*texImage
=
2364 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2367 /* when error, clear all proxy texture image parameters */
2369 clear_teximage_fields(texImage
);
2372 /* no error, set the tex image parameters */
2373 struct gl_texture_object
*texObj
=
2374 _mesa_get_current_tex_object(ctx
, target
);
2375 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2380 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2381 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2382 depth
, border
, internalFormat
,
2385 else if (texImage
) {
2386 clear_teximage_fields(texImage
);
2391 /* non-proxy target */
2392 const GLuint face
= _mesa_tex_target_to_face(target
);
2393 struct gl_texture_object
*texObj
;
2394 struct gl_texture_image
*texImage
;
2397 return; /* error was recorded */
2400 if (ctx
->NewState
& _NEW_PIXEL
)
2401 _mesa_update_state(ctx
);
2403 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2405 _mesa_lock_texture(ctx
, texObj
);
2407 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2410 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2413 gl_format texFormat
;
2415 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2417 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2418 internalFormat
, format
,
2421 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2422 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2423 width
, height
, depth
,
2424 border
, internalFormat
, texFormat
);
2426 /* Give the texture to the driver. <pixels> may be null. */
2427 ASSERT(ctx
->Driver
.TexImage3D
);
2430 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2431 width
, border
, format
,
2432 type
, pixels
, &ctx
->Unpack
, texObj
,
2436 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2437 width
, height
, border
, format
,
2438 type
, pixels
, &ctx
->Unpack
, texObj
,
2442 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2443 width
, height
, depth
, border
, format
,
2444 type
, pixels
, &ctx
->Unpack
, texObj
,
2448 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2451 check_gen_mipmap(ctx
, target
, texObj
, level
);
2453 update_fbo_texture(ctx
, texObj
, face
, level
);
2456 texObj
->_Complete
= GL_FALSE
;
2457 ctx
->NewState
|= _NEW_TEXTURE
;
2460 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2464 _mesa_unlock_texture(ctx
, texObj
);
2470 * Called from the API. Note that width includes the border.
2473 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2474 GLsizei width
, GLint border
, GLenum format
,
2475 GLenum type
, const GLvoid
*pixels
)
2477 GET_CURRENT_CONTEXT(ctx
);
2478 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2479 border
, format
, type
, pixels
);
2484 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2485 GLsizei width
, GLsizei height
, GLint border
,
2486 GLenum format
, GLenum type
,
2487 const GLvoid
*pixels
)
2489 GET_CURRENT_CONTEXT(ctx
);
2490 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2491 border
, format
, type
, pixels
);
2496 * Called by the API or display list executor.
2497 * Note that width and height include the border.
2500 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2501 GLsizei width
, GLsizei height
, GLsizei depth
,
2502 GLint border
, GLenum format
, GLenum type
,
2503 const GLvoid
*pixels
)
2505 GET_CURRENT_CONTEXT(ctx
);
2506 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2507 border
, format
, type
, pixels
);
2512 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2513 GLsizei width
, GLsizei height
, GLsizei depth
,
2514 GLint border
, GLenum format
, GLenum type
,
2515 const GLvoid
*pixels
)
2517 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2518 depth
, border
, format
, type
, pixels
);
2522 #if FEATURE_OES_EGL_image
2524 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2526 struct gl_texture_object
*texObj
;
2527 struct gl_texture_image
*texImage
;
2528 GET_CURRENT_CONTEXT(ctx
);
2529 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2531 if (!ctx
->Extensions
.OES_EGL_image
) {
2532 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2533 "glEGLImageTargetTexture2DOES(unsupported)");
2537 if (target
!= GL_TEXTURE_2D
) {
2538 _mesa_error(ctx
, GL_INVALID_ENUM
,
2539 "glEGLImageTargetTexture2D(target=%d)", target
);
2543 if (ctx
->NewState
& _NEW_PIXEL
)
2544 _mesa_update_state(ctx
);
2546 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2547 _mesa_lock_texture(ctx
, texObj
);
2549 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2551 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2553 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2555 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2556 texObj
, texImage
, image
);
2559 texObj
->_Complete
= GL_FALSE
;
2560 ctx
->NewState
|= _NEW_TEXTURE
;
2562 _mesa_unlock_texture(ctx
, texObj
);
2570 * Implement all the glTexSubImage1/2/3D() functions.
2573 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2574 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2575 GLsizei width
, GLsizei height
, GLsizei depth
,
2576 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2578 struct gl_texture_object
*texObj
;
2579 struct gl_texture_image
*texImage
;
2581 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2583 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2584 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2586 _mesa_lookup_enum_by_nr(target
), level
,
2587 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2588 _mesa_lookup_enum_by_nr(format
),
2589 _mesa_lookup_enum_by_nr(type
), pixels
);
2591 /* check target (proxies not allowed) */
2592 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2593 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2594 dims
, _mesa_lookup_enum_by_nr(target
));
2598 if (ctx
->NewState
& _NEW_PIXEL
)
2599 _mesa_update_state(ctx
);
2601 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2602 width
, height
, depth
, format
, type
)) {
2603 return; /* error was detected */
2606 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2608 _mesa_lock_texture(ctx
, texObj
);
2610 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2612 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2613 xoffset
, yoffset
, zoffset
,
2614 width
, height
, depth
,
2615 format
, type
, texImage
)) {
2616 /* error was recorded */
2618 else if (width
> 0 && height
> 0 && depth
> 0) {
2619 /* If we have a border, offset=-1 is legal. Bias by border width. */
2622 zoffset
+= texImage
->Border
;
2625 yoffset
+= texImage
->Border
;
2628 xoffset
+= texImage
->Border
;
2633 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2635 format
, type
, pixels
,
2636 &ctx
->Unpack
, texObj
, texImage
);
2639 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2640 xoffset
, yoffset
, width
, height
,
2641 format
, type
, pixels
,
2642 &ctx
->Unpack
, texObj
, texImage
);
2645 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2646 xoffset
, yoffset
, zoffset
,
2647 width
, height
, depth
,
2648 format
, type
, pixels
,
2649 &ctx
->Unpack
, texObj
, texImage
);
2652 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2655 check_gen_mipmap(ctx
, target
, texObj
, level
);
2657 ctx
->NewState
|= _NEW_TEXTURE
;
2660 _mesa_unlock_texture(ctx
, texObj
);
2665 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2666 GLint xoffset
, GLsizei width
,
2667 GLenum format
, GLenum type
,
2668 const GLvoid
*pixels
)
2670 GET_CURRENT_CONTEXT(ctx
);
2671 texsubimage(ctx
, 1, target
, level
,
2674 format
, type
, pixels
);
2679 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2680 GLint xoffset
, GLint yoffset
,
2681 GLsizei width
, GLsizei height
,
2682 GLenum format
, GLenum type
,
2683 const GLvoid
*pixels
)
2685 GET_CURRENT_CONTEXT(ctx
);
2686 texsubimage(ctx
, 2, target
, level
,
2687 xoffset
, yoffset
, 0,
2689 format
, type
, pixels
);
2695 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2696 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2697 GLsizei width
, GLsizei height
, GLsizei depth
,
2698 GLenum format
, GLenum type
,
2699 const GLvoid
*pixels
)
2701 GET_CURRENT_CONTEXT(ctx
);
2702 texsubimage(ctx
, 3, target
, level
,
2703 xoffset
, yoffset
, zoffset
,
2704 width
, height
, depth
,
2705 format
, type
, pixels
);
2711 * Implement the glCopyTexImage1/2D() functions.
2714 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2715 GLenum target
, GLint level
, GLenum internalFormat
,
2716 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2718 struct gl_texture_object
*texObj
;
2719 struct gl_texture_image
*texImage
;
2720 const GLuint face
= _mesa_tex_target_to_face(target
);
2722 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2724 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2725 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2727 _mesa_lookup_enum_by_nr(target
), level
,
2728 _mesa_lookup_enum_by_nr(internalFormat
),
2729 x
, y
, width
, height
, border
);
2731 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2732 _mesa_update_state(ctx
);
2734 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2735 width
, height
, border
))
2738 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2740 _mesa_lock_texture(ctx
, texObj
);
2742 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2745 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2748 /* choose actual hw format */
2749 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2754 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2755 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2757 /* Free old texture image */
2758 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2760 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2761 border
, internalFormat
, texFormat
);
2763 /* Allocate texture memory (no pixel data yet) */
2765 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2766 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2767 &ctx
->Unpack
, texObj
, texImage
);
2770 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2771 width
, height
, border
, GL_NONE
, GL_NONE
,
2772 NULL
, &ctx
->Unpack
, texObj
, texImage
);
2775 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2778 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
, dstX
,
2782 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, dstX
, dstY
,
2783 srcX
, srcY
, width
, height
);
2786 check_gen_mipmap(ctx
, target
, texObj
, level
);
2788 update_fbo_texture(ctx
, texObj
, face
, level
);
2791 texObj
->_Complete
= GL_FALSE
;
2792 ctx
->NewState
|= _NEW_TEXTURE
;
2795 /* probably too large of image */
2796 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2800 _mesa_unlock_texture(ctx
, texObj
);
2806 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2807 GLenum internalFormat
,
2809 GLsizei width
, GLint border
)
2811 GET_CURRENT_CONTEXT(ctx
);
2812 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2818 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2819 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2822 GET_CURRENT_CONTEXT(ctx
);
2823 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2824 x
, y
, width
, height
, border
);
2830 * Implementation for glCopyTexSubImage1/2/3D() functions.
2833 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2834 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2835 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2837 struct gl_texture_object
*texObj
;
2838 struct gl_texture_image
*texImage
;
2840 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2842 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2843 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2845 _mesa_lookup_enum_by_nr(target
),
2846 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2848 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2849 _mesa_update_state(ctx
);
2851 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2854 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2856 _mesa_lock_texture(ctx
, texObj
);
2858 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2860 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2861 zoffset
, width
, height
, texImage
)) {
2862 /* error was recored */
2865 /* If we have a border, offset=-1 is legal. Bias by border width. */
2868 zoffset
+= texImage
->Border
;
2871 yoffset
+= texImage
->Border
;
2874 xoffset
+= texImage
->Border
;
2877 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2881 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2882 xoffset
, x
, y
, width
);
2885 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2887 x
, y
, width
, height
);
2890 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2891 xoffset
, yoffset
, zoffset
,
2892 x
, y
, width
, height
);
2895 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
2898 check_gen_mipmap(ctx
, target
, texObj
, level
);
2900 ctx
->NewState
|= _NEW_TEXTURE
;
2904 _mesa_unlock_texture(ctx
, texObj
);
2909 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2910 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2912 GET_CURRENT_CONTEXT(ctx
);
2913 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
2919 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2920 GLint xoffset
, GLint yoffset
,
2921 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2923 GET_CURRENT_CONTEXT(ctx
);
2924 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
2931 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2932 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2933 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2935 GET_CURRENT_CONTEXT(ctx
);
2936 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2937 x
, y
, width
, height
);
2943 /**********************************************************************/
2944 /****** Compressed Textures ******/
2945 /**********************************************************************/
2949 * Return expected size of a compressed texture.
2952 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2955 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2956 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2961 * Return compressed texture block size, in pixels.
2964 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
2966 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2967 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
2972 * Error checking for glCompressedTexImage[123]D().
2973 * \param reason returns reason for error, if any
2974 * \return error code or GL_NO_ERROR.
2977 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2978 GLenum target
, GLint level
,
2979 GLenum internalFormat
, GLsizei width
,
2980 GLsizei height
, GLsizei depth
, GLint border
,
2981 GLsizei imageSize
, char **reason
)
2983 const GLenum proxyTarget
= get_proxy_target(target
);
2984 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2986 GLenum choose_format
;
2988 GLenum proxy_format
;
2990 *reason
= ""; /* no error */
2992 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2994 return GL_INVALID_ENUM
;
2997 /* This will detect any invalid internalFormat value */
2998 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2999 *reason
= "internalFormat";
3000 return GL_INVALID_ENUM
;
3003 switch (internalFormat
) {
3005 case GL_PALETTE4_RGB8_OES
:
3006 case GL_PALETTE4_RGBA8_OES
:
3007 case GL_PALETTE4_R5_G6_B5_OES
:
3008 case GL_PALETTE4_RGBA4_OES
:
3009 case GL_PALETTE4_RGB5_A1_OES
:
3010 case GL_PALETTE8_RGB8_OES
:
3011 case GL_PALETTE8_RGBA8_OES
:
3012 case GL_PALETTE8_R5_G6_B5_OES
:
3013 case GL_PALETTE8_RGBA4_OES
:
3014 case GL_PALETTE8_RGB5_A1_OES
:
3015 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3017 proxy_format
= choose_format
;
3020 if (level
> 0 || level
< -maxLevels
) {
3022 return GL_INVALID_VALUE
;
3025 if (dimensions
!= 2) {
3026 *reason
= "compressed paletted textures must be 2D";
3027 return GL_INVALID_OPERATION
;
3030 /* Figure out the expected texture size (in bytes). This will be
3031 * checked against the actual size later.
3033 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3036 /* This is for the benefit of the TestProxyTexImage below. It expects
3037 * level to be non-negative. OES_compressed_paletted_texture uses a
3038 * weird mechanism where the level specified to glCompressedTexImage2D
3039 * is -(n-1) number of levels in the texture, and the data specifies the
3040 * complete mipmap stack. This is done to ensure the palette is the
3041 * same for all levels.
3048 choose_format
= GL_NONE
;
3049 choose_type
= GL_NONE
;
3050 proxy_format
= internalFormat
;
3053 if (level
< 0 || level
>= maxLevels
) {
3055 return GL_INVALID_VALUE
;
3058 /* Figure out the expected texture size (in bytes). This will be
3059 * checked against the actual size later.
3061 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3065 /* This should really never fail */
3066 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3067 *reason
= "internalFormat";
3068 return GL_INVALID_ENUM
;
3071 /* No compressed formats support borders at this time */
3073 *reason
= "border != 0";
3074 return GL_INVALID_VALUE
;
3077 /* For cube map, width must equal height */
3078 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3079 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
) {
3080 *reason
= "width != height";
3081 return GL_INVALID_VALUE
;
3084 /* check image size against compression block size */
3086 gl_format texFormat
=
3087 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3088 choose_format
, choose_type
);
3091 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3092 if ((width
> bw
&& width
% bw
> 0) ||
3093 (height
> bh
&& height
% bh
> 0)) {
3095 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3096 * generated [...] if any parameter combinations are not
3097 * supported by the specific compressed internal format.
3099 *reason
= "invalid width or height for compression format";
3100 return GL_INVALID_OPERATION
;
3104 /* check image sizes */
3105 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3106 proxy_format
, choose_format
,
3108 width
, height
, depth
, border
)) {
3109 /* See error comment above */
3110 *reason
= "invalid width, height or format";
3111 return GL_INVALID_OPERATION
;
3114 /* check image size in bytes */
3115 if (expectedSize
!= imageSize
) {
3116 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3117 * if <imageSize> is not consistent with the format, dimensions, and
3118 * contents of the specified image.
3120 *reason
= "imageSize inconsistant with width/height/format";
3121 return GL_INVALID_VALUE
;
3129 * Error checking for glCompressedTexSubImage[123]D().
3130 * \warning There are some bad assumptions here about the size of compressed
3131 * texture tiles (multiple of 4) used to test the validity of the
3132 * offset and size parameters.
3133 * \return error code or GL_NO_ERROR.
3136 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3137 GLenum target
, GLint level
,
3138 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3139 GLsizei width
, GLsizei height
, GLsizei depth
,
3140 GLenum format
, GLsizei imageSize
)
3142 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3146 if (dimensions
== 1) {
3147 /* 1D compressed textures not allowed */
3148 return GL_INVALID_ENUM
;
3150 else if (dimensions
== 2) {
3151 if (target
== GL_PROXY_TEXTURE_2D
) {
3152 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3154 else if (target
== GL_TEXTURE_2D
) {
3155 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3157 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3158 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3159 return GL_INVALID_ENUM
; /*target*/
3160 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3162 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3163 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3164 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3165 return GL_INVALID_ENUM
; /*target*/
3166 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3169 return GL_INVALID_ENUM
; /*target*/
3172 else if (dimensions
== 3) {
3173 /* 3D compressed textures not allowed */
3174 return GL_INVALID_ENUM
;
3177 maxTextureSize
= 1 << (maxLevels
- 1);
3179 /* this will catch any invalid compressed format token */
3180 if (!_mesa_is_compressed_format(ctx
, format
))
3181 return GL_INVALID_ENUM
;
3183 if (width
< 1 || width
> maxTextureSize
)
3184 return GL_INVALID_VALUE
;
3186 if ((height
< 1 || height
> maxTextureSize
)
3188 return GL_INVALID_VALUE
;
3190 if (level
< 0 || level
>= maxLevels
)
3191 return GL_INVALID_VALUE
;
3194 * do checks which depend on compression block size
3196 get_compressed_block_size(format
, &bw
, &bh
);
3198 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3199 return GL_INVALID_VALUE
;
3201 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3202 return GL_INVALID_VALUE
;
3204 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3205 return GL_INVALID_VALUE
;
3207 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3208 if (expectedSize
!= imageSize
)
3209 return GL_INVALID_VALUE
;
3216 * Do second part of glCompressedTexSubImage error checking.
3217 * \return GL_TRUE if error found, GL_FALSE otherwise.
3220 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3221 GLsizei width
, GLsizei height
,
3222 GLsizei depth
, GLenum format
,
3223 struct gl_texture_image
*texImage
)
3226 if ((GLint
) format
!= texImage
->InternalFormat
) {
3227 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3228 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3232 if (((width
== 1 || width
== 2) &&
3233 width
!= (GLsizei
) texImage
->Width
) ||
3234 (width
> (GLsizei
) texImage
->Width
)) {
3235 _mesa_error(ctx
, GL_INVALID_VALUE
,
3236 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3241 if (((height
== 1 || height
== 2) &&
3242 height
!= (GLsizei
) texImage
->Height
) ||
3243 (height
> (GLsizei
) texImage
->Height
)) {
3244 _mesa_error(ctx
, GL_INVALID_VALUE
,
3245 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3251 if (((depth
== 1 || depth
== 2) &&
3252 depth
!= (GLsizei
) texImage
->Depth
) ||
3253 (depth
> (GLsizei
) texImage
->Depth
)) {
3254 _mesa_error(ctx
, GL_INVALID_VALUE
,
3255 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3265 * Implementation of the glCompressedTexImage1/2/3D() functions.
3268 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3269 GLenum target
, GLint level
,
3270 GLenum internalFormat
, GLsizei width
,
3271 GLsizei height
, GLsizei depth
, GLint border
,
3272 GLsizei imageSize
, const GLvoid
*data
)
3277 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3279 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3281 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3283 _mesa_lookup_enum_by_nr(target
), level
,
3284 _mesa_lookup_enum_by_nr(internalFormat
),
3285 width
, height
, depth
, border
, imageSize
, data
);
3288 if (!legal_teximage_target(ctx
, dims
, target
)) {
3289 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3290 dims
, _mesa_lookup_enum_by_nr(target
));
3294 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3295 internalFormat
, width
, height
, depth
,
3296 border
, imageSize
, &reason
);
3299 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3304 /* XXX this is kind of a hack */
3306 switch (internalFormat
) {
3307 case GL_PALETTE4_RGB8_OES
:
3308 case GL_PALETTE4_RGBA8_OES
:
3309 case GL_PALETTE4_R5_G6_B5_OES
:
3310 case GL_PALETTE4_RGBA4_OES
:
3311 case GL_PALETTE4_RGB5_A1_OES
:
3312 case GL_PALETTE8_RGB8_OES
:
3313 case GL_PALETTE8_RGBA8_OES
:
3314 case GL_PALETTE8_R5_G6_B5_OES
:
3315 case GL_PALETTE8_RGBA4_OES
:
3316 case GL_PALETTE8_RGB5_A1_OES
:
3317 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3318 width
, height
, imageSize
, data
);
3324 if (_mesa_is_proxy_texture(target
)) {
3325 /* Proxy texture: just check for errors and update proxy state */
3326 struct gl_texture_image
*texImage
;
3329 struct gl_texture_object
*texObj
=
3330 _mesa_get_current_tex_object(ctx
, target
);
3331 gl_format texFormat
=
3332 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3333 internalFormat
, GL_NONE
, GL_NONE
);
3334 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3335 error
= GL_OUT_OF_MEMORY
;
3339 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3342 /* if error, clear all proxy texture image parameters */
3343 clear_teximage_fields(texImage
);
3346 /* no error: store the teximage parameters */
3347 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3348 depth
, border
, internalFormat
,
3354 /* non-proxy target */
3355 struct gl_texture_object
*texObj
;
3356 struct gl_texture_image
*texImage
;
3359 _mesa_error(ctx
, error
, "glCompressedTexImage%uD", dims
);
3363 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3365 _mesa_lock_texture(ctx
, texObj
);
3367 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3369 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3370 "glCompressedTexImage%uD", dims
);
3373 gl_format texFormat
;
3375 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3377 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3378 internalFormat
, GL_NONE
,
3381 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3382 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3383 width
, height
, depth
,
3384 border
, internalFormat
, texFormat
);
3388 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3389 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3392 border
, imageSize
, data
,
3396 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3397 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3400 border
, imageSize
, data
,
3404 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3405 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3407 width
, height
, depth
,
3408 border
, imageSize
, data
,
3412 _mesa_problem(ctx
, "bad dims in compressedteximage");
3415 check_gen_mipmap(ctx
, target
, texObj
, level
);
3418 texObj
->_Complete
= GL_FALSE
;
3419 ctx
->NewState
|= _NEW_TEXTURE
;
3422 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3423 "glCompressedTexImage%uD", dims
);
3427 _mesa_unlock_texture(ctx
, texObj
);
3433 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3434 GLenum internalFormat
, GLsizei width
,
3435 GLint border
, GLsizei imageSize
,
3438 GET_CURRENT_CONTEXT(ctx
);
3439 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3440 width
, 1, 1, border
, imageSize
, data
);
3445 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3446 GLenum internalFormat
, GLsizei width
,
3447 GLsizei height
, GLint border
, GLsizei imageSize
,
3450 GET_CURRENT_CONTEXT(ctx
);
3451 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3452 width
, height
, 1, border
, imageSize
, data
);
3457 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3458 GLenum internalFormat
, GLsizei width
,
3459 GLsizei height
, GLsizei depth
, GLint border
,
3460 GLsizei imageSize
, const GLvoid
*data
)
3462 GET_CURRENT_CONTEXT(ctx
);
3463 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3464 width
, height
, depth
, border
, imageSize
, data
);
3469 * Common helper for glCompressedTexSubImage1/2/3D().
3472 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3473 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3474 GLsizei width
, GLsizei height
, GLsizei depth
,
3475 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3477 struct gl_texture_object
*texObj
;
3478 struct gl_texture_image
*texImage
;
3480 GET_CURRENT_CONTEXT(ctx
);
3481 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3483 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3484 xoffset
, 0, 0, /* pos */
3485 width
, height
, depth
, /* size */
3488 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3492 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3494 _mesa_lock_texture(ctx
, texObj
);
3496 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3499 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3500 format
, texImage
)) {
3501 /* error was recorded */
3503 else if (width
> 0 && height
> 0 && depth
> 0) {
3506 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3507 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3509 format
, imageSize
, data
,
3514 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3515 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3518 format
, imageSize
, data
,
3523 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3524 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3525 xoffset
, yoffset
, zoffset
,
3526 width
, height
, depth
,
3527 format
, imageSize
, data
,
3535 check_gen_mipmap(ctx
, target
, texObj
, level
);
3537 ctx
->NewState
|= _NEW_TEXTURE
;
3540 _mesa_unlock_texture(ctx
, texObj
);
3545 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3546 GLsizei width
, GLenum format
,
3547 GLsizei imageSize
, const GLvoid
*data
)
3549 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3550 format
, imageSize
, data
);
3555 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3556 GLint yoffset
, GLsizei width
, GLsizei height
,
3557 GLenum format
, GLsizei imageSize
,
3560 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3561 width
, height
, 1, format
, imageSize
, data
);
3566 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3567 GLint yoffset
, GLint zoffset
, GLsizei width
,
3568 GLsizei height
, GLsizei depth
, GLenum format
,
3569 GLsizei imageSize
, const GLvoid
*data
)
3571 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3572 width
, height
, depth
, format
, imageSize
, data
);
3577 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3578 * return the basic data type and number of components for the format.
3579 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3582 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3583 GLenum
*datatype
, GLuint
*components
)
3585 switch (internalFormat
) {
3587 *datatype
= GL_UNSIGNED_BYTE
;
3591 *datatype
= GL_UNSIGNED_SHORT
;
3594 case GL_ALPHA16F_ARB
:
3595 *datatype
= GL_HALF_FLOAT
;
3598 case GL_ALPHA32F_ARB
:
3599 *datatype
= GL_FLOAT
;
3602 case GL_ALPHA8I_EXT
:
3603 *datatype
= GL_BYTE
;
3606 case GL_ALPHA16I_EXT
:
3607 *datatype
= GL_SHORT
;
3610 case GL_ALPHA32I_EXT
:
3614 case GL_ALPHA8UI_EXT
:
3615 *datatype
= GL_UNSIGNED_BYTE
;
3618 case GL_ALPHA16UI_EXT
:
3619 *datatype
= GL_UNSIGNED_SHORT
;
3622 case GL_ALPHA32UI_EXT
:
3623 *datatype
= GL_UNSIGNED_INT
;
3627 *datatype
= GL_UNSIGNED_BYTE
;
3630 case GL_LUMINANCE16
:
3631 *datatype
= GL_UNSIGNED_SHORT
;
3634 case GL_LUMINANCE16F_ARB
:
3635 *datatype
= GL_HALF_FLOAT
;
3638 case GL_LUMINANCE32F_ARB
:
3639 *datatype
= GL_FLOAT
;
3642 case GL_LUMINANCE8I_EXT
:
3643 *datatype
= GL_BYTE
;
3646 case GL_LUMINANCE16I_EXT
:
3647 *datatype
= GL_SHORT
;
3650 case GL_LUMINANCE32I_EXT
:
3654 case GL_LUMINANCE8UI_EXT
:
3655 *datatype
= GL_UNSIGNED_BYTE
;
3658 case GL_LUMINANCE16UI_EXT
:
3659 *datatype
= GL_UNSIGNED_SHORT
;
3662 case GL_LUMINANCE32UI_EXT
:
3663 *datatype
= GL_UNSIGNED_INT
;
3666 case GL_LUMINANCE8_ALPHA8
:
3667 *datatype
= GL_UNSIGNED_BYTE
;
3670 case GL_LUMINANCE16_ALPHA16
:
3671 *datatype
= GL_UNSIGNED_SHORT
;
3674 case GL_LUMINANCE_ALPHA16F_ARB
:
3675 *datatype
= GL_HALF_FLOAT
;
3678 case GL_LUMINANCE_ALPHA32F_ARB
:
3679 *datatype
= GL_FLOAT
;
3682 case GL_LUMINANCE_ALPHA8I_EXT
:
3683 *datatype
= GL_BYTE
;
3686 case GL_LUMINANCE_ALPHA16I_EXT
:
3687 *datatype
= GL_SHORT
;
3690 case GL_LUMINANCE_ALPHA32I_EXT
:
3694 case GL_LUMINANCE_ALPHA8UI_EXT
:
3695 *datatype
= GL_UNSIGNED_BYTE
;
3698 case GL_LUMINANCE_ALPHA16UI_EXT
:
3699 *datatype
= GL_UNSIGNED_SHORT
;
3702 case GL_LUMINANCE_ALPHA32UI_EXT
:
3703 *datatype
= GL_UNSIGNED_INT
;
3707 *datatype
= GL_UNSIGNED_BYTE
;
3710 case GL_INTENSITY16
:
3711 *datatype
= GL_UNSIGNED_SHORT
;
3714 case GL_INTENSITY16F_ARB
:
3715 *datatype
= GL_HALF_FLOAT
;
3718 case GL_INTENSITY32F_ARB
:
3719 *datatype
= GL_FLOAT
;
3722 case GL_INTENSITY8I_EXT
:
3723 *datatype
= GL_BYTE
;
3726 case GL_INTENSITY16I_EXT
:
3727 *datatype
= GL_SHORT
;
3730 case GL_INTENSITY32I_EXT
:
3734 case GL_INTENSITY8UI_EXT
:
3735 *datatype
= GL_UNSIGNED_BYTE
;
3738 case GL_INTENSITY16UI_EXT
:
3739 *datatype
= GL_UNSIGNED_SHORT
;
3742 case GL_INTENSITY32UI_EXT
:
3743 *datatype
= GL_UNSIGNED_INT
;
3747 *datatype
= GL_UNSIGNED_BYTE
;
3751 *datatype
= GL_UNSIGNED_SHORT
;
3754 case GL_RGBA16F_ARB
:
3755 *datatype
= GL_HALF_FLOAT
;
3758 case GL_RGBA32F_ARB
:
3759 *datatype
= GL_FLOAT
;
3763 *datatype
= GL_BYTE
;
3766 case GL_RGBA16I_EXT
:
3767 *datatype
= GL_SHORT
;
3770 case GL_RGBA32I_EXT
:
3774 case GL_RGBA8UI_EXT
:
3775 *datatype
= GL_UNSIGNED_BYTE
;
3778 case GL_RGBA16UI_EXT
:
3779 *datatype
= GL_UNSIGNED_SHORT
;
3782 case GL_RGBA32UI_EXT
:
3783 *datatype
= GL_UNSIGNED_INT
;
3790 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3793 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3800 /** GL_ARB_texture_buffer_object */
3802 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3804 struct gl_texture_object
*texObj
;
3805 struct gl_buffer_object
*bufObj
;
3809 GET_CURRENT_CONTEXT(ctx
);
3810 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3812 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3813 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3817 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3818 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3822 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3823 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3828 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3829 if (buffer
&& !bufObj
) {
3830 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3834 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3836 _mesa_lock_texture(ctx
, texObj
);
3838 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3839 texObj
->BufferObjectFormat
= internalFormat
;
3841 _mesa_unlock_texture(ctx
, texObj
);