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 * Return the simple base format for a given internal texture format.
62 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
64 * \param ctx GL context.
65 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
67 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
68 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
70 * This is the format which is used during texture application (i.e. the
71 * texture format and env mode determine the arithmetic used.
73 * XXX this could be static
76 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
78 switch (internalFormat
) {
93 case GL_LUMINANCE_ALPHA
:
94 case GL_LUMINANCE4_ALPHA4
:
95 case GL_LUMINANCE6_ALPHA2
:
96 case GL_LUMINANCE8_ALPHA8
:
97 case GL_LUMINANCE12_ALPHA4
:
98 case GL_LUMINANCE12_ALPHA12
:
99 case GL_LUMINANCE16_ALPHA16
:
100 return GL_LUMINANCE_ALPHA
;
131 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
133 if (ctx
->API
!= API_OPENGL
) {
134 switch (internalFormat
) {
142 if (ctx
->Extensions
.ARB_depth_texture
) {
143 switch (internalFormat
) {
144 case GL_DEPTH_COMPONENT
:
145 case GL_DEPTH_COMPONENT16
:
146 case GL_DEPTH_COMPONENT24
:
147 case GL_DEPTH_COMPONENT32
:
148 return GL_DEPTH_COMPONENT
;
154 switch (internalFormat
) {
155 case GL_COMPRESSED_ALPHA
:
157 case GL_COMPRESSED_LUMINANCE
:
159 case GL_COMPRESSED_LUMINANCE_ALPHA
:
160 return GL_LUMINANCE_ALPHA
;
161 case GL_COMPRESSED_INTENSITY
:
163 case GL_COMPRESSED_RGB
:
165 case GL_COMPRESSED_RGBA
:
171 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
172 switch (internalFormat
) {
173 case GL_COMPRESSED_RGB_FXT1_3DFX
:
175 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
182 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
183 switch (internalFormat
) {
184 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
186 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
187 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
188 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
195 if (ctx
->Extensions
.S3_s3tc
) {
196 switch (internalFormat
) {
208 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
209 if (internalFormat
== GL_YCBCR_MESA
)
210 return GL_YCBCR_MESA
;
213 if (ctx
->Extensions
.ARB_texture_float
) {
214 switch (internalFormat
) {
215 case GL_ALPHA16F_ARB
:
216 case GL_ALPHA32F_ARB
:
224 case GL_INTENSITY16F_ARB
:
225 case GL_INTENSITY32F_ARB
:
227 case GL_LUMINANCE16F_ARB
:
228 case GL_LUMINANCE32F_ARB
:
230 case GL_LUMINANCE_ALPHA16F_ARB
:
231 case GL_LUMINANCE_ALPHA32F_ARB
:
232 return GL_LUMINANCE_ALPHA
;
238 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
239 switch (internalFormat
) {
248 if (ctx
->Extensions
.EXT_texture_snorm
) {
249 switch (internalFormat
) {
264 case GL_RGBA16_SNORM
:
267 case GL_ALPHA8_SNORM
:
268 case GL_ALPHA16_SNORM
:
270 case GL_LUMINANCE_SNORM
:
271 case GL_LUMINANCE8_SNORM
:
272 case GL_LUMINANCE16_SNORM
:
274 case GL_LUMINANCE_ALPHA_SNORM
:
275 case GL_LUMINANCE8_ALPHA8_SNORM
:
276 case GL_LUMINANCE16_ALPHA16_SNORM
:
277 return GL_LUMINANCE_ALPHA
;
278 case GL_INTENSITY_SNORM
:
279 case GL_INTENSITY8_SNORM
:
280 case GL_INTENSITY16_SNORM
:
287 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
288 switch (internalFormat
) {
289 case GL_DEPTH_STENCIL_EXT
:
290 case GL_DEPTH24_STENCIL8_EXT
:
291 return GL_DEPTH_STENCIL_EXT
;
297 #if FEATURE_EXT_texture_sRGB
298 if (ctx
->Extensions
.EXT_texture_sRGB
) {
299 switch (internalFormat
) {
302 case GL_COMPRESSED_SRGB_EXT
:
303 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
305 case GL_SRGB_ALPHA_EXT
:
306 case GL_SRGB8_ALPHA8_EXT
:
307 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
308 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
309 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
310 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
312 case GL_SLUMINANCE_ALPHA_EXT
:
313 case GL_SLUMINANCE8_ALPHA8_EXT
:
314 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
315 return GL_LUMINANCE_ALPHA
;
316 case GL_SLUMINANCE_EXT
:
317 case GL_SLUMINANCE8_EXT
:
318 case GL_COMPRESSED_SLUMINANCE_EXT
:
324 #endif /* FEATURE_EXT_texture_sRGB */
326 if (ctx
->Extensions
.EXT_texture_integer
) {
327 switch (internalFormat
) {
329 case GL_RGBA16UI_EXT
:
330 case GL_RGBA32UI_EXT
:
343 case GL_ALPHA8UI_EXT
:
344 case GL_ALPHA16UI_EXT
:
345 case GL_ALPHA32UI_EXT
:
347 case GL_ALPHA16I_EXT
:
348 case GL_ALPHA32I_EXT
:
350 case GL_INTENSITY8UI_EXT
:
351 case GL_INTENSITY16UI_EXT
:
352 case GL_INTENSITY32UI_EXT
:
353 case GL_INTENSITY8I_EXT
:
354 case GL_INTENSITY16I_EXT
:
355 case GL_INTENSITY32I_EXT
:
357 case GL_LUMINANCE8UI_EXT
:
358 case GL_LUMINANCE16UI_EXT
:
359 case GL_LUMINANCE32UI_EXT
:
360 case GL_LUMINANCE8I_EXT
:
361 case GL_LUMINANCE16I_EXT
:
362 case GL_LUMINANCE32I_EXT
:
364 case GL_LUMINANCE_ALPHA8UI_EXT
:
365 case GL_LUMINANCE_ALPHA16UI_EXT
:
366 case GL_LUMINANCE_ALPHA32UI_EXT
:
367 case GL_LUMINANCE_ALPHA8I_EXT
:
368 case GL_LUMINANCE_ALPHA16I_EXT
:
369 case GL_LUMINANCE_ALPHA32I_EXT
:
370 return GL_LUMINANCE_ALPHA
;
376 if (ctx
->Extensions
.ARB_texture_rg
) {
377 switch (internalFormat
) {
379 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
381 if (!ctx
->Extensions
.ARB_half_float_pixel
)
385 if (!ctx
->Extensions
.ARB_texture_float
)
394 if (!ctx
->Extensions
.EXT_texture_integer
)
400 case GL_COMPRESSED_RED
:
404 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
406 if (!ctx
->Extensions
.ARB_half_float_pixel
)
410 if (!ctx
->Extensions
.ARB_texture_float
)
419 if (!ctx
->Extensions
.EXT_texture_integer
)
425 case GL_COMPRESSED_RG
:
432 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
433 switch (internalFormat
) {
441 if (ctx
->Extensions
.EXT_packed_float
) {
442 switch (internalFormat
) {
443 case GL_R11F_G11F_B10F_EXT
:
450 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
451 switch (internalFormat
) {
452 case GL_DEPTH_COMPONENT32F
:
453 return GL_DEPTH_COMPONENT
;
454 case GL_DEPTH32F_STENCIL8
:
455 return GL_DEPTH_STENCIL
;
461 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
462 switch (internalFormat
) {
463 case GL_COMPRESSED_RED_RGTC1
:
464 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
466 case GL_COMPRESSED_RG_RGTC2
:
467 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
474 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
475 switch (internalFormat
) {
476 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
477 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
479 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
480 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
481 return GL_LUMINANCE_ALPHA
;
487 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
488 switch (internalFormat
) {
489 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
490 return GL_LUMINANCE_ALPHA
;
496 if (ctx
->API
== API_OPENGLES
) {
497 switch (internalFormat
) {
498 case GL_PALETTE4_RGB8_OES
:
499 case GL_PALETTE4_R5_G6_B5_OES
:
500 case GL_PALETTE8_RGB8_OES
:
501 case GL_PALETTE8_R5_G6_B5_OES
:
503 case GL_PALETTE4_RGBA8_OES
:
504 case GL_PALETTE8_RGB5_A1_OES
:
505 case GL_PALETTE4_RGBA4_OES
:
506 case GL_PALETTE4_RGB5_A1_OES
:
507 case GL_PALETTE8_RGBA8_OES
:
508 case GL_PALETTE8_RGBA4_OES
:
515 return -1; /* error */
520 * For cube map faces, return a face index in [0,5].
521 * For other targets return 0;
524 _mesa_tex_target_to_face(GLenum target
)
526 if (_mesa_is_cube_face(target
))
527 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
535 * Store a gl_texture_image pointer in a gl_texture_object structure
536 * according to the target and level parameters.
538 * \param tObj texture object.
539 * \param target texture target.
540 * \param level image level.
541 * \param texImage texture image.
544 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
545 GLenum target
, GLint level
,
546 struct gl_texture_image
*texImage
)
548 const GLuint face
= _mesa_tex_target_to_face(target
);
552 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
555 tObj
->Image
[face
][level
] = texImage
;
557 /* Set the 'back' pointer */
558 texImage
->TexObject
= tObj
;
559 texImage
->Level
= level
;
560 texImage
->Face
= face
;
565 * Allocate a texture image structure.
567 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
570 * \return a pointer to gl_texture_image struct with all fields initialized to
573 struct gl_texture_image
*
574 _mesa_new_texture_image( struct gl_context
*ctx
)
577 return CALLOC_STRUCT(gl_texture_image
);
582 * Free a gl_texture_image and associated data.
583 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
585 * \param texImage texture image.
587 * Free the texture image structure and the associated image data.
590 _mesa_delete_texture_image(struct gl_context
*ctx
,
591 struct gl_texture_image
*texImage
)
593 /* Free texImage->Data and/or any other driver-specific texture
596 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
597 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
602 * Test if a target is a proxy target.
604 * \param target texture target.
606 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
609 _mesa_is_proxy_texture(GLenum target
)
612 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
613 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
615 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
617 return (target
== GL_PROXY_TEXTURE_1D
||
618 target
== GL_PROXY_TEXTURE_2D
||
619 target
== GL_PROXY_TEXTURE_3D
||
620 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
621 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
622 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
623 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
628 * Return the proxy target which corresponds to the given texture target
631 get_proxy_target(GLenum target
)
635 case GL_PROXY_TEXTURE_1D
:
636 return GL_PROXY_TEXTURE_1D
;
638 case GL_PROXY_TEXTURE_2D
:
639 return GL_PROXY_TEXTURE_2D
;
641 case GL_PROXY_TEXTURE_3D
:
642 return GL_PROXY_TEXTURE_3D
;
643 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
644 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
645 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
646 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
647 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
648 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
649 case GL_TEXTURE_CUBE_MAP_ARB
:
650 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
651 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
652 case GL_TEXTURE_RECTANGLE_NV
:
653 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
654 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
655 case GL_TEXTURE_1D_ARRAY_EXT
:
656 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
657 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
658 case GL_TEXTURE_2D_ARRAY_EXT
:
659 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
660 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
662 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
669 * Get the texture object that corresponds to the target of the given
670 * texture unit. The target should have already been checked for validity.
672 * \param ctx GL context.
673 * \param texUnit texture unit.
674 * \param target texture target.
676 * \return pointer to the texture object on success, or NULL on failure.
678 struct gl_texture_object
*
679 _mesa_select_tex_object(struct gl_context
*ctx
,
680 const struct gl_texture_unit
*texUnit
,
683 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
684 ctx
->Extensions
.EXT_texture_array
);
688 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
689 case GL_PROXY_TEXTURE_1D
:
690 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
692 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
693 case GL_PROXY_TEXTURE_2D
:
694 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
696 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
697 case GL_PROXY_TEXTURE_3D
:
698 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
699 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
700 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
701 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
702 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
703 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
704 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
705 case GL_TEXTURE_CUBE_MAP_ARB
:
706 return ctx
->Extensions
.ARB_texture_cube_map
707 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
708 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
709 return ctx
->Extensions
.ARB_texture_cube_map
710 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
711 case GL_TEXTURE_RECTANGLE_NV
:
712 return ctx
->Extensions
.NV_texture_rectangle
713 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
714 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
715 return ctx
->Extensions
.NV_texture_rectangle
716 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
717 case GL_TEXTURE_1D_ARRAY_EXT
:
718 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
719 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
720 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
721 case GL_TEXTURE_2D_ARRAY_EXT
:
722 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
723 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
724 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
725 case GL_TEXTURE_BUFFER
:
726 return ctx
->Extensions
.ARB_texture_buffer_object
727 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
728 case GL_TEXTURE_EXTERNAL_OES
:
729 return ctx
->Extensions
.OES_EGL_image_external
730 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
732 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
739 * Return pointer to texture object for given target on current texture unit.
741 struct gl_texture_object
*
742 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
744 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
745 return _mesa_select_tex_object(ctx
, texUnit
, target
);
750 * Get a texture image pointer from a texture object, given a texture
751 * target and mipmap level. The target and level parameters should
752 * have already been error-checked.
754 * \param ctx GL context.
755 * \param texObj texture unit.
756 * \param target texture target.
757 * \param level image level.
759 * \return pointer to the texture image structure, or NULL on failure.
761 struct gl_texture_image
*
762 _mesa_select_tex_image(struct gl_context
*ctx
,
763 const struct gl_texture_object
*texObj
,
764 GLenum target
, GLint level
)
766 const GLuint face
= _mesa_tex_target_to_face(target
);
770 ASSERT(level
< MAX_TEXTURE_LEVELS
);
772 return texObj
->Image
[face
][level
];
777 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
778 * it and install it. Only return NULL if passed a bad parameter or run
781 struct gl_texture_image
*
782 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
783 GLenum target
, GLint level
)
785 struct gl_texture_image
*texImage
;
790 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
792 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
794 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
798 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
806 * Return pointer to the specified proxy texture image.
807 * Note that proxy textures are per-context, not per-texture unit.
808 * \return pointer to texture image or NULL if invalid target, invalid
809 * level, or out of memory.
811 struct gl_texture_image
*
812 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
814 struct gl_texture_image
*texImage
;
821 case GL_PROXY_TEXTURE_1D
:
822 if (level
>= ctx
->Const
.MaxTextureLevels
)
824 texIndex
= TEXTURE_1D_INDEX
;
826 case GL_PROXY_TEXTURE_2D
:
827 if (level
>= ctx
->Const
.MaxTextureLevels
)
829 texIndex
= TEXTURE_2D_INDEX
;
831 case GL_PROXY_TEXTURE_3D
:
832 if (level
>= ctx
->Const
.Max3DTextureLevels
)
834 texIndex
= TEXTURE_3D_INDEX
;
836 case GL_PROXY_TEXTURE_CUBE_MAP
:
837 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
839 texIndex
= TEXTURE_CUBE_INDEX
;
841 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
844 texIndex
= TEXTURE_RECT_INDEX
;
846 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
847 if (level
>= ctx
->Const
.MaxTextureLevels
)
849 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
851 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
852 if (level
>= ctx
->Const
.MaxTextureLevels
)
854 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
860 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
862 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
864 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
867 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
868 /* Set the 'back' pointer */
869 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
876 * Get the maximum number of allowed mipmap levels.
878 * \param ctx GL context.
879 * \param target texture target.
881 * \return the maximum number of allowed mipmap levels for the given
882 * texture target, or zero if passed a bad target.
887 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
891 case GL_PROXY_TEXTURE_1D
:
893 case GL_PROXY_TEXTURE_2D
:
894 return ctx
->Const
.MaxTextureLevels
;
896 case GL_PROXY_TEXTURE_3D
:
897 return ctx
->Const
.Max3DTextureLevels
;
898 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
899 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
900 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
901 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
902 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
903 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
904 case GL_TEXTURE_CUBE_MAP_ARB
:
905 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
906 return ctx
->Extensions
.ARB_texture_cube_map
907 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
908 case GL_TEXTURE_RECTANGLE_NV
:
909 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
910 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
911 case GL_TEXTURE_1D_ARRAY_EXT
:
912 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
913 case GL_TEXTURE_2D_ARRAY_EXT
:
914 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
915 return (ctx
->Extensions
.MESA_texture_array
||
916 ctx
->Extensions
.EXT_texture_array
)
917 ? ctx
->Const
.MaxTextureLevels
: 0;
918 case GL_TEXTURE_BUFFER
:
919 case GL_TEXTURE_EXTERNAL_OES
:
922 return 0; /* bad target */
928 * Return number of dimensions per mipmap level for the given texture target.
931 _mesa_get_texture_dimensions(GLenum target
)
935 case GL_PROXY_TEXTURE_1D
:
938 case GL_TEXTURE_RECTANGLE
:
939 case GL_TEXTURE_CUBE_MAP
:
940 case GL_PROXY_TEXTURE_2D
:
941 case GL_PROXY_TEXTURE_RECTANGLE
:
942 case GL_PROXY_TEXTURE_CUBE_MAP
:
943 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
944 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
945 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
946 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
947 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
948 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
949 case GL_TEXTURE_1D_ARRAY
:
950 case GL_PROXY_TEXTURE_1D_ARRAY
:
951 case GL_TEXTURE_EXTERNAL_OES
:
954 case GL_PROXY_TEXTURE_3D
:
955 case GL_TEXTURE_2D_ARRAY
:
956 case GL_PROXY_TEXTURE_2D_ARRAY
:
958 case GL_TEXTURE_BUFFER
:
961 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
970 #if 000 /* not used anymore */
972 * glTexImage[123]D can accept a NULL image pointer. In this case we
973 * create a texture image with unspecified image contents per the OpenGL
977 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
979 const GLint components
= _mesa_components_in_format(format
);
980 const GLint numPixels
= width
* height
* depth
;
981 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
985 * Let's see if anyone finds this. If glTexImage2D() is called with
986 * a NULL image pointer then load the texture image with something
987 * interesting instead of leaving it indeterminate.
990 static const char message
[8][32] = {
994 " X X XXXX XXX XXXXX ",
997 " X X XXXXX XXX X X ",
1001 GLubyte
*imgPtr
= data
;
1003 for (h
= 0; h
< depth
; h
++) {
1004 for (i
= 0; i
< height
; i
++) {
1005 GLint srcRow
= 7 - (i
% 8);
1006 for (j
= 0; j
< width
; j
++) {
1007 GLint srcCol
= j
% 32;
1008 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1009 for (k
= 0; k
< components
; k
++) {
1025 * Set the size and format-related fields of a gl_texture_image struct
1026 * to zero. This is used when a proxy texture test fails.
1029 clear_teximage_fields(struct gl_texture_image
*img
)
1032 img
->_BaseFormat
= 0;
1033 img
->InternalFormat
= 0;
1042 img
->HeightLog2
= 0;
1044 img
->TexFormat
= MESA_FORMAT_NONE
;
1049 * Initialize basic fields of the gl_texture_image struct.
1051 * \param ctx GL context.
1052 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1053 * \param img texture image structure to be initialized.
1054 * \param width image width.
1055 * \param height image height.
1056 * \param depth image depth.
1057 * \param border image border.
1058 * \param internalFormat internal format.
1059 * \param format the actual hardware format (one of MESA_FORMAT_*)
1061 * Fills in the fields of \p img with the given information.
1062 * Note: width, height and depth include the border.
1065 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1066 struct gl_texture_image
*img
,
1067 GLsizei width
, GLsizei height
, GLsizei depth
,
1068 GLint border
, GLenum internalFormat
,
1073 ASSERT(height
>= 0);
1076 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1077 ASSERT(img
->_BaseFormat
> 0);
1078 img
->InternalFormat
= internalFormat
;
1079 img
->Border
= border
;
1081 img
->Height
= height
;
1084 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1085 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1087 if (height
== 1) { /* 1-D texture */
1089 img
->HeightLog2
= 0;
1092 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1093 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1096 if (depth
== 1) { /* 2-D texture */
1101 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1102 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1105 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1107 img
->TexFormat
= format
;
1112 * Free and clear fields of the gl_texture_image struct.
1114 * \param ctx GL context.
1115 * \param texImage texture image structure to be cleared.
1117 * After the call, \p texImage will have no data associated with it. Its
1118 * fields are cleared so that its parent object will test incomplete.
1121 _mesa_clear_texture_image(struct gl_context
*ctx
,
1122 struct gl_texture_image
*texImage
)
1124 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1125 clear_teximage_fields(texImage
);
1130 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1131 * level, width, height and depth against the ctx->Const limits for textures.
1133 * A hardware driver might override this function if, for example, the
1134 * max 3D texture size is 512x512x64 (i.e. not a cube).
1136 * Note that width, height, depth == 0 is not an error. However, a
1137 * texture with zero width/height/depth will be considered "incomplete"
1138 * and texturing will effectively be disabled.
1140 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1141 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1142 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1143 * \param level as passed to glTexImage
1144 * \param internalFormat as passed to glTexImage
1145 * \param format as passed to glTexImage
1146 * \param type as passed to glTexImage
1147 * \param width as passed to glTexImage
1148 * \param height as passed to glTexImage
1149 * \param depth as passed to glTexImage
1150 * \param border as passed to glTexImage
1151 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1154 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1155 GLint internalFormat
, GLenum format
, GLenum type
,
1156 GLint width
, GLint height
, GLint depth
, GLint border
)
1160 (void) internalFormat
;
1165 case GL_PROXY_TEXTURE_1D
:
1166 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1167 if (width
< 2 * border
|| width
> 2 + maxSize
)
1169 if (level
>= ctx
->Const
.MaxTextureLevels
)
1171 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1172 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1177 case GL_PROXY_TEXTURE_2D
:
1178 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1179 if (width
< 2 * border
|| width
> 2 + maxSize
)
1181 if (height
< 2 * border
|| height
> 2 + maxSize
)
1183 if (level
>= ctx
->Const
.MaxTextureLevels
)
1185 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1186 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1188 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1193 case GL_PROXY_TEXTURE_3D
:
1194 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1195 if (width
< 2 * border
|| width
> 2 + maxSize
)
1197 if (height
< 2 * border
|| height
> 2 + maxSize
)
1199 if (depth
< 2 * border
|| depth
> 2 + maxSize
)
1201 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1203 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1204 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1206 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1208 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1213 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1214 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1215 if (width
< 0 || width
> maxSize
)
1217 if (height
< 0 || height
> maxSize
)
1223 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1224 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1225 if (width
< 2 * border
|| width
> 2 + maxSize
)
1227 if (height
< 2 * border
|| height
> 2 + maxSize
)
1229 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1231 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1232 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1234 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1239 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1240 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1241 if (width
< 2 * border
|| width
> 2 + maxSize
)
1243 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1245 if (level
>= ctx
->Const
.MaxTextureLevels
)
1247 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1248 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1253 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1254 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1255 if (width
< 2 * border
|| width
> 2 + maxSize
)
1257 if (height
< 2 * border
|| height
> 2 + maxSize
)
1259 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1261 if (level
>= ctx
->Const
.MaxTextureLevels
)
1263 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1264 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1266 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1272 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1279 * Check if the memory used by the texture would exceed the driver's limit.
1280 * This lets us support a max 3D texture size of 8K (for example) but
1281 * prevents allocating a full 8K x 8K x 8K texture.
1282 * XXX this could be rolled into the proxy texture size test (above) but
1283 * we don't have the actual texture internal format at that point.
1286 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1287 GLint width
, GLint height
, GLint depth
)
1289 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1290 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1291 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1297 * Helper function to determine whether a target and specific compression
1298 * format are supported.
1301 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1304 (void) intFormat
; /* not used yet */
1308 case GL_PROXY_TEXTURE_2D
:
1309 return GL_TRUE
; /* true for any compressed format so far */
1310 case GL_PROXY_TEXTURE_CUBE_MAP
:
1311 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1312 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1313 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1314 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1315 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1316 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1317 return ctx
->Extensions
.ARB_texture_cube_map
;
1318 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1319 case GL_TEXTURE_2D_ARRAY_EXT
:
1320 return (ctx
->Extensions
.MESA_texture_array
||
1321 ctx
->Extensions
.EXT_texture_array
);
1329 * Check if the given texture target value is legal for a
1330 * glTexImage1/2/3D call.
1333 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1339 case GL_PROXY_TEXTURE_1D
:
1347 case GL_PROXY_TEXTURE_2D
:
1349 case GL_PROXY_TEXTURE_CUBE_MAP
:
1350 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1351 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1352 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1353 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1354 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1355 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1356 return ctx
->Extensions
.ARB_texture_cube_map
;
1357 case GL_TEXTURE_RECTANGLE_NV
:
1358 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1359 return ctx
->Extensions
.NV_texture_rectangle
;
1360 case GL_TEXTURE_1D_ARRAY_EXT
:
1361 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1362 return (ctx
->Extensions
.MESA_texture_array
||
1363 ctx
->Extensions
.EXT_texture_array
);
1370 case GL_PROXY_TEXTURE_3D
:
1372 case GL_TEXTURE_2D_ARRAY_EXT
:
1373 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1374 return (ctx
->Extensions
.MESA_texture_array
||
1375 ctx
->Extensions
.EXT_texture_array
);
1380 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1387 * Check if the given texture target value is legal for a
1388 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1389 * The difference compared to legal_teximage_target() above is that
1390 * proxy targets are not supported.
1393 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1397 return target
== GL_TEXTURE_1D
;
1402 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1403 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1404 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1405 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1406 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1407 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1408 return ctx
->Extensions
.ARB_texture_cube_map
;
1409 case GL_TEXTURE_RECTANGLE_NV
:
1410 return ctx
->Extensions
.NV_texture_rectangle
;
1411 case GL_TEXTURE_1D_ARRAY_EXT
:
1412 return (ctx
->Extensions
.MESA_texture_array
||
1413 ctx
->Extensions
.EXT_texture_array
);
1421 case GL_TEXTURE_2D_ARRAY_EXT
:
1422 return (ctx
->Extensions
.MESA_texture_array
||
1423 ctx
->Extensions
.EXT_texture_array
);
1428 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1436 * Helper function to determine if a texture object is mutable (in terms
1437 * of GL_ARB_texture_storage).
1440 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1442 if (ctx
->Extensions
.ARB_texture_storage
) {
1443 struct gl_texture_object
*texObj
=
1444 _mesa_get_current_tex_object(ctx
, target
);
1445 return !texObj
->Immutable
;
1453 * Test the glTexImage[123]D() parameters for errors.
1455 * \param ctx GL context.
1456 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1457 * \param target texture target given by the user.
1458 * \param level image level given by the user.
1459 * \param internalFormat internal format given by the user.
1460 * \param format pixel data format given by the user.
1461 * \param type pixel data type given by the user.
1462 * \param width image width given by the user.
1463 * \param height image height given by the user.
1464 * \param depth image depth given by the user.
1465 * \param border image border given by the user.
1467 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1469 * Verifies each of the parameters against the constants specified in
1470 * __struct gl_contextRec::Const and the supported extensions, and according
1471 * to the OpenGL specification.
1474 texture_error_check( struct gl_context
*ctx
,
1475 GLuint dimensions
, GLenum target
,
1476 GLint level
, GLint internalFormat
,
1477 GLenum format
, GLenum type
,
1478 GLint width
, GLint height
,
1479 GLint depth
, GLint border
)
1481 const GLenum proxyTarget
= get_proxy_target(target
);
1482 const GLboolean isProxy
= target
== proxyTarget
;
1483 GLboolean sizeOK
= GL_TRUE
;
1484 GLboolean colorFormat
;
1486 /* Even though there are no color-index textures, we still have to support
1487 * uploading color-index data and remapping it to RGB via the
1488 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1490 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1492 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1493 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1495 _mesa_error(ctx
, GL_INVALID_VALUE
,
1496 "glTexImage%dD(level=%d)", dimensions
, level
);
1502 if (border
< 0 || border
> 1 ||
1503 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1504 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1506 _mesa_error(ctx
, GL_INVALID_VALUE
,
1507 "glTexImage%dD(border=%d)", dimensions
, border
);
1512 if (width
< 0 || height
< 0 || depth
< 0) {
1514 _mesa_error(ctx
, GL_INVALID_VALUE
,
1515 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1520 /* Do this simple check before calling the TestProxyTexImage() function */
1521 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1522 sizeOK
= (width
== height
);
1526 * Use the proxy texture driver hook to see if the size/level/etc are
1529 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1530 internalFormat
, format
,
1531 type
, width
, height
,
1535 _mesa_error(ctx
, GL_INVALID_VALUE
,
1536 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1537 dimensions
, level
, width
, height
, depth
);
1542 /* Check internalFormat */
1543 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1545 _mesa_error(ctx
, GL_INVALID_VALUE
,
1546 "glTexImage%dD(internalFormat=%s)",
1547 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1552 /* Check incoming image format and type */
1553 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1554 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1555 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1556 * GL_EXT_texture_integer extension, some combinations should generate
1557 * GL_INVALID_ENUM instead (grr!).
1560 GLenum error
= _mesa_is_integer_format(format
)
1561 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1562 _mesa_error(ctx
, error
,
1563 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1564 dimensions
, format
, type
);
1569 /* make sure internal format and format basically agree */
1570 colorFormat
= _mesa_is_color_format(format
);
1571 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1572 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1573 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1574 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1575 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1577 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1578 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1579 dimensions
, internalFormat
, format
);
1583 /* additional checks for ycbcr textures */
1584 if (internalFormat
== GL_YCBCR_MESA
) {
1585 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1586 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1587 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1589 _mesa_snprintf(message
, sizeof(message
),
1590 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1591 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1592 return GL_TRUE
; /* error */
1594 if (target
!= GL_TEXTURE_2D
&&
1595 target
!= GL_PROXY_TEXTURE_2D
&&
1596 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1597 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1599 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1605 _mesa_snprintf(message
, sizeof(message
),
1606 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1607 dimensions
, border
);
1608 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1614 /* additional checks for depth textures */
1615 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1616 /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */
1617 if (target
!= GL_TEXTURE_1D
&&
1618 target
!= GL_PROXY_TEXTURE_1D
&&
1619 target
!= GL_TEXTURE_2D
&&
1620 target
!= GL_PROXY_TEXTURE_2D
&&
1621 target
!= GL_TEXTURE_1D_ARRAY
&&
1622 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1623 target
!= GL_TEXTURE_2D_ARRAY
&&
1624 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1625 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1626 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1628 _mesa_error(ctx
, GL_INVALID_ENUM
,
1629 "glTexImage(target/internalFormat)");
1634 /* additional checks for compressed textures */
1635 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1636 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1638 _mesa_error(ctx
, GL_INVALID_ENUM
,
1639 "glTexImage%dD(target)", dimensions
);
1644 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1645 "glTexImage%dD(border!=0)", dimensions
);
1651 /* additional checks for integer textures */
1652 if (ctx
->Extensions
.EXT_texture_integer
&&
1653 (_mesa_is_integer_format(format
) !=
1654 _mesa_is_integer_format(internalFormat
))) {
1656 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1657 "glTexImage%dD(integer/non-integer format mismatch)",
1663 if (!mutable_tex_object(ctx
, target
)) {
1664 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1665 "glTexImage%dD(immutable texture)", dimensions
);
1669 /* if we get here, the parameters are OK */
1675 * Test glTexSubImage[123]D() parameters for errors.
1677 * \param ctx GL context.
1678 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1679 * \param target texture target given by the user.
1680 * \param level image level given by the user.
1681 * \param xoffset sub-image x offset given by the user.
1682 * \param yoffset sub-image y offset given by the user.
1683 * \param zoffset sub-image z offset given by the user.
1684 * \param format pixel data format given by the user.
1685 * \param type pixel data type given by the user.
1686 * \param width image width given by the user.
1687 * \param height image height given by the user.
1688 * \param depth image depth given by the user.
1690 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1692 * Verifies each of the parameters against the constants specified in
1693 * __struct gl_contextRec::Const and the supported extensions, and according
1694 * to the OpenGL specification.
1697 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1698 GLenum target
, GLint level
,
1699 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1700 GLint width
, GLint height
, GLint depth
,
1701 GLenum format
, GLenum type
)
1703 /* Basic level check */
1704 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1705 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1709 /* Check for negative sizes */
1711 _mesa_error(ctx
, GL_INVALID_VALUE
,
1712 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1715 if (height
< 0 && dimensions
> 1) {
1716 _mesa_error(ctx
, GL_INVALID_VALUE
,
1717 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1720 if (depth
< 0 && dimensions
> 2) {
1721 _mesa_error(ctx
, GL_INVALID_VALUE
,
1722 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1726 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1727 /* As with the glTexImage2D check above, the error code here
1728 * depends on texture integer.
1730 GLenum error
= _mesa_is_integer_format(format
)
1731 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1732 _mesa_error(ctx
, error
,
1733 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1734 dimensions
, format
, type
);
1743 * Do second part of glTexSubImage which depends on the destination texture.
1744 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1747 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1748 GLenum target
, GLint level
,
1749 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1750 GLint width
, GLint height
, GLint depth
,
1751 GLenum format
, GLenum type
,
1752 const struct gl_texture_image
*destTex
)
1755 /* undefined image level */
1756 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1760 if (xoffset
< -((GLint
)destTex
->Border
)) {
1761 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1765 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1766 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1770 if (dimensions
> 1) {
1771 if (yoffset
< -((GLint
)destTex
->Border
)) {
1772 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1776 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1777 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1782 if (dimensions
> 2) {
1783 if (zoffset
< -((GLint
)destTex
->Border
)) {
1784 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1787 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1788 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1793 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1796 /* do tests which depend on compression block size */
1797 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1799 /* offset must be multiple of block size */
1800 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1801 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1802 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1803 dimensions
, xoffset
, yoffset
);
1806 /* size must be multiple of bw by bh or equal to whole texture size */
1807 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1808 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1809 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1812 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1813 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1814 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1824 * Test glCopyTexImage[12]D() parameters for errors.
1826 * \param ctx GL context.
1827 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1828 * \param target texture target given by the user.
1829 * \param level image level given by the user.
1830 * \param internalFormat internal format given by the user.
1831 * \param width image width given by the user.
1832 * \param height image height given by the user.
1833 * \param border texture border.
1835 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1837 * Verifies each of the parameters against the constants specified in
1838 * __struct gl_contextRec::Const and the supported extensions, and according
1839 * to the OpenGL specification.
1842 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1843 GLenum target
, GLint level
, GLint internalFormat
,
1844 GLint width
, GLint height
, GLint border
)
1846 const GLenum proxyTarget
= get_proxy_target(target
);
1847 const GLenum type
= GL_FLOAT
;
1852 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1853 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1854 dimensions
, _mesa_lookup_enum_by_nr(target
));
1858 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1859 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1860 _mesa_error(ctx
, GL_INVALID_VALUE
,
1861 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1865 /* Check that the source buffer is complete */
1866 if (ctx
->ReadBuffer
->Name
) {
1867 if (ctx
->ReadBuffer
->_Status
== 0) {
1868 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1870 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1871 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1872 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1878 if (border
< 0 || border
> 1 ||
1879 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1880 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1884 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1885 if (baseFormat
< 0) {
1886 _mesa_error(ctx
, GL_INVALID_VALUE
,
1887 "glCopyTexImage%dD(internalFormat)", dimensions
);
1891 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
1892 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1893 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1897 /* Do size, level checking */
1898 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1899 ? (width
== height
) : 1;
1901 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1902 internalFormat
, baseFormat
,
1903 type
, width
, height
,
1907 if (dimensions
== 1) {
1908 _mesa_error(ctx
, GL_INVALID_VALUE
,
1909 "glCopyTexImage1D(width=%d)", width
);
1912 ASSERT(dimensions
== 2);
1913 _mesa_error(ctx
, GL_INVALID_VALUE
,
1914 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1919 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1920 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1921 _mesa_error(ctx
, GL_INVALID_ENUM
,
1922 "glCopyTexImage%dD(target)", dimensions
);
1926 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1927 "glCopyTexImage%dD(border!=0)", dimensions
);
1932 if (!mutable_tex_object(ctx
, target
)) {
1933 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1934 "glCopyTexImage%dD(immutable texture)", dimensions
);
1938 /* if we get here, the parameters are OK */
1944 * Test glCopyTexSubImage[12]D() parameters for errors.
1945 * Note that this is the first part of error checking.
1946 * See also copytexsubimage_error_check2() below for the second part.
1948 * \param ctx GL context.
1949 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1950 * \param target texture target given by the user.
1951 * \param level image level given by the user.
1953 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1956 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
1957 GLenum target
, GLint level
)
1959 /* Check that the source buffer is complete */
1960 if (ctx
->ReadBuffer
->Name
) {
1961 if (ctx
->ReadBuffer
->_Status
== 0) {
1962 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1964 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1965 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1966 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1971 /* check target (proxies not allowed) */
1972 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1973 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
1974 dimensions
, _mesa_lookup_enum_by_nr(target
));
1979 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1980 _mesa_error(ctx
, GL_INVALID_VALUE
,
1981 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1990 * Second part of error checking for glCopyTexSubImage[12]D().
1991 * \param xoffset sub-image x offset given by the user.
1992 * \param yoffset sub-image y offset given by the user.
1993 * \param zoffset sub-image z offset given by the user.
1994 * \param width image width given by the user.
1995 * \param height image height given by the user.
1998 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1999 GLenum target
, GLint level
,
2000 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2001 GLsizei width
, GLsizei height
,
2002 const struct gl_texture_image
*teximage
)
2004 /* check that dest tex image exists */
2006 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2007 "glCopyTexSubImage%dD(undefined texture level: %d)",
2014 _mesa_error(ctx
, GL_INVALID_VALUE
,
2015 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2018 if (dimensions
> 1 && height
< 0) {
2019 _mesa_error(ctx
, GL_INVALID_VALUE
,
2020 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2024 /* check x/y offsets */
2025 if (xoffset
< -((GLint
)teximage
->Border
)) {
2026 _mesa_error(ctx
, GL_INVALID_VALUE
,
2027 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2030 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2031 _mesa_error(ctx
, GL_INVALID_VALUE
,
2032 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2035 if (dimensions
> 1) {
2036 if (yoffset
< -((GLint
)teximage
->Border
)) {
2037 _mesa_error(ctx
, GL_INVALID_VALUE
,
2038 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2041 /* NOTE: we're adding the border here, not subtracting! */
2042 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2043 _mesa_error(ctx
, GL_INVALID_VALUE
,
2044 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2049 /* check z offset */
2050 if (dimensions
> 2) {
2051 if (zoffset
< -((GLint
)teximage
->Border
)) {
2052 _mesa_error(ctx
, GL_INVALID_VALUE
,
2053 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2056 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2057 _mesa_error(ctx
, GL_INVALID_VALUE
,
2058 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2063 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2064 /* offset must be multiple of 4 */
2065 if ((xoffset
& 3) || (yoffset
& 3)) {
2066 _mesa_error(ctx
, GL_INVALID_VALUE
,
2067 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2070 /* size must be multiple of 4 */
2071 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2072 _mesa_error(ctx
, GL_INVALID_VALUE
,
2073 "glCopyTexSubImage%dD(width)", dimensions
);
2076 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2077 _mesa_error(ctx
, GL_INVALID_VALUE
,
2078 "glCopyTexSubImage%dD(height)", dimensions
);
2083 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2084 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2088 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2089 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2090 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2091 dimensions
, teximage
->_BaseFormat
);
2095 /* If copying into an integer texture, the source buffer must also be
2098 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2099 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2100 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2101 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2102 "glCopyTexSubImage%dD(source buffer is not integer format)",
2108 /* if we get here, the parameters are OK */
2113 /** Callback info for walking over FBO hash table */
2116 struct gl_context
*ctx
;
2117 struct gl_texture_object
*texObj
;
2123 * Check render to texture callback. Called from _mesa_HashWalk().
2126 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2128 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2129 const struct cb_info
*info
= (struct cb_info
*) userData
;
2130 struct gl_context
*ctx
= info
->ctx
;
2131 const struct gl_texture_object
*texObj
= info
->texObj
;
2132 const GLuint level
= info
->level
, face
= info
->face
;
2134 /* If this is a user-created FBO */
2137 /* check if any of the FBO's attachments point to 'texObj' */
2138 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2139 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2140 if (att
->Type
== GL_TEXTURE
&&
2141 att
->Texture
== texObj
&&
2142 att
->TextureLevel
== level
&&
2143 att
->CubeMapFace
== face
) {
2144 ASSERT(_mesa_get_attachment_teximage(att
));
2145 /* Tell driver about the new renderbuffer texture */
2146 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2147 /* Mark fb status as indeterminate to force re-validation */
2156 * When a texture image is specified we have to check if it's bound to
2157 * any framebuffer objects (render to texture) in order to detect changes
2158 * in size or format since that effects FBO completeness.
2159 * Any FBOs rendering into the texture must be re-validated.
2162 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2163 GLuint face
, GLuint level
)
2165 /* Only check this texture if it's been marked as RenderToTexture */
2166 if (texObj
->_RenderToTexture
) {
2167 struct cb_info info
;
2169 info
.texObj
= texObj
;
2172 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2178 * If the texture object's GenerateMipmap flag is set and we've
2179 * changed the texture base level image, regenerate the rest of the
2180 * mipmap levels now.
2183 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2184 struct gl_texture_object
*texObj
, GLint level
)
2186 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2187 if (texObj
->GenerateMipmap
&&
2188 level
== texObj
->BaseLevel
&&
2189 level
< texObj
->MaxLevel
) {
2190 ASSERT(ctx
->Driver
.GenerateMipmap
);
2191 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2196 /** Debug helper: override the user-requested internal format */
2198 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2201 if (internalFormat
== GL_RGBA16F_ARB
||
2202 internalFormat
== GL_RGBA32F_ARB
) {
2203 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2206 else if (internalFormat
== GL_RGB16F_ARB
||
2207 internalFormat
== GL_RGB32F_ARB
) {
2208 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2211 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2212 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2213 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2214 return GL_LUMINANCE_ALPHA
;
2216 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2217 internalFormat
== GL_LUMINANCE32F_ARB
) {
2218 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2219 return GL_LUMINANCE
;
2221 else if (internalFormat
== GL_ALPHA16F_ARB
||
2222 internalFormat
== GL_ALPHA32F_ARB
) {
2223 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2227 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2228 internalFormat = GL_RGBA;
2232 return internalFormat
;
2235 return internalFormat
;
2241 * Choose the actual hardware format for a texture image.
2242 * Try to use the same format as the previous image level when possible.
2243 * Otherwise, ask the driver for the best format.
2244 * It's important to try to choose a consistant format for all levels
2245 * for efficient texture memory layout/allocation. In particular, this
2246 * comes up during automatic mipmap generation.
2249 _mesa_choose_texture_format(struct gl_context
*ctx
,
2250 struct gl_texture_object
*texObj
,
2251 GLenum target
, GLint level
,
2252 GLenum internalFormat
, GLenum format
, GLenum type
)
2256 /* see if we've already chosen a format for the previous level */
2258 struct gl_texture_image
*prevImage
=
2259 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2260 /* See if the prev level is defined and has an internal format which
2261 * matches the new internal format.
2264 prevImage
->Width
> 0 &&
2265 prevImage
->InternalFormat
== internalFormat
) {
2266 /* use the same format */
2267 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2268 return prevImage
->TexFormat
;
2272 /* choose format from scratch */
2273 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2274 ASSERT(f
!= MESA_FORMAT_NONE
);
2279 * Adjust pixel unpack params and image dimensions to strip off the
2282 * Gallium and intel don't support texture borders. They've seldem been used
2283 * and seldom been implemented correctly anyway.
2285 * \param unpackNew returns the new pixel unpack parameters
2288 strip_texture_border(GLint
*border
,
2289 GLint
*width
, GLint
*height
, GLint
*depth
,
2290 const struct gl_pixelstore_attrib
*unpack
,
2291 struct gl_pixelstore_attrib
*unpackNew
)
2293 assert(*border
> 0); /* sanity check */
2295 *unpackNew
= *unpack
;
2297 if (unpackNew
->RowLength
== 0)
2298 unpackNew
->RowLength
= *width
;
2300 if (depth
&& unpackNew
->ImageHeight
== 0)
2301 unpackNew
->ImageHeight
= *height
;
2303 unpackNew
->SkipPixels
+= *border
;
2305 unpackNew
->SkipRows
+= *border
;
2307 unpackNew
->SkipImages
+= *border
;
2309 assert(*width
>= 3);
2310 *width
= *width
- 2 * *border
;
2311 if (height
&& *height
>= 3)
2312 *height
= *height
- 2 * *border
;
2313 if (depth
&& *depth
>= 3)
2314 *depth
= *depth
- 2 * *border
;
2319 * Common code to implement all the glTexImage1D/2D/3D functions.
2322 teximage(struct gl_context
*ctx
, GLuint dims
,
2323 GLenum target
, GLint level
, GLint internalFormat
,
2324 GLsizei width
, GLsizei height
, GLsizei depth
,
2325 GLint border
, GLenum format
, GLenum type
,
2326 const GLvoid
*pixels
)
2329 struct gl_pixelstore_attrib unpack_no_border
;
2330 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2332 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2334 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2335 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2337 _mesa_lookup_enum_by_nr(target
), level
,
2338 _mesa_lookup_enum_by_nr(internalFormat
),
2339 width
, height
, depth
, border
,
2340 _mesa_lookup_enum_by_nr(format
),
2341 _mesa_lookup_enum_by_nr(type
), pixels
);
2343 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2345 /* target error checking */
2346 if (!legal_teximage_target(ctx
, dims
, target
)) {
2347 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2348 dims
, _mesa_lookup_enum_by_nr(target
));
2352 /* general error checking */
2353 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2354 format
, type
, width
, height
, depth
, border
);
2356 if (_mesa_is_proxy_texture(target
)) {
2357 /* Proxy texture: just clear or set state depending on error checking */
2358 struct gl_texture_image
*texImage
=
2359 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2362 /* when error, clear all proxy texture image parameters */
2364 clear_teximage_fields(texImage
);
2367 /* no error, set the tex image parameters */
2368 struct gl_texture_object
*texObj
=
2369 _mesa_get_current_tex_object(ctx
, target
);
2370 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2375 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2376 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2377 depth
, border
, internalFormat
,
2380 else if (texImage
) {
2381 clear_teximage_fields(texImage
);
2386 /* non-proxy target */
2387 const GLuint face
= _mesa_tex_target_to_face(target
);
2388 struct gl_texture_object
*texObj
;
2389 struct gl_texture_image
*texImage
;
2392 return; /* error was recorded */
2395 /* Allow a hardware driver to just strip out the border, to provide
2396 * reliable but slightly incorrect hardware rendering instead of
2397 * rarely-tested software fallback rendering.
2399 if (border
&& ctx
->Const
.StripTextureBorder
) {
2400 strip_texture_border(&border
, &width
, &height
, &depth
, unpack
,
2402 unpack
= &unpack_no_border
;
2405 if (ctx
->NewState
& _NEW_PIXEL
)
2406 _mesa_update_state(ctx
);
2408 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2410 _mesa_lock_texture(ctx
, texObj
);
2412 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2415 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2418 gl_format texFormat
;
2420 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2422 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2423 internalFormat
, format
,
2426 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2427 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2428 width
, height
, depth
,
2429 border
, internalFormat
, texFormat
);
2431 /* Give the texture to the driver. <pixels> may be null. */
2432 ASSERT(ctx
->Driver
.TexImage3D
);
2435 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2436 width
, border
, format
,
2437 type
, pixels
, unpack
, texObj
,
2441 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2442 width
, height
, border
, format
,
2443 type
, pixels
, unpack
, texObj
,
2447 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2448 width
, height
, depth
, border
, format
,
2449 type
, pixels
, unpack
, texObj
,
2453 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2456 check_gen_mipmap(ctx
, target
, texObj
, level
);
2458 update_fbo_texture(ctx
, texObj
, face
, level
);
2461 texObj
->_Complete
= GL_FALSE
;
2462 ctx
->NewState
|= _NEW_TEXTURE
;
2465 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2469 _mesa_unlock_texture(ctx
, texObj
);
2475 * Called from the API. Note that width includes the border.
2478 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2479 GLsizei width
, GLint border
, GLenum format
,
2480 GLenum type
, const GLvoid
*pixels
)
2482 GET_CURRENT_CONTEXT(ctx
);
2483 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2484 border
, format
, type
, pixels
);
2489 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2490 GLsizei width
, GLsizei height
, GLint border
,
2491 GLenum format
, GLenum type
,
2492 const GLvoid
*pixels
)
2494 GET_CURRENT_CONTEXT(ctx
);
2495 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2496 border
, format
, type
, pixels
);
2501 * Called by the API or display list executor.
2502 * Note that width and height include the border.
2505 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2506 GLsizei width
, GLsizei height
, GLsizei depth
,
2507 GLint border
, GLenum format
, GLenum type
,
2508 const GLvoid
*pixels
)
2510 GET_CURRENT_CONTEXT(ctx
);
2511 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2512 border
, format
, type
, pixels
);
2517 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2518 GLsizei width
, GLsizei height
, GLsizei depth
,
2519 GLint border
, GLenum format
, GLenum type
,
2520 const GLvoid
*pixels
)
2522 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2523 depth
, border
, format
, type
, pixels
);
2527 #if FEATURE_OES_EGL_image
2529 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2531 struct gl_texture_object
*texObj
;
2532 struct gl_texture_image
*texImage
;
2533 GET_CURRENT_CONTEXT(ctx
);
2534 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2536 if ((target
== GL_TEXTURE_2D
&&
2537 !ctx
->Extensions
.OES_EGL_image
) ||
2538 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2539 !ctx
->Extensions
.OES_EGL_image_external
)) {
2540 _mesa_error(ctx
, GL_INVALID_ENUM
,
2541 "glEGLImageTargetTexture2D(target=%d)", target
);
2545 if (ctx
->NewState
& _NEW_PIXEL
)
2546 _mesa_update_state(ctx
);
2548 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2549 _mesa_lock_texture(ctx
, texObj
);
2551 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2553 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2555 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2557 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2558 texObj
, texImage
, image
);
2561 texObj
->_Complete
= GL_FALSE
;
2562 ctx
->NewState
|= _NEW_TEXTURE
;
2564 _mesa_unlock_texture(ctx
, texObj
);
2572 * Implement all the glTexSubImage1/2/3D() functions.
2575 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2576 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2577 GLsizei width
, GLsizei height
, GLsizei depth
,
2578 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2580 struct gl_texture_object
*texObj
;
2581 struct gl_texture_image
*texImage
;
2583 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2585 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2586 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2588 _mesa_lookup_enum_by_nr(target
), level
,
2589 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2590 _mesa_lookup_enum_by_nr(format
),
2591 _mesa_lookup_enum_by_nr(type
), pixels
);
2593 /* check target (proxies not allowed) */
2594 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2595 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2596 dims
, _mesa_lookup_enum_by_nr(target
));
2600 if (ctx
->NewState
& _NEW_PIXEL
)
2601 _mesa_update_state(ctx
);
2603 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2604 width
, height
, depth
, format
, type
)) {
2605 return; /* error was detected */
2608 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2610 _mesa_lock_texture(ctx
, texObj
);
2612 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2614 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2615 xoffset
, yoffset
, zoffset
,
2616 width
, height
, depth
,
2617 format
, type
, texImage
)) {
2618 /* error was recorded */
2620 else if (width
> 0 && height
> 0 && depth
> 0) {
2621 /* If we have a border, offset=-1 is legal. Bias by border width. */
2624 zoffset
+= texImage
->Border
;
2627 yoffset
+= texImage
->Border
;
2630 xoffset
+= texImage
->Border
;
2635 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2637 format
, type
, pixels
,
2638 &ctx
->Unpack
, texObj
, texImage
);
2641 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2642 xoffset
, yoffset
, width
, height
,
2643 format
, type
, pixels
,
2644 &ctx
->Unpack
, texObj
, texImage
);
2647 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2648 xoffset
, yoffset
, zoffset
,
2649 width
, height
, depth
,
2650 format
, type
, pixels
,
2651 &ctx
->Unpack
, texObj
, texImage
);
2654 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2657 check_gen_mipmap(ctx
, target
, texObj
, level
);
2659 ctx
->NewState
|= _NEW_TEXTURE
;
2662 _mesa_unlock_texture(ctx
, texObj
);
2667 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2668 GLint xoffset
, GLsizei width
,
2669 GLenum format
, GLenum type
,
2670 const GLvoid
*pixels
)
2672 GET_CURRENT_CONTEXT(ctx
);
2673 texsubimage(ctx
, 1, target
, level
,
2676 format
, type
, pixels
);
2681 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2682 GLint xoffset
, GLint yoffset
,
2683 GLsizei width
, GLsizei height
,
2684 GLenum format
, GLenum type
,
2685 const GLvoid
*pixels
)
2687 GET_CURRENT_CONTEXT(ctx
);
2688 texsubimage(ctx
, 2, target
, level
,
2689 xoffset
, yoffset
, 0,
2691 format
, type
, pixels
);
2697 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2698 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2699 GLsizei width
, GLsizei height
, GLsizei depth
,
2700 GLenum format
, GLenum type
,
2701 const GLvoid
*pixels
)
2703 GET_CURRENT_CONTEXT(ctx
);
2704 texsubimage(ctx
, 3, target
, level
,
2705 xoffset
, yoffset
, zoffset
,
2706 width
, height
, depth
,
2707 format
, type
, pixels
);
2713 * Implement the glCopyTexImage1/2D() functions.
2716 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2717 GLenum target
, GLint level
, GLenum internalFormat
,
2718 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2720 struct gl_texture_object
*texObj
;
2721 struct gl_texture_image
*texImage
;
2722 const GLuint face
= _mesa_tex_target_to_face(target
);
2724 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2726 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2727 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2729 _mesa_lookup_enum_by_nr(target
), level
,
2730 _mesa_lookup_enum_by_nr(internalFormat
),
2731 x
, y
, width
, height
, border
);
2733 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2734 _mesa_update_state(ctx
);
2736 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2737 width
, height
, border
))
2740 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2742 if (border
&& ctx
->Const
.StripTextureBorder
) {
2744 width
-= border
* 2;
2747 height
-= border
* 2;
2752 _mesa_lock_texture(ctx
, texObj
);
2754 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2757 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2760 /* choose actual hw format */
2761 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2766 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2767 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2769 /* Free old texture image */
2770 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2772 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2773 border
, internalFormat
, texFormat
);
2775 /* Allocate texture memory (no pixel data yet) */
2777 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2778 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2779 &ctx
->Unpack
, texObj
, texImage
);
2782 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2783 width
, height
, border
, GL_NONE
, GL_NONE
,
2784 NULL
, &ctx
->Unpack
, texObj
, texImage
);
2787 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2790 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
, dstX
,
2794 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, dstX
, dstY
,
2795 srcX
, srcY
, width
, height
);
2798 check_gen_mipmap(ctx
, target
, texObj
, level
);
2800 update_fbo_texture(ctx
, texObj
, face
, level
);
2803 texObj
->_Complete
= GL_FALSE
;
2804 ctx
->NewState
|= _NEW_TEXTURE
;
2807 /* probably too large of image */
2808 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2812 _mesa_unlock_texture(ctx
, texObj
);
2818 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2819 GLenum internalFormat
,
2821 GLsizei width
, GLint border
)
2823 GET_CURRENT_CONTEXT(ctx
);
2824 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2830 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2831 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2834 GET_CURRENT_CONTEXT(ctx
);
2835 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2836 x
, y
, width
, height
, border
);
2842 * Implementation for glCopyTexSubImage1/2/3D() functions.
2845 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2846 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2847 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2849 struct gl_texture_object
*texObj
;
2850 struct gl_texture_image
*texImage
;
2852 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2854 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2855 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2857 _mesa_lookup_enum_by_nr(target
),
2858 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2860 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2861 _mesa_update_state(ctx
);
2863 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2866 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2868 _mesa_lock_texture(ctx
, texObj
);
2870 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2872 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2873 zoffset
, width
, height
, texImage
)) {
2874 /* error was recored */
2877 /* If we have a border, offset=-1 is legal. Bias by border width. */
2880 zoffset
+= texImage
->Border
;
2883 yoffset
+= texImage
->Border
;
2886 xoffset
+= texImage
->Border
;
2889 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2893 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2894 xoffset
, x
, y
, width
);
2897 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2899 x
, y
, width
, height
);
2902 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2903 xoffset
, yoffset
, zoffset
,
2904 x
, y
, width
, height
);
2907 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
2910 check_gen_mipmap(ctx
, target
, texObj
, level
);
2912 ctx
->NewState
|= _NEW_TEXTURE
;
2916 _mesa_unlock_texture(ctx
, texObj
);
2921 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2922 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2924 GET_CURRENT_CONTEXT(ctx
);
2925 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
2931 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2932 GLint xoffset
, GLint yoffset
,
2933 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2935 GET_CURRENT_CONTEXT(ctx
);
2936 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
2943 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2944 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2945 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2947 GET_CURRENT_CONTEXT(ctx
);
2948 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2949 x
, y
, width
, height
);
2955 /**********************************************************************/
2956 /****** Compressed Textures ******/
2957 /**********************************************************************/
2961 * Return expected size of a compressed texture.
2964 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2967 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2968 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2973 * Return compressed texture block size, in pixels.
2976 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
2978 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2979 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
2984 * Error checking for glCompressedTexImage[123]D().
2985 * \param reason returns reason for error, if any
2986 * \return error code or GL_NO_ERROR.
2989 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2990 GLenum target
, GLint level
,
2991 GLenum internalFormat
, GLsizei width
,
2992 GLsizei height
, GLsizei depth
, GLint border
,
2993 GLsizei imageSize
, char **reason
)
2995 const GLenum proxyTarget
= get_proxy_target(target
);
2996 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2998 GLenum choose_format
;
3000 GLenum proxy_format
;
3002 *reason
= ""; /* no error */
3004 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3006 return GL_INVALID_ENUM
;
3009 /* This will detect any invalid internalFormat value */
3010 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3011 *reason
= "internalFormat";
3012 return GL_INVALID_ENUM
;
3015 switch (internalFormat
) {
3017 case GL_PALETTE4_RGB8_OES
:
3018 case GL_PALETTE4_RGBA8_OES
:
3019 case GL_PALETTE4_R5_G6_B5_OES
:
3020 case GL_PALETTE4_RGBA4_OES
:
3021 case GL_PALETTE4_RGB5_A1_OES
:
3022 case GL_PALETTE8_RGB8_OES
:
3023 case GL_PALETTE8_RGBA8_OES
:
3024 case GL_PALETTE8_R5_G6_B5_OES
:
3025 case GL_PALETTE8_RGBA4_OES
:
3026 case GL_PALETTE8_RGB5_A1_OES
:
3027 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3029 proxy_format
= choose_format
;
3032 if (level
> 0 || level
< -maxLevels
) {
3034 return GL_INVALID_VALUE
;
3037 if (dimensions
!= 2) {
3038 *reason
= "compressed paletted textures must be 2D";
3039 return GL_INVALID_OPERATION
;
3042 /* Figure out the expected texture size (in bytes). This will be
3043 * checked against the actual size later.
3045 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3048 /* This is for the benefit of the TestProxyTexImage below. It expects
3049 * level to be non-negative. OES_compressed_paletted_texture uses a
3050 * weird mechanism where the level specified to glCompressedTexImage2D
3051 * is -(n-1) number of levels in the texture, and the data specifies the
3052 * complete mipmap stack. This is done to ensure the palette is the
3053 * same for all levels.
3060 choose_format
= GL_NONE
;
3061 choose_type
= GL_NONE
;
3062 proxy_format
= internalFormat
;
3065 if (level
< 0 || level
>= maxLevels
) {
3067 return GL_INVALID_VALUE
;
3070 /* Figure out the expected texture size (in bytes). This will be
3071 * checked against the actual size later.
3073 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3077 /* This should really never fail */
3078 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3079 *reason
= "internalFormat";
3080 return GL_INVALID_ENUM
;
3083 /* No compressed formats support borders at this time */
3085 *reason
= "border != 0";
3086 return GL_INVALID_VALUE
;
3089 /* For cube map, width must equal height */
3090 if (_mesa_is_cube_face(target
) && width
!= height
) {
3091 *reason
= "width != height";
3092 return GL_INVALID_VALUE
;
3095 /* check image size against compression block size */
3097 gl_format texFormat
=
3098 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3099 choose_format
, choose_type
);
3102 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3103 if ((width
> bw
&& width
% bw
> 0) ||
3104 (height
> bh
&& height
% bh
> 0)) {
3106 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3107 * generated [...] if any parameter combinations are not
3108 * supported by the specific compressed internal format.
3110 *reason
= "invalid width or height for compression format";
3111 return GL_INVALID_OPERATION
;
3115 /* check image sizes */
3116 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3117 proxy_format
, choose_format
,
3119 width
, height
, depth
, border
)) {
3120 /* See error comment above */
3121 *reason
= "invalid width, height or format";
3122 return GL_INVALID_OPERATION
;
3125 /* check image size in bytes */
3126 if (expectedSize
!= imageSize
) {
3127 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3128 * if <imageSize> is not consistent with the format, dimensions, and
3129 * contents of the specified image.
3131 *reason
= "imageSize inconsistant with width/height/format";
3132 return GL_INVALID_VALUE
;
3135 if (!mutable_tex_object(ctx
, target
)) {
3136 *reason
= "immutable texture";
3137 return GL_INVALID_OPERATION
;
3145 * Error checking for glCompressedTexSubImage[123]D().
3146 * \warning There are some bad assumptions here about the size of compressed
3147 * texture tiles (multiple of 4) used to test the validity of the
3148 * offset and size parameters.
3149 * \return error code or GL_NO_ERROR.
3152 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3153 GLenum target
, GLint level
,
3154 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3155 GLsizei width
, GLsizei height
, GLsizei depth
,
3156 GLenum format
, GLsizei imageSize
)
3158 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3162 if (dimensions
== 1) {
3163 /* 1D compressed textures not allowed */
3164 return GL_INVALID_ENUM
;
3166 else if (dimensions
== 2) {
3167 if (target
== GL_PROXY_TEXTURE_2D
) {
3168 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3170 else if (target
== GL_TEXTURE_2D
) {
3171 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3173 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3174 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3175 return GL_INVALID_ENUM
; /*target*/
3176 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3178 else if (_mesa_is_cube_face(target
)) {
3179 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3180 return GL_INVALID_ENUM
; /*target*/
3181 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3184 return GL_INVALID_ENUM
; /*target*/
3187 else if (dimensions
== 3) {
3188 /* 3D compressed textures not allowed */
3189 return GL_INVALID_ENUM
;
3192 maxTextureSize
= 1 << (maxLevels
- 1);
3194 /* this will catch any invalid compressed format token */
3195 if (!_mesa_is_compressed_format(ctx
, format
))
3196 return GL_INVALID_ENUM
;
3198 if (width
< 1 || width
> maxTextureSize
)
3199 return GL_INVALID_VALUE
;
3201 if ((height
< 1 || height
> maxTextureSize
)
3203 return GL_INVALID_VALUE
;
3205 if (level
< 0 || level
>= maxLevels
)
3206 return GL_INVALID_VALUE
;
3209 * do checks which depend on compression block size
3211 get_compressed_block_size(format
, &bw
, &bh
);
3213 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3214 return GL_INVALID_VALUE
;
3216 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3217 return GL_INVALID_VALUE
;
3219 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3220 return GL_INVALID_VALUE
;
3222 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3223 if (expectedSize
!= imageSize
)
3224 return GL_INVALID_VALUE
;
3231 * Do second part of glCompressedTexSubImage error checking.
3232 * \return GL_TRUE if error found, GL_FALSE otherwise.
3235 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3236 GLsizei width
, GLsizei height
,
3237 GLsizei depth
, GLenum format
,
3238 struct gl_texture_image
*texImage
)
3241 if ((GLint
) format
!= texImage
->InternalFormat
) {
3242 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3243 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3247 if (((width
== 1 || width
== 2) &&
3248 width
!= (GLsizei
) texImage
->Width
) ||
3249 (width
> (GLsizei
) texImage
->Width
)) {
3250 _mesa_error(ctx
, GL_INVALID_VALUE
,
3251 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3256 if (((height
== 1 || height
== 2) &&
3257 height
!= (GLsizei
) texImage
->Height
) ||
3258 (height
> (GLsizei
) texImage
->Height
)) {
3259 _mesa_error(ctx
, GL_INVALID_VALUE
,
3260 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3266 if (((depth
== 1 || depth
== 2) &&
3267 depth
!= (GLsizei
) texImage
->Depth
) ||
3268 (depth
> (GLsizei
) texImage
->Depth
)) {
3269 _mesa_error(ctx
, GL_INVALID_VALUE
,
3270 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3280 * Implementation of the glCompressedTexImage1/2/3D() functions.
3283 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3284 GLenum target
, GLint level
,
3285 GLenum internalFormat
, GLsizei width
,
3286 GLsizei height
, GLsizei depth
, GLint border
,
3287 GLsizei imageSize
, const GLvoid
*data
)
3292 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3294 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3296 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3298 _mesa_lookup_enum_by_nr(target
), level
,
3299 _mesa_lookup_enum_by_nr(internalFormat
),
3300 width
, height
, depth
, border
, imageSize
, data
);
3303 if (!legal_teximage_target(ctx
, dims
, target
)) {
3304 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3305 dims
, _mesa_lookup_enum_by_nr(target
));
3309 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3310 internalFormat
, width
, height
, depth
,
3311 border
, imageSize
, &reason
);
3314 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3319 /* XXX this is kind of a hack */
3321 switch (internalFormat
) {
3322 case GL_PALETTE4_RGB8_OES
:
3323 case GL_PALETTE4_RGBA8_OES
:
3324 case GL_PALETTE4_R5_G6_B5_OES
:
3325 case GL_PALETTE4_RGBA4_OES
:
3326 case GL_PALETTE4_RGB5_A1_OES
:
3327 case GL_PALETTE8_RGB8_OES
:
3328 case GL_PALETTE8_RGBA8_OES
:
3329 case GL_PALETTE8_R5_G6_B5_OES
:
3330 case GL_PALETTE8_RGBA4_OES
:
3331 case GL_PALETTE8_RGB5_A1_OES
:
3332 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3333 width
, height
, imageSize
, data
);
3339 if (_mesa_is_proxy_texture(target
)) {
3340 /* Proxy texture: just check for errors and update proxy state */
3341 struct gl_texture_image
*texImage
;
3344 struct gl_texture_object
*texObj
=
3345 _mesa_get_current_tex_object(ctx
, target
);
3346 gl_format texFormat
=
3347 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3348 internalFormat
, GL_NONE
, GL_NONE
);
3349 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3350 error
= GL_OUT_OF_MEMORY
;
3354 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3357 /* if error, clear all proxy texture image parameters */
3358 clear_teximage_fields(texImage
);
3361 /* no error: store the teximage parameters */
3362 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3363 depth
, border
, internalFormat
,
3369 /* non-proxy target */
3370 struct gl_texture_object
*texObj
;
3371 struct gl_texture_image
*texImage
;
3374 _mesa_error(ctx
, error
, "glCompressedTexImage%uD", dims
);
3378 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3380 _mesa_lock_texture(ctx
, texObj
);
3382 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3384 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3385 "glCompressedTexImage%uD", dims
);
3388 gl_format texFormat
;
3390 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3392 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3393 internalFormat
, GL_NONE
,
3396 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3397 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3398 width
, height
, depth
,
3399 border
, internalFormat
, texFormat
);
3403 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3404 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3407 border
, imageSize
, data
,
3411 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3412 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3415 border
, imageSize
, data
,
3419 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3420 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3422 width
, height
, depth
,
3423 border
, imageSize
, data
,
3427 _mesa_problem(ctx
, "bad dims in compressedteximage");
3430 check_gen_mipmap(ctx
, target
, texObj
, level
);
3433 texObj
->_Complete
= GL_FALSE
;
3434 ctx
->NewState
|= _NEW_TEXTURE
;
3437 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3438 "glCompressedTexImage%uD", dims
);
3442 _mesa_unlock_texture(ctx
, texObj
);
3448 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3449 GLenum internalFormat
, GLsizei width
,
3450 GLint border
, GLsizei imageSize
,
3453 GET_CURRENT_CONTEXT(ctx
);
3454 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3455 width
, 1, 1, border
, imageSize
, data
);
3460 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3461 GLenum internalFormat
, GLsizei width
,
3462 GLsizei height
, GLint border
, GLsizei imageSize
,
3465 GET_CURRENT_CONTEXT(ctx
);
3466 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3467 width
, height
, 1, border
, imageSize
, data
);
3472 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3473 GLenum internalFormat
, GLsizei width
,
3474 GLsizei height
, GLsizei depth
, GLint border
,
3475 GLsizei imageSize
, const GLvoid
*data
)
3477 GET_CURRENT_CONTEXT(ctx
);
3478 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3479 width
, height
, depth
, border
, imageSize
, data
);
3484 * Common helper for glCompressedTexSubImage1/2/3D().
3487 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3488 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3489 GLsizei width
, GLsizei height
, GLsizei depth
,
3490 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3492 struct gl_texture_object
*texObj
;
3493 struct gl_texture_image
*texImage
;
3495 GET_CURRENT_CONTEXT(ctx
);
3496 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3498 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3499 xoffset
, 0, 0, /* pos */
3500 width
, height
, depth
, /* size */
3503 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3507 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3509 _mesa_lock_texture(ctx
, texObj
);
3511 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3514 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3515 format
, texImage
)) {
3516 /* error was recorded */
3518 else if (width
> 0 && height
> 0 && depth
> 0) {
3521 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3522 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3524 format
, imageSize
, data
,
3529 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3530 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3533 format
, imageSize
, data
,
3538 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3539 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3540 xoffset
, yoffset
, zoffset
,
3541 width
, height
, depth
,
3542 format
, imageSize
, data
,
3550 check_gen_mipmap(ctx
, target
, texObj
, level
);
3552 ctx
->NewState
|= _NEW_TEXTURE
;
3555 _mesa_unlock_texture(ctx
, texObj
);
3560 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3561 GLsizei width
, GLenum format
,
3562 GLsizei imageSize
, const GLvoid
*data
)
3564 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3565 format
, imageSize
, data
);
3570 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3571 GLint yoffset
, GLsizei width
, GLsizei height
,
3572 GLenum format
, GLsizei imageSize
,
3575 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3576 width
, height
, 1, format
, imageSize
, data
);
3581 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3582 GLint yoffset
, GLint zoffset
, GLsizei width
,
3583 GLsizei height
, GLsizei depth
, GLenum format
,
3584 GLsizei imageSize
, const GLvoid
*data
)
3586 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3587 width
, height
, depth
, format
, imageSize
, data
);
3592 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3593 * return the basic data type and number of components for the format.
3594 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3597 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3598 GLenum
*datatype
, GLuint
*components
)
3600 switch (internalFormat
) {
3602 *datatype
= GL_UNSIGNED_BYTE
;
3606 *datatype
= GL_UNSIGNED_SHORT
;
3609 case GL_ALPHA16F_ARB
:
3610 *datatype
= GL_HALF_FLOAT
;
3613 case GL_ALPHA32F_ARB
:
3614 *datatype
= GL_FLOAT
;
3617 case GL_ALPHA8I_EXT
:
3618 *datatype
= GL_BYTE
;
3621 case GL_ALPHA16I_EXT
:
3622 *datatype
= GL_SHORT
;
3625 case GL_ALPHA32I_EXT
:
3629 case GL_ALPHA8UI_EXT
:
3630 *datatype
= GL_UNSIGNED_BYTE
;
3633 case GL_ALPHA16UI_EXT
:
3634 *datatype
= GL_UNSIGNED_SHORT
;
3637 case GL_ALPHA32UI_EXT
:
3638 *datatype
= GL_UNSIGNED_INT
;
3642 *datatype
= GL_UNSIGNED_BYTE
;
3645 case GL_LUMINANCE16
:
3646 *datatype
= GL_UNSIGNED_SHORT
;
3649 case GL_LUMINANCE16F_ARB
:
3650 *datatype
= GL_HALF_FLOAT
;
3653 case GL_LUMINANCE32F_ARB
:
3654 *datatype
= GL_FLOAT
;
3657 case GL_LUMINANCE8I_EXT
:
3658 *datatype
= GL_BYTE
;
3661 case GL_LUMINANCE16I_EXT
:
3662 *datatype
= GL_SHORT
;
3665 case GL_LUMINANCE32I_EXT
:
3669 case GL_LUMINANCE8UI_EXT
:
3670 *datatype
= GL_UNSIGNED_BYTE
;
3673 case GL_LUMINANCE16UI_EXT
:
3674 *datatype
= GL_UNSIGNED_SHORT
;
3677 case GL_LUMINANCE32UI_EXT
:
3678 *datatype
= GL_UNSIGNED_INT
;
3681 case GL_LUMINANCE8_ALPHA8
:
3682 *datatype
= GL_UNSIGNED_BYTE
;
3685 case GL_LUMINANCE16_ALPHA16
:
3686 *datatype
= GL_UNSIGNED_SHORT
;
3689 case GL_LUMINANCE_ALPHA16F_ARB
:
3690 *datatype
= GL_HALF_FLOAT
;
3693 case GL_LUMINANCE_ALPHA32F_ARB
:
3694 *datatype
= GL_FLOAT
;
3697 case GL_LUMINANCE_ALPHA8I_EXT
:
3698 *datatype
= GL_BYTE
;
3701 case GL_LUMINANCE_ALPHA16I_EXT
:
3702 *datatype
= GL_SHORT
;
3705 case GL_LUMINANCE_ALPHA32I_EXT
:
3709 case GL_LUMINANCE_ALPHA8UI_EXT
:
3710 *datatype
= GL_UNSIGNED_BYTE
;
3713 case GL_LUMINANCE_ALPHA16UI_EXT
:
3714 *datatype
= GL_UNSIGNED_SHORT
;
3717 case GL_LUMINANCE_ALPHA32UI_EXT
:
3718 *datatype
= GL_UNSIGNED_INT
;
3722 *datatype
= GL_UNSIGNED_BYTE
;
3725 case GL_INTENSITY16
:
3726 *datatype
= GL_UNSIGNED_SHORT
;
3729 case GL_INTENSITY16F_ARB
:
3730 *datatype
= GL_HALF_FLOAT
;
3733 case GL_INTENSITY32F_ARB
:
3734 *datatype
= GL_FLOAT
;
3737 case GL_INTENSITY8I_EXT
:
3738 *datatype
= GL_BYTE
;
3741 case GL_INTENSITY16I_EXT
:
3742 *datatype
= GL_SHORT
;
3745 case GL_INTENSITY32I_EXT
:
3749 case GL_INTENSITY8UI_EXT
:
3750 *datatype
= GL_UNSIGNED_BYTE
;
3753 case GL_INTENSITY16UI_EXT
:
3754 *datatype
= GL_UNSIGNED_SHORT
;
3757 case GL_INTENSITY32UI_EXT
:
3758 *datatype
= GL_UNSIGNED_INT
;
3762 *datatype
= GL_UNSIGNED_BYTE
;
3766 *datatype
= GL_UNSIGNED_SHORT
;
3769 case GL_RGBA16F_ARB
:
3770 *datatype
= GL_HALF_FLOAT
;
3773 case GL_RGBA32F_ARB
:
3774 *datatype
= GL_FLOAT
;
3778 *datatype
= GL_BYTE
;
3781 case GL_RGBA16I_EXT
:
3782 *datatype
= GL_SHORT
;
3785 case GL_RGBA32I_EXT
:
3789 case GL_RGBA8UI_EXT
:
3790 *datatype
= GL_UNSIGNED_BYTE
;
3793 case GL_RGBA16UI_EXT
:
3794 *datatype
= GL_UNSIGNED_SHORT
;
3797 case GL_RGBA32UI_EXT
:
3798 *datatype
= GL_UNSIGNED_INT
;
3805 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3808 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3815 /** GL_ARB_texture_buffer_object */
3817 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3819 struct gl_texture_object
*texObj
;
3820 struct gl_buffer_object
*bufObj
;
3824 GET_CURRENT_CONTEXT(ctx
);
3825 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3827 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3828 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3832 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3833 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3837 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3838 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3843 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3844 if (buffer
&& !bufObj
) {
3845 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3849 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3851 _mesa_lock_texture(ctx
, texObj
);
3853 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3854 texObj
->BufferObjectFormat
= internalFormat
;
3856 _mesa_unlock_texture(ctx
, texObj
);