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"
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
) {
93 case GL_LUMINANCE_ALPHA
:
94 case GL_LUMINANCE4_ALPHA4
:
95 case GL_LUMINANCE6_ALPHA2
:
96 case GL_LUMINANCE8_ALPHA8
:
97 case GL_LUMINANCE12_ALPHA4
:
98 case GL_LUMINANCE12_ALPHA12
:
99 case GL_LUMINANCE16_ALPHA16
:
100 return GL_LUMINANCE_ALPHA
;
131 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
133 if (_mesa_is_gles(ctx
)) {
134 switch (internalFormat
) {
142 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
143 switch (internalFormat
) {
151 if (ctx
->Extensions
.ARB_depth_texture
) {
152 switch (internalFormat
) {
153 case GL_DEPTH_COMPONENT
:
154 case GL_DEPTH_COMPONENT16
:
155 case GL_DEPTH_COMPONENT24
:
156 case GL_DEPTH_COMPONENT32
:
157 return GL_DEPTH_COMPONENT
;
163 switch (internalFormat
) {
164 case GL_COMPRESSED_ALPHA
:
166 case GL_COMPRESSED_LUMINANCE
:
168 case GL_COMPRESSED_LUMINANCE_ALPHA
:
169 return GL_LUMINANCE_ALPHA
;
170 case GL_COMPRESSED_INTENSITY
:
172 case GL_COMPRESSED_RGB
:
174 case GL_COMPRESSED_RGBA
:
180 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
181 switch (internalFormat
) {
182 case GL_COMPRESSED_RGB_FXT1_3DFX
:
184 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
191 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
192 switch (internalFormat
) {
193 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
195 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
196 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
197 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
204 if (ctx
->Extensions
.S3_s3tc
) {
205 switch (internalFormat
) {
217 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
218 if (internalFormat
== GL_YCBCR_MESA
)
219 return GL_YCBCR_MESA
;
222 if (ctx
->Extensions
.ARB_texture_float
) {
223 switch (internalFormat
) {
224 case GL_ALPHA16F_ARB
:
225 case GL_ALPHA32F_ARB
:
233 case GL_INTENSITY16F_ARB
:
234 case GL_INTENSITY32F_ARB
:
236 case GL_LUMINANCE16F_ARB
:
237 case GL_LUMINANCE32F_ARB
:
239 case GL_LUMINANCE_ALPHA16F_ARB
:
240 case GL_LUMINANCE_ALPHA32F_ARB
:
241 return GL_LUMINANCE_ALPHA
;
247 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
248 switch (internalFormat
) {
257 if (ctx
->Extensions
.EXT_texture_snorm
) {
258 switch (internalFormat
) {
273 case GL_RGBA16_SNORM
:
276 case GL_ALPHA8_SNORM
:
277 case GL_ALPHA16_SNORM
:
279 case GL_LUMINANCE_SNORM
:
280 case GL_LUMINANCE8_SNORM
:
281 case GL_LUMINANCE16_SNORM
:
283 case GL_LUMINANCE_ALPHA_SNORM
:
284 case GL_LUMINANCE8_ALPHA8_SNORM
:
285 case GL_LUMINANCE16_ALPHA16_SNORM
:
286 return GL_LUMINANCE_ALPHA
;
287 case GL_INTENSITY_SNORM
:
288 case GL_INTENSITY8_SNORM
:
289 case GL_INTENSITY16_SNORM
:
296 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
297 switch (internalFormat
) {
298 case GL_DEPTH_STENCIL_EXT
:
299 case GL_DEPTH24_STENCIL8_EXT
:
300 return GL_DEPTH_STENCIL_EXT
;
306 #if FEATURE_EXT_texture_sRGB
307 if (ctx
->Extensions
.EXT_texture_sRGB
) {
308 switch (internalFormat
) {
311 case GL_COMPRESSED_SRGB_EXT
:
312 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
314 case GL_SRGB_ALPHA_EXT
:
315 case GL_SRGB8_ALPHA8_EXT
:
316 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
317 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
318 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
319 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
321 case GL_SLUMINANCE_ALPHA_EXT
:
322 case GL_SLUMINANCE8_ALPHA8_EXT
:
323 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
324 return GL_LUMINANCE_ALPHA
;
325 case GL_SLUMINANCE_EXT
:
326 case GL_SLUMINANCE8_EXT
:
327 case GL_COMPRESSED_SLUMINANCE_EXT
:
333 #endif /* FEATURE_EXT_texture_sRGB */
335 if (ctx
->Version
>= 30 ||
336 ctx
->Extensions
.EXT_texture_integer
) {
337 switch (internalFormat
) {
339 case GL_RGBA16UI_EXT
:
340 case GL_RGBA32UI_EXT
:
356 if (ctx
->Extensions
.EXT_texture_integer
) {
357 switch (internalFormat
) {
358 case GL_ALPHA8UI_EXT
:
359 case GL_ALPHA16UI_EXT
:
360 case GL_ALPHA32UI_EXT
:
362 case GL_ALPHA16I_EXT
:
363 case GL_ALPHA32I_EXT
:
365 case GL_INTENSITY8UI_EXT
:
366 case GL_INTENSITY16UI_EXT
:
367 case GL_INTENSITY32UI_EXT
:
368 case GL_INTENSITY8I_EXT
:
369 case GL_INTENSITY16I_EXT
:
370 case GL_INTENSITY32I_EXT
:
372 case GL_LUMINANCE8UI_EXT
:
373 case GL_LUMINANCE16UI_EXT
:
374 case GL_LUMINANCE32UI_EXT
:
375 case GL_LUMINANCE8I_EXT
:
376 case GL_LUMINANCE16I_EXT
:
377 case GL_LUMINANCE32I_EXT
:
379 case GL_LUMINANCE_ALPHA8UI_EXT
:
380 case GL_LUMINANCE_ALPHA16UI_EXT
:
381 case GL_LUMINANCE_ALPHA32UI_EXT
:
382 case GL_LUMINANCE_ALPHA8I_EXT
:
383 case GL_LUMINANCE_ALPHA16I_EXT
:
384 case GL_LUMINANCE_ALPHA32I_EXT
:
385 return GL_LUMINANCE_ALPHA
;
391 if (ctx
->Extensions
.ARB_texture_rg
) {
392 switch (internalFormat
) {
394 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
396 if (!ctx
->Extensions
.ARB_half_float_pixel
)
400 if (!ctx
->Extensions
.ARB_texture_float
)
409 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
415 case GL_COMPRESSED_RED
:
419 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
421 if (!ctx
->Extensions
.ARB_half_float_pixel
)
425 if (!ctx
->Extensions
.ARB_texture_float
)
434 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
440 case GL_COMPRESSED_RG
:
447 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
448 switch (internalFormat
) {
456 if (ctx
->Extensions
.EXT_packed_float
) {
457 switch (internalFormat
) {
458 case GL_R11F_G11F_B10F_EXT
:
465 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
466 switch (internalFormat
) {
467 case GL_DEPTH_COMPONENT32F
:
468 return GL_DEPTH_COMPONENT
;
469 case GL_DEPTH32F_STENCIL8
:
470 return GL_DEPTH_STENCIL
;
476 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
477 switch (internalFormat
) {
478 case GL_COMPRESSED_RED_RGTC1
:
479 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
481 case GL_COMPRESSED_RG_RGTC2
:
482 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
489 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
490 switch (internalFormat
) {
491 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
492 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
494 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
495 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
496 return GL_LUMINANCE_ALPHA
;
502 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
503 switch (internalFormat
) {
504 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
505 return GL_LUMINANCE_ALPHA
;
511 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
512 switch (internalFormat
) {
513 case GL_ETC1_RGB8_OES
:
520 if (ctx
->API
== API_OPENGLES
) {
521 switch (internalFormat
) {
522 case GL_PALETTE4_RGB8_OES
:
523 case GL_PALETTE4_R5_G6_B5_OES
:
524 case GL_PALETTE8_RGB8_OES
:
525 case GL_PALETTE8_R5_G6_B5_OES
:
527 case GL_PALETTE4_RGBA8_OES
:
528 case GL_PALETTE8_RGB5_A1_OES
:
529 case GL_PALETTE4_RGBA4_OES
:
530 case GL_PALETTE4_RGB5_A1_OES
:
531 case GL_PALETTE8_RGBA8_OES
:
532 case GL_PALETTE8_RGBA4_OES
:
539 return -1; /* error */
544 * Is the given texture format a generic compressed format?
547 is_generic_compressed_format(GLenum format
)
550 case GL_COMPRESSED_RED
:
551 case GL_COMPRESSED_RG
:
552 case GL_COMPRESSED_RGB
:
553 case GL_COMPRESSED_RGBA
:
554 case GL_COMPRESSED_ALPHA
:
555 case GL_COMPRESSED_LUMINANCE
:
556 case GL_COMPRESSED_LUMINANCE_ALPHA
:
557 case GL_COMPRESSED_INTENSITY
:
558 case GL_COMPRESSED_SRGB
:
559 case GL_COMPRESSED_SRGB_ALPHA
:
560 case GL_COMPRESSED_SLUMINANCE
:
561 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
570 * For cube map faces, return a face index in [0,5].
571 * For other targets return 0;
574 _mesa_tex_target_to_face(GLenum target
)
576 if (_mesa_is_cube_face(target
))
577 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
585 * Install gl_texture_image in a gl_texture_object according to the target
586 * and level parameters.
588 * \param tObj texture object.
589 * \param target texture target.
590 * \param level image level.
591 * \param texImage texture image.
594 set_tex_image(struct gl_texture_object
*tObj
,
595 GLenum target
, GLint level
,
596 struct gl_texture_image
*texImage
)
598 const GLuint face
= _mesa_tex_target_to_face(target
);
602 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
605 tObj
->Image
[face
][level
] = texImage
;
607 /* Set the 'back' pointer */
608 texImage
->TexObject
= tObj
;
609 texImage
->Level
= level
;
610 texImage
->Face
= face
;
615 * Allocate a texture image structure.
617 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
620 * \return a pointer to gl_texture_image struct with all fields initialized to
623 struct gl_texture_image
*
624 _mesa_new_texture_image( struct gl_context
*ctx
)
627 return CALLOC_STRUCT(gl_texture_image
);
632 * Free a gl_texture_image and associated data.
633 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
635 * \param texImage texture image.
637 * Free the texture image structure and the associated image data.
640 _mesa_delete_texture_image(struct gl_context
*ctx
,
641 struct gl_texture_image
*texImage
)
643 /* Free texImage->Data and/or any other driver-specific texture
646 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
647 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
653 * Test if a target is a proxy target.
655 * \param target texture target.
657 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
660 _mesa_is_proxy_texture(GLenum target
)
663 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
664 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
666 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
668 return (target
== GL_PROXY_TEXTURE_1D
||
669 target
== GL_PROXY_TEXTURE_2D
||
670 target
== GL_PROXY_TEXTURE_3D
||
671 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
672 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
673 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
674 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
679 * Return the proxy target which corresponds to the given texture target
682 get_proxy_target(GLenum target
)
686 case GL_PROXY_TEXTURE_1D
:
687 return GL_PROXY_TEXTURE_1D
;
689 case GL_PROXY_TEXTURE_2D
:
690 return GL_PROXY_TEXTURE_2D
;
692 case GL_PROXY_TEXTURE_3D
:
693 return GL_PROXY_TEXTURE_3D
;
694 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
695 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
696 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
697 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
698 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
699 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
700 case GL_TEXTURE_CUBE_MAP_ARB
:
701 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
702 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
703 case GL_TEXTURE_RECTANGLE_NV
:
704 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
705 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
706 case GL_TEXTURE_1D_ARRAY_EXT
:
707 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
708 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
709 case GL_TEXTURE_2D_ARRAY_EXT
:
710 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
711 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
713 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
720 * Get the texture object that corresponds to the target of the given
721 * texture unit. The target should have already been checked for validity.
723 * \param ctx GL context.
724 * \param texUnit texture unit.
725 * \param target texture target.
727 * \return pointer to the texture object on success, or NULL on failure.
729 struct gl_texture_object
*
730 _mesa_select_tex_object(struct gl_context
*ctx
,
731 const struct gl_texture_unit
*texUnit
,
734 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
735 ctx
->Extensions
.EXT_texture_array
);
739 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
740 case GL_PROXY_TEXTURE_1D
:
741 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
743 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
744 case GL_PROXY_TEXTURE_2D
:
745 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
747 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
748 case GL_PROXY_TEXTURE_3D
:
749 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
750 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
751 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
752 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
753 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
754 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
755 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
756 case GL_TEXTURE_CUBE_MAP_ARB
:
757 return ctx
->Extensions
.ARB_texture_cube_map
758 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
759 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
760 return ctx
->Extensions
.ARB_texture_cube_map
761 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
762 case GL_TEXTURE_RECTANGLE_NV
:
763 return ctx
->Extensions
.NV_texture_rectangle
764 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
765 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
766 return ctx
->Extensions
.NV_texture_rectangle
767 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
768 case GL_TEXTURE_1D_ARRAY_EXT
:
769 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
770 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
771 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
772 case GL_TEXTURE_2D_ARRAY_EXT
:
773 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
774 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
775 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
776 case GL_TEXTURE_BUFFER
:
777 return ctx
->Extensions
.ARB_texture_buffer_object
778 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
779 case GL_TEXTURE_EXTERNAL_OES
:
780 return ctx
->Extensions
.OES_EGL_image_external
781 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
783 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
790 * Return pointer to texture object for given target on current texture unit.
792 struct gl_texture_object
*
793 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
795 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
796 return _mesa_select_tex_object(ctx
, texUnit
, target
);
801 * Get a texture image pointer from a texture object, given a texture
802 * target and mipmap level. The target and level parameters should
803 * have already been error-checked.
805 * \param ctx GL context.
806 * \param texObj texture unit.
807 * \param target texture target.
808 * \param level image level.
810 * \return pointer to the texture image structure, or NULL on failure.
812 struct gl_texture_image
*
813 _mesa_select_tex_image(struct gl_context
*ctx
,
814 const struct gl_texture_object
*texObj
,
815 GLenum target
, GLint level
)
817 const GLuint face
= _mesa_tex_target_to_face(target
);
821 ASSERT(level
< MAX_TEXTURE_LEVELS
);
823 return texObj
->Image
[face
][level
];
828 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
829 * it and install it. Only return NULL if passed a bad parameter or run
832 struct gl_texture_image
*
833 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
834 GLenum target
, GLint level
)
836 struct gl_texture_image
*texImage
;
841 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
843 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
845 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
849 set_tex_image(texObj
, target
, level
, texImage
);
857 * Return pointer to the specified proxy texture image.
858 * Note that proxy textures are per-context, not per-texture unit.
859 * \return pointer to texture image or NULL if invalid target, invalid
860 * level, or out of memory.
862 struct gl_texture_image
*
863 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
865 struct gl_texture_image
*texImage
;
872 case GL_PROXY_TEXTURE_1D
:
873 if (level
>= ctx
->Const
.MaxTextureLevels
)
875 texIndex
= TEXTURE_1D_INDEX
;
877 case GL_PROXY_TEXTURE_2D
:
878 if (level
>= ctx
->Const
.MaxTextureLevels
)
880 texIndex
= TEXTURE_2D_INDEX
;
882 case GL_PROXY_TEXTURE_3D
:
883 if (level
>= ctx
->Const
.Max3DTextureLevels
)
885 texIndex
= TEXTURE_3D_INDEX
;
887 case GL_PROXY_TEXTURE_CUBE_MAP
:
888 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
890 texIndex
= TEXTURE_CUBE_INDEX
;
892 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
895 texIndex
= TEXTURE_RECT_INDEX
;
897 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
898 if (level
>= ctx
->Const
.MaxTextureLevels
)
900 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
902 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
903 if (level
>= ctx
->Const
.MaxTextureLevels
)
905 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
911 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
913 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
915 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
918 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
919 /* Set the 'back' pointer */
920 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
927 * Get the maximum number of allowed mipmap levels.
929 * \param ctx GL context.
930 * \param target texture target.
932 * \return the maximum number of allowed mipmap levels for the given
933 * texture target, or zero if passed a bad target.
938 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
942 case GL_PROXY_TEXTURE_1D
:
944 case GL_PROXY_TEXTURE_2D
:
945 return ctx
->Const
.MaxTextureLevels
;
947 case GL_PROXY_TEXTURE_3D
:
948 return ctx
->Const
.Max3DTextureLevels
;
949 case GL_TEXTURE_CUBE_MAP
:
950 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
951 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
952 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
953 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
954 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
955 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
956 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
957 return ctx
->Extensions
.ARB_texture_cube_map
958 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
959 case GL_TEXTURE_RECTANGLE_NV
:
960 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
961 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
962 case GL_TEXTURE_1D_ARRAY_EXT
:
963 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
964 case GL_TEXTURE_2D_ARRAY_EXT
:
965 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
966 return (ctx
->Extensions
.MESA_texture_array
||
967 ctx
->Extensions
.EXT_texture_array
)
968 ? ctx
->Const
.MaxTextureLevels
: 0;
969 case GL_TEXTURE_BUFFER
:
970 case GL_TEXTURE_EXTERNAL_OES
:
973 return 0; /* bad target */
979 * Return number of dimensions per mipmap level for the given texture target.
982 _mesa_get_texture_dimensions(GLenum target
)
986 case GL_PROXY_TEXTURE_1D
:
989 case GL_TEXTURE_RECTANGLE
:
990 case GL_TEXTURE_CUBE_MAP
:
991 case GL_PROXY_TEXTURE_2D
:
992 case GL_PROXY_TEXTURE_RECTANGLE
:
993 case GL_PROXY_TEXTURE_CUBE_MAP
:
994 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
995 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
996 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
997 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
998 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
999 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1000 case GL_TEXTURE_1D_ARRAY
:
1001 case GL_PROXY_TEXTURE_1D_ARRAY
:
1002 case GL_TEXTURE_EXTERNAL_OES
:
1005 case GL_PROXY_TEXTURE_3D
:
1006 case GL_TEXTURE_2D_ARRAY
:
1007 case GL_PROXY_TEXTURE_2D_ARRAY
:
1009 case GL_TEXTURE_BUFFER
:
1012 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1021 #if 000 /* not used anymore */
1023 * glTexImage[123]D can accept a NULL image pointer. In this case we
1024 * create a texture image with unspecified image contents per the OpenGL
1028 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1030 const GLint components
= _mesa_components_in_format(format
);
1031 const GLint numPixels
= width
* height
* depth
;
1032 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1036 * Let's see if anyone finds this. If glTexImage2D() is called with
1037 * a NULL image pointer then load the texture image with something
1038 * interesting instead of leaving it indeterminate.
1041 static const char message
[8][32] = {
1042 " X X XXXXX XXX X ",
1043 " XX XX X X X X X ",
1045 " X X XXXX XXX XXXXX ",
1048 " X X XXXXX XXX X X ",
1052 GLubyte
*imgPtr
= data
;
1054 for (h
= 0; h
< depth
; h
++) {
1055 for (i
= 0; i
< height
; i
++) {
1056 GLint srcRow
= 7 - (i
% 8);
1057 for (j
= 0; j
< width
; j
++) {
1058 GLint srcCol
= j
% 32;
1059 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1060 for (k
= 0; k
< components
; k
++) {
1076 * Set the size and format-related fields of a gl_texture_image struct
1077 * to zero. This is used when a proxy texture test fails.
1080 clear_teximage_fields(struct gl_texture_image
*img
)
1083 img
->_BaseFormat
= 0;
1084 img
->InternalFormat
= 0;
1093 img
->HeightLog2
= 0;
1095 img
->TexFormat
= MESA_FORMAT_NONE
;
1100 * Initialize basic fields of the gl_texture_image struct.
1102 * \param ctx GL context.
1103 * \param img texture image structure to be initialized.
1104 * \param width image width.
1105 * \param height image height.
1106 * \param depth image depth.
1107 * \param border image border.
1108 * \param internalFormat internal format.
1109 * \param format the actual hardware format (one of MESA_FORMAT_*)
1111 * Fills in the fields of \p img with the given information.
1112 * Note: width, height and depth include the border.
1115 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1116 struct gl_texture_image
*img
,
1117 GLsizei width
, GLsizei height
, GLsizei depth
,
1118 GLint border
, GLenum internalFormat
,
1124 ASSERT(height
>= 0);
1127 target
= img
->TexObject
->Target
;
1128 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1129 ASSERT(img
->_BaseFormat
> 0);
1130 img
->InternalFormat
= internalFormat
;
1131 img
->Border
= border
;
1133 img
->Height
= height
;
1136 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1137 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1141 case GL_TEXTURE_BUFFER
:
1142 case GL_PROXY_TEXTURE_1D
:
1147 img
->HeightLog2
= 0;
1154 case GL_TEXTURE_1D_ARRAY
:
1155 case GL_PROXY_TEXTURE_1D_ARRAY
:
1156 img
->Height2
= height
; /* no border */
1157 img
->HeightLog2
= 0; /* not used */
1165 case GL_TEXTURE_RECTANGLE
:
1166 case GL_TEXTURE_CUBE_MAP
:
1167 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1168 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1169 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1170 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1171 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1172 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1173 case GL_TEXTURE_EXTERNAL_OES
:
1174 case GL_PROXY_TEXTURE_2D
:
1175 case GL_PROXY_TEXTURE_RECTANGLE
:
1176 case GL_PROXY_TEXTURE_CUBE_MAP
:
1177 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1178 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1185 case GL_TEXTURE_2D_ARRAY
:
1186 case GL_PROXY_TEXTURE_2D_ARRAY
:
1187 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1188 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1189 img
->Depth2
= depth
; /* no border */
1190 img
->DepthLog2
= 0; /* not used */
1193 case GL_PROXY_TEXTURE_3D
:
1194 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1195 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1196 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1197 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1200 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1204 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1205 img
->TexFormat
= format
;
1210 * Free and clear fields of the gl_texture_image struct.
1212 * \param ctx GL context.
1213 * \param texImage texture image structure to be cleared.
1215 * After the call, \p texImage will have no data associated with it. Its
1216 * fields are cleared so that its parent object will test incomplete.
1219 _mesa_clear_texture_image(struct gl_context
*ctx
,
1220 struct gl_texture_image
*texImage
)
1222 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1223 clear_teximage_fields(texImage
);
1228 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1229 * level, width, height and depth against the ctx->Const limits for textures.
1231 * A hardware driver might override this function if, for example, the
1232 * max 3D texture size is 512x512x64 (i.e. not a cube).
1234 * Note that width, height, depth == 0 is not an error. However, a
1235 * texture with zero width/height/depth will be considered "incomplete"
1236 * and texturing will effectively be disabled.
1238 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1239 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1240 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1241 * \param level as passed to glTexImage
1242 * \param internalFormat as passed to glTexImage
1243 * \param format as passed to glTexImage
1244 * \param type as passed to glTexImage
1245 * \param width as passed to glTexImage
1246 * \param height as passed to glTexImage
1247 * \param depth as passed to glTexImage
1248 * \param border as passed to glTexImage
1249 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1252 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1253 GLint internalFormat
, GLenum format
, GLenum type
,
1254 GLint width
, GLint height
, GLint depth
, GLint border
)
1258 (void) internalFormat
;
1263 case GL_PROXY_TEXTURE_1D
:
1264 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1265 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1267 if (level
>= ctx
->Const
.MaxTextureLevels
)
1269 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1270 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1275 case GL_PROXY_TEXTURE_2D
:
1276 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1277 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1279 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1281 if (level
>= ctx
->Const
.MaxTextureLevels
)
1283 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1284 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1286 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1291 case GL_PROXY_TEXTURE_3D
:
1292 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1293 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1295 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1297 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1299 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1301 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1302 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1304 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1306 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1311 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1312 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1313 if (width
< 0 || width
> maxSize
)
1315 if (height
< 0 || height
> maxSize
)
1321 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1322 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 (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1329 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1330 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1332 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1337 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1338 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 (level
>= ctx
->Const
.MaxTextureLevels
)
1345 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1346 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1351 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1352 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 (level
>= ctx
->Const
.MaxTextureLevels
)
1361 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1362 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1364 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1370 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1377 * Check if the memory used by the texture would exceed the driver's limit.
1378 * This lets us support a max 3D texture size of 8K (for example) but
1379 * prevents allocating a full 8K x 8K x 8K texture.
1380 * XXX this could be rolled into the proxy texture size test (above) but
1381 * we don't have the actual texture internal format at that point.
1384 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1385 GLint width
, GLint height
, GLint depth
)
1387 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1388 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1389 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1394 * Return true if the format is only valid for glCompressedTexImage.
1397 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1400 case GL_ETC1_RGB8_OES
:
1409 * Helper function to determine whether a target and specific compression
1410 * format are supported.
1413 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1416 (void) intFormat
; /* not used yet */
1420 case GL_PROXY_TEXTURE_2D
:
1421 return GL_TRUE
; /* true for any compressed format so far */
1422 case GL_PROXY_TEXTURE_CUBE_MAP
:
1423 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1424 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1425 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1426 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1427 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1428 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1429 return ctx
->Extensions
.ARB_texture_cube_map
;
1430 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1431 case GL_TEXTURE_2D_ARRAY_EXT
:
1432 return (ctx
->Extensions
.MESA_texture_array
||
1433 ctx
->Extensions
.EXT_texture_array
);
1441 * Check if the given texture target value is legal for a
1442 * glTexImage1/2/3D call.
1445 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1451 case GL_PROXY_TEXTURE_1D
:
1459 case GL_PROXY_TEXTURE_2D
:
1461 case GL_PROXY_TEXTURE_CUBE_MAP
:
1462 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1463 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1464 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1465 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1466 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1467 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1468 return ctx
->Extensions
.ARB_texture_cube_map
;
1469 case GL_TEXTURE_RECTANGLE_NV
:
1470 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1471 return ctx
->Extensions
.NV_texture_rectangle
;
1472 case GL_TEXTURE_1D_ARRAY_EXT
:
1473 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1474 return (ctx
->Extensions
.MESA_texture_array
||
1475 ctx
->Extensions
.EXT_texture_array
);
1482 case GL_PROXY_TEXTURE_3D
:
1484 case GL_TEXTURE_2D_ARRAY_EXT
:
1485 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1486 return (ctx
->Extensions
.MESA_texture_array
||
1487 ctx
->Extensions
.EXT_texture_array
);
1492 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1499 * Check if the given texture target value is legal for a
1500 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1501 * The difference compared to legal_teximage_target() above is that
1502 * proxy targets are not supported.
1505 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1509 return target
== GL_TEXTURE_1D
;
1514 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1515 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1516 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1517 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1518 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1519 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1520 return ctx
->Extensions
.ARB_texture_cube_map
;
1521 case GL_TEXTURE_RECTANGLE_NV
:
1522 return ctx
->Extensions
.NV_texture_rectangle
;
1523 case GL_TEXTURE_1D_ARRAY_EXT
:
1524 return (ctx
->Extensions
.MESA_texture_array
||
1525 ctx
->Extensions
.EXT_texture_array
);
1533 case GL_TEXTURE_2D_ARRAY_EXT
:
1534 return (ctx
->Extensions
.MESA_texture_array
||
1535 ctx
->Extensions
.EXT_texture_array
);
1540 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1548 * Helper function to determine if a texture object is mutable (in terms
1549 * of GL_ARB_texture_storage).
1552 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1554 if (ctx
->Extensions
.ARB_texture_storage
) {
1555 struct gl_texture_object
*texObj
=
1556 _mesa_get_current_tex_object(ctx
, target
);
1557 return !texObj
->Immutable
;
1565 * Test the glTexImage[123]D() parameters for errors.
1567 * \param ctx GL context.
1568 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1569 * \param target texture target given by the user.
1570 * \param level image level given by the user.
1571 * \param internalFormat internal format given by the user.
1572 * \param format pixel data format given by the user.
1573 * \param type pixel data type given by the user.
1574 * \param width image width given by the user.
1575 * \param height image height given by the user.
1576 * \param depth image depth given by the user.
1577 * \param border image border given by the user.
1579 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1581 * Verifies each of the parameters against the constants specified in
1582 * __struct gl_contextRec::Const and the supported extensions, and according
1583 * to the OpenGL specification.
1586 texture_error_check( struct gl_context
*ctx
,
1587 GLuint dimensions
, GLenum target
,
1588 GLint level
, GLint internalFormat
,
1589 GLenum format
, GLenum type
,
1590 GLint width
, GLint height
,
1591 GLint depth
, GLint border
)
1593 const GLenum proxyTarget
= get_proxy_target(target
);
1594 const GLboolean isProxy
= target
== proxyTarget
;
1595 GLboolean sizeOK
= GL_TRUE
;
1596 GLboolean colorFormat
;
1599 /* Even though there are no color-index textures, we still have to support
1600 * uploading color-index data and remapping it to RGB via the
1601 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1603 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1605 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1606 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1608 _mesa_error(ctx
, GL_INVALID_VALUE
,
1609 "glTexImage%dD(level=%d)", dimensions
, level
);
1615 if (border
< 0 || border
> 1 ||
1616 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1617 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1619 _mesa_error(ctx
, GL_INVALID_VALUE
,
1620 "glTexImage%dD(border=%d)", dimensions
, border
);
1625 if (width
< 0 || height
< 0 || depth
< 0) {
1627 _mesa_error(ctx
, GL_INVALID_VALUE
,
1628 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1633 /* Do this simple check before calling the TestProxyTexImage() function */
1634 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1635 sizeOK
= (width
== height
);
1639 * Use the proxy texture driver hook to see if the size/level/etc are
1642 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1643 internalFormat
, format
,
1644 type
, width
, height
,
1648 _mesa_error(ctx
, GL_INVALID_VALUE
,
1649 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1650 dimensions
, level
, width
, height
, depth
);
1655 /* Check internalFormat */
1656 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1658 _mesa_error(ctx
, GL_INVALID_VALUE
,
1659 "glTexImage%dD(internalFormat=%s)",
1660 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1665 /* Check incoming image format and type */
1666 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1667 if (err
!= GL_NO_ERROR
) {
1669 _mesa_error(ctx
, err
,
1670 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1671 dimensions
, format
, type
);
1676 /* make sure internal format and format basically agree */
1677 colorFormat
= _mesa_is_color_format(format
);
1678 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1679 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1680 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1681 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1682 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1684 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1685 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1686 dimensions
, internalFormat
, format
);
1690 /* additional checks for ycbcr textures */
1691 if (internalFormat
== GL_YCBCR_MESA
) {
1692 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1693 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1694 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1696 _mesa_snprintf(message
, sizeof(message
),
1697 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1698 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1699 return GL_TRUE
; /* error */
1701 if (target
!= GL_TEXTURE_2D
&&
1702 target
!= GL_PROXY_TEXTURE_2D
&&
1703 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1704 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1706 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1712 _mesa_snprintf(message
, sizeof(message
),
1713 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1714 dimensions
, border
);
1715 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1721 /* additional checks for depth textures */
1722 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1723 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1724 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1725 if (target
!= GL_TEXTURE_1D
&&
1726 target
!= GL_PROXY_TEXTURE_1D
&&
1727 target
!= GL_TEXTURE_2D
&&
1728 target
!= GL_PROXY_TEXTURE_2D
&&
1729 target
!= GL_TEXTURE_1D_ARRAY
&&
1730 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1731 target
!= GL_TEXTURE_2D_ARRAY
&&
1732 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1733 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1734 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1735 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1736 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))) {
1738 _mesa_error(ctx
, GL_INVALID_ENUM
,
1739 "glTexImage(target/internalFormat)");
1744 /* additional checks for compressed textures */
1745 if (_mesa_is_compressed_format(ctx
, internalFormat
) ||
1746 is_generic_compressed_format(internalFormat
)) {
1747 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1749 _mesa_error(ctx
, GL_INVALID_ENUM
,
1750 "glTexImage%dD(target)", dimensions
);
1753 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1754 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1755 "glTexImage%dD(no compression for format)", dimensions
);
1760 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1761 "glTexImage%dD(border!=0)", dimensions
);
1767 /* additional checks for integer textures */
1768 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1769 (_mesa_is_enum_format_integer(format
) !=
1770 _mesa_is_enum_format_integer(internalFormat
))) {
1772 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1773 "glTexImage%dD(integer/non-integer format mismatch)",
1779 if (!mutable_tex_object(ctx
, target
)) {
1780 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1781 "glTexImage%dD(immutable texture)", dimensions
);
1785 /* if we get here, the parameters are OK */
1791 * Test glTexSubImage[123]D() parameters for errors.
1793 * \param ctx GL context.
1794 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1795 * \param target texture target given by the user.
1796 * \param level image level given by the user.
1797 * \param xoffset sub-image x offset given by the user.
1798 * \param yoffset sub-image y offset given by the user.
1799 * \param zoffset sub-image z offset given by the user.
1800 * \param format pixel data format given by the user.
1801 * \param type pixel data type given by the user.
1802 * \param width image width given by the user.
1803 * \param height image height given by the user.
1804 * \param depth image depth given by the user.
1806 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1808 * Verifies each of the parameters against the constants specified in
1809 * __struct gl_contextRec::Const and the supported extensions, and according
1810 * to the OpenGL specification.
1813 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1814 GLenum target
, GLint level
,
1815 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1816 GLint width
, GLint height
, GLint depth
,
1817 GLenum format
, GLenum type
)
1821 /* Basic level check */
1822 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1823 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1827 /* Check for negative sizes */
1829 _mesa_error(ctx
, GL_INVALID_VALUE
,
1830 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1833 if (height
< 0 && dimensions
> 1) {
1834 _mesa_error(ctx
, GL_INVALID_VALUE
,
1835 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1838 if (depth
< 0 && dimensions
> 2) {
1839 _mesa_error(ctx
, GL_INVALID_VALUE
,
1840 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1844 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1845 if (err
!= GL_NO_ERROR
) {
1846 _mesa_error(ctx
, err
,
1847 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1848 dimensions
, format
, type
);
1857 * Do second part of glTexSubImage which depends on the destination texture.
1858 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1861 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1862 GLenum target
, GLint level
,
1863 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1864 GLint width
, GLint height
, GLint depth
,
1865 GLenum format
, GLenum type
,
1866 const struct gl_texture_image
*destTex
)
1869 /* undefined image level */
1870 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1874 if (xoffset
< -((GLint
)destTex
->Border
)) {
1875 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1879 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1880 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1884 if (dimensions
> 1) {
1885 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destTex
->Border
;
1886 if (yoffset
< -yBorder
) {
1887 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1891 if (yoffset
+ height
> (GLint
) destTex
->Height
+ yBorder
) {
1892 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1897 if (dimensions
> 2) {
1898 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destTex
->Border
;
1899 if (zoffset
< -zBorder
) {
1900 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1903 if (zoffset
+ depth
> (GLint
) destTex
->Depth
+ zBorder
) {
1904 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1909 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1912 if (compressedteximage_only_format(ctx
, destTex
->InternalFormat
)) {
1913 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1914 "glTexSubImage%dD(no compression for format)", dimensions
);
1918 /* do tests which depend on compression block size */
1919 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1921 /* offset must be multiple of block size */
1922 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1923 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1924 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1925 dimensions
, xoffset
, yoffset
);
1928 /* size must be multiple of bw by bh or equal to whole texture size */
1929 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1930 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1931 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1934 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1935 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1936 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1941 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
1942 /* both source and dest must be integer-valued, or neither */
1943 if (_mesa_is_format_integer_color(destTex
->TexFormat
) !=
1944 _mesa_is_enum_format_integer(format
)) {
1945 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1946 "glTexSubImage%dD(integer/non-integer format mismatch)",
1957 * Test glCopyTexImage[12]D() parameters for errors.
1959 * \param ctx GL context.
1960 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1961 * \param target texture target given by the user.
1962 * \param level image level given by the user.
1963 * \param internalFormat internal format given by the user.
1964 * \param width image width given by the user.
1965 * \param height image height given by the user.
1966 * \param border texture border.
1968 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1970 * Verifies each of the parameters against the constants specified in
1971 * __struct gl_contextRec::Const and the supported extensions, and according
1972 * to the OpenGL specification.
1975 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1976 GLenum target
, GLint level
, GLint internalFormat
,
1977 GLint width
, GLint height
, GLint border
)
1979 const GLenum proxyTarget
= get_proxy_target(target
);
1980 const GLenum type
= GL_FLOAT
;
1985 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1986 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1987 dimensions
, _mesa_lookup_enum_by_nr(target
));
1991 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1992 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1993 _mesa_error(ctx
, GL_INVALID_VALUE
,
1994 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1998 /* Check that the source buffer is complete */
1999 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2000 if (ctx
->ReadBuffer
->_Status
== 0) {
2001 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2003 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2004 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2005 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2009 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2010 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2011 "glCopyTexImage%dD(multisample FBO)",
2018 if (border
< 0 || border
> 1 ||
2019 ((target
== GL_TEXTURE_RECTANGLE_NV
||
2020 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2024 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2025 if (baseFormat
< 0) {
2026 _mesa_error(ctx
, GL_INVALID_VALUE
,
2027 "glCopyTexImage%dD(internalFormat)", dimensions
);
2031 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2032 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2033 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2037 /* From the EXT_texture_integer spec:
2039 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2040 * if the texture internalformat is an integer format and the read color
2041 * buffer is not an integer format, or if the internalformat is not an
2042 * integer format and the read color buffer is an integer format."
2044 if (_mesa_is_color_format(internalFormat
)) {
2045 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2047 if (_mesa_is_enum_format_integer(rb
->InternalFormat
) !=
2048 _mesa_is_enum_format_integer(internalFormat
)) {
2049 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2050 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2055 /* Do size, level checking */
2056 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
2057 ? (width
== height
) : 1;
2059 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
2060 internalFormat
, baseFormat
,
2061 type
, width
, height
,
2065 if (dimensions
== 1) {
2066 _mesa_error(ctx
, GL_INVALID_VALUE
,
2067 "glCopyTexImage1D(width=%d)", width
);
2070 ASSERT(dimensions
== 2);
2071 _mesa_error(ctx
, GL_INVALID_VALUE
,
2072 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2077 if (_mesa_is_compressed_format(ctx
, internalFormat
) ||
2078 is_generic_compressed_format(internalFormat
)) {
2079 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2080 _mesa_error(ctx
, GL_INVALID_ENUM
,
2081 "glCopyTexImage%dD(target)", dimensions
);
2084 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2085 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2086 "glCopyTexImage%dD(no compression for format)", dimensions
);
2090 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2091 "glCopyTexImage%dD(border!=0)", dimensions
);
2096 if (!mutable_tex_object(ctx
, target
)) {
2097 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2098 "glCopyTexImage%dD(immutable texture)", dimensions
);
2102 /* if we get here, the parameters are OK */
2108 * Test glCopyTexSubImage[12]D() parameters for errors.
2109 * Note that this is the first part of error checking.
2110 * See also copytexsubimage_error_check2() below for the second part.
2112 * \param ctx GL context.
2113 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2114 * \param target texture target given by the user.
2115 * \param level image level given by the user.
2117 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2120 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2121 GLenum target
, GLint level
)
2123 /* Check that the source buffer is complete */
2124 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2125 if (ctx
->ReadBuffer
->_Status
== 0) {
2126 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2128 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2129 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2130 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2134 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2135 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2136 "glCopyTexSubImage%dD(multisample FBO)",
2142 /* check target (proxies not allowed) */
2143 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2144 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2145 dimensions
, _mesa_lookup_enum_by_nr(target
));
2150 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2151 _mesa_error(ctx
, GL_INVALID_VALUE
,
2152 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2161 * Second part of error checking for glCopyTexSubImage[12]D().
2162 * \param xoffset sub-image x offset given by the user.
2163 * \param yoffset sub-image y offset given by the user.
2164 * \param zoffset sub-image z offset given by the user.
2165 * \param width image width given by the user.
2166 * \param height image height given by the user.
2169 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2170 GLenum target
, GLint level
,
2171 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2172 GLsizei width
, GLsizei height
,
2173 const struct gl_texture_image
*teximage
)
2175 /* check that dest tex image exists */
2177 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2178 "glCopyTexSubImage%dD(undefined texture level: %d)",
2185 _mesa_error(ctx
, GL_INVALID_VALUE
,
2186 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2189 if (dimensions
> 1 && height
< 0) {
2190 _mesa_error(ctx
, GL_INVALID_VALUE
,
2191 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2195 /* check x/y offsets */
2196 if (xoffset
< -((GLint
)teximage
->Border
)) {
2197 _mesa_error(ctx
, GL_INVALID_VALUE
,
2198 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2201 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2202 _mesa_error(ctx
, GL_INVALID_VALUE
,
2203 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2206 if (dimensions
> 1) {
2207 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : teximage
->Border
;
2208 if (yoffset
< -yBorder
) {
2209 _mesa_error(ctx
, GL_INVALID_VALUE
,
2210 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2213 /* NOTE: we're adding the border here, not subtracting! */
2214 if (yoffset
+ height
> (GLint
) teximage
->Height
+ yBorder
) {
2215 _mesa_error(ctx
, GL_INVALID_VALUE
,
2216 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2221 /* check z offset */
2222 if (dimensions
> 2) {
2223 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : teximage
->Border
;
2224 if (zoffset
< -zBorder
) {
2225 _mesa_error(ctx
, GL_INVALID_VALUE
,
2226 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2229 if (zoffset
> (GLint
) teximage
->Depth
+ zBorder
) {
2230 _mesa_error(ctx
, GL_INVALID_VALUE
,
2231 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2236 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2237 if (compressedteximage_only_format(ctx
, teximage
->InternalFormat
)) {
2238 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2239 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2242 /* offset must be multiple of 4 */
2243 if ((xoffset
& 3) || (yoffset
& 3)) {
2244 _mesa_error(ctx
, GL_INVALID_VALUE
,
2245 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2248 /* size must be multiple of 4 */
2249 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2250 _mesa_error(ctx
, GL_INVALID_VALUE
,
2251 "glCopyTexSubImage%dD(width)", dimensions
);
2254 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2255 _mesa_error(ctx
, GL_INVALID_VALUE
,
2256 "glCopyTexSubImage%dD(height)", dimensions
);
2261 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2262 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2266 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2267 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2268 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2269 dimensions
, teximage
->_BaseFormat
);
2273 /* From the EXT_texture_integer spec:
2275 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2276 * if the texture internalformat is an integer format and the read color
2277 * buffer is not an integer format, or if the internalformat is not an
2278 * integer format and the read color buffer is an integer format."
2280 if (_mesa_is_color_format(teximage
->InternalFormat
)) {
2281 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2283 if (_mesa_is_format_integer_color(rb
->Format
) !=
2284 _mesa_is_format_integer_color(teximage
->TexFormat
)) {
2285 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2286 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2291 /* if we get here, the parameters are OK */
2296 /** Callback info for walking over FBO hash table */
2299 struct gl_context
*ctx
;
2300 struct gl_texture_object
*texObj
;
2306 * Check render to texture callback. Called from _mesa_HashWalk().
2309 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2311 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2312 const struct cb_info
*info
= (struct cb_info
*) userData
;
2313 struct gl_context
*ctx
= info
->ctx
;
2314 const struct gl_texture_object
*texObj
= info
->texObj
;
2315 const GLuint level
= info
->level
, face
= info
->face
;
2317 /* If this is a user-created FBO */
2318 if (_mesa_is_user_fbo(fb
)) {
2320 /* check if any of the FBO's attachments point to 'texObj' */
2321 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2322 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2323 if (att
->Type
== GL_TEXTURE
&&
2324 att
->Texture
== texObj
&&
2325 att
->TextureLevel
== level
&&
2326 att
->CubeMapFace
== face
) {
2327 ASSERT(_mesa_get_attachment_teximage(att
));
2328 /* Tell driver about the new renderbuffer texture */
2329 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2330 /* Mark fb status as indeterminate to force re-validation */
2339 * When a texture image is specified we have to check if it's bound to
2340 * any framebuffer objects (render to texture) in order to detect changes
2341 * in size or format since that effects FBO completeness.
2342 * Any FBOs rendering into the texture must be re-validated.
2345 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2346 struct gl_texture_object
*texObj
,
2347 GLuint face
, GLuint level
)
2349 /* Only check this texture if it's been marked as RenderToTexture */
2350 if (texObj
->_RenderToTexture
) {
2351 struct cb_info info
;
2353 info
.texObj
= texObj
;
2356 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2362 * If the texture object's GenerateMipmap flag is set and we've
2363 * changed the texture base level image, regenerate the rest of the
2364 * mipmap levels now.
2367 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2368 struct gl_texture_object
*texObj
, GLint level
)
2370 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2371 if (texObj
->GenerateMipmap
&&
2372 level
== texObj
->BaseLevel
&&
2373 level
< texObj
->MaxLevel
) {
2374 ASSERT(ctx
->Driver
.GenerateMipmap
);
2375 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2380 /** Debug helper: override the user-requested internal format */
2382 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2385 if (internalFormat
== GL_RGBA16F_ARB
||
2386 internalFormat
== GL_RGBA32F_ARB
) {
2387 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2390 else if (internalFormat
== GL_RGB16F_ARB
||
2391 internalFormat
== GL_RGB32F_ARB
) {
2392 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2395 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2396 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2397 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2398 return GL_LUMINANCE_ALPHA
;
2400 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2401 internalFormat
== GL_LUMINANCE32F_ARB
) {
2402 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2403 return GL_LUMINANCE
;
2405 else if (internalFormat
== GL_ALPHA16F_ARB
||
2406 internalFormat
== GL_ALPHA32F_ARB
) {
2407 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2411 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2412 internalFormat = GL_RGBA;
2416 return internalFormat
;
2419 return internalFormat
;
2425 * Choose the actual hardware format for a texture image.
2426 * Try to use the same format as the previous image level when possible.
2427 * Otherwise, ask the driver for the best format.
2428 * It's important to try to choose a consistant format for all levels
2429 * for efficient texture memory layout/allocation. In particular, this
2430 * comes up during automatic mipmap generation.
2433 _mesa_choose_texture_format(struct gl_context
*ctx
,
2434 struct gl_texture_object
*texObj
,
2435 GLenum target
, GLint level
,
2436 GLenum internalFormat
, GLenum format
, GLenum type
)
2440 /* see if we've already chosen a format for the previous level */
2442 struct gl_texture_image
*prevImage
=
2443 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2444 /* See if the prev level is defined and has an internal format which
2445 * matches the new internal format.
2448 prevImage
->Width
> 0 &&
2449 prevImage
->InternalFormat
== internalFormat
) {
2450 /* use the same format */
2451 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2452 return prevImage
->TexFormat
;
2456 /* choose format from scratch */
2457 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2458 ASSERT(f
!= MESA_FORMAT_NONE
);
2463 * Adjust pixel unpack params and image dimensions to strip off the
2464 * one-pixel texture border.
2466 * Gallium and intel don't support texture borders. They've seldem been used
2467 * and seldom been implemented correctly anyway.
2469 * \param unpackNew returns the new pixel unpack parameters
2472 strip_texture_border(GLenum target
,
2473 GLint
*width
, GLint
*height
, GLint
*depth
,
2474 const struct gl_pixelstore_attrib
*unpack
,
2475 struct gl_pixelstore_attrib
*unpackNew
)
2481 *unpackNew
= *unpack
;
2483 if (unpackNew
->RowLength
== 0)
2484 unpackNew
->RowLength
= *width
;
2486 if (unpackNew
->ImageHeight
== 0)
2487 unpackNew
->ImageHeight
= *height
;
2489 assert(*width
>= 3);
2490 unpackNew
->SkipPixels
++; /* skip the border */
2491 *width
= *width
- 2; /* reduce the width by two border pixels */
2493 /* The min height of a texture with a border is 3 */
2494 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2495 unpackNew
->SkipRows
++; /* skip the border */
2496 *height
= *height
- 2; /* reduce the height by two border pixels */
2499 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
) {
2500 unpackNew
->SkipImages
++; /* skip the border */
2501 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2506 * Common code to implement all the glTexImage1D/2D/3D functions.
2509 teximage(struct gl_context
*ctx
, GLuint dims
,
2510 GLenum target
, GLint level
, GLint internalFormat
,
2511 GLsizei width
, GLsizei height
, GLsizei depth
,
2512 GLint border
, GLenum format
, GLenum type
,
2513 const GLvoid
*pixels
)
2516 struct gl_pixelstore_attrib unpack_no_border
;
2517 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2519 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2521 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2522 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2524 _mesa_lookup_enum_by_nr(target
), level
,
2525 _mesa_lookup_enum_by_nr(internalFormat
),
2526 width
, height
, depth
, border
,
2527 _mesa_lookup_enum_by_nr(format
),
2528 _mesa_lookup_enum_by_nr(type
), pixels
);
2530 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2532 /* target error checking */
2533 if (!legal_teximage_target(ctx
, dims
, target
)) {
2534 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2535 dims
, _mesa_lookup_enum_by_nr(target
));
2539 /* general error checking */
2540 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2541 format
, type
, width
, height
, depth
, border
);
2543 if (_mesa_is_proxy_texture(target
)) {
2544 /* Proxy texture: just clear or set state depending on error checking */
2545 struct gl_texture_image
*texImage
=
2546 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2549 /* when error, clear all proxy texture image parameters */
2551 clear_teximage_fields(texImage
);
2554 /* no error, set the tex image parameters */
2555 struct gl_texture_object
*texObj
=
2556 _mesa_get_current_tex_object(ctx
, target
);
2557 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2562 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2563 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
2564 depth
, border
, internalFormat
,
2567 else if (texImage
) {
2568 clear_teximage_fields(texImage
);
2573 /* non-proxy target */
2574 const GLuint face
= _mesa_tex_target_to_face(target
);
2575 struct gl_texture_object
*texObj
;
2576 struct gl_texture_image
*texImage
;
2579 return; /* error was recorded */
2582 /* Allow a hardware driver to just strip out the border, to provide
2583 * reliable but slightly incorrect hardware rendering instead of
2584 * rarely-tested software fallback rendering.
2586 if (border
&& ctx
->Const
.StripTextureBorder
) {
2587 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
2590 unpack
= &unpack_no_border
;
2593 if (ctx
->NewState
& _NEW_PIXEL
)
2594 _mesa_update_state(ctx
);
2596 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2598 _mesa_lock_texture(ctx
, texObj
);
2600 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2603 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2606 gl_format texFormat
;
2608 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2610 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2611 internalFormat
, format
,
2614 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2615 _mesa_init_teximage_fields(ctx
, texImage
,
2616 width
, height
, depth
,
2617 border
, internalFormat
, texFormat
);
2619 /* Give the texture to the driver. <pixels> may be null. */
2620 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
2621 type
, pixels
, unpack
);
2623 check_gen_mipmap(ctx
, target
, texObj
, level
);
2625 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2627 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2630 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2634 _mesa_unlock_texture(ctx
, texObj
);
2640 * Called from the API. Note that width includes the border.
2643 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2644 GLsizei width
, GLint border
, GLenum format
,
2645 GLenum type
, const GLvoid
*pixels
)
2647 GET_CURRENT_CONTEXT(ctx
);
2648 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2649 border
, format
, type
, pixels
);
2654 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2655 GLsizei width
, GLsizei height
, GLint border
,
2656 GLenum format
, GLenum type
,
2657 const GLvoid
*pixels
)
2659 GET_CURRENT_CONTEXT(ctx
);
2660 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2661 border
, format
, type
, pixels
);
2666 * Called by the API or display list executor.
2667 * Note that width and height include the border.
2670 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2671 GLsizei width
, GLsizei height
, GLsizei depth
,
2672 GLint border
, GLenum format
, GLenum type
,
2673 const GLvoid
*pixels
)
2675 GET_CURRENT_CONTEXT(ctx
);
2676 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2677 border
, format
, type
, pixels
);
2682 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2683 GLsizei width
, GLsizei height
, GLsizei depth
,
2684 GLint border
, GLenum format
, GLenum type
,
2685 const GLvoid
*pixels
)
2687 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2688 depth
, border
, format
, type
, pixels
);
2692 #if FEATURE_OES_EGL_image
2694 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2696 struct gl_texture_object
*texObj
;
2697 struct gl_texture_image
*texImage
;
2698 GET_CURRENT_CONTEXT(ctx
);
2699 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2701 if ((target
== GL_TEXTURE_2D
&&
2702 !ctx
->Extensions
.OES_EGL_image
) ||
2703 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2704 !ctx
->Extensions
.OES_EGL_image_external
)) {
2705 _mesa_error(ctx
, GL_INVALID_ENUM
,
2706 "glEGLImageTargetTexture2D(target=%d)", target
);
2710 if (ctx
->NewState
& _NEW_PIXEL
)
2711 _mesa_update_state(ctx
);
2713 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2714 _mesa_lock_texture(ctx
, texObj
);
2716 if (texObj
->Immutable
) {
2717 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2718 "glEGLImageTargetTexture2D(texture is immutable)");
2719 _mesa_unlock_texture(ctx
, texObj
);
2723 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2725 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2727 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2729 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2730 texObj
, texImage
, image
);
2732 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2734 _mesa_unlock_texture(ctx
, texObj
);
2742 * Implement all the glTexSubImage1/2/3D() functions.
2745 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2746 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2747 GLsizei width
, GLsizei height
, GLsizei depth
,
2748 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2750 struct gl_texture_object
*texObj
;
2751 struct gl_texture_image
*texImage
;
2753 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2755 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2756 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2758 _mesa_lookup_enum_by_nr(target
), level
,
2759 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2760 _mesa_lookup_enum_by_nr(format
),
2761 _mesa_lookup_enum_by_nr(type
), pixels
);
2763 /* check target (proxies not allowed) */
2764 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2765 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2766 dims
, _mesa_lookup_enum_by_nr(target
));
2770 if (ctx
->NewState
& _NEW_PIXEL
)
2771 _mesa_update_state(ctx
);
2773 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2774 width
, height
, depth
, format
, type
)) {
2775 return; /* error was detected */
2778 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2780 _mesa_lock_texture(ctx
, texObj
);
2782 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2784 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2785 xoffset
, yoffset
, zoffset
,
2786 width
, height
, depth
,
2787 format
, type
, texImage
)) {
2788 /* error was recorded */
2790 else if (width
> 0 && height
> 0 && depth
> 0) {
2791 /* If we have a border, offset=-1 is legal. Bias by border width. */
2794 if (target
!= GL_TEXTURE_2D_ARRAY
)
2795 zoffset
+= texImage
->Border
;
2798 if (target
!= GL_TEXTURE_1D_ARRAY
)
2799 yoffset
+= texImage
->Border
;
2802 xoffset
+= texImage
->Border
;
2805 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
2806 xoffset
, yoffset
, zoffset
,
2807 width
, height
, depth
,
2808 format
, type
, pixels
, &ctx
->Unpack
);
2810 check_gen_mipmap(ctx
, target
, texObj
, level
);
2812 ctx
->NewState
|= _NEW_TEXTURE
;
2815 _mesa_unlock_texture(ctx
, texObj
);
2820 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2821 GLint xoffset
, GLsizei width
,
2822 GLenum format
, GLenum type
,
2823 const GLvoid
*pixels
)
2825 GET_CURRENT_CONTEXT(ctx
);
2826 texsubimage(ctx
, 1, target
, level
,
2829 format
, type
, pixels
);
2834 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2835 GLint xoffset
, GLint yoffset
,
2836 GLsizei width
, GLsizei height
,
2837 GLenum format
, GLenum type
,
2838 const GLvoid
*pixels
)
2840 GET_CURRENT_CONTEXT(ctx
);
2841 texsubimage(ctx
, 2, target
, level
,
2842 xoffset
, yoffset
, 0,
2844 format
, type
, pixels
);
2850 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2851 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2852 GLsizei width
, GLsizei height
, GLsizei depth
,
2853 GLenum format
, GLenum type
,
2854 const GLvoid
*pixels
)
2856 GET_CURRENT_CONTEXT(ctx
);
2857 texsubimage(ctx
, 3, target
, level
,
2858 xoffset
, yoffset
, zoffset
,
2859 width
, height
, depth
,
2860 format
, type
, pixels
);
2866 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
2867 * from. This depends on whether the texture contains color or depth values.
2869 static struct gl_renderbuffer
*
2870 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
2872 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
2873 /* reading from depth/stencil buffer */
2874 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
2877 /* copying from color buffer */
2878 return ctx
->ReadBuffer
->_ColorReadBuffer
;
2885 * Implement the glCopyTexImage1/2D() functions.
2888 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2889 GLenum target
, GLint level
, GLenum internalFormat
,
2890 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2892 struct gl_texture_object
*texObj
;
2893 struct gl_texture_image
*texImage
;
2894 const GLuint face
= _mesa_tex_target_to_face(target
);
2896 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2898 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2899 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2901 _mesa_lookup_enum_by_nr(target
), level
,
2902 _mesa_lookup_enum_by_nr(internalFormat
),
2903 x
, y
, width
, height
, border
);
2905 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2906 _mesa_update_state(ctx
);
2908 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2909 width
, height
, border
))
2912 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2914 if (border
&& ctx
->Const
.StripTextureBorder
) {
2916 width
-= border
* 2;
2919 height
-= border
* 2;
2924 _mesa_lock_texture(ctx
, texObj
);
2926 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2929 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2932 /* choose actual hw format */
2933 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2938 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2939 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
2941 /* Free old texture image */
2942 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2944 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
2945 border
, internalFormat
, texFormat
);
2947 /* Allocate texture memory (no pixel data yet) */
2948 ctx
->Driver
.TexImage(ctx
, dims
, texImage
,
2950 NULL
, &ctx
->Unpack
);
2952 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2954 struct gl_renderbuffer
*srcRb
=
2955 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
2957 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
2958 srcRb
, srcX
, srcY
, width
, height
);
2961 check_gen_mipmap(ctx
, target
, texObj
, level
);
2963 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2965 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2968 /* probably too large of image */
2969 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2973 _mesa_unlock_texture(ctx
, texObj
);
2979 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2980 GLenum internalFormat
,
2982 GLsizei width
, GLint border
)
2984 GET_CURRENT_CONTEXT(ctx
);
2985 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2991 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2992 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2995 GET_CURRENT_CONTEXT(ctx
);
2996 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2997 x
, y
, width
, height
, border
);
3003 * Implementation for glCopyTexSubImage1/2/3D() functions.
3006 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3007 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3008 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3010 struct gl_texture_object
*texObj
;
3011 struct gl_texture_image
*texImage
;
3013 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3015 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3016 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3018 _mesa_lookup_enum_by_nr(target
),
3019 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3021 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3022 _mesa_update_state(ctx
);
3024 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
3027 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3029 _mesa_lock_texture(ctx
, texObj
);
3031 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3033 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
3034 zoffset
, width
, height
, texImage
)) {
3035 /* error was recored */
3038 /* If we have a border, offset=-1 is legal. Bias by border width. */
3041 if (target
!= GL_TEXTURE_2D_ARRAY
)
3042 zoffset
+= texImage
->Border
;
3045 if (target
!= GL_TEXTURE_1D_ARRAY
)
3046 yoffset
+= texImage
->Border
;
3049 xoffset
+= texImage
->Border
;
3052 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3054 struct gl_renderbuffer
*srcRb
=
3055 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3057 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3058 xoffset
, yoffset
, zoffset
,
3059 srcRb
, x
, y
, width
, height
);
3061 check_gen_mipmap(ctx
, target
, texObj
, level
);
3063 ctx
->NewState
|= _NEW_TEXTURE
;
3067 _mesa_unlock_texture(ctx
, texObj
);
3072 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3073 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3075 GET_CURRENT_CONTEXT(ctx
);
3076 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3082 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3083 GLint xoffset
, GLint yoffset
,
3084 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3086 GET_CURRENT_CONTEXT(ctx
);
3087 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3094 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3095 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3096 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3098 GET_CURRENT_CONTEXT(ctx
);
3099 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3100 x
, y
, width
, height
);
3106 /**********************************************************************/
3107 /****** Compressed Textures ******/
3108 /**********************************************************************/
3112 * Return expected size of a compressed texture.
3115 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3118 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3119 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3124 * Return compressed texture block size, in pixels.
3127 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3129 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3130 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3135 * Error checking for glCompressedTexImage[123]D().
3136 * \param reason returns reason for error, if any
3137 * \return error code or GL_NO_ERROR.
3140 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3141 GLenum target
, GLint level
,
3142 GLenum internalFormat
, GLsizei width
,
3143 GLsizei height
, GLsizei depth
, GLint border
,
3144 GLsizei imageSize
, char **reason
)
3146 const GLenum proxyTarget
= get_proxy_target(target
);
3147 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3149 GLenum choose_format
;
3151 GLenum proxy_format
;
3153 *reason
= ""; /* no error */
3155 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3157 return GL_INVALID_ENUM
;
3160 /* This will detect any invalid internalFormat value */
3161 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3162 *reason
= "internalFormat";
3163 return GL_INVALID_ENUM
;
3166 switch (internalFormat
) {
3168 case GL_PALETTE4_RGB8_OES
:
3169 case GL_PALETTE4_RGBA8_OES
:
3170 case GL_PALETTE4_R5_G6_B5_OES
:
3171 case GL_PALETTE4_RGBA4_OES
:
3172 case GL_PALETTE4_RGB5_A1_OES
:
3173 case GL_PALETTE8_RGB8_OES
:
3174 case GL_PALETTE8_RGBA8_OES
:
3175 case GL_PALETTE8_R5_G6_B5_OES
:
3176 case GL_PALETTE8_RGBA4_OES
:
3177 case GL_PALETTE8_RGB5_A1_OES
:
3178 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3180 proxy_format
= choose_format
;
3183 if (level
> 0 || level
< -maxLevels
) {
3185 return GL_INVALID_VALUE
;
3188 if (dimensions
!= 2) {
3189 *reason
= "compressed paletted textures must be 2D";
3190 return GL_INVALID_OPERATION
;
3193 /* Figure out the expected texture size (in bytes). This will be
3194 * checked against the actual size later.
3196 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3199 /* This is for the benefit of the TestProxyTexImage below. It expects
3200 * level to be non-negative. OES_compressed_paletted_texture uses a
3201 * weird mechanism where the level specified to glCompressedTexImage2D
3202 * is -(n-1) number of levels in the texture, and the data specifies the
3203 * complete mipmap stack. This is done to ensure the palette is the
3204 * same for all levels.
3211 choose_format
= GL_NONE
;
3212 choose_type
= GL_NONE
;
3213 proxy_format
= internalFormat
;
3216 if (level
< 0 || level
>= maxLevels
) {
3218 return GL_INVALID_VALUE
;
3221 /* Figure out the expected texture size (in bytes). This will be
3222 * checked against the actual size later.
3224 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3228 /* This should really never fail */
3229 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3230 *reason
= "internalFormat";
3231 return GL_INVALID_ENUM
;
3234 /* No compressed formats support borders at this time */
3236 *reason
= "border != 0";
3237 return GL_INVALID_VALUE
;
3240 /* For cube map, width must equal height */
3241 if (_mesa_is_cube_face(target
) && width
!= height
) {
3242 *reason
= "width != height";
3243 return GL_INVALID_VALUE
;
3246 /* check image size against compression block size */
3248 gl_format texFormat
=
3249 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3250 choose_format
, choose_type
);
3253 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3254 if ((width
> bw
&& width
% bw
> 0) ||
3255 (height
> bh
&& height
% bh
> 0)) {
3257 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3258 * generated [...] if any parameter combinations are not
3259 * supported by the specific compressed internal format.
3261 *reason
= "invalid width or height for compression format";
3262 return GL_INVALID_OPERATION
;
3266 /* check image sizes */
3267 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3268 proxy_format
, choose_format
,
3270 width
, height
, depth
, border
)) {
3271 /* See error comment above */
3272 *reason
= "invalid width, height or format";
3273 return GL_INVALID_OPERATION
;
3276 /* check image size in bytes */
3277 if (expectedSize
!= imageSize
) {
3278 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3279 * if <imageSize> is not consistent with the format, dimensions, and
3280 * contents of the specified image.
3282 *reason
= "imageSize inconsistant with width/height/format";
3283 return GL_INVALID_VALUE
;
3286 if (!mutable_tex_object(ctx
, target
)) {
3287 *reason
= "immutable texture";
3288 return GL_INVALID_OPERATION
;
3296 * Error checking for glCompressedTexSubImage[123]D().
3297 * \warning There are some bad assumptions here about the size of compressed
3298 * texture tiles (multiple of 4) used to test the validity of the
3299 * offset and size parameters.
3300 * \return error code or GL_NO_ERROR.
3303 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3304 GLenum target
, GLint level
,
3305 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3306 GLsizei width
, GLsizei height
, GLsizei depth
,
3307 GLenum format
, GLsizei imageSize
)
3309 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3313 if (dimensions
== 1) {
3314 /* 1D compressed textures not allowed */
3315 return GL_INVALID_ENUM
;
3317 else if (dimensions
== 2) {
3318 if (target
== GL_PROXY_TEXTURE_2D
) {
3319 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3321 else if (target
== GL_TEXTURE_2D
) {
3322 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3324 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3325 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3326 return GL_INVALID_ENUM
; /*target*/
3327 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3329 else if (_mesa_is_cube_face(target
)) {
3330 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3331 return GL_INVALID_ENUM
; /*target*/
3332 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3335 return GL_INVALID_ENUM
; /*target*/
3338 else if (dimensions
== 3) {
3339 /* 3D compressed textures not allowed */
3340 return GL_INVALID_ENUM
;
3343 maxTextureSize
= 1 << (maxLevels
- 1);
3345 /* this will catch any invalid compressed format token */
3346 if (!_mesa_is_compressed_format(ctx
, format
))
3347 return GL_INVALID_ENUM
;
3349 if (width
< 1 || width
> maxTextureSize
)
3350 return GL_INVALID_VALUE
;
3352 if ((height
< 1 || height
> maxTextureSize
)
3354 return GL_INVALID_VALUE
;
3356 if (level
< 0 || level
>= maxLevels
)
3357 return GL_INVALID_VALUE
;
3360 * do checks which depend on compression block size
3362 get_compressed_block_size(format
, &bw
, &bh
);
3364 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3365 return GL_INVALID_VALUE
;
3367 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3368 return GL_INVALID_VALUE
;
3370 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3371 return GL_INVALID_VALUE
;
3373 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3374 if (expectedSize
!= imageSize
)
3375 return GL_INVALID_VALUE
;
3382 * Do second part of glCompressedTexSubImage error checking.
3383 * \return GL_TRUE if error found, GL_FALSE otherwise.
3386 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3387 GLsizei width
, GLsizei height
,
3388 GLsizei depth
, GLenum format
,
3389 struct gl_texture_image
*texImage
)
3392 if ((GLint
) format
!= texImage
->InternalFormat
) {
3393 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3394 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3398 if (compressedteximage_only_format(ctx
, format
)) {
3399 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3400 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3405 if (((width
== 1 || width
== 2) &&
3406 width
!= (GLsizei
) texImage
->Width
) ||
3407 (width
> (GLsizei
) texImage
->Width
)) {
3408 _mesa_error(ctx
, GL_INVALID_VALUE
,
3409 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3414 if (((height
== 1 || height
== 2) &&
3415 height
!= (GLsizei
) texImage
->Height
) ||
3416 (height
> (GLsizei
) texImage
->Height
)) {
3417 _mesa_error(ctx
, GL_INVALID_VALUE
,
3418 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3424 if (((depth
== 1 || depth
== 2) &&
3425 depth
!= (GLsizei
) texImage
->Depth
) ||
3426 (depth
> (GLsizei
) texImage
->Depth
)) {
3427 _mesa_error(ctx
, GL_INVALID_VALUE
,
3428 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3438 * Implementation of the glCompressedTexImage1/2/3D() functions.
3441 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3442 GLenum target
, GLint level
,
3443 GLenum internalFormat
, GLsizei width
,
3444 GLsizei height
, GLsizei depth
, GLint border
,
3445 GLsizei imageSize
, const GLvoid
*data
)
3450 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3452 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3454 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3456 _mesa_lookup_enum_by_nr(target
), level
,
3457 _mesa_lookup_enum_by_nr(internalFormat
),
3458 width
, height
, depth
, border
, imageSize
, data
);
3461 if (!legal_teximage_target(ctx
, dims
, target
)) {
3462 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3463 dims
, _mesa_lookup_enum_by_nr(target
));
3467 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3468 internalFormat
, width
, height
, depth
,
3469 border
, imageSize
, &reason
);
3472 /* XXX this is kind of a hack */
3473 if (!error
&& dims
== 2) {
3474 switch (internalFormat
) {
3475 case GL_PALETTE4_RGB8_OES
:
3476 case GL_PALETTE4_RGBA8_OES
:
3477 case GL_PALETTE4_R5_G6_B5_OES
:
3478 case GL_PALETTE4_RGBA4_OES
:
3479 case GL_PALETTE4_RGB5_A1_OES
:
3480 case GL_PALETTE8_RGB8_OES
:
3481 case GL_PALETTE8_RGBA8_OES
:
3482 case GL_PALETTE8_R5_G6_B5_OES
:
3483 case GL_PALETTE8_RGBA4_OES
:
3484 case GL_PALETTE8_RGB5_A1_OES
:
3485 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3486 width
, height
, imageSize
, data
);
3492 if (_mesa_is_proxy_texture(target
)) {
3493 /* Proxy texture: just check for errors and update proxy state */
3494 struct gl_texture_image
*texImage
;
3497 struct gl_texture_object
*texObj
=
3498 _mesa_get_current_tex_object(ctx
, target
);
3499 gl_format texFormat
=
3500 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3501 internalFormat
, GL_NONE
, GL_NONE
);
3502 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3503 error
= GL_OUT_OF_MEMORY
;
3507 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3510 /* if error, clear all proxy texture image parameters */
3511 clear_teximage_fields(texImage
);
3514 /* no error: store the teximage parameters */
3515 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
3516 depth
, border
, internalFormat
,
3522 /* non-proxy target */
3523 struct gl_texture_object
*texObj
;
3524 struct gl_texture_image
*texImage
;
3527 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3531 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3533 _mesa_lock_texture(ctx
, texObj
);
3535 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3537 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3538 "glCompressedTexImage%uD", dims
);
3541 gl_format texFormat
;
3543 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3545 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3546 internalFormat
, GL_NONE
,
3549 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3550 _mesa_init_teximage_fields(ctx
, texImage
,
3551 width
, height
, depth
,
3552 border
, internalFormat
, texFormat
);
3554 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
, imageSize
,
3557 check_gen_mipmap(ctx
, target
, texObj
, level
);
3559 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3562 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3563 "glCompressedTexImage%uD", dims
);
3567 _mesa_unlock_texture(ctx
, texObj
);
3573 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3574 GLenum internalFormat
, GLsizei width
,
3575 GLint border
, GLsizei imageSize
,
3578 GET_CURRENT_CONTEXT(ctx
);
3579 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3580 width
, 1, 1, border
, imageSize
, data
);
3585 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3586 GLenum internalFormat
, GLsizei width
,
3587 GLsizei height
, GLint border
, GLsizei imageSize
,
3590 GET_CURRENT_CONTEXT(ctx
);
3591 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3592 width
, height
, 1, border
, imageSize
, data
);
3597 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3598 GLenum internalFormat
, GLsizei width
,
3599 GLsizei height
, GLsizei depth
, GLint border
,
3600 GLsizei imageSize
, const GLvoid
*data
)
3602 GET_CURRENT_CONTEXT(ctx
);
3603 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3604 width
, height
, depth
, border
, imageSize
, data
);
3609 * Common helper for glCompressedTexSubImage1/2/3D().
3612 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3613 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3614 GLsizei width
, GLsizei height
, GLsizei depth
,
3615 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3617 struct gl_texture_object
*texObj
;
3618 struct gl_texture_image
*texImage
;
3620 GET_CURRENT_CONTEXT(ctx
);
3621 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3623 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3624 xoffset
, 0, 0, /* pos */
3625 width
, height
, depth
, /* size */
3628 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3632 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3634 _mesa_lock_texture(ctx
, texObj
);
3636 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3639 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3640 format
, texImage
)) {
3641 /* error was recorded */
3643 else if (width
> 0 && height
> 0 && depth
> 0) {
3644 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3645 xoffset
, yoffset
, zoffset
,
3646 width
, height
, depth
,
3647 format
, imageSize
, data
);
3649 check_gen_mipmap(ctx
, target
, texObj
, level
);
3651 ctx
->NewState
|= _NEW_TEXTURE
;
3654 _mesa_unlock_texture(ctx
, texObj
);
3659 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3660 GLsizei width
, GLenum format
,
3661 GLsizei imageSize
, const GLvoid
*data
)
3663 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3664 format
, imageSize
, data
);
3669 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3670 GLint yoffset
, GLsizei width
, GLsizei height
,
3671 GLenum format
, GLsizei imageSize
,
3674 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3675 width
, height
, 1, format
, imageSize
, data
);
3680 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3681 GLint yoffset
, GLint zoffset
, GLsizei width
,
3682 GLsizei height
, GLsizei depth
, GLenum format
,
3683 GLsizei imageSize
, const GLvoid
*data
)
3685 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3686 width
, height
, depth
, format
, imageSize
, data
);
3690 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3692 switch (internalFormat
) {
3694 return MESA_FORMAT_A8
;
3696 return MESA_FORMAT_A16
;
3697 case GL_ALPHA16F_ARB
:
3698 return MESA_FORMAT_ALPHA_FLOAT16
;
3699 case GL_ALPHA32F_ARB
:
3700 return MESA_FORMAT_ALPHA_FLOAT32
;
3701 case GL_ALPHA8I_EXT
:
3702 return MESA_FORMAT_ALPHA_INT8
;
3703 case GL_ALPHA16I_EXT
:
3704 return MESA_FORMAT_ALPHA_INT16
;
3705 case GL_ALPHA32I_EXT
:
3706 return MESA_FORMAT_ALPHA_INT32
;
3707 case GL_ALPHA8UI_EXT
:
3708 return MESA_FORMAT_ALPHA_UINT8
;
3709 case GL_ALPHA16UI_EXT
:
3710 return MESA_FORMAT_ALPHA_UINT16
;
3711 case GL_ALPHA32UI_EXT
:
3712 return MESA_FORMAT_ALPHA_UINT32
;
3714 return MESA_FORMAT_L8
;
3715 case GL_LUMINANCE16
:
3716 return MESA_FORMAT_L16
;
3717 case GL_LUMINANCE16F_ARB
:
3718 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3719 case GL_LUMINANCE32F_ARB
:
3720 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3721 case GL_LUMINANCE8I_EXT
:
3722 return MESA_FORMAT_LUMINANCE_INT8
;
3723 case GL_LUMINANCE16I_EXT
:
3724 return MESA_FORMAT_LUMINANCE_INT16
;
3725 case GL_LUMINANCE32I_EXT
:
3726 return MESA_FORMAT_LUMINANCE_INT32
;
3727 case GL_LUMINANCE8UI_EXT
:
3728 return MESA_FORMAT_LUMINANCE_UINT8
;
3729 case GL_LUMINANCE16UI_EXT
:
3730 return MESA_FORMAT_LUMINANCE_UINT16
;
3731 case GL_LUMINANCE32UI_EXT
:
3732 return MESA_FORMAT_LUMINANCE_UINT32
;
3733 case GL_LUMINANCE8_ALPHA8
:
3734 return MESA_FORMAT_AL88
;
3735 case GL_LUMINANCE16_ALPHA16
:
3736 return MESA_FORMAT_AL1616
;
3737 case GL_LUMINANCE_ALPHA16F_ARB
:
3738 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3739 case GL_LUMINANCE_ALPHA32F_ARB
:
3740 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3741 case GL_LUMINANCE_ALPHA8I_EXT
:
3742 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3743 case GL_LUMINANCE_ALPHA16I_EXT
:
3744 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3745 case GL_LUMINANCE_ALPHA32I_EXT
:
3746 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3747 case GL_LUMINANCE_ALPHA8UI_EXT
:
3748 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3749 case GL_LUMINANCE_ALPHA16UI_EXT
:
3750 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3751 case GL_LUMINANCE_ALPHA32UI_EXT
:
3752 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3754 return MESA_FORMAT_I8
;
3755 case GL_INTENSITY16
:
3756 return MESA_FORMAT_I16
;
3757 case GL_INTENSITY16F_ARB
:
3758 return MESA_FORMAT_INTENSITY_FLOAT16
;
3759 case GL_INTENSITY32F_ARB
:
3760 return MESA_FORMAT_INTENSITY_FLOAT32
;
3761 case GL_INTENSITY8I_EXT
:
3762 return MESA_FORMAT_INTENSITY_INT8
;
3763 case GL_INTENSITY16I_EXT
:
3764 return MESA_FORMAT_INTENSITY_INT16
;
3765 case GL_INTENSITY32I_EXT
:
3766 return MESA_FORMAT_INTENSITY_INT32
;
3767 case GL_INTENSITY8UI_EXT
:
3768 return MESA_FORMAT_INTENSITY_UINT8
;
3769 case GL_INTENSITY16UI_EXT
:
3770 return MESA_FORMAT_INTENSITY_UINT16
;
3771 case GL_INTENSITY32UI_EXT
:
3772 return MESA_FORMAT_INTENSITY_UINT32
;
3774 return MESA_FORMAT_RGBA8888_REV
;
3776 return MESA_FORMAT_RGBA_16
;
3777 case GL_RGBA16F_ARB
:
3778 return MESA_FORMAT_RGBA_FLOAT16
;
3779 case GL_RGBA32F_ARB
:
3780 return MESA_FORMAT_RGBA_FLOAT32
;
3782 return MESA_FORMAT_RGBA_INT8
;
3783 case GL_RGBA16I_EXT
:
3784 return MESA_FORMAT_RGBA_INT16
;
3785 case GL_RGBA32I_EXT
:
3786 return MESA_FORMAT_RGBA_INT32
;
3787 case GL_RGBA8UI_EXT
:
3788 return MESA_FORMAT_RGBA_UINT8
;
3789 case GL_RGBA16UI_EXT
:
3790 return MESA_FORMAT_RGBA_UINT16
;
3791 case GL_RGBA32UI_EXT
:
3792 return MESA_FORMAT_RGBA_UINT32
;
3795 return MESA_FORMAT_GR88
;
3797 return MESA_FORMAT_RG1616
;
3799 return MESA_FORMAT_RG_FLOAT16
;
3801 return MESA_FORMAT_RG_FLOAT32
;
3803 return MESA_FORMAT_RG_INT8
;
3805 return MESA_FORMAT_RG_INT16
;
3807 return MESA_FORMAT_RG_INT32
;
3809 return MESA_FORMAT_RG_UINT8
;
3811 return MESA_FORMAT_RG_UINT16
;
3813 return MESA_FORMAT_RG_UINT32
;
3816 return MESA_FORMAT_R8
;
3818 return MESA_FORMAT_R16
;
3820 return MESA_FORMAT_R_FLOAT16
;
3822 return MESA_FORMAT_R_FLOAT32
;
3824 return MESA_FORMAT_R_INT8
;
3826 return MESA_FORMAT_R_INT16
;
3828 return MESA_FORMAT_R_INT32
;
3830 return MESA_FORMAT_R_UINT8
;
3832 return MESA_FORMAT_R_UINT16
;
3834 return MESA_FORMAT_R_UINT32
;
3837 return MESA_FORMAT_NONE
;
3842 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3844 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
3847 if (format
== MESA_FORMAT_NONE
)
3848 return MESA_FORMAT_NONE
;
3850 datatype
= _mesa_get_format_datatype(format
);
3851 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3852 return MESA_FORMAT_NONE
;
3854 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3855 return MESA_FORMAT_NONE
;
3857 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
3858 * any mention of R/RG formats, but they appear in the GL 3.1 core
3861 if (ctx
->Version
<= 30) {
3862 GLenum base_format
= _mesa_get_format_base_format(format
);
3864 if (base_format
== GL_R
|| base_format
== GL_RG
)
3865 return MESA_FORMAT_NONE
;
3871 /** GL_ARB_texture_buffer_object */
3873 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3875 struct gl_texture_object
*texObj
;
3876 struct gl_buffer_object
*bufObj
;
3879 GET_CURRENT_CONTEXT(ctx
);
3880 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3882 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3883 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3887 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3888 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3892 format
= validate_texbuffer_format(ctx
, internalFormat
);
3893 if (format
== MESA_FORMAT_NONE
) {
3894 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3899 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3900 if (buffer
&& !bufObj
) {
3901 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3905 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3907 _mesa_lock_texture(ctx
, texObj
);
3909 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3910 texObj
->BufferObjectFormat
= internalFormat
;
3911 texObj
->_BufferObjectFormat
= format
;
3913 _mesa_unlock_texture(ctx
, texObj
);