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 if (ctx
->Extensions
.S3_s3tc
) {
207 switch (internalFormat
) {
219 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
220 if (internalFormat
== GL_YCBCR_MESA
)
221 return GL_YCBCR_MESA
;
224 if (ctx
->Extensions
.ARB_texture_float
) {
225 switch (internalFormat
) {
226 case GL_ALPHA16F_ARB
:
227 case GL_ALPHA32F_ARB
:
235 case GL_INTENSITY16F_ARB
:
236 case GL_INTENSITY32F_ARB
:
238 case GL_LUMINANCE16F_ARB
:
239 case GL_LUMINANCE32F_ARB
:
241 case GL_LUMINANCE_ALPHA16F_ARB
:
242 case GL_LUMINANCE_ALPHA32F_ARB
:
243 return GL_LUMINANCE_ALPHA
;
249 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
250 switch (internalFormat
) {
259 if (ctx
->Extensions
.EXT_texture_snorm
) {
260 switch (internalFormat
) {
275 case GL_RGBA16_SNORM
:
278 case GL_ALPHA8_SNORM
:
279 case GL_ALPHA16_SNORM
:
281 case GL_LUMINANCE_SNORM
:
282 case GL_LUMINANCE8_SNORM
:
283 case GL_LUMINANCE16_SNORM
:
285 case GL_LUMINANCE_ALPHA_SNORM
:
286 case GL_LUMINANCE8_ALPHA8_SNORM
:
287 case GL_LUMINANCE16_ALPHA16_SNORM
:
288 return GL_LUMINANCE_ALPHA
;
289 case GL_INTENSITY_SNORM
:
290 case GL_INTENSITY8_SNORM
:
291 case GL_INTENSITY16_SNORM
:
298 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
299 switch (internalFormat
) {
300 case GL_DEPTH_STENCIL_EXT
:
301 case GL_DEPTH24_STENCIL8_EXT
:
302 return GL_DEPTH_STENCIL_EXT
;
308 if (ctx
->Extensions
.EXT_texture_sRGB
) {
309 switch (internalFormat
) {
312 case GL_COMPRESSED_SRGB_EXT
:
313 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
315 case GL_SRGB_ALPHA_EXT
:
316 case GL_SRGB8_ALPHA8_EXT
:
317 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
318 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
319 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
320 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
322 case GL_SLUMINANCE_ALPHA_EXT
:
323 case GL_SLUMINANCE8_ALPHA8_EXT
:
324 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
325 return GL_LUMINANCE_ALPHA
;
326 case GL_SLUMINANCE_EXT
:
327 case GL_SLUMINANCE8_EXT
:
328 case GL_COMPRESSED_SLUMINANCE_EXT
:
335 if (ctx
->Version
>= 30 ||
336 ctx
->Extensions
.EXT_texture_integer
) {
337 switch (internalFormat
) {
339 case GL_RGBA16UI_EXT
:
340 case GL_RGBA32UI_EXT
:
356 if (ctx
->Extensions
.EXT_texture_integer
) {
357 switch (internalFormat
) {
358 case GL_ALPHA8UI_EXT
:
359 case GL_ALPHA16UI_EXT
:
360 case GL_ALPHA32UI_EXT
:
362 case GL_ALPHA16I_EXT
:
363 case GL_ALPHA32I_EXT
:
365 case GL_INTENSITY8UI_EXT
:
366 case GL_INTENSITY16UI_EXT
:
367 case GL_INTENSITY32UI_EXT
:
368 case GL_INTENSITY8I_EXT
:
369 case GL_INTENSITY16I_EXT
:
370 case GL_INTENSITY32I_EXT
:
372 case GL_LUMINANCE8UI_EXT
:
373 case GL_LUMINANCE16UI_EXT
:
374 case GL_LUMINANCE32UI_EXT
:
375 case GL_LUMINANCE8I_EXT
:
376 case GL_LUMINANCE16I_EXT
:
377 case GL_LUMINANCE32I_EXT
:
379 case GL_LUMINANCE_ALPHA8UI_EXT
:
380 case GL_LUMINANCE_ALPHA16UI_EXT
:
381 case GL_LUMINANCE_ALPHA32UI_EXT
:
382 case GL_LUMINANCE_ALPHA8I_EXT
:
383 case GL_LUMINANCE_ALPHA16I_EXT
:
384 case GL_LUMINANCE_ALPHA32I_EXT
:
385 return GL_LUMINANCE_ALPHA
;
391 if (ctx
->Extensions
.ARB_texture_rg
) {
392 switch (internalFormat
) {
394 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
396 if (!ctx
->Extensions
.ARB_half_float_pixel
)
400 if (!ctx
->Extensions
.ARB_texture_float
)
409 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
415 case GL_COMPRESSED_RED
:
419 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
421 if (!ctx
->Extensions
.ARB_half_float_pixel
)
425 if (!ctx
->Extensions
.ARB_texture_float
)
434 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
440 case GL_COMPRESSED_RG
:
447 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
448 switch (internalFormat
) {
456 if (ctx
->Extensions
.EXT_packed_float
) {
457 switch (internalFormat
) {
458 case GL_R11F_G11F_B10F_EXT
:
465 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
466 switch (internalFormat
) {
467 case GL_DEPTH_COMPONENT32F
:
468 return GL_DEPTH_COMPONENT
;
469 case GL_DEPTH32F_STENCIL8
:
470 return GL_DEPTH_STENCIL
;
476 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
477 switch (internalFormat
) {
478 case GL_COMPRESSED_RED_RGTC1
:
479 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
481 case GL_COMPRESSED_RG_RGTC2
:
482 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
489 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
490 switch (internalFormat
) {
491 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
492 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
494 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
495 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
496 return GL_LUMINANCE_ALPHA
;
502 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
503 switch (internalFormat
) {
504 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
505 return GL_LUMINANCE_ALPHA
;
511 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
512 switch (internalFormat
) {
513 case GL_ETC1_RGB8_OES
:
520 if (ctx
->API
== API_OPENGLES
) {
521 switch (internalFormat
) {
522 case GL_PALETTE4_RGB8_OES
:
523 case GL_PALETTE4_R5_G6_B5_OES
:
524 case GL_PALETTE8_RGB8_OES
:
525 case GL_PALETTE8_R5_G6_B5_OES
:
527 case GL_PALETTE4_RGBA8_OES
:
528 case GL_PALETTE8_RGB5_A1_OES
:
529 case GL_PALETTE4_RGBA4_OES
:
530 case GL_PALETTE4_RGB5_A1_OES
:
531 case GL_PALETTE8_RGBA8_OES
:
532 case GL_PALETTE8_RGBA4_OES
:
539 return -1; /* error */
544 * For cube map faces, return a face index in [0,5].
545 * For other targets return 0;
548 _mesa_tex_target_to_face(GLenum target
)
550 if (_mesa_is_cube_face(target
))
551 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
559 * Install gl_texture_image in a gl_texture_object according to the target
560 * and level parameters.
562 * \param tObj texture object.
563 * \param target texture target.
564 * \param level image level.
565 * \param texImage texture image.
568 set_tex_image(struct gl_texture_object
*tObj
,
569 GLenum target
, GLint level
,
570 struct gl_texture_image
*texImage
)
572 const GLuint face
= _mesa_tex_target_to_face(target
);
576 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
579 tObj
->Image
[face
][level
] = texImage
;
581 /* Set the 'back' pointer */
582 texImage
->TexObject
= tObj
;
583 texImage
->Level
= level
;
584 texImage
->Face
= face
;
589 * Allocate a texture image structure.
591 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
594 * \return a pointer to gl_texture_image struct with all fields initialized to
597 struct gl_texture_image
*
598 _mesa_new_texture_image( struct gl_context
*ctx
)
601 return CALLOC_STRUCT(gl_texture_image
);
606 * Free a gl_texture_image and associated data.
607 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
609 * \param texImage texture image.
611 * Free the texture image structure and the associated image data.
614 _mesa_delete_texture_image(struct gl_context
*ctx
,
615 struct gl_texture_image
*texImage
)
617 /* Free texImage->Data and/or any other driver-specific texture
620 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
621 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
627 * Test if a target is a proxy target.
629 * \param target texture target.
631 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
634 _mesa_is_proxy_texture(GLenum target
)
637 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
638 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
640 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
642 return (target
== GL_PROXY_TEXTURE_1D
||
643 target
== GL_PROXY_TEXTURE_2D
||
644 target
== GL_PROXY_TEXTURE_3D
||
645 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
646 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
647 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
648 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
653 * Return the proxy target which corresponds to the given texture target
656 _mesa_get_proxy_target(GLenum target
)
660 case GL_PROXY_TEXTURE_1D
:
661 return GL_PROXY_TEXTURE_1D
;
663 case GL_PROXY_TEXTURE_2D
:
664 return GL_PROXY_TEXTURE_2D
;
666 case GL_PROXY_TEXTURE_3D
:
667 return GL_PROXY_TEXTURE_3D
;
668 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
669 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
670 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
671 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
672 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
673 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
674 case GL_TEXTURE_CUBE_MAP_ARB
:
675 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
676 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
677 case GL_TEXTURE_RECTANGLE_NV
:
678 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
679 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
680 case GL_TEXTURE_1D_ARRAY_EXT
:
681 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
682 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
683 case GL_TEXTURE_2D_ARRAY_EXT
:
684 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
685 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
687 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
694 * Get the texture object that corresponds to the target of the given
695 * texture unit. The target should have already been checked for validity.
697 * \param ctx GL context.
698 * \param texUnit texture unit.
699 * \param target texture target.
701 * \return pointer to the texture object on success, or NULL on failure.
703 struct gl_texture_object
*
704 _mesa_select_tex_object(struct gl_context
*ctx
,
705 const struct gl_texture_unit
*texUnit
,
708 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
709 ctx
->Extensions
.EXT_texture_array
);
713 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
714 case GL_PROXY_TEXTURE_1D
:
715 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
717 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
718 case GL_PROXY_TEXTURE_2D
:
719 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
721 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
722 case GL_PROXY_TEXTURE_3D
:
723 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
724 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
725 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
726 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
727 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
728 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
729 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
730 case GL_TEXTURE_CUBE_MAP_ARB
:
731 return ctx
->Extensions
.ARB_texture_cube_map
732 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
733 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
734 return ctx
->Extensions
.ARB_texture_cube_map
735 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
736 case GL_TEXTURE_RECTANGLE_NV
:
737 return ctx
->Extensions
.NV_texture_rectangle
738 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
739 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
740 return ctx
->Extensions
.NV_texture_rectangle
741 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
742 case GL_TEXTURE_1D_ARRAY_EXT
:
743 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
744 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
745 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
746 case GL_TEXTURE_2D_ARRAY_EXT
:
747 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
748 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
749 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
750 case GL_TEXTURE_BUFFER
:
751 return _mesa_is_desktop_gl(ctx
)
752 && ctx
->Extensions
.ARB_texture_buffer_object
753 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
754 case GL_TEXTURE_EXTERNAL_OES
:
755 return ctx
->Extensions
.OES_EGL_image_external
756 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
758 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
765 * Return pointer to texture object for given target on current texture unit.
767 struct gl_texture_object
*
768 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
770 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
771 return _mesa_select_tex_object(ctx
, texUnit
, target
);
776 * Get a texture image pointer from a texture object, given a texture
777 * target and mipmap level. The target and level parameters should
778 * have already been error-checked.
780 * \param ctx GL context.
781 * \param texObj texture unit.
782 * \param target texture target.
783 * \param level image level.
785 * \return pointer to the texture image structure, or NULL on failure.
787 struct gl_texture_image
*
788 _mesa_select_tex_image(struct gl_context
*ctx
,
789 const struct gl_texture_object
*texObj
,
790 GLenum target
, GLint level
)
792 const GLuint face
= _mesa_tex_target_to_face(target
);
796 ASSERT(level
< MAX_TEXTURE_LEVELS
);
798 return texObj
->Image
[face
][level
];
803 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
804 * it and install it. Only return NULL if passed a bad parameter or run
807 struct gl_texture_image
*
808 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
809 GLenum target
, GLint level
)
811 struct gl_texture_image
*texImage
;
816 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
818 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
820 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
824 set_tex_image(texObj
, target
, level
, texImage
);
832 * Return pointer to the specified proxy texture image.
833 * Note that proxy textures are per-context, not per-texture unit.
834 * \return pointer to texture image or NULL if invalid target, invalid
835 * level, or out of memory.
837 static struct gl_texture_image
*
838 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
840 struct gl_texture_image
*texImage
;
847 case GL_PROXY_TEXTURE_1D
:
848 if (level
>= ctx
->Const
.MaxTextureLevels
)
850 texIndex
= TEXTURE_1D_INDEX
;
852 case GL_PROXY_TEXTURE_2D
:
853 if (level
>= ctx
->Const
.MaxTextureLevels
)
855 texIndex
= TEXTURE_2D_INDEX
;
857 case GL_PROXY_TEXTURE_3D
:
858 if (level
>= ctx
->Const
.Max3DTextureLevels
)
860 texIndex
= TEXTURE_3D_INDEX
;
862 case GL_PROXY_TEXTURE_CUBE_MAP
:
863 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
865 texIndex
= TEXTURE_CUBE_INDEX
;
867 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
870 texIndex
= TEXTURE_RECT_INDEX
;
872 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
873 if (level
>= ctx
->Const
.MaxTextureLevels
)
875 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
877 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
878 if (level
>= ctx
->Const
.MaxTextureLevels
)
880 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
886 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
888 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
890 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
893 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
894 /* Set the 'back' pointer */
895 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
902 * Get the maximum number of allowed mipmap levels.
904 * \param ctx GL context.
905 * \param target texture target.
907 * \return the maximum number of allowed mipmap levels for the given
908 * texture target, or zero if passed a bad target.
913 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
917 case GL_PROXY_TEXTURE_1D
:
919 case GL_PROXY_TEXTURE_2D
:
920 return ctx
->Const
.MaxTextureLevels
;
922 case GL_PROXY_TEXTURE_3D
:
923 return ctx
->Const
.Max3DTextureLevels
;
924 case GL_TEXTURE_CUBE_MAP
:
925 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
926 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
927 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
928 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
929 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
930 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
931 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
932 return ctx
->Extensions
.ARB_texture_cube_map
933 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
934 case GL_TEXTURE_RECTANGLE_NV
:
935 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
936 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
937 case GL_TEXTURE_1D_ARRAY_EXT
:
938 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
939 case GL_TEXTURE_2D_ARRAY_EXT
:
940 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
941 return (ctx
->Extensions
.MESA_texture_array
||
942 ctx
->Extensions
.EXT_texture_array
)
943 ? ctx
->Const
.MaxTextureLevels
: 0;
944 case GL_TEXTURE_BUFFER
:
945 return _mesa_is_desktop_gl(ctx
)
946 && ctx
->Extensions
.ARB_texture_buffer_object
948 case GL_TEXTURE_EXTERNAL_OES
:
951 return 0; /* bad target */
957 * Return number of dimensions per mipmap level for the given texture target.
960 _mesa_get_texture_dimensions(GLenum target
)
964 case GL_PROXY_TEXTURE_1D
:
967 case GL_TEXTURE_RECTANGLE
:
968 case GL_TEXTURE_CUBE_MAP
:
969 case GL_PROXY_TEXTURE_2D
:
970 case GL_PROXY_TEXTURE_RECTANGLE
:
971 case GL_PROXY_TEXTURE_CUBE_MAP
:
972 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
973 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
974 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
975 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
976 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
977 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
978 case GL_TEXTURE_1D_ARRAY
:
979 case GL_PROXY_TEXTURE_1D_ARRAY
:
980 case GL_TEXTURE_EXTERNAL_OES
:
983 case GL_PROXY_TEXTURE_3D
:
984 case GL_TEXTURE_2D_ARRAY
:
985 case GL_PROXY_TEXTURE_2D_ARRAY
:
987 case GL_TEXTURE_BUFFER
:
990 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
999 #if 000 /* not used anymore */
1001 * glTexImage[123]D can accept a NULL image pointer. In this case we
1002 * create a texture image with unspecified image contents per the OpenGL
1006 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1008 const GLint components
= _mesa_components_in_format(format
);
1009 const GLint numPixels
= width
* height
* depth
;
1010 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1014 * Let's see if anyone finds this. If glTexImage2D() is called with
1015 * a NULL image pointer then load the texture image with something
1016 * interesting instead of leaving it indeterminate.
1019 static const char message
[8][32] = {
1020 " X X XXXXX XXX X ",
1021 " XX XX X X X X X ",
1023 " X X XXXX XXX XXXXX ",
1026 " X X XXXXX XXX X X ",
1030 GLubyte
*imgPtr
= data
;
1032 for (h
= 0; h
< depth
; h
++) {
1033 for (i
= 0; i
< height
; i
++) {
1034 GLint srcRow
= 7 - (i
% 8);
1035 for (j
= 0; j
< width
; j
++) {
1036 GLint srcCol
= j
% 32;
1037 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1038 for (k
= 0; k
< components
; k
++) {
1054 * Set the size and format-related fields of a gl_texture_image struct
1055 * to zero. This is used when a proxy texture test fails.
1058 clear_teximage_fields(struct gl_texture_image
*img
)
1061 img
->_BaseFormat
= 0;
1062 img
->InternalFormat
= 0;
1071 img
->HeightLog2
= 0;
1073 img
->TexFormat
= MESA_FORMAT_NONE
;
1078 * Initialize basic fields of the gl_texture_image struct.
1080 * \param ctx GL context.
1081 * \param img texture image structure to be initialized.
1082 * \param width image width.
1083 * \param height image height.
1084 * \param depth image depth.
1085 * \param border image border.
1086 * \param internalFormat internal format.
1087 * \param format the actual hardware format (one of MESA_FORMAT_*)
1089 * Fills in the fields of \p img with the given information.
1090 * Note: width, height and depth include the border.
1093 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1094 struct gl_texture_image
*img
,
1095 GLsizei width
, GLsizei height
, GLsizei depth
,
1096 GLint border
, GLenum internalFormat
,
1102 ASSERT(height
>= 0);
1105 target
= img
->TexObject
->Target
;
1106 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1107 ASSERT(img
->_BaseFormat
> 0);
1108 img
->InternalFormat
= internalFormat
;
1109 img
->Border
= border
;
1111 img
->Height
= height
;
1114 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1115 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1119 case GL_TEXTURE_BUFFER
:
1120 case GL_PROXY_TEXTURE_1D
:
1125 img
->HeightLog2
= 0;
1132 case GL_TEXTURE_1D_ARRAY
:
1133 case GL_PROXY_TEXTURE_1D_ARRAY
:
1134 img
->Height2
= height
; /* no border */
1135 img
->HeightLog2
= 0; /* not used */
1143 case GL_TEXTURE_RECTANGLE
:
1144 case GL_TEXTURE_CUBE_MAP
:
1145 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1146 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1147 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1148 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1149 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1150 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1151 case GL_TEXTURE_EXTERNAL_OES
:
1152 case GL_PROXY_TEXTURE_2D
:
1153 case GL_PROXY_TEXTURE_RECTANGLE
:
1154 case GL_PROXY_TEXTURE_CUBE_MAP
:
1155 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1156 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1163 case GL_TEXTURE_2D_ARRAY
:
1164 case GL_PROXY_TEXTURE_2D_ARRAY
:
1165 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1166 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1167 img
->Depth2
= depth
; /* no border */
1168 img
->DepthLog2
= 0; /* not used */
1171 case GL_PROXY_TEXTURE_3D
:
1172 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1173 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1174 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1175 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1178 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1182 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1183 img
->TexFormat
= format
;
1188 * Free and clear fields of the gl_texture_image struct.
1190 * \param ctx GL context.
1191 * \param texImage texture image structure to be cleared.
1193 * After the call, \p texImage will have no data associated with it. Its
1194 * fields are cleared so that its parent object will test incomplete.
1197 _mesa_clear_texture_image(struct gl_context
*ctx
,
1198 struct gl_texture_image
*texImage
)
1200 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1201 clear_teximage_fields(texImage
);
1206 * Check the width, height, depth and border of a texture image are legal.
1207 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1209 * The target and level parameters will have already been validated.
1210 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1213 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1214 GLint level
, GLint width
, GLint height
,
1215 GLint depth
, GLint border
)
1221 case GL_PROXY_TEXTURE_1D
:
1222 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1223 maxSize
>>= level
; /* level size */
1224 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1226 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1227 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1233 case GL_PROXY_TEXTURE_2D
:
1234 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1236 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1238 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1240 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1241 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1243 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1249 case GL_PROXY_TEXTURE_3D
:
1250 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1252 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1254 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1256 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1258 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1259 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1261 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1263 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1268 case GL_TEXTURE_RECTANGLE_NV
:
1269 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1272 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1273 if (width
< 0 || width
> maxSize
)
1275 if (height
< 0 || height
> maxSize
)
1279 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1280 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1281 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1282 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1283 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1284 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1285 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1286 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1288 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1290 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1292 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1293 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1295 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1300 case GL_TEXTURE_1D_ARRAY_EXT
:
1301 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1302 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1304 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1306 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1308 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1309 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1314 case GL_TEXTURE_2D_ARRAY_EXT
:
1315 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1316 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1318 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1320 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1322 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1324 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1325 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1327 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1333 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1340 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1341 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1342 * \param destImage the destination texture image.
1343 * \return GL_TRUE if error found, GL_FALSE otherwise.
1346 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1347 const char *function
, GLuint dims
,
1348 const struct gl_texture_image
*destImage
,
1349 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1350 GLsizei subWidth
, GLsizei subHeight
,
1353 const GLenum target
= destImage
->TexObject
->Target
;
1358 _mesa_error(ctx
, GL_INVALID_VALUE
,
1359 "%s%dD(width=%d)", function
, dims
, subWidth
);
1363 if (dims
> 1 && subHeight
< 0) {
1364 _mesa_error(ctx
, GL_INVALID_VALUE
,
1365 "%s%dD(height=%d)", function
, dims
, subHeight
);
1369 if (dims
> 2 && subDepth
< 0) {
1370 _mesa_error(ctx
, GL_INVALID_VALUE
,
1371 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1375 /* check xoffset and width */
1376 if (xoffset
< -destImage
->Border
) {
1377 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1382 if (xoffset
+ subWidth
> destImage
->Width
) {
1383 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1388 /* check yoffset and height */
1390 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1391 if (yoffset
< -yBorder
) {
1392 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1396 if (yoffset
+ subHeight
> destImage
->Height
) {
1397 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1403 /* check zoffset and depth */
1405 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1406 if (zoffset
< -zBorder
) {
1407 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1410 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1411 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1417 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1418 * compressed texture images can be updated. But, that restriction may be
1419 * relaxed for particular compressed formats. At this time, all the
1420 * compressed formats supported by Mesa allow sub-textures to be updated
1421 * along compressed block boundaries.
1423 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1425 if (bw
!= 1 || bh
!= 1) {
1426 /* offset must be multiple of block size */
1427 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1428 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1429 "%s%dD(xoffset = %d, yoffset = %d)",
1430 function
, dims
, xoffset
, yoffset
);
1434 /* size must be multiple of bw by bh or equal to whole texture size */
1435 if ((subWidth
% bw
!= 0) && subWidth
!= destImage
->Width
) {
1436 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1437 "%s%dD(width = %d)", function
, dims
, subWidth
);
1441 if ((subHeight
% bh
!= 0) && subHeight
!= destImage
->Height
) {
1442 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1443 "%s%dD(height = %d)", function
, dims
, subHeight
);
1455 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1456 * specific texture image size checks.
1458 * A hardware driver might override this function if, for example, the
1459 * max 3D texture size is 512x512x64 (i.e. not a cube).
1461 * Note that width, height, depth == 0 is not an error. However, a
1462 * texture with zero width/height/depth will be considered "incomplete"
1463 * and texturing will effectively be disabled.
1465 * \param target any texture target/type
1466 * \param level as passed to glTexImage
1467 * \param format the MESA_FORMAT_x for the tex image
1468 * \param width as passed to glTexImage
1469 * \param height as passed to glTexImage
1470 * \param depth as passed to glTexImage
1471 * \param border as passed to glTexImage
1472 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1475 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1477 GLint width
, GLint height
, GLint depth
, GLint border
)
1479 /* We just check if the image size is less than MaxTextureMbytes.
1480 * Some drivers may do more specific checks.
1482 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1483 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1484 mbytes
*= _mesa_num_tex_faces(target
);
1485 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1490 * Return true if the format is only valid for glCompressedTexImage.
1493 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1496 case GL_ETC1_RGB8_OES
:
1497 case GL_PALETTE4_RGB8_OES
:
1498 case GL_PALETTE4_RGBA8_OES
:
1499 case GL_PALETTE4_R5_G6_B5_OES
:
1500 case GL_PALETTE4_RGBA4_OES
:
1501 case GL_PALETTE4_RGB5_A1_OES
:
1502 case GL_PALETTE8_RGB8_OES
:
1503 case GL_PALETTE8_RGBA8_OES
:
1504 case GL_PALETTE8_R5_G6_B5_OES
:
1505 case GL_PALETTE8_RGBA4_OES
:
1506 case GL_PALETTE8_RGB5_A1_OES
:
1515 * Helper function to determine whether a target and specific compression
1516 * format are supported.
1519 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1522 (void) intFormat
; /* not used yet */
1526 case GL_PROXY_TEXTURE_2D
:
1527 return GL_TRUE
; /* true for any compressed format so far */
1528 case GL_PROXY_TEXTURE_CUBE_MAP
:
1529 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1530 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1531 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1532 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1533 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1534 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1535 return ctx
->Extensions
.ARB_texture_cube_map
;
1536 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1537 case GL_TEXTURE_2D_ARRAY_EXT
:
1538 return (ctx
->Extensions
.MESA_texture_array
||
1539 ctx
->Extensions
.EXT_texture_array
);
1547 * Check if the given texture target value is legal for a
1548 * glTexImage1/2/3D call.
1551 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1557 case GL_PROXY_TEXTURE_1D
:
1558 return _mesa_is_desktop_gl(ctx
);
1566 case GL_PROXY_TEXTURE_2D
:
1567 return _mesa_is_desktop_gl(ctx
);
1568 case GL_PROXY_TEXTURE_CUBE_MAP
:
1569 return _mesa_is_desktop_gl(ctx
)
1570 && ctx
->Extensions
.ARB_texture_cube_map
;
1571 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1572 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1573 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1574 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1575 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1576 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1577 return ctx
->Extensions
.ARB_texture_cube_map
;
1578 case GL_TEXTURE_RECTANGLE_NV
:
1579 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1580 return _mesa_is_desktop_gl(ctx
)
1581 && ctx
->Extensions
.NV_texture_rectangle
;
1582 case GL_TEXTURE_1D_ARRAY_EXT
:
1583 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1584 return _mesa_is_desktop_gl(ctx
)
1585 && (ctx
->Extensions
.MESA_texture_array
||
1586 ctx
->Extensions
.EXT_texture_array
);
1594 case GL_PROXY_TEXTURE_3D
:
1595 return _mesa_is_desktop_gl(ctx
);
1596 case GL_TEXTURE_2D_ARRAY_EXT
:
1597 return (_mesa_is_desktop_gl(ctx
)
1598 && (ctx
->Extensions
.MESA_texture_array
||
1599 ctx
->Extensions
.EXT_texture_array
))
1600 || _mesa_is_gles3(ctx
);
1601 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1602 return _mesa_is_desktop_gl(ctx
)
1603 && (ctx
->Extensions
.MESA_texture_array
||
1604 ctx
->Extensions
.EXT_texture_array
);
1609 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1616 * Check if the given texture target value is legal for a
1617 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1618 * The difference compared to legal_teximage_target() above is that
1619 * proxy targets are not supported.
1622 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1626 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1631 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1632 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1633 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1634 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1635 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1636 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1637 return ctx
->Extensions
.ARB_texture_cube_map
;
1638 case GL_TEXTURE_RECTANGLE_NV
:
1639 return _mesa_is_desktop_gl(ctx
)
1640 && ctx
->Extensions
.NV_texture_rectangle
;
1641 case GL_TEXTURE_1D_ARRAY_EXT
:
1642 return _mesa_is_desktop_gl(ctx
)
1643 && (ctx
->Extensions
.MESA_texture_array
||
1644 ctx
->Extensions
.EXT_texture_array
);
1652 case GL_TEXTURE_2D_ARRAY_EXT
:
1653 return (_mesa_is_desktop_gl(ctx
)
1654 && (ctx
->Extensions
.MESA_texture_array
||
1655 ctx
->Extensions
.EXT_texture_array
))
1656 || _mesa_is_gles3(ctx
);
1661 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1669 * Helper function to determine if a texture object is mutable (in terms
1670 * of GL_ARB_texture_storage).
1673 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1675 if (ctx
->Extensions
.ARB_texture_storage
) {
1676 struct gl_texture_object
*texObj
=
1677 _mesa_get_current_tex_object(ctx
, target
);
1678 return !texObj
->Immutable
;
1685 * Return expected size of a compressed texture.
1688 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1691 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1692 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1697 * Test the glTexImage[123]D() parameters for errors.
1699 * \param ctx GL context.
1700 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1701 * \param target texture target given by the user (already validated).
1702 * \param level image level given by the user.
1703 * \param internalFormat internal format given by the user.
1704 * \param format pixel data format given by the user.
1705 * \param type pixel data type given by the user.
1706 * \param width image width given by the user.
1707 * \param height image height given by the user.
1708 * \param depth image depth given by the user.
1709 * \param border image border given by the user.
1711 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1713 * Verifies each of the parameters against the constants specified in
1714 * __struct gl_contextRec::Const and the supported extensions, and according
1715 * to the OpenGL specification.
1716 * Note that we don't fully error-check the width, height, depth values
1717 * here. That's done in _mesa_legal_texture_dimensions() which is used
1718 * by several other GL entrypoints. Plus, texture dims have a special
1719 * interaction with proxy textures.
1722 texture_error_check( struct gl_context
*ctx
,
1723 GLuint dimensions
, GLenum target
,
1724 GLint level
, GLint internalFormat
,
1725 GLenum format
, GLenum type
,
1726 GLint width
, GLint height
,
1727 GLint depth
, GLint border
)
1729 GLboolean colorFormat
;
1732 /* Even though there are no color-index textures, we still have to support
1733 * uploading color-index data and remapping it to RGB via the
1734 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1736 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1738 /* Note: for proxy textures, some error conditions immediately generate
1739 * a GL error in the usual way. But others do not generate a GL error.
1740 * Instead, they cause the width, height, depth, format fields of the
1741 * texture image to be zeroed-out. The GL spec seems to indicate that the
1742 * zero-out behaviour is only used in cases related to memory allocation.
1746 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1747 _mesa_error(ctx
, GL_INVALID_VALUE
,
1748 "glTexImage%dD(level=%d)", dimensions
, level
);
1753 if (border
< 0 || border
> 1 ||
1754 ((ctx
->API
!= API_OPENGL
||
1755 target
== GL_TEXTURE_RECTANGLE_NV
||
1756 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1757 _mesa_error(ctx
, GL_INVALID_VALUE
,
1758 "glTexImage%dD(border=%d)", dimensions
, border
);
1762 if (width
< 0 || height
< 0 || depth
< 0) {
1763 _mesa_error(ctx
, GL_INVALID_VALUE
,
1764 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1768 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1769 * combinations of format, internalFormat, and type that can be used.
1770 * Formats and types that require additional extensions (e.g., GL_FLOAT
1771 * requires GL_OES_texture_float) are filtered elsewhere.
1773 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
1774 if (format
!= internalFormat
) {
1775 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1776 "glTexImage%dD(format = %s, internalFormat = %s)",
1778 _mesa_lookup_enum_by_nr(format
),
1779 _mesa_lookup_enum_by_nr(internalFormat
));
1783 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1784 if (err
!= GL_NO_ERROR
) {
1785 _mesa_error(ctx
, err
,
1786 "glTexImage%dD(format = %s, type = %s)",
1788 _mesa_lookup_enum_by_nr(format
),
1789 _mesa_lookup_enum_by_nr(type
));
1794 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1795 _mesa_is_cube_face(target
)) && width
!= height
) {
1796 _mesa_error(ctx
, GL_INVALID_VALUE
,
1797 "glTexImage2D(cube width != height)");
1801 /* Check internalFormat */
1802 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1803 _mesa_error(ctx
, GL_INVALID_VALUE
,
1804 "glTexImage%dD(internalFormat=%s)",
1805 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1809 /* Check incoming image format and type */
1810 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1811 if (err
!= GL_NO_ERROR
) {
1812 _mesa_error(ctx
, err
,
1813 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1814 dimensions
, format
, type
);
1818 /* make sure internal format and format basically agree */
1819 colorFormat
= _mesa_is_color_format(format
);
1820 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1821 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1822 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1823 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1824 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1825 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1826 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1827 dimensions
, internalFormat
, format
);
1831 /* additional checks for ycbcr textures */
1832 if (internalFormat
== GL_YCBCR_MESA
) {
1833 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1834 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1835 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1837 _mesa_snprintf(message
, sizeof(message
),
1838 "glTexImage%dD(format/type YCBCR mismatch)",
1840 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1841 return GL_TRUE
; /* error */
1843 if (target
!= GL_TEXTURE_2D
&&
1844 target
!= GL_PROXY_TEXTURE_2D
&&
1845 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1846 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1847 _mesa_error(ctx
, GL_INVALID_ENUM
,
1848 "glTexImage%dD(bad target for YCbCr texture)",
1854 _mesa_snprintf(message
, sizeof(message
),
1855 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1856 dimensions
, border
);
1857 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1862 /* additional checks for depth textures */
1863 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1864 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1865 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1866 if (target
!= GL_TEXTURE_1D
&&
1867 target
!= GL_PROXY_TEXTURE_1D
&&
1868 target
!= GL_TEXTURE_2D
&&
1869 target
!= GL_PROXY_TEXTURE_2D
&&
1870 target
!= GL_TEXTURE_1D_ARRAY
&&
1871 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1872 target
!= GL_TEXTURE_2D_ARRAY
&&
1873 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1874 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1875 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1876 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1877 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))) {
1878 _mesa_error(ctx
, GL_INVALID_ENUM
,
1879 "glTexImage%dD(bad target for depth texture)",
1885 /* additional checks for compressed textures */
1886 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1887 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1888 _mesa_error(ctx
, GL_INVALID_ENUM
,
1889 "glTexImage%dD(target can't be compressed)", dimensions
);
1892 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1893 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1894 "glTexImage%dD(no compression for format)", dimensions
);
1898 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1899 "glTexImage%dD(border!=0)", dimensions
);
1904 /* additional checks for integer textures */
1905 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1906 (_mesa_is_enum_format_integer(format
) !=
1907 _mesa_is_enum_format_integer(internalFormat
))) {
1908 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1909 "glTexImage%dD(integer/non-integer format mismatch)",
1914 if (!mutable_tex_object(ctx
, target
)) {
1915 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1916 "glTexImage%dD(immutable texture)", dimensions
);
1920 /* if we get here, the parameters are OK */
1926 * Error checking for glCompressedTexImage[123]D().
1927 * Note that the width, height and depth values are not fully error checked
1929 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1932 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
1933 GLenum target
, GLint level
,
1934 GLenum internalFormat
, GLsizei width
,
1935 GLsizei height
, GLsizei depth
, GLint border
,
1938 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
1940 GLenum choose_format
;
1942 GLenum proxy_format
;
1943 GLenum error
= GL_NO_ERROR
;
1944 char *reason
= ""; /* no error */
1946 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1948 error
= GL_INVALID_ENUM
;
1952 /* This will detect any invalid internalFormat value */
1953 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
1954 reason
= "internalFormat";
1955 error
= GL_INVALID_ENUM
;
1959 switch (internalFormat
) {
1961 case GL_PALETTE4_RGB8_OES
:
1962 case GL_PALETTE4_RGBA8_OES
:
1963 case GL_PALETTE4_R5_G6_B5_OES
:
1964 case GL_PALETTE4_RGBA4_OES
:
1965 case GL_PALETTE4_RGB5_A1_OES
:
1966 case GL_PALETTE8_RGB8_OES
:
1967 case GL_PALETTE8_RGBA8_OES
:
1968 case GL_PALETTE8_R5_G6_B5_OES
:
1969 case GL_PALETTE8_RGBA4_OES
:
1970 case GL_PALETTE8_RGB5_A1_OES
:
1971 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
1973 proxy_format
= choose_format
;
1975 /* check level (note that level should be zero or less!) */
1976 if (level
> 0 || level
< -maxLevels
) {
1978 error
= GL_INVALID_VALUE
;
1982 if (dimensions
!= 2) {
1983 reason
= "compressed paletted textures must be 2D";
1984 error
= GL_INVALID_OPERATION
;
1988 /* Figure out the expected texture size (in bytes). This will be
1989 * checked against the actual size later.
1991 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
1994 /* This is for the benefit of the TestProxyTexImage below. It expects
1995 * level to be non-negative. OES_compressed_paletted_texture uses a
1996 * weird mechanism where the level specified to glCompressedTexImage2D
1997 * is -(n-1) number of levels in the texture, and the data specifies the
1998 * complete mipmap stack. This is done to ensure the palette is the
1999 * same for all levels.
2006 choose_format
= GL_NONE
;
2007 choose_type
= GL_NONE
;
2008 proxy_format
= internalFormat
;
2011 if (level
< 0 || level
>= maxLevels
) {
2013 error
= GL_INVALID_VALUE
;
2017 /* Figure out the expected texture size (in bytes). This will be
2018 * checked against the actual size later.
2020 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2024 /* This should really never fail */
2025 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2026 reason
= "internalFormat";
2027 error
= GL_INVALID_ENUM
;
2031 /* No compressed formats support borders at this time */
2033 reason
= "border != 0";
2034 error
= GL_INVALID_VALUE
;
2038 /* For cube map, width must equal height */
2039 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2040 _mesa_is_cube_face(target
)) && width
!= height
) {
2041 reason
= "width != height";
2042 error
= GL_INVALID_VALUE
;
2046 /* check image size against compression block size */
2047 /* XXX possibly move this into the _mesa_legal_texture_dimensions() func */
2049 gl_format texFormat
=
2050 ctx
->Driver
.ChooseTextureFormat(ctx
, target
, proxy_format
,
2051 choose_format
, choose_type
);
2054 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
2055 if ((width
> bw
&& width
% bw
> 0) ||
2056 (height
> bh
&& height
% bh
> 0)) {
2058 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
2059 * generated [...] if any parameter combinations are not
2060 * supported by the specific compressed internal format.
2062 reason
= "invalid width or height for compression format";
2063 error
= GL_INVALID_OPERATION
;
2068 /* check image size in bytes */
2069 if (expectedSize
!= imageSize
) {
2070 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2071 * if <imageSize> is not consistent with the format, dimensions, and
2072 * contents of the specified image.
2074 reason
= "imageSize inconsistant with width/height/format";
2075 error
= GL_INVALID_VALUE
;
2079 if (!mutable_tex_object(ctx
, target
)) {
2080 reason
= "immutable texture";
2081 error
= GL_INVALID_OPERATION
;
2088 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2095 * Test glTexSubImage[123]D() parameters for errors.
2097 * \param ctx GL context.
2098 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2099 * \param target texture target given by the user (already validated)
2100 * \param level image level given by the user.
2101 * \param xoffset sub-image x offset given by the user.
2102 * \param yoffset sub-image y offset given by the user.
2103 * \param zoffset sub-image z offset given by the user.
2104 * \param format pixel data format given by the user.
2105 * \param type pixel data type given by the user.
2106 * \param width image width given by the user.
2107 * \param height image height given by the user.
2108 * \param depth image depth given by the user.
2110 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2112 * Verifies each of the parameters against the constants specified in
2113 * __struct gl_contextRec::Const and the supported extensions, and according
2114 * to the OpenGL specification.
2117 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2118 GLenum target
, GLint level
,
2119 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2120 GLint width
, GLint height
, GLint depth
,
2121 GLenum format
, GLenum type
)
2123 struct gl_texture_object
*texObj
;
2124 struct gl_texture_image
*texImage
;
2127 /* check target (proxies not allowed) */
2128 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2129 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2130 dimensions
, _mesa_lookup_enum_by_nr(target
));
2135 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2136 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2141 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2142 * combinations of format and type that can be used. Formats and types
2143 * that require additional extensions (e.g., GL_FLOAT requires
2144 * GL_OES_texture_float) are filtered elsewhere.
2146 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2147 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2148 if (err
!= GL_NO_ERROR
) {
2149 _mesa_error(ctx
, err
,
2150 "glTexSubImage%dD(format = %s, type = %s)",
2152 _mesa_lookup_enum_by_nr(format
),
2153 _mesa_lookup_enum_by_nr(type
));
2158 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2159 if (err
!= GL_NO_ERROR
) {
2160 _mesa_error(ctx
, err
,
2161 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
2162 dimensions
, format
, type
);
2166 /* Get dest texture object / image pointers */
2167 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2169 /* must be out of memory */
2170 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2174 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2176 /* non-existant texture level */
2177 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2178 "glTexSubImage%dD(invalid texture image)", dimensions
);
2182 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2183 texImage
, xoffset
, yoffset
, 0,
2184 width
, height
, 1)) {
2188 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2189 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2190 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2191 "glTexSubImage%dD(no compression for format)", dimensions
);
2196 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2197 /* both source and dest must be integer-valued, or neither */
2198 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2199 _mesa_is_enum_format_integer(format
)) {
2200 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2201 "glTexSubImage%dD(integer/non-integer format mismatch)",
2212 * Test glCopyTexImage[12]D() parameters for errors.
2214 * \param ctx GL context.
2215 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2216 * \param target texture target given by the user.
2217 * \param level image level given by the user.
2218 * \param internalFormat internal format given by the user.
2219 * \param width image width given by the user.
2220 * \param height image height given by the user.
2221 * \param border texture border.
2223 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2225 * Verifies each of the parameters against the constants specified in
2226 * __struct gl_contextRec::Const and the supported extensions, and according
2227 * to the OpenGL specification.
2230 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2231 GLenum target
, GLint level
, GLint internalFormat
,
2232 GLint width
, GLint height
, GLint border
)
2237 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2238 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2239 dimensions
, _mesa_lookup_enum_by_nr(target
));
2244 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2245 _mesa_error(ctx
, GL_INVALID_VALUE
,
2246 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2250 /* Check that the source buffer is complete */
2251 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2252 if (ctx
->ReadBuffer
->_Status
== 0) {
2253 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2255 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2256 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2257 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2261 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2262 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2263 "glCopyTexImage%dD(multisample FBO)",
2270 if (border
< 0 || border
> 1 ||
2271 ((ctx
->API
!= API_OPENGL
||
2272 target
== GL_TEXTURE_RECTANGLE_NV
||
2273 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2274 _mesa_error(ctx
, GL_INVALID_VALUE
,
2275 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2279 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2282 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2283 switch (internalFormat
) {
2288 case GL_LUMINANCE_ALPHA
:
2291 _mesa_error(ctx
, GL_INVALID_VALUE
,
2292 "glCopyTexImage%dD(internalFormat)", dimensions
);
2297 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2298 if (baseFormat
< 0) {
2299 _mesa_error(ctx
, GL_INVALID_VALUE
,
2300 "glCopyTexImage%dD(internalFormat)", dimensions
);
2304 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2305 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2306 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2310 /* From the EXT_texture_integer spec:
2312 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2313 * if the texture internalformat is an integer format and the read color
2314 * buffer is not an integer format, or if the internalformat is not an
2315 * integer format and the read color buffer is an integer format."
2317 if (_mesa_is_color_format(internalFormat
)) {
2318 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2320 if (_mesa_is_enum_format_integer(rb
->InternalFormat
) !=
2321 _mesa_is_enum_format_integer(internalFormat
)) {
2322 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2323 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2328 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2329 _mesa_is_cube_face(target
)) && width
!= height
) {
2330 _mesa_error(ctx
, GL_INVALID_VALUE
,
2331 "glTexImage2D(cube width != height)");
2335 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2336 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2337 _mesa_error(ctx
, GL_INVALID_ENUM
,
2338 "glCopyTexImage%dD(target)", dimensions
);
2341 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2342 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2343 "glCopyTexImage%dD(no compression for format)", dimensions
);
2347 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2348 "glCopyTexImage%dD(border!=0)", dimensions
);
2353 if (!mutable_tex_object(ctx
, target
)) {
2354 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2355 "glCopyTexImage%dD(immutable texture)", dimensions
);
2359 /* if we get here, the parameters are OK */
2365 * Test glCopyTexSubImage[12]D() parameters for errors.
2366 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2369 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2370 GLenum target
, GLint level
,
2371 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2372 GLint width
, GLint height
)
2374 struct gl_texture_object
*texObj
;
2375 struct gl_texture_image
*texImage
;
2377 /* Check that the source buffer is complete */
2378 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2379 if (ctx
->ReadBuffer
->_Status
== 0) {
2380 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2382 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2383 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2384 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2388 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2390 "glCopyTexSubImage%dD(multisample FBO)",
2396 /* check target (proxies not allowed) */
2397 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2398 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2399 dimensions
, _mesa_lookup_enum_by_nr(target
));
2404 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2405 _mesa_error(ctx
, GL_INVALID_VALUE
,
2406 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2410 /* Get dest texture object / image pointers */
2411 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2413 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2417 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2419 /* destination image does not exist */
2420 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2421 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2425 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2426 dimensions
, texImage
,
2427 xoffset
, yoffset
, zoffset
,
2428 width
, height
, 1)) {
2432 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2433 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2435 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2440 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2441 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2445 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2446 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2447 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2448 dimensions
, texImage
->_BaseFormat
);
2452 /* From the EXT_texture_integer spec:
2454 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2455 * if the texture internalformat is an integer format and the read color
2456 * buffer is not an integer format, or if the internalformat is not an
2457 * integer format and the read color buffer is an integer format."
2459 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2460 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2462 if (_mesa_is_format_integer_color(rb
->Format
) !=
2463 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2464 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2465 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2470 /* if we get here, the parameters are OK */
2475 /** Callback info for walking over FBO hash table */
2478 struct gl_context
*ctx
;
2479 struct gl_texture_object
*texObj
;
2485 * Check render to texture callback. Called from _mesa_HashWalk().
2488 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2490 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2491 const struct cb_info
*info
= (struct cb_info
*) userData
;
2492 struct gl_context
*ctx
= info
->ctx
;
2493 const struct gl_texture_object
*texObj
= info
->texObj
;
2494 const GLuint level
= info
->level
, face
= info
->face
;
2496 /* If this is a user-created FBO */
2497 if (_mesa_is_user_fbo(fb
)) {
2499 /* check if any of the FBO's attachments point to 'texObj' */
2500 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2501 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2502 if (att
->Type
== GL_TEXTURE
&&
2503 att
->Texture
== texObj
&&
2504 att
->TextureLevel
== level
&&
2505 att
->CubeMapFace
== face
) {
2506 ASSERT(_mesa_get_attachment_teximage(att
));
2507 /* Tell driver about the new renderbuffer texture */
2508 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2509 /* Mark fb status as indeterminate to force re-validation */
2518 * When a texture image is specified we have to check if it's bound to
2519 * any framebuffer objects (render to texture) in order to detect changes
2520 * in size or format since that effects FBO completeness.
2521 * Any FBOs rendering into the texture must be re-validated.
2524 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2525 struct gl_texture_object
*texObj
,
2526 GLuint face
, GLuint level
)
2528 /* Only check this texture if it's been marked as RenderToTexture */
2529 if (texObj
->_RenderToTexture
) {
2530 struct cb_info info
;
2532 info
.texObj
= texObj
;
2535 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2541 * If the texture object's GenerateMipmap flag is set and we've
2542 * changed the texture base level image, regenerate the rest of the
2543 * mipmap levels now.
2546 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2547 struct gl_texture_object
*texObj
, GLint level
)
2549 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2550 if (texObj
->GenerateMipmap
&&
2551 level
== texObj
->BaseLevel
&&
2552 level
< texObj
->MaxLevel
) {
2553 ASSERT(ctx
->Driver
.GenerateMipmap
);
2554 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2559 /** Debug helper: override the user-requested internal format */
2561 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2564 if (internalFormat
== GL_RGBA16F_ARB
||
2565 internalFormat
== GL_RGBA32F_ARB
) {
2566 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2569 else if (internalFormat
== GL_RGB16F_ARB
||
2570 internalFormat
== GL_RGB32F_ARB
) {
2571 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2574 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2575 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2576 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2577 return GL_LUMINANCE_ALPHA
;
2579 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2580 internalFormat
== GL_LUMINANCE32F_ARB
) {
2581 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2582 return GL_LUMINANCE
;
2584 else if (internalFormat
== GL_ALPHA16F_ARB
||
2585 internalFormat
== GL_ALPHA32F_ARB
) {
2586 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2590 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2591 internalFormat = GL_RGBA;
2595 return internalFormat
;
2598 return internalFormat
;
2604 * Choose the actual hardware format for a texture image.
2605 * Try to use the same format as the previous image level when possible.
2606 * Otherwise, ask the driver for the best format.
2607 * It's important to try to choose a consistant format for all levels
2608 * for efficient texture memory layout/allocation. In particular, this
2609 * comes up during automatic mipmap generation.
2612 _mesa_choose_texture_format(struct gl_context
*ctx
,
2613 struct gl_texture_object
*texObj
,
2614 GLenum target
, GLint level
,
2615 GLenum internalFormat
, GLenum format
, GLenum type
)
2619 /* see if we've already chosen a format for the previous level */
2621 struct gl_texture_image
*prevImage
=
2622 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2623 /* See if the prev level is defined and has an internal format which
2624 * matches the new internal format.
2627 prevImage
->Width
> 0 &&
2628 prevImage
->InternalFormat
== internalFormat
) {
2629 /* use the same format */
2630 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2631 return prevImage
->TexFormat
;
2635 /* If the application requested compression to an S3TC format but we don't
2636 * have the DTXn library, force a generic compressed format instead.
2638 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2639 const GLenum before
= internalFormat
;
2641 switch (internalFormat
) {
2642 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2643 if (!ctx
->Mesa_DXTn
)
2644 internalFormat
= GL_COMPRESSED_RGB
;
2646 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2647 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2648 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2649 if (!ctx
->Mesa_DXTn
)
2650 internalFormat
= GL_COMPRESSED_RGBA
;
2656 if (before
!= internalFormat
) {
2658 "DXT compression requested (%s), "
2659 "but libtxc_dxtn library not installed. Using %s "
2661 _mesa_lookup_enum_by_nr(before
),
2662 _mesa_lookup_enum_by_nr(internalFormat
));
2666 /* choose format from scratch */
2667 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2669 ASSERT(f
!= MESA_FORMAT_NONE
);
2674 * Adjust pixel unpack params and image dimensions to strip off the
2675 * one-pixel texture border.
2677 * Gallium and intel don't support texture borders. They've seldem been used
2678 * and seldom been implemented correctly anyway.
2680 * \param unpackNew returns the new pixel unpack parameters
2683 strip_texture_border(GLenum target
,
2684 GLint
*width
, GLint
*height
, GLint
*depth
,
2685 const struct gl_pixelstore_attrib
*unpack
,
2686 struct gl_pixelstore_attrib
*unpackNew
)
2692 *unpackNew
= *unpack
;
2694 if (unpackNew
->RowLength
== 0)
2695 unpackNew
->RowLength
= *width
;
2697 if (unpackNew
->ImageHeight
== 0)
2698 unpackNew
->ImageHeight
= *height
;
2700 assert(*width
>= 3);
2701 unpackNew
->SkipPixels
++; /* skip the border */
2702 *width
= *width
- 2; /* reduce the width by two border pixels */
2704 /* The min height of a texture with a border is 3 */
2705 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2706 unpackNew
->SkipRows
++; /* skip the border */
2707 *height
= *height
- 2; /* reduce the height by two border pixels */
2710 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
) {
2711 unpackNew
->SkipImages
++; /* skip the border */
2712 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2718 * Common code to implement all the glTexImage1D/2D/3D functions
2719 * as well as glCompressedTexImage1D/2D/3D.
2720 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2721 * \param format the user's image format (only used if !compressed)
2722 * \param type the user's image type (only used if !compressed)
2723 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2726 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2727 GLenum target
, GLint level
, GLint internalFormat
,
2728 GLsizei width
, GLsizei height
, GLsizei depth
,
2729 GLint border
, GLenum format
, GLenum type
,
2730 GLsizei imageSize
, const GLvoid
*pixels
)
2732 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2733 struct gl_pixelstore_attrib unpack_no_border
;
2734 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2735 struct gl_texture_object
*texObj
;
2736 gl_format texFormat
;
2737 GLboolean dimensionsOK
, sizeOK
;
2739 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2741 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2744 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2746 _mesa_lookup_enum_by_nr(target
), level
,
2747 _mesa_lookup_enum_by_nr(internalFormat
),
2748 width
, height
, depth
, border
, pixels
);
2751 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2753 _mesa_lookup_enum_by_nr(target
), level
,
2754 _mesa_lookup_enum_by_nr(internalFormat
),
2755 width
, height
, depth
, border
,
2756 _mesa_lookup_enum_by_nr(format
),
2757 _mesa_lookup_enum_by_nr(type
), pixels
);
2760 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2762 /* target error checking */
2763 if (!legal_teximage_target(ctx
, dims
, target
)) {
2764 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2765 func
, dims
, _mesa_lookup_enum_by_nr(target
));
2769 /* general error checking */
2771 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2773 width
, height
, depth
,
2778 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2779 format
, type
, width
, height
, depth
, border
))
2783 /* Here we convert a cpal compressed image into a regular glTexImage2D
2784 * call by decompressing the texture. If we really want to support cpal
2785 * textures in any driver this would have to be changed.
2787 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
2788 switch (internalFormat
) {
2789 case GL_PALETTE4_RGB8_OES
:
2790 case GL_PALETTE4_RGBA8_OES
:
2791 case GL_PALETTE4_R5_G6_B5_OES
:
2792 case GL_PALETTE4_RGBA4_OES
:
2793 case GL_PALETTE4_RGB5_A1_OES
:
2794 case GL_PALETTE8_RGB8_OES
:
2795 case GL_PALETTE8_RGBA8_OES
:
2796 case GL_PALETTE8_R5_G6_B5_OES
:
2797 case GL_PALETTE8_RGBA4_OES
:
2798 case GL_PALETTE8_RGB5_A1_OES
:
2799 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
2800 width
, height
, imageSize
, pixels
);
2805 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2808 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2809 internalFormat
, format
, type
);
2810 assert(texFormat
!= MESA_FORMAT_NONE
);
2812 /* check that width, height, depth are legal for the mipmap level */
2813 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
2814 height
, depth
, border
);
2816 /* check that the texture won't take too much memory, etc */
2817 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
2819 width
, height
, depth
, border
);
2821 if (_mesa_is_proxy_texture(target
)) {
2822 /* Proxy texture: just clear or set state depending on error checking */
2823 struct gl_texture_image
*texImage
=
2824 get_proxy_tex_image(ctx
, target
, level
);
2827 return; /* GL_OUT_OF_MEMORY already recorded */
2829 if (dimensionsOK
&& sizeOK
) {
2830 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
2831 border
, internalFormat
, texFormat
);
2834 clear_teximage_fields(texImage
);
2838 /* non-proxy target */
2839 const GLuint face
= _mesa_tex_target_to_face(target
);
2840 struct gl_texture_image
*texImage
;
2842 if (!dimensionsOK
) {
2843 _mesa_error(ctx
, GL_INVALID_VALUE
,
2844 "glTexImage%uD(invalid width or height or depth)",
2850 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
2851 "glTexImage%uD(image too large)", dims
);
2855 /* Allow a hardware driver to just strip out the border, to provide
2856 * reliable but slightly incorrect hardware rendering instead of
2857 * rarely-tested software fallback rendering.
2859 if (border
&& ctx
->Const
.StripTextureBorder
) {
2860 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
2863 unpack
= &unpack_no_border
;
2866 if (ctx
->NewState
& _NEW_PIXEL
)
2867 _mesa_update_state(ctx
);
2869 _mesa_lock_texture(ctx
, texObj
);
2871 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2874 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
2877 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2879 _mesa_init_teximage_fields(ctx
, texImage
,
2880 width
, height
, depth
,
2881 border
, internalFormat
, texFormat
);
2883 /* Give the texture to the driver. <pixels> may be null. */
2885 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
2889 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
2890 type
, pixels
, unpack
);
2893 check_gen_mipmap(ctx
, target
, texObj
, level
);
2895 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2897 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2900 _mesa_unlock_texture(ctx
, texObj
);
2907 * Called from the API. Note that width includes the border.
2910 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2911 GLsizei width
, GLint border
, GLenum format
,
2912 GLenum type
, const GLvoid
*pixels
)
2914 GET_CURRENT_CONTEXT(ctx
);
2915 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
2916 border
, format
, type
, 0, pixels
);
2921 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2922 GLsizei width
, GLsizei height
, GLint border
,
2923 GLenum format
, GLenum type
,
2924 const GLvoid
*pixels
)
2926 GET_CURRENT_CONTEXT(ctx
);
2927 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
2928 border
, format
, type
, 0, pixels
);
2933 * Called by the API or display list executor.
2934 * Note that width and height include the border.
2937 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2938 GLsizei width
, GLsizei height
, GLsizei depth
,
2939 GLint border
, GLenum format
, GLenum type
,
2940 const GLvoid
*pixels
)
2942 GET_CURRENT_CONTEXT(ctx
);
2943 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
2944 width
, height
, depth
,
2945 border
, format
, type
, 0, pixels
);
2950 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2951 GLsizei width
, GLsizei height
, GLsizei depth
,
2952 GLint border
, GLenum format
, GLenum type
,
2953 const GLvoid
*pixels
)
2955 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2956 depth
, border
, format
, type
, pixels
);
2961 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2963 struct gl_texture_object
*texObj
;
2964 struct gl_texture_image
*texImage
;
2966 GET_CURRENT_CONTEXT(ctx
);
2967 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2971 valid_target
= ctx
->Extensions
.OES_EGL_image
;
2973 case GL_TEXTURE_EXTERNAL_OES
:
2974 valid_target
= ctx
->Extensions
.OES_EGL_image_external
;
2977 valid_target
= false;
2981 if (!valid_target
) {
2982 _mesa_error(ctx
, GL_INVALID_ENUM
,
2983 "glEGLImageTargetTexture2D(target=%d)", target
);
2987 if (ctx
->NewState
& _NEW_PIXEL
)
2988 _mesa_update_state(ctx
);
2990 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2991 _mesa_lock_texture(ctx
, texObj
);
2993 if (texObj
->Immutable
) {
2994 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2995 "glEGLImageTargetTexture2D(texture is immutable)");
2996 _mesa_unlock_texture(ctx
, texObj
);
3000 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3002 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3004 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3006 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3007 texObj
, texImage
, image
);
3009 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3011 _mesa_unlock_texture(ctx
, texObj
);
3018 * Implement all the glTexSubImage1/2/3D() functions.
3021 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3022 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3023 GLsizei width
, GLsizei height
, GLsizei depth
,
3024 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3026 struct gl_texture_object
*texObj
;
3027 struct gl_texture_image
*texImage
;
3029 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3031 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3032 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3034 _mesa_lookup_enum_by_nr(target
), level
,
3035 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3036 _mesa_lookup_enum_by_nr(format
),
3037 _mesa_lookup_enum_by_nr(type
), pixels
);
3039 /* check target (proxies not allowed) */
3040 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3041 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3042 dims
, _mesa_lookup_enum_by_nr(target
));
3046 if (ctx
->NewState
& _NEW_PIXEL
)
3047 _mesa_update_state(ctx
);
3049 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3050 xoffset
, yoffset
, zoffset
,
3051 width
, height
, depth
, format
, type
)) {
3052 return; /* error was detected */
3055 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3057 _mesa_lock_texture(ctx
, texObj
);
3059 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3061 if (width
> 0 && height
> 0 && depth
> 0) {
3062 /* If we have a border, offset=-1 is legal. Bias by border width. */
3065 if (target
!= GL_TEXTURE_2D_ARRAY
)
3066 zoffset
+= texImage
->Border
;
3069 if (target
!= GL_TEXTURE_1D_ARRAY
)
3070 yoffset
+= texImage
->Border
;
3073 xoffset
+= texImage
->Border
;
3076 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3077 xoffset
, yoffset
, zoffset
,
3078 width
, height
, depth
,
3079 format
, type
, pixels
, &ctx
->Unpack
);
3081 check_gen_mipmap(ctx
, target
, texObj
, level
);
3083 ctx
->NewState
|= _NEW_TEXTURE
;
3086 _mesa_unlock_texture(ctx
, texObj
);
3091 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3092 GLint xoffset
, GLsizei width
,
3093 GLenum format
, GLenum type
,
3094 const GLvoid
*pixels
)
3096 GET_CURRENT_CONTEXT(ctx
);
3097 texsubimage(ctx
, 1, target
, level
,
3100 format
, type
, pixels
);
3105 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3106 GLint xoffset
, GLint yoffset
,
3107 GLsizei width
, GLsizei height
,
3108 GLenum format
, GLenum type
,
3109 const GLvoid
*pixels
)
3111 GET_CURRENT_CONTEXT(ctx
);
3112 texsubimage(ctx
, 2, target
, level
,
3113 xoffset
, yoffset
, 0,
3115 format
, type
, pixels
);
3121 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3122 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3123 GLsizei width
, GLsizei height
, GLsizei depth
,
3124 GLenum format
, GLenum type
,
3125 const GLvoid
*pixels
)
3127 GET_CURRENT_CONTEXT(ctx
);
3128 texsubimage(ctx
, 3, target
, level
,
3129 xoffset
, yoffset
, zoffset
,
3130 width
, height
, depth
,
3131 format
, type
, pixels
);
3137 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3138 * from. This depends on whether the texture contains color or depth values.
3140 static struct gl_renderbuffer
*
3141 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3143 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3144 /* reading from depth/stencil buffer */
3145 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3148 /* copying from color buffer */
3149 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3156 * Implement the glCopyTexImage1/2D() functions.
3159 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3160 GLenum target
, GLint level
, GLenum internalFormat
,
3161 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3163 struct gl_texture_object
*texObj
;
3164 struct gl_texture_image
*texImage
;
3165 const GLuint face
= _mesa_tex_target_to_face(target
);
3166 gl_format texFormat
;
3168 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3170 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3171 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3173 _mesa_lookup_enum_by_nr(target
), level
,
3174 _mesa_lookup_enum_by_nr(internalFormat
),
3175 x
, y
, width
, height
, border
);
3177 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3178 _mesa_update_state(ctx
);
3180 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3181 width
, height
, border
))
3184 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3186 _mesa_error(ctx
, GL_INVALID_VALUE
,
3187 "glCopyTexImage%uD(invalid width or height)", dims
);
3191 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3194 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3195 internalFormat
, GL_NONE
, GL_NONE
);
3196 assert(texFormat
!= MESA_FORMAT_NONE
);
3198 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3200 width
, height
, 1, border
)) {
3201 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3202 "glCopyTexImage%uD(image too large)", dims
);
3206 if (border
&& ctx
->Const
.StripTextureBorder
) {
3208 width
-= border
* 2;
3211 height
-= border
* 2;
3216 _mesa_lock_texture(ctx
, texObj
);
3218 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3221 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3224 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3226 /* Free old texture image */
3227 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3229 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3230 border
, internalFormat
, texFormat
);
3232 /* Allocate texture memory (no pixel data yet) */
3233 ctx
->Driver
.TexImage(ctx
, dims
, texImage
,
3235 NULL
, &ctx
->Unpack
);
3237 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3239 struct gl_renderbuffer
*srcRb
=
3240 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3242 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
3243 srcRb
, srcX
, srcY
, width
, height
);
3246 check_gen_mipmap(ctx
, target
, texObj
, level
);
3248 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3250 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3253 _mesa_unlock_texture(ctx
, texObj
);
3259 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3260 GLenum internalFormat
,
3262 GLsizei width
, GLint border
)
3264 GET_CURRENT_CONTEXT(ctx
);
3265 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3271 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3272 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3275 GET_CURRENT_CONTEXT(ctx
);
3276 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3277 x
, y
, width
, height
, border
);
3283 * Implementation for glCopyTexSubImage1/2/3D() functions.
3286 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3287 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3288 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3290 struct gl_texture_object
*texObj
;
3291 struct gl_texture_image
*texImage
;
3293 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3295 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3296 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3298 _mesa_lookup_enum_by_nr(target
),
3299 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3301 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3302 _mesa_update_state(ctx
);
3304 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3305 xoffset
, yoffset
, zoffset
, width
, height
)) {
3309 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3311 _mesa_lock_texture(ctx
, texObj
);
3313 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3315 /* If we have a border, offset=-1 is legal. Bias by border width. */
3318 if (target
!= GL_TEXTURE_2D_ARRAY
)
3319 zoffset
+= texImage
->Border
;
3322 if (target
!= GL_TEXTURE_1D_ARRAY
)
3323 yoffset
+= texImage
->Border
;
3326 xoffset
+= texImage
->Border
;
3329 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3331 struct gl_renderbuffer
*srcRb
=
3332 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3334 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3335 xoffset
, yoffset
, zoffset
,
3336 srcRb
, x
, y
, width
, height
);
3338 check_gen_mipmap(ctx
, target
, texObj
, level
);
3340 ctx
->NewState
|= _NEW_TEXTURE
;
3343 _mesa_unlock_texture(ctx
, texObj
);
3348 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3349 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3351 GET_CURRENT_CONTEXT(ctx
);
3352 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3358 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3359 GLint xoffset
, GLint yoffset
,
3360 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3362 GET_CURRENT_CONTEXT(ctx
);
3363 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3370 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3371 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3372 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3374 GET_CURRENT_CONTEXT(ctx
);
3375 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3376 x
, y
, width
, height
);
3382 /**********************************************************************/
3383 /****** Compressed Textures ******/
3384 /**********************************************************************/
3388 * Error checking for glCompressedTexSubImage[123]D().
3389 * \return error code or GL_NO_ERROR.
3392 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3393 GLenum target
, GLint level
,
3394 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3395 GLsizei width
, GLsizei height
, GLsizei depth
,
3396 GLenum format
, GLsizei imageSize
)
3398 struct gl_texture_object
*texObj
;
3399 struct gl_texture_image
*texImage
;
3406 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3407 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3408 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3409 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3410 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3411 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3415 targetOK
= GL_FALSE
;
3419 assert(dims
== 1 || dims
== 3);
3420 /* no 1D or 3D compressed textures at this time */
3421 targetOK
= GL_FALSE
;
3425 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3430 /* this will catch any invalid compressed format token */
3431 if (!_mesa_is_compressed_format(ctx
, format
)) {
3432 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3437 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3438 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3443 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3444 if (expectedSize
!= imageSize
) {
3445 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3450 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3452 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3453 "glCompressedTexSubImage%uD()", dims
);
3457 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3459 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3460 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3464 if ((GLint
) format
!= texImage
->InternalFormat
) {
3465 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3466 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3470 if (compressedteximage_only_format(ctx
, format
)) {
3471 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3472 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3477 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3478 texImage
, xoffset
, yoffset
, zoffset
,
3479 width
, height
, depth
)) {
3488 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3489 GLenum internalFormat
, GLsizei width
,
3490 GLint border
, GLsizei imageSize
,
3493 GET_CURRENT_CONTEXT(ctx
);
3494 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3495 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3500 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3501 GLenum internalFormat
, GLsizei width
,
3502 GLsizei height
, GLint border
, GLsizei imageSize
,
3505 GET_CURRENT_CONTEXT(ctx
);
3506 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3507 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3512 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3513 GLenum internalFormat
, GLsizei width
,
3514 GLsizei height
, GLsizei depth
, GLint border
,
3515 GLsizei imageSize
, const GLvoid
*data
)
3517 GET_CURRENT_CONTEXT(ctx
);
3518 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3519 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3524 * Common helper for glCompressedTexSubImage1/2/3D().
3527 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3528 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3529 GLsizei width
, GLsizei height
, GLsizei depth
,
3530 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3532 struct gl_texture_object
*texObj
;
3533 struct gl_texture_image
*texImage
;
3534 GET_CURRENT_CONTEXT(ctx
);
3535 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3537 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3538 xoffset
, yoffset
, zoffset
,
3539 width
, height
, depth
,
3540 format
, imageSize
)) {
3544 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3546 _mesa_lock_texture(ctx
, texObj
);
3548 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3551 if (width
> 0 && height
> 0 && depth
> 0) {
3552 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3553 xoffset
, yoffset
, zoffset
,
3554 width
, height
, depth
,
3555 format
, imageSize
, data
);
3557 check_gen_mipmap(ctx
, target
, texObj
, level
);
3559 ctx
->NewState
|= _NEW_TEXTURE
;
3562 _mesa_unlock_texture(ctx
, texObj
);
3567 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3568 GLsizei width
, GLenum format
,
3569 GLsizei imageSize
, const GLvoid
*data
)
3571 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3572 format
, imageSize
, data
);
3577 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3578 GLint yoffset
, GLsizei width
, GLsizei height
,
3579 GLenum format
, GLsizei imageSize
,
3582 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3583 width
, height
, 1, format
, imageSize
, data
);
3588 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3589 GLint yoffset
, GLint zoffset
, GLsizei width
,
3590 GLsizei height
, GLsizei depth
, GLenum format
,
3591 GLsizei imageSize
, const GLvoid
*data
)
3593 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3594 width
, height
, depth
, format
, imageSize
, data
);
3598 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3600 switch (internalFormat
) {
3602 return MESA_FORMAT_A8
;
3604 return MESA_FORMAT_A16
;
3605 case GL_ALPHA16F_ARB
:
3606 return MESA_FORMAT_ALPHA_FLOAT16
;
3607 case GL_ALPHA32F_ARB
:
3608 return MESA_FORMAT_ALPHA_FLOAT32
;
3609 case GL_ALPHA8I_EXT
:
3610 return MESA_FORMAT_ALPHA_INT8
;
3611 case GL_ALPHA16I_EXT
:
3612 return MESA_FORMAT_ALPHA_INT16
;
3613 case GL_ALPHA32I_EXT
:
3614 return MESA_FORMAT_ALPHA_INT32
;
3615 case GL_ALPHA8UI_EXT
:
3616 return MESA_FORMAT_ALPHA_UINT8
;
3617 case GL_ALPHA16UI_EXT
:
3618 return MESA_FORMAT_ALPHA_UINT16
;
3619 case GL_ALPHA32UI_EXT
:
3620 return MESA_FORMAT_ALPHA_UINT32
;
3622 return MESA_FORMAT_L8
;
3623 case GL_LUMINANCE16
:
3624 return MESA_FORMAT_L16
;
3625 case GL_LUMINANCE16F_ARB
:
3626 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3627 case GL_LUMINANCE32F_ARB
:
3628 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3629 case GL_LUMINANCE8I_EXT
:
3630 return MESA_FORMAT_LUMINANCE_INT8
;
3631 case GL_LUMINANCE16I_EXT
:
3632 return MESA_FORMAT_LUMINANCE_INT16
;
3633 case GL_LUMINANCE32I_EXT
:
3634 return MESA_FORMAT_LUMINANCE_INT32
;
3635 case GL_LUMINANCE8UI_EXT
:
3636 return MESA_FORMAT_LUMINANCE_UINT8
;
3637 case GL_LUMINANCE16UI_EXT
:
3638 return MESA_FORMAT_LUMINANCE_UINT16
;
3639 case GL_LUMINANCE32UI_EXT
:
3640 return MESA_FORMAT_LUMINANCE_UINT32
;
3641 case GL_LUMINANCE8_ALPHA8
:
3642 return MESA_FORMAT_AL88
;
3643 case GL_LUMINANCE16_ALPHA16
:
3644 return MESA_FORMAT_AL1616
;
3645 case GL_LUMINANCE_ALPHA16F_ARB
:
3646 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3647 case GL_LUMINANCE_ALPHA32F_ARB
:
3648 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3649 case GL_LUMINANCE_ALPHA8I_EXT
:
3650 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3651 case GL_LUMINANCE_ALPHA16I_EXT
:
3652 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3653 case GL_LUMINANCE_ALPHA32I_EXT
:
3654 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3655 case GL_LUMINANCE_ALPHA8UI_EXT
:
3656 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3657 case GL_LUMINANCE_ALPHA16UI_EXT
:
3658 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3659 case GL_LUMINANCE_ALPHA32UI_EXT
:
3660 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3662 return MESA_FORMAT_I8
;
3663 case GL_INTENSITY16
:
3664 return MESA_FORMAT_I16
;
3665 case GL_INTENSITY16F_ARB
:
3666 return MESA_FORMAT_INTENSITY_FLOAT16
;
3667 case GL_INTENSITY32F_ARB
:
3668 return MESA_FORMAT_INTENSITY_FLOAT32
;
3669 case GL_INTENSITY8I_EXT
:
3670 return MESA_FORMAT_INTENSITY_INT8
;
3671 case GL_INTENSITY16I_EXT
:
3672 return MESA_FORMAT_INTENSITY_INT16
;
3673 case GL_INTENSITY32I_EXT
:
3674 return MESA_FORMAT_INTENSITY_INT32
;
3675 case GL_INTENSITY8UI_EXT
:
3676 return MESA_FORMAT_INTENSITY_UINT8
;
3677 case GL_INTENSITY16UI_EXT
:
3678 return MESA_FORMAT_INTENSITY_UINT16
;
3679 case GL_INTENSITY32UI_EXT
:
3680 return MESA_FORMAT_INTENSITY_UINT32
;
3682 return MESA_FORMAT_RGBA8888_REV
;
3684 return MESA_FORMAT_RGBA_16
;
3685 case GL_RGBA16F_ARB
:
3686 return MESA_FORMAT_RGBA_FLOAT16
;
3687 case GL_RGBA32F_ARB
:
3688 return MESA_FORMAT_RGBA_FLOAT32
;
3690 return MESA_FORMAT_RGBA_INT8
;
3691 case GL_RGBA16I_EXT
:
3692 return MESA_FORMAT_RGBA_INT16
;
3693 case GL_RGBA32I_EXT
:
3694 return MESA_FORMAT_RGBA_INT32
;
3695 case GL_RGBA8UI_EXT
:
3696 return MESA_FORMAT_RGBA_UINT8
;
3697 case GL_RGBA16UI_EXT
:
3698 return MESA_FORMAT_RGBA_UINT16
;
3699 case GL_RGBA32UI_EXT
:
3700 return MESA_FORMAT_RGBA_UINT32
;
3703 return MESA_FORMAT_GR88
;
3705 return MESA_FORMAT_RG1616
;
3707 return MESA_FORMAT_RG_FLOAT16
;
3709 return MESA_FORMAT_RG_FLOAT32
;
3711 return MESA_FORMAT_RG_INT8
;
3713 return MESA_FORMAT_RG_INT16
;
3715 return MESA_FORMAT_RG_INT32
;
3717 return MESA_FORMAT_RG_UINT8
;
3719 return MESA_FORMAT_RG_UINT16
;
3721 return MESA_FORMAT_RG_UINT32
;
3724 return MESA_FORMAT_R8
;
3726 return MESA_FORMAT_R16
;
3728 return MESA_FORMAT_R_FLOAT16
;
3730 return MESA_FORMAT_R_FLOAT32
;
3732 return MESA_FORMAT_R_INT8
;
3734 return MESA_FORMAT_R_INT16
;
3736 return MESA_FORMAT_R_INT32
;
3738 return MESA_FORMAT_R_UINT8
;
3740 return MESA_FORMAT_R_UINT16
;
3742 return MESA_FORMAT_R_UINT32
;
3745 return MESA_FORMAT_NONE
;
3750 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3752 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
3755 if (format
== MESA_FORMAT_NONE
)
3756 return MESA_FORMAT_NONE
;
3758 datatype
= _mesa_get_format_datatype(format
);
3759 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3760 return MESA_FORMAT_NONE
;
3762 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3763 return MESA_FORMAT_NONE
;
3765 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
3766 * any mention of R/RG formats, but they appear in the GL 3.1 core
3769 if (ctx
->Version
<= 30) {
3770 GLenum base_format
= _mesa_get_format_base_format(format
);
3772 if (base_format
== GL_R
|| base_format
== GL_RG
)
3773 return MESA_FORMAT_NONE
;
3779 /** GL_ARB_texture_buffer_object */
3781 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3783 struct gl_texture_object
*texObj
;
3784 struct gl_buffer_object
*bufObj
;
3787 GET_CURRENT_CONTEXT(ctx
);
3788 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3790 if (!(ctx
->Extensions
.ARB_texture_buffer_object
3791 && _mesa_is_desktop_gl(ctx
))) {
3792 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3796 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3797 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3801 format
= validate_texbuffer_format(ctx
, internalFormat
);
3802 if (format
== MESA_FORMAT_NONE
) {
3803 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3808 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3809 if (buffer
&& !bufObj
) {
3810 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3814 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3816 _mesa_lock_texture(ctx
, texObj
);
3818 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3819 texObj
->BufferObjectFormat
= internalFormat
;
3820 texObj
->_BufferObjectFormat
= format
;
3822 _mesa_unlock_texture(ctx
, texObj
);