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 return -1; /* error */
519 * For cube map faces, return a face index in [0,5].
520 * For other targets return 0;
523 _mesa_tex_target_to_face(GLenum target
)
525 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
526 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
527 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
535 * Store a gl_texture_image pointer in a gl_texture_object structure
536 * according to the target and level parameters.
538 * \param tObj texture object.
539 * \param target texture target.
540 * \param level image level.
541 * \param texImage texture image.
544 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
545 GLenum target
, GLint level
,
546 struct gl_texture_image
*texImage
)
548 const GLuint face
= _mesa_tex_target_to_face(target
);
552 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
554 tObj
->Image
[face
][level
] = texImage
;
556 /* Set the 'back' pointer */
557 texImage
->TexObject
= tObj
;
558 texImage
->Level
= level
;
559 texImage
->Face
= face
;
564 * Allocate a texture image structure.
566 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
569 * \return a pointer to gl_texture_image struct with all fields initialized to
572 struct gl_texture_image
*
573 _mesa_new_texture_image( struct gl_context
*ctx
)
576 return CALLOC_STRUCT(gl_texture_image
);
581 * Free texture image data.
582 * This function is a fallback called via ctx->Driver.FreeTextureImageBuffer().
584 * \param texImage texture image.
586 * Free the texture image data if it's not marked as client data.
589 _mesa_free_texture_image_data(struct gl_context
*ctx
,
590 struct gl_texture_image
*texImage
)
594 if (texImage
->Data
&& !texImage
->IsClientData
) {
595 /* free the old texture data */
596 _mesa_free_texmemory(texImage
->Data
);
599 texImage
->Data
= NULL
;
604 * Free texture image.
606 * \param texImage texture image.
608 * Free the texture image structure and the associated image data.
611 _mesa_delete_texture_image(struct gl_context
*ctx
,
612 struct gl_texture_image
*texImage
)
614 /* Free texImage->Data and/or any other driver-specific texture
617 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
618 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
620 ASSERT(texImage
->Data
== NULL
);
621 if (texImage
->ImageOffsets
)
622 free(texImage
->ImageOffsets
);
628 * Test if a target is a proxy target.
630 * \param target texture target.
632 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
635 _mesa_is_proxy_texture(GLenum target
)
637 /* NUM_TEXTURE_TARGETS should match number of terms below,
638 * except there's no proxy for GL_TEXTURE_BUFFER.
640 assert(NUM_TEXTURE_TARGETS
== 8);
642 return (target
== GL_PROXY_TEXTURE_1D
||
643 target
== GL_PROXY_TEXTURE_2D
||
644 target
== GL_PROXY_TEXTURE_3D
||
645 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
646 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
647 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
648 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
653 * Return the proxy target which corresponds to the given texture target
656 get_proxy_target(GLenum target
)
660 case GL_PROXY_TEXTURE_1D
:
661 return GL_PROXY_TEXTURE_1D
;
663 case GL_PROXY_TEXTURE_2D
:
664 return GL_PROXY_TEXTURE_2D
;
666 case GL_PROXY_TEXTURE_3D
:
667 return GL_PROXY_TEXTURE_3D
;
668 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
669 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
670 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
671 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
672 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
673 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
674 case GL_TEXTURE_CUBE_MAP_ARB
:
675 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
676 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
677 case GL_TEXTURE_RECTANGLE_NV
:
678 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
679 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
680 case GL_TEXTURE_1D_ARRAY_EXT
:
681 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
682 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
683 case GL_TEXTURE_2D_ARRAY_EXT
:
684 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
685 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
687 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
694 * Get the texture object that corresponds to the target of the given
695 * texture unit. The target should have already been checked for validity.
697 * \param ctx GL context.
698 * \param texUnit texture unit.
699 * \param target texture target.
701 * \return pointer to the texture object on success, or NULL on failure.
703 struct gl_texture_object
*
704 _mesa_select_tex_object(struct gl_context
*ctx
,
705 const struct gl_texture_unit
*texUnit
,
708 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
709 ctx
->Extensions
.EXT_texture_array
);
713 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
714 case GL_PROXY_TEXTURE_1D
:
715 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
717 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
718 case GL_PROXY_TEXTURE_2D
:
719 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
721 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
722 case GL_PROXY_TEXTURE_3D
:
723 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
724 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
725 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
726 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
727 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
728 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
729 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
730 case GL_TEXTURE_CUBE_MAP_ARB
:
731 return ctx
->Extensions
.ARB_texture_cube_map
732 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
733 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
734 return ctx
->Extensions
.ARB_texture_cube_map
735 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
736 case GL_TEXTURE_RECTANGLE_NV
:
737 return ctx
->Extensions
.NV_texture_rectangle
738 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
739 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
740 return ctx
->Extensions
.NV_texture_rectangle
741 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
742 case GL_TEXTURE_1D_ARRAY_EXT
:
743 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
744 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
745 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
746 case GL_TEXTURE_2D_ARRAY_EXT
:
747 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
748 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
749 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
750 case GL_TEXTURE_BUFFER
:
751 return ctx
->Extensions
.ARB_texture_buffer_object
752 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
754 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
761 * Return pointer to texture object for given target on current texture unit.
763 struct gl_texture_object
*
764 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
766 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
767 return _mesa_select_tex_object(ctx
, texUnit
, target
);
772 * Get a texture image pointer from a texture object, given a texture
773 * target and mipmap level. The target and level parameters should
774 * have already been error-checked.
776 * \param ctx GL context.
777 * \param texObj texture unit.
778 * \param target texture target.
779 * \param level image level.
781 * \return pointer to the texture image structure, or NULL on failure.
783 struct gl_texture_image
*
784 _mesa_select_tex_image(struct gl_context
*ctx
,
785 const struct gl_texture_object
*texObj
,
786 GLenum target
, GLint level
)
788 const GLuint face
= _mesa_tex_target_to_face(target
);
792 ASSERT(level
< MAX_TEXTURE_LEVELS
);
794 return texObj
->Image
[face
][level
];
799 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
800 * it and install it. Only return NULL if passed a bad parameter or run
803 struct gl_texture_image
*
804 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
805 GLenum target
, GLint level
)
807 struct gl_texture_image
*texImage
;
812 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
814 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
816 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
820 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
828 * Return pointer to the specified proxy texture image.
829 * Note that proxy textures are per-context, not per-texture unit.
830 * \return pointer to texture image or NULL if invalid target, invalid
831 * level, or out of memory.
833 struct gl_texture_image
*
834 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
836 struct gl_texture_image
*texImage
;
843 case GL_PROXY_TEXTURE_1D
:
844 if (level
>= ctx
->Const
.MaxTextureLevels
)
846 texIndex
= TEXTURE_1D_INDEX
;
848 case GL_PROXY_TEXTURE_2D
:
849 if (level
>= ctx
->Const
.MaxTextureLevels
)
851 texIndex
= TEXTURE_2D_INDEX
;
853 case GL_PROXY_TEXTURE_3D
:
854 if (level
>= ctx
->Const
.Max3DTextureLevels
)
856 texIndex
= TEXTURE_3D_INDEX
;
858 case GL_PROXY_TEXTURE_CUBE_MAP
:
859 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
861 texIndex
= TEXTURE_CUBE_INDEX
;
863 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
866 texIndex
= TEXTURE_RECT_INDEX
;
868 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
869 if (level
>= ctx
->Const
.MaxTextureLevels
)
871 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
873 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
874 if (level
>= ctx
->Const
.MaxTextureLevels
)
876 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
882 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
884 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
886 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
889 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
890 /* Set the 'back' pointer */
891 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
898 * Get the maximum number of allowed mipmap levels.
900 * \param ctx GL context.
901 * \param target texture target.
903 * \return the maximum number of allowed mipmap levels for the given
904 * texture target, or zero if passed a bad target.
909 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
913 case GL_PROXY_TEXTURE_1D
:
915 case GL_PROXY_TEXTURE_2D
:
916 return ctx
->Const
.MaxTextureLevels
;
918 case GL_PROXY_TEXTURE_3D
:
919 return ctx
->Const
.Max3DTextureLevels
;
920 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
921 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
922 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
923 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
924 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
925 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
926 case GL_TEXTURE_CUBE_MAP_ARB
:
927 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
928 return ctx
->Extensions
.ARB_texture_cube_map
929 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
930 case GL_TEXTURE_RECTANGLE_NV
:
931 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
932 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
933 case GL_TEXTURE_1D_ARRAY_EXT
:
934 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
935 case GL_TEXTURE_2D_ARRAY_EXT
:
936 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
937 return (ctx
->Extensions
.MESA_texture_array
||
938 ctx
->Extensions
.EXT_texture_array
)
939 ? ctx
->Const
.MaxTextureLevels
: 0;
940 case GL_TEXTURE_BUFFER
:
943 return 0; /* bad target */
949 * Return number of dimensions per mipmap level for the given texture target.
952 _mesa_get_texture_dimensions(GLenum target
)
956 case GL_PROXY_TEXTURE_1D
:
959 case GL_TEXTURE_RECTANGLE
:
960 case GL_TEXTURE_CUBE_MAP
:
961 case GL_PROXY_TEXTURE_2D
:
962 case GL_PROXY_TEXTURE_RECTANGLE
:
963 case GL_PROXY_TEXTURE_CUBE_MAP
:
964 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
965 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
966 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
967 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
968 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
969 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
970 case GL_TEXTURE_1D_ARRAY
:
971 case GL_PROXY_TEXTURE_1D_ARRAY
:
974 case GL_PROXY_TEXTURE_3D
:
975 case GL_TEXTURE_2D_ARRAY
:
976 case GL_PROXY_TEXTURE_2D_ARRAY
:
978 case GL_TEXTURE_BUFFER
:
981 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
990 #if 000 /* not used anymore */
992 * glTexImage[123]D can accept a NULL image pointer. In this case we
993 * create a texture image with unspecified image contents per the OpenGL
997 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
999 const GLint components
= _mesa_components_in_format(format
);
1000 const GLint numPixels
= width
* height
* depth
;
1001 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1005 * Let's see if anyone finds this. If glTexImage2D() is called with
1006 * a NULL image pointer then load the texture image with something
1007 * interesting instead of leaving it indeterminate.
1010 static const char message
[8][32] = {
1011 " X X XXXXX XXX X ",
1012 " XX XX X X X X X ",
1014 " X X XXXX XXX XXXXX ",
1017 " X X XXXXX XXX X X ",
1021 GLubyte
*imgPtr
= data
;
1023 for (h
= 0; h
< depth
; h
++) {
1024 for (i
= 0; i
< height
; i
++) {
1025 GLint srcRow
= 7 - (i
% 8);
1026 for (j
= 0; j
< width
; j
++) {
1027 GLint srcCol
= j
% 32;
1028 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1029 for (k
= 0; k
< components
; k
++) {
1045 * Reset the fields of a gl_texture_image struct to zero.
1047 * \param img texture image structure.
1049 * This is called when a proxy texture test fails, we set all the
1050 * image members (except DriverData) to zero.
1051 * It's also used in glTexImage[123]D as a safeguard to be sure all
1052 * required fields get initialized properly by the Driver.TexImage[123]D
1056 clear_teximage_fields(struct gl_texture_image
*img
)
1059 img
->_BaseFormat
= 0;
1060 img
->InternalFormat
= 0;
1066 if (img
->ImageOffsets
) {
1067 free(img
->ImageOffsets
);
1068 img
->ImageOffsets
= NULL
;
1074 img
->HeightLog2
= 0;
1077 img
->TexFormat
= MESA_FORMAT_NONE
;
1078 img
->FetchTexelc
= NULL
;
1079 img
->FetchTexelf
= NULL
;
1084 * Initialize basic fields of the gl_texture_image struct.
1086 * \param ctx GL context.
1087 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1088 * \param img texture image structure to be initialized.
1089 * \param width image width.
1090 * \param height image height.
1091 * \param depth image depth.
1092 * \param border image border.
1093 * \param internalFormat internal format.
1094 * \param format the actual hardware format (one of MESA_FORMAT_*)
1096 * Fills in the fields of \p img with the given information.
1097 * Note: width, height and depth include the border.
1100 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1101 struct gl_texture_image
*img
,
1102 GLsizei width
, GLsizei height
, GLsizei depth
,
1103 GLint border
, GLenum internalFormat
,
1110 ASSERT(height
>= 0);
1113 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1114 ASSERT(img
->_BaseFormat
> 0);
1115 img
->InternalFormat
= internalFormat
;
1116 img
->Border
= border
;
1118 img
->Height
= height
;
1121 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1122 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1124 if (height
== 1) { /* 1-D texture */
1126 img
->HeightLog2
= 0;
1129 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1130 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1133 if (depth
== 1) { /* 2-D texture */
1138 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1139 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1142 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1144 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1145 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1146 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1147 img
->_IsPowerOfTwo
= GL_TRUE
;
1149 img
->_IsPowerOfTwo
= GL_FALSE
;
1151 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1152 img
->RowStride
= width
;
1153 /* Allocate the ImageOffsets array and initialize to typical values.
1154 * We allocate the array for 1D/2D textures too in order to avoid special-
1155 * case code in the texstore routines.
1157 if (img
->ImageOffsets
)
1158 free(img
->ImageOffsets
);
1159 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1160 for (i
= 0; i
< depth
; i
++) {
1161 img
->ImageOffsets
[i
] = i
* width
* height
;
1164 /* Compute Width/Height/DepthScale for mipmap lod computation */
1165 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1166 /* scale = 1.0 since texture coords directly map to texels */
1167 img
->WidthScale
= 1.0;
1168 img
->HeightScale
= 1.0;
1169 img
->DepthScale
= 1.0;
1172 img
->WidthScale
= (GLfloat
) img
->Width
;
1173 img
->HeightScale
= (GLfloat
) img
->Height
;
1174 img
->DepthScale
= (GLfloat
) img
->Depth
;
1177 img
->TexFormat
= format
;
1182 * Free and clear fields of the gl_texture_image struct.
1184 * \param ctx GL context.
1185 * \param texImage texture image structure to be cleared.
1187 * After the call, \p texImage will have no data associated with it. Its
1188 * fields are cleared so that its parent object will test incomplete.
1191 _mesa_clear_texture_image(struct gl_context
*ctx
,
1192 struct gl_texture_image
*texImage
)
1194 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1195 clear_teximage_fields(texImage
);
1200 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1201 * level, width, height and depth against the ctx->Const limits for textures.
1203 * A hardware driver might override this function if, for example, the
1204 * max 3D texture size is 512x512x64 (i.e. not a cube).
1206 * Note that width, height, depth == 0 is not an error. However, a
1207 * texture with zero width/height/depth will be considered "incomplete"
1208 * and texturing will effectively be disabled.
1210 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1211 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1212 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1213 * \param level as passed to glTexImage
1214 * \param internalFormat as passed to glTexImage
1215 * \param format as passed to glTexImage
1216 * \param type as passed to glTexImage
1217 * \param width as passed to glTexImage
1218 * \param height as passed to glTexImage
1219 * \param depth as passed to glTexImage
1220 * \param border as passed to glTexImage
1221 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1224 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1225 GLint internalFormat
, GLenum format
, GLenum type
,
1226 GLint width
, GLint height
, GLint depth
, GLint border
)
1230 (void) internalFormat
;
1235 case GL_PROXY_TEXTURE_1D
:
1236 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1237 if (width
< 2 * border
|| width
> 2 + maxSize
)
1239 if (level
>= ctx
->Const
.MaxTextureLevels
)
1241 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1242 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1247 case GL_PROXY_TEXTURE_2D
:
1248 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1249 if (width
< 2 * border
|| width
> 2 + maxSize
)
1251 if (height
< 2 * border
|| height
> 2 + maxSize
)
1253 if (level
>= ctx
->Const
.MaxTextureLevels
)
1255 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1256 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1258 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1263 case GL_PROXY_TEXTURE_3D
:
1264 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1265 if (width
< 2 * border
|| width
> 2 + maxSize
)
1267 if (height
< 2 * border
|| height
> 2 + maxSize
)
1269 if (depth
< 2 * border
|| depth
> 2 + maxSize
)
1271 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1273 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1274 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1276 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1278 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1283 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1284 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1285 if (width
< 0 || width
> maxSize
)
1287 if (height
< 0 || height
> maxSize
)
1293 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1294 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1295 if (width
< 2 * border
|| width
> 2 + maxSize
)
1297 if (height
< 2 * border
|| height
> 2 + maxSize
)
1299 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1301 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1302 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1304 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1309 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1310 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1311 if (width
< 2 * border
|| width
> 2 + maxSize
)
1313 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1315 if (level
>= ctx
->Const
.MaxTextureLevels
)
1317 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1318 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1323 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1324 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1325 if (width
< 2 * border
|| width
> 2 + maxSize
)
1327 if (height
< 2 * border
|| height
> 2 + maxSize
)
1329 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1331 if (level
>= ctx
->Const
.MaxTextureLevels
)
1333 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1334 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1336 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1342 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1349 * Check if the memory used by the texture would exceed the driver's limit.
1350 * This lets us support a max 3D texture size of 8K (for example) but
1351 * prevents allocating a full 8K x 8K x 8K texture.
1352 * XXX this could be rolled into the proxy texture size test (above) but
1353 * we don't have the actual texture internal format at that point.
1356 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1357 GLint width
, GLint height
, GLint depth
)
1359 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1360 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1361 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1367 * Helper function to determine whether a target and specific compression
1368 * format are supported.
1371 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1374 (void) intFormat
; /* not used yet */
1378 case GL_PROXY_TEXTURE_2D
:
1379 return GL_TRUE
; /* true for any compressed format so far */
1380 case GL_PROXY_TEXTURE_CUBE_MAP
:
1381 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1382 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1383 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1384 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1385 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1386 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1387 return ctx
->Extensions
.ARB_texture_cube_map
;
1388 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1389 case GL_TEXTURE_2D_ARRAY_EXT
:
1390 return (ctx
->Extensions
.MESA_texture_array
||
1391 ctx
->Extensions
.EXT_texture_array
);
1399 * Check if the given texture target value is legal for a
1400 * glTexImage1/2/3D call.
1403 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1409 case GL_PROXY_TEXTURE_1D
:
1417 case GL_PROXY_TEXTURE_2D
:
1419 case GL_PROXY_TEXTURE_CUBE_MAP
:
1420 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1421 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1422 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1423 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1424 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1425 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1426 return ctx
->Extensions
.ARB_texture_cube_map
;
1427 case GL_TEXTURE_RECTANGLE_NV
:
1428 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1429 return ctx
->Extensions
.NV_texture_rectangle
;
1430 case GL_TEXTURE_1D_ARRAY_EXT
:
1431 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1432 return (ctx
->Extensions
.MESA_texture_array
||
1433 ctx
->Extensions
.EXT_texture_array
);
1440 case GL_PROXY_TEXTURE_3D
:
1442 case GL_TEXTURE_2D_ARRAY_EXT
:
1443 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1444 return (ctx
->Extensions
.MESA_texture_array
||
1445 ctx
->Extensions
.EXT_texture_array
);
1450 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1457 * Check if the given texture target value is legal for a
1458 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1459 * The difference compared to legal_teximage_target() above is that
1460 * proxy targets are not supported.
1463 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1467 return target
== GL_TEXTURE_1D
;
1472 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1473 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1474 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1475 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1476 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1477 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1478 return ctx
->Extensions
.ARB_texture_cube_map
;
1479 case GL_TEXTURE_RECTANGLE_NV
:
1480 return ctx
->Extensions
.NV_texture_rectangle
;
1481 case GL_TEXTURE_1D_ARRAY_EXT
:
1482 return (ctx
->Extensions
.MESA_texture_array
||
1483 ctx
->Extensions
.EXT_texture_array
);
1491 case GL_TEXTURE_2D_ARRAY_EXT
:
1492 return (ctx
->Extensions
.MESA_texture_array
||
1493 ctx
->Extensions
.EXT_texture_array
);
1498 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1506 * Test the glTexImage[123]D() parameters for errors.
1508 * \param ctx GL context.
1509 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1510 * \param target texture target given by the user.
1511 * \param level image level given by the user.
1512 * \param internalFormat internal format given by the user.
1513 * \param format pixel data format given by the user.
1514 * \param type pixel data type given by the user.
1515 * \param width image width given by the user.
1516 * \param height image height given by the user.
1517 * \param depth image depth given by the user.
1518 * \param border image border given by the user.
1520 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1522 * Verifies each of the parameters against the constants specified in
1523 * __struct gl_contextRec::Const and the supported extensions, and according
1524 * to the OpenGL specification.
1527 texture_error_check( struct gl_context
*ctx
,
1528 GLuint dimensions
, GLenum target
,
1529 GLint level
, GLint internalFormat
,
1530 GLenum format
, GLenum type
,
1531 GLint width
, GLint height
,
1532 GLint depth
, GLint border
)
1534 const GLenum proxyTarget
= get_proxy_target(target
);
1535 const GLboolean isProxy
= target
== proxyTarget
;
1536 GLboolean sizeOK
= GL_TRUE
;
1537 GLboolean colorFormat
;
1539 /* Even though there are no color-index textures, we still have to support
1540 * uploading color-index data and remapping it to RGB via the
1541 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1543 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1545 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1546 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1548 _mesa_error(ctx
, GL_INVALID_VALUE
,
1549 "glTexImage%dD(level=%d)", dimensions
, level
);
1555 if (border
< 0 || border
> 1 ||
1556 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1557 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1559 _mesa_error(ctx
, GL_INVALID_VALUE
,
1560 "glTexImage%dD(border=%d)", dimensions
, border
);
1565 if (width
< 0 || height
< 0 || depth
< 0) {
1567 _mesa_error(ctx
, GL_INVALID_VALUE
,
1568 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1573 /* Do this simple check before calling the TestProxyTexImage() function */
1574 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1575 sizeOK
= (width
== height
);
1579 * Use the proxy texture driver hook to see if the size/level/etc are
1582 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1583 internalFormat
, format
,
1584 type
, width
, height
,
1588 _mesa_error(ctx
, GL_INVALID_VALUE
,
1589 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1590 dimensions
, level
, width
, height
, depth
);
1595 /* Check internalFormat */
1596 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1598 _mesa_error(ctx
, GL_INVALID_VALUE
,
1599 "glTexImage%dD(internalFormat=%s)",
1600 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1605 /* Check incoming image format and type */
1606 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1607 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1608 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1609 * GL_EXT_texture_integer extension, some combinations should generate
1610 * GL_INVALID_ENUM instead (grr!).
1613 GLenum error
= _mesa_is_integer_format(format
)
1614 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1615 _mesa_error(ctx
, error
,
1616 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1617 dimensions
, format
, type
);
1622 /* make sure internal format and format basically agree */
1623 colorFormat
= _mesa_is_color_format(format
);
1624 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1625 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1626 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1627 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1628 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1630 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1631 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1632 dimensions
, internalFormat
, format
);
1636 /* additional checks for ycbcr textures */
1637 if (internalFormat
== GL_YCBCR_MESA
) {
1638 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1639 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1640 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1642 _mesa_snprintf(message
, sizeof(message
),
1643 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1644 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1645 return GL_TRUE
; /* error */
1647 if (target
!= GL_TEXTURE_2D
&&
1648 target
!= GL_PROXY_TEXTURE_2D
&&
1649 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1650 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1652 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1658 _mesa_snprintf(message
, sizeof(message
),
1659 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1660 dimensions
, border
);
1661 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1667 /* additional checks for depth textures */
1668 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1669 /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */
1670 if (target
!= GL_TEXTURE_1D
&&
1671 target
!= GL_PROXY_TEXTURE_1D
&&
1672 target
!= GL_TEXTURE_2D
&&
1673 target
!= GL_PROXY_TEXTURE_2D
&&
1674 target
!= GL_TEXTURE_1D_ARRAY
&&
1675 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1676 target
!= GL_TEXTURE_2D_ARRAY
&&
1677 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1678 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1679 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1681 _mesa_error(ctx
, GL_INVALID_ENUM
,
1682 "glTexImage(target/internalFormat)");
1687 /* additional checks for compressed textures */
1688 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1689 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1691 _mesa_error(ctx
, GL_INVALID_ENUM
,
1692 "glTexImage%dD(target)", dimensions
);
1697 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1698 "glTexImage%dD(border!=0)", dimensions
);
1704 /* additional checks for integer textures */
1705 if (ctx
->Extensions
.EXT_texture_integer
&&
1706 (_mesa_is_integer_format(format
) !=
1707 _mesa_is_integer_format(internalFormat
))) {
1709 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1710 "glTexImage%dD(integer/non-integer format mismatch)",
1716 /* if we get here, the parameters are OK */
1722 * Test glTexSubImage[123]D() parameters for errors.
1724 * \param ctx GL context.
1725 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1726 * \param target texture target given by the user.
1727 * \param level image level given by the user.
1728 * \param xoffset sub-image x offset given by the user.
1729 * \param yoffset sub-image y offset given by the user.
1730 * \param zoffset sub-image z offset given by the user.
1731 * \param format pixel data format given by the user.
1732 * \param type pixel data type given by the user.
1733 * \param width image width given by the user.
1734 * \param height image height given by the user.
1735 * \param depth image depth given by the user.
1737 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1739 * Verifies each of the parameters against the constants specified in
1740 * __struct gl_contextRec::Const and the supported extensions, and according
1741 * to the OpenGL specification.
1744 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1745 GLenum target
, GLint level
,
1746 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1747 GLint width
, GLint height
, GLint depth
,
1748 GLenum format
, GLenum type
)
1750 /* Basic level check */
1751 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1752 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1756 /* Check for negative sizes */
1758 _mesa_error(ctx
, GL_INVALID_VALUE
,
1759 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1762 if (height
< 0 && dimensions
> 1) {
1763 _mesa_error(ctx
, GL_INVALID_VALUE
,
1764 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1767 if (depth
< 0 && dimensions
> 2) {
1768 _mesa_error(ctx
, GL_INVALID_VALUE
,
1769 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1773 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1774 /* As with the glTexImage2D check above, the error code here
1775 * depends on texture integer.
1777 GLenum error
= _mesa_is_integer_format(format
)
1778 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1779 _mesa_error(ctx
, error
,
1780 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1781 dimensions
, format
, type
);
1790 * Do second part of glTexSubImage which depends on the destination texture.
1791 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1794 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1795 GLenum target
, GLint level
,
1796 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1797 GLint width
, GLint height
, GLint depth
,
1798 GLenum format
, GLenum type
,
1799 const struct gl_texture_image
*destTex
)
1802 /* undefined image level */
1803 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1807 if (xoffset
< -((GLint
)destTex
->Border
)) {
1808 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1812 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1813 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1817 if (dimensions
> 1) {
1818 if (yoffset
< -((GLint
)destTex
->Border
)) {
1819 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1823 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1824 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1829 if (dimensions
> 2) {
1830 if (zoffset
< -((GLint
)destTex
->Border
)) {
1831 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1834 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1835 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1840 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1843 /* do tests which depend on compression block size */
1844 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1846 /* offset must be multiple of block size */
1847 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1848 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1849 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1850 dimensions
, xoffset
, yoffset
);
1853 /* size must be multiple of bw by bh or equal to whole texture size */
1854 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1855 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1856 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1859 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1860 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1861 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1871 * Test glCopyTexImage[12]D() parameters for errors.
1873 * \param ctx GL context.
1874 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1875 * \param target texture target given by the user.
1876 * \param level image level given by the user.
1877 * \param internalFormat internal format given by the user.
1878 * \param width image width given by the user.
1879 * \param height image height given by the user.
1880 * \param border texture border.
1882 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1884 * Verifies each of the parameters against the constants specified in
1885 * __struct gl_contextRec::Const and the supported extensions, and according
1886 * to the OpenGL specification.
1889 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1890 GLenum target
, GLint level
, GLint internalFormat
,
1891 GLint width
, GLint height
, GLint border
)
1893 const GLenum proxyTarget
= get_proxy_target(target
);
1894 const GLenum type
= GL_FLOAT
;
1899 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1900 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1901 dimensions
, _mesa_lookup_enum_by_nr(target
));
1905 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1906 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1907 _mesa_error(ctx
, GL_INVALID_VALUE
,
1908 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1912 /* Check that the source buffer is complete */
1913 if (ctx
->ReadBuffer
->Name
) {
1914 if (ctx
->ReadBuffer
->_Status
== 0) {
1915 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1917 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1918 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1919 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1925 if (border
< 0 || border
> 1 ||
1926 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1927 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1931 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1933 _mesa_error(ctx
, GL_INVALID_VALUE
,
1934 "glCopyTexImage%dD(internalFormat)", dimensions
);
1938 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1939 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1940 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1944 /* Do size, level checking */
1945 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1946 ? (width
== height
) : 1;
1948 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1949 internalFormat
, format
,
1950 type
, width
, height
,
1954 if (dimensions
== 1) {
1955 _mesa_error(ctx
, GL_INVALID_VALUE
,
1956 "glCopyTexImage1D(width=%d)", width
);
1959 ASSERT(dimensions
== 2);
1960 _mesa_error(ctx
, GL_INVALID_VALUE
,
1961 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1966 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1967 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1968 _mesa_error(ctx
, GL_INVALID_ENUM
,
1969 "glCopyTexImage%dD(target)", dimensions
);
1973 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1974 "glCopyTexImage%dD(border!=0)", dimensions
);
1978 else if (_mesa_is_depth_format(internalFormat
)) {
1979 /* make sure we have depth/stencil buffers */
1980 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1981 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1982 "glCopyTexImage%dD(no depth)", dimensions
);
1986 else if (_mesa_is_depthstencil_format(internalFormat
)) {
1987 /* make sure we have depth/stencil buffers */
1988 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
1989 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1990 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
1995 /* if we get here, the parameters are OK */
2001 * Test glCopyTexSubImage[12]D() parameters for errors.
2002 * Note that this is the first part of error checking.
2003 * See also copytexsubimage_error_check2() below for the second part.
2005 * \param ctx GL context.
2006 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2007 * \param target texture target given by the user.
2008 * \param level image level given by the user.
2010 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2013 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2014 GLenum target
, GLint level
)
2016 /* Check that the source buffer is complete */
2017 if (ctx
->ReadBuffer
->Name
) {
2018 if (ctx
->ReadBuffer
->_Status
== 0) {
2019 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2021 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2022 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2023 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2028 /* check target (proxies not allowed) */
2029 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2030 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2031 dimensions
, _mesa_lookup_enum_by_nr(target
));
2036 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2037 _mesa_error(ctx
, GL_INVALID_VALUE
,
2038 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2047 * Second part of error checking for glCopyTexSubImage[12]D().
2048 * \param xoffset sub-image x offset given by the user.
2049 * \param yoffset sub-image y offset given by the user.
2050 * \param zoffset sub-image z offset given by the user.
2051 * \param width image width given by the user.
2052 * \param height image height given by the user.
2055 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2056 GLenum target
, GLint level
,
2057 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2058 GLsizei width
, GLsizei height
,
2059 const struct gl_texture_image
*teximage
)
2061 /* check that dest tex image exists */
2063 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2064 "glCopyTexSubImage%dD(undefined texture level: %d)",
2071 _mesa_error(ctx
, GL_INVALID_VALUE
,
2072 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2075 if (dimensions
> 1 && height
< 0) {
2076 _mesa_error(ctx
, GL_INVALID_VALUE
,
2077 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2081 /* check x/y offsets */
2082 if (xoffset
< -((GLint
)teximage
->Border
)) {
2083 _mesa_error(ctx
, GL_INVALID_VALUE
,
2084 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2087 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2088 _mesa_error(ctx
, GL_INVALID_VALUE
,
2089 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2092 if (dimensions
> 1) {
2093 if (yoffset
< -((GLint
)teximage
->Border
)) {
2094 _mesa_error(ctx
, GL_INVALID_VALUE
,
2095 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2098 /* NOTE: we're adding the border here, not subtracting! */
2099 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2100 _mesa_error(ctx
, GL_INVALID_VALUE
,
2101 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2106 /* check z offset */
2107 if (dimensions
> 2) {
2108 if (zoffset
< -((GLint
)teximage
->Border
)) {
2109 _mesa_error(ctx
, GL_INVALID_VALUE
,
2110 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2113 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2114 _mesa_error(ctx
, GL_INVALID_VALUE
,
2115 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2120 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2121 /* offset must be multiple of 4 */
2122 if ((xoffset
& 3) || (yoffset
& 3)) {
2123 _mesa_error(ctx
, GL_INVALID_VALUE
,
2124 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2127 /* size must be multiple of 4 */
2128 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2129 _mesa_error(ctx
, GL_INVALID_VALUE
,
2130 "glCopyTexSubImage%dD(width)", dimensions
);
2133 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2134 _mesa_error(ctx
, GL_INVALID_VALUE
,
2135 "glCopyTexSubImage%dD(height)", dimensions
);
2140 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2141 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2145 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2146 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2147 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2148 dimensions
, teximage
->_BaseFormat
);
2152 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2153 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2154 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2155 "glCopyTexSubImage%dD(no depth buffer)",
2160 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2161 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2162 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2163 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2169 /* If copying into an integer texture, the source buffer must also be
2172 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2173 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2174 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2175 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2176 "glCopyTexSubImage%dD(source buffer is not integer format)",
2182 /* if we get here, the parameters are OK */
2187 /** Callback info for walking over FBO hash table */
2190 struct gl_context
*ctx
;
2191 struct gl_texture_object
*texObj
;
2197 * Check render to texture callback. Called from _mesa_HashWalk().
2200 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2202 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2203 const struct cb_info
*info
= (struct cb_info
*) userData
;
2204 struct gl_context
*ctx
= info
->ctx
;
2205 const struct gl_texture_object
*texObj
= info
->texObj
;
2206 const GLuint level
= info
->level
, face
= info
->face
;
2208 /* If this is a user-created FBO */
2211 /* check if any of the FBO's attachments point to 'texObj' */
2212 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2213 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2214 if (att
->Type
== GL_TEXTURE
&&
2215 att
->Texture
== texObj
&&
2216 att
->TextureLevel
== level
&&
2217 att
->CubeMapFace
== face
) {
2218 ASSERT(_mesa_get_attachment_teximage(att
));
2219 /* Tell driver about the new renderbuffer texture */
2220 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2221 /* Mark fb status as indeterminate to force re-validation */
2230 * When a texture image is specified we have to check if it's bound to
2231 * any framebuffer objects (render to texture) in order to detect changes
2232 * in size or format since that effects FBO completeness.
2233 * Any FBOs rendering into the texture must be re-validated.
2236 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2237 GLuint face
, GLuint level
)
2239 /* Only check this texture if it's been marked as RenderToTexture */
2240 if (texObj
->_RenderToTexture
) {
2241 struct cb_info info
;
2243 info
.texObj
= texObj
;
2246 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2252 * If the texture object's GenerateMipmap flag is set and we've
2253 * changed the texture base level image, regenerate the rest of the
2254 * mipmap levels now.
2257 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2258 struct gl_texture_object
*texObj
, GLint level
)
2260 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2261 if (texObj
->GenerateMipmap
&&
2262 level
== texObj
->BaseLevel
&&
2263 level
< texObj
->MaxLevel
) {
2264 ASSERT(ctx
->Driver
.GenerateMipmap
);
2265 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2270 /** Debug helper: override the user-requested internal format */
2272 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2275 if (internalFormat
== GL_RGBA16F_ARB
||
2276 internalFormat
== GL_RGBA32F_ARB
) {
2277 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2280 else if (internalFormat
== GL_RGB16F_ARB
||
2281 internalFormat
== GL_RGB32F_ARB
) {
2282 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2285 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2286 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2287 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2288 return GL_LUMINANCE_ALPHA
;
2290 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2291 internalFormat
== GL_LUMINANCE32F_ARB
) {
2292 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2293 return GL_LUMINANCE
;
2295 else if (internalFormat
== GL_ALPHA16F_ARB
||
2296 internalFormat
== GL_ALPHA32F_ARB
) {
2297 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2301 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2302 internalFormat = GL_RGBA;
2306 return internalFormat
;
2309 return internalFormat
;
2315 * Choose the actual hardware format for a texture image.
2316 * Try to use the same format as the previous image level when possible.
2317 * Otherwise, ask the driver for the best format.
2318 * It's important to try to choose a consistant format for all levels
2319 * for efficient texture memory layout/allocation. In particular, this
2320 * comes up during automatic mipmap generation.
2323 _mesa_choose_texture_format(struct gl_context
*ctx
,
2324 struct gl_texture_object
*texObj
,
2325 GLenum target
, GLint level
,
2326 GLenum internalFormat
, GLenum format
, GLenum type
)
2330 /* see if we've already chosen a format for the previous level */
2332 struct gl_texture_image
*prevImage
=
2333 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2334 /* See if the prev level is defined and has an internal format which
2335 * matches the new internal format.
2338 prevImage
->Width
> 0 &&
2339 prevImage
->InternalFormat
== internalFormat
) {
2340 /* use the same format */
2341 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2342 return prevImage
->TexFormat
;
2346 /* choose format from scratch */
2347 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2348 ASSERT(f
!= MESA_FORMAT_NONE
);
2354 * Common code to implement all the glTexImage1D/2D/3D functions.
2357 teximage(struct gl_context
*ctx
, GLuint dims
,
2358 GLenum target
, GLint level
, GLint internalFormat
,
2359 GLsizei width
, GLsizei height
, GLsizei depth
,
2360 GLint border
, GLenum format
, GLenum type
,
2361 const GLvoid
*pixels
)
2365 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2367 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2368 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2370 _mesa_lookup_enum_by_nr(target
), level
,
2371 _mesa_lookup_enum_by_nr(internalFormat
),
2372 width
, height
, depth
, border
,
2373 _mesa_lookup_enum_by_nr(format
),
2374 _mesa_lookup_enum_by_nr(type
), pixels
);
2376 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2378 /* target error checking */
2379 if (!legal_teximage_target(ctx
, dims
, target
)) {
2380 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2381 dims
, _mesa_lookup_enum_by_nr(target
));
2385 /* general error checking */
2386 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2387 format
, type
, width
, height
, depth
, border
);
2389 if (_mesa_is_proxy_texture(target
)) {
2390 /* Proxy texture: just clear or set state depending on error checking */
2391 struct gl_texture_image
*texImage
=
2392 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2395 /* when error, clear all proxy texture image parameters */
2397 clear_teximage_fields(texImage
);
2400 /* no error, set the tex image parameters */
2401 struct gl_texture_object
*texObj
=
2402 _mesa_get_current_tex_object(ctx
, target
);
2403 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2408 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2409 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2410 depth
, border
, internalFormat
,
2413 else if (texImage
) {
2414 clear_teximage_fields(texImage
);
2419 /* non-proxy target */
2420 const GLuint face
= _mesa_tex_target_to_face(target
);
2421 struct gl_texture_object
*texObj
;
2422 struct gl_texture_image
*texImage
;
2425 return; /* error was recorded */
2428 if (ctx
->NewState
& _NEW_PIXEL
)
2429 _mesa_update_state(ctx
);
2431 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2433 _mesa_lock_texture(ctx
, texObj
);
2435 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2438 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2441 gl_format texFormat
;
2443 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2445 ASSERT(texImage
->Data
== NULL
);
2446 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2447 internalFormat
, format
,
2450 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2451 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2452 width
, height
, depth
,
2453 border
, internalFormat
, texFormat
);
2455 /* Give the texture to the driver. <pixels> may be null. */
2456 ASSERT(ctx
->Driver
.TexImage3D
);
2459 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2460 width
, border
, format
,
2461 type
, pixels
, &ctx
->Unpack
, texObj
,
2465 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2466 width
, height
, border
, format
,
2467 type
, pixels
, &ctx
->Unpack
, texObj
,
2471 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2472 width
, height
, depth
, border
, format
,
2473 type
, pixels
, &ctx
->Unpack
, texObj
,
2477 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2480 check_gen_mipmap(ctx
, target
, texObj
, level
);
2482 update_fbo_texture(ctx
, texObj
, face
, level
);
2485 texObj
->_Complete
= GL_FALSE
;
2486 ctx
->NewState
|= _NEW_TEXTURE
;
2489 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2493 _mesa_unlock_texture(ctx
, texObj
);
2499 * Called from the API. Note that width includes the border.
2502 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2503 GLsizei width
, GLint border
, GLenum format
,
2504 GLenum type
, const GLvoid
*pixels
)
2506 GET_CURRENT_CONTEXT(ctx
);
2507 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2508 border
, format
, type
, pixels
);
2513 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2514 GLsizei width
, GLsizei height
, GLint border
,
2515 GLenum format
, GLenum type
,
2516 const GLvoid
*pixels
)
2518 GET_CURRENT_CONTEXT(ctx
);
2519 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2520 border
, format
, type
, pixels
);
2525 * Called by the API or display list executor.
2526 * Note that width and height include the border.
2529 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2530 GLsizei width
, GLsizei height
, GLsizei depth
,
2531 GLint border
, GLenum format
, GLenum type
,
2532 const GLvoid
*pixels
)
2534 GET_CURRENT_CONTEXT(ctx
);
2535 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2536 border
, format
, type
, pixels
);
2541 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2542 GLsizei width
, GLsizei height
, GLsizei depth
,
2543 GLint border
, GLenum format
, GLenum type
,
2544 const GLvoid
*pixels
)
2546 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2547 depth
, border
, format
, type
, pixels
);
2551 #if FEATURE_OES_EGL_image
2553 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2555 struct gl_texture_object
*texObj
;
2556 struct gl_texture_image
*texImage
;
2557 GET_CURRENT_CONTEXT(ctx
);
2558 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2560 if (!ctx
->Extensions
.OES_EGL_image
) {
2561 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2562 "glEGLImageTargetTexture2DOES(unsupported)");
2566 if (target
!= GL_TEXTURE_2D
) {
2567 _mesa_error(ctx
, GL_INVALID_ENUM
,
2568 "glEGLImageTargetTexture2D(target=%d)", target
);
2572 if (ctx
->NewState
& _NEW_PIXEL
)
2573 _mesa_update_state(ctx
);
2575 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2576 _mesa_lock_texture(ctx
, texObj
);
2578 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2580 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2582 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2584 ASSERT(texImage
->Data
== NULL
);
2585 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2586 texObj
, texImage
, image
);
2589 texObj
->_Complete
= GL_FALSE
;
2590 ctx
->NewState
|= _NEW_TEXTURE
;
2592 _mesa_unlock_texture(ctx
, texObj
);
2600 * Implement all the glTexSubImage1/2/3D() functions.
2603 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2604 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2605 GLsizei width
, GLsizei height
, GLsizei depth
,
2606 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2608 struct gl_texture_object
*texObj
;
2609 struct gl_texture_image
*texImage
;
2611 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2613 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2614 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2616 _mesa_lookup_enum_by_nr(target
), level
,
2617 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2618 _mesa_lookup_enum_by_nr(format
),
2619 _mesa_lookup_enum_by_nr(type
), pixels
);
2621 /* check target (proxies not allowed) */
2622 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2623 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2624 dims
, _mesa_lookup_enum_by_nr(target
));
2628 if (ctx
->NewState
& _NEW_PIXEL
)
2629 _mesa_update_state(ctx
);
2631 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2632 width
, height
, depth
, format
, type
)) {
2633 return; /* error was detected */
2636 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2638 _mesa_lock_texture(ctx
, texObj
);
2640 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2642 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2643 xoffset
, yoffset
, zoffset
,
2644 width
, height
, depth
,
2645 format
, type
, texImage
)) {
2646 /* error was recorded */
2648 else if (width
> 0 && height
> 0 && depth
> 0) {
2649 /* If we have a border, offset=-1 is legal. Bias by border width. */
2652 zoffset
+= texImage
->Border
;
2655 yoffset
+= texImage
->Border
;
2658 xoffset
+= texImage
->Border
;
2663 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2665 format
, type
, pixels
,
2666 &ctx
->Unpack
, texObj
, texImage
);
2669 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2670 xoffset
, yoffset
, width
, height
,
2671 format
, type
, pixels
,
2672 &ctx
->Unpack
, texObj
, texImage
);
2675 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2676 xoffset
, yoffset
, zoffset
,
2677 width
, height
, depth
,
2678 format
, type
, pixels
,
2679 &ctx
->Unpack
, texObj
, texImage
);
2682 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2685 check_gen_mipmap(ctx
, target
, texObj
, level
);
2687 ctx
->NewState
|= _NEW_TEXTURE
;
2690 _mesa_unlock_texture(ctx
, texObj
);
2695 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2696 GLint xoffset
, GLsizei width
,
2697 GLenum format
, GLenum type
,
2698 const GLvoid
*pixels
)
2700 GET_CURRENT_CONTEXT(ctx
);
2701 texsubimage(ctx
, 1, target
, level
,
2704 format
, type
, pixels
);
2709 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2710 GLint xoffset
, GLint yoffset
,
2711 GLsizei width
, GLsizei height
,
2712 GLenum format
, GLenum type
,
2713 const GLvoid
*pixels
)
2715 GET_CURRENT_CONTEXT(ctx
);
2716 texsubimage(ctx
, 2, target
, level
,
2717 xoffset
, yoffset
, 0,
2719 format
, type
, pixels
);
2725 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2726 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2727 GLsizei width
, GLsizei height
, GLsizei depth
,
2728 GLenum format
, GLenum type
,
2729 const GLvoid
*pixels
)
2731 GET_CURRENT_CONTEXT(ctx
);
2732 texsubimage(ctx
, 3, target
, level
,
2733 xoffset
, yoffset
, zoffset
,
2734 width
, height
, depth
,
2735 format
, type
, pixels
);
2741 * Implement the glCopyTexImage1/2D() functions.
2744 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2745 GLenum target
, GLint level
, GLenum internalFormat
,
2746 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2748 struct gl_texture_object
*texObj
;
2749 struct gl_texture_image
*texImage
;
2750 const GLuint face
= _mesa_tex_target_to_face(target
);
2752 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2754 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2755 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2757 _mesa_lookup_enum_by_nr(target
), level
,
2758 _mesa_lookup_enum_by_nr(internalFormat
),
2759 x
, y
, width
, height
, border
);
2761 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2762 _mesa_update_state(ctx
);
2764 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2765 width
, height
, border
))
2768 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2770 _mesa_lock_texture(ctx
, texObj
);
2772 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2775 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2778 /* choose actual hw format */
2779 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2784 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2785 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2787 /* Free old texture image */
2788 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2790 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2791 border
, internalFormat
, texFormat
);
2793 /* Allocate texture memory (no pixel data yet) */
2795 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2796 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2797 &ctx
->Unpack
, texObj
, texImage
);
2800 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2801 width
, height
, border
, GL_NONE
, GL_NONE
,
2802 NULL
, &ctx
->Unpack
, texObj
, texImage
);
2805 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2808 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
, dstX
,
2812 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, dstX
, dstY
,
2813 srcX
, srcY
, width
, height
);
2816 check_gen_mipmap(ctx
, target
, texObj
, level
);
2818 update_fbo_texture(ctx
, texObj
, face
, level
);
2821 texObj
->_Complete
= GL_FALSE
;
2822 ctx
->NewState
|= _NEW_TEXTURE
;
2825 /* probably too large of image */
2826 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2830 _mesa_unlock_texture(ctx
, texObj
);
2836 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2837 GLenum internalFormat
,
2839 GLsizei width
, GLint border
)
2841 GET_CURRENT_CONTEXT(ctx
);
2842 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2848 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2849 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2852 GET_CURRENT_CONTEXT(ctx
);
2853 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2854 x
, y
, width
, height
, border
);
2860 * Implementation for glCopyTexSubImage1/2/3D() functions.
2863 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2864 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2865 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2867 struct gl_texture_object
*texObj
;
2868 struct gl_texture_image
*texImage
;
2870 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2872 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2873 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2875 _mesa_lookup_enum_by_nr(target
),
2876 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2878 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2879 _mesa_update_state(ctx
);
2881 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2884 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2886 _mesa_lock_texture(ctx
, texObj
);
2888 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2890 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2891 zoffset
, width
, height
, texImage
)) {
2892 /* error was recored */
2895 /* If we have a border, offset=-1 is legal. Bias by border width. */
2898 zoffset
+= texImage
->Border
;
2901 yoffset
+= texImage
->Border
;
2904 xoffset
+= texImage
->Border
;
2907 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2911 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2912 xoffset
, x
, y
, width
);
2915 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2917 x
, y
, width
, height
);
2920 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2921 xoffset
, yoffset
, zoffset
,
2922 x
, y
, width
, height
);
2925 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
2928 check_gen_mipmap(ctx
, target
, texObj
, level
);
2930 ctx
->NewState
|= _NEW_TEXTURE
;
2934 _mesa_unlock_texture(ctx
, texObj
);
2939 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2940 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2942 GET_CURRENT_CONTEXT(ctx
);
2943 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
2949 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2950 GLint xoffset
, GLint yoffset
,
2951 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2953 GET_CURRENT_CONTEXT(ctx
);
2954 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
2961 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2962 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2963 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2965 GET_CURRENT_CONTEXT(ctx
);
2966 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2967 x
, y
, width
, height
);
2973 /**********************************************************************/
2974 /****** Compressed Textures ******/
2975 /**********************************************************************/
2979 * Return expected size of a compressed texture.
2982 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2985 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2986 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2991 * Return compressed texture block size, in pixels.
2994 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
2996 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2997 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3002 * Error checking for glCompressedTexImage[123]D().
3003 * \param reason returns reason for error, if any
3004 * \return error code or GL_NO_ERROR.
3007 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3008 GLenum target
, GLint level
,
3009 GLenum internalFormat
, GLsizei width
,
3010 GLsizei height
, GLsizei depth
, GLint border
,
3011 GLsizei imageSize
, char **reason
)
3013 const GLenum proxyTarget
= get_proxy_target(target
);
3014 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3017 *reason
= ""; /* no error */
3020 if (level
< 0 || level
>= maxLevels
) {
3022 return GL_INVALID_VALUE
;
3025 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3027 return GL_INVALID_ENUM
;
3030 /* This will detect any invalid internalFormat value */
3031 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3032 *reason
= "internalFormat";
3033 return GL_INVALID_ENUM
;
3036 /* This should really never fail */
3037 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3038 *reason
= "internalFormat";
3039 return GL_INVALID_ENUM
;
3042 /* No compressed formats support borders at this time */
3044 *reason
= "border != 0";
3045 return GL_INVALID_VALUE
;
3048 /* For cube map, width must equal height */
3049 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3050 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
) {
3051 *reason
= "width != height";
3052 return GL_INVALID_VALUE
;
3055 /* check image size against compression block size */
3057 gl_format texFormat
=
3058 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3062 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3063 if ((width
> bw
&& width
% bw
> 0) ||
3064 (height
> bh
&& height
% bh
> 0)) {
3066 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3067 * generated [...] if any parameter combinations are not
3068 * supported by the specific compressed internal format.
3070 *reason
= "invalid width or height for compression format";
3071 return GL_INVALID_OPERATION
;
3075 /* check image sizes */
3076 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3077 internalFormat
, GL_NONE
, GL_NONE
,
3078 width
, height
, depth
, border
)) {
3079 /* See error comment above */
3080 *reason
= "invalid width, height or format";
3081 return GL_INVALID_OPERATION
;
3084 /* check image size in bytes */
3085 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3086 if (expectedSize
!= imageSize
) {
3087 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3088 * if <imageSize> is not consistent with the format, dimensions, and
3089 * contents of the specified image.
3091 *reason
= "imageSize inconsistant with width/height/format";
3092 return GL_INVALID_VALUE
;
3100 * Error checking for glCompressedTexSubImage[123]D().
3101 * \warning There are some bad assumptions here about the size of compressed
3102 * texture tiles (multiple of 4) used to test the validity of the
3103 * offset and size parameters.
3104 * \return error code or GL_NO_ERROR.
3107 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3108 GLenum target
, GLint level
,
3109 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3110 GLsizei width
, GLsizei height
, GLsizei depth
,
3111 GLenum format
, GLsizei imageSize
)
3113 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3117 if (dimensions
== 1) {
3118 /* 1D compressed textures not allowed */
3119 return GL_INVALID_ENUM
;
3121 else if (dimensions
== 2) {
3122 if (target
== GL_PROXY_TEXTURE_2D
) {
3123 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3125 else if (target
== GL_TEXTURE_2D
) {
3126 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3128 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3129 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3130 return GL_INVALID_ENUM
; /*target*/
3131 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3133 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3134 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3135 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3136 return GL_INVALID_ENUM
; /*target*/
3137 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3140 return GL_INVALID_ENUM
; /*target*/
3143 else if (dimensions
== 3) {
3144 /* 3D compressed textures not allowed */
3145 return GL_INVALID_ENUM
;
3148 maxTextureSize
= 1 << (maxLevels
- 1);
3150 /* this will catch any invalid compressed format token */
3151 if (!_mesa_is_compressed_format(ctx
, format
))
3152 return GL_INVALID_ENUM
;
3154 if (width
< 1 || width
> maxTextureSize
)
3155 return GL_INVALID_VALUE
;
3157 if ((height
< 1 || height
> maxTextureSize
)
3159 return GL_INVALID_VALUE
;
3161 if (level
< 0 || level
>= maxLevels
)
3162 return GL_INVALID_VALUE
;
3165 * do checks which depend on compression block size
3167 get_compressed_block_size(format
, &bw
, &bh
);
3169 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3170 return GL_INVALID_VALUE
;
3172 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3173 return GL_INVALID_VALUE
;
3175 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3176 return GL_INVALID_VALUE
;
3178 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3179 if (expectedSize
!= imageSize
)
3180 return GL_INVALID_VALUE
;
3187 * Do second part of glCompressedTexSubImage error checking.
3188 * \return GL_TRUE if error found, GL_FALSE otherwise.
3191 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3192 GLsizei width
, GLsizei height
,
3193 GLsizei depth
, GLenum format
,
3194 struct gl_texture_image
*texImage
)
3197 if ((GLint
) format
!= texImage
->InternalFormat
) {
3198 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3199 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3203 if (((width
== 1 || width
== 2) &&
3204 width
!= (GLsizei
) texImage
->Width
) ||
3205 (width
> (GLsizei
) texImage
->Width
)) {
3206 _mesa_error(ctx
, GL_INVALID_VALUE
,
3207 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3212 if (((height
== 1 || height
== 2) &&
3213 height
!= (GLsizei
) texImage
->Height
) ||
3214 (height
> (GLsizei
) texImage
->Height
)) {
3215 _mesa_error(ctx
, GL_INVALID_VALUE
,
3216 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3222 if (((depth
== 1 || depth
== 2) &&
3223 depth
!= (GLsizei
) texImage
->Depth
) ||
3224 (depth
> (GLsizei
) texImage
->Depth
)) {
3225 _mesa_error(ctx
, GL_INVALID_VALUE
,
3226 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3236 * Implementation of the glCompressedTexImage1/2/3D() functions.
3239 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3240 GLenum target
, GLint level
,
3241 GLenum internalFormat
, GLsizei width
,
3242 GLsizei height
, GLsizei depth
, GLint border
,
3243 GLsizei imageSize
, const GLvoid
*data
)
3248 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3250 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3252 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3254 _mesa_lookup_enum_by_nr(target
), level
,
3255 _mesa_lookup_enum_by_nr(internalFormat
),
3256 width
, height
, depth
, border
, imageSize
, data
);
3259 if (!legal_teximage_target(ctx
, dims
, target
)) {
3260 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3261 dims
, _mesa_lookup_enum_by_nr(target
));
3265 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3266 internalFormat
, width
, height
, depth
,
3267 border
, imageSize
, &reason
);
3270 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3275 /* XXX this is kind of a hack */
3277 switch (internalFormat
) {
3278 case GL_PALETTE4_RGB8_OES
:
3279 case GL_PALETTE4_RGBA8_OES
:
3280 case GL_PALETTE4_R5_G6_B5_OES
:
3281 case GL_PALETTE4_RGBA4_OES
:
3282 case GL_PALETTE4_RGB5_A1_OES
:
3283 case GL_PALETTE8_RGB8_OES
:
3284 case GL_PALETTE8_RGBA8_OES
:
3285 case GL_PALETTE8_R5_G6_B5_OES
:
3286 case GL_PALETTE8_RGBA4_OES
:
3287 case GL_PALETTE8_RGB5_A1_OES
:
3288 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3289 width
, height
, imageSize
, data
);
3295 if (_mesa_is_proxy_texture(target
)) {
3296 /* Proxy texture: just check for errors and update proxy state */
3297 struct gl_texture_image
*texImage
;
3300 struct gl_texture_object
*texObj
=
3301 _mesa_get_current_tex_object(ctx
, target
);
3302 gl_format texFormat
=
3303 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3304 internalFormat
, GL_NONE
, GL_NONE
);
3305 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3306 error
= GL_OUT_OF_MEMORY
;
3310 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3313 /* if error, clear all proxy texture image parameters */
3314 clear_teximage_fields(texImage
);
3317 /* no error: store the teximage parameters */
3318 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3319 depth
, border
, internalFormat
,
3325 /* non-proxy target */
3326 struct gl_texture_object
*texObj
;
3327 struct gl_texture_image
*texImage
;
3330 _mesa_error(ctx
, error
, "glCompressedTexImage%uD", dims
);
3334 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3336 _mesa_lock_texture(ctx
, texObj
);
3338 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3340 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3341 "glCompressedTexImage%uD", dims
);
3344 gl_format texFormat
;
3346 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3347 ASSERT(texImage
->Data
== NULL
);
3349 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3350 internalFormat
, GL_NONE
,
3353 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3354 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3355 width
, height
, depth
,
3356 border
, internalFormat
, texFormat
);
3360 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3361 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3364 border
, imageSize
, data
,
3368 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3369 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3372 border
, imageSize
, data
,
3376 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3377 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3379 width
, height
, depth
,
3380 border
, imageSize
, data
,
3384 _mesa_problem(ctx
, "bad dims in compressedteximage");
3387 check_gen_mipmap(ctx
, target
, texObj
, level
);
3390 texObj
->_Complete
= GL_FALSE
;
3391 ctx
->NewState
|= _NEW_TEXTURE
;
3394 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3395 "glCompressedTexImage%uD", dims
);
3399 _mesa_unlock_texture(ctx
, texObj
);
3405 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3406 GLenum internalFormat
, GLsizei width
,
3407 GLint border
, GLsizei imageSize
,
3410 GET_CURRENT_CONTEXT(ctx
);
3411 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3412 width
, 1, 1, border
, imageSize
, data
);
3417 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3418 GLenum internalFormat
, GLsizei width
,
3419 GLsizei height
, GLint border
, GLsizei imageSize
,
3422 GET_CURRENT_CONTEXT(ctx
);
3423 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3424 width
, height
, 1, border
, imageSize
, data
);
3429 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3430 GLenum internalFormat
, GLsizei width
,
3431 GLsizei height
, GLsizei depth
, GLint border
,
3432 GLsizei imageSize
, const GLvoid
*data
)
3434 GET_CURRENT_CONTEXT(ctx
);
3435 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3436 width
, height
, depth
, border
, imageSize
, data
);
3441 * Common helper for glCompressedTexSubImage1/2/3D().
3444 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3445 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3446 GLsizei width
, GLsizei height
, GLsizei depth
,
3447 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3449 struct gl_texture_object
*texObj
;
3450 struct gl_texture_image
*texImage
;
3452 GET_CURRENT_CONTEXT(ctx
);
3453 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3455 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3456 xoffset
, 0, 0, /* pos */
3457 width
, height
, depth
, /* size */
3460 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3464 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3466 _mesa_lock_texture(ctx
, texObj
);
3468 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3471 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3472 format
, texImage
)) {
3473 /* error was recorded */
3475 else if (width
> 0 && height
> 0 && depth
> 0) {
3478 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3479 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3481 format
, imageSize
, data
,
3486 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3487 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3490 format
, imageSize
, data
,
3495 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3496 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3497 xoffset
, yoffset
, zoffset
,
3498 width
, height
, depth
,
3499 format
, imageSize
, data
,
3507 check_gen_mipmap(ctx
, target
, texObj
, level
);
3509 ctx
->NewState
|= _NEW_TEXTURE
;
3512 _mesa_unlock_texture(ctx
, texObj
);
3517 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3518 GLsizei width
, GLenum format
,
3519 GLsizei imageSize
, const GLvoid
*data
)
3521 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3522 format
, imageSize
, data
);
3527 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3528 GLint yoffset
, GLsizei width
, GLsizei height
,
3529 GLenum format
, GLsizei imageSize
,
3532 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3533 width
, height
, 1, format
, imageSize
, data
);
3538 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3539 GLint yoffset
, GLint zoffset
, GLsizei width
,
3540 GLsizei height
, GLsizei depth
, GLenum format
,
3541 GLsizei imageSize
, const GLvoid
*data
)
3543 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3544 width
, height
, depth
, format
, imageSize
, data
);
3549 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3550 * return the basic data type and number of components for the format.
3551 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3554 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3555 GLenum
*datatype
, GLuint
*components
)
3557 switch (internalFormat
) {
3559 *datatype
= GL_UNSIGNED_BYTE
;
3563 *datatype
= GL_UNSIGNED_SHORT
;
3566 case GL_ALPHA16F_ARB
:
3567 *datatype
= GL_HALF_FLOAT
;
3570 case GL_ALPHA32F_ARB
:
3571 *datatype
= GL_FLOAT
;
3574 case GL_ALPHA8I_EXT
:
3575 *datatype
= GL_BYTE
;
3578 case GL_ALPHA16I_EXT
:
3579 *datatype
= GL_SHORT
;
3582 case GL_ALPHA32I_EXT
:
3586 case GL_ALPHA8UI_EXT
:
3587 *datatype
= GL_UNSIGNED_BYTE
;
3590 case GL_ALPHA16UI_EXT
:
3591 *datatype
= GL_UNSIGNED_SHORT
;
3594 case GL_ALPHA32UI_EXT
:
3595 *datatype
= GL_UNSIGNED_INT
;
3599 *datatype
= GL_UNSIGNED_BYTE
;
3602 case GL_LUMINANCE16
:
3603 *datatype
= GL_UNSIGNED_SHORT
;
3606 case GL_LUMINANCE16F_ARB
:
3607 *datatype
= GL_HALF_FLOAT
;
3610 case GL_LUMINANCE32F_ARB
:
3611 *datatype
= GL_FLOAT
;
3614 case GL_LUMINANCE8I_EXT
:
3615 *datatype
= GL_BYTE
;
3618 case GL_LUMINANCE16I_EXT
:
3619 *datatype
= GL_SHORT
;
3622 case GL_LUMINANCE32I_EXT
:
3626 case GL_LUMINANCE8UI_EXT
:
3627 *datatype
= GL_UNSIGNED_BYTE
;
3630 case GL_LUMINANCE16UI_EXT
:
3631 *datatype
= GL_UNSIGNED_SHORT
;
3634 case GL_LUMINANCE32UI_EXT
:
3635 *datatype
= GL_UNSIGNED_INT
;
3638 case GL_LUMINANCE8_ALPHA8
:
3639 *datatype
= GL_UNSIGNED_BYTE
;
3642 case GL_LUMINANCE16_ALPHA16
:
3643 *datatype
= GL_UNSIGNED_SHORT
;
3646 case GL_LUMINANCE_ALPHA16F_ARB
:
3647 *datatype
= GL_HALF_FLOAT
;
3650 case GL_LUMINANCE_ALPHA32F_ARB
:
3651 *datatype
= GL_FLOAT
;
3654 case GL_LUMINANCE_ALPHA8I_EXT
:
3655 *datatype
= GL_BYTE
;
3658 case GL_LUMINANCE_ALPHA16I_EXT
:
3659 *datatype
= GL_SHORT
;
3662 case GL_LUMINANCE_ALPHA32I_EXT
:
3666 case GL_LUMINANCE_ALPHA8UI_EXT
:
3667 *datatype
= GL_UNSIGNED_BYTE
;
3670 case GL_LUMINANCE_ALPHA16UI_EXT
:
3671 *datatype
= GL_UNSIGNED_SHORT
;
3674 case GL_LUMINANCE_ALPHA32UI_EXT
:
3675 *datatype
= GL_UNSIGNED_INT
;
3679 *datatype
= GL_UNSIGNED_BYTE
;
3682 case GL_INTENSITY16
:
3683 *datatype
= GL_UNSIGNED_SHORT
;
3686 case GL_INTENSITY16F_ARB
:
3687 *datatype
= GL_HALF_FLOAT
;
3690 case GL_INTENSITY32F_ARB
:
3691 *datatype
= GL_FLOAT
;
3694 case GL_INTENSITY8I_EXT
:
3695 *datatype
= GL_BYTE
;
3698 case GL_INTENSITY16I_EXT
:
3699 *datatype
= GL_SHORT
;
3702 case GL_INTENSITY32I_EXT
:
3706 case GL_INTENSITY8UI_EXT
:
3707 *datatype
= GL_UNSIGNED_BYTE
;
3710 case GL_INTENSITY16UI_EXT
:
3711 *datatype
= GL_UNSIGNED_SHORT
;
3714 case GL_INTENSITY32UI_EXT
:
3715 *datatype
= GL_UNSIGNED_INT
;
3719 *datatype
= GL_UNSIGNED_BYTE
;
3723 *datatype
= GL_UNSIGNED_SHORT
;
3726 case GL_RGBA16F_ARB
:
3727 *datatype
= GL_HALF_FLOAT
;
3730 case GL_RGBA32F_ARB
:
3731 *datatype
= GL_FLOAT
;
3735 *datatype
= GL_BYTE
;
3738 case GL_RGBA16I_EXT
:
3739 *datatype
= GL_SHORT
;
3742 case GL_RGBA32I_EXT
:
3746 case GL_RGBA8UI_EXT
:
3747 *datatype
= GL_UNSIGNED_BYTE
;
3750 case GL_RGBA16UI_EXT
:
3751 *datatype
= GL_UNSIGNED_SHORT
;
3754 case GL_RGBA32UI_EXT
:
3755 *datatype
= GL_UNSIGNED_INT
;
3762 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3765 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3772 /** GL_ARB_texture_buffer_object */
3774 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3776 struct gl_texture_object
*texObj
;
3777 struct gl_buffer_object
*bufObj
;
3781 GET_CURRENT_CONTEXT(ctx
);
3782 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3784 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3785 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3789 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3790 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3794 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3795 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3800 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3801 if (buffer
&& !bufObj
) {
3802 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3806 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3808 _mesa_lock_texture(ctx
, texObj
);
3810 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3811 texObj
->BufferObjectFormat
= internalFormat
;
3813 _mesa_unlock_texture(ctx
, texObj
);