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
2424 * one-pixel texture border.
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(GLenum target
,
2433 GLint
*width
, GLint
*height
, GLint
*depth
,
2434 const struct gl_pixelstore_attrib
*unpack
,
2435 struct gl_pixelstore_attrib
*unpackNew
)
2441 *unpackNew
= *unpack
;
2443 if (unpackNew
->RowLength
== 0)
2444 unpackNew
->RowLength
= *width
;
2446 if (unpackNew
->ImageHeight
== 0)
2447 unpackNew
->ImageHeight
= *height
;
2449 assert(*width
>= 3);
2450 unpackNew
->SkipPixels
++; /* skip the border */
2451 *width
= *width
- 2; /* reduce the width by two border pixels */
2453 /* The min height of a texture with a border is 3 */
2454 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2455 unpackNew
->SkipRows
++; /* skip the border */
2456 *height
= *height
- 2; /* reduce the height by two border pixels */
2459 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
) {
2460 unpackNew
->SkipImages
++; /* skip the border */
2461 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2466 * Common code to implement all the glTexImage1D/2D/3D functions.
2469 teximage(struct gl_context
*ctx
, GLuint dims
,
2470 GLenum target
, GLint level
, GLint internalFormat
,
2471 GLsizei width
, GLsizei height
, GLsizei depth
,
2472 GLint border
, GLenum format
, GLenum type
,
2473 const GLvoid
*pixels
)
2476 struct gl_pixelstore_attrib unpack_no_border
;
2477 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2479 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2481 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2482 _mesa_debug(ctx
, "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2484 _mesa_lookup_enum_by_nr(target
), level
,
2485 _mesa_lookup_enum_by_nr(internalFormat
),
2486 width
, height
, depth
, border
,
2487 _mesa_lookup_enum_by_nr(format
),
2488 _mesa_lookup_enum_by_nr(type
), pixels
);
2490 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2492 /* target error checking */
2493 if (!legal_teximage_target(ctx
, dims
, target
)) {
2494 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexImage%uD(target=%s)",
2495 dims
, _mesa_lookup_enum_by_nr(target
));
2499 /* general error checking */
2500 error
= texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2501 format
, type
, width
, height
, depth
, border
);
2503 if (_mesa_is_proxy_texture(target
)) {
2504 /* Proxy texture: just clear or set state depending on error checking */
2505 struct gl_texture_image
*texImage
=
2506 _mesa_get_proxy_tex_image(ctx
, target
, level
);
2509 /* when error, clear all proxy texture image parameters */
2511 clear_teximage_fields(texImage
);
2514 /* no error, set the tex image parameters */
2515 struct gl_texture_object
*texObj
=
2516 _mesa_get_current_tex_object(ctx
, target
);
2517 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2522 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2523 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
2524 depth
, border
, internalFormat
,
2527 else if (texImage
) {
2528 clear_teximage_fields(texImage
);
2533 /* non-proxy target */
2534 const GLuint face
= _mesa_tex_target_to_face(target
);
2535 struct gl_texture_object
*texObj
;
2536 struct gl_texture_image
*texImage
;
2539 return; /* error was recorded */
2542 /* Allow a hardware driver to just strip out the border, to provide
2543 * reliable but slightly incorrect hardware rendering instead of
2544 * rarely-tested software fallback rendering.
2546 if (border
&& ctx
->Const
.StripTextureBorder
) {
2547 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
2550 unpack
= &unpack_no_border
;
2553 if (ctx
->NewState
& _NEW_PIXEL
)
2554 _mesa_update_state(ctx
);
2556 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2558 _mesa_lock_texture(ctx
, texObj
);
2560 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2563 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2566 gl_format texFormat
;
2568 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2570 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
2571 internalFormat
, format
,
2574 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
2575 _mesa_init_teximage_fields(ctx
, texImage
,
2576 width
, height
, depth
,
2577 border
, internalFormat
, texFormat
);
2579 /* Give the texture to the driver. <pixels> may be null. */
2580 ASSERT(ctx
->Driver
.TexImage3D
);
2583 ctx
->Driver
.TexImage1D(ctx
, texImage
, internalFormat
,
2584 width
, border
, format
,
2585 type
, pixels
, unpack
);
2588 ctx
->Driver
.TexImage2D(ctx
, texImage
, internalFormat
,
2589 width
, height
, border
, format
,
2590 type
, pixels
, unpack
);
2593 ctx
->Driver
.TexImage3D(ctx
, texImage
, internalFormat
,
2594 width
, height
, depth
, border
, format
,
2595 type
, pixels
, unpack
);
2598 _mesa_problem(ctx
, "invalid dims=%u in teximage()", dims
);
2601 check_gen_mipmap(ctx
, target
, texObj
, level
);
2603 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2606 texObj
->_Complete
= GL_FALSE
;
2607 ctx
->NewState
|= _NEW_TEXTURE
;
2610 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage%uD", dims
);
2614 _mesa_unlock_texture(ctx
, texObj
);
2620 * Called from the API. Note that width includes the border.
2623 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
2624 GLsizei width
, GLint border
, GLenum format
,
2625 GLenum type
, const GLvoid
*pixels
)
2627 GET_CURRENT_CONTEXT(ctx
);
2628 teximage(ctx
, 1, target
, level
, internalFormat
, width
, 1, 1,
2629 border
, format
, type
, pixels
);
2634 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
2635 GLsizei width
, GLsizei height
, GLint border
,
2636 GLenum format
, GLenum type
,
2637 const GLvoid
*pixels
)
2639 GET_CURRENT_CONTEXT(ctx
);
2640 teximage(ctx
, 2, target
, level
, internalFormat
, width
, height
, 1,
2641 border
, format
, type
, pixels
);
2646 * Called by the API or display list executor.
2647 * Note that width and height include the border.
2650 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
2651 GLsizei width
, GLsizei height
, GLsizei depth
,
2652 GLint border
, GLenum format
, GLenum type
,
2653 const GLvoid
*pixels
)
2655 GET_CURRENT_CONTEXT(ctx
);
2656 teximage(ctx
, 3, target
, level
, internalFormat
, width
, height
, depth
,
2657 border
, format
, type
, pixels
);
2662 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
2663 GLsizei width
, GLsizei height
, GLsizei depth
,
2664 GLint border
, GLenum format
, GLenum type
,
2665 const GLvoid
*pixels
)
2667 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
2668 depth
, border
, format
, type
, pixels
);
2672 #if FEATURE_OES_EGL_image
2674 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
2676 struct gl_texture_object
*texObj
;
2677 struct gl_texture_image
*texImage
;
2678 GET_CURRENT_CONTEXT(ctx
);
2679 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2681 if ((target
== GL_TEXTURE_2D
&&
2682 !ctx
->Extensions
.OES_EGL_image
) ||
2683 (target
== GL_TEXTURE_EXTERNAL_OES
&&
2684 !ctx
->Extensions
.OES_EGL_image_external
)) {
2685 _mesa_error(ctx
, GL_INVALID_ENUM
,
2686 "glEGLImageTargetTexture2D(target=%d)", target
);
2690 if (ctx
->NewState
& _NEW_PIXEL
)
2691 _mesa_update_state(ctx
);
2693 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2694 _mesa_lock_texture(ctx
, texObj
);
2696 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
2698 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
2700 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2702 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
2703 texObj
, texImage
, image
);
2706 texObj
->_Complete
= GL_FALSE
;
2707 ctx
->NewState
|= _NEW_TEXTURE
;
2709 _mesa_unlock_texture(ctx
, texObj
);
2717 * Implement all the glTexSubImage1/2/3D() functions.
2720 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
2721 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2722 GLsizei width
, GLsizei height
, GLsizei depth
,
2723 GLenum format
, GLenum type
, const GLvoid
*pixels
)
2725 struct gl_texture_object
*texObj
;
2726 struct gl_texture_image
*texImage
;
2728 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2730 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2731 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
2733 _mesa_lookup_enum_by_nr(target
), level
,
2734 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
2735 _mesa_lookup_enum_by_nr(format
),
2736 _mesa_lookup_enum_by_nr(type
), pixels
);
2738 /* check target (proxies not allowed) */
2739 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
2740 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2741 dims
, _mesa_lookup_enum_by_nr(target
));
2745 if (ctx
->NewState
& _NEW_PIXEL
)
2746 _mesa_update_state(ctx
);
2748 if (subtexture_error_check(ctx
, dims
, target
, level
, xoffset
, yoffset
, zoffset
,
2749 width
, height
, depth
, format
, type
)) {
2750 return; /* error was detected */
2753 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2755 _mesa_lock_texture(ctx
, texObj
);
2757 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2759 if (subtexture_error_check2(ctx
, dims
, target
, level
,
2760 xoffset
, yoffset
, zoffset
,
2761 width
, height
, depth
,
2762 format
, type
, texImage
)) {
2763 /* error was recorded */
2765 else if (width
> 0 && height
> 0 && depth
> 0) {
2766 /* If we have a border, offset=-1 is legal. Bias by border width. */
2769 if (target
!= GL_TEXTURE_2D_ARRAY
)
2770 zoffset
+= texImage
->Border
;
2773 if (target
!= GL_TEXTURE_1D_ARRAY
)
2774 yoffset
+= texImage
->Border
;
2777 xoffset
+= texImage
->Border
;
2782 ctx
->Driver
.TexSubImage1D(ctx
, texImage
,
2784 format
, type
, pixels
, &ctx
->Unpack
);
2787 ctx
->Driver
.TexSubImage2D(ctx
, texImage
,
2788 xoffset
, yoffset
, width
, height
,
2789 format
, type
, pixels
, &ctx
->Unpack
);
2792 ctx
->Driver
.TexSubImage3D(ctx
, texImage
,
2793 xoffset
, yoffset
, zoffset
,
2794 width
, height
, depth
,
2795 format
, type
, pixels
, &ctx
->Unpack
);
2798 _mesa_problem(ctx
, "unexpected dims in subteximage()");
2801 check_gen_mipmap(ctx
, target
, texObj
, level
);
2803 ctx
->NewState
|= _NEW_TEXTURE
;
2806 _mesa_unlock_texture(ctx
, texObj
);
2811 _mesa_TexSubImage1D( GLenum target
, GLint level
,
2812 GLint xoffset
, GLsizei width
,
2813 GLenum format
, GLenum type
,
2814 const GLvoid
*pixels
)
2816 GET_CURRENT_CONTEXT(ctx
);
2817 texsubimage(ctx
, 1, target
, level
,
2820 format
, type
, pixels
);
2825 _mesa_TexSubImage2D( GLenum target
, GLint level
,
2826 GLint xoffset
, GLint yoffset
,
2827 GLsizei width
, GLsizei height
,
2828 GLenum format
, GLenum type
,
2829 const GLvoid
*pixels
)
2831 GET_CURRENT_CONTEXT(ctx
);
2832 texsubimage(ctx
, 2, target
, level
,
2833 xoffset
, yoffset
, 0,
2835 format
, type
, pixels
);
2841 _mesa_TexSubImage3D( GLenum target
, GLint level
,
2842 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2843 GLsizei width
, GLsizei height
, GLsizei depth
,
2844 GLenum format
, GLenum type
,
2845 const GLvoid
*pixels
)
2847 GET_CURRENT_CONTEXT(ctx
);
2848 texsubimage(ctx
, 3, target
, level
,
2849 xoffset
, yoffset
, zoffset
,
2850 width
, height
, depth
,
2851 format
, type
, pixels
);
2857 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
2858 * from. This depends on whether the texture contains color or depth values.
2860 static struct gl_renderbuffer
*
2861 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
2863 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
2864 /* reading from depth/stencil buffer */
2865 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
2868 /* copying from color buffer */
2869 return ctx
->ReadBuffer
->_ColorReadBuffer
;
2876 * Implement the glCopyTexImage1/2D() functions.
2879 copyteximage(struct gl_context
*ctx
, GLuint dims
,
2880 GLenum target
, GLint level
, GLenum internalFormat
,
2881 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
2883 struct gl_texture_object
*texObj
;
2884 struct gl_texture_image
*texImage
;
2885 const GLuint face
= _mesa_tex_target_to_face(target
);
2887 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
2889 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
2890 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
2892 _mesa_lookup_enum_by_nr(target
), level
,
2893 _mesa_lookup_enum_by_nr(internalFormat
),
2894 x
, y
, width
, height
, border
);
2896 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
2897 _mesa_update_state(ctx
);
2899 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
2900 width
, height
, border
))
2903 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2905 if (border
&& ctx
->Const
.StripTextureBorder
) {
2907 width
-= border
* 2;
2910 height
-= border
* 2;
2915 _mesa_lock_texture(ctx
, texObj
);
2917 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
2920 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2923 /* choose actual hw format */
2924 gl_format texFormat
= _mesa_choose_texture_format(ctx
, texObj
,
2929 if (legal_texture_size(ctx
, texFormat
, width
, height
, 1)) {
2930 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0;
2932 /* Free old texture image */
2933 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
2935 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
2936 border
, internalFormat
, texFormat
);
2938 /* Allocate texture memory (no pixel data yet) */
2940 ctx
->Driver
.TexImage1D(ctx
, texImage
, internalFormat
,
2941 width
, border
, GL_NONE
, GL_NONE
, NULL
,
2945 ctx
->Driver
.TexImage2D(ctx
, texImage
, internalFormat
,
2946 width
, height
, border
, GL_NONE
, GL_NONE
,
2947 NULL
, &ctx
->Unpack
);
2950 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
2952 struct gl_renderbuffer
*srcRb
=
2953 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
2956 ctx
->Driver
.CopyTexSubImage1D(ctx
, texImage
, dstX
,
2957 srcRb
, srcX
, srcY
, width
);
2960 ctx
->Driver
.CopyTexSubImage2D(ctx
, texImage
, dstX
, dstY
,
2961 srcRb
, srcX
, srcY
, width
, height
);
2964 check_gen_mipmap(ctx
, target
, texObj
, level
);
2966 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
2969 texObj
->_Complete
= GL_FALSE
;
2970 ctx
->NewState
|= _NEW_TEXTURE
;
2973 /* probably too large of image */
2974 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
2978 _mesa_unlock_texture(ctx
, texObj
);
2984 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
2985 GLenum internalFormat
,
2987 GLsizei width
, GLint border
)
2989 GET_CURRENT_CONTEXT(ctx
);
2990 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
2996 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
2997 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3000 GET_CURRENT_CONTEXT(ctx
);
3001 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3002 x
, y
, width
, height
, border
);
3008 * Implementation for glCopyTexSubImage1/2/3D() functions.
3011 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3012 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3013 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3015 struct gl_texture_object
*texObj
;
3016 struct gl_texture_image
*texImage
;
3018 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3020 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3021 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3023 _mesa_lookup_enum_by_nr(target
),
3024 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3026 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3027 _mesa_update_state(ctx
);
3029 if (copytexsubimage_error_check1(ctx
, dims
, target
, level
))
3032 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3034 _mesa_lock_texture(ctx
, texObj
);
3036 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3038 if (copytexsubimage_error_check2(ctx
, dims
, target
, level
, xoffset
, yoffset
,
3039 zoffset
, width
, height
, texImage
)) {
3040 /* error was recored */
3043 /* If we have a border, offset=-1 is legal. Bias by border width. */
3046 if (target
!= GL_TEXTURE_2D_ARRAY
)
3047 zoffset
+= texImage
->Border
;
3050 if (target
!= GL_TEXTURE_1D_ARRAY
)
3051 yoffset
+= texImage
->Border
;
3054 xoffset
+= texImage
->Border
;
3057 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3059 struct gl_renderbuffer
*srcRb
=
3060 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3064 ctx
->Driver
.CopyTexSubImage1D(ctx
, texImage
, xoffset
,
3065 srcRb
, x
, y
, width
);
3068 ctx
->Driver
.CopyTexSubImage2D(ctx
, texImage
, xoffset
, yoffset
,
3069 srcRb
, x
, y
, width
, height
);
3072 ctx
->Driver
.CopyTexSubImage3D(ctx
, texImage
,
3073 xoffset
, yoffset
, zoffset
,
3074 srcRb
, x
, y
, width
, height
);
3077 _mesa_problem(ctx
, "bad dims in copytexsubimage()");
3080 check_gen_mipmap(ctx
, target
, texObj
, level
);
3082 ctx
->NewState
|= _NEW_TEXTURE
;
3086 _mesa_unlock_texture(ctx
, texObj
);
3091 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3092 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3094 GET_CURRENT_CONTEXT(ctx
);
3095 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3101 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3102 GLint xoffset
, GLint yoffset
,
3103 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3105 GET_CURRENT_CONTEXT(ctx
);
3106 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3113 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3114 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3115 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3117 GET_CURRENT_CONTEXT(ctx
);
3118 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3119 x
, y
, width
, height
);
3125 /**********************************************************************/
3126 /****** Compressed Textures ******/
3127 /**********************************************************************/
3131 * Return expected size of a compressed texture.
3134 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
3137 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3138 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
3143 * Return compressed texture block size, in pixels.
3146 get_compressed_block_size(GLenum glformat
, GLuint
*bw
, GLuint
*bh
)
3148 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
3149 _mesa_get_format_block_size(mesaFormat
, bw
, bh
);
3154 * Error checking for glCompressedTexImage[123]D().
3155 * \param reason returns reason for error, if any
3156 * \return error code or GL_NO_ERROR.
3159 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3160 GLenum target
, GLint level
,
3161 GLenum internalFormat
, GLsizei width
,
3162 GLsizei height
, GLsizei depth
, GLint border
,
3163 GLsizei imageSize
, char **reason
)
3165 const GLenum proxyTarget
= get_proxy_target(target
);
3166 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
3168 GLenum choose_format
;
3170 GLenum proxy_format
;
3172 *reason
= ""; /* no error */
3174 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
3176 return GL_INVALID_ENUM
;
3179 /* This will detect any invalid internalFormat value */
3180 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
3181 *reason
= "internalFormat";
3182 return GL_INVALID_ENUM
;
3185 switch (internalFormat
) {
3187 case GL_PALETTE4_RGB8_OES
:
3188 case GL_PALETTE4_RGBA8_OES
:
3189 case GL_PALETTE4_R5_G6_B5_OES
:
3190 case GL_PALETTE4_RGBA4_OES
:
3191 case GL_PALETTE4_RGB5_A1_OES
:
3192 case GL_PALETTE8_RGB8_OES
:
3193 case GL_PALETTE8_RGBA8_OES
:
3194 case GL_PALETTE8_R5_G6_B5_OES
:
3195 case GL_PALETTE8_RGBA4_OES
:
3196 case GL_PALETTE8_RGB5_A1_OES
:
3197 _mesa_cpal_compressed_format_type(internalFormat
, &choose_format
,
3199 proxy_format
= choose_format
;
3202 if (level
> 0 || level
< -maxLevels
) {
3204 return GL_INVALID_VALUE
;
3207 if (dimensions
!= 2) {
3208 *reason
= "compressed paletted textures must be 2D";
3209 return GL_INVALID_OPERATION
;
3212 /* Figure out the expected texture size (in bytes). This will be
3213 * checked against the actual size later.
3215 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
3218 /* This is for the benefit of the TestProxyTexImage below. It expects
3219 * level to be non-negative. OES_compressed_paletted_texture uses a
3220 * weird mechanism where the level specified to glCompressedTexImage2D
3221 * is -(n-1) number of levels in the texture, and the data specifies the
3222 * complete mipmap stack. This is done to ensure the palette is the
3223 * same for all levels.
3230 choose_format
= GL_NONE
;
3231 choose_type
= GL_NONE
;
3232 proxy_format
= internalFormat
;
3235 if (level
< 0 || level
>= maxLevels
) {
3237 return GL_INVALID_VALUE
;
3240 /* Figure out the expected texture size (in bytes). This will be
3241 * checked against the actual size later.
3243 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
3247 /* This should really never fail */
3248 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
3249 *reason
= "internalFormat";
3250 return GL_INVALID_ENUM
;
3253 /* No compressed formats support borders at this time */
3255 *reason
= "border != 0";
3256 return GL_INVALID_VALUE
;
3259 /* For cube map, width must equal height */
3260 if (_mesa_is_cube_face(target
) && width
!= height
) {
3261 *reason
= "width != height";
3262 return GL_INVALID_VALUE
;
3265 /* check image size against compression block size */
3267 gl_format texFormat
=
3268 ctx
->Driver
.ChooseTextureFormat(ctx
, proxy_format
,
3269 choose_format
, choose_type
);
3272 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
3273 if ((width
> bw
&& width
% bw
> 0) ||
3274 (height
> bh
&& height
% bh
> 0)) {
3276 * Per GL_ARB_texture_compression: GL_INVALID_OPERATION is
3277 * generated [...] if any parameter combinations are not
3278 * supported by the specific compressed internal format.
3280 *reason
= "invalid width or height for compression format";
3281 return GL_INVALID_OPERATION
;
3285 /* check image sizes */
3286 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxyTarget
, level
,
3287 proxy_format
, choose_format
,
3289 width
, height
, depth
, border
)) {
3290 /* See error comment above */
3291 *reason
= "invalid width, height or format";
3292 return GL_INVALID_OPERATION
;
3295 /* check image size in bytes */
3296 if (expectedSize
!= imageSize
) {
3297 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
3298 * if <imageSize> is not consistent with the format, dimensions, and
3299 * contents of the specified image.
3301 *reason
= "imageSize inconsistant with width/height/format";
3302 return GL_INVALID_VALUE
;
3305 if (!mutable_tex_object(ctx
, target
)) {
3306 *reason
= "immutable texture";
3307 return GL_INVALID_OPERATION
;
3315 * Error checking for glCompressedTexSubImage[123]D().
3316 * \warning There are some bad assumptions here about the size of compressed
3317 * texture tiles (multiple of 4) used to test the validity of the
3318 * offset and size parameters.
3319 * \return error code or GL_NO_ERROR.
3322 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dimensions
,
3323 GLenum target
, GLint level
,
3324 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3325 GLsizei width
, GLsizei height
, GLsizei depth
,
3326 GLenum format
, GLsizei imageSize
)
3328 GLint expectedSize
, maxLevels
= 0, maxTextureSize
;
3332 if (dimensions
== 1) {
3333 /* 1D compressed textures not allowed */
3334 return GL_INVALID_ENUM
;
3336 else if (dimensions
== 2) {
3337 if (target
== GL_PROXY_TEXTURE_2D
) {
3338 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3340 else if (target
== GL_TEXTURE_2D
) {
3341 maxLevels
= ctx
->Const
.MaxTextureLevels
;
3343 else if (target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
) {
3344 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3345 return GL_INVALID_ENUM
; /*target*/
3346 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3348 else if (_mesa_is_cube_face(target
)) {
3349 if (!ctx
->Extensions
.ARB_texture_cube_map
)
3350 return GL_INVALID_ENUM
; /*target*/
3351 maxLevels
= ctx
->Const
.MaxCubeTextureLevels
;
3354 return GL_INVALID_ENUM
; /*target*/
3357 else if (dimensions
== 3) {
3358 /* 3D compressed textures not allowed */
3359 return GL_INVALID_ENUM
;
3362 maxTextureSize
= 1 << (maxLevels
- 1);
3364 /* this will catch any invalid compressed format token */
3365 if (!_mesa_is_compressed_format(ctx
, format
))
3366 return GL_INVALID_ENUM
;
3368 if (width
< 1 || width
> maxTextureSize
)
3369 return GL_INVALID_VALUE
;
3371 if ((height
< 1 || height
> maxTextureSize
)
3373 return GL_INVALID_VALUE
;
3375 if (level
< 0 || level
>= maxLevels
)
3376 return GL_INVALID_VALUE
;
3379 * do checks which depend on compression block size
3381 get_compressed_block_size(format
, &bw
, &bh
);
3383 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0))
3384 return GL_INVALID_VALUE
;
3386 if ((width
% bw
!= 0) && width
!= 2 && width
!= 1)
3387 return GL_INVALID_VALUE
;
3389 if ((height
% bh
!= 0) && height
!= 2 && height
!= 1)
3390 return GL_INVALID_VALUE
;
3392 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3393 if (expectedSize
!= imageSize
)
3394 return GL_INVALID_VALUE
;
3401 * Do second part of glCompressedTexSubImage error checking.
3402 * \return GL_TRUE if error found, GL_FALSE otherwise.
3405 compressed_subtexture_error_check2(struct gl_context
*ctx
, GLuint dims
,
3406 GLsizei width
, GLsizei height
,
3407 GLsizei depth
, GLenum format
,
3408 struct gl_texture_image
*texImage
)
3411 if ((GLint
) format
!= texImage
->InternalFormat
) {
3412 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3413 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3417 if (compressedteximage_only_format(ctx
, format
)) {
3418 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3419 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3424 if (((width
== 1 || width
== 2) &&
3425 width
!= (GLsizei
) texImage
->Width
) ||
3426 (width
> (GLsizei
) texImage
->Width
)) {
3427 _mesa_error(ctx
, GL_INVALID_VALUE
,
3428 "glCompressedTexSubImage%uD(width=%d)", dims
, width
);
3433 if (((height
== 1 || height
== 2) &&
3434 height
!= (GLsizei
) texImage
->Height
) ||
3435 (height
> (GLsizei
) texImage
->Height
)) {
3436 _mesa_error(ctx
, GL_INVALID_VALUE
,
3437 "glCompressedTexSubImage%uD(height=%d)", dims
, height
);
3443 if (((depth
== 1 || depth
== 2) &&
3444 depth
!= (GLsizei
) texImage
->Depth
) ||
3445 (depth
> (GLsizei
) texImage
->Depth
)) {
3446 _mesa_error(ctx
, GL_INVALID_VALUE
,
3447 "glCompressedTexSubImage%uD(depth=%d)", dims
, depth
);
3457 * Implementation of the glCompressedTexImage1/2/3D() functions.
3460 compressedteximage(struct gl_context
*ctx
, GLuint dims
,
3461 GLenum target
, GLint level
,
3462 GLenum internalFormat
, GLsizei width
,
3463 GLsizei height
, GLsizei depth
, GLint border
,
3464 GLsizei imageSize
, const GLvoid
*data
)
3469 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3471 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3473 "glCompressedTexImage%uDARB %s %d %s %d %d %d %d %d %p\n",
3475 _mesa_lookup_enum_by_nr(target
), level
,
3476 _mesa_lookup_enum_by_nr(internalFormat
),
3477 width
, height
, depth
, border
, imageSize
, data
);
3480 if (!legal_teximage_target(ctx
, dims
, target
)) {
3481 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target=%s)",
3482 dims
, _mesa_lookup_enum_by_nr(target
));
3486 error
= compressed_texture_error_check(ctx
, dims
, target
, level
,
3487 internalFormat
, width
, height
, depth
,
3488 border
, imageSize
, &reason
);
3491 /* XXX this is kind of a hack */
3492 if (!error
&& dims
== 2) {
3493 switch (internalFormat
) {
3494 case GL_PALETTE4_RGB8_OES
:
3495 case GL_PALETTE4_RGBA8_OES
:
3496 case GL_PALETTE4_R5_G6_B5_OES
:
3497 case GL_PALETTE4_RGBA4_OES
:
3498 case GL_PALETTE4_RGB5_A1_OES
:
3499 case GL_PALETTE8_RGB8_OES
:
3500 case GL_PALETTE8_RGBA8_OES
:
3501 case GL_PALETTE8_R5_G6_B5_OES
:
3502 case GL_PALETTE8_RGBA4_OES
:
3503 case GL_PALETTE8_RGB5_A1_OES
:
3504 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3505 width
, height
, imageSize
, data
);
3511 if (_mesa_is_proxy_texture(target
)) {
3512 /* Proxy texture: just check for errors and update proxy state */
3513 struct gl_texture_image
*texImage
;
3516 struct gl_texture_object
*texObj
=
3517 _mesa_get_current_tex_object(ctx
, target
);
3518 gl_format texFormat
=
3519 _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3520 internalFormat
, GL_NONE
, GL_NONE
);
3521 if (!legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3522 error
= GL_OUT_OF_MEMORY
;
3526 texImage
= _mesa_get_proxy_tex_image(ctx
, target
, level
);
3529 /* if error, clear all proxy texture image parameters */
3530 clear_teximage_fields(texImage
);
3533 /* no error: store the teximage parameters */
3534 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
,
3535 depth
, border
, internalFormat
,
3541 /* non-proxy target */
3542 struct gl_texture_object
*texObj
;
3543 struct gl_texture_image
*texImage
;
3546 _mesa_error(ctx
, error
, "glCompressedTexImage%uD(%s)", dims
, reason
);
3550 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3552 _mesa_lock_texture(ctx
, texObj
);
3554 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3556 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3557 "glCompressedTexImage%uD", dims
);
3560 gl_format texFormat
;
3562 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3564 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3565 internalFormat
, GL_NONE
,
3568 if (legal_texture_size(ctx
, texFormat
, width
, height
, depth
)) {
3569 _mesa_init_teximage_fields(ctx
, texImage
,
3570 width
, height
, depth
,
3571 border
, internalFormat
, texFormat
);
3575 ASSERT(ctx
->Driver
.CompressedTexImage1D
);
3576 ctx
->Driver
.CompressedTexImage1D(ctx
, texImage
,
3579 border
, imageSize
, data
);
3582 ASSERT(ctx
->Driver
.CompressedTexImage2D
);
3583 ctx
->Driver
.CompressedTexImage2D(ctx
, texImage
,
3586 border
, imageSize
, data
);
3589 ASSERT(ctx
->Driver
.CompressedTexImage3D
);
3590 ctx
->Driver
.CompressedTexImage3D(ctx
, texImage
,
3592 width
, height
, depth
,
3593 border
, imageSize
, data
);
3596 _mesa_problem(ctx
, "bad dims in compressedteximage");
3599 check_gen_mipmap(ctx
, target
, texObj
, level
);
3602 texObj
->_Complete
= GL_FALSE
;
3603 ctx
->NewState
|= _NEW_TEXTURE
;
3606 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3607 "glCompressedTexImage%uD", dims
);
3611 _mesa_unlock_texture(ctx
, texObj
);
3617 _mesa_CompressedTexImage1DARB(GLenum target
, GLint level
,
3618 GLenum internalFormat
, GLsizei width
,
3619 GLint border
, GLsizei imageSize
,
3622 GET_CURRENT_CONTEXT(ctx
);
3623 compressedteximage(ctx
, 1, target
, level
, internalFormat
,
3624 width
, 1, 1, border
, imageSize
, data
);
3629 _mesa_CompressedTexImage2DARB(GLenum target
, GLint level
,
3630 GLenum internalFormat
, GLsizei width
,
3631 GLsizei height
, GLint border
, GLsizei imageSize
,
3634 GET_CURRENT_CONTEXT(ctx
);
3635 compressedteximage(ctx
, 2, target
, level
, internalFormat
,
3636 width
, height
, 1, border
, imageSize
, data
);
3641 _mesa_CompressedTexImage3DARB(GLenum target
, GLint level
,
3642 GLenum internalFormat
, GLsizei width
,
3643 GLsizei height
, GLsizei depth
, GLint border
,
3644 GLsizei imageSize
, const GLvoid
*data
)
3646 GET_CURRENT_CONTEXT(ctx
);
3647 compressedteximage(ctx
, 3, target
, level
, internalFormat
,
3648 width
, height
, depth
, border
, imageSize
, data
);
3653 * Common helper for glCompressedTexSubImage1/2/3D().
3656 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3657 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3658 GLsizei width
, GLsizei height
, GLsizei depth
,
3659 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3661 struct gl_texture_object
*texObj
;
3662 struct gl_texture_image
*texImage
;
3664 GET_CURRENT_CONTEXT(ctx
);
3665 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3667 error
= compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3668 xoffset
, 0, 0, /* pos */
3669 width
, height
, depth
, /* size */
3672 _mesa_error(ctx
, error
, "glCompressedTexSubImage%uD", dims
);
3676 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3678 _mesa_lock_texture(ctx
, texObj
);
3680 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3683 if (compressed_subtexture_error_check2(ctx
, dims
, width
, height
, depth
,
3684 format
, texImage
)) {
3685 /* error was recorded */
3687 else if (width
> 0 && height
> 0 && depth
> 0) {
3690 if (ctx
->Driver
.CompressedTexSubImage1D
) {
3691 ctx
->Driver
.CompressedTexSubImage1D(ctx
, texImage
,
3693 format
, imageSize
, data
);
3697 if (ctx
->Driver
.CompressedTexSubImage2D
) {
3698 ctx
->Driver
.CompressedTexSubImage2D(ctx
, texImage
,
3701 format
, imageSize
, data
);
3705 if (ctx
->Driver
.CompressedTexSubImage3D
) {
3706 ctx
->Driver
.CompressedTexSubImage3D(ctx
, texImage
,
3707 xoffset
, yoffset
, zoffset
,
3708 width
, height
, depth
,
3709 format
, imageSize
, data
);
3716 check_gen_mipmap(ctx
, target
, texObj
, level
);
3718 ctx
->NewState
|= _NEW_TEXTURE
;
3721 _mesa_unlock_texture(ctx
, texObj
);
3726 _mesa_CompressedTexSubImage1DARB(GLenum target
, GLint level
, GLint xoffset
,
3727 GLsizei width
, GLenum format
,
3728 GLsizei imageSize
, const GLvoid
*data
)
3730 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3731 format
, imageSize
, data
);
3736 _mesa_CompressedTexSubImage2DARB(GLenum target
, GLint level
, GLint xoffset
,
3737 GLint yoffset
, GLsizei width
, GLsizei height
,
3738 GLenum format
, GLsizei imageSize
,
3741 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3742 width
, height
, 1, format
, imageSize
, data
);
3747 _mesa_CompressedTexSubImage3DARB(GLenum target
, GLint level
, GLint xoffset
,
3748 GLint yoffset
, GLint zoffset
, GLsizei width
,
3749 GLsizei height
, GLsizei depth
, GLenum format
,
3750 GLsizei imageSize
, const GLvoid
*data
)
3752 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3753 width
, height
, depth
, format
, imageSize
, data
);
3758 * Helper for glTexBuffer(). Check if internalFormat is legal. If so,
3759 * return the basic data type and number of components for the format.
3760 * \param return GL_TRUE if internalFormat is legal, GL_FALSE otherwise
3763 get_sized_format_info(const struct gl_context
*ctx
, GLenum internalFormat
,
3764 GLenum
*datatype
, GLuint
*components
)
3766 switch (internalFormat
) {
3768 *datatype
= GL_UNSIGNED_BYTE
;
3772 *datatype
= GL_UNSIGNED_SHORT
;
3775 case GL_ALPHA16F_ARB
:
3776 *datatype
= GL_HALF_FLOAT
;
3779 case GL_ALPHA32F_ARB
:
3780 *datatype
= GL_FLOAT
;
3783 case GL_ALPHA8I_EXT
:
3784 *datatype
= GL_BYTE
;
3787 case GL_ALPHA16I_EXT
:
3788 *datatype
= GL_SHORT
;
3791 case GL_ALPHA32I_EXT
:
3795 case GL_ALPHA8UI_EXT
:
3796 *datatype
= GL_UNSIGNED_BYTE
;
3799 case GL_ALPHA16UI_EXT
:
3800 *datatype
= GL_UNSIGNED_SHORT
;
3803 case GL_ALPHA32UI_EXT
:
3804 *datatype
= GL_UNSIGNED_INT
;
3808 *datatype
= GL_UNSIGNED_BYTE
;
3811 case GL_LUMINANCE16
:
3812 *datatype
= GL_UNSIGNED_SHORT
;
3815 case GL_LUMINANCE16F_ARB
:
3816 *datatype
= GL_HALF_FLOAT
;
3819 case GL_LUMINANCE32F_ARB
:
3820 *datatype
= GL_FLOAT
;
3823 case GL_LUMINANCE8I_EXT
:
3824 *datatype
= GL_BYTE
;
3827 case GL_LUMINANCE16I_EXT
:
3828 *datatype
= GL_SHORT
;
3831 case GL_LUMINANCE32I_EXT
:
3835 case GL_LUMINANCE8UI_EXT
:
3836 *datatype
= GL_UNSIGNED_BYTE
;
3839 case GL_LUMINANCE16UI_EXT
:
3840 *datatype
= GL_UNSIGNED_SHORT
;
3843 case GL_LUMINANCE32UI_EXT
:
3844 *datatype
= GL_UNSIGNED_INT
;
3847 case GL_LUMINANCE8_ALPHA8
:
3848 *datatype
= GL_UNSIGNED_BYTE
;
3851 case GL_LUMINANCE16_ALPHA16
:
3852 *datatype
= GL_UNSIGNED_SHORT
;
3855 case GL_LUMINANCE_ALPHA16F_ARB
:
3856 *datatype
= GL_HALF_FLOAT
;
3859 case GL_LUMINANCE_ALPHA32F_ARB
:
3860 *datatype
= GL_FLOAT
;
3863 case GL_LUMINANCE_ALPHA8I_EXT
:
3864 *datatype
= GL_BYTE
;
3867 case GL_LUMINANCE_ALPHA16I_EXT
:
3868 *datatype
= GL_SHORT
;
3871 case GL_LUMINANCE_ALPHA32I_EXT
:
3875 case GL_LUMINANCE_ALPHA8UI_EXT
:
3876 *datatype
= GL_UNSIGNED_BYTE
;
3879 case GL_LUMINANCE_ALPHA16UI_EXT
:
3880 *datatype
= GL_UNSIGNED_SHORT
;
3883 case GL_LUMINANCE_ALPHA32UI_EXT
:
3884 *datatype
= GL_UNSIGNED_INT
;
3888 *datatype
= GL_UNSIGNED_BYTE
;
3891 case GL_INTENSITY16
:
3892 *datatype
= GL_UNSIGNED_SHORT
;
3895 case GL_INTENSITY16F_ARB
:
3896 *datatype
= GL_HALF_FLOAT
;
3899 case GL_INTENSITY32F_ARB
:
3900 *datatype
= GL_FLOAT
;
3903 case GL_INTENSITY8I_EXT
:
3904 *datatype
= GL_BYTE
;
3907 case GL_INTENSITY16I_EXT
:
3908 *datatype
= GL_SHORT
;
3911 case GL_INTENSITY32I_EXT
:
3915 case GL_INTENSITY8UI_EXT
:
3916 *datatype
= GL_UNSIGNED_BYTE
;
3919 case GL_INTENSITY16UI_EXT
:
3920 *datatype
= GL_UNSIGNED_SHORT
;
3923 case GL_INTENSITY32UI_EXT
:
3924 *datatype
= GL_UNSIGNED_INT
;
3928 *datatype
= GL_UNSIGNED_BYTE
;
3932 *datatype
= GL_UNSIGNED_SHORT
;
3935 case GL_RGBA16F_ARB
:
3936 *datatype
= GL_HALF_FLOAT
;
3939 case GL_RGBA32F_ARB
:
3940 *datatype
= GL_FLOAT
;
3944 *datatype
= GL_BYTE
;
3947 case GL_RGBA16I_EXT
:
3948 *datatype
= GL_SHORT
;
3951 case GL_RGBA32I_EXT
:
3955 case GL_RGBA8UI_EXT
:
3956 *datatype
= GL_UNSIGNED_BYTE
;
3959 case GL_RGBA16UI_EXT
:
3960 *datatype
= GL_UNSIGNED_SHORT
;
3963 case GL_RGBA32UI_EXT
:
3964 *datatype
= GL_UNSIGNED_INT
;
3971 if (*datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
3974 if (*datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
3981 /** GL_ARB_texture_buffer_object */
3983 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
3985 struct gl_texture_object
*texObj
;
3986 struct gl_buffer_object
*bufObj
;
3990 GET_CURRENT_CONTEXT(ctx
);
3991 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
3993 if (!ctx
->Extensions
.ARB_texture_buffer_object
) {
3994 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
3998 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
3999 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4003 if (!get_sized_format_info(ctx
, internalFormat
, &dataType
, &comps
)) {
4004 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4009 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4010 if (buffer
&& !bufObj
) {
4011 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4015 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4017 _mesa_lock_texture(ctx
, texObj
);
4019 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4020 texObj
->BufferObjectFormat
= internalFormat
;
4022 _mesa_unlock_texture(ctx
, texObj
);