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"
52 * State changes which we care about for glCopyTex[Sub]Image() calls.
53 * In particular, we care about pixel transfer state and buffer state
54 * (such as glReadBuffer to make sure we read from the right renderbuffer).
56 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
61 * Return the simple base format for a given internal texture format.
62 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
64 * \param ctx GL context.
65 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
67 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
68 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
70 * This is the format which is used during texture application (i.e. the
71 * texture format and env mode determine the arithmetic used.
74 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
76 switch (internalFormat
) {
91 case GL_LUMINANCE_ALPHA
:
92 case GL_LUMINANCE4_ALPHA4
:
93 case GL_LUMINANCE6_ALPHA2
:
94 case GL_LUMINANCE8_ALPHA8
:
95 case GL_LUMINANCE12_ALPHA4
:
96 case GL_LUMINANCE12_ALPHA12
:
97 case GL_LUMINANCE16_ALPHA16
:
98 return GL_LUMINANCE_ALPHA
;
129 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
131 if (ctx
->API
!= API_OPENGL
) {
132 switch (internalFormat
) {
140 if (ctx
->Extensions
.ARB_depth_texture
) {
141 switch (internalFormat
) {
142 case GL_DEPTH_COMPONENT
:
143 case GL_DEPTH_COMPONENT16
:
144 case GL_DEPTH_COMPONENT24
:
145 case GL_DEPTH_COMPONENT32
:
146 return GL_DEPTH_COMPONENT
;
152 switch (internalFormat
) {
153 case GL_COMPRESSED_ALPHA
:
155 case GL_COMPRESSED_LUMINANCE
:
157 case GL_COMPRESSED_LUMINANCE_ALPHA
:
158 return GL_LUMINANCE_ALPHA
;
159 case GL_COMPRESSED_INTENSITY
:
161 case GL_COMPRESSED_RGB
:
163 case GL_COMPRESSED_RGBA
:
169 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
170 switch (internalFormat
) {
171 case GL_COMPRESSED_RGB_FXT1_3DFX
:
173 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
180 if (ctx
->Extensions
.EXT_texture_compression_s3tc
) {
181 switch (internalFormat
) {
182 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
184 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
185 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
186 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
193 if (ctx
->Extensions
.S3_s3tc
) {
194 switch (internalFormat
) {
206 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
207 if (internalFormat
== GL_YCBCR_MESA
)
208 return GL_YCBCR_MESA
;
211 if (ctx
->Extensions
.ARB_texture_float
) {
212 switch (internalFormat
) {
213 case GL_ALPHA16F_ARB
:
214 case GL_ALPHA32F_ARB
:
222 case GL_INTENSITY16F_ARB
:
223 case GL_INTENSITY32F_ARB
:
225 case GL_LUMINANCE16F_ARB
:
226 case GL_LUMINANCE32F_ARB
:
228 case GL_LUMINANCE_ALPHA16F_ARB
:
229 case GL_LUMINANCE_ALPHA32F_ARB
:
230 return GL_LUMINANCE_ALPHA
;
236 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
237 switch (internalFormat
) {
246 if (ctx
->Extensions
.EXT_texture_snorm
) {
247 switch (internalFormat
) {
262 case GL_RGBA16_SNORM
:
265 case GL_ALPHA8_SNORM
:
266 case GL_ALPHA16_SNORM
:
268 case GL_LUMINANCE_SNORM
:
269 case GL_LUMINANCE8_SNORM
:
270 case GL_LUMINANCE16_SNORM
:
272 case GL_LUMINANCE_ALPHA_SNORM
:
273 case GL_LUMINANCE8_ALPHA8_SNORM
:
274 case GL_LUMINANCE16_ALPHA16_SNORM
:
275 return GL_LUMINANCE_ALPHA
;
276 case GL_INTENSITY_SNORM
:
277 case GL_INTENSITY8_SNORM
:
278 case GL_INTENSITY16_SNORM
:
285 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
286 switch (internalFormat
) {
287 case GL_DEPTH_STENCIL_EXT
:
288 case GL_DEPTH24_STENCIL8_EXT
:
289 return GL_DEPTH_STENCIL_EXT
;
295 #if FEATURE_EXT_texture_sRGB
296 if (ctx
->Extensions
.EXT_texture_sRGB
) {
297 switch (internalFormat
) {
300 case GL_COMPRESSED_SRGB_EXT
:
301 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
303 case GL_SRGB_ALPHA_EXT
:
304 case GL_SRGB8_ALPHA8_EXT
:
305 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
306 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
307 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
308 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
310 case GL_SLUMINANCE_ALPHA_EXT
:
311 case GL_SLUMINANCE8_ALPHA8_EXT
:
312 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
313 return GL_LUMINANCE_ALPHA
;
314 case GL_SLUMINANCE_EXT
:
315 case GL_SLUMINANCE8_EXT
:
316 case GL_COMPRESSED_SLUMINANCE_EXT
:
322 #endif /* FEATURE_EXT_texture_sRGB */
324 if (ctx
->VersionMajor
>= 3 ||
325 ctx
->Extensions
.EXT_texture_integer
) {
326 switch (internalFormat
) {
328 case GL_RGBA16UI_EXT
:
329 case GL_RGBA32UI_EXT
:
345 if (ctx
->Extensions
.EXT_texture_integer
) {
346 switch (internalFormat
) {
347 case GL_ALPHA8UI_EXT
:
348 case GL_ALPHA16UI_EXT
:
349 case GL_ALPHA32UI_EXT
:
351 case GL_ALPHA16I_EXT
:
352 case GL_ALPHA32I_EXT
:
354 case GL_INTENSITY8UI_EXT
:
355 case GL_INTENSITY16UI_EXT
:
356 case GL_INTENSITY32UI_EXT
:
357 case GL_INTENSITY8I_EXT
:
358 case GL_INTENSITY16I_EXT
:
359 case GL_INTENSITY32I_EXT
:
361 case GL_LUMINANCE8UI_EXT
:
362 case GL_LUMINANCE16UI_EXT
:
363 case GL_LUMINANCE32UI_EXT
:
364 case GL_LUMINANCE8I_EXT
:
365 case GL_LUMINANCE16I_EXT
:
366 case GL_LUMINANCE32I_EXT
:
368 case GL_LUMINANCE_ALPHA8UI_EXT
:
369 case GL_LUMINANCE_ALPHA16UI_EXT
:
370 case GL_LUMINANCE_ALPHA32UI_EXT
:
371 case GL_LUMINANCE_ALPHA8I_EXT
:
372 case GL_LUMINANCE_ALPHA16I_EXT
:
373 case GL_LUMINANCE_ALPHA32I_EXT
:
374 return GL_LUMINANCE_ALPHA
;
380 if (ctx
->Extensions
.ARB_texture_rg
) {
381 switch (internalFormat
) {
383 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
385 if (!ctx
->Extensions
.ARB_half_float_pixel
)
389 if (!ctx
->Extensions
.ARB_texture_float
)
398 if (ctx
->VersionMajor
< 3 && !ctx
->Extensions
.EXT_texture_integer
)
404 case GL_COMPRESSED_RED
:
408 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
410 if (!ctx
->Extensions
.ARB_half_float_pixel
)
414 if (!ctx
->Extensions
.ARB_texture_float
)
423 if (ctx
->VersionMajor
< 3 && !ctx
->Extensions
.EXT_texture_integer
)
429 case GL_COMPRESSED_RG
:
436 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
437 switch (internalFormat
) {
445 if (ctx
->Extensions
.EXT_packed_float
) {
446 switch (internalFormat
) {
447 case GL_R11F_G11F_B10F_EXT
:
454 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
455 switch (internalFormat
) {
456 case GL_DEPTH_COMPONENT32F
:
457 return GL_DEPTH_COMPONENT
;
458 case GL_DEPTH32F_STENCIL8
:
459 return GL_DEPTH_STENCIL
;
465 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
466 switch (internalFormat
) {
467 case GL_COMPRESSED_RED_RGTC1
:
468 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
470 case GL_COMPRESSED_RG_RGTC2
:
471 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
478 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
479 switch (internalFormat
) {
480 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
481 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
483 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
484 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
485 return GL_LUMINANCE_ALPHA
;
491 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
492 switch (internalFormat
) {
493 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
494 return GL_LUMINANCE_ALPHA
;
500 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
501 switch (internalFormat
) {
502 case GL_ETC1_RGB8_OES
:
509 if (ctx
->API
== API_OPENGLES
) {
510 switch (internalFormat
) {
511 case GL_PALETTE4_RGB8_OES
:
512 case GL_PALETTE4_R5_G6_B5_OES
:
513 case GL_PALETTE8_RGB8_OES
:
514 case GL_PALETTE8_R5_G6_B5_OES
:
516 case GL_PALETTE4_RGBA8_OES
:
517 case GL_PALETTE8_RGB5_A1_OES
:
518 case GL_PALETTE4_RGBA4_OES
:
519 case GL_PALETTE4_RGB5_A1_OES
:
520 case GL_PALETTE8_RGBA8_OES
:
521 case GL_PALETTE8_RGBA4_OES
:
528 return -1; /* error */
533 * For cube map faces, return a face index in [0,5].
534 * For other targets return 0;
537 _mesa_tex_target_to_face(GLenum target
)
539 if (_mesa_is_cube_face(target
))
540 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
548 * Install gl_texture_image in a gl_texture_object according to the target
549 * and level parameters.
551 * \param tObj texture object.
552 * \param target texture target.
553 * \param level image level.
554 * \param texImage texture image.
557 set_tex_image(struct gl_texture_object
*tObj
,
558 GLenum target
, GLint level
,
559 struct gl_texture_image
*texImage
)
561 const GLuint face
= _mesa_tex_target_to_face(target
);
565 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
568 tObj
->Image
[face
][level
] = texImage
;
570 /* Set the 'back' pointer */
571 texImage
->TexObject
= tObj
;
572 texImage
->Level
= level
;
573 texImage
->Face
= face
;
578 * Allocate a texture image structure.
580 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
583 * \return a pointer to gl_texture_image struct with all fields initialized to
586 struct gl_texture_image
*
587 _mesa_new_texture_image( struct gl_context
*ctx
)
590 return CALLOC_STRUCT(gl_texture_image
);
595 * Free a gl_texture_image and associated data.
596 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
598 * \param texImage texture image.
600 * Free the texture image structure and the associated image data.
603 _mesa_delete_texture_image(struct gl_context
*ctx
,
604 struct gl_texture_image
*texImage
)
606 /* Free texImage->Data and/or any other driver-specific texture
609 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
610 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
616 * Test if a target is a proxy target.
618 * \param target texture target.
620 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
623 _mesa_is_proxy_texture(GLenum target
)
626 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
627 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
629 assert(NUM_TEXTURE_TARGETS
== 7 + 2);
631 return (target
== GL_PROXY_TEXTURE_1D
||
632 target
== GL_PROXY_TEXTURE_2D
||
633 target
== GL_PROXY_TEXTURE_3D
||
634 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
635 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
636 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
637 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
);
642 * Return the proxy target which corresponds to the given texture target
645 get_proxy_target(GLenum target
)
649 case GL_PROXY_TEXTURE_1D
:
650 return GL_PROXY_TEXTURE_1D
;
652 case GL_PROXY_TEXTURE_2D
:
653 return GL_PROXY_TEXTURE_2D
;
655 case GL_PROXY_TEXTURE_3D
:
656 return GL_PROXY_TEXTURE_3D
;
657 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
658 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
659 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
660 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
661 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
662 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
663 case GL_TEXTURE_CUBE_MAP_ARB
:
664 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
665 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
666 case GL_TEXTURE_RECTANGLE_NV
:
667 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
668 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
669 case GL_TEXTURE_1D_ARRAY_EXT
:
670 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
671 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
672 case GL_TEXTURE_2D_ARRAY_EXT
:
673 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
674 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
676 _mesa_problem(NULL
, "unexpected target in get_proxy_target()");
683 * Get the texture object that corresponds to the target of the given
684 * texture unit. The target should have already been checked for validity.
686 * \param ctx GL context.
687 * \param texUnit texture unit.
688 * \param target texture target.
690 * \return pointer to the texture object on success, or NULL on failure.
692 struct gl_texture_object
*
693 _mesa_select_tex_object(struct gl_context
*ctx
,
694 const struct gl_texture_unit
*texUnit
,
697 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
698 ctx
->Extensions
.EXT_texture_array
);
702 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
703 case GL_PROXY_TEXTURE_1D
:
704 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
706 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
707 case GL_PROXY_TEXTURE_2D
:
708 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
710 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
711 case GL_PROXY_TEXTURE_3D
:
712 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
713 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
714 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
715 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
716 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
717 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
718 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
719 case GL_TEXTURE_CUBE_MAP_ARB
:
720 return ctx
->Extensions
.ARB_texture_cube_map
721 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
722 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
723 return ctx
->Extensions
.ARB_texture_cube_map
724 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
725 case GL_TEXTURE_RECTANGLE_NV
:
726 return ctx
->Extensions
.NV_texture_rectangle
727 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
728 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
729 return ctx
->Extensions
.NV_texture_rectangle
730 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
731 case GL_TEXTURE_1D_ARRAY_EXT
:
732 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
733 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
734 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
735 case GL_TEXTURE_2D_ARRAY_EXT
:
736 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
737 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
738 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
739 case GL_TEXTURE_BUFFER
:
740 return ctx
->Extensions
.ARB_texture_buffer_object
741 ? texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
742 case GL_TEXTURE_EXTERNAL_OES
:
743 return ctx
->Extensions
.OES_EGL_image_external
744 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
746 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
753 * Return pointer to texture object for given target on current texture unit.
755 struct gl_texture_object
*
756 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
758 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
759 return _mesa_select_tex_object(ctx
, texUnit
, target
);
764 * Get a texture image pointer from a texture object, given a texture
765 * target and mipmap level. The target and level parameters should
766 * have already been error-checked.
768 * \param ctx GL context.
769 * \param texObj texture unit.
770 * \param target texture target.
771 * \param level image level.
773 * \return pointer to the texture image structure, or NULL on failure.
775 struct gl_texture_image
*
776 _mesa_select_tex_image(struct gl_context
*ctx
,
777 const struct gl_texture_object
*texObj
,
778 GLenum target
, GLint level
)
780 const GLuint face
= _mesa_tex_target_to_face(target
);
784 ASSERT(level
< MAX_TEXTURE_LEVELS
);
786 return texObj
->Image
[face
][level
];
791 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
792 * it and install it. Only return NULL if passed a bad parameter or run
795 struct gl_texture_image
*
796 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
797 GLenum target
, GLint level
)
799 struct gl_texture_image
*texImage
;
804 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
806 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
808 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
812 set_tex_image(texObj
, target
, level
, texImage
);
820 * Return pointer to the specified proxy texture image.
821 * Note that proxy textures are per-context, not per-texture unit.
822 * \return pointer to texture image or NULL if invalid target, invalid
823 * level, or out of memory.
825 struct gl_texture_image
*
826 _mesa_get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
828 struct gl_texture_image
*texImage
;
835 case GL_PROXY_TEXTURE_1D
:
836 if (level
>= ctx
->Const
.MaxTextureLevels
)
838 texIndex
= TEXTURE_1D_INDEX
;
840 case GL_PROXY_TEXTURE_2D
:
841 if (level
>= ctx
->Const
.MaxTextureLevels
)
843 texIndex
= TEXTURE_2D_INDEX
;
845 case GL_PROXY_TEXTURE_3D
:
846 if (level
>= ctx
->Const
.Max3DTextureLevels
)
848 texIndex
= TEXTURE_3D_INDEX
;
850 case GL_PROXY_TEXTURE_CUBE_MAP
:
851 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
853 texIndex
= TEXTURE_CUBE_INDEX
;
855 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
858 texIndex
= TEXTURE_RECT_INDEX
;
860 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
861 if (level
>= ctx
->Const
.MaxTextureLevels
)
863 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
865 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
866 if (level
>= ctx
->Const
.MaxTextureLevels
)
868 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
874 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
876 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
878 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
881 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
882 /* Set the 'back' pointer */
883 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
890 * Get the maximum number of allowed mipmap levels.
892 * \param ctx GL context.
893 * \param target texture target.
895 * \return the maximum number of allowed mipmap levels for the given
896 * texture target, or zero if passed a bad target.
901 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
905 case GL_PROXY_TEXTURE_1D
:
907 case GL_PROXY_TEXTURE_2D
:
908 return ctx
->Const
.MaxTextureLevels
;
910 case GL_PROXY_TEXTURE_3D
:
911 return ctx
->Const
.Max3DTextureLevels
;
912 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
913 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
914 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
915 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
916 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
917 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
918 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
919 return ctx
->Extensions
.ARB_texture_cube_map
920 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
921 case GL_TEXTURE_RECTANGLE_NV
:
922 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
923 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
924 case GL_TEXTURE_1D_ARRAY_EXT
:
925 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
926 case GL_TEXTURE_2D_ARRAY_EXT
:
927 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
928 return (ctx
->Extensions
.MESA_texture_array
||
929 ctx
->Extensions
.EXT_texture_array
)
930 ? ctx
->Const
.MaxTextureLevels
: 0;
931 case GL_TEXTURE_BUFFER
:
932 case GL_TEXTURE_EXTERNAL_OES
:
935 return 0; /* bad target */
941 * Return number of dimensions per mipmap level for the given texture target.
944 _mesa_get_texture_dimensions(GLenum target
)
948 case GL_PROXY_TEXTURE_1D
:
951 case GL_TEXTURE_RECTANGLE
:
952 case GL_TEXTURE_CUBE_MAP
:
953 case GL_PROXY_TEXTURE_2D
:
954 case GL_PROXY_TEXTURE_RECTANGLE
:
955 case GL_PROXY_TEXTURE_CUBE_MAP
:
956 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
957 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
958 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
959 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
960 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
961 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
962 case GL_TEXTURE_1D_ARRAY
:
963 case GL_PROXY_TEXTURE_1D_ARRAY
:
964 case GL_TEXTURE_EXTERNAL_OES
:
967 case GL_PROXY_TEXTURE_3D
:
968 case GL_TEXTURE_2D_ARRAY
:
969 case GL_PROXY_TEXTURE_2D_ARRAY
:
971 case GL_TEXTURE_BUFFER
:
974 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
983 #if 000 /* not used anymore */
985 * glTexImage[123]D can accept a NULL image pointer. In this case we
986 * create a texture image with unspecified image contents per the OpenGL
990 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
992 const GLint components
= _mesa_components_in_format(format
);
993 const GLint numPixels
= width
* height
* depth
;
994 GLubyte
*data
= (GLubyte
*) MALLOC(numPixels
* components
* sizeof(GLubyte
));
998 * Let's see if anyone finds this. If glTexImage2D() is called with
999 * a NULL image pointer then load the texture image with something
1000 * interesting instead of leaving it indeterminate.
1003 static const char message
[8][32] = {
1004 " X X XXXXX XXX X ",
1005 " XX XX X X X X X ",
1007 " X X XXXX XXX XXXXX ",
1010 " X X XXXXX XXX X X ",
1014 GLubyte
*imgPtr
= data
;
1016 for (h
= 0; h
< depth
; h
++) {
1017 for (i
= 0; i
< height
; i
++) {
1018 GLint srcRow
= 7 - (i
% 8);
1019 for (j
= 0; j
< width
; j
++) {
1020 GLint srcCol
= j
% 32;
1021 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1022 for (k
= 0; k
< components
; k
++) {
1038 * Set the size and format-related fields of a gl_texture_image struct
1039 * to zero. This is used when a proxy texture test fails.
1042 clear_teximage_fields(struct gl_texture_image
*img
)
1045 img
->_BaseFormat
= 0;
1046 img
->InternalFormat
= 0;
1055 img
->HeightLog2
= 0;
1057 img
->TexFormat
= MESA_FORMAT_NONE
;
1062 * Initialize basic fields of the gl_texture_image struct.
1064 * \param ctx GL context.
1065 * \param img texture image structure to be initialized.
1066 * \param width image width.
1067 * \param height image height.
1068 * \param depth image depth.
1069 * \param border image border.
1070 * \param internalFormat internal format.
1071 * \param format the actual hardware format (one of MESA_FORMAT_*)
1073 * Fills in the fields of \p img with the given information.
1074 * Note: width, height and depth include the border.
1077 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1078 struct gl_texture_image
*img
,
1079 GLsizei width
, GLsizei height
, GLsizei depth
,
1080 GLint border
, GLenum internalFormat
,
1086 ASSERT(height
>= 0);
1089 target
= img
->TexObject
->Target
;
1090 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1091 ASSERT(img
->_BaseFormat
> 0);
1092 img
->InternalFormat
= internalFormat
;
1093 img
->Border
= border
;
1095 img
->Height
= height
;
1098 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1099 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1103 case GL_TEXTURE_BUFFER
:
1104 case GL_PROXY_TEXTURE_1D
:
1109 img
->HeightLog2
= 0;
1116 case GL_TEXTURE_1D_ARRAY
:
1117 case GL_PROXY_TEXTURE_1D_ARRAY
:
1118 img
->Height2
= height
; /* no border */
1119 img
->HeightLog2
= 0; /* not used */
1127 case GL_TEXTURE_RECTANGLE
:
1128 case GL_TEXTURE_CUBE_MAP
:
1129 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1130 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1131 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1132 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1133 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1134 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1135 case GL_TEXTURE_EXTERNAL_OES
:
1136 case GL_PROXY_TEXTURE_2D
:
1137 case GL_PROXY_TEXTURE_RECTANGLE
:
1138 case GL_PROXY_TEXTURE_CUBE_MAP
:
1139 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1140 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1147 case GL_TEXTURE_2D_ARRAY
:
1148 case GL_PROXY_TEXTURE_2D_ARRAY
:
1149 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1150 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1151 img
->Depth2
= depth
; /* no border */
1152 img
->DepthLog2
= 0; /* not used */
1155 case GL_PROXY_TEXTURE_3D
:
1156 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1157 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1158 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1159 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1162 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1166 img
->MaxLog2
= MAX2(img
->WidthLog2
, img
->HeightLog2
);
1167 img
->TexFormat
= format
;
1172 * Free and clear fields of the gl_texture_image struct.
1174 * \param ctx GL context.
1175 * \param texImage texture image structure to be cleared.
1177 * After the call, \p texImage will have no data associated with it. Its
1178 * fields are cleared so that its parent object will test incomplete.
1181 _mesa_clear_texture_image(struct gl_context
*ctx
,
1182 struct gl_texture_image
*texImage
)
1184 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1185 clear_teximage_fields(texImage
);
1190 * This is the fallback for Driver.TestProxyTexImage(). Test the texture
1191 * level, width, height and depth against the ctx->Const limits for textures.
1193 * A hardware driver might override this function if, for example, the
1194 * max 3D texture size is 512x512x64 (i.e. not a cube).
1196 * Note that width, height, depth == 0 is not an error. However, a
1197 * texture with zero width/height/depth will be considered "incomplete"
1198 * and texturing will effectively be disabled.
1200 * \param target one of GL_PROXY_TEXTURE_1D, GL_PROXY_TEXTURE_2D,
1201 * GL_PROXY_TEXTURE_3D, GL_PROXY_TEXTURE_RECTANGLE_NV,
1202 * GL_PROXY_TEXTURE_CUBE_MAP_ARB.
1203 * \param level as passed to glTexImage
1204 * \param internalFormat as passed to glTexImage
1205 * \param format as passed to glTexImage
1206 * \param type as passed to glTexImage
1207 * \param width as passed to glTexImage
1208 * \param height as passed to glTexImage
1209 * \param depth as passed to glTexImage
1210 * \param border as passed to glTexImage
1211 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1214 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1215 GLint internalFormat
, GLenum format
, GLenum type
,
1216 GLint width
, GLint height
, GLint depth
, GLint border
)
1220 (void) internalFormat
;
1225 case GL_PROXY_TEXTURE_1D
:
1226 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1227 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1229 if (level
>= ctx
->Const
.MaxTextureLevels
)
1231 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1232 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1237 case GL_PROXY_TEXTURE_2D
:
1238 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1239 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1241 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1243 if (level
>= ctx
->Const
.MaxTextureLevels
)
1245 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1246 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1248 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1253 case GL_PROXY_TEXTURE_3D
:
1254 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1255 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1257 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1259 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1261 if (level
>= ctx
->Const
.Max3DTextureLevels
)
1263 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1264 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1266 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1268 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1273 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1274 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1275 if (width
< 0 || width
> maxSize
)
1277 if (height
< 0 || height
> maxSize
)
1283 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1284 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1285 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1287 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1289 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1291 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1292 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1294 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1299 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1300 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1301 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1303 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1305 if (level
>= ctx
->Const
.MaxTextureLevels
)
1307 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1308 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1313 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1314 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1315 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1317 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1319 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1321 if (level
>= ctx
->Const
.MaxTextureLevels
)
1323 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1324 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1326 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1332 _mesa_problem(ctx
, "Invalid target in _mesa_test_proxy_teximage");
1339 * Check if the memory used by the texture would exceed the driver's limit.
1340 * This lets us support a max 3D texture size of 8K (for example) but
1341 * prevents allocating a full 8K x 8K x 8K texture.
1342 * XXX this could be rolled into the proxy texture size test (above) but
1343 * we don't have the actual texture internal format at that point.
1346 legal_texture_size(struct gl_context
*ctx
, gl_format format
,
1347 GLint width
, GLint height
, GLint depth
)
1349 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1350 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1351 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1356 * Return true if the format is only valid for glCompressedTexImage.
1359 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1362 case GL_ETC1_RGB8_OES
:
1371 * Helper function to determine whether a target and specific compression
1372 * format are supported.
1375 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1378 (void) intFormat
; /* not used yet */
1382 case GL_PROXY_TEXTURE_2D
:
1383 return GL_TRUE
; /* true for any compressed format so far */
1384 case GL_PROXY_TEXTURE_CUBE_MAP
:
1385 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1386 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1387 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1388 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1389 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1390 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1391 return ctx
->Extensions
.ARB_texture_cube_map
;
1392 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1393 case GL_TEXTURE_2D_ARRAY_EXT
:
1394 return (ctx
->Extensions
.MESA_texture_array
||
1395 ctx
->Extensions
.EXT_texture_array
);
1403 * Check if the given texture target value is legal for a
1404 * glTexImage1/2/3D call.
1407 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1413 case GL_PROXY_TEXTURE_1D
:
1421 case GL_PROXY_TEXTURE_2D
:
1423 case GL_PROXY_TEXTURE_CUBE_MAP
:
1424 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1425 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1426 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1427 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1428 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1429 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1430 return ctx
->Extensions
.ARB_texture_cube_map
;
1431 case GL_TEXTURE_RECTANGLE_NV
:
1432 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1433 return ctx
->Extensions
.NV_texture_rectangle
;
1434 case GL_TEXTURE_1D_ARRAY_EXT
:
1435 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1436 return (ctx
->Extensions
.MESA_texture_array
||
1437 ctx
->Extensions
.EXT_texture_array
);
1444 case GL_PROXY_TEXTURE_3D
:
1446 case GL_TEXTURE_2D_ARRAY_EXT
:
1447 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1448 return (ctx
->Extensions
.MESA_texture_array
||
1449 ctx
->Extensions
.EXT_texture_array
);
1454 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1461 * Check if the given texture target value is legal for a
1462 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1463 * The difference compared to legal_teximage_target() above is that
1464 * proxy targets are not supported.
1467 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1471 return target
== GL_TEXTURE_1D
;
1476 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1477 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1478 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1479 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1480 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1481 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1482 return ctx
->Extensions
.ARB_texture_cube_map
;
1483 case GL_TEXTURE_RECTANGLE_NV
:
1484 return ctx
->Extensions
.NV_texture_rectangle
;
1485 case GL_TEXTURE_1D_ARRAY_EXT
:
1486 return (ctx
->Extensions
.MESA_texture_array
||
1487 ctx
->Extensions
.EXT_texture_array
);
1495 case GL_TEXTURE_2D_ARRAY_EXT
:
1496 return (ctx
->Extensions
.MESA_texture_array
||
1497 ctx
->Extensions
.EXT_texture_array
);
1502 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1510 * Helper function to determine if a texture object is mutable (in terms
1511 * of GL_ARB_texture_storage).
1514 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1516 if (ctx
->Extensions
.ARB_texture_storage
) {
1517 struct gl_texture_object
*texObj
=
1518 _mesa_get_current_tex_object(ctx
, target
);
1519 return !texObj
->Immutable
;
1527 * Test the glTexImage[123]D() parameters for errors.
1529 * \param ctx GL context.
1530 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1531 * \param target texture target given by the user.
1532 * \param level image level given by the user.
1533 * \param internalFormat internal format given by the user.
1534 * \param format pixel data format given by the user.
1535 * \param type pixel data type given by the user.
1536 * \param width image width given by the user.
1537 * \param height image height given by the user.
1538 * \param depth image depth given by the user.
1539 * \param border image border given by the user.
1541 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1543 * Verifies each of the parameters against the constants specified in
1544 * __struct gl_contextRec::Const and the supported extensions, and according
1545 * to the OpenGL specification.
1548 texture_error_check( struct gl_context
*ctx
,
1549 GLuint dimensions
, GLenum target
,
1550 GLint level
, GLint internalFormat
,
1551 GLenum format
, GLenum type
,
1552 GLint width
, GLint height
,
1553 GLint depth
, GLint border
)
1555 const GLenum proxyTarget
= get_proxy_target(target
);
1556 const GLboolean isProxy
= target
== proxyTarget
;
1557 GLboolean sizeOK
= GL_TRUE
;
1558 GLboolean colorFormat
;
1561 /* Even though there are no color-index textures, we still have to support
1562 * uploading color-index data and remapping it to RGB via the
1563 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1565 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1567 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1568 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1570 _mesa_error(ctx
, GL_INVALID_VALUE
,
1571 "glTexImage%dD(level=%d)", dimensions
, level
);
1577 if (border
< 0 || border
> 1 ||
1578 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1579 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1581 _mesa_error(ctx
, GL_INVALID_VALUE
,
1582 "glTexImage%dD(border=%d)", dimensions
, border
);
1587 if (width
< 0 || height
< 0 || depth
< 0) {
1589 _mesa_error(ctx
, GL_INVALID_VALUE
,
1590 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1595 /* Do this simple check before calling the TestProxyTexImage() function */
1596 if (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
1597 sizeOK
= (width
== height
);
1601 * Use the proxy texture driver hook to see if the size/level/etc are
1604 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
1605 internalFormat
, format
,
1606 type
, width
, height
,
1610 _mesa_error(ctx
, GL_INVALID_VALUE
,
1611 "glTexImage%dD(level=%d, width=%d, height=%d, depth=%d)",
1612 dimensions
, level
, width
, height
, depth
);
1617 /* Check internalFormat */
1618 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1620 _mesa_error(ctx
, GL_INVALID_VALUE
,
1621 "glTexImage%dD(internalFormat=%s)",
1622 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1627 /* Check incoming image format and type */
1628 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1629 if (err
!= GL_NO_ERROR
) {
1631 _mesa_error(ctx
, err
,
1632 "glTexImage%dD(incompatible format 0x%x, type 0x%x)",
1633 dimensions
, format
, type
);
1638 /* make sure internal format and format basically agree */
1639 colorFormat
= _mesa_is_color_format(format
);
1640 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
1641 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
1642 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
1643 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
1644 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
1646 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1647 "glTexImage%dD(incompatible internalFormat 0x%x, format 0x%x)",
1648 dimensions
, internalFormat
, format
);
1652 /* additional checks for ycbcr textures */
1653 if (internalFormat
== GL_YCBCR_MESA
) {
1654 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
1655 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
1656 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
1658 _mesa_snprintf(message
, sizeof(message
),
1659 "glTexImage%dD(format/type YCBCR mismatch", dimensions
);
1660 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
1661 return GL_TRUE
; /* error */
1663 if (target
!= GL_TEXTURE_2D
&&
1664 target
!= GL_PROXY_TEXTURE_2D
&&
1665 target
!= GL_TEXTURE_RECTANGLE_NV
&&
1666 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
1668 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage(target)");
1674 _mesa_snprintf(message
, sizeof(message
),
1675 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
1676 dimensions
, border
);
1677 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
1683 /* additional checks for depth textures */
1684 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
) {
1685 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
1686 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
1687 if (target
!= GL_TEXTURE_1D
&&
1688 target
!= GL_PROXY_TEXTURE_1D
&&
1689 target
!= GL_TEXTURE_2D
&&
1690 target
!= GL_PROXY_TEXTURE_2D
&&
1691 target
!= GL_TEXTURE_1D_ARRAY
&&
1692 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1693 target
!= GL_TEXTURE_2D_ARRAY
&&
1694 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1695 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1696 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1697 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
1698 (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_gpu_shader4
))) {
1700 _mesa_error(ctx
, GL_INVALID_ENUM
,
1701 "glTexImage(target/internalFormat)");
1706 /* additional checks for compressed textures */
1707 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
1708 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
1710 _mesa_error(ctx
, GL_INVALID_ENUM
,
1711 "glTexImage%dD(target)", dimensions
);
1714 if (compressedteximage_only_format(ctx
, internalFormat
)) {
1715 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1716 "glTexImage%dD(no compression for format)", dimensions
);
1721 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1722 "glTexImage%dD(border!=0)", dimensions
);
1728 /* additional checks for integer textures */
1729 if ((ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_texture_integer
) &&
1730 (_mesa_is_integer_format(format
) !=
1731 _mesa_is_integer_format(internalFormat
))) {
1733 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1734 "glTexImage%dD(integer/non-integer format mismatch)",
1740 if (!mutable_tex_object(ctx
, target
)) {
1741 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1742 "glTexImage%dD(immutable texture)", dimensions
);
1746 /* if we get here, the parameters are OK */
1752 * Test glTexSubImage[123]D() parameters for errors.
1754 * \param ctx GL context.
1755 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1756 * \param target texture target given by the user.
1757 * \param level image level given by the user.
1758 * \param xoffset sub-image x offset given by the user.
1759 * \param yoffset sub-image y offset given by the user.
1760 * \param zoffset sub-image z offset given by the user.
1761 * \param format pixel data format given by the user.
1762 * \param type pixel data type given by the user.
1763 * \param width image width given by the user.
1764 * \param height image height given by the user.
1765 * \param depth image depth given by the user.
1767 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1769 * Verifies each of the parameters against the constants specified in
1770 * __struct gl_contextRec::Const and the supported extensions, and according
1771 * to the OpenGL specification.
1774 subtexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1775 GLenum target
, GLint level
,
1776 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1777 GLint width
, GLint height
, GLint depth
,
1778 GLenum format
, GLenum type
)
1782 /* Basic level check */
1783 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1784 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage2D(level=%d)", level
);
1788 /* Check for negative sizes */
1790 _mesa_error(ctx
, GL_INVALID_VALUE
,
1791 "glTexSubImage%dD(width=%d)", dimensions
, width
);
1794 if (height
< 0 && dimensions
> 1) {
1795 _mesa_error(ctx
, GL_INVALID_VALUE
,
1796 "glTexSubImage%dD(height=%d)", dimensions
, height
);
1799 if (depth
< 0 && dimensions
> 2) {
1800 _mesa_error(ctx
, GL_INVALID_VALUE
,
1801 "glTexSubImage%dD(depth=%d)", dimensions
, depth
);
1805 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1806 if (err
!= GL_NO_ERROR
) {
1807 _mesa_error(ctx
, err
,
1808 "glTexSubImage%dD(incompatible format 0x%x, type 0x%x)",
1809 dimensions
, format
, type
);
1818 * Do second part of glTexSubImage which depends on the destination texture.
1819 * \return GL_TRUE if error recorded, GL_FALSE otherwise
1822 subtexture_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
1823 GLenum target
, GLint level
,
1824 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1825 GLint width
, GLint height
, GLint depth
,
1826 GLenum format
, GLenum type
,
1827 const struct gl_texture_image
*destTex
)
1830 /* undefined image level */
1831 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexSubImage%dD", dimensions
);
1835 if (xoffset
< -((GLint
)destTex
->Border
)) {
1836 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset)",
1840 if (xoffset
+ width
> (GLint
) (destTex
->Width
+ destTex
->Border
)) {
1841 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(xoffset+width)",
1845 if (dimensions
> 1) {
1846 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destTex
->Border
;
1847 if (yoffset
< -yBorder
) {
1848 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset)",
1852 if (yoffset
+ height
> (GLint
) destTex
->Height
+ yBorder
) {
1853 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage%dD(yoffset+height)",
1858 if (dimensions
> 2) {
1859 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destTex
->Border
;
1860 if (zoffset
< -zBorder
) {
1861 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset)");
1864 if (zoffset
+ depth
> (GLint
) destTex
->Depth
+ zBorder
) {
1865 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexSubImage3D(zoffset+depth)");
1870 if (_mesa_is_format_compressed(destTex
->TexFormat
)) {
1873 if (compressedteximage_only_format(ctx
, destTex
->InternalFormat
)) {
1874 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1875 "glTexSubImage%dD(no compression for format)", dimensions
);
1879 /* do tests which depend on compression block size */
1880 _mesa_get_format_block_size(destTex
->TexFormat
, &bw
, &bh
);
1882 /* offset must be multiple of block size */
1883 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1884 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1885 "glTexSubImage%dD(xoffset = %d, yoffset = %d)",
1886 dimensions
, xoffset
, yoffset
);
1889 /* size must be multiple of bw by bh or equal to whole texture size */
1890 if ((width
% bw
!= 0) && (GLuint
) width
!= destTex
->Width
) {
1891 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1892 "glTexSubImage%dD(width = %d)", dimensions
, width
);
1895 if ((height
% bh
!= 0) && (GLuint
) height
!= destTex
->Height
) {
1896 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1897 "glTexSubImage%dD(height = %d)", dimensions
, height
);
1902 if (ctx
->VersionMajor
>= 3 || ctx
->Extensions
.EXT_texture_integer
) {
1903 /* both source and dest must be integer-valued, or neither */
1904 if (_mesa_is_format_integer_color(destTex
->TexFormat
) !=
1905 _mesa_is_integer_format(format
)) {
1906 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1907 "glTexSubImage%dD(integer/non-integer format mismatch)",
1918 * Test glCopyTexImage[12]D() parameters for errors.
1920 * \param ctx GL context.
1921 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1922 * \param target texture target given by the user.
1923 * \param level image level given by the user.
1924 * \param internalFormat internal format given by the user.
1925 * \param width image width given by the user.
1926 * \param height image height given by the user.
1927 * \param border texture border.
1929 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
1931 * Verifies each of the parameters against the constants specified in
1932 * __struct gl_contextRec::Const and the supported extensions, and according
1933 * to the OpenGL specification.
1936 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
1937 GLenum target
, GLint level
, GLint internalFormat
,
1938 GLint width
, GLint height
, GLint border
)
1940 const GLenum proxyTarget
= get_proxy_target(target
);
1941 const GLenum type
= GL_FLOAT
;
1946 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
1947 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
1948 dimensions
, _mesa_lookup_enum_by_nr(target
));
1952 /* Basic level check (more checking in ctx->Driver.TestProxyTexImage) */
1953 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
1954 _mesa_error(ctx
, GL_INVALID_VALUE
,
1955 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
1959 /* Check that the source buffer is complete */
1960 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
1961 if (ctx
->ReadBuffer
->_Status
== 0) {
1962 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
1964 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
1965 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
1966 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
1970 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
1971 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION
,
1972 "glCopyTexImage%dD(multisample FBO)",
1979 if (border
< 0 || border
> 1 ||
1980 ((target
== GL_TEXTURE_RECTANGLE_NV
||
1981 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1985 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
1986 if (baseFormat
< 0) {
1987 _mesa_error(ctx
, GL_INVALID_VALUE
,
1988 "glCopyTexImage%dD(internalFormat)", dimensions
);
1992 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
1993 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1994 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
1998 /* From the EXT_texture_integer spec:
2000 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2001 * if the texture internalformat is an integer format and the read color
2002 * buffer is not an integer format, or if the internalformat is not an
2003 * integer format and the read color buffer is an integer format."
2005 if (_mesa_is_color_format(internalFormat
)) {
2006 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2008 if (_mesa_is_integer_format(rb
->InternalFormat
) !=
2009 _mesa_is_integer_format(internalFormat
)) {
2010 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2011 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2016 /* Do size, level checking */
2017 sizeOK
= (proxyTarget
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
)
2018 ? (width
== height
) : 1;
2020 sizeOK
= sizeOK
&& ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
2021 internalFormat
, baseFormat
,
2022 type
, width
, height
,
2026 if (dimensions
== 1) {
2027 _mesa_error(ctx
, GL_INVALID_VALUE
,
2028 "glCopyTexImage1D(width=%d)", width
);
2031 ASSERT(dimensions
== 2);
2032 _mesa_error(ctx
, GL_INVALID_VALUE
,
2033 "glCopyTexImage2D(width=%d, height=%d)", width
, height
);
2038 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2039 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2040 _mesa_error(ctx
, GL_INVALID_ENUM
,
2041 "glCopyTexImage%dD(target)", dimensions
);
2044 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2045 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2046 "glCopyTexImage%dD(no compression for format)", dimensions
);
2050 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2051 "glCopyTexImage%dD(border!=0)", dimensions
);
2056 if (!mutable_tex_object(ctx
, target
)) {
2057 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2058 "glCopyTexImage%dD(immutable texture)", dimensions
);
2062 /* if we get here, the parameters are OK */
2068 * Test glCopyTexSubImage[12]D() parameters for errors.
2069 * Note that this is the first part of error checking.
2070 * See also copytexsubimage_error_check2() below for the second part.
2072 * \param ctx GL context.
2073 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2074 * \param target texture target given by the user.
2075 * \param level image level given by the user.
2077 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2080 copytexsubimage_error_check1( struct gl_context
*ctx
, GLuint dimensions
,
2081 GLenum target
, GLint level
)
2083 /* Check that the source buffer is complete */
2084 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2085 if (ctx
->ReadBuffer
->_Status
== 0) {
2086 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2088 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2089 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2090 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2094 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2095 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION
,
2096 "glCopyTexSubImage%dD(multisample FBO)",
2102 /* check target (proxies not allowed) */
2103 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2104 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2105 dimensions
, _mesa_lookup_enum_by_nr(target
));
2110 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
2111 _mesa_error(ctx
, GL_INVALID_VALUE
,
2112 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2121 * Second part of error checking for glCopyTexSubImage[12]D().
2122 * \param xoffset sub-image x offset given by the user.
2123 * \param yoffset sub-image y offset given by the user.
2124 * \param zoffset sub-image z offset given by the user.
2125 * \param width image width given by the user.
2126 * \param height image height given by the user.
2129 copytexsubimage_error_check2( struct gl_context
*ctx
, GLuint dimensions
,
2130 GLenum target
, GLint level
,
2131 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2132 GLsizei width
, GLsizei height
,
2133 const struct gl_texture_image
*teximage
)
2135 /* check that dest tex image exists */
2137 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2138 "glCopyTexSubImage%dD(undefined texture level: %d)",
2145 _mesa_error(ctx
, GL_INVALID_VALUE
,
2146 "glCopyTexSubImage%dD(width=%d)", dimensions
, width
);
2149 if (dimensions
> 1 && height
< 0) {
2150 _mesa_error(ctx
, GL_INVALID_VALUE
,
2151 "glCopyTexSubImage%dD(height=%d)", dimensions
, height
);
2155 /* check x/y offsets */
2156 if (xoffset
< -((GLint
)teximage
->Border
)) {
2157 _mesa_error(ctx
, GL_INVALID_VALUE
,
2158 "glCopyTexSubImage%dD(xoffset=%d)", dimensions
, xoffset
);
2161 if (xoffset
+ width
> (GLint
) (teximage
->Width
+ teximage
->Border
)) {
2162 _mesa_error(ctx
, GL_INVALID_VALUE
,
2163 "glCopyTexSubImage%dD(xoffset+width)", dimensions
);
2166 if (dimensions
> 1) {
2167 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : teximage
->Border
;
2168 if (yoffset
< -yBorder
) {
2169 _mesa_error(ctx
, GL_INVALID_VALUE
,
2170 "glCopyTexSubImage%dD(yoffset=%d)", dimensions
, yoffset
);
2173 /* NOTE: we're adding the border here, not subtracting! */
2174 if (yoffset
+ height
> (GLint
) teximage
->Height
+ yBorder
) {
2175 _mesa_error(ctx
, GL_INVALID_VALUE
,
2176 "glCopyTexSubImage%dD(yoffset+height)", dimensions
);
2181 /* check z offset */
2182 if (dimensions
> 2) {
2183 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : teximage
->Border
;
2184 if (zoffset
< -zBorder
) {
2185 _mesa_error(ctx
, GL_INVALID_VALUE
,
2186 "glCopyTexSubImage%dD(zoffset)", dimensions
);
2189 if (zoffset
> (GLint
) teximage
->Depth
+ zBorder
) {
2190 _mesa_error(ctx
, GL_INVALID_VALUE
,
2191 "glCopyTexSubImage%dD(zoffset+depth)", dimensions
);
2196 if (_mesa_is_format_compressed(teximage
->TexFormat
)) {
2197 if (compressedteximage_only_format(ctx
, teximage
->InternalFormat
)) {
2198 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2199 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2202 /* offset must be multiple of 4 */
2203 if ((xoffset
& 3) || (yoffset
& 3)) {
2204 _mesa_error(ctx
, GL_INVALID_VALUE
,
2205 "glCopyTexSubImage%dD(xoffset or yoffset)", dimensions
);
2208 /* size must be multiple of 4 */
2209 if ((width
& 3) != 0 && (GLuint
) width
!= teximage
->Width
) {
2210 _mesa_error(ctx
, GL_INVALID_VALUE
,
2211 "glCopyTexSubImage%dD(width)", dimensions
);
2214 if ((height
& 3) != 0 && (GLuint
) height
!= teximage
->Height
) {
2215 _mesa_error(ctx
, GL_INVALID_VALUE
,
2216 "glCopyTexSubImage%dD(height)", dimensions
);
2221 if (teximage
->InternalFormat
== GL_YCBCR_MESA
) {
2222 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2226 if (!_mesa_source_buffer_exists(ctx
, teximage
->_BaseFormat
)) {
2227 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2228 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2229 dimensions
, teximage
->_BaseFormat
);
2233 /* From the EXT_texture_integer spec:
2235 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2236 * if the texture internalformat is an integer format and the read color
2237 * buffer is not an integer format, or if the internalformat is not an
2238 * integer format and the read color buffer is an integer format."
2240 if (_mesa_is_color_format(teximage
->InternalFormat
)) {
2241 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2243 if (_mesa_is_format_integer_color(rb
->Format
) !=
2244 _mesa_is_format_integer_color(teximage
->TexFormat
)) {
2245 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2246 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2251 /* if we get here, the parameters are OK */
2256 /** Callback info for walking over FBO hash table */
2259 struct gl_context
*ctx
;
2260 struct gl_texture_object
*texObj
;
2266 * Check render to texture callback. Called from _mesa_HashWalk().
2269 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2271 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2272 const struct cb_info
*info
= (struct cb_info
*) userData
;
2273 struct gl_context
*ctx
= info
->ctx
;
2274 const struct gl_texture_object
*texObj
= info
->texObj
;
2275 const GLuint level
= info
->level
, face
= info
->face
;
2277 /* If this is a user-created FBO */
2278 if (_mesa_is_user_fbo(fb
)) {
2280 /* check if any of the FBO's attachments point to 'texObj' */
2281 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2282 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2283 if (att
->Type
== GL_TEXTURE
&&
2284 att
->Texture
== texObj
&&
2285 att
->TextureLevel
== level
&&
2286 att
->CubeMapFace
== face
) {
2287 ASSERT(_mesa_get_attachment_teximage(att
));
2288 /* Tell driver about the new renderbuffer texture */
2289 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2290 /* Mark fb status as indeterminate to force re-validation */
2299 * When a texture image is specified we have to check if it's bound to
2300 * any framebuffer objects (render to texture) in order to detect changes
2301 * in size or format since that effects FBO completeness.
2302 * Any FBOs rendering into the texture must be re-validated.
2305 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2306 struct gl_texture_object
*texObj
,
2307 GLuint face
, GLuint level
)
2309 /* Only check this texture if it's been marked as RenderToTexture */
2310 if (texObj
->_RenderToTexture
) {
2311 struct cb_info info
;
2313 info
.texObj
= texObj
;
2316 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2322 * If the texture object's GenerateMipmap flag is set and we've
2323 * changed the texture base level image, regenerate the rest of the
2324 * mipmap levels now.
2327 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2328 struct gl_texture_object
*texObj
, GLint level
)
2330 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2331 if (texObj
->GenerateMipmap
&&
2332 level
== texObj
->BaseLevel
&&
2333 level
< texObj
->MaxLevel
) {
2334 ASSERT(ctx
->Driver
.GenerateMipmap
);
2335 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2340 /** Debug helper: override the user-requested internal format */
2342 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2345 if (internalFormat
== GL_RGBA16F_ARB
||
2346 internalFormat
== GL_RGBA32F_ARB
) {
2347 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2350 else if (internalFormat
== GL_RGB16F_ARB
||
2351 internalFormat
== GL_RGB32F_ARB
) {
2352 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2355 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2356 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2357 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2358 return GL_LUMINANCE_ALPHA
;
2360 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2361 internalFormat
== GL_LUMINANCE32F_ARB
) {
2362 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2363 return GL_LUMINANCE
;
2365 else if (internalFormat
== GL_ALPHA16F_ARB
||
2366 internalFormat
== GL_ALPHA32F_ARB
) {
2367 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2371 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2372 internalFormat = GL_RGBA;
2376 return internalFormat
;
2379 return internalFormat
;
2385 * Choose the actual hardware format for a texture image.
2386 * Try to use the same format as the previous image level when possible.
2387 * Otherwise, ask the driver for the best format.
2388 * It's important to try to choose a consistant format for all levels
2389 * for efficient texture memory layout/allocation. In particular, this
2390 * comes up during automatic mipmap generation.
2393 _mesa_choose_texture_format(struct gl_context
*ctx
,
2394 struct gl_texture_object
*texObj
,
2395 GLenum target
, GLint level
,
2396 GLenum internalFormat
, GLenum format
, GLenum type
)
2400 /* see if we've already chosen a format for the previous level */
2402 struct gl_texture_image
*prevImage
=
2403 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2404 /* See if the prev level is defined and has an internal format which
2405 * matches the new internal format.
2408 prevImage
->Width
> 0 &&
2409 prevImage
->InternalFormat
== internalFormat
) {
2410 /* use the same format */
2411 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2412 return prevImage
->TexFormat
;
2416 /* choose format from scratch */
2417 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
2418 ASSERT(f
!= MESA_FORMAT_NONE
);
2423 * Adjust pixel unpack params and image dimensions to strip off the
2426 * Gallium and intel don't support texture borders. They've seldem been used
2427 * and seldom been implemented correctly anyway.
2429 * \param unpackNew returns the new pixel unpack parameters
2432 strip_texture_border(GLint
*border
,
2433 GLint
*width
, GLint
*height
, GLint
*depth
,
2434 const struct gl_pixelstore_attrib
*unpack
,
2435 struct gl_pixelstore_attrib
*unpackNew
)
2437 assert(*border
> 0); /* sanity check */
2439 *unpackNew
= *unpack
;
2441 if (unpackNew
->RowLength
== 0)
2442 unpackNew
->RowLength
= *width
;
2444 if (depth
&& unpackNew
->ImageHeight
== 0)
2445 unpackNew
->ImageHeight
= *height
;
2447 unpackNew
->SkipPixels
+= *border
;
2449 unpackNew
->SkipRows
+= *border
;
2451 unpackNew
->SkipImages
+= *border
;
2453 assert(*width
>= 3);
2454 *width
= *width
- 2 * *border
;
2455 if (height
&& *height
>= 3)
2456 *height
= *height
- 2 * *border
;
2457 if (depth
&& *depth
>= 3)
2458 *depth
= *depth
- 2 * *border
;
2463 * Common code to implement all the glTexImage1D/2D/3D functions.
2466 teximage(struct gl_context
*ctx
, GLuint dims
,
2467 GLenum target
, GLint level
, GLint internalFormat
,
2468 GLsizei width
, GLsizei height
, GLsizei depth
,
2469 GLint border
, GLenum format
, GLenum type
,
2470 const GLvoid
*pixels
)
2473 struct gl_pixelstore_attrib unpack_no_border
;
2474 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2476 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2478 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2479 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2481 _mesa_lookup_enum_by_nr(target
), level
,
2482 _mesa_lookup_enum_by_nr(internalFormat
),
2483 width
, height
, depth
, border
,
2484 _mesa_lookup_enum_by_nr(format
),
2485 _mesa_lookup_enum_by_nr(type
), pixels
);
2487 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2489 /* target error checking */
2490 if (!legal_teximage_target(ctx
, dims
, target
)) {
2491 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2492 dims
, _mesa_lookup_enum_by_nr(target
));
2496 /* general error checking */
2497 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2498 format
, type
, width
, height
, depth
, border
);
2500 if (_mesa_is_proxy_texture(target
)) {
2501 /* Proxy texture: just clear or set state depending on error checking */
2502 struct gl_texture_image
*texImage
=
2503 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2506 /* when error, clear all proxy texture image parameters */
2508 clear_teximage_fields(texImage
);
2511 /* no error, set the tex image parameters */
2512 struct gl_texture_object
*texObj
=
2513 _mesa_get_current_tex_object(ctx
, target
);
2514 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2519 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2520 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
2521 depth
, border
, internalFormat
,
2524 else if (texImage
) {
2525 clear_teximage_fields(texImage
);
2530 /* non-proxy target */
2531 const GLuint face
= _mesa_tex_target_to_face(target
);
2532 struct gl_texture_object
*texObj
;
2533 struct gl_texture_image
*texImage
;
2536 return; /* error was recorded */
2539 /* Allow a hardware driver to just strip out the border, to provide
2540 * reliable but slightly incorrect hardware rendering instead of
2541 * rarely-tested software fallback rendering.
2543 if (border
&& ctx
->Const
.StripTextureBorder
) {
2544 strip_texture_border(&border
, &width
, &height
, &depth
, unpack
,
2546 unpack
= &unpack_no_border
;
2549 if (ctx
->NewState
& _NEW_PIXEL
)
2550 _mesa_update_state(ctx
);
2552 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2554 _mesa_lock_texture(ctx
, texObj
);
2556 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2559 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2562 gl_format texFormat
;
2564 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2566 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2567 internalFormat
, format
,
2570 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2571 _mesa_init_teximage_fields(ctx
, texImage
,
2572 width
, height
, depth
,
2573 border
, internalFormat
, texFormat
);
2575 /* Give the texture to the driver. <pixels> may be null. */
2576 ASSERT(ctx
->Driver
.TexImage3D
);
2579 ctx
->Driver
.TexImage1D(ctx
, texImage
, internalFormat
,
2580 width
, border
, format
,
2581 type
, pixels
, unpack
);
2584 ctx
->Driver
.TexImage2D(ctx
, texImage
, internalFormat
,
2585 width
, height
, border
, format
,
2586 type
, pixels
, unpack
);
2589 ctx
->Driver
.TexImage3D(ctx
, texImage
, internalFormat
,
2590 width
, height
, depth
, border
, format
,
2591 type
, pixels
, unpack
);
2594 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2597 check_gen_mipmap(ctx
, target
, texObj
, level
);
2599 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2602 texObj
->_Complete
= GL_FALSE
;
2603 ctx
->NewState
|= _NEW_TEXTURE
;
2606 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2610 _mesa_unlock_texture(ctx
, texObj
);
2616 * Called from the API. Note that width includes the border.
2619 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2620 GLsizei width
, GLint border
, GLenum format
,
2621 GLenum type
, const GLvoid
*pixels
)
2623 GET_CURRENT_CONTEXT(ctx
);
2624 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2625 border
, format
, type
, pixels
);
2630 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2631 GLsizei width
, GLsizei height
, GLint border
,
2632 GLenum format
, GLenum type
,
2633 const GLvoid
*pixels
)
2635 GET_CURRENT_CONTEXT(ctx
);
2636 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2637 border
, format
, type
, pixels
);
2642 * Called by the API or display list executor.
2643 * Note that width and height include the border.
2646 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2647 GLsizei width
, GLsizei height
, GLsizei depth
,
2648 GLint border
, GLenum format
, GLenum type
,
2649 const GLvoid
*pixels
)
2651 GET_CURRENT_CONTEXT(ctx
);
2652 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2653 border
, format
, type
, pixels
);
2658 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2659 GLsizei width
, GLsizei height
, GLsizei depth
,
2660 GLint border
, GLenum format
, GLenum type
,
2661 const GLvoid
*pixels
)
2663 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2664 depth
, border
, format
, type
, pixels
);
2668 #if FEATURE_OES_EGL_image
2670 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2672 struct gl_texture_object
*texObj
;
2673 struct gl_texture_image
*texImage
;
2674 GET_CURRENT_CONTEXT(ctx
);
2675 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2677 if ((target
== GL_TEXTURE_2D
&&
2678 !ctx
->Extensions
.OES_EGL_image
) ||
2679 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2680 !ctx
->Extensions
.OES_EGL_image_external
)) {
2681 _mesa_error(ctx
, GL_INVALID_ENUM
,
2682 "glEGLImageTargetTexture2D(target=%d)", target
);
2686 if (ctx
->NewState
& _NEW_PIXEL
)
2687 _mesa_update_state(ctx
);
2689 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2690 _mesa_lock_texture(ctx
, texObj
);
2692 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2694 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2696 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2698 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2699 texObj
, texImage
, image
);
2702 texObj
->_Complete
= GL_FALSE
;
2703 ctx
->NewState
|= _NEW_TEXTURE
;
2705 _mesa_unlock_texture(ctx
, texObj
);
2713 * Implement all the glTexSubImage1/2/3D() functions.
2716 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2717 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2718 GLsizei width
, GLsizei height
, GLsizei depth
,
2719 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2721 struct gl_texture_object
*texObj
;
2722 struct gl_texture_image
*texImage
;
2724 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2726 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2727 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2729 _mesa_lookup_enum_by_nr(target
), level
,
2730 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2731 _mesa_lookup_enum_by_nr(format
),
2732 _mesa_lookup_enum_by_nr(type
), pixels
);
2734 /* check target (proxies not allowed) */
2735 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2736 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2737 dims
, _mesa_lookup_enum_by_nr(target
));
2741 if (ctx
->NewState
& _NEW_PIXEL
)
2742 _mesa_update_state(ctx
);
2744 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2745 width
, height
, depth
, format
, type
)) {
2746 return; /* error was detected */
2749 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2751 _mesa_lock_texture(ctx
, texObj
);
2753 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2755 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2756 xoffset
, yoffset
, zoffset
,
2757 width
, height
, depth
,
2758 format
, type
, texImage
)) {
2759 /* error was recorded */
2761 else if (width
> 0 && height
> 0 && depth
> 0) {
2762 /* If we have a border, offset=-1 is legal. Bias by border width. */
2765 if (target
!= GL_TEXTURE_2D_ARRAY
)
2766 zoffset
+= texImage
->Border
;
2769 if (target
!= GL_TEXTURE_1D_ARRAY
)
2770 yoffset
+= texImage
->Border
;
2773 xoffset
+= texImage
->Border
;
2778 ctx
->Driver
.TexSubImage1D(ctx
, texImage
,
2780 format
, type
, pixels
, &ctx
->Unpack
);
2783 ctx
->Driver
.TexSubImage2D(ctx
, texImage
,
2784 xoffset
, yoffset
, width
, height
,
2785 format
, type
, pixels
, &ctx
->Unpack
);
2788 ctx
->Driver
.TexSubImage3D(ctx
, texImage
,
2789 xoffset
, yoffset
, zoffset
,
2790 width
, height
, depth
,
2791 format
, type
, pixels
, &ctx
->Unpack
);
2794 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2797 check_gen_mipmap(ctx
, target
, texObj
, level
);
2799 ctx
->NewState
|= _NEW_TEXTURE
;
2802 _mesa_unlock_texture(ctx
, texObj
);
2807 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2808 GLint xoffset
, GLsizei width
,
2809 GLenum format
, GLenum type
,
2810 const GLvoid
*pixels
)
2812 GET_CURRENT_CONTEXT(ctx
);
2813 texsubimage(ctx
, 1, target
, level
,
2816 format
, type
, pixels
);
2821 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2822 GLint xoffset
, GLint yoffset
,
2823 GLsizei width
, GLsizei height
,
2824 GLenum format
, GLenum type
,
2825 const GLvoid
*pixels
)
2827 GET_CURRENT_CONTEXT(ctx
);
2828 texsubimage(ctx
, 2, target
, level
,
2829 xoffset
, yoffset
, 0,
2831 format
, type
, pixels
);
2837 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2838 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2839 GLsizei width
, GLsizei height
, GLsizei depth
,
2840 GLenum format
, GLenum type
,
2841 const GLvoid
*pixels
)
2843 GET_CURRENT_CONTEXT(ctx
);
2844 texsubimage(ctx
, 3, target
, level
,
2845 xoffset
, yoffset
, zoffset
,
2846 width
, height
, depth
,
2847 format
, type
, pixels
);
2853 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
2854 * from. This depends on whether the texture contains color or depth values.
2856 static struct gl_renderbuffer
*
2857 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
2859 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
2860 /* reading from depth/stencil buffer */
2861 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
2864 /* copying from color buffer */
2865 return ctx
->ReadBuffer
->_ColorReadBuffer
;
2872 * Implement the glCopyTexImage1/2D() functions.
2875 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2876 GLenum target
, GLint level
, GLenum internalFormat
,
2877 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2879 struct gl_texture_object
*texObj
;
2880 struct gl_texture_image
*texImage
;
2881 const GLuint face
= _mesa_tex_target_to_face(target
);
2883 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2885 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2886 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2888 _mesa_lookup_enum_by_nr(target
), level
,
2889 _mesa_lookup_enum_by_nr(internalFormat
),
2890 x
, y
, width
, height
, border
);
2892 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2893 _mesa_update_state(ctx
);
2895 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2896 width
, height
, border
))
2899 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2901 if (border
&& ctx
->Const
.StripTextureBorder
) {
2903 width
-= border
* 2;
2906 height
-= border
* 2;
2911 _mesa_lock_texture(ctx
, texObj
);
2913 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2916 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2919 /* choose actual hw format */
2920 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2925 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2926 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2928 /* Free old texture image */
2929 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2931 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
2932 border
, internalFormat
, texFormat
);
2934 /* Allocate texture memory (no pixel data yet) */
2936 ctx
->Driver
.TexImage1D(ctx
, texImage
, internalFormat
,
2937 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2941 ctx
->Driver
.TexImage2D(ctx
, texImage
, internalFormat
,
2942 width
, height
, border
, GL_NONE
, GL_NONE
,
2943 NULL
, &ctx
->Unpack
);
2946 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2948 struct gl_renderbuffer
*srcRb
=
2949 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
2952 ctx
->Driver
.CopyTexSubImage1D(ctx
, texImage
, dstX
,
2953 srcRb
, srcX
, srcY
, width
);
2956 ctx
->Driver
.CopyTexSubImage2D(ctx
, texImage
, dstX
, dstY
,
2957 srcRb
, srcX
, srcY
, width
, height
);
2960 check_gen_mipmap(ctx
, target
, texObj
, level
);
2962 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2965 texObj
->_Complete
= GL_FALSE
;
2966 ctx
->NewState
|= _NEW_TEXTURE
;
2969 /* probably too large of image */
2970 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2974 _mesa_unlock_texture(ctx
, texObj
);
2980 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2981 GLenum internalFormat
,
2983 GLsizei width
, GLint border
)
2985 GET_CURRENT_CONTEXT(ctx
);
2986 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2992 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2993 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
2996 GET_CURRENT_CONTEXT(ctx
);
2997 copyteximage(ctx
, 2, target
, level
, internalFormat
,
2998 x
, y
, width
, height
, border
);
3004 * Implementation for glCopyTexSubImage1/2/3D() functions.
3007 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3008 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3009 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3011 struct gl_texture_object
*texObj
;
3012 struct gl_texture_image
*texImage
;
3014 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3016 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3017 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3019 _mesa_lookup_enum_by_nr(target
),
3020 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3022 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3023 _mesa_update_state(ctx
);
3025 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
3028 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3030 _mesa_lock_texture(ctx
, texObj
);
3032 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3034 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
3035 zoffset
, width
, height
, texImage
)) {
3036 /* error was recored */
3039 /* If we have a border, offset=-1 is legal. Bias by border width. */
3042 if (target
!= GL_TEXTURE_2D_ARRAY
)
3043 zoffset
+= texImage
->Border
;
3046 if (target
!= GL_TEXTURE_1D_ARRAY
)
3047 yoffset
+= texImage
->Border
;
3050 xoffset
+= texImage
->Border
;
3053 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3055 struct gl_renderbuffer
*srcRb
=
3056 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3060 ctx
->Driver
.CopyTexSubImage1D(ctx
, texImage
, xoffset
,
3061 srcRb
, x
, y
, width
);
3064 ctx
->Driver
.CopyTexSubImage2D(ctx
, texImage
, xoffset
, yoffset
,
3065 srcRb
, x
, y
, width
, height
);
3068 ctx
->Driver
.CopyTexSubImage3D(ctx
, texImage
,
3069 xoffset
, yoffset
, zoffset
,
3070 srcRb
, x
, y
, width
, height
);
3073 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
3076 check_gen_mipmap(ctx
, target
, texObj
, level
);
3078 ctx
->NewState
|= _NEW_TEXTURE
;
3082 _mesa_unlock_texture(ctx
, texObj
);
3087 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3088 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3090 GET_CURRENT_CONTEXT(ctx
);
3091 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3097 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3098 GLint xoffset
, GLint yoffset
,
3099 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3101 GET_CURRENT_CONTEXT(ctx
);
3102 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3109 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3110 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3111 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3113 GET_CURRENT_CONTEXT(ctx
);
3114 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3115 x
, y
, width
, height
);
3121 /**********************************************************************/
3122 /****** Compressed Textures ******/
3123 /**********************************************************************/
3127 * Return expected size of a compressed texture.
3130 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3133 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3134 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3139 * Return compressed texture block size, in pixels.
3142 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3144 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3145 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3150 * Error checking for glCompressedTexImage[123]D().
3151 * \param reason returns reason for error, if any
3152 * \return error code or GL_NO_ERROR.
3155 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3156 GLenum target
, GLint level
,
3157 GLenum internalFormat
, GLsizei width
,
3158 GLsizei height
, GLsizei depth
, GLint border
,
3159 GLsizei imageSize
, char **reason
)
3161 const GLenum proxyTarget
= get_proxy_target(target
);
3162 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3164 GLenum choose_format
;
3166 GLenum proxy_format
;
3168 *reason
= ""; /* no error */
3170 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3172 return GL_INVALID_ENUM
;
3175 /* This will detect any invalid internalFormat value */
3176 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3177 *reason
= "internalFormat";
3178 return GL_INVALID_ENUM
;
3181 switch (internalFormat
) {
3183 case GL_PALETTE4_RGB8_OES
:
3184 case GL_PALETTE4_RGBA8_OES
:
3185 case GL_PALETTE4_R5_G6_B5_OES
:
3186 case GL_PALETTE4_RGBA4_OES
:
3187 case GL_PALETTE4_RGB5_A1_OES
:
3188 case GL_PALETTE8_RGB8_OES
:
3189 case GL_PALETTE8_RGBA8_OES
:
3190 case GL_PALETTE8_R5_G6_B5_OES
:
3191 case GL_PALETTE8_RGBA4_OES
:
3192 case GL_PALETTE8_RGB5_A1_OES
:
3193 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3195 proxy_format
= choose_format
;
3198 if (level
> 0 || level
< -maxLevels
) {
3200 return GL_INVALID_VALUE
;
3203 if (dimensions
!= 2) {
3204 *reason
= "compressed paletted textures must be 2D";
3205 return GL_INVALID_OPERATION
;
3208 /* Figure out the expected texture size (in bytes). This will be
3209 * checked against the actual size later.
3211 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3214 /* This is for the benefit of the TestProxyTexImage below. It expects
3215 * level to be non-negative. OES_compressed_paletted_texture uses a
3216 * weird mechanism where the level specified to glCompressedTexImage2D
3217 * is -(n-1) number of levels in the texture, and the data specifies the
3218 * complete mipmap stack. This is done to ensure the palette is the
3219 * same for all levels.
3226 choose_format
= GL_NONE
;
3227 choose_type
= GL_NONE
;
3228 proxy_format
= internalFormat
;
3231 if (level
< 0 || level
>= maxLevels
) {
3233 return GL_INVALID_VALUE
;
3236 /* Figure out the expected texture size (in bytes). This will be
3237 * checked against the actual size later.
3239 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3243 /* This should really never fail */
3244 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3245 *reason
= "internalFormat";
3246 return GL_INVALID_ENUM
;
3249 /* No compressed formats support borders at this time */
3251 *reason
= "border != 0";
3252 return GL_INVALID_VALUE
;
3255 /* For cube map, width must equal height */
3256 if (_mesa_is_cube_face(target
) && width
!= height
) {
3257 *reason
= "width != height";
3258 return GL_INVALID_VALUE
;
3261 /* check image size against compression block size */
3263 gl_format texFormat
=
3264 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3265 choose_format
, choose_type
);
3268 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3269 if ((width
> bw
&& width
% bw
> 0) ||
3270 (height
> bh
&& height
% bh
> 0)) {
3272 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3273 * generated [...] if any parameter combinations are not
3274 * supported by the specific compressed internal format.
3276 *reason
= "invalid width or height for compression format";
3277 return GL_INVALID_OPERATION
;
3281 /* check image sizes */
3282 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3283 proxy_format
, choose_format
,
3285 width
, height
, depth
, border
)) {
3286 /* See error comment above */
3287 *reason
= "invalid width, height or format";
3288 return GL_INVALID_OPERATION
;
3291 /* check image size in bytes */
3292 if (expectedSize
!= imageSize
) {
3293 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3294 * if <imageSize> is not consistent with the format, dimensions, and
3295 * contents of the specified image.
3297 *reason
= "imageSize inconsistant with width/height/format";
3298 return GL_INVALID_VALUE
;
3301 if (!mutable_tex_object(ctx
, target
)) {
3302 *reason
= "immutable texture";
3303 return GL_INVALID_OPERATION
;
3311 * Error checking for glCompressedTexSubImage[123]D().
3312 * \warning There are some bad assumptions here about the size of compressed
3313 * texture tiles (multiple of 4) used to test the validity of the
3314 * offset and size parameters.
3315 * \return error code or GL_NO_ERROR.
3318 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3319 GLenum target
, GLint level
,
3320 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3321 GLsizei width
, GLsizei height
, GLsizei depth
,
3322 GLenum format
, GLsizei imageSize
)
3324 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3328 if (dimensions
== 1) {
3329 /* 1D compressed textures not allowed */
3330 return GL_INVALID_ENUM
;
3332 else if (dimensions
== 2) {
3333 if (target
== GL_PROXY_TEXTURE_2D
) {
3334 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3336 else if (target
== GL_TEXTURE_2D
) {
3337 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3339 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3340 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3341 return GL_INVALID_ENUM
; /*target*/
3342 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3344 else if (_mesa_is_cube_face(target
)) {
3345 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3346 return GL_INVALID_ENUM
; /*target*/
3347 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3350 return GL_INVALID_ENUM
; /*target*/
3353 else if (dimensions
== 3) {
3354 /* 3D compressed textures not allowed */
3355 return GL_INVALID_ENUM
;
3358 maxTextureSize
= 1 << (maxLevels
- 1);
3360 /* this will catch any invalid compressed format token */
3361 if (!_mesa_is_compressed_format(ctx
, format
))
3362 return GL_INVALID_ENUM
;
3364 if (width
< 1 || width
> maxTextureSize
)
3365 return GL_INVALID_VALUE
;
3367 if ((height
< 1 || height
> maxTextureSize
)
3369 return GL_INVALID_VALUE
;
3371 if (level
< 0 || level
>= maxLevels
)
3372 return GL_INVALID_VALUE
;
3375 * do checks which depend on compression block size
3377 get_compressed_block_size(format
, &bw
, &bh
);
3379 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3380 return GL_INVALID_VALUE
;
3382 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3383 return GL_INVALID_VALUE
;
3385 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3386 return GL_INVALID_VALUE
;
3388 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3389 if (expectedSize
!= imageSize
)
3390 return GL_INVALID_VALUE
;
3397 * Do second part of glCompressedTexSubImage error checking.
3398 * \return GL_TRUE if error found, GL_FALSE otherwise.
3401 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3402 GLsizei width
, GLsizei height
,
3403 GLsizei depth
, GLenum format
,
3404 struct gl_texture_image
*texImage
)
3407 if ((GLint
) format
!= texImage
->InternalFormat
) {
3408 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3409 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3413 if (compressedteximage_only_format(ctx
, format
)) {
3414 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3415 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3420 if (((width
== 1 || width
== 2) &&
3421 width
!= (GLsizei
) texImage
->Width
) ||
3422 (width
> (GLsizei
) texImage
->Width
)) {
3423 _mesa_error(ctx
, GL_INVALID_VALUE
,
3424 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3429 if (((height
== 1 || height
== 2) &&
3430 height
!= (GLsizei
) texImage
->Height
) ||
3431 (height
> (GLsizei
) texImage
->Height
)) {
3432 _mesa_error(ctx
, GL_INVALID_VALUE
,
3433 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3439 if (((depth
== 1 || depth
== 2) &&
3440 depth
!= (GLsizei
) texImage
->Depth
) ||
3441 (depth
> (GLsizei
) texImage
->Depth
)) {
3442 _mesa_error(ctx
, GL_INVALID_VALUE
,
3443 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3453 * Implementation of the glCompressedTexImage1/2/3D() functions.
3456 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3457 GLenum target
, GLint level
,
3458 GLenum internalFormat
, GLsizei width
,
3459 GLsizei height
, GLsizei depth
, GLint border
,
3460 GLsizei imageSize
, const GLvoid
*data
)
3465 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3467 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3469 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3471 _mesa_lookup_enum_by_nr(target
), level
,
3472 _mesa_lookup_enum_by_nr(internalFormat
),
3473 width
, height
, depth
, border
, imageSize
, data
);
3476 if (!legal_teximage_target(ctx
, dims
, target
)) {
3477 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3478 dims
, _mesa_lookup_enum_by_nr(target
));
3482 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3483 internalFormat
, width
, height
, depth
,
3484 border
, imageSize
, &reason
);
3487 /* XXX this is kind of a hack */
3488 if (!error
&& dims
== 2) {
3489 switch (internalFormat
) {
3490 case GL_PALETTE4_RGB8_OES
:
3491 case GL_PALETTE4_RGBA8_OES
:
3492 case GL_PALETTE4_R5_G6_B5_OES
:
3493 case GL_PALETTE4_RGBA4_OES
:
3494 case GL_PALETTE4_RGB5_A1_OES
:
3495 case GL_PALETTE8_RGB8_OES
:
3496 case GL_PALETTE8_RGBA8_OES
:
3497 case GL_PALETTE8_R5_G6_B5_OES
:
3498 case GL_PALETTE8_RGBA4_OES
:
3499 case GL_PALETTE8_RGB5_A1_OES
:
3500 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3501 width
, height
, imageSize
, data
);
3507 if (_mesa_is_proxy_texture(target
)) {
3508 /* Proxy texture: just check for errors and update proxy state */
3509 struct gl_texture_image
*texImage
;
3512 struct gl_texture_object
*texObj
=
3513 _mesa_get_current_tex_object(ctx
, target
);
3514 gl_format texFormat
=
3515 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3516 internalFormat
, GL_NONE
, GL_NONE
);
3517 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3518 error
= GL_OUT_OF_MEMORY
;
3522 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3525 /* if error, clear all proxy texture image parameters */
3526 clear_teximage_fields(texImage
);
3529 /* no error: store the teximage parameters */
3530 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
3531 depth
, border
, internalFormat
,
3537 /* non-proxy target */
3538 struct gl_texture_object
*texObj
;
3539 struct gl_texture_image
*texImage
;
3542 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3546 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3548 _mesa_lock_texture(ctx
, texObj
);
3550 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3552 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3553 "glCompressedTexImage%uD", dims
);
3556 gl_format texFormat
;
3558 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3560 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3561 internalFormat
, GL_NONE
,
3564 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3565 _mesa_init_teximage_fields(ctx
, texImage
,
3566 width
, height
, depth
,
3567 border
, internalFormat
, texFormat
);
3571 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3572 ctx
->Driver
.CompressedTexImage1D(ctx
, texImage
,
3575 border
, imageSize
, data
);
3578 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3579 ctx
->Driver
.CompressedTexImage2D(ctx
, texImage
,
3582 border
, imageSize
, data
);
3585 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3586 ctx
->Driver
.CompressedTexImage3D(ctx
, texImage
,
3588 width
, height
, depth
,
3589 border
, imageSize
, data
);
3592 _mesa_problem(ctx
, "bad dims in compressedteximage");
3595 check_gen_mipmap(ctx
, target
, texObj
, level
);
3598 texObj
->_Complete
= GL_FALSE
;
3599 ctx
->NewState
|= _NEW_TEXTURE
;
3602 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3603 "glCompressedTexImage%uD", dims
);
3607 _mesa_unlock_texture(ctx
, texObj
);
3613 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3614 GLenum internalFormat
, GLsizei width
,
3615 GLint border
, GLsizei imageSize
,
3618 GET_CURRENT_CONTEXT(ctx
);
3619 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3620 width
, 1, 1, border
, imageSize
, data
);
3625 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3626 GLenum internalFormat
, GLsizei width
,
3627 GLsizei height
, GLint border
, GLsizei imageSize
,
3630 GET_CURRENT_CONTEXT(ctx
);
3631 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3632 width
, height
, 1, border
, imageSize
, data
);
3637 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3638 GLenum internalFormat
, GLsizei width
,
3639 GLsizei height
, GLsizei depth
, GLint border
,
3640 GLsizei imageSize
, const GLvoid
*data
)
3642 GET_CURRENT_CONTEXT(ctx
);
3643 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3644 width
, height
, depth
, border
, imageSize
, data
);
3649 * Common helper for glCompressedTexSubImage1/2/3D().
3652 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3653 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3654 GLsizei width
, GLsizei height
, GLsizei depth
,
3655 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3657 struct gl_texture_object
*texObj
;
3658 struct gl_texture_image
*texImage
;
3660 GET_CURRENT_CONTEXT(ctx
);
3661 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3663 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3664 xoffset
, 0, 0, /* pos */
3665 width
, height
, depth
, /* size */
3668 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3672 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3674 _mesa_lock_texture(ctx
, texObj
);
3676 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3679 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3680 format
, texImage
)) {
3681 /* error was recorded */
3683 else if (width
> 0 && height
> 0 && depth
> 0) {
3686 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3687 ctx
->Driver
.CompressedTexSubImage1D(ctx
, texImage
,
3689 format
, imageSize
, data
);
3693 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3694 ctx
->Driver
.CompressedTexSubImage2D(ctx
, texImage
,
3697 format
, imageSize
, data
);
3701 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3702 ctx
->Driver
.CompressedTexSubImage3D(ctx
, texImage
,
3703 xoffset
, yoffset
, zoffset
,
3704 width
, height
, depth
,
3705 format
, imageSize
, data
);
3712 check_gen_mipmap(ctx
, target
, texObj
, level
);
3714 ctx
->NewState
|= _NEW_TEXTURE
;
3717 _mesa_unlock_texture(ctx
, texObj
);
3722 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3723 GLsizei width
, GLenum format
,
3724 GLsizei imageSize
, const GLvoid
*data
)
3726 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3727 format
, imageSize
, data
);
3732 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3733 GLint yoffset
, GLsizei width
, GLsizei height
,
3734 GLenum format
, GLsizei imageSize
,
3737 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3738 width
, height
, 1, format
, imageSize
, data
);
3743 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3744 GLint yoffset
, GLint zoffset
, GLsizei width
,
3745 GLsizei height
, GLsizei depth
, GLenum format
,
3746 GLsizei imageSize
, const GLvoid
*data
)
3748 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3749 width
, height
, depth
, format
, imageSize
, data
);
3754 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3755 * return the basic data type and number of components for the format.
3756 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3759 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3760 GLenum
*datatype
, GLuint
*components
)
3762 switch (internalFormat
) {
3764 *datatype
= GL_UNSIGNED_BYTE
;
3768 *datatype
= GL_UNSIGNED_SHORT
;
3771 case GL_ALPHA16F_ARB
:
3772 *datatype
= GL_HALF_FLOAT
;
3775 case GL_ALPHA32F_ARB
:
3776 *datatype
= GL_FLOAT
;
3779 case GL_ALPHA8I_EXT
:
3780 *datatype
= GL_BYTE
;
3783 case GL_ALPHA16I_EXT
:
3784 *datatype
= GL_SHORT
;
3787 case GL_ALPHA32I_EXT
:
3791 case GL_ALPHA8UI_EXT
:
3792 *datatype
= GL_UNSIGNED_BYTE
;
3795 case GL_ALPHA16UI_EXT
:
3796 *datatype
= GL_UNSIGNED_SHORT
;
3799 case GL_ALPHA32UI_EXT
:
3800 *datatype
= GL_UNSIGNED_INT
;
3804 *datatype
= GL_UNSIGNED_BYTE
;
3807 case GL_LUMINANCE16
:
3808 *datatype
= GL_UNSIGNED_SHORT
;
3811 case GL_LUMINANCE16F_ARB
:
3812 *datatype
= GL_HALF_FLOAT
;
3815 case GL_LUMINANCE32F_ARB
:
3816 *datatype
= GL_FLOAT
;
3819 case GL_LUMINANCE8I_EXT
:
3820 *datatype
= GL_BYTE
;
3823 case GL_LUMINANCE16I_EXT
:
3824 *datatype
= GL_SHORT
;
3827 case GL_LUMINANCE32I_EXT
:
3831 case GL_LUMINANCE8UI_EXT
:
3832 *datatype
= GL_UNSIGNED_BYTE
;
3835 case GL_LUMINANCE16UI_EXT
:
3836 *datatype
= GL_UNSIGNED_SHORT
;
3839 case GL_LUMINANCE32UI_EXT
:
3840 *datatype
= GL_UNSIGNED_INT
;
3843 case GL_LUMINANCE8_ALPHA8
:
3844 *datatype
= GL_UNSIGNED_BYTE
;
3847 case GL_LUMINANCE16_ALPHA16
:
3848 *datatype
= GL_UNSIGNED_SHORT
;
3851 case GL_LUMINANCE_ALPHA16F_ARB
:
3852 *datatype
= GL_HALF_FLOAT
;
3855 case GL_LUMINANCE_ALPHA32F_ARB
:
3856 *datatype
= GL_FLOAT
;
3859 case GL_LUMINANCE_ALPHA8I_EXT
:
3860 *datatype
= GL_BYTE
;
3863 case GL_LUMINANCE_ALPHA16I_EXT
:
3864 *datatype
= GL_SHORT
;
3867 case GL_LUMINANCE_ALPHA32I_EXT
:
3871 case GL_LUMINANCE_ALPHA8UI_EXT
:
3872 *datatype
= GL_UNSIGNED_BYTE
;
3875 case GL_LUMINANCE_ALPHA16UI_EXT
:
3876 *datatype
= GL_UNSIGNED_SHORT
;
3879 case GL_LUMINANCE_ALPHA32UI_EXT
:
3880 *datatype
= GL_UNSIGNED_INT
;
3884 *datatype
= GL_UNSIGNED_BYTE
;
3887 case GL_INTENSITY16
:
3888 *datatype
= GL_UNSIGNED_SHORT
;
3891 case GL_INTENSITY16F_ARB
:
3892 *datatype
= GL_HALF_FLOAT
;
3895 case GL_INTENSITY32F_ARB
:
3896 *datatype
= GL_FLOAT
;
3899 case GL_INTENSITY8I_EXT
:
3900 *datatype
= GL_BYTE
;
3903 case GL_INTENSITY16I_EXT
:
3904 *datatype
= GL_SHORT
;
3907 case GL_INTENSITY32I_EXT
:
3911 case GL_INTENSITY8UI_EXT
:
3912 *datatype
= GL_UNSIGNED_BYTE
;
3915 case GL_INTENSITY16UI_EXT
:
3916 *datatype
= GL_UNSIGNED_SHORT
;
3919 case GL_INTENSITY32UI_EXT
:
3920 *datatype
= GL_UNSIGNED_INT
;
3924 *datatype
= GL_UNSIGNED_BYTE
;
3928 *datatype
= GL_UNSIGNED_SHORT
;
3931 case GL_RGBA16F_ARB
:
3932 *datatype
= GL_HALF_FLOAT
;
3935 case GL_RGBA32F_ARB
:
3936 *datatype
= GL_FLOAT
;
3940 *datatype
= GL_BYTE
;
3943 case GL_RGBA16I_EXT
:
3944 *datatype
= GL_SHORT
;
3947 case GL_RGBA32I_EXT
:
3951 case GL_RGBA8UI_EXT
:
3952 *datatype
= GL_UNSIGNED_BYTE
;
3955 case GL_RGBA16UI_EXT
:
3956 *datatype
= GL_UNSIGNED_SHORT
;
3959 case GL_RGBA32UI_EXT
:
3960 *datatype
= GL_UNSIGNED_INT
;
3967 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3970 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3977 /** GL_ARB_texture_buffer_object */
3979 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3981 struct gl_texture_object
*texObj
;
3982 struct gl_buffer_object
*bufObj
;
3986 GET_CURRENT_CONTEXT(ctx
);
3987 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3989 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3990 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3994 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3995 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
3999 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
4000 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4005 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4006 if (buffer
&& !bufObj
) {
4007 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4011 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4013 _mesa_lock_texture(ctx
, texObj
);
4015 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4016 texObj
->BufferObjectFormat
= internalFormat
;
4018 _mesa_unlock_texture(ctx
, texObj
);