2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "mfeatures.h"
44 #include "texcompress.h"
53 * State changes which we care about for glCopyTex[Sub]Image() calls.
54 * In particular, we care about pixel transfer state and buffer state
55 * (such as glReadBuffer to make sure we read from the right renderbuffer).
57 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
62 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
66 _mesa_alloc_texmemory(GLsizei bytes
)
68 return _mesa_align_malloc(bytes
, 512);
73 * Free texture memory allocated with _mesa_alloc_texmemory()
76 _mesa_free_texmemory(void *m
)
83 * Return the simple base format for a given internal texture format.
84 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
86 * \param ctx GL context.
87 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
89 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
90 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
92 * This is the format which is used during texture application (i.e. the
93 * texture format and env mode determine the arithmetic used.
95 * XXX this could be static
98 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
100 switch (internalFormat
) {
115 case GL_LUMINANCE_ALPHA
:
116 case GL_LUMINANCE4_ALPHA4
:
117 case GL_LUMINANCE6_ALPHA2
:
118 case GL_LUMINANCE8_ALPHA8
:
119 case GL_LUMINANCE12_ALPHA4
:
120 case GL_LUMINANCE12_ALPHA12
:
121 case GL_LUMINANCE16_ALPHA16
:
122 return GL_LUMINANCE_ALPHA
;
153 if (ctx
->Extensions
.EXT_texture_format_BGRA8888
) {
154 switch (internalFormat
) {
162 if (ctx
->Extensions
.EXT_paletted_texture
) {
163 switch (internalFormat
) {
165 case GL_COLOR_INDEX1_EXT
:
166 case GL_COLOR_INDEX2_EXT
:
167 case GL_COLOR_INDEX4_EXT
:
168 case GL_COLOR_INDEX8_EXT
:
169 case GL_COLOR_INDEX12_EXT
:
170 case GL_COLOR_INDEX16_EXT
:
171 return GL_COLOR_INDEX
;
177 if (ctx
->Extensions
.ARB_depth_texture
) {
178 switch (internalFormat
) {
179 case GL_DEPTH_COMPONENT
:
180 case GL_DEPTH_COMPONENT16
:
181 case GL_DEPTH_COMPONENT24
:
182 case GL_DEPTH_COMPONENT32
:
183 return GL_DEPTH_COMPONENT
;
189 switch (internalFormat
) {
190 case GL_COMPRESSED_ALPHA
:
192 case GL_COMPRESSED_LUMINANCE
:
194 case GL_COMPRESSED_LUMINANCE_ALPHA
:
195 return GL_LUMINANCE_ALPHA
;
196 case GL_COMPRESSED_INTENSITY
:
198 case GL_COMPRESSED_RGB
:
200 case GL_COMPRESSED_RGBA
:
206 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
207 switch (internalFormat
) {
208 case GL_COMPRESSED_RGB_FXT1_3DFX
:
210 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
217 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
218 switch (internalFormat
) {
219 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
221 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
222 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
223 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
230 if (ctx
->Extensions
.S3_s3tc
) {
231 switch (internalFormat
) {
243 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
244 if (internalFormat
== GL_YCBCR_MESA
)
245 return GL_YCBCR_MESA
;
248 if (ctx
->Extensions
.ARB_texture_float
) {
249 switch (internalFormat
) {
250 case GL_ALPHA16F_ARB
:
251 case GL_ALPHA32F_ARB
:
259 case GL_INTENSITY16F_ARB
:
260 case GL_INTENSITY32F_ARB
:
262 case GL_LUMINANCE16F_ARB
:
263 case GL_LUMINANCE32F_ARB
:
265 case GL_LUMINANCE_ALPHA16F_ARB
:
266 case GL_LUMINANCE_ALPHA32F_ARB
:
267 return GL_LUMINANCE_ALPHA
;
273 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
274 switch (internalFormat
) {
283 if (ctx
->Extensions
.EXT_texture_snorm
) {
284 switch (internalFormat
) {
299 case GL_RGBA16_SNORM
:
302 case GL_ALPHA8_SNORM
:
303 case GL_ALPHA16_SNORM
:
305 case GL_LUMINANCE_SNORM
:
306 case GL_LUMINANCE8_SNORM
:
307 case GL_LUMINANCE16_SNORM
:
309 case GL_LUMINANCE_ALPHA_SNORM
:
310 case GL_LUMINANCE8_ALPHA8_SNORM
:
311 case GL_LUMINANCE16_ALPHA16_SNORM
:
312 return GL_LUMINANCE_ALPHA
;
313 case GL_INTENSITY_SNORM
:
314 case GL_INTENSITY8_SNORM
:
315 case GL_INTENSITY16_SNORM
:
322 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
323 switch (internalFormat
) {
324 case GL_DEPTH_STENCIL_EXT
:
325 case GL_DEPTH24_STENCIL8_EXT
:
326 return GL_DEPTH_STENCIL_EXT
;
332 #if FEATURE_EXT_texture_sRGB
333 if (ctx
->Extensions
.EXT_texture_sRGB
) {
334 switch (internalFormat
) {
337 case GL_COMPRESSED_SRGB_EXT
:
338 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
340 case GL_SRGB_ALPHA_EXT
:
341 case GL_SRGB8_ALPHA8_EXT
:
342 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
343 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
344 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
345 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
347 case GL_SLUMINANCE_ALPHA_EXT
:
348 case GL_SLUMINANCE8_ALPHA8_EXT
:
349 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
350 return GL_LUMINANCE_ALPHA
;
351 case GL_SLUMINANCE_EXT
:
352 case GL_SLUMINANCE8_EXT
:
353 case GL_COMPRESSED_SLUMINANCE_EXT
:
359 #endif /* FEATURE_EXT_texture_sRGB */
361 if (ctx
->Extensions
.EXT_texture_integer
) {
362 switch (internalFormat
) {
364 case GL_RGBA16UI_EXT
:
365 case GL_RGBA32UI_EXT
:
377 case GL_ALPHA8UI_EXT
:
378 case GL_ALPHA16UI_EXT
:
379 case GL_ALPHA32UI_EXT
:
381 case GL_ALPHA16I_EXT
:
382 case GL_ALPHA32I_EXT
:
384 case GL_INTENSITY8UI_EXT
:
385 case GL_INTENSITY16UI_EXT
:
386 case GL_INTENSITY32UI_EXT
:
387 case GL_INTENSITY8I_EXT
:
388 case GL_INTENSITY16I_EXT
:
389 case GL_INTENSITY32I_EXT
:
391 case GL_LUMINANCE8UI_EXT
:
392 case GL_LUMINANCE16UI_EXT
:
393 case GL_LUMINANCE32UI_EXT
:
394 case GL_LUMINANCE8I_EXT
:
395 case GL_LUMINANCE16I_EXT
:
396 case GL_LUMINANCE32I_EXT
:
398 case GL_LUMINANCE_ALPHA8UI_EXT
:
399 case GL_LUMINANCE_ALPHA16UI_EXT
:
400 case GL_LUMINANCE_ALPHA32UI_EXT
:
401 case GL_LUMINANCE_ALPHA8I_EXT
:
402 case GL_LUMINANCE_ALPHA16I_EXT
:
403 case GL_LUMINANCE_ALPHA32I_EXT
:
404 return GL_LUMINANCE_ALPHA
;
410 if (ctx
->Extensions
.ARB_texture_rg
) {
411 switch (internalFormat
) {
413 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
415 if (!ctx
->Extensions
.ARB_half_float_pixel
)
419 if (!ctx
->Extensions
.ARB_texture_float
)
428 if (!ctx
->Extensions
.EXT_texture_integer
)
434 case GL_COMPRESSED_RED
:
438 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
440 if (!ctx
->Extensions
.ARB_half_float_pixel
)
444 if (!ctx
->Extensions
.ARB_texture_float
)
453 if (!ctx
->Extensions
.EXT_texture_integer
)
459 case GL_COMPRESSED_RG
:
466 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
467 switch (internalFormat
) {
475 if (ctx
->Extensions
.EXT_packed_float
) {
476 switch (internalFormat
) {
477 case GL_R11F_G11F_B10F_EXT
:
484 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
485 switch (internalFormat
) {
486 case GL_DEPTH_COMPONENT32F
:
487 return GL_DEPTH_COMPONENT
;
488 case GL_DEPTH32F_STENCIL8
:
489 return GL_DEPTH_STENCIL
;
495 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
496 switch (internalFormat
) {
497 case GL_COMPRESSED_RED_RGTC1
:
498 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
500 case GL_COMPRESSED_RG_RGTC2
:
501 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
508 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
509 switch (internalFormat
) {
510 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
511 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
513 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
514 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
515 return GL_LUMINANCE_ALPHA
;
521 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
522 switch (internalFormat
) {
523 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
524 return GL_LUMINANCE_ALPHA
;
530 return -1; /* error */
535 * For cube map faces, return a face index in [0,5].
536 * For other targets return 0;
539 _mesa_tex_target_to_face(GLenum target
)
541 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
542 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
543 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
551 * Store a gl_texture_image pointer in a gl_texture_object structure
552 * according to the target and level parameters.
554 * \param tObj texture object.
555 * \param target texture target.
556 * \param level image level.
557 * \param texImage texture image.
560 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
561 GLenum target
, GLint level
,
562 struct gl_texture_image
*texImage
)
564 const GLuint face
= _mesa_tex_target_to_face(target
);
568 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
570 tObj
->Image
[face
][level
] = texImage
;
572 /* Set the 'back' pointer */
573 texImage
->TexObject
= tObj
;
574 texImage
->Level
= level
;
575 texImage
->Face
= face
;
580 * Allocate a texture image structure.
582 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
585 * \return a pointer to gl_texture_image struct with all fields initialized to
588 struct gl_texture_image
*
589 _mesa_new_texture_image( struct gl_context
*ctx
)
592 return CALLOC_STRUCT(gl_texture_image
);
597 * Free texture image data.
598 * This function is a fallback called via ctx->Driver.FreeTextureImageBuffer().
600 * \param texImage texture image.
602 * Free the texture image data if it's not marked as client data.
605 _mesa_free_texture_image_data(struct gl_context
*ctx
,
606 struct gl_texture_image
*texImage
)
610 if (texImage
->Data
&& !texImage
->IsClientData
) {
611 /* free the old texture data */
612 _mesa_free_texmemory(texImage
->Data
);
615 texImage
->Data
= NULL
;
620 * Free texture image.
622 * \param texImage texture image.
624 * Free the texture image structure and the associated image data.
627 _mesa_delete_texture_image(struct gl_context
*ctx
,
628 struct gl_texture_image
*texImage
)
630 /* Free texImage->Data and/or any other driver-specific texture
633 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
634 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
636 ASSERT(texImage
->Data
== NULL
);
637 if (texImage
->ImageOffsets
)
638 free(texImage
->ImageOffsets
);
644 * Test if a target is a proxy target.
646 * \param target texture target.
648 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
651 _mesa_is_proxy_texture(GLenum target
)
653 /* NUM_TEXTURE_TARGETS should match number of terms below,
654 * except there's no proxy for GL_TEXTURE_BUFFER.
656 assert(NUM_TEXTURE_TARGETS
== 8);
658 return (target
== GL_PROXY_TEXTURE_1D
||
659 target
== GL_PROXY_TEXTURE_2D
||
660 target
== GL_PROXY_TEXTURE_3D
||
661 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
662 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
663 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
664 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
669 * Return the proxy target which corresponds to the given texture target
672 get_proxy_target(GLenum target
)
676 case GL_PROXY_TEXTURE_1D
:
677 return GL_PROXY_TEXTURE_1D
;
679 case GL_PROXY_TEXTURE_2D
:
680 return GL_PROXY_TEXTURE_2D
;
682 case GL_PROXY_TEXTURE_3D
:
683 return GL_PROXY_TEXTURE_3D
;
684 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
685 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
686 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
687 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
688 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
689 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
690 case GL_TEXTURE_CUBE_MAP_ARB
:
691 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
692 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
693 case GL_TEXTURE_RECTANGLE_NV
:
694 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
695 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
696 case GL_TEXTURE_1D_ARRAY_EXT
:
697 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
698 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
699 case GL_TEXTURE_2D_ARRAY_EXT
:
700 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
701 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
703 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
710 * Get the texture object that corresponds to the target of the given
711 * texture unit. The target should have already been checked for validity.
713 * \param ctx GL context.
714 * \param texUnit texture unit.
715 * \param target texture target.
717 * \return pointer to the texture object on success, or NULL on failure.
719 struct gl_texture_object
*
720 _mesa_select_tex_object(struct gl_context
*ctx
,
721 const struct gl_texture_unit
*texUnit
,
724 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
725 ctx
->Extensions
.EXT_texture_array
);
729 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
730 case GL_PROXY_TEXTURE_1D
:
731 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
733 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
734 case GL_PROXY_TEXTURE_2D
:
735 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
737 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
738 case GL_PROXY_TEXTURE_3D
:
739 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
740 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
741 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
742 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
743 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
744 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
745 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
746 case GL_TEXTURE_CUBE_MAP_ARB
:
747 return ctx
->Extensions
.ARB_texture_cube_map
748 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
749 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
750 return ctx
->Extensions
.ARB_texture_cube_map
751 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
752 case GL_TEXTURE_RECTANGLE_NV
:
753 return ctx
->Extensions
.NV_texture_rectangle
754 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
755 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
756 return ctx
->Extensions
.NV_texture_rectangle
757 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
758 case GL_TEXTURE_1D_ARRAY_EXT
:
759 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
760 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
761 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
762 case GL_TEXTURE_2D_ARRAY_EXT
:
763 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
764 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
765 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
766 case GL_TEXTURE_BUFFER
:
767 return ctx
->Extensions
.ARB_texture_buffer_object
768 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
770 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
777 * Return pointer to texture object for given target on current texture unit.
779 struct gl_texture_object
*
780 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
782 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
783 return _mesa_select_tex_object(ctx
, texUnit
, target
);
788 * Get a texture image pointer from a texture object, given a texture
789 * target and mipmap level. The target and level parameters should
790 * have already been error-checked.
792 * \param ctx GL context.
793 * \param texObj texture unit.
794 * \param target texture target.
795 * \param level image level.
797 * \return pointer to the texture image structure, or NULL on failure.
799 struct gl_texture_image
*
800 _mesa_select_tex_image(struct gl_context
*ctx
,
801 const struct gl_texture_object
*texObj
,
802 GLenum target
, GLint level
)
804 const GLuint face
= _mesa_tex_target_to_face(target
);
808 ASSERT(level
< MAX_TEXTURE_LEVELS
);
810 return texObj
->Image
[face
][level
];
815 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
816 * it and install it. Only return NULL if passed a bad parameter or run
819 struct gl_texture_image
*
820 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
821 GLenum target
, GLint level
)
823 struct gl_texture_image
*texImage
;
828 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
830 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
832 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
836 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
844 * Return pointer to the specified proxy texture image.
845 * Note that proxy textures are per-context, not per-texture unit.
846 * \return pointer to texture image or NULL if invalid target, invalid
847 * level, or out of memory.
849 struct gl_texture_image
*
850 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
852 struct gl_texture_image
*texImage
;
859 case GL_PROXY_TEXTURE_1D
:
860 if (level
>= ctx
->Const
.MaxTextureLevels
)
862 texIndex
= TEXTURE_1D_INDEX
;
864 case GL_PROXY_TEXTURE_2D
:
865 if (level
>= ctx
->Const
.MaxTextureLevels
)
867 texIndex
= TEXTURE_2D_INDEX
;
869 case GL_PROXY_TEXTURE_3D
:
870 if (level
>= ctx
->Const
.Max3DTextureLevels
)
872 texIndex
= TEXTURE_3D_INDEX
;
874 case GL_PROXY_TEXTURE_CUBE_MAP
:
875 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
877 texIndex
= TEXTURE_CUBE_INDEX
;
879 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
882 texIndex
= TEXTURE_RECT_INDEX
;
884 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
885 if (level
>= ctx
->Const
.MaxTextureLevels
)
887 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
889 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
890 if (level
>= ctx
->Const
.MaxTextureLevels
)
892 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
898 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
900 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
902 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
905 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
906 /* Set the 'back' pointer */
907 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
914 * Get the maximum number of allowed mipmap levels.
916 * \param ctx GL context.
917 * \param target texture target.
919 * \return the maximum number of allowed mipmap levels for the given
920 * texture target, or zero if passed a bad target.
925 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
929 case GL_PROXY_TEXTURE_1D
:
931 case GL_PROXY_TEXTURE_2D
:
932 return ctx
->Const
.MaxTextureLevels
;
934 case GL_PROXY_TEXTURE_3D
:
935 return ctx
->Const
.Max3DTextureLevels
;
936 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
937 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
938 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
939 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
940 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
941 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
942 case GL_TEXTURE_CUBE_MAP_ARB
:
943 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
944 return ctx
->Extensions
.ARB_texture_cube_map
945 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
946 case GL_TEXTURE_RECTANGLE_NV
:
947 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
948 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
949 case GL_TEXTURE_1D_ARRAY_EXT
:
950 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
951 case GL_TEXTURE_2D_ARRAY_EXT
:
952 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
953 return (ctx
->Extensions
.MESA_texture_array
||
954 ctx
->Extensions
.EXT_texture_array
)
955 ? ctx
->Const
.MaxTextureLevels
: 0;
956 case GL_TEXTURE_BUFFER
:
959 return 0; /* bad target */
965 * Return number of dimensions per mipmap level for the given texture target.
968 _mesa_get_texture_dimensions(GLenum target
)
972 case GL_PROXY_TEXTURE_1D
:
975 case GL_TEXTURE_RECTANGLE
:
976 case GL_TEXTURE_CUBE_MAP
:
977 case GL_PROXY_TEXTURE_2D
:
978 case GL_PROXY_TEXTURE_RECTANGLE
:
979 case GL_PROXY_TEXTURE_CUBE_MAP
:
980 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
981 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
982 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
983 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
984 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
985 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
986 case GL_TEXTURE_1D_ARRAY
:
987 case GL_PROXY_TEXTURE_1D_ARRAY
:
990 case GL_PROXY_TEXTURE_3D
:
991 case GL_TEXTURE_2D_ARRAY
:
992 case GL_PROXY_TEXTURE_2D_ARRAY
:
994 case GL_TEXTURE_BUFFER
:
997 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1006 #if 000 /* not used anymore */
1008 * glTexImage[123]D can accept a NULL image pointer. In this case we
1009 * create a texture image with unspecified image contents per the OpenGL
1013 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1015 const GLint components
= _mesa_components_in_format(format
);
1016 const GLint numPixels
= width
* height
* depth
;
1017 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1021 * Let's see if anyone finds this. If glTexImage2D() is called with
1022 * a NULL image pointer then load the texture image with something
1023 * interesting instead of leaving it indeterminate.
1026 static const char message
[8][32] = {
1027 " X X XXXXX XXX X ",
1028 " XX XX X X X X X ",
1030 " X X XXXX XXX XXXXX ",
1033 " X X XXXXX XXX X X ",
1037 GLubyte
*imgPtr
= data
;
1039 for (h
= 0; h
< depth
; h
++) {
1040 for (i
= 0; i
< height
; i
++) {
1041 GLint srcRow
= 7 - (i
% 8);
1042 for (j
= 0; j
< width
; j
++) {
1043 GLint srcCol
= j
% 32;
1044 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1045 for (k
= 0; k
< components
; k
++) {
1061 * Reset the fields of a gl_texture_image struct to zero.
1063 * \param img texture image structure.
1065 * This is called when a proxy texture test fails, we set all the
1066 * image members (except DriverData) to zero.
1067 * It's also used in glTexImage[123]D as a safeguard to be sure all
1068 * required fields get initialized properly by the Driver.TexImage[123]D
1072 clear_teximage_fields(struct gl_texture_image
*img
)
1075 img
->_BaseFormat
= 0;
1076 img
->InternalFormat
= 0;
1082 if (img
->ImageOffsets
) {
1083 free(img
->ImageOffsets
);
1084 img
->ImageOffsets
= NULL
;
1090 img
->HeightLog2
= 0;
1093 img
->TexFormat
= MESA_FORMAT_NONE
;
1094 img
->FetchTexelc
= NULL
;
1095 img
->FetchTexelf
= NULL
;
1100 * Initialize basic fields of the gl_texture_image struct.
1102 * \param ctx GL context.
1103 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1104 * \param img texture image structure to be initialized.
1105 * \param width image width.
1106 * \param height image height.
1107 * \param depth image depth.
1108 * \param border image border.
1109 * \param internalFormat internal format.
1110 * \param format the actual hardware format (one of MESA_FORMAT_*)
1112 * Fills in the fields of \p img with the given information.
1113 * Note: width, height and depth include the border.
1116 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1117 struct gl_texture_image
*img
,
1118 GLsizei width
, GLsizei height
, GLsizei depth
,
1119 GLint border
, GLenum internalFormat
,
1126 ASSERT(height
>= 0);
1129 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1130 ASSERT(img
->_BaseFormat
> 0);
1131 img
->InternalFormat
= internalFormat
;
1132 img
->Border
= border
;
1134 img
->Height
= height
;
1137 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1138 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1140 if (height
== 1) { /* 1-D texture */
1142 img
->HeightLog2
= 0;
1145 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1146 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1149 if (depth
== 1) { /* 2-D texture */
1154 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1155 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1158 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1160 if ((width
== 1 || _mesa_is_pow_two(img
->Width2
)) &&
1161 (height
== 1 || _mesa_is_pow_two(img
->Height2
)) &&
1162 (depth
== 1 || _mesa_is_pow_two(img
->Depth2
)))
1163 img
->_IsPowerOfTwo
= GL_TRUE
;
1165 img
->_IsPowerOfTwo
= GL_FALSE
;
1167 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1168 img
->RowStride
= width
;
1169 /* Allocate the ImageOffsets array and initialize to typical values.
1170 * We allocate the array for 1D/2D textures too in order to avoid special-
1171 * case code in the texstore routines.
1173 if (img
->ImageOffsets
)
1174 free(img
->ImageOffsets
);
1175 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1176 for (i
= 0; i
< depth
; i
++) {
1177 img
->ImageOffsets
[i
] = i
* width
* height
;
1180 /* Compute Width/Height/DepthScale for mipmap lod computation */
1181 if (target
== GL_TEXTURE_RECTANGLE_NV
) {
1182 /* scale = 1.0 since texture coords directly map to texels */
1183 img
->WidthScale
= 1.0;
1184 img
->HeightScale
= 1.0;
1185 img
->DepthScale
= 1.0;
1188 img
->WidthScale
= (GLfloat
) img
->Width
;
1189 img
->HeightScale
= (GLfloat
) img
->Height
;
1190 img
->DepthScale
= (GLfloat
) img
->Depth
;
1193 img
->TexFormat
= format
;
1195 dims
= _mesa_get_texture_dimensions(target
);
1197 _mesa_set_fetch_functions(img
, dims
);
1202 * Free and clear fields of the gl_texture_image struct.
1204 * \param ctx GL context.
1205 * \param texImage texture image structure to be cleared.
1207 * After the call, \p texImage will have no data associated with it. Its
1208 * fields are cleared so that its parent object will test incomplete.
1211 _mesa_clear_texture_image(struct gl_context
*ctx
,
1212 struct gl_texture_image
*texImage
)
1214 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1215 clear_teximage_fields(texImage
);
1220 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1221 * level, width, height and depth against the ctx->Const limits for textures.
1223 * A hardware driver might override this function if, for example, the
1224 * max 3D texture size is 512x512x64 (i.e. not a cube).
1226 * Note that width, height, depth == 0 is not an error. However, a
1227 * texture with zero width/height/depth will be considered "incomplete"
1228 * and texturing will effectively be disabled.
1230 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1231 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1232 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1233 * \param level as passed to glTexImage
1234 * \param internalFormat as passed to glTexImage
1235 * \param format as passed to glTexImage
1236 * \param type as passed to glTexImage
1237 * \param width as passed to glTexImage
1238 * \param height as passed to glTexImage
1239 * \param depth as passed to glTexImage
1240 * \param border as passed to glTexImage
1241 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1244 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1245 GLint internalFormat
, GLenum format
, GLenum type
,
1246 GLint width
, GLint height
, GLint depth
, GLint border
)
1250 (void) internalFormat
;
1255 case GL_PROXY_TEXTURE_1D
:
1256 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1257 if (width
< 2 * border
|| width
> 2 + maxSize
)
1259 if (level
>= ctx
->Const
.MaxTextureLevels
)
1261 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1262 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1267 case GL_PROXY_TEXTURE_2D
:
1268 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1269 if (width
< 2 * border
|| width
> 2 + maxSize
)
1271 if (height
< 2 * border
|| height
> 2 + maxSize
)
1273 if (level
>= ctx
->Const
.MaxTextureLevels
)
1275 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1276 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1278 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1283 case GL_PROXY_TEXTURE_3D
:
1284 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1285 if (width
< 2 * border
|| width
> 2 + maxSize
)
1287 if (height
< 2 * border
|| height
> 2 + maxSize
)
1289 if (depth
< 2 * border
|| depth
> 2 + maxSize
)
1291 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1293 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1294 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1296 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1298 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1303 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1304 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1305 if (width
< 0 || width
> maxSize
)
1307 if (height
< 0 || height
> maxSize
)
1313 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1314 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1315 if (width
< 2 * border
|| width
> 2 + maxSize
)
1317 if (height
< 2 * border
|| height
> 2 + maxSize
)
1319 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1321 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1322 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1324 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1329 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1330 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1331 if (width
< 2 * border
|| width
> 2 + maxSize
)
1333 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1335 if (level
>= ctx
->Const
.MaxTextureLevels
)
1337 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1338 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1343 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1344 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1345 if (width
< 2 * border
|| width
> 2 + maxSize
)
1347 if (height
< 2 * border
|| height
> 2 + maxSize
)
1349 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1351 if (level
>= ctx
->Const
.MaxTextureLevels
)
1353 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1354 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1356 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1362 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1369 * Check if the memory used by the texture would exceed the driver's limit.
1370 * This lets us support a max 3D texture size of 8K (for example) but
1371 * prevents allocating a full 8K x 8K x 8K texture.
1372 * XXX this could be rolled into the proxy texture size test (above) but
1373 * we don't have the actual texture internal format at that point.
1376 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1377 GLint width
, GLint height
, GLint depth
)
1379 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1380 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1381 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1387 * Helper function to determine whether a target and specific compression
1388 * format are supported.
1391 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1394 (void) intFormat
; /* not used yet */
1398 case GL_PROXY_TEXTURE_2D
:
1399 return GL_TRUE
; /* true for any compressed format so far */
1400 case GL_PROXY_TEXTURE_CUBE_MAP
:
1401 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1402 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1403 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1404 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1405 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1406 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1407 return ctx
->Extensions
.ARB_texture_cube_map
;
1408 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1409 case GL_TEXTURE_2D_ARRAY_EXT
:
1410 return (ctx
->Extensions
.MESA_texture_array
||
1411 ctx
->Extensions
.EXT_texture_array
);
1419 * Check if the given texture target value is legal for a
1420 * glTexImage1/2/3D call.
1423 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1429 case GL_PROXY_TEXTURE_1D
:
1437 case GL_PROXY_TEXTURE_2D
:
1439 case GL_PROXY_TEXTURE_CUBE_MAP
:
1440 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1441 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1442 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1443 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1444 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1445 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1446 return ctx
->Extensions
.ARB_texture_cube_map
;
1447 case GL_TEXTURE_RECTANGLE_NV
:
1448 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1449 return ctx
->Extensions
.NV_texture_rectangle
;
1450 case GL_TEXTURE_1D_ARRAY_EXT
:
1451 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1452 return (ctx
->Extensions
.MESA_texture_array
||
1453 ctx
->Extensions
.EXT_texture_array
);
1460 case GL_PROXY_TEXTURE_3D
:
1462 case GL_TEXTURE_2D_ARRAY_EXT
:
1463 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1464 return (ctx
->Extensions
.MESA_texture_array
||
1465 ctx
->Extensions
.EXT_texture_array
);
1470 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1477 * Check if the given texture target value is legal for a
1478 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1479 * The difference compared to legal_teximage_target() above is that
1480 * proxy targets are not supported.
1483 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1487 return target
== GL_TEXTURE_1D
;
1492 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1493 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1494 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1495 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1496 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1497 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1498 return ctx
->Extensions
.ARB_texture_cube_map
;
1499 case GL_TEXTURE_RECTANGLE_NV
:
1500 return ctx
->Extensions
.NV_texture_rectangle
;
1501 case GL_TEXTURE_1D_ARRAY_EXT
:
1502 return (ctx
->Extensions
.MESA_texture_array
||
1503 ctx
->Extensions
.EXT_texture_array
);
1511 case GL_TEXTURE_2D_ARRAY_EXT
:
1512 return (ctx
->Extensions
.MESA_texture_array
||
1513 ctx
->Extensions
.EXT_texture_array
);
1518 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1526 * Test the glTexImage[123]D() parameters for errors.
1528 * \param ctx GL context.
1529 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1530 * \param target texture target given by the user.
1531 * \param level image level given by the user.
1532 * \param internalFormat internal format given by the user.
1533 * \param format pixel data format given by the user.
1534 * \param type pixel data type given by the user.
1535 * \param width image width given by the user.
1536 * \param height image height given by the user.
1537 * \param depth image depth given by the user.
1538 * \param border image border given by the user.
1540 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1542 * Verifies each of the parameters against the constants specified in
1543 * __struct gl_contextRec::Const and the supported extensions, and according
1544 * to the OpenGL specification.
1547 texture_error_check( struct gl_context
*ctx
,
1548 GLuint dimensions
, GLenum target
,
1549 GLint level
, GLint internalFormat
,
1550 GLenum format
, GLenum type
,
1551 GLint width
, GLint height
,
1552 GLint depth
, GLint border
)
1554 const GLenum proxyTarget
= get_proxy_target(target
);
1555 const GLboolean isProxy
= target
== proxyTarget
;
1556 GLboolean sizeOK
= GL_TRUE
;
1557 GLboolean colorFormat
, indexFormat
;
1559 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1560 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1562 _mesa_error(ctx
, GL_INVALID_VALUE
,
1563 "glTexImage%dD(level=%d)", dimensions
, level
);
1569 if (border
< 0 || border
> 1 ||
1570 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1571 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1573 _mesa_error(ctx
, GL_INVALID_VALUE
,
1574 "glTexImage%dD(border=%d)", dimensions
, border
);
1579 if (width
< 0 || height
< 0 || depth
< 0) {
1581 _mesa_error(ctx
, GL_INVALID_VALUE
,
1582 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1587 /* Do this simple check before calling the TestProxyTexImage() function */
1588 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1589 sizeOK
= (width
== height
);
1593 * Use the proxy texture driver hook to see if the size/level/etc are
1596 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1597 internalFormat
, format
,
1598 type
, width
, height
,
1602 _mesa_error(ctx
, GL_INVALID_VALUE
,
1603 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1604 dimensions
, level
, width
, height
, depth
);
1609 /* Check internalFormat */
1610 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1612 _mesa_error(ctx
, GL_INVALID_VALUE
,
1613 "glTexImage%dD(internalFormat=%s)",
1614 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1619 /* Check incoming image format and type */
1620 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1621 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1622 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1623 * GL_EXT_texture_integer extension, some combinations should generate
1624 * GL_INVALID_ENUM instead (grr!).
1627 GLenum error
= _mesa_is_integer_format(format
)
1628 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1629 _mesa_error(ctx
, error
,
1630 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1631 dimensions
, format
, type
);
1636 /* make sure internal format and format basically agree */
1637 colorFormat
= _mesa_is_color_format(format
);
1638 indexFormat
= _mesa_is_index_format(format
);
1639 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1640 (_mesa_is_index_format(internalFormat
) && !indexFormat
) ||
1641 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1642 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1643 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1644 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1646 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1647 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1648 dimensions
, internalFormat
, format
);
1652 /* additional checks for ycbcr textures */
1653 if (internalFormat
== GL_YCBCR_MESA
) {
1654 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1655 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1656 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1658 _mesa_snprintf(message
, sizeof(message
),
1659 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1660 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1661 return GL_TRUE
; /* error */
1663 if (target
!= GL_TEXTURE_2D
&&
1664 target
!= GL_PROXY_TEXTURE_2D
&&
1665 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1666 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1668 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1674 _mesa_snprintf(message
, sizeof(message
),
1675 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1676 dimensions
, border
);
1677 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1683 /* additional checks for depth textures */
1684 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1685 /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */
1686 if (target
!= GL_TEXTURE_1D
&&
1687 target
!= GL_PROXY_TEXTURE_1D
&&
1688 target
!= GL_TEXTURE_2D
&&
1689 target
!= GL_PROXY_TEXTURE_2D
&&
1690 target
!= GL_TEXTURE_1D_ARRAY
&&
1691 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1692 target
!= GL_TEXTURE_2D_ARRAY
&&
1693 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1694 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1695 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1697 _mesa_error(ctx
, GL_INVALID_ENUM
,
1698 "glTexImage(target/internalFormat)");
1703 /* additional checks for compressed textures */
1704 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1705 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1707 _mesa_error(ctx
, GL_INVALID_ENUM
,
1708 "glTexImage%dD(target)", dimensions
);
1713 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1714 "glTexImage%dD(border!=0)", dimensions
);
1720 /* additional checks for integer textures */
1721 if (ctx
->Extensions
.EXT_texture_integer
&&
1722 (_mesa_is_integer_format(format
) !=
1723 _mesa_is_integer_format(internalFormat
))) {
1725 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1726 "glTexImage%dD(integer/non-integer format mismatch)",
1732 /* if we get here, the parameters are OK */
1738 * Test glTexSubImage[123]D() parameters for errors.
1740 * \param ctx GL context.
1741 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1742 * \param target texture target given by the user.
1743 * \param level image level given by the user.
1744 * \param xoffset sub-image x offset given by the user.
1745 * \param yoffset sub-image y offset given by the user.
1746 * \param zoffset sub-image z offset given by the user.
1747 * \param format pixel data format given by the user.
1748 * \param type pixel data type given by the user.
1749 * \param width image width given by the user.
1750 * \param height image height given by the user.
1751 * \param depth image depth given by the user.
1753 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1755 * Verifies each of the parameters against the constants specified in
1756 * __struct gl_contextRec::Const and the supported extensions, and according
1757 * to the OpenGL specification.
1760 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1761 GLenum target
, GLint level
,
1762 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1763 GLint width
, GLint height
, GLint depth
,
1764 GLenum format
, GLenum type
)
1766 /* Basic level check */
1767 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1768 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1772 /* Check for negative sizes */
1774 _mesa_error(ctx
, GL_INVALID_VALUE
,
1775 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1778 if (height
< 0 && dimensions
> 1) {
1779 _mesa_error(ctx
, GL_INVALID_VALUE
,
1780 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1783 if (depth
< 0 && dimensions
> 2) {
1784 _mesa_error(ctx
, GL_INVALID_VALUE
,
1785 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1789 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1790 /* As with the glTexImage2D check above, the error code here
1791 * depends on texture integer.
1793 GLenum error
= _mesa_is_integer_format(format
)
1794 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1795 _mesa_error(ctx
, error
,
1796 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1797 dimensions
, format
, type
);
1806 * Do second part of glTexSubImage which depends on the destination texture.
1807 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1810 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1811 GLenum target
, GLint level
,
1812 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1813 GLint width
, GLint height
, GLint depth
,
1814 GLenum format
, GLenum type
,
1815 const struct gl_texture_image
*destTex
)
1818 /* undefined image level */
1819 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1823 if (xoffset
< -((GLint
)destTex
->Border
)) {
1824 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1828 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1829 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1833 if (dimensions
> 1) {
1834 if (yoffset
< -((GLint
)destTex
->Border
)) {
1835 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1839 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1840 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1845 if (dimensions
> 2) {
1846 if (zoffset
< -((GLint
)destTex
->Border
)) {
1847 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1850 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1851 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1856 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1859 /* do tests which depend on compression block size */
1860 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1862 /* offset must be multiple of block size */
1863 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1864 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1865 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1866 dimensions
, xoffset
, yoffset
);
1869 /* size must be multiple of bw by bh or equal to whole texture size */
1870 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1871 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1872 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1875 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1876 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1877 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1887 * Test glCopyTexImage[12]D() parameters for errors.
1889 * \param ctx GL context.
1890 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1891 * \param target texture target given by the user.
1892 * \param level image level given by the user.
1893 * \param internalFormat internal format given by the user.
1894 * \param width image width given by the user.
1895 * \param height image height given by the user.
1896 * \param border texture border.
1898 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1900 * Verifies each of the parameters against the constants specified in
1901 * __struct gl_contextRec::Const and the supported extensions, and according
1902 * to the OpenGL specification.
1905 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1906 GLenum target
, GLint level
, GLint internalFormat
,
1907 GLint width
, GLint height
, GLint border
)
1909 const GLenum proxyTarget
= get_proxy_target(target
);
1910 const GLenum type
= GL_FLOAT
;
1915 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1916 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1917 dimensions
, _mesa_lookup_enum_by_nr(target
));
1921 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1922 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1923 _mesa_error(ctx
, GL_INVALID_VALUE
,
1924 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1928 /* Check that the source buffer is complete */
1929 if (ctx
->ReadBuffer
->Name
) {
1930 if (ctx
->ReadBuffer
->_Status
== 0) {
1931 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1933 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1934 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1935 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1941 if (border
< 0 || border
> 1 ||
1942 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1943 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1947 format
= _mesa_base_tex_format(ctx
, internalFormat
);
1949 _mesa_error(ctx
, GL_INVALID_VALUE
,
1950 "glCopyTexImage%dD(internalFormat)", dimensions
);
1954 if (!_mesa_source_buffer_exists(ctx
, format
)) {
1955 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1956 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1960 /* Do size, level checking */
1961 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1962 ? (width
== height
) : 1;
1964 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1965 internalFormat
, format
,
1966 type
, width
, height
,
1970 if (dimensions
== 1) {
1971 _mesa_error(ctx
, GL_INVALID_VALUE
,
1972 "glCopyTexImage1D(width=%d)", width
);
1975 ASSERT(dimensions
== 2);
1976 _mesa_error(ctx
, GL_INVALID_VALUE
,
1977 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1982 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1983 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1984 _mesa_error(ctx
, GL_INVALID_ENUM
,
1985 "glCopyTexImage%dD(target)", dimensions
);
1989 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1990 "glCopyTexImage%dD(border!=0)", dimensions
);
1994 else if (_mesa_is_depth_format(internalFormat
)) {
1995 /* make sure we have depth/stencil buffers */
1996 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
1997 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1998 "glCopyTexImage%dD(no depth)", dimensions
);
2002 else if (_mesa_is_depthstencil_format(internalFormat
)) {
2003 /* make sure we have depth/stencil buffers */
2004 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2005 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2006 "glCopyTexImage%dD(no depth/stencil buffer)", dimensions
);
2011 /* if we get here, the parameters are OK */
2017 * Test glCopyTexSubImage[12]D() parameters for errors.
2018 * Note that this is the first part of error checking.
2019 * See also copytexsubimage_error_check2() below for the second part.
2021 * \param ctx GL context.
2022 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2023 * \param target texture target given by the user.
2024 * \param level image level given by the user.
2026 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2029 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2030 GLenum target
, GLint level
)
2032 /* Check that the source buffer is complete */
2033 if (ctx
->ReadBuffer
->Name
) {
2034 if (ctx
->ReadBuffer
->_Status
== 0) {
2035 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2037 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2038 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2039 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2044 /* check target (proxies not allowed) */
2045 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2046 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2047 dimensions
, _mesa_lookup_enum_by_nr(target
));
2052 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2053 _mesa_error(ctx
, GL_INVALID_VALUE
,
2054 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2063 * Second part of error checking for glCopyTexSubImage[12]D().
2064 * \param xoffset sub-image x offset given by the user.
2065 * \param yoffset sub-image y offset given by the user.
2066 * \param zoffset sub-image z offset given by the user.
2067 * \param width image width given by the user.
2068 * \param height image height given by the user.
2071 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2072 GLenum target
, GLint level
,
2073 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2074 GLsizei width
, GLsizei height
,
2075 const struct gl_texture_image
*teximage
)
2077 /* check that dest tex image exists */
2079 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2080 "glCopyTexSubImage%dD(undefined texture level: %d)",
2087 _mesa_error(ctx
, GL_INVALID_VALUE
,
2088 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2091 if (dimensions
> 1 && height
< 0) {
2092 _mesa_error(ctx
, GL_INVALID_VALUE
,
2093 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2097 /* check x/y offsets */
2098 if (xoffset
< -((GLint
)teximage
->Border
)) {
2099 _mesa_error(ctx
, GL_INVALID_VALUE
,
2100 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2103 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2104 _mesa_error(ctx
, GL_INVALID_VALUE
,
2105 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2108 if (dimensions
> 1) {
2109 if (yoffset
< -((GLint
)teximage
->Border
)) {
2110 _mesa_error(ctx
, GL_INVALID_VALUE
,
2111 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2114 /* NOTE: we're adding the border here, not subtracting! */
2115 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2116 _mesa_error(ctx
, GL_INVALID_VALUE
,
2117 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2122 /* check z offset */
2123 if (dimensions
> 2) {
2124 if (zoffset
< -((GLint
)teximage
->Border
)) {
2125 _mesa_error(ctx
, GL_INVALID_VALUE
,
2126 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2129 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2130 _mesa_error(ctx
, GL_INVALID_VALUE
,
2131 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2136 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2137 /* offset must be multiple of 4 */
2138 if ((xoffset
& 3) || (yoffset
& 3)) {
2139 _mesa_error(ctx
, GL_INVALID_VALUE
,
2140 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2143 /* size must be multiple of 4 */
2144 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2145 _mesa_error(ctx
, GL_INVALID_VALUE
,
2146 "glCopyTexSubImage%dD(width)", dimensions
);
2149 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2150 _mesa_error(ctx
, GL_INVALID_VALUE
,
2151 "glCopyTexSubImage%dD(height)", dimensions
);
2156 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2157 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2161 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2162 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2163 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2164 dimensions
, teximage
->_BaseFormat
);
2168 if (teximage
->_BaseFormat
== GL_DEPTH_COMPONENT
) {
2169 if (!ctx
->ReadBuffer
->_DepthBuffer
) {
2170 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2171 "glCopyTexSubImage%dD(no depth buffer)",
2176 else if (teximage
->_BaseFormat
== GL_DEPTH_STENCIL_EXT
) {
2177 if (!ctx
->ReadBuffer
->_DepthBuffer
|| !ctx
->ReadBuffer
->_StencilBuffer
) {
2178 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2179 "glCopyTexSubImage%dD(no depth/stencil buffer)",
2185 /* If copying into an integer texture, the source buffer must also be
2188 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2189 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2190 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2191 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2192 "glCopyTexSubImage%dD(source buffer is not integer format)",
2198 /* if we get here, the parameters are OK */
2203 /** Callback info for walking over FBO hash table */
2206 struct gl_context
*ctx
;
2207 struct gl_texture_object
*texObj
;
2213 * Check render to texture callback. Called from _mesa_HashWalk().
2216 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2218 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2219 const struct cb_info
*info
= (struct cb_info
*) userData
;
2220 struct gl_context
*ctx
= info
->ctx
;
2221 const struct gl_texture_object
*texObj
= info
->texObj
;
2222 const GLuint level
= info
->level
, face
= info
->face
;
2224 /* If this is a user-created FBO */
2227 /* check if any of the FBO's attachments point to 'texObj' */
2228 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2229 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2230 if (att
->Type
== GL_TEXTURE
&&
2231 att
->Texture
== texObj
&&
2232 att
->TextureLevel
== level
&&
2233 att
->CubeMapFace
== face
) {
2234 ASSERT(_mesa_get_attachment_teximage(att
));
2235 /* Tell driver about the new renderbuffer texture */
2236 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2237 /* Mark fb status as indeterminate to force re-validation */
2246 * When a texture image is specified we have to check if it's bound to
2247 * any framebuffer objects (render to texture) in order to detect changes
2248 * in size or format since that effects FBO completeness.
2249 * Any FBOs rendering into the texture must be re-validated.
2252 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2253 GLuint face
, GLuint level
)
2255 /* Only check this texture if it's been marked as RenderToTexture */
2256 if (texObj
->_RenderToTexture
) {
2257 struct cb_info info
;
2259 info
.texObj
= texObj
;
2262 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2268 * If the texture object's GenerateMipmap flag is set and we've
2269 * changed the texture base level image, regenerate the rest of the
2270 * mipmap levels now.
2273 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2274 struct gl_texture_object
*texObj
, GLint level
)
2276 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2277 if (texObj
->GenerateMipmap
&&
2278 level
== texObj
->BaseLevel
&&
2279 level
< texObj
->MaxLevel
) {
2280 ASSERT(ctx
->Driver
.GenerateMipmap
);
2281 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2286 /** Debug helper: override the user-requested internal format */
2288 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2291 if (internalFormat
== GL_RGBA16F_ARB
||
2292 internalFormat
== GL_RGBA32F_ARB
) {
2293 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2296 else if (internalFormat
== GL_RGB16F_ARB
||
2297 internalFormat
== GL_RGB32F_ARB
) {
2298 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2301 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2302 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2303 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2304 return GL_LUMINANCE_ALPHA
;
2306 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2307 internalFormat
== GL_LUMINANCE32F_ARB
) {
2308 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2309 return GL_LUMINANCE
;
2311 else if (internalFormat
== GL_ALPHA16F_ARB
||
2312 internalFormat
== GL_ALPHA32F_ARB
) {
2313 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2317 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2318 internalFormat = GL_RGBA;
2322 return internalFormat
;
2325 return internalFormat
;
2331 * Choose the actual hardware format for a texture image.
2332 * Try to use the same format as the previous image level when possible.
2333 * Otherwise, ask the driver for the best format.
2334 * It's important to try to choose a consistant format for all levels
2335 * for efficient texture memory layout/allocation. In particular, this
2336 * comes up during automatic mipmap generation.
2339 _mesa_choose_texture_format(struct gl_context
*ctx
,
2340 struct gl_texture_object
*texObj
,
2341 GLenum target
, GLint level
,
2342 GLenum internalFormat
, GLenum format
, GLenum type
)
2346 /* see if we've already chosen a format for the previous level */
2348 struct gl_texture_image
*prevImage
=
2349 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2350 /* See if the prev level is defined and has an internal format which
2351 * matches the new internal format.
2354 prevImage
->Width
> 0 &&
2355 prevImage
->InternalFormat
== internalFormat
) {
2356 /* use the same format */
2357 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2358 return prevImage
->TexFormat
;
2362 /* choose format from scratch */
2363 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2364 ASSERT(f
!= MESA_FORMAT_NONE
);
2370 * Common code to implement all the glTexImage1D/2D/3D functions.
2373 teximage(struct gl_context
*ctx
, GLuint dims
,
2374 GLenum target
, GLint level
, GLint internalFormat
,
2375 GLsizei width
, GLsizei height
, GLsizei depth
,
2376 GLint border
, GLenum format
, GLenum type
,
2377 const GLvoid
*pixels
)
2381 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2383 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2384 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2386 _mesa_lookup_enum_by_nr(target
), level
,
2387 _mesa_lookup_enum_by_nr(internalFormat
),
2388 width
, height
, depth
, border
,
2389 _mesa_lookup_enum_by_nr(format
),
2390 _mesa_lookup_enum_by_nr(type
), pixels
);
2392 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2394 /* target error checking */
2395 if (!legal_teximage_target(ctx
, dims
, target
)) {
2396 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2397 dims
, _mesa_lookup_enum_by_nr(target
));
2401 /* general error checking */
2402 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2403 format
, type
, width
, height
, depth
, border
);
2405 if (_mesa_is_proxy_texture(target
)) {
2406 /* Proxy texture: just clear or set state depending on error checking */
2407 struct gl_texture_image
*texImage
=
2408 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2411 /* when error, clear all proxy texture image parameters */
2413 clear_teximage_fields(texImage
);
2416 /* no error, set the tex image parameters */
2417 struct gl_texture_object
*texObj
=
2418 _mesa_get_current_tex_object(ctx
, target
);
2419 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2424 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2425 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2426 depth
, border
, internalFormat
,
2429 else if (texImage
) {
2430 clear_teximage_fields(texImage
);
2435 /* non-proxy target */
2436 const GLuint face
= _mesa_tex_target_to_face(target
);
2437 struct gl_texture_object
*texObj
;
2438 struct gl_texture_image
*texImage
;
2441 return; /* error was recorded */
2444 if (ctx
->NewState
& _NEW_PIXEL
)
2445 _mesa_update_state(ctx
);
2447 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2449 _mesa_lock_texture(ctx
, texObj
);
2451 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2454 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2457 gl_format texFormat
;
2459 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2461 ASSERT(texImage
->Data
== NULL
);
2462 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2463 internalFormat
, format
,
2466 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2467 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2468 width
, height
, depth
,
2469 border
, internalFormat
, texFormat
);
2471 /* Give the texture to the driver. <pixels> may be null. */
2472 ASSERT(ctx
->Driver
.TexImage3D
);
2475 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2476 width
, border
, format
,
2477 type
, pixels
, &ctx
->Unpack
, texObj
,
2481 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2482 width
, height
, border
, format
,
2483 type
, pixels
, &ctx
->Unpack
, texObj
,
2487 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2488 width
, height
, depth
, border
, format
,
2489 type
, pixels
, &ctx
->Unpack
, texObj
,
2493 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2496 check_gen_mipmap(ctx
, target
, texObj
, level
);
2498 update_fbo_texture(ctx
, texObj
, face
, level
);
2501 texObj
->_Complete
= GL_FALSE
;
2502 ctx
->NewState
|= _NEW_TEXTURE
;
2505 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2509 _mesa_unlock_texture(ctx
, texObj
);
2515 * Called from the API. Note that width includes the border.
2518 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2519 GLsizei width
, GLint border
, GLenum format
,
2520 GLenum type
, const GLvoid
*pixels
)
2522 GET_CURRENT_CONTEXT(ctx
);
2523 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2524 border
, format
, type
, pixels
);
2529 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2530 GLsizei width
, GLsizei height
, GLint border
,
2531 GLenum format
, GLenum type
,
2532 const GLvoid
*pixels
)
2534 GET_CURRENT_CONTEXT(ctx
);
2535 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2536 border
, format
, type
, pixels
);
2541 * Called by the API or display list executor.
2542 * Note that width and height include the border.
2545 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2546 GLsizei width
, GLsizei height
, GLsizei depth
,
2547 GLint border
, GLenum format
, GLenum type
,
2548 const GLvoid
*pixels
)
2550 GET_CURRENT_CONTEXT(ctx
);
2551 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2552 border
, format
, type
, pixels
);
2557 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2558 GLsizei width
, GLsizei height
, GLsizei depth
,
2559 GLint border
, GLenum format
, GLenum type
,
2560 const GLvoid
*pixels
)
2562 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2563 depth
, border
, format
, type
, pixels
);
2567 #if FEATURE_OES_EGL_image
2569 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2571 struct gl_texture_object
*texObj
;
2572 struct gl_texture_image
*texImage
;
2573 GET_CURRENT_CONTEXT(ctx
);
2574 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2576 if (!ctx
->Extensions
.OES_EGL_image
) {
2577 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2578 "glEGLImageTargetTexture2DOES(unsupported)");
2582 if (target
!= GL_TEXTURE_2D
) {
2583 _mesa_error(ctx
, GL_INVALID_ENUM
,
2584 "glEGLImageTargetTexture2D(target=%d)", target
);
2588 if (ctx
->NewState
& _NEW_PIXEL
)
2589 _mesa_update_state(ctx
);
2591 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2592 _mesa_lock_texture(ctx
, texObj
);
2594 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2596 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2598 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2600 ASSERT(texImage
->Data
== NULL
);
2601 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2602 texObj
, texImage
, image
);
2605 texObj
->_Complete
= GL_FALSE
;
2606 ctx
->NewState
|= _NEW_TEXTURE
;
2608 _mesa_unlock_texture(ctx
, texObj
);
2616 * Implement all the glTexSubImage1/2/3D() functions.
2619 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2620 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2621 GLsizei width
, GLsizei height
, GLsizei depth
,
2622 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2624 struct gl_texture_object
*texObj
;
2625 struct gl_texture_image
*texImage
;
2627 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2629 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2630 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2632 _mesa_lookup_enum_by_nr(target
), level
,
2633 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2634 _mesa_lookup_enum_by_nr(format
),
2635 _mesa_lookup_enum_by_nr(type
), pixels
);
2637 /* check target (proxies not allowed) */
2638 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2639 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2640 dims
, _mesa_lookup_enum_by_nr(target
));
2644 if (ctx
->NewState
& _NEW_PIXEL
)
2645 _mesa_update_state(ctx
);
2647 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2648 width
, height
, depth
, format
, type
)) {
2649 return; /* error was detected */
2652 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2654 _mesa_lock_texture(ctx
, texObj
);
2656 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2658 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2659 xoffset
, yoffset
, zoffset
,
2660 width
, height
, depth
,
2661 format
, type
, texImage
)) {
2662 /* error was recorded */
2664 else if (width
> 0 && height
> 0 && depth
> 0) {
2665 /* If we have a border, offset=-1 is legal. Bias by border width. */
2668 zoffset
+= texImage
->Border
;
2671 yoffset
+= texImage
->Border
;
2674 xoffset
+= texImage
->Border
;
2679 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2681 format
, type
, pixels
,
2682 &ctx
->Unpack
, texObj
, texImage
);
2685 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2686 xoffset
, yoffset
, width
, height
,
2687 format
, type
, pixels
,
2688 &ctx
->Unpack
, texObj
, texImage
);
2691 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2692 xoffset
, yoffset
, zoffset
,
2693 width
, height
, depth
,
2694 format
, type
, pixels
,
2695 &ctx
->Unpack
, texObj
, texImage
);
2698 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2701 check_gen_mipmap(ctx
, target
, texObj
, level
);
2703 ctx
->NewState
|= _NEW_TEXTURE
;
2706 _mesa_unlock_texture(ctx
, texObj
);
2711 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2712 GLint xoffset
, GLsizei width
,
2713 GLenum format
, GLenum type
,
2714 const GLvoid
*pixels
)
2716 GET_CURRENT_CONTEXT(ctx
);
2717 texsubimage(ctx
, 1, target
, level
,
2720 format
, type
, pixels
);
2725 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2726 GLint xoffset
, GLint yoffset
,
2727 GLsizei width
, GLsizei height
,
2728 GLenum format
, GLenum type
,
2729 const GLvoid
*pixels
)
2731 GET_CURRENT_CONTEXT(ctx
);
2732 texsubimage(ctx
, 2, target
, level
,
2733 xoffset
, yoffset
, 0,
2735 format
, type
, pixels
);
2741 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2742 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2743 GLsizei width
, GLsizei height
, GLsizei depth
,
2744 GLenum format
, GLenum type
,
2745 const GLvoid
*pixels
)
2747 GET_CURRENT_CONTEXT(ctx
);
2748 texsubimage(ctx
, 3, target
, level
,
2749 xoffset
, yoffset
, zoffset
,
2750 width
, height
, depth
,
2751 format
, type
, pixels
);
2757 * Implement the glCopyTexImage1/2D() functions.
2760 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2761 GLenum target
, GLint level
, GLenum internalFormat
,
2762 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2764 struct gl_texture_object
*texObj
;
2765 struct gl_texture_image
*texImage
;
2766 const GLuint face
= _mesa_tex_target_to_face(target
);
2768 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2770 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2771 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2773 _mesa_lookup_enum_by_nr(target
), level
,
2774 _mesa_lookup_enum_by_nr(internalFormat
),
2775 x
, y
, width
, height
, border
);
2777 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2778 _mesa_update_state(ctx
);
2780 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2781 width
, height
, border
))
2784 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2786 _mesa_lock_texture(ctx
, texObj
);
2788 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2791 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2794 /* choose actual hw format */
2795 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2800 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2801 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2803 /* Free old texture image */
2804 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2806 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2807 border
, internalFormat
, texFormat
);
2809 /* Allocate texture memory (no pixel data yet) */
2811 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2812 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2813 &ctx
->Unpack
, texObj
, texImage
);
2816 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2817 width
, height
, border
, GL_NONE
, GL_NONE
,
2818 NULL
, &ctx
->Unpack
, texObj
, texImage
);
2821 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2824 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
, dstX
,
2828 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, dstX
, dstY
,
2829 srcX
, srcY
, width
, height
);
2832 check_gen_mipmap(ctx
, target
, texObj
, level
);
2834 update_fbo_texture(ctx
, texObj
, face
, level
);
2837 texObj
->_Complete
= GL_FALSE
;
2838 ctx
->NewState
|= _NEW_TEXTURE
;
2841 /* probably too large of image */
2842 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2846 _mesa_unlock_texture(ctx
, texObj
);
2852 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2853 GLenum internalFormat
,
2855 GLsizei width
, GLint border
)
2857 GET_CURRENT_CONTEXT(ctx
);
2858 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2864 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2865 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2868 GET_CURRENT_CONTEXT(ctx
);
2869 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2870 x
, y
, width
, height
, border
);
2876 * Implementation for glCopyTexSubImage1/2/3D() functions.
2879 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2880 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2881 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2883 struct gl_texture_object
*texObj
;
2884 struct gl_texture_image
*texImage
;
2886 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2888 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2889 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2891 _mesa_lookup_enum_by_nr(target
),
2892 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2894 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2895 _mesa_update_state(ctx
);
2897 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2900 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2902 _mesa_lock_texture(ctx
, texObj
);
2904 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2906 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2907 zoffset
, width
, height
, texImage
)) {
2908 /* error was recored */
2911 /* If we have a border, offset=-1 is legal. Bias by border width. */
2914 zoffset
+= texImage
->Border
;
2917 yoffset
+= texImage
->Border
;
2920 xoffset
+= texImage
->Border
;
2923 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2927 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2928 xoffset
, x
, y
, width
);
2931 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2933 x
, y
, width
, height
);
2936 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2937 xoffset
, yoffset
, zoffset
,
2938 x
, y
, width
, height
);
2941 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
2944 check_gen_mipmap(ctx
, target
, texObj
, level
);
2946 ctx
->NewState
|= _NEW_TEXTURE
;
2950 _mesa_unlock_texture(ctx
, texObj
);
2955 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2956 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2958 GET_CURRENT_CONTEXT(ctx
);
2959 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
2965 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2966 GLint xoffset
, GLint yoffset
,
2967 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2969 GET_CURRENT_CONTEXT(ctx
);
2970 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
2977 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2978 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2979 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2981 GET_CURRENT_CONTEXT(ctx
);
2982 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2983 x
, y
, width
, height
);
2989 /**********************************************************************/
2990 /****** Compressed Textures ******/
2991 /**********************************************************************/
2995 * Return expected size of a compressed texture.
2998 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3001 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3002 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3007 * Return compressed texture block size, in pixels.
3010 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3012 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3013 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3018 * Error checking for glCompressedTexImage[123]D().
3019 * \param reason returns reason for error, if any
3020 * \return error code or GL_NO_ERROR.
3023 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3024 GLenum target
, GLint level
,
3025 GLenum internalFormat
, GLsizei width
,
3026 GLsizei height
, GLsizei depth
, GLint border
,
3027 GLsizei imageSize
, char **reason
)
3029 const GLenum proxyTarget
= get_proxy_target(target
);
3030 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3033 *reason
= ""; /* no error */
3036 if (level
< 0 || level
>= maxLevels
) {
3038 return GL_INVALID_VALUE
;
3041 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3043 return GL_INVALID_ENUM
;
3046 /* This will detect any invalid internalFormat value */
3047 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3048 *reason
= "internalFormat";
3049 return GL_INVALID_ENUM
;
3052 /* This should really never fail */
3053 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3054 *reason
= "internalFormat";
3055 return GL_INVALID_ENUM
;
3058 /* No compressed formats support borders at this time */
3060 *reason
= "border != 0";
3061 return GL_INVALID_VALUE
;
3064 /* For cube map, width must equal height */
3065 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3066 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
) {
3067 *reason
= "width != height";
3068 return GL_INVALID_VALUE
;
3071 /* check image size against compression block size */
3073 gl_format texFormat
=
3074 ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
,
3078 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3079 if ((width
> bw
&& width
% bw
> 0) ||
3080 (height
> bh
&& height
% bh
> 0)) {
3082 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3083 * generated [...] if any parameter combinations are not
3084 * supported by the specific compressed internal format.
3086 *reason
= "invalid width or height for compression format";
3087 return GL_INVALID_OPERATION
;
3091 /* check image sizes */
3092 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3093 internalFormat
, GL_NONE
, GL_NONE
,
3094 width
, height
, depth
, border
)) {
3095 /* See error comment above */
3096 *reason
= "invalid width, height or format";
3097 return GL_INVALID_OPERATION
;
3100 /* check image size in bytes */
3101 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3102 if (expectedSize
!= imageSize
) {
3103 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3104 * if <imageSize> is not consistent with the format, dimensions, and
3105 * contents of the specified image.
3107 *reason
= "imageSize inconsistant with width/height/format";
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
)
3264 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3266 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3268 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3270 _mesa_lookup_enum_by_nr(target
), level
,
3271 _mesa_lookup_enum_by_nr(internalFormat
),
3272 width
, height
, depth
, border
, imageSize
, data
);
3275 if (!legal_teximage_target(ctx
, dims
, target
)) {
3276 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3277 dims
, _mesa_lookup_enum_by_nr(target
));
3281 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3282 internalFormat
, width
, height
, depth
,
3283 border
, imageSize
, &reason
);
3286 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3291 /* XXX this is kind of a hack */
3293 switch (internalFormat
) {
3294 case GL_PALETTE4_RGB8_OES
:
3295 case GL_PALETTE4_RGBA8_OES
:
3296 case GL_PALETTE4_R5_G6_B5_OES
:
3297 case GL_PALETTE4_RGBA4_OES
:
3298 case GL_PALETTE4_RGB5_A1_OES
:
3299 case GL_PALETTE8_RGB8_OES
:
3300 case GL_PALETTE8_RGBA8_OES
:
3301 case GL_PALETTE8_R5_G6_B5_OES
:
3302 case GL_PALETTE8_RGBA4_OES
:
3303 case GL_PALETTE8_RGB5_A1_OES
:
3304 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3305 width
, height
, imageSize
, data
);
3311 if (_mesa_is_proxy_texture(target
)) {
3312 /* Proxy texture: just check for errors and update proxy state */
3313 struct gl_texture_image
*texImage
;
3316 struct gl_texture_object
*texObj
=
3317 _mesa_get_current_tex_object(ctx
, target
);
3318 gl_format texFormat
=
3319 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3320 internalFormat
, GL_NONE
, GL_NONE
);
3321 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3322 error
= GL_OUT_OF_MEMORY
;
3326 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3329 /* if error, clear all proxy texture image parameters */
3330 clear_teximage_fields(texImage
);
3333 /* no error: store the teximage parameters */
3334 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3335 depth
, border
, internalFormat
,
3341 /* non-proxy target */
3342 struct gl_texture_object
*texObj
;
3343 struct gl_texture_image
*texImage
;
3346 _mesa_error(ctx
, error
, "glCompressedTexImage%uD", dims
);
3350 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3352 _mesa_lock_texture(ctx
, texObj
);
3354 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3356 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3357 "glCompressedTexImage%uD", dims
);
3360 gl_format texFormat
;
3362 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3363 ASSERT(texImage
->Data
== NULL
);
3365 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3366 internalFormat
, GL_NONE
,
3369 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3370 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3371 width
, height
, depth
,
3372 border
, internalFormat
, texFormat
);
3376 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3377 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3380 border
, imageSize
, data
,
3384 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3385 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3388 border
, imageSize
, data
,
3392 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3393 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3395 width
, height
, depth
,
3396 border
, imageSize
, data
,
3400 _mesa_problem(ctx
, "bad dims in compressedteximage");
3403 check_gen_mipmap(ctx
, target
, texObj
, level
);
3406 texObj
->_Complete
= GL_FALSE
;
3407 ctx
->NewState
|= _NEW_TEXTURE
;
3410 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3411 "glCompressedTexImage%uD", dims
);
3415 _mesa_unlock_texture(ctx
, texObj
);
3421 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3422 GLenum internalFormat
, GLsizei width
,
3423 GLint border
, GLsizei imageSize
,
3426 GET_CURRENT_CONTEXT(ctx
);
3427 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3428 width
, 1, 1, border
, imageSize
, data
);
3433 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3434 GLenum internalFormat
, GLsizei width
,
3435 GLsizei height
, GLint border
, GLsizei imageSize
,
3438 GET_CURRENT_CONTEXT(ctx
);
3439 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3440 width
, height
, 1, border
, imageSize
, data
);
3445 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3446 GLenum internalFormat
, GLsizei width
,
3447 GLsizei height
, GLsizei depth
, GLint border
,
3448 GLsizei imageSize
, const GLvoid
*data
)
3450 GET_CURRENT_CONTEXT(ctx
);
3451 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3452 width
, height
, depth
, border
, imageSize
, data
);
3457 * Common helper for glCompressedTexSubImage1/2/3D().
3460 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3461 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3462 GLsizei width
, GLsizei height
, GLsizei depth
,
3463 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3465 struct gl_texture_object
*texObj
;
3466 struct gl_texture_image
*texImage
;
3468 GET_CURRENT_CONTEXT(ctx
);
3469 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3471 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3472 xoffset
, 0, 0, /* pos */
3473 width
, height
, depth
, /* size */
3476 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3480 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3482 _mesa_lock_texture(ctx
, texObj
);
3484 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3487 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3488 format
, texImage
)) {
3489 /* error was recorded */
3491 else if (width
> 0 && height
> 0 && depth
> 0) {
3494 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3495 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3497 format
, imageSize
, data
,
3502 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3503 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3506 format
, imageSize
, data
,
3511 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3512 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3513 xoffset
, yoffset
, zoffset
,
3514 width
, height
, depth
,
3515 format
, imageSize
, data
,
3523 check_gen_mipmap(ctx
, target
, texObj
, level
);
3525 ctx
->NewState
|= _NEW_TEXTURE
;
3528 _mesa_unlock_texture(ctx
, texObj
);
3533 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3534 GLsizei width
, GLenum format
,
3535 GLsizei imageSize
, const GLvoid
*data
)
3537 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3538 format
, imageSize
, data
);
3543 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3544 GLint yoffset
, GLsizei width
, GLsizei height
,
3545 GLenum format
, GLsizei imageSize
,
3548 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3549 width
, height
, 1, format
, imageSize
, data
);
3554 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3555 GLint yoffset
, GLint zoffset
, GLsizei width
,
3556 GLsizei height
, GLsizei depth
, GLenum format
,
3557 GLsizei imageSize
, const GLvoid
*data
)
3559 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3560 width
, height
, depth
, format
, imageSize
, data
);
3565 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3566 * return the basic data type and number of components for the format.
3567 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3570 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3571 GLenum
*datatype
, GLuint
*components
)
3573 switch (internalFormat
) {
3575 *datatype
= GL_UNSIGNED_BYTE
;
3579 *datatype
= GL_UNSIGNED_SHORT
;
3582 case GL_ALPHA16F_ARB
:
3583 *datatype
= GL_HALF_FLOAT
;
3586 case GL_ALPHA32F_ARB
:
3587 *datatype
= GL_FLOAT
;
3590 case GL_ALPHA8I_EXT
:
3591 *datatype
= GL_BYTE
;
3594 case GL_ALPHA16I_EXT
:
3595 *datatype
= GL_SHORT
;
3598 case GL_ALPHA32I_EXT
:
3602 case GL_ALPHA8UI_EXT
:
3603 *datatype
= GL_UNSIGNED_BYTE
;
3606 case GL_ALPHA16UI_EXT
:
3607 *datatype
= GL_UNSIGNED_SHORT
;
3610 case GL_ALPHA32UI_EXT
:
3611 *datatype
= GL_UNSIGNED_INT
;
3615 *datatype
= GL_UNSIGNED_BYTE
;
3618 case GL_LUMINANCE16
:
3619 *datatype
= GL_UNSIGNED_SHORT
;
3622 case GL_LUMINANCE16F_ARB
:
3623 *datatype
= GL_HALF_FLOAT
;
3626 case GL_LUMINANCE32F_ARB
:
3627 *datatype
= GL_FLOAT
;
3630 case GL_LUMINANCE8I_EXT
:
3631 *datatype
= GL_BYTE
;
3634 case GL_LUMINANCE16I_EXT
:
3635 *datatype
= GL_SHORT
;
3638 case GL_LUMINANCE32I_EXT
:
3642 case GL_LUMINANCE8UI_EXT
:
3643 *datatype
= GL_UNSIGNED_BYTE
;
3646 case GL_LUMINANCE16UI_EXT
:
3647 *datatype
= GL_UNSIGNED_SHORT
;
3650 case GL_LUMINANCE32UI_EXT
:
3651 *datatype
= GL_UNSIGNED_INT
;
3654 case GL_LUMINANCE8_ALPHA8
:
3655 *datatype
= GL_UNSIGNED_BYTE
;
3658 case GL_LUMINANCE16_ALPHA16
:
3659 *datatype
= GL_UNSIGNED_SHORT
;
3662 case GL_LUMINANCE_ALPHA16F_ARB
:
3663 *datatype
= GL_HALF_FLOAT
;
3666 case GL_LUMINANCE_ALPHA32F_ARB
:
3667 *datatype
= GL_FLOAT
;
3670 case GL_LUMINANCE_ALPHA8I_EXT
:
3671 *datatype
= GL_BYTE
;
3674 case GL_LUMINANCE_ALPHA16I_EXT
:
3675 *datatype
= GL_SHORT
;
3678 case GL_LUMINANCE_ALPHA32I_EXT
:
3682 case GL_LUMINANCE_ALPHA8UI_EXT
:
3683 *datatype
= GL_UNSIGNED_BYTE
;
3686 case GL_LUMINANCE_ALPHA16UI_EXT
:
3687 *datatype
= GL_UNSIGNED_SHORT
;
3690 case GL_LUMINANCE_ALPHA32UI_EXT
:
3691 *datatype
= GL_UNSIGNED_INT
;
3695 *datatype
= GL_UNSIGNED_BYTE
;
3698 case GL_INTENSITY16
:
3699 *datatype
= GL_UNSIGNED_SHORT
;
3702 case GL_INTENSITY16F_ARB
:
3703 *datatype
= GL_HALF_FLOAT
;
3706 case GL_INTENSITY32F_ARB
:
3707 *datatype
= GL_FLOAT
;
3710 case GL_INTENSITY8I_EXT
:
3711 *datatype
= GL_BYTE
;
3714 case GL_INTENSITY16I_EXT
:
3715 *datatype
= GL_SHORT
;
3718 case GL_INTENSITY32I_EXT
:
3722 case GL_INTENSITY8UI_EXT
:
3723 *datatype
= GL_UNSIGNED_BYTE
;
3726 case GL_INTENSITY16UI_EXT
:
3727 *datatype
= GL_UNSIGNED_SHORT
;
3730 case GL_INTENSITY32UI_EXT
:
3731 *datatype
= GL_UNSIGNED_INT
;
3735 *datatype
= GL_UNSIGNED_BYTE
;
3739 *datatype
= GL_UNSIGNED_SHORT
;
3742 case GL_RGBA16F_ARB
:
3743 *datatype
= GL_HALF_FLOAT
;
3746 case GL_RGBA32F_ARB
:
3747 *datatype
= GL_FLOAT
;
3751 *datatype
= GL_BYTE
;
3754 case GL_RGBA16I_EXT
:
3755 *datatype
= GL_SHORT
;
3758 case GL_RGBA32I_EXT
:
3762 case GL_RGBA8UI_EXT
:
3763 *datatype
= GL_UNSIGNED_BYTE
;
3766 case GL_RGBA16UI_EXT
:
3767 *datatype
= GL_UNSIGNED_SHORT
;
3770 case GL_RGBA32UI_EXT
:
3771 *datatype
= GL_UNSIGNED_INT
;
3778 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3781 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3788 /** GL_ARB_texture_buffer_object */
3790 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3792 struct gl_texture_object
*texObj
;
3793 struct gl_buffer_object
*bufObj
;
3797 GET_CURRENT_CONTEXT(ctx
);
3798 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3800 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3801 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3805 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3806 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3810 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3811 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3816 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3817 if (buffer
&& !bufObj
) {
3818 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3822 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3824 _mesa_lock_texture(ctx
, texObj
);
3826 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3827 texObj
->BufferObjectFormat
= internalFormat
;
3829 _mesa_unlock_texture(ctx
, texObj
);