2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "mfeatures.h"
44 #include "texcompress.h"
45 #include "texcompress_cpal.h"
50 #include "glformats.h"
54 * State changes which we care about for glCopyTex[Sub]Image() calls.
55 * In particular, we care about pixel transfer state and buffer state
56 * (such as glReadBuffer to make sure we read from the right renderbuffer).
58 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
63 * Return the simple base format for a given internal texture format.
64 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
66 * \param ctx GL context.
67 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
69 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
70 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
72 * This is the format which is used during texture application (i.e. the
73 * texture format and env mode determine the arithmetic used.
76 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
78 switch (internalFormat
) {
84 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
91 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
93 case GL_LUMINANCE_ALPHA
:
94 case GL_LUMINANCE4_ALPHA4
:
95 case GL_LUMINANCE6_ALPHA2
:
96 case GL_LUMINANCE8_ALPHA8
:
97 case GL_LUMINANCE12_ALPHA4
:
98 case GL_LUMINANCE12_ALPHA12
:
99 case GL_LUMINANCE16_ALPHA16
:
100 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
106 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
108 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
119 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
133 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
135 if (_mesa_is_gles(ctx
)) {
136 switch (internalFormat
) {
144 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
145 switch (internalFormat
) {
153 if (ctx
->Extensions
.ARB_depth_texture
) {
154 switch (internalFormat
) {
155 case GL_DEPTH_COMPONENT
:
156 case GL_DEPTH_COMPONENT16
:
157 case GL_DEPTH_COMPONENT24
:
158 case GL_DEPTH_COMPONENT32
:
159 return GL_DEPTH_COMPONENT
;
165 switch (internalFormat
) {
166 case GL_COMPRESSED_ALPHA
:
168 case GL_COMPRESSED_LUMINANCE
:
170 case GL_COMPRESSED_LUMINANCE_ALPHA
:
171 return GL_LUMINANCE_ALPHA
;
172 case GL_COMPRESSED_INTENSITY
:
174 case GL_COMPRESSED_RGB
:
176 case GL_COMPRESSED_RGBA
:
182 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
183 switch (internalFormat
) {
184 case GL_COMPRESSED_RGB_FXT1_3DFX
:
186 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
193 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
194 switch (internalFormat
) {
195 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
197 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
198 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
199 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
206 /* GL_COMPRESSED_RGBA_S3TC_DXT3_ANGLE && GL_COMPRESSED_RGBA_S3TC_DXT5_ANGLE */
207 if (ctx
->API
== API_OPENGLES2
&&
208 ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
209 switch (internalFormat
) {
210 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
211 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
218 if (ctx
->Extensions
.S3_s3tc
) {
219 switch (internalFormat
) {
231 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
232 if (internalFormat
== GL_YCBCR_MESA
)
233 return GL_YCBCR_MESA
;
236 if (ctx
->Extensions
.ARB_texture_float
) {
237 switch (internalFormat
) {
238 case GL_ALPHA16F_ARB
:
239 case GL_ALPHA32F_ARB
:
247 case GL_INTENSITY16F_ARB
:
248 case GL_INTENSITY32F_ARB
:
250 case GL_LUMINANCE16F_ARB
:
251 case GL_LUMINANCE32F_ARB
:
253 case GL_LUMINANCE_ALPHA16F_ARB
:
254 case GL_LUMINANCE_ALPHA32F_ARB
:
255 return GL_LUMINANCE_ALPHA
;
261 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
262 switch (internalFormat
) {
271 if (ctx
->Extensions
.EXT_texture_snorm
) {
272 switch (internalFormat
) {
287 case GL_RGBA16_SNORM
:
290 case GL_ALPHA8_SNORM
:
291 case GL_ALPHA16_SNORM
:
293 case GL_LUMINANCE_SNORM
:
294 case GL_LUMINANCE8_SNORM
:
295 case GL_LUMINANCE16_SNORM
:
297 case GL_LUMINANCE_ALPHA_SNORM
:
298 case GL_LUMINANCE8_ALPHA8_SNORM
:
299 case GL_LUMINANCE16_ALPHA16_SNORM
:
300 return GL_LUMINANCE_ALPHA
;
301 case GL_INTENSITY_SNORM
:
302 case GL_INTENSITY8_SNORM
:
303 case GL_INTENSITY16_SNORM
:
310 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
311 switch (internalFormat
) {
312 case GL_DEPTH_STENCIL_EXT
:
313 case GL_DEPTH24_STENCIL8_EXT
:
314 return GL_DEPTH_STENCIL_EXT
;
320 if (ctx
->Extensions
.EXT_texture_sRGB
) {
321 switch (internalFormat
) {
324 case GL_COMPRESSED_SRGB_EXT
:
325 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
327 case GL_SRGB_ALPHA_EXT
:
328 case GL_SRGB8_ALPHA8_EXT
:
329 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
330 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
331 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
332 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
334 case GL_SLUMINANCE_ALPHA_EXT
:
335 case GL_SLUMINANCE8_ALPHA8_EXT
:
336 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
337 return GL_LUMINANCE_ALPHA
;
338 case GL_SLUMINANCE_EXT
:
339 case GL_SLUMINANCE8_EXT
:
340 case GL_COMPRESSED_SLUMINANCE_EXT
:
347 if (ctx
->Version
>= 30 ||
348 ctx
->Extensions
.EXT_texture_integer
) {
349 switch (internalFormat
) {
351 case GL_RGBA16UI_EXT
:
352 case GL_RGBA32UI_EXT
:
368 if (ctx
->Extensions
.EXT_texture_integer
) {
369 switch (internalFormat
) {
370 case GL_ALPHA8UI_EXT
:
371 case GL_ALPHA16UI_EXT
:
372 case GL_ALPHA32UI_EXT
:
374 case GL_ALPHA16I_EXT
:
375 case GL_ALPHA32I_EXT
:
377 case GL_INTENSITY8UI_EXT
:
378 case GL_INTENSITY16UI_EXT
:
379 case GL_INTENSITY32UI_EXT
:
380 case GL_INTENSITY8I_EXT
:
381 case GL_INTENSITY16I_EXT
:
382 case GL_INTENSITY32I_EXT
:
384 case GL_LUMINANCE8UI_EXT
:
385 case GL_LUMINANCE16UI_EXT
:
386 case GL_LUMINANCE32UI_EXT
:
387 case GL_LUMINANCE8I_EXT
:
388 case GL_LUMINANCE16I_EXT
:
389 case GL_LUMINANCE32I_EXT
:
391 case GL_LUMINANCE_ALPHA8UI_EXT
:
392 case GL_LUMINANCE_ALPHA16UI_EXT
:
393 case GL_LUMINANCE_ALPHA32UI_EXT
:
394 case GL_LUMINANCE_ALPHA8I_EXT
:
395 case GL_LUMINANCE_ALPHA16I_EXT
:
396 case GL_LUMINANCE_ALPHA32I_EXT
:
397 return GL_LUMINANCE_ALPHA
;
403 if (ctx
->Extensions
.ARB_texture_rg
) {
404 switch (internalFormat
) {
406 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
408 if (!ctx
->Extensions
.ARB_half_float_pixel
)
412 if (!ctx
->Extensions
.ARB_texture_float
)
421 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
427 case GL_COMPRESSED_RED
:
431 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
433 if (!ctx
->Extensions
.ARB_half_float_pixel
)
437 if (!ctx
->Extensions
.ARB_texture_float
)
446 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
452 case GL_COMPRESSED_RG
:
459 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
460 switch (internalFormat
) {
468 if (ctx
->Extensions
.EXT_packed_float
) {
469 switch (internalFormat
) {
470 case GL_R11F_G11F_B10F_EXT
:
477 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
478 switch (internalFormat
) {
479 case GL_DEPTH_COMPONENT32F
:
480 return GL_DEPTH_COMPONENT
;
481 case GL_DEPTH32F_STENCIL8
:
482 return GL_DEPTH_STENCIL
;
488 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
489 switch (internalFormat
) {
490 case GL_COMPRESSED_RED_RGTC1
:
491 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
493 case GL_COMPRESSED_RG_RGTC2
:
494 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
501 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
502 switch (internalFormat
) {
503 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
504 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
506 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
507 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
508 return GL_LUMINANCE_ALPHA
;
514 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
515 switch (internalFormat
) {
516 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
517 return GL_LUMINANCE_ALPHA
;
523 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
524 switch (internalFormat
) {
525 case GL_ETC1_RGB8_OES
:
532 if (ctx
->API
== API_OPENGLES
) {
533 switch (internalFormat
) {
534 case GL_PALETTE4_RGB8_OES
:
535 case GL_PALETTE4_R5_G6_B5_OES
:
536 case GL_PALETTE8_RGB8_OES
:
537 case GL_PALETTE8_R5_G6_B5_OES
:
539 case GL_PALETTE4_RGBA8_OES
:
540 case GL_PALETTE8_RGB5_A1_OES
:
541 case GL_PALETTE4_RGBA4_OES
:
542 case GL_PALETTE4_RGB5_A1_OES
:
543 case GL_PALETTE8_RGBA8_OES
:
544 case GL_PALETTE8_RGBA4_OES
:
551 return -1; /* error */
556 * For cube map faces, return a face index in [0,5].
557 * For other targets return 0;
560 _mesa_tex_target_to_face(GLenum target
)
562 if (_mesa_is_cube_face(target
))
563 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
571 * Install gl_texture_image in a gl_texture_object according to the target
572 * and level parameters.
574 * \param tObj texture object.
575 * \param target texture target.
576 * \param level image level.
577 * \param texImage texture image.
580 set_tex_image(struct gl_texture_object
*tObj
,
581 GLenum target
, GLint level
,
582 struct gl_texture_image
*texImage
)
584 const GLuint face
= _mesa_tex_target_to_face(target
);
588 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
591 tObj
->Image
[face
][level
] = texImage
;
593 /* Set the 'back' pointer */
594 texImage
->TexObject
= tObj
;
595 texImage
->Level
= level
;
596 texImage
->Face
= face
;
601 * Allocate a texture image structure.
603 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
606 * \return a pointer to gl_texture_image struct with all fields initialized to
609 struct gl_texture_image
*
610 _mesa_new_texture_image( struct gl_context
*ctx
)
613 return CALLOC_STRUCT(gl_texture_image
);
618 * Free a gl_texture_image and associated data.
619 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
621 * \param texImage texture image.
623 * Free the texture image structure and the associated image data.
626 _mesa_delete_texture_image(struct gl_context
*ctx
,
627 struct gl_texture_image
*texImage
)
629 /* Free texImage->Data and/or any other driver-specific texture
632 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
633 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
639 * Test if a target is a proxy target.
641 * \param target texture target.
643 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
646 _mesa_is_proxy_texture(GLenum target
)
649 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
650 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
652 assert(NUM_TEXTURE_TARGETS
== 8 + 2);
654 return (target
== GL_PROXY_TEXTURE_1D
||
655 target
== GL_PROXY_TEXTURE_2D
||
656 target
== GL_PROXY_TEXTURE_3D
||
657 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
658 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
659 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
660 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
661 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
);
666 * Return the proxy target which corresponds to the given texture target
669 _mesa_get_proxy_target(GLenum target
)
673 case GL_PROXY_TEXTURE_1D
:
674 return GL_PROXY_TEXTURE_1D
;
676 case GL_PROXY_TEXTURE_2D
:
677 return GL_PROXY_TEXTURE_2D
;
679 case GL_PROXY_TEXTURE_3D
:
680 return GL_PROXY_TEXTURE_3D
;
681 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
682 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
683 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
684 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
685 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
686 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
687 case GL_TEXTURE_CUBE_MAP_ARB
:
688 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
689 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
690 case GL_TEXTURE_RECTANGLE_NV
:
691 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
692 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
693 case GL_TEXTURE_1D_ARRAY_EXT
:
694 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
695 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
696 case GL_TEXTURE_2D_ARRAY_EXT
:
697 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
698 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
699 case GL_TEXTURE_CUBE_MAP_ARRAY
:
700 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
701 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
703 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
710 * Get the texture object that corresponds to the target of the given
711 * texture unit. The target should have already been checked for validity.
713 * \param ctx GL context.
714 * \param texUnit texture unit.
715 * \param target texture target.
717 * \return pointer to the texture object on success, or NULL on failure.
719 struct gl_texture_object
*
720 _mesa_select_tex_object(struct gl_context
*ctx
,
721 const struct gl_texture_unit
*texUnit
,
724 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
725 ctx
->Extensions
.EXT_texture_array
);
729 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
730 case GL_PROXY_TEXTURE_1D
:
731 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
733 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
734 case GL_PROXY_TEXTURE_2D
:
735 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
737 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
738 case GL_PROXY_TEXTURE_3D
:
739 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
740 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
741 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
742 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
743 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
744 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
745 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
746 case GL_TEXTURE_CUBE_MAP_ARB
:
747 return ctx
->Extensions
.ARB_texture_cube_map
748 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
749 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
750 return ctx
->Extensions
.ARB_texture_cube_map
751 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
752 case GL_TEXTURE_CUBE_MAP_ARRAY
:
753 return ctx
->Extensions
.ARB_texture_cube_map_array
754 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
755 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
756 return ctx
->Extensions
.ARB_texture_cube_map_array
757 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
758 case GL_TEXTURE_RECTANGLE_NV
:
759 return ctx
->Extensions
.NV_texture_rectangle
760 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
761 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
762 return ctx
->Extensions
.NV_texture_rectangle
763 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
764 case GL_TEXTURE_1D_ARRAY_EXT
:
765 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
766 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
767 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
768 case GL_TEXTURE_2D_ARRAY_EXT
:
769 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
770 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
771 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
772 case GL_TEXTURE_BUFFER
:
773 return _mesa_is_desktop_gl(ctx
)
774 && ctx
->Extensions
.ARB_texture_buffer_object
775 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
776 case GL_TEXTURE_EXTERNAL_OES
:
777 return ctx
->Extensions
.OES_EGL_image_external
778 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
780 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
787 * Return pointer to texture object for given target on current texture unit.
789 struct gl_texture_object
*
790 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
792 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
793 return _mesa_select_tex_object(ctx
, texUnit
, target
);
798 * Get a texture image pointer from a texture object, given a texture
799 * target and mipmap level. The target and level parameters should
800 * have already been error-checked.
802 * \param ctx GL context.
803 * \param texObj texture unit.
804 * \param target texture target.
805 * \param level image level.
807 * \return pointer to the texture image structure, or NULL on failure.
809 struct gl_texture_image
*
810 _mesa_select_tex_image(struct gl_context
*ctx
,
811 const struct gl_texture_object
*texObj
,
812 GLenum target
, GLint level
)
814 const GLuint face
= _mesa_tex_target_to_face(target
);
818 ASSERT(level
< MAX_TEXTURE_LEVELS
);
820 return texObj
->Image
[face
][level
];
825 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
826 * it and install it. Only return NULL if passed a bad parameter or run
829 struct gl_texture_image
*
830 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
831 GLenum target
, GLint level
)
833 struct gl_texture_image
*texImage
;
838 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
840 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
842 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
846 set_tex_image(texObj
, target
, level
, texImage
);
854 * Return pointer to the specified proxy texture image.
855 * Note that proxy textures are per-context, not per-texture unit.
856 * \return pointer to texture image or NULL if invalid target, invalid
857 * level, or out of memory.
859 static struct gl_texture_image
*
860 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
862 struct gl_texture_image
*texImage
;
869 case GL_PROXY_TEXTURE_1D
:
870 if (level
>= ctx
->Const
.MaxTextureLevels
)
872 texIndex
= TEXTURE_1D_INDEX
;
874 case GL_PROXY_TEXTURE_2D
:
875 if (level
>= ctx
->Const
.MaxTextureLevels
)
877 texIndex
= TEXTURE_2D_INDEX
;
879 case GL_PROXY_TEXTURE_3D
:
880 if (level
>= ctx
->Const
.Max3DTextureLevels
)
882 texIndex
= TEXTURE_3D_INDEX
;
884 case GL_PROXY_TEXTURE_CUBE_MAP
:
885 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
887 texIndex
= TEXTURE_CUBE_INDEX
;
889 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
892 texIndex
= TEXTURE_RECT_INDEX
;
894 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
895 if (level
>= ctx
->Const
.MaxTextureLevels
)
897 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
899 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
900 if (level
>= ctx
->Const
.MaxTextureLevels
)
902 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
904 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
905 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
907 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
913 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
915 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
917 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
920 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
921 /* Set the 'back' pointer */
922 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
929 * Get the maximum number of allowed mipmap levels.
931 * \param ctx GL context.
932 * \param target texture target.
934 * \return the maximum number of allowed mipmap levels for the given
935 * texture target, or zero if passed a bad target.
940 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
944 case GL_PROXY_TEXTURE_1D
:
946 case GL_PROXY_TEXTURE_2D
:
947 return ctx
->Const
.MaxTextureLevels
;
949 case GL_PROXY_TEXTURE_3D
:
950 return ctx
->Const
.Max3DTextureLevels
;
951 case GL_TEXTURE_CUBE_MAP
:
952 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
953 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
954 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
955 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
956 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
957 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
958 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
959 return ctx
->Extensions
.ARB_texture_cube_map
960 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
961 case GL_TEXTURE_RECTANGLE_NV
:
962 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
963 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
964 case GL_TEXTURE_1D_ARRAY_EXT
:
965 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
966 case GL_TEXTURE_2D_ARRAY_EXT
:
967 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
968 return (ctx
->Extensions
.MESA_texture_array
||
969 ctx
->Extensions
.EXT_texture_array
)
970 ? ctx
->Const
.MaxTextureLevels
: 0;
971 case GL_TEXTURE_CUBE_MAP_ARRAY
:
972 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
973 return ctx
->Extensions
.ARB_texture_cube_map_array
974 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
975 case GL_TEXTURE_BUFFER
:
976 return _mesa_is_desktop_gl(ctx
)
977 && ctx
->Extensions
.ARB_texture_buffer_object
979 case GL_TEXTURE_EXTERNAL_OES
:
982 return 0; /* bad target */
988 * Return number of dimensions per mipmap level for the given texture target.
991 _mesa_get_texture_dimensions(GLenum target
)
995 case GL_PROXY_TEXTURE_1D
:
998 case GL_TEXTURE_RECTANGLE
:
999 case GL_TEXTURE_CUBE_MAP
:
1000 case GL_PROXY_TEXTURE_2D
:
1001 case GL_PROXY_TEXTURE_RECTANGLE
:
1002 case GL_PROXY_TEXTURE_CUBE_MAP
:
1003 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1004 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1005 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1006 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1007 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1008 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1009 case GL_TEXTURE_1D_ARRAY
:
1010 case GL_PROXY_TEXTURE_1D_ARRAY
:
1011 case GL_TEXTURE_EXTERNAL_OES
:
1014 case GL_PROXY_TEXTURE_3D
:
1015 case GL_TEXTURE_2D_ARRAY
:
1016 case GL_PROXY_TEXTURE_2D_ARRAY
:
1017 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1018 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1020 case GL_TEXTURE_BUFFER
:
1023 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1032 #if 000 /* not used anymore */
1034 * glTexImage[123]D can accept a NULL image pointer. In this case we
1035 * create a texture image with unspecified image contents per the OpenGL
1039 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1041 const GLint components
= _mesa_components_in_format(format
);
1042 const GLint numPixels
= width
* height
* depth
;
1043 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1047 * Let's see if anyone finds this. If glTexImage2D() is called with
1048 * a NULL image pointer then load the texture image with something
1049 * interesting instead of leaving it indeterminate.
1052 static const char message
[8][32] = {
1053 " X X XXXXX XXX X ",
1054 " XX XX X X X X X ",
1056 " X X XXXX XXX XXXXX ",
1059 " X X XXXXX XXX X X ",
1063 GLubyte
*imgPtr
= data
;
1065 for (h
= 0; h
< depth
; h
++) {
1066 for (i
= 0; i
< height
; i
++) {
1067 GLint srcRow
= 7 - (i
% 8);
1068 for (j
= 0; j
< width
; j
++) {
1069 GLint srcCol
= j
% 32;
1070 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1071 for (k
= 0; k
< components
; k
++) {
1087 * Set the size and format-related fields of a gl_texture_image struct
1088 * to zero. This is used when a proxy texture test fails.
1091 clear_teximage_fields(struct gl_texture_image
*img
)
1094 img
->_BaseFormat
= 0;
1095 img
->InternalFormat
= 0;
1104 img
->HeightLog2
= 0;
1106 img
->TexFormat
= MESA_FORMAT_NONE
;
1111 * Initialize basic fields of the gl_texture_image struct.
1113 * \param ctx GL context.
1114 * \param img texture image structure to be initialized.
1115 * \param width image width.
1116 * \param height image height.
1117 * \param depth image depth.
1118 * \param border image border.
1119 * \param internalFormat internal format.
1120 * \param format the actual hardware format (one of MESA_FORMAT_*)
1122 * Fills in the fields of \p img with the given information.
1123 * Note: width, height and depth include the border.
1126 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1127 struct gl_texture_image
*img
,
1128 GLsizei width
, GLsizei height
, GLsizei depth
,
1129 GLint border
, GLenum internalFormat
,
1135 ASSERT(height
>= 0);
1138 target
= img
->TexObject
->Target
;
1139 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1140 ASSERT(img
->_BaseFormat
> 0);
1141 img
->InternalFormat
= internalFormat
;
1142 img
->Border
= border
;
1144 img
->Height
= height
;
1147 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1148 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1152 case GL_TEXTURE_BUFFER
:
1153 case GL_PROXY_TEXTURE_1D
:
1158 img
->HeightLog2
= 0;
1165 case GL_TEXTURE_1D_ARRAY
:
1166 case GL_PROXY_TEXTURE_1D_ARRAY
:
1167 img
->Height2
= height
; /* no border */
1168 img
->HeightLog2
= 0; /* not used */
1176 case GL_TEXTURE_RECTANGLE
:
1177 case GL_TEXTURE_CUBE_MAP
:
1178 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1179 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1180 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1181 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1182 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1183 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1184 case GL_TEXTURE_EXTERNAL_OES
:
1185 case GL_PROXY_TEXTURE_2D
:
1186 case GL_PROXY_TEXTURE_RECTANGLE
:
1187 case GL_PROXY_TEXTURE_CUBE_MAP
:
1188 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1189 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1196 case GL_TEXTURE_2D_ARRAY
:
1197 case GL_PROXY_TEXTURE_2D_ARRAY
:
1198 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1199 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1200 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1201 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1202 img
->Depth2
= depth
; /* no border */
1203 img
->DepthLog2
= 0; /* not used */
1206 case GL_PROXY_TEXTURE_3D
:
1207 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1208 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1209 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1210 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1213 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1217 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1218 img
->TexFormat
= format
;
1223 * Free and clear fields of the gl_texture_image struct.
1225 * \param ctx GL context.
1226 * \param texImage texture image structure to be cleared.
1228 * After the call, \p texImage will have no data associated with it. Its
1229 * fields are cleared so that its parent object will test incomplete.
1232 _mesa_clear_texture_image(struct gl_context
*ctx
,
1233 struct gl_texture_image
*texImage
)
1235 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1236 clear_teximage_fields(texImage
);
1241 * Check the width, height, depth and border of a texture image are legal.
1242 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1244 * The target and level parameters will have already been validated.
1245 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1248 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1249 GLint level
, GLint width
, GLint height
,
1250 GLint depth
, GLint border
)
1256 case GL_PROXY_TEXTURE_1D
:
1257 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1258 maxSize
>>= level
; /* level size */
1259 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1261 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1262 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1268 case GL_PROXY_TEXTURE_2D
:
1269 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1271 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1273 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1275 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1276 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1278 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1284 case GL_PROXY_TEXTURE_3D
:
1285 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1287 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1289 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1291 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1293 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1294 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1296 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1298 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1303 case GL_TEXTURE_RECTANGLE_NV
:
1304 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1307 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1308 if (width
< 0 || width
> maxSize
)
1310 if (height
< 0 || height
> maxSize
)
1314 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1315 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1316 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1317 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1318 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1319 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1320 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1321 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1323 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1325 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1327 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1328 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1330 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1335 case GL_TEXTURE_1D_ARRAY_EXT
:
1336 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1337 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1339 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1341 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1343 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1344 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1349 case GL_TEXTURE_2D_ARRAY_EXT
:
1350 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1351 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1353 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1355 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1357 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1359 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1360 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1362 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1367 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1368 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1369 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1370 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1372 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1374 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1376 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1378 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1379 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1381 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1386 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1393 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1394 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1395 * \param destImage the destination texture image.
1396 * \return GL_TRUE if error found, GL_FALSE otherwise.
1399 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1400 const char *function
, GLuint dims
,
1401 const struct gl_texture_image
*destImage
,
1402 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1403 GLsizei subWidth
, GLsizei subHeight
,
1406 const GLenum target
= destImage
->TexObject
->Target
;
1411 _mesa_error(ctx
, GL_INVALID_VALUE
,
1412 "%s%dD(width=%d)", function
, dims
, subWidth
);
1416 if (dims
> 1 && subHeight
< 0) {
1417 _mesa_error(ctx
, GL_INVALID_VALUE
,
1418 "%s%dD(height=%d)", function
, dims
, subHeight
);
1422 if (dims
> 2 && subDepth
< 0) {
1423 _mesa_error(ctx
, GL_INVALID_VALUE
,
1424 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1428 /* check xoffset and width */
1429 if (xoffset
< -destImage
->Border
) {
1430 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1435 if (xoffset
+ subWidth
> destImage
->Width
) {
1436 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1441 /* check yoffset and height */
1443 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1444 if (yoffset
< -yBorder
) {
1445 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1449 if (yoffset
+ subHeight
> destImage
->Height
) {
1450 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1456 /* check zoffset and depth */
1458 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1459 if (zoffset
< -zBorder
) {
1460 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1463 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1464 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1470 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1471 * compressed texture images can be updated. But, that restriction may be
1472 * relaxed for particular compressed formats. At this time, all the
1473 * compressed formats supported by Mesa allow sub-textures to be updated
1474 * along compressed block boundaries.
1476 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1478 if (bw
!= 1 || bh
!= 1) {
1479 /* offset must be multiple of block size */
1480 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1481 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1482 "%s%dD(xoffset = %d, yoffset = %d)",
1483 function
, dims
, xoffset
, yoffset
);
1487 /* size must be multiple of bw by bh or equal to whole texture size */
1488 if ((subWidth
% bw
!= 0) && subWidth
!= destImage
->Width
) {
1489 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1490 "%s%dD(width = %d)", function
, dims
, subWidth
);
1494 if ((subHeight
% bh
!= 0) && subHeight
!= destImage
->Height
) {
1495 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1496 "%s%dD(height = %d)", function
, dims
, subHeight
);
1508 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1509 * specific texture image size checks.
1511 * A hardware driver might override this function if, for example, the
1512 * max 3D texture size is 512x512x64 (i.e. not a cube).
1514 * Note that width, height, depth == 0 is not an error. However, a
1515 * texture with zero width/height/depth will be considered "incomplete"
1516 * and texturing will effectively be disabled.
1518 * \param target any texture target/type
1519 * \param level as passed to glTexImage
1520 * \param format the MESA_FORMAT_x for the tex image
1521 * \param width as passed to glTexImage
1522 * \param height as passed to glTexImage
1523 * \param depth as passed to glTexImage
1524 * \param border as passed to glTexImage
1525 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1528 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1530 GLint width
, GLint height
, GLint depth
, GLint border
)
1532 /* We just check if the image size is less than MaxTextureMbytes.
1533 * Some drivers may do more specific checks.
1535 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1536 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1537 mbytes
*= _mesa_num_tex_faces(target
);
1538 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1543 * Return true if the format is only valid for glCompressedTexImage.
1546 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1549 case GL_ETC1_RGB8_OES
:
1550 case GL_PALETTE4_RGB8_OES
:
1551 case GL_PALETTE4_RGBA8_OES
:
1552 case GL_PALETTE4_R5_G6_B5_OES
:
1553 case GL_PALETTE4_RGBA4_OES
:
1554 case GL_PALETTE4_RGB5_A1_OES
:
1555 case GL_PALETTE8_RGB8_OES
:
1556 case GL_PALETTE8_RGBA8_OES
:
1557 case GL_PALETTE8_R5_G6_B5_OES
:
1558 case GL_PALETTE8_RGBA4_OES
:
1559 case GL_PALETTE8_RGB5_A1_OES
:
1568 * Helper function to determine whether a target and specific compression
1569 * format are supported.
1572 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1575 (void) intFormat
; /* not used yet */
1579 case GL_PROXY_TEXTURE_2D
:
1580 return GL_TRUE
; /* true for any compressed format so far */
1581 case GL_PROXY_TEXTURE_CUBE_MAP
:
1582 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1583 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1584 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1585 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1586 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1587 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1588 return ctx
->Extensions
.ARB_texture_cube_map
;
1589 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1590 case GL_TEXTURE_2D_ARRAY_EXT
:
1591 return (ctx
->Extensions
.MESA_texture_array
||
1592 ctx
->Extensions
.EXT_texture_array
);
1593 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1594 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1595 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1603 * Check if the given texture target value is legal for a
1604 * glTexImage1/2/3D call.
1607 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1613 case GL_PROXY_TEXTURE_1D
:
1614 return _mesa_is_desktop_gl(ctx
);
1622 case GL_PROXY_TEXTURE_2D
:
1623 return _mesa_is_desktop_gl(ctx
);
1624 case GL_PROXY_TEXTURE_CUBE_MAP
:
1625 return _mesa_is_desktop_gl(ctx
)
1626 && ctx
->Extensions
.ARB_texture_cube_map
;
1627 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1628 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1629 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1630 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1631 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1632 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1633 return ctx
->Extensions
.ARB_texture_cube_map
;
1634 case GL_TEXTURE_RECTANGLE_NV
:
1635 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1636 return _mesa_is_desktop_gl(ctx
)
1637 && ctx
->Extensions
.NV_texture_rectangle
;
1638 case GL_TEXTURE_1D_ARRAY_EXT
:
1639 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1640 return _mesa_is_desktop_gl(ctx
)
1641 && (ctx
->Extensions
.MESA_texture_array
||
1642 ctx
->Extensions
.EXT_texture_array
);
1650 case GL_PROXY_TEXTURE_3D
:
1651 return _mesa_is_desktop_gl(ctx
);
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
);
1657 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1658 return _mesa_is_desktop_gl(ctx
)
1659 && (ctx
->Extensions
.MESA_texture_array
||
1660 ctx
->Extensions
.EXT_texture_array
);
1661 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1662 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1663 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1668 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1675 * Check if the given texture target value is legal for a
1676 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1677 * The difference compared to legal_teximage_target() above is that
1678 * proxy targets are not supported.
1681 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1685 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1690 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1691 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1692 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1693 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1694 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1695 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1696 return ctx
->Extensions
.ARB_texture_cube_map
;
1697 case GL_TEXTURE_RECTANGLE_NV
:
1698 return _mesa_is_desktop_gl(ctx
)
1699 && ctx
->Extensions
.NV_texture_rectangle
;
1700 case GL_TEXTURE_1D_ARRAY_EXT
:
1701 return _mesa_is_desktop_gl(ctx
)
1702 && (ctx
->Extensions
.MESA_texture_array
||
1703 ctx
->Extensions
.EXT_texture_array
);
1711 case GL_TEXTURE_2D_ARRAY_EXT
:
1712 return (_mesa_is_desktop_gl(ctx
)
1713 && (ctx
->Extensions
.MESA_texture_array
||
1714 ctx
->Extensions
.EXT_texture_array
))
1715 || _mesa_is_gles3(ctx
);
1716 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1717 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1718 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1723 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1731 * Helper function to determine if a texture object is mutable (in terms
1732 * of GL_ARB_texture_storage).
1735 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1737 if (ctx
->Extensions
.ARB_texture_storage
) {
1738 struct gl_texture_object
*texObj
=
1739 _mesa_get_current_tex_object(ctx
, target
);
1740 return !texObj
->Immutable
;
1747 * Return expected size of a compressed texture.
1750 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1753 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1754 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1759 * Test the glTexImage[123]D() parameters for errors.
1761 * \param ctx GL context.
1762 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1763 * \param target texture target given by the user (already validated).
1764 * \param level image level given by the user.
1765 * \param internalFormat internal format given by the user.
1766 * \param format pixel data format given by the user.
1767 * \param type pixel data type given by the user.
1768 * \param width image width given by the user.
1769 * \param height image height given by the user.
1770 * \param depth image depth given by the user.
1771 * \param border image border given by the user.
1773 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1775 * Verifies each of the parameters against the constants specified in
1776 * __struct gl_contextRec::Const and the supported extensions, and according
1777 * to the OpenGL specification.
1778 * Note that we don't fully error-check the width, height, depth values
1779 * here. That's done in _mesa_legal_texture_dimensions() which is used
1780 * by several other GL entrypoints. Plus, texture dims have a special
1781 * interaction with proxy textures.
1784 texture_error_check( struct gl_context
*ctx
,
1785 GLuint dimensions
, GLenum target
,
1786 GLint level
, GLint internalFormat
,
1787 GLenum format
, GLenum type
,
1788 GLint width
, GLint height
,
1789 GLint depth
, GLint border
)
1791 GLboolean colorFormat
;
1794 /* Even though there are no color-index textures, we still have to support
1795 * uploading color-index data and remapping it to RGB via the
1796 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1798 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1800 /* Note: for proxy textures, some error conditions immediately generate
1801 * a GL error in the usual way. But others do not generate a GL error.
1802 * Instead, they cause the width, height, depth, format fields of the
1803 * texture image to be zeroed-out. The GL spec seems to indicate that the
1804 * zero-out behaviour is only used in cases related to memory allocation.
1808 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1809 _mesa_error(ctx
, GL_INVALID_VALUE
,
1810 "glTexImage%dD(level=%d)", dimensions
, level
);
1815 if (border
< 0 || border
> 1 ||
1816 ((ctx
->API
!= API_OPENGL
||
1817 target
== GL_TEXTURE_RECTANGLE_NV
||
1818 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1819 _mesa_error(ctx
, GL_INVALID_VALUE
,
1820 "glTexImage%dD(border=%d)", dimensions
, border
);
1824 if (width
< 0 || height
< 0 || depth
< 0) {
1825 _mesa_error(ctx
, GL_INVALID_VALUE
,
1826 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1830 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1831 * combinations of format, internalFormat, and type that can be used.
1832 * Formats and types that require additional extensions (e.g., GL_FLOAT
1833 * requires GL_OES_texture_float) are filtered elsewhere.
1836 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
1837 if (format
!= internalFormat
) {
1838 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1839 "glTexImage%dD(format = %s, internalFormat = %s)",
1841 _mesa_lookup_enum_by_nr(format
),
1842 _mesa_lookup_enum_by_nr(internalFormat
));
1846 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1847 if (err
!= GL_NO_ERROR
) {
1848 _mesa_error(ctx
, err
,
1849 "glTexImage%dD(format = %s, type = %s)",
1851 _mesa_lookup_enum_by_nr(format
),
1852 _mesa_lookup_enum_by_nr(type
));
1857 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1858 _mesa_is_cube_face(target
)) && width
!= height
) {
1859 _mesa_error(ctx
, GL_INVALID_VALUE
,
1860 "glTexImage2D(cube width != height)");
1864 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1865 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && width
!= height
) {
1866 _mesa_error(ctx
, GL_INVALID_VALUE
,
1867 "glTexImage3D(cube array width != height)");
1871 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1872 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && (depth
% 6)) {
1873 _mesa_error(ctx
, GL_INVALID_VALUE
,
1874 "glTexImage3D(cube array depth not multiple of 6)");
1878 /* Check internalFormat */
1879 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1880 _mesa_error(ctx
, GL_INVALID_VALUE
,
1881 "glTexImage%dD(internalFormat=%s)",
1882 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1886 /* Check incoming image format and type */
1887 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1888 if (err
!= GL_NO_ERROR
) {
1889 _mesa_error(ctx
, err
,
1890 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1891 dimensions
, format
, type
);
1895 /* make sure internal format and format basically agree */
1896 colorFormat
= _mesa_is_color_format(format
);
1897 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1898 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1899 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1900 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1901 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1902 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1903 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1904 dimensions
, internalFormat
, format
);
1908 /* additional checks for ycbcr textures */
1909 if (internalFormat
== GL_YCBCR_MESA
) {
1910 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1911 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1912 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1914 _mesa_snprintf(message
, sizeof(message
),
1915 "glTexImage%dD(format/type YCBCR mismatch)",
1917 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1918 return GL_TRUE
; /* error */
1920 if (target
!= GL_TEXTURE_2D
&&
1921 target
!= GL_PROXY_TEXTURE_2D
&&
1922 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1923 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1924 _mesa_error(ctx
, GL_INVALID_ENUM
,
1925 "glTexImage%dD(bad target for YCbCr texture)",
1931 _mesa_snprintf(message
, sizeof(message
),
1932 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1933 dimensions
, border
);
1934 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1939 /* additional checks for depth textures */
1940 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1941 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1942 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1943 if (target
!= GL_TEXTURE_1D
&&
1944 target
!= GL_PROXY_TEXTURE_1D
&&
1945 target
!= GL_TEXTURE_2D
&&
1946 target
!= GL_PROXY_TEXTURE_2D
&&
1947 target
!= GL_TEXTURE_1D_ARRAY
&&
1948 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1949 target
!= GL_TEXTURE_2D_ARRAY
&&
1950 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1951 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1952 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1953 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1954 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
)) &&
1955 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
1956 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
1957 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
1958 _mesa_error(ctx
, GL_INVALID_ENUM
,
1959 "glTexImage%dD(bad target for depth texture)",
1965 /* additional checks for compressed textures */
1966 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1967 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1968 _mesa_error(ctx
, GL_INVALID_ENUM
,
1969 "glTexImage%dD(target can't be compressed)", dimensions
);
1972 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1973 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1974 "glTexImage%dD(no compression for format)", dimensions
);
1978 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1979 "glTexImage%dD(border!=0)", dimensions
);
1984 /* additional checks for integer textures */
1985 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1986 (_mesa_is_enum_format_integer(format
) !=
1987 _mesa_is_enum_format_integer(internalFormat
))) {
1988 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1989 "glTexImage%dD(integer/non-integer format mismatch)",
1994 if (!mutable_tex_object(ctx
, target
)) {
1995 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1996 "glTexImage%dD(immutable texture)", dimensions
);
2000 /* if we get here, the parameters are OK */
2006 * Error checking for glCompressedTexImage[123]D().
2007 * Note that the width, height and depth values are not fully error checked
2009 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2012 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2013 GLenum target
, GLint level
,
2014 GLenum internalFormat
, GLsizei width
,
2015 GLsizei height
, GLsizei depth
, GLint border
,
2018 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2020 GLenum error
= GL_NO_ERROR
;
2021 char *reason
= ""; /* no error */
2023 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2025 error
= GL_INVALID_ENUM
;
2029 /* This will detect any invalid internalFormat value */
2030 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2031 reason
= "internalFormat";
2032 error
= GL_INVALID_ENUM
;
2036 switch (internalFormat
) {
2037 case GL_PALETTE4_RGB8_OES
:
2038 case GL_PALETTE4_RGBA8_OES
:
2039 case GL_PALETTE4_R5_G6_B5_OES
:
2040 case GL_PALETTE4_RGBA4_OES
:
2041 case GL_PALETTE4_RGB5_A1_OES
:
2042 case GL_PALETTE8_RGB8_OES
:
2043 case GL_PALETTE8_RGBA8_OES
:
2044 case GL_PALETTE8_R5_G6_B5_OES
:
2045 case GL_PALETTE8_RGBA4_OES
:
2046 case GL_PALETTE8_RGB5_A1_OES
:
2047 /* check level (note that level should be zero or less!) */
2048 if (level
> 0 || level
< -maxLevels
) {
2050 error
= GL_INVALID_VALUE
;
2054 if (dimensions
!= 2) {
2055 reason
= "compressed paletted textures must be 2D";
2056 error
= GL_INVALID_OPERATION
;
2060 /* Figure out the expected texture size (in bytes). This will be
2061 * checked against the actual size later.
2063 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2066 /* This is for the benefit of the TestProxyTexImage below. It expects
2067 * level to be non-negative. OES_compressed_paletted_texture uses a
2068 * weird mechanism where the level specified to glCompressedTexImage2D
2069 * is -(n-1) number of levels in the texture, and the data specifies the
2070 * complete mipmap stack. This is done to ensure the palette is the
2071 * same for all levels.
2078 if (level
< 0 || level
>= maxLevels
) {
2080 error
= GL_INVALID_VALUE
;
2084 /* Figure out the expected texture size (in bytes). This will be
2085 * checked against the actual size later.
2087 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2091 /* This should really never fail */
2092 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2093 reason
= "internalFormat";
2094 error
= GL_INVALID_ENUM
;
2098 /* No compressed formats support borders at this time */
2100 reason
= "border != 0";
2101 error
= GL_INVALID_VALUE
;
2105 /* For cube map, width must equal height */
2106 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2107 _mesa_is_cube_face(target
)) && width
!= height
) {
2108 reason
= "width != height";
2109 error
= GL_INVALID_VALUE
;
2113 /* check image size in bytes */
2114 if (expectedSize
!= imageSize
) {
2115 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2116 * if <imageSize> is not consistent with the format, dimensions, and
2117 * contents of the specified image.
2119 reason
= "imageSize inconsistant with width/height/format";
2120 error
= GL_INVALID_VALUE
;
2124 if (!mutable_tex_object(ctx
, target
)) {
2125 reason
= "immutable texture";
2126 error
= GL_INVALID_OPERATION
;
2133 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2140 * Test glTexSubImage[123]D() parameters for errors.
2142 * \param ctx GL context.
2143 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2144 * \param target texture target given by the user (already validated)
2145 * \param level image level given by the user.
2146 * \param xoffset sub-image x offset given by the user.
2147 * \param yoffset sub-image y offset given by the user.
2148 * \param zoffset sub-image z offset given by the user.
2149 * \param format pixel data format given by the user.
2150 * \param type pixel data type given by the user.
2151 * \param width image width given by the user.
2152 * \param height image height given by the user.
2153 * \param depth image depth given by the user.
2155 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2157 * Verifies each of the parameters against the constants specified in
2158 * __struct gl_contextRec::Const and the supported extensions, and according
2159 * to the OpenGL specification.
2162 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2163 GLenum target
, GLint level
,
2164 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2165 GLint width
, GLint height
, GLint depth
,
2166 GLenum format
, GLenum type
)
2168 struct gl_texture_object
*texObj
;
2169 struct gl_texture_image
*texImage
;
2172 /* check target (proxies not allowed) */
2173 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2174 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2175 dimensions
, _mesa_lookup_enum_by_nr(target
));
2180 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2181 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2186 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2187 * combinations of format and type that can be used. Formats and types
2188 * that require additional extensions (e.g., GL_FLOAT requires
2189 * GL_OES_texture_float) are filtered elsewhere.
2191 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2192 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2193 if (err
!= GL_NO_ERROR
) {
2194 _mesa_error(ctx
, err
,
2195 "glTexSubImage%dD(format = %s, type = %s)",
2197 _mesa_lookup_enum_by_nr(format
),
2198 _mesa_lookup_enum_by_nr(type
));
2203 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2204 if (err
!= GL_NO_ERROR
) {
2205 _mesa_error(ctx
, err
,
2206 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
2207 dimensions
, format
, type
);
2211 /* Get dest texture object / image pointers */
2212 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2214 /* must be out of memory */
2215 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2219 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2221 /* non-existant texture level */
2222 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2223 "glTexSubImage%dD(invalid texture image)", dimensions
);
2227 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2228 texImage
, xoffset
, yoffset
, 0,
2229 width
, height
, 1)) {
2233 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2234 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2235 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2236 "glTexSubImage%dD(no compression for format)", dimensions
);
2241 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2242 /* both source and dest must be integer-valued, or neither */
2243 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2244 _mesa_is_enum_format_integer(format
)) {
2245 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2246 "glTexSubImage%dD(integer/non-integer format mismatch)",
2257 * Test glCopyTexImage[12]D() parameters for errors.
2259 * \param ctx GL context.
2260 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2261 * \param target texture target given by the user.
2262 * \param level image level given by the user.
2263 * \param internalFormat internal format given by the user.
2264 * \param width image width given by the user.
2265 * \param height image height given by the user.
2266 * \param border texture border.
2268 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2270 * Verifies each of the parameters against the constants specified in
2271 * __struct gl_contextRec::Const and the supported extensions, and according
2272 * to the OpenGL specification.
2275 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2276 GLenum target
, GLint level
, GLint internalFormat
,
2277 GLint width
, GLint height
, GLint border
)
2282 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2283 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2284 dimensions
, _mesa_lookup_enum_by_nr(target
));
2289 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2290 _mesa_error(ctx
, GL_INVALID_VALUE
,
2291 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2295 /* Check that the source buffer is complete */
2296 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2297 if (ctx
->ReadBuffer
->_Status
== 0) {
2298 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2300 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2301 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2302 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2306 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2307 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2308 "glCopyTexImage%dD(multisample FBO)",
2315 if (border
< 0 || border
> 1 ||
2316 ((ctx
->API
!= API_OPENGL
||
2317 target
== GL_TEXTURE_RECTANGLE_NV
||
2318 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2319 _mesa_error(ctx
, GL_INVALID_VALUE
,
2320 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2324 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2327 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2328 switch (internalFormat
) {
2333 case GL_LUMINANCE_ALPHA
:
2336 _mesa_error(ctx
, GL_INVALID_VALUE
,
2337 "glCopyTexImage%dD(internalFormat)", dimensions
);
2342 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2343 if (baseFormat
< 0) {
2344 _mesa_error(ctx
, GL_INVALID_VALUE
,
2345 "glCopyTexImage%dD(internalFormat)", dimensions
);
2349 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2350 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2351 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2355 /* From the EXT_texture_integer spec:
2357 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2358 * if the texture internalformat is an integer format and the read color
2359 * buffer is not an integer format, or if the internalformat is not an
2360 * integer format and the read color buffer is an integer format."
2362 if (_mesa_is_color_format(internalFormat
)) {
2363 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2365 if (_mesa_is_enum_format_integer(rb
->InternalFormat
) !=
2366 _mesa_is_enum_format_integer(internalFormat
)) {
2367 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2368 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2373 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2374 _mesa_is_cube_face(target
)) && width
!= height
) {
2375 _mesa_error(ctx
, GL_INVALID_VALUE
,
2376 "glTexImage2D(cube width != height)");
2380 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2381 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2382 _mesa_error(ctx
, GL_INVALID_ENUM
,
2383 "glCopyTexImage%dD(target)", dimensions
);
2386 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2387 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2388 "glCopyTexImage%dD(no compression for format)", dimensions
);
2392 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2393 "glCopyTexImage%dD(border!=0)", dimensions
);
2398 if (!mutable_tex_object(ctx
, target
)) {
2399 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2400 "glCopyTexImage%dD(immutable texture)", dimensions
);
2404 /* if we get here, the parameters are OK */
2410 * Test glCopyTexSubImage[12]D() parameters for errors.
2411 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2414 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2415 GLenum target
, GLint level
,
2416 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2417 GLint width
, GLint height
)
2419 struct gl_texture_object
*texObj
;
2420 struct gl_texture_image
*texImage
;
2422 /* Check that the source buffer is complete */
2423 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2424 if (ctx
->ReadBuffer
->_Status
== 0) {
2425 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2427 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2428 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2429 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2433 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2434 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2435 "glCopyTexSubImage%dD(multisample FBO)",
2441 /* check target (proxies not allowed) */
2442 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2443 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2444 dimensions
, _mesa_lookup_enum_by_nr(target
));
2449 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2450 _mesa_error(ctx
, GL_INVALID_VALUE
,
2451 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2455 /* Get dest texture object / image pointers */
2456 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2458 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2462 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2464 /* destination image does not exist */
2465 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2466 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2470 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2471 dimensions
, texImage
,
2472 xoffset
, yoffset
, zoffset
,
2473 width
, height
, 1)) {
2477 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2478 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2479 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2480 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2485 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2486 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2490 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2491 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2492 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2493 dimensions
, texImage
->_BaseFormat
);
2497 /* From the EXT_texture_integer spec:
2499 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2500 * if the texture internalformat is an integer format and the read color
2501 * buffer is not an integer format, or if the internalformat is not an
2502 * integer format and the read color buffer is an integer format."
2504 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2505 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2507 if (_mesa_is_format_integer_color(rb
->Format
) !=
2508 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2509 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2510 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2515 /* if we get here, the parameters are OK */
2520 /** Callback info for walking over FBO hash table */
2523 struct gl_context
*ctx
;
2524 struct gl_texture_object
*texObj
;
2530 * Check render to texture callback. Called from _mesa_HashWalk().
2533 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2535 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2536 const struct cb_info
*info
= (struct cb_info
*) userData
;
2537 struct gl_context
*ctx
= info
->ctx
;
2538 const struct gl_texture_object
*texObj
= info
->texObj
;
2539 const GLuint level
= info
->level
, face
= info
->face
;
2541 /* If this is a user-created FBO */
2542 if (_mesa_is_user_fbo(fb
)) {
2544 /* check if any of the FBO's attachments point to 'texObj' */
2545 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2546 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2547 if (att
->Type
== GL_TEXTURE
&&
2548 att
->Texture
== texObj
&&
2549 att
->TextureLevel
== level
&&
2550 att
->CubeMapFace
== face
) {
2551 ASSERT(_mesa_get_attachment_teximage(att
));
2552 /* Tell driver about the new renderbuffer texture */
2553 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2554 /* Mark fb status as indeterminate to force re-validation */
2563 * When a texture image is specified we have to check if it's bound to
2564 * any framebuffer objects (render to texture) in order to detect changes
2565 * in size or format since that effects FBO completeness.
2566 * Any FBOs rendering into the texture must be re-validated.
2569 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2570 struct gl_texture_object
*texObj
,
2571 GLuint face
, GLuint level
)
2573 /* Only check this texture if it's been marked as RenderToTexture */
2574 if (texObj
->_RenderToTexture
) {
2575 struct cb_info info
;
2577 info
.texObj
= texObj
;
2580 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2586 * If the texture object's GenerateMipmap flag is set and we've
2587 * changed the texture base level image, regenerate the rest of the
2588 * mipmap levels now.
2591 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2592 struct gl_texture_object
*texObj
, GLint level
)
2594 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2595 if (texObj
->GenerateMipmap
&&
2596 level
== texObj
->BaseLevel
&&
2597 level
< texObj
->MaxLevel
) {
2598 ASSERT(ctx
->Driver
.GenerateMipmap
);
2599 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2604 /** Debug helper: override the user-requested internal format */
2606 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2609 if (internalFormat
== GL_RGBA16F_ARB
||
2610 internalFormat
== GL_RGBA32F_ARB
) {
2611 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2614 else if (internalFormat
== GL_RGB16F_ARB
||
2615 internalFormat
== GL_RGB32F_ARB
) {
2616 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2619 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2620 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2621 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2622 return GL_LUMINANCE_ALPHA
;
2624 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2625 internalFormat
== GL_LUMINANCE32F_ARB
) {
2626 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2627 return GL_LUMINANCE
;
2629 else if (internalFormat
== GL_ALPHA16F_ARB
||
2630 internalFormat
== GL_ALPHA32F_ARB
) {
2631 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2635 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2636 internalFormat = GL_RGBA;
2640 return internalFormat
;
2643 return internalFormat
;
2649 * Choose the actual hardware format for a texture image.
2650 * Try to use the same format as the previous image level when possible.
2651 * Otherwise, ask the driver for the best format.
2652 * It's important to try to choose a consistant format for all levels
2653 * for efficient texture memory layout/allocation. In particular, this
2654 * comes up during automatic mipmap generation.
2657 _mesa_choose_texture_format(struct gl_context
*ctx
,
2658 struct gl_texture_object
*texObj
,
2659 GLenum target
, GLint level
,
2660 GLenum internalFormat
, GLenum format
, GLenum type
)
2664 /* see if we've already chosen a format for the previous level */
2666 struct gl_texture_image
*prevImage
=
2667 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2668 /* See if the prev level is defined and has an internal format which
2669 * matches the new internal format.
2672 prevImage
->Width
> 0 &&
2673 prevImage
->InternalFormat
== internalFormat
) {
2674 /* use the same format */
2675 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2676 return prevImage
->TexFormat
;
2680 /* If the application requested compression to an S3TC format but we don't
2681 * have the DTXn library, force a generic compressed format instead.
2683 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2684 const GLenum before
= internalFormat
;
2686 switch (internalFormat
) {
2687 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2688 if (!ctx
->Mesa_DXTn
)
2689 internalFormat
= GL_COMPRESSED_RGB
;
2691 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2692 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2693 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2694 if (!ctx
->Mesa_DXTn
)
2695 internalFormat
= GL_COMPRESSED_RGBA
;
2701 if (before
!= internalFormat
) {
2703 "DXT compression requested (%s), "
2704 "but libtxc_dxtn library not installed. Using %s "
2706 _mesa_lookup_enum_by_nr(before
),
2707 _mesa_lookup_enum_by_nr(internalFormat
));
2711 /* choose format from scratch */
2712 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2714 ASSERT(f
!= MESA_FORMAT_NONE
);
2719 * Adjust pixel unpack params and image dimensions to strip off the
2720 * one-pixel texture border.
2722 * Gallium and intel don't support texture borders. They've seldem been used
2723 * and seldom been implemented correctly anyway.
2725 * \param unpackNew returns the new pixel unpack parameters
2728 strip_texture_border(GLenum target
,
2729 GLint
*width
, GLint
*height
, GLint
*depth
,
2730 const struct gl_pixelstore_attrib
*unpack
,
2731 struct gl_pixelstore_attrib
*unpackNew
)
2737 *unpackNew
= *unpack
;
2739 if (unpackNew
->RowLength
== 0)
2740 unpackNew
->RowLength
= *width
;
2742 if (unpackNew
->ImageHeight
== 0)
2743 unpackNew
->ImageHeight
= *height
;
2745 assert(*width
>= 3);
2746 unpackNew
->SkipPixels
++; /* skip the border */
2747 *width
= *width
- 2; /* reduce the width by two border pixels */
2749 /* The min height of a texture with a border is 3 */
2750 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2751 unpackNew
->SkipRows
++; /* skip the border */
2752 *height
= *height
- 2; /* reduce the height by two border pixels */
2755 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
&& target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2756 unpackNew
->SkipImages
++; /* skip the border */
2757 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2763 * Common code to implement all the glTexImage1D/2D/3D functions
2764 * as well as glCompressedTexImage1D/2D/3D.
2765 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2766 * \param format the user's image format (only used if !compressed)
2767 * \param type the user's image type (only used if !compressed)
2768 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2771 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2772 GLenum target
, GLint level
, GLint internalFormat
,
2773 GLsizei width
, GLsizei height
, GLsizei depth
,
2774 GLint border
, GLenum format
, GLenum type
,
2775 GLsizei imageSize
, const GLvoid
*pixels
)
2777 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2778 struct gl_pixelstore_attrib unpack_no_border
;
2779 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2780 struct gl_texture_object
*texObj
;
2781 gl_format texFormat
;
2782 GLboolean dimensionsOK
, sizeOK
;
2784 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2786 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2789 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2791 _mesa_lookup_enum_by_nr(target
), level
,
2792 _mesa_lookup_enum_by_nr(internalFormat
),
2793 width
, height
, depth
, border
, pixels
);
2796 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2798 _mesa_lookup_enum_by_nr(target
), level
,
2799 _mesa_lookup_enum_by_nr(internalFormat
),
2800 width
, height
, depth
, border
,
2801 _mesa_lookup_enum_by_nr(format
),
2802 _mesa_lookup_enum_by_nr(type
), pixels
);
2805 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2807 /* target error checking */
2808 if (!legal_teximage_target(ctx
, dims
, target
)) {
2809 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2810 func
, dims
, _mesa_lookup_enum_by_nr(target
));
2814 /* general error checking */
2816 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
2818 width
, height
, depth
,
2823 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2824 format
, type
, width
, height
, depth
, border
))
2828 /* Here we convert a cpal compressed image into a regular glTexImage2D
2829 * call by decompressing the texture. If we really want to support cpal
2830 * textures in any driver this would have to be changed.
2832 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
2833 switch (internalFormat
) {
2834 case GL_PALETTE4_RGB8_OES
:
2835 case GL_PALETTE4_RGBA8_OES
:
2836 case GL_PALETTE4_R5_G6_B5_OES
:
2837 case GL_PALETTE4_RGBA4_OES
:
2838 case GL_PALETTE4_RGB5_A1_OES
:
2839 case GL_PALETTE8_RGB8_OES
:
2840 case GL_PALETTE8_RGBA8_OES
:
2841 case GL_PALETTE8_R5_G6_B5_OES
:
2842 case GL_PALETTE8_RGBA4_OES
:
2843 case GL_PALETTE8_RGB5_A1_OES
:
2844 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
2845 width
, height
, imageSize
, pixels
);
2850 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2853 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2854 internalFormat
, format
, type
);
2855 assert(texFormat
!= MESA_FORMAT_NONE
);
2857 /* check that width, height, depth are legal for the mipmap level */
2858 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
2859 height
, depth
, border
);
2861 /* check that the texture won't take too much memory, etc */
2862 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
2864 width
, height
, depth
, border
);
2866 if (_mesa_is_proxy_texture(target
)) {
2867 /* Proxy texture: just clear or set state depending on error checking */
2868 struct gl_texture_image
*texImage
=
2869 get_proxy_tex_image(ctx
, target
, level
);
2872 return; /* GL_OUT_OF_MEMORY already recorded */
2874 if (dimensionsOK
&& sizeOK
) {
2875 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
2876 border
, internalFormat
, texFormat
);
2879 clear_teximage_fields(texImage
);
2883 /* non-proxy target */
2884 const GLuint face
= _mesa_tex_target_to_face(target
);
2885 struct gl_texture_image
*texImage
;
2887 if (!dimensionsOK
) {
2888 _mesa_error(ctx
, GL_INVALID_VALUE
,
2889 "glTexImage%uD(invalid width or height or depth)",
2895 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
2896 "glTexImage%uD(image too large)", dims
);
2900 /* Allow a hardware driver to just strip out the border, to provide
2901 * reliable but slightly incorrect hardware rendering instead of
2902 * rarely-tested software fallback rendering.
2904 if (border
&& ctx
->Const
.StripTextureBorder
) {
2905 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
2908 unpack
= &unpack_no_border
;
2911 if (ctx
->NewState
& _NEW_PIXEL
)
2912 _mesa_update_state(ctx
);
2914 _mesa_lock_texture(ctx
, texObj
);
2916 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2919 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
2922 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2924 _mesa_init_teximage_fields(ctx
, texImage
,
2925 width
, height
, depth
,
2926 border
, internalFormat
, texFormat
);
2928 /* Give the texture to the driver. <pixels> may be null. */
2929 if (width
> 0 && height
> 0 && depth
> 0) {
2931 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
2935 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
2936 type
, pixels
, unpack
);
2940 check_gen_mipmap(ctx
, target
, texObj
, level
);
2942 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2944 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2947 _mesa_unlock_texture(ctx
, texObj
);
2954 * Called from the API. Note that width includes the border.
2957 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2958 GLsizei width
, GLint border
, GLenum format
,
2959 GLenum type
, const GLvoid
*pixels
)
2961 GET_CURRENT_CONTEXT(ctx
);
2962 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
2963 border
, format
, type
, 0, pixels
);
2968 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2969 GLsizei width
, GLsizei height
, GLint border
,
2970 GLenum format
, GLenum type
,
2971 const GLvoid
*pixels
)
2973 GET_CURRENT_CONTEXT(ctx
);
2974 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
2975 border
, format
, type
, 0, pixels
);
2980 * Called by the API or display list executor.
2981 * Note that width and height include the border.
2984 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2985 GLsizei width
, GLsizei height
, GLsizei depth
,
2986 GLint border
, GLenum format
, GLenum type
,
2987 const GLvoid
*pixels
)
2989 GET_CURRENT_CONTEXT(ctx
);
2990 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
2991 width
, height
, depth
,
2992 border
, format
, type
, 0, pixels
);
2997 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2998 GLsizei width
, GLsizei height
, GLsizei depth
,
2999 GLint border
, GLenum format
, GLenum type
,
3000 const GLvoid
*pixels
)
3002 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3003 depth
, border
, format
, type
, pixels
);
3008 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3010 struct gl_texture_object
*texObj
;
3011 struct gl_texture_image
*texImage
;
3013 GET_CURRENT_CONTEXT(ctx
);
3014 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3018 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3020 case GL_TEXTURE_EXTERNAL_OES
:
3021 valid_target
= ctx
->Extensions
.OES_EGL_image_external
;
3024 valid_target
= false;
3028 if (!valid_target
) {
3029 _mesa_error(ctx
, GL_INVALID_ENUM
,
3030 "glEGLImageTargetTexture2D(target=%d)", target
);
3034 if (ctx
->NewState
& _NEW_PIXEL
)
3035 _mesa_update_state(ctx
);
3037 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3038 _mesa_lock_texture(ctx
, texObj
);
3040 if (texObj
->Immutable
) {
3041 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3042 "glEGLImageTargetTexture2D(texture is immutable)");
3043 _mesa_unlock_texture(ctx
, texObj
);
3047 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3049 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3051 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3053 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3054 texObj
, texImage
, image
);
3056 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3058 _mesa_unlock_texture(ctx
, texObj
);
3065 * Implement all the glTexSubImage1/2/3D() functions.
3068 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3069 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3070 GLsizei width
, GLsizei height
, GLsizei depth
,
3071 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3073 struct gl_texture_object
*texObj
;
3074 struct gl_texture_image
*texImage
;
3076 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3078 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3079 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3081 _mesa_lookup_enum_by_nr(target
), level
,
3082 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3083 _mesa_lookup_enum_by_nr(format
),
3084 _mesa_lookup_enum_by_nr(type
), pixels
);
3086 /* check target (proxies not allowed) */
3087 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3088 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3089 dims
, _mesa_lookup_enum_by_nr(target
));
3093 if (ctx
->NewState
& _NEW_PIXEL
)
3094 _mesa_update_state(ctx
);
3096 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3097 xoffset
, yoffset
, zoffset
,
3098 width
, height
, depth
, format
, type
)) {
3099 return; /* error was detected */
3102 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3104 _mesa_lock_texture(ctx
, texObj
);
3106 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3108 if (width
> 0 && height
> 0 && depth
> 0) {
3109 /* If we have a border, offset=-1 is legal. Bias by border width. */
3112 if (target
!= GL_TEXTURE_2D_ARRAY
)
3113 zoffset
+= texImage
->Border
;
3116 if (target
!= GL_TEXTURE_1D_ARRAY
)
3117 yoffset
+= texImage
->Border
;
3120 xoffset
+= texImage
->Border
;
3123 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3124 xoffset
, yoffset
, zoffset
,
3125 width
, height
, depth
,
3126 format
, type
, pixels
, &ctx
->Unpack
);
3128 check_gen_mipmap(ctx
, target
, texObj
, level
);
3130 ctx
->NewState
|= _NEW_TEXTURE
;
3133 _mesa_unlock_texture(ctx
, texObj
);
3138 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3139 GLint xoffset
, GLsizei width
,
3140 GLenum format
, GLenum type
,
3141 const GLvoid
*pixels
)
3143 GET_CURRENT_CONTEXT(ctx
);
3144 texsubimage(ctx
, 1, target
, level
,
3147 format
, type
, pixels
);
3152 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3153 GLint xoffset
, GLint yoffset
,
3154 GLsizei width
, GLsizei height
,
3155 GLenum format
, GLenum type
,
3156 const GLvoid
*pixels
)
3158 GET_CURRENT_CONTEXT(ctx
);
3159 texsubimage(ctx
, 2, target
, level
,
3160 xoffset
, yoffset
, 0,
3162 format
, type
, pixels
);
3168 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3169 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3170 GLsizei width
, GLsizei height
, GLsizei depth
,
3171 GLenum format
, GLenum type
,
3172 const GLvoid
*pixels
)
3174 GET_CURRENT_CONTEXT(ctx
);
3175 texsubimage(ctx
, 3, target
, level
,
3176 xoffset
, yoffset
, zoffset
,
3177 width
, height
, depth
,
3178 format
, type
, pixels
);
3184 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3185 * from. This depends on whether the texture contains color or depth values.
3187 static struct gl_renderbuffer
*
3188 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3190 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3191 /* reading from depth/stencil buffer */
3192 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3195 /* copying from color buffer */
3196 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3203 * Implement the glCopyTexImage1/2D() functions.
3206 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3207 GLenum target
, GLint level
, GLenum internalFormat
,
3208 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3210 struct gl_texture_object
*texObj
;
3211 struct gl_texture_image
*texImage
;
3212 const GLuint face
= _mesa_tex_target_to_face(target
);
3213 gl_format texFormat
;
3215 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3217 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3218 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3220 _mesa_lookup_enum_by_nr(target
), level
,
3221 _mesa_lookup_enum_by_nr(internalFormat
),
3222 x
, y
, width
, height
, border
);
3224 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3225 _mesa_update_state(ctx
);
3227 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3228 width
, height
, border
))
3231 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3233 _mesa_error(ctx
, GL_INVALID_VALUE
,
3234 "glCopyTexImage%uD(invalid width or height)", dims
);
3238 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3241 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3242 internalFormat
, GL_NONE
, GL_NONE
);
3243 assert(texFormat
!= MESA_FORMAT_NONE
);
3245 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3247 width
, height
, 1, border
)) {
3248 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3249 "glCopyTexImage%uD(image too large)", dims
);
3253 if (border
&& ctx
->Const
.StripTextureBorder
) {
3255 width
-= border
* 2;
3258 height
-= border
* 2;
3263 _mesa_lock_texture(ctx
, texObj
);
3265 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3268 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3271 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3273 /* Free old texture image */
3274 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3276 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3277 border
, internalFormat
, texFormat
);
3279 /* Allocate texture memory (no pixel data yet) */
3280 ctx
->Driver
.TexImage(ctx
, dims
, texImage
,
3282 NULL
, &ctx
->Unpack
);
3284 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3286 struct gl_renderbuffer
*srcRb
=
3287 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3289 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
3290 srcRb
, srcX
, srcY
, width
, height
);
3293 check_gen_mipmap(ctx
, target
, texObj
, level
);
3295 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3297 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3300 _mesa_unlock_texture(ctx
, texObj
);
3306 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3307 GLenum internalFormat
,
3309 GLsizei width
, GLint border
)
3311 GET_CURRENT_CONTEXT(ctx
);
3312 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3318 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3319 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3322 GET_CURRENT_CONTEXT(ctx
);
3323 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3324 x
, y
, width
, height
, border
);
3330 * Implementation for glCopyTexSubImage1/2/3D() functions.
3333 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3334 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3335 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3337 struct gl_texture_object
*texObj
;
3338 struct gl_texture_image
*texImage
;
3340 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3342 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3343 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3345 _mesa_lookup_enum_by_nr(target
),
3346 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3348 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3349 _mesa_update_state(ctx
);
3351 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3352 xoffset
, yoffset
, zoffset
, width
, height
)) {
3356 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3358 _mesa_lock_texture(ctx
, texObj
);
3360 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3362 /* If we have a border, offset=-1 is legal. Bias by border width. */
3365 if (target
!= GL_TEXTURE_2D_ARRAY
)
3366 zoffset
+= texImage
->Border
;
3369 if (target
!= GL_TEXTURE_1D_ARRAY
)
3370 yoffset
+= texImage
->Border
;
3373 xoffset
+= texImage
->Border
;
3376 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3378 struct gl_renderbuffer
*srcRb
=
3379 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3381 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3382 xoffset
, yoffset
, zoffset
,
3383 srcRb
, x
, y
, width
, height
);
3385 check_gen_mipmap(ctx
, target
, texObj
, level
);
3387 ctx
->NewState
|= _NEW_TEXTURE
;
3390 _mesa_unlock_texture(ctx
, texObj
);
3395 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3396 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3398 GET_CURRENT_CONTEXT(ctx
);
3399 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3405 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3406 GLint xoffset
, GLint yoffset
,
3407 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3409 GET_CURRENT_CONTEXT(ctx
);
3410 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3417 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3418 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3419 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3421 GET_CURRENT_CONTEXT(ctx
);
3422 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3423 x
, y
, width
, height
);
3429 /**********************************************************************/
3430 /****** Compressed Textures ******/
3431 /**********************************************************************/
3435 * Error checking for glCompressedTexSubImage[123]D().
3436 * \return error code or GL_NO_ERROR.
3439 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3440 GLenum target
, GLint level
,
3441 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3442 GLsizei width
, GLsizei height
, GLsizei depth
,
3443 GLenum format
, GLsizei imageSize
)
3445 struct gl_texture_object
*texObj
;
3446 struct gl_texture_image
*texImage
;
3453 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3454 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3455 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3456 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3457 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3458 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3462 targetOK
= GL_FALSE
;
3466 assert(dims
== 1 || dims
== 3);
3467 /* no 1D or 3D compressed textures at this time */
3468 targetOK
= GL_FALSE
;
3472 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3477 /* this will catch any invalid compressed format token */
3478 if (!_mesa_is_compressed_format(ctx
, format
)) {
3479 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3484 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3485 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3490 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3491 if (expectedSize
!= imageSize
) {
3492 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3497 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3499 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3500 "glCompressedTexSubImage%uD()", dims
);
3504 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3506 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3507 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3511 if ((GLint
) format
!= texImage
->InternalFormat
) {
3512 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3513 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3517 if (compressedteximage_only_format(ctx
, format
)) {
3518 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3519 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3524 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3525 texImage
, xoffset
, yoffset
, zoffset
,
3526 width
, height
, depth
)) {
3535 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3536 GLenum internalFormat
, GLsizei width
,
3537 GLint border
, GLsizei imageSize
,
3540 GET_CURRENT_CONTEXT(ctx
);
3541 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3542 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3547 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3548 GLenum internalFormat
, GLsizei width
,
3549 GLsizei height
, GLint border
, GLsizei imageSize
,
3552 GET_CURRENT_CONTEXT(ctx
);
3553 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3554 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3559 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3560 GLenum internalFormat
, GLsizei width
,
3561 GLsizei height
, GLsizei depth
, GLint border
,
3562 GLsizei imageSize
, const GLvoid
*data
)
3564 GET_CURRENT_CONTEXT(ctx
);
3565 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3566 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3571 * Common helper for glCompressedTexSubImage1/2/3D().
3574 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3575 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3576 GLsizei width
, GLsizei height
, GLsizei depth
,
3577 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3579 struct gl_texture_object
*texObj
;
3580 struct gl_texture_image
*texImage
;
3581 GET_CURRENT_CONTEXT(ctx
);
3582 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3584 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3585 xoffset
, yoffset
, zoffset
,
3586 width
, height
, depth
,
3587 format
, imageSize
)) {
3591 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3593 _mesa_lock_texture(ctx
, texObj
);
3595 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3598 if (width
> 0 && height
> 0 && depth
> 0) {
3599 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3600 xoffset
, yoffset
, zoffset
,
3601 width
, height
, depth
,
3602 format
, imageSize
, data
);
3604 check_gen_mipmap(ctx
, target
, texObj
, level
);
3606 ctx
->NewState
|= _NEW_TEXTURE
;
3609 _mesa_unlock_texture(ctx
, texObj
);
3614 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3615 GLsizei width
, GLenum format
,
3616 GLsizei imageSize
, const GLvoid
*data
)
3618 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3619 format
, imageSize
, data
);
3624 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3625 GLint yoffset
, GLsizei width
, GLsizei height
,
3626 GLenum format
, GLsizei imageSize
,
3629 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3630 width
, height
, 1, format
, imageSize
, data
);
3635 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3636 GLint yoffset
, GLint zoffset
, GLsizei width
,
3637 GLsizei height
, GLsizei depth
, GLenum format
,
3638 GLsizei imageSize
, const GLvoid
*data
)
3640 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3641 width
, height
, depth
, format
, imageSize
, data
);
3645 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3647 switch (internalFormat
) {
3649 return MESA_FORMAT_A8
;
3651 return MESA_FORMAT_A16
;
3652 case GL_ALPHA16F_ARB
:
3653 return MESA_FORMAT_ALPHA_FLOAT16
;
3654 case GL_ALPHA32F_ARB
:
3655 return MESA_FORMAT_ALPHA_FLOAT32
;
3656 case GL_ALPHA8I_EXT
:
3657 return MESA_FORMAT_ALPHA_INT8
;
3658 case GL_ALPHA16I_EXT
:
3659 return MESA_FORMAT_ALPHA_INT16
;
3660 case GL_ALPHA32I_EXT
:
3661 return MESA_FORMAT_ALPHA_INT32
;
3662 case GL_ALPHA8UI_EXT
:
3663 return MESA_FORMAT_ALPHA_UINT8
;
3664 case GL_ALPHA16UI_EXT
:
3665 return MESA_FORMAT_ALPHA_UINT16
;
3666 case GL_ALPHA32UI_EXT
:
3667 return MESA_FORMAT_ALPHA_UINT32
;
3669 return MESA_FORMAT_L8
;
3670 case GL_LUMINANCE16
:
3671 return MESA_FORMAT_L16
;
3672 case GL_LUMINANCE16F_ARB
:
3673 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3674 case GL_LUMINANCE32F_ARB
:
3675 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3676 case GL_LUMINANCE8I_EXT
:
3677 return MESA_FORMAT_LUMINANCE_INT8
;
3678 case GL_LUMINANCE16I_EXT
:
3679 return MESA_FORMAT_LUMINANCE_INT16
;
3680 case GL_LUMINANCE32I_EXT
:
3681 return MESA_FORMAT_LUMINANCE_INT32
;
3682 case GL_LUMINANCE8UI_EXT
:
3683 return MESA_FORMAT_LUMINANCE_UINT8
;
3684 case GL_LUMINANCE16UI_EXT
:
3685 return MESA_FORMAT_LUMINANCE_UINT16
;
3686 case GL_LUMINANCE32UI_EXT
:
3687 return MESA_FORMAT_LUMINANCE_UINT32
;
3688 case GL_LUMINANCE8_ALPHA8
:
3689 return MESA_FORMAT_AL88
;
3690 case GL_LUMINANCE16_ALPHA16
:
3691 return MESA_FORMAT_AL1616
;
3692 case GL_LUMINANCE_ALPHA16F_ARB
:
3693 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3694 case GL_LUMINANCE_ALPHA32F_ARB
:
3695 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3696 case GL_LUMINANCE_ALPHA8I_EXT
:
3697 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3698 case GL_LUMINANCE_ALPHA16I_EXT
:
3699 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3700 case GL_LUMINANCE_ALPHA32I_EXT
:
3701 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3702 case GL_LUMINANCE_ALPHA8UI_EXT
:
3703 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3704 case GL_LUMINANCE_ALPHA16UI_EXT
:
3705 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3706 case GL_LUMINANCE_ALPHA32UI_EXT
:
3707 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3709 return MESA_FORMAT_I8
;
3710 case GL_INTENSITY16
:
3711 return MESA_FORMAT_I16
;
3712 case GL_INTENSITY16F_ARB
:
3713 return MESA_FORMAT_INTENSITY_FLOAT16
;
3714 case GL_INTENSITY32F_ARB
:
3715 return MESA_FORMAT_INTENSITY_FLOAT32
;
3716 case GL_INTENSITY8I_EXT
:
3717 return MESA_FORMAT_INTENSITY_INT8
;
3718 case GL_INTENSITY16I_EXT
:
3719 return MESA_FORMAT_INTENSITY_INT16
;
3720 case GL_INTENSITY32I_EXT
:
3721 return MESA_FORMAT_INTENSITY_INT32
;
3722 case GL_INTENSITY8UI_EXT
:
3723 return MESA_FORMAT_INTENSITY_UINT8
;
3724 case GL_INTENSITY16UI_EXT
:
3725 return MESA_FORMAT_INTENSITY_UINT16
;
3726 case GL_INTENSITY32UI_EXT
:
3727 return MESA_FORMAT_INTENSITY_UINT32
;
3729 return MESA_FORMAT_RGBA8888_REV
;
3731 return MESA_FORMAT_RGBA_16
;
3732 case GL_RGBA16F_ARB
:
3733 return MESA_FORMAT_RGBA_FLOAT16
;
3734 case GL_RGBA32F_ARB
:
3735 return MESA_FORMAT_RGBA_FLOAT32
;
3737 return MESA_FORMAT_RGBA_INT8
;
3738 case GL_RGBA16I_EXT
:
3739 return MESA_FORMAT_RGBA_INT16
;
3740 case GL_RGBA32I_EXT
:
3741 return MESA_FORMAT_RGBA_INT32
;
3742 case GL_RGBA8UI_EXT
:
3743 return MESA_FORMAT_RGBA_UINT8
;
3744 case GL_RGBA16UI_EXT
:
3745 return MESA_FORMAT_RGBA_UINT16
;
3746 case GL_RGBA32UI_EXT
:
3747 return MESA_FORMAT_RGBA_UINT32
;
3750 return MESA_FORMAT_GR88
;
3752 return MESA_FORMAT_RG1616
;
3754 return MESA_FORMAT_RG_FLOAT16
;
3756 return MESA_FORMAT_RG_FLOAT32
;
3758 return MESA_FORMAT_RG_INT8
;
3760 return MESA_FORMAT_RG_INT16
;
3762 return MESA_FORMAT_RG_INT32
;
3764 return MESA_FORMAT_RG_UINT8
;
3766 return MESA_FORMAT_RG_UINT16
;
3768 return MESA_FORMAT_RG_UINT32
;
3771 return MESA_FORMAT_R8
;
3773 return MESA_FORMAT_R16
;
3775 return MESA_FORMAT_R_FLOAT16
;
3777 return MESA_FORMAT_R_FLOAT32
;
3779 return MESA_FORMAT_R_INT8
;
3781 return MESA_FORMAT_R_INT16
;
3783 return MESA_FORMAT_R_INT32
;
3785 return MESA_FORMAT_R_UINT8
;
3787 return MESA_FORMAT_R_UINT16
;
3789 return MESA_FORMAT_R_UINT32
;
3792 return MESA_FORMAT_NONE
;
3797 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3799 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
3802 if (format
== MESA_FORMAT_NONE
)
3803 return MESA_FORMAT_NONE
;
3805 datatype
= _mesa_get_format_datatype(format
);
3806 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3807 return MESA_FORMAT_NONE
;
3809 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3810 return MESA_FORMAT_NONE
;
3812 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
3813 * any mention of R/RG formats, but they appear in the GL 3.1 core
3816 if (ctx
->Version
<= 30) {
3817 GLenum base_format
= _mesa_get_format_base_format(format
);
3819 if (base_format
== GL_R
|| base_format
== GL_RG
)
3820 return MESA_FORMAT_NONE
;
3826 /** GL_ARB_texture_buffer_object */
3828 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3830 struct gl_texture_object
*texObj
;
3831 struct gl_buffer_object
*bufObj
;
3834 GET_CURRENT_CONTEXT(ctx
);
3835 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3837 if (!(ctx
->Extensions
.ARB_texture_buffer_object
3838 && _mesa_is_desktop_gl(ctx
))) {
3839 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3843 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3844 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3848 format
= validate_texbuffer_format(ctx
, internalFormat
);
3849 if (format
== MESA_FORMAT_NONE
) {
3850 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3855 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3856 if (buffer
&& !bufObj
) {
3857 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3861 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3863 _mesa_lock_texture(ctx
, texObj
);
3865 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3866 texObj
->BufferObjectFormat
= internalFormat
;
3867 texObj
->_BufferObjectFormat
= format
;
3869 _mesa_unlock_texture(ctx
, texObj
);