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"
53 * State changes which we care about for glCopyTex[Sub]Image() calls.
54 * In particular, we care about pixel transfer state and buffer state
55 * (such as glReadBuffer to make sure we read from the right renderbuffer).
57 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
62 * Return the simple base format for a given internal texture format.
63 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
65 * \param ctx GL context.
66 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
68 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
69 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
71 * This is the format which is used during texture application (i.e. the
72 * texture format and env mode determine the arithmetic used.
75 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
77 switch (internalFormat
) {
92 case GL_LUMINANCE_ALPHA
:
93 case GL_LUMINANCE4_ALPHA4
:
94 case GL_LUMINANCE6_ALPHA2
:
95 case GL_LUMINANCE8_ALPHA8
:
96 case GL_LUMINANCE12_ALPHA4
:
97 case GL_LUMINANCE12_ALPHA12
:
98 case GL_LUMINANCE16_ALPHA16
:
99 return GL_LUMINANCE_ALPHA
;
130 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
132 if (ctx
->API
!= API_OPENGL
) {
133 switch (internalFormat
) {
141 if (ctx
->Extensions
.ARB_depth_texture
) {
142 switch (internalFormat
) {
143 case GL_DEPTH_COMPONENT
:
144 case GL_DEPTH_COMPONENT16
:
145 case GL_DEPTH_COMPONENT24
:
146 case GL_DEPTH_COMPONENT32
:
147 return GL_DEPTH_COMPONENT
;
153 switch (internalFormat
) {
154 case GL_COMPRESSED_ALPHA
:
156 case GL_COMPRESSED_LUMINANCE
:
158 case GL_COMPRESSED_LUMINANCE_ALPHA
:
159 return GL_LUMINANCE_ALPHA
;
160 case GL_COMPRESSED_INTENSITY
:
162 case GL_COMPRESSED_RGB
:
164 case GL_COMPRESSED_RGBA
:
170 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
171 switch (internalFormat
) {
172 case GL_COMPRESSED_RGB_FXT1_3DFX
:
174 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
181 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
182 switch (internalFormat
) {
183 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
185 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
186 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
187 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
194 if (ctx
->Extensions
.S3_s3tc
) {
195 switch (internalFormat
) {
207 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
208 if (internalFormat
== GL_YCBCR_MESA
)
209 return GL_YCBCR_MESA
;
212 if (ctx
->Extensions
.ARB_texture_float
) {
213 switch (internalFormat
) {
214 case GL_ALPHA16F_ARB
:
215 case GL_ALPHA32F_ARB
:
223 case GL_INTENSITY16F_ARB
:
224 case GL_INTENSITY32F_ARB
:
226 case GL_LUMINANCE16F_ARB
:
227 case GL_LUMINANCE32F_ARB
:
229 case GL_LUMINANCE_ALPHA16F_ARB
:
230 case GL_LUMINANCE_ALPHA32F_ARB
:
231 return GL_LUMINANCE_ALPHA
;
237 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
238 switch (internalFormat
) {
247 if (ctx
->Extensions
.EXT_texture_snorm
) {
248 switch (internalFormat
) {
263 case GL_RGBA16_SNORM
:
266 case GL_ALPHA8_SNORM
:
267 case GL_ALPHA16_SNORM
:
269 case GL_LUMINANCE_SNORM
:
270 case GL_LUMINANCE8_SNORM
:
271 case GL_LUMINANCE16_SNORM
:
273 case GL_LUMINANCE_ALPHA_SNORM
:
274 case GL_LUMINANCE8_ALPHA8_SNORM
:
275 case GL_LUMINANCE16_ALPHA16_SNORM
:
276 return GL_LUMINANCE_ALPHA
;
277 case GL_INTENSITY_SNORM
:
278 case GL_INTENSITY8_SNORM
:
279 case GL_INTENSITY16_SNORM
:
286 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
287 switch (internalFormat
) {
288 case GL_DEPTH_STENCIL_EXT
:
289 case GL_DEPTH24_STENCIL8_EXT
:
290 return GL_DEPTH_STENCIL_EXT
;
296 #if FEATURE_EXT_texture_sRGB
297 if (ctx
->Extensions
.EXT_texture_sRGB
) {
298 switch (internalFormat
) {
301 case GL_COMPRESSED_SRGB_EXT
:
302 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
304 case GL_SRGB_ALPHA_EXT
:
305 case GL_SRGB8_ALPHA8_EXT
:
306 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
307 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
308 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
309 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
311 case GL_SLUMINANCE_ALPHA_EXT
:
312 case GL_SLUMINANCE8_ALPHA8_EXT
:
313 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
314 return GL_LUMINANCE_ALPHA
;
315 case GL_SLUMINANCE_EXT
:
316 case GL_SLUMINANCE8_EXT
:
317 case GL_COMPRESSED_SLUMINANCE_EXT
:
323 #endif /* FEATURE_EXT_texture_sRGB */
325 if (ctx
->VersionMajor
>= 3 ||
326 ctx
->Extensions
.EXT_texture_integer
) {
327 switch (internalFormat
) {
329 case GL_RGBA16UI_EXT
:
330 case GL_RGBA32UI_EXT
:
346 if (ctx
->Extensions
.EXT_texture_integer
) {
347 switch (internalFormat
) {
348 case GL_ALPHA8UI_EXT
:
349 case GL_ALPHA16UI_EXT
:
350 case GL_ALPHA32UI_EXT
:
352 case GL_ALPHA16I_EXT
:
353 case GL_ALPHA32I_EXT
:
355 case GL_INTENSITY8UI_EXT
:
356 case GL_INTENSITY16UI_EXT
:
357 case GL_INTENSITY32UI_EXT
:
358 case GL_INTENSITY8I_EXT
:
359 case GL_INTENSITY16I_EXT
:
360 case GL_INTENSITY32I_EXT
:
362 case GL_LUMINANCE8UI_EXT
:
363 case GL_LUMINANCE16UI_EXT
:
364 case GL_LUMINANCE32UI_EXT
:
365 case GL_LUMINANCE8I_EXT
:
366 case GL_LUMINANCE16I_EXT
:
367 case GL_LUMINANCE32I_EXT
:
369 case GL_LUMINANCE_ALPHA8UI_EXT
:
370 case GL_LUMINANCE_ALPHA16UI_EXT
:
371 case GL_LUMINANCE_ALPHA32UI_EXT
:
372 case GL_LUMINANCE_ALPHA8I_EXT
:
373 case GL_LUMINANCE_ALPHA16I_EXT
:
374 case GL_LUMINANCE_ALPHA32I_EXT
:
375 return GL_LUMINANCE_ALPHA
;
381 if (ctx
->Extensions
.ARB_texture_rg
) {
382 switch (internalFormat
) {
384 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
386 if (!ctx
->Extensions
.ARB_half_float_pixel
)
390 if (!ctx
->Extensions
.ARB_texture_float
)
399 if (ctx
->VersionMajor
< 3 && !ctx
->Extensions
.EXT_texture_integer
)
405 case GL_COMPRESSED_RED
:
409 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
411 if (!ctx
->Extensions
.ARB_half_float_pixel
)
415 if (!ctx
->Extensions
.ARB_texture_float
)
424 if (ctx
->VersionMajor
< 3 && !ctx
->Extensions
.EXT_texture_integer
)
430 case GL_COMPRESSED_RG
:
437 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
438 switch (internalFormat
) {
446 if (ctx
->Extensions
.EXT_packed_float
) {
447 switch (internalFormat
) {
448 case GL_R11F_G11F_B10F_EXT
:
455 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
456 switch (internalFormat
) {
457 case GL_DEPTH_COMPONENT32F
:
458 return GL_DEPTH_COMPONENT
;
459 case GL_DEPTH32F_STENCIL8
:
460 return GL_DEPTH_STENCIL
;
466 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
467 switch (internalFormat
) {
468 case GL_COMPRESSED_RED_RGTC1
:
469 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
471 case GL_COMPRESSED_RG_RGTC2
:
472 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
479 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
480 switch (internalFormat
) {
481 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
482 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
484 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
485 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
486 return GL_LUMINANCE_ALPHA
;
492 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
493 switch (internalFormat
) {
494 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
495 return GL_LUMINANCE_ALPHA
;
501 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
502 switch (internalFormat
) {
503 case GL_ETC1_RGB8_OES
:
510 if (ctx
->API
== API_OPENGLES
) {
511 switch (internalFormat
) {
512 case GL_PALETTE4_RGB8_OES
:
513 case GL_PALETTE4_R5_G6_B5_OES
:
514 case GL_PALETTE8_RGB8_OES
:
515 case GL_PALETTE8_R5_G6_B5_OES
:
517 case GL_PALETTE4_RGBA8_OES
:
518 case GL_PALETTE8_RGB5_A1_OES
:
519 case GL_PALETTE4_RGBA4_OES
:
520 case GL_PALETTE4_RGB5_A1_OES
:
521 case GL_PALETTE8_RGBA8_OES
:
522 case GL_PALETTE8_RGBA4_OES
:
529 return -1; /* error */
534 * For cube map faces, return a face index in [0,5].
535 * For other targets return 0;
538 _mesa_tex_target_to_face(GLenum target
)
540 if (_mesa_is_cube_face(target
))
541 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
549 * Install gl_texture_image in a gl_texture_object according to the target
550 * and level parameters.
552 * \param tObj texture object.
553 * \param target texture target.
554 * \param level image level.
555 * \param texImage texture image.
558 set_tex_image(struct gl_texture_object
*tObj
,
559 GLenum target
, GLint level
,
560 struct gl_texture_image
*texImage
)
562 const GLuint face
= _mesa_tex_target_to_face(target
);
566 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
569 tObj
->Image
[face
][level
] = texImage
;
571 /* Set the 'back' pointer */
572 texImage
->TexObject
= tObj
;
573 texImage
->Level
= level
;
574 texImage
->Face
= face
;
579 * Allocate a texture image structure.
581 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
584 * \return a pointer to gl_texture_image struct with all fields initialized to
587 struct gl_texture_image
*
588 _mesa_new_texture_image( struct gl_context
*ctx
)
591 return CALLOC_STRUCT(gl_texture_image
);
596 * Free a gl_texture_image and associated data.
597 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
599 * \param texImage texture image.
601 * Free the texture image structure and the associated image data.
604 _mesa_delete_texture_image(struct gl_context
*ctx
,
605 struct gl_texture_image
*texImage
)
607 /* Free texImage->Data and/or any other driver-specific texture
610 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
611 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
617 * Test if a target is a proxy target.
619 * \param target texture target.
621 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
624 _mesa_is_proxy_texture(GLenum target
)
627 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
628 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
630 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
632 return (target
== GL_PROXY_TEXTURE_1D
||
633 target
== GL_PROXY_TEXTURE_2D
||
634 target
== GL_PROXY_TEXTURE_3D
||
635 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
636 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
637 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
638 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
643 * Return the proxy target which corresponds to the given texture target
646 get_proxy_target(GLenum target
)
650 case GL_PROXY_TEXTURE_1D
:
651 return GL_PROXY_TEXTURE_1D
;
653 case GL_PROXY_TEXTURE_2D
:
654 return GL_PROXY_TEXTURE_2D
;
656 case GL_PROXY_TEXTURE_3D
:
657 return GL_PROXY_TEXTURE_3D
;
658 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
659 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
660 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
661 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
662 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
663 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
664 case GL_TEXTURE_CUBE_MAP_ARB
:
665 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
666 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
667 case GL_TEXTURE_RECTANGLE_NV
:
668 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
669 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
670 case GL_TEXTURE_1D_ARRAY_EXT
:
671 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
672 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
673 case GL_TEXTURE_2D_ARRAY_EXT
:
674 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
675 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
677 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
684 * Get the texture object that corresponds to the target of the given
685 * texture unit. The target should have already been checked for validity.
687 * \param ctx GL context.
688 * \param texUnit texture unit.
689 * \param target texture target.
691 * \return pointer to the texture object on success, or NULL on failure.
693 struct gl_texture_object
*
694 _mesa_select_tex_object(struct gl_context
*ctx
,
695 const struct gl_texture_unit
*texUnit
,
698 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
699 ctx
->Extensions
.EXT_texture_array
);
703 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
704 case GL_PROXY_TEXTURE_1D
:
705 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
707 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
708 case GL_PROXY_TEXTURE_2D
:
709 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
711 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
712 case GL_PROXY_TEXTURE_3D
:
713 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
714 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
715 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
716 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
717 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
718 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
719 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
720 case GL_TEXTURE_CUBE_MAP_ARB
:
721 return ctx
->Extensions
.ARB_texture_cube_map
722 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
723 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
724 return ctx
->Extensions
.ARB_texture_cube_map
725 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
726 case GL_TEXTURE_RECTANGLE_NV
:
727 return ctx
->Extensions
.NV_texture_rectangle
728 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
729 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
730 return ctx
->Extensions
.NV_texture_rectangle
731 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
732 case GL_TEXTURE_1D_ARRAY_EXT
:
733 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
734 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
735 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
736 case GL_TEXTURE_2D_ARRAY_EXT
:
737 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
738 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
739 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
740 case GL_TEXTURE_BUFFER
:
741 return ctx
->Extensions
.ARB_texture_buffer_object
742 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
743 case GL_TEXTURE_EXTERNAL_OES
:
744 return ctx
->Extensions
.OES_EGL_image_external
745 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
747 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
754 * Return pointer to texture object for given target on current texture unit.
756 struct gl_texture_object
*
757 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
759 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
760 return _mesa_select_tex_object(ctx
, texUnit
, target
);
765 * Get a texture image pointer from a texture object, given a texture
766 * target and mipmap level. The target and level parameters should
767 * have already been error-checked.
769 * \param ctx GL context.
770 * \param texObj texture unit.
771 * \param target texture target.
772 * \param level image level.
774 * \return pointer to the texture image structure, or NULL on failure.
776 struct gl_texture_image
*
777 _mesa_select_tex_image(struct gl_context
*ctx
,
778 const struct gl_texture_object
*texObj
,
779 GLenum target
, GLint level
)
781 const GLuint face
= _mesa_tex_target_to_face(target
);
785 ASSERT(level
< MAX_TEXTURE_LEVELS
);
787 return texObj
->Image
[face
][level
];
792 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
793 * it and install it. Only return NULL if passed a bad parameter or run
796 struct gl_texture_image
*
797 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
798 GLenum target
, GLint level
)
800 struct gl_texture_image
*texImage
;
805 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
807 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
809 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
813 set_tex_image(texObj
, target
, level
, texImage
);
821 * Return pointer to the specified proxy texture image.
822 * Note that proxy textures are per-context, not per-texture unit.
823 * \return pointer to texture image or NULL if invalid target, invalid
824 * level, or out of memory.
826 struct gl_texture_image
*
827 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
829 struct gl_texture_image
*texImage
;
836 case GL_PROXY_TEXTURE_1D
:
837 if (level
>= ctx
->Const
.MaxTextureLevels
)
839 texIndex
= TEXTURE_1D_INDEX
;
841 case GL_PROXY_TEXTURE_2D
:
842 if (level
>= ctx
->Const
.MaxTextureLevels
)
844 texIndex
= TEXTURE_2D_INDEX
;
846 case GL_PROXY_TEXTURE_3D
:
847 if (level
>= ctx
->Const
.Max3DTextureLevels
)
849 texIndex
= TEXTURE_3D_INDEX
;
851 case GL_PROXY_TEXTURE_CUBE_MAP
:
852 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
854 texIndex
= TEXTURE_CUBE_INDEX
;
856 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
859 texIndex
= TEXTURE_RECT_INDEX
;
861 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
862 if (level
>= ctx
->Const
.MaxTextureLevels
)
864 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
866 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
867 if (level
>= ctx
->Const
.MaxTextureLevels
)
869 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
875 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
877 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
879 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
882 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
883 /* Set the 'back' pointer */
884 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
891 * Get the maximum number of allowed mipmap levels.
893 * \param ctx GL context.
894 * \param target texture target.
896 * \return the maximum number of allowed mipmap levels for the given
897 * texture target, or zero if passed a bad target.
902 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
906 case GL_PROXY_TEXTURE_1D
:
908 case GL_PROXY_TEXTURE_2D
:
909 return ctx
->Const
.MaxTextureLevels
;
911 case GL_PROXY_TEXTURE_3D
:
912 return ctx
->Const
.Max3DTextureLevels
;
913 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
914 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
915 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
916 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
917 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
918 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
919 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
920 return ctx
->Extensions
.ARB_texture_cube_map
921 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
922 case GL_TEXTURE_RECTANGLE_NV
:
923 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
924 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
925 case GL_TEXTURE_1D_ARRAY_EXT
:
926 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
927 case GL_TEXTURE_2D_ARRAY_EXT
:
928 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
929 return (ctx
->Extensions
.MESA_texture_array
||
930 ctx
->Extensions
.EXT_texture_array
)
931 ? ctx
->Const
.MaxTextureLevels
: 0;
932 case GL_TEXTURE_BUFFER
:
933 case GL_TEXTURE_EXTERNAL_OES
:
936 return 0; /* bad target */
942 * Return number of dimensions per mipmap level for the given texture target.
945 _mesa_get_texture_dimensions(GLenum target
)
949 case GL_PROXY_TEXTURE_1D
:
952 case GL_TEXTURE_RECTANGLE
:
953 case GL_TEXTURE_CUBE_MAP
:
954 case GL_PROXY_TEXTURE_2D
:
955 case GL_PROXY_TEXTURE_RECTANGLE
:
956 case GL_PROXY_TEXTURE_CUBE_MAP
:
957 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
958 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
959 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
960 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
961 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
962 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
963 case GL_TEXTURE_1D_ARRAY
:
964 case GL_PROXY_TEXTURE_1D_ARRAY
:
965 case GL_TEXTURE_EXTERNAL_OES
:
968 case GL_PROXY_TEXTURE_3D
:
969 case GL_TEXTURE_2D_ARRAY
:
970 case GL_PROXY_TEXTURE_2D_ARRAY
:
972 case GL_TEXTURE_BUFFER
:
975 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
984 #if 000 /* not used anymore */
986 * glTexImage[123]D can accept a NULL image pointer. In this case we
987 * create a texture image with unspecified image contents per the OpenGL
991 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
993 const GLint components
= _mesa_components_in_format(format
);
994 const GLint numPixels
= width
* height
* depth
;
995 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
999 * Let's see if anyone finds this. If glTexImage2D() is called with
1000 * a NULL image pointer then load the texture image with something
1001 * interesting instead of leaving it indeterminate.
1004 static const char message
[8][32] = {
1005 " X X XXXXX XXX X ",
1006 " XX XX X X X X X ",
1008 " X X XXXX XXX XXXXX ",
1011 " X X XXXXX XXX X X ",
1015 GLubyte
*imgPtr
= data
;
1017 for (h
= 0; h
< depth
; h
++) {
1018 for (i
= 0; i
< height
; i
++) {
1019 GLint srcRow
= 7 - (i
% 8);
1020 for (j
= 0; j
< width
; j
++) {
1021 GLint srcCol
= j
% 32;
1022 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1023 for (k
= 0; k
< components
; k
++) {
1039 * Set the size and format-related fields of a gl_texture_image struct
1040 * to zero. This is used when a proxy texture test fails.
1043 clear_teximage_fields(struct gl_texture_image
*img
)
1046 img
->_BaseFormat
= 0;
1047 img
->InternalFormat
= 0;
1056 img
->HeightLog2
= 0;
1058 img
->TexFormat
= MESA_FORMAT_NONE
;
1063 * Initialize basic fields of the gl_texture_image struct.
1065 * \param ctx GL context.
1066 * \param img texture image structure to be initialized.
1067 * \param width image width.
1068 * \param height image height.
1069 * \param depth image depth.
1070 * \param border image border.
1071 * \param internalFormat internal format.
1072 * \param format the actual hardware format (one of MESA_FORMAT_*)
1074 * Fills in the fields of \p img with the given information.
1075 * Note: width, height and depth include the border.
1078 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1079 struct gl_texture_image
*img
,
1080 GLsizei width
, GLsizei height
, GLsizei depth
,
1081 GLint border
, GLenum internalFormat
,
1087 ASSERT(height
>= 0);
1090 target
= img
->TexObject
->Target
;
1091 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1092 ASSERT(img
->_BaseFormat
> 0);
1093 img
->InternalFormat
= internalFormat
;
1094 img
->Border
= border
;
1096 img
->Height
= height
;
1099 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1100 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1104 case GL_TEXTURE_BUFFER
:
1105 case GL_PROXY_TEXTURE_1D
:
1110 img
->HeightLog2
= 0;
1117 case GL_TEXTURE_1D_ARRAY
:
1118 case GL_PROXY_TEXTURE_1D_ARRAY
:
1119 img
->Height2
= height
; /* no border */
1120 img
->HeightLog2
= 0; /* not used */
1128 case GL_TEXTURE_RECTANGLE
:
1129 case GL_TEXTURE_CUBE_MAP
:
1130 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1131 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1132 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1133 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1134 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1135 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1136 case GL_TEXTURE_EXTERNAL_OES
:
1137 case GL_PROXY_TEXTURE_2D
:
1138 case GL_PROXY_TEXTURE_RECTANGLE
:
1139 case GL_PROXY_TEXTURE_CUBE_MAP
:
1140 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1141 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1148 case GL_TEXTURE_2D_ARRAY
:
1149 case GL_PROXY_TEXTURE_2D_ARRAY
:
1150 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1151 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1152 img
->Depth2
= depth
; /* no border */
1153 img
->DepthLog2
= 0; /* not used */
1156 case GL_PROXY_TEXTURE_3D
:
1157 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1158 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1159 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1160 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1163 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1167 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1168 img
->TexFormat
= format
;
1173 * Free and clear fields of the gl_texture_image struct.
1175 * \param ctx GL context.
1176 * \param texImage texture image structure to be cleared.
1178 * After the call, \p texImage will have no data associated with it. Its
1179 * fields are cleared so that its parent object will test incomplete.
1182 _mesa_clear_texture_image(struct gl_context
*ctx
,
1183 struct gl_texture_image
*texImage
)
1185 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1186 clear_teximage_fields(texImage
);
1191 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1192 * level, width, height and depth against the ctx->Const limits for textures.
1194 * A hardware driver might override this function if, for example, the
1195 * max 3D texture size is 512x512x64 (i.e. not a cube).
1197 * Note that width, height, depth == 0 is not an error. However, a
1198 * texture with zero width/height/depth will be considered "incomplete"
1199 * and texturing will effectively be disabled.
1201 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1202 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1203 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1204 * \param level as passed to glTexImage
1205 * \param internalFormat as passed to glTexImage
1206 * \param format as passed to glTexImage
1207 * \param type as passed to glTexImage
1208 * \param width as passed to glTexImage
1209 * \param height as passed to glTexImage
1210 * \param depth as passed to glTexImage
1211 * \param border as passed to glTexImage
1212 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1215 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1216 GLint internalFormat
, GLenum format
, GLenum type
,
1217 GLint width
, GLint height
, GLint depth
, GLint border
)
1221 (void) internalFormat
;
1226 case GL_PROXY_TEXTURE_1D
:
1227 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1228 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1230 if (level
>= ctx
->Const
.MaxTextureLevels
)
1232 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1233 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1238 case GL_PROXY_TEXTURE_2D
:
1239 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1240 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1242 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1244 if (level
>= ctx
->Const
.MaxTextureLevels
)
1246 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1247 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1249 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1254 case GL_PROXY_TEXTURE_3D
:
1255 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1256 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1258 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1260 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1262 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1264 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1265 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1267 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1269 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1274 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1275 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1276 if (width
< 0 || width
> maxSize
)
1278 if (height
< 0 || height
> maxSize
)
1284 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1285 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1286 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1288 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1290 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1292 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1293 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1295 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1300 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1301 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1302 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1304 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1306 if (level
>= ctx
->Const
.MaxTextureLevels
)
1308 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1309 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1314 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1315 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1316 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1318 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1320 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1322 if (level
>= ctx
->Const
.MaxTextureLevels
)
1324 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1325 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1327 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1333 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1340 * Check if the memory used by the texture would exceed the driver's limit.
1341 * This lets us support a max 3D texture size of 8K (for example) but
1342 * prevents allocating a full 8K x 8K x 8K texture.
1343 * XXX this could be rolled into the proxy texture size test (above) but
1344 * we don't have the actual texture internal format at that point.
1347 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1348 GLint width
, GLint height
, GLint depth
)
1350 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1351 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1352 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1357 * Return true if the format is only valid for glCompressedTexImage.
1360 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1363 case GL_ETC1_RGB8_OES
:
1372 * Helper function to determine whether a target and specific compression
1373 * format are supported.
1376 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1379 (void) intFormat
; /* not used yet */
1383 case GL_PROXY_TEXTURE_2D
:
1384 return GL_TRUE
; /* true for any compressed format so far */
1385 case GL_PROXY_TEXTURE_CUBE_MAP
:
1386 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1387 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1388 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1389 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1390 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1391 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1392 return ctx
->Extensions
.ARB_texture_cube_map
;
1393 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1394 case GL_TEXTURE_2D_ARRAY_EXT
:
1395 return (ctx
->Extensions
.MESA_texture_array
||
1396 ctx
->Extensions
.EXT_texture_array
);
1404 * Check if the given texture target value is legal for a
1405 * glTexImage1/2/3D call.
1408 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1414 case GL_PROXY_TEXTURE_1D
:
1422 case GL_PROXY_TEXTURE_2D
:
1424 case GL_PROXY_TEXTURE_CUBE_MAP
:
1425 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1426 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1427 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1428 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1429 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1430 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1431 return ctx
->Extensions
.ARB_texture_cube_map
;
1432 case GL_TEXTURE_RECTANGLE_NV
:
1433 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1434 return ctx
->Extensions
.NV_texture_rectangle
;
1435 case GL_TEXTURE_1D_ARRAY_EXT
:
1436 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1437 return (ctx
->Extensions
.MESA_texture_array
||
1438 ctx
->Extensions
.EXT_texture_array
);
1445 case GL_PROXY_TEXTURE_3D
:
1447 case GL_TEXTURE_2D_ARRAY_EXT
:
1448 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1449 return (ctx
->Extensions
.MESA_texture_array
||
1450 ctx
->Extensions
.EXT_texture_array
);
1455 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1462 * Check if the given texture target value is legal for a
1463 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1464 * The difference compared to legal_teximage_target() above is that
1465 * proxy targets are not supported.
1468 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1472 return target
== GL_TEXTURE_1D
;
1477 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1478 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1479 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1480 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1481 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1482 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1483 return ctx
->Extensions
.ARB_texture_cube_map
;
1484 case GL_TEXTURE_RECTANGLE_NV
:
1485 return ctx
->Extensions
.NV_texture_rectangle
;
1486 case GL_TEXTURE_1D_ARRAY_EXT
:
1487 return (ctx
->Extensions
.MESA_texture_array
||
1488 ctx
->Extensions
.EXT_texture_array
);
1496 case GL_TEXTURE_2D_ARRAY_EXT
:
1497 return (ctx
->Extensions
.MESA_texture_array
||
1498 ctx
->Extensions
.EXT_texture_array
);
1503 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1511 * Helper function to determine if a texture object is mutable (in terms
1512 * of GL_ARB_texture_storage).
1515 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1517 if (ctx
->Extensions
.ARB_texture_storage
) {
1518 struct gl_texture_object
*texObj
=
1519 _mesa_get_current_tex_object(ctx
, target
);
1520 return !texObj
->Immutable
;
1528 * Test the glTexImage[123]D() parameters for errors.
1530 * \param ctx GL context.
1531 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1532 * \param target texture target given by the user.
1533 * \param level image level given by the user.
1534 * \param internalFormat internal format given by the user.
1535 * \param format pixel data format given by the user.
1536 * \param type pixel data type given by the user.
1537 * \param width image width given by the user.
1538 * \param height image height given by the user.
1539 * \param depth image depth given by the user.
1540 * \param border image border given by the user.
1542 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1544 * Verifies each of the parameters against the constants specified in
1545 * __struct gl_contextRec::Const and the supported extensions, and according
1546 * to the OpenGL specification.
1549 texture_error_check( struct gl_context
*ctx
,
1550 GLuint dimensions
, GLenum target
,
1551 GLint level
, GLint internalFormat
,
1552 GLenum format
, GLenum type
,
1553 GLint width
, GLint height
,
1554 GLint depth
, GLint border
)
1556 const GLenum proxyTarget
= get_proxy_target(target
);
1557 const GLboolean isProxy
= target
== proxyTarget
;
1558 GLboolean sizeOK
= GL_TRUE
;
1559 GLboolean colorFormat
;
1562 /* Even though there are no color-index textures, we still have to support
1563 * uploading color-index data and remapping it to RGB via the
1564 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1566 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1568 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1569 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1571 _mesa_error(ctx
, GL_INVALID_VALUE
,
1572 "glTexImage%dD(level=%d)", dimensions
, level
);
1578 if (border
< 0 || border
> 1 ||
1579 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1580 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1582 _mesa_error(ctx
, GL_INVALID_VALUE
,
1583 "glTexImage%dD(border=%d)", dimensions
, border
);
1588 if (width
< 0 || height
< 0 || depth
< 0) {
1590 _mesa_error(ctx
, GL_INVALID_VALUE
,
1591 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1596 /* Do this simple check before calling the TestProxyTexImage() function */
1597 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1598 sizeOK
= (width
== height
);
1602 * Use the proxy texture driver hook to see if the size/level/etc are
1605 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1606 internalFormat
, format
,
1607 type
, width
, height
,
1611 _mesa_error(ctx
, GL_INVALID_VALUE
,
1612 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1613 dimensions
, level
, width
, height
, depth
);
1618 /* Check internalFormat */
1619 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1621 _mesa_error(ctx
, GL_INVALID_VALUE
,
1622 "glTexImage%dD(internalFormat=%s)",
1623 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1628 /* Check incoming image format and type */
1629 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1630 if (err
!= GL_NO_ERROR
) {
1632 _mesa_error(ctx
, err
,
1633 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1634 dimensions
, format
, type
);
1639 /* make sure internal format and format basically agree */
1640 colorFormat
= _mesa_is_color_format(format
);
1641 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1642 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1643 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1644 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1645 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1647 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1648 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1649 dimensions
, internalFormat
, format
);
1653 /* additional checks for ycbcr textures */
1654 if (internalFormat
== GL_YCBCR_MESA
) {
1655 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1656 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1657 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1659 _mesa_snprintf(message
, sizeof(message
),
1660 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1661 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1662 return GL_TRUE
; /* error */
1664 if (target
!= GL_TEXTURE_2D
&&
1665 target
!= GL_PROXY_TEXTURE_2D
&&
1666 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1667 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1669 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1675 _mesa_snprintf(message
, sizeof(message
),
1676 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1677 dimensions
, border
);
1678 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1684 /* additional checks for depth textures */
1685 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1686 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1687 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1688 if (target
!= GL_TEXTURE_1D
&&
1689 target
!= GL_PROXY_TEXTURE_1D
&&
1690 target
!= GL_TEXTURE_2D
&&
1691 target
!= GL_PROXY_TEXTURE_2D
&&
1692 target
!= GL_TEXTURE_1D_ARRAY
&&
1693 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1694 target
!= GL_TEXTURE_2D_ARRAY
&&
1695 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1696 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1697 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1698 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1699 (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_gpu_shader4
))) {
1701 _mesa_error(ctx
, GL_INVALID_ENUM
,
1702 "glTexImage(target/internalFormat)");
1707 /* additional checks for compressed textures */
1708 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1709 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1711 _mesa_error(ctx
, GL_INVALID_ENUM
,
1712 "glTexImage%dD(target)", dimensions
);
1715 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1716 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1717 "glTexImage%dD(no compression for format)", dimensions
);
1722 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1723 "glTexImage%dD(border!=0)", dimensions
);
1729 /* additional checks for integer textures */
1730 if ((ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_texture_integer
) &&
1731 (_mesa_is_integer_format(format
) !=
1732 _mesa_is_integer_format(internalFormat
))) {
1734 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1735 "glTexImage%dD(integer/non-integer format mismatch)",
1741 if (!mutable_tex_object(ctx
, target
)) {
1742 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1743 "glTexImage%dD(immutable texture)", dimensions
);
1747 /* if we get here, the parameters are OK */
1753 * Test glTexSubImage[123]D() parameters for errors.
1755 * \param ctx GL context.
1756 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1757 * \param target texture target given by the user.
1758 * \param level image level given by the user.
1759 * \param xoffset sub-image x offset given by the user.
1760 * \param yoffset sub-image y offset given by the user.
1761 * \param zoffset sub-image z offset given by the user.
1762 * \param format pixel data format given by the user.
1763 * \param type pixel data type given by the user.
1764 * \param width image width given by the user.
1765 * \param height image height given by the user.
1766 * \param depth image depth given by the user.
1768 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1770 * Verifies each of the parameters against the constants specified in
1771 * __struct gl_contextRec::Const and the supported extensions, and according
1772 * to the OpenGL specification.
1775 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1776 GLenum target
, GLint level
,
1777 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1778 GLint width
, GLint height
, GLint depth
,
1779 GLenum format
, GLenum type
)
1783 /* Basic level check */
1784 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1785 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1789 /* Check for negative sizes */
1791 _mesa_error(ctx
, GL_INVALID_VALUE
,
1792 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1795 if (height
< 0 && dimensions
> 1) {
1796 _mesa_error(ctx
, GL_INVALID_VALUE
,
1797 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1800 if (depth
< 0 && dimensions
> 2) {
1801 _mesa_error(ctx
, GL_INVALID_VALUE
,
1802 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1806 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1807 if (err
!= GL_NO_ERROR
) {
1808 _mesa_error(ctx
, err
,
1809 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1810 dimensions
, format
, type
);
1819 * Do second part of glTexSubImage which depends on the destination texture.
1820 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1823 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1824 GLenum target
, GLint level
,
1825 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1826 GLint width
, GLint height
, GLint depth
,
1827 GLenum format
, GLenum type
,
1828 const struct gl_texture_image
*destTex
)
1831 /* undefined image level */
1832 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1836 if (xoffset
< -((GLint
)destTex
->Border
)) {
1837 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1841 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1842 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1846 if (dimensions
> 1) {
1847 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destTex
->Border
;
1848 if (yoffset
< -yBorder
) {
1849 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1853 if (yoffset
+ height
> (GLint
) destTex
->Height
+ yBorder
) {
1854 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1859 if (dimensions
> 2) {
1860 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destTex
->Border
;
1861 if (zoffset
< -zBorder
) {
1862 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1865 if (zoffset
+ depth
> (GLint
) destTex
->Depth
+ zBorder
) {
1866 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1871 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1874 if (compressedteximage_only_format(ctx
, destTex
->InternalFormat
)) {
1875 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1876 "glTexSubImage%dD(no compression for format)", dimensions
);
1880 /* do tests which depend on compression block size */
1881 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1883 /* offset must be multiple of block size */
1884 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1885 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1886 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1887 dimensions
, xoffset
, yoffset
);
1890 /* size must be multiple of bw by bh or equal to whole texture size */
1891 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1892 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1893 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1896 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1897 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1898 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1903 if (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_texture_integer
) {
1904 /* both source and dest must be integer-valued, or neither */
1905 if (_mesa_is_format_integer_color(destTex
->TexFormat
) !=
1906 _mesa_is_integer_format(format
)) {
1907 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1908 "glTexSubImage%dD(integer/non-integer format mismatch)",
1919 * Test glCopyTexImage[12]D() parameters for errors.
1921 * \param ctx GL context.
1922 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1923 * \param target texture target given by the user.
1924 * \param level image level given by the user.
1925 * \param internalFormat internal format given by the user.
1926 * \param width image width given by the user.
1927 * \param height image height given by the user.
1928 * \param border texture border.
1930 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1932 * Verifies each of the parameters against the constants specified in
1933 * __struct gl_contextRec::Const and the supported extensions, and according
1934 * to the OpenGL specification.
1937 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1938 GLenum target
, GLint level
, GLint internalFormat
,
1939 GLint width
, GLint height
, GLint border
)
1941 const GLenum proxyTarget
= get_proxy_target(target
);
1942 const GLenum type
= GL_FLOAT
;
1947 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1948 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1949 dimensions
, _mesa_lookup_enum_by_nr(target
));
1953 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1954 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1955 _mesa_error(ctx
, GL_INVALID_VALUE
,
1956 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1960 /* Check that the source buffer is complete */
1961 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
1962 if (ctx
->ReadBuffer
->_Status
== 0) {
1963 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1965 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1966 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1967 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1971 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
1972 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION
,
1973 "glCopyTexImage%dD(multisample FBO)",
1980 if (border
< 0 || border
> 1 ||
1981 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1982 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1986 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1987 if (baseFormat
< 0) {
1988 _mesa_error(ctx
, GL_INVALID_VALUE
,
1989 "glCopyTexImage%dD(internalFormat)", dimensions
);
1993 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
1994 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1995 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1999 /* From the EXT_texture_integer spec:
2001 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2002 * if the texture internalformat is an integer format and the read color
2003 * buffer is not an integer format, or if the internalformat is not an
2004 * integer format and the read color buffer is an integer format."
2006 if (_mesa_is_color_format(internalFormat
)) {
2007 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2009 if (_mesa_is_integer_format(rb
->InternalFormat
) !=
2010 _mesa_is_integer_format(internalFormat
)) {
2011 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2012 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2017 /* Do size, level checking */
2018 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
2019 ? (width
== height
) : 1;
2021 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
2022 internalFormat
, baseFormat
,
2023 type
, width
, height
,
2027 if (dimensions
== 1) {
2028 _mesa_error(ctx
, GL_INVALID_VALUE
,
2029 "glCopyTexImage1D(width=%d)", width
);
2032 ASSERT(dimensions
== 2);
2033 _mesa_error(ctx
, GL_INVALID_VALUE
,
2034 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2039 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2040 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2041 _mesa_error(ctx
, GL_INVALID_ENUM
,
2042 "glCopyTexImage%dD(target)", dimensions
);
2045 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2046 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2047 "glCopyTexImage%dD(no compression for format)", dimensions
);
2051 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2052 "glCopyTexImage%dD(border!=0)", dimensions
);
2057 if (!mutable_tex_object(ctx
, target
)) {
2058 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2059 "glCopyTexImage%dD(immutable texture)", dimensions
);
2063 /* if we get here, the parameters are OK */
2069 * Test glCopyTexSubImage[12]D() parameters for errors.
2070 * Note that this is the first part of error checking.
2071 * See also copytexsubimage_error_check2() below for the second part.
2073 * \param ctx GL context.
2074 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2075 * \param target texture target given by the user.
2076 * \param level image level given by the user.
2078 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2081 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2082 GLenum target
, GLint level
)
2084 /* Check that the source buffer is complete */
2085 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2086 if (ctx
->ReadBuffer
->_Status
== 0) {
2087 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2089 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2090 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2091 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2095 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2096 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION
,
2097 "glCopyTexSubImage%dD(multisample FBO)",
2103 /* check target (proxies not allowed) */
2104 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2105 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2106 dimensions
, _mesa_lookup_enum_by_nr(target
));
2111 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2112 _mesa_error(ctx
, GL_INVALID_VALUE
,
2113 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2122 * Second part of error checking for glCopyTexSubImage[12]D().
2123 * \param xoffset sub-image x offset given by the user.
2124 * \param yoffset sub-image y offset given by the user.
2125 * \param zoffset sub-image z offset given by the user.
2126 * \param width image width given by the user.
2127 * \param height image height given by the user.
2130 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2131 GLenum target
, GLint level
,
2132 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2133 GLsizei width
, GLsizei height
,
2134 const struct gl_texture_image
*teximage
)
2136 /* check that dest tex image exists */
2138 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2139 "glCopyTexSubImage%dD(undefined texture level: %d)",
2146 _mesa_error(ctx
, GL_INVALID_VALUE
,
2147 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2150 if (dimensions
> 1 && height
< 0) {
2151 _mesa_error(ctx
, GL_INVALID_VALUE
,
2152 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2156 /* check x/y offsets */
2157 if (xoffset
< -((GLint
)teximage
->Border
)) {
2158 _mesa_error(ctx
, GL_INVALID_VALUE
,
2159 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2162 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2163 _mesa_error(ctx
, GL_INVALID_VALUE
,
2164 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2167 if (dimensions
> 1) {
2168 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : teximage
->Border
;
2169 if (yoffset
< -yBorder
) {
2170 _mesa_error(ctx
, GL_INVALID_VALUE
,
2171 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2174 /* NOTE: we're adding the border here, not subtracting! */
2175 if (yoffset
+ height
> (GLint
) teximage
->Height
+ yBorder
) {
2176 _mesa_error(ctx
, GL_INVALID_VALUE
,
2177 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2182 /* check z offset */
2183 if (dimensions
> 2) {
2184 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : teximage
->Border
;
2185 if (zoffset
< -zBorder
) {
2186 _mesa_error(ctx
, GL_INVALID_VALUE
,
2187 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2190 if (zoffset
> (GLint
) teximage
->Depth
+ zBorder
) {
2191 _mesa_error(ctx
, GL_INVALID_VALUE
,
2192 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2197 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2198 if (compressedteximage_only_format(ctx
, teximage
->InternalFormat
)) {
2199 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2200 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2203 /* offset must be multiple of 4 */
2204 if ((xoffset
& 3) || (yoffset
& 3)) {
2205 _mesa_error(ctx
, GL_INVALID_VALUE
,
2206 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2209 /* size must be multiple of 4 */
2210 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2211 _mesa_error(ctx
, GL_INVALID_VALUE
,
2212 "glCopyTexSubImage%dD(width)", dimensions
);
2215 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2216 _mesa_error(ctx
, GL_INVALID_VALUE
,
2217 "glCopyTexSubImage%dD(height)", dimensions
);
2222 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2223 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2227 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2228 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2229 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2230 dimensions
, teximage
->_BaseFormat
);
2234 /* From the EXT_texture_integer spec:
2236 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2237 * if the texture internalformat is an integer format and the read color
2238 * buffer is not an integer format, or if the internalformat is not an
2239 * integer format and the read color buffer is an integer format."
2241 if (_mesa_is_color_format(teximage
->InternalFormat
)) {
2242 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2244 if (_mesa_is_format_integer_color(rb
->Format
) !=
2245 _mesa_is_format_integer_color(teximage
->TexFormat
)) {
2246 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2247 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2252 /* if we get here, the parameters are OK */
2257 /** Callback info for walking over FBO hash table */
2260 struct gl_context
*ctx
;
2261 struct gl_texture_object
*texObj
;
2267 * Check render to texture callback. Called from _mesa_HashWalk().
2270 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2272 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2273 const struct cb_info
*info
= (struct cb_info
*) userData
;
2274 struct gl_context
*ctx
= info
->ctx
;
2275 const struct gl_texture_object
*texObj
= info
->texObj
;
2276 const GLuint level
= info
->level
, face
= info
->face
;
2278 /* If this is a user-created FBO */
2279 if (_mesa_is_user_fbo(fb
)) {
2281 /* check if any of the FBO's attachments point to 'texObj' */
2282 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2283 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2284 if (att
->Type
== GL_TEXTURE
&&
2285 att
->Texture
== texObj
&&
2286 att
->TextureLevel
== level
&&
2287 att
->CubeMapFace
== face
) {
2288 ASSERT(_mesa_get_attachment_teximage(att
));
2289 /* Tell driver about the new renderbuffer texture */
2290 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2291 /* Mark fb status as indeterminate to force re-validation */
2300 * When a texture image is specified we have to check if it's bound to
2301 * any framebuffer objects (render to texture) in order to detect changes
2302 * in size or format since that effects FBO completeness.
2303 * Any FBOs rendering into the texture must be re-validated.
2306 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2307 struct gl_texture_object
*texObj
,
2308 GLuint face
, GLuint level
)
2310 /* Only check this texture if it's been marked as RenderToTexture */
2311 if (texObj
->_RenderToTexture
) {
2312 struct cb_info info
;
2314 info
.texObj
= texObj
;
2317 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2323 * If the texture object's GenerateMipmap flag is set and we've
2324 * changed the texture base level image, regenerate the rest of the
2325 * mipmap levels now.
2328 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2329 struct gl_texture_object
*texObj
, GLint level
)
2331 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2332 if (texObj
->GenerateMipmap
&&
2333 level
== texObj
->BaseLevel
&&
2334 level
< texObj
->MaxLevel
) {
2335 ASSERT(ctx
->Driver
.GenerateMipmap
);
2336 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2341 /** Debug helper: override the user-requested internal format */
2343 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2346 if (internalFormat
== GL_RGBA16F_ARB
||
2347 internalFormat
== GL_RGBA32F_ARB
) {
2348 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2351 else if (internalFormat
== GL_RGB16F_ARB
||
2352 internalFormat
== GL_RGB32F_ARB
) {
2353 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2356 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2357 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2358 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2359 return GL_LUMINANCE_ALPHA
;
2361 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2362 internalFormat
== GL_LUMINANCE32F_ARB
) {
2363 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2364 return GL_LUMINANCE
;
2366 else if (internalFormat
== GL_ALPHA16F_ARB
||
2367 internalFormat
== GL_ALPHA32F_ARB
) {
2368 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2372 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2373 internalFormat = GL_RGBA;
2377 return internalFormat
;
2380 return internalFormat
;
2386 * Choose the actual hardware format for a texture image.
2387 * Try to use the same format as the previous image level when possible.
2388 * Otherwise, ask the driver for the best format.
2389 * It's important to try to choose a consistant format for all levels
2390 * for efficient texture memory layout/allocation. In particular, this
2391 * comes up during automatic mipmap generation.
2394 _mesa_choose_texture_format(struct gl_context
*ctx
,
2395 struct gl_texture_object
*texObj
,
2396 GLenum target
, GLint level
,
2397 GLenum internalFormat
, GLenum format
, GLenum type
)
2401 /* see if we've already chosen a format for the previous level */
2403 struct gl_texture_image
*prevImage
=
2404 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2405 /* See if the prev level is defined and has an internal format which
2406 * matches the new internal format.
2409 prevImage
->Width
> 0 &&
2410 prevImage
->InternalFormat
== internalFormat
) {
2411 /* use the same format */
2412 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2413 return prevImage
->TexFormat
;
2417 /* choose format from scratch */
2418 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2419 ASSERT(f
!= MESA_FORMAT_NONE
);
2424 * Adjust pixel unpack params and image dimensions to strip off the
2425 * one-pixel texture border.
2427 * Gallium and intel don't support texture borders. They've seldem been used
2428 * and seldom been implemented correctly anyway.
2430 * \param unpackNew returns the new pixel unpack parameters
2433 strip_texture_border(GLenum target
,
2434 GLint
*width
, GLint
*height
, GLint
*depth
,
2435 const struct gl_pixelstore_attrib
*unpack
,
2436 struct gl_pixelstore_attrib
*unpackNew
)
2442 *unpackNew
= *unpack
;
2444 if (unpackNew
->RowLength
== 0)
2445 unpackNew
->RowLength
= *width
;
2447 if (unpackNew
->ImageHeight
== 0)
2448 unpackNew
->ImageHeight
= *height
;
2450 assert(*width
>= 3);
2451 unpackNew
->SkipPixels
++; /* skip the border */
2452 *width
= *width
- 2; /* reduce the width by two border pixels */
2454 /* The min height of a texture with a border is 3 */
2455 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2456 unpackNew
->SkipRows
++; /* skip the border */
2457 *height
= *height
- 2; /* reduce the height by two border pixels */
2460 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
) {
2461 unpackNew
->SkipImages
++; /* skip the border */
2462 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2467 * Common code to implement all the glTexImage1D/2D/3D functions.
2470 teximage(struct gl_context
*ctx
, GLuint dims
,
2471 GLenum target
, GLint level
, GLint internalFormat
,
2472 GLsizei width
, GLsizei height
, GLsizei depth
,
2473 GLint border
, GLenum format
, GLenum type
,
2474 const GLvoid
*pixels
)
2477 struct gl_pixelstore_attrib unpack_no_border
;
2478 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2480 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2482 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2483 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2485 _mesa_lookup_enum_by_nr(target
), level
,
2486 _mesa_lookup_enum_by_nr(internalFormat
),
2487 width
, height
, depth
, border
,
2488 _mesa_lookup_enum_by_nr(format
),
2489 _mesa_lookup_enum_by_nr(type
), pixels
);
2491 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2493 /* target error checking */
2494 if (!legal_teximage_target(ctx
, dims
, target
)) {
2495 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2496 dims
, _mesa_lookup_enum_by_nr(target
));
2500 /* general error checking */
2501 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2502 format
, type
, width
, height
, depth
, border
);
2504 if (_mesa_is_proxy_texture(target
)) {
2505 /* Proxy texture: just clear or set state depending on error checking */
2506 struct gl_texture_image
*texImage
=
2507 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2510 /* when error, clear all proxy texture image parameters */
2512 clear_teximage_fields(texImage
);
2515 /* no error, set the tex image parameters */
2516 struct gl_texture_object
*texObj
=
2517 _mesa_get_current_tex_object(ctx
, target
);
2518 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2523 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2524 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
2525 depth
, border
, internalFormat
,
2528 else if (texImage
) {
2529 clear_teximage_fields(texImage
);
2534 /* non-proxy target */
2535 const GLuint face
= _mesa_tex_target_to_face(target
);
2536 struct gl_texture_object
*texObj
;
2537 struct gl_texture_image
*texImage
;
2540 return; /* error was recorded */
2543 /* Allow a hardware driver to just strip out the border, to provide
2544 * reliable but slightly incorrect hardware rendering instead of
2545 * rarely-tested software fallback rendering.
2547 if (border
&& ctx
->Const
.StripTextureBorder
) {
2548 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
2551 unpack
= &unpack_no_border
;
2554 if (ctx
->NewState
& _NEW_PIXEL
)
2555 _mesa_update_state(ctx
);
2557 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2559 _mesa_lock_texture(ctx
, texObj
);
2561 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2564 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2567 gl_format texFormat
;
2569 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2571 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2572 internalFormat
, format
,
2575 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2576 _mesa_init_teximage_fields(ctx
, texImage
,
2577 width
, height
, depth
,
2578 border
, internalFormat
, texFormat
);
2580 /* Give the texture to the driver. <pixels> may be null. */
2581 ASSERT(ctx
->Driver
.TexImage3D
);
2584 ctx
->Driver
.TexImage1D(ctx
, texImage
, internalFormat
,
2585 width
, border
, format
,
2586 type
, pixels
, unpack
);
2589 ctx
->Driver
.TexImage2D(ctx
, texImage
, internalFormat
,
2590 width
, height
, border
, format
,
2591 type
, pixels
, unpack
);
2594 ctx
->Driver
.TexImage3D(ctx
, texImage
, internalFormat
,
2595 width
, height
, depth
, border
, format
,
2596 type
, pixels
, unpack
);
2599 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2602 check_gen_mipmap(ctx
, target
, texObj
, level
);
2604 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2606 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2609 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2613 _mesa_unlock_texture(ctx
, texObj
);
2619 * Called from the API. Note that width includes the border.
2622 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2623 GLsizei width
, GLint border
, GLenum format
,
2624 GLenum type
, const GLvoid
*pixels
)
2626 GET_CURRENT_CONTEXT(ctx
);
2627 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2628 border
, format
, type
, pixels
);
2633 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2634 GLsizei width
, GLsizei height
, GLint border
,
2635 GLenum format
, GLenum type
,
2636 const GLvoid
*pixels
)
2638 GET_CURRENT_CONTEXT(ctx
);
2639 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2640 border
, format
, type
, pixels
);
2645 * Called by the API or display list executor.
2646 * Note that width and height include the border.
2649 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2650 GLsizei width
, GLsizei height
, GLsizei depth
,
2651 GLint border
, GLenum format
, GLenum type
,
2652 const GLvoid
*pixels
)
2654 GET_CURRENT_CONTEXT(ctx
);
2655 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2656 border
, format
, type
, pixels
);
2661 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2662 GLsizei width
, GLsizei height
, GLsizei depth
,
2663 GLint border
, GLenum format
, GLenum type
,
2664 const GLvoid
*pixels
)
2666 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2667 depth
, border
, format
, type
, pixels
);
2671 #if FEATURE_OES_EGL_image
2673 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2675 struct gl_texture_object
*texObj
;
2676 struct gl_texture_image
*texImage
;
2677 GET_CURRENT_CONTEXT(ctx
);
2678 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2680 if ((target
== GL_TEXTURE_2D
&&
2681 !ctx
->Extensions
.OES_EGL_image
) ||
2682 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2683 !ctx
->Extensions
.OES_EGL_image_external
)) {
2684 _mesa_error(ctx
, GL_INVALID_ENUM
,
2685 "glEGLImageTargetTexture2D(target=%d)", target
);
2689 if (ctx
->NewState
& _NEW_PIXEL
)
2690 _mesa_update_state(ctx
);
2692 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2693 _mesa_lock_texture(ctx
, texObj
);
2695 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2697 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2699 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2701 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2702 texObj
, texImage
, image
);
2704 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2706 _mesa_unlock_texture(ctx
, texObj
);
2714 * Implement all the glTexSubImage1/2/3D() functions.
2717 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2718 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2719 GLsizei width
, GLsizei height
, GLsizei depth
,
2720 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2722 struct gl_texture_object
*texObj
;
2723 struct gl_texture_image
*texImage
;
2725 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2727 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2728 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2730 _mesa_lookup_enum_by_nr(target
), level
,
2731 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2732 _mesa_lookup_enum_by_nr(format
),
2733 _mesa_lookup_enum_by_nr(type
), pixels
);
2735 /* check target (proxies not allowed) */
2736 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2737 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2738 dims
, _mesa_lookup_enum_by_nr(target
));
2742 if (ctx
->NewState
& _NEW_PIXEL
)
2743 _mesa_update_state(ctx
);
2745 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2746 width
, height
, depth
, format
, type
)) {
2747 return; /* error was detected */
2750 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2752 _mesa_lock_texture(ctx
, texObj
);
2754 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2756 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2757 xoffset
, yoffset
, zoffset
,
2758 width
, height
, depth
,
2759 format
, type
, texImage
)) {
2760 /* error was recorded */
2762 else if (width
> 0 && height
> 0 && depth
> 0) {
2763 /* If we have a border, offset=-1 is legal. Bias by border width. */
2766 if (target
!= GL_TEXTURE_2D_ARRAY
)
2767 zoffset
+= texImage
->Border
;
2770 if (target
!= GL_TEXTURE_1D_ARRAY
)
2771 yoffset
+= texImage
->Border
;
2774 xoffset
+= texImage
->Border
;
2779 ctx
->Driver
.TexSubImage1D(ctx
, texImage
,
2781 format
, type
, pixels
, &ctx
->Unpack
);
2784 ctx
->Driver
.TexSubImage2D(ctx
, texImage
,
2785 xoffset
, yoffset
, width
, height
,
2786 format
, type
, pixels
, &ctx
->Unpack
);
2789 ctx
->Driver
.TexSubImage3D(ctx
, texImage
,
2790 xoffset
, yoffset
, zoffset
,
2791 width
, height
, depth
,
2792 format
, type
, pixels
, &ctx
->Unpack
);
2795 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2798 check_gen_mipmap(ctx
, target
, texObj
, level
);
2800 ctx
->NewState
|= _NEW_TEXTURE
;
2803 _mesa_unlock_texture(ctx
, texObj
);
2808 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2809 GLint xoffset
, GLsizei width
,
2810 GLenum format
, GLenum type
,
2811 const GLvoid
*pixels
)
2813 GET_CURRENT_CONTEXT(ctx
);
2814 texsubimage(ctx
, 1, target
, level
,
2817 format
, type
, pixels
);
2822 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2823 GLint xoffset
, GLint yoffset
,
2824 GLsizei width
, GLsizei height
,
2825 GLenum format
, GLenum type
,
2826 const GLvoid
*pixels
)
2828 GET_CURRENT_CONTEXT(ctx
);
2829 texsubimage(ctx
, 2, target
, level
,
2830 xoffset
, yoffset
, 0,
2832 format
, type
, pixels
);
2838 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2839 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2840 GLsizei width
, GLsizei height
, GLsizei depth
,
2841 GLenum format
, GLenum type
,
2842 const GLvoid
*pixels
)
2844 GET_CURRENT_CONTEXT(ctx
);
2845 texsubimage(ctx
, 3, target
, level
,
2846 xoffset
, yoffset
, zoffset
,
2847 width
, height
, depth
,
2848 format
, type
, pixels
);
2854 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
2855 * from. This depends on whether the texture contains color or depth values.
2857 static struct gl_renderbuffer
*
2858 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
2860 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
2861 /* reading from depth/stencil buffer */
2862 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
2865 /* copying from color buffer */
2866 return ctx
->ReadBuffer
->_ColorReadBuffer
;
2873 * Implement the glCopyTexImage1/2D() functions.
2876 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2877 GLenum target
, GLint level
, GLenum internalFormat
,
2878 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2880 struct gl_texture_object
*texObj
;
2881 struct gl_texture_image
*texImage
;
2882 const GLuint face
= _mesa_tex_target_to_face(target
);
2884 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2886 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2887 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2889 _mesa_lookup_enum_by_nr(target
), level
,
2890 _mesa_lookup_enum_by_nr(internalFormat
),
2891 x
, y
, width
, height
, border
);
2893 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2894 _mesa_update_state(ctx
);
2896 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2897 width
, height
, border
))
2900 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2902 if (border
&& ctx
->Const
.StripTextureBorder
) {
2904 width
-= border
* 2;
2907 height
-= border
* 2;
2912 _mesa_lock_texture(ctx
, texObj
);
2914 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2917 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2920 /* choose actual hw format */
2921 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2926 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2927 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2929 /* Free old texture image */
2930 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2932 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
2933 border
, internalFormat
, texFormat
);
2935 /* Allocate texture memory (no pixel data yet) */
2937 ctx
->Driver
.TexImage1D(ctx
, texImage
, internalFormat
,
2938 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2942 ctx
->Driver
.TexImage2D(ctx
, texImage
, internalFormat
,
2943 width
, height
, border
, GL_NONE
, GL_NONE
,
2944 NULL
, &ctx
->Unpack
);
2947 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2949 struct gl_renderbuffer
*srcRb
=
2950 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
2953 ctx
->Driver
.CopyTexSubImage1D(ctx
, texImage
, dstX
,
2954 srcRb
, srcX
, srcY
, width
);
2957 ctx
->Driver
.CopyTexSubImage2D(ctx
, texImage
, dstX
, dstY
,
2958 srcRb
, srcX
, srcY
, width
, height
);
2961 check_gen_mipmap(ctx
, target
, texObj
, level
);
2963 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2965 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2968 /* probably too large of image */
2969 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2973 _mesa_unlock_texture(ctx
, texObj
);
2979 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2980 GLenum internalFormat
,
2982 GLsizei width
, GLint border
)
2984 GET_CURRENT_CONTEXT(ctx
);
2985 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2991 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2992 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2995 GET_CURRENT_CONTEXT(ctx
);
2996 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2997 x
, y
, width
, height
, border
);
3003 * Implementation for glCopyTexSubImage1/2/3D() functions.
3006 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3007 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3008 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3010 struct gl_texture_object
*texObj
;
3011 struct gl_texture_image
*texImage
;
3013 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3015 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3016 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3018 _mesa_lookup_enum_by_nr(target
),
3019 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3021 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3022 _mesa_update_state(ctx
);
3024 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
3027 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3029 _mesa_lock_texture(ctx
, texObj
);
3031 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3033 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
3034 zoffset
, width
, height
, texImage
)) {
3035 /* error was recored */
3038 /* If we have a border, offset=-1 is legal. Bias by border width. */
3041 if (target
!= GL_TEXTURE_2D_ARRAY
)
3042 zoffset
+= texImage
->Border
;
3045 if (target
!= GL_TEXTURE_1D_ARRAY
)
3046 yoffset
+= texImage
->Border
;
3049 xoffset
+= texImage
->Border
;
3052 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3054 struct gl_renderbuffer
*srcRb
=
3055 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3059 ctx
->Driver
.CopyTexSubImage1D(ctx
, texImage
, xoffset
,
3060 srcRb
, x
, y
, width
);
3063 ctx
->Driver
.CopyTexSubImage2D(ctx
, texImage
, xoffset
, yoffset
,
3064 srcRb
, x
, y
, width
, height
);
3067 ctx
->Driver
.CopyTexSubImage3D(ctx
, texImage
,
3068 xoffset
, yoffset
, zoffset
,
3069 srcRb
, x
, y
, width
, height
);
3072 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
3075 check_gen_mipmap(ctx
, target
, texObj
, level
);
3077 ctx
->NewState
|= _NEW_TEXTURE
;
3081 _mesa_unlock_texture(ctx
, texObj
);
3086 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3087 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3089 GET_CURRENT_CONTEXT(ctx
);
3090 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3096 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3097 GLint xoffset
, GLint yoffset
,
3098 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3100 GET_CURRENT_CONTEXT(ctx
);
3101 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3108 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3109 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3110 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3112 GET_CURRENT_CONTEXT(ctx
);
3113 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3114 x
, y
, width
, height
);
3120 /**********************************************************************/
3121 /****** Compressed Textures ******/
3122 /**********************************************************************/
3126 * Return expected size of a compressed texture.
3129 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3132 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3133 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3138 * Return compressed texture block size, in pixels.
3141 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3143 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3144 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3149 * Error checking for glCompressedTexImage[123]D().
3150 * \param reason returns reason for error, if any
3151 * \return error code or GL_NO_ERROR.
3154 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3155 GLenum target
, GLint level
,
3156 GLenum internalFormat
, GLsizei width
,
3157 GLsizei height
, GLsizei depth
, GLint border
,
3158 GLsizei imageSize
, char **reason
)
3160 const GLenum proxyTarget
= get_proxy_target(target
);
3161 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3163 GLenum choose_format
;
3165 GLenum proxy_format
;
3167 *reason
= ""; /* no error */
3169 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3171 return GL_INVALID_ENUM
;
3174 /* This will detect any invalid internalFormat value */
3175 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3176 *reason
= "internalFormat";
3177 return GL_INVALID_ENUM
;
3180 switch (internalFormat
) {
3182 case GL_PALETTE4_RGB8_OES
:
3183 case GL_PALETTE4_RGBA8_OES
:
3184 case GL_PALETTE4_R5_G6_B5_OES
:
3185 case GL_PALETTE4_RGBA4_OES
:
3186 case GL_PALETTE4_RGB5_A1_OES
:
3187 case GL_PALETTE8_RGB8_OES
:
3188 case GL_PALETTE8_RGBA8_OES
:
3189 case GL_PALETTE8_R5_G6_B5_OES
:
3190 case GL_PALETTE8_RGBA4_OES
:
3191 case GL_PALETTE8_RGB5_A1_OES
:
3192 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3194 proxy_format
= choose_format
;
3197 if (level
> 0 || level
< -maxLevels
) {
3199 return GL_INVALID_VALUE
;
3202 if (dimensions
!= 2) {
3203 *reason
= "compressed paletted textures must be 2D";
3204 return GL_INVALID_OPERATION
;
3207 /* Figure out the expected texture size (in bytes). This will be
3208 * checked against the actual size later.
3210 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3213 /* This is for the benefit of the TestProxyTexImage below. It expects
3214 * level to be non-negative. OES_compressed_paletted_texture uses a
3215 * weird mechanism where the level specified to glCompressedTexImage2D
3216 * is -(n-1) number of levels in the texture, and the data specifies the
3217 * complete mipmap stack. This is done to ensure the palette is the
3218 * same for all levels.
3225 choose_format
= GL_NONE
;
3226 choose_type
= GL_NONE
;
3227 proxy_format
= internalFormat
;
3230 if (level
< 0 || level
>= maxLevels
) {
3232 return GL_INVALID_VALUE
;
3235 /* Figure out the expected texture size (in bytes). This will be
3236 * checked against the actual size later.
3238 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3242 /* This should really never fail */
3243 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3244 *reason
= "internalFormat";
3245 return GL_INVALID_ENUM
;
3248 /* No compressed formats support borders at this time */
3250 *reason
= "border != 0";
3251 return GL_INVALID_VALUE
;
3254 /* For cube map, width must equal height */
3255 if (_mesa_is_cube_face(target
) && width
!= height
) {
3256 *reason
= "width != height";
3257 return GL_INVALID_VALUE
;
3260 /* check image size against compression block size */
3262 gl_format texFormat
=
3263 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3264 choose_format
, choose_type
);
3267 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3268 if ((width
> bw
&& width
% bw
> 0) ||
3269 (height
> bh
&& height
% bh
> 0)) {
3271 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3272 * generated [...] if any parameter combinations are not
3273 * supported by the specific compressed internal format.
3275 *reason
= "invalid width or height for compression format";
3276 return GL_INVALID_OPERATION
;
3280 /* check image sizes */
3281 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3282 proxy_format
, choose_format
,
3284 width
, height
, depth
, border
)) {
3285 /* See error comment above */
3286 *reason
= "invalid width, height or format";
3287 return GL_INVALID_OPERATION
;
3290 /* check image size in bytes */
3291 if (expectedSize
!= imageSize
) {
3292 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3293 * if <imageSize> is not consistent with the format, dimensions, and
3294 * contents of the specified image.
3296 *reason
= "imageSize inconsistant with width/height/format";
3297 return GL_INVALID_VALUE
;
3300 if (!mutable_tex_object(ctx
, target
)) {
3301 *reason
= "immutable texture";
3302 return GL_INVALID_OPERATION
;
3310 * Error checking for glCompressedTexSubImage[123]D().
3311 * \warning There are some bad assumptions here about the size of compressed
3312 * texture tiles (multiple of 4) used to test the validity of the
3313 * offset and size parameters.
3314 * \return error code or GL_NO_ERROR.
3317 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3318 GLenum target
, GLint level
,
3319 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3320 GLsizei width
, GLsizei height
, GLsizei depth
,
3321 GLenum format
, GLsizei imageSize
)
3323 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3327 if (dimensions
== 1) {
3328 /* 1D compressed textures not allowed */
3329 return GL_INVALID_ENUM
;
3331 else if (dimensions
== 2) {
3332 if (target
== GL_PROXY_TEXTURE_2D
) {
3333 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3335 else if (target
== GL_TEXTURE_2D
) {
3336 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3338 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3339 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3340 return GL_INVALID_ENUM
; /*target*/
3341 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3343 else if (_mesa_is_cube_face(target
)) {
3344 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3345 return GL_INVALID_ENUM
; /*target*/
3346 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3349 return GL_INVALID_ENUM
; /*target*/
3352 else if (dimensions
== 3) {
3353 /* 3D compressed textures not allowed */
3354 return GL_INVALID_ENUM
;
3357 maxTextureSize
= 1 << (maxLevels
- 1);
3359 /* this will catch any invalid compressed format token */
3360 if (!_mesa_is_compressed_format(ctx
, format
))
3361 return GL_INVALID_ENUM
;
3363 if (width
< 1 || width
> maxTextureSize
)
3364 return GL_INVALID_VALUE
;
3366 if ((height
< 1 || height
> maxTextureSize
)
3368 return GL_INVALID_VALUE
;
3370 if (level
< 0 || level
>= maxLevels
)
3371 return GL_INVALID_VALUE
;
3374 * do checks which depend on compression block size
3376 get_compressed_block_size(format
, &bw
, &bh
);
3378 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3379 return GL_INVALID_VALUE
;
3381 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3382 return GL_INVALID_VALUE
;
3384 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3385 return GL_INVALID_VALUE
;
3387 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3388 if (expectedSize
!= imageSize
)
3389 return GL_INVALID_VALUE
;
3396 * Do second part of glCompressedTexSubImage error checking.
3397 * \return GL_TRUE if error found, GL_FALSE otherwise.
3400 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3401 GLsizei width
, GLsizei height
,
3402 GLsizei depth
, GLenum format
,
3403 struct gl_texture_image
*texImage
)
3406 if ((GLint
) format
!= texImage
->InternalFormat
) {
3407 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3408 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3412 if (compressedteximage_only_format(ctx
, format
)) {
3413 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3414 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3419 if (((width
== 1 || width
== 2) &&
3420 width
!= (GLsizei
) texImage
->Width
) ||
3421 (width
> (GLsizei
) texImage
->Width
)) {
3422 _mesa_error(ctx
, GL_INVALID_VALUE
,
3423 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3428 if (((height
== 1 || height
== 2) &&
3429 height
!= (GLsizei
) texImage
->Height
) ||
3430 (height
> (GLsizei
) texImage
->Height
)) {
3431 _mesa_error(ctx
, GL_INVALID_VALUE
,
3432 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3438 if (((depth
== 1 || depth
== 2) &&
3439 depth
!= (GLsizei
) texImage
->Depth
) ||
3440 (depth
> (GLsizei
) texImage
->Depth
)) {
3441 _mesa_error(ctx
, GL_INVALID_VALUE
,
3442 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3452 * Implementation of the glCompressedTexImage1/2/3D() functions.
3455 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3456 GLenum target
, GLint level
,
3457 GLenum internalFormat
, GLsizei width
,
3458 GLsizei height
, GLsizei depth
, GLint border
,
3459 GLsizei imageSize
, const GLvoid
*data
)
3464 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3466 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3468 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3470 _mesa_lookup_enum_by_nr(target
), level
,
3471 _mesa_lookup_enum_by_nr(internalFormat
),
3472 width
, height
, depth
, border
, imageSize
, data
);
3475 if (!legal_teximage_target(ctx
, dims
, target
)) {
3476 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3477 dims
, _mesa_lookup_enum_by_nr(target
));
3481 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3482 internalFormat
, width
, height
, depth
,
3483 border
, imageSize
, &reason
);
3486 /* XXX this is kind of a hack */
3487 if (!error
&& dims
== 2) {
3488 switch (internalFormat
) {
3489 case GL_PALETTE4_RGB8_OES
:
3490 case GL_PALETTE4_RGBA8_OES
:
3491 case GL_PALETTE4_R5_G6_B5_OES
:
3492 case GL_PALETTE4_RGBA4_OES
:
3493 case GL_PALETTE4_RGB5_A1_OES
:
3494 case GL_PALETTE8_RGB8_OES
:
3495 case GL_PALETTE8_RGBA8_OES
:
3496 case GL_PALETTE8_R5_G6_B5_OES
:
3497 case GL_PALETTE8_RGBA4_OES
:
3498 case GL_PALETTE8_RGB5_A1_OES
:
3499 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3500 width
, height
, imageSize
, data
);
3506 if (_mesa_is_proxy_texture(target
)) {
3507 /* Proxy texture: just check for errors and update proxy state */
3508 struct gl_texture_image
*texImage
;
3511 struct gl_texture_object
*texObj
=
3512 _mesa_get_current_tex_object(ctx
, target
);
3513 gl_format texFormat
=
3514 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3515 internalFormat
, GL_NONE
, GL_NONE
);
3516 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3517 error
= GL_OUT_OF_MEMORY
;
3521 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3524 /* if error, clear all proxy texture image parameters */
3525 clear_teximage_fields(texImage
);
3528 /* no error: store the teximage parameters */
3529 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
3530 depth
, border
, internalFormat
,
3536 /* non-proxy target */
3537 struct gl_texture_object
*texObj
;
3538 struct gl_texture_image
*texImage
;
3541 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3545 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3547 _mesa_lock_texture(ctx
, texObj
);
3549 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3551 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3552 "glCompressedTexImage%uD", dims
);
3555 gl_format texFormat
;
3557 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3559 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3560 internalFormat
, GL_NONE
,
3563 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3564 _mesa_init_teximage_fields(ctx
, texImage
,
3565 width
, height
, depth
,
3566 border
, internalFormat
, texFormat
);
3570 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3571 ctx
->Driver
.CompressedTexImage1D(ctx
, texImage
,
3574 border
, imageSize
, data
);
3577 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3578 ctx
->Driver
.CompressedTexImage2D(ctx
, texImage
,
3581 border
, imageSize
, data
);
3584 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3585 ctx
->Driver
.CompressedTexImage3D(ctx
, texImage
,
3587 width
, height
, depth
,
3588 border
, imageSize
, data
);
3591 _mesa_problem(ctx
, "bad dims in compressedteximage");
3594 check_gen_mipmap(ctx
, target
, texObj
, level
);
3596 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3599 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3600 "glCompressedTexImage%uD", dims
);
3604 _mesa_unlock_texture(ctx
, texObj
);
3610 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3611 GLenum internalFormat
, GLsizei width
,
3612 GLint border
, GLsizei imageSize
,
3615 GET_CURRENT_CONTEXT(ctx
);
3616 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3617 width
, 1, 1, border
, imageSize
, data
);
3622 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3623 GLenum internalFormat
, GLsizei width
,
3624 GLsizei height
, GLint border
, GLsizei imageSize
,
3627 GET_CURRENT_CONTEXT(ctx
);
3628 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3629 width
, height
, 1, border
, imageSize
, data
);
3634 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3635 GLenum internalFormat
, GLsizei width
,
3636 GLsizei height
, GLsizei depth
, GLint border
,
3637 GLsizei imageSize
, const GLvoid
*data
)
3639 GET_CURRENT_CONTEXT(ctx
);
3640 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3641 width
, height
, depth
, border
, imageSize
, data
);
3646 * Common helper for glCompressedTexSubImage1/2/3D().
3649 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3650 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3651 GLsizei width
, GLsizei height
, GLsizei depth
,
3652 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3654 struct gl_texture_object
*texObj
;
3655 struct gl_texture_image
*texImage
;
3657 GET_CURRENT_CONTEXT(ctx
);
3658 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3660 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3661 xoffset
, 0, 0, /* pos */
3662 width
, height
, depth
, /* size */
3665 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3669 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3671 _mesa_lock_texture(ctx
, texObj
);
3673 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3676 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3677 format
, texImage
)) {
3678 /* error was recorded */
3680 else if (width
> 0 && height
> 0 && depth
> 0) {
3683 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3684 ctx
->Driver
.CompressedTexSubImage1D(ctx
, texImage
,
3686 format
, imageSize
, data
);
3690 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3691 ctx
->Driver
.CompressedTexSubImage2D(ctx
, texImage
,
3694 format
, imageSize
, data
);
3698 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3699 ctx
->Driver
.CompressedTexSubImage3D(ctx
, texImage
,
3700 xoffset
, yoffset
, zoffset
,
3701 width
, height
, depth
,
3702 format
, imageSize
, data
);
3709 check_gen_mipmap(ctx
, target
, texObj
, level
);
3711 ctx
->NewState
|= _NEW_TEXTURE
;
3714 _mesa_unlock_texture(ctx
, texObj
);
3719 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3720 GLsizei width
, GLenum format
,
3721 GLsizei imageSize
, const GLvoid
*data
)
3723 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3724 format
, imageSize
, data
);
3729 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3730 GLint yoffset
, GLsizei width
, GLsizei height
,
3731 GLenum format
, GLsizei imageSize
,
3734 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3735 width
, height
, 1, format
, imageSize
, data
);
3740 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3741 GLint yoffset
, GLint zoffset
, GLsizei width
,
3742 GLsizei height
, GLsizei depth
, GLenum format
,
3743 GLsizei imageSize
, const GLvoid
*data
)
3745 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3746 width
, height
, depth
, format
, imageSize
, data
);
3750 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3752 switch (internalFormat
) {
3754 return MESA_FORMAT_A8
;
3756 return MESA_FORMAT_A16
;
3757 case GL_ALPHA16F_ARB
:
3758 return MESA_FORMAT_ALPHA_FLOAT16
;
3759 case GL_ALPHA32F_ARB
:
3760 return MESA_FORMAT_ALPHA_FLOAT32
;
3761 case GL_ALPHA8I_EXT
:
3762 return MESA_FORMAT_ALPHA_INT8
;
3763 case GL_ALPHA16I_EXT
:
3764 return MESA_FORMAT_ALPHA_INT16
;
3765 case GL_ALPHA32I_EXT
:
3766 return MESA_FORMAT_ALPHA_INT32
;
3767 case GL_ALPHA8UI_EXT
:
3768 return MESA_FORMAT_ALPHA_UINT8
;
3769 case GL_ALPHA16UI_EXT
:
3770 return MESA_FORMAT_ALPHA_UINT16
;
3771 case GL_ALPHA32UI_EXT
:
3772 return MESA_FORMAT_ALPHA_UINT32
;
3774 return MESA_FORMAT_L8
;
3775 case GL_LUMINANCE16
:
3776 return MESA_FORMAT_L16
;
3777 case GL_LUMINANCE16F_ARB
:
3778 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3779 case GL_LUMINANCE32F_ARB
:
3780 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3781 case GL_LUMINANCE8I_EXT
:
3782 return MESA_FORMAT_LUMINANCE_INT8
;
3783 case GL_LUMINANCE16I_EXT
:
3784 return MESA_FORMAT_LUMINANCE_INT16
;
3785 case GL_LUMINANCE32I_EXT
:
3786 return MESA_FORMAT_LUMINANCE_INT32
;
3787 case GL_LUMINANCE8UI_EXT
:
3788 return MESA_FORMAT_LUMINANCE_UINT8
;
3789 case GL_LUMINANCE16UI_EXT
:
3790 return MESA_FORMAT_LUMINANCE_UINT16
;
3791 case GL_LUMINANCE32UI_EXT
:
3792 return MESA_FORMAT_LUMINANCE_UINT32
;
3793 case GL_LUMINANCE8_ALPHA8
:
3794 return MESA_FORMAT_AL88
;
3795 case GL_LUMINANCE16_ALPHA16
:
3796 return MESA_FORMAT_AL1616
;
3797 case GL_LUMINANCE_ALPHA16F_ARB
:
3798 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3799 case GL_LUMINANCE_ALPHA32F_ARB
:
3800 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3801 case GL_LUMINANCE_ALPHA8I_EXT
:
3802 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3803 case GL_LUMINANCE_ALPHA16I_EXT
:
3804 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3805 case GL_LUMINANCE_ALPHA32I_EXT
:
3806 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3807 case GL_LUMINANCE_ALPHA8UI_EXT
:
3808 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3809 case GL_LUMINANCE_ALPHA16UI_EXT
:
3810 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3811 case GL_LUMINANCE_ALPHA32UI_EXT
:
3812 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3814 return MESA_FORMAT_I8
;
3815 case GL_INTENSITY16
:
3816 return MESA_FORMAT_I16
;
3817 case GL_INTENSITY16F_ARB
:
3818 return MESA_FORMAT_INTENSITY_FLOAT16
;
3819 case GL_INTENSITY32F_ARB
:
3820 return MESA_FORMAT_INTENSITY_FLOAT32
;
3821 case GL_INTENSITY8I_EXT
:
3822 return MESA_FORMAT_INTENSITY_INT8
;
3823 case GL_INTENSITY16I_EXT
:
3824 return MESA_FORMAT_INTENSITY_INT16
;
3825 case GL_INTENSITY32I_EXT
:
3826 return MESA_FORMAT_INTENSITY_INT32
;
3827 case GL_INTENSITY8UI_EXT
:
3828 return MESA_FORMAT_INTENSITY_UINT8
;
3829 case GL_INTENSITY16UI_EXT
:
3830 return MESA_FORMAT_INTENSITY_UINT16
;
3831 case GL_INTENSITY32UI_EXT
:
3832 return MESA_FORMAT_INTENSITY_UINT32
;
3834 return MESA_FORMAT_RGBA8888_REV
;
3836 return MESA_FORMAT_RGBA_16
;
3837 case GL_RGBA16F_ARB
:
3838 return MESA_FORMAT_RGBA_FLOAT16
;
3839 case GL_RGBA32F_ARB
:
3840 return MESA_FORMAT_RGBA_FLOAT32
;
3842 return MESA_FORMAT_RGBA_INT8
;
3843 case GL_RGBA16I_EXT
:
3844 return MESA_FORMAT_RGBA_INT16
;
3845 case GL_RGBA32I_EXT
:
3846 return MESA_FORMAT_RGBA_INT32
;
3847 case GL_RGBA8UI_EXT
:
3848 return MESA_FORMAT_RGBA_UINT8
;
3849 case GL_RGBA16UI_EXT
:
3850 return MESA_FORMAT_RGBA_UINT16
;
3851 case GL_RGBA32UI_EXT
:
3852 return MESA_FORMAT_RGBA_UINT32
;
3855 return MESA_FORMAT_GR88
;
3857 return MESA_FORMAT_RG1616
;
3859 return MESA_FORMAT_RG_FLOAT16
;
3861 return MESA_FORMAT_RG_FLOAT32
;
3863 return MESA_FORMAT_RG_INT8
;
3865 return MESA_FORMAT_RG_INT16
;
3867 return MESA_FORMAT_RG_INT32
;
3869 return MESA_FORMAT_RG_UINT8
;
3871 return MESA_FORMAT_RG_UINT16
;
3873 return MESA_FORMAT_RG_UINT32
;
3876 return MESA_FORMAT_R8
;
3878 return MESA_FORMAT_R16
;
3880 return MESA_FORMAT_R_FLOAT16
;
3882 return MESA_FORMAT_R_FLOAT32
;
3884 return MESA_FORMAT_R_INT8
;
3886 return MESA_FORMAT_R_INT16
;
3888 return MESA_FORMAT_R_INT32
;
3890 return MESA_FORMAT_R_UINT8
;
3892 return MESA_FORMAT_R_UINT16
;
3894 return MESA_FORMAT_R_UINT32
;
3897 return MESA_FORMAT_NONE
;
3902 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3904 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
3907 if (format
== MESA_FORMAT_NONE
)
3908 return MESA_FORMAT_NONE
;
3910 datatype
= _mesa_get_format_datatype(format
);
3911 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3912 return MESA_FORMAT_NONE
;
3914 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3915 return MESA_FORMAT_NONE
;
3917 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
3918 * any mention of R/RG formats, but they appear in the GL 3.1 core
3921 if (ctx
->VersionMajor
< 3 ||
3922 (ctx
->VersionMajor
== 3 && ctx
->VersionMinor
== 0)) {
3923 GLenum base_format
= _mesa_get_format_base_format(format
);
3925 if (base_format
== GL_R
|| base_format
== GL_RG
)
3926 return MESA_FORMAT_NONE
;
3932 /** GL_ARB_texture_buffer_object */
3934 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3936 struct gl_texture_object
*texObj
;
3937 struct gl_buffer_object
*bufObj
;
3940 GET_CURRENT_CONTEXT(ctx
);
3941 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3943 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3944 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3948 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3949 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3953 format
= validate_texbuffer_format(ctx
, internalFormat
);
3954 if (format
== MESA_FORMAT_NONE
) {
3955 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3960 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3961 if (buffer
&& !bufObj
) {
3962 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3966 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3968 _mesa_lock_texture(ctx
, texObj
);
3970 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3971 texObj
->BufferObjectFormat
= internalFormat
;
3972 texObj
->_BufferObjectFormat
= format
;
3974 _mesa_unlock_texture(ctx
, texObj
);