2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "mfeatures.h"
44 #include "texcompress.h"
52 * State changes which we care about for glCopyTex[Sub]Image() calls.
53 * In particular, we care about pixel transfer state and buffer state
54 * (such as glReadBuffer to make sure we read from the right renderbuffer).
56 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
61 * Return the simple base format for a given internal texture format.
62 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
64 * \param ctx GL context.
65 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
67 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
68 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
70 * This is the format which is used during texture application (i.e. the
71 * texture format and env mode determine the arithmetic used.
73 * XXX this could be static
76 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
78 switch (internalFormat
) {
93 case GL_LUMINANCE_ALPHA
:
94 case GL_LUMINANCE4_ALPHA4
:
95 case GL_LUMINANCE6_ALPHA2
:
96 case GL_LUMINANCE8_ALPHA8
:
97 case GL_LUMINANCE12_ALPHA4
:
98 case GL_LUMINANCE12_ALPHA12
:
99 case GL_LUMINANCE16_ALPHA16
:
100 return GL_LUMINANCE_ALPHA
;
131 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
133 if (ctx
->API
!= API_OPENGL
) {
134 switch (internalFormat
) {
142 if (ctx
->Extensions
.ARB_depth_texture
) {
143 switch (internalFormat
) {
144 case GL_DEPTH_COMPONENT
:
145 case GL_DEPTH_COMPONENT16
:
146 case GL_DEPTH_COMPONENT24
:
147 case GL_DEPTH_COMPONENT32
:
148 return GL_DEPTH_COMPONENT
;
154 switch (internalFormat
) {
155 case GL_COMPRESSED_ALPHA
:
157 case GL_COMPRESSED_LUMINANCE
:
159 case GL_COMPRESSED_LUMINANCE_ALPHA
:
160 return GL_LUMINANCE_ALPHA
;
161 case GL_COMPRESSED_INTENSITY
:
163 case GL_COMPRESSED_RGB
:
165 case GL_COMPRESSED_RGBA
:
171 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
172 switch (internalFormat
) {
173 case GL_COMPRESSED_RGB_FXT1_3DFX
:
175 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
182 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
183 switch (internalFormat
) {
184 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
186 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
187 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
188 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
195 if (ctx
->Extensions
.S3_s3tc
) {
196 switch (internalFormat
) {
208 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
209 if (internalFormat
== GL_YCBCR_MESA
)
210 return GL_YCBCR_MESA
;
213 if (ctx
->Extensions
.ARB_texture_float
) {
214 switch (internalFormat
) {
215 case GL_ALPHA16F_ARB
:
216 case GL_ALPHA32F_ARB
:
224 case GL_INTENSITY16F_ARB
:
225 case GL_INTENSITY32F_ARB
:
227 case GL_LUMINANCE16F_ARB
:
228 case GL_LUMINANCE32F_ARB
:
230 case GL_LUMINANCE_ALPHA16F_ARB
:
231 case GL_LUMINANCE_ALPHA32F_ARB
:
232 return GL_LUMINANCE_ALPHA
;
238 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
239 switch (internalFormat
) {
248 if (ctx
->Extensions
.EXT_texture_snorm
) {
249 switch (internalFormat
) {
264 case GL_RGBA16_SNORM
:
267 case GL_ALPHA8_SNORM
:
268 case GL_ALPHA16_SNORM
:
270 case GL_LUMINANCE_SNORM
:
271 case GL_LUMINANCE8_SNORM
:
272 case GL_LUMINANCE16_SNORM
:
274 case GL_LUMINANCE_ALPHA_SNORM
:
275 case GL_LUMINANCE8_ALPHA8_SNORM
:
276 case GL_LUMINANCE16_ALPHA16_SNORM
:
277 return GL_LUMINANCE_ALPHA
;
278 case GL_INTENSITY_SNORM
:
279 case GL_INTENSITY8_SNORM
:
280 case GL_INTENSITY16_SNORM
:
287 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
288 switch (internalFormat
) {
289 case GL_DEPTH_STENCIL_EXT
:
290 case GL_DEPTH24_STENCIL8_EXT
:
291 return GL_DEPTH_STENCIL_EXT
;
297 #if FEATURE_EXT_texture_sRGB
298 if (ctx
->Extensions
.EXT_texture_sRGB
) {
299 switch (internalFormat
) {
302 case GL_COMPRESSED_SRGB_EXT
:
303 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
305 case GL_SRGB_ALPHA_EXT
:
306 case GL_SRGB8_ALPHA8_EXT
:
307 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
308 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
309 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
310 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
312 case GL_SLUMINANCE_ALPHA_EXT
:
313 case GL_SLUMINANCE8_ALPHA8_EXT
:
314 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
315 return GL_LUMINANCE_ALPHA
;
316 case GL_SLUMINANCE_EXT
:
317 case GL_SLUMINANCE8_EXT
:
318 case GL_COMPRESSED_SLUMINANCE_EXT
:
324 #endif /* FEATURE_EXT_texture_sRGB */
326 if (ctx
->Extensions
.EXT_texture_integer
) {
327 switch (internalFormat
) {
329 case GL_RGBA16UI_EXT
:
330 case GL_RGBA32UI_EXT
:
343 case GL_ALPHA8UI_EXT
:
344 case GL_ALPHA16UI_EXT
:
345 case GL_ALPHA32UI_EXT
:
347 case GL_ALPHA16I_EXT
:
348 case GL_ALPHA32I_EXT
:
350 case GL_INTENSITY8UI_EXT
:
351 case GL_INTENSITY16UI_EXT
:
352 case GL_INTENSITY32UI_EXT
:
353 case GL_INTENSITY8I_EXT
:
354 case GL_INTENSITY16I_EXT
:
355 case GL_INTENSITY32I_EXT
:
357 case GL_LUMINANCE8UI_EXT
:
358 case GL_LUMINANCE16UI_EXT
:
359 case GL_LUMINANCE32UI_EXT
:
360 case GL_LUMINANCE8I_EXT
:
361 case GL_LUMINANCE16I_EXT
:
362 case GL_LUMINANCE32I_EXT
:
364 case GL_LUMINANCE_ALPHA8UI_EXT
:
365 case GL_LUMINANCE_ALPHA16UI_EXT
:
366 case GL_LUMINANCE_ALPHA32UI_EXT
:
367 case GL_LUMINANCE_ALPHA8I_EXT
:
368 case GL_LUMINANCE_ALPHA16I_EXT
:
369 case GL_LUMINANCE_ALPHA32I_EXT
:
370 return GL_LUMINANCE_ALPHA
;
376 if (ctx
->Extensions
.ARB_texture_rg
) {
377 switch (internalFormat
) {
379 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
381 if (!ctx
->Extensions
.ARB_half_float_pixel
)
385 if (!ctx
->Extensions
.ARB_texture_float
)
394 if (!ctx
->Extensions
.EXT_texture_integer
)
400 case GL_COMPRESSED_RED
:
404 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
406 if (!ctx
->Extensions
.ARB_half_float_pixel
)
410 if (!ctx
->Extensions
.ARB_texture_float
)
419 if (!ctx
->Extensions
.EXT_texture_integer
)
425 case GL_COMPRESSED_RG
:
432 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
433 switch (internalFormat
) {
441 if (ctx
->Extensions
.EXT_packed_float
) {
442 switch (internalFormat
) {
443 case GL_R11F_G11F_B10F_EXT
:
450 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
451 switch (internalFormat
) {
452 case GL_DEPTH_COMPONENT32F
:
453 return GL_DEPTH_COMPONENT
;
454 case GL_DEPTH32F_STENCIL8
:
455 return GL_DEPTH_STENCIL
;
461 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
462 switch (internalFormat
) {
463 case GL_COMPRESSED_RED_RGTC1
:
464 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
466 case GL_COMPRESSED_RG_RGTC2
:
467 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
474 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
475 switch (internalFormat
) {
476 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
477 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
479 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
480 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
481 return GL_LUMINANCE_ALPHA
;
487 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
488 switch (internalFormat
) {
489 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
490 return GL_LUMINANCE_ALPHA
;
496 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
497 switch (internalFormat
) {
498 case GL_ETC1_RGB8_OES
:
505 if (ctx
->API
== API_OPENGLES
) {
506 switch (internalFormat
) {
507 case GL_PALETTE4_RGB8_OES
:
508 case GL_PALETTE4_R5_G6_B5_OES
:
509 case GL_PALETTE8_RGB8_OES
:
510 case GL_PALETTE8_R5_G6_B5_OES
:
512 case GL_PALETTE4_RGBA8_OES
:
513 case GL_PALETTE8_RGB5_A1_OES
:
514 case GL_PALETTE4_RGBA4_OES
:
515 case GL_PALETTE4_RGB5_A1_OES
:
516 case GL_PALETTE8_RGBA8_OES
:
517 case GL_PALETTE8_RGBA4_OES
:
524 return -1; /* error */
529 * For cube map faces, return a face index in [0,5].
530 * For other targets return 0;
533 _mesa_tex_target_to_face(GLenum target
)
535 if (_mesa_is_cube_face(target
))
536 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
544 * Install gl_texture_image in a gl_texture_object according to the target
545 * and level parameters.
547 * \param tObj texture object.
548 * \param target texture target.
549 * \param level image level.
550 * \param texImage texture image.
553 set_tex_image(struct gl_texture_object
*tObj
,
554 GLenum target
, GLint level
,
555 struct gl_texture_image
*texImage
)
557 const GLuint face
= _mesa_tex_target_to_face(target
);
561 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
564 tObj
->Image
[face
][level
] = texImage
;
566 /* Set the 'back' pointer */
567 texImage
->TexObject
= tObj
;
568 texImage
->Level
= level
;
569 texImage
->Face
= face
;
574 * Allocate a texture image structure.
576 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
579 * \return a pointer to gl_texture_image struct with all fields initialized to
582 struct gl_texture_image
*
583 _mesa_new_texture_image( struct gl_context
*ctx
)
586 return CALLOC_STRUCT(gl_texture_image
);
591 * Free a gl_texture_image and associated data.
592 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
594 * \param texImage texture image.
596 * Free the texture image structure and the associated image data.
599 _mesa_delete_texture_image(struct gl_context
*ctx
,
600 struct gl_texture_image
*texImage
)
602 /* Free texImage->Data and/or any other driver-specific texture
605 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
606 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
612 * Test if a target is a proxy target.
614 * \param target texture target.
616 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
619 _mesa_is_proxy_texture(GLenum target
)
622 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
623 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
625 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
627 return (target
== GL_PROXY_TEXTURE_1D
||
628 target
== GL_PROXY_TEXTURE_2D
||
629 target
== GL_PROXY_TEXTURE_3D
||
630 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
631 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
632 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
633 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
638 * Return the proxy target which corresponds to the given texture target
641 get_proxy_target(GLenum target
)
645 case GL_PROXY_TEXTURE_1D
:
646 return GL_PROXY_TEXTURE_1D
;
648 case GL_PROXY_TEXTURE_2D
:
649 return GL_PROXY_TEXTURE_2D
;
651 case GL_PROXY_TEXTURE_3D
:
652 return GL_PROXY_TEXTURE_3D
;
653 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
654 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
655 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
656 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
657 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
658 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
659 case GL_TEXTURE_CUBE_MAP_ARB
:
660 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
661 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
662 case GL_TEXTURE_RECTANGLE_NV
:
663 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
664 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
665 case GL_TEXTURE_1D_ARRAY_EXT
:
666 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
667 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
668 case GL_TEXTURE_2D_ARRAY_EXT
:
669 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
670 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
672 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
679 * Get the texture object that corresponds to the target of the given
680 * texture unit. The target should have already been checked for validity.
682 * \param ctx GL context.
683 * \param texUnit texture unit.
684 * \param target texture target.
686 * \return pointer to the texture object on success, or NULL on failure.
688 struct gl_texture_object
*
689 _mesa_select_tex_object(struct gl_context
*ctx
,
690 const struct gl_texture_unit
*texUnit
,
693 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
694 ctx
->Extensions
.EXT_texture_array
);
698 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
699 case GL_PROXY_TEXTURE_1D
:
700 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
702 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
703 case GL_PROXY_TEXTURE_2D
:
704 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
706 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
707 case GL_PROXY_TEXTURE_3D
:
708 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
709 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
710 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
711 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
712 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
713 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
714 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
715 case GL_TEXTURE_CUBE_MAP_ARB
:
716 return ctx
->Extensions
.ARB_texture_cube_map
717 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
718 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
719 return ctx
->Extensions
.ARB_texture_cube_map
720 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
721 case GL_TEXTURE_RECTANGLE_NV
:
722 return ctx
->Extensions
.NV_texture_rectangle
723 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
724 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
725 return ctx
->Extensions
.NV_texture_rectangle
726 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
727 case GL_TEXTURE_1D_ARRAY_EXT
:
728 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
729 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
730 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
731 case GL_TEXTURE_2D_ARRAY_EXT
:
732 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
733 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
734 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
735 case GL_TEXTURE_BUFFER
:
736 return ctx
->Extensions
.ARB_texture_buffer_object
737 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
738 case GL_TEXTURE_EXTERNAL_OES
:
739 return ctx
->Extensions
.OES_EGL_image_external
740 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
742 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
749 * Return pointer to texture object for given target on current texture unit.
751 struct gl_texture_object
*
752 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
754 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
755 return _mesa_select_tex_object(ctx
, texUnit
, target
);
760 * Get a texture image pointer from a texture object, given a texture
761 * target and mipmap level. The target and level parameters should
762 * have already been error-checked.
764 * \param ctx GL context.
765 * \param texObj texture unit.
766 * \param target texture target.
767 * \param level image level.
769 * \return pointer to the texture image structure, or NULL on failure.
771 struct gl_texture_image
*
772 _mesa_select_tex_image(struct gl_context
*ctx
,
773 const struct gl_texture_object
*texObj
,
774 GLenum target
, GLint level
)
776 const GLuint face
= _mesa_tex_target_to_face(target
);
780 ASSERT(level
< MAX_TEXTURE_LEVELS
);
782 return texObj
->Image
[face
][level
];
787 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
788 * it and install it. Only return NULL if passed a bad parameter or run
791 struct gl_texture_image
*
792 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
793 GLenum target
, GLint level
)
795 struct gl_texture_image
*texImage
;
800 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
802 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
804 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
808 set_tex_image(texObj
, target
, level
, texImage
);
816 * Return pointer to the specified proxy texture image.
817 * Note that proxy textures are per-context, not per-texture unit.
818 * \return pointer to texture image or NULL if invalid target, invalid
819 * level, or out of memory.
821 struct gl_texture_image
*
822 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
824 struct gl_texture_image
*texImage
;
831 case GL_PROXY_TEXTURE_1D
:
832 if (level
>= ctx
->Const
.MaxTextureLevels
)
834 texIndex
= TEXTURE_1D_INDEX
;
836 case GL_PROXY_TEXTURE_2D
:
837 if (level
>= ctx
->Const
.MaxTextureLevels
)
839 texIndex
= TEXTURE_2D_INDEX
;
841 case GL_PROXY_TEXTURE_3D
:
842 if (level
>= ctx
->Const
.Max3DTextureLevels
)
844 texIndex
= TEXTURE_3D_INDEX
;
846 case GL_PROXY_TEXTURE_CUBE_MAP
:
847 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
849 texIndex
= TEXTURE_CUBE_INDEX
;
851 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
854 texIndex
= TEXTURE_RECT_INDEX
;
856 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
857 if (level
>= ctx
->Const
.MaxTextureLevels
)
859 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
861 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
862 if (level
>= ctx
->Const
.MaxTextureLevels
)
864 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
870 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
872 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
874 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
877 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
878 /* Set the 'back' pointer */
879 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
886 * Get the maximum number of allowed mipmap levels.
888 * \param ctx GL context.
889 * \param target texture target.
891 * \return the maximum number of allowed mipmap levels for the given
892 * texture target, or zero if passed a bad target.
897 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
901 case GL_PROXY_TEXTURE_1D
:
903 case GL_PROXY_TEXTURE_2D
:
904 return ctx
->Const
.MaxTextureLevels
;
906 case GL_PROXY_TEXTURE_3D
:
907 return ctx
->Const
.Max3DTextureLevels
;
908 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
909 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
910 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
911 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
912 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
913 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
914 case GL_TEXTURE_CUBE_MAP_ARB
:
915 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
916 return ctx
->Extensions
.ARB_texture_cube_map
917 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
918 case GL_TEXTURE_RECTANGLE_NV
:
919 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
920 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
921 case GL_TEXTURE_1D_ARRAY_EXT
:
922 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
923 case GL_TEXTURE_2D_ARRAY_EXT
:
924 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
925 return (ctx
->Extensions
.MESA_texture_array
||
926 ctx
->Extensions
.EXT_texture_array
)
927 ? ctx
->Const
.MaxTextureLevels
: 0;
928 case GL_TEXTURE_BUFFER
:
929 case GL_TEXTURE_EXTERNAL_OES
:
932 return 0; /* bad target */
938 * Return number of dimensions per mipmap level for the given texture target.
941 _mesa_get_texture_dimensions(GLenum target
)
945 case GL_PROXY_TEXTURE_1D
:
948 case GL_TEXTURE_RECTANGLE
:
949 case GL_TEXTURE_CUBE_MAP
:
950 case GL_PROXY_TEXTURE_2D
:
951 case GL_PROXY_TEXTURE_RECTANGLE
:
952 case GL_PROXY_TEXTURE_CUBE_MAP
:
953 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
954 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
955 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
956 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
957 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
958 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
959 case GL_TEXTURE_1D_ARRAY
:
960 case GL_PROXY_TEXTURE_1D_ARRAY
:
961 case GL_TEXTURE_EXTERNAL_OES
:
964 case GL_PROXY_TEXTURE_3D
:
965 case GL_TEXTURE_2D_ARRAY
:
966 case GL_PROXY_TEXTURE_2D_ARRAY
:
968 case GL_TEXTURE_BUFFER
:
971 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
980 #if 000 /* not used anymore */
982 * glTexImage[123]D can accept a NULL image pointer. In this case we
983 * create a texture image with unspecified image contents per the OpenGL
987 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
989 const GLint components
= _mesa_components_in_format(format
);
990 const GLint numPixels
= width
* height
* depth
;
991 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
995 * Let's see if anyone finds this. If glTexImage2D() is called with
996 * a NULL image pointer then load the texture image with something
997 * interesting instead of leaving it indeterminate.
1000 static const char message
[8][32] = {
1001 " X X XXXXX XXX X ",
1002 " XX XX X X X X X ",
1004 " X X XXXX XXX XXXXX ",
1007 " X X XXXXX XXX X X ",
1011 GLubyte
*imgPtr
= data
;
1013 for (h
= 0; h
< depth
; h
++) {
1014 for (i
= 0; i
< height
; i
++) {
1015 GLint srcRow
= 7 - (i
% 8);
1016 for (j
= 0; j
< width
; j
++) {
1017 GLint srcCol
= j
% 32;
1018 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1019 for (k
= 0; k
< components
; k
++) {
1035 * Set the size and format-related fields of a gl_texture_image struct
1036 * to zero. This is used when a proxy texture test fails.
1039 clear_teximage_fields(struct gl_texture_image
*img
)
1042 img
->_BaseFormat
= 0;
1043 img
->InternalFormat
= 0;
1052 img
->HeightLog2
= 0;
1054 img
->TexFormat
= MESA_FORMAT_NONE
;
1059 * Initialize basic fields of the gl_texture_image struct.
1061 * \param ctx GL context.
1062 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1063 * \param img texture image structure to be initialized.
1064 * \param width image width.
1065 * \param height image height.
1066 * \param depth image depth.
1067 * \param border image border.
1068 * \param internalFormat internal format.
1069 * \param format the actual hardware format (one of MESA_FORMAT_*)
1071 * Fills in the fields of \p img with the given information.
1072 * Note: width, height and depth include the border.
1075 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1076 struct gl_texture_image
*img
,
1077 GLsizei width
, GLsizei height
, GLsizei depth
,
1078 GLint border
, GLenum internalFormat
,
1083 ASSERT(height
>= 0);
1086 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1087 ASSERT(img
->_BaseFormat
> 0);
1088 img
->InternalFormat
= internalFormat
;
1089 img
->Border
= border
;
1091 img
->Height
= height
;
1094 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1095 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1097 if (height
== 1) { /* 1-D texture */
1099 img
->HeightLog2
= 0;
1102 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1103 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1106 if (depth
== 1) { /* 2-D texture */
1111 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1112 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1115 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1117 img
->TexFormat
= format
;
1122 * Free and clear fields of the gl_texture_image struct.
1124 * \param ctx GL context.
1125 * \param texImage texture image structure to be cleared.
1127 * After the call, \p texImage will have no data associated with it. Its
1128 * fields are cleared so that its parent object will test incomplete.
1131 _mesa_clear_texture_image(struct gl_context
*ctx
,
1132 struct gl_texture_image
*texImage
)
1134 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1135 clear_teximage_fields(texImage
);
1140 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1141 * level, width, height and depth against the ctx->Const limits for textures.
1143 * A hardware driver might override this function if, for example, the
1144 * max 3D texture size is 512x512x64 (i.e. not a cube).
1146 * Note that width, height, depth == 0 is not an error. However, a
1147 * texture with zero width/height/depth will be considered "incomplete"
1148 * and texturing will effectively be disabled.
1150 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1151 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1152 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1153 * \param level as passed to glTexImage
1154 * \param internalFormat as passed to glTexImage
1155 * \param format as passed to glTexImage
1156 * \param type as passed to glTexImage
1157 * \param width as passed to glTexImage
1158 * \param height as passed to glTexImage
1159 * \param depth as passed to glTexImage
1160 * \param border as passed to glTexImage
1161 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1164 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1165 GLint internalFormat
, GLenum format
, GLenum type
,
1166 GLint width
, GLint height
, GLint depth
, GLint border
)
1170 (void) internalFormat
;
1175 case GL_PROXY_TEXTURE_1D
:
1176 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1177 if (width
< 2 * border
|| width
> 2 + maxSize
)
1179 if (level
>= ctx
->Const
.MaxTextureLevels
)
1181 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1182 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1187 case GL_PROXY_TEXTURE_2D
:
1188 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1189 if (width
< 2 * border
|| width
> 2 + maxSize
)
1191 if (height
< 2 * border
|| height
> 2 + maxSize
)
1193 if (level
>= ctx
->Const
.MaxTextureLevels
)
1195 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1196 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1198 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1203 case GL_PROXY_TEXTURE_3D
:
1204 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1205 if (width
< 2 * border
|| width
> 2 + maxSize
)
1207 if (height
< 2 * border
|| height
> 2 + maxSize
)
1209 if (depth
< 2 * border
|| depth
> 2 + maxSize
)
1211 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1213 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1214 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1216 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1218 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1223 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1224 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1225 if (width
< 0 || width
> maxSize
)
1227 if (height
< 0 || height
> maxSize
)
1233 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1234 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1235 if (width
< 2 * border
|| width
> 2 + maxSize
)
1237 if (height
< 2 * border
|| height
> 2 + maxSize
)
1239 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1241 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1242 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1244 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1249 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1250 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1251 if (width
< 2 * border
|| width
> 2 + maxSize
)
1253 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1255 if (level
>= ctx
->Const
.MaxTextureLevels
)
1257 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1258 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1263 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1264 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1265 if (width
< 2 * border
|| width
> 2 + maxSize
)
1267 if (height
< 2 * border
|| height
> 2 + maxSize
)
1269 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1271 if (level
>= ctx
->Const
.MaxTextureLevels
)
1273 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1274 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1276 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1282 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1289 * Check if the memory used by the texture would exceed the driver's limit.
1290 * This lets us support a max 3D texture size of 8K (for example) but
1291 * prevents allocating a full 8K x 8K x 8K texture.
1292 * XXX this could be rolled into the proxy texture size test (above) but
1293 * we don't have the actual texture internal format at that point.
1296 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1297 GLint width
, GLint height
, GLint depth
)
1299 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1300 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1301 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1306 * Return true if the format is only valid for glCompressedTexImage.
1309 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1312 case GL_ETC1_RGB8_OES
:
1321 * Helper function to determine whether a target and specific compression
1322 * format are supported.
1325 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1328 (void) intFormat
; /* not used yet */
1332 case GL_PROXY_TEXTURE_2D
:
1333 return GL_TRUE
; /* true for any compressed format so far */
1334 case GL_PROXY_TEXTURE_CUBE_MAP
:
1335 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1336 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1337 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1338 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1339 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1340 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1341 return ctx
->Extensions
.ARB_texture_cube_map
;
1342 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1343 case GL_TEXTURE_2D_ARRAY_EXT
:
1344 return (ctx
->Extensions
.MESA_texture_array
||
1345 ctx
->Extensions
.EXT_texture_array
);
1353 * Check if the given texture target value is legal for a
1354 * glTexImage1/2/3D call.
1357 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1363 case GL_PROXY_TEXTURE_1D
:
1371 case GL_PROXY_TEXTURE_2D
:
1373 case GL_PROXY_TEXTURE_CUBE_MAP
:
1374 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1375 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1376 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1377 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1378 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1379 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1380 return ctx
->Extensions
.ARB_texture_cube_map
;
1381 case GL_TEXTURE_RECTANGLE_NV
:
1382 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1383 return ctx
->Extensions
.NV_texture_rectangle
;
1384 case GL_TEXTURE_1D_ARRAY_EXT
:
1385 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1386 return (ctx
->Extensions
.MESA_texture_array
||
1387 ctx
->Extensions
.EXT_texture_array
);
1394 case GL_PROXY_TEXTURE_3D
:
1396 case GL_TEXTURE_2D_ARRAY_EXT
:
1397 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1398 return (ctx
->Extensions
.MESA_texture_array
||
1399 ctx
->Extensions
.EXT_texture_array
);
1404 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1411 * Check if the given texture target value is legal for a
1412 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1413 * The difference compared to legal_teximage_target() above is that
1414 * proxy targets are not supported.
1417 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1421 return target
== GL_TEXTURE_1D
;
1426 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1427 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1428 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1429 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1430 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1431 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1432 return ctx
->Extensions
.ARB_texture_cube_map
;
1433 case GL_TEXTURE_RECTANGLE_NV
:
1434 return ctx
->Extensions
.NV_texture_rectangle
;
1435 case GL_TEXTURE_1D_ARRAY_EXT
:
1436 return (ctx
->Extensions
.MESA_texture_array
||
1437 ctx
->Extensions
.EXT_texture_array
);
1445 case GL_TEXTURE_2D_ARRAY_EXT
:
1446 return (ctx
->Extensions
.MESA_texture_array
||
1447 ctx
->Extensions
.EXT_texture_array
);
1452 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1460 * Helper function to determine if a texture object is mutable (in terms
1461 * of GL_ARB_texture_storage).
1464 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1466 if (ctx
->Extensions
.ARB_texture_storage
) {
1467 struct gl_texture_object
*texObj
=
1468 _mesa_get_current_tex_object(ctx
, target
);
1469 return !texObj
->Immutable
;
1477 * Test the glTexImage[123]D() parameters for errors.
1479 * \param ctx GL context.
1480 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1481 * \param target texture target given by the user.
1482 * \param level image level given by the user.
1483 * \param internalFormat internal format given by the user.
1484 * \param format pixel data format given by the user.
1485 * \param type pixel data type given by the user.
1486 * \param width image width given by the user.
1487 * \param height image height given by the user.
1488 * \param depth image depth given by the user.
1489 * \param border image border given by the user.
1491 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1493 * Verifies each of the parameters against the constants specified in
1494 * __struct gl_contextRec::Const and the supported extensions, and according
1495 * to the OpenGL specification.
1498 texture_error_check( struct gl_context
*ctx
,
1499 GLuint dimensions
, GLenum target
,
1500 GLint level
, GLint internalFormat
,
1501 GLenum format
, GLenum type
,
1502 GLint width
, GLint height
,
1503 GLint depth
, GLint border
)
1505 const GLenum proxyTarget
= get_proxy_target(target
);
1506 const GLboolean isProxy
= target
== proxyTarget
;
1507 GLboolean sizeOK
= GL_TRUE
;
1508 GLboolean colorFormat
;
1510 /* Even though there are no color-index textures, we still have to support
1511 * uploading color-index data and remapping it to RGB via the
1512 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1514 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1516 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1517 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1519 _mesa_error(ctx
, GL_INVALID_VALUE
,
1520 "glTexImage%dD(level=%d)", dimensions
, level
);
1526 if (border
< 0 || border
> 1 ||
1527 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1528 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1530 _mesa_error(ctx
, GL_INVALID_VALUE
,
1531 "glTexImage%dD(border=%d)", dimensions
, border
);
1536 if (width
< 0 || height
< 0 || depth
< 0) {
1538 _mesa_error(ctx
, GL_INVALID_VALUE
,
1539 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1544 /* Do this simple check before calling the TestProxyTexImage() function */
1545 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1546 sizeOK
= (width
== height
);
1550 * Use the proxy texture driver hook to see if the size/level/etc are
1553 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1554 internalFormat
, format
,
1555 type
, width
, height
,
1559 _mesa_error(ctx
, GL_INVALID_VALUE
,
1560 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1561 dimensions
, level
, width
, height
, depth
);
1566 /* Check internalFormat */
1567 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1569 _mesa_error(ctx
, GL_INVALID_VALUE
,
1570 "glTexImage%dD(internalFormat=%s)",
1571 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1576 /* Check incoming image format and type */
1577 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1578 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1579 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1580 * GL_EXT_texture_integer extension, some combinations should generate
1581 * GL_INVALID_ENUM instead (grr!).
1584 GLenum error
= _mesa_is_integer_format(format
)
1585 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1586 _mesa_error(ctx
, error
,
1587 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1588 dimensions
, format
, type
);
1593 /* make sure internal format and format basically agree */
1594 colorFormat
= _mesa_is_color_format(format
);
1595 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1596 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1597 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1598 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1599 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1602 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1603 dimensions
, internalFormat
, format
);
1607 /* additional checks for ycbcr textures */
1608 if (internalFormat
== GL_YCBCR_MESA
) {
1609 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1610 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1611 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1613 _mesa_snprintf(message
, sizeof(message
),
1614 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1615 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1616 return GL_TRUE
; /* error */
1618 if (target
!= GL_TEXTURE_2D
&&
1619 target
!= GL_PROXY_TEXTURE_2D
&&
1620 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1621 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1623 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1629 _mesa_snprintf(message
, sizeof(message
),
1630 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1631 dimensions
, border
);
1632 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1638 /* additional checks for depth textures */
1639 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1640 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1641 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1642 if (target
!= GL_TEXTURE_1D
&&
1643 target
!= GL_PROXY_TEXTURE_1D
&&
1644 target
!= GL_TEXTURE_2D
&&
1645 target
!= GL_PROXY_TEXTURE_2D
&&
1646 target
!= GL_TEXTURE_1D_ARRAY
&&
1647 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1648 target
!= GL_TEXTURE_2D_ARRAY
&&
1649 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1650 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1651 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1652 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1653 (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_gpu_shader4
))) {
1655 _mesa_error(ctx
, GL_INVALID_ENUM
,
1656 "glTexImage(target/internalFormat)");
1661 /* additional checks for compressed textures */
1662 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1663 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1665 _mesa_error(ctx
, GL_INVALID_ENUM
,
1666 "glTexImage%dD(target)", dimensions
);
1669 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1670 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1671 "glTexImage%dD(no compression for format)", dimensions
);
1676 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1677 "glTexImage%dD(border!=0)", dimensions
);
1683 /* additional checks for integer textures */
1684 if (ctx
->Extensions
.EXT_texture_integer
&&
1685 (_mesa_is_integer_format(format
) !=
1686 _mesa_is_integer_format(internalFormat
))) {
1688 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1689 "glTexImage%dD(integer/non-integer format mismatch)",
1695 if (!mutable_tex_object(ctx
, target
)) {
1696 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1697 "glTexImage%dD(immutable texture)", dimensions
);
1701 /* if we get here, the parameters are OK */
1707 * Test glTexSubImage[123]D() parameters for errors.
1709 * \param ctx GL context.
1710 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1711 * \param target texture target given by the user.
1712 * \param level image level given by the user.
1713 * \param xoffset sub-image x offset given by the user.
1714 * \param yoffset sub-image y offset given by the user.
1715 * \param zoffset sub-image z offset given by the user.
1716 * \param format pixel data format given by the user.
1717 * \param type pixel data type given by the user.
1718 * \param width image width given by the user.
1719 * \param height image height given by the user.
1720 * \param depth image depth given by the user.
1722 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1724 * Verifies each of the parameters against the constants specified in
1725 * __struct gl_contextRec::Const and the supported extensions, and according
1726 * to the OpenGL specification.
1729 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1730 GLenum target
, GLint level
,
1731 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1732 GLint width
, GLint height
, GLint depth
,
1733 GLenum format
, GLenum type
)
1735 /* Basic level check */
1736 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1737 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1741 /* Check for negative sizes */
1743 _mesa_error(ctx
, GL_INVALID_VALUE
,
1744 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1747 if (height
< 0 && dimensions
> 1) {
1748 _mesa_error(ctx
, GL_INVALID_VALUE
,
1749 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1752 if (depth
< 0 && dimensions
> 2) {
1753 _mesa_error(ctx
, GL_INVALID_VALUE
,
1754 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1758 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1759 /* As with the glTexImage2D check above, the error code here
1760 * depends on texture integer.
1762 GLenum error
= _mesa_is_integer_format(format
)
1763 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1764 _mesa_error(ctx
, error
,
1765 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1766 dimensions
, format
, type
);
1775 * Do second part of glTexSubImage which depends on the destination texture.
1776 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1779 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1780 GLenum target
, GLint level
,
1781 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1782 GLint width
, GLint height
, GLint depth
,
1783 GLenum format
, GLenum type
,
1784 const struct gl_texture_image
*destTex
)
1787 /* undefined image level */
1788 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1792 if (xoffset
< -((GLint
)destTex
->Border
)) {
1793 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1797 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1798 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1802 if (dimensions
> 1) {
1803 if (yoffset
< -((GLint
)destTex
->Border
)) {
1804 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1808 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1809 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1814 if (dimensions
> 2) {
1815 if (zoffset
< -((GLint
)destTex
->Border
)) {
1816 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1819 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1820 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1825 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1828 if (compressedteximage_only_format(ctx
, destTex
->InternalFormat
)) {
1829 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1830 "glTexSubImage%dD(no compression for format)", dimensions
);
1834 /* do tests which depend on compression block size */
1835 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1837 /* offset must be multiple of block size */
1838 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1839 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1840 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1841 dimensions
, xoffset
, yoffset
);
1844 /* size must be multiple of bw by bh or equal to whole texture size */
1845 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1846 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1847 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1850 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1851 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1852 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1862 * Test glCopyTexImage[12]D() parameters for errors.
1864 * \param ctx GL context.
1865 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1866 * \param target texture target given by the user.
1867 * \param level image level given by the user.
1868 * \param internalFormat internal format given by the user.
1869 * \param width image width given by the user.
1870 * \param height image height given by the user.
1871 * \param border texture border.
1873 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1875 * Verifies each of the parameters against the constants specified in
1876 * __struct gl_contextRec::Const and the supported extensions, and according
1877 * to the OpenGL specification.
1880 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1881 GLenum target
, GLint level
, GLint internalFormat
,
1882 GLint width
, GLint height
, GLint border
)
1884 const GLenum proxyTarget
= get_proxy_target(target
);
1885 const GLenum type
= GL_FLOAT
;
1890 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1891 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1892 dimensions
, _mesa_lookup_enum_by_nr(target
));
1896 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1897 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1898 _mesa_error(ctx
, GL_INVALID_VALUE
,
1899 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1903 /* Check that the source buffer is complete */
1904 if (ctx
->ReadBuffer
->Name
) {
1905 if (ctx
->ReadBuffer
->_Status
== 0) {
1906 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1908 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1909 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1910 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1916 if (border
< 0 || border
> 1 ||
1917 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1918 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1922 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1923 if (baseFormat
< 0) {
1924 _mesa_error(ctx
, GL_INVALID_VALUE
,
1925 "glCopyTexImage%dD(internalFormat)", dimensions
);
1929 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
1930 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1931 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1935 /* Do size, level checking */
1936 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1937 ? (width
== height
) : 1;
1939 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1940 internalFormat
, baseFormat
,
1941 type
, width
, height
,
1945 if (dimensions
== 1) {
1946 _mesa_error(ctx
, GL_INVALID_VALUE
,
1947 "glCopyTexImage1D(width=%d)", width
);
1950 ASSERT(dimensions
== 2);
1951 _mesa_error(ctx
, GL_INVALID_VALUE
,
1952 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1957 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1958 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1959 _mesa_error(ctx
, GL_INVALID_ENUM
,
1960 "glCopyTexImage%dD(target)", dimensions
);
1963 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1964 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1965 "glCopyTexImage%dD(no compression for format)", dimensions
);
1969 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1970 "glCopyTexImage%dD(border!=0)", dimensions
);
1975 if (!mutable_tex_object(ctx
, target
)) {
1976 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1977 "glCopyTexImage%dD(immutable texture)", dimensions
);
1981 /* if we get here, the parameters are OK */
1987 * Test glCopyTexSubImage[12]D() parameters for errors.
1988 * Note that this is the first part of error checking.
1989 * See also copytexsubimage_error_check2() below for the second part.
1991 * \param ctx GL context.
1992 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1993 * \param target texture target given by the user.
1994 * \param level image level given by the user.
1996 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1999 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2000 GLenum target
, GLint level
)
2002 /* Check that the source buffer is complete */
2003 if (ctx
->ReadBuffer
->Name
) {
2004 if (ctx
->ReadBuffer
->_Status
== 0) {
2005 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2007 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2008 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2009 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2014 /* check target (proxies not allowed) */
2015 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2016 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2017 dimensions
, _mesa_lookup_enum_by_nr(target
));
2022 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2023 _mesa_error(ctx
, GL_INVALID_VALUE
,
2024 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2033 * Second part of error checking for glCopyTexSubImage[12]D().
2034 * \param xoffset sub-image x offset given by the user.
2035 * \param yoffset sub-image y offset given by the user.
2036 * \param zoffset sub-image z offset given by the user.
2037 * \param width image width given by the user.
2038 * \param height image height given by the user.
2041 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2042 GLenum target
, GLint level
,
2043 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2044 GLsizei width
, GLsizei height
,
2045 const struct gl_texture_image
*teximage
)
2047 /* check that dest tex image exists */
2049 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2050 "glCopyTexSubImage%dD(undefined texture level: %d)",
2057 _mesa_error(ctx
, GL_INVALID_VALUE
,
2058 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2061 if (dimensions
> 1 && height
< 0) {
2062 _mesa_error(ctx
, GL_INVALID_VALUE
,
2063 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2067 /* check x/y offsets */
2068 if (xoffset
< -((GLint
)teximage
->Border
)) {
2069 _mesa_error(ctx
, GL_INVALID_VALUE
,
2070 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2073 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2074 _mesa_error(ctx
, GL_INVALID_VALUE
,
2075 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2078 if (dimensions
> 1) {
2079 if (yoffset
< -((GLint
)teximage
->Border
)) {
2080 _mesa_error(ctx
, GL_INVALID_VALUE
,
2081 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2084 /* NOTE: we're adding the border here, not subtracting! */
2085 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2086 _mesa_error(ctx
, GL_INVALID_VALUE
,
2087 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2092 /* check z offset */
2093 if (dimensions
> 2) {
2094 if (zoffset
< -((GLint
)teximage
->Border
)) {
2095 _mesa_error(ctx
, GL_INVALID_VALUE
,
2096 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2099 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2100 _mesa_error(ctx
, GL_INVALID_VALUE
,
2101 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2106 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2107 if (compressedteximage_only_format(ctx
, teximage
->InternalFormat
)) {
2108 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2109 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2112 /* offset must be multiple of 4 */
2113 if ((xoffset
& 3) || (yoffset
& 3)) {
2114 _mesa_error(ctx
, GL_INVALID_VALUE
,
2115 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2118 /* size must be multiple of 4 */
2119 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2120 _mesa_error(ctx
, GL_INVALID_VALUE
,
2121 "glCopyTexSubImage%dD(width)", dimensions
);
2124 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2125 _mesa_error(ctx
, GL_INVALID_VALUE
,
2126 "glCopyTexSubImage%dD(height)", dimensions
);
2131 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2132 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2136 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2137 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2138 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2139 dimensions
, teximage
->_BaseFormat
);
2143 /* If copying into an integer texture, the source buffer must also be
2146 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2147 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2148 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2149 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2150 "glCopyTexSubImage%dD(source buffer is not integer format)",
2156 /* if we get here, the parameters are OK */
2161 /** Callback info for walking over FBO hash table */
2164 struct gl_context
*ctx
;
2165 struct gl_texture_object
*texObj
;
2171 * Check render to texture callback. Called from _mesa_HashWalk().
2174 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2176 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2177 const struct cb_info
*info
= (struct cb_info
*) userData
;
2178 struct gl_context
*ctx
= info
->ctx
;
2179 const struct gl_texture_object
*texObj
= info
->texObj
;
2180 const GLuint level
= info
->level
, face
= info
->face
;
2182 /* If this is a user-created FBO */
2185 /* check if any of the FBO's attachments point to 'texObj' */
2186 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2187 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2188 if (att
->Type
== GL_TEXTURE
&&
2189 att
->Texture
== texObj
&&
2190 att
->TextureLevel
== level
&&
2191 att
->CubeMapFace
== face
) {
2192 ASSERT(_mesa_get_attachment_teximage(att
));
2193 /* Tell driver about the new renderbuffer texture */
2194 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2195 /* Mark fb status as indeterminate to force re-validation */
2204 * When a texture image is specified we have to check if it's bound to
2205 * any framebuffer objects (render to texture) in order to detect changes
2206 * in size or format since that effects FBO completeness.
2207 * Any FBOs rendering into the texture must be re-validated.
2210 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2211 struct gl_texture_object
*texObj
,
2212 GLuint face
, GLuint level
)
2214 /* Only check this texture if it's been marked as RenderToTexture */
2215 if (texObj
->_RenderToTexture
) {
2216 struct cb_info info
;
2218 info
.texObj
= texObj
;
2221 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2227 * If the texture object's GenerateMipmap flag is set and we've
2228 * changed the texture base level image, regenerate the rest of the
2229 * mipmap levels now.
2232 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2233 struct gl_texture_object
*texObj
, GLint level
)
2235 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2236 if (texObj
->GenerateMipmap
&&
2237 level
== texObj
->BaseLevel
&&
2238 level
< texObj
->MaxLevel
) {
2239 ASSERT(ctx
->Driver
.GenerateMipmap
);
2240 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2245 /** Debug helper: override the user-requested internal format */
2247 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2250 if (internalFormat
== GL_RGBA16F_ARB
||
2251 internalFormat
== GL_RGBA32F_ARB
) {
2252 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2255 else if (internalFormat
== GL_RGB16F_ARB
||
2256 internalFormat
== GL_RGB32F_ARB
) {
2257 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2260 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2261 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2262 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2263 return GL_LUMINANCE_ALPHA
;
2265 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2266 internalFormat
== GL_LUMINANCE32F_ARB
) {
2267 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2268 return GL_LUMINANCE
;
2270 else if (internalFormat
== GL_ALPHA16F_ARB
||
2271 internalFormat
== GL_ALPHA32F_ARB
) {
2272 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2276 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2277 internalFormat = GL_RGBA;
2281 return internalFormat
;
2284 return internalFormat
;
2290 * Choose the actual hardware format for a texture image.
2291 * Try to use the same format as the previous image level when possible.
2292 * Otherwise, ask the driver for the best format.
2293 * It's important to try to choose a consistant format for all levels
2294 * for efficient texture memory layout/allocation. In particular, this
2295 * comes up during automatic mipmap generation.
2298 _mesa_choose_texture_format(struct gl_context
*ctx
,
2299 struct gl_texture_object
*texObj
,
2300 GLenum target
, GLint level
,
2301 GLenum internalFormat
, GLenum format
, GLenum type
)
2305 /* see if we've already chosen a format for the previous level */
2307 struct gl_texture_image
*prevImage
=
2308 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2309 /* See if the prev level is defined and has an internal format which
2310 * matches the new internal format.
2313 prevImage
->Width
> 0 &&
2314 prevImage
->InternalFormat
== internalFormat
) {
2315 /* use the same format */
2316 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2317 return prevImage
->TexFormat
;
2321 /* choose format from scratch */
2322 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2323 ASSERT(f
!= MESA_FORMAT_NONE
);
2328 * Adjust pixel unpack params and image dimensions to strip off the
2331 * Gallium and intel don't support texture borders. They've seldem been used
2332 * and seldom been implemented correctly anyway.
2334 * \param unpackNew returns the new pixel unpack parameters
2337 strip_texture_border(GLint
*border
,
2338 GLint
*width
, GLint
*height
, GLint
*depth
,
2339 const struct gl_pixelstore_attrib
*unpack
,
2340 struct gl_pixelstore_attrib
*unpackNew
)
2342 assert(*border
> 0); /* sanity check */
2344 *unpackNew
= *unpack
;
2346 if (unpackNew
->RowLength
== 0)
2347 unpackNew
->RowLength
= *width
;
2349 if (depth
&& unpackNew
->ImageHeight
== 0)
2350 unpackNew
->ImageHeight
= *height
;
2352 unpackNew
->SkipPixels
+= *border
;
2354 unpackNew
->SkipRows
+= *border
;
2356 unpackNew
->SkipImages
+= *border
;
2358 assert(*width
>= 3);
2359 *width
= *width
- 2 * *border
;
2360 if (height
&& *height
>= 3)
2361 *height
= *height
- 2 * *border
;
2362 if (depth
&& *depth
>= 3)
2363 *depth
= *depth
- 2 * *border
;
2368 * Common code to implement all the glTexImage1D/2D/3D functions.
2371 teximage(struct gl_context
*ctx
, GLuint dims
,
2372 GLenum target
, GLint level
, GLint internalFormat
,
2373 GLsizei width
, GLsizei height
, GLsizei depth
,
2374 GLint border
, GLenum format
, GLenum type
,
2375 const GLvoid
*pixels
)
2378 struct gl_pixelstore_attrib unpack_no_border
;
2379 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2381 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2383 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2384 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2386 _mesa_lookup_enum_by_nr(target
), level
,
2387 _mesa_lookup_enum_by_nr(internalFormat
),
2388 width
, height
, depth
, border
,
2389 _mesa_lookup_enum_by_nr(format
),
2390 _mesa_lookup_enum_by_nr(type
), pixels
);
2392 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2394 /* target error checking */
2395 if (!legal_teximage_target(ctx
, dims
, target
)) {
2396 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2397 dims
, _mesa_lookup_enum_by_nr(target
));
2401 /* general error checking */
2402 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2403 format
, type
, width
, height
, depth
, border
);
2405 if (_mesa_is_proxy_texture(target
)) {
2406 /* Proxy texture: just clear or set state depending on error checking */
2407 struct gl_texture_image
*texImage
=
2408 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2411 /* when error, clear all proxy texture image parameters */
2413 clear_teximage_fields(texImage
);
2416 /* no error, set the tex image parameters */
2417 struct gl_texture_object
*texObj
=
2418 _mesa_get_current_tex_object(ctx
, target
);
2419 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2424 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2425 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2426 depth
, border
, internalFormat
,
2429 else if (texImage
) {
2430 clear_teximage_fields(texImage
);
2435 /* non-proxy target */
2436 const GLuint face
= _mesa_tex_target_to_face(target
);
2437 struct gl_texture_object
*texObj
;
2438 struct gl_texture_image
*texImage
;
2441 return; /* error was recorded */
2444 /* Allow a hardware driver to just strip out the border, to provide
2445 * reliable but slightly incorrect hardware rendering instead of
2446 * rarely-tested software fallback rendering.
2448 if (border
&& ctx
->Const
.StripTextureBorder
) {
2449 strip_texture_border(&border
, &width
, &height
, &depth
, unpack
,
2451 unpack
= &unpack_no_border
;
2454 if (ctx
->NewState
& _NEW_PIXEL
)
2455 _mesa_update_state(ctx
);
2457 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2459 _mesa_lock_texture(ctx
, texObj
);
2461 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2464 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2467 gl_format texFormat
;
2469 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2471 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2472 internalFormat
, format
,
2475 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2476 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2477 width
, height
, depth
,
2478 border
, internalFormat
, texFormat
);
2480 /* Give the texture to the driver. <pixels> may be null. */
2481 ASSERT(ctx
->Driver
.TexImage3D
);
2484 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2485 width
, border
, format
,
2486 type
, pixels
, unpack
, texObj
,
2490 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2491 width
, height
, border
, format
,
2492 type
, pixels
, unpack
, texObj
,
2496 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2497 width
, height
, depth
, border
, format
,
2498 type
, pixels
, unpack
, texObj
,
2502 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2505 check_gen_mipmap(ctx
, target
, texObj
, level
);
2507 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2510 texObj
->_Complete
= GL_FALSE
;
2511 ctx
->NewState
|= _NEW_TEXTURE
;
2514 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2518 _mesa_unlock_texture(ctx
, texObj
);
2524 * Called from the API. Note that width includes the border.
2527 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2528 GLsizei width
, GLint border
, GLenum format
,
2529 GLenum type
, const GLvoid
*pixels
)
2531 GET_CURRENT_CONTEXT(ctx
);
2532 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2533 border
, format
, type
, pixels
);
2538 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2539 GLsizei width
, GLsizei height
, GLint border
,
2540 GLenum format
, GLenum type
,
2541 const GLvoid
*pixels
)
2543 GET_CURRENT_CONTEXT(ctx
);
2544 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2545 border
, format
, type
, pixels
);
2550 * Called by the API or display list executor.
2551 * Note that width and height include the border.
2554 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2555 GLsizei width
, GLsizei height
, GLsizei depth
,
2556 GLint border
, GLenum format
, GLenum type
,
2557 const GLvoid
*pixels
)
2559 GET_CURRENT_CONTEXT(ctx
);
2560 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2561 border
, format
, type
, pixels
);
2566 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2567 GLsizei width
, GLsizei height
, GLsizei depth
,
2568 GLint border
, GLenum format
, GLenum type
,
2569 const GLvoid
*pixels
)
2571 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2572 depth
, border
, format
, type
, pixels
);
2576 #if FEATURE_OES_EGL_image
2578 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2580 struct gl_texture_object
*texObj
;
2581 struct gl_texture_image
*texImage
;
2582 GET_CURRENT_CONTEXT(ctx
);
2583 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2585 if ((target
== GL_TEXTURE_2D
&&
2586 !ctx
->Extensions
.OES_EGL_image
) ||
2587 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2588 !ctx
->Extensions
.OES_EGL_image_external
)) {
2589 _mesa_error(ctx
, GL_INVALID_ENUM
,
2590 "glEGLImageTargetTexture2D(target=%d)", target
);
2594 if (ctx
->NewState
& _NEW_PIXEL
)
2595 _mesa_update_state(ctx
);
2597 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2598 _mesa_lock_texture(ctx
, texObj
);
2600 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2602 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2604 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2606 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2607 texObj
, texImage
, image
);
2610 texObj
->_Complete
= GL_FALSE
;
2611 ctx
->NewState
|= _NEW_TEXTURE
;
2613 _mesa_unlock_texture(ctx
, texObj
);
2621 * Implement all the glTexSubImage1/2/3D() functions.
2624 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2625 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2626 GLsizei width
, GLsizei height
, GLsizei depth
,
2627 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2629 struct gl_texture_object
*texObj
;
2630 struct gl_texture_image
*texImage
;
2632 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2634 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2635 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2637 _mesa_lookup_enum_by_nr(target
), level
,
2638 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2639 _mesa_lookup_enum_by_nr(format
),
2640 _mesa_lookup_enum_by_nr(type
), pixels
);
2642 /* check target (proxies not allowed) */
2643 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2644 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2645 dims
, _mesa_lookup_enum_by_nr(target
));
2649 if (ctx
->NewState
& _NEW_PIXEL
)
2650 _mesa_update_state(ctx
);
2652 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2653 width
, height
, depth
, format
, type
)) {
2654 return; /* error was detected */
2657 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2659 _mesa_lock_texture(ctx
, texObj
);
2661 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2663 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2664 xoffset
, yoffset
, zoffset
,
2665 width
, height
, depth
,
2666 format
, type
, texImage
)) {
2667 /* error was recorded */
2669 else if (width
> 0 && height
> 0 && depth
> 0) {
2670 /* If we have a border, offset=-1 is legal. Bias by border width. */
2673 zoffset
+= texImage
->Border
;
2676 yoffset
+= texImage
->Border
;
2679 xoffset
+= texImage
->Border
;
2684 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2686 format
, type
, pixels
,
2687 &ctx
->Unpack
, texObj
, texImage
);
2690 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2691 xoffset
, yoffset
, width
, height
,
2692 format
, type
, pixels
,
2693 &ctx
->Unpack
, texObj
, texImage
);
2696 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2697 xoffset
, yoffset
, zoffset
,
2698 width
, height
, depth
,
2699 format
, type
, pixels
,
2700 &ctx
->Unpack
, texObj
, texImage
);
2703 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2706 check_gen_mipmap(ctx
, target
, texObj
, level
);
2708 ctx
->NewState
|= _NEW_TEXTURE
;
2711 _mesa_unlock_texture(ctx
, texObj
);
2716 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2717 GLint xoffset
, GLsizei width
,
2718 GLenum format
, GLenum type
,
2719 const GLvoid
*pixels
)
2721 GET_CURRENT_CONTEXT(ctx
);
2722 texsubimage(ctx
, 1, target
, level
,
2725 format
, type
, pixels
);
2730 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2731 GLint xoffset
, GLint yoffset
,
2732 GLsizei width
, GLsizei height
,
2733 GLenum format
, GLenum type
,
2734 const GLvoid
*pixels
)
2736 GET_CURRENT_CONTEXT(ctx
);
2737 texsubimage(ctx
, 2, target
, level
,
2738 xoffset
, yoffset
, 0,
2740 format
, type
, pixels
);
2746 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2747 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2748 GLsizei width
, GLsizei height
, GLsizei depth
,
2749 GLenum format
, GLenum type
,
2750 const GLvoid
*pixels
)
2752 GET_CURRENT_CONTEXT(ctx
);
2753 texsubimage(ctx
, 3, target
, level
,
2754 xoffset
, yoffset
, zoffset
,
2755 width
, height
, depth
,
2756 format
, type
, pixels
);
2762 * Implement the glCopyTexImage1/2D() functions.
2765 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2766 GLenum target
, GLint level
, GLenum internalFormat
,
2767 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2769 struct gl_texture_object
*texObj
;
2770 struct gl_texture_image
*texImage
;
2771 const GLuint face
= _mesa_tex_target_to_face(target
);
2773 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2775 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2776 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2778 _mesa_lookup_enum_by_nr(target
), level
,
2779 _mesa_lookup_enum_by_nr(internalFormat
),
2780 x
, y
, width
, height
, border
);
2782 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2783 _mesa_update_state(ctx
);
2785 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2786 width
, height
, border
))
2789 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2791 if (border
&& ctx
->Const
.StripTextureBorder
) {
2793 width
-= border
* 2;
2796 height
-= border
* 2;
2801 _mesa_lock_texture(ctx
, texObj
);
2803 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2806 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2809 /* choose actual hw format */
2810 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2815 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2816 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2818 /* Free old texture image */
2819 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2821 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2822 border
, internalFormat
, texFormat
);
2824 /* Allocate texture memory (no pixel data yet) */
2826 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2827 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2828 &ctx
->Unpack
, texObj
, texImage
);
2831 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2832 width
, height
, border
, GL_NONE
, GL_NONE
,
2833 NULL
, &ctx
->Unpack
, texObj
, texImage
);
2836 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2839 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
, dstX
,
2843 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, dstX
, dstY
,
2844 srcX
, srcY
, width
, height
);
2847 check_gen_mipmap(ctx
, target
, texObj
, level
);
2849 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2852 texObj
->_Complete
= GL_FALSE
;
2853 ctx
->NewState
|= _NEW_TEXTURE
;
2856 /* probably too large of image */
2857 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2861 _mesa_unlock_texture(ctx
, texObj
);
2867 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2868 GLenum internalFormat
,
2870 GLsizei width
, GLint border
)
2872 GET_CURRENT_CONTEXT(ctx
);
2873 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2879 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2880 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2883 GET_CURRENT_CONTEXT(ctx
);
2884 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2885 x
, y
, width
, height
, border
);
2891 * Implementation for glCopyTexSubImage1/2/3D() functions.
2894 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2895 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2896 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2898 struct gl_texture_object
*texObj
;
2899 struct gl_texture_image
*texImage
;
2901 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2903 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2904 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2906 _mesa_lookup_enum_by_nr(target
),
2907 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2909 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2910 _mesa_update_state(ctx
);
2912 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2915 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2917 _mesa_lock_texture(ctx
, texObj
);
2919 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2921 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2922 zoffset
, width
, height
, texImage
)) {
2923 /* error was recored */
2926 /* If we have a border, offset=-1 is legal. Bias by border width. */
2929 zoffset
+= texImage
->Border
;
2932 yoffset
+= texImage
->Border
;
2935 xoffset
+= texImage
->Border
;
2938 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2942 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2943 xoffset
, x
, y
, width
);
2946 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2948 x
, y
, width
, height
);
2951 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2952 xoffset
, yoffset
, zoffset
,
2953 x
, y
, width
, height
);
2956 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
2959 check_gen_mipmap(ctx
, target
, texObj
, level
);
2961 ctx
->NewState
|= _NEW_TEXTURE
;
2965 _mesa_unlock_texture(ctx
, texObj
);
2970 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2971 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2973 GET_CURRENT_CONTEXT(ctx
);
2974 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
2980 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2981 GLint xoffset
, GLint yoffset
,
2982 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2984 GET_CURRENT_CONTEXT(ctx
);
2985 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
2992 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2993 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2994 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2996 GET_CURRENT_CONTEXT(ctx
);
2997 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2998 x
, y
, width
, height
);
3004 /**********************************************************************/
3005 /****** Compressed Textures ******/
3006 /**********************************************************************/
3010 * Return expected size of a compressed texture.
3013 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3016 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3017 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3022 * Return compressed texture block size, in pixels.
3025 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3027 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3028 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3033 * Error checking for glCompressedTexImage[123]D().
3034 * \param reason returns reason for error, if any
3035 * \return error code or GL_NO_ERROR.
3038 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3039 GLenum target
, GLint level
,
3040 GLenum internalFormat
, GLsizei width
,
3041 GLsizei height
, GLsizei depth
, GLint border
,
3042 GLsizei imageSize
, char **reason
)
3044 const GLenum proxyTarget
= get_proxy_target(target
);
3045 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3047 GLenum choose_format
;
3049 GLenum proxy_format
;
3051 *reason
= ""; /* no error */
3053 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3055 return GL_INVALID_ENUM
;
3058 /* This will detect any invalid internalFormat value */
3059 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3060 *reason
= "internalFormat";
3061 return GL_INVALID_ENUM
;
3064 switch (internalFormat
) {
3066 case GL_PALETTE4_RGB8_OES
:
3067 case GL_PALETTE4_RGBA8_OES
:
3068 case GL_PALETTE4_R5_G6_B5_OES
:
3069 case GL_PALETTE4_RGBA4_OES
:
3070 case GL_PALETTE4_RGB5_A1_OES
:
3071 case GL_PALETTE8_RGB8_OES
:
3072 case GL_PALETTE8_RGBA8_OES
:
3073 case GL_PALETTE8_R5_G6_B5_OES
:
3074 case GL_PALETTE8_RGBA4_OES
:
3075 case GL_PALETTE8_RGB5_A1_OES
:
3076 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3078 proxy_format
= choose_format
;
3081 if (level
> 0 || level
< -maxLevels
) {
3083 return GL_INVALID_VALUE
;
3086 if (dimensions
!= 2) {
3087 *reason
= "compressed paletted textures must be 2D";
3088 return GL_INVALID_OPERATION
;
3091 /* Figure out the expected texture size (in bytes). This will be
3092 * checked against the actual size later.
3094 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3097 /* This is for the benefit of the TestProxyTexImage below. It expects
3098 * level to be non-negative. OES_compressed_paletted_texture uses a
3099 * weird mechanism where the level specified to glCompressedTexImage2D
3100 * is -(n-1) number of levels in the texture, and the data specifies the
3101 * complete mipmap stack. This is done to ensure the palette is the
3102 * same for all levels.
3109 choose_format
= GL_NONE
;
3110 choose_type
= GL_NONE
;
3111 proxy_format
= internalFormat
;
3114 if (level
< 0 || level
>= maxLevels
) {
3116 return GL_INVALID_VALUE
;
3119 /* Figure out the expected texture size (in bytes). This will be
3120 * checked against the actual size later.
3122 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3126 /* This should really never fail */
3127 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3128 *reason
= "internalFormat";
3129 return GL_INVALID_ENUM
;
3132 /* No compressed formats support borders at this time */
3134 *reason
= "border != 0";
3135 return GL_INVALID_VALUE
;
3138 /* For cube map, width must equal height */
3139 if (_mesa_is_cube_face(target
) && width
!= height
) {
3140 *reason
= "width != height";
3141 return GL_INVALID_VALUE
;
3144 /* check image size against compression block size */
3146 gl_format texFormat
=
3147 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3148 choose_format
, choose_type
);
3151 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3152 if ((width
> bw
&& width
% bw
> 0) ||
3153 (height
> bh
&& height
% bh
> 0)) {
3155 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3156 * generated [...] if any parameter combinations are not
3157 * supported by the specific compressed internal format.
3159 *reason
= "invalid width or height for compression format";
3160 return GL_INVALID_OPERATION
;
3164 /* check image sizes */
3165 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3166 proxy_format
, choose_format
,
3168 width
, height
, depth
, border
)) {
3169 /* See error comment above */
3170 *reason
= "invalid width, height or format";
3171 return GL_INVALID_OPERATION
;
3174 /* check image size in bytes */
3175 if (expectedSize
!= imageSize
) {
3176 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3177 * if <imageSize> is not consistent with the format, dimensions, and
3178 * contents of the specified image.
3180 *reason
= "imageSize inconsistant with width/height/format";
3181 return GL_INVALID_VALUE
;
3184 if (!mutable_tex_object(ctx
, target
)) {
3185 *reason
= "immutable texture";
3186 return GL_INVALID_OPERATION
;
3194 * Error checking for glCompressedTexSubImage[123]D().
3195 * \warning There are some bad assumptions here about the size of compressed
3196 * texture tiles (multiple of 4) used to test the validity of the
3197 * offset and size parameters.
3198 * \return error code or GL_NO_ERROR.
3201 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3202 GLenum target
, GLint level
,
3203 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3204 GLsizei width
, GLsizei height
, GLsizei depth
,
3205 GLenum format
, GLsizei imageSize
)
3207 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3211 if (dimensions
== 1) {
3212 /* 1D compressed textures not allowed */
3213 return GL_INVALID_ENUM
;
3215 else if (dimensions
== 2) {
3216 if (target
== GL_PROXY_TEXTURE_2D
) {
3217 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3219 else if (target
== GL_TEXTURE_2D
) {
3220 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3222 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3223 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3224 return GL_INVALID_ENUM
; /*target*/
3225 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3227 else if (_mesa_is_cube_face(target
)) {
3228 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3229 return GL_INVALID_ENUM
; /*target*/
3230 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3233 return GL_INVALID_ENUM
; /*target*/
3236 else if (dimensions
== 3) {
3237 /* 3D compressed textures not allowed */
3238 return GL_INVALID_ENUM
;
3241 maxTextureSize
= 1 << (maxLevels
- 1);
3243 /* this will catch any invalid compressed format token */
3244 if (!_mesa_is_compressed_format(ctx
, format
))
3245 return GL_INVALID_ENUM
;
3247 if (width
< 1 || width
> maxTextureSize
)
3248 return GL_INVALID_VALUE
;
3250 if ((height
< 1 || height
> maxTextureSize
)
3252 return GL_INVALID_VALUE
;
3254 if (level
< 0 || level
>= maxLevels
)
3255 return GL_INVALID_VALUE
;
3258 * do checks which depend on compression block size
3260 get_compressed_block_size(format
, &bw
, &bh
);
3262 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3263 return GL_INVALID_VALUE
;
3265 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3266 return GL_INVALID_VALUE
;
3268 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3269 return GL_INVALID_VALUE
;
3271 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3272 if (expectedSize
!= imageSize
)
3273 return GL_INVALID_VALUE
;
3280 * Do second part of glCompressedTexSubImage error checking.
3281 * \return GL_TRUE if error found, GL_FALSE otherwise.
3284 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3285 GLsizei width
, GLsizei height
,
3286 GLsizei depth
, GLenum format
,
3287 struct gl_texture_image
*texImage
)
3290 if ((GLint
) format
!= texImage
->InternalFormat
) {
3291 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3292 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3296 if (compressedteximage_only_format(ctx
, format
)) {
3297 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3298 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3303 if (((width
== 1 || width
== 2) &&
3304 width
!= (GLsizei
) texImage
->Width
) ||
3305 (width
> (GLsizei
) texImage
->Width
)) {
3306 _mesa_error(ctx
, GL_INVALID_VALUE
,
3307 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3312 if (((height
== 1 || height
== 2) &&
3313 height
!= (GLsizei
) texImage
->Height
) ||
3314 (height
> (GLsizei
) texImage
->Height
)) {
3315 _mesa_error(ctx
, GL_INVALID_VALUE
,
3316 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3322 if (((depth
== 1 || depth
== 2) &&
3323 depth
!= (GLsizei
) texImage
->Depth
) ||
3324 (depth
> (GLsizei
) texImage
->Depth
)) {
3325 _mesa_error(ctx
, GL_INVALID_VALUE
,
3326 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3336 * Implementation of the glCompressedTexImage1/2/3D() functions.
3339 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3340 GLenum target
, GLint level
,
3341 GLenum internalFormat
, GLsizei width
,
3342 GLsizei height
, GLsizei depth
, GLint border
,
3343 GLsizei imageSize
, const GLvoid
*data
)
3348 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3350 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3352 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3354 _mesa_lookup_enum_by_nr(target
), level
,
3355 _mesa_lookup_enum_by_nr(internalFormat
),
3356 width
, height
, depth
, border
, imageSize
, data
);
3359 if (!legal_teximage_target(ctx
, dims
, target
)) {
3360 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3361 dims
, _mesa_lookup_enum_by_nr(target
));
3365 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3366 internalFormat
, width
, height
, depth
,
3367 border
, imageSize
, &reason
);
3370 /* XXX this is kind of a hack */
3371 if (!error
&& dims
== 2) {
3372 switch (internalFormat
) {
3373 case GL_PALETTE4_RGB8_OES
:
3374 case GL_PALETTE4_RGBA8_OES
:
3375 case GL_PALETTE4_R5_G6_B5_OES
:
3376 case GL_PALETTE4_RGBA4_OES
:
3377 case GL_PALETTE4_RGB5_A1_OES
:
3378 case GL_PALETTE8_RGB8_OES
:
3379 case GL_PALETTE8_RGBA8_OES
:
3380 case GL_PALETTE8_R5_G6_B5_OES
:
3381 case GL_PALETTE8_RGBA4_OES
:
3382 case GL_PALETTE8_RGB5_A1_OES
:
3383 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3384 width
, height
, imageSize
, data
);
3390 if (_mesa_is_proxy_texture(target
)) {
3391 /* Proxy texture: just check for errors and update proxy state */
3392 struct gl_texture_image
*texImage
;
3395 struct gl_texture_object
*texObj
=
3396 _mesa_get_current_tex_object(ctx
, target
);
3397 gl_format texFormat
=
3398 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3399 internalFormat
, GL_NONE
, GL_NONE
);
3400 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3401 error
= GL_OUT_OF_MEMORY
;
3405 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3408 /* if error, clear all proxy texture image parameters */
3409 clear_teximage_fields(texImage
);
3412 /* no error: store the teximage parameters */
3413 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3414 depth
, border
, internalFormat
,
3420 /* non-proxy target */
3421 struct gl_texture_object
*texObj
;
3422 struct gl_texture_image
*texImage
;
3425 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3429 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3431 _mesa_lock_texture(ctx
, texObj
);
3433 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3435 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3436 "glCompressedTexImage%uD", dims
);
3439 gl_format texFormat
;
3441 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3443 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3444 internalFormat
, GL_NONE
,
3447 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3448 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3449 width
, height
, depth
,
3450 border
, internalFormat
, texFormat
);
3454 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3455 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3458 border
, imageSize
, data
,
3462 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3463 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3466 border
, imageSize
, data
,
3470 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3471 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3473 width
, height
, depth
,
3474 border
, imageSize
, data
,
3478 _mesa_problem(ctx
, "bad dims in compressedteximage");
3481 check_gen_mipmap(ctx
, target
, texObj
, level
);
3484 texObj
->_Complete
= GL_FALSE
;
3485 ctx
->NewState
|= _NEW_TEXTURE
;
3488 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3489 "glCompressedTexImage%uD", dims
);
3493 _mesa_unlock_texture(ctx
, texObj
);
3499 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3500 GLenum internalFormat
, GLsizei width
,
3501 GLint border
, GLsizei imageSize
,
3504 GET_CURRENT_CONTEXT(ctx
);
3505 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3506 width
, 1, 1, border
, imageSize
, data
);
3511 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3512 GLenum internalFormat
, GLsizei width
,
3513 GLsizei height
, GLint border
, GLsizei imageSize
,
3516 GET_CURRENT_CONTEXT(ctx
);
3517 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3518 width
, height
, 1, border
, imageSize
, data
);
3523 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3524 GLenum internalFormat
, GLsizei width
,
3525 GLsizei height
, GLsizei depth
, GLint border
,
3526 GLsizei imageSize
, const GLvoid
*data
)
3528 GET_CURRENT_CONTEXT(ctx
);
3529 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3530 width
, height
, depth
, border
, imageSize
, data
);
3535 * Common helper for glCompressedTexSubImage1/2/3D().
3538 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3539 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3540 GLsizei width
, GLsizei height
, GLsizei depth
,
3541 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3543 struct gl_texture_object
*texObj
;
3544 struct gl_texture_image
*texImage
;
3546 GET_CURRENT_CONTEXT(ctx
);
3547 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3549 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3550 xoffset
, 0, 0, /* pos */
3551 width
, height
, depth
, /* size */
3554 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3558 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3560 _mesa_lock_texture(ctx
, texObj
);
3562 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3565 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3566 format
, texImage
)) {
3567 /* error was recorded */
3569 else if (width
> 0 && height
> 0 && depth
> 0) {
3572 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3573 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3575 format
, imageSize
, data
,
3580 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3581 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3584 format
, imageSize
, data
,
3589 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3590 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3591 xoffset
, yoffset
, zoffset
,
3592 width
, height
, depth
,
3593 format
, imageSize
, data
,
3601 check_gen_mipmap(ctx
, target
, texObj
, level
);
3603 ctx
->NewState
|= _NEW_TEXTURE
;
3606 _mesa_unlock_texture(ctx
, texObj
);
3611 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3612 GLsizei width
, GLenum format
,
3613 GLsizei imageSize
, const GLvoid
*data
)
3615 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3616 format
, imageSize
, data
);
3621 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3622 GLint yoffset
, GLsizei width
, GLsizei height
,
3623 GLenum format
, GLsizei imageSize
,
3626 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3627 width
, height
, 1, format
, imageSize
, data
);
3632 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3633 GLint yoffset
, GLint zoffset
, GLsizei width
,
3634 GLsizei height
, GLsizei depth
, GLenum format
,
3635 GLsizei imageSize
, const GLvoid
*data
)
3637 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3638 width
, height
, depth
, format
, imageSize
, data
);
3643 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3644 * return the basic data type and number of components for the format.
3645 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3648 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3649 GLenum
*datatype
, GLuint
*components
)
3651 switch (internalFormat
) {
3653 *datatype
= GL_UNSIGNED_BYTE
;
3657 *datatype
= GL_UNSIGNED_SHORT
;
3660 case GL_ALPHA16F_ARB
:
3661 *datatype
= GL_HALF_FLOAT
;
3664 case GL_ALPHA32F_ARB
:
3665 *datatype
= GL_FLOAT
;
3668 case GL_ALPHA8I_EXT
:
3669 *datatype
= GL_BYTE
;
3672 case GL_ALPHA16I_EXT
:
3673 *datatype
= GL_SHORT
;
3676 case GL_ALPHA32I_EXT
:
3680 case GL_ALPHA8UI_EXT
:
3681 *datatype
= GL_UNSIGNED_BYTE
;
3684 case GL_ALPHA16UI_EXT
:
3685 *datatype
= GL_UNSIGNED_SHORT
;
3688 case GL_ALPHA32UI_EXT
:
3689 *datatype
= GL_UNSIGNED_INT
;
3693 *datatype
= GL_UNSIGNED_BYTE
;
3696 case GL_LUMINANCE16
:
3697 *datatype
= GL_UNSIGNED_SHORT
;
3700 case GL_LUMINANCE16F_ARB
:
3701 *datatype
= GL_HALF_FLOAT
;
3704 case GL_LUMINANCE32F_ARB
:
3705 *datatype
= GL_FLOAT
;
3708 case GL_LUMINANCE8I_EXT
:
3709 *datatype
= GL_BYTE
;
3712 case GL_LUMINANCE16I_EXT
:
3713 *datatype
= GL_SHORT
;
3716 case GL_LUMINANCE32I_EXT
:
3720 case GL_LUMINANCE8UI_EXT
:
3721 *datatype
= GL_UNSIGNED_BYTE
;
3724 case GL_LUMINANCE16UI_EXT
:
3725 *datatype
= GL_UNSIGNED_SHORT
;
3728 case GL_LUMINANCE32UI_EXT
:
3729 *datatype
= GL_UNSIGNED_INT
;
3732 case GL_LUMINANCE8_ALPHA8
:
3733 *datatype
= GL_UNSIGNED_BYTE
;
3736 case GL_LUMINANCE16_ALPHA16
:
3737 *datatype
= GL_UNSIGNED_SHORT
;
3740 case GL_LUMINANCE_ALPHA16F_ARB
:
3741 *datatype
= GL_HALF_FLOAT
;
3744 case GL_LUMINANCE_ALPHA32F_ARB
:
3745 *datatype
= GL_FLOAT
;
3748 case GL_LUMINANCE_ALPHA8I_EXT
:
3749 *datatype
= GL_BYTE
;
3752 case GL_LUMINANCE_ALPHA16I_EXT
:
3753 *datatype
= GL_SHORT
;
3756 case GL_LUMINANCE_ALPHA32I_EXT
:
3760 case GL_LUMINANCE_ALPHA8UI_EXT
:
3761 *datatype
= GL_UNSIGNED_BYTE
;
3764 case GL_LUMINANCE_ALPHA16UI_EXT
:
3765 *datatype
= GL_UNSIGNED_SHORT
;
3768 case GL_LUMINANCE_ALPHA32UI_EXT
:
3769 *datatype
= GL_UNSIGNED_INT
;
3773 *datatype
= GL_UNSIGNED_BYTE
;
3776 case GL_INTENSITY16
:
3777 *datatype
= GL_UNSIGNED_SHORT
;
3780 case GL_INTENSITY16F_ARB
:
3781 *datatype
= GL_HALF_FLOAT
;
3784 case GL_INTENSITY32F_ARB
:
3785 *datatype
= GL_FLOAT
;
3788 case GL_INTENSITY8I_EXT
:
3789 *datatype
= GL_BYTE
;
3792 case GL_INTENSITY16I_EXT
:
3793 *datatype
= GL_SHORT
;
3796 case GL_INTENSITY32I_EXT
:
3800 case GL_INTENSITY8UI_EXT
:
3801 *datatype
= GL_UNSIGNED_BYTE
;
3804 case GL_INTENSITY16UI_EXT
:
3805 *datatype
= GL_UNSIGNED_SHORT
;
3808 case GL_INTENSITY32UI_EXT
:
3809 *datatype
= GL_UNSIGNED_INT
;
3813 *datatype
= GL_UNSIGNED_BYTE
;
3817 *datatype
= GL_UNSIGNED_SHORT
;
3820 case GL_RGBA16F_ARB
:
3821 *datatype
= GL_HALF_FLOAT
;
3824 case GL_RGBA32F_ARB
:
3825 *datatype
= GL_FLOAT
;
3829 *datatype
= GL_BYTE
;
3832 case GL_RGBA16I_EXT
:
3833 *datatype
= GL_SHORT
;
3836 case GL_RGBA32I_EXT
:
3840 case GL_RGBA8UI_EXT
:
3841 *datatype
= GL_UNSIGNED_BYTE
;
3844 case GL_RGBA16UI_EXT
:
3845 *datatype
= GL_UNSIGNED_SHORT
;
3848 case GL_RGBA32UI_EXT
:
3849 *datatype
= GL_UNSIGNED_INT
;
3856 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3859 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3866 /** GL_ARB_texture_buffer_object */
3868 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3870 struct gl_texture_object
*texObj
;
3871 struct gl_buffer_object
*bufObj
;
3875 GET_CURRENT_CONTEXT(ctx
);
3876 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3878 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3879 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3883 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3884 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3888 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3889 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3894 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3895 if (buffer
&& !bufObj
) {
3896 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3900 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3902 _mesa_lock_texture(ctx
, texObj
);
3904 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3905 texObj
->BufferObjectFormat
= internalFormat
;
3907 _mesa_unlock_texture(ctx
, texObj
);