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"
45 #include "texcompress_cpal.h"
50 #include "glformats.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
63 * Return the simple base format for a given internal texture format.
64 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
66 * \param ctx GL context.
67 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
69 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
70 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
72 * This is the format which is used during texture application (i.e. the
73 * texture format and env mode determine the arithmetic used.
76 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
78 switch (internalFormat
) {
84 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
91 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
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 (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
106 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
108 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
119 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
133 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
135 if (_mesa_is_gles(ctx
)) {
136 switch (internalFormat
) {
144 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
145 switch (internalFormat
) {
153 if (ctx
->Extensions
.ARB_depth_texture
) {
154 switch (internalFormat
) {
155 case GL_DEPTH_COMPONENT
:
156 case GL_DEPTH_COMPONENT16
:
157 case GL_DEPTH_COMPONENT24
:
158 case GL_DEPTH_COMPONENT32
:
159 return GL_DEPTH_COMPONENT
;
165 switch (internalFormat
) {
166 case GL_COMPRESSED_ALPHA
:
168 case GL_COMPRESSED_LUMINANCE
:
170 case GL_COMPRESSED_LUMINANCE_ALPHA
:
171 return GL_LUMINANCE_ALPHA
;
172 case GL_COMPRESSED_INTENSITY
:
174 case GL_COMPRESSED_RGB
:
176 case GL_COMPRESSED_RGBA
:
182 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
183 switch (internalFormat
) {
184 case GL_COMPRESSED_RGB_FXT1_3DFX
:
186 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
193 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
194 switch (internalFormat
) {
195 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
197 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
198 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
199 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
206 /* GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE && GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE */
207 if (ctx
->API
== API_OPENGLES2
&&
208 ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
209 switch (internalFormat
) {
210 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
211 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
218 if (ctx
->Extensions
.S3_s3tc
) {
219 switch (internalFormat
) {
231 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
232 if (internalFormat
== GL_YCBCR_MESA
)
233 return GL_YCBCR_MESA
;
236 if (ctx
->Extensions
.ARB_texture_float
) {
237 switch (internalFormat
) {
238 case GL_ALPHA16F_ARB
:
239 case GL_ALPHA32F_ARB
:
247 case GL_INTENSITY16F_ARB
:
248 case GL_INTENSITY32F_ARB
:
250 case GL_LUMINANCE16F_ARB
:
251 case GL_LUMINANCE32F_ARB
:
253 case GL_LUMINANCE_ALPHA16F_ARB
:
254 case GL_LUMINANCE_ALPHA32F_ARB
:
255 return GL_LUMINANCE_ALPHA
;
261 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
262 switch (internalFormat
) {
271 if (ctx
->Extensions
.EXT_texture_snorm
) {
272 switch (internalFormat
) {
287 case GL_RGBA16_SNORM
:
290 case GL_ALPHA8_SNORM
:
291 case GL_ALPHA16_SNORM
:
293 case GL_LUMINANCE_SNORM
:
294 case GL_LUMINANCE8_SNORM
:
295 case GL_LUMINANCE16_SNORM
:
297 case GL_LUMINANCE_ALPHA_SNORM
:
298 case GL_LUMINANCE8_ALPHA8_SNORM
:
299 case GL_LUMINANCE16_ALPHA16_SNORM
:
300 return GL_LUMINANCE_ALPHA
;
301 case GL_INTENSITY_SNORM
:
302 case GL_INTENSITY8_SNORM
:
303 case GL_INTENSITY16_SNORM
:
310 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
311 switch (internalFormat
) {
312 case GL_DEPTH_STENCIL_EXT
:
313 case GL_DEPTH24_STENCIL8_EXT
:
314 return GL_DEPTH_STENCIL_EXT
;
320 if (ctx
->Extensions
.EXT_texture_sRGB
) {
321 switch (internalFormat
) {
324 case GL_COMPRESSED_SRGB_EXT
:
325 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
327 case GL_SRGB_ALPHA_EXT
:
328 case GL_SRGB8_ALPHA8_EXT
:
329 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
330 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
331 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
332 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
334 case GL_SLUMINANCE_ALPHA_EXT
:
335 case GL_SLUMINANCE8_ALPHA8_EXT
:
336 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
337 return GL_LUMINANCE_ALPHA
;
338 case GL_SLUMINANCE_EXT
:
339 case GL_SLUMINANCE8_EXT
:
340 case GL_COMPRESSED_SLUMINANCE_EXT
:
347 if (ctx
->Version
>= 30 ||
348 ctx
->Extensions
.EXT_texture_integer
) {
349 switch (internalFormat
) {
351 case GL_RGBA16UI_EXT
:
352 case GL_RGBA32UI_EXT
:
368 if (ctx
->Extensions
.EXT_texture_integer
) {
369 switch (internalFormat
) {
370 case GL_ALPHA8UI_EXT
:
371 case GL_ALPHA16UI_EXT
:
372 case GL_ALPHA32UI_EXT
:
374 case GL_ALPHA16I_EXT
:
375 case GL_ALPHA32I_EXT
:
377 case GL_INTENSITY8UI_EXT
:
378 case GL_INTENSITY16UI_EXT
:
379 case GL_INTENSITY32UI_EXT
:
380 case GL_INTENSITY8I_EXT
:
381 case GL_INTENSITY16I_EXT
:
382 case GL_INTENSITY32I_EXT
:
384 case GL_LUMINANCE8UI_EXT
:
385 case GL_LUMINANCE16UI_EXT
:
386 case GL_LUMINANCE32UI_EXT
:
387 case GL_LUMINANCE8I_EXT
:
388 case GL_LUMINANCE16I_EXT
:
389 case GL_LUMINANCE32I_EXT
:
391 case GL_LUMINANCE_ALPHA8UI_EXT
:
392 case GL_LUMINANCE_ALPHA16UI_EXT
:
393 case GL_LUMINANCE_ALPHA32UI_EXT
:
394 case GL_LUMINANCE_ALPHA8I_EXT
:
395 case GL_LUMINANCE_ALPHA16I_EXT
:
396 case GL_LUMINANCE_ALPHA32I_EXT
:
397 return GL_LUMINANCE_ALPHA
;
403 if (ctx
->Extensions
.ARB_texture_rg
) {
404 switch (internalFormat
) {
406 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
408 if (!ctx
->Extensions
.ARB_half_float_pixel
)
412 if (!ctx
->Extensions
.ARB_texture_float
)
421 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
427 case GL_COMPRESSED_RED
:
431 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
433 if (!ctx
->Extensions
.ARB_half_float_pixel
)
437 if (!ctx
->Extensions
.ARB_texture_float
)
446 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
452 case GL_COMPRESSED_RG
:
459 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
460 switch (internalFormat
) {
468 if (ctx
->Extensions
.EXT_packed_float
) {
469 switch (internalFormat
) {
470 case GL_R11F_G11F_B10F_EXT
:
477 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
478 switch (internalFormat
) {
479 case GL_DEPTH_COMPONENT32F
:
480 return GL_DEPTH_COMPONENT
;
481 case GL_DEPTH32F_STENCIL8
:
482 return GL_DEPTH_STENCIL
;
488 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
489 switch (internalFormat
) {
490 case GL_COMPRESSED_RED_RGTC1
:
491 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
493 case GL_COMPRESSED_RG_RGTC2
:
494 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
501 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
502 switch (internalFormat
) {
503 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
504 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
506 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
507 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
508 return GL_LUMINANCE_ALPHA
;
514 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
515 switch (internalFormat
) {
516 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
517 return GL_LUMINANCE_ALPHA
;
523 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
524 switch (internalFormat
) {
525 case GL_ETC1_RGB8_OES
:
532 if (ctx
->API
== API_OPENGLES
) {
533 switch (internalFormat
) {
534 case GL_PALETTE4_RGB8_OES
:
535 case GL_PALETTE4_R5_G6_B5_OES
:
536 case GL_PALETTE8_RGB8_OES
:
537 case GL_PALETTE8_R5_G6_B5_OES
:
539 case GL_PALETTE4_RGBA8_OES
:
540 case GL_PALETTE8_RGB5_A1_OES
:
541 case GL_PALETTE4_RGBA4_OES
:
542 case GL_PALETTE4_RGB5_A1_OES
:
543 case GL_PALETTE8_RGBA8_OES
:
544 case GL_PALETTE8_RGBA4_OES
:
551 return -1; /* error */
556 * For cube map faces, return a face index in [0,5].
557 * For other targets return 0;
560 _mesa_tex_target_to_face(GLenum target
)
562 if (_mesa_is_cube_face(target
))
563 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
571 * Install gl_texture_image in a gl_texture_object according to the target
572 * and level parameters.
574 * \param tObj texture object.
575 * \param target texture target.
576 * \param level image level.
577 * \param texImage texture image.
580 set_tex_image(struct gl_texture_object
*tObj
,
581 GLenum target
, GLint level
,
582 struct gl_texture_image
*texImage
)
584 const GLuint face
= _mesa_tex_target_to_face(target
);
588 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
591 tObj
->Image
[face
][level
] = texImage
;
593 /* Set the 'back' pointer */
594 texImage
->TexObject
= tObj
;
595 texImage
->Level
= level
;
596 texImage
->Face
= face
;
601 * Allocate a texture image structure.
603 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
606 * \return a pointer to gl_texture_image struct with all fields initialized to
609 struct gl_texture_image
*
610 _mesa_new_texture_image( struct gl_context
*ctx
)
613 return CALLOC_STRUCT(gl_texture_image
);
618 * Free a gl_texture_image and associated data.
619 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
621 * \param texImage texture image.
623 * Free the texture image structure and the associated image data.
626 _mesa_delete_texture_image(struct gl_context
*ctx
,
627 struct gl_texture_image
*texImage
)
629 /* Free texImage->Data and/or any other driver-specific texture
632 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
633 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
639 * Test if a target is a proxy target.
641 * \param target texture target.
643 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
646 _mesa_is_proxy_texture(GLenum target
)
649 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
650 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
652 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
654 return (target
== GL_PROXY_TEXTURE_1D
||
655 target
== GL_PROXY_TEXTURE_2D
||
656 target
== GL_PROXY_TEXTURE_3D
||
657 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
658 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
659 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
660 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
665 * Return the proxy target which corresponds to the given texture target
668 _mesa_get_proxy_target(GLenum target
)
672 case GL_PROXY_TEXTURE_1D
:
673 return GL_PROXY_TEXTURE_1D
;
675 case GL_PROXY_TEXTURE_2D
:
676 return GL_PROXY_TEXTURE_2D
;
678 case GL_PROXY_TEXTURE_3D
:
679 return GL_PROXY_TEXTURE_3D
;
680 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
681 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
682 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
683 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
684 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
685 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
686 case GL_TEXTURE_CUBE_MAP_ARB
:
687 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
688 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
689 case GL_TEXTURE_RECTANGLE_NV
:
690 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
691 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
692 case GL_TEXTURE_1D_ARRAY_EXT
:
693 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
694 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
695 case GL_TEXTURE_2D_ARRAY_EXT
:
696 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
697 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
699 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
706 * Get the texture object that corresponds to the target of the given
707 * texture unit. The target should have already been checked for validity.
709 * \param ctx GL context.
710 * \param texUnit texture unit.
711 * \param target texture target.
713 * \return pointer to the texture object on success, or NULL on failure.
715 struct gl_texture_object
*
716 _mesa_select_tex_object(struct gl_context
*ctx
,
717 const struct gl_texture_unit
*texUnit
,
720 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
721 ctx
->Extensions
.EXT_texture_array
);
725 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
726 case GL_PROXY_TEXTURE_1D
:
727 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
729 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
730 case GL_PROXY_TEXTURE_2D
:
731 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
733 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
734 case GL_PROXY_TEXTURE_3D
:
735 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
736 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
737 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
738 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
739 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
740 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
741 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
742 case GL_TEXTURE_CUBE_MAP_ARB
:
743 return ctx
->Extensions
.ARB_texture_cube_map
744 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
745 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
746 return ctx
->Extensions
.ARB_texture_cube_map
747 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
748 case GL_TEXTURE_RECTANGLE_NV
:
749 return ctx
->Extensions
.NV_texture_rectangle
750 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
751 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
752 return ctx
->Extensions
.NV_texture_rectangle
753 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
754 case GL_TEXTURE_1D_ARRAY_EXT
:
755 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
756 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
757 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
758 case GL_TEXTURE_2D_ARRAY_EXT
:
759 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
760 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
761 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
762 case GL_TEXTURE_BUFFER
:
763 return _mesa_is_desktop_gl(ctx
)
764 && ctx
->Extensions
.ARB_texture_buffer_object
765 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
766 case GL_TEXTURE_EXTERNAL_OES
:
767 return ctx
->Extensions
.OES_EGL_image_external
768 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
770 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
777 * Return pointer to texture object for given target on current texture unit.
779 struct gl_texture_object
*
780 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
782 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
783 return _mesa_select_tex_object(ctx
, texUnit
, target
);
788 * Get a texture image pointer from a texture object, given a texture
789 * target and mipmap level. The target and level parameters should
790 * have already been error-checked.
792 * \param ctx GL context.
793 * \param texObj texture unit.
794 * \param target texture target.
795 * \param level image level.
797 * \return pointer to the texture image structure, or NULL on failure.
799 struct gl_texture_image
*
800 _mesa_select_tex_image(struct gl_context
*ctx
,
801 const struct gl_texture_object
*texObj
,
802 GLenum target
, GLint level
)
804 const GLuint face
= _mesa_tex_target_to_face(target
);
808 ASSERT(level
< MAX_TEXTURE_LEVELS
);
810 return texObj
->Image
[face
][level
];
815 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
816 * it and install it. Only return NULL if passed a bad parameter or run
819 struct gl_texture_image
*
820 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
821 GLenum target
, GLint level
)
823 struct gl_texture_image
*texImage
;
828 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
830 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
832 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
836 set_tex_image(texObj
, target
, level
, texImage
);
844 * Return pointer to the specified proxy texture image.
845 * Note that proxy textures are per-context, not per-texture unit.
846 * \return pointer to texture image or NULL if invalid target, invalid
847 * level, or out of memory.
849 static struct gl_texture_image
*
850 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
852 struct gl_texture_image
*texImage
;
859 case GL_PROXY_TEXTURE_1D
:
860 if (level
>= ctx
->Const
.MaxTextureLevels
)
862 texIndex
= TEXTURE_1D_INDEX
;
864 case GL_PROXY_TEXTURE_2D
:
865 if (level
>= ctx
->Const
.MaxTextureLevels
)
867 texIndex
= TEXTURE_2D_INDEX
;
869 case GL_PROXY_TEXTURE_3D
:
870 if (level
>= ctx
->Const
.Max3DTextureLevels
)
872 texIndex
= TEXTURE_3D_INDEX
;
874 case GL_PROXY_TEXTURE_CUBE_MAP
:
875 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
877 texIndex
= TEXTURE_CUBE_INDEX
;
879 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
882 texIndex
= TEXTURE_RECT_INDEX
;
884 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
885 if (level
>= ctx
->Const
.MaxTextureLevels
)
887 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
889 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
890 if (level
>= ctx
->Const
.MaxTextureLevels
)
892 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
898 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
900 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
902 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
905 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
906 /* Set the 'back' pointer */
907 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
914 * Get the maximum number of allowed mipmap levels.
916 * \param ctx GL context.
917 * \param target texture target.
919 * \return the maximum number of allowed mipmap levels for the given
920 * texture target, or zero if passed a bad target.
925 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
929 case GL_PROXY_TEXTURE_1D
:
931 case GL_PROXY_TEXTURE_2D
:
932 return ctx
->Const
.MaxTextureLevels
;
934 case GL_PROXY_TEXTURE_3D
:
935 return ctx
->Const
.Max3DTextureLevels
;
936 case GL_TEXTURE_CUBE_MAP
:
937 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
938 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
939 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
940 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
941 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
942 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
943 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
944 return ctx
->Extensions
.ARB_texture_cube_map
945 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
946 case GL_TEXTURE_RECTANGLE_NV
:
947 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
948 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
949 case GL_TEXTURE_1D_ARRAY_EXT
:
950 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
951 case GL_TEXTURE_2D_ARRAY_EXT
:
952 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
953 return (ctx
->Extensions
.MESA_texture_array
||
954 ctx
->Extensions
.EXT_texture_array
)
955 ? ctx
->Const
.MaxTextureLevels
: 0;
956 case GL_TEXTURE_BUFFER
:
957 return _mesa_is_desktop_gl(ctx
)
958 && ctx
->Extensions
.ARB_texture_buffer_object
960 case GL_TEXTURE_EXTERNAL_OES
:
963 return 0; /* bad target */
969 * Return number of dimensions per mipmap level for the given texture target.
972 _mesa_get_texture_dimensions(GLenum target
)
976 case GL_PROXY_TEXTURE_1D
:
979 case GL_TEXTURE_RECTANGLE
:
980 case GL_TEXTURE_CUBE_MAP
:
981 case GL_PROXY_TEXTURE_2D
:
982 case GL_PROXY_TEXTURE_RECTANGLE
:
983 case GL_PROXY_TEXTURE_CUBE_MAP
:
984 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
985 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
986 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
987 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
988 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
989 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
990 case GL_TEXTURE_1D_ARRAY
:
991 case GL_PROXY_TEXTURE_1D_ARRAY
:
992 case GL_TEXTURE_EXTERNAL_OES
:
995 case GL_PROXY_TEXTURE_3D
:
996 case GL_TEXTURE_2D_ARRAY
:
997 case GL_PROXY_TEXTURE_2D_ARRAY
:
999 case GL_TEXTURE_BUFFER
:
1002 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1011 #if 000 /* not used anymore */
1013 * glTexImage[123]D can accept a NULL image pointer. In this case we
1014 * create a texture image with unspecified image contents per the OpenGL
1018 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1020 const GLint components
= _mesa_components_in_format(format
);
1021 const GLint numPixels
= width
* height
* depth
;
1022 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1026 * Let's see if anyone finds this. If glTexImage2D() is called with
1027 * a NULL image pointer then load the texture image with something
1028 * interesting instead of leaving it indeterminate.
1031 static const char message
[8][32] = {
1032 " X X XXXXX XXX X ",
1033 " XX XX X X X X X ",
1035 " X X XXXX XXX XXXXX ",
1038 " X X XXXXX XXX X X ",
1042 GLubyte
*imgPtr
= data
;
1044 for (h
= 0; h
< depth
; h
++) {
1045 for (i
= 0; i
< height
; i
++) {
1046 GLint srcRow
= 7 - (i
% 8);
1047 for (j
= 0; j
< width
; j
++) {
1048 GLint srcCol
= j
% 32;
1049 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1050 for (k
= 0; k
< components
; k
++) {
1066 * Set the size and format-related fields of a gl_texture_image struct
1067 * to zero. This is used when a proxy texture test fails.
1070 clear_teximage_fields(struct gl_texture_image
*img
)
1073 img
->_BaseFormat
= 0;
1074 img
->InternalFormat
= 0;
1083 img
->HeightLog2
= 0;
1085 img
->TexFormat
= MESA_FORMAT_NONE
;
1090 * Initialize basic fields of the gl_texture_image struct.
1092 * \param ctx GL context.
1093 * \param img texture image structure to be initialized.
1094 * \param width image width.
1095 * \param height image height.
1096 * \param depth image depth.
1097 * \param border image border.
1098 * \param internalFormat internal format.
1099 * \param format the actual hardware format (one of MESA_FORMAT_*)
1101 * Fills in the fields of \p img with the given information.
1102 * Note: width, height and depth include the border.
1105 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1106 struct gl_texture_image
*img
,
1107 GLsizei width
, GLsizei height
, GLsizei depth
,
1108 GLint border
, GLenum internalFormat
,
1114 ASSERT(height
>= 0);
1117 target
= img
->TexObject
->Target
;
1118 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1119 ASSERT(img
->_BaseFormat
> 0);
1120 img
->InternalFormat
= internalFormat
;
1121 img
->Border
= border
;
1123 img
->Height
= height
;
1126 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1127 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1131 case GL_TEXTURE_BUFFER
:
1132 case GL_PROXY_TEXTURE_1D
:
1137 img
->HeightLog2
= 0;
1144 case GL_TEXTURE_1D_ARRAY
:
1145 case GL_PROXY_TEXTURE_1D_ARRAY
:
1146 img
->Height2
= height
; /* no border */
1147 img
->HeightLog2
= 0; /* not used */
1155 case GL_TEXTURE_RECTANGLE
:
1156 case GL_TEXTURE_CUBE_MAP
:
1157 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1158 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1159 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1160 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1161 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1162 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1163 case GL_TEXTURE_EXTERNAL_OES
:
1164 case GL_PROXY_TEXTURE_2D
:
1165 case GL_PROXY_TEXTURE_RECTANGLE
:
1166 case GL_PROXY_TEXTURE_CUBE_MAP
:
1167 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1168 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1175 case GL_TEXTURE_2D_ARRAY
:
1176 case GL_PROXY_TEXTURE_2D_ARRAY
:
1177 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1178 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1179 img
->Depth2
= depth
; /* no border */
1180 img
->DepthLog2
= 0; /* not used */
1183 case GL_PROXY_TEXTURE_3D
:
1184 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1185 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1186 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1187 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1190 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1194 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1195 img
->TexFormat
= format
;
1200 * Free and clear fields of the gl_texture_image struct.
1202 * \param ctx GL context.
1203 * \param texImage texture image structure to be cleared.
1205 * After the call, \p texImage will have no data associated with it. Its
1206 * fields are cleared so that its parent object will test incomplete.
1209 _mesa_clear_texture_image(struct gl_context
*ctx
,
1210 struct gl_texture_image
*texImage
)
1212 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1213 clear_teximage_fields(texImage
);
1218 * Check the width, height, depth and border of a texture image are legal.
1219 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1221 * The target and level parameters will have already been validated.
1222 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1225 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1226 GLint level
, GLint width
, GLint height
,
1227 GLint depth
, GLint border
)
1233 case GL_PROXY_TEXTURE_1D
:
1234 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1235 maxSize
>>= level
; /* level size */
1236 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1238 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1239 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1245 case GL_PROXY_TEXTURE_2D
:
1246 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1248 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1250 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
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
))
1261 case GL_PROXY_TEXTURE_3D
:
1262 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1264 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1266 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1268 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1270 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1271 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1273 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1275 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1280 case GL_TEXTURE_RECTANGLE_NV
:
1281 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1284 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1285 if (width
< 0 || width
> maxSize
)
1287 if (height
< 0 || height
> maxSize
)
1291 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1292 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1293 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1294 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1295 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1296 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1297 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1298 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1300 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1302 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1304 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1305 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1307 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1312 case GL_TEXTURE_1D_ARRAY_EXT
:
1313 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1314 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1316 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1318 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1320 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1321 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1326 case GL_TEXTURE_2D_ARRAY_EXT
:
1327 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1328 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1330 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1332 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1334 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1336 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1337 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1339 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1345 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1352 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1353 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1354 * \param destImage the destination texture image.
1355 * \return GL_TRUE if error found, GL_FALSE otherwise.
1358 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1359 const char *function
, GLuint dims
,
1360 const struct gl_texture_image
*destImage
,
1361 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1362 GLsizei subWidth
, GLsizei subHeight
,
1365 const GLenum target
= destImage
->TexObject
->Target
;
1370 _mesa_error(ctx
, GL_INVALID_VALUE
,
1371 "%s%dD(width=%d)", function
, dims
, subWidth
);
1375 if (dims
> 1 && subHeight
< 0) {
1376 _mesa_error(ctx
, GL_INVALID_VALUE
,
1377 "%s%dD(height=%d)", function
, dims
, subHeight
);
1381 if (dims
> 2 && subDepth
< 0) {
1382 _mesa_error(ctx
, GL_INVALID_VALUE
,
1383 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1387 /* check xoffset and width */
1388 if (xoffset
< -destImage
->Border
) {
1389 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1394 if (xoffset
+ subWidth
> destImage
->Width
) {
1395 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1400 /* check yoffset and height */
1402 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1403 if (yoffset
< -yBorder
) {
1404 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1408 if (yoffset
+ subHeight
> destImage
->Height
) {
1409 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1415 /* check zoffset and depth */
1417 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1418 if (zoffset
< -zBorder
) {
1419 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1422 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1423 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1429 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1430 * compressed texture images can be updated. But, that restriction may be
1431 * relaxed for particular compressed formats. At this time, all the
1432 * compressed formats supported by Mesa allow sub-textures to be updated
1433 * along compressed block boundaries.
1435 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1437 if (bw
!= 1 || bh
!= 1) {
1438 /* offset must be multiple of block size */
1439 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1440 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1441 "%s%dD(xoffset = %d, yoffset = %d)",
1442 function
, dims
, xoffset
, yoffset
);
1446 /* size must be multiple of bw by bh or equal to whole texture size */
1447 if ((subWidth
% bw
!= 0) && subWidth
!= destImage
->Width
) {
1448 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1449 "%s%dD(width = %d)", function
, dims
, subWidth
);
1453 if ((subHeight
% bh
!= 0) && subHeight
!= destImage
->Height
) {
1454 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1455 "%s%dD(height = %d)", function
, dims
, subHeight
);
1467 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1468 * specific texture image size checks.
1470 * A hardware driver might override this function if, for example, the
1471 * max 3D texture size is 512x512x64 (i.e. not a cube).
1473 * Note that width, height, depth == 0 is not an error. However, a
1474 * texture with zero width/height/depth will be considered "incomplete"
1475 * and texturing will effectively be disabled.
1477 * \param target any texture target/type
1478 * \param level as passed to glTexImage
1479 * \param format the MESA_FORMAT_x for the tex image
1480 * \param width as passed to glTexImage
1481 * \param height as passed to glTexImage
1482 * \param depth as passed to glTexImage
1483 * \param border as passed to glTexImage
1484 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1487 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1489 GLint width
, GLint height
, GLint depth
, GLint border
)
1491 /* We just check if the image size is less than MaxTextureMbytes.
1492 * Some drivers may do more specific checks.
1494 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1495 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1496 mbytes
*= _mesa_num_tex_faces(target
);
1497 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1502 * Return true if the format is only valid for glCompressedTexImage.
1505 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1508 case GL_ETC1_RGB8_OES
:
1509 case GL_PALETTE4_RGB8_OES
:
1510 case GL_PALETTE4_RGBA8_OES
:
1511 case GL_PALETTE4_R5_G6_B5_OES
:
1512 case GL_PALETTE4_RGBA4_OES
:
1513 case GL_PALETTE4_RGB5_A1_OES
:
1514 case GL_PALETTE8_RGB8_OES
:
1515 case GL_PALETTE8_RGBA8_OES
:
1516 case GL_PALETTE8_R5_G6_B5_OES
:
1517 case GL_PALETTE8_RGBA4_OES
:
1518 case GL_PALETTE8_RGB5_A1_OES
:
1527 * Helper function to determine whether a target and specific compression
1528 * format are supported.
1531 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1534 (void) intFormat
; /* not used yet */
1538 case GL_PROXY_TEXTURE_2D
:
1539 return GL_TRUE
; /* true for any compressed format so far */
1540 case GL_PROXY_TEXTURE_CUBE_MAP
:
1541 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1542 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1543 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1544 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1545 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1546 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1547 return ctx
->Extensions
.ARB_texture_cube_map
;
1548 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1549 case GL_TEXTURE_2D_ARRAY_EXT
:
1550 return (ctx
->Extensions
.MESA_texture_array
||
1551 ctx
->Extensions
.EXT_texture_array
);
1559 * Check if the given texture target value is legal for a
1560 * glTexImage1/2/3D call.
1563 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1569 case GL_PROXY_TEXTURE_1D
:
1570 return _mesa_is_desktop_gl(ctx
);
1578 case GL_PROXY_TEXTURE_2D
:
1579 return _mesa_is_desktop_gl(ctx
);
1580 case GL_PROXY_TEXTURE_CUBE_MAP
:
1581 return _mesa_is_desktop_gl(ctx
)
1582 && ctx
->Extensions
.ARB_texture_cube_map
;
1583 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1584 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1585 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1586 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1587 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1588 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1589 return ctx
->Extensions
.ARB_texture_cube_map
;
1590 case GL_TEXTURE_RECTANGLE_NV
:
1591 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1592 return _mesa_is_desktop_gl(ctx
)
1593 && ctx
->Extensions
.NV_texture_rectangle
;
1594 case GL_TEXTURE_1D_ARRAY_EXT
:
1595 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1596 return _mesa_is_desktop_gl(ctx
)
1597 && (ctx
->Extensions
.MESA_texture_array
||
1598 ctx
->Extensions
.EXT_texture_array
);
1606 case GL_PROXY_TEXTURE_3D
:
1607 return _mesa_is_desktop_gl(ctx
);
1608 case GL_TEXTURE_2D_ARRAY_EXT
:
1609 return (_mesa_is_desktop_gl(ctx
)
1610 && (ctx
->Extensions
.MESA_texture_array
||
1611 ctx
->Extensions
.EXT_texture_array
))
1612 || _mesa_is_gles3(ctx
);
1613 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1614 return _mesa_is_desktop_gl(ctx
)
1615 && (ctx
->Extensions
.MESA_texture_array
||
1616 ctx
->Extensions
.EXT_texture_array
);
1621 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1628 * Check if the given texture target value is legal for a
1629 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1630 * The difference compared to legal_teximage_target() above is that
1631 * proxy targets are not supported.
1634 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1638 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1643 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1644 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1645 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1646 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1647 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1648 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1649 return ctx
->Extensions
.ARB_texture_cube_map
;
1650 case GL_TEXTURE_RECTANGLE_NV
:
1651 return _mesa_is_desktop_gl(ctx
)
1652 && ctx
->Extensions
.NV_texture_rectangle
;
1653 case GL_TEXTURE_1D_ARRAY_EXT
:
1654 return _mesa_is_desktop_gl(ctx
)
1655 && (ctx
->Extensions
.MESA_texture_array
||
1656 ctx
->Extensions
.EXT_texture_array
);
1664 case GL_TEXTURE_2D_ARRAY_EXT
:
1665 return (_mesa_is_desktop_gl(ctx
)
1666 && (ctx
->Extensions
.MESA_texture_array
||
1667 ctx
->Extensions
.EXT_texture_array
))
1668 || _mesa_is_gles3(ctx
);
1673 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1681 * Helper function to determine if a texture object is mutable (in terms
1682 * of GL_ARB_texture_storage).
1685 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1687 if (ctx
->Extensions
.ARB_texture_storage
) {
1688 struct gl_texture_object
*texObj
=
1689 _mesa_get_current_tex_object(ctx
, target
);
1690 return !texObj
->Immutable
;
1697 * Return expected size of a compressed texture.
1700 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1703 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1704 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1709 * Test the glTexImage[123]D() parameters for errors.
1711 * \param ctx GL context.
1712 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1713 * \param target texture target given by the user (already validated).
1714 * \param level image level given by the user.
1715 * \param internalFormat internal format given by the user.
1716 * \param format pixel data format given by the user.
1717 * \param type pixel data type given by the user.
1718 * \param width image width given by the user.
1719 * \param height image height given by the user.
1720 * \param depth image depth given by the user.
1721 * \param border image border given by the user.
1723 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1725 * Verifies each of the parameters against the constants specified in
1726 * __struct gl_contextRec::Const and the supported extensions, and according
1727 * to the OpenGL specification.
1728 * Note that we don't fully error-check the width, height, depth values
1729 * here. That's done in _mesa_legal_texture_dimensions() which is used
1730 * by several other GL entrypoints. Plus, texture dims have a special
1731 * interaction with proxy textures.
1734 texture_error_check( struct gl_context
*ctx
,
1735 GLuint dimensions
, GLenum target
,
1736 GLint level
, GLint internalFormat
,
1737 GLenum format
, GLenum type
,
1738 GLint width
, GLint height
,
1739 GLint depth
, GLint border
)
1741 GLboolean colorFormat
;
1744 /* Even though there are no color-index textures, we still have to support
1745 * uploading color-index data and remapping it to RGB via the
1746 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1748 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1750 /* Note: for proxy textures, some error conditions immediately generate
1751 * a GL error in the usual way. But others do not generate a GL error.
1752 * Instead, they cause the width, height, depth, format fields of the
1753 * texture image to be zeroed-out. The GL spec seems to indicate that the
1754 * zero-out behaviour is only used in cases related to memory allocation.
1758 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1759 _mesa_error(ctx
, GL_INVALID_VALUE
,
1760 "glTexImage%dD(level=%d)", dimensions
, level
);
1765 if (border
< 0 || border
> 1 ||
1766 ((ctx
->API
!= API_OPENGL
||
1767 target
== GL_TEXTURE_RECTANGLE_NV
||
1768 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1769 _mesa_error(ctx
, GL_INVALID_VALUE
,
1770 "glTexImage%dD(border=%d)", dimensions
, border
);
1774 if (width
< 0 || height
< 0 || depth
< 0) {
1775 _mesa_error(ctx
, GL_INVALID_VALUE
,
1776 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1780 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1781 * combinations of format, internalFormat, and type that can be used.
1782 * Formats and types that require additional extensions (e.g., GL_FLOAT
1783 * requires GL_OES_texture_float) are filtered elsewhere.
1785 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
1786 if (format
!= internalFormat
) {
1787 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1788 "glTexImage%dD(format = %s, internalFormat = %s)",
1790 _mesa_lookup_enum_by_nr(format
),
1791 _mesa_lookup_enum_by_nr(internalFormat
));
1795 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1796 if (err
!= GL_NO_ERROR
) {
1797 _mesa_error(ctx
, err
,
1798 "glTexImage%dD(format = %s, type = %s)",
1800 _mesa_lookup_enum_by_nr(format
),
1801 _mesa_lookup_enum_by_nr(type
));
1806 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1807 _mesa_is_cube_face(target
)) && width
!= height
) {
1808 _mesa_error(ctx
, GL_INVALID_VALUE
,
1809 "glTexImage2D(cube width != height)");
1813 /* Check internalFormat */
1814 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1815 _mesa_error(ctx
, GL_INVALID_VALUE
,
1816 "glTexImage%dD(internalFormat=%s)",
1817 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1821 /* Check incoming image format and type */
1822 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1823 if (err
!= GL_NO_ERROR
) {
1824 _mesa_error(ctx
, err
,
1825 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1826 dimensions
, format
, type
);
1830 /* make sure internal format and format basically agree */
1831 colorFormat
= _mesa_is_color_format(format
);
1832 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1833 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1834 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1835 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1836 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1837 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1838 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1839 dimensions
, internalFormat
, format
);
1843 /* additional checks for ycbcr textures */
1844 if (internalFormat
== GL_YCBCR_MESA
) {
1845 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1846 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1847 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1849 _mesa_snprintf(message
, sizeof(message
),
1850 "glTexImage%dD(format/type YCBCR mismatch)",
1852 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1853 return GL_TRUE
; /* error */
1855 if (target
!= GL_TEXTURE_2D
&&
1856 target
!= GL_PROXY_TEXTURE_2D
&&
1857 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1858 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1859 _mesa_error(ctx
, GL_INVALID_ENUM
,
1860 "glTexImage%dD(bad target for YCbCr texture)",
1866 _mesa_snprintf(message
, sizeof(message
),
1867 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1868 dimensions
, border
);
1869 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1874 /* additional checks for depth textures */
1875 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1876 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1877 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1878 if (target
!= GL_TEXTURE_1D
&&
1879 target
!= GL_PROXY_TEXTURE_1D
&&
1880 target
!= GL_TEXTURE_2D
&&
1881 target
!= GL_PROXY_TEXTURE_2D
&&
1882 target
!= GL_TEXTURE_1D_ARRAY
&&
1883 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1884 target
!= GL_TEXTURE_2D_ARRAY
&&
1885 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1886 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1887 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1888 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1889 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))) {
1890 _mesa_error(ctx
, GL_INVALID_ENUM
,
1891 "glTexImage%dD(bad target for depth texture)",
1897 /* additional checks for compressed textures */
1898 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1899 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1900 _mesa_error(ctx
, GL_INVALID_ENUM
,
1901 "glTexImage%dD(target can't be compressed)", dimensions
);
1904 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1905 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1906 "glTexImage%dD(no compression for format)", dimensions
);
1910 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1911 "glTexImage%dD(border!=0)", dimensions
);
1916 /* additional checks for integer textures */
1917 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1918 (_mesa_is_enum_format_integer(format
) !=
1919 _mesa_is_enum_format_integer(internalFormat
))) {
1920 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1921 "glTexImage%dD(integer/non-integer format mismatch)",
1926 if (!mutable_tex_object(ctx
, target
)) {
1927 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1928 "glTexImage%dD(immutable texture)", dimensions
);
1932 /* if we get here, the parameters are OK */
1938 * Error checking for glCompressedTexImage[123]D().
1939 * Note that the width, height and depth values are not fully error checked
1941 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1944 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
1945 GLenum target
, GLint level
,
1946 GLenum internalFormat
, GLsizei width
,
1947 GLsizei height
, GLsizei depth
, GLint border
,
1950 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1952 GLenum choose_format
;
1954 GLenum proxy_format
;
1955 GLenum error
= GL_NO_ERROR
;
1956 char *reason
= ""; /* no error */
1958 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1960 error
= GL_INVALID_ENUM
;
1964 /* This will detect any invalid internalFormat value */
1965 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
1966 reason
= "internalFormat";
1967 error
= GL_INVALID_ENUM
;
1971 switch (internalFormat
) {
1973 case GL_PALETTE4_RGB8_OES
:
1974 case GL_PALETTE4_RGBA8_OES
:
1975 case GL_PALETTE4_R5_G6_B5_OES
:
1976 case GL_PALETTE4_RGBA4_OES
:
1977 case GL_PALETTE4_RGB5_A1_OES
:
1978 case GL_PALETTE8_RGB8_OES
:
1979 case GL_PALETTE8_RGBA8_OES
:
1980 case GL_PALETTE8_R5_G6_B5_OES
:
1981 case GL_PALETTE8_RGBA4_OES
:
1982 case GL_PALETTE8_RGB5_A1_OES
:
1983 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
1985 proxy_format
= choose_format
;
1987 /* check level (note that level should be zero or less!) */
1988 if (level
> 0 || level
< -maxLevels
) {
1990 error
= GL_INVALID_VALUE
;
1994 if (dimensions
!= 2) {
1995 reason
= "compressed paletted textures must be 2D";
1996 error
= GL_INVALID_OPERATION
;
2000 /* Figure out the expected texture size (in bytes). This will be
2001 * checked against the actual size later.
2003 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2006 /* This is for the benefit of the TestProxyTexImage below. It expects
2007 * level to be non-negative. OES_compressed_paletted_texture uses a
2008 * weird mechanism where the level specified to glCompressedTexImage2D
2009 * is -(n-1) number of levels in the texture, and the data specifies the
2010 * complete mipmap stack. This is done to ensure the palette is the
2011 * same for all levels.
2018 choose_format
= GL_NONE
;
2019 choose_type
= GL_NONE
;
2020 proxy_format
= internalFormat
;
2023 if (level
< 0 || level
>= maxLevels
) {
2025 error
= GL_INVALID_VALUE
;
2029 /* Figure out the expected texture size (in bytes). This will be
2030 * checked against the actual size later.
2032 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2036 /* This should really never fail */
2037 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2038 reason
= "internalFormat";
2039 error
= GL_INVALID_ENUM
;
2043 /* No compressed formats support borders at this time */
2045 reason
= "border != 0";
2046 error
= GL_INVALID_VALUE
;
2050 /* For cube map, width must equal height */
2051 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2052 _mesa_is_cube_face(target
)) && width
!= height
) {
2053 reason
= "width != height";
2054 error
= GL_INVALID_VALUE
;
2058 /* check image size against compression block size */
2059 /* XXX possibly move this into the _mesa_legal_texture_dimensions() func */
2061 gl_format texFormat
=
2062 ctx
->Driver
.ChooseTextureFormat(ctx
, target
, proxy_format
,
2063 choose_format
, choose_type
);
2066 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
2067 if ((width
> bw
&& width
% bw
> 0) ||
2068 (height
> bh
&& height
% bh
> 0)) {
2070 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
2071 * generated [...] if any parameter combinations are not
2072 * supported by the specific compressed internal format.
2074 reason
= "invalid width or height for compression format";
2075 error
= GL_INVALID_OPERATION
;
2080 /* check image size in bytes */
2081 if (expectedSize
!= imageSize
) {
2082 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2083 * if <imageSize> is not consistent with the format, dimensions, and
2084 * contents of the specified image.
2086 reason
= "imageSize inconsistant with width/height/format";
2087 error
= GL_INVALID_VALUE
;
2091 if (!mutable_tex_object(ctx
, target
)) {
2092 reason
= "immutable texture";
2093 error
= GL_INVALID_OPERATION
;
2100 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2107 * Test glTexSubImage[123]D() parameters for errors.
2109 * \param ctx GL context.
2110 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2111 * \param target texture target given by the user (already validated)
2112 * \param level image level given by the user.
2113 * \param xoffset sub-image x offset given by the user.
2114 * \param yoffset sub-image y offset given by the user.
2115 * \param zoffset sub-image z offset given by the user.
2116 * \param format pixel data format given by the user.
2117 * \param type pixel data type given by the user.
2118 * \param width image width given by the user.
2119 * \param height image height given by the user.
2120 * \param depth image depth given by the user.
2122 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2124 * Verifies each of the parameters against the constants specified in
2125 * __struct gl_contextRec::Const and the supported extensions, and according
2126 * to the OpenGL specification.
2129 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2130 GLenum target
, GLint level
,
2131 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2132 GLint width
, GLint height
, GLint depth
,
2133 GLenum format
, GLenum type
)
2135 struct gl_texture_object
*texObj
;
2136 struct gl_texture_image
*texImage
;
2139 /* check target (proxies not allowed) */
2140 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2141 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2142 dimensions
, _mesa_lookup_enum_by_nr(target
));
2147 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2148 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2153 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2154 * combinations of format and type that can be used. Formats and types
2155 * that require additional extensions (e.g., GL_FLOAT requires
2156 * GL_OES_texture_float) are filtered elsewhere.
2158 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2159 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2160 if (err
!= GL_NO_ERROR
) {
2161 _mesa_error(ctx
, err
,
2162 "glTexSubImage%dD(format = %s, type = %s)",
2164 _mesa_lookup_enum_by_nr(format
),
2165 _mesa_lookup_enum_by_nr(type
));
2170 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2171 if (err
!= GL_NO_ERROR
) {
2172 _mesa_error(ctx
, err
,
2173 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
2174 dimensions
, format
, type
);
2178 /* Get dest texture object / image pointers */
2179 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2181 /* must be out of memory */
2182 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2186 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2188 /* non-existant texture level */
2189 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2190 "glTexSubImage%dD(invalid texture image)", dimensions
);
2194 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2195 texImage
, xoffset
, yoffset
, 0,
2196 width
, height
, 1)) {
2200 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2201 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2202 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2203 "glTexSubImage%dD(no compression for format)", dimensions
);
2208 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2209 /* both source and dest must be integer-valued, or neither */
2210 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2211 _mesa_is_enum_format_integer(format
)) {
2212 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2213 "glTexSubImage%dD(integer/non-integer format mismatch)",
2224 * Test glCopyTexImage[12]D() parameters for errors.
2226 * \param ctx GL context.
2227 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2228 * \param target texture target given by the user.
2229 * \param level image level given by the user.
2230 * \param internalFormat internal format given by the user.
2231 * \param width image width given by the user.
2232 * \param height image height given by the user.
2233 * \param border texture border.
2235 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2237 * Verifies each of the parameters against the constants specified in
2238 * __struct gl_contextRec::Const and the supported extensions, and according
2239 * to the OpenGL specification.
2242 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2243 GLenum target
, GLint level
, GLint internalFormat
,
2244 GLint width
, GLint height
, GLint border
)
2249 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2250 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2251 dimensions
, _mesa_lookup_enum_by_nr(target
));
2256 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2257 _mesa_error(ctx
, GL_INVALID_VALUE
,
2258 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2262 /* Check that the source buffer is complete */
2263 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2264 if (ctx
->ReadBuffer
->_Status
== 0) {
2265 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2267 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2268 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2269 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2273 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2274 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2275 "glCopyTexImage%dD(multisample FBO)",
2282 if (border
< 0 || border
> 1 ||
2283 ((ctx
->API
!= API_OPENGL
||
2284 target
== GL_TEXTURE_RECTANGLE_NV
||
2285 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2286 _mesa_error(ctx
, GL_INVALID_VALUE
,
2287 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2291 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2294 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2295 switch (internalFormat
) {
2300 case GL_LUMINANCE_ALPHA
:
2303 _mesa_error(ctx
, GL_INVALID_VALUE
,
2304 "glCopyTexImage%dD(internalFormat)", dimensions
);
2309 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2310 if (baseFormat
< 0) {
2311 _mesa_error(ctx
, GL_INVALID_VALUE
,
2312 "glCopyTexImage%dD(internalFormat)", dimensions
);
2316 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2317 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2318 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2322 /* From the EXT_texture_integer spec:
2324 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2325 * if the texture internalformat is an integer format and the read color
2326 * buffer is not an integer format, or if the internalformat is not an
2327 * integer format and the read color buffer is an integer format."
2329 if (_mesa_is_color_format(internalFormat
)) {
2330 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2332 if (_mesa_is_enum_format_integer(rb
->InternalFormat
) !=
2333 _mesa_is_enum_format_integer(internalFormat
)) {
2334 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2335 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2340 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2341 _mesa_is_cube_face(target
)) && width
!= height
) {
2342 _mesa_error(ctx
, GL_INVALID_VALUE
,
2343 "glTexImage2D(cube width != height)");
2347 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2348 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2349 _mesa_error(ctx
, GL_INVALID_ENUM
,
2350 "glCopyTexImage%dD(target)", dimensions
);
2353 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2354 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2355 "glCopyTexImage%dD(no compression for format)", dimensions
);
2359 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2360 "glCopyTexImage%dD(border!=0)", dimensions
);
2365 if (!mutable_tex_object(ctx
, target
)) {
2366 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2367 "glCopyTexImage%dD(immutable texture)", dimensions
);
2371 /* if we get here, the parameters are OK */
2377 * Test glCopyTexSubImage[12]D() parameters for errors.
2378 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2381 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2382 GLenum target
, GLint level
,
2383 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2384 GLint width
, GLint height
)
2386 struct gl_texture_object
*texObj
;
2387 struct gl_texture_image
*texImage
;
2389 /* Check that the source buffer is complete */
2390 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2391 if (ctx
->ReadBuffer
->_Status
== 0) {
2392 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2394 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2395 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2396 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2400 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2401 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2402 "glCopyTexSubImage%dD(multisample FBO)",
2408 /* check target (proxies not allowed) */
2409 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2410 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2411 dimensions
, _mesa_lookup_enum_by_nr(target
));
2416 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2417 _mesa_error(ctx
, GL_INVALID_VALUE
,
2418 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2422 /* Get dest texture object / image pointers */
2423 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2425 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2429 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2431 /* destination image does not exist */
2432 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2433 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2437 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2438 dimensions
, texImage
,
2439 xoffset
, yoffset
, zoffset
,
2440 width
, height
, 1)) {
2444 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2445 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2446 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2447 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2452 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2453 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2457 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2458 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2459 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2460 dimensions
, texImage
->_BaseFormat
);
2464 /* From the EXT_texture_integer spec:
2466 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2467 * if the texture internalformat is an integer format and the read color
2468 * buffer is not an integer format, or if the internalformat is not an
2469 * integer format and the read color buffer is an integer format."
2471 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2472 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2474 if (_mesa_is_format_integer_color(rb
->Format
) !=
2475 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2476 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2477 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2482 /* if we get here, the parameters are OK */
2487 /** Callback info for walking over FBO hash table */
2490 struct gl_context
*ctx
;
2491 struct gl_texture_object
*texObj
;
2497 * Check render to texture callback. Called from _mesa_HashWalk().
2500 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2502 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2503 const struct cb_info
*info
= (struct cb_info
*) userData
;
2504 struct gl_context
*ctx
= info
->ctx
;
2505 const struct gl_texture_object
*texObj
= info
->texObj
;
2506 const GLuint level
= info
->level
, face
= info
->face
;
2508 /* If this is a user-created FBO */
2509 if (_mesa_is_user_fbo(fb
)) {
2511 /* check if any of the FBO's attachments point to 'texObj' */
2512 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2513 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2514 if (att
->Type
== GL_TEXTURE
&&
2515 att
->Texture
== texObj
&&
2516 att
->TextureLevel
== level
&&
2517 att
->CubeMapFace
== face
) {
2518 ASSERT(_mesa_get_attachment_teximage(att
));
2519 /* Tell driver about the new renderbuffer texture */
2520 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2521 /* Mark fb status as indeterminate to force re-validation */
2530 * When a texture image is specified we have to check if it's bound to
2531 * any framebuffer objects (render to texture) in order to detect changes
2532 * in size or format since that effects FBO completeness.
2533 * Any FBOs rendering into the texture must be re-validated.
2536 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2537 struct gl_texture_object
*texObj
,
2538 GLuint face
, GLuint level
)
2540 /* Only check this texture if it's been marked as RenderToTexture */
2541 if (texObj
->_RenderToTexture
) {
2542 struct cb_info info
;
2544 info
.texObj
= texObj
;
2547 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2553 * If the texture object's GenerateMipmap flag is set and we've
2554 * changed the texture base level image, regenerate the rest of the
2555 * mipmap levels now.
2558 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2559 struct gl_texture_object
*texObj
, GLint level
)
2561 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2562 if (texObj
->GenerateMipmap
&&
2563 level
== texObj
->BaseLevel
&&
2564 level
< texObj
->MaxLevel
) {
2565 ASSERT(ctx
->Driver
.GenerateMipmap
);
2566 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2571 /** Debug helper: override the user-requested internal format */
2573 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2576 if (internalFormat
== GL_RGBA16F_ARB
||
2577 internalFormat
== GL_RGBA32F_ARB
) {
2578 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2581 else if (internalFormat
== GL_RGB16F_ARB
||
2582 internalFormat
== GL_RGB32F_ARB
) {
2583 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2586 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2587 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2588 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2589 return GL_LUMINANCE_ALPHA
;
2591 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2592 internalFormat
== GL_LUMINANCE32F_ARB
) {
2593 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2594 return GL_LUMINANCE
;
2596 else if (internalFormat
== GL_ALPHA16F_ARB
||
2597 internalFormat
== GL_ALPHA32F_ARB
) {
2598 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2602 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2603 internalFormat = GL_RGBA;
2607 return internalFormat
;
2610 return internalFormat
;
2616 * Choose the actual hardware format for a texture image.
2617 * Try to use the same format as the previous image level when possible.
2618 * Otherwise, ask the driver for the best format.
2619 * It's important to try to choose a consistant format for all levels
2620 * for efficient texture memory layout/allocation. In particular, this
2621 * comes up during automatic mipmap generation.
2624 _mesa_choose_texture_format(struct gl_context
*ctx
,
2625 struct gl_texture_object
*texObj
,
2626 GLenum target
, GLint level
,
2627 GLenum internalFormat
, GLenum format
, GLenum type
)
2631 /* see if we've already chosen a format for the previous level */
2633 struct gl_texture_image
*prevImage
=
2634 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2635 /* See if the prev level is defined and has an internal format which
2636 * matches the new internal format.
2639 prevImage
->Width
> 0 &&
2640 prevImage
->InternalFormat
== internalFormat
) {
2641 /* use the same format */
2642 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2643 return prevImage
->TexFormat
;
2647 /* If the application requested compression to an S3TC format but we don't
2648 * have the DTXn library, force a generic compressed format instead.
2650 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2651 const GLenum before
= internalFormat
;
2653 switch (internalFormat
) {
2654 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2655 if (!ctx
->Mesa_DXTn
)
2656 internalFormat
= GL_COMPRESSED_RGB
;
2658 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2659 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2660 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2661 if (!ctx
->Mesa_DXTn
)
2662 internalFormat
= GL_COMPRESSED_RGBA
;
2668 if (before
!= internalFormat
) {
2670 "DXT compression requested (%s), "
2671 "but libtxc_dxtn library not installed. Using %s "
2673 _mesa_lookup_enum_by_nr(before
),
2674 _mesa_lookup_enum_by_nr(internalFormat
));
2678 /* choose format from scratch */
2679 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2681 ASSERT(f
!= MESA_FORMAT_NONE
);
2686 * Adjust pixel unpack params and image dimensions to strip off the
2687 * one-pixel texture border.
2689 * Gallium and intel don't support texture borders. They've seldem been used
2690 * and seldom been implemented correctly anyway.
2692 * \param unpackNew returns the new pixel unpack parameters
2695 strip_texture_border(GLenum target
,
2696 GLint
*width
, GLint
*height
, GLint
*depth
,
2697 const struct gl_pixelstore_attrib
*unpack
,
2698 struct gl_pixelstore_attrib
*unpackNew
)
2704 *unpackNew
= *unpack
;
2706 if (unpackNew
->RowLength
== 0)
2707 unpackNew
->RowLength
= *width
;
2709 if (unpackNew
->ImageHeight
== 0)
2710 unpackNew
->ImageHeight
= *height
;
2712 assert(*width
>= 3);
2713 unpackNew
->SkipPixels
++; /* skip the border */
2714 *width
= *width
- 2; /* reduce the width by two border pixels */
2716 /* The min height of a texture with a border is 3 */
2717 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2718 unpackNew
->SkipRows
++; /* skip the border */
2719 *height
= *height
- 2; /* reduce the height by two border pixels */
2722 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
) {
2723 unpackNew
->SkipImages
++; /* skip the border */
2724 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2730 * Common code to implement all the glTexImage1D/2D/3D functions
2731 * as well as glCompressedTexImage1D/2D/3D.
2732 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2733 * \param format the user's image format (only used if !compressed)
2734 * \param type the user's image type (only used if !compressed)
2735 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2738 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2739 GLenum target
, GLint level
, GLint internalFormat
,
2740 GLsizei width
, GLsizei height
, GLsizei depth
,
2741 GLint border
, GLenum format
, GLenum type
,
2742 GLsizei imageSize
, const GLvoid
*pixels
)
2744 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2745 struct gl_pixelstore_attrib unpack_no_border
;
2746 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2747 struct gl_texture_object
*texObj
;
2748 gl_format texFormat
;
2749 GLboolean dimensionsOK
, sizeOK
;
2751 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2753 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2756 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2758 _mesa_lookup_enum_by_nr(target
), level
,
2759 _mesa_lookup_enum_by_nr(internalFormat
),
2760 width
, height
, depth
, border
, pixels
);
2763 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2765 _mesa_lookup_enum_by_nr(target
), level
,
2766 _mesa_lookup_enum_by_nr(internalFormat
),
2767 width
, height
, depth
, border
,
2768 _mesa_lookup_enum_by_nr(format
),
2769 _mesa_lookup_enum_by_nr(type
), pixels
);
2772 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2774 /* target error checking */
2775 if (!legal_teximage_target(ctx
, dims
, target
)) {
2776 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2777 func
, dims
, _mesa_lookup_enum_by_nr(target
));
2781 /* general error checking */
2783 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2785 width
, height
, depth
,
2790 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2791 format
, type
, width
, height
, depth
, border
))
2795 /* Here we convert a cpal compressed image into a regular glTexImage2D
2796 * call by decompressing the texture. If we really want to support cpal
2797 * textures in any driver this would have to be changed.
2799 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
2800 switch (internalFormat
) {
2801 case GL_PALETTE4_RGB8_OES
:
2802 case GL_PALETTE4_RGBA8_OES
:
2803 case GL_PALETTE4_R5_G6_B5_OES
:
2804 case GL_PALETTE4_RGBA4_OES
:
2805 case GL_PALETTE4_RGB5_A1_OES
:
2806 case GL_PALETTE8_RGB8_OES
:
2807 case GL_PALETTE8_RGBA8_OES
:
2808 case GL_PALETTE8_R5_G6_B5_OES
:
2809 case GL_PALETTE8_RGBA4_OES
:
2810 case GL_PALETTE8_RGB5_A1_OES
:
2811 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
2812 width
, height
, imageSize
, pixels
);
2817 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2820 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2821 internalFormat
, format
, type
);
2822 assert(texFormat
!= MESA_FORMAT_NONE
);
2824 /* check that width, height, depth are legal for the mipmap level */
2825 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
2826 height
, depth
, border
);
2828 /* check that the texture won't take too much memory, etc */
2829 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
2831 width
, height
, depth
, border
);
2833 if (_mesa_is_proxy_texture(target
)) {
2834 /* Proxy texture: just clear or set state depending on error checking */
2835 struct gl_texture_image
*texImage
=
2836 get_proxy_tex_image(ctx
, target
, level
);
2839 return; /* GL_OUT_OF_MEMORY already recorded */
2841 if (dimensionsOK
&& sizeOK
) {
2842 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
2843 border
, internalFormat
, texFormat
);
2846 clear_teximage_fields(texImage
);
2850 /* non-proxy target */
2851 const GLuint face
= _mesa_tex_target_to_face(target
);
2852 struct gl_texture_image
*texImage
;
2854 if (!dimensionsOK
) {
2855 _mesa_error(ctx
, GL_INVALID_VALUE
,
2856 "glTexImage%uD(invalid width or height or depth)",
2862 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
2863 "glTexImage%uD(image too large)", dims
);
2867 /* Allow a hardware driver to just strip out the border, to provide
2868 * reliable but slightly incorrect hardware rendering instead of
2869 * rarely-tested software fallback rendering.
2871 if (border
&& ctx
->Const
.StripTextureBorder
) {
2872 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
2875 unpack
= &unpack_no_border
;
2878 if (ctx
->NewState
& _NEW_PIXEL
)
2879 _mesa_update_state(ctx
);
2881 _mesa_lock_texture(ctx
, texObj
);
2883 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2886 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
2889 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2891 _mesa_init_teximage_fields(ctx
, texImage
,
2892 width
, height
, depth
,
2893 border
, internalFormat
, texFormat
);
2895 /* Give the texture to the driver. <pixels> may be null. */
2897 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
2901 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
2902 type
, pixels
, unpack
);
2905 check_gen_mipmap(ctx
, target
, texObj
, level
);
2907 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2909 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2912 _mesa_unlock_texture(ctx
, texObj
);
2919 * Called from the API. Note that width includes the border.
2922 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2923 GLsizei width
, GLint border
, GLenum format
,
2924 GLenum type
, const GLvoid
*pixels
)
2926 GET_CURRENT_CONTEXT(ctx
);
2927 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
2928 border
, format
, type
, 0, pixels
);
2933 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2934 GLsizei width
, GLsizei height
, GLint border
,
2935 GLenum format
, GLenum type
,
2936 const GLvoid
*pixels
)
2938 GET_CURRENT_CONTEXT(ctx
);
2939 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
2940 border
, format
, type
, 0, pixels
);
2945 * Called by the API or display list executor.
2946 * Note that width and height include the border.
2949 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2950 GLsizei width
, GLsizei height
, GLsizei depth
,
2951 GLint border
, GLenum format
, GLenum type
,
2952 const GLvoid
*pixels
)
2954 GET_CURRENT_CONTEXT(ctx
);
2955 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
2956 width
, height
, depth
,
2957 border
, format
, type
, 0, pixels
);
2962 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2963 GLsizei width
, GLsizei height
, GLsizei depth
,
2964 GLint border
, GLenum format
, GLenum type
,
2965 const GLvoid
*pixels
)
2967 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2968 depth
, border
, format
, type
, pixels
);
2973 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2975 struct gl_texture_object
*texObj
;
2976 struct gl_texture_image
*texImage
;
2978 GET_CURRENT_CONTEXT(ctx
);
2979 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2983 valid_target
= ctx
->Extensions
.OES_EGL_image
;
2985 case GL_TEXTURE_EXTERNAL_OES
:
2986 valid_target
= ctx
->Extensions
.OES_EGL_image_external
;
2989 valid_target
= false;
2993 if (!valid_target
) {
2994 _mesa_error(ctx
, GL_INVALID_ENUM
,
2995 "glEGLImageTargetTexture2D(target=%d)", target
);
2999 if (ctx
->NewState
& _NEW_PIXEL
)
3000 _mesa_update_state(ctx
);
3002 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3003 _mesa_lock_texture(ctx
, texObj
);
3005 if (texObj
->Immutable
) {
3006 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3007 "glEGLImageTargetTexture2D(texture is immutable)");
3008 _mesa_unlock_texture(ctx
, texObj
);
3012 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3014 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3016 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3018 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3019 texObj
, texImage
, image
);
3021 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3023 _mesa_unlock_texture(ctx
, texObj
);
3030 * Implement all the glTexSubImage1/2/3D() functions.
3033 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3034 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3035 GLsizei width
, GLsizei height
, GLsizei depth
,
3036 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3038 struct gl_texture_object
*texObj
;
3039 struct gl_texture_image
*texImage
;
3041 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3043 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3044 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3046 _mesa_lookup_enum_by_nr(target
), level
,
3047 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3048 _mesa_lookup_enum_by_nr(format
),
3049 _mesa_lookup_enum_by_nr(type
), pixels
);
3051 /* check target (proxies not allowed) */
3052 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3053 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3054 dims
, _mesa_lookup_enum_by_nr(target
));
3058 if (ctx
->NewState
& _NEW_PIXEL
)
3059 _mesa_update_state(ctx
);
3061 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3062 xoffset
, yoffset
, zoffset
,
3063 width
, height
, depth
, format
, type
)) {
3064 return; /* error was detected */
3067 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3069 _mesa_lock_texture(ctx
, texObj
);
3071 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3073 if (width
> 0 && height
> 0 && depth
> 0) {
3074 /* If we have a border, offset=-1 is legal. Bias by border width. */
3077 if (target
!= GL_TEXTURE_2D_ARRAY
)
3078 zoffset
+= texImage
->Border
;
3081 if (target
!= GL_TEXTURE_1D_ARRAY
)
3082 yoffset
+= texImage
->Border
;
3085 xoffset
+= texImage
->Border
;
3088 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3089 xoffset
, yoffset
, zoffset
,
3090 width
, height
, depth
,
3091 format
, type
, pixels
, &ctx
->Unpack
);
3093 check_gen_mipmap(ctx
, target
, texObj
, level
);
3095 ctx
->NewState
|= _NEW_TEXTURE
;
3098 _mesa_unlock_texture(ctx
, texObj
);
3103 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3104 GLint xoffset
, GLsizei width
,
3105 GLenum format
, GLenum type
,
3106 const GLvoid
*pixels
)
3108 GET_CURRENT_CONTEXT(ctx
);
3109 texsubimage(ctx
, 1, target
, level
,
3112 format
, type
, pixels
);
3117 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3118 GLint xoffset
, GLint yoffset
,
3119 GLsizei width
, GLsizei height
,
3120 GLenum format
, GLenum type
,
3121 const GLvoid
*pixels
)
3123 GET_CURRENT_CONTEXT(ctx
);
3124 texsubimage(ctx
, 2, target
, level
,
3125 xoffset
, yoffset
, 0,
3127 format
, type
, pixels
);
3133 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3134 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3135 GLsizei width
, GLsizei height
, GLsizei depth
,
3136 GLenum format
, GLenum type
,
3137 const GLvoid
*pixels
)
3139 GET_CURRENT_CONTEXT(ctx
);
3140 texsubimage(ctx
, 3, target
, level
,
3141 xoffset
, yoffset
, zoffset
,
3142 width
, height
, depth
,
3143 format
, type
, pixels
);
3149 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3150 * from. This depends on whether the texture contains color or depth values.
3152 static struct gl_renderbuffer
*
3153 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3155 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3156 /* reading from depth/stencil buffer */
3157 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3160 /* copying from color buffer */
3161 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3168 * Implement the glCopyTexImage1/2D() functions.
3171 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3172 GLenum target
, GLint level
, GLenum internalFormat
,
3173 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3175 struct gl_texture_object
*texObj
;
3176 struct gl_texture_image
*texImage
;
3177 const GLuint face
= _mesa_tex_target_to_face(target
);
3178 gl_format texFormat
;
3180 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3182 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3183 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3185 _mesa_lookup_enum_by_nr(target
), level
,
3186 _mesa_lookup_enum_by_nr(internalFormat
),
3187 x
, y
, width
, height
, border
);
3189 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3190 _mesa_update_state(ctx
);
3192 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3193 width
, height
, border
))
3196 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3198 _mesa_error(ctx
, GL_INVALID_VALUE
,
3199 "glCopyTexImage%uD(invalid width or height)", dims
);
3203 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3206 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3207 internalFormat
, GL_NONE
, GL_NONE
);
3208 assert(texFormat
!= MESA_FORMAT_NONE
);
3210 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3212 width
, height
, 1, border
)) {
3213 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3214 "glCopyTexImage%uD(image too large)", dims
);
3218 if (border
&& ctx
->Const
.StripTextureBorder
) {
3220 width
-= border
* 2;
3223 height
-= border
* 2;
3228 _mesa_lock_texture(ctx
, texObj
);
3230 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3233 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3236 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3238 /* Free old texture image */
3239 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3241 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3242 border
, internalFormat
, texFormat
);
3244 /* Allocate texture memory (no pixel data yet) */
3245 ctx
->Driver
.TexImage(ctx
, dims
, texImage
,
3247 NULL
, &ctx
->Unpack
);
3249 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3251 struct gl_renderbuffer
*srcRb
=
3252 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3254 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
3255 srcRb
, srcX
, srcY
, width
, height
);
3258 check_gen_mipmap(ctx
, target
, texObj
, level
);
3260 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3262 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3265 _mesa_unlock_texture(ctx
, texObj
);
3271 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3272 GLenum internalFormat
,
3274 GLsizei width
, GLint border
)
3276 GET_CURRENT_CONTEXT(ctx
);
3277 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3283 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3284 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3287 GET_CURRENT_CONTEXT(ctx
);
3288 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3289 x
, y
, width
, height
, border
);
3295 * Implementation for glCopyTexSubImage1/2/3D() functions.
3298 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3299 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3300 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3302 struct gl_texture_object
*texObj
;
3303 struct gl_texture_image
*texImage
;
3305 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3307 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3308 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3310 _mesa_lookup_enum_by_nr(target
),
3311 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3313 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3314 _mesa_update_state(ctx
);
3316 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3317 xoffset
, yoffset
, zoffset
, width
, height
)) {
3321 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3323 _mesa_lock_texture(ctx
, texObj
);
3325 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3327 /* If we have a border, offset=-1 is legal. Bias by border width. */
3330 if (target
!= GL_TEXTURE_2D_ARRAY
)
3331 zoffset
+= texImage
->Border
;
3334 if (target
!= GL_TEXTURE_1D_ARRAY
)
3335 yoffset
+= texImage
->Border
;
3338 xoffset
+= texImage
->Border
;
3341 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3343 struct gl_renderbuffer
*srcRb
=
3344 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3346 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3347 xoffset
, yoffset
, zoffset
,
3348 srcRb
, x
, y
, width
, height
);
3350 check_gen_mipmap(ctx
, target
, texObj
, level
);
3352 ctx
->NewState
|= _NEW_TEXTURE
;
3355 _mesa_unlock_texture(ctx
, texObj
);
3360 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3361 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3363 GET_CURRENT_CONTEXT(ctx
);
3364 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3370 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3371 GLint xoffset
, GLint yoffset
,
3372 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3374 GET_CURRENT_CONTEXT(ctx
);
3375 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3382 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3383 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3384 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3386 GET_CURRENT_CONTEXT(ctx
);
3387 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3388 x
, y
, width
, height
);
3394 /**********************************************************************/
3395 /****** Compressed Textures ******/
3396 /**********************************************************************/
3400 * Error checking for glCompressedTexSubImage[123]D().
3401 * \return error code or GL_NO_ERROR.
3404 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3405 GLenum target
, GLint level
,
3406 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3407 GLsizei width
, GLsizei height
, GLsizei depth
,
3408 GLenum format
, GLsizei imageSize
)
3410 struct gl_texture_object
*texObj
;
3411 struct gl_texture_image
*texImage
;
3418 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3419 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3420 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3421 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3422 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3423 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3427 targetOK
= GL_FALSE
;
3431 assert(dims
== 1 || dims
== 3);
3432 /* no 1D or 3D compressed textures at this time */
3433 targetOK
= GL_FALSE
;
3437 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3442 /* this will catch any invalid compressed format token */
3443 if (!_mesa_is_compressed_format(ctx
, format
)) {
3444 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3449 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3450 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3455 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3456 if (expectedSize
!= imageSize
) {
3457 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3462 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3464 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3465 "glCompressedTexSubImage%uD()", dims
);
3469 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3471 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3472 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3476 if ((GLint
) format
!= texImage
->InternalFormat
) {
3477 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3478 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3482 if (compressedteximage_only_format(ctx
, format
)) {
3483 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3484 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3489 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3490 texImage
, xoffset
, yoffset
, zoffset
,
3491 width
, height
, depth
)) {
3500 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3501 GLenum internalFormat
, GLsizei width
,
3502 GLint border
, GLsizei imageSize
,
3505 GET_CURRENT_CONTEXT(ctx
);
3506 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3507 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3512 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3513 GLenum internalFormat
, GLsizei width
,
3514 GLsizei height
, GLint border
, GLsizei imageSize
,
3517 GET_CURRENT_CONTEXT(ctx
);
3518 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3519 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3524 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3525 GLenum internalFormat
, GLsizei width
,
3526 GLsizei height
, GLsizei depth
, GLint border
,
3527 GLsizei imageSize
, const GLvoid
*data
)
3529 GET_CURRENT_CONTEXT(ctx
);
3530 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3531 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3536 * Common helper for glCompressedTexSubImage1/2/3D().
3539 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3540 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3541 GLsizei width
, GLsizei height
, GLsizei depth
,
3542 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3544 struct gl_texture_object
*texObj
;
3545 struct gl_texture_image
*texImage
;
3546 GET_CURRENT_CONTEXT(ctx
);
3547 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3549 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3550 xoffset
, yoffset
, zoffset
,
3551 width
, height
, depth
,
3552 format
, imageSize
)) {
3556 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3558 _mesa_lock_texture(ctx
, texObj
);
3560 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3563 if (width
> 0 && height
> 0 && depth
> 0) {
3564 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3565 xoffset
, yoffset
, zoffset
,
3566 width
, height
, depth
,
3567 format
, imageSize
, data
);
3569 check_gen_mipmap(ctx
, target
, texObj
, level
);
3571 ctx
->NewState
|= _NEW_TEXTURE
;
3574 _mesa_unlock_texture(ctx
, texObj
);
3579 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3580 GLsizei width
, GLenum format
,
3581 GLsizei imageSize
, const GLvoid
*data
)
3583 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3584 format
, imageSize
, data
);
3589 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3590 GLint yoffset
, GLsizei width
, GLsizei height
,
3591 GLenum format
, GLsizei imageSize
,
3594 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3595 width
, height
, 1, format
, imageSize
, data
);
3600 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3601 GLint yoffset
, GLint zoffset
, GLsizei width
,
3602 GLsizei height
, GLsizei depth
, GLenum format
,
3603 GLsizei imageSize
, const GLvoid
*data
)
3605 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3606 width
, height
, depth
, format
, imageSize
, data
);
3610 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3612 switch (internalFormat
) {
3614 return MESA_FORMAT_A8
;
3616 return MESA_FORMAT_A16
;
3617 case GL_ALPHA16F_ARB
:
3618 return MESA_FORMAT_ALPHA_FLOAT16
;
3619 case GL_ALPHA32F_ARB
:
3620 return MESA_FORMAT_ALPHA_FLOAT32
;
3621 case GL_ALPHA8I_EXT
:
3622 return MESA_FORMAT_ALPHA_INT8
;
3623 case GL_ALPHA16I_EXT
:
3624 return MESA_FORMAT_ALPHA_INT16
;
3625 case GL_ALPHA32I_EXT
:
3626 return MESA_FORMAT_ALPHA_INT32
;
3627 case GL_ALPHA8UI_EXT
:
3628 return MESA_FORMAT_ALPHA_UINT8
;
3629 case GL_ALPHA16UI_EXT
:
3630 return MESA_FORMAT_ALPHA_UINT16
;
3631 case GL_ALPHA32UI_EXT
:
3632 return MESA_FORMAT_ALPHA_UINT32
;
3634 return MESA_FORMAT_L8
;
3635 case GL_LUMINANCE16
:
3636 return MESA_FORMAT_L16
;
3637 case GL_LUMINANCE16F_ARB
:
3638 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3639 case GL_LUMINANCE32F_ARB
:
3640 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3641 case GL_LUMINANCE8I_EXT
:
3642 return MESA_FORMAT_LUMINANCE_INT8
;
3643 case GL_LUMINANCE16I_EXT
:
3644 return MESA_FORMAT_LUMINANCE_INT16
;
3645 case GL_LUMINANCE32I_EXT
:
3646 return MESA_FORMAT_LUMINANCE_INT32
;
3647 case GL_LUMINANCE8UI_EXT
:
3648 return MESA_FORMAT_LUMINANCE_UINT8
;
3649 case GL_LUMINANCE16UI_EXT
:
3650 return MESA_FORMAT_LUMINANCE_UINT16
;
3651 case GL_LUMINANCE32UI_EXT
:
3652 return MESA_FORMAT_LUMINANCE_UINT32
;
3653 case GL_LUMINANCE8_ALPHA8
:
3654 return MESA_FORMAT_AL88
;
3655 case GL_LUMINANCE16_ALPHA16
:
3656 return MESA_FORMAT_AL1616
;
3657 case GL_LUMINANCE_ALPHA16F_ARB
:
3658 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3659 case GL_LUMINANCE_ALPHA32F_ARB
:
3660 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3661 case GL_LUMINANCE_ALPHA8I_EXT
:
3662 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3663 case GL_LUMINANCE_ALPHA16I_EXT
:
3664 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3665 case GL_LUMINANCE_ALPHA32I_EXT
:
3666 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3667 case GL_LUMINANCE_ALPHA8UI_EXT
:
3668 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3669 case GL_LUMINANCE_ALPHA16UI_EXT
:
3670 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3671 case GL_LUMINANCE_ALPHA32UI_EXT
:
3672 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3674 return MESA_FORMAT_I8
;
3675 case GL_INTENSITY16
:
3676 return MESA_FORMAT_I16
;
3677 case GL_INTENSITY16F_ARB
:
3678 return MESA_FORMAT_INTENSITY_FLOAT16
;
3679 case GL_INTENSITY32F_ARB
:
3680 return MESA_FORMAT_INTENSITY_FLOAT32
;
3681 case GL_INTENSITY8I_EXT
:
3682 return MESA_FORMAT_INTENSITY_INT8
;
3683 case GL_INTENSITY16I_EXT
:
3684 return MESA_FORMAT_INTENSITY_INT16
;
3685 case GL_INTENSITY32I_EXT
:
3686 return MESA_FORMAT_INTENSITY_INT32
;
3687 case GL_INTENSITY8UI_EXT
:
3688 return MESA_FORMAT_INTENSITY_UINT8
;
3689 case GL_INTENSITY16UI_EXT
:
3690 return MESA_FORMAT_INTENSITY_UINT16
;
3691 case GL_INTENSITY32UI_EXT
:
3692 return MESA_FORMAT_INTENSITY_UINT32
;
3694 return MESA_FORMAT_RGBA8888_REV
;
3696 return MESA_FORMAT_RGBA_16
;
3697 case GL_RGBA16F_ARB
:
3698 return MESA_FORMAT_RGBA_FLOAT16
;
3699 case GL_RGBA32F_ARB
:
3700 return MESA_FORMAT_RGBA_FLOAT32
;
3702 return MESA_FORMAT_RGBA_INT8
;
3703 case GL_RGBA16I_EXT
:
3704 return MESA_FORMAT_RGBA_INT16
;
3705 case GL_RGBA32I_EXT
:
3706 return MESA_FORMAT_RGBA_INT32
;
3707 case GL_RGBA8UI_EXT
:
3708 return MESA_FORMAT_RGBA_UINT8
;
3709 case GL_RGBA16UI_EXT
:
3710 return MESA_FORMAT_RGBA_UINT16
;
3711 case GL_RGBA32UI_EXT
:
3712 return MESA_FORMAT_RGBA_UINT32
;
3715 return MESA_FORMAT_GR88
;
3717 return MESA_FORMAT_RG1616
;
3719 return MESA_FORMAT_RG_FLOAT16
;
3721 return MESA_FORMAT_RG_FLOAT32
;
3723 return MESA_FORMAT_RG_INT8
;
3725 return MESA_FORMAT_RG_INT16
;
3727 return MESA_FORMAT_RG_INT32
;
3729 return MESA_FORMAT_RG_UINT8
;
3731 return MESA_FORMAT_RG_UINT16
;
3733 return MESA_FORMAT_RG_UINT32
;
3736 return MESA_FORMAT_R8
;
3738 return MESA_FORMAT_R16
;
3740 return MESA_FORMAT_R_FLOAT16
;
3742 return MESA_FORMAT_R_FLOAT32
;
3744 return MESA_FORMAT_R_INT8
;
3746 return MESA_FORMAT_R_INT16
;
3748 return MESA_FORMAT_R_INT32
;
3750 return MESA_FORMAT_R_UINT8
;
3752 return MESA_FORMAT_R_UINT16
;
3754 return MESA_FORMAT_R_UINT32
;
3757 return MESA_FORMAT_NONE
;
3762 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3764 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
3767 if (format
== MESA_FORMAT_NONE
)
3768 return MESA_FORMAT_NONE
;
3770 datatype
= _mesa_get_format_datatype(format
);
3771 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3772 return MESA_FORMAT_NONE
;
3774 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3775 return MESA_FORMAT_NONE
;
3777 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
3778 * any mention of R/RG formats, but they appear in the GL 3.1 core
3781 if (ctx
->Version
<= 30) {
3782 GLenum base_format
= _mesa_get_format_base_format(format
);
3784 if (base_format
== GL_R
|| base_format
== GL_RG
)
3785 return MESA_FORMAT_NONE
;
3791 /** GL_ARB_texture_buffer_object */
3793 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3795 struct gl_texture_object
*texObj
;
3796 struct gl_buffer_object
*bufObj
;
3799 GET_CURRENT_CONTEXT(ctx
);
3800 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3802 if (!(ctx
->Extensions
.ARB_texture_buffer_object
3803 && _mesa_is_desktop_gl(ctx
))) {
3804 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3808 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3809 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3813 format
= validate_texbuffer_format(ctx
, internalFormat
);
3814 if (format
== MESA_FORMAT_NONE
) {
3815 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3820 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3821 if (buffer
&& !bufObj
) {
3822 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3826 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3828 _mesa_lock_texture(ctx
, texObj
);
3830 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3831 texObj
->BufferObjectFormat
= internalFormat
;
3832 texObj
->_BufferObjectFormat
= format
;
3834 _mesa_unlock_texture(ctx
, texObj
);