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 return _mesa_is_desktop_gl(ctx
) &&
971 (ctx
->Extensions
.ARB_texture_buffer_object
||
972 (ctx
->Version
>= 31)) ? 1 : 0;
973 case GL_TEXTURE_EXTERNAL_OES
:
976 return 0; /* bad target */
982 * Return number of dimensions per mipmap level for the given texture target.
985 _mesa_get_texture_dimensions(GLenum target
)
989 case GL_PROXY_TEXTURE_1D
:
992 case GL_TEXTURE_RECTANGLE
:
993 case GL_TEXTURE_CUBE_MAP
:
994 case GL_PROXY_TEXTURE_2D
:
995 case GL_PROXY_TEXTURE_RECTANGLE
:
996 case GL_PROXY_TEXTURE_CUBE_MAP
:
997 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
998 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
999 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1000 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1001 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1002 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1003 case GL_TEXTURE_1D_ARRAY
:
1004 case GL_PROXY_TEXTURE_1D_ARRAY
:
1005 case GL_TEXTURE_EXTERNAL_OES
:
1008 case GL_PROXY_TEXTURE_3D
:
1009 case GL_TEXTURE_2D_ARRAY
:
1010 case GL_PROXY_TEXTURE_2D_ARRAY
:
1012 case GL_TEXTURE_BUFFER
:
1015 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1024 #if 000 /* not used anymore */
1026 * glTexImage[123]D can accept a NULL image pointer. In this case we
1027 * create a texture image with unspecified image contents per the OpenGL
1031 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1033 const GLint components
= _mesa_components_in_format(format
);
1034 const GLint numPixels
= width
* height
* depth
;
1035 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1039 * Let's see if anyone finds this. If glTexImage2D() is called with
1040 * a NULL image pointer then load the texture image with something
1041 * interesting instead of leaving it indeterminate.
1044 static const char message
[8][32] = {
1045 " X X XXXXX XXX X ",
1046 " XX XX X X X X X ",
1048 " X X XXXX XXX XXXXX ",
1051 " X X XXXXX XXX X X ",
1055 GLubyte
*imgPtr
= data
;
1057 for (h
= 0; h
< depth
; h
++) {
1058 for (i
= 0; i
< height
; i
++) {
1059 GLint srcRow
= 7 - (i
% 8);
1060 for (j
= 0; j
< width
; j
++) {
1061 GLint srcCol
= j
% 32;
1062 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1063 for (k
= 0; k
< components
; k
++) {
1079 * Set the size and format-related fields of a gl_texture_image struct
1080 * to zero. This is used when a proxy texture test fails.
1083 clear_teximage_fields(struct gl_texture_image
*img
)
1086 img
->_BaseFormat
= 0;
1087 img
->InternalFormat
= 0;
1096 img
->HeightLog2
= 0;
1098 img
->TexFormat
= MESA_FORMAT_NONE
;
1103 * Initialize basic fields of the gl_texture_image struct.
1105 * \param ctx GL context.
1106 * \param img texture image structure to be initialized.
1107 * \param width image width.
1108 * \param height image height.
1109 * \param depth image depth.
1110 * \param border image border.
1111 * \param internalFormat internal format.
1112 * \param format the actual hardware format (one of MESA_FORMAT_*)
1114 * Fills in the fields of \p img with the given information.
1115 * Note: width, height and depth include the border.
1118 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1119 struct gl_texture_image
*img
,
1120 GLsizei width
, GLsizei height
, GLsizei depth
,
1121 GLint border
, GLenum internalFormat
,
1127 ASSERT(height
>= 0);
1130 target
= img
->TexObject
->Target
;
1131 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1132 ASSERT(img
->_BaseFormat
> 0);
1133 img
->InternalFormat
= internalFormat
;
1134 img
->Border
= border
;
1136 img
->Height
= height
;
1139 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1140 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1144 case GL_TEXTURE_BUFFER
:
1145 case GL_PROXY_TEXTURE_1D
:
1150 img
->HeightLog2
= 0;
1157 case GL_TEXTURE_1D_ARRAY
:
1158 case GL_PROXY_TEXTURE_1D_ARRAY
:
1159 img
->Height2
= height
; /* no border */
1160 img
->HeightLog2
= 0; /* not used */
1168 case GL_TEXTURE_RECTANGLE
:
1169 case GL_TEXTURE_CUBE_MAP
:
1170 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1171 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1172 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1173 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1174 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1175 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1176 case GL_TEXTURE_EXTERNAL_OES
:
1177 case GL_PROXY_TEXTURE_2D
:
1178 case GL_PROXY_TEXTURE_RECTANGLE
:
1179 case GL_PROXY_TEXTURE_CUBE_MAP
:
1180 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1181 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1188 case GL_TEXTURE_2D_ARRAY
:
1189 case GL_PROXY_TEXTURE_2D_ARRAY
:
1190 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1191 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1192 img
->Depth2
= depth
; /* no border */
1193 img
->DepthLog2
= 0; /* not used */
1196 case GL_PROXY_TEXTURE_3D
:
1197 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1198 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1199 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1200 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1203 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1207 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1208 img
->TexFormat
= format
;
1213 * Free and clear fields of the gl_texture_image struct.
1215 * \param ctx GL context.
1216 * \param texImage texture image structure to be cleared.
1218 * After the call, \p texImage will have no data associated with it. Its
1219 * fields are cleared so that its parent object will test incomplete.
1222 _mesa_clear_texture_image(struct gl_context
*ctx
,
1223 struct gl_texture_image
*texImage
)
1225 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1226 clear_teximage_fields(texImage
);
1231 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1232 * level, width, height and depth against the ctx->Const limits for textures.
1234 * A hardware driver might override this function if, for example, the
1235 * max 3D texture size is 512x512x64 (i.e. not a cube).
1237 * Note that width, height, depth == 0 is not an error. However, a
1238 * texture with zero width/height/depth will be considered "incomplete"
1239 * and texturing will effectively be disabled.
1241 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1242 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1243 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1244 * \param level as passed to glTexImage
1245 * \param internalFormat as passed to glTexImage
1246 * \param format as passed to glTexImage
1247 * \param type as passed to glTexImage
1248 * \param width as passed to glTexImage
1249 * \param height as passed to glTexImage
1250 * \param depth as passed to glTexImage
1251 * \param border as passed to glTexImage
1252 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1255 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1256 GLint internalFormat
, GLenum format
, GLenum type
,
1257 GLint width
, GLint height
, GLint depth
, GLint border
)
1261 (void) internalFormat
;
1266 case GL_PROXY_TEXTURE_1D
:
1267 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1268 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1270 if (level
>= ctx
->Const
.MaxTextureLevels
)
1272 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1273 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1278 case GL_PROXY_TEXTURE_2D
:
1279 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1280 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1282 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1284 if (level
>= ctx
->Const
.MaxTextureLevels
)
1286 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1287 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1289 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1294 case GL_PROXY_TEXTURE_3D
:
1295 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1296 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1298 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1300 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1302 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1304 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1305 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1307 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1309 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1314 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1315 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1316 if (width
< 0 || width
> maxSize
)
1318 if (height
< 0 || height
> maxSize
)
1324 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1325 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1326 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1328 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1330 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1332 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1333 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1335 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1340 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1341 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1342 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1344 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1346 if (level
>= ctx
->Const
.MaxTextureLevels
)
1348 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1349 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1354 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1355 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1356 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1358 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1360 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1362 if (level
>= ctx
->Const
.MaxTextureLevels
)
1364 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1365 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1367 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1373 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1380 * Check if the memory used by the texture would exceed the driver's limit.
1381 * This lets us support a max 3D texture size of 8K (for example) but
1382 * prevents allocating a full 8K x 8K x 8K texture.
1383 * XXX this could be rolled into the proxy texture size test (above) but
1384 * we don't have the actual texture internal format at that point.
1387 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1388 GLint width
, GLint height
, GLint depth
)
1390 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1391 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1392 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1397 * Return true if the format is only valid for glCompressedTexImage.
1400 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1403 case GL_ETC1_RGB8_OES
:
1412 * Helper function to determine whether a target and specific compression
1413 * format are supported.
1416 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1419 (void) intFormat
; /* not used yet */
1423 case GL_PROXY_TEXTURE_2D
:
1424 return GL_TRUE
; /* true for any compressed format so far */
1425 case GL_PROXY_TEXTURE_CUBE_MAP
:
1426 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1427 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1428 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1429 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1430 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1431 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1432 return ctx
->Extensions
.ARB_texture_cube_map
;
1433 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1434 case GL_TEXTURE_2D_ARRAY_EXT
:
1435 return (ctx
->Extensions
.MESA_texture_array
||
1436 ctx
->Extensions
.EXT_texture_array
);
1444 * Check if the given texture target value is legal for a
1445 * glTexImage1/2/3D call.
1448 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1454 case GL_PROXY_TEXTURE_1D
:
1462 case GL_PROXY_TEXTURE_2D
:
1464 case GL_PROXY_TEXTURE_CUBE_MAP
:
1465 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1466 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1467 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1468 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1469 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1470 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1471 return ctx
->Extensions
.ARB_texture_cube_map
;
1472 case GL_TEXTURE_RECTANGLE_NV
:
1473 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1474 return ctx
->Extensions
.NV_texture_rectangle
;
1475 case GL_TEXTURE_1D_ARRAY_EXT
:
1476 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1477 return (ctx
->Extensions
.MESA_texture_array
||
1478 ctx
->Extensions
.EXT_texture_array
);
1485 case GL_PROXY_TEXTURE_3D
:
1487 case GL_TEXTURE_2D_ARRAY_EXT
:
1488 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1489 return (ctx
->Extensions
.MESA_texture_array
||
1490 ctx
->Extensions
.EXT_texture_array
);
1495 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1502 * Check if the given texture target value is legal for a
1503 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1504 * The difference compared to legal_teximage_target() above is that
1505 * proxy targets are not supported.
1508 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1512 return target
== GL_TEXTURE_1D
;
1517 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1518 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1519 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1520 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1521 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1522 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1523 return ctx
->Extensions
.ARB_texture_cube_map
;
1524 case GL_TEXTURE_RECTANGLE_NV
:
1525 return ctx
->Extensions
.NV_texture_rectangle
;
1526 case GL_TEXTURE_1D_ARRAY_EXT
:
1527 return (ctx
->Extensions
.MESA_texture_array
||
1528 ctx
->Extensions
.EXT_texture_array
);
1536 case GL_TEXTURE_2D_ARRAY_EXT
:
1537 return (ctx
->Extensions
.MESA_texture_array
||
1538 ctx
->Extensions
.EXT_texture_array
);
1543 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1551 * Helper function to determine if a texture object is mutable (in terms
1552 * of GL_ARB_texture_storage).
1555 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1557 if (ctx
->Extensions
.ARB_texture_storage
) {
1558 struct gl_texture_object
*texObj
=
1559 _mesa_get_current_tex_object(ctx
, target
);
1560 return !texObj
->Immutable
;
1568 * Test the glTexImage[123]D() parameters for errors.
1570 * \param ctx GL context.
1571 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1572 * \param target texture target given by the user.
1573 * \param level image level given by the user.
1574 * \param internalFormat internal format given by the user.
1575 * \param format pixel data format given by the user.
1576 * \param type pixel data type given by the user.
1577 * \param width image width given by the user.
1578 * \param height image height given by the user.
1579 * \param depth image depth given by the user.
1580 * \param border image border given by the user.
1582 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1584 * Verifies each of the parameters against the constants specified in
1585 * __struct gl_contextRec::Const and the supported extensions, and according
1586 * to the OpenGL specification.
1589 texture_error_check( struct gl_context
*ctx
,
1590 GLuint dimensions
, GLenum target
,
1591 GLint level
, GLint internalFormat
,
1592 GLenum format
, GLenum type
,
1593 GLint width
, GLint height
,
1594 GLint depth
, GLint border
)
1596 const GLenum proxyTarget
= get_proxy_target(target
);
1597 const GLboolean isProxy
= target
== proxyTarget
;
1598 GLboolean sizeOK
= GL_TRUE
;
1599 GLboolean colorFormat
;
1602 /* Even though there are no color-index textures, we still have to support
1603 * uploading color-index data and remapping it to RGB via the
1604 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1606 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1608 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1609 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1611 _mesa_error(ctx
, GL_INVALID_VALUE
,
1612 "glTexImage%dD(level=%d)", dimensions
, level
);
1618 if (border
< 0 || border
> 1 ||
1619 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1620 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1622 _mesa_error(ctx
, GL_INVALID_VALUE
,
1623 "glTexImage%dD(border=%d)", dimensions
, border
);
1628 if (width
< 0 || height
< 0 || depth
< 0) {
1630 _mesa_error(ctx
, GL_INVALID_VALUE
,
1631 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1636 /* Do this simple check before calling the TestProxyTexImage() function */
1637 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1638 sizeOK
= (width
== height
);
1642 * Use the proxy texture driver hook to see if the size/level/etc are
1645 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1646 internalFormat
, format
,
1647 type
, width
, height
,
1651 _mesa_error(ctx
, GL_INVALID_VALUE
,
1652 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1653 dimensions
, level
, width
, height
, depth
);
1658 /* Check internalFormat */
1659 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1661 _mesa_error(ctx
, GL_INVALID_VALUE
,
1662 "glTexImage%dD(internalFormat=%s)",
1663 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1668 /* Check incoming image format and type */
1669 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1670 if (err
!= GL_NO_ERROR
) {
1672 _mesa_error(ctx
, err
,
1673 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1674 dimensions
, format
, type
);
1679 /* make sure internal format and format basically agree */
1680 colorFormat
= _mesa_is_color_format(format
);
1681 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1682 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1683 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1684 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1685 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1687 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1688 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1689 dimensions
, internalFormat
, format
);
1693 /* additional checks for ycbcr textures */
1694 if (internalFormat
== GL_YCBCR_MESA
) {
1695 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1696 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1697 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1699 _mesa_snprintf(message
, sizeof(message
),
1700 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1701 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1702 return GL_TRUE
; /* error */
1704 if (target
!= GL_TEXTURE_2D
&&
1705 target
!= GL_PROXY_TEXTURE_2D
&&
1706 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1707 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1709 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1715 _mesa_snprintf(message
, sizeof(message
),
1716 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1717 dimensions
, border
);
1718 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1724 /* additional checks for depth textures */
1725 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1726 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1727 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1728 if (target
!= GL_TEXTURE_1D
&&
1729 target
!= GL_PROXY_TEXTURE_1D
&&
1730 target
!= GL_TEXTURE_2D
&&
1731 target
!= GL_PROXY_TEXTURE_2D
&&
1732 target
!= GL_TEXTURE_1D_ARRAY
&&
1733 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1734 target
!= GL_TEXTURE_2D_ARRAY
&&
1735 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1736 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1737 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1738 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1739 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
))) {
1741 _mesa_error(ctx
, GL_INVALID_ENUM
,
1742 "glTexImage(target/internalFormat)");
1747 /* additional checks for compressed textures */
1748 if (_mesa_is_compressed_format(ctx
, internalFormat
) ||
1749 is_generic_compressed_format(internalFormat
)) {
1750 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1752 _mesa_error(ctx
, GL_INVALID_ENUM
,
1753 "glTexImage%dD(target)", dimensions
);
1756 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1757 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1758 "glTexImage%dD(no compression for format)", dimensions
);
1763 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1764 "glTexImage%dD(border!=0)", dimensions
);
1770 /* additional checks for integer textures */
1771 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
1772 (_mesa_is_enum_format_integer(format
) !=
1773 _mesa_is_enum_format_integer(internalFormat
))) {
1775 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1776 "glTexImage%dD(integer/non-integer format mismatch)",
1782 if (!mutable_tex_object(ctx
, target
)) {
1783 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1784 "glTexImage%dD(immutable texture)", dimensions
);
1788 /* if we get here, the parameters are OK */
1794 * Test glTexSubImage[123]D() parameters for errors.
1796 * \param ctx GL context.
1797 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1798 * \param target texture target given by the user.
1799 * \param level image level given by the user.
1800 * \param xoffset sub-image x offset given by the user.
1801 * \param yoffset sub-image y offset given by the user.
1802 * \param zoffset sub-image z offset given by the user.
1803 * \param format pixel data format given by the user.
1804 * \param type pixel data type given by the user.
1805 * \param width image width given by the user.
1806 * \param height image height given by the user.
1807 * \param depth image depth given by the user.
1809 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1811 * Verifies each of the parameters against the constants specified in
1812 * __struct gl_contextRec::Const and the supported extensions, and according
1813 * to the OpenGL specification.
1816 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1817 GLenum target
, GLint level
,
1818 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1819 GLint width
, GLint height
, GLint depth
,
1820 GLenum format
, GLenum type
)
1824 /* Basic level check */
1825 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1826 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1830 /* Check for negative sizes */
1832 _mesa_error(ctx
, GL_INVALID_VALUE
,
1833 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1836 if (height
< 0 && dimensions
> 1) {
1837 _mesa_error(ctx
, GL_INVALID_VALUE
,
1838 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1841 if (depth
< 0 && dimensions
> 2) {
1842 _mesa_error(ctx
, GL_INVALID_VALUE
,
1843 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1847 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1848 if (err
!= GL_NO_ERROR
) {
1849 _mesa_error(ctx
, err
,
1850 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1851 dimensions
, format
, type
);
1860 * Do second part of glTexSubImage which depends on the destination texture.
1861 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1864 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1865 GLenum target
, GLint level
,
1866 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1867 GLint width
, GLint height
, GLint depth
,
1868 GLenum format
, GLenum type
,
1869 const struct gl_texture_image
*destTex
)
1872 /* undefined image level */
1873 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1877 if (xoffset
< -((GLint
)destTex
->Border
)) {
1878 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1882 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1883 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1887 if (dimensions
> 1) {
1888 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destTex
->Border
;
1889 if (yoffset
< -yBorder
) {
1890 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1894 if (yoffset
+ height
> (GLint
) destTex
->Height
+ yBorder
) {
1895 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1900 if (dimensions
> 2) {
1901 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destTex
->Border
;
1902 if (zoffset
< -zBorder
) {
1903 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1906 if (zoffset
+ depth
> (GLint
) destTex
->Depth
+ zBorder
) {
1907 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1912 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1915 if (compressedteximage_only_format(ctx
, destTex
->InternalFormat
)) {
1916 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1917 "glTexSubImage%dD(no compression for format)", dimensions
);
1921 /* do tests which depend on compression block size */
1922 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1924 /* offset must be multiple of block size */
1925 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1926 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1927 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1928 dimensions
, xoffset
, yoffset
);
1931 /* size must be multiple of bw by bh or equal to whole texture size */
1932 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1933 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1934 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1937 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1938 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1939 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1944 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
1945 /* both source and dest must be integer-valued, or neither */
1946 if (_mesa_is_format_integer_color(destTex
->TexFormat
) !=
1947 _mesa_is_enum_format_integer(format
)) {
1948 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1949 "glTexSubImage%dD(integer/non-integer format mismatch)",
1960 * Test glCopyTexImage[12]D() parameters for errors.
1962 * \param ctx GL context.
1963 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1964 * \param target texture target given by the user.
1965 * \param level image level given by the user.
1966 * \param internalFormat internal format given by the user.
1967 * \param width image width given by the user.
1968 * \param height image height given by the user.
1969 * \param border texture border.
1971 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1973 * Verifies each of the parameters against the constants specified in
1974 * __struct gl_contextRec::Const and the supported extensions, and according
1975 * to the OpenGL specification.
1978 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1979 GLenum target
, GLint level
, GLint internalFormat
,
1980 GLint width
, GLint height
, GLint border
)
1982 const GLenum proxyTarget
= get_proxy_target(target
);
1983 const GLenum type
= GL_FLOAT
;
1988 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1989 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1990 dimensions
, _mesa_lookup_enum_by_nr(target
));
1994 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1995 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1996 _mesa_error(ctx
, GL_INVALID_VALUE
,
1997 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2001 /* Check that the source buffer is complete */
2002 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2003 if (ctx
->ReadBuffer
->_Status
== 0) {
2004 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2006 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2007 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2008 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2012 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2013 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2014 "glCopyTexImage%dD(multisample FBO)",
2021 if (border
< 0 || border
> 1 ||
2022 ((target
== GL_TEXTURE_RECTANGLE_NV
||
2023 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2027 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2028 if (baseFormat
< 0) {
2029 _mesa_error(ctx
, GL_INVALID_VALUE
,
2030 "glCopyTexImage%dD(internalFormat)", dimensions
);
2034 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2035 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2036 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2040 /* From the EXT_texture_integer spec:
2042 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2043 * if the texture internalformat is an integer format and the read color
2044 * buffer is not an integer format, or if the internalformat is not an
2045 * integer format and the read color buffer is an integer format."
2047 if (_mesa_is_color_format(internalFormat
)) {
2048 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2050 if (_mesa_is_enum_format_integer(rb
->InternalFormat
) !=
2051 _mesa_is_enum_format_integer(internalFormat
)) {
2052 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2053 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2058 /* Do size, level checking */
2059 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
2060 ? (width
== height
) : 1;
2062 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
2063 internalFormat
, baseFormat
,
2064 type
, width
, height
,
2068 if (dimensions
== 1) {
2069 _mesa_error(ctx
, GL_INVALID_VALUE
,
2070 "glCopyTexImage1D(width=%d)", width
);
2073 ASSERT(dimensions
== 2);
2074 _mesa_error(ctx
, GL_INVALID_VALUE
,
2075 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2080 if (_mesa_is_compressed_format(ctx
, internalFormat
) ||
2081 is_generic_compressed_format(internalFormat
)) {
2082 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2083 _mesa_error(ctx
, GL_INVALID_ENUM
,
2084 "glCopyTexImage%dD(target)", dimensions
);
2087 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2088 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2089 "glCopyTexImage%dD(no compression for format)", dimensions
);
2093 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2094 "glCopyTexImage%dD(border!=0)", dimensions
);
2099 if (!mutable_tex_object(ctx
, target
)) {
2100 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2101 "glCopyTexImage%dD(immutable texture)", dimensions
);
2105 /* if we get here, the parameters are OK */
2111 * Test glCopyTexSubImage[12]D() parameters for errors.
2112 * Note that this is the first part of error checking.
2113 * See also copytexsubimage_error_check2() below for the second part.
2115 * \param ctx GL context.
2116 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2117 * \param target texture target given by the user.
2118 * \param level image level given by the user.
2120 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2123 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2124 GLenum target
, GLint level
)
2126 /* Check that the source buffer is complete */
2127 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2128 if (ctx
->ReadBuffer
->_Status
== 0) {
2129 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2131 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2132 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2133 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2137 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2138 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2139 "glCopyTexSubImage%dD(multisample FBO)",
2145 /* check target (proxies not allowed) */
2146 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2147 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2148 dimensions
, _mesa_lookup_enum_by_nr(target
));
2153 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2154 _mesa_error(ctx
, GL_INVALID_VALUE
,
2155 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2164 * Second part of error checking for glCopyTexSubImage[12]D().
2165 * \param xoffset sub-image x offset given by the user.
2166 * \param yoffset sub-image y offset given by the user.
2167 * \param zoffset sub-image z offset given by the user.
2168 * \param width image width given by the user.
2169 * \param height image height given by the user.
2172 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2173 GLenum target
, GLint level
,
2174 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2175 GLsizei width
, GLsizei height
,
2176 const struct gl_texture_image
*teximage
)
2178 /* check that dest tex image exists */
2180 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2181 "glCopyTexSubImage%dD(undefined texture level: %d)",
2188 _mesa_error(ctx
, GL_INVALID_VALUE
,
2189 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2192 if (dimensions
> 1 && height
< 0) {
2193 _mesa_error(ctx
, GL_INVALID_VALUE
,
2194 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2198 /* check x/y offsets */
2199 if (xoffset
< -((GLint
)teximage
->Border
)) {
2200 _mesa_error(ctx
, GL_INVALID_VALUE
,
2201 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2204 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2205 _mesa_error(ctx
, GL_INVALID_VALUE
,
2206 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2209 if (dimensions
> 1) {
2210 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : teximage
->Border
;
2211 if (yoffset
< -yBorder
) {
2212 _mesa_error(ctx
, GL_INVALID_VALUE
,
2213 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2216 /* NOTE: we're adding the border here, not subtracting! */
2217 if (yoffset
+ height
> (GLint
) teximage
->Height
+ yBorder
) {
2218 _mesa_error(ctx
, GL_INVALID_VALUE
,
2219 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2224 /* check z offset */
2225 if (dimensions
> 2) {
2226 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : teximage
->Border
;
2227 if (zoffset
< -zBorder
) {
2228 _mesa_error(ctx
, GL_INVALID_VALUE
,
2229 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2232 if (zoffset
> (GLint
) teximage
->Depth
+ zBorder
) {
2233 _mesa_error(ctx
, GL_INVALID_VALUE
,
2234 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2239 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2240 if (compressedteximage_only_format(ctx
, teximage
->InternalFormat
)) {
2241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2242 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2245 /* offset must be multiple of 4 */
2246 if ((xoffset
& 3) || (yoffset
& 3)) {
2247 _mesa_error(ctx
, GL_INVALID_VALUE
,
2248 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2251 /* size must be multiple of 4 */
2252 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2253 _mesa_error(ctx
, GL_INVALID_VALUE
,
2254 "glCopyTexSubImage%dD(width)", dimensions
);
2257 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2258 _mesa_error(ctx
, GL_INVALID_VALUE
,
2259 "glCopyTexSubImage%dD(height)", dimensions
);
2264 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2265 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2269 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2270 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2271 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2272 dimensions
, teximage
->_BaseFormat
);
2276 /* From the EXT_texture_integer spec:
2278 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2279 * if the texture internalformat is an integer format and the read color
2280 * buffer is not an integer format, or if the internalformat is not an
2281 * integer format and the read color buffer is an integer format."
2283 if (_mesa_is_color_format(teximage
->InternalFormat
)) {
2284 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2286 if (_mesa_is_format_integer_color(rb
->Format
) !=
2287 _mesa_is_format_integer_color(teximage
->TexFormat
)) {
2288 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2289 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2294 /* if we get here, the parameters are OK */
2299 /** Callback info for walking over FBO hash table */
2302 struct gl_context
*ctx
;
2303 struct gl_texture_object
*texObj
;
2309 * Check render to texture callback. Called from _mesa_HashWalk().
2312 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2314 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2315 const struct cb_info
*info
= (struct cb_info
*) userData
;
2316 struct gl_context
*ctx
= info
->ctx
;
2317 const struct gl_texture_object
*texObj
= info
->texObj
;
2318 const GLuint level
= info
->level
, face
= info
->face
;
2320 /* If this is a user-created FBO */
2321 if (_mesa_is_user_fbo(fb
)) {
2323 /* check if any of the FBO's attachments point to 'texObj' */
2324 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2325 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2326 if (att
->Type
== GL_TEXTURE
&&
2327 att
->Texture
== texObj
&&
2328 att
->TextureLevel
== level
&&
2329 att
->CubeMapFace
== face
) {
2330 ASSERT(_mesa_get_attachment_teximage(att
));
2331 /* Tell driver about the new renderbuffer texture */
2332 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2333 /* Mark fb status as indeterminate to force re-validation */
2342 * When a texture image is specified we have to check if it's bound to
2343 * any framebuffer objects (render to texture) in order to detect changes
2344 * in size or format since that effects FBO completeness.
2345 * Any FBOs rendering into the texture must be re-validated.
2348 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2349 struct gl_texture_object
*texObj
,
2350 GLuint face
, GLuint level
)
2352 /* Only check this texture if it's been marked as RenderToTexture */
2353 if (texObj
->_RenderToTexture
) {
2354 struct cb_info info
;
2356 info
.texObj
= texObj
;
2359 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2365 * If the texture object's GenerateMipmap flag is set and we've
2366 * changed the texture base level image, regenerate the rest of the
2367 * mipmap levels now.
2370 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2371 struct gl_texture_object
*texObj
, GLint level
)
2373 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2374 if (texObj
->GenerateMipmap
&&
2375 level
== texObj
->BaseLevel
&&
2376 level
< texObj
->MaxLevel
) {
2377 ASSERT(ctx
->Driver
.GenerateMipmap
);
2378 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2383 /** Debug helper: override the user-requested internal format */
2385 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2388 if (internalFormat
== GL_RGBA16F_ARB
||
2389 internalFormat
== GL_RGBA32F_ARB
) {
2390 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2393 else if (internalFormat
== GL_RGB16F_ARB
||
2394 internalFormat
== GL_RGB32F_ARB
) {
2395 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2398 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2399 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2400 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2401 return GL_LUMINANCE_ALPHA
;
2403 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2404 internalFormat
== GL_LUMINANCE32F_ARB
) {
2405 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2406 return GL_LUMINANCE
;
2408 else if (internalFormat
== GL_ALPHA16F_ARB
||
2409 internalFormat
== GL_ALPHA32F_ARB
) {
2410 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2414 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2415 internalFormat = GL_RGBA;
2419 return internalFormat
;
2422 return internalFormat
;
2428 * Choose the actual hardware format for a texture image.
2429 * Try to use the same format as the previous image level when possible.
2430 * Otherwise, ask the driver for the best format.
2431 * It's important to try to choose a consistant format for all levels
2432 * for efficient texture memory layout/allocation. In particular, this
2433 * comes up during automatic mipmap generation.
2436 _mesa_choose_texture_format(struct gl_context
*ctx
,
2437 struct gl_texture_object
*texObj
,
2438 GLenum target
, GLint level
,
2439 GLenum internalFormat
, GLenum format
, GLenum type
)
2443 /* see if we've already chosen a format for the previous level */
2445 struct gl_texture_image
*prevImage
=
2446 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2447 /* See if the prev level is defined and has an internal format which
2448 * matches the new internal format.
2451 prevImage
->Width
> 0 &&
2452 prevImage
->InternalFormat
== internalFormat
) {
2453 /* use the same format */
2454 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2455 return prevImage
->TexFormat
;
2459 /* choose format from scratch */
2460 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2461 ASSERT(f
!= MESA_FORMAT_NONE
);
2466 * Adjust pixel unpack params and image dimensions to strip off the
2467 * one-pixel texture border.
2469 * Gallium and intel don't support texture borders. They've seldem been used
2470 * and seldom been implemented correctly anyway.
2472 * \param unpackNew returns the new pixel unpack parameters
2475 strip_texture_border(GLenum target
,
2476 GLint
*width
, GLint
*height
, GLint
*depth
,
2477 const struct gl_pixelstore_attrib
*unpack
,
2478 struct gl_pixelstore_attrib
*unpackNew
)
2484 *unpackNew
= *unpack
;
2486 if (unpackNew
->RowLength
== 0)
2487 unpackNew
->RowLength
= *width
;
2489 if (unpackNew
->ImageHeight
== 0)
2490 unpackNew
->ImageHeight
= *height
;
2492 assert(*width
>= 3);
2493 unpackNew
->SkipPixels
++; /* skip the border */
2494 *width
= *width
- 2; /* reduce the width by two border pixels */
2496 /* The min height of a texture with a border is 3 */
2497 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2498 unpackNew
->SkipRows
++; /* skip the border */
2499 *height
= *height
- 2; /* reduce the height by two border pixels */
2502 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
) {
2503 unpackNew
->SkipImages
++; /* skip the border */
2504 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2509 * Common code to implement all the glTexImage1D/2D/3D functions.
2512 teximage(struct gl_context
*ctx
, GLuint dims
,
2513 GLenum target
, GLint level
, GLint internalFormat
,
2514 GLsizei width
, GLsizei height
, GLsizei depth
,
2515 GLint border
, GLenum format
, GLenum type
,
2516 const GLvoid
*pixels
)
2519 struct gl_pixelstore_attrib unpack_no_border
;
2520 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2522 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2524 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2525 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2527 _mesa_lookup_enum_by_nr(target
), level
,
2528 _mesa_lookup_enum_by_nr(internalFormat
),
2529 width
, height
, depth
, border
,
2530 _mesa_lookup_enum_by_nr(format
),
2531 _mesa_lookup_enum_by_nr(type
), pixels
);
2533 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2535 /* target error checking */
2536 if (!legal_teximage_target(ctx
, dims
, target
)) {
2537 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2538 dims
, _mesa_lookup_enum_by_nr(target
));
2542 /* general error checking */
2543 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2544 format
, type
, width
, height
, depth
, border
);
2546 if (_mesa_is_proxy_texture(target
)) {
2547 /* Proxy texture: just clear or set state depending on error checking */
2548 struct gl_texture_image
*texImage
=
2549 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2552 /* when error, clear all proxy texture image parameters */
2554 clear_teximage_fields(texImage
);
2557 /* no error, set the tex image parameters */
2558 struct gl_texture_object
*texObj
=
2559 _mesa_get_current_tex_object(ctx
, target
);
2560 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2565 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2566 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
2567 depth
, border
, internalFormat
,
2570 else if (texImage
) {
2571 clear_teximage_fields(texImage
);
2576 /* non-proxy target */
2577 const GLuint face
= _mesa_tex_target_to_face(target
);
2578 struct gl_texture_object
*texObj
;
2579 struct gl_texture_image
*texImage
;
2582 return; /* error was recorded */
2585 /* Allow a hardware driver to just strip out the border, to provide
2586 * reliable but slightly incorrect hardware rendering instead of
2587 * rarely-tested software fallback rendering.
2589 if (border
&& ctx
->Const
.StripTextureBorder
) {
2590 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
2593 unpack
= &unpack_no_border
;
2596 if (ctx
->NewState
& _NEW_PIXEL
)
2597 _mesa_update_state(ctx
);
2599 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2601 _mesa_lock_texture(ctx
, texObj
);
2603 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2606 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2609 gl_format texFormat
;
2611 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2613 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2614 internalFormat
, format
,
2617 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2618 _mesa_init_teximage_fields(ctx
, texImage
,
2619 width
, height
, depth
,
2620 border
, internalFormat
, texFormat
);
2622 /* Give the texture to the driver. <pixels> may be null. */
2623 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
2624 type
, pixels
, unpack
);
2626 check_gen_mipmap(ctx
, target
, texObj
, level
);
2628 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2630 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2633 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2637 _mesa_unlock_texture(ctx
, texObj
);
2643 * Called from the API. Note that width includes the border.
2646 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2647 GLsizei width
, GLint border
, GLenum format
,
2648 GLenum type
, const GLvoid
*pixels
)
2650 GET_CURRENT_CONTEXT(ctx
);
2651 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2652 border
, format
, type
, pixels
);
2657 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2658 GLsizei width
, GLsizei height
, GLint border
,
2659 GLenum format
, GLenum type
,
2660 const GLvoid
*pixels
)
2662 GET_CURRENT_CONTEXT(ctx
);
2663 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2664 border
, format
, type
, pixels
);
2669 * Called by the API or display list executor.
2670 * Note that width and height include the border.
2673 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2674 GLsizei width
, GLsizei height
, GLsizei depth
,
2675 GLint border
, GLenum format
, GLenum type
,
2676 const GLvoid
*pixels
)
2678 GET_CURRENT_CONTEXT(ctx
);
2679 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2680 border
, format
, type
, pixels
);
2685 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2686 GLsizei width
, GLsizei height
, GLsizei depth
,
2687 GLint border
, GLenum format
, GLenum type
,
2688 const GLvoid
*pixels
)
2690 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2691 depth
, border
, format
, type
, pixels
);
2695 #if FEATURE_OES_EGL_image
2697 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2699 struct gl_texture_object
*texObj
;
2700 struct gl_texture_image
*texImage
;
2701 GET_CURRENT_CONTEXT(ctx
);
2702 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2704 if ((target
== GL_TEXTURE_2D
&&
2705 !ctx
->Extensions
.OES_EGL_image
) ||
2706 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2707 !ctx
->Extensions
.OES_EGL_image_external
)) {
2708 _mesa_error(ctx
, GL_INVALID_ENUM
,
2709 "glEGLImageTargetTexture2D(target=%d)", target
);
2713 if (ctx
->NewState
& _NEW_PIXEL
)
2714 _mesa_update_state(ctx
);
2716 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2717 _mesa_lock_texture(ctx
, texObj
);
2719 if (texObj
->Immutable
) {
2720 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2721 "glEGLImageTargetTexture2D(texture is immutable)");
2722 _mesa_unlock_texture(ctx
, texObj
);
2726 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2728 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2730 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2732 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2733 texObj
, texImage
, image
);
2735 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2737 _mesa_unlock_texture(ctx
, texObj
);
2745 * Implement all the glTexSubImage1/2/3D() functions.
2748 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2749 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2750 GLsizei width
, GLsizei height
, GLsizei depth
,
2751 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2753 struct gl_texture_object
*texObj
;
2754 struct gl_texture_image
*texImage
;
2756 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2758 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2759 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2761 _mesa_lookup_enum_by_nr(target
), level
,
2762 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2763 _mesa_lookup_enum_by_nr(format
),
2764 _mesa_lookup_enum_by_nr(type
), pixels
);
2766 /* check target (proxies not allowed) */
2767 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2768 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2769 dims
, _mesa_lookup_enum_by_nr(target
));
2773 if (ctx
->NewState
& _NEW_PIXEL
)
2774 _mesa_update_state(ctx
);
2776 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2777 width
, height
, depth
, format
, type
)) {
2778 return; /* error was detected */
2781 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2783 _mesa_lock_texture(ctx
, texObj
);
2785 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2787 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2788 xoffset
, yoffset
, zoffset
,
2789 width
, height
, depth
,
2790 format
, type
, texImage
)) {
2791 /* error was recorded */
2793 else if (width
> 0 && height
> 0 && depth
> 0) {
2794 /* If we have a border, offset=-1 is legal. Bias by border width. */
2797 if (target
!= GL_TEXTURE_2D_ARRAY
)
2798 zoffset
+= texImage
->Border
;
2801 if (target
!= GL_TEXTURE_1D_ARRAY
)
2802 yoffset
+= texImage
->Border
;
2805 xoffset
+= texImage
->Border
;
2808 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
2809 xoffset
, yoffset
, zoffset
,
2810 width
, height
, depth
,
2811 format
, type
, pixels
, &ctx
->Unpack
);
2813 check_gen_mipmap(ctx
, target
, texObj
, level
);
2815 ctx
->NewState
|= _NEW_TEXTURE
;
2818 _mesa_unlock_texture(ctx
, texObj
);
2823 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2824 GLint xoffset
, GLsizei width
,
2825 GLenum format
, GLenum type
,
2826 const GLvoid
*pixels
)
2828 GET_CURRENT_CONTEXT(ctx
);
2829 texsubimage(ctx
, 1, target
, level
,
2832 format
, type
, pixels
);
2837 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2838 GLint xoffset
, GLint yoffset
,
2839 GLsizei width
, GLsizei height
,
2840 GLenum format
, GLenum type
,
2841 const GLvoid
*pixels
)
2843 GET_CURRENT_CONTEXT(ctx
);
2844 texsubimage(ctx
, 2, target
, level
,
2845 xoffset
, yoffset
, 0,
2847 format
, type
, pixels
);
2853 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2854 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2855 GLsizei width
, GLsizei height
, GLsizei depth
,
2856 GLenum format
, GLenum type
,
2857 const GLvoid
*pixels
)
2859 GET_CURRENT_CONTEXT(ctx
);
2860 texsubimage(ctx
, 3, target
, level
,
2861 xoffset
, yoffset
, zoffset
,
2862 width
, height
, depth
,
2863 format
, type
, pixels
);
2869 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
2870 * from. This depends on whether the texture contains color or depth values.
2872 static struct gl_renderbuffer
*
2873 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
2875 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
2876 /* reading from depth/stencil buffer */
2877 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
2880 /* copying from color buffer */
2881 return ctx
->ReadBuffer
->_ColorReadBuffer
;
2888 * Implement the glCopyTexImage1/2D() functions.
2891 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2892 GLenum target
, GLint level
, GLenum internalFormat
,
2893 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2895 struct gl_texture_object
*texObj
;
2896 struct gl_texture_image
*texImage
;
2897 const GLuint face
= _mesa_tex_target_to_face(target
);
2899 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2901 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2902 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2904 _mesa_lookup_enum_by_nr(target
), level
,
2905 _mesa_lookup_enum_by_nr(internalFormat
),
2906 x
, y
, width
, height
, border
);
2908 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2909 _mesa_update_state(ctx
);
2911 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2912 width
, height
, border
))
2915 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2917 if (border
&& ctx
->Const
.StripTextureBorder
) {
2919 width
-= border
* 2;
2922 height
-= border
* 2;
2927 _mesa_lock_texture(ctx
, texObj
);
2929 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2932 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2935 /* choose actual hw format */
2936 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2941 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2942 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
2944 /* Free old texture image */
2945 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2947 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
2948 border
, internalFormat
, texFormat
);
2950 /* Allocate texture memory (no pixel data yet) */
2951 ctx
->Driver
.TexImage(ctx
, dims
, texImage
,
2953 NULL
, &ctx
->Unpack
);
2955 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2957 struct gl_renderbuffer
*srcRb
=
2958 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
2960 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
2961 srcRb
, srcX
, srcY
, width
, height
);
2964 check_gen_mipmap(ctx
, target
, texObj
, level
);
2966 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2968 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2971 /* probably too large of image */
2972 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2976 _mesa_unlock_texture(ctx
, texObj
);
2982 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2983 GLenum internalFormat
,
2985 GLsizei width
, GLint border
)
2987 GET_CURRENT_CONTEXT(ctx
);
2988 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2994 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2995 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2998 GET_CURRENT_CONTEXT(ctx
);
2999 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3000 x
, y
, width
, height
, border
);
3006 * Implementation for glCopyTexSubImage1/2/3D() functions.
3009 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3010 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3011 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3013 struct gl_texture_object
*texObj
;
3014 struct gl_texture_image
*texImage
;
3016 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3018 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3019 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3021 _mesa_lookup_enum_by_nr(target
),
3022 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3024 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3025 _mesa_update_state(ctx
);
3027 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
3030 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3032 _mesa_lock_texture(ctx
, texObj
);
3034 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3036 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
3037 zoffset
, width
, height
, texImage
)) {
3038 /* error was recored */
3041 /* If we have a border, offset=-1 is legal. Bias by border width. */
3044 if (target
!= GL_TEXTURE_2D_ARRAY
)
3045 zoffset
+= texImage
->Border
;
3048 if (target
!= GL_TEXTURE_1D_ARRAY
)
3049 yoffset
+= texImage
->Border
;
3052 xoffset
+= texImage
->Border
;
3055 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3057 struct gl_renderbuffer
*srcRb
=
3058 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3060 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3061 xoffset
, yoffset
, zoffset
,
3062 srcRb
, x
, y
, width
, height
);
3064 check_gen_mipmap(ctx
, target
, texObj
, level
);
3066 ctx
->NewState
|= _NEW_TEXTURE
;
3070 _mesa_unlock_texture(ctx
, texObj
);
3075 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3076 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3078 GET_CURRENT_CONTEXT(ctx
);
3079 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3085 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3086 GLint xoffset
, GLint yoffset
,
3087 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3089 GET_CURRENT_CONTEXT(ctx
);
3090 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3097 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3098 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3099 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3101 GET_CURRENT_CONTEXT(ctx
);
3102 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3103 x
, y
, width
, height
);
3109 /**********************************************************************/
3110 /****** Compressed Textures ******/
3111 /**********************************************************************/
3115 * Return expected size of a compressed texture.
3118 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3121 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3122 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3127 * Return compressed texture block size, in pixels.
3130 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3132 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3133 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3138 * Error checking for glCompressedTexImage[123]D().
3139 * \param reason returns reason for error, if any
3140 * \return error code or GL_NO_ERROR.
3143 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3144 GLenum target
, GLint level
,
3145 GLenum internalFormat
, GLsizei width
,
3146 GLsizei height
, GLsizei depth
, GLint border
,
3147 GLsizei imageSize
, char **reason
)
3149 const GLenum proxyTarget
= get_proxy_target(target
);
3150 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3152 GLenum choose_format
;
3154 GLenum proxy_format
;
3156 *reason
= ""; /* no error */
3158 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3160 return GL_INVALID_ENUM
;
3163 /* This will detect any invalid internalFormat value */
3164 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3165 *reason
= "internalFormat";
3166 return GL_INVALID_ENUM
;
3169 switch (internalFormat
) {
3171 case GL_PALETTE4_RGB8_OES
:
3172 case GL_PALETTE4_RGBA8_OES
:
3173 case GL_PALETTE4_R5_G6_B5_OES
:
3174 case GL_PALETTE4_RGBA4_OES
:
3175 case GL_PALETTE4_RGB5_A1_OES
:
3176 case GL_PALETTE8_RGB8_OES
:
3177 case GL_PALETTE8_RGBA8_OES
:
3178 case GL_PALETTE8_R5_G6_B5_OES
:
3179 case GL_PALETTE8_RGBA4_OES
:
3180 case GL_PALETTE8_RGB5_A1_OES
:
3181 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3183 proxy_format
= choose_format
;
3186 if (level
> 0 || level
< -maxLevels
) {
3188 return GL_INVALID_VALUE
;
3191 if (dimensions
!= 2) {
3192 *reason
= "compressed paletted textures must be 2D";
3193 return GL_INVALID_OPERATION
;
3196 /* Figure out the expected texture size (in bytes). This will be
3197 * checked against the actual size later.
3199 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3202 /* This is for the benefit of the TestProxyTexImage below. It expects
3203 * level to be non-negative. OES_compressed_paletted_texture uses a
3204 * weird mechanism where the level specified to glCompressedTexImage2D
3205 * is -(n-1) number of levels in the texture, and the data specifies the
3206 * complete mipmap stack. This is done to ensure the palette is the
3207 * same for all levels.
3214 choose_format
= GL_NONE
;
3215 choose_type
= GL_NONE
;
3216 proxy_format
= internalFormat
;
3219 if (level
< 0 || level
>= maxLevels
) {
3221 return GL_INVALID_VALUE
;
3224 /* Figure out the expected texture size (in bytes). This will be
3225 * checked against the actual size later.
3227 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3231 /* This should really never fail */
3232 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3233 *reason
= "internalFormat";
3234 return GL_INVALID_ENUM
;
3237 /* No compressed formats support borders at this time */
3239 *reason
= "border != 0";
3240 return GL_INVALID_VALUE
;
3243 /* For cube map, width must equal height */
3244 if (_mesa_is_cube_face(target
) && width
!= height
) {
3245 *reason
= "width != height";
3246 return GL_INVALID_VALUE
;
3249 /* check image size against compression block size */
3251 gl_format texFormat
=
3252 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3253 choose_format
, choose_type
);
3256 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3257 if ((width
> bw
&& width
% bw
> 0) ||
3258 (height
> bh
&& height
% bh
> 0)) {
3260 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3261 * generated [...] if any parameter combinations are not
3262 * supported by the specific compressed internal format.
3264 *reason
= "invalid width or height for compression format";
3265 return GL_INVALID_OPERATION
;
3269 /* check image sizes */
3270 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3271 proxy_format
, choose_format
,
3273 width
, height
, depth
, border
)) {
3274 /* See error comment above */
3275 *reason
= "invalid width, height or format";
3276 return GL_INVALID_OPERATION
;
3279 /* check image size in bytes */
3280 if (expectedSize
!= imageSize
) {
3281 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3282 * if <imageSize> is not consistent with the format, dimensions, and
3283 * contents of the specified image.
3285 *reason
= "imageSize inconsistant with width/height/format";
3286 return GL_INVALID_VALUE
;
3289 if (!mutable_tex_object(ctx
, target
)) {
3290 *reason
= "immutable texture";
3291 return GL_INVALID_OPERATION
;
3299 * Error checking for glCompressedTexSubImage[123]D().
3300 * \warning There are some bad assumptions here about the size of compressed
3301 * texture tiles (multiple of 4) used to test the validity of the
3302 * offset and size parameters.
3303 * \return error code or GL_NO_ERROR.
3306 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3307 GLenum target
, GLint level
,
3308 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3309 GLsizei width
, GLsizei height
, GLsizei depth
,
3310 GLenum format
, GLsizei imageSize
)
3312 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3316 if (dimensions
== 1) {
3317 /* 1D compressed textures not allowed */
3318 return GL_INVALID_ENUM
;
3320 else if (dimensions
== 2) {
3321 if (target
== GL_PROXY_TEXTURE_2D
) {
3322 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3324 else if (target
== GL_TEXTURE_2D
) {
3325 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3327 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3328 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3329 return GL_INVALID_ENUM
; /*target*/
3330 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3332 else if (_mesa_is_cube_face(target
)) {
3333 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3334 return GL_INVALID_ENUM
; /*target*/
3335 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3338 return GL_INVALID_ENUM
; /*target*/
3341 else if (dimensions
== 3) {
3342 /* 3D compressed textures not allowed */
3343 return GL_INVALID_ENUM
;
3346 maxTextureSize
= 1 << (maxLevels
- 1);
3348 /* this will catch any invalid compressed format token */
3349 if (!_mesa_is_compressed_format(ctx
, format
))
3350 return GL_INVALID_ENUM
;
3352 if (width
< 1 || width
> maxTextureSize
)
3353 return GL_INVALID_VALUE
;
3355 if ((height
< 1 || height
> maxTextureSize
)
3357 return GL_INVALID_VALUE
;
3359 if (level
< 0 || level
>= maxLevels
)
3360 return GL_INVALID_VALUE
;
3363 * do checks which depend on compression block size
3365 get_compressed_block_size(format
, &bw
, &bh
);
3367 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3368 return GL_INVALID_VALUE
;
3370 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3371 return GL_INVALID_VALUE
;
3373 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3374 return GL_INVALID_VALUE
;
3376 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3377 if (expectedSize
!= imageSize
)
3378 return GL_INVALID_VALUE
;
3385 * Do second part of glCompressedTexSubImage error checking.
3386 * \return GL_TRUE if error found, GL_FALSE otherwise.
3389 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3390 GLsizei width
, GLsizei height
,
3391 GLsizei depth
, GLenum format
,
3392 struct gl_texture_image
*texImage
)
3395 if ((GLint
) format
!= texImage
->InternalFormat
) {
3396 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3397 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3401 if (compressedteximage_only_format(ctx
, format
)) {
3402 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3403 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3408 if (((width
== 1 || width
== 2) &&
3409 width
!= (GLsizei
) texImage
->Width
) ||
3410 (width
> (GLsizei
) texImage
->Width
)) {
3411 _mesa_error(ctx
, GL_INVALID_VALUE
,
3412 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3417 if (((height
== 1 || height
== 2) &&
3418 height
!= (GLsizei
) texImage
->Height
) ||
3419 (height
> (GLsizei
) texImage
->Height
)) {
3420 _mesa_error(ctx
, GL_INVALID_VALUE
,
3421 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3427 if (((depth
== 1 || depth
== 2) &&
3428 depth
!= (GLsizei
) texImage
->Depth
) ||
3429 (depth
> (GLsizei
) texImage
->Depth
)) {
3430 _mesa_error(ctx
, GL_INVALID_VALUE
,
3431 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3441 * Implementation of the glCompressedTexImage1/2/3D() functions.
3444 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3445 GLenum target
, GLint level
,
3446 GLenum internalFormat
, GLsizei width
,
3447 GLsizei height
, GLsizei depth
, GLint border
,
3448 GLsizei imageSize
, const GLvoid
*data
)
3453 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3455 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3457 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3459 _mesa_lookup_enum_by_nr(target
), level
,
3460 _mesa_lookup_enum_by_nr(internalFormat
),
3461 width
, height
, depth
, border
, imageSize
, data
);
3464 if (!legal_teximage_target(ctx
, dims
, target
)) {
3465 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3466 dims
, _mesa_lookup_enum_by_nr(target
));
3470 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3471 internalFormat
, width
, height
, depth
,
3472 border
, imageSize
, &reason
);
3475 /* XXX this is kind of a hack */
3476 if (!error
&& dims
== 2) {
3477 switch (internalFormat
) {
3478 case GL_PALETTE4_RGB8_OES
:
3479 case GL_PALETTE4_RGBA8_OES
:
3480 case GL_PALETTE4_R5_G6_B5_OES
:
3481 case GL_PALETTE4_RGBA4_OES
:
3482 case GL_PALETTE4_RGB5_A1_OES
:
3483 case GL_PALETTE8_RGB8_OES
:
3484 case GL_PALETTE8_RGBA8_OES
:
3485 case GL_PALETTE8_R5_G6_B5_OES
:
3486 case GL_PALETTE8_RGBA4_OES
:
3487 case GL_PALETTE8_RGB5_A1_OES
:
3488 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3489 width
, height
, imageSize
, data
);
3495 if (_mesa_is_proxy_texture(target
)) {
3496 /* Proxy texture: just check for errors and update proxy state */
3497 struct gl_texture_image
*texImage
;
3500 struct gl_texture_object
*texObj
=
3501 _mesa_get_current_tex_object(ctx
, target
);
3502 gl_format texFormat
=
3503 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3504 internalFormat
, GL_NONE
, GL_NONE
);
3505 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3506 error
= GL_OUT_OF_MEMORY
;
3510 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3513 /* if error, clear all proxy texture image parameters */
3514 clear_teximage_fields(texImage
);
3517 /* no error: store the teximage parameters */
3518 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
3519 depth
, border
, internalFormat
,
3525 /* non-proxy target */
3526 struct gl_texture_object
*texObj
;
3527 struct gl_texture_image
*texImage
;
3530 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3534 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3536 _mesa_lock_texture(ctx
, texObj
);
3538 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3540 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3541 "glCompressedTexImage%uD", dims
);
3544 gl_format texFormat
;
3546 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3548 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3549 internalFormat
, GL_NONE
,
3552 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3553 _mesa_init_teximage_fields(ctx
, texImage
,
3554 width
, height
, depth
,
3555 border
, internalFormat
, texFormat
);
3557 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
, imageSize
,
3560 check_gen_mipmap(ctx
, target
, texObj
, level
);
3562 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3565 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3566 "glCompressedTexImage%uD", dims
);
3570 _mesa_unlock_texture(ctx
, texObj
);
3576 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3577 GLenum internalFormat
, GLsizei width
,
3578 GLint border
, GLsizei imageSize
,
3581 GET_CURRENT_CONTEXT(ctx
);
3582 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3583 width
, 1, 1, border
, imageSize
, data
);
3588 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3589 GLenum internalFormat
, GLsizei width
,
3590 GLsizei height
, GLint border
, GLsizei imageSize
,
3593 GET_CURRENT_CONTEXT(ctx
);
3594 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3595 width
, height
, 1, border
, imageSize
, data
);
3600 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3601 GLenum internalFormat
, GLsizei width
,
3602 GLsizei height
, GLsizei depth
, GLint border
,
3603 GLsizei imageSize
, const GLvoid
*data
)
3605 GET_CURRENT_CONTEXT(ctx
);
3606 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3607 width
, height
, depth
, border
, imageSize
, data
);
3612 * Common helper for glCompressedTexSubImage1/2/3D().
3615 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3616 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3617 GLsizei width
, GLsizei height
, GLsizei depth
,
3618 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3620 struct gl_texture_object
*texObj
;
3621 struct gl_texture_image
*texImage
;
3623 GET_CURRENT_CONTEXT(ctx
);
3624 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3626 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3627 xoffset
, 0, 0, /* pos */
3628 width
, height
, depth
, /* size */
3631 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3635 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3637 _mesa_lock_texture(ctx
, texObj
);
3639 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3642 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3643 format
, texImage
)) {
3644 /* error was recorded */
3646 else if (width
> 0 && height
> 0 && depth
> 0) {
3647 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3648 xoffset
, yoffset
, zoffset
,
3649 width
, height
, depth
,
3650 format
, imageSize
, data
);
3652 check_gen_mipmap(ctx
, target
, texObj
, level
);
3654 ctx
->NewState
|= _NEW_TEXTURE
;
3657 _mesa_unlock_texture(ctx
, texObj
);
3662 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3663 GLsizei width
, GLenum format
,
3664 GLsizei imageSize
, const GLvoid
*data
)
3666 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3667 format
, imageSize
, data
);
3672 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3673 GLint yoffset
, GLsizei width
, GLsizei height
,
3674 GLenum format
, GLsizei imageSize
,
3677 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3678 width
, height
, 1, format
, imageSize
, data
);
3683 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3684 GLint yoffset
, GLint zoffset
, GLsizei width
,
3685 GLsizei height
, GLsizei depth
, GLenum format
,
3686 GLsizei imageSize
, const GLvoid
*data
)
3688 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3689 width
, height
, depth
, format
, imageSize
, data
);
3693 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3695 switch (internalFormat
) {
3697 return MESA_FORMAT_A8
;
3699 return MESA_FORMAT_A16
;
3700 case GL_ALPHA16F_ARB
:
3701 return MESA_FORMAT_ALPHA_FLOAT16
;
3702 case GL_ALPHA32F_ARB
:
3703 return MESA_FORMAT_ALPHA_FLOAT32
;
3704 case GL_ALPHA8I_EXT
:
3705 return MESA_FORMAT_ALPHA_INT8
;
3706 case GL_ALPHA16I_EXT
:
3707 return MESA_FORMAT_ALPHA_INT16
;
3708 case GL_ALPHA32I_EXT
:
3709 return MESA_FORMAT_ALPHA_INT32
;
3710 case GL_ALPHA8UI_EXT
:
3711 return MESA_FORMAT_ALPHA_UINT8
;
3712 case GL_ALPHA16UI_EXT
:
3713 return MESA_FORMAT_ALPHA_UINT16
;
3714 case GL_ALPHA32UI_EXT
:
3715 return MESA_FORMAT_ALPHA_UINT32
;
3717 return MESA_FORMAT_L8
;
3718 case GL_LUMINANCE16
:
3719 return MESA_FORMAT_L16
;
3720 case GL_LUMINANCE16F_ARB
:
3721 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3722 case GL_LUMINANCE32F_ARB
:
3723 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3724 case GL_LUMINANCE8I_EXT
:
3725 return MESA_FORMAT_LUMINANCE_INT8
;
3726 case GL_LUMINANCE16I_EXT
:
3727 return MESA_FORMAT_LUMINANCE_INT16
;
3728 case GL_LUMINANCE32I_EXT
:
3729 return MESA_FORMAT_LUMINANCE_INT32
;
3730 case GL_LUMINANCE8UI_EXT
:
3731 return MESA_FORMAT_LUMINANCE_UINT8
;
3732 case GL_LUMINANCE16UI_EXT
:
3733 return MESA_FORMAT_LUMINANCE_UINT16
;
3734 case GL_LUMINANCE32UI_EXT
:
3735 return MESA_FORMAT_LUMINANCE_UINT32
;
3736 case GL_LUMINANCE8_ALPHA8
:
3737 return MESA_FORMAT_AL88
;
3738 case GL_LUMINANCE16_ALPHA16
:
3739 return MESA_FORMAT_AL1616
;
3740 case GL_LUMINANCE_ALPHA16F_ARB
:
3741 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3742 case GL_LUMINANCE_ALPHA32F_ARB
:
3743 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3744 case GL_LUMINANCE_ALPHA8I_EXT
:
3745 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3746 case GL_LUMINANCE_ALPHA16I_EXT
:
3747 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3748 case GL_LUMINANCE_ALPHA32I_EXT
:
3749 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3750 case GL_LUMINANCE_ALPHA8UI_EXT
:
3751 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3752 case GL_LUMINANCE_ALPHA16UI_EXT
:
3753 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3754 case GL_LUMINANCE_ALPHA32UI_EXT
:
3755 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3757 return MESA_FORMAT_I8
;
3758 case GL_INTENSITY16
:
3759 return MESA_FORMAT_I16
;
3760 case GL_INTENSITY16F_ARB
:
3761 return MESA_FORMAT_INTENSITY_FLOAT16
;
3762 case GL_INTENSITY32F_ARB
:
3763 return MESA_FORMAT_INTENSITY_FLOAT32
;
3764 case GL_INTENSITY8I_EXT
:
3765 return MESA_FORMAT_INTENSITY_INT8
;
3766 case GL_INTENSITY16I_EXT
:
3767 return MESA_FORMAT_INTENSITY_INT16
;
3768 case GL_INTENSITY32I_EXT
:
3769 return MESA_FORMAT_INTENSITY_INT32
;
3770 case GL_INTENSITY8UI_EXT
:
3771 return MESA_FORMAT_INTENSITY_UINT8
;
3772 case GL_INTENSITY16UI_EXT
:
3773 return MESA_FORMAT_INTENSITY_UINT16
;
3774 case GL_INTENSITY32UI_EXT
:
3775 return MESA_FORMAT_INTENSITY_UINT32
;
3777 return MESA_FORMAT_RGBA8888_REV
;
3779 return MESA_FORMAT_RGBA_16
;
3780 case GL_RGBA16F_ARB
:
3781 return MESA_FORMAT_RGBA_FLOAT16
;
3782 case GL_RGBA32F_ARB
:
3783 return MESA_FORMAT_RGBA_FLOAT32
;
3785 return MESA_FORMAT_RGBA_INT8
;
3786 case GL_RGBA16I_EXT
:
3787 return MESA_FORMAT_RGBA_INT16
;
3788 case GL_RGBA32I_EXT
:
3789 return MESA_FORMAT_RGBA_INT32
;
3790 case GL_RGBA8UI_EXT
:
3791 return MESA_FORMAT_RGBA_UINT8
;
3792 case GL_RGBA16UI_EXT
:
3793 return MESA_FORMAT_RGBA_UINT16
;
3794 case GL_RGBA32UI_EXT
:
3795 return MESA_FORMAT_RGBA_UINT32
;
3798 return MESA_FORMAT_GR88
;
3800 return MESA_FORMAT_RG1616
;
3802 return MESA_FORMAT_RG_FLOAT16
;
3804 return MESA_FORMAT_RG_FLOAT32
;
3806 return MESA_FORMAT_RG_INT8
;
3808 return MESA_FORMAT_RG_INT16
;
3810 return MESA_FORMAT_RG_INT32
;
3812 return MESA_FORMAT_RG_UINT8
;
3814 return MESA_FORMAT_RG_UINT16
;
3816 return MESA_FORMAT_RG_UINT32
;
3819 return MESA_FORMAT_R8
;
3821 return MESA_FORMAT_R16
;
3823 return MESA_FORMAT_R_FLOAT16
;
3825 return MESA_FORMAT_R_FLOAT32
;
3827 return MESA_FORMAT_R_INT8
;
3829 return MESA_FORMAT_R_INT16
;
3831 return MESA_FORMAT_R_INT32
;
3833 return MESA_FORMAT_R_UINT8
;
3835 return MESA_FORMAT_R_UINT16
;
3837 return MESA_FORMAT_R_UINT32
;
3840 return MESA_FORMAT_NONE
;
3845 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3847 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
3850 if (format
== MESA_FORMAT_NONE
)
3851 return MESA_FORMAT_NONE
;
3853 datatype
= _mesa_get_format_datatype(format
);
3854 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3855 return MESA_FORMAT_NONE
;
3857 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3858 return MESA_FORMAT_NONE
;
3860 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
3861 * any mention of R/RG formats, but they appear in the GL 3.1 core
3864 if (ctx
->Version
<= 30) {
3865 GLenum base_format
= _mesa_get_format_base_format(format
);
3867 if (base_format
== GL_R
|| base_format
== GL_RG
)
3868 return MESA_FORMAT_NONE
;
3874 /** GL_ARB_texture_buffer_object */
3876 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3878 struct gl_texture_object
*texObj
;
3879 struct gl_buffer_object
*bufObj
;
3882 GET_CURRENT_CONTEXT(ctx
);
3883 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3885 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3886 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3890 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3891 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3895 format
= validate_texbuffer_format(ctx
, internalFormat
);
3896 if (format
== MESA_FORMAT_NONE
) {
3897 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3902 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3903 if (buffer
&& !bufObj
) {
3904 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3908 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3910 _mesa_lock_texture(ctx
, texObj
);
3912 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3913 texObj
->BufferObjectFormat
= internalFormat
;
3914 texObj
->_BufferObjectFormat
= format
;
3916 _mesa_unlock_texture(ctx
, texObj
);