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 switch (internalFormat
) {
143 case GL_COMPRESSED_ALPHA
:
145 case GL_COMPRESSED_LUMINANCE
:
147 case GL_COMPRESSED_LUMINANCE_ALPHA
:
148 return GL_LUMINANCE_ALPHA
;
149 case GL_COMPRESSED_INTENSITY
:
151 case GL_COMPRESSED_RGB
:
153 case GL_COMPRESSED_RGBA
:
159 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
160 switch (internalFormat
) {
161 case GL_COMPRESSED_RGB_FXT1_3DFX
:
163 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
170 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
171 switch (internalFormat
) {
172 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
174 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
175 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
176 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
183 if (ctx
->Extensions
.S3_s3tc
) {
184 switch (internalFormat
) {
196 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
197 if (internalFormat
== GL_YCBCR_MESA
)
198 return GL_YCBCR_MESA
;
201 if (ctx
->Extensions
.ARB_texture_float
) {
202 switch (internalFormat
) {
203 case GL_ALPHA16F_ARB
:
204 case GL_ALPHA32F_ARB
:
212 case GL_INTENSITY16F_ARB
:
213 case GL_INTENSITY32F_ARB
:
215 case GL_LUMINANCE16F_ARB
:
216 case GL_LUMINANCE32F_ARB
:
218 case GL_LUMINANCE_ALPHA16F_ARB
:
219 case GL_LUMINANCE_ALPHA32F_ARB
:
220 return GL_LUMINANCE_ALPHA
;
226 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
227 switch (internalFormat
) {
236 if (ctx
->Extensions
.EXT_texture_snorm
) {
237 switch (internalFormat
) {
252 case GL_RGBA16_SNORM
:
255 case GL_ALPHA8_SNORM
:
256 case GL_ALPHA16_SNORM
:
258 case GL_LUMINANCE_SNORM
:
259 case GL_LUMINANCE8_SNORM
:
260 case GL_LUMINANCE16_SNORM
:
262 case GL_LUMINANCE_ALPHA_SNORM
:
263 case GL_LUMINANCE8_ALPHA8_SNORM
:
264 case GL_LUMINANCE16_ALPHA16_SNORM
:
265 return GL_LUMINANCE_ALPHA
;
266 case GL_INTENSITY_SNORM
:
267 case GL_INTENSITY8_SNORM
:
268 case GL_INTENSITY16_SNORM
:
275 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
276 switch (internalFormat
) {
277 case GL_DEPTH_STENCIL_EXT
:
278 case GL_DEPTH24_STENCIL8_EXT
:
279 return GL_DEPTH_STENCIL_EXT
;
285 #if FEATURE_EXT_texture_sRGB
286 if (ctx
->Extensions
.EXT_texture_sRGB
) {
287 switch (internalFormat
) {
290 case GL_COMPRESSED_SRGB_EXT
:
291 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
293 case GL_SRGB_ALPHA_EXT
:
294 case GL_SRGB8_ALPHA8_EXT
:
295 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
296 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
297 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
298 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
300 case GL_SLUMINANCE_ALPHA_EXT
:
301 case GL_SLUMINANCE8_ALPHA8_EXT
:
302 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
303 return GL_LUMINANCE_ALPHA
;
304 case GL_SLUMINANCE_EXT
:
305 case GL_SLUMINANCE8_EXT
:
306 case GL_COMPRESSED_SLUMINANCE_EXT
:
312 #endif /* FEATURE_EXT_texture_sRGB */
314 if (ctx
->VersionMajor
>= 3 ||
315 ctx
->Extensions
.EXT_texture_integer
) {
316 switch (internalFormat
) {
318 case GL_RGBA16UI_EXT
:
319 case GL_RGBA32UI_EXT
:
335 if (ctx
->Extensions
.EXT_texture_integer
) {
336 switch (internalFormat
) {
337 case GL_ALPHA8UI_EXT
:
338 case GL_ALPHA16UI_EXT
:
339 case GL_ALPHA32UI_EXT
:
341 case GL_ALPHA16I_EXT
:
342 case GL_ALPHA32I_EXT
:
344 case GL_INTENSITY8UI_EXT
:
345 case GL_INTENSITY16UI_EXT
:
346 case GL_INTENSITY32UI_EXT
:
347 case GL_INTENSITY8I_EXT
:
348 case GL_INTENSITY16I_EXT
:
349 case GL_INTENSITY32I_EXT
:
351 case GL_LUMINANCE8UI_EXT
:
352 case GL_LUMINANCE16UI_EXT
:
353 case GL_LUMINANCE32UI_EXT
:
354 case GL_LUMINANCE8I_EXT
:
355 case GL_LUMINANCE16I_EXT
:
356 case GL_LUMINANCE32I_EXT
:
358 case GL_LUMINANCE_ALPHA8UI_EXT
:
359 case GL_LUMINANCE_ALPHA16UI_EXT
:
360 case GL_LUMINANCE_ALPHA32UI_EXT
:
361 case GL_LUMINANCE_ALPHA8I_EXT
:
362 case GL_LUMINANCE_ALPHA16I_EXT
:
363 case GL_LUMINANCE_ALPHA32I_EXT
:
364 return GL_LUMINANCE_ALPHA
;
370 if (ctx
->Extensions
.ARB_texture_rg
) {
371 switch (internalFormat
) {
373 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
375 if (!ctx
->Extensions
.ARB_half_float_pixel
)
379 if (!ctx
->Extensions
.ARB_texture_float
)
388 if (ctx
->VersionMajor
< 3 && !ctx
->Extensions
.EXT_texture_integer
)
394 case GL_COMPRESSED_RED
:
398 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
400 if (!ctx
->Extensions
.ARB_half_float_pixel
)
404 if (!ctx
->Extensions
.ARB_texture_float
)
413 if (ctx
->VersionMajor
< 3 && !ctx
->Extensions
.EXT_texture_integer
)
419 case GL_COMPRESSED_RG
:
426 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
427 switch (internalFormat
) {
428 case GL_DEPTH_COMPONENT32F
:
429 return GL_DEPTH_COMPONENT
;
430 case GL_DEPTH32F_STENCIL8
:
431 return GL_DEPTH_STENCIL
;
437 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
438 switch (internalFormat
) {
439 case GL_COMPRESSED_RED_RGTC1
:
440 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
442 case GL_COMPRESSED_RG_RGTC2
:
443 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
450 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
451 switch (internalFormat
) {
452 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
453 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
455 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
456 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
457 return GL_LUMINANCE_ALPHA
;
463 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
464 switch (internalFormat
) {
465 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
466 return GL_LUMINANCE_ALPHA
;
472 if (ctx
->API
== API_OPENGLES
) {
473 switch (internalFormat
) {
474 case GL_PALETTE4_RGB8_OES
:
475 case GL_PALETTE4_R5_G6_B5_OES
:
476 case GL_PALETTE8_RGB8_OES
:
477 case GL_PALETTE8_R5_G6_B5_OES
:
479 case GL_PALETTE4_RGBA8_OES
:
480 case GL_PALETTE8_RGB5_A1_OES
:
481 case GL_PALETTE4_RGBA4_OES
:
482 case GL_PALETTE4_RGB5_A1_OES
:
483 case GL_PALETTE8_RGBA8_OES
:
484 case GL_PALETTE8_RGBA4_OES
:
491 return -1; /* error */
496 * Is the given texture format a generic compressed format?
499 is_generic_compressed_format(GLenum format
)
502 case GL_COMPRESSED_RED
:
503 case GL_COMPRESSED_RG
:
504 case GL_COMPRESSED_RGB
:
505 case GL_COMPRESSED_RGBA
:
506 case GL_COMPRESSED_ALPHA
:
507 case GL_COMPRESSED_LUMINANCE
:
508 case GL_COMPRESSED_LUMINANCE_ALPHA
:
509 case GL_COMPRESSED_INTENSITY
:
510 case GL_COMPRESSED_SRGB
:
511 case GL_COMPRESSED_SRGB_ALPHA
:
512 case GL_COMPRESSED_SLUMINANCE
:
513 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
522 * For cube map faces, return a face index in [0,5].
523 * For other targets return 0;
526 _mesa_tex_target_to_face(GLenum target
)
528 if (_mesa_is_cube_face(target
))
529 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
537 * Install gl_texture_image in a gl_texture_object according to the target
538 * and level parameters.
540 * \param tObj texture object.
541 * \param target texture target.
542 * \param level image level.
543 * \param texImage texture image.
546 set_tex_image(struct gl_texture_object
*tObj
,
547 GLenum target
, GLint level
,
548 struct gl_texture_image
*texImage
)
550 const GLuint face
= _mesa_tex_target_to_face(target
);
554 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
557 tObj
->Image
[face
][level
] = texImage
;
559 /* Set the 'back' pointer */
560 texImage
->TexObject
= tObj
;
561 texImage
->Level
= level
;
562 texImage
->Face
= face
;
567 * Allocate a texture image structure.
569 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
572 * \return a pointer to gl_texture_image struct with all fields initialized to
575 struct gl_texture_image
*
576 _mesa_new_texture_image( struct gl_context
*ctx
)
579 return CALLOC_STRUCT(gl_texture_image
);
584 * Free a gl_texture_image and associated data.
585 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
587 * \param texImage texture image.
589 * Free the texture image structure and the associated image data.
592 _mesa_delete_texture_image(struct gl_context
*ctx
,
593 struct gl_texture_image
*texImage
)
595 /* Free texImage->Data and/or any other driver-specific texture
598 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
599 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
605 * Test if a target is a proxy target.
607 * \param target texture target.
609 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
612 _mesa_is_proxy_texture(GLenum target
)
615 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
616 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
618 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
620 return (target
== GL_PROXY_TEXTURE_1D
||
621 target
== GL_PROXY_TEXTURE_2D
||
622 target
== GL_PROXY_TEXTURE_3D
||
623 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
624 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
625 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
626 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
631 * Return the proxy target which corresponds to the given texture target
634 get_proxy_target(GLenum target
)
638 case GL_PROXY_TEXTURE_1D
:
639 return GL_PROXY_TEXTURE_1D
;
641 case GL_PROXY_TEXTURE_2D
:
642 return GL_PROXY_TEXTURE_2D
;
644 case GL_PROXY_TEXTURE_3D
:
645 return GL_PROXY_TEXTURE_3D
;
646 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
647 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
648 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
649 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
650 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
651 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
652 case GL_TEXTURE_CUBE_MAP_ARB
:
653 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
654 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
655 case GL_TEXTURE_RECTANGLE_NV
:
656 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
657 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
658 case GL_TEXTURE_1D_ARRAY_EXT
:
659 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
660 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
661 case GL_TEXTURE_2D_ARRAY_EXT
:
662 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
663 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
665 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
672 * Get the texture object that corresponds to the target of the given
673 * texture unit. The target should have already been checked for validity.
675 * \param ctx GL context.
676 * \param texUnit texture unit.
677 * \param target texture target.
679 * \return pointer to the texture object on success, or NULL on failure.
681 struct gl_texture_object
*
682 _mesa_select_tex_object(struct gl_context
*ctx
,
683 const struct gl_texture_unit
*texUnit
,
686 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
687 ctx
->Extensions
.EXT_texture_array
);
691 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
692 case GL_PROXY_TEXTURE_1D
:
693 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
695 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
696 case GL_PROXY_TEXTURE_2D
:
697 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
699 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
700 case GL_PROXY_TEXTURE_3D
:
701 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
702 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
703 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
704 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
705 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
706 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
707 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
708 case GL_TEXTURE_CUBE_MAP_ARB
:
709 return ctx
->Extensions
.ARB_texture_cube_map
710 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
711 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
712 return ctx
->Extensions
.ARB_texture_cube_map
713 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
714 case GL_TEXTURE_RECTANGLE_NV
:
715 return ctx
->Extensions
.NV_texture_rectangle
716 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
717 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
718 return ctx
->Extensions
.NV_texture_rectangle
719 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
720 case GL_TEXTURE_1D_ARRAY_EXT
:
721 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
722 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
723 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
724 case GL_TEXTURE_2D_ARRAY_EXT
:
725 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
726 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
727 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
728 case GL_TEXTURE_BUFFER
:
729 return ctx
->Extensions
.ARB_texture_buffer_object
730 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
731 case GL_TEXTURE_EXTERNAL_OES
:
732 return ctx
->Extensions
.OES_EGL_image_external
733 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
735 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
742 * Return pointer to texture object for given target on current texture unit.
744 struct gl_texture_object
*
745 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
747 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
748 return _mesa_select_tex_object(ctx
, texUnit
, target
);
753 * Get a texture image pointer from a texture object, given a texture
754 * target and mipmap level. The target and level parameters should
755 * have already been error-checked.
757 * \param ctx GL context.
758 * \param texObj texture unit.
759 * \param target texture target.
760 * \param level image level.
762 * \return pointer to the texture image structure, or NULL on failure.
764 struct gl_texture_image
*
765 _mesa_select_tex_image(struct gl_context
*ctx
,
766 const struct gl_texture_object
*texObj
,
767 GLenum target
, GLint level
)
769 const GLuint face
= _mesa_tex_target_to_face(target
);
773 ASSERT(level
< MAX_TEXTURE_LEVELS
);
775 return texObj
->Image
[face
][level
];
780 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
781 * it and install it. Only return NULL if passed a bad parameter or run
784 struct gl_texture_image
*
785 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
786 GLenum target
, GLint level
)
788 struct gl_texture_image
*texImage
;
793 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
795 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
797 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
801 set_tex_image(texObj
, target
, level
, texImage
);
809 * Return pointer to the specified proxy texture image.
810 * Note that proxy textures are per-context, not per-texture unit.
811 * \return pointer to texture image or NULL if invalid target, invalid
812 * level, or out of memory.
814 struct gl_texture_image
*
815 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
817 struct gl_texture_image
*texImage
;
824 case GL_PROXY_TEXTURE_1D
:
825 if (level
>= ctx
->Const
.MaxTextureLevels
)
827 texIndex
= TEXTURE_1D_INDEX
;
829 case GL_PROXY_TEXTURE_2D
:
830 if (level
>= ctx
->Const
.MaxTextureLevels
)
832 texIndex
= TEXTURE_2D_INDEX
;
834 case GL_PROXY_TEXTURE_3D
:
835 if (level
>= ctx
->Const
.Max3DTextureLevels
)
837 texIndex
= TEXTURE_3D_INDEX
;
839 case GL_PROXY_TEXTURE_CUBE_MAP
:
840 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
842 texIndex
= TEXTURE_CUBE_INDEX
;
844 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
847 texIndex
= TEXTURE_RECT_INDEX
;
849 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
850 if (level
>= ctx
->Const
.MaxTextureLevels
)
852 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
854 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
855 if (level
>= ctx
->Const
.MaxTextureLevels
)
857 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
863 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
865 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
867 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
870 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
871 /* Set the 'back' pointer */
872 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
879 * Get the maximum number of allowed mipmap levels.
881 * \param ctx GL context.
882 * \param target texture target.
884 * \return the maximum number of allowed mipmap levels for the given
885 * texture target, or zero if passed a bad target.
890 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
894 case GL_PROXY_TEXTURE_1D
:
896 case GL_PROXY_TEXTURE_2D
:
897 return ctx
->Const
.MaxTextureLevels
;
899 case GL_PROXY_TEXTURE_3D
:
900 return ctx
->Const
.Max3DTextureLevels
;
901 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
902 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
903 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
904 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
905 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
906 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
907 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
908 return ctx
->Extensions
.ARB_texture_cube_map
909 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
910 case GL_TEXTURE_RECTANGLE_NV
:
911 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
912 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
913 case GL_TEXTURE_1D_ARRAY_EXT
:
914 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
915 case GL_TEXTURE_2D_ARRAY_EXT
:
916 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
917 return (ctx
->Extensions
.MESA_texture_array
||
918 ctx
->Extensions
.EXT_texture_array
)
919 ? ctx
->Const
.MaxTextureLevels
: 0;
920 case GL_TEXTURE_BUFFER
:
921 case GL_TEXTURE_EXTERNAL_OES
:
924 return 0; /* bad target */
930 * Return number of dimensions per mipmap level for the given texture target.
933 _mesa_get_texture_dimensions(GLenum target
)
937 case GL_PROXY_TEXTURE_1D
:
940 case GL_TEXTURE_RECTANGLE
:
941 case GL_TEXTURE_CUBE_MAP
:
942 case GL_PROXY_TEXTURE_2D
:
943 case GL_PROXY_TEXTURE_RECTANGLE
:
944 case GL_PROXY_TEXTURE_CUBE_MAP
:
945 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
946 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
947 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
948 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
949 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
950 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
951 case GL_TEXTURE_1D_ARRAY
:
952 case GL_PROXY_TEXTURE_1D_ARRAY
:
953 case GL_TEXTURE_EXTERNAL_OES
:
956 case GL_PROXY_TEXTURE_3D
:
957 case GL_TEXTURE_2D_ARRAY
:
958 case GL_PROXY_TEXTURE_2D_ARRAY
:
960 case GL_TEXTURE_BUFFER
:
963 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
972 #if 000 /* not used anymore */
974 * glTexImage[123]D can accept a NULL image pointer. In this case we
975 * create a texture image with unspecified image contents per the OpenGL
979 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
981 const GLint components
= _mesa_components_in_format(format
);
982 const GLint numPixels
= width
* height
* depth
;
983 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
987 * Let's see if anyone finds this. If glTexImage2D() is called with
988 * a NULL image pointer then load the texture image with something
989 * interesting instead of leaving it indeterminate.
992 static const char message
[8][32] = {
996 " X X XXXX XXX XXXXX ",
999 " X X XXXXX XXX X X ",
1003 GLubyte
*imgPtr
= data
;
1005 for (h
= 0; h
< depth
; h
++) {
1006 for (i
= 0; i
< height
; i
++) {
1007 GLint srcRow
= 7 - (i
% 8);
1008 for (j
= 0; j
< width
; j
++) {
1009 GLint srcCol
= j
% 32;
1010 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1011 for (k
= 0; k
< components
; k
++) {
1027 * Set the size and format-related fields of a gl_texture_image struct
1028 * to zero. This is used when a proxy texture test fails.
1031 clear_teximage_fields(struct gl_texture_image
*img
)
1034 img
->_BaseFormat
= 0;
1035 img
->InternalFormat
= 0;
1044 img
->HeightLog2
= 0;
1046 img
->TexFormat
= MESA_FORMAT_NONE
;
1051 * Initialize basic fields of the gl_texture_image struct.
1053 * \param ctx GL context.
1054 * \param img texture image structure to be initialized.
1055 * \param width image width.
1056 * \param height image height.
1057 * \param depth image depth.
1058 * \param border image border.
1059 * \param internalFormat internal format.
1060 * \param format the actual hardware format (one of MESA_FORMAT_*)
1062 * Fills in the fields of \p img with the given information.
1063 * Note: width, height and depth include the border.
1066 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1067 struct gl_texture_image
*img
,
1068 GLsizei width
, GLsizei height
, GLsizei depth
,
1069 GLint border
, GLenum internalFormat
,
1075 ASSERT(height
>= 0);
1078 target
= img
->TexObject
->Target
;
1079 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1080 ASSERT(img
->_BaseFormat
> 0);
1081 img
->InternalFormat
= internalFormat
;
1082 img
->Border
= border
;
1084 img
->Height
= height
;
1087 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1088 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1092 case GL_TEXTURE_BUFFER
:
1093 case GL_PROXY_TEXTURE_1D
:
1098 img
->HeightLog2
= 0;
1105 case GL_TEXTURE_1D_ARRAY
:
1106 case GL_PROXY_TEXTURE_1D_ARRAY
:
1107 img
->Height2
= height
; /* no border */
1108 img
->HeightLog2
= 0; /* not used */
1116 case GL_TEXTURE_RECTANGLE
:
1117 case GL_TEXTURE_CUBE_MAP
:
1118 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1119 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1120 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1121 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1122 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1123 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1124 case GL_TEXTURE_EXTERNAL_OES
:
1125 case GL_PROXY_TEXTURE_2D
:
1126 case GL_PROXY_TEXTURE_RECTANGLE
:
1127 case GL_PROXY_TEXTURE_CUBE_MAP
:
1128 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1129 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1136 case GL_TEXTURE_2D_ARRAY
:
1137 case GL_PROXY_TEXTURE_2D_ARRAY
:
1138 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1139 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1140 img
->Depth2
= depth
; /* no border */
1141 img
->DepthLog2
= 0; /* not used */
1144 case GL_PROXY_TEXTURE_3D
:
1145 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1146 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1147 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1148 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1151 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1155 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1156 img
->TexFormat
= format
;
1161 * Free and clear fields of the gl_texture_image struct.
1163 * \param ctx GL context.
1164 * \param texImage texture image structure to be cleared.
1166 * After the call, \p texImage will have no data associated with it. Its
1167 * fields are cleared so that its parent object will test incomplete.
1170 _mesa_clear_texture_image(struct gl_context
*ctx
,
1171 struct gl_texture_image
*texImage
)
1173 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1174 clear_teximage_fields(texImage
);
1179 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1180 * level, width, height and depth against the ctx->Const limits for textures.
1182 * A hardware driver might override this function if, for example, the
1183 * max 3D texture size is 512x512x64 (i.e. not a cube).
1185 * Note that width, height, depth == 0 is not an error. However, a
1186 * texture with zero width/height/depth will be considered "incomplete"
1187 * and texturing will effectively be disabled.
1189 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1190 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1191 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1192 * \param level as passed to glTexImage
1193 * \param internalFormat as passed to glTexImage
1194 * \param format as passed to glTexImage
1195 * \param type as passed to glTexImage
1196 * \param width as passed to glTexImage
1197 * \param height as passed to glTexImage
1198 * \param depth as passed to glTexImage
1199 * \param border as passed to glTexImage
1200 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1203 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1204 GLint internalFormat
, GLenum format
, GLenum type
,
1205 GLint width
, GLint height
, GLint depth
, GLint border
)
1209 (void) internalFormat
;
1214 case GL_PROXY_TEXTURE_1D
:
1215 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1216 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1218 if (level
>= ctx
->Const
.MaxTextureLevels
)
1220 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1221 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1226 case GL_PROXY_TEXTURE_2D
:
1227 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1228 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1230 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1232 if (level
>= ctx
->Const
.MaxTextureLevels
)
1234 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1235 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1237 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1242 case GL_PROXY_TEXTURE_3D
:
1243 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1244 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1246 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1248 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1250 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1252 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1253 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1255 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1257 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1262 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1263 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1264 if (width
< 0 || width
> maxSize
)
1266 if (height
< 0 || height
> maxSize
)
1272 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1273 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1274 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1276 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1278 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1280 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1281 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1283 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1288 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1289 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1290 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1292 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1294 if (level
>= ctx
->Const
.MaxTextureLevels
)
1296 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1297 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1302 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1303 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1304 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1306 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1308 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1310 if (level
>= ctx
->Const
.MaxTextureLevels
)
1312 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1313 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1315 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1321 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1328 * Check if the memory used by the texture would exceed the driver's limit.
1329 * This lets us support a max 3D texture size of 8K (for example) but
1330 * prevents allocating a full 8K x 8K x 8K texture.
1331 * XXX this could be rolled into the proxy texture size test (above) but
1332 * we don't have the actual texture internal format at that point.
1335 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1336 GLint width
, GLint height
, GLint depth
)
1338 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1339 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1340 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1345 * Helper function to determine whether a target and specific compression
1346 * format are supported.
1349 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1352 (void) intFormat
; /* not used yet */
1356 case GL_PROXY_TEXTURE_2D
:
1357 return GL_TRUE
; /* true for any compressed format so far */
1358 case GL_PROXY_TEXTURE_CUBE_MAP
:
1359 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1360 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1361 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1362 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1363 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1364 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1365 return ctx
->Extensions
.ARB_texture_cube_map
;
1366 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1367 case GL_TEXTURE_2D_ARRAY_EXT
:
1368 return (ctx
->Extensions
.MESA_texture_array
||
1369 ctx
->Extensions
.EXT_texture_array
);
1377 * Check if the given texture target value is legal for a
1378 * glTexImage1/2/3D call.
1381 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1387 case GL_PROXY_TEXTURE_1D
:
1395 case GL_PROXY_TEXTURE_2D
:
1397 case GL_PROXY_TEXTURE_CUBE_MAP
:
1398 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1399 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1400 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1401 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1402 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1403 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1404 return ctx
->Extensions
.ARB_texture_cube_map
;
1405 case GL_TEXTURE_RECTANGLE_NV
:
1406 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1407 return ctx
->Extensions
.NV_texture_rectangle
;
1408 case GL_TEXTURE_1D_ARRAY_EXT
:
1409 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1410 return (ctx
->Extensions
.MESA_texture_array
||
1411 ctx
->Extensions
.EXT_texture_array
);
1418 case GL_PROXY_TEXTURE_3D
:
1420 case GL_TEXTURE_2D_ARRAY_EXT
:
1421 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1422 return (ctx
->Extensions
.MESA_texture_array
||
1423 ctx
->Extensions
.EXT_texture_array
);
1428 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1435 * Check if the given texture target value is legal for a
1436 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1437 * The difference compared to legal_teximage_target() above is that
1438 * proxy targets are not supported.
1441 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1445 return target
== GL_TEXTURE_1D
;
1450 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1451 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1452 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1453 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1454 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1455 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1456 return ctx
->Extensions
.ARB_texture_cube_map
;
1457 case GL_TEXTURE_RECTANGLE_NV
:
1458 return ctx
->Extensions
.NV_texture_rectangle
;
1459 case GL_TEXTURE_1D_ARRAY_EXT
:
1460 return (ctx
->Extensions
.MESA_texture_array
||
1461 ctx
->Extensions
.EXT_texture_array
);
1469 case GL_TEXTURE_2D_ARRAY_EXT
:
1470 return (ctx
->Extensions
.MESA_texture_array
||
1471 ctx
->Extensions
.EXT_texture_array
);
1476 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1484 * Helper function to determine if a texture object is mutable (in terms
1485 * of GL_ARB_texture_storage).
1488 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1490 if (ctx
->Extensions
.ARB_texture_storage
) {
1491 struct gl_texture_object
*texObj
=
1492 _mesa_get_current_tex_object(ctx
, target
);
1493 return !texObj
->Immutable
;
1501 * Test the glTexImage[123]D() parameters for errors.
1503 * \param ctx GL context.
1504 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1505 * \param target texture target given by the user.
1506 * \param level image level given by the user.
1507 * \param internalFormat internal format given by the user.
1508 * \param format pixel data format given by the user.
1509 * \param type pixel data type given by the user.
1510 * \param width image width given by the user.
1511 * \param height image height given by the user.
1512 * \param depth image depth given by the user.
1513 * \param border image border given by the user.
1515 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1517 * Verifies each of the parameters against the constants specified in
1518 * __struct gl_contextRec::Const and the supported extensions, and according
1519 * to the OpenGL specification.
1522 texture_error_check( struct gl_context
*ctx
,
1523 GLuint dimensions
, GLenum target
,
1524 GLint level
, GLint internalFormat
,
1525 GLenum format
, GLenum type
,
1526 GLint width
, GLint height
,
1527 GLint depth
, GLint border
)
1529 const GLenum proxyTarget
= get_proxy_target(target
);
1530 const GLboolean isProxy
= target
== proxyTarget
;
1531 GLboolean sizeOK
= GL_TRUE
;
1532 GLboolean colorFormat
;
1535 /* Even though there are no color-index textures, we still have to support
1536 * uploading color-index data and remapping it to RGB via the
1537 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1539 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1541 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1542 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1544 _mesa_error(ctx
, GL_INVALID_VALUE
,
1545 "glTexImage%dD(level=%d)", dimensions
, level
);
1551 if (border
< 0 || border
> 1 ||
1552 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1553 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1555 _mesa_error(ctx
, GL_INVALID_VALUE
,
1556 "glTexImage%dD(border=%d)", dimensions
, border
);
1561 if (width
< 0 || height
< 0 || depth
< 0) {
1563 _mesa_error(ctx
, GL_INVALID_VALUE
,
1564 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1569 /* Do this simple check before calling the TestProxyTexImage() function */
1570 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1571 sizeOK
= (width
== height
);
1575 * Use the proxy texture driver hook to see if the size/level/etc are
1578 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1579 internalFormat
, format
,
1580 type
, width
, height
,
1584 _mesa_error(ctx
, GL_INVALID_VALUE
,
1585 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1586 dimensions
, level
, width
, height
, depth
);
1591 /* Check internalFormat */
1592 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1594 _mesa_error(ctx
, GL_INVALID_VALUE
,
1595 "glTexImage%dD(internalFormat=%s)",
1596 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1601 /* Check incoming image format and type */
1602 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1603 if (err
!= GL_NO_ERROR
) {
1605 _mesa_error(ctx
, err
,
1606 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1607 dimensions
, format
, type
);
1612 /* make sure internal format and format basically agree */
1613 colorFormat
= _mesa_is_color_format(format
);
1614 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1615 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1616 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1617 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1618 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1620 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1621 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1622 dimensions
, internalFormat
, format
);
1626 /* additional checks for ycbcr textures */
1627 if (internalFormat
== GL_YCBCR_MESA
) {
1628 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1629 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1630 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1632 _mesa_snprintf(message
, sizeof(message
),
1633 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1634 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1635 return GL_TRUE
; /* error */
1637 if (target
!= GL_TEXTURE_2D
&&
1638 target
!= GL_PROXY_TEXTURE_2D
&&
1639 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1640 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1642 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1648 _mesa_snprintf(message
, sizeof(message
),
1649 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1650 dimensions
, border
);
1651 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1657 /* additional checks for depth textures */
1658 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1659 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1660 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1661 if (target
!= GL_TEXTURE_1D
&&
1662 target
!= GL_PROXY_TEXTURE_1D
&&
1663 target
!= GL_TEXTURE_2D
&&
1664 target
!= GL_PROXY_TEXTURE_2D
&&
1665 target
!= GL_TEXTURE_1D_ARRAY
&&
1666 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1667 target
!= GL_TEXTURE_2D_ARRAY
&&
1668 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1669 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1670 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1671 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1672 (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_gpu_shader4
))) {
1674 _mesa_error(ctx
, GL_INVALID_ENUM
,
1675 "glTexImage(target/internalFormat)");
1680 /* additional checks for compressed textures */
1681 if (_mesa_is_compressed_format(ctx
, internalFormat
) ||
1682 is_generic_compressed_format(internalFormat
)) {
1683 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1685 _mesa_error(ctx
, GL_INVALID_ENUM
,
1686 "glTexImage%dD(target)", dimensions
);
1691 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1692 "glTexImage%dD(border!=0)", dimensions
);
1698 /* additional checks for integer textures */
1699 if ((ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_texture_integer
) &&
1700 (_mesa_is_integer_format(format
) !=
1701 _mesa_is_integer_format(internalFormat
))) {
1703 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1704 "glTexImage%dD(integer/non-integer format mismatch)",
1710 if (!mutable_tex_object(ctx
, target
)) {
1711 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1712 "glTexImage%dD(immutable texture)", dimensions
);
1716 /* if we get here, the parameters are OK */
1722 * Test glTexSubImage[123]D() parameters for errors.
1724 * \param ctx GL context.
1725 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1726 * \param target texture target given by the user.
1727 * \param level image level given by the user.
1728 * \param xoffset sub-image x offset given by the user.
1729 * \param yoffset sub-image y offset given by the user.
1730 * \param zoffset sub-image z offset given by the user.
1731 * \param format pixel data format given by the user.
1732 * \param type pixel data type given by the user.
1733 * \param width image width given by the user.
1734 * \param height image height given by the user.
1735 * \param depth image depth given by the user.
1737 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1739 * Verifies each of the parameters against the constants specified in
1740 * __struct gl_contextRec::Const and the supported extensions, and according
1741 * to the OpenGL specification.
1744 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1745 GLenum target
, GLint level
,
1746 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1747 GLint width
, GLint height
, GLint depth
,
1748 GLenum format
, GLenum type
)
1752 /* Basic level check */
1753 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1754 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1758 /* Check for negative sizes */
1760 _mesa_error(ctx
, GL_INVALID_VALUE
,
1761 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1764 if (height
< 0 && dimensions
> 1) {
1765 _mesa_error(ctx
, GL_INVALID_VALUE
,
1766 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1769 if (depth
< 0 && dimensions
> 2) {
1770 _mesa_error(ctx
, GL_INVALID_VALUE
,
1771 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1775 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1776 if (err
!= GL_NO_ERROR
) {
1777 _mesa_error(ctx
, err
,
1778 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1779 dimensions
, format
, type
);
1788 * Do second part of glTexSubImage which depends on the destination texture.
1789 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1792 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1793 GLenum target
, GLint level
,
1794 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1795 GLint width
, GLint height
, GLint depth
,
1796 GLenum format
, GLenum type
,
1797 const struct gl_texture_image
*destTex
)
1800 /* undefined image level */
1801 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1805 if (xoffset
< -((GLint
)destTex
->Border
)) {
1806 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1810 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1811 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1815 if (dimensions
> 1) {
1816 if (yoffset
< -((GLint
)destTex
->Border
)) {
1817 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1821 if (yoffset
+ height
> (GLint
) (destTex
->Height
+ destTex
->Border
)) {
1822 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1827 if (dimensions
> 2) {
1828 if (zoffset
< -((GLint
)destTex
->Border
)) {
1829 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1832 if (zoffset
+ depth
> (GLint
) (destTex
->Depth
+ destTex
->Border
)) {
1833 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1838 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1841 /* do tests which depend on compression block size */
1842 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1844 /* offset must be multiple of block size */
1845 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1846 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1847 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1848 dimensions
, xoffset
, yoffset
);
1851 /* size must be multiple of bw by bh or equal to whole texture size */
1852 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1853 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1854 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1857 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1858 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1859 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1864 if (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_texture_integer
) {
1865 /* both source and dest must be integer-valued, or neither */
1866 if (_mesa_is_format_integer_color(destTex
->TexFormat
) !=
1867 _mesa_is_integer_format(format
)) {
1868 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1869 "glTexSubImage%dD(integer/non-integer format mismatch)",
1880 * Test glCopyTexImage[12]D() parameters for errors.
1882 * \param ctx GL context.
1883 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1884 * \param target texture target given by the user.
1885 * \param level image level given by the user.
1886 * \param internalFormat internal format given by the user.
1887 * \param width image width given by the user.
1888 * \param height image height given by the user.
1889 * \param border texture border.
1891 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1893 * Verifies each of the parameters against the constants specified in
1894 * __struct gl_contextRec::Const and the supported extensions, and according
1895 * to the OpenGL specification.
1898 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1899 GLenum target
, GLint level
, GLint internalFormat
,
1900 GLint width
, GLint height
, GLint border
)
1902 const GLenum proxyTarget
= get_proxy_target(target
);
1903 const GLenum type
= GL_FLOAT
;
1908 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1909 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1910 dimensions
, _mesa_lookup_enum_by_nr(target
));
1914 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1915 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1916 _mesa_error(ctx
, GL_INVALID_VALUE
,
1917 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1921 /* Check that the source buffer is complete */
1922 if (ctx
->ReadBuffer
->Name
) {
1923 if (ctx
->ReadBuffer
->_Status
== 0) {
1924 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1926 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1927 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1928 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1932 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
1933 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION
,
1934 "glCopyTexImage%dD(multisample FBO)",
1941 if (border
< 0 || border
> 1 ||
1942 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1943 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1947 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1948 if (baseFormat
< 0) {
1949 _mesa_error(ctx
, GL_INVALID_VALUE
,
1950 "glCopyTexImage%dD(internalFormat)", dimensions
);
1954 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
1955 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1956 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1960 /* From the EXT_texture_integer spec:
1962 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
1963 * if the texture internalformat is an integer format and the read color
1964 * buffer is not an integer format, or if the internalformat is not an
1965 * integer format and the read color buffer is an integer format."
1967 if (_mesa_is_color_format(internalFormat
)) {
1968 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
1970 if (_mesa_is_integer_format(rb
->InternalFormat
) !=
1971 _mesa_is_integer_format(internalFormat
)) {
1972 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1973 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
1978 /* Do size, level checking */
1979 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
1980 ? (width
== height
) : 1;
1982 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1983 internalFormat
, baseFormat
,
1984 type
, width
, height
,
1988 if (dimensions
== 1) {
1989 _mesa_error(ctx
, GL_INVALID_VALUE
,
1990 "glCopyTexImage1D(width=%d)", width
);
1993 ASSERT(dimensions
== 2);
1994 _mesa_error(ctx
, GL_INVALID_VALUE
,
1995 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2000 if (_mesa_is_compressed_format(ctx
, internalFormat
) ||
2001 is_generic_compressed_format(internalFormat
)) {
2002 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2003 _mesa_error(ctx
, GL_INVALID_ENUM
,
2004 "glCopyTexImage%dD(target)", dimensions
);
2008 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2009 "glCopyTexImage%dD(border!=0)", dimensions
);
2014 if (!mutable_tex_object(ctx
, target
)) {
2015 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2016 "glCopyTexImage%dD(immutable texture)", dimensions
);
2020 /* if we get here, the parameters are OK */
2026 * Test glCopyTexSubImage[12]D() parameters for errors.
2027 * Note that this is the first part of error checking.
2028 * See also copytexsubimage_error_check2() below for the second part.
2030 * \param ctx GL context.
2031 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2032 * \param target texture target given by the user.
2033 * \param level image level given by the user.
2035 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2038 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2039 GLenum target
, GLint level
)
2041 /* Check that the source buffer is complete */
2042 if (ctx
->ReadBuffer
->Name
) {
2043 if (ctx
->ReadBuffer
->_Status
== 0) {
2044 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2046 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2047 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2048 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2052 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2053 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION
,
2054 "glCopyTexSubImage%dD(multisample FBO)",
2060 /* check target (proxies not allowed) */
2061 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2062 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2063 dimensions
, _mesa_lookup_enum_by_nr(target
));
2068 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2069 _mesa_error(ctx
, GL_INVALID_VALUE
,
2070 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2079 * Second part of error checking for glCopyTexSubImage[12]D().
2080 * \param xoffset sub-image x offset given by the user.
2081 * \param yoffset sub-image y offset given by the user.
2082 * \param zoffset sub-image z offset given by the user.
2083 * \param width image width given by the user.
2084 * \param height image height given by the user.
2087 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2088 GLenum target
, GLint level
,
2089 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2090 GLsizei width
, GLsizei height
,
2091 const struct gl_texture_image
*teximage
)
2093 /* check that dest tex image exists */
2095 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2096 "glCopyTexSubImage%dD(undefined texture level: %d)",
2103 _mesa_error(ctx
, GL_INVALID_VALUE
,
2104 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2107 if (dimensions
> 1 && height
< 0) {
2108 _mesa_error(ctx
, GL_INVALID_VALUE
,
2109 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2113 /* check x/y offsets */
2114 if (xoffset
< -((GLint
)teximage
->Border
)) {
2115 _mesa_error(ctx
, GL_INVALID_VALUE
,
2116 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2119 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2120 _mesa_error(ctx
, GL_INVALID_VALUE
,
2121 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2124 if (dimensions
> 1) {
2125 if (yoffset
< -((GLint
)teximage
->Border
)) {
2126 _mesa_error(ctx
, GL_INVALID_VALUE
,
2127 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2130 /* NOTE: we're adding the border here, not subtracting! */
2131 if (yoffset
+ height
> (GLint
) (teximage
->Height
+ teximage
->Border
)) {
2132 _mesa_error(ctx
, GL_INVALID_VALUE
,
2133 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2138 /* check z offset */
2139 if (dimensions
> 2) {
2140 if (zoffset
< -((GLint
)teximage
->Border
)) {
2141 _mesa_error(ctx
, GL_INVALID_VALUE
,
2142 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2145 if (zoffset
> (GLint
) (teximage
->Depth
+ teximage
->Border
)) {
2146 _mesa_error(ctx
, GL_INVALID_VALUE
,
2147 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2152 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2153 /* offset must be multiple of 4 */
2154 if ((xoffset
& 3) || (yoffset
& 3)) {
2155 _mesa_error(ctx
, GL_INVALID_VALUE
,
2156 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2159 /* size must be multiple of 4 */
2160 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2161 _mesa_error(ctx
, GL_INVALID_VALUE
,
2162 "glCopyTexSubImage%dD(width)", dimensions
);
2165 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2166 _mesa_error(ctx
, GL_INVALID_VALUE
,
2167 "glCopyTexSubImage%dD(height)", dimensions
);
2172 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2173 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2177 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2178 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2179 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2180 dimensions
, teximage
->_BaseFormat
);
2184 /* From the EXT_texture_integer spec:
2186 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2187 * if the texture internalformat is an integer format and the read color
2188 * buffer is not an integer format, or if the internalformat is not an
2189 * integer format and the read color buffer is an integer format."
2191 if (_mesa_is_color_format(teximage
->InternalFormat
)) {
2192 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2194 if (_mesa_is_format_integer_color(rb
->Format
) !=
2195 _mesa_is_format_integer_color(teximage
->TexFormat
)) {
2196 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2197 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2202 /* if we get here, the parameters are OK */
2207 /** Callback info for walking over FBO hash table */
2210 struct gl_context
*ctx
;
2211 struct gl_texture_object
*texObj
;
2217 * Check render to texture callback. Called from _mesa_HashWalk().
2220 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2222 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2223 const struct cb_info
*info
= (struct cb_info
*) userData
;
2224 struct gl_context
*ctx
= info
->ctx
;
2225 const struct gl_texture_object
*texObj
= info
->texObj
;
2226 const GLuint level
= info
->level
, face
= info
->face
;
2228 /* If this is a user-created FBO */
2231 /* check if any of the FBO's attachments point to 'texObj' */
2232 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2233 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2234 if (att
->Type
== GL_TEXTURE
&&
2235 att
->Texture
== texObj
&&
2236 att
->TextureLevel
== level
&&
2237 att
->CubeMapFace
== face
) {
2238 ASSERT(_mesa_get_attachment_teximage(att
));
2239 /* Tell driver about the new renderbuffer texture */
2240 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2241 /* Mark fb status as indeterminate to force re-validation */
2250 * When a texture image is specified we have to check if it's bound to
2251 * any framebuffer objects (render to texture) in order to detect changes
2252 * in size or format since that effects FBO completeness.
2253 * Any FBOs rendering into the texture must be re-validated.
2256 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2257 struct gl_texture_object
*texObj
,
2258 GLuint face
, GLuint level
)
2260 /* Only check this texture if it's been marked as RenderToTexture */
2261 if (texObj
->_RenderToTexture
) {
2262 struct cb_info info
;
2264 info
.texObj
= texObj
;
2267 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2273 * If the texture object's GenerateMipmap flag is set and we've
2274 * changed the texture base level image, regenerate the rest of the
2275 * mipmap levels now.
2278 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2279 struct gl_texture_object
*texObj
, GLint level
)
2281 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2282 if (texObj
->GenerateMipmap
&&
2283 level
== texObj
->BaseLevel
&&
2284 level
< texObj
->MaxLevel
) {
2285 ASSERT(ctx
->Driver
.GenerateMipmap
);
2286 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2291 /** Debug helper: override the user-requested internal format */
2293 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2296 if (internalFormat
== GL_RGBA16F_ARB
||
2297 internalFormat
== GL_RGBA32F_ARB
) {
2298 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2301 else if (internalFormat
== GL_RGB16F_ARB
||
2302 internalFormat
== GL_RGB32F_ARB
) {
2303 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2306 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2307 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2308 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2309 return GL_LUMINANCE_ALPHA
;
2311 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2312 internalFormat
== GL_LUMINANCE32F_ARB
) {
2313 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2314 return GL_LUMINANCE
;
2316 else if (internalFormat
== GL_ALPHA16F_ARB
||
2317 internalFormat
== GL_ALPHA32F_ARB
) {
2318 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2322 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2323 internalFormat = GL_RGBA;
2327 return internalFormat
;
2330 return internalFormat
;
2336 * Choose the actual hardware format for a texture image.
2337 * Try to use the same format as the previous image level when possible.
2338 * Otherwise, ask the driver for the best format.
2339 * It's important to try to choose a consistant format for all levels
2340 * for efficient texture memory layout/allocation. In particular, this
2341 * comes up during automatic mipmap generation.
2344 _mesa_choose_texture_format(struct gl_context
*ctx
,
2345 struct gl_texture_object
*texObj
,
2346 GLenum target
, GLint level
,
2347 GLenum internalFormat
, GLenum format
, GLenum type
)
2351 /* see if we've already chosen a format for the previous level */
2353 struct gl_texture_image
*prevImage
=
2354 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2355 /* See if the prev level is defined and has an internal format which
2356 * matches the new internal format.
2359 prevImage
->Width
> 0 &&
2360 prevImage
->InternalFormat
== internalFormat
) {
2361 /* use the same format */
2362 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2363 return prevImage
->TexFormat
;
2367 /* choose format from scratch */
2368 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2369 ASSERT(f
!= MESA_FORMAT_NONE
);
2374 * Adjust pixel unpack params and image dimensions to strip off the
2377 * Gallium and intel don't support texture borders. They've seldem been used
2378 * and seldom been implemented correctly anyway.
2380 * \param unpackNew returns the new pixel unpack parameters
2383 strip_texture_border(GLint
*border
,
2384 GLint
*width
, GLint
*height
, GLint
*depth
,
2385 const struct gl_pixelstore_attrib
*unpack
,
2386 struct gl_pixelstore_attrib
*unpackNew
)
2388 assert(*border
> 0); /* sanity check */
2390 *unpackNew
= *unpack
;
2392 if (unpackNew
->RowLength
== 0)
2393 unpackNew
->RowLength
= *width
;
2395 if (depth
&& unpackNew
->ImageHeight
== 0)
2396 unpackNew
->ImageHeight
= *height
;
2398 unpackNew
->SkipPixels
+= *border
;
2400 unpackNew
->SkipRows
+= *border
;
2402 unpackNew
->SkipImages
+= *border
;
2404 assert(*width
>= 3);
2405 *width
= *width
- 2 * *border
;
2406 if (height
&& *height
>= 3)
2407 *height
= *height
- 2 * *border
;
2408 if (depth
&& *depth
>= 3)
2409 *depth
= *depth
- 2 * *border
;
2414 * Common code to implement all the glTexImage1D/2D/3D functions.
2417 teximage(struct gl_context
*ctx
, GLuint dims
,
2418 GLenum target
, GLint level
, GLint internalFormat
,
2419 GLsizei width
, GLsizei height
, GLsizei depth
,
2420 GLint border
, GLenum format
, GLenum type
,
2421 const GLvoid
*pixels
)
2424 struct gl_pixelstore_attrib unpack_no_border
;
2425 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2427 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2429 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2430 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2432 _mesa_lookup_enum_by_nr(target
), level
,
2433 _mesa_lookup_enum_by_nr(internalFormat
),
2434 width
, height
, depth
, border
,
2435 _mesa_lookup_enum_by_nr(format
),
2436 _mesa_lookup_enum_by_nr(type
), pixels
);
2438 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2440 /* target error checking */
2441 if (!legal_teximage_target(ctx
, dims
, target
)) {
2442 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2443 dims
, _mesa_lookup_enum_by_nr(target
));
2447 /* general error checking */
2448 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2449 format
, type
, width
, height
, depth
, border
);
2451 if (_mesa_is_proxy_texture(target
)) {
2452 /* Proxy texture: just clear or set state depending on error checking */
2453 struct gl_texture_image
*texImage
=
2454 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2457 /* when error, clear all proxy texture image parameters */
2459 clear_teximage_fields(texImage
);
2462 /* no error, set the tex image parameters */
2463 struct gl_texture_object
*texObj
=
2464 _mesa_get_current_tex_object(ctx
, target
);
2465 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2470 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2471 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
2472 depth
, border
, internalFormat
,
2475 else if (texImage
) {
2476 clear_teximage_fields(texImage
);
2481 /* non-proxy target */
2482 const GLuint face
= _mesa_tex_target_to_face(target
);
2483 struct gl_texture_object
*texObj
;
2484 struct gl_texture_image
*texImage
;
2487 return; /* error was recorded */
2490 /* Allow a hardware driver to just strip out the border, to provide
2491 * reliable but slightly incorrect hardware rendering instead of
2492 * rarely-tested software fallback rendering.
2494 if (border
&& ctx
->Const
.StripTextureBorder
) {
2495 strip_texture_border(&border
, &width
, &height
, &depth
, unpack
,
2497 unpack
= &unpack_no_border
;
2500 if (ctx
->NewState
& _NEW_PIXEL
)
2501 _mesa_update_state(ctx
);
2503 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2505 _mesa_lock_texture(ctx
, texObj
);
2507 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2510 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2513 gl_format texFormat
;
2515 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2517 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2518 internalFormat
, format
,
2521 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2522 _mesa_init_teximage_fields(ctx
, texImage
,
2523 width
, height
, depth
,
2524 border
, internalFormat
, texFormat
);
2526 /* Give the texture to the driver. <pixels> may be null. */
2527 ASSERT(ctx
->Driver
.TexImage3D
);
2530 ctx
->Driver
.TexImage1D(ctx
, texImage
, internalFormat
,
2531 width
, border
, format
,
2532 type
, pixels
, unpack
);
2535 ctx
->Driver
.TexImage2D(ctx
, texImage
, internalFormat
,
2536 width
, height
, border
, format
,
2537 type
, pixels
, unpack
);
2540 ctx
->Driver
.TexImage3D(ctx
, texImage
, internalFormat
,
2541 width
, height
, depth
, border
, format
,
2542 type
, pixels
, unpack
);
2545 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2548 check_gen_mipmap(ctx
, target
, texObj
, level
);
2550 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2553 texObj
->_Complete
= GL_FALSE
;
2554 ctx
->NewState
|= _NEW_TEXTURE
;
2557 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2561 _mesa_unlock_texture(ctx
, texObj
);
2567 * Called from the API. Note that width includes the border.
2570 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2571 GLsizei width
, GLint border
, GLenum format
,
2572 GLenum type
, const GLvoid
*pixels
)
2574 GET_CURRENT_CONTEXT(ctx
);
2575 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2576 border
, format
, type
, pixels
);
2581 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2582 GLsizei width
, GLsizei height
, GLint border
,
2583 GLenum format
, GLenum type
,
2584 const GLvoid
*pixels
)
2586 GET_CURRENT_CONTEXT(ctx
);
2587 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2588 border
, format
, type
, pixels
);
2593 * Called by the API or display list executor.
2594 * Note that width and height include the border.
2597 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2598 GLsizei width
, GLsizei height
, GLsizei depth
,
2599 GLint border
, GLenum format
, GLenum type
,
2600 const GLvoid
*pixels
)
2602 GET_CURRENT_CONTEXT(ctx
);
2603 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2604 border
, format
, type
, pixels
);
2609 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2610 GLsizei width
, GLsizei height
, GLsizei depth
,
2611 GLint border
, GLenum format
, GLenum type
,
2612 const GLvoid
*pixels
)
2614 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2615 depth
, border
, format
, type
, pixels
);
2619 #if FEATURE_OES_EGL_image
2621 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2623 struct gl_texture_object
*texObj
;
2624 struct gl_texture_image
*texImage
;
2625 GET_CURRENT_CONTEXT(ctx
);
2626 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2628 if ((target
== GL_TEXTURE_2D
&&
2629 !ctx
->Extensions
.OES_EGL_image
) ||
2630 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2631 !ctx
->Extensions
.OES_EGL_image_external
)) {
2632 _mesa_error(ctx
, GL_INVALID_ENUM
,
2633 "glEGLImageTargetTexture2D(target=%d)", target
);
2637 if (ctx
->NewState
& _NEW_PIXEL
)
2638 _mesa_update_state(ctx
);
2640 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2641 _mesa_lock_texture(ctx
, texObj
);
2643 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2645 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2647 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2649 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2650 texObj
, texImage
, image
);
2653 texObj
->_Complete
= GL_FALSE
;
2654 ctx
->NewState
|= _NEW_TEXTURE
;
2656 _mesa_unlock_texture(ctx
, texObj
);
2664 * Implement all the glTexSubImage1/2/3D() functions.
2667 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2668 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2669 GLsizei width
, GLsizei height
, GLsizei depth
,
2670 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2672 struct gl_texture_object
*texObj
;
2673 struct gl_texture_image
*texImage
;
2675 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2677 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2678 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2680 _mesa_lookup_enum_by_nr(target
), level
,
2681 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2682 _mesa_lookup_enum_by_nr(format
),
2683 _mesa_lookup_enum_by_nr(type
), pixels
);
2685 /* check target (proxies not allowed) */
2686 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2687 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2688 dims
, _mesa_lookup_enum_by_nr(target
));
2692 if (ctx
->NewState
& _NEW_PIXEL
)
2693 _mesa_update_state(ctx
);
2695 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2696 width
, height
, depth
, format
, type
)) {
2697 return; /* error was detected */
2700 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2702 _mesa_lock_texture(ctx
, texObj
);
2704 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2706 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2707 xoffset
, yoffset
, zoffset
,
2708 width
, height
, depth
,
2709 format
, type
, texImage
)) {
2710 /* error was recorded */
2712 else if (width
> 0 && height
> 0 && depth
> 0) {
2713 /* If we have a border, offset=-1 is legal. Bias by border width. */
2716 zoffset
+= texImage
->Border
;
2719 yoffset
+= texImage
->Border
;
2722 xoffset
+= texImage
->Border
;
2727 ctx
->Driver
.TexSubImage1D(ctx
, texImage
,
2729 format
, type
, pixels
, &ctx
->Unpack
);
2732 ctx
->Driver
.TexSubImage2D(ctx
, texImage
,
2733 xoffset
, yoffset
, width
, height
,
2734 format
, type
, pixels
, &ctx
->Unpack
);
2737 ctx
->Driver
.TexSubImage3D(ctx
, texImage
,
2738 xoffset
, yoffset
, zoffset
,
2739 width
, height
, depth
,
2740 format
, type
, pixels
, &ctx
->Unpack
);
2743 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2746 check_gen_mipmap(ctx
, target
, texObj
, level
);
2748 ctx
->NewState
|= _NEW_TEXTURE
;
2751 _mesa_unlock_texture(ctx
, texObj
);
2756 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2757 GLint xoffset
, GLsizei width
,
2758 GLenum format
, GLenum type
,
2759 const GLvoid
*pixels
)
2761 GET_CURRENT_CONTEXT(ctx
);
2762 texsubimage(ctx
, 1, target
, level
,
2765 format
, type
, pixels
);
2770 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2771 GLint xoffset
, GLint yoffset
,
2772 GLsizei width
, GLsizei height
,
2773 GLenum format
, GLenum type
,
2774 const GLvoid
*pixels
)
2776 GET_CURRENT_CONTEXT(ctx
);
2777 texsubimage(ctx
, 2, target
, level
,
2778 xoffset
, yoffset
, 0,
2780 format
, type
, pixels
);
2786 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2787 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2788 GLsizei width
, GLsizei height
, GLsizei depth
,
2789 GLenum format
, GLenum type
,
2790 const GLvoid
*pixels
)
2792 GET_CURRENT_CONTEXT(ctx
);
2793 texsubimage(ctx
, 3, target
, level
,
2794 xoffset
, yoffset
, zoffset
,
2795 width
, height
, depth
,
2796 format
, type
, pixels
);
2802 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
2803 * from. This depends on whether the texture contains color or depth values.
2805 static struct gl_renderbuffer
*
2806 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
2808 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
2809 /* reading from depth/stencil buffer */
2810 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
2813 /* copying from color buffer */
2814 return ctx
->ReadBuffer
->_ColorReadBuffer
;
2821 * Implement the glCopyTexImage1/2D() functions.
2824 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2825 GLenum target
, GLint level
, GLenum internalFormat
,
2826 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2828 struct gl_texture_object
*texObj
;
2829 struct gl_texture_image
*texImage
;
2830 const GLuint face
= _mesa_tex_target_to_face(target
);
2832 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2834 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2835 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2837 _mesa_lookup_enum_by_nr(target
), level
,
2838 _mesa_lookup_enum_by_nr(internalFormat
),
2839 x
, y
, width
, height
, border
);
2841 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2842 _mesa_update_state(ctx
);
2844 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2845 width
, height
, border
))
2848 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2850 if (border
&& ctx
->Const
.StripTextureBorder
) {
2852 width
-= border
* 2;
2855 height
-= border
* 2;
2860 _mesa_lock_texture(ctx
, texObj
);
2862 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2865 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2868 /* choose actual hw format */
2869 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2874 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2875 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2877 /* Free old texture image */
2878 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2880 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
2881 border
, internalFormat
, texFormat
);
2883 /* Allocate texture memory (no pixel data yet) */
2885 ctx
->Driver
.TexImage1D(ctx
, texImage
, internalFormat
,
2886 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2890 ctx
->Driver
.TexImage2D(ctx
, texImage
, internalFormat
,
2891 width
, height
, border
, GL_NONE
, GL_NONE
,
2892 NULL
, &ctx
->Unpack
);
2895 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2897 struct gl_renderbuffer
*srcRb
=
2898 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
2901 ctx
->Driver
.CopyTexSubImage1D(ctx
, texImage
, dstX
,
2902 srcRb
, srcX
, srcY
, width
);
2905 ctx
->Driver
.CopyTexSubImage2D(ctx
, texImage
, dstX
, dstY
,
2906 srcRb
, srcX
, srcY
, width
, height
);
2909 check_gen_mipmap(ctx
, target
, texObj
, level
);
2911 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2914 texObj
->_Complete
= GL_FALSE
;
2915 ctx
->NewState
|= _NEW_TEXTURE
;
2918 /* probably too large of image */
2919 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2923 _mesa_unlock_texture(ctx
, texObj
);
2929 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2930 GLenum internalFormat
,
2932 GLsizei width
, GLint border
)
2934 GET_CURRENT_CONTEXT(ctx
);
2935 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2941 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2942 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2945 GET_CURRENT_CONTEXT(ctx
);
2946 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2947 x
, y
, width
, height
, border
);
2953 * Implementation for glCopyTexSubImage1/2/3D() functions.
2956 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2957 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2958 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
2960 struct gl_texture_object
*texObj
;
2961 struct gl_texture_image
*texImage
;
2963 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2965 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2966 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
2968 _mesa_lookup_enum_by_nr(target
),
2969 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
2971 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2972 _mesa_update_state(ctx
);
2974 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
2977 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2979 _mesa_lock_texture(ctx
, texObj
);
2981 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2983 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
2984 zoffset
, width
, height
, texImage
)) {
2985 /* error was recored */
2988 /* If we have a border, offset=-1 is legal. Bias by border width. */
2991 zoffset
+= texImage
->Border
;
2994 yoffset
+= texImage
->Border
;
2997 xoffset
+= texImage
->Border
;
3000 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3002 struct gl_renderbuffer
*srcRb
=
3003 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3007 ctx
->Driver
.CopyTexSubImage1D(ctx
, texImage
, xoffset
,
3008 srcRb
, x
, y
, width
);
3011 ctx
->Driver
.CopyTexSubImage2D(ctx
, texImage
, xoffset
, yoffset
,
3012 srcRb
, x
, y
, width
, height
);
3015 ctx
->Driver
.CopyTexSubImage3D(ctx
, texImage
,
3016 xoffset
, yoffset
, zoffset
,
3017 srcRb
, x
, y
, width
, height
);
3020 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
3023 check_gen_mipmap(ctx
, target
, texObj
, level
);
3025 ctx
->NewState
|= _NEW_TEXTURE
;
3029 _mesa_unlock_texture(ctx
, texObj
);
3034 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3035 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3037 GET_CURRENT_CONTEXT(ctx
);
3038 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3044 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3045 GLint xoffset
, GLint yoffset
,
3046 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3048 GET_CURRENT_CONTEXT(ctx
);
3049 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3056 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3057 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3058 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3060 GET_CURRENT_CONTEXT(ctx
);
3061 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3062 x
, y
, width
, height
);
3068 /**********************************************************************/
3069 /****** Compressed Textures ******/
3070 /**********************************************************************/
3074 * Return expected size of a compressed texture.
3077 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3080 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3081 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3086 * Return compressed texture block size, in pixels.
3089 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3091 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3092 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3097 * Error checking for glCompressedTexImage[123]D().
3098 * \param reason returns reason for error, if any
3099 * \return error code or GL_NO_ERROR.
3102 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3103 GLenum target
, GLint level
,
3104 GLenum internalFormat
, GLsizei width
,
3105 GLsizei height
, GLsizei depth
, GLint border
,
3106 GLsizei imageSize
, char **reason
)
3108 const GLenum proxyTarget
= get_proxy_target(target
);
3109 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3111 GLenum choose_format
;
3113 GLenum proxy_format
;
3115 *reason
= ""; /* no error */
3117 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3119 return GL_INVALID_ENUM
;
3122 /* This will detect any invalid internalFormat value */
3123 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3124 *reason
= "internalFormat";
3125 return GL_INVALID_ENUM
;
3128 switch (internalFormat
) {
3130 case GL_PALETTE4_RGB8_OES
:
3131 case GL_PALETTE4_RGBA8_OES
:
3132 case GL_PALETTE4_R5_G6_B5_OES
:
3133 case GL_PALETTE4_RGBA4_OES
:
3134 case GL_PALETTE4_RGB5_A1_OES
:
3135 case GL_PALETTE8_RGB8_OES
:
3136 case GL_PALETTE8_RGBA8_OES
:
3137 case GL_PALETTE8_R5_G6_B5_OES
:
3138 case GL_PALETTE8_RGBA4_OES
:
3139 case GL_PALETTE8_RGB5_A1_OES
:
3140 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3142 proxy_format
= choose_format
;
3145 if (level
> 0 || level
< -maxLevels
) {
3147 return GL_INVALID_VALUE
;
3150 if (dimensions
!= 2) {
3151 *reason
= "compressed paletted textures must be 2D";
3152 return GL_INVALID_OPERATION
;
3155 /* Figure out the expected texture size (in bytes). This will be
3156 * checked against the actual size later.
3158 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3161 /* This is for the benefit of the TestProxyTexImage below. It expects
3162 * level to be non-negative. OES_compressed_paletted_texture uses a
3163 * weird mechanism where the level specified to glCompressedTexImage2D
3164 * is -(n-1) number of levels in the texture, and the data specifies the
3165 * complete mipmap stack. This is done to ensure the palette is the
3166 * same for all levels.
3173 choose_format
= GL_NONE
;
3174 choose_type
= GL_NONE
;
3175 proxy_format
= internalFormat
;
3178 if (level
< 0 || level
>= maxLevels
) {
3180 return GL_INVALID_VALUE
;
3183 /* Figure out the expected texture size (in bytes). This will be
3184 * checked against the actual size later.
3186 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3190 /* This should really never fail */
3191 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3192 *reason
= "internalFormat";
3193 return GL_INVALID_ENUM
;
3196 /* No compressed formats support borders at this time */
3198 *reason
= "border != 0";
3199 return GL_INVALID_VALUE
;
3202 /* For cube map, width must equal height */
3203 if (_mesa_is_cube_face(target
) && width
!= height
) {
3204 *reason
= "width != height";
3205 return GL_INVALID_VALUE
;
3208 /* check image size against compression block size */
3210 gl_format texFormat
=
3211 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3212 choose_format
, choose_type
);
3215 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3216 if ((width
> bw
&& width
% bw
> 0) ||
3217 (height
> bh
&& height
% bh
> 0)) {
3219 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3220 * generated [...] if any parameter combinations are not
3221 * supported by the specific compressed internal format.
3223 *reason
= "invalid width or height for compression format";
3224 return GL_INVALID_OPERATION
;
3228 /* check image sizes */
3229 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3230 proxy_format
, choose_format
,
3232 width
, height
, depth
, border
)) {
3233 /* See error comment above */
3234 *reason
= "invalid width, height or format";
3235 return GL_INVALID_OPERATION
;
3238 /* check image size in bytes */
3239 if (expectedSize
!= imageSize
) {
3240 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3241 * if <imageSize> is not consistent with the format, dimensions, and
3242 * contents of the specified image.
3244 *reason
= "imageSize inconsistant with width/height/format";
3245 return GL_INVALID_VALUE
;
3248 if (!mutable_tex_object(ctx
, target
)) {
3249 *reason
= "immutable texture";
3250 return GL_INVALID_OPERATION
;
3258 * Error checking for glCompressedTexSubImage[123]D().
3259 * \warning There are some bad assumptions here about the size of compressed
3260 * texture tiles (multiple of 4) used to test the validity of the
3261 * offset and size parameters.
3262 * \return error code or GL_NO_ERROR.
3265 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3266 GLenum target
, GLint level
,
3267 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3268 GLsizei width
, GLsizei height
, GLsizei depth
,
3269 GLenum format
, GLsizei imageSize
)
3271 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3275 if (dimensions
== 1) {
3276 /* 1D compressed textures not allowed */
3277 return GL_INVALID_ENUM
;
3279 else if (dimensions
== 2) {
3280 if (target
== GL_PROXY_TEXTURE_2D
) {
3281 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3283 else if (target
== GL_TEXTURE_2D
) {
3284 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3286 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3287 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3288 return GL_INVALID_ENUM
; /*target*/
3289 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3291 else if (_mesa_is_cube_face(target
)) {
3292 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3293 return GL_INVALID_ENUM
; /*target*/
3294 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3297 return GL_INVALID_ENUM
; /*target*/
3300 else if (dimensions
== 3) {
3301 /* 3D compressed textures not allowed */
3302 return GL_INVALID_ENUM
;
3305 maxTextureSize
= 1 << (maxLevels
- 1);
3307 /* this will catch any invalid compressed format token */
3308 if (!_mesa_is_compressed_format(ctx
, format
))
3309 return GL_INVALID_ENUM
;
3311 if (width
< 1 || width
> maxTextureSize
)
3312 return GL_INVALID_VALUE
;
3314 if ((height
< 1 || height
> maxTextureSize
)
3316 return GL_INVALID_VALUE
;
3318 if (level
< 0 || level
>= maxLevels
)
3319 return GL_INVALID_VALUE
;
3322 * do checks which depend on compression block size
3324 get_compressed_block_size(format
, &bw
, &bh
);
3326 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3327 return GL_INVALID_VALUE
;
3329 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3330 return GL_INVALID_VALUE
;
3332 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3333 return GL_INVALID_VALUE
;
3335 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3336 if (expectedSize
!= imageSize
)
3337 return GL_INVALID_VALUE
;
3344 * Do second part of glCompressedTexSubImage error checking.
3345 * \return GL_TRUE if error found, GL_FALSE otherwise.
3348 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3349 GLsizei width
, GLsizei height
,
3350 GLsizei depth
, GLenum format
,
3351 struct gl_texture_image
*texImage
)
3354 if ((GLint
) format
!= texImage
->InternalFormat
) {
3355 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3356 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3360 if (((width
== 1 || width
== 2) &&
3361 width
!= (GLsizei
) texImage
->Width
) ||
3362 (width
> (GLsizei
) texImage
->Width
)) {
3363 _mesa_error(ctx
, GL_INVALID_VALUE
,
3364 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3369 if (((height
== 1 || height
== 2) &&
3370 height
!= (GLsizei
) texImage
->Height
) ||
3371 (height
> (GLsizei
) texImage
->Height
)) {
3372 _mesa_error(ctx
, GL_INVALID_VALUE
,
3373 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3379 if (((depth
== 1 || depth
== 2) &&
3380 depth
!= (GLsizei
) texImage
->Depth
) ||
3381 (depth
> (GLsizei
) texImage
->Depth
)) {
3382 _mesa_error(ctx
, GL_INVALID_VALUE
,
3383 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3393 * Implementation of the glCompressedTexImage1/2/3D() functions.
3396 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3397 GLenum target
, GLint level
,
3398 GLenum internalFormat
, GLsizei width
,
3399 GLsizei height
, GLsizei depth
, GLint border
,
3400 GLsizei imageSize
, const GLvoid
*data
)
3405 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3407 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3409 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3411 _mesa_lookup_enum_by_nr(target
), level
,
3412 _mesa_lookup_enum_by_nr(internalFormat
),
3413 width
, height
, depth
, border
, imageSize
, data
);
3416 if (!legal_teximage_target(ctx
, dims
, target
)) {
3417 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3418 dims
, _mesa_lookup_enum_by_nr(target
));
3422 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3423 internalFormat
, width
, height
, depth
,
3424 border
, imageSize
, &reason
);
3427 /* XXX this is kind of a hack */
3428 if (!error
&& dims
== 2) {
3429 switch (internalFormat
) {
3430 case GL_PALETTE4_RGB8_OES
:
3431 case GL_PALETTE4_RGBA8_OES
:
3432 case GL_PALETTE4_R5_G6_B5_OES
:
3433 case GL_PALETTE4_RGBA4_OES
:
3434 case GL_PALETTE4_RGB5_A1_OES
:
3435 case GL_PALETTE8_RGB8_OES
:
3436 case GL_PALETTE8_RGBA8_OES
:
3437 case GL_PALETTE8_R5_G6_B5_OES
:
3438 case GL_PALETTE8_RGBA4_OES
:
3439 case GL_PALETTE8_RGB5_A1_OES
:
3440 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3441 width
, height
, imageSize
, data
);
3447 if (_mesa_is_proxy_texture(target
)) {
3448 /* Proxy texture: just check for errors and update proxy state */
3449 struct gl_texture_image
*texImage
;
3452 struct gl_texture_object
*texObj
=
3453 _mesa_get_current_tex_object(ctx
, target
);
3454 gl_format texFormat
=
3455 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3456 internalFormat
, GL_NONE
, GL_NONE
);
3457 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3458 error
= GL_OUT_OF_MEMORY
;
3462 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3465 /* if error, clear all proxy texture image parameters */
3466 clear_teximage_fields(texImage
);
3469 /* no error: store the teximage parameters */
3470 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
3471 depth
, border
, internalFormat
,
3477 /* non-proxy target */
3478 struct gl_texture_object
*texObj
;
3479 struct gl_texture_image
*texImage
;
3482 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3486 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3488 _mesa_lock_texture(ctx
, texObj
);
3490 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3492 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3493 "glCompressedTexImage%uD", dims
);
3496 gl_format texFormat
;
3498 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3500 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3501 internalFormat
, GL_NONE
,
3504 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3505 _mesa_init_teximage_fields(ctx
, texImage
,
3506 width
, height
, depth
,
3507 border
, internalFormat
, texFormat
);
3511 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3512 ctx
->Driver
.CompressedTexImage1D(ctx
, texImage
,
3515 border
, imageSize
, data
);
3518 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3519 ctx
->Driver
.CompressedTexImage2D(ctx
, texImage
,
3522 border
, imageSize
, data
);
3525 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3526 ctx
->Driver
.CompressedTexImage3D(ctx
, texImage
,
3528 width
, height
, depth
,
3529 border
, imageSize
, data
);
3532 _mesa_problem(ctx
, "bad dims in compressedteximage");
3535 check_gen_mipmap(ctx
, target
, texObj
, level
);
3538 texObj
->_Complete
= GL_FALSE
;
3539 ctx
->NewState
|= _NEW_TEXTURE
;
3542 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3543 "glCompressedTexImage%uD", dims
);
3547 _mesa_unlock_texture(ctx
, texObj
);
3553 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3554 GLenum internalFormat
, GLsizei width
,
3555 GLint border
, GLsizei imageSize
,
3558 GET_CURRENT_CONTEXT(ctx
);
3559 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3560 width
, 1, 1, border
, imageSize
, data
);
3565 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3566 GLenum internalFormat
, GLsizei width
,
3567 GLsizei height
, GLint border
, GLsizei imageSize
,
3570 GET_CURRENT_CONTEXT(ctx
);
3571 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3572 width
, height
, 1, border
, imageSize
, data
);
3577 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3578 GLenum internalFormat
, GLsizei width
,
3579 GLsizei height
, GLsizei depth
, GLint border
,
3580 GLsizei imageSize
, const GLvoid
*data
)
3582 GET_CURRENT_CONTEXT(ctx
);
3583 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3584 width
, height
, depth
, border
, imageSize
, data
);
3589 * Common helper for glCompressedTexSubImage1/2/3D().
3592 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3593 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3594 GLsizei width
, GLsizei height
, GLsizei depth
,
3595 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3597 struct gl_texture_object
*texObj
;
3598 struct gl_texture_image
*texImage
;
3600 GET_CURRENT_CONTEXT(ctx
);
3601 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3603 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3604 xoffset
, 0, 0, /* pos */
3605 width
, height
, depth
, /* size */
3608 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3612 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3614 _mesa_lock_texture(ctx
, texObj
);
3616 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3619 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3620 format
, texImage
)) {
3621 /* error was recorded */
3623 else if (width
> 0 && height
> 0 && depth
> 0) {
3626 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3627 ctx
->Driver
.CompressedTexSubImage1D(ctx
, texImage
,
3629 format
, imageSize
, data
);
3633 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3634 ctx
->Driver
.CompressedTexSubImage2D(ctx
, texImage
,
3637 format
, imageSize
, data
);
3641 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3642 ctx
->Driver
.CompressedTexSubImage3D(ctx
, texImage
,
3643 xoffset
, yoffset
, zoffset
,
3644 width
, height
, depth
,
3645 format
, imageSize
, data
);
3652 check_gen_mipmap(ctx
, target
, texObj
, level
);
3654 ctx
->NewState
|= _NEW_TEXTURE
;
3657 _mesa_unlock_texture(ctx
, texObj
);
3662 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3663 GLsizei width
, GLenum format
,
3664 GLsizei imageSize
, const GLvoid
*data
)
3666 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3667 format
, imageSize
, data
);
3672 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3673 GLint yoffset
, GLsizei width
, GLsizei height
,
3674 GLenum format
, GLsizei imageSize
,
3677 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3678 width
, height
, 1, format
, imageSize
, data
);
3683 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3684 GLint yoffset
, GLint zoffset
, GLsizei width
,
3685 GLsizei height
, GLsizei depth
, GLenum format
,
3686 GLsizei imageSize
, const GLvoid
*data
)
3688 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3689 width
, height
, depth
, format
, imageSize
, data
);
3694 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3695 * return the basic data type and number of components for the format.
3696 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3699 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3700 GLenum
*datatype
, GLuint
*components
)
3702 switch (internalFormat
) {
3704 *datatype
= GL_UNSIGNED_BYTE
;
3708 *datatype
= GL_UNSIGNED_SHORT
;
3711 case GL_ALPHA16F_ARB
:
3712 *datatype
= GL_HALF_FLOAT
;
3715 case GL_ALPHA32F_ARB
:
3716 *datatype
= GL_FLOAT
;
3719 case GL_ALPHA8I_EXT
:
3720 *datatype
= GL_BYTE
;
3723 case GL_ALPHA16I_EXT
:
3724 *datatype
= GL_SHORT
;
3727 case GL_ALPHA32I_EXT
:
3731 case GL_ALPHA8UI_EXT
:
3732 *datatype
= GL_UNSIGNED_BYTE
;
3735 case GL_ALPHA16UI_EXT
:
3736 *datatype
= GL_UNSIGNED_SHORT
;
3739 case GL_ALPHA32UI_EXT
:
3740 *datatype
= GL_UNSIGNED_INT
;
3744 *datatype
= GL_UNSIGNED_BYTE
;
3747 case GL_LUMINANCE16
:
3748 *datatype
= GL_UNSIGNED_SHORT
;
3751 case GL_LUMINANCE16F_ARB
:
3752 *datatype
= GL_HALF_FLOAT
;
3755 case GL_LUMINANCE32F_ARB
:
3756 *datatype
= GL_FLOAT
;
3759 case GL_LUMINANCE8I_EXT
:
3760 *datatype
= GL_BYTE
;
3763 case GL_LUMINANCE16I_EXT
:
3764 *datatype
= GL_SHORT
;
3767 case GL_LUMINANCE32I_EXT
:
3771 case GL_LUMINANCE8UI_EXT
:
3772 *datatype
= GL_UNSIGNED_BYTE
;
3775 case GL_LUMINANCE16UI_EXT
:
3776 *datatype
= GL_UNSIGNED_SHORT
;
3779 case GL_LUMINANCE32UI_EXT
:
3780 *datatype
= GL_UNSIGNED_INT
;
3783 case GL_LUMINANCE8_ALPHA8
:
3784 *datatype
= GL_UNSIGNED_BYTE
;
3787 case GL_LUMINANCE16_ALPHA16
:
3788 *datatype
= GL_UNSIGNED_SHORT
;
3791 case GL_LUMINANCE_ALPHA16F_ARB
:
3792 *datatype
= GL_HALF_FLOAT
;
3795 case GL_LUMINANCE_ALPHA32F_ARB
:
3796 *datatype
= GL_FLOAT
;
3799 case GL_LUMINANCE_ALPHA8I_EXT
:
3800 *datatype
= GL_BYTE
;
3803 case GL_LUMINANCE_ALPHA16I_EXT
:
3804 *datatype
= GL_SHORT
;
3807 case GL_LUMINANCE_ALPHA32I_EXT
:
3811 case GL_LUMINANCE_ALPHA8UI_EXT
:
3812 *datatype
= GL_UNSIGNED_BYTE
;
3815 case GL_LUMINANCE_ALPHA16UI_EXT
:
3816 *datatype
= GL_UNSIGNED_SHORT
;
3819 case GL_LUMINANCE_ALPHA32UI_EXT
:
3820 *datatype
= GL_UNSIGNED_INT
;
3824 *datatype
= GL_UNSIGNED_BYTE
;
3827 case GL_INTENSITY16
:
3828 *datatype
= GL_UNSIGNED_SHORT
;
3831 case GL_INTENSITY16F_ARB
:
3832 *datatype
= GL_HALF_FLOAT
;
3835 case GL_INTENSITY32F_ARB
:
3836 *datatype
= GL_FLOAT
;
3839 case GL_INTENSITY8I_EXT
:
3840 *datatype
= GL_BYTE
;
3843 case GL_INTENSITY16I_EXT
:
3844 *datatype
= GL_SHORT
;
3847 case GL_INTENSITY32I_EXT
:
3851 case GL_INTENSITY8UI_EXT
:
3852 *datatype
= GL_UNSIGNED_BYTE
;
3855 case GL_INTENSITY16UI_EXT
:
3856 *datatype
= GL_UNSIGNED_SHORT
;
3859 case GL_INTENSITY32UI_EXT
:
3860 *datatype
= GL_UNSIGNED_INT
;
3864 *datatype
= GL_UNSIGNED_BYTE
;
3868 *datatype
= GL_UNSIGNED_SHORT
;
3871 case GL_RGBA16F_ARB
:
3872 *datatype
= GL_HALF_FLOAT
;
3875 case GL_RGBA32F_ARB
:
3876 *datatype
= GL_FLOAT
;
3880 *datatype
= GL_BYTE
;
3883 case GL_RGBA16I_EXT
:
3884 *datatype
= GL_SHORT
;
3887 case GL_RGBA32I_EXT
:
3891 case GL_RGBA8UI_EXT
:
3892 *datatype
= GL_UNSIGNED_BYTE
;
3895 case GL_RGBA16UI_EXT
:
3896 *datatype
= GL_UNSIGNED_SHORT
;
3899 case GL_RGBA32UI_EXT
:
3900 *datatype
= GL_UNSIGNED_INT
;
3907 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3910 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3917 /** GL_ARB_texture_buffer_object */
3919 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3921 struct gl_texture_object
*texObj
;
3922 struct gl_buffer_object
*bufObj
;
3926 GET_CURRENT_CONTEXT(ctx
);
3927 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3929 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3930 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3934 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3935 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3939 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
3940 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3945 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3946 if (buffer
&& !bufObj
) {
3947 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3951 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3953 _mesa_lock_texture(ctx
, texObj
);
3955 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3956 texObj
->BufferObjectFormat
= internalFormat
;
3958 _mesa_unlock_texture(ctx
, texObj
);