2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
29 * Texture image-related functions.
34 #include "bufferobj.h"
38 #include "framebuffer.h"
43 #include "multisample.h"
45 #include "texcompress.h"
46 #include "texcompress_cpal.h"
50 #include "texstorage.h"
52 #include "glformats.h"
56 * State changes which we care about for glCopyTex[Sub]Image() calls.
57 * In particular, we care about pixel transfer state and buffer state
58 * (such as glReadBuffer to make sure we read from the right renderbuffer).
60 #define NEW_COPY_TEX_STATE (_NEW_BUFFERS | _NEW_PIXEL)
65 * Return the simple base format for a given internal texture format.
66 * For example, given GL_LUMINANCE12_ALPHA4, return GL_LUMINANCE_ALPHA.
68 * \param ctx GL context.
69 * \param internalFormat the internal texture format token or 1, 2, 3, or 4.
71 * \return the corresponding \u base internal format (GL_ALPHA, GL_LUMINANCE,
72 * GL_LUMANCE_ALPHA, GL_INTENSITY, GL_RGB, or GL_RGBA), or -1 if invalid enum.
74 * This is the format which is used during texture application (i.e. the
75 * texture format and env mode determine the arithmetic used.
78 _mesa_base_tex_format( struct gl_context
*ctx
, GLint internalFormat
)
80 switch (internalFormat
) {
86 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_ALPHA
: -1;
93 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE
: -1;
95 case GL_LUMINANCE_ALPHA
:
96 case GL_LUMINANCE4_ALPHA4
:
97 case GL_LUMINANCE6_ALPHA2
:
98 case GL_LUMINANCE8_ALPHA8
:
99 case GL_LUMINANCE12_ALPHA4
:
100 case GL_LUMINANCE12_ALPHA12
:
101 case GL_LUMINANCE16_ALPHA16
:
102 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_LUMINANCE_ALPHA
: -1;
108 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_INTENSITY
: -1;
110 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGB
: -1;
121 return (ctx
->API
!= API_OPENGL_CORE
) ? GL_RGBA
: -1;
135 /* GL_BGRA can be an internal format *only* in OpenGL ES (1.x or 2.0).
137 if (_mesa_is_gles(ctx
)) {
138 switch (internalFormat
) {
146 if (ctx
->Extensions
.ARB_ES2_compatibility
) {
147 switch (internalFormat
) {
155 if (ctx
->Extensions
.ARB_depth_texture
) {
156 switch (internalFormat
) {
157 case GL_DEPTH_COMPONENT
:
158 case GL_DEPTH_COMPONENT16
:
159 case GL_DEPTH_COMPONENT24
:
160 case GL_DEPTH_COMPONENT32
:
161 return GL_DEPTH_COMPONENT
;
167 switch (internalFormat
) {
168 case GL_COMPRESSED_ALPHA
:
170 case GL_COMPRESSED_LUMINANCE
:
172 case GL_COMPRESSED_LUMINANCE_ALPHA
:
173 return GL_LUMINANCE_ALPHA
;
174 case GL_COMPRESSED_INTENSITY
:
176 case GL_COMPRESSED_RGB
:
178 case GL_COMPRESSED_RGBA
:
184 if (ctx
->Extensions
.TDFX_texture_compression_FXT1
) {
185 switch (internalFormat
) {
186 case GL_COMPRESSED_RGB_FXT1_3DFX
:
188 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
195 /* Assume that the ANGLE flag will always be set if the EXT flag is set.
197 if (ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
198 switch (internalFormat
) {
199 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
201 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
202 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
203 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
210 if (_mesa_is_desktop_gl(ctx
)
211 && ctx
->Extensions
.ANGLE_texture_compression_dxt
) {
212 switch (internalFormat
) {
224 if (ctx
->Extensions
.MESA_ycbcr_texture
) {
225 if (internalFormat
== GL_YCBCR_MESA
)
226 return GL_YCBCR_MESA
;
229 if (ctx
->Extensions
.ARB_texture_float
) {
230 switch (internalFormat
) {
231 case GL_ALPHA16F_ARB
:
232 case GL_ALPHA32F_ARB
:
240 case GL_INTENSITY16F_ARB
:
241 case GL_INTENSITY32F_ARB
:
243 case GL_LUMINANCE16F_ARB
:
244 case GL_LUMINANCE32F_ARB
:
246 case GL_LUMINANCE_ALPHA16F_ARB
:
247 case GL_LUMINANCE_ALPHA32F_ARB
:
248 return GL_LUMINANCE_ALPHA
;
254 if (ctx
->Extensions
.ATI_envmap_bumpmap
) {
255 switch (internalFormat
) {
264 if (ctx
->Extensions
.EXT_texture_snorm
) {
265 switch (internalFormat
) {
280 case GL_RGBA16_SNORM
:
283 case GL_ALPHA8_SNORM
:
284 case GL_ALPHA16_SNORM
:
286 case GL_LUMINANCE_SNORM
:
287 case GL_LUMINANCE8_SNORM
:
288 case GL_LUMINANCE16_SNORM
:
290 case GL_LUMINANCE_ALPHA_SNORM
:
291 case GL_LUMINANCE8_ALPHA8_SNORM
:
292 case GL_LUMINANCE16_ALPHA16_SNORM
:
293 return GL_LUMINANCE_ALPHA
;
294 case GL_INTENSITY_SNORM
:
295 case GL_INTENSITY8_SNORM
:
296 case GL_INTENSITY16_SNORM
:
303 if (ctx
->Extensions
.EXT_packed_depth_stencil
) {
304 switch (internalFormat
) {
305 case GL_DEPTH_STENCIL_EXT
:
306 case GL_DEPTH24_STENCIL8_EXT
:
307 return GL_DEPTH_STENCIL_EXT
;
313 if (ctx
->Extensions
.EXT_texture_sRGB
) {
314 switch (internalFormat
) {
317 case GL_COMPRESSED_SRGB_EXT
:
319 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
320 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGB
: -1;
321 case GL_SRGB_ALPHA_EXT
:
322 case GL_SRGB8_ALPHA8_EXT
:
323 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
325 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
326 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
327 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
328 return ctx
->Extensions
.EXT_texture_compression_s3tc
? GL_RGBA
: -1;
329 case GL_SLUMINANCE_ALPHA_EXT
:
330 case GL_SLUMINANCE8_ALPHA8_EXT
:
331 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
332 return GL_LUMINANCE_ALPHA
;
333 case GL_SLUMINANCE_EXT
:
334 case GL_SLUMINANCE8_EXT
:
335 case GL_COMPRESSED_SLUMINANCE_EXT
:
342 if (ctx
->Version
>= 30 ||
343 ctx
->Extensions
.EXT_texture_integer
) {
344 switch (internalFormat
) {
346 case GL_RGBA16UI_EXT
:
347 case GL_RGBA32UI_EXT
:
363 if (ctx
->Extensions
.EXT_texture_integer
) {
364 switch (internalFormat
) {
365 case GL_ALPHA8UI_EXT
:
366 case GL_ALPHA16UI_EXT
:
367 case GL_ALPHA32UI_EXT
:
369 case GL_ALPHA16I_EXT
:
370 case GL_ALPHA32I_EXT
:
372 case GL_INTENSITY8UI_EXT
:
373 case GL_INTENSITY16UI_EXT
:
374 case GL_INTENSITY32UI_EXT
:
375 case GL_INTENSITY8I_EXT
:
376 case GL_INTENSITY16I_EXT
:
377 case GL_INTENSITY32I_EXT
:
379 case GL_LUMINANCE8UI_EXT
:
380 case GL_LUMINANCE16UI_EXT
:
381 case GL_LUMINANCE32UI_EXT
:
382 case GL_LUMINANCE8I_EXT
:
383 case GL_LUMINANCE16I_EXT
:
384 case GL_LUMINANCE32I_EXT
:
386 case GL_LUMINANCE_ALPHA8UI_EXT
:
387 case GL_LUMINANCE_ALPHA16UI_EXT
:
388 case GL_LUMINANCE_ALPHA32UI_EXT
:
389 case GL_LUMINANCE_ALPHA8I_EXT
:
390 case GL_LUMINANCE_ALPHA16I_EXT
:
391 case GL_LUMINANCE_ALPHA32I_EXT
:
392 return GL_LUMINANCE_ALPHA
;
398 if (ctx
->Extensions
.ARB_texture_rg
) {
399 switch (internalFormat
) {
401 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
403 if (!ctx
->Extensions
.ARB_half_float_pixel
)
407 if (!ctx
->Extensions
.ARB_texture_float
)
416 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
422 case GL_COMPRESSED_RED
:
426 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
428 if (!ctx
->Extensions
.ARB_half_float_pixel
)
432 if (!ctx
->Extensions
.ARB_texture_float
)
441 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
447 case GL_COMPRESSED_RG
:
454 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
455 switch (internalFormat
) {
463 if (ctx
->Extensions
.EXT_packed_float
) {
464 switch (internalFormat
) {
465 case GL_R11F_G11F_B10F_EXT
:
472 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
473 switch (internalFormat
) {
474 case GL_DEPTH_COMPONENT32F
:
475 return GL_DEPTH_COMPONENT
;
476 case GL_DEPTH32F_STENCIL8
:
477 return GL_DEPTH_STENCIL
;
483 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
484 switch (internalFormat
) {
485 case GL_COMPRESSED_RED_RGTC1
:
486 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
488 case GL_COMPRESSED_RG_RGTC2
:
489 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
496 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
497 switch (internalFormat
) {
498 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
499 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
501 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
502 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
503 return GL_LUMINANCE_ALPHA
;
509 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
510 switch (internalFormat
) {
511 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
512 return GL_LUMINANCE_ALPHA
;
518 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
519 switch (internalFormat
) {
520 case GL_ETC1_RGB8_OES
:
527 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
528 switch (internalFormat
) {
529 case GL_COMPRESSED_RGB8_ETC2
:
530 case GL_COMPRESSED_SRGB8_ETC2
:
532 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
533 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
534 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
535 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
537 case GL_COMPRESSED_R11_EAC
:
538 case GL_COMPRESSED_SIGNED_R11_EAC
:
540 case GL_COMPRESSED_RG11_EAC
:
541 case GL_COMPRESSED_SIGNED_RG11_EAC
:
548 if (ctx
->API
== API_OPENGLES
) {
549 switch (internalFormat
) {
550 case GL_PALETTE4_RGB8_OES
:
551 case GL_PALETTE4_R5_G6_B5_OES
:
552 case GL_PALETTE8_RGB8_OES
:
553 case GL_PALETTE8_R5_G6_B5_OES
:
555 case GL_PALETTE4_RGBA8_OES
:
556 case GL_PALETTE8_RGB5_A1_OES
:
557 case GL_PALETTE4_RGBA4_OES
:
558 case GL_PALETTE4_RGB5_A1_OES
:
559 case GL_PALETTE8_RGBA8_OES
:
560 case GL_PALETTE8_RGBA4_OES
:
567 return -1; /* error */
572 * For cube map faces, return a face index in [0,5].
573 * For other targets return 0;
576 _mesa_tex_target_to_face(GLenum target
)
578 if (_mesa_is_cube_face(target
))
579 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
587 * Install gl_texture_image in a gl_texture_object according to the target
588 * and level parameters.
590 * \param tObj texture object.
591 * \param target texture target.
592 * \param level image level.
593 * \param texImage texture image.
596 set_tex_image(struct gl_texture_object
*tObj
,
597 GLenum target
, GLint level
,
598 struct gl_texture_image
*texImage
)
600 const GLuint face
= _mesa_tex_target_to_face(target
);
604 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
607 tObj
->Image
[face
][level
] = texImage
;
609 /* Set the 'back' pointer */
610 texImage
->TexObject
= tObj
;
611 texImage
->Level
= level
;
612 texImage
->Face
= face
;
617 * Allocate a texture image structure.
619 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
622 * \return a pointer to gl_texture_image struct with all fields initialized to
625 struct gl_texture_image
*
626 _mesa_new_texture_image( struct gl_context
*ctx
)
629 return CALLOC_STRUCT(gl_texture_image
);
634 * Free a gl_texture_image and associated data.
635 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
637 * \param texImage texture image.
639 * Free the texture image structure and the associated image data.
642 _mesa_delete_texture_image(struct gl_context
*ctx
,
643 struct gl_texture_image
*texImage
)
645 /* Free texImage->Data and/or any other driver-specific texture
648 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
649 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
655 * Test if a target is a proxy target.
657 * \param target texture target.
659 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
662 _mesa_is_proxy_texture(GLenum target
)
665 static const GLenum targets
[] = {
669 GL_PROXY_TEXTURE_CUBE_MAP
,
670 GL_PROXY_TEXTURE_RECTANGLE
,
671 GL_PROXY_TEXTURE_1D_ARRAY
,
672 GL_PROXY_TEXTURE_2D_ARRAY
,
673 GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
,
674 GL_PROXY_TEXTURE_2D_MULTISAMPLE
,
675 GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
678 * NUM_TEXTURE_TARGETS should match number of terms above, except there's no
679 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
681 STATIC_ASSERT(NUM_TEXTURE_TARGETS
== Elements(targets
) + 2);
683 for (i
= 0; i
< Elements(targets
); ++i
)
684 if (target
== targets
[i
])
691 * Return the proxy target which corresponds to the given texture target
694 _mesa_get_proxy_target(GLenum target
)
698 case GL_PROXY_TEXTURE_1D
:
699 return GL_PROXY_TEXTURE_1D
;
701 case GL_PROXY_TEXTURE_2D
:
702 return GL_PROXY_TEXTURE_2D
;
704 case GL_PROXY_TEXTURE_3D
:
705 return GL_PROXY_TEXTURE_3D
;
706 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
707 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
708 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
709 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
710 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
711 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
712 case GL_TEXTURE_CUBE_MAP_ARB
:
713 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
714 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
715 case GL_TEXTURE_RECTANGLE_NV
:
716 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
717 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
718 case GL_TEXTURE_1D_ARRAY_EXT
:
719 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
720 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
721 case GL_TEXTURE_2D_ARRAY_EXT
:
722 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
723 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
724 case GL_TEXTURE_CUBE_MAP_ARRAY
:
725 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
726 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
727 case GL_TEXTURE_2D_MULTISAMPLE
:
728 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
729 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
730 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
731 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
732 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
734 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
741 * Get the texture object that corresponds to the target of the given
742 * texture unit. The target should have already been checked for validity.
744 * \param ctx GL context.
745 * \param texUnit texture unit.
746 * \param target texture target.
748 * \return pointer to the texture object on success, or NULL on failure.
750 struct gl_texture_object
*
751 _mesa_select_tex_object(struct gl_context
*ctx
,
752 const struct gl_texture_unit
*texUnit
,
755 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
756 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
.MESA_texture_array
||
1022 ctx
->Extensions
.EXT_texture_array
)
1023 ? ctx
->Const
.MaxTextureLevels
: 0;
1024 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1025 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1026 return ctx
->Extensions
.ARB_texture_cube_map_array
1027 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1028 case GL_TEXTURE_BUFFER
:
1029 return ctx
->API
== API_OPENGL_CORE
&&
1030 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1031 case GL_TEXTURE_2D_MULTISAMPLE
:
1032 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1033 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1034 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1035 return _mesa_is_desktop_gl(ctx
)
1036 && ctx
->Extensions
.ARB_texture_multisample
1038 case GL_TEXTURE_EXTERNAL_OES
:
1041 return 0; /* bad target */
1047 * Return number of dimensions per mipmap level for the given texture target.
1050 _mesa_get_texture_dimensions(GLenum target
)
1054 case GL_PROXY_TEXTURE_1D
:
1057 case GL_TEXTURE_RECTANGLE
:
1058 case GL_TEXTURE_CUBE_MAP
:
1059 case GL_PROXY_TEXTURE_2D
:
1060 case GL_PROXY_TEXTURE_RECTANGLE
:
1061 case GL_PROXY_TEXTURE_CUBE_MAP
:
1062 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1063 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1064 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1065 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1066 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1067 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1068 case GL_TEXTURE_1D_ARRAY
:
1069 case GL_PROXY_TEXTURE_1D_ARRAY
:
1070 case GL_TEXTURE_EXTERNAL_OES
:
1071 case GL_TEXTURE_2D_MULTISAMPLE
:
1072 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1075 case GL_PROXY_TEXTURE_3D
:
1076 case GL_TEXTURE_2D_ARRAY
:
1077 case GL_PROXY_TEXTURE_2D_ARRAY
:
1078 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1079 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1080 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1081 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1083 case GL_TEXTURE_BUFFER
:
1086 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1094 * Return the maximum number of mipmap levels for the given target
1095 * and the dimensions.
1096 * The dimensions are expected not to include the border.
1099 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1106 case GL_TEXTURE_1D_ARRAY
:
1107 case GL_PROXY_TEXTURE_1D
:
1108 case GL_PROXY_TEXTURE_1D_ARRAY
:
1111 case GL_TEXTURE_CUBE_MAP
:
1112 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1113 case GL_PROXY_TEXTURE_CUBE_MAP
:
1114 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1118 case GL_TEXTURE_2D_ARRAY
:
1119 case GL_PROXY_TEXTURE_2D
:
1120 case GL_PROXY_TEXTURE_2D_ARRAY
:
1121 size
= MAX2(width
, height
);
1124 case GL_PROXY_TEXTURE_3D
:
1125 size
= MAX3(width
, height
, depth
);
1127 case GL_TEXTURE_RECTANGLE
:
1128 case GL_TEXTURE_EXTERNAL_OES
:
1129 case GL_TEXTURE_2D_MULTISAMPLE
:
1130 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1131 case GL_PROXY_TEXTURE_RECTANGLE
:
1132 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1133 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1140 return _mesa_logbase2(size
) + 1;
1144 #if 000 /* not used anymore */
1146 * glTexImage[123]D can accept a NULL image pointer. In this case we
1147 * create a texture image with unspecified image contents per the OpenGL
1151 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1153 const GLint components
= _mesa_components_in_format(format
);
1154 const GLint numPixels
= width
* height
* depth
;
1155 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1159 * Let's see if anyone finds this. If glTexImage2D() is called with
1160 * a NULL image pointer then load the texture image with something
1161 * interesting instead of leaving it indeterminate.
1164 static const char message
[8][32] = {
1165 " X X XXXXX XXX X ",
1166 " XX XX X X X X X ",
1168 " X X XXXX XXX XXXXX ",
1171 " X X XXXXX XXX X X ",
1175 GLubyte
*imgPtr
= data
;
1177 for (h
= 0; h
< depth
; h
++) {
1178 for (i
= 0; i
< height
; i
++) {
1179 GLint srcRow
= 7 - (i
% 8);
1180 for (j
= 0; j
< width
; j
++) {
1181 GLint srcCol
= j
% 32;
1182 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1183 for (k
= 0; k
< components
; k
++) {
1199 * Set the size and format-related fields of a gl_texture_image struct
1200 * to zero. This is used when a proxy texture test fails.
1203 clear_teximage_fields(struct gl_texture_image
*img
)
1206 img
->_BaseFormat
= 0;
1207 img
->InternalFormat
= 0;
1216 img
->HeightLog2
= 0;
1218 img
->TexFormat
= MESA_FORMAT_NONE
;
1219 img
->NumSamples
= 0;
1220 img
->FixedSampleLocations
= GL_TRUE
;
1225 * Initialize basic fields of the gl_texture_image struct.
1227 * \param ctx GL context.
1228 * \param img texture image structure to be initialized.
1229 * \param width image width.
1230 * \param height image height.
1231 * \param depth image depth.
1232 * \param border image border.
1233 * \param internalFormat internal format.
1234 * \param format the actual hardware format (one of MESA_FORMAT_*)
1236 * Fills in the fields of \p img with the given information.
1237 * Note: width, height and depth include the border.
1240 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1241 struct gl_texture_image
*img
,
1242 GLsizei width
, GLsizei height
, GLsizei depth
,
1243 GLint border
, GLenum internalFormat
,
1249 ASSERT(height
>= 0);
1252 target
= img
->TexObject
->Target
;
1253 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1254 ASSERT(img
->_BaseFormat
> 0);
1255 img
->InternalFormat
= internalFormat
;
1256 img
->Border
= border
;
1258 img
->Height
= height
;
1261 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1262 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1264 img
->NumSamples
= 0;
1265 img
->FixedSampleLocations
= GL_TRUE
;
1269 case GL_TEXTURE_BUFFER
:
1270 case GL_PROXY_TEXTURE_1D
:
1275 img
->HeightLog2
= 0;
1282 case GL_TEXTURE_1D_ARRAY
:
1283 case GL_PROXY_TEXTURE_1D_ARRAY
:
1284 img
->Height2
= height
; /* no border */
1285 img
->HeightLog2
= 0; /* not used */
1293 case GL_TEXTURE_RECTANGLE
:
1294 case GL_TEXTURE_CUBE_MAP
:
1295 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1296 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1297 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1298 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1299 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1300 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1301 case GL_TEXTURE_EXTERNAL_OES
:
1302 case GL_PROXY_TEXTURE_2D
:
1303 case GL_PROXY_TEXTURE_RECTANGLE
:
1304 case GL_PROXY_TEXTURE_CUBE_MAP
:
1305 case GL_TEXTURE_2D_MULTISAMPLE
:
1306 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1307 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1308 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1315 case GL_TEXTURE_2D_ARRAY
:
1316 case GL_PROXY_TEXTURE_2D_ARRAY
:
1317 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1318 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1319 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1320 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1321 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1322 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1323 img
->Depth2
= depth
; /* no border */
1324 img
->DepthLog2
= 0; /* not used */
1327 case GL_PROXY_TEXTURE_3D
:
1328 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1329 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1330 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1331 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1334 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1339 _mesa_get_tex_max_num_levels(target
,
1340 img
->Width2
, img
->Height2
, img
->Depth2
);
1341 img
->TexFormat
= format
;
1346 * Free and clear fields of the gl_texture_image struct.
1348 * \param ctx GL context.
1349 * \param texImage texture image structure to be cleared.
1351 * After the call, \p texImage will have no data associated with it. Its
1352 * fields are cleared so that its parent object will test incomplete.
1355 _mesa_clear_texture_image(struct gl_context
*ctx
,
1356 struct gl_texture_image
*texImage
)
1358 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1359 clear_teximage_fields(texImage
);
1364 * Check the width, height, depth and border of a texture image are legal.
1365 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1367 * The target and level parameters will have already been validated.
1368 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1371 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1372 GLint level
, GLint width
, GLint height
,
1373 GLint depth
, GLint border
)
1379 case GL_PROXY_TEXTURE_1D
:
1380 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1381 maxSize
>>= level
; /* level size */
1382 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1384 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1385 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1391 case GL_PROXY_TEXTURE_2D
:
1392 case GL_TEXTURE_2D_MULTISAMPLE
:
1393 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1394 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1396 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1398 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1400 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1401 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1403 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1409 case GL_PROXY_TEXTURE_3D
:
1410 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1412 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1414 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1416 if (depth
< 2 * border
|| depth
> 2 * border
+ maxSize
)
1418 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1419 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1421 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1423 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1428 case GL_TEXTURE_RECTANGLE_NV
:
1429 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1432 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1433 if (width
< 0 || width
> maxSize
)
1435 if (height
< 0 || height
> maxSize
)
1439 case GL_TEXTURE_CUBE_MAP
:
1440 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1441 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1442 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1443 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1444 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1445 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1446 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1447 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1449 if (width
!= height
)
1451 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1453 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1455 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1456 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1458 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1463 case GL_TEXTURE_1D_ARRAY_EXT
:
1464 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1465 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1467 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1469 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1471 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1472 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1477 case GL_TEXTURE_2D_ARRAY_EXT
:
1478 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1479 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1480 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1481 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1483 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1485 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1487 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1489 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1490 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1492 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1497 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1498 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1499 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1500 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1502 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1504 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
|| depth
% 6)
1506 if (width
!= height
)
1508 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1510 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1511 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1513 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1518 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1525 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1526 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1527 * \param destImage the destination texture image.
1528 * \return GL_TRUE if error found, GL_FALSE otherwise.
1531 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1532 const char *function
, GLuint dims
,
1533 const struct gl_texture_image
*destImage
,
1534 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1535 GLsizei subWidth
, GLsizei subHeight
,
1538 const GLenum target
= destImage
->TexObject
->Target
;
1543 _mesa_error(ctx
, GL_INVALID_VALUE
,
1544 "%s%dD(width=%d)", function
, dims
, subWidth
);
1548 if (dims
> 1 && subHeight
< 0) {
1549 _mesa_error(ctx
, GL_INVALID_VALUE
,
1550 "%s%dD(height=%d)", function
, dims
, subHeight
);
1554 if (dims
> 2 && subDepth
< 0) {
1555 _mesa_error(ctx
, GL_INVALID_VALUE
,
1556 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1560 /* check xoffset and width */
1561 if (xoffset
< - (GLint
) destImage
->Border
) {
1562 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1567 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1568 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1573 /* check yoffset and height */
1575 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1576 if (yoffset
< -yBorder
) {
1577 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1581 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1582 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1588 /* check zoffset and depth */
1590 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1591 if (zoffset
< -zBorder
) {
1592 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1595 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1596 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1602 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1603 * compressed texture images can be updated. But, that restriction may be
1604 * relaxed for particular compressed formats. At this time, all the
1605 * compressed formats supported by Mesa allow sub-textures to be updated
1606 * along compressed block boundaries.
1608 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1610 if (bw
!= 1 || bh
!= 1) {
1611 /* offset must be multiple of block size */
1612 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1613 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1614 "%s%dD(xoffset = %d, yoffset = %d)",
1615 function
, dims
, xoffset
, yoffset
);
1619 /* The size must be a multiple of bw x bh, or we must be using a
1620 * offset+size that exactly hits the edge of the image. This
1621 * is important for small mipmap levels (1x1, 2x1, etc) and for
1624 if ((subWidth
% bw
!= 0) &&
1625 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1626 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1627 "%s%dD(width = %d)", function
, dims
, subWidth
);
1631 if ((subHeight
% bh
!= 0) &&
1632 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1633 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1634 "%s%dD(height = %d)", function
, dims
, subHeight
);
1646 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1647 * specific texture image size checks.
1649 * A hardware driver might override this function if, for example, the
1650 * max 3D texture size is 512x512x64 (i.e. not a cube).
1652 * Note that width, height, depth == 0 is not an error. However, a
1653 * texture with zero width/height/depth will be considered "incomplete"
1654 * and texturing will effectively be disabled.
1656 * \param target any texture target/type
1657 * \param level as passed to glTexImage
1658 * \param format the MESA_FORMAT_x for the tex image
1659 * \param width as passed to glTexImage
1660 * \param height as passed to glTexImage
1661 * \param depth as passed to glTexImage
1662 * \param border as passed to glTexImage
1663 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1666 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1668 GLint width
, GLint height
, GLint depth
, GLint border
)
1670 /* We just check if the image size is less than MaxTextureMbytes.
1671 * Some drivers may do more specific checks.
1673 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1674 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1675 mbytes
*= _mesa_num_tex_faces(target
);
1676 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1681 * Return true if the format is only valid for glCompressedTexImage.
1684 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1687 case GL_ETC1_RGB8_OES
:
1688 case GL_PALETTE4_RGB8_OES
:
1689 case GL_PALETTE4_RGBA8_OES
:
1690 case GL_PALETTE4_R5_G6_B5_OES
:
1691 case GL_PALETTE4_RGBA4_OES
:
1692 case GL_PALETTE4_RGB5_A1_OES
:
1693 case GL_PALETTE8_RGB8_OES
:
1694 case GL_PALETTE8_RGBA8_OES
:
1695 case GL_PALETTE8_R5_G6_B5_OES
:
1696 case GL_PALETTE8_RGBA4_OES
:
1697 case GL_PALETTE8_RGB5_A1_OES
:
1706 * Helper function to determine whether a target and specific compression
1707 * format are supported.
1710 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1713 (void) intFormat
; /* not used yet */
1717 case GL_PROXY_TEXTURE_2D
:
1718 return GL_TRUE
; /* true for any compressed format so far */
1719 case GL_PROXY_TEXTURE_CUBE_MAP
:
1720 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1721 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1722 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1723 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1724 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1725 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1726 return ctx
->Extensions
.ARB_texture_cube_map
;
1727 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1728 case GL_TEXTURE_2D_ARRAY_EXT
:
1729 return (ctx
->Extensions
.MESA_texture_array
||
1730 ctx
->Extensions
.EXT_texture_array
);
1731 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1732 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1733 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1741 * Check if the given texture target value is legal for a
1742 * glTexImage1/2/3D call.
1745 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1751 case GL_PROXY_TEXTURE_1D
:
1752 return _mesa_is_desktop_gl(ctx
);
1760 case GL_PROXY_TEXTURE_2D
:
1761 return _mesa_is_desktop_gl(ctx
);
1762 case GL_PROXY_TEXTURE_CUBE_MAP
:
1763 return _mesa_is_desktop_gl(ctx
)
1764 && ctx
->Extensions
.ARB_texture_cube_map
;
1765 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1766 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1767 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1768 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1769 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1770 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1771 return ctx
->Extensions
.ARB_texture_cube_map
;
1772 case GL_TEXTURE_RECTANGLE_NV
:
1773 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1774 return _mesa_is_desktop_gl(ctx
)
1775 && ctx
->Extensions
.NV_texture_rectangle
;
1776 case GL_TEXTURE_1D_ARRAY_EXT
:
1777 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1778 return _mesa_is_desktop_gl(ctx
)
1779 && (ctx
->Extensions
.MESA_texture_array
||
1780 ctx
->Extensions
.EXT_texture_array
);
1788 case GL_PROXY_TEXTURE_3D
:
1789 return _mesa_is_desktop_gl(ctx
);
1790 case GL_TEXTURE_2D_ARRAY_EXT
:
1791 return (_mesa_is_desktop_gl(ctx
)
1792 && (ctx
->Extensions
.MESA_texture_array
||
1793 ctx
->Extensions
.EXT_texture_array
))
1794 || _mesa_is_gles3(ctx
);
1795 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1796 return _mesa_is_desktop_gl(ctx
)
1797 && (ctx
->Extensions
.MESA_texture_array
||
1798 ctx
->Extensions
.EXT_texture_array
);
1799 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1800 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1801 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1806 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1813 * Check if the given texture target value is legal for a
1814 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1815 * The difference compared to legal_teximage_target() above is that
1816 * proxy targets are not supported.
1819 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1823 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1828 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1829 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1830 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1831 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1832 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1833 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1834 return ctx
->Extensions
.ARB_texture_cube_map
;
1835 case GL_TEXTURE_RECTANGLE_NV
:
1836 return _mesa_is_desktop_gl(ctx
)
1837 && ctx
->Extensions
.NV_texture_rectangle
;
1838 case GL_TEXTURE_1D_ARRAY_EXT
:
1839 return _mesa_is_desktop_gl(ctx
)
1840 && (ctx
->Extensions
.MESA_texture_array
||
1841 ctx
->Extensions
.EXT_texture_array
);
1849 case GL_TEXTURE_2D_ARRAY_EXT
:
1850 return (_mesa_is_desktop_gl(ctx
)
1851 && (ctx
->Extensions
.MESA_texture_array
||
1852 ctx
->Extensions
.EXT_texture_array
))
1853 || _mesa_is_gles3(ctx
);
1854 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1855 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1856 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1861 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1869 * Helper function to determine if a texture object is mutable (in terms
1870 * of GL_ARB_texture_storage).
1873 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1875 struct gl_texture_object
*texObj
= _mesa_get_current_tex_object(ctx
, target
);
1876 return !texObj
->Immutable
;
1881 * Return expected size of a compressed texture.
1884 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1887 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1888 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1893 * Test the glTexImage[123]D() parameters for errors.
1895 * \param ctx GL context.
1896 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1897 * \param target texture target given by the user (already validated).
1898 * \param level image level given by the user.
1899 * \param internalFormat internal format given by the user.
1900 * \param format pixel data format given by the user.
1901 * \param type pixel data type given by the user.
1902 * \param width image width given by the user.
1903 * \param height image height given by the user.
1904 * \param depth image depth given by the user.
1905 * \param border image border given by the user.
1907 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1909 * Verifies each of the parameters against the constants specified in
1910 * __struct gl_contextRec::Const and the supported extensions, and according
1911 * to the OpenGL specification.
1912 * Note that we don't fully error-check the width, height, depth values
1913 * here. That's done in _mesa_legal_texture_dimensions() which is used
1914 * by several other GL entrypoints. Plus, texture dims have a special
1915 * interaction with proxy textures.
1918 texture_error_check( struct gl_context
*ctx
,
1919 GLuint dimensions
, GLenum target
,
1920 GLint level
, GLint internalFormat
,
1921 GLenum format
, GLenum type
,
1922 GLint width
, GLint height
,
1923 GLint depth
, GLint border
)
1925 GLboolean colorFormat
;
1928 /* Even though there are no color-index textures, we still have to support
1929 * uploading color-index data and remapping it to RGB via the
1930 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1932 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1934 /* Note: for proxy textures, some error conditions immediately generate
1935 * a GL error in the usual way. But others do not generate a GL error.
1936 * Instead, they cause the width, height, depth, format fields of the
1937 * texture image to be zeroed-out. The GL spec seems to indicate that the
1938 * zero-out behaviour is only used in cases related to memory allocation.
1942 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1943 _mesa_error(ctx
, GL_INVALID_VALUE
,
1944 "glTexImage%dD(level=%d)", dimensions
, level
);
1949 if (border
< 0 || border
> 1 ||
1950 ((ctx
->API
!= API_OPENGL_COMPAT
||
1951 target
== GL_TEXTURE_RECTANGLE_NV
||
1952 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1953 _mesa_error(ctx
, GL_INVALID_VALUE
,
1954 "glTexImage%dD(border=%d)", dimensions
, border
);
1958 if (width
< 0 || height
< 0 || depth
< 0) {
1959 _mesa_error(ctx
, GL_INVALID_VALUE
,
1960 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1964 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1965 * combinations of format, internalFormat, and type that can be used.
1966 * Formats and types that require additional extensions (e.g., GL_FLOAT
1967 * requires GL_OES_texture_float) are filtered elsewhere.
1970 if (_mesa_is_gles(ctx
)) {
1971 if (_mesa_is_gles3(ctx
)) {
1972 err
= _mesa_es3_error_check_format_and_type(format
, type
,
1975 if (format
!= internalFormat
) {
1976 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1977 "glTexImage%dD(format = %s, internalFormat = %s)",
1979 _mesa_lookup_enum_by_nr(format
),
1980 _mesa_lookup_enum_by_nr(internalFormat
));
1984 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1986 if (err
!= GL_NO_ERROR
) {
1987 _mesa_error(ctx
, err
,
1988 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
1990 _mesa_lookup_enum_by_nr(format
),
1991 _mesa_lookup_enum_by_nr(type
),
1992 _mesa_lookup_enum_by_nr(internalFormat
));
1997 /* Check internalFormat */
1998 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
1999 _mesa_error(ctx
, GL_INVALID_VALUE
,
2000 "glTexImage%dD(internalFormat=%s)",
2001 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2005 /* Check incoming image format and type */
2006 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2007 if (err
!= GL_NO_ERROR
) {
2008 _mesa_error(ctx
, err
,
2009 "glTexImage%dD(incompatible format = %s, type = %s)",
2010 dimensions
, _mesa_lookup_enum_by_nr(format
),
2011 _mesa_lookup_enum_by_nr(type
));
2015 /* make sure internal format and format basically agree */
2016 colorFormat
= _mesa_is_color_format(format
);
2017 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2018 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2019 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2020 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2021 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2022 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2023 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2024 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2025 _mesa_lookup_enum_by_nr(format
));
2029 /* additional checks for ycbcr textures */
2030 if (internalFormat
== GL_YCBCR_MESA
) {
2031 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2032 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2033 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2035 _mesa_snprintf(message
, sizeof(message
),
2036 "glTexImage%dD(format/type YCBCR mismatch)",
2038 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2039 return GL_TRUE
; /* error */
2041 if (target
!= GL_TEXTURE_2D
&&
2042 target
!= GL_PROXY_TEXTURE_2D
&&
2043 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2044 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2045 _mesa_error(ctx
, GL_INVALID_ENUM
,
2046 "glTexImage%dD(bad target for YCbCr texture)",
2052 _mesa_snprintf(message
, sizeof(message
),
2053 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2054 dimensions
, border
);
2055 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2060 /* additional checks for depth textures */
2061 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2062 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2063 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
2064 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
2065 if (target
!= GL_TEXTURE_1D
&&
2066 target
!= GL_PROXY_TEXTURE_1D
&&
2067 target
!= GL_TEXTURE_2D
&&
2068 target
!= GL_PROXY_TEXTURE_2D
&&
2069 target
!= GL_TEXTURE_1D_ARRAY
&&
2070 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2071 target
!= GL_TEXTURE_2D_ARRAY
&&
2072 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2073 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2074 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2075 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2076 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2077 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2078 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2079 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2080 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2081 _mesa_error(ctx
, GL_INVALID_ENUM
,
2082 "glTexImage%dD(bad target for depth texture)",
2088 /* additional checks for compressed textures */
2089 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2090 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2091 _mesa_error(ctx
, GL_INVALID_ENUM
,
2092 "glTexImage%dD(target can't be compressed)", dimensions
);
2095 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2096 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2097 "glTexImage%dD(no compression for format)", dimensions
);
2101 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2102 "glTexImage%dD(border!=0)", dimensions
);
2107 /* additional checks for integer textures */
2108 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2109 (_mesa_is_enum_format_integer(format
) !=
2110 _mesa_is_enum_format_integer(internalFormat
))) {
2111 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2112 "glTexImage%dD(integer/non-integer format mismatch)",
2117 if (!mutable_tex_object(ctx
, target
)) {
2118 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2119 "glTexImage%dD(immutable texture)", dimensions
);
2123 /* if we get here, the parameters are OK */
2129 * Error checking for glCompressedTexImage[123]D().
2130 * Note that the width, height and depth values are not fully error checked
2132 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2135 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2136 GLenum target
, GLint level
,
2137 GLenum internalFormat
, GLsizei width
,
2138 GLsizei height
, GLsizei depth
, GLint border
,
2141 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2143 GLenum error
= GL_NO_ERROR
;
2144 char *reason
= ""; /* no error */
2146 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2148 error
= GL_INVALID_ENUM
;
2152 /* This will detect any invalid internalFormat value */
2153 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2154 reason
= "internalFormat";
2155 error
= GL_INVALID_ENUM
;
2159 switch (internalFormat
) {
2160 case GL_PALETTE4_RGB8_OES
:
2161 case GL_PALETTE4_RGBA8_OES
:
2162 case GL_PALETTE4_R5_G6_B5_OES
:
2163 case GL_PALETTE4_RGBA4_OES
:
2164 case GL_PALETTE4_RGB5_A1_OES
:
2165 case GL_PALETTE8_RGB8_OES
:
2166 case GL_PALETTE8_RGBA8_OES
:
2167 case GL_PALETTE8_R5_G6_B5_OES
:
2168 case GL_PALETTE8_RGBA4_OES
:
2169 case GL_PALETTE8_RGB5_A1_OES
:
2170 /* check level (note that level should be zero or less!) */
2171 if (level
> 0 || level
< -maxLevels
) {
2173 error
= GL_INVALID_VALUE
;
2177 if (dimensions
!= 2) {
2178 reason
= "compressed paletted textures must be 2D";
2179 error
= GL_INVALID_OPERATION
;
2183 /* Figure out the expected texture size (in bytes). This will be
2184 * checked against the actual size later.
2186 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2189 /* This is for the benefit of the TestProxyTexImage below. It expects
2190 * level to be non-negative. OES_compressed_paletted_texture uses a
2191 * weird mechanism where the level specified to glCompressedTexImage2D
2192 * is -(n-1) number of levels in the texture, and the data specifies the
2193 * complete mipmap stack. This is done to ensure the palette is the
2194 * same for all levels.
2201 if (level
< 0 || level
>= maxLevels
) {
2203 error
= GL_INVALID_VALUE
;
2207 /* Figure out the expected texture size (in bytes). This will be
2208 * checked against the actual size later.
2210 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2214 /* This should really never fail */
2215 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2216 reason
= "internalFormat";
2217 error
= GL_INVALID_ENUM
;
2221 /* No compressed formats support borders at this time */
2223 reason
= "border != 0";
2224 error
= GL_INVALID_VALUE
;
2228 /* check image size in bytes */
2229 if (expectedSize
!= imageSize
) {
2230 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2231 * if <imageSize> is not consistent with the format, dimensions, and
2232 * contents of the specified image.
2234 reason
= "imageSize inconsistant with width/height/format";
2235 error
= GL_INVALID_VALUE
;
2239 if (!mutable_tex_object(ctx
, target
)) {
2240 reason
= "immutable texture";
2241 error
= GL_INVALID_OPERATION
;
2248 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2255 * Test glTexSubImage[123]D() parameters for errors.
2257 * \param ctx GL context.
2258 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2259 * \param target texture target given by the user (already validated)
2260 * \param level image level given by the user.
2261 * \param xoffset sub-image x offset given by the user.
2262 * \param yoffset sub-image y offset given by the user.
2263 * \param zoffset sub-image z offset given by the user.
2264 * \param format pixel data format given by the user.
2265 * \param type pixel data type given by the user.
2266 * \param width image width given by the user.
2267 * \param height image height given by the user.
2268 * \param depth image depth given by the user.
2270 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2272 * Verifies each of the parameters against the constants specified in
2273 * __struct gl_contextRec::Const and the supported extensions, and according
2274 * to the OpenGL specification.
2277 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2278 GLenum target
, GLint level
,
2279 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2280 GLint width
, GLint height
, GLint depth
,
2281 GLenum format
, GLenum type
)
2283 struct gl_texture_object
*texObj
;
2284 struct gl_texture_image
*texImage
;
2287 /* check target (proxies not allowed) */
2288 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2289 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2290 dimensions
, _mesa_lookup_enum_by_nr(target
));
2295 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2296 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2301 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2302 * combinations of format and type that can be used. Formats and types
2303 * that require additional extensions (e.g., GL_FLOAT requires
2304 * GL_OES_texture_float) are filtered elsewhere.
2306 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2307 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2308 if (err
!= GL_NO_ERROR
) {
2309 _mesa_error(ctx
, err
,
2310 "glTexSubImage%dD(format = %s, type = %s)",
2312 _mesa_lookup_enum_by_nr(format
),
2313 _mesa_lookup_enum_by_nr(type
));
2318 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2319 if (err
!= GL_NO_ERROR
) {
2320 _mesa_error(ctx
, err
,
2321 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2322 dimensions
, _mesa_lookup_enum_by_nr(format
),
2323 _mesa_lookup_enum_by_nr(type
));
2327 /* Get dest texture object / image pointers */
2328 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2330 /* must be out of memory */
2331 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2335 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2337 /* non-existant texture level */
2338 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2339 "glTexSubImage%dD(invalid texture image)", dimensions
);
2343 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2344 texImage
, xoffset
, yoffset
, 0,
2345 width
, height
, 1)) {
2349 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2350 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2351 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2352 "glTexSubImage%dD(no compression for format)", dimensions
);
2357 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2358 /* both source and dest must be integer-valued, or neither */
2359 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2360 _mesa_is_enum_format_integer(format
)) {
2361 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2362 "glTexSubImage%dD(integer/non-integer format mismatch)",
2373 * Test glCopyTexImage[12]D() parameters for errors.
2375 * \param ctx GL context.
2376 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2377 * \param target texture target given by the user.
2378 * \param level image level given by the user.
2379 * \param internalFormat internal format given by the user.
2380 * \param width image width given by the user.
2381 * \param height image height given by the user.
2382 * \param border texture border.
2384 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2386 * Verifies each of the parameters against the constants specified in
2387 * __struct gl_contextRec::Const and the supported extensions, and according
2388 * to the OpenGL specification.
2391 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2392 GLenum target
, GLint level
, GLint internalFormat
,
2393 GLint width
, GLint height
, GLint border
)
2396 GLint rb_base_format
;
2397 struct gl_renderbuffer
*rb
;
2398 GLenum rb_internal_format
;
2401 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2402 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2403 dimensions
, _mesa_lookup_enum_by_nr(target
));
2408 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2409 _mesa_error(ctx
, GL_INVALID_VALUE
,
2410 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2414 /* Check that the source buffer is complete */
2415 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2416 if (ctx
->ReadBuffer
->_Status
== 0) {
2417 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2419 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2420 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2421 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2425 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2426 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2427 "glCopyTexImage%dD(multisample FBO)",
2434 if (border
< 0 || border
> 1 ||
2435 ((ctx
->API
!= API_OPENGL_COMPAT
||
2436 target
== GL_TEXTURE_RECTANGLE_NV
||
2437 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2438 _mesa_error(ctx
, GL_INVALID_VALUE
,
2439 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2443 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2445 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2446 "glCopyTexImage%dD(read buffer)", dimensions
);
2450 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2453 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2454 switch (internalFormat
) {
2459 case GL_LUMINANCE_ALPHA
:
2462 _mesa_error(ctx
, GL_INVALID_VALUE
,
2463 "glCopyTexImage%dD(internalFormat)", dimensions
);
2468 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2469 if (baseFormat
< 0) {
2470 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2471 "glCopyTexImage%dD(internalFormat)", dimensions
);
2475 rb_internal_format
= rb
->InternalFormat
;
2476 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2477 if (_mesa_is_color_format(internalFormat
)) {
2478 if (rb_base_format
< 0) {
2479 _mesa_error(ctx
, GL_INVALID_VALUE
,
2480 "glCopyTexImage%dD(internalFormat)", dimensions
);
2485 if (_mesa_is_gles(ctx
)) {
2487 if (_mesa_base_format_component_count(baseFormat
) >
2488 _mesa_base_format_component_count(rb_base_format
)) {
2491 if (baseFormat
== GL_DEPTH_COMPONENT
||
2492 baseFormat
== GL_DEPTH_STENCIL
||
2493 rb_base_format
== GL_DEPTH_COMPONENT
||
2494 rb_base_format
== GL_DEPTH_STENCIL
||
2495 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2496 baseFormat
== GL_ALPHA
) &&
2497 rb_base_format
!= GL_RGBA
) ||
2498 internalFormat
== GL_RGB9_E5
) {
2501 if (internalFormat
== GL_RGB9_E5
) {
2505 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2506 "glCopyTexImage%dD(internalFormat)", dimensions
);
2511 if (_mesa_is_gles3(ctx
)) {
2512 bool rb_is_srgb
= false;
2513 bool dst_is_srgb
= false;
2515 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2516 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2520 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2524 if (rb_is_srgb
!= dst_is_srgb
) {
2525 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2526 * OpenGLES 3.0.0 spec says:
2528 * "The error INVALID_OPERATION is also generated if the
2529 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2530 * framebuffer attachment corresponding to the read buffer
2531 * is LINEAR (see section 6.1.13) and internalformat is
2532 * one of the sRGB formats described in section 3.8.16, or
2533 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2534 * SRGB and internalformat is not one of the sRGB formats."
2536 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2537 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2542 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2543 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2544 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2548 /* From the EXT_texture_integer spec:
2550 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2551 * if the texture internalformat is an integer format and the read color
2552 * buffer is not an integer format, or if the internalformat is not an
2553 * integer format and the read color buffer is an integer format."
2555 if (_mesa_is_color_format(internalFormat
)) {
2556 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2557 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2558 if (is_int
|| is_rbint
) {
2559 if (is_int
!= is_rbint
) {
2560 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2561 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2563 } else if (_mesa_is_gles(ctx
) &&
2564 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2565 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2566 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2567 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2573 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2574 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2575 _mesa_error(ctx
, GL_INVALID_ENUM
,
2576 "glCopyTexImage%dD(target)", dimensions
);
2579 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2580 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2581 "glCopyTexImage%dD(no compression for format)", dimensions
);
2585 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2586 "glCopyTexImage%dD(border!=0)", dimensions
);
2591 if (!mutable_tex_object(ctx
, target
)) {
2592 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2593 "glCopyTexImage%dD(immutable texture)", dimensions
);
2597 /* if we get here, the parameters are OK */
2603 * Test glCopyTexSubImage[12]D() parameters for errors.
2604 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2607 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2608 GLenum target
, GLint level
,
2609 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2610 GLint width
, GLint height
)
2612 struct gl_texture_object
*texObj
;
2613 struct gl_texture_image
*texImage
;
2615 /* Check that the source buffer is complete */
2616 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2617 if (ctx
->ReadBuffer
->_Status
== 0) {
2618 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2620 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2621 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2622 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2626 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2627 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2628 "glCopyTexSubImage%dD(multisample FBO)",
2634 /* check target (proxies not allowed) */
2635 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2636 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2637 dimensions
, _mesa_lookup_enum_by_nr(target
));
2642 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2643 _mesa_error(ctx
, GL_INVALID_VALUE
,
2644 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2648 /* Get dest texture object / image pointers */
2649 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2651 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2655 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2657 /* destination image does not exist */
2658 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2659 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2663 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2664 dimensions
, texImage
,
2665 xoffset
, yoffset
, zoffset
,
2666 width
, height
, 1)) {
2670 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2671 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2672 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2673 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2678 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2679 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2683 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2684 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2685 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2686 dimensions
, texImage
->_BaseFormat
);
2690 /* From the EXT_texture_integer spec:
2692 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2693 * if the texture internalformat is an integer format and the read color
2694 * buffer is not an integer format, or if the internalformat is not an
2695 * integer format and the read color buffer is an integer format."
2697 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2698 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2700 if (_mesa_is_format_integer_color(rb
->Format
) !=
2701 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2702 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2703 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2708 /* if we get here, the parameters are OK */
2713 /** Callback info for walking over FBO hash table */
2716 struct gl_context
*ctx
;
2717 struct gl_texture_object
*texObj
;
2723 * Check render to texture callback. Called from _mesa_HashWalk().
2726 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2728 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2729 const struct cb_info
*info
= (struct cb_info
*) userData
;
2730 struct gl_context
*ctx
= info
->ctx
;
2731 const struct gl_texture_object
*texObj
= info
->texObj
;
2732 const GLuint level
= info
->level
, face
= info
->face
;
2734 /* If this is a user-created FBO */
2735 if (_mesa_is_user_fbo(fb
)) {
2737 /* check if any of the FBO's attachments point to 'texObj' */
2738 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2739 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2740 if (att
->Type
== GL_TEXTURE
&&
2741 att
->Texture
== texObj
&&
2742 att
->TextureLevel
== level
&&
2743 att
->CubeMapFace
== face
) {
2744 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2745 ASSERT(att
->Renderbuffer
->TexImage
);
2746 /* Mark fb status as indeterminate to force re-validation */
2755 * When a texture image is specified we have to check if it's bound to
2756 * any framebuffer objects (render to texture) in order to detect changes
2757 * in size or format since that effects FBO completeness.
2758 * Any FBOs rendering into the texture must be re-validated.
2761 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2762 struct gl_texture_object
*texObj
,
2763 GLuint face
, GLuint level
)
2765 /* Only check this texture if it's been marked as RenderToTexture */
2766 if (texObj
->_RenderToTexture
) {
2767 struct cb_info info
;
2769 info
.texObj
= texObj
;
2772 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2778 * If the texture object's GenerateMipmap flag is set and we've
2779 * changed the texture base level image, regenerate the rest of the
2780 * mipmap levels now.
2783 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2784 struct gl_texture_object
*texObj
, GLint level
)
2786 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2787 if (texObj
->GenerateMipmap
&&
2788 level
== texObj
->BaseLevel
&&
2789 level
< texObj
->MaxLevel
) {
2790 ASSERT(ctx
->Driver
.GenerateMipmap
);
2791 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2796 /** Debug helper: override the user-requested internal format */
2798 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2801 if (internalFormat
== GL_RGBA16F_ARB
||
2802 internalFormat
== GL_RGBA32F_ARB
) {
2803 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2806 else if (internalFormat
== GL_RGB16F_ARB
||
2807 internalFormat
== GL_RGB32F_ARB
) {
2808 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2811 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2812 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2813 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2814 return GL_LUMINANCE_ALPHA
;
2816 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2817 internalFormat
== GL_LUMINANCE32F_ARB
) {
2818 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2819 return GL_LUMINANCE
;
2821 else if (internalFormat
== GL_ALPHA16F_ARB
||
2822 internalFormat
== GL_ALPHA32F_ARB
) {
2823 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2827 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2828 internalFormat = GL_RGBA;
2832 return internalFormat
;
2835 return internalFormat
;
2841 * Choose the actual hardware format for a texture image.
2842 * Try to use the same format as the previous image level when possible.
2843 * Otherwise, ask the driver for the best format.
2844 * It's important to try to choose a consistant format for all levels
2845 * for efficient texture memory layout/allocation. In particular, this
2846 * comes up during automatic mipmap generation.
2849 _mesa_choose_texture_format(struct gl_context
*ctx
,
2850 struct gl_texture_object
*texObj
,
2851 GLenum target
, GLint level
,
2852 GLenum internalFormat
, GLenum format
, GLenum type
)
2856 /* see if we've already chosen a format for the previous level */
2858 struct gl_texture_image
*prevImage
=
2859 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2860 /* See if the prev level is defined and has an internal format which
2861 * matches the new internal format.
2864 prevImage
->Width
> 0 &&
2865 prevImage
->InternalFormat
== internalFormat
) {
2866 /* use the same format */
2867 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2868 return prevImage
->TexFormat
;
2872 /* If the application requested compression to an S3TC format but we don't
2873 * have the DTXn library, force a generic compressed format instead.
2875 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2876 const GLenum before
= internalFormat
;
2878 switch (internalFormat
) {
2879 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2880 if (!ctx
->Mesa_DXTn
)
2881 internalFormat
= GL_COMPRESSED_RGB
;
2883 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2884 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2885 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2886 if (!ctx
->Mesa_DXTn
)
2887 internalFormat
= GL_COMPRESSED_RGBA
;
2893 if (before
!= internalFormat
) {
2895 "DXT compression requested (%s), "
2896 "but libtxc_dxtn library not installed. Using %s "
2898 _mesa_lookup_enum_by_nr(before
),
2899 _mesa_lookup_enum_by_nr(internalFormat
));
2903 /* choose format from scratch */
2904 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2906 ASSERT(f
!= MESA_FORMAT_NONE
);
2912 * Adjust pixel unpack params and image dimensions to strip off the
2913 * one-pixel texture border.
2915 * Gallium and intel don't support texture borders. They've seldem been used
2916 * and seldom been implemented correctly anyway.
2918 * \param unpackNew returns the new pixel unpack parameters
2921 strip_texture_border(GLenum target
,
2922 GLint
*width
, GLint
*height
, GLint
*depth
,
2923 const struct gl_pixelstore_attrib
*unpack
,
2924 struct gl_pixelstore_attrib
*unpackNew
)
2930 *unpackNew
= *unpack
;
2932 if (unpackNew
->RowLength
== 0)
2933 unpackNew
->RowLength
= *width
;
2935 if (unpackNew
->ImageHeight
== 0)
2936 unpackNew
->ImageHeight
= *height
;
2938 assert(*width
>= 3);
2939 unpackNew
->SkipPixels
++; /* skip the border */
2940 *width
= *width
- 2; /* reduce the width by two border pixels */
2942 /* The min height of a texture with a border is 3 */
2943 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2944 unpackNew
->SkipRows
++; /* skip the border */
2945 *height
= *height
- 2; /* reduce the height by two border pixels */
2949 target
!= GL_TEXTURE_2D_ARRAY
&&
2950 target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2951 unpackNew
->SkipImages
++; /* skip the border */
2952 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2958 * Common code to implement all the glTexImage1D/2D/3D functions
2959 * as well as glCompressedTexImage1D/2D/3D.
2960 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2961 * \param format the user's image format (only used if !compressed)
2962 * \param type the user's image type (only used if !compressed)
2963 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2966 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2967 GLenum target
, GLint level
, GLint internalFormat
,
2968 GLsizei width
, GLsizei height
, GLsizei depth
,
2969 GLint border
, GLenum format
, GLenum type
,
2970 GLsizei imageSize
, const GLvoid
*pixels
)
2972 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2973 struct gl_pixelstore_attrib unpack_no_border
;
2974 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2975 struct gl_texture_object
*texObj
;
2976 gl_format texFormat
;
2977 GLboolean dimensionsOK
, sizeOK
;
2979 FLUSH_VERTICES(ctx
, 0);
2981 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2984 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
2986 _mesa_lookup_enum_by_nr(target
), level
,
2987 _mesa_lookup_enum_by_nr(internalFormat
),
2988 width
, height
, depth
, border
, pixels
);
2991 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
2993 _mesa_lookup_enum_by_nr(target
), level
,
2994 _mesa_lookup_enum_by_nr(internalFormat
),
2995 width
, height
, depth
, border
,
2996 _mesa_lookup_enum_by_nr(format
),
2997 _mesa_lookup_enum_by_nr(type
), pixels
);
3000 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3002 /* target error checking */
3003 if (!legal_teximage_target(ctx
, dims
, target
)) {
3004 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3005 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3009 /* general error checking */
3011 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3013 width
, height
, depth
,
3018 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3019 format
, type
, width
, height
, depth
, border
))
3023 /* Here we convert a cpal compressed image into a regular glTexImage2D
3024 * call by decompressing the texture. If we really want to support cpal
3025 * textures in any driver this would have to be changed.
3027 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3028 switch (internalFormat
) {
3029 case GL_PALETTE4_RGB8_OES
:
3030 case GL_PALETTE4_RGBA8_OES
:
3031 case GL_PALETTE4_R5_G6_B5_OES
:
3032 case GL_PALETTE4_RGBA4_OES
:
3033 case GL_PALETTE4_RGB5_A1_OES
:
3034 case GL_PALETTE8_RGB8_OES
:
3035 case GL_PALETTE8_RGBA8_OES
:
3036 case GL_PALETTE8_R5_G6_B5_OES
:
3037 case GL_PALETTE8_RGBA4_OES
:
3038 case GL_PALETTE8_RGB5_A1_OES
:
3039 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3040 width
, height
, imageSize
, pixels
);
3045 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3049 /* For glCompressedTexImage() the driver has no choice about the
3050 * texture format since we'll never transcode the user's compressed
3051 * image data. The internalFormat was error checked earlier.
3053 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3056 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3057 internalFormat
, format
, type
);
3060 assert(texFormat
!= MESA_FORMAT_NONE
);
3062 /* check that width, height, depth are legal for the mipmap level */
3063 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3064 height
, depth
, border
);
3066 /* check that the texture won't take too much memory, etc */
3067 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3069 width
, height
, depth
, border
);
3071 if (_mesa_is_proxy_texture(target
)) {
3072 /* Proxy texture: just clear or set state depending on error checking */
3073 struct gl_texture_image
*texImage
=
3074 get_proxy_tex_image(ctx
, target
, level
);
3077 return; /* GL_OUT_OF_MEMORY already recorded */
3079 if (dimensionsOK
&& sizeOK
) {
3080 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3081 border
, internalFormat
, texFormat
);
3084 clear_teximage_fields(texImage
);
3088 /* non-proxy target */
3089 const GLuint face
= _mesa_tex_target_to_face(target
);
3090 struct gl_texture_image
*texImage
;
3092 if (!dimensionsOK
) {
3093 _mesa_error(ctx
, GL_INVALID_VALUE
,
3094 "glTexImage%uD(invalid width or height or depth)",
3100 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3101 "glTexImage%uD(image too large)", dims
);
3105 /* Allow a hardware driver to just strip out the border, to provide
3106 * reliable but slightly incorrect hardware rendering instead of
3107 * rarely-tested software fallback rendering.
3109 if (border
&& ctx
->Const
.StripTextureBorder
) {
3110 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3113 unpack
= &unpack_no_border
;
3116 if (ctx
->NewState
& _NEW_PIXEL
)
3117 _mesa_update_state(ctx
);
3119 _mesa_lock_texture(ctx
, texObj
);
3121 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3124 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3127 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3129 _mesa_init_teximage_fields(ctx
, texImage
,
3130 width
, height
, depth
,
3131 border
, internalFormat
, texFormat
);
3133 /* Give the texture to the driver. <pixels> may be null. */
3134 if (width
> 0 && height
> 0 && depth
> 0) {
3136 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3140 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3141 type
, pixels
, unpack
);
3145 check_gen_mipmap(ctx
, target
, texObj
, level
);
3147 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3149 _mesa_dirty_texobj(ctx
, texObj
);
3152 _mesa_unlock_texture(ctx
, texObj
);
3159 * Called from the API. Note that width includes the border.
3162 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3163 GLsizei width
, GLint border
, GLenum format
,
3164 GLenum type
, const GLvoid
*pixels
)
3166 GET_CURRENT_CONTEXT(ctx
);
3167 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3168 border
, format
, type
, 0, pixels
);
3173 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3174 GLsizei width
, GLsizei height
, GLint border
,
3175 GLenum format
, GLenum type
,
3176 const GLvoid
*pixels
)
3178 GET_CURRENT_CONTEXT(ctx
);
3179 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3180 border
, format
, type
, 0, pixels
);
3185 * Called by the API or display list executor.
3186 * Note that width and height include the border.
3189 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3190 GLsizei width
, GLsizei height
, GLsizei depth
,
3191 GLint border
, GLenum format
, GLenum type
,
3192 const GLvoid
*pixels
)
3194 GET_CURRENT_CONTEXT(ctx
);
3195 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3196 width
, height
, depth
,
3197 border
, format
, type
, 0, pixels
);
3202 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3203 GLsizei width
, GLsizei height
, GLsizei depth
,
3204 GLint border
, GLenum format
, GLenum type
,
3205 const GLvoid
*pixels
)
3207 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3208 depth
, border
, format
, type
, pixels
);
3213 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3215 struct gl_texture_object
*texObj
;
3216 struct gl_texture_image
*texImage
;
3218 GET_CURRENT_CONTEXT(ctx
);
3219 FLUSH_VERTICES(ctx
, 0);
3223 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3225 case GL_TEXTURE_EXTERNAL_OES
:
3227 _mesa_is_gles(ctx
) ? ctx
->Extensions
.OES_EGL_image_external
: false;
3230 valid_target
= false;
3234 if (!valid_target
) {
3235 _mesa_error(ctx
, GL_INVALID_ENUM
,
3236 "glEGLImageTargetTexture2D(target=%d)", target
);
3241 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3242 "glEGLImageTargetTexture2D(image=%p)", image
);
3246 if (ctx
->NewState
& _NEW_PIXEL
)
3247 _mesa_update_state(ctx
);
3249 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3250 _mesa_lock_texture(ctx
, texObj
);
3252 if (texObj
->Immutable
) {
3253 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3254 "glEGLImageTargetTexture2D(texture is immutable)");
3255 _mesa_unlock_texture(ctx
, texObj
);
3259 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3261 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3263 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3265 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3266 texObj
, texImage
, image
);
3268 _mesa_dirty_texobj(ctx
, texObj
);
3270 _mesa_unlock_texture(ctx
, texObj
);
3277 * Implement all the glTexSubImage1/2/3D() functions.
3280 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3281 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3282 GLsizei width
, GLsizei height
, GLsizei depth
,
3283 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3285 struct gl_texture_object
*texObj
;
3286 struct gl_texture_image
*texImage
;
3288 FLUSH_VERTICES(ctx
, 0);
3290 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3291 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3293 _mesa_lookup_enum_by_nr(target
), level
,
3294 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3295 _mesa_lookup_enum_by_nr(format
),
3296 _mesa_lookup_enum_by_nr(type
), pixels
);
3298 /* check target (proxies not allowed) */
3299 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3300 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3301 dims
, _mesa_lookup_enum_by_nr(target
));
3305 if (ctx
->NewState
& _NEW_PIXEL
)
3306 _mesa_update_state(ctx
);
3308 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3309 xoffset
, yoffset
, zoffset
,
3310 width
, height
, depth
, format
, type
)) {
3311 return; /* error was detected */
3314 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3316 _mesa_lock_texture(ctx
, texObj
);
3318 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3320 if (width
> 0 && height
> 0 && depth
> 0) {
3321 /* If we have a border, offset=-1 is legal. Bias by border width. */
3324 if (target
!= GL_TEXTURE_2D_ARRAY
)
3325 zoffset
+= texImage
->Border
;
3328 if (target
!= GL_TEXTURE_1D_ARRAY
)
3329 yoffset
+= texImage
->Border
;
3332 xoffset
+= texImage
->Border
;
3335 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3336 xoffset
, yoffset
, zoffset
,
3337 width
, height
, depth
,
3338 format
, type
, pixels
, &ctx
->Unpack
);
3340 check_gen_mipmap(ctx
, target
, texObj
, level
);
3342 ctx
->NewState
|= _NEW_TEXTURE
;
3345 _mesa_unlock_texture(ctx
, texObj
);
3350 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3351 GLint xoffset
, GLsizei width
,
3352 GLenum format
, GLenum type
,
3353 const GLvoid
*pixels
)
3355 GET_CURRENT_CONTEXT(ctx
);
3356 texsubimage(ctx
, 1, target
, level
,
3359 format
, type
, pixels
);
3364 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3365 GLint xoffset
, GLint yoffset
,
3366 GLsizei width
, GLsizei height
,
3367 GLenum format
, GLenum type
,
3368 const GLvoid
*pixels
)
3370 GET_CURRENT_CONTEXT(ctx
);
3371 texsubimage(ctx
, 2, target
, level
,
3372 xoffset
, yoffset
, 0,
3374 format
, type
, pixels
);
3380 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3381 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3382 GLsizei width
, GLsizei height
, GLsizei depth
,
3383 GLenum format
, GLenum type
,
3384 const GLvoid
*pixels
)
3386 GET_CURRENT_CONTEXT(ctx
);
3387 texsubimage(ctx
, 3, target
, level
,
3388 xoffset
, yoffset
, zoffset
,
3389 width
, height
, depth
,
3390 format
, type
, pixels
);
3396 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3397 * from. This depends on whether the texture contains color or depth values.
3399 static struct gl_renderbuffer
*
3400 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3402 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3403 /* reading from depth/stencil buffer */
3404 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3407 /* copying from color buffer */
3408 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3413 copytexsubimage_by_slice(struct gl_context
*ctx
,
3414 struct gl_texture_image
*texImage
,
3416 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3417 struct gl_renderbuffer
*rb
,
3419 GLsizei width
, GLsizei height
)
3421 if (texImage
->TexObject
->Target
== GL_TEXTURE_1D_ARRAY
) {
3424 /* For 1D arrays, we copy each scanline of the source rectangle into the
3427 assert(zoffset
== 0);
3429 for (slice
= 0; slice
< height
; slice
++) {
3430 assert(yoffset
+ slice
< texImage
->Height
);
3431 ctx
->Driver
.CopyTexSubImage(ctx
, 2, texImage
,
3432 xoffset
, 0, yoffset
+ slice
,
3433 rb
, x
, y
+ slice
, width
, 1);
3436 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3437 xoffset
, yoffset
, zoffset
,
3438 rb
, x
, y
, width
, height
);
3444 * Implement the glCopyTexImage1/2D() functions.
3447 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3448 GLenum target
, GLint level
, GLenum internalFormat
,
3449 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3451 struct gl_texture_object
*texObj
;
3452 struct gl_texture_image
*texImage
;
3453 const GLuint face
= _mesa_tex_target_to_face(target
);
3454 gl_format texFormat
;
3456 FLUSH_VERTICES(ctx
, 0);
3458 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3459 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3461 _mesa_lookup_enum_by_nr(target
), level
,
3462 _mesa_lookup_enum_by_nr(internalFormat
),
3463 x
, y
, width
, height
, border
);
3465 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3466 _mesa_update_state(ctx
);
3468 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3469 width
, height
, border
))
3472 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3474 _mesa_error(ctx
, GL_INVALID_VALUE
,
3475 "glCopyTexImage%uD(invalid width or height)", dims
);
3479 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3482 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3483 internalFormat
, GL_NONE
, GL_NONE
);
3484 assert(texFormat
!= MESA_FORMAT_NONE
);
3486 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3488 width
, height
, 1, border
)) {
3489 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3490 "glCopyTexImage%uD(image too large)", dims
);
3494 if (border
&& ctx
->Const
.StripTextureBorder
) {
3496 width
-= border
* 2;
3499 height
-= border
* 2;
3504 _mesa_lock_texture(ctx
, texObj
);
3506 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3509 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3512 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3514 /* Free old texture image */
3515 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3517 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3518 border
, internalFormat
, texFormat
);
3520 if (width
&& height
) {
3521 /* Allocate texture memory (no pixel data yet) */
3522 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3524 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3526 struct gl_renderbuffer
*srcRb
=
3527 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3529 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3531 srcRb
, srcX
, srcY
, width
, height
);
3534 check_gen_mipmap(ctx
, target
, texObj
, level
);
3537 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3539 _mesa_dirty_texobj(ctx
, texObj
);
3542 _mesa_unlock_texture(ctx
, texObj
);
3548 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3549 GLenum internalFormat
,
3551 GLsizei width
, GLint border
)
3553 GET_CURRENT_CONTEXT(ctx
);
3554 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3560 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3561 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3564 GET_CURRENT_CONTEXT(ctx
);
3565 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3566 x
, y
, width
, height
, border
);
3572 * Implementation for glCopyTexSubImage1/2/3D() functions.
3575 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3576 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3577 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3579 struct gl_texture_object
*texObj
;
3580 struct gl_texture_image
*texImage
;
3582 FLUSH_VERTICES(ctx
, 0);
3584 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3585 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3587 _mesa_lookup_enum_by_nr(target
),
3588 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3590 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3591 _mesa_update_state(ctx
);
3593 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3594 xoffset
, yoffset
, zoffset
, width
, height
)) {
3598 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3600 _mesa_lock_texture(ctx
, texObj
);
3602 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3604 /* If we have a border, offset=-1 is legal. Bias by border width. */
3607 if (target
!= GL_TEXTURE_2D_ARRAY
)
3608 zoffset
+= texImage
->Border
;
3611 if (target
!= GL_TEXTURE_1D_ARRAY
)
3612 yoffset
+= texImage
->Border
;
3615 xoffset
+= texImage
->Border
;
3618 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3620 struct gl_renderbuffer
*srcRb
=
3621 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3623 copytexsubimage_by_slice(ctx
, texImage
, dims
,
3624 xoffset
, yoffset
, zoffset
,
3625 srcRb
, x
, y
, width
, height
);
3627 check_gen_mipmap(ctx
, target
, texObj
, level
);
3629 ctx
->NewState
|= _NEW_TEXTURE
;
3632 _mesa_unlock_texture(ctx
, texObj
);
3637 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3638 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3640 GET_CURRENT_CONTEXT(ctx
);
3641 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3647 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3648 GLint xoffset
, GLint yoffset
,
3649 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3651 GET_CURRENT_CONTEXT(ctx
);
3652 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3659 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3660 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3661 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3663 GET_CURRENT_CONTEXT(ctx
);
3664 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3665 x
, y
, width
, height
);
3671 /**********************************************************************/
3672 /****** Compressed Textures ******/
3673 /**********************************************************************/
3677 * Error checking for glCompressedTexSubImage[123]D().
3678 * \return error code or GL_NO_ERROR.
3681 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3682 GLenum target
, GLint level
,
3683 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3684 GLsizei width
, GLsizei height
, GLsizei depth
,
3685 GLenum format
, GLsizei imageSize
)
3687 struct gl_texture_object
*texObj
;
3688 struct gl_texture_image
*texImage
;
3696 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3697 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3698 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3699 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3700 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3701 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3705 targetOK
= GL_FALSE
;
3710 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3714 /* no 1D compressed textures at this time */
3715 targetOK
= GL_FALSE
;
3720 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3725 /* this will catch any invalid compressed format token */
3726 if (!_mesa_is_compressed_format(ctx
, format
)) {
3727 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3732 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3733 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3738 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3739 if (expectedSize
!= imageSize
) {
3740 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3745 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3747 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3748 "glCompressedTexSubImage%uD()", dims
);
3752 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3754 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3755 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3759 if ((GLint
) format
!= texImage
->InternalFormat
) {
3760 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3761 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3765 if (compressedteximage_only_format(ctx
, format
)) {
3766 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3767 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3772 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3773 texImage
, xoffset
, yoffset
, zoffset
,
3774 width
, height
, depth
)) {
3783 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3784 GLenum internalFormat
, GLsizei width
,
3785 GLint border
, GLsizei imageSize
,
3788 GET_CURRENT_CONTEXT(ctx
);
3789 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3790 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3795 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3796 GLenum internalFormat
, GLsizei width
,
3797 GLsizei height
, GLint border
, GLsizei imageSize
,
3800 GET_CURRENT_CONTEXT(ctx
);
3801 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3802 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3807 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3808 GLenum internalFormat
, GLsizei width
,
3809 GLsizei height
, GLsizei depth
, GLint border
,
3810 GLsizei imageSize
, const GLvoid
*data
)
3812 GET_CURRENT_CONTEXT(ctx
);
3813 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3814 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3819 * Common helper for glCompressedTexSubImage1/2/3D().
3822 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3823 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3824 GLsizei width
, GLsizei height
, GLsizei depth
,
3825 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3827 struct gl_texture_object
*texObj
;
3828 struct gl_texture_image
*texImage
;
3829 GET_CURRENT_CONTEXT(ctx
);
3830 FLUSH_VERTICES(ctx
, 0);
3832 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3833 xoffset
, yoffset
, zoffset
,
3834 width
, height
, depth
,
3835 format
, imageSize
)) {
3839 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3841 _mesa_lock_texture(ctx
, texObj
);
3843 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3846 if (width
> 0 && height
> 0 && depth
> 0) {
3847 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3848 xoffset
, yoffset
, zoffset
,
3849 width
, height
, depth
,
3850 format
, imageSize
, data
);
3852 check_gen_mipmap(ctx
, target
, texObj
, level
);
3854 ctx
->NewState
|= _NEW_TEXTURE
;
3857 _mesa_unlock_texture(ctx
, texObj
);
3862 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3863 GLsizei width
, GLenum format
,
3864 GLsizei imageSize
, const GLvoid
*data
)
3866 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3867 format
, imageSize
, data
);
3872 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3873 GLint yoffset
, GLsizei width
, GLsizei height
,
3874 GLenum format
, GLsizei imageSize
,
3877 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3878 width
, height
, 1, format
, imageSize
, data
);
3883 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3884 GLint yoffset
, GLint zoffset
, GLsizei width
,
3885 GLsizei height
, GLsizei depth
, GLenum format
,
3886 GLsizei imageSize
, const GLvoid
*data
)
3888 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3889 width
, height
, depth
, format
, imageSize
, data
);
3893 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3895 switch (internalFormat
) {
3897 return MESA_FORMAT_A8
;
3899 return MESA_FORMAT_A16
;
3900 case GL_ALPHA16F_ARB
:
3901 return MESA_FORMAT_ALPHA_FLOAT16
;
3902 case GL_ALPHA32F_ARB
:
3903 return MESA_FORMAT_ALPHA_FLOAT32
;
3904 case GL_ALPHA8I_EXT
:
3905 return MESA_FORMAT_ALPHA_INT8
;
3906 case GL_ALPHA16I_EXT
:
3907 return MESA_FORMAT_ALPHA_INT16
;
3908 case GL_ALPHA32I_EXT
:
3909 return MESA_FORMAT_ALPHA_INT32
;
3910 case GL_ALPHA8UI_EXT
:
3911 return MESA_FORMAT_ALPHA_UINT8
;
3912 case GL_ALPHA16UI_EXT
:
3913 return MESA_FORMAT_ALPHA_UINT16
;
3914 case GL_ALPHA32UI_EXT
:
3915 return MESA_FORMAT_ALPHA_UINT32
;
3917 return MESA_FORMAT_L8
;
3918 case GL_LUMINANCE16
:
3919 return MESA_FORMAT_L16
;
3920 case GL_LUMINANCE16F_ARB
:
3921 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3922 case GL_LUMINANCE32F_ARB
:
3923 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3924 case GL_LUMINANCE8I_EXT
:
3925 return MESA_FORMAT_LUMINANCE_INT8
;
3926 case GL_LUMINANCE16I_EXT
:
3927 return MESA_FORMAT_LUMINANCE_INT16
;
3928 case GL_LUMINANCE32I_EXT
:
3929 return MESA_FORMAT_LUMINANCE_INT32
;
3930 case GL_LUMINANCE8UI_EXT
:
3931 return MESA_FORMAT_LUMINANCE_UINT8
;
3932 case GL_LUMINANCE16UI_EXT
:
3933 return MESA_FORMAT_LUMINANCE_UINT16
;
3934 case GL_LUMINANCE32UI_EXT
:
3935 return MESA_FORMAT_LUMINANCE_UINT32
;
3936 case GL_LUMINANCE8_ALPHA8
:
3937 return MESA_FORMAT_AL88
;
3938 case GL_LUMINANCE16_ALPHA16
:
3939 return MESA_FORMAT_AL1616
;
3940 case GL_LUMINANCE_ALPHA16F_ARB
:
3941 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3942 case GL_LUMINANCE_ALPHA32F_ARB
:
3943 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3944 case GL_LUMINANCE_ALPHA8I_EXT
:
3945 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3946 case GL_LUMINANCE_ALPHA16I_EXT
:
3947 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3948 case GL_LUMINANCE_ALPHA32I_EXT
:
3949 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3950 case GL_LUMINANCE_ALPHA8UI_EXT
:
3951 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3952 case GL_LUMINANCE_ALPHA16UI_EXT
:
3953 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3954 case GL_LUMINANCE_ALPHA32UI_EXT
:
3955 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3957 return MESA_FORMAT_I8
;
3958 case GL_INTENSITY16
:
3959 return MESA_FORMAT_I16
;
3960 case GL_INTENSITY16F_ARB
:
3961 return MESA_FORMAT_INTENSITY_FLOAT16
;
3962 case GL_INTENSITY32F_ARB
:
3963 return MESA_FORMAT_INTENSITY_FLOAT32
;
3964 case GL_INTENSITY8I_EXT
:
3965 return MESA_FORMAT_INTENSITY_INT8
;
3966 case GL_INTENSITY16I_EXT
:
3967 return MESA_FORMAT_INTENSITY_INT16
;
3968 case GL_INTENSITY32I_EXT
:
3969 return MESA_FORMAT_INTENSITY_INT32
;
3970 case GL_INTENSITY8UI_EXT
:
3971 return MESA_FORMAT_INTENSITY_UINT8
;
3972 case GL_INTENSITY16UI_EXT
:
3973 return MESA_FORMAT_INTENSITY_UINT16
;
3974 case GL_INTENSITY32UI_EXT
:
3975 return MESA_FORMAT_INTENSITY_UINT32
;
3977 return MESA_FORMAT_RGBA8888_REV
;
3979 return MESA_FORMAT_RGBA_16
;
3980 case GL_RGBA16F_ARB
:
3981 return MESA_FORMAT_RGBA_FLOAT16
;
3982 case GL_RGBA32F_ARB
:
3983 return MESA_FORMAT_RGBA_FLOAT32
;
3985 return MESA_FORMAT_RGBA_INT8
;
3986 case GL_RGBA16I_EXT
:
3987 return MESA_FORMAT_RGBA_INT16
;
3988 case GL_RGBA32I_EXT
:
3989 return MESA_FORMAT_RGBA_INT32
;
3990 case GL_RGBA8UI_EXT
:
3991 return MESA_FORMAT_RGBA_UINT8
;
3992 case GL_RGBA16UI_EXT
:
3993 return MESA_FORMAT_RGBA_UINT16
;
3994 case GL_RGBA32UI_EXT
:
3995 return MESA_FORMAT_RGBA_UINT32
;
3998 return MESA_FORMAT_GR88
;
4000 return MESA_FORMAT_GR1616
;
4002 return MESA_FORMAT_RG_FLOAT16
;
4004 return MESA_FORMAT_RG_FLOAT32
;
4006 return MESA_FORMAT_RG_INT8
;
4008 return MESA_FORMAT_RG_INT16
;
4010 return MESA_FORMAT_RG_INT32
;
4012 return MESA_FORMAT_RG_UINT8
;
4014 return MESA_FORMAT_RG_UINT16
;
4016 return MESA_FORMAT_RG_UINT32
;
4019 return MESA_FORMAT_R8
;
4021 return MESA_FORMAT_R16
;
4023 return MESA_FORMAT_R_FLOAT16
;
4025 return MESA_FORMAT_R_FLOAT32
;
4027 return MESA_FORMAT_R_INT8
;
4029 return MESA_FORMAT_R_INT16
;
4031 return MESA_FORMAT_R_INT32
;
4033 return MESA_FORMAT_R_UINT8
;
4035 return MESA_FORMAT_R_UINT16
;
4037 return MESA_FORMAT_R_UINT32
;
4040 return MESA_FORMAT_RGB_FLOAT32
;
4042 return MESA_FORMAT_RGB_UINT32
;
4044 return MESA_FORMAT_RGB_INT32
;
4047 return MESA_FORMAT_NONE
;
4053 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4055 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4058 if (format
== MESA_FORMAT_NONE
)
4059 return MESA_FORMAT_NONE
;
4061 datatype
= _mesa_get_format_datatype(format
);
4062 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4063 return MESA_FORMAT_NONE
;
4065 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4066 return MESA_FORMAT_NONE
;
4068 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
4069 * any mention of R/RG formats, but they appear in the GL 3.1 core
4072 if (ctx
->Version
<= 30) {
4073 GLenum base_format
= _mesa_get_format_base_format(format
);
4075 if (base_format
== GL_R
|| base_format
== GL_RG
)
4076 return MESA_FORMAT_NONE
;
4079 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4080 GLenum base_format
= _mesa_get_format_base_format(format
);
4081 if (base_format
== GL_RGB
)
4082 return MESA_FORMAT_NONE
;
4089 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4090 struct gl_buffer_object
*bufObj
,
4091 GLintptr offset
, GLsizeiptr size
)
4093 struct gl_texture_object
*texObj
;
4096 FLUSH_VERTICES(ctx
, 0);
4098 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4099 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4103 format
= validate_texbuffer_format(ctx
, internalFormat
);
4104 if (format
== MESA_FORMAT_NONE
) {
4105 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4110 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4112 _mesa_lock_texture(ctx
, texObj
);
4114 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4115 texObj
->BufferObjectFormat
= internalFormat
;
4116 texObj
->_BufferObjectFormat
= format
;
4117 texObj
->BufferOffset
= offset
;
4118 texObj
->BufferSize
= size
;
4120 _mesa_unlock_texture(ctx
, texObj
);
4124 /** GL_ARB_texture_buffer_object */
4126 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4128 struct gl_buffer_object
*bufObj
;
4130 GET_CURRENT_CONTEXT(ctx
);
4132 /* NOTE: ARB_texture_buffer_object has interactions with
4133 * the compatibility profile that are not implemented.
4135 if (!(ctx
->API
== API_OPENGL_CORE
&&
4136 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4137 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4141 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4142 if (!bufObj
&& buffer
) {
4143 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4147 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4151 /** GL_ARB_texture_buffer_range */
4153 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4154 GLintptr offset
, GLsizeiptr size
)
4156 struct gl_buffer_object
*bufObj
;
4158 GET_CURRENT_CONTEXT(ctx
);
4160 if (!(ctx
->API
== API_OPENGL_CORE
&&
4161 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4162 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4166 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4170 (offset
+ size
) > bufObj
->Size
) {
4171 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4174 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4175 _mesa_error(ctx
, GL_INVALID_VALUE
,
4176 "glTexBufferRange(invalid offset alignment)");
4179 } else if (buffer
) {
4180 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4188 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4193 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4195 /* Everything that is allowed for renderbuffers,
4196 * except for a base format of GL_STENCIL_INDEX.
4198 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4199 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4203 /** GL_ARB_texture_multisample */
4205 check_multisample_target(GLuint dims
, GLenum target
)
4208 case GL_TEXTURE_2D_MULTISAMPLE
:
4209 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4212 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4213 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4223 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4224 GLint internalformat
, GLsizei width
, GLsizei height
,
4225 GLsizei depth
, GLboolean fixedsamplelocations
,
4226 GLboolean immutable
, const char *func
)
4228 struct gl_texture_object
*texObj
;
4229 struct gl_texture_image
*texImage
;
4230 GLboolean sizeOK
, dimensionsOK
;
4231 gl_format texFormat
;
4232 GLenum sample_count_error
;
4234 GET_CURRENT_CONTEXT(ctx
);
4236 if (!(ctx
->Extensions
.ARB_texture_multisample
4237 && _mesa_is_desktop_gl(ctx
))) {
4238 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4242 if (!check_multisample_target(dims
, target
)) {
4243 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4247 /* check that the specified internalformat is color/depth/stencil-renderable;
4248 * refer GL3.1 spec 4.4.4
4251 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4252 _mesa_error(ctx
, GL_INVALID_ENUM
,
4253 "%s(internalformat=%s not legal for immutable-format)",
4254 func
, _mesa_lookup_enum_by_nr(internalformat
));
4258 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4259 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4260 "%s(internalformat=%s)",
4261 func
, _mesa_lookup_enum_by_nr(internalformat
));
4265 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4266 internalformat
, samples
);
4267 if (sample_count_error
!= GL_NO_ERROR
) {
4268 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4272 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4274 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4275 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4276 "%s(texture object 0)",
4281 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4283 if (texImage
== NULL
) {
4284 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4288 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4289 internalformat
, GL_NONE
, GL_NONE
);
4290 assert(texFormat
!= MESA_FORMAT_NONE
);
4292 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4293 width
, height
, depth
, 0);
4295 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4296 width
, height
, depth
, 0);
4298 if (_mesa_is_proxy_texture(target
)) {
4299 if (dimensionsOK
&& sizeOK
) {
4300 _mesa_init_teximage_fields(ctx
, texImage
,
4301 width
, height
, depth
, 0, internalformat
, texFormat
);
4302 texImage
->NumSamples
= samples
;
4303 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4306 /* clear all image fields */
4307 _mesa_init_teximage_fields(ctx
, texImage
,
4308 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4312 if (!dimensionsOK
) {
4313 _mesa_error(ctx
, GL_INVALID_VALUE
,
4314 "%s(invalid width or height)", func
);
4319 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4320 "%s(texture too large)", func
);
4324 /* Check if texObj->Immutable is set */
4325 if (texObj
->Immutable
) {
4326 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4330 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4332 _mesa_init_teximage_fields(ctx
, texImage
,
4333 width
, height
, depth
, 0, internalformat
, texFormat
);
4335 texImage
->NumSamples
= samples
;
4336 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4338 if (width
> 0 && height
> 0 && depth
> 0) {
4339 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4340 width
, height
, depth
)) {
4341 /* tidy up the texture image state. strictly speaking,
4342 * we're allowed to just leave this in whatever state we
4343 * like, but being tidy is good.
4345 _mesa_init_teximage_fields(ctx
, texImage
,
4346 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4350 texObj
->Immutable
= immutable
;
4351 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4357 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4358 GLint internalformat
, GLsizei width
,
4359 GLsizei height
, GLboolean fixedsamplelocations
)
4361 teximagemultisample(2, target
, samples
, internalformat
,
4362 width
, height
, 1, fixedsamplelocations
, GL_FALSE
,
4363 "glTexImage2DMultisample");
4368 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4369 GLint internalformat
, GLsizei width
,
4370 GLsizei height
, GLsizei depth
,
4371 GLboolean fixedsamplelocations
)
4373 teximagemultisample(3, target
, samples
, internalformat
,
4374 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
,
4375 "glTexImage3DMultisample");
4380 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4381 GLenum internalformat
, GLsizei width
,
4382 GLsizei height
, GLboolean fixedsamplelocations
)
4384 teximagemultisample(2, target
, samples
, internalformat
,
4385 width
, height
, 1, fixedsamplelocations
, GL_TRUE
,
4386 "glTexStorage2DMultisample");
4391 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4392 GLenum internalformat
, GLsizei width
,
4393 GLsizei height
, GLsizei depth
,
4394 GLboolean fixedsamplelocations
)
4396 teximagemultisample(3, target
, samples
, internalformat
,
4397 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
,
4398 "glTexStorage3DMultisample");