2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * Texture image-related functions.
33 #include "bufferobj.h"
37 #include "framebuffer.h"
42 #include "multisample.h"
44 #include "texcompress.h"
45 #include "texcompress_cpal.h"
49 #include "texstorage.h"
51 #include "glformats.h"
55 * State changes which we care about for glCopyTex[Sub]Image() calls.
56 * In particular, we care about pixel transfer state and buffer state
57 * (such as glReadBuffer to make sure we read from the right renderbuffer).
59 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
64 * Return the simple base format for a given internal texture format.
65 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
67 * \param ctx GL context.
68 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
70 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
71 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
73 * This is the format which is used during texture application (i.e. the
74 * texture format and env mode determine the arithmetic used.
77 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
79 switch (internalFormat
) {
85 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
92 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
94 case GL_LUMINANCE_ALPHA
:
95 case GL_LUMINANCE4_ALPHA4
:
96 case GL_LUMINANCE6_ALPHA2
:
97 case GL_LUMINANCE8_ALPHA8
:
98 case GL_LUMINANCE12_ALPHA4
:
99 case GL_LUMINANCE12_ALPHA12
:
100 case GL_LUMINANCE16_ALPHA16
:
101 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
107 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
109 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
120 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
134 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
136 if (_mesa_is_gles(ctx
)) {
137 switch (internalFormat
) {
145 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
146 switch (internalFormat
) {
154 if (ctx
->Extensions
.ARB_depth_texture
) {
155 switch (internalFormat
) {
156 case GL_DEPTH_COMPONENT
:
157 case GL_DEPTH_COMPONENT16
:
158 case GL_DEPTH_COMPONENT24
:
159 case GL_DEPTH_COMPONENT32
:
160 return GL_DEPTH_COMPONENT
;
166 switch (internalFormat
) {
167 case GL_COMPRESSED_ALPHA
:
169 case GL_COMPRESSED_LUMINANCE
:
171 case GL_COMPRESSED_LUMINANCE_ALPHA
:
172 return GL_LUMINANCE_ALPHA
;
173 case GL_COMPRESSED_INTENSITY
:
175 case GL_COMPRESSED_RGB
:
177 case GL_COMPRESSED_RGBA
:
183 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
184 switch (internalFormat
) {
185 case GL_COMPRESSED_RGB_FXT1_3DFX
:
187 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
194 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
196 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
197 switch (internalFormat
) {
198 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
200 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
201 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
202 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
209 if (_mesa_is_desktop_gl(ctx
)
210 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
211 switch (internalFormat
) {
223 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
224 if (internalFormat
== GL_YCBCR_MESA
)
225 return GL_YCBCR_MESA
;
228 if (ctx
->Extensions
.ARB_texture_float
) {
229 switch (internalFormat
) {
230 case GL_ALPHA16F_ARB
:
231 case GL_ALPHA32F_ARB
:
239 case GL_INTENSITY16F_ARB
:
240 case GL_INTENSITY32F_ARB
:
242 case GL_LUMINANCE16F_ARB
:
243 case GL_LUMINANCE32F_ARB
:
245 case GL_LUMINANCE_ALPHA16F_ARB
:
246 case GL_LUMINANCE_ALPHA32F_ARB
:
247 return GL_LUMINANCE_ALPHA
;
253 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
254 switch (internalFormat
) {
263 if (ctx
->Extensions
.EXT_texture_snorm
) {
264 switch (internalFormat
) {
279 case GL_RGBA16_SNORM
:
282 case GL_ALPHA8_SNORM
:
283 case GL_ALPHA16_SNORM
:
285 case GL_LUMINANCE_SNORM
:
286 case GL_LUMINANCE8_SNORM
:
287 case GL_LUMINANCE16_SNORM
:
289 case GL_LUMINANCE_ALPHA_SNORM
:
290 case GL_LUMINANCE8_ALPHA8_SNORM
:
291 case GL_LUMINANCE16_ALPHA16_SNORM
:
292 return GL_LUMINANCE_ALPHA
;
293 case GL_INTENSITY_SNORM
:
294 case GL_INTENSITY8_SNORM
:
295 case GL_INTENSITY16_SNORM
:
302 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
303 switch (internalFormat
) {
304 case GL_DEPTH_STENCIL_EXT
:
305 case GL_DEPTH24_STENCIL8_EXT
:
306 return GL_DEPTH_STENCIL_EXT
;
312 if (ctx
->Extensions
.EXT_texture_sRGB
) {
313 switch (internalFormat
) {
316 case GL_COMPRESSED_SRGB_EXT
:
317 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
319 case GL_SRGB_ALPHA_EXT
:
320 case GL_SRGB8_ALPHA8_EXT
:
321 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
322 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
323 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
324 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
326 case GL_SLUMINANCE_ALPHA_EXT
:
327 case GL_SLUMINANCE8_ALPHA8_EXT
:
328 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
329 return GL_LUMINANCE_ALPHA
;
330 case GL_SLUMINANCE_EXT
:
331 case GL_SLUMINANCE8_EXT
:
332 case GL_COMPRESSED_SLUMINANCE_EXT
:
339 if (ctx
->Version
>= 30 ||
340 ctx
->Extensions
.EXT_texture_integer
) {
341 switch (internalFormat
) {
343 case GL_RGBA16UI_EXT
:
344 case GL_RGBA32UI_EXT
:
360 if (ctx
->Extensions
.EXT_texture_integer
) {
361 switch (internalFormat
) {
362 case GL_ALPHA8UI_EXT
:
363 case GL_ALPHA16UI_EXT
:
364 case GL_ALPHA32UI_EXT
:
366 case GL_ALPHA16I_EXT
:
367 case GL_ALPHA32I_EXT
:
369 case GL_INTENSITY8UI_EXT
:
370 case GL_INTENSITY16UI_EXT
:
371 case GL_INTENSITY32UI_EXT
:
372 case GL_INTENSITY8I_EXT
:
373 case GL_INTENSITY16I_EXT
:
374 case GL_INTENSITY32I_EXT
:
376 case GL_LUMINANCE8UI_EXT
:
377 case GL_LUMINANCE16UI_EXT
:
378 case GL_LUMINANCE32UI_EXT
:
379 case GL_LUMINANCE8I_EXT
:
380 case GL_LUMINANCE16I_EXT
:
381 case GL_LUMINANCE32I_EXT
:
383 case GL_LUMINANCE_ALPHA8UI_EXT
:
384 case GL_LUMINANCE_ALPHA16UI_EXT
:
385 case GL_LUMINANCE_ALPHA32UI_EXT
:
386 case GL_LUMINANCE_ALPHA8I_EXT
:
387 case GL_LUMINANCE_ALPHA16I_EXT
:
388 case GL_LUMINANCE_ALPHA32I_EXT
:
389 return GL_LUMINANCE_ALPHA
;
395 if (ctx
->Extensions
.ARB_texture_rg
) {
396 switch (internalFormat
) {
398 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
400 if (!ctx
->Extensions
.ARB_half_float_pixel
)
404 if (!ctx
->Extensions
.ARB_texture_float
)
413 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
419 case GL_COMPRESSED_RED
:
423 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
425 if (!ctx
->Extensions
.ARB_half_float_pixel
)
429 if (!ctx
->Extensions
.ARB_texture_float
)
438 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
444 case GL_COMPRESSED_RG
:
451 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
452 switch (internalFormat
) {
460 if (ctx
->Extensions
.EXT_packed_float
) {
461 switch (internalFormat
) {
462 case GL_R11F_G11F_B10F_EXT
:
469 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
470 switch (internalFormat
) {
471 case GL_DEPTH_COMPONENT32F
:
472 return GL_DEPTH_COMPONENT
;
473 case GL_DEPTH32F_STENCIL8
:
474 return GL_DEPTH_STENCIL
;
480 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
481 switch (internalFormat
) {
482 case GL_COMPRESSED_RED_RGTC1
:
483 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
485 case GL_COMPRESSED_RG_RGTC2
:
486 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
493 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
494 switch (internalFormat
) {
495 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
496 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
498 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
499 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
500 return GL_LUMINANCE_ALPHA
;
506 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
507 switch (internalFormat
) {
508 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
509 return GL_LUMINANCE_ALPHA
;
515 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
516 switch (internalFormat
) {
517 case GL_ETC1_RGB8_OES
:
524 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
525 switch (internalFormat
) {
526 case GL_COMPRESSED_RGB8_ETC2
:
527 case GL_COMPRESSED_SRGB8_ETC2
:
529 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
530 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
531 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
532 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
534 case GL_COMPRESSED_R11_EAC
:
535 case GL_COMPRESSED_SIGNED_R11_EAC
:
537 case GL_COMPRESSED_RG11_EAC
:
538 case GL_COMPRESSED_SIGNED_RG11_EAC
:
545 if (ctx
->API
== API_OPENGLES
) {
546 switch (internalFormat
) {
547 case GL_PALETTE4_RGB8_OES
:
548 case GL_PALETTE4_R5_G6_B5_OES
:
549 case GL_PALETTE8_RGB8_OES
:
550 case GL_PALETTE8_R5_G6_B5_OES
:
552 case GL_PALETTE4_RGBA8_OES
:
553 case GL_PALETTE8_RGB5_A1_OES
:
554 case GL_PALETTE4_RGBA4_OES
:
555 case GL_PALETTE4_RGB5_A1_OES
:
556 case GL_PALETTE8_RGBA8_OES
:
557 case GL_PALETTE8_RGBA4_OES
:
564 return -1; /* error */
569 * For cube map faces, return a face index in [0,5].
570 * For other targets return 0;
573 _mesa_tex_target_to_face(GLenum target
)
575 if (_mesa_is_cube_face(target
))
576 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
584 * Install gl_texture_image in a gl_texture_object according to the target
585 * and level parameters.
587 * \param tObj texture object.
588 * \param target texture target.
589 * \param level image level.
590 * \param texImage texture image.
593 set_tex_image(struct gl_texture_object
*tObj
,
594 GLenum target
, GLint level
,
595 struct gl_texture_image
*texImage
)
597 const GLuint face
= _mesa_tex_target_to_face(target
);
601 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
604 tObj
->Image
[face
][level
] = texImage
;
606 /* Set the 'back' pointer */
607 texImage
->TexObject
= tObj
;
608 texImage
->Level
= level
;
609 texImage
->Face
= face
;
614 * Allocate a texture image structure.
616 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
619 * \return a pointer to gl_texture_image struct with all fields initialized to
622 struct gl_texture_image
*
623 _mesa_new_texture_image( struct gl_context
*ctx
)
626 return CALLOC_STRUCT(gl_texture_image
);
631 * Free a gl_texture_image and associated data.
632 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
634 * \param texImage texture image.
636 * Free the texture image structure and the associated image data.
639 _mesa_delete_texture_image(struct gl_context
*ctx
,
640 struct gl_texture_image
*texImage
)
642 /* Free texImage->Data and/or any other driver-specific texture
645 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
646 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
652 * Test if a target is a proxy target.
654 * \param target texture target.
656 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
659 _mesa_is_proxy_texture(GLenum target
)
662 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
663 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
665 assert(NUM_TEXTURE_TARGETS
== 10 + 2);
667 return (target
== GL_PROXY_TEXTURE_1D
||
668 target
== GL_PROXY_TEXTURE_2D
||
669 target
== GL_PROXY_TEXTURE_3D
||
670 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
671 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
672 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
673 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
674 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
675 target
== GL_PROXY_TEXTURE_2D_MULTISAMPLE
||
676 target
== GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
);
681 * Return the proxy target which corresponds to the given texture target
684 _mesa_get_proxy_target(GLenum target
)
688 case GL_PROXY_TEXTURE_1D
:
689 return GL_PROXY_TEXTURE_1D
;
691 case GL_PROXY_TEXTURE_2D
:
692 return GL_PROXY_TEXTURE_2D
;
694 case GL_PROXY_TEXTURE_3D
:
695 return GL_PROXY_TEXTURE_3D
;
696 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
697 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
698 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
699 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
700 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
701 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
702 case GL_TEXTURE_CUBE_MAP_ARB
:
703 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
704 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
705 case GL_TEXTURE_RECTANGLE_NV
:
706 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
707 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
708 case GL_TEXTURE_1D_ARRAY_EXT
:
709 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
710 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
711 case GL_TEXTURE_2D_ARRAY_EXT
:
712 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
713 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
714 case GL_TEXTURE_CUBE_MAP_ARRAY
:
715 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
716 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
717 case GL_TEXTURE_2D_MULTISAMPLE
:
718 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
719 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
720 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
721 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
722 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
724 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
731 * Get the texture object that corresponds to the target of the given
732 * texture unit. The target should have already been checked for validity.
734 * \param ctx GL context.
735 * \param texUnit texture unit.
736 * \param target texture target.
738 * \return pointer to the texture object on success, or NULL on failure.
740 struct gl_texture_object
*
741 _mesa_select_tex_object(struct gl_context
*ctx
,
742 const struct gl_texture_unit
*texUnit
,
745 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
746 ctx
->Extensions
.EXT_texture_array
);
750 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
751 case GL_PROXY_TEXTURE_1D
:
752 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
754 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
755 case GL_PROXY_TEXTURE_2D
:
756 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
758 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
759 case GL_PROXY_TEXTURE_3D
:
760 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
761 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
762 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
763 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
764 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
765 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
766 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
767 case GL_TEXTURE_CUBE_MAP_ARB
:
768 return ctx
->Extensions
.ARB_texture_cube_map
769 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
770 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
771 return ctx
->Extensions
.ARB_texture_cube_map
772 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
773 case GL_TEXTURE_CUBE_MAP_ARRAY
:
774 return ctx
->Extensions
.ARB_texture_cube_map_array
775 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
776 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
777 return ctx
->Extensions
.ARB_texture_cube_map_array
778 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
779 case GL_TEXTURE_RECTANGLE_NV
:
780 return ctx
->Extensions
.NV_texture_rectangle
781 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
782 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
783 return ctx
->Extensions
.NV_texture_rectangle
784 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
785 case GL_TEXTURE_1D_ARRAY_EXT
:
786 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
787 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
788 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
789 case GL_TEXTURE_2D_ARRAY_EXT
:
790 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
791 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
792 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
793 case GL_TEXTURE_BUFFER
:
794 return ctx
->API
== API_OPENGL_CORE
&&
795 ctx
->Extensions
.ARB_texture_buffer_object
?
796 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
797 case GL_TEXTURE_EXTERNAL_OES
:
798 return ctx
->Extensions
.OES_EGL_image_external
799 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
800 case GL_TEXTURE_2D_MULTISAMPLE
:
801 return ctx
->Extensions
.ARB_texture_multisample
802 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
803 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
804 return ctx
->Extensions
.ARB_texture_multisample
805 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
806 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
807 return ctx
->Extensions
.ARB_texture_multisample
808 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
809 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
810 return ctx
->Extensions
.ARB_texture_multisample
811 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
813 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
820 * Return pointer to texture object for given target on current texture unit.
822 struct gl_texture_object
*
823 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
825 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
826 return _mesa_select_tex_object(ctx
, texUnit
, target
);
831 * Get a texture image pointer from a texture object, given a texture
832 * target and mipmap level. The target and level parameters should
833 * have already been error-checked.
835 * \param ctx GL context.
836 * \param texObj texture unit.
837 * \param target texture target.
838 * \param level image level.
840 * \return pointer to the texture image structure, or NULL on failure.
842 struct gl_texture_image
*
843 _mesa_select_tex_image(struct gl_context
*ctx
,
844 const struct gl_texture_object
*texObj
,
845 GLenum target
, GLint level
)
847 const GLuint face
= _mesa_tex_target_to_face(target
);
851 ASSERT(level
< MAX_TEXTURE_LEVELS
);
853 return texObj
->Image
[face
][level
];
858 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
859 * it and install it. Only return NULL if passed a bad parameter or run
862 struct gl_texture_image
*
863 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
864 GLenum target
, GLint level
)
866 struct gl_texture_image
*texImage
;
871 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
873 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
875 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
879 set_tex_image(texObj
, target
, level
, texImage
);
887 * Return pointer to the specified proxy texture image.
888 * Note that proxy textures are per-context, not per-texture unit.
889 * \return pointer to texture image or NULL if invalid target, invalid
890 * level, or out of memory.
892 static struct gl_texture_image
*
893 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
895 struct gl_texture_image
*texImage
;
902 case GL_PROXY_TEXTURE_1D
:
903 if (level
>= ctx
->Const
.MaxTextureLevels
)
905 texIndex
= TEXTURE_1D_INDEX
;
907 case GL_PROXY_TEXTURE_2D
:
908 if (level
>= ctx
->Const
.MaxTextureLevels
)
910 texIndex
= TEXTURE_2D_INDEX
;
912 case GL_PROXY_TEXTURE_3D
:
913 if (level
>= ctx
->Const
.Max3DTextureLevels
)
915 texIndex
= TEXTURE_3D_INDEX
;
917 case GL_PROXY_TEXTURE_CUBE_MAP
:
918 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
920 texIndex
= TEXTURE_CUBE_INDEX
;
922 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
925 texIndex
= TEXTURE_RECT_INDEX
;
927 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
928 if (level
>= ctx
->Const
.MaxTextureLevels
)
930 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
932 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
933 if (level
>= ctx
->Const
.MaxTextureLevels
)
935 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
937 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
938 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
940 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
942 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
945 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
947 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
950 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
956 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
958 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
960 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
963 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
964 /* Set the 'back' pointer */
965 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
972 * Get the maximum number of allowed mipmap levels.
974 * \param ctx GL context.
975 * \param target texture target.
977 * \return the maximum number of allowed mipmap levels for the given
978 * texture target, or zero if passed a bad target.
983 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
987 case GL_PROXY_TEXTURE_1D
:
989 case GL_PROXY_TEXTURE_2D
:
990 return ctx
->Const
.MaxTextureLevels
;
992 case GL_PROXY_TEXTURE_3D
:
993 return ctx
->Const
.Max3DTextureLevels
;
994 case GL_TEXTURE_CUBE_MAP
:
995 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
996 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
997 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
998 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
999 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1000 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1001 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1002 return ctx
->Extensions
.ARB_texture_cube_map
1003 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1004 case GL_TEXTURE_RECTANGLE_NV
:
1005 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1006 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
1007 case GL_TEXTURE_1D_ARRAY_EXT
:
1008 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1009 case GL_TEXTURE_2D_ARRAY_EXT
:
1010 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1011 return (ctx
->Extensions
.MESA_texture_array
||
1012 ctx
->Extensions
.EXT_texture_array
)
1013 ? ctx
->Const
.MaxTextureLevels
: 0;
1014 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1015 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1016 return ctx
->Extensions
.ARB_texture_cube_map_array
1017 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1018 case GL_TEXTURE_BUFFER
:
1019 return ctx
->API
== API_OPENGL_CORE
&&
1020 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1021 case GL_TEXTURE_2D_MULTISAMPLE
:
1022 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1023 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1024 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1025 return _mesa_is_desktop_gl(ctx
)
1026 && ctx
->Extensions
.ARB_texture_multisample
1028 case GL_TEXTURE_EXTERNAL_OES
:
1031 return 0; /* bad target */
1037 * Return number of dimensions per mipmap level for the given texture target.
1040 _mesa_get_texture_dimensions(GLenum target
)
1044 case GL_PROXY_TEXTURE_1D
:
1047 case GL_TEXTURE_RECTANGLE
:
1048 case GL_TEXTURE_CUBE_MAP
:
1049 case GL_PROXY_TEXTURE_2D
:
1050 case GL_PROXY_TEXTURE_RECTANGLE
:
1051 case GL_PROXY_TEXTURE_CUBE_MAP
:
1052 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1053 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1054 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1055 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1056 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1057 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1058 case GL_TEXTURE_1D_ARRAY
:
1059 case GL_PROXY_TEXTURE_1D_ARRAY
:
1060 case GL_TEXTURE_EXTERNAL_OES
:
1061 case GL_TEXTURE_2D_MULTISAMPLE
:
1062 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1065 case GL_PROXY_TEXTURE_3D
:
1066 case GL_TEXTURE_2D_ARRAY
:
1067 case GL_PROXY_TEXTURE_2D_ARRAY
:
1068 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1069 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1070 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1071 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1073 case GL_TEXTURE_BUFFER
:
1076 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1084 * Return the maximum number of mipmap levels for the given target
1085 * and the dimensions.
1086 * The dimensions are expected not to include the border.
1089 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1096 case GL_TEXTURE_1D_ARRAY
:
1099 case GL_TEXTURE_CUBE_MAP
:
1100 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1101 ASSERT(width
== height
);
1105 case GL_TEXTURE_2D_ARRAY
:
1106 size
= MAX2(width
, height
);
1109 size
= MAX3(width
, height
, depth
);
1111 case GL_TEXTURE_RECTANGLE
:
1112 case GL_TEXTURE_EXTERNAL_OES
:
1113 case GL_TEXTURE_2D_MULTISAMPLE
:
1114 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1121 return _mesa_logbase2(size
) + 1;
1125 #if 000 /* not used anymore */
1127 * glTexImage[123]D can accept a NULL image pointer. In this case we
1128 * create a texture image with unspecified image contents per the OpenGL
1132 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1134 const GLint components
= _mesa_components_in_format(format
);
1135 const GLint numPixels
= width
* height
* depth
;
1136 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1140 * Let's see if anyone finds this. If glTexImage2D() is called with
1141 * a NULL image pointer then load the texture image with something
1142 * interesting instead of leaving it indeterminate.
1145 static const char message
[8][32] = {
1146 " X X XXXXX XXX X ",
1147 " XX XX X X X X X ",
1149 " X X XXXX XXX XXXXX ",
1152 " X X XXXXX XXX X X ",
1156 GLubyte
*imgPtr
= data
;
1158 for (h
= 0; h
< depth
; h
++) {
1159 for (i
= 0; i
< height
; i
++) {
1160 GLint srcRow
= 7 - (i
% 8);
1161 for (j
= 0; j
< width
; j
++) {
1162 GLint srcCol
= j
% 32;
1163 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1164 for (k
= 0; k
< components
; k
++) {
1180 * Set the size and format-related fields of a gl_texture_image struct
1181 * to zero. This is used when a proxy texture test fails.
1184 clear_teximage_fields(struct gl_texture_image
*img
)
1187 img
->_BaseFormat
= 0;
1188 img
->InternalFormat
= 0;
1197 img
->HeightLog2
= 0;
1199 img
->TexFormat
= MESA_FORMAT_NONE
;
1200 img
->NumSamples
= 0;
1201 img
->FixedSampleLocations
= GL_TRUE
;
1206 * Initialize basic fields of the gl_texture_image struct.
1208 * \param ctx GL context.
1209 * \param img texture image structure to be initialized.
1210 * \param width image width.
1211 * \param height image height.
1212 * \param depth image depth.
1213 * \param border image border.
1214 * \param internalFormat internal format.
1215 * \param format the actual hardware format (one of MESA_FORMAT_*)
1217 * Fills in the fields of \p img with the given information.
1218 * Note: width, height and depth include the border.
1221 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1222 struct gl_texture_image
*img
,
1223 GLsizei width
, GLsizei height
, GLsizei depth
,
1224 GLint border
, GLenum internalFormat
,
1230 ASSERT(height
>= 0);
1233 target
= img
->TexObject
->Target
;
1234 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1235 ASSERT(img
->_BaseFormat
> 0);
1236 img
->InternalFormat
= internalFormat
;
1237 img
->Border
= border
;
1239 img
->Height
= height
;
1242 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1243 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1245 img
->NumSamples
= 0;
1246 img
->FixedSampleLocations
= GL_TRUE
;
1250 case GL_TEXTURE_BUFFER
:
1251 case GL_PROXY_TEXTURE_1D
:
1256 img
->HeightLog2
= 0;
1263 case GL_TEXTURE_1D_ARRAY
:
1264 case GL_PROXY_TEXTURE_1D_ARRAY
:
1265 img
->Height2
= height
; /* no border */
1266 img
->HeightLog2
= 0; /* not used */
1274 case GL_TEXTURE_RECTANGLE
:
1275 case GL_TEXTURE_CUBE_MAP
:
1276 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1277 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1278 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1279 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1280 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1281 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1282 case GL_TEXTURE_EXTERNAL_OES
:
1283 case GL_PROXY_TEXTURE_2D
:
1284 case GL_PROXY_TEXTURE_RECTANGLE
:
1285 case GL_PROXY_TEXTURE_CUBE_MAP
:
1286 case GL_TEXTURE_2D_MULTISAMPLE
:
1287 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1288 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1289 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1296 case GL_TEXTURE_2D_ARRAY
:
1297 case GL_PROXY_TEXTURE_2D_ARRAY
:
1298 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1299 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1300 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1301 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1302 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1303 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1304 img
->Depth2
= depth
; /* no border */
1305 img
->DepthLog2
= 0; /* not used */
1308 case GL_PROXY_TEXTURE_3D
:
1309 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1310 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1311 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1312 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1315 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1320 _mesa_get_tex_max_num_levels(target
,
1321 img
->Width2
, img
->Height2
, img
->Depth2
);
1322 img
->TexFormat
= format
;
1327 * Free and clear fields of the gl_texture_image struct.
1329 * \param ctx GL context.
1330 * \param texImage texture image structure to be cleared.
1332 * After the call, \p texImage will have no data associated with it. Its
1333 * fields are cleared so that its parent object will test incomplete.
1336 _mesa_clear_texture_image(struct gl_context
*ctx
,
1337 struct gl_texture_image
*texImage
)
1339 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1340 clear_teximage_fields(texImage
);
1345 * Check the width, height, depth and border of a texture image are legal.
1346 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1348 * The target and level parameters will have already been validated.
1349 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1352 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1353 GLint level
, GLint width
, GLint height
,
1354 GLint depth
, GLint border
)
1360 case GL_PROXY_TEXTURE_1D
:
1361 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1362 maxSize
>>= level
; /* level size */
1363 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1365 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1366 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1372 case GL_PROXY_TEXTURE_2D
:
1373 case GL_TEXTURE_2D_MULTISAMPLE
:
1374 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1375 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1377 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1379 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1381 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1382 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1384 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1390 case GL_PROXY_TEXTURE_3D
:
1391 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1393 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1395 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1397 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1399 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1400 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1402 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1404 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1409 case GL_TEXTURE_RECTANGLE_NV
:
1410 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1413 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1414 if (width
< 0 || width
> maxSize
)
1416 if (height
< 0 || height
> maxSize
)
1420 case GL_TEXTURE_CUBE_MAP
:
1421 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1422 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1423 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1424 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1425 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1426 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1427 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1428 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1430 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1432 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1434 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1435 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1437 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1442 case GL_TEXTURE_1D_ARRAY_EXT
:
1443 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1444 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1446 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1448 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1450 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1451 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1456 case GL_TEXTURE_2D_ARRAY_EXT
:
1457 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1458 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1459 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1460 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1462 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1464 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1466 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1468 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1469 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1471 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1476 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1477 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1478 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1479 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1481 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1483 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1485 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1487 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1488 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1490 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1495 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1502 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1503 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1504 * \param destImage the destination texture image.
1505 * \return GL_TRUE if error found, GL_FALSE otherwise.
1508 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1509 const char *function
, GLuint dims
,
1510 const struct gl_texture_image
*destImage
,
1511 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1512 GLsizei subWidth
, GLsizei subHeight
,
1515 const GLenum target
= destImage
->TexObject
->Target
;
1520 _mesa_error(ctx
, GL_INVALID_VALUE
,
1521 "%s%dD(width=%d)", function
, dims
, subWidth
);
1525 if (dims
> 1 && subHeight
< 0) {
1526 _mesa_error(ctx
, GL_INVALID_VALUE
,
1527 "%s%dD(height=%d)", function
, dims
, subHeight
);
1531 if (dims
> 2 && subDepth
< 0) {
1532 _mesa_error(ctx
, GL_INVALID_VALUE
,
1533 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1537 /* check xoffset and width */
1538 if (xoffset
< -destImage
->Border
) {
1539 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1544 if (xoffset
+ subWidth
> destImage
->Width
) {
1545 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1550 /* check yoffset and height */
1552 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1553 if (yoffset
< -yBorder
) {
1554 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1558 if (yoffset
+ subHeight
> destImage
->Height
) {
1559 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1565 /* check zoffset and depth */
1567 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1568 if (zoffset
< -zBorder
) {
1569 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1572 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1573 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1579 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1580 * compressed texture images can be updated. But, that restriction may be
1581 * relaxed for particular compressed formats. At this time, all the
1582 * compressed formats supported by Mesa allow sub-textures to be updated
1583 * along compressed block boundaries.
1585 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1587 if (bw
!= 1 || bh
!= 1) {
1588 /* offset must be multiple of block size */
1589 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1590 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1591 "%s%dD(xoffset = %d, yoffset = %d)",
1592 function
, dims
, xoffset
, yoffset
);
1596 /* size must be multiple of bw by bh or equal to whole texture size */
1597 if ((subWidth
% bw
!= 0) && subWidth
!= destImage
->Width
) {
1598 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1599 "%s%dD(width = %d)", function
, dims
, subWidth
);
1603 if ((subHeight
% bh
!= 0) && subHeight
!= destImage
->Height
) {
1604 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1605 "%s%dD(height = %d)", function
, dims
, subHeight
);
1617 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1618 * specific texture image size checks.
1620 * A hardware driver might override this function if, for example, the
1621 * max 3D texture size is 512x512x64 (i.e. not a cube).
1623 * Note that width, height, depth == 0 is not an error. However, a
1624 * texture with zero width/height/depth will be considered "incomplete"
1625 * and texturing will effectively be disabled.
1627 * \param target any texture target/type
1628 * \param level as passed to glTexImage
1629 * \param format the MESA_FORMAT_x for the tex image
1630 * \param width as passed to glTexImage
1631 * \param height as passed to glTexImage
1632 * \param depth as passed to glTexImage
1633 * \param border as passed to glTexImage
1634 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1637 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1639 GLint width
, GLint height
, GLint depth
, GLint border
)
1641 /* We just check if the image size is less than MaxTextureMbytes.
1642 * Some drivers may do more specific checks.
1644 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1645 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1646 mbytes
*= _mesa_num_tex_faces(target
);
1647 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1652 * Return true if the format is only valid for glCompressedTexImage.
1655 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1658 case GL_ETC1_RGB8_OES
:
1659 case GL_PALETTE4_RGB8_OES
:
1660 case GL_PALETTE4_RGBA8_OES
:
1661 case GL_PALETTE4_R5_G6_B5_OES
:
1662 case GL_PALETTE4_RGBA4_OES
:
1663 case GL_PALETTE4_RGB5_A1_OES
:
1664 case GL_PALETTE8_RGB8_OES
:
1665 case GL_PALETTE8_RGBA8_OES
:
1666 case GL_PALETTE8_R5_G6_B5_OES
:
1667 case GL_PALETTE8_RGBA4_OES
:
1668 case GL_PALETTE8_RGB5_A1_OES
:
1677 * Helper function to determine whether a target and specific compression
1678 * format are supported.
1681 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1684 (void) intFormat
; /* not used yet */
1688 case GL_PROXY_TEXTURE_2D
:
1689 return GL_TRUE
; /* true for any compressed format so far */
1690 case GL_PROXY_TEXTURE_CUBE_MAP
:
1691 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1692 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1693 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1694 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1695 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1696 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1697 return ctx
->Extensions
.ARB_texture_cube_map
;
1698 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1699 case GL_TEXTURE_2D_ARRAY_EXT
:
1700 return (ctx
->Extensions
.MESA_texture_array
||
1701 ctx
->Extensions
.EXT_texture_array
);
1702 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1703 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1704 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1712 * Check if the given texture target value is legal for a
1713 * glTexImage1/2/3D call.
1716 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1722 case GL_PROXY_TEXTURE_1D
:
1723 return _mesa_is_desktop_gl(ctx
);
1731 case GL_PROXY_TEXTURE_2D
:
1732 return _mesa_is_desktop_gl(ctx
);
1733 case GL_PROXY_TEXTURE_CUBE_MAP
:
1734 return _mesa_is_desktop_gl(ctx
)
1735 && ctx
->Extensions
.ARB_texture_cube_map
;
1736 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1737 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1738 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1739 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1740 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1741 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1742 return ctx
->Extensions
.ARB_texture_cube_map
;
1743 case GL_TEXTURE_RECTANGLE_NV
:
1744 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1745 return _mesa_is_desktop_gl(ctx
)
1746 && ctx
->Extensions
.NV_texture_rectangle
;
1747 case GL_TEXTURE_1D_ARRAY_EXT
:
1748 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1749 return _mesa_is_desktop_gl(ctx
)
1750 && (ctx
->Extensions
.MESA_texture_array
||
1751 ctx
->Extensions
.EXT_texture_array
);
1759 case GL_PROXY_TEXTURE_3D
:
1760 return _mesa_is_desktop_gl(ctx
);
1761 case GL_TEXTURE_2D_ARRAY_EXT
:
1762 return (_mesa_is_desktop_gl(ctx
)
1763 && (ctx
->Extensions
.MESA_texture_array
||
1764 ctx
->Extensions
.EXT_texture_array
))
1765 || _mesa_is_gles3(ctx
);
1766 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1767 return _mesa_is_desktop_gl(ctx
)
1768 && (ctx
->Extensions
.MESA_texture_array
||
1769 ctx
->Extensions
.EXT_texture_array
);
1770 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1771 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1772 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1777 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1784 * Check if the given texture target value is legal for a
1785 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1786 * The difference compared to legal_teximage_target() above is that
1787 * proxy targets are not supported.
1790 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1794 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1799 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1800 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1801 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1802 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1803 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1804 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1805 return ctx
->Extensions
.ARB_texture_cube_map
;
1806 case GL_TEXTURE_RECTANGLE_NV
:
1807 return _mesa_is_desktop_gl(ctx
)
1808 && ctx
->Extensions
.NV_texture_rectangle
;
1809 case GL_TEXTURE_1D_ARRAY_EXT
:
1810 return _mesa_is_desktop_gl(ctx
)
1811 && (ctx
->Extensions
.MESA_texture_array
||
1812 ctx
->Extensions
.EXT_texture_array
);
1820 case GL_TEXTURE_2D_ARRAY_EXT
:
1821 return (_mesa_is_desktop_gl(ctx
)
1822 && (ctx
->Extensions
.MESA_texture_array
||
1823 ctx
->Extensions
.EXT_texture_array
))
1824 || _mesa_is_gles3(ctx
);
1825 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1826 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1827 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1832 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1840 * Helper function to determine if a texture object is mutable (in terms
1841 * of GL_ARB_texture_storage).
1844 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1846 if (ctx
->Extensions
.ARB_texture_storage
) {
1847 struct gl_texture_object
*texObj
=
1848 _mesa_get_current_tex_object(ctx
, target
);
1849 return !texObj
->Immutable
;
1856 * Return expected size of a compressed texture.
1859 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1862 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1863 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1868 * Test the glTexImage[123]D() parameters for errors.
1870 * \param ctx GL context.
1871 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1872 * \param target texture target given by the user (already validated).
1873 * \param level image level given by the user.
1874 * \param internalFormat internal format given by the user.
1875 * \param format pixel data format given by the user.
1876 * \param type pixel data type given by the user.
1877 * \param width image width given by the user.
1878 * \param height image height given by the user.
1879 * \param depth image depth given by the user.
1880 * \param border image border given by the user.
1882 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1884 * Verifies each of the parameters against the constants specified in
1885 * __struct gl_contextRec::Const and the supported extensions, and according
1886 * to the OpenGL specification.
1887 * Note that we don't fully error-check the width, height, depth values
1888 * here. That's done in _mesa_legal_texture_dimensions() which is used
1889 * by several other GL entrypoints. Plus, texture dims have a special
1890 * interaction with proxy textures.
1893 texture_error_check( struct gl_context
*ctx
,
1894 GLuint dimensions
, GLenum target
,
1895 GLint level
, GLint internalFormat
,
1896 GLenum format
, GLenum type
,
1897 GLint width
, GLint height
,
1898 GLint depth
, GLint border
)
1900 GLboolean colorFormat
;
1903 /* Even though there are no color-index textures, we still have to support
1904 * uploading color-index data and remapping it to RGB via the
1905 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1907 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1909 /* Note: for proxy textures, some error conditions immediately generate
1910 * a GL error in the usual way. But others do not generate a GL error.
1911 * Instead, they cause the width, height, depth, format fields of the
1912 * texture image to be zeroed-out. The GL spec seems to indicate that the
1913 * zero-out behaviour is only used in cases related to memory allocation.
1917 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1918 _mesa_error(ctx
, GL_INVALID_VALUE
,
1919 "glTexImage%dD(level=%d)", dimensions
, level
);
1924 if (border
< 0 || border
> 1 ||
1925 ((ctx
->API
!= API_OPENGL_COMPAT
||
1926 target
== GL_TEXTURE_RECTANGLE_NV
||
1927 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1928 _mesa_error(ctx
, GL_INVALID_VALUE
,
1929 "glTexImage%dD(border=%d)", dimensions
, border
);
1933 if (width
< 0 || height
< 0 || depth
< 0) {
1934 _mesa_error(ctx
, GL_INVALID_VALUE
,
1935 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1939 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1940 * combinations of format, internalFormat, and type that can be used.
1941 * Formats and types that require additional extensions (e.g., GL_FLOAT
1942 * requires GL_OES_texture_float) are filtered elsewhere.
1945 if (_mesa_is_gles(ctx
)) {
1946 if (_mesa_is_gles3(ctx
)) {
1947 err
= _mesa_es3_error_check_format_and_type(format
, type
,
1950 if (format
!= internalFormat
) {
1951 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1952 "glTexImage%dD(format = %s, internalFormat = %s)",
1954 _mesa_lookup_enum_by_nr(format
),
1955 _mesa_lookup_enum_by_nr(internalFormat
));
1959 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1961 if (err
!= GL_NO_ERROR
) {
1962 _mesa_error(ctx
, err
,
1963 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
1965 _mesa_lookup_enum_by_nr(format
),
1966 _mesa_lookup_enum_by_nr(type
),
1967 _mesa_lookup_enum_by_nr(internalFormat
));
1972 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1973 _mesa_is_cube_face(target
)) && width
!= height
) {
1974 _mesa_error(ctx
, GL_INVALID_VALUE
,
1975 "glTexImage2D(cube width != height)");
1979 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1980 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && width
!= height
) {
1981 _mesa_error(ctx
, GL_INVALID_VALUE
,
1982 "glTexImage3D(cube array width != height)");
1986 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1987 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && (depth
% 6)) {
1988 _mesa_error(ctx
, GL_INVALID_VALUE
,
1989 "glTexImage3D(cube array depth not multiple of 6)");
1993 /* Check internalFormat */
1994 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1995 _mesa_error(ctx
, GL_INVALID_VALUE
,
1996 "glTexImage%dD(internalFormat=%s)",
1997 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2001 /* Check incoming image format and type */
2002 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2003 if (err
!= GL_NO_ERROR
) {
2004 _mesa_error(ctx
, err
,
2005 "glTexImage%dD(incompatible format = %s, type = %s)",
2006 dimensions
, _mesa_lookup_enum_by_nr(format
),
2007 _mesa_lookup_enum_by_nr(type
));
2011 /* make sure internal format and format basically agree */
2012 colorFormat
= _mesa_is_color_format(format
);
2013 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2014 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2015 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2016 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2017 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2018 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2019 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2020 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2021 _mesa_lookup_enum_by_nr(format
));
2025 /* additional checks for ycbcr textures */
2026 if (internalFormat
== GL_YCBCR_MESA
) {
2027 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2028 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2029 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2031 _mesa_snprintf(message
, sizeof(message
),
2032 "glTexImage%dD(format/type YCBCR mismatch)",
2034 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2035 return GL_TRUE
; /* error */
2037 if (target
!= GL_TEXTURE_2D
&&
2038 target
!= GL_PROXY_TEXTURE_2D
&&
2039 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2040 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2041 _mesa_error(ctx
, GL_INVALID_ENUM
,
2042 "glTexImage%dD(bad target for YCbCr texture)",
2048 _mesa_snprintf(message
, sizeof(message
),
2049 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2050 dimensions
, border
);
2051 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2056 /* additional checks for depth textures */
2057 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2058 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2059 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
2060 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
2061 if (target
!= GL_TEXTURE_1D
&&
2062 target
!= GL_PROXY_TEXTURE_1D
&&
2063 target
!= GL_TEXTURE_2D
&&
2064 target
!= GL_PROXY_TEXTURE_2D
&&
2065 target
!= GL_TEXTURE_1D_ARRAY
&&
2066 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2067 target
!= GL_TEXTURE_2D_ARRAY
&&
2068 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2069 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2070 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2071 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2072 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2073 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2074 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2075 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2076 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2077 _mesa_error(ctx
, GL_INVALID_ENUM
,
2078 "glTexImage%dD(bad target for depth texture)",
2084 /* additional checks for compressed textures */
2085 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2086 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2087 _mesa_error(ctx
, GL_INVALID_ENUM
,
2088 "glTexImage%dD(target can't be compressed)", dimensions
);
2091 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2092 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2093 "glTexImage%dD(no compression for format)", dimensions
);
2097 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2098 "glTexImage%dD(border!=0)", dimensions
);
2103 /* additional checks for integer textures */
2104 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2105 (_mesa_is_enum_format_integer(format
) !=
2106 _mesa_is_enum_format_integer(internalFormat
))) {
2107 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2108 "glTexImage%dD(integer/non-integer format mismatch)",
2113 if (!mutable_tex_object(ctx
, target
)) {
2114 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2115 "glTexImage%dD(immutable texture)", dimensions
);
2119 /* if we get here, the parameters are OK */
2125 * Error checking for glCompressedTexImage[123]D().
2126 * Note that the width, height and depth values are not fully error checked
2128 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2131 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2132 GLenum target
, GLint level
,
2133 GLenum internalFormat
, GLsizei width
,
2134 GLsizei height
, GLsizei depth
, GLint border
,
2137 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2139 GLenum error
= GL_NO_ERROR
;
2140 char *reason
= ""; /* no error */
2142 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2144 error
= GL_INVALID_ENUM
;
2148 /* This will detect any invalid internalFormat value */
2149 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2150 reason
= "internalFormat";
2151 error
= GL_INVALID_ENUM
;
2155 switch (internalFormat
) {
2156 case GL_PALETTE4_RGB8_OES
:
2157 case GL_PALETTE4_RGBA8_OES
:
2158 case GL_PALETTE4_R5_G6_B5_OES
:
2159 case GL_PALETTE4_RGBA4_OES
:
2160 case GL_PALETTE4_RGB5_A1_OES
:
2161 case GL_PALETTE8_RGB8_OES
:
2162 case GL_PALETTE8_RGBA8_OES
:
2163 case GL_PALETTE8_R5_G6_B5_OES
:
2164 case GL_PALETTE8_RGBA4_OES
:
2165 case GL_PALETTE8_RGB5_A1_OES
:
2166 /* check level (note that level should be zero or less!) */
2167 if (level
> 0 || level
< -maxLevels
) {
2169 error
= GL_INVALID_VALUE
;
2173 if (dimensions
!= 2) {
2174 reason
= "compressed paletted textures must be 2D";
2175 error
= GL_INVALID_OPERATION
;
2179 /* Figure out the expected texture size (in bytes). This will be
2180 * checked against the actual size later.
2182 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2185 /* This is for the benefit of the TestProxyTexImage below. It expects
2186 * level to be non-negative. OES_compressed_paletted_texture uses a
2187 * weird mechanism where the level specified to glCompressedTexImage2D
2188 * is -(n-1) number of levels in the texture, and the data specifies the
2189 * complete mipmap stack. This is done to ensure the palette is the
2190 * same for all levels.
2197 if (level
< 0 || level
>= maxLevels
) {
2199 error
= GL_INVALID_VALUE
;
2203 /* Figure out the expected texture size (in bytes). This will be
2204 * checked against the actual size later.
2206 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2210 /* This should really never fail */
2211 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2212 reason
= "internalFormat";
2213 error
= GL_INVALID_ENUM
;
2217 /* No compressed formats support borders at this time */
2219 reason
= "border != 0";
2220 error
= GL_INVALID_VALUE
;
2224 /* For cube map, width must equal height */
2225 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2226 _mesa_is_cube_face(target
)) && width
!= height
) {
2227 reason
= "width != height";
2228 error
= GL_INVALID_VALUE
;
2232 /* check image size in bytes */
2233 if (expectedSize
!= imageSize
) {
2234 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2235 * if <imageSize> is not consistent with the format, dimensions, and
2236 * contents of the specified image.
2238 reason
= "imageSize inconsistant with width/height/format";
2239 error
= GL_INVALID_VALUE
;
2243 if (!mutable_tex_object(ctx
, target
)) {
2244 reason
= "immutable texture";
2245 error
= GL_INVALID_OPERATION
;
2252 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2259 * Test glTexSubImage[123]D() parameters for errors.
2261 * \param ctx GL context.
2262 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2263 * \param target texture target given by the user (already validated)
2264 * \param level image level given by the user.
2265 * \param xoffset sub-image x offset given by the user.
2266 * \param yoffset sub-image y offset given by the user.
2267 * \param zoffset sub-image z offset given by the user.
2268 * \param format pixel data format given by the user.
2269 * \param type pixel data type given by the user.
2270 * \param width image width given by the user.
2271 * \param height image height given by the user.
2272 * \param depth image depth given by the user.
2274 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2276 * Verifies each of the parameters against the constants specified in
2277 * __struct gl_contextRec::Const and the supported extensions, and according
2278 * to the OpenGL specification.
2281 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2282 GLenum target
, GLint level
,
2283 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2284 GLint width
, GLint height
, GLint depth
,
2285 GLenum format
, GLenum type
)
2287 struct gl_texture_object
*texObj
;
2288 struct gl_texture_image
*texImage
;
2291 /* check target (proxies not allowed) */
2292 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2293 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2294 dimensions
, _mesa_lookup_enum_by_nr(target
));
2299 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2300 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2305 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2306 * combinations of format and type that can be used. Formats and types
2307 * that require additional extensions (e.g., GL_FLOAT requires
2308 * GL_OES_texture_float) are filtered elsewhere.
2310 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2311 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2312 if (err
!= GL_NO_ERROR
) {
2313 _mesa_error(ctx
, err
,
2314 "glTexSubImage%dD(format = %s, type = %s)",
2316 _mesa_lookup_enum_by_nr(format
),
2317 _mesa_lookup_enum_by_nr(type
));
2322 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2323 if (err
!= GL_NO_ERROR
) {
2324 _mesa_error(ctx
, err
,
2325 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2326 dimensions
, _mesa_lookup_enum_by_nr(format
),
2327 _mesa_lookup_enum_by_nr(type
));
2331 /* Get dest texture object / image pointers */
2332 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2334 /* must be out of memory */
2335 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2339 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2341 /* non-existant texture level */
2342 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2343 "glTexSubImage%dD(invalid texture image)", dimensions
);
2347 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2348 texImage
, xoffset
, yoffset
, 0,
2349 width
, height
, 1)) {
2353 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2354 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2355 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2356 "glTexSubImage%dD(no compression for format)", dimensions
);
2361 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2362 /* both source and dest must be integer-valued, or neither */
2363 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2364 _mesa_is_enum_format_integer(format
)) {
2365 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2366 "glTexSubImage%dD(integer/non-integer format mismatch)",
2377 * Test glCopyTexImage[12]D() parameters for errors.
2379 * \param ctx GL context.
2380 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2381 * \param target texture target given by the user.
2382 * \param level image level given by the user.
2383 * \param internalFormat internal format given by the user.
2384 * \param width image width given by the user.
2385 * \param height image height given by the user.
2386 * \param border texture border.
2388 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2390 * Verifies each of the parameters against the constants specified in
2391 * __struct gl_contextRec::Const and the supported extensions, and according
2392 * to the OpenGL specification.
2395 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2396 GLenum target
, GLint level
, GLint internalFormat
,
2397 GLint width
, GLint height
, GLint border
)
2400 GLint rb_base_format
;
2401 struct gl_renderbuffer
*rb
;
2402 GLenum rb_internal_format
;
2405 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2406 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2407 dimensions
, _mesa_lookup_enum_by_nr(target
));
2412 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2413 _mesa_error(ctx
, GL_INVALID_VALUE
,
2414 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2418 /* Check that the source buffer is complete */
2419 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2420 if (ctx
->ReadBuffer
->_Status
== 0) {
2421 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2423 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2424 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2425 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2429 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2430 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2431 "glCopyTexImage%dD(multisample FBO)",
2438 if (border
< 0 || border
> 1 ||
2439 ((ctx
->API
!= API_OPENGL_COMPAT
||
2440 target
== GL_TEXTURE_RECTANGLE_NV
||
2441 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2442 _mesa_error(ctx
, GL_INVALID_VALUE
,
2443 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2447 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2449 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2450 "glCopyTexImage%dD(read buffer)", dimensions
);
2454 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2457 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2458 switch (internalFormat
) {
2463 case GL_LUMINANCE_ALPHA
:
2466 _mesa_error(ctx
, GL_INVALID_VALUE
,
2467 "glCopyTexImage%dD(internalFormat)", dimensions
);
2472 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2473 if (baseFormat
< 0) {
2474 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2475 "glCopyTexImage%dD(internalFormat)", dimensions
);
2479 rb_internal_format
= rb
->InternalFormat
;
2480 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2481 if (_mesa_is_color_format(internalFormat
)) {
2482 if (rb_base_format
< 0) {
2483 _mesa_error(ctx
, GL_INVALID_VALUE
,
2484 "glCopyTexImage%dD(internalFormat)", dimensions
);
2489 if (_mesa_is_gles(ctx
)) {
2491 if (_mesa_base_format_component_count(baseFormat
) >
2492 _mesa_base_format_component_count(rb_base_format
)) {
2495 if (baseFormat
== GL_DEPTH_COMPONENT
||
2496 baseFormat
== GL_DEPTH_STENCIL
||
2497 rb_base_format
== GL_DEPTH_COMPONENT
||
2498 rb_base_format
== GL_DEPTH_STENCIL
||
2499 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2500 baseFormat
== GL_ALPHA
) &&
2501 rb_base_format
!= GL_RGBA
) ||
2502 internalFormat
== GL_RGB9_E5
) {
2505 if (internalFormat
== GL_RGB9_E5
) {
2509 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2510 "glCopyTexImage%dD(internalFormat)", dimensions
);
2515 if (_mesa_is_gles3(ctx
)) {
2516 bool rb_is_srgb
= false;
2517 bool dst_is_srgb
= false;
2519 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2520 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2524 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2528 if (rb_is_srgb
!= dst_is_srgb
) {
2529 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2530 * OpenGLES 3.0.0 spec says:
2532 * "The error INVALID_OPERATION is also generated if the
2533 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2534 * framebuffer attachment corresponding to the read buffer
2535 * is LINEAR (see section 6.1.13) and internalformat is
2536 * one of the sRGB formats described in section 3.8.16, or
2537 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2538 * SRGB and internalformat is not one of the sRGB formats."
2540 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2541 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2546 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2547 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2548 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2552 /* From the EXT_texture_integer spec:
2554 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2555 * if the texture internalformat is an integer format and the read color
2556 * buffer is not an integer format, or if the internalformat is not an
2557 * integer format and the read color buffer is an integer format."
2559 if (_mesa_is_color_format(internalFormat
)) {
2560 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2561 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2562 if (is_int
|| is_rbint
) {
2563 if (is_int
!= is_rbint
) {
2564 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2565 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2567 } else if (_mesa_is_gles(ctx
) &&
2568 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2569 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2570 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2571 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2577 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2578 _mesa_is_cube_face(target
)) && width
!= height
) {
2579 _mesa_error(ctx
, GL_INVALID_VALUE
,
2580 "glTexImage2D(cube width != height)");
2584 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2585 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2586 _mesa_error(ctx
, GL_INVALID_ENUM
,
2587 "glCopyTexImage%dD(target)", dimensions
);
2590 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2591 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2592 "glCopyTexImage%dD(no compression for format)", dimensions
);
2596 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2597 "glCopyTexImage%dD(border!=0)", dimensions
);
2602 if (!mutable_tex_object(ctx
, target
)) {
2603 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2604 "glCopyTexImage%dD(immutable texture)", dimensions
);
2608 /* if we get here, the parameters are OK */
2614 * Test glCopyTexSubImage[12]D() parameters for errors.
2615 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2618 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2619 GLenum target
, GLint level
,
2620 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2621 GLint width
, GLint height
)
2623 struct gl_texture_object
*texObj
;
2624 struct gl_texture_image
*texImage
;
2626 /* Check that the source buffer is complete */
2627 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2628 if (ctx
->ReadBuffer
->_Status
== 0) {
2629 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2631 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2632 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2633 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2637 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2638 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2639 "glCopyTexSubImage%dD(multisample FBO)",
2645 /* check target (proxies not allowed) */
2646 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2647 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2648 dimensions
, _mesa_lookup_enum_by_nr(target
));
2653 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2654 _mesa_error(ctx
, GL_INVALID_VALUE
,
2655 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2659 /* Get dest texture object / image pointers */
2660 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2662 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2666 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2668 /* destination image does not exist */
2669 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2670 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2674 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2675 dimensions
, texImage
,
2676 xoffset
, yoffset
, zoffset
,
2677 width
, height
, 1)) {
2681 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2682 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2683 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2684 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2689 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2690 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2694 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2695 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2696 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2697 dimensions
, texImage
->_BaseFormat
);
2701 /* From the EXT_texture_integer spec:
2703 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2704 * if the texture internalformat is an integer format and the read color
2705 * buffer is not an integer format, or if the internalformat is not an
2706 * integer format and the read color buffer is an integer format."
2708 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2709 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2711 if (_mesa_is_format_integer_color(rb
->Format
) !=
2712 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2713 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2714 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2719 /* if we get here, the parameters are OK */
2724 /** Callback info for walking over FBO hash table */
2727 struct gl_context
*ctx
;
2728 struct gl_texture_object
*texObj
;
2734 * Check render to texture callback. Called from _mesa_HashWalk().
2737 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2739 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2740 const struct cb_info
*info
= (struct cb_info
*) userData
;
2741 struct gl_context
*ctx
= info
->ctx
;
2742 const struct gl_texture_object
*texObj
= info
->texObj
;
2743 const GLuint level
= info
->level
, face
= info
->face
;
2745 /* If this is a user-created FBO */
2746 if (_mesa_is_user_fbo(fb
)) {
2748 /* check if any of the FBO's attachments point to 'texObj' */
2749 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2750 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2751 if (att
->Type
== GL_TEXTURE
&&
2752 att
->Texture
== texObj
&&
2753 att
->TextureLevel
== level
&&
2754 att
->CubeMapFace
== face
) {
2755 ASSERT(_mesa_get_attachment_teximage(att
));
2756 /* Tell driver about the new renderbuffer texture */
2757 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2758 /* Mark fb status as indeterminate to force re-validation */
2767 * When a texture image is specified we have to check if it's bound to
2768 * any framebuffer objects (render to texture) in order to detect changes
2769 * in size or format since that effects FBO completeness.
2770 * Any FBOs rendering into the texture must be re-validated.
2773 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2774 struct gl_texture_object
*texObj
,
2775 GLuint face
, GLuint level
)
2777 /* Only check this texture if it's been marked as RenderToTexture */
2778 if (texObj
->_RenderToTexture
) {
2779 struct cb_info info
;
2781 info
.texObj
= texObj
;
2784 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2790 * If the texture object's GenerateMipmap flag is set and we've
2791 * changed the texture base level image, regenerate the rest of the
2792 * mipmap levels now.
2795 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2796 struct gl_texture_object
*texObj
, GLint level
)
2798 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2799 if (texObj
->GenerateMipmap
&&
2800 level
== texObj
->BaseLevel
&&
2801 level
< texObj
->MaxLevel
) {
2802 ASSERT(ctx
->Driver
.GenerateMipmap
);
2803 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2808 /** Debug helper: override the user-requested internal format */
2810 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2813 if (internalFormat
== GL_RGBA16F_ARB
||
2814 internalFormat
== GL_RGBA32F_ARB
) {
2815 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2818 else if (internalFormat
== GL_RGB16F_ARB
||
2819 internalFormat
== GL_RGB32F_ARB
) {
2820 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2823 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2824 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2825 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2826 return GL_LUMINANCE_ALPHA
;
2828 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2829 internalFormat
== GL_LUMINANCE32F_ARB
) {
2830 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2831 return GL_LUMINANCE
;
2833 else if (internalFormat
== GL_ALPHA16F_ARB
||
2834 internalFormat
== GL_ALPHA32F_ARB
) {
2835 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2839 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2840 internalFormat = GL_RGBA;
2844 return internalFormat
;
2847 return internalFormat
;
2853 * Choose the actual hardware format for a texture image.
2854 * Try to use the same format as the previous image level when possible.
2855 * Otherwise, ask the driver for the best format.
2856 * It's important to try to choose a consistant format for all levels
2857 * for efficient texture memory layout/allocation. In particular, this
2858 * comes up during automatic mipmap generation.
2861 _mesa_choose_texture_format(struct gl_context
*ctx
,
2862 struct gl_texture_object
*texObj
,
2863 GLenum target
, GLint level
,
2864 GLenum internalFormat
, GLenum format
, GLenum type
)
2868 /* see if we've already chosen a format for the previous level */
2870 struct gl_texture_image
*prevImage
=
2871 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2872 /* See if the prev level is defined and has an internal format which
2873 * matches the new internal format.
2876 prevImage
->Width
> 0 &&
2877 prevImage
->InternalFormat
== internalFormat
) {
2878 /* use the same format */
2879 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2880 return prevImage
->TexFormat
;
2884 /* If the application requested compression to an S3TC format but we don't
2885 * have the DTXn library, force a generic compressed format instead.
2887 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2888 const GLenum before
= internalFormat
;
2890 switch (internalFormat
) {
2891 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2892 if (!ctx
->Mesa_DXTn
)
2893 internalFormat
= GL_COMPRESSED_RGB
;
2895 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2896 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2897 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2898 if (!ctx
->Mesa_DXTn
)
2899 internalFormat
= GL_COMPRESSED_RGBA
;
2905 if (before
!= internalFormat
) {
2907 "DXT compression requested (%s), "
2908 "but libtxc_dxtn library not installed. Using %s "
2910 _mesa_lookup_enum_by_nr(before
),
2911 _mesa_lookup_enum_by_nr(internalFormat
));
2915 /* choose format from scratch */
2916 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2918 ASSERT(f
!= MESA_FORMAT_NONE
);
2923 * Adjust pixel unpack params and image dimensions to strip off the
2924 * one-pixel texture border.
2926 * Gallium and intel don't support texture borders. They've seldem been used
2927 * and seldom been implemented correctly anyway.
2929 * \param unpackNew returns the new pixel unpack parameters
2932 strip_texture_border(GLenum target
,
2933 GLint
*width
, GLint
*height
, GLint
*depth
,
2934 const struct gl_pixelstore_attrib
*unpack
,
2935 struct gl_pixelstore_attrib
*unpackNew
)
2941 *unpackNew
= *unpack
;
2943 if (unpackNew
->RowLength
== 0)
2944 unpackNew
->RowLength
= *width
;
2946 if (unpackNew
->ImageHeight
== 0)
2947 unpackNew
->ImageHeight
= *height
;
2949 assert(*width
>= 3);
2950 unpackNew
->SkipPixels
++; /* skip the border */
2951 *width
= *width
- 2; /* reduce the width by two border pixels */
2953 /* The min height of a texture with a border is 3 */
2954 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2955 unpackNew
->SkipRows
++; /* skip the border */
2956 *height
= *height
- 2; /* reduce the height by two border pixels */
2959 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
&& target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2960 unpackNew
->SkipImages
++; /* skip the border */
2961 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2967 * Common code to implement all the glTexImage1D/2D/3D functions
2968 * as well as glCompressedTexImage1D/2D/3D.
2969 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2970 * \param format the user's image format (only used if !compressed)
2971 * \param type the user's image type (only used if !compressed)
2972 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2975 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2976 GLenum target
, GLint level
, GLint internalFormat
,
2977 GLsizei width
, GLsizei height
, GLsizei depth
,
2978 GLint border
, GLenum format
, GLenum type
,
2979 GLsizei imageSize
, const GLvoid
*pixels
)
2981 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2982 struct gl_pixelstore_attrib unpack_no_border
;
2983 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2984 struct gl_texture_object
*texObj
;
2985 gl_format texFormat
;
2986 GLboolean dimensionsOK
, sizeOK
;
2988 FLUSH_VERTICES(ctx
, 0);
2990 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2993 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2995 _mesa_lookup_enum_by_nr(target
), level
,
2996 _mesa_lookup_enum_by_nr(internalFormat
),
2997 width
, height
, depth
, border
, pixels
);
3000 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3002 _mesa_lookup_enum_by_nr(target
), level
,
3003 _mesa_lookup_enum_by_nr(internalFormat
),
3004 width
, height
, depth
, border
,
3005 _mesa_lookup_enum_by_nr(format
),
3006 _mesa_lookup_enum_by_nr(type
), pixels
);
3009 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3011 /* target error checking */
3012 if (!legal_teximage_target(ctx
, dims
, target
)) {
3013 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3014 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3018 /* general error checking */
3020 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3022 width
, height
, depth
,
3027 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3028 format
, type
, width
, height
, depth
, border
))
3032 /* Here we convert a cpal compressed image into a regular glTexImage2D
3033 * call by decompressing the texture. If we really want to support cpal
3034 * textures in any driver this would have to be changed.
3036 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3037 switch (internalFormat
) {
3038 case GL_PALETTE4_RGB8_OES
:
3039 case GL_PALETTE4_RGBA8_OES
:
3040 case GL_PALETTE4_R5_G6_B5_OES
:
3041 case GL_PALETTE4_RGBA4_OES
:
3042 case GL_PALETTE4_RGB5_A1_OES
:
3043 case GL_PALETTE8_RGB8_OES
:
3044 case GL_PALETTE8_RGBA8_OES
:
3045 case GL_PALETTE8_R5_G6_B5_OES
:
3046 case GL_PALETTE8_RGBA4_OES
:
3047 case GL_PALETTE8_RGB5_A1_OES
:
3048 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3049 width
, height
, imageSize
, pixels
);
3054 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3058 /* For glCompressedTexImage() the driver has no choice about the
3059 * texture format since we'll never transcode the user's compressed
3060 * image data. The internalFormat was error checked earlier.
3062 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3065 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3066 internalFormat
, format
, type
);
3069 assert(texFormat
!= MESA_FORMAT_NONE
);
3071 /* check that width, height, depth are legal for the mipmap level */
3072 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3073 height
, depth
, border
);
3075 /* check that the texture won't take too much memory, etc */
3076 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3078 width
, height
, depth
, border
);
3080 if (_mesa_is_proxy_texture(target
)) {
3081 /* Proxy texture: just clear or set state depending on error checking */
3082 struct gl_texture_image
*texImage
=
3083 get_proxy_tex_image(ctx
, target
, level
);
3086 return; /* GL_OUT_OF_MEMORY already recorded */
3088 if (dimensionsOK
&& sizeOK
) {
3089 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3090 border
, internalFormat
, texFormat
);
3093 clear_teximage_fields(texImage
);
3097 /* non-proxy target */
3098 const GLuint face
= _mesa_tex_target_to_face(target
);
3099 struct gl_texture_image
*texImage
;
3101 if (!dimensionsOK
) {
3102 _mesa_error(ctx
, GL_INVALID_VALUE
,
3103 "glTexImage%uD(invalid width or height or depth)",
3109 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3110 "glTexImage%uD(image too large)", dims
);
3114 /* Allow a hardware driver to just strip out the border, to provide
3115 * reliable but slightly incorrect hardware rendering instead of
3116 * rarely-tested software fallback rendering.
3118 if (border
&& ctx
->Const
.StripTextureBorder
) {
3119 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3122 unpack
= &unpack_no_border
;
3125 if (ctx
->NewState
& _NEW_PIXEL
)
3126 _mesa_update_state(ctx
);
3128 _mesa_lock_texture(ctx
, texObj
);
3130 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3133 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3136 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3138 _mesa_init_teximage_fields(ctx
, texImage
,
3139 width
, height
, depth
,
3140 border
, internalFormat
, texFormat
);
3142 /* Give the texture to the driver. <pixels> may be null. */
3143 if (width
> 0 && height
> 0 && depth
> 0) {
3145 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3149 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3150 type
, pixels
, unpack
);
3154 check_gen_mipmap(ctx
, target
, texObj
, level
);
3156 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3158 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3161 _mesa_unlock_texture(ctx
, texObj
);
3168 * Called from the API. Note that width includes the border.
3171 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3172 GLsizei width
, GLint border
, GLenum format
,
3173 GLenum type
, const GLvoid
*pixels
)
3175 GET_CURRENT_CONTEXT(ctx
);
3176 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3177 border
, format
, type
, 0, pixels
);
3182 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3183 GLsizei width
, GLsizei height
, GLint border
,
3184 GLenum format
, GLenum type
,
3185 const GLvoid
*pixels
)
3187 GET_CURRENT_CONTEXT(ctx
);
3188 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3189 border
, format
, type
, 0, pixels
);
3194 * Called by the API or display list executor.
3195 * Note that width and height include the border.
3198 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3199 GLsizei width
, GLsizei height
, GLsizei depth
,
3200 GLint border
, GLenum format
, GLenum type
,
3201 const GLvoid
*pixels
)
3203 GET_CURRENT_CONTEXT(ctx
);
3204 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3205 width
, height
, depth
,
3206 border
, format
, type
, 0, pixels
);
3211 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3212 GLsizei width
, GLsizei height
, GLsizei depth
,
3213 GLint border
, GLenum format
, GLenum type
,
3214 const GLvoid
*pixels
)
3216 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3217 depth
, border
, format
, type
, pixels
);
3222 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3224 struct gl_texture_object
*texObj
;
3225 struct gl_texture_image
*texImage
;
3227 GET_CURRENT_CONTEXT(ctx
);
3228 FLUSH_VERTICES(ctx
, 0);
3232 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3234 case GL_TEXTURE_EXTERNAL_OES
:
3235 valid_target
= ctx
->Extensions
.OES_EGL_image_external
;
3238 valid_target
= false;
3242 if (!valid_target
) {
3243 _mesa_error(ctx
, GL_INVALID_ENUM
,
3244 "glEGLImageTargetTexture2D(target=%d)", target
);
3249 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3250 "glEGLImageTargetTexture2D(image=%p)", image
);
3254 if (ctx
->NewState
& _NEW_PIXEL
)
3255 _mesa_update_state(ctx
);
3257 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3258 _mesa_lock_texture(ctx
, texObj
);
3260 if (texObj
->Immutable
) {
3261 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3262 "glEGLImageTargetTexture2D(texture is immutable)");
3263 _mesa_unlock_texture(ctx
, texObj
);
3267 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3269 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3271 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3273 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3274 texObj
, texImage
, image
);
3276 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3278 _mesa_unlock_texture(ctx
, texObj
);
3285 * Implement all the glTexSubImage1/2/3D() functions.
3288 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3289 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3290 GLsizei width
, GLsizei height
, GLsizei depth
,
3291 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3293 struct gl_texture_object
*texObj
;
3294 struct gl_texture_image
*texImage
;
3296 FLUSH_VERTICES(ctx
, 0);
3298 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3299 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3301 _mesa_lookup_enum_by_nr(target
), level
,
3302 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3303 _mesa_lookup_enum_by_nr(format
),
3304 _mesa_lookup_enum_by_nr(type
), pixels
);
3306 /* check target (proxies not allowed) */
3307 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3308 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3309 dims
, _mesa_lookup_enum_by_nr(target
));
3313 if (ctx
->NewState
& _NEW_PIXEL
)
3314 _mesa_update_state(ctx
);
3316 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3317 xoffset
, yoffset
, zoffset
,
3318 width
, height
, depth
, format
, type
)) {
3319 return; /* error was detected */
3322 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3324 _mesa_lock_texture(ctx
, texObj
);
3326 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3328 if (width
> 0 && height
> 0 && depth
> 0) {
3329 /* If we have a border, offset=-1 is legal. Bias by border width. */
3332 if (target
!= GL_TEXTURE_2D_ARRAY
)
3333 zoffset
+= texImage
->Border
;
3336 if (target
!= GL_TEXTURE_1D_ARRAY
)
3337 yoffset
+= texImage
->Border
;
3340 xoffset
+= texImage
->Border
;
3343 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3344 xoffset
, yoffset
, zoffset
,
3345 width
, height
, depth
,
3346 format
, type
, pixels
, &ctx
->Unpack
);
3348 check_gen_mipmap(ctx
, target
, texObj
, level
);
3350 ctx
->NewState
|= _NEW_TEXTURE
;
3353 _mesa_unlock_texture(ctx
, texObj
);
3358 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3359 GLint xoffset
, GLsizei width
,
3360 GLenum format
, GLenum type
,
3361 const GLvoid
*pixels
)
3363 GET_CURRENT_CONTEXT(ctx
);
3364 texsubimage(ctx
, 1, target
, level
,
3367 format
, type
, pixels
);
3372 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3373 GLint xoffset
, GLint yoffset
,
3374 GLsizei width
, GLsizei height
,
3375 GLenum format
, GLenum type
,
3376 const GLvoid
*pixels
)
3378 GET_CURRENT_CONTEXT(ctx
);
3379 texsubimage(ctx
, 2, target
, level
,
3380 xoffset
, yoffset
, 0,
3382 format
, type
, pixels
);
3388 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3389 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3390 GLsizei width
, GLsizei height
, GLsizei depth
,
3391 GLenum format
, GLenum type
,
3392 const GLvoid
*pixels
)
3394 GET_CURRENT_CONTEXT(ctx
);
3395 texsubimage(ctx
, 3, target
, level
,
3396 xoffset
, yoffset
, zoffset
,
3397 width
, height
, depth
,
3398 format
, type
, pixels
);
3404 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3405 * from. This depends on whether the texture contains color or depth values.
3407 static struct gl_renderbuffer
*
3408 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3410 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3411 /* reading from depth/stencil buffer */
3412 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3415 /* copying from color buffer */
3416 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3423 * Implement the glCopyTexImage1/2D() functions.
3426 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3427 GLenum target
, GLint level
, GLenum internalFormat
,
3428 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3430 struct gl_texture_object
*texObj
;
3431 struct gl_texture_image
*texImage
;
3432 const GLuint face
= _mesa_tex_target_to_face(target
);
3433 gl_format texFormat
;
3435 FLUSH_VERTICES(ctx
, 0);
3437 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3438 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3440 _mesa_lookup_enum_by_nr(target
), level
,
3441 _mesa_lookup_enum_by_nr(internalFormat
),
3442 x
, y
, width
, height
, border
);
3444 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3445 _mesa_update_state(ctx
);
3447 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3448 width
, height
, border
))
3451 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3453 _mesa_error(ctx
, GL_INVALID_VALUE
,
3454 "glCopyTexImage%uD(invalid width or height)", dims
);
3458 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3461 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3462 internalFormat
, GL_NONE
, GL_NONE
);
3463 assert(texFormat
!= MESA_FORMAT_NONE
);
3465 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3467 width
, height
, 1, border
)) {
3468 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3469 "glCopyTexImage%uD(image too large)", dims
);
3473 if (border
&& ctx
->Const
.StripTextureBorder
) {
3475 width
-= border
* 2;
3478 height
-= border
* 2;
3483 _mesa_lock_texture(ctx
, texObj
);
3485 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3488 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3491 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3493 /* Free old texture image */
3494 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3496 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3497 border
, internalFormat
, texFormat
);
3499 if (width
&& height
) {
3500 /* Allocate texture memory (no pixel data yet) */
3501 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3503 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3505 struct gl_renderbuffer
*srcRb
=
3506 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3508 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
3509 srcRb
, srcX
, srcY
, width
, height
);
3512 check_gen_mipmap(ctx
, target
, texObj
, level
);
3515 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3517 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3520 _mesa_unlock_texture(ctx
, texObj
);
3526 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3527 GLenum internalFormat
,
3529 GLsizei width
, GLint border
)
3531 GET_CURRENT_CONTEXT(ctx
);
3532 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3538 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3539 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3542 GET_CURRENT_CONTEXT(ctx
);
3543 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3544 x
, y
, width
, height
, border
);
3550 * Implementation for glCopyTexSubImage1/2/3D() functions.
3553 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3554 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3555 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3557 struct gl_texture_object
*texObj
;
3558 struct gl_texture_image
*texImage
;
3560 FLUSH_VERTICES(ctx
, 0);
3562 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3563 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3565 _mesa_lookup_enum_by_nr(target
),
3566 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3568 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3569 _mesa_update_state(ctx
);
3571 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3572 xoffset
, yoffset
, zoffset
, width
, height
)) {
3576 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3578 _mesa_lock_texture(ctx
, texObj
);
3580 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3582 /* If we have a border, offset=-1 is legal. Bias by border width. */
3585 if (target
!= GL_TEXTURE_2D_ARRAY
)
3586 zoffset
+= texImage
->Border
;
3589 if (target
!= GL_TEXTURE_1D_ARRAY
)
3590 yoffset
+= texImage
->Border
;
3593 xoffset
+= texImage
->Border
;
3596 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3598 struct gl_renderbuffer
*srcRb
=
3599 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3601 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3602 xoffset
, yoffset
, zoffset
,
3603 srcRb
, x
, y
, width
, height
);
3605 check_gen_mipmap(ctx
, target
, texObj
, level
);
3607 ctx
->NewState
|= _NEW_TEXTURE
;
3610 _mesa_unlock_texture(ctx
, texObj
);
3615 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3616 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3618 GET_CURRENT_CONTEXT(ctx
);
3619 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3625 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3626 GLint xoffset
, GLint yoffset
,
3627 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3629 GET_CURRENT_CONTEXT(ctx
);
3630 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3637 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3638 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3639 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3641 GET_CURRENT_CONTEXT(ctx
);
3642 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3643 x
, y
, width
, height
);
3649 /**********************************************************************/
3650 /****** Compressed Textures ******/
3651 /**********************************************************************/
3655 * Error checking for glCompressedTexSubImage[123]D().
3656 * \return error code or GL_NO_ERROR.
3659 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3660 GLenum target
, GLint level
,
3661 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3662 GLsizei width
, GLsizei height
, GLsizei depth
,
3663 GLenum format
, GLsizei imageSize
)
3665 struct gl_texture_object
*texObj
;
3666 struct gl_texture_image
*texImage
;
3674 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3675 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3676 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3677 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3678 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3679 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3683 targetOK
= GL_FALSE
;
3688 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3692 /* no 1D compressed textures at this time */
3693 targetOK
= GL_FALSE
;
3698 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3703 /* this will catch any invalid compressed format token */
3704 if (!_mesa_is_compressed_format(ctx
, format
)) {
3705 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3710 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3711 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3716 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3717 if (expectedSize
!= imageSize
) {
3718 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3723 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3725 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3726 "glCompressedTexSubImage%uD()", dims
);
3730 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3732 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3733 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3737 if ((GLint
) format
!= texImage
->InternalFormat
) {
3738 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3739 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3743 if (compressedteximage_only_format(ctx
, format
)) {
3744 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3745 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3750 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3751 texImage
, xoffset
, yoffset
, zoffset
,
3752 width
, height
, depth
)) {
3761 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3762 GLenum internalFormat
, GLsizei width
,
3763 GLint border
, GLsizei imageSize
,
3766 GET_CURRENT_CONTEXT(ctx
);
3767 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3768 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3773 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3774 GLenum internalFormat
, GLsizei width
,
3775 GLsizei height
, GLint border
, GLsizei imageSize
,
3778 GET_CURRENT_CONTEXT(ctx
);
3779 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3780 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3785 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3786 GLenum internalFormat
, GLsizei width
,
3787 GLsizei height
, GLsizei depth
, GLint border
,
3788 GLsizei imageSize
, const GLvoid
*data
)
3790 GET_CURRENT_CONTEXT(ctx
);
3791 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3792 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3797 * Common helper for glCompressedTexSubImage1/2/3D().
3800 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3801 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3802 GLsizei width
, GLsizei height
, GLsizei depth
,
3803 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3805 struct gl_texture_object
*texObj
;
3806 struct gl_texture_image
*texImage
;
3807 GET_CURRENT_CONTEXT(ctx
);
3808 FLUSH_VERTICES(ctx
, 0);
3810 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3811 xoffset
, yoffset
, zoffset
,
3812 width
, height
, depth
,
3813 format
, imageSize
)) {
3817 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3819 _mesa_lock_texture(ctx
, texObj
);
3821 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3824 if (width
> 0 && height
> 0 && depth
> 0) {
3825 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3826 xoffset
, yoffset
, zoffset
,
3827 width
, height
, depth
,
3828 format
, imageSize
, data
);
3830 check_gen_mipmap(ctx
, target
, texObj
, level
);
3832 ctx
->NewState
|= _NEW_TEXTURE
;
3835 _mesa_unlock_texture(ctx
, texObj
);
3840 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3841 GLsizei width
, GLenum format
,
3842 GLsizei imageSize
, const GLvoid
*data
)
3844 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3845 format
, imageSize
, data
);
3850 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3851 GLint yoffset
, GLsizei width
, GLsizei height
,
3852 GLenum format
, GLsizei imageSize
,
3855 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3856 width
, height
, 1, format
, imageSize
, data
);
3861 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3862 GLint yoffset
, GLint zoffset
, GLsizei width
,
3863 GLsizei height
, GLsizei depth
, GLenum format
,
3864 GLsizei imageSize
, const GLvoid
*data
)
3866 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3867 width
, height
, depth
, format
, imageSize
, data
);
3871 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3873 switch (internalFormat
) {
3875 return MESA_FORMAT_A8
;
3877 return MESA_FORMAT_A16
;
3878 case GL_ALPHA16F_ARB
:
3879 return MESA_FORMAT_ALPHA_FLOAT16
;
3880 case GL_ALPHA32F_ARB
:
3881 return MESA_FORMAT_ALPHA_FLOAT32
;
3882 case GL_ALPHA8I_EXT
:
3883 return MESA_FORMAT_ALPHA_INT8
;
3884 case GL_ALPHA16I_EXT
:
3885 return MESA_FORMAT_ALPHA_INT16
;
3886 case GL_ALPHA32I_EXT
:
3887 return MESA_FORMAT_ALPHA_INT32
;
3888 case GL_ALPHA8UI_EXT
:
3889 return MESA_FORMAT_ALPHA_UINT8
;
3890 case GL_ALPHA16UI_EXT
:
3891 return MESA_FORMAT_ALPHA_UINT16
;
3892 case GL_ALPHA32UI_EXT
:
3893 return MESA_FORMAT_ALPHA_UINT32
;
3895 return MESA_FORMAT_L8
;
3896 case GL_LUMINANCE16
:
3897 return MESA_FORMAT_L16
;
3898 case GL_LUMINANCE16F_ARB
:
3899 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3900 case GL_LUMINANCE32F_ARB
:
3901 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3902 case GL_LUMINANCE8I_EXT
:
3903 return MESA_FORMAT_LUMINANCE_INT8
;
3904 case GL_LUMINANCE16I_EXT
:
3905 return MESA_FORMAT_LUMINANCE_INT16
;
3906 case GL_LUMINANCE32I_EXT
:
3907 return MESA_FORMAT_LUMINANCE_INT32
;
3908 case GL_LUMINANCE8UI_EXT
:
3909 return MESA_FORMAT_LUMINANCE_UINT8
;
3910 case GL_LUMINANCE16UI_EXT
:
3911 return MESA_FORMAT_LUMINANCE_UINT16
;
3912 case GL_LUMINANCE32UI_EXT
:
3913 return MESA_FORMAT_LUMINANCE_UINT32
;
3914 case GL_LUMINANCE8_ALPHA8
:
3915 return MESA_FORMAT_AL88
;
3916 case GL_LUMINANCE16_ALPHA16
:
3917 return MESA_FORMAT_AL1616
;
3918 case GL_LUMINANCE_ALPHA16F_ARB
:
3919 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3920 case GL_LUMINANCE_ALPHA32F_ARB
:
3921 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3922 case GL_LUMINANCE_ALPHA8I_EXT
:
3923 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3924 case GL_LUMINANCE_ALPHA16I_EXT
:
3925 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3926 case GL_LUMINANCE_ALPHA32I_EXT
:
3927 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3928 case GL_LUMINANCE_ALPHA8UI_EXT
:
3929 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3930 case GL_LUMINANCE_ALPHA16UI_EXT
:
3931 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3932 case GL_LUMINANCE_ALPHA32UI_EXT
:
3933 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3935 return MESA_FORMAT_I8
;
3936 case GL_INTENSITY16
:
3937 return MESA_FORMAT_I16
;
3938 case GL_INTENSITY16F_ARB
:
3939 return MESA_FORMAT_INTENSITY_FLOAT16
;
3940 case GL_INTENSITY32F_ARB
:
3941 return MESA_FORMAT_INTENSITY_FLOAT32
;
3942 case GL_INTENSITY8I_EXT
:
3943 return MESA_FORMAT_INTENSITY_INT8
;
3944 case GL_INTENSITY16I_EXT
:
3945 return MESA_FORMAT_INTENSITY_INT16
;
3946 case GL_INTENSITY32I_EXT
:
3947 return MESA_FORMAT_INTENSITY_INT32
;
3948 case GL_INTENSITY8UI_EXT
:
3949 return MESA_FORMAT_INTENSITY_UINT8
;
3950 case GL_INTENSITY16UI_EXT
:
3951 return MESA_FORMAT_INTENSITY_UINT16
;
3952 case GL_INTENSITY32UI_EXT
:
3953 return MESA_FORMAT_INTENSITY_UINT32
;
3955 return MESA_FORMAT_RGBA8888_REV
;
3957 return MESA_FORMAT_RGBA_16
;
3958 case GL_RGBA16F_ARB
:
3959 return MESA_FORMAT_RGBA_FLOAT16
;
3960 case GL_RGBA32F_ARB
:
3961 return MESA_FORMAT_RGBA_FLOAT32
;
3963 return MESA_FORMAT_RGBA_INT8
;
3964 case GL_RGBA16I_EXT
:
3965 return MESA_FORMAT_RGBA_INT16
;
3966 case GL_RGBA32I_EXT
:
3967 return MESA_FORMAT_RGBA_INT32
;
3968 case GL_RGBA8UI_EXT
:
3969 return MESA_FORMAT_RGBA_UINT8
;
3970 case GL_RGBA16UI_EXT
:
3971 return MESA_FORMAT_RGBA_UINT16
;
3972 case GL_RGBA32UI_EXT
:
3973 return MESA_FORMAT_RGBA_UINT32
;
3976 return MESA_FORMAT_GR88
;
3978 return MESA_FORMAT_GR1616
;
3980 return MESA_FORMAT_RG_FLOAT16
;
3982 return MESA_FORMAT_RG_FLOAT32
;
3984 return MESA_FORMAT_RG_INT8
;
3986 return MESA_FORMAT_RG_INT16
;
3988 return MESA_FORMAT_RG_INT32
;
3990 return MESA_FORMAT_RG_UINT8
;
3992 return MESA_FORMAT_RG_UINT16
;
3994 return MESA_FORMAT_RG_UINT32
;
3997 return MESA_FORMAT_R8
;
3999 return MESA_FORMAT_R16
;
4001 return MESA_FORMAT_R_FLOAT16
;
4003 return MESA_FORMAT_R_FLOAT32
;
4005 return MESA_FORMAT_R_INT8
;
4007 return MESA_FORMAT_R_INT16
;
4009 return MESA_FORMAT_R_INT32
;
4011 return MESA_FORMAT_R_UINT8
;
4013 return MESA_FORMAT_R_UINT16
;
4015 return MESA_FORMAT_R_UINT32
;
4018 return MESA_FORMAT_RGB_FLOAT32
;
4020 return MESA_FORMAT_RGB_UINT32
;
4022 return MESA_FORMAT_RGB_INT32
;
4025 return MESA_FORMAT_NONE
;
4030 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4032 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4035 if (format
== MESA_FORMAT_NONE
)
4036 return MESA_FORMAT_NONE
;
4038 datatype
= _mesa_get_format_datatype(format
);
4039 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4040 return MESA_FORMAT_NONE
;
4042 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4043 return MESA_FORMAT_NONE
;
4045 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
4046 * any mention of R/RG formats, but they appear in the GL 3.1 core
4049 if (ctx
->Version
<= 30) {
4050 GLenum base_format
= _mesa_get_format_base_format(format
);
4052 if (base_format
== GL_R
|| base_format
== GL_RG
)
4053 return MESA_FORMAT_NONE
;
4056 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4057 GLenum base_format
= _mesa_get_format_base_format(format
);
4058 if (base_format
== GL_RGB
)
4059 return MESA_FORMAT_NONE
;
4066 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4067 struct gl_buffer_object
*bufObj
,
4068 GLintptr offset
, GLsizeiptr size
)
4070 struct gl_texture_object
*texObj
;
4073 FLUSH_VERTICES(ctx
, 0);
4075 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4076 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4080 format
= validate_texbuffer_format(ctx
, internalFormat
);
4081 if (format
== MESA_FORMAT_NONE
) {
4082 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4087 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4089 _mesa_lock_texture(ctx
, texObj
);
4091 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4092 texObj
->BufferObjectFormat
= internalFormat
;
4093 texObj
->_BufferObjectFormat
= format
;
4094 texObj
->BufferOffset
= offset
;
4095 texObj
->BufferSize
= size
;
4097 _mesa_unlock_texture(ctx
, texObj
);
4100 /** GL_ARB_texture_buffer_object */
4102 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4104 struct gl_buffer_object
*bufObj
;
4106 GET_CURRENT_CONTEXT(ctx
);
4108 /* NOTE: ARB_texture_buffer_object has interactions with
4109 * the compatibility profile that are not implemented.
4111 if (!(ctx
->API
== API_OPENGL_CORE
&&
4112 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4113 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4117 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4118 if (!bufObj
&& buffer
) {
4119 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4123 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4126 /** GL_ARB_texture_buffer_range */
4128 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4129 GLintptr offset
, GLsizeiptr size
)
4131 struct gl_buffer_object
*bufObj
;
4133 GET_CURRENT_CONTEXT(ctx
);
4135 if (!(ctx
->API
== API_OPENGL_CORE
&&
4136 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4137 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4141 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4145 (offset
+ size
) > bufObj
->Size
) {
4146 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4149 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4150 _mesa_error(ctx
, GL_INVALID_VALUE
,
4151 "glTexBufferRange(invalid offset alignment)");
4154 } else if (buffer
) {
4155 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4163 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4167 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4169 /* Everything that is allowed for renderbuffers,
4170 * except for a base format of GL_STENCIL_INDEX.
4172 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4173 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4176 /** GL_ARB_texture_multisample */
4178 check_multisample_target(GLuint dims
, GLenum target
)
4181 case GL_TEXTURE_2D_MULTISAMPLE
:
4182 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4185 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4186 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4195 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4196 GLint internalformat
, GLsizei width
, GLsizei height
,
4197 GLsizei depth
, GLboolean fixedsamplelocations
,
4198 GLboolean immutable
, const char *func
)
4200 struct gl_texture_object
*texObj
;
4201 struct gl_texture_image
*texImage
;
4202 GLboolean sizeOK
, dimensionsOK
;
4203 gl_format texFormat
;
4204 GLenum sample_count_error
;
4206 GET_CURRENT_CONTEXT(ctx
);
4208 if (!(ctx
->Extensions
.ARB_texture_multisample
4209 && _mesa_is_desktop_gl(ctx
))) {
4210 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4214 if (!check_multisample_target(dims
, target
)) {
4215 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4219 /* check that the specified internalformat is color/depth/stencil-renderable;
4220 * refer GL3.1 spec 4.4.4
4223 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4224 _mesa_error(ctx
, GL_INVALID_ENUM
,
4225 "%s(internalformat=%s not legal for immutable-format)",
4226 func
, _mesa_lookup_enum_by_nr(internalformat
));
4230 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4231 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4232 "%s(internalformat=%s)",
4233 func
, _mesa_lookup_enum_by_nr(internalformat
));
4237 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4238 internalformat
, samples
);
4239 if (sample_count_error
!= GL_NO_ERROR
) {
4240 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4244 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4246 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4247 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4248 "%s(texture object 0)",
4253 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4255 if (texImage
== NULL
) {
4256 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4260 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4261 internalformat
, GL_NONE
, GL_NONE
);
4262 assert(texFormat
!= MESA_FORMAT_NONE
);
4264 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4265 width
, height
, depth
, 0);
4267 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4268 width
, height
, depth
, 0);
4270 if (_mesa_is_proxy_texture(target
)) {
4271 if (dimensionsOK
&& sizeOK
) {
4272 _mesa_init_teximage_fields(ctx
, texImage
,
4273 width
, height
, depth
, 0, internalformat
, texFormat
);
4274 texImage
->NumSamples
= samples
;
4275 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4278 /* clear all image fields */
4279 _mesa_init_teximage_fields(ctx
, texImage
,
4280 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4284 if (!dimensionsOK
) {
4285 _mesa_error(ctx
, GL_INVALID_VALUE
,
4286 "%s(invalid width or height)", func
);
4291 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4292 "%s(texture too large)", func
);
4296 /* Check if texObj->Immutable is set */
4297 if (texObj
->Immutable
) {
4298 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4302 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4304 _mesa_init_teximage_fields(ctx
, texImage
,
4305 width
, height
, depth
, 0, internalformat
, texFormat
);
4307 texImage
->NumSamples
= samples
;
4308 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4310 if (width
> 0 && height
> 0 && depth
> 0) {
4312 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4313 width
, height
, depth
)) {
4314 /* tidy up the texture image state. strictly speaking,
4315 * we're allowed to just leave this in whatever state we
4316 * like, but being tidy is good.
4318 _mesa_init_teximage_fields(ctx
, texImage
,
4319 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4323 texObj
->Immutable
= immutable
;
4324 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4329 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4330 GLint internalformat
, GLsizei width
,
4331 GLsizei height
, GLboolean fixedsamplelocations
)
4333 teximagemultisample(2, target
, samples
, internalformat
,
4334 width
, height
, 1, fixedsamplelocations
, GL_FALSE
, "glTexImage2DMultisample");
4338 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4339 GLint internalformat
, GLsizei width
,
4340 GLsizei height
, GLsizei depth
,
4341 GLboolean fixedsamplelocations
)
4343 teximagemultisample(3, target
, samples
, internalformat
,
4344 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
, "glTexImage3DMultisample");
4349 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4350 GLenum internalformat
, GLsizei width
,
4351 GLsizei height
, GLboolean fixedsamplelocations
)
4353 teximagemultisample(2, target
, samples
, internalformat
,
4354 width
, height
, 1, fixedsamplelocations
, GL_TRUE
, "glTexStorage2DMultisample");
4358 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4359 GLenum internalformat
, GLsizei width
,
4360 GLsizei height
, GLsizei depth
,
4361 GLboolean fixedsamplelocations
)
4363 teximagemultisample(3, target
, samples
, internalformat
,
4364 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
, "glTexStorage3DMultisample");