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"
57 * State changes which we care about for glCopyTex[Sub]Image() calls.
58 * In particular, we care about pixel transfer state and buffer state
59 * (such as glReadBuffer to make sure we read from the right renderbuffer).
61 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
66 * Return the simple base format for a given internal texture format.
67 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
69 * \param ctx GL context.
70 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
72 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
73 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
75 * This is the format which is used during texture application (i.e. the
76 * texture format and env mode determine the arithmetic used.
79 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
81 switch (internalFormat
) {
87 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
94 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
96 case GL_LUMINANCE_ALPHA
:
97 case GL_LUMINANCE4_ALPHA4
:
98 case GL_LUMINANCE6_ALPHA2
:
99 case GL_LUMINANCE8_ALPHA8
:
100 case GL_LUMINANCE12_ALPHA4
:
101 case GL_LUMINANCE12_ALPHA12
:
102 case GL_LUMINANCE16_ALPHA16
:
103 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
109 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
111 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
122 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
136 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
138 if (_mesa_is_gles(ctx
)) {
139 switch (internalFormat
) {
147 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
148 switch (internalFormat
) {
156 if (ctx
->Extensions
.ARB_depth_texture
) {
157 switch (internalFormat
) {
158 case GL_DEPTH_COMPONENT
:
159 case GL_DEPTH_COMPONENT16
:
160 case GL_DEPTH_COMPONENT24
:
161 case GL_DEPTH_COMPONENT32
:
162 return GL_DEPTH_COMPONENT
;
168 switch (internalFormat
) {
169 case GL_COMPRESSED_ALPHA
:
171 case GL_COMPRESSED_LUMINANCE
:
173 case GL_COMPRESSED_LUMINANCE_ALPHA
:
174 return GL_LUMINANCE_ALPHA
;
175 case GL_COMPRESSED_INTENSITY
:
177 case GL_COMPRESSED_RGB
:
179 case GL_COMPRESSED_RGBA
:
185 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
186 switch (internalFormat
) {
187 case GL_COMPRESSED_RGB_FXT1_3DFX
:
189 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
196 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
198 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
199 switch (internalFormat
) {
200 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
202 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
203 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
204 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
211 if (_mesa_is_desktop_gl(ctx
)
212 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
213 switch (internalFormat
) {
225 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
226 if (internalFormat
== GL_YCBCR_MESA
)
227 return GL_YCBCR_MESA
;
230 if (ctx
->Extensions
.ARB_texture_float
) {
231 switch (internalFormat
) {
232 case GL_ALPHA16F_ARB
:
233 case GL_ALPHA32F_ARB
:
241 case GL_INTENSITY16F_ARB
:
242 case GL_INTENSITY32F_ARB
:
244 case GL_LUMINANCE16F_ARB
:
245 case GL_LUMINANCE32F_ARB
:
247 case GL_LUMINANCE_ALPHA16F_ARB
:
248 case GL_LUMINANCE_ALPHA32F_ARB
:
249 return GL_LUMINANCE_ALPHA
;
255 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
256 switch (internalFormat
) {
265 if (ctx
->Extensions
.EXT_texture_snorm
) {
266 switch (internalFormat
) {
281 case GL_RGBA16_SNORM
:
284 case GL_ALPHA8_SNORM
:
285 case GL_ALPHA16_SNORM
:
287 case GL_LUMINANCE_SNORM
:
288 case GL_LUMINANCE8_SNORM
:
289 case GL_LUMINANCE16_SNORM
:
291 case GL_LUMINANCE_ALPHA_SNORM
:
292 case GL_LUMINANCE8_ALPHA8_SNORM
:
293 case GL_LUMINANCE16_ALPHA16_SNORM
:
294 return GL_LUMINANCE_ALPHA
;
295 case GL_INTENSITY_SNORM
:
296 case GL_INTENSITY8_SNORM
:
297 case GL_INTENSITY16_SNORM
:
304 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
305 switch (internalFormat
) {
306 case GL_DEPTH_STENCIL_EXT
:
307 case GL_DEPTH24_STENCIL8_EXT
:
308 return GL_DEPTH_STENCIL_EXT
;
314 if (ctx
->Extensions
.EXT_texture_sRGB
) {
315 switch (internalFormat
) {
318 case GL_COMPRESSED_SRGB_EXT
:
320 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
321 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
322 case GL_SRGB_ALPHA_EXT
:
323 case GL_SRGB8_ALPHA8_EXT
:
324 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
326 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
327 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
328 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
329 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
330 case GL_SLUMINANCE_ALPHA_EXT
:
331 case GL_SLUMINANCE8_ALPHA8_EXT
:
332 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
333 return GL_LUMINANCE_ALPHA
;
334 case GL_SLUMINANCE_EXT
:
335 case GL_SLUMINANCE8_EXT
:
336 case GL_COMPRESSED_SLUMINANCE_EXT
:
343 if (ctx
->Version
>= 30 ||
344 ctx
->Extensions
.EXT_texture_integer
) {
345 switch (internalFormat
) {
347 case GL_RGBA16UI_EXT
:
348 case GL_RGBA32UI_EXT
:
364 if (ctx
->Extensions
.EXT_texture_integer
) {
365 switch (internalFormat
) {
366 case GL_ALPHA8UI_EXT
:
367 case GL_ALPHA16UI_EXT
:
368 case GL_ALPHA32UI_EXT
:
370 case GL_ALPHA16I_EXT
:
371 case GL_ALPHA32I_EXT
:
373 case GL_INTENSITY8UI_EXT
:
374 case GL_INTENSITY16UI_EXT
:
375 case GL_INTENSITY32UI_EXT
:
376 case GL_INTENSITY8I_EXT
:
377 case GL_INTENSITY16I_EXT
:
378 case GL_INTENSITY32I_EXT
:
380 case GL_LUMINANCE8UI_EXT
:
381 case GL_LUMINANCE16UI_EXT
:
382 case GL_LUMINANCE32UI_EXT
:
383 case GL_LUMINANCE8I_EXT
:
384 case GL_LUMINANCE16I_EXT
:
385 case GL_LUMINANCE32I_EXT
:
387 case GL_LUMINANCE_ALPHA8UI_EXT
:
388 case GL_LUMINANCE_ALPHA16UI_EXT
:
389 case GL_LUMINANCE_ALPHA32UI_EXT
:
390 case GL_LUMINANCE_ALPHA8I_EXT
:
391 case GL_LUMINANCE_ALPHA16I_EXT
:
392 case GL_LUMINANCE_ALPHA32I_EXT
:
393 return GL_LUMINANCE_ALPHA
;
399 if (ctx
->Extensions
.ARB_texture_rg
) {
400 switch (internalFormat
) {
402 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
404 if (!ctx
->Extensions
.ARB_half_float_pixel
)
408 if (!ctx
->Extensions
.ARB_texture_float
)
417 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
423 case GL_COMPRESSED_RED
:
427 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
429 if (!ctx
->Extensions
.ARB_half_float_pixel
)
433 if (!ctx
->Extensions
.ARB_texture_float
)
442 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
448 case GL_COMPRESSED_RG
:
455 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
456 switch (internalFormat
) {
464 if (ctx
->Extensions
.EXT_packed_float
) {
465 switch (internalFormat
) {
466 case GL_R11F_G11F_B10F_EXT
:
473 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
474 switch (internalFormat
) {
475 case GL_DEPTH_COMPONENT32F
:
476 return GL_DEPTH_COMPONENT
;
477 case GL_DEPTH32F_STENCIL8
:
478 return GL_DEPTH_STENCIL
;
484 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
485 switch (internalFormat
) {
486 case GL_COMPRESSED_RED_RGTC1
:
487 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
489 case GL_COMPRESSED_RG_RGTC2
:
490 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
497 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
498 switch (internalFormat
) {
499 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
500 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
502 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
503 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
504 return GL_LUMINANCE_ALPHA
;
510 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
511 switch (internalFormat
) {
512 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
513 return GL_LUMINANCE_ALPHA
;
519 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
520 switch (internalFormat
) {
521 case GL_ETC1_RGB8_OES
:
528 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
529 switch (internalFormat
) {
530 case GL_COMPRESSED_RGB8_ETC2
:
531 case GL_COMPRESSED_SRGB8_ETC2
:
533 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
534 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
535 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
536 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
538 case GL_COMPRESSED_R11_EAC
:
539 case GL_COMPRESSED_SIGNED_R11_EAC
:
541 case GL_COMPRESSED_RG11_EAC
:
542 case GL_COMPRESSED_SIGNED_RG11_EAC
:
549 if (ctx
->API
== API_OPENGLES
) {
550 switch (internalFormat
) {
551 case GL_PALETTE4_RGB8_OES
:
552 case GL_PALETTE4_R5_G6_B5_OES
:
553 case GL_PALETTE8_RGB8_OES
:
554 case GL_PALETTE8_R5_G6_B5_OES
:
556 case GL_PALETTE4_RGBA8_OES
:
557 case GL_PALETTE8_RGB5_A1_OES
:
558 case GL_PALETTE4_RGBA4_OES
:
559 case GL_PALETTE4_RGB5_A1_OES
:
560 case GL_PALETTE8_RGBA8_OES
:
561 case GL_PALETTE8_RGBA4_OES
:
568 return -1; /* error */
573 * For cube map faces, return a face index in [0,5].
574 * For other targets return 0;
577 _mesa_tex_target_to_face(GLenum target
)
579 if (_mesa_is_cube_face(target
))
580 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
588 * Install gl_texture_image in a gl_texture_object according to the target
589 * and level parameters.
591 * \param tObj texture object.
592 * \param target texture target.
593 * \param level image level.
594 * \param texImage texture image.
597 set_tex_image(struct gl_texture_object
*tObj
,
598 GLenum target
, GLint level
,
599 struct gl_texture_image
*texImage
)
601 const GLuint face
= _mesa_tex_target_to_face(target
);
605 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
608 tObj
->Image
[face
][level
] = texImage
;
610 /* Set the 'back' pointer */
611 texImage
->TexObject
= tObj
;
612 texImage
->Level
= level
;
613 texImage
->Face
= face
;
618 * Allocate a texture image structure.
620 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
623 * \return a pointer to gl_texture_image struct with all fields initialized to
626 struct gl_texture_image
*
627 _mesa_new_texture_image( struct gl_context
*ctx
)
630 return CALLOC_STRUCT(gl_texture_image
);
635 * Free a gl_texture_image and associated data.
636 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
638 * \param texImage texture image.
640 * Free the texture image structure and the associated image data.
643 _mesa_delete_texture_image(struct gl_context
*ctx
,
644 struct gl_texture_image
*texImage
)
646 /* Free texImage->Data and/or any other driver-specific texture
649 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
650 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
656 * Test if a target is a proxy target.
658 * \param target texture target.
660 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
663 _mesa_is_proxy_texture(GLenum target
)
666 static const GLenum targets
[] = {
670 GL_PROXY_TEXTURE_CUBE_MAP
,
671 GL_PROXY_TEXTURE_RECTANGLE
,
672 GL_PROXY_TEXTURE_1D_ARRAY
,
673 GL_PROXY_TEXTURE_2D_ARRAY
,
674 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
675 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
676 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
679 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
680 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
682 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== Elements(targets
) + 2);
684 for (i
= 0; i
< Elements(targets
); ++i
)
685 if (target
== targets
[i
])
692 * Return the proxy target which corresponds to the given texture target
695 _mesa_get_proxy_target(GLenum target
)
699 case GL_PROXY_TEXTURE_1D
:
700 return GL_PROXY_TEXTURE_1D
;
702 case GL_PROXY_TEXTURE_2D
:
703 return GL_PROXY_TEXTURE_2D
;
705 case GL_PROXY_TEXTURE_3D
:
706 return GL_PROXY_TEXTURE_3D
;
707 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
708 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
709 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
710 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
711 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
712 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
713 case GL_TEXTURE_CUBE_MAP_ARB
:
714 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
715 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
716 case GL_TEXTURE_RECTANGLE_NV
:
717 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
718 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
719 case GL_TEXTURE_1D_ARRAY_EXT
:
720 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
721 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
722 case GL_TEXTURE_2D_ARRAY_EXT
:
723 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
724 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
725 case GL_TEXTURE_CUBE_MAP_ARRAY
:
726 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
727 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
728 case GL_TEXTURE_2D_MULTISAMPLE
:
729 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
730 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
731 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
732 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
733 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
735 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
742 * Get the texture object that corresponds to the target of the given
743 * texture unit. The target should have already been checked for validity.
745 * \param ctx GL context.
746 * \param texUnit texture unit.
747 * \param target texture target.
749 * \return pointer to the texture object on success, or NULL on failure.
751 struct gl_texture_object
*
752 _mesa_select_tex_object(struct gl_context
*ctx
,
753 const struct gl_texture_unit
*texUnit
,
756 const GLboolean arrayTex
= ctx
->Extensions
.EXT_texture_array
;
760 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
761 case GL_PROXY_TEXTURE_1D
:
762 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
764 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
765 case GL_PROXY_TEXTURE_2D
:
766 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
768 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
769 case GL_PROXY_TEXTURE_3D
:
770 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
771 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
772 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
773 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
774 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
775 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
776 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
777 case GL_TEXTURE_CUBE_MAP_ARB
:
778 return ctx
->Extensions
.ARB_texture_cube_map
779 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
780 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
781 return ctx
->Extensions
.ARB_texture_cube_map
782 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
783 case GL_TEXTURE_CUBE_MAP_ARRAY
:
784 return ctx
->Extensions
.ARB_texture_cube_map_array
785 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
786 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
787 return ctx
->Extensions
.ARB_texture_cube_map_array
788 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
789 case GL_TEXTURE_RECTANGLE_NV
:
790 return ctx
->Extensions
.NV_texture_rectangle
791 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
792 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
793 return ctx
->Extensions
.NV_texture_rectangle
794 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
795 case GL_TEXTURE_1D_ARRAY_EXT
:
796 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
797 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
798 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
799 case GL_TEXTURE_2D_ARRAY_EXT
:
800 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
801 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
802 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
803 case GL_TEXTURE_BUFFER
:
804 return ctx
->API
== API_OPENGL_CORE
&&
805 ctx
->Extensions
.ARB_texture_buffer_object
?
806 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
807 case GL_TEXTURE_EXTERNAL_OES
:
808 return _mesa_is_gles(ctx
) && ctx
->Extensions
.OES_EGL_image_external
809 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
810 case GL_TEXTURE_2D_MULTISAMPLE
:
811 return ctx
->Extensions
.ARB_texture_multisample
812 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
813 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
814 return ctx
->Extensions
.ARB_texture_multisample
815 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
816 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
817 return ctx
->Extensions
.ARB_texture_multisample
818 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
819 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
820 return ctx
->Extensions
.ARB_texture_multisample
821 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
823 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
830 * Return pointer to texture object for given target on current texture unit.
832 struct gl_texture_object
*
833 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
835 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
836 return _mesa_select_tex_object(ctx
, texUnit
, target
);
841 * Get a texture image pointer from a texture object, given a texture
842 * target and mipmap level. The target and level parameters should
843 * have already been error-checked.
845 * \param ctx GL context.
846 * \param texObj texture unit.
847 * \param target texture target.
848 * \param level image level.
850 * \return pointer to the texture image structure, or NULL on failure.
852 struct gl_texture_image
*
853 _mesa_select_tex_image(struct gl_context
*ctx
,
854 const struct gl_texture_object
*texObj
,
855 GLenum target
, GLint level
)
857 const GLuint face
= _mesa_tex_target_to_face(target
);
861 ASSERT(level
< MAX_TEXTURE_LEVELS
);
863 return texObj
->Image
[face
][level
];
868 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
869 * it and install it. Only return NULL if passed a bad parameter or run
872 struct gl_texture_image
*
873 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
874 GLenum target
, GLint level
)
876 struct gl_texture_image
*texImage
;
881 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
883 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
885 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
889 set_tex_image(texObj
, target
, level
, texImage
);
897 * Return pointer to the specified proxy texture image.
898 * Note that proxy textures are per-context, not per-texture unit.
899 * \return pointer to texture image or NULL if invalid target, invalid
900 * level, or out of memory.
902 static struct gl_texture_image
*
903 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
905 struct gl_texture_image
*texImage
;
912 case GL_PROXY_TEXTURE_1D
:
913 if (level
>= ctx
->Const
.MaxTextureLevels
)
915 texIndex
= TEXTURE_1D_INDEX
;
917 case GL_PROXY_TEXTURE_2D
:
918 if (level
>= ctx
->Const
.MaxTextureLevels
)
920 texIndex
= TEXTURE_2D_INDEX
;
922 case GL_PROXY_TEXTURE_3D
:
923 if (level
>= ctx
->Const
.Max3DTextureLevels
)
925 texIndex
= TEXTURE_3D_INDEX
;
927 case GL_PROXY_TEXTURE_CUBE_MAP
:
928 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
930 texIndex
= TEXTURE_CUBE_INDEX
;
932 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
935 texIndex
= TEXTURE_RECT_INDEX
;
937 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
938 if (level
>= ctx
->Const
.MaxTextureLevels
)
940 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
942 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
943 if (level
>= ctx
->Const
.MaxTextureLevels
)
945 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
947 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
948 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
950 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
952 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
955 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
957 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
960 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
966 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
968 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
970 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
973 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
974 /* Set the 'back' pointer */
975 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
982 * Get the maximum number of allowed mipmap levels.
984 * \param ctx GL context.
985 * \param target texture target.
987 * \return the maximum number of allowed mipmap levels for the given
988 * texture target, or zero if passed a bad target.
993 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
997 case GL_PROXY_TEXTURE_1D
:
999 case GL_PROXY_TEXTURE_2D
:
1000 return ctx
->Const
.MaxTextureLevels
;
1002 case GL_PROXY_TEXTURE_3D
:
1003 return ctx
->Const
.Max3DTextureLevels
;
1004 case GL_TEXTURE_CUBE_MAP
:
1005 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
1006 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
1007 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
1008 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1009 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1010 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1011 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1012 return ctx
->Extensions
.ARB_texture_cube_map
1013 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1014 case GL_TEXTURE_RECTANGLE_NV
:
1015 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1016 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
1017 case GL_TEXTURE_1D_ARRAY_EXT
:
1018 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1019 case GL_TEXTURE_2D_ARRAY_EXT
:
1020 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1021 return ctx
->Extensions
.EXT_texture_array
1022 ? ctx
->Const
.MaxTextureLevels
: 0;
1023 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1024 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1025 return ctx
->Extensions
.ARB_texture_cube_map_array
1026 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1027 case GL_TEXTURE_BUFFER
:
1028 return ctx
->API
== API_OPENGL_CORE
&&
1029 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1030 case GL_TEXTURE_2D_MULTISAMPLE
:
1031 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1032 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1033 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1034 return _mesa_is_desktop_gl(ctx
)
1035 && ctx
->Extensions
.ARB_texture_multisample
1037 case GL_TEXTURE_EXTERNAL_OES
:
1040 return 0; /* bad target */
1046 * Return number of dimensions per mipmap level for the given texture target.
1049 _mesa_get_texture_dimensions(GLenum target
)
1053 case GL_PROXY_TEXTURE_1D
:
1056 case GL_TEXTURE_RECTANGLE
:
1057 case GL_TEXTURE_CUBE_MAP
:
1058 case GL_PROXY_TEXTURE_2D
:
1059 case GL_PROXY_TEXTURE_RECTANGLE
:
1060 case GL_PROXY_TEXTURE_CUBE_MAP
:
1061 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1062 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1063 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1064 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1065 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1066 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1067 case GL_TEXTURE_1D_ARRAY
:
1068 case GL_PROXY_TEXTURE_1D_ARRAY
:
1069 case GL_TEXTURE_EXTERNAL_OES
:
1070 case GL_TEXTURE_2D_MULTISAMPLE
:
1071 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1074 case GL_PROXY_TEXTURE_3D
:
1075 case GL_TEXTURE_2D_ARRAY
:
1076 case GL_PROXY_TEXTURE_2D_ARRAY
:
1077 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1078 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1079 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1080 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1082 case GL_TEXTURE_BUFFER
:
1085 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1093 * Return the maximum number of mipmap levels for the given target
1094 * and the dimensions.
1095 * The dimensions are expected not to include the border.
1098 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1105 case GL_TEXTURE_1D_ARRAY
:
1106 case GL_PROXY_TEXTURE_1D
:
1107 case GL_PROXY_TEXTURE_1D_ARRAY
:
1110 case GL_TEXTURE_CUBE_MAP
:
1111 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1112 case GL_PROXY_TEXTURE_CUBE_MAP
:
1113 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1117 case GL_TEXTURE_2D_ARRAY
:
1118 case GL_PROXY_TEXTURE_2D
:
1119 case GL_PROXY_TEXTURE_2D_ARRAY
:
1120 size
= MAX2(width
, height
);
1123 case GL_PROXY_TEXTURE_3D
:
1124 size
= MAX3(width
, height
, depth
);
1126 case GL_TEXTURE_RECTANGLE
:
1127 case GL_TEXTURE_EXTERNAL_OES
:
1128 case GL_TEXTURE_2D_MULTISAMPLE
:
1129 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1130 case GL_PROXY_TEXTURE_RECTANGLE
:
1131 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1132 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1139 return _mesa_logbase2(size
) + 1;
1143 #if 000 /* not used anymore */
1145 * glTexImage[123]D can accept a NULL image pointer. In this case we
1146 * create a texture image with unspecified image contents per the OpenGL
1150 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1152 const GLint components
= _mesa_components_in_format(format
);
1153 const GLint numPixels
= width
* height
* depth
;
1154 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1158 * Let's see if anyone finds this. If glTexImage2D() is called with
1159 * a NULL image pointer then load the texture image with something
1160 * interesting instead of leaving it indeterminate.
1163 static const char message
[8][32] = {
1164 " X X XXXXX XXX X ",
1165 " XX XX X X X X X ",
1167 " X X XXXX XXX XXXXX ",
1170 " X X XXXXX XXX X X ",
1174 GLubyte
*imgPtr
= data
;
1176 for (h
= 0; h
< depth
; h
++) {
1177 for (i
= 0; i
< height
; i
++) {
1178 GLint srcRow
= 7 - (i
% 8);
1179 for (j
= 0; j
< width
; j
++) {
1180 GLint srcCol
= j
% 32;
1181 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1182 for (k
= 0; k
< components
; k
++) {
1198 * Set the size and format-related fields of a gl_texture_image struct
1199 * to zero. This is used when a proxy texture test fails.
1202 clear_teximage_fields(struct gl_texture_image
*img
)
1205 img
->_BaseFormat
= 0;
1206 img
->InternalFormat
= 0;
1215 img
->HeightLog2
= 0;
1217 img
->TexFormat
= MESA_FORMAT_NONE
;
1218 img
->NumSamples
= 0;
1219 img
->FixedSampleLocations
= GL_TRUE
;
1224 * Initialize basic fields of the gl_texture_image struct.
1226 * \param ctx GL context.
1227 * \param img texture image structure to be initialized.
1228 * \param width image width.
1229 * \param height image height.
1230 * \param depth image depth.
1231 * \param border image border.
1232 * \param internalFormat internal format.
1233 * \param format the actual hardware format (one of MESA_FORMAT_*)
1235 * Fills in the fields of \p img with the given information.
1236 * Note: width, height and depth include the border.
1239 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1240 struct gl_texture_image
*img
,
1241 GLsizei width
, GLsizei height
, GLsizei depth
,
1242 GLint border
, GLenum internalFormat
,
1248 ASSERT(height
>= 0);
1251 target
= img
->TexObject
->Target
;
1252 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1253 ASSERT(img
->_BaseFormat
> 0);
1254 img
->InternalFormat
= internalFormat
;
1255 img
->Border
= border
;
1257 img
->Height
= height
;
1260 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1261 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1263 img
->NumSamples
= 0;
1264 img
->FixedSampleLocations
= GL_TRUE
;
1268 case GL_TEXTURE_BUFFER
:
1269 case GL_PROXY_TEXTURE_1D
:
1274 img
->HeightLog2
= 0;
1281 case GL_TEXTURE_1D_ARRAY
:
1282 case GL_PROXY_TEXTURE_1D_ARRAY
:
1283 img
->Height2
= height
; /* no border */
1284 img
->HeightLog2
= 0; /* not used */
1292 case GL_TEXTURE_RECTANGLE
:
1293 case GL_TEXTURE_CUBE_MAP
:
1294 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1295 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1296 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1297 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1298 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1299 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1300 case GL_TEXTURE_EXTERNAL_OES
:
1301 case GL_PROXY_TEXTURE_2D
:
1302 case GL_PROXY_TEXTURE_RECTANGLE
:
1303 case GL_PROXY_TEXTURE_CUBE_MAP
:
1304 case GL_TEXTURE_2D_MULTISAMPLE
:
1305 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1306 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1307 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1314 case GL_TEXTURE_2D_ARRAY
:
1315 case GL_PROXY_TEXTURE_2D_ARRAY
:
1316 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1317 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1318 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1319 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1320 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1321 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1322 img
->Depth2
= depth
; /* no border */
1323 img
->DepthLog2
= 0; /* not used */
1326 case GL_PROXY_TEXTURE_3D
:
1327 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1328 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1329 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1330 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1333 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1338 _mesa_get_tex_max_num_levels(target
,
1339 img
->Width2
, img
->Height2
, img
->Depth2
);
1340 img
->TexFormat
= format
;
1345 * Free and clear fields of the gl_texture_image struct.
1347 * \param ctx GL context.
1348 * \param texImage texture image structure to be cleared.
1350 * After the call, \p texImage will have no data associated with it. Its
1351 * fields are cleared so that its parent object will test incomplete.
1354 _mesa_clear_texture_image(struct gl_context
*ctx
,
1355 struct gl_texture_image
*texImage
)
1357 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1358 clear_teximage_fields(texImage
);
1363 * Check the width, height, depth and border of a texture image are legal.
1364 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1366 * The target and level parameters will have already been validated.
1367 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1370 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1371 GLint level
, GLint width
, GLint height
,
1372 GLint depth
, GLint border
)
1378 case GL_PROXY_TEXTURE_1D
:
1379 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1380 maxSize
>>= level
; /* level size */
1381 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1383 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1384 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1390 case GL_PROXY_TEXTURE_2D
:
1391 case GL_TEXTURE_2D_MULTISAMPLE
:
1392 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1393 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1395 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1397 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1399 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1400 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1402 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1408 case GL_PROXY_TEXTURE_3D
:
1409 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1411 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1413 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1415 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1417 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1418 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1420 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1422 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1427 case GL_TEXTURE_RECTANGLE_NV
:
1428 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1431 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1432 if (width
< 0 || width
> maxSize
)
1434 if (height
< 0 || height
> maxSize
)
1438 case GL_TEXTURE_CUBE_MAP
:
1439 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1440 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1441 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1442 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1443 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1444 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1445 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1446 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1448 if (width
!= height
)
1450 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1452 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1454 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1455 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1457 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1462 case GL_TEXTURE_1D_ARRAY_EXT
:
1463 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1464 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1466 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1468 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1470 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1471 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1476 case GL_TEXTURE_2D_ARRAY_EXT
:
1477 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1478 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1479 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1480 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1482 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1484 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1486 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1488 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1489 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1491 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1496 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1497 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1498 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1499 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1501 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1503 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1505 if (width
!= height
)
1507 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1509 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1510 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1512 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1517 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1524 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1525 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1526 * \param destImage the destination texture image.
1527 * \return GL_TRUE if error found, GL_FALSE otherwise.
1530 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1531 const char *function
, GLuint dims
,
1532 const struct gl_texture_image
*destImage
,
1533 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1534 GLsizei subWidth
, GLsizei subHeight
,
1537 const GLenum target
= destImage
->TexObject
->Target
;
1542 _mesa_error(ctx
, GL_INVALID_VALUE
,
1543 "%s%dD(width=%d)", function
, dims
, subWidth
);
1547 if (dims
> 1 && subHeight
< 0) {
1548 _mesa_error(ctx
, GL_INVALID_VALUE
,
1549 "%s%dD(height=%d)", function
, dims
, subHeight
);
1553 if (dims
> 2 && subDepth
< 0) {
1554 _mesa_error(ctx
, GL_INVALID_VALUE
,
1555 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1559 /* check xoffset and width */
1560 if (xoffset
< - (GLint
) destImage
->Border
) {
1561 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1566 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1567 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1572 /* check yoffset and height */
1574 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1575 if (yoffset
< -yBorder
) {
1576 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1580 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1581 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1587 /* check zoffset and depth */
1589 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1590 if (zoffset
< -zBorder
) {
1591 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1594 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1595 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1601 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1602 * compressed texture images can be updated. But, that restriction may be
1603 * relaxed for particular compressed formats. At this time, all the
1604 * compressed formats supported by Mesa allow sub-textures to be updated
1605 * along compressed block boundaries.
1607 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1609 if (bw
!= 1 || bh
!= 1) {
1610 /* offset must be multiple of block size */
1611 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1612 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1613 "%s%dD(xoffset = %d, yoffset = %d)",
1614 function
, dims
, xoffset
, yoffset
);
1618 /* The size must be a multiple of bw x bh, or we must be using a
1619 * offset+size that exactly hits the edge of the image. This
1620 * is important for small mipmap levels (1x1, 2x1, etc) and for
1623 if ((subWidth
% bw
!= 0) &&
1624 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1625 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1626 "%s%dD(width = %d)", function
, dims
, subWidth
);
1630 if ((subHeight
% bh
!= 0) &&
1631 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1632 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1633 "%s%dD(height = %d)", function
, dims
, subHeight
);
1645 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1646 * specific texture image size checks.
1648 * A hardware driver might override this function if, for example, the
1649 * max 3D texture size is 512x512x64 (i.e. not a cube).
1651 * Note that width, height, depth == 0 is not an error. However, a
1652 * texture with zero width/height/depth will be considered "incomplete"
1653 * and texturing will effectively be disabled.
1655 * \param target any texture target/type
1656 * \param level as passed to glTexImage
1657 * \param format the MESA_FORMAT_x for the tex image
1658 * \param width as passed to glTexImage
1659 * \param height as passed to glTexImage
1660 * \param depth as passed to glTexImage
1661 * \param border as passed to glTexImage
1662 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1665 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1667 GLint width
, GLint height
, GLint depth
, GLint border
)
1669 /* We just check if the image size is less than MaxTextureMbytes.
1670 * Some drivers may do more specific checks.
1672 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1673 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1674 mbytes
*= _mesa_num_tex_faces(target
);
1675 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1680 * Return true if the format is only valid for glCompressedTexImage.
1683 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1686 case GL_ETC1_RGB8_OES
:
1687 case GL_PALETTE4_RGB8_OES
:
1688 case GL_PALETTE4_RGBA8_OES
:
1689 case GL_PALETTE4_R5_G6_B5_OES
:
1690 case GL_PALETTE4_RGBA4_OES
:
1691 case GL_PALETTE4_RGB5_A1_OES
:
1692 case GL_PALETTE8_RGB8_OES
:
1693 case GL_PALETTE8_RGBA8_OES
:
1694 case GL_PALETTE8_R5_G6_B5_OES
:
1695 case GL_PALETTE8_RGBA4_OES
:
1696 case GL_PALETTE8_RGB5_A1_OES
:
1705 * Helper function to determine whether a target and specific compression
1706 * format are supported.
1709 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1712 (void) intFormat
; /* not used yet */
1716 case GL_PROXY_TEXTURE_2D
:
1717 return GL_TRUE
; /* true for any compressed format so far */
1718 case GL_PROXY_TEXTURE_CUBE_MAP
:
1719 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1720 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1721 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1722 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1723 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1724 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1725 return ctx
->Extensions
.ARB_texture_cube_map
;
1726 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1727 case GL_TEXTURE_2D_ARRAY_EXT
:
1728 return ctx
->Extensions
.EXT_texture_array
;
1729 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1730 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1731 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1739 * Check if the given texture target value is legal for a
1740 * glTexImage1/2/3D call.
1743 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1749 case GL_PROXY_TEXTURE_1D
:
1750 return _mesa_is_desktop_gl(ctx
);
1758 case GL_PROXY_TEXTURE_2D
:
1759 return _mesa_is_desktop_gl(ctx
);
1760 case GL_PROXY_TEXTURE_CUBE_MAP
:
1761 return _mesa_is_desktop_gl(ctx
)
1762 && ctx
->Extensions
.ARB_texture_cube_map
;
1763 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1764 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1765 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1766 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1767 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1768 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1769 return ctx
->Extensions
.ARB_texture_cube_map
;
1770 case GL_TEXTURE_RECTANGLE_NV
:
1771 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1772 return _mesa_is_desktop_gl(ctx
)
1773 && ctx
->Extensions
.NV_texture_rectangle
;
1774 case GL_TEXTURE_1D_ARRAY_EXT
:
1775 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1776 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1784 case GL_PROXY_TEXTURE_3D
:
1785 return _mesa_is_desktop_gl(ctx
);
1786 case GL_TEXTURE_2D_ARRAY_EXT
:
1787 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1788 || _mesa_is_gles3(ctx
);
1789 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1790 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1791 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1792 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1793 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1798 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1805 * Check if the given texture target value is legal for a
1806 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1807 * The difference compared to legal_teximage_target() above is that
1808 * proxy targets are not supported.
1811 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1815 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1820 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1821 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1822 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1823 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1824 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1825 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1826 return ctx
->Extensions
.ARB_texture_cube_map
;
1827 case GL_TEXTURE_RECTANGLE_NV
:
1828 return _mesa_is_desktop_gl(ctx
)
1829 && ctx
->Extensions
.NV_texture_rectangle
;
1830 case GL_TEXTURE_1D_ARRAY_EXT
:
1831 return _mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
;
1839 case GL_TEXTURE_2D_ARRAY_EXT
:
1840 return (_mesa_is_desktop_gl(ctx
) && ctx
->Extensions
.EXT_texture_array
)
1841 || _mesa_is_gles3(ctx
);
1842 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1843 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1844 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1849 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1857 * Helper function to determine if a texture object is mutable (in terms
1858 * of GL_ARB_texture_storage).
1861 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1863 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1864 return !texObj
->Immutable
;
1869 * Return expected size of a compressed texture.
1872 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1875 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1876 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1881 * Test the glTexImage[123]D() parameters for errors.
1883 * \param ctx GL context.
1884 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1885 * \param target texture target given by the user (already validated).
1886 * \param level image level given by the user.
1887 * \param internalFormat internal format given by the user.
1888 * \param format pixel data format given by the user.
1889 * \param type pixel data type given by the user.
1890 * \param width image width given by the user.
1891 * \param height image height given by the user.
1892 * \param depth image depth given by the user.
1893 * \param border image border given by the user.
1895 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1897 * Verifies each of the parameters against the constants specified in
1898 * __struct gl_contextRec::Const and the supported extensions, and according
1899 * to the OpenGL specification.
1900 * Note that we don't fully error-check the width, height, depth values
1901 * here. That's done in _mesa_legal_texture_dimensions() which is used
1902 * by several other GL entrypoints. Plus, texture dims have a special
1903 * interaction with proxy textures.
1906 texture_error_check( struct gl_context
*ctx
,
1907 GLuint dimensions
, GLenum target
,
1908 GLint level
, GLint internalFormat
,
1909 GLenum format
, GLenum type
,
1910 GLint width
, GLint height
,
1911 GLint depth
, GLint border
)
1913 GLboolean colorFormat
;
1916 /* Even though there are no color-index textures, we still have to support
1917 * uploading color-index data and remapping it to RGB via the
1918 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1920 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1922 /* Note: for proxy textures, some error conditions immediately generate
1923 * a GL error in the usual way. But others do not generate a GL error.
1924 * Instead, they cause the width, height, depth, format fields of the
1925 * texture image to be zeroed-out. The GL spec seems to indicate that the
1926 * zero-out behaviour is only used in cases related to memory allocation.
1930 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1931 _mesa_error(ctx
, GL_INVALID_VALUE
,
1932 "glTexImage%dD(level=%d)", dimensions
, level
);
1937 if (border
< 0 || border
> 1 ||
1938 ((ctx
->API
!= API_OPENGL_COMPAT
||
1939 target
== GL_TEXTURE_RECTANGLE_NV
||
1940 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1941 _mesa_error(ctx
, GL_INVALID_VALUE
,
1942 "glTexImage%dD(border=%d)", dimensions
, border
);
1946 if (width
< 0 || height
< 0 || depth
< 0) {
1947 _mesa_error(ctx
, GL_INVALID_VALUE
,
1948 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1952 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1953 * combinations of format, internalFormat, and type that can be used.
1954 * Formats and types that require additional extensions (e.g., GL_FLOAT
1955 * requires GL_OES_texture_float) are filtered elsewhere.
1958 if (_mesa_is_gles(ctx
)) {
1959 if (_mesa_is_gles3(ctx
)) {
1960 err
= _mesa_es3_error_check_format_and_type(format
, type
,
1963 if (format
!= internalFormat
) {
1964 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1965 "glTexImage%dD(format = %s, internalFormat = %s)",
1967 _mesa_lookup_enum_by_nr(format
),
1968 _mesa_lookup_enum_by_nr(internalFormat
));
1972 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1974 if (err
!= GL_NO_ERROR
) {
1975 _mesa_error(ctx
, err
,
1976 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
1978 _mesa_lookup_enum_by_nr(format
),
1979 _mesa_lookup_enum_by_nr(type
),
1980 _mesa_lookup_enum_by_nr(internalFormat
));
1985 /* Check internalFormat */
1986 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1987 _mesa_error(ctx
, GL_INVALID_VALUE
,
1988 "glTexImage%dD(internalFormat=%s)",
1989 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
1993 /* Check incoming image format and type */
1994 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
1995 if (err
!= GL_NO_ERROR
) {
1996 _mesa_error(ctx
, err
,
1997 "glTexImage%dD(incompatible format = %s, type = %s)",
1998 dimensions
, _mesa_lookup_enum_by_nr(format
),
1999 _mesa_lookup_enum_by_nr(type
));
2003 /* make sure internal format and format basically agree */
2004 colorFormat
= _mesa_is_color_format(format
);
2005 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2006 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2007 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2008 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2009 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2010 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2011 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2012 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2013 _mesa_lookup_enum_by_nr(format
));
2017 /* additional checks for ycbcr textures */
2018 if (internalFormat
== GL_YCBCR_MESA
) {
2019 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2020 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2021 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2023 _mesa_snprintf(message
, sizeof(message
),
2024 "glTexImage%dD(format/type YCBCR mismatch)",
2026 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2027 return GL_TRUE
; /* error */
2029 if (target
!= GL_TEXTURE_2D
&&
2030 target
!= GL_PROXY_TEXTURE_2D
&&
2031 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2032 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2033 _mesa_error(ctx
, GL_INVALID_ENUM
,
2034 "glTexImage%dD(bad target for YCbCr texture)",
2040 _mesa_snprintf(message
, sizeof(message
),
2041 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2042 dimensions
, border
);
2043 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2048 /* additional checks for depth textures */
2049 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2050 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2051 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
2052 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
2053 if (target
!= GL_TEXTURE_1D
&&
2054 target
!= GL_PROXY_TEXTURE_1D
&&
2055 target
!= GL_TEXTURE_2D
&&
2056 target
!= GL_PROXY_TEXTURE_2D
&&
2057 target
!= GL_TEXTURE_1D_ARRAY
&&
2058 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2059 target
!= GL_TEXTURE_2D_ARRAY
&&
2060 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2061 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2062 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2063 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2064 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2065 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2066 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2067 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2068 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2069 _mesa_error(ctx
, GL_INVALID_ENUM
,
2070 "glTexImage%dD(bad target for depth texture)",
2076 /* additional checks for compressed textures */
2077 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2078 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2079 _mesa_error(ctx
, GL_INVALID_ENUM
,
2080 "glTexImage%dD(target can't be compressed)", dimensions
);
2083 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2084 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2085 "glTexImage%dD(no compression for format)", dimensions
);
2089 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2090 "glTexImage%dD(border!=0)", dimensions
);
2095 /* additional checks for integer textures */
2096 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2097 (_mesa_is_enum_format_integer(format
) !=
2098 _mesa_is_enum_format_integer(internalFormat
))) {
2099 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2100 "glTexImage%dD(integer/non-integer format mismatch)",
2105 if (!mutable_tex_object(ctx
, target
)) {
2106 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2107 "glTexImage%dD(immutable texture)", dimensions
);
2111 /* if we get here, the parameters are OK */
2117 * Error checking for glCompressedTexImage[123]D().
2118 * Note that the width, height and depth values are not fully error checked
2120 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2123 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2124 GLenum target
, GLint level
,
2125 GLenum internalFormat
, GLsizei width
,
2126 GLsizei height
, GLsizei depth
, GLint border
,
2129 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2131 GLenum error
= GL_NO_ERROR
;
2132 char *reason
= ""; /* no error */
2134 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2136 error
= GL_INVALID_ENUM
;
2140 /* This will detect any invalid internalFormat value */
2141 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2142 reason
= "internalFormat";
2143 error
= GL_INVALID_ENUM
;
2147 switch (internalFormat
) {
2148 case GL_PALETTE4_RGB8_OES
:
2149 case GL_PALETTE4_RGBA8_OES
:
2150 case GL_PALETTE4_R5_G6_B5_OES
:
2151 case GL_PALETTE4_RGBA4_OES
:
2152 case GL_PALETTE4_RGB5_A1_OES
:
2153 case GL_PALETTE8_RGB8_OES
:
2154 case GL_PALETTE8_RGBA8_OES
:
2155 case GL_PALETTE8_R5_G6_B5_OES
:
2156 case GL_PALETTE8_RGBA4_OES
:
2157 case GL_PALETTE8_RGB5_A1_OES
:
2158 /* check level (note that level should be zero or less!) */
2159 if (level
> 0 || level
< -maxLevels
) {
2161 error
= GL_INVALID_VALUE
;
2165 if (dimensions
!= 2) {
2166 reason
= "compressed paletted textures must be 2D";
2167 error
= GL_INVALID_OPERATION
;
2171 /* Figure out the expected texture size (in bytes). This will be
2172 * checked against the actual size later.
2174 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2177 /* This is for the benefit of the TestProxyTexImage below. It expects
2178 * level to be non-negative. OES_compressed_paletted_texture uses a
2179 * weird mechanism where the level specified to glCompressedTexImage2D
2180 * is -(n-1) number of levels in the texture, and the data specifies the
2181 * complete mipmap stack. This is done to ensure the palette is the
2182 * same for all levels.
2189 if (level
< 0 || level
>= maxLevels
) {
2191 error
= GL_INVALID_VALUE
;
2195 /* Figure out the expected texture size (in bytes). This will be
2196 * checked against the actual size later.
2198 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2202 /* This should really never fail */
2203 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2204 reason
= "internalFormat";
2205 error
= GL_INVALID_ENUM
;
2209 /* No compressed formats support borders at this time */
2211 reason
= "border != 0";
2212 error
= GL_INVALID_VALUE
;
2216 /* check image size in bytes */
2217 if (expectedSize
!= imageSize
) {
2218 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2219 * if <imageSize> is not consistent with the format, dimensions, and
2220 * contents of the specified image.
2222 reason
= "imageSize inconsistant with width/height/format";
2223 error
= GL_INVALID_VALUE
;
2227 if (!mutable_tex_object(ctx
, target
)) {
2228 reason
= "immutable texture";
2229 error
= GL_INVALID_OPERATION
;
2236 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2243 * Test glTexSubImage[123]D() parameters for errors.
2245 * \param ctx GL context.
2246 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2247 * \param target texture target given by the user (already validated)
2248 * \param level image level given by the user.
2249 * \param xoffset sub-image x offset given by the user.
2250 * \param yoffset sub-image y offset given by the user.
2251 * \param zoffset sub-image z offset given by the user.
2252 * \param format pixel data format given by the user.
2253 * \param type pixel data type given by the user.
2254 * \param width image width given by the user.
2255 * \param height image height given by the user.
2256 * \param depth image depth given by the user.
2258 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2260 * Verifies each of the parameters against the constants specified in
2261 * __struct gl_contextRec::Const and the supported extensions, and according
2262 * to the OpenGL specification.
2265 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2266 GLenum target
, GLint level
,
2267 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2268 GLint width
, GLint height
, GLint depth
,
2269 GLenum format
, GLenum type
)
2271 struct gl_texture_object
*texObj
;
2272 struct gl_texture_image
*texImage
;
2275 /* check target (proxies not allowed) */
2276 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2277 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2278 dimensions
, _mesa_lookup_enum_by_nr(target
));
2283 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2284 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2289 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2290 * combinations of format and type that can be used. Formats and types
2291 * that require additional extensions (e.g., GL_FLOAT requires
2292 * GL_OES_texture_float) are filtered elsewhere.
2294 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2295 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2296 if (err
!= GL_NO_ERROR
) {
2297 _mesa_error(ctx
, err
,
2298 "glTexSubImage%dD(format = %s, type = %s)",
2300 _mesa_lookup_enum_by_nr(format
),
2301 _mesa_lookup_enum_by_nr(type
));
2306 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2307 if (err
!= GL_NO_ERROR
) {
2308 _mesa_error(ctx
, err
,
2309 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2310 dimensions
, _mesa_lookup_enum_by_nr(format
),
2311 _mesa_lookup_enum_by_nr(type
));
2315 /* Get dest texture object / image pointers */
2316 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2318 /* must be out of memory */
2319 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2323 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2325 /* non-existant texture level */
2326 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2327 "glTexSubImage%dD(invalid texture image)", dimensions
);
2331 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2332 texImage
, xoffset
, yoffset
, 0,
2333 width
, height
, 1)) {
2337 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2338 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2339 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2340 "glTexSubImage%dD(no compression for format)", dimensions
);
2345 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2346 /* both source and dest must be integer-valued, or neither */
2347 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2348 _mesa_is_enum_format_integer(format
)) {
2349 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2350 "glTexSubImage%dD(integer/non-integer format mismatch)",
2361 * Test glCopyTexImage[12]D() parameters for errors.
2363 * \param ctx GL context.
2364 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2365 * \param target texture target given by the user.
2366 * \param level image level given by the user.
2367 * \param internalFormat internal format given by the user.
2368 * \param width image width given by the user.
2369 * \param height image height given by the user.
2370 * \param border texture border.
2372 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2374 * Verifies each of the parameters against the constants specified in
2375 * __struct gl_contextRec::Const and the supported extensions, and according
2376 * to the OpenGL specification.
2379 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2380 GLenum target
, GLint level
, GLint internalFormat
,
2381 GLint width
, GLint height
, GLint border
)
2384 GLint rb_base_format
;
2385 struct gl_renderbuffer
*rb
;
2386 GLenum rb_internal_format
;
2389 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2390 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2391 dimensions
, _mesa_lookup_enum_by_nr(target
));
2396 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2397 _mesa_error(ctx
, GL_INVALID_VALUE
,
2398 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2402 /* Check that the source buffer is complete */
2403 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2404 if (ctx
->ReadBuffer
->_Status
== 0) {
2405 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2407 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2408 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2409 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2413 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2414 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2415 "glCopyTexImage%dD(multisample FBO)",
2422 if (border
< 0 || border
> 1 ||
2423 ((ctx
->API
!= API_OPENGL_COMPAT
||
2424 target
== GL_TEXTURE_RECTANGLE_NV
||
2425 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2426 _mesa_error(ctx
, GL_INVALID_VALUE
,
2427 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2431 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2433 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2434 "glCopyTexImage%dD(read buffer)", dimensions
);
2438 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2441 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2442 switch (internalFormat
) {
2447 case GL_LUMINANCE_ALPHA
:
2450 _mesa_error(ctx
, GL_INVALID_VALUE
,
2451 "glCopyTexImage%dD(internalFormat)", dimensions
);
2456 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2457 if (baseFormat
< 0) {
2458 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2459 "glCopyTexImage%dD(internalFormat)", dimensions
);
2463 rb_internal_format
= rb
->InternalFormat
;
2464 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2465 if (_mesa_is_color_format(internalFormat
)) {
2466 if (rb_base_format
< 0) {
2467 _mesa_error(ctx
, GL_INVALID_VALUE
,
2468 "glCopyTexImage%dD(internalFormat)", dimensions
);
2473 if (_mesa_is_gles(ctx
)) {
2475 if (_mesa_base_format_component_count(baseFormat
) >
2476 _mesa_base_format_component_count(rb_base_format
)) {
2479 if (baseFormat
== GL_DEPTH_COMPONENT
||
2480 baseFormat
== GL_DEPTH_STENCIL
||
2481 rb_base_format
== GL_DEPTH_COMPONENT
||
2482 rb_base_format
== GL_DEPTH_STENCIL
||
2483 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2484 baseFormat
== GL_ALPHA
) &&
2485 rb_base_format
!= GL_RGBA
) ||
2486 internalFormat
== GL_RGB9_E5
) {
2489 if (internalFormat
== GL_RGB9_E5
) {
2493 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2494 "glCopyTexImage%dD(internalFormat)", dimensions
);
2499 if (_mesa_is_gles3(ctx
)) {
2500 bool rb_is_srgb
= false;
2501 bool dst_is_srgb
= false;
2503 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2504 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2508 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2512 if (rb_is_srgb
!= dst_is_srgb
) {
2513 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2514 * OpenGLES 3.0.0 spec says:
2516 * "The error INVALID_OPERATION is also generated if the
2517 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2518 * framebuffer attachment corresponding to the read buffer
2519 * is LINEAR (see section 6.1.13) and internalformat is
2520 * one of the sRGB formats described in section 3.8.16, or
2521 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2522 * SRGB and internalformat is not one of the sRGB formats."
2524 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2525 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2530 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2531 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2532 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2536 /* From the EXT_texture_integer spec:
2538 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2539 * if the texture internalformat is an integer format and the read color
2540 * buffer is not an integer format, or if the internalformat is not an
2541 * integer format and the read color buffer is an integer format."
2543 if (_mesa_is_color_format(internalFormat
)) {
2544 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2545 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2546 if (is_int
|| is_rbint
) {
2547 if (is_int
!= is_rbint
) {
2548 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2549 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2551 } else if (_mesa_is_gles(ctx
) &&
2552 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2553 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2554 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2555 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2561 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2562 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2563 _mesa_error(ctx
, GL_INVALID_ENUM
,
2564 "glCopyTexImage%dD(target)", dimensions
);
2567 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2568 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2569 "glCopyTexImage%dD(no compression for format)", dimensions
);
2573 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2574 "glCopyTexImage%dD(border!=0)", dimensions
);
2579 if (!mutable_tex_object(ctx
, target
)) {
2580 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2581 "glCopyTexImage%dD(immutable texture)", dimensions
);
2585 /* if we get here, the parameters are OK */
2591 * Test glCopyTexSubImage[12]D() parameters for errors.
2592 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2595 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2596 GLenum target
, GLint level
,
2597 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2598 GLint width
, GLint height
)
2600 struct gl_texture_object
*texObj
;
2601 struct gl_texture_image
*texImage
;
2603 /* Check that the source buffer is complete */
2604 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2605 if (ctx
->ReadBuffer
->_Status
== 0) {
2606 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2608 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2609 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2610 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2614 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2615 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2616 "glCopyTexSubImage%dD(multisample FBO)",
2622 /* check target (proxies not allowed) */
2623 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2624 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2625 dimensions
, _mesa_lookup_enum_by_nr(target
));
2630 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2631 _mesa_error(ctx
, GL_INVALID_VALUE
,
2632 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2636 /* Get dest texture object / image pointers */
2637 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2639 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2643 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2645 /* destination image does not exist */
2646 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2647 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2651 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2652 dimensions
, texImage
,
2653 xoffset
, yoffset
, zoffset
,
2654 width
, height
, 1)) {
2658 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2659 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2660 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2661 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2666 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2667 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2671 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2672 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2673 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2674 dimensions
, texImage
->_BaseFormat
);
2678 /* From the EXT_texture_integer spec:
2680 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2681 * if the texture internalformat is an integer format and the read color
2682 * buffer is not an integer format, or if the internalformat is not an
2683 * integer format and the read color buffer is an integer format."
2685 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2686 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2688 if (_mesa_is_format_integer_color(rb
->Format
) !=
2689 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2690 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2691 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2696 /* if we get here, the parameters are OK */
2701 /** Callback info for walking over FBO hash table */
2704 struct gl_context
*ctx
;
2705 struct gl_texture_object
*texObj
;
2711 * Check render to texture callback. Called from _mesa_HashWalk().
2714 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2716 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2717 const struct cb_info
*info
= (struct cb_info
*) userData
;
2718 struct gl_context
*ctx
= info
->ctx
;
2719 const struct gl_texture_object
*texObj
= info
->texObj
;
2720 const GLuint level
= info
->level
, face
= info
->face
;
2722 /* If this is a user-created FBO */
2723 if (_mesa_is_user_fbo(fb
)) {
2725 /* check if any of the FBO's attachments point to 'texObj' */
2726 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2727 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2728 if (att
->Type
== GL_TEXTURE
&&
2729 att
->Texture
== texObj
&&
2730 att
->TextureLevel
== level
&&
2731 att
->CubeMapFace
== face
) {
2732 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2733 ASSERT(att
->Renderbuffer
->TexImage
);
2734 /* Mark fb status as indeterminate to force re-validation */
2743 * When a texture image is specified we have to check if it's bound to
2744 * any framebuffer objects (render to texture) in order to detect changes
2745 * in size or format since that effects FBO completeness.
2746 * Any FBOs rendering into the texture must be re-validated.
2749 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2750 struct gl_texture_object
*texObj
,
2751 GLuint face
, GLuint level
)
2753 /* Only check this texture if it's been marked as RenderToTexture */
2754 if (texObj
->_RenderToTexture
) {
2755 struct cb_info info
;
2757 info
.texObj
= texObj
;
2760 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2766 * If the texture object's GenerateMipmap flag is set and we've
2767 * changed the texture base level image, regenerate the rest of the
2768 * mipmap levels now.
2771 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2772 struct gl_texture_object
*texObj
, GLint level
)
2774 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2775 if (texObj
->GenerateMipmap
&&
2776 level
== texObj
->BaseLevel
&&
2777 level
< texObj
->MaxLevel
) {
2778 ASSERT(ctx
->Driver
.GenerateMipmap
);
2779 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2784 /** Debug helper: override the user-requested internal format */
2786 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2789 if (internalFormat
== GL_RGBA16F_ARB
||
2790 internalFormat
== GL_RGBA32F_ARB
) {
2791 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2794 else if (internalFormat
== GL_RGB16F_ARB
||
2795 internalFormat
== GL_RGB32F_ARB
) {
2796 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2799 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2800 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2801 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2802 return GL_LUMINANCE_ALPHA
;
2804 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2805 internalFormat
== GL_LUMINANCE32F_ARB
) {
2806 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2807 return GL_LUMINANCE
;
2809 else if (internalFormat
== GL_ALPHA16F_ARB
||
2810 internalFormat
== GL_ALPHA32F_ARB
) {
2811 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2815 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2816 internalFormat = GL_RGBA;
2820 return internalFormat
;
2823 return internalFormat
;
2829 * Choose the actual hardware format for a texture image.
2830 * Try to use the same format as the previous image level when possible.
2831 * Otherwise, ask the driver for the best format.
2832 * It's important to try to choose a consistant format for all levels
2833 * for efficient texture memory layout/allocation. In particular, this
2834 * comes up during automatic mipmap generation.
2837 _mesa_choose_texture_format(struct gl_context
*ctx
,
2838 struct gl_texture_object
*texObj
,
2839 GLenum target
, GLint level
,
2840 GLenum internalFormat
, GLenum format
, GLenum type
)
2844 /* see if we've already chosen a format for the previous level */
2846 struct gl_texture_image
*prevImage
=
2847 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2848 /* See if the prev level is defined and has an internal format which
2849 * matches the new internal format.
2852 prevImage
->Width
> 0 &&
2853 prevImage
->InternalFormat
== internalFormat
) {
2854 /* use the same format */
2855 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2856 return prevImage
->TexFormat
;
2860 /* If the application requested compression to an S3TC format but we don't
2861 * have the DXTn library, force a generic compressed format instead.
2863 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2864 const GLenum before
= internalFormat
;
2866 switch (internalFormat
) {
2867 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2868 if (!ctx
->Mesa_DXTn
)
2869 internalFormat
= GL_COMPRESSED_RGB
;
2871 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2872 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2873 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2874 if (!ctx
->Mesa_DXTn
)
2875 internalFormat
= GL_COMPRESSED_RGBA
;
2881 if (before
!= internalFormat
) {
2883 "DXT compression requested (%s), "
2884 "but libtxc_dxtn library not installed. Using %s "
2886 _mesa_lookup_enum_by_nr(before
),
2887 _mesa_lookup_enum_by_nr(internalFormat
));
2891 /* choose format from scratch */
2892 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2894 ASSERT(f
!= MESA_FORMAT_NONE
);
2900 * Adjust pixel unpack params and image dimensions to strip off the
2901 * one-pixel texture border.
2903 * Gallium and intel don't support texture borders. They've seldem been used
2904 * and seldom been implemented correctly anyway.
2906 * \param unpackNew returns the new pixel unpack parameters
2909 strip_texture_border(GLenum target
,
2910 GLint
*width
, GLint
*height
, GLint
*depth
,
2911 const struct gl_pixelstore_attrib
*unpack
,
2912 struct gl_pixelstore_attrib
*unpackNew
)
2918 *unpackNew
= *unpack
;
2920 if (unpackNew
->RowLength
== 0)
2921 unpackNew
->RowLength
= *width
;
2923 if (unpackNew
->ImageHeight
== 0)
2924 unpackNew
->ImageHeight
= *height
;
2926 assert(*width
>= 3);
2927 unpackNew
->SkipPixels
++; /* skip the border */
2928 *width
= *width
- 2; /* reduce the width by two border pixels */
2930 /* The min height of a texture with a border is 3 */
2931 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2932 unpackNew
->SkipRows
++; /* skip the border */
2933 *height
= *height
- 2; /* reduce the height by two border pixels */
2937 target
!= GL_TEXTURE_2D_ARRAY
&&
2938 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2939 unpackNew
->SkipImages
++; /* skip the border */
2940 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2946 * Common code to implement all the glTexImage1D/2D/3D functions
2947 * as well as glCompressedTexImage1D/2D/3D.
2948 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2949 * \param format the user's image format (only used if !compressed)
2950 * \param type the user's image type (only used if !compressed)
2951 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2954 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2955 GLenum target
, GLint level
, GLint internalFormat
,
2956 GLsizei width
, GLsizei height
, GLsizei depth
,
2957 GLint border
, GLenum format
, GLenum type
,
2958 GLsizei imageSize
, const GLvoid
*pixels
)
2960 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2961 struct gl_pixelstore_attrib unpack_no_border
;
2962 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2963 struct gl_texture_object
*texObj
;
2964 gl_format texFormat
;
2965 GLboolean dimensionsOK
, sizeOK
;
2967 FLUSH_VERTICES(ctx
, 0);
2969 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2972 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2974 _mesa_lookup_enum_by_nr(target
), level
,
2975 _mesa_lookup_enum_by_nr(internalFormat
),
2976 width
, height
, depth
, border
, pixels
);
2979 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2981 _mesa_lookup_enum_by_nr(target
), level
,
2982 _mesa_lookup_enum_by_nr(internalFormat
),
2983 width
, height
, depth
, border
,
2984 _mesa_lookup_enum_by_nr(format
),
2985 _mesa_lookup_enum_by_nr(type
), pixels
);
2988 internalFormat
= override_internal_format(internalFormat
, width
, height
);
2990 /* target error checking */
2991 if (!legal_teximage_target(ctx
, dims
, target
)) {
2992 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
2993 func
, dims
, _mesa_lookup_enum_by_nr(target
));
2997 /* general error checking */
2999 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3001 width
, height
, depth
,
3006 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3007 format
, type
, width
, height
, depth
, border
))
3011 /* Here we convert a cpal compressed image into a regular glTexImage2D
3012 * call by decompressing the texture. If we really want to support cpal
3013 * textures in any driver this would have to be changed.
3015 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3016 switch (internalFormat
) {
3017 case GL_PALETTE4_RGB8_OES
:
3018 case GL_PALETTE4_RGBA8_OES
:
3019 case GL_PALETTE4_R5_G6_B5_OES
:
3020 case GL_PALETTE4_RGBA4_OES
:
3021 case GL_PALETTE4_RGB5_A1_OES
:
3022 case GL_PALETTE8_RGB8_OES
:
3023 case GL_PALETTE8_RGBA8_OES
:
3024 case GL_PALETTE8_R5_G6_B5_OES
:
3025 case GL_PALETTE8_RGBA4_OES
:
3026 case GL_PALETTE8_RGB5_A1_OES
:
3027 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3028 width
, height
, imageSize
, pixels
);
3033 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3037 /* For glCompressedTexImage() the driver has no choice about the
3038 * texture format since we'll never transcode the user's compressed
3039 * image data. The internalFormat was error checked earlier.
3041 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3044 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3045 internalFormat
, format
, type
);
3048 assert(texFormat
!= MESA_FORMAT_NONE
);
3050 /* check that width, height, depth are legal for the mipmap level */
3051 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3052 height
, depth
, border
);
3054 /* check that the texture won't take too much memory, etc */
3055 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3057 width
, height
, depth
, border
);
3059 if (_mesa_is_proxy_texture(target
)) {
3060 /* Proxy texture: just clear or set state depending on error checking */
3061 struct gl_texture_image
*texImage
=
3062 get_proxy_tex_image(ctx
, target
, level
);
3065 return; /* GL_OUT_OF_MEMORY already recorded */
3067 if (dimensionsOK
&& sizeOK
) {
3068 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3069 border
, internalFormat
, texFormat
);
3072 clear_teximage_fields(texImage
);
3076 /* non-proxy target */
3077 const GLuint face
= _mesa_tex_target_to_face(target
);
3078 struct gl_texture_image
*texImage
;
3080 if (!dimensionsOK
) {
3081 _mesa_error(ctx
, GL_INVALID_VALUE
,
3082 "glTexImage%uD(invalid width or height or depth)",
3088 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3089 "glTexImage%uD(image too large)", dims
);
3093 /* Allow a hardware driver to just strip out the border, to provide
3094 * reliable but slightly incorrect hardware rendering instead of
3095 * rarely-tested software fallback rendering.
3097 if (border
&& ctx
->Const
.StripTextureBorder
) {
3098 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3101 unpack
= &unpack_no_border
;
3104 if (ctx
->NewState
& _NEW_PIXEL
)
3105 _mesa_update_state(ctx
);
3107 _mesa_lock_texture(ctx
, texObj
);
3109 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3112 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3115 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3117 _mesa_init_teximage_fields(ctx
, texImage
,
3118 width
, height
, depth
,
3119 border
, internalFormat
, texFormat
);
3121 /* Give the texture to the driver. <pixels> may be null. */
3122 if (width
> 0 && height
> 0 && depth
> 0) {
3124 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3128 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3129 type
, pixels
, unpack
);
3133 check_gen_mipmap(ctx
, target
, texObj
, level
);
3135 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3137 _mesa_dirty_texobj(ctx
, texObj
);
3140 _mesa_unlock_texture(ctx
, texObj
);
3147 * Called from the API. Note that width includes the border.
3150 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3151 GLsizei width
, GLint border
, GLenum format
,
3152 GLenum type
, const GLvoid
*pixels
)
3154 GET_CURRENT_CONTEXT(ctx
);
3155 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3156 border
, format
, type
, 0, pixels
);
3161 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3162 GLsizei width
, GLsizei height
, GLint border
,
3163 GLenum format
, GLenum type
,
3164 const GLvoid
*pixels
)
3166 GET_CURRENT_CONTEXT(ctx
);
3167 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3168 border
, format
, type
, 0, pixels
);
3173 * Called by the API or display list executor.
3174 * Note that width and height include the border.
3177 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3178 GLsizei width
, GLsizei height
, GLsizei depth
,
3179 GLint border
, GLenum format
, GLenum type
,
3180 const GLvoid
*pixels
)
3182 GET_CURRENT_CONTEXT(ctx
);
3183 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3184 width
, height
, depth
,
3185 border
, format
, type
, 0, pixels
);
3190 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3191 GLsizei width
, GLsizei height
, GLsizei depth
,
3192 GLint border
, GLenum format
, GLenum type
,
3193 const GLvoid
*pixels
)
3195 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3196 depth
, border
, format
, type
, pixels
);
3201 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3203 struct gl_texture_object
*texObj
;
3204 struct gl_texture_image
*texImage
;
3206 GET_CURRENT_CONTEXT(ctx
);
3207 FLUSH_VERTICES(ctx
, 0);
3211 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3213 case GL_TEXTURE_EXTERNAL_OES
:
3215 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3218 valid_target
= false;
3222 if (!valid_target
) {
3223 _mesa_error(ctx
, GL_INVALID_ENUM
,
3224 "glEGLImageTargetTexture2D(target=%d)", target
);
3229 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3230 "glEGLImageTargetTexture2D(image=%p)", image
);
3234 if (ctx
->NewState
& _NEW_PIXEL
)
3235 _mesa_update_state(ctx
);
3237 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3238 _mesa_lock_texture(ctx
, texObj
);
3240 if (texObj
->Immutable
) {
3241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3242 "glEGLImageTargetTexture2D(texture is immutable)");
3243 _mesa_unlock_texture(ctx
, texObj
);
3247 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3249 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3251 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3253 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3254 texObj
, texImage
, image
);
3256 _mesa_dirty_texobj(ctx
, texObj
);
3258 _mesa_unlock_texture(ctx
, texObj
);
3265 * Implement all the glTexSubImage1/2/3D() functions.
3268 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3269 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3270 GLsizei width
, GLsizei height
, GLsizei depth
,
3271 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3273 struct gl_texture_object
*texObj
;
3274 struct gl_texture_image
*texImage
;
3276 FLUSH_VERTICES(ctx
, 0);
3278 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3279 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3281 _mesa_lookup_enum_by_nr(target
), level
,
3282 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3283 _mesa_lookup_enum_by_nr(format
),
3284 _mesa_lookup_enum_by_nr(type
), pixels
);
3286 /* check target (proxies not allowed) */
3287 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3288 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3289 dims
, _mesa_lookup_enum_by_nr(target
));
3293 if (ctx
->NewState
& _NEW_PIXEL
)
3294 _mesa_update_state(ctx
);
3296 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3297 xoffset
, yoffset
, zoffset
,
3298 width
, height
, depth
, format
, type
)) {
3299 return; /* error was detected */
3302 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3304 _mesa_lock_texture(ctx
, texObj
);
3306 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3308 if (width
> 0 && height
> 0 && depth
> 0) {
3309 /* If we have a border, offset=-1 is legal. Bias by border width. */
3312 if (target
!= GL_TEXTURE_2D_ARRAY
)
3313 zoffset
+= texImage
->Border
;
3316 if (target
!= GL_TEXTURE_1D_ARRAY
)
3317 yoffset
+= texImage
->Border
;
3320 xoffset
+= texImage
->Border
;
3323 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3324 xoffset
, yoffset
, zoffset
,
3325 width
, height
, depth
,
3326 format
, type
, pixels
, &ctx
->Unpack
);
3328 check_gen_mipmap(ctx
, target
, texObj
, level
);
3330 ctx
->NewState
|= _NEW_TEXTURE
;
3333 _mesa_unlock_texture(ctx
, texObj
);
3338 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3339 GLint xoffset
, GLsizei width
,
3340 GLenum format
, GLenum type
,
3341 const GLvoid
*pixels
)
3343 GET_CURRENT_CONTEXT(ctx
);
3344 texsubimage(ctx
, 1, target
, level
,
3347 format
, type
, pixels
);
3352 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3353 GLint xoffset
, GLint yoffset
,
3354 GLsizei width
, GLsizei height
,
3355 GLenum format
, GLenum type
,
3356 const GLvoid
*pixels
)
3358 GET_CURRENT_CONTEXT(ctx
);
3359 texsubimage(ctx
, 2, target
, level
,
3360 xoffset
, yoffset
, 0,
3362 format
, type
, pixels
);
3368 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3369 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3370 GLsizei width
, GLsizei height
, GLsizei depth
,
3371 GLenum format
, GLenum type
,
3372 const GLvoid
*pixels
)
3374 GET_CURRENT_CONTEXT(ctx
);
3375 texsubimage(ctx
, 3, target
, level
,
3376 xoffset
, yoffset
, zoffset
,
3377 width
, height
, depth
,
3378 format
, type
, pixels
);
3384 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3385 * from. This depends on whether the texture contains color or depth values.
3387 static struct gl_renderbuffer
*
3388 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3390 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3391 /* reading from depth/stencil buffer */
3392 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3395 /* copying from color buffer */
3396 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3401 copytexsubimage_by_slice(struct gl_context
*ctx
,
3402 struct gl_texture_image
*texImage
,
3404 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3405 struct gl_renderbuffer
*rb
,
3407 GLsizei width
, GLsizei height
)
3409 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3412 /* For 1D arrays, we copy each scanline of the source rectangle into the
3415 assert(zoffset
== 0);
3417 for (slice
= 0; slice
< height
; slice
++) {
3418 assert(yoffset
+ slice
< texImage
->Height
);
3419 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3420 xoffset
, 0, yoffset
+ slice
,
3421 rb
, x
, y
+ slice
, width
, 1);
3424 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3425 xoffset
, yoffset
, zoffset
,
3426 rb
, x
, y
, width
, height
);
3432 * Implement the glCopyTexImage1/2D() functions.
3435 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3436 GLenum target
, GLint level
, GLenum internalFormat
,
3437 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3439 struct gl_texture_object
*texObj
;
3440 struct gl_texture_image
*texImage
;
3441 const GLuint face
= _mesa_tex_target_to_face(target
);
3442 gl_format texFormat
;
3444 FLUSH_VERTICES(ctx
, 0);
3446 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3447 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3449 _mesa_lookup_enum_by_nr(target
), level
,
3450 _mesa_lookup_enum_by_nr(internalFormat
),
3451 x
, y
, width
, height
, border
);
3453 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3454 _mesa_update_state(ctx
);
3456 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3457 width
, height
, border
))
3460 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3462 _mesa_error(ctx
, GL_INVALID_VALUE
,
3463 "glCopyTexImage%uD(invalid width or height)", dims
);
3467 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3470 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3471 internalFormat
, GL_NONE
, GL_NONE
);
3472 assert(texFormat
!= MESA_FORMAT_NONE
);
3474 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3476 width
, height
, 1, border
)) {
3477 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3478 "glCopyTexImage%uD(image too large)", dims
);
3482 if (border
&& ctx
->Const
.StripTextureBorder
) {
3484 width
-= border
* 2;
3487 height
-= border
* 2;
3492 _mesa_lock_texture(ctx
, texObj
);
3494 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3497 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3500 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3502 /* Free old texture image */
3503 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3505 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3506 border
, internalFormat
, texFormat
);
3508 if (width
&& height
) {
3509 /* Allocate texture memory (no pixel data yet) */
3510 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3512 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3514 struct gl_renderbuffer
*srcRb
=
3515 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3517 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3519 srcRb
, srcX
, srcY
, width
, height
);
3522 check_gen_mipmap(ctx
, target
, texObj
, level
);
3525 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3527 _mesa_dirty_texobj(ctx
, texObj
);
3530 _mesa_unlock_texture(ctx
, texObj
);
3536 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3537 GLenum internalFormat
,
3539 GLsizei width
, GLint border
)
3541 GET_CURRENT_CONTEXT(ctx
);
3542 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3548 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3549 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3552 GET_CURRENT_CONTEXT(ctx
);
3553 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3554 x
, y
, width
, height
, border
);
3560 * Implementation for glCopyTexSubImage1/2/3D() functions.
3563 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3564 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3565 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3567 struct gl_texture_object
*texObj
;
3568 struct gl_texture_image
*texImage
;
3570 FLUSH_VERTICES(ctx
, 0);
3572 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3573 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3575 _mesa_lookup_enum_by_nr(target
),
3576 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3578 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3579 _mesa_update_state(ctx
);
3581 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3582 xoffset
, yoffset
, zoffset
, width
, height
)) {
3586 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3588 _mesa_lock_texture(ctx
, texObj
);
3590 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3592 /* If we have a border, offset=-1 is legal. Bias by border width. */
3595 if (target
!= GL_TEXTURE_2D_ARRAY
)
3596 zoffset
+= texImage
->Border
;
3599 if (target
!= GL_TEXTURE_1D_ARRAY
)
3600 yoffset
+= texImage
->Border
;
3603 xoffset
+= texImage
->Border
;
3606 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3608 struct gl_renderbuffer
*srcRb
=
3609 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3611 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3612 xoffset
, yoffset
, zoffset
,
3613 srcRb
, x
, y
, width
, height
);
3615 check_gen_mipmap(ctx
, target
, texObj
, level
);
3617 ctx
->NewState
|= _NEW_TEXTURE
;
3620 _mesa_unlock_texture(ctx
, texObj
);
3625 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3626 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3628 GET_CURRENT_CONTEXT(ctx
);
3629 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3635 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3636 GLint xoffset
, GLint yoffset
,
3637 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3639 GET_CURRENT_CONTEXT(ctx
);
3640 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3647 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3648 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3649 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3651 GET_CURRENT_CONTEXT(ctx
);
3652 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3653 x
, y
, width
, height
);
3659 /**********************************************************************/
3660 /****** Compressed Textures ******/
3661 /**********************************************************************/
3665 * Error checking for glCompressedTexSubImage[123]D().
3666 * \return error code or GL_NO_ERROR.
3669 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3670 GLenum target
, GLint level
,
3671 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3672 GLsizei width
, GLsizei height
, GLsizei depth
,
3673 GLenum format
, GLsizei imageSize
)
3675 struct gl_texture_object
*texObj
;
3676 struct gl_texture_image
*texImage
;
3684 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3685 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3686 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3687 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3688 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3689 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3693 targetOK
= GL_FALSE
;
3698 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3702 /* no 1D compressed textures at this time */
3703 targetOK
= GL_FALSE
;
3708 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3713 /* this will catch any invalid compressed format token */
3714 if (!_mesa_is_compressed_format(ctx
, format
)) {
3715 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3720 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3721 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3726 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3727 if (expectedSize
!= imageSize
) {
3728 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3733 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3735 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3736 "glCompressedTexSubImage%uD()", dims
);
3740 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3742 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3743 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3747 if ((GLint
) format
!= texImage
->InternalFormat
) {
3748 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3749 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3753 if (compressedteximage_only_format(ctx
, format
)) {
3754 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3755 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3760 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3761 texImage
, xoffset
, yoffset
, zoffset
,
3762 width
, height
, depth
)) {
3771 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3772 GLenum internalFormat
, GLsizei width
,
3773 GLint border
, GLsizei imageSize
,
3776 GET_CURRENT_CONTEXT(ctx
);
3777 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3778 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3783 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3784 GLenum internalFormat
, GLsizei width
,
3785 GLsizei height
, GLint border
, GLsizei imageSize
,
3788 GET_CURRENT_CONTEXT(ctx
);
3789 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3790 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3795 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3796 GLenum internalFormat
, GLsizei width
,
3797 GLsizei height
, GLsizei depth
, GLint border
,
3798 GLsizei imageSize
, const GLvoid
*data
)
3800 GET_CURRENT_CONTEXT(ctx
);
3801 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3802 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3807 * Common helper for glCompressedTexSubImage1/2/3D().
3810 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3811 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3812 GLsizei width
, GLsizei height
, GLsizei depth
,
3813 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3815 struct gl_texture_object
*texObj
;
3816 struct gl_texture_image
*texImage
;
3817 GET_CURRENT_CONTEXT(ctx
);
3818 FLUSH_VERTICES(ctx
, 0);
3820 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3821 xoffset
, yoffset
, zoffset
,
3822 width
, height
, depth
,
3823 format
, imageSize
)) {
3827 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3829 _mesa_lock_texture(ctx
, texObj
);
3831 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3834 if (width
> 0 && height
> 0 && depth
> 0) {
3835 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3836 xoffset
, yoffset
, zoffset
,
3837 width
, height
, depth
,
3838 format
, imageSize
, data
);
3840 check_gen_mipmap(ctx
, target
, texObj
, level
);
3842 ctx
->NewState
|= _NEW_TEXTURE
;
3845 _mesa_unlock_texture(ctx
, texObj
);
3850 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3851 GLsizei width
, GLenum format
,
3852 GLsizei imageSize
, const GLvoid
*data
)
3854 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3855 format
, imageSize
, data
);
3860 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3861 GLint yoffset
, GLsizei width
, GLsizei height
,
3862 GLenum format
, GLsizei imageSize
,
3865 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3866 width
, height
, 1, format
, imageSize
, data
);
3871 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3872 GLint yoffset
, GLint zoffset
, GLsizei width
,
3873 GLsizei height
, GLsizei depth
, GLenum format
,
3874 GLsizei imageSize
, const GLvoid
*data
)
3876 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3877 width
, height
, depth
, format
, imageSize
, data
);
3881 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3883 if (ctx
->API
!= API_OPENGL_CORE
) {
3884 switch (internalFormat
) {
3886 return MESA_FORMAT_A8
;
3888 return MESA_FORMAT_A16
;
3889 case GL_ALPHA16F_ARB
:
3890 return MESA_FORMAT_ALPHA_FLOAT16
;
3891 case GL_ALPHA32F_ARB
:
3892 return MESA_FORMAT_ALPHA_FLOAT32
;
3893 case GL_ALPHA8I_EXT
:
3894 return MESA_FORMAT_ALPHA_INT8
;
3895 case GL_ALPHA16I_EXT
:
3896 return MESA_FORMAT_ALPHA_INT16
;
3897 case GL_ALPHA32I_EXT
:
3898 return MESA_FORMAT_ALPHA_INT32
;
3899 case GL_ALPHA8UI_EXT
:
3900 return MESA_FORMAT_ALPHA_UINT8
;
3901 case GL_ALPHA16UI_EXT
:
3902 return MESA_FORMAT_ALPHA_UINT16
;
3903 case GL_ALPHA32UI_EXT
:
3904 return MESA_FORMAT_ALPHA_UINT32
;
3906 return MESA_FORMAT_L8
;
3907 case GL_LUMINANCE16
:
3908 return MESA_FORMAT_L16
;
3909 case GL_LUMINANCE16F_ARB
:
3910 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3911 case GL_LUMINANCE32F_ARB
:
3912 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3913 case GL_LUMINANCE8I_EXT
:
3914 return MESA_FORMAT_LUMINANCE_INT8
;
3915 case GL_LUMINANCE16I_EXT
:
3916 return MESA_FORMAT_LUMINANCE_INT16
;
3917 case GL_LUMINANCE32I_EXT
:
3918 return MESA_FORMAT_LUMINANCE_INT32
;
3919 case GL_LUMINANCE8UI_EXT
:
3920 return MESA_FORMAT_LUMINANCE_UINT8
;
3921 case GL_LUMINANCE16UI_EXT
:
3922 return MESA_FORMAT_LUMINANCE_UINT16
;
3923 case GL_LUMINANCE32UI_EXT
:
3924 return MESA_FORMAT_LUMINANCE_UINT32
;
3925 case GL_LUMINANCE8_ALPHA8
:
3926 return MESA_FORMAT_AL88
;
3927 case GL_LUMINANCE16_ALPHA16
:
3928 return MESA_FORMAT_AL1616
;
3929 case GL_LUMINANCE_ALPHA16F_ARB
:
3930 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3931 case GL_LUMINANCE_ALPHA32F_ARB
:
3932 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3933 case GL_LUMINANCE_ALPHA8I_EXT
:
3934 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3935 case GL_LUMINANCE_ALPHA16I_EXT
:
3936 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3937 case GL_LUMINANCE_ALPHA32I_EXT
:
3938 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3939 case GL_LUMINANCE_ALPHA8UI_EXT
:
3940 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3941 case GL_LUMINANCE_ALPHA16UI_EXT
:
3942 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3943 case GL_LUMINANCE_ALPHA32UI_EXT
:
3944 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3946 return MESA_FORMAT_I8
;
3947 case GL_INTENSITY16
:
3948 return MESA_FORMAT_I16
;
3949 case GL_INTENSITY16F_ARB
:
3950 return MESA_FORMAT_INTENSITY_FLOAT16
;
3951 case GL_INTENSITY32F_ARB
:
3952 return MESA_FORMAT_INTENSITY_FLOAT32
;
3953 case GL_INTENSITY8I_EXT
:
3954 return MESA_FORMAT_INTENSITY_INT8
;
3955 case GL_INTENSITY16I_EXT
:
3956 return MESA_FORMAT_INTENSITY_INT16
;
3957 case GL_INTENSITY32I_EXT
:
3958 return MESA_FORMAT_INTENSITY_INT32
;
3959 case GL_INTENSITY8UI_EXT
:
3960 return MESA_FORMAT_INTENSITY_UINT8
;
3961 case GL_INTENSITY16UI_EXT
:
3962 return MESA_FORMAT_INTENSITY_UINT16
;
3963 case GL_INTENSITY32UI_EXT
:
3964 return MESA_FORMAT_INTENSITY_UINT32
;
3970 if (ctx
->API
== API_OPENGL_CORE
&&
3971 ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
3972 switch (internalFormat
) {
3974 return MESA_FORMAT_RGB_FLOAT32
;
3976 return MESA_FORMAT_RGB_UINT32
;
3978 return MESA_FORMAT_RGB_INT32
;
3984 switch (internalFormat
) {
3986 return MESA_FORMAT_RGBA8888_REV
;
3988 return MESA_FORMAT_RGBA_16
;
3989 case GL_RGBA16F_ARB
:
3990 return MESA_FORMAT_RGBA_FLOAT16
;
3991 case GL_RGBA32F_ARB
:
3992 return MESA_FORMAT_RGBA_FLOAT32
;
3994 return MESA_FORMAT_RGBA_INT8
;
3995 case GL_RGBA16I_EXT
:
3996 return MESA_FORMAT_RGBA_INT16
;
3997 case GL_RGBA32I_EXT
:
3998 return MESA_FORMAT_RGBA_INT32
;
3999 case GL_RGBA8UI_EXT
:
4000 return MESA_FORMAT_RGBA_UINT8
;
4001 case GL_RGBA16UI_EXT
:
4002 return MESA_FORMAT_RGBA_UINT16
;
4003 case GL_RGBA32UI_EXT
:
4004 return MESA_FORMAT_RGBA_UINT32
;
4007 return MESA_FORMAT_GR88
;
4009 return MESA_FORMAT_GR1616
;
4011 return MESA_FORMAT_RG_FLOAT16
;
4013 return MESA_FORMAT_RG_FLOAT32
;
4015 return MESA_FORMAT_RG_INT8
;
4017 return MESA_FORMAT_RG_INT16
;
4019 return MESA_FORMAT_RG_INT32
;
4021 return MESA_FORMAT_RG_UINT8
;
4023 return MESA_FORMAT_RG_UINT16
;
4025 return MESA_FORMAT_RG_UINT32
;
4028 return MESA_FORMAT_R8
;
4030 return MESA_FORMAT_R16
;
4032 return MESA_FORMAT_R_FLOAT16
;
4034 return MESA_FORMAT_R_FLOAT32
;
4036 return MESA_FORMAT_R_INT8
;
4038 return MESA_FORMAT_R_INT16
;
4040 return MESA_FORMAT_R_INT32
;
4042 return MESA_FORMAT_R_UINT8
;
4044 return MESA_FORMAT_R_UINT16
;
4046 return MESA_FORMAT_R_UINT32
;
4049 return MESA_FORMAT_NONE
;
4055 _mesa_validate_texbuffer_format(const struct gl_context
*ctx
,
4056 GLenum internalFormat
)
4058 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4061 if (format
== MESA_FORMAT_NONE
)
4062 return MESA_FORMAT_NONE
;
4064 datatype
= _mesa_get_format_datatype(format
);
4065 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4066 return MESA_FORMAT_NONE
;
4068 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4069 return MESA_FORMAT_NONE
;
4071 if (!ctx
->Extensions
.ARB_texture_rg
) {
4072 GLenum base_format
= _mesa_get_format_base_format(format
);
4073 if (base_format
== GL_R
|| base_format
== GL_RG
)
4074 return MESA_FORMAT_NONE
;
4077 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4078 GLenum base_format
= _mesa_get_format_base_format(format
);
4079 if (base_format
== GL_RGB
)
4080 return MESA_FORMAT_NONE
;
4087 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4088 struct gl_buffer_object
*bufObj
,
4089 GLintptr offset
, GLsizeiptr size
)
4091 struct gl_texture_object
*texObj
;
4094 FLUSH_VERTICES(ctx
, 0);
4096 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4097 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4101 format
= _mesa_validate_texbuffer_format(ctx
, internalFormat
);
4102 if (format
== MESA_FORMAT_NONE
) {
4103 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4108 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4110 _mesa_lock_texture(ctx
, texObj
);
4112 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4113 texObj
->BufferObjectFormat
= internalFormat
;
4114 texObj
->_BufferObjectFormat
= format
;
4115 texObj
->BufferOffset
= offset
;
4116 texObj
->BufferSize
= size
;
4118 _mesa_unlock_texture(ctx
, texObj
);
4122 /** GL_ARB_texture_buffer_object */
4124 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4126 struct gl_buffer_object
*bufObj
;
4128 GET_CURRENT_CONTEXT(ctx
);
4130 /* NOTE: ARB_texture_buffer_object has interactions with
4131 * the compatibility profile that are not implemented.
4133 if (!(ctx
->API
== API_OPENGL_CORE
&&
4134 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4135 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4139 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4140 if (!bufObj
&& buffer
) {
4141 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4145 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4149 /** GL_ARB_texture_buffer_range */
4151 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4152 GLintptr offset
, GLsizeiptr size
)
4154 struct gl_buffer_object
*bufObj
;
4156 GET_CURRENT_CONTEXT(ctx
);
4158 if (!(ctx
->API
== API_OPENGL_CORE
&&
4159 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4160 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4164 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4168 (offset
+ size
) > bufObj
->Size
) {
4169 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4172 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4173 _mesa_error(ctx
, GL_INVALID_VALUE
,
4174 "glTexBufferRange(invalid offset alignment)");
4177 } else if (buffer
) {
4178 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4186 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4191 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4193 /* Everything that is allowed for renderbuffers,
4194 * except for a base format of GL_STENCIL_INDEX.
4196 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4197 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4201 /** GL_ARB_texture_multisample */
4203 check_multisample_target(GLuint dims
, GLenum target
)
4206 case GL_TEXTURE_2D_MULTISAMPLE
:
4207 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4210 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4211 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4221 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4222 GLint internalformat
, GLsizei width
, GLsizei height
,
4223 GLsizei depth
, GLboolean fixedsamplelocations
,
4224 GLboolean immutable
, const char *func
)
4226 struct gl_texture_object
*texObj
;
4227 struct gl_texture_image
*texImage
;
4228 GLboolean sizeOK
, dimensionsOK
;
4229 gl_format texFormat
;
4230 GLenum sample_count_error
;
4232 GET_CURRENT_CONTEXT(ctx
);
4234 if (!(ctx
->Extensions
.ARB_texture_multisample
4235 && _mesa_is_desktop_gl(ctx
))) {
4236 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4240 if (!check_multisample_target(dims
, target
)) {
4241 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4245 /* check that the specified internalformat is color/depth/stencil-renderable;
4246 * refer GL3.1 spec 4.4.4
4249 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4250 _mesa_error(ctx
, GL_INVALID_ENUM
,
4251 "%s(internalformat=%s not legal for immutable-format)",
4252 func
, _mesa_lookup_enum_by_nr(internalformat
));
4256 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4257 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4258 "%s(internalformat=%s)",
4259 func
, _mesa_lookup_enum_by_nr(internalformat
));
4263 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4264 internalformat
, samples
);
4265 if (sample_count_error
!= GL_NO_ERROR
) {
4266 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4270 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4272 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4273 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4274 "%s(texture object 0)",
4279 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4281 if (texImage
== NULL
) {
4282 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4286 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4287 internalformat
, GL_NONE
, GL_NONE
);
4288 assert(texFormat
!= MESA_FORMAT_NONE
);
4290 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4291 width
, height
, depth
, 0);
4293 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4294 width
, height
, depth
, 0);
4296 if (_mesa_is_proxy_texture(target
)) {
4297 if (dimensionsOK
&& sizeOK
) {
4298 _mesa_init_teximage_fields(ctx
, texImage
,
4299 width
, height
, depth
, 0, internalformat
, texFormat
);
4300 texImage
->NumSamples
= samples
;
4301 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4304 /* clear all image fields */
4305 _mesa_init_teximage_fields(ctx
, texImage
,
4306 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4310 if (!dimensionsOK
) {
4311 _mesa_error(ctx
, GL_INVALID_VALUE
,
4312 "%s(invalid width or height)", func
);
4317 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4318 "%s(texture too large)", func
);
4322 /* Check if texObj->Immutable is set */
4323 if (texObj
->Immutable
) {
4324 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4328 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4330 _mesa_init_teximage_fields(ctx
, texImage
,
4331 width
, height
, depth
, 0, internalformat
, texFormat
);
4333 texImage
->NumSamples
= samples
;
4334 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4336 if (width
> 0 && height
> 0 && depth
> 0) {
4337 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4338 width
, height
, depth
)) {
4339 /* tidy up the texture image state. strictly speaking,
4340 * we're allowed to just leave this in whatever state we
4341 * like, but being tidy is good.
4343 _mesa_init_teximage_fields(ctx
, texImage
,
4344 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4348 texObj
->Immutable
= immutable
;
4351 _mesa_set_texture_view_state(ctx
, texObj
, target
, 1);
4354 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4360 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4361 GLenum internalformat
, GLsizei width
,
4362 GLsizei height
, GLboolean fixedsamplelocations
)
4364 teximagemultisample(2, target
, samples
, internalformat
,
4365 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4366 "glTexImage2DMultisample");
4371 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4372 GLenum internalformat
, GLsizei width
,
4373 GLsizei height
, GLsizei depth
,
4374 GLboolean fixedsamplelocations
)
4376 teximagemultisample(3, target
, samples
, internalformat
,
4377 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4378 "glTexImage3DMultisample");
4383 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4384 GLenum internalformat
, GLsizei width
,
4385 GLsizei height
, GLboolean fixedsamplelocations
)
4387 teximagemultisample(2, target
, samples
, internalformat
,
4388 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4389 "glTexStorage2DMultisample");
4394 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4395 GLenum internalformat
, GLsizei width
,
4396 GLsizei height
, GLsizei depth
,
4397 GLboolean fixedsamplelocations
)
4399 teximagemultisample(3, target
, samples
, internalformat
,
4400 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4401 "glTexStorage3DMultisample");