2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
43 #include "multisample.h"
45 #include "texcompress.h"
46 #include "texcompress_cpal.h"
50 #include "texstorage.h"
51 #include "textureview.h"
53 #include "glformats.h"
58 * State changes which we care about for glCopyTex[Sub]Image() calls.
59 * In particular, we care about pixel transfer state and buffer state
60 * (such as glReadBuffer to make sure we read from the right renderbuffer).
62 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
67 * Return the simple base format for a given internal texture format.
68 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
70 * \param ctx GL context.
71 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
73 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
74 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
76 * This is the format which is used during texture application (i.e. the
77 * texture format and env mode determine the arithmetic used.
80 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
82 switch (internalFormat
) {
88 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
95 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
97 case GL_LUMINANCE_ALPHA
:
98 case GL_LUMINANCE4_ALPHA4
:
99 case GL_LUMINANCE6_ALPHA2
:
100 case GL_LUMINANCE8_ALPHA8
:
101 case GL_LUMINANCE12_ALPHA4
:
102 case GL_LUMINANCE12_ALPHA12
:
103 case GL_LUMINANCE16_ALPHA16
:
104 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
110 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
112 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
123 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
137 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
139 if (_mesa_is_gles(ctx
)) {
140 switch (internalFormat
) {
148 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
149 switch (internalFormat
) {
157 if (ctx
->Extensions
.ARB_depth_texture
) {
158 switch (internalFormat
) {
159 case GL_DEPTH_COMPONENT
:
160 case GL_DEPTH_COMPONENT16
:
161 case GL_DEPTH_COMPONENT24
:
162 case GL_DEPTH_COMPONENT32
:
163 return GL_DEPTH_COMPONENT
;
164 case GL_DEPTH_STENCIL
:
165 case GL_DEPTH24_STENCIL8
:
166 return GL_DEPTH_STENCIL
;
172 switch (internalFormat
) {
173 case GL_COMPRESSED_ALPHA
:
175 case GL_COMPRESSED_LUMINANCE
:
177 case GL_COMPRESSED_LUMINANCE_ALPHA
:
178 return GL_LUMINANCE_ALPHA
;
179 case GL_COMPRESSED_INTENSITY
:
181 case GL_COMPRESSED_RGB
:
183 case GL_COMPRESSED_RGBA
:
189 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
190 switch (internalFormat
) {
191 case GL_COMPRESSED_RGB_FXT1_3DFX
:
193 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
200 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
202 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
203 switch (internalFormat
) {
204 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
206 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
207 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
208 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
215 if (_mesa_is_desktop_gl(ctx
)
216 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
217 switch (internalFormat
) {
229 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
230 if (internalFormat
== GL_YCBCR_MESA
)
231 return GL_YCBCR_MESA
;
234 if (ctx
->Extensions
.ARB_texture_float
) {
235 switch (internalFormat
) {
236 case GL_ALPHA16F_ARB
:
237 case GL_ALPHA32F_ARB
:
245 case GL_INTENSITY16F_ARB
:
246 case GL_INTENSITY32F_ARB
:
248 case GL_LUMINANCE16F_ARB
:
249 case GL_LUMINANCE32F_ARB
:
251 case GL_LUMINANCE_ALPHA16F_ARB
:
252 case GL_LUMINANCE_ALPHA32F_ARB
:
253 return GL_LUMINANCE_ALPHA
;
259 if (ctx
->Extensions
.EXT_texture_snorm
) {
260 switch (internalFormat
) {
275 case GL_RGBA16_SNORM
:
278 case GL_ALPHA8_SNORM
:
279 case GL_ALPHA16_SNORM
:
281 case GL_LUMINANCE_SNORM
:
282 case GL_LUMINANCE8_SNORM
:
283 case GL_LUMINANCE16_SNORM
:
285 case GL_LUMINANCE_ALPHA_SNORM
:
286 case GL_LUMINANCE8_ALPHA8_SNORM
:
287 case GL_LUMINANCE16_ALPHA16_SNORM
:
288 return GL_LUMINANCE_ALPHA
;
289 case GL_INTENSITY_SNORM
:
290 case GL_INTENSITY8_SNORM
:
291 case GL_INTENSITY16_SNORM
:
298 if (ctx
->Extensions
.EXT_texture_sRGB
) {
299 switch (internalFormat
) {
302 case GL_COMPRESSED_SRGB_EXT
:
304 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
305 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
306 case GL_SRGB_ALPHA_EXT
:
307 case GL_SRGB8_ALPHA8_EXT
:
308 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
310 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
311 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
312 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
313 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
314 case GL_SLUMINANCE_ALPHA_EXT
:
315 case GL_SLUMINANCE8_ALPHA8_EXT
:
316 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
317 return GL_LUMINANCE_ALPHA
;
318 case GL_SLUMINANCE_EXT
:
319 case GL_SLUMINANCE8_EXT
:
320 case GL_COMPRESSED_SLUMINANCE_EXT
:
327 if (ctx
->Version
>= 30 ||
328 ctx
->Extensions
.EXT_texture_integer
) {
329 switch (internalFormat
) {
331 case GL_RGBA16UI_EXT
:
332 case GL_RGBA32UI_EXT
:
348 if (ctx
->Extensions
.EXT_texture_integer
) {
349 switch (internalFormat
) {
350 case GL_ALPHA8UI_EXT
:
351 case GL_ALPHA16UI_EXT
:
352 case GL_ALPHA32UI_EXT
:
354 case GL_ALPHA16I_EXT
:
355 case GL_ALPHA32I_EXT
:
357 case GL_INTENSITY8UI_EXT
:
358 case GL_INTENSITY16UI_EXT
:
359 case GL_INTENSITY32UI_EXT
:
360 case GL_INTENSITY8I_EXT
:
361 case GL_INTENSITY16I_EXT
:
362 case GL_INTENSITY32I_EXT
:
364 case GL_LUMINANCE8UI_EXT
:
365 case GL_LUMINANCE16UI_EXT
:
366 case GL_LUMINANCE32UI_EXT
:
367 case GL_LUMINANCE8I_EXT
:
368 case GL_LUMINANCE16I_EXT
:
369 case GL_LUMINANCE32I_EXT
:
371 case GL_LUMINANCE_ALPHA8UI_EXT
:
372 case GL_LUMINANCE_ALPHA16UI_EXT
:
373 case GL_LUMINANCE_ALPHA32UI_EXT
:
374 case GL_LUMINANCE_ALPHA8I_EXT
:
375 case GL_LUMINANCE_ALPHA16I_EXT
:
376 case GL_LUMINANCE_ALPHA32I_EXT
:
377 return GL_LUMINANCE_ALPHA
;
383 if (ctx
->Extensions
.ARB_texture_rg
) {
384 switch (internalFormat
) {
387 if (!ctx
->Extensions
.ARB_texture_float
)
396 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
402 case GL_COMPRESSED_RED
:
407 if (!ctx
->Extensions
.ARB_texture_float
)
416 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
422 case GL_COMPRESSED_RG
:
429 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
430 switch (internalFormat
) {
438 if (ctx
->Extensions
.EXT_packed_float
) {
439 switch (internalFormat
) {
440 case GL_R11F_G11F_B10F_EXT
:
447 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
448 switch (internalFormat
) {
449 case GL_DEPTH_COMPONENT32F
:
450 return GL_DEPTH_COMPONENT
;
451 case GL_DEPTH32F_STENCIL8
:
452 return GL_DEPTH_STENCIL
;
458 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
459 switch (internalFormat
) {
460 case GL_COMPRESSED_RED_RGTC1
:
461 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
463 case GL_COMPRESSED_RG_RGTC2
:
464 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
471 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
472 switch (internalFormat
) {
473 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
474 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
476 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
477 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
478 return GL_LUMINANCE_ALPHA
;
484 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
485 switch (internalFormat
) {
486 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
487 return GL_LUMINANCE_ALPHA
;
493 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
494 switch (internalFormat
) {
495 case GL_ETC1_RGB8_OES
:
502 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
503 switch (internalFormat
) {
504 case GL_COMPRESSED_RGB8_ETC2
:
505 case GL_COMPRESSED_SRGB8_ETC2
:
507 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
508 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
509 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
510 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
512 case GL_COMPRESSED_R11_EAC
:
513 case GL_COMPRESSED_SIGNED_R11_EAC
:
515 case GL_COMPRESSED_RG11_EAC
:
516 case GL_COMPRESSED_SIGNED_RG11_EAC
:
523 if (_mesa_is_desktop_gl(ctx
) &&
524 ctx
->Extensions
.ARB_texture_compression_bptc
) {
525 switch (internalFormat
) {
526 case GL_COMPRESSED_RGBA_BPTC_UNORM
:
527 case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM
:
529 case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT
:
530 case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT
:
537 if (ctx
->API
== API_OPENGLES
) {
538 switch (internalFormat
) {
539 case GL_PALETTE4_RGB8_OES
:
540 case GL_PALETTE4_R5_G6_B5_OES
:
541 case GL_PALETTE8_RGB8_OES
:
542 case GL_PALETTE8_R5_G6_B5_OES
:
544 case GL_PALETTE4_RGBA8_OES
:
545 case GL_PALETTE8_RGB5_A1_OES
:
546 case GL_PALETTE4_RGBA4_OES
:
547 case GL_PALETTE4_RGB5_A1_OES
:
548 case GL_PALETTE8_RGBA8_OES
:
549 case GL_PALETTE8_RGBA4_OES
:
556 return -1; /* error */
561 * For cube map faces, return a face index in [0,5].
562 * For other targets return 0;
565 _mesa_tex_target_to_face(GLenum target
)
567 if (_mesa_is_cube_face(target
))
568 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
576 * Install gl_texture_image in a gl_texture_object according to the target
577 * and level parameters.
579 * \param tObj texture object.
580 * \param target texture target.
581 * \param level image level.
582 * \param texImage texture image.
585 set_tex_image(struct gl_texture_object
*tObj
,
586 GLenum target
, GLint level
,
587 struct gl_texture_image
*texImage
)
589 const GLuint face
= _mesa_tex_target_to_face(target
);
593 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
596 tObj
->Image
[face
][level
] = texImage
;
598 /* Set the 'back' pointer */
599 texImage
->TexObject
= tObj
;
600 texImage
->Level
= level
;
601 texImage
->Face
= face
;
606 * Allocate a texture image structure.
608 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
611 * \return a pointer to gl_texture_image struct with all fields initialized to
614 struct gl_texture_image
*
615 _mesa_new_texture_image( struct gl_context
*ctx
)
618 return CALLOC_STRUCT(gl_texture_image
);
623 * Free a gl_texture_image and associated data.
624 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
626 * \param texImage texture image.
628 * Free the texture image structure and the associated image data.
631 _mesa_delete_texture_image(struct gl_context
*ctx
,
632 struct gl_texture_image
*texImage
)
634 /* Free texImage->Data and/or any other driver-specific texture
637 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
638 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
644 * Test if a target is a proxy target.
646 * \param target texture target.
648 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
651 _mesa_is_proxy_texture(GLenum target
)
654 static const GLenum targets
[] = {
658 GL_PROXY_TEXTURE_CUBE_MAP
,
659 GL_PROXY_TEXTURE_RECTANGLE
,
660 GL_PROXY_TEXTURE_1D_ARRAY
,
661 GL_PROXY_TEXTURE_2D_ARRAY
,
662 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
663 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
664 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
667 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
668 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
670 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== Elements(targets
) + 2);
672 for (i
= 0; i
< Elements(targets
); ++i
)
673 if (target
== targets
[i
])
680 * Return the proxy target which corresponds to the given texture target
683 proxy_target(GLenum target
)
687 case GL_PROXY_TEXTURE_1D
:
688 return GL_PROXY_TEXTURE_1D
;
690 case GL_PROXY_TEXTURE_2D
:
691 return GL_PROXY_TEXTURE_2D
;
693 case GL_PROXY_TEXTURE_3D
:
694 return GL_PROXY_TEXTURE_3D
;
695 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
696 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
697 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
698 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
699 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
700 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
701 case GL_TEXTURE_CUBE_MAP_ARB
:
702 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
703 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
704 case GL_TEXTURE_RECTANGLE_NV
:
705 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
706 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
707 case GL_TEXTURE_1D_ARRAY_EXT
:
708 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
709 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
710 case GL_TEXTURE_2D_ARRAY_EXT
:
711 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
712 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
713 case GL_TEXTURE_CUBE_MAP_ARRAY
:
714 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
715 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
716 case GL_TEXTURE_2D_MULTISAMPLE
:
717 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
718 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
719 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
720 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
721 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
723 _mesa_problem(NULL
, "unexpected target in proxy_target()");
730 * Return a pointer to the current texture object for the given target
731 * on the current texture unit.
732 * Note: all <target> error checking should have been done by this point.
734 struct gl_texture_object
*
735 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
737 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
738 const GLboolean arrayTex
= ctx
->Extensions
.EXT_texture_array
;
742 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
743 case GL_PROXY_TEXTURE_1D
:
744 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
746 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
747 case GL_PROXY_TEXTURE_2D
:
748 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
750 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
751 case GL_PROXY_TEXTURE_3D
:
752 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
753 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
754 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
755 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
756 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
757 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
758 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
759 case GL_TEXTURE_CUBE_MAP_ARB
:
760 return ctx
->Extensions
.ARB_texture_cube_map
761 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
762 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
763 return ctx
->Extensions
.ARB_texture_cube_map
764 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
765 case GL_TEXTURE_CUBE_MAP_ARRAY
:
766 return ctx
->Extensions
.ARB_texture_cube_map_array
767 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
768 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
769 return ctx
->Extensions
.ARB_texture_cube_map_array
770 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
771 case GL_TEXTURE_RECTANGLE_NV
:
772 return ctx
->Extensions
.NV_texture_rectangle
773 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
774 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
775 return ctx
->Extensions
.NV_texture_rectangle
776 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
777 case GL_TEXTURE_1D_ARRAY_EXT
:
778 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
779 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
780 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
781 case GL_TEXTURE_2D_ARRAY_EXT
:
782 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
783 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
784 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
785 case GL_TEXTURE_BUFFER
:
786 return ctx
->API
== API_OPENGL_CORE
&&
787 ctx
->Extensions
.ARB_texture_buffer_object
?
788 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
789 case GL_TEXTURE_EXTERNAL_OES
:
790 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
791 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
792 case GL_TEXTURE_2D_MULTISAMPLE
:
793 return ctx
->Extensions
.ARB_texture_multisample
794 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
795 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
796 return ctx
->Extensions
.ARB_texture_multisample
797 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
798 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
799 return ctx
->Extensions
.ARB_texture_multisample
800 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
801 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
802 return ctx
->Extensions
.ARB_texture_multisample
803 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
805 _mesa_problem(NULL
, "bad target in _mesa_get_current_tex_object()");
813 * Get a texture image pointer from a texture object, given a texture
814 * target and mipmap level. The target and level parameters should
815 * have already been error-checked.
817 * \param ctx GL context.
818 * \param texObj texture unit.
819 * \param target texture target.
820 * \param level image level.
822 * \return pointer to the texture image structure, or NULL on failure.
824 struct gl_texture_image
*
825 _mesa_select_tex_image(struct gl_context
*ctx
,
826 const struct gl_texture_object
*texObj
,
827 GLenum target
, GLint level
)
829 const GLuint face
= _mesa_tex_target_to_face(target
);
833 ASSERT(level
< MAX_TEXTURE_LEVELS
);
835 return texObj
->Image
[face
][level
];
840 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
841 * it and install it. Only return NULL if passed a bad parameter or run
844 struct gl_texture_image
*
845 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
846 GLenum target
, GLint level
)
848 struct gl_texture_image
*texImage
;
853 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
855 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
857 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
861 set_tex_image(texObj
, target
, level
, texImage
);
869 * Return pointer to the specified proxy texture image.
870 * Note that proxy textures are per-context, not per-texture unit.
871 * \return pointer to texture image or NULL if invalid target, invalid
872 * level, or out of memory.
874 static struct gl_texture_image
*
875 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
877 struct gl_texture_image
*texImage
;
884 case GL_PROXY_TEXTURE_1D
:
885 if (level
>= ctx
->Const
.MaxTextureLevels
)
887 texIndex
= TEXTURE_1D_INDEX
;
889 case GL_PROXY_TEXTURE_2D
:
890 if (level
>= ctx
->Const
.MaxTextureLevels
)
892 texIndex
= TEXTURE_2D_INDEX
;
894 case GL_PROXY_TEXTURE_3D
:
895 if (level
>= ctx
->Const
.Max3DTextureLevels
)
897 texIndex
= TEXTURE_3D_INDEX
;
899 case GL_PROXY_TEXTURE_CUBE_MAP
:
900 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
902 texIndex
= TEXTURE_CUBE_INDEX
;
904 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
907 texIndex
= TEXTURE_RECT_INDEX
;
909 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
910 if (level
>= ctx
->Const
.MaxTextureLevels
)
912 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
914 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
915 if (level
>= ctx
->Const
.MaxTextureLevels
)
917 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
919 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
920 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
922 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
924 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
927 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
929 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
932 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
938 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
940 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
942 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
945 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
946 /* Set the 'back' pointer */
947 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
954 * Get the maximum number of allowed mipmap levels.
956 * \param ctx GL context.
957 * \param target texture target.
959 * \return the maximum number of allowed mipmap levels for the given
960 * texture target, or zero if passed a bad target.
965 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
969 case GL_PROXY_TEXTURE_1D
:
971 case GL_PROXY_TEXTURE_2D
:
972 return ctx
->Const
.MaxTextureLevels
;
974 case GL_PROXY_TEXTURE_3D
:
975 return ctx
->Const
.Max3DTextureLevels
;
976 case GL_TEXTURE_CUBE_MAP
:
977 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
978 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
979 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
980 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
981 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
982 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
983 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
984 return ctx
->Extensions
.ARB_texture_cube_map
985 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
986 case GL_TEXTURE_RECTANGLE_NV
:
987 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
988 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
989 case GL_TEXTURE_1D_ARRAY_EXT
:
990 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
991 case GL_TEXTURE_2D_ARRAY_EXT
:
992 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
993 return ctx
->Extensions
.EXT_texture_array
994 ? ctx
->Const
.MaxTextureLevels
: 0;
995 case GL_TEXTURE_CUBE_MAP_ARRAY
:
996 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
997 return ctx
->Extensions
.ARB_texture_cube_map_array
998 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
999 case GL_TEXTURE_BUFFER
:
1000 return ctx
->API
== API_OPENGL_CORE
&&
1001 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1002 case GL_TEXTURE_2D_MULTISAMPLE
:
1003 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1004 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1005 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1006 return _mesa_is_desktop_gl(ctx
)
1007 && ctx
->Extensions
.ARB_texture_multisample
1009 case GL_TEXTURE_EXTERNAL_OES
:
1012 return 0; /* bad target */
1018 * Return number of dimensions per mipmap level for the given texture target.
1021 _mesa_get_texture_dimensions(GLenum target
)
1025 case GL_PROXY_TEXTURE_1D
:
1028 case GL_TEXTURE_RECTANGLE
:
1029 case GL_TEXTURE_CUBE_MAP
:
1030 case GL_PROXY_TEXTURE_2D
:
1031 case GL_PROXY_TEXTURE_RECTANGLE
:
1032 case GL_PROXY_TEXTURE_CUBE_MAP
:
1033 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1034 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1035 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1036 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1037 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1038 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1039 case GL_TEXTURE_1D_ARRAY
:
1040 case GL_PROXY_TEXTURE_1D_ARRAY
:
1041 case GL_TEXTURE_EXTERNAL_OES
:
1042 case GL_TEXTURE_2D_MULTISAMPLE
:
1043 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1046 case GL_PROXY_TEXTURE_3D
:
1047 case GL_TEXTURE_2D_ARRAY
:
1048 case GL_PROXY_TEXTURE_2D_ARRAY
:
1049 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1050 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1051 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1052 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1054 case GL_TEXTURE_BUFFER
:
1057 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1065 * Check if a texture target can have more than one layer.
1068 _mesa_tex_target_is_layered(GLenum target
)
1072 case GL_PROXY_TEXTURE_1D
:
1074 case GL_PROXY_TEXTURE_2D
:
1075 case GL_TEXTURE_RECTANGLE
:
1076 case GL_PROXY_TEXTURE_RECTANGLE
:
1077 case GL_TEXTURE_2D_MULTISAMPLE
:
1078 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1079 case GL_TEXTURE_BUFFER
:
1080 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1081 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1082 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1083 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1084 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1085 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1086 case GL_TEXTURE_EXTERNAL_OES
:
1090 case GL_PROXY_TEXTURE_3D
:
1091 case GL_TEXTURE_CUBE_MAP
:
1092 case GL_PROXY_TEXTURE_CUBE_MAP
:
1093 case GL_TEXTURE_1D_ARRAY
:
1094 case GL_PROXY_TEXTURE_1D_ARRAY
:
1095 case GL_TEXTURE_2D_ARRAY
:
1096 case GL_PROXY_TEXTURE_2D_ARRAY
:
1097 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1098 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1099 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1100 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1104 assert(!"Invalid texture target.");
1111 * Return the number of layers present in the given level of an array,
1112 * cubemap or 3D texture. If the texture is not layered return zero.
1115 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1117 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1119 switch (texObj
->Target
) {
1122 case GL_TEXTURE_RECTANGLE
:
1123 case GL_TEXTURE_2D_MULTISAMPLE
:
1124 case GL_TEXTURE_BUFFER
:
1125 case GL_TEXTURE_EXTERNAL_OES
:
1128 case GL_TEXTURE_CUBE_MAP
:
1131 case GL_TEXTURE_1D_ARRAY
: {
1132 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1133 return img
? img
->Height
: 0;
1137 case GL_TEXTURE_2D_ARRAY
:
1138 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1139 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1140 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1141 return img
? img
->Depth
: 0;
1145 assert(!"Invalid texture target.");
1152 * Return the maximum number of mipmap levels for the given target
1153 * and the dimensions.
1154 * The dimensions are expected not to include the border.
1157 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1164 case GL_TEXTURE_1D_ARRAY
:
1165 case GL_PROXY_TEXTURE_1D
:
1166 case GL_PROXY_TEXTURE_1D_ARRAY
:
1169 case GL_TEXTURE_CUBE_MAP
:
1170 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1171 case GL_PROXY_TEXTURE_CUBE_MAP
:
1172 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1176 case GL_TEXTURE_2D_ARRAY
:
1177 case GL_PROXY_TEXTURE_2D
:
1178 case GL_PROXY_TEXTURE_2D_ARRAY
:
1179 size
= MAX2(width
, height
);
1182 case GL_PROXY_TEXTURE_3D
:
1183 size
= MAX3(width
, height
, depth
);
1185 case GL_TEXTURE_RECTANGLE
:
1186 case GL_TEXTURE_EXTERNAL_OES
:
1187 case GL_TEXTURE_2D_MULTISAMPLE
:
1188 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1189 case GL_PROXY_TEXTURE_RECTANGLE
:
1190 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1191 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1198 return _mesa_logbase2(size
) + 1;
1202 #if 000 /* not used anymore */
1204 * glTexImage[123]D can accept a NULL image pointer. In this case we
1205 * create a texture image with unspecified image contents per the OpenGL
1209 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1211 const GLint components
= _mesa_components_in_format(format
);
1212 const GLint numPixels
= width
* height
* depth
;
1213 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1217 * Let's see if anyone finds this. If glTexImage2D() is called with
1218 * a NULL image pointer then load the texture image with something
1219 * interesting instead of leaving it indeterminate.
1222 static const char message
[8][32] = {
1223 " X X XXXXX XXX X ",
1224 " XX XX X X X X X ",
1226 " X X XXXX XXX XXXXX ",
1229 " X X XXXXX XXX X X ",
1233 GLubyte
*imgPtr
= data
;
1235 for (h
= 0; h
< depth
; h
++) {
1236 for (i
= 0; i
< height
; i
++) {
1237 GLint srcRow
= 7 - (i
% 8);
1238 for (j
= 0; j
< width
; j
++) {
1239 GLint srcCol
= j
% 32;
1240 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1241 for (k
= 0; k
< components
; k
++) {
1257 * Set the size and format-related fields of a gl_texture_image struct
1258 * to zero. This is used when a proxy texture test fails.
1261 clear_teximage_fields(struct gl_texture_image
*img
)
1264 img
->_BaseFormat
= 0;
1265 img
->InternalFormat
= 0;
1274 img
->HeightLog2
= 0;
1276 img
->TexFormat
= MESA_FORMAT_NONE
;
1277 img
->NumSamples
= 0;
1278 img
->FixedSampleLocations
= GL_TRUE
;
1283 * Initialize basic fields of the gl_texture_image struct.
1285 * \param ctx GL context.
1286 * \param img texture image structure to be initialized.
1287 * \param width image width.
1288 * \param height image height.
1289 * \param depth image depth.
1290 * \param border image border.
1291 * \param internalFormat internal format.
1292 * \param format the actual hardware format (one of MESA_FORMAT_*)
1293 * \param numSamples number of samples per texel, or zero for non-MS.
1294 * \param fixedSampleLocations are sample locations fixed?
1296 * Fills in the fields of \p img with the given information.
1297 * Note: width, height and depth include the border.
1300 init_teximage_fields_ms(struct gl_context
*ctx
,
1301 struct gl_texture_image
*img
,
1302 GLsizei width
, GLsizei height
, GLsizei depth
,
1303 GLint border
, GLenum internalFormat
,
1305 GLuint numSamples
, GLboolean fixedSampleLocations
)
1310 ASSERT(height
>= 0);
1313 target
= img
->TexObject
->Target
;
1314 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1315 ASSERT(img
->_BaseFormat
> 0);
1316 img
->InternalFormat
= internalFormat
;
1317 img
->Border
= border
;
1319 img
->Height
= height
;
1322 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1323 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1325 img
->NumSamples
= 0;
1326 img
->FixedSampleLocations
= GL_TRUE
;
1330 case GL_TEXTURE_BUFFER
:
1331 case GL_PROXY_TEXTURE_1D
:
1336 img
->HeightLog2
= 0;
1343 case GL_TEXTURE_1D_ARRAY
:
1344 case GL_PROXY_TEXTURE_1D_ARRAY
:
1345 img
->Height2
= height
; /* no border */
1346 img
->HeightLog2
= 0; /* not used */
1354 case GL_TEXTURE_RECTANGLE
:
1355 case GL_TEXTURE_CUBE_MAP
:
1356 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1357 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1358 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1359 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1360 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1361 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1362 case GL_TEXTURE_EXTERNAL_OES
:
1363 case GL_PROXY_TEXTURE_2D
:
1364 case GL_PROXY_TEXTURE_RECTANGLE
:
1365 case GL_PROXY_TEXTURE_CUBE_MAP
:
1366 case GL_TEXTURE_2D_MULTISAMPLE
:
1367 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1368 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1369 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1376 case GL_TEXTURE_2D_ARRAY
:
1377 case GL_PROXY_TEXTURE_2D_ARRAY
:
1378 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1379 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1380 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1381 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1382 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1383 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1384 img
->Depth2
= depth
; /* no border */
1385 img
->DepthLog2
= 0; /* not used */
1388 case GL_PROXY_TEXTURE_3D
:
1389 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1390 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1391 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1392 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1395 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1400 _mesa_get_tex_max_num_levels(target
,
1401 img
->Width2
, img
->Height2
, img
->Depth2
);
1402 img
->TexFormat
= format
;
1403 img
->NumSamples
= numSamples
;
1404 img
->FixedSampleLocations
= fixedSampleLocations
;
1409 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1410 struct gl_texture_image
*img
,
1411 GLsizei width
, GLsizei height
, GLsizei depth
,
1412 GLint border
, GLenum internalFormat
,
1415 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1416 internalFormat
, format
, 0, GL_TRUE
);
1421 * Free and clear fields of the gl_texture_image struct.
1423 * \param ctx GL context.
1424 * \param texImage texture image structure to be cleared.
1426 * After the call, \p texImage will have no data associated with it. Its
1427 * fields are cleared so that its parent object will test incomplete.
1430 _mesa_clear_texture_image(struct gl_context
*ctx
,
1431 struct gl_texture_image
*texImage
)
1433 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1434 clear_teximage_fields(texImage
);
1439 * Check the width, height, depth and border of a texture image are legal.
1440 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1442 * The target and level parameters will have already been validated.
1443 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1446 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1447 GLint level
, GLint width
, GLint height
,
1448 GLint depth
, GLint border
)
1454 case GL_PROXY_TEXTURE_1D
:
1455 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1456 maxSize
>>= level
; /* level size */
1457 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1459 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1460 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1466 case GL_PROXY_TEXTURE_2D
:
1467 case GL_TEXTURE_2D_MULTISAMPLE
:
1468 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1469 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1471 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1473 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1475 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1476 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1478 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1484 case GL_PROXY_TEXTURE_3D
:
1485 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1487 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1489 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1491 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1493 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1494 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1496 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1498 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1503 case GL_TEXTURE_RECTANGLE_NV
:
1504 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1507 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1508 if (width
< 0 || width
> maxSize
)
1510 if (height
< 0 || height
> maxSize
)
1514 case GL_TEXTURE_CUBE_MAP
:
1515 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1516 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1517 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1518 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1519 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1520 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1521 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1522 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1524 if (width
!= height
)
1526 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1528 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1530 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1531 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1533 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1538 case GL_TEXTURE_1D_ARRAY_EXT
:
1539 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1540 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1542 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1544 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1546 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1547 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1552 case GL_TEXTURE_2D_ARRAY_EXT
:
1553 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1554 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1555 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1556 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1558 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1560 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1562 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1564 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1565 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1567 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1572 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1573 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1574 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1575 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1577 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1579 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1581 if (width
!= height
)
1583 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1585 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1586 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1588 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1593 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1600 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1601 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1602 * \param destImage the destination texture image.
1603 * \return GL_TRUE if error found, GL_FALSE otherwise.
1606 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1607 const char *function
, GLuint dims
,
1608 const struct gl_texture_image
*destImage
,
1609 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1610 GLsizei subWidth
, GLsizei subHeight
,
1613 const GLenum target
= destImage
->TexObject
->Target
;
1618 _mesa_error(ctx
, GL_INVALID_VALUE
,
1619 "%s%dD(width=%d)", function
, dims
, subWidth
);
1623 if (dims
> 1 && subHeight
< 0) {
1624 _mesa_error(ctx
, GL_INVALID_VALUE
,
1625 "%s%dD(height=%d)", function
, dims
, subHeight
);
1629 if (dims
> 2 && subDepth
< 0) {
1630 _mesa_error(ctx
, GL_INVALID_VALUE
,
1631 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1635 /* check xoffset and width */
1636 if (xoffset
< - (GLint
) destImage
->Border
) {
1637 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1642 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1643 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1648 /* check yoffset and height */
1650 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1651 if (yoffset
< -yBorder
) {
1652 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1656 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1657 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1663 /* check zoffset and depth */
1665 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1666 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1667 0 : destImage
->Border
;
1669 if (zoffset
< -zBorder
) {
1670 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1673 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1674 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1680 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1681 * compressed texture images can be updated. But, that restriction may be
1682 * relaxed for particular compressed formats. At this time, all the
1683 * compressed formats supported by Mesa allow sub-textures to be updated
1684 * along compressed block boundaries.
1686 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1688 if (bw
!= 1 || bh
!= 1) {
1689 /* offset must be multiple of block size */
1690 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1691 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1692 "%s%dD(xoffset = %d, yoffset = %d)",
1693 function
, dims
, xoffset
, yoffset
);
1697 /* The size must be a multiple of bw x bh, or we must be using a
1698 * offset+size that exactly hits the edge of the image. This
1699 * is important for small mipmap levels (1x1, 2x1, etc) and for
1702 if ((subWidth
% bw
!= 0) &&
1703 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1704 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1705 "%s%dD(width = %d)", function
, dims
, subWidth
);
1709 if ((subHeight
% bh
!= 0) &&
1710 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1711 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1712 "%s%dD(height = %d)", function
, dims
, subHeight
);
1724 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1725 * specific texture image size checks.
1727 * A hardware driver might override this function if, for example, the
1728 * max 3D texture size is 512x512x64 (i.e. not a cube).
1730 * Note that width, height, depth == 0 is not an error. However, a
1731 * texture with zero width/height/depth will be considered "incomplete"
1732 * and texturing will effectively be disabled.
1734 * \param target any texture target/type
1735 * \param level as passed to glTexImage
1736 * \param format the MESA_FORMAT_x for the tex image
1737 * \param width as passed to glTexImage
1738 * \param height as passed to glTexImage
1739 * \param depth as passed to glTexImage
1740 * \param border as passed to glTexImage
1741 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1744 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1746 GLint width
, GLint height
, GLint depth
, GLint border
)
1748 /* We just check if the image size is less than MaxTextureMbytes.
1749 * Some drivers may do more specific checks.
1751 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1752 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1753 mbytes
*= _mesa_num_tex_faces(target
);
1754 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1759 * Return true if the format is only valid for glCompressedTexImage.
1762 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1765 case GL_ETC1_RGB8_OES
:
1766 case GL_PALETTE4_RGB8_OES
:
1767 case GL_PALETTE4_RGBA8_OES
:
1768 case GL_PALETTE4_R5_G6_B5_OES
:
1769 case GL_PALETTE4_RGBA4_OES
:
1770 case GL_PALETTE4_RGB5_A1_OES
:
1771 case GL_PALETTE8_RGB8_OES
:
1772 case GL_PALETTE8_RGBA8_OES
:
1773 case GL_PALETTE8_R5_G6_B5_OES
:
1774 case GL_PALETTE8_RGBA4_OES
:
1775 case GL_PALETTE8_RGB5_A1_OES
:
1784 * Helper function to determine whether a target and specific compression
1785 * format are supported.
1788 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1791 (void) intFormat
; /* not used yet */
1795 case GL_PROXY_TEXTURE_2D
:
1796 return GL_TRUE
; /* true for any compressed format so far */
1797 case GL_PROXY_TEXTURE_CUBE_MAP
:
1798 case GL_TEXTURE_CUBE_MAP
:
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_PROXY_TEXTURE_2D_ARRAY_EXT
:
1807 case GL_TEXTURE_2D_ARRAY_EXT
:
1808 return ctx
->Extensions
.EXT_texture_array
;
1809 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1810 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1811 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1819 * Check if the given texture target value is legal for a
1820 * glTexImage1/2/3D call.
1823 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1829 case GL_PROXY_TEXTURE_1D
:
1830 return _mesa_is_desktop_gl(ctx
);
1838 case GL_PROXY_TEXTURE_2D
:
1839 return _mesa_is_desktop_gl(ctx
);
1840 case GL_PROXY_TEXTURE_CUBE_MAP
:
1841 return _mesa_is_desktop_gl(ctx
)
1842 && ctx
->Extensions
.ARB_texture_cube_map
;
1843 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1844 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1845 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1846 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1847 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1848 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1849 return ctx
->Extensions
.ARB_texture_cube_map
;
1850 case GL_TEXTURE_RECTANGLE_NV
:
1851 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1852 return _mesa_is_desktop_gl(ctx
)
1853 && ctx
->Extensions
.NV_texture_rectangle
;
1854 case GL_TEXTURE_1D_ARRAY_EXT
:
1855 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1856 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1864 case GL_PROXY_TEXTURE_3D
:
1865 return _mesa_is_desktop_gl(ctx
);
1866 case GL_TEXTURE_2D_ARRAY_EXT
:
1867 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1868 || _mesa_is_gles3(ctx
);
1869 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1870 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1871 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1872 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1873 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1878 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1885 * Check if the given texture target value is legal for a
1886 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1887 * The difference compared to legal_teximage_target() above is that
1888 * proxy targets are not supported.
1891 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1895 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1900 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1901 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1902 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1903 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1904 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1905 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1906 return ctx
->Extensions
.ARB_texture_cube_map
;
1907 case GL_TEXTURE_RECTANGLE_NV
:
1908 return _mesa_is_desktop_gl(ctx
)
1909 && ctx
->Extensions
.NV_texture_rectangle
;
1910 case GL_TEXTURE_1D_ARRAY_EXT
:
1911 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1919 case GL_TEXTURE_2D_ARRAY_EXT
:
1920 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1921 || _mesa_is_gles3(ctx
);
1922 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1923 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1924 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1929 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1937 * Helper function to determine if a texture object is mutable (in terms
1938 * of GL_ARB_texture_storage).
1941 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1943 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1944 return !texObj
->Immutable
;
1949 * Return expected size of a compressed texture.
1952 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1955 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1956 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1960 * Verify that a texture format is valid with a particular target
1962 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1963 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1966 * \param ctx GL context
1967 * \param target Texture target
1968 * \param internalFormat Internal format of the texture image
1969 * \param dimensions Dimensionality at the caller. This is \b not used
1970 * in the validation. It is only used when logging
1972 * \param caller Base name of the calling function (e.g.,
1973 * "glTexImage" or "glTexStorage").
1975 * \returns true if the combination is legal, false otherwise.
1978 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1979 GLenum target
, GLenum internalFormat
,
1980 unsigned dimensions
,
1983 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1984 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
1985 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1986 * Profile spec says:
1988 * "Textures with a base internal format of DEPTH_COMPONENT or
1989 * DEPTH_STENCIL are supported by texture image specification
1990 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1991 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1992 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1993 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1994 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1995 * formats in conjunction with any other target will result in an
1996 * INVALID_OPERATION error."
1998 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1999 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
2001 if (target
!= GL_TEXTURE_1D
&&
2002 target
!= GL_PROXY_TEXTURE_1D
&&
2003 target
!= GL_TEXTURE_2D
&&
2004 target
!= GL_PROXY_TEXTURE_2D
&&
2005 target
!= GL_TEXTURE_1D_ARRAY
&&
2006 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2007 target
!= GL_TEXTURE_2D_ARRAY
&&
2008 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2009 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2010 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2011 !((_mesa_is_cube_face(target
) ||
2012 target
== GL_TEXTURE_CUBE_MAP
||
2013 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2014 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2015 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2016 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2017 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2018 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2019 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2020 "%s%dD(bad target for depth texture)",
2021 caller
, dimensions
);
2030 texture_formats_agree(GLenum internalFormat
,
2033 GLboolean colorFormat
;
2034 GLboolean is_format_depth_or_depthstencil
;
2035 GLboolean is_internalFormat_depth_or_depthstencil
;
2037 /* Even though there are no color-index textures, we still have to support
2038 * uploading color-index data and remapping it to RGB via the
2039 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2041 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2043 is_internalFormat_depth_or_depthstencil
=
2044 _mesa_is_depth_format(internalFormat
) ||
2045 _mesa_is_depthstencil_format(internalFormat
);
2047 is_format_depth_or_depthstencil
=
2048 _mesa_is_depth_format(format
) ||
2049 _mesa_is_depthstencil_format(format
);
2051 colorFormat
= _mesa_is_color_format(format
);
2053 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2056 if (is_internalFormat_depth_or_depthstencil
!=
2057 is_format_depth_or_depthstencil
)
2060 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2067 * Test the glTexImage[123]D() parameters for errors.
2069 * \param ctx GL context.
2070 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2071 * \param target texture target given by the user (already validated).
2072 * \param level image level given by the user.
2073 * \param internalFormat internal format given by the user.
2074 * \param format pixel data format given by the user.
2075 * \param type pixel data type given by the user.
2076 * \param width image width given by the user.
2077 * \param height image height given by the user.
2078 * \param depth image depth given by the user.
2079 * \param border image border given by the user.
2081 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2083 * Verifies each of the parameters against the constants specified in
2084 * __struct gl_contextRec::Const and the supported extensions, and according
2085 * to the OpenGL specification.
2086 * Note that we don't fully error-check the width, height, depth values
2087 * here. That's done in _mesa_legal_texture_dimensions() which is used
2088 * by several other GL entrypoints. Plus, texture dims have a special
2089 * interaction with proxy textures.
2092 texture_error_check( struct gl_context
*ctx
,
2093 GLuint dimensions
, GLenum target
,
2094 GLint level
, GLint internalFormat
,
2095 GLenum format
, GLenum type
,
2096 GLint width
, GLint height
,
2097 GLint depth
, GLint border
)
2101 /* Note: for proxy textures, some error conditions immediately generate
2102 * a GL error in the usual way. But others do not generate a GL error.
2103 * Instead, they cause the width, height, depth, format fields of the
2104 * texture image to be zeroed-out. The GL spec seems to indicate that the
2105 * zero-out behaviour is only used in cases related to memory allocation.
2109 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2110 _mesa_error(ctx
, GL_INVALID_VALUE
,
2111 "glTexImage%dD(level=%d)", dimensions
, level
);
2116 if (border
< 0 || border
> 1 ||
2117 ((ctx
->API
!= API_OPENGL_COMPAT
||
2118 target
== GL_TEXTURE_RECTANGLE_NV
||
2119 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2120 _mesa_error(ctx
, GL_INVALID_VALUE
,
2121 "glTexImage%dD(border=%d)", dimensions
, border
);
2125 if (width
< 0 || height
< 0 || depth
< 0) {
2126 _mesa_error(ctx
, GL_INVALID_VALUE
,
2127 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2131 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2132 * combinations of format, internalFormat, and type that can be used.
2133 * Formats and types that require additional extensions (e.g., GL_FLOAT
2134 * requires GL_OES_texture_float) are filtered elsewhere.
2137 if (_mesa_is_gles(ctx
)) {
2138 if (_mesa_is_gles3(ctx
)) {
2139 err
= _mesa_es3_error_check_format_and_type(format
, type
,
2142 if (format
!= internalFormat
) {
2143 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2144 "glTexImage%dD(format = %s, internalFormat = %s)",
2146 _mesa_lookup_enum_by_nr(format
),
2147 _mesa_lookup_enum_by_nr(internalFormat
));
2151 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2153 if (err
!= GL_NO_ERROR
) {
2154 _mesa_error(ctx
, err
,
2155 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2157 _mesa_lookup_enum_by_nr(format
),
2158 _mesa_lookup_enum_by_nr(type
),
2159 _mesa_lookup_enum_by_nr(internalFormat
));
2164 /* Check internalFormat */
2165 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2166 _mesa_error(ctx
, GL_INVALID_VALUE
,
2167 "glTexImage%dD(internalFormat=%s)",
2168 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2172 /* Check incoming image format and type */
2173 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2174 if (err
!= GL_NO_ERROR
) {
2175 _mesa_error(ctx
, err
,
2176 "glTexImage%dD(incompatible format = %s, type = %s)",
2177 dimensions
, _mesa_lookup_enum_by_nr(format
),
2178 _mesa_lookup_enum_by_nr(type
));
2182 /* make sure internal format and format basically agree */
2183 if (!texture_formats_agree(internalFormat
, format
)) {
2184 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2185 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2186 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2187 _mesa_lookup_enum_by_nr(format
));
2191 /* additional checks for ycbcr textures */
2192 if (internalFormat
== GL_YCBCR_MESA
) {
2193 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2194 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2195 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2197 _mesa_snprintf(message
, sizeof(message
),
2198 "glTexImage%dD(format/type YCBCR mismatch)",
2200 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2201 return GL_TRUE
; /* error */
2203 if (target
!= GL_TEXTURE_2D
&&
2204 target
!= GL_PROXY_TEXTURE_2D
&&
2205 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2206 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2207 _mesa_error(ctx
, GL_INVALID_ENUM
,
2208 "glTexImage%dD(bad target for YCbCr texture)",
2214 _mesa_snprintf(message
, sizeof(message
),
2215 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2216 dimensions
, border
);
2217 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2222 /* additional checks for depth textures */
2223 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2224 dimensions
, "glTexImage"))
2227 /* additional checks for compressed textures */
2228 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2229 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2230 _mesa_error(ctx
, GL_INVALID_ENUM
,
2231 "glTexImage%dD(target can't be compressed)", dimensions
);
2234 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2235 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2236 "glTexImage%dD(no compression for format)", dimensions
);
2240 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2241 "glTexImage%dD(border!=0)", dimensions
);
2246 /* additional checks for integer textures */
2247 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2248 (_mesa_is_enum_format_integer(format
) !=
2249 _mesa_is_enum_format_integer(internalFormat
))) {
2250 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2251 "glTexImage%dD(integer/non-integer format mismatch)",
2256 if (!mutable_tex_object(ctx
, target
)) {
2257 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2258 "glTexImage%dD(immutable texture)", dimensions
);
2262 /* if we get here, the parameters are OK */
2268 _mesa_compressed_texture_pixel_storage_error_check(struct gl_context
*ctx
,
2270 struct gl_pixelstore_attrib
*packing
,
2273 if (!_mesa_is_desktop_gl(ctx
) || !packing
->CompressedBlockSize
)
2276 if (packing
->CompressedBlockWidth
&& packing
->SkipPixels
% packing
->CompressedBlockWidth
) {
2277 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2278 "%s(skip-pixels %% block-width)", caller
);
2282 if (dimensions
> 1 && packing
->CompressedBlockHeight
&& packing
->SkipRows
% packing
->CompressedBlockHeight
) {
2283 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2284 "%s(skip-rows %% block-height)", caller
);
2288 if (dimensions
> 2 && packing
->CompressedBlockDepth
&& packing
->SkipImages
% packing
->CompressedBlockDepth
) {
2289 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2290 "%s(skip-images %% block-depth)", caller
);
2298 * Error checking for glCompressedTexImage[123]D().
2299 * Note that the width, height and depth values are not fully error checked
2301 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2304 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2305 GLenum target
, GLint level
,
2306 GLenum internalFormat
, GLsizei width
,
2307 GLsizei height
, GLsizei depth
, GLint border
,
2310 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2312 GLenum error
= GL_NO_ERROR
;
2313 char *reason
= ""; /* no error */
2315 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2317 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
2319 * "The ETC2/EAC texture compression algorithm supports only
2320 * two-dimensional images. If internalformat is an ETC2/EAC format,
2321 * CompressedTexImage3D will generate an INVALID_OPERATION error if
2322 * target is not TEXTURE_2D_ARRAY."
2324 error
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
2328 /* This will detect any invalid internalFormat value */
2329 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2330 _mesa_error(ctx
, GL_INVALID_ENUM
,
2331 "glCompressedTexImage%dD(internalFormat=%s)",
2332 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2336 switch (internalFormat
) {
2337 case GL_PALETTE4_RGB8_OES
:
2338 case GL_PALETTE4_RGBA8_OES
:
2339 case GL_PALETTE4_R5_G6_B5_OES
:
2340 case GL_PALETTE4_RGBA4_OES
:
2341 case GL_PALETTE4_RGB5_A1_OES
:
2342 case GL_PALETTE8_RGB8_OES
:
2343 case GL_PALETTE8_RGBA8_OES
:
2344 case GL_PALETTE8_R5_G6_B5_OES
:
2345 case GL_PALETTE8_RGBA4_OES
:
2346 case GL_PALETTE8_RGB5_A1_OES
:
2347 /* check level (note that level should be zero or less!) */
2348 if (level
> 0 || level
< -maxLevels
) {
2350 error
= GL_INVALID_VALUE
;
2354 if (dimensions
!= 2) {
2355 reason
= "compressed paletted textures must be 2D";
2356 error
= GL_INVALID_OPERATION
;
2360 /* Figure out the expected texture size (in bytes). This will be
2361 * checked against the actual size later.
2363 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2366 /* This is for the benefit of the TestProxyTexImage below. It expects
2367 * level to be non-negative. OES_compressed_paletted_texture uses a
2368 * weird mechanism where the level specified to glCompressedTexImage2D
2369 * is -(n-1) number of levels in the texture, and the data specifies the
2370 * complete mipmap stack. This is done to ensure the palette is the
2371 * same for all levels.
2378 if (level
< 0 || level
>= maxLevels
) {
2380 error
= GL_INVALID_VALUE
;
2384 /* Figure out the expected texture size (in bytes). This will be
2385 * checked against the actual size later.
2387 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2391 /* This should really never fail */
2392 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2393 reason
= "internalFormat";
2394 error
= GL_INVALID_ENUM
;
2398 /* No compressed formats support borders at this time */
2400 reason
= "border != 0";
2401 error
= GL_INVALID_VALUE
;
2405 /* Check for invalid pixel storage modes */
2406 if (!_mesa_compressed_texture_pixel_storage_error_check(ctx
, dimensions
,
2408 "glCompressedTexImage")) {
2412 /* check image size in bytes */
2413 if (expectedSize
!= imageSize
) {
2414 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2415 * if <imageSize> is not consistent with the format, dimensions, and
2416 * contents of the specified image.
2418 reason
= "imageSize inconsistant with width/height/format";
2419 error
= GL_INVALID_VALUE
;
2423 if (!mutable_tex_object(ctx
, target
)) {
2424 reason
= "immutable texture";
2425 error
= GL_INVALID_OPERATION
;
2432 /* Note: not all error paths exit through here. */
2433 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2440 * Test glTexSubImage[123]D() parameters for errors.
2442 * \param ctx GL context.
2443 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2444 * \param target texture target given by the user (already validated)
2445 * \param level image level given by the user.
2446 * \param xoffset sub-image x offset given by the user.
2447 * \param yoffset sub-image y offset given by the user.
2448 * \param zoffset sub-image z offset given by the user.
2449 * \param format pixel data format given by the user.
2450 * \param type pixel data type given by the user.
2451 * \param width image width given by the user.
2452 * \param height image height given by the user.
2453 * \param depth image depth given by the user.
2455 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2457 * Verifies each of the parameters against the constants specified in
2458 * __struct gl_contextRec::Const and the supported extensions, and according
2459 * to the OpenGL specification.
2462 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2463 GLenum target
, GLint level
,
2464 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2465 GLint width
, GLint height
, GLint depth
,
2466 GLenum format
, GLenum type
)
2468 struct gl_texture_object
*texObj
;
2469 struct gl_texture_image
*texImage
;
2472 /* check target (proxies not allowed) */
2473 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2474 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2475 dimensions
, _mesa_lookup_enum_by_nr(target
));
2480 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2481 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2486 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2487 * combinations of format and type that can be used. Formats and types
2488 * that require additional extensions (e.g., GL_FLOAT requires
2489 * GL_OES_texture_float) are filtered elsewhere.
2491 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2492 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2493 if (err
!= GL_NO_ERROR
) {
2494 _mesa_error(ctx
, err
,
2495 "glTexSubImage%dD(format = %s, type = %s)",
2497 _mesa_lookup_enum_by_nr(format
),
2498 _mesa_lookup_enum_by_nr(type
));
2503 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2504 if (err
!= GL_NO_ERROR
) {
2505 _mesa_error(ctx
, err
,
2506 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2507 dimensions
, _mesa_lookup_enum_by_nr(format
),
2508 _mesa_lookup_enum_by_nr(type
));
2512 /* Get dest texture object / image pointers */
2513 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2515 /* must be out of memory */
2516 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2520 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2522 /* non-existant texture level */
2523 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2524 "glTexSubImage%dD(invalid texture image)", dimensions
);
2528 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2529 texImage
, xoffset
, yoffset
, 0,
2530 width
, height
, 1)) {
2534 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2535 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2536 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2537 "glTexSubImage%dD(no compression for format)", dimensions
);
2542 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2543 /* both source and dest must be integer-valued, or neither */
2544 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2545 _mesa_is_enum_format_integer(format
)) {
2546 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2547 "glTexSubImage%dD(integer/non-integer format mismatch)",
2558 * Test glCopyTexImage[12]D() parameters for errors.
2560 * \param ctx GL context.
2561 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2562 * \param target texture target given by the user.
2563 * \param level image level given by the user.
2564 * \param internalFormat internal format given by the user.
2565 * \param width image width given by the user.
2566 * \param height image height given by the user.
2567 * \param border texture border.
2569 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2571 * Verifies each of the parameters against the constants specified in
2572 * __struct gl_contextRec::Const and the supported extensions, and according
2573 * to the OpenGL specification.
2576 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2577 GLenum target
, GLint level
, GLint internalFormat
,
2578 GLint width
, GLint height
, GLint border
)
2581 GLint rb_base_format
;
2582 struct gl_renderbuffer
*rb
;
2583 GLenum rb_internal_format
;
2586 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2587 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2588 dimensions
, _mesa_lookup_enum_by_nr(target
));
2593 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2594 _mesa_error(ctx
, GL_INVALID_VALUE
,
2595 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2599 /* Check that the source buffer is complete */
2600 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2601 if (ctx
->ReadBuffer
->_Status
== 0) {
2602 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2604 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2605 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2606 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2610 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2611 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2612 "glCopyTexImage%dD(multisample FBO)",
2619 if (border
< 0 || border
> 1 ||
2620 ((ctx
->API
!= API_OPENGL_COMPAT
||
2621 target
== GL_TEXTURE_RECTANGLE_NV
||
2622 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2623 _mesa_error(ctx
, GL_INVALID_VALUE
,
2624 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2628 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2630 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2631 "glCopyTexImage%dD(read buffer)", dimensions
);
2635 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2638 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2639 switch (internalFormat
) {
2644 case GL_LUMINANCE_ALPHA
:
2647 _mesa_error(ctx
, GL_INVALID_VALUE
,
2648 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2649 _mesa_lookup_enum_by_nr(internalFormat
));
2654 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2655 if (baseFormat
< 0) {
2656 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2657 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2658 _mesa_lookup_enum_by_nr(internalFormat
));
2662 rb_internal_format
= rb
->InternalFormat
;
2663 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2664 if (_mesa_is_color_format(internalFormat
)) {
2665 if (rb_base_format
< 0) {
2666 _mesa_error(ctx
, GL_INVALID_VALUE
,
2667 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2668 _mesa_lookup_enum_by_nr(internalFormat
));
2673 if (_mesa_is_gles(ctx
)) {
2675 if (_mesa_base_format_component_count(baseFormat
) >
2676 _mesa_base_format_component_count(rb_base_format
)) {
2679 if (baseFormat
== GL_DEPTH_COMPONENT
||
2680 baseFormat
== GL_DEPTH_STENCIL
||
2681 rb_base_format
== GL_DEPTH_COMPONENT
||
2682 rb_base_format
== GL_DEPTH_STENCIL
||
2683 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2684 baseFormat
== GL_ALPHA
) &&
2685 rb_base_format
!= GL_RGBA
) ||
2686 internalFormat
== GL_RGB9_E5
) {
2689 if (internalFormat
== GL_RGB9_E5
) {
2693 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2694 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2695 _mesa_lookup_enum_by_nr(internalFormat
));
2700 if (_mesa_is_gles3(ctx
)) {
2701 bool rb_is_srgb
= false;
2702 bool dst_is_srgb
= false;
2704 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2705 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2709 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2713 if (rb_is_srgb
!= dst_is_srgb
) {
2714 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2715 * OpenGLES 3.0.0 spec says:
2717 * "The error INVALID_OPERATION is also generated if the
2718 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2719 * framebuffer attachment corresponding to the read buffer
2720 * is LINEAR (see section 6.1.13) and internalformat is
2721 * one of the sRGB formats described in section 3.8.16, or
2722 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2723 * SRGB and internalformat is not one of the sRGB formats."
2725 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2726 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2730 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2731 * types for SNORM formats. Also, conversion to SNORM formats is not
2732 * allowed by Table 3.2 on Page 110.
2734 if(_mesa_is_enum_format_snorm(internalFormat
)) {
2735 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2736 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2737 _mesa_lookup_enum_by_nr(internalFormat
));
2742 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2743 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2744 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2748 /* From the EXT_texture_integer spec:
2750 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2751 * if the texture internalformat is an integer format and the read color
2752 * buffer is not an integer format, or if the internalformat is not an
2753 * integer format and the read color buffer is an integer format."
2755 if (_mesa_is_color_format(internalFormat
)) {
2756 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2757 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2758 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2759 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2760 if (is_int
|| is_rbint
) {
2761 if (is_int
!= is_rbint
) {
2762 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2763 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2765 } else if (_mesa_is_gles(ctx
) &&
2766 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2767 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2768 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2769 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2774 /* From page 138 of OpenGL ES 3.0 spec:
2775 * "The error INVALID_OPERATION is generated if floating-point RGBA
2776 * data is required; if signed integer RGBA data is required and the
2777 * format of the current color buffer is not signed integer; if
2778 * unsigned integer RGBA data is required and the format of the
2779 * current color buffer is not unsigned integer; or if fixed-point
2780 * RGBA data is required and the format of the current color buffer
2781 * is not fixed-point.
2783 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2784 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2785 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2788 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2789 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2790 _mesa_error(ctx
, GL_INVALID_ENUM
,
2791 "glCopyTexImage%dD(target)", dimensions
);
2794 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2795 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2796 "glCopyTexImage%dD(no compression for format)", dimensions
);
2800 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2801 "glCopyTexImage%dD(border!=0)", dimensions
);
2806 if (!mutable_tex_object(ctx
, target
)) {
2807 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2808 "glCopyTexImage%dD(immutable texture)", dimensions
);
2812 /* if we get here, the parameters are OK */
2818 * Test glCopyTexSubImage[12]D() parameters for errors.
2819 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2822 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2823 GLenum target
, GLint level
,
2824 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2825 GLint width
, GLint height
)
2827 struct gl_texture_object
*texObj
;
2828 struct gl_texture_image
*texImage
;
2830 /* Check that the source buffer is complete */
2831 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2832 if (ctx
->ReadBuffer
->_Status
== 0) {
2833 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2835 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2836 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2837 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2841 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2842 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2843 "glCopyTexSubImage%dD(multisample FBO)",
2849 /* check target (proxies not allowed) */
2850 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2851 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2852 dimensions
, _mesa_lookup_enum_by_nr(target
));
2857 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2858 _mesa_error(ctx
, GL_INVALID_VALUE
,
2859 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2863 /* Get dest texture object / image pointers */
2864 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2866 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2870 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2872 /* destination image does not exist */
2873 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2874 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2878 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2879 dimensions
, texImage
,
2880 xoffset
, yoffset
, zoffset
,
2881 width
, height
, 1)) {
2885 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2886 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2887 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2888 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2893 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2894 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2898 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2899 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2900 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2901 dimensions
, texImage
->_BaseFormat
);
2905 /* From the EXT_texture_integer spec:
2907 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2908 * if the texture internalformat is an integer format and the read color
2909 * buffer is not an integer format, or if the internalformat is not an
2910 * integer format and the read color buffer is an integer format."
2912 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2913 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2915 if (_mesa_is_format_integer_color(rb
->Format
) !=
2916 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2917 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2918 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2923 /* if we get here, the parameters are OK */
2928 /** Callback info for walking over FBO hash table */
2931 struct gl_context
*ctx
;
2932 struct gl_texture_object
*texObj
;
2938 * Check render to texture callback. Called from _mesa_HashWalk().
2941 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2943 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2944 const struct cb_info
*info
= (struct cb_info
*) userData
;
2945 struct gl_context
*ctx
= info
->ctx
;
2946 const struct gl_texture_object
*texObj
= info
->texObj
;
2947 const GLuint level
= info
->level
, face
= info
->face
;
2949 /* If this is a user-created FBO */
2950 if (_mesa_is_user_fbo(fb
)) {
2952 /* check if any of the FBO's attachments point to 'texObj' */
2953 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2954 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2955 if (att
->Type
== GL_TEXTURE
&&
2956 att
->Texture
== texObj
&&
2957 att
->TextureLevel
== level
&&
2958 att
->CubeMapFace
== face
) {
2959 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2960 ASSERT(att
->Renderbuffer
->TexImage
);
2961 /* Mark fb status as indeterminate to force re-validation */
2970 * When a texture image is specified we have to check if it's bound to
2971 * any framebuffer objects (render to texture) in order to detect changes
2972 * in size or format since that effects FBO completeness.
2973 * Any FBOs rendering into the texture must be re-validated.
2976 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2977 struct gl_texture_object
*texObj
,
2978 GLuint face
, GLuint level
)
2980 /* Only check this texture if it's been marked as RenderToTexture */
2981 if (texObj
->_RenderToTexture
) {
2982 struct cb_info info
;
2984 info
.texObj
= texObj
;
2987 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2993 * If the texture object's GenerateMipmap flag is set and we've
2994 * changed the texture base level image, regenerate the rest of the
2995 * mipmap levels now.
2998 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2999 struct gl_texture_object
*texObj
, GLint level
)
3001 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
3002 if (texObj
->GenerateMipmap
&&
3003 level
== texObj
->BaseLevel
&&
3004 level
< texObj
->MaxLevel
) {
3005 ASSERT(ctx
->Driver
.GenerateMipmap
);
3006 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
3011 /** Debug helper: override the user-requested internal format */
3013 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
3016 if (internalFormat
== GL_RGBA16F_ARB
||
3017 internalFormat
== GL_RGBA32F_ARB
) {
3018 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3021 else if (internalFormat
== GL_RGB16F_ARB
||
3022 internalFormat
== GL_RGB32F_ARB
) {
3023 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3026 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3027 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3028 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3029 return GL_LUMINANCE_ALPHA
;
3031 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3032 internalFormat
== GL_LUMINANCE32F_ARB
) {
3033 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3034 return GL_LUMINANCE
;
3036 else if (internalFormat
== GL_ALPHA16F_ARB
||
3037 internalFormat
== GL_ALPHA32F_ARB
) {
3038 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3042 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3043 internalFormat = GL_RGBA;
3047 return internalFormat
;
3050 return internalFormat
;
3056 * Choose the actual hardware format for a texture image.
3057 * Try to use the same format as the previous image level when possible.
3058 * Otherwise, ask the driver for the best format.
3059 * It's important to try to choose a consistant format for all levels
3060 * for efficient texture memory layout/allocation. In particular, this
3061 * comes up during automatic mipmap generation.
3064 _mesa_choose_texture_format(struct gl_context
*ctx
,
3065 struct gl_texture_object
*texObj
,
3066 GLenum target
, GLint level
,
3067 GLenum internalFormat
, GLenum format
, GLenum type
)
3071 /* see if we've already chosen a format for the previous level */
3073 struct gl_texture_image
*prevImage
=
3074 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
3075 /* See if the prev level is defined and has an internal format which
3076 * matches the new internal format.
3079 prevImage
->Width
> 0 &&
3080 prevImage
->InternalFormat
== internalFormat
) {
3081 /* use the same format */
3082 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3083 return prevImage
->TexFormat
;
3087 /* If the application requested compression to an S3TC format but we don't
3088 * have the DXTn library, force a generic compressed format instead.
3090 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3091 const GLenum before
= internalFormat
;
3093 switch (internalFormat
) {
3094 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3095 if (!ctx
->Mesa_DXTn
)
3096 internalFormat
= GL_COMPRESSED_RGB
;
3098 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3099 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3100 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3101 if (!ctx
->Mesa_DXTn
)
3102 internalFormat
= GL_COMPRESSED_RGBA
;
3108 if (before
!= internalFormat
) {
3110 "DXT compression requested (%s), "
3111 "but libtxc_dxtn library not installed. Using %s "
3113 _mesa_lookup_enum_by_nr(before
),
3114 _mesa_lookup_enum_by_nr(internalFormat
));
3118 /* choose format from scratch */
3119 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3121 ASSERT(f
!= MESA_FORMAT_NONE
);
3127 * Adjust pixel unpack params and image dimensions to strip off the
3128 * one-pixel texture border.
3130 * Gallium and intel don't support texture borders. They've seldem been used
3131 * and seldom been implemented correctly anyway.
3133 * \param unpackNew returns the new pixel unpack parameters
3136 strip_texture_border(GLenum target
,
3137 GLint
*width
, GLint
*height
, GLint
*depth
,
3138 const struct gl_pixelstore_attrib
*unpack
,
3139 struct gl_pixelstore_attrib
*unpackNew
)
3145 *unpackNew
= *unpack
;
3147 if (unpackNew
->RowLength
== 0)
3148 unpackNew
->RowLength
= *width
;
3150 if (unpackNew
->ImageHeight
== 0)
3151 unpackNew
->ImageHeight
= *height
;
3153 assert(*width
>= 3);
3154 unpackNew
->SkipPixels
++; /* skip the border */
3155 *width
= *width
- 2; /* reduce the width by two border pixels */
3157 /* The min height of a texture with a border is 3 */
3158 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3159 unpackNew
->SkipRows
++; /* skip the border */
3160 *height
= *height
- 2; /* reduce the height by two border pixels */
3164 target
!= GL_TEXTURE_2D_ARRAY
&&
3165 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3166 unpackNew
->SkipImages
++; /* skip the border */
3167 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3173 * Common code to implement all the glTexImage1D/2D/3D functions
3174 * as well as glCompressedTexImage1D/2D/3D.
3175 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3176 * \param format the user's image format (only used if !compressed)
3177 * \param type the user's image type (only used if !compressed)
3178 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3181 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3182 GLenum target
, GLint level
, GLint internalFormat
,
3183 GLsizei width
, GLsizei height
, GLsizei depth
,
3184 GLint border
, GLenum format
, GLenum type
,
3185 GLsizei imageSize
, const GLvoid
*pixels
)
3187 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3188 struct gl_pixelstore_attrib unpack_no_border
;
3189 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3190 struct gl_texture_object
*texObj
;
3191 mesa_format texFormat
;
3192 GLboolean dimensionsOK
, sizeOK
;
3194 FLUSH_VERTICES(ctx
, 0);
3196 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3199 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3201 _mesa_lookup_enum_by_nr(target
), level
,
3202 _mesa_lookup_enum_by_nr(internalFormat
),
3203 width
, height
, depth
, border
, pixels
);
3206 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3208 _mesa_lookup_enum_by_nr(target
), level
,
3209 _mesa_lookup_enum_by_nr(internalFormat
),
3210 width
, height
, depth
, border
,
3211 _mesa_lookup_enum_by_nr(format
),
3212 _mesa_lookup_enum_by_nr(type
), pixels
);
3215 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3217 /* target error checking */
3218 if (!legal_teximage_target(ctx
, dims
, target
)) {
3219 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3220 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3224 /* general error checking */
3226 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3228 width
, height
, depth
,
3233 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3234 format
, type
, width
, height
, depth
, border
))
3238 /* Here we convert a cpal compressed image into a regular glTexImage2D
3239 * call by decompressing the texture. If we really want to support cpal
3240 * textures in any driver this would have to be changed.
3242 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3243 switch (internalFormat
) {
3244 case GL_PALETTE4_RGB8_OES
:
3245 case GL_PALETTE4_RGBA8_OES
:
3246 case GL_PALETTE4_R5_G6_B5_OES
:
3247 case GL_PALETTE4_RGBA4_OES
:
3248 case GL_PALETTE4_RGB5_A1_OES
:
3249 case GL_PALETTE8_RGB8_OES
:
3250 case GL_PALETTE8_RGBA8_OES
:
3251 case GL_PALETTE8_R5_G6_B5_OES
:
3252 case GL_PALETTE8_RGBA4_OES
:
3253 case GL_PALETTE8_RGB5_A1_OES
:
3254 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3255 width
, height
, imageSize
, pixels
);
3260 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3264 /* For glCompressedTexImage() the driver has no choice about the
3265 * texture format since we'll never transcode the user's compressed
3266 * image data. The internalFormat was error checked earlier.
3268 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3271 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3272 internalFormat
, format
, type
);
3275 assert(texFormat
!= MESA_FORMAT_NONE
);
3277 /* check that width, height, depth are legal for the mipmap level */
3278 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3279 height
, depth
, border
);
3281 /* check that the texture won't take too much memory, etc */
3282 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3284 width
, height
, depth
, border
);
3286 if (_mesa_is_proxy_texture(target
)) {
3287 /* Proxy texture: just clear or set state depending on error checking */
3288 struct gl_texture_image
*texImage
=
3289 get_proxy_tex_image(ctx
, target
, level
);
3292 return; /* GL_OUT_OF_MEMORY already recorded */
3294 if (dimensionsOK
&& sizeOK
) {
3295 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3296 border
, internalFormat
, texFormat
);
3299 clear_teximage_fields(texImage
);
3303 /* non-proxy target */
3304 const GLuint face
= _mesa_tex_target_to_face(target
);
3305 struct gl_texture_image
*texImage
;
3307 if (!dimensionsOK
) {
3308 _mesa_error(ctx
, GL_INVALID_VALUE
,
3309 "glTexImage%uD(invalid width or height or depth)",
3315 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3316 "glTexImage%uD(image too large)", dims
);
3320 /* Allow a hardware driver to just strip out the border, to provide
3321 * reliable but slightly incorrect hardware rendering instead of
3322 * rarely-tested software fallback rendering.
3324 if (border
&& ctx
->Const
.StripTextureBorder
) {
3325 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3328 unpack
= &unpack_no_border
;
3331 if (ctx
->NewState
& _NEW_PIXEL
)
3332 _mesa_update_state(ctx
);
3334 _mesa_lock_texture(ctx
, texObj
);
3336 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3339 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3342 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3344 _mesa_init_teximage_fields(ctx
, texImage
,
3345 width
, height
, depth
,
3346 border
, internalFormat
, texFormat
);
3348 /* Give the texture to the driver. <pixels> may be null. */
3349 if (width
> 0 && height
> 0 && depth
> 0) {
3351 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3355 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3356 type
, pixels
, unpack
);
3360 check_gen_mipmap(ctx
, target
, texObj
, level
);
3362 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3364 _mesa_dirty_texobj(ctx
, texObj
);
3367 _mesa_unlock_texture(ctx
, texObj
);
3374 * Called from the API. Note that width includes the border.
3377 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3378 GLsizei width
, GLint border
, GLenum format
,
3379 GLenum type
, const GLvoid
*pixels
)
3381 GET_CURRENT_CONTEXT(ctx
);
3382 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3383 border
, format
, type
, 0, pixels
);
3388 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3389 GLsizei width
, GLsizei height
, GLint border
,
3390 GLenum format
, GLenum type
,
3391 const GLvoid
*pixels
)
3393 GET_CURRENT_CONTEXT(ctx
);
3394 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3395 border
, format
, type
, 0, pixels
);
3400 * Called by the API or display list executor.
3401 * Note that width and height include the border.
3404 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3405 GLsizei width
, GLsizei height
, GLsizei depth
,
3406 GLint border
, GLenum format
, GLenum type
,
3407 const GLvoid
*pixels
)
3409 GET_CURRENT_CONTEXT(ctx
);
3410 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3411 width
, height
, depth
,
3412 border
, format
, type
, 0, pixels
);
3417 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3418 GLsizei width
, GLsizei height
, GLsizei depth
,
3419 GLint border
, GLenum format
, GLenum type
,
3420 const GLvoid
*pixels
)
3422 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3423 depth
, border
, format
, type
, pixels
);
3428 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3430 struct gl_texture_object
*texObj
;
3431 struct gl_texture_image
*texImage
;
3433 GET_CURRENT_CONTEXT(ctx
);
3434 FLUSH_VERTICES(ctx
, 0);
3438 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3440 case GL_TEXTURE_EXTERNAL_OES
:
3442 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3445 valid_target
= false;
3449 if (!valid_target
) {
3450 _mesa_error(ctx
, GL_INVALID_ENUM
,
3451 "glEGLImageTargetTexture2D(target=%d)", target
);
3456 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3457 "glEGLImageTargetTexture2D(image=%p)", image
);
3461 if (ctx
->NewState
& _NEW_PIXEL
)
3462 _mesa_update_state(ctx
);
3464 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3465 _mesa_lock_texture(ctx
, texObj
);
3467 if (texObj
->Immutable
) {
3468 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3469 "glEGLImageTargetTexture2D(texture is immutable)");
3470 _mesa_unlock_texture(ctx
, texObj
);
3474 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3476 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3478 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3480 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3481 texObj
, texImage
, image
);
3483 _mesa_dirty_texobj(ctx
, texObj
);
3485 _mesa_unlock_texture(ctx
, texObj
);
3492 * Implement all the glTexSubImage1/2/3D() functions.
3495 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3496 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3497 GLsizei width
, GLsizei height
, GLsizei depth
,
3498 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3500 struct gl_texture_object
*texObj
;
3501 struct gl_texture_image
*texImage
;
3503 FLUSH_VERTICES(ctx
, 0);
3505 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3506 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3508 _mesa_lookup_enum_by_nr(target
), level
,
3509 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3510 _mesa_lookup_enum_by_nr(format
),
3511 _mesa_lookup_enum_by_nr(type
), pixels
);
3513 /* check target (proxies not allowed) */
3514 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3515 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3516 dims
, _mesa_lookup_enum_by_nr(target
));
3520 if (ctx
->NewState
& _NEW_PIXEL
)
3521 _mesa_update_state(ctx
);
3523 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3524 xoffset
, yoffset
, zoffset
,
3525 width
, height
, depth
, format
, type
)) {
3526 return; /* error was detected */
3529 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3531 _mesa_lock_texture(ctx
, texObj
);
3533 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3535 if (width
> 0 && height
> 0 && depth
> 0) {
3536 /* If we have a border, offset=-1 is legal. Bias by border width. */
3539 if (target
!= GL_TEXTURE_2D_ARRAY
)
3540 zoffset
+= texImage
->Border
;
3543 if (target
!= GL_TEXTURE_1D_ARRAY
)
3544 yoffset
+= texImage
->Border
;
3547 xoffset
+= texImage
->Border
;
3550 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3551 xoffset
, yoffset
, zoffset
,
3552 width
, height
, depth
,
3553 format
, type
, pixels
, &ctx
->Unpack
);
3555 check_gen_mipmap(ctx
, target
, texObj
, level
);
3557 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3558 * the texel data, not the texture format, size, etc.
3562 _mesa_unlock_texture(ctx
, texObj
);
3567 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3568 GLint xoffset
, GLsizei width
,
3569 GLenum format
, GLenum type
,
3570 const GLvoid
*pixels
)
3572 GET_CURRENT_CONTEXT(ctx
);
3573 texsubimage(ctx
, 1, target
, level
,
3576 format
, type
, pixels
);
3581 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3582 GLint xoffset
, GLint yoffset
,
3583 GLsizei width
, GLsizei height
,
3584 GLenum format
, GLenum type
,
3585 const GLvoid
*pixels
)
3587 GET_CURRENT_CONTEXT(ctx
);
3588 texsubimage(ctx
, 2, target
, level
,
3589 xoffset
, yoffset
, 0,
3591 format
, type
, pixels
);
3597 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3598 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3599 GLsizei width
, GLsizei height
, GLsizei depth
,
3600 GLenum format
, GLenum type
,
3601 const GLvoid
*pixels
)
3603 GET_CURRENT_CONTEXT(ctx
);
3604 texsubimage(ctx
, 3, target
, level
,
3605 xoffset
, yoffset
, zoffset
,
3606 width
, height
, depth
,
3607 format
, type
, pixels
);
3613 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3614 * from. This depends on whether the texture contains color or depth values.
3616 static struct gl_renderbuffer
*
3617 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3619 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3620 /* reading from depth/stencil buffer */
3621 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3624 /* copying from color buffer */
3625 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3630 copytexsubimage_by_slice(struct gl_context
*ctx
,
3631 struct gl_texture_image
*texImage
,
3633 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3634 struct gl_renderbuffer
*rb
,
3636 GLsizei width
, GLsizei height
)
3638 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3641 /* For 1D arrays, we copy each scanline of the source rectangle into the
3644 assert(zoffset
== 0);
3646 for (slice
= 0; slice
< height
; slice
++) {
3647 assert(yoffset
+ slice
< texImage
->Height
);
3648 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3649 xoffset
, 0, yoffset
+ slice
,
3650 rb
, x
, y
+ slice
, width
, 1);
3653 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3654 xoffset
, yoffset
, zoffset
,
3655 rb
, x
, y
, width
, height
);
3660 formats_differ_in_component_sizes (mesa_format f1
,
3663 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3664 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3665 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3666 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3668 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3669 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3670 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3671 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3673 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3674 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3675 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3676 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3683 * Implement the glCopyTexImage1/2D() functions.
3686 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3687 GLenum target
, GLint level
, GLenum internalFormat
,
3688 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3690 struct gl_texture_object
*texObj
;
3691 struct gl_texture_image
*texImage
;
3692 const GLuint face
= _mesa_tex_target_to_face(target
);
3693 mesa_format texFormat
;
3694 struct gl_renderbuffer
*rb
;
3696 FLUSH_VERTICES(ctx
, 0);
3698 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3699 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3701 _mesa_lookup_enum_by_nr(target
), level
,
3702 _mesa_lookup_enum_by_nr(internalFormat
),
3703 x
, y
, width
, height
, border
);
3705 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3706 _mesa_update_state(ctx
);
3708 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3709 width
, height
, border
))
3712 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3714 _mesa_error(ctx
, GL_INVALID_VALUE
,
3715 "glCopyTexImage%uD(invalid width or height)", dims
);
3719 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3722 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3723 internalFormat
, GL_NONE
, GL_NONE
);
3725 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3727 if (_mesa_is_gles3(ctx
)) {
3728 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3729 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3730 * OpenGL ES 3.0. Khronos bug# 9807.
3732 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3733 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3734 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer and"
3735 " writing to unsized internal format)", dims
);
3739 /* From Page 139 of OpenGL ES 3.0 spec:
3740 * "If internalformat is sized, the internal format of the new texel
3741 * array is internalformat, and this is also the new texel array’s
3742 * effective internal format. If the component sizes of internalformat
3743 * do not exactly match the corresponding component sizes of the source
3744 * buffer’s effective internal format, described below, an
3745 * INVALID_OPERATION error is generated. If internalformat is unsized,
3746 * the internal format of the new texel array is the effective internal
3747 * format of the source buffer, and this is also the new texel array’s
3748 * effective internal format.
3750 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3751 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3752 "glCopyTexImage%uD(componenet size changed in"
3753 " internal format)", dims
);
3758 assert(texFormat
!= MESA_FORMAT_NONE
);
3760 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3762 width
, height
, 1, border
)) {
3763 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3764 "glCopyTexImage%uD(image too large)", dims
);
3768 if (border
&& ctx
->Const
.StripTextureBorder
) {
3770 width
-= border
* 2;
3773 height
-= border
* 2;
3778 _mesa_lock_texture(ctx
, texObj
);
3780 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3783 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3786 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3788 /* Free old texture image */
3789 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3791 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3792 border
, internalFormat
, texFormat
);
3794 if (width
&& height
) {
3795 /* Allocate texture memory (no pixel data yet) */
3796 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3798 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3800 struct gl_renderbuffer
*srcRb
=
3801 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3803 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3805 srcRb
, srcX
, srcY
, width
, height
);
3808 check_gen_mipmap(ctx
, target
, texObj
, level
);
3811 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3813 _mesa_dirty_texobj(ctx
, texObj
);
3816 _mesa_unlock_texture(ctx
, texObj
);
3822 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3823 GLenum internalFormat
,
3825 GLsizei width
, GLint border
)
3827 GET_CURRENT_CONTEXT(ctx
);
3828 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3834 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3835 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3838 GET_CURRENT_CONTEXT(ctx
);
3839 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3840 x
, y
, width
, height
, border
);
3846 * Implementation for glCopyTexSubImage1/2/3D() functions.
3849 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3850 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3851 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3853 struct gl_texture_object
*texObj
;
3854 struct gl_texture_image
*texImage
;
3856 FLUSH_VERTICES(ctx
, 0);
3858 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3859 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3861 _mesa_lookup_enum_by_nr(target
),
3862 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3864 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3865 _mesa_update_state(ctx
);
3867 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3868 xoffset
, yoffset
, zoffset
, width
, height
)) {
3872 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3874 _mesa_lock_texture(ctx
, texObj
);
3876 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3878 /* If we have a border, offset=-1 is legal. Bias by border width. */
3881 if (target
!= GL_TEXTURE_2D_ARRAY
)
3882 zoffset
+= texImage
->Border
;
3885 if (target
!= GL_TEXTURE_1D_ARRAY
)
3886 yoffset
+= texImage
->Border
;
3889 xoffset
+= texImage
->Border
;
3892 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3894 struct gl_renderbuffer
*srcRb
=
3895 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3897 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3898 xoffset
, yoffset
, zoffset
,
3899 srcRb
, x
, y
, width
, height
);
3901 check_gen_mipmap(ctx
, target
, texObj
, level
);
3903 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3904 * the texel data, not the texture format, size, etc.
3908 _mesa_unlock_texture(ctx
, texObj
);
3913 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3914 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3916 GET_CURRENT_CONTEXT(ctx
);
3917 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3923 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3924 GLint xoffset
, GLint yoffset
,
3925 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3927 GET_CURRENT_CONTEXT(ctx
);
3928 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3935 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3936 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3937 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3939 GET_CURRENT_CONTEXT(ctx
);
3940 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3941 x
, y
, width
, height
);
3945 check_clear_tex_image(struct gl_context
*ctx
,
3946 const char *function
,
3947 struct gl_texture_image
*texImage
,
3948 GLenum format
, GLenum type
,
3950 GLubyte
*clearValue
)
3952 struct gl_texture_object
*texObj
= texImage
->TexObject
;
3953 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
3954 GLenum internalFormat
= texImage
->InternalFormat
;
3957 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
3958 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3959 "%s(buffer texture)", function
);
3963 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
3964 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3965 "%s(compressed texture)", function
);
3969 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
3970 if (err
!= GL_NO_ERROR
) {
3971 _mesa_error(ctx
, err
,
3972 "%s(incompatible format = %s, type = %s)",
3974 _mesa_lookup_enum_by_nr(format
),
3975 _mesa_lookup_enum_by_nr(type
));
3979 /* make sure internal format and format basically agree */
3980 if (!texture_formats_agree(internalFormat
, format
)) {
3981 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3982 "%s(incompatible internalFormat = %s, format = %s)",
3984 _mesa_lookup_enum_by_nr(internalFormat
),
3985 _mesa_lookup_enum_by_nr(format
));
3989 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
3990 /* both source and dest must be integer-valued, or neither */
3991 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
3992 _mesa_is_enum_format_integer(format
)) {
3993 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3994 "%s(integer/non-integer format mismatch)",
4000 if (!_mesa_texstore(ctx
,
4002 texImage
->_BaseFormat
,
4003 texImage
->TexFormat
,
4004 0, /* dstRowStride */
4006 1, 1, 1, /* srcWidth/Height/Depth */
4008 data
? data
: zeroData
,
4009 &ctx
->DefaultPacking
)) {
4010 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4017 static struct gl_texture_object
*
4018 get_tex_obj_for_clear(struct gl_context
*ctx
,
4019 const char *function
,
4022 struct gl_texture_object
*texObj
;
4025 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4029 texObj
= _mesa_lookup_texture(ctx
, texture
);
4031 if (texObj
== NULL
) {
4032 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4036 if (texObj
->Target
== 0) {
4037 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4045 get_tex_images_for_clear(struct gl_context
*ctx
,
4046 const char *function
,
4047 struct gl_texture_object
*texObj
,
4049 struct gl_texture_image
**texImages
)
4054 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4055 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4059 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4060 for (i
= 0; i
< MAX_FACES
; i
++) {
4061 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4063 texImages
[i
] = _mesa_select_tex_image(ctx
, texObj
, target
, level
);
4064 if (texImages
[i
] == NULL
) {
4065 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4066 "%s(invalid level)", function
);
4074 texImages
[0] = _mesa_select_tex_image(ctx
, texObj
, texObj
->Target
, level
);
4076 if (texImages
[0] == NULL
) {
4077 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4085 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4086 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4087 GLsizei width
, GLsizei height
, GLsizei depth
,
4088 GLenum format
, GLenum type
, const void *data
)
4090 GET_CURRENT_CONTEXT(ctx
);
4091 struct gl_texture_object
*texObj
;
4092 struct gl_texture_image
*texImages
[MAX_FACES
];
4093 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4095 int minDepth
, maxDepth
;
4097 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4102 _mesa_lock_texture(ctx
, texObj
);
4104 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4105 texObj
, level
, texImages
);
4109 if (numImages
== 1) {
4110 minDepth
= -(int) texImages
[0]->Border
;
4111 maxDepth
= texImages
[0]->Depth
;
4114 maxDepth
= numImages
;
4117 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4118 yoffset
< -(GLint
) texImages
[0]->Border
||
4119 zoffset
< minDepth
||
4123 xoffset
+ width
> texImages
[0]->Width
||
4124 yoffset
+ height
> texImages
[0]->Height
||
4125 zoffset
+ depth
> maxDepth
) {
4126 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4127 "glClearSubTexImage(invalid dimensions)");
4131 if (numImages
== 1) {
4132 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4134 format
, type
, data
, clearValue
[0])) {
4135 ctx
->Driver
.ClearTexSubImage(ctx
,
4137 xoffset
, yoffset
, zoffset
,
4138 width
, height
, depth
,
4139 data
? clearValue
[0] : NULL
);
4142 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4143 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4145 format
, type
, data
, clearValue
[i
]))
4148 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4149 ctx
->Driver
.ClearTexSubImage(ctx
,
4151 xoffset
, yoffset
, 0,
4153 data
? clearValue
[i
] : NULL
);
4158 _mesa_unlock_texture(ctx
, texObj
);
4162 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4163 GLenum format
, GLenum type
, const void *data
)
4165 GET_CURRENT_CONTEXT(ctx
);
4166 struct gl_texture_object
*texObj
;
4167 struct gl_texture_image
*texImages
[MAX_FACES
];
4168 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4171 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4176 _mesa_lock_texture(ctx
, texObj
);
4178 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4179 texObj
, level
, texImages
);
4181 for (i
= 0; i
< numImages
; i
++) {
4182 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4189 for (i
= 0; i
< numImages
; i
++) {
4190 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4191 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4192 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4193 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4194 texImages
[i
]->Width
,
4195 texImages
[i
]->Height
,
4196 texImages
[i
]->Depth
,
4197 data
? clearValue
[i
] : NULL
);
4201 _mesa_unlock_texture(ctx
, texObj
);
4207 /**********************************************************************/
4208 /****** Compressed Textures ******/
4209 /**********************************************************************/
4213 * Error checking for glCompressedTexSubImage[123]D().
4214 * \return error code or GL_NO_ERROR.
4217 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4218 GLenum target
, GLint level
,
4219 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4220 GLsizei width
, GLsizei height
, GLsizei depth
,
4221 GLenum format
, GLsizei imageSize
)
4223 struct gl_texture_object
*texObj
;
4224 struct gl_texture_image
*texImage
;
4232 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4233 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4234 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4235 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4236 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4237 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4241 targetOK
= GL_FALSE
;
4246 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
4250 /* no 1D compressed textures at this time */
4251 targetOK
= GL_FALSE
;
4256 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexSubImage%uD(target)",
4261 /* this will catch any invalid compressed format token */
4262 if (!_mesa_is_compressed_format(ctx
, format
)) {
4263 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
4268 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4269 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage%uD(level=%d)",
4274 /* Check for invalid pixel storage modes */
4275 if (!_mesa_compressed_texture_pixel_storage_error_check(ctx
, dims
,
4277 "glCompressedTexSubImage")) {
4282 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4283 if (expectedSize
!= imageSize
) {
4284 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage%uD(size=%d)",
4289 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4291 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4292 "glCompressedTexSubImage%uD()", dims
);
4296 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
4298 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4299 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
4303 if ((GLint
) format
!= texImage
->InternalFormat
) {
4304 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4305 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
4309 if (compressedteximage_only_format(ctx
, format
)) {
4310 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4311 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
4316 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
4317 texImage
, xoffset
, yoffset
, zoffset
,
4318 width
, height
, depth
)) {
4327 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4328 GLenum internalFormat
, GLsizei width
,
4329 GLint border
, GLsizei imageSize
,
4332 GET_CURRENT_CONTEXT(ctx
);
4333 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4334 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4339 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4340 GLenum internalFormat
, GLsizei width
,
4341 GLsizei height
, GLint border
, GLsizei imageSize
,
4344 GET_CURRENT_CONTEXT(ctx
);
4345 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4346 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4351 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4352 GLenum internalFormat
, GLsizei width
,
4353 GLsizei height
, GLsizei depth
, GLint border
,
4354 GLsizei imageSize
, const GLvoid
*data
)
4356 GET_CURRENT_CONTEXT(ctx
);
4357 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4358 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4363 * Common helper for glCompressedTexSubImage1/2/3D().
4366 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
4367 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4368 GLsizei width
, GLsizei height
, GLsizei depth
,
4369 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
4371 struct gl_texture_object
*texObj
;
4372 struct gl_texture_image
*texImage
;
4373 GET_CURRENT_CONTEXT(ctx
);
4374 FLUSH_VERTICES(ctx
, 0);
4376 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
4377 xoffset
, yoffset
, zoffset
,
4378 width
, height
, depth
,
4379 format
, imageSize
)) {
4383 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4385 _mesa_lock_texture(ctx
, texObj
);
4387 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
4390 if (width
> 0 && height
> 0 && depth
> 0) {
4391 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4392 xoffset
, yoffset
, zoffset
,
4393 width
, height
, depth
,
4394 format
, imageSize
, data
);
4396 check_gen_mipmap(ctx
, target
, texObj
, level
);
4398 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4399 * the texel data, not the texture format, size, etc.
4403 _mesa_unlock_texture(ctx
, texObj
);
4408 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4409 GLsizei width
, GLenum format
,
4410 GLsizei imageSize
, const GLvoid
*data
)
4412 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
4413 format
, imageSize
, data
);
4418 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4419 GLint yoffset
, GLsizei width
, GLsizei height
,
4420 GLenum format
, GLsizei imageSize
,
4423 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
4424 width
, height
, 1, format
, imageSize
, data
);
4429 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4430 GLint yoffset
, GLint zoffset
, GLsizei width
,
4431 GLsizei height
, GLsizei depth
, GLenum format
,
4432 GLsizei imageSize
, const GLvoid
*data
)
4434 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
4435 width
, height
, depth
, format
, imageSize
, data
);
4439 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4441 if (ctx
->API
!= API_OPENGL_CORE
) {
4442 switch (internalFormat
) {
4444 return MESA_FORMAT_A_UNORM8
;
4446 return MESA_FORMAT_A_UNORM16
;
4447 case GL_ALPHA16F_ARB
:
4448 return MESA_FORMAT_A_FLOAT16
;
4449 case GL_ALPHA32F_ARB
:
4450 return MESA_FORMAT_A_FLOAT32
;
4451 case GL_ALPHA8I_EXT
:
4452 return MESA_FORMAT_A_SINT8
;
4453 case GL_ALPHA16I_EXT
:
4454 return MESA_FORMAT_A_SINT16
;
4455 case GL_ALPHA32I_EXT
:
4456 return MESA_FORMAT_A_SINT32
;
4457 case GL_ALPHA8UI_EXT
:
4458 return MESA_FORMAT_A_UINT8
;
4459 case GL_ALPHA16UI_EXT
:
4460 return MESA_FORMAT_A_UINT16
;
4461 case GL_ALPHA32UI_EXT
:
4462 return MESA_FORMAT_A_UINT32
;
4464 return MESA_FORMAT_L_UNORM8
;
4465 case GL_LUMINANCE16
:
4466 return MESA_FORMAT_L_UNORM16
;
4467 case GL_LUMINANCE16F_ARB
:
4468 return MESA_FORMAT_L_FLOAT16
;
4469 case GL_LUMINANCE32F_ARB
:
4470 return MESA_FORMAT_L_FLOAT32
;
4471 case GL_LUMINANCE8I_EXT
:
4472 return MESA_FORMAT_L_SINT8
;
4473 case GL_LUMINANCE16I_EXT
:
4474 return MESA_FORMAT_L_SINT16
;
4475 case GL_LUMINANCE32I_EXT
:
4476 return MESA_FORMAT_L_SINT32
;
4477 case GL_LUMINANCE8UI_EXT
:
4478 return MESA_FORMAT_L_UINT8
;
4479 case GL_LUMINANCE16UI_EXT
:
4480 return MESA_FORMAT_L_UINT16
;
4481 case GL_LUMINANCE32UI_EXT
:
4482 return MESA_FORMAT_L_UINT32
;
4483 case GL_LUMINANCE8_ALPHA8
:
4484 return MESA_FORMAT_L8A8_UNORM
;
4485 case GL_LUMINANCE16_ALPHA16
:
4486 return MESA_FORMAT_L16A16_UNORM
;
4487 case GL_LUMINANCE_ALPHA16F_ARB
:
4488 return MESA_FORMAT_LA_FLOAT16
;
4489 case GL_LUMINANCE_ALPHA32F_ARB
:
4490 return MESA_FORMAT_LA_FLOAT32
;
4491 case GL_LUMINANCE_ALPHA8I_EXT
:
4492 return MESA_FORMAT_LA_SINT8
;
4493 case GL_LUMINANCE_ALPHA16I_EXT
:
4494 return MESA_FORMAT_LA_SINT8
;
4495 case GL_LUMINANCE_ALPHA32I_EXT
:
4496 return MESA_FORMAT_LA_SINT16
;
4497 case GL_LUMINANCE_ALPHA8UI_EXT
:
4498 return MESA_FORMAT_LA_UINT8
;
4499 case GL_LUMINANCE_ALPHA16UI_EXT
:
4500 return MESA_FORMAT_LA_UINT16
;
4501 case GL_LUMINANCE_ALPHA32UI_EXT
:
4502 return MESA_FORMAT_LA_UINT32
;
4504 return MESA_FORMAT_I_UNORM8
;
4505 case GL_INTENSITY16
:
4506 return MESA_FORMAT_I_UNORM16
;
4507 case GL_INTENSITY16F_ARB
:
4508 return MESA_FORMAT_I_FLOAT16
;
4509 case GL_INTENSITY32F_ARB
:
4510 return MESA_FORMAT_I_FLOAT32
;
4511 case GL_INTENSITY8I_EXT
:
4512 return MESA_FORMAT_I_SINT8
;
4513 case GL_INTENSITY16I_EXT
:
4514 return MESA_FORMAT_I_SINT16
;
4515 case GL_INTENSITY32I_EXT
:
4516 return MESA_FORMAT_I_SINT32
;
4517 case GL_INTENSITY8UI_EXT
:
4518 return MESA_FORMAT_I_UINT8
;
4519 case GL_INTENSITY16UI_EXT
:
4520 return MESA_FORMAT_I_UINT16
;
4521 case GL_INTENSITY32UI_EXT
:
4522 return MESA_FORMAT_I_UINT32
;
4528 if (ctx
->API
== API_OPENGL_CORE
&&
4529 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4530 switch (internalFormat
) {
4532 return MESA_FORMAT_RGB_FLOAT32
;
4534 return MESA_FORMAT_RGB_UINT32
;
4536 return MESA_FORMAT_RGB_SINT32
;
4542 switch (internalFormat
) {
4544 return MESA_FORMAT_R8G8B8A8_UNORM
;
4546 return MESA_FORMAT_RGBA_UNORM16
;
4547 case GL_RGBA16F_ARB
:
4548 return MESA_FORMAT_RGBA_FLOAT16
;
4549 case GL_RGBA32F_ARB
:
4550 return MESA_FORMAT_RGBA_FLOAT32
;
4552 return MESA_FORMAT_RGBA_SINT8
;
4553 case GL_RGBA16I_EXT
:
4554 return MESA_FORMAT_RGBA_SINT16
;
4555 case GL_RGBA32I_EXT
:
4556 return MESA_FORMAT_RGBA_SINT32
;
4557 case GL_RGBA8UI_EXT
:
4558 return MESA_FORMAT_RGBA_UINT8
;
4559 case GL_RGBA16UI_EXT
:
4560 return MESA_FORMAT_RGBA_UINT16
;
4561 case GL_RGBA32UI_EXT
:
4562 return MESA_FORMAT_RGBA_UINT32
;
4565 return MESA_FORMAT_R8G8_UNORM
;
4567 return MESA_FORMAT_R16G16_UNORM
;
4569 return MESA_FORMAT_RG_FLOAT16
;
4571 return MESA_FORMAT_RG_FLOAT32
;
4573 return MESA_FORMAT_RG_SINT8
;
4575 return MESA_FORMAT_RG_SINT16
;
4577 return MESA_FORMAT_RG_SINT32
;
4579 return MESA_FORMAT_RG_UINT8
;
4581 return MESA_FORMAT_RG_UINT16
;
4583 return MESA_FORMAT_RG_UINT32
;
4586 return MESA_FORMAT_R_UNORM8
;
4588 return MESA_FORMAT_R_UNORM16
;
4590 return MESA_FORMAT_R_FLOAT16
;
4592 return MESA_FORMAT_R_FLOAT32
;
4594 return MESA_FORMAT_R_SINT8
;
4596 return MESA_FORMAT_R_SINT16
;
4598 return MESA_FORMAT_R_SINT32
;
4600 return MESA_FORMAT_R_UINT8
;
4602 return MESA_FORMAT_R_UINT16
;
4604 return MESA_FORMAT_R_UINT32
;
4607 return MESA_FORMAT_NONE
;
4613 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4614 GLenum internalFormat
)
4616 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
4619 if (format
== MESA_FORMAT_NONE
)
4620 return MESA_FORMAT_NONE
;
4622 datatype
= _mesa_get_format_datatype(format
);
4624 /* The GL_ARB_texture_buffer_object spec says:
4626 * "If ARB_texture_float is not supported, references to the
4627 * floating-point internal formats provided by that extension should be
4628 * removed, and such formats may not be passed to TexBufferARB."
4630 * As a result, GL_HALF_FLOAT internal format depends on both
4631 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
4633 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
4634 !ctx
->Extensions
.ARB_texture_float
)
4635 return MESA_FORMAT_NONE
;
4637 if (!ctx
->Extensions
.ARB_texture_rg
) {
4638 GLenum base_format
= _mesa_get_format_base_format(format
);
4639 if (base_format
== GL_R
|| base_format
== GL_RG
)
4640 return MESA_FORMAT_NONE
;
4643 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4644 GLenum base_format
= _mesa_get_format_base_format(format
);
4645 if (base_format
== GL_RGB
)
4646 return MESA_FORMAT_NONE
;
4653 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4654 struct gl_buffer_object
*bufObj
,
4655 GLintptr offset
, GLsizeiptr size
)
4657 struct gl_texture_object
*texObj
;
4660 FLUSH_VERTICES(ctx
, 0);
4662 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4663 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4667 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
4668 if (format
== MESA_FORMAT_NONE
) {
4669 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4674 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4676 _mesa_lock_texture(ctx
, texObj
);
4678 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4679 texObj
->BufferObjectFormat
= internalFormat
;
4680 texObj
->_BufferObjectFormat
= format
;
4681 texObj
->BufferOffset
= offset
;
4682 texObj
->BufferSize
= size
;
4684 _mesa_unlock_texture(ctx
, texObj
);
4688 /** GL_ARB_texture_buffer_object */
4690 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4692 struct gl_buffer_object
*bufObj
;
4694 GET_CURRENT_CONTEXT(ctx
);
4696 /* NOTE: ARB_texture_buffer_object has interactions with
4697 * the compatibility profile that are not implemented.
4699 if (!(ctx
->API
== API_OPENGL_CORE
&&
4700 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4701 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4705 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4706 if (!bufObj
&& buffer
) {
4707 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4711 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4715 /** GL_ARB_texture_buffer_range */
4717 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4718 GLintptr offset
, GLsizeiptr size
)
4720 struct gl_buffer_object
*bufObj
;
4722 GET_CURRENT_CONTEXT(ctx
);
4724 if (!(ctx
->API
== API_OPENGL_CORE
&&
4725 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4726 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4730 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4734 (offset
+ size
) > bufObj
->Size
) {
4735 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4738 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4739 _mesa_error(ctx
, GL_INVALID_VALUE
,
4740 "glTexBufferRange(invalid offset alignment)");
4743 } else if (buffer
) {
4744 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4752 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4757 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4759 /* Everything that is allowed for renderbuffers,
4760 * except for a base format of GL_STENCIL_INDEX.
4762 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4763 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4767 /** GL_ARB_texture_multisample */
4769 check_multisample_target(GLuint dims
, GLenum target
)
4772 case GL_TEXTURE_2D_MULTISAMPLE
:
4773 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4776 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4777 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4787 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4788 GLint internalformat
, GLsizei width
, GLsizei height
,
4789 GLsizei depth
, GLboolean fixedsamplelocations
,
4790 GLboolean immutable
, const char *func
)
4792 struct gl_texture_object
*texObj
;
4793 struct gl_texture_image
*texImage
;
4794 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
4795 mesa_format texFormat
;
4796 GLenum sample_count_error
;
4798 GET_CURRENT_CONTEXT(ctx
);
4800 if (!(ctx
->Extensions
.ARB_texture_multisample
4801 && _mesa_is_desktop_gl(ctx
))) {
4802 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4806 if (!check_multisample_target(dims
, target
)) {
4807 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4811 /* check that the specified internalformat is color/depth/stencil-renderable;
4812 * refer GL3.1 spec 4.4.4
4815 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4816 _mesa_error(ctx
, GL_INVALID_ENUM
,
4817 "%s(internalformat=%s not legal for immutable-format)",
4818 func
, _mesa_lookup_enum_by_nr(internalformat
));
4822 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4823 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4824 "%s(internalformat=%s)",
4825 func
, _mesa_lookup_enum_by_nr(internalformat
));
4829 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4830 internalformat
, samples
);
4831 samplesOK
= sample_count_error
== GL_NO_ERROR
;
4833 /* Page 254 of OpenGL 4.4 spec says:
4834 * "Proxy arrays for two-dimensional multisample and two-dimensional
4835 * multisample array textures are operated on in the same way when
4836 * TexImage2DMultisample is called with target specified as
4837 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
4838 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
4839 * However, if samples is not supported, then no error is generated.
4841 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
4842 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4846 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4848 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4849 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4850 "%s(texture object 0)",
4855 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4857 if (texImage
== NULL
) {
4858 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4862 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4863 internalformat
, GL_NONE
, GL_NONE
);
4864 assert(texFormat
!= MESA_FORMAT_NONE
);
4866 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4867 width
, height
, depth
, 0);
4869 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4870 width
, height
, depth
, 0);
4872 if (_mesa_is_proxy_texture(target
)) {
4873 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
4874 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
4875 internalformat
, texFormat
,
4876 samples
, fixedsamplelocations
);
4879 /* clear all image fields */
4880 clear_teximage_fields(texImage
);
4884 if (!dimensionsOK
) {
4885 _mesa_error(ctx
, GL_INVALID_VALUE
,
4886 "%s(invalid width or height)", func
);
4891 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4892 "%s(texture too large)", func
);
4896 /* Check if texObj->Immutable is set */
4897 if (texObj
->Immutable
) {
4898 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4902 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4904 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
4905 internalformat
, texFormat
,
4906 samples
, fixedsamplelocations
);
4908 if (width
> 0 && height
> 0 && depth
> 0) {
4909 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4910 width
, height
, depth
)) {
4911 /* tidy up the texture image state. strictly speaking,
4912 * we're allowed to just leave this in whatever state we
4913 * like, but being tidy is good.
4915 _mesa_init_teximage_fields(ctx
, texImage
,
4916 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4920 texObj
->Immutable
= immutable
;
4923 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
4926 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4932 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4933 GLenum internalformat
, GLsizei width
,
4934 GLsizei height
, GLboolean fixedsamplelocations
)
4936 teximagemultisample(2, target
, samples
, internalformat
,
4937 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4938 "glTexImage2DMultisample");
4943 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4944 GLenum internalformat
, GLsizei width
,
4945 GLsizei height
, GLsizei depth
,
4946 GLboolean fixedsamplelocations
)
4948 teximagemultisample(3, target
, samples
, internalformat
,
4949 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4950 "glTexImage3DMultisample");
4955 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4956 GLenum internalformat
, GLsizei width
,
4957 GLsizei height
, GLboolean fixedsamplelocations
)
4959 teximagemultisample(2, target
, samples
, internalformat
,
4960 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4961 "glTexStorage2DMultisample");
4965 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4966 GLenum internalformat
, GLsizei width
,
4967 GLsizei height
, GLsizei depth
,
4968 GLboolean fixedsamplelocations
)
4970 teximagemultisample(3, target
, samples
, internalformat
,
4971 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4972 "glTexStorage3DMultisample");