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 /* Tell driver about the new renderbuffer texture */
2764 ctx
->Driver
.RenderTexture(ctx
, ctx
->DrawBuffer
, att
);
2765 /* Mark fb status as indeterminate to force re-validation */
2774 * When a texture image is specified we have to check if it's bound to
2775 * any framebuffer objects (render to texture) in order to detect changes
2776 * in size or format since that effects FBO completeness.
2777 * Any FBOs rendering into the texture must be re-validated.
2780 _mesa_update_fbo_texture(struct gl_context
*ctx
,
2781 struct gl_texture_object
*texObj
,
2782 GLuint face
, GLuint level
)
2784 /* Only check this texture if it's been marked as RenderToTexture */
2785 if (texObj
->_RenderToTexture
) {
2786 struct cb_info info
;
2788 info
.texObj
= texObj
;
2791 _mesa_HashWalk(ctx
->Shared
->FrameBuffers
, check_rtt_cb
, &info
);
2797 * If the texture object's GenerateMipmap flag is set and we've
2798 * changed the texture base level image, regenerate the rest of the
2799 * mipmap levels now.
2802 check_gen_mipmap(struct gl_context
*ctx
, GLenum target
,
2803 struct gl_texture_object
*texObj
, GLint level
)
2805 ASSERT(target
!= GL_TEXTURE_CUBE_MAP
);
2806 if (texObj
->GenerateMipmap
&&
2807 level
== texObj
->BaseLevel
&&
2808 level
< texObj
->MaxLevel
) {
2809 ASSERT(ctx
->Driver
.GenerateMipmap
);
2810 ctx
->Driver
.GenerateMipmap(ctx
, target
, texObj
);
2815 /** Debug helper: override the user-requested internal format */
2817 override_internal_format(GLenum internalFormat
, GLint width
, GLint height
)
2820 if (internalFormat
== GL_RGBA16F_ARB
||
2821 internalFormat
== GL_RGBA32F_ARB
) {
2822 printf("Convert rgba float tex to int %d x %d\n", width
, height
);
2825 else if (internalFormat
== GL_RGB16F_ARB
||
2826 internalFormat
== GL_RGB32F_ARB
) {
2827 printf("Convert rgb float tex to int %d x %d\n", width
, height
);
2830 else if (internalFormat
== GL_LUMINANCE_ALPHA16F_ARB
||
2831 internalFormat
== GL_LUMINANCE_ALPHA32F_ARB
) {
2832 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2833 return GL_LUMINANCE_ALPHA
;
2835 else if (internalFormat
== GL_LUMINANCE16F_ARB
||
2836 internalFormat
== GL_LUMINANCE32F_ARB
) {
2837 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2838 return GL_LUMINANCE
;
2840 else if (internalFormat
== GL_ALPHA16F_ARB
||
2841 internalFormat
== GL_ALPHA32F_ARB
) {
2842 printf("Convert luminance float tex to int %d x %d\n", width
, height
);
2846 else if (internalFormat == GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) {
2847 internalFormat = GL_RGBA;
2851 return internalFormat
;
2854 return internalFormat
;
2860 * Choose the actual hardware format for a texture image.
2861 * Try to use the same format as the previous image level when possible.
2862 * Otherwise, ask the driver for the best format.
2863 * It's important to try to choose a consistant format for all levels
2864 * for efficient texture memory layout/allocation. In particular, this
2865 * comes up during automatic mipmap generation.
2868 _mesa_choose_texture_format(struct gl_context
*ctx
,
2869 struct gl_texture_object
*texObj
,
2870 GLenum target
, GLint level
,
2871 GLenum internalFormat
, GLenum format
, GLenum type
)
2875 /* see if we've already chosen a format for the previous level */
2877 struct gl_texture_image
*prevImage
=
2878 _mesa_select_tex_image(ctx
, texObj
, target
, level
- 1);
2879 /* See if the prev level is defined and has an internal format which
2880 * matches the new internal format.
2883 prevImage
->Width
> 0 &&
2884 prevImage
->InternalFormat
== internalFormat
) {
2885 /* use the same format */
2886 ASSERT(prevImage
->TexFormat
!= MESA_FORMAT_NONE
);
2887 return prevImage
->TexFormat
;
2891 /* If the application requested compression to an S3TC format but we don't
2892 * have the DTXn library, force a generic compressed format instead.
2894 if (internalFormat
!= format
&& format
!= GL_NONE
) {
2895 const GLenum before
= internalFormat
;
2897 switch (internalFormat
) {
2898 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
2899 if (!ctx
->Mesa_DXTn
)
2900 internalFormat
= GL_COMPRESSED_RGB
;
2902 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
2903 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
2904 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
2905 if (!ctx
->Mesa_DXTn
)
2906 internalFormat
= GL_COMPRESSED_RGBA
;
2912 if (before
!= internalFormat
) {
2914 "DXT compression requested (%s), "
2915 "but libtxc_dxtn library not installed. Using %s "
2917 _mesa_lookup_enum_by_nr(before
),
2918 _mesa_lookup_enum_by_nr(internalFormat
));
2922 /* choose format from scratch */
2923 f
= ctx
->Driver
.ChooseTextureFormat(ctx
, texObj
->Target
, internalFormat
,
2925 ASSERT(f
!= MESA_FORMAT_NONE
);
2930 * Adjust pixel unpack params and image dimensions to strip off the
2931 * one-pixel texture border.
2933 * Gallium and intel don't support texture borders. They've seldem been used
2934 * and seldom been implemented correctly anyway.
2936 * \param unpackNew returns the new pixel unpack parameters
2939 strip_texture_border(GLenum target
,
2940 GLint
*width
, GLint
*height
, GLint
*depth
,
2941 const struct gl_pixelstore_attrib
*unpack
,
2942 struct gl_pixelstore_attrib
*unpackNew
)
2948 *unpackNew
= *unpack
;
2950 if (unpackNew
->RowLength
== 0)
2951 unpackNew
->RowLength
= *width
;
2953 if (unpackNew
->ImageHeight
== 0)
2954 unpackNew
->ImageHeight
= *height
;
2956 assert(*width
>= 3);
2957 unpackNew
->SkipPixels
++; /* skip the border */
2958 *width
= *width
- 2; /* reduce the width by two border pixels */
2960 /* The min height of a texture with a border is 3 */
2961 if (*height
>= 3 && target
!= GL_TEXTURE_1D_ARRAY
) {
2962 unpackNew
->SkipRows
++; /* skip the border */
2963 *height
= *height
- 2; /* reduce the height by two border pixels */
2966 if (*depth
>= 3 && target
!= GL_TEXTURE_2D_ARRAY
&& target
!= GL_TEXTURE_CUBE_MAP_ARRAY
) {
2967 unpackNew
->SkipImages
++; /* skip the border */
2968 *depth
= *depth
- 2; /* reduce the depth by two border pixels */
2974 * Common code to implement all the glTexImage1D/2D/3D functions
2975 * as well as glCompressedTexImage1D/2D/3D.
2976 * \param compressed only GL_TRUE for glCompressedTexImage1D/2D/3D calls.
2977 * \param format the user's image format (only used if !compressed)
2978 * \param type the user's image type (only used if !compressed)
2979 * \param imageSize only used for glCompressedTexImage1D/2D/3D calls.
2982 teximage(struct gl_context
*ctx
, GLboolean compressed
, GLuint dims
,
2983 GLenum target
, GLint level
, GLint internalFormat
,
2984 GLsizei width
, GLsizei height
, GLsizei depth
,
2985 GLint border
, GLenum format
, GLenum type
,
2986 GLsizei imageSize
, const GLvoid
*pixels
)
2988 const char *func
= compressed
? "glCompressedTexImage" : "glTexImage";
2989 struct gl_pixelstore_attrib unpack_no_border
;
2990 const struct gl_pixelstore_attrib
*unpack
= &ctx
->Unpack
;
2991 struct gl_texture_object
*texObj
;
2992 gl_format texFormat
;
2993 GLboolean dimensionsOK
, sizeOK
;
2995 FLUSH_VERTICES(ctx
, 0);
2997 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
)) {
3000 "glCompressedTexImage%uD %s %d %s %d %d %d %d %p\n",
3002 _mesa_lookup_enum_by_nr(target
), level
,
3003 _mesa_lookup_enum_by_nr(internalFormat
),
3004 width
, height
, depth
, border
, pixels
);
3007 "glTexImage%uD %s %d %s %d %d %d %d %s %s %p\n",
3009 _mesa_lookup_enum_by_nr(target
), level
,
3010 _mesa_lookup_enum_by_nr(internalFormat
),
3011 width
, height
, depth
, border
,
3012 _mesa_lookup_enum_by_nr(format
),
3013 _mesa_lookup_enum_by_nr(type
), pixels
);
3016 internalFormat
= override_internal_format(internalFormat
, width
, height
);
3018 /* target error checking */
3019 if (!legal_teximage_target(ctx
, dims
, target
)) {
3020 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s%uD(target=%s)",
3021 func
, dims
, _mesa_lookup_enum_by_nr(target
));
3025 /* general error checking */
3027 if (compressed_texture_error_check(ctx
, dims
, target
, level
,
3029 width
, height
, depth
,
3034 if (texture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3035 format
, type
, width
, height
, depth
, border
))
3039 /* Here we convert a cpal compressed image into a regular glTexImage2D
3040 * call by decompressing the texture. If we really want to support cpal
3041 * textures in any driver this would have to be changed.
3043 if (ctx
->API
== API_OPENGLES
&& compressed
&& dims
== 2) {
3044 switch (internalFormat
) {
3045 case GL_PALETTE4_RGB8_OES
:
3046 case GL_PALETTE4_RGBA8_OES
:
3047 case GL_PALETTE4_R5_G6_B5_OES
:
3048 case GL_PALETTE4_RGBA4_OES
:
3049 case GL_PALETTE4_RGB5_A1_OES
:
3050 case GL_PALETTE8_RGB8_OES
:
3051 case GL_PALETTE8_RGBA8_OES
:
3052 case GL_PALETTE8_R5_G6_B5_OES
:
3053 case GL_PALETTE8_RGBA4_OES
:
3054 case GL_PALETTE8_RGB5_A1_OES
:
3055 _mesa_cpal_compressed_teximage2d(target
, level
, internalFormat
,
3056 width
, height
, imageSize
, pixels
);
3061 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3065 /* For glCompressedTexImage() the driver has no choice about the
3066 * texture format since we'll never transcode the user's compressed
3067 * image data. The internalFormat was error checked earlier.
3069 texFormat
= _mesa_glenum_to_compressed_format(internalFormat
);
3072 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3073 internalFormat
, format
, type
);
3076 assert(texFormat
!= MESA_FORMAT_NONE
);
3078 /* check that width, height, depth are legal for the mipmap level */
3079 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, level
, width
,
3080 height
, depth
, border
);
3082 /* check that the texture won't take too much memory, etc */
3083 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3085 width
, height
, depth
, border
);
3087 if (_mesa_is_proxy_texture(target
)) {
3088 /* Proxy texture: just clear or set state depending on error checking */
3089 struct gl_texture_image
*texImage
=
3090 get_proxy_tex_image(ctx
, target
, level
);
3093 return; /* GL_OUT_OF_MEMORY already recorded */
3095 if (dimensionsOK
&& sizeOK
) {
3096 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, depth
,
3097 border
, internalFormat
, texFormat
);
3100 clear_teximage_fields(texImage
);
3104 /* non-proxy target */
3105 const GLuint face
= _mesa_tex_target_to_face(target
);
3106 struct gl_texture_image
*texImage
;
3108 if (!dimensionsOK
) {
3109 _mesa_error(ctx
, GL_INVALID_VALUE
,
3110 "glTexImage%uD(invalid width or height or depth)",
3116 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3117 "glTexImage%uD(image too large)", dims
);
3121 /* Allow a hardware driver to just strip out the border, to provide
3122 * reliable but slightly incorrect hardware rendering instead of
3123 * rarely-tested software fallback rendering.
3125 if (border
&& ctx
->Const
.StripTextureBorder
) {
3126 strip_texture_border(target
, &width
, &height
, &depth
, unpack
,
3129 unpack
= &unpack_no_border
;
3132 if (ctx
->NewState
& _NEW_PIXEL
)
3133 _mesa_update_state(ctx
);
3135 _mesa_lock_texture(ctx
, texObj
);
3137 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3140 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s%uD", func
, dims
);
3143 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3145 _mesa_init_teximage_fields(ctx
, texImage
,
3146 width
, height
, depth
,
3147 border
, internalFormat
, texFormat
);
3149 /* Give the texture to the driver. <pixels> may be null. */
3150 if (width
> 0 && height
> 0 && depth
> 0) {
3152 ctx
->Driver
.CompressedTexImage(ctx
, dims
, texImage
,
3156 ctx
->Driver
.TexImage(ctx
, dims
, texImage
, format
,
3157 type
, pixels
, unpack
);
3161 check_gen_mipmap(ctx
, target
, texObj
, level
);
3163 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3165 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3168 _mesa_unlock_texture(ctx
, texObj
);
3175 * Called from the API. Note that width includes the border.
3178 _mesa_TexImage1D( GLenum target
, GLint level
, GLint internalFormat
,
3179 GLsizei width
, GLint border
, GLenum format
,
3180 GLenum type
, const GLvoid
*pixels
)
3182 GET_CURRENT_CONTEXT(ctx
);
3183 teximage(ctx
, GL_FALSE
, 1, target
, level
, internalFormat
, width
, 1, 1,
3184 border
, format
, type
, 0, pixels
);
3189 _mesa_TexImage2D( GLenum target
, GLint level
, GLint internalFormat
,
3190 GLsizei width
, GLsizei height
, GLint border
,
3191 GLenum format
, GLenum type
,
3192 const GLvoid
*pixels
)
3194 GET_CURRENT_CONTEXT(ctx
);
3195 teximage(ctx
, GL_FALSE
, 2, target
, level
, internalFormat
, width
, height
, 1,
3196 border
, format
, type
, 0, pixels
);
3201 * Called by the API or display list executor.
3202 * Note that width and height include the border.
3205 _mesa_TexImage3D( GLenum target
, GLint level
, GLint internalFormat
,
3206 GLsizei width
, GLsizei height
, GLsizei depth
,
3207 GLint border
, GLenum format
, GLenum type
,
3208 const GLvoid
*pixels
)
3210 GET_CURRENT_CONTEXT(ctx
);
3211 teximage(ctx
, GL_FALSE
, 3, target
, level
, internalFormat
,
3212 width
, height
, depth
,
3213 border
, format
, type
, 0, pixels
);
3218 _mesa_TexImage3DEXT( GLenum target
, GLint level
, GLenum internalFormat
,
3219 GLsizei width
, GLsizei height
, GLsizei depth
,
3220 GLint border
, GLenum format
, GLenum type
,
3221 const GLvoid
*pixels
)
3223 _mesa_TexImage3D(target
, level
, (GLint
) internalFormat
, width
, height
,
3224 depth
, border
, format
, type
, pixels
);
3229 _mesa_EGLImageTargetTexture2DOES (GLenum target
, GLeglImageOES image
)
3231 struct gl_texture_object
*texObj
;
3232 struct gl_texture_image
*texImage
;
3234 GET_CURRENT_CONTEXT(ctx
);
3235 FLUSH_VERTICES(ctx
, 0);
3239 valid_target
= ctx
->Extensions
.OES_EGL_image
;
3241 case GL_TEXTURE_EXTERNAL_OES
:
3242 valid_target
= ctx
->Extensions
.OES_EGL_image_external
;
3245 valid_target
= false;
3249 if (!valid_target
) {
3250 _mesa_error(ctx
, GL_INVALID_ENUM
,
3251 "glEGLImageTargetTexture2D(target=%d)", target
);
3256 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3257 "glEGLImageTargetTexture2D(image=%p)", image
);
3261 if (ctx
->NewState
& _NEW_PIXEL
)
3262 _mesa_update_state(ctx
);
3264 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3265 _mesa_lock_texture(ctx
, texObj
);
3267 if (texObj
->Immutable
) {
3268 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3269 "glEGLImageTargetTexture2D(texture is immutable)");
3270 _mesa_unlock_texture(ctx
, texObj
);
3274 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, 0);
3276 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glEGLImageTargetTexture2D");
3278 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3280 ctx
->Driver
.EGLImageTargetTexture2D(ctx
, target
,
3281 texObj
, texImage
, image
);
3283 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3285 _mesa_unlock_texture(ctx
, texObj
);
3292 * Implement all the glTexSubImage1/2/3D() functions.
3295 texsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3296 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3297 GLsizei width
, GLsizei height
, GLsizei depth
,
3298 GLenum format
, GLenum type
, const GLvoid
*pixels
)
3300 struct gl_texture_object
*texObj
;
3301 struct gl_texture_image
*texImage
;
3303 FLUSH_VERTICES(ctx
, 0);
3305 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3306 _mesa_debug(ctx
, "glTexSubImage%uD %s %d %d %d %d %d %d %d %s %s %p\n",
3308 _mesa_lookup_enum_by_nr(target
), level
,
3309 xoffset
, yoffset
, zoffset
, width
, height
, depth
,
3310 _mesa_lookup_enum_by_nr(format
),
3311 _mesa_lookup_enum_by_nr(type
), pixels
);
3313 /* check target (proxies not allowed) */
3314 if (!legal_texsubimage_target(ctx
, dims
, target
)) {
3315 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexSubImage%uD(target=%s)",
3316 dims
, _mesa_lookup_enum_by_nr(target
));
3320 if (ctx
->NewState
& _NEW_PIXEL
)
3321 _mesa_update_state(ctx
);
3323 if (texsubimage_error_check(ctx
, dims
, target
, level
,
3324 xoffset
, yoffset
, zoffset
,
3325 width
, height
, depth
, format
, type
)) {
3326 return; /* error was detected */
3329 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3331 _mesa_lock_texture(ctx
, texObj
);
3333 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3335 if (width
> 0 && height
> 0 && depth
> 0) {
3336 /* If we have a border, offset=-1 is legal. Bias by border width. */
3339 if (target
!= GL_TEXTURE_2D_ARRAY
)
3340 zoffset
+= texImage
->Border
;
3343 if (target
!= GL_TEXTURE_1D_ARRAY
)
3344 yoffset
+= texImage
->Border
;
3347 xoffset
+= texImage
->Border
;
3350 ctx
->Driver
.TexSubImage(ctx
, dims
, texImage
,
3351 xoffset
, yoffset
, zoffset
,
3352 width
, height
, depth
,
3353 format
, type
, pixels
, &ctx
->Unpack
);
3355 check_gen_mipmap(ctx
, target
, texObj
, level
);
3357 ctx
->NewState
|= _NEW_TEXTURE
;
3360 _mesa_unlock_texture(ctx
, texObj
);
3365 _mesa_TexSubImage1D( GLenum target
, GLint level
,
3366 GLint xoffset
, GLsizei width
,
3367 GLenum format
, GLenum type
,
3368 const GLvoid
*pixels
)
3370 GET_CURRENT_CONTEXT(ctx
);
3371 texsubimage(ctx
, 1, target
, level
,
3374 format
, type
, pixels
);
3379 _mesa_TexSubImage2D( GLenum target
, GLint level
,
3380 GLint xoffset
, GLint yoffset
,
3381 GLsizei width
, GLsizei height
,
3382 GLenum format
, GLenum type
,
3383 const GLvoid
*pixels
)
3385 GET_CURRENT_CONTEXT(ctx
);
3386 texsubimage(ctx
, 2, target
, level
,
3387 xoffset
, yoffset
, 0,
3389 format
, type
, pixels
);
3395 _mesa_TexSubImage3D( GLenum target
, GLint level
,
3396 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3397 GLsizei width
, GLsizei height
, GLsizei depth
,
3398 GLenum format
, GLenum type
,
3399 const GLvoid
*pixels
)
3401 GET_CURRENT_CONTEXT(ctx
);
3402 texsubimage(ctx
, 3, target
, level
,
3403 xoffset
, yoffset
, zoffset
,
3404 width
, height
, depth
,
3405 format
, type
, pixels
);
3411 * For glCopyTexSubImage, return the source renderbuffer to copy texel data
3412 * from. This depends on whether the texture contains color or depth values.
3414 static struct gl_renderbuffer
*
3415 get_copy_tex_image_source(struct gl_context
*ctx
, gl_format texFormat
)
3417 if (_mesa_get_format_bits(texFormat
, GL_DEPTH_BITS
) > 0) {
3418 /* reading from depth/stencil buffer */
3419 return ctx
->ReadBuffer
->Attachment
[BUFFER_DEPTH
].Renderbuffer
;
3422 /* copying from color buffer */
3423 return ctx
->ReadBuffer
->_ColorReadBuffer
;
3430 * Implement the glCopyTexImage1/2D() functions.
3433 copyteximage(struct gl_context
*ctx
, GLuint dims
,
3434 GLenum target
, GLint level
, GLenum internalFormat
,
3435 GLint x
, GLint y
, GLsizei width
, GLsizei height
, GLint border
)
3437 struct gl_texture_object
*texObj
;
3438 struct gl_texture_image
*texImage
;
3439 const GLuint face
= _mesa_tex_target_to_face(target
);
3440 gl_format texFormat
;
3442 FLUSH_VERTICES(ctx
, 0);
3444 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3445 _mesa_debug(ctx
, "glCopyTexImage%uD %s %d %s %d %d %d %d %d\n",
3447 _mesa_lookup_enum_by_nr(target
), level
,
3448 _mesa_lookup_enum_by_nr(internalFormat
),
3449 x
, y
, width
, height
, border
);
3451 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3452 _mesa_update_state(ctx
);
3454 if (copytexture_error_check(ctx
, dims
, target
, level
, internalFormat
,
3455 width
, height
, border
))
3458 if (!_mesa_legal_texture_dimensions(ctx
, target
, level
, width
, height
,
3460 _mesa_error(ctx
, GL_INVALID_VALUE
,
3461 "glCopyTexImage%uD(invalid width or height)", dims
);
3465 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3468 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, level
,
3469 internalFormat
, GL_NONE
, GL_NONE
);
3470 assert(texFormat
!= MESA_FORMAT_NONE
);
3472 if (!ctx
->Driver
.TestProxyTexImage(ctx
, _mesa_get_proxy_target(target
),
3474 width
, height
, 1, border
)) {
3475 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3476 "glCopyTexImage%uD(image too large)", dims
);
3480 if (border
&& ctx
->Const
.StripTextureBorder
) {
3482 width
-= border
* 2;
3485 height
-= border
* 2;
3490 _mesa_lock_texture(ctx
, texObj
);
3492 texImage
= _mesa_get_tex_image(ctx
, texObj
, target
, level
);
3495 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCopyTexImage%uD", dims
);
3498 GLint srcX
= x
, srcY
= y
, dstX
= 0, dstY
= 0, dstZ
= 0;
3500 /* Free old texture image */
3501 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
3503 _mesa_init_teximage_fields(ctx
, texImage
, width
, height
, 1,
3504 border
, internalFormat
, texFormat
);
3506 if (width
&& height
) {
3507 /* Allocate texture memory (no pixel data yet) */
3508 ctx
->Driver
.AllocTextureImageBuffer(ctx
, texImage
);
3510 if (_mesa_clip_copytexsubimage(ctx
, &dstX
, &dstY
, &srcX
, &srcY
,
3512 struct gl_renderbuffer
*srcRb
=
3513 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3515 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
, dstX
, dstY
, dstZ
,
3516 srcRb
, srcX
, srcY
, width
, height
);
3519 check_gen_mipmap(ctx
, target
, texObj
, level
);
3522 _mesa_update_fbo_texture(ctx
, texObj
, face
, level
);
3524 _mesa_dirty_texobj(ctx
, texObj
, GL_TRUE
);
3527 _mesa_unlock_texture(ctx
, texObj
);
3533 _mesa_CopyTexImage1D( GLenum target
, GLint level
,
3534 GLenum internalFormat
,
3536 GLsizei width
, GLint border
)
3538 GET_CURRENT_CONTEXT(ctx
);
3539 copyteximage(ctx
, 1, target
, level
, internalFormat
, x
, y
, width
, 1, border
);
3545 _mesa_CopyTexImage2D( GLenum target
, GLint level
, GLenum internalFormat
,
3546 GLint x
, GLint y
, GLsizei width
, GLsizei height
,
3549 GET_CURRENT_CONTEXT(ctx
);
3550 copyteximage(ctx
, 2, target
, level
, internalFormat
,
3551 x
, y
, width
, height
, border
);
3557 * Implementation for glCopyTexSubImage1/2/3D() functions.
3560 copytexsubimage(struct gl_context
*ctx
, GLuint dims
, GLenum target
, GLint level
,
3561 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3562 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3564 struct gl_texture_object
*texObj
;
3565 struct gl_texture_image
*texImage
;
3567 FLUSH_VERTICES(ctx
, 0);
3569 if (MESA_VERBOSE
& (VERBOSE_API
|VERBOSE_TEXTURE
))
3570 _mesa_debug(ctx
, "glCopyTexSubImage%uD %s %d %d %d %d %d %d %d %d\n",
3572 _mesa_lookup_enum_by_nr(target
),
3573 level
, xoffset
, yoffset
, zoffset
, x
, y
, width
, height
);
3575 if (ctx
->NewState
& NEW_COPY_TEX_STATE
)
3576 _mesa_update_state(ctx
);
3578 if (copytexsubimage_error_check(ctx
, dims
, target
, level
,
3579 xoffset
, yoffset
, zoffset
, width
, height
)) {
3583 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3585 _mesa_lock_texture(ctx
, texObj
);
3587 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3589 /* If we have a border, offset=-1 is legal. Bias by border width. */
3592 if (target
!= GL_TEXTURE_2D_ARRAY
)
3593 zoffset
+= texImage
->Border
;
3596 if (target
!= GL_TEXTURE_1D_ARRAY
)
3597 yoffset
+= texImage
->Border
;
3600 xoffset
+= texImage
->Border
;
3603 if (_mesa_clip_copytexsubimage(ctx
, &xoffset
, &yoffset
, &x
, &y
,
3605 struct gl_renderbuffer
*srcRb
=
3606 get_copy_tex_image_source(ctx
, texImage
->TexFormat
);
3608 ctx
->Driver
.CopyTexSubImage(ctx
, dims
, texImage
,
3609 xoffset
, yoffset
, zoffset
,
3610 srcRb
, x
, y
, width
, height
);
3612 check_gen_mipmap(ctx
, target
, texObj
, level
);
3614 ctx
->NewState
|= _NEW_TEXTURE
;
3617 _mesa_unlock_texture(ctx
, texObj
);
3622 _mesa_CopyTexSubImage1D( GLenum target
, GLint level
,
3623 GLint xoffset
, GLint x
, GLint y
, GLsizei width
)
3625 GET_CURRENT_CONTEXT(ctx
);
3626 copytexsubimage(ctx
, 1, target
, level
, xoffset
, 0, 0, x
, y
, width
, 1);
3632 _mesa_CopyTexSubImage2D( GLenum target
, GLint level
,
3633 GLint xoffset
, GLint yoffset
,
3634 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3636 GET_CURRENT_CONTEXT(ctx
);
3637 copytexsubimage(ctx
, 2, target
, level
, xoffset
, yoffset
, 0, x
, y
,
3644 _mesa_CopyTexSubImage3D( GLenum target
, GLint level
,
3645 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3646 GLint x
, GLint y
, GLsizei width
, GLsizei height
)
3648 GET_CURRENT_CONTEXT(ctx
);
3649 copytexsubimage(ctx
, 3, target
, level
, xoffset
, yoffset
, zoffset
,
3650 x
, y
, width
, height
);
3656 /**********************************************************************/
3657 /****** Compressed Textures ******/
3658 /**********************************************************************/
3662 * Error checking for glCompressedTexSubImage[123]D().
3663 * \return error code or GL_NO_ERROR.
3666 compressed_subtexture_error_check(struct gl_context
*ctx
, GLint dims
,
3667 GLenum target
, GLint level
,
3668 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3669 GLsizei width
, GLsizei height
, GLsizei depth
,
3670 GLenum format
, GLsizei imageSize
)
3672 struct gl_texture_object
*texObj
;
3673 struct gl_texture_image
*texImage
;
3681 case GL_TEXTURE_CUBE_MAP_POSITIVE_X
:
3682 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X
:
3683 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y
:
3684 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
:
3685 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z
:
3686 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
:
3690 targetOK
= GL_FALSE
;
3695 targetOK
= (target
== GL_TEXTURE_2D_ARRAY
);
3699 /* no 1D compressed textures at this time */
3700 targetOK
= GL_FALSE
;
3705 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(target)",
3710 /* this will catch any invalid compressed format token */
3711 if (!_mesa_is_compressed_format(ctx
, format
)) {
3712 _mesa_error(ctx
, GL_INVALID_ENUM
, "glCompressedTexImage%uD(format)",
3717 if (level
< 0 || level
>= _mesa_max_texture_levels(ctx
, target
)) {
3718 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(level=%d)",
3723 expectedSize
= compressed_tex_size(width
, height
, depth
, format
);
3724 if (expectedSize
!= imageSize
) {
3725 _mesa_error(ctx
, GL_INVALID_VALUE
, "glCompressedTexImage%uD(size=%d)",
3730 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3732 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
3733 "glCompressedTexSubImage%uD()", dims
);
3737 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3739 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3740 "glCompressedTexSubImage%uD(invalid texture image)", dims
);
3744 if ((GLint
) format
!= texImage
->InternalFormat
) {
3745 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3746 "glCompressedTexSubImage%uD(format=0x%x)", dims
, format
);
3750 if (compressedteximage_only_format(ctx
, format
)) {
3751 _mesa_error(ctx
, GL_INVALID_OPERATION
,
3752 "glCompressedTexSubImage%uD(format=0x%x cannot be updated)"
3757 if (error_check_subtexture_dimensions(ctx
, "glCompressedTexSubImage", dims
,
3758 texImage
, xoffset
, yoffset
, zoffset
,
3759 width
, height
, depth
)) {
3768 _mesa_CompressedTexImage1D(GLenum target
, GLint level
,
3769 GLenum internalFormat
, GLsizei width
,
3770 GLint border
, GLsizei imageSize
,
3773 GET_CURRENT_CONTEXT(ctx
);
3774 teximage(ctx
, GL_TRUE
, 1, target
, level
, internalFormat
,
3775 width
, 1, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3780 _mesa_CompressedTexImage2D(GLenum target
, GLint level
,
3781 GLenum internalFormat
, GLsizei width
,
3782 GLsizei height
, GLint border
, GLsizei imageSize
,
3785 GET_CURRENT_CONTEXT(ctx
);
3786 teximage(ctx
, GL_TRUE
, 2, target
, level
, internalFormat
,
3787 width
, height
, 1, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3792 _mesa_CompressedTexImage3D(GLenum target
, GLint level
,
3793 GLenum internalFormat
, GLsizei width
,
3794 GLsizei height
, GLsizei depth
, GLint border
,
3795 GLsizei imageSize
, const GLvoid
*data
)
3797 GET_CURRENT_CONTEXT(ctx
);
3798 teximage(ctx
, GL_TRUE
, 3, target
, level
, internalFormat
,
3799 width
, height
, depth
, border
, GL_NONE
, GL_NONE
, imageSize
, data
);
3804 * Common helper for glCompressedTexSubImage1/2/3D().
3807 compressed_tex_sub_image(GLuint dims
, GLenum target
, GLint level
,
3808 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3809 GLsizei width
, GLsizei height
, GLsizei depth
,
3810 GLenum format
, GLsizei imageSize
, const GLvoid
*data
)
3812 struct gl_texture_object
*texObj
;
3813 struct gl_texture_image
*texImage
;
3814 GET_CURRENT_CONTEXT(ctx
);
3815 FLUSH_VERTICES(ctx
, 0);
3817 if (compressed_subtexture_error_check(ctx
, dims
, target
, level
,
3818 xoffset
, yoffset
, zoffset
,
3819 width
, height
, depth
,
3820 format
, imageSize
)) {
3824 texObj
= _mesa_get_current_tex_object(ctx
, target
);
3826 _mesa_lock_texture(ctx
, texObj
);
3828 texImage
= _mesa_select_tex_image(ctx
, texObj
, target
, level
);
3831 if (width
> 0 && height
> 0 && depth
> 0) {
3832 ctx
->Driver
.CompressedTexSubImage(ctx
, dims
, texImage
,
3833 xoffset
, yoffset
, zoffset
,
3834 width
, height
, depth
,
3835 format
, imageSize
, data
);
3837 check_gen_mipmap(ctx
, target
, texObj
, level
);
3839 ctx
->NewState
|= _NEW_TEXTURE
;
3842 _mesa_unlock_texture(ctx
, texObj
);
3847 _mesa_CompressedTexSubImage1D(GLenum target
, GLint level
, GLint xoffset
,
3848 GLsizei width
, GLenum format
,
3849 GLsizei imageSize
, const GLvoid
*data
)
3851 compressed_tex_sub_image(1, target
, level
, xoffset
, 0, 0, width
, 1, 1,
3852 format
, imageSize
, data
);
3857 _mesa_CompressedTexSubImage2D(GLenum target
, GLint level
, GLint xoffset
,
3858 GLint yoffset
, GLsizei width
, GLsizei height
,
3859 GLenum format
, GLsizei imageSize
,
3862 compressed_tex_sub_image(2, target
, level
, xoffset
, yoffset
, 0,
3863 width
, height
, 1, format
, imageSize
, data
);
3868 _mesa_CompressedTexSubImage3D(GLenum target
, GLint level
, GLint xoffset
,
3869 GLint yoffset
, GLint zoffset
, GLsizei width
,
3870 GLsizei height
, GLsizei depth
, GLenum format
,
3871 GLsizei imageSize
, const GLvoid
*data
)
3873 compressed_tex_sub_image(3, target
, level
, xoffset
, yoffset
, zoffset
,
3874 width
, height
, depth
, format
, imageSize
, data
);
3878 get_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
3880 switch (internalFormat
) {
3882 return MESA_FORMAT_A8
;
3884 return MESA_FORMAT_A16
;
3885 case GL_ALPHA16F_ARB
:
3886 return MESA_FORMAT_ALPHA_FLOAT16
;
3887 case GL_ALPHA32F_ARB
:
3888 return MESA_FORMAT_ALPHA_FLOAT32
;
3889 case GL_ALPHA8I_EXT
:
3890 return MESA_FORMAT_ALPHA_INT8
;
3891 case GL_ALPHA16I_EXT
:
3892 return MESA_FORMAT_ALPHA_INT16
;
3893 case GL_ALPHA32I_EXT
:
3894 return MESA_FORMAT_ALPHA_INT32
;
3895 case GL_ALPHA8UI_EXT
:
3896 return MESA_FORMAT_ALPHA_UINT8
;
3897 case GL_ALPHA16UI_EXT
:
3898 return MESA_FORMAT_ALPHA_UINT16
;
3899 case GL_ALPHA32UI_EXT
:
3900 return MESA_FORMAT_ALPHA_UINT32
;
3902 return MESA_FORMAT_L8
;
3903 case GL_LUMINANCE16
:
3904 return MESA_FORMAT_L16
;
3905 case GL_LUMINANCE16F_ARB
:
3906 return MESA_FORMAT_LUMINANCE_FLOAT16
;
3907 case GL_LUMINANCE32F_ARB
:
3908 return MESA_FORMAT_LUMINANCE_FLOAT32
;
3909 case GL_LUMINANCE8I_EXT
:
3910 return MESA_FORMAT_LUMINANCE_INT8
;
3911 case GL_LUMINANCE16I_EXT
:
3912 return MESA_FORMAT_LUMINANCE_INT16
;
3913 case GL_LUMINANCE32I_EXT
:
3914 return MESA_FORMAT_LUMINANCE_INT32
;
3915 case GL_LUMINANCE8UI_EXT
:
3916 return MESA_FORMAT_LUMINANCE_UINT8
;
3917 case GL_LUMINANCE16UI_EXT
:
3918 return MESA_FORMAT_LUMINANCE_UINT16
;
3919 case GL_LUMINANCE32UI_EXT
:
3920 return MESA_FORMAT_LUMINANCE_UINT32
;
3921 case GL_LUMINANCE8_ALPHA8
:
3922 return MESA_FORMAT_AL88
;
3923 case GL_LUMINANCE16_ALPHA16
:
3924 return MESA_FORMAT_AL1616
;
3925 case GL_LUMINANCE_ALPHA16F_ARB
:
3926 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
;
3927 case GL_LUMINANCE_ALPHA32F_ARB
:
3928 return MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
;
3929 case GL_LUMINANCE_ALPHA8I_EXT
:
3930 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3931 case GL_LUMINANCE_ALPHA16I_EXT
:
3932 return MESA_FORMAT_LUMINANCE_ALPHA_INT8
;
3933 case GL_LUMINANCE_ALPHA32I_EXT
:
3934 return MESA_FORMAT_LUMINANCE_ALPHA_INT16
;
3935 case GL_LUMINANCE_ALPHA8UI_EXT
:
3936 return MESA_FORMAT_LUMINANCE_ALPHA_UINT8
;
3937 case GL_LUMINANCE_ALPHA16UI_EXT
:
3938 return MESA_FORMAT_LUMINANCE_ALPHA_UINT16
;
3939 case GL_LUMINANCE_ALPHA32UI_EXT
:
3940 return MESA_FORMAT_LUMINANCE_ALPHA_UINT32
;
3942 return MESA_FORMAT_I8
;
3943 case GL_INTENSITY16
:
3944 return MESA_FORMAT_I16
;
3945 case GL_INTENSITY16F_ARB
:
3946 return MESA_FORMAT_INTENSITY_FLOAT16
;
3947 case GL_INTENSITY32F_ARB
:
3948 return MESA_FORMAT_INTENSITY_FLOAT32
;
3949 case GL_INTENSITY8I_EXT
:
3950 return MESA_FORMAT_INTENSITY_INT8
;
3951 case GL_INTENSITY16I_EXT
:
3952 return MESA_FORMAT_INTENSITY_INT16
;
3953 case GL_INTENSITY32I_EXT
:
3954 return MESA_FORMAT_INTENSITY_INT32
;
3955 case GL_INTENSITY8UI_EXT
:
3956 return MESA_FORMAT_INTENSITY_UINT8
;
3957 case GL_INTENSITY16UI_EXT
:
3958 return MESA_FORMAT_INTENSITY_UINT16
;
3959 case GL_INTENSITY32UI_EXT
:
3960 return MESA_FORMAT_INTENSITY_UINT32
;
3962 return MESA_FORMAT_RGBA8888_REV
;
3964 return MESA_FORMAT_RGBA_16
;
3965 case GL_RGBA16F_ARB
:
3966 return MESA_FORMAT_RGBA_FLOAT16
;
3967 case GL_RGBA32F_ARB
:
3968 return MESA_FORMAT_RGBA_FLOAT32
;
3970 return MESA_FORMAT_RGBA_INT8
;
3971 case GL_RGBA16I_EXT
:
3972 return MESA_FORMAT_RGBA_INT16
;
3973 case GL_RGBA32I_EXT
:
3974 return MESA_FORMAT_RGBA_INT32
;
3975 case GL_RGBA8UI_EXT
:
3976 return MESA_FORMAT_RGBA_UINT8
;
3977 case GL_RGBA16UI_EXT
:
3978 return MESA_FORMAT_RGBA_UINT16
;
3979 case GL_RGBA32UI_EXT
:
3980 return MESA_FORMAT_RGBA_UINT32
;
3983 return MESA_FORMAT_GR88
;
3985 return MESA_FORMAT_GR1616
;
3987 return MESA_FORMAT_RG_FLOAT16
;
3989 return MESA_FORMAT_RG_FLOAT32
;
3991 return MESA_FORMAT_RG_INT8
;
3993 return MESA_FORMAT_RG_INT16
;
3995 return MESA_FORMAT_RG_INT32
;
3997 return MESA_FORMAT_RG_UINT8
;
3999 return MESA_FORMAT_RG_UINT16
;
4001 return MESA_FORMAT_RG_UINT32
;
4004 return MESA_FORMAT_R8
;
4006 return MESA_FORMAT_R16
;
4008 return MESA_FORMAT_R_FLOAT16
;
4010 return MESA_FORMAT_R_FLOAT32
;
4012 return MESA_FORMAT_R_INT8
;
4014 return MESA_FORMAT_R_INT16
;
4016 return MESA_FORMAT_R_INT32
;
4018 return MESA_FORMAT_R_UINT8
;
4020 return MESA_FORMAT_R_UINT16
;
4022 return MESA_FORMAT_R_UINT32
;
4025 return MESA_FORMAT_RGB_FLOAT32
;
4027 return MESA_FORMAT_RGB_UINT32
;
4029 return MESA_FORMAT_RGB_INT32
;
4032 return MESA_FORMAT_NONE
;
4037 validate_texbuffer_format(const struct gl_context
*ctx
, GLenum internalFormat
)
4039 gl_format format
= get_texbuffer_format(ctx
, internalFormat
);
4042 if (format
== MESA_FORMAT_NONE
)
4043 return MESA_FORMAT_NONE
;
4045 datatype
= _mesa_get_format_datatype(format
);
4046 if (datatype
== GL_FLOAT
&& !ctx
->Extensions
.ARB_texture_float
)
4047 return MESA_FORMAT_NONE
;
4049 if (datatype
== GL_HALF_FLOAT
&& !ctx
->Extensions
.ARB_half_float_pixel
)
4050 return MESA_FORMAT_NONE
;
4052 /* The GL_ARB_texture_rg and GL_ARB_texture_buffer_object specs don't make
4053 * any mention of R/RG formats, but they appear in the GL 3.1 core
4056 if (ctx
->Version
<= 30) {
4057 GLenum base_format
= _mesa_get_format_base_format(format
);
4059 if (base_format
== GL_R
|| base_format
== GL_RG
)
4060 return MESA_FORMAT_NONE
;
4063 if (!ctx
->Extensions
.ARB_texture_buffer_object_rgb32
) {
4064 GLenum base_format
= _mesa_get_format_base_format(format
);
4065 if (base_format
== GL_RGB
)
4066 return MESA_FORMAT_NONE
;
4073 texbufferrange(struct gl_context
*ctx
, GLenum target
, GLenum internalFormat
,
4074 struct gl_buffer_object
*bufObj
,
4075 GLintptr offset
, GLsizeiptr size
)
4077 struct gl_texture_object
*texObj
;
4080 FLUSH_VERTICES(ctx
, 0);
4082 if (target
!= GL_TEXTURE_BUFFER_ARB
) {
4083 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(target)");
4087 format
= validate_texbuffer_format(ctx
, internalFormat
);
4088 if (format
== MESA_FORMAT_NONE
) {
4089 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexBuffer(internalFormat 0x%x)",
4094 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4096 _mesa_lock_texture(ctx
, texObj
);
4098 _mesa_reference_buffer_object(ctx
, &texObj
->BufferObject
, bufObj
);
4099 texObj
->BufferObjectFormat
= internalFormat
;
4100 texObj
->_BufferObjectFormat
= format
;
4101 texObj
->BufferOffset
= offset
;
4102 texObj
->BufferSize
= size
;
4104 _mesa_unlock_texture(ctx
, texObj
);
4107 /** GL_ARB_texture_buffer_object */
4109 _mesa_TexBuffer(GLenum target
, GLenum internalFormat
, GLuint buffer
)
4111 struct gl_buffer_object
*bufObj
;
4113 GET_CURRENT_CONTEXT(ctx
);
4115 /* NOTE: ARB_texture_buffer_object has interactions with
4116 * the compatibility profile that are not implemented.
4118 if (!(ctx
->API
== API_OPENGL_CORE
&&
4119 ctx
->Extensions
.ARB_texture_buffer_object
)) {
4120 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer");
4124 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4125 if (!bufObj
&& buffer
) {
4126 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBuffer(buffer %u)", buffer
);
4130 texbufferrange(ctx
, target
, internalFormat
, bufObj
, 0, buffer
? -1 : 0);
4133 /** GL_ARB_texture_buffer_range */
4135 _mesa_TexBufferRange(GLenum target
, GLenum internalFormat
, GLuint buffer
,
4136 GLintptr offset
, GLsizeiptr size
)
4138 struct gl_buffer_object
*bufObj
;
4140 GET_CURRENT_CONTEXT(ctx
);
4142 if (!(ctx
->API
== API_OPENGL_CORE
&&
4143 ctx
->Extensions
.ARB_texture_buffer_range
)) {
4144 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange");
4148 bufObj
= _mesa_lookup_bufferobj(ctx
, buffer
);
4152 (offset
+ size
) > bufObj
->Size
) {
4153 _mesa_error(ctx
, GL_INVALID_VALUE
, "glTexBufferRange");
4156 if (offset
% ctx
->Const
.TextureBufferOffsetAlignment
) {
4157 _mesa_error(ctx
, GL_INVALID_VALUE
,
4158 "glTexBufferRange(invalid offset alignment)");
4161 } else if (buffer
) {
4162 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexBufferRange(buffer %u)",
4170 texbufferrange(ctx
, target
, internalFormat
, bufObj
, offset
, size
);
4174 is_renderable_texture_format(struct gl_context
*ctx
, GLenum internalformat
)
4176 /* Everything that is allowed for renderbuffers,
4177 * except for a base format of GL_STENCIL_INDEX.
4179 GLenum baseFormat
= _mesa_base_fbo_format(ctx
, internalformat
);
4180 return baseFormat
!= 0 && baseFormat
!= GL_STENCIL_INDEX
;
4183 /** GL_ARB_texture_multisample */
4185 check_multisample_target(GLuint dims
, GLenum target
)
4188 case GL_TEXTURE_2D_MULTISAMPLE
:
4189 case GL_PROXY_TEXTURE_2D_MULTISAMPLE
:
4192 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4193 case GL_PROXY_TEXTURE_2D_MULTISAMPLE_ARRAY
:
4202 teximagemultisample(GLuint dims
, GLenum target
, GLsizei samples
,
4203 GLint internalformat
, GLsizei width
, GLsizei height
,
4204 GLsizei depth
, GLboolean fixedsamplelocations
,
4205 GLboolean immutable
, const char *func
)
4207 struct gl_texture_object
*texObj
;
4208 struct gl_texture_image
*texImage
;
4209 GLboolean sizeOK
, dimensionsOK
;
4210 gl_format texFormat
;
4211 GLenum sample_count_error
;
4213 GET_CURRENT_CONTEXT(ctx
);
4215 if (!(ctx
->Extensions
.ARB_texture_multisample
4216 && _mesa_is_desktop_gl(ctx
))) {
4217 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(unsupported)", func
);
4221 if (!check_multisample_target(dims
, target
)) {
4222 _mesa_error(ctx
, GL_INVALID_ENUM
, "%s(target)", func
);
4226 /* check that the specified internalformat is color/depth/stencil-renderable;
4227 * refer GL3.1 spec 4.4.4
4230 if (immutable
&& !_mesa_is_legal_tex_storage_format(ctx
, internalformat
)) {
4231 _mesa_error(ctx
, GL_INVALID_ENUM
,
4232 "%s(internalformat=%s not legal for immutable-format)",
4233 func
, _mesa_lookup_enum_by_nr(internalformat
));
4237 if (!is_renderable_texture_format(ctx
, internalformat
)) {
4238 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4239 "%s(internalformat=%s)",
4240 func
, _mesa_lookup_enum_by_nr(internalformat
));
4244 sample_count_error
= _mesa_check_sample_count(ctx
, target
,
4245 internalformat
, samples
);
4246 if (sample_count_error
!= GL_NO_ERROR
) {
4247 _mesa_error(ctx
, sample_count_error
, "%s(samples)", func
);
4251 texObj
= _mesa_get_current_tex_object(ctx
, target
);
4253 if (immutable
&& (!texObj
|| (texObj
->Name
== 0))) {
4254 _mesa_error(ctx
, GL_INVALID_OPERATION
,
4255 "%s(texture object 0)",
4260 texImage
= _mesa_get_tex_image(ctx
, texObj
, 0, 0);
4262 if (texImage
== NULL
) {
4263 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "%s()", func
);
4267 texFormat
= _mesa_choose_texture_format(ctx
, texObj
, target
, 0,
4268 internalformat
, GL_NONE
, GL_NONE
);
4269 assert(texFormat
!= MESA_FORMAT_NONE
);
4271 dimensionsOK
= _mesa_legal_texture_dimensions(ctx
, target
, 0,
4272 width
, height
, depth
, 0);
4274 sizeOK
= ctx
->Driver
.TestProxyTexImage(ctx
, target
, 0, texFormat
,
4275 width
, height
, depth
, 0);
4277 if (_mesa_is_proxy_texture(target
)) {
4278 if (dimensionsOK
&& sizeOK
) {
4279 _mesa_init_teximage_fields(ctx
, texImage
,
4280 width
, height
, depth
, 0, internalformat
, texFormat
);
4281 texImage
->NumSamples
= samples
;
4282 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4285 /* clear all image fields */
4286 _mesa_init_teximage_fields(ctx
, texImage
,
4287 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4291 if (!dimensionsOK
) {
4292 _mesa_error(ctx
, GL_INVALID_VALUE
,
4293 "%s(invalid width or height)", func
);
4298 _mesa_error(ctx
, GL_OUT_OF_MEMORY
,
4299 "%s(texture too large)", func
);
4303 /* Check if texObj->Immutable is set */
4304 if (texObj
->Immutable
) {
4305 _mesa_error(ctx
, GL_INVALID_OPERATION
, "%s(immutable)", func
);
4309 ctx
->Driver
.FreeTextureImageBuffer(ctx
, texImage
);
4311 _mesa_init_teximage_fields(ctx
, texImage
,
4312 width
, height
, depth
, 0, internalformat
, texFormat
);
4314 texImage
->NumSamples
= samples
;
4315 texImage
->FixedSampleLocations
= fixedsamplelocations
;
4317 if (width
> 0 && height
> 0 && depth
> 0) {
4319 if (!ctx
->Driver
.AllocTextureStorage(ctx
, texObj
, 1,
4320 width
, height
, depth
)) {
4321 /* tidy up the texture image state. strictly speaking,
4322 * we're allowed to just leave this in whatever state we
4323 * like, but being tidy is good.
4325 _mesa_init_teximage_fields(ctx
, texImage
,
4326 0, 0, 0, 0, GL_NONE
, MESA_FORMAT_NONE
);
4330 texObj
->Immutable
= immutable
;
4331 _mesa_update_fbo_texture(ctx
, texObj
, 0, 0);
4336 _mesa_TexImage2DMultisample(GLenum target
, GLsizei samples
,
4337 GLint internalformat
, GLsizei width
,
4338 GLsizei height
, GLboolean fixedsamplelocations
)
4340 teximagemultisample(2, target
, samples
, internalformat
,
4341 width
, height
, 1, fixedsamplelocations
, GL_FALSE
, "glTexImage2DMultisample");
4345 _mesa_TexImage3DMultisample(GLenum target
, GLsizei samples
,
4346 GLint internalformat
, GLsizei width
,
4347 GLsizei height
, GLsizei depth
,
4348 GLboolean fixedsamplelocations
)
4350 teximagemultisample(3, target
, samples
, internalformat
,
4351 width
, height
, depth
, fixedsamplelocations
, GL_FALSE
, "glTexImage3DMultisample");
4356 _mesa_TexStorage2DMultisample(GLenum target
, GLsizei samples
,
4357 GLenum internalformat
, GLsizei width
,
4358 GLsizei height
, GLboolean fixedsamplelocations
)
4360 teximagemultisample(2, target
, samples
, internalformat
,
4361 width
, height
, 1, fixedsamplelocations
, GL_TRUE
, "glTexStorage2DMultisample");
4365 _mesa_TexStorage3DMultisample(GLenum target
, GLsizei samples
,
4366 GLenum internalformat
, GLsizei width
,
4367 GLsizei height
, GLsizei depth
,
4368 GLboolean fixedsamplelocations
)
4370 teximagemultisample(3, target
, samples
, internalformat
,
4371 width
, height
, depth
, fixedsamplelocations
, GL_TRUE
, "glTexStorage3DMultisample");