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
:
318 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
320 case GL_SRGB_ALPHA_EXT
:
321 case GL_SRGB8_ALPHA8_EXT
:
322 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
323 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
324 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
325 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
327 case GL_SLUMINANCE_ALPHA_EXT
:
328 case GL_SLUMINANCE8_ALPHA8_EXT
:
329 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
330 return GL_LUMINANCE_ALPHA
;
331 case GL_SLUMINANCE_EXT
:
332 case GL_SLUMINANCE8_EXT
:
333 case GL_COMPRESSED_SLUMINANCE_EXT
:
340 if (ctx
->Version
>= 30 ||
341 ctx
->Extensions
.EXT_texture_integer
) {
342 switch (internalFormat
) {
344 case GL_RGBA16UI_EXT
:
345 case GL_RGBA32UI_EXT
:
361 if (ctx
->Extensions
.EXT_texture_integer
) {
362 switch (internalFormat
) {
363 case GL_ALPHA8UI_EXT
:
364 case GL_ALPHA16UI_EXT
:
365 case GL_ALPHA32UI_EXT
:
367 case GL_ALPHA16I_EXT
:
368 case GL_ALPHA32I_EXT
:
370 case GL_INTENSITY8UI_EXT
:
371 case GL_INTENSITY16UI_EXT
:
372 case GL_INTENSITY32UI_EXT
:
373 case GL_INTENSITY8I_EXT
:
374 case GL_INTENSITY16I_EXT
:
375 case GL_INTENSITY32I_EXT
:
377 case GL_LUMINANCE8UI_EXT
:
378 case GL_LUMINANCE16UI_EXT
:
379 case GL_LUMINANCE32UI_EXT
:
380 case GL_LUMINANCE8I_EXT
:
381 case GL_LUMINANCE16I_EXT
:
382 case GL_LUMINANCE32I_EXT
:
384 case GL_LUMINANCE_ALPHA8UI_EXT
:
385 case GL_LUMINANCE_ALPHA16UI_EXT
:
386 case GL_LUMINANCE_ALPHA32UI_EXT
:
387 case GL_LUMINANCE_ALPHA8I_EXT
:
388 case GL_LUMINANCE_ALPHA16I_EXT
:
389 case GL_LUMINANCE_ALPHA32I_EXT
:
390 return GL_LUMINANCE_ALPHA
;
396 if (ctx
->Extensions
.ARB_texture_rg
) {
397 switch (internalFormat
) {
399 /* R16F depends on both ARB_half_float_pixel and ARB_texture_float.
401 if (!ctx
->Extensions
.ARB_half_float_pixel
)
405 if (!ctx
->Extensions
.ARB_texture_float
)
414 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
420 case GL_COMPRESSED_RED
:
424 /* RG16F depends on both ARB_half_float_pixel and ARB_texture_float.
426 if (!ctx
->Extensions
.ARB_half_float_pixel
)
430 if (!ctx
->Extensions
.ARB_texture_float
)
439 if (ctx
->Version
< 30 && !ctx
->Extensions
.EXT_texture_integer
)
445 case GL_COMPRESSED_RG
:
452 if (ctx
->Extensions
.EXT_texture_shared_exponent
) {
453 switch (internalFormat
) {
461 if (ctx
->Extensions
.EXT_packed_float
) {
462 switch (internalFormat
) {
463 case GL_R11F_G11F_B10F_EXT
:
470 if (ctx
->Extensions
.ARB_depth_buffer_float
) {
471 switch (internalFormat
) {
472 case GL_DEPTH_COMPONENT32F
:
473 return GL_DEPTH_COMPONENT
;
474 case GL_DEPTH32F_STENCIL8
:
475 return GL_DEPTH_STENCIL
;
481 if (ctx
->Extensions
.ARB_texture_compression_rgtc
) {
482 switch (internalFormat
) {
483 case GL_COMPRESSED_RED_RGTC1
:
484 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
486 case GL_COMPRESSED_RG_RGTC2
:
487 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
494 if (ctx
->Extensions
.EXT_texture_compression_latc
) {
495 switch (internalFormat
) {
496 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
497 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
499 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
500 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
501 return GL_LUMINANCE_ALPHA
;
507 if (ctx
->Extensions
.ATI_texture_compression_3dc
) {
508 switch (internalFormat
) {
509 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
510 return GL_LUMINANCE_ALPHA
;
516 if (ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
) {
517 switch (internalFormat
) {
518 case GL_ETC1_RGB8_OES
:
525 if (_mesa_is_gles3(ctx
) || ctx
->Extensions
.ARB_ES3_compatibility
) {
526 switch (internalFormat
) {
527 case GL_COMPRESSED_RGB8_ETC2
:
528 case GL_COMPRESSED_SRGB8_ETC2
:
530 case GL_COMPRESSED_RGBA8_ETC2_EAC
:
531 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC
:
532 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
533 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2
:
535 case GL_COMPRESSED_R11_EAC
:
536 case GL_COMPRESSED_SIGNED_R11_EAC
:
538 case GL_COMPRESSED_RG11_EAC
:
539 case GL_COMPRESSED_SIGNED_RG11_EAC
:
546 if (ctx
->API
== API_OPENGLES
) {
547 switch (internalFormat
) {
548 case GL_PALETTE4_RGB8_OES
:
549 case GL_PALETTE4_R5_G6_B5_OES
:
550 case GL_PALETTE8_RGB8_OES
:
551 case GL_PALETTE8_R5_G6_B5_OES
:
553 case GL_PALETTE4_RGBA8_OES
:
554 case GL_PALETTE8_RGB5_A1_OES
:
555 case GL_PALETTE4_RGBA4_OES
:
556 case GL_PALETTE4_RGB5_A1_OES
:
557 case GL_PALETTE8_RGBA8_OES
:
558 case GL_PALETTE8_RGBA4_OES
:
565 return -1; /* error */
570 * For cube map faces, return a face index in [0,5].
571 * For other targets return 0;
574 _mesa_tex_target_to_face(GLenum target
)
576 if (_mesa_is_cube_face(target
))
577 return (GLuint
) target
- (GLuint
) GL_TEXTURE_CUBE_MAP_POSITIVE_X
;
585 * Install gl_texture_image in a gl_texture_object according to the target
586 * and level parameters.
588 * \param tObj texture object.
589 * \param target texture target.
590 * \param level image level.
591 * \param texImage texture image.
594 set_tex_image(struct gl_texture_object
*tObj
,
595 GLenum target
, GLint level
,
596 struct gl_texture_image
*texImage
)
598 const GLuint face
= _mesa_tex_target_to_face(target
);
602 if (target
== GL_TEXTURE_RECTANGLE_NV
|| target
== GL_TEXTURE_EXTERNAL_OES
)
605 tObj
->Image
[face
][level
] = texImage
;
607 /* Set the 'back' pointer */
608 texImage
->TexObject
= tObj
;
609 texImage
->Level
= level
;
610 texImage
->Face
= face
;
615 * Allocate a texture image structure.
617 * Called via ctx->Driver.NewTextureImage() unless overriden by a device
620 * \return a pointer to gl_texture_image struct with all fields initialized to
623 struct gl_texture_image
*
624 _mesa_new_texture_image( struct gl_context
*ctx
)
627 return CALLOC_STRUCT(gl_texture_image
);
632 * Free a gl_texture_image and associated data.
633 * This function is a fallback called via ctx->Driver.DeleteTextureImage().
635 * \param texImage texture image.
637 * Free the texture image structure and the associated image data.
640 _mesa_delete_texture_image(struct gl_context
*ctx
,
641 struct gl_texture_image
*texImage
)
643 /* Free texImage->Data and/or any other driver-specific texture
646 ASSERT(ctx
->Driver
.FreeTextureImageBuffer
);
647 ctx
->Driver
.FreeTextureImageBuffer( ctx
, texImage
);
653 * Test if a target is a proxy target.
655 * \param target texture target.
657 * \return GL_TRUE if the target is a proxy target, GL_FALSE otherwise.
660 _mesa_is_proxy_texture(GLenum target
)
663 * NUM_TEXTURE_TARGETS should match number of terms below, except there's no
664 * proxy for GL_TEXTURE_BUFFER and GL_TEXTURE_EXTERNAL_OES.
666 assert(NUM_TEXTURE_TARGETS
== 10 + 2);
668 return (target
== GL_PROXY_TEXTURE_1D
||
669 target
== GL_PROXY_TEXTURE_2D
||
670 target
== GL_PROXY_TEXTURE_3D
||
671 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
672 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
||
673 target
== GL_PROXY_TEXTURE_1D_ARRAY_EXT
||
674 target
== GL_PROXY_TEXTURE_2D_ARRAY_EXT
||
675 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
676 target
== GL_PROXY_TEXTURE_2D_MULTISAMPLE
||
677 target
== GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
);
682 * Return the proxy target which corresponds to the given texture target
685 _mesa_get_proxy_target(GLenum target
)
689 case GL_PROXY_TEXTURE_1D
:
690 return GL_PROXY_TEXTURE_1D
;
692 case GL_PROXY_TEXTURE_2D
:
693 return GL_PROXY_TEXTURE_2D
;
695 case GL_PROXY_TEXTURE_3D
:
696 return GL_PROXY_TEXTURE_3D
;
697 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
698 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
699 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
700 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
701 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
702 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
703 case GL_TEXTURE_CUBE_MAP_ARB
:
704 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
705 return GL_PROXY_TEXTURE_CUBE_MAP_ARB
;
706 case GL_TEXTURE_RECTANGLE_NV
:
707 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
708 return GL_PROXY_TEXTURE_RECTANGLE_NV
;
709 case GL_TEXTURE_1D_ARRAY_EXT
:
710 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
711 return GL_PROXY_TEXTURE_1D_ARRAY_EXT
;
712 case GL_TEXTURE_2D_ARRAY_EXT
:
713 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
714 return GL_PROXY_TEXTURE_2D_ARRAY_EXT
;
715 case GL_TEXTURE_CUBE_MAP_ARRAY
:
716 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
717 return GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
;
718 case GL_TEXTURE_2D_MULTISAMPLE
:
719 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
720 return GL_PROXY_TEXTURE_2D_MULTISAMPLE
;
721 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
722 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
723 return GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
;
725 _mesa_problem(NULL
, "unexpected target in _mesa_get_proxy_target()");
732 * Get the texture object that corresponds to the target of the given
733 * texture unit. The target should have already been checked for validity.
735 * \param ctx GL context.
736 * \param texUnit texture unit.
737 * \param target texture target.
739 * \return pointer to the texture object on success, or NULL on failure.
741 struct gl_texture_object
*
742 _mesa_select_tex_object(struct gl_context
*ctx
,
743 const struct gl_texture_unit
*texUnit
,
746 const GLboolean arrayTex
= (ctx
->Extensions
.MESA_texture_array
||
747 ctx
->Extensions
.EXT_texture_array
);
751 return texUnit
->CurrentTex
[TEXTURE_1D_INDEX
];
752 case GL_PROXY_TEXTURE_1D
:
753 return ctx
->Texture
.ProxyTex
[TEXTURE_1D_INDEX
];
755 return texUnit
->CurrentTex
[TEXTURE_2D_INDEX
];
756 case GL_PROXY_TEXTURE_2D
:
757 return ctx
->Texture
.ProxyTex
[TEXTURE_2D_INDEX
];
759 return texUnit
->CurrentTex
[TEXTURE_3D_INDEX
];
760 case GL_PROXY_TEXTURE_3D
:
761 return ctx
->Texture
.ProxyTex
[TEXTURE_3D_INDEX
];
762 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
763 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
764 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
765 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
766 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
767 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
768 case GL_TEXTURE_CUBE_MAP_ARB
:
769 return ctx
->Extensions
.ARB_texture_cube_map
770 ? texUnit
->CurrentTex
[TEXTURE_CUBE_INDEX
] : NULL
;
771 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
772 return ctx
->Extensions
.ARB_texture_cube_map
773 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_INDEX
] : NULL
;
774 case GL_TEXTURE_CUBE_MAP_ARRAY
:
775 return ctx
->Extensions
.ARB_texture_cube_map_array
776 ? texUnit
->CurrentTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
777 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
778 return ctx
->Extensions
.ARB_texture_cube_map_array
779 ? ctx
->Texture
.ProxyTex
[TEXTURE_CUBE_ARRAY_INDEX
] : NULL
;
780 case GL_TEXTURE_RECTANGLE_NV
:
781 return ctx
->Extensions
.NV_texture_rectangle
782 ? texUnit
->CurrentTex
[TEXTURE_RECT_INDEX
] : NULL
;
783 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
784 return ctx
->Extensions
.NV_texture_rectangle
785 ? ctx
->Texture
.ProxyTex
[TEXTURE_RECT_INDEX
] : NULL
;
786 case GL_TEXTURE_1D_ARRAY_EXT
:
787 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
788 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
789 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_1D_ARRAY_INDEX
] : NULL
;
790 case GL_TEXTURE_2D_ARRAY_EXT
:
791 return arrayTex
? texUnit
->CurrentTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
792 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
793 return arrayTex
? ctx
->Texture
.ProxyTex
[TEXTURE_2D_ARRAY_INDEX
] : NULL
;
794 case GL_TEXTURE_BUFFER
:
795 return ctx
->API
== API_OPENGL_CORE
&&
796 ctx
->Extensions
.ARB_texture_buffer_object
?
797 texUnit
->CurrentTex
[TEXTURE_BUFFER_INDEX
] : NULL
;
798 case GL_TEXTURE_EXTERNAL_OES
:
799 return ctx
->Extensions
.OES_EGL_image_external
800 ? texUnit
->CurrentTex
[TEXTURE_EXTERNAL_INDEX
] : NULL
;
801 case GL_TEXTURE_2D_MULTISAMPLE
:
802 return ctx
->Extensions
.ARB_texture_multisample
803 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
804 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
805 return ctx
->Extensions
.ARB_texture_multisample
806 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_INDEX
] : NULL
;
807 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
808 return ctx
->Extensions
.ARB_texture_multisample
809 ? texUnit
->CurrentTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
810 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
811 return ctx
->Extensions
.ARB_texture_multisample
812 ? ctx
->Texture
.ProxyTex
[TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
] : NULL
;
814 _mesa_problem(NULL
, "bad target in _mesa_select_tex_object()");
821 * Return pointer to texture object for given target on current texture unit.
823 struct gl_texture_object
*
824 _mesa_get_current_tex_object(struct gl_context
*ctx
, GLenum target
)
826 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
827 return _mesa_select_tex_object(ctx
, texUnit
, target
);
832 * Get a texture image pointer from a texture object, given a texture
833 * target and mipmap level. The target and level parameters should
834 * have already been error-checked.
836 * \param ctx GL context.
837 * \param texObj texture unit.
838 * \param target texture target.
839 * \param level image level.
841 * \return pointer to the texture image structure, or NULL on failure.
843 struct gl_texture_image
*
844 _mesa_select_tex_image(struct gl_context
*ctx
,
845 const struct gl_texture_object
*texObj
,
846 GLenum target
, GLint level
)
848 const GLuint face
= _mesa_tex_target_to_face(target
);
852 ASSERT(level
< MAX_TEXTURE_LEVELS
);
854 return texObj
->Image
[face
][level
];
859 * Like _mesa_select_tex_image() but if the image doesn't exist, allocate
860 * it and install it. Only return NULL if passed a bad parameter or run
863 struct gl_texture_image
*
864 _mesa_get_tex_image(struct gl_context
*ctx
, struct gl_texture_object
*texObj
,
865 GLenum target
, GLint level
)
867 struct gl_texture_image
*texImage
;
872 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
874 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
876 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "texture image allocation");
880 set_tex_image(texObj
, target
, level
, texImage
);
888 * Return pointer to the specified proxy texture image.
889 * Note that proxy textures are per-context, not per-texture unit.
890 * \return pointer to texture image or NULL if invalid target, invalid
891 * level, or out of memory.
893 static struct gl_texture_image
*
894 get_proxy_tex_image(struct gl_context
*ctx
, GLenum target
, GLint level
)
896 struct gl_texture_image
*texImage
;
903 case GL_PROXY_TEXTURE_1D
:
904 if (level
>= ctx
->Const
.MaxTextureLevels
)
906 texIndex
= TEXTURE_1D_INDEX
;
908 case GL_PROXY_TEXTURE_2D
:
909 if (level
>= ctx
->Const
.MaxTextureLevels
)
911 texIndex
= TEXTURE_2D_INDEX
;
913 case GL_PROXY_TEXTURE_3D
:
914 if (level
>= ctx
->Const
.Max3DTextureLevels
)
916 texIndex
= TEXTURE_3D_INDEX
;
918 case GL_PROXY_TEXTURE_CUBE_MAP
:
919 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
921 texIndex
= TEXTURE_CUBE_INDEX
;
923 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
926 texIndex
= TEXTURE_RECT_INDEX
;
928 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
929 if (level
>= ctx
->Const
.MaxTextureLevels
)
931 texIndex
= TEXTURE_1D_ARRAY_INDEX
;
933 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
934 if (level
>= ctx
->Const
.MaxTextureLevels
)
936 texIndex
= TEXTURE_2D_ARRAY_INDEX
;
938 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
939 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
941 texIndex
= TEXTURE_CUBE_ARRAY_INDEX
;
943 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
946 texIndex
= TEXTURE_2D_MULTISAMPLE_INDEX
;
948 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
951 texIndex
= TEXTURE_2D_MULTISAMPLE_ARRAY_INDEX
;
957 texImage
= ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
];
959 texImage
= ctx
->Driver
.NewTextureImage(ctx
);
961 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "proxy texture allocation");
964 ctx
->Texture
.ProxyTex
[texIndex
]->Image
[0][level
] = texImage
;
965 /* Set the 'back' pointer */
966 texImage
->TexObject
= ctx
->Texture
.ProxyTex
[texIndex
];
973 * Get the maximum number of allowed mipmap levels.
975 * \param ctx GL context.
976 * \param target texture target.
978 * \return the maximum number of allowed mipmap levels for the given
979 * texture target, or zero if passed a bad target.
984 _mesa_max_texture_levels(struct gl_context
*ctx
, GLenum target
)
988 case GL_PROXY_TEXTURE_1D
:
990 case GL_PROXY_TEXTURE_2D
:
991 return ctx
->Const
.MaxTextureLevels
;
993 case GL_PROXY_TEXTURE_3D
:
994 return ctx
->Const
.Max3DTextureLevels
;
995 case GL_TEXTURE_CUBE_MAP
:
996 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB
:
997 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB
:
998 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB
:
999 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB
:
1000 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB
:
1001 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
:
1002 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1003 return ctx
->Extensions
.ARB_texture_cube_map
1004 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1005 case GL_TEXTURE_RECTANGLE_NV
:
1006 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1007 return ctx
->Extensions
.NV_texture_rectangle
? 1 : 0;
1008 case GL_TEXTURE_1D_ARRAY_EXT
:
1009 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1010 case GL_TEXTURE_2D_ARRAY_EXT
:
1011 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1012 return (ctx
->Extensions
.MESA_texture_array
||
1013 ctx
->Extensions
.EXT_texture_array
)
1014 ? ctx
->Const
.MaxTextureLevels
: 0;
1015 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1016 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1017 return ctx
->Extensions
.ARB_texture_cube_map_array
1018 ? ctx
->Const
.MaxCubeTextureLevels
: 0;
1019 case GL_TEXTURE_BUFFER
:
1020 return ctx
->API
== API_OPENGL_CORE
&&
1021 ctx
->Extensions
.ARB_texture_buffer_object
? 1 : 0;
1022 case GL_TEXTURE_2D_MULTISAMPLE
:
1023 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1024 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1025 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1026 return _mesa_is_desktop_gl(ctx
)
1027 && ctx
->Extensions
.ARB_texture_multisample
1029 case GL_TEXTURE_EXTERNAL_OES
:
1032 return 0; /* bad target */
1038 * Return number of dimensions per mipmap level for the given texture target.
1041 _mesa_get_texture_dimensions(GLenum target
)
1045 case GL_PROXY_TEXTURE_1D
:
1048 case GL_TEXTURE_RECTANGLE
:
1049 case GL_TEXTURE_CUBE_MAP
:
1050 case GL_PROXY_TEXTURE_2D
:
1051 case GL_PROXY_TEXTURE_RECTANGLE
:
1052 case GL_PROXY_TEXTURE_CUBE_MAP
:
1053 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1054 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1055 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1056 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1057 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1058 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1059 case GL_TEXTURE_1D_ARRAY
:
1060 case GL_PROXY_TEXTURE_1D_ARRAY
:
1061 case GL_TEXTURE_EXTERNAL_OES
:
1062 case GL_TEXTURE_2D_MULTISAMPLE
:
1063 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1066 case GL_PROXY_TEXTURE_3D
:
1067 case GL_TEXTURE_2D_ARRAY
:
1068 case GL_PROXY_TEXTURE_2D_ARRAY
:
1069 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1070 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1071 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1072 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1074 case GL_TEXTURE_BUFFER
:
1077 _mesa_problem(NULL
, "invalid target 0x%x in get_texture_dimensions()",
1085 * Return the maximum number of mipmap levels for the given target
1086 * and the dimensions.
1087 * The dimensions are expected not to include the border.
1090 _mesa_get_tex_max_num_levels(GLenum target
, GLsizei width
, GLsizei height
,
1097 case GL_TEXTURE_1D_ARRAY
:
1100 case GL_TEXTURE_CUBE_MAP
:
1101 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1102 ASSERT(width
== height
);
1106 case GL_TEXTURE_2D_ARRAY
:
1107 size
= MAX2(width
, height
);
1110 size
= MAX3(width
, height
, depth
);
1112 case GL_TEXTURE_RECTANGLE
:
1113 case GL_TEXTURE_EXTERNAL_OES
:
1114 case GL_TEXTURE_2D_MULTISAMPLE
:
1115 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1122 return _mesa_logbase2(size
) + 1;
1126 #if 000 /* not used anymore */
1128 * glTexImage[123]D can accept a NULL image pointer. In this case we
1129 * create a texture image with unspecified image contents per the OpenGL
1133 make_null_texture(GLint width
, GLint height
, GLint depth
, GLenum format
)
1135 const GLint components
= _mesa_components_in_format(format
);
1136 const GLint numPixels
= width
* height
* depth
;
1137 GLubyte
*data
= (GLubyte
*) malloc(numPixels
* components
* sizeof(GLubyte
));
1141 * Let's see if anyone finds this. If glTexImage2D() is called with
1142 * a NULL image pointer then load the texture image with something
1143 * interesting instead of leaving it indeterminate.
1146 static const char message
[8][32] = {
1147 " X X XXXXX XXX X ",
1148 " XX XX X X X X X ",
1150 " X X XXXX XXX XXXXX ",
1153 " X X XXXXX XXX X X ",
1157 GLubyte
*imgPtr
= data
;
1159 for (h
= 0; h
< depth
; h
++) {
1160 for (i
= 0; i
< height
; i
++) {
1161 GLint srcRow
= 7 - (i
% 8);
1162 for (j
= 0; j
< width
; j
++) {
1163 GLint srcCol
= j
% 32;
1164 GLubyte texel
= (message
[srcRow
][srcCol
]=='X') ? 255 : 70;
1165 for (k
= 0; k
< components
; k
++) {
1181 * Set the size and format-related fields of a gl_texture_image struct
1182 * to zero. This is used when a proxy texture test fails.
1185 clear_teximage_fields(struct gl_texture_image
*img
)
1188 img
->_BaseFormat
= 0;
1189 img
->InternalFormat
= 0;
1198 img
->HeightLog2
= 0;
1200 img
->TexFormat
= MESA_FORMAT_NONE
;
1201 img
->NumSamples
= 0;
1202 img
->FixedSampleLocations
= GL_TRUE
;
1207 * Initialize basic fields of the gl_texture_image struct.
1209 * \param ctx GL context.
1210 * \param img texture image structure to be initialized.
1211 * \param width image width.
1212 * \param height image height.
1213 * \param depth image depth.
1214 * \param border image border.
1215 * \param internalFormat internal format.
1216 * \param format the actual hardware format (one of MESA_FORMAT_*)
1218 * Fills in the fields of \p img with the given information.
1219 * Note: width, height and depth include the border.
1222 _mesa_init_teximage_fields(struct gl_context
*ctx
,
1223 struct gl_texture_image
*img
,
1224 GLsizei width
, GLsizei height
, GLsizei depth
,
1225 GLint border
, GLenum internalFormat
,
1231 ASSERT(height
>= 0);
1234 target
= img
->TexObject
->Target
;
1235 img
->_BaseFormat
= _mesa_base_tex_format( ctx
, internalFormat
);
1236 ASSERT(img
->_BaseFormat
> 0);
1237 img
->InternalFormat
= internalFormat
;
1238 img
->Border
= border
;
1240 img
->Height
= height
;
1243 img
->Width2
= width
- 2 * border
; /* == 1 << img->WidthLog2; */
1244 img
->WidthLog2
= _mesa_logbase2(img
->Width2
);
1246 img
->NumSamples
= 0;
1247 img
->FixedSampleLocations
= GL_TRUE
;
1251 case GL_TEXTURE_BUFFER
:
1252 case GL_PROXY_TEXTURE_1D
:
1257 img
->HeightLog2
= 0;
1264 case GL_TEXTURE_1D_ARRAY
:
1265 case GL_PROXY_TEXTURE_1D_ARRAY
:
1266 img
->Height2
= height
; /* no border */
1267 img
->HeightLog2
= 0; /* not used */
1275 case GL_TEXTURE_RECTANGLE
:
1276 case GL_TEXTURE_CUBE_MAP
:
1277 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1278 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1279 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1280 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1281 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1282 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1283 case GL_TEXTURE_EXTERNAL_OES
:
1284 case GL_PROXY_TEXTURE_2D
:
1285 case GL_PROXY_TEXTURE_RECTANGLE
:
1286 case GL_PROXY_TEXTURE_CUBE_MAP
:
1287 case GL_TEXTURE_2D_MULTISAMPLE
:
1288 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1289 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1290 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1297 case GL_TEXTURE_2D_ARRAY
:
1298 case GL_PROXY_TEXTURE_2D_ARRAY
:
1299 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1300 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1301 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1302 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1303 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1304 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1305 img
->Depth2
= depth
; /* no border */
1306 img
->DepthLog2
= 0; /* not used */
1309 case GL_PROXY_TEXTURE_3D
:
1310 img
->Height2
= height
- 2 * border
; /* == 1 << img->HeightLog2; */
1311 img
->HeightLog2
= _mesa_logbase2(img
->Height2
);
1312 img
->Depth2
= depth
- 2 * border
; /* == 1 << img->DepthLog2; */
1313 img
->DepthLog2
= _mesa_logbase2(img
->Depth2
);
1316 _mesa_problem(NULL
, "invalid target 0x%x in _mesa_init_teximage_fields()",
1321 _mesa_get_tex_max_num_levels(target
,
1322 img
->Width2
, img
->Height2
, img
->Depth2
);
1323 img
->TexFormat
= format
;
1328 * Free and clear fields of the gl_texture_image struct.
1330 * \param ctx GL context.
1331 * \param texImage texture image structure to be cleared.
1333 * After the call, \p texImage will have no data associated with it. Its
1334 * fields are cleared so that its parent object will test incomplete.
1337 _mesa_clear_texture_image(struct gl_context
*ctx
,
1338 struct gl_texture_image
*texImage
)
1340 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
1341 clear_teximage_fields(texImage
);
1346 * Check the width, height, depth and border of a texture image are legal.
1347 * Used by all the glTexImage, glCompressedTexImage and glCopyTexImage
1349 * The target and level parameters will have already been validated.
1350 * \return GL_TRUE if size is OK, GL_FALSE otherwise.
1353 _mesa_legal_texture_dimensions(struct gl_context
*ctx
, GLenum target
,
1354 GLint level
, GLint width
, GLint height
,
1355 GLint depth
, GLint border
)
1361 case GL_PROXY_TEXTURE_1D
:
1362 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1); /* level zero size */
1363 maxSize
>>= level
; /* level size */
1364 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1366 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1367 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1373 case GL_PROXY_TEXTURE_2D
:
1374 case GL_TEXTURE_2D_MULTISAMPLE
:
1375 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
1376 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1378 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1380 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1382 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1383 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1385 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1391 case GL_PROXY_TEXTURE_3D
:
1392 maxSize
= 1 << (ctx
->Const
.Max3DTextureLevels
- 1);
1394 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1396 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1398 if (depth
< 2 * border
|| depth
> 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
))
1405 if (depth
> 0 && !_mesa_is_pow_two(depth
- 2 * border
))
1410 case GL_TEXTURE_RECTANGLE_NV
:
1411 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1414 maxSize
= ctx
->Const
.MaxTextureRectSize
;
1415 if (width
< 0 || width
> maxSize
)
1417 if (height
< 0 || height
> maxSize
)
1421 case GL_TEXTURE_CUBE_MAP
:
1422 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1423 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1424 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1425 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1426 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1427 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1428 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1429 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1431 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1433 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1435 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1436 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1438 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1443 case GL_TEXTURE_1D_ARRAY_EXT
:
1444 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1445 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1447 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1449 if (height
< 1 || height
> ctx
->Const
.MaxArrayTextureLayers
)
1451 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1452 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1457 case GL_TEXTURE_2D_ARRAY_EXT
:
1458 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1459 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1460 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
1461 maxSize
= 1 << (ctx
->Const
.MaxTextureLevels
- 1);
1463 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1465 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1467 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1469 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1470 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1472 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1477 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1478 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1479 maxSize
= 1 << (ctx
->Const
.MaxCubeTextureLevels
- 1);
1480 if (width
< 2 * border
|| width
> 2 * border
+ maxSize
)
1482 if (height
< 2 * border
|| height
> 2 * border
+ maxSize
)
1484 if (depth
< 1 || depth
> ctx
->Const
.MaxArrayTextureLayers
)
1486 if (level
>= ctx
->Const
.MaxCubeTextureLevels
)
1488 if (!ctx
->Extensions
.ARB_texture_non_power_of_two
) {
1489 if (width
> 0 && !_mesa_is_pow_two(width
- 2 * border
))
1491 if (height
> 0 && !_mesa_is_pow_two(height
- 2 * border
))
1496 _mesa_problem(ctx
, "Invalid target in _mesa_legal_texture_dimensions()");
1503 * Do error checking of xoffset, yoffset, zoffset, width, height and depth
1504 * for glTexSubImage, glCopyTexSubImage and glCompressedTexSubImage.
1505 * \param destImage the destination texture image.
1506 * \return GL_TRUE if error found, GL_FALSE otherwise.
1509 error_check_subtexture_dimensions(struct gl_context
*ctx
,
1510 const char *function
, GLuint dims
,
1511 const struct gl_texture_image
*destImage
,
1512 GLint xoffset
, GLint yoffset
, GLint zoffset
,
1513 GLsizei subWidth
, GLsizei subHeight
,
1516 const GLenum target
= destImage
->TexObject
->Target
;
1521 _mesa_error(ctx
, GL_INVALID_VALUE
,
1522 "%s%dD(width=%d)", function
, dims
, subWidth
);
1526 if (dims
> 1 && subHeight
< 0) {
1527 _mesa_error(ctx
, GL_INVALID_VALUE
,
1528 "%s%dD(height=%d)", function
, dims
, subHeight
);
1532 if (dims
> 2 && subDepth
< 0) {
1533 _mesa_error(ctx
, GL_INVALID_VALUE
,
1534 "%s%dD(depth=%d)", function
, dims
, subDepth
);
1538 /* check xoffset and width */
1539 if (xoffset
< - (GLint
) destImage
->Border
) {
1540 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset)",
1545 if (xoffset
+ subWidth
> (GLint
) destImage
->Width
) {
1546 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(xoffset+width)",
1551 /* check yoffset and height */
1553 GLint yBorder
= (target
== GL_TEXTURE_1D_ARRAY
) ? 0 : destImage
->Border
;
1554 if (yoffset
< -yBorder
) {
1555 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset)",
1559 if (yoffset
+ subHeight
> (GLint
) destImage
->Height
) {
1560 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s%dD(yoffset+height)",
1566 /* check zoffset and depth */
1568 GLint zBorder
= (target
== GL_TEXTURE_2D_ARRAY
) ? 0 : destImage
->Border
;
1569 if (zoffset
< -zBorder
) {
1570 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset)", function
);
1573 if (zoffset
+ subDepth
> (GLint
) destImage
->Depth
) {
1574 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s3D(zoffset+depth)", function
);
1580 * The OpenGL spec (and GL_ARB_texture_compression) says only whole
1581 * compressed texture images can be updated. But, that restriction may be
1582 * relaxed for particular compressed formats. At this time, all the
1583 * compressed formats supported by Mesa allow sub-textures to be updated
1584 * along compressed block boundaries.
1586 _mesa_get_format_block_size(destImage
->TexFormat
, &bw
, &bh
);
1588 if (bw
!= 1 || bh
!= 1) {
1589 /* offset must be multiple of block size */
1590 if ((xoffset
% bw
!= 0) || (yoffset
% bh
!= 0)) {
1591 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1592 "%s%dD(xoffset = %d, yoffset = %d)",
1593 function
, dims
, xoffset
, yoffset
);
1597 /* The size must be a multiple of bw x bh, or we must be using a
1598 * offset+size that exactly hits the edge of the image. This
1599 * is important for small mipmap levels (1x1, 2x1, etc) and for
1602 if ((subWidth
% bw
!= 0) &&
1603 (xoffset
+ subWidth
!= (GLint
) destImage
->Width
)) {
1604 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1605 "%s%dD(width = %d)", function
, dims
, subWidth
);
1609 if ((subHeight
% bh
!= 0) &&
1610 (yoffset
+ subHeight
!= (GLint
) destImage
->Height
)) {
1611 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1612 "%s%dD(height = %d)", function
, dims
, subHeight
);
1624 * This is the fallback for Driver.TestProxyTexImage() for doing device-
1625 * specific texture image size checks.
1627 * A hardware driver might override this function if, for example, the
1628 * max 3D texture size is 512x512x64 (i.e. not a cube).
1630 * Note that width, height, depth == 0 is not an error. However, a
1631 * texture with zero width/height/depth will be considered "incomplete"
1632 * and texturing will effectively be disabled.
1634 * \param target any texture target/type
1635 * \param level as passed to glTexImage
1636 * \param format the MESA_FORMAT_x for the tex image
1637 * \param width as passed to glTexImage
1638 * \param height as passed to glTexImage
1639 * \param depth as passed to glTexImage
1640 * \param border as passed to glTexImage
1641 * \return GL_TRUE if the image is acceptable, GL_FALSE if not acceptable.
1644 _mesa_test_proxy_teximage(struct gl_context
*ctx
, GLenum target
, GLint level
,
1646 GLint width
, GLint height
, GLint depth
, GLint border
)
1648 /* We just check if the image size is less than MaxTextureMbytes.
1649 * Some drivers may do more specific checks.
1651 uint64_t bytes
= _mesa_format_image_size64(format
, width
, height
, depth
);
1652 uint64_t mbytes
= bytes
/ (1024 * 1024); /* convert to MB */
1653 mbytes
*= _mesa_num_tex_faces(target
);
1654 return mbytes
<= (uint64_t) ctx
->Const
.MaxTextureMbytes
;
1659 * Return true if the format is only valid for glCompressedTexImage.
1662 compressedteximage_only_format(const struct gl_context
*ctx
, GLenum format
)
1665 case GL_ETC1_RGB8_OES
:
1666 case GL_PALETTE4_RGB8_OES
:
1667 case GL_PALETTE4_RGBA8_OES
:
1668 case GL_PALETTE4_R5_G6_B5_OES
:
1669 case GL_PALETTE4_RGBA4_OES
:
1670 case GL_PALETTE4_RGB5_A1_OES
:
1671 case GL_PALETTE8_RGB8_OES
:
1672 case GL_PALETTE8_RGBA8_OES
:
1673 case GL_PALETTE8_R5_G6_B5_OES
:
1674 case GL_PALETTE8_RGBA4_OES
:
1675 case GL_PALETTE8_RGB5_A1_OES
:
1684 * Helper function to determine whether a target and specific compression
1685 * format are supported.
1688 target_can_be_compressed(const struct gl_context
*ctx
, GLenum target
,
1691 (void) intFormat
; /* not used yet */
1695 case GL_PROXY_TEXTURE_2D
:
1696 return GL_TRUE
; /* true for any compressed format so far */
1697 case GL_PROXY_TEXTURE_CUBE_MAP
:
1698 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1699 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1700 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1701 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1702 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1703 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1704 return ctx
->Extensions
.ARB_texture_cube_map
;
1705 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1706 case GL_TEXTURE_2D_ARRAY_EXT
:
1707 return (ctx
->Extensions
.MESA_texture_array
||
1708 ctx
->Extensions
.EXT_texture_array
);
1709 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1710 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1711 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1719 * Check if the given texture target value is legal for a
1720 * glTexImage1/2/3D call.
1723 legal_teximage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1729 case GL_PROXY_TEXTURE_1D
:
1730 return _mesa_is_desktop_gl(ctx
);
1738 case GL_PROXY_TEXTURE_2D
:
1739 return _mesa_is_desktop_gl(ctx
);
1740 case GL_PROXY_TEXTURE_CUBE_MAP
:
1741 return _mesa_is_desktop_gl(ctx
)
1742 && ctx
->Extensions
.ARB_texture_cube_map
;
1743 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1744 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1745 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1746 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1747 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1748 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1749 return ctx
->Extensions
.ARB_texture_cube_map
;
1750 case GL_TEXTURE_RECTANGLE_NV
:
1751 case GL_PROXY_TEXTURE_RECTANGLE_NV
:
1752 return _mesa_is_desktop_gl(ctx
)
1753 && ctx
->Extensions
.NV_texture_rectangle
;
1754 case GL_TEXTURE_1D_ARRAY_EXT
:
1755 case GL_PROXY_TEXTURE_1D_ARRAY_EXT
:
1756 return _mesa_is_desktop_gl(ctx
)
1757 && (ctx
->Extensions
.MESA_texture_array
||
1758 ctx
->Extensions
.EXT_texture_array
);
1766 case GL_PROXY_TEXTURE_3D
:
1767 return _mesa_is_desktop_gl(ctx
);
1768 case GL_TEXTURE_2D_ARRAY_EXT
:
1769 return (_mesa_is_desktop_gl(ctx
)
1770 && (ctx
->Extensions
.MESA_texture_array
||
1771 ctx
->Extensions
.EXT_texture_array
))
1772 || _mesa_is_gles3(ctx
);
1773 case GL_PROXY_TEXTURE_2D_ARRAY_EXT
:
1774 return _mesa_is_desktop_gl(ctx
)
1775 && (ctx
->Extensions
.MESA_texture_array
||
1776 ctx
->Extensions
.EXT_texture_array
);
1777 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1778 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1779 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1784 _mesa_problem(ctx
, "invalid dims=%u in legal_teximage_target()", dims
);
1791 * Check if the given texture target value is legal for a
1792 * glTexSubImage, glCopyTexSubImage or glCopyTexImage call.
1793 * The difference compared to legal_teximage_target() above is that
1794 * proxy targets are not supported.
1797 legal_texsubimage_target(struct gl_context
*ctx
, GLuint dims
, GLenum target
)
1801 return _mesa_is_desktop_gl(ctx
) && target
== GL_TEXTURE_1D
;
1806 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
1807 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
1808 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
1809 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
1810 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
1811 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
1812 return ctx
->Extensions
.ARB_texture_cube_map
;
1813 case GL_TEXTURE_RECTANGLE_NV
:
1814 return _mesa_is_desktop_gl(ctx
)
1815 && ctx
->Extensions
.NV_texture_rectangle
;
1816 case GL_TEXTURE_1D_ARRAY_EXT
:
1817 return _mesa_is_desktop_gl(ctx
)
1818 && (ctx
->Extensions
.MESA_texture_array
||
1819 ctx
->Extensions
.EXT_texture_array
);
1827 case GL_TEXTURE_2D_ARRAY_EXT
:
1828 return (_mesa_is_desktop_gl(ctx
)
1829 && (ctx
->Extensions
.MESA_texture_array
||
1830 ctx
->Extensions
.EXT_texture_array
))
1831 || _mesa_is_gles3(ctx
);
1832 case GL_TEXTURE_CUBE_MAP_ARRAY
:
1833 case GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
:
1834 return ctx
->Extensions
.ARB_texture_cube_map_array
;
1839 _mesa_problem(ctx
, "invalid dims=%u in legal_texsubimage_target()",
1847 * Helper function to determine if a texture object is mutable (in terms
1848 * of GL_ARB_texture_storage).
1851 mutable_tex_object(struct gl_context
*ctx
, GLenum target
)
1853 if (ctx
->Extensions
.ARB_texture_storage
) {
1854 struct gl_texture_object
*texObj
=
1855 _mesa_get_current_tex_object(ctx
, target
);
1856 return !texObj
->Immutable
;
1863 * Return expected size of a compressed texture.
1866 compressed_tex_size(GLsizei width
, GLsizei height
, GLsizei depth
,
1869 gl_format mesaFormat
= _mesa_glenum_to_compressed_format(glformat
);
1870 return _mesa_format_image_size(mesaFormat
, width
, height
, depth
);
1875 * Test the glTexImage[123]D() parameters for errors.
1877 * \param ctx GL context.
1878 * \param dimensions texture image dimensions (must be 1, 2 or 3).
1879 * \param target texture target given by the user (already validated).
1880 * \param level image level given by the user.
1881 * \param internalFormat internal format given by the user.
1882 * \param format pixel data format given by the user.
1883 * \param type pixel data type given by the user.
1884 * \param width image width given by the user.
1885 * \param height image height given by the user.
1886 * \param depth image depth given by the user.
1887 * \param border image border given by the user.
1889 * \return GL_TRUE if a error is found, GL_FALSE otherwise
1891 * Verifies each of the parameters against the constants specified in
1892 * __struct gl_contextRec::Const and the supported extensions, and according
1893 * to the OpenGL specification.
1894 * Note that we don't fully error-check the width, height, depth values
1895 * here. That's done in _mesa_legal_texture_dimensions() which is used
1896 * by several other GL entrypoints. Plus, texture dims have a special
1897 * interaction with proxy textures.
1900 texture_error_check( struct gl_context
*ctx
,
1901 GLuint dimensions
, GLenum target
,
1902 GLint level
, GLint internalFormat
,
1903 GLenum format
, GLenum type
,
1904 GLint width
, GLint height
,
1905 GLint depth
, GLint border
)
1907 GLboolean colorFormat
;
1910 /* Even though there are no color-index textures, we still have to support
1911 * uploading color-index data and remapping it to RGB via the
1912 * GL_PIXEL_MAP_I_TO_[RGBA] tables.
1914 const GLboolean indexFormat
= (format
== GL_COLOR_INDEX
);
1916 /* Note: for proxy textures, some error conditions immediately generate
1917 * a GL error in the usual way. But others do not generate a GL error.
1918 * Instead, they cause the width, height, depth, format fields of the
1919 * texture image to be zeroed-out. The GL spec seems to indicate that the
1920 * zero-out behaviour is only used in cases related to memory allocation.
1924 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
1925 _mesa_error(ctx
, GL_INVALID_VALUE
,
1926 "glTexImage%dD(level=%d)", dimensions
, level
);
1931 if (border
< 0 || border
> 1 ||
1932 ((ctx
->API
!= API_OPENGL_COMPAT
||
1933 target
== GL_TEXTURE_RECTANGLE_NV
||
1934 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
1935 _mesa_error(ctx
, GL_INVALID_VALUE
,
1936 "glTexImage%dD(border=%d)", dimensions
, border
);
1940 if (width
< 0 || height
< 0 || depth
< 0) {
1941 _mesa_error(ctx
, GL_INVALID_VALUE
,
1942 "glTexImage%dD(width, height or depth < 0)", dimensions
);
1946 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
1947 * combinations of format, internalFormat, and type that can be used.
1948 * Formats and types that require additional extensions (e.g., GL_FLOAT
1949 * requires GL_OES_texture_float) are filtered elsewhere.
1952 if (_mesa_is_gles(ctx
)) {
1953 if (_mesa_is_gles3(ctx
)) {
1954 err
= _mesa_es3_error_check_format_and_type(format
, type
,
1957 if (format
!= internalFormat
) {
1958 _mesa_error(ctx
, GL_INVALID_OPERATION
,
1959 "glTexImage%dD(format = %s, internalFormat = %s)",
1961 _mesa_lookup_enum_by_nr(format
),
1962 _mesa_lookup_enum_by_nr(internalFormat
));
1966 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
1968 if (err
!= GL_NO_ERROR
) {
1969 _mesa_error(ctx
, err
,
1970 "glTexImage%dD(format = %s, type = %s, internalFormat = %s)",
1972 _mesa_lookup_enum_by_nr(format
),
1973 _mesa_lookup_enum_by_nr(type
),
1974 _mesa_lookup_enum_by_nr(internalFormat
));
1979 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
1980 _mesa_is_cube_face(target
)) && width
!= height
) {
1981 _mesa_error(ctx
, GL_INVALID_VALUE
,
1982 "glTexImage2D(cube width != height)");
1986 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1987 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && width
!= height
) {
1988 _mesa_error(ctx
, GL_INVALID_VALUE
,
1989 "glTexImage3D(cube array width != height)");
1993 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
||
1994 target
== GL_TEXTURE_CUBE_MAP_ARRAY
) && (depth
% 6)) {
1995 _mesa_error(ctx
, GL_INVALID_VALUE
,
1996 "glTexImage3D(cube array depth not multiple of 6)");
2000 /* Check internalFormat */
2001 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2002 _mesa_error(ctx
, GL_INVALID_VALUE
,
2003 "glTexImage%dD(internalFormat=%s)",
2004 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
));
2008 /* Check incoming image format and type */
2009 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2010 if (err
!= GL_NO_ERROR
) {
2011 _mesa_error(ctx
, err
,
2012 "glTexImage%dD(incompatible format = %s, type = %s)",
2013 dimensions
, _mesa_lookup_enum_by_nr(format
),
2014 _mesa_lookup_enum_by_nr(type
));
2018 /* make sure internal format and format basically agree */
2019 colorFormat
= _mesa_is_color_format(format
);
2020 if ((_mesa_is_color_format(internalFormat
) && !colorFormat
&& !indexFormat
) ||
2021 (_mesa_is_depth_format(internalFormat
) != _mesa_is_depth_format(format
)) ||
2022 (_mesa_is_ycbcr_format(internalFormat
) != _mesa_is_ycbcr_format(format
)) ||
2023 (_mesa_is_depthstencil_format(internalFormat
) != _mesa_is_depthstencil_format(format
)) ||
2024 (_mesa_is_dudv_format(internalFormat
) != _mesa_is_dudv_format(format
))) {
2025 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2026 "glTexImage%dD(incompatible internalFormat = %s, format = %s)",
2027 dimensions
, _mesa_lookup_enum_by_nr(internalFormat
),
2028 _mesa_lookup_enum_by_nr(format
));
2032 /* additional checks for ycbcr textures */
2033 if (internalFormat
== GL_YCBCR_MESA
) {
2034 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2035 if (type
!= GL_UNSIGNED_SHORT_8_8_MESA
&&
2036 type
!= GL_UNSIGNED_SHORT_8_8_REV_MESA
) {
2038 _mesa_snprintf(message
, sizeof(message
),
2039 "glTexImage%dD(format/type YCBCR mismatch)",
2041 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s", message
);
2042 return GL_TRUE
; /* error */
2044 if (target
!= GL_TEXTURE_2D
&&
2045 target
!= GL_PROXY_TEXTURE_2D
&&
2046 target
!= GL_TEXTURE_RECTANGLE_NV
&&
2047 target
!= GL_PROXY_TEXTURE_RECTANGLE_NV
) {
2048 _mesa_error(ctx
, GL_INVALID_ENUM
,
2049 "glTexImage%dD(bad target for YCbCr texture)",
2055 _mesa_snprintf(message
, sizeof(message
),
2056 "glTexImage%dD(format=GL_YCBCR_MESA and border=%d)",
2057 dimensions
, border
);
2058 _mesa_error(ctx
, GL_INVALID_VALUE
, "%s", message
);
2063 /* additional checks for depth textures */
2064 if (_mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_COMPONENT
2065 || _mesa_base_tex_format(ctx
, internalFormat
) == GL_DEPTH_STENCIL
) {
2066 /* Only 1D, 2D, rect, array and cube textures supported, not 3D
2067 * Cubemaps are only supported for GL version > 3.0 or with EXT_gpu_shader4 */
2068 if (target
!= GL_TEXTURE_1D
&&
2069 target
!= GL_PROXY_TEXTURE_1D
&&
2070 target
!= GL_TEXTURE_2D
&&
2071 target
!= GL_PROXY_TEXTURE_2D
&&
2072 target
!= GL_TEXTURE_1D_ARRAY
&&
2073 target
!= GL_PROXY_TEXTURE_1D_ARRAY
&&
2074 target
!= GL_TEXTURE_2D_ARRAY
&&
2075 target
!= GL_PROXY_TEXTURE_2D_ARRAY
&&
2076 target
!= GL_TEXTURE_RECTANGLE_ARB
&&
2077 target
!= GL_PROXY_TEXTURE_RECTANGLE_ARB
&&
2078 !((_mesa_is_cube_face(target
) || target
== GL_PROXY_TEXTURE_CUBE_MAP
) &&
2079 (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_gpu_shader4
2080 || (ctx
->API
== API_OPENGLES2
&& ctx
->Extensions
.OES_depth_texture_cube_map
))) &&
2081 !((target
== GL_TEXTURE_CUBE_MAP_ARRAY
||
2082 target
== GL_PROXY_TEXTURE_CUBE_MAP_ARRAY
) &&
2083 ctx
->Extensions
.ARB_texture_cube_map_array
)) {
2084 _mesa_error(ctx
, GL_INVALID_ENUM
,
2085 "glTexImage%dD(bad target for depth texture)",
2091 /* additional checks for compressed textures */
2092 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2093 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2094 _mesa_error(ctx
, GL_INVALID_ENUM
,
2095 "glTexImage%dD(target can't be compressed)", dimensions
);
2098 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2099 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2100 "glTexImage%dD(no compression for format)", dimensions
);
2104 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2105 "glTexImage%dD(border!=0)", dimensions
);
2110 /* additional checks for integer textures */
2111 if ((ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) &&
2112 (_mesa_is_enum_format_integer(format
) !=
2113 _mesa_is_enum_format_integer(internalFormat
))) {
2114 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2115 "glTexImage%dD(integer/non-integer format mismatch)",
2120 if (!mutable_tex_object(ctx
, target
)) {
2121 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2122 "glTexImage%dD(immutable texture)", dimensions
);
2126 /* if we get here, the parameters are OK */
2132 * Error checking for glCompressedTexImage[123]D().
2133 * Note that the width, height and depth values are not fully error checked
2135 * \return GL_TRUE if a error is found, GL_FALSE otherwise
2138 compressed_texture_error_check(struct gl_context
*ctx
, GLint dimensions
,
2139 GLenum target
, GLint level
,
2140 GLenum internalFormat
, GLsizei width
,
2141 GLsizei height
, GLsizei depth
, GLint border
,
2144 const GLint maxLevels
= _mesa_max_texture_levels(ctx
, target
);
2146 GLenum error
= GL_NO_ERROR
;
2147 char *reason
= ""; /* no error */
2149 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2151 error
= GL_INVALID_ENUM
;
2155 /* This will detect any invalid internalFormat value */
2156 if (!_mesa_is_compressed_format(ctx
, internalFormat
)) {
2157 reason
= "internalFormat";
2158 error
= GL_INVALID_ENUM
;
2162 switch (internalFormat
) {
2163 case GL_PALETTE4_RGB8_OES
:
2164 case GL_PALETTE4_RGBA8_OES
:
2165 case GL_PALETTE4_R5_G6_B5_OES
:
2166 case GL_PALETTE4_RGBA4_OES
:
2167 case GL_PALETTE4_RGB5_A1_OES
:
2168 case GL_PALETTE8_RGB8_OES
:
2169 case GL_PALETTE8_RGBA8_OES
:
2170 case GL_PALETTE8_R5_G6_B5_OES
:
2171 case GL_PALETTE8_RGBA4_OES
:
2172 case GL_PALETTE8_RGB5_A1_OES
:
2173 /* check level (note that level should be zero or less!) */
2174 if (level
> 0 || level
< -maxLevels
) {
2176 error
= GL_INVALID_VALUE
;
2180 if (dimensions
!= 2) {
2181 reason
= "compressed paletted textures must be 2D";
2182 error
= GL_INVALID_OPERATION
;
2186 /* Figure out the expected texture size (in bytes). This will be
2187 * checked against the actual size later.
2189 expectedSize
= _mesa_cpal_compressed_size(level
, internalFormat
,
2192 /* This is for the benefit of the TestProxyTexImage below. It expects
2193 * level to be non-negative. OES_compressed_paletted_texture uses a
2194 * weird mechanism where the level specified to glCompressedTexImage2D
2195 * is -(n-1) number of levels in the texture, and the data specifies the
2196 * complete mipmap stack. This is done to ensure the palette is the
2197 * same for all levels.
2204 if (level
< 0 || level
>= maxLevels
) {
2206 error
= GL_INVALID_VALUE
;
2210 /* Figure out the expected texture size (in bytes). This will be
2211 * checked against the actual size later.
2213 expectedSize
= compressed_tex_size(width
, height
, depth
, internalFormat
);
2217 /* This should really never fail */
2218 if (_mesa_base_tex_format(ctx
, internalFormat
) < 0) {
2219 reason
= "internalFormat";
2220 error
= GL_INVALID_ENUM
;
2224 /* No compressed formats support borders at this time */
2226 reason
= "border != 0";
2227 error
= GL_INVALID_VALUE
;
2231 /* For cube map, width must equal height */
2232 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2233 _mesa_is_cube_face(target
)) && width
!= height
) {
2234 reason
= "width != height";
2235 error
= GL_INVALID_VALUE
;
2239 /* check image size in bytes */
2240 if (expectedSize
!= imageSize
) {
2241 /* Per GL_ARB_texture_compression: GL_INVALID_VALUE is generated [...]
2242 * if <imageSize> is not consistent with the format, dimensions, and
2243 * contents of the specified image.
2245 reason
= "imageSize inconsistant with width/height/format";
2246 error
= GL_INVALID_VALUE
;
2250 if (!mutable_tex_object(ctx
, target
)) {
2251 reason
= "immutable texture";
2252 error
= GL_INVALID_OPERATION
;
2259 _mesa_error(ctx
, error
, "glCompressedTexImage%dD(%s)", dimensions
, reason
);
2266 * Test glTexSubImage[123]D() parameters for errors.
2268 * \param ctx GL context.
2269 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2270 * \param target texture target given by the user (already validated)
2271 * \param level image level given by the user.
2272 * \param xoffset sub-image x offset given by the user.
2273 * \param yoffset sub-image y offset given by the user.
2274 * \param zoffset sub-image z offset given by the user.
2275 * \param format pixel data format given by the user.
2276 * \param type pixel data type given by the user.
2277 * \param width image width given by the user.
2278 * \param height image height given by the user.
2279 * \param depth image depth given by the user.
2281 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2283 * Verifies each of the parameters against the constants specified in
2284 * __struct gl_contextRec::Const and the supported extensions, and according
2285 * to the OpenGL specification.
2288 texsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2289 GLenum target
, GLint level
,
2290 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2291 GLint width
, GLint height
, GLint depth
,
2292 GLenum format
, GLenum type
)
2294 struct gl_texture_object
*texObj
;
2295 struct gl_texture_image
*texImage
;
2298 /* check target (proxies not allowed) */
2299 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2300 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
2301 dimensions
, _mesa_lookup_enum_by_nr(target
));
2306 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2307 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(level=%d)",
2312 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2313 * combinations of format and type that can be used. Formats and types
2314 * that require additional extensions (e.g., GL_FLOAT requires
2315 * GL_OES_texture_float) are filtered elsewhere.
2317 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2318 err
= _mesa_es_error_check_format_and_type(format
, type
, dimensions
);
2319 if (err
!= GL_NO_ERROR
) {
2320 _mesa_error(ctx
, err
,
2321 "glTexSubImage%dD(format = %s, type = %s)",
2323 _mesa_lookup_enum_by_nr(format
),
2324 _mesa_lookup_enum_by_nr(type
));
2329 err
= _mesa_error_check_format_and_type(ctx
, format
, type
);
2330 if (err
!= GL_NO_ERROR
) {
2331 _mesa_error(ctx
, err
,
2332 "glTexSubImage%dD(incompatible format = %s, type = %s)",
2333 dimensions
, _mesa_lookup_enum_by_nr(format
),
2334 _mesa_lookup_enum_by_nr(type
));
2338 /* Get dest texture object / image pointers */
2339 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2341 /* must be out of memory */
2342 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage%dD()", dimensions
);
2346 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2348 /* non-existant texture level */
2349 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2350 "glTexSubImage%dD(invalid texture image)", dimensions
);
2354 if (error_check_subtexture_dimensions(ctx
, "glTexSubImage", dimensions
,
2355 texImage
, xoffset
, yoffset
, 0,
2356 width
, height
, 1)) {
2360 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2361 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2362 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2363 "glTexSubImage%dD(no compression for format)", dimensions
);
2368 if (ctx
->Version
>= 30 || ctx
->Extensions
.EXT_texture_integer
) {
2369 /* both source and dest must be integer-valued, or neither */
2370 if (_mesa_is_format_integer_color(texImage
->TexFormat
) !=
2371 _mesa_is_enum_format_integer(format
)) {
2372 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2373 "glTexSubImage%dD(integer/non-integer format mismatch)",
2384 * Test glCopyTexImage[12]D() parameters for errors.
2386 * \param ctx GL context.
2387 * \param dimensions texture image dimensions (must be 1, 2 or 3).
2388 * \param target texture target given by the user.
2389 * \param level image level given by the user.
2390 * \param internalFormat internal format given by the user.
2391 * \param width image width given by the user.
2392 * \param height image height given by the user.
2393 * \param border texture border.
2395 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2397 * Verifies each of the parameters against the constants specified in
2398 * __struct gl_contextRec::Const and the supported extensions, and according
2399 * to the OpenGL specification.
2402 copytexture_error_check( struct gl_context
*ctx
, GLuint dimensions
,
2403 GLenum target
, GLint level
, GLint internalFormat
,
2404 GLint width
, GLint height
, GLint border
)
2407 GLint rb_base_format
;
2408 struct gl_renderbuffer
*rb
;
2409 GLenum rb_internal_format
;
2412 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2413 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexImage%uD(target=%s)",
2414 dimensions
, _mesa_lookup_enum_by_nr(target
));
2419 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2420 _mesa_error(ctx
, GL_INVALID_VALUE
,
2421 "glCopyTexImage%dD(level=%d)", dimensions
, level
);
2425 /* Check that the source buffer is complete */
2426 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2427 if (ctx
->ReadBuffer
->_Status
== 0) {
2428 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2430 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2431 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2432 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2436 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2437 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2438 "glCopyTexImage%dD(multisample FBO)",
2445 if (border
< 0 || border
> 1 ||
2446 ((ctx
->API
!= API_OPENGL_COMPAT
||
2447 target
== GL_TEXTURE_RECTANGLE_NV
||
2448 target
== GL_PROXY_TEXTURE_RECTANGLE_NV
) && border
!= 0)) {
2449 _mesa_error(ctx
, GL_INVALID_VALUE
,
2450 "glCopyTexImage%dD(border=%d)", dimensions
, border
);
2454 rb
= _mesa_get_read_renderbuffer_for_format(ctx
, internalFormat
);
2456 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2457 "glCopyTexImage%dD(read buffer)", dimensions
);
2461 /* OpenGL ES 1.x and OpenGL ES 2.0 impose additional restrictions on the
2464 if (_mesa_is_gles(ctx
) && !_mesa_is_gles3(ctx
)) {
2465 switch (internalFormat
) {
2470 case GL_LUMINANCE_ALPHA
:
2473 _mesa_error(ctx
, GL_INVALID_VALUE
,
2474 "glCopyTexImage%dD(internalFormat)", dimensions
);
2479 baseFormat
= _mesa_base_tex_format(ctx
, internalFormat
);
2480 if (baseFormat
< 0) {
2481 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2482 "glCopyTexImage%dD(internalFormat)", dimensions
);
2486 rb_internal_format
= rb
->InternalFormat
;
2487 rb_base_format
= _mesa_base_tex_format(ctx
, rb
->InternalFormat
);
2488 if (_mesa_is_color_format(internalFormat
)) {
2489 if (rb_base_format
< 0) {
2490 _mesa_error(ctx
, GL_INVALID_VALUE
,
2491 "glCopyTexImage%dD(internalFormat)", dimensions
);
2496 if (_mesa_is_gles(ctx
)) {
2498 if (_mesa_base_format_component_count(baseFormat
) >
2499 _mesa_base_format_component_count(rb_base_format
)) {
2502 if (baseFormat
== GL_DEPTH_COMPONENT
||
2503 baseFormat
== GL_DEPTH_STENCIL
||
2504 rb_base_format
== GL_DEPTH_COMPONENT
||
2505 rb_base_format
== GL_DEPTH_STENCIL
||
2506 ((baseFormat
== GL_LUMINANCE_ALPHA
||
2507 baseFormat
== GL_ALPHA
) &&
2508 rb_base_format
!= GL_RGBA
) ||
2509 internalFormat
== GL_RGB9_E5
) {
2512 if (internalFormat
== GL_RGB9_E5
) {
2516 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2517 "glCopyTexImage%dD(internalFormat)", dimensions
);
2522 if (_mesa_is_gles3(ctx
)) {
2523 bool rb_is_srgb
= false;
2524 bool dst_is_srgb
= false;
2526 if (ctx
->Extensions
.EXT_framebuffer_sRGB
&&
2527 _mesa_get_format_color_encoding(rb
->Format
) == GL_SRGB
) {
2531 if (_mesa_get_linear_internalformat(internalFormat
) != internalFormat
) {
2535 if (rb_is_srgb
!= dst_is_srgb
) {
2536 /* Page 137 (page 149 of the PDF) in section 3.8.5 of the
2537 * OpenGLES 3.0.0 spec says:
2539 * "The error INVALID_OPERATION is also generated if the
2540 * value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING for the
2541 * framebuffer attachment corresponding to the read buffer
2542 * is LINEAR (see section 6.1.13) and internalformat is
2543 * one of the sRGB formats described in section 3.8.16, or
2544 * if the value of FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING is
2545 * SRGB and internalformat is not one of the sRGB formats."
2547 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2548 "glCopyTexImage%dD(srgb usage mismatch)", dimensions
);
2553 if (!_mesa_source_buffer_exists(ctx
, baseFormat
)) {
2554 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2555 "glCopyTexImage%dD(missing readbuffer)", dimensions
);
2559 /* From the EXT_texture_integer spec:
2561 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2562 * if the texture internalformat is an integer format and the read color
2563 * buffer is not an integer format, or if the internalformat is not an
2564 * integer format and the read color buffer is an integer format."
2566 if (_mesa_is_color_format(internalFormat
)) {
2567 bool is_int
= _mesa_is_enum_format_integer(internalFormat
);
2568 bool is_rbint
= _mesa_is_enum_format_integer(rb_internal_format
);
2569 if (is_int
|| is_rbint
) {
2570 if (is_int
!= is_rbint
) {
2571 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2572 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2574 } else if (_mesa_is_gles(ctx
) &&
2575 _mesa_is_enum_format_unsigned_int(internalFormat
) !=
2576 _mesa_is_enum_format_unsigned_int(rb_internal_format
)) {
2577 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2578 "glCopyTexImage%dD(signed vs unsigned integer)", dimensions
);
2584 if ((target
== GL_PROXY_TEXTURE_CUBE_MAP_ARB
||
2585 _mesa_is_cube_face(target
)) && width
!= height
) {
2586 _mesa_error(ctx
, GL_INVALID_VALUE
,
2587 "glTexImage2D(cube width != height)");
2591 if (_mesa_is_compressed_format(ctx
, internalFormat
)) {
2592 if (!target_can_be_compressed(ctx
, target
, internalFormat
)) {
2593 _mesa_error(ctx
, GL_INVALID_ENUM
,
2594 "glCopyTexImage%dD(target)", dimensions
);
2597 if (compressedteximage_only_format(ctx
, internalFormat
)) {
2598 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2599 "glCopyTexImage%dD(no compression for format)", dimensions
);
2603 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2604 "glCopyTexImage%dD(border!=0)", dimensions
);
2609 if (!mutable_tex_object(ctx
, target
)) {
2610 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2611 "glCopyTexImage%dD(immutable texture)", dimensions
);
2615 /* if we get here, the parameters are OK */
2621 * Test glCopyTexSubImage[12]D() parameters for errors.
2622 * \return GL_TRUE if an error was detected, or GL_FALSE if no errors.
2625 copytexsubimage_error_check(struct gl_context
*ctx
, GLuint dimensions
,
2626 GLenum target
, GLint level
,
2627 GLint xoffset
, GLint yoffset
, GLint zoffset
,
2628 GLint width
, GLint height
)
2630 struct gl_texture_object
*texObj
;
2631 struct gl_texture_image
*texImage
;
2633 /* Check that the source buffer is complete */
2634 if (_mesa_is_user_fbo(ctx
->ReadBuffer
)) {
2635 if (ctx
->ReadBuffer
->_Status
== 0) {
2636 _mesa_test_framebuffer_completeness(ctx
, ctx
->ReadBuffer
);
2638 if (ctx
->ReadBuffer
->_Status
!= GL_FRAMEBUFFER_COMPLETE_EXT
) {
2639 _mesa_error(ctx
, GL_INVALID_FRAMEBUFFER_OPERATION_EXT
,
2640 "glCopyTexImage%dD(invalid readbuffer)", dimensions
);
2644 if (ctx
->ReadBuffer
->Visual
.samples
> 0) {
2645 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2646 "glCopyTexSubImage%dD(multisample FBO)",
2652 /* check target (proxies not allowed) */
2653 if (!legal_texsubimage_target(ctx
, dimensions
, target
)) {
2654 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCopyTexSubImage%uD(target=%s)",
2655 dimensions
, _mesa_lookup_enum_by_nr(target
));
2660 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
2661 _mesa_error(ctx
, GL_INVALID_VALUE
,
2662 "glCopyTexSubImage%dD(level=%d)", dimensions
, level
);
2666 /* Get dest texture object / image pointers */
2667 texObj
= _mesa_get_current_tex_object(ctx
, target
);
2669 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexSubImage%dD()", dimensions
);
2673 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
2675 /* destination image does not exist */
2676 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2677 "glCopyTexSubImage%dD(invalid texture image)", dimensions
);
2681 if (error_check_subtexture_dimensions(ctx
, "glCopyTexSubImage",
2682 dimensions
, texImage
,
2683 xoffset
, yoffset
, zoffset
,
2684 width
, height
, 1)) {
2688 if (_mesa_is_format_compressed(texImage
->TexFormat
)) {
2689 if (compressedteximage_only_format(ctx
, texImage
->InternalFormat
)) {
2690 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2691 "glCopyTexSubImage%dD(no compression for format)", dimensions
);
2696 if (texImage
->InternalFormat
== GL_YCBCR_MESA
) {
2697 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glCopyTexSubImage2D");
2701 if (!_mesa_source_buffer_exists(ctx
, texImage
->_BaseFormat
)) {
2702 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2703 "glCopyTexSubImage%dD(missing readbuffer, format=0x%x)",
2704 dimensions
, texImage
->_BaseFormat
);
2708 /* From the EXT_texture_integer spec:
2710 * "INVALID_OPERATION is generated by CopyTexImage* and CopyTexSubImage*
2711 * if the texture internalformat is an integer format and the read color
2712 * buffer is not an integer format, or if the internalformat is not an
2713 * integer format and the read color buffer is an integer format."
2715 if (_mesa_is_color_format(texImage
->InternalFormat
)) {
2716 struct gl_renderbuffer
*rb
= ctx
->ReadBuffer
->_ColorReadBuffer
;
2718 if (_mesa_is_format_integer_color(rb
->Format
) !=
2719 _mesa_is_format_integer_color(texImage
->TexFormat
)) {
2720 _mesa_error(ctx
, GL_INVALID_OPERATION
,
2721 "glCopyTexImage%dD(integer vs non-integer)", dimensions
);
2726 /* if we get here, the parameters are OK */
2731 /** Callback info for walking over FBO hash table */
2734 struct gl_context
*ctx
;
2735 struct gl_texture_object
*texObj
;
2741 * Check render to texture callback. Called from _mesa_HashWalk().
2744 check_rtt_cb(GLuint key
, void *data
, void *userData
)
2746 struct gl_framebuffer
*fb
= (struct gl_framebuffer
*) data
;
2747 const struct cb_info
*info
= (struct cb_info
*) userData
;
2748 struct gl_context
*ctx
= info
->ctx
;
2749 const struct gl_texture_object
*texObj
= info
->texObj
;
2750 const GLuint level
= info
->level
, face
= info
->face
;
2752 /* If this is a user-created FBO */
2753 if (_mesa_is_user_fbo(fb
)) {
2755 /* check if any of the FBO's attachments point to 'texObj' */
2756 for (i
= 0; i
< BUFFER_COUNT
; i
++) {
2757 struct gl_renderbuffer_attachment
*att
= fb
->Attachment
+ i
;
2758 if (att
->Type
== GL_TEXTURE
&&
2759 att
->Texture
== texObj
&&
2760 att
->TextureLevel
== level
&&
2761 att
->CubeMapFace
== face
) {
2762 ASSERT(_mesa_get_attachment_teximage(att
));
2763 _mesa_update_texture_renderbuffer(ctx
, ctx
->DrawBuffer
, att
);
2764 /* Mark fb status as indeterminate to force re-validation */
2773 * When a texture image is specified we have to check if it's bound to
2774 * any framebuffer objects (render to texture) in order to detect changes
2775 * in size or format since that effects FBO completeness.
2776 * Any FBOs rendering into the texture must be re-validated.
2779 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2780 struct gl_texture_object
*texObj
,
2781 GLuint face
, GLuint level
)
2783 /* Only check this texture if it's been marked as RenderToTexture */
2784 if (texObj
->_RenderToTexture
) {
2785 struct cb_info info
;
2787 info
.texObj
= texObj
;
2790 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2796 * If the texture object's GenerateMipmap flag is set and we've
2797 * changed the texture base level image, regenerate the rest of the
2798 * mipmap levels now.
2801 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2802 struct gl_texture_object
*texObj
, GLint level
)
2804 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2805 if (texObj
->GenerateMipmap
&&
2806 level
== texObj
->BaseLevel
&&
2807 level
< texObj
->MaxLevel
) {
2808 ASSERT(ctx
->Driver
.GenerateMipmap
);
2809 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2814 /** Debug helper: override the user-requested internal format */
2816 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2819 if (internalFormat
== GL_RGBA16F_ARB
||
2820 internalFormat
== GL_RGBA32F_ARB
) {
2821 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2824 else if (internalFormat
== GL_RGB16F_ARB
||
2825 internalFormat
== GL_RGB32F_ARB
) {
2826 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2829 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2830 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2831 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2832 return GL_LUMINANCE_ALPHA
;
2834 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2835 internalFormat
== GL_LUMINANCE32F_ARB
) {
2836 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2837 return GL_LUMINANCE
;
2839 else if (internalFormat
== GL_ALPHA16F_ARB
||
2840 internalFormat
== GL_ALPHA32F_ARB
) {
2841 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2845 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2846 internalFormat = GL_RGBA;
2850 return internalFormat
;
2853 return internalFormat
;
2859 * Choose the actual hardware format for a texture image.
2860 * Try to use the same format as the previous image level when possible.
2861 * Otherwise, ask the driver for the best format.
2862 * It's important to try to choose a consistant format for all levels
2863 * for efficient texture memory layout/allocation. In particular, this
2864 * comes up during automatic mipmap generation.
2867 _mesa_choose_texture_format(struct gl_context
*ctx
,
2868 struct gl_texture_object
*texObj
,
2869 GLenum target
, GLint level
,
2870 GLenum internalFormat
, GLenum format
, GLenum type
)
2874 /* see if we've already chosen a format for the previous level */
2876 struct gl_texture_image
*prevImage
=
2877 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2878 /* See if the prev level is defined and has an internal format which
2879 * matches the new internal format.
2882 prevImage
->Width
> 0 &&
2883 prevImage
->InternalFormat
== internalFormat
) {
2884 /* use the same format */
2885 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2886 return prevImage
->TexFormat
;
2890 /* If the application requested compression to an S3TC format but we don't
2891 * have the DTXn library, force a generic compressed format instead.
2893 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2894 const GLenum before
= internalFormat
;
2896 switch (internalFormat
) {
2897 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2898 if (!ctx
->Mesa_DXTn
)
2899 internalFormat
= GL_COMPRESSED_RGB
;
2901 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2902 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2903 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2904 if (!ctx
->Mesa_DXTn
)
2905 internalFormat
= GL_COMPRESSED_RGBA
;
2911 if (before
!= internalFormat
) {
2913 "DXT compression requested (%s), "
2914 "but libtxc_dxtn library not installed. Using %s "
2916 _mesa_lookup_enum_by_nr(before
),
2917 _mesa_lookup_enum_by_nr(internalFormat
));
2921 /* choose format from scratch */
2922 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2924 ASSERT(f
!= MESA_FORMAT_NONE
);
2929 * Adjust pixel unpack params and image dimensions to strip off the
2930 * one-pixel texture border.
2932 * Gallium and intel don't support texture borders. They've seldem been used
2933 * and seldom been implemented correctly anyway.
2935 * \param unpackNew returns the new pixel unpack parameters
2938 strip_texture_border(GLenum target
,
2939 GLint
*width
, GLint
*height
, GLint
*depth
,
2940 const struct gl_pixelstore_attrib
*unpack
,
2941 struct gl_pixelstore_attrib
*unpackNew
)
2947 *unpackNew
= *unpack
;
2949 if (unpackNew
->RowLength
== 0)
2950 unpackNew
->RowLength
= *width
;
2952 if (unpackNew
->ImageHeight
== 0)
2953 unpackNew
->ImageHeight
= *height
;
2955 assert(*width
>= 3);
2956 unpackNew
->SkipPixels
++; /* skip the border */
2957 *width
= *width
- 2; /* reduce the width by two border pixels */
2959 /* The min height of a texture with a border is 3 */
2960 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2961 unpackNew
->SkipRows
++; /* skip the border */
2962 *height
= *height
- 2; /* reduce the height by two border pixels */
2965 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
&& target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2966 unpackNew
->SkipImages
++; /* skip the border */
2967 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2973 * Common code to implement all the glTexImage1D/2D/3D functions
2974 * as well as glCompressedTexImage1D/2D/3D.
2975 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2976 * \param format the user's image format (only used if !compressed)
2977 * \param type the user's image type (only used if !compressed)
2978 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2981 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2982 GLenum target
, GLint level
, GLint internalFormat
,
2983 GLsizei width
, GLsizei height
, GLsizei depth
,
2984 GLint border
, GLenum format
, GLenum type
,
2985 GLsizei imageSize
, const GLvoid
*pixels
)
2987 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2988 struct gl_pixelstore_attrib unpack_no_border
;
2989 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2990 struct gl_texture_object
*texObj
;
2991 gl_format texFormat
;
2992 GLboolean dimensionsOK
, sizeOK
;
2994 FLUSH_VERTICES(ctx
, 0);
2996 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
2999 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3001 _mesa_lookup_enum_by_nr(target
), level
,
3002 _mesa_lookup_enum_by_nr(internalFormat
),
3003 width
, height
, depth
, border
, pixels
);
3006 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3008 _mesa_lookup_enum_by_nr(target
), level
,
3009 _mesa_lookup_enum_by_nr(internalFormat
),
3010 width
, height
, depth
, border
,
3011 _mesa_lookup_enum_by_nr(format
),
3012 _mesa_lookup_enum_by_nr(type
), pixels
);
3015 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3017 /* target error checking */
3018 if (!legal_teximage_target(ctx
, dims
, target
)) {
3019 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3020 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3024 /* general error checking */
3026 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3028 width
, height
, depth
,
3033 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3034 format
, type
, width
, height
, depth
, border
))
3038 /* Here we convert a cpal compressed image into a regular glTexImage2D
3039 * call by decompressing the texture. If we really want to support cpal
3040 * textures in any driver this would have to be changed.
3042 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3043 switch (internalFormat
) {
3044 case GL_PALETTE4_RGB8_OES
:
3045 case GL_PALETTE4_RGBA8_OES
:
3046 case GL_PALETTE4_R5_G6_B5_OES
:
3047 case GL_PALETTE4_RGBA4_OES
:
3048 case GL_PALETTE4_RGB5_A1_OES
:
3049 case GL_PALETTE8_RGB8_OES
:
3050 case GL_PALETTE8_RGBA8_OES
:
3051 case GL_PALETTE8_R5_G6_B5_OES
:
3052 case GL_PALETTE8_RGBA4_OES
:
3053 case GL_PALETTE8_RGB5_A1_OES
:
3054 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3055 width
, height
, imageSize
, pixels
);
3060 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3064 /* For glCompressedTexImage() the driver has no choice about the
3065 * texture format since we'll never transcode the user's compressed
3066 * image data. The internalFormat was error checked earlier.
3068 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3071 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3072 internalFormat
, format
, type
);
3075 assert(texFormat
!= MESA_FORMAT_NONE
);
3077 /* check that width, height, depth are legal for the mipmap level */
3078 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3079 height
, depth
, border
);
3081 /* check that the texture won't take too much memory, etc */
3082 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3084 width
, height
, depth
, border
);
3086 if (_mesa_is_proxy_texture(target
)) {
3087 /* Proxy texture: just clear or set state depending on error checking */
3088 struct gl_texture_image
*texImage
=
3089 get_proxy_tex_image(ctx
, target
, level
);
3092 return; /* GL_OUT_OF_MEMORY already recorded */
3094 if (dimensionsOK
&& sizeOK
) {
3095 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3096 border
, internalFormat
, texFormat
);
3099 clear_teximage_fields(texImage
);
3103 /* non-proxy target */
3104 const GLuint face
= _mesa_tex_target_to_face(target
);
3105 struct gl_texture_image
*texImage
;
3107 if (!dimensionsOK
) {
3108 _mesa_error(ctx
, GL_INVALID_VALUE
,
3109 "glTexImage%uD(invalid width or height or depth)",
3115 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3116 "glTexImage%uD(image too large)", dims
);
3120 /* Allow a hardware driver to just strip out the border, to provide
3121 * reliable but slightly incorrect hardware rendering instead of
3122 * rarely-tested software fallback rendering.
3124 if (border
&& ctx
->Const
.StripTextureBorder
) {
3125 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3128 unpack
= &unpack_no_border
;
3131 if (ctx
->NewState
& _NEW_PIXEL
)
3132 _mesa_update_state(ctx
);
3134 _mesa_lock_texture(ctx
, texObj
);
3136 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3139 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3142 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3144 _mesa_init_teximage_fields(ctx
, texImage
,
3145 width
, height
, depth
,
3146 border
, internalFormat
, texFormat
);
3148 /* Give the texture to the driver. <pixels> may be null. */
3149 if (width
> 0 && height
> 0 && depth
> 0) {
3151 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3155 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3156 type
, pixels
, unpack
);
3160 check_gen_mipmap(ctx
, target
, texObj
, level
);
3162 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3164 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3167 _mesa_unlock_texture(ctx
, texObj
);
3174 * Called from the API. Note that width includes the border.
3177 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3178 GLsizei width
, GLint border
, GLenum format
,
3179 GLenum type
, const GLvoid
*pixels
)
3181 GET_CURRENT_CONTEXT(ctx
);
3182 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3183 border
, format
, type
, 0, pixels
);
3188 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3189 GLsizei width
, GLsizei height
, GLint border
,
3190 GLenum format
, GLenum type
,
3191 const GLvoid
*pixels
)
3193 GET_CURRENT_CONTEXT(ctx
);
3194 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3195 border
, format
, type
, 0, pixels
);
3200 * Called by the API or display list executor.
3201 * Note that width and height include the border.
3204 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3205 GLsizei width
, GLsizei height
, GLsizei depth
,
3206 GLint border
, GLenum format
, GLenum type
,
3207 const GLvoid
*pixels
)
3209 GET_CURRENT_CONTEXT(ctx
);
3210 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3211 width
, height
, depth
,
3212 border
, format
, type
, 0, pixels
);
3217 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3218 GLsizei width
, GLsizei height
, GLsizei depth
,
3219 GLint border
, GLenum format
, GLenum type
,
3220 const GLvoid
*pixels
)
3222 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3223 depth
, border
, format
, type
, pixels
);
3228 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3230 struct gl_texture_object
*texObj
;
3231 struct gl_texture_image
*texImage
;
3233 GET_CURRENT_CONTEXT(ctx
);
3234 FLUSH_VERTICES(ctx
, 0);
3238 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3240 case GL_TEXTURE_EXTERNAL_OES
:
3241 valid_target
= ctx
->Extensions
.OES_EGL_image_external
;
3244 valid_target
= false;
3248 if (!valid_target
) {
3249 _mesa_error(ctx
, GL_INVALID_ENUM
,
3250 "glEGLImageTargetTexture2D(target=%d)", target
);
3255 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3256 "glEGLImageTargetTexture2D(image=%p)", image
);
3260 if (ctx
->NewState
& _NEW_PIXEL
)
3261 _mesa_update_state(ctx
);
3263 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3264 _mesa_lock_texture(ctx
, texObj
);
3266 if (texObj
->Immutable
) {
3267 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3268 "glEGLImageTargetTexture2D(texture is immutable)");
3269 _mesa_unlock_texture(ctx
, texObj
);
3273 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3275 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3277 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3279 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3280 texObj
, texImage
, image
);
3282 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3284 _mesa_unlock_texture(ctx
, texObj
);
3291 * Implement all the glTexSubImage1/2/3D() functions.
3294 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3295 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3296 GLsizei width
, GLsizei height
, GLsizei depth
,
3297 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3299 struct gl_texture_object
*texObj
;
3300 struct gl_texture_image
*texImage
;
3302 FLUSH_VERTICES(ctx
, 0);
3304 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3305 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3307 _mesa_lookup_enum_by_nr(target
), level
,
3308 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3309 _mesa_lookup_enum_by_nr(format
),
3310 _mesa_lookup_enum_by_nr(type
), pixels
);
3312 /* check target (proxies not allowed) */
3313 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3314 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3315 dims
, _mesa_lookup_enum_by_nr(target
));
3319 if (ctx
->NewState
& _NEW_PIXEL
)
3320 _mesa_update_state(ctx
);
3322 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3323 xoffset
, yoffset
, zoffset
,
3324 width
, height
, depth
, format
, type
)) {
3325 return; /* error was detected */
3328 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3330 _mesa_lock_texture(ctx
, texObj
);
3332 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3334 if (width
> 0 && height
> 0 && depth
> 0) {
3335 /* If we have a border, offset=-1 is legal. Bias by border width. */
3338 if (target
!= GL_TEXTURE_2D_ARRAY
)
3339 zoffset
+= texImage
->Border
;
3342 if (target
!= GL_TEXTURE_1D_ARRAY
)
3343 yoffset
+= texImage
->Border
;
3346 xoffset
+= texImage
->Border
;
3349 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3350 xoffset
, yoffset
, zoffset
,
3351 width
, height
, depth
,
3352 format
, type
, pixels
, &ctx
->Unpack
);
3354 check_gen_mipmap(ctx
, target
, texObj
, level
);
3356 ctx
->NewState
|= _NEW_TEXTURE
;
3359 _mesa_unlock_texture(ctx
, texObj
);
3364 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3365 GLint xoffset
, GLsizei width
,
3366 GLenum format
, GLenum type
,
3367 const GLvoid
*pixels
)
3369 GET_CURRENT_CONTEXT(ctx
);
3370 texsubimage(ctx
, 1, target
, level
,
3373 format
, type
, pixels
);
3378 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3379 GLint xoffset
, GLint yoffset
,
3380 GLsizei width
, GLsizei height
,
3381 GLenum format
, GLenum type
,
3382 const GLvoid
*pixels
)
3384 GET_CURRENT_CONTEXT(ctx
);
3385 texsubimage(ctx
, 2, target
, level
,
3386 xoffset
, yoffset
, 0,
3388 format
, type
, pixels
);
3394 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3395 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3396 GLsizei width
, GLsizei height
, GLsizei depth
,
3397 GLenum format
, GLenum type
,
3398 const GLvoid
*pixels
)
3400 GET_CURRENT_CONTEXT(ctx
);
3401 texsubimage(ctx
, 3, target
, level
,
3402 xoffset
, yoffset
, zoffset
,
3403 width
, height
, depth
,
3404 format
, type
, pixels
);
3410 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3411 * from. This depends on whether the texture contains color or depth values.
3413 static struct gl_renderbuffer
*
3414 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3416 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3417 /* reading from depth/stencil buffer */
3418 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3421 /* copying from color buffer */
3422 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3429 * Implement the glCopyTexImage1/2D() functions.
3432 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3433 GLenum target
, GLint level
, GLenum internalFormat
,
3434 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3436 struct gl_texture_object
*texObj
;
3437 struct gl_texture_image
*texImage
;
3438 const GLuint face
= _mesa_tex_target_to_face(target
);
3439 gl_format texFormat
;
3441 FLUSH_VERTICES(ctx
, 0);
3443 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3444 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3446 _mesa_lookup_enum_by_nr(target
), level
,
3447 _mesa_lookup_enum_by_nr(internalFormat
),
3448 x
, y
, width
, height
, border
);
3450 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3451 _mesa_update_state(ctx
);
3453 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3454 width
, height
, border
))
3457 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3459 _mesa_error(ctx
, GL_INVALID_VALUE
,
3460 "glCopyTexImage%uD(invalid width or height)", dims
);
3464 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3467 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3468 internalFormat
, GL_NONE
, GL_NONE
);
3469 assert(texFormat
!= MESA_FORMAT_NONE
);
3471 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3473 width
, height
, 1, border
)) {
3474 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3475 "glCopyTexImage%uD(image too large)", dims
);
3479 if (border
&& ctx
->Const
.StripTextureBorder
) {
3481 width
-= border
* 2;
3484 height
-= border
* 2;
3489 _mesa_lock_texture(ctx
, texObj
);
3491 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3494 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3497 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3499 /* Free old texture image */
3500 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3502 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3503 border
, internalFormat
, texFormat
);
3505 if (width
&& height
) {
3506 /* Allocate texture memory (no pixel data yet) */
3507 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3509 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3511 struct gl_renderbuffer
*srcRb
=
3512 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3514 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
3515 srcRb
, srcX
, srcY
, width
, height
);
3518 check_gen_mipmap(ctx
, target
, texObj
, level
);
3521 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3523 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3526 _mesa_unlock_texture(ctx
, texObj
);
3532 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3533 GLenum internalFormat
,
3535 GLsizei width
, GLint border
)
3537 GET_CURRENT_CONTEXT(ctx
);
3538 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3544 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3545 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3548 GET_CURRENT_CONTEXT(ctx
);
3549 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3550 x
, y
, width
, height
, border
);
3556 * Implementation for glCopyTexSubImage1/2/3D() functions.
3559 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3560 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3561 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3563 struct gl_texture_object
*texObj
;
3564 struct gl_texture_image
*texImage
;
3566 FLUSH_VERTICES(ctx
, 0);
3568 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3569 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3571 _mesa_lookup_enum_by_nr(target
),
3572 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3574 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3575 _mesa_update_state(ctx
);
3577 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3578 xoffset
, yoffset
, zoffset
, width
, height
)) {
3582 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3584 _mesa_lock_texture(ctx
, texObj
);
3586 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3588 /* If we have a border, offset=-1 is legal. Bias by border width. */
3591 if (target
!= GL_TEXTURE_2D_ARRAY
)
3592 zoffset
+= texImage
->Border
;
3595 if (target
!= GL_TEXTURE_1D_ARRAY
)
3596 yoffset
+= texImage
->Border
;
3599 xoffset
+= texImage
->Border
;
3602 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3604 struct gl_renderbuffer
*srcRb
=
3605 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3607 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3608 xoffset
, yoffset
, zoffset
,
3609 srcRb
, x
, y
, width
, height
);
3611 check_gen_mipmap(ctx
, target
, texObj
, level
);
3613 ctx
->NewState
|= _NEW_TEXTURE
;
3616 _mesa_unlock_texture(ctx
, texObj
);
3621 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3622 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3624 GET_CURRENT_CONTEXT(ctx
);
3625 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3631 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3632 GLint xoffset
, GLint yoffset
,
3633 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3635 GET_CURRENT_CONTEXT(ctx
);
3636 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3643 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3644 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3645 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3647 GET_CURRENT_CONTEXT(ctx
);
3648 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3649 x
, y
, width
, height
);
3655 /**********************************************************************/
3656 /****** Compressed Textures ******/
3657 /**********************************************************************/
3661 * Error checking for glCompressedTexSubImage[123]D().
3662 * \return error code or GL_NO_ERROR.
3665 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3666 GLenum target
, GLint level
,
3667 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3668 GLsizei width
, GLsizei height
, GLsizei depth
,
3669 GLenum format
, GLsizei imageSize
)
3671 struct gl_texture_object
*texObj
;
3672 struct gl_texture_image
*texImage
;
3680 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3681 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3682 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3683 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3684 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3685 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3689 targetOK
= GL_FALSE
;
3694 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3698 /* no 1D compressed textures at this time */
3699 targetOK
= GL_FALSE
;
3704 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3709 /* this will catch any invalid compressed format token */
3710 if (!_mesa_is_compressed_format(ctx
, format
)) {
3711 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3716 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3717 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3722 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3723 if (expectedSize
!= imageSize
) {
3724 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3729 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3731 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3732 "glCompressedTexSubImage%uD()", dims
);
3736 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3738 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3739 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3743 if ((GLint
) format
!= texImage
->InternalFormat
) {
3744 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3745 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3749 if (compressedteximage_only_format(ctx
, format
)) {
3750 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3751 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3756 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3757 texImage
, xoffset
, yoffset
, zoffset
,
3758 width
, height
, depth
)) {
3767 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3768 GLenum internalFormat
, GLsizei width
,
3769 GLint border
, GLsizei imageSize
,
3772 GET_CURRENT_CONTEXT(ctx
);
3773 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3774 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3779 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3780 GLenum internalFormat
, GLsizei width
,
3781 GLsizei height
, GLint border
, GLsizei imageSize
,
3784 GET_CURRENT_CONTEXT(ctx
);
3785 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3786 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3791 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3792 GLenum internalFormat
, GLsizei width
,
3793 GLsizei height
, GLsizei depth
, GLint border
,
3794 GLsizei imageSize
, const GLvoid
*data
)
3796 GET_CURRENT_CONTEXT(ctx
);
3797 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3798 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3803 * Common helper for glCompressedTexSubImage1/2/3D().
3806 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3807 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3808 GLsizei width
, GLsizei height
, GLsizei depth
,
3809 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3811 struct gl_texture_object
*texObj
;
3812 struct gl_texture_image
*texImage
;
3813 GET_CURRENT_CONTEXT(ctx
);
3814 FLUSH_VERTICES(ctx
, 0);
3816 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3817 xoffset
, yoffset
, zoffset
,
3818 width
, height
, depth
,
3819 format
, imageSize
)) {
3823 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3825 _mesa_lock_texture(ctx
, texObj
);
3827 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3830 if (width
> 0 && height
> 0 && depth
> 0) {
3831 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3832 xoffset
, yoffset
, zoffset
,
3833 width
, height
, depth
,
3834 format
, imageSize
, data
);
3836 check_gen_mipmap(ctx
, target
, texObj
, level
);
3838 ctx
->NewState
|= _NEW_TEXTURE
;
3841 _mesa_unlock_texture(ctx
, texObj
);
3846 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3847 GLsizei width
, GLenum format
,
3848 GLsizei imageSize
, const GLvoid
*data
)
3850 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3851 format
, imageSize
, data
);
3856 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3857 GLint yoffset
, GLsizei width
, GLsizei height
,
3858 GLenum format
, GLsizei imageSize
,
3861 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3862 width
, height
, 1, format
, imageSize
, data
);
3867 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3868 GLint yoffset
, GLint zoffset
, GLsizei width
,
3869 GLsizei height
, GLsizei depth
, GLenum format
,
3870 GLsizei imageSize
, const GLvoid
*data
)
3872 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3873 width
, height
, depth
, format
, imageSize
, data
);
3877 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3879 switch (internalFormat
) {
3881 return MESA_FORMAT_A8
;
3883 return MESA_FORMAT_A16
;
3884 case GL_ALPHA16F_ARB
:
3885 return MESA_FORMAT_ALPHA_FLOAT16
;
3886 case GL_ALPHA32F_ARB
:
3887 return MESA_FORMAT_ALPHA_FLOAT32
;
3888 case GL_ALPHA8I_EXT
:
3889 return MESA_FORMAT_ALPHA_INT8
;
3890 case GL_ALPHA16I_EXT
:
3891 return MESA_FORMAT_ALPHA_INT16
;
3892 case GL_ALPHA32I_EXT
:
3893 return MESA_FORMAT_ALPHA_INT32
;
3894 case GL_ALPHA8UI_EXT
:
3895 return MESA_FORMAT_ALPHA_UINT8
;
3896 case GL_ALPHA16UI_EXT
:
3897 return MESA_FORMAT_ALPHA_UINT16
;
3898 case GL_ALPHA32UI_EXT
:
3899 return MESA_FORMAT_ALPHA_UINT32
;
3901 return MESA_FORMAT_L8
;
3902 case GL_LUMINANCE16
:
3903 return MESA_FORMAT_L16
;
3904 case GL_LUMINANCE16F_ARB
:
3905 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3906 case GL_LUMINANCE32F_ARB
:
3907 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3908 case GL_LUMINANCE8I_EXT
:
3909 return MESA_FORMAT_LUMINANCE_INT8
;
3910 case GL_LUMINANCE16I_EXT
:
3911 return MESA_FORMAT_LUMINANCE_INT16
;
3912 case GL_LUMINANCE32I_EXT
:
3913 return MESA_FORMAT_LUMINANCE_INT32
;
3914 case GL_LUMINANCE8UI_EXT
:
3915 return MESA_FORMAT_LUMINANCE_UINT8
;
3916 case GL_LUMINANCE16UI_EXT
:
3917 return MESA_FORMAT_LUMINANCE_UINT16
;
3918 case GL_LUMINANCE32UI_EXT
:
3919 return MESA_FORMAT_LUMINANCE_UINT32
;
3920 case GL_LUMINANCE8_ALPHA8
:
3921 return MESA_FORMAT_AL88
;
3922 case GL_LUMINANCE16_ALPHA16
:
3923 return MESA_FORMAT_AL1616
;
3924 case GL_LUMINANCE_ALPHA16F_ARB
:
3925 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3926 case GL_LUMINANCE_ALPHA32F_ARB
:
3927 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3928 case GL_LUMINANCE_ALPHA8I_EXT
:
3929 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3930 case GL_LUMINANCE_ALPHA16I_EXT
:
3931 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3932 case GL_LUMINANCE_ALPHA32I_EXT
:
3933 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3934 case GL_LUMINANCE_ALPHA8UI_EXT
:
3935 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3936 case GL_LUMINANCE_ALPHA16UI_EXT
:
3937 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3938 case GL_LUMINANCE_ALPHA32UI_EXT
:
3939 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3941 return MESA_FORMAT_I8
;
3942 case GL_INTENSITY16
:
3943 return MESA_FORMAT_I16
;
3944 case GL_INTENSITY16F_ARB
:
3945 return MESA_FORMAT_INTENSITY_FLOAT16
;
3946 case GL_INTENSITY32F_ARB
:
3947 return MESA_FORMAT_INTENSITY_FLOAT32
;
3948 case GL_INTENSITY8I_EXT
:
3949 return MESA_FORMAT_INTENSITY_INT8
;
3950 case GL_INTENSITY16I_EXT
:
3951 return MESA_FORMAT_INTENSITY_INT16
;
3952 case GL_INTENSITY32I_EXT
:
3953 return MESA_FORMAT_INTENSITY_INT32
;
3954 case GL_INTENSITY8UI_EXT
:
3955 return MESA_FORMAT_INTENSITY_UINT8
;
3956 case GL_INTENSITY16UI_EXT
:
3957 return MESA_FORMAT_INTENSITY_UINT16
;
3958 case GL_INTENSITY32UI_EXT
:
3959 return MESA_FORMAT_INTENSITY_UINT32
;
3961 return MESA_FORMAT_RGBA8888_REV
;
3963 return MESA_FORMAT_RGBA_16
;
3964 case GL_RGBA16F_ARB
:
3965 return MESA_FORMAT_RGBA_FLOAT16
;
3966 case GL_RGBA32F_ARB
:
3967 return MESA_FORMAT_RGBA_FLOAT32
;
3969 return MESA_FORMAT_RGBA_INT8
;
3970 case GL_RGBA16I_EXT
:
3971 return MESA_FORMAT_RGBA_INT16
;
3972 case GL_RGBA32I_EXT
:
3973 return MESA_FORMAT_RGBA_INT32
;
3974 case GL_RGBA8UI_EXT
:
3975 return MESA_FORMAT_RGBA_UINT8
;
3976 case GL_RGBA16UI_EXT
:
3977 return MESA_FORMAT_RGBA_UINT16
;
3978 case GL_RGBA32UI_EXT
:
3979 return MESA_FORMAT_RGBA_UINT32
;
3982 return MESA_FORMAT_GR88
;
3984 return MESA_FORMAT_GR1616
;
3986 return MESA_FORMAT_RG_FLOAT16
;
3988 return MESA_FORMAT_RG_FLOAT32
;
3990 return MESA_FORMAT_RG_INT8
;
3992 return MESA_FORMAT_RG_INT16
;
3994 return MESA_FORMAT_RG_INT32
;
3996 return MESA_FORMAT_RG_UINT8
;
3998 return MESA_FORMAT_RG_UINT16
;
4000 return MESA_FORMAT_RG_UINT32
;
4003 return MESA_FORMAT_R8
;
4005 return MESA_FORMAT_R16
;
4007 return MESA_FORMAT_R_FLOAT16
;
4009 return MESA_FORMAT_R_FLOAT32
;
4011 return MESA_FORMAT_R_INT8
;
4013 return MESA_FORMAT_R_INT16
;
4015 return MESA_FORMAT_R_INT32
;
4017 return MESA_FORMAT_R_UINT8
;
4019 return MESA_FORMAT_R_UINT16
;
4021 return MESA_FORMAT_R_UINT32
;
4024 return MESA_FORMAT_RGB_FLOAT32
;
4026 return MESA_FORMAT_RGB_UINT32
;
4028 return MESA_FORMAT_RGB_INT32
;
4031 return MESA_FORMAT_NONE
;
4036 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4038 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4041 if (format
== MESA_FORMAT_NONE
)
4042 return MESA_FORMAT_NONE
;
4044 datatype
= _mesa_get_format_datatype(format
);
4045 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4046 return MESA_FORMAT_NONE
;
4048 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4049 return MESA_FORMAT_NONE
;
4051 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
4052 * any mention of R/RG formats, but they appear in the GL 3.1 core
4055 if (ctx
->Version
<= 30) {
4056 GLenum base_format
= _mesa_get_format_base_format(format
);
4058 if (base_format
== GL_R
|| base_format
== GL_RG
)
4059 return MESA_FORMAT_NONE
;
4062 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4063 GLenum base_format
= _mesa_get_format_base_format(format
);
4064 if (base_format
== GL_RGB
)
4065 return MESA_FORMAT_NONE
;
4072 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4073 struct gl_buffer_object
*bufObj
,
4074 GLintptr offset
, GLsizeiptr size
)
4076 struct gl_texture_object
*texObj
;
4079 FLUSH_VERTICES(ctx
, 0);
4081 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4082 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4086 format
= validate_texbuffer_format(ctx
, internalFormat
);
4087 if (format
== MESA_FORMAT_NONE
) {
4088 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4093 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4095 _mesa_lock_texture(ctx
, texObj
);
4097 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4098 texObj
->BufferObjectFormat
= internalFormat
;
4099 texObj
->_BufferObjectFormat
= format
;
4100 texObj
->BufferOffset
= offset
;
4101 texObj
->BufferSize
= size
;
4103 _mesa_unlock_texture(ctx
, texObj
);
4106 /** GL_ARB_texture_buffer_object */
4108 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4110 struct gl_buffer_object
*bufObj
;
4112 GET_CURRENT_CONTEXT(ctx
);
4114 /* NOTE: ARB_texture_buffer_object has interactions with
4115 * the compatibility profile that are not implemented.
4117 if (!(ctx
->API
== API_OPENGL_CORE
&&
4118 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4119 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4123 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4124 if (!bufObj
&& buffer
) {
4125 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4129 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4132 /** GL_ARB_texture_buffer_range */
4134 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4135 GLintptr offset
, GLsizeiptr size
)
4137 struct gl_buffer_object
*bufObj
;
4139 GET_CURRENT_CONTEXT(ctx
);
4141 if (!(ctx
->API
== API_OPENGL_CORE
&&
4142 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4143 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4147 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4151 (offset
+ size
) > bufObj
->Size
) {
4152 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4155 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4156 _mesa_error(ctx
, GL_INVALID_VALUE
,
4157 "glTexBufferRange(invalid offset alignment)");
4160 } else if (buffer
) {
4161 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4169 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4173 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4175 /* Everything that is allowed for renderbuffers,
4176 * except for a base format of GL_STENCIL_INDEX.
4178 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4179 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4182 /** GL_ARB_texture_multisample */
4184 check_multisample_target(GLuint dims
, GLenum target
)
4187 case GL_TEXTURE_2D_MULTISAMPLE
:
4188 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4191 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4192 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4201 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4202 GLint internalformat
, GLsizei width
, GLsizei height
,
4203 GLsizei depth
, GLboolean fixedsamplelocations
,
4204 GLboolean immutable
, const char *func
)
4206 struct gl_texture_object
*texObj
;
4207 struct gl_texture_image
*texImage
;
4208 GLboolean sizeOK
, dimensionsOK
;
4209 gl_format texFormat
;
4210 GLenum sample_count_error
;
4212 GET_CURRENT_CONTEXT(ctx
);
4214 if (!(ctx
->Extensions
.ARB_texture_multisample
4215 && _mesa_is_desktop_gl(ctx
))) {
4216 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4220 if (!check_multisample_target(dims
, target
)) {
4221 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4225 /* check that the specified internalformat is color/depth/stencil-renderable;
4226 * refer GL3.1 spec 4.4.4
4229 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4230 _mesa_error(ctx
, GL_INVALID_ENUM
,
4231 "%s(internalformat=%s not legal for immutable-format)",
4232 func
, _mesa_lookup_enum_by_nr(internalformat
));
4236 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4237 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4238 "%s(internalformat=%s)",
4239 func
, _mesa_lookup_enum_by_nr(internalformat
));
4243 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4244 internalformat
, samples
);
4245 if (sample_count_error
!= GL_NO_ERROR
) {
4246 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4250 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4252 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4253 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4254 "%s(texture object 0)",
4259 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4261 if (texImage
== NULL
) {
4262 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4266 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4267 internalformat
, GL_NONE
, GL_NONE
);
4268 assert(texFormat
!= MESA_FORMAT_NONE
);
4270 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4271 width
, height
, depth
, 0);
4273 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4274 width
, height
, depth
, 0);
4276 if (_mesa_is_proxy_texture(target
)) {
4277 if (dimensionsOK
&& sizeOK
) {
4278 _mesa_init_teximage_fields(ctx
, texImage
,
4279 width
, height
, depth
, 0, internalformat
, texFormat
);
4280 texImage
->NumSamples
= samples
;
4281 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4284 /* clear all image fields */
4285 _mesa_init_teximage_fields(ctx
, texImage
,
4286 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4290 if (!dimensionsOK
) {
4291 _mesa_error(ctx
, GL_INVALID_VALUE
,
4292 "%s(invalid width or height)", func
);
4297 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4298 "%s(texture too large)", func
);
4302 /* Check if texObj->Immutable is set */
4303 if (texObj
->Immutable
) {
4304 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4308 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4310 _mesa_init_teximage_fields(ctx
, texImage
,
4311 width
, height
, depth
, 0, internalformat
, texFormat
);
4313 texImage
->NumSamples
= samples
;
4314 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4316 if (width
> 0 && height
> 0 && depth
> 0) {
4318 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4319 width
, height
, depth
)) {
4320 /* tidy up the texture image state. strictly speaking,
4321 * we're allowed to just leave this in whatever state we
4322 * like, but being tidy is good.
4324 _mesa_init_teximage_fields(ctx
, texImage
,
4325 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4329 texObj
->Immutable
= immutable
;
4330 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4335 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4336 GLint internalformat
, GLsizei width
,
4337 GLsizei height
, GLboolean fixedsamplelocations
)
4339 teximagemultisample(2, target
, samples
, internalformat
,
4340 width
, height
, 1, fixedsamplelocations
, GL_FALSE
, "glTexImage2DMultisample");
4344 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4345 GLint internalformat
, GLsizei width
,
4346 GLsizei height
, GLsizei depth
,
4347 GLboolean fixedsamplelocations
)
4349 teximagemultisample(3, target
, samples
, internalformat
,
4350 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
, "glTexImage3DMultisample");
4355 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4356 GLenum internalformat
, GLsizei width
,
4357 GLsizei height
, GLboolean fixedsamplelocations
)
4359 teximagemultisample(2, target
, samples
, internalformat
,
4360 width
, height
, 1, fixedsamplelocations
, GL_TRUE
, "glTexStorage2DMultisample");
4364 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4365 GLenum internalformat
, GLsizei width
,
4366 GLsizei height
, GLsizei depth
,
4367 GLboolean fixedsamplelocations
)
4369 teximagemultisample(3, target
, samples
, internalformat
,
4370 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
, "glTexStorage3DMultisample");