2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "mfeatures.h"
44 #include "texcompress.h"
52 * State changes which we care about for glCopyTex[Sub]Image() calls.
53 * In particular, we care about pixel transfer state and buffer state
54 * (such as glReadBuffer to make sure we read from the right renderbuffer).
56 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
61 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
65 _mesa_alloc_texmemory(GLsizei bytes
)
67 return _mesa_align_malloc(bytes
, 512);
72 * Free texture memory allocated with _mesa_alloc_texmemory()
75 _mesa_free_texmemory(void *m
)
82 * Return the simple base format for a given internal texture format.
83 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
85 * \param ctx GL context.
86 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
88 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
89 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
91 * This is the format which is used during texture application (i.e. the
92 * texture format and env mode determine the arithmetic used.
94 * XXX this could be static
97 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
99 switch (internalFormat
) {
114 case GL_LUMINANCE_ALPHA
:
115 case GL_LUMINANCE4_ALPHA4
:
116 case GL_LUMINANCE6_ALPHA2
:
117 case GL_LUMINANCE8_ALPHA8
:
118 case GL_LUMINANCE12_ALPHA4
:
119 case GL_LUMINANCE12_ALPHA12
:
120 case GL_LUMINANCE16_ALPHA16
:
121 return GL_LUMINANCE_ALPHA
;
152 if (ctx
->Extensions
.EXT_texture_format_BGRA8888
) {
153 switch (internalFormat
) {
161 if (ctx
->Extensions
.ARB_depth_texture
) {
162 switch (internalFormat
) {
163 case GL_DEPTH_COMPONENT
:
164 case GL_DEPTH_COMPONENT16
:
165 case GL_DEPTH_COMPONENT24
:
166 case GL_DEPTH_COMPONENT32
:
167 return GL_DEPTH_COMPONENT
;
173 switch (internalFormat
) {
174 case GL_COMPRESSED_ALPHA
:
176 case GL_COMPRESSED_LUMINANCE
:
178 case GL_COMPRESSED_LUMINANCE_ALPHA
:
179 return GL_LUMINANCE_ALPHA
;
180 case GL_COMPRESSED_INTENSITY
:
182 case GL_COMPRESSED_RGB
:
184 case GL_COMPRESSED_RGBA
:
190 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
191 switch (internalFormat
) {
192 case GL_COMPRESSED_RGB_FXT1_3DFX
:
194 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
201 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
202 switch (internalFormat
) {
203 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
205 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
206 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
207 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
214 if (ctx
->Extensions
.S3_s3tc
) {
215 switch (internalFormat
) {
227 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
228 if (internalFormat
== GL_YCBCR_MESA
)
229 return GL_YCBCR_MESA
;
232 if (ctx
->Extensions
.ARB_texture_float
) {
233 switch (internalFormat
) {
234 case GL_ALPHA16F_ARB
:
235 case GL_ALPHA32F_ARB
:
243 case GL_INTENSITY16F_ARB
:
244 case GL_INTENSITY32F_ARB
:
246 case GL_LUMINANCE16F_ARB
:
247 case GL_LUMINANCE32F_ARB
:
249 case GL_LUMINANCE_ALPHA16F_ARB
:
250 case GL_LUMINANCE_ALPHA32F_ARB
:
251 return GL_LUMINANCE_ALPHA
;
257 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
258 switch (internalFormat
) {
267 if (ctx
->Extensions
.EXT_texture_snorm
) {
268 switch (internalFormat
) {
283 case GL_RGBA16_SNORM
:
286 case GL_ALPHA8_SNORM
:
287 case GL_ALPHA16_SNORM
:
289 case GL_LUMINANCE_SNORM
:
290 case GL_LUMINANCE8_SNORM
:
291 case GL_LUMINANCE16_SNORM
:
293 case GL_LUMINANCE_ALPHA_SNORM
:
294 case GL_LUMINANCE8_ALPHA8_SNORM
:
295 case GL_LUMINANCE16_ALPHA16_SNORM
:
296 return GL_LUMINANCE_ALPHA
;
297 case GL_INTENSITY_SNORM
:
298 case GL_INTENSITY8_SNORM
:
299 case GL_INTENSITY16_SNORM
:
306 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
307 switch (internalFormat
) {
308 case GL_DEPTH_STENCIL_EXT
:
309 case GL_DEPTH24_STENCIL8_EXT
:
310 return GL_DEPTH_STENCIL_EXT
;
316 #if FEATURE_EXT_texture_sRGB
317 if (ctx
->Extensions
.EXT_texture_sRGB
) {
318 switch (internalFormat
) {
321 case GL_COMPRESSED_SRGB_EXT
:
322 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
324 case GL_SRGB_ALPHA_EXT
:
325 case GL_SRGB8_ALPHA8_EXT
:
326 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
327 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
328 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
329 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
331 case GL_SLUMINANCE_ALPHA_EXT
:
332 case GL_SLUMINANCE8_ALPHA8_EXT
:
333 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
334 return GL_LUMINANCE_ALPHA
;
335 case GL_SLUMINANCE_EXT
:
336 case GL_SLUMINANCE8_EXT
:
337 case GL_COMPRESSED_SLUMINANCE_EXT
:
343 #endif /* FEATURE_EXT_texture_sRGB */
345 if (ctx
->Extensions
.EXT_texture_integer
) {
346 switch (internalFormat
) {
348 case GL_RGBA16UI_EXT
:
349 case GL_RGBA32UI_EXT
:
361 case GL_ALPHA8UI_EXT
:
362 case GL_ALPHA16UI_EXT
:
363 case GL_ALPHA32UI_EXT
:
365 case GL_ALPHA16I_EXT
:
366 case GL_ALPHA32I_EXT
:
368 case GL_INTENSITY8UI_EXT
:
369 case GL_INTENSITY16UI_EXT
:
370 case GL_INTENSITY32UI_EXT
:
371 case GL_INTENSITY8I_EXT
:
372 case GL_INTENSITY16I_EXT
:
373 case GL_INTENSITY32I_EXT
:
375 case GL_LUMINANCE8UI_EXT
:
376 case GL_LUMINANCE16UI_EXT
:
377 case GL_LUMINANCE32UI_EXT
:
378 case GL_LUMINANCE8I_EXT
:
379 case GL_LUMINANCE16I_EXT
:
380 case GL_LUMINANCE32I_EXT
:
382 case GL_LUMINANCE_ALPHA8UI_EXT
:
383 case GL_LUMINANCE_ALPHA16UI_EXT
:
384 case GL_LUMINANCE_ALPHA32UI_EXT
:
385 case GL_LUMINANCE_ALPHA8I_EXT
:
386 case GL_LUMINANCE_ALPHA16I_EXT
:
387 case GL_LUMINANCE_ALPHA32I_EXT
:
388 return GL_LUMINANCE_ALPHA
;
394 if (ctx
->Extensions
.ARB_texture_rg
) {
395 switch (internalFormat
) {
397 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
399 if (!ctx
->Extensions
.ARB_half_float_pixel
)
403 if (!ctx
->Extensions
.ARB_texture_float
)
412 if (!ctx
->Extensions
.EXT_texture_integer
)
418 case GL_COMPRESSED_RED
:
422 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
424 if (!ctx
->Extensions
.ARB_half_float_pixel
)
428 if (!ctx
->Extensions
.ARB_texture_float
)
437 if (!ctx
->Extensions
.EXT_texture_integer
)
443 case GL_COMPRESSED_RG
:
450 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
451 switch (internalFormat
) {
459 if (ctx
->Extensions
.EXT_packed_float
) {
460 switch (internalFormat
) {
461 case GL_R11F_G11F_B10F_EXT
:
468 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
469 switch (internalFormat
) {
470 case GL_DEPTH_COMPONENT32F
:
471 return GL_DEPTH_COMPONENT
;
472 case GL_DEPTH32F_STENCIL8
:
473 return GL_DEPTH_STENCIL
;
479 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
480 switch (internalFormat
) {
481 case GL_COMPRESSED_RED_RGTC1
:
482 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
484 case GL_COMPRESSED_RG_RGTC2
:
485 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
492 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
493 switch (internalFormat
) {
494 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
495 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
497 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
498 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
499 return GL_LUMINANCE_ALPHA
;
505 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
506 switch (internalFormat
) {
507 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
508 return GL_LUMINANCE_ALPHA
;
514 if (ctx
->API
== API_OPENGLES
) {
515 switch (internalFormat
) {
516 case GL_PALETTE4_RGB8_OES
:
517 case GL_PALETTE4_R5_G6_B5_OES
:
518 case GL_PALETTE8_RGB8_OES
:
519 case GL_PALETTE8_R5_G6_B5_OES
:
521 case GL_PALETTE4_RGBA8_OES
:
522 case GL_PALETTE8_RGB5_A1_OES
:
523 case GL_PALETTE4_RGBA4_OES
:
524 case GL_PALETTE4_RGB5_A1_OES
:
525 case GL_PALETTE8_RGBA8_OES
:
526 case GL_PALETTE8_RGBA4_OES
:
533 return -1; /* error */
538 * For cube map faces, return a face index in [0,5].
539 * For other targets return 0;
542 _mesa_tex_target_to_face(GLenum target
)
544 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
545 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
546 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
554 * Store a gl_texture_image pointer in a gl_texture_object structure
555 * according to the target and level parameters.
557 * \param tObj texture object.
558 * \param target texture target.
559 * \param level image level.
560 * \param texImage texture image.
563 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
564 GLenum target
, GLint level
,
565 struct gl_texture_image
*texImage
)
567 const GLuint face
= _mesa_tex_target_to_face(target
);
571 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
573 tObj
->Image
[face
][level
] = texImage
;
575 /* Set the 'back' pointer */
576 texImage
->TexObject
= tObj
;
577 texImage
->Level
= level
;
578 texImage
->Face
= face
;
583 * Allocate a texture image structure.
585 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
588 * \return a pointer to gl_texture_image struct with all fields initialized to
591 struct gl_texture_image
*
592 _mesa_new_texture_image( struct gl_context
*ctx
)
595 return CALLOC_STRUCT(gl_texture_image
);
600 * Free texture image data.
601 * This function is a fallback called via ctx->Driver.FreeTextureImageBuffer().
603 * \param texImage texture image.
605 * Free the texture image data if it's not marked as client data.
608 _mesa_free_texture_image_data(struct gl_context
*ctx
,
609 struct gl_texture_image
*texImage
)
613 if (texImage
->Data
&& !texImage
->IsClientData
) {
614 /* free the old texture data */
615 _mesa_free_texmemory(texImage
->Data
);
618 texImage
->Data
= NULL
;
623 * Free a gl_texture_image and associated data.
624 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
626 * \param texImage texture image.
628 * Free the texture image structure and the associated image data.
631 _mesa_delete_texture_image(struct gl_context
*ctx
,
632 struct gl_texture_image
*texImage
)
634 /* Free texImage->Data and/or any other driver-specific texture
637 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
638 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
640 ASSERT(texImage
->Data
== NULL
);
641 if (texImage
->ImageOffsets
)
642 free(texImage
->ImageOffsets
);
648 * Test if a target is a proxy target.
650 * \param target texture target.
652 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
655 _mesa_is_proxy_texture(GLenum target
)
657 /* NUM_TEXTURE_TARGETS should match number of terms below,
658 * except there's no proxy for GL_TEXTURE_BUFFER.
660 assert(NUM_TEXTURE_TARGETS
== 8);
662 return (target
== GL_PROXY_TEXTURE_1D
||
663 target
== GL_PROXY_TEXTURE_2D
||
664 target
== GL_PROXY_TEXTURE_3D
||
665 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
666 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
667 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
668 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
673 * Return the proxy target which corresponds to the given texture target
676 get_proxy_target(GLenum target
)
680 case GL_PROXY_TEXTURE_1D
:
681 return GL_PROXY_TEXTURE_1D
;
683 case GL_PROXY_TEXTURE_2D
:
684 return GL_PROXY_TEXTURE_2D
;
686 case GL_PROXY_TEXTURE_3D
:
687 return GL_PROXY_TEXTURE_3D
;
688 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
689 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
690 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
691 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
692 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
693 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
694 case GL_TEXTURE_CUBE_MAP_ARB
:
695 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
696 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
697 case GL_TEXTURE_RECTANGLE_NV
:
698 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
699 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
700 case GL_TEXTURE_1D_ARRAY_EXT
:
701 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
702 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
703 case GL_TEXTURE_2D_ARRAY_EXT
:
704 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
705 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
707 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
714 * Get the texture object that corresponds to the target of the given
715 * texture unit. The target should have already been checked for validity.
717 * \param ctx GL context.
718 * \param texUnit texture unit.
719 * \param target texture target.
721 * \return pointer to the texture object on success, or NULL on failure.
723 struct gl_texture_object
*
724 _mesa_select_tex_object(struct gl_context
*ctx
,
725 const struct gl_texture_unit
*texUnit
,
728 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
729 ctx
->Extensions
.EXT_texture_array
);
733 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
734 case GL_PROXY_TEXTURE_1D
:
735 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
737 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
738 case GL_PROXY_TEXTURE_2D
:
739 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
741 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
742 case GL_PROXY_TEXTURE_3D
:
743 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
744 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
745 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
746 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
747 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
748 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
749 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
750 case GL_TEXTURE_CUBE_MAP_ARB
:
751 return ctx
->Extensions
.ARB_texture_cube_map
752 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
753 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
754 return ctx
->Extensions
.ARB_texture_cube_map
755 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
756 case GL_TEXTURE_RECTANGLE_NV
:
757 return ctx
->Extensions
.NV_texture_rectangle
758 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
759 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
760 return ctx
->Extensions
.NV_texture_rectangle
761 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
762 case GL_TEXTURE_1D_ARRAY_EXT
:
763 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
764 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
765 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
766 case GL_TEXTURE_2D_ARRAY_EXT
:
767 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
768 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
769 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
770 case GL_TEXTURE_BUFFER
:
771 return ctx
->Extensions
.ARB_texture_buffer_object
772 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
774 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
781 * Return pointer to texture object for given target on current texture unit.
783 struct gl_texture_object
*
784 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
786 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
787 return _mesa_select_tex_object(ctx
, texUnit
, target
);
792 * Get a texture image pointer from a texture object, given a texture
793 * target and mipmap level. The target and level parameters should
794 * have already been error-checked.
796 * \param ctx GL context.
797 * \param texObj texture unit.
798 * \param target texture target.
799 * \param level image level.
801 * \return pointer to the texture image structure, or NULL on failure.
803 struct gl_texture_image
*
804 _mesa_select_tex_image(struct gl_context
*ctx
,
805 const struct gl_texture_object
*texObj
,
806 GLenum target
, GLint level
)
808 const GLuint face
= _mesa_tex_target_to_face(target
);
812 ASSERT(level
< MAX_TEXTURE_LEVELS
);
814 return texObj
->Image
[face
][level
];
819 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
820 * it and install it. Only return NULL if passed a bad parameter or run
823 struct gl_texture_image
*
824 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
825 GLenum target
, GLint level
)
827 struct gl_texture_image
*texImage
;
832 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
834 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
836 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
840 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
848 * Return pointer to the specified proxy texture image.
849 * Note that proxy textures are per-context, not per-texture unit.
850 * \return pointer to texture image or NULL if invalid target, invalid
851 * level, or out of memory.
853 struct gl_texture_image
*
854 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
856 struct gl_texture_image
*texImage
;
863 case GL_PROXY_TEXTURE_1D
:
864 if (level
>= ctx
->Const
.MaxTextureLevels
)
866 texIndex
= TEXTURE_1D_INDEX
;
868 case GL_PROXY_TEXTURE_2D
:
869 if (level
>= ctx
->Const
.MaxTextureLevels
)
871 texIndex
= TEXTURE_2D_INDEX
;
873 case GL_PROXY_TEXTURE_3D
:
874 if (level
>= ctx
->Const
.Max3DTextureLevels
)
876 texIndex
= TEXTURE_3D_INDEX
;
878 case GL_PROXY_TEXTURE_CUBE_MAP
:
879 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
881 texIndex
= TEXTURE_CUBE_INDEX
;
883 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
886 texIndex
= TEXTURE_RECT_INDEX
;
888 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
889 if (level
>= ctx
->Const
.MaxTextureLevels
)
891 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
893 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
894 if (level
>= ctx
->Const
.MaxTextureLevels
)
896 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
902 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
904 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
906 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
909 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
910 /* Set the 'back' pointer */
911 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
918 * Get the maximum number of allowed mipmap levels.
920 * \param ctx GL context.
921 * \param target texture target.
923 * \return the maximum number of allowed mipmap levels for the given
924 * texture target, or zero if passed a bad target.
929 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
933 case GL_PROXY_TEXTURE_1D
:
935 case GL_PROXY_TEXTURE_2D
:
936 return ctx
->Const
.MaxTextureLevels
;
938 case GL_PROXY_TEXTURE_3D
:
939 return ctx
->Const
.Max3DTextureLevels
;
940 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
941 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
942 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
943 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
944 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
945 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
946 case GL_TEXTURE_CUBE_MAP_ARB
:
947 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
948 return ctx
->Extensions
.ARB_texture_cube_map
949 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
950 case GL_TEXTURE_RECTANGLE_NV
:
951 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
952 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
953 case GL_TEXTURE_1D_ARRAY_EXT
:
954 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
955 case GL_TEXTURE_2D_ARRAY_EXT
:
956 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
957 return (ctx
->Extensions
.MESA_texture_array
||
958 ctx
->Extensions
.EXT_texture_array
)
959 ? ctx
->Const
.MaxTextureLevels
: 0;
960 case GL_TEXTURE_BUFFER
:
963 return 0; /* bad target */
969 * Return number of dimensions per mipmap level for the given texture target.
972 _mesa_get_texture_dimensions(GLenum target
)
976 case GL_PROXY_TEXTURE_1D
:
979 case GL_TEXTURE_RECTANGLE
:
980 case GL_TEXTURE_CUBE_MAP
:
981 case GL_PROXY_TEXTURE_2D
:
982 case GL_PROXY_TEXTURE_RECTANGLE
:
983 case GL_PROXY_TEXTURE_CUBE_MAP
:
984 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
985 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
986 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
987 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
988 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
989 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
990 case GL_TEXTURE_1D_ARRAY
:
991 case GL_PROXY_TEXTURE_1D_ARRAY
:
994 case GL_PROXY_TEXTURE_3D
:
995 case GL_TEXTURE_2D_ARRAY
:
996 case GL_PROXY_TEXTURE_2D_ARRAY
:
998 case GL_TEXTURE_BUFFER
:
1001 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1010 #if 000 /* not used anymore */
1012 * glTexImage[123]D can accept a NULL image pointer. In this case we
1013 * create a texture image with unspecified image contents per the OpenGL
1017 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1019 const GLint components
= _mesa_components_in_format(format
);
1020 const GLint numPixels
= width
* height
* depth
;
1021 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1025 * Let's see if anyone finds this. If glTexImage2D() is called with
1026 * a NULL image pointer then load the texture image with something
1027 * interesting instead of leaving it indeterminate.
1030 static const char message
[8][32] = {
1031 " X X XXXXX XXX X ",
1032 " XX XX X X X X X ",
1034 " X X XXXX XXX XXXXX ",
1037 " X X XXXXX XXX X X ",
1041 GLubyte
*imgPtr
= data
;
1043 for (h
= 0; h
< depth
; h
++) {
1044 for (i
= 0; i
< height
; i
++) {
1045 GLint srcRow
= 7 - (i
% 8);
1046 for (j
= 0; j
< width
; j
++) {
1047 GLint srcCol
= j
% 32;
1048 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1049 for (k
= 0; k
< components
; k
++) {
1065 * Reset the fields of a gl_texture_image struct to zero.
1067 * \param img texture image structure.
1069 * This is called when a proxy texture test fails, we set all the
1070 * image members (except DriverData) to zero.
1071 * It's also used in glTexImage[123]D as a safeguard to be sure all
1072 * required fields get initialized properly by the Driver.TexImage[123]D
1076 clear_teximage_fields(struct gl_texture_image
*img
)
1079 img
->_BaseFormat
= 0;
1080 img
->InternalFormat
= 0;
1086 if (img
->ImageOffsets
) {
1087 free(img
->ImageOffsets
);
1088 img
->ImageOffsets
= NULL
;
1094 img
->HeightLog2
= 0;
1097 img
->TexFormat
= MESA_FORMAT_NONE
;
1102 * Initialize basic fields of the gl_texture_image struct.
1104 * \param ctx GL context.
1105 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1106 * \param img texture image structure to be initialized.
1107 * \param width image width.
1108 * \param height image height.
1109 * \param depth image depth.
1110 * \param border image border.
1111 * \param internalFormat internal format.
1112 * \param format the actual hardware format (one of MESA_FORMAT_*)
1114 * Fills in the fields of \p img with the given information.
1115 * Note: width, height and depth include the border.
1118 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1119 struct gl_texture_image
*img
,
1120 GLsizei width
, GLsizei height
, GLsizei depth
,
1121 GLint border
, GLenum internalFormat
,
1128 ASSERT(height
>= 0);
1131 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1132 ASSERT(img
->_BaseFormat
> 0);
1133 img
->InternalFormat
= internalFormat
;
1134 img
->Border
= border
;
1136 img
->Height
= height
;
1139 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1140 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1142 if (height
== 1) { /* 1-D texture */
1144 img
->HeightLog2
= 0;
1147 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1148 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1151 if (depth
== 1) { /* 2-D texture */
1156 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1157 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1160 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1162 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1163 img
->RowStride
= width
;
1164 /* Allocate the ImageOffsets array and initialize to typical values.
1165 * We allocate the array for 1D/2D textures too in order to avoid special-
1166 * case code in the texstore routines.
1168 if (img
->ImageOffsets
)
1169 free(img
->ImageOffsets
);
1170 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1171 for (i
= 0; i
< depth
; i
++) {
1172 img
->ImageOffsets
[i
] = i
* width
* height
;
1175 img
->TexFormat
= format
;
1180 * Free and clear fields of the gl_texture_image struct.
1182 * \param ctx GL context.
1183 * \param texImage texture image structure to be cleared.
1185 * After the call, \p texImage will have no data associated with it. Its
1186 * fields are cleared so that its parent object will test incomplete.
1189 _mesa_clear_texture_image(struct gl_context
*ctx
,
1190 struct gl_texture_image
*texImage
)
1192 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1193 clear_teximage_fields(texImage
);
1198 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1199 * level, width, height and depth against the ctx->Const limits for textures.
1201 * A hardware driver might override this function if, for example, the
1202 * max 3D texture size is 512x512x64 (i.e. not a cube).
1204 * Note that width, height, depth == 0 is not an error. However, a
1205 * texture with zero width/height/depth will be considered "incomplete"
1206 * and texturing will effectively be disabled.
1208 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1209 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1210 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1211 * \param level as passed to glTexImage
1212 * \param internalFormat as passed to glTexImage
1213 * \param format as passed to glTexImage
1214 * \param type as passed to glTexImage
1215 * \param width as passed to glTexImage
1216 * \param height as passed to glTexImage
1217 * \param depth as passed to glTexImage
1218 * \param border as passed to glTexImage
1219 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1222 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1223 GLint internalFormat
, GLenum format
, GLenum type
,
1224 GLint width
, GLint height
, GLint depth
, GLint border
)
1228 (void) internalFormat
;
1233 case GL_PROXY_TEXTURE_1D
:
1234 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1235 if (width
< 2 * border
|| width
> 2 + maxSize
)
1237 if (level
>= ctx
->Const
.MaxTextureLevels
)
1239 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1240 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1245 case GL_PROXY_TEXTURE_2D
:
1246 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1247 if (width
< 2 * border
|| width
> 2 + maxSize
)
1249 if (height
< 2 * border
|| height
> 2 + maxSize
)
1251 if (level
>= ctx
->Const
.MaxTextureLevels
)
1253 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1254 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1256 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1261 case GL_PROXY_TEXTURE_3D
:
1262 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1263 if (width
< 2 * border
|| width
> 2 + maxSize
)
1265 if (height
< 2 * border
|| height
> 2 + maxSize
)
1267 if (depth
< 2 * border
|| depth
> 2 + maxSize
)
1269 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1271 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1272 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1274 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1276 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1281 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1282 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1283 if (width
< 0 || width
> maxSize
)
1285 if (height
< 0 || height
> maxSize
)
1291 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1292 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1293 if (width
< 2 * border
|| width
> 2 + maxSize
)
1295 if (height
< 2 * border
|| height
> 2 + maxSize
)
1297 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1299 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1300 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1302 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1307 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1308 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1309 if (width
< 2 * border
|| width
> 2 + maxSize
)
1311 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1313 if (level
>= ctx
->Const
.MaxTextureLevels
)
1315 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1316 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1321 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1322 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1323 if (width
< 2 * border
|| width
> 2 + maxSize
)
1325 if (height
< 2 * border
|| height
> 2 + maxSize
)
1327 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1329 if (level
>= ctx
->Const
.MaxTextureLevels
)
1331 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1332 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1334 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1340 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1347 * Check if the memory used by the texture would exceed the driver's limit.
1348 * This lets us support a max 3D texture size of 8K (for example) but
1349 * prevents allocating a full 8K x 8K x 8K texture.
1350 * XXX this could be rolled into the proxy texture size test (above) but
1351 * we don't have the actual texture internal format at that point.
1354 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1355 GLint width
, GLint height
, GLint depth
)
1357 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1358 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1359 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1365 * Helper function to determine whether a target and specific compression
1366 * format are supported.
1369 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1372 (void) intFormat
; /* not used yet */
1376 case GL_PROXY_TEXTURE_2D
:
1377 return GL_TRUE
; /* true for any compressed format so far */
1378 case GL_PROXY_TEXTURE_CUBE_MAP
:
1379 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1380 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1381 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1382 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1383 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1384 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1385 return ctx
->Extensions
.ARB_texture_cube_map
;
1386 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1387 case GL_TEXTURE_2D_ARRAY_EXT
:
1388 return (ctx
->Extensions
.MESA_texture_array
||
1389 ctx
->Extensions
.EXT_texture_array
);
1397 * Check if the given texture target value is legal for a
1398 * glTexImage1/2/3D call.
1401 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1407 case GL_PROXY_TEXTURE_1D
:
1415 case GL_PROXY_TEXTURE_2D
:
1417 case GL_PROXY_TEXTURE_CUBE_MAP
:
1418 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1419 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1420 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1421 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1422 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1423 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1424 return ctx
->Extensions
.ARB_texture_cube_map
;
1425 case GL_TEXTURE_RECTANGLE_NV
:
1426 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1427 return ctx
->Extensions
.NV_texture_rectangle
;
1428 case GL_TEXTURE_1D_ARRAY_EXT
:
1429 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1430 return (ctx
->Extensions
.MESA_texture_array
||
1431 ctx
->Extensions
.EXT_texture_array
);
1438 case GL_PROXY_TEXTURE_3D
:
1440 case GL_TEXTURE_2D_ARRAY_EXT
:
1441 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1442 return (ctx
->Extensions
.MESA_texture_array
||
1443 ctx
->Extensions
.EXT_texture_array
);
1448 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1455 * Check if the given texture target value is legal for a
1456 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1457 * The difference compared to legal_teximage_target() above is that
1458 * proxy targets are not supported.
1461 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1465 return target
== GL_TEXTURE_1D
;
1470 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1471 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1472 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1473 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1474 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1475 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1476 return ctx
->Extensions
.ARB_texture_cube_map
;
1477 case GL_TEXTURE_RECTANGLE_NV
:
1478 return ctx
->Extensions
.NV_texture_rectangle
;
1479 case GL_TEXTURE_1D_ARRAY_EXT
:
1480 return (ctx
->Extensions
.MESA_texture_array
||
1481 ctx
->Extensions
.EXT_texture_array
);
1489 case GL_TEXTURE_2D_ARRAY_EXT
:
1490 return (ctx
->Extensions
.MESA_texture_array
||
1491 ctx
->Extensions
.EXT_texture_array
);
1496 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1504 * Test the glTexImage[123]D() parameters for errors.
1506 * \param ctx GL context.
1507 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1508 * \param target texture target given by the user.
1509 * \param level image level given by the user.
1510 * \param internalFormat internal format given by the user.
1511 * \param format pixel data format given by the user.
1512 * \param type pixel data type given by the user.
1513 * \param width image width given by the user.
1514 * \param height image height given by the user.
1515 * \param depth image depth given by the user.
1516 * \param border image border given by the user.
1518 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1520 * Verifies each of the parameters against the constants specified in
1521 * __struct gl_contextRec::Const and the supported extensions, and according
1522 * to the OpenGL specification.
1525 texture_error_check( struct gl_context
*ctx
,
1526 GLuint dimensions
, GLenum target
,
1527 GLint level
, GLint internalFormat
,
1528 GLenum format
, GLenum type
,
1529 GLint width
, GLint height
,
1530 GLint depth
, GLint border
)
1532 const GLenum proxyTarget
= get_proxy_target(target
);
1533 const GLboolean isProxy
= target
== proxyTarget
;
1534 GLboolean sizeOK
= GL_TRUE
;
1535 GLboolean colorFormat
;
1537 /* Even though there are no color-index textures, we still have to support
1538 * uploading color-index data and remapping it to RGB via the
1539 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1541 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1543 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1544 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1546 _mesa_error(ctx
, GL_INVALID_VALUE
,
1547 "glTexImage%dD(level=%d)", dimensions
, level
);
1553 if (border
< 0 || border
> 1 ||
1554 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1555 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1557 _mesa_error(ctx
, GL_INVALID_VALUE
,
1558 "glTexImage%dD(border=%d)", dimensions
, border
);
1563 if (width
< 0 || height
< 0 || depth
< 0) {
1565 _mesa_error(ctx
, GL_INVALID_VALUE
,
1566 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1571 /* Do this simple check before calling the TestProxyTexImage() function */
1572 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1573 sizeOK
= (width
== height
);
1577 * Use the proxy texture driver hook to see if the size/level/etc are
1580 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1581 internalFormat
, format
,
1582 type
, width
, height
,
1586 _mesa_error(ctx
, GL_INVALID_VALUE
,
1587 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1588 dimensions
, level
, width
, height
, depth
);
1593 /* Check internalFormat */
1594 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1596 _mesa_error(ctx
, GL_INVALID_VALUE
,
1597 "glTexImage%dD(internalFormat=%s)",
1598 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1603 /* Check incoming image format and type */
1604 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1605 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1606 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1607 * GL_EXT_texture_integer extension, some combinations should generate
1608 * GL_INVALID_ENUM instead (grr!).
1611 GLenum error
= _mesa_is_integer_format(format
)
1612 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1613 _mesa_error(ctx
, error
,
1614 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1615 dimensions
, format
, type
);
1620 /* make sure internal format and format basically agree */
1621 colorFormat
= _mesa_is_color_format(format
);
1622 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1623 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1624 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1625 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1626 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1628 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1629 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1630 dimensions
, internalFormat
, format
);
1634 /* additional checks for ycbcr textures */
1635 if (internalFormat
== GL_YCBCR_MESA
) {
1636 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1637 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1638 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1640 _mesa_snprintf(message
, sizeof(message
),
1641 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1642 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1643 return GL_TRUE
; /* error */
1645 if (target
!= GL_TEXTURE_2D
&&
1646 target
!= GL_PROXY_TEXTURE_2D
&&
1647 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1648 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1650 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1656 _mesa_snprintf(message
, sizeof(message
),
1657 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1658 dimensions
, border
);
1659 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1665 /* additional checks for depth textures */
1666 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1667 /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */
1668 if (target
!= GL_TEXTURE_1D
&&
1669 target
!= GL_PROXY_TEXTURE_1D
&&
1670 target
!= GL_TEXTURE_2D
&&
1671 target
!= GL_PROXY_TEXTURE_2D
&&
1672 target
!= GL_TEXTURE_1D_ARRAY
&&
1673 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1674 target
!= GL_TEXTURE_2D_ARRAY
&&
1675 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1676 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1677 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1679 _mesa_error(ctx
, GL_INVALID_ENUM
,
1680 "glTexImage(target/internalFormat)");
1685 /* additional checks for compressed textures */
1686 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1687 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1689 _mesa_error(ctx
, GL_INVALID_ENUM
,
1690 "glTexImage%dD(target)", dimensions
);
1695 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1696 "glTexImage%dD(border!=0)", dimensions
);
1702 /* additional checks for integer textures */
1703 if (ctx
->Extensions
.EXT_texture_integer
&&
1704 (_mesa_is_integer_format(format
) !=
1705 _mesa_is_integer_format(internalFormat
))) {
1707 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1708 "glTexImage%dD(integer/non-integer format mismatch)",
1714 /* if we get here, the parameters are OK */
1720 * Test glTexSubImage[123]D() parameters for errors.
1722 * \param ctx GL context.
1723 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1724 * \param target texture target given by the user.
1725 * \param level image level given by the user.
1726 * \param xoffset sub-image x offset given by the user.
1727 * \param yoffset sub-image y offset given by the user.
1728 * \param zoffset sub-image z offset given by the user.
1729 * \param format pixel data format given by the user.
1730 * \param type pixel data type given by the user.
1731 * \param width image width given by the user.
1732 * \param height image height given by the user.
1733 * \param depth image depth given by the user.
1735 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1737 * Verifies each of the parameters against the constants specified in
1738 * __struct gl_contextRec::Const and the supported extensions, and according
1739 * to the OpenGL specification.
1742 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1743 GLenum target
, GLint level
,
1744 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1745 GLint width
, GLint height
, GLint depth
,
1746 GLenum format
, GLenum type
)
1748 /* Basic level check */
1749 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1750 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1754 /* Check for negative sizes */
1756 _mesa_error(ctx
, GL_INVALID_VALUE
,
1757 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1760 if (height
< 0 && dimensions
> 1) {
1761 _mesa_error(ctx
, GL_INVALID_VALUE
,
1762 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1765 if (depth
< 0 && dimensions
> 2) {
1766 _mesa_error(ctx
, GL_INVALID_VALUE
,
1767 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1771 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1772 /* As with the glTexImage2D check above, the error code here
1773 * depends on texture integer.
1775 GLenum error
= _mesa_is_integer_format(format
)
1776 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1777 _mesa_error(ctx
, error
,
1778 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1779 dimensions
, format
, type
);
1788 * Do second part of glTexSubImage which depends on the destination texture.
1789 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1792 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1793 GLenum target
, GLint level
,
1794 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1795 GLint width
, GLint height
, GLint depth
,
1796 GLenum format
, GLenum type
,
1797 const struct gl_texture_image
*destTex
)
1800 /* undefined image level */
1801 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1805 if (xoffset
< -((GLint
)destTex
->Border
)) {
1806 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1810 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1811 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1815 if (dimensions
> 1) {
1816 if (yoffset
< -((GLint
)destTex
->Border
)) {
1817 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1821 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1822 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1827 if (dimensions
> 2) {
1828 if (zoffset
< -((GLint
)destTex
->Border
)) {
1829 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1832 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1833 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1838 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1841 /* do tests which depend on compression block size */
1842 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1844 /* offset must be multiple of block size */
1845 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1846 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1847 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1848 dimensions
, xoffset
, yoffset
);
1851 /* size must be multiple of bw by bh or equal to whole texture size */
1852 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1853 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1854 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1857 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1858 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1859 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1869 * Test glCopyTexImage[12]D() parameters for errors.
1871 * \param ctx GL context.
1872 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1873 * \param target texture target given by the user.
1874 * \param level image level given by the user.
1875 * \param internalFormat internal format given by the user.
1876 * \param width image width given by the user.
1877 * \param height image height given by the user.
1878 * \param border texture border.
1880 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1882 * Verifies each of the parameters against the constants specified in
1883 * __struct gl_contextRec::Const and the supported extensions, and according
1884 * to the OpenGL specification.
1887 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1888 GLenum target
, GLint level
, GLint internalFormat
,
1889 GLint width
, GLint height
, GLint border
)
1891 const GLenum proxyTarget
= get_proxy_target(target
);
1892 const GLenum type
= GL_FLOAT
;
1897 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1898 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1899 dimensions
, _mesa_lookup_enum_by_nr(target
));
1903 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1904 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1905 _mesa_error(ctx
, GL_INVALID_VALUE
,
1906 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1910 /* Check that the source buffer is complete */
1911 if (ctx
->ReadBuffer
->Name
) {
1912 if (ctx
->ReadBuffer
->_Status
== 0) {
1913 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1915 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1916 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1917 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1923 if (border
< 0 || border
> 1 ||
1924 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1925 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1929 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1931 _mesa_error(ctx
, GL_INVALID_VALUE
,
1932 "glCopyTexImage%dD(internalFormat)", dimensions
);
1936 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1937 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1938 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1942 /* Do size, level checking */
1943 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1944 ? (width
== height
) : 1;
1946 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1947 internalFormat
, format
,
1948 type
, width
, height
,
1952 if (dimensions
== 1) {
1953 _mesa_error(ctx
, GL_INVALID_VALUE
,
1954 "glCopyTexImage1D(width=%d)", width
);
1957 ASSERT(dimensions
== 2);
1958 _mesa_error(ctx
, GL_INVALID_VALUE
,
1959 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1964 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1965 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1966 _mesa_error(ctx
, GL_INVALID_ENUM
,
1967 "glCopyTexImage%dD(target)", dimensions
);
1971 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1972 "glCopyTexImage%dD(border!=0)", dimensions
);
1976 else if (_mesa_is_depth_format(internalFormat
)) {
1977 /* make sure we have depth/stencil buffers */
1978 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1979 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1980 "glCopyTexImage%dD(no depth)", dimensions
);
1984 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1985 /* make sure we have depth/stencil buffers */
1986 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1987 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1988 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
1993 /* if we get here, the parameters are OK */
1999 * Test glCopyTexSubImage[12]D() parameters for errors.
2000 * Note that this is the first part of error checking.
2001 * See also copytexsubimage_error_check2() below for the second part.
2003 * \param ctx GL context.
2004 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2005 * \param target texture target given by the user.
2006 * \param level image level given by the user.
2008 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2011 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2012 GLenum target
, GLint level
)
2014 /* Check that the source buffer is complete */
2015 if (ctx
->ReadBuffer
->Name
) {
2016 if (ctx
->ReadBuffer
->_Status
== 0) {
2017 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2019 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2020 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2021 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2026 /* check target (proxies not allowed) */
2027 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2028 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2029 dimensions
, _mesa_lookup_enum_by_nr(target
));
2034 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2035 _mesa_error(ctx
, GL_INVALID_VALUE
,
2036 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2045 * Second part of error checking for glCopyTexSubImage[12]D().
2046 * \param xoffset sub-image x offset given by the user.
2047 * \param yoffset sub-image y offset given by the user.
2048 * \param zoffset sub-image z offset given by the user.
2049 * \param width image width given by the user.
2050 * \param height image height given by the user.
2053 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2054 GLenum target
, GLint level
,
2055 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2056 GLsizei width
, GLsizei height
,
2057 const struct gl_texture_image
*teximage
)
2059 /* check that dest tex image exists */
2061 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2062 "glCopyTexSubImage%dD(undefined texture level: %d)",
2069 _mesa_error(ctx
, GL_INVALID_VALUE
,
2070 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2073 if (dimensions
> 1 && height
< 0) {
2074 _mesa_error(ctx
, GL_INVALID_VALUE
,
2075 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2079 /* check x/y offsets */
2080 if (xoffset
< -((GLint
)teximage
->Border
)) {
2081 _mesa_error(ctx
, GL_INVALID_VALUE
,
2082 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2085 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2086 _mesa_error(ctx
, GL_INVALID_VALUE
,
2087 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2090 if (dimensions
> 1) {
2091 if (yoffset
< -((GLint
)teximage
->Border
)) {
2092 _mesa_error(ctx
, GL_INVALID_VALUE
,
2093 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2096 /* NOTE: we're adding the border here, not subtracting! */
2097 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2098 _mesa_error(ctx
, GL_INVALID_VALUE
,
2099 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2104 /* check z offset */
2105 if (dimensions
> 2) {
2106 if (zoffset
< -((GLint
)teximage
->Border
)) {
2107 _mesa_error(ctx
, GL_INVALID_VALUE
,
2108 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2111 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2112 _mesa_error(ctx
, GL_INVALID_VALUE
,
2113 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2118 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2119 /* offset must be multiple of 4 */
2120 if ((xoffset
& 3) || (yoffset
& 3)) {
2121 _mesa_error(ctx
, GL_INVALID_VALUE
,
2122 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2125 /* size must be multiple of 4 */
2126 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2127 _mesa_error(ctx
, GL_INVALID_VALUE
,
2128 "glCopyTexSubImage%dD(width)", dimensions
);
2131 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2132 _mesa_error(ctx
, GL_INVALID_VALUE
,
2133 "glCopyTexSubImage%dD(height)", dimensions
);
2138 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2139 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2143 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2144 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2145 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2146 dimensions
, teximage
->_BaseFormat
);
2150 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2151 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2152 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2153 "glCopyTexSubImage%dD(no depth buffer)",
2158 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2159 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2160 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2161 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2167 /* If copying into an integer texture, the source buffer must also be
2170 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2171 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2172 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2173 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2174 "glCopyTexSubImage%dD(source buffer is not integer format)",
2180 /* if we get here, the parameters are OK */
2185 /** Callback info for walking over FBO hash table */
2188 struct gl_context
*ctx
;
2189 struct gl_texture_object
*texObj
;
2195 * Check render to texture callback. Called from _mesa_HashWalk().
2198 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2200 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2201 const struct cb_info
*info
= (struct cb_info
*) userData
;
2202 struct gl_context
*ctx
= info
->ctx
;
2203 const struct gl_texture_object
*texObj
= info
->texObj
;
2204 const GLuint level
= info
->level
, face
= info
->face
;
2206 /* If this is a user-created FBO */
2209 /* check if any of the FBO's attachments point to 'texObj' */
2210 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2211 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2212 if (att
->Type
== GL_TEXTURE
&&
2213 att
->Texture
== texObj
&&
2214 att
->TextureLevel
== level
&&
2215 att
->CubeMapFace
== face
) {
2216 ASSERT(_mesa_get_attachment_teximage(att
));
2217 /* Tell driver about the new renderbuffer texture */
2218 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2219 /* Mark fb status as indeterminate to force re-validation */
2228 * When a texture image is specified we have to check if it's bound to
2229 * any framebuffer objects (render to texture) in order to detect changes
2230 * in size or format since that effects FBO completeness.
2231 * Any FBOs rendering into the texture must be re-validated.
2234 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2235 GLuint face
, GLuint level
)
2237 /* Only check this texture if it's been marked as RenderToTexture */
2238 if (texObj
->_RenderToTexture
) {
2239 struct cb_info info
;
2241 info
.texObj
= texObj
;
2244 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2250 * If the texture object's GenerateMipmap flag is set and we've
2251 * changed the texture base level image, regenerate the rest of the
2252 * mipmap levels now.
2255 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2256 struct gl_texture_object
*texObj
, GLint level
)
2258 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2259 if (texObj
->GenerateMipmap
&&
2260 level
== texObj
->BaseLevel
&&
2261 level
< texObj
->MaxLevel
) {
2262 ASSERT(ctx
->Driver
.GenerateMipmap
);
2263 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2268 /** Debug helper: override the user-requested internal format */
2270 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2273 if (internalFormat
== GL_RGBA16F_ARB
||
2274 internalFormat
== GL_RGBA32F_ARB
) {
2275 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2278 else if (internalFormat
== GL_RGB16F_ARB
||
2279 internalFormat
== GL_RGB32F_ARB
) {
2280 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2283 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2284 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2285 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2286 return GL_LUMINANCE_ALPHA
;
2288 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2289 internalFormat
== GL_LUMINANCE32F_ARB
) {
2290 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2291 return GL_LUMINANCE
;
2293 else if (internalFormat
== GL_ALPHA16F_ARB
||
2294 internalFormat
== GL_ALPHA32F_ARB
) {
2295 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2299 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2300 internalFormat = GL_RGBA;
2304 return internalFormat
;
2307 return internalFormat
;
2313 * Choose the actual hardware format for a texture image.
2314 * Try to use the same format as the previous image level when possible.
2315 * Otherwise, ask the driver for the best format.
2316 * It's important to try to choose a consistant format for all levels
2317 * for efficient texture memory layout/allocation. In particular, this
2318 * comes up during automatic mipmap generation.
2321 _mesa_choose_texture_format(struct gl_context
*ctx
,
2322 struct gl_texture_object
*texObj
,
2323 GLenum target
, GLint level
,
2324 GLenum internalFormat
, GLenum format
, GLenum type
)
2328 /* see if we've already chosen a format for the previous level */
2330 struct gl_texture_image
*prevImage
=
2331 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2332 /* See if the prev level is defined and has an internal format which
2333 * matches the new internal format.
2336 prevImage
->Width
> 0 &&
2337 prevImage
->InternalFormat
== internalFormat
) {
2338 /* use the same format */
2339 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2340 return prevImage
->TexFormat
;
2344 /* choose format from scratch */
2345 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2346 ASSERT(f
!= MESA_FORMAT_NONE
);
2352 * Common code to implement all the glTexImage1D/2D/3D functions.
2355 teximage(struct gl_context
*ctx
, GLuint dims
,
2356 GLenum target
, GLint level
, GLint internalFormat
,
2357 GLsizei width
, GLsizei height
, GLsizei depth
,
2358 GLint border
, GLenum format
, GLenum type
,
2359 const GLvoid
*pixels
)
2363 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2365 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2366 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2368 _mesa_lookup_enum_by_nr(target
), level
,
2369 _mesa_lookup_enum_by_nr(internalFormat
),
2370 width
, height
, depth
, border
,
2371 _mesa_lookup_enum_by_nr(format
),
2372 _mesa_lookup_enum_by_nr(type
), pixels
);
2374 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2376 /* target error checking */
2377 if (!legal_teximage_target(ctx
, dims
, target
)) {
2378 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2379 dims
, _mesa_lookup_enum_by_nr(target
));
2383 /* general error checking */
2384 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2385 format
, type
, width
, height
, depth
, border
);
2387 if (_mesa_is_proxy_texture(target
)) {
2388 /* Proxy texture: just clear or set state depending on error checking */
2389 struct gl_texture_image
*texImage
=
2390 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2393 /* when error, clear all proxy texture image parameters */
2395 clear_teximage_fields(texImage
);
2398 /* no error, set the tex image parameters */
2399 struct gl_texture_object
*texObj
=
2400 _mesa_get_current_tex_object(ctx
, target
);
2401 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2406 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2407 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2408 depth
, border
, internalFormat
,
2411 else if (texImage
) {
2412 clear_teximage_fields(texImage
);
2417 /* non-proxy target */
2418 const GLuint face
= _mesa_tex_target_to_face(target
);
2419 struct gl_texture_object
*texObj
;
2420 struct gl_texture_image
*texImage
;
2423 return; /* error was recorded */
2426 if (ctx
->NewState
& _NEW_PIXEL
)
2427 _mesa_update_state(ctx
);
2429 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2431 _mesa_lock_texture(ctx
, texObj
);
2433 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2436 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2439 gl_format texFormat
;
2441 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2443 ASSERT(texImage
->Data
== NULL
);
2444 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2445 internalFormat
, format
,
2448 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2449 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2450 width
, height
, depth
,
2451 border
, internalFormat
, texFormat
);
2453 /* Give the texture to the driver. <pixels> may be null. */
2454 ASSERT(ctx
->Driver
.TexImage3D
);
2457 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2458 width
, border
, format
,
2459 type
, pixels
, &ctx
->Unpack
, texObj
,
2463 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2464 width
, height
, border
, format
,
2465 type
, pixels
, &ctx
->Unpack
, texObj
,
2469 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2470 width
, height
, depth
, border
, format
,
2471 type
, pixels
, &ctx
->Unpack
, texObj
,
2475 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2478 check_gen_mipmap(ctx
, target
, texObj
, level
);
2480 update_fbo_texture(ctx
, texObj
, face
, level
);
2483 texObj
->_Complete
= GL_FALSE
;
2484 ctx
->NewState
|= _NEW_TEXTURE
;
2487 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2491 _mesa_unlock_texture(ctx
, texObj
);
2497 * Called from the API. Note that width includes the border.
2500 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2501 GLsizei width
, GLint border
, GLenum format
,
2502 GLenum type
, const GLvoid
*pixels
)
2504 GET_CURRENT_CONTEXT(ctx
);
2505 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2506 border
, format
, type
, pixels
);
2511 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2512 GLsizei width
, GLsizei height
, GLint border
,
2513 GLenum format
, GLenum type
,
2514 const GLvoid
*pixels
)
2516 GET_CURRENT_CONTEXT(ctx
);
2517 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2518 border
, format
, type
, pixels
);
2523 * Called by the API or display list executor.
2524 * Note that width and height include the border.
2527 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2528 GLsizei width
, GLsizei height
, GLsizei depth
,
2529 GLint border
, GLenum format
, GLenum type
,
2530 const GLvoid
*pixels
)
2532 GET_CURRENT_CONTEXT(ctx
);
2533 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2534 border
, format
, type
, pixels
);
2539 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2540 GLsizei width
, GLsizei height
, GLsizei depth
,
2541 GLint border
, GLenum format
, GLenum type
,
2542 const GLvoid
*pixels
)
2544 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2545 depth
, border
, format
, type
, pixels
);
2549 #if FEATURE_OES_EGL_image
2551 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2553 struct gl_texture_object
*texObj
;
2554 struct gl_texture_image
*texImage
;
2555 GET_CURRENT_CONTEXT(ctx
);
2556 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2558 if (!ctx
->Extensions
.OES_EGL_image
) {
2559 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2560 "glEGLImageTargetTexture2DOES(unsupported)");
2564 if (target
!= GL_TEXTURE_2D
) {
2565 _mesa_error(ctx
, GL_INVALID_ENUM
,
2566 "glEGLImageTargetTexture2D(target=%d)", target
);
2570 if (ctx
->NewState
& _NEW_PIXEL
)
2571 _mesa_update_state(ctx
);
2573 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2574 _mesa_lock_texture(ctx
, texObj
);
2576 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2578 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2580 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2582 ASSERT(texImage
->Data
== NULL
);
2583 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2584 texObj
, texImage
, image
);
2587 texObj
->_Complete
= GL_FALSE
;
2588 ctx
->NewState
|= _NEW_TEXTURE
;
2590 _mesa_unlock_texture(ctx
, texObj
);
2598 * Implement all the glTexSubImage1/2/3D() functions.
2601 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2602 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2603 GLsizei width
, GLsizei height
, GLsizei depth
,
2604 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2606 struct gl_texture_object
*texObj
;
2607 struct gl_texture_image
*texImage
;
2609 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2611 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2612 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2614 _mesa_lookup_enum_by_nr(target
), level
,
2615 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2616 _mesa_lookup_enum_by_nr(format
),
2617 _mesa_lookup_enum_by_nr(type
), pixels
);
2619 /* check target (proxies not allowed) */
2620 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2621 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2622 dims
, _mesa_lookup_enum_by_nr(target
));
2626 if (ctx
->NewState
& _NEW_PIXEL
)
2627 _mesa_update_state(ctx
);
2629 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2630 width
, height
, depth
, format
, type
)) {
2631 return; /* error was detected */
2634 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2636 _mesa_lock_texture(ctx
, texObj
);
2638 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2640 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2641 xoffset
, yoffset
, zoffset
,
2642 width
, height
, depth
,
2643 format
, type
, texImage
)) {
2644 /* error was recorded */
2646 else if (width
> 0 && height
> 0 && depth
> 0) {
2647 /* If we have a border, offset=-1 is legal. Bias by border width. */
2650 zoffset
+= texImage
->Border
;
2653 yoffset
+= texImage
->Border
;
2656 xoffset
+= texImage
->Border
;
2661 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2663 format
, type
, pixels
,
2664 &ctx
->Unpack
, texObj
, texImage
);
2667 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2668 xoffset
, yoffset
, width
, height
,
2669 format
, type
, pixels
,
2670 &ctx
->Unpack
, texObj
, texImage
);
2673 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2674 xoffset
, yoffset
, zoffset
,
2675 width
, height
, depth
,
2676 format
, type
, pixels
,
2677 &ctx
->Unpack
, texObj
, texImage
);
2680 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2683 check_gen_mipmap(ctx
, target
, texObj
, level
);
2685 ctx
->NewState
|= _NEW_TEXTURE
;
2688 _mesa_unlock_texture(ctx
, texObj
);
2693 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2694 GLint xoffset
, GLsizei width
,
2695 GLenum format
, GLenum type
,
2696 const GLvoid
*pixels
)
2698 GET_CURRENT_CONTEXT(ctx
);
2699 texsubimage(ctx
, 1, target
, level
,
2702 format
, type
, pixels
);
2707 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2708 GLint xoffset
, GLint yoffset
,
2709 GLsizei width
, GLsizei height
,
2710 GLenum format
, GLenum type
,
2711 const GLvoid
*pixels
)
2713 GET_CURRENT_CONTEXT(ctx
);
2714 texsubimage(ctx
, 2, target
, level
,
2715 xoffset
, yoffset
, 0,
2717 format
, type
, pixels
);
2723 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2724 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2725 GLsizei width
, GLsizei height
, GLsizei depth
,
2726 GLenum format
, GLenum type
,
2727 const GLvoid
*pixels
)
2729 GET_CURRENT_CONTEXT(ctx
);
2730 texsubimage(ctx
, 3, target
, level
,
2731 xoffset
, yoffset
, zoffset
,
2732 width
, height
, depth
,
2733 format
, type
, pixels
);
2739 * Implement the glCopyTexImage1/2D() functions.
2742 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2743 GLenum target
, GLint level
, GLenum internalFormat
,
2744 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2746 struct gl_texture_object
*texObj
;
2747 struct gl_texture_image
*texImage
;
2748 const GLuint face
= _mesa_tex_target_to_face(target
);
2750 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2752 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2753 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2755 _mesa_lookup_enum_by_nr(target
), level
,
2756 _mesa_lookup_enum_by_nr(internalFormat
),
2757 x
, y
, width
, height
, border
);
2759 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2760 _mesa_update_state(ctx
);
2762 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2763 width
, height
, border
))
2766 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2768 _mesa_lock_texture(ctx
, texObj
);
2770 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2773 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2776 /* choose actual hw format */
2777 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2782 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2783 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2785 /* Free old texture image */
2786 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2788 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2789 border
, internalFormat
, texFormat
);
2791 /* Allocate texture memory (no pixel data yet) */
2793 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2794 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2795 &ctx
->Unpack
, texObj
, texImage
);
2798 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2799 width
, height
, border
, GL_NONE
, GL_NONE
,
2800 NULL
, &ctx
->Unpack
, texObj
, texImage
);
2803 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2806 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
, dstX
,
2810 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, dstX
, dstY
,
2811 srcX
, srcY
, width
, height
);
2814 check_gen_mipmap(ctx
, target
, texObj
, level
);
2816 update_fbo_texture(ctx
, texObj
, face
, level
);
2819 texObj
->_Complete
= GL_FALSE
;
2820 ctx
->NewState
|= _NEW_TEXTURE
;
2823 /* probably too large of image */
2824 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2828 _mesa_unlock_texture(ctx
, texObj
);
2834 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2835 GLenum internalFormat
,
2837 GLsizei width
, GLint border
)
2839 GET_CURRENT_CONTEXT(ctx
);
2840 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2846 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2847 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2850 GET_CURRENT_CONTEXT(ctx
);
2851 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2852 x
, y
, width
, height
, border
);
2858 * Implementation for glCopyTexSubImage1/2/3D() functions.
2861 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2862 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2863 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2865 struct gl_texture_object
*texObj
;
2866 struct gl_texture_image
*texImage
;
2868 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2870 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2871 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2873 _mesa_lookup_enum_by_nr(target
),
2874 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2876 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2877 _mesa_update_state(ctx
);
2879 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2882 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2884 _mesa_lock_texture(ctx
, texObj
);
2886 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2888 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2889 zoffset
, width
, height
, texImage
)) {
2890 /* error was recored */
2893 /* If we have a border, offset=-1 is legal. Bias by border width. */
2896 zoffset
+= texImage
->Border
;
2899 yoffset
+= texImage
->Border
;
2902 xoffset
+= texImage
->Border
;
2905 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2909 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2910 xoffset
, x
, y
, width
);
2913 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2915 x
, y
, width
, height
);
2918 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2919 xoffset
, yoffset
, zoffset
,
2920 x
, y
, width
, height
);
2923 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
2926 check_gen_mipmap(ctx
, target
, texObj
, level
);
2928 ctx
->NewState
|= _NEW_TEXTURE
;
2932 _mesa_unlock_texture(ctx
, texObj
);
2937 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2938 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2940 GET_CURRENT_CONTEXT(ctx
);
2941 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
2947 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2948 GLint xoffset
, GLint yoffset
,
2949 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2951 GET_CURRENT_CONTEXT(ctx
);
2952 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
2959 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2960 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2961 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2963 GET_CURRENT_CONTEXT(ctx
);
2964 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2965 x
, y
, width
, height
);
2971 /**********************************************************************/
2972 /****** Compressed Textures ******/
2973 /**********************************************************************/
2977 * Return expected size of a compressed texture.
2980 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2983 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2984 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2989 * Return compressed texture block size, in pixels.
2992 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
2994 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2995 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3000 * Error checking for glCompressedTexImage[123]D().
3001 * \param reason returns reason for error, if any
3002 * \return error code or GL_NO_ERROR.
3005 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3006 GLenum target
, GLint level
,
3007 GLenum internalFormat
, GLsizei width
,
3008 GLsizei height
, GLsizei depth
, GLint border
,
3009 GLsizei imageSize
, char **reason
)
3011 const GLenum proxyTarget
= get_proxy_target(target
);
3012 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3014 GLenum choose_format
;
3016 GLenum proxy_format
;
3018 *reason
= ""; /* no error */
3020 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3022 return GL_INVALID_ENUM
;
3025 /* This will detect any invalid internalFormat value */
3026 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3027 *reason
= "internalFormat";
3028 return GL_INVALID_ENUM
;
3031 switch (internalFormat
) {
3033 case GL_PALETTE4_RGB8_OES
:
3034 case GL_PALETTE4_RGBA8_OES
:
3035 case GL_PALETTE4_R5_G6_B5_OES
:
3036 case GL_PALETTE4_RGBA4_OES
:
3037 case GL_PALETTE4_RGB5_A1_OES
:
3038 case GL_PALETTE8_RGB8_OES
:
3039 case GL_PALETTE8_RGBA8_OES
:
3040 case GL_PALETTE8_R5_G6_B5_OES
:
3041 case GL_PALETTE8_RGBA4_OES
:
3042 case GL_PALETTE8_RGB5_A1_OES
:
3043 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3045 proxy_format
= choose_format
;
3048 if (level
> 0 || level
< -maxLevels
) {
3050 return GL_INVALID_VALUE
;
3053 if (dimensions
!= 2) {
3054 *reason
= "compressed paletted textures must be 2D";
3055 return GL_INVALID_OPERATION
;
3058 /* Figure out the expected texture size (in bytes). This will be
3059 * checked against the actual size later.
3061 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3064 /* This is for the benefit of the TestProxyTexImage below. It expects
3065 * level to be non-negative. OES_compressed_paletted_texture uses a
3066 * weird mechanism where the level specified to glCompressedTexImage2D
3067 * is -(n-1) number of levels in the texture, and the data specifies the
3068 * complete mipmap stack. This is done to ensure the palette is the
3069 * same for all levels.
3076 choose_format
= GL_NONE
;
3077 choose_type
= GL_NONE
;
3078 proxy_format
= internalFormat
;
3081 if (level
< 0 || level
>= maxLevels
) {
3083 return GL_INVALID_VALUE
;
3086 /* Figure out the expected texture size (in bytes). This will be
3087 * checked against the actual size later.
3089 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3093 /* This should really never fail */
3094 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3095 *reason
= "internalFormat";
3096 return GL_INVALID_ENUM
;
3099 /* No compressed formats support borders at this time */
3101 *reason
= "border != 0";
3102 return GL_INVALID_VALUE
;
3105 /* For cube map, width must equal height */
3106 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3107 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
) {
3108 *reason
= "width != height";
3109 return GL_INVALID_VALUE
;
3112 /* check image size against compression block size */
3114 gl_format texFormat
=
3115 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3116 choose_format
, choose_type
);
3119 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3120 if ((width
> bw
&& width
% bw
> 0) ||
3121 (height
> bh
&& height
% bh
> 0)) {
3123 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3124 * generated [...] if any parameter combinations are not
3125 * supported by the specific compressed internal format.
3127 *reason
= "invalid width or height for compression format";
3128 return GL_INVALID_OPERATION
;
3132 /* check image sizes */
3133 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3134 proxy_format
, choose_format
,
3136 width
, height
, depth
, border
)) {
3137 /* See error comment above */
3138 *reason
= "invalid width, height or format";
3139 return GL_INVALID_OPERATION
;
3142 /* check image size in bytes */
3143 if (expectedSize
!= imageSize
) {
3144 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3145 * if <imageSize> is not consistent with the format, dimensions, and
3146 * contents of the specified image.
3148 *reason
= "imageSize inconsistant with width/height/format";
3149 return GL_INVALID_VALUE
;
3157 * Error checking for glCompressedTexSubImage[123]D().
3158 * \warning There are some bad assumptions here about the size of compressed
3159 * texture tiles (multiple of 4) used to test the validity of the
3160 * offset and size parameters.
3161 * \return error code or GL_NO_ERROR.
3164 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3165 GLenum target
, GLint level
,
3166 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3167 GLsizei width
, GLsizei height
, GLsizei depth
,
3168 GLenum format
, GLsizei imageSize
)
3170 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3174 if (dimensions
== 1) {
3175 /* 1D compressed textures not allowed */
3176 return GL_INVALID_ENUM
;
3178 else if (dimensions
== 2) {
3179 if (target
== GL_PROXY_TEXTURE_2D
) {
3180 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3182 else if (target
== GL_TEXTURE_2D
) {
3183 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3185 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3186 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3187 return GL_INVALID_ENUM
; /*target*/
3188 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3190 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3191 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3192 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3193 return GL_INVALID_ENUM
; /*target*/
3194 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3197 return GL_INVALID_ENUM
; /*target*/
3200 else if (dimensions
== 3) {
3201 /* 3D compressed textures not allowed */
3202 return GL_INVALID_ENUM
;
3205 maxTextureSize
= 1 << (maxLevels
- 1);
3207 /* this will catch any invalid compressed format token */
3208 if (!_mesa_is_compressed_format(ctx
, format
))
3209 return GL_INVALID_ENUM
;
3211 if (width
< 1 || width
> maxTextureSize
)
3212 return GL_INVALID_VALUE
;
3214 if ((height
< 1 || height
> maxTextureSize
)
3216 return GL_INVALID_VALUE
;
3218 if (level
< 0 || level
>= maxLevels
)
3219 return GL_INVALID_VALUE
;
3222 * do checks which depend on compression block size
3224 get_compressed_block_size(format
, &bw
, &bh
);
3226 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3227 return GL_INVALID_VALUE
;
3229 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3230 return GL_INVALID_VALUE
;
3232 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3233 return GL_INVALID_VALUE
;
3235 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3236 if (expectedSize
!= imageSize
)
3237 return GL_INVALID_VALUE
;
3244 * Do second part of glCompressedTexSubImage error checking.
3245 * \return GL_TRUE if error found, GL_FALSE otherwise.
3248 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3249 GLsizei width
, GLsizei height
,
3250 GLsizei depth
, GLenum format
,
3251 struct gl_texture_image
*texImage
)
3254 if ((GLint
) format
!= texImage
->InternalFormat
) {
3255 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3256 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3260 if (((width
== 1 || width
== 2) &&
3261 width
!= (GLsizei
) texImage
->Width
) ||
3262 (width
> (GLsizei
) texImage
->Width
)) {
3263 _mesa_error(ctx
, GL_INVALID_VALUE
,
3264 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3269 if (((height
== 1 || height
== 2) &&
3270 height
!= (GLsizei
) texImage
->Height
) ||
3271 (height
> (GLsizei
) texImage
->Height
)) {
3272 _mesa_error(ctx
, GL_INVALID_VALUE
,
3273 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3279 if (((depth
== 1 || depth
== 2) &&
3280 depth
!= (GLsizei
) texImage
->Depth
) ||
3281 (depth
> (GLsizei
) texImage
->Depth
)) {
3282 _mesa_error(ctx
, GL_INVALID_VALUE
,
3283 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3293 * Implementation of the glCompressedTexImage1/2/3D() functions.
3296 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3297 GLenum target
, GLint level
,
3298 GLenum internalFormat
, GLsizei width
,
3299 GLsizei height
, GLsizei depth
, GLint border
,
3300 GLsizei imageSize
, const GLvoid
*data
)
3305 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3307 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3309 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3311 _mesa_lookup_enum_by_nr(target
), level
,
3312 _mesa_lookup_enum_by_nr(internalFormat
),
3313 width
, height
, depth
, border
, imageSize
, data
);
3316 if (!legal_teximage_target(ctx
, dims
, target
)) {
3317 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3318 dims
, _mesa_lookup_enum_by_nr(target
));
3322 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3323 internalFormat
, width
, height
, depth
,
3324 border
, imageSize
, &reason
);
3327 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3332 /* XXX this is kind of a hack */
3334 switch (internalFormat
) {
3335 case GL_PALETTE4_RGB8_OES
:
3336 case GL_PALETTE4_RGBA8_OES
:
3337 case GL_PALETTE4_R5_G6_B5_OES
:
3338 case GL_PALETTE4_RGBA4_OES
:
3339 case GL_PALETTE4_RGB5_A1_OES
:
3340 case GL_PALETTE8_RGB8_OES
:
3341 case GL_PALETTE8_RGBA8_OES
:
3342 case GL_PALETTE8_R5_G6_B5_OES
:
3343 case GL_PALETTE8_RGBA4_OES
:
3344 case GL_PALETTE8_RGB5_A1_OES
:
3345 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3346 width
, height
, imageSize
, data
);
3352 if (_mesa_is_proxy_texture(target
)) {
3353 /* Proxy texture: just check for errors and update proxy state */
3354 struct gl_texture_image
*texImage
;
3357 struct gl_texture_object
*texObj
=
3358 _mesa_get_current_tex_object(ctx
, target
);
3359 gl_format texFormat
=
3360 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3361 internalFormat
, GL_NONE
, GL_NONE
);
3362 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3363 error
= GL_OUT_OF_MEMORY
;
3367 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3370 /* if error, clear all proxy texture image parameters */
3371 clear_teximage_fields(texImage
);
3374 /* no error: store the teximage parameters */
3375 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3376 depth
, border
, internalFormat
,
3382 /* non-proxy target */
3383 struct gl_texture_object
*texObj
;
3384 struct gl_texture_image
*texImage
;
3387 _mesa_error(ctx
, error
, "glCompressedTexImage%uD", dims
);
3391 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3393 _mesa_lock_texture(ctx
, texObj
);
3395 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3397 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3398 "glCompressedTexImage%uD", dims
);
3401 gl_format texFormat
;
3403 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3404 ASSERT(texImage
->Data
== NULL
);
3406 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3407 internalFormat
, GL_NONE
,
3410 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3411 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3412 width
, height
, depth
,
3413 border
, internalFormat
, texFormat
);
3417 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3418 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3421 border
, imageSize
, data
,
3425 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3426 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3429 border
, imageSize
, data
,
3433 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3434 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3436 width
, height
, depth
,
3437 border
, imageSize
, data
,
3441 _mesa_problem(ctx
, "bad dims in compressedteximage");
3444 check_gen_mipmap(ctx
, target
, texObj
, level
);
3447 texObj
->_Complete
= GL_FALSE
;
3448 ctx
->NewState
|= _NEW_TEXTURE
;
3451 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3452 "glCompressedTexImage%uD", dims
);
3456 _mesa_unlock_texture(ctx
, texObj
);
3462 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3463 GLenum internalFormat
, GLsizei width
,
3464 GLint border
, GLsizei imageSize
,
3467 GET_CURRENT_CONTEXT(ctx
);
3468 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3469 width
, 1, 1, border
, imageSize
, data
);
3474 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3475 GLenum internalFormat
, GLsizei width
,
3476 GLsizei height
, GLint border
, GLsizei imageSize
,
3479 GET_CURRENT_CONTEXT(ctx
);
3480 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3481 width
, height
, 1, border
, imageSize
, data
);
3486 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3487 GLenum internalFormat
, GLsizei width
,
3488 GLsizei height
, GLsizei depth
, GLint border
,
3489 GLsizei imageSize
, const GLvoid
*data
)
3491 GET_CURRENT_CONTEXT(ctx
);
3492 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3493 width
, height
, depth
, border
, imageSize
, data
);
3498 * Common helper for glCompressedTexSubImage1/2/3D().
3501 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3502 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3503 GLsizei width
, GLsizei height
, GLsizei depth
,
3504 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3506 struct gl_texture_object
*texObj
;
3507 struct gl_texture_image
*texImage
;
3509 GET_CURRENT_CONTEXT(ctx
);
3510 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3512 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3513 xoffset
, 0, 0, /* pos */
3514 width
, height
, depth
, /* size */
3517 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3521 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3523 _mesa_lock_texture(ctx
, texObj
);
3525 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3528 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3529 format
, texImage
)) {
3530 /* error was recorded */
3532 else if (width
> 0 && height
> 0 && depth
> 0) {
3535 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3536 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3538 format
, imageSize
, data
,
3543 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3544 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3547 format
, imageSize
, data
,
3552 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3553 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3554 xoffset
, yoffset
, zoffset
,
3555 width
, height
, depth
,
3556 format
, imageSize
, data
,
3564 check_gen_mipmap(ctx
, target
, texObj
, level
);
3566 ctx
->NewState
|= _NEW_TEXTURE
;
3569 _mesa_unlock_texture(ctx
, texObj
);
3574 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3575 GLsizei width
, GLenum format
,
3576 GLsizei imageSize
, const GLvoid
*data
)
3578 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3579 format
, imageSize
, data
);
3584 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3585 GLint yoffset
, GLsizei width
, GLsizei height
,
3586 GLenum format
, GLsizei imageSize
,
3589 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3590 width
, height
, 1, format
, imageSize
, data
);
3595 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3596 GLint yoffset
, GLint zoffset
, GLsizei width
,
3597 GLsizei height
, GLsizei depth
, GLenum format
,
3598 GLsizei imageSize
, const GLvoid
*data
)
3600 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3601 width
, height
, depth
, format
, imageSize
, data
);
3606 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3607 * return the basic data type and number of components for the format.
3608 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3611 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3612 GLenum
*datatype
, GLuint
*components
)
3614 switch (internalFormat
) {
3616 *datatype
= GL_UNSIGNED_BYTE
;
3620 *datatype
= GL_UNSIGNED_SHORT
;
3623 case GL_ALPHA16F_ARB
:
3624 *datatype
= GL_HALF_FLOAT
;
3627 case GL_ALPHA32F_ARB
:
3628 *datatype
= GL_FLOAT
;
3631 case GL_ALPHA8I_EXT
:
3632 *datatype
= GL_BYTE
;
3635 case GL_ALPHA16I_EXT
:
3636 *datatype
= GL_SHORT
;
3639 case GL_ALPHA32I_EXT
:
3643 case GL_ALPHA8UI_EXT
:
3644 *datatype
= GL_UNSIGNED_BYTE
;
3647 case GL_ALPHA16UI_EXT
:
3648 *datatype
= GL_UNSIGNED_SHORT
;
3651 case GL_ALPHA32UI_EXT
:
3652 *datatype
= GL_UNSIGNED_INT
;
3656 *datatype
= GL_UNSIGNED_BYTE
;
3659 case GL_LUMINANCE16
:
3660 *datatype
= GL_UNSIGNED_SHORT
;
3663 case GL_LUMINANCE16F_ARB
:
3664 *datatype
= GL_HALF_FLOAT
;
3667 case GL_LUMINANCE32F_ARB
:
3668 *datatype
= GL_FLOAT
;
3671 case GL_LUMINANCE8I_EXT
:
3672 *datatype
= GL_BYTE
;
3675 case GL_LUMINANCE16I_EXT
:
3676 *datatype
= GL_SHORT
;
3679 case GL_LUMINANCE32I_EXT
:
3683 case GL_LUMINANCE8UI_EXT
:
3684 *datatype
= GL_UNSIGNED_BYTE
;
3687 case GL_LUMINANCE16UI_EXT
:
3688 *datatype
= GL_UNSIGNED_SHORT
;
3691 case GL_LUMINANCE32UI_EXT
:
3692 *datatype
= GL_UNSIGNED_INT
;
3695 case GL_LUMINANCE8_ALPHA8
:
3696 *datatype
= GL_UNSIGNED_BYTE
;
3699 case GL_LUMINANCE16_ALPHA16
:
3700 *datatype
= GL_UNSIGNED_SHORT
;
3703 case GL_LUMINANCE_ALPHA16F_ARB
:
3704 *datatype
= GL_HALF_FLOAT
;
3707 case GL_LUMINANCE_ALPHA32F_ARB
:
3708 *datatype
= GL_FLOAT
;
3711 case GL_LUMINANCE_ALPHA8I_EXT
:
3712 *datatype
= GL_BYTE
;
3715 case GL_LUMINANCE_ALPHA16I_EXT
:
3716 *datatype
= GL_SHORT
;
3719 case GL_LUMINANCE_ALPHA32I_EXT
:
3723 case GL_LUMINANCE_ALPHA8UI_EXT
:
3724 *datatype
= GL_UNSIGNED_BYTE
;
3727 case GL_LUMINANCE_ALPHA16UI_EXT
:
3728 *datatype
= GL_UNSIGNED_SHORT
;
3731 case GL_LUMINANCE_ALPHA32UI_EXT
:
3732 *datatype
= GL_UNSIGNED_INT
;
3736 *datatype
= GL_UNSIGNED_BYTE
;
3739 case GL_INTENSITY16
:
3740 *datatype
= GL_UNSIGNED_SHORT
;
3743 case GL_INTENSITY16F_ARB
:
3744 *datatype
= GL_HALF_FLOAT
;
3747 case GL_INTENSITY32F_ARB
:
3748 *datatype
= GL_FLOAT
;
3751 case GL_INTENSITY8I_EXT
:
3752 *datatype
= GL_BYTE
;
3755 case GL_INTENSITY16I_EXT
:
3756 *datatype
= GL_SHORT
;
3759 case GL_INTENSITY32I_EXT
:
3763 case GL_INTENSITY8UI_EXT
:
3764 *datatype
= GL_UNSIGNED_BYTE
;
3767 case GL_INTENSITY16UI_EXT
:
3768 *datatype
= GL_UNSIGNED_SHORT
;
3771 case GL_INTENSITY32UI_EXT
:
3772 *datatype
= GL_UNSIGNED_INT
;
3776 *datatype
= GL_UNSIGNED_BYTE
;
3780 *datatype
= GL_UNSIGNED_SHORT
;
3783 case GL_RGBA16F_ARB
:
3784 *datatype
= GL_HALF_FLOAT
;
3787 case GL_RGBA32F_ARB
:
3788 *datatype
= GL_FLOAT
;
3792 *datatype
= GL_BYTE
;
3795 case GL_RGBA16I_EXT
:
3796 *datatype
= GL_SHORT
;
3799 case GL_RGBA32I_EXT
:
3803 case GL_RGBA8UI_EXT
:
3804 *datatype
= GL_UNSIGNED_BYTE
;
3807 case GL_RGBA16UI_EXT
:
3808 *datatype
= GL_UNSIGNED_SHORT
;
3811 case GL_RGBA32UI_EXT
:
3812 *datatype
= GL_UNSIGNED_INT
;
3819 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3822 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3829 /** GL_ARB_texture_buffer_object */
3831 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3833 struct gl_texture_object
*texObj
;
3834 struct gl_buffer_object
*bufObj
;
3838 GET_CURRENT_CONTEXT(ctx
);
3839 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3841 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3842 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3846 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3847 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3851 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3852 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3857 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3858 if (buffer
&& !bufObj
) {
3859 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3863 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3865 _mesa_lock_texture(ctx
, texObj
);
3867 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3868 texObj
->BufferObjectFormat
= internalFormat
;
3870 _mesa_unlock_texture(ctx
, texObj
);