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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
43 #include "multisample.h"
45 #include "texcompress.h"
46 #include "texcompress_cpal.h"
50 #include "texstorage.h"
52 #include "glformats.h"
56 * State changes which we care about for glCopyTex[Sub]Image() calls.
57 * In particular, we care about pixel transfer state and buffer state
58 * (such as glReadBuffer to make sure we read from the right renderbuffer).
60 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
65 * Return the simple base format for a given internal texture format.
66 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
68 * \param ctx GL context.
69 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
71 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
72 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
74 * This is the format which is used during texture application (i.e. the
75 * texture format and env mode determine the arithmetic used.
78 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
80 switch (internalFormat
) {
86 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
93 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
95 case GL_LUMINANCE_ALPHA
:
96 case GL_LUMINANCE4_ALPHA4
:
97 case GL_LUMINANCE6_ALPHA2
:
98 case GL_LUMINANCE8_ALPHA8
:
99 case GL_LUMINANCE12_ALPHA4
:
100 case GL_LUMINANCE12_ALPHA12
:
101 case GL_LUMINANCE16_ALPHA16
:
102 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
108 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
110 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
121 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
135 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
137 if (_mesa_is_gles(ctx
)) {
138 switch (internalFormat
) {
146 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
147 switch (internalFormat
) {
155 if (ctx
->Extensions
.ARB_depth_texture
) {
156 switch (internalFormat
) {
157 case GL_DEPTH_COMPONENT
:
158 case GL_DEPTH_COMPONENT16
:
159 case GL_DEPTH_COMPONENT24
:
160 case GL_DEPTH_COMPONENT32
:
161 return GL_DEPTH_COMPONENT
;
167 switch (internalFormat
) {
168 case GL_COMPRESSED_ALPHA
:
170 case GL_COMPRESSED_LUMINANCE
:
172 case GL_COMPRESSED_LUMINANCE_ALPHA
:
173 return GL_LUMINANCE_ALPHA
;
174 case GL_COMPRESSED_INTENSITY
:
176 case GL_COMPRESSED_RGB
:
178 case GL_COMPRESSED_RGBA
:
184 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
185 switch (internalFormat
) {
186 case GL_COMPRESSED_RGB_FXT1_3DFX
:
188 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
195 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
197 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
198 switch (internalFormat
) {
199 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
201 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
202 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
203 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
210 if (_mesa_is_desktop_gl(ctx
)
211 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
212 switch (internalFormat
) {
224 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
225 if (internalFormat
== GL_YCBCR_MESA
)
226 return GL_YCBCR_MESA
;
229 if (ctx
->Extensions
.ARB_texture_float
) {
230 switch (internalFormat
) {
231 case GL_ALPHA16F_ARB
:
232 case GL_ALPHA32F_ARB
:
240 case GL_INTENSITY16F_ARB
:
241 case GL_INTENSITY32F_ARB
:
243 case GL_LUMINANCE16F_ARB
:
244 case GL_LUMINANCE32F_ARB
:
246 case GL_LUMINANCE_ALPHA16F_ARB
:
247 case GL_LUMINANCE_ALPHA32F_ARB
:
248 return GL_LUMINANCE_ALPHA
;
254 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
255 switch (internalFormat
) {
264 if (ctx
->Extensions
.EXT_texture_snorm
) {
265 switch (internalFormat
) {
280 case GL_RGBA16_SNORM
:
283 case GL_ALPHA8_SNORM
:
284 case GL_ALPHA16_SNORM
:
286 case GL_LUMINANCE_SNORM
:
287 case GL_LUMINANCE8_SNORM
:
288 case GL_LUMINANCE16_SNORM
:
290 case GL_LUMINANCE_ALPHA_SNORM
:
291 case GL_LUMINANCE8_ALPHA8_SNORM
:
292 case GL_LUMINANCE16_ALPHA16_SNORM
:
293 return GL_LUMINANCE_ALPHA
;
294 case GL_INTENSITY_SNORM
:
295 case GL_INTENSITY8_SNORM
:
296 case GL_INTENSITY16_SNORM
:
303 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
304 switch (internalFormat
) {
305 case GL_DEPTH_STENCIL_EXT
:
306 case GL_DEPTH24_STENCIL8_EXT
:
307 return GL_DEPTH_STENCIL_EXT
;
313 if (ctx
->Extensions
.EXT_texture_sRGB
) {
314 switch (internalFormat
) {
317 case GL_COMPRESSED_SRGB_EXT
:
319 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
320 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
321 case GL_SRGB_ALPHA_EXT
:
322 case GL_SRGB8_ALPHA8_EXT
:
323 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
325 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
326 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
327 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
328 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
329 case GL_SLUMINANCE_ALPHA_EXT
:
330 case GL_SLUMINANCE8_ALPHA8_EXT
:
331 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
332 return GL_LUMINANCE_ALPHA
;
333 case GL_SLUMINANCE_EXT
:
334 case GL_SLUMINANCE8_EXT
:
335 case GL_COMPRESSED_SLUMINANCE_EXT
:
342 if (ctx
->Version
>= 30 ||
343 ctx
->Extensions
.EXT_texture_integer
) {
344 switch (internalFormat
) {
346 case GL_RGBA16UI_EXT
:
347 case GL_RGBA32UI_EXT
:
363 if (ctx
->Extensions
.EXT_texture_integer
) {
364 switch (internalFormat
) {
365 case GL_ALPHA8UI_EXT
:
366 case GL_ALPHA16UI_EXT
:
367 case GL_ALPHA32UI_EXT
:
369 case GL_ALPHA16I_EXT
:
370 case GL_ALPHA32I_EXT
:
372 case GL_INTENSITY8UI_EXT
:
373 case GL_INTENSITY16UI_EXT
:
374 case GL_INTENSITY32UI_EXT
:
375 case GL_INTENSITY8I_EXT
:
376 case GL_INTENSITY16I_EXT
:
377 case GL_INTENSITY32I_EXT
:
379 case GL_LUMINANCE8UI_EXT
:
380 case GL_LUMINANCE16UI_EXT
:
381 case GL_LUMINANCE32UI_EXT
:
382 case GL_LUMINANCE8I_EXT
:
383 case GL_LUMINANCE16I_EXT
:
384 case GL_LUMINANCE32I_EXT
:
386 case GL_LUMINANCE_ALPHA8UI_EXT
:
387 case GL_LUMINANCE_ALPHA16UI_EXT
:
388 case GL_LUMINANCE_ALPHA32UI_EXT
:
389 case GL_LUMINANCE_ALPHA8I_EXT
:
390 case GL_LUMINANCE_ALPHA16I_EXT
:
391 case GL_LUMINANCE_ALPHA32I_EXT
:
392 return GL_LUMINANCE_ALPHA
;
398 if (ctx
->Extensions
.ARB_texture_rg
) {
399 switch (internalFormat
) {
401 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
403 if (!ctx
->Extensions
.ARB_half_float_pixel
)
407 if (!ctx
->Extensions
.ARB_texture_float
)
416 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
422 case GL_COMPRESSED_RED
:
426 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
428 if (!ctx
->Extensions
.ARB_half_float_pixel
)
432 if (!ctx
->Extensions
.ARB_texture_float
)
441 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
447 case GL_COMPRESSED_RG
:
454 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
455 switch (internalFormat
) {
463 if (ctx
->Extensions
.EXT_packed_float
) {
464 switch (internalFormat
) {
465 case GL_R11F_G11F_B10F_EXT
:
472 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
473 switch (internalFormat
) {
474 case GL_DEPTH_COMPONENT32F
:
475 return GL_DEPTH_COMPONENT
;
476 case GL_DEPTH32F_STENCIL8
:
477 return GL_DEPTH_STENCIL
;
483 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
484 switch (internalFormat
) {
485 case GL_COMPRESSED_RED_RGTC1
:
486 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
488 case GL_COMPRESSED_RG_RGTC2
:
489 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
496 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
497 switch (internalFormat
) {
498 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
499 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
501 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
502 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
503 return GL_LUMINANCE_ALPHA
;
509 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
510 switch (internalFormat
) {
511 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
512 return GL_LUMINANCE_ALPHA
;
518 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
519 switch (internalFormat
) {
520 case GL_ETC1_RGB8_OES
:
527 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
528 switch (internalFormat
) {
529 case GL_COMPRESSED_RGB8_ETC2
:
530 case GL_COMPRESSED_SRGB8_ETC2
:
532 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
533 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
534 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
535 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
537 case GL_COMPRESSED_R11_EAC
:
538 case GL_COMPRESSED_SIGNED_R11_EAC
:
540 case GL_COMPRESSED_RG11_EAC
:
541 case GL_COMPRESSED_SIGNED_RG11_EAC
:
548 if (ctx
->API
== API_OPENGLES
) {
549 switch (internalFormat
) {
550 case GL_PALETTE4_RGB8_OES
:
551 case GL_PALETTE4_R5_G6_B5_OES
:
552 case GL_PALETTE8_RGB8_OES
:
553 case GL_PALETTE8_R5_G6_B5_OES
:
555 case GL_PALETTE4_RGBA8_OES
:
556 case GL_PALETTE8_RGB5_A1_OES
:
557 case GL_PALETTE4_RGBA4_OES
:
558 case GL_PALETTE4_RGB5_A1_OES
:
559 case GL_PALETTE8_RGBA8_OES
:
560 case GL_PALETTE8_RGBA4_OES
:
567 return -1; /* error */
572 * For cube map faces, return a face index in [0,5].
573 * For other targets return 0;
576 _mesa_tex_target_to_face(GLenum target
)
578 if (_mesa_is_cube_face(target
))
579 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
587 * Install gl_texture_image in a gl_texture_object according to the target
588 * and level parameters.
590 * \param tObj texture object.
591 * \param target texture target.
592 * \param level image level.
593 * \param texImage texture image.
596 set_tex_image(struct gl_texture_object
*tObj
,
597 GLenum target
, GLint level
,
598 struct gl_texture_image
*texImage
)
600 const GLuint face
= _mesa_tex_target_to_face(target
);
604 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
607 tObj
->Image
[face
][level
] = texImage
;
609 /* Set the 'back' pointer */
610 texImage
->TexObject
= tObj
;
611 texImage
->Level
= level
;
612 texImage
->Face
= face
;
617 * Allocate a texture image structure.
619 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
622 * \return a pointer to gl_texture_image struct with all fields initialized to
625 struct gl_texture_image
*
626 _mesa_new_texture_image( struct gl_context
*ctx
)
629 return CALLOC_STRUCT(gl_texture_image
);
634 * Free a gl_texture_image and associated data.
635 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
637 * \param texImage texture image.
639 * Free the texture image structure and the associated image data.
642 _mesa_delete_texture_image(struct gl_context
*ctx
,
643 struct gl_texture_image
*texImage
)
645 /* Free texImage->Data and/or any other driver-specific texture
648 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
649 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
655 * Test if a target is a proxy target.
657 * \param target texture target.
659 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
662 _mesa_is_proxy_texture(GLenum target
)
665 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
666 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
668 assert(NUM_TEXTURE_TARGETS
== 10 + 2);
670 return (target
== GL_PROXY_TEXTURE_1D
||
671 target
== GL_PROXY_TEXTURE_2D
||
672 target
== GL_PROXY_TEXTURE_3D
||
673 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
674 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
675 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
676 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
677 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
678 target
== GL_PROXY_TEXTURE_2D_MULTISAMPLE
||
679 target
== GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
);
684 * Return the proxy target which corresponds to the given texture target
687 _mesa_get_proxy_target(GLenum target
)
691 case GL_PROXY_TEXTURE_1D
:
692 return GL_PROXY_TEXTURE_1D
;
694 case GL_PROXY_TEXTURE_2D
:
695 return GL_PROXY_TEXTURE_2D
;
697 case GL_PROXY_TEXTURE_3D
:
698 return GL_PROXY_TEXTURE_3D
;
699 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
700 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
701 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
702 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
703 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
704 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
705 case GL_TEXTURE_CUBE_MAP_ARB
:
706 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
707 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
708 case GL_TEXTURE_RECTANGLE_NV
:
709 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
710 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
711 case GL_TEXTURE_1D_ARRAY_EXT
:
712 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
713 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
714 case GL_TEXTURE_2D_ARRAY_EXT
:
715 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
716 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
717 case GL_TEXTURE_CUBE_MAP_ARRAY
:
718 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
719 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
720 case GL_TEXTURE_2D_MULTISAMPLE
:
721 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
722 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
723 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
724 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
725 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
727 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
734 * Get the texture object that corresponds to the target of the given
735 * texture unit. The target should have already been checked for validity.
737 * \param ctx GL context.
738 * \param texUnit texture unit.
739 * \param target texture target.
741 * \return pointer to the texture object on success, or NULL on failure.
743 struct gl_texture_object
*
744 _mesa_select_tex_object(struct gl_context
*ctx
,
745 const struct gl_texture_unit
*texUnit
,
748 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
749 ctx
->Extensions
.EXT_texture_array
);
753 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
754 case GL_PROXY_TEXTURE_1D
:
755 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
757 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
758 case GL_PROXY_TEXTURE_2D
:
759 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
761 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
762 case GL_PROXY_TEXTURE_3D
:
763 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
764 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
765 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
766 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
767 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
768 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
769 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
770 case GL_TEXTURE_CUBE_MAP_ARB
:
771 return ctx
->Extensions
.ARB_texture_cube_map
772 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
773 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
774 return ctx
->Extensions
.ARB_texture_cube_map
775 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
776 case GL_TEXTURE_CUBE_MAP_ARRAY
:
777 return ctx
->Extensions
.ARB_texture_cube_map_array
778 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
779 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
780 return ctx
->Extensions
.ARB_texture_cube_map_array
781 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
782 case GL_TEXTURE_RECTANGLE_NV
:
783 return ctx
->Extensions
.NV_texture_rectangle
784 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
785 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
786 return ctx
->Extensions
.NV_texture_rectangle
787 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
788 case GL_TEXTURE_1D_ARRAY_EXT
:
789 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
790 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
791 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
792 case GL_TEXTURE_2D_ARRAY_EXT
:
793 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
794 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
795 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
796 case GL_TEXTURE_BUFFER
:
797 return ctx
->API
== API_OPENGL_CORE
&&
798 ctx
->Extensions
.ARB_texture_buffer_object
?
799 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
800 case GL_TEXTURE_EXTERNAL_OES
:
801 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
802 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
803 case GL_TEXTURE_2D_MULTISAMPLE
:
804 return ctx
->Extensions
.ARB_texture_multisample
805 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
806 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
807 return ctx
->Extensions
.ARB_texture_multisample
808 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
809 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
810 return ctx
->Extensions
.ARB_texture_multisample
811 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
812 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
813 return ctx
->Extensions
.ARB_texture_multisample
814 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
816 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
823 * Return pointer to texture object for given target on current texture unit.
825 struct gl_texture_object
*
826 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
828 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
829 return _mesa_select_tex_object(ctx
, texUnit
, target
);
834 * Get a texture image pointer from a texture object, given a texture
835 * target and mipmap level. The target and level parameters should
836 * have already been error-checked.
838 * \param ctx GL context.
839 * \param texObj texture unit.
840 * \param target texture target.
841 * \param level image level.
843 * \return pointer to the texture image structure, or NULL on failure.
845 struct gl_texture_image
*
846 _mesa_select_tex_image(struct gl_context
*ctx
,
847 const struct gl_texture_object
*texObj
,
848 GLenum target
, GLint level
)
850 const GLuint face
= _mesa_tex_target_to_face(target
);
854 ASSERT(level
< MAX_TEXTURE_LEVELS
);
856 return texObj
->Image
[face
][level
];
861 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
862 * it and install it. Only return NULL if passed a bad parameter or run
865 struct gl_texture_image
*
866 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
867 GLenum target
, GLint level
)
869 struct gl_texture_image
*texImage
;
874 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
876 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
878 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
882 set_tex_image(texObj
, target
, level
, texImage
);
890 * Return pointer to the specified proxy texture image.
891 * Note that proxy textures are per-context, not per-texture unit.
892 * \return pointer to texture image or NULL if invalid target, invalid
893 * level, or out of memory.
895 static struct gl_texture_image
*
896 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
898 struct gl_texture_image
*texImage
;
905 case GL_PROXY_TEXTURE_1D
:
906 if (level
>= ctx
->Const
.MaxTextureLevels
)
908 texIndex
= TEXTURE_1D_INDEX
;
910 case GL_PROXY_TEXTURE_2D
:
911 if (level
>= ctx
->Const
.MaxTextureLevels
)
913 texIndex
= TEXTURE_2D_INDEX
;
915 case GL_PROXY_TEXTURE_3D
:
916 if (level
>= ctx
->Const
.Max3DTextureLevels
)
918 texIndex
= TEXTURE_3D_INDEX
;
920 case GL_PROXY_TEXTURE_CUBE_MAP
:
921 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
923 texIndex
= TEXTURE_CUBE_INDEX
;
925 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
928 texIndex
= TEXTURE_RECT_INDEX
;
930 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
931 if (level
>= ctx
->Const
.MaxTextureLevels
)
933 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
935 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
936 if (level
>= ctx
->Const
.MaxTextureLevels
)
938 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
940 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
941 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
943 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
945 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
948 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
950 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
953 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
959 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
961 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
963 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
966 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
967 /* Set the 'back' pointer */
968 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
975 * Get the maximum number of allowed mipmap levels.
977 * \param ctx GL context.
978 * \param target texture target.
980 * \return the maximum number of allowed mipmap levels for the given
981 * texture target, or zero if passed a bad target.
986 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
990 case GL_PROXY_TEXTURE_1D
:
992 case GL_PROXY_TEXTURE_2D
:
993 return ctx
->Const
.MaxTextureLevels
;
995 case GL_PROXY_TEXTURE_3D
:
996 return ctx
->Const
.Max3DTextureLevels
;
997 case GL_TEXTURE_CUBE_MAP
:
998 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
999 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1000 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1001 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1002 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1003 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1004 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1005 return ctx
->Extensions
.ARB_texture_cube_map
1006 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1007 case GL_TEXTURE_RECTANGLE_NV
:
1008 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1009 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
1010 case GL_TEXTURE_1D_ARRAY_EXT
:
1011 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1012 case GL_TEXTURE_2D_ARRAY_EXT
:
1013 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1014 return (ctx
->Extensions
.MESA_texture_array
||
1015 ctx
->Extensions
.EXT_texture_array
)
1016 ? ctx
->Const
.MaxTextureLevels
: 0;
1017 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1018 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1019 return ctx
->Extensions
.ARB_texture_cube_map_array
1020 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1021 case GL_TEXTURE_BUFFER
:
1022 return ctx
->API
== API_OPENGL_CORE
&&
1023 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1024 case GL_TEXTURE_2D_MULTISAMPLE
:
1025 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1026 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1027 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1028 return _mesa_is_desktop_gl(ctx
)
1029 && ctx
->Extensions
.ARB_texture_multisample
1031 case GL_TEXTURE_EXTERNAL_OES
:
1034 return 0; /* bad target */
1040 * Return number of dimensions per mipmap level for the given texture target.
1043 _mesa_get_texture_dimensions(GLenum target
)
1047 case GL_PROXY_TEXTURE_1D
:
1050 case GL_TEXTURE_RECTANGLE
:
1051 case GL_TEXTURE_CUBE_MAP
:
1052 case GL_PROXY_TEXTURE_2D
:
1053 case GL_PROXY_TEXTURE_RECTANGLE
:
1054 case GL_PROXY_TEXTURE_CUBE_MAP
:
1055 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1056 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1057 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1058 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1059 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1060 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1061 case GL_TEXTURE_1D_ARRAY
:
1062 case GL_PROXY_TEXTURE_1D_ARRAY
:
1063 case GL_TEXTURE_EXTERNAL_OES
:
1064 case GL_TEXTURE_2D_MULTISAMPLE
:
1065 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1068 case GL_PROXY_TEXTURE_3D
:
1069 case GL_TEXTURE_2D_ARRAY
:
1070 case GL_PROXY_TEXTURE_2D_ARRAY
:
1071 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1072 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1073 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1074 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1076 case GL_TEXTURE_BUFFER
:
1079 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1087 * Return the maximum number of mipmap levels for the given target
1088 * and the dimensions.
1089 * The dimensions are expected not to include the border.
1092 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1099 case GL_TEXTURE_1D_ARRAY
:
1102 case GL_TEXTURE_CUBE_MAP
:
1103 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1104 ASSERT(width
== height
);
1108 case GL_TEXTURE_2D_ARRAY
:
1109 size
= MAX2(width
, height
);
1112 size
= MAX3(width
, height
, depth
);
1114 case GL_TEXTURE_RECTANGLE
:
1115 case GL_TEXTURE_EXTERNAL_OES
:
1116 case GL_TEXTURE_2D_MULTISAMPLE
:
1117 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1124 return _mesa_logbase2(size
) + 1;
1128 #if 000 /* not used anymore */
1130 * glTexImage[123]D can accept a NULL image pointer. In this case we
1131 * create a texture image with unspecified image contents per the OpenGL
1135 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1137 const GLint components
= _mesa_components_in_format(format
);
1138 const GLint numPixels
= width
* height
* depth
;
1139 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1143 * Let's see if anyone finds this. If glTexImage2D() is called with
1144 * a NULL image pointer then load the texture image with something
1145 * interesting instead of leaving it indeterminate.
1148 static const char message
[8][32] = {
1149 " X X XXXXX XXX X ",
1150 " XX XX X X X X X ",
1152 " X X XXXX XXX XXXXX ",
1155 " X X XXXXX XXX X X ",
1159 GLubyte
*imgPtr
= data
;
1161 for (h
= 0; h
< depth
; h
++) {
1162 for (i
= 0; i
< height
; i
++) {
1163 GLint srcRow
= 7 - (i
% 8);
1164 for (j
= 0; j
< width
; j
++) {
1165 GLint srcCol
= j
% 32;
1166 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1167 for (k
= 0; k
< components
; k
++) {
1183 * Set the size and format-related fields of a gl_texture_image struct
1184 * to zero. This is used when a proxy texture test fails.
1187 clear_teximage_fields(struct gl_texture_image
*img
)
1190 img
->_BaseFormat
= 0;
1191 img
->InternalFormat
= 0;
1200 img
->HeightLog2
= 0;
1202 img
->TexFormat
= MESA_FORMAT_NONE
;
1203 img
->NumSamples
= 0;
1204 img
->FixedSampleLocations
= GL_TRUE
;
1209 * Initialize basic fields of the gl_texture_image struct.
1211 * \param ctx GL context.
1212 * \param img texture image structure to be initialized.
1213 * \param width image width.
1214 * \param height image height.
1215 * \param depth image depth.
1216 * \param border image border.
1217 * \param internalFormat internal format.
1218 * \param format the actual hardware format (one of MESA_FORMAT_*)
1220 * Fills in the fields of \p img with the given information.
1221 * Note: width, height and depth include the border.
1224 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1225 struct gl_texture_image
*img
,
1226 GLsizei width
, GLsizei height
, GLsizei depth
,
1227 GLint border
, GLenum internalFormat
,
1233 ASSERT(height
>= 0);
1236 target
= img
->TexObject
->Target
;
1237 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1238 ASSERT(img
->_BaseFormat
> 0);
1239 img
->InternalFormat
= internalFormat
;
1240 img
->Border
= border
;
1242 img
->Height
= height
;
1245 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1246 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1248 img
->NumSamples
= 0;
1249 img
->FixedSampleLocations
= GL_TRUE
;
1253 case GL_TEXTURE_BUFFER
:
1254 case GL_PROXY_TEXTURE_1D
:
1259 img
->HeightLog2
= 0;
1266 case GL_TEXTURE_1D_ARRAY
:
1267 case GL_PROXY_TEXTURE_1D_ARRAY
:
1268 img
->Height2
= height
; /* no border */
1269 img
->HeightLog2
= 0; /* not used */
1277 case GL_TEXTURE_RECTANGLE
:
1278 case GL_TEXTURE_CUBE_MAP
:
1279 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1280 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1281 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1282 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1283 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1284 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1285 case GL_TEXTURE_EXTERNAL_OES
:
1286 case GL_PROXY_TEXTURE_2D
:
1287 case GL_PROXY_TEXTURE_RECTANGLE
:
1288 case GL_PROXY_TEXTURE_CUBE_MAP
:
1289 case GL_TEXTURE_2D_MULTISAMPLE
:
1290 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1291 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1292 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1299 case GL_TEXTURE_2D_ARRAY
:
1300 case GL_PROXY_TEXTURE_2D_ARRAY
:
1301 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1302 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1303 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1304 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1305 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1306 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1307 img
->Depth2
= depth
; /* no border */
1308 img
->DepthLog2
= 0; /* not used */
1311 case GL_PROXY_TEXTURE_3D
:
1312 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1313 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1314 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1315 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1318 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1323 _mesa_get_tex_max_num_levels(target
,
1324 img
->Width2
, img
->Height2
, img
->Depth2
);
1325 img
->TexFormat
= format
;
1330 * Free and clear fields of the gl_texture_image struct.
1332 * \param ctx GL context.
1333 * \param texImage texture image structure to be cleared.
1335 * After the call, \p texImage will have no data associated with it. Its
1336 * fields are cleared so that its parent object will test incomplete.
1339 _mesa_clear_texture_image(struct gl_context
*ctx
,
1340 struct gl_texture_image
*texImage
)
1342 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1343 clear_teximage_fields(texImage
);
1348 * Check the width, height, depth and border of a texture image are legal.
1349 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1351 * The target and level parameters will have already been validated.
1352 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1355 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1356 GLint level
, GLint width
, GLint height
,
1357 GLint depth
, GLint border
)
1363 case GL_PROXY_TEXTURE_1D
:
1364 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1365 maxSize
>>= level
; /* level size */
1366 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1368 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1369 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1375 case GL_PROXY_TEXTURE_2D
:
1376 case GL_TEXTURE_2D_MULTISAMPLE
:
1377 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1378 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1380 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1382 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1384 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1385 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1387 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1393 case GL_PROXY_TEXTURE_3D
:
1394 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1396 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1398 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1400 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1402 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1403 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1405 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1407 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1412 case GL_TEXTURE_RECTANGLE_NV
:
1413 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1416 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1417 if (width
< 0 || width
> maxSize
)
1419 if (height
< 0 || height
> maxSize
)
1423 case GL_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 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1431 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1433 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1435 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1437 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1438 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1440 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1445 case GL_TEXTURE_1D_ARRAY_EXT
:
1446 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1447 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1449 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1451 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1453 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1454 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1459 case GL_TEXTURE_2D_ARRAY_EXT
:
1460 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1461 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1462 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1463 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1465 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1467 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1469 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1471 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1472 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1474 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1479 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1480 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1481 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1482 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1484 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1486 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1488 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1490 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1491 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1493 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1498 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1505 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1506 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1507 * \param destImage the destination texture image.
1508 * \return GL_TRUE if error found, GL_FALSE otherwise.
1511 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1512 const char *function
, GLuint dims
,
1513 const struct gl_texture_image
*destImage
,
1514 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1515 GLsizei subWidth
, GLsizei subHeight
,
1518 const GLenum target
= destImage
->TexObject
->Target
;
1523 _mesa_error(ctx
, GL_INVALID_VALUE
,
1524 "%s%dD(width=%d)", function
, dims
, subWidth
);
1528 if (dims
> 1 && subHeight
< 0) {
1529 _mesa_error(ctx
, GL_INVALID_VALUE
,
1530 "%s%dD(height=%d)", function
, dims
, subHeight
);
1534 if (dims
> 2 && subDepth
< 0) {
1535 _mesa_error(ctx
, GL_INVALID_VALUE
,
1536 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1540 /* check xoffset and width */
1541 if (xoffset
< - (GLint
) destImage
->Border
) {
1542 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1547 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1548 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1553 /* check yoffset and height */
1555 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1556 if (yoffset
< -yBorder
) {
1557 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1561 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1562 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1568 /* check zoffset and depth */
1570 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1571 if (zoffset
< -zBorder
) {
1572 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1575 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1576 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1582 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1583 * compressed texture images can be updated. But, that restriction may be
1584 * relaxed for particular compressed formats. At this time, all the
1585 * compressed formats supported by Mesa allow sub-textures to be updated
1586 * along compressed block boundaries.
1588 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1590 if (bw
!= 1 || bh
!= 1) {
1591 /* offset must be multiple of block size */
1592 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1593 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1594 "%s%dD(xoffset = %d, yoffset = %d)",
1595 function
, dims
, xoffset
, yoffset
);
1599 /* The size must be a multiple of bw x bh, or we must be using a
1600 * offset+size that exactly hits the edge of the image. This
1601 * is important for small mipmap levels (1x1, 2x1, etc) and for
1604 if ((subWidth
% bw
!= 0) &&
1605 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1606 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1607 "%s%dD(width = %d)", function
, dims
, subWidth
);
1611 if ((subHeight
% bh
!= 0) &&
1612 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1613 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1614 "%s%dD(height = %d)", function
, dims
, subHeight
);
1626 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1627 * specific texture image size checks.
1629 * A hardware driver might override this function if, for example, the
1630 * max 3D texture size is 512x512x64 (i.e. not a cube).
1632 * Note that width, height, depth == 0 is not an error. However, a
1633 * texture with zero width/height/depth will be considered "incomplete"
1634 * and texturing will effectively be disabled.
1636 * \param target any texture target/type
1637 * \param level as passed to glTexImage
1638 * \param format the MESA_FORMAT_x for the tex image
1639 * \param width as passed to glTexImage
1640 * \param height as passed to glTexImage
1641 * \param depth as passed to glTexImage
1642 * \param border as passed to glTexImage
1643 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1646 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1648 GLint width
, GLint height
, GLint depth
, GLint border
)
1650 /* We just check if the image size is less than MaxTextureMbytes.
1651 * Some drivers may do more specific checks.
1653 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1654 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1655 mbytes
*= _mesa_num_tex_faces(target
);
1656 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1661 * Return true if the format is only valid for glCompressedTexImage.
1664 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1667 case GL_ETC1_RGB8_OES
:
1668 case GL_PALETTE4_RGB8_OES
:
1669 case GL_PALETTE4_RGBA8_OES
:
1670 case GL_PALETTE4_R5_G6_B5_OES
:
1671 case GL_PALETTE4_RGBA4_OES
:
1672 case GL_PALETTE4_RGB5_A1_OES
:
1673 case GL_PALETTE8_RGB8_OES
:
1674 case GL_PALETTE8_RGBA8_OES
:
1675 case GL_PALETTE8_R5_G6_B5_OES
:
1676 case GL_PALETTE8_RGBA4_OES
:
1677 case GL_PALETTE8_RGB5_A1_OES
:
1686 * Helper function to determine whether a target and specific compression
1687 * format are supported.
1690 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1693 (void) intFormat
; /* not used yet */
1697 case GL_PROXY_TEXTURE_2D
:
1698 return GL_TRUE
; /* true for any compressed format so far */
1699 case GL_PROXY_TEXTURE_CUBE_MAP
:
1700 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1701 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1702 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1703 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1704 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1705 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1706 return ctx
->Extensions
.ARB_texture_cube_map
;
1707 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1708 case GL_TEXTURE_2D_ARRAY_EXT
:
1709 return (ctx
->Extensions
.MESA_texture_array
||
1710 ctx
->Extensions
.EXT_texture_array
);
1711 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1712 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1713 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1721 * Check if the given texture target value is legal for a
1722 * glTexImage1/2/3D call.
1725 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1731 case GL_PROXY_TEXTURE_1D
:
1732 return _mesa_is_desktop_gl(ctx
);
1740 case GL_PROXY_TEXTURE_2D
:
1741 return _mesa_is_desktop_gl(ctx
);
1742 case GL_PROXY_TEXTURE_CUBE_MAP
:
1743 return _mesa_is_desktop_gl(ctx
)
1744 && ctx
->Extensions
.ARB_texture_cube_map
;
1745 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1746 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1747 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1748 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1749 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1750 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1751 return ctx
->Extensions
.ARB_texture_cube_map
;
1752 case GL_TEXTURE_RECTANGLE_NV
:
1753 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1754 return _mesa_is_desktop_gl(ctx
)
1755 && ctx
->Extensions
.NV_texture_rectangle
;
1756 case GL_TEXTURE_1D_ARRAY_EXT
:
1757 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1758 return _mesa_is_desktop_gl(ctx
)
1759 && (ctx
->Extensions
.MESA_texture_array
||
1760 ctx
->Extensions
.EXT_texture_array
);
1768 case GL_PROXY_TEXTURE_3D
:
1769 return _mesa_is_desktop_gl(ctx
);
1770 case GL_TEXTURE_2D_ARRAY_EXT
:
1771 return (_mesa_is_desktop_gl(ctx
)
1772 && (ctx
->Extensions
.MESA_texture_array
||
1773 ctx
->Extensions
.EXT_texture_array
))
1774 || _mesa_is_gles3(ctx
);
1775 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1776 return _mesa_is_desktop_gl(ctx
)
1777 && (ctx
->Extensions
.MESA_texture_array
||
1778 ctx
->Extensions
.EXT_texture_array
);
1779 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1780 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1781 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1786 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1793 * Check if the given texture target value is legal for a
1794 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1795 * The difference compared to legal_teximage_target() above is that
1796 * proxy targets are not supported.
1799 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1803 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1808 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1809 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1810 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1811 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1812 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1813 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1814 return ctx
->Extensions
.ARB_texture_cube_map
;
1815 case GL_TEXTURE_RECTANGLE_NV
:
1816 return _mesa_is_desktop_gl(ctx
)
1817 && ctx
->Extensions
.NV_texture_rectangle
;
1818 case GL_TEXTURE_1D_ARRAY_EXT
:
1819 return _mesa_is_desktop_gl(ctx
)
1820 && (ctx
->Extensions
.MESA_texture_array
||
1821 ctx
->Extensions
.EXT_texture_array
);
1829 case GL_TEXTURE_2D_ARRAY_EXT
:
1830 return (_mesa_is_desktop_gl(ctx
)
1831 && (ctx
->Extensions
.MESA_texture_array
||
1832 ctx
->Extensions
.EXT_texture_array
))
1833 || _mesa_is_gles3(ctx
);
1834 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1835 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1836 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1841 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1849 * Helper function to determine if a texture object is mutable (in terms
1850 * of GL_ARB_texture_storage).
1853 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1855 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1856 return !texObj
->Immutable
;
1861 * Return expected size of a compressed texture.
1864 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1867 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1868 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1873 * Test the glTexImage[123]D() parameters for errors.
1875 * \param ctx GL context.
1876 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1877 * \param target texture target given by the user (already validated).
1878 * \param level image level given by the user.
1879 * \param internalFormat internal format given by the user.
1880 * \param format pixel data format given by the user.
1881 * \param type pixel data type given by the user.
1882 * \param width image width given by the user.
1883 * \param height image height given by the user.
1884 * \param depth image depth given by the user.
1885 * \param border image border given by the user.
1887 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1889 * Verifies each of the parameters against the constants specified in
1890 * __struct gl_contextRec::Const and the supported extensions, and according
1891 * to the OpenGL specification.
1892 * Note that we don't fully error-check the width, height, depth values
1893 * here. That's done in _mesa_legal_texture_dimensions() which is used
1894 * by several other GL entrypoints. Plus, texture dims have a special
1895 * interaction with proxy textures.
1898 texture_error_check( struct gl_context
*ctx
,
1899 GLuint dimensions
, GLenum target
,
1900 GLint level
, GLint internalFormat
,
1901 GLenum format
, GLenum type
,
1902 GLint width
, GLint height
,
1903 GLint depth
, GLint border
)
1905 GLboolean colorFormat
;
1908 /* Even though there are no color-index textures, we still have to support
1909 * uploading color-index data and remapping it to RGB via the
1910 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1912 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1914 /* Note: for proxy textures, some error conditions immediately generate
1915 * a GL error in the usual way. But others do not generate a GL error.
1916 * Instead, they cause the width, height, depth, format fields of the
1917 * texture image to be zeroed-out. The GL spec seems to indicate that the
1918 * zero-out behaviour is only used in cases related to memory allocation.
1922 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1923 _mesa_error(ctx
, GL_INVALID_VALUE
,
1924 "glTexImage%dD(level=%d)", dimensions
, level
);
1929 if (border
< 0 || border
> 1 ||
1930 ((ctx
->API
!= API_OPENGL_COMPAT
||
1931 target
== GL_TEXTURE_RECTANGLE_NV
||
1932 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1933 _mesa_error(ctx
, GL_INVALID_VALUE
,
1934 "glTexImage%dD(border=%d)", dimensions
, border
);
1938 if (width
< 0 || height
< 0 || depth
< 0) {
1939 _mesa_error(ctx
, GL_INVALID_VALUE
,
1940 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1944 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1945 * combinations of format, internalFormat, and type that can be used.
1946 * Formats and types that require additional extensions (e.g., GL_FLOAT
1947 * requires GL_OES_texture_float) are filtered elsewhere.
1950 if (_mesa_is_gles(ctx
)) {
1951 if (_mesa_is_gles3(ctx
)) {
1952 err
= _mesa_es3_error_check_format_and_type(format
, type
,
1955 if (format
!= internalFormat
) {
1956 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1957 "glTexImage%dD(format = %s, internalFormat = %s)",
1959 _mesa_lookup_enum_by_nr(format
),
1960 _mesa_lookup_enum_by_nr(internalFormat
));
1964 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1966 if (err
!= GL_NO_ERROR
) {
1967 _mesa_error(ctx
, err
,
1968 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
1970 _mesa_lookup_enum_by_nr(format
),
1971 _mesa_lookup_enum_by_nr(type
),
1972 _mesa_lookup_enum_by_nr(internalFormat
));
1977 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1978 _mesa_is_cube_face(target
)) && width
!= height
) {
1979 _mesa_error(ctx
, GL_INVALID_VALUE
,
1980 "glTexImage2D(cube width != height)");
1984 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1985 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && width
!= height
) {
1986 _mesa_error(ctx
, GL_INVALID_VALUE
,
1987 "glTexImage3D(cube array width != height)");
1991 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1992 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && (depth
% 6)) {
1993 _mesa_error(ctx
, GL_INVALID_VALUE
,
1994 "glTexImage3D(cube array depth not multiple of 6)");
1998 /* Check internalFormat */
1999 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2000 _mesa_error(ctx
, GL_INVALID_VALUE
,
2001 "glTexImage%dD(internalFormat=%s)",
2002 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2006 /* Check incoming image format and type */
2007 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2008 if (err
!= GL_NO_ERROR
) {
2009 _mesa_error(ctx
, err
,
2010 "glTexImage%dD(incompatible format = %s, type = %s)",
2011 dimensions
, _mesa_lookup_enum_by_nr(format
),
2012 _mesa_lookup_enum_by_nr(type
));
2016 /* make sure internal format and format basically agree */
2017 colorFormat
= _mesa_is_color_format(format
);
2018 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2019 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2020 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2021 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2022 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2023 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2024 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2025 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2026 _mesa_lookup_enum_by_nr(format
));
2030 /* additional checks for ycbcr textures */
2031 if (internalFormat
== GL_YCBCR_MESA
) {
2032 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2033 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2034 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2036 _mesa_snprintf(message
, sizeof(message
),
2037 "glTexImage%dD(format/type YCBCR mismatch)",
2039 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2040 return GL_TRUE
; /* error */
2042 if (target
!= GL_TEXTURE_2D
&&
2043 target
!= GL_PROXY_TEXTURE_2D
&&
2044 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2045 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2046 _mesa_error(ctx
, GL_INVALID_ENUM
,
2047 "glTexImage%dD(bad target for YCbCr texture)",
2053 _mesa_snprintf(message
, sizeof(message
),
2054 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2055 dimensions
, border
);
2056 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2061 /* additional checks for depth textures */
2062 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2063 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2064 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
2065 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
2066 if (target
!= GL_TEXTURE_1D
&&
2067 target
!= GL_PROXY_TEXTURE_1D
&&
2068 target
!= GL_TEXTURE_2D
&&
2069 target
!= GL_PROXY_TEXTURE_2D
&&
2070 target
!= GL_TEXTURE_1D_ARRAY
&&
2071 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2072 target
!= GL_TEXTURE_2D_ARRAY
&&
2073 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2074 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2075 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2076 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2077 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2078 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2079 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2080 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2081 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2082 _mesa_error(ctx
, GL_INVALID_ENUM
,
2083 "glTexImage%dD(bad target for depth texture)",
2089 /* additional checks for compressed textures */
2090 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2091 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2092 _mesa_error(ctx
, GL_INVALID_ENUM
,
2093 "glTexImage%dD(target can't be compressed)", dimensions
);
2096 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2097 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2098 "glTexImage%dD(no compression for format)", dimensions
);
2102 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2103 "glTexImage%dD(border!=0)", dimensions
);
2108 /* additional checks for integer textures */
2109 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2110 (_mesa_is_enum_format_integer(format
) !=
2111 _mesa_is_enum_format_integer(internalFormat
))) {
2112 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2113 "glTexImage%dD(integer/non-integer format mismatch)",
2118 if (!mutable_tex_object(ctx
, target
)) {
2119 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2120 "glTexImage%dD(immutable texture)", dimensions
);
2124 /* if we get here, the parameters are OK */
2130 * Error checking for glCompressedTexImage[123]D().
2131 * Note that the width, height and depth values are not fully error checked
2133 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2136 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2137 GLenum target
, GLint level
,
2138 GLenum internalFormat
, GLsizei width
,
2139 GLsizei height
, GLsizei depth
, GLint border
,
2142 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2144 GLenum error
= GL_NO_ERROR
;
2145 char *reason
= ""; /* no error */
2147 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2149 error
= GL_INVALID_ENUM
;
2153 /* This will detect any invalid internalFormat value */
2154 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2155 reason
= "internalFormat";
2156 error
= GL_INVALID_ENUM
;
2160 switch (internalFormat
) {
2161 case GL_PALETTE4_RGB8_OES
:
2162 case GL_PALETTE4_RGBA8_OES
:
2163 case GL_PALETTE4_R5_G6_B5_OES
:
2164 case GL_PALETTE4_RGBA4_OES
:
2165 case GL_PALETTE4_RGB5_A1_OES
:
2166 case GL_PALETTE8_RGB8_OES
:
2167 case GL_PALETTE8_RGBA8_OES
:
2168 case GL_PALETTE8_R5_G6_B5_OES
:
2169 case GL_PALETTE8_RGBA4_OES
:
2170 case GL_PALETTE8_RGB5_A1_OES
:
2171 /* check level (note that level should be zero or less!) */
2172 if (level
> 0 || level
< -maxLevels
) {
2174 error
= GL_INVALID_VALUE
;
2178 if (dimensions
!= 2) {
2179 reason
= "compressed paletted textures must be 2D";
2180 error
= GL_INVALID_OPERATION
;
2184 /* Figure out the expected texture size (in bytes). This will be
2185 * checked against the actual size later.
2187 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2190 /* This is for the benefit of the TestProxyTexImage below. It expects
2191 * level to be non-negative. OES_compressed_paletted_texture uses a
2192 * weird mechanism where the level specified to glCompressedTexImage2D
2193 * is -(n-1) number of levels in the texture, and the data specifies the
2194 * complete mipmap stack. This is done to ensure the palette is the
2195 * same for all levels.
2202 if (level
< 0 || level
>= maxLevels
) {
2204 error
= GL_INVALID_VALUE
;
2208 /* Figure out the expected texture size (in bytes). This will be
2209 * checked against the actual size later.
2211 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2215 /* This should really never fail */
2216 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2217 reason
= "internalFormat";
2218 error
= GL_INVALID_ENUM
;
2222 /* No compressed formats support borders at this time */
2224 reason
= "border != 0";
2225 error
= GL_INVALID_VALUE
;
2229 /* For cube map, width must equal height */
2230 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2231 _mesa_is_cube_face(target
)) && width
!= height
) {
2232 reason
= "width != height";
2233 error
= GL_INVALID_VALUE
;
2237 /* check image size in bytes */
2238 if (expectedSize
!= imageSize
) {
2239 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2240 * if <imageSize> is not consistent with the format, dimensions, and
2241 * contents of the specified image.
2243 reason
= "imageSize inconsistant with width/height/format";
2244 error
= GL_INVALID_VALUE
;
2248 if (!mutable_tex_object(ctx
, target
)) {
2249 reason
= "immutable texture";
2250 error
= GL_INVALID_OPERATION
;
2257 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2264 * Test glTexSubImage[123]D() parameters for errors.
2266 * \param ctx GL context.
2267 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2268 * \param target texture target given by the user (already validated)
2269 * \param level image level given by the user.
2270 * \param xoffset sub-image x offset given by the user.
2271 * \param yoffset sub-image y offset given by the user.
2272 * \param zoffset sub-image z offset given by the user.
2273 * \param format pixel data format given by the user.
2274 * \param type pixel data type given by the user.
2275 * \param width image width given by the user.
2276 * \param height image height given by the user.
2277 * \param depth image depth given by the user.
2279 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2281 * Verifies each of the parameters against the constants specified in
2282 * __struct gl_contextRec::Const and the supported extensions, and according
2283 * to the OpenGL specification.
2286 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2287 GLenum target
, GLint level
,
2288 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2289 GLint width
, GLint height
, GLint depth
,
2290 GLenum format
, GLenum type
)
2292 struct gl_texture_object
*texObj
;
2293 struct gl_texture_image
*texImage
;
2296 /* check target (proxies not allowed) */
2297 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2298 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2299 dimensions
, _mesa_lookup_enum_by_nr(target
));
2304 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2305 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2310 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2311 * combinations of format and type that can be used. Formats and types
2312 * that require additional extensions (e.g., GL_FLOAT requires
2313 * GL_OES_texture_float) are filtered elsewhere.
2315 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2316 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2317 if (err
!= GL_NO_ERROR
) {
2318 _mesa_error(ctx
, err
,
2319 "glTexSubImage%dD(format = %s, type = %s)",
2321 _mesa_lookup_enum_by_nr(format
),
2322 _mesa_lookup_enum_by_nr(type
));
2327 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2328 if (err
!= GL_NO_ERROR
) {
2329 _mesa_error(ctx
, err
,
2330 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2331 dimensions
, _mesa_lookup_enum_by_nr(format
),
2332 _mesa_lookup_enum_by_nr(type
));
2336 /* Get dest texture object / image pointers */
2337 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2339 /* must be out of memory */
2340 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2344 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2346 /* non-existant texture level */
2347 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2348 "glTexSubImage%dD(invalid texture image)", dimensions
);
2352 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2353 texImage
, xoffset
, yoffset
, 0,
2354 width
, height
, 1)) {
2358 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2359 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2360 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2361 "glTexSubImage%dD(no compression for format)", dimensions
);
2366 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2367 /* both source and dest must be integer-valued, or neither */
2368 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2369 _mesa_is_enum_format_integer(format
)) {
2370 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2371 "glTexSubImage%dD(integer/non-integer format mismatch)",
2382 * Test glCopyTexImage[12]D() parameters for errors.
2384 * \param ctx GL context.
2385 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2386 * \param target texture target given by the user.
2387 * \param level image level given by the user.
2388 * \param internalFormat internal format given by the user.
2389 * \param width image width given by the user.
2390 * \param height image height given by the user.
2391 * \param border texture border.
2393 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2395 * Verifies each of the parameters against the constants specified in
2396 * __struct gl_contextRec::Const and the supported extensions, and according
2397 * to the OpenGL specification.
2400 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2401 GLenum target
, GLint level
, GLint internalFormat
,
2402 GLint width
, GLint height
, GLint border
)
2405 GLint rb_base_format
;
2406 struct gl_renderbuffer
*rb
;
2407 GLenum rb_internal_format
;
2410 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2411 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2412 dimensions
, _mesa_lookup_enum_by_nr(target
));
2417 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2418 _mesa_error(ctx
, GL_INVALID_VALUE
,
2419 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2423 /* Check that the source buffer is complete */
2424 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2425 if (ctx
->ReadBuffer
->_Status
== 0) {
2426 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2428 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2429 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2430 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2434 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2435 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2436 "glCopyTexImage%dD(multisample FBO)",
2443 if (border
< 0 || border
> 1 ||
2444 ((ctx
->API
!= API_OPENGL_COMPAT
||
2445 target
== GL_TEXTURE_RECTANGLE_NV
||
2446 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2447 _mesa_error(ctx
, GL_INVALID_VALUE
,
2448 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2452 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2454 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2455 "glCopyTexImage%dD(read buffer)", dimensions
);
2459 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2462 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2463 switch (internalFormat
) {
2468 case GL_LUMINANCE_ALPHA
:
2471 _mesa_error(ctx
, GL_INVALID_VALUE
,
2472 "glCopyTexImage%dD(internalFormat)", dimensions
);
2477 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2478 if (baseFormat
< 0) {
2479 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2480 "glCopyTexImage%dD(internalFormat)", dimensions
);
2484 rb_internal_format
= rb
->InternalFormat
;
2485 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2486 if (_mesa_is_color_format(internalFormat
)) {
2487 if (rb_base_format
< 0) {
2488 _mesa_error(ctx
, GL_INVALID_VALUE
,
2489 "glCopyTexImage%dD(internalFormat)", dimensions
);
2494 if (_mesa_is_gles(ctx
)) {
2496 if (_mesa_base_format_component_count(baseFormat
) >
2497 _mesa_base_format_component_count(rb_base_format
)) {
2500 if (baseFormat
== GL_DEPTH_COMPONENT
||
2501 baseFormat
== GL_DEPTH_STENCIL
||
2502 rb_base_format
== GL_DEPTH_COMPONENT
||
2503 rb_base_format
== GL_DEPTH_STENCIL
||
2504 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2505 baseFormat
== GL_ALPHA
) &&
2506 rb_base_format
!= GL_RGBA
) ||
2507 internalFormat
== GL_RGB9_E5
) {
2510 if (internalFormat
== GL_RGB9_E5
) {
2514 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2515 "glCopyTexImage%dD(internalFormat)", dimensions
);
2520 if (_mesa_is_gles3(ctx
)) {
2521 bool rb_is_srgb
= false;
2522 bool dst_is_srgb
= false;
2524 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2525 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2529 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2533 if (rb_is_srgb
!= dst_is_srgb
) {
2534 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2535 * OpenGLES 3.0.0 spec says:
2537 * "The error INVALID_OPERATION is also generated if the
2538 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2539 * framebuffer attachment corresponding to the read buffer
2540 * is LINEAR (see section 6.1.13) and internalformat is
2541 * one of the sRGB formats described in section 3.8.16, or
2542 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2543 * SRGB and internalformat is not one of the sRGB formats."
2545 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2546 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2551 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2552 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2553 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2557 /* From the EXT_texture_integer spec:
2559 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2560 * if the texture internalformat is an integer format and the read color
2561 * buffer is not an integer format, or if the internalformat is not an
2562 * integer format and the read color buffer is an integer format."
2564 if (_mesa_is_color_format(internalFormat
)) {
2565 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2566 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2567 if (is_int
|| is_rbint
) {
2568 if (is_int
!= is_rbint
) {
2569 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2570 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2572 } else if (_mesa_is_gles(ctx
) &&
2573 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2574 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2575 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2576 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2582 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2583 _mesa_is_cube_face(target
)) && width
!= height
) {
2584 _mesa_error(ctx
, GL_INVALID_VALUE
,
2585 "glTexImage2D(cube width != height)");
2589 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2590 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2591 _mesa_error(ctx
, GL_INVALID_ENUM
,
2592 "glCopyTexImage%dD(target)", dimensions
);
2595 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2596 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2597 "glCopyTexImage%dD(no compression for format)", dimensions
);
2601 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2602 "glCopyTexImage%dD(border!=0)", dimensions
);
2607 if (!mutable_tex_object(ctx
, target
)) {
2608 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2609 "glCopyTexImage%dD(immutable texture)", dimensions
);
2613 /* if we get here, the parameters are OK */
2619 * Test glCopyTexSubImage[12]D() parameters for errors.
2620 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2623 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2624 GLenum target
, GLint level
,
2625 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2626 GLint width
, GLint height
)
2628 struct gl_texture_object
*texObj
;
2629 struct gl_texture_image
*texImage
;
2631 /* Check that the source buffer is complete */
2632 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2633 if (ctx
->ReadBuffer
->_Status
== 0) {
2634 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2636 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2637 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2638 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2642 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2643 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2644 "glCopyTexSubImage%dD(multisample FBO)",
2650 /* check target (proxies not allowed) */
2651 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2652 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2653 dimensions
, _mesa_lookup_enum_by_nr(target
));
2658 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2659 _mesa_error(ctx
, GL_INVALID_VALUE
,
2660 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2664 /* Get dest texture object / image pointers */
2665 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2667 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2671 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2673 /* destination image does not exist */
2674 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2675 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2679 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2680 dimensions
, texImage
,
2681 xoffset
, yoffset
, zoffset
,
2682 width
, height
, 1)) {
2686 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2687 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2688 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2689 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2694 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2695 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2699 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2700 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2701 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2702 dimensions
, texImage
->_BaseFormat
);
2706 /* From the EXT_texture_integer spec:
2708 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2709 * if the texture internalformat is an integer format and the read color
2710 * buffer is not an integer format, or if the internalformat is not an
2711 * integer format and the read color buffer is an integer format."
2713 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2714 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2716 if (_mesa_is_format_integer_color(rb
->Format
) !=
2717 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2718 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2719 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2724 /* if we get here, the parameters are OK */
2729 /** Callback info for walking over FBO hash table */
2732 struct gl_context
*ctx
;
2733 struct gl_texture_object
*texObj
;
2739 * Check render to texture callback. Called from _mesa_HashWalk().
2742 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2744 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2745 const struct cb_info
*info
= (struct cb_info
*) userData
;
2746 struct gl_context
*ctx
= info
->ctx
;
2747 const struct gl_texture_object
*texObj
= info
->texObj
;
2748 const GLuint level
= info
->level
, face
= info
->face
;
2750 /* If this is a user-created FBO */
2751 if (_mesa_is_user_fbo(fb
)) {
2753 /* check if any of the FBO's attachments point to 'texObj' */
2754 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2755 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2756 if (att
->Type
== GL_TEXTURE
&&
2757 att
->Texture
== texObj
&&
2758 att
->TextureLevel
== level
&&
2759 att
->CubeMapFace
== face
) {
2760 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2761 ASSERT(att
->Renderbuffer
->TexImage
);
2762 /* Mark fb status as indeterminate to force re-validation */
2771 * When a texture image is specified we have to check if it's bound to
2772 * any framebuffer objects (render to texture) in order to detect changes
2773 * in size or format since that effects FBO completeness.
2774 * Any FBOs rendering into the texture must be re-validated.
2777 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2778 struct gl_texture_object
*texObj
,
2779 GLuint face
, GLuint level
)
2781 /* Only check this texture if it's been marked as RenderToTexture */
2782 if (texObj
->_RenderToTexture
) {
2783 struct cb_info info
;
2785 info
.texObj
= texObj
;
2788 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2794 * If the texture object's GenerateMipmap flag is set and we've
2795 * changed the texture base level image, regenerate the rest of the
2796 * mipmap levels now.
2799 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2800 struct gl_texture_object
*texObj
, GLint level
)
2802 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2803 if (texObj
->GenerateMipmap
&&
2804 level
== texObj
->BaseLevel
&&
2805 level
< texObj
->MaxLevel
) {
2806 ASSERT(ctx
->Driver
.GenerateMipmap
);
2807 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2812 /** Debug helper: override the user-requested internal format */
2814 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2817 if (internalFormat
== GL_RGBA16F_ARB
||
2818 internalFormat
== GL_RGBA32F_ARB
) {
2819 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2822 else if (internalFormat
== GL_RGB16F_ARB
||
2823 internalFormat
== GL_RGB32F_ARB
) {
2824 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2827 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2828 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2829 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2830 return GL_LUMINANCE_ALPHA
;
2832 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2833 internalFormat
== GL_LUMINANCE32F_ARB
) {
2834 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2835 return GL_LUMINANCE
;
2837 else if (internalFormat
== GL_ALPHA16F_ARB
||
2838 internalFormat
== GL_ALPHA32F_ARB
) {
2839 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2843 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2844 internalFormat = GL_RGBA;
2848 return internalFormat
;
2851 return internalFormat
;
2857 * Choose the actual hardware format for a texture image.
2858 * Try to use the same format as the previous image level when possible.
2859 * Otherwise, ask the driver for the best format.
2860 * It's important to try to choose a consistant format for all levels
2861 * for efficient texture memory layout/allocation. In particular, this
2862 * comes up during automatic mipmap generation.
2865 _mesa_choose_texture_format(struct gl_context
*ctx
,
2866 struct gl_texture_object
*texObj
,
2867 GLenum target
, GLint level
,
2868 GLenum internalFormat
, GLenum format
, GLenum type
)
2872 /* see if we've already chosen a format for the previous level */
2874 struct gl_texture_image
*prevImage
=
2875 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2876 /* See if the prev level is defined and has an internal format which
2877 * matches the new internal format.
2880 prevImage
->Width
> 0 &&
2881 prevImage
->InternalFormat
== internalFormat
) {
2882 /* use the same format */
2883 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2884 return prevImage
->TexFormat
;
2888 /* If the application requested compression to an S3TC format but we don't
2889 * have the DTXn library, force a generic compressed format instead.
2891 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2892 const GLenum before
= internalFormat
;
2894 switch (internalFormat
) {
2895 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2896 if (!ctx
->Mesa_DXTn
)
2897 internalFormat
= GL_COMPRESSED_RGB
;
2899 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2900 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2901 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2902 if (!ctx
->Mesa_DXTn
)
2903 internalFormat
= GL_COMPRESSED_RGBA
;
2909 if (before
!= internalFormat
) {
2911 "DXT compression requested (%s), "
2912 "but libtxc_dxtn library not installed. Using %s "
2914 _mesa_lookup_enum_by_nr(before
),
2915 _mesa_lookup_enum_by_nr(internalFormat
));
2919 /* choose format from scratch */
2920 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2922 ASSERT(f
!= MESA_FORMAT_NONE
);
2928 * Adjust pixel unpack params and image dimensions to strip off the
2929 * one-pixel texture border.
2931 * Gallium and intel don't support texture borders. They've seldem been used
2932 * and seldom been implemented correctly anyway.
2934 * \param unpackNew returns the new pixel unpack parameters
2937 strip_texture_border(GLenum target
,
2938 GLint
*width
, GLint
*height
, GLint
*depth
,
2939 const struct gl_pixelstore_attrib
*unpack
,
2940 struct gl_pixelstore_attrib
*unpackNew
)
2946 *unpackNew
= *unpack
;
2948 if (unpackNew
->RowLength
== 0)
2949 unpackNew
->RowLength
= *width
;
2951 if (unpackNew
->ImageHeight
== 0)
2952 unpackNew
->ImageHeight
= *height
;
2954 assert(*width
>= 3);
2955 unpackNew
->SkipPixels
++; /* skip the border */
2956 *width
= *width
- 2; /* reduce the width by two border pixels */
2958 /* The min height of a texture with a border is 3 */
2959 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2960 unpackNew
->SkipRows
++; /* skip the border */
2961 *height
= *height
- 2; /* reduce the height by two border pixels */
2965 target
!= GL_TEXTURE_2D_ARRAY
&&
2966 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2967 unpackNew
->SkipImages
++; /* skip the border */
2968 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2974 * Common code to implement all the glTexImage1D/2D/3D functions
2975 * as well as glCompressedTexImage1D/2D/3D.
2976 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2977 * \param format the user's image format (only used if !compressed)
2978 * \param type the user's image type (only used if !compressed)
2979 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2982 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2983 GLenum target
, GLint level
, GLint internalFormat
,
2984 GLsizei width
, GLsizei height
, GLsizei depth
,
2985 GLint border
, GLenum format
, GLenum type
,
2986 GLsizei imageSize
, const GLvoid
*pixels
)
2988 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2989 struct gl_pixelstore_attrib unpack_no_border
;
2990 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2991 struct gl_texture_object
*texObj
;
2992 gl_format texFormat
;
2993 GLboolean dimensionsOK
, sizeOK
;
2995 FLUSH_VERTICES(ctx
, 0);
2997 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3000 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3002 _mesa_lookup_enum_by_nr(target
), level
,
3003 _mesa_lookup_enum_by_nr(internalFormat
),
3004 width
, height
, depth
, border
, pixels
);
3007 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3009 _mesa_lookup_enum_by_nr(target
), level
,
3010 _mesa_lookup_enum_by_nr(internalFormat
),
3011 width
, height
, depth
, border
,
3012 _mesa_lookup_enum_by_nr(format
),
3013 _mesa_lookup_enum_by_nr(type
), pixels
);
3016 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3018 /* target error checking */
3019 if (!legal_teximage_target(ctx
, dims
, target
)) {
3020 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3021 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3025 /* general error checking */
3027 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3029 width
, height
, depth
,
3034 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3035 format
, type
, width
, height
, depth
, border
))
3039 /* Here we convert a cpal compressed image into a regular glTexImage2D
3040 * call by decompressing the texture. If we really want to support cpal
3041 * textures in any driver this would have to be changed.
3043 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3044 switch (internalFormat
) {
3045 case GL_PALETTE4_RGB8_OES
:
3046 case GL_PALETTE4_RGBA8_OES
:
3047 case GL_PALETTE4_R5_G6_B5_OES
:
3048 case GL_PALETTE4_RGBA4_OES
:
3049 case GL_PALETTE4_RGB5_A1_OES
:
3050 case GL_PALETTE8_RGB8_OES
:
3051 case GL_PALETTE8_RGBA8_OES
:
3052 case GL_PALETTE8_R5_G6_B5_OES
:
3053 case GL_PALETTE8_RGBA4_OES
:
3054 case GL_PALETTE8_RGB5_A1_OES
:
3055 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3056 width
, height
, imageSize
, pixels
);
3061 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3065 /* For glCompressedTexImage() the driver has no choice about the
3066 * texture format since we'll never transcode the user's compressed
3067 * image data. The internalFormat was error checked earlier.
3069 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3072 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3073 internalFormat
, format
, type
);
3076 assert(texFormat
!= MESA_FORMAT_NONE
);
3078 /* check that width, height, depth are legal for the mipmap level */
3079 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3080 height
, depth
, border
);
3082 /* check that the texture won't take too much memory, etc */
3083 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3085 width
, height
, depth
, border
);
3087 if (_mesa_is_proxy_texture(target
)) {
3088 /* Proxy texture: just clear or set state depending on error checking */
3089 struct gl_texture_image
*texImage
=
3090 get_proxy_tex_image(ctx
, target
, level
);
3093 return; /* GL_OUT_OF_MEMORY already recorded */
3095 if (dimensionsOK
&& sizeOK
) {
3096 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3097 border
, internalFormat
, texFormat
);
3100 clear_teximage_fields(texImage
);
3104 /* non-proxy target */
3105 const GLuint face
= _mesa_tex_target_to_face(target
);
3106 struct gl_texture_image
*texImage
;
3108 if (!dimensionsOK
) {
3109 _mesa_error(ctx
, GL_INVALID_VALUE
,
3110 "glTexImage%uD(invalid width or height or depth)",
3116 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3117 "glTexImage%uD(image too large)", dims
);
3121 /* Allow a hardware driver to just strip out the border, to provide
3122 * reliable but slightly incorrect hardware rendering instead of
3123 * rarely-tested software fallback rendering.
3125 if (border
&& ctx
->Const
.StripTextureBorder
) {
3126 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3129 unpack
= &unpack_no_border
;
3132 if (ctx
->NewState
& _NEW_PIXEL
)
3133 _mesa_update_state(ctx
);
3135 _mesa_lock_texture(ctx
, texObj
);
3137 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3140 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3143 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3145 _mesa_init_teximage_fields(ctx
, texImage
,
3146 width
, height
, depth
,
3147 border
, internalFormat
, texFormat
);
3149 /* Give the texture to the driver. <pixels> may be null. */
3150 if (width
> 0 && height
> 0 && depth
> 0) {
3152 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3156 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3157 type
, pixels
, unpack
);
3161 check_gen_mipmap(ctx
, target
, texObj
, level
);
3163 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3165 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3168 _mesa_unlock_texture(ctx
, texObj
);
3175 * Called from the API. Note that width includes the border.
3178 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3179 GLsizei width
, GLint border
, GLenum format
,
3180 GLenum type
, const GLvoid
*pixels
)
3182 GET_CURRENT_CONTEXT(ctx
);
3183 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3184 border
, format
, type
, 0, pixels
);
3189 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3190 GLsizei width
, GLsizei height
, GLint border
,
3191 GLenum format
, GLenum type
,
3192 const GLvoid
*pixels
)
3194 GET_CURRENT_CONTEXT(ctx
);
3195 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3196 border
, format
, type
, 0, pixels
);
3201 * Called by the API or display list executor.
3202 * Note that width and height include the border.
3205 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3206 GLsizei width
, GLsizei height
, GLsizei depth
,
3207 GLint border
, GLenum format
, GLenum type
,
3208 const GLvoid
*pixels
)
3210 GET_CURRENT_CONTEXT(ctx
);
3211 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3212 width
, height
, depth
,
3213 border
, format
, type
, 0, pixels
);
3218 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3219 GLsizei width
, GLsizei height
, GLsizei depth
,
3220 GLint border
, GLenum format
, GLenum type
,
3221 const GLvoid
*pixels
)
3223 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3224 depth
, border
, format
, type
, pixels
);
3229 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3231 struct gl_texture_object
*texObj
;
3232 struct gl_texture_image
*texImage
;
3234 GET_CURRENT_CONTEXT(ctx
);
3235 FLUSH_VERTICES(ctx
, 0);
3239 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3241 case GL_TEXTURE_EXTERNAL_OES
:
3243 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3246 valid_target
= false;
3250 if (!valid_target
) {
3251 _mesa_error(ctx
, GL_INVALID_ENUM
,
3252 "glEGLImageTargetTexture2D(target=%d)", target
);
3257 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3258 "glEGLImageTargetTexture2D(image=%p)", image
);
3262 if (ctx
->NewState
& _NEW_PIXEL
)
3263 _mesa_update_state(ctx
);
3265 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3266 _mesa_lock_texture(ctx
, texObj
);
3268 if (texObj
->Immutable
) {
3269 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3270 "glEGLImageTargetTexture2D(texture is immutable)");
3271 _mesa_unlock_texture(ctx
, texObj
);
3275 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3277 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3279 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3281 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3282 texObj
, texImage
, image
);
3284 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3286 _mesa_unlock_texture(ctx
, texObj
);
3293 * Implement all the glTexSubImage1/2/3D() functions.
3296 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3297 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3298 GLsizei width
, GLsizei height
, GLsizei depth
,
3299 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3301 struct gl_texture_object
*texObj
;
3302 struct gl_texture_image
*texImage
;
3304 FLUSH_VERTICES(ctx
, 0);
3306 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3307 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3309 _mesa_lookup_enum_by_nr(target
), level
,
3310 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3311 _mesa_lookup_enum_by_nr(format
),
3312 _mesa_lookup_enum_by_nr(type
), pixels
);
3314 /* check target (proxies not allowed) */
3315 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3316 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3317 dims
, _mesa_lookup_enum_by_nr(target
));
3321 if (ctx
->NewState
& _NEW_PIXEL
)
3322 _mesa_update_state(ctx
);
3324 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3325 xoffset
, yoffset
, zoffset
,
3326 width
, height
, depth
, format
, type
)) {
3327 return; /* error was detected */
3330 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3332 _mesa_lock_texture(ctx
, texObj
);
3334 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3336 if (width
> 0 && height
> 0 && depth
> 0) {
3337 /* If we have a border, offset=-1 is legal. Bias by border width. */
3340 if (target
!= GL_TEXTURE_2D_ARRAY
)
3341 zoffset
+= texImage
->Border
;
3344 if (target
!= GL_TEXTURE_1D_ARRAY
)
3345 yoffset
+= texImage
->Border
;
3348 xoffset
+= texImage
->Border
;
3351 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3352 xoffset
, yoffset
, zoffset
,
3353 width
, height
, depth
,
3354 format
, type
, pixels
, &ctx
->Unpack
);
3356 check_gen_mipmap(ctx
, target
, texObj
, level
);
3358 ctx
->NewState
|= _NEW_TEXTURE
;
3361 _mesa_unlock_texture(ctx
, texObj
);
3366 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3367 GLint xoffset
, GLsizei width
,
3368 GLenum format
, GLenum type
,
3369 const GLvoid
*pixels
)
3371 GET_CURRENT_CONTEXT(ctx
);
3372 texsubimage(ctx
, 1, target
, level
,
3375 format
, type
, pixels
);
3380 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3381 GLint xoffset
, GLint yoffset
,
3382 GLsizei width
, GLsizei height
,
3383 GLenum format
, GLenum type
,
3384 const GLvoid
*pixels
)
3386 GET_CURRENT_CONTEXT(ctx
);
3387 texsubimage(ctx
, 2, target
, level
,
3388 xoffset
, yoffset
, 0,
3390 format
, type
, pixels
);
3396 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3397 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3398 GLsizei width
, GLsizei height
, GLsizei depth
,
3399 GLenum format
, GLenum type
,
3400 const GLvoid
*pixels
)
3402 GET_CURRENT_CONTEXT(ctx
);
3403 texsubimage(ctx
, 3, target
, level
,
3404 xoffset
, yoffset
, zoffset
,
3405 width
, height
, depth
,
3406 format
, type
, pixels
);
3412 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3413 * from. This depends on whether the texture contains color or depth values.
3415 static struct gl_renderbuffer
*
3416 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3418 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3419 /* reading from depth/stencil buffer */
3420 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3423 /* copying from color buffer */
3424 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3429 copytexsubimage_by_slice(struct gl_context
*ctx
,
3430 struct gl_texture_image
*texImage
,
3432 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3433 struct gl_renderbuffer
*rb
,
3435 GLsizei width
, GLsizei height
)
3437 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3440 /* For 1D arrays, we copy each scanline of the source rectangle into the
3443 assert(zoffset
== 0);
3445 for (slice
= 0; slice
< height
; slice
++) {
3446 assert(yoffset
+ slice
< texImage
->Height
);
3447 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3448 xoffset
, 0, yoffset
+ slice
,
3449 rb
, x
, y
+ slice
, width
, 1);
3452 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3453 xoffset
, yoffset
, zoffset
,
3454 rb
, x
, y
, width
, height
);
3460 * Implement the glCopyTexImage1/2D() functions.
3463 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3464 GLenum target
, GLint level
, GLenum internalFormat
,
3465 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3467 struct gl_texture_object
*texObj
;
3468 struct gl_texture_image
*texImage
;
3469 const GLuint face
= _mesa_tex_target_to_face(target
);
3470 gl_format texFormat
;
3472 FLUSH_VERTICES(ctx
, 0);
3474 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3475 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3477 _mesa_lookup_enum_by_nr(target
), level
,
3478 _mesa_lookup_enum_by_nr(internalFormat
),
3479 x
, y
, width
, height
, border
);
3481 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3482 _mesa_update_state(ctx
);
3484 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3485 width
, height
, border
))
3488 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3490 _mesa_error(ctx
, GL_INVALID_VALUE
,
3491 "glCopyTexImage%uD(invalid width or height)", dims
);
3495 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3498 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3499 internalFormat
, GL_NONE
, GL_NONE
);
3500 assert(texFormat
!= MESA_FORMAT_NONE
);
3502 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3504 width
, height
, 1, border
)) {
3505 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3506 "glCopyTexImage%uD(image too large)", dims
);
3510 if (border
&& ctx
->Const
.StripTextureBorder
) {
3512 width
-= border
* 2;
3515 height
-= border
* 2;
3520 _mesa_lock_texture(ctx
, texObj
);
3522 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3525 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3528 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3530 /* Free old texture image */
3531 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3533 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3534 border
, internalFormat
, texFormat
);
3536 if (width
&& height
) {
3537 /* Allocate texture memory (no pixel data yet) */
3538 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3540 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3542 struct gl_renderbuffer
*srcRb
=
3543 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3545 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3547 srcRb
, srcX
, srcY
, width
, height
);
3550 check_gen_mipmap(ctx
, target
, texObj
, level
);
3553 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3555 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3558 _mesa_unlock_texture(ctx
, texObj
);
3564 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3565 GLenum internalFormat
,
3567 GLsizei width
, GLint border
)
3569 GET_CURRENT_CONTEXT(ctx
);
3570 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3576 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3577 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3580 GET_CURRENT_CONTEXT(ctx
);
3581 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3582 x
, y
, width
, height
, border
);
3588 * Implementation for glCopyTexSubImage1/2/3D() functions.
3591 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3592 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3593 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3595 struct gl_texture_object
*texObj
;
3596 struct gl_texture_image
*texImage
;
3598 FLUSH_VERTICES(ctx
, 0);
3600 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3601 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3603 _mesa_lookup_enum_by_nr(target
),
3604 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3606 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3607 _mesa_update_state(ctx
);
3609 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3610 xoffset
, yoffset
, zoffset
, width
, height
)) {
3614 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3616 _mesa_lock_texture(ctx
, texObj
);
3618 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3620 /* If we have a border, offset=-1 is legal. Bias by border width. */
3623 if (target
!= GL_TEXTURE_2D_ARRAY
)
3624 zoffset
+= texImage
->Border
;
3627 if (target
!= GL_TEXTURE_1D_ARRAY
)
3628 yoffset
+= texImage
->Border
;
3631 xoffset
+= texImage
->Border
;
3634 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3636 struct gl_renderbuffer
*srcRb
=
3637 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3639 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3640 xoffset
, yoffset
, zoffset
,
3641 srcRb
, x
, y
, width
, height
);
3643 check_gen_mipmap(ctx
, target
, texObj
, level
);
3645 ctx
->NewState
|= _NEW_TEXTURE
;
3648 _mesa_unlock_texture(ctx
, texObj
);
3653 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3654 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3656 GET_CURRENT_CONTEXT(ctx
);
3657 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3663 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3664 GLint xoffset
, GLint yoffset
,
3665 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3667 GET_CURRENT_CONTEXT(ctx
);
3668 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3675 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3676 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3677 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3679 GET_CURRENT_CONTEXT(ctx
);
3680 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3681 x
, y
, width
, height
);
3687 /**********************************************************************/
3688 /****** Compressed Textures ******/
3689 /**********************************************************************/
3693 * Error checking for glCompressedTexSubImage[123]D().
3694 * \return error code or GL_NO_ERROR.
3697 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3698 GLenum target
, GLint level
,
3699 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3700 GLsizei width
, GLsizei height
, GLsizei depth
,
3701 GLenum format
, GLsizei imageSize
)
3703 struct gl_texture_object
*texObj
;
3704 struct gl_texture_image
*texImage
;
3712 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3713 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3714 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3715 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3716 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3717 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3721 targetOK
= GL_FALSE
;
3726 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3730 /* no 1D compressed textures at this time */
3731 targetOK
= GL_FALSE
;
3736 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3741 /* this will catch any invalid compressed format token */
3742 if (!_mesa_is_compressed_format(ctx
, format
)) {
3743 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3748 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3749 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3754 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3755 if (expectedSize
!= imageSize
) {
3756 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3761 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3763 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3764 "glCompressedTexSubImage%uD()", dims
);
3768 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3770 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3771 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3775 if ((GLint
) format
!= texImage
->InternalFormat
) {
3776 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3777 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3781 if (compressedteximage_only_format(ctx
, format
)) {
3782 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3783 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3788 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3789 texImage
, xoffset
, yoffset
, zoffset
,
3790 width
, height
, depth
)) {
3799 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3800 GLenum internalFormat
, GLsizei width
,
3801 GLint border
, GLsizei imageSize
,
3804 GET_CURRENT_CONTEXT(ctx
);
3805 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3806 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3811 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3812 GLenum internalFormat
, GLsizei width
,
3813 GLsizei height
, GLint border
, GLsizei imageSize
,
3816 GET_CURRENT_CONTEXT(ctx
);
3817 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3818 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3823 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3824 GLenum internalFormat
, GLsizei width
,
3825 GLsizei height
, GLsizei depth
, GLint border
,
3826 GLsizei imageSize
, const GLvoid
*data
)
3828 GET_CURRENT_CONTEXT(ctx
);
3829 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3830 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3835 * Common helper for glCompressedTexSubImage1/2/3D().
3838 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3839 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3840 GLsizei width
, GLsizei height
, GLsizei depth
,
3841 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3843 struct gl_texture_object
*texObj
;
3844 struct gl_texture_image
*texImage
;
3845 GET_CURRENT_CONTEXT(ctx
);
3846 FLUSH_VERTICES(ctx
, 0);
3848 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3849 xoffset
, yoffset
, zoffset
,
3850 width
, height
, depth
,
3851 format
, imageSize
)) {
3855 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3857 _mesa_lock_texture(ctx
, texObj
);
3859 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3862 if (width
> 0 && height
> 0 && depth
> 0) {
3863 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3864 xoffset
, yoffset
, zoffset
,
3865 width
, height
, depth
,
3866 format
, imageSize
, data
);
3868 check_gen_mipmap(ctx
, target
, texObj
, level
);
3870 ctx
->NewState
|= _NEW_TEXTURE
;
3873 _mesa_unlock_texture(ctx
, texObj
);
3878 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3879 GLsizei width
, GLenum format
,
3880 GLsizei imageSize
, const GLvoid
*data
)
3882 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3883 format
, imageSize
, data
);
3888 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3889 GLint yoffset
, GLsizei width
, GLsizei height
,
3890 GLenum format
, GLsizei imageSize
,
3893 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3894 width
, height
, 1, format
, imageSize
, data
);
3899 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3900 GLint yoffset
, GLint zoffset
, GLsizei width
,
3901 GLsizei height
, GLsizei depth
, GLenum format
,
3902 GLsizei imageSize
, const GLvoid
*data
)
3904 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3905 width
, height
, depth
, format
, imageSize
, data
);
3909 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3911 switch (internalFormat
) {
3913 return MESA_FORMAT_A8
;
3915 return MESA_FORMAT_A16
;
3916 case GL_ALPHA16F_ARB
:
3917 return MESA_FORMAT_ALPHA_FLOAT16
;
3918 case GL_ALPHA32F_ARB
:
3919 return MESA_FORMAT_ALPHA_FLOAT32
;
3920 case GL_ALPHA8I_EXT
:
3921 return MESA_FORMAT_ALPHA_INT8
;
3922 case GL_ALPHA16I_EXT
:
3923 return MESA_FORMAT_ALPHA_INT16
;
3924 case GL_ALPHA32I_EXT
:
3925 return MESA_FORMAT_ALPHA_INT32
;
3926 case GL_ALPHA8UI_EXT
:
3927 return MESA_FORMAT_ALPHA_UINT8
;
3928 case GL_ALPHA16UI_EXT
:
3929 return MESA_FORMAT_ALPHA_UINT16
;
3930 case GL_ALPHA32UI_EXT
:
3931 return MESA_FORMAT_ALPHA_UINT32
;
3933 return MESA_FORMAT_L8
;
3934 case GL_LUMINANCE16
:
3935 return MESA_FORMAT_L16
;
3936 case GL_LUMINANCE16F_ARB
:
3937 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3938 case GL_LUMINANCE32F_ARB
:
3939 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3940 case GL_LUMINANCE8I_EXT
:
3941 return MESA_FORMAT_LUMINANCE_INT8
;
3942 case GL_LUMINANCE16I_EXT
:
3943 return MESA_FORMAT_LUMINANCE_INT16
;
3944 case GL_LUMINANCE32I_EXT
:
3945 return MESA_FORMAT_LUMINANCE_INT32
;
3946 case GL_LUMINANCE8UI_EXT
:
3947 return MESA_FORMAT_LUMINANCE_UINT8
;
3948 case GL_LUMINANCE16UI_EXT
:
3949 return MESA_FORMAT_LUMINANCE_UINT16
;
3950 case GL_LUMINANCE32UI_EXT
:
3951 return MESA_FORMAT_LUMINANCE_UINT32
;
3952 case GL_LUMINANCE8_ALPHA8
:
3953 return MESA_FORMAT_AL88
;
3954 case GL_LUMINANCE16_ALPHA16
:
3955 return MESA_FORMAT_AL1616
;
3956 case GL_LUMINANCE_ALPHA16F_ARB
:
3957 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3958 case GL_LUMINANCE_ALPHA32F_ARB
:
3959 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3960 case GL_LUMINANCE_ALPHA8I_EXT
:
3961 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3962 case GL_LUMINANCE_ALPHA16I_EXT
:
3963 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3964 case GL_LUMINANCE_ALPHA32I_EXT
:
3965 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3966 case GL_LUMINANCE_ALPHA8UI_EXT
:
3967 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3968 case GL_LUMINANCE_ALPHA16UI_EXT
:
3969 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3970 case GL_LUMINANCE_ALPHA32UI_EXT
:
3971 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3973 return MESA_FORMAT_I8
;
3974 case GL_INTENSITY16
:
3975 return MESA_FORMAT_I16
;
3976 case GL_INTENSITY16F_ARB
:
3977 return MESA_FORMAT_INTENSITY_FLOAT16
;
3978 case GL_INTENSITY32F_ARB
:
3979 return MESA_FORMAT_INTENSITY_FLOAT32
;
3980 case GL_INTENSITY8I_EXT
:
3981 return MESA_FORMAT_INTENSITY_INT8
;
3982 case GL_INTENSITY16I_EXT
:
3983 return MESA_FORMAT_INTENSITY_INT16
;
3984 case GL_INTENSITY32I_EXT
:
3985 return MESA_FORMAT_INTENSITY_INT32
;
3986 case GL_INTENSITY8UI_EXT
:
3987 return MESA_FORMAT_INTENSITY_UINT8
;
3988 case GL_INTENSITY16UI_EXT
:
3989 return MESA_FORMAT_INTENSITY_UINT16
;
3990 case GL_INTENSITY32UI_EXT
:
3991 return MESA_FORMAT_INTENSITY_UINT32
;
3993 return MESA_FORMAT_RGBA8888_REV
;
3995 return MESA_FORMAT_RGBA_16
;
3996 case GL_RGBA16F_ARB
:
3997 return MESA_FORMAT_RGBA_FLOAT16
;
3998 case GL_RGBA32F_ARB
:
3999 return MESA_FORMAT_RGBA_FLOAT32
;
4001 return MESA_FORMAT_RGBA_INT8
;
4002 case GL_RGBA16I_EXT
:
4003 return MESA_FORMAT_RGBA_INT16
;
4004 case GL_RGBA32I_EXT
:
4005 return MESA_FORMAT_RGBA_INT32
;
4006 case GL_RGBA8UI_EXT
:
4007 return MESA_FORMAT_RGBA_UINT8
;
4008 case GL_RGBA16UI_EXT
:
4009 return MESA_FORMAT_RGBA_UINT16
;
4010 case GL_RGBA32UI_EXT
:
4011 return MESA_FORMAT_RGBA_UINT32
;
4014 return MESA_FORMAT_GR88
;
4016 return MESA_FORMAT_GR1616
;
4018 return MESA_FORMAT_RG_FLOAT16
;
4020 return MESA_FORMAT_RG_FLOAT32
;
4022 return MESA_FORMAT_RG_INT8
;
4024 return MESA_FORMAT_RG_INT16
;
4026 return MESA_FORMAT_RG_INT32
;
4028 return MESA_FORMAT_RG_UINT8
;
4030 return MESA_FORMAT_RG_UINT16
;
4032 return MESA_FORMAT_RG_UINT32
;
4035 return MESA_FORMAT_R8
;
4037 return MESA_FORMAT_R16
;
4039 return MESA_FORMAT_R_FLOAT16
;
4041 return MESA_FORMAT_R_FLOAT32
;
4043 return MESA_FORMAT_R_INT8
;
4045 return MESA_FORMAT_R_INT16
;
4047 return MESA_FORMAT_R_INT32
;
4049 return MESA_FORMAT_R_UINT8
;
4051 return MESA_FORMAT_R_UINT16
;
4053 return MESA_FORMAT_R_UINT32
;
4056 return MESA_FORMAT_RGB_FLOAT32
;
4058 return MESA_FORMAT_RGB_UINT32
;
4060 return MESA_FORMAT_RGB_INT32
;
4063 return MESA_FORMAT_NONE
;
4069 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4071 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4074 if (format
== MESA_FORMAT_NONE
)
4075 return MESA_FORMAT_NONE
;
4077 datatype
= _mesa_get_format_datatype(format
);
4078 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4079 return MESA_FORMAT_NONE
;
4081 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4082 return MESA_FORMAT_NONE
;
4084 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
4085 * any mention of R/RG formats, but they appear in the GL 3.1 core
4088 if (ctx
->Version
<= 30) {
4089 GLenum base_format
= _mesa_get_format_base_format(format
);
4091 if (base_format
== GL_R
|| base_format
== GL_RG
)
4092 return MESA_FORMAT_NONE
;
4095 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4096 GLenum base_format
= _mesa_get_format_base_format(format
);
4097 if (base_format
== GL_RGB
)
4098 return MESA_FORMAT_NONE
;
4105 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4106 struct gl_buffer_object
*bufObj
,
4107 GLintptr offset
, GLsizeiptr size
)
4109 struct gl_texture_object
*texObj
;
4112 FLUSH_VERTICES(ctx
, 0);
4114 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4115 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4119 format
= validate_texbuffer_format(ctx
, internalFormat
);
4120 if (format
== MESA_FORMAT_NONE
) {
4121 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4126 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4128 _mesa_lock_texture(ctx
, texObj
);
4130 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4131 texObj
->BufferObjectFormat
= internalFormat
;
4132 texObj
->_BufferObjectFormat
= format
;
4133 texObj
->BufferOffset
= offset
;
4134 texObj
->BufferSize
= size
;
4136 _mesa_unlock_texture(ctx
, texObj
);
4140 /** GL_ARB_texture_buffer_object */
4142 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4144 struct gl_buffer_object
*bufObj
;
4146 GET_CURRENT_CONTEXT(ctx
);
4148 /* NOTE: ARB_texture_buffer_object has interactions with
4149 * the compatibility profile that are not implemented.
4151 if (!(ctx
->API
== API_OPENGL_CORE
&&
4152 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4153 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4157 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4158 if (!bufObj
&& buffer
) {
4159 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4163 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4167 /** GL_ARB_texture_buffer_range */
4169 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4170 GLintptr offset
, GLsizeiptr size
)
4172 struct gl_buffer_object
*bufObj
;
4174 GET_CURRENT_CONTEXT(ctx
);
4176 if (!(ctx
->API
== API_OPENGL_CORE
&&
4177 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4178 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4182 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4186 (offset
+ size
) > bufObj
->Size
) {
4187 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4190 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4191 _mesa_error(ctx
, GL_INVALID_VALUE
,
4192 "glTexBufferRange(invalid offset alignment)");
4195 } else if (buffer
) {
4196 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4204 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4209 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4211 /* Everything that is allowed for renderbuffers,
4212 * except for a base format of GL_STENCIL_INDEX.
4214 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4215 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4219 /** GL_ARB_texture_multisample */
4221 check_multisample_target(GLuint dims
, GLenum target
)
4224 case GL_TEXTURE_2D_MULTISAMPLE
:
4225 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4228 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4229 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4239 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4240 GLint internalformat
, GLsizei width
, GLsizei height
,
4241 GLsizei depth
, GLboolean fixedsamplelocations
,
4242 GLboolean immutable
, const char *func
)
4244 struct gl_texture_object
*texObj
;
4245 struct gl_texture_image
*texImage
;
4246 GLboolean sizeOK
, dimensionsOK
;
4247 gl_format texFormat
;
4248 GLenum sample_count_error
;
4250 GET_CURRENT_CONTEXT(ctx
);
4252 if (!(ctx
->Extensions
.ARB_texture_multisample
4253 && _mesa_is_desktop_gl(ctx
))) {
4254 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4258 if (!check_multisample_target(dims
, target
)) {
4259 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4263 /* check that the specified internalformat is color/depth/stencil-renderable;
4264 * refer GL3.1 spec 4.4.4
4267 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4268 _mesa_error(ctx
, GL_INVALID_ENUM
,
4269 "%s(internalformat=%s not legal for immutable-format)",
4270 func
, _mesa_lookup_enum_by_nr(internalformat
));
4274 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4275 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4276 "%s(internalformat=%s)",
4277 func
, _mesa_lookup_enum_by_nr(internalformat
));
4281 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4282 internalformat
, samples
);
4283 if (sample_count_error
!= GL_NO_ERROR
) {
4284 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4288 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4290 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4291 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4292 "%s(texture object 0)",
4297 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4299 if (texImage
== NULL
) {
4300 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4304 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4305 internalformat
, GL_NONE
, GL_NONE
);
4306 assert(texFormat
!= MESA_FORMAT_NONE
);
4308 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4309 width
, height
, depth
, 0);
4311 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4312 width
, height
, depth
, 0);
4314 if (_mesa_is_proxy_texture(target
)) {
4315 if (dimensionsOK
&& sizeOK
) {
4316 _mesa_init_teximage_fields(ctx
, texImage
,
4317 width
, height
, depth
, 0, internalformat
, texFormat
);
4318 texImage
->NumSamples
= samples
;
4319 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4322 /* clear all image fields */
4323 _mesa_init_teximage_fields(ctx
, texImage
,
4324 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4328 if (!dimensionsOK
) {
4329 _mesa_error(ctx
, GL_INVALID_VALUE
,
4330 "%s(invalid width or height)", func
);
4335 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4336 "%s(texture too large)", func
);
4340 /* Check if texObj->Immutable is set */
4341 if (texObj
->Immutable
) {
4342 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4346 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4348 _mesa_init_teximage_fields(ctx
, texImage
,
4349 width
, height
, depth
, 0, internalformat
, texFormat
);
4351 texImage
->NumSamples
= samples
;
4352 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4354 if (width
> 0 && height
> 0 && depth
> 0) {
4355 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4356 width
, height
, depth
)) {
4357 /* tidy up the texture image state. strictly speaking,
4358 * we're allowed to just leave this in whatever state we
4359 * like, but being tidy is good.
4361 _mesa_init_teximage_fields(ctx
, texImage
,
4362 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4366 texObj
->Immutable
= immutable
;
4367 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4373 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4374 GLint internalformat
, GLsizei width
,
4375 GLsizei height
, GLboolean fixedsamplelocations
)
4377 teximagemultisample(2, target
, samples
, internalformat
,
4378 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4379 "glTexImage2DMultisample");
4384 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4385 GLint internalformat
, GLsizei width
,
4386 GLsizei height
, GLsizei depth
,
4387 GLboolean fixedsamplelocations
)
4389 teximagemultisample(3, target
, samples
, internalformat
,
4390 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4391 "glTexImage3DMultisample");
4396 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4397 GLenum internalformat
, GLsizei width
,
4398 GLsizei height
, GLboolean fixedsamplelocations
)
4400 teximagemultisample(2, target
, samples
, internalformat
,
4401 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4402 "glTexStorage2DMultisample");
4407 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4408 GLenum internalformat
, GLsizei width
,
4409 GLsizei height
, GLsizei depth
,
4410 GLboolean fixedsamplelocations
)
4412 teximagemultisample(3, target
, samples
, internalformat
,
4413 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4414 "glTexStorage3DMultisample");