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 (ctx
->API
== API_OPENGLES
) {
524 switch (internalFormat
) {
525 case GL_PALETTE4_RGB8_OES
:
526 case GL_PALETTE4_R5_G6_B5_OES
:
527 case GL_PALETTE8_RGB8_OES
:
528 case GL_PALETTE8_R5_G6_B5_OES
:
530 case GL_PALETTE4_RGBA8_OES
:
531 case GL_PALETTE8_RGB5_A1_OES
:
532 case GL_PALETTE4_RGBA4_OES
:
533 case GL_PALETTE4_RGB5_A1_OES
:
534 case GL_PALETTE8_RGBA8_OES
:
535 case GL_PALETTE8_RGBA4_OES
:
542 return -1; /* error */
547 * For cube map faces, return a face index in [0,5].
548 * For other targets return 0;
551 _mesa_tex_target_to_face(GLenum target
)
553 if (_mesa_is_cube_face(target
))
554 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
562 * Install gl_texture_image in a gl_texture_object according to the target
563 * and level parameters.
565 * \param tObj texture object.
566 * \param target texture target.
567 * \param level image level.
568 * \param texImage texture image.
571 set_tex_image(struct gl_texture_object
*tObj
,
572 GLenum target
, GLint level
,
573 struct gl_texture_image
*texImage
)
575 const GLuint face
= _mesa_tex_target_to_face(target
);
579 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
582 tObj
->Image
[face
][level
] = texImage
;
584 /* Set the 'back' pointer */
585 texImage
->TexObject
= tObj
;
586 texImage
->Level
= level
;
587 texImage
->Face
= face
;
592 * Allocate a texture image structure.
594 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
597 * \return a pointer to gl_texture_image struct with all fields initialized to
600 struct gl_texture_image
*
601 _mesa_new_texture_image( struct gl_context
*ctx
)
604 return CALLOC_STRUCT(gl_texture_image
);
609 * Free a gl_texture_image and associated data.
610 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
612 * \param texImage texture image.
614 * Free the texture image structure and the associated image data.
617 _mesa_delete_texture_image(struct gl_context
*ctx
,
618 struct gl_texture_image
*texImage
)
620 /* Free texImage->Data and/or any other driver-specific texture
623 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
624 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
630 * Test if a target is a proxy target.
632 * \param target texture target.
634 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
637 _mesa_is_proxy_texture(GLenum target
)
640 static const GLenum targets
[] = {
644 GL_PROXY_TEXTURE_CUBE_MAP
,
645 GL_PROXY_TEXTURE_RECTANGLE
,
646 GL_PROXY_TEXTURE_1D_ARRAY
,
647 GL_PROXY_TEXTURE_2D_ARRAY
,
648 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
649 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
650 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
653 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
654 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
656 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== Elements(targets
) + 2);
658 for (i
= 0; i
< Elements(targets
); ++i
)
659 if (target
== targets
[i
])
666 * Return the proxy target which corresponds to the given texture target
669 proxy_target(GLenum target
)
673 case GL_PROXY_TEXTURE_1D
:
674 return GL_PROXY_TEXTURE_1D
;
676 case GL_PROXY_TEXTURE_2D
:
677 return GL_PROXY_TEXTURE_2D
;
679 case GL_PROXY_TEXTURE_3D
:
680 return GL_PROXY_TEXTURE_3D
;
681 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
682 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
683 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
684 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
685 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
686 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
687 case GL_TEXTURE_CUBE_MAP_ARB
:
688 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
689 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
690 case GL_TEXTURE_RECTANGLE_NV
:
691 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
692 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
693 case GL_TEXTURE_1D_ARRAY_EXT
:
694 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
695 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
696 case GL_TEXTURE_2D_ARRAY_EXT
:
697 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
698 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
699 case GL_TEXTURE_CUBE_MAP_ARRAY
:
700 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
701 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
702 case GL_TEXTURE_2D_MULTISAMPLE
:
703 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
704 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
705 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
706 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
707 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
709 _mesa_problem(NULL
, "unexpected target in proxy_target()");
716 * Return a pointer to the current texture object for the given target
717 * on the current texture unit.
718 * Note: all <target> error checking should have been done by this point.
720 struct gl_texture_object
*
721 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
723 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
724 const GLboolean arrayTex
= ctx
->Extensions
.EXT_texture_array
;
728 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
729 case GL_PROXY_TEXTURE_1D
:
730 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
732 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
733 case GL_PROXY_TEXTURE_2D
:
734 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
736 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
737 case GL_PROXY_TEXTURE_3D
:
738 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
739 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
740 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
741 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
742 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
743 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
744 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
745 case GL_TEXTURE_CUBE_MAP_ARB
:
746 return ctx
->Extensions
.ARB_texture_cube_map
747 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
748 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
749 return ctx
->Extensions
.ARB_texture_cube_map
750 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
751 case GL_TEXTURE_CUBE_MAP_ARRAY
:
752 return ctx
->Extensions
.ARB_texture_cube_map_array
753 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
754 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
755 return ctx
->Extensions
.ARB_texture_cube_map_array
756 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
757 case GL_TEXTURE_RECTANGLE_NV
:
758 return ctx
->Extensions
.NV_texture_rectangle
759 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
760 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
761 return ctx
->Extensions
.NV_texture_rectangle
762 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
763 case GL_TEXTURE_1D_ARRAY_EXT
:
764 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
765 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
766 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
767 case GL_TEXTURE_2D_ARRAY_EXT
:
768 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
769 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
770 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
771 case GL_TEXTURE_BUFFER
:
772 return ctx
->API
== API_OPENGL_CORE
&&
773 ctx
->Extensions
.ARB_texture_buffer_object
?
774 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
775 case GL_TEXTURE_EXTERNAL_OES
:
776 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
777 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
778 case GL_TEXTURE_2D_MULTISAMPLE
:
779 return ctx
->Extensions
.ARB_texture_multisample
780 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
781 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
782 return ctx
->Extensions
.ARB_texture_multisample
783 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
784 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
785 return ctx
->Extensions
.ARB_texture_multisample
786 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
787 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
788 return ctx
->Extensions
.ARB_texture_multisample
789 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
791 _mesa_problem(NULL
, "bad target in _mesa_get_current_tex_object()");
799 * Get a texture image pointer from a texture object, given a texture
800 * target and mipmap level. The target and level parameters should
801 * have already been error-checked.
803 * \param ctx GL context.
804 * \param texObj texture unit.
805 * \param target texture target.
806 * \param level image level.
808 * \return pointer to the texture image structure, or NULL on failure.
810 struct gl_texture_image
*
811 _mesa_select_tex_image(struct gl_context
*ctx
,
812 const struct gl_texture_object
*texObj
,
813 GLenum target
, GLint level
)
815 const GLuint face
= _mesa_tex_target_to_face(target
);
819 ASSERT(level
< MAX_TEXTURE_LEVELS
);
821 return texObj
->Image
[face
][level
];
826 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
827 * it and install it. Only return NULL if passed a bad parameter or run
830 struct gl_texture_image
*
831 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
832 GLenum target
, GLint level
)
834 struct gl_texture_image
*texImage
;
839 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
841 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
843 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
847 set_tex_image(texObj
, target
, level
, texImage
);
855 * Return pointer to the specified proxy texture image.
856 * Note that proxy textures are per-context, not per-texture unit.
857 * \return pointer to texture image or NULL if invalid target, invalid
858 * level, or out of memory.
860 static struct gl_texture_image
*
861 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
863 struct gl_texture_image
*texImage
;
870 case GL_PROXY_TEXTURE_1D
:
871 if (level
>= ctx
->Const
.MaxTextureLevels
)
873 texIndex
= TEXTURE_1D_INDEX
;
875 case GL_PROXY_TEXTURE_2D
:
876 if (level
>= ctx
->Const
.MaxTextureLevels
)
878 texIndex
= TEXTURE_2D_INDEX
;
880 case GL_PROXY_TEXTURE_3D
:
881 if (level
>= ctx
->Const
.Max3DTextureLevels
)
883 texIndex
= TEXTURE_3D_INDEX
;
885 case GL_PROXY_TEXTURE_CUBE_MAP
:
886 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
888 texIndex
= TEXTURE_CUBE_INDEX
;
890 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
893 texIndex
= TEXTURE_RECT_INDEX
;
895 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
896 if (level
>= ctx
->Const
.MaxTextureLevels
)
898 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
900 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
901 if (level
>= ctx
->Const
.MaxTextureLevels
)
903 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
905 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
906 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
908 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
910 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
913 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
915 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
918 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
924 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
926 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
928 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
931 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
932 /* Set the 'back' pointer */
933 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
940 * Get the maximum number of allowed mipmap levels.
942 * \param ctx GL context.
943 * \param target texture target.
945 * \return the maximum number of allowed mipmap levels for the given
946 * texture target, or zero if passed a bad target.
951 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
955 case GL_PROXY_TEXTURE_1D
:
957 case GL_PROXY_TEXTURE_2D
:
958 return ctx
->Const
.MaxTextureLevels
;
960 case GL_PROXY_TEXTURE_3D
:
961 return ctx
->Const
.Max3DTextureLevels
;
962 case GL_TEXTURE_CUBE_MAP
:
963 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
964 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
965 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
966 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
967 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
968 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
969 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
970 return ctx
->Extensions
.ARB_texture_cube_map
971 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
972 case GL_TEXTURE_RECTANGLE_NV
:
973 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
974 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
975 case GL_TEXTURE_1D_ARRAY_EXT
:
976 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
977 case GL_TEXTURE_2D_ARRAY_EXT
:
978 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
979 return ctx
->Extensions
.EXT_texture_array
980 ? ctx
->Const
.MaxTextureLevels
: 0;
981 case GL_TEXTURE_CUBE_MAP_ARRAY
:
982 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
983 return ctx
->Extensions
.ARB_texture_cube_map_array
984 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
985 case GL_TEXTURE_BUFFER
:
986 return ctx
->API
== API_OPENGL_CORE
&&
987 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
988 case GL_TEXTURE_2D_MULTISAMPLE
:
989 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
990 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
991 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
992 return _mesa_is_desktop_gl(ctx
)
993 && ctx
->Extensions
.ARB_texture_multisample
995 case GL_TEXTURE_EXTERNAL_OES
:
998 return 0; /* bad target */
1004 * Return number of dimensions per mipmap level for the given texture target.
1007 _mesa_get_texture_dimensions(GLenum target
)
1011 case GL_PROXY_TEXTURE_1D
:
1014 case GL_TEXTURE_RECTANGLE
:
1015 case GL_TEXTURE_CUBE_MAP
:
1016 case GL_PROXY_TEXTURE_2D
:
1017 case GL_PROXY_TEXTURE_RECTANGLE
:
1018 case GL_PROXY_TEXTURE_CUBE_MAP
:
1019 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1020 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1021 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1022 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1023 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1024 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1025 case GL_TEXTURE_1D_ARRAY
:
1026 case GL_PROXY_TEXTURE_1D_ARRAY
:
1027 case GL_TEXTURE_EXTERNAL_OES
:
1028 case GL_TEXTURE_2D_MULTISAMPLE
:
1029 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1032 case GL_PROXY_TEXTURE_3D
:
1033 case GL_TEXTURE_2D_ARRAY
:
1034 case GL_PROXY_TEXTURE_2D_ARRAY
:
1035 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1036 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1037 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1038 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1040 case GL_TEXTURE_BUFFER
:
1043 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1051 * Check if a texture target can have more than one layer.
1054 _mesa_tex_target_is_layered(GLenum target
)
1058 case GL_PROXY_TEXTURE_1D
:
1060 case GL_PROXY_TEXTURE_2D
:
1061 case GL_TEXTURE_RECTANGLE
:
1062 case GL_PROXY_TEXTURE_RECTANGLE
:
1063 case GL_TEXTURE_2D_MULTISAMPLE
:
1064 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1065 case GL_TEXTURE_BUFFER
:
1066 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1067 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1068 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1069 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1070 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1071 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1072 case GL_TEXTURE_EXTERNAL_OES
:
1076 case GL_PROXY_TEXTURE_3D
:
1077 case GL_TEXTURE_CUBE_MAP
:
1078 case GL_PROXY_TEXTURE_CUBE_MAP
:
1079 case GL_TEXTURE_1D_ARRAY
:
1080 case GL_PROXY_TEXTURE_1D_ARRAY
:
1081 case GL_TEXTURE_2D_ARRAY
:
1082 case GL_PROXY_TEXTURE_2D_ARRAY
:
1083 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1084 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1085 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1086 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1090 assert(!"Invalid texture target.");
1097 * Return the number of layers present in the given level of an array,
1098 * cubemap or 3D texture. If the texture is not layered return zero.
1101 _mesa_get_texture_layers(const struct gl_texture_object
*texObj
, GLint level
)
1103 assert(level
>= 0 && level
< MAX_TEXTURE_LEVELS
);
1105 switch (texObj
->Target
) {
1108 case GL_TEXTURE_RECTANGLE
:
1109 case GL_TEXTURE_2D_MULTISAMPLE
:
1110 case GL_TEXTURE_BUFFER
:
1111 case GL_TEXTURE_EXTERNAL_OES
:
1114 case GL_TEXTURE_CUBE_MAP
:
1117 case GL_TEXTURE_1D_ARRAY
: {
1118 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1119 return img
? img
->Height
: 0;
1123 case GL_TEXTURE_2D_ARRAY
:
1124 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1125 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
: {
1126 struct gl_texture_image
*img
= texObj
->Image
[0][level
];
1127 return img
? img
->Depth
: 0;
1131 assert(!"Invalid texture target.");
1138 * Return the maximum number of mipmap levels for the given target
1139 * and the dimensions.
1140 * The dimensions are expected not to include the border.
1143 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1150 case GL_TEXTURE_1D_ARRAY
:
1151 case GL_PROXY_TEXTURE_1D
:
1152 case GL_PROXY_TEXTURE_1D_ARRAY
:
1155 case GL_TEXTURE_CUBE_MAP
:
1156 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1157 case GL_PROXY_TEXTURE_CUBE_MAP
:
1158 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1162 case GL_TEXTURE_2D_ARRAY
:
1163 case GL_PROXY_TEXTURE_2D
:
1164 case GL_PROXY_TEXTURE_2D_ARRAY
:
1165 size
= MAX2(width
, height
);
1168 case GL_PROXY_TEXTURE_3D
:
1169 size
= MAX3(width
, height
, depth
);
1171 case GL_TEXTURE_RECTANGLE
:
1172 case GL_TEXTURE_EXTERNAL_OES
:
1173 case GL_TEXTURE_2D_MULTISAMPLE
:
1174 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1175 case GL_PROXY_TEXTURE_RECTANGLE
:
1176 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1177 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1184 return _mesa_logbase2(size
) + 1;
1188 #if 000 /* not used anymore */
1190 * glTexImage[123]D can accept a NULL image pointer. In this case we
1191 * create a texture image with unspecified image contents per the OpenGL
1195 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1197 const GLint components
= _mesa_components_in_format(format
);
1198 const GLint numPixels
= width
* height
* depth
;
1199 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1203 * Let's see if anyone finds this. If glTexImage2D() is called with
1204 * a NULL image pointer then load the texture image with something
1205 * interesting instead of leaving it indeterminate.
1208 static const char message
[8][32] = {
1209 " X X XXXXX XXX X ",
1210 " XX XX X X X X X ",
1212 " X X XXXX XXX XXXXX ",
1215 " X X XXXXX XXX X X ",
1219 GLubyte
*imgPtr
= data
;
1221 for (h
= 0; h
< depth
; h
++) {
1222 for (i
= 0; i
< height
; i
++) {
1223 GLint srcRow
= 7 - (i
% 8);
1224 for (j
= 0; j
< width
; j
++) {
1225 GLint srcCol
= j
% 32;
1226 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1227 for (k
= 0; k
< components
; k
++) {
1243 * Set the size and format-related fields of a gl_texture_image struct
1244 * to zero. This is used when a proxy texture test fails.
1247 clear_teximage_fields(struct gl_texture_image
*img
)
1250 img
->_BaseFormat
= 0;
1251 img
->InternalFormat
= 0;
1260 img
->HeightLog2
= 0;
1262 img
->TexFormat
= MESA_FORMAT_NONE
;
1263 img
->NumSamples
= 0;
1264 img
->FixedSampleLocations
= GL_TRUE
;
1269 * Initialize basic fields of the gl_texture_image struct.
1271 * \param ctx GL context.
1272 * \param img texture image structure to be initialized.
1273 * \param width image width.
1274 * \param height image height.
1275 * \param depth image depth.
1276 * \param border image border.
1277 * \param internalFormat internal format.
1278 * \param format the actual hardware format (one of MESA_FORMAT_*)
1279 * \param numSamples number of samples per texel, or zero for non-MS.
1280 * \param fixedSampleLocations are sample locations fixed?
1282 * Fills in the fields of \p img with the given information.
1283 * Note: width, height and depth include the border.
1286 init_teximage_fields_ms(struct gl_context
*ctx
,
1287 struct gl_texture_image
*img
,
1288 GLsizei width
, GLsizei height
, GLsizei depth
,
1289 GLint border
, GLenum internalFormat
,
1291 GLuint numSamples
, GLboolean fixedSampleLocations
)
1296 ASSERT(height
>= 0);
1299 target
= img
->TexObject
->Target
;
1300 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1301 ASSERT(img
->_BaseFormat
> 0);
1302 img
->InternalFormat
= internalFormat
;
1303 img
->Border
= border
;
1305 img
->Height
= height
;
1308 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1309 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1311 img
->NumSamples
= 0;
1312 img
->FixedSampleLocations
= GL_TRUE
;
1316 case GL_TEXTURE_BUFFER
:
1317 case GL_PROXY_TEXTURE_1D
:
1322 img
->HeightLog2
= 0;
1329 case GL_TEXTURE_1D_ARRAY
:
1330 case GL_PROXY_TEXTURE_1D_ARRAY
:
1331 img
->Height2
= height
; /* no border */
1332 img
->HeightLog2
= 0; /* not used */
1340 case GL_TEXTURE_RECTANGLE
:
1341 case GL_TEXTURE_CUBE_MAP
:
1342 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1343 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1344 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1345 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1346 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1347 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1348 case GL_TEXTURE_EXTERNAL_OES
:
1349 case GL_PROXY_TEXTURE_2D
:
1350 case GL_PROXY_TEXTURE_RECTANGLE
:
1351 case GL_PROXY_TEXTURE_CUBE_MAP
:
1352 case GL_TEXTURE_2D_MULTISAMPLE
:
1353 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1354 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1355 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1362 case GL_TEXTURE_2D_ARRAY
:
1363 case GL_PROXY_TEXTURE_2D_ARRAY
:
1364 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1365 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1366 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1367 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1368 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1369 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1370 img
->Depth2
= depth
; /* no border */
1371 img
->DepthLog2
= 0; /* not used */
1374 case GL_PROXY_TEXTURE_3D
:
1375 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1376 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1377 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1378 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1381 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1386 _mesa_get_tex_max_num_levels(target
,
1387 img
->Width2
, img
->Height2
, img
->Depth2
);
1388 img
->TexFormat
= format
;
1389 img
->NumSamples
= numSamples
;
1390 img
->FixedSampleLocations
= fixedSampleLocations
;
1395 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1396 struct gl_texture_image
*img
,
1397 GLsizei width
, GLsizei height
, GLsizei depth
,
1398 GLint border
, GLenum internalFormat
,
1401 init_teximage_fields_ms(ctx
, img
, width
, height
, depth
, border
,
1402 internalFormat
, format
, 0, GL_TRUE
);
1407 * Free and clear fields of the gl_texture_image struct.
1409 * \param ctx GL context.
1410 * \param texImage texture image structure to be cleared.
1412 * After the call, \p texImage will have no data associated with it. Its
1413 * fields are cleared so that its parent object will test incomplete.
1416 _mesa_clear_texture_image(struct gl_context
*ctx
,
1417 struct gl_texture_image
*texImage
)
1419 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1420 clear_teximage_fields(texImage
);
1425 * Check the width, height, depth and border of a texture image are legal.
1426 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1428 * The target and level parameters will have already been validated.
1429 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1432 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1433 GLint level
, GLint width
, GLint height
,
1434 GLint depth
, GLint border
)
1440 case GL_PROXY_TEXTURE_1D
:
1441 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1442 maxSize
>>= level
; /* level size */
1443 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1445 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1446 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1452 case GL_PROXY_TEXTURE_2D
:
1453 case GL_TEXTURE_2D_MULTISAMPLE
:
1454 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1455 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1457 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1459 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1461 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1462 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1464 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1470 case GL_PROXY_TEXTURE_3D
:
1471 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1473 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1475 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1477 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1479 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1480 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1482 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1484 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1489 case GL_TEXTURE_RECTANGLE_NV
:
1490 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1493 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1494 if (width
< 0 || width
> maxSize
)
1496 if (height
< 0 || height
> maxSize
)
1500 case GL_TEXTURE_CUBE_MAP
:
1501 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1502 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1503 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1504 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1505 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1506 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1507 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1508 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1510 if (width
!= height
)
1512 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1514 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1516 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1517 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1519 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1524 case GL_TEXTURE_1D_ARRAY_EXT
:
1525 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1526 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1528 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1530 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1532 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1533 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1538 case GL_TEXTURE_2D_ARRAY_EXT
:
1539 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1540 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1541 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1542 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1544 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1546 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1548 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1550 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1551 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1553 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1558 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1559 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1560 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1561 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1563 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1565 if (depth
< 0 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1567 if (width
!= height
)
1569 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1571 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1572 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1574 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1579 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1586 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1587 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1588 * \param destImage the destination texture image.
1589 * \return GL_TRUE if error found, GL_FALSE otherwise.
1592 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1593 const char *function
, GLuint dims
,
1594 const struct gl_texture_image
*destImage
,
1595 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1596 GLsizei subWidth
, GLsizei subHeight
,
1599 const GLenum target
= destImage
->TexObject
->Target
;
1604 _mesa_error(ctx
, GL_INVALID_VALUE
,
1605 "%s%dD(width=%d)", function
, dims
, subWidth
);
1609 if (dims
> 1 && subHeight
< 0) {
1610 _mesa_error(ctx
, GL_INVALID_VALUE
,
1611 "%s%dD(height=%d)", function
, dims
, subHeight
);
1615 if (dims
> 2 && subDepth
< 0) {
1616 _mesa_error(ctx
, GL_INVALID_VALUE
,
1617 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1621 /* check xoffset and width */
1622 if (xoffset
< - (GLint
) destImage
->Border
) {
1623 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1628 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1629 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1634 /* check yoffset and height */
1636 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1637 if (yoffset
< -yBorder
) {
1638 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1642 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1643 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1649 /* check zoffset and depth */
1651 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
||
1652 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) ?
1653 0 : destImage
->Border
;
1655 if (zoffset
< -zBorder
) {
1656 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1659 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1660 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1666 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1667 * compressed texture images can be updated. But, that restriction may be
1668 * relaxed for particular compressed formats. At this time, all the
1669 * compressed formats supported by Mesa allow sub-textures to be updated
1670 * along compressed block boundaries.
1672 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1674 if (bw
!= 1 || bh
!= 1) {
1675 /* offset must be multiple of block size */
1676 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1677 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1678 "%s%dD(xoffset = %d, yoffset = %d)",
1679 function
, dims
, xoffset
, yoffset
);
1683 /* The size must be a multiple of bw x bh, or we must be using a
1684 * offset+size that exactly hits the edge of the image. This
1685 * is important for small mipmap levels (1x1, 2x1, etc) and for
1688 if ((subWidth
% bw
!= 0) &&
1689 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1690 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1691 "%s%dD(width = %d)", function
, dims
, subWidth
);
1695 if ((subHeight
% bh
!= 0) &&
1696 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1697 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1698 "%s%dD(height = %d)", function
, dims
, subHeight
);
1710 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1711 * specific texture image size checks.
1713 * A hardware driver might override this function if, for example, the
1714 * max 3D texture size is 512x512x64 (i.e. not a cube).
1716 * Note that width, height, depth == 0 is not an error. However, a
1717 * texture with zero width/height/depth will be considered "incomplete"
1718 * and texturing will effectively be disabled.
1720 * \param target any texture target/type
1721 * \param level as passed to glTexImage
1722 * \param format the MESA_FORMAT_x for the tex image
1723 * \param width as passed to glTexImage
1724 * \param height as passed to glTexImage
1725 * \param depth as passed to glTexImage
1726 * \param border as passed to glTexImage
1727 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1730 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1732 GLint width
, GLint height
, GLint depth
, GLint border
)
1734 /* We just check if the image size is less than MaxTextureMbytes.
1735 * Some drivers may do more specific checks.
1737 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1738 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1739 mbytes
*= _mesa_num_tex_faces(target
);
1740 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1745 * Return true if the format is only valid for glCompressedTexImage.
1748 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1751 case GL_ETC1_RGB8_OES
:
1752 case GL_PALETTE4_RGB8_OES
:
1753 case GL_PALETTE4_RGBA8_OES
:
1754 case GL_PALETTE4_R5_G6_B5_OES
:
1755 case GL_PALETTE4_RGBA4_OES
:
1756 case GL_PALETTE4_RGB5_A1_OES
:
1757 case GL_PALETTE8_RGB8_OES
:
1758 case GL_PALETTE8_RGBA8_OES
:
1759 case GL_PALETTE8_R5_G6_B5_OES
:
1760 case GL_PALETTE8_RGBA4_OES
:
1761 case GL_PALETTE8_RGB5_A1_OES
:
1770 * Helper function to determine whether a target and specific compression
1771 * format are supported.
1774 _mesa_target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1777 (void) intFormat
; /* not used yet */
1781 case GL_PROXY_TEXTURE_2D
:
1782 return GL_TRUE
; /* true for any compressed format so far */
1783 case GL_PROXY_TEXTURE_CUBE_MAP
:
1784 case GL_TEXTURE_CUBE_MAP
:
1785 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1786 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1787 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1788 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1789 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1790 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1791 return ctx
->Extensions
.ARB_texture_cube_map
;
1792 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1793 case GL_TEXTURE_2D_ARRAY_EXT
:
1794 return ctx
->Extensions
.EXT_texture_array
;
1795 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1796 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1797 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1805 * Check if the given texture target value is legal for a
1806 * glTexImage1/2/3D call.
1809 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1815 case GL_PROXY_TEXTURE_1D
:
1816 return _mesa_is_desktop_gl(ctx
);
1824 case GL_PROXY_TEXTURE_2D
:
1825 return _mesa_is_desktop_gl(ctx
);
1826 case GL_PROXY_TEXTURE_CUBE_MAP
:
1827 return _mesa_is_desktop_gl(ctx
)
1828 && ctx
->Extensions
.ARB_texture_cube_map
;
1829 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1830 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1831 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1832 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1833 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1834 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1835 return ctx
->Extensions
.ARB_texture_cube_map
;
1836 case GL_TEXTURE_RECTANGLE_NV
:
1837 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1838 return _mesa_is_desktop_gl(ctx
)
1839 && ctx
->Extensions
.NV_texture_rectangle
;
1840 case GL_TEXTURE_1D_ARRAY_EXT
:
1841 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1842 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1850 case GL_PROXY_TEXTURE_3D
:
1851 return _mesa_is_desktop_gl(ctx
);
1852 case GL_TEXTURE_2D_ARRAY_EXT
:
1853 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1854 || _mesa_is_gles3(ctx
);
1855 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1856 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1857 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1858 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1859 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1864 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1871 * Check if the given texture target value is legal for a
1872 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1873 * The difference compared to legal_teximage_target() above is that
1874 * proxy targets are not supported.
1877 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1881 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1886 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1887 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1888 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1889 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1890 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1891 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1892 return ctx
->Extensions
.ARB_texture_cube_map
;
1893 case GL_TEXTURE_RECTANGLE_NV
:
1894 return _mesa_is_desktop_gl(ctx
)
1895 && ctx
->Extensions
.NV_texture_rectangle
;
1896 case GL_TEXTURE_1D_ARRAY_EXT
:
1897 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1905 case GL_TEXTURE_2D_ARRAY_EXT
:
1906 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1907 || _mesa_is_gles3(ctx
);
1908 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1909 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1910 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1915 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1923 * Helper function to determine if a texture object is mutable (in terms
1924 * of GL_ARB_texture_storage).
1927 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1929 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1930 return !texObj
->Immutable
;
1935 * Return expected size of a compressed texture.
1938 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1941 mesa_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1942 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1946 * Verify that a texture format is valid with a particular target
1948 * In particular, textures with base format of \c GL_DEPTH_COMPONENT or
1949 * \c GL_DEPTH_STENCIL are only valid with certain, context dependent texture
1952 * \param ctx GL context
1953 * \param target Texture target
1954 * \param internalFormat Internal format of the texture image
1955 * \param dimensions Dimensionality at the caller. This is \b not used
1956 * in the validation. It is only used when logging
1958 * \param caller Base name of the calling function (e.g.,
1959 * "glTexImage" or "glTexStorage").
1961 * \returns true if the combination is legal, false otherwise.
1964 _mesa_legal_texture_base_format_for_target(struct gl_context
*ctx
,
1965 GLenum target
, GLenum internalFormat
,
1966 unsigned dimensions
,
1969 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
1970 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
1971 /* Section 3.8.3 (Texture Image Specification) of the OpenGL 3.3 Core
1972 * Profile spec says:
1974 * "Textures with a base internal format of DEPTH_COMPONENT or
1975 * DEPTH_STENCIL are supported by texture image specification
1976 * commands only if target is TEXTURE_1D, TEXTURE_2D,
1977 * TEXTURE_1D_ARRAY, TEXTURE_2D_ARRAY, TEXTURE_RECTANGLE,
1978 * TEXTURE_CUBE_MAP, PROXY_TEXTURE_1D, PROXY_TEXTURE_2D,
1979 * PROXY_TEXTURE_1D_ARRAY, PROXY_TEXTURE_2D_ARRAY,
1980 * PROXY_TEXTURE_RECTANGLE, or PROXY_TEXTURE_CUBE_MAP. Using these
1981 * formats in conjunction with any other target will result in an
1982 * INVALID_OPERATION error."
1984 * Cubemaps are only supported with desktop OpenGL version >= 3.0,
1985 * EXT_gpu_shader4, or, on OpenGL ES 2.0+, OES_depth_texture_cube_map.
1987 if (target
!= GL_TEXTURE_1D
&&
1988 target
!= GL_PROXY_TEXTURE_1D
&&
1989 target
!= GL_TEXTURE_2D
&&
1990 target
!= GL_PROXY_TEXTURE_2D
&&
1991 target
!= GL_TEXTURE_1D_ARRAY
&&
1992 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
1993 target
!= GL_TEXTURE_2D_ARRAY
&&
1994 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
1995 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
1996 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
1997 !((_mesa_is_cube_face(target
) ||
1998 target
== GL_TEXTURE_CUBE_MAP
||
1999 target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2000 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2001 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2002 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2003 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2004 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2005 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2006 "%s%dD(bad target for depth texture)",
2007 caller
, dimensions
);
2016 texture_formats_agree(GLenum internalFormat
,
2019 GLboolean colorFormat
;
2020 GLboolean is_format_depth_or_depthstencil
;
2021 GLboolean is_internalFormat_depth_or_depthstencil
;
2023 /* Even though there are no color-index textures, we still have to support
2024 * uploading color-index data and remapping it to RGB via the
2025 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
2027 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
2029 is_internalFormat_depth_or_depthstencil
=
2030 _mesa_is_depth_format(internalFormat
) ||
2031 _mesa_is_depthstencil_format(internalFormat
);
2033 is_format_depth_or_depthstencil
=
2034 _mesa_is_depth_format(format
) ||
2035 _mesa_is_depthstencil_format(format
);
2037 colorFormat
= _mesa_is_color_format(format
);
2039 if (_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
)
2042 if (is_internalFormat_depth_or_depthstencil
!=
2043 is_format_depth_or_depthstencil
)
2046 if (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
))
2053 * Test the glTexImage[123]D() parameters for errors.
2055 * \param ctx GL context.
2056 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2057 * \param target texture target given by the user (already validated).
2058 * \param level image level given by the user.
2059 * \param internalFormat internal format given by the user.
2060 * \param format pixel data format given by the user.
2061 * \param type pixel data type given by the user.
2062 * \param width image width given by the user.
2063 * \param height image height given by the user.
2064 * \param depth image depth given by the user.
2065 * \param border image border given by the user.
2067 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2069 * Verifies each of the parameters against the constants specified in
2070 * __struct gl_contextRec::Const and the supported extensions, and according
2071 * to the OpenGL specification.
2072 * Note that we don't fully error-check the width, height, depth values
2073 * here. That's done in _mesa_legal_texture_dimensions() which is used
2074 * by several other GL entrypoints. Plus, texture dims have a special
2075 * interaction with proxy textures.
2078 texture_error_check( struct gl_context
*ctx
,
2079 GLuint dimensions
, GLenum target
,
2080 GLint level
, GLint internalFormat
,
2081 GLenum format
, GLenum type
,
2082 GLint width
, GLint height
,
2083 GLint depth
, GLint border
)
2087 /* Note: for proxy textures, some error conditions immediately generate
2088 * a GL error in the usual way. But others do not generate a GL error.
2089 * Instead, they cause the width, height, depth, format fields of the
2090 * texture image to be zeroed-out. The GL spec seems to indicate that the
2091 * zero-out behaviour is only used in cases related to memory allocation.
2095 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2096 _mesa_error(ctx
, GL_INVALID_VALUE
,
2097 "glTexImage%dD(level=%d)", dimensions
, level
);
2102 if (border
< 0 || border
> 1 ||
2103 ((ctx
->API
!= API_OPENGL_COMPAT
||
2104 target
== GL_TEXTURE_RECTANGLE_NV
||
2105 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2106 _mesa_error(ctx
, GL_INVALID_VALUE
,
2107 "glTexImage%dD(border=%d)", dimensions
, border
);
2111 if (width
< 0 || height
< 0 || depth
< 0) {
2112 _mesa_error(ctx
, GL_INVALID_VALUE
,
2113 "glTexImage%dD(width, height or depth < 0)", dimensions
);
2117 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2118 * combinations of format, internalFormat, and type that can be used.
2119 * Formats and types that require additional extensions (e.g., GL_FLOAT
2120 * requires GL_OES_texture_float) are filtered elsewhere.
2123 if (_mesa_is_gles(ctx
)) {
2124 if (_mesa_is_gles3(ctx
)) {
2125 err
= _mesa_es3_error_check_format_and_type(format
, type
,
2128 if (format
!= internalFormat
) {
2129 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2130 "glTexImage%dD(format = %s, internalFormat = %s)",
2132 _mesa_lookup_enum_by_nr(format
),
2133 _mesa_lookup_enum_by_nr(internalFormat
));
2137 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2139 if (err
!= GL_NO_ERROR
) {
2140 _mesa_error(ctx
, err
,
2141 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
2143 _mesa_lookup_enum_by_nr(format
),
2144 _mesa_lookup_enum_by_nr(type
),
2145 _mesa_lookup_enum_by_nr(internalFormat
));
2150 /* Check internalFormat */
2151 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2152 _mesa_error(ctx
, GL_INVALID_VALUE
,
2153 "glTexImage%dD(internalFormat=%s)",
2154 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2158 /* Check incoming image format and type */
2159 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2160 if (err
!= GL_NO_ERROR
) {
2161 _mesa_error(ctx
, err
,
2162 "glTexImage%dD(incompatible format = %s, type = %s)",
2163 dimensions
, _mesa_lookup_enum_by_nr(format
),
2164 _mesa_lookup_enum_by_nr(type
));
2168 /* make sure internal format and format basically agree */
2169 if (!texture_formats_agree(internalFormat
, format
)) {
2170 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2171 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2172 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2173 _mesa_lookup_enum_by_nr(format
));
2177 /* additional checks for ycbcr textures */
2178 if (internalFormat
== GL_YCBCR_MESA
) {
2179 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2180 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2181 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2183 _mesa_snprintf(message
, sizeof(message
),
2184 "glTexImage%dD(format/type YCBCR mismatch)",
2186 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2187 return GL_TRUE
; /* error */
2189 if (target
!= GL_TEXTURE_2D
&&
2190 target
!= GL_PROXY_TEXTURE_2D
&&
2191 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2192 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2193 _mesa_error(ctx
, GL_INVALID_ENUM
,
2194 "glTexImage%dD(bad target for YCbCr texture)",
2200 _mesa_snprintf(message
, sizeof(message
),
2201 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2202 dimensions
, border
);
2203 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2208 /* additional checks for depth textures */
2209 if (!_mesa_legal_texture_base_format_for_target(ctx
, target
, internalFormat
,
2210 dimensions
, "glTexImage"))
2213 /* additional checks for compressed textures */
2214 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2215 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2216 _mesa_error(ctx
, GL_INVALID_ENUM
,
2217 "glTexImage%dD(target can't be compressed)", dimensions
);
2220 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2221 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2222 "glTexImage%dD(no compression for format)", dimensions
);
2226 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2227 "glTexImage%dD(border!=0)", dimensions
);
2232 /* additional checks for integer textures */
2233 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2234 (_mesa_is_enum_format_integer(format
) !=
2235 _mesa_is_enum_format_integer(internalFormat
))) {
2236 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2237 "glTexImage%dD(integer/non-integer format mismatch)",
2242 if (!mutable_tex_object(ctx
, target
)) {
2243 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2244 "glTexImage%dD(immutable texture)", dimensions
);
2248 /* if we get here, the parameters are OK */
2254 _mesa_compressed_texture_pixel_storage_error_check(struct gl_context
*ctx
,
2256 struct gl_pixelstore_attrib
*packing
,
2259 if (!_mesa_is_desktop_gl(ctx
) || !packing
->CompressedBlockSize
)
2262 if (packing
->CompressedBlockWidth
&& packing
->SkipPixels
% packing
->CompressedBlockWidth
) {
2263 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2264 "%s(skip-pixels %% block-width)", caller
);
2268 if (dimensions
> 1 && packing
->CompressedBlockHeight
&& packing
->SkipRows
% packing
->CompressedBlockHeight
) {
2269 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2270 "%s(skip-rows %% block-height)", caller
);
2274 if (dimensions
> 2 && packing
->CompressedBlockDepth
&& packing
->SkipImages
% packing
->CompressedBlockDepth
) {
2275 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2276 "%s(skip-images %% block-depth)", caller
);
2284 * Error checking for glCompressedTexImage[123]D().
2285 * Note that the width, height and depth values are not fully error checked
2287 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2290 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2291 GLenum target
, GLint level
,
2292 GLenum internalFormat
, GLsizei width
,
2293 GLsizei height
, GLsizei depth
, GLint border
,
2296 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2298 GLenum error
= GL_NO_ERROR
;
2299 char *reason
= ""; /* no error */
2301 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2303 /* From section 3.8.6, page 146 of OpenGL ES 3.0 spec:
2305 * "The ETC2/EAC texture compression algorithm supports only
2306 * two-dimensional images. If internalformat is an ETC2/EAC format,
2307 * CompressedTexImage3D will generate an INVALID_OPERATION error if
2308 * target is not TEXTURE_2D_ARRAY."
2310 error
= _mesa_is_desktop_gl(ctx
) ? GL_INVALID_ENUM
: GL_INVALID_OPERATION
;
2314 /* This will detect any invalid internalFormat value */
2315 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2316 _mesa_error(ctx
, GL_INVALID_ENUM
,
2317 "glCompressedTexImage%dD(internalFormat=%s)",
2318 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2322 switch (internalFormat
) {
2323 case GL_PALETTE4_RGB8_OES
:
2324 case GL_PALETTE4_RGBA8_OES
:
2325 case GL_PALETTE4_R5_G6_B5_OES
:
2326 case GL_PALETTE4_RGBA4_OES
:
2327 case GL_PALETTE4_RGB5_A1_OES
:
2328 case GL_PALETTE8_RGB8_OES
:
2329 case GL_PALETTE8_RGBA8_OES
:
2330 case GL_PALETTE8_R5_G6_B5_OES
:
2331 case GL_PALETTE8_RGBA4_OES
:
2332 case GL_PALETTE8_RGB5_A1_OES
:
2333 /* check level (note that level should be zero or less!) */
2334 if (level
> 0 || level
< -maxLevels
) {
2336 error
= GL_INVALID_VALUE
;
2340 if (dimensions
!= 2) {
2341 reason
= "compressed paletted textures must be 2D";
2342 error
= GL_INVALID_OPERATION
;
2346 /* Figure out the expected texture size (in bytes). This will be
2347 * checked against the actual size later.
2349 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2352 /* This is for the benefit of the TestProxyTexImage below. It expects
2353 * level to be non-negative. OES_compressed_paletted_texture uses a
2354 * weird mechanism where the level specified to glCompressedTexImage2D
2355 * is -(n-1) number of levels in the texture, and the data specifies the
2356 * complete mipmap stack. This is done to ensure the palette is the
2357 * same for all levels.
2364 if (level
< 0 || level
>= maxLevels
) {
2366 error
= GL_INVALID_VALUE
;
2370 /* Figure out the expected texture size (in bytes). This will be
2371 * checked against the actual size later.
2373 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2377 /* This should really never fail */
2378 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2379 reason
= "internalFormat";
2380 error
= GL_INVALID_ENUM
;
2384 /* No compressed formats support borders at this time */
2386 reason
= "border != 0";
2387 error
= GL_INVALID_VALUE
;
2391 /* Check for invalid pixel storage modes */
2392 if (!_mesa_compressed_texture_pixel_storage_error_check(ctx
, dimensions
,
2394 "glCompressedTexImage")) {
2398 /* check image size in bytes */
2399 if (expectedSize
!= imageSize
) {
2400 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2401 * if <imageSize> is not consistent with the format, dimensions, and
2402 * contents of the specified image.
2404 reason
= "imageSize inconsistant with width/height/format";
2405 error
= GL_INVALID_VALUE
;
2409 if (!mutable_tex_object(ctx
, target
)) {
2410 reason
= "immutable texture";
2411 error
= GL_INVALID_OPERATION
;
2418 /* Note: not all error paths exit through here. */
2419 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2426 * Test glTexSubImage[123]D() parameters for errors.
2428 * \param ctx GL context.
2429 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2430 * \param target texture target given by the user (already validated)
2431 * \param level image level given by the user.
2432 * \param xoffset sub-image x offset given by the user.
2433 * \param yoffset sub-image y offset given by the user.
2434 * \param zoffset sub-image z offset given by the user.
2435 * \param format pixel data format given by the user.
2436 * \param type pixel data type given by the user.
2437 * \param width image width given by the user.
2438 * \param height image height given by the user.
2439 * \param depth image depth given by the user.
2441 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2443 * Verifies each of the parameters against the constants specified in
2444 * __struct gl_contextRec::Const and the supported extensions, and according
2445 * to the OpenGL specification.
2448 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2449 GLenum target
, GLint level
,
2450 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2451 GLint width
, GLint height
, GLint depth
,
2452 GLenum format
, GLenum type
)
2454 struct gl_texture_object
*texObj
;
2455 struct gl_texture_image
*texImage
;
2458 /* check target (proxies not allowed) */
2459 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2460 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2461 dimensions
, _mesa_lookup_enum_by_nr(target
));
2466 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2467 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2472 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2473 * combinations of format and type that can be used. Formats and types
2474 * that require additional extensions (e.g., GL_FLOAT requires
2475 * GL_OES_texture_float) are filtered elsewhere.
2477 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2478 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2479 if (err
!= GL_NO_ERROR
) {
2480 _mesa_error(ctx
, err
,
2481 "glTexSubImage%dD(format = %s, type = %s)",
2483 _mesa_lookup_enum_by_nr(format
),
2484 _mesa_lookup_enum_by_nr(type
));
2489 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2490 if (err
!= GL_NO_ERROR
) {
2491 _mesa_error(ctx
, err
,
2492 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2493 dimensions
, _mesa_lookup_enum_by_nr(format
),
2494 _mesa_lookup_enum_by_nr(type
));
2498 /* Get dest texture object / image pointers */
2499 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2501 /* must be out of memory */
2502 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2506 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2508 /* non-existant texture level */
2509 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2510 "glTexSubImage%dD(invalid texture image)", dimensions
);
2514 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2515 texImage
, xoffset
, yoffset
, 0,
2516 width
, height
, 1)) {
2520 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2521 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2522 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2523 "glTexSubImage%dD(no compression for format)", dimensions
);
2528 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2529 /* both source and dest must be integer-valued, or neither */
2530 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2531 _mesa_is_enum_format_integer(format
)) {
2532 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2533 "glTexSubImage%dD(integer/non-integer format mismatch)",
2544 * Test glCopyTexImage[12]D() parameters for errors.
2546 * \param ctx GL context.
2547 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2548 * \param target texture target given by the user.
2549 * \param level image level given by the user.
2550 * \param internalFormat internal format given by the user.
2551 * \param width image width given by the user.
2552 * \param height image height given by the user.
2553 * \param border texture border.
2555 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2557 * Verifies each of the parameters against the constants specified in
2558 * __struct gl_contextRec::Const and the supported extensions, and according
2559 * to the OpenGL specification.
2562 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2563 GLenum target
, GLint level
, GLint internalFormat
,
2564 GLint width
, GLint height
, GLint border
)
2567 GLint rb_base_format
;
2568 struct gl_renderbuffer
*rb
;
2569 GLenum rb_internal_format
;
2572 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2573 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2574 dimensions
, _mesa_lookup_enum_by_nr(target
));
2579 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2580 _mesa_error(ctx
, GL_INVALID_VALUE
,
2581 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2585 /* Check that the source buffer is complete */
2586 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2587 if (ctx
->ReadBuffer
->_Status
== 0) {
2588 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2590 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2591 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2592 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2596 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2597 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2598 "glCopyTexImage%dD(multisample FBO)",
2605 if (border
< 0 || border
> 1 ||
2606 ((ctx
->API
!= API_OPENGL_COMPAT
||
2607 target
== GL_TEXTURE_RECTANGLE_NV
||
2608 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2609 _mesa_error(ctx
, GL_INVALID_VALUE
,
2610 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2614 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2616 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2617 "glCopyTexImage%dD(read buffer)", dimensions
);
2621 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2624 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2625 switch (internalFormat
) {
2630 case GL_LUMINANCE_ALPHA
:
2633 _mesa_error(ctx
, GL_INVALID_VALUE
,
2634 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2635 _mesa_lookup_enum_by_nr(internalFormat
));
2640 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2641 if (baseFormat
< 0) {
2642 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2643 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2644 _mesa_lookup_enum_by_nr(internalFormat
));
2648 rb_internal_format
= rb
->InternalFormat
;
2649 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2650 if (_mesa_is_color_format(internalFormat
)) {
2651 if (rb_base_format
< 0) {
2652 _mesa_error(ctx
, GL_INVALID_VALUE
,
2653 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2654 _mesa_lookup_enum_by_nr(internalFormat
));
2659 if (_mesa_is_gles(ctx
)) {
2661 if (_mesa_base_format_component_count(baseFormat
) >
2662 _mesa_base_format_component_count(rb_base_format
)) {
2665 if (baseFormat
== GL_DEPTH_COMPONENT
||
2666 baseFormat
== GL_DEPTH_STENCIL
||
2667 rb_base_format
== GL_DEPTH_COMPONENT
||
2668 rb_base_format
== GL_DEPTH_STENCIL
||
2669 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2670 baseFormat
== GL_ALPHA
) &&
2671 rb_base_format
!= GL_RGBA
) ||
2672 internalFormat
== GL_RGB9_E5
) {
2675 if (internalFormat
== GL_RGB9_E5
) {
2679 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2680 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2681 _mesa_lookup_enum_by_nr(internalFormat
));
2686 if (_mesa_is_gles3(ctx
)) {
2687 bool rb_is_srgb
= false;
2688 bool dst_is_srgb
= false;
2690 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2691 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2695 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2699 if (rb_is_srgb
!= dst_is_srgb
) {
2700 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2701 * OpenGLES 3.0.0 spec says:
2703 * "The error INVALID_OPERATION is also generated if the
2704 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2705 * framebuffer attachment corresponding to the read buffer
2706 * is LINEAR (see section 6.1.13) and internalformat is
2707 * one of the sRGB formats described in section 3.8.16, or
2708 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2709 * SRGB and internalformat is not one of the sRGB formats."
2711 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2712 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2716 /* Page 139, Table 3.15 of OpenGL ES 3.0 spec does not define ReadPixels
2717 * types for SNORM formats. Also, conversion to SNORM formats is not
2718 * allowed by Table 3.2 on Page 110.
2720 if(_mesa_is_enum_format_snorm(internalFormat
)) {
2721 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2722 "glCopyTexImage%dD(internalFormat=%s)", dimensions
,
2723 _mesa_lookup_enum_by_nr(internalFormat
));
2728 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2729 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2730 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2734 /* From the EXT_texture_integer spec:
2736 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2737 * if the texture internalformat is an integer format and the read color
2738 * buffer is not an integer format, or if the internalformat is not an
2739 * integer format and the read color buffer is an integer format."
2741 if (_mesa_is_color_format(internalFormat
)) {
2742 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2743 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2744 bool is_unorm
= _mesa_is_enum_format_unorm(internalFormat
);
2745 bool is_rbunorm
= _mesa_is_enum_format_unorm(rb_internal_format
);
2746 if (is_int
|| is_rbint
) {
2747 if (is_int
!= is_rbint
) {
2748 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2749 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2751 } else if (_mesa_is_gles(ctx
) &&
2752 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2753 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2754 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2755 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2760 /* From page 138 of OpenGL ES 3.0 spec:
2761 * "The error INVALID_OPERATION is generated if floating-point RGBA
2762 * data is required; if signed integer RGBA data is required and the
2763 * format of the current color buffer is not signed integer; if
2764 * unsigned integer RGBA data is required and the format of the
2765 * current color buffer is not unsigned integer; or if fixed-point
2766 * RGBA data is required and the format of the current color buffer
2767 * is not fixed-point.
2769 if (_mesa_is_gles(ctx
) && is_unorm
!= is_rbunorm
)
2770 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2771 "glCopyTexImage%dD(unorm vs non-unorm)", dimensions
);
2774 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2775 if (!_mesa_target_can_be_compressed(ctx
, target
, internalFormat
)) {
2776 _mesa_error(ctx
, GL_INVALID_ENUM
,
2777 "glCopyTexImage%dD(target)", dimensions
);
2780 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2781 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2782 "glCopyTexImage%dD(no compression for format)", dimensions
);
2786 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2787 "glCopyTexImage%dD(border!=0)", dimensions
);
2792 if (!mutable_tex_object(ctx
, target
)) {
2793 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2794 "glCopyTexImage%dD(immutable texture)", dimensions
);
2798 /* if we get here, the parameters are OK */
2804 * Test glCopyTexSubImage[12]D() parameters for errors.
2805 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2808 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2809 GLenum target
, GLint level
,
2810 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2811 GLint width
, GLint height
)
2813 struct gl_texture_object
*texObj
;
2814 struct gl_texture_image
*texImage
;
2816 /* Check that the source buffer is complete */
2817 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2818 if (ctx
->ReadBuffer
->_Status
== 0) {
2819 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2821 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2822 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2823 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2827 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2828 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2829 "glCopyTexSubImage%dD(multisample FBO)",
2835 /* check target (proxies not allowed) */
2836 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2837 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2838 dimensions
, _mesa_lookup_enum_by_nr(target
));
2843 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2844 _mesa_error(ctx
, GL_INVALID_VALUE
,
2845 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2849 /* Get dest texture object / image pointers */
2850 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2852 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2856 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2858 /* destination image does not exist */
2859 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2860 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2864 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2865 dimensions
, texImage
,
2866 xoffset
, yoffset
, zoffset
,
2867 width
, height
, 1)) {
2871 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2872 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2873 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2874 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2879 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2880 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2884 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2885 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2886 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2887 dimensions
, texImage
->_BaseFormat
);
2891 /* From the EXT_texture_integer spec:
2893 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2894 * if the texture internalformat is an integer format and the read color
2895 * buffer is not an integer format, or if the internalformat is not an
2896 * integer format and the read color buffer is an integer format."
2898 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2899 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2901 if (_mesa_is_format_integer_color(rb
->Format
) !=
2902 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2903 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2904 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2909 /* if we get here, the parameters are OK */
2914 /** Callback info for walking over FBO hash table */
2917 struct gl_context
*ctx
;
2918 struct gl_texture_object
*texObj
;
2924 * Check render to texture callback. Called from _mesa_HashWalk().
2927 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2929 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2930 const struct cb_info
*info
= (struct cb_info
*) userData
;
2931 struct gl_context
*ctx
= info
->ctx
;
2932 const struct gl_texture_object
*texObj
= info
->texObj
;
2933 const GLuint level
= info
->level
, face
= info
->face
;
2935 /* If this is a user-created FBO */
2936 if (_mesa_is_user_fbo(fb
)) {
2938 /* check if any of the FBO's attachments point to 'texObj' */
2939 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2940 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2941 if (att
->Type
== GL_TEXTURE
&&
2942 att
->Texture
== texObj
&&
2943 att
->TextureLevel
== level
&&
2944 att
->CubeMapFace
== face
) {
2945 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2946 ASSERT(att
->Renderbuffer
->TexImage
);
2947 /* Mark fb status as indeterminate to force re-validation */
2956 * When a texture image is specified we have to check if it's bound to
2957 * any framebuffer objects (render to texture) in order to detect changes
2958 * in size or format since that effects FBO completeness.
2959 * Any FBOs rendering into the texture must be re-validated.
2962 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2963 struct gl_texture_object
*texObj
,
2964 GLuint face
, GLuint level
)
2966 /* Only check this texture if it's been marked as RenderToTexture */
2967 if (texObj
->_RenderToTexture
) {
2968 struct cb_info info
;
2970 info
.texObj
= texObj
;
2973 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2979 * If the texture object's GenerateMipmap flag is set and we've
2980 * changed the texture base level image, regenerate the rest of the
2981 * mipmap levels now.
2984 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2985 struct gl_texture_object
*texObj
, GLint level
)
2987 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2988 if (texObj
->GenerateMipmap
&&
2989 level
== texObj
->BaseLevel
&&
2990 level
< texObj
->MaxLevel
) {
2991 ASSERT(ctx
->Driver
.GenerateMipmap
);
2992 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2997 /** Debug helper: override the user-requested internal format */
2999 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
3002 if (internalFormat
== GL_RGBA16F_ARB
||
3003 internalFormat
== GL_RGBA32F_ARB
) {
3004 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
3007 else if (internalFormat
== GL_RGB16F_ARB
||
3008 internalFormat
== GL_RGB32F_ARB
) {
3009 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
3012 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
3013 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
3014 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3015 return GL_LUMINANCE_ALPHA
;
3017 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
3018 internalFormat
== GL_LUMINANCE32F_ARB
) {
3019 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3020 return GL_LUMINANCE
;
3022 else if (internalFormat
== GL_ALPHA16F_ARB
||
3023 internalFormat
== GL_ALPHA32F_ARB
) {
3024 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
3028 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
3029 internalFormat = GL_RGBA;
3033 return internalFormat
;
3036 return internalFormat
;
3042 * Choose the actual hardware format for a texture image.
3043 * Try to use the same format as the previous image level when possible.
3044 * Otherwise, ask the driver for the best format.
3045 * It's important to try to choose a consistant format for all levels
3046 * for efficient texture memory layout/allocation. In particular, this
3047 * comes up during automatic mipmap generation.
3050 _mesa_choose_texture_format(struct gl_context
*ctx
,
3051 struct gl_texture_object
*texObj
,
3052 GLenum target
, GLint level
,
3053 GLenum internalFormat
, GLenum format
, GLenum type
)
3057 /* see if we've already chosen a format for the previous level */
3059 struct gl_texture_image
*prevImage
=
3060 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
3061 /* See if the prev level is defined and has an internal format which
3062 * matches the new internal format.
3065 prevImage
->Width
> 0 &&
3066 prevImage
->InternalFormat
== internalFormat
) {
3067 /* use the same format */
3068 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
3069 return prevImage
->TexFormat
;
3073 /* If the application requested compression to an S3TC format but we don't
3074 * have the DXTn library, force a generic compressed format instead.
3076 if (internalFormat
!= format
&& format
!= GL_NONE
) {
3077 const GLenum before
= internalFormat
;
3079 switch (internalFormat
) {
3080 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
3081 if (!ctx
->Mesa_DXTn
)
3082 internalFormat
= GL_COMPRESSED_RGB
;
3084 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
3085 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
3086 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
3087 if (!ctx
->Mesa_DXTn
)
3088 internalFormat
= GL_COMPRESSED_RGBA
;
3094 if (before
!= internalFormat
) {
3096 "DXT compression requested (%s), "
3097 "but libtxc_dxtn library not installed. Using %s "
3099 _mesa_lookup_enum_by_nr(before
),
3100 _mesa_lookup_enum_by_nr(internalFormat
));
3104 /* choose format from scratch */
3105 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, target
, internalFormat
,
3107 ASSERT(f
!= MESA_FORMAT_NONE
);
3113 * Adjust pixel unpack params and image dimensions to strip off the
3114 * one-pixel texture border.
3116 * Gallium and intel don't support texture borders. They've seldem been used
3117 * and seldom been implemented correctly anyway.
3119 * \param unpackNew returns the new pixel unpack parameters
3122 strip_texture_border(GLenum target
,
3123 GLint
*width
, GLint
*height
, GLint
*depth
,
3124 const struct gl_pixelstore_attrib
*unpack
,
3125 struct gl_pixelstore_attrib
*unpackNew
)
3131 *unpackNew
= *unpack
;
3133 if (unpackNew
->RowLength
== 0)
3134 unpackNew
->RowLength
= *width
;
3136 if (unpackNew
->ImageHeight
== 0)
3137 unpackNew
->ImageHeight
= *height
;
3139 assert(*width
>= 3);
3140 unpackNew
->SkipPixels
++; /* skip the border */
3141 *width
= *width
- 2; /* reduce the width by two border pixels */
3143 /* The min height of a texture with a border is 3 */
3144 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
3145 unpackNew
->SkipRows
++; /* skip the border */
3146 *height
= *height
- 2; /* reduce the height by two border pixels */
3150 target
!= GL_TEXTURE_2D_ARRAY
&&
3151 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
3152 unpackNew
->SkipImages
++; /* skip the border */
3153 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
3159 * Common code to implement all the glTexImage1D/2D/3D functions
3160 * as well as glCompressedTexImage1D/2D/3D.
3161 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
3162 * \param format the user's image format (only used if !compressed)
3163 * \param type the user's image type (only used if !compressed)
3164 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
3167 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
3168 GLenum target
, GLint level
, GLint internalFormat
,
3169 GLsizei width
, GLsizei height
, GLsizei depth
,
3170 GLint border
, GLenum format
, GLenum type
,
3171 GLsizei imageSize
, const GLvoid
*pixels
)
3173 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
3174 struct gl_pixelstore_attrib unpack_no_border
;
3175 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
3176 struct gl_texture_object
*texObj
;
3177 mesa_format texFormat
;
3178 GLboolean dimensionsOK
, sizeOK
;
3180 FLUSH_VERTICES(ctx
, 0);
3182 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3185 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3187 _mesa_lookup_enum_by_nr(target
), level
,
3188 _mesa_lookup_enum_by_nr(internalFormat
),
3189 width
, height
, depth
, border
, pixels
);
3192 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3194 _mesa_lookup_enum_by_nr(target
), level
,
3195 _mesa_lookup_enum_by_nr(internalFormat
),
3196 width
, height
, depth
, border
,
3197 _mesa_lookup_enum_by_nr(format
),
3198 _mesa_lookup_enum_by_nr(type
), pixels
);
3201 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3203 /* target error checking */
3204 if (!legal_teximage_target(ctx
, dims
, target
)) {
3205 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3206 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3210 /* general error checking */
3212 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3214 width
, height
, depth
,
3219 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3220 format
, type
, width
, height
, depth
, border
))
3224 /* Here we convert a cpal compressed image into a regular glTexImage2D
3225 * call by decompressing the texture. If we really want to support cpal
3226 * textures in any driver this would have to be changed.
3228 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3229 switch (internalFormat
) {
3230 case GL_PALETTE4_RGB8_OES
:
3231 case GL_PALETTE4_RGBA8_OES
:
3232 case GL_PALETTE4_R5_G6_B5_OES
:
3233 case GL_PALETTE4_RGBA4_OES
:
3234 case GL_PALETTE4_RGB5_A1_OES
:
3235 case GL_PALETTE8_RGB8_OES
:
3236 case GL_PALETTE8_RGBA8_OES
:
3237 case GL_PALETTE8_R5_G6_B5_OES
:
3238 case GL_PALETTE8_RGBA4_OES
:
3239 case GL_PALETTE8_RGB5_A1_OES
:
3240 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3241 width
, height
, imageSize
, pixels
);
3246 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3250 /* For glCompressedTexImage() the driver has no choice about the
3251 * texture format since we'll never transcode the user's compressed
3252 * image data. The internalFormat was error checked earlier.
3254 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3257 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3258 internalFormat
, format
, type
);
3261 assert(texFormat
!= MESA_FORMAT_NONE
);
3263 /* check that width, height, depth are legal for the mipmap level */
3264 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3265 height
, depth
, border
);
3267 /* check that the texture won't take too much memory, etc */
3268 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3270 width
, height
, depth
, border
);
3272 if (_mesa_is_proxy_texture(target
)) {
3273 /* Proxy texture: just clear or set state depending on error checking */
3274 struct gl_texture_image
*texImage
=
3275 get_proxy_tex_image(ctx
, target
, level
);
3278 return; /* GL_OUT_OF_MEMORY already recorded */
3280 if (dimensionsOK
&& sizeOK
) {
3281 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3282 border
, internalFormat
, texFormat
);
3285 clear_teximage_fields(texImage
);
3289 /* non-proxy target */
3290 const GLuint face
= _mesa_tex_target_to_face(target
);
3291 struct gl_texture_image
*texImage
;
3293 if (!dimensionsOK
) {
3294 _mesa_error(ctx
, GL_INVALID_VALUE
,
3295 "glTexImage%uD(invalid width or height or depth)",
3301 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3302 "glTexImage%uD(image too large)", dims
);
3306 /* Allow a hardware driver to just strip out the border, to provide
3307 * reliable but slightly incorrect hardware rendering instead of
3308 * rarely-tested software fallback rendering.
3310 if (border
&& ctx
->Const
.StripTextureBorder
) {
3311 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3314 unpack
= &unpack_no_border
;
3317 if (ctx
->NewState
& _NEW_PIXEL
)
3318 _mesa_update_state(ctx
);
3320 _mesa_lock_texture(ctx
, texObj
);
3322 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3325 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3328 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3330 _mesa_init_teximage_fields(ctx
, texImage
,
3331 width
, height
, depth
,
3332 border
, internalFormat
, texFormat
);
3334 /* Give the texture to the driver. <pixels> may be null. */
3335 if (width
> 0 && height
> 0 && depth
> 0) {
3337 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3341 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3342 type
, pixels
, unpack
);
3346 check_gen_mipmap(ctx
, target
, texObj
, level
);
3348 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3350 _mesa_dirty_texobj(ctx
, texObj
);
3353 _mesa_unlock_texture(ctx
, texObj
);
3360 * Called from the API. Note that width includes the border.
3363 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3364 GLsizei width
, GLint border
, GLenum format
,
3365 GLenum type
, const GLvoid
*pixels
)
3367 GET_CURRENT_CONTEXT(ctx
);
3368 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3369 border
, format
, type
, 0, pixels
);
3374 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3375 GLsizei width
, GLsizei height
, GLint border
,
3376 GLenum format
, GLenum type
,
3377 const GLvoid
*pixels
)
3379 GET_CURRENT_CONTEXT(ctx
);
3380 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3381 border
, format
, type
, 0, pixels
);
3386 * Called by the API or display list executor.
3387 * Note that width and height include the border.
3390 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3391 GLsizei width
, GLsizei height
, GLsizei depth
,
3392 GLint border
, GLenum format
, GLenum type
,
3393 const GLvoid
*pixels
)
3395 GET_CURRENT_CONTEXT(ctx
);
3396 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3397 width
, height
, depth
,
3398 border
, format
, type
, 0, pixels
);
3403 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3404 GLsizei width
, GLsizei height
, GLsizei depth
,
3405 GLint border
, GLenum format
, GLenum type
,
3406 const GLvoid
*pixels
)
3408 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3409 depth
, border
, format
, type
, pixels
);
3414 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3416 struct gl_texture_object
*texObj
;
3417 struct gl_texture_image
*texImage
;
3419 GET_CURRENT_CONTEXT(ctx
);
3420 FLUSH_VERTICES(ctx
, 0);
3424 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3426 case GL_TEXTURE_EXTERNAL_OES
:
3428 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3431 valid_target
= false;
3435 if (!valid_target
) {
3436 _mesa_error(ctx
, GL_INVALID_ENUM
,
3437 "glEGLImageTargetTexture2D(target=%d)", target
);
3442 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3443 "glEGLImageTargetTexture2D(image=%p)", image
);
3447 if (ctx
->NewState
& _NEW_PIXEL
)
3448 _mesa_update_state(ctx
);
3450 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3451 _mesa_lock_texture(ctx
, texObj
);
3453 if (texObj
->Immutable
) {
3454 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3455 "glEGLImageTargetTexture2D(texture is immutable)");
3456 _mesa_unlock_texture(ctx
, texObj
);
3460 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3462 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3464 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3466 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3467 texObj
, texImage
, image
);
3469 _mesa_dirty_texobj(ctx
, texObj
);
3471 _mesa_unlock_texture(ctx
, texObj
);
3478 * Implement all the glTexSubImage1/2/3D() functions.
3481 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3482 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3483 GLsizei width
, GLsizei height
, GLsizei depth
,
3484 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3486 struct gl_texture_object
*texObj
;
3487 struct gl_texture_image
*texImage
;
3489 FLUSH_VERTICES(ctx
, 0);
3491 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3492 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3494 _mesa_lookup_enum_by_nr(target
), level
,
3495 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3496 _mesa_lookup_enum_by_nr(format
),
3497 _mesa_lookup_enum_by_nr(type
), pixels
);
3499 /* check target (proxies not allowed) */
3500 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3501 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3502 dims
, _mesa_lookup_enum_by_nr(target
));
3506 if (ctx
->NewState
& _NEW_PIXEL
)
3507 _mesa_update_state(ctx
);
3509 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3510 xoffset
, yoffset
, zoffset
,
3511 width
, height
, depth
, format
, type
)) {
3512 return; /* error was detected */
3515 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3517 _mesa_lock_texture(ctx
, texObj
);
3519 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3521 if (width
> 0 && height
> 0 && depth
> 0) {
3522 /* If we have a border, offset=-1 is legal. Bias by border width. */
3525 if (target
!= GL_TEXTURE_2D_ARRAY
)
3526 zoffset
+= texImage
->Border
;
3529 if (target
!= GL_TEXTURE_1D_ARRAY
)
3530 yoffset
+= texImage
->Border
;
3533 xoffset
+= texImage
->Border
;
3536 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3537 xoffset
, yoffset
, zoffset
,
3538 width
, height
, depth
,
3539 format
, type
, pixels
, &ctx
->Unpack
);
3541 check_gen_mipmap(ctx
, target
, texObj
, level
);
3543 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3544 * the texel data, not the texture format, size, etc.
3548 _mesa_unlock_texture(ctx
, texObj
);
3553 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3554 GLint xoffset
, GLsizei width
,
3555 GLenum format
, GLenum type
,
3556 const GLvoid
*pixels
)
3558 GET_CURRENT_CONTEXT(ctx
);
3559 texsubimage(ctx
, 1, target
, level
,
3562 format
, type
, pixels
);
3567 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3568 GLint xoffset
, GLint yoffset
,
3569 GLsizei width
, GLsizei height
,
3570 GLenum format
, GLenum type
,
3571 const GLvoid
*pixels
)
3573 GET_CURRENT_CONTEXT(ctx
);
3574 texsubimage(ctx
, 2, target
, level
,
3575 xoffset
, yoffset
, 0,
3577 format
, type
, pixels
);
3583 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3584 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3585 GLsizei width
, GLsizei height
, GLsizei depth
,
3586 GLenum format
, GLenum type
,
3587 const GLvoid
*pixels
)
3589 GET_CURRENT_CONTEXT(ctx
);
3590 texsubimage(ctx
, 3, target
, level
,
3591 xoffset
, yoffset
, zoffset
,
3592 width
, height
, depth
,
3593 format
, type
, pixels
);
3599 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3600 * from. This depends on whether the texture contains color or depth values.
3602 static struct gl_renderbuffer
*
3603 get_copy_tex_image_source(struct gl_context
*ctx
, mesa_format texFormat
)
3605 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3606 /* reading from depth/stencil buffer */
3607 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3610 /* copying from color buffer */
3611 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3616 copytexsubimage_by_slice(struct gl_context
*ctx
,
3617 struct gl_texture_image
*texImage
,
3619 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3620 struct gl_renderbuffer
*rb
,
3622 GLsizei width
, GLsizei height
)
3624 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3627 /* For 1D arrays, we copy each scanline of the source rectangle into the
3630 assert(zoffset
== 0);
3632 for (slice
= 0; slice
< height
; slice
++) {
3633 assert(yoffset
+ slice
< texImage
->Height
);
3634 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3635 xoffset
, 0, yoffset
+ slice
,
3636 rb
, x
, y
+ slice
, width
, 1);
3639 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3640 xoffset
, yoffset
, zoffset
,
3641 rb
, x
, y
, width
, height
);
3646 formats_differ_in_component_sizes (mesa_format f1
,
3649 GLint f1_r_bits
= _mesa_get_format_bits(f1
, GL_RED_BITS
);
3650 GLint f1_g_bits
= _mesa_get_format_bits(f1
, GL_GREEN_BITS
);
3651 GLint f1_b_bits
= _mesa_get_format_bits(f1
, GL_BLUE_BITS
);
3652 GLint f1_a_bits
= _mesa_get_format_bits(f1
, GL_ALPHA_BITS
);
3654 GLint f2_r_bits
= _mesa_get_format_bits(f2
, GL_RED_BITS
);
3655 GLint f2_g_bits
= _mesa_get_format_bits(f2
, GL_GREEN_BITS
);
3656 GLint f2_b_bits
= _mesa_get_format_bits(f2
, GL_BLUE_BITS
);
3657 GLint f2_a_bits
= _mesa_get_format_bits(f2
, GL_ALPHA_BITS
);
3659 if ((f1_r_bits
&& f2_r_bits
&& f1_r_bits
!= f2_r_bits
)
3660 || (f1_g_bits
&& f2_g_bits
&& f1_g_bits
!= f2_g_bits
)
3661 || (f1_b_bits
&& f2_b_bits
&& f1_b_bits
!= f2_b_bits
)
3662 || (f1_a_bits
&& f2_a_bits
&& f1_a_bits
!= f2_a_bits
))
3669 * Implement the glCopyTexImage1/2D() functions.
3672 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3673 GLenum target
, GLint level
, GLenum internalFormat
,
3674 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3676 struct gl_texture_object
*texObj
;
3677 struct gl_texture_image
*texImage
;
3678 const GLuint face
= _mesa_tex_target_to_face(target
);
3679 mesa_format texFormat
;
3680 struct gl_renderbuffer
*rb
;
3682 FLUSH_VERTICES(ctx
, 0);
3684 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3685 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3687 _mesa_lookup_enum_by_nr(target
), level
,
3688 _mesa_lookup_enum_by_nr(internalFormat
),
3689 x
, y
, width
, height
, border
);
3691 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3692 _mesa_update_state(ctx
);
3694 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3695 width
, height
, border
))
3698 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3700 _mesa_error(ctx
, GL_INVALID_VALUE
,
3701 "glCopyTexImage%uD(invalid width or height)", dims
);
3705 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3708 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3709 internalFormat
, GL_NONE
, GL_NONE
);
3711 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
3713 if (_mesa_is_gles3(ctx
)) {
3714 if (_mesa_is_enum_format_unsized(internalFormat
)) {
3715 /* Conversion from GL_RGB10_A2 source buffer format is not allowed in
3716 * OpenGL ES 3.0. Khronos bug# 9807.
3718 if (rb
->InternalFormat
== GL_RGB10_A2
) {
3719 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3720 "glCopyTexImage%uD(Reading from GL_RGB10_A2 buffer and"
3721 " writing to unsized internal format)", dims
);
3725 /* From Page 139 of OpenGL ES 3.0 spec:
3726 * "If internalformat is sized, the internal format of the new texel
3727 * array is internalformat, and this is also the new texel array’s
3728 * effective internal format. If the component sizes of internalformat
3729 * do not exactly match the corresponding component sizes of the source
3730 * buffer’s effective internal format, described below, an
3731 * INVALID_OPERATION error is generated. If internalformat is unsized,
3732 * the internal format of the new texel array is the effective internal
3733 * format of the source buffer, and this is also the new texel array’s
3734 * effective internal format.
3736 else if (formats_differ_in_component_sizes (texFormat
, rb
->Format
)) {
3737 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3738 "glCopyTexImage%uD(componenet size changed in"
3739 " internal format)", dims
);
3744 assert(texFormat
!= MESA_FORMAT_NONE
);
3746 if (!ctx
->Driver
.TestProxyTexImage(ctx
, proxy_target(target
),
3748 width
, height
, 1, border
)) {
3749 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3750 "glCopyTexImage%uD(image too large)", dims
);
3754 if (border
&& ctx
->Const
.StripTextureBorder
) {
3756 width
-= border
* 2;
3759 height
-= border
* 2;
3764 _mesa_lock_texture(ctx
, texObj
);
3766 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3769 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3772 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3774 /* Free old texture image */
3775 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3777 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3778 border
, internalFormat
, texFormat
);
3780 if (width
&& height
) {
3781 /* Allocate texture memory (no pixel data yet) */
3782 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3784 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3786 struct gl_renderbuffer
*srcRb
=
3787 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3789 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3791 srcRb
, srcX
, srcY
, width
, height
);
3794 check_gen_mipmap(ctx
, target
, texObj
, level
);
3797 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3799 _mesa_dirty_texobj(ctx
, texObj
);
3802 _mesa_unlock_texture(ctx
, texObj
);
3808 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3809 GLenum internalFormat
,
3811 GLsizei width
, GLint border
)
3813 GET_CURRENT_CONTEXT(ctx
);
3814 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3820 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3821 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3824 GET_CURRENT_CONTEXT(ctx
);
3825 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3826 x
, y
, width
, height
, border
);
3832 * Implementation for glCopyTexSubImage1/2/3D() functions.
3835 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3836 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3837 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3839 struct gl_texture_object
*texObj
;
3840 struct gl_texture_image
*texImage
;
3842 FLUSH_VERTICES(ctx
, 0);
3844 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3845 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3847 _mesa_lookup_enum_by_nr(target
),
3848 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3850 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3851 _mesa_update_state(ctx
);
3853 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3854 xoffset
, yoffset
, zoffset
, width
, height
)) {
3858 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3860 _mesa_lock_texture(ctx
, texObj
);
3862 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3864 /* If we have a border, offset=-1 is legal. Bias by border width. */
3867 if (target
!= GL_TEXTURE_2D_ARRAY
)
3868 zoffset
+= texImage
->Border
;
3871 if (target
!= GL_TEXTURE_1D_ARRAY
)
3872 yoffset
+= texImage
->Border
;
3875 xoffset
+= texImage
->Border
;
3878 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3880 struct gl_renderbuffer
*srcRb
=
3881 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3883 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3884 xoffset
, yoffset
, zoffset
,
3885 srcRb
, x
, y
, width
, height
);
3887 check_gen_mipmap(ctx
, target
, texObj
, level
);
3889 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
3890 * the texel data, not the texture format, size, etc.
3894 _mesa_unlock_texture(ctx
, texObj
);
3899 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3900 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3902 GET_CURRENT_CONTEXT(ctx
);
3903 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3909 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3910 GLint xoffset
, GLint yoffset
,
3911 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3913 GET_CURRENT_CONTEXT(ctx
);
3914 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3921 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3922 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3923 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3925 GET_CURRENT_CONTEXT(ctx
);
3926 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3927 x
, y
, width
, height
);
3931 check_clear_tex_image(struct gl_context
*ctx
,
3932 const char *function
,
3933 struct gl_texture_image
*texImage
,
3934 GLenum format
, GLenum type
,
3936 GLubyte
*clearValue
)
3938 struct gl_texture_object
*texObj
= texImage
->TexObject
;
3939 static const GLubyte zeroData
[MAX_PIXEL_BYTES
];
3940 GLenum internalFormat
= texImage
->InternalFormat
;
3943 if (texObj
->Target
== GL_TEXTURE_BUFFER
) {
3944 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3945 "%s(buffer texture)", function
);
3949 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
3950 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3951 "%s(compressed texture)", function
);
3955 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
3956 if (err
!= GL_NO_ERROR
) {
3957 _mesa_error(ctx
, err
,
3958 "%s(incompatible format = %s, type = %s)",
3960 _mesa_lookup_enum_by_nr(format
),
3961 _mesa_lookup_enum_by_nr(type
));
3965 /* make sure internal format and format basically agree */
3966 if (!texture_formats_agree(internalFormat
, format
)) {
3967 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3968 "%s(incompatible internalFormat = %s, format = %s)",
3970 _mesa_lookup_enum_by_nr(internalFormat
),
3971 _mesa_lookup_enum_by_nr(format
));
3975 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
3976 /* both source and dest must be integer-valued, or neither */
3977 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
3978 _mesa_is_enum_format_integer(format
)) {
3979 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3980 "%s(integer/non-integer format mismatch)",
3986 if (!_mesa_texstore(ctx
,
3988 texImage
->_BaseFormat
,
3989 texImage
->TexFormat
,
3990 0, /* dstRowStride */
3992 1, 1, 1, /* srcWidth/Height/Depth */
3994 data
? data
: zeroData
,
3995 &ctx
->DefaultPacking
)) {
3996 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid format)", function
);
4003 static struct gl_texture_object
*
4004 get_tex_obj_for_clear(struct gl_context
*ctx
,
4005 const char *function
,
4008 struct gl_texture_object
*texObj
;
4011 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(zero texture)", function
);
4015 texObj
= _mesa_lookup_texture(ctx
, texture
);
4017 if (texObj
== NULL
) {
4018 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(non-gen name)", function
);
4022 if (texObj
->Target
== 0) {
4023 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unbound tex)", function
);
4031 get_tex_images_for_clear(struct gl_context
*ctx
,
4032 const char *function
,
4033 struct gl_texture_object
*texObj
,
4035 struct gl_texture_image
**texImages
)
4040 if (level
< 0 || level
>= MAX_TEXTURE_LEVELS
) {
4041 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4045 if (texObj
->Target
== GL_TEXTURE_CUBE_MAP
) {
4046 for (i
= 0; i
< MAX_FACES
; i
++) {
4047 target
= GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
;
4049 texImages
[i
] = _mesa_select_tex_image(ctx
, texObj
, target
, level
);
4050 if (texImages
[i
] == NULL
) {
4051 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4052 "%s(invalid level)", function
);
4060 texImages
[0] = _mesa_select_tex_image(ctx
, texObj
, texObj
->Target
, level
);
4062 if (texImages
[0] == NULL
) {
4063 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(invalid level)", function
);
4071 _mesa_ClearTexSubImage( GLuint texture
, GLint level
,
4072 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4073 GLsizei width
, GLsizei height
, GLsizei depth
,
4074 GLenum format
, GLenum type
, const void *data
)
4076 GET_CURRENT_CONTEXT(ctx
);
4077 struct gl_texture_object
*texObj
;
4078 struct gl_texture_image
*texImages
[MAX_FACES
];
4079 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4081 int minDepth
, maxDepth
;
4083 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexSubImage", texture
);
4088 _mesa_lock_texture(ctx
, texObj
);
4090 numImages
= get_tex_images_for_clear(ctx
, "glClearTexSubImage",
4091 texObj
, level
, texImages
);
4095 if (numImages
== 1) {
4096 minDepth
= -(int) texImages
[0]->Border
;
4097 maxDepth
= texImages
[0]->Depth
;
4100 maxDepth
= numImages
;
4103 if (xoffset
< -(GLint
) texImages
[0]->Border
||
4104 yoffset
< -(GLint
) texImages
[0]->Border
||
4105 zoffset
< minDepth
||
4109 xoffset
+ width
> texImages
[0]->Width
||
4110 yoffset
+ height
> texImages
[0]->Height
||
4111 zoffset
+ depth
> maxDepth
) {
4112 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4113 "glClearSubTexImage(invalid dimensions)");
4117 if (numImages
== 1) {
4118 if (check_clear_tex_image(ctx
, "glClearTexSubImage",
4120 format
, type
, data
, clearValue
[0])) {
4121 ctx
->Driver
.ClearTexSubImage(ctx
,
4123 xoffset
, yoffset
, zoffset
,
4124 width
, height
, depth
,
4125 data
? clearValue
[0] : NULL
);
4128 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4129 if (!check_clear_tex_image(ctx
, "glClearTexSubImage",
4131 format
, type
, data
, clearValue
[i
]))
4134 for (i
= zoffset
; i
< zoffset
+ depth
; i
++) {
4135 ctx
->Driver
.ClearTexSubImage(ctx
,
4137 xoffset
, yoffset
, 0,
4139 data
? clearValue
[i
] : NULL
);
4144 _mesa_unlock_texture(ctx
, texObj
);
4148 _mesa_ClearTexImage( GLuint texture
, GLint level
,
4149 GLenum format
, GLenum type
, const void *data
)
4151 GET_CURRENT_CONTEXT(ctx
);
4152 struct gl_texture_object
*texObj
;
4153 struct gl_texture_image
*texImages
[MAX_FACES
];
4154 GLubyte clearValue
[MAX_FACES
][MAX_PIXEL_BYTES
];
4157 texObj
= get_tex_obj_for_clear(ctx
, "glClearTexImage", texture
);
4162 _mesa_lock_texture(ctx
, texObj
);
4164 numImages
= get_tex_images_for_clear(ctx
, "glClearTexImage",
4165 texObj
, level
, texImages
);
4167 for (i
= 0; i
< numImages
; i
++) {
4168 if (!check_clear_tex_image(ctx
, "glClearTexImage",
4175 for (i
= 0; i
< numImages
; i
++) {
4176 ctx
->Driver
.ClearTexSubImage(ctx
, texImages
[i
],
4177 -(GLint
) texImages
[i
]->Border
, /* xoffset */
4178 -(GLint
) texImages
[i
]->Border
, /* yoffset */
4179 -(GLint
) texImages
[i
]->Border
, /* zoffset */
4180 texImages
[i
]->Width
,
4181 texImages
[i
]->Height
,
4182 texImages
[i
]->Depth
,
4183 data
? clearValue
[i
] : NULL
);
4187 _mesa_unlock_texture(ctx
, texObj
);
4193 /**********************************************************************/
4194 /****** Compressed Textures ******/
4195 /**********************************************************************/
4199 * Error checking for glCompressedTexSubImage[123]D().
4200 * \return error code or GL_NO_ERROR.
4203 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
4204 GLenum target
, GLint level
,
4205 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4206 GLsizei width
, GLsizei height
, GLsizei depth
,
4207 GLenum format
, GLsizei imageSize
)
4209 struct gl_texture_object
*texObj
;
4210 struct gl_texture_image
*texImage
;
4218 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
4219 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
4220 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
4221 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
4222 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
4223 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
4227 targetOK
= GL_FALSE
;
4232 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
4236 /* no 1D compressed textures at this time */
4237 targetOK
= GL_FALSE
;
4242 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexSubImage%uD(target)",
4247 /* this will catch any invalid compressed format token */
4248 if (!_mesa_is_compressed_format(ctx
, format
)) {
4249 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
4254 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
4255 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage%uD(level=%d)",
4260 /* Check for invalid pixel storage modes */
4261 if (!_mesa_compressed_texture_pixel_storage_error_check(ctx
, dims
,
4263 "glCompressedTexSubImage")) {
4268 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
4269 if (expectedSize
!= imageSize
) {
4270 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexSubImage%uD(size=%d)",
4275 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4277 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4278 "glCompressedTexSubImage%uD()", dims
);
4282 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
4284 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4285 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
4289 if ((GLint
) format
!= texImage
->InternalFormat
) {
4290 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4291 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
4295 if (compressedteximage_only_format(ctx
, format
)) {
4296 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4297 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
4302 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
4303 texImage
, xoffset
, yoffset
, zoffset
,
4304 width
, height
, depth
)) {
4313 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
4314 GLenum internalFormat
, GLsizei width
,
4315 GLint border
, GLsizei imageSize
,
4318 GET_CURRENT_CONTEXT(ctx
);
4319 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
4320 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4325 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
4326 GLenum internalFormat
, GLsizei width
,
4327 GLsizei height
, GLint border
, GLsizei imageSize
,
4330 GET_CURRENT_CONTEXT(ctx
);
4331 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
4332 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4337 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
4338 GLenum internalFormat
, GLsizei width
,
4339 GLsizei height
, GLsizei depth
, GLint border
,
4340 GLsizei imageSize
, const GLvoid
*data
)
4342 GET_CURRENT_CONTEXT(ctx
);
4343 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
4344 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
4349 * Common helper for glCompressedTexSubImage1/2/3D().
4352 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
4353 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4354 GLsizei width
, GLsizei height
, GLsizei depth
,
4355 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
4357 struct gl_texture_object
*texObj
;
4358 struct gl_texture_image
*texImage
;
4359 GET_CURRENT_CONTEXT(ctx
);
4360 FLUSH_VERTICES(ctx
, 0);
4362 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
4363 xoffset
, yoffset
, zoffset
,
4364 width
, height
, depth
,
4365 format
, imageSize
)) {
4369 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4371 _mesa_lock_texture(ctx
, texObj
);
4373 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
4376 if (width
> 0 && height
> 0 && depth
> 0) {
4377 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
4378 xoffset
, yoffset
, zoffset
,
4379 width
, height
, depth
,
4380 format
, imageSize
, data
);
4382 check_gen_mipmap(ctx
, target
, texObj
, level
);
4384 /* NOTE: Don't signal _NEW_TEXTURE since we've only changed
4385 * the texel data, not the texture format, size, etc.
4389 _mesa_unlock_texture(ctx
, texObj
);
4394 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
4395 GLsizei width
, GLenum format
,
4396 GLsizei imageSize
, const GLvoid
*data
)
4398 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
4399 format
, imageSize
, data
);
4404 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
4405 GLint yoffset
, GLsizei width
, GLsizei height
,
4406 GLenum format
, GLsizei imageSize
,
4409 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
4410 width
, height
, 1, format
, imageSize
, data
);
4415 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
4416 GLint yoffset
, GLint zoffset
, GLsizei width
,
4417 GLsizei height
, GLsizei depth
, GLenum format
,
4418 GLsizei imageSize
, const GLvoid
*data
)
4420 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
4421 width
, height
, depth
, format
, imageSize
, data
);
4425 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4427 if (ctx
->API
!= API_OPENGL_CORE
) {
4428 switch (internalFormat
) {
4430 return MESA_FORMAT_A_UNORM8
;
4432 return MESA_FORMAT_A_UNORM16
;
4433 case GL_ALPHA16F_ARB
:
4434 return MESA_FORMAT_A_FLOAT16
;
4435 case GL_ALPHA32F_ARB
:
4436 return MESA_FORMAT_A_FLOAT32
;
4437 case GL_ALPHA8I_EXT
:
4438 return MESA_FORMAT_A_SINT8
;
4439 case GL_ALPHA16I_EXT
:
4440 return MESA_FORMAT_A_SINT16
;
4441 case GL_ALPHA32I_EXT
:
4442 return MESA_FORMAT_A_SINT32
;
4443 case GL_ALPHA8UI_EXT
:
4444 return MESA_FORMAT_A_UINT8
;
4445 case GL_ALPHA16UI_EXT
:
4446 return MESA_FORMAT_A_UINT16
;
4447 case GL_ALPHA32UI_EXT
:
4448 return MESA_FORMAT_A_UINT32
;
4450 return MESA_FORMAT_L_UNORM8
;
4451 case GL_LUMINANCE16
:
4452 return MESA_FORMAT_L_UNORM16
;
4453 case GL_LUMINANCE16F_ARB
:
4454 return MESA_FORMAT_L_FLOAT16
;
4455 case GL_LUMINANCE32F_ARB
:
4456 return MESA_FORMAT_L_FLOAT32
;
4457 case GL_LUMINANCE8I_EXT
:
4458 return MESA_FORMAT_L_SINT8
;
4459 case GL_LUMINANCE16I_EXT
:
4460 return MESA_FORMAT_L_SINT16
;
4461 case GL_LUMINANCE32I_EXT
:
4462 return MESA_FORMAT_L_SINT32
;
4463 case GL_LUMINANCE8UI_EXT
:
4464 return MESA_FORMAT_L_UINT8
;
4465 case GL_LUMINANCE16UI_EXT
:
4466 return MESA_FORMAT_L_UINT16
;
4467 case GL_LUMINANCE32UI_EXT
:
4468 return MESA_FORMAT_L_UINT32
;
4469 case GL_LUMINANCE8_ALPHA8
:
4470 return MESA_FORMAT_L8A8_UNORM
;
4471 case GL_LUMINANCE16_ALPHA16
:
4472 return MESA_FORMAT_L16A16_UNORM
;
4473 case GL_LUMINANCE_ALPHA16F_ARB
:
4474 return MESA_FORMAT_LA_FLOAT16
;
4475 case GL_LUMINANCE_ALPHA32F_ARB
:
4476 return MESA_FORMAT_LA_FLOAT32
;
4477 case GL_LUMINANCE_ALPHA8I_EXT
:
4478 return MESA_FORMAT_LA_SINT8
;
4479 case GL_LUMINANCE_ALPHA16I_EXT
:
4480 return MESA_FORMAT_LA_SINT8
;
4481 case GL_LUMINANCE_ALPHA32I_EXT
:
4482 return MESA_FORMAT_LA_SINT16
;
4483 case GL_LUMINANCE_ALPHA8UI_EXT
:
4484 return MESA_FORMAT_LA_UINT8
;
4485 case GL_LUMINANCE_ALPHA16UI_EXT
:
4486 return MESA_FORMAT_LA_UINT16
;
4487 case GL_LUMINANCE_ALPHA32UI_EXT
:
4488 return MESA_FORMAT_LA_UINT32
;
4490 return MESA_FORMAT_I_UNORM8
;
4491 case GL_INTENSITY16
:
4492 return MESA_FORMAT_I_UNORM16
;
4493 case GL_INTENSITY16F_ARB
:
4494 return MESA_FORMAT_I_FLOAT16
;
4495 case GL_INTENSITY32F_ARB
:
4496 return MESA_FORMAT_I_FLOAT32
;
4497 case GL_INTENSITY8I_EXT
:
4498 return MESA_FORMAT_I_SINT8
;
4499 case GL_INTENSITY16I_EXT
:
4500 return MESA_FORMAT_I_SINT16
;
4501 case GL_INTENSITY32I_EXT
:
4502 return MESA_FORMAT_I_SINT32
;
4503 case GL_INTENSITY8UI_EXT
:
4504 return MESA_FORMAT_I_UINT8
;
4505 case GL_INTENSITY16UI_EXT
:
4506 return MESA_FORMAT_I_UINT16
;
4507 case GL_INTENSITY32UI_EXT
:
4508 return MESA_FORMAT_I_UINT32
;
4514 if (ctx
->API
== API_OPENGL_CORE
&&
4515 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4516 switch (internalFormat
) {
4518 return MESA_FORMAT_RGB_FLOAT32
;
4520 return MESA_FORMAT_RGB_UINT32
;
4522 return MESA_FORMAT_RGB_SINT32
;
4528 switch (internalFormat
) {
4530 return MESA_FORMAT_R8G8B8A8_UNORM
;
4532 return MESA_FORMAT_RGBA_UNORM16
;
4533 case GL_RGBA16F_ARB
:
4534 return MESA_FORMAT_RGBA_FLOAT16
;
4535 case GL_RGBA32F_ARB
:
4536 return MESA_FORMAT_RGBA_FLOAT32
;
4538 return MESA_FORMAT_RGBA_SINT8
;
4539 case GL_RGBA16I_EXT
:
4540 return MESA_FORMAT_RGBA_SINT16
;
4541 case GL_RGBA32I_EXT
:
4542 return MESA_FORMAT_RGBA_SINT32
;
4543 case GL_RGBA8UI_EXT
:
4544 return MESA_FORMAT_RGBA_UINT8
;
4545 case GL_RGBA16UI_EXT
:
4546 return MESA_FORMAT_RGBA_UINT16
;
4547 case GL_RGBA32UI_EXT
:
4548 return MESA_FORMAT_RGBA_UINT32
;
4551 return MESA_FORMAT_R8G8_UNORM
;
4553 return MESA_FORMAT_R16G16_UNORM
;
4555 return MESA_FORMAT_RG_FLOAT16
;
4557 return MESA_FORMAT_RG_FLOAT32
;
4559 return MESA_FORMAT_RG_SINT8
;
4561 return MESA_FORMAT_RG_SINT16
;
4563 return MESA_FORMAT_RG_SINT32
;
4565 return MESA_FORMAT_RG_UINT8
;
4567 return MESA_FORMAT_RG_UINT16
;
4569 return MESA_FORMAT_RG_UINT32
;
4572 return MESA_FORMAT_R_UNORM8
;
4574 return MESA_FORMAT_R_UNORM16
;
4576 return MESA_FORMAT_R_FLOAT16
;
4578 return MESA_FORMAT_R_FLOAT32
;
4580 return MESA_FORMAT_R_SINT8
;
4582 return MESA_FORMAT_R_SINT16
;
4584 return MESA_FORMAT_R_SINT32
;
4586 return MESA_FORMAT_R_UINT8
;
4588 return MESA_FORMAT_R_UINT16
;
4590 return MESA_FORMAT_R_UINT32
;
4593 return MESA_FORMAT_NONE
;
4599 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4600 GLenum internalFormat
)
4602 mesa_format format
= get_texbuffer_format(ctx
, internalFormat
);
4605 if (format
== MESA_FORMAT_NONE
)
4606 return MESA_FORMAT_NONE
;
4608 datatype
= _mesa_get_format_datatype(format
);
4610 /* The GL_ARB_texture_buffer_object spec says:
4612 * "If ARB_texture_float is not supported, references to the
4613 * floating-point internal formats provided by that extension should be
4614 * removed, and such formats may not be passed to TexBufferARB."
4616 * As a result, GL_HALF_FLOAT internal format depends on both
4617 * GL_ARB_texture_float and GL_ARB_half_float_pixel.
4619 if ((datatype
== GL_FLOAT
|| datatype
== GL_HALF_FLOAT
) &&
4620 !ctx
->Extensions
.ARB_texture_float
)
4621 return MESA_FORMAT_NONE
;
4623 if (!ctx
->Extensions
.ARB_texture_rg
) {
4624 GLenum base_format
= _mesa_get_format_base_format(format
);
4625 if (base_format
== GL_R
|| base_format
== GL_RG
)
4626 return MESA_FORMAT_NONE
;
4629 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4630 GLenum base_format
= _mesa_get_format_base_format(format
);
4631 if (base_format
== GL_RGB
)
4632 return MESA_FORMAT_NONE
;
4639 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4640 struct gl_buffer_object
*bufObj
,
4641 GLintptr offset
, GLsizeiptr size
)
4643 struct gl_texture_object
*texObj
;
4646 FLUSH_VERTICES(ctx
, 0);
4648 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4649 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4653 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
4654 if (format
== MESA_FORMAT_NONE
) {
4655 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4660 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4662 _mesa_lock_texture(ctx
, texObj
);
4664 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4665 texObj
->BufferObjectFormat
= internalFormat
;
4666 texObj
->_BufferObjectFormat
= format
;
4667 texObj
->BufferOffset
= offset
;
4668 texObj
->BufferSize
= size
;
4670 _mesa_unlock_texture(ctx
, texObj
);
4674 /** GL_ARB_texture_buffer_object */
4676 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4678 struct gl_buffer_object
*bufObj
;
4680 GET_CURRENT_CONTEXT(ctx
);
4682 /* NOTE: ARB_texture_buffer_object has interactions with
4683 * the compatibility profile that are not implemented.
4685 if (!(ctx
->API
== API_OPENGL_CORE
&&
4686 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4687 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4691 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4692 if (!bufObj
&& buffer
) {
4693 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4697 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4701 /** GL_ARB_texture_buffer_range */
4703 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4704 GLintptr offset
, GLsizeiptr size
)
4706 struct gl_buffer_object
*bufObj
;
4708 GET_CURRENT_CONTEXT(ctx
);
4710 if (!(ctx
->API
== API_OPENGL_CORE
&&
4711 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4712 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4716 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4720 (offset
+ size
) > bufObj
->Size
) {
4721 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4724 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4725 _mesa_error(ctx
, GL_INVALID_VALUE
,
4726 "glTexBufferRange(invalid offset alignment)");
4729 } else if (buffer
) {
4730 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4738 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4743 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4745 /* Everything that is allowed for renderbuffers,
4746 * except for a base format of GL_STENCIL_INDEX.
4748 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4749 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4753 /** GL_ARB_texture_multisample */
4755 check_multisample_target(GLuint dims
, GLenum target
)
4758 case GL_TEXTURE_2D_MULTISAMPLE
:
4759 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4762 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4763 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4773 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4774 GLint internalformat
, GLsizei width
, GLsizei height
,
4775 GLsizei depth
, GLboolean fixedsamplelocations
,
4776 GLboolean immutable
, const char *func
)
4778 struct gl_texture_object
*texObj
;
4779 struct gl_texture_image
*texImage
;
4780 GLboolean sizeOK
, dimensionsOK
, samplesOK
;
4781 mesa_format texFormat
;
4782 GLenum sample_count_error
;
4784 GET_CURRENT_CONTEXT(ctx
);
4786 if (!(ctx
->Extensions
.ARB_texture_multisample
4787 && _mesa_is_desktop_gl(ctx
))) {
4788 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4792 if (!check_multisample_target(dims
, target
)) {
4793 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4797 /* check that the specified internalformat is color/depth/stencil-renderable;
4798 * refer GL3.1 spec 4.4.4
4801 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4802 _mesa_error(ctx
, GL_INVALID_ENUM
,
4803 "%s(internalformat=%s not legal for immutable-format)",
4804 func
, _mesa_lookup_enum_by_nr(internalformat
));
4808 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4809 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4810 "%s(internalformat=%s)",
4811 func
, _mesa_lookup_enum_by_nr(internalformat
));
4815 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4816 internalformat
, samples
);
4817 samplesOK
= sample_count_error
== GL_NO_ERROR
;
4819 /* Page 254 of OpenGL 4.4 spec says:
4820 * "Proxy arrays for two-dimensional multisample and two-dimensional
4821 * multisample array textures are operated on in the same way when
4822 * TexImage2DMultisample is called with target specified as
4823 * PROXY_TEXTURE_2D_MULTISAMPLE, or TexImage3DMultisample is called
4824 * with target specified as PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY.
4825 * However, if samples is not supported, then no error is generated.
4827 if (!samplesOK
&& !_mesa_is_proxy_texture(target
)) {
4828 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4832 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4834 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4835 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4836 "%s(texture object 0)",
4841 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4843 if (texImage
== NULL
) {
4844 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4848 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4849 internalformat
, GL_NONE
, GL_NONE
);
4850 assert(texFormat
!= MESA_FORMAT_NONE
);
4852 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4853 width
, height
, depth
, 0);
4855 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4856 width
, height
, depth
, 0);
4858 if (_mesa_is_proxy_texture(target
)) {
4859 if (samplesOK
&& dimensionsOK
&& sizeOK
) {
4860 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
4861 internalformat
, texFormat
,
4862 samples
, fixedsamplelocations
);
4865 /* clear all image fields */
4866 clear_teximage_fields(texImage
);
4870 if (!dimensionsOK
) {
4871 _mesa_error(ctx
, GL_INVALID_VALUE
,
4872 "%s(invalid width or height)", func
);
4877 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4878 "%s(texture too large)", func
);
4882 /* Check if texObj->Immutable is set */
4883 if (texObj
->Immutable
) {
4884 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4888 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4890 init_teximage_fields_ms(ctx
, texImage
, width
, height
, depth
, 0,
4891 internalformat
, texFormat
,
4892 samples
, fixedsamplelocations
);
4894 if (width
> 0 && height
> 0 && depth
> 0) {
4895 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4896 width
, height
, depth
)) {
4897 /* tidy up the texture image state. strictly speaking,
4898 * we're allowed to just leave this in whatever state we
4899 * like, but being tidy is good.
4901 _mesa_init_teximage_fields(ctx
, texImage
,
4902 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4906 texObj
->Immutable
= immutable
;
4909 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
4912 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4918 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4919 GLenum internalformat
, GLsizei width
,
4920 GLsizei height
, GLboolean fixedsamplelocations
)
4922 teximagemultisample(2, target
, samples
, internalformat
,
4923 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4924 "glTexImage2DMultisample");
4929 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4930 GLenum internalformat
, GLsizei width
,
4931 GLsizei height
, GLsizei depth
,
4932 GLboolean fixedsamplelocations
)
4934 teximagemultisample(3, target
, samples
, internalformat
,
4935 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4936 "glTexImage3DMultisample");
4941 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4942 GLenum internalformat
, GLsizei width
,
4943 GLsizei height
, GLboolean fixedsamplelocations
)
4945 teximagemultisample(2, target
, samples
, internalformat
,
4946 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4947 "glTexStorage2DMultisample");
4951 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4952 GLenum internalformat
, GLsizei width
,
4953 GLsizei height
, GLsizei depth
,
4954 GLboolean fixedsamplelocations
)
4956 teximagemultisample(3, target
, samples
, internalformat
,
4957 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4958 "glTexStorage3DMultisample");