2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "mfeatures.h"
44 #include "texcompress.h"
52 * State changes which we care about for glCopyTex[Sub]Image() calls.
53 * In particular, we care about pixel transfer state and buffer state
54 * (such as glReadBuffer to make sure we read from the right renderbuffer).
56 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
61 * We allocate texture memory on 512-byte boundaries so we can use MMX/SSE
65 _mesa_alloc_texmemory(GLsizei bytes
)
67 return _mesa_align_malloc(bytes
, 512);
72 * Free texture memory allocated with _mesa_alloc_texmemory()
75 _mesa_free_texmemory(void *m
)
82 * Return the simple base format for a given internal texture format.
83 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
85 * \param ctx GL context.
86 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
88 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
89 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
91 * This is the format which is used during texture application (i.e. the
92 * texture format and env mode determine the arithmetic used.
94 * XXX this could be static
97 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
99 switch (internalFormat
) {
114 case GL_LUMINANCE_ALPHA
:
115 case GL_LUMINANCE4_ALPHA4
:
116 case GL_LUMINANCE6_ALPHA2
:
117 case GL_LUMINANCE8_ALPHA8
:
118 case GL_LUMINANCE12_ALPHA4
:
119 case GL_LUMINANCE12_ALPHA12
:
120 case GL_LUMINANCE16_ALPHA16
:
121 return GL_LUMINANCE_ALPHA
;
152 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
154 if (ctx
->API
!= API_OPENGL
) {
155 switch (internalFormat
) {
163 if (ctx
->Extensions
.ARB_depth_texture
) {
164 switch (internalFormat
) {
165 case GL_DEPTH_COMPONENT
:
166 case GL_DEPTH_COMPONENT16
:
167 case GL_DEPTH_COMPONENT24
:
168 case GL_DEPTH_COMPONENT32
:
169 return GL_DEPTH_COMPONENT
;
175 switch (internalFormat
) {
176 case GL_COMPRESSED_ALPHA
:
178 case GL_COMPRESSED_LUMINANCE
:
180 case GL_COMPRESSED_LUMINANCE_ALPHA
:
181 return GL_LUMINANCE_ALPHA
;
182 case GL_COMPRESSED_INTENSITY
:
184 case GL_COMPRESSED_RGB
:
186 case GL_COMPRESSED_RGBA
:
192 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
193 switch (internalFormat
) {
194 case GL_COMPRESSED_RGB_FXT1_3DFX
:
196 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
203 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
204 switch (internalFormat
) {
205 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
207 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
208 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
209 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
216 if (ctx
->Extensions
.S3_s3tc
) {
217 switch (internalFormat
) {
229 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
230 if (internalFormat
== GL_YCBCR_MESA
)
231 return GL_YCBCR_MESA
;
234 if (ctx
->Extensions
.ARB_texture_float
) {
235 switch (internalFormat
) {
236 case GL_ALPHA16F_ARB
:
237 case GL_ALPHA32F_ARB
:
245 case GL_INTENSITY16F_ARB
:
246 case GL_INTENSITY32F_ARB
:
248 case GL_LUMINANCE16F_ARB
:
249 case GL_LUMINANCE32F_ARB
:
251 case GL_LUMINANCE_ALPHA16F_ARB
:
252 case GL_LUMINANCE_ALPHA32F_ARB
:
253 return GL_LUMINANCE_ALPHA
;
259 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
260 switch (internalFormat
) {
269 if (ctx
->Extensions
.EXT_texture_snorm
) {
270 switch (internalFormat
) {
285 case GL_RGBA16_SNORM
:
288 case GL_ALPHA8_SNORM
:
289 case GL_ALPHA16_SNORM
:
291 case GL_LUMINANCE_SNORM
:
292 case GL_LUMINANCE8_SNORM
:
293 case GL_LUMINANCE16_SNORM
:
295 case GL_LUMINANCE_ALPHA_SNORM
:
296 case GL_LUMINANCE8_ALPHA8_SNORM
:
297 case GL_LUMINANCE16_ALPHA16_SNORM
:
298 return GL_LUMINANCE_ALPHA
;
299 case GL_INTENSITY_SNORM
:
300 case GL_INTENSITY8_SNORM
:
301 case GL_INTENSITY16_SNORM
:
308 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
309 switch (internalFormat
) {
310 case GL_DEPTH_STENCIL_EXT
:
311 case GL_DEPTH24_STENCIL8_EXT
:
312 return GL_DEPTH_STENCIL_EXT
;
318 #if FEATURE_EXT_texture_sRGB
319 if (ctx
->Extensions
.EXT_texture_sRGB
) {
320 switch (internalFormat
) {
323 case GL_COMPRESSED_SRGB_EXT
:
324 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
326 case GL_SRGB_ALPHA_EXT
:
327 case GL_SRGB8_ALPHA8_EXT
:
328 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
329 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
330 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
331 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
333 case GL_SLUMINANCE_ALPHA_EXT
:
334 case GL_SLUMINANCE8_ALPHA8_EXT
:
335 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
336 return GL_LUMINANCE_ALPHA
;
337 case GL_SLUMINANCE_EXT
:
338 case GL_SLUMINANCE8_EXT
:
339 case GL_COMPRESSED_SLUMINANCE_EXT
:
345 #endif /* FEATURE_EXT_texture_sRGB */
347 if (ctx
->Extensions
.EXT_texture_integer
) {
348 switch (internalFormat
) {
350 case GL_RGBA16UI_EXT
:
351 case GL_RGBA32UI_EXT
:
363 case GL_ALPHA8UI_EXT
:
364 case GL_ALPHA16UI_EXT
:
365 case GL_ALPHA32UI_EXT
:
367 case GL_ALPHA16I_EXT
:
368 case GL_ALPHA32I_EXT
:
370 case GL_INTENSITY8UI_EXT
:
371 case GL_INTENSITY16UI_EXT
:
372 case GL_INTENSITY32UI_EXT
:
373 case GL_INTENSITY8I_EXT
:
374 case GL_INTENSITY16I_EXT
:
375 case GL_INTENSITY32I_EXT
:
377 case GL_LUMINANCE8UI_EXT
:
378 case GL_LUMINANCE16UI_EXT
:
379 case GL_LUMINANCE32UI_EXT
:
380 case GL_LUMINANCE8I_EXT
:
381 case GL_LUMINANCE16I_EXT
:
382 case GL_LUMINANCE32I_EXT
:
384 case GL_LUMINANCE_ALPHA8UI_EXT
:
385 case GL_LUMINANCE_ALPHA16UI_EXT
:
386 case GL_LUMINANCE_ALPHA32UI_EXT
:
387 case GL_LUMINANCE_ALPHA8I_EXT
:
388 case GL_LUMINANCE_ALPHA16I_EXT
:
389 case GL_LUMINANCE_ALPHA32I_EXT
:
390 return GL_LUMINANCE_ALPHA
;
396 if (ctx
->Extensions
.ARB_texture_rg
) {
397 switch (internalFormat
) {
399 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
401 if (!ctx
->Extensions
.ARB_half_float_pixel
)
405 if (!ctx
->Extensions
.ARB_texture_float
)
414 if (!ctx
->Extensions
.EXT_texture_integer
)
420 case GL_COMPRESSED_RED
:
424 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
426 if (!ctx
->Extensions
.ARB_half_float_pixel
)
430 if (!ctx
->Extensions
.ARB_texture_float
)
439 if (!ctx
->Extensions
.EXT_texture_integer
)
445 case GL_COMPRESSED_RG
:
452 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
453 switch (internalFormat
) {
461 if (ctx
->Extensions
.EXT_packed_float
) {
462 switch (internalFormat
) {
463 case GL_R11F_G11F_B10F_EXT
:
470 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
471 switch (internalFormat
) {
472 case GL_DEPTH_COMPONENT32F
:
473 return GL_DEPTH_COMPONENT
;
474 case GL_DEPTH32F_STENCIL8
:
475 return GL_DEPTH_STENCIL
;
481 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
482 switch (internalFormat
) {
483 case GL_COMPRESSED_RED_RGTC1
:
484 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
486 case GL_COMPRESSED_RG_RGTC2
:
487 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
494 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
495 switch (internalFormat
) {
496 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
497 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
499 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
500 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
501 return GL_LUMINANCE_ALPHA
;
507 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
508 switch (internalFormat
) {
509 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
510 return GL_LUMINANCE_ALPHA
;
516 if (ctx
->API
== API_OPENGLES
) {
517 switch (internalFormat
) {
518 case GL_PALETTE4_RGB8_OES
:
519 case GL_PALETTE4_R5_G6_B5_OES
:
520 case GL_PALETTE8_RGB8_OES
:
521 case GL_PALETTE8_R5_G6_B5_OES
:
523 case GL_PALETTE4_RGBA8_OES
:
524 case GL_PALETTE8_RGB5_A1_OES
:
525 case GL_PALETTE4_RGBA4_OES
:
526 case GL_PALETTE4_RGB5_A1_OES
:
527 case GL_PALETTE8_RGBA8_OES
:
528 case GL_PALETTE8_RGBA4_OES
:
535 return -1; /* error */
540 * For cube map faces, return a face index in [0,5].
541 * For other targets return 0;
544 _mesa_tex_target_to_face(GLenum target
)
546 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
547 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
)
548 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
556 * Store a gl_texture_image pointer in a gl_texture_object structure
557 * according to the target and level parameters.
559 * \param tObj texture object.
560 * \param target texture target.
561 * \param level image level.
562 * \param texImage texture image.
565 _mesa_set_tex_image(struct gl_texture_object
*tObj
,
566 GLenum target
, GLint level
,
567 struct gl_texture_image
*texImage
)
569 const GLuint face
= _mesa_tex_target_to_face(target
);
573 ASSERT(target
!= GL_TEXTURE_RECTANGLE_NV
|| level
== 0);
575 tObj
->Image
[face
][level
] = texImage
;
577 /* Set the 'back' pointer */
578 texImage
->TexObject
= tObj
;
579 texImage
->Level
= level
;
580 texImage
->Face
= face
;
585 * Allocate a texture image structure.
587 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
590 * \return a pointer to gl_texture_image struct with all fields initialized to
593 struct gl_texture_image
*
594 _mesa_new_texture_image( struct gl_context
*ctx
)
597 return CALLOC_STRUCT(gl_texture_image
);
602 * Free texture image data.
603 * This function is a fallback called via ctx->Driver.FreeTextureImageBuffer().
605 * \param texImage texture image.
607 * Free the texture image data if it's not marked as client data.
610 _mesa_free_texture_image_data(struct gl_context
*ctx
,
611 struct gl_texture_image
*texImage
)
615 if (texImage
->Data
) {
616 /* free the old texture data */
617 _mesa_free_texmemory(texImage
->Data
);
620 texImage
->Data
= NULL
;
625 * Free a gl_texture_image and associated data.
626 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
628 * \param texImage texture image.
630 * Free the texture image structure and the associated image data.
633 _mesa_delete_texture_image(struct gl_context
*ctx
,
634 struct gl_texture_image
*texImage
)
636 /* Free texImage->Data and/or any other driver-specific texture
639 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
640 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
642 ASSERT(texImage
->Data
== NULL
);
643 if (texImage
->ImageOffsets
)
644 free(texImage
->ImageOffsets
);
650 * Test if a target is a proxy target.
652 * \param target texture target.
654 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
657 _mesa_is_proxy_texture(GLenum target
)
659 /* NUM_TEXTURE_TARGETS should match number of terms below,
660 * except there's no proxy for GL_TEXTURE_BUFFER.
662 assert(NUM_TEXTURE_TARGETS
== 8);
664 return (target
== GL_PROXY_TEXTURE_1D
||
665 target
== GL_PROXY_TEXTURE_2D
||
666 target
== GL_PROXY_TEXTURE_3D
||
667 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
668 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
669 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
670 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
675 * Return the proxy target which corresponds to the given texture target
678 get_proxy_target(GLenum target
)
682 case GL_PROXY_TEXTURE_1D
:
683 return GL_PROXY_TEXTURE_1D
;
685 case GL_PROXY_TEXTURE_2D
:
686 return GL_PROXY_TEXTURE_2D
;
688 case GL_PROXY_TEXTURE_3D
:
689 return GL_PROXY_TEXTURE_3D
;
690 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
691 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
692 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
693 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
694 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
695 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
696 case GL_TEXTURE_CUBE_MAP_ARB
:
697 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
698 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
699 case GL_TEXTURE_RECTANGLE_NV
:
700 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
701 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
702 case GL_TEXTURE_1D_ARRAY_EXT
:
703 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
704 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
705 case GL_TEXTURE_2D_ARRAY_EXT
:
706 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
707 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
709 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
716 * Get the texture object that corresponds to the target of the given
717 * texture unit. The target should have already been checked for validity.
719 * \param ctx GL context.
720 * \param texUnit texture unit.
721 * \param target texture target.
723 * \return pointer to the texture object on success, or NULL on failure.
725 struct gl_texture_object
*
726 _mesa_select_tex_object(struct gl_context
*ctx
,
727 const struct gl_texture_unit
*texUnit
,
730 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
731 ctx
->Extensions
.EXT_texture_array
);
735 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
736 case GL_PROXY_TEXTURE_1D
:
737 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
739 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
740 case GL_PROXY_TEXTURE_2D
:
741 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
743 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
744 case GL_PROXY_TEXTURE_3D
:
745 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
746 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
747 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
748 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
749 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
750 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
751 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
752 case GL_TEXTURE_CUBE_MAP_ARB
:
753 return ctx
->Extensions
.ARB_texture_cube_map
754 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
755 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
756 return ctx
->Extensions
.ARB_texture_cube_map
757 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
758 case GL_TEXTURE_RECTANGLE_NV
:
759 return ctx
->Extensions
.NV_texture_rectangle
760 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
761 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
762 return ctx
->Extensions
.NV_texture_rectangle
763 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
764 case GL_TEXTURE_1D_ARRAY_EXT
:
765 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
766 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
767 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
768 case GL_TEXTURE_2D_ARRAY_EXT
:
769 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
770 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
771 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
772 case GL_TEXTURE_BUFFER
:
773 return ctx
->Extensions
.ARB_texture_buffer_object
774 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
776 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
783 * Return pointer to texture object for given target on current texture unit.
785 struct gl_texture_object
*
786 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
788 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
789 return _mesa_select_tex_object(ctx
, texUnit
, target
);
794 * Get a texture image pointer from a texture object, given a texture
795 * target and mipmap level. The target and level parameters should
796 * have already been error-checked.
798 * \param ctx GL context.
799 * \param texObj texture unit.
800 * \param target texture target.
801 * \param level image level.
803 * \return pointer to the texture image structure, or NULL on failure.
805 struct gl_texture_image
*
806 _mesa_select_tex_image(struct gl_context
*ctx
,
807 const struct gl_texture_object
*texObj
,
808 GLenum target
, GLint level
)
810 const GLuint face
= _mesa_tex_target_to_face(target
);
814 ASSERT(level
< MAX_TEXTURE_LEVELS
);
816 return texObj
->Image
[face
][level
];
821 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
822 * it and install it. Only return NULL if passed a bad parameter or run
825 struct gl_texture_image
*
826 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
827 GLenum target
, GLint level
)
829 struct gl_texture_image
*texImage
;
834 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
836 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
838 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
842 _mesa_set_tex_image(texObj
, target
, level
, texImage
);
850 * Return pointer to the specified proxy texture image.
851 * Note that proxy textures are per-context, not per-texture unit.
852 * \return pointer to texture image or NULL if invalid target, invalid
853 * level, or out of memory.
855 struct gl_texture_image
*
856 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
858 struct gl_texture_image
*texImage
;
865 case GL_PROXY_TEXTURE_1D
:
866 if (level
>= ctx
->Const
.MaxTextureLevels
)
868 texIndex
= TEXTURE_1D_INDEX
;
870 case GL_PROXY_TEXTURE_2D
:
871 if (level
>= ctx
->Const
.MaxTextureLevels
)
873 texIndex
= TEXTURE_2D_INDEX
;
875 case GL_PROXY_TEXTURE_3D
:
876 if (level
>= ctx
->Const
.Max3DTextureLevels
)
878 texIndex
= TEXTURE_3D_INDEX
;
880 case GL_PROXY_TEXTURE_CUBE_MAP
:
881 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
883 texIndex
= TEXTURE_CUBE_INDEX
;
885 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
888 texIndex
= TEXTURE_RECT_INDEX
;
890 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
891 if (level
>= ctx
->Const
.MaxTextureLevels
)
893 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
895 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
896 if (level
>= ctx
->Const
.MaxTextureLevels
)
898 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
904 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
906 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
908 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
911 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
912 /* Set the 'back' pointer */
913 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
920 * Get the maximum number of allowed mipmap levels.
922 * \param ctx GL context.
923 * \param target texture target.
925 * \return the maximum number of allowed mipmap levels for the given
926 * texture target, or zero if passed a bad target.
931 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
935 case GL_PROXY_TEXTURE_1D
:
937 case GL_PROXY_TEXTURE_2D
:
938 return ctx
->Const
.MaxTextureLevels
;
940 case GL_PROXY_TEXTURE_3D
:
941 return ctx
->Const
.Max3DTextureLevels
;
942 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
943 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
944 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
945 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
946 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
947 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
948 case GL_TEXTURE_CUBE_MAP_ARB
:
949 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
950 return ctx
->Extensions
.ARB_texture_cube_map
951 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
952 case GL_TEXTURE_RECTANGLE_NV
:
953 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
954 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
955 case GL_TEXTURE_1D_ARRAY_EXT
:
956 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
957 case GL_TEXTURE_2D_ARRAY_EXT
:
958 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
959 return (ctx
->Extensions
.MESA_texture_array
||
960 ctx
->Extensions
.EXT_texture_array
)
961 ? ctx
->Const
.MaxTextureLevels
: 0;
962 case GL_TEXTURE_BUFFER
:
965 return 0; /* bad target */
971 * Return number of dimensions per mipmap level for the given texture target.
974 _mesa_get_texture_dimensions(GLenum target
)
978 case GL_PROXY_TEXTURE_1D
:
981 case GL_TEXTURE_RECTANGLE
:
982 case GL_TEXTURE_CUBE_MAP
:
983 case GL_PROXY_TEXTURE_2D
:
984 case GL_PROXY_TEXTURE_RECTANGLE
:
985 case GL_PROXY_TEXTURE_CUBE_MAP
:
986 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
987 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
988 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
989 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
990 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
991 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
992 case GL_TEXTURE_1D_ARRAY
:
993 case GL_PROXY_TEXTURE_1D_ARRAY
:
996 case GL_PROXY_TEXTURE_3D
:
997 case GL_TEXTURE_2D_ARRAY
:
998 case GL_PROXY_TEXTURE_2D_ARRAY
:
1000 case GL_TEXTURE_BUFFER
:
1003 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1012 #if 000 /* not used anymore */
1014 * glTexImage[123]D can accept a NULL image pointer. In this case we
1015 * create a texture image with unspecified image contents per the OpenGL
1019 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1021 const GLint components
= _mesa_components_in_format(format
);
1022 const GLint numPixels
= width
* height
* depth
;
1023 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1027 * Let's see if anyone finds this. If glTexImage2D() is called with
1028 * a NULL image pointer then load the texture image with something
1029 * interesting instead of leaving it indeterminate.
1032 static const char message
[8][32] = {
1033 " X X XXXXX XXX X ",
1034 " XX XX X X X X X ",
1036 " X X XXXX XXX XXXXX ",
1039 " X X XXXXX XXX X X ",
1043 GLubyte
*imgPtr
= data
;
1045 for (h
= 0; h
< depth
; h
++) {
1046 for (i
= 0; i
< height
; i
++) {
1047 GLint srcRow
= 7 - (i
% 8);
1048 for (j
= 0; j
< width
; j
++) {
1049 GLint srcCol
= j
% 32;
1050 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1051 for (k
= 0; k
< components
; k
++) {
1067 * Reset the fields of a gl_texture_image struct to zero.
1069 * \param img texture image structure.
1071 * This is called when a proxy texture test fails, we set all the
1072 * image members (except DriverData) to zero.
1073 * It's also used in glTexImage[123]D as a safeguard to be sure all
1074 * required fields get initialized properly by the Driver.TexImage[123]D
1078 clear_teximage_fields(struct gl_texture_image
*img
)
1081 img
->_BaseFormat
= 0;
1082 img
->InternalFormat
= 0;
1088 if (img
->ImageOffsets
) {
1089 free(img
->ImageOffsets
);
1090 img
->ImageOffsets
= NULL
;
1096 img
->HeightLog2
= 0;
1099 img
->TexFormat
= MESA_FORMAT_NONE
;
1104 * Initialize basic fields of the gl_texture_image struct.
1106 * \param ctx GL context.
1107 * \param target texture target (GL_TEXTURE_1D, GL_TEXTURE_RECTANGLE, etc).
1108 * \param img texture image structure to be initialized.
1109 * \param width image width.
1110 * \param height image height.
1111 * \param depth image depth.
1112 * \param border image border.
1113 * \param internalFormat internal format.
1114 * \param format the actual hardware format (one of MESA_FORMAT_*)
1116 * Fills in the fields of \p img with the given information.
1117 * Note: width, height and depth include the border.
1120 _mesa_init_teximage_fields(struct gl_context
*ctx
, GLenum target
,
1121 struct gl_texture_image
*img
,
1122 GLsizei width
, GLsizei height
, GLsizei depth
,
1123 GLint border
, GLenum internalFormat
,
1130 ASSERT(height
>= 0);
1133 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1134 ASSERT(img
->_BaseFormat
> 0);
1135 img
->InternalFormat
= internalFormat
;
1136 img
->Border
= border
;
1138 img
->Height
= height
;
1141 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1142 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1144 if (height
== 1) { /* 1-D texture */
1146 img
->HeightLog2
= 0;
1149 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1150 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1153 if (depth
== 1) { /* 2-D texture */
1158 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1159 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1162 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1164 /* RowStride and ImageOffsets[] describe how to address texels in 'Data' */
1165 img
->RowStride
= width
;
1166 /* Allocate the ImageOffsets array and initialize to typical values.
1167 * We allocate the array for 1D/2D textures too in order to avoid special-
1168 * case code in the texstore routines.
1170 if (img
->ImageOffsets
)
1171 free(img
->ImageOffsets
);
1172 img
->ImageOffsets
= (GLuint
*) malloc(depth
* sizeof(GLuint
));
1173 for (i
= 0; i
< depth
; i
++) {
1174 img
->ImageOffsets
[i
] = i
* width
* height
;
1177 img
->TexFormat
= format
;
1182 * Free and clear fields of the gl_texture_image struct.
1184 * \param ctx GL context.
1185 * \param texImage texture image structure to be cleared.
1187 * After the call, \p texImage will have no data associated with it. Its
1188 * fields are cleared so that its parent object will test incomplete.
1191 _mesa_clear_texture_image(struct gl_context
*ctx
,
1192 struct gl_texture_image
*texImage
)
1194 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1195 clear_teximage_fields(texImage
);
1200 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1201 * level, width, height and depth against the ctx->Const limits for textures.
1203 * A hardware driver might override this function if, for example, the
1204 * max 3D texture size is 512x512x64 (i.e. not a cube).
1206 * Note that width, height, depth == 0 is not an error. However, a
1207 * texture with zero width/height/depth will be considered "incomplete"
1208 * and texturing will effectively be disabled.
1210 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1211 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1212 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1213 * \param level as passed to glTexImage
1214 * \param internalFormat as passed to glTexImage
1215 * \param format as passed to glTexImage
1216 * \param type as passed to glTexImage
1217 * \param width as passed to glTexImage
1218 * \param height as passed to glTexImage
1219 * \param depth as passed to glTexImage
1220 * \param border as passed to glTexImage
1221 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1224 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1225 GLint internalFormat
, GLenum format
, GLenum type
,
1226 GLint width
, GLint height
, GLint depth
, GLint border
)
1230 (void) internalFormat
;
1235 case GL_PROXY_TEXTURE_1D
:
1236 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1237 if (width
< 2 * border
|| width
> 2 + maxSize
)
1239 if (level
>= ctx
->Const
.MaxTextureLevels
)
1241 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1242 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1247 case GL_PROXY_TEXTURE_2D
:
1248 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1249 if (width
< 2 * border
|| width
> 2 + maxSize
)
1251 if (height
< 2 * border
|| height
> 2 + maxSize
)
1253 if (level
>= ctx
->Const
.MaxTextureLevels
)
1255 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1256 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1258 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1263 case GL_PROXY_TEXTURE_3D
:
1264 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1265 if (width
< 2 * border
|| width
> 2 + maxSize
)
1267 if (height
< 2 * border
|| height
> 2 + maxSize
)
1269 if (depth
< 2 * border
|| depth
> 2 + maxSize
)
1271 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1273 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1274 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1276 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1278 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1283 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1284 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1285 if (width
< 0 || width
> maxSize
)
1287 if (height
< 0 || height
> maxSize
)
1293 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1294 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1295 if (width
< 2 * border
|| width
> 2 + maxSize
)
1297 if (height
< 2 * border
|| height
> 2 + maxSize
)
1299 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1301 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1302 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1304 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1309 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1310 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1311 if (width
< 2 * border
|| width
> 2 + maxSize
)
1313 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1315 if (level
>= ctx
->Const
.MaxTextureLevels
)
1317 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1318 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1323 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1324 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1325 if (width
< 2 * border
|| width
> 2 + maxSize
)
1327 if (height
< 2 * border
|| height
> 2 + maxSize
)
1329 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1331 if (level
>= ctx
->Const
.MaxTextureLevels
)
1333 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1334 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1336 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1342 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1349 * Check if the memory used by the texture would exceed the driver's limit.
1350 * This lets us support a max 3D texture size of 8K (for example) but
1351 * prevents allocating a full 8K x 8K x 8K texture.
1352 * XXX this could be rolled into the proxy texture size test (above) but
1353 * we don't have the actual texture internal format at that point.
1356 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1357 GLint width
, GLint height
, GLint depth
)
1359 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1360 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1361 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1367 * Helper function to determine whether a target and specific compression
1368 * format are supported.
1371 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1374 (void) intFormat
; /* not used yet */
1378 case GL_PROXY_TEXTURE_2D
:
1379 return GL_TRUE
; /* true for any compressed format so far */
1380 case GL_PROXY_TEXTURE_CUBE_MAP
:
1381 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1382 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1383 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1384 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1385 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1386 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1387 return ctx
->Extensions
.ARB_texture_cube_map
;
1388 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1389 case GL_TEXTURE_2D_ARRAY_EXT
:
1390 return (ctx
->Extensions
.MESA_texture_array
||
1391 ctx
->Extensions
.EXT_texture_array
);
1399 * Check if the given texture target value is legal for a
1400 * glTexImage1/2/3D call.
1403 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1409 case GL_PROXY_TEXTURE_1D
:
1417 case GL_PROXY_TEXTURE_2D
:
1419 case GL_PROXY_TEXTURE_CUBE_MAP
:
1420 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1421 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1422 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1423 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1424 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1425 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1426 return ctx
->Extensions
.ARB_texture_cube_map
;
1427 case GL_TEXTURE_RECTANGLE_NV
:
1428 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1429 return ctx
->Extensions
.NV_texture_rectangle
;
1430 case GL_TEXTURE_1D_ARRAY_EXT
:
1431 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1432 return (ctx
->Extensions
.MESA_texture_array
||
1433 ctx
->Extensions
.EXT_texture_array
);
1440 case GL_PROXY_TEXTURE_3D
:
1442 case GL_TEXTURE_2D_ARRAY_EXT
:
1443 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1444 return (ctx
->Extensions
.MESA_texture_array
||
1445 ctx
->Extensions
.EXT_texture_array
);
1450 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1457 * Check if the given texture target value is legal for a
1458 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1459 * The difference compared to legal_teximage_target() above is that
1460 * proxy targets are not supported.
1463 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1467 return target
== GL_TEXTURE_1D
;
1472 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1473 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1474 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1475 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1476 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1477 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1478 return ctx
->Extensions
.ARB_texture_cube_map
;
1479 case GL_TEXTURE_RECTANGLE_NV
:
1480 return ctx
->Extensions
.NV_texture_rectangle
;
1481 case GL_TEXTURE_1D_ARRAY_EXT
:
1482 return (ctx
->Extensions
.MESA_texture_array
||
1483 ctx
->Extensions
.EXT_texture_array
);
1491 case GL_TEXTURE_2D_ARRAY_EXT
:
1492 return (ctx
->Extensions
.MESA_texture_array
||
1493 ctx
->Extensions
.EXT_texture_array
);
1498 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1506 * Test the glTexImage[123]D() parameters for errors.
1508 * \param ctx GL context.
1509 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1510 * \param target texture target given by the user.
1511 * \param level image level given by the user.
1512 * \param internalFormat internal format given by the user.
1513 * \param format pixel data format given by the user.
1514 * \param type pixel data type given by the user.
1515 * \param width image width given by the user.
1516 * \param height image height given by the user.
1517 * \param depth image depth given by the user.
1518 * \param border image border given by the user.
1520 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1522 * Verifies each of the parameters against the constants specified in
1523 * __struct gl_contextRec::Const and the supported extensions, and according
1524 * to the OpenGL specification.
1527 texture_error_check( struct gl_context
*ctx
,
1528 GLuint dimensions
, GLenum target
,
1529 GLint level
, GLint internalFormat
,
1530 GLenum format
, GLenum type
,
1531 GLint width
, GLint height
,
1532 GLint depth
, GLint border
)
1534 const GLenum proxyTarget
= get_proxy_target(target
);
1535 const GLboolean isProxy
= target
== proxyTarget
;
1536 GLboolean sizeOK
= GL_TRUE
;
1537 GLboolean colorFormat
;
1539 /* Even though there are no color-index textures, we still have to support
1540 * uploading color-index data and remapping it to RGB via the
1541 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1543 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1545 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1546 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1548 _mesa_error(ctx
, GL_INVALID_VALUE
,
1549 "glTexImage%dD(level=%d)", dimensions
, level
);
1555 if (border
< 0 || border
> 1 ||
1556 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1557 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1559 _mesa_error(ctx
, GL_INVALID_VALUE
,
1560 "glTexImage%dD(border=%d)", dimensions
, border
);
1565 if (width
< 0 || height
< 0 || depth
< 0) {
1567 _mesa_error(ctx
, GL_INVALID_VALUE
,
1568 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1573 /* Do this simple check before calling the TestProxyTexImage() function */
1574 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1575 sizeOK
= (width
== height
);
1579 * Use the proxy texture driver hook to see if the size/level/etc are
1582 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1583 internalFormat
, format
,
1584 type
, width
, height
,
1588 _mesa_error(ctx
, GL_INVALID_VALUE
,
1589 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1590 dimensions
, level
, width
, height
, depth
);
1595 /* Check internalFormat */
1596 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1598 _mesa_error(ctx
, GL_INVALID_VALUE
,
1599 "glTexImage%dD(internalFormat=%s)",
1600 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1605 /* Check incoming image format and type */
1606 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1607 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1608 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1609 * GL_EXT_texture_integer extension, some combinations should generate
1610 * GL_INVALID_ENUM instead (grr!).
1613 GLenum error
= _mesa_is_integer_format(format
)
1614 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1615 _mesa_error(ctx
, error
,
1616 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1617 dimensions
, format
, type
);
1622 /* make sure internal format and format basically agree */
1623 colorFormat
= _mesa_is_color_format(format
);
1624 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1625 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1626 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1627 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1628 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1630 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1631 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1632 dimensions
, internalFormat
, format
);
1636 /* additional checks for ycbcr textures */
1637 if (internalFormat
== GL_YCBCR_MESA
) {
1638 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1639 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1640 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1642 _mesa_snprintf(message
, sizeof(message
),
1643 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1644 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1645 return GL_TRUE
; /* error */
1647 if (target
!= GL_TEXTURE_2D
&&
1648 target
!= GL_PROXY_TEXTURE_2D
&&
1649 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1650 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1652 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1658 _mesa_snprintf(message
, sizeof(message
),
1659 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1660 dimensions
, border
);
1661 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1667 /* additional checks for depth textures */
1668 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1669 /* Only 1D, 2D, rect and array textures supported, not 3D or cubes */
1670 if (target
!= GL_TEXTURE_1D
&&
1671 target
!= GL_PROXY_TEXTURE_1D
&&
1672 target
!= GL_TEXTURE_2D
&&
1673 target
!= GL_PROXY_TEXTURE_2D
&&
1674 target
!= GL_TEXTURE_1D_ARRAY
&&
1675 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1676 target
!= GL_TEXTURE_2D_ARRAY
&&
1677 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1678 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1679 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
) {
1681 _mesa_error(ctx
, GL_INVALID_ENUM
,
1682 "glTexImage(target/internalFormat)");
1687 /* additional checks for compressed textures */
1688 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1689 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1691 _mesa_error(ctx
, GL_INVALID_ENUM
,
1692 "glTexImage%dD(target)", dimensions
);
1697 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1698 "glTexImage%dD(border!=0)", dimensions
);
1704 /* additional checks for integer textures */
1705 if (ctx
->Extensions
.EXT_texture_integer
&&
1706 (_mesa_is_integer_format(format
) !=
1707 _mesa_is_integer_format(internalFormat
))) {
1709 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1710 "glTexImage%dD(integer/non-integer format mismatch)",
1716 /* if we get here, the parameters are OK */
1722 * Test glTexSubImage[123]D() parameters for errors.
1724 * \param ctx GL context.
1725 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1726 * \param target texture target given by the user.
1727 * \param level image level given by the user.
1728 * \param xoffset sub-image x offset given by the user.
1729 * \param yoffset sub-image y offset given by the user.
1730 * \param zoffset sub-image z offset given by the user.
1731 * \param format pixel data format given by the user.
1732 * \param type pixel data type given by the user.
1733 * \param width image width given by the user.
1734 * \param height image height given by the user.
1735 * \param depth image depth given by the user.
1737 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1739 * Verifies each of the parameters against the constants specified in
1740 * __struct gl_contextRec::Const and the supported extensions, and according
1741 * to the OpenGL specification.
1744 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1745 GLenum target
, GLint level
,
1746 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1747 GLint width
, GLint height
, GLint depth
,
1748 GLenum format
, GLenum type
)
1750 /* Basic level check */
1751 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1752 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1756 /* Check for negative sizes */
1758 _mesa_error(ctx
, GL_INVALID_VALUE
,
1759 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1762 if (height
< 0 && dimensions
> 1) {
1763 _mesa_error(ctx
, GL_INVALID_VALUE
,
1764 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1767 if (depth
< 0 && dimensions
> 2) {
1768 _mesa_error(ctx
, GL_INVALID_VALUE
,
1769 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1773 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1774 /* As with the glTexImage2D check above, the error code here
1775 * depends on texture integer.
1777 GLenum error
= _mesa_is_integer_format(format
)
1778 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1779 _mesa_error(ctx
, error
,
1780 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1781 dimensions
, format
, type
);
1790 * Do second part of glTexSubImage which depends on the destination texture.
1791 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1794 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1795 GLenum target
, GLint level
,
1796 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1797 GLint width
, GLint height
, GLint depth
,
1798 GLenum format
, GLenum type
,
1799 const struct gl_texture_image
*destTex
)
1802 /* undefined image level */
1803 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1807 if (xoffset
< -((GLint
)destTex
->Border
)) {
1808 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1812 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1813 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1817 if (dimensions
> 1) {
1818 if (yoffset
< -((GLint
)destTex
->Border
)) {
1819 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1823 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1824 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1829 if (dimensions
> 2) {
1830 if (zoffset
< -((GLint
)destTex
->Border
)) {
1831 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1834 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1835 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1840 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1843 /* do tests which depend on compression block size */
1844 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1846 /* offset must be multiple of block size */
1847 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1848 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1849 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1850 dimensions
, xoffset
, yoffset
);
1853 /* size must be multiple of bw by bh or equal to whole texture size */
1854 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1855 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1856 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1859 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1860 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1861 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1871 * Test glCopyTexImage[12]D() parameters for errors.
1873 * \param ctx GL context.
1874 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1875 * \param target texture target given by the user.
1876 * \param level image level given by the user.
1877 * \param internalFormat internal format given by the user.
1878 * \param width image width given by the user.
1879 * \param height image height given by the user.
1880 * \param border texture border.
1882 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1884 * Verifies each of the parameters against the constants specified in
1885 * __struct gl_contextRec::Const and the supported extensions, and according
1886 * to the OpenGL specification.
1889 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1890 GLenum target
, GLint level
, GLint internalFormat
,
1891 GLint width
, GLint height
, GLint border
)
1893 const GLenum proxyTarget
= get_proxy_target(target
);
1894 const GLenum type
= GL_FLOAT
;
1899 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1900 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1901 dimensions
, _mesa_lookup_enum_by_nr(target
));
1905 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1906 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1907 _mesa_error(ctx
, GL_INVALID_VALUE
,
1908 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1912 /* Check that the source buffer is complete */
1913 if (ctx
->ReadBuffer
->Name
) {
1914 if (ctx
->ReadBuffer
->_Status
== 0) {
1915 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1917 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1918 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1919 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1925 if (border
< 0 || border
> 1 ||
1926 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1927 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1931 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1932 if (baseFormat
< 0) {
1933 _mesa_error(ctx
, GL_INVALID_VALUE
,
1934 "glCopyTexImage%dD(internalFormat)", dimensions
);
1938 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
1939 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1940 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1944 /* Do size, level checking */
1945 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1946 ? (width
== height
) : 1;
1948 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1949 internalFormat
, baseFormat
,
1950 type
, width
, height
,
1954 if (dimensions
== 1) {
1955 _mesa_error(ctx
, GL_INVALID_VALUE
,
1956 "glCopyTexImage1D(width=%d)", width
);
1959 ASSERT(dimensions
== 2);
1960 _mesa_error(ctx
, GL_INVALID_VALUE
,
1961 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1966 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1967 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1968 _mesa_error(ctx
, GL_INVALID_ENUM
,
1969 "glCopyTexImage%dD(target)", dimensions
);
1973 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1974 "glCopyTexImage%dD(border!=0)", dimensions
);
1979 /* if we get here, the parameters are OK */
1985 * Test glCopyTexSubImage[12]D() parameters for errors.
1986 * Note that this is the first part of error checking.
1987 * See also copytexsubimage_error_check2() below for the second part.
1989 * \param ctx GL context.
1990 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1991 * \param target texture target given by the user.
1992 * \param level image level given by the user.
1994 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1997 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
1998 GLenum target
, GLint level
)
2000 /* Check that the source buffer is complete */
2001 if (ctx
->ReadBuffer
->Name
) {
2002 if (ctx
->ReadBuffer
->_Status
== 0) {
2003 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2005 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2006 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2007 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2012 /* check target (proxies not allowed) */
2013 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2014 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2015 dimensions
, _mesa_lookup_enum_by_nr(target
));
2020 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2021 _mesa_error(ctx
, GL_INVALID_VALUE
,
2022 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2031 * Second part of error checking for glCopyTexSubImage[12]D().
2032 * \param xoffset sub-image x offset given by the user.
2033 * \param yoffset sub-image y offset given by the user.
2034 * \param zoffset sub-image z offset given by the user.
2035 * \param width image width given by the user.
2036 * \param height image height given by the user.
2039 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2040 GLenum target
, GLint level
,
2041 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2042 GLsizei width
, GLsizei height
,
2043 const struct gl_texture_image
*teximage
)
2045 /* check that dest tex image exists */
2047 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2048 "glCopyTexSubImage%dD(undefined texture level: %d)",
2055 _mesa_error(ctx
, GL_INVALID_VALUE
,
2056 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2059 if (dimensions
> 1 && height
< 0) {
2060 _mesa_error(ctx
, GL_INVALID_VALUE
,
2061 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2065 /* check x/y offsets */
2066 if (xoffset
< -((GLint
)teximage
->Border
)) {
2067 _mesa_error(ctx
, GL_INVALID_VALUE
,
2068 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2071 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2072 _mesa_error(ctx
, GL_INVALID_VALUE
,
2073 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2076 if (dimensions
> 1) {
2077 if (yoffset
< -((GLint
)teximage
->Border
)) {
2078 _mesa_error(ctx
, GL_INVALID_VALUE
,
2079 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2082 /* NOTE: we're adding the border here, not subtracting! */
2083 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2084 _mesa_error(ctx
, GL_INVALID_VALUE
,
2085 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2090 /* check z offset */
2091 if (dimensions
> 2) {
2092 if (zoffset
< -((GLint
)teximage
->Border
)) {
2093 _mesa_error(ctx
, GL_INVALID_VALUE
,
2094 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2097 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2098 _mesa_error(ctx
, GL_INVALID_VALUE
,
2099 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2104 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2105 /* offset must be multiple of 4 */
2106 if ((xoffset
& 3) || (yoffset
& 3)) {
2107 _mesa_error(ctx
, GL_INVALID_VALUE
,
2108 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2111 /* size must be multiple of 4 */
2112 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2113 _mesa_error(ctx
, GL_INVALID_VALUE
,
2114 "glCopyTexSubImage%dD(width)", dimensions
);
2117 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2118 _mesa_error(ctx
, GL_INVALID_VALUE
,
2119 "glCopyTexSubImage%dD(height)", dimensions
);
2124 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2125 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2129 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2130 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2131 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2132 dimensions
, teximage
->_BaseFormat
);
2136 /* If copying into an integer texture, the source buffer must also be
2139 if (_mesa_is_format_integer_color(teximage
->TexFormat
)) {
2140 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2141 if (!_mesa_is_format_integer_color(rb
->Format
)) {
2142 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2143 "glCopyTexSubImage%dD(source buffer is not integer format)",
2149 /* if we get here, the parameters are OK */
2154 /** Callback info for walking over FBO hash table */
2157 struct gl_context
*ctx
;
2158 struct gl_texture_object
*texObj
;
2164 * Check render to texture callback. Called from _mesa_HashWalk().
2167 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2169 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2170 const struct cb_info
*info
= (struct cb_info
*) userData
;
2171 struct gl_context
*ctx
= info
->ctx
;
2172 const struct gl_texture_object
*texObj
= info
->texObj
;
2173 const GLuint level
= info
->level
, face
= info
->face
;
2175 /* If this is a user-created FBO */
2178 /* check if any of the FBO's attachments point to 'texObj' */
2179 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2180 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2181 if (att
->Type
== GL_TEXTURE
&&
2182 att
->Texture
== texObj
&&
2183 att
->TextureLevel
== level
&&
2184 att
->CubeMapFace
== face
) {
2185 ASSERT(_mesa_get_attachment_teximage(att
));
2186 /* Tell driver about the new renderbuffer texture */
2187 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2188 /* Mark fb status as indeterminate to force re-validation */
2197 * When a texture image is specified we have to check if it's bound to
2198 * any framebuffer objects (render to texture) in order to detect changes
2199 * in size or format since that effects FBO completeness.
2200 * Any FBOs rendering into the texture must be re-validated.
2203 update_fbo_texture(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
2204 GLuint face
, GLuint level
)
2206 /* Only check this texture if it's been marked as RenderToTexture */
2207 if (texObj
->_RenderToTexture
) {
2208 struct cb_info info
;
2210 info
.texObj
= texObj
;
2213 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2219 * If the texture object's GenerateMipmap flag is set and we've
2220 * changed the texture base level image, regenerate the rest of the
2221 * mipmap levels now.
2224 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2225 struct gl_texture_object
*texObj
, GLint level
)
2227 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2228 if (texObj
->GenerateMipmap
&&
2229 level
== texObj
->BaseLevel
&&
2230 level
< texObj
->MaxLevel
) {
2231 ASSERT(ctx
->Driver
.GenerateMipmap
);
2232 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2237 /** Debug helper: override the user-requested internal format */
2239 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2242 if (internalFormat
== GL_RGBA16F_ARB
||
2243 internalFormat
== GL_RGBA32F_ARB
) {
2244 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2247 else if (internalFormat
== GL_RGB16F_ARB
||
2248 internalFormat
== GL_RGB32F_ARB
) {
2249 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2252 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2253 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2254 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2255 return GL_LUMINANCE_ALPHA
;
2257 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2258 internalFormat
== GL_LUMINANCE32F_ARB
) {
2259 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2260 return GL_LUMINANCE
;
2262 else if (internalFormat
== GL_ALPHA16F_ARB
||
2263 internalFormat
== GL_ALPHA32F_ARB
) {
2264 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2268 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2269 internalFormat = GL_RGBA;
2273 return internalFormat
;
2276 return internalFormat
;
2282 * Choose the actual hardware format for a texture image.
2283 * Try to use the same format as the previous image level when possible.
2284 * Otherwise, ask the driver for the best format.
2285 * It's important to try to choose a consistant format for all levels
2286 * for efficient texture memory layout/allocation. In particular, this
2287 * comes up during automatic mipmap generation.
2290 _mesa_choose_texture_format(struct gl_context
*ctx
,
2291 struct gl_texture_object
*texObj
,
2292 GLenum target
, GLint level
,
2293 GLenum internalFormat
, GLenum format
, GLenum type
)
2297 /* see if we've already chosen a format for the previous level */
2299 struct gl_texture_image
*prevImage
=
2300 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2301 /* See if the prev level is defined and has an internal format which
2302 * matches the new internal format.
2305 prevImage
->Width
> 0 &&
2306 prevImage
->InternalFormat
== internalFormat
) {
2307 /* use the same format */
2308 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2309 return prevImage
->TexFormat
;
2313 /* choose format from scratch */
2314 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2315 ASSERT(f
!= MESA_FORMAT_NONE
);
2321 * Common code to implement all the glTexImage1D/2D/3D functions.
2324 teximage(struct gl_context
*ctx
, GLuint dims
,
2325 GLenum target
, GLint level
, GLint internalFormat
,
2326 GLsizei width
, GLsizei height
, GLsizei depth
,
2327 GLint border
, GLenum format
, GLenum type
,
2328 const GLvoid
*pixels
)
2332 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2334 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2335 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2337 _mesa_lookup_enum_by_nr(target
), level
,
2338 _mesa_lookup_enum_by_nr(internalFormat
),
2339 width
, height
, depth
, border
,
2340 _mesa_lookup_enum_by_nr(format
),
2341 _mesa_lookup_enum_by_nr(type
), pixels
);
2343 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2345 /* target error checking */
2346 if (!legal_teximage_target(ctx
, dims
, target
)) {
2347 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2348 dims
, _mesa_lookup_enum_by_nr(target
));
2352 /* general error checking */
2353 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2354 format
, type
, width
, height
, depth
, border
);
2356 if (_mesa_is_proxy_texture(target
)) {
2357 /* Proxy texture: just clear or set state depending on error checking */
2358 struct gl_texture_image
*texImage
=
2359 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2362 /* when error, clear all proxy texture image parameters */
2364 clear_teximage_fields(texImage
);
2367 /* no error, set the tex image parameters */
2368 struct gl_texture_object
*texObj
=
2369 _mesa_get_current_tex_object(ctx
, target
);
2370 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2375 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2376 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
2377 depth
, border
, internalFormat
,
2380 else if (texImage
) {
2381 clear_teximage_fields(texImage
);
2386 /* non-proxy target */
2387 const GLuint face
= _mesa_tex_target_to_face(target
);
2388 struct gl_texture_object
*texObj
;
2389 struct gl_texture_image
*texImage
;
2392 return; /* error was recorded */
2395 if (ctx
->NewState
& _NEW_PIXEL
)
2396 _mesa_update_state(ctx
);
2398 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2400 _mesa_lock_texture(ctx
, texObj
);
2402 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2405 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2408 gl_format texFormat
;
2410 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2412 ASSERT(texImage
->Data
== NULL
);
2413 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2414 internalFormat
, format
,
2417 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2418 _mesa_init_teximage_fields(ctx
, target
, texImage
,
2419 width
, height
, depth
,
2420 border
, internalFormat
, texFormat
);
2422 /* Give the texture to the driver. <pixels> may be null. */
2423 ASSERT(ctx
->Driver
.TexImage3D
);
2426 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2427 width
, border
, format
,
2428 type
, pixels
, &ctx
->Unpack
, texObj
,
2432 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2433 width
, height
, border
, format
,
2434 type
, pixels
, &ctx
->Unpack
, texObj
,
2438 ctx
->Driver
.TexImage3D(ctx
, target
, level
, internalFormat
,
2439 width
, height
, depth
, border
, format
,
2440 type
, pixels
, &ctx
->Unpack
, texObj
,
2444 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2447 check_gen_mipmap(ctx
, target
, texObj
, level
);
2449 update_fbo_texture(ctx
, texObj
, face
, level
);
2452 texObj
->_Complete
= GL_FALSE
;
2453 ctx
->NewState
|= _NEW_TEXTURE
;
2456 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2460 _mesa_unlock_texture(ctx
, texObj
);
2466 * Called from the API. Note that width includes the border.
2469 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2470 GLsizei width
, GLint border
, GLenum format
,
2471 GLenum type
, const GLvoid
*pixels
)
2473 GET_CURRENT_CONTEXT(ctx
);
2474 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2475 border
, format
, type
, pixels
);
2480 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2481 GLsizei width
, GLsizei height
, GLint border
,
2482 GLenum format
, GLenum type
,
2483 const GLvoid
*pixels
)
2485 GET_CURRENT_CONTEXT(ctx
);
2486 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2487 border
, format
, type
, pixels
);
2492 * Called by the API or display list executor.
2493 * Note that width and height include the border.
2496 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2497 GLsizei width
, GLsizei height
, GLsizei depth
,
2498 GLint border
, GLenum format
, GLenum type
,
2499 const GLvoid
*pixels
)
2501 GET_CURRENT_CONTEXT(ctx
);
2502 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2503 border
, format
, type
, pixels
);
2508 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2509 GLsizei width
, GLsizei height
, GLsizei depth
,
2510 GLint border
, GLenum format
, GLenum type
,
2511 const GLvoid
*pixels
)
2513 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2514 depth
, border
, format
, type
, pixels
);
2518 #if FEATURE_OES_EGL_image
2520 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2522 struct gl_texture_object
*texObj
;
2523 struct gl_texture_image
*texImage
;
2524 GET_CURRENT_CONTEXT(ctx
);
2525 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2527 if (!ctx
->Extensions
.OES_EGL_image
) {
2528 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2529 "glEGLImageTargetTexture2DOES(unsupported)");
2533 if (target
!= GL_TEXTURE_2D
) {
2534 _mesa_error(ctx
, GL_INVALID_ENUM
,
2535 "glEGLImageTargetTexture2D(target=%d)", target
);
2539 if (ctx
->NewState
& _NEW_PIXEL
)
2540 _mesa_update_state(ctx
);
2542 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2543 _mesa_lock_texture(ctx
, texObj
);
2545 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2547 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2549 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2551 ASSERT(texImage
->Data
== NULL
);
2552 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2553 texObj
, texImage
, image
);
2556 texObj
->_Complete
= GL_FALSE
;
2557 ctx
->NewState
|= _NEW_TEXTURE
;
2559 _mesa_unlock_texture(ctx
, texObj
);
2567 * Implement all the glTexSubImage1/2/3D() functions.
2570 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2571 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2572 GLsizei width
, GLsizei height
, GLsizei depth
,
2573 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2575 struct gl_texture_object
*texObj
;
2576 struct gl_texture_image
*texImage
;
2578 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2580 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2581 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2583 _mesa_lookup_enum_by_nr(target
), level
,
2584 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2585 _mesa_lookup_enum_by_nr(format
),
2586 _mesa_lookup_enum_by_nr(type
), pixels
);
2588 /* check target (proxies not allowed) */
2589 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2590 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2591 dims
, _mesa_lookup_enum_by_nr(target
));
2595 if (ctx
->NewState
& _NEW_PIXEL
)
2596 _mesa_update_state(ctx
);
2598 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2599 width
, height
, depth
, format
, type
)) {
2600 return; /* error was detected */
2603 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2605 _mesa_lock_texture(ctx
, texObj
);
2607 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2609 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2610 xoffset
, yoffset
, zoffset
,
2611 width
, height
, depth
,
2612 format
, type
, texImage
)) {
2613 /* error was recorded */
2615 else if (width
> 0 && height
> 0 && depth
> 0) {
2616 /* If we have a border, offset=-1 is legal. Bias by border width. */
2619 zoffset
+= texImage
->Border
;
2622 yoffset
+= texImage
->Border
;
2625 xoffset
+= texImage
->Border
;
2630 ctx
->Driver
.TexSubImage1D(ctx
, target
, level
,
2632 format
, type
, pixels
,
2633 &ctx
->Unpack
, texObj
, texImage
);
2636 ctx
->Driver
.TexSubImage2D(ctx
, target
, level
,
2637 xoffset
, yoffset
, width
, height
,
2638 format
, type
, pixels
,
2639 &ctx
->Unpack
, texObj
, texImage
);
2642 ctx
->Driver
.TexSubImage3D(ctx
, target
, level
,
2643 xoffset
, yoffset
, zoffset
,
2644 width
, height
, depth
,
2645 format
, type
, pixels
,
2646 &ctx
->Unpack
, texObj
, texImage
);
2649 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2652 check_gen_mipmap(ctx
, target
, texObj
, level
);
2654 ctx
->NewState
|= _NEW_TEXTURE
;
2657 _mesa_unlock_texture(ctx
, texObj
);
2662 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2663 GLint xoffset
, GLsizei width
,
2664 GLenum format
, GLenum type
,
2665 const GLvoid
*pixels
)
2667 GET_CURRENT_CONTEXT(ctx
);
2668 texsubimage(ctx
, 1, target
, level
,
2671 format
, type
, pixels
);
2676 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2677 GLint xoffset
, GLint yoffset
,
2678 GLsizei width
, GLsizei height
,
2679 GLenum format
, GLenum type
,
2680 const GLvoid
*pixels
)
2682 GET_CURRENT_CONTEXT(ctx
);
2683 texsubimage(ctx
, 2, target
, level
,
2684 xoffset
, yoffset
, 0,
2686 format
, type
, pixels
);
2692 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2693 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2694 GLsizei width
, GLsizei height
, GLsizei depth
,
2695 GLenum format
, GLenum type
,
2696 const GLvoid
*pixels
)
2698 GET_CURRENT_CONTEXT(ctx
);
2699 texsubimage(ctx
, 3, target
, level
,
2700 xoffset
, yoffset
, zoffset
,
2701 width
, height
, depth
,
2702 format
, type
, pixels
);
2708 * Implement the glCopyTexImage1/2D() functions.
2711 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2712 GLenum target
, GLint level
, GLenum internalFormat
,
2713 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2715 struct gl_texture_object
*texObj
;
2716 struct gl_texture_image
*texImage
;
2717 const GLuint face
= _mesa_tex_target_to_face(target
);
2719 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2721 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2722 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2724 _mesa_lookup_enum_by_nr(target
), level
,
2725 _mesa_lookup_enum_by_nr(internalFormat
),
2726 x
, y
, width
, height
, border
);
2728 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2729 _mesa_update_state(ctx
);
2731 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2732 width
, height
, border
))
2735 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2737 _mesa_lock_texture(ctx
, texObj
);
2739 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2742 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2745 /* choose actual hw format */
2746 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2751 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2752 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2754 /* Free old texture image */
2755 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2757 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
, 1,
2758 border
, internalFormat
, texFormat
);
2760 /* Allocate texture memory (no pixel data yet) */
2762 ctx
->Driver
.TexImage1D(ctx
, target
, level
, internalFormat
,
2763 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2764 &ctx
->Unpack
, texObj
, texImage
);
2767 ctx
->Driver
.TexImage2D(ctx
, target
, level
, internalFormat
,
2768 width
, height
, border
, GL_NONE
, GL_NONE
,
2769 NULL
, &ctx
->Unpack
, texObj
, texImage
);
2772 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2775 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
, dstX
,
2779 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
, dstX
, dstY
,
2780 srcX
, srcY
, width
, height
);
2783 check_gen_mipmap(ctx
, target
, texObj
, level
);
2785 update_fbo_texture(ctx
, texObj
, face
, level
);
2788 texObj
->_Complete
= GL_FALSE
;
2789 ctx
->NewState
|= _NEW_TEXTURE
;
2792 /* probably too large of image */
2793 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2797 _mesa_unlock_texture(ctx
, texObj
);
2803 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2804 GLenum internalFormat
,
2806 GLsizei width
, GLint border
)
2808 GET_CURRENT_CONTEXT(ctx
);
2809 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2815 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2816 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2819 GET_CURRENT_CONTEXT(ctx
);
2820 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2821 x
, y
, width
, height
, border
);
2827 * Implementation for glCopyTexSubImage1/2/3D() functions.
2830 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2831 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2832 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2834 struct gl_texture_object
*texObj
;
2835 struct gl_texture_image
*texImage
;
2837 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2839 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2840 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2842 _mesa_lookup_enum_by_nr(target
),
2843 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2845 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2846 _mesa_update_state(ctx
);
2848 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2851 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2853 _mesa_lock_texture(ctx
, texObj
);
2855 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2857 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2858 zoffset
, width
, height
, texImage
)) {
2859 /* error was recored */
2862 /* If we have a border, offset=-1 is legal. Bias by border width. */
2865 zoffset
+= texImage
->Border
;
2868 yoffset
+= texImage
->Border
;
2871 xoffset
+= texImage
->Border
;
2874 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2878 ctx
->Driver
.CopyTexSubImage1D(ctx
, target
, level
,
2879 xoffset
, x
, y
, width
);
2882 ctx
->Driver
.CopyTexSubImage2D(ctx
, target
, level
,
2884 x
, y
, width
, height
);
2887 ctx
->Driver
.CopyTexSubImage3D(ctx
, target
, level
,
2888 xoffset
, yoffset
, zoffset
,
2889 x
, y
, width
, height
);
2892 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
2895 check_gen_mipmap(ctx
, target
, texObj
, level
);
2897 ctx
->NewState
|= _NEW_TEXTURE
;
2901 _mesa_unlock_texture(ctx
, texObj
);
2906 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
2907 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
2909 GET_CURRENT_CONTEXT(ctx
);
2910 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
2916 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
2917 GLint xoffset
, GLint yoffset
,
2918 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2920 GET_CURRENT_CONTEXT(ctx
);
2921 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
2928 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
2929 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2930 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2932 GET_CURRENT_CONTEXT(ctx
);
2933 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
2934 x
, y
, width
, height
);
2940 /**********************************************************************/
2941 /****** Compressed Textures ******/
2942 /**********************************************************************/
2946 * Return expected size of a compressed texture.
2949 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
2952 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2953 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
2958 * Return compressed texture block size, in pixels.
2961 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
2963 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
2964 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
2969 * Error checking for glCompressedTexImage[123]D().
2970 * \param reason returns reason for error, if any
2971 * \return error code or GL_NO_ERROR.
2974 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2975 GLenum target
, GLint level
,
2976 GLenum internalFormat
, GLsizei width
,
2977 GLsizei height
, GLsizei depth
, GLint border
,
2978 GLsizei imageSize
, char **reason
)
2980 const GLenum proxyTarget
= get_proxy_target(target
);
2981 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2983 GLenum choose_format
;
2985 GLenum proxy_format
;
2987 *reason
= ""; /* no error */
2989 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2991 return GL_INVALID_ENUM
;
2994 /* This will detect any invalid internalFormat value */
2995 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2996 *reason
= "internalFormat";
2997 return GL_INVALID_ENUM
;
3000 switch (internalFormat
) {
3002 case GL_PALETTE4_RGB8_OES
:
3003 case GL_PALETTE4_RGBA8_OES
:
3004 case GL_PALETTE4_R5_G6_B5_OES
:
3005 case GL_PALETTE4_RGBA4_OES
:
3006 case GL_PALETTE4_RGB5_A1_OES
:
3007 case GL_PALETTE8_RGB8_OES
:
3008 case GL_PALETTE8_RGBA8_OES
:
3009 case GL_PALETTE8_R5_G6_B5_OES
:
3010 case GL_PALETTE8_RGBA4_OES
:
3011 case GL_PALETTE8_RGB5_A1_OES
:
3012 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3014 proxy_format
= choose_format
;
3017 if (level
> 0 || level
< -maxLevels
) {
3019 return GL_INVALID_VALUE
;
3022 if (dimensions
!= 2) {
3023 *reason
= "compressed paletted textures must be 2D";
3024 return GL_INVALID_OPERATION
;
3027 /* Figure out the expected texture size (in bytes). This will be
3028 * checked against the actual size later.
3030 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3033 /* This is for the benefit of the TestProxyTexImage below. It expects
3034 * level to be non-negative. OES_compressed_paletted_texture uses a
3035 * weird mechanism where the level specified to glCompressedTexImage2D
3036 * is -(n-1) number of levels in the texture, and the data specifies the
3037 * complete mipmap stack. This is done to ensure the palette is the
3038 * same for all levels.
3045 choose_format
= GL_NONE
;
3046 choose_type
= GL_NONE
;
3047 proxy_format
= internalFormat
;
3050 if (level
< 0 || level
>= maxLevels
) {
3052 return GL_INVALID_VALUE
;
3055 /* Figure out the expected texture size (in bytes). This will be
3056 * checked against the actual size later.
3058 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3062 /* This should really never fail */
3063 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3064 *reason
= "internalFormat";
3065 return GL_INVALID_ENUM
;
3068 /* No compressed formats support borders at this time */
3070 *reason
= "border != 0";
3071 return GL_INVALID_VALUE
;
3074 /* For cube map, width must equal height */
3075 if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3076 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
&& width
!= height
) {
3077 *reason
= "width != height";
3078 return GL_INVALID_VALUE
;
3081 /* check image size against compression block size */
3083 gl_format texFormat
=
3084 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3085 choose_format
, choose_type
);
3088 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3089 if ((width
> bw
&& width
% bw
> 0) ||
3090 (height
> bh
&& height
% bh
> 0)) {
3092 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3093 * generated [...] if any parameter combinations are not
3094 * supported by the specific compressed internal format.
3096 *reason
= "invalid width or height for compression format";
3097 return GL_INVALID_OPERATION
;
3101 /* check image sizes */
3102 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3103 proxy_format
, choose_format
,
3105 width
, height
, depth
, border
)) {
3106 /* See error comment above */
3107 *reason
= "invalid width, height or format";
3108 return GL_INVALID_OPERATION
;
3111 /* check image size in bytes */
3112 if (expectedSize
!= imageSize
) {
3113 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3114 * if <imageSize> is not consistent with the format, dimensions, and
3115 * contents of the specified image.
3117 *reason
= "imageSize inconsistant with width/height/format";
3118 return GL_INVALID_VALUE
;
3126 * Error checking for glCompressedTexSubImage[123]D().
3127 * \warning There are some bad assumptions here about the size of compressed
3128 * texture tiles (multiple of 4) used to test the validity of the
3129 * offset and size parameters.
3130 * \return error code or GL_NO_ERROR.
3133 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3134 GLenum target
, GLint level
,
3135 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3136 GLsizei width
, GLsizei height
, GLsizei depth
,
3137 GLenum format
, GLsizei imageSize
)
3139 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3143 if (dimensions
== 1) {
3144 /* 1D compressed textures not allowed */
3145 return GL_INVALID_ENUM
;
3147 else if (dimensions
== 2) {
3148 if (target
== GL_PROXY_TEXTURE_2D
) {
3149 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3151 else if (target
== GL_TEXTURE_2D
) {
3152 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3154 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3155 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3156 return GL_INVALID_ENUM
; /*target*/
3157 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3159 else if (target
>= GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
&&
3160 target
<= GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
) {
3161 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3162 return GL_INVALID_ENUM
; /*target*/
3163 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3166 return GL_INVALID_ENUM
; /*target*/
3169 else if (dimensions
== 3) {
3170 /* 3D compressed textures not allowed */
3171 return GL_INVALID_ENUM
;
3174 maxTextureSize
= 1 << (maxLevels
- 1);
3176 /* this will catch any invalid compressed format token */
3177 if (!_mesa_is_compressed_format(ctx
, format
))
3178 return GL_INVALID_ENUM
;
3180 if (width
< 1 || width
> maxTextureSize
)
3181 return GL_INVALID_VALUE
;
3183 if ((height
< 1 || height
> maxTextureSize
)
3185 return GL_INVALID_VALUE
;
3187 if (level
< 0 || level
>= maxLevels
)
3188 return GL_INVALID_VALUE
;
3191 * do checks which depend on compression block size
3193 get_compressed_block_size(format
, &bw
, &bh
);
3195 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3196 return GL_INVALID_VALUE
;
3198 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3199 return GL_INVALID_VALUE
;
3201 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3202 return GL_INVALID_VALUE
;
3204 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3205 if (expectedSize
!= imageSize
)
3206 return GL_INVALID_VALUE
;
3213 * Do second part of glCompressedTexSubImage error checking.
3214 * \return GL_TRUE if error found, GL_FALSE otherwise.
3217 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3218 GLsizei width
, GLsizei height
,
3219 GLsizei depth
, GLenum format
,
3220 struct gl_texture_image
*texImage
)
3223 if ((GLint
) format
!= texImage
->InternalFormat
) {
3224 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3225 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3229 if (((width
== 1 || width
== 2) &&
3230 width
!= (GLsizei
) texImage
->Width
) ||
3231 (width
> (GLsizei
) texImage
->Width
)) {
3232 _mesa_error(ctx
, GL_INVALID_VALUE
,
3233 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3238 if (((height
== 1 || height
== 2) &&
3239 height
!= (GLsizei
) texImage
->Height
) ||
3240 (height
> (GLsizei
) texImage
->Height
)) {
3241 _mesa_error(ctx
, GL_INVALID_VALUE
,
3242 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3248 if (((depth
== 1 || depth
== 2) &&
3249 depth
!= (GLsizei
) texImage
->Depth
) ||
3250 (depth
> (GLsizei
) texImage
->Depth
)) {
3251 _mesa_error(ctx
, GL_INVALID_VALUE
,
3252 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3262 * Implementation of the glCompressedTexImage1/2/3D() functions.
3265 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3266 GLenum target
, GLint level
,
3267 GLenum internalFormat
, GLsizei width
,
3268 GLsizei height
, GLsizei depth
, GLint border
,
3269 GLsizei imageSize
, const GLvoid
*data
)
3274 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3276 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3278 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3280 _mesa_lookup_enum_by_nr(target
), level
,
3281 _mesa_lookup_enum_by_nr(internalFormat
),
3282 width
, height
, depth
, border
, imageSize
, data
);
3285 if (!legal_teximage_target(ctx
, dims
, target
)) {
3286 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3287 dims
, _mesa_lookup_enum_by_nr(target
));
3291 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3292 internalFormat
, width
, height
, depth
,
3293 border
, imageSize
, &reason
);
3296 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3301 /* XXX this is kind of a hack */
3303 switch (internalFormat
) {
3304 case GL_PALETTE4_RGB8_OES
:
3305 case GL_PALETTE4_RGBA8_OES
:
3306 case GL_PALETTE4_R5_G6_B5_OES
:
3307 case GL_PALETTE4_RGBA4_OES
:
3308 case GL_PALETTE4_RGB5_A1_OES
:
3309 case GL_PALETTE8_RGB8_OES
:
3310 case GL_PALETTE8_RGBA8_OES
:
3311 case GL_PALETTE8_R5_G6_B5_OES
:
3312 case GL_PALETTE8_RGBA4_OES
:
3313 case GL_PALETTE8_RGB5_A1_OES
:
3314 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3315 width
, height
, imageSize
, data
);
3321 if (_mesa_is_proxy_texture(target
)) {
3322 /* Proxy texture: just check for errors and update proxy state */
3323 struct gl_texture_image
*texImage
;
3326 struct gl_texture_object
*texObj
=
3327 _mesa_get_current_tex_object(ctx
, target
);
3328 gl_format texFormat
=
3329 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3330 internalFormat
, GL_NONE
, GL_NONE
);
3331 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3332 error
= GL_OUT_OF_MEMORY
;
3336 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3339 /* if error, clear all proxy texture image parameters */
3340 clear_teximage_fields(texImage
);
3343 /* no error: store the teximage parameters */
3344 _mesa_init_teximage_fields(ctx
, target
, texImage
, width
, height
,
3345 depth
, border
, internalFormat
,
3351 /* non-proxy target */
3352 struct gl_texture_object
*texObj
;
3353 struct gl_texture_image
*texImage
;
3356 _mesa_error(ctx
, error
, "glCompressedTexImage%uD", dims
);
3360 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3362 _mesa_lock_texture(ctx
, texObj
);
3364 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3366 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3367 "glCompressedTexImage%uD", dims
);
3370 gl_format texFormat
;
3372 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3373 ASSERT(texImage
->Data
== NULL
);
3375 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3376 internalFormat
, GL_NONE
,
3379 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3380 _mesa_init_teximage_fields(ctx
, target
, texImage
,
3381 width
, height
, depth
,
3382 border
, internalFormat
, texFormat
);
3386 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3387 ctx
->Driver
.CompressedTexImage1D(ctx
, target
, level
,
3390 border
, imageSize
, data
,
3394 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3395 ctx
->Driver
.CompressedTexImage2D(ctx
, target
, level
,
3398 border
, imageSize
, data
,
3402 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3403 ctx
->Driver
.CompressedTexImage3D(ctx
, target
, level
,
3405 width
, height
, depth
,
3406 border
, imageSize
, data
,
3410 _mesa_problem(ctx
, "bad dims in compressedteximage");
3413 check_gen_mipmap(ctx
, target
, texObj
, level
);
3416 texObj
->_Complete
= GL_FALSE
;
3417 ctx
->NewState
|= _NEW_TEXTURE
;
3420 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3421 "glCompressedTexImage%uD", dims
);
3425 _mesa_unlock_texture(ctx
, texObj
);
3431 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3432 GLenum internalFormat
, GLsizei width
,
3433 GLint border
, GLsizei imageSize
,
3436 GET_CURRENT_CONTEXT(ctx
);
3437 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3438 width
, 1, 1, border
, imageSize
, data
);
3443 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3444 GLenum internalFormat
, GLsizei width
,
3445 GLsizei height
, GLint border
, GLsizei imageSize
,
3448 GET_CURRENT_CONTEXT(ctx
);
3449 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3450 width
, height
, 1, border
, imageSize
, data
);
3455 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3456 GLenum internalFormat
, GLsizei width
,
3457 GLsizei height
, GLsizei depth
, GLint border
,
3458 GLsizei imageSize
, const GLvoid
*data
)
3460 GET_CURRENT_CONTEXT(ctx
);
3461 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3462 width
, height
, depth
, border
, imageSize
, data
);
3467 * Common helper for glCompressedTexSubImage1/2/3D().
3470 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3471 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3472 GLsizei width
, GLsizei height
, GLsizei depth
,
3473 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3475 struct gl_texture_object
*texObj
;
3476 struct gl_texture_image
*texImage
;
3478 GET_CURRENT_CONTEXT(ctx
);
3479 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3481 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3482 xoffset
, 0, 0, /* pos */
3483 width
, height
, depth
, /* size */
3486 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3490 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3492 _mesa_lock_texture(ctx
, texObj
);
3494 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3497 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3498 format
, texImage
)) {
3499 /* error was recorded */
3501 else if (width
> 0 && height
> 0 && depth
> 0) {
3504 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3505 ctx
->Driver
.CompressedTexSubImage1D(ctx
, target
, level
,
3507 format
, imageSize
, data
,
3512 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3513 ctx
->Driver
.CompressedTexSubImage2D(ctx
, target
, level
,
3516 format
, imageSize
, data
,
3521 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3522 ctx
->Driver
.CompressedTexSubImage3D(ctx
, target
, level
,
3523 xoffset
, yoffset
, zoffset
,
3524 width
, height
, depth
,
3525 format
, imageSize
, data
,
3533 check_gen_mipmap(ctx
, target
, texObj
, level
);
3535 ctx
->NewState
|= _NEW_TEXTURE
;
3538 _mesa_unlock_texture(ctx
, texObj
);
3543 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3544 GLsizei width
, GLenum format
,
3545 GLsizei imageSize
, const GLvoid
*data
)
3547 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3548 format
, imageSize
, data
);
3553 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3554 GLint yoffset
, GLsizei width
, GLsizei height
,
3555 GLenum format
, GLsizei imageSize
,
3558 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3559 width
, height
, 1, format
, imageSize
, data
);
3564 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3565 GLint yoffset
, GLint zoffset
, GLsizei width
,
3566 GLsizei height
, GLsizei depth
, GLenum format
,
3567 GLsizei imageSize
, const GLvoid
*data
)
3569 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3570 width
, height
, depth
, format
, imageSize
, data
);
3575 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3576 * return the basic data type and number of components for the format.
3577 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3580 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3581 GLenum
*datatype
, GLuint
*components
)
3583 switch (internalFormat
) {
3585 *datatype
= GL_UNSIGNED_BYTE
;
3589 *datatype
= GL_UNSIGNED_SHORT
;
3592 case GL_ALPHA16F_ARB
:
3593 *datatype
= GL_HALF_FLOAT
;
3596 case GL_ALPHA32F_ARB
:
3597 *datatype
= GL_FLOAT
;
3600 case GL_ALPHA8I_EXT
:
3601 *datatype
= GL_BYTE
;
3604 case GL_ALPHA16I_EXT
:
3605 *datatype
= GL_SHORT
;
3608 case GL_ALPHA32I_EXT
:
3612 case GL_ALPHA8UI_EXT
:
3613 *datatype
= GL_UNSIGNED_BYTE
;
3616 case GL_ALPHA16UI_EXT
:
3617 *datatype
= GL_UNSIGNED_SHORT
;
3620 case GL_ALPHA32UI_EXT
:
3621 *datatype
= GL_UNSIGNED_INT
;
3625 *datatype
= GL_UNSIGNED_BYTE
;
3628 case GL_LUMINANCE16
:
3629 *datatype
= GL_UNSIGNED_SHORT
;
3632 case GL_LUMINANCE16F_ARB
:
3633 *datatype
= GL_HALF_FLOAT
;
3636 case GL_LUMINANCE32F_ARB
:
3637 *datatype
= GL_FLOAT
;
3640 case GL_LUMINANCE8I_EXT
:
3641 *datatype
= GL_BYTE
;
3644 case GL_LUMINANCE16I_EXT
:
3645 *datatype
= GL_SHORT
;
3648 case GL_LUMINANCE32I_EXT
:
3652 case GL_LUMINANCE8UI_EXT
:
3653 *datatype
= GL_UNSIGNED_BYTE
;
3656 case GL_LUMINANCE16UI_EXT
:
3657 *datatype
= GL_UNSIGNED_SHORT
;
3660 case GL_LUMINANCE32UI_EXT
:
3661 *datatype
= GL_UNSIGNED_INT
;
3664 case GL_LUMINANCE8_ALPHA8
:
3665 *datatype
= GL_UNSIGNED_BYTE
;
3668 case GL_LUMINANCE16_ALPHA16
:
3669 *datatype
= GL_UNSIGNED_SHORT
;
3672 case GL_LUMINANCE_ALPHA16F_ARB
:
3673 *datatype
= GL_HALF_FLOAT
;
3676 case GL_LUMINANCE_ALPHA32F_ARB
:
3677 *datatype
= GL_FLOAT
;
3680 case GL_LUMINANCE_ALPHA8I_EXT
:
3681 *datatype
= GL_BYTE
;
3684 case GL_LUMINANCE_ALPHA16I_EXT
:
3685 *datatype
= GL_SHORT
;
3688 case GL_LUMINANCE_ALPHA32I_EXT
:
3692 case GL_LUMINANCE_ALPHA8UI_EXT
:
3693 *datatype
= GL_UNSIGNED_BYTE
;
3696 case GL_LUMINANCE_ALPHA16UI_EXT
:
3697 *datatype
= GL_UNSIGNED_SHORT
;
3700 case GL_LUMINANCE_ALPHA32UI_EXT
:
3701 *datatype
= GL_UNSIGNED_INT
;
3705 *datatype
= GL_UNSIGNED_BYTE
;
3708 case GL_INTENSITY16
:
3709 *datatype
= GL_UNSIGNED_SHORT
;
3712 case GL_INTENSITY16F_ARB
:
3713 *datatype
= GL_HALF_FLOAT
;
3716 case GL_INTENSITY32F_ARB
:
3717 *datatype
= GL_FLOAT
;
3720 case GL_INTENSITY8I_EXT
:
3721 *datatype
= GL_BYTE
;
3724 case GL_INTENSITY16I_EXT
:
3725 *datatype
= GL_SHORT
;
3728 case GL_INTENSITY32I_EXT
:
3732 case GL_INTENSITY8UI_EXT
:
3733 *datatype
= GL_UNSIGNED_BYTE
;
3736 case GL_INTENSITY16UI_EXT
:
3737 *datatype
= GL_UNSIGNED_SHORT
;
3740 case GL_INTENSITY32UI_EXT
:
3741 *datatype
= GL_UNSIGNED_INT
;
3745 *datatype
= GL_UNSIGNED_BYTE
;
3749 *datatype
= GL_UNSIGNED_SHORT
;
3752 case GL_RGBA16F_ARB
:
3753 *datatype
= GL_HALF_FLOAT
;
3756 case GL_RGBA32F_ARB
:
3757 *datatype
= GL_FLOAT
;
3761 *datatype
= GL_BYTE
;
3764 case GL_RGBA16I_EXT
:
3765 *datatype
= GL_SHORT
;
3768 case GL_RGBA32I_EXT
:
3772 case GL_RGBA8UI_EXT
:
3773 *datatype
= GL_UNSIGNED_BYTE
;
3776 case GL_RGBA16UI_EXT
:
3777 *datatype
= GL_UNSIGNED_SHORT
;
3780 case GL_RGBA32UI_EXT
:
3781 *datatype
= GL_UNSIGNED_INT
;
3788 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3791 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3798 /** GL_ARB_texture_buffer_object */
3800 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3802 struct gl_texture_object
*texObj
;
3803 struct gl_buffer_object
*bufObj
;
3807 GET_CURRENT_CONTEXT(ctx
);
3808 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3810 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3811 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3815 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3816 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3820 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3821 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3826 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3827 if (buffer
&& !bufObj
) {
3828 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3832 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3834 _mesa_lock_texture(ctx
, texObj
);
3836 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3837 texObj
->BufferObjectFormat
= internalFormat
;
3839 _mesa_unlock_texture(ctx
, texObj
);