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 * Is the given texture format a generic compressed format?
537 is_generic_compressed_format(GLenum format
)
540 case GL_COMPRESSED_RED
:
541 case GL_COMPRESSED_RG
:
542 case GL_COMPRESSED_RGB
:
543 case GL_COMPRESSED_RGBA
:
544 case GL_COMPRESSED_ALPHA
:
545 case GL_COMPRESSED_LUMINANCE
:
546 case GL_COMPRESSED_LUMINANCE_ALPHA
:
547 case GL_COMPRESSED_INTENSITY
:
548 case GL_COMPRESSED_SRGB
:
549 case GL_COMPRESSED_SRGB_ALPHA
:
550 case GL_COMPRESSED_SLUMINANCE
:
551 case GL_COMPRESSED_SLUMINANCE_ALPHA
:
560 * For cube map faces, return a face index in [0,5].
561 * For other targets return 0;
564 _mesa_tex_target_to_face(GLenum target
)
566 if (_mesa_is_cube_face(target
))
567 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
575 * Install gl_texture_image in a gl_texture_object according to the target
576 * and level parameters.
578 * \param tObj texture object.
579 * \param target texture target.
580 * \param level image level.
581 * \param texImage texture image.
584 set_tex_image(struct gl_texture_object
*tObj
,
585 GLenum target
, GLint level
,
586 struct gl_texture_image
*texImage
)
588 const GLuint face
= _mesa_tex_target_to_face(target
);
592 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
595 tObj
->Image
[face
][level
] = texImage
;
597 /* Set the 'back' pointer */
598 texImage
->TexObject
= tObj
;
599 texImage
->Level
= level
;
600 texImage
->Face
= face
;
605 * Allocate a texture image structure.
607 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
610 * \return a pointer to gl_texture_image struct with all fields initialized to
613 struct gl_texture_image
*
614 _mesa_new_texture_image( struct gl_context
*ctx
)
617 return CALLOC_STRUCT(gl_texture_image
);
622 * Free a gl_texture_image and associated data.
623 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
625 * \param texImage texture image.
627 * Free the texture image structure and the associated image data.
630 _mesa_delete_texture_image(struct gl_context
*ctx
,
631 struct gl_texture_image
*texImage
)
633 /* Free texImage->Data and/or any other driver-specific texture
636 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
637 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
643 * Test if a target is a proxy target.
645 * \param target texture target.
647 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
650 _mesa_is_proxy_texture(GLenum target
)
653 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
654 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
656 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
658 return (target
== GL_PROXY_TEXTURE_1D
||
659 target
== GL_PROXY_TEXTURE_2D
||
660 target
== GL_PROXY_TEXTURE_3D
||
661 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
662 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
663 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
664 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
669 * Return the proxy target which corresponds to the given texture target
672 get_proxy_target(GLenum target
)
676 case GL_PROXY_TEXTURE_1D
:
677 return GL_PROXY_TEXTURE_1D
;
679 case GL_PROXY_TEXTURE_2D
:
680 return GL_PROXY_TEXTURE_2D
;
682 case GL_PROXY_TEXTURE_3D
:
683 return GL_PROXY_TEXTURE_3D
;
684 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
685 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
686 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
687 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
688 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
689 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
690 case GL_TEXTURE_CUBE_MAP_ARB
:
691 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
692 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
693 case GL_TEXTURE_RECTANGLE_NV
:
694 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
695 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
696 case GL_TEXTURE_1D_ARRAY_EXT
:
697 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
698 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
699 case GL_TEXTURE_2D_ARRAY_EXT
:
700 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
701 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
703 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
710 * Get the texture object that corresponds to the target of the given
711 * texture unit. The target should have already been checked for validity.
713 * \param ctx GL context.
714 * \param texUnit texture unit.
715 * \param target texture target.
717 * \return pointer to the texture object on success, or NULL on failure.
719 struct gl_texture_object
*
720 _mesa_select_tex_object(struct gl_context
*ctx
,
721 const struct gl_texture_unit
*texUnit
,
724 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
725 ctx
->Extensions
.EXT_texture_array
);
729 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
730 case GL_PROXY_TEXTURE_1D
:
731 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
733 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
734 case GL_PROXY_TEXTURE_2D
:
735 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
737 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
738 case GL_PROXY_TEXTURE_3D
:
739 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
740 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
741 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
742 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
743 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
744 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
745 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
746 case GL_TEXTURE_CUBE_MAP_ARB
:
747 return ctx
->Extensions
.ARB_texture_cube_map
748 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
749 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
750 return ctx
->Extensions
.ARB_texture_cube_map
751 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
752 case GL_TEXTURE_RECTANGLE_NV
:
753 return ctx
->Extensions
.NV_texture_rectangle
754 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
755 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
756 return ctx
->Extensions
.NV_texture_rectangle
757 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
758 case GL_TEXTURE_1D_ARRAY_EXT
:
759 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
760 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
761 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
762 case GL_TEXTURE_2D_ARRAY_EXT
:
763 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
764 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
765 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
766 case GL_TEXTURE_BUFFER
:
767 return ctx
->Extensions
.ARB_texture_buffer_object
768 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
769 case GL_TEXTURE_EXTERNAL_OES
:
770 return ctx
->Extensions
.OES_EGL_image_external
771 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
773 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
780 * Return pointer to texture object for given target on current texture unit.
782 struct gl_texture_object
*
783 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
785 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
786 return _mesa_select_tex_object(ctx
, texUnit
, target
);
791 * Get a texture image pointer from a texture object, given a texture
792 * target and mipmap level. The target and level parameters should
793 * have already been error-checked.
795 * \param ctx GL context.
796 * \param texObj texture unit.
797 * \param target texture target.
798 * \param level image level.
800 * \return pointer to the texture image structure, or NULL on failure.
802 struct gl_texture_image
*
803 _mesa_select_tex_image(struct gl_context
*ctx
,
804 const struct gl_texture_object
*texObj
,
805 GLenum target
, GLint level
)
807 const GLuint face
= _mesa_tex_target_to_face(target
);
811 ASSERT(level
< MAX_TEXTURE_LEVELS
);
813 return texObj
->Image
[face
][level
];
818 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
819 * it and install it. Only return NULL if passed a bad parameter or run
822 struct gl_texture_image
*
823 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
824 GLenum target
, GLint level
)
826 struct gl_texture_image
*texImage
;
831 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
833 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
835 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
839 set_tex_image(texObj
, target
, level
, texImage
);
847 * Return pointer to the specified proxy texture image.
848 * Note that proxy textures are per-context, not per-texture unit.
849 * \return pointer to texture image or NULL if invalid target, invalid
850 * level, or out of memory.
852 struct gl_texture_image
*
853 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
855 struct gl_texture_image
*texImage
;
862 case GL_PROXY_TEXTURE_1D
:
863 if (level
>= ctx
->Const
.MaxTextureLevels
)
865 texIndex
= TEXTURE_1D_INDEX
;
867 case GL_PROXY_TEXTURE_2D
:
868 if (level
>= ctx
->Const
.MaxTextureLevels
)
870 texIndex
= TEXTURE_2D_INDEX
;
872 case GL_PROXY_TEXTURE_3D
:
873 if (level
>= ctx
->Const
.Max3DTextureLevels
)
875 texIndex
= TEXTURE_3D_INDEX
;
877 case GL_PROXY_TEXTURE_CUBE_MAP
:
878 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
880 texIndex
= TEXTURE_CUBE_INDEX
;
882 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
885 texIndex
= TEXTURE_RECT_INDEX
;
887 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
888 if (level
>= ctx
->Const
.MaxTextureLevels
)
890 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
892 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
893 if (level
>= ctx
->Const
.MaxTextureLevels
)
895 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
901 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
903 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
905 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
908 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
909 /* Set the 'back' pointer */
910 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
917 * Get the maximum number of allowed mipmap levels.
919 * \param ctx GL context.
920 * \param target texture target.
922 * \return the maximum number of allowed mipmap levels for the given
923 * texture target, or zero if passed a bad target.
928 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
932 case GL_PROXY_TEXTURE_1D
:
934 case GL_PROXY_TEXTURE_2D
:
935 return ctx
->Const
.MaxTextureLevels
;
937 case GL_PROXY_TEXTURE_3D
:
938 return ctx
->Const
.Max3DTextureLevels
;
939 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
940 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
941 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
942 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
943 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
944 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
945 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
946 return ctx
->Extensions
.ARB_texture_cube_map
947 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
948 case GL_TEXTURE_RECTANGLE_NV
:
949 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
950 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
951 case GL_TEXTURE_1D_ARRAY_EXT
:
952 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
953 case GL_TEXTURE_2D_ARRAY_EXT
:
954 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
955 return (ctx
->Extensions
.MESA_texture_array
||
956 ctx
->Extensions
.EXT_texture_array
)
957 ? ctx
->Const
.MaxTextureLevels
: 0;
958 case GL_TEXTURE_BUFFER
:
959 case GL_TEXTURE_EXTERNAL_OES
:
962 return 0; /* bad target */
968 * Return number of dimensions per mipmap level for the given texture target.
971 _mesa_get_texture_dimensions(GLenum target
)
975 case GL_PROXY_TEXTURE_1D
:
978 case GL_TEXTURE_RECTANGLE
:
979 case GL_TEXTURE_CUBE_MAP
:
980 case GL_PROXY_TEXTURE_2D
:
981 case GL_PROXY_TEXTURE_RECTANGLE
:
982 case GL_PROXY_TEXTURE_CUBE_MAP
:
983 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
984 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
985 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
986 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
987 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
988 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
989 case GL_TEXTURE_1D_ARRAY
:
990 case GL_PROXY_TEXTURE_1D_ARRAY
:
991 case GL_TEXTURE_EXTERNAL_OES
:
994 case GL_PROXY_TEXTURE_3D
:
995 case GL_TEXTURE_2D_ARRAY
:
996 case GL_PROXY_TEXTURE_2D_ARRAY
:
998 case GL_TEXTURE_BUFFER
:
1001 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1010 #if 000 /* not used anymore */
1012 * glTexImage[123]D can accept a NULL image pointer. In this case we
1013 * create a texture image with unspecified image contents per the OpenGL
1017 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1019 const GLint components
= _mesa_components_in_format(format
);
1020 const GLint numPixels
= width
* height
* depth
;
1021 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
1025 * Let's see if anyone finds this. If glTexImage2D() is called with
1026 * a NULL image pointer then load the texture image with something
1027 * interesting instead of leaving it indeterminate.
1030 static const char message
[8][32] = {
1031 " X X XXXXX XXX X ",
1032 " XX XX X X X X X ",
1034 " X X XXXX XXX XXXXX ",
1037 " X X XXXXX XXX X X ",
1041 GLubyte
*imgPtr
= data
;
1043 for (h
= 0; h
< depth
; h
++) {
1044 for (i
= 0; i
< height
; i
++) {
1045 GLint srcRow
= 7 - (i
% 8);
1046 for (j
= 0; j
< width
; j
++) {
1047 GLint srcCol
= j
% 32;
1048 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1049 for (k
= 0; k
< components
; k
++) {
1065 * Set the size and format-related fields of a gl_texture_image struct
1066 * to zero. This is used when a proxy texture test fails.
1069 clear_teximage_fields(struct gl_texture_image
*img
)
1072 img
->_BaseFormat
= 0;
1073 img
->InternalFormat
= 0;
1082 img
->HeightLog2
= 0;
1084 img
->TexFormat
= MESA_FORMAT_NONE
;
1089 * Initialize basic fields of the gl_texture_image struct.
1091 * \param ctx GL context.
1092 * \param img texture image structure to be initialized.
1093 * \param width image width.
1094 * \param height image height.
1095 * \param depth image depth.
1096 * \param border image border.
1097 * \param internalFormat internal format.
1098 * \param format the actual hardware format (one of MESA_FORMAT_*)
1100 * Fills in the fields of \p img with the given information.
1101 * Note: width, height and depth include the border.
1104 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1105 struct gl_texture_image
*img
,
1106 GLsizei width
, GLsizei height
, GLsizei depth
,
1107 GLint border
, GLenum internalFormat
,
1113 ASSERT(height
>= 0);
1116 target
= img
->TexObject
->Target
;
1117 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1118 ASSERT(img
->_BaseFormat
> 0);
1119 img
->InternalFormat
= internalFormat
;
1120 img
->Border
= border
;
1122 img
->Height
= height
;
1125 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1126 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1130 case GL_TEXTURE_BUFFER
:
1131 case GL_PROXY_TEXTURE_1D
:
1136 img
->HeightLog2
= 0;
1143 case GL_TEXTURE_1D_ARRAY
:
1144 case GL_PROXY_TEXTURE_1D_ARRAY
:
1145 img
->Height2
= height
; /* no border */
1146 img
->HeightLog2
= 0; /* not used */
1154 case GL_TEXTURE_RECTANGLE
:
1155 case GL_TEXTURE_CUBE_MAP
:
1156 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1157 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1158 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1159 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1160 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1161 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1162 case GL_TEXTURE_EXTERNAL_OES
:
1163 case GL_PROXY_TEXTURE_2D
:
1164 case GL_PROXY_TEXTURE_RECTANGLE
:
1165 case GL_PROXY_TEXTURE_CUBE_MAP
:
1166 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1167 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1174 case GL_TEXTURE_2D_ARRAY
:
1175 case GL_PROXY_TEXTURE_2D_ARRAY
:
1176 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1177 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1178 img
->Depth2
= depth
; /* no border */
1179 img
->DepthLog2
= 0; /* not used */
1182 case GL_PROXY_TEXTURE_3D
:
1183 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1184 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1185 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1186 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1189 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1193 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1194 img
->TexFormat
= format
;
1199 * Free and clear fields of the gl_texture_image struct.
1201 * \param ctx GL context.
1202 * \param texImage texture image structure to be cleared.
1204 * After the call, \p texImage will have no data associated with it. Its
1205 * fields are cleared so that its parent object will test incomplete.
1208 _mesa_clear_texture_image(struct gl_context
*ctx
,
1209 struct gl_texture_image
*texImage
)
1211 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1212 clear_teximage_fields(texImage
);
1217 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1218 * level, width, height and depth against the ctx->Const limits for textures.
1220 * A hardware driver might override this function if, for example, the
1221 * max 3D texture size is 512x512x64 (i.e. not a cube).
1223 * Note that width, height, depth == 0 is not an error. However, a
1224 * texture with zero width/height/depth will be considered "incomplete"
1225 * and texturing will effectively be disabled.
1227 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1228 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1229 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1230 * \param level as passed to glTexImage
1231 * \param internalFormat as passed to glTexImage
1232 * \param format as passed to glTexImage
1233 * \param type as passed to glTexImage
1234 * \param width as passed to glTexImage
1235 * \param height as passed to glTexImage
1236 * \param depth as passed to glTexImage
1237 * \param border as passed to glTexImage
1238 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1241 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1242 GLint internalFormat
, GLenum format
, GLenum type
,
1243 GLint width
, GLint height
, GLint depth
, GLint border
)
1247 (void) internalFormat
;
1252 case GL_PROXY_TEXTURE_1D
:
1253 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1254 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1256 if (level
>= ctx
->Const
.MaxTextureLevels
)
1258 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1259 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1264 case GL_PROXY_TEXTURE_2D
:
1265 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1266 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1268 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1270 if (level
>= ctx
->Const
.MaxTextureLevels
)
1272 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1273 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1275 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1280 case GL_PROXY_TEXTURE_3D
:
1281 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1282 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1284 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1286 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1288 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1290 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1291 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1293 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1295 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1300 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1301 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1302 if (width
< 0 || width
> maxSize
)
1304 if (height
< 0 || height
> maxSize
)
1310 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1311 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1312 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1314 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1316 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1318 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1319 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1321 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1326 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1327 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1328 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1330 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1332 if (level
>= ctx
->Const
.MaxTextureLevels
)
1334 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1335 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1340 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1341 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1342 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1344 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1346 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1348 if (level
>= ctx
->Const
.MaxTextureLevels
)
1350 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1351 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1353 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1359 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1366 * Check if the memory used by the texture would exceed the driver's limit.
1367 * This lets us support a max 3D texture size of 8K (for example) but
1368 * prevents allocating a full 8K x 8K x 8K texture.
1369 * XXX this could be rolled into the proxy texture size test (above) but
1370 * we don't have the actual texture internal format at that point.
1373 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1374 GLint width
, GLint height
, GLint depth
)
1376 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1377 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1378 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1383 * Return true if the format is only valid for glCompressedTexImage.
1386 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1389 case GL_ETC1_RGB8_OES
:
1398 * Helper function to determine whether a target and specific compression
1399 * format are supported.
1402 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1405 (void) intFormat
; /* not used yet */
1409 case GL_PROXY_TEXTURE_2D
:
1410 return GL_TRUE
; /* true for any compressed format so far */
1411 case GL_PROXY_TEXTURE_CUBE_MAP
:
1412 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1413 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1414 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1415 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1416 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1417 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1418 return ctx
->Extensions
.ARB_texture_cube_map
;
1419 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1420 case GL_TEXTURE_2D_ARRAY_EXT
:
1421 return (ctx
->Extensions
.MESA_texture_array
||
1422 ctx
->Extensions
.EXT_texture_array
);
1430 * Check if the given texture target value is legal for a
1431 * glTexImage1/2/3D call.
1434 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1440 case GL_PROXY_TEXTURE_1D
:
1448 case GL_PROXY_TEXTURE_2D
:
1450 case GL_PROXY_TEXTURE_CUBE_MAP
:
1451 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1452 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1453 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1454 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1455 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1456 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1457 return ctx
->Extensions
.ARB_texture_cube_map
;
1458 case GL_TEXTURE_RECTANGLE_NV
:
1459 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1460 return ctx
->Extensions
.NV_texture_rectangle
;
1461 case GL_TEXTURE_1D_ARRAY_EXT
:
1462 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1463 return (ctx
->Extensions
.MESA_texture_array
||
1464 ctx
->Extensions
.EXT_texture_array
);
1471 case GL_PROXY_TEXTURE_3D
:
1473 case GL_TEXTURE_2D_ARRAY_EXT
:
1474 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1475 return (ctx
->Extensions
.MESA_texture_array
||
1476 ctx
->Extensions
.EXT_texture_array
);
1481 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1488 * Check if the given texture target value is legal for a
1489 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1490 * The difference compared to legal_teximage_target() above is that
1491 * proxy targets are not supported.
1494 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1498 return target
== GL_TEXTURE_1D
;
1503 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1504 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1505 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1506 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1507 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1508 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1509 return ctx
->Extensions
.ARB_texture_cube_map
;
1510 case GL_TEXTURE_RECTANGLE_NV
:
1511 return ctx
->Extensions
.NV_texture_rectangle
;
1512 case GL_TEXTURE_1D_ARRAY_EXT
:
1513 return (ctx
->Extensions
.MESA_texture_array
||
1514 ctx
->Extensions
.EXT_texture_array
);
1522 case GL_TEXTURE_2D_ARRAY_EXT
:
1523 return (ctx
->Extensions
.MESA_texture_array
||
1524 ctx
->Extensions
.EXT_texture_array
);
1529 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1537 * Helper function to determine if a texture object is mutable (in terms
1538 * of GL_ARB_texture_storage).
1541 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1543 if (ctx
->Extensions
.ARB_texture_storage
) {
1544 struct gl_texture_object
*texObj
=
1545 _mesa_get_current_tex_object(ctx
, target
);
1546 return !texObj
->Immutable
;
1554 * Test the glTexImage[123]D() parameters for errors.
1556 * \param ctx GL context.
1557 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1558 * \param target texture target given by the user.
1559 * \param level image level given by the user.
1560 * \param internalFormat internal format given by the user.
1561 * \param format pixel data format given by the user.
1562 * \param type pixel data type given by the user.
1563 * \param width image width given by the user.
1564 * \param height image height given by the user.
1565 * \param depth image depth given by the user.
1566 * \param border image border given by the user.
1568 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1570 * Verifies each of the parameters against the constants specified in
1571 * __struct gl_contextRec::Const and the supported extensions, and according
1572 * to the OpenGL specification.
1575 texture_error_check( struct gl_context
*ctx
,
1576 GLuint dimensions
, GLenum target
,
1577 GLint level
, GLint internalFormat
,
1578 GLenum format
, GLenum type
,
1579 GLint width
, GLint height
,
1580 GLint depth
, GLint border
)
1582 const GLenum proxyTarget
= get_proxy_target(target
);
1583 const GLboolean isProxy
= target
== proxyTarget
;
1584 GLboolean sizeOK
= GL_TRUE
;
1585 GLboolean colorFormat
;
1588 /* Even though there are no color-index textures, we still have to support
1589 * uploading color-index data and remapping it to RGB via the
1590 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1592 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1594 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1595 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1597 _mesa_error(ctx
, GL_INVALID_VALUE
,
1598 "glTexImage%dD(level=%d)", dimensions
, level
);
1604 if (border
< 0 || border
> 1 ||
1605 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1606 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1608 _mesa_error(ctx
, GL_INVALID_VALUE
,
1609 "glTexImage%dD(border=%d)", dimensions
, border
);
1614 if (width
< 0 || height
< 0 || depth
< 0) {
1616 _mesa_error(ctx
, GL_INVALID_VALUE
,
1617 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1622 /* Do this simple check before calling the TestProxyTexImage() function */
1623 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1624 sizeOK
= (width
== height
);
1628 * Use the proxy texture driver hook to see if the size/level/etc are
1631 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1632 internalFormat
, format
,
1633 type
, width
, height
,
1637 _mesa_error(ctx
, GL_INVALID_VALUE
,
1638 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1639 dimensions
, level
, width
, height
, depth
);
1644 /* Check internalFormat */
1645 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1647 _mesa_error(ctx
, GL_INVALID_VALUE
,
1648 "glTexImage%dD(internalFormat=%s)",
1649 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1654 /* Check incoming image format and type */
1655 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1656 if (err
!= GL_NO_ERROR
) {
1658 _mesa_error(ctx
, err
,
1659 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1660 dimensions
, format
, type
);
1665 /* make sure internal format and format basically agree */
1666 colorFormat
= _mesa_is_color_format(format
);
1667 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1668 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1669 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1670 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1671 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1673 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1674 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1675 dimensions
, internalFormat
, format
);
1679 /* additional checks for ycbcr textures */
1680 if (internalFormat
== GL_YCBCR_MESA
) {
1681 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1682 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1683 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1685 _mesa_snprintf(message
, sizeof(message
),
1686 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1687 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1688 return GL_TRUE
; /* error */
1690 if (target
!= GL_TEXTURE_2D
&&
1691 target
!= GL_PROXY_TEXTURE_2D
&&
1692 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1693 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1695 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1701 _mesa_snprintf(message
, sizeof(message
),
1702 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1703 dimensions
, border
);
1704 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1710 /* additional checks for depth textures */
1711 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1712 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1713 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1714 if (target
!= GL_TEXTURE_1D
&&
1715 target
!= GL_PROXY_TEXTURE_1D
&&
1716 target
!= GL_TEXTURE_2D
&&
1717 target
!= GL_PROXY_TEXTURE_2D
&&
1718 target
!= GL_TEXTURE_1D_ARRAY
&&
1719 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1720 target
!= GL_TEXTURE_2D_ARRAY
&&
1721 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1722 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1723 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1724 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1725 (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_gpu_shader4
))) {
1727 _mesa_error(ctx
, GL_INVALID_ENUM
,
1728 "glTexImage(target/internalFormat)");
1733 /* additional checks for compressed textures */
1734 if (_mesa_is_compressed_format(ctx
, internalFormat
) ||
1735 is_generic_compressed_format(internalFormat
)) {
1736 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1738 _mesa_error(ctx
, GL_INVALID_ENUM
,
1739 "glTexImage%dD(target)", dimensions
);
1742 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1743 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1744 "glTexImage%dD(no compression for format)", dimensions
);
1749 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1750 "glTexImage%dD(border!=0)", dimensions
);
1756 /* additional checks for integer textures */
1757 if ((ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_texture_integer
) &&
1758 (_mesa_is_integer_format(format
) !=
1759 _mesa_is_integer_format(internalFormat
))) {
1761 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1762 "glTexImage%dD(integer/non-integer format mismatch)",
1768 if (!mutable_tex_object(ctx
, target
)) {
1769 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1770 "glTexImage%dD(immutable texture)", dimensions
);
1774 /* if we get here, the parameters are OK */
1780 * Test glTexSubImage[123]D() parameters for errors.
1782 * \param ctx GL context.
1783 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1784 * \param target texture target given by the user.
1785 * \param level image level given by the user.
1786 * \param xoffset sub-image x offset given by the user.
1787 * \param yoffset sub-image y offset given by the user.
1788 * \param zoffset sub-image z offset given by the user.
1789 * \param format pixel data format given by the user.
1790 * \param type pixel data type given by the user.
1791 * \param width image width given by the user.
1792 * \param height image height given by the user.
1793 * \param depth image depth given by the user.
1795 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1797 * Verifies each of the parameters against the constants specified in
1798 * __struct gl_contextRec::Const and the supported extensions, and according
1799 * to the OpenGL specification.
1802 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1803 GLenum target
, GLint level
,
1804 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1805 GLint width
, GLint height
, GLint depth
,
1806 GLenum format
, GLenum type
)
1810 /* Basic level check */
1811 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1812 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1816 /* Check for negative sizes */
1818 _mesa_error(ctx
, GL_INVALID_VALUE
,
1819 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1822 if (height
< 0 && dimensions
> 1) {
1823 _mesa_error(ctx
, GL_INVALID_VALUE
,
1824 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1827 if (depth
< 0 && dimensions
> 2) {
1828 _mesa_error(ctx
, GL_INVALID_VALUE
,
1829 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1833 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1834 if (err
!= GL_NO_ERROR
) {
1835 _mesa_error(ctx
, err
,
1836 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1837 dimensions
, format
, type
);
1846 * Do second part of glTexSubImage which depends on the destination texture.
1847 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1850 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1851 GLenum target
, GLint level
,
1852 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1853 GLint width
, GLint height
, GLint depth
,
1854 GLenum format
, GLenum type
,
1855 const struct gl_texture_image
*destTex
)
1858 /* undefined image level */
1859 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1863 if (xoffset
< -((GLint
)destTex
->Border
)) {
1864 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1868 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1869 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1873 if (dimensions
> 1) {
1874 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destTex
->Border
;
1875 if (yoffset
< -yBorder
) {
1876 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1880 if (yoffset
+ height
> (GLint
) destTex
->Height
+ yBorder
) {
1881 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1886 if (dimensions
> 2) {
1887 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destTex
->Border
;
1888 if (zoffset
< -zBorder
) {
1889 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1892 if (zoffset
+ depth
> (GLint
) destTex
->Depth
+ zBorder
) {
1893 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1898 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1901 if (compressedteximage_only_format(ctx
, destTex
->InternalFormat
)) {
1902 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1903 "glTexSubImage%dD(no compression for format)", dimensions
);
1907 /* do tests which depend on compression block size */
1908 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1910 /* offset must be multiple of block size */
1911 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1912 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1913 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1914 dimensions
, xoffset
, yoffset
);
1917 /* size must be multiple of bw by bh or equal to whole texture size */
1918 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1919 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1920 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1923 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1924 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1925 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1930 if (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_texture_integer
) {
1931 /* both source and dest must be integer-valued, or neither */
1932 if (_mesa_is_format_integer_color(destTex
->TexFormat
) !=
1933 _mesa_is_integer_format(format
)) {
1934 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1935 "glTexSubImage%dD(integer/non-integer format mismatch)",
1946 * Test glCopyTexImage[12]D() parameters for errors.
1948 * \param ctx GL context.
1949 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1950 * \param target texture target given by the user.
1951 * \param level image level given by the user.
1952 * \param internalFormat internal format given by the user.
1953 * \param width image width given by the user.
1954 * \param height image height given by the user.
1955 * \param border texture border.
1957 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1959 * Verifies each of the parameters against the constants specified in
1960 * __struct gl_contextRec::Const and the supported extensions, and according
1961 * to the OpenGL specification.
1964 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1965 GLenum target
, GLint level
, GLint internalFormat
,
1966 GLint width
, GLint height
, GLint border
)
1968 const GLenum proxyTarget
= get_proxy_target(target
);
1969 const GLenum type
= GL_FLOAT
;
1974 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1975 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1976 dimensions
, _mesa_lookup_enum_by_nr(target
));
1980 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1981 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1982 _mesa_error(ctx
, GL_INVALID_VALUE
,
1983 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1987 /* Check that the source buffer is complete */
1988 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
1989 if (ctx
->ReadBuffer
->_Status
== 0) {
1990 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1992 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1993 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1994 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1998 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
1999 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION
,
2000 "glCopyTexImage%dD(multisample FBO)",
2007 if (border
< 0 || border
> 1 ||
2008 ((target
== GL_TEXTURE_RECTANGLE_NV
||
2009 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2013 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2014 if (baseFormat
< 0) {
2015 _mesa_error(ctx
, GL_INVALID_VALUE
,
2016 "glCopyTexImage%dD(internalFormat)", dimensions
);
2020 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2021 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2022 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2026 /* From the EXT_texture_integer spec:
2028 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2029 * if the texture internalformat is an integer format and the read color
2030 * buffer is not an integer format, or if the internalformat is not an
2031 * integer format and the read color buffer is an integer format."
2033 if (_mesa_is_color_format(internalFormat
)) {
2034 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2036 if (_mesa_is_integer_format(rb
->InternalFormat
) !=
2037 _mesa_is_integer_format(internalFormat
)) {
2038 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2039 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2044 /* Do size, level checking */
2045 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
2046 ? (width
== height
) : 1;
2048 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
2049 internalFormat
, baseFormat
,
2050 type
, width
, height
,
2054 if (dimensions
== 1) {
2055 _mesa_error(ctx
, GL_INVALID_VALUE
,
2056 "glCopyTexImage1D(width=%d)", width
);
2059 ASSERT(dimensions
== 2);
2060 _mesa_error(ctx
, GL_INVALID_VALUE
,
2061 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2066 if (_mesa_is_compressed_format(ctx
, internalFormat
) ||
2067 is_generic_compressed_format(internalFormat
)) {
2068 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2069 _mesa_error(ctx
, GL_INVALID_ENUM
,
2070 "glCopyTexImage%dD(target)", dimensions
);
2073 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2074 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2075 "glCopyTexImage%dD(no compression for format)", dimensions
);
2079 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2080 "glCopyTexImage%dD(border!=0)", dimensions
);
2085 if (!mutable_tex_object(ctx
, target
)) {
2086 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2087 "glCopyTexImage%dD(immutable texture)", dimensions
);
2091 /* if we get here, the parameters are OK */
2097 * Test glCopyTexSubImage[12]D() parameters for errors.
2098 * Note that this is the first part of error checking.
2099 * See also copytexsubimage_error_check2() below for the second part.
2101 * \param ctx GL context.
2102 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2103 * \param target texture target given by the user.
2104 * \param level image level given by the user.
2106 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2109 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2110 GLenum target
, GLint level
)
2112 /* Check that the source buffer is complete */
2113 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2114 if (ctx
->ReadBuffer
->_Status
== 0) {
2115 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2117 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2118 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2119 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2123 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2124 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION
,
2125 "glCopyTexSubImage%dD(multisample FBO)",
2131 /* check target (proxies not allowed) */
2132 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2133 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2134 dimensions
, _mesa_lookup_enum_by_nr(target
));
2139 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2140 _mesa_error(ctx
, GL_INVALID_VALUE
,
2141 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2150 * Second part of error checking for glCopyTexSubImage[12]D().
2151 * \param xoffset sub-image x offset given by the user.
2152 * \param yoffset sub-image y offset given by the user.
2153 * \param zoffset sub-image z offset given by the user.
2154 * \param width image width given by the user.
2155 * \param height image height given by the user.
2158 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2159 GLenum target
, GLint level
,
2160 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2161 GLsizei width
, GLsizei height
,
2162 const struct gl_texture_image
*teximage
)
2164 /* check that dest tex image exists */
2166 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2167 "glCopyTexSubImage%dD(undefined texture level: %d)",
2174 _mesa_error(ctx
, GL_INVALID_VALUE
,
2175 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2178 if (dimensions
> 1 && height
< 0) {
2179 _mesa_error(ctx
, GL_INVALID_VALUE
,
2180 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2184 /* check x/y offsets */
2185 if (xoffset
< -((GLint
)teximage
->Border
)) {
2186 _mesa_error(ctx
, GL_INVALID_VALUE
,
2187 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2190 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2191 _mesa_error(ctx
, GL_INVALID_VALUE
,
2192 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2195 if (dimensions
> 1) {
2196 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : teximage
->Border
;
2197 if (yoffset
< -yBorder
) {
2198 _mesa_error(ctx
, GL_INVALID_VALUE
,
2199 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2202 /* NOTE: we're adding the border here, not subtracting! */
2203 if (yoffset
+ height
> (GLint
) teximage
->Height
+ yBorder
) {
2204 _mesa_error(ctx
, GL_INVALID_VALUE
,
2205 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2210 /* check z offset */
2211 if (dimensions
> 2) {
2212 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : teximage
->Border
;
2213 if (zoffset
< -zBorder
) {
2214 _mesa_error(ctx
, GL_INVALID_VALUE
,
2215 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2218 if (zoffset
> (GLint
) teximage
->Depth
+ zBorder
) {
2219 _mesa_error(ctx
, GL_INVALID_VALUE
,
2220 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2225 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2226 if (compressedteximage_only_format(ctx
, teximage
->InternalFormat
)) {
2227 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2228 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2231 /* offset must be multiple of 4 */
2232 if ((xoffset
& 3) || (yoffset
& 3)) {
2233 _mesa_error(ctx
, GL_INVALID_VALUE
,
2234 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2237 /* size must be multiple of 4 */
2238 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2239 _mesa_error(ctx
, GL_INVALID_VALUE
,
2240 "glCopyTexSubImage%dD(width)", dimensions
);
2243 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2244 _mesa_error(ctx
, GL_INVALID_VALUE
,
2245 "glCopyTexSubImage%dD(height)", dimensions
);
2250 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2251 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2255 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2256 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2257 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2258 dimensions
, teximage
->_BaseFormat
);
2262 /* From the EXT_texture_integer spec:
2264 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2265 * if the texture internalformat is an integer format and the read color
2266 * buffer is not an integer format, or if the internalformat is not an
2267 * integer format and the read color buffer is an integer format."
2269 if (_mesa_is_color_format(teximage
->InternalFormat
)) {
2270 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2272 if (_mesa_is_format_integer_color(rb
->Format
) !=
2273 _mesa_is_format_integer_color(teximage
->TexFormat
)) {
2274 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2275 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2280 /* if we get here, the parameters are OK */
2285 /** Callback info for walking over FBO hash table */
2288 struct gl_context
*ctx
;
2289 struct gl_texture_object
*texObj
;
2295 * Check render to texture callback. Called from _mesa_HashWalk().
2298 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2300 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2301 const struct cb_info
*info
= (struct cb_info
*) userData
;
2302 struct gl_context
*ctx
= info
->ctx
;
2303 const struct gl_texture_object
*texObj
= info
->texObj
;
2304 const GLuint level
= info
->level
, face
= info
->face
;
2306 /* If this is a user-created FBO */
2307 if (_mesa_is_user_fbo(fb
)) {
2309 /* check if any of the FBO's attachments point to 'texObj' */
2310 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2311 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2312 if (att
->Type
== GL_TEXTURE
&&
2313 att
->Texture
== texObj
&&
2314 att
->TextureLevel
== level
&&
2315 att
->CubeMapFace
== face
) {
2316 ASSERT(_mesa_get_attachment_teximage(att
));
2317 /* Tell driver about the new renderbuffer texture */
2318 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2319 /* Mark fb status as indeterminate to force re-validation */
2328 * When a texture image is specified we have to check if it's bound to
2329 * any framebuffer objects (render to texture) in order to detect changes
2330 * in size or format since that effects FBO completeness.
2331 * Any FBOs rendering into the texture must be re-validated.
2334 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2335 struct gl_texture_object
*texObj
,
2336 GLuint face
, GLuint level
)
2338 /* Only check this texture if it's been marked as RenderToTexture */
2339 if (texObj
->_RenderToTexture
) {
2340 struct cb_info info
;
2342 info
.texObj
= texObj
;
2345 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2351 * If the texture object's GenerateMipmap flag is set and we've
2352 * changed the texture base level image, regenerate the rest of the
2353 * mipmap levels now.
2356 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2357 struct gl_texture_object
*texObj
, GLint level
)
2359 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2360 if (texObj
->GenerateMipmap
&&
2361 level
== texObj
->BaseLevel
&&
2362 level
< texObj
->MaxLevel
) {
2363 ASSERT(ctx
->Driver
.GenerateMipmap
);
2364 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2369 /** Debug helper: override the user-requested internal format */
2371 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2374 if (internalFormat
== GL_RGBA16F_ARB
||
2375 internalFormat
== GL_RGBA32F_ARB
) {
2376 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2379 else if (internalFormat
== GL_RGB16F_ARB
||
2380 internalFormat
== GL_RGB32F_ARB
) {
2381 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2384 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2385 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2386 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2387 return GL_LUMINANCE_ALPHA
;
2389 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2390 internalFormat
== GL_LUMINANCE32F_ARB
) {
2391 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2392 return GL_LUMINANCE
;
2394 else if (internalFormat
== GL_ALPHA16F_ARB
||
2395 internalFormat
== GL_ALPHA32F_ARB
) {
2396 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2400 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2401 internalFormat = GL_RGBA;
2405 return internalFormat
;
2408 return internalFormat
;
2414 * Choose the actual hardware format for a texture image.
2415 * Try to use the same format as the previous image level when possible.
2416 * Otherwise, ask the driver for the best format.
2417 * It's important to try to choose a consistant format for all levels
2418 * for efficient texture memory layout/allocation. In particular, this
2419 * comes up during automatic mipmap generation.
2422 _mesa_choose_texture_format(struct gl_context
*ctx
,
2423 struct gl_texture_object
*texObj
,
2424 GLenum target
, GLint level
,
2425 GLenum internalFormat
, GLenum format
, GLenum type
)
2429 /* see if we've already chosen a format for the previous level */
2431 struct gl_texture_image
*prevImage
=
2432 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2433 /* See if the prev level is defined and has an internal format which
2434 * matches the new internal format.
2437 prevImage
->Width
> 0 &&
2438 prevImage
->InternalFormat
== internalFormat
) {
2439 /* use the same format */
2440 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2441 return prevImage
->TexFormat
;
2445 /* choose format from scratch */
2446 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2447 ASSERT(f
!= MESA_FORMAT_NONE
);
2452 * Adjust pixel unpack params and image dimensions to strip off the
2453 * one-pixel texture border.
2455 * Gallium and intel don't support texture borders. They've seldem been used
2456 * and seldom been implemented correctly anyway.
2458 * \param unpackNew returns the new pixel unpack parameters
2461 strip_texture_border(GLenum target
,
2462 GLint
*width
, GLint
*height
, GLint
*depth
,
2463 const struct gl_pixelstore_attrib
*unpack
,
2464 struct gl_pixelstore_attrib
*unpackNew
)
2470 *unpackNew
= *unpack
;
2472 if (unpackNew
->RowLength
== 0)
2473 unpackNew
->RowLength
= *width
;
2475 if (unpackNew
->ImageHeight
== 0)
2476 unpackNew
->ImageHeight
= *height
;
2478 assert(*width
>= 3);
2479 unpackNew
->SkipPixels
++; /* skip the border */
2480 *width
= *width
- 2; /* reduce the width by two border pixels */
2482 /* The min height of a texture with a border is 3 */
2483 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2484 unpackNew
->SkipRows
++; /* skip the border */
2485 *height
= *height
- 2; /* reduce the height by two border pixels */
2488 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
) {
2489 unpackNew
->SkipImages
++; /* skip the border */
2490 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2495 * Common code to implement all the glTexImage1D/2D/3D functions.
2498 teximage(struct gl_context
*ctx
, GLuint dims
,
2499 GLenum target
, GLint level
, GLint internalFormat
,
2500 GLsizei width
, GLsizei height
, GLsizei depth
,
2501 GLint border
, GLenum format
, GLenum type
,
2502 const GLvoid
*pixels
)
2505 struct gl_pixelstore_attrib unpack_no_border
;
2506 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2508 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2510 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2511 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2513 _mesa_lookup_enum_by_nr(target
), level
,
2514 _mesa_lookup_enum_by_nr(internalFormat
),
2515 width
, height
, depth
, border
,
2516 _mesa_lookup_enum_by_nr(format
),
2517 _mesa_lookup_enum_by_nr(type
), pixels
);
2519 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2521 /* target error checking */
2522 if (!legal_teximage_target(ctx
, dims
, target
)) {
2523 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2524 dims
, _mesa_lookup_enum_by_nr(target
));
2528 /* general error checking */
2529 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2530 format
, type
, width
, height
, depth
, border
);
2532 if (_mesa_is_proxy_texture(target
)) {
2533 /* Proxy texture: just clear or set state depending on error checking */
2534 struct gl_texture_image
*texImage
=
2535 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2538 /* when error, clear all proxy texture image parameters */
2540 clear_teximage_fields(texImage
);
2543 /* no error, set the tex image parameters */
2544 struct gl_texture_object
*texObj
=
2545 _mesa_get_current_tex_object(ctx
, target
);
2546 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2551 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2552 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
2553 depth
, border
, internalFormat
,
2556 else if (texImage
) {
2557 clear_teximage_fields(texImage
);
2562 /* non-proxy target */
2563 const GLuint face
= _mesa_tex_target_to_face(target
);
2564 struct gl_texture_object
*texObj
;
2565 struct gl_texture_image
*texImage
;
2568 return; /* error was recorded */
2571 /* Allow a hardware driver to just strip out the border, to provide
2572 * reliable but slightly incorrect hardware rendering instead of
2573 * rarely-tested software fallback rendering.
2575 if (border
&& ctx
->Const
.StripTextureBorder
) {
2576 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
2579 unpack
= &unpack_no_border
;
2582 if (ctx
->NewState
& _NEW_PIXEL
)
2583 _mesa_update_state(ctx
);
2585 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2587 _mesa_lock_texture(ctx
, texObj
);
2589 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2592 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2595 gl_format texFormat
;
2597 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2599 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2600 internalFormat
, format
,
2603 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2604 _mesa_init_teximage_fields(ctx
, texImage
,
2605 width
, height
, depth
,
2606 border
, internalFormat
, texFormat
);
2608 /* Give the texture to the driver. <pixels> may be null. */
2609 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, internalFormat
,
2610 width
, height
, depth
, border
, format
,
2611 type
, pixels
, unpack
);
2613 check_gen_mipmap(ctx
, target
, texObj
, level
);
2615 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2617 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2620 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2624 _mesa_unlock_texture(ctx
, texObj
);
2630 * Called from the API. Note that width includes the border.
2633 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2634 GLsizei width
, GLint border
, GLenum format
,
2635 GLenum type
, const GLvoid
*pixels
)
2637 GET_CURRENT_CONTEXT(ctx
);
2638 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2639 border
, format
, type
, pixels
);
2644 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2645 GLsizei width
, GLsizei height
, GLint border
,
2646 GLenum format
, GLenum type
,
2647 const GLvoid
*pixels
)
2649 GET_CURRENT_CONTEXT(ctx
);
2650 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2651 border
, format
, type
, pixels
);
2656 * Called by the API or display list executor.
2657 * Note that width and height include the border.
2660 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2661 GLsizei width
, GLsizei height
, GLsizei depth
,
2662 GLint border
, GLenum format
, GLenum type
,
2663 const GLvoid
*pixels
)
2665 GET_CURRENT_CONTEXT(ctx
);
2666 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2667 border
, format
, type
, pixels
);
2672 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2673 GLsizei width
, GLsizei height
, GLsizei depth
,
2674 GLint border
, GLenum format
, GLenum type
,
2675 const GLvoid
*pixels
)
2677 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2678 depth
, border
, format
, type
, pixels
);
2682 #if FEATURE_OES_EGL_image
2684 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2686 struct gl_texture_object
*texObj
;
2687 struct gl_texture_image
*texImage
;
2688 GET_CURRENT_CONTEXT(ctx
);
2689 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2691 if ((target
== GL_TEXTURE_2D
&&
2692 !ctx
->Extensions
.OES_EGL_image
) ||
2693 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2694 !ctx
->Extensions
.OES_EGL_image_external
)) {
2695 _mesa_error(ctx
, GL_INVALID_ENUM
,
2696 "glEGLImageTargetTexture2D(target=%d)", target
);
2700 if (ctx
->NewState
& _NEW_PIXEL
)
2701 _mesa_update_state(ctx
);
2703 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2704 _mesa_lock_texture(ctx
, texObj
);
2706 if (texObj
->Immutable
) {
2707 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2708 "glEGLImageTargetTexture2D(texture is immutable)");
2709 _mesa_unlock_texture(ctx
, texObj
);
2713 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2715 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2717 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2719 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2720 texObj
, texImage
, image
);
2722 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2724 _mesa_unlock_texture(ctx
, texObj
);
2732 * Implement all the glTexSubImage1/2/3D() functions.
2735 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2736 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2737 GLsizei width
, GLsizei height
, GLsizei depth
,
2738 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2740 struct gl_texture_object
*texObj
;
2741 struct gl_texture_image
*texImage
;
2743 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2745 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2746 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2748 _mesa_lookup_enum_by_nr(target
), level
,
2749 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2750 _mesa_lookup_enum_by_nr(format
),
2751 _mesa_lookup_enum_by_nr(type
), pixels
);
2753 /* check target (proxies not allowed) */
2754 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2755 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2756 dims
, _mesa_lookup_enum_by_nr(target
));
2760 if (ctx
->NewState
& _NEW_PIXEL
)
2761 _mesa_update_state(ctx
);
2763 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2764 width
, height
, depth
, format
, type
)) {
2765 return; /* error was detected */
2768 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2770 _mesa_lock_texture(ctx
, texObj
);
2772 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2774 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2775 xoffset
, yoffset
, zoffset
,
2776 width
, height
, depth
,
2777 format
, type
, texImage
)) {
2778 /* error was recorded */
2780 else if (width
> 0 && height
> 0 && depth
> 0) {
2781 /* If we have a border, offset=-1 is legal. Bias by border width. */
2784 if (target
!= GL_TEXTURE_2D_ARRAY
)
2785 zoffset
+= texImage
->Border
;
2788 if (target
!= GL_TEXTURE_1D_ARRAY
)
2789 yoffset
+= texImage
->Border
;
2792 xoffset
+= texImage
->Border
;
2795 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
2796 xoffset
, yoffset
, zoffset
,
2797 width
, height
, depth
,
2798 format
, type
, pixels
, &ctx
->Unpack
);
2800 check_gen_mipmap(ctx
, target
, texObj
, level
);
2802 ctx
->NewState
|= _NEW_TEXTURE
;
2805 _mesa_unlock_texture(ctx
, texObj
);
2810 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2811 GLint xoffset
, GLsizei width
,
2812 GLenum format
, GLenum type
,
2813 const GLvoid
*pixels
)
2815 GET_CURRENT_CONTEXT(ctx
);
2816 texsubimage(ctx
, 1, target
, level
,
2819 format
, type
, pixels
);
2824 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2825 GLint xoffset
, GLint yoffset
,
2826 GLsizei width
, GLsizei height
,
2827 GLenum format
, GLenum type
,
2828 const GLvoid
*pixels
)
2830 GET_CURRENT_CONTEXT(ctx
);
2831 texsubimage(ctx
, 2, target
, level
,
2832 xoffset
, yoffset
, 0,
2834 format
, type
, pixels
);
2840 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2841 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2842 GLsizei width
, GLsizei height
, GLsizei depth
,
2843 GLenum format
, GLenum type
,
2844 const GLvoid
*pixels
)
2846 GET_CURRENT_CONTEXT(ctx
);
2847 texsubimage(ctx
, 3, target
, level
,
2848 xoffset
, yoffset
, zoffset
,
2849 width
, height
, depth
,
2850 format
, type
, pixels
);
2856 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
2857 * from. This depends on whether the texture contains color or depth values.
2859 static struct gl_renderbuffer
*
2860 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
2862 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
2863 /* reading from depth/stencil buffer */
2864 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
2867 /* copying from color buffer */
2868 return ctx
->ReadBuffer
->_ColorReadBuffer
;
2875 * Implement the glCopyTexImage1/2D() functions.
2878 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2879 GLenum target
, GLint level
, GLenum internalFormat
,
2880 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2882 struct gl_texture_object
*texObj
;
2883 struct gl_texture_image
*texImage
;
2884 const GLuint face
= _mesa_tex_target_to_face(target
);
2886 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2888 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2889 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2891 _mesa_lookup_enum_by_nr(target
), level
,
2892 _mesa_lookup_enum_by_nr(internalFormat
),
2893 x
, y
, width
, height
, border
);
2895 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2896 _mesa_update_state(ctx
);
2898 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2899 width
, height
, border
))
2902 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2904 if (border
&& ctx
->Const
.StripTextureBorder
) {
2906 width
-= border
* 2;
2909 height
-= border
* 2;
2914 _mesa_lock_texture(ctx
, texObj
);
2916 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2919 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2922 /* choose actual hw format */
2923 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2928 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2929 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
2931 /* Free old texture image */
2932 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2934 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
2935 border
, internalFormat
, texFormat
);
2937 /* Allocate texture memory (no pixel data yet) */
2938 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, internalFormat
,
2939 width
, height
, 1, border
, GL_NONE
, GL_NONE
,
2940 NULL
, &ctx
->Unpack
);
2942 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2944 struct gl_renderbuffer
*srcRb
=
2945 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
2947 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
2948 srcRb
, srcX
, srcY
, width
, height
);
2951 check_gen_mipmap(ctx
, target
, texObj
, level
);
2953 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2955 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
2958 /* probably too large of image */
2959 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2963 _mesa_unlock_texture(ctx
, texObj
);
2969 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2970 GLenum internalFormat
,
2972 GLsizei width
, GLint border
)
2974 GET_CURRENT_CONTEXT(ctx
);
2975 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2981 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2982 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2985 GET_CURRENT_CONTEXT(ctx
);
2986 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2987 x
, y
, width
, height
, border
);
2993 * Implementation for glCopyTexSubImage1/2/3D() functions.
2996 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2997 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2998 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3000 struct gl_texture_object
*texObj
;
3001 struct gl_texture_image
*texImage
;
3003 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3005 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3006 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3008 _mesa_lookup_enum_by_nr(target
),
3009 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3011 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3012 _mesa_update_state(ctx
);
3014 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
3017 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3019 _mesa_lock_texture(ctx
, texObj
);
3021 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3023 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
3024 zoffset
, width
, height
, texImage
)) {
3025 /* error was recored */
3028 /* If we have a border, offset=-1 is legal. Bias by border width. */
3031 if (target
!= GL_TEXTURE_2D_ARRAY
)
3032 zoffset
+= texImage
->Border
;
3035 if (target
!= GL_TEXTURE_1D_ARRAY
)
3036 yoffset
+= texImage
->Border
;
3039 xoffset
+= texImage
->Border
;
3042 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3044 struct gl_renderbuffer
*srcRb
=
3045 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3047 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3048 xoffset
, yoffset
, zoffset
,
3049 srcRb
, x
, y
, width
, height
);
3051 check_gen_mipmap(ctx
, target
, texObj
, level
);
3053 ctx
->NewState
|= _NEW_TEXTURE
;
3057 _mesa_unlock_texture(ctx
, texObj
);
3062 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3063 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3065 GET_CURRENT_CONTEXT(ctx
);
3066 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3072 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3073 GLint xoffset
, GLint yoffset
,
3074 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3076 GET_CURRENT_CONTEXT(ctx
);
3077 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3084 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3085 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3086 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3088 GET_CURRENT_CONTEXT(ctx
);
3089 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3090 x
, y
, width
, height
);
3096 /**********************************************************************/
3097 /****** Compressed Textures ******/
3098 /**********************************************************************/
3102 * Return expected size of a compressed texture.
3105 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3108 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3109 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3114 * Return compressed texture block size, in pixels.
3117 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3119 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3120 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3125 * Error checking for glCompressedTexImage[123]D().
3126 * \param reason returns reason for error, if any
3127 * \return error code or GL_NO_ERROR.
3130 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3131 GLenum target
, GLint level
,
3132 GLenum internalFormat
, GLsizei width
,
3133 GLsizei height
, GLsizei depth
, GLint border
,
3134 GLsizei imageSize
, char **reason
)
3136 const GLenum proxyTarget
= get_proxy_target(target
);
3137 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3139 GLenum choose_format
;
3141 GLenum proxy_format
;
3143 *reason
= ""; /* no error */
3145 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3147 return GL_INVALID_ENUM
;
3150 /* This will detect any invalid internalFormat value */
3151 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3152 *reason
= "internalFormat";
3153 return GL_INVALID_ENUM
;
3156 switch (internalFormat
) {
3158 case GL_PALETTE4_RGB8_OES
:
3159 case GL_PALETTE4_RGBA8_OES
:
3160 case GL_PALETTE4_R5_G6_B5_OES
:
3161 case GL_PALETTE4_RGBA4_OES
:
3162 case GL_PALETTE4_RGB5_A1_OES
:
3163 case GL_PALETTE8_RGB8_OES
:
3164 case GL_PALETTE8_RGBA8_OES
:
3165 case GL_PALETTE8_R5_G6_B5_OES
:
3166 case GL_PALETTE8_RGBA4_OES
:
3167 case GL_PALETTE8_RGB5_A1_OES
:
3168 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3170 proxy_format
= choose_format
;
3173 if (level
> 0 || level
< -maxLevels
) {
3175 return GL_INVALID_VALUE
;
3178 if (dimensions
!= 2) {
3179 *reason
= "compressed paletted textures must be 2D";
3180 return GL_INVALID_OPERATION
;
3183 /* Figure out the expected texture size (in bytes). This will be
3184 * checked against the actual size later.
3186 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3189 /* This is for the benefit of the TestProxyTexImage below. It expects
3190 * level to be non-negative. OES_compressed_paletted_texture uses a
3191 * weird mechanism where the level specified to glCompressedTexImage2D
3192 * is -(n-1) number of levels in the texture, and the data specifies the
3193 * complete mipmap stack. This is done to ensure the palette is the
3194 * same for all levels.
3201 choose_format
= GL_NONE
;
3202 choose_type
= GL_NONE
;
3203 proxy_format
= internalFormat
;
3206 if (level
< 0 || level
>= maxLevels
) {
3208 return GL_INVALID_VALUE
;
3211 /* Figure out the expected texture size (in bytes). This will be
3212 * checked against the actual size later.
3214 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3218 /* This should really never fail */
3219 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3220 *reason
= "internalFormat";
3221 return GL_INVALID_ENUM
;
3224 /* No compressed formats support borders at this time */
3226 *reason
= "border != 0";
3227 return GL_INVALID_VALUE
;
3230 /* For cube map, width must equal height */
3231 if (_mesa_is_cube_face(target
) && width
!= height
) {
3232 *reason
= "width != height";
3233 return GL_INVALID_VALUE
;
3236 /* check image size against compression block size */
3238 gl_format texFormat
=
3239 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3240 choose_format
, choose_type
);
3243 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3244 if ((width
> bw
&& width
% bw
> 0) ||
3245 (height
> bh
&& height
% bh
> 0)) {
3247 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3248 * generated [...] if any parameter combinations are not
3249 * supported by the specific compressed internal format.
3251 *reason
= "invalid width or height for compression format";
3252 return GL_INVALID_OPERATION
;
3256 /* check image sizes */
3257 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3258 proxy_format
, choose_format
,
3260 width
, height
, depth
, border
)) {
3261 /* See error comment above */
3262 *reason
= "invalid width, height or format";
3263 return GL_INVALID_OPERATION
;
3266 /* check image size in bytes */
3267 if (expectedSize
!= imageSize
) {
3268 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3269 * if <imageSize> is not consistent with the format, dimensions, and
3270 * contents of the specified image.
3272 *reason
= "imageSize inconsistant with width/height/format";
3273 return GL_INVALID_VALUE
;
3276 if (!mutable_tex_object(ctx
, target
)) {
3277 *reason
= "immutable texture";
3278 return GL_INVALID_OPERATION
;
3286 * Error checking for glCompressedTexSubImage[123]D().
3287 * \warning There are some bad assumptions here about the size of compressed
3288 * texture tiles (multiple of 4) used to test the validity of the
3289 * offset and size parameters.
3290 * \return error code or GL_NO_ERROR.
3293 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3294 GLenum target
, GLint level
,
3295 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3296 GLsizei width
, GLsizei height
, GLsizei depth
,
3297 GLenum format
, GLsizei imageSize
)
3299 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3303 if (dimensions
== 1) {
3304 /* 1D compressed textures not allowed */
3305 return GL_INVALID_ENUM
;
3307 else if (dimensions
== 2) {
3308 if (target
== GL_PROXY_TEXTURE_2D
) {
3309 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3311 else if (target
== GL_TEXTURE_2D
) {
3312 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3314 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3315 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3316 return GL_INVALID_ENUM
; /*target*/
3317 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3319 else if (_mesa_is_cube_face(target
)) {
3320 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3321 return GL_INVALID_ENUM
; /*target*/
3322 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3325 return GL_INVALID_ENUM
; /*target*/
3328 else if (dimensions
== 3) {
3329 /* 3D compressed textures not allowed */
3330 return GL_INVALID_ENUM
;
3333 maxTextureSize
= 1 << (maxLevels
- 1);
3335 /* this will catch any invalid compressed format token */
3336 if (!_mesa_is_compressed_format(ctx
, format
))
3337 return GL_INVALID_ENUM
;
3339 if (width
< 1 || width
> maxTextureSize
)
3340 return GL_INVALID_VALUE
;
3342 if ((height
< 1 || height
> maxTextureSize
)
3344 return GL_INVALID_VALUE
;
3346 if (level
< 0 || level
>= maxLevels
)
3347 return GL_INVALID_VALUE
;
3350 * do checks which depend on compression block size
3352 get_compressed_block_size(format
, &bw
, &bh
);
3354 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3355 return GL_INVALID_VALUE
;
3357 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3358 return GL_INVALID_VALUE
;
3360 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3361 return GL_INVALID_VALUE
;
3363 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3364 if (expectedSize
!= imageSize
)
3365 return GL_INVALID_VALUE
;
3372 * Do second part of glCompressedTexSubImage error checking.
3373 * \return GL_TRUE if error found, GL_FALSE otherwise.
3376 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3377 GLsizei width
, GLsizei height
,
3378 GLsizei depth
, GLenum format
,
3379 struct gl_texture_image
*texImage
)
3382 if ((GLint
) format
!= texImage
->InternalFormat
) {
3383 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3384 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3388 if (compressedteximage_only_format(ctx
, format
)) {
3389 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3390 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3395 if (((width
== 1 || width
== 2) &&
3396 width
!= (GLsizei
) texImage
->Width
) ||
3397 (width
> (GLsizei
) texImage
->Width
)) {
3398 _mesa_error(ctx
, GL_INVALID_VALUE
,
3399 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3404 if (((height
== 1 || height
== 2) &&
3405 height
!= (GLsizei
) texImage
->Height
) ||
3406 (height
> (GLsizei
) texImage
->Height
)) {
3407 _mesa_error(ctx
, GL_INVALID_VALUE
,
3408 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3414 if (((depth
== 1 || depth
== 2) &&
3415 depth
!= (GLsizei
) texImage
->Depth
) ||
3416 (depth
> (GLsizei
) texImage
->Depth
)) {
3417 _mesa_error(ctx
, GL_INVALID_VALUE
,
3418 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3428 * Implementation of the glCompressedTexImage1/2/3D() functions.
3431 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3432 GLenum target
, GLint level
,
3433 GLenum internalFormat
, GLsizei width
,
3434 GLsizei height
, GLsizei depth
, GLint border
,
3435 GLsizei imageSize
, const GLvoid
*data
)
3440 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3442 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3444 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3446 _mesa_lookup_enum_by_nr(target
), level
,
3447 _mesa_lookup_enum_by_nr(internalFormat
),
3448 width
, height
, depth
, border
, imageSize
, data
);
3451 if (!legal_teximage_target(ctx
, dims
, target
)) {
3452 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3453 dims
, _mesa_lookup_enum_by_nr(target
));
3457 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3458 internalFormat
, width
, height
, depth
,
3459 border
, imageSize
, &reason
);
3462 /* XXX this is kind of a hack */
3463 if (!error
&& dims
== 2) {
3464 switch (internalFormat
) {
3465 case GL_PALETTE4_RGB8_OES
:
3466 case GL_PALETTE4_RGBA8_OES
:
3467 case GL_PALETTE4_R5_G6_B5_OES
:
3468 case GL_PALETTE4_RGBA4_OES
:
3469 case GL_PALETTE4_RGB5_A1_OES
:
3470 case GL_PALETTE8_RGB8_OES
:
3471 case GL_PALETTE8_RGBA8_OES
:
3472 case GL_PALETTE8_R5_G6_B5_OES
:
3473 case GL_PALETTE8_RGBA4_OES
:
3474 case GL_PALETTE8_RGB5_A1_OES
:
3475 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3476 width
, height
, imageSize
, data
);
3482 if (_mesa_is_proxy_texture(target
)) {
3483 /* Proxy texture: just check for errors and update proxy state */
3484 struct gl_texture_image
*texImage
;
3487 struct gl_texture_object
*texObj
=
3488 _mesa_get_current_tex_object(ctx
, target
);
3489 gl_format texFormat
=
3490 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3491 internalFormat
, GL_NONE
, GL_NONE
);
3492 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3493 error
= GL_OUT_OF_MEMORY
;
3497 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3500 /* if error, clear all proxy texture image parameters */
3501 clear_teximage_fields(texImage
);
3504 /* no error: store the teximage parameters */
3505 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
3506 depth
, border
, internalFormat
,
3512 /* non-proxy target */
3513 struct gl_texture_object
*texObj
;
3514 struct gl_texture_image
*texImage
;
3517 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3521 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3523 _mesa_lock_texture(ctx
, texObj
);
3525 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3527 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3528 "glCompressedTexImage%uD", dims
);
3531 gl_format texFormat
;
3533 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3535 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3536 internalFormat
, GL_NONE
,
3539 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3540 _mesa_init_teximage_fields(ctx
, texImage
,
3541 width
, height
, depth
,
3542 border
, internalFormat
, texFormat
);
3544 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3546 width
, height
, depth
,
3547 border
, imageSize
, data
);
3549 check_gen_mipmap(ctx
, target
, texObj
, level
);
3551 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3554 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3555 "glCompressedTexImage%uD", dims
);
3559 _mesa_unlock_texture(ctx
, texObj
);
3565 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3566 GLenum internalFormat
, GLsizei width
,
3567 GLint border
, GLsizei imageSize
,
3570 GET_CURRENT_CONTEXT(ctx
);
3571 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3572 width
, 1, 1, border
, imageSize
, data
);
3577 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3578 GLenum internalFormat
, GLsizei width
,
3579 GLsizei height
, GLint border
, GLsizei imageSize
,
3582 GET_CURRENT_CONTEXT(ctx
);
3583 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3584 width
, height
, 1, border
, imageSize
, data
);
3589 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3590 GLenum internalFormat
, GLsizei width
,
3591 GLsizei height
, GLsizei depth
, GLint border
,
3592 GLsizei imageSize
, const GLvoid
*data
)
3594 GET_CURRENT_CONTEXT(ctx
);
3595 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3596 width
, height
, depth
, border
, imageSize
, data
);
3601 * Common helper for glCompressedTexSubImage1/2/3D().
3604 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3605 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3606 GLsizei width
, GLsizei height
, GLsizei depth
,
3607 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3609 struct gl_texture_object
*texObj
;
3610 struct gl_texture_image
*texImage
;
3612 GET_CURRENT_CONTEXT(ctx
);
3613 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3615 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3616 xoffset
, 0, 0, /* pos */
3617 width
, height
, depth
, /* size */
3620 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3624 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3626 _mesa_lock_texture(ctx
, texObj
);
3628 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3631 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3632 format
, texImage
)) {
3633 /* error was recorded */
3635 else if (width
> 0 && height
> 0 && depth
> 0) {
3636 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3637 xoffset
, yoffset
, zoffset
,
3638 width
, height
, depth
,
3639 format
, imageSize
, data
);
3641 check_gen_mipmap(ctx
, target
, texObj
, level
);
3643 ctx
->NewState
|= _NEW_TEXTURE
;
3646 _mesa_unlock_texture(ctx
, texObj
);
3651 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3652 GLsizei width
, GLenum format
,
3653 GLsizei imageSize
, const GLvoid
*data
)
3655 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3656 format
, imageSize
, data
);
3661 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3662 GLint yoffset
, GLsizei width
, GLsizei height
,
3663 GLenum format
, GLsizei imageSize
,
3666 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3667 width
, height
, 1, format
, imageSize
, data
);
3672 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3673 GLint yoffset
, GLint zoffset
, GLsizei width
,
3674 GLsizei height
, GLsizei depth
, GLenum format
,
3675 GLsizei imageSize
, const GLvoid
*data
)
3677 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3678 width
, height
, depth
, format
, imageSize
, data
);
3682 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3684 switch (internalFormat
) {
3686 return MESA_FORMAT_A8
;
3688 return MESA_FORMAT_A16
;
3689 case GL_ALPHA16F_ARB
:
3690 return MESA_FORMAT_ALPHA_FLOAT16
;
3691 case GL_ALPHA32F_ARB
:
3692 return MESA_FORMAT_ALPHA_FLOAT32
;
3693 case GL_ALPHA8I_EXT
:
3694 return MESA_FORMAT_ALPHA_INT8
;
3695 case GL_ALPHA16I_EXT
:
3696 return MESA_FORMAT_ALPHA_INT16
;
3697 case GL_ALPHA32I_EXT
:
3698 return MESA_FORMAT_ALPHA_INT32
;
3699 case GL_ALPHA8UI_EXT
:
3700 return MESA_FORMAT_ALPHA_UINT8
;
3701 case GL_ALPHA16UI_EXT
:
3702 return MESA_FORMAT_ALPHA_UINT16
;
3703 case GL_ALPHA32UI_EXT
:
3704 return MESA_FORMAT_ALPHA_UINT32
;
3706 return MESA_FORMAT_L8
;
3707 case GL_LUMINANCE16
:
3708 return MESA_FORMAT_L16
;
3709 case GL_LUMINANCE16F_ARB
:
3710 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3711 case GL_LUMINANCE32F_ARB
:
3712 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3713 case GL_LUMINANCE8I_EXT
:
3714 return MESA_FORMAT_LUMINANCE_INT8
;
3715 case GL_LUMINANCE16I_EXT
:
3716 return MESA_FORMAT_LUMINANCE_INT16
;
3717 case GL_LUMINANCE32I_EXT
:
3718 return MESA_FORMAT_LUMINANCE_INT32
;
3719 case GL_LUMINANCE8UI_EXT
:
3720 return MESA_FORMAT_LUMINANCE_UINT8
;
3721 case GL_LUMINANCE16UI_EXT
:
3722 return MESA_FORMAT_LUMINANCE_UINT16
;
3723 case GL_LUMINANCE32UI_EXT
:
3724 return MESA_FORMAT_LUMINANCE_UINT32
;
3725 case GL_LUMINANCE8_ALPHA8
:
3726 return MESA_FORMAT_AL88
;
3727 case GL_LUMINANCE16_ALPHA16
:
3728 return MESA_FORMAT_AL1616
;
3729 case GL_LUMINANCE_ALPHA16F_ARB
:
3730 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3731 case GL_LUMINANCE_ALPHA32F_ARB
:
3732 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3733 case GL_LUMINANCE_ALPHA8I_EXT
:
3734 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3735 case GL_LUMINANCE_ALPHA16I_EXT
:
3736 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3737 case GL_LUMINANCE_ALPHA32I_EXT
:
3738 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3739 case GL_LUMINANCE_ALPHA8UI_EXT
:
3740 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3741 case GL_LUMINANCE_ALPHA16UI_EXT
:
3742 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3743 case GL_LUMINANCE_ALPHA32UI_EXT
:
3744 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3746 return MESA_FORMAT_I8
;
3747 case GL_INTENSITY16
:
3748 return MESA_FORMAT_I16
;
3749 case GL_INTENSITY16F_ARB
:
3750 return MESA_FORMAT_INTENSITY_FLOAT16
;
3751 case GL_INTENSITY32F_ARB
:
3752 return MESA_FORMAT_INTENSITY_FLOAT32
;
3753 case GL_INTENSITY8I_EXT
:
3754 return MESA_FORMAT_INTENSITY_INT8
;
3755 case GL_INTENSITY16I_EXT
:
3756 return MESA_FORMAT_INTENSITY_INT16
;
3757 case GL_INTENSITY32I_EXT
:
3758 return MESA_FORMAT_INTENSITY_INT32
;
3759 case GL_INTENSITY8UI_EXT
:
3760 return MESA_FORMAT_INTENSITY_UINT8
;
3761 case GL_INTENSITY16UI_EXT
:
3762 return MESA_FORMAT_INTENSITY_UINT16
;
3763 case GL_INTENSITY32UI_EXT
:
3764 return MESA_FORMAT_INTENSITY_UINT32
;
3766 return MESA_FORMAT_RGBA8888_REV
;
3768 return MESA_FORMAT_RGBA_16
;
3769 case GL_RGBA16F_ARB
:
3770 return MESA_FORMAT_RGBA_FLOAT16
;
3771 case GL_RGBA32F_ARB
:
3772 return MESA_FORMAT_RGBA_FLOAT32
;
3774 return MESA_FORMAT_RGBA_INT8
;
3775 case GL_RGBA16I_EXT
:
3776 return MESA_FORMAT_RGBA_INT16
;
3777 case GL_RGBA32I_EXT
:
3778 return MESA_FORMAT_RGBA_INT32
;
3779 case GL_RGBA8UI_EXT
:
3780 return MESA_FORMAT_RGBA_UINT8
;
3781 case GL_RGBA16UI_EXT
:
3782 return MESA_FORMAT_RGBA_UINT16
;
3783 case GL_RGBA32UI_EXT
:
3784 return MESA_FORMAT_RGBA_UINT32
;
3787 return MESA_FORMAT_GR88
;
3789 return MESA_FORMAT_RG1616
;
3791 return MESA_FORMAT_RG_FLOAT16
;
3793 return MESA_FORMAT_RG_FLOAT32
;
3795 return MESA_FORMAT_RG_INT8
;
3797 return MESA_FORMAT_RG_INT16
;
3799 return MESA_FORMAT_RG_INT32
;
3801 return MESA_FORMAT_RG_UINT8
;
3803 return MESA_FORMAT_RG_UINT16
;
3805 return MESA_FORMAT_RG_UINT32
;
3808 return MESA_FORMAT_R8
;
3810 return MESA_FORMAT_R16
;
3812 return MESA_FORMAT_R_FLOAT16
;
3814 return MESA_FORMAT_R_FLOAT32
;
3816 return MESA_FORMAT_R_INT8
;
3818 return MESA_FORMAT_R_INT16
;
3820 return MESA_FORMAT_R_INT32
;
3822 return MESA_FORMAT_R_UINT8
;
3824 return MESA_FORMAT_R_UINT16
;
3826 return MESA_FORMAT_R_UINT32
;
3829 return MESA_FORMAT_NONE
;
3834 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3836 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
3839 if (format
== MESA_FORMAT_NONE
)
3840 return MESA_FORMAT_NONE
;
3842 datatype
= _mesa_get_format_datatype(format
);
3843 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3844 return MESA_FORMAT_NONE
;
3846 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3847 return MESA_FORMAT_NONE
;
3849 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
3850 * any mention of R/RG formats, but they appear in the GL 3.1 core
3853 if (ctx
->VersionMajor
< 3 ||
3854 (ctx
->VersionMajor
== 3 && ctx
->VersionMinor
== 0)) {
3855 GLenum base_format
= _mesa_get_format_base_format(format
);
3857 if (base_format
== GL_R
|| base_format
== GL_RG
)
3858 return MESA_FORMAT_NONE
;
3864 /** GL_ARB_texture_buffer_object */
3866 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3868 struct gl_texture_object
*texObj
;
3869 struct gl_buffer_object
*bufObj
;
3872 GET_CURRENT_CONTEXT(ctx
);
3873 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3875 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3876 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3880 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3881 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3885 format
= validate_texbuffer_format(ctx
, internalFormat
);
3886 if (format
== MESA_FORMAT_NONE
) {
3887 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
3892 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
3893 if (buffer
&& !bufObj
) {
3894 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
3898 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3900 _mesa_lock_texture(ctx
, texObj
);
3902 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
3903 texObj
->BufferObjectFormat
= internalFormat
;
3904 texObj
->_BufferObjectFormat
= format
;
3906 _mesa_unlock_texture(ctx
, texObj
);