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 * Return the simple base format for a given internal texture format.
62 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
64 * \param ctx GL context.
65 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
67 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
68 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
70 * This is the format which is used during texture application (i.e. the
71 * texture format and env mode determine the arithmetic used.
73 * XXX this could be static
76 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
78 switch (internalFormat
) {
93 case GL_LUMINANCE_ALPHA
:
94 case GL_LUMINANCE4_ALPHA4
:
95 case GL_LUMINANCE6_ALPHA2
:
96 case GL_LUMINANCE8_ALPHA8
:
97 case GL_LUMINANCE12_ALPHA4
:
98 case GL_LUMINANCE12_ALPHA12
:
99 case GL_LUMINANCE16_ALPHA16
:
100 return GL_LUMINANCE_ALPHA
;
131 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
133 if (ctx
->API
!= API_OPENGL
) {
134 switch (internalFormat
) {
142 if (ctx
->Extensions
.ARB_depth_texture
) {
143 switch (internalFormat
) {
144 case GL_DEPTH_COMPONENT
:
145 case GL_DEPTH_COMPONENT16
:
146 case GL_DEPTH_COMPONENT24
:
147 case GL_DEPTH_COMPONENT32
:
148 return GL_DEPTH_COMPONENT
;
154 switch (internalFormat
) {
155 case GL_COMPRESSED_ALPHA
:
157 case GL_COMPRESSED_LUMINANCE
:
159 case GL_COMPRESSED_LUMINANCE_ALPHA
:
160 return GL_LUMINANCE_ALPHA
;
161 case GL_COMPRESSED_INTENSITY
:
163 case GL_COMPRESSED_RGB
:
165 case GL_COMPRESSED_RGBA
:
171 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
172 switch (internalFormat
) {
173 case GL_COMPRESSED_RGB_FXT1_3DFX
:
175 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
182 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
183 switch (internalFormat
) {
184 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
186 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
187 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
188 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
195 if (ctx
->Extensions
.S3_s3tc
) {
196 switch (internalFormat
) {
208 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
209 if (internalFormat
== GL_YCBCR_MESA
)
210 return GL_YCBCR_MESA
;
213 if (ctx
->Extensions
.ARB_texture_float
) {
214 switch (internalFormat
) {
215 case GL_ALPHA16F_ARB
:
216 case GL_ALPHA32F_ARB
:
224 case GL_INTENSITY16F_ARB
:
225 case GL_INTENSITY32F_ARB
:
227 case GL_LUMINANCE16F_ARB
:
228 case GL_LUMINANCE32F_ARB
:
230 case GL_LUMINANCE_ALPHA16F_ARB
:
231 case GL_LUMINANCE_ALPHA32F_ARB
:
232 return GL_LUMINANCE_ALPHA
;
238 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
239 switch (internalFormat
) {
248 if (ctx
->Extensions
.EXT_texture_snorm
) {
249 switch (internalFormat
) {
264 case GL_RGBA16_SNORM
:
267 case GL_ALPHA8_SNORM
:
268 case GL_ALPHA16_SNORM
:
270 case GL_LUMINANCE_SNORM
:
271 case GL_LUMINANCE8_SNORM
:
272 case GL_LUMINANCE16_SNORM
:
274 case GL_LUMINANCE_ALPHA_SNORM
:
275 case GL_LUMINANCE8_ALPHA8_SNORM
:
276 case GL_LUMINANCE16_ALPHA16_SNORM
:
277 return GL_LUMINANCE_ALPHA
;
278 case GL_INTENSITY_SNORM
:
279 case GL_INTENSITY8_SNORM
:
280 case GL_INTENSITY16_SNORM
:
287 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
288 switch (internalFormat
) {
289 case GL_DEPTH_STENCIL_EXT
:
290 case GL_DEPTH24_STENCIL8_EXT
:
291 return GL_DEPTH_STENCIL_EXT
;
297 #if FEATURE_EXT_texture_sRGB
298 if (ctx
->Extensions
.EXT_texture_sRGB
) {
299 switch (internalFormat
) {
302 case GL_COMPRESSED_SRGB_EXT
:
303 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
305 case GL_SRGB_ALPHA_EXT
:
306 case GL_SRGB8_ALPHA8_EXT
:
307 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
308 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
309 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
310 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
312 case GL_SLUMINANCE_ALPHA_EXT
:
313 case GL_SLUMINANCE8_ALPHA8_EXT
:
314 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
315 return GL_LUMINANCE_ALPHA
;
316 case GL_SLUMINANCE_EXT
:
317 case GL_SLUMINANCE8_EXT
:
318 case GL_COMPRESSED_SLUMINANCE_EXT
:
324 #endif /* FEATURE_EXT_texture_sRGB */
326 if (ctx
->VersionMajor
>= 3 ||
327 ctx
->Extensions
.EXT_texture_integer
) {
328 switch (internalFormat
) {
330 case GL_RGBA16UI_EXT
:
331 case GL_RGBA32UI_EXT
:
347 if (ctx
->Extensions
.EXT_texture_integer
) {
348 switch (internalFormat
) {
349 case GL_ALPHA8UI_EXT
:
350 case GL_ALPHA16UI_EXT
:
351 case GL_ALPHA32UI_EXT
:
353 case GL_ALPHA16I_EXT
:
354 case GL_ALPHA32I_EXT
:
356 case GL_INTENSITY8UI_EXT
:
357 case GL_INTENSITY16UI_EXT
:
358 case GL_INTENSITY32UI_EXT
:
359 case GL_INTENSITY8I_EXT
:
360 case GL_INTENSITY16I_EXT
:
361 case GL_INTENSITY32I_EXT
:
363 case GL_LUMINANCE8UI_EXT
:
364 case GL_LUMINANCE16UI_EXT
:
365 case GL_LUMINANCE32UI_EXT
:
366 case GL_LUMINANCE8I_EXT
:
367 case GL_LUMINANCE16I_EXT
:
368 case GL_LUMINANCE32I_EXT
:
370 case GL_LUMINANCE_ALPHA8UI_EXT
:
371 case GL_LUMINANCE_ALPHA16UI_EXT
:
372 case GL_LUMINANCE_ALPHA32UI_EXT
:
373 case GL_LUMINANCE_ALPHA8I_EXT
:
374 case GL_LUMINANCE_ALPHA16I_EXT
:
375 case GL_LUMINANCE_ALPHA32I_EXT
:
376 return GL_LUMINANCE_ALPHA
;
382 if (ctx
->Extensions
.ARB_texture_rg
) {
383 switch (internalFormat
) {
385 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
387 if (!ctx
->Extensions
.ARB_half_float_pixel
)
391 if (!ctx
->Extensions
.ARB_texture_float
)
400 if (ctx
->VersionMajor
< 3 && !ctx
->Extensions
.EXT_texture_integer
)
406 case GL_COMPRESSED_RED
:
410 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
412 if (!ctx
->Extensions
.ARB_half_float_pixel
)
416 if (!ctx
->Extensions
.ARB_texture_float
)
425 if (ctx
->VersionMajor
< 3 && !ctx
->Extensions
.EXT_texture_integer
)
431 case GL_COMPRESSED_RG
:
438 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
439 switch (internalFormat
) {
447 if (ctx
->Extensions
.EXT_packed_float
) {
448 switch (internalFormat
) {
449 case GL_R11F_G11F_B10F_EXT
:
456 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
457 switch (internalFormat
) {
458 case GL_DEPTH_COMPONENT32F
:
459 return GL_DEPTH_COMPONENT
;
460 case GL_DEPTH32F_STENCIL8
:
461 return GL_DEPTH_STENCIL
;
467 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
468 switch (internalFormat
) {
469 case GL_COMPRESSED_RED_RGTC1
:
470 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
472 case GL_COMPRESSED_RG_RGTC2
:
473 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
480 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
481 switch (internalFormat
) {
482 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
483 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
485 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
486 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
487 return GL_LUMINANCE_ALPHA
;
493 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
494 switch (internalFormat
) {
495 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
496 return GL_LUMINANCE_ALPHA
;
502 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
503 switch (internalFormat
) {
504 case GL_ETC1_RGB8_OES
:
511 if (ctx
->API
== API_OPENGLES
) {
512 switch (internalFormat
) {
513 case GL_PALETTE4_RGB8_OES
:
514 case GL_PALETTE4_R5_G6_B5_OES
:
515 case GL_PALETTE8_RGB8_OES
:
516 case GL_PALETTE8_R5_G6_B5_OES
:
518 case GL_PALETTE4_RGBA8_OES
:
519 case GL_PALETTE8_RGB5_A1_OES
:
520 case GL_PALETTE4_RGBA4_OES
:
521 case GL_PALETTE4_RGB5_A1_OES
:
522 case GL_PALETTE8_RGBA8_OES
:
523 case GL_PALETTE8_RGBA4_OES
:
530 return -1; /* error */
535 * For cube map faces, return a face index in [0,5].
536 * For other targets return 0;
539 _mesa_tex_target_to_face(GLenum target
)
541 if (_mesa_is_cube_face(target
))
542 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
550 * Install gl_texture_image in a gl_texture_object according to the target
551 * and level parameters.
553 * \param tObj texture object.
554 * \param target texture target.
555 * \param level image level.
556 * \param texImage texture image.
559 set_tex_image(struct gl_texture_object
*tObj
,
560 GLenum target
, GLint level
,
561 struct gl_texture_image
*texImage
)
563 const GLuint face
= _mesa_tex_target_to_face(target
);
567 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
570 tObj
->Image
[face
][level
] = texImage
;
572 /* Set the 'back' pointer */
573 texImage
->TexObject
= tObj
;
574 texImage
->Level
= level
;
575 texImage
->Face
= face
;
580 * Allocate a texture image structure.
582 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
585 * \return a pointer to gl_texture_image struct with all fields initialized to
588 struct gl_texture_image
*
589 _mesa_new_texture_image( struct gl_context
*ctx
)
592 return CALLOC_STRUCT(gl_texture_image
);
597 * Free a gl_texture_image and associated data.
598 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
600 * \param texImage texture image.
602 * Free the texture image structure and the associated image data.
605 _mesa_delete_texture_image(struct gl_context
*ctx
,
606 struct gl_texture_image
*texImage
)
608 /* Free texImage->Data and/or any other driver-specific texture
611 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
612 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
618 * Test if a target is a proxy target.
620 * \param target texture target.
622 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
625 _mesa_is_proxy_texture(GLenum target
)
628 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
629 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
631 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
633 return (target
== GL_PROXY_TEXTURE_1D
||
634 target
== GL_PROXY_TEXTURE_2D
||
635 target
== GL_PROXY_TEXTURE_3D
||
636 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
637 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
638 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
639 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
644 * Return the proxy target which corresponds to the given texture target
647 get_proxy_target(GLenum target
)
651 case GL_PROXY_TEXTURE_1D
:
652 return GL_PROXY_TEXTURE_1D
;
654 case GL_PROXY_TEXTURE_2D
:
655 return GL_PROXY_TEXTURE_2D
;
657 case GL_PROXY_TEXTURE_3D
:
658 return GL_PROXY_TEXTURE_3D
;
659 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
660 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
661 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
662 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
663 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
664 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
665 case GL_TEXTURE_CUBE_MAP_ARB
:
666 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
667 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
668 case GL_TEXTURE_RECTANGLE_NV
:
669 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
670 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
671 case GL_TEXTURE_1D_ARRAY_EXT
:
672 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
673 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
674 case GL_TEXTURE_2D_ARRAY_EXT
:
675 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
676 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
678 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
685 * Get the texture object that corresponds to the target of the given
686 * texture unit. The target should have already been checked for validity.
688 * \param ctx GL context.
689 * \param texUnit texture unit.
690 * \param target texture target.
692 * \return pointer to the texture object on success, or NULL on failure.
694 struct gl_texture_object
*
695 _mesa_select_tex_object(struct gl_context
*ctx
,
696 const struct gl_texture_unit
*texUnit
,
699 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
700 ctx
->Extensions
.EXT_texture_array
);
704 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
705 case GL_PROXY_TEXTURE_1D
:
706 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
708 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
709 case GL_PROXY_TEXTURE_2D
:
710 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
712 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
713 case GL_PROXY_TEXTURE_3D
:
714 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
715 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
716 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
717 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
718 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
719 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
720 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
721 case GL_TEXTURE_CUBE_MAP_ARB
:
722 return ctx
->Extensions
.ARB_texture_cube_map
723 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
724 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
725 return ctx
->Extensions
.ARB_texture_cube_map
726 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
727 case GL_TEXTURE_RECTANGLE_NV
:
728 return ctx
->Extensions
.NV_texture_rectangle
729 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
730 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
731 return ctx
->Extensions
.NV_texture_rectangle
732 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
733 case GL_TEXTURE_1D_ARRAY_EXT
:
734 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
735 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
736 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
737 case GL_TEXTURE_2D_ARRAY_EXT
:
738 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
739 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
740 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
741 case GL_TEXTURE_BUFFER
:
742 return ctx
->Extensions
.ARB_texture_buffer_object
743 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
744 case GL_TEXTURE_EXTERNAL_OES
:
745 return ctx
->Extensions
.OES_EGL_image_external
746 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
748 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
755 * Return pointer to texture object for given target on current texture unit.
757 struct gl_texture_object
*
758 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
760 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
761 return _mesa_select_tex_object(ctx
, texUnit
, target
);
766 * Get a texture image pointer from a texture object, given a texture
767 * target and mipmap level. The target and level parameters should
768 * have already been error-checked.
770 * \param ctx GL context.
771 * \param texObj texture unit.
772 * \param target texture target.
773 * \param level image level.
775 * \return pointer to the texture image structure, or NULL on failure.
777 struct gl_texture_image
*
778 _mesa_select_tex_image(struct gl_context
*ctx
,
779 const struct gl_texture_object
*texObj
,
780 GLenum target
, GLint level
)
782 const GLuint face
= _mesa_tex_target_to_face(target
);
786 ASSERT(level
< MAX_TEXTURE_LEVELS
);
788 return texObj
->Image
[face
][level
];
793 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
794 * it and install it. Only return NULL if passed a bad parameter or run
797 struct gl_texture_image
*
798 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
799 GLenum target
, GLint level
)
801 struct gl_texture_image
*texImage
;
806 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
808 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
810 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
814 set_tex_image(texObj
, target
, level
, texImage
);
822 * Return pointer to the specified proxy texture image.
823 * Note that proxy textures are per-context, not per-texture unit.
824 * \return pointer to texture image or NULL if invalid target, invalid
825 * level, or out of memory.
827 struct gl_texture_image
*
828 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
830 struct gl_texture_image
*texImage
;
837 case GL_PROXY_TEXTURE_1D
:
838 if (level
>= ctx
->Const
.MaxTextureLevels
)
840 texIndex
= TEXTURE_1D_INDEX
;
842 case GL_PROXY_TEXTURE_2D
:
843 if (level
>= ctx
->Const
.MaxTextureLevels
)
845 texIndex
= TEXTURE_2D_INDEX
;
847 case GL_PROXY_TEXTURE_3D
:
848 if (level
>= ctx
->Const
.Max3DTextureLevels
)
850 texIndex
= TEXTURE_3D_INDEX
;
852 case GL_PROXY_TEXTURE_CUBE_MAP
:
853 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
855 texIndex
= TEXTURE_CUBE_INDEX
;
857 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
860 texIndex
= TEXTURE_RECT_INDEX
;
862 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
863 if (level
>= ctx
->Const
.MaxTextureLevels
)
865 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
867 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
868 if (level
>= ctx
->Const
.MaxTextureLevels
)
870 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
876 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
878 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
880 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
883 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
884 /* Set the 'back' pointer */
885 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
892 * Get the maximum number of allowed mipmap levels.
894 * \param ctx GL context.
895 * \param target texture target.
897 * \return the maximum number of allowed mipmap levels for the given
898 * texture target, or zero if passed a bad target.
903 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
907 case GL_PROXY_TEXTURE_1D
:
909 case GL_PROXY_TEXTURE_2D
:
910 return ctx
->Const
.MaxTextureLevels
;
912 case GL_PROXY_TEXTURE_3D
:
913 return ctx
->Const
.Max3DTextureLevels
;
914 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
915 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
916 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
917 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
918 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
919 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
920 case GL_TEXTURE_CUBE_MAP_ARB
:
921 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
922 return ctx
->Extensions
.ARB_texture_cube_map
923 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
924 case GL_TEXTURE_RECTANGLE_NV
:
925 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
926 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
927 case GL_TEXTURE_1D_ARRAY_EXT
:
928 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
929 case GL_TEXTURE_2D_ARRAY_EXT
:
930 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
931 return (ctx
->Extensions
.MESA_texture_array
||
932 ctx
->Extensions
.EXT_texture_array
)
933 ? ctx
->Const
.MaxTextureLevels
: 0;
934 case GL_TEXTURE_BUFFER
:
935 case GL_TEXTURE_EXTERNAL_OES
:
938 return 0; /* bad target */
944 * Return number of dimensions per mipmap level for the given texture target.
947 _mesa_get_texture_dimensions(GLenum target
)
951 case GL_PROXY_TEXTURE_1D
:
954 case GL_TEXTURE_RECTANGLE
:
955 case GL_TEXTURE_CUBE_MAP
:
956 case GL_PROXY_TEXTURE_2D
:
957 case GL_PROXY_TEXTURE_RECTANGLE
:
958 case GL_PROXY_TEXTURE_CUBE_MAP
:
959 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
960 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
961 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
962 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
963 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
964 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
965 case GL_TEXTURE_1D_ARRAY
:
966 case GL_PROXY_TEXTURE_1D_ARRAY
:
967 case GL_TEXTURE_EXTERNAL_OES
:
970 case GL_PROXY_TEXTURE_3D
:
971 case GL_TEXTURE_2D_ARRAY
:
972 case GL_PROXY_TEXTURE_2D_ARRAY
:
974 case GL_TEXTURE_BUFFER
:
977 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
986 #if 000 /* not used anymore */
988 * glTexImage[123]D can accept a NULL image pointer. In this case we
989 * create a texture image with unspecified image contents per the OpenGL
993 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
995 const GLint components
= _mesa_components_in_format(format
);
996 const GLint numPixels
= width
* height
* depth
;
997 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1001 * Let's see if anyone finds this. If glTexImage2D() is called with
1002 * a NULL image pointer then load the texture image with something
1003 * interesting instead of leaving it indeterminate.
1006 static const char message
[8][32] = {
1007 " X X XXXXX XXX X ",
1008 " XX XX X X X X X ",
1010 " X X XXXX XXX XXXXX ",
1013 " X X XXXXX XXX X X ",
1017 GLubyte
*imgPtr
= data
;
1019 for (h
= 0; h
< depth
; h
++) {
1020 for (i
= 0; i
< height
; i
++) {
1021 GLint srcRow
= 7 - (i
% 8);
1022 for (j
= 0; j
< width
; j
++) {
1023 GLint srcCol
= j
% 32;
1024 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1025 for (k
= 0; k
< components
; k
++) {
1041 * Set the size and format-related fields of a gl_texture_image struct
1042 * to zero. This is used when a proxy texture test fails.
1045 clear_teximage_fields(struct gl_texture_image
*img
)
1048 img
->_BaseFormat
= 0;
1049 img
->InternalFormat
= 0;
1058 img
->HeightLog2
= 0;
1060 img
->TexFormat
= MESA_FORMAT_NONE
;
1065 * Initialize basic fields of the gl_texture_image struct.
1067 * \param ctx GL context.
1068 * \param img texture image structure to be initialized.
1069 * \param width image width.
1070 * \param height image height.
1071 * \param depth image depth.
1072 * \param border image border.
1073 * \param internalFormat internal format.
1074 * \param format the actual hardware format (one of MESA_FORMAT_*)
1076 * Fills in the fields of \p img with the given information.
1077 * Note: width, height and depth include the border.
1080 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1081 struct gl_texture_image
*img
,
1082 GLsizei width
, GLsizei height
, GLsizei depth
,
1083 GLint border
, GLenum internalFormat
,
1088 ASSERT(height
>= 0);
1091 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1092 ASSERT(img
->_BaseFormat
> 0);
1093 img
->InternalFormat
= internalFormat
;
1094 img
->Border
= border
;
1096 img
->Height
= height
;
1099 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1100 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1102 if (height
== 1) { /* 1-D texture */
1104 img
->HeightLog2
= 0;
1107 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1108 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1111 if (depth
== 1) { /* 2-D texture */
1116 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1117 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1120 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1122 img
->TexFormat
= format
;
1127 * Free and clear fields of the gl_texture_image struct.
1129 * \param ctx GL context.
1130 * \param texImage texture image structure to be cleared.
1132 * After the call, \p texImage will have no data associated with it. Its
1133 * fields are cleared so that its parent object will test incomplete.
1136 _mesa_clear_texture_image(struct gl_context
*ctx
,
1137 struct gl_texture_image
*texImage
)
1139 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1140 clear_teximage_fields(texImage
);
1145 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1146 * level, width, height and depth against the ctx->Const limits for textures.
1148 * A hardware driver might override this function if, for example, the
1149 * max 3D texture size is 512x512x64 (i.e. not a cube).
1151 * Note that width, height, depth == 0 is not an error. However, a
1152 * texture with zero width/height/depth will be considered "incomplete"
1153 * and texturing will effectively be disabled.
1155 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1156 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1157 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1158 * \param level as passed to glTexImage
1159 * \param internalFormat as passed to glTexImage
1160 * \param format as passed to glTexImage
1161 * \param type as passed to glTexImage
1162 * \param width as passed to glTexImage
1163 * \param height as passed to glTexImage
1164 * \param depth as passed to glTexImage
1165 * \param border as passed to glTexImage
1166 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1169 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1170 GLint internalFormat
, GLenum format
, GLenum type
,
1171 GLint width
, GLint height
, GLint depth
, GLint border
)
1175 (void) internalFormat
;
1180 case GL_PROXY_TEXTURE_1D
:
1181 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1182 if (width
< 2 * border
|| width
> maxSize
)
1184 if (level
>= ctx
->Const
.MaxTextureLevels
)
1186 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1187 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1192 case GL_PROXY_TEXTURE_2D
:
1193 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1194 if (width
< 2 * border
|| width
> maxSize
)
1196 if (height
< 2 * border
|| height
> maxSize
)
1198 if (level
>= ctx
->Const
.MaxTextureLevels
)
1200 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1201 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1203 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1208 case GL_PROXY_TEXTURE_3D
:
1209 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1210 if (width
< 2 * border
|| width
> maxSize
)
1212 if (height
< 2 * border
|| height
> maxSize
)
1214 if (depth
< 2 * border
|| depth
> maxSize
)
1216 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1218 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1219 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1221 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1223 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1228 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1229 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1230 if (width
< 0 || width
> maxSize
)
1232 if (height
< 0 || height
> maxSize
)
1238 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1239 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1240 if (width
< 2 * border
|| width
> maxSize
)
1242 if (height
< 2 * border
|| height
> maxSize
)
1244 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1246 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1247 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1249 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1254 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1255 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1256 if (width
< 2 * border
|| width
> maxSize
)
1258 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1260 if (level
>= ctx
->Const
.MaxTextureLevels
)
1262 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1263 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1268 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1269 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1270 if (width
< 2 * border
|| width
> maxSize
)
1272 if (height
< 2 * border
|| height
> maxSize
)
1274 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1276 if (level
>= ctx
->Const
.MaxTextureLevels
)
1278 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1279 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1281 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1287 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1294 * Check if the memory used by the texture would exceed the driver's limit.
1295 * This lets us support a max 3D texture size of 8K (for example) but
1296 * prevents allocating a full 8K x 8K x 8K texture.
1297 * XXX this could be rolled into the proxy texture size test (above) but
1298 * we don't have the actual texture internal format at that point.
1301 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1302 GLint width
, GLint height
, GLint depth
)
1304 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1305 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1306 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1311 * Return true if the format is only valid for glCompressedTexImage.
1314 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1317 case GL_ETC1_RGB8_OES
:
1326 * Helper function to determine whether a target and specific compression
1327 * format are supported.
1330 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1333 (void) intFormat
; /* not used yet */
1337 case GL_PROXY_TEXTURE_2D
:
1338 return GL_TRUE
; /* true for any compressed format so far */
1339 case GL_PROXY_TEXTURE_CUBE_MAP
:
1340 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1341 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1342 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1343 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1344 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1345 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1346 return ctx
->Extensions
.ARB_texture_cube_map
;
1347 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1348 case GL_TEXTURE_2D_ARRAY_EXT
:
1349 return (ctx
->Extensions
.MESA_texture_array
||
1350 ctx
->Extensions
.EXT_texture_array
);
1358 * Check if the given texture target value is legal for a
1359 * glTexImage1/2/3D call.
1362 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1368 case GL_PROXY_TEXTURE_1D
:
1376 case GL_PROXY_TEXTURE_2D
:
1378 case GL_PROXY_TEXTURE_CUBE_MAP
:
1379 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1380 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1381 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1382 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1383 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1384 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1385 return ctx
->Extensions
.ARB_texture_cube_map
;
1386 case GL_TEXTURE_RECTANGLE_NV
:
1387 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1388 return ctx
->Extensions
.NV_texture_rectangle
;
1389 case GL_TEXTURE_1D_ARRAY_EXT
:
1390 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1391 return (ctx
->Extensions
.MESA_texture_array
||
1392 ctx
->Extensions
.EXT_texture_array
);
1399 case GL_PROXY_TEXTURE_3D
:
1401 case GL_TEXTURE_2D_ARRAY_EXT
:
1402 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1403 return (ctx
->Extensions
.MESA_texture_array
||
1404 ctx
->Extensions
.EXT_texture_array
);
1409 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1416 * Check if the given texture target value is legal for a
1417 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1418 * The difference compared to legal_teximage_target() above is that
1419 * proxy targets are not supported.
1422 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1426 return target
== GL_TEXTURE_1D
;
1431 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1432 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1433 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1434 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1435 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1436 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1437 return ctx
->Extensions
.ARB_texture_cube_map
;
1438 case GL_TEXTURE_RECTANGLE_NV
:
1439 return ctx
->Extensions
.NV_texture_rectangle
;
1440 case GL_TEXTURE_1D_ARRAY_EXT
:
1441 return (ctx
->Extensions
.MESA_texture_array
||
1442 ctx
->Extensions
.EXT_texture_array
);
1450 case GL_TEXTURE_2D_ARRAY_EXT
:
1451 return (ctx
->Extensions
.MESA_texture_array
||
1452 ctx
->Extensions
.EXT_texture_array
);
1457 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1465 * Helper function to determine if a texture object is mutable (in terms
1466 * of GL_ARB_texture_storage).
1469 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1471 if (ctx
->Extensions
.ARB_texture_storage
) {
1472 struct gl_texture_object
*texObj
=
1473 _mesa_get_current_tex_object(ctx
, target
);
1474 return !texObj
->Immutable
;
1482 * Test the glTexImage[123]D() parameters for errors.
1484 * \param ctx GL context.
1485 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1486 * \param target texture target given by the user.
1487 * \param level image level given by the user.
1488 * \param internalFormat internal format given by the user.
1489 * \param format pixel data format given by the user.
1490 * \param type pixel data type given by the user.
1491 * \param width image width given by the user.
1492 * \param height image height given by the user.
1493 * \param depth image depth given by the user.
1494 * \param border image border given by the user.
1496 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1498 * Verifies each of the parameters against the constants specified in
1499 * __struct gl_contextRec::Const and the supported extensions, and according
1500 * to the OpenGL specification.
1503 texture_error_check( struct gl_context
*ctx
,
1504 GLuint dimensions
, GLenum target
,
1505 GLint level
, GLint internalFormat
,
1506 GLenum format
, GLenum type
,
1507 GLint width
, GLint height
,
1508 GLint depth
, GLint border
)
1510 const GLenum proxyTarget
= get_proxy_target(target
);
1511 const GLboolean isProxy
= target
== proxyTarget
;
1512 GLboolean sizeOK
= GL_TRUE
;
1513 GLboolean colorFormat
;
1515 /* Even though there are no color-index textures, we still have to support
1516 * uploading color-index data and remapping it to RGB via the
1517 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1519 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1521 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1522 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1524 _mesa_error(ctx
, GL_INVALID_VALUE
,
1525 "glTexImage%dD(level=%d)", dimensions
, level
);
1531 if (border
< 0 || border
> 1 ||
1532 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1533 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1535 _mesa_error(ctx
, GL_INVALID_VALUE
,
1536 "glTexImage%dD(border=%d)", dimensions
, border
);
1541 if (width
< 0 || height
< 0 || depth
< 0) {
1543 _mesa_error(ctx
, GL_INVALID_VALUE
,
1544 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1549 /* Do this simple check before calling the TestProxyTexImage() function */
1550 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1551 sizeOK
= (width
== height
);
1555 * Use the proxy texture driver hook to see if the size/level/etc are
1558 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1559 internalFormat
, format
,
1560 type
, width
, height
,
1564 _mesa_error(ctx
, GL_INVALID_VALUE
,
1565 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1566 dimensions
, level
, width
, height
, depth
);
1571 /* Check internalFormat */
1572 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1574 _mesa_error(ctx
, GL_INVALID_VALUE
,
1575 "glTexImage%dD(internalFormat=%s)",
1576 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1581 /* Check incoming image format and type */
1582 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1583 /* Normally, GL_INVALID_OPERATION is generated by a format/type
1584 * mismatch (see the 1.2 spec page 94, sec 3.6.4.). But with the
1585 * GL_EXT_texture_integer extension, some combinations should generate
1586 * GL_INVALID_ENUM instead (grr!).
1589 GLenum error
= _mesa_is_integer_format(format
)
1590 ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
1591 _mesa_error(ctx
, error
,
1592 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1593 dimensions
, format
, type
);
1598 /* make sure internal format and format basically agree */
1599 colorFormat
= _mesa_is_color_format(format
);
1600 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1601 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1602 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1603 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1604 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1606 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1607 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1608 dimensions
, internalFormat
, format
);
1612 /* additional checks for ycbcr textures */
1613 if (internalFormat
== GL_YCBCR_MESA
) {
1614 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1615 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1616 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1618 _mesa_snprintf(message
, sizeof(message
),
1619 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1620 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1621 return GL_TRUE
; /* error */
1623 if (target
!= GL_TEXTURE_2D
&&
1624 target
!= GL_PROXY_TEXTURE_2D
&&
1625 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1626 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1628 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1634 _mesa_snprintf(message
, sizeof(message
),
1635 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1636 dimensions
, border
);
1637 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1643 /* additional checks for depth textures */
1644 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1645 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1646 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1647 if (target
!= GL_TEXTURE_1D
&&
1648 target
!= GL_PROXY_TEXTURE_1D
&&
1649 target
!= GL_TEXTURE_2D
&&
1650 target
!= GL_PROXY_TEXTURE_2D
&&
1651 target
!= GL_TEXTURE_1D_ARRAY
&&
1652 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1653 target
!= GL_TEXTURE_2D_ARRAY
&&
1654 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1655 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1656 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1657 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1658 (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_gpu_shader4
))) {
1660 _mesa_error(ctx
, GL_INVALID_ENUM
,
1661 "glTexImage(target/internalFormat)");
1666 /* additional checks for compressed textures */
1667 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1668 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1670 _mesa_error(ctx
, GL_INVALID_ENUM
,
1671 "glTexImage%dD(target)", dimensions
);
1674 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1675 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1676 "glTexImage%dD(no compression for format)", dimensions
);
1681 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1682 "glTexImage%dD(border!=0)", dimensions
);
1688 /* additional checks for integer textures */
1689 if ((ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_texture_integer
) &&
1690 (_mesa_is_integer_format(format
) !=
1691 _mesa_is_integer_format(internalFormat
))) {
1693 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1694 "glTexImage%dD(integer/non-integer format mismatch)",
1700 if (!mutable_tex_object(ctx
, target
)) {
1701 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1702 "glTexImage%dD(immutable texture)", dimensions
);
1706 /* if we get here, the parameters are OK */
1712 * Test glTexSubImage[123]D() parameters for errors.
1714 * \param ctx GL context.
1715 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1716 * \param target texture target given by the user.
1717 * \param level image level given by the user.
1718 * \param xoffset sub-image x offset given by the user.
1719 * \param yoffset sub-image y offset given by the user.
1720 * \param zoffset sub-image z offset given by the user.
1721 * \param format pixel data format given by the user.
1722 * \param type pixel data type given by the user.
1723 * \param width image width given by the user.
1724 * \param height image height given by the user.
1725 * \param depth image depth given by the user.
1727 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1729 * Verifies each of the parameters against the constants specified in
1730 * __struct gl_contextRec::Const and the supported extensions, and according
1731 * to the OpenGL specification.
1734 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1735 GLenum target
, GLint level
,
1736 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1737 GLint width
, GLint height
, GLint depth
,
1738 GLenum format
, GLenum type
)
1740 /* Basic level check */
1741 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1742 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1746 /* Check for negative sizes */
1748 _mesa_error(ctx
, GL_INVALID_VALUE
,
1749 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1752 if (height
< 0 && dimensions
> 1) {
1753 _mesa_error(ctx
, GL_INVALID_VALUE
,
1754 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1757 if (depth
< 0 && dimensions
> 2) {
1758 _mesa_error(ctx
, GL_INVALID_VALUE
,
1759 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1763 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
)) {
1764 /* As with the glTexImage2D check above, the error code here
1765 * depends on texture integer.
1767 GLenum error
= _mesa_is_integer_format(format
)
1768 ? GL_INVALID_OPERATION
: GL_INVALID_ENUM
;
1769 _mesa_error(ctx
, error
,
1770 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1771 dimensions
, format
, type
);
1780 * Do second part of glTexSubImage which depends on the destination texture.
1781 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1784 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1785 GLenum target
, GLint level
,
1786 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1787 GLint width
, GLint height
, GLint depth
,
1788 GLenum format
, GLenum type
,
1789 const struct gl_texture_image
*destTex
)
1792 /* undefined image level */
1793 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1797 if (xoffset
< -((GLint
)destTex
->Border
)) {
1798 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1802 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1803 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1807 if (dimensions
> 1) {
1808 if (yoffset
< -((GLint
)destTex
->Border
)) {
1809 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1813 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1814 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1819 if (dimensions
> 2) {
1820 if (zoffset
< -((GLint
)destTex
->Border
)) {
1821 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1824 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1825 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1830 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1833 if (compressedteximage_only_format(ctx
, destTex
->InternalFormat
)) {
1834 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1835 "glTexSubImage%dD(no compression for format)", dimensions
);
1839 /* do tests which depend on compression block size */
1840 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1842 /* offset must be multiple of block size */
1843 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1844 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1845 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1846 dimensions
, xoffset
, yoffset
);
1849 /* size must be multiple of bw by bh or equal to whole texture size */
1850 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1851 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1852 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1855 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1856 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1857 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1867 * Test glCopyTexImage[12]D() parameters for errors.
1869 * \param ctx GL context.
1870 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1871 * \param target texture target given by the user.
1872 * \param level image level given by the user.
1873 * \param internalFormat internal format given by the user.
1874 * \param width image width given by the user.
1875 * \param height image height given by the user.
1876 * \param border texture border.
1878 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1880 * Verifies each of the parameters against the constants specified in
1881 * __struct gl_contextRec::Const and the supported extensions, and according
1882 * to the OpenGL specification.
1885 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1886 GLenum target
, GLint level
, GLint internalFormat
,
1887 GLint width
, GLint height
, GLint border
)
1889 const GLenum proxyTarget
= get_proxy_target(target
);
1890 const GLenum type
= GL_FLOAT
;
1895 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1896 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1897 dimensions
, _mesa_lookup_enum_by_nr(target
));
1901 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1902 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1903 _mesa_error(ctx
, GL_INVALID_VALUE
,
1904 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1908 /* Check that the source buffer is complete */
1909 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
1910 if (ctx
->ReadBuffer
->_Status
== 0) {
1911 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1913 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1914 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1915 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1919 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
1920 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION
,
1921 "glCopyTexImage%dD(multisample FBO)",
1928 if (border
< 0 || border
> 1 ||
1929 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1930 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1934 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1935 if (baseFormat
< 0) {
1936 _mesa_error(ctx
, GL_INVALID_VALUE
,
1937 "glCopyTexImage%dD(internalFormat)", dimensions
);
1941 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
1942 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1943 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1947 /* From the EXT_texture_integer spec:
1949 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
1950 * if the texture internalformat is an integer format and the read color
1951 * buffer is not an integer format, or if the internalformat is not an
1952 * integer format and the read color buffer is an integer format."
1954 if (_mesa_is_color_format(internalFormat
)) {
1955 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
1957 if (_mesa_is_integer_format(rb
->InternalFormat
) !=
1958 _mesa_is_integer_format(internalFormat
)) {
1959 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1960 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
1965 /* Do size, level checking */
1966 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1967 ? (width
== height
) : 1;
1969 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1970 internalFormat
, baseFormat
,
1971 type
, width
, height
,
1975 if (dimensions
== 1) {
1976 _mesa_error(ctx
, GL_INVALID_VALUE
,
1977 "glCopyTexImage1D(width=%d)", width
);
1980 ASSERT(dimensions
== 2);
1981 _mesa_error(ctx
, GL_INVALID_VALUE
,
1982 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
1987 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1988 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1989 _mesa_error(ctx
, GL_INVALID_ENUM
,
1990 "glCopyTexImage%dD(target)", dimensions
);
1993 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1994 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1995 "glCopyTexImage%dD(no compression for format)", dimensions
);
1999 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2000 "glCopyTexImage%dD(border!=0)", dimensions
);
2005 if (!mutable_tex_object(ctx
, target
)) {
2006 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2007 "glCopyTexImage%dD(immutable texture)", dimensions
);
2011 /* if we get here, the parameters are OK */
2017 * Test glCopyTexSubImage[12]D() parameters for errors.
2018 * Note that this is the first part of error checking.
2019 * See also copytexsubimage_error_check2() below for the second part.
2021 * \param ctx GL context.
2022 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2023 * \param target texture target given by the user.
2024 * \param level image level given by the user.
2026 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2029 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2030 GLenum target
, GLint level
)
2032 /* Check that the source buffer is complete */
2033 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2034 if (ctx
->ReadBuffer
->_Status
== 0) {
2035 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2037 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2038 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2039 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2043 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2044 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION
,
2045 "glCopyTexSubImage%dD(multisample FBO)",
2051 /* check target (proxies not allowed) */
2052 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2053 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2054 dimensions
, _mesa_lookup_enum_by_nr(target
));
2059 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2060 _mesa_error(ctx
, GL_INVALID_VALUE
,
2061 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2070 * Second part of error checking for glCopyTexSubImage[12]D().
2071 * \param xoffset sub-image x offset given by the user.
2072 * \param yoffset sub-image y offset given by the user.
2073 * \param zoffset sub-image z offset given by the user.
2074 * \param width image width given by the user.
2075 * \param height image height given by the user.
2078 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2079 GLenum target
, GLint level
,
2080 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2081 GLsizei width
, GLsizei height
,
2082 const struct gl_texture_image
*teximage
)
2084 /* check that dest tex image exists */
2086 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2087 "glCopyTexSubImage%dD(undefined texture level: %d)",
2094 _mesa_error(ctx
, GL_INVALID_VALUE
,
2095 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2098 if (dimensions
> 1 && height
< 0) {
2099 _mesa_error(ctx
, GL_INVALID_VALUE
,
2100 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2104 /* check x/y offsets */
2105 if (xoffset
< -((GLint
)teximage
->Border
)) {
2106 _mesa_error(ctx
, GL_INVALID_VALUE
,
2107 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2110 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2111 _mesa_error(ctx
, GL_INVALID_VALUE
,
2112 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2115 if (dimensions
> 1) {
2116 if (yoffset
< -((GLint
)teximage
->Border
)) {
2117 _mesa_error(ctx
, GL_INVALID_VALUE
,
2118 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2121 /* NOTE: we're adding the border here, not subtracting! */
2122 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2123 _mesa_error(ctx
, GL_INVALID_VALUE
,
2124 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2129 /* check z offset */
2130 if (dimensions
> 2) {
2131 if (zoffset
< -((GLint
)teximage
->Border
)) {
2132 _mesa_error(ctx
, GL_INVALID_VALUE
,
2133 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2136 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2137 _mesa_error(ctx
, GL_INVALID_VALUE
,
2138 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2143 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2144 if (compressedteximage_only_format(ctx
, teximage
->InternalFormat
)) {
2145 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2146 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2149 /* offset must be multiple of 4 */
2150 if ((xoffset
& 3) || (yoffset
& 3)) {
2151 _mesa_error(ctx
, GL_INVALID_VALUE
,
2152 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2155 /* size must be multiple of 4 */
2156 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2157 _mesa_error(ctx
, GL_INVALID_VALUE
,
2158 "glCopyTexSubImage%dD(width)", dimensions
);
2161 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2162 _mesa_error(ctx
, GL_INVALID_VALUE
,
2163 "glCopyTexSubImage%dD(height)", dimensions
);
2168 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2169 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2173 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2174 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2175 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2176 dimensions
, teximage
->_BaseFormat
);
2180 /* From the EXT_texture_integer spec:
2182 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2183 * if the texture internalformat is an integer format and the read color
2184 * buffer is not an integer format, or if the internalformat is not an
2185 * integer format and the read color buffer is an integer format."
2187 if (_mesa_is_color_format(teximage
->InternalFormat
)) {
2188 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2190 if (_mesa_is_format_integer_color(rb
->Format
) !=
2191 _mesa_is_format_integer_color(teximage
->TexFormat
)) {
2192 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2193 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2198 /* if we get here, the parameters are OK */
2203 /** Callback info for walking over FBO hash table */
2206 struct gl_context
*ctx
;
2207 struct gl_texture_object
*texObj
;
2213 * Check render to texture callback. Called from _mesa_HashWalk().
2216 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2218 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2219 const struct cb_info
*info
= (struct cb_info
*) userData
;
2220 struct gl_context
*ctx
= info
->ctx
;
2221 const struct gl_texture_object
*texObj
= info
->texObj
;
2222 const GLuint level
= info
->level
, face
= info
->face
;
2224 /* If this is a user-created FBO */
2225 if (_mesa_is_user_fbo(fb
)) {
2227 /* check if any of the FBO's attachments point to 'texObj' */
2228 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2229 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2230 if (att
->Type
== GL_TEXTURE
&&
2231 att
->Texture
== texObj
&&
2232 att
->TextureLevel
== level
&&
2233 att
->CubeMapFace
== face
) {
2234 ASSERT(_mesa_get_attachment_teximage(att
));
2235 /* Tell driver about the new renderbuffer texture */
2236 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2237 /* Mark fb status as indeterminate to force re-validation */
2246 * When a texture image is specified we have to check if it's bound to
2247 * any framebuffer objects (render to texture) in order to detect changes
2248 * in size or format since that effects FBO completeness.
2249 * Any FBOs rendering into the texture must be re-validated.
2252 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2253 struct gl_texture_object
*texObj
,
2254 GLuint face
, GLuint level
)
2256 /* Only check this texture if it's been marked as RenderToTexture */
2257 if (texObj
->_RenderToTexture
) {
2258 struct cb_info info
;
2260 info
.texObj
= texObj
;
2263 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2269 * If the texture object's GenerateMipmap flag is set and we've
2270 * changed the texture base level image, regenerate the rest of the
2271 * mipmap levels now.
2274 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2275 struct gl_texture_object
*texObj
, GLint level
)
2277 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2278 if (texObj
->GenerateMipmap
&&
2279 level
== texObj
->BaseLevel
&&
2280 level
< texObj
->MaxLevel
) {
2281 ASSERT(ctx
->Driver
.GenerateMipmap
);
2282 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2287 /** Debug helper: override the user-requested internal format */
2289 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2292 if (internalFormat
== GL_RGBA16F_ARB
||
2293 internalFormat
== GL_RGBA32F_ARB
) {
2294 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2297 else if (internalFormat
== GL_RGB16F_ARB
||
2298 internalFormat
== GL_RGB32F_ARB
) {
2299 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2302 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2303 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2304 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2305 return GL_LUMINANCE_ALPHA
;
2307 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2308 internalFormat
== GL_LUMINANCE32F_ARB
) {
2309 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2310 return GL_LUMINANCE
;
2312 else if (internalFormat
== GL_ALPHA16F_ARB
||
2313 internalFormat
== GL_ALPHA32F_ARB
) {
2314 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2318 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2319 internalFormat = GL_RGBA;
2323 return internalFormat
;
2326 return internalFormat
;
2332 * Choose the actual hardware format for a texture image.
2333 * Try to use the same format as the previous image level when possible.
2334 * Otherwise, ask the driver for the best format.
2335 * It's important to try to choose a consistant format for all levels
2336 * for efficient texture memory layout/allocation. In particular, this
2337 * comes up during automatic mipmap generation.
2340 _mesa_choose_texture_format(struct gl_context
*ctx
,
2341 struct gl_texture_object
*texObj
,
2342 GLenum target
, GLint level
,
2343 GLenum internalFormat
, GLenum format
, GLenum type
)
2347 /* see if we've already chosen a format for the previous level */
2349 struct gl_texture_image
*prevImage
=
2350 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2351 /* See if the prev level is defined and has an internal format which
2352 * matches the new internal format.
2355 prevImage
->Width
> 0 &&
2356 prevImage
->InternalFormat
== internalFormat
) {
2357 /* use the same format */
2358 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2359 return prevImage
->TexFormat
;
2363 /* choose format from scratch */
2364 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2365 ASSERT(f
!= MESA_FORMAT_NONE
);
2370 * Adjust pixel unpack params and image dimensions to strip off the
2373 * Gallium and intel don't support texture borders. They've seldem been used
2374 * and seldom been implemented correctly anyway.
2376 * \param unpackNew returns the new pixel unpack parameters
2379 strip_texture_border(GLint
*border
,
2380 GLint
*width
, GLint
*height
, GLint
*depth
,
2381 const struct gl_pixelstore_attrib
*unpack
,
2382 struct gl_pixelstore_attrib
*unpackNew
)
2384 assert(*border
> 0); /* sanity check */
2386 *unpackNew
= *unpack
;
2388 if (unpackNew
->RowLength
== 0)
2389 unpackNew
->RowLength
= *width
;
2391 if (depth
&& unpackNew
->ImageHeight
== 0)
2392 unpackNew
->ImageHeight
= *height
;
2394 unpackNew
->SkipPixels
+= *border
;
2396 unpackNew
->SkipRows
+= *border
;
2398 unpackNew
->SkipImages
+= *border
;
2400 assert(*width
>= 3);
2401 *width
= *width
- 2 * *border
;
2402 if (height
&& *height
>= 3)
2403 *height
= *height
- 2 * *border
;
2404 if (depth
&& *depth
>= 3)
2405 *depth
= *depth
- 2 * *border
;
2410 * Common code to implement all the glTexImage1D/2D/3D functions.
2413 teximage(struct gl_context
*ctx
, GLuint dims
,
2414 GLenum target
, GLint level
, GLint internalFormat
,
2415 GLsizei width
, GLsizei height
, GLsizei depth
,
2416 GLint border
, GLenum format
, GLenum type
,
2417 const GLvoid
*pixels
)
2420 struct gl_pixelstore_attrib unpack_no_border
;
2421 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2423 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2425 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2426 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2428 _mesa_lookup_enum_by_nr(target
), level
,
2429 _mesa_lookup_enum_by_nr(internalFormat
),
2430 width
, height
, depth
, border
,
2431 _mesa_lookup_enum_by_nr(format
),
2432 _mesa_lookup_enum_by_nr(type
), pixels
);
2434 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2436 /* target error checking */
2437 if (!legal_teximage_target(ctx
, dims
, target
)) {
2438 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2439 dims
, _mesa_lookup_enum_by_nr(target
));
2443 /* general error checking */
2444 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2445 format
, type
, width
, height
, depth
, border
);
2447 if (_mesa_is_proxy_texture(target
)) {
2448 /* Proxy texture: just clear or set state depending on error checking */
2449 struct gl_texture_image
*texImage
=
2450 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2453 /* when error, clear all proxy texture image parameters */
2455 clear_teximage_fields(texImage
);
2458 /* no error, set the tex image parameters */
2459 struct gl_texture_object
*texObj
=
2460 _mesa_get_current_tex_object(ctx
, target
);
2461 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2466 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2467 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
2468 depth
, border
, internalFormat
,
2471 else if (texImage
) {
2472 clear_teximage_fields(texImage
);
2477 /* non-proxy target */
2478 const GLuint face
= _mesa_tex_target_to_face(target
);
2479 struct gl_texture_object
*texObj
;
2480 struct gl_texture_image
*texImage
;
2483 return; /* error was recorded */
2486 /* Allow a hardware driver to just strip out the border, to provide
2487 * reliable but slightly incorrect hardware rendering instead of
2488 * rarely-tested software fallback rendering.
2490 if (border
&& ctx
->Const
.StripTextureBorder
) {
2491 strip_texture_border(&border
, &width
, &height
, &depth
, unpack
,
2493 unpack
= &unpack_no_border
;
2496 if (ctx
->NewState
& _NEW_PIXEL
)
2497 _mesa_update_state(ctx
);
2499 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2501 _mesa_lock_texture(ctx
, texObj
);
2503 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2506 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2509 gl_format texFormat
;
2511 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2513 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2514 internalFormat
, format
,
2517 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2518 _mesa_init_teximage_fields(ctx
, texImage
,
2519 width
, height
, depth
,
2520 border
, internalFormat
, texFormat
);
2522 /* Give the texture to the driver. <pixels> may be null. */
2523 ASSERT(ctx
->Driver
.TexImage3D
);
2526 ctx
->Driver
.TexImage1D(ctx
, texImage
, internalFormat
,
2527 width
, border
, format
,
2528 type
, pixels
, unpack
);
2531 ctx
->Driver
.TexImage2D(ctx
, texImage
, internalFormat
,
2532 width
, height
, border
, format
,
2533 type
, pixels
, unpack
);
2536 ctx
->Driver
.TexImage3D(ctx
, texImage
, internalFormat
,
2537 width
, height
, depth
, border
, format
,
2538 type
, pixels
, unpack
);
2541 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2544 check_gen_mipmap(ctx
, target
, texObj
, level
);
2546 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2549 texObj
->_Complete
= GL_FALSE
;
2550 ctx
->NewState
|= _NEW_TEXTURE
;
2553 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2557 _mesa_unlock_texture(ctx
, texObj
);
2563 * Called from the API. Note that width includes the border.
2566 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2567 GLsizei width
, GLint border
, GLenum format
,
2568 GLenum type
, const GLvoid
*pixels
)
2570 GET_CURRENT_CONTEXT(ctx
);
2571 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2572 border
, format
, type
, pixels
);
2577 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2578 GLsizei width
, GLsizei height
, GLint border
,
2579 GLenum format
, GLenum type
,
2580 const GLvoid
*pixels
)
2582 GET_CURRENT_CONTEXT(ctx
);
2583 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2584 border
, format
, type
, pixels
);
2589 * Called by the API or display list executor.
2590 * Note that width and height include the border.
2593 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2594 GLsizei width
, GLsizei height
, GLsizei depth
,
2595 GLint border
, GLenum format
, GLenum type
,
2596 const GLvoid
*pixels
)
2598 GET_CURRENT_CONTEXT(ctx
);
2599 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2600 border
, format
, type
, pixels
);
2605 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2606 GLsizei width
, GLsizei height
, GLsizei depth
,
2607 GLint border
, GLenum format
, GLenum type
,
2608 const GLvoid
*pixels
)
2610 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2611 depth
, border
, format
, type
, pixels
);
2615 #if FEATURE_OES_EGL_image
2617 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2619 struct gl_texture_object
*texObj
;
2620 struct gl_texture_image
*texImage
;
2621 GET_CURRENT_CONTEXT(ctx
);
2622 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2624 if ((target
== GL_TEXTURE_2D
&&
2625 !ctx
->Extensions
.OES_EGL_image
) ||
2626 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2627 !ctx
->Extensions
.OES_EGL_image_external
)) {
2628 _mesa_error(ctx
, GL_INVALID_ENUM
,
2629 "glEGLImageTargetTexture2D(target=%d)", target
);
2633 if (ctx
->NewState
& _NEW_PIXEL
)
2634 _mesa_update_state(ctx
);
2636 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2637 _mesa_lock_texture(ctx
, texObj
);
2639 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2641 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2643 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2645 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2646 texObj
, texImage
, image
);
2649 texObj
->_Complete
= GL_FALSE
;
2650 ctx
->NewState
|= _NEW_TEXTURE
;
2652 _mesa_unlock_texture(ctx
, texObj
);
2660 * Implement all the glTexSubImage1/2/3D() functions.
2663 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2664 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2665 GLsizei width
, GLsizei height
, GLsizei depth
,
2666 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2668 struct gl_texture_object
*texObj
;
2669 struct gl_texture_image
*texImage
;
2671 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2673 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2674 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2676 _mesa_lookup_enum_by_nr(target
), level
,
2677 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2678 _mesa_lookup_enum_by_nr(format
),
2679 _mesa_lookup_enum_by_nr(type
), pixels
);
2681 /* check target (proxies not allowed) */
2682 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2683 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2684 dims
, _mesa_lookup_enum_by_nr(target
));
2688 if (ctx
->NewState
& _NEW_PIXEL
)
2689 _mesa_update_state(ctx
);
2691 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2692 width
, height
, depth
, format
, type
)) {
2693 return; /* error was detected */
2696 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2698 _mesa_lock_texture(ctx
, texObj
);
2700 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2702 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2703 xoffset
, yoffset
, zoffset
,
2704 width
, height
, depth
,
2705 format
, type
, texImage
)) {
2706 /* error was recorded */
2708 else if (width
> 0 && height
> 0 && depth
> 0) {
2709 /* If we have a border, offset=-1 is legal. Bias by border width. */
2712 zoffset
+= texImage
->Border
;
2715 yoffset
+= texImage
->Border
;
2718 xoffset
+= texImage
->Border
;
2723 ctx
->Driver
.TexSubImage1D(ctx
, texImage
,
2725 format
, type
, pixels
, &ctx
->Unpack
);
2728 ctx
->Driver
.TexSubImage2D(ctx
, texImage
,
2729 xoffset
, yoffset
, width
, height
,
2730 format
, type
, pixels
, &ctx
->Unpack
);
2733 ctx
->Driver
.TexSubImage3D(ctx
, texImage
,
2734 xoffset
, yoffset
, zoffset
,
2735 width
, height
, depth
,
2736 format
, type
, pixels
, &ctx
->Unpack
);
2739 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2742 check_gen_mipmap(ctx
, target
, texObj
, level
);
2744 ctx
->NewState
|= _NEW_TEXTURE
;
2747 _mesa_unlock_texture(ctx
, texObj
);
2752 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2753 GLint xoffset
, GLsizei width
,
2754 GLenum format
, GLenum type
,
2755 const GLvoid
*pixels
)
2757 GET_CURRENT_CONTEXT(ctx
);
2758 texsubimage(ctx
, 1, target
, level
,
2761 format
, type
, pixels
);
2766 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2767 GLint xoffset
, GLint yoffset
,
2768 GLsizei width
, GLsizei height
,
2769 GLenum format
, GLenum type
,
2770 const GLvoid
*pixels
)
2772 GET_CURRENT_CONTEXT(ctx
);
2773 texsubimage(ctx
, 2, target
, level
,
2774 xoffset
, yoffset
, 0,
2776 format
, type
, pixels
);
2782 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2783 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2784 GLsizei width
, GLsizei height
, GLsizei depth
,
2785 GLenum format
, GLenum type
,
2786 const GLvoid
*pixels
)
2788 GET_CURRENT_CONTEXT(ctx
);
2789 texsubimage(ctx
, 3, target
, level
,
2790 xoffset
, yoffset
, zoffset
,
2791 width
, height
, depth
,
2792 format
, type
, pixels
);
2798 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
2799 * from. This depends on whether the texture contains color or depth values.
2801 static struct gl_renderbuffer
*
2802 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
2804 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
2805 /* reading from depth/stencil buffer */
2806 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
2809 /* copying from color buffer */
2810 return ctx
->ReadBuffer
->_ColorReadBuffer
;
2817 * Implement the glCopyTexImage1/2D() functions.
2820 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2821 GLenum target
, GLint level
, GLenum internalFormat
,
2822 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2824 struct gl_texture_object
*texObj
;
2825 struct gl_texture_image
*texImage
;
2826 const GLuint face
= _mesa_tex_target_to_face(target
);
2828 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2830 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2831 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2833 _mesa_lookup_enum_by_nr(target
), level
,
2834 _mesa_lookup_enum_by_nr(internalFormat
),
2835 x
, y
, width
, height
, border
);
2837 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2838 _mesa_update_state(ctx
);
2840 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2841 width
, height
, border
))
2844 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2846 if (border
&& ctx
->Const
.StripTextureBorder
) {
2848 width
-= border
* 2;
2851 height
-= border
* 2;
2856 _mesa_lock_texture(ctx
, texObj
);
2858 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2861 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2864 /* choose actual hw format */
2865 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2870 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2871 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2873 /* Free old texture image */
2874 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2876 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
2877 border
, internalFormat
, texFormat
);
2879 /* Allocate texture memory (no pixel data yet) */
2881 ctx
->Driver
.TexImage1D(ctx
, texImage
, internalFormat
,
2882 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2886 ctx
->Driver
.TexImage2D(ctx
, texImage
, internalFormat
,
2887 width
, height
, border
, GL_NONE
, GL_NONE
,
2888 NULL
, &ctx
->Unpack
);
2891 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2893 struct gl_renderbuffer
*srcRb
=
2894 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
2897 ctx
->Driver
.CopyTexSubImage1D(ctx
, texImage
, dstX
,
2898 srcRb
, srcX
, srcY
, width
);
2901 ctx
->Driver
.CopyTexSubImage2D(ctx
, texImage
, dstX
, dstY
,
2902 srcRb
, srcX
, srcY
, width
, height
);
2905 check_gen_mipmap(ctx
, target
, texObj
, level
);
2907 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2910 texObj
->_Complete
= GL_FALSE
;
2911 ctx
->NewState
|= _NEW_TEXTURE
;
2914 /* probably too large of image */
2915 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2919 _mesa_unlock_texture(ctx
, texObj
);
2925 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2926 GLenum internalFormat
,
2928 GLsizei width
, GLint border
)
2930 GET_CURRENT_CONTEXT(ctx
);
2931 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2937 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2938 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2941 GET_CURRENT_CONTEXT(ctx
);
2942 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2943 x
, y
, width
, height
, border
);
2949 * Implementation for glCopyTexSubImage1/2/3D() functions.
2952 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2953 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2954 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2956 struct gl_texture_object
*texObj
;
2957 struct gl_texture_image
*texImage
;
2959 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2961 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2962 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2964 _mesa_lookup_enum_by_nr(target
),
2965 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2967 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2968 _mesa_update_state(ctx
);
2970 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2973 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2975 _mesa_lock_texture(ctx
, texObj
);
2977 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2979 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2980 zoffset
, width
, height
, texImage
)) {
2981 /* error was recored */
2984 /* If we have a border, offset=-1 is legal. Bias by border width. */
2987 zoffset
+= texImage
->Border
;
2990 yoffset
+= texImage
->Border
;
2993 xoffset
+= texImage
->Border
;
2996 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
2998 struct gl_renderbuffer
*srcRb
=
2999 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3003 ctx
->Driver
.CopyTexSubImage1D(ctx
, texImage
, xoffset
,
3004 srcRb
, x
, y
, width
);
3007 ctx
->Driver
.CopyTexSubImage2D(ctx
, texImage
, xoffset
, yoffset
,
3008 srcRb
, x
, y
, width
, height
);
3011 ctx
->Driver
.CopyTexSubImage3D(ctx
, texImage
,
3012 xoffset
, yoffset
, zoffset
,
3013 srcRb
, x
, y
, width
, height
);
3016 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
3019 check_gen_mipmap(ctx
, target
, texObj
, level
);
3021 ctx
->NewState
|= _NEW_TEXTURE
;
3025 _mesa_unlock_texture(ctx
, texObj
);
3030 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3031 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3033 GET_CURRENT_CONTEXT(ctx
);
3034 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3040 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3041 GLint xoffset
, GLint yoffset
,
3042 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3044 GET_CURRENT_CONTEXT(ctx
);
3045 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3052 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3053 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3054 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3056 GET_CURRENT_CONTEXT(ctx
);
3057 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3058 x
, y
, width
, height
);
3064 /**********************************************************************/
3065 /****** Compressed Textures ******/
3066 /**********************************************************************/
3070 * Return expected size of a compressed texture.
3073 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3076 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3077 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3082 * Return compressed texture block size, in pixels.
3085 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3087 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3088 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3093 * Error checking for glCompressedTexImage[123]D().
3094 * \param reason returns reason for error, if any
3095 * \return error code or GL_NO_ERROR.
3098 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3099 GLenum target
, GLint level
,
3100 GLenum internalFormat
, GLsizei width
,
3101 GLsizei height
, GLsizei depth
, GLint border
,
3102 GLsizei imageSize
, char **reason
)
3104 const GLenum proxyTarget
= get_proxy_target(target
);
3105 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3107 GLenum choose_format
;
3109 GLenum proxy_format
;
3111 *reason
= ""; /* no error */
3113 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3115 return GL_INVALID_ENUM
;
3118 /* This will detect any invalid internalFormat value */
3119 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3120 *reason
= "internalFormat";
3121 return GL_INVALID_ENUM
;
3124 switch (internalFormat
) {
3126 case GL_PALETTE4_RGB8_OES
:
3127 case GL_PALETTE4_RGBA8_OES
:
3128 case GL_PALETTE4_R5_G6_B5_OES
:
3129 case GL_PALETTE4_RGBA4_OES
:
3130 case GL_PALETTE4_RGB5_A1_OES
:
3131 case GL_PALETTE8_RGB8_OES
:
3132 case GL_PALETTE8_RGBA8_OES
:
3133 case GL_PALETTE8_R5_G6_B5_OES
:
3134 case GL_PALETTE8_RGBA4_OES
:
3135 case GL_PALETTE8_RGB5_A1_OES
:
3136 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3138 proxy_format
= choose_format
;
3141 if (level
> 0 || level
< -maxLevels
) {
3143 return GL_INVALID_VALUE
;
3146 if (dimensions
!= 2) {
3147 *reason
= "compressed paletted textures must be 2D";
3148 return GL_INVALID_OPERATION
;
3151 /* Figure out the expected texture size (in bytes). This will be
3152 * checked against the actual size later.
3154 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3157 /* This is for the benefit of the TestProxyTexImage below. It expects
3158 * level to be non-negative. OES_compressed_paletted_texture uses a
3159 * weird mechanism where the level specified to glCompressedTexImage2D
3160 * is -(n-1) number of levels in the texture, and the data specifies the
3161 * complete mipmap stack. This is done to ensure the palette is the
3162 * same for all levels.
3169 choose_format
= GL_NONE
;
3170 choose_type
= GL_NONE
;
3171 proxy_format
= internalFormat
;
3174 if (level
< 0 || level
>= maxLevels
) {
3176 return GL_INVALID_VALUE
;
3179 /* Figure out the expected texture size (in bytes). This will be
3180 * checked against the actual size later.
3182 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3186 /* This should really never fail */
3187 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3188 *reason
= "internalFormat";
3189 return GL_INVALID_ENUM
;
3192 /* No compressed formats support borders at this time */
3194 *reason
= "border != 0";
3195 return GL_INVALID_VALUE
;
3198 /* For cube map, width must equal height */
3199 if (_mesa_is_cube_face(target
) && width
!= height
) {
3200 *reason
= "width != height";
3201 return GL_INVALID_VALUE
;
3204 /* check image size against compression block size */
3206 gl_format texFormat
=
3207 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3208 choose_format
, choose_type
);
3211 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3212 if ((width
> bw
&& width
% bw
> 0) ||
3213 (height
> bh
&& height
% bh
> 0)) {
3215 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3216 * generated [...] if any parameter combinations are not
3217 * supported by the specific compressed internal format.
3219 *reason
= "invalid width or height for compression format";
3220 return GL_INVALID_OPERATION
;
3224 /* check image sizes */
3225 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3226 proxy_format
, choose_format
,
3228 width
, height
, depth
, border
)) {
3229 /* See error comment above */
3230 *reason
= "invalid width, height or format";
3231 return GL_INVALID_OPERATION
;
3234 /* check image size in bytes */
3235 if (expectedSize
!= imageSize
) {
3236 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3237 * if <imageSize> is not consistent with the format, dimensions, and
3238 * contents of the specified image.
3240 *reason
= "imageSize inconsistant with width/height/format";
3241 return GL_INVALID_VALUE
;
3244 if (!mutable_tex_object(ctx
, target
)) {
3245 *reason
= "immutable texture";
3246 return GL_INVALID_OPERATION
;
3254 * Error checking for glCompressedTexSubImage[123]D().
3255 * \warning There are some bad assumptions here about the size of compressed
3256 * texture tiles (multiple of 4) used to test the validity of the
3257 * offset and size parameters.
3258 * \return error code or GL_NO_ERROR.
3261 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3262 GLenum target
, GLint level
,
3263 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3264 GLsizei width
, GLsizei height
, GLsizei depth
,
3265 GLenum format
, GLsizei imageSize
)
3267 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3271 if (dimensions
== 1) {
3272 /* 1D compressed textures not allowed */
3273 return GL_INVALID_ENUM
;
3275 else if (dimensions
== 2) {
3276 if (target
== GL_PROXY_TEXTURE_2D
) {
3277 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3279 else if (target
== GL_TEXTURE_2D
) {
3280 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3282 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3283 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3284 return GL_INVALID_ENUM
; /*target*/
3285 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3287 else if (_mesa_is_cube_face(target
)) {
3288 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3289 return GL_INVALID_ENUM
; /*target*/
3290 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3293 return GL_INVALID_ENUM
; /*target*/
3296 else if (dimensions
== 3) {
3297 /* 3D compressed textures not allowed */
3298 return GL_INVALID_ENUM
;
3301 maxTextureSize
= 1 << (maxLevels
- 1);
3303 /* this will catch any invalid compressed format token */
3304 if (!_mesa_is_compressed_format(ctx
, format
))
3305 return GL_INVALID_ENUM
;
3307 if (width
< 1 || width
> maxTextureSize
)
3308 return GL_INVALID_VALUE
;
3310 if ((height
< 1 || height
> maxTextureSize
)
3312 return GL_INVALID_VALUE
;
3314 if (level
< 0 || level
>= maxLevels
)
3315 return GL_INVALID_VALUE
;
3318 * do checks which depend on compression block size
3320 get_compressed_block_size(format
, &bw
, &bh
);
3322 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3323 return GL_INVALID_VALUE
;
3325 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3326 return GL_INVALID_VALUE
;
3328 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3329 return GL_INVALID_VALUE
;
3331 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3332 if (expectedSize
!= imageSize
)
3333 return GL_INVALID_VALUE
;
3340 * Do second part of glCompressedTexSubImage error checking.
3341 * \return GL_TRUE if error found, GL_FALSE otherwise.
3344 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3345 GLsizei width
, GLsizei height
,
3346 GLsizei depth
, GLenum format
,
3347 struct gl_texture_image
*texImage
)
3350 if ((GLint
) format
!= texImage
->InternalFormat
) {
3351 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3352 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3356 if (compressedteximage_only_format(ctx
, format
)) {
3357 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3358 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3363 if (((width
== 1 || width
== 2) &&
3364 width
!= (GLsizei
) texImage
->Width
) ||
3365 (width
> (GLsizei
) texImage
->Width
)) {
3366 _mesa_error(ctx
, GL_INVALID_VALUE
,
3367 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3372 if (((height
== 1 || height
== 2) &&
3373 height
!= (GLsizei
) texImage
->Height
) ||
3374 (height
> (GLsizei
) texImage
->Height
)) {
3375 _mesa_error(ctx
, GL_INVALID_VALUE
,
3376 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3382 if (((depth
== 1 || depth
== 2) &&
3383 depth
!= (GLsizei
) texImage
->Depth
) ||
3384 (depth
> (GLsizei
) texImage
->Depth
)) {
3385 _mesa_error(ctx
, GL_INVALID_VALUE
,
3386 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3396 * Implementation of the glCompressedTexImage1/2/3D() functions.
3399 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3400 GLenum target
, GLint level
,
3401 GLenum internalFormat
, GLsizei width
,
3402 GLsizei height
, GLsizei depth
, GLint border
,
3403 GLsizei imageSize
, const GLvoid
*data
)
3408 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3410 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3412 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3414 _mesa_lookup_enum_by_nr(target
), level
,
3415 _mesa_lookup_enum_by_nr(internalFormat
),
3416 width
, height
, depth
, border
, imageSize
, data
);
3419 if (!legal_teximage_target(ctx
, dims
, target
)) {
3420 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3421 dims
, _mesa_lookup_enum_by_nr(target
));
3425 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3426 internalFormat
, width
, height
, depth
,
3427 border
, imageSize
, &reason
);
3430 /* XXX this is kind of a hack */
3431 if (!error
&& dims
== 2) {
3432 switch (internalFormat
) {
3433 case GL_PALETTE4_RGB8_OES
:
3434 case GL_PALETTE4_RGBA8_OES
:
3435 case GL_PALETTE4_R5_G6_B5_OES
:
3436 case GL_PALETTE4_RGBA4_OES
:
3437 case GL_PALETTE4_RGB5_A1_OES
:
3438 case GL_PALETTE8_RGB8_OES
:
3439 case GL_PALETTE8_RGBA8_OES
:
3440 case GL_PALETTE8_R5_G6_B5_OES
:
3441 case GL_PALETTE8_RGBA4_OES
:
3442 case GL_PALETTE8_RGB5_A1_OES
:
3443 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3444 width
, height
, imageSize
, data
);
3450 if (_mesa_is_proxy_texture(target
)) {
3451 /* Proxy texture: just check for errors and update proxy state */
3452 struct gl_texture_image
*texImage
;
3455 struct gl_texture_object
*texObj
=
3456 _mesa_get_current_tex_object(ctx
, target
);
3457 gl_format texFormat
=
3458 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3459 internalFormat
, GL_NONE
, GL_NONE
);
3460 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3461 error
= GL_OUT_OF_MEMORY
;
3465 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3468 /* if error, clear all proxy texture image parameters */
3469 clear_teximage_fields(texImage
);
3472 /* no error: store the teximage parameters */
3473 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
3474 depth
, border
, internalFormat
,
3480 /* non-proxy target */
3481 struct gl_texture_object
*texObj
;
3482 struct gl_texture_image
*texImage
;
3485 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3489 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3491 _mesa_lock_texture(ctx
, texObj
);
3493 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3495 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3496 "glCompressedTexImage%uD", dims
);
3499 gl_format texFormat
;
3501 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3503 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3504 internalFormat
, GL_NONE
,
3507 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3508 _mesa_init_teximage_fields(ctx
, texImage
,
3509 width
, height
, depth
,
3510 border
, internalFormat
, texFormat
);
3514 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3515 ctx
->Driver
.CompressedTexImage1D(ctx
, texImage
,
3518 border
, imageSize
, data
);
3521 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3522 ctx
->Driver
.CompressedTexImage2D(ctx
, texImage
,
3525 border
, imageSize
, data
);
3528 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3529 ctx
->Driver
.CompressedTexImage3D(ctx
, texImage
,
3531 width
, height
, depth
,
3532 border
, imageSize
, data
);
3535 _mesa_problem(ctx
, "bad dims in compressedteximage");
3538 check_gen_mipmap(ctx
, target
, texObj
, level
);
3541 texObj
->_Complete
= GL_FALSE
;
3542 ctx
->NewState
|= _NEW_TEXTURE
;
3545 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3546 "glCompressedTexImage%uD", dims
);
3550 _mesa_unlock_texture(ctx
, texObj
);
3556 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3557 GLenum internalFormat
, GLsizei width
,
3558 GLint border
, GLsizei imageSize
,
3561 GET_CURRENT_CONTEXT(ctx
);
3562 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3563 width
, 1, 1, border
, imageSize
, data
);
3568 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3569 GLenum internalFormat
, GLsizei width
,
3570 GLsizei height
, GLint border
, GLsizei imageSize
,
3573 GET_CURRENT_CONTEXT(ctx
);
3574 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3575 width
, height
, 1, border
, imageSize
, data
);
3580 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3581 GLenum internalFormat
, GLsizei width
,
3582 GLsizei height
, GLsizei depth
, GLint border
,
3583 GLsizei imageSize
, const GLvoid
*data
)
3585 GET_CURRENT_CONTEXT(ctx
);
3586 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3587 width
, height
, depth
, border
, imageSize
, data
);
3592 * Common helper for glCompressedTexSubImage1/2/3D().
3595 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3596 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3597 GLsizei width
, GLsizei height
, GLsizei depth
,
3598 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3600 struct gl_texture_object
*texObj
;
3601 struct gl_texture_image
*texImage
;
3603 GET_CURRENT_CONTEXT(ctx
);
3604 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3606 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3607 xoffset
, 0, 0, /* pos */
3608 width
, height
, depth
, /* size */
3611 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3615 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3617 _mesa_lock_texture(ctx
, texObj
);
3619 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3622 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3623 format
, texImage
)) {
3624 /* error was recorded */
3626 else if (width
> 0 && height
> 0 && depth
> 0) {
3629 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3630 ctx
->Driver
.CompressedTexSubImage1D(ctx
, texImage
,
3632 format
, imageSize
, data
);
3636 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3637 ctx
->Driver
.CompressedTexSubImage2D(ctx
, texImage
,
3640 format
, imageSize
, data
);
3644 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3645 ctx
->Driver
.CompressedTexSubImage3D(ctx
, texImage
,
3646 xoffset
, yoffset
, zoffset
,
3647 width
, height
, depth
,
3648 format
, imageSize
, data
);
3655 check_gen_mipmap(ctx
, target
, texObj
, level
);
3657 ctx
->NewState
|= _NEW_TEXTURE
;
3660 _mesa_unlock_texture(ctx
, texObj
);
3665 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3666 GLsizei width
, GLenum format
,
3667 GLsizei imageSize
, const GLvoid
*data
)
3669 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3670 format
, imageSize
, data
);
3675 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3676 GLint yoffset
, GLsizei width
, GLsizei height
,
3677 GLenum format
, GLsizei imageSize
,
3680 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3681 width
, height
, 1, format
, imageSize
, data
);
3686 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3687 GLint yoffset
, GLint zoffset
, GLsizei width
,
3688 GLsizei height
, GLsizei depth
, GLenum format
,
3689 GLsizei imageSize
, const GLvoid
*data
)
3691 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3692 width
, height
, depth
, format
, imageSize
, data
);
3697 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3698 * return the basic data type and number of components for the format.
3699 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3702 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3703 GLenum
*datatype
, GLuint
*components
)
3705 switch (internalFormat
) {
3707 *datatype
= GL_UNSIGNED_BYTE
;
3711 *datatype
= GL_UNSIGNED_SHORT
;
3714 case GL_ALPHA16F_ARB
:
3715 *datatype
= GL_HALF_FLOAT
;
3718 case GL_ALPHA32F_ARB
:
3719 *datatype
= GL_FLOAT
;
3722 case GL_ALPHA8I_EXT
:
3723 *datatype
= GL_BYTE
;
3726 case GL_ALPHA16I_EXT
:
3727 *datatype
= GL_SHORT
;
3730 case GL_ALPHA32I_EXT
:
3734 case GL_ALPHA8UI_EXT
:
3735 *datatype
= GL_UNSIGNED_BYTE
;
3738 case GL_ALPHA16UI_EXT
:
3739 *datatype
= GL_UNSIGNED_SHORT
;
3742 case GL_ALPHA32UI_EXT
:
3743 *datatype
= GL_UNSIGNED_INT
;
3747 *datatype
= GL_UNSIGNED_BYTE
;
3750 case GL_LUMINANCE16
:
3751 *datatype
= GL_UNSIGNED_SHORT
;
3754 case GL_LUMINANCE16F_ARB
:
3755 *datatype
= GL_HALF_FLOAT
;
3758 case GL_LUMINANCE32F_ARB
:
3759 *datatype
= GL_FLOAT
;
3762 case GL_LUMINANCE8I_EXT
:
3763 *datatype
= GL_BYTE
;
3766 case GL_LUMINANCE16I_EXT
:
3767 *datatype
= GL_SHORT
;
3770 case GL_LUMINANCE32I_EXT
:
3774 case GL_LUMINANCE8UI_EXT
:
3775 *datatype
= GL_UNSIGNED_BYTE
;
3778 case GL_LUMINANCE16UI_EXT
:
3779 *datatype
= GL_UNSIGNED_SHORT
;
3782 case GL_LUMINANCE32UI_EXT
:
3783 *datatype
= GL_UNSIGNED_INT
;
3786 case GL_LUMINANCE8_ALPHA8
:
3787 *datatype
= GL_UNSIGNED_BYTE
;
3790 case GL_LUMINANCE16_ALPHA16
:
3791 *datatype
= GL_UNSIGNED_SHORT
;
3794 case GL_LUMINANCE_ALPHA16F_ARB
:
3795 *datatype
= GL_HALF_FLOAT
;
3798 case GL_LUMINANCE_ALPHA32F_ARB
:
3799 *datatype
= GL_FLOAT
;
3802 case GL_LUMINANCE_ALPHA8I_EXT
:
3803 *datatype
= GL_BYTE
;
3806 case GL_LUMINANCE_ALPHA16I_EXT
:
3807 *datatype
= GL_SHORT
;
3810 case GL_LUMINANCE_ALPHA32I_EXT
:
3814 case GL_LUMINANCE_ALPHA8UI_EXT
:
3815 *datatype
= GL_UNSIGNED_BYTE
;
3818 case GL_LUMINANCE_ALPHA16UI_EXT
:
3819 *datatype
= GL_UNSIGNED_SHORT
;
3822 case GL_LUMINANCE_ALPHA32UI_EXT
:
3823 *datatype
= GL_UNSIGNED_INT
;
3827 *datatype
= GL_UNSIGNED_BYTE
;
3830 case GL_INTENSITY16
:
3831 *datatype
= GL_UNSIGNED_SHORT
;
3834 case GL_INTENSITY16F_ARB
:
3835 *datatype
= GL_HALF_FLOAT
;
3838 case GL_INTENSITY32F_ARB
:
3839 *datatype
= GL_FLOAT
;
3842 case GL_INTENSITY8I_EXT
:
3843 *datatype
= GL_BYTE
;
3846 case GL_INTENSITY16I_EXT
:
3847 *datatype
= GL_SHORT
;
3850 case GL_INTENSITY32I_EXT
:
3854 case GL_INTENSITY8UI_EXT
:
3855 *datatype
= GL_UNSIGNED_BYTE
;
3858 case GL_INTENSITY16UI_EXT
:
3859 *datatype
= GL_UNSIGNED_SHORT
;
3862 case GL_INTENSITY32UI_EXT
:
3863 *datatype
= GL_UNSIGNED_INT
;
3867 *datatype
= GL_UNSIGNED_BYTE
;
3871 *datatype
= GL_UNSIGNED_SHORT
;
3874 case GL_RGBA16F_ARB
:
3875 *datatype
= GL_HALF_FLOAT
;
3878 case GL_RGBA32F_ARB
:
3879 *datatype
= GL_FLOAT
;
3883 *datatype
= GL_BYTE
;
3886 case GL_RGBA16I_EXT
:
3887 *datatype
= GL_SHORT
;
3890 case GL_RGBA32I_EXT
:
3894 case GL_RGBA8UI_EXT
:
3895 *datatype
= GL_UNSIGNED_BYTE
;
3898 case GL_RGBA16UI_EXT
:
3899 *datatype
= GL_UNSIGNED_SHORT
;
3902 case GL_RGBA32UI_EXT
:
3903 *datatype
= GL_UNSIGNED_INT
;
3910 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3913 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3920 /** GL_ARB_texture_buffer_object */
3922 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3924 struct gl_texture_object
*texObj
;
3925 struct gl_buffer_object
*bufObj
;
3929 GET_CURRENT_CONTEXT(ctx
);
3930 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3932 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3933 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3937 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3938 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3942 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3943 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3948 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3949 if (buffer
&& !bufObj
) {
3950 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3954 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3956 _mesa_lock_texture(ctx
, texObj
);
3958 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3959 texObj
->BufferObjectFormat
= internalFormat
;
3961 _mesa_unlock_texture(ctx
, texObj
);