2 * mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
43 #include "mfeatures.h"
45 #include "texcompress.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
63 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
67 _mesa_alloc_texmemory(GLsizei bytes
)
69 return _mesa_align_malloc(bytes
, 512);
74 * Free texture memory allocated with _mesa_alloc_texmemory()
77 _mesa_free_texmemory(void *m
)
84 * Compute floor(log_base_2(n)).
114 * Return the simple base format for a given internal texture format.
115 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
117 * \param ctx GL context.
118 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
120 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
121 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
123 * This is the format which is used during texture application (i.e. the
124 * texture format and env mode determine the arithmetic used.
126 * XXX this could be static
129 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
131 switch (internalFormat
) {
146 case GL_LUMINANCE_ALPHA
:
147 case GL_LUMINANCE4_ALPHA4
:
148 case GL_LUMINANCE6_ALPHA2
:
149 case GL_LUMINANCE8_ALPHA8
:
150 case GL_LUMINANCE12_ALPHA4
:
151 case GL_LUMINANCE12_ALPHA12
:
152 case GL_LUMINANCE16_ALPHA16
:
153 return GL_LUMINANCE_ALPHA
;
184 if (ctx
->Extensions
.EXT_texture_format_BGRA8888
) {
185 switch (internalFormat
) {
193 if (ctx
->Extensions
.EXT_paletted_texture
) {
194 switch (internalFormat
) {
196 case GL_COLOR_INDEX1_EXT
:
197 case GL_COLOR_INDEX2_EXT
:
198 case GL_COLOR_INDEX4_EXT
:
199 case GL_COLOR_INDEX8_EXT
:
200 case GL_COLOR_INDEX12_EXT
:
201 case GL_COLOR_INDEX16_EXT
:
202 return GL_COLOR_INDEX
;
208 if (ctx
->Extensions
.ARB_depth_texture
) {
209 switch (internalFormat
) {
210 case GL_DEPTH_COMPONENT
:
211 case GL_DEPTH_COMPONENT16
:
212 case GL_DEPTH_COMPONENT24
:
213 case GL_DEPTH_COMPONENT32
:
214 return GL_DEPTH_COMPONENT
;
220 switch (internalFormat
) {
221 case GL_COMPRESSED_ALPHA
:
223 case GL_COMPRESSED_LUMINANCE
:
225 case GL_COMPRESSED_LUMINANCE_ALPHA
:
226 return GL_LUMINANCE_ALPHA
;
227 case GL_COMPRESSED_INTENSITY
:
229 case GL_COMPRESSED_RGB
:
231 case GL_COMPRESSED_RGBA
:
237 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
238 switch (internalFormat
) {
239 case GL_COMPRESSED_RGB_FXT1_3DFX
:
241 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
248 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
249 switch (internalFormat
) {
250 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
252 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
253 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
254 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
261 if (ctx
->Extensions
.S3_s3tc
) {
262 switch (internalFormat
) {
274 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
275 if (internalFormat
== GL_YCBCR_MESA
)
276 return GL_YCBCR_MESA
;
279 if (ctx
->Extensions
.ARB_texture_float
) {
280 switch (internalFormat
) {
281 case GL_ALPHA16F_ARB
:
282 case GL_ALPHA32F_ARB
:
290 case GL_INTENSITY16F_ARB
:
291 case GL_INTENSITY32F_ARB
:
293 case GL_LUMINANCE16F_ARB
:
294 case GL_LUMINANCE32F_ARB
:
296 case GL_LUMINANCE_ALPHA16F_ARB
:
297 case GL_LUMINANCE_ALPHA32F_ARB
:
298 return GL_LUMINANCE_ALPHA
;
304 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
305 switch (internalFormat
) {
314 if (ctx
->Extensions
.EXT_texture_snorm
) {
315 switch (internalFormat
) {
330 case GL_RGBA16_SNORM
:
333 case GL_ALPHA8_SNORM
:
334 case GL_ALPHA16_SNORM
:
336 case GL_LUMINANCE_SNORM
:
337 case GL_LUMINANCE8_SNORM
:
338 case GL_LUMINANCE16_SNORM
:
340 case GL_LUMINANCE_ALPHA_SNORM
:
341 case GL_LUMINANCE8_ALPHA8_SNORM
:
342 case GL_LUMINANCE16_ALPHA16_SNORM
:
343 return GL_LUMINANCE_ALPHA
;
344 case GL_INTENSITY_SNORM
:
345 case GL_INTENSITY8_SNORM
:
346 case GL_INTENSITY16_SNORM
:
353 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
354 switch (internalFormat
) {
355 case GL_DEPTH_STENCIL_EXT
:
356 case GL_DEPTH24_STENCIL8_EXT
:
357 return GL_DEPTH_STENCIL_EXT
;
363 #if FEATURE_EXT_texture_sRGB
364 if (ctx
->Extensions
.EXT_texture_sRGB
) {
365 switch (internalFormat
) {
368 case GL_COMPRESSED_SRGB_EXT
:
369 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
371 case GL_SRGB_ALPHA_EXT
:
372 case GL_SRGB8_ALPHA8_EXT
:
373 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
374 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
375 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
376 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
378 case GL_SLUMINANCE_ALPHA_EXT
:
379 case GL_SLUMINANCE8_ALPHA8_EXT
:
380 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
381 return GL_LUMINANCE_ALPHA
;
382 case GL_SLUMINANCE_EXT
:
383 case GL_SLUMINANCE8_EXT
:
384 case GL_COMPRESSED_SLUMINANCE_EXT
:
390 #endif /* FEATURE_EXT_texture_sRGB */
392 if (ctx
->Extensions
.EXT_texture_integer
) {
393 switch (internalFormat
) {
395 case GL_RGBA16UI_EXT
:
396 case GL_RGBA32UI_EXT
:
408 case GL_ALPHA8UI_EXT
:
409 case GL_ALPHA16UI_EXT
:
410 case GL_ALPHA32UI_EXT
:
412 case GL_ALPHA16I_EXT
:
413 case GL_ALPHA32I_EXT
:
415 case GL_INTENSITY8UI_EXT
:
416 case GL_INTENSITY16UI_EXT
:
417 case GL_INTENSITY32UI_EXT
:
418 case GL_INTENSITY8I_EXT
:
419 case GL_INTENSITY16I_EXT
:
420 case GL_INTENSITY32I_EXT
:
422 case GL_LUMINANCE8UI_EXT
:
423 case GL_LUMINANCE16UI_EXT
:
424 case GL_LUMINANCE32UI_EXT
:
425 case GL_LUMINANCE8I_EXT
:
426 case GL_LUMINANCE16I_EXT
:
427 case GL_LUMINANCE32I_EXT
:
429 case GL_LUMINANCE_ALPHA8UI_EXT
:
430 case GL_LUMINANCE_ALPHA16UI_EXT
:
431 case GL_LUMINANCE_ALPHA32UI_EXT
:
432 case GL_LUMINANCE_ALPHA8I_EXT
:
433 case GL_LUMINANCE_ALPHA16I_EXT
:
434 case GL_LUMINANCE_ALPHA32I_EXT
:
435 return GL_LUMINANCE_ALPHA
;
441 if (ctx
->Extensions
.ARB_texture_rg
) {
442 switch (internalFormat
) {
444 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
446 if (!ctx
->Extensions
.ARB_half_float_pixel
)
450 if (!ctx
->Extensions
.ARB_texture_float
)
459 if (!ctx
->Extensions
.EXT_texture_integer
)
465 case GL_COMPRESSED_RED
:
469 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
471 if (!ctx
->Extensions
.ARB_half_float_pixel
)
475 if (!ctx
->Extensions
.ARB_texture_float
)
484 if (!ctx
->Extensions
.EXT_texture_integer
)
490 case GL_COMPRESSED_RG
:
497 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
498 switch (internalFormat
) {
506 if (ctx
->Extensions
.EXT_packed_float
) {
507 switch (internalFormat
) {
508 case GL_R11F_G11F_B10F_EXT
:
515 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
516 switch (internalFormat
) {
517 case GL_DEPTH_COMPONENT32F
:
518 return GL_DEPTH_COMPONENT
;
519 case GL_DEPTH32F_STENCIL8
:
520 return GL_DEPTH_STENCIL
;
526 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
527 switch (internalFormat
) {
528 case GL_COMPRESSED_RED_RGTC1
:
529 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
531 case GL_COMPRESSED_RG_RGTC2
:
532 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
539 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
540 switch (internalFormat
) {
541 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
542 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
544 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
545 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
546 return GL_LUMINANCE_ALPHA
;
552 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
553 switch (internalFormat
) {
554 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
555 return GL_LUMINANCE_ALPHA
;
561 return -1; /* error */
566 * For cube map faces, return a face index in [0,5].
567 * For other targets return 0;
570 _mesa_tex_target_to_face(GLenum target
)
572 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
573 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
574 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
582 * Store a gl_texture_image pointer in a gl_texture_object structure
583 * according to the target and level parameters.
585 * \param tObj texture object.
586 * \param target texture target.
587 * \param level image level.
588 * \param texImage texture image.
590 * This was basically prompted by the introduction of cube maps.
593 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
594 GLenum target
, GLint level
,
595 struct gl_texture_image
*texImage
)
597 const GLuint face
= _mesa_tex_target_to_face(target
);
601 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
603 tObj
->Image
[face
][level
] = texImage
;
605 /* Set the 'back' pointer */
606 texImage
->TexObject
= tObj
;
611 * Allocate a texture image structure.
613 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
616 * \return a pointer to gl_texture_image struct with all fields initialized to
619 struct gl_texture_image
*
620 _mesa_new_texture_image( struct gl_context
*ctx
)
623 return CALLOC_STRUCT(gl_texture_image
);
628 * Free texture image data.
629 * This function is a fallback called via ctx->Driver.FreeTexImageData().
631 * \param texImage texture image.
633 * Free the texture image data if it's not marked as client data.
636 _mesa_free_texture_image_data(struct gl_context
*ctx
,
637 struct gl_texture_image
*texImage
)
641 if (texImage
->Data
&& !texImage
->IsClientData
) {
642 /* free the old texture data */
643 _mesa_free_texmemory(texImage
->Data
);
646 texImage
->Data
= NULL
;
651 * Free texture image.
653 * \param texImage texture image.
655 * Free the texture image structure and the associated image data.
658 _mesa_delete_texture_image(struct gl_context
*ctx
,
659 struct gl_texture_image
*texImage
)
661 /* Free texImage->Data and/or any other driver-specific texture
664 ASSERT(ctx
->Driver
.FreeTexImageData
);
665 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
667 ASSERT(texImage
->Data
== NULL
);
668 if (texImage
->ImageOffsets
)
669 free(texImage
->ImageOffsets
);
675 * Test if a target is a proxy target.
677 * \param target texture target.
679 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
682 _mesa_is_proxy_texture(GLenum target
)
684 /* NUM_TEXTURE_TARGETS should match number of terms below,
685 * except there's no proxy for GL_TEXTURE_BUFFER.
687 assert(NUM_TEXTURE_TARGETS
== 8);
689 return (target
== GL_PROXY_TEXTURE_1D
||
690 target
== GL_PROXY_TEXTURE_2D
||
691 target
== GL_PROXY_TEXTURE_3D
||
692 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
693 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
694 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
695 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
700 * Return the proxy target which corresponds to the given texture target
703 get_proxy_target(GLenum target
)
707 case GL_PROXY_TEXTURE_1D
:
708 return GL_PROXY_TEXTURE_1D
;
710 case GL_PROXY_TEXTURE_2D
:
711 return GL_PROXY_TEXTURE_2D
;
713 case GL_PROXY_TEXTURE_3D
:
714 return GL_PROXY_TEXTURE_3D
;
715 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
716 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
717 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
718 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
719 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
720 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
721 case GL_TEXTURE_CUBE_MAP_ARB
:
722 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
723 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
724 case GL_TEXTURE_RECTANGLE_NV
:
725 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
726 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
727 case GL_TEXTURE_1D_ARRAY_EXT
:
728 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
729 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
730 case GL_TEXTURE_2D_ARRAY_EXT
:
731 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
732 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
734 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
741 * Get the texture object that corresponds to the target of the given
744 * \param ctx GL context.
745 * \param texUnit texture unit.
746 * \param target texture target.
748 * \return pointer to the texture object on success, or NULL on failure.
750 * \sa gl_texture_unit.
752 struct gl_texture_object
*
753 _mesa_select_tex_object(struct gl_context
*ctx
,
754 const struct gl_texture_unit
*texUnit
,
757 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
758 ctx
->Extensions
.EXT_texture_array
);
762 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
763 case GL_PROXY_TEXTURE_1D
:
764 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
766 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
767 case GL_PROXY_TEXTURE_2D
:
768 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
770 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
771 case GL_PROXY_TEXTURE_3D
:
772 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
773 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
774 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
775 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
776 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
777 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
778 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
779 case GL_TEXTURE_CUBE_MAP_ARB
:
780 return ctx
->Extensions
.ARB_texture_cube_map
781 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
782 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
783 return ctx
->Extensions
.ARB_texture_cube_map
784 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
785 case GL_TEXTURE_RECTANGLE_NV
:
786 return ctx
->Extensions
.NV_texture_rectangle
787 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
788 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
789 return ctx
->Extensions
.NV_texture_rectangle
790 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
791 case GL_TEXTURE_1D_ARRAY_EXT
:
792 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
793 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
794 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
795 case GL_TEXTURE_2D_ARRAY_EXT
:
796 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
797 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
798 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
799 case GL_TEXTURE_BUFFER
:
800 return ctx
->Extensions
.ARB_texture_buffer_object
801 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
803 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
810 * Return pointer to texture object for given target on current texture unit.
812 struct gl_texture_object
*
813 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
815 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
816 return _mesa_select_tex_object(ctx
, texUnit
, target
);
821 * Get a texture image pointer from a texture object, given a texture
822 * target and mipmap level. The target and level parameters should
823 * have already been error-checked.
825 * \param ctx GL context.
826 * \param texObj texture unit.
827 * \param target texture target.
828 * \param level image level.
830 * \return pointer to the texture image structure, or NULL on failure.
832 struct gl_texture_image
*
833 _mesa_select_tex_image(struct gl_context
*ctx
,
834 const struct gl_texture_object
*texObj
,
835 GLenum target
, GLint level
)
837 const GLuint face
= _mesa_tex_target_to_face(target
);
841 ASSERT(level
< MAX_TEXTURE_LEVELS
);
843 return texObj
->Image
[face
][level
];
848 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
849 * it and install it. Only return NULL if passed a bad parameter or run
852 struct gl_texture_image
*
853 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
854 GLenum target
, GLint level
)
856 struct gl_texture_image
*texImage
;
861 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
863 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
865 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
869 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
877 * Return pointer to the specified proxy texture image.
878 * Note that proxy textures are per-context, not per-texture unit.
879 * \return pointer to texture image or NULL if invalid target, invalid
880 * level, or out of memory.
882 struct gl_texture_image
*
883 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
885 struct gl_texture_image
*texImage
;
892 case GL_PROXY_TEXTURE_1D
:
893 if (level
>= ctx
->Const
.MaxTextureLevels
)
895 texIndex
= TEXTURE_1D_INDEX
;
897 case GL_PROXY_TEXTURE_2D
:
898 if (level
>= ctx
->Const
.MaxTextureLevels
)
900 texIndex
= TEXTURE_2D_INDEX
;
902 case GL_PROXY_TEXTURE_3D
:
903 if (level
>= ctx
->Const
.Max3DTextureLevels
)
905 texIndex
= TEXTURE_3D_INDEX
;
907 case GL_PROXY_TEXTURE_CUBE_MAP
:
908 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
910 texIndex
= TEXTURE_CUBE_INDEX
;
912 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
915 texIndex
= TEXTURE_RECT_INDEX
;
917 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
918 if (level
>= ctx
->Const
.MaxTextureLevels
)
920 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
922 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
923 if (level
>= ctx
->Const
.MaxTextureLevels
)
925 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
931 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
933 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
935 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
938 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
939 /* Set the 'back' pointer */
940 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
947 * Get the maximum number of allowed mipmap levels.
949 * \param ctx GL context.
950 * \param target texture target.
952 * \return the maximum number of allowed mipmap levels for the given
953 * texture target, or zero if passed a bad target.
958 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
962 case GL_PROXY_TEXTURE_1D
:
964 case GL_PROXY_TEXTURE_2D
:
965 return ctx
->Const
.MaxTextureLevels
;
967 case GL_PROXY_TEXTURE_3D
:
968 return ctx
->Const
.Max3DTextureLevels
;
969 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
970 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
971 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
972 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
973 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
974 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
975 case GL_TEXTURE_CUBE_MAP_ARB
:
976 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
977 return ctx
->Extensions
.ARB_texture_cube_map
978 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
979 case GL_TEXTURE_RECTANGLE_NV
:
980 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
981 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
982 case GL_TEXTURE_1D_ARRAY_EXT
:
983 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
984 case GL_TEXTURE_2D_ARRAY_EXT
:
985 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
986 return (ctx
->Extensions
.MESA_texture_array
||
987 ctx
->Extensions
.EXT_texture_array
)
988 ? ctx
->Const
.MaxTextureLevels
: 0;
989 case GL_TEXTURE_BUFFER
:
992 return 0; /* bad target */
998 * Return number of dimensions per mipmap level for the given texture target.
1001 _mesa_get_texture_dimensions(GLenum target
)
1005 case GL_PROXY_TEXTURE_1D
:
1008 case GL_TEXTURE_RECTANGLE
:
1009 case GL_TEXTURE_CUBE_MAP
:
1010 case GL_PROXY_TEXTURE_2D
:
1011 case GL_PROXY_TEXTURE_RECTANGLE
:
1012 case GL_PROXY_TEXTURE_CUBE_MAP
:
1013 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1014 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1015 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1016 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1017 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1018 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1019 case GL_TEXTURE_1D_ARRAY
:
1020 case GL_PROXY_TEXTURE_1D_ARRAY
:
1023 case GL_PROXY_TEXTURE_3D
:
1024 case GL_TEXTURE_2D_ARRAY
:
1025 case GL_PROXY_TEXTURE_2D_ARRAY
:
1027 case GL_TEXTURE_BUFFER
:
1030 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1039 #if 000 /* not used anymore */
1041 * glTexImage[123]D can accept a NULL image pointer. In this case we
1042 * create a texture image with unspecified image contents per the OpenGL
1046 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1048 const GLint components
= _mesa_components_in_format(format
);
1049 const GLint numPixels
= width
* height
* depth
;
1050 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1054 * Let's see if anyone finds this. If glTexImage2D() is called with
1055 * a NULL image pointer then load the texture image with something
1056 * interesting instead of leaving it indeterminate.
1059 static const char message
[8][32] = {
1060 " X X XXXXX XXX X ",
1061 " XX XX X X X X X ",
1063 " X X XXXX XXX XXXXX ",
1066 " X X XXXXX XXX X X ",
1070 GLubyte
*imgPtr
= data
;
1072 for (h
= 0; h
< depth
; h
++) {
1073 for (i
= 0; i
< height
; i
++) {
1074 GLint srcRow
= 7 - (i
% 8);
1075 for (j
= 0; j
< width
; j
++) {
1076 GLint srcCol
= j
% 32;
1077 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1078 for (k
= 0; k
< components
; k
++) {
1094 * Reset the fields of a gl_texture_image struct to zero.
1096 * \param img texture image structure.
1098 * This is called when a proxy texture test fails, we set all the
1099 * image members (except DriverData) to zero.
1100 * It's also used in glTexImage[123]D as a safeguard to be sure all
1101 * required fields get initialized properly by the Driver.TexImage[123]D
1105 clear_teximage_fields(struct gl_texture_image
*img
)
1108 img
->_BaseFormat
= 0;
1109 img
->InternalFormat
= 0;
1115 if (img
->ImageOffsets
) {
1116 free(img
->ImageOffsets
);
1117 img
->ImageOffsets
= NULL
;
1123 img
->HeightLog2
= 0;
1126 img
->TexFormat
= MESA_FORMAT_NONE
;
1127 img
->FetchTexelc
= NULL
;
1128 img
->FetchTexelf
= NULL
;
1133 * Initialize basic fields of the gl_texture_image struct.
1135 * \param ctx GL context.
1136 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1137 * \param img texture image structure to be initialized.
1138 * \param width image width.
1139 * \param height image height.
1140 * \param depth image depth.
1141 * \param border image border.
1142 * \param internalFormat internal format.
1143 * \param format the actual hardware format (one of MESA_FORMAT_*)
1145 * Fills in the fields of \p img with the given information.
1146 * Note: width, height and depth include the border.
1149 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1150 struct gl_texture_image
*img
,
1151 GLsizei width
, GLsizei height
, GLsizei depth
,
1152 GLint border
, GLenum internalFormat
,
1159 ASSERT(height
>= 0);
1162 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1163 ASSERT(img
->_BaseFormat
> 0);
1164 img
->InternalFormat
= internalFormat
;
1165 img
->Border
= border
;
1167 img
->Height
= height
;
1170 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1171 img
->WidthLog2
= logbase2(img
->Width2
);
1173 if (height
== 1) { /* 1-D texture */
1175 img
->HeightLog2
= 0;
1178 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1179 img
->HeightLog2
= logbase2(img
->Height2
);
1182 if (depth
== 1) { /* 2-D texture */
1187 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1188 img
->DepthLog2
= logbase2(img
->Depth2
);
1191 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1193 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1194 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1195 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1196 img
->_IsPowerOfTwo
= GL_TRUE
;
1198 img
->_IsPowerOfTwo
= GL_FALSE
;
1200 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1201 img
->RowStride
= width
;
1202 /* Allocate the ImageOffsets array and initialize to typical values.
1203 * We allocate the array for 1D/2D textures too in order to avoid special-
1204 * case code in the texstore routines.
1206 if (img
->ImageOffsets
)
1207 free(img
->ImageOffsets
);
1208 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1209 for (i
= 0; i
< depth
; i
++) {
1210 img
->ImageOffsets
[i
] = i
* width
* height
;
1213 /* Compute Width/Height/DepthScale for mipmap lod computation */
1214 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1215 /* scale = 1.0 since texture coords directly map to texels */
1216 img
->WidthScale
= 1.0;
1217 img
->HeightScale
= 1.0;
1218 img
->DepthScale
= 1.0;
1221 img
->WidthScale
= (GLfloat
) img
->Width
;
1222 img
->HeightScale
= (GLfloat
) img
->Height
;
1223 img
->DepthScale
= (GLfloat
) img
->Depth
;
1226 img
->TexFormat
= format
;
1228 dims
= _mesa_get_texture_dimensions(target
);
1230 _mesa_set_fetch_functions(img
, dims
);
1235 * Free and clear fields of the gl_texture_image struct.
1237 * \param ctx GL context.
1238 * \param texImage texture image structure to be cleared.
1240 * After the call, \p texImage will have no data associated with it. Its
1241 * fields are cleared so that its parent object will test incomplete.
1244 _mesa_clear_texture_image(struct gl_context
*ctx
,
1245 struct gl_texture_image
*texImage
)
1247 ctx
->Driver
.FreeTexImageData(ctx
, texImage
);
1248 clear_teximage_fields(texImage
);
1253 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1254 * level, width, height and depth against the ctx->Const limits for textures.
1256 * A hardware driver might override this function if, for example, the
1257 * max 3D texture size is 512x512x64 (i.e. not a cube).
1259 * Note that width, height, depth == 0 is not an error. However, a
1260 * texture with zero width/height/depth will be considered "incomplete"
1261 * and texturing will effectively be disabled.
1263 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1264 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1265 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1266 * \param level as passed to glTexImage
1267 * \param internalFormat as passed to glTexImage
1268 * \param format as passed to glTexImage
1269 * \param type as passed to glTexImage
1270 * \param width as passed to glTexImage
1271 * \param height as passed to glTexImage
1272 * \param depth as passed to glTexImage
1273 * \param border as passed to glTexImage
1274 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1277 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1278 GLint internalFormat
, GLenum format
, GLenum type
,
1279 GLint width
, GLint height
, GLint depth
, GLint border
)
1283 (void) internalFormat
;
1288 case GL_PROXY_TEXTURE_1D
:
1289 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1290 if (width
< 2 * border
|| width
> 2 + maxSize
)
1292 if (level
>= ctx
->Const
.MaxTextureLevels
)
1294 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1295 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1300 case GL_PROXY_TEXTURE_2D
:
1301 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1302 if (width
< 2 * border
|| width
> 2 + maxSize
)
1304 if (height
< 2 * border
|| height
> 2 + maxSize
)
1306 if (level
>= ctx
->Const
.MaxTextureLevels
)
1308 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1309 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1311 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1316 case GL_PROXY_TEXTURE_3D
:
1317 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1318 if (width
< 2 * border
|| width
> 2 + maxSize
)
1320 if (height
< 2 * border
|| height
> 2 + maxSize
)
1322 if (depth
< 2 * border
|| depth
> 2 + maxSize
)
1324 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1326 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1327 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1329 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1331 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1336 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1337 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1338 if (width
< 0 || width
> maxSize
)
1340 if (height
< 0 || height
> maxSize
)
1346 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1347 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1348 if (width
< 2 * border
|| width
> 2 + maxSize
)
1350 if (height
< 2 * border
|| height
> 2 + maxSize
)
1352 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1354 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1355 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1357 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1362 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1363 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1364 if (width
< 2 * border
|| width
> 2 + maxSize
)
1366 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1368 if (level
>= ctx
->Const
.MaxTextureLevels
)
1370 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1371 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1376 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1377 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1378 if (width
< 2 * border
|| width
> 2 + maxSize
)
1380 if (height
< 2 * border
|| height
> 2 + maxSize
)
1382 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1384 if (level
>= ctx
->Const
.MaxTextureLevels
)
1386 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1387 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1389 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1395 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1402 * Check if the memory used by the texture would exceed the driver's limit.
1403 * This lets us support a max 3D texture size of 8K (for example) but
1404 * prevents allocating a full 8K x 8K x 8K texture.
1405 * XXX this could be rolled into the proxy texture size test (above) but
1406 * we don't have the actual texture internal format at that point.
1409 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1410 GLint width
, GLint height
, GLint depth
)
1412 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1413 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1414 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1420 * Helper function to determine whether a target and specific compression
1421 * format are supported.
1424 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1427 (void) intFormat
; /* not used yet */
1431 case GL_PROXY_TEXTURE_2D
:
1432 return GL_TRUE
; /* true for any compressed format so far */
1433 case GL_PROXY_TEXTURE_CUBE_MAP
:
1434 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1435 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1436 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1437 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1438 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1439 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1440 return ctx
->Extensions
.ARB_texture_cube_map
;
1441 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1442 case GL_TEXTURE_2D_ARRAY_EXT
:
1443 return (ctx
->Extensions
.MESA_texture_array
||
1444 ctx
->Extensions
.EXT_texture_array
);
1452 * Check if the given texture target value is legal for a
1453 * glTexImage1/2/3D call.
1456 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1462 case GL_PROXY_TEXTURE_1D
:
1470 case GL_PROXY_TEXTURE_2D
:
1472 case GL_PROXY_TEXTURE_CUBE_MAP
:
1473 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1474 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1475 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1476 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1477 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1478 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1479 return ctx
->Extensions
.ARB_texture_cube_map
;
1480 case GL_TEXTURE_RECTANGLE_NV
:
1481 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1482 return ctx
->Extensions
.NV_texture_rectangle
;
1483 case GL_TEXTURE_1D_ARRAY_EXT
:
1484 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1485 return (ctx
->Extensions
.MESA_texture_array
||
1486 ctx
->Extensions
.EXT_texture_array
);
1493 case GL_PROXY_TEXTURE_3D
:
1495 case GL_TEXTURE_2D_ARRAY_EXT
:
1496 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1497 return (ctx
->Extensions
.MESA_texture_array
||
1498 ctx
->Extensions
.EXT_texture_array
);
1503 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1510 * Check if the given texture target value is legal for a
1511 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1512 * The difference compared to legal_teximage_target() above is that
1513 * proxy targets are not supported.
1516 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1520 return target
== GL_TEXTURE_1D
;
1525 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1526 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1527 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1528 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1529 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1530 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1531 return ctx
->Extensions
.ARB_texture_cube_map
;
1532 case GL_TEXTURE_RECTANGLE_NV
:
1533 return ctx
->Extensions
.NV_texture_rectangle
;
1534 case GL_TEXTURE_1D_ARRAY_EXT
:
1535 return (ctx
->Extensions
.MESA_texture_array
||
1536 ctx
->Extensions
.EXT_texture_array
);
1544 case GL_TEXTURE_2D_ARRAY_EXT
:
1545 return (ctx
->Extensions
.MESA_texture_array
||
1546 ctx
->Extensions
.EXT_texture_array
);
1551 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1559 * Test the glTexImage[123]D() parameters for errors.
1561 * \param ctx GL context.
1562 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1563 * \param target texture target given by the user.
1564 * \param level image level given by the user.
1565 * \param internalFormat internal format given by the user.
1566 * \param format pixel data format given by the user.
1567 * \param type pixel data type given by the user.
1568 * \param width image width given by the user.
1569 * \param height image height given by the user.
1570 * \param depth image depth given by the user.
1571 * \param border image border given by the user.
1573 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1575 * Verifies each of the parameters against the constants specified in
1576 * __struct gl_contextRec::Const and the supported extensions, and according
1577 * to the OpenGL specification.
1580 texture_error_check( struct gl_context
*ctx
,
1581 GLuint dimensions
, GLenum target
,
1582 GLint level
, GLint internalFormat
,
1583 GLenum format
, GLenum type
,
1584 GLint width
, GLint height
,
1585 GLint depth
, GLint border
)
1587 const GLenum proxyTarget
= get_proxy_target(target
);
1588 const GLboolean isProxy
= target
== proxyTarget
;
1589 GLboolean sizeOK
= GL_TRUE
;
1590 GLboolean colorFormat
, indexFormat
;
1592 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1593 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1595 _mesa_error(ctx
, GL_INVALID_VALUE
,
1596 "glTexImage%dD(level=%d)", dimensions
, level
);
1602 if (border
< 0 || border
> 1 ||
1603 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1604 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1606 _mesa_error(ctx
, GL_INVALID_VALUE
,
1607 "glTexImage%dD(border=%d)", dimensions
, border
);
1612 if (width
< 0 || height
< 0 || depth
< 0) {
1614 _mesa_error(ctx
, GL_INVALID_VALUE
,
1615 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1620 /* Do this simple check before calling the TestProxyTexImage() function */
1621 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1622 sizeOK
= (width
== height
);
1626 * Use the proxy texture driver hook to see if the size/level/etc are
1629 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1630 internalFormat
, format
,
1631 type
, width
, height
,
1635 _mesa_error(ctx
, GL_INVALID_VALUE
,
1636 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1637 dimensions
, level
, width
, height
, depth
);
1642 /* Check internalFormat */
1643 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1645 _mesa_error(ctx
, GL_INVALID_VALUE
,
1646 "glTexImage%dD(internalFormat=%s)",
1647 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1652 /* Check incoming image format and type */
1653 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1654 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1655 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1656 * GL_EXT_texture_integer extension, some combinations should generate
1657 * GL_INVALID_ENUM instead (grr!).
1660 GLenum error
= _mesa_is_integer_format(format
)
1661 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1662 _mesa_error(ctx
, error
,
1663 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1664 dimensions
, format
, type
);
1669 /* make sure internal format and format basically agree */
1670 colorFormat
= _mesa_is_color_format(format
);
1671 indexFormat
= _mesa_is_index_format(format
);
1672 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1673 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1674 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1675 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1676 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1677 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1679 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1680 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1681 dimensions
, internalFormat
, format
);
1685 /* additional checks for ycbcr textures */
1686 if (internalFormat
== GL_YCBCR_MESA
) {
1687 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1688 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1689 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1691 _mesa_snprintf(message
, sizeof(message
),
1692 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1693 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1694 return GL_TRUE
; /* error */
1696 if (target
!= GL_TEXTURE_2D
&&
1697 target
!= GL_PROXY_TEXTURE_2D
&&
1698 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1699 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1701 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1707 _mesa_snprintf(message
, sizeof(message
),
1708 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1709 dimensions
, border
);
1710 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1716 /* additional checks for depth textures */
1717 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1718 /* Only 1D, 2D and rectangular textures supported, not 3D or cubes */
1719 if (target
!= GL_TEXTURE_1D
&&
1720 target
!= GL_PROXY_TEXTURE_1D
&&
1721 target
!= GL_TEXTURE_2D
&&
1722 target
!= GL_PROXY_TEXTURE_2D
&&
1723 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1724 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1726 _mesa_error(ctx
, GL_INVALID_ENUM
,
1727 "glTexImage(target/internalFormat)");
1732 /* additional checks for compressed textures */
1733 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1734 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1736 _mesa_error(ctx
, GL_INVALID_ENUM
,
1737 "glTexImage%dD(target)", dimensions
);
1742 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1743 "glTexImage%dD(border!=0)", dimensions
);
1749 /* additional checks for integer textures */
1750 if (ctx
->Extensions
.EXT_texture_integer
&&
1751 (_mesa_is_integer_format(format
) !=
1752 _mesa_is_integer_format(internalFormat
))) {
1754 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1755 "glTexImage%dD(integer/non-integer format mismatch)",
1761 /* if we get here, the parameters are OK */
1767 * Test glTexSubImage[123]D() parameters for errors.
1769 * \param ctx GL context.
1770 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1771 * \param target texture target given by the user.
1772 * \param level image level given by the user.
1773 * \param xoffset sub-image x offset given by the user.
1774 * \param yoffset sub-image y offset given by the user.
1775 * \param zoffset sub-image z offset given by the user.
1776 * \param format pixel data format given by the user.
1777 * \param type pixel data type given by the user.
1778 * \param width image width given by the user.
1779 * \param height image height given by the user.
1780 * \param depth image depth given by the user.
1782 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1784 * Verifies each of the parameters against the constants specified in
1785 * __struct gl_contextRec::Const and the supported extensions, and according
1786 * to the OpenGL specification.
1789 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1790 GLenum target
, GLint level
,
1791 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1792 GLint width
, GLint height
, GLint depth
,
1793 GLenum format
, GLenum type
)
1795 /* Basic level check */
1796 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1797 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1801 /* Check for negative sizes */
1803 _mesa_error(ctx
, GL_INVALID_VALUE
,
1804 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1807 if (height
< 0 && dimensions
> 1) {
1808 _mesa_error(ctx
, GL_INVALID_VALUE
,
1809 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1812 if (depth
< 0 && dimensions
> 2) {
1813 _mesa_error(ctx
, GL_INVALID_VALUE
,
1814 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1818 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1819 /* As with the glTexImage2D check above, the error code here
1820 * depends on texture integer.
1822 GLenum error
= _mesa_is_integer_format(format
)
1823 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1824 _mesa_error(ctx
, error
,
1825 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1826 dimensions
, format
, type
);
1835 * Do second part of glTexSubImage which depends on the destination texture.
1836 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1839 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1840 GLenum target
, GLint level
,
1841 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1842 GLint width
, GLint height
, GLint depth
,
1843 GLenum format
, GLenum type
,
1844 const struct gl_texture_image
*destTex
)
1847 /* undefined image level */
1848 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1852 if (xoffset
< -((GLint
)destTex
->Border
)) {
1853 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1857 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1858 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1862 if (dimensions
> 1) {
1863 if (yoffset
< -((GLint
)destTex
->Border
)) {
1864 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1868 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1869 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1874 if (dimensions
> 2) {
1875 if (zoffset
< -((GLint
)destTex
->Border
)) {
1876 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1879 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1880 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1885 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1888 /* do tests which depend on compression block size */
1889 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1891 /* offset must be multiple of block size */
1892 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1893 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1894 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1895 dimensions
, xoffset
, yoffset
);
1898 /* size must be multiple of bw by bh or equal to whole texture size */
1899 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1900 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1901 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1904 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1905 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1906 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1916 * Test glCopyTexImage[12]D() parameters for errors.
1918 * \param ctx GL context.
1919 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1920 * \param target texture target given by the user.
1921 * \param level image level given by the user.
1922 * \param internalFormat internal format given by the user.
1923 * \param width image width given by the user.
1924 * \param height image height given by the user.
1925 * \param border texture border.
1927 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1929 * Verifies each of the parameters against the constants specified in
1930 * __struct gl_contextRec::Const and the supported extensions, and according
1931 * to the OpenGL specification.
1934 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1935 GLenum target
, GLint level
, GLint internalFormat
,
1936 GLint width
, GLint height
, GLint border
)
1938 const GLenum proxyTarget
= get_proxy_target(target
);
1939 const GLenum type
= GL_FLOAT
;
1944 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1945 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1946 dimensions
, _mesa_lookup_enum_by_nr(target
));
1950 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1951 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1952 _mesa_error(ctx
, GL_INVALID_VALUE
,
1953 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1957 /* Check that the source buffer is complete */
1958 if (ctx
->ReadBuffer
->Name
) {
1959 if (ctx
->ReadBuffer
->_Status
== 0) {
1960 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1962 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1963 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1964 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1970 if (border
< 0 || border
> 1 ||
1971 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1972 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1976 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1978 _mesa_error(ctx
, GL_INVALID_VALUE
,
1979 "glCopyTexImage%dD(internalFormat)", dimensions
);
1983 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1984 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1985 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1989 /* Do size, level checking */
1990 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1991 ? (width
== height
) : 1;
1993 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1994 internalFormat
, format
,
1995 type
, width
, height
,
1999 if (dimensions
== 1) {
2000 _mesa_error(ctx
, GL_INVALID_VALUE
,
2001 "glCopyTexImage1D(width=%d)", width
);
2004 ASSERT(dimensions
== 2);
2005 _mesa_error(ctx
, GL_INVALID_VALUE
,
2006 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2011 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2012 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2013 _mesa_error(ctx
, GL_INVALID_ENUM
,
2014 "glCopyTexImage%dD(target)", dimensions
);
2018 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2019 "glCopyTexImage%dD(border!=0)", dimensions
);
2023 else if (_mesa_is_depth_format(internalFormat
)) {
2024 /* make sure we have depth/stencil buffers */
2025 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2026 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2027 "glCopyTexImage%dD(no depth)", dimensions
);
2031 else if (_mesa_is_depthstencil_format(internalFormat
)) {
2032 /* make sure we have depth/stencil buffers */
2033 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2034 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2035 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
2040 /* if we get here, the parameters are OK */
2046 * Test glCopyTexSubImage[12]D() parameters for errors.
2047 * Note that this is the first part of error checking.
2048 * See also copytexsubimage_error_check2() below for the second part.
2050 * \param ctx GL context.
2051 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2052 * \param target texture target given by the user.
2053 * \param level image level given by the user.
2055 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2058 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2059 GLenum target
, GLint level
)
2061 /* Check that the source buffer is complete */
2062 if (ctx
->ReadBuffer
->Name
) {
2063 if (ctx
->ReadBuffer
->_Status
== 0) {
2064 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2066 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2067 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2068 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2073 /* check target (proxies not allowed) */
2074 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2075 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2076 dimensions
, _mesa_lookup_enum_by_nr(target
));
2081 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2082 _mesa_error(ctx
, GL_INVALID_VALUE
,
2083 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2092 * Second part of error checking for glCopyTexSubImage[12]D().
2093 * \param xoffset sub-image x offset given by the user.
2094 * \param yoffset sub-image y offset given by the user.
2095 * \param zoffset sub-image z offset given by the user.
2096 * \param width image width given by the user.
2097 * \param height image height given by the user.
2100 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2101 GLenum target
, GLint level
,
2102 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2103 GLsizei width
, GLsizei height
,
2104 const struct gl_texture_image
*teximage
)
2106 /* check that dest tex image exists */
2108 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2109 "glCopyTexSubImage%dD(undefined texture level: %d)",
2116 _mesa_error(ctx
, GL_INVALID_VALUE
,
2117 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2120 if (dimensions
> 1 && height
< 0) {
2121 _mesa_error(ctx
, GL_INVALID_VALUE
,
2122 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2126 /* check x/y offsets */
2127 if (xoffset
< -((GLint
)teximage
->Border
)) {
2128 _mesa_error(ctx
, GL_INVALID_VALUE
,
2129 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2132 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2133 _mesa_error(ctx
, GL_INVALID_VALUE
,
2134 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2137 if (dimensions
> 1) {
2138 if (yoffset
< -((GLint
)teximage
->Border
)) {
2139 _mesa_error(ctx
, GL_INVALID_VALUE
,
2140 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2143 /* NOTE: we're adding the border here, not subtracting! */
2144 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2145 _mesa_error(ctx
, GL_INVALID_VALUE
,
2146 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2151 /* check z offset */
2152 if (dimensions
> 2) {
2153 if (zoffset
< -((GLint
)teximage
->Border
)) {
2154 _mesa_error(ctx
, GL_INVALID_VALUE
,
2155 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2158 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2159 _mesa_error(ctx
, GL_INVALID_VALUE
,
2160 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2165 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2166 /* offset must be multiple of 4 */
2167 if ((xoffset
& 3) || (yoffset
& 3)) {
2168 _mesa_error(ctx
, GL_INVALID_VALUE
,
2169 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2172 /* size must be multiple of 4 */
2173 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2174 _mesa_error(ctx
, GL_INVALID_VALUE
,
2175 "glCopyTexSubImage%dD(width)", dimensions
);
2178 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2179 _mesa_error(ctx
, GL_INVALID_VALUE
,
2180 "glCopyTexSubImage%dD(height)", dimensions
);
2185 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2186 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2190 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2191 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2192 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2193 dimensions
, teximage
->_BaseFormat
);
2197 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2198 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2199 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2200 "glCopyTexSubImage%dD(no depth buffer)",
2205 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2206 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2207 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2208 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2214 /* If copying into an integer texture, the source buffer must also be
2217 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2218 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2219 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2220 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2221 "glCopyTexSubImage%dD(source buffer is not integer format)",
2227 /* if we get here, the parameters are OK */
2232 /** Callback info for walking over FBO hash table */
2235 struct gl_context
*ctx
;
2236 struct gl_texture_object
*texObj
;
2242 * Check render to texture callback. Called from _mesa_HashWalk().
2245 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2247 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2248 const struct cb_info
*info
= (struct cb_info
*) userData
;
2249 struct gl_context
*ctx
= info
->ctx
;
2250 const struct gl_texture_object
*texObj
= info
->texObj
;
2251 const GLuint level
= info
->level
, face
= info
->face
;
2253 /* If this is a user-created FBO */
2256 /* check if any of the FBO's attachments point to 'texObj' */
2257 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2258 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2259 if (att
->Type
== GL_TEXTURE
&&
2260 att
->Texture
== texObj
&&
2261 att
->TextureLevel
== level
&&
2262 att
->CubeMapFace
== face
) {
2263 ASSERT(_mesa_get_attachment_teximage(att
));
2264 /* Tell driver about the new renderbuffer texture */
2265 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2266 /* Mark fb status as indeterminate to force re-validation */
2275 * When a texture image is specified we have to check if it's bound to
2276 * any framebuffer objects (render to texture) in order to detect changes
2277 * in size or format since that effects FBO completeness.
2278 * Any FBOs rendering into the texture must be re-validated.
2281 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2282 GLuint face
, GLuint level
)
2284 /* Only check this texture if it's been marked as RenderToTexture */
2285 if (texObj
->_RenderToTexture
) {
2286 struct cb_info info
;
2288 info
.texObj
= texObj
;
2291 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2297 * If the texture object's GenerateMipmap flag is set and we've
2298 * changed the texture base level image, regenerate the rest of the
2299 * mipmap levels now.
2302 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2303 struct gl_texture_object
*texObj
, GLint level
)
2305 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2306 if (texObj
->GenerateMipmap
&&
2307 level
== texObj
->BaseLevel
&&
2308 level
< texObj
->MaxLevel
) {
2309 ASSERT(ctx
->Driver
.GenerateMipmap
);
2310 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2315 /** Debug helper: override the user-requested internal format */
2317 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2320 if (internalFormat
== GL_RGBA16F_ARB
||
2321 internalFormat
== GL_RGBA32F_ARB
) {
2322 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2325 else if (internalFormat
== GL_RGB16F_ARB
||
2326 internalFormat
== GL_RGB32F_ARB
) {
2327 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2330 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2331 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2332 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2333 return GL_LUMINANCE_ALPHA
;
2335 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2336 internalFormat
== GL_LUMINANCE32F_ARB
) {
2337 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2338 return GL_LUMINANCE
;
2340 else if (internalFormat
== GL_ALPHA16F_ARB
||
2341 internalFormat
== GL_ALPHA32F_ARB
) {
2342 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2346 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2347 internalFormat = GL_RGBA;
2351 return internalFormat
;
2354 return internalFormat
;
2360 * Choose the actual hardware format for a texture image.
2361 * Try to use the same format as the previous image level when possible.
2362 * Otherwise, ask the driver for the best format.
2363 * It's important to try to choose a consistant format for all levels
2364 * for efficient texture memory layout/allocation. In particular, this
2365 * comes up during automatic mipmap generation.
2368 _mesa_choose_texture_format(struct gl_context
*ctx
,
2369 struct gl_texture_object
*texObj
,
2370 GLenum target
, GLint level
,
2371 GLenum internalFormat
, GLenum format
, GLenum type
)
2375 /* see if we've already chosen a format for the previous level */
2377 struct gl_texture_image
*prevImage
=
2378 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2379 /* See if the prev level is defined and has an internal format which
2380 * matches the new internal format.
2383 prevImage
->Width
> 0 &&
2384 prevImage
->InternalFormat
== internalFormat
) {
2385 /* use the same format */
2386 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2387 return prevImage
->TexFormat
;
2391 /* choose format from scratch */
2392 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2393 ASSERT(f
!= MESA_FORMAT_NONE
);
2399 * Common code to implement all the glTexImage1D/2D/3D functions.
2402 teximage(struct gl_context
*ctx
, GLuint dims
,
2403 GLenum target
, GLint level
, GLint internalFormat
,
2404 GLsizei width
, GLsizei height
, GLsizei depth
,
2405 GLint border
, GLenum format
, GLenum type
,
2406 const GLvoid
*pixels
)
2410 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2412 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2413 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2415 _mesa_lookup_enum_by_nr(target
), level
,
2416 _mesa_lookup_enum_by_nr(internalFormat
),
2417 width
, height
, depth
, border
,
2418 _mesa_lookup_enum_by_nr(format
),
2419 _mesa_lookup_enum_by_nr(type
), pixels
);
2421 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2423 /* target error checking */
2424 if (!legal_teximage_target(ctx
, dims
, target
)) {
2425 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2426 dims
, _mesa_lookup_enum_by_nr(target
));
2430 /* general error checking */
2431 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2432 format
, type
, width
, height
, depth
, border
);
2434 if (_mesa_is_proxy_texture(target
)) {
2435 /* Proxy texture: just clear or set state depending on error checking */
2436 struct gl_texture_image
*texImage
=
2437 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2440 /* when error, clear all proxy texture image parameters */
2442 clear_teximage_fields(texImage
);
2445 /* no error, set the tex image parameters */
2446 struct gl_texture_object
*texObj
=
2447 _mesa_get_current_tex_object(ctx
, target
);
2448 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2453 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2454 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2455 depth
, border
, internalFormat
,
2458 else if (texImage
) {
2459 clear_teximage_fields(texImage
);
2464 /* non-proxy target */
2465 const GLuint face
= _mesa_tex_target_to_face(target
);
2466 struct gl_texture_object
*texObj
;
2467 struct gl_texture_image
*texImage
;
2470 return; /* error was recorded */
2473 if (ctx
->NewState
& _NEW_PIXEL
)
2474 _mesa_update_state(ctx
);
2476 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2478 _mesa_lock_texture(ctx
, texObj
);
2480 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2483 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2486 gl_format texFormat
;
2488 if (texImage
->Data
) {
2489 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2492 ASSERT(texImage
->Data
== NULL
);
2493 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2494 internalFormat
, format
,
2497 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2498 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2499 width
, height
, depth
,
2500 border
, internalFormat
, texFormat
);
2502 /* Give the texture to the driver. <pixels> may be null. */
2503 ASSERT(ctx
->Driver
.TexImage3D
);
2506 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2507 width
, border
, format
,
2508 type
, pixels
, &ctx
->Unpack
, texObj
,
2512 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2513 width
, height
, border
, format
,
2514 type
, pixels
, &ctx
->Unpack
, texObj
,
2518 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2519 width
, height
, depth
, border
, format
,
2520 type
, pixels
, &ctx
->Unpack
, texObj
,
2524 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2527 check_gen_mipmap(ctx
, target
, texObj
, level
);
2529 update_fbo_texture(ctx
, texObj
, face
, level
);
2532 texObj
->_Complete
= GL_FALSE
;
2533 ctx
->NewState
|= _NEW_TEXTURE
;
2536 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2540 _mesa_unlock_texture(ctx
, texObj
);
2546 * Called from the API. Note that width includes the border.
2549 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2550 GLsizei width
, GLint border
, GLenum format
,
2551 GLenum type
, const GLvoid
*pixels
)
2553 GET_CURRENT_CONTEXT(ctx
);
2554 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2555 border
, format
, type
, pixels
);
2560 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2561 GLsizei width
, GLsizei height
, GLint border
,
2562 GLenum format
, GLenum type
,
2563 const GLvoid
*pixels
)
2565 GET_CURRENT_CONTEXT(ctx
);
2566 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2567 border
, format
, type
, pixels
);
2572 * Called by the API or display list executor.
2573 * Note that width and height include the border.
2576 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2577 GLsizei width
, GLsizei height
, GLsizei depth
,
2578 GLint border
, GLenum format
, GLenum type
,
2579 const GLvoid
*pixels
)
2581 GET_CURRENT_CONTEXT(ctx
);
2582 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2583 border
, format
, type
, pixels
);
2588 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2589 GLsizei width
, GLsizei height
, GLsizei depth
,
2590 GLint border
, GLenum format
, GLenum type
,
2591 const GLvoid
*pixels
)
2593 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2594 depth
, border
, format
, type
, pixels
);
2598 #if FEATURE_OES_EGL_image
2600 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2602 struct gl_texture_object
*texObj
;
2603 struct gl_texture_image
*texImage
;
2604 GET_CURRENT_CONTEXT(ctx
);
2605 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2607 if (!ctx
->Extensions
.OES_EGL_image
) {
2608 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2609 "glEGLImageTargetTexture2DOES(unsupported)");
2613 if (target
!= GL_TEXTURE_2D
) {
2614 _mesa_error(ctx
, GL_INVALID_ENUM
,
2615 "glEGLImageTargetTexture2D(target=%d)", target
);
2619 if (ctx
->NewState
& _NEW_PIXEL
)
2620 _mesa_update_state(ctx
);
2622 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2623 _mesa_lock_texture(ctx
, texObj
);
2625 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2627 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2630 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2632 ASSERT(texImage
->Data
== NULL
);
2633 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2634 texObj
, texImage
, image
);
2637 texObj
->_Complete
= GL_FALSE
;
2638 ctx
->NewState
|= _NEW_TEXTURE
;
2640 _mesa_unlock_texture(ctx
, texObj
);
2648 * Implement all the glTexSubImage1/2/3D() functions.
2651 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2652 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2653 GLsizei width
, GLsizei height
, GLsizei depth
,
2654 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2656 struct gl_texture_object
*texObj
;
2657 struct gl_texture_image
*texImage
;
2659 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2661 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2662 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2664 _mesa_lookup_enum_by_nr(target
), level
,
2665 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2666 _mesa_lookup_enum_by_nr(format
),
2667 _mesa_lookup_enum_by_nr(type
), pixels
);
2669 /* check target (proxies not allowed) */
2670 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2671 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2672 dims
, _mesa_lookup_enum_by_nr(target
));
2676 if (ctx
->NewState
& _NEW_PIXEL
)
2677 _mesa_update_state(ctx
);
2679 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2680 width
, height
, depth
, format
, type
)) {
2681 return; /* error was detected */
2684 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2686 _mesa_lock_texture(ctx
, texObj
);
2688 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2690 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2691 xoffset
, yoffset
, zoffset
,
2692 width
, height
, depth
,
2693 format
, type
, texImage
)) {
2694 /* error was recorded */
2696 else if (width
> 0 && height
> 0 && height
> 0) {
2697 /* If we have a border, offset=-1 is legal. Bias by border width. */
2700 zoffset
+= texImage
->Border
;
2703 yoffset
+= texImage
->Border
;
2706 xoffset
+= texImage
->Border
;
2711 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2713 format
, type
, pixels
,
2714 &ctx
->Unpack
, texObj
, texImage
);
2717 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2718 xoffset
, yoffset
, width
, height
,
2719 format
, type
, pixels
,
2720 &ctx
->Unpack
, texObj
, texImage
);
2723 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2724 xoffset
, yoffset
, zoffset
,
2725 width
, height
, depth
,
2726 format
, type
, pixels
,
2727 &ctx
->Unpack
, texObj
, texImage
);
2730 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2733 check_gen_mipmap(ctx
, target
, texObj
, level
);
2735 ctx
->NewState
|= _NEW_TEXTURE
;
2738 _mesa_unlock_texture(ctx
, texObj
);
2743 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2744 GLint xoffset
, GLsizei width
,
2745 GLenum format
, GLenum type
,
2746 const GLvoid
*pixels
)
2748 GET_CURRENT_CONTEXT(ctx
);
2749 texsubimage(ctx
, 1, target
, level
,
2752 format
, type
, pixels
);
2757 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2758 GLint xoffset
, GLint yoffset
,
2759 GLsizei width
, GLsizei height
,
2760 GLenum format
, GLenum type
,
2761 const GLvoid
*pixels
)
2763 GET_CURRENT_CONTEXT(ctx
);
2764 texsubimage(ctx
, 2, target
, level
,
2765 xoffset
, yoffset
, 0,
2767 format
, type
, pixels
);
2773 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2774 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2775 GLsizei width
, GLsizei height
, GLsizei depth
,
2776 GLenum format
, GLenum type
,
2777 const GLvoid
*pixels
)
2779 GET_CURRENT_CONTEXT(ctx
);
2780 texsubimage(ctx
, 3, target
, level
,
2781 xoffset
, yoffset
, zoffset
,
2782 width
, height
, depth
,
2783 format
, type
, pixels
);
2789 * Implement the glCopyTexImage1/2D() functions.
2792 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2793 GLenum target
, GLint level
, GLenum internalFormat
,
2794 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2796 struct gl_texture_object
*texObj
;
2797 struct gl_texture_image
*texImage
;
2798 const GLuint face
= _mesa_tex_target_to_face(target
);
2800 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2802 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2803 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2805 _mesa_lookup_enum_by_nr(target
), level
,
2806 _mesa_lookup_enum_by_nr(internalFormat
),
2807 x
, y
, width
, height
, border
);
2809 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2810 _mesa_update_state(ctx
);
2812 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2813 width
, height
, border
))
2816 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2818 _mesa_lock_texture(ctx
, texObj
);
2820 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2823 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2826 gl_format texFormat
;
2828 if (texImage
->Data
) {
2829 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
2832 ASSERT(texImage
->Data
== NULL
);
2834 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2835 internalFormat
, GL_NONE
,
2838 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2839 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2840 border
, internalFormat
, texFormat
);
2842 ASSERT(ctx
->Driver
.CopyTexImage2D
);
2844 ctx
->Driver
.CopyTexImage1D(ctx
, target
, level
, internalFormat
,
2845 x
, y
, width
, border
);
2847 ctx
->Driver
.CopyTexImage2D(ctx
, target
, level
, internalFormat
,
2848 x
, y
, width
, height
, border
);
2850 check_gen_mipmap(ctx
, target
, texObj
, level
);
2852 update_fbo_texture(ctx
, texObj
, face
, level
);
2855 texObj
->_Complete
= GL_FALSE
;
2856 ctx
->NewState
|= _NEW_TEXTURE
;
2859 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2863 _mesa_unlock_texture(ctx
, texObj
);
2869 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2870 GLenum internalFormat
,
2872 GLsizei width
, GLint border
)
2874 GET_CURRENT_CONTEXT(ctx
);
2875 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2881 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2882 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2885 GET_CURRENT_CONTEXT(ctx
);
2886 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2887 x
, y
, width
, height
, border
);
2893 * Implementation for glCopyTexSubImage1/2/3D() functions.
2896 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2897 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2898 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2900 struct gl_texture_object
*texObj
;
2901 struct gl_texture_image
*texImage
;
2903 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2905 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2906 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2908 _mesa_lookup_enum_by_nr(target
),
2909 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2911 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2912 _mesa_update_state(ctx
);
2914 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2917 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2919 _mesa_lock_texture(ctx
, texObj
);
2921 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2923 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2924 zoffset
, width
, height
, texImage
)) {
2925 /* error was recored */
2928 /* If we have a border, offset=-1 is legal. Bias by border width. */
2931 zoffset
+= texImage
->Border
;
2934 yoffset
+= texImage
->Border
;
2937 xoffset
+= texImage
->Border
;
2940 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2944 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2945 xoffset
, x
, y
, width
);
2948 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2950 x
, y
, width
, height
);
2953 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2954 xoffset
, yoffset
, zoffset
,
2955 x
, y
, width
, height
);
2958 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
2961 check_gen_mipmap(ctx
, target
, texObj
, level
);
2963 ctx
->NewState
|= _NEW_TEXTURE
;
2967 _mesa_unlock_texture(ctx
, texObj
);
2972 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2973 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2975 GET_CURRENT_CONTEXT(ctx
);
2976 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
2982 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2983 GLint xoffset
, GLint yoffset
,
2984 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2986 GET_CURRENT_CONTEXT(ctx
);
2987 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
2994 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2995 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2996 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2998 GET_CURRENT_CONTEXT(ctx
);
2999 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3000 x
, y
, width
, height
);
3006 /**********************************************************************/
3007 /****** Compressed Textures ******/
3008 /**********************************************************************/
3012 * Return expected size of a compressed texture.
3015 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3018 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3019 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3024 * Return compressed texture block size, in pixels.
3027 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3029 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3030 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3035 * Error checking for glCompressedTexImage[123]D().
3036 * \return error code or GL_NO_ERROR.
3039 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3040 GLenum target
, GLint level
,
3041 GLenum internalFormat
, GLsizei width
,
3042 GLsizei height
, GLsizei depth
, GLint border
,
3045 const GLenum proxyTarget
= get_proxy_target(target
);
3046 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3050 if (level
< 0 || level
>= maxLevels
)
3051 return GL_INVALID_VALUE
;
3053 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3054 return GL_INVALID_ENUM
;
3057 /* This will detect any invalid internalFormat value */
3058 if (!_mesa_is_compressed_format(ctx
, internalFormat
))
3059 return GL_INVALID_ENUM
;
3061 /* This should really never fail */
3062 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0)
3063 return GL_INVALID_ENUM
;
3065 /* No compressed formats support borders at this time */
3067 return GL_INVALID_VALUE
;
3069 /* For cube map, width must equal height */
3070 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3071 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
)
3072 return GL_INVALID_VALUE
;
3074 /* check image size against compression block size */
3076 gl_format texFormat
=
3077 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3081 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3082 if ((width
> bw
&& width
% bw
> 0) ||
3083 (height
> bh
&& height
% bh
> 0)) {
3085 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3086 * generated [...] if any parameter combinations are not
3087 * supported by the specific compressed internal format.
3089 return GL_INVALID_OPERATION
;
3093 /* check image sizes */
3094 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3095 internalFormat
, GL_NONE
, GL_NONE
,
3096 width
, height
, depth
, border
)) {
3097 /* See error comment above */
3098 return GL_INVALID_OPERATION
;
3101 /* check image size in bytes */
3102 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3103 if (expectedSize
!= imageSize
) {
3104 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3105 * if <imageSize> is not consistent with the format, dimensions, and
3106 * contents of the specified image.
3108 return GL_INVALID_VALUE
;
3116 * Error checking for glCompressedTexSubImage[123]D().
3117 * \warning There are some bad assumptions here about the size of compressed
3118 * texture tiles (multiple of 4) used to test the validity of the
3119 * offset and size parameters.
3120 * \return error code or GL_NO_ERROR.
3123 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3124 GLenum target
, GLint level
,
3125 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3126 GLsizei width
, GLsizei height
, GLsizei depth
,
3127 GLenum format
, GLsizei imageSize
)
3129 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3133 if (dimensions
== 1) {
3134 /* 1D compressed textures not allowed */
3135 return GL_INVALID_ENUM
;
3137 else if (dimensions
== 2) {
3138 if (target
== GL_PROXY_TEXTURE_2D
) {
3139 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3141 else if (target
== GL_TEXTURE_2D
) {
3142 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3144 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3145 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3146 return GL_INVALID_ENUM
; /*target*/
3147 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3149 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3150 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3151 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3152 return GL_INVALID_ENUM
; /*target*/
3153 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3156 return GL_INVALID_ENUM
; /*target*/
3159 else if (dimensions
== 3) {
3160 /* 3D compressed textures not allowed */
3161 return GL_INVALID_ENUM
;
3164 maxTextureSize
= 1 << (maxLevels
- 1);
3166 /* this will catch any invalid compressed format token */
3167 if (!_mesa_is_compressed_format(ctx
, format
))
3168 return GL_INVALID_ENUM
;
3170 if (width
< 1 || width
> maxTextureSize
)
3171 return GL_INVALID_VALUE
;
3173 if ((height
< 1 || height
> maxTextureSize
)
3175 return GL_INVALID_VALUE
;
3177 if (level
< 0 || level
>= maxLevels
)
3178 return GL_INVALID_VALUE
;
3181 * do checks which depend on compression block size
3183 get_compressed_block_size(format
, &bw
, &bh
);
3185 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3186 return GL_INVALID_VALUE
;
3188 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3189 return GL_INVALID_VALUE
;
3191 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3192 return GL_INVALID_VALUE
;
3194 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3195 if (expectedSize
!= imageSize
)
3196 return GL_INVALID_VALUE
;
3203 * Do second part of glCompressedTexSubImage error checking.
3204 * \return GL_TRUE if error found, GL_FALSE otherwise.
3207 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3208 GLsizei width
, GLsizei height
,
3209 GLsizei depth
, GLenum format
,
3210 struct gl_texture_image
*texImage
)
3213 if ((GLint
) format
!= texImage
->InternalFormat
) {
3214 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3215 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3219 if (((width
== 1 || width
== 2) &&
3220 width
!= (GLsizei
) texImage
->Width
) ||
3221 (width
> (GLsizei
) texImage
->Width
)) {
3222 _mesa_error(ctx
, GL_INVALID_VALUE
,
3223 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3228 if (((height
== 1 || height
== 2) &&
3229 height
!= (GLsizei
) texImage
->Height
) ||
3230 (height
> (GLsizei
) texImage
->Height
)) {
3231 _mesa_error(ctx
, GL_INVALID_VALUE
,
3232 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3238 if (((depth
== 1 || depth
== 2) &&
3239 depth
!= (GLsizei
) texImage
->Depth
) ||
3240 (depth
> (GLsizei
) texImage
->Depth
)) {
3241 _mesa_error(ctx
, GL_INVALID_VALUE
,
3242 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3252 * Implementation of the glCompressedTexImage1/2/3D() functions.
3255 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3256 GLenum target
, GLint level
,
3257 GLenum internalFormat
, GLsizei width
,
3258 GLsizei height
, GLsizei depth
, GLint border
,
3259 GLsizei imageSize
, const GLvoid
*data
)
3263 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3265 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3267 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3269 _mesa_lookup_enum_by_nr(target
), level
,
3270 _mesa_lookup_enum_by_nr(internalFormat
),
3271 width
, height
, depth
, border
, imageSize
, data
);
3274 if (!legal_teximage_target(ctx
, dims
, target
)) {
3275 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3276 dims
, _mesa_lookup_enum_by_nr(target
));
3280 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3281 internalFormat
, width
, height
, depth
,
3285 _mesa_error(ctx
, error
, "glTexImage2D");
3290 /* XXX this is kind of a hack */
3292 switch (internalFormat
) {
3293 case GL_PALETTE4_RGB8_OES
:
3294 case GL_PALETTE4_RGBA8_OES
:
3295 case GL_PALETTE4_R5_G6_B5_OES
:
3296 case GL_PALETTE4_RGBA4_OES
:
3297 case GL_PALETTE4_RGB5_A1_OES
:
3298 case GL_PALETTE8_RGB8_OES
:
3299 case GL_PALETTE8_RGBA8_OES
:
3300 case GL_PALETTE8_R5_G6_B5_OES
:
3301 case GL_PALETTE8_RGBA4_OES
:
3302 case GL_PALETTE8_RGB5_A1_OES
:
3303 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3304 width
, height
, imageSize
, data
);
3310 if (_mesa_is_proxy_texture(target
)) {
3311 /* Proxy texture: just check for errors and update proxy state */
3312 struct gl_texture_image
*texImage
;
3315 struct gl_texture_object
*texObj
=
3316 _mesa_get_current_tex_object(ctx
, target
);
3317 gl_format texFormat
=
3318 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3319 internalFormat
, GL_NONE
, GL_NONE
);
3320 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3321 error
= GL_OUT_OF_MEMORY
;
3325 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3328 /* if error, clear all proxy texture image parameters */
3329 clear_teximage_fields(texImage
);
3332 /* no error: store the teximage parameters */
3333 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3334 depth
, border
, internalFormat
,
3340 /* non-proxy target */
3341 struct gl_texture_object
*texObj
;
3342 struct gl_texture_image
*texImage
;
3345 _mesa_error(ctx
, error
, "glCompressedTexImage%uD", dims
);
3349 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3351 _mesa_lock_texture(ctx
, texObj
);
3353 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3355 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3356 "glCompressedTexImage%uD", dims
);
3359 gl_format texFormat
;
3361 if (texImage
->Data
) {
3362 ctx
->Driver
.FreeTexImageData( ctx
, texImage
);
3364 ASSERT(texImage
->Data
== NULL
);
3366 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3367 internalFormat
, GL_NONE
,
3370 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3371 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3372 width
, height
, depth
,
3373 border
, internalFormat
, texFormat
);
3377 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3378 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3381 border
, imageSize
, data
,
3385 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3386 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3389 border
, imageSize
, data
,
3393 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3394 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3396 width
, height
, depth
,
3397 border
, imageSize
, data
,
3401 _mesa_problem(ctx
, "bad dims in compressedteximage");
3404 check_gen_mipmap(ctx
, target
, texObj
, level
);
3407 texObj
->_Complete
= GL_FALSE
;
3408 ctx
->NewState
|= _NEW_TEXTURE
;
3411 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3412 "glCompressedTexImage%uD", dims
);
3416 _mesa_unlock_texture(ctx
, texObj
);
3422 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3423 GLenum internalFormat
, GLsizei width
,
3424 GLint border
, GLsizei imageSize
,
3427 GET_CURRENT_CONTEXT(ctx
);
3428 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3429 width
, 1, 1, border
, imageSize
, data
);
3434 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3435 GLenum internalFormat
, GLsizei width
,
3436 GLsizei height
, GLint border
, GLsizei imageSize
,
3439 GET_CURRENT_CONTEXT(ctx
);
3440 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3441 width
, height
, 1, border
, imageSize
, data
);
3446 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3447 GLenum internalFormat
, GLsizei width
,
3448 GLsizei height
, GLsizei depth
, GLint border
,
3449 GLsizei imageSize
, const GLvoid
*data
)
3451 GET_CURRENT_CONTEXT(ctx
);
3452 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3453 width
, height
, depth
, border
, imageSize
, data
);
3458 * Common helper for glCompressedTexSubImage1/2/3D().
3461 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3462 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3463 GLsizei width
, GLsizei height
, GLsizei depth
,
3464 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3466 struct gl_texture_object
*texObj
;
3467 struct gl_texture_image
*texImage
;
3469 GET_CURRENT_CONTEXT(ctx
);
3470 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3472 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3473 xoffset
, 0, 0, /* pos */
3474 width
, height
, depth
, /* size */
3477 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3481 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3483 _mesa_lock_texture(ctx
, texObj
);
3485 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3488 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3489 format
, texImage
)) {
3490 /* error was recorded */
3492 else if (width
> 0 && height
> 0 && depth
> 0) {
3495 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3496 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3498 format
, imageSize
, data
,
3503 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3504 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3507 format
, imageSize
, data
,
3512 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3513 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3514 xoffset
, yoffset
, zoffset
,
3515 width
, height
, depth
,
3516 format
, imageSize
, data
,
3524 check_gen_mipmap(ctx
, target
, texObj
, level
);
3526 ctx
->NewState
|= _NEW_TEXTURE
;
3529 _mesa_unlock_texture(ctx
, texObj
);
3534 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3535 GLsizei width
, GLenum format
,
3536 GLsizei imageSize
, const GLvoid
*data
)
3538 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3539 format
, imageSize
, data
);
3544 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3545 GLint yoffset
, GLsizei width
, GLsizei height
,
3546 GLenum format
, GLsizei imageSize
,
3549 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3550 width
, height
, 1, format
, imageSize
, data
);
3555 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3556 GLint yoffset
, GLint zoffset
, GLsizei width
,
3557 GLsizei height
, GLsizei depth
, GLenum format
,
3558 GLsizei imageSize
, const GLvoid
*data
)
3560 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3561 width
, height
, depth
, format
, imageSize
, data
);
3566 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3567 * return the basic data type and number of components for the format.
3568 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3571 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3572 GLenum
*datatype
, GLuint
*components
)
3574 switch (internalFormat
) {
3576 *datatype
= GL_UNSIGNED_BYTE
;
3580 *datatype
= GL_UNSIGNED_SHORT
;
3583 case GL_ALPHA16F_ARB
:
3584 *datatype
= GL_HALF_FLOAT
;
3587 case GL_ALPHA32F_ARB
:
3588 *datatype
= GL_FLOAT
;
3591 case GL_ALPHA8I_EXT
:
3592 *datatype
= GL_BYTE
;
3595 case GL_ALPHA16I_EXT
:
3596 *datatype
= GL_SHORT
;
3599 case GL_ALPHA32I_EXT
:
3603 case GL_ALPHA8UI_EXT
:
3604 *datatype
= GL_UNSIGNED_BYTE
;
3607 case GL_ALPHA16UI_EXT
:
3608 *datatype
= GL_UNSIGNED_SHORT
;
3611 case GL_ALPHA32UI_EXT
:
3612 *datatype
= GL_UNSIGNED_INT
;
3616 *datatype
= GL_UNSIGNED_BYTE
;
3619 case GL_LUMINANCE16
:
3620 *datatype
= GL_UNSIGNED_SHORT
;
3623 case GL_LUMINANCE16F_ARB
:
3624 *datatype
= GL_HALF_FLOAT
;
3627 case GL_LUMINANCE32F_ARB
:
3628 *datatype
= GL_FLOAT
;
3631 case GL_LUMINANCE8I_EXT
:
3632 *datatype
= GL_BYTE
;
3635 case GL_LUMINANCE16I_EXT
:
3636 *datatype
= GL_SHORT
;
3639 case GL_LUMINANCE32I_EXT
:
3643 case GL_LUMINANCE8UI_EXT
:
3644 *datatype
= GL_UNSIGNED_BYTE
;
3647 case GL_LUMINANCE16UI_EXT
:
3648 *datatype
= GL_UNSIGNED_SHORT
;
3651 case GL_LUMINANCE32UI_EXT
:
3652 *datatype
= GL_UNSIGNED_INT
;
3655 case GL_LUMINANCE8_ALPHA8
:
3656 *datatype
= GL_UNSIGNED_BYTE
;
3659 case GL_LUMINANCE16_ALPHA16
:
3660 *datatype
= GL_UNSIGNED_SHORT
;
3663 case GL_LUMINANCE_ALPHA16F_ARB
:
3664 *datatype
= GL_HALF_FLOAT
;
3667 case GL_LUMINANCE_ALPHA32F_ARB
:
3668 *datatype
= GL_FLOAT
;
3671 case GL_LUMINANCE_ALPHA8I_EXT
:
3672 *datatype
= GL_BYTE
;
3675 case GL_LUMINANCE_ALPHA16I_EXT
:
3676 *datatype
= GL_SHORT
;
3679 case GL_LUMINANCE_ALPHA32I_EXT
:
3683 case GL_LUMINANCE_ALPHA8UI_EXT
:
3684 *datatype
= GL_UNSIGNED_BYTE
;
3687 case GL_LUMINANCE_ALPHA16UI_EXT
:
3688 *datatype
= GL_UNSIGNED_SHORT
;
3691 case GL_LUMINANCE_ALPHA32UI_EXT
:
3692 *datatype
= GL_UNSIGNED_INT
;
3696 *datatype
= GL_UNSIGNED_BYTE
;
3699 case GL_INTENSITY16
:
3700 *datatype
= GL_UNSIGNED_SHORT
;
3703 case GL_INTENSITY16F_ARB
:
3704 *datatype
= GL_HALF_FLOAT
;
3707 case GL_INTENSITY32F_ARB
:
3708 *datatype
= GL_FLOAT
;
3711 case GL_INTENSITY8I_EXT
:
3712 *datatype
= GL_BYTE
;
3715 case GL_INTENSITY16I_EXT
:
3716 *datatype
= GL_SHORT
;
3719 case GL_INTENSITY32I_EXT
:
3723 case GL_INTENSITY8UI_EXT
:
3724 *datatype
= GL_UNSIGNED_BYTE
;
3727 case GL_INTENSITY16UI_EXT
:
3728 *datatype
= GL_UNSIGNED_SHORT
;
3731 case GL_INTENSITY32UI_EXT
:
3732 *datatype
= GL_UNSIGNED_INT
;
3736 *datatype
= GL_UNSIGNED_BYTE
;
3740 *datatype
= GL_UNSIGNED_SHORT
;
3743 case GL_RGBA16F_ARB
:
3744 *datatype
= GL_HALF_FLOAT
;
3747 case GL_RGBA32F_ARB
:
3748 *datatype
= GL_FLOAT
;
3752 *datatype
= GL_BYTE
;
3755 case GL_RGBA16I_EXT
:
3756 *datatype
= GL_SHORT
;
3759 case GL_RGBA32I_EXT
:
3763 case GL_RGBA8UI_EXT
:
3764 *datatype
= GL_UNSIGNED_BYTE
;
3767 case GL_RGBA16UI_EXT
:
3768 *datatype
= GL_UNSIGNED_SHORT
;
3771 case GL_RGBA32UI_EXT
:
3772 *datatype
= GL_UNSIGNED_INT
;
3779 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3782 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3789 /** GL_ARB_texture_buffer_object */
3791 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3793 struct gl_texture_object
*texObj
;
3794 struct gl_buffer_object
*bufObj
;
3798 GET_CURRENT_CONTEXT(ctx
);
3799 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3801 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3802 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3806 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3807 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3811 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3812 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3817 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3818 if (buffer
&& !bufObj
) {
3819 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3823 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3825 _mesa_lock_texture(ctx
, texObj
);
3827 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3828 texObj
->BufferObjectFormat
= internalFormat
;
3830 _mesa_unlock_texture(ctx
, texObj
);