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
:
342 case GL_ALPHA8UI_EXT
:
343 case GL_ALPHA16UI_EXT
:
344 case GL_ALPHA32UI_EXT
:
346 case GL_ALPHA16I_EXT
:
347 case GL_ALPHA32I_EXT
:
349 case GL_INTENSITY8UI_EXT
:
350 case GL_INTENSITY16UI_EXT
:
351 case GL_INTENSITY32UI_EXT
:
352 case GL_INTENSITY8I_EXT
:
353 case GL_INTENSITY16I_EXT
:
354 case GL_INTENSITY32I_EXT
:
356 case GL_LUMINANCE8UI_EXT
:
357 case GL_LUMINANCE16UI_EXT
:
358 case GL_LUMINANCE32UI_EXT
:
359 case GL_LUMINANCE8I_EXT
:
360 case GL_LUMINANCE16I_EXT
:
361 case GL_LUMINANCE32I_EXT
:
363 case GL_LUMINANCE_ALPHA8UI_EXT
:
364 case GL_LUMINANCE_ALPHA16UI_EXT
:
365 case GL_LUMINANCE_ALPHA32UI_EXT
:
366 case GL_LUMINANCE_ALPHA8I_EXT
:
367 case GL_LUMINANCE_ALPHA16I_EXT
:
368 case GL_LUMINANCE_ALPHA32I_EXT
:
369 return GL_LUMINANCE_ALPHA
;
375 if (ctx
->Extensions
.ARB_texture_rg
) {
376 switch (internalFormat
) {
378 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
380 if (!ctx
->Extensions
.ARB_half_float_pixel
)
384 if (!ctx
->Extensions
.ARB_texture_float
)
393 if (!ctx
->Extensions
.EXT_texture_integer
)
399 case GL_COMPRESSED_RED
:
403 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
405 if (!ctx
->Extensions
.ARB_half_float_pixel
)
409 if (!ctx
->Extensions
.ARB_texture_float
)
418 if (!ctx
->Extensions
.EXT_texture_integer
)
424 case GL_COMPRESSED_RG
:
431 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
432 switch (internalFormat
) {
440 if (ctx
->Extensions
.EXT_packed_float
) {
441 switch (internalFormat
) {
442 case GL_R11F_G11F_B10F_EXT
:
449 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
450 switch (internalFormat
) {
451 case GL_DEPTH_COMPONENT32F
:
452 return GL_DEPTH_COMPONENT
;
453 case GL_DEPTH32F_STENCIL8
:
454 return GL_DEPTH_STENCIL
;
460 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
461 switch (internalFormat
) {
462 case GL_COMPRESSED_RED_RGTC1
:
463 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
465 case GL_COMPRESSED_RG_RGTC2
:
466 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
473 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
474 switch (internalFormat
) {
475 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
476 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
478 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
479 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
480 return GL_LUMINANCE_ALPHA
;
486 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
487 switch (internalFormat
) {
488 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
489 return GL_LUMINANCE_ALPHA
;
495 if (ctx
->API
== API_OPENGLES
) {
496 switch (internalFormat
) {
497 case GL_PALETTE4_RGB8_OES
:
498 case GL_PALETTE4_R5_G6_B5_OES
:
499 case GL_PALETTE8_RGB8_OES
:
500 case GL_PALETTE8_R5_G6_B5_OES
:
502 case GL_PALETTE4_RGBA8_OES
:
503 case GL_PALETTE8_RGB5_A1_OES
:
504 case GL_PALETTE4_RGBA4_OES
:
505 case GL_PALETTE4_RGB5_A1_OES
:
506 case GL_PALETTE8_RGBA8_OES
:
507 case GL_PALETTE8_RGBA4_OES
:
514 return -1; /* error */
519 * For cube map faces, return a face index in [0,5].
520 * For other targets return 0;
523 _mesa_tex_target_to_face(GLenum target
)
525 if (_mesa_is_cube_face(target
))
526 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
534 * Store a gl_texture_image pointer in a gl_texture_object structure
535 * according to the target and level parameters.
537 * \param tObj texture object.
538 * \param target texture target.
539 * \param level image level.
540 * \param texImage texture image.
543 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
544 GLenum target
, GLint level
,
545 struct gl_texture_image
*texImage
)
547 const GLuint face
= _mesa_tex_target_to_face(target
);
551 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
554 tObj
->Image
[face
][level
] = texImage
;
556 /* Set the 'back' pointer */
557 texImage
->TexObject
= tObj
;
558 texImage
->Level
= level
;
559 texImage
->Face
= face
;
564 * Allocate a texture image structure.
566 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
569 * \return a pointer to gl_texture_image struct with all fields initialized to
572 struct gl_texture_image
*
573 _mesa_new_texture_image( struct gl_context
*ctx
)
576 return CALLOC_STRUCT(gl_texture_image
);
581 * Free a gl_texture_image and associated data.
582 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
584 * \param texImage texture image.
586 * Free the texture image structure and the associated image data.
589 _mesa_delete_texture_image(struct gl_context
*ctx
,
590 struct gl_texture_image
*texImage
)
592 /* Free texImage->Data and/or any other driver-specific texture
595 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
596 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
601 * Test if a target is a proxy target.
603 * \param target texture target.
605 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
608 _mesa_is_proxy_texture(GLenum target
)
611 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
612 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
614 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
616 return (target
== GL_PROXY_TEXTURE_1D
||
617 target
== GL_PROXY_TEXTURE_2D
||
618 target
== GL_PROXY_TEXTURE_3D
||
619 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
620 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
621 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
622 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
627 * Return the proxy target which corresponds to the given texture target
630 get_proxy_target(GLenum target
)
634 case GL_PROXY_TEXTURE_1D
:
635 return GL_PROXY_TEXTURE_1D
;
637 case GL_PROXY_TEXTURE_2D
:
638 return GL_PROXY_TEXTURE_2D
;
640 case GL_PROXY_TEXTURE_3D
:
641 return GL_PROXY_TEXTURE_3D
;
642 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
643 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
644 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
645 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
646 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
647 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
648 case GL_TEXTURE_CUBE_MAP_ARB
:
649 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
650 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
651 case GL_TEXTURE_RECTANGLE_NV
:
652 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
653 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
654 case GL_TEXTURE_1D_ARRAY_EXT
:
655 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
656 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
657 case GL_TEXTURE_2D_ARRAY_EXT
:
658 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
659 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
661 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
668 * Get the texture object that corresponds to the target of the given
669 * texture unit. The target should have already been checked for validity.
671 * \param ctx GL context.
672 * \param texUnit texture unit.
673 * \param target texture target.
675 * \return pointer to the texture object on success, or NULL on failure.
677 struct gl_texture_object
*
678 _mesa_select_tex_object(struct gl_context
*ctx
,
679 const struct gl_texture_unit
*texUnit
,
682 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
683 ctx
->Extensions
.EXT_texture_array
);
687 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
688 case GL_PROXY_TEXTURE_1D
:
689 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
691 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
692 case GL_PROXY_TEXTURE_2D
:
693 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
695 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
696 case GL_PROXY_TEXTURE_3D
:
697 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
698 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
699 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
700 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
701 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
702 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
703 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
704 case GL_TEXTURE_CUBE_MAP_ARB
:
705 return ctx
->Extensions
.ARB_texture_cube_map
706 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
707 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
708 return ctx
->Extensions
.ARB_texture_cube_map
709 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
710 case GL_TEXTURE_RECTANGLE_NV
:
711 return ctx
->Extensions
.NV_texture_rectangle
712 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
713 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
714 return ctx
->Extensions
.NV_texture_rectangle
715 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
716 case GL_TEXTURE_1D_ARRAY_EXT
:
717 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
718 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
719 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
720 case GL_TEXTURE_2D_ARRAY_EXT
:
721 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
722 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
723 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
724 case GL_TEXTURE_BUFFER
:
725 return ctx
->Extensions
.ARB_texture_buffer_object
726 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
727 case GL_TEXTURE_EXTERNAL_OES
:
728 return ctx
->Extensions
.OES_EGL_image_external
729 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
731 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
738 * Return pointer to texture object for given target on current texture unit.
740 struct gl_texture_object
*
741 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
743 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
744 return _mesa_select_tex_object(ctx
, texUnit
, target
);
749 * Get a texture image pointer from a texture object, given a texture
750 * target and mipmap level. The target and level parameters should
751 * have already been error-checked.
753 * \param ctx GL context.
754 * \param texObj texture unit.
755 * \param target texture target.
756 * \param level image level.
758 * \return pointer to the texture image structure, or NULL on failure.
760 struct gl_texture_image
*
761 _mesa_select_tex_image(struct gl_context
*ctx
,
762 const struct gl_texture_object
*texObj
,
763 GLenum target
, GLint level
)
765 const GLuint face
= _mesa_tex_target_to_face(target
);
769 ASSERT(level
< MAX_TEXTURE_LEVELS
);
771 return texObj
->Image
[face
][level
];
776 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
777 * it and install it. Only return NULL if passed a bad parameter or run
780 struct gl_texture_image
*
781 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
782 GLenum target
, GLint level
)
784 struct gl_texture_image
*texImage
;
789 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
791 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
793 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
797 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
805 * Return pointer to the specified proxy texture image.
806 * Note that proxy textures are per-context, not per-texture unit.
807 * \return pointer to texture image or NULL if invalid target, invalid
808 * level, or out of memory.
810 struct gl_texture_image
*
811 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
813 struct gl_texture_image
*texImage
;
820 case GL_PROXY_TEXTURE_1D
:
821 if (level
>= ctx
->Const
.MaxTextureLevels
)
823 texIndex
= TEXTURE_1D_INDEX
;
825 case GL_PROXY_TEXTURE_2D
:
826 if (level
>= ctx
->Const
.MaxTextureLevels
)
828 texIndex
= TEXTURE_2D_INDEX
;
830 case GL_PROXY_TEXTURE_3D
:
831 if (level
>= ctx
->Const
.Max3DTextureLevels
)
833 texIndex
= TEXTURE_3D_INDEX
;
835 case GL_PROXY_TEXTURE_CUBE_MAP
:
836 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
838 texIndex
= TEXTURE_CUBE_INDEX
;
840 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
843 texIndex
= TEXTURE_RECT_INDEX
;
845 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
846 if (level
>= ctx
->Const
.MaxTextureLevels
)
848 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
850 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
851 if (level
>= ctx
->Const
.MaxTextureLevels
)
853 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
859 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
861 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
863 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
866 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
867 /* Set the 'back' pointer */
868 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
875 * Get the maximum number of allowed mipmap levels.
877 * \param ctx GL context.
878 * \param target texture target.
880 * \return the maximum number of allowed mipmap levels for the given
881 * texture target, or zero if passed a bad target.
886 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
890 case GL_PROXY_TEXTURE_1D
:
892 case GL_PROXY_TEXTURE_2D
:
893 return ctx
->Const
.MaxTextureLevels
;
895 case GL_PROXY_TEXTURE_3D
:
896 return ctx
->Const
.Max3DTextureLevels
;
897 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
898 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
899 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
900 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
901 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
902 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
903 case GL_TEXTURE_CUBE_MAP_ARB
:
904 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
905 return ctx
->Extensions
.ARB_texture_cube_map
906 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
907 case GL_TEXTURE_RECTANGLE_NV
:
908 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
909 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
910 case GL_TEXTURE_1D_ARRAY_EXT
:
911 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
912 case GL_TEXTURE_2D_ARRAY_EXT
:
913 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
914 return (ctx
->Extensions
.MESA_texture_array
||
915 ctx
->Extensions
.EXT_texture_array
)
916 ? ctx
->Const
.MaxTextureLevels
: 0;
917 case GL_TEXTURE_BUFFER
:
918 case GL_TEXTURE_EXTERNAL_OES
:
921 return 0; /* bad target */
927 * Return number of dimensions per mipmap level for the given texture target.
930 _mesa_get_texture_dimensions(GLenum target
)
934 case GL_PROXY_TEXTURE_1D
:
937 case GL_TEXTURE_RECTANGLE
:
938 case GL_TEXTURE_CUBE_MAP
:
939 case GL_PROXY_TEXTURE_2D
:
940 case GL_PROXY_TEXTURE_RECTANGLE
:
941 case GL_PROXY_TEXTURE_CUBE_MAP
:
942 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
943 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
944 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
945 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
946 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
947 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
948 case GL_TEXTURE_1D_ARRAY
:
949 case GL_PROXY_TEXTURE_1D_ARRAY
:
950 case GL_TEXTURE_EXTERNAL_OES
:
953 case GL_PROXY_TEXTURE_3D
:
954 case GL_TEXTURE_2D_ARRAY
:
955 case GL_PROXY_TEXTURE_2D_ARRAY
:
957 case GL_TEXTURE_BUFFER
:
960 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
969 #if 000 /* not used anymore */
971 * glTexImage[123]D can accept a NULL image pointer. In this case we
972 * create a texture image with unspecified image contents per the OpenGL
976 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
978 const GLint components
= _mesa_components_in_format(format
);
979 const GLint numPixels
= width
* height
* depth
;
980 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
984 * Let's see if anyone finds this. If glTexImage2D() is called with
985 * a NULL image pointer then load the texture image with something
986 * interesting instead of leaving it indeterminate.
989 static const char message
[8][32] = {
993 " X X XXXX XXX XXXXX ",
996 " X X XXXXX XXX X X ",
1000 GLubyte
*imgPtr
= data
;
1002 for (h
= 0; h
< depth
; h
++) {
1003 for (i
= 0; i
< height
; i
++) {
1004 GLint srcRow
= 7 - (i
% 8);
1005 for (j
= 0; j
< width
; j
++) {
1006 GLint srcCol
= j
% 32;
1007 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1008 for (k
= 0; k
< components
; k
++) {
1024 * Reset the fields of a gl_texture_image struct to zero.
1026 * \param img texture image structure.
1028 * This is called when a proxy texture test fails, we set all the
1029 * image members (except DriverData) to zero.
1030 * It's also used in glTexImage[123]D as a safeguard to be sure all
1031 * required fields get initialized properly by the Driver.TexImage[123]D
1035 clear_teximage_fields(struct gl_texture_image
*img
)
1038 img
->_BaseFormat
= 0;
1039 img
->InternalFormat
= 0;
1048 img
->HeightLog2
= 0;
1050 img
->TexFormat
= MESA_FORMAT_NONE
;
1055 * Initialize basic fields of the gl_texture_image struct.
1057 * \param ctx GL context.
1058 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1059 * \param img texture image structure to be initialized.
1060 * \param width image width.
1061 * \param height image height.
1062 * \param depth image depth.
1063 * \param border image border.
1064 * \param internalFormat internal format.
1065 * \param format the actual hardware format (one of MESA_FORMAT_*)
1067 * Fills in the fields of \p img with the given information.
1068 * Note: width, height and depth include the border.
1071 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1072 struct gl_texture_image
*img
,
1073 GLsizei width
, GLsizei height
, GLsizei depth
,
1074 GLint border
, GLenum internalFormat
,
1079 ASSERT(height
>= 0);
1082 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1083 ASSERT(img
->_BaseFormat
> 0);
1084 img
->InternalFormat
= internalFormat
;
1085 img
->Border
= border
;
1087 img
->Height
= height
;
1090 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1091 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1093 if (height
== 1) { /* 1-D texture */
1095 img
->HeightLog2
= 0;
1098 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1099 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1102 if (depth
== 1) { /* 2-D texture */
1107 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1108 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1111 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1113 img
->TexFormat
= format
;
1118 * Free and clear fields of the gl_texture_image struct.
1120 * \param ctx GL context.
1121 * \param texImage texture image structure to be cleared.
1123 * After the call, \p texImage will have no data associated with it. Its
1124 * fields are cleared so that its parent object will test incomplete.
1127 _mesa_clear_texture_image(struct gl_context
*ctx
,
1128 struct gl_texture_image
*texImage
)
1130 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1131 clear_teximage_fields(texImage
);
1136 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1137 * level, width, height and depth against the ctx->Const limits for textures.
1139 * A hardware driver might override this function if, for example, the
1140 * max 3D texture size is 512x512x64 (i.e. not a cube).
1142 * Note that width, height, depth == 0 is not an error. However, a
1143 * texture with zero width/height/depth will be considered "incomplete"
1144 * and texturing will effectively be disabled.
1146 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1147 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1148 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1149 * \param level as passed to glTexImage
1150 * \param internalFormat as passed to glTexImage
1151 * \param format as passed to glTexImage
1152 * \param type as passed to glTexImage
1153 * \param width as passed to glTexImage
1154 * \param height as passed to glTexImage
1155 * \param depth as passed to glTexImage
1156 * \param border as passed to glTexImage
1157 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1160 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1161 GLint internalFormat
, GLenum format
, GLenum type
,
1162 GLint width
, GLint height
, GLint depth
, GLint border
)
1166 (void) internalFormat
;
1171 case GL_PROXY_TEXTURE_1D
:
1172 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1173 if (width
< 2 * border
|| width
> 2 + maxSize
)
1175 if (level
>= ctx
->Const
.MaxTextureLevels
)
1177 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1178 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1183 case GL_PROXY_TEXTURE_2D
:
1184 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1185 if (width
< 2 * border
|| width
> 2 + maxSize
)
1187 if (height
< 2 * border
|| height
> 2 + maxSize
)
1189 if (level
>= ctx
->Const
.MaxTextureLevels
)
1191 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1192 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1194 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1199 case GL_PROXY_TEXTURE_3D
:
1200 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1201 if (width
< 2 * border
|| width
> 2 + maxSize
)
1203 if (height
< 2 * border
|| height
> 2 + maxSize
)
1205 if (depth
< 2 * border
|| depth
> 2 + maxSize
)
1207 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1209 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1210 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1212 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1214 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1219 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1220 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1221 if (width
< 0 || width
> maxSize
)
1223 if (height
< 0 || height
> maxSize
)
1229 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1230 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1231 if (width
< 2 * border
|| width
> 2 + maxSize
)
1233 if (height
< 2 * border
|| height
> 2 + maxSize
)
1235 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1237 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1238 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1240 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1245 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1246 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1247 if (width
< 2 * border
|| width
> 2 + maxSize
)
1249 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1251 if (level
>= ctx
->Const
.MaxTextureLevels
)
1253 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1254 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1259 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1260 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1261 if (width
< 2 * border
|| width
> 2 + maxSize
)
1263 if (height
< 2 * border
|| height
> 2 + maxSize
)
1265 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1267 if (level
>= ctx
->Const
.MaxTextureLevels
)
1269 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1270 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1272 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1278 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1285 * Check if the memory used by the texture would exceed the driver's limit.
1286 * This lets us support a max 3D texture size of 8K (for example) but
1287 * prevents allocating a full 8K x 8K x 8K texture.
1288 * XXX this could be rolled into the proxy texture size test (above) but
1289 * we don't have the actual texture internal format at that point.
1292 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1293 GLint width
, GLint height
, GLint depth
)
1295 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1296 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1297 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1303 * Helper function to determine whether a target and specific compression
1304 * format are supported.
1307 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1310 (void) intFormat
; /* not used yet */
1314 case GL_PROXY_TEXTURE_2D
:
1315 return GL_TRUE
; /* true for any compressed format so far */
1316 case GL_PROXY_TEXTURE_CUBE_MAP
:
1317 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1318 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1319 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1320 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1321 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1322 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1323 return ctx
->Extensions
.ARB_texture_cube_map
;
1324 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1325 case GL_TEXTURE_2D_ARRAY_EXT
:
1326 return (ctx
->Extensions
.MESA_texture_array
||
1327 ctx
->Extensions
.EXT_texture_array
);
1335 * Check if the given texture target value is legal for a
1336 * glTexImage1/2/3D call.
1339 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1345 case GL_PROXY_TEXTURE_1D
:
1353 case GL_PROXY_TEXTURE_2D
:
1355 case GL_PROXY_TEXTURE_CUBE_MAP
:
1356 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1357 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1358 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1359 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1360 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1361 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1362 return ctx
->Extensions
.ARB_texture_cube_map
;
1363 case GL_TEXTURE_RECTANGLE_NV
:
1364 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1365 return ctx
->Extensions
.NV_texture_rectangle
;
1366 case GL_TEXTURE_1D_ARRAY_EXT
:
1367 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1368 return (ctx
->Extensions
.MESA_texture_array
||
1369 ctx
->Extensions
.EXT_texture_array
);
1376 case GL_PROXY_TEXTURE_3D
:
1378 case GL_TEXTURE_2D_ARRAY_EXT
:
1379 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1380 return (ctx
->Extensions
.MESA_texture_array
||
1381 ctx
->Extensions
.EXT_texture_array
);
1386 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1393 * Check if the given texture target value is legal for a
1394 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1395 * The difference compared to legal_teximage_target() above is that
1396 * proxy targets are not supported.
1399 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1403 return target
== GL_TEXTURE_1D
;
1408 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1409 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1410 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1411 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1412 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1413 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1414 return ctx
->Extensions
.ARB_texture_cube_map
;
1415 case GL_TEXTURE_RECTANGLE_NV
:
1416 return ctx
->Extensions
.NV_texture_rectangle
;
1417 case GL_TEXTURE_1D_ARRAY_EXT
:
1418 return (ctx
->Extensions
.MESA_texture_array
||
1419 ctx
->Extensions
.EXT_texture_array
);
1427 case GL_TEXTURE_2D_ARRAY_EXT
:
1428 return (ctx
->Extensions
.MESA_texture_array
||
1429 ctx
->Extensions
.EXT_texture_array
);
1434 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1442 * Helper function to determine if a texture object is mutable (in terms
1443 * of GL_ARB_texture_storage).
1446 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1448 if (ctx
->Extensions
.ARB_texture_storage
) {
1449 struct gl_texture_object
*texObj
=
1450 _mesa_get_current_tex_object(ctx
, target
);
1451 return !texObj
->Immutable
;
1459 * Test the glTexImage[123]D() parameters for errors.
1461 * \param ctx GL context.
1462 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1463 * \param target texture target given by the user.
1464 * \param level image level given by the user.
1465 * \param internalFormat internal format given by the user.
1466 * \param format pixel data format given by the user.
1467 * \param type pixel data type given by the user.
1468 * \param width image width given by the user.
1469 * \param height image height given by the user.
1470 * \param depth image depth given by the user.
1471 * \param border image border given by the user.
1473 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1475 * Verifies each of the parameters against the constants specified in
1476 * __struct gl_contextRec::Const and the supported extensions, and according
1477 * to the OpenGL specification.
1480 texture_error_check( struct gl_context
*ctx
,
1481 GLuint dimensions
, GLenum target
,
1482 GLint level
, GLint internalFormat
,
1483 GLenum format
, GLenum type
,
1484 GLint width
, GLint height
,
1485 GLint depth
, GLint border
)
1487 const GLenum proxyTarget
= get_proxy_target(target
);
1488 const GLboolean isProxy
= target
== proxyTarget
;
1489 GLboolean sizeOK
= GL_TRUE
;
1490 GLboolean colorFormat
;
1492 /* Even though there are no color-index textures, we still have to support
1493 * uploading color-index data and remapping it to RGB via the
1494 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1496 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1498 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1499 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1501 _mesa_error(ctx
, GL_INVALID_VALUE
,
1502 "glTexImage%dD(level=%d)", dimensions
, level
);
1508 if (border
< 0 || border
> 1 ||
1509 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1510 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1512 _mesa_error(ctx
, GL_INVALID_VALUE
,
1513 "glTexImage%dD(border=%d)", dimensions
, border
);
1518 if (width
< 0 || height
< 0 || depth
< 0) {
1520 _mesa_error(ctx
, GL_INVALID_VALUE
,
1521 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1526 /* Do this simple check before calling the TestProxyTexImage() function */
1527 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1528 sizeOK
= (width
== height
);
1532 * Use the proxy texture driver hook to see if the size/level/etc are
1535 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1536 internalFormat
, format
,
1537 type
, width
, height
,
1541 _mesa_error(ctx
, GL_INVALID_VALUE
,
1542 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1543 dimensions
, level
, width
, height
, depth
);
1548 /* Check internalFormat */
1549 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1551 _mesa_error(ctx
, GL_INVALID_VALUE
,
1552 "glTexImage%dD(internalFormat=%s)",
1553 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1558 /* Check incoming image format and type */
1559 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1560 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1561 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1562 * GL_EXT_texture_integer extension, some combinations should generate
1563 * GL_INVALID_ENUM instead (grr!).
1566 GLenum error
= _mesa_is_integer_format(format
)
1567 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1568 _mesa_error(ctx
, error
,
1569 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1570 dimensions
, format
, type
);
1575 /* make sure internal format and format basically agree */
1576 colorFormat
= _mesa_is_color_format(format
);
1577 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1578 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1579 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1580 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1581 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1583 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1584 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1585 dimensions
, internalFormat
, format
);
1589 /* additional checks for ycbcr textures */
1590 if (internalFormat
== GL_YCBCR_MESA
) {
1591 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1592 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1593 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1595 _mesa_snprintf(message
, sizeof(message
),
1596 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1597 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1598 return GL_TRUE
; /* error */
1600 if (target
!= GL_TEXTURE_2D
&&
1601 target
!= GL_PROXY_TEXTURE_2D
&&
1602 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1603 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1605 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1611 _mesa_snprintf(message
, sizeof(message
),
1612 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1613 dimensions
, border
);
1614 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1620 /* additional checks for depth textures */
1621 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1622 /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */
1623 if (target
!= GL_TEXTURE_1D
&&
1624 target
!= GL_PROXY_TEXTURE_1D
&&
1625 target
!= GL_TEXTURE_2D
&&
1626 target
!= GL_PROXY_TEXTURE_2D
&&
1627 target
!= GL_TEXTURE_1D_ARRAY
&&
1628 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1629 target
!= GL_TEXTURE_2D_ARRAY
&&
1630 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1631 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1632 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1634 _mesa_error(ctx
, GL_INVALID_ENUM
,
1635 "glTexImage(target/internalFormat)");
1640 /* additional checks for compressed textures */
1641 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1642 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1644 _mesa_error(ctx
, GL_INVALID_ENUM
,
1645 "glTexImage%dD(target)", dimensions
);
1650 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1651 "glTexImage%dD(border!=0)", dimensions
);
1657 /* additional checks for integer textures */
1658 if (ctx
->Extensions
.EXT_texture_integer
&&
1659 (_mesa_is_integer_format(format
) !=
1660 _mesa_is_integer_format(internalFormat
))) {
1662 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1663 "glTexImage%dD(integer/non-integer format mismatch)",
1669 if (!mutable_tex_object(ctx
, target
)) {
1670 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1671 "glTexImage%dD(immutable texture)", dimensions
);
1675 /* if we get here, the parameters are OK */
1681 * Test glTexSubImage[123]D() parameters for errors.
1683 * \param ctx GL context.
1684 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1685 * \param target texture target given by the user.
1686 * \param level image level given by the user.
1687 * \param xoffset sub-image x offset given by the user.
1688 * \param yoffset sub-image y offset given by the user.
1689 * \param zoffset sub-image z offset given by the user.
1690 * \param format pixel data format given by the user.
1691 * \param type pixel data type given by the user.
1692 * \param width image width given by the user.
1693 * \param height image height given by the user.
1694 * \param depth image depth given by the user.
1696 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1698 * Verifies each of the parameters against the constants specified in
1699 * __struct gl_contextRec::Const and the supported extensions, and according
1700 * to the OpenGL specification.
1703 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1704 GLenum target
, GLint level
,
1705 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1706 GLint width
, GLint height
, GLint depth
,
1707 GLenum format
, GLenum type
)
1709 /* Basic level check */
1710 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1711 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1715 /* Check for negative sizes */
1717 _mesa_error(ctx
, GL_INVALID_VALUE
,
1718 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1721 if (height
< 0 && dimensions
> 1) {
1722 _mesa_error(ctx
, GL_INVALID_VALUE
,
1723 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1726 if (depth
< 0 && dimensions
> 2) {
1727 _mesa_error(ctx
, GL_INVALID_VALUE
,
1728 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1732 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1733 /* As with the glTexImage2D check above, the error code here
1734 * depends on texture integer.
1736 GLenum error
= _mesa_is_integer_format(format
)
1737 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1738 _mesa_error(ctx
, error
,
1739 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1740 dimensions
, format
, type
);
1749 * Do second part of glTexSubImage which depends on the destination texture.
1750 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1753 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1754 GLenum target
, GLint level
,
1755 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1756 GLint width
, GLint height
, GLint depth
,
1757 GLenum format
, GLenum type
,
1758 const struct gl_texture_image
*destTex
)
1761 /* undefined image level */
1762 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1766 if (xoffset
< -((GLint
)destTex
->Border
)) {
1767 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1771 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1772 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1776 if (dimensions
> 1) {
1777 if (yoffset
< -((GLint
)destTex
->Border
)) {
1778 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1782 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1783 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1788 if (dimensions
> 2) {
1789 if (zoffset
< -((GLint
)destTex
->Border
)) {
1790 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1793 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1794 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1799 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1802 /* do tests which depend on compression block size */
1803 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1805 /* offset must be multiple of block size */
1806 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1807 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1808 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1809 dimensions
, xoffset
, yoffset
);
1812 /* size must be multiple of bw by bh or equal to whole texture size */
1813 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1814 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1815 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1818 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1819 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1820 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1830 * Test glCopyTexImage[12]D() parameters for errors.
1832 * \param ctx GL context.
1833 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1834 * \param target texture target given by the user.
1835 * \param level image level given by the user.
1836 * \param internalFormat internal format given by the user.
1837 * \param width image width given by the user.
1838 * \param height image height given by the user.
1839 * \param border texture border.
1841 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1843 * Verifies each of the parameters against the constants specified in
1844 * __struct gl_contextRec::Const and the supported extensions, and according
1845 * to the OpenGL specification.
1848 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1849 GLenum target
, GLint level
, GLint internalFormat
,
1850 GLint width
, GLint height
, GLint border
)
1852 const GLenum proxyTarget
= get_proxy_target(target
);
1853 const GLenum type
= GL_FLOAT
;
1858 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1859 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1860 dimensions
, _mesa_lookup_enum_by_nr(target
));
1864 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1865 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1866 _mesa_error(ctx
, GL_INVALID_VALUE
,
1867 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1871 /* Check that the source buffer is complete */
1872 if (ctx
->ReadBuffer
->Name
) {
1873 if (ctx
->ReadBuffer
->_Status
== 0) {
1874 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1876 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1877 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1878 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1884 if (border
< 0 || border
> 1 ||
1885 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1886 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1890 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1891 if (baseFormat
< 0) {
1892 _mesa_error(ctx
, GL_INVALID_VALUE
,
1893 "glCopyTexImage%dD(internalFormat)", dimensions
);
1897 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
1898 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1899 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1903 /* Do size, level checking */
1904 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1905 ? (width
== height
) : 1;
1907 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1908 internalFormat
, baseFormat
,
1909 type
, width
, height
,
1913 if (dimensions
== 1) {
1914 _mesa_error(ctx
, GL_INVALID_VALUE
,
1915 "glCopyTexImage1D(width=%d)", width
);
1918 ASSERT(dimensions
== 2);
1919 _mesa_error(ctx
, GL_INVALID_VALUE
,
1920 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1925 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1926 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1927 _mesa_error(ctx
, GL_INVALID_ENUM
,
1928 "glCopyTexImage%dD(target)", dimensions
);
1932 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1933 "glCopyTexImage%dD(border!=0)", dimensions
);
1938 if (!mutable_tex_object(ctx
, target
)) {
1939 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1940 "glCopyTexImage%dD(immutable texture)", dimensions
);
1944 /* if we get here, the parameters are OK */
1950 * Test glCopyTexSubImage[12]D() parameters for errors.
1951 * Note that this is the first part of error checking.
1952 * See also copytexsubimage_error_check2() below for the second part.
1954 * \param ctx GL context.
1955 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1956 * \param target texture target given by the user.
1957 * \param level image level given by the user.
1959 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1962 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
1963 GLenum target
, GLint level
)
1965 /* Check that the source buffer is complete */
1966 if (ctx
->ReadBuffer
->Name
) {
1967 if (ctx
->ReadBuffer
->_Status
== 0) {
1968 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1970 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1971 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1972 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1977 /* check target (proxies not allowed) */
1978 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1979 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
1980 dimensions
, _mesa_lookup_enum_by_nr(target
));
1985 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1986 _mesa_error(ctx
, GL_INVALID_VALUE
,
1987 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
1996 * Second part of error checking for glCopyTexSubImage[12]D().
1997 * \param xoffset sub-image x offset given by the user.
1998 * \param yoffset sub-image y offset given by the user.
1999 * \param zoffset sub-image z offset given by the user.
2000 * \param width image width given by the user.
2001 * \param height image height given by the user.
2004 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2005 GLenum target
, GLint level
,
2006 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2007 GLsizei width
, GLsizei height
,
2008 const struct gl_texture_image
*teximage
)
2010 /* check that dest tex image exists */
2012 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2013 "glCopyTexSubImage%dD(undefined texture level: %d)",
2020 _mesa_error(ctx
, GL_INVALID_VALUE
,
2021 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2024 if (dimensions
> 1 && height
< 0) {
2025 _mesa_error(ctx
, GL_INVALID_VALUE
,
2026 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2030 /* check x/y offsets */
2031 if (xoffset
< -((GLint
)teximage
->Border
)) {
2032 _mesa_error(ctx
, GL_INVALID_VALUE
,
2033 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2036 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2037 _mesa_error(ctx
, GL_INVALID_VALUE
,
2038 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2041 if (dimensions
> 1) {
2042 if (yoffset
< -((GLint
)teximage
->Border
)) {
2043 _mesa_error(ctx
, GL_INVALID_VALUE
,
2044 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2047 /* NOTE: we're adding the border here, not subtracting! */
2048 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2049 _mesa_error(ctx
, GL_INVALID_VALUE
,
2050 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2055 /* check z offset */
2056 if (dimensions
> 2) {
2057 if (zoffset
< -((GLint
)teximage
->Border
)) {
2058 _mesa_error(ctx
, GL_INVALID_VALUE
,
2059 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2062 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2063 _mesa_error(ctx
, GL_INVALID_VALUE
,
2064 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2069 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2070 /* offset must be multiple of 4 */
2071 if ((xoffset
& 3) || (yoffset
& 3)) {
2072 _mesa_error(ctx
, GL_INVALID_VALUE
,
2073 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2076 /* size must be multiple of 4 */
2077 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2078 _mesa_error(ctx
, GL_INVALID_VALUE
,
2079 "glCopyTexSubImage%dD(width)", dimensions
);
2082 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2083 _mesa_error(ctx
, GL_INVALID_VALUE
,
2084 "glCopyTexSubImage%dD(height)", dimensions
);
2089 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2090 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2094 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2095 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2096 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2097 dimensions
, teximage
->_BaseFormat
);
2101 /* If copying into an integer texture, the source buffer must also be
2104 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2105 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2106 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2107 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2108 "glCopyTexSubImage%dD(source buffer is not integer format)",
2114 /* if we get here, the parameters are OK */
2119 /** Callback info for walking over FBO hash table */
2122 struct gl_context
*ctx
;
2123 struct gl_texture_object
*texObj
;
2129 * Check render to texture callback. Called from _mesa_HashWalk().
2132 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2134 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2135 const struct cb_info
*info
= (struct cb_info
*) userData
;
2136 struct gl_context
*ctx
= info
->ctx
;
2137 const struct gl_texture_object
*texObj
= info
->texObj
;
2138 const GLuint level
= info
->level
, face
= info
->face
;
2140 /* If this is a user-created FBO */
2143 /* check if any of the FBO's attachments point to 'texObj' */
2144 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2145 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2146 if (att
->Type
== GL_TEXTURE
&&
2147 att
->Texture
== texObj
&&
2148 att
->TextureLevel
== level
&&
2149 att
->CubeMapFace
== face
) {
2150 ASSERT(_mesa_get_attachment_teximage(att
));
2151 /* Tell driver about the new renderbuffer texture */
2152 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2153 /* Mark fb status as indeterminate to force re-validation */
2162 * When a texture image is specified we have to check if it's bound to
2163 * any framebuffer objects (render to texture) in order to detect changes
2164 * in size or format since that effects FBO completeness.
2165 * Any FBOs rendering into the texture must be re-validated.
2168 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2169 GLuint face
, GLuint level
)
2171 /* Only check this texture if it's been marked as RenderToTexture */
2172 if (texObj
->_RenderToTexture
) {
2173 struct cb_info info
;
2175 info
.texObj
= texObj
;
2178 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2184 * If the texture object's GenerateMipmap flag is set and we've
2185 * changed the texture base level image, regenerate the rest of the
2186 * mipmap levels now.
2189 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2190 struct gl_texture_object
*texObj
, GLint level
)
2192 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2193 if (texObj
->GenerateMipmap
&&
2194 level
== texObj
->BaseLevel
&&
2195 level
< texObj
->MaxLevel
) {
2196 ASSERT(ctx
->Driver
.GenerateMipmap
);
2197 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2202 /** Debug helper: override the user-requested internal format */
2204 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2207 if (internalFormat
== GL_RGBA16F_ARB
||
2208 internalFormat
== GL_RGBA32F_ARB
) {
2209 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2212 else if (internalFormat
== GL_RGB16F_ARB
||
2213 internalFormat
== GL_RGB32F_ARB
) {
2214 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2217 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2218 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2219 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2220 return GL_LUMINANCE_ALPHA
;
2222 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2223 internalFormat
== GL_LUMINANCE32F_ARB
) {
2224 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2225 return GL_LUMINANCE
;
2227 else if (internalFormat
== GL_ALPHA16F_ARB
||
2228 internalFormat
== GL_ALPHA32F_ARB
) {
2229 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2233 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2234 internalFormat = GL_RGBA;
2238 return internalFormat
;
2241 return internalFormat
;
2247 * Choose the actual hardware format for a texture image.
2248 * Try to use the same format as the previous image level when possible.
2249 * Otherwise, ask the driver for the best format.
2250 * It's important to try to choose a consistant format for all levels
2251 * for efficient texture memory layout/allocation. In particular, this
2252 * comes up during automatic mipmap generation.
2255 _mesa_choose_texture_format(struct gl_context
*ctx
,
2256 struct gl_texture_object
*texObj
,
2257 GLenum target
, GLint level
,
2258 GLenum internalFormat
, GLenum format
, GLenum type
)
2262 /* see if we've already chosen a format for the previous level */
2264 struct gl_texture_image
*prevImage
=
2265 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2266 /* See if the prev level is defined and has an internal format which
2267 * matches the new internal format.
2270 prevImage
->Width
> 0 &&
2271 prevImage
->InternalFormat
== internalFormat
) {
2272 /* use the same format */
2273 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2274 return prevImage
->TexFormat
;
2278 /* choose format from scratch */
2279 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2280 ASSERT(f
!= MESA_FORMAT_NONE
);
2285 * Adjust pixel unpack params and image dimensions to strip off the
2288 * Gallium and intel don't support texture borders. They've seldem been used
2289 * and seldom been implemented correctly anyway.
2291 * \param unpackNew returns the new pixel unpack parameters
2294 strip_texture_border(GLint
*border
,
2295 GLint
*width
, GLint
*height
, GLint
*depth
,
2296 const struct gl_pixelstore_attrib
*unpack
,
2297 struct gl_pixelstore_attrib
*unpackNew
)
2299 assert(*border
> 0); /* sanity check */
2301 *unpackNew
= *unpack
;
2303 if (unpackNew
->RowLength
== 0)
2304 unpackNew
->RowLength
= *width
;
2306 if (depth
&& unpackNew
->ImageHeight
== 0)
2307 unpackNew
->ImageHeight
= *height
;
2309 unpackNew
->SkipPixels
+= *border
;
2311 unpackNew
->SkipRows
+= *border
;
2313 unpackNew
->SkipImages
+= *border
;
2315 assert(*width
>= 3);
2316 *width
= *width
- 2 * *border
;
2317 if (height
&& *height
>= 3)
2318 *height
= *height
- 2 * *border
;
2319 if (depth
&& *depth
>= 3)
2320 *depth
= *depth
- 2 * *border
;
2325 * Common code to implement all the glTexImage1D/2D/3D functions.
2328 teximage(struct gl_context
*ctx
, GLuint dims
,
2329 GLenum target
, GLint level
, GLint internalFormat
,
2330 GLsizei width
, GLsizei height
, GLsizei depth
,
2331 GLint border
, GLenum format
, GLenum type
,
2332 const GLvoid
*pixels
)
2335 struct gl_pixelstore_attrib unpack_no_border
;
2336 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2338 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2340 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2341 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2343 _mesa_lookup_enum_by_nr(target
), level
,
2344 _mesa_lookup_enum_by_nr(internalFormat
),
2345 width
, height
, depth
, border
,
2346 _mesa_lookup_enum_by_nr(format
),
2347 _mesa_lookup_enum_by_nr(type
), pixels
);
2349 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2351 /* target error checking */
2352 if (!legal_teximage_target(ctx
, dims
, target
)) {
2353 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2354 dims
, _mesa_lookup_enum_by_nr(target
));
2358 /* general error checking */
2359 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2360 format
, type
, width
, height
, depth
, border
);
2362 if (_mesa_is_proxy_texture(target
)) {
2363 /* Proxy texture: just clear or set state depending on error checking */
2364 struct gl_texture_image
*texImage
=
2365 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2368 /* when error, clear all proxy texture image parameters */
2370 clear_teximage_fields(texImage
);
2373 /* no error, set the tex image parameters */
2374 struct gl_texture_object
*texObj
=
2375 _mesa_get_current_tex_object(ctx
, target
);
2376 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2381 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2382 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2383 depth
, border
, internalFormat
,
2386 else if (texImage
) {
2387 clear_teximage_fields(texImage
);
2392 /* non-proxy target */
2393 const GLuint face
= _mesa_tex_target_to_face(target
);
2394 struct gl_texture_object
*texObj
;
2395 struct gl_texture_image
*texImage
;
2398 return; /* error was recorded */
2401 /* Allow a hardware driver to just strip out the border, to provide
2402 * reliable but slightly incorrect hardware rendering instead of
2403 * rarely-tested software fallback rendering.
2405 if (border
&& ctx
->Const
.StripTextureBorder
) {
2406 strip_texture_border(&border
, &width
, &height
, &depth
, unpack
,
2408 unpack
= &unpack_no_border
;
2411 if (ctx
->NewState
& _NEW_PIXEL
)
2412 _mesa_update_state(ctx
);
2414 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2416 _mesa_lock_texture(ctx
, texObj
);
2418 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2421 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2424 gl_format texFormat
;
2426 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2428 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2429 internalFormat
, format
,
2432 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2433 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2434 width
, height
, depth
,
2435 border
, internalFormat
, texFormat
);
2437 /* Give the texture to the driver. <pixels> may be null. */
2438 ASSERT(ctx
->Driver
.TexImage3D
);
2441 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2442 width
, border
, format
,
2443 type
, pixels
, unpack
, texObj
,
2447 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2448 width
, height
, border
, format
,
2449 type
, pixels
, unpack
, texObj
,
2453 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2454 width
, height
, depth
, border
, format
,
2455 type
, pixels
, unpack
, texObj
,
2459 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2462 check_gen_mipmap(ctx
, target
, texObj
, level
);
2464 update_fbo_texture(ctx
, texObj
, face
, level
);
2467 texObj
->_Complete
= GL_FALSE
;
2468 ctx
->NewState
|= _NEW_TEXTURE
;
2471 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2475 _mesa_unlock_texture(ctx
, texObj
);
2481 * Called from the API. Note that width includes the border.
2484 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2485 GLsizei width
, GLint border
, GLenum format
,
2486 GLenum type
, const GLvoid
*pixels
)
2488 GET_CURRENT_CONTEXT(ctx
);
2489 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2490 border
, format
, type
, pixels
);
2495 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2496 GLsizei width
, GLsizei height
, GLint border
,
2497 GLenum format
, GLenum type
,
2498 const GLvoid
*pixels
)
2500 GET_CURRENT_CONTEXT(ctx
);
2501 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2502 border
, format
, type
, pixels
);
2507 * Called by the API or display list executor.
2508 * Note that width and height include the border.
2511 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2512 GLsizei width
, GLsizei height
, GLsizei depth
,
2513 GLint border
, GLenum format
, GLenum type
,
2514 const GLvoid
*pixels
)
2516 GET_CURRENT_CONTEXT(ctx
);
2517 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2518 border
, format
, type
, pixels
);
2523 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2524 GLsizei width
, GLsizei height
, GLsizei depth
,
2525 GLint border
, GLenum format
, GLenum type
,
2526 const GLvoid
*pixels
)
2528 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2529 depth
, border
, format
, type
, pixels
);
2533 #if FEATURE_OES_EGL_image
2535 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2537 struct gl_texture_object
*texObj
;
2538 struct gl_texture_image
*texImage
;
2539 GET_CURRENT_CONTEXT(ctx
);
2540 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2542 if ((target
== GL_TEXTURE_2D
&&
2543 !ctx
->Extensions
.OES_EGL_image
) ||
2544 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2545 !ctx
->Extensions
.OES_EGL_image_external
)) {
2546 _mesa_error(ctx
, GL_INVALID_ENUM
,
2547 "glEGLImageTargetTexture2D(target=%d)", target
);
2551 if (ctx
->NewState
& _NEW_PIXEL
)
2552 _mesa_update_state(ctx
);
2554 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2555 _mesa_lock_texture(ctx
, texObj
);
2557 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2559 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2561 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2563 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2564 texObj
, texImage
, image
);
2567 texObj
->_Complete
= GL_FALSE
;
2568 ctx
->NewState
|= _NEW_TEXTURE
;
2570 _mesa_unlock_texture(ctx
, texObj
);
2578 * Implement all the glTexSubImage1/2/3D() functions.
2581 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2582 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2583 GLsizei width
, GLsizei height
, GLsizei depth
,
2584 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2586 struct gl_texture_object
*texObj
;
2587 struct gl_texture_image
*texImage
;
2589 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2591 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2592 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2594 _mesa_lookup_enum_by_nr(target
), level
,
2595 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2596 _mesa_lookup_enum_by_nr(format
),
2597 _mesa_lookup_enum_by_nr(type
), pixels
);
2599 /* check target (proxies not allowed) */
2600 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2601 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2602 dims
, _mesa_lookup_enum_by_nr(target
));
2606 if (ctx
->NewState
& _NEW_PIXEL
)
2607 _mesa_update_state(ctx
);
2609 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2610 width
, height
, depth
, format
, type
)) {
2611 return; /* error was detected */
2614 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2616 _mesa_lock_texture(ctx
, texObj
);
2618 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2620 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2621 xoffset
, yoffset
, zoffset
,
2622 width
, height
, depth
,
2623 format
, type
, texImage
)) {
2624 /* error was recorded */
2626 else if (width
> 0 && height
> 0 && depth
> 0) {
2627 /* If we have a border, offset=-1 is legal. Bias by border width. */
2630 zoffset
+= texImage
->Border
;
2633 yoffset
+= texImage
->Border
;
2636 xoffset
+= texImage
->Border
;
2641 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2643 format
, type
, pixels
,
2644 &ctx
->Unpack
, texObj
, texImage
);
2647 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2648 xoffset
, yoffset
, width
, height
,
2649 format
, type
, pixels
,
2650 &ctx
->Unpack
, texObj
, texImage
);
2653 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2654 xoffset
, yoffset
, zoffset
,
2655 width
, height
, depth
,
2656 format
, type
, pixels
,
2657 &ctx
->Unpack
, texObj
, texImage
);
2660 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2663 check_gen_mipmap(ctx
, target
, texObj
, level
);
2665 ctx
->NewState
|= _NEW_TEXTURE
;
2668 _mesa_unlock_texture(ctx
, texObj
);
2673 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2674 GLint xoffset
, GLsizei width
,
2675 GLenum format
, GLenum type
,
2676 const GLvoid
*pixels
)
2678 GET_CURRENT_CONTEXT(ctx
);
2679 texsubimage(ctx
, 1, target
, level
,
2682 format
, type
, pixels
);
2687 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2688 GLint xoffset
, GLint yoffset
,
2689 GLsizei width
, GLsizei height
,
2690 GLenum format
, GLenum type
,
2691 const GLvoid
*pixels
)
2693 GET_CURRENT_CONTEXT(ctx
);
2694 texsubimage(ctx
, 2, target
, level
,
2695 xoffset
, yoffset
, 0,
2697 format
, type
, pixels
);
2703 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2704 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2705 GLsizei width
, GLsizei height
, GLsizei depth
,
2706 GLenum format
, GLenum type
,
2707 const GLvoid
*pixels
)
2709 GET_CURRENT_CONTEXT(ctx
);
2710 texsubimage(ctx
, 3, target
, level
,
2711 xoffset
, yoffset
, zoffset
,
2712 width
, height
, depth
,
2713 format
, type
, pixels
);
2719 * Implement the glCopyTexImage1/2D() functions.
2722 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2723 GLenum target
, GLint level
, GLenum internalFormat
,
2724 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2726 struct gl_texture_object
*texObj
;
2727 struct gl_texture_image
*texImage
;
2728 const GLuint face
= _mesa_tex_target_to_face(target
);
2730 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2732 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2733 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2735 _mesa_lookup_enum_by_nr(target
), level
,
2736 _mesa_lookup_enum_by_nr(internalFormat
),
2737 x
, y
, width
, height
, border
);
2739 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2740 _mesa_update_state(ctx
);
2742 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2743 width
, height
, border
))
2746 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2748 if (border
&& ctx
->Const
.StripTextureBorder
) {
2750 width
-= border
* 2;
2753 height
-= border
* 2;
2758 _mesa_lock_texture(ctx
, texObj
);
2760 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2763 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2766 /* choose actual hw format */
2767 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2772 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2773 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2775 /* Free old texture image */
2776 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2778 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2779 border
, internalFormat
, texFormat
);
2781 /* Allocate texture memory (no pixel data yet) */
2783 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2784 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2785 &ctx
->Unpack
, texObj
, texImage
);
2788 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2789 width
, height
, border
, GL_NONE
, GL_NONE
,
2790 NULL
, &ctx
->Unpack
, texObj
, texImage
);
2793 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2796 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
, dstX
,
2800 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, dstX
, dstY
,
2801 srcX
, srcY
, width
, height
);
2804 check_gen_mipmap(ctx
, target
, texObj
, level
);
2806 update_fbo_texture(ctx
, texObj
, face
, level
);
2809 texObj
->_Complete
= GL_FALSE
;
2810 ctx
->NewState
|= _NEW_TEXTURE
;
2813 /* probably too large of image */
2814 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2818 _mesa_unlock_texture(ctx
, texObj
);
2824 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2825 GLenum internalFormat
,
2827 GLsizei width
, GLint border
)
2829 GET_CURRENT_CONTEXT(ctx
);
2830 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2836 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2837 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2840 GET_CURRENT_CONTEXT(ctx
);
2841 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2842 x
, y
, width
, height
, border
);
2848 * Implementation for glCopyTexSubImage1/2/3D() functions.
2851 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2852 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2853 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2855 struct gl_texture_object
*texObj
;
2856 struct gl_texture_image
*texImage
;
2858 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2860 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2861 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2863 _mesa_lookup_enum_by_nr(target
),
2864 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2866 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2867 _mesa_update_state(ctx
);
2869 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2872 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2874 _mesa_lock_texture(ctx
, texObj
);
2876 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2878 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2879 zoffset
, width
, height
, texImage
)) {
2880 /* error was recored */
2883 /* If we have a border, offset=-1 is legal. Bias by border width. */
2886 zoffset
+= texImage
->Border
;
2889 yoffset
+= texImage
->Border
;
2892 xoffset
+= texImage
->Border
;
2895 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2899 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2900 xoffset
, x
, y
, width
);
2903 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2905 x
, y
, width
, height
);
2908 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2909 xoffset
, yoffset
, zoffset
,
2910 x
, y
, width
, height
);
2913 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
2916 check_gen_mipmap(ctx
, target
, texObj
, level
);
2918 ctx
->NewState
|= _NEW_TEXTURE
;
2922 _mesa_unlock_texture(ctx
, texObj
);
2927 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2928 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2930 GET_CURRENT_CONTEXT(ctx
);
2931 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
2937 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2938 GLint xoffset
, GLint yoffset
,
2939 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2941 GET_CURRENT_CONTEXT(ctx
);
2942 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
2949 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2950 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2951 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2953 GET_CURRENT_CONTEXT(ctx
);
2954 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2955 x
, y
, width
, height
);
2961 /**********************************************************************/
2962 /****** Compressed Textures ******/
2963 /**********************************************************************/
2967 * Return expected size of a compressed texture.
2970 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2973 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2974 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2979 * Return compressed texture block size, in pixels.
2982 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
2984 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2985 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
2990 * Error checking for glCompressedTexImage[123]D().
2991 * \param reason returns reason for error, if any
2992 * \return error code or GL_NO_ERROR.
2995 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2996 GLenum target
, GLint level
,
2997 GLenum internalFormat
, GLsizei width
,
2998 GLsizei height
, GLsizei depth
, GLint border
,
2999 GLsizei imageSize
, char **reason
)
3001 const GLenum proxyTarget
= get_proxy_target(target
);
3002 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3004 GLenum choose_format
;
3006 GLenum proxy_format
;
3008 *reason
= ""; /* no error */
3010 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3012 return GL_INVALID_ENUM
;
3015 /* This will detect any invalid internalFormat value */
3016 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3017 *reason
= "internalFormat";
3018 return GL_INVALID_ENUM
;
3021 switch (internalFormat
) {
3023 case GL_PALETTE4_RGB8_OES
:
3024 case GL_PALETTE4_RGBA8_OES
:
3025 case GL_PALETTE4_R5_G6_B5_OES
:
3026 case GL_PALETTE4_RGBA4_OES
:
3027 case GL_PALETTE4_RGB5_A1_OES
:
3028 case GL_PALETTE8_RGB8_OES
:
3029 case GL_PALETTE8_RGBA8_OES
:
3030 case GL_PALETTE8_R5_G6_B5_OES
:
3031 case GL_PALETTE8_RGBA4_OES
:
3032 case GL_PALETTE8_RGB5_A1_OES
:
3033 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3035 proxy_format
= choose_format
;
3038 if (level
> 0 || level
< -maxLevels
) {
3040 return GL_INVALID_VALUE
;
3043 if (dimensions
!= 2) {
3044 *reason
= "compressed paletted textures must be 2D";
3045 return GL_INVALID_OPERATION
;
3048 /* Figure out the expected texture size (in bytes). This will be
3049 * checked against the actual size later.
3051 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3054 /* This is for the benefit of the TestProxyTexImage below. It expects
3055 * level to be non-negative. OES_compressed_paletted_texture uses a
3056 * weird mechanism where the level specified to glCompressedTexImage2D
3057 * is -(n-1) number of levels in the texture, and the data specifies the
3058 * complete mipmap stack. This is done to ensure the palette is the
3059 * same for all levels.
3066 choose_format
= GL_NONE
;
3067 choose_type
= GL_NONE
;
3068 proxy_format
= internalFormat
;
3071 if (level
< 0 || level
>= maxLevels
) {
3073 return GL_INVALID_VALUE
;
3076 /* Figure out the expected texture size (in bytes). This will be
3077 * checked against the actual size later.
3079 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3083 /* This should really never fail */
3084 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3085 *reason
= "internalFormat";
3086 return GL_INVALID_ENUM
;
3089 /* No compressed formats support borders at this time */
3091 *reason
= "border != 0";
3092 return GL_INVALID_VALUE
;
3095 /* For cube map, width must equal height */
3096 if (_mesa_is_cube_face(target
) && width
!= height
) {
3097 *reason
= "width != height";
3098 return GL_INVALID_VALUE
;
3101 /* check image size against compression block size */
3103 gl_format texFormat
=
3104 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3105 choose_format
, choose_type
);
3108 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3109 if ((width
> bw
&& width
% bw
> 0) ||
3110 (height
> bh
&& height
% bh
> 0)) {
3112 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3113 * generated [...] if any parameter combinations are not
3114 * supported by the specific compressed internal format.
3116 *reason
= "invalid width or height for compression format";
3117 return GL_INVALID_OPERATION
;
3121 /* check image sizes */
3122 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3123 proxy_format
, choose_format
,
3125 width
, height
, depth
, border
)) {
3126 /* See error comment above */
3127 *reason
= "invalid width, height or format";
3128 return GL_INVALID_OPERATION
;
3131 /* check image size in bytes */
3132 if (expectedSize
!= imageSize
) {
3133 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3134 * if <imageSize> is not consistent with the format, dimensions, and
3135 * contents of the specified image.
3137 *reason
= "imageSize inconsistant with width/height/format";
3138 return GL_INVALID_VALUE
;
3141 if (!mutable_tex_object(ctx
, target
)) {
3142 *reason
= "immutable texture";
3143 return GL_INVALID_OPERATION
;
3151 * Error checking for glCompressedTexSubImage[123]D().
3152 * \warning There are some bad assumptions here about the size of compressed
3153 * texture tiles (multiple of 4) used to test the validity of the
3154 * offset and size parameters.
3155 * \return error code or GL_NO_ERROR.
3158 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3159 GLenum target
, GLint level
,
3160 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3161 GLsizei width
, GLsizei height
, GLsizei depth
,
3162 GLenum format
, GLsizei imageSize
)
3164 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3168 if (dimensions
== 1) {
3169 /* 1D compressed textures not allowed */
3170 return GL_INVALID_ENUM
;
3172 else if (dimensions
== 2) {
3173 if (target
== GL_PROXY_TEXTURE_2D
) {
3174 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3176 else if (target
== GL_TEXTURE_2D
) {
3177 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3179 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3180 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3181 return GL_INVALID_ENUM
; /*target*/
3182 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3184 else if (_mesa_is_cube_face(target
)) {
3185 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3186 return GL_INVALID_ENUM
; /*target*/
3187 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3190 return GL_INVALID_ENUM
; /*target*/
3193 else if (dimensions
== 3) {
3194 /* 3D compressed textures not allowed */
3195 return GL_INVALID_ENUM
;
3198 maxTextureSize
= 1 << (maxLevels
- 1);
3200 /* this will catch any invalid compressed format token */
3201 if (!_mesa_is_compressed_format(ctx
, format
))
3202 return GL_INVALID_ENUM
;
3204 if (width
< 1 || width
> maxTextureSize
)
3205 return GL_INVALID_VALUE
;
3207 if ((height
< 1 || height
> maxTextureSize
)
3209 return GL_INVALID_VALUE
;
3211 if (level
< 0 || level
>= maxLevels
)
3212 return GL_INVALID_VALUE
;
3215 * do checks which depend on compression block size
3217 get_compressed_block_size(format
, &bw
, &bh
);
3219 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3220 return GL_INVALID_VALUE
;
3222 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3223 return GL_INVALID_VALUE
;
3225 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3226 return GL_INVALID_VALUE
;
3228 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3229 if (expectedSize
!= imageSize
)
3230 return GL_INVALID_VALUE
;
3237 * Do second part of glCompressedTexSubImage error checking.
3238 * \return GL_TRUE if error found, GL_FALSE otherwise.
3241 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3242 GLsizei width
, GLsizei height
,
3243 GLsizei depth
, GLenum format
,
3244 struct gl_texture_image
*texImage
)
3247 if ((GLint
) format
!= texImage
->InternalFormat
) {
3248 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3249 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3253 if (((width
== 1 || width
== 2) &&
3254 width
!= (GLsizei
) texImage
->Width
) ||
3255 (width
> (GLsizei
) texImage
->Width
)) {
3256 _mesa_error(ctx
, GL_INVALID_VALUE
,
3257 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3262 if (((height
== 1 || height
== 2) &&
3263 height
!= (GLsizei
) texImage
->Height
) ||
3264 (height
> (GLsizei
) texImage
->Height
)) {
3265 _mesa_error(ctx
, GL_INVALID_VALUE
,
3266 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3272 if (((depth
== 1 || depth
== 2) &&
3273 depth
!= (GLsizei
) texImage
->Depth
) ||
3274 (depth
> (GLsizei
) texImage
->Depth
)) {
3275 _mesa_error(ctx
, GL_INVALID_VALUE
,
3276 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3286 * Implementation of the glCompressedTexImage1/2/3D() functions.
3289 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3290 GLenum target
, GLint level
,
3291 GLenum internalFormat
, GLsizei width
,
3292 GLsizei height
, GLsizei depth
, GLint border
,
3293 GLsizei imageSize
, const GLvoid
*data
)
3298 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3300 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3302 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3304 _mesa_lookup_enum_by_nr(target
), level
,
3305 _mesa_lookup_enum_by_nr(internalFormat
),
3306 width
, height
, depth
, border
, imageSize
, data
);
3309 if (!legal_teximage_target(ctx
, dims
, target
)) {
3310 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3311 dims
, _mesa_lookup_enum_by_nr(target
));
3315 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3316 internalFormat
, width
, height
, depth
,
3317 border
, imageSize
, &reason
);
3320 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3325 /* XXX this is kind of a hack */
3327 switch (internalFormat
) {
3328 case GL_PALETTE4_RGB8_OES
:
3329 case GL_PALETTE4_RGBA8_OES
:
3330 case GL_PALETTE4_R5_G6_B5_OES
:
3331 case GL_PALETTE4_RGBA4_OES
:
3332 case GL_PALETTE4_RGB5_A1_OES
:
3333 case GL_PALETTE8_RGB8_OES
:
3334 case GL_PALETTE8_RGBA8_OES
:
3335 case GL_PALETTE8_R5_G6_B5_OES
:
3336 case GL_PALETTE8_RGBA4_OES
:
3337 case GL_PALETTE8_RGB5_A1_OES
:
3338 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3339 width
, height
, imageSize
, data
);
3345 if (_mesa_is_proxy_texture(target
)) {
3346 /* Proxy texture: just check for errors and update proxy state */
3347 struct gl_texture_image
*texImage
;
3350 struct gl_texture_object
*texObj
=
3351 _mesa_get_current_tex_object(ctx
, target
);
3352 gl_format texFormat
=
3353 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3354 internalFormat
, GL_NONE
, GL_NONE
);
3355 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3356 error
= GL_OUT_OF_MEMORY
;
3360 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3363 /* if error, clear all proxy texture image parameters */
3364 clear_teximage_fields(texImage
);
3367 /* no error: store the teximage parameters */
3368 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3369 depth
, border
, internalFormat
,
3375 /* non-proxy target */
3376 struct gl_texture_object
*texObj
;
3377 struct gl_texture_image
*texImage
;
3380 _mesa_error(ctx
, error
, "glCompressedTexImage%uD", dims
);
3384 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3386 _mesa_lock_texture(ctx
, texObj
);
3388 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3390 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3391 "glCompressedTexImage%uD", dims
);
3394 gl_format texFormat
;
3396 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3398 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3399 internalFormat
, GL_NONE
,
3402 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3403 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3404 width
, height
, depth
,
3405 border
, internalFormat
, texFormat
);
3409 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3410 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3413 border
, imageSize
, data
,
3417 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3418 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3421 border
, imageSize
, data
,
3425 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3426 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3428 width
, height
, depth
,
3429 border
, imageSize
, data
,
3433 _mesa_problem(ctx
, "bad dims in compressedteximage");
3436 check_gen_mipmap(ctx
, target
, texObj
, level
);
3439 texObj
->_Complete
= GL_FALSE
;
3440 ctx
->NewState
|= _NEW_TEXTURE
;
3443 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3444 "glCompressedTexImage%uD", dims
);
3448 _mesa_unlock_texture(ctx
, texObj
);
3454 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3455 GLenum internalFormat
, GLsizei width
,
3456 GLint border
, GLsizei imageSize
,
3459 GET_CURRENT_CONTEXT(ctx
);
3460 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3461 width
, 1, 1, border
, imageSize
, data
);
3466 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3467 GLenum internalFormat
, GLsizei width
,
3468 GLsizei height
, GLint border
, GLsizei imageSize
,
3471 GET_CURRENT_CONTEXT(ctx
);
3472 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3473 width
, height
, 1, border
, imageSize
, data
);
3478 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3479 GLenum internalFormat
, GLsizei width
,
3480 GLsizei height
, GLsizei depth
, GLint border
,
3481 GLsizei imageSize
, const GLvoid
*data
)
3483 GET_CURRENT_CONTEXT(ctx
);
3484 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3485 width
, height
, depth
, border
, imageSize
, data
);
3490 * Common helper for glCompressedTexSubImage1/2/3D().
3493 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3494 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3495 GLsizei width
, GLsizei height
, GLsizei depth
,
3496 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3498 struct gl_texture_object
*texObj
;
3499 struct gl_texture_image
*texImage
;
3501 GET_CURRENT_CONTEXT(ctx
);
3502 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3504 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3505 xoffset
, 0, 0, /* pos */
3506 width
, height
, depth
, /* size */
3509 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3513 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3515 _mesa_lock_texture(ctx
, texObj
);
3517 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3520 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3521 format
, texImage
)) {
3522 /* error was recorded */
3524 else if (width
> 0 && height
> 0 && depth
> 0) {
3527 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3528 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3530 format
, imageSize
, data
,
3535 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3536 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3539 format
, imageSize
, data
,
3544 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3545 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3546 xoffset
, yoffset
, zoffset
,
3547 width
, height
, depth
,
3548 format
, imageSize
, data
,
3556 check_gen_mipmap(ctx
, target
, texObj
, level
);
3558 ctx
->NewState
|= _NEW_TEXTURE
;
3561 _mesa_unlock_texture(ctx
, texObj
);
3566 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3567 GLsizei width
, GLenum format
,
3568 GLsizei imageSize
, const GLvoid
*data
)
3570 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3571 format
, imageSize
, data
);
3576 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3577 GLint yoffset
, GLsizei width
, GLsizei height
,
3578 GLenum format
, GLsizei imageSize
,
3581 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3582 width
, height
, 1, format
, imageSize
, data
);
3587 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3588 GLint yoffset
, GLint zoffset
, GLsizei width
,
3589 GLsizei height
, GLsizei depth
, GLenum format
,
3590 GLsizei imageSize
, const GLvoid
*data
)
3592 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3593 width
, height
, depth
, format
, imageSize
, data
);
3598 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3599 * return the basic data type and number of components for the format.
3600 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3603 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3604 GLenum
*datatype
, GLuint
*components
)
3606 switch (internalFormat
) {
3608 *datatype
= GL_UNSIGNED_BYTE
;
3612 *datatype
= GL_UNSIGNED_SHORT
;
3615 case GL_ALPHA16F_ARB
:
3616 *datatype
= GL_HALF_FLOAT
;
3619 case GL_ALPHA32F_ARB
:
3620 *datatype
= GL_FLOAT
;
3623 case GL_ALPHA8I_EXT
:
3624 *datatype
= GL_BYTE
;
3627 case GL_ALPHA16I_EXT
:
3628 *datatype
= GL_SHORT
;
3631 case GL_ALPHA32I_EXT
:
3635 case GL_ALPHA8UI_EXT
:
3636 *datatype
= GL_UNSIGNED_BYTE
;
3639 case GL_ALPHA16UI_EXT
:
3640 *datatype
= GL_UNSIGNED_SHORT
;
3643 case GL_ALPHA32UI_EXT
:
3644 *datatype
= GL_UNSIGNED_INT
;
3648 *datatype
= GL_UNSIGNED_BYTE
;
3651 case GL_LUMINANCE16
:
3652 *datatype
= GL_UNSIGNED_SHORT
;
3655 case GL_LUMINANCE16F_ARB
:
3656 *datatype
= GL_HALF_FLOAT
;
3659 case GL_LUMINANCE32F_ARB
:
3660 *datatype
= GL_FLOAT
;
3663 case GL_LUMINANCE8I_EXT
:
3664 *datatype
= GL_BYTE
;
3667 case GL_LUMINANCE16I_EXT
:
3668 *datatype
= GL_SHORT
;
3671 case GL_LUMINANCE32I_EXT
:
3675 case GL_LUMINANCE8UI_EXT
:
3676 *datatype
= GL_UNSIGNED_BYTE
;
3679 case GL_LUMINANCE16UI_EXT
:
3680 *datatype
= GL_UNSIGNED_SHORT
;
3683 case GL_LUMINANCE32UI_EXT
:
3684 *datatype
= GL_UNSIGNED_INT
;
3687 case GL_LUMINANCE8_ALPHA8
:
3688 *datatype
= GL_UNSIGNED_BYTE
;
3691 case GL_LUMINANCE16_ALPHA16
:
3692 *datatype
= GL_UNSIGNED_SHORT
;
3695 case GL_LUMINANCE_ALPHA16F_ARB
:
3696 *datatype
= GL_HALF_FLOAT
;
3699 case GL_LUMINANCE_ALPHA32F_ARB
:
3700 *datatype
= GL_FLOAT
;
3703 case GL_LUMINANCE_ALPHA8I_EXT
:
3704 *datatype
= GL_BYTE
;
3707 case GL_LUMINANCE_ALPHA16I_EXT
:
3708 *datatype
= GL_SHORT
;
3711 case GL_LUMINANCE_ALPHA32I_EXT
:
3715 case GL_LUMINANCE_ALPHA8UI_EXT
:
3716 *datatype
= GL_UNSIGNED_BYTE
;
3719 case GL_LUMINANCE_ALPHA16UI_EXT
:
3720 *datatype
= GL_UNSIGNED_SHORT
;
3723 case GL_LUMINANCE_ALPHA32UI_EXT
:
3724 *datatype
= GL_UNSIGNED_INT
;
3728 *datatype
= GL_UNSIGNED_BYTE
;
3731 case GL_INTENSITY16
:
3732 *datatype
= GL_UNSIGNED_SHORT
;
3735 case GL_INTENSITY16F_ARB
:
3736 *datatype
= GL_HALF_FLOAT
;
3739 case GL_INTENSITY32F_ARB
:
3740 *datatype
= GL_FLOAT
;
3743 case GL_INTENSITY8I_EXT
:
3744 *datatype
= GL_BYTE
;
3747 case GL_INTENSITY16I_EXT
:
3748 *datatype
= GL_SHORT
;
3751 case GL_INTENSITY32I_EXT
:
3755 case GL_INTENSITY8UI_EXT
:
3756 *datatype
= GL_UNSIGNED_BYTE
;
3759 case GL_INTENSITY16UI_EXT
:
3760 *datatype
= GL_UNSIGNED_SHORT
;
3763 case GL_INTENSITY32UI_EXT
:
3764 *datatype
= GL_UNSIGNED_INT
;
3768 *datatype
= GL_UNSIGNED_BYTE
;
3772 *datatype
= GL_UNSIGNED_SHORT
;
3775 case GL_RGBA16F_ARB
:
3776 *datatype
= GL_HALF_FLOAT
;
3779 case GL_RGBA32F_ARB
:
3780 *datatype
= GL_FLOAT
;
3784 *datatype
= GL_BYTE
;
3787 case GL_RGBA16I_EXT
:
3788 *datatype
= GL_SHORT
;
3791 case GL_RGBA32I_EXT
:
3795 case GL_RGBA8UI_EXT
:
3796 *datatype
= GL_UNSIGNED_BYTE
;
3799 case GL_RGBA16UI_EXT
:
3800 *datatype
= GL_UNSIGNED_SHORT
;
3803 case GL_RGBA32UI_EXT
:
3804 *datatype
= GL_UNSIGNED_INT
;
3811 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3814 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3821 /** GL_ARB_texture_buffer_object */
3823 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3825 struct gl_texture_object
*texObj
;
3826 struct gl_buffer_object
*bufObj
;
3830 GET_CURRENT_CONTEXT(ctx
);
3831 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3833 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3834 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3838 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3839 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3843 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3844 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3849 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3850 if (buffer
&& !bufObj
) {
3851 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3855 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3857 _mesa_lock_texture(ctx
, texObj
);
3859 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3860 texObj
->BufferObjectFormat
= internalFormat
;
3862 _mesa_unlock_texture(ctx
, texObj
);